aboutsummaryrefslogtreecommitdiff
path: root/engines/avalanche/avalot.h
blob: 2a5234af08e0548569d10a8b96fda7fdf56f9989 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

/*
 * This code is based on the original source code of Lord Avalot d'Argent version 1.3.
 * Copyright (c) 1994-1995 Mike, Mark and Thomas Thurman.
 */

/* AVALOT		The kernel of the program. */

#ifndef AVALANCHE_AVALOT_H
#define AVALANCHE_AVALOT_H

#include "avalanche/animation.h"

#include "common/events.h"
#include "common/system.h"
#include "common/str.h"
#include "common/scummsys.h"
#include "common/file.h"
#include "graphics/surface.h"

namespace Avalanche {
class AvalancheEngine;

class Clock {
public:
	Clock(AvalancheEngine *vm);

	void update();
	
private:
	static const int kCenterX = 510;
	static const int kCenterY = 183;

	AvalancheEngine *_vm;

	uint16 _hour, _minute, _second, _hourAngle, _oldHour, _oldMinute, _oldHourAngle;
	Common::Point _clockHandHour, _clockHandMinute;

	void calcHand(uint16 angle, uint16 length, Common::Point &endPoint, byte color);
	void drawHand(const Common::Point &endPoint, byte color);
	void plotHands();
	void chime();
};

static const byte kObjectNum = 18; // always preface with a #
static const int16 kCarryLimit = 12;  // carry limit

static const int16 kNumlockCode = 32;  // Code for Num Lock
static const int16 kMouseSize = 134;

struct MouseHotspotType { // mouse-void
	int16 _horizontal, _vertical;
};

struct PedType {
	int16 _x, _y;
	Direction _direction;
};

struct MagicType {
	byte _operation; // one of the operations
	uint16 _data; // data for them
};

struct FieldType {
	int16 _x1, _y1, _x2, _y2;
};

struct ByteField {
	byte _x1, _y1, _x2, _y2;
};

struct LineType : public FieldType {
	byte _color;
};

typedef int8 TuneType[31];

struct QuasipedType {
	byte _whichPed, _foregroundColor, _room, _backgroundColor;
	People _who;
};

#if 0
struct Sundry { // Things which must be saved over a backtobootstrap, outside DNA.
	Common::String _qEnidFilename;
	bool _qSoundFx;
	byte _qThinks;
	bool _qThinkThing;
};
#endif

class Avalot {
public:
	static const int16 kXW = 30;
	static const int16 kYW = 36; // x width & y whatsit
	static const int16 kMargin = 5;
	static const MouseHotspotType kMouseHotSpots[9];
	static const int16 kMaxSprites = 2; // Current max no. of sprites.

	// For Thinkabout:
	static const bool kThing = true;
	static const bool kPerson = false;

	// Magic/portal constants:
	enum Magics {
		kMagicNothing, // Ignore it if this line is touched.
		kMagicBounce, // Bounce off this line. Not valid for portals.
		kMagicExclaim, // Put up a chain of scrolls.
		kMagicTransport, // Enter new room.
		kMagicUnfinished, // Unfinished connection.
		kMagicSpecial, // Special function.
		kMagicOpenDoor // Opening door.
	};

	// These following static constants should be included in CFG when it's written.

	static const bool kSlowComputer = false; // Stops walking when mouse touches toolbar.
	static const int16 kBorder = 1; // size of border on shadowboxes
	static const int16 kWalk = 3;
	static const int16 kRun = 5;
	static const int32 kCatacombMap[8][8];
	static const char kSpludwicksOrder[3];
	static const QuasipedType kQuasipeds[16];

	enum Pitch {
		kPitchInvalid,
		kPitchLower,
		kPitchSame,
		kPitchHigher
	};

	static const uint16 kNotes[12];
	static const TuneType kTune;

	static const char *kVersionNum;
	static const char *kCopyright;
	static const int16 kVersionCode = 130; // Same as kVersionCode, but numerically & without the ".".
	static const int16 kGameCode = 2; // Avalot's code number



	Avalot(AvalancheEngine *vm);
	~Avalot();

	bool _holdLeftMouse;
	Clock _clock;
	
	// If this is greater than zero, the next line you type is stored in the DNA in a position dictated by the value.
	// If a scroll comes up, or you leave the room, it's automatically set to zero.
	byte _interrogation;

	// Former DNA structure
	byte _carryNum; // How many objects you're carrying...
	bool _objects[kObjectNum]; // ...and which ones they are.
	int16 _dnascore; // your score, of course
	int32 _money; // your current amount of dosh
	Room _room; // your current room
	byte _roomCount[100]; // Add one to each every time you enter a room
	bool _wonNim; // Have you *won* Nim? (That's harder.)
	byte _wineState; // 0=good (Notts), 1=passable(Argent) ... 3=vinegar.
	bool _cwytalotGone; // Has Cwytalot rushed off to Jerusalem yet?
	byte _passwordNum; // Number of the passw for this game.
	bool _aylesIsAwake; // pretty obvious!
	byte _drawbridgeOpen; // Between 0 (shut) and 4 (open).
	byte _avariciusTalk; // How much Avaricius has said to you.
	bool _rottenOnion; // And has it rotted?
	bool _onionInVinegar; // Is the onion in the vinegar?
	byte _givenToSpludwick; // 0 = nothing given, 1 = onion...
	byte _brummieStairs; // Progression through the stairs trick.
	byte _cardiffQuestionNum; // Things you get asked in Cardiff.
	bool _passedCwytalotInHerts; // Have you passed Cwytalot in Herts?
	bool _avvyIsAwake; // Well? Is Avvy awake? (Screen 1 only.)
	bool _avvyInBed; // True if Avvy's in bed, but awake.
	bool _userMovesAvvy; // If this is false, the user has no control over Avvy's movements.
	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.
	bool _givenBadgeToIby; // Have you given the badge to Iby yet?
	bool _friarWillTieYouUp; // If you're going to get tied up.
	bool _tiedUp; // You ARE tied up!
	byte _boxContent; // 0 = money (sixpence), 254 = empty, any other number implies the contents of the box.
	bool _talkedToCrapulus; // Pretty self-explanatory.
	byte _jacquesState; // 0=asleep, 1=awake, 2=gets up, 3=gone.
	bool _bellsAreRinging; // Is Jacques ringing the bells?
	bool _standingOnDais; // In room 71, inside Cardiff Castle.
	bool _takenPen; // Have you taken the pen (in Cardiff?)
	bool _arrowTriggered; // And has the arrow been triggered?
	bool _arrowInTheDoor;  // Did the arrow hit the wall?
	Common::String _favouriteDrink, _favouriteSong, _worstPlaceOnEarth, _spareEvening; // Personalisation str's
	uint32 _totalTime; // Your total time playing this game, in ticks.
	byte _jumpStatus; // Fixes how high you're jumping.
	bool _mushroomGrowing; // Is the mushroom growing in 42?
	bool _spludwickAtHome; // Is Spludwick at home?
	byte _lastRoom;
	byte _lastRoomNotMap;
	bool _crapulusWillTell; // Will Crapulus tell you about Spludwick being away?
	bool _enterCatacombsFromLustiesRoom;
	bool _teetotal; // Are we touching any more drinks?
	byte _malagauche; // Position of Malagauche. See Celer for more info.
	char _drinking; // What's he getting you?
	bool _enteredLustiesRoomAsMonk;
	byte _catacombX, _catacombY;   // XY coords in the catacombs.
	bool _avvysInTheCupboard; // On screen 22.
	bool _geidaFollows; // Is Geida following you?
	byte _nextBell; // For the ringing.
	bool _givenPotionToGeida; // Does Geida have the potion?
	bool _lustieIsAsleep; // Is BDL asleep?
	Room _flipToWhere;
	byte _flipToPed; // For the sequencer.
	bool _beenTiedUp; // In r__Robins.
	bool _sittingInPub; // Are you sitting down in the pub?
	byte _spurgeTalkCount; // Count for talking to Spurge.
	bool _metAvaroid;
	bool _takenMushroom, _givenPenToAyles, _askedDogfoodAboutNim;
	// End of former DNA Structure

	byte _lineNum; // Number of lines.
	LineType _lines[50]; // For Also.
	enum MouseState { kMouseStateNo, kMouseStateYes, kMouseStateVirtual } _mouse;
	bool _dropsOk, _scReturn, _soundFx, _cheat;
	Common::String _mouseText;
	bool _weirdWord;
	bool _letMeOut;
	Common::String _scroll[15];
	byte _scrollNum, _whichwas;
	byte _thinks;
	bool _thinkThing;
	int16 _talkX, _talkY;
	byte _talkBackgroundColor, _talkFontColor;
	byte _scrollBells; // no. of times to ring the bell
	bool _onToolbar, _seeScroll; // TODO: maybe this means we're interacting with the toolbar / a scroll?
	char _objectList[10];
	::Graphics::Surface _digits[10]; // digitsize and rwlitesize are defined in Lucerna::load_digits() !!!
	::Graphics::Surface _directions[9]; // Maybe it will be needed to move them to the class itself instead.
	// Called .free() for them in ~Gyro().
	int8 _scoreToDisplay[3];
	byte _currentMouse; // current mouse-void
	Common::String _verbStr; // what you can do with your object. :-)
	Common::String *_also[31][2];
	PedType _peds[15];
	MagicType _magics[15];
	MagicType _portals[7];
	FieldType _fields[30];
	byte _fieldNum;
	Common::String _flags;
	Common::String _listen;
	byte _cp, _ledStatus, _defaultLed;
	FontType _font;
	bool _alive;
	byte _buffer[2000];
	uint16 _bufSize;
	int16 _underScroll; // Y-coord of just under the scroll text.
	Common::String _roomnName; // Name of actual room
	Common::String _subject; // What you're talking to them about.
	byte _subjectNum; // The same thing.
	bool _keyboardClick; // Is a keyboard click noise wanted?
	People _him, _her;
	byte _it;
	int32 _roomTime; // Set to 0 when you enter a room, added to in every loop.

	People _lastPerson; // Last person to have been selected using the People menu.
	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.
	bool _holdTheDawn; // If this is true, calling Dawn will do nothing. It's used, for example, at the start, to stop Load from dawning.
	bool _isLoaded; // Is it a loaded gamestate?
	Common::String _enidFilename;

	void handleKeyDown(Common::Event &event); // To replace Basher::keyboard_link() and Basher::typein().
	void setup();
	void runAvalot();

	void init();
	void callVerb(VerbCode id);
	void drawAlsoLines();
	void loadRoom(byte num);
	void exitRoom(byte x);
	void enterRoom(Room room, byte ped);
	void thinkAbout(byte object, bool type); // Hey!!! Get it and put it!!!
	void loadDigits(); // Load the scoring digits & rwlites
	void drawToolbar();
	void drawScore();
	void incScore(byte num); // Add on no. of points
	void useCompass(const Common::Point &cursorPos); // Click on the compass on the toolbar to control Avvy's movement.
	void fxToggle();
	void refreshObjectList();
	void checkClick();
	void errorLed();
	void dusk();
	void dawn();
	void drawDirection(); // Draws the little icon at the left end of the text input field.
	void gameOver();
	uint16 bearing(byte whichPed); // Returns the bearing from ped 'whichped' to Avvy, in degrees.
	void fixFlashers();
	void loadAlso(byte num);

	// There are two kinds of redraw: Major and Minor. Minor is what happens when you load a game, etc. Major redraws EVERYTHING.
	void minorRedraw();
	void majorRedraw();

	void spriteRun();

	Common::String intToStr(int32 num);
	void newMouse(byte id);
	void setMousePointerWait();    // Makes hourglass.
	void loadMouse(byte which);

	void setBackgroundColor(byte x);
	void drawShadowBox(int16 x1, int16 y1, int16 x2, int16 y2, Common::String t);

	void resetVariables();
	void newGame(); // This sets up the DNA for a completely new game.
	void slowDown();
	bool setFlag(char x);
	bool decreaseMoney(uint16 amount); // Called pennycheck in the original.
	void hangAroundForAWhile();
	
	Common::String getName(People whose);
	byte getNameChar(People whose);
	Common::String getThing(byte which);
	char getThingChar(byte which);
	Common::String getItem(byte which); // Called get_better in the original.
	Common::String f5Does(); // This procedure determines what f5 does.

	void openDoor(Room whither, byte ped, byte magicnum); // Handles slidey-open doors.
	void flipRoom(Room room, byte ped);

	void setRoom(People persId, Room roomId);
	Room getRoom(People persId);
private:
	AvalancheEngine *_vm;

	static Room _whereIs[29];

	Common::File file;
	Common::String readAlsoStringFromFile();
	void scram(Common::String &str);
	void unScramble();

	void zoomOut(int16 x, int16 y); // Only used when entering the map.
	void enterNewTown();
	void findPeople(byte room);
	void putGeidaAt(byte whichPed, byte ped);
	void guideAvvy(Common::Point cursorPos);

	// Will be used in dusk() and dawn().
	bool _fxHidden;

	int8 fades(int8 x);
	void fadeOut(byte n);
	void fadeIn(byte n);

	void drawShadow(int16 x1, int16 y1, int16 x2, int16 y2, byte hc, byte sc);
};

} // End of namespace Avalanche

#endif // AVALANCHE_AVALOT_H