ScummVM API documentation
3dck.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 FREESCAPE_GAMES_3DCK_H
23 #define FREESCAPE_GAMES_3DCK_H
24 
25 #include "freescape/freescape.h"
26 #include "freescape/language/execution_3dck16.h"
27 
28 namespace Freescape {
29 
30 class KitEngine : public FreescapeEngine {
31 public:
32  KitEngine(OSystem *syst, const ADGameDescription *gd);
33 
34  void loadAssets() override;
35  void initGameState() override;
36  void gotoArea(uint16 areaID, int entranceID) override;
37  void checkIfStillInArea() override;
38  bool checkIfGameEnded() override;
39  void borderScreen() override {}
40  void drawUI() override;
41  bool handleInput(const Common::Event &event) override;
42  void updatePlayerMovement(float deltaTime) override;
43  void updateTimeVariables() override;
44  void updateScripts() override;
45  bool executeObjectConditions(GeometricObject *obj, bool shot, bool collided, bool activated) override;
46  void executeLocalGlobalConditions(bool shot, bool collided, bool timer) override {}
47  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return false; }
48  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override { return false; }
49 
50 private:
51  struct ObjectData;
52  struct ScriptState : FCLKit16ExecutionState {
53  ObjectData *object = nullptr;
54  uint16 area = 0;
55  byte events = 0;
56  };
57 
58  struct ConditionData {
59  Common::String name;
60  FCLInstructionVector condition;
61  ScriptState script;
62  };
63 
64  struct SensorData {
65  byte colors[2] = {};
66  uint16 interval = 0;
67  uint16 range = 0;
68  uint16 unknown = 0;
69  uint16 directions = 0;
70  };
71 
72  struct ObjectData {
73  uint16 id = 0;
74  byte type = 0;
75  byte flags = 0;
76  uint16 state = 0;
77  Math::Vector3d origin, size, initialOrigin;
78  Common::Array<uint16> members;
80  FCLInstructionVector condition;
81  SensorData sensor;
82  ScriptState script;
83  Common::Array<uint16> animatedObjects;
84  uint16 animator = 0;
85  };
86 
87  struct AreaData {
89  Common::Array<uint16> objectOrder;
91  };
92 
93  struct ScriptEntry {
94  ScriptState *script;
95  bool resume;
96  ScriptEntry(ScriptState *s, bool r) : script(s), resume(r) {}
97  };
98 
99  void loadWorld(Common::SeekableReadStream &file);
100  void loadSounds(Common::SeekableReadStream &file);
101  void playPendingSound();
102  Area *loadArea(Common::SeekableReadStream &file);
103  Object *loadObject(Common::SeekableReadStream &file, ObjectData &data);
105  void resetScripts();
106  void startScript(ScriptState &script);
107  void beginScriptFrame();
108  FCLExecutionResult executeCode(ScriptState &script, uint &budget);
109  void executeIfThenElse(const FCLInstruction &instruction, ScriptState &script);
110  void executeConditional(const FCLInstruction &instruction, ScriptState &script);
111  void executeSetVariable(const FCLInstruction &instruction, ScriptState &script);
112  void executeIncrementVariable(const FCLInstruction &instruction, ScriptState &script);
113  void executeDecrementVariable(const FCLInstruction &instruction, ScriptState &script);
114  void executeAndVariable(const FCLInstruction &instruction, ScriptState &script);
115  void executeOrVariable(const FCLInstruction &instruction, ScriptState &script);
116  void executeNotVariable(const FCLInstruction &instruction, ScriptState &script);
117  void executeVariableComparison(const FCLInstruction &instruction, ScriptState &script);
118  void executeObjectStatus(const FCLInstruction &instruction);
119  bool checkObjectStatus(const FCLInstruction &instruction);
120  void executeGetPosition(const FCLInstruction &instruction);
121  bool executeCall(const FCLInstruction &instruction, ScriptState &script);
122  bool executeGoto(const FCLInstruction &instruction);
123  void executeMode(const FCLInstruction &instruction);
124  bool executeDelay(const FCLInstruction &instruction);
125  void executeLoop(const FCLInstruction &instruction, ScriptState &script);
126  bool executeAgain(ScriptState &script, uint32 ip);
127  void executeStartAnim(const FCLInstruction &instruction);
128  void executeStopAnim(const FCLInstruction &instruction);
129  void executeTriggerAnim(const FCLInstruction &instruction);
130  void executeInclude(const FCLInstruction &instruction, ScriptState &script);
131  void executeRemove(const FCLInstruction &instruction, ScriptState &script);
132  bool executeWaitTrigger(ScriptState &script, uint32 ip);
133  void executeMove(const FCLInstruction &instruction, ScriptState &script);
134  void executeSound(const FCLInstruction &instruction);
135  void readSystemVariables();
136  void writeSystemVariables();
137  void setScriptVariable(byte index, uint32 value);
138  void setVariableResult(const FCLInstruction &instruction, ScriptState &script, uint32 value);
139  int32 getVariableOrConstant(int32 operand, Token::Type type) const;
140  void getObjectReference(const FCLInstruction &instruction, uint16 &area, uint16 &id) const;
141  ObjectData *scriptObject(uint16 area, uint16 id);
142  ObjectData *scriptAnimator(const FCLInstruction &instruction);
143  void collectObjects(uint16 area, uint16 id, Common::Array<uint16> &objects);
144  void setObjectStatus(uint16 area, uint16 id, Token::Type operation);
145  bool moveAnimation(ScriptState &script, Math::Vector3d movement, bool absolute);
146  void updateInteractions();
147  void interact(bool shot);
148  void printMessage(uint16 indicator, const Common::String &message);
149  void updateIndicators();
150  uint32 indicatorColor(byte color) const;
151 
153  Common::Array<ConditionData> _globalConditions;
154  Common::Array<uint16> _indicatorData;
155  Common::Array<uint16> _controlData;
156 
157  byte _palette[256 * 3];
158  uint16 _initialPlayerHeight;
159  uint16 _initialCondition = 0, _timerInterval = 0, _activationRange = 0;
160  uint32 _kitVariables[256] = {};
161  uint32 _changedVariables = 0;
162  uint32 _scriptTicks = 0, _timerTicks = 0, _delayUntil = 0;
163  int _lastScriptTick = 0;
164  bool _timerTriggered = false, _initialScriptPending = false;
165  bool _scriptFrameActive = false, _scriptDelayed = false;
166  int _pendingSound = -1;
167  byte _pendingInteractions = 0, _shootCooldown = 0, _activateCooldown = 0;
168  uint _scriptQueueIndex = 0;
169  Common::Array<ScriptEntry> _scriptQueue;
170  Common::Array<ScriptState *> _suspendedScripts;
171  Graphics::ManagedSurface _scriptSurface;
172 };
173 
174 } // namespace Freescape
175 
176 #endif
Definition: geometricobject.h:34
Definition: managed_surface.h:51
Definition: str.h:59
Definition: area.h:36
Definition: advancedDetector.h:164
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: 3dck.h:48
Definition: area.h:41
Definition: execution_3dck16.h:36
Definition: stream.h:745
Definition: freescape.h:191
Definition: ustr.h:57
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: 3dck.h:47
Definition: events.h:218
Definition: object.h:56
Definition: system.h:166
Definition: instruction.h:49
Definition: 3dck.h:30