ScummVM API documentation
dragons.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 #ifndef DRAGONS_DRAGONS_H
22 #define DRAGONS_DRAGONS_H
23 
24 #include "gui/EventRecorder.h"
25 #include "engines/engine.h"
26 #include "dragons/specialopcodes.h"
27 #include "dragons/detection.h"
28 
29 namespace Dragons {
30 
31 struct SaveHeader {
32  Common::String description;
33  uint32 version;
34  uint32 flags;
35  uint32 saveDate;
36  uint32 saveTime;
37  uint32 playTime;
38  Graphics::Surface *thumbnail;
39 };
40 
41 enum kReadSaveHeaderError {
42  kRSHENoError = 0,
43  kRSHEInvalidType = 1,
44  kRSHEInvalidVersion = 2,
45  kRSHEIoError = 3
46 };
47 
48 enum Flags : uint {
49  ENGINE_FLAG_1 = 1,
50  ENGINE_FLAG_2 = 2,
51  ENGINE_FLAG_4 = 4,
52  ENGINE_FLAG_8 = 8,
53  ENGINE_FLAG_10 = 0x10,
54  ENGINE_FLAG_20 = 0x20,
55  ENGINE_FLAG_40 = 0x40,
56  ENGINE_FLAG_80 = 0x80, // Inventory bag visible
57  ENGINE_FLAG_100 = 0x100,
58  ENGINE_FLAG_200 = 0x200,
59  ENGINE_FLAG_400 = 0x400,
60  ENGINE_FLAG_800 = 0x800,
61  ENGINE_FLAG_1000_SUBTITLES_DISABLED = 0x1000,
62  ENGINE_FLAG_8000 = 0x8000, // speech dialog is playing.
63 
64  ENGINE_FLAG_10000 = 0x10000,
65  ENGINE_FLAG_20000 = 0x20000,
66  ENGINE_FLAG_80000 = 0x80000,
67  ENGINE_FLAG_100000 = 0x100000,
68  ENGINE_FLAG_200000 = 0x200000,
69  ENGINE_FLAG_400000 = 0x400000,
70  ENGINE_FLAG_2000000 = 0x2000000,
71  ENGINE_FLAG_4000000 = 0x4000000,
72  ENGINE_FLAG_8000000 = 0x8000000,
73  ENGINE_FLAG_20000000 = 0x20000000,
74  ENGINE_FLAG_80000000 = 0x80000000 //Flicker idle animation running.
75 };
76 
77 enum UnkFlags {
78  ENGINE_UNK1_FLAG_1 = 1,
79  ENGINE_UNK1_FLAG_2 = 2,
80  ENGINE_UNK1_FLAG_4 = 4,
81  ENGINE_UNK1_FLAG_8 = 8,
82  ENGINE_UNK1_FLAG_10 = 0x10,
83  ENGINE_UNK1_FLAG_20 = 0x20,
84  ENGINE_UNK1_FLAG_40 = 0x40,
85  ENGINE_UNK1_FLAG_80 = 0x80
86 };
87 
88 enum MouseWheel {
89  MOUSE_WHEEL_NO_EVENT,
90  MOUSE_WHEEL_DOWN,
91  MOUSE_WHEEL_UP
92 };
93 
95  int16 paletteType;
96  int16 startOffset;
97  int16 endOffset;
98  int16 updateInterval;
99  int16 updateCounter;
100 };
101 
102 enum DragonsAction {
103  kDragonsActionNone,
104  kDragonsActionUp,
105  kDragonsActionDown,
106  kDragonsActionLeft,
107  kDragonsActionRight,
108  kDragonsActionSquare,
109  kDragonsActionTriangle,
110  kDragonsActionCircle,
111  kDragonsActionCross,
112  kDragonsActionL1,
113  kDragonsActionR1,
114  kDragonsActionSelect,
115  kDragonsActionChangeCommand,
116  kDragonsActionInventory,
117  kDragonsActionEnter,
118  kDragonsActionMenu,
119  kDragonsActionPause,
120  kDragonsActionDebug,
121  kDragonsActionDebugGfx,
122  kDragonsActionQuit
123 };
124 
125 class BigfileArchive;
127 class Cursor;
128 class Credits;
129 class DragonFLG;
130 class DragonImg;
131 class DragonOBD;
132 class DragonRMS;
133 class DragonVAR;
134 class DragonINIResource;
135 class FontManager;
136 class Inventory;
137 class Scene;
138 class Screen;
139 class ActorManager;
140 class Actor;
141 class SequenceOpcodes;
142 class ScriptOpcodes;
143 class Talk;
144 class SoundManager;
145 class StrPlayer;
146 struct DragonINI;
147 
149  Actor *flames[10];
150  uint16 quads[10];
151  int16 baseYOffset;
152  int16 flameOffsetIdx;
153  int16 loadingFlamesUpdateCounter;
154  int16 loadingFlamesRiseCounter;
155 
157  baseYOffset = 0;
158  flameOffsetIdx = 0;
159  loadingFlamesUpdateCounter = 0;
160  loadingFlamesRiseCounter = 0;
161 
162  memset(flames, 0, ARRAYSIZE(flames)*sizeof(flames[0]));
163  memset(quads, 0, ARRAYSIZE(quads)*sizeof(quads[0]));
164  }
165 };
166 
167 class DragonsEngine : public Engine {
168 public:
169  DragonOBD *_dragonOBD;
170  DragonImg *_dragonImg;
171  DragonRMS *_dragonRMS;
172  ActorManager *_actorManager;
173  DragonINIResource *_dragonINIResource;
174  FontManager *_fontManager;
175  ScriptOpcodes *_scriptOpcodes;
176  Scene *_scene;
177  uint16 _flickerInitialSceneDirection;
178  Inventory *_inventory;
179  Cursor *_cursor;
180  Credits *_credits;
181  Talk *_talk;
182  SoundManager *_sound;
183  StrPlayer *_strPlayer;
184 
185  PaletteCyclingInstruction _paletteCyclingTbl[8];
186 
187  bool _isLoadingDialogAudio;
188  uint16 _videoFlags; // TODO move to screen?
189 
190  void loadCurrentSceneMsf();
191 
192  Screen *_screen;
193  uint16 _sceneId1; //TODO wire this up. I think it might be where to restore save game from?
194 
195 private:
196  Common::Language _language;
197  BigfileArchive *_bigfileArchive;
198  DragonFLG *_dragonFLG;
199  DragonVAR *_dragonVAR;
200  BackgroundResourceLoader *_backgroundResourceLoader;
201  SequenceOpcodes *_sequenceOpcodes;
202  uint32 _nextUpdatetime;
203  uint32 _flags;
204  uint32 _unkFlags1;
205  Common::Point _cursorPosition;
206  uint32 _flickerIdleCounter;
207  uint32 _bit_flags_8006fbd8;
208  //unk
209 
210  uint16 _run_func_ptr_unk_countdown_timer;
211 
212  uint32 _randomState;
213 
214  LoadingScreenState *_loadingScreenState;
215 
216  // input
217  bool _leftMouseButtonUp;
218  bool _leftMouseButtonDown;
219  bool _rightMouseButtonUp;
220  bool _iKeyUp;
221  bool _downKeyDown;
222  bool _downKeyUp;
223  bool _upKeyDown;
224  bool _upKeyUp;
225  bool _enterKeyUp;
226 
227  bool _leftKeyDown;
228  bool _leftKeyUp;
229  bool _rightKeyDown;
230  bool _rightKeyUp;
231  bool _wKeyDown;
232  bool _aKeyDown;
233  bool _sKeyDown;
234  bool _dKeyDown;
235  bool _oKeyDown;
236  bool _pKeyDown;
237  MouseWheel _mouseWheel;
238 
239  bool _debugMode;
240  bool _isGamePaused;
241  bool _inMenu;
242 
243  void (*_sceneUpdateFunction)();
244  void (*_vsyncUpdateFunction)();
245 protected:
246  bool hasFeature(EngineFeature f) const override;
247 public:
248  DragonsEngine(OSystem *syst, const ADGameDescription *desc);
249  ~DragonsEngine();
250 
251  void updateEvents();
252  Common::Error run() override;
253 
254  Common::String getSavegameFilename(int num);
255  static Common::String getSavegameFilename(const Common::String &target, int num);
256  static kReadSaveHeaderError readSaveHeader(Common::SeekableReadStream *in, SaveHeader &header, bool skipThumbnail = true);
257 
258  Common::Error loadGameState(int slot) override;
259  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
260  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave) override;
261  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
262  void syncSoundSettings() override;
263 
264  void updateActorSequences();
265  void setFlags(uint32 flags);
266  void clearFlags(uint32 flags);
267  uint32 getMultipleFlags(uint32 flags);
268  uint32 getAllFlags();
269  void setAllFlags(uint32 flags);
270  bool isFlagSet(uint32 flag);
271  bool isUnkFlagSet(uint32 flag);
272 
273  void setUnkFlags(uint32 flags);
274  void clearUnkFlags(uint32 flags);
275 
276  byte *getBackgroundPalette();
277  DragonINI *getINI(uint32 index);
278  uint16 getVar(uint16 offset);
279  void setVar(uint16 offset, uint16 value);
280  uint16 getCurrentSceneId() const;
281 
282  void waitForFrames(uint16 numFrames);
283  void waitForFramesAllowSkip(uint16 numFrames);
284 
285 
286  void playOrStopSound(uint16 soundId);
287 
288  void fadeFromBlack();
289  void fadeFromBlackExcludingFont();
290  void fadeFromBlack(uint32 flags);
291 
292  void fadeToBlack();
293  void fadeToBlackExcludingFont();
294  void fadeToBlack(uint32 flags);
295 
296  uint16 ipt_img_file_related();
297  void performAction();
298 
299  void reset_screen_maybe();
300 
301  void init();
302  void loadScene(uint16 sceneId);
303 
304  void reset();
305 
306  void runSceneUpdaterFunction();
307  void setSceneUpdateFunction(void (*newUpdateFunction)());
308  void clearSceneUpdateFunction();
309  void (*getSceneUpdateFunction())();
310 
311  void setVsyncUpdateFunction(void (*newUpdateFunction)());
312  bool isVsyncUpdaterFunctionRunning();
313  void runVsyncUpdaterFunction();
314 
315  bool isActionButtonPressed();
316  bool isLeftKeyPressed();
317  bool isRightKeyPressed();
318  bool isUpKeyPressed();
319  bool isDownKeyPressed();
320  bool isSquareButtonPressed();
321  bool isTriangleButtonPressed();
322  bool isCircleButtonPressed();
323  bool isCrossButtonPressed();
324  bool isL1ButtonPressed();
325  bool isR1ButtonPressed();
326  bool checkForActionButtonRelease();
327  bool checkForDownKeyRelease();
328  bool checkForUpKeyRelease();
329  bool checkForWheelUp();
330  bool checkForWheelDown();
331 
332  bool isDebugMode();
333 
334  uint16 getRand(uint16 max);
335 
336  void setupPalette1();
337 
338  bool isInMenu();
339 
340  void loadingScreenUpdate();
341 
342  void clearAllText();
343 
344  //TODO this logic should probably go in its own class.
345  uint16 getBigFileTotalRecords();
346  uint32 getBigFileInfoTblFromDragonEXE();
347  uint32 getFontOffsetFromDragonEXE();
348  uint32 getSpeechTblOffsetFromDragonEXE();
349  uint32 getCutscenePaletteOffsetFromDragonEXE();
350  uint32 defaultResponseOffsetFromDragonEXE();
351  uint16 getCursorHandPointerSequenceID();
352  uint32 getMiniGame3StartingDialog();
353  uint32 getMiniGame3PickAHatDialog();
354  uint32 getMiniGame3DataOffset();
355  uint32 getDialogTextId(uint32 textId);
356 private:
357  bool savegame(const char *filename, const char *description);
358  bool loadgame(const char *filename);
359  void gameLoop();
360  void updateHandler();
361  void updatePathfindingActors();
362  void updatePaletteCycling();
363  void updateFlickerIdleAnimation();
364  void updateCamera();
365 
366  uint32 calulateTimeLeft();
367  void wait();
368  uint16 getIniFromImg();
369  void runINIScripts();
370  void engineFlag0x20UpdateFunction();
371 
372 
373  bool isInputEnabled();
374  bool checkForInventoryButtonRelease();
375 
376  void walkFlickerToObject();
377 
378  void seedRandom(int32 seed);
379  uint32 shuffleRandState();
380 
381  void initializeSound();
382 
383  void SomeInitSound_fun_8003f64c();
384 
385  void initSubtitleFlag();
386 
387  void loadingScreen();
388 
389  void mainMenu();
390 
391  bool checkAudioVideoFiles();
392  bool validateAVFile(const char *filename);
393 
394  uint32 getDialogTextIdGrb(uint32 textId);
395  uint32 getDialogTextIdDe(uint32 textId);
396  uint32 getDialogTextIdFr(uint32 textId);
397 };
398 
399 DragonsEngine *getEngine();
400 
401 } // End of namespace Dragons
402 
403 #endif //DRAGONS_DRAGONS_H
#define ARRAYSIZE(x)
Definition: util.h:91
Definition: dragons.h:31
Definition: dragons.h:148
Definition: str.h:59
Definition: background.h:36
Definition: surface.h:66
Definition: dragonflg.h:49
EngineFeature
Definition: engine.h:250
Definition: dragonini.h:64
Definition: bigfile.h:42
Definition: scene.h:41
Definition: error.h:84
Definition: advancedDetector.h:120
Definition: credits.h:33
Definition: sound.h:49
Definition: stream.h:745
Definition: actor.h:85
Definition: sequenceopcodes.h:57
Definition: screen.h:67
Definition: dragonobd.h:30
Definition: dragonvar.h:30
Definition: dragonrms.h:42
Definition: ustr.h:57
Definition: inventory.h:46
Definition: rect.h:45
bool skipThumbnail(Common::SeekableReadStream &in)
Definition: strplayer.h:30
Definition: actor.h:26
Definition: actor.h:59
Definition: system.h:175
Definition: scriptopcodes.h:54
Definition: font.h:52
Definition: dragonini.h:43
Definition: engine.h:143
Definition: cursor.h:34
Definition: dragons.h:167
Definition: dragons.h:94
Definition: talk.h:49
Definition: dragonimg.h:42
Language
Definition: language.h:45