ScummVM API documentation
script.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 VCRUISE_SCRIPT_H
23 #define VCRUISE_SCRIPT_H
24 
25 #include "common/array.h"
26 #include "common/hashmap.h"
27 #include "common/path.h"
28 #include "common/ptr.h"
29 #include "common/types.h"
30 
31 namespace Common {
32 
33 class ReadStream;
34 
35 } // End of namespace Common
36 
37 namespace VCruise {
38 
39 struct ScreenScriptSet;
40 struct RoomScriptSet;
41 struct ScriptSet;
42 struct ITextPreprocessor;
43 
44 namespace ScriptOps {
45 
46 enum ScriptOp {
47  kInvalid,
48 
49  kNumber,
50 
51  kRotate,
52  kAngle,
53  kAngleGGet,
54  kSpeed,
55  kSAnimL,
56  kChangeL,
57  kAnimR,
58  kAnimF,
59  kAnimN,
60  kAnimG,
61  kAnimS,
62  kAnim,
63  kStatic,
64  kVarLoad,
65  kVarStore,
66  kVarAddAndStore,
67  kVarGlobalLoad,
68  kVarGlobalStore,
69  kItemCheck,
70  kItemHaveSpace,
71  kItemRemove,
72  kItemHighlightSet,
73  kItemAdd,
74  kItemClear,
75  kSetCursor,
76  kSetRoom,
77  kLMB,
78  kLMB1,
79  kSoundS1,
80  kSoundS2,
81  kSoundS3,
82  kSoundL1,
83  kSoundL2,
84  kSoundL3,
85  k3DSoundS2,
86  k3DSoundL2,
87  k3DSoundL3,
88  kStopAL,
89  kRange,
90  kAddXSound,
91  kClrXSound,
92  kStopSndLA,
93  kStopSndLO,
94  kMusic,
95  kMusicVolRamp,
96  kParm0,
97  kParm1,
98  kParm2,
99  kParm3,
100  kParmG,
101  kSParmX,
102  kSAnimX,
103  kVolumeDn2,
104  kVolumeDn3,
105  kVolumeDn4,
106  kVolumeUp3,
107  kRandom,
108  kDrop,
109  kDup,
110  kSwap,
111  kSay1,
112  kSay2,
113  kSay3,
114  kSay3Get,
115  kSetTimer,
116  kGetTimer,
117  kDelay,
118  kLoSet,
119  kLoGet,
120  kHiSet,
121  kHiGet,
122 
123  kNot,
124  kAnd,
125  kOr,
126  kSub,
127  kAdd,
128  kNegate,
129  kCmpEq,
130  kCmpLt,
131  kCmpGt,
132 
133  kBitLoad,
134  kBitSet0,
135  kBitSet1,
136 
137  kDisc1,
138  kDisc2,
139  kDisc3,
140 
141  kGoto,
142 
143  kEscOn,
144  kEscOff,
145  kEscGet,
146  kBackStart,
147  kSaveAs,
148  kSave0,
149  kExit,
150  kAllowSaves,
151 
152  kAnimName,
153  kValueName,
154  kVarName,
155  kSoundName,
156  kCursorName,
157  kDubbing,
158 
159  kCheckValue, // Check if stack top is equal to arg. If it is, pop the argument, otherwise leave it on the stack and skip the next instruction.
160  kJump, // Offset instruction index by arg.
161 
162  // Schizm ops
163  kCallFunction,
164  kMusicStop,
165  kMusicPlayScore,
166  kScoreAlways,
167  kScoreNormal,
168  kSndPlay,
169  kSndPlayEx,
170  kSndPlay3D,
171  kSndPlaying,
172  kSndWait,
173  kSndHalt,
174  kSndToBack,
175  kSndStop,
176  kSndStopAll,
177  kSndAddRandom,
178  kSndClearRandom,
179  kVolumeAdd,
180  kVolumeChange,
181  kAnimVolume,
182  kAnimChange,
183  kScreenName,
184  kExtractByte,
185  kInsertByte,
186  kString,
187  kCmpNE,
188  kCmpLE,
189  kCmpGE,
190  kReturn,
191  kSpeech,
192  kSpeechEx,
193  kSpeechTest,
194  kSay,
195  kRandomInclusive,
196  kHeroOut,
197  kHeroGetPos,
198  kHeroSetPos,
199  kHeroGet,
200  kGarbage,
201  kGetRoom,
202  kBitAnd,
203  kBitOr,
204  kAngleGet,
205  kIsCDVersion,
206  kIsDVDVersion,
207  kDisc,
208  kHidePanel,
209  kRotateUpdate,
210  kMul,
211  kDiv,
212  kMod,
213  kGetDigit,
214  kPuzzleInit,
215  kPuzzleCanPress,
216  kPuzzleDoMove1,
217  kPuzzleDoMove2,
218  kPuzzleDone,
219  kPuzzleWhoWon,
220  kFn,
221  kItemHighlightSetTrue,
222 
223  // AD2044 ops
224  kAnimT,
225  kAnimForward,
226  kAnimReverse,
227  kAnimKForward,
228  kNoUpdate,
229  kNoClear,
230  kSay1_AD2044,
231  kSay2_AD2044,
232  kSay1Rnd,
233  kM,
234  kEM,
235  kSE,
236  kSDot,
237  kE,
238  kDot,
239  kSound,
240  kISound,
241  kUSound,
242  kSay2K,
243  kSay3K,
244  kRGet,
245  kRSet,
246  kEndRSet,
247  kStop,
248 
249  kNumOps,
250 };
251 
252 } // End of namespace ScriptOps
253 
254 struct Instruction {
255  Instruction();
256  explicit Instruction(ScriptOps::ScriptOp paramOp);
257  Instruction(ScriptOps::ScriptOp paramOp, int32 paramArg);
258 
259  ScriptOps::ScriptOp op;
260  int32 arg;
261 };
262 
263 struct Script {
265 };
266 
271 
273  Common::SharedPtr<Script> entryScript;
274  ScriptMap_t interactionScripts;
275 };
276 
278  ScreenScriptSetMap_t screenScripts;
279  ScreenNameMap_t screenNames;
280 };
281 
282 struct ScriptSet {
283  ScriptSet();
284 
285  RoomScriptSetMap_t roomScripts;
286 
288  Common::Array<Common::String> functionNames;
290 };
291 
292 struct FunctionDef {
293  Common::String fnName;
295 };
296 
297 // Global state is required for Schizm because its preprocessor defines exist across files.
298 // For example, volPortWaves is set in Room01 but used in Room03 and Room20
300  virtual ~IScriptCompilerGlobalState();
301 
302  virtual void define(const Common::String &key, uint roomNumber, int32 value) = 0;
303  virtual bool getDefine(const Common::String &str, uint &outRoomNumber, int32 &outValue) const = 0;
304 
305  virtual uint getFunctionIndex(const Common::String &fnName) = 0;
306  virtual void setFunction(uint fnIndex, const Common::SharedPtr<Script> &fn) = 0;
307 
308  virtual uint getNumFunctions() const = 0;
309  virtual void dumpFunctionNames(Common::Array<Common::String> &fnNames) const = 0;
310  virtual Common::SharedPtr<Script> getFunction(uint fnIndex) const = 0;
311 };
312 
313 Common::SharedPtr<IScriptCompilerGlobalState> createScriptCompilerGlobalState();
314 Common::SharedPtr<ScriptSet> compileReahLogicFile(Common::ReadStream &stream, uint streamSize, const Common::Path &blamePath);
315 Common::SharedPtr<ScriptSet> compileAD2044LogicFile(Common::ReadStream &stream, uint streamSize, const Common::Path &blamePath);
316 
317 void compileSchizmLogicFile(ScriptSet &scriptSet, uint loadAsRoom, uint fileRoom, Common::ReadStream &stream, uint streamSize, const Common::Path &blamePath, IScriptCompilerGlobalState *gs);
318 bool checkSchizmLogicForDuplicatedRoom(Common::ReadStream &stream, uint streamSize);
319 void optimizeScriptSet(ScriptSet &scriptSet);
320 
321 }
322 
323 #endif
Definition: str.h:59
Definition: script.h:277
Definition: array.h:52
Definition: script.h:272
Definition: path.h:52
Definition: script.h:282
Definition: ad2044_items.h:27
Definition: script.h:263
Definition: hashmap.h:85
Definition: algorithm.h:29
Definition: script.h:299
Definition: script.h:292
Definition: stream.h:385
Definition: script.h:254