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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef MADS_GAME_H
24 #define MADS_GAME_H
25 
26 #include "common/scummsys.h"
27 #include "common/savefile.h"
28 #include "common/str-array.h"
29 #include "common/serializer.h"
30 #include "mads/audio.h"
31 #include "mads/scene.h"
32 #include "mads/game_data.h"
33 #include "mads/globals.h"
34 #include "mads/inventory.h"
35 #include "mads/player.h"
36 #include "mads/screen.h"
37 #include "mads/camera.h"
38 
39 namespace MADS {
40 
41 class MADSEngine;
42 
43 enum KernelMode {
44 	KERNEL_GAME_LOAD = 0, KERNEL_SECTION_PRELOAD = 1, KERNEL_SECTION_INIT = 2,
45 	KERNEL_ROOM_PRELOAD = 3, KERNEL_ROOM_INIT = 4, KERNEL_ACTIVE_CODE = 5
46 };
47 
48 enum SyncType {
49 	SYNC_SEQ = 1, SYNC_PLAYER = 2, SYNC_ANIM = 3, SYNC_CLOCK = 4
50 };
51 
52 
53 #define MADS_SAVEGAME_VERSION 1
54 
55 struct MADSSavegameHeader {
56 	uint8 _version;
57 	Common::String _saveName;
58 	Graphics::Surface *_thumbnail;
59 	int _year, _month, _day;
60 	int _hour, _minute;
61 	int _totalFrames;
62 };
63 
64 class Game {
65 private:
66 	/**
67 	 * Main game loop
68 	 */
69 	void gameLoop();
70 
71 	/**
72 	 * Inner game loop for executing gameplay within a game section
73 	 */
74 	void sectionLoop();
75 
76 	/**
77 	 * Load quotes data
78 	 */
79 	void loadQuotes();
80 protected:
81 	MADSEngine *_vm;
82 	MSurface *_surface;
83 	int _statusFlag;
84 	Common::StringArray _quotes;
85 	bool _quoteEmergency;
86 	bool _vocabEmergency;
87 	bool _anyEmergency;
88 	int _lastSave;
89 	Common::String _saveName;
90 	Common::InSaveFile *_saveFile;
91 	Graphics::Surface *_saveThumb;
92 
93 	/**
94 	 * Constructor
95 	 */
96 	Game(MADSEngine *vm);
97 
98 	/**
99 	 * Initializes the current section number of the game
100 	 */
101 	void initSection(int sectionNumber);
102 
103 	//@{
104 	/** @name Virtual Method list */
105 
106 	/**
107 	 * Perform any game-specifcic startup
108 	 */
109 	virtual void startGame() = 0;
110 
111 	/**
112 	 * Initializes global variables for a new game
113 	 */
114 	virtual void initializeGlobals() = 0;
115 
116 	/**
117 	 * Set up the section handler specific to each section
118 	 */
119 	virtual void setSectionHandler() = 0;
120 
121 	/**
122 	 * Checks for whether to show a dialog
123 	 */
124 	virtual void checkShowDialog() = 0;
125 
126 	//@}
127 
128 public:
129 	static Game *init(MADSEngine *vm);
130 
131 public:
132 	Player _player;
133 	ScreenObjects _screenObjects;
134 	int _sectionNumber;
135 	int _priorSectionNumber;
136 	int _currentSectionNumber;
137 	InventoryObjects _objects;
138 	SectionHandler *_sectionHandler;
139 	VisitedScenes _visitedScenes;
140 	Scene _scene;
141 	KernelMode _kernelMode;
142 	int _trigger;
143 	ScreenTransition _fx;
144 	TriggerMode _triggerMode;
145 	TriggerMode _triggerSetupMode;
146 	uint32 _priorFrameTimer;
147 	Common::String _aaName;
148 	int _winStatus;
149 	int _widepipeCtr;
150 	int _loadGameSlot;
151 	int _panningSpeed;
152 	Camera _camX, _camY;
153 
154 public:
155 	virtual ~Game();
156 
157 	/**
158 	 * Main outer loop for the game
159 	 */
160 	void run();
161 
162 	/**
163 	 * Return the number of quotes
164 	 */
getQuotesSize()165 	uint32 getQuotesSize() { return _quotes.size(); }
166 
167 	/**
168 	 * Get a specific quote string
169 	 */
getQuote(uint32 index)170 	const Common::String &getQuote(uint32 index) { return _quotes[index - 1]; }
171 
172 	/**
173 	 * Split a quote into two lines for display on-screen
174 	 */
175 	void splitQuote(const Common::String &source, Common::String &line1, Common::String &line2);
176 
177 	Common::StringArray getMessage(uint32 id);
178 
179 	/**
180 	 * Returns the globals for the game
181 	 */
182 	virtual Globals &globals() = 0;
183 
184 	/**
185 	* Standard object handling across the game
186 	*/
187 	virtual void doObjectAction() = 0;
188 
189 	/**
190 	 * Fallback handler for any action that isn't explicitly handled
191 	 */
192 	virtual void unhandledAction() = 0;
193 
194 	/**
195 	 * Global game step
196 	 */
197 	virtual void step() = 0;
198 
199 	/**
200 	 * Synchronize the game data
201 	 * @param s			Serializer
202 	 * @param phase1	If true, it's synchronizing the basic scene information
203 	 */
204 	virtual void synchronize(Common::Serializer &s, bool phase1);
205 
setNaughtyMode(bool naughtyMode)206 	virtual void setNaughtyMode(bool naughtyMode) {}
getNaughtyMode()207 	virtual bool getNaughtyMode() const { return true; }
208 
209 	// DEPRECATED: ScummVM re-implementation keeps all the quotes loaded, so the methods below are stubs
clearQuotes()210 	void clearQuotes() {}
loadQuoteRange(int startNum,int endNum)211 	void loadQuoteRange(int startNum, int endNum) {}
loadQuoteSet(...)212 	void loadQuoteSet(...) {}
loadQuote(int quoteNum)213 	void loadQuote(int quoteNum) {}
214 
215 	/**
216 	* Handle a keyboard event
217 	*/
218 	void handleKeypress(const Common::KeyState &kbd);
219 
220 	/**
221 	 * Starts a savegame loading.
222 	 * @remarks	Due to the way the engine is implemented, loading is done in two
223 	 * parts, the second part after the specific scene has been loaded
224 	 */
225 	void loadGame(int slotNumber);
226 
227 	/**
228 	 * Save the current game
229 	 */
230 	void saveGame(int slotNumber, const Common::String &saveName);
231 
232 	/**
233 	 * Write out a savegame header
234 	 */
235 	void writeSavegameHeader(Common::OutSaveFile *out, MADSSavegameHeader &header);
236 
237 	/**
238 	 * Read in a savegame header
239 	 */
240 	WARN_UNUSED_RESULT static bool readSavegameHeader(Common::InSaveFile *in, MADSSavegameHeader &header, bool skipThumbnail = true);
241 
242 	/**
243 	 * Creates a temporary thumbnail for use in saving games
244 	 */
245 	void createThumbnail();
246 
247 	void syncTimers(SyncType slaveType, int slaveId, SyncType masterType, int masterId);
248 
249 	void camInitDefault();
250 	void camSetSpeed();
251 	void camUpdate();
252 };
253 
254 } // End of namespace MADS
255 
256 #endif /* MADS_GAME_H */
257