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 // TODO: Enable keymapper for dragon arcade sequences
100 /*
101 enum DragonArcadeKeyEvent {
102  kDragonArcadeKeyLeft,
103  kDragonArcadeKeyRight,
104  kDragonArcadeKeyUp,
105  kDragonArcadeKeyDown,
106  kDragonArcadeKeyLeftUp,
107  kDragonArcadeKeyRightUp,
108  kDragonArcadeKeyLeftDown,
109  kDragonArcadeKeyRightDown,
110  kDragonArcadeKeyJumpMode,
111  kDragonArcadeKeyFire,
112 };
113 */
114 
115 
116 class DgdsEngine : public Engine {
117 public:
118  Common::Platform _platform;
119  Common::Language _gameLang;
120  Sound *_soundPlayer;
121  Graphics::ManagedSurface _compositionBuffer;
122 
123  static const byte HOC_CHAR_SWAP_ICONS[];
124 
125 private:
126  Console *_console;
127 
128  ResourceManager *_resource;
129  Decompressor *_decompressor;
130 
131  DgdsGameId _gameId;
132  Graphics::ManagedSurface _backgroundBuffer;
133  Common::String _backgroundFile; // Record the background file name for save games.
134  Graphics::ManagedSurface _storedAreaBuffer;
135  SDSScene *_scene;
136  GDSScene *_gdsScene;
137  Menu *_menu;
138 
139  ADSInterpreter *_adsInterp;
140  GamePalettes *_gamePals;
141  Globals *_gameGlobals;
142  Inventory *_inventory;
143 
144  // Dragon only
145  DragonArcade *_dragonArcade;
146 
147  // HoC only
148  ShellGame *_shellGame;
149  HocIntro *_hocIntro;
150  ChinaTank *_chinaTank;
151  ChinaTrain *_chinaTrain;
152 
153  FontManager *_fontManager;
154  Common::SharedPtr<Image> _corners;
156 
157  // Settings which we should integrate with ScummVM settings UI
158  DgdsDetailLevel _detailLevel;
159  int _textSpeed;
160  int _difficulty;
161 
162  bool _justChangedScene1;
163  bool _justChangedScene2;
164 
165  Common::RandomSource _random;
166  Common::Point _lastMouse; // originals start mouse at 0,0.
167  int _currentCursor;
168  Common::Point _currentCursorHot;
169 
170  Clock _clock;
171 
172  MenuId _menuToTrigger;
173 
174  bool _isLoading;
175  const char *_rstFileName;
176 
177  bool _isDemo;
178  bool _isEGA;
179  bool _flipMode;
180  bool _skipNextFrame;
181  uint32 _thisFrameMs;
182  int16 _lastGlobalFade; // Only used in Willy Beamish
183  uint _lastGlobalFadedPal;
184 
185 public:
186  DgdsEngine(OSystem *syst, const ADGameDescription *gameDesc);
187  virtual ~DgdsEngine();
188 
189  virtual Common::Error run() override;
190 
191  void restartGame();
192 
193  DgdsGameId getGameId() const { return _gameId; }
194  Common::Language getGameLang() const { return _gameLang; }
195  Common::Platform getPlatform() const { return _platform; }
196 
197  Graphics::ManagedSurface &getBackgroundBuffer() { return _backgroundBuffer; }
198  Graphics::ManagedSurface &getStoredAreaBuffer() { return _storedAreaBuffer; }
199 
200  // Various game engine singletons
201  Common::SeekableReadStream *getResource(const Common::String &name, bool ignorePatches);
202  ResourceManager *getResourceManager() { return _resource; }
203  Decompressor *getDecompressor() { return _decompressor; }
204  const SDSScene *getScene() const { return _scene; }
205  SDSScene *getScene() { return _scene; }
206  GDSScene *getGDSScene() { return _gdsScene; }
207  const FontManager *getFontMan() const { return _fontManager; }
208  const Common::SharedPtr<Image> &getUICorners() { return _corners; }
209  const Common::SharedPtr<Image> &getIcons() { return _icons; }
210  GamePalettes *getGamePals() { return _gamePals; }
211  Globals *getGameGlobals() { return _gameGlobals; }
212  Inventory *getInventory() { return _inventory; }
213  Clock &getClock() { return _clock; }
214  ADSInterpreter *adsInterpreter() { return _adsInterp; }
215  Common::RandomSource &getRandom() { return _random; }
216 
217  bool changeScene(int sceneNum);
218  void setMouseCursor(int num);
219 
220  int getTextSpeed() const { return _textSpeed; }
221  void setTextSpeed(int16 speed) { _textSpeed = speed; }
222  int16 getDifficulty() const { return _difficulty; }
223  void setDifficulty(int16 difficulty) { _difficulty = difficulty; }
224  DgdsDetailLevel getDetailLevel() const { return _detailLevel; }
225  void setDetailLevel(DgdsDetailLevel level) { _detailLevel = level; }
226 
227  void setShowClock(bool val);
228  bool justChangedScene1() const { return _justChangedScene1; }
229  bool justChangedScene2() const { return _justChangedScene2; }
230  Common::Point getLastMouse() const { return _lastMouse; }
231  Common::Point getLastMouseMinusHot() const;
232 
233  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
234  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
235  bool canSaveAutosaveCurrently() override;
236 
237  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override {
238  Common::Serializer s(nullptr, stream);
239  return syncGame(s);
240  }
241 
243  Common::Serializer s(stream, nullptr);
244  return syncGame(s);
245  }
246 
247  bool hasFeature(EngineFeature f) const override {
248  return
249  (f == kSupportsReturnToLauncher) ||
252  };
253 
254  void setBackgroundFile(const Common::String &name) { _backgroundFile = name; }
255  const Common::String &getBackgroundFile() const { return _backgroundFile; }
256  void setMenuToTrigger(MenuId menu) { _menuToTrigger = menu; }
257  bool isInvButtonVisible() const;
258  ShellGame *getShellGame() { return _shellGame; }
259  HocIntro *getHocIntro() { return _hocIntro; }
260  ChinaTrain *getChinaTrain() { return _chinaTrain; }
261  ChinaTank *getChinaTank() { return _chinaTank; }
262  DragonArcade *getDragonArcade() { return _dragonArcade; }
263  void setSkipNextFrame() { _skipNextFrame = true; }
264  uint32 getThisFrameMs() const { return _thisFrameMs; }
265 
266  static DgdsEngine *getInstance() { return static_cast<DgdsEngine *>(g_engine); }
267  void setFlipMode(bool mode) { _flipMode = mode; }
268 
269  bool isEGA() const { return _isEGA; }
270 
271  void enableKeymapper();
272  void disableKeymapper();
273 
274 private:
275  Common::Error syncGame(Common::Serializer &s);
276 
277  void loadCorners(const Common::String &filename);
278  void loadIcons();
279  void checkDrawInventoryButton();
280 
281  void init(bool restarting);
282  void loadGameFiles();
283  void loadRestartFile();
284 };
285 
286 } // End of namespace Dgds
287 
288 #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
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:237
bool canSaveAutosaveCurrently() override
bool hasFeature(EngineFeature f) const override
Definition: dgds.h:247
virtual Common::Error run() override
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: menu.h:73
Definition: clock.h:39
Definition: ustr.h:57
Definition: china_tank.h:28
Definition: scene.h:430
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: rect.h:45
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Definition: dgds.h:242
Definition: dragon_arcade.h:85
Definition: dgds.h:116
Definition: system.h:161
Definition: ptr.h:159
Definition: scene.h:373
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:28
Platform
Definition: platform.h:46
Definition: shell_game.h:30
Language
Definition: language.h:45
Definition: resource.h:49