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