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 
32 namespace Alcachofa {
33 
34 class 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 
39 enum class ScriptOp {
40  Nop,
41  Dup,
42  PushAddr,
43  PushDynAddr,
44  PushValue,
45  Deref,
46  Pop1,
47  PopN,
48  Store,
49  LoadString,
50  ScriptCall,
51  KernelCall,
52  JumpIfFalse,
53  JumpIfTrue,
54  Jump,
55  Negate,
56  BooleanNot,
57  Mul,
58  Add,
59  Sub,
60  Less,
61  Greater,
62  LessEquals,
63  GreaterEquals,
64  Equals,
65  NotEquals,
66  BitAnd,
67  BitOr,
68  ReturnValue,
69  ReturnVoid,
70  Crash
71 };
72 
73 enum class ScriptKernelTask {
74  Nop = 0,
75  PlayVideo,
76  PlaySound,
77  PlayMusic,
78  StopMusic,
79  WaitForMusicToEnd,
80  ShowCenterBottomText,
81  StopAndTurn,
82  StopAndTurnMe,
83  ChangeCharacter,
84  SayText,
85  SayTextV2, // TODO: Reverse engineer this variant
86  Go,
87  Put,
88  ChangeCharacterRoom,
89  KillProcesses,
90  LerpCharacterLodBias,
91  On,
92  Off,
93  Pickup,
94  CharacterPickup,
95  Drop,
96  CharacterDrop,
97  Delay,
98  HadNoMousePressFor,
99  Fork,
100  Animate,
101  AnimateCharacter,
102  AnimateTalking,
103  ChangeRoom,
104  ToggleRoomFloor,
105  SetDialogLineReturn,
106  DialogMenu,
107  ClearInventory,
108  FadeType0,
109  FadeType1,
110  LerpWorldLodBias,
111  FadeType2,
112  SetActiveTextureSet,
113  SetMaxCamSpeedFactor,
114  WaitCamStopping,
115  CamFollow,
116  CamShake,
117  LerpCamXY,
118  LerpCamZ,
119  LerpCamScale,
120  LerpCamToObjectWithScale,
121  LerpCamToObjectResettingZ,
122  LerpCamRotation,
123  LerpOrSetCam, // only V1
124  FadeIn,
125  FadeOut,
126  FadeIn2,
127  FadeOut2,
128  LerpCamXYZ,
129  LerpCamToObjectKeepingZ,
130 
131  ChangeDoor,
132  Disguise
133 };
134 
135 enum class ScriptFlags {
136  None = 0,
137  AllowMissing = (1 << 0),
138  IsBackground = (1 << 1)
139 };
140 inline ScriptFlags operator | (ScriptFlags a, ScriptFlags b) {
141  return (ScriptFlags)(((uint)a) | ((uint)b));
142 }
143 inline bool operator & (ScriptFlags a, ScriptFlags b) {
144  return ((uint)a) & ((uint)b);
145 }
146 
149 
150  int32 _op;
151  int32 _arg;
152 };
153 
154 class Script {
155 public:
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 
173  using VariableNameIterator = Common::HashMap<Common::String, uint32>::const_iterator;
174  inline VariableNameIterator beginVariables() const { return _variableNames.begin(); }
175  inline VariableNameIterator endVariables() const { return _variableNames.end(); }
176  inline bool hasVariable(const char *name) const { return _variableNames.contains(name); }
177 
178  void setScriptTimer(bool reset);
179 private:
180  friend struct ScriptTask;
181  friend struct ScriptTimerTask;
184  Common::Array<ScriptInstruction> _instructions;
185  Common::Array<int32> _variables;
187  uint32 _scriptTimer = 0;
188 };
189 
190 }
191 
192 #endif // ALCACHOFA_SCRIPT_H
Definition: alcachofa.h:45
Definition: str.h:59
Definition: scheduler.h:164
Definition: array.h:52
Definition: script.h:154
Definition: span.h:893
Definition: serializer.h:79
int32 _op
int32 because it still has to be mapped using a game-specific translation table
Definition: script.h:150
Definition: stream.h:385
Definition: script.h:147