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  Go,
86  Put,
87  ChangeCharacterRoom,
88  KillProcesses,
89  LerpCharacterLodBias,
90  On,
91  Off,
92  Pickup,
93  CharacterPickup,
94  Drop,
95  CharacterDrop,
96  Delay,
97  HadNoMousePressFor,
98  Fork,
99  Animate,
100  AnimateCharacter,
101  AnimateTalking,
102  ChangeRoom,
103  ToggleRoomFloor,
104  SetDialogLineReturn,
105  DialogMenu,
106  ClearInventory,
107  FadeType0,
108  FadeType1,
109  LerpWorldLodBias,
110  FadeType2,
111  SetActiveTextureSet,
112  SetMaxCamSpeedFactor,
113  WaitCamStopping,
114  CamFollow,
115  CamShake,
116  LerpCamXY,
117  LerpCamZ,
118  LerpCamScale,
119  LerpCamToObjectWithScale,
120  LerpCamToObjectResettingZ,
121  LerpCamRotation,
122  FadeIn,
123  FadeOut,
124  FadeIn2,
125  FadeOut2,
126  LerpCamXYZ,
127  LerpCamToObjectKeepingZ,
128 
129  SheriffTakesCharacter,
130  ChangeDoor,
131  Disguise
132 };
133 
134 enum class ScriptFlags {
135  None = 0,
136  AllowMissing = (1 << 0),
137  IsBackground = (1 << 1)
138 };
139 inline ScriptFlags operator | (ScriptFlags a, ScriptFlags b) {
140  return (ScriptFlags)(((uint)a) | ((uint)b));
141 }
142 inline bool operator & (ScriptFlags a, ScriptFlags b) {
143  return ((uint)a) & ((uint)b);
144 }
145 
148 
149  int32 _op;
150  int32 _arg;
151 };
152 
153 class Script {
154 public:
155  Script();
156 
157  void syncGame(Common::Serializer &s);
158  int32 variable(const char *name) const;
159  int32 &variable(const char *name);
160  Process *createProcess(
161  MainCharacterKind character,
162  const Common::String &procedure,
163  ScriptFlags flags = ScriptFlags::None);
164  Process *createProcess(
165  MainCharacterKind character,
166  const Common::String &behavior,
167  const Common::String &action,
168  ScriptFlags flags = ScriptFlags::None);
169  bool hasProcedure(const Common::String &behavior, const Common::String &action) const;
170  bool hasProcedure(const Common::String &procedure) const;
171 
172  using VariableNameIterator = Common::HashMap<Common::String, uint32>::const_iterator;
173  inline VariableNameIterator beginVariables() const { return _variableNames.begin(); }
174  inline VariableNameIterator endVariables() const { return _variableNames.end(); }
175  inline bool hasVariable(const char *name) const { return _variableNames.contains(name); }
176 
177  void setScriptTimer(bool reset);
178 private:
179  friend struct ScriptTask;
180  friend struct ScriptTimerTask;
183  Common::Array<ScriptInstruction> _instructions;
184  Common::Array<int32> _variables;
186  uint32 _scriptTimer = 0;
187 };
188 
189 }
190 
191 #endif // ALCACHOFA_SCRIPT_H
Definition: alcachofa.h:45
Definition: str.h:59
Definition: scheduler.h:164
Definition: array.h:52
Definition: script.h:153
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:149
Definition: stream.h:385
Definition: script.h:146