ScummVM API documentation
asylum.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 ASYLUM_ASYLUM_H
23 #define ASYLUM_ASYLUM_H
24 
25 #include "common/file.h"
26 #include "common/language.h"
27 #include "common/random.h"
28 #include "common/rect.h"
29 #include "common/scummsys.h"
30 #include "common/serializer.h"
31 #include "common/system.h"
32 
33 #include "engines/advancedDetector.h"
34 #include "engines/engine.h"
35 
36 #include "asylum/resources/data.h"
37 
38 #include "asylum/console.h"
39 #include "asylum/eventhandler.h"
40 #include "asylum/shared.h"
41 
51 struct ADGameDescription;
52 
53 namespace Asylum {
54 
55 class Cursor;
56 class Encounter;
57 class Menu;
58 class Puzzles;
59 class ResourceManager;
60 class Savegame;
61 class Scene;
62 class Screen;
63 class ScriptManager;
64 class Special;
65 class Speech;
66 class Sound;
67 class Text;
68 class VideoPlayer;
69 
70 class AsylumEngine: public Engine, public Common::Serializable {
71 protected:
72  // Engine APIs
73  virtual Common::Error run() override;
74  virtual bool hasFeature(EngineFeature f) const override;
75 
76 public:
77  enum StartGameType {
78  kStartGamePlayIntro,
79  kStartGameLoad,
80  kStartGameScene
81  };
82 
83  AsylumEngine(OSystem *system, const ADGameDescription *gd);
84  virtual ~AsylumEngine();
85 
89  bool startGame(ResourcePackId sceneId, StartGameType type);
90 
94  void restart();
95 
99  void handleEvents();
100 
106  void switchScene(ResourcePackId sceneId) { (void)startGame(sceneId, kStartGameScene); }
107 
113  uint32 getTick() { return _system->getMillis() + _tickOffset; }
114 
120  void setTick(uint32 offset) { _tickOffset = offset - _system->getMillis(); }
121 
125  void reset();
126 
131  uint32 lastScreenUpdate;
132 
133  // Game
134  Cursor *cursor() { return _cursor; }
135  Encounter *encounter() { return _encounter; }
136  Menu *menu() { return _menu; }
137  ResourceManager *resource() { return _resource; }
138  Savegame *savegame() { return _savegame; }
139  Scene *scene() { return _scene; }
140  Screen *screen() { return _screen; }
141  ScriptManager *script() { return _script; }
142  Special *special() { return _special; }
143  Speech *speech() { return _speech; }
144  Sound *sound() { return _sound; }
145  Text *text() { return _text; }
146  VideoPlayer *video() { return _video; }
147 
148  SharedData *data() { return &_data; }
149  Puzzles *puzzles() { return _puzzles; }
150 
151  // Flags
152  void setGameFlag(GameFlag flag);
153  void clearGameFlag(GameFlag flag);
154  void toggleGameFlag(GameFlag flag);
155  bool isGameFlagSet(GameFlag flag) const;
156  bool isGameFlagNotSet(GameFlag flag) const;
157  bool areGameFlagsSet(uint from, uint to) const;
158  void resetFlags() { memset(_gameFlags, 0, sizeof(_gameFlags)); }
159 
160  // Misc
161  uint getRandom(uint max) { return max ? _rnd->getRandomNumber(max - 1) : 0; }
162  uint getRandomBit() { return _rnd->getRandomBit(); }
163 
164  bool rectContains(const int16 (*rectPtr)[4], const Common::Point &p) const;
165 
166  // Steam achievements
167  void unlockAchievement(const Common::String &id);
168  void checkAchievements();
169 
175  void switchEventHandler(EventHandler *handler);
176 
182  void notify(AsylumEventType type, int32 param1 = 0, int32 param2 = 0);
183 
187  void updateReverseStereo();
188 
189  // Serializable
190  void saveLoadWithSerializer(Common::Serializer &s) override;
191 
192  bool checkGameVersion(const char *version) { return !strcmp(_gameDescription->extra, version); }
193  bool isAltDemo() { return Common::File::exists("asylum.dat"); }
194  Common::Language getLanguage() { return _gameDescription->language; }
195  Common::String getTargetName() { return _targetName; }
196  Common::String getMoviesFileName() { return Common::String::format("%s.movies", _targetName.c_str()); }
197  bool isMenuVisible() { return _handler == (EventHandler *)_menu; }
198  EventHandler *getEventHandler() { return _handler; }
199 
200  // Save/Load
201  int getAutosaveSlot() const override { return getMetaEngine()->getAutosaveSlot(); }
202  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
203  Common::Error loadGameState(int slot) override;
204  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
205  bool canSaveAutosaveCurrently() override;
206  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
207 
208 private:
209  const ADGameDescription *_gameDescription;
210 
211  // Misc
212  Console *_console;
213  Common::RandomSource *_rnd;
214 
215  // Game
216  Cursor *_cursor;
217  Encounter *_encounter;
218  Menu *_menu;
219  ResourceManager *_resource;
220  Savegame *_savegame;
221  Scene *_scene;
222  Screen *_screen;
223  ScriptManager *_script;
224  Special *_special;
225  Speech *_speech;
226  Sound *_sound;
227  Text *_text;
228  VideoPlayer *_video;
229 
230  // Current EventHandler class instance
231  EventHandler *_handler;
232 
233  // Game data
234  Puzzles *_puzzles;
235  SharedData _data;
236  uint32 _gameFlags[130];
237  bool _introPlayed;
238  int32 _tickOffset;
239 
240  void updateMouseCursor();
241  void processDelayedEvents();
242 
246  void playIntro();
247 
248  // Debug
249  friend class Console;
250  Scene *_previousScene;
251  ResourcePackId _delayedSceneIndex;
252  int32 _delayedVideoIndex;
253 };
254 
255 } // namespace Asylum
256 
257 #endif // ASYLUM_ASYLUM_H
virtual int getAutosaveSlot() const
Definition: metaengine.h:304
void notify(AsylumEventType type, int32 param1=0, int32 param2=0)
Definition: encounters.h:84
bool canSaveAutosaveCurrently() override
Definition: str.h:59
virtual bool hasFeature(EngineFeature f) const override
EngineFeature
Definition: engine.h:250
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: data.h:130
bool canSaveGameStateCurrently(Common::U32String *msg=nullptr) override
Definition: error.h:84
Definition: screen.h:80
virtual Common::Error run() override
const char * extra
Definition: advancedDetector.h:137
Definition: advancedDetector.h:120
Definition: asylum.h:53
Definition: speech.h:33
void setTick(uint32 offset)
Definition: asylum.h:120
Definition: random.h:44
Definition: default_display_client.h:78
virtual uint32 getMillis(bool skipRecord=false)=0
Definition: text.h:43
uint getRandomNumber(uint max)
OSystem * _system
Definition: engine.h:148
MetaEngine * getMetaEngine() const
Definition: engine.h:529
Definition: serializer.h:79
Definition: savegame.h:37
Common::Error loadGameState(int slot) override
Definition: menu.h:39
Common::Language language
Definition: advancedDetector.h:150
void switchEventHandler(EventHandler *handler)
Definition: puzzles.h:35
Definition: video.h:54
Definition: ustr.h:57
uint32 screenUpdateCount
Definition: asylum.h:130
Definition: cursor.h:51
Definition: eventhandler.h:61
Definition: scene.h:78
Definition: rect.h:45
Definition: asylum.h:70
Definition: cursor.h:27
Definition: sound.h:102
Definition: console.h:55
Definition: serializer.h:308
Definition: script.h:121
const Common::String _targetName
Definition: engine.h:180
static bool exists(const Path &filename)
uint32 getTick()
Definition: asylum.h:113
Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave=false) override
bool canLoadGameStateCurrently(Common::U32String *msg=nullptr) override
void switchScene(ResourcePackId sceneId)
Definition: asylum.h:106
Definition: system.h:175
Definition: respack.h:72
Definition: special.h:35
int getAutosaveSlot() const override
Definition: asylum.h:201
Definition: engine.h:143
bool startGame(ResourcePackId sceneId, StartGameType type)
Language
Definition: language.h:45