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 
32 namespace Common {
33 class String;
34 class SeekableReadStream;
35 }
36 
37 namespace ZVision {
38 
39 class ZVision;
40 
41 enum 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,
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 
104 struct 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 
114 inline 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 
123 inline 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 
128 inline bool operator!=(const Location& lhs, const Location& rhs) {
129  return !(lhs == rhs);
130 }
131 
132 inline bool operator!=(const Location& lhs, const char* rhs) {
133  return !(lhs == rhs);
134 }
135 
142 
144 public:
145  ScriptManager(ZVision *engine);
146  ~ScriptManager();
147 
148 private:
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  int _changeLocationDelayCycles;
196 
197  uint32 _currentlyFocusedControl;
198 
199 public:
200  void initialize(bool restarted = false);
201  void process(uint deltaTimeMillis);
202  void queuePuzzles(uint32 key);
203 
204  int getStateValue(uint32 key);
205  void setStateValue(uint32 key, int value);
206 
207  uint getStateFlag(uint32 key);
208  void setStateFlag(uint32 key, uint value);
209  void unsetStateFlag(uint32 key, uint value);
210 
211  void addControl(Control *control);
212  Control *getControl(uint32 key);
213 
214  void enableControl(uint32 key);
215  void disableControl(uint32 key);
216 
217  void focusControl(uint32 key);
218  // Only change focus control without call focus/unfocus.
219  void setFocusControlKey(uint32 key);
220 
221  void addSideFX(ScriptingEffect *fx);
222  ScriptingEffect *getSideFX(uint32 key);
223  void deleteSideFx(uint32 key);
224  void stopSideFx(uint32 key);
225  void killSideFx(uint32 key);
226  void killSideFxType(ScriptingEffect::ScriptingEffectType type);
227 
228  void addEvent(Common::Event);
229  void flushEvent(Common::EventType type);
230 
237  void onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos);
244  void onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos);
252  bool onMouseMove(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos);
258  void onKeyDown(Common::KeyState keyState);
264  void onKeyUp(Common::KeyState keyState);
265 
267  void changeLocation(char world, char room, char node, char view, uint32 offset);
268  void changeLocation(const Location &_newLocation);
269 
270  bool changingLocation() const;
271 
272  void serialize(Common::WriteStream *stream);
273  void deserialize(Common::SeekableReadStream *stream);
274 
275  Location getCurrentLocation() const;
276  Location getLastLocation();
277  Location getLastMenuLocation();
278 
286  void trimCommentsAndWhiteSpace(Common::String *string) const;
287 
288 private:
289  void referenceTableAddPuzzle(uint32 key, PuzzleRef ref);
290  void addPuzzlesToReferenceTable(ScriptScope &scope);
291  void updateNodes(uint deltaTimeMillis);
292  void updateControls(uint deltaTimeMillis);
293  bool checkPuzzleCriteria(Puzzle *puzzle, uint counter);
294  void cleanStateTable();
295  void cleanScriptScope(ScriptScope &scope);
296  bool execScope(ScriptScope &scope);
297 
299  void ChangeLocationReal(bool isLoading);
300 
301  int8 inventoryGetCount();
302  void inventorySetCount(int8 cnt);
303  int16 inventoryGetItem(int8 id);
304  void inventorySetItem(int8 id, int16 item);
305 
306  void setStateFlagSilent(uint32 key, uint value);
307  void setStateValueSilent(uint32 key, int value);
308 
309 public:
310  void inventoryAdd(int16 item);
311  void inventoryDrop(int16 item);
312  void inventoryCycle();
313 
314 private:
321  void parseScrFile(const Common::Path &fileName, ScriptScope &scope);
322 
330  void parsePuzzle(Puzzle *puzzle, Common::SeekableReadStream &stream);
331 
341  bool parseCriteria(Common::SeekableReadStream &stream, Common::List<Common::List<Puzzle::CriteriaEntry> > &criteriaList, uint32 key) const;
342 
352  void parseResults(Common::SeekableReadStream &stream, Common::List<ResultAction *> &actionList, uint32 key) const;
353 
360  uint parseFlags(Common::SeekableReadStream &stream) const;
361 
368  Control *parseControl(Common::String &line, Common::SeekableReadStream &stream);
369 };
370 
381 class ValueSlot {
382 public:
383  ValueSlot(ScriptManager *scriptManager, const char *slotValue);
384  int16 getValue();
385 private:
386  int16 _value;
387  bool _slot;
388  ScriptManager *_scriptManager;
389 };
390 
391 } // End of namespace ZVision
392 
393 #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:31
Definition: script_manager.h:143
Definition: path.h:52
Definition: stream.h:745
Definition: focus_list.h:27
Definition: queue.h:42
Definition: script_manager.h:104
Definition: scripting_effect.h:45
Definition: events.h:210
Definition: algorithm.h:29
Definition: rect.h:144
Definition: script_manager.h:381
Definition: keyboard.h:294