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