-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCSB.h
More file actions
4319 lines (4056 loc) · 151 KB
/
CSB.h
File metadata and controls
4319 lines (4056 loc) · 151 KB
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
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// CSB.h : main header file for the CSB application
//
#ifdef __GNUC__
#define ALIGN4 __attribute__((aligned(4)))
#else
#define ALIGN4
#endif
//#ifdef _DEBUG
#define TraceFlash(msg) traceFlash(msg)
void traceFlash(const char *msg, i32 x=-1, i32 y=-1);
void MemMove(ui8 *, ui8 *, int);
//#else
//#define TraceFlash(msg) ;
//#endif
#pragma pack(1)
#define MAX_LOADSTRING 100
#ifdef _LINUX
extern char szCSBVersion[MAX_LOADSTRING];
#else
extern char szCSBVersion[MAX_LOADSTRING];
#endif
#define FLOOR_BITMAP_SIZE 7840
#define CEILING_BITMAP_SIZE 3248
//#define TEMP_BITMAP_SIZE 10880
void AllocateTempBitmap(int size);
extern std::unique_ptr<ui8[]> g_tempBitmap;
extern int g_tempBitmapSize;
enum GAMESTATE
{
GAMESTATE_202 = 202,
GAMESTATE_ResumeSavedGame = 0,
GAMESTATE_AtPrisonDoor = 99,
GAMESTATE_EnterPrison = 1,
};
enum COLOR
{
COLOR_7 = 7,
COLOR_8 = 8,
COLOR_11 = 11,
COLOR_13 = 13
};
enum MALLOCID
{
MALLOC001 = 1,
MALLOC002,
MALLOC003,
MALLOC004,
MALLOC005,
MALLOC006,
MALLOC007,
MALLOC008,
MALLOC009,
MALLOC010,
MALLOC011,
MALLOC012,
MALLOC013,
MALLOC014,
MALLOC015,
MALLOC016,
MALLOC017,
MALLOC018,
MALLOC019,
MALLOC020,
MALLOC021,
MALLOC022,
MALLOC023,
MALLOC024,
MALLOC025,
MALLOC026,
MALLOC027,
MALLOC028,
MALLOC029,
MALLOC030,
MALLOC031,
MALLOC032,
MALLOC033,
MALLOC034,
MALLOC035,
MALLOC036,
MALLOC037,
MALLOC038,
MALLOC039,
MALLOC040,
MALLOC041,
MALLOC042,
MALLOC043,
MALLOC044,
MALLOC045,
MALLOC046,
MALLOC047,
MALLOC048,
MALLOC049,
MALLOC050,
MALLOC051,
MALLOC052,
MALLOC053,
MALLOC054,
MALLOC055,
MALLOC056,
MALLOC057,
MALLOC058,
MALLOC059,
MALLOC060,
MALLOC061,
MALLOC062,
MALLOC063,
MALLOC064,
MALLOC065,
MALLOC066,
MALLOC067,
MALLOC068,
MALLOC069,
MALLOC070,
MALLOC071,
MALLOC072,
MALLOC073,
MALLOC074,
MALLOC075,
MALLOC076,
MALLOC077,
MALLOC078,
MALLOC079,
MALLOC080,
MALLOC081,
MALLOC082,
MALLOC083,
MALLOC084,
MALLOC085,
MALLOC086,
MALLOC087,
MALLOC088,
MALLOC089,
MALLOC090,
MALLOC091,
MALLOC092,
MALLOC093,
MALLOC094,
MALLOC095,
MALLOC096,
MALLOC097,
MALLOC098,
MALLOC099,
MALLOC100,
MALLOC101,
MALLOC102,
MALLOC103,
MALLOC104,
MALLOC105,
MALLOC106,
MALLOC107,
MALLOC108,
MALLOC109,
MALLOC110,
MALLOC111,
MALLOC112,
MALLOC113,
MALLOC114,
MALLOC115,
MALLOC116,
MALLOC117,
MALLOC118,
MALLOC119,
MALLOC120,
MALLOC121,
MALLOC122,
MALLOC123,
MALLOC124,
};
class SKIN_CACHE
{
i32 m_level; // -1 if cache is empty;
i8 m_columns[16][64]; //Records from Expool.
i8 m_size[16]; //Record sizes; (-1 need to look) (0 no record exists)
ui8 *defaultSkins;
i32 Load(i32 level, i32 x);
public:
SKIN_CACHE(){m_level=-1;defaultSkins=NULL;};
~SKIN_CACHE(){};
ui8 GetSkin(i32 level, i32 x, i32 y);
void SetSkin(i32 level, i32 x, i32 y, i8 skinNum);
ui8 GetDefaultSkin(i32 level);
void Cleanup(){if (defaultSkins!=NULL)UI_free(defaultSkins);defaultSkins=NULL;m_level=-1;};
};
extern SKIN_CACHE skinCache;
extern bool drawAsSize4Monsters;
extern bool invisibleMonsters;
class TEMPORARY_MEMORY
{
public:
ui8 *m;
TEMPORARY_MEMORY(){m=NULL;};
~TEMPORARY_MEMORY(){if(m!=NULL)UI_free(m);};
};
i16 CLOSE(i32 handle);
class TEMPORARY_FILE
{
public:
i32 f;
TEMPORARY_FILE(){f=-1;};
~TEMPORARY_FILE(){Cleanup();};
void Cleanup(){if(f>=0)CLOSE(f);f=-1;};
};
struct OVERLAYDATA
{
i32 m_overlayNumber;
ui8 m_overlay[136*224];
ui32 m_overlayPalette[256];
i16 m_table[4096];
i32 m_p1, m_p2, m_p3, m_p4;
bool m_change;
OVERLAYDATA();
~OVERLAYDATA();
bool ReadOverlay(i32 overlayNumber);
void Mirror();
void CreateOverlayTable(i16 *palettte, bool useOverlay);
void Cleanup();
};
extern OVERLAYDATA currentOverlay;
struct SOUNDDATA
{
i32 m_soundNum{-1};
i32 m_size{-1}; // Size of m_sound.
ui8 *m_sound{}; // The uncompressed PCM data
~SOUNDDATA();
bool ReadSound(i32 soundNum);
void Allocate(i32 numSample);
void Cleanup();
std::unique_ptr<ui8[]> Decode(i32 volume); //Allocate memory and create an internal .wav file
};
extern SOUNDDATA currentSound;
struct SECTIONHEADER
{
unsigned type;
unsigned id;
unsigned compressedSize;
unsigned uncompressedSize;
unsigned fileOffset;
char name[16];
};
struct OVLDECODE
{
OVLDECODE(ui32 getCodeword());
~OVLDECODE();
bool GetBytes(void *buf, ui32 num);
private:
ui32 (*m_getCodeword)();
ui32 *m_codes;
ui8 *m_chars;
ui32 m_bitsRemaining;
ui32 m_codeword;
ui32 m_tableLen;
ui32 m_maxTableLen;
ui32 m_codeSize;
ui8 *m_stack;
ui32 m_stklen;
ui32 m_maxstack;
ui32 m_a, m_b, m_c, m_ch;
void EnlargeStack();
void EnlargeTable();
};
enum CSB_GRAPHICTYPE
{
CGT_ViewportOverlay = 0,
CGT_Portrait = 1,
CGT_Sound = 2,
CGT_Backgrounds = 3,
CGT_OverlayPalette = 4,
CGT_AlternateMonsterGraphic = 5,
CGT_WallDecoration = 6,
CGT_FloorDecoration = 7,
};
struct CSB_BITMAPINFOHEADER
{
ui32 biSize;
i32 biWidth;
i32 biHeight;
ui16 biPlanes;
ui16 biBitCount;
ui32 biCompression;
ui32 biSizeImage;
i32 biXPelsPerMeter;
i32 biYPelsPerMeter;
i32 biClrUsed;
ui32 biClrImportant;
};
struct CSB_BITMAPFILEHEADER
{
ui16 bfType;
ui32 bfSize;
ui16 bfReserved1;
ui16 bfReserved2;
ui32 bfOffBits;
};
ui8 *ReadCSBgraphic(CSB_GRAPHICTYPE type,
ui32 id,
ui32 minimumSize,
ui32 *actualSize,
bool mustExist,
i32 mallocID);
struct BACKGROUND_MASK
{
ui16 srcX; // In pixel units. Must be multiple of 16
ui16 srcY; // In pixel units
i16 dstX; // In pixel units
ui16 dstY; // In pixel units
ui16 width; // In pixel units
ui16 height; // In pixel units
ui16 mask[1];
};
struct AFFINEMASK
{
i32 Cxx;
i32 Cxy;
i32 Cxc;
i32 Cyx;
i32 Cyy;
i32 Cyc;
i32 srcX;
i32 srcY;
i32 srcWidth;
i32 srcHeight;
i32 dstWidth;
i32 dstHeight;
};
struct BACKGROUND_GRAPHIC
{
ui32 id;
i32 size;
ui8 *data;
};
class BACKGROUND_LIB
{
private:
BACKGROUND_GRAPHIC *backgroundGraphics;
i32 size; // Size of backgroundGraphicsArray.
i32 num;
i32 sequence;
i32 FindGraphicInCache(ui32 graphicID, bool mustExist);
i32 GetBackgroundGraphic(ui32 graphicID,
i32 minimumSize,
ui32 *actualSize,
bool mustExist);
i32 BackgroundGraphicExists(ui32 graphicID,
i32 minimumSize,
ui32 *actualSize,
bool mustExist);
i32 CreateBackgroundGraphic(ui32 graphicID,
ui32 graphicSize);
public:
BACKGROUND_LIB();
~BACKGROUND_LIB();
void Cleanup();
//ui8 *GetSkins(i32 level); //levelwidth * level height
ui16 *GetSkinDef(ui32 skinNum,
ui32 minimumSize,
ui32 *skinDefSize);
BACKGROUND_MASK *GetMask(ui32 graphicID, ui32 maskNumber, ui32 minimumSize);
BACKGROUND_MASK *MaskExists(ui32 graphicID, ui32 maskNumber);
ui32 *GetBitmap(ui32 graphicID, ui32 minimumSize, ui32 *bitmapSize);
void DumpGraphic(i32 graphicID, i32 maskNum, char *extension);
void InsertBitmap(ui32 ID, ui32 size, ui32 *address);
BACKGROUND_MASK *CreateNewMask(ui32 ID, ui32 num, BACKGROUND_MASK *pMask);
AFFINEMASK *CreateNewAffineMask(ui32 ID, ui32 num, AFFINEMASK *paffine);
void CreateVirtualMask(BACKGROUND_MASK *pOld, BACKGROUND_MASK *pNew, AFFINEMASK *paffine);
void CreateVirtualBitmap(ui32 *pGraphic,
i32 graphicSize,
i32 virtualGraphicID,
AFFINEMASK *pMask);
i32 GetDecorationBitmap(ui32 decorationID,
ui32 decorationNumber,
ui32 locationNumber,
ui16 **pBitmap,
ui8 **pLocation,
ui32 *actualSize);
ui16 GetSkinID(ui32 skinNum, ui32 IDnum);
ui16 *GetCode(ui32 skinNum);
ui16 GetWallGraphicID(ui32 skinNum);
ui16 GetFloorGraphicID(ui32 skinNum);
ui16 GetMiddleGraphicID(ui32 skinNum);
ui16 GetCeilingGraphicID(ui32 skinNum);
ui16 GetWallDecorationID(ui32 skinNum, ui32 decorationNum);
ui16 GetWallMaskID(ui32 skinNum);
ui16 GetFloorMaskID(ui32 skinNum);
ui16 GetMiddleMaskID(ui32 skinNum);
ui16 GetCeilingMaskID(ui32 skinNum);
};
extern BACKGROUND_LIB backgroundLib;
struct LOCATIONREL
{
LOCATIONREL() = default;
LOCATIONREL(i32 L, i32 X, i32 Y, i32 P=0)
{
l=L; x=X; y=Y; p=P;
};
ui32 Integer() const; //Pack in a single 18-bit integer.
LOCATIONREL *Integer(i32 i); //Unpack from 18-bit integer.
bool IsValid() const;
i32 l{-1};
i32 x;
i32 y;
i32 p;
};
struct MONSTERMOVEFILTERLOCATION
{
LOCATIONREL locr;
ui16 maxDistance;
ui16 partyLevelOnly;
RN filterObj;
};
class MONSTERMOVEFILTERCACHE
{
MONSTERMOVEFILTERLOCATION mmfloc[64];
MONSTERMOVEFILTERLOCATION global;
public:
MONSTERMOVEFILTERCACHE();
~MONSTERMOVEFILTERCACHE();
MONSTERMOVEFILTERLOCATION *GetLocation(i32 level);
void Clear();
};
extern MONSTERMOVEFILTERCACHE monsterMoveFilterCache;
struct EXTENDEDFEATURESBLOCK
{
char sentinel[20];
i32 dataMapLength;
ui32 dataTypeMapChecksum;
ui32 dataIndexMapChecksum;
ui32 extendedFeaturesChecksum;
char version;
char flags;
enum FLAGS
{
LevelDSAInfoPresent = 0x01,
SimpleEncryption = 0x04,
IndirectText = 0x08,
AutoRecord = 0x10,
ExpandedPortraits = 0x20,
DMRules = 0x40, // Designer-specified
BigActuators = 0x80
};
ui16 numDSA;
ui32 editingOptions;
ui32 gameInfoSize; // not including the trailing which is not written
ui32 cellFlagArraySize;
ui32 graphicsSignature1;
ui32 graphicsSignature2;
ui32 spellFilterLocation;
//Bit 31 set if location is valid.
ui32 extendedFlags; //Why did I think 8 would suffice?
enum EXTENDEDFLAGS
{
OverlayActive = 0x00000001,
InvisibleMonsters = 0x00000002,
DrawAsSize4Monsters = 0x00000004,
DMRulesOption = 0x00000008, //player-specified
ExtendedWallDecorations = 0x00000010,
SequencedTimers = 0x00000020,
DefaultDirectX = 0x00000040,
ExtendedTimers = 0x00000080, // 32-bit time + 8-bit level.
};
i32 overlayOrdinal; //overlay Number + 1
i32 overlayP1;
i32 overlayP2;
i32 overlayP3;
i32 overlayP4;
ui32 CSBgraphicsSignature1;
ui32 CSBgraphicsSignature2;
char hintKey[8];
char fill[512-104];
};
enum ICOUNTER
{
icntPumpMsg = 0,
icntVBL = 1,
icntVBLLoop = 2,
icntRemoveCursor=3,
icntCreateCursorBitmap=4,
icntGetCursorPos=5,
icntInvalidate=6,
icntCopyViewportToScreen=7,
icntFloorAndCeiling=8,
icntPlaceCursor=9,
icntTAG002336=10,
icntDisplayCharacterDamage=11,
icntTAG0197d2=12,
numInstrumentation
};
class ICOUNTS
{
public:
i32 m_InstrumentationCounts[numInstrumentation];
ICOUNTS();
};
#define Instrumentation(i) InstrumentationCounts.m_InstrumentationCounts[i]++;
extern ICOUNTS InstrumentationCounts;
enum GRAPHICROOMTYPE
{
gRoomSTONE = 0,
gRoomOPEN = 1,
gRoomPIT = 2,
gRoomTELEPORTER = 3,
gRoomDOOREDGE = 4, //A door seen on edge
gRoomDOORFACING = 5, //A door seen on flat side
gRoomSTAIREDGE = 6, //Stairway at right angle to party facing
gRoomSTAIRFACING= 7 //Stairway in direction party is facing
};
enum ROOMTYPE
{
roomSTONE = 0,
roomOPEN = 1,
roomPIT = 2,
roomSTAIRS = 3,
roomDOOR = 4,
roomTELEPORTER = 5,
roomFALSEWALL = 6,
roomDOOREDGE = 16, //A door seen on edge
roomDOORFACING = 17, //A door seen on flat side
roomSTAIREDGE = 18, //Stairway at right angle to party facing
roomSTAIRFACING= 19, //Stairway in direction party is facing
roomEXTERIOR = 20 //Exterior wall of dungeon
};
enum ATTACKTYPE
{
atk_JUGGLE = 0, //Not in CSB
atk_BLOCK = 1,
atk_CHOP = 2,
atk_SPEED = 3, //Not in CSB
atk_BLOWHORN = 4,
atk_FLIP = 5,
atk_PUNCH = 6,
atk_KICK = 7,
atk_WARCRY = 8,
atk_STAB1 = 9,
atk_CLIMBDOWN = 10,
atk_FREEZELIFE = 11,
atk_HIT = 12,
atk_SWING = 13,
atk_STAB2 = 14,
atk_THRUST = 15,
atk_JAB = 16,
atk_PARRY = 17,
atk_HACK = 18,
atk_BERZERK = 19,
atk_FIREBALL = 20,
atk_DISPELL = 21,
atk_CONFUSE = 22,
atk_LIGHTNING = 23,
atk_DISRUPT = 24,
atk_MELEE = 25,
atk_PRAY = 26, // Not in CSB
atk_INVOKE = 27,
atk_SLASH = 28,
atk_CLEAVE = 29,
atk_BASH = 30,
atk_STUN = 31,
atk_SHOOT = 32,
atk_SPELLSHIELD = 33,
atk_FIRESHIELD = 34,
atk_FLUXCAGE = 35,
atk_HEAL = 36,
atk_CALM = 37,
atk_LIGHT = 38,
atk_WINDOW = 39,
atk_SPIT = 40,
atk_BRANDISH = 41,
atk_THROW = 42,
atk_FUSE = 43
};
#define soundPRESSUREPAD 1
#define soundMONDEATH 4
#define soundTELEPORT 17
#define soundDOOROPENING 18
#define Luck 0 // What is this? Rabbit's foot adds 10!
#define Strength 1
#define Dexterity 2
#define Wisdom 3
#define Vitality 4
#define AntiMagic 5
#define AntiFire 6
//inline ROOMTYPE RoomType(CELLFLAG cf) {return (ROOMTYPE)(cf>>5);};
// Not needed. CELLFLAG automatically promoted to i32.
inline ROOMTYPE RoomType(i32 cf) {return (ROOMTYPE)(cf>>5);};
typedef ui16 DIRECTION;
extern DIRECTION dirNORTH, dirEAST, dirSOUTH, dirWEST;
class ICONDISPLAY
{
public:
i16 pixelX;
i16 pixelY;
private:
i16 m_objectType; //OBJECTTYPE /cannot access directly because
//VC++ wants to allocate 32 bits.
public:
OBJ_NAME_INDEX objectType() {return (OBJ_NAME_INDEX)m_objectType;};
void objectType(OBJ_NAME_INDEX obj) {m_objectType=(i16)obj;};
};
struct SUMMARIZEROOMDATA
{
i32 x, y, relativeCellNumber;
i32 skinNumber;
ROOMTYPE roomType;
i32 championPortraitOrdinal;
GRAPHICROOMTYPE graphicRoomType;
RN rn2;
i32 decorations[3]; //right, front, left
RN text[3]; //right, front, left
};
#define BITS0_0(x) (UI8)((((x) )&0x0001))
#define BITS0_1(x) (UI8)((((x) )&0x0003))
#define BITS0_2(x) (UI8)((((x) )&0x0007))
#define BITS0_3(x) (UI8)((((x) )&0x000f))
#define BITS0_4(x) (UI8)((((x) )&0x001f))
#define BITS0_5(x) (UI8)((((x) )&0x003f))
#define BITS0_6(x) (UI8)((((x) )&0x007f))
#define BITS0_7(x) (UI8)((((x) )&0x00ff))
#define BITS0_9(x) (((x) )&0x03ff)
#define BITS0_8(x) (((x) )&0x00ff)
#define BITS1_1(x) (((x)>> 1)&0x0001)
#define BITS1_2(x) (((x)>> 1)&0x0003)
#define BITS1_4(x) (((x)>> 1)&0x000f)
#define BITS2_2(x) (((x)>> 2)&0x0001)
#define BITS3_4(x) (((x)>> 3)&0x0003)
#define BITS3_15(x) (((x)>> 3)&0x1fff)
#define BITS4_5(x) (UI8) ((((x)>> 4)&0x0003))
#define BITS4_7(x) (UI8) ((((x)>> 4)&0x000f))
#define BITS4_9(x) (UI8) ((((x)>> 4)&0x003f))
#define BITS4_11(x) (UI8) ((((x)>> 4)&0x00ff))
#define BITS4_15(x) (UI16)((((x)>> 4)&0x0fff))
#define BITS5_5(x) (UI8) ((((x)>> 5)&0x0001))
#define BITS5_6(x) (UI8) ((((x)>> 5)&0x0003))
#define BITS5_9(x) (UI8) ((((x)>> 5)&0x001f))
#define BITS5_15(x) (UI16)((((x)>> 5)&0x07ff))
#define BITS6_6(x) (UI8)((((x)>> 6)&0x0001))
#define BITS6_7(x) (UI8)((((x)>> 6)&0x0003))
#define BITS6_10(x) (UI8)((((x)>> 6)&0x001f))
#define BITS6_11(x) (UI8)((((x)>> 6)&0x003f))
#define BITS7_7(x) (UI8)((((x)>> 7)&0x0001))
#define BITS7_8(x) (UI8)((((x)>> 7)&0x0003))
#define BITS7_10(x) (UI8)((((x)>> 7)&0x000f))
#define BITS7_11(x) (UI8)((((x)>> 7)&0x001f))
#define BITS7_15(x) (UI16)((((x)>> 7)&0x01ff))
#define BITS8_8(x) (UI8)((((x)>> 8)&0x0001))
#define BITS8_11(x) (UI8)((((x)>> 8)&0x000f))
#define BITS8_9(x) (UI8)((((x)>> 8)&0x0003))
#define BITS8_12(x) (UI8)((((x)>> 8)&0x001f))
#define BITS8_14(x) (UI8)((((x)>> 8)&0x007f))
#define BITS8_15(x) (UI8)((((x)>> 8)&0x00ff))
#define BITS9_9(x) (UI8)((((x)>> 9)&0x0001))
#define BITS9_11(x) (UI8)((((x)>> 9)&0x0007))
#define BITS9_12(x) (UI8)((((x)>> 9)&0x000f))
#define BITS9_13(x) (UI8)((((x)>> 9)&0x001f))
#define BITS9_15(x) (UI8)((((x)>> 9)&0x007f))
#define BITS10_10(x) (UI8)((((x)>>10)&0x0001))
#define BITS10_13(x) (UI8)((((x)>>10)&0x000f))
#define BITS10_14(x) (UI8)((((x)>>10)&0x001f))
#define BITS10_11(x) (UI8)((((x)>>10)&0x0003))
#define BITS10_15(x) (UI8)((((x)>>10)&0x003f))
#define BITS11_11(x) (UI8)((((x)>>11)&0x0001))
#define BITS11_15(x) (UI8)((((x)>>11)&0x001f))
#define BITS12_12(x) (UI8)((((x)>>12)&0x0001))
#define BITS12_13(x) (UI8)((((x)>>12)&0x0003))
#define BITS12_15(x) (UI8)((((x)>>12)&0x000f))
#define BITS13_13(x) (UI8)((((x)>>13)&0x0001))
#define BITS13_14(x) (UI8)((((x)>>13)&0x0003))
#define BITS13_15(x) (UI8)((((x)>>13)&0x0007))
#define BITS14_14(x) (UI8)((((x)>>14)&0x0001))
#define BITS14_15(x) (UI8)((((x)>>14)&0x0003))
#define BITS15_15(x) (UI8)((((x)>>15)&0x0001))
#define SETBBITS0_0(d,s) (d) = (I8)(((d)&0xfffe)|(((s)&0x0001) ))
#define SETBBITS0_2(d,s) (d) = (I8)(((d)&0xfff8)|(((s)&0x0007) ))
#define SETWBITS0_0(d,s) (d) = (i16)(((d)&0xfffe)|(((s)&0x0001) ))
#define SETWBITS0_2(d,s) (d) = (i16)(((d)&0xfff8)|(((s)&0x0007) ))
#define SETWBITS0_3(d,s) (d) = (i16)(((d)&0xfff0)|(((s)&0x000f) ))
#define SETWBITS0_4(d,s) (d) = (i16)(((d)&0xffe0)|(((s)&0x001f) ))
#define SETWBITS0_5(d,s) (d) = (i16)(((d)&0xffc0)|(((s)&0x003f) ))
#define SETWBITS0_6(d,s) (d) = (i16)(((d)&0xff80)|(((s)&0x007f) ))
#define SETWBITS0_7(d,s) (d) = (i16)(((d)&0xff00)|(((s)&0x00ff) ))
#define SETWBITS3_15(d,s) (d) = (i16)(((d)&0x0007)|(((s)&0x1fff)<< 3))
#define SETWBITS5_6(d,s) (d) = (i16)(((d)&0xff9f)|(((s)&0x0003)<< 5))
#define SETWBITS5_9(d,s) (d) = (i16)(((d)&0xfc1f)|(((s)&0x001f)<< 5))
#define SETWBITS6_7(d,s) (d) = (i16)(((d)&0xff3f)|(((s)&0x0003)<< 6))
#define SETWBITS6_11(d,s) (d) = (i16)(((d)&0xf03f)|(((s)&0x003f)<< 6))
#define SETWBITS7_7(d,s) (d) = (i16)(((d)&0xff7f)|(((s)&0x0001)<< 7))
#define SETWBITS7_15(d,s) (d) = (i16)(((d)&0x007f)|(((s)&0x01ff)<< 7))
#define SETWBITS8_8(d,s) (d) = (i16)(((d)&0xfeff)|(((s)&0x0001)<< 8))
#define SETWBITS8_9(d,s) (d) = (i16)(((d)&0xfcff)|(((s)&0x0003)<< 8))
#define SETWBITS8_14(d,s) (d) = (i16)(((d)&0x80ff)|(((s)&0x007f)<< 8))
#define SETWBITS8_15(d,s) (d) = (i16)(((d)&0x00ff)|(((s)&0x00ff)<< 8))
#define SETWBITS9_9(d,s) (d) = (i16)(((d)&0xfdff)|(((s)&0x0001)<< 9))
#define SETWBITS9_11(d,s) (d) = (i16)(((d)&0xf1ff)|(((s)&0x0007)<< 9))
#define SETWBITS9_12(d,s) (d) = (i16)(((d)&0xe1ff)|(((s)&0x000f)<< 9))
#define SETWBITS9_13(d,s) (d) = (i16)(((d)&0xc1ff)|(((s)&0x001f)<< 9))
#define SETWBITS10_10(d,s) (d) = (i16)(((d)&0xfbff)|(((s)&0x0001)<<10))
#define SETWBITS11_11(d,s) (d) = (i16)(((d)&0xf7ff)|(((s)&0x0001)<<11))
#define SETWBITS12_12(d,s) (d) = (i16)(((d)&0xefff)|(((s)&0x0001)<<12))
#define SETWBITS10_11(d,s) (d) = (i16)(((d)&0xf3ff)|(((s)&0x0003)<<10))
#define SETWBITS10_13(d,s) (d) = (i16)(((d)&0xc3ff)|(((s)&0x000f)<<10))
#define SETWBITS10_15(d,s) (d) = (i16)(((d)&0x03ff)|(((s)&0x003f)<<10))
#define SETWBITS12_13(d,s) (d) = (i16)(((d)&0xcfff)|(((s)&0x0003)<<12))
#define SETWBITS12_15(d,s) (d) = (i16)(((d)&0x0fff)|(((s)&0x000f)<<12))
#define SETWBITS13_13(d,s) (d) = (i16)(((d)&0xdfff)|(((s)&0x0001)<<13))
#define SETWBITS13_14(d,s) (d) = (i16)(((d)&0x9fff)|(((s)&0x0003)<<13))
#define SETWBITS14_14(d,s) (d) = (i16)(((d)&0xbfff)|(((s)&0x0001)<<14))
#define SETWBITS14_15(d,s) (d) = (i16)(((d)&0x3fff)|(((s)&0x0003)<<14))
#define SETWBITS15_15(d,s) (d) = (i16)(((d)&0x7fff)|(((s)&0x0001)<<15))
#define SETIBITS24_35(d,s) (d) = (i32)(((d)&0xffffff)|(((s)&0xff)<<24))
class DBCOMMON
{
friend class DB0;
friend class DB1;
friend class DB2;
friend class DB3;
friend class DB4;
friend class DB5;
friend class DB6;
friend class DB7;
friend class DB8;
friend class DB9;
friend class DB10;
friend class DB11;
friend struct DB14;
friend struct DB15;
friend void ConvertListOfObjects(RN *, bool,i32 level, i32 x, i32 y);
//public:
RN m_link;
void swapLink();
public:
const RN link();
RN *pLink();
void link(RN rn);
bool IsDBType(DBTYPE);
DB0 *CastToDB0();
DB1 *CastToDB1();
DB2 *CastToDB2();
DB3 *CastToDB3();
DB4 *CastToDB4();
DB5 *CastToDB5();
DB6 *CastToDB6();
DB7 *CastToDB7();
DB8 *CastToDB8();
DB9 *CastToDB9();
DB10 *CastToDB10();
DB11 *CastToDB11();
DB14 *CastToDB14();
DB15 *CastToDB15();
};
class DB0:public DBCOMMON
{ //Door
friend struct DATABASES;
friend void DumpDB0(FILE *f, RN object, CELLFLAG cf);
i16 word2; //bit 0 = 1 if open
//bits 1-4 = ornateness
//bit 5 = Mode of operation (0=sideways, 1=up)
//bit 6 = door switch
//bit 7 = Can open with fireball
//bit 8 = Can open with axe
//bits 9-15 ????
// 0400 means reflect/rotate image randomly to cause appearance of movement
void swap();
public:
const ui8 doorType() {return (UI8)(word2 & 1);};
void doorType(i32 d){word2=(ui16)((word2&0xfffe)|(d&1));};
// Each level can have two door types.
const i32 ornateness(){return (word2>>1) & 0xf;};
void ornateness(i32 o){word2=(ui16)((word2&0xffe1)|((o&0xf)<<1));};
const ui8 mode() {return (UI8)((word2>>5) & 1);}; //up/down
void mode(bool b){word2=(ui16)(b?(word2|0x0020):(word2&0xffdf));}; //up/down
const bool canOpenWithFireball() {return (word2>>7) & 1;};
void canOpenWithFireball(bool b){word2=(ui16)(b?(word2|0x0080):(word2&0xff7f));};
const bool canOpenWithAxe() {return (word2>>8) & 1;};
void canOpenWithAxe(bool b){word2=(ui16)(b?(word2|0x0100):(word2&0xffef));};
const ui8 doorSwitch() {return (UI8)((word2>>6) & 1);};
void doorSwitch(bool b){word2=(ui16)(b?(word2|0x0040):(word2&0xffbf));};
};
class DB1:public DBCOMMON
{ //Teleporter
friend void DumpDB1(FILE *f, RN object, CELLFLAG /*cf*/);
friend struct DATABASES;
void swap();
private:
i16 word2; // bits 0-4 = mapX
// bits 5-9 = mapY
// bits 10-11 = new facing or rotation
// bit 12 = 1= absolute facing; 0=rotate relative
// bits 13-14 = 0 = objects only
// 1 = monsters only
// 2 = party or objects only
// 3 = anything
// bit 15 = audible buzz
i16 word4; // bits 8-15 = level
public:
i32 destX() const {return BITS0_4(word2);};
void destX(ui32 x) {SETWBITS0_4(word2,x);};
i32 destY() const {return BITS5_9(word2);};
void destY(ui32 y) {SETWBITS5_9(word2,y);};
ui8 destLevel() const {return BITS8_15(word4);};
void destLevel(ui32 l) {SETWBITS8_15(word4,l);};
ui8 rotation() const {return BITS10_11(word2);};
void rotation(i32 r) {SETWBITS10_11(word2,r);};
ui8 facingMode() const {return BITS12_12(word2);};
void facingMode(ui32 f) {SETWBITS12_12(word2,f);};
ui8 what() const {return BITS13_14(word2);};
void what(ui32 w) {SETWBITS13_14(word2,w);};
ui8 audible() const {return BITS15_15(word2);};
void audible(ui32 w) {SETWBITS15_15(word2,w);};
void copyTeleporter(DB1 *pSrc)
{
word2 = pSrc->word2;
word4 = pSrc->word4;
};
};
class DB2:public DBCOMMON // Text
{
i16 word2; // bit 0 = Show
// bits 3-15
friend struct DATABASES;
void swap();
public:
void Clear();
bool show() {return BITS0_0(word2) != 0;};
void show(bool s) {SETWBITS0_0(word2,s?1:0);};
i32 index() {return BITS3_15(word2);};
void index(i32 i) {SETWBITS3_15(word2,i);};
};
// Action field in DB3 record
enum ACTUATORACTION
{
actuatorAction_SET = 0,
actuatorAction_CLEAR = 1,
actuatorAction_TOGGLE = 2,
actuatorAction_CONSTPRESSURE = 3
};
enum
{
//Bit flags in State
PORTRAIT_InActive = 1,
PORTRAIT_HidePortrait = 2,
PORTRAIT_HideGraphic = 4,
// How to respond to messsages
PORTRAIT_ResponseNone = 0, //Do nothing
PORTRAIT_ResponseSet = 1, //Set Active or Show
PORTRAIT_ResponseClear = 2, //Set Inactive or Hide
PORTRAIT_ResponseToggle = 3, //Toggle Active or Show
// Where to find 2-bit Response actions in 'responses' fields
PORTRAIT_ActiveResponse = 0,
PORTRAIT_PortraitResponse = 2,
PORTRAIT_GraphicResponse = 4
};
class DB3:public DBCOMMON // An actuator (pressure pad, keyhole, etc.)
{
friend void DumpDB3(FILE *, RN, i32, i32, i32, CELLFLAG);
friend struct DATABASES;
void swap();
private:
i16 word2; // bits 0-6 = Actuator Type
// 0 = Do nothing
// 1 = A simple wall switch that
// can be pressed with anything.
// 2 = ?
// 3 = Lock. Keys stays in hand
// 4 = Lock. Key removed from hand.
// 5 =
// Byte 8 (position) of Timer6 is bit number.
// Bits 7-15 are value. Bits in this value
// are Set/Cleared/Toggled by Timer6.
// "position" of timer6 tells which bit to
// fiddle with.
// Actuator is 'pressed' when bits 7-10 are
// equal to bits 11-14. (The first 4 bits of
// value equals second 4 bits).
// 6 =
// In a closed (stone) room
// Bits 7-15 are a 9-bit counter. A SET
// function increments and anything else
// decrements the counter. You cannot change
// a counter that equals zero. (Why?)
// The actuator is considered 'pressed'
// if the count is non-zero.
// In an open room this is a monster generator
// and is actuated by a timer event type 5.
// word 6 bits 8-15 non-zero causes once only.
// A type 65 record is created and
// the generator is disabled.
// If >= 128 then the time
// is queued to go off at
// 64 * ((word 6 bits 8-15)-126)
// (I presume to reactivate generator!).
// 7 = In stone - missile launcher. One predefined.
// 8 = In open room:
// Operated only by party. Value is
// an OBJECTTYPE that we search for in the
// party's possessions. Actuated if party
// possesses such an object.
//
// In Stone: A missile launcher. A spell.
// Value = 0 Fireballs
// 9 = In stone - Missile Launcher. Two predefined.
// 10 = In stone - Missile Launcher. Two spells.
// 11 = Lock. Key removed from hand.
// 14 = Missile Launcher. One available object.
// When a timer of type 6 is sent to
// an actuator of type 14 then the first
// object at the proper position in the same
// room as the actuator is removed
// from the room and launched as a missile
// in the adjacent room.
// 15 = Missile Launcher. Two available objects.
// When a timer of type 6 is sent to
// an actuator of type 15 then the first two
// objects at the proper position in the same
// room as the actuator are removed
// from the room and launched as missiles
// in the adjacent room.
// 47 = DSA
// bits 7-15 = value
private:
i16 word4; // bit 2 = causes bits 1-6 of word 2 to be cleared. "Once only"???
// bits 3-4 Action when switch changes state
// 0=set when closed
// 1=clear when closed
// 2=toggle when closed
// 3=set when closed, clear when opened