aboutsummaryrefslogtreecommitdiff
path: root/engines/lure/res_struct.h
blob: e2f596292bf599d48dbd973dc771fa6ed2137f96 (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
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
/* 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 LURE_RESSTRUCT_H
#define LURE_RESSTRUCT_H

#include "lure/luredefs.h"
#include "common/list.h"
#include "common/file.h"
#include "common/ptr.h"

namespace Lure {

using namespace Common;

/*-------------------------------------------------------------------------*/
/* Structure definitions                                                   */
/*                                                                         */
/*-------------------------------------------------------------------------*/

/* HACK/FIXME: three structs are misaligned (at least on 4-byte aligned system,
   should have more troubles with coming 64bit systems), GET_NEXT let us read
   properly sequence of struct in lure.dat hardcoding size of struct.
*/

#define GET_NEXT(v, sc)		v = (sc *)(((byte *)v) + kSizeOf##sc)

#define kSizeOfRoomExitJoinResource			13
#define kSizeOfHotspotResource				62
#define kSizeOfHotspotActionResource		3


#include "common/pack-start.h"	// START STRUCT PACKING

struct VersionStructure {
	uint16 id;
	byte vMajor;
	byte vMinor;
} PACKED_STRUCT;

struct FileEntry {
	uint16 id;
	byte unused;
	byte sizeExtension;
	uint16 size;
	uint16 offset;
} PACKED_STRUCT;

struct HotspotResource {
	uint16 hotspotId;
	uint16 nameId;
	uint16 descId;
	uint16 descId2;
	uint32 actions;
	uint16 actionsOffset;
	uint16 roomNumber;
	byte layer;
	byte scriptLoadFlag;
	uint16 loadOffset;
	uint16 startX;
	uint16 startY;
	uint16 width;
	uint16 height;
	uint16 widthCopy;
	uint16 heightCopy;
	uint16 yCorrection;
	int16 walkX;
	uint16 walkY;
	int8 talkX;
	int8 talkY;
	uint16 colourOffset;
	uint16 animRecordId;
	uint16 hotspotScriptOffset;
	uint16 talkScriptOffset;
	uint16 tickProcId;
	uint16 tickTimeout;
	uint16 tickScriptOffset;
	uint16 npcSchedule;
	uint16 characterMode;
	uint16 delayCtr;
	byte flags2;
	byte hdrFlags;
} PACKED_STRUCT;

struct HotspotAnimResource {
	uint16 animRecordId;
	uint16 animId;
	uint16 flags;
	uint16 upOffset;
	uint16 downOffset;
	uint16 leftOffset;
	uint16 rightOffset;
	uint8 upFrame;
	uint8 downFrame;
	uint8 leftFrame;
	uint8 rightFrame;
} PACKED_STRUCT;

struct MovementResource {
	uint16 frameNumber;
	int16 xChange;
	int16 yChange;
} PACKED_STRUCT;

struct RoomRect {
	int16 xs, xe;
	int16 ys, ye;
} PACKED_STRUCT;

struct RoomResource {
	uint16 roomNumber;
	uint8 hdrFlags;
	uint8 unused;
	uint32 actions;
	uint16 descId;
	uint16 numLayers;
	uint16 layers[4];
	uint16 sequenceOffset;
	int16 clippingXStart;
	int16 clippingXEnd;
	uint8 areaFlag;
	uint8 numExits;
	uint32 exitTime;
	RoomRect walkBounds;
} PACKED_STRUCT;

struct RoomExitResource {
	int16 xs, xe, ys, ye;
	uint16 sequenceOffset;
	uint8 newRoom;
	uint8 direction;
	int16 newRoomX, newRoomY;
} PACKED_STRUCT;

struct HotspotOverrideResource {
	uint16 hotspotId;
	int16 xs, xe, ys, ye;
} PACKED_STRUCT;

struct RoomExitHotspotResource {
	uint16 hotspotId;
	int16 xs, xe;
	int16 ys, ye;
	uint16 cursorNum;
	uint16 destRoomNumber;
} PACKED_STRUCT;

struct RoomExitJoinResource {
	uint16 hotspot1Id;
	byte h1CurrentFrame;
	byte h1DestFrame;
	uint8 h1OpenSound;
	uint8 h1CloseSound;
	uint16 hotspot2Id;
	byte h2CurrentFrame;
	byte h2DestFrame;
	uint8 h2OpenSound;
	uint8 h2CloseSound;
	byte blocked;
} PACKED_STRUCT;

struct HotspotActionResource {
	byte action;
	uint16 sequenceOffset;
} PACKED_STRUCT;

struct TalkHeaderResource {
	uint16 hotspotId;
	uint16 offset;
} PACKED_STRUCT;

struct TalkDataHeaderResource {
	uint16 recordId;
	uint16 listOffset;
	uint16 responsesOffset;
} PACKED_STRUCT;

struct TalkDataResource {
	uint16 preSequenceId;
	uint16 descId;
	uint16 postSequenceId;
} PACKED_STRUCT;

struct TalkResponseResource {
	uint16 sequenceId1;
	uint16 sequenceId2;
	uint16 sequenceId3;
} PACKED_STRUCT;

struct RoomExitCoordinateResource {
	int16 x;
	int16 y;
	uint16 roomNumber;
} PACKED_STRUCT;

#define ROOM_EXIT_COORDINATES_NUM_ENTRIES 6
#define ROOM_EXIT_COORDINATES_NUM_ROOMS 52

struct RoomExitCoordinateEntryResource {
	uint8 roomIndex[ROOM_EXIT_COORDINATES_NUM_ROOMS];
	RoomExitCoordinateResource entries[ROOM_EXIT_COORDINATES_NUM_ENTRIES];
} PACKED_STRUCT;

#define MAX_SCHEDULE_ENTRY_PARAMS 5

struct CharacterScheduleResource {
	uint16 action;
	uint16 params[MAX_SCHEDULE_ENTRY_PARAMS];
} PACKED_STRUCT;

struct RoomExitIndexedHotspotResource {
	uint8 roomNumber;
	uint8 hotspotIndex;
	uint16 hotspotId;
} PACKED_STRUCT;

enum SoundDescFlags {SF_IN_USE = 1, SF_RESTORE = 2};

// In desc entry, numChannels: bits 0-1 # roland, bits 2-3 #adlib, bits 4-5 #internal

struct SoundDescResource {
	uint8 soundNumber;
	uint8 channel;
	uint8 numChannels;
	uint8 flags;
	uint8 volume;
} PACKED_STRUCT;

#include "common/pack-end.h"	// END STRUCT PACKING

/** Enumeration used for direction facings */
enum Direction {UP, DOWN, LEFT, RIGHT, NO_DIRECTION};

// Support classes to hold loaded resources

class RoomExitHotspotData {
public:
	RoomExitHotspotData(RoomExitHotspotResource *rec);

	uint16 hotspotId;
	int16 xs, xe;
	int16 ys, ye;
	uint16 cursorNum;
	uint16 destRoomNumber;
};

typedef Common::List<Common::SharedPtr<RoomExitHotspotData> > RoomExitHotspotList;

class RoomExitData {
public:
	RoomExitData(RoomExitResource *rec);
	bool insideRect(int16 xp, int16 yp);

	int16 xs, xe, ys, ye;
	uint16 sequenceOffset;
	Direction direction;
	uint8 roomNumber;
	uint16 x, y;
};

class RoomExitList: public Common::List<Common::SharedPtr<RoomExitData> > {
public:
	RoomExitData *checkExits(int16 xp, int16 yp);
};

#define ROOM_PATHS_WIDTH 40
#define ROOM_PATHS_HEIGHT 24
#define ROOM_PATHS_SIZE (ROOM_PATHS_WIDTH / 8 * ROOM_PATHS_HEIGHT)
#define DECODED_PATHS_WIDTH 42
#define DECODED_PATHS_HEIGHT 26

typedef uint16 RoomPathsDecompressedData[DECODED_PATHS_WIDTH * DECODED_PATHS_HEIGHT];

class RoomPathsData {
private:
	byte _data[ROOM_PATHS_HEIGHT * ROOM_PATHS_WIDTH];
public:
	RoomPathsData() {}
	RoomPathsData(byte *srcData) { load(srcData); }

	void load(byte *srcData) {
		memcpy(_data, srcData, ROOM_PATHS_SIZE);
	}
	const byte *data() { return _data; }
	bool isOccupied(int x, int y);
	bool isOccupied(int x, int y, int width);
	void setOccupied(int x, int y, int width);
	void clearOccupied(int x, int y, int width);
	void decompress(RoomPathsDecompressedData &dataOut, int characterWidth);
};

#define MAX_NUM_LAYERS 4

class RoomData {
public:
	RoomData(RoomResource *rec, MemoryBlock *pathData);

	uint16 roomNumber;
	uint8 hdrFlags;
	uint8 flags;
	uint32 actions;
	uint16 descId;
	uint16 numLayers;
	uint16 layers[MAX_NUM_LAYERS];
	uint16 sequenceOffset;
	int16 clippingXStart;
	int16 clippingXEnd;
	uint8 areaFlag;
	uint32 exitTime;
	Common::Rect walkBounds;
	RoomExitHotspotList exitHotspots;
	RoomExitList exits;
	RoomPathsData paths;
};

class RoomDataList: public Common::List<Common::SharedPtr<RoomData> > {
public:
	void saveToStream(WriteStream *stream);
	void loadFromStream(ReadStream *stream);
};

struct RoomExitJoinStruct {
	uint16 hotspotId;
	byte currentFrame;
	byte destFrame;
	uint8 openSound;
	uint8 closeSound;
};

class RoomExitJoinData {
public:
	RoomExitJoinData(RoomExitJoinResource *rec);

	RoomExitJoinStruct hotspots[2];

	byte blocked;
};

class RoomExitJoinList: public Common::List<Common::SharedPtr<RoomExitJoinData> > {
public:
	void saveToStream(WriteStream *stream);
	void loadFromStream(ReadStream *stream);
};

class HotspotActionData {
public:
	HotspotActionData(HotspotActionResource *rec);

	Action action;
	uint16 sequenceOffset;
};

class HotspotActionList: public Common::List<Common::SharedPtr<HotspotActionData> > {
public:
	uint16 recordId;

	HotspotActionList(uint16 id, byte *data);
	uint16 getActionOffset(Action action);
};

class HotspotActionSet: public Common::List<Common::SharedPtr<HotspotActionList> > {
public:
	HotspotActionList *getActions(uint16 recordId);
};

enum CharacterMode {CHARMODE_NONE, CHARMODE_HESITATE, CHARMODE_IDLE, CHARMODE_PAUSED,
	CHARMODE_WAIT_FOR_PLAYER, CHARMODE_CONVERSING, CHARMODE_PLAYER_WAIT,
	CHARMODE_WAIT_FOR_INTERACT, CHARMODE_INTERACTING, CHARMODE_SPECIAL_PLAYER};

enum BlockedState {BS_NONE, BS_INITIAL, BS_FINAL};

enum VariantBool {VB_INITIAL, VB_FALSE, VB_TRUE};

enum CurrentAction {NO_ACTION, START_WALKING, DISPATCH_ACTION, EXEC_HOTSPOT_SCRIPT,
	PROCESSING_PATH, WALKING};

class CharacterScheduleSet;

class CharacterScheduleEntry {
private:
	CharacterScheduleSet *_parent;
	Action _action;
	uint16 _params[MAX_TELL_COMMANDS * 3];
	int _numParams;
public:
	CharacterScheduleEntry() { _action = NONE; _parent = NULL; }
	CharacterScheduleEntry(Action theAction, ...);
	CharacterScheduleEntry(CharacterScheduleSet *parentSet,
		CharacterScheduleResource *&rec);
	CharacterScheduleEntry(CharacterScheduleEntry *src);

	Action action() { return _action; }
	int numParams() { return _numParams; }
	uint16 param(int index);
	void setDetails(Action theAction, ...);
	void setDetails2(Action theAction, int numParamEntries, uint16 *paramList);
	CharacterScheduleEntry *next();
	CharacterScheduleSet *parent() { return _parent; }
	uint16 id();
};

class CurrentActionEntry {
private:
	CurrentAction _action;
	CharacterScheduleEntry *_supportData;
	uint16 _roomNumber;
	bool _dynamicSupportData;
public:
	CurrentActionEntry(CurrentAction newAction, uint16 roomNum);
	CurrentActionEntry(CurrentAction newAction, CharacterScheduleEntry *data, uint16 roomNum);
	CurrentActionEntry(Action newAction, uint16 roomNum, uint16 param1, uint16 param2);
	CurrentActionEntry(CurrentActionEntry *src);
	virtual ~CurrentActionEntry() {
		if (_dynamicSupportData) delete _supportData;
	}

	CurrentAction action() { return _action; }
	CharacterScheduleEntry &supportData() {
		if (!_supportData) error("Access made to non-defined action support record");
		return *_supportData;
	}
	bool hasSupportData() { return _supportData != NULL; }
	uint16 roomNumber() { return _roomNumber; }
	void setAction(CurrentAction newAction) { _action = newAction; }
	void setRoomNumber(uint16 roomNum) { _roomNumber = roomNum; }
	void setSupportData(CharacterScheduleEntry *newRec) {
		assert((newRec == NULL) || (newRec->parent() != NULL));
		_supportData = newRec;
	}
	void setSupportData(uint16 entryId);

	void saveToStream(WriteStream *stream);
	static CurrentActionEntry *loadFromStream(ReadStream *stream);
};

class CurrentActionStack {
private:
	typedef Common::List<Common::SharedPtr<CurrentActionEntry> > ActionsList;
	ActionsList _actions;
	void validateStack() {
		if (_actions.size() > 20)
			error("NPC character got an excessive number of pending actions");
	}
public:
	CurrentActionStack() { _actions.clear(); }

	bool isEmpty() { return _actions.begin() == _actions.end(); }
	void clear() { _actions.clear(); }
	CurrentActionEntry &top() { return **_actions.begin(); }
	CurrentAction action() { return isEmpty() ? NO_ACTION : top().action(); }
	void pop() { _actions.erase(_actions.begin()); }
	int size() { return _actions.size(); }
	void list(char *buffer);
	void list() { list(NULL); }

	void addBack(CurrentAction newAction, uint16 roomNum) {
		_actions.push_back(ActionsList::value_type(new CurrentActionEntry(newAction, roomNum)));
		validateStack();
	}
	void addBack(CurrentAction newAction, CharacterScheduleEntry *rec, uint16 roomNum) {
		_actions.push_back(ActionsList::value_type(new CurrentActionEntry(newAction, rec, roomNum)));
		validateStack();
	}
	void addBack(Action newAction, uint16 roomNum, uint16 param1, uint16 param2) {
		_actions.push_back(ActionsList::value_type(new CurrentActionEntry(newAction, roomNum, param1, param2)));
		validateStack();
	}
	void addFront(CurrentAction newAction, uint16 roomNum) {
		_actions.push_front(ActionsList::value_type(new CurrentActionEntry(newAction, roomNum)));
		validateStack();
	}
	void addFront(CurrentAction newAction, CharacterScheduleEntry *rec, uint16 roomNum) {
		_actions.push_front(ActionsList::value_type(new CurrentActionEntry(newAction, rec, roomNum)));
		validateStack();
	}
	void addFront(Action newAction, uint16 roomNum, uint16 param1, uint16 param2) {
		_actions.push_front(ActionsList::value_type(new CurrentActionEntry(newAction, roomNum, param1, param2)));
		validateStack();
	}

	void saveToStream(WriteStream *stream);
	void loadFromStream(ReadStream *stream);
	void copyFrom(CurrentActionStack &stack);
};

class HotspotData {
public:
	CurrentActionStack npcSchedule;
	HotspotData(HotspotResource *rec);

	uint16 hotspotId;
	uint16 nameId;
	uint16 descId;
	uint16 descId2;
	uint32 actions;
	uint16 actionsOffset;
	byte flags;
	uint16 roomNumber;
	byte layer;
	byte scriptLoadFlag;
	uint16 loadOffset;
	int16 startX;
	int16 startY;
	uint16 width;
	uint16 height;
	uint16 widthCopy;
	uint16 heightCopy;
	uint16 yCorrection;
	int16 walkX;
	uint16 walkY;
	int8 talkX;
	int8 talkY;
	uint16 colourOffset;
	uint16 animRecordId;
	uint16 hotspotScriptOffset;
	uint16 talkScriptOffset;
	uint16 tickProcId;
	uint16 tickTimeout;
	uint16 tickScriptOffset;
	CharacterMode characterMode;
	uint16 delayCtr;
	uint8 flags2;
	uint8 headerFlags;

	// Runtime fields
	uint16 actionCtr;
	BlockedState blockedState;
	bool blockedFlag;
	VariantBool coveredFlag;
	uint16 talkMessageId;
	uint16 talkerId;
	uint16 talkDestCharacterId;
	uint16 talkCountdown;
	uint16 pauseCtr;
	uint16 useHotspotId;
	uint16 talkGate;
	uint16 actionHotspotId;
	uint16 talkOverride;
	uint16 scriptHotspotId;

	void enable() { flags |= 0x80; }
	void disable() { flags &= 0x7F; }
	Direction nonVisualDirection() { return (Direction) scriptLoadFlag; }
	void saveToStream(WriteStream *stream);
	void loadFromStream(ReadStream *stream);
};

class HotspotDataList: public Common::List<Common::SharedPtr<HotspotData> > {
public:
	void saveToStream(WriteStream *stream);
	void loadFromStream(ReadStream *stream);
};

class HotspotOverrideData {
public:
	HotspotOverrideData(HotspotOverrideResource *rec);

	uint16 hotspotId;
	int16 xs, xe, ys, ye;
};

typedef Common::List<Common::SharedPtr<HotspotOverrideData> > HotspotOverrideList;

class MovementData {
public:
	MovementData(MovementResource *);

	uint16 frameNumber;
	int16 xChange;
	int16 yChange;
};

class MovementDataList: public Common::List<Common::SharedPtr<MovementData> > {
public:
	bool getFrame(uint16 currentFrame, int16 &xChange, int16 &yChange,
		uint16 &nextFrame);
};

class HotspotAnimData {
public:
	HotspotAnimData(HotspotAnimResource *rec);

	uint16 animRecordId;
	uint16 animId;
	uint16 flags;
	uint8 upFrame;
	uint8 downFrame;
	uint8 leftFrame;
	uint8 rightFrame;

	MovementDataList leftFrames, rightFrames;
	MovementDataList upFrames, downFrames;
};

typedef Common::List<Common::SharedPtr<HotspotAnimData> > HotspotAnimList;

// Talk header list

class TalkHeaderData {
private:
	uint16 *_data;
	int _numEntries;
public:
	TalkHeaderData(uint16 charId, uint16 *entries);
	~TalkHeaderData();

	uint16 characterId;
	uint16 getEntry(int index);
};

typedef Common::List<Common::SharedPtr<TalkHeaderData> > TalkHeaderList;

class TalkEntryData {
public:
	TalkEntryData(TalkDataResource *rec);

	uint16 preSequenceId;
	uint16 descId;
	uint16 postSequenceId;
};

typedef Common::List<Common::SharedPtr<TalkEntryData> > TalkEntryList;

class TalkData {
public:
	TalkData(uint16 id);
	~TalkData();

	uint16 recordId;
	TalkEntryList entries;
	TalkEntryList responses;

	TalkEntryData *getResponse(int index);
};

class TalkDataList: public Common::List<Common::SharedPtr<TalkData> > {
public:
	void saveToStream(WriteStream *stream);
	void loadFromStream(ReadStream *stream);
};

struct RoomExitCoordinateData {
	int16 x;
	int16 y;
	uint16 roomNumber;
	byte hotspotIndexId;
};

class RoomExitCoordinates {
private:
	RoomExitCoordinateData _entries[ROOM_EXIT_COORDINATES_NUM_ENTRIES];
	uint8 _roomIndex[ROOM_EXIT_COORDINATES_NUM_ROOMS];
public:
	RoomExitCoordinates(RoomExitCoordinateEntryResource *rec);
	RoomExitCoordinateData &getData(uint16 destRoomNumber);
};

class RoomExitCoordinatesList: public Common::List<Common::SharedPtr<RoomExitCoordinates> > {
public:
	RoomExitCoordinates &getEntry(uint16 roomNumber);
};

class RoomExitIndexedHotspotData {
public:
	RoomExitIndexedHotspotData(RoomExitIndexedHotspotResource *rec);

	uint16 roomNumber;
	uint8 hotspotIndex;
	uint16 hotspotId;
};

class RoomExitIndexedHotspotList: public Common::List<Common::SharedPtr<RoomExitIndexedHotspotData> > {
public:
	uint16 getHotspot(uint16 roomNumber, uint8 hotspotIndexId);
};

// The following classes hold any sequence offsets that are being delayed

class SequenceDelayData {
private:
	SequenceDelayData() {};
public:
	SequenceDelayData(uint16 delay, uint16 seqOffset, bool canClearFlag);
	static SequenceDelayData *load(uint32 delay, uint16 seqOffset, bool canClearFlag);

	uint32 timeoutCtr;
	uint16 sequenceOffset;
	bool canClear;
};

class SequenceDelayList: public Common::List<Common::SharedPtr<SequenceDelayData> > {
public:
	void add(uint16 delay, uint16 seqOffset, bool canClear);
	void tick();
	void clear(bool forceClear = false);

	void saveToStream(WriteStream *stream);
	void loadFromStream(ReadStream *stream);
};

// The following classes holds the data for NPC schedules

extern const int actionNumParams[NPC_JUMP_ADDRESS+1];

class CharacterScheduleSet: public Common::List<Common::SharedPtr<CharacterScheduleEntry> > {
private:
	uint16 _id;
public:
	CharacterScheduleSet(CharacterScheduleResource *rec, uint16 setId);
	uint16 getId(CharacterScheduleEntry *rec);
	uint16 id() { return _id; }
};

class CharacterScheduleList: public Common::List<Common::SharedPtr<CharacterScheduleSet> > {
public:
	CharacterScheduleEntry *getEntry(uint16 id, CharacterScheduleSet *currentSet = NULL);
};

typedef List<uint16> CharacterScheduleOffsets;

// The follow classes are used to store the NPC schedule Ids for the random actions a follower can do in each room

enum RandomActionType {REPEATABLE, REPEAT_ONCE, REPEAT_ONCE_DONE};

class RandomActionSet {
private:
	uint16 _roomNumber;
	int _numActions;
	RandomActionType *_types;
	uint16 *_ids;
public:
	RandomActionSet(uint16 *&offset);
	~RandomActionSet();

	uint16 roomNumber() { return _roomNumber; }
	int numActions() { return _numActions; }
	void getEntry(int index, RandomActionType &actionType, uint16 &id) {
		assert((index >= 0) && (index < _numActions));
		actionType = _types[index];
		id = _ids[index];
	}
	void setDone(int index) {
		assert((index >= 0) && (index < _numActions));
		assert(_types[index] == REPEAT_ONCE);
		_types[index] = REPEAT_ONCE_DONE;
	}
	void saveToStream(Common::WriteStream *stream);
	void loadFromStream(Common::ReadStream *stream);
};

class RandomActionList: public Common::List<Common::SharedPtr<RandomActionSet> > {
public:
	RandomActionSet *getRoom(uint16 roomNumber);
	void saveToStream(Common::WriteStream *stream);
	void loadFromStream(Common::ReadStream *stream);
};

class PausedCharacter {
public:
	PausedCharacter(uint16 SrcCharId, uint16 DestCharId);

	uint16 srcCharId;
	uint16 destCharId;
	uint16 counter;
	HotspotData *charHotspot;
};

class Hotspot;

class PausedCharacterList: public Common::List<Common::SharedPtr<PausedCharacter> > {
public:
	void reset(uint16 hotspotId);
	void countdown();
	void scan(Hotspot &h);
	int check(uint16 charId, int numImpinging, uint16 *impingingList);
};

struct ServeEntry {
	uint16 hotspotId;
	uint8 serveFlags;
};

#define NUM_SERVE_CUSTOMERS 4

enum BarmanGraphicType {BG_RANDOM = 0, BG_BEER = 1, BG_EXTRA1 = 2, BG_EXTRA2 = 3};

struct BarEntry {
	uint16 roomNumber;
	uint16 barmanId;
	ServeEntry customers[NUM_SERVE_CUSTOMERS];
	const uint16 *graphics[4];
	uint16 gridLine;
	ServeEntry *currentCustomer;
};

class BarmanLists {
	BarEntry _barList[3];
public:
	BarmanLists();

	void reset();
	BarEntry &getDetails(uint16 roomNumber);
	void saveToStream(Common::WriteStream *stream);
	void loadFromStream(Common::ReadStream *stream);
};

enum BarmanAction {WALK_AROUND = 1, POLISH_BAR = 2, WAIT = 3, WAIT_DIALOG = 4, SERVE_BEER = 5};

struct RoomTranslationRecord {
	uint8 srcRoom;
	uint8 destRoom;
};

extern const RoomTranslationRecord roomTranslations[];

enum StringEnum {S_CREDITS = 25, S_RESTART_GAME = 26, S_SAVE_GAME = 27, S_RESTORE_GAME = 28,
	S_QUIT = 29, S_FAST_TEXT = 30, S_SLOW_TEXT = 31, S_SOUND_ON = 32, S_SOUND_OFF = 33,
	S_ACTION_NOTHING = 34, S_FOR = 35, S_TO = 36, S_ON = 37, S_AND_THEN = 38, S_FINISH = 39,
	S_CONFIRM_YN = 40, S_YOU_ARE_CARRYING = 41, S_INV_NOTHING = 42, S_YOU_HAVE = 43,
	S_GROAT = 44, S_GROATS = 45,
	S_ARTICLE_LIST = 46};

class StringList {
private:
	MemoryBlock *_data;
	int _numEntries;
	char **_entries;
public:
	StringList() { _numEntries = 0; }
	~StringList() { clear(); }

	void load(MemoryBlock *data);
	void clear();
	int count() { return _numEntries; }
	const char *getString(int index) {
		if ((index < 0) || (index >= _numEntries)) error("Invalid index specified to String List");
		return _entries[index];
	}
	const char *getString(Action action) { return getString((int) action - 1); }
	const char *getString(StringEnum sEnum) { return getString((int) sEnum); }
};

// The following class holds the field list used by the script engine as
// well as miscellaneous fields used by the game.

#define NUM_VALUE_FIELDS 90

enum FieldName {
	ROOM_NUMBER = 0,
	CHARACTER_HOTSPOT_ID = 1,
	USE_HOTSPOT_ID = 2,
	ACTIVE_HOTSPOT_ID = 3,
	SEQUENCE_RESULT = 4,
	GENERAL = 5,
	GIVE_TALK_INDEX = 6,
	NEW_ROOM_NUMBER = 7,
	OLD_ROOM_NUMBER = 8,
	CELL_DOOR_STATE = 9,
	TORCH_HIDE = 10,
	PRISONER_DEAD = 15,
	BOTTLE_FILLED = 18,
	TALK_INDEX = 19,
	SACK_CUT = 20,
	ROOM_EXIT_ANIMATION = 76,
	AREA_FLAG = 82
};

struct PlayerNewPosition {
	Point position;
	uint16 roomNumber;
};

class ValueTableData {
private:
	uint16 _numGroats;
	PlayerNewPosition _playerNewPos;
	uint8 _textCtr1, _textCtr2; // originally 2 2-bit counters
	uint8 _hdrFlagMask;

	uint16 _fieldList[NUM_VALUE_FIELDS];
	bool isKnownField(uint16 fieldIndex);
public:
	ValueTableData();
	void reset();
	uint16 getField(uint16 fieldIndex);
	uint16 getField(FieldName fieldName);

	void setField(uint16 fieldIndex, uint16 value);
	void setField(FieldName fieldName, uint16 value);
	int size() { return NUM_VALUE_FIELDS; }

	uint16 &numGroats() { return _numGroats; }
	uint8 &textCtr1() { return _textCtr1; }
	uint8 &textCtr2() { return _textCtr2; }
	uint8 &hdrFlagMask() { return _hdrFlagMask; }
	PlayerNewPosition &playerNewPos() { return _playerNewPos; }

	void saveToStream(Common::WriteStream *stream);
	void loadFromStream(Common::ReadStream *stream);
};

} // End of namespace Lure

#endif