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 /*
24  * This code is based on the original source code of Lord Avalot d'Argent version 1.3.
25  * Copyright (c) 1994-1995 Mike, Mark and Thomas Thurman.
26  */
27 
28 #ifndef AVALANCHE_AVALANCHE_H
29 #define AVALANCHE_AVALANCHE_H
30 
31 #include "avalanche/console.h"
32 #include "avalanche/graphics.h"
33 #include "avalanche/parser.h"
34 #include "avalanche/avalot.h"
35 #include "avalanche/dialogs.h"
36 #include "avalanche/background.h"
37 #include "avalanche/sequence.h"
38 #include "avalanche/timer.h"
39 #include "avalanche/animation.h"
40 #include "avalanche/dropdown.h"
41 #include "avalanche/closing.h"
42 #include "avalanche/sound.h"
43 #include "avalanche/nim.h"
44 #include "avalanche/clock.h"
45 #include "avalanche/ghostroom.h"
46 #include "avalanche/help.h"
47 #include "avalanche/shootemup.h"
48 #include "avalanche/mainmenu.h"
49 #include "avalanche/highscore.h"
50 
51 #include "common/error.h"
52 #include "common/serializer.h"
53 
54 #include "engines/engine.h"
55 
56 #include "graphics/cursorman.h"
57 
58 namespace Common {
59 class RandomSource;
60 }
61 
62 namespace Avalanche {
63 
64 struct AvalancheGameDescription;
65 
66 static const int kSavegameVersion = 2;
67 
68 enum Pitch {
69 	kPitchInvalid,
70 	kPitchLower,
71 	kPitchSame,
72 	kPitchHigher
73 };
74 
75 class AvalancheEngine : public Engine {
76 public:
77 	byte _saveNum; // number of times this game has been saved
78 
79 	Clock *_clock;
80 	GraphicManager *_graphics;
81 	Parser *_parser;
82 	Dialogs *_dialogs;
83 	Background *_background;
84 	Sequence *_sequence;
85 	Timer *_timer;
86 	Animation *_animation;
87 	DropDownMenu *_dropdown;
88 	Closing *_closing;
89 	SoundHandler *_sound;
90 	Nim *_nim;
91 	GhostRoom *_ghostroom;
92 	Help *_help;
93 	HighScore *_highscore;
94 
95 	OSystem *_system;
96 
97 	AvalancheEngine(OSystem *syst, const AvalancheGameDescription *gd);
98 	~AvalancheEngine() override;
99 
100 	Common::ErrorCode initialize();
101 
102 	Common::RandomSource *_rnd;
103 
104 	const AvalancheGameDescription *_gameDescription;
105 	uint32 getFeatures() const;
106 	const char *getGameId() const;
107 	Common::Platform getPlatform() const;
108 	bool hasFeature(EngineFeature f) const override;
109 	const char *getCopyrightString() const;
110 
111 	void synchronize(Common::Serializer &sz);
112 	bool canSaveGameStateCurrently() override;
113 	Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
114 	bool saveGame(const int16 slot, const Common::String &desc);
115 	bool canLoadGameStateCurrently() override;
116 	Common::Error loadGameState(int slot) override;
117 	bool loadGame(const int16 slot);
118 	Common::String expandDate(int d, int m, int y);
119 	uint32 getTimeInSeconds();
120 
121 	void updateEvents();
122 	bool getEvent(Common::Event &event); // A wrapper around _eventMan->pollEvent(), so we can use it in Scrolls::normscroll() for example.
123 	Common::Point getMousePos();
124 
125 protected:
126 	// Engine APIs
127 	Common::Error run() override;
128 
129 public:
130 	// For Thinkabout:
131 	static const bool kThing = true;
132 	static const bool kPerson = false;
133 
134 	static const char kSpludwicksOrder[3];
135 
136 	static const uint16 kNotes[12];
137 
138 	bool _holdLeftMouse;
139 
140 	// If this is greater than zero, the next line you type is stored in the DNA in a position dictated by the value.
141 	// If a scroll comes up, or you leave the room, it's automatically set to zero.
142 	byte _interrogation;
143 
144 	// Former DNA structure
145 	byte _carryNum; // How many objects you're carrying...
146 	bool _objects[kObjectNum]; // ...and which ones they are.
147 	int16 _score; // your score, of course
148 	int32 _money; // your current amount of dosh
149 	Room _room; // your current room
150 	bool _wonNim; // Have you *won* Nim? (That's harder.)
151 	byte _wineState; // 0=good (Notts), 1=passable(Argent) ... 3=vinegar.
152 	bool _cwytalotGone; // Has Cwytalot rushed off to Jerusalem yet?
153 	byte _passwordNum; // Number of the passw for this game.
154 	bool _aylesIsAwake; // pretty obvious!
155 	byte _drawbridgeOpen; // Between 0 (shut) and 4 (open).
156 	byte _avariciusTalk; // How much Avaricius has said to you.
157 	bool _rottenOnion; // And has it rotted?
158 	bool _onionInVinegar; // Is the onion in the vinegar?
159 	byte _givenToSpludwick; // 0 = nothing given, 1 = onion...
160 	byte _brummieStairs; // Progression through the stairs trick.
161 	byte _cardiffQuestionNum; // Things you get asked in Cardiff.
162 	bool _avvyIsAwake; // Well? Is Avvy awake? (Screen 1 only.)
163 	bool _avvyInBed; // True if Avvy's in bed, but awake.
164 	bool _userMovesAvvy; // If this is false, the user has no control over Avvy's movements.
165 	byte _npcFacing; // If there's an NPC in the current room which turns it's head according to Avvy's movement (keep looking at him), this variable tells which way it's facing at the moment.
166 	bool _givenBadgeToIby; // Have you given the badge to Iby yet?
167 	bool _friarWillTieYouUp; // If you're going to get tied up.
168 	bool _tiedUp; // You ARE tied up!
169 	byte _boxContent; // 0 = money (sixpence), 254 = empty, any other number implies the contents of the box.
170 	bool _talkedToCrapulus; // Pretty self-explanatory.
171 	byte _jacquesState; // 0=asleep, 1=awake, 2=gets up, 3=gone.
172 	bool _bellsAreRinging; // Is Jacques ringing the bells?
173 	bool _standingOnDais; // In room 71, inside Cardiff Castle.
174 	bool _takenPen; // Have you taken the pen (in Cardiff?)
175 	bool _arrowInTheDoor;  // Did the arrow hit the wall?
176 	Common::String _favoriteDrink, _favoriteSong, _worstPlaceOnEarth, _spareEvening; // Personalisation str's
177 	uint32 _startTime; // When did you start playing this session?
178 	uint32 _totalTime; // Your total time playing this game, in seconds. Updated only at saving and loading.
179 	byte _jumpStatus; // Fixes how high you're jumping.
180 	bool _mushroomGrowing; // Is the mushroom growing in 42?
181 	bool _crapulusWillTell; // Will Crapulus tell you about Spludwick being away?
182 	bool _enterCatacombsFromLustiesRoom;
183 	bool _teetotal; // Are we touching any more drinks?
184 	byte _malagauche; // Position of Malagauche. See Celer for more info.
185 	char _drinking; // What's he getting you?
186 	bool _enteredLustiesRoomAsMonk;
187 	byte _catacombX, _catacombY;   // XY coords in the catacombs.
188 	bool _avvysInTheCupboard; // On screen 22.
189 	bool _geidaFollows; // Is Geida following you?
190 	bool _givenPotionToGeida; // Does Geida have the potion?
191 	bool _lustieIsAsleep; // Is BDL asleep?
192 	bool _beenTiedUp; // In r__Robins.
193 	bool _sittingInPub; // Are you sitting down in the pub?
194 	byte _spurgeTalkCount; // Count for talking to Spurge.
195 	bool _metAvaroid;
196 	bool _takenMushroom, _givenPenToAyles, _askedDogfoodAboutNim;
197 	// End of former DNA Structure
198 
199 	bool _showDebugLines;
200 	byte _lineNum; // Number of lines.
201 	LineType _lines[50]; // For Also.
202 	bool _dropsOk;
203 	bool _cheat; // CHECKME: Currently unused
204 	bool _letMeOut;
205 	byte _thinks;
206 	bool _thinkThing;
207 	bool _animationsEnabled; // If set to TRUE, it stops the animation system working. This prevents display of the new sprites before the new picture is loaded or during the display of a scroll. Original name: seescroll.
208 	char _objectList[10];
209 	// Called .free() for them in ~Gyro().
210 
211 	byte _currentMouse; // current mouse-void
212 	Common::String *_also[31][2];
213 	PedType _peds[15];
214 	MagicType _magics[15];
215 	MagicType _portals[7];
216 	FieldType _fields[30];
217 	byte _fieldNum;
218 	Common::String _listen;
219 	byte _cp, _ledStatus;
220 	FontType _font;
221 	bool _alive;
222 	byte _subjectNum; // The same thing.
223 	People _him, _her;
224 	byte _it;
225 	uint32 _roomCycles; // Set to 0 when you enter a room, added to in every loop. Cycles since you've been in this room.
226 
227 	bool _doingSpriteRun; // Only set to True if we're doing a sprite_run at this moment. This stops the trippancy system from moving any of the sprites.
228 	bool _soundFx;
229 
230 	bool _isLoaded; // Is it a loaded gamestate?
231 
232 	void callVerb(VerbCode id);
233 	void loadBackground(byte num);
234 	void loadRoom(byte num);
235 	void thinkAbout(byte object, bool type); // Hey!!! Get it and put it!!!
236 	void incScore(byte num); // Add on no. of points
237 	void fxToggle();
238 	void refreshObjectList();
239 	void errorLed();
240 	void fadeOut();
241 	void fadeIn();
242 	void drawDirection(); // Draws the little icon at the left end of the text input field.
243 	void gameOver();
244 	uint16 bearing(byte whichPed); // Returns the bearing from ped 'whichped' to Avvy, in degrees.
245 
246 	// There are two kinds of redraw: Major and Minor. Minor is what happens when you load a game, etc.
247 	// Major was replaced with GraphicManager::refreshScreen(), it redraws EVERYTHING.
248 	void minorRedraw();
249 
250 	void spriteRun();
251 
252 	Common::String intToStr(int32 num);
253 	void newGame(); // This sets up the DNA for a completely new game.
254 	bool getFlag(char x);
255 	bool decreaseMoney(uint16 amount); // Called pennycheck in the original.
256 
257 	Common::String getName(People whose);
258 	Common::String getItem(byte which); // Called get_better in the original.
259 	Common::String f5Does(); // This procedure determines what f5 does.
260 
261 	void openDoor(Room whither, byte ped, byte magicnum); // Handles slidey-open doors.
262 	void flipRoom(Room room, byte ped);
263 
264 	void setRoom(People persId, Room roomId);
265 	Room getRoom(People persId);
266 private:
267 	static const int16 kMaxSprites = 2; // Current max no. of sprites.
268 	static Room _whereIs[29];
269 
270 	// Will be used in dusk() and dawn().
271 	bool _fxHidden;
272 	byte _fxPal[16][16][3];
273 
274 	bool _spludwickAtHome; // Is Spludwick at home?
275 	bool _passedCwytalotInHerts; // Have you passed Cwytalot in Herts?
276 	bool _holdTheDawn; // If this is true, calling Dawn will do nothing. It's used, for example, at the start, to stop Load from dawning.
277 	byte _lastRoom;
278 	byte _lastRoomNotMap;
279 	byte _roomCount[100]; // Add one to each every time you enter a room
280 	Common::String _mouseText;
281 	Common::String _flags;
282 	Common::String _roomnName; // Name of actual room
283 	int8 _scoreToDisplay[3];
284 
285 	Common::String readAlsoStringFromFile(Common::File &file);
286 	void runAvalot();
287 	void init();
288 	void initVariables();
289 	void setup();
290 	void scram(Common::String &str);
291 	void unScramble();
292 	void handleKeyDown(Common::Event &event); // To replace Basher::keyboard_link() and Basher::typein().
293 	void enterNewTown();
294 	void findPeople(byte room);
295 	void putGeidaAt(byte whichPed, byte ped);
296 	void guideAvvy(Common::Point cursorPos);
297 	void enterRoom(Room room, byte ped);
298 	void exitRoom(byte x);
299 	void drawToolbar();
300 	void drawScore();
301 	void useCompass(const Common::Point &cursorPos); // Click on the compass on the toolbar to control Avvy's movement.
302 	void checkClick();
303 	void fixFlashers();
304 	void loadAlso(byte num);
305 	void resetAllVariables();
306 	void resetVariables();
307 };
308 
309 } // End of namespace Avalanche
310 
311 #endif // AVALANCHE_AVALANCHE_H
312