ScummVM API documentation
ultima8.h
1 
2 /* ScummVM - Graphic Adventure Engine
3  *
4  * ScummVM is the legal property of its developers, whose names
5  * are too numerous to list here. Please refer to the COPYRIGHT
6  * file distributed with this source distribution.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef ULTIMA8_ULTIMA8
24 #define ULTIMA8_ULTIMA8
25 
26 #include "common/events.h"
27 #include "common/random.h"
28 #include "common/stream.h"
29 #include "graphics/screen.h"
30 #include "ultima/shared/std/containers.h"
31 #include "ultima/ultima8/usecode/intrinsics.h"
32 #include "ultima/ultima8/misc/common_types.h"
33 #include "ultima/ultima8/games/game_info.h"
34 #include "ultima/ultima8/gfx/render_surface.h"
35 #include "ultima/ultima8/metaengine.h"
36 #include "ultima/detection.h"
37 
38 namespace Ultima {
39 namespace Ultima8 {
40 
41 class Debugger;
42 class Kernel;
43 class UCMachine;
44 class Game;
45 class Gump;
46 class GameMapGump;
47 class MenuGump;
48 class InverterGump;
49 class RenderSurface;
50 class PaletteManager;
51 class GameData;
52 class World;
53 class ObjectManager;
54 class FontManager;
55 class Mouse;
56 class AvatarMoverProcess;
57 class Texture;
58 class AudioMixer;
59 class ConfigFileManager;
60 struct GameInfo;
61 
62 #define GAME_IS_U8 (Ultima8Engine::get_instance()->getGameInfo()->_type == GameInfo::GAME_U8)
63 #define GAME_IS_REMORSE (Ultima8Engine::get_instance()->getGameInfo()->_type == GameInfo::GAME_REMORSE)
64 #define GAME_IS_REGRET (Ultima8Engine::get_instance()->getGameInfo()->_type == GameInfo::GAME_REGRET)
65 #define GAME_IS_CRUSADER (GAME_IS_REMORSE || GAME_IS_REGRET)
66 #define GAME_IS_DEMO (Ultima8Engine::get_instance()->getGameInfo()->_ucOffVariant == GameInfo::GAME_UC_DEMO)
67 
68 class Ultima8Engine : public Engine {
69  friend class Debugger;
70 private:
71  Common::RandomSource _randomSource;
72 
73  bool _isRunning;
74  GameInfo *_gameInfo;
75  const UltimaGameDescription *_gameDescription;
76 
77  // minimal system
78  ConfigFileManager *_configFileMan;
79 
80  static Ultima8Engine *_instance;
81 
82  bool _fontOverride;
83  bool _fontAntialiasing;
84  // Audio Mixer
85  AudioMixer *_audioMixer;
86  uint32 _saveCount;
87 
88  // full system
89  Game *_game;
90  Common::Error _lastError;
91 
92  Kernel *_kernel;
93  ObjectManager *_objectManager;
94  UCMachine *_ucMachine;
95  RenderSurface *_screen;
96  Mouse *_mouse;
97  PaletteManager *_paletteManager;
98  GameData *_gameData;
99  World *_world;
100  FontManager *_fontManager;
101 
102  Gump *_desktopGump;
103  GameMapGump *_gameMapGump;
104  InverterGump *_inverterGump;
105  AvatarMoverProcess *_avatarMoverProcess;
106 
107  // Various dependency flags
108  // Timing stuff
109  int32 _lerpFactor;
110  bool _inBetweenFrame;
111  uint32 _priorFrameCounterTime;
112 
113  bool _highRes;
114  bool _frameSkip;
115  bool _frameLimit;
116  bool _interpolate;
117  int32 _animationRate;
118 
119  // Sort of Camera Related Stuff, move somewhere else
120 
121  bool _avatarInStasis;
122  bool _paintEditorItems;
124  bool _showTouching;
125  int32 _timeOffset;
126  bool _hasCheated;
127  bool _cheatsEnabled;
128  unsigned int _inversion;
129  bool _crusaderTeleporting;
130  uint32 _moveKeyFrame;
131  bool _cruStasis;
132 private:
136  void showSplashScreen();
137 
139  void writeSaveInfo(Common::WriteStream *ws);
140 
142  void save(Common::WriteStream *ws);
143 
145  bool load(Common::ReadStream *rs, uint32 version);
146 
148  void resetEngine();
149 
151  void setupCoreGumps();
152 
154 // void fullReset();
155 
156  void handleDelayedEvents();
157 
158  bool pollEvent(Common::Event &event);
159 protected:
160  // Engine APIs
161  Common::Error run() override;
162 
163  Common::Error initialize();
164  void deinitialize();
165 
166  void pauseEngineIntern(bool pause) override;
167 
168 public:
169  Ultima8Engine(OSystem *syst, const Ultima::UltimaGameDescription *gameDesc);
170  ~Ultima8Engine() override;
171 
172  void initializePath(const Common::FSNode &gamePath) override;
173 
174  static Ultima8Engine *get_instance() {
175  return _instance;
176  }
177 
178  bool hasFeature(EngineFeature f) const override;
179 
180  Common::Language getLanguage() const;
181 
182  bool setupGame();
183  Common::Error startupGame();
184 
185  void changeVideoMode(int width, int height);
186 
188  const GameInfo *getGameInfo() const {
189  return _gameInfo;
190  }
191 
192  RenderSurface *getRenderScreen() {
193  return _screen;
194  }
195 
196  Graphics::Screen *getScreen() const;
197 
198  Common::Error runGame();
199  virtual void handleEvent(const Common::Event &event);
200 
201  void handleActionDown(KeybindingAction action);
202  void handleActionUp(KeybindingAction action);
203 
204  void paint();
205 
206  static const int U8_DEFAULT_SCREEN_WIDTH = 320;
207  static const int U8_DEFAULT_SCREEN_HEIGHT = 200;
208  static const int CRUSADER_DEFAULT_SCREEN_WIDTH = 640;
209  static const int CRUSADER_DEFAULT_SCREEN_HEIGHT = 480;
210 
211  static const int U8_HIRES_SCREEN_WIDTH = 640;
212  static const int U8_HIRES_SCREEN_HEIGHT = 400;
213  static const int CRUSADER_HIRES_SCREEN_WIDTH = 1024;
214  static const int CRUSADER_HIRES_SCREEN_HEIGHT = 768;
215 
216  INTRINSIC(I_getCurrentTimerTick);
217  INTRINSIC(I_setAvatarInStasis);
218  INTRINSIC(I_getAvatarInStasis);
219  INTRINSIC(I_getTimeInGameHours);
220  INTRINSIC(I_getTimeInMinutes);
221  INTRINSIC(I_getTimeInSeconds);
222  INTRINSIC(I_setTimeInGameHours);
223  INTRINSIC(I_avatarCanCheat);
224  INTRINSIC(I_getCrusaderTeleporting);
225  INTRINSIC(I_setCrusaderTeleporting);
226  INTRINSIC(I_clrCrusaderTeleporting);
227  INTRINSIC(I_makeAvatarACheater);
228  INTRINSIC(I_closeItemGumps);
229  INTRINSIC(I_setCruStasis);
230  INTRINSIC(I_clrCruStasis);
231  INTRINSIC(I_moveKeyDownRecently);
232 
233  void setAvatarInStasis(bool stat) {
234  _avatarInStasis = stat;
235  }
236  bool isAvatarInStasis() const {
237  return _avatarInStasis;
238  }
239  void toggleAvatarInStasis() {
240  _avatarInStasis = !_avatarInStasis;
241  }
242  bool isPaintEditorItems() const {
243  return _paintEditorItems;
244  }
245  void togglePaintEditorItems() {
246  _paintEditorItems = !_paintEditorItems;
247  }
248  bool isShowTouchingItems() const {
249  return _showTouching;
250  }
251  void toggleShowTouchingItems() {
252  _showTouching = !_showTouching;
253  }
254 
255  bool isCrusaderTeleporting() const {
256  return _crusaderTeleporting;
257  }
258  void setCrusaderTeleporting(bool flag) {
259  _crusaderTeleporting = flag;
260  }
261  void setCruStasis(bool flag) {
262  _cruStasis = flag;
263  }
264  bool isCruStasis() const {
265  return _cruStasis;
266  }
267 
268  void moveKeyEvent();
269  bool moveKeyDownRecently();
270 
271  uint32 getGameTimeInSeconds();
272 
273  GameMapGump *getGameMapGump() {
274  return _gameMapGump;
275  }
276  Gump *getDesktopGump() {
277  return _desktopGump;
278  }
279  Gump *getGump(uint16 gumpid);
280 
283  void addGump(Gump *gump);
284 
285  AvatarMoverProcess *getAvatarMoverProcess() {
286  return _avatarMoverProcess;
287  }
288 
289  Common::RandomSource &getRandomSource() {
290  return _randomSource;
291  }
292 
296  void syncSoundSettings() override;
297 
301  void applyGameSettings() override;
302 
306  void openConfigDialog();
307 
311  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return true; }
312 
316  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
317 
321  Common::Error loadGameState(int slot) override;
322 
326  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
327 
332 
336  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave) override;
337 
340  bool newGame(int saveSlot = -1);
341 
345 public:
346  unsigned int getInversion() const {
347  return _inversion;
348  }
349  void setInversion(unsigned int i) {
350  _inversion = i & 0xFFFF;
351  }
352  bool isInverted() {
353  return (_inversion >= 0x4000 && _inversion < 0xC000);
354  }
355 public:
356  bool areCheatsEnabled() const {
357  return _cheatsEnabled;
358  }
359  void setCheatMode(bool enabled) {
360  _cheatsEnabled = enabled;
361  }
362  bool hasCheated() const {
363  return _hasCheated;
364  }
365  void makeCheater() {
366  _hasCheated = true;
367  }
368  bool isInterpolationEnabled() const {
369  return _interpolate;
370  }
371 };
372 
373 } // End of namespace Ultima8
374 } // End of namespace Ultima
375 
376 #endif
Definition: audio_mixer.h:36
Definition: str.h:59
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave) override
EngineFeature
Definition: engine.h:253
Definition: stream.h:77
Definition: error.h:84
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Definition: object_manager.h:38
void pauseEngineIntern(bool pause) override
Definition: random.h:44
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave=false) override
Definition: render_surface.h:40
Definition: font_manager.h:41
Definition: stream.h:745
const GameInfo * getGameInfo() const
Get current GameInfo struct.
Definition: ultima8.h:188
Definition: detection.h:65
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: ultima8.h:311
Definition: screen.h:48
Definition: avatar_mover_process.h:37
Definition: gump.h:47
Definition: game_data.h:51
bool hasFeature(EngineFeature f) const override
void applyGameSettings() override
Definition: detection.h:27
Definition: world.h:72
Definition: uc_machine.h:41
Definition: ustr.h:57
Definition: palette_manager.h:34
Common::Error loadGameState(int slot) override
void initializePath(const Common::FSNode &gamePath) override
Definition: events.h:199
Definition: fs.h:69
void setError(Common::Error &error)
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: kernel.h:41
bool newGame(int saveSlot=-1)
Definition: stream.h:385
Definition: game.h:31
Common::Error run() override
Definition: debugger.h:37
Definition: system.h:161
Definition: game_map_gump.h:38
Definition: config_file_manager.h:34
Definition: ultima8.h:68
void syncSoundSettings() override
Definition: paletteman.h:47
Definition: mouse.h:73
Definition: engine.h:144
GameInfo contains detailed information about the game.
Definition: game_info.h:33
Definition: inverter_gump.h:36
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Language
Definition: language.h:45