ScummVM API documentation
dgds.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 DGDS_DGDS_H
23 #define DGDS_DGDS_H
24 
25 #include "common/error.h"
26 #include "common/events.h"
27 #include "common/platform.h"
28 #include "common/random.h"
29 #include "common/serializer.h"
30 
31 #include "graphics/surface.h"
32 #include "graphics/managed_surface.h"
33 
34 #include "engines/advancedDetector.h"
35 #include "engines/engine.h"
36 
37 #include "gui/debugger.h"
38 
39 #include "dgds/resource.h"
40 #include "dgds/clock.h"
41 #include "dgds/menu.h"
42 
43 
44 namespace Dgds {
45 
46 class Console;
47 class ResourceManager;
48 class Decompressor;
49 class Image;
50 class GamePalettes;
51 class FontManager;
52 class Inventory;
53 class SDSScene;
54 class GDSScene;
55 class Sound;
56 class REQFileData;
57 class Menu;
58 struct DgdsADS;
59 class ADSInterpreter;
60 class Globals;
61 class ShellGame;
62 class DragonArcade;
63 class HocIntro;
64 class ChinaTank;
65 class ChinaTrain;
66 
67 const float MS_PER_FRAME = 16.6667f;
68 
69 enum DgdsGameId {
70  GID_DRAGON,
71  GID_HOC,
72  GID_WILLY,
73  GID_SQ5DEMO,
74  GID_COMINGATTRACTIONS,
75  GID_QUARKY,
76  GID_CASTAWAY,
77  GID_INVALID,
78 };
79 
80 enum DgdsDetailLevel {
81  kDgdsDetailLow = 0,
82  kDgdsDetailHigh = 1
83 };
84 
85 enum DgdsKeyEvent {
86  kDgdsKeyLoad,
87  kDgdsKeySave,
88  kDgdsKeyToggleMenu,
89  kDgdsKeyToggleClock,
90  kDgdsKeyNextChoice,
91  kDgdsKeyPrevChoice,
92  kDgdsKeyNextItem,
93  kDgdsKeyPrevItem,
94  kDgdsKeyPickUp,
95  kDgdsKeyLook,
96  kDgdsKeyActivate,
97 };
98 
99 enum DgdsMouseCursor {
100  kDgdsMouseGameDefault = -1,
101  kDgdsMouseWait = -2,
102  kDgdsMouseLook = -3,
103 };
104 
105 // TODO: Enable keymapper for dragon arcade sequences
106 /*
107 enum DragonArcadeKeyEvent {
108  kDragonArcadeKeyLeft,
109  kDragonArcadeKeyRight,
110  kDragonArcadeKeyUp,
111  kDragonArcadeKeyDown,
112  kDragonArcadeKeyLeftUp,
113  kDragonArcadeKeyRightUp,
114  kDragonArcadeKeyLeftDown,
115  kDragonArcadeKeyRightDown,
116  kDragonArcadeKeyJumpMode,
117  kDragonArcadeKeyFire,
118 };
119 */
120 
121 
122 class DgdsEngine : public Engine {
123 public:
124  Sound *_soundPlayer;
125  Graphics::ManagedSurface _compositionBuffer;
126 
127  static const byte HOC_CHAR_SWAP_ICONS[];
128 
129 private:
130  Common::Platform _platform;
131  Common::Language _gameLang;
132 
133  Console *_console;
134 
135  ResourceManager *_resource;
136  Decompressor *_decompressor;
137 
138  DgdsGameId _gameId;
139  Graphics::ManagedSurface _backgroundBuffer;
140  Common::String _backgroundFile; // Record the background file name for save games.
141  Graphics::ManagedSurface _storedAreaBuffer;
142  SDSScene *_scene;
143  GDSScene *_gdsScene;
144  Menu *_menu;
145 
146  ADSInterpreter *_adsInterp;
147  GamePalettes *_gamePals;
148  Globals *_gameGlobals;
149  Inventory *_inventory;
150 
151  // Dragon only
152  DragonArcade *_dragonArcade;
153 
154  // HoC only
155  ShellGame *_shellGame;
156  HocIntro *_hocIntro;
157  ChinaTank *_chinaTank;
158  ChinaTrain *_chinaTrain;
159 
160  FontManager *_fontManager;
161  Common::SharedPtr<Image> _corners;
163 
164  // Settings which we should integrate with ScummVM settings UI
165  DgdsDetailLevel _detailLevel;
166  int _textSpeed;
167  int _difficulty;
168 
169  bool _justChangedScene1;
170  // There is another flag in Rise of the Dragon, but it seems to never be used for anything?
171  //bool _justChangedScene2;
172 
173  Common::RandomSource _random;
174  Common::Point _lastMouse; // originals start mouse at 0,0.
175  Common::EventType _lastMouseEvent; // a pending mouse event to process.
176  int _currentCursor;
177  Common::Point _currentCursorHot;
178 
179  Clock _clock;
180 
181  MenuId _menuToTrigger;
182 
183  bool _isLoading;
184  const char *_rstFileName;
185 
186  bool _isDemo;
187  bool _isEGA;
188  bool _isAltDlgColors;
189  bool _flipMode;
190  uint32 _thisFrameMs;
191  int16 _lastGlobalFade; // Only used in Willy Beamish
192  uint _lastGlobalFadedPal; // Only used in Willy Beamish
193 
194  bool _debugShowHotAreas;
195 
196 public:
197  DgdsEngine(OSystem *syst, const ADGameDescription *gameDesc);
198  virtual ~DgdsEngine();
199 
200  virtual Common::Error run() override;
201 
202  void restartGame();
203 
204  DgdsGameId getGameId() const { return _gameId; }
205  Common::Language getGameLang() const { return _gameLang; }
206  Common::Platform getPlatform() const { return _platform; }
207 
208  Graphics::ManagedSurface &getBackgroundBuffer() { return _backgroundBuffer; }
209  Graphics::ManagedSurface &getStoredAreaBuffer() { return _storedAreaBuffer; }
210 
211  // Various game engine singletons
212  Common::SeekableReadStream *getResource(const Common::String &name, bool ignorePatches);
213  ResourceManager *getResourceManager() { return _resource; }
214  Decompressor *getDecompressor() { return _decompressor; }
215  const SDSScene *getScene() const { return _scene; }
216  SDSScene *getScene() { return _scene; }
217  GDSScene *getGDSScene() { return _gdsScene; }
218  const FontManager *getFontMan() const { return _fontManager; }
219  const Common::SharedPtr<Image> &getUICorners() { return _corners; }
220  const Common::SharedPtr<Image> &getIcons() { return _icons; }
221  GamePalettes *getGamePals() { return _gamePals; }
222  Globals *getGameGlobals() { return _gameGlobals; }
223  Inventory *getInventory() { return _inventory; }
224  Clock &getClock() { return _clock; }
225  ADSInterpreter *adsInterpreter() { return _adsInterp; }
226  Common::RandomSource &getRandom() { return _random; }
227 
228  bool changeScene(int sceneNum);
229  void setMouseCursor(int num);
230 
231  int getTextSpeed() const { return _textSpeed; }
232  void setTextSpeed(int16 speed) { _textSpeed = speed; }
233  int16 getDifficulty() const { return _difficulty; }
234  void setDifficulty(int16 difficulty) { _difficulty = difficulty; }
235  DgdsDetailLevel getDetailLevel() const { return _detailLevel; }
236  void setDetailLevel(DgdsDetailLevel level) { _detailLevel = level; }
237 
238  void setShowClock(bool val);
239  bool justChangedScene1() const { return _justChangedScene1; }
240  Common::Point getLastMouse() const { return _lastMouse; }
241  Common::Point getLastMouseMinusHot() const;
242 
243  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
244  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
245  bool canSaveAutosaveCurrently() override;
246 
247  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override {
248  Common::Serializer s(nullptr, stream);
249  return syncGame(s);
250  }
251 
253  Common::Serializer s(stream, nullptr);
254  return syncGame(s);
255  }
256 
257  bool hasFeature(EngineFeature f) const override {
258  return
259  (f == kSupportsReturnToLauncher) ||
262  };
263 
264  void setBackgroundFile(const Common::String &name) { _backgroundFile = name; }
265  const Common::String &getBackgroundFile() const { return _backgroundFile; }
266  void setMenuToTrigger(MenuId menu) { _menuToTrigger = menu; }
267  bool isInvButtonVisible() const;
268  ShellGame *getShellGame() { return _shellGame; }
269  HocIntro *getHocIntro() { return _hocIntro; }
270  ChinaTrain *getChinaTrain() { return _chinaTrain; }
271  ChinaTank *getChinaTank() { return _chinaTank; }
272  DragonArcade *getDragonArcade() { return _dragonArcade; }
273  uint32 getThisFrameMs() const { return _thisFrameMs; }
274 
275  static DgdsEngine *getInstance() { return static_cast<DgdsEngine *>(g_engine); }
276  void setFlipMode(bool mode) { _flipMode = mode; }
277 
278  bool isEGA() const { return _isEGA; }
279  bool isDemo() const { return _isDemo; }
280  bool isAltDlgColors() const { return _isAltDlgColors; }
281 
282  void enableKeymapper();
283  void disableKeymapper();
284 
285  void setDebugShowHotAreas(bool enable) { _debugShowHotAreas = enable; }
286  bool getDebugShowHotAreas() const { return _debugShowHotAreas; }
287 
288  static void dumpFrame(const Graphics::ManagedSurface &surf, const char *name);
289 
290  void dimPalForWillyDialog(bool force);
291 
292 private:
293  Common::Error syncGame(Common::Serializer &s);
294 
295  void loadCorners(const Common::String &filename);
296  void loadIcons();
297  void checkDrawInventoryButton();
298 
299  void init(bool restarting);
300  void loadGameFiles();
301  void loadRestartFile();
302  void pumpMessages();
303 };
304 
305 } // End of namespace Dgds
306 
307 #endif // DGDS_DGDS_H
Definition: managed_surface.h:51
Definition: str.h:59
EngineFeature
Definition: engine.h:253
Definition: game_palettes.h:45
Definition: stream.h:77
Definition: error.h:84
Definition: advancedDetector.h:163
EventType
Definition: events.h:49
Definition: globals.h:81
Definition: inventory.h:37
Definition: random.h:44
Definition: ads.h:28
Definition: sound.h:51
Definition: hoc_intro.h:33
Definition: stream.h:745
Engine * g_engine
Definition: serializer.h:79
Definition: console.h:31
Definition: engine.h:267
Definition: ads.h:63
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave=false) override
Definition: dgds.h:247
bool canSaveAutosaveCurrently() override
bool hasFeature(EngineFeature f) const override
Definition: dgds.h:257
virtual Common::Error run() override
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: menu.h:75
Definition: clock.h:39
Definition: ustr.h:57
Definition: china_tank.h:28
Definition: scene.h:271
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: rect.h:45
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Definition: dgds.h:252
Definition: dragon_arcade.h:85
Definition: dgds.h:122
Definition: system.h:161
Definition: ptr.h:159
Definition: scene.h:214
Definition: movie_decoder.h:32
Definition: font.h:99
Definition: engine.h:285
Definition: engine.h:144
Definition: decompress.h:67
Definition: china_train.h:159
Platform
Definition: platform.h:46
Definition: shell_game.h:30
Language
Definition: language.h:45
Definition: resource.h:49