-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathC_code.c
2175 lines (2031 loc) · 55.7 KB
/
C_code.c
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 "include/aw2.h"
#define ABS(aValue) ((aValue) >= 0 ? (aValue) : -(aValue))
struct RandomizerSettings {
u16 base : 1;
u16 growth : 2; // vanilla, randomized, 0%, 100%
u16 caps : 2; // vanilla, randomized, 30
u16 class : 1;
u16 itemStats : 1;
u16 foundItems : 1;
u16 shopItems : 1;
u16 disp : 1;
};
struct RandomizerValues {
u32 seed : 31;
u32 variance : 1;
// u32 bonus : 5;
};
// 8034dcc update music
extern struct RandomizerSettings RandBitflags;
extern struct RandomizerValues RandValues;
extern u8 gCh;
extern u32 gGameClock;
// 0x0803CC84 - Loads Design Map 1/2/3 Names into RAM
extern void LoadDesignRoomName(int, int); // 0x803CC84
void LoadDesignRoom1Name(void) { LoadDesignRoomName(0x200B204, 0x20280C2); }
#define SHORTCALL __attribute__((short_call))
#define CONSTFUNC __attribute__((const))
extern int ModNum(int a, int b) SHORTCALL;
int NextSeededRN(u16 *currentRN) {
// This generates a pseudorandom string of 16 bits
// In other words, a pseudorandom integer that can range from 0 to 65535
u16 rn = (currentRN[1] << 11) + (currentRN[0] >> 5);
// Shift state[2] one bit
currentRN[2] *= 2;
// "carry" the top bit of state[1] to state[2]
if (currentRN[1] & 0x8000)
currentRN[2]++;
rn ^= currentRN[2];
// Shifting the whole state 16 bits
currentRN[2] = currentRN[1];
currentRN[1] = currentRN[0];
currentRN[0] = rn;
return rn;
}
void InitSeededRN(int seed, u16 *currentRN) {
// This table is a collection of 8 possible initial rn state
// 3 entries will be picked based of which "seed" was given
u16 initTable[8] = {0xA36E, 0x924E, 0xB784, 0x4F67,
0x8092, 0x592D, 0x8E70, 0xA794};
int mod = ModNum(seed, 7);
currentRN[0] = initTable[(mod++ & 7)];
currentRN[1] = initTable[(mod++ & 7)];
currentRN[2] = initTable[(mod & 7)];
if (ModNum(seed, 13) > 0)
for (mod = ModNum(seed, 13); mod != 0; mod--)
NextSeededRN(currentRN);
}
u16 GetNthRN(int n, int seed) {
u16 currentRN[3] = {0, 0, 0};
InitSeededRN(seed, currentRN);
int result = 0;
for (int i = 0; i < n; i++) {
result = NextSeededRN(currentRN);
}
return result;
}
int GetInitialSeed(void) {
int result = RandValues.seed;
if (!result) {
result =
0; // TacticianName[1] | (TacticianName[2]<<8) | (TacticianName[3]<<16);
int clock = gGameClock;
result = (GetNthRN(clock, result) << 4) | GetNthRN(clock, result);
}
if (result > 999999) {
result &= 0xEFFFF;
}
return result;
}
extern u8 DesignRoom1Name[12];
u16 HashByte_Global(int number, int max, int noise, int offset) {
if (max == 0)
return 0;
offset = ModNum(offset, 32);
u32 hash = 5381;
hash = ((hash << 5) + hash) ^ number;
// hash = ((hash << 5) + hash) ^ *StartTimeSeedRamLabel;
for (int i = 0; i < 12; ++i) {
if (!DesignRoom1Name[i]) {
break;
}
hash = ((hash << 5) + hash) ^ DesignRoom1Name[i];
};
u8 seed[3] = {(noise & 0xFF), (noise & 0xFF00) >> 8,
(noise & 0xFF0000) >> 16};
for (int i = 0; i < 3; ++i) {
if (!seed[i]) {
break;
}
hash = ((hash << 5) + hash) ^ seed[i];
};
hash = GetNthRN(offset + 1, hash);
return ModNum((hash & 0x2FFFFFFF), max);
};
u16 HashByte_Ch(int number, int max, int noise, int offset) {
noise += (gCh << 8);
return HashByte_Global(number, max, noise, offset);
};
s16 HashByte_ChIfConfig(int number, int max, int noise, int offset) {
if (DesignRoom1Name[0] == 0x41 ||
DesignRoom1Name[0] == 0x43) { // "A" or "C" = no random stats
return (-1);
}
if (DesignRoom1Name[0] == 0x20) { // blank char
// asm("mov r11, r11");
noise += (gCh << 8);
if (DesignRoom1Name[1] == 0x41 || DesignRoom1Name[1] == 0x43) {
return (-1);
}
}
return HashByte_Global(number, max, noise, offset);
};
s16 HashPercent(int number, int noise, int offset, int global,
int earlygamePromo) {
if (number < 0)
number = 0;
int variation = (RandValues.variance) * 5;
int percentage = 0;
if (global) {
percentage = HashByte_Global(number, variation * 2, noise,
offset); // rn up to 150 e.g. 125
} else {
percentage = HashByte_Ch(number, variation * 2, noise, offset);
} // rn up to 150 e.g. 125
percentage += (100 - variation); // 125 + 25 = 150
if (earlygamePromo == 1) {
if (percentage > 125) {
percentage = percentage / 2;
}
}
if (earlygamePromo == 2) {
if (percentage > 150) {
percentage = percentage / 2;
}
}
int ret = (percentage * number) / 100; // 1.5 * 120 (we want to negate this)
if (ret > 127)
ret = (200 - percentage) * number / 100;
if (ret < 0)
ret = 0;
return ret;
};
s16 HashByPercent_Ch(int number, int noise, int offset, int earlygamePromo) {
return HashPercent(number, noise, offset, false, earlygamePromo);
};
s16 HashByPercent(int number, int noise, int offset) {
return HashPercent(number, noise, offset, true, false);
};
// 80442AC enable co power if mov r0, #1, bx lr
const s8 PowModifiers[] = {-30, -20, -10, 0, 10, 20, 30,
40, 50, 60, 70, 80, -30, -20};
const s8 CoPowModifiers[] = {-10, 0, 10, 20, 30, 40, 50,
60, 70, 80, 80, 80, -10, 0};
const s8 SCoPowModifiers[] = {10, 20, 30, 40, 50, 60, 70,
80, 80, 80, 80, 80, 10, 20};
const s8 DefModifiers[] = {-30, -20, -10, 0, 10, 20, 30, 40,
50, 10, -30, -20, 0, 20, 30};
const s8 CoDefModifiers[] = {-20, -10, 0, 10, 20, 30, 40, 50,
60, 60, -20, -10, 10, 30, 40};
const s8 SCoDefModifiers[] = {-10, 0, 10, 20, 30, 40, 50, 60,
60, 60, -10, 0, 20, 40, 50};
enum {
none1,
inf,
mech,
mdt,
apc,
tank,
recon,
tcop,
neo,
lndr,
artl,
rckt,
none2,
none3,
anti,
miss,
fighter,
bomber,
none4,
copter,
none5,
bship,
cruiser,
none6,
sub
};
#define tcop_factory 0x14
#define apc_factory 0x7
// 0x60 / 32 days of 3 units
// clang-format off
const u8 GenericFactoryUnits[] = {
tcop_factory, tank, inf, // on loop?
recon, none1, none1, // day 1
none1, none1, mech,
none1, inf, none1,
inf, tank, none1,
inf, recon, mech,
none1, apc_factory, artl,
apc_factory, none1, copter,
mdt, none1, none1,
none1, neo, none1,
none1, none1, rckt,
tank, recon, tank, // day 11
// below is identical to Liberation (Hard)
copter, copter, copter,
tank, none1, anti,
none1, artl, mdt,
none1, none1, none1,
inf, none1, neo,
tank, tank, tank,
none1, inf, none1,
bomber, none1, anti,
artl, inf, none1,
mdt, none1, tank,
none1, fighter, none1,
none1, anti, mech,
inf, mdt, artl,
none1, none1, none1,
bomber, neo, fighter,
mech, none1, tank,
none1, tank, none1,
anti, anti, none1,
none1, none1, tank,
tank, inf, mech,
};
// Liberation (Hard)
const u8 GenericFactoryUnits2[] = {
tcop_factory, tank, inf, // on loop?
recon, copter, none1, // day 1
none1, anti, mech,
none1, none1, none1,
bomber, mdt, artl,
inf, none1, mech,
none1, fighter, none1,
apc_factory, none1, tank,
neo, rckt, neo,
none1, none1, none1,
none1, tcop_factory, inf,
miss, recon, none1,
copter, copter, copter,
tank, none1, anti,
none1, artl, mdt,
none1, none1, none1,
inf, none1, neo,
tank, tank, tank,
none1, inf, none1,
bomber, none1, anti,
artl, inf, none1,
mdt, none1, tank,
none1, fighter, none1,
none1, anti, mech,
inf, mdt, artl,
none1, none1, none1,
bomber, neo, fighter,
mech, none1, tank,
none1, tank, none1,
anti, anti, none1,
none1, none1, tank,
tank, inf, mech,
};
const u8 validNoneUnits[] = {none1, none1, none1, none1, none1, inf, mech, recon, };
const u8 validWeakUnits[] = {inf, mech, apc_factory, recon, tcop_factory, none1};
const u8 validMedUnits[] = {inf, mech, tank, recon, anti, copter, artl, none1};
const u8 validStrongUnits[] = {mdt, mech, tank, rckt, anti,
copter, miss, fighter, bomber, neo, none1};
// clang-format on
void RandomizeFactoryUnits(int difficulty, u8 data[0x60]) {
int tmp = 0;
int rand = 0;
int size = 0;
const u8 *bank = validWeakUnits;
for (int i = 0; i < 0x60; ++i) {
tmp = data[i];
switch (tmp) {
case none1: {
bank = validNoneUnits;
break;
}
case inf: {
bank = validWeakUnits;
break;
}
case mech: {
bank = validWeakUnits;
break;
}
case apc_factory: {
bank = validWeakUnits;
break;
}
case recon: {
bank = validWeakUnits;
break;
}
case tcop_factory: {
bank = validWeakUnits;
break;
}
case tank: {
bank = validMedUnits;
break;
}
case anti: {
bank = validMedUnits;
break;
}
case copter: {
bank = validMedUnits;
break;
}
case artl: {
bank = validMedUnits;
break;
}
case mdt: {
bank = validStrongUnits;
break;
}
case rckt: {
bank = validStrongUnits;
break;
}
case miss: {
bank = validStrongUnits;
break;
}
case fighter: {
bank = validStrongUnits;
break;
}
case bomber: {
bank = validStrongUnits;
break;
}
case neo: {
bank = validStrongUnits;
break;
}
default:
}
if (bank == validNoneUnits) {
size = sizeof(validNoneUnits);
}
if (bank == validWeakUnits) {
size = sizeof(validWeakUnits);
}
if (bank == validMedUnits) {
size = sizeof(validMedUnits);
}
if (bank == validStrongUnits) {
size = sizeof(validStrongUnits);
}
rand = HashByte_Ch(i, size, gCh, tmp);
data[i] = bank[rand];
}
};
struct PlayerStruct {
u32 funds; // P1 Funds
u32 spent; // P1 Total Funds spent
u32 income; // P1 Current Income
u8 bases; // P1's Owned Bases Total
u8 cities; // P1's Owned Cities Total
u8 airports; // P1's Owned Airports Total
u8 ports; // P1's Owned Ports Total
u8 properties; // P1 Properties Owned
u8 captures; // P1's Properties Captured?
// padding
u16 padding1;
u8 defeated; // =01 when P1 is defeated
u16 destroyedThisTurn; // Stores count of units destroyed this turn
u16 totalDestroyed; // Stores count of maximum units destroyed
u8 teamColour; // Player 1 Team Colour
u8 aiControlled; // 00 = None, 01 = Human, 02 = AI
u8 turnState; // =03 when P1's Turn
u8 co; // P1 CO
/*
020232DE : P1 CO Mode (00 = Normal, 01 = COP, 02 = SCOP)
020232DF : P1 CO Mode (Used for COP Activation)
020232E0 W : P1 S/COP Charge
020232E4 : P1, which COP noise to play/Is COP/SCOP ready?
020232E5 : P1 CO Power Uses
020232E6 : Temp Firepower Bonus
020232E8 : Temp Defence Bonus
020232EA : P1's Team (Used for attacking)
020232EC : Stores a team related byte - Appears to be the used
one, others used for setup 020232ED : P1's HQ X Co-ordinate 020232EE
: P1's HQ Y Co-ordinate 020232EF : P1's Selection Cursor X
Co-ordinate 020232F0 : P1's Selection Cursor Y Co-ordinate
020232F2 : If set to True, Kill Player on next End Turn. 020232F3 : Rank
Earned 020232F4 : Points for Speed Score 020232F5
: Points for Power Score 020232F6 : Points for Technique Score
020232F8 : Total Score
020232FA : Stores Unit count
020232FB : Stores Unit Lost Count
*/
};
extern struct PlayerStruct gPlayer0; // neutral properties 02023284
extern struct PlayerStruct gPlayer1; // 20232C0
extern struct PlayerStruct gPlayer2; // 20232FC
extern struct PlayerStruct gPlayer3; // 2023338
extern struct PlayerStruct gPlayer4; // 2023374
int IsCoAiControlled(int co) {
int result = false;
if (gPlayer1.co == co) {
if (gPlayer1.aiControlled == 2) {
result = true;
}
}
if (gPlayer2.co == co) {
if (gPlayer2.aiControlled == 2) {
result = true;
}
}
if (gPlayer3.co == co) {
if (gPlayer3.aiControlled == 2) {
result = true;
}
}
if (gPlayer4.co == co) {
if (gPlayer4.aiControlled == 2) {
result = true;
}
}
// asm("mov r11, r11");
return result;
}
// const int PowModifiers[13] = { -30, -20, -10, 0, 10, 15, 20, 30, 40, 50,
// 60, 70, 75 } ;
int HashPow(int number, int noise, int offset, int coPow) {
LoadDesignRoom1Name();
const s8 *table = PowModifiers;
int size = sizeof(PowModifiers);
switch (coPow) {
case 0x44: {
table = CoPowModifiers;
size = sizeof(CoPowModifiers);
offset += 41; // make it reroll stats using the better modifiers list
break;
}
case 0x88: {
table = SCoPowModifiers;
size = sizeof(SCoPowModifiers);
offset += 66; // make it reroll stats using the better modifiers list
break;
}
default:
}
int result = HashByte_ChIfConfig(number, size, noise, offset);
if (result < 0) {
return number;
}
return table[result];
};
int HashDef(int number, int noise, int offset, int coPow) {
LoadDesignRoom1Name();
const s8 *table = DefModifiers;
int size = sizeof(DefModifiers);
switch (coPow) {
case 0x44: {
table = CoDefModifiers;
size = sizeof(CoDefModifiers);
offset += 41; // make it reroll stats using the better modifiers list
break;
}
case 0x88: {
table = SCoDefModifiers;
size = sizeof(SCoDefModifiers);
offset += 66; // make it reroll stats using the better modifiers list
break;
}
default:
}
int result = HashByte_ChIfConfig(number, size, noise, offset);
if (result < 0) {
return number;
}
result = table[result];
// lash max 20 def in sco
if ((noise == 0xC) && (coPow == 0x88)) {
if (result > 10) {
result = 10;
}
}
if (IsCoAiControlled(noise)) {
if (result > 40) {
result = 40;
}
}
return result;
};
const s8 MovModifiers[] = {-1, -2, 0, 0, 0, 1, 2, 3};
const s8 CoMov[] = {0, -1, 1, 0, 0, 0, 0, 2, 2, 1};
const s8 SCoMov[] = {1, 0, 0, 0, 0, 1, 2, 3, 4, 3};
const s8 RangedMovModifiers[] = {0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 2, 3};
const s8 RangedCoMov[] = {
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0}; // so they can get a +range boost instead
const s8 RangedSCoMov[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const s8 InfantryMov[] = {0, 0, 0, 0, 0, 1, 2, 1, -1, 0, 0, 0, 0, 0,
1, 2, 3, -1, 0, 0, 0, 0, 0, 1, 2, 3, -1, 8};
const s8 CoInfantryMov[] = {0, 0, 0, 2, 1, 1, 1, 1, 2, 3, -1, 8};
const s8 SCoInfantryMov[] = {0, 0, 0, 4, 1, 1, 2, 6, 2, 3, 5, 8};
const s8 MechMov[] = {0, 0, 0, 0, -1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, -1, 1, 1, 0, 0, 2, 3};
const s8 CoMechMov[] = {0, 0, 0, 0, 1, 2, 4, 1, 2, 1, 3};
const s8 SCoMechMov[] = {0, 0, 0, 0, 3, 4, 5, 1, 2, 1, 3};
const s8 ReconMov[] = {0, 0, 1, 2, 3, -1, -2, 1, 2, 3};
const s8 CoReconMov[] = {0, 0, 1, 2, 3, 1, 1, 1, 2, 3};
const s8 SCoReconMov[] = {0, 0, 2, 2, 3, 1, 1, 1, 2, 3};
const s8 FighterMov[] = {0, 0, 0, 0, 0, -1, -2, -3, -4, 1, 2};
const s8 CoFighterMov[] = {0, 0, 0, 0, 0, 1, -1, -2, -3, 1, 2};
const s8 SCoFighterMov[] = {0, 0, 0, 0, 0, 1, 2, -1, -2, 2, 1};
const s8 BomberMov[] = {0, 0, 0, 0, 3, 1, 2, -1, -2, -3, -4, -1, -2};
const s8 CoBomberMov[] = {0, 0, 0, 0, 1, 1, 3, 1, 2, -1, -2, 0, 0};
const s8 SCoBomberMov[] = {0, 1, 1, 1, 2, 1, 3, 1, 3, -1, 2, 0, 0};
int HashMov(int number, int noise, int offset, int coPow) {
// int result = HashByte_Global(number, (max_mov - min_mov)+1, noise,
// noise); result = (max_mov - result) + min_mov;
LoadDesignRoom1Name();
const s8 *table = MovModifiers;
int size = sizeof(MovModifiers);
switch (coPow) {
case 0x44: {
switch (offset) {
case inf: {
table = CoInfantryMov;
size = sizeof(CoInfantryMov);
offset += 41;
break;
}
case mech: {
table = CoMechMov;
size = sizeof(CoMechMov);
offset += 41;
break;
}
case recon: {
table = CoReconMov;
size = sizeof(CoReconMov);
offset += 41;
break;
}
case fighter: {
table = CoFighterMov;
size = sizeof(CoFighterMov);
offset += 41;
break;
}
case bomber: {
table = CoBomberMov;
size = sizeof(CoBomberMov);
offset += 41;
break;
}
case artl:
case rckt:
case miss:
case bship: {
table = RangedCoMov;
size = sizeof(RangedCoMov);
offset += 41;
break;
}
default: {
table = CoMov;
size = sizeof(CoMov);
offset += 41;
}
}
break;
}
case 0x88: {
switch (offset) {
case inf: {
table = SCoInfantryMov;
size = sizeof(SCoInfantryMov);
offset += 66;
break;
}
case mech: {
table = SCoMechMov;
size = sizeof(SCoMechMov);
offset += 66;
break;
}
case recon: {
table = SCoReconMov;
size = sizeof(SCoReconMov);
offset += 66;
break;
}
case fighter: {
table = SCoFighterMov;
size = sizeof(SCoFighterMov);
offset += 66;
break;
}
case bomber: {
table = SCoBomberMov;
size = sizeof(SCoBomberMov);
offset += 66;
break;
}
case artl:
case rckt:
case miss:
case bship: {
table = RangedSCoMov;
size = sizeof(RangedSCoMov);
offset += 66;
break;
}
default: {
table = SCoMov;
size = sizeof(SCoMov);
offset += 66;
}
}
break;
}
default: {
switch (offset) {
case inf: {
table = InfantryMov;
size = sizeof(InfantryMov);
break;
}
case mech: {
table = MechMov;
size = sizeof(MechMov);
break;
}
case recon: {
table = ReconMov;
size = sizeof(ReconMov);
break;
}
case fighter: {
table = FighterMov;
size = sizeof(FighterMov);
break;
}
case bomber: {
table = BomberMov;
size = sizeof(BomberMov);
break;
}
case artl:
case rckt:
case miss:
case bship: {
table = RangedMovModifiers;
size = sizeof(RangedMovModifiers);
break;
}
default:
}
}
}
int result = HashByte_ChIfConfig(number, size, noise, offset + 21);
if (result < 0) {
return number;
}
return table[result];
};
const s8 RangeModifiers[] = {0, 0, 0, 0, 0, 1, 2, 1, 2};
const s8 CoRange[] = {0, 0, 0, 0, 0, 1, 2, 3, 4};
const s8 SCoRange[] = {1, 1, 5, 1, 1, 1, 2, 3, 4};
const s8 AiDirectCmbRange[] = {0, 0, 0, 0};
const s8 ArtilleryRange[] = {0, 0, 0, 1, 1, 1, 2, 1, 2, -1};
const s8 CoArtilleryRange[] = {1, 1, 1, 2, 3, 1, 2, 3, 4, -1};
const s8 SCoArtilleryRange[] = {1, 1, 2, 3, 4, 1, 2, 3, 4, 1};
const s8 RocketRange[] = {0, 0, 0, 1, 1, 1, 2, 3, 4, -1, -2};
const s8 CoRocketRange[] = {0, 1, 2, 1, 2, 1, 2, 3, 4, -1, -1};
const s8 SCoRocketRange[] = {1, 1, 2, 3, 4, 1, 2, 3, 4, 1, 1};
const s8 MissileRange[] = {0, 0, 0, 1, 1, 1, 2, 3, 4, -1, -2};
const s8 CoMissileRange[] = {0, 1, 2, 1, 2, 1, 2, 3, 4, -1, 0};
const s8 SCoMissileRange[] = {1, 1, 2, 3, 4, 1, 2, 3, 4, 1, 1};
const s8 BattleshipRange[] = {0, 0, 0, 1, 1, 1, 2, -1, -2};
const s8 CoBattleshipRange[] = {0, 1, 1, 2, 3, 1, 2, -1, 0};
const s8 SCoBattleshipRange[] = {1, 1, 2, 3, 2, 1, 2, 1, 1};
int HashRange(int number, int noise, int offset, int otherNum, int coPow) {
// int result = HashByte_Global(number, (max_range - min_range)+1, noise,
// noise); result = (max_range - result) + min_range;
LoadDesignRoom1Name();
const s8 *table = RangeModifiers;
int size = sizeof(RangeModifiers);
int aiControlled = IsCoAiControlled(noise);
if (aiControlled) {
table = AiDirectCmbRange;
size = sizeof(AiDirectCmbRange);
}
if ((offset == inf) || (offset == recon)) {
return 0;
}
if (HashMov(otherNum, noise, offset, coPow) > 0) {
return 0;
}
switch (coPow) {
case 0x44: {
switch (offset) {
case artl: {
table = CoArtilleryRange;
size = sizeof(CoArtilleryRange);
offset += 41;
break;
}
case rckt: {
table = CoRocketRange;
size = sizeof(CoRocketRange);
offset += 41;
break;
}
case miss: {
table = CoMissileRange;
size = sizeof(CoMissileRange);
offset += 41;
break;
}
case bship: {
table = CoBattleshipRange;
size = sizeof(CoBattleshipRange);
offset += 41;
break;
}
default: {
table = CoRange;
size = sizeof(CoRange);
if (aiControlled) {
table = AiDirectCmbRange;
size = sizeof(AiDirectCmbRange);
}
}
}
break;
}
case 0x88: {
switch (offset) {
case artl: {
table = SCoArtilleryRange;
size = sizeof(SCoArtilleryRange);
offset += 66;
break;
}
case rckt: {
table = SCoRocketRange;
size = sizeof(SCoRocketRange);
offset += 66;
break;
}
case miss: {
table = SCoMissileRange;
size = sizeof(SCoMissileRange);
offset += 66;
break;
}
case bship: {
table = SCoBattleshipRange;
size = sizeof(SCoBattleshipRange);
offset += 66;
break;
}
default: {
table = SCoRange;
size = sizeof(SCoRange);
offset += 66;
if (aiControlled) {
table = AiDirectCmbRange;
size = sizeof(AiDirectCmbRange);
}
}
}
break;
}
default: {
switch (offset) {
case artl: {
table = ArtilleryRange;
size = sizeof(ArtilleryRange);
break;
}
case rckt: {
table = RocketRange;
size = sizeof(RocketRange);
break;
}
case miss: {
table = MissileRange;
size = sizeof(MissileRange);
break;
}
case bship: {
table = BattleshipRange;
size = sizeof(BattleshipRange);
break;
}
default:
}
break;
}
}
int result = HashByte_ChIfConfig(number, size, noise, offset + 31);
if (result < 0) {
return number;
}
return table[result];
};
//
// function address 2163c InitMap ?
// bl 247A4 sets 3003f68
// bl 8014e44 -> 8014dcc decides on address to store into 3003f68 based on
// 3000050 map size at 21666 load 3003f68 // [3003f68]!! pointer to current
// buffer ? store to 201e450
// [201e450..201e451]?
// 215fc
// around 216fe it sets the terrain for the map
// [201f8c4]!! // terrain
// [201eeb0]!! // tiles
// map size pointer: 8499590
// gMapTile[y][x]: 849959c ?
// r9 as 3003f68 poin 2003010
//
// [2003012]!! // tiles for map
//
// size + 0x417a offset: copy of map size / header stuff?
// 20225f0
// [201ee72]!!
// f4e0 - make road at coords?
// to 201E450 ram / 201EE72
extern void MakeTile(void); // uses above three ram
extern u16 mapTileData[];
extern u16 terrainTileData[];
extern int NumberOfMapPieces;
extern int FrequencyOfObjects_Link;
struct Map_Struct {
u8 x;
u8 y;
u16 data[];
};
struct ChHeader {
u16 x;
u16 y;
};
extern struct Map_Struct *MapPiecesTable[0xFF];
struct randomMapInfo {
u8 sizeX;
u8 sizeY;
u8 blackHoleExists;
u8 city;
u8 base;
u8 airport;
u8 port;
u8 silo;
u8 minicannon;
u8 laser;
u8 blackcannon;
u8 deathray;
u8 factory;
u8 volcano;
};
void GenerateMap(struct Map_Struct *dst, struct ChHeader *head, int chID);
void CopyMapPiece(u16 dst[], u8 placement_x, u8 placement_y, int defaultTile,
struct randomMapInfo *mapInfo);
extern int RandomizeMaps;
int ShouldMapBeRandomized(void) {
LoadDesignRoom1Name();
// DesignRoom1Name[0] = 2; // don't randomize if design room 1 name starts
// with "B" or "C"
if (DesignRoom1Name[0] == 0x42 || DesignRoom1Name[0] == 0x43) {
return false;
}
if (DesignRoom1Name[0] == 0x20) {
if (DesignRoom1Name[1] == 0x42 || DesignRoom1Name[1] == 0x43) {
return false;
}
}
return RandomizeMaps; // change to return false; later
}
struct Vec2u {
int x;
int y;
};
extern int Rand(int val);
int NextRN(int val) {
if (!val) {
val = 0x29ae6736;
}
val = Rand(val);
return val;
}
extern void MakeRoad(int x, int y);
extern void MakeRoadSimple(int x, int y);
extern void MakeTileSimple(int x, int y, int tile);
extern void MakeMountain(int x, int y, int one);
extern void MakeForest(int x, int y, int one);
extern void MakeForestSimple(int x, int y, int one);
extern void MakeRiver(int x, int y);
extern void MakeSea(int x, int y, int one);
extern void MakeSeaSafe(int x, int y, int one);
extern void MakeSeaSafest(int x, int y);
extern void MakeBridge(int x, int y, int one);
extern void MakeShoal(int x, int y, int one);
extern void MakePipe(int x, int y);
extern void MakeSeam(int x, int y);
extern void MakeReefSafe(int x, int y, int one);
extern int GetSeamType(int x, int y);
#define HQ_OS (0x714 >> 2)
#define BASE_OS (0x718 >> 2)
#define HQ_BM (0x728 >> 2)
#define BASE_BM (0x72c >> 2)
#define HQ_GE (0x73C >> 2)
#define BASE_GE (0x740 >> 2)
#define HQ_YS (0x750 >> 2)
#define BASE_YS (0x754 >> 2)
#define Mountain 0x80 >> 2
#define Plain 0x4 >> 2
#define Forest 0x21C >> 2
#define Sea 0x20 >> 2 // 1 tile of sea in plains
#define SeaC 0xA8 >> 2 // connecting to sea