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 GOB_PREGOB_ONCEUPON_ONCEUPON_H
24 #define GOB_PREGOB_ONCEUPON_ONCEUPON_H
25 
26 #include "common/system.h"
27 #include "common/str.h"
28 
29 #include "gob/pregob/pregob.h"
30 
31 #include "gob/pregob/onceupon/stork.h"
32 
33 namespace Gob {
34 
35 class Surface;
36 class Font;
37 
38 class ANIObject;
39 
40 namespace OnceUpon {
41 
42 class OnceUpon : public PreGob {
43 public:
44 	/** Number of languages we support. */
45 	static const uint kLanguageCount = 5;
46 
47 
48 	OnceUpon(GobEngine *vm);
49 	~OnceUpon() override;
50 
51 
52 protected:
53 	/** A description of a menu button. */
54 	struct MenuButton {
55 		bool needDraw; ///< Does the button need drawing?
56 
57 		int16 left;   ///< Left   coordinate of the button.
58 		int16 top;    ///< Top    coordinate of the button.
59 		int16 right;  ///< Right  coordinate of the button.
60 		int16 bottom; ///< Bottom coordinate of the button.
61 
62 		int16 srcLeft;   ///< Left  coordinate of the button's sprite.
63 		int16 srcTop;    ///< Top   coordinate of the button's sprite.
64 		int16 srcRight;  ///< Right coordinate of the button's sprite.
65 		int16 srcBottom; ///< Right coordinate of the button's sprite.
66 
67 		int16 dstX; ///< Destination X coordinate of the button's sprite.
68 		int16 dstY; ///< Destination Y coordinate of the button's sprite.
69 
70 		uint id; ///< The button's ID.
71 	};
72 
73 	/** Parameters for the stork section. */
74 	struct StorkParam {
75 		const char *backdrop; ///< Backdrop image file.
76 
77 		uint  houseCount;         ///< Number of houses.
78 		const MenuButton *houses; ///< House button definitions.
79 
80 		const Stork::BundleDrop *drops; ///< The bundle drop parameters.
81 	};
82 
83 	void init();
84 	void deinit();
85 
86 	/** Handle the copy protection.
87 	 *
88 	 *  @param  colors    Colors the copy protection animals can be.
89 	 *  @param  shapes    The shape that's the correct answer for each animal in each color.
90 	 *  @param  obfuscate Extra obfuscate table. correctShape = shapes[colors][obfuscate[animal]].
91 	 *  @return true if the user guessed the correct shape, false otherwise.
92 	 */
93 	bool doCopyProtection(const uint8 colors[7], const uint8 shapes[7 * 20], const uint8 obfuscate[4]);
94 
95 	/** Show the intro. */
96 	void showIntro();
97 
98 	/** Handle the start menu.
99 	 *
100 	 *  @param animalsButton Definition of the menu button that leads to the animal names screen. Can be 0.
101 	 *  @param animalCount   Number of animals in the animal names screen.
102 	 *  @param animalButtons Definition of the buttons that make up the animals in the animal names screen.
103 	 *  @param animalNames   File prefixes for the name of each animal.
104 	 */
105 	void doStartMenu(const MenuButton *animalsButton, uint animalCount,
106 	                 const MenuButton *animalButtons, const char * const *animalNames);
107 
108 	/** Play the game proper. */
109 	void playGame();
110 
111 
112 	/** Return the parameters for the stork section. */
113 	virtual const StorkParam &getStorkParameters() const = 0;
114 
115 
116 private:
117 	/** All actions a user can request in a menu. */
118 	enum MenuAction {
119 		kMenuActionNone = 0, ///< No action.
120 		kMenuActionAnimals , ///< Do the animal names.
121 		kMenuActionPlay    , ///< Play the game.
122 		kMenuActionRestart , ///< Restart the section.
123 		kMenuActionMainMenu, ///< Go to the main menu.
124 		kMenuActionQuit      ///< Quit the game.
125 	};
126 
127 	/** Difficulty levels. */
128 	enum Difficulty {
129 		kDifficultyBeginner     = 0,
130 		kDifficultyIntermediate = 1,
131 		kDifficultyAdvanced     = 2,
132 		kDifficultyCount
133 	};
134 
135 	/** The different sounds common in the game. */
136 	enum Sound {
137 		kSoundClick = 0,
138 		kSoundStork    ,
139 		kSoundJump     ,
140 		kSoundCount
141 	};
142 
143 	/** Action the character generation wants us to take. */
144 	enum CharGenAction {
145 		kCharGenDone    = 0, ///< Created a character, move on.
146 		kCharGenAbort      , ///< Aborted the character generation.
147 		kCharGenRestart      ///< Restart the character generation.
148 	};
149 
150 	/** A complete screen backup. */
151 	struct ScreenBackup {
152 		Surface *screen; ///< Screen contents.
153 		int palette;     ///< Screen palette.
154 
155 		bool changedCursor; ///< Did we change the cursor?
156 		bool cursorVisible; ///< Was the cursor visible?
157 
158 		ScreenBackup();
159 		~ScreenBackup();
160 	};
161 
162 
163 	/** The number of game sections. */
164 	static const int kSectionCount = 15;
165 
166 	static const MenuButton kMainMenuDifficultyButton[]; ///< Difficulty buttons.
167 	static const MenuButton kSectionButtons[];           ///< Section buttons.
168 
169 	static const MenuButton kIngameButtons[];            ///< Ingame menu buttons.
170 
171 	static const MenuButton kAnimalNamesBack;   ///< "Back" button in the animal names screens.
172 	static const MenuButton kLanguageButtons[]; ///< Language buttons in the animal names screen.
173 
174 	static const MenuButton kSectionStorkHouses[];
175 
176 	static const MenuButton kCharGenHeadButtons[];
177 	static const MenuButton kCharGenHeads[];
178 	static const MenuButton kCharGenHairButtons[];
179 	static const MenuButton kCharGenJacketButtons[];
180 	static const MenuButton kCharGenTrousersButtons[];
181 	static const MenuButton kCharGenNameEntry[];
182 
183 	/** All general game sounds we know about. */
184 	static const char *kSound[kSoundCount];
185 
186 
187 	static const AnimProperties kClownAnimations[];
188 	static const AnimProperties kTitleAnimation;
189 	static const AnimProperties kSectionStorkAnimations[];
190 	static const AnimProperties kSectionEndAnimations[];
191 
192 
193 	/** Function pointer type for a section handler. */
194 	typedef bool (OnceUpon::*SectionFunc)();
195 	/** Section handler function. */
196 	static const SectionFunc kSectionFuncs[kSectionCount];
197 
198 
199 	/** Did we open the game archives? */
200 	bool _openedArchives;
201 
202 	// Fonts
203 	Font *_jeudak;
204 	Font *_lettre;
205 	Font *_plettre;
206 	Font *_glettre;
207 
208 	/** The current palette. */
209 	int _palette;
210 
211 	bool _quit; ///< Did the user request a normal game quit?
212 
213 	Difficulty _difficulty; ///< The current difficulty.
214 	int        _section;    ///< The current game section.
215 
216 	Common::String _name; ///< The name of the child.
217 
218 	uint8 _house;
219 
220 	uint8 _head;
221 	uint8 _colorHair;
222 	uint8 _colorJacket;
223 	uint8 _colorTrousers;
224 
225 
226 	// -- General helpers --
227 
228 	void setGamePalette(uint palette); ///< Set a game palette.
229 	void setGameCursor();              ///< Set the default game cursor.
230 
231 	/** Draw this sprite in a fancy, animated line-by-line way. */
232 	void drawLineByLine(const Surface &src, int16 left, int16 top, int16 right, int16 bottom,
233 	                    int16 x, int16 y) const;
234 
235 	/** Backup the screen contents. */
236 	void backupScreen(ScreenBackup &backup, bool setDefaultCursor = false);
237 	/** Restore the screen contents with a previously made backup. */
238 	void restoreScreen(ScreenBackup &backup);
239 
240 	Common::String fixString(const Common::String &str) const; ///< Fix a string if necessary.
241 	void fixTXTStrings(TXTFile &txt) const override;                    ///< Fix all strings in a TXT.
242 
243 
244 	// -- Copy protection helpers --
245 
246 	/** Set up the copy protection. */
247 	int8 cpSetup(const uint8 colors[7], const uint8 shapes[7 * 20],
248 	             const uint8 obfuscate[4], const Surface sprites[2]);
249 	/** Find the shape under these coordinates. */
250 	int8 cpFindShape(int16 x, int16 y) const;
251 	/** Display the "You are wrong" screen. */
252 	void cpWrong();
253 
254 
255 	// -- Show different game screens --
256 
257 	void showWait(uint palette = 0xFFFF); ///< Show the wait / loading screen.
258 	void showQuote();                     ///< Show the quote about fairytales.
259 	void showTitle();                     ///< Show the Once Upon A Time title.
260 	void showChapter(int chapter);        ///< Show a chapter intro text.
261 	void showByeBye();                    ///< Show the "bye bye" screen.
262 
263 	/** Handle the "listen to animal names" part. */
264 	void handleAnimalNames(uint count, const MenuButton *buttons, const char * const *names);
265 
266 
267 	// -- Menu helpers --
268 
269 	MenuAction handleStartMenu(const MenuButton *animalsButton); ///< Handle the start  menu.
270 	MenuAction handleMainMenu();                                 ///< Handle the main   menu.
271 	MenuAction handleIngameMenu();                               ///< Handle the ingame menu.
272 
273 	void drawStartMenu(const MenuButton *animalsButton); ///< Draw the start  menu.
274 	void drawMainMenu();                                 ///< Draw the main   menu.
275 	void drawIngameMenu();                               ///< Draw the ingame menu.
276 
277 	/** Draw the difficulty label. */
278 	void drawMenuDifficulty();
279 
280 	/** Clear the ingame menu in an animated way. */
281 	void clearIngameMenu(const Surface &background);
282 
283 	/** Handle the whole ingame menu. */
284 	MenuAction doIngameMenu();
285 	/** Handle the whole ingame menu if ESC or right mouse button was pressed. */
286 	MenuAction doIngameMenu(int16 &key, MouseButtons &mouseButtons);
287 
288 
289 	// -- Menu button helpers --
290 
291 	/** Find the button under these coordinates. */
292 	int checkButton(const MenuButton *buttons, uint count, int16 x, int16 y, int failValue = -1) const;
293 
294 	/** Draw a menu button. */
295 	void drawButton (Surface &dest, const Surface &src, const MenuButton &button, int transp = -1) const;
296 	/** Draw multiple menu buttons. */
297 	void drawButtons(Surface &dest, const Surface &src, const MenuButton *buttons, uint count, int transp = -1) const;
298 
299 	/** Draw a border around a button. */
300 	void drawButtonBorder(const MenuButton &button, uint8 color);
301 
302 
303 	// -- Animal names helpers --
304 
305 	/** Set up the animal chooser. */
306 	void anSetupChooser();
307 	/** Set up the language chooser for one animal. */
308 	void anSetupNames(const MenuButton &animal);
309 	/** Play / Display the name of an animal in one language. */
310 	void anPlayAnimalName(const Common::String &animal, uint language);
311 
312 
313 	// -- Game sections --
314 
315 	bool playSection();
316 
317 	bool sectionStork();
318 	bool sectionChapter1();
319 	bool sectionParents();
320 	bool sectionChapter2();
321 	bool sectionForest0();
322 	bool sectionChapter3();
323 	bool sectionEvilCastle();
324 	bool sectionChapter4();
325 	bool sectionForest1();
326 	bool sectionChapter5();
327 	bool sectionBossFight();
328 	bool sectionChapter6();
329 	bool sectionForest2();
330 	bool sectionChapter7();
331 	bool sectionEnd();
332 
333 	CharGenAction characterGenerator();
334 	void charGenSetup(uint stage);
335 	void charGenDrawName();
336 
337 	static bool enterString(Common::String &name, int16 key, uint maxLength, const Font &font);
338 };
339 
340 } // End of namespace OnceUpon
341 
342 } // End of namespace Gob
343 
344 #endif // GOB_PREGOB_ONCEUPON_ONCEUPON_H
345