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