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/detection.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 extern const char *const engineKeyMapId;
71 extern const char *const resviewerKeyMapId;
72 
73 class AsylumEngine: public Engine, public Common::Serializable {
74 protected:
75  // Engine APIs
76  virtual Common::Error run() override;
77  virtual bool hasFeature(EngineFeature f) const override;
78 
79 public:
80  enum StartGameType {
81  kStartGamePlayIntro,
82  kStartGameLoad,
83  kStartGameScene
84  };
85 
86  AsylumEngine(OSystem *system, const ADGameDescription *gd);
87  virtual ~AsylumEngine();
88 
92  bool startGame(ResourcePackId sceneId, StartGameType type);
93 
97  void restart();
98 
102  void handleEvents();
103 
109  void switchScene(ResourcePackId sceneId) { (void)startGame(sceneId, kStartGameScene); }
110 
116  uint32 getTick() { return _system->getMillis() + _tickOffset; }
117 
123  void setTick(uint32 offset) { _tickOffset = offset - _system->getMillis(); }
124 
128  void reset();
129 
134  uint32 lastScreenUpdate;
135 
136  // Game
137  Cursor *cursor() { return _cursor; }
138  Encounter *encounter() { return _encounter; }
139  Menu *menu() { return _menu; }
140  ResourceManager *resource() { return _resource; }
141  Savegame *savegame() { return _savegame; }
142  Scene *scene() { return _scene; }
143  Screen *screen() { return _screen; }
144  ScriptManager *script() { return _script; }
145  Special *special() { return _special; }
146  Speech *speech() { return _speech; }
147  Sound *sound() { return _sound; }
148  Text *text() { return _text; }
149  VideoPlayer *video() { return _video; }
150 
151  SharedData *data() { return &_data; }
152  Puzzles *puzzles() { return _puzzles; }
153 
154  // Flags
155  void setGameFlag(GameFlag flag);
156  void clearGameFlag(GameFlag flag);
157  void toggleGameFlag(GameFlag flag);
158  bool isGameFlagSet(GameFlag flag) const;
159  bool isGameFlagNotSet(GameFlag flag) const;
160  bool areGameFlagsSet(uint from, uint to) const;
161  void resetFlags() { memset(_gameFlags, 0, sizeof(_gameFlags)); }
162 
163  // Misc
164  uint getRandom(uint max) { return max ? _rnd->getRandomNumber(max - 1) : 0; }
165  uint getRandomBit() { return _rnd->getRandomBit(); }
166 
167  bool rectContains(const int16 (*rectPtr)[4], const Common::Point &p) const;
168 
169  // Steam achievements
170  void unlockAchievement(const Common::String &id);
171  void checkAchievements();
172 
178  void switchEventHandler(EventHandler *handler);
179 
185  void notify(AsylumEventType type, int32 param1 = 0, int32 param2 = 0);
186 
190  void updateReverseStereo();
191 
192  // Serializable
193  void saveLoadWithSerializer(Common::Serializer &s) override;
194 
195  bool checkGameVersion(const char *version) { return !strcmp(_gameDescription->extra, version); }
196  bool isAltDemo() { return Common::File::exists("asylum.dat"); }
197  Common::Language getLanguage() { return _gameDescription->language; }
198  Common::String getTargetName() { return _targetName; }
199  Common::String getMoviesFileName() { return Common::String::format("%s.movies", _targetName.c_str()); }
200  bool isMenuVisible() { return _handler == (EventHandler *)_menu; }
201  EventHandler *getEventHandler() { return _handler; }
202 
203  // Save/Load
204  int getAutosaveSlot() const override { return getMetaEngine()->getAutosaveSlot(); }
205  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
206  Common::Error loadGameState(int slot) override;
207  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
208  bool canSaveAutosaveCurrently() override;
209  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
210 
211 private:
212  const ADGameDescription *_gameDescription;
213 
214  // Misc
215  Common::RandomSource *_rnd;
216 
217  // Game
218  Cursor *_cursor;
219  Encounter *_encounter;
220  Menu *_menu;
221  ResourceManager *_resource;
222  Savegame *_savegame;
223  Scene *_scene;
224  Screen *_screen;
225  ScriptManager *_script;
226  Special *_special;
227  Speech *_speech;
228  Sound *_sound;
229  Text *_text;
230  VideoPlayer *_video;
231 
232  // Current EventHandler class instance
233  EventHandler *_handler;
234 
235  // Game data
236  Puzzles *_puzzles;
237  SharedData _data;
238  uint32 _gameFlags[130];
239  bool _introPlayed;
240  int32 _tickOffset;
241 
242  void updateMouseCursor();
243  void processDelayedEvents();
244 
248  void playIntro();
249 
250  // Debug
251  friend class Console;
252  Scene *_previousScene;
253  ResourcePackId _delayedSceneIndex;
254  int32 _delayedVideoIndex;
255 };
256 
257 } // namespace Asylum
258 
259 #endif // ASYLUM_ASYLUM_H
virtual int getAutosaveSlot() const
Definition: metaengine.h:317
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:253
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:180
Definition: advancedDetector.h:163
Definition: asylum.h:53
Definition: speech.h:33
void setTick(uint32 offset)
Definition: asylum.h:123
Definition: random.h:44
virtual uint32 getMillis(bool skipRecord=false)=0
Definition: text.h:44
uint getRandomNumber(uint max)
Definition: atari-screen.h:60
OSystem * _system
Definition: engine.h:149
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:193
void switchEventHandler(EventHandler *handler)
Definition: puzzles.h:35
Definition: video.h:54
Definition: ustr.h:57
Definition: atari-cursor.h:38
uint32 screenUpdateCount
Definition: asylum.h:133
Definition: cursor.h:45
Definition: eventhandler.h:61
Definition: scene.h:85
Definition: rect.h:45
Definition: asylum.h:73
Definition: sound.h:102
Definition: console.h:38
Definition: serializer.h:308
Definition: script.h:121
const Common::String _targetName
Definition: engine.h:181
static bool exists(const Path &filename)
uint32 getTick()
Definition: asylum.h:116
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:109
Definition: system.h:161
Definition: respack.h:72
Definition: special.h:35
int getAutosaveSlot() const override
Definition: asylum.h:204
Definition: engine.h:144
bool startGame(ResourcePackId sceneId, StartGameType type)
Language
Definition: language.h:45