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 "zvision/scripting/puzzle.h"
26 #include "zvision/scripting/control.h"
27 #include "zvision/scripting/scripting_effect.h"
28 
29 #include "common/hashmap.h"
30 #include "common/queue.h"
31 #include "common/events.h"
32 
33 namespace Common {
34 class String;
35 class SeekableReadStream;
36 }
37 
38 namespace ZVision {
39 
40 class ZVision;
41 
42 enum StateKey {
43  StateKey_World = 3,
44  StateKey_Room = 4,
45  StateKey_Node = 5,
46  StateKey_View = 6,
47  StateKey_ViewPos = 7,
48  StateKey_KeyPress = 8,
49  StateKey_InventoryItem = 9,
50  StateKey_LMouse = 10,
51  StateKey_NotSet = 11, // This key doesn't set
52  StateKey_Rounds = 12,
53  StateKey_Venus = 13,
54  StateKey_RMouse = 18,
55  StateKey_MenuState = 19,
56  StateKey_RestoreFlag = 20,
57  StateKey_Quitting = 39,
58  StateKey_LastWorld = 40,
59  StateKey_LastRoom = 41,
60  StateKey_LastNode = 42,
61  StateKey_LastView = 43,
62  StateKey_LastViewPos = 44,
63  StateKey_Menu_LastWorld = 45,
64  StateKey_Menu_LastRoom = 46,
65  StateKey_Menu_LastNode = 47,
66  StateKey_Menu_LastView = 48,
67  StateKey_Menu_LastViewPos = 49,
68  StateKey_KbdRotateSpeed = 50,
69  StateKey_Subtitles = 51,
70  StateKey_StreamSkipKey = 52,
71  StateKey_RotateSpeed = 53,
72  StateKey_Volume = 56,
73  StateKey_Qsound = 57,
74  StateKey_VenusEnable = 58,
75  StateKey_HighQuality = 59,
76  StateKey_VideoLineSkip = 65,
77  StateKey_Platform = 66,
78  StateKey_InstallLevel = 67,
79  StateKey_CountryCode = 68,
80  StateKey_CPU = 69,
81  StateKey_MovieCursor = 70,
82  StateKey_NoTurnAnim = 71,
83  StateKey_WIN958 = 72,
84  StateKey_ShowErrorDlg = 73,
85  StateKey_DebugCheats = 74,
86  StateKey_JapanFonts = 75,
87  StateKey_ExecScopeStyle = 76,
88  StateKey_Brightness = 77,
89  StateKey_MPEGMovies = 78,
90  StateKey_EF9_R = 91,
91  StateKey_EF9_G = 92,
92  StateKey_EF9_B = 93,
93  StateKey_EF9_Speed = 94,
94  StateKey_Inv_Cnt_Slot = 100,
95  StateKey_Inv_1_Slot = 101,
96  StateKey_Inv_49_Slot = 149,
97  // ZGI only
98  StateKey_Inv_TotalSlots = 150,
99  StateKey_Inv_StartSlot = 151,
100  StateKey_Spell_1 = 191,
101  StateKey_Active_Spell = 205,
102  StateKey_Reversed_Spellbooc = 206
103 };
104 
105 struct Location {
106  Location() : world('g'), room('a'), node('r'), view('y'), offset(0) {}
107 
108  char world;
109  char room;
110  char node;
111  char view;
112  uint32 offset;
113 };
114 
115 inline bool operator==(const Location& lhs, const Location& rhs) {
116  return (
117  lhs.world == rhs.world &&
118  lhs.room == rhs.room &&
119  lhs.node == rhs.node &&
120  lhs.view == rhs.view
121  );
122 }
123 
124 inline bool operator==(const Location& lhs, const char* rhs) {
125  Common::String lhsStr = Common::String::format("%c%c%c%c", lhs.world, lhs.room, lhs.node, lhs.view);
126  return lhsStr == rhs;
127 }
128 
129 inline bool operator!=(const Location& lhs, const Location& rhs) {
130  return !(lhs == rhs);
131 }
132 
133 inline bool operator!=(const Location& lhs, const char* rhs) {
134  return !(lhs == rhs);
135 }
136 
143 
145 public:
146  ScriptManager(ZVision *engine);
147  ~ScriptManager();
148 
149 private:
150  ZVision *_engine;
151 
152  struct ScriptScope {
153  uint32 procCount;
154 
155  PuzzleList *scopeQueue; // For adding puzzles to queue
156  PuzzleList *execQueue; // Switch to it when execute
157  PuzzleList privQueueOne;
158  PuzzleList privQueueTwo;
159 
160  PuzzleList puzzles;
161  ControlList controls;
162  };
163 
164  struct PuzzleRef {
165  Puzzle *puz;
166  ScriptScope *scope;
167  };
168 
170 
176  StateMap _globalState;
178  StateMap _globalStateFlags;
180  PuzzleMap _referenceTable;
182  ControlList *_activeControls;
183 
184  EventList _controlEvents;
185 
186  ScriptScope universe;
187  ScriptScope world;
188  ScriptScope room;
189  ScriptScope nodeview;
190 
192  SideFXList _activeSideFx;
193 
194  Location _currentLocation;
195  Location _nextLocation;
196  int _changeLocationDelayCycles;
197 
198  uint32 _currentlyFocusedControl;
199 
200 public:
201  void initialize();
202  void update(uint deltaTimeMillis);
203  void queuePuzzles(uint32 key);
204 
205  int getStateValue(uint32 key);
206  void setStateValue(uint32 key, int value);
207 
208  uint getStateFlag(uint32 key);
209  void setStateFlag(uint32 key, uint value);
210  void unsetStateFlag(uint32 key, uint value);
211 
212  void addControl(Control *control);
213  Control *getControl(uint32 key);
214 
215  void enableControl(uint32 key);
216  void disableControl(uint32 key);
217 
218  void focusControl(uint32 key);
219  // Only change focus control without call focus/unfocus.
220  void setFocusControlKey(uint32 key);
221 
222  void addSideFX(ScriptingEffect *fx);
223  ScriptingEffect *getSideFX(uint32 key);
224  void deleteSideFx(uint32 key);
225  void stopSideFx(uint32 key);
226  void killSideFx(uint32 key);
227  void killSideFxType(ScriptingEffect::ScriptingEffectType type);
228 
229  void addEvent(Common::Event);
230  void flushEvent(Common::EventType type);
231 
238  void onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos);
245  void onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos);
253  bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos);
259  void onKeyDown(Common::KeyState keyState);
265  void onKeyUp(Common::KeyState keyState);
266 
268  void changeLocation(char world, char room, char node, char view, uint32 offset);
269  void changeLocation(const Location &_newLocation);
270 
271  void serialize(Common::WriteStream *stream);
272  void deserialize(Common::SeekableReadStream *stream);
273 
274  Location getCurrentLocation() const;
275  Location getLastLocation();
276  Location getLastMenuLocation();
277 
285  void trimCommentsAndWhiteSpace(Common::String *string) const;
286 
287 private:
288  void referenceTableAddPuzzle(uint32 key, PuzzleRef ref);
289  void addPuzzlesToReferenceTable(ScriptScope &scope);
290  void updateNodes(uint deltaTimeMillis);
291  void updateControls(uint deltaTimeMillis);
292  bool checkPuzzleCriteria(Puzzle *puzzle, uint counter);
293  void cleanStateTable();
294  void cleanScriptScope(ScriptScope &scope);
295  bool execScope(ScriptScope &scope);
296 
298  void ChangeLocationReal(bool isLoading);
299 
300  int8 inventoryGetCount();
301  void inventorySetCount(int8 cnt);
302  int16 inventoryGetItem(int8 id);
303  void inventorySetItem(int8 id, int16 item);
304 
305  void setStateFlagSilent(uint32 key, uint value);
306  void setStateValueSilent(uint32 key, int value);
307 
308 public:
309  void inventoryAdd(int16 item);
310  void inventoryDrop(int16 item);
311  void inventoryCycle();
312 
313 private:
320  void parseScrFile(const Common::Path &fileName, ScriptScope &scope);
321 
329  void parsePuzzle(Puzzle *puzzle, Common::SeekableReadStream &stream);
330 
340  bool parseCriteria(Common::SeekableReadStream &stream, Common::List<Common::List<Puzzle::CriteriaEntry> > &criteriaList, uint32 key) const;
341 
350  void parseResults(Common::SeekableReadStream &stream, Common::List<ResultAction *> &actionList) const;
351 
358  uint parseFlags(Common::SeekableReadStream &stream) const;
359 
366  Control *parseControl(Common::String &line, Common::SeekableReadStream &stream);
367 };
368 
369 class ValueSlot {
370 public:
371  ValueSlot(ScriptManager *scriptManager, const char *slotValue);
372  int16 getValue();
373 private:
374  int16 value;
375  bool slot;
376  ScriptManager *_scriptManager;
377 };
378 
379 } // End of namespace ZVision
380 
381 #endif
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: stream.h:77
Definition: control.h:43
EventType
Definition: events.h:49
Definition: puzzle.h:32
Definition: script_manager.h:144
Definition: path.h:52
Definition: stream.h:745
Definition: clock.h:29
Definition: queue.h:42
Definition: script_manager.h:105
Definition: scripting_effect.h:45
Definition: events.h:199
Definition: algorithm.h:29
Definition: rect.h:45
Definition: script_manager.h:369
Definition: keyboard.h:294