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 DRACI_SCRIPT_H
23 #define DRACI_SCRIPT_H
24 
25 #include "common/array.h"
26 #include "common/stream.h"
27 
28 namespace Common {
29 class ReadStream;
30 }
31 
32 namespace Draci {
33 
34 enum {
37 
38  kNumCommands = 55
39 };
40 
41 class DraciEngine;
42 class Script;
43 
44 typedef void (Script::*GPLHandler)(const Common::Array<int> &);
45 typedef int (Script::*GPLOperatorHandler)(int, int) const;
46 typedef int (Script::*GPLFunctionHandler)(int) const;
47 
54  kGPL2Num = 1,
55  kGPL2Str = 2,
56  kGPL2Ident = 3,
57  kGPL2Math = 4
58 };
59 
60 struct GPL2Command {
61  byte _number;
62  byte _subNumber;
63  const char *_name;
64  uint16 _numParams;
65  GPL2ParameterType _paramTypes[kMaxParams];
66  GPLHandler _handler;
67 };
68 
69 struct GPL2Operator {
70  GPLOperatorHandler _handler;
71  const char *_name;
72 };
73 
74 struct GPL2Function {
75  GPLFunctionHandler _handler;
76  const char *_name;
77 };
78 
83 struct GPL2Program {
84  GPL2Program() : _bytecode(NULL), _length(0) {}
85 
86  byte *_bytecode;
87  uint16 _length;
88 };
89 
90 class Animation;
91 class GameObject;
92 
93 class Script {
94 
95 public:
96  Script(DraciEngine *vm) : _vm(vm), _jump(0), _endProgram(false) { setupCommandList(); }
97 
98  void run(const GPL2Program &program, uint16 offset);
99  void runWrapper(const GPL2Program &program, uint16 offset, bool disableCursor, bool releaseAnims);
100  bool testExpression(const GPL2Program &program, uint16 offset) const;
101  void endCurrentProgram(bool value) { _endProgram = value; }
102  bool shouldEndProgram() const { return _endProgram; }
103 
104 private:
105  int _jump;
106  bool _endProgram;
107 
109  const GPL2Command *_commandList;
110  const GPL2Operator *_operatorList;
111  const GPL2Function *_functionList;
112 
113  void c_If(const Common::Array<int> &params);
114  void c_Goto(const Common::Array<int> &params);
115  void c_Let(const Common::Array<int> &params);
116  void load(const Common::Array<int> &params);
117  void start(const Common::Array<int> &params);
118  void loadMusic(const Common::Array<int> &params);
119  void startMusic(const Common::Array<int> &params);
120  void stopMusic(const Common::Array<int> &params);
121  void mark(const Common::Array<int> &params);
122  void release(const Common::Array<int> &params);
123  void icoStat(const Common::Array<int> &params);
124  void objStat(const Common::Array<int> &params);
125  void objStatOn(const Common::Array<int> &params);
126  void execInit(const Common::Array<int> &params);
127  void execLook(const Common::Array<int> &params);
128  void execUse(const Common::Array<int> &params);
129  void stayOn(const Common::Array<int> &params);
130  void walkOn(const Common::Array<int> &params);
131  void walkOnPlay(const Common::Array<int> &params);
132  void play(const Common::Array<int> &params);
133  void startPlay(const Common::Array<int> &params);
134  void justTalk(const Common::Array<int> &params);
135  void justStay(const Common::Array<int> &params);
136  void newRoom(const Common::Array<int> &params);
137  void talk(const Common::Array<int> &params);
138  void loadMap(const Common::Array<int> &params);
139  void roomMap(const Common::Array<int> &params);
140  void disableQuickHero(const Common::Array<int> &params);
141  void enableQuickHero(const Common::Array<int> &params);
142  void disableSpeedText(const Common::Array<int> &params);
143  void enableSpeedText(const Common::Array<int> &params);
144  void dialogue(const Common::Array<int> &params);
145  void exitDialogue(const Common::Array<int> &params);
146  void resetDialogue(const Common::Array<int> &params);
147  void resetDialogueFrom(const Common::Array<int> &params);
148  void resetBlock(const Common::Array<int> &params);
149  void setPalette(const Common::Array<int> &params);
150  void blackPalette(const Common::Array<int> &params);
151  void fadePalette(const Common::Array<int> &params);
152  void fadePalettePlay(const Common::Array<int> &params);
153  void loadPalette(const Common::Array<int> &params);
154  void quitGame(const Common::Array<int> &params);
155  void pushNewRoom(const Common::Array<int> &params);
156  void popNewRoom(const Common::Array<int> &params);
157 
158  int operAnd(int op1, int op2) const;
159  int operOr(int op1, int op2) const;
160  int operXor(int op1, int op2) const;
161  int operSub(int op1, int op2) const;
162  int operAdd(int op1, int op2) const;
163  int operDiv(int op1, int op2) const;
164  int operMul(int op1, int op2) const;
165  int operEqual(int op1, int op2) const;
166  int operNotEqual(int op1, int op2) const;
167  int operGreater(int op1, int op2) const;
168  int operLess(int op1, int op2) const;
169  int operGreaterOrEqual(int op1, int op2) const;
170  int operLessOrEqual(int op1, int op2) const;
171  int operMod(int op1, int op2) const;
172 
173  int funcRandom(int n) const;
174  int funcNot(int n) const;
175  int funcIsIcoOn(int iconID) const;
176  int funcIcoStat(int iconID) const;
177  int funcActIco(int iconID) const;
178  int funcIsIcoAct(int iconID) const;
179  int funcIsObjOn(int objID) const;
180  int funcIsObjOff(int objID) const;
181  int funcIsObjAway(int objID) const;
182  int funcActPhase(int objID) const;
183  int funcObjStat(int objID) const;
184  int funcLastBlock(int blockID) const;
185  int funcAtBegin(int yesno) const;
186  int funcBlockVar(int blockID) const;
187  int funcHasBeen(int blockID) const;
188  int funcMaxLine(int lines) const;
189 
190  void setupCommandList();
191  const GPL2Command *findCommand(byte num, byte subnum) const;
192  int handleMathExpression(Common::ReadStream *reader) const;
193 
194  DraciEngine *_vm;
195 };
196 
197 } // End of namespace Draci
198 
199 #endif // DRACI_SCRIPT_H
Definition: draci.h:68
Definition: animation.h:59
Definition: script.h:74
Definition: script.h:36
Definition: script.h:60
Definition: script.h:93
Definition: game.h:88
Definition: algorithm.h:29
Definition: animation.h:30
Definition: stream.h:385
Definition: script.h:69
Definition: script.h:83
GPL2ParameterType
Definition: script.h:53