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 enum class ScriptOp {
37  Nop,
38  Dup,
39  PushAddr,
40  PushValue,
41  Deref,
42  Crash5,
43  PopN,
44  Store,
45  Crash8,
46  Crash9,
47  LoadString,
48  LoadString2,
49  Crash12,
50  ScriptCall,
51  KernelCall,
52  JumpIfFalse,
53  JumpIfTrue,
54  Jump,
55  Negate,
56  BooleanNot,
57  Mul,
58  Crash21,
59  Crash22,
60  Add,
61  Sub,
62  Less,
63  Greater,
64  LessEquals,
65  GreaterEquals,
66  Equals,
67  NotEquals,
68  BitAnd,
69  BitOr,
70  Crash33,
71  Crash34,
72  Crash35,
73  Crash36,
74  Return
75 };
76 
77 enum class ScriptKernelTask {
78  PlayVideo = 1,
79  PlaySound,
80  PlayMusic,
81  StopMusic,
82  WaitForMusicToEnd,
83  ShowCenterBottomText,
84  StopAndTurn,
85  StopAndTurnMe,
86  ChangeCharacter,
87  SayText,
88  Nop10,
89  Go,
90  Put,
91  ChangeCharacterRoom,
92  KillProcesses,
93  LerpCharacterLodBias,
94  On,
95  Off,
96  Pickup,
97  CharacterPickup,
98  Drop,
99  CharacterDrop,
100  Delay,
101  HadNoMousePressFor,
102  Nop24,
103  Fork,
104  Animate,
105  AnimateCharacter,
106  AnimateTalking,
107  ChangeRoom,
108  ToggleRoomFloor,
109  SetDialogLineReturn,
110  DialogMenu,
111  ClearInventory,
112  Nop34,
113  FadeType0,
114  FadeType1,
115  LerpWorldLodBias,
116  FadeType2,
117  SetActiveTextureSet,
118  SetMaxCamSpeedFactor,
119  WaitCamStopping,
120  CamFollow,
121  CamShake,
122  LerpCamXY,
123  LerpCamZ,
124  LerpCamScale,
125  LerpCamToObjectWithScale,
126  LerpCamToObjectResettingZ,
127  LerpCamRotation,
128  FadeIn,
129  FadeOut,
130  FadeIn2,
131  FadeOut2,
132  LerpCamXYZ,
133  LerpCamToObjectKeepingZ
134 };
135 
136 enum class ScriptFlags {
137  None = 0,
138  AllowMissing = (1 << 0),
139  IsBackground = (1 << 1)
140 };
141 inline ScriptFlags operator | (ScriptFlags a, ScriptFlags b) {
142  return (ScriptFlags)(((uint)a) | ((uint)b));
143 }
144 inline bool operator & (ScriptFlags a, ScriptFlags b) {
145  return ((uint)a) & ((uint)b);
146 }
147 
150 
151  ScriptOp _op;
152  int32 _arg;
153 };
154 
155 class Script {
156 public:
157  Script();
158 
159  void syncGame(Common::Serializer &s);
160  void updateCommonVariables();
161  int32 variable(const char *name) const;
162  int32 &variable(const char *name);
163  Process *createProcess(
164  MainCharacterKind character,
165  const Common::String &procedure,
166  ScriptFlags flags = ScriptFlags::None);
167  Process *createProcess(
168  MainCharacterKind character,
169  const Common::String &behavior,
170  const Common::String &action,
171  ScriptFlags flags = ScriptFlags::None);
172  bool hasProcedure(const Common::String &behavior, const Common::String &action) const;
173  bool hasProcedure(const Common::String &procedure) const;
174 
175  using VariableNameIterator = Common::HashMap<Common::String, uint32>::const_iterator;
176  inline VariableNameIterator beginVariables() const { return _variableNames.begin(); }
177  inline VariableNameIterator endVariables() const { return _variableNames.end(); }
178  inline bool hasVariable(const char *name) const { return _variableNames.contains(name); }
179 
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:155
Definition: span.h:893
Definition: serializer.h:79
Definition: stream.h:385
Definition: script.h:148