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 ALCACHOFA_SCRIPT_H
23#define ALCACHOFA_SCRIPT_H
24
25#include "alcachofa/common.h"
26
27#include "common/hashmap.h"
28#include "common/span.h"
29#include "common/stream.h"
30#include "common/system.h"
31
32namespace Alcachofa {
33
34class Process;
35
36// the ScriptOp and ScriptKernelTask enums represent the *implemented* order
37// the specific Game instance maps the version-specific op codes to our order
38// keep the order in sync with ScriptOpNames/KernelCallNames in script-debug.h
39
40enum class ScriptOp {
41 Nop,
42 Dup,
43 PushAddr,
44 PushDynAddr,
45 PushValue,
46 Deref,
47 Pop1,
48 PopN,
49 Store,
50 LoadString,
51 ScriptCall,
52 KernelCall,
53 JumpIfFalse,
54 JumpIfTrue,
55 Jump,
56 Negate,
57 BooleanNot,
58 Mul,
59 Add,
60 Sub,
61 Less,
62 Greater,
63 LessEquals,
64 GreaterEquals,
65 Equals,
66 NotEquals,
67 BitAnd,
68 BitOr,
69 ReturnValue,
70 ReturnVoid,
71 Crash
72};
73
74enum class ScriptKernelTask {
75 Nop = 0,
76 PlayVideo,
77 PlaySound,
78 PlayMusic,
79 StopMusic,
80 WaitForMusicToEnd,
81 ShowCenterBottomText,
82 StopAndTurn,
83 StopAndTurnMe,
84 ChangeCharacter,
85 SayText,
86 SayTextOnlySound, // only used in secta with subtitles turned off...
87 Go,
88 Put,
89 ChangeCharacterRoom,
90 KillProcesses,
91 LerpCharacterLodBias,
92 On,
93 Off,
94 Pickup,
95 CharacterPickup,
96 Drop,
97 CharacterDrop,
98 Delay,
99 HadNoMousePressFor,
100 Fork,
101 Animate,
102 AnimateCharacter,
103 AnimateTalking,
104 ChangeRoom,
105 ToggleRoomFloor,
106 SetDialogLineReturn,
107 DialogMenu,
108 ClearInventory,
109 FadeType0,
110 FadeType1,
111 LerpWorldLodBias,
112 FadeType2,
113 SetActiveTextureSet,
114 SetMaxCamSpeedFactor,
115 WaitCamStopping,
116 CamFollow,
117 CamShake,
118 LerpCamXY,
119 LerpCamZ,
120 LerpCamScale,
121 LerpCamToObjectWithScale,
122 LerpCamToObjectResettingZ,
123 LerpCamRotation,
124 LerpOrSetCam, // only V1 and V2
125 FadeIn,
126 FadeOut,
127 FadeIn2,
128 FadeOut2,
129 LerpCamXYZ,
130 LerpCamToObjectKeepingZ,
131 Disguise,
132 WaitForMouseClick // only V2.1
133};
134
135enum class ScriptFlags {
136 None = 0,
137 AllowMissing = (1 << 0),
138 IsBackground = (1 << 1)
139};
140inline ScriptFlags operator | (ScriptFlags a, ScriptFlags b) {
141 return (ScriptFlags)(((uint)a) | ((uint)b));
142}
143inline bool operator & (ScriptFlags a, ScriptFlags b) {
144 return ((uint)a) & ((uint)b);
145}
146
149
150 int32 _op;
151 int32 _arg;
152};
153
154class Script {
155public:
156 Script();
157
158 void syncGame(Common::Serializer &s);
159 int32 variable(const char *name) const;
160 int32 &variable(const char *name);
161 Process *createProcess(
162 MainCharacterKind character,
163 const Common::String &procedure,
164 ScriptFlags flags = ScriptFlags::None);
165 Process *createProcess(
166 MainCharacterKind character,
167 const Common::String &behavior,
168 const Common::String &action,
169 ScriptFlags flags = ScriptFlags::None);
170 bool hasProcedure(const Common::String &behavior, const Common::String &action) const;
171 bool hasProcedure(const Common::String &procedure) const;
172 Common::String procedureAt(uint32 pc) const;
173
174 using VariableNameIterator = Common::HashMap<Common::String, uint32>::const_iterator;
175 inline VariableNameIterator beginVariables() const { return _variableNames.begin(); }
176 inline VariableNameIterator endVariables() const { return _variableNames.end(); }
177 inline bool hasVariable(const char *name) const { return _variableNames.contains(name); }
178
179 void setScriptTimer(bool reset);
180 void fixNestedMenuPop(uint32 pc);
181private:
182 friend struct ScriptTask;
183 friend struct ScriptTimerTask;
186 _procedures; // In CORVINO there are some mixed-case character names but upper-case procedures
188 Common::Array<int32> _variables;
190 uint32 _scriptTimer = 0;
191};
192
193}
194
195#endif // ALCACHOFA_SCRIPT_H
Definition: scheduler.h:164
Definition: script.h:154
Definition: array.h:52
Definition: stream.h:385
Definition: serializer.h:80
Definition: span.h:893
Definition: str.h:59
bool contains(const Key &key) const
Definition: hashmap.h:598
Definition: script.h:147
int32 _op
int32 because it still has to be mapped using a game-specific translation table
Definition: script.h:150