ScummVM API documentation
8bit.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_8BIT_H
23 #define FREESCAPE_GAMES_3DCK_8BIT_H
24 
25 #include "freescape/freescape.h"
26 #include "freescape/language/execution_3dck8.h"
27 
28 namespace Freescape {
29 
30 class Kit8Engine : public FreescapeEngine {
31 public:
32  Kit8Engine(OSystem *syst, const ADGameDescription *gd);
33 
34  void loadAssets() override;
35  void initGameState() override;
36  void gotoArea(uint16 areaID, int entranceID) override;
37  Math::Vector3d clipPosition(const Math::Vector3d &position) const override;
38  void checkIfStillInArea() override;
39  bool checkIfGameEnded() override { return false; }
40  void borderScreen() override {}
41  void drawUI() override;
42  void initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target) override;
43  bool handleInput(const Common::Event &event) override;
44  void updatePlayerMovement(float deltaTime) override;
45  void updateTimeVariables() override;
46  void checkSensors() override;
47  void updateScripts() override;
48  void playSound(int index, bool sync, Sound::Type type = Sound::kTypeNormal) override;
49  bool executeObjectConditions(GeometricObject *obj, bool shot, bool collided, bool activated) override;
50  void executeLocalGlobalConditions(bool shot, bool collided, bool timer) override {}
51  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return false; }
52  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override { return false; }
53 
54 private:
56  static const uint kFrameDuration = 100;
57 
58  struct ConditionData {
59  byte id;
60  FCLInstructionVector condition;
61  };
62 
63  struct AreaData {
64  byte palette[4];
65  Common::Array<byte> globals;
67  };
68 
70  Area *loadArea(Common::SeekableReadStream &file);
71  GeometricObject *loadGeometricObject(Common::SeekableReadStream &file, const byte header[9]);
72  void loadPresentation();
73  void loadPresentationZX();
74  void loadPresentationC64();
75  void loadSounds();
76  void loadSoundsZX();
77  void playPendingSound();
78  void applyPalette();
79  void applyPaletteZX();
80  void applyPaletteC64();
81  void setAttributesZX(const Common::Rect &rect, byte color);
82  void setMovementMode(byte mode);
83  void readSystemVariables();
84  void writeSystemVariables();
85  void resetScripts();
86  bool isFrameReady() const { return int32(_lastTime - _nextFrameTime) >= 0; }
87  void pauseEngineIntern(bool pause) override;
88  void beginScriptFrame();
89  void startScript(ScriptState &script, const FCLInstructionVector &code);
90  FCLExecutionResult executeCode(ScriptState &script, uint &budget);
91  void executeArithmetic(const FCLInstruction &instruction, ScriptState &script);
92  void executeComparison(const FCLInstruction &instruction, ScriptState &script);
93  void executeConditional(const FCLInstruction &instruction, ScriptState &script);
94  void executeObjectStatus(const FCLInstruction &instruction);
95  void executeGoto(const FCLInstruction &instruction);
96  void executeMode(const FCLInstruction &instruction);
97  void executeCall(const FCLInstruction &instruction, ScriptState &script);
98  void executeSound(const FCLInstruction &instruction);
99  void executeColour(const FCLInstruction &instruction);
100  void getObjectReference(const FCLInstruction &instruction, uint16 &area, uint16 &id) const;
101  Object *scriptObject(uint16 area, uint16 id);
102  void interact(bool shot);
103  void printMessage(byte id, byte x, byte y);
104  void printText(const Common::String &text, byte x, byte y, byte color);
105  void updateInstruments();
106 
108  Common::Array<ConditionData> _globalConditions, _procedures;
110  ScriptState _script;
111  const Common::Array<ConditionData> *_activeConditions = nullptr;
112  uint _conditionIndex = 0;
113  bool _initialScriptPending = true, _scriptFrameActive = false, _globalPhase = false;
114  bool _redrawPending = false;
115  byte _kitVariables[128] = {};
116  uint16 _changedVariables = 0;
117  byte _currentKey = 255;
118  byte _palette[4] = {};
119  byte _colorPatterns[15][4] = {};
120  byte _zxPalette[16 * 3] = {};
121  byte _borderAttributes[32 * 24] = {}, _attributes[32 * 24] = {};
122  byte _instruments[8][6] = {};
123  byte _textColor = 7, _movementMode = 1;
124  bool _textOutputEnabled = false;
125  byte _climbHeight = 0, _fallHeight = 0, _walkSpeed = 0, _activationRange = 0;
126  byte _shotObject = 0, _hitObject = 0, _activatedObject = 0;
127  bool _fallen = false, _crushed = false, _crossVisible = true;
128  bool _timerTriggered = false, _pendingTimer = false;
129  byte _pendingSound = 0;
130  bool _soundSyncReady = false;
131  uint32 _lastTime = 0, _timerTicks = 0, _timerInterval = 0, _delayUntil = 0;
132  uint32 _nextFrameTime = 0, _pauseStartTime = 0;
133  byte _fontData[96][8] = {};
134  bool _hasFont = false;
135  Graphics::ManagedSurface _scriptSurface, _overlaySurface, _borderSurface;
136 };
137 
138 } // namespace Freescape
139 
140 #endif
Definition: geometricobject.h:34
Definition: managed_surface.h:51
Definition: execution_3dck8.h:30
Definition: keymap.h:66
Definition: str.h:59
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: 8bit.h:51
Definition: area.h:36
Definition: advancedDetector.h:164
Definition: rect.h:536
Definition: area.h:41
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: 8bit.h:52
Definition: stream.h:745
Definition: freescape.h:191
Definition: ustr.h:57
Definition: 8bit.h:30
Definition: events.h:218
Definition: object.h:56
Definition: system.h:166
Definition: instruction.h:49