ScummVM API documentation
script_manager.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef ZVISION_SCRIPT_MANAGER_H
23#define ZVISION_SCRIPT_MANAGER_H
24
25#include "common/events.h"
26#include "common/hashmap.h"
27#include "common/queue.h"
28#include "zvision/scripting/control.h"
29#include "zvision/scripting/puzzle.h"
30#include "zvision/scripting/scripting_effect.h"
31
32namespace Common {
33class String;
34class SeekableReadStream;
35}
36
37namespace ZVision {
38
39class ZVision;
40
41enum StateKey {
42 StateKey_World = 3,
43 StateKey_Room = 4,
44 StateKey_Node = 5,
45 StateKey_View = 6,
46 StateKey_ViewPos = 7,
47 StateKey_KeyPress = 8,
48 StateKey_InventoryItem = 9,
49 StateKey_LMouse = 10,
50 StateKey_NotSet = 11, // This key doesn't set
51 StateKey_Rounds = 12,
52 StateKey_Venus = 13,
53 StateKey_RMouse = 18,
54 StateKey_MenuState = 19,
55 StateKey_RestoreFlag = 20,
56 StateKey_Quitting = 39,
57 StateKey_LastWorld = 40,
58 StateKey_LastRoom = 41,
59 StateKey_LastNode = 42,
60 StateKey_LastView = 43,
61 StateKey_LastViewPos = 44,
62 StateKey_Menu_LastWorld = 45,
63 StateKey_Menu_LastRoom = 46,
64 StateKey_Menu_LastNode = 47,
65 StateKey_Menu_LastView = 48,
66 StateKey_Menu_LastViewPos = 49,
67 StateKey_KbdRotateSpeed = 50,
68 StateKey_Subtitles = 51,
69 StateKey_StreamSkipKey = 52,
70 StateKey_RotateSpeed = 53,
71 StateKey_Volume = 56,
72 StateKey_Qsound = 57,
73 StateKey_VenusEnable = 58,
74 StateKey_HighQuality = 59,
75 StateKey_VideoLineSkip = 65,
76 StateKey_Platform = 66, // 0 = Windows, !0 = DOS
77 StateKey_InstallLevel = 67,
78 StateKey_CountryCode = 68,
79 StateKey_CPU = 69, // !1 = 486, 1 = i586/Pentium
80 StateKey_MovieCursor = 70,
81 StateKey_NoTurnAnim = 71,
82 StateKey_WIN958 = 72, // 0 = high system RAM, !0 = low system RAM (<8MB)
83 StateKey_ShowErrorDlg = 73,
84 StateKey_DebugCheats = 74,
85 StateKey_JapanFonts = 75,
86 StateKey_ExecScopeStyle = 76, // 0 = ZGI, 1 = Nemesis
87 StateKey_Brightness = 77,
88 StateKey_MPEGMovies = 78,
89 StateKey_EF9_R = 91,
90 StateKey_EF9_G = 92,
91 StateKey_EF9_B = 93,
92 StateKey_EF9_Speed = 94,
93 StateKey_Inv_Cnt_Slot = 100,
94 StateKey_Inv_1_Slot = 101,
95 StateKey_Inv_49_Slot = 149,
96 // ZGI only
97 StateKey_Inv_TotalSlots = 150,
98 StateKey_Inv_StartSlot = 151,
99 StateKey_Spell_1 = 191,
100 StateKey_Active_Spell = 205,
101 StateKey_Reversed_Spellbooc = 206
102};
103
104struct Location {
105 Location() : world('g'), room('a'), node('r'), view('y'), offset(0) {}
106
107 char world;
108 char room;
109 char node;
110 char view;
111 uint32 offset;
112};
113
114inline bool operator==(const Location& lhs, const Location& rhs) {
115 return (
116 lhs.world == rhs.world &&
117 lhs.room == rhs.room &&
118 lhs.node == rhs.node &&
119 lhs.view == rhs.view
120 );
121}
122
123inline bool operator==(const Location& lhs, const char* rhs) {
124 Common::String lhsStr = Common::String::format("%c%c%c%c", lhs.world, lhs.room, lhs.node, lhs.view);
125 return lhsStr == rhs;
126}
127
128inline bool operator!=(const Location& lhs, const Location& rhs) {
129 return !(lhs == rhs);
130}
131
132inline bool operator!=(const Location& lhs, const char* rhs) {
133 return !(lhs == rhs);
134}
135
136typedef Common::List<Puzzle *> PuzzleList;
137typedef Common::Queue<Puzzle *> PuzzleQueue;
138typedef Common::List<Control *> ControlList;
139typedef Common::HashMap<uint32, int32> StateMap;
140typedef Common::List<ScriptingEffect *> SideFXList;
141typedef Common::List<Common::Event> EventList;
142
144public:
145 ScriptManager(ZVision *engine);
147
148private:
149 ZVision *_engine;
150
151 struct ScriptScope {
152 uint32 procCount;
153
154 PuzzleList *scopeQueue; // For adding puzzles to queue
155 PuzzleList *execQueue; // Switch to it when execute
156 PuzzleList privQueueOne;
157 PuzzleList privQueueTwo;
158
159 PuzzleList puzzles;
160 ControlList controls;
161 };
162
163 struct PuzzleRef {
164 Puzzle *puz;
165 ScriptScope *scope;
166 };
167
169
175 StateMap _globalState;
177 StateMap _globalStateFlags;
179 PuzzleMap _referenceTable;
181 ControlList *_activeControls;
182
183 EventList _controlEvents;
184
185 ScriptScope _universe;
186 ScriptScope _world;
187 ScriptScope _room;
188 ScriptScope _nodeview;
189
191 SideFXList _activeSideFx;
192
193 Location _currentLocation;
194 Location _nextLocation;
195 const uint8 _changeLocationExtraCycles = 16;
196
197 uint32 _currentlyFocusedControl;
198
199public:
200 enum TransitionLevel {
201 NONE,
202 VIEW,
203 NODE,
204 ROOM,
205 WORLD
206 };
207
208 void initialize(bool restarted = false);
209 void process(uint deltaTimeMillis);
210 void queuePuzzles(uint32 key);
211
212 int getStateValue(uint32 key);
213 void setStateValue(uint32 key, int value);
214
215 uint getStateFlag(uint32 key);
216 void setStateFlag(uint32 key, uint value);
217 void unsetStateFlag(uint32 key, uint value);
218
219 void addControl(Control *control);
220 Control *getControl(uint32 key);
221
222 void enableControl(uint32 key);
223 void disableControl(uint32 key);
224
225 void focusControl(uint32 key);
226 // Only change focus control without call focus/unfocus.
227 void setFocusControlKey(uint32 key);
228
229 void addSideFX(ScriptingEffect *fx);
230 ScriptingEffect *getSideFX(uint32 key);
231 void deleteSideFx(uint32 key);
232 void stopSideFx(uint32 key);
233 void killSideFx(uint32 key);
234 void killSideFxType(ScriptingEffect::ScriptingEffectType type);
235
236 void addEvent(Common::Event);
237 void flushEvent(Common::EventType type);
238
245 void onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos);
252 void onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos);
260 bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos);
272 void onKeyUp(Common::KeyState keyState);
273
275 void changeLocation(char world, char room, char node, char view, uint32 offset);
276 void changeLocation(const Location &_newLocation);
277
278 bool changingLocation() const;
279
280 void serialize(Common::WriteStream *stream);
281 void deserialize(Common::SeekableReadStream *stream);
282
283 Location getCurrentLocation() const;
284 Location getLastLocation();
285 Location getLastMenuLocation();
286
295
296private:
297 void referenceTableAddPuzzle(uint32 key, PuzzleRef ref);
298 void addPuzzlesToReferenceTable(ScriptScope &scope);
299 void updateNodes(uint deltaTimeMillis);
300 void updateControls(uint deltaTimeMillis);
312 bool checkPuzzleCriteria(Puzzle *puzzle, uint counter);
313 void cleanStateTable(); // Set all global state values to zero
314 void cleanScriptScope(ScriptScope &scope); // Resets everything in this scope, all lists empty, procCount to zero.
315 bool execScope(ScriptScope &scope);
316
318 void ChangeLocationReal(bool isLoading);
319
320 int8 inventoryGetCount();
321 void inventorySetCount(int8 cnt);
322 int16 inventoryGetItem(int8 id);
323 void inventorySetItem(int8 id, int16 item);
324
325 void setStateFlagSilent(uint32 key, uint value);
326 void setStateValueSilent(uint32 key, int value);
327
328public:
329 void inventoryAdd(int16 item);
330 void inventoryDrop(int16 item);
331 void inventoryCycle();
332
333private:
340 void parseScrFile(const Common::Path &fileName, ScriptScope &scope);
341
349 void parsePuzzle(Puzzle *puzzle, Common::SeekableReadStream &stream);
350
360 bool parseCriteria(Common::SeekableReadStream &stream, Common::List<Common::List<Puzzle::CriteriaEntry> > &criteriaList, uint32 key) const;
361
371 void parseResults(Common::SeekableReadStream &stream, Common::List<ResultAction *> &actionList, uint32 key) const;
372
379 uint parseFlags(Common::SeekableReadStream &stream) const;
380
387 Control *parseControl(Common::String &line, Common::SeekableReadStream &stream);
388};
389
401public:
402 ValueSlot(ScriptManager *scriptManager, const char *slotValue);
403 int16 getValue();
404private:
405 int16 _value;
406 bool _slot;
407 ScriptManager *_scriptManager;
408};
409
410} // End of namespace ZVision
411
412#endif
Definition: path.h:52
Definition: queue.h:42
Definition: stream.h:745
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: stream.h:77
Definition: control.h:43
Definition: script_manager.h:143
void onKeyUp(Common::KeyState keyState)
void onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos)
void trimCommentsAndWhiteSpace(Common::String *string) const
void changeLocation(char world, char room, char node, char view, uint32 offset)
void onKeyDown(Common::KeyState keyState)
bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos)
void onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos)
Definition: scripting_effect.h:45
Definition: script_manager.h:400
EventType
Definition: events.h:49
Definition: algorithm.h:29
Definition: focus_list.h:27
Definition: events.h:218
Definition: keyboard.h:294
Definition: rect.h:144
Definition: script_manager.h:104
Definition: puzzle.h:31