-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathSnipes.cpp
More file actions
2522 lines (2399 loc) · 77.1 KB
/
Snipes.cpp
File metadata and controls
2522 lines (2399 loc) · 77.1 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
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "config.h"
#include "Snipes.h"
#include "types.h"
#include "macros.h"
#include "console.h"
#include "timer.h"
#include "sound.h"
#include "keyboard.h"
#include "platform.h"
bool got_ctrl_break = false;
bool forfeit_match = false;
bool instant_quit = false;
bool sound_enabled = true;
bool shooting_sound_enabled = false;
BYTE fast_forward = false;
BYTE spacebar_state = false;
static BYTE keyboard_state = 0;
#ifdef CHEAT
bool rerecordingMode;
int single_step = 0;
int step_backwards = 0;
int increment_initial_seed = 0;
WORD skip_to_frame = 0;
#endif
#if defined(PLAYBACK_FOR_SCREEN_RECORDING) && !defined(CHEAT)
#define _PLAYBACK_FOR_SCREEN_RECORDING 1
#else
#define _PLAYBACK_FOR_SCREEN_RECORDING 0
#endif
static WORD random_seed_lo = 33, random_seed_hi = 467;
WORD GetRandomMasked(WORD mask)
{
random_seed_lo *= 2;
if (random_seed_lo > 941)
random_seed_lo -= 941;
random_seed_hi *= 2;
if (random_seed_hi > 947)
random_seed_hi -= 947;
return (random_seed_lo + random_seed_hi) & mask;
}
template <WORD RANGE>
WORD GetRandomRanged()
{
WORD mask = RANGE-1;
mask |= mask >> 1;
mask |= mask >> 2;
mask |= mask >> 4;
mask |= mask >> 8;
if (mask == RANGE-1)
return GetRandomMasked(mask);
for (;;)
{
WORD number = GetRandomMasked(mask);
if (number < RANGE)
return number;
}
}
Uint skillLevelLetter = 0;
Uint skillLevelNumber = 1;
void ParseSkillLevel(char *skillLevel, DWORD skillLevelLength)
{
Uint skillLevelNumberTmp = 0;
for (; skillLevelLength; skillLevel++, skillLevelLength--)
{
if (skillLevelNumberTmp >= 0x80)
{
// strange behavior, but this is what the original game does
skillLevelNumber = 1;
return;
}
char chr = *skillLevel;
if (inrange(chr, 'a', 'z'))
skillLevelLetter = chr - 'a';
else
if (inrange(chr, 'A', 'Z'))
skillLevelLetter = chr - 'A';
else
if (inrange(chr, '0', '9'))
skillLevelNumberTmp = skillLevelNumberTmp * 10 + (chr - '0');
}
if (inrange(skillLevelNumberTmp, 1, 9))
skillLevelNumber = skillLevelNumberTmp;
}
void ReadSkillLevel()
{
char skillLevel[0x80] = {};
DWORD skillLevelLength = ReadTextFromConsole(skillLevel, _countof(skillLevel));
if (skillLevelLength && skillLevel[skillLevelLength-1] == '\n')
skillLevelLength--;
if (skillLevelLength && skillLevel[skillLevelLength-1] == '\r')
skillLevelLength--;
for (Uint i=0; i<skillLevelLength; i++)
if (skillLevel[i] != ' ')
{
ParseSkillLevel(skillLevel + i, skillLevelLength - i);
break;
}
}
static const BYTE snipeShootingAccuracyTable ['Z'-'A'+1] = {2, 3, 4, 3, 4, 4, 3, 4, 3, 4, 4, 5, 3, 4, 3, 4, 3, 4, 3, 4, 4, 5, 4, 4, 5, 5}; // higher number = higher accuracy
static const bool enableSmallSnipesTable ['Z'-'A'+1] = {0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1};
static const bool bouncingBulletTable ['Z'-'A'+1] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
static const BYTE smallSnipeExplosionChanceTable['Z'-'A'+1] = {0x7F, 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0x1F, 0x7F, 0x7F, 0x3F, 0x3F, 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0x1F, 0x3F, 0x1F, 0x1F, 0x0F}; // lower number = higher chance
static const BYTE maxSnipesTable ['9'-'1'+1] = { 10, 20, 30, 40, 60, 80, 100, 120, 150};
static const BYTE numSnipePortalsTable ['9'-'1'+1] = { 3, 3, 4, 4, 5, 5, 6, 8, 10};
static const BYTE numLivesTable ['9'-'1'+1] = { 5, 5, 5, 5, 5, 4, 4, 3, 2};
bool enableElectricWalls, enableSmallSnipes, snipePortalsResistSnipeSpears, enableBouncingBullets;
BYTE snipeShootingAccuracy, smallSnipeExplosionChance, maxSnipes, numSnipePortalsAtStart, numLives;
enum MoveDirection : BYTE // progresses from 0 to 7 in the clockwise direction
{
MoveDirection_Up,
MoveDirection_UpRight,
MoveDirection_Right,
MoveDirection_DownRight,
MoveDirection_Down,
MoveDirection_DownLeft,
MoveDirection_Left,
MoveDirection_UpLeft,
MoveDirection_COUNT
};
enum MoveDirectionMask : BYTE
{
MoveDirectionMask_Diagonal = 1,
MoveDirectionMask_UpDown = 4,
MoveDirectionMask_All = MoveDirection_COUNT - 1
};
MoveDirection operator+ (MoveDirection dir, int n ) {return (MoveDirection ) ((BYTE )dir + n); }
MoveDirection operator- (MoveDirection dir, int n ) {return (MoveDirection ) ((BYTE )dir - n); }
MoveDirection operator& (MoveDirection dir, MoveDirectionMask mask) {return (MoveDirection ) ((BYTE )dir & mask);}
MoveDirection &operator+=(MoveDirection &dir, int n ) {return (MoveDirection&) ((BYTE&)dir += n); }
MoveDirection &operator-=(MoveDirection &dir, int n ) {return (MoveDirection&) ((BYTE&)dir -= n); }
MoveDirection &operator&=(MoveDirection &dir, MoveDirectionMask mask) {return (MoveDirection&) ((BYTE&)dir &= mask);}
MoveDirection &operator++(MoveDirection &dir ) {return (MoveDirection&)++(BYTE&)dir; }
MoveDirection &operator--(MoveDirection &dir ) {return (MoveDirection&)--(BYTE&)dir; }
MoveDirection operator++(MoveDirection &dir, int ) {return (MoveDirection ) ((BYTE&)dir)++; }
MoveDirection operator--(MoveDirection &dir, int ) {return (MoveDirection ) ((BYTE&)dir)--; }
enum OrthogonalDirection : BYTE
{
OrthogonalDirection_Up,
OrthogonalDirection_Right,
OrthogonalDirection_Down,
OrthogonalDirection_Left,
OrthogonalDirection_COUNT
};
enum OrthogonalDirectionMask : BYTE
{
OrthogonalDirectionMask_All = OrthogonalDirection_COUNT - 1
};
OrthogonalDirection operator+ (OrthogonalDirection dir, int n ) {return (OrthogonalDirection ) ((BYTE )dir + n); }
OrthogonalDirection operator& (OrthogonalDirection dir, OrthogonalDirectionMask mask) {return (OrthogonalDirection ) ((BYTE )dir & mask);}
MoveDirection OrthoDirectionToMoveDirection(OrthogonalDirection dir) {return (MoveDirection)(dir << 1);}
static const BYTE bulletBounceTable[OrthogonalDirection_COUNT][MoveDirection_COUNT] =
{
{4, 3, 4, 4, 4, 4, 4, 5,},
{6, 7, 6, 5, 6, 6, 6, 6,},
{0, 0, 0, 1, 0, 7, 0, 0,},
{2, 2, 2, 2, 2, 3, 2, 1,},
};
struct Coord
{
union
{
struct {BYTE x,y;};
WORD xy;
};
Coord &operator=(WORD _xy) {xy = _xy; return *this;}
};
typedef BYTE ObjectIndex;
#ifdef OBJECT_TABLE_BINARY_COMPATIBILITY
typedef WORD sprite SpritePointer; // FAKE_POINTER to current sprite frame
#else
typedef const WORD *SpritePointer;
#endif
#define DEFINE_ANCESTOR(parent) operator parent&() {return *(parent*)this;}
#define DEFINE_OBJECT_AND_MEMBERS(className,member1,member2,member3,memberFunctions) \
struct className\
{\
ObjectIndex next; /* objects[] index of the next object in the linked list of this object's type */\
member1;\
union\
{\
struct {BYTE x, y;};\
Coord xy;\
};\
member2;\
member3;\
SpritePointer sprite;\
memberFunctions\
};
DEFINE_OBJECT_AND_MEMBERS(Object, BYTE unused1, BYTE unused2, BYTE unused3,);
DEFINE_OBJECT_AND_MEMBERS(SnipePortal, BYTE unused, BYTE spawnFrame, BYTE animFrame, DEFINE_ANCESTOR(Object));
DEFINE_OBJECT_AND_MEMBERS(Explosion, BYTE unused, BYTE spriteSize, BYTE animFrame, DEFINE_ANCESTOR(Object));
#define DEFINE_MOVING_OBJECT_AND_MEMBERS(className,member1,member2,memberFunctions) DEFINE_OBJECT_AND_MEMBERS(className, member1, MoveDirection moveDirection, member2, memberFunctions)
DEFINE_MOVING_OBJECT_AND_MEMBERS(MovingObject, BYTE unused1, BYTE unused2, DEFINE_ANCESTOR(Object));
DEFINE_MOVING_OBJECT_AND_MEMBERS(Player, BYTE firingFrame, BYTE inputFrame, DEFINE_ANCESTOR(Object) DEFINE_ANCESTOR(MovingObject));
DEFINE_MOVING_OBJECT_AND_MEMBERS(Enemy, BYTE movementFlags, BYTE moveFrame, DEFINE_ANCESTOR(Object) DEFINE_ANCESTOR(MovingObject));
DEFINE_MOVING_OBJECT_AND_MEMBERS(Weapon, BYTE weaponType, BYTE animFrame, DEFINE_ANCESTOR(Object) DEFINE_ANCESTOR(MovingObject));
struct LargeSnipe : public Enemy { DEFINE_ANCESTOR(Object) DEFINE_ANCESTOR(MovingObject) };
struct SmallSnipe : public Enemy { DEFINE_ANCESTOR(Object) DEFINE_ANCESTOR(MovingObject) };
enum EnemyMovementFlag : BYTE
{
EnemyMovementFlag_TurnDirection = 1 << 0, // clear = clockwise, set = counterclockwise; set in stone when a snipe comes out of a snipe portal
EnemyMovementFlag_SmallSnipeMoveStraight = 1 << 1, // for small snipes only; clear = move based on direction of player, set = keep moving in current direction until an obstacle is hit
};
enum SoundEffect : BYTE
{
SoundEffect_Bullet = 0,
SoundEffect_Spear = 1,
SoundEffect_ExplodeSmallSnipe = 2,
SoundEffect_ExplodeLargeSnipe = 3,
SoundEffect_ExplodePlayer = 4,
SoundEffect_None = 0xFF
};
BYTE playerFiringPeriod; // in pairs of frames
WORD frame;
static bool playerAnimEyesNotWide, isPlayerDying, isPlayerExploding;
static BYTE lastHUD_numSmallSnipes, lastHUD_numSnipePortalsDestroyed, lastHUD_numLargeSnipes, lastHUD_numPlayerDeaths;
static BYTE numSnipePortals, numSmallSnipes, numWeapons, numPlayerDeaths, numLargeSnipes, playerEyeAnimFrame, orthoDistance;
static ObjectIndex objectHead_free, objectHead_weapons, objectHead_explosions, objectHead_smallSnipes, objectHead_largeSnipes, objectHead_snipePortals;
static OrthogonalDirection weaponCollisionDirection;
static SoundEffect currentSoundEffect = SoundEffect_None;
static BYTE currentSoundEffectFrame;
static WORD lastHUD_numSmallSnipesDestroyed, lastHUD_numLargeSnipesDestroyed, numSmallSnipesDestroyed, numLargeSnipesDestroyed, viewportFocusX, viewportFocusY;
static MazeTile *weaponTestPos;
static SHORT lastHUD_score, score;
Object *currentObject;
const WORD *currentSprite;
#define MAX_OBJECTS 0x100
static BYTE weaponBouncesRemaining[MAX_OBJECTS];
static Object objects[MAX_OBJECTS];
#define OBJECT_PLAYER 0x00
#define OBJECT_LASTFREE 0xFD
#define OBJECT_PLAYEREXPLOSION 0xFE
enum
{
WeaponType_Bullet = 0, // fired by the player
WeaponType_Spear = 6, // fired by a snipe
};
template <typename OBJECT_TYPE>
OBJECT_TYPE &SetCurrentObject(ObjectIndex i)
{
OBJECT_TYPE &object = ((OBJECT_TYPE*)objects)[i]; // cast the array before dereferencing, to avoid a bug that would otherwise happen with GCC's "-fstrict-aliasing" optimization
currentObject = (Object*)&object;
return object;
}
Player &player = ((Player *)objects)[OBJECT_PLAYER ];
Explosion &playerExplosion = ((Explosion*)objects)[OBJECT_PLAYEREXPLOSION];
static MazeTile maze[MAZE_WIDTH * MAZE_HEIGHT];
static const char statusLine[] = "\xDA\xBF\xB3\x01\x1A\xB3\x02\xB3""Skill""\xC0\xD9\xB3\x01\x1A\xB3\x02\xB3""Time Men Left Score 0 0000001 Man Left""e";
void InitializeHUD()
{
char (&scratchBuffer)[WINDOW_WIDTH] = (char(&)[WINDOW_WIDTH])maze;
char skillLetter = skillLevelLetter + 'A';
memset(scratchBuffer, ' ', WINDOW_WIDTH);
outputText (0x17, WINDOW_WIDTH, 0, 0, scratchBuffer);
outputText (0x17, WINDOW_WIDTH, 1, 0, scratchBuffer);
outputText (0x17, WINDOW_WIDTH, 2, 0, scratchBuffer);
outputText (0x17, 2, 0, 0, statusLine);
#ifdef CHEAT_OMNISCIENCE
outputText (0x17, 1, 0, 40, "\xB3");
outputText (0x17, 1, 1, 40, "\xB3");
outputText (0x17, 1, 2, 40, "\xB3");
#endif
outputNumber(0x13, 0, 2, 0, 3, 0);
outputText (0x17, 1, 0, 6, statusLine+2);
outputText (0x13, 2, 0, 8, statusLine+3);
outputNumber(0x13, 0, 4, 0, 11, 0);
outputText (0x17, 1, 0, 16, statusLine+5);
outputText (0x13, 1, 0, 18, statusLine+6);
outputNumber(0x13, 0, 4, 0, 20, 0);
outputText (0x17, 1, 0, 25, statusLine+7);
outputText (0x17, 5, 0, 27, statusLine+8);
outputNumber(0x17, 0, 1, 0, 38, skillLevelNumber);
outputText (0x17, 1, 0, 37, &skillLetter);
outputText (0x17, 2, 1, 0, statusLine+13);
outputText (0x17, 1, 1, 6, statusLine+15);
outputText (0x17, 2, 1, 8, statusLine+16);
outputText (0x17, 1, 1, 16, statusLine+18);
outputText (0x17, 1, 1, 18, statusLine+19);
outputText (0x17, 1, 1, 25, statusLine+20);
outputText (0x17, 4, 1, 27, statusLine+21);
memcpy(scratchBuffer, statusLine+25, 40);
scratchBuffer[0] = numLives + '0';
scratchBuffer[1] = 0;
if (numLives == 1)
scratchBuffer[6] = 'a';
outputText (0x17, 40, 2, 0, scratchBuffer);
lastHUD_numSmallSnipes = 0xFF;
lastHUD_numSnipePortalsDestroyed = 0xFF;
lastHUD_numLargeSnipes = 0xFF;
lastHUD_numSmallSnipesDestroyed = 0xFFFF;
lastHUD_numLargeSnipesDestroyed = 0xFFFF;
lastHUD_numPlayerDeaths = 0xFF;
lastHUD_score = -1;
}
#define MAZE_SCRATCH_BUFFER_SIZE (MAZE_WIDTH_IN_CELLS * MAZE_HEIGHT_IN_CELLS)
void CreateMaze_helper(SHORT &data_1E0, BYTE data_2AF)
{
switch (data_2AF)
{
case 0:
data_1E0 -= MAZE_WIDTH_IN_CELLS;
if (data_1E0 < 0)
data_1E0 += MAZE_SCRATCH_BUFFER_SIZE;
break;
case 1:
data_1E0 += MAZE_WIDTH_IN_CELLS;
if (data_1E0 >= MAZE_SCRATCH_BUFFER_SIZE)
data_1E0 -= MAZE_SCRATCH_BUFFER_SIZE;
break;
case 2:
if ((data_1E0 & 0xF) == 0)
data_1E0 += 0xF;
else
data_1E0--;
break;
case 3:
if ((data_1E0 & 0xF) == 0xF)
data_1E0 -= 0xF;
else
data_1E0++;
break;
default:
UNREACHABLE;
}
}
void CreateMaze()
{
BYTE (&mazeScratchBuffer)[MAZE_SCRATCH_BUFFER_SIZE] = (BYTE(&)[MAZE_SCRATCH_BUFFER_SIZE])objects;
memset(mazeScratchBuffer, 0xF, MAZE_SCRATCH_BUFFER_SIZE);
mazeScratchBuffer[0] = 0xE;
mazeScratchBuffer[1] = 0xD;
Uint numMazeCellsUninitialized = MAZE_SCRATCH_BUFFER_SIZE - 2;
static const BYTE data_EA3[] = {8, 4, 2, 1};
static const BYTE data_EA7[] = {4, 8, 1, 2};
for (;;)
{
outer_loop:
if (!numMazeCellsUninitialized)
break;
WORD data_1DE = GetRandomRanged<MAZE_SCRATCH_BUFFER_SIZE>();
if (mazeScratchBuffer[data_1DE] != 0xF)
continue;
WORD data_1E0;
WORD data_1E2 = GetRandomMasked(3);
WORD data_1E4 = 0;
BYTE data_2AF;
for (;;)
{
if (data_1E4 > 3)
goto outer_loop;
data_2AF = data_1E2 & 3;
data_1E0 = data_1DE;
CreateMaze_helper((SHORT&)data_1E0, data_2AF);
if (mazeScratchBuffer[data_1E0] != 0xF)
break;
data_1E2++;
data_1E4++;
}
numMazeCellsUninitialized--;
mazeScratchBuffer[data_1E0] ^= data_EA7[data_2AF];
mazeScratchBuffer[data_1DE] ^= data_EA3[data_2AF];
data_1E2 = data_1DE;
for (;;)
{
BYTE data_2AF = (BYTE)GetRandomMasked(3);
BYTE data_2B0 = (BYTE)GetRandomMasked(3) + 1;
data_1E0 = data_1E2;
for (;;)
{
CreateMaze_helper((SHORT&)data_1E0, data_2AF);
if (!data_2B0 || mazeScratchBuffer[data_1E0] != 0xF)
break;
mazeScratchBuffer[data_1E0] ^= data_EA7[data_2AF];
mazeScratchBuffer[data_1E2] ^= data_EA3[data_2AF];
numMazeCellsUninitialized--;
data_2B0--;
data_1E2 = data_1E0;
}
if (data_2B0)
goto outer_loop;
}
}
for (WORD data_1DE = 0; data_1DE < 0x40; data_1DE++)
{
WORD data_1E0 = GetRandomRanged<MAZE_SCRATCH_BUFFER_SIZE>();
BYTE data_2AF = (BYTE)GetRandomMasked(3);
mazeScratchBuffer[data_1E0] &= ~data_EA3[data_2AF];
CreateMaze_helper((SHORT&)data_1E0, data_2AF);
mazeScratchBuffer[data_1E0] &= ~data_EA7[data_2AF];
}
for (Uint i=0; i<_countof(maze); i++)
maze[i] = MazeTile(0x9, ' ');
WORD data_1E4 = 0;
WORD data_1E2 = 0;
for (WORD data_1DE = 0; data_1DE < MAZE_HEIGHT_IN_CELLS; data_1DE++)
{
for (WORD data_1E0 = 0; data_1E0 < MAZE_WIDTH_IN_CELLS; data_1E0++)
{
if (mazeScratchBuffer[data_1E2] & 8)
for (Uint i=0; i<MAZE_CELL_WIDTH-1; i++)
maze[data_1E4 + 1 + i] = MazeTile(0x9, 0xCD);
if (mazeScratchBuffer[data_1E2] & 2)
{
WORD data_1E6 = data_1E4 + MAZE_WIDTH;
for (WORD data_1E8 = 1; data_1E8 <= MAZE_CELL_HEIGHT-1; data_1E8++)
{
maze[data_1E6] = MazeTile(0x9, 0xBA);
data_1E6 += MAZE_WIDTH;
}
}
WORD data_1E6;
if (data_1DE)
data_1E6 = data_1E2 - (!data_1E0 ? 1 : 1 + MAZE_WIDTH_IN_CELLS);
else
{
if (!data_1E0)
data_1E6 = MAZE_SCRATCH_BUFFER_SIZE - 1;
else
data_1E6 = data_1E2 + MAZE_SCRATCH_BUFFER_SIZE - (1 + MAZE_WIDTH_IN_CELLS);
}
static BYTE data_EAB[] = {0x20, 0xBA, 0xBA, 0xBA, 0xCD, 0xBC, 0xBB, 0xB9, 0xCD, 0xC8, 0xC9, 0xCC, 0xCD, 0xCA, 0xCB, 0xCE};
maze[data_1E4].chr = data_EAB[(mazeScratchBuffer[data_1E2] & 0xA) | (mazeScratchBuffer[data_1E6] & 0x5)];
maze[data_1E4].color = 0x9;
data_1E4 += MAZE_CELL_WIDTH;
data_1E2++;
}
data_1E4 += MAZE_WIDTH * (MAZE_CELL_HEIGHT-1);
}
}
BYTE CreateNewObject()
{
ObjectIndex object = objectHead_free;
if (object)
objectHead_free = objects[object].next;
return object;
}
#define EXPLOSION_SIZE(x,y) ((y)*10+(x))
#define SPRITE_SIZE(x,y) (((x)<<8)+(y))
// snipe portal
static const WORD data_1002[] = {SPRITE_SIZE(2,2), 0xFDA, 0xEBF, 0xDC0, 0xCD9};
static const WORD data_100C[] = {SPRITE_SIZE(2,2), 0xEFF, 0xEFF, 0xEFF, 0xEFF};
static const WORD data_1016[] = {SPRITE_SIZE(2,2), 0xEDA, 0xEBF, 0xEC0, 0xED9};
static const WORD data_1020[] = {SPRITE_SIZE(2,2), 0xEFF, 0xEFF, 0xEFF, 0xEFF};
static const WORD data_102A[] = {SPRITE_SIZE(2,2), 0xDDA, 0xDBF, 0xDC0, 0xDD9};
static const WORD data_1034[] = {SPRITE_SIZE(2,2), 0xEFF, 0xEFF, 0xEFF, 0xEFF};
static const WORD data_103E[] = {SPRITE_SIZE(2,2), 0xCDA, 0xCBF, 0xCC0, 0xCD9};
static const WORD data_1048[] = {SPRITE_SIZE(2,2), 0xEFF, 0xEFF, 0xEFF, 0xEFF};
static const WORD data_1052[] = {SPRITE_SIZE(2,2), 0xBDA, 0xBBF, 0xBC0, 0xBD9};
static const WORD data_105C[] = {SPRITE_SIZE(2,2), 0xEFF, 0xEFF, 0xEFF, 0xEFF};
static const WORD data_1066[] = {SPRITE_SIZE(2,2), 0xADA, 0xABF, 0xAC0, 0xAD9};
static const WORD data_1070[] = {SPRITE_SIZE(2,2), 0xEFF, 0xEFF, 0xEFF, 0xEFF};
static const WORD data_107A[] = {SPRITE_SIZE(2,2), 0x9DA, 0x9BF, 0x9C0, 0x9D9};
static const WORD data_1084[] = {SPRITE_SIZE(2,2), 0xEFF, 0xEFF, 0xEFF, 0xEFF};
static const WORD data_108E[] = {SPRITE_SIZE(2,2), 0x4DA, 0x4BF, 0x4C0, 0x4D9};
static const WORD data_1098[] = {SPRITE_SIZE(2,2), 0xEFF, 0xEFF, 0xEFF, 0xEFF};
static const WORD *data_10A2[] = {data_1002, data_100C, data_1016, data_1020, data_102A, data_1034, data_103E, data_1048, data_1052, data_105C, data_1066, data_1070, data_107A, data_1084, data_108E, data_1098};
// player
static const WORD data_10E2[] = {SPRITE_SIZE(2,2), 0xF93, 0xF93, 0xF11, 0xF10};
static const WORD data_10EC[] = {SPRITE_SIZE(2,2), 0xF4F, 0xF4F, 0xF11, 0xF10};
//static const WORD *data_10F6[] = {data_10E2, data_10EC};
// small snipe
static const WORD data_10FE[] = {SPRITE_SIZE(1,1), 0x202};
// large snipe
static const WORD data_1108[] = {SPRITE_SIZE(2,1), 0x201, 0x218};
static const WORD data_1112[] = {SPRITE_SIZE(2,1), 0x201, 0x21A};
static const WORD data_111C[] = {SPRITE_SIZE(2,1), 0x201, 0x219};
static const WORD data_1126[] = {SPRITE_SIZE(2,1), 0x21B, 0x201};
static const WORD *data_1130[] = {data_1108, data_1112, data_1112, data_1112, data_111C, data_1126, data_1126, data_1126};
// bullet
static const WORD data_1150[] = {SPRITE_SIZE(1,1), 0xE09};
static const WORD data_115A[] = {SPRITE_SIZE(1,1), 0xB0F};
static const WORD *data_11D4[] = {data_1150, data_115A, data_1150, data_115A};
// spear
static const WORD data_1164[] = {SPRITE_SIZE(1,1), 0xA18};
static const WORD data_116E[] = {SPRITE_SIZE(1,1), 0xA2F};
static const WORD data_1178[] = {SPRITE_SIZE(1,1), 0xA1A};
static const WORD data_1182[] = {SPRITE_SIZE(1,1), 0xA5C};
static const WORD data_118C[] = {SPRITE_SIZE(1,1), 0xA19};
static const WORD data_1196[] = {SPRITE_SIZE(1,1), 0xA2F};
static const WORD data_11A0[] = {SPRITE_SIZE(1,1), 0xA1B};
static const WORD data_11AA[] = {SPRITE_SIZE(1,1), 0xA5C};
static const WORD *data_11B4[] = {data_1164, data_116E, data_1178, data_1182, data_118C, data_1196, data_11A0, data_11AA};
// player or snipe portal explosion
static const WORD data_12C2[] = {SPRITE_SIZE(2,2), 0xFB0, 0xFB2, 0xFB2, 0xFB0};
static const WORD data_12CC[] = {SPRITE_SIZE(2,2), 0xBB2, 0xBB0, 0xBB0, 0xBB2};
static const WORD data_12D6[] = {SPRITE_SIZE(2,2), 0xCB0, 0xCB2, 0xCB2, 0xCB0};
static const WORD data_12E0[] = {SPRITE_SIZE(2,2), 0x4B2, 0x4B0, 0x4B0, 0x4B2};
static const WORD data_12EA[] = {SPRITE_SIZE(2,2), 0x62A, 0x60F, 0x62A, 0x60F};
static const WORD data_12F4[] = {SPRITE_SIZE(2,2), 0x807, 0x820, 0x807, 0x820};
static const WORD *data_12FE[] = {data_12C2, data_12CC, data_12D6, data_12E0, data_12EA, data_12F4};
// large snipe explosion
static const WORD data_1316[] = {SPRITE_SIZE(2,1), 0xFB0, 0xFB2};
static const WORD data_1320[] = {SPRITE_SIZE(2,1), 0xBB2, 0xBB0};
static const WORD data_132A[] = {SPRITE_SIZE(2,1), 0xCB0, 0xCB2};
static const WORD data_1334[] = {SPRITE_SIZE(2,1), 0x4B2, 0x4B0};
static const WORD data_133E[] = {SPRITE_SIZE(2,1), 0x62A, 0x60F};
static const WORD data_1348[] = {SPRITE_SIZE(2,1), 0x807, 0x820};
static const WORD *data_1352[] = {data_1316, data_1320, data_132A, data_1334, data_133E, data_1348};
// small snipe explosion
static const WORD data_136A[] = {SPRITE_SIZE(1,1), 0xFB2};
static const WORD data_1374[] = {SPRITE_SIZE(1,1), 0xB0F};
static const WORD data_137E[] = {SPRITE_SIZE(1,1), 0xC09};
static const WORD data_1388[] = {SPRITE_SIZE(1,1), 0x407};
static const WORD *data_1392[] = {data_136A, data_136A, data_136A, data_1374, data_137E, data_1388};
bool IsPlayer(BYTE chr)
{
return chr == 0x93 || chr == 0x4F || chr == 0x11 || chr == 0x10;
}
bool IsSnipePortal(MazeTile tile)
{
#if defined(FIX_BUGS) || defined(FIX_SNIPE_PORTAL_IDENTIFICATION_BUG)
return tile.chr == 0xDA || tile.chr == 0xBF || tile.chr == 0xC0 || tile.chr == 0xD9 || tile.chr == 0xFF;
#else
for (Uint i=1; i<_countof(data_1002); i++)
if ((WORD&)tile == data_1002[i])
return true;
return tile.chr == 0xFF;
#endif
}
#ifdef OBJECT_TABLE_BINARY_COMPATIBILITY
#define FAKE_POINTER(n) 0x##n
const WORD *FakePointerToPointer(WORD fakePtr)
{
switch (fakePtr)
{
case FAKE_POINTER(1002): return data_1002;
case FAKE_POINTER(100C): return data_100C;
case FAKE_POINTER(1016): return data_1016;
case FAKE_POINTER(1020): return data_1020;
case FAKE_POINTER(102A): return data_102A;
case FAKE_POINTER(1034): return data_1034;
case FAKE_POINTER(103E): return data_103E;
case FAKE_POINTER(1048): return data_1048;
case FAKE_POINTER(1052): return data_1052;
case FAKE_POINTER(105C): return data_105C;
case FAKE_POINTER(1066): return data_1066;
case FAKE_POINTER(1070): return data_1070;
case FAKE_POINTER(107A): return data_107A;
case FAKE_POINTER(1084): return data_1084;
case FAKE_POINTER(108E): return data_108E;
case FAKE_POINTER(1098): return data_1098;
case FAKE_POINTER(10E2): return data_10E2;
case FAKE_POINTER(10EC): return data_10EC;
case FAKE_POINTER(10FE): return data_10FE;
case FAKE_POINTER(1108): return data_1108;
case FAKE_POINTER(1112): return data_1112;
case FAKE_POINTER(111C): return data_111C;
case FAKE_POINTER(1126): return data_1126;
case FAKE_POINTER(1150): return data_1150;
case FAKE_POINTER(115A): return data_115A;
case FAKE_POINTER(1164): return data_1164;
case FAKE_POINTER(116E): return data_116E;
case FAKE_POINTER(1178): return data_1178;
case FAKE_POINTER(1182): return data_1182;
case FAKE_POINTER(118C): return data_118C;
case FAKE_POINTER(1196): return data_1196;
case FAKE_POINTER(11A0): return data_11A0;
case FAKE_POINTER(11AA): return data_11AA;
case FAKE_POINTER(12C2): return data_12C2;
case FAKE_POINTER(12CC): return data_12CC;
case FAKE_POINTER(12D6): return data_12D6;
case FAKE_POINTER(12E0): return data_12E0;
case FAKE_POINTER(12EA): return data_12EA;
case FAKE_POINTER(12F4): return data_12F4;
case FAKE_POINTER(1316): return data_1316;
case FAKE_POINTER(1320): return data_1320;
case FAKE_POINTER(132A): return data_132A;
case FAKE_POINTER(1334): return data_1334;
case FAKE_POINTER(133E): return data_133E;
case FAKE_POINTER(1348): return data_1348;
case FAKE_POINTER(136A): return data_136A;
case FAKE_POINTER(1374): return data_1374;
case FAKE_POINTER(137E): return data_137E;
case FAKE_POINTER(1388): return data_1388;
default:
return NULL;
}
}
WORD PointerToFakePointer(const WORD *ptr)
{
if (ptr == data_1002) return FAKE_POINTER(1002);
if (ptr == data_100C) return FAKE_POINTER(100C);
if (ptr == data_1016) return FAKE_POINTER(1016);
if (ptr == data_1020) return FAKE_POINTER(1020);
if (ptr == data_102A) return FAKE_POINTER(102A);
if (ptr == data_1034) return FAKE_POINTER(1034);
if (ptr == data_103E) return FAKE_POINTER(103E);
if (ptr == data_1048) return FAKE_POINTER(1048);
if (ptr == data_1052) return FAKE_POINTER(1052);
if (ptr == data_105C) return FAKE_POINTER(105C);
if (ptr == data_1066) return FAKE_POINTER(1066);
if (ptr == data_1070) return FAKE_POINTER(1070);
if (ptr == data_107A) return FAKE_POINTER(107A);
if (ptr == data_1084) return FAKE_POINTER(1084);
if (ptr == data_108E) return FAKE_POINTER(108E);
if (ptr == data_1098) return FAKE_POINTER(1098);
if (ptr == data_10E2) return FAKE_POINTER(10E2);
if (ptr == data_10EC) return FAKE_POINTER(10EC);
if (ptr == data_10FE) return FAKE_POINTER(10FE);
if (ptr == data_1108) return FAKE_POINTER(1108);
if (ptr == data_1112) return FAKE_POINTER(1112);
if (ptr == data_111C) return FAKE_POINTER(111C);
if (ptr == data_1126) return FAKE_POINTER(1126);
if (ptr == data_1150) return FAKE_POINTER(1150);
if (ptr == data_115A) return FAKE_POINTER(115A);
if (ptr == data_1164) return FAKE_POINTER(1164);
if (ptr == data_116E) return FAKE_POINTER(116E);
if (ptr == data_1178) return FAKE_POINTER(1178);
if (ptr == data_1182) return FAKE_POINTER(1182);
if (ptr == data_118C) return FAKE_POINTER(118C);
if (ptr == data_1196) return FAKE_POINTER(1196);
if (ptr == data_11A0) return FAKE_POINTER(11A0);
if (ptr == data_11AA) return FAKE_POINTER(11AA);
if (ptr == data_12C2) return FAKE_POINTER(12C2);
if (ptr == data_12CC) return FAKE_POINTER(12CC);
if (ptr == data_12D6) return FAKE_POINTER(12D6);
if (ptr == data_12E0) return FAKE_POINTER(12E0);
if (ptr == data_12EA) return FAKE_POINTER(12EA);
if (ptr == data_12F4) return FAKE_POINTER(12F4);
if (ptr == data_1316) return FAKE_POINTER(1316);
if (ptr == data_1320) return FAKE_POINTER(1320);
if (ptr == data_132A) return FAKE_POINTER(132A);
if (ptr == data_1334) return FAKE_POINTER(1334);
if (ptr == data_133E) return FAKE_POINTER(133E);
if (ptr == data_1348) return FAKE_POINTER(1348);
if (ptr == data_136A) return FAKE_POINTER(136A);
if (ptr == data_1374) return FAKE_POINTER(1374);
if (ptr == data_137E) return FAKE_POINTER(137E);
if (ptr == data_1388) return FAKE_POINTER(1388);
__debugbreak();
return 0;
}
#else // OBJECT_TABLE_BINARY_COMPATIBILITY
#define FAKE_POINTER(n) (data_##n)
#define FakePointerToPointer(n) (n)
#define PointerToFakePointer(n) (n)
#endif // OBJECT_TABLE_BINARY_COMPATIBILITY
#ifdef USE_MODULO_LOOKUP_TABLE
static const bool data_11E8[] = {
0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,
0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,
0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0
};
bool IsDiagonalDoubledPhase(BYTE n)
{
return data_11E8[n];
}
#else
bool IsDiagonalDoubledPhase(BYTE n)
{
return n % 3 & 1;
}
#endif
static const BYTE mazeWallCharacters[] = {0xB9, 0xBA, 0xBB, 0xBC, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE};
static const BYTE enemyCharacters[] = {0x01, 0x02, 0x18, 0x1A, 0x19, 0x1B};
void FreeObject(ObjectIndex object)
{
objects[object].next = objectHead_free;
objectHead_free = object;
}
bool IsObjectLocationOccupied(BYTE y, BYTE x)
{
BYTE spriteHeight = ((BYTE*)currentSprite)[0];
BYTE spriteWidth = ((BYTE*)currentSprite)[1];
MazeTile *mazeTile = &maze[y * MAZE_WIDTH];
for (BYTE row = 0; row < spriteHeight; row++)
{
for (BYTE column = 0; column < spriteWidth; column++)
{
if (mazeTile[x].chr != ' ')
return true;
if (++x >= MAZE_WIDTH)
x = 0;
}
mazeTile += MAZE_WIDTH;
if (mazeTile >= &maze[_countof(maze)])
mazeTile -= _countof(maze);
}
return false;
}
void PlotObjectToMaze() // plots object currentObject with sprite currentSprite
{
BYTE spriteHeight = ((BYTE*)currentSprite)[0];
BYTE spriteWidth = ((BYTE*)currentSprite)[1];
MazeTile *spriteTile = (MazeTile*)¤tSprite[1];
MazeTile *mazeTile = &maze[currentObject->y * MAZE_WIDTH];
for (BYTE row = 0; row < spriteHeight; row++)
{
BYTE x = currentObject->x;
for (BYTE column = 0; column < spriteWidth; column++)
{
mazeTile[x] = *spriteTile++;
if (++x >= MAZE_WIDTH)
x = 0;
}
mazeTile += MAZE_WIDTH;
if (mazeTile >= &maze[_countof(maze)])
mazeTile -= _countof(maze);
}
}
void PlaceObjectInRandomUnoccupiedMazeCell()
{
do
{
currentObject->x = (BYTE)GetRandomRanged<MAZE_WIDTH / MAZE_CELL_WIDTH >() * MAZE_CELL_WIDTH + MAZE_CELL_WIDTH /2;
currentObject->y = (BYTE)GetRandomRanged<MAZE_HEIGHT / MAZE_CELL_HEIGHT>() * MAZE_CELL_HEIGHT + MAZE_CELL_HEIGHT/2;
}
while (IsObjectLocationOccupied(currentObject->y, currentObject->x));
}
void CreateSnipePortalsAndPlayer()
{
for (WORD data_B58 = 1; data_B58 <= OBJECT_LASTFREE; data_B58++)
objects[data_B58].next = data_B58 + 1;
objects[OBJECT_LASTFREE].next = 0;
objectHead_free = 1;
objectHead_weapons = 0;
objectHead_explosions = 0;
objectHead_smallSnipes = 0;
objectHead_largeSnipes = 0;
objectHead_snipePortals = 0;
for (WORD data_B58 = 0; data_B58 < numSnipePortalsAtStart; data_B58++)
{
ObjectIndex newSnipePortal = CreateNewObject();
objects[newSnipePortal].next = objectHead_snipePortals;
objectHead_snipePortals = newSnipePortal;
SnipePortal &snipePortal = SetCurrentObject<SnipePortal>(newSnipePortal);
snipePortal.sprite = FAKE_POINTER(1002);
currentSprite = data_1002;
PlaceObjectInRandomUnoccupiedMazeCell();
snipePortal.unused = 0;
snipePortal.animFrame = (BYTE)GetRandomMasked(0xF);
snipePortal.spawnFrame = 1;
PlotObjectToMaze();
}
numSnipePortals = numSnipePortalsAtStart;
numSmallSnipesDestroyed = 0;
numSmallSnipes = 0;
numWeapons = 0;
numLargeSnipesDestroyed = 0;
numPlayerDeaths = 0;
numLargeSnipes = 0;
score = 0;
playerAnimEyesNotWide = false;
playerEyeAnimFrame = 0;
isPlayerDying = false;
isPlayerExploding = false;
player.sprite = FAKE_POINTER(10E2);
currentSprite = data_10E2;
currentObject = (Object*)&player;
PlaceObjectInRandomUnoccupiedMazeCell();
PlotObjectToMaze();
viewportFocusX = player.x;
viewportFocusY = player.y;
player.inputFrame = 1;
player.firingFrame = 1;
}
void SetSoundEffectState(BYTE frame, SoundEffect index)
{
if (currentSoundEffect != SoundEffect_None && index < currentSoundEffect)
return;
if (!shooting_sound_enabled && !index)
return;
currentSoundEffectFrame = frame;
currentSoundEffect = index;
}
void DrawViewport();
bool UpdateHUD(bool incrementFrame = true) // returns true if the match has been won
{
frame += incrementFrame;
if (lastHUD_numLargeSnipesDestroyed != numLargeSnipesDestroyed)
outputNumber(0x13, 0, 4, 0, 11, lastHUD_numLargeSnipesDestroyed = numLargeSnipesDestroyed);
if (lastHUD_numSmallSnipesDestroyed != numSmallSnipesDestroyed)
outputNumber(0x13, 0, 4, 0, 20, lastHUD_numSmallSnipesDestroyed = numSmallSnipesDestroyed);
if (lastHUD_numSnipePortalsDestroyed != numSnipePortals)
{
outputNumber(0x17, 0, 2, 1, 3, lastHUD_numSnipePortalsDestroyed = numSnipePortals);
outputNumber(0x13, 0, 2, 0, 3, numSnipePortalsAtStart - numSnipePortals);
}
if (lastHUD_numLargeSnipes != numLargeSnipes)
outputNumber(0x17, 0, 3, 1, 12, lastHUD_numLargeSnipes = numLargeSnipes);
if (lastHUD_numSmallSnipes != numSmallSnipes)
outputNumber(0x17, 0, 3, 1, 21, lastHUD_numSmallSnipes = numSmallSnipes);
if (lastHUD_score != score)
{
lastHUD_score = score;
if (lastHUD_score > 0)
outputNumber(0x17, 1, 5, 2, 33, lastHUD_score);
else
outputText (0x17, 6, 2, 33, statusLine+65);
}
#ifdef CHEAT_OMNISCIENCE
{
char hex[strlength("RNG 941,947")+1];
sprintf(hex, "RNG %03u,%03u", random_seed_lo, random_seed_hi);
outputText(0x17, strlength("RNG 941,947"), 2, 42, hex);
}
#endif
if (lastHUD_numPlayerDeaths != numPlayerDeaths)
{
BYTE livesRemaining = numLives - (lastHUD_numPlayerDeaths = numPlayerDeaths);
if (livesRemaining == 1)
outputText (0x1C, 10, 2, 0, statusLine+71);
else
{
{} outputNumber(0x17, 0, 1, 2, 0, livesRemaining);
if (!livesRemaining)
{
outputNumber(0x1C, 0, 1, 2, 0, 0);
outputText (0x1C, 1, 2, 3, statusLine+81);
}
}
}
outputNumber(0x17, 0, 5, 1, 34, frame); // Time
if (numLargeSnipes || numSnipePortals || numSmallSnipes)
return false;
DrawViewport();
EraseBottomTwoLines();
CloseDirectConsole(WINDOW_HEIGHT-2);
WriteTextToConsole("Congratulations --- YOU ACTUALLY WON!!!\r\n");
return true;
}
void ExplodeObject(ObjectIndex arg)
{
if (arg == OBJECT_PLAYER) // explode the player (and don't overwrite the player object)
{
arg = OBJECT_PLAYEREXPLOSION;
playerExplosion.x = player.x;
playerExplosion.y = player.y;
playerExplosion.spriteSize = EXPLOSION_SIZE(2,2);
playerExplosion.sprite = FAKE_POINTER(12C2);
isPlayerExploding = true;
}
Explosion &explosion = SetCurrentObject<Explosion>(arg);
explosion.next = objectHead_explosions;
objectHead_explosions = arg;
const WORD *data_CC4 = FakePointerToPointer(explosion.sprite);
BYTE data_CC8 = ((BYTE*)data_CC4)[0];
BYTE data_CC9 = ((BYTE*)data_CC4)[1];
if (data_CC8 == 2 && data_CC9 == 2)
{
explosion.sprite = FAKE_POINTER(12C2);
currentSprite = data_12C2;
explosion.spriteSize = EXPLOSION_SIZE(2,2);
explosion.animFrame = 0;
SetSoundEffectState(0, SoundEffect_ExplodePlayer);
}
if (data_CC8 == 1 && data_CC9 == 2)
{
explosion.sprite = FAKE_POINTER(1316);
currentSprite = data_1316;
explosion.spriteSize = EXPLOSION_SIZE(2,1);
explosion.animFrame = 0;
SetSoundEffectState(0, SoundEffect_ExplodeLargeSnipe);
}
if (data_CC8 == 1 && data_CC9 == 1)
{
explosion.sprite = FAKE_POINTER(136A);
currentSprite = data_136A;
explosion.spriteSize = EXPLOSION_SIZE(1,1);
explosion.animFrame = 2;
SetSoundEffectState(2, SoundEffect_ExplodeSmallSnipe);
}
PlotObjectToMaze();
}
void FreeObjectInList_worker(ObjectIndex *objectHead, ObjectIndex object)
{
ObjectIndex data_CCA = *objectHead;
if (object == data_CCA)
{
*objectHead = objects[object].next;
return;
}
for (;;)
{
ObjectIndex data_CCB = objects[data_CCA].next;
if (!data_CCB)
return;
if (object == data_CCB)
break;
data_CCA = data_CCB;
}
objects[data_CCA].next = objects[object].next;
}
void FreeObjectInList(ObjectIndex *objectHead, ObjectIndex object)
{
if (object == OBJECT_PLAYER)
{
ExplodeObject(object);
return;
}
FreeObjectInList_worker(objectHead, object);
if (objectHead != &objectHead_weapons)
{
ExplodeObject(object);
return;
}
FreeObject(object);
}
bool MoveWeaponAndTestHit(OrthogonalDirection arg)
{
switch (weaponCollisionDirection = arg)
{
case OrthogonalDirection_Up:
weaponTestPos -= MAZE_WIDTH;
if (--currentObject->y == 0xFF)
{
currentObject->y = MAZE_HEIGHT - 1;
weaponTestPos += _countof(maze);
}
break;
case OrthogonalDirection_Right:
weaponTestPos++;
if (++currentObject->x >= MAZE_WIDTH)
{
currentObject->x = 0;
weaponTestPos -= MAZE_WIDTH;
}
break;
case OrthogonalDirection_Down:
weaponTestPos += MAZE_WIDTH;
if (++currentObject->y >= MAZE_HEIGHT)
{
currentObject->y = 0;
weaponTestPos -= _countof(maze);