ScummVM API documentation
riven_scripts.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 RIVEN_SCRIPTS_H
23 #define RIVEN_SCRIPTS_H
24 
25 #include "mohawk/riven_stack.h"
26 
27 #include "common/str-array.h"
28 #include "common/ptr.h"
29 #include "common/textconsole.h"
30 
31 #define DECLARE_OPCODE(x) void x(uint16 op, const ArgumentArray &args)
32 
33 namespace Common {
34 class ReadStream;
35 }
36 
37 namespace Mohawk {
38 
39 // Script Types
40 enum {
41  kMouseDownScript = 0,
42  kMouseDragScript = 1,
43  kMouseUpScript = 2,
44  kMouseEnterScript = 3,
45  kMouseInsideScript = 4,
46  kMouseLeaveScript = 5,
47 
48  kCardLoadScript = 6,
49  kCardLeaveScript = 7,
50  kCardFrameScript = 8,
51  kCardEnterScript = 9,
52  kCardUpdateScript = 10
53 };
54 
55 enum RivenCommandType {
56  kRivenCommandDrawBitmap = 1,
57  kRivenCommandChangeCard = 2,
58  kRivenCommandPlayScriptSLST = 3,
59  kRivenCommandPlaySound = 4,
60  kRivenCommandSetVariable = 7,
61  kRivenCommandSwitch = 8,
62  kRivenCommandEnableHotspot = 9,
63  kRivenCommandDisableHotspot = 10,
64  kRivenCommandStopSound = 12,
65  kRivenCommandChangeCursor = 13,
66  kRivenCommandDelay = 14,
67  kRivenCommandRunExternal = 17,
68  kRivenCommandTransition = 18,
69  kRivenCommandRefreshCard = 19,
70  kRivenCommandBeginScreenUpdate = 20,
71  kRivenCommandApplyScreenUpdate = 21,
72  kRivenCommandIncrementVariable = 24,
73  kRivenCommandChangeStack = 27,
74  kRivenCommandDisableMovie = 28,
75  kRivenCommandDisableAllMovies = 29,
76  kRivenCommandEnableMovie = 31,
77  kRivenCommandPlayMovieBlocking = 32,
78  kRivenCommandPlayMovie = 33,
79  kRivenCommandStopMovie = 34,
80  kRivenCommandUnk36 = 36,
81  kRivenCommandFadeAmbientSounds = 37,
82  kRivenCommandStoreMovieOpcode = 38,
83  kRivenCommandActivatePLST = 39,
84  kRivenCommandActivateSLST = 40,
85  kRivenCommandActivateMLSTAndPlay = 41,
86  kRivenCommandActivateBLST = 43,
87  kRivenCommandActivateFLST = 44,
88  kRivenCommandZipMode = 45,
89  kRivenCommandActivateMLST = 46,
90  kRivenCommandTimer = 1001
91 };
92 
93 class MohawkEngine_Riven;
94 class RivenCommand;
95 class RivenScript;
96 class RivenScriptManager;
97 struct MLSTRecord;
98 
99 typedef Common::SharedPtr<RivenScript> RivenScriptPtr;
100 typedef Common::SharedPtr<RivenCommand> RivenCommandPtr;
101 
108 class RivenScript {
109 public:
110  RivenScript();
111  ~RivenScript();
112 
114  void addCommand(RivenCommandPtr command);
115 
117  bool empty() const;
118 
125  void run(RivenScriptManager *scriptManager);
126 
128  void dumpScript(byte tabs);
129 
131  void applyCardPatches(MohawkEngine_Riven *vm, uint32 cardGlobalId, uint16 scriptType, uint16 hotspotId);
132 
134  RivenScript &operator+=(const RivenScript &other);
135 
137  static const char *getTypeName(uint16 type);
138 
139 private:
141 };
142 
144 RivenScriptPtr &operator+=(RivenScriptPtr &lhs, const RivenScriptPtr &rhs);
145 
152  uint16 type;
153  RivenScriptPtr script;
154 };
155 
157 
165 public:
168 
170  RivenScriptPtr readScript(Common::ReadStream *stream);
171 
178  RivenScriptPtr readScriptFromData(uint16 *data, uint16 size);
179 
181  RivenScriptPtr createScriptFromData(uint commandCount, ...);
182 
188  RivenScriptPtr createScriptWithCommand(RivenCommand *command);
189 
191  RivenScriptList readScripts(Common::ReadStream *stream);
192 
194  void runScript(const RivenScriptPtr &script, bool queue);
195 
197  bool hasQueuedScripts() const;
198 
200  void runQueuedScripts();
201 
208  bool runningQueuedScripts() const;
209 
218  void stopAllScripts();
219 
221  bool stoppingAllScripts() const;
222 
224  RivenScriptPtr script;
225  uint32 time;
226  uint16 slot;
227  };
228 
229  uint16 getStoredMovieOpcodeSlot() { return _storedMovieOpcode.slot; }
230  uint32 getStoredMovieOpcodeTime() { return _storedMovieOpcode.time; }
231  void setStoredMovieOpcode(const StoredMovieOpcode &op);
232  void runStoredMovieOpcode();
233  void clearStoredMovieOpcode();
234 
235 private:
236  MohawkEngine_Riven *_vm;
237 
239  bool _runningQueuedScripts;
240  bool _stoppingAllScripts;
241 
242  StoredMovieOpcode _storedMovieOpcode;
243 
244  RivenCommandPtr readCommand(Common::ReadStream *stream);
245 };
246 
253 public:
255  virtual ~RivenCommand();
256 
258  virtual void dump(byte tabs) = 0;
259 
261  virtual void execute() = 0;
262 
264  virtual RivenCommandType getType() const = 0;
265 
267  virtual void applyCardPatches(uint32 globalId, int scriptType, uint16 hotspotId) {}
268 
269 protected:
270  MohawkEngine_Riven *_vm;
271 };
272 
281 public:
282  static RivenSimpleCommand *createFromStream(MohawkEngine_Riven *vm, RivenCommandType type, Common::ReadStream *stream);
283 
285 
286  RivenSimpleCommand(MohawkEngine_Riven *vm, RivenCommandType type, const ArgumentArray &arguments);
287  ~RivenSimpleCommand() override;
288 
289  // RivenCommand API
290  void dump(byte tabs) override;
291  void execute() override;
292  RivenCommandType getType() const override;
293 
294 private:
295  typedef void (RivenSimpleCommand::*OpcodeProcRiven)(uint16 op, const ArgumentArray &args);
296  struct RivenOpcode {
297  OpcodeProcRiven proc;
298  const char *desc;
299  };
300 
301 
302  void setupOpcodes();
303  Common::String describe() const;
304 
305  void activateMLST(const MLSTRecord &mlst) const;
306 
307  DECLARE_OPCODE(empty) { warning ("Unknown Opcode %04x", op); }
308 
309  // Opcodes
310  DECLARE_OPCODE(drawBitmap);
311  DECLARE_OPCODE(switchCard);
312  DECLARE_OPCODE(playScriptSLST);
313  DECLARE_OPCODE(playSound);
314  DECLARE_OPCODE(setVariable);
315  DECLARE_OPCODE(enableHotspot);
316  DECLARE_OPCODE(disableHotspot);
317  DECLARE_OPCODE(stopSound);
318  DECLARE_OPCODE(changeCursor);
319  DECLARE_OPCODE(delay);
320  DECLARE_OPCODE(runExternalCommand);
321  DECLARE_OPCODE(transition);
322  DECLARE_OPCODE(refreshCard);
323  DECLARE_OPCODE(beginScreenUpdate);
324  DECLARE_OPCODE(applyScreenUpdate);
325  DECLARE_OPCODE(incrementVariable);
326  DECLARE_OPCODE(disableMovie);
327  DECLARE_OPCODE(disableAllMovies);
328  DECLARE_OPCODE(enableMovie);
329  DECLARE_OPCODE(playMovieBlocking);
330  DECLARE_OPCODE(playMovie);
331  DECLARE_OPCODE(stopMovie);
332  DECLARE_OPCODE(unk_36);
333  DECLARE_OPCODE(fadeAmbientSounds);
334  DECLARE_OPCODE(storeMovieOpcode);
335  DECLARE_OPCODE(activatePLST);
336  DECLARE_OPCODE(activateSLST);
337  DECLARE_OPCODE(activateMLSTAndPlay);
338  DECLARE_OPCODE(activateBLST);
339  DECLARE_OPCODE(activateFLST);
340  DECLARE_OPCODE(zipMode);
341  DECLARE_OPCODE(activateMLST);
342 
343  const RivenOpcode *_opcodes;
344 
345  RivenCommandType _type;
346  ArgumentArray _arguments;
347 };
348 
358 public:
359  static RivenSwitchCommand *createFromStream(MohawkEngine_Riven *vm, Common::ReadStream *stream);
360  ~RivenSwitchCommand() override;
361 
362  // RivenCommand API
363  void dump(byte tabs) override;
364  void execute() override;
365  RivenCommandType getType() const override;
366  void applyCardPatches(uint32 globalId, int scriptType, uint16 hotspotId) override;
367 
368 private:
370 
371  struct Branch {
372  uint16 value;
373  RivenScriptPtr script;
374  };
375 
376  uint16 _variableId;
377  Common::Array<Branch> _branches;
378 };
379 
388 public:
389  RivenStackChangeCommand(MohawkEngine_Riven *vm, uint16 stackId, uint32 globalCardId,
390  bool byStackId, bool byStackCardId);
391 
392  static RivenStackChangeCommand *createFromStream(MohawkEngine_Riven *vm, Common::ReadStream *stream);
393  ~RivenStackChangeCommand() override;
394 
395  // RivenCommand API
396  void dump(byte tabs) override;
397  void execute() override;
398  RivenCommandType getType() const override;
399 
400 private:
401  uint16 _stackId;
402  uint32 _cardId;
403  bool _byStackId; // Otherwise by stack name id
404  bool _byStackCardId; // Otherwise by global card id
405 };
406 
414 public:
416 
417  // RivenCommand API
418  void dump(byte tabs) override;
419  void execute() override;
420  RivenCommandType getType() const override;
421 
422 private:
424 };
425 
426 } // End of namespace Mohawk
427 
428 #undef DECLARE_OPCODE
429 
430 #endif
Definition: riven_scripts.h:223
Definition: str.h:59
Definition: riven_scripts.h:357
void warning(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: array.h:52
Definition: riven_scripts.h:387
Definition: riven_scripts.h:413
Definition: riven.h:91
virtual void applyCardPatches(uint32 globalId, int scriptType, uint16 hotspotId)
Definition: riven_scripts.h:267
Definition: riven_scripts.h:164
Definition: algorithm.h:29
Definition: riven_scripts.h:108
Definition: riven_scripts.h:280
Definition: stream.h:385
Definition: riven_scripts.h:252
Definition: riven_card.h:203
RivenScriptPtr & operator+=(RivenScriptPtr &lhs, const RivenScriptPtr &rhs)
Definition: riven_scripts.h:151
Definition: bitmap.h:32