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 // keep the order in sync with ScriptOpNames/KernelCallNames in script-debug.h
39 
40 enum 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 
74 enum 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  SayTextV2, // TODO: Reverse engineer this variant
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 };
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  Common::String procedureAt(uint32 pc) 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  void fixNestedMenuPop(uint32 pc);
180 private:
181  friend struct ScriptTask;
182  friend struct ScriptTimerTask;
185  Common::Array<ScriptInstruction> _instructions;
186  Common::Array<int32> _variables;
188  uint32 _scriptTimer = 0;
189 };
190 
191 }
192 
193 #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