aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra/kyra_v3.h
blob: 0b56f0da13a5b2df8e90a34e520740c9097a7951 (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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
/* 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.
 *
 * $URL$
 * $Id$
 *
 */

#ifndef KYRA_KYRA_V3_H
#define KYRA_KYRA_V3_H

#include "kyra/kyra.h"
#include "kyra/screen_v3.h"
#include "kyra/script.h"

#include "common/hashmap.h"
#include "common/list.h"

namespace Kyra {

class SoundDigital;
class Screen_v3;
class MainMenu;
class WSAMovieV2;
class TextDisplayer_v3;
struct Button;

class KyraEngine_v3 : public KyraEngine {
public:
	KyraEngine_v3(OSystem *system, const GameFlags &flags);
	~KyraEngine_v3();

	Screen *screen() { return _screen; }
	SoundDigital *soundDigital() { return _soundDigital; }

	int go();

	void playVQA(const char *name);

	virtual Movie *createWSAMovie();
private:
	Screen_v3 *_screen;
	SoundDigital *_soundDigital;

	int init();

	void preinit();
	void startup();
	void runStartupScript(int script, int unk1);

	void setupOpcodeTable();

	// run
	bool _runFlag;

	void runLoop();
	void handleInput(int x, int y);

	void update();
	void updateMouse();

	void delay(uint32 millis, bool update = false, bool isMainLoop = false);

	// - Input
	void updateInput();
	int checkInput(Button *buttonList, bool mainLoop = false);
	void removeInputTop();

	int _mouseX, _mouseY;
	int _mouseState;

	struct Event {
		Common::Event event;
		bool causedSkip;

		Event() : event(), causedSkip(false) {}
		Event(Common::Event e) : event(e), causedSkip(false) {}
		Event(Common::Event e, bool skip) : event(e), causedSkip(skip) {}

		operator Common::Event() const { return event; }
	};
	Common::List<Event> _eventList;

	bool skipFlag() const;
	void resetSkipFlag(bool removeEvent = true);

	// sound specific
private:
	void playMenuAudioFile();

	int _musicSoundChannel;
	int _fadeOutMusicChannel;
	const char *_menuAudioFile;

	static const char *_soundList[];
	static const int _soundListSize;

	int _curMusicTrack;

	void playMusicTrack(int track, int force);
	void stopMusicTrack();

	int musicUpdate(int forceRestart);
	void fadeOutMusic(int ticks);

	void snd_playVoiceFile(int) {}

	// main menu
	void initMainMenu();
	void uninitMainMenu();

	WSAMovieV2 *_menuAnim;
	MainMenu *_menu;

	// timer
	void setupTimers();

	void setWalkspeed(uint8);
	void setCommandLineRestoreTimer(int secs);

	void timerRestoreCommandLine(int arg);
	void timerRunSceneScript7(int arg);
	void timerFleaDeath(int arg);

	// pathfinder
	int _pathfinderFlag;

	bool lineIsPassable(int x, int y);

private:
	// main menu
	static const char *_mainMenuStrings[];

	// animator
	struct AnimObj {
		uint16 index;
		uint16 type;
		bool enabled;
		bool needRefresh;
		uint16 unk8;
		uint16 flags;
		int16 xPos1, yPos1;
		uint8 *shapePtr;
		uint16 shapeIndex;
		uint16 animNum;
		uint16 shapeIndex3;
		uint16 shapeIndex2;
		int16 xPos2, yPos2;
		int16 xPos3, yPos3;
		int16 width, height;
		int16 width2, height2;
		uint16 palette;
		AnimObj *nextObject;
	};

	AnimObj *_animObjects;
	uint8 *_gamePlayBuffer;

	void clearAnimObjects();

	AnimObj *_animList;
	bool _drawNoShapeFlag;
	AnimObj *initAnimList(AnimObj *list, AnimObj *entry);
	AnimObj *addToAnimListSorted(AnimObj *list, AnimObj *entry);
	AnimObj *deleteAnimListEntry(AnimObj *list, AnimObj *entry);

	void animSetupPaletteEntry(AnimObj *anim);

	void restorePage3();

	void drawAnimObjects();
	void drawSceneAnimObject(AnimObj *obj, int x, int y, int drawLayer);
	void drawCharacterAnimObject(AnimObj *obj, int x, int y, int drawLayer);

	void refreshAnimObjects(int force);
	void refreshAnimObjectsIfNeed();

	bool _loadingState;
	void updateCharacterAnim(int charId);

	void updateSceneAnim(int anim, int newFrame);
	void removeSceneAnimObject(int anim, int refresh);

	// interface
	uint8 *_interface;
	uint8 *_interfaceCommandLine;

	void loadInterfaceShapes();
	void loadInterface();

	void showMessage(const char *string, uint8 c0, uint8 c1);
	void updateCommandLine();
	void restoreCommandLine();

	int _commandLineY;
	const char *_shownMessage;
	bool _restoreCommandLine;
	bool _inventoryState;

	// localization
	uint8 *_scoreFile;
	uint8 *_cCodeFile;
	uint8 *_scenesFile;
	uint8 *_itemFile;
	uint8 *_actorFile;
	uint32 _actorFileSize;
	uint8 *_sceneStrings;

	uint8 *getTableEntry(uint8 *buffer, int id);

	// items
	uint8 *_itemBuffer1;
	uint8 *_itemBuffer2;
	struct Item {
		uint16 id;
		uint16 sceneId;
		int16 x, y;
		uint16 unk8;
	};

	Item *_itemList;
	uint16 _hiddenItems[100];

	void resetItem(int index);
	void resetItemList();

	int findFreeItem();
	
	void initItems();

	int checkItemCollision(int x, int y);

	// -> hand item
	void setItemMouseCursor();

	int _itemInHand;
	int _handItemSet;

	// shapes
	typedef Common::HashMap<int, uint8*> ShapeMap;
	ShapeMap _gameShapes;

	void addShapeToPool(const uint8 *data, int realIndex, int shape);
	uint8 *getShapePtr(int shape) const { return _gameShapes[shape]; }

	void initMouseShapes();

	int _malcolmShapes;
	void loadMalcolmShapes(int newShapes);
	void updateMalcolmShapes();

	int _malcolmShapeXOffset, _malcolmShapeYOffset;

	struct ShapeDesc {
		uint8 width, height;
		int8 xOffset, yOffset;
	};
	static const ShapeDesc _shapeDescs[];
	static const int _shapeDescsSize;

	// scene animation
	struct SceneAnim {
		uint16 flags;
		int16 x, y;
		int16 x2, y2;
		int16 width, height;
		uint16 unk10;
		uint16 specialSize;
		uint16 unk14;
		uint16 shapeIndex;
		uint16 wsaFlag;
		char filename[13];
	};

	SceneAnim *_sceneAnims;
	WSAMovieV2 *_sceneAnimMovie[16];
	uint8 *_sceneShapes[20];

	void freeSceneShapes();
	void freeSceneAnims();

	// voice
	int _currentTalkFile;
	void openTalkFile(int file);

	// scene
	struct SceneDesc {
		char filename1[10];
		char filename2[10];
		uint16 exit1, exit2, exit3, exit4;
		uint8 flags, sound;
	};

	SceneDesc *_sceneList;
	uint16 _sceneExit1, _sceneExit2, _sceneExit3, _sceneExit4;
	int _sceneEnterX1, _sceneEnterY1;
	int _sceneEnterX2, _sceneEnterY2;
	int _sceneEnterX3, _sceneEnterY3;
	int _sceneEnterX4, _sceneEnterY4;

	int _specialExitCount;
	uint16 _specialExitTable[25];
	bool checkSpecialSceneExit(int index, int x, int y);

	bool _noScriptEnter;
	void enterNewScene(uint16 scene, int facing, int unk1, int unk2, int unk3);
	void enterNewSceneUnk1(int facing, int unk1, int unk2);
	void enterNewSceneUnk2(int unk1);
	int _enterNewSceneLock;

	void unloadScene();

	void loadScenePal();
	void loadSceneMsc();
	void initSceneScript(int unk1);
	void initSceneAnims(int unk1);
	void initSceneScreen(int unk1);

	bool _noStartupChat;
	void runSceneScript4(int unk1);
	void runSceneScript8();

	int _sceneMinX, _sceneMaxX;
	int _maskPageMinY, _maskPageMaxY;

	ScriptState _sceneScriptState;
	ScriptData _sceneScriptData;
	WSAMovieV2 *_wsaSlots[10];

	bool _specialSceneScriptState[10];
	ScriptState _sceneSpecialScripts[10];
	uint32 _sceneSpecialScriptsTimer[10];
	int _lastProcessedSceneScript;
	bool _specialSceneScriptRunFlag;

	void updateSpecialSceneScripts();

	int8 _sceneDatPalette[45];
	int8 _sceneDatLayerTable[15];

	int getDrawLayer(int x, int y);

	int getScale(int x, int y);
	int _scaleTable[15];

	bool _unkSceneScreenFlag1;

	// character
	struct Character {
		uint16 sceneId;
		uint16 dlgIndex;
		uint8 unk4;
		uint8 facing;
		uint16 animFrame;
		//uint8 unk8, unk9;
		uint32 walkspeed;
		uint16 inventory[10];
		int16 x1, y1;
		int16 x2, y2;
		int16 x3, y3;
	};

	Character _mainCharacter;
	int _mainCharX, _mainCharY;
	int _charScale;

	void moveCharacter(int facing, int x, int y);

	void updateCharPosWithUpdate();
	void updateCharPos(uint8 *table, int force);

	uint32 _updateCharPosNextUpdate;
	static const int8 _updateCharPosXTable[];
	static const int8 _updateCharPosYTable[];

	void updateCharAnimFrame(int character, uint8 *table);
	int8 _characterAnimTable[2];
	static const uint8 _characterFrameTable[];

	bool _overwriteSceneFacing;

	void updateCharPal(int unk1);
	int _lastCharPalLayer;
	bool _charPalUpdate;

	// unk
	uint8 *_unkBuffer1040Bytes;
	uint8 *_costPalBuffer;
	uint8 *_screenBuffer;
	uint8 *_gfxBackUpRect;
	uint8 *_paletteOverlay;

	int _unk3, _unk4, _unk5;

	void loadCostPal();
	void loadShadowShape();
	void loadExtrasShapes();

	// opcodes
	int o3_setCharacterPos(ScriptState *script);
	int o3_refreshCharacter(ScriptState *script);
	int o3_showSceneFileMessage(ScriptState *script);
	int o3_defineItem(ScriptState *script);
	int o3_queryGameFlag(ScriptState *script);
	int o3_resetGameFlag(ScriptState *script);
	int o3_setGameFlag(ScriptState *script);
	int o3_hideMouse(ScriptState *script);
	int o3_setMousePos(ScriptState *script);
	int o3_showMouse(ScriptState *script);
	int o3_delay(ScriptState *script);
	int o3_setSceneFilename(ScriptState *script);
	int o3_getRand(ScriptState *script);
	int o3_defineRoomEntrance(ScriptState *script);
	int o3_setSpecialSceneScriptRunTime(ScriptState *script);
	int o3_defineSceneAnim(ScriptState *script);
	int o3_updateSceneAnim(ScriptState *script);
	int o3_defineScene(ScriptState *script);
	int o3_setSpecialSceneScriptState(ScriptState *script);
	int o3_clearSpecialSceneScriptState(ScriptState *script);
	int o3_querySpecialSceneScriptState(ScriptState *script);
	int o3_setHiddenItemsEntry(ScriptState *script);
	int o3_getHiddenItemsEntry(ScriptState *script);
	int o3_removeSceneAnimObject(ScriptState *script);
	int o3_dummy(ScriptState *script);

	// misc
	TextDisplayer_v3 *_text;
	bool _wsaPlayingVQA;

	// resource specific
private:
	static const char *_languageExtension[];
	static const int _languageExtensionSize;

	int getMaxFileSize(const char *file);
	char *appendLanguage(char *buf, int lang, int bufSize);

	int loadLanguageFile(const char *file, uint8 *&buffer);
};

} // end of namespace Kyra

#endif