ScummVM API documentation
mads.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 MADS_ENGINE_H
23 #define MADS_ENGINE_H
24 
25 #include "audio/mixer.h"
26 #include "common/events.h"
27 #include "common/serializer.h"
28 #include "common/stack.h"
29 #include "common/random.h"
30 #include "common/util.h"
31 #include "engines/engine.h"
32 #include "mads/detection.h"
33 #include "graphics/screen.h"
34 #include "mads/core/sound_manager.h"
35 #include "mads/core/game.h"
36 #include "mads/core/speech.h"
37 
38 namespace MADS {
39 
40 #define DEBUG_BASIC 1
41 #define DEBUG_INTERMEDIATE 2
42 #define DEBUG_DETAILED 3
43 
44 enum MADSDebugChannels {
45  kDebugPath = 1,
46  kDebugScripts,
47  kDebugGraphics,
48  kDebugConversations
49 };
50 
51 enum MADSActions {
52  kActionNone,
53  kActionEscape,
54  kActionGameMenu,
55  kActionSave,
56  kActionRestore,
57  kActionScrollUp,
58  kActionScrollDown,
59  kActionStartGame,
60  kActionResumeGame,
61  kActionShowIntro,
62  kActionCredits,
63  kActionQuotes,
64  kActionRestartAnimation
65 };
66 
67 typedef void (*TimerFunction)();
68 
69 class MADSEngine : public Engine {
70 private:
71  uint16 _shakeRandom = 0x4D2;
72 
73  void initGlobals();
74  void syncGame(Common::Serializer &s);
75  bool isSpecialKey(Common::KeyCode key) const;
76  void updateScreen();
77 
78 protected:
79  const MADSGameDescription *_gameDescription;
80  Common::RandomSource _randomSource;
81  Graphics::Screen *_screen = nullptr;
83  uint32 _nextFrameTime = 0;
84  Common::Point _mousePos;
85  int _mouseButtons = 0;
86  Audio::SoundHandle _speechHandle;
87  TimerFunction _timerFunction = nullptr;
88  uint32 _nextTimerTime = 0;
89 
90  bool hasFeature(EngineFeature f) const override;
91 
92  void pollEvents();
93  void checkForTimerFunction();
94 
95 public:
96  MADS::SoundManager *_soundManager = nullptr;
97  bool _musicFlag = true;
98  bool _soundFlag = true;
99  bool &_speechFlag = speech_on;
100 
101 public:
102  MADSEngine(OSystem *syst, const MADSGameDescription *gameDesc);
103  ~MADSEngine() override;
104  void initializePath(const Common::FSNode &gamePath) override;
105 
106  uint32 getFeatures() const;
107  Common::Language getLanguage() const;
108  Common::Platform getPlatform() const;
109  uint16 getVersion() const;
110  uint32 getGameID() const;
111  uint32 getGameFeatures() const;
112  bool isDemo() const;
113  bool isCDROM() const;
114 
115  void readConfigFile();
116  int getRandomNumber(int maxNumber);
117  int getRandomNumber(int minNumber, int maxNumber);
118 
119  Graphics::Screen *getScreen() const {
120  return _screen;
121  }
122 
123  bool hasPendingKey();
124  int getKey();
125  void flushKeys();
126 
127  int getMouseState(int &x, int &y);
128 
132  uint32 getMillis();
133 
134  /* Callback routines in game-specific MAIN module */
135  int main_cheating_key(int mykey) const {
136  return mykey;
137  }
138  int main_normal_key(int mykey) const {
139  return mykey;
140  }
141  virtual int main_copy_verify() {
142  return COPY_SUCCEED;
143  }
144 
145  bool canLoadGameStateCurrently(Common::U32String *msg) override;
147  return canLoadGameStateCurrently(msg);
148  }
149  Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave) override;
151  virtual void syncRoom(Common::Serializer &s) = 0;
152  SaveStateList listSaves() const;
153 
154  virtual void global_init_code() = 0;
155  virtual void section_music(int section_num) = 0;
156  virtual void global_section_constructor() = 0;
157  virtual void global_daemon_code() = 0;
158  virtual void global_pre_parser_code() = 0;
159  virtual void global_parser_code() = 0;
160  virtual void global_error_code() = 0;
161  virtual void global_room_init() = 0;
162  virtual void global_sound_driver() = 0;
163  virtual void global_game_main_loop() {}
164  virtual void global_verb_filter() {}
165  virtual void player_keep_walking();
166 
167  void playSpeech(Audio::AudioStream *stream);
168  void stopSpeech();
169  bool isSpeechPlaying() const;
170 
174  void setTimerFunction(TimerFunction fn) {
175  _timerFunction = fn;
176  }
177 };
178 
179 extern MADSEngine *g_engine;
180 
181 } // namespace MADS
182 
183 #endif
EngineFeature
Definition: engine.h:282
Definition: stream.h:77
Definition: error.h:81
Definition: random.h:44
Definition: stream.h:745
Definition: screen.h:47
Engine * g_engine
Definition: serializer.h:80
Definition: mixer.h:49
void setTimerFunction(TimerFunction fn)
Definition: mads.h:174
Definition: ustr.h:57
Common::Error loadGameStream(Common::SeekableReadStream *stream) override
Definition: sound_manager.h:90
Definition: fs.h:69
Definition: rect.h:144
Definition: audiostream.h:50
uint32 getMillis()
Definition: detection.h:41
Definition: mads.h:69
void initializePath(const Common::FSNode &gamePath) override
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave) override
Definition: anim_timer.h:27
bool canSaveGameStateCurrently(Common::U32String *msg) override
Definition: mads.h:146
Definition: system.h:166
Definition: engine.h:149
bool canLoadGameStateCurrently(Common::U32String *msg) override
Platform
Definition: platform.h:93
bool hasFeature(EngineFeature f) const override
Language
Definition: language.h:45