aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra/lol.h
blob: 194d24ddf8259dcb9ba078ed7d6b0263bf5f6193 (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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
/* 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_LOL_H
#define KYRA_LOL_H

#include "kyra/kyra_v1.h"
#include "kyra/script_tim.h"
#include "kyra/script.h"

#include "common/list.h"

namespace Kyra {

class Screen_LoL;
class WSAMovie_v2;
struct Button;

struct LoLCharacter {
	uint16 flags;
	char name[11];
	uint8 raceClassSex;
	int16 id;
	uint8 curFaceFrame;
	uint8 nextFaceFrame;
	uint16 field_12;
	uint16 field_14;
	uint8 field_16;
	uint16 field_17[5];
	uint16 field_21;
	uint16 field_23;
	uint16 field_25;
	uint16 field_27[2];
	uint8 field_2B;
	uint16 field_2C;
	uint16 field_2E;
	uint16 field_30;
	uint16 field_32;
	uint16 field_34;
	uint8 field_36;
	uint16 field_37;
	uint16 hitPointsCur;
	uint16 hitPointsMax;
	uint16 magicPointsCur;
	uint16 magicPointsMax;
	uint8 field_41;
	uint16 damageSuffered;
	uint16 weaponHit;
	uint16 field_46;
	uint16 field_48;
	uint16 field_4A;
	uint16 field_4C;
	uint16 rand;
	uint16 items[11];
	uint8 field_66[3];
	uint8 field_69[3];
	uint8 field_6C;
	uint8 field_6D;
	uint16 field_6E;
	uint16 field_70;
	uint16 field_72;
	uint16 field_74;
	uint16 field_76;
	uint8 arrayUnk2[5];
	uint8 arrayUnk1[5];
};

struct SpellProperty {
	uint16 field_0;
	uint16 unkArr[4];
	uint16 field_A;
	uint16 field_C;
	uint16 field_E;
	uint16 spellNameCode;
	uint16 mpRequired[4];
	uint16 field_1A;
};

struct CMZ {
	uint8 unk[4];
	uint16 itemIndex;
	uint8 field_6;
	uint8 field_7;
	uint8 field_8;
	uint8 flags;
};

struct LVL {
	uint8 field_0;
	uint8 field_1;
	uint8 field_2;
	uint8 field_3;
	uint8 field_4;
	uint16 cmzIndex;
	uint16 p_1a;
	uint16 p_1b;
	uint8 field_B;
	uint16 p_2a;
	uint16 p_2b;
	uint8 field_10;
	uint8 field_11;
	uint8 field_12;
	uint8 field_13;
	uint8 field_14;
	uint8 field_15;
	uint8 field_16;
	uint8 field_17;
	uint8 field_18;
	uint16 field_19;
	uint8 field_1B;
	uint8 field_1C;
	int16 field_1D;
	uint8 field_1F;
	uint8 field_20;
	uint8 *offs_lvl415;
	uint8 field_25;
	uint8 field_26;
	uint8 field_27;
	uint8 field_28;
	uint8 field_29;
	uint8 field_2A;
	uint8 field_2B;
	uint8 field_2C;
	uint8 field_2D;
	uint8 field_2E;
};

struct LevelShapeProperty {
	uint16 shapeIndex[10];
	uint8 scaleFlag[10];
	uint16 shapeX[10];
	uint16 shapeY[10];
	int8 next;
	uint8 flags;
};

struct CompassDef {
	uint8 shapeIndex;
	int8 x;
	int8 y;
	uint8 flags;
};

struct ScriptOffsUnkStruct {
	uint8 field_0;
	uint8 field_1;
	uint8 field_2;
	uint8 field_3;
	uint8 field_4;
	uint8 field_5;
	uint8 field_6;
	uint8 field_7;
	uint8 field_8;
};

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

	Screen *screen();
private:
	Screen_LoL *_screen;
	TIMInterpreter *_tim;

	Common::Error init();
	Common::Error go();

	// initialization
	void initStaticResource();
	void preInit();

	void initializeCursors();
	int mainMenu();

	void startup();
	void startupNew();

	void runLoop();

	// mouse
	void setMouseCursorToIcon(int icon);
	void setMouseCursorToItemInHand();
	uint8 *getItemIconShapePtr(int index);

	// intro
	void setupPrologueData(bool load);

	void showIntro();

	struct CharacterPrev {
		const char *name;
		int x, y;
		int attrib[3];
	};

	static const CharacterPrev _charPreviews[];

	WSAMovie_v2 *_chargenWSA;
	static const uint8 _chargenFrameTable[];
	int chooseCharacter();

	void kingSelectionIntro();
	void kingSelectionReminder();
	void kingSelectionOutro();
	void processCharacterSelection();
	void updateSelectionAnims();
	int selectionCharInfo(int character);
	void selectionCharInfoIntro(char *file);

	int getCharSelection();
	int selectionCharAccept();

	int _charSelection;
	int _charSelectionInfoResult;

	uint32 _selectionAnimTimers[4];
	uint8 _selectionAnimFrames[4];
	static const uint8 _selectionAnimIndexTable[];

	static const uint16 _selectionPosTable[];

	static const uint8 _selectionChar1IdxTable[];
	static const uint8 _selectionChar2IdxTable[];
	static const uint8 _selectionChar3IdxTable[];
	static const uint8 _selectionChar4IdxTable[];

	static const uint8 _reminderChar1IdxTable[];
	static const uint8 _reminderChar2IdxTable[];
	static const uint8 _reminderChar3IdxTable[];
	static const uint8 _reminderChar4IdxTable[];

	static const uint8 _charInfoFrameTable[];

	// timer
	void setupTimers() {}

	// sound
	void snd_playVoiceFile(int) { /* XXX */ }
	void snd_playSoundEffect(int track, int volume);

	int _lastSfxTrack;

	int _unkAudioSpecOffs;
	bool _unkLangAudio;

	char **_ingameSoundList;
	int _ingameSoundListSize;

	const uint16 *_ingameSoundIndex;
	int _ingameSoundIndexSize;
	const uint8 *_ingameGMSoundIndex;
	int _ingameGMSoundIndexSize;
	const uint8 *_ingameMT32SoundIndex;
	int _ingameMT32SoundIndexSize;

	// gui
	void gui_drawPlayField();
	void gui_drawScene(int pageNum);
	void gui_drawAllCharPortraitsWithStats();
	void gui_drawCharPortraitWithStats(int charNum);
	void gui_drawPortraitBox(int x, int y, int w, int h, int frameColor1, int frameColor2, int fillColor);
	void gui_drawCharFaceShape(int charNum, int x, int y, int pageNum);
	void gui_drawLiveMagicBar(int x, int y, int curPoints, int unk, int maxPoints, int w, int h, int col1, int col2, int flag);
	void gui_drawMoneyBox(int pageNum);
	void gui_drawInventory();
	void gui_drawInventoryItem(int index);
	void gui_drawCompass();
	void gui_drawScroll();

	bool _weaponsDisabled;
	int _unkDrawPortraitIndex;
	int _updateUnk2;
	int _compassDirectionIndex;

	const CompassDef *_compassDefs;
	int _compassDefsSize;

	// emc scripts
	void runInitScript(const char *filename, int func);
	void runInfScript(const char *filename);
	void runResidentScript(int func, int reg0);
	void runResidentScriptCustom(int func, int reg0, int reg1, int reg2, int reg3, int reg4);
	bool checkScriptUnk(int func);
	
	EMCData _scriptData;
	bool _scriptBoolSkipExec;
	uint8 _unkScriptByte;
	uint16 _unkPara2;
	uint16 _currentBlock;
	bool _boolScriptFuncDone;
	int16 _scriptExecutedFuncs[18];

	uint16 _gameFlags[15];

	// emc opcode
	int o2_setGameFlag(EMCState *script);
	int o2_testGameFlag(EMCState *script);
	int o2_loadLevelSupplemenaryFiles(EMCState *script);
	int o2_loadCmzFile(EMCState *script);
	int o2_loadMonsterShapes(EMCState *script);
	int o2_allocItemPropertiesBuffer(EMCState *script);
	int o2_setItemProperty(EMCState *script);
	int o2_makeItem(EMCState *script);	
	int o2_getItemPara(EMCState *script);
	int o2_getCharacterStat(EMCState *script);
	int o2_setCharacterStat(EMCState *script);
	int o2_loadLevelShapes(EMCState *script);
	int o2_closeLevelShapeFile(EMCState *script);
	int o2_loadDoorShapes(EMCState *script);
	int o2_setGlobalVar(EMCState *script);
	int o2_mapShapeToBlock(EMCState *script);
	int o2_resetBlockShapeAssignment(EMCState *script);
	int o2_setPaletteBrightness(EMCState *script);
	int o2_assignCustomSfx(EMCState *script);

	// tim opcode
	void setupOpcodeTable();

	Common::Array<const TIMOpcode*> _timIntroOpcodes;
	int tlol_setupPaletteFade(const TIM *tim, const uint16 *param);
	int tlol_loadPalette(const TIM *tim, const uint16 *param);
	int tlol_setupPaletteFadeEx(const TIM *tim, const uint16 *param);
	int tlol_processWsaFrame(const TIM *tim, const uint16 *param);
	int tlol_displayText(const TIM *tim, const uint16 *param);

	// translation
	int _lang;

	uint8 *_landsFile;
	uint8 *_levelLangFile;

	int _lastUsedStringBuffer;
	char _stringBuffer[5][512];	// TODO: The original used a size of 512, it looks a bit large.
								// Maybe we can someday reduce the size.
	const char *getLangString(uint16 id);
	uint8 *getTableEntry(uint8 *buffer, uint16 id);

	static const char * const _languageExt[];

	// graphics
	void setupScreenDims();

	uint8 **_itemIconShapes;
	int _numItemIconShapes;
	uint8 **_itemShapes;
	int _numItemShapes;
	uint8 **_gameShapes;
	int _numGameShapes;
	uint8 **_thrownShapes;
	int _numThrownShapes;
	uint8 **_iceShapes;
	int _numIceShapes;
	uint8 **_fireballShapes;
	int _numFireballShapes;

	const int8 *_gameShapeMap;
	int _gameShapeMapSize;

	uint8 *_characterFaceShapes[40][3];

	// characters
	bool addCharacter(int id);
	void initCharacter(int charNum, int firstFaceFrame, int unk2, int redraw);
	void initCharacterUnkSub(int charNum, int unk1, int unk2, int unk3);
	int countActiveCharacters();
	void loadCharFaceShapes(int charNum, int id);
	void calcCharPortraitXpos();

	void updatePortraitWithStats();
	void updatePortraits();
	void updatePortraitUnkTimeSub(int unk1, int unk2);

	void setCharFaceFrame(int charNum, int frameNum);
	void faceFrameRefresh(int charNum);

	LoLCharacter *_characters;
	uint16 _activeCharsXpos[3];
	int _charFlagUnk;
	int _updateCharNum;
	int _updateCharV1;
	int _updateCharV2;
	int _updateCharV3;
	int _updateCharV4;
	int _updateCharV5;
	int _updateCharV6;
	uint32 _updateCharTime;
	uint32 _updatePortraitNext;

	int _loadLevelFlag;
	int _levelFlagUnk;

	uint8 **_monsterShapes;
	uint8 **_monsterPalettes;
	uint8 **_buf4;
	uint8 _monsterUnk[3];

	const LoLCharacter *_charDefaults;
	int _charDefaultsSize;

	// level
	void loadLevel(int index);
	void addLevelItems();
	int initCmzWithScript(int block);
	void initCMZ1(LVL *l, int a);
	void initCMZ2(LVL *l, uint16 a, uint16 b);
	int cmzS1(uint16 a, uint16 b, uint16 c, uint16 d);
	void cmzS2(LVL *l, int a);
	void cmzS3(LVL *l);
	void cmzS4(uint16 &itemIndex, int a);
	int cmzS5(uint16 a, uint16 b);
	void cmzS6(uint16 &itemIndex, int a);
	void cmzS7(int itemIndex, int a);
	void loadLevelWLL(int index, bool mapShapes);
	void moveItemToCMZ(uint16 *cmzItemIndex, uint16 item);
	int assignLevelShapes(int index);
	uint8 *getLevelShapes(int index);
	void loadLevelCMZ(int index);
	void loadCMZ_Sub(int index1, int index2);
	void loadCmzFile(const char *file);
	void loadMonsterShapes(const char *file, int monsterIndex, int b);
	void releaseMonsterShapes(int monsterIndex);
	void loadLevelShpDat(const char *shpFile, const char *datFile, bool flag);
	void loadLevelSupplemenaryFiles(const char *file, int specialColor, int weight, int vcnLen, int vmpLen, const char *langFile);

	void drawScene(int pageNum);

	void generateBlockDrawingBuffer(int block, int b);
	void generateBlockDrawingBufferF0(int16 wllOffset, uint8 wllIndex, uint8 wllVmpIndex, int16 vmpOffset, uint8 len, uint8 numEntries);
	void generateBlockDrawingBufferF1(int16 wllOffset, uint8 wllIndex, uint8 wllVmpIndex, int16 vmpOffset, uint8 len, uint8 numEntries);
	bool testWllBuffer5Value(int index);
	void assignBlockCaps(int a, int b);

	void drawVcnBlocks(uint8 *vcnBlocks, uint16 *blockDrawingBuffer, uint8 *vcnShift, int pageNum);
	void drawSceneShapes();
	void setLevelShapesDim(int index, int16 &x1, int16 &x2, int dim);
	void scaleLevelShapesDim(int index, int16 &y1, int16 &y2, int dim);
	void drawLevelModifyScreenDim(int dim, int16 x1, int16 y1, int16 x2, int16 y2);
	void drawDecorations(int index);
	void drawIceShapes(int index, int iceShapeIndex);
	void drawDoor(uint8 *shape, uint8 *table, int index, int unk2, int w, int h, int flags);
	void drawDoorShapes(uint8 *shape, uint8 *table, int x, int y, int flags, const uint8 *ovl);
	void drawScriptShapes(int pageNum);
	void updateSceneWindow();

	void turnOnLamp();
	void updateLampStatus();

	void setLF1(uint16 & a, uint16 & b, int block, uint16 d, uint16 e);
	void setLF2(int block);
	
	int _unkFlag;
	int _scriptFuncIndex;
	uint8 _currentLevel;
	bool _loadLevelFlag2;
	int _lvlBlockIndex;
	int _lvlShapeIndex;
	bool _unkDrawLevelBool;
	uint8 *_vcnBlocks;
	uint8 *_vcnShift;
	uint8 *_vcnExpTable;
	uint16 *_vmpPtr;
	uint16 *_blockDrawingBuffer;
	uint8 *_sceneWindowBuffer;
	LevelShapeProperty *_levelShapeProperties;
	uint8 **_levelShapes;

	char _lastSuppFile[12];
	char _lastSuppLangFile[12];
	char *_lastSuppLangFilePtr;
	int _lastSpecialColor;
	int _lastSpecialColorWeight;

	int _sceneDrawVar1;
	int _sceneDrawVar2;
	int _sceneDrawVar3;
	int _wllProcessFlag;

	uint8 *_tlcTable2;
	uint8 *_tlcTable1;

	int _loadSuppFilesFlag;

	int _lampOilStatus;
	int _brightness;
	int _lampStatusUnk;
	uint32 _lampStatusTimer;

	uint8 *_wllVmpMap;
	int8 *_wllShapeMap;
	uint8 *_wllBuffer3;
	uint8 *_wllBuffer4;
	uint8 *_wllBuffer5;

	int16 *_lvlShapeTop;
	int16 *_lvlShapeBottom;
	int16 *_lvlShapeLeftRight;

	CMZ *_cmzBuffer;
	CMZ *_curBlockCaps[18];
	LVL *_lvlBuffer;
	uint8 *_lvl415;

	uint16 _unkCmzU1;
	uint16 _unkCmzU2;
	
	Common::SeekableReadStream *_lvlShpFileHandle;
	uint16 _lvlShpNum;
	uint32 *_lvlShpHeader;
	uint16 _levelFileDataSize;
	LevelShapeProperty *_levelFileData;

	uint8 *_doorShapes[2];
	int16 _shpDoorX;
	int16 _shpDoorY;
	int16 _doorScaleW;
	int16 _doorScaleH;

	uint8 _unkGameFlag;

	uint8 *_tempBuffer5120;
	
	const char *const * _levelDatList;
	int _levelDatListSize;
	const char *const * _levelShpList;
	int _levelShpListSize;

	const int8 *_dscUnk1;
	int _dscUnk1Size;
	const int8 *_dscShapeIndex;
	int _dscShapeIndexSize;
	const uint8 *_dscOvlMap;
	int _dscOvlMapSize;
	const uint16 *_dscShapeScaleW;
	int _dscShapeScaleWSize;
	const uint16 *_dscShapeScaleH;
	int _dscShapeScaleHSize;
	const int16 *_dscShapeX;
	int _dscShapeXSize;
	const int8 *_dscShapeY;
	int _dscShapeYSize;
	const uint8 *_dscTileIndex;
	int _dscTileIndexSize;
	const uint8 *_dscUnk2;
	int _dscUnk2Size;
	const uint8 *_dscDoorShpIndex;
	int _dscDoorShpIndexSize;
	const int8 *_dscDim1;
	int _dscDim1Size;
	const int8 *_dscDim2;
	int _dscDim2Size;
	const uint8 *_dscBlockMap;
	int _dscBlockMapSize;
	const uint8 *_dscDimMap;
	int _dscDimMapSize;
	const uint8 *_dscDoor2;
	int _dscDoor2Size;
	const uint16 *_dscDoorScaleTable;
	int _dscDoorScaleTableSize;
	const uint16 *_dscDoor4;
	int _dscDoor4Size;
	const uint8 *_dscShapeOvlIndex;
	int _dscShapeOvlIndexSize;
	const int8 *_dscBlockIndex;
	int _dscBlockIndexSize;
	const uint8 *_dscDoor1;
	int _dscDoor1Size;
	const int16 *_dscDoorX;
	int _dscDoorXSize;
	const int16 *_dscDoorY;
	int _dscDoorYSize;
	
	int _sceneDrawPage1;
	int _sceneDrawPage2;

	// items
	struct ItemInPlay {
		uint16 itemIndexUnk;
		uint8 unk2;
		uint16 unk3;
		uint16 cmzIndex;
		uint16 unk7;
		uint16 anonymous_4;
		int8 level;
		uint16 itemPropertyIndex;
		uint16 shpCurFrame_flg;
		uint8 field10;
		uint16 anon8;
		uint8 anon9;
	};

	struct ItemProperty {
		uint16 nameStringId;
		uint8 shpIndex;
		uint16 flags;
		uint16 unk5;
		uint8 itemScriptFunc;
		uint8 unk8;
		uint8 unk9;
		uint8 unkA;
		uint16 unkB;
		uint8 unkD;
	};

	void giveCredits(int credits, int redraw);
	int makeItem(int itemIndex, int curFrame, int flags);
	bool testUnkItemFlags(int itemIndex);
	void clearItemTableEntry(int itemIndex);
	void *cmzGetItemOffset(uint16 index);
	void runItemScript(int reg1, int item, int reg0, int reg3, int reg4);

	uint8 _moneyColumnHeight[5];
	uint16 _credits;

	ItemInPlay *_itemsInPlay;
	ItemProperty *_itemProperties;

	int _itemInHand;
	uint16 _inventoryItemIndex[48];
	int _inventoryCurItem;
	int _unkInventFlag;

	EMCData _itemScript;

	// spells
	int8 _availableSpells[7];
	int _selectedSpell;
	const SpellProperty *_spellProperties;
	int _spellPropertiesSize;

	// unneeded
	void setWalkspeed(uint8) {}
	void setHandItem(uint16) {}
	void removeHandItem() {}
	bool lineIsPassable(int, int) { return false; }

	// save
	Common::Error loadGameState(int slot) { return Common::kNoError; }
	Common::Error saveGameState(int slot, const char *saveName, const Graphics::Surface *thumbnail) { return Common::kNoError; }
};

} // end of namespace Kyra

#endif