-
Notifications
You must be signed in to change notification settings - Fork 3
/
C_code.c
10786 lines (10078 loc) · 288 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
// #define FORCE_SPECIFIC_SEED
#define VersionNumber " SRR V1.8.7"
#ifdef FE8
#include "headers/prelude.h"
#include "headers/types.h"
#endif
#ifdef FE7
#include "headers/prelude.h"
#include "headers/types.h"
#endif
#ifdef FE6
#include "headers/prelude.h"
#include "headers/types.h"
#endif
extern int maxStat;
int GetGlobalStatCap(void);
#include "headers/gbafe.h"
#define PUREFUNC __attribute__((pure))
#define ARMFUNC __attribute__((target("arm")))
typedef struct
{
/* 00 */ PROC_HEADER;
/* 2c */ int seed;
s8 id; // menu id
u8 offset;
u8 redraw;
s8 digit;
u8 freezeSeed;
u8 calledFromChapter;
u8 reloadPlayers;
u8 reloadEnemies;
u8 skill;
u8 choosingSkill;
u8 clear;
s8 Option[24];
} ConfigMenuProc;
void ReloadAllUnits(ConfigMenuProc *);
int Div(int a, int b) PUREFUNC;
int Div1(int a, int b) PUREFUNC;
int Mod(int a, int b) PUREFUNC;
int DivArm(int b, int a) PUREFUNC;
extern u8 gCh;
extern u16 gTurn;
extern u8 gPhase;
extern u8 gResumed;
static char * const TacticianName = (char * const)(0x202BC18); // 8 bytes long
extern void SetFlag(int flag); // 80798E4
extern void UnsetFlag(int flag);
extern int CheckFlag(int flag);
extern int CasualModeFlag;
#define true 1
#define false 0
struct RandomizerSettings
{
u32 base : 2; // vanilla, random
u32 growth : 2; // vanilla, randomized, 0%, 100%
u32 levelups : 2; // vanilla, seeded, fixed, pad
u32 caps : 3; // vanilla, randomized, 0, 15, 30, 45, 60
u32 class : 2; // vanilla, randomized, players only, enemies only
u32 shopItems : 1;
u32 foundItems : 2; // vanilla, random
u32 randMusic : 2; // vanilla, random
u32 colours : 3; // vanilla, random, janky, portraits only
u32 itemStats : 2; // vanilla, random
u32 itemDur : 2; // vanilla, infinite weps, infinite
u32 playerBonus : 5; // +20 / -10 levels for players
u32 grow50 : 1; // always 50%
u32 fog : 2; // vanilla, always off, always on
u32 disp : 1; // stat screen display
}; // 32 / 32 bits used
struct RandomizerValues
{
u32 seed : 20; // max value of 999999 /
u32 variance : 5; // up to 5*31 / 100%
u32 bonus : 5; // +20 / -10 levels for enemies
u32 skills : 2; // vanilla, random, fixed, rand + x skill
};
struct RecruitmentValues
{
u8 recruitment : 3;
u8 pauseNameReplace : 1;
u8 newClasses : 2;
u8 ai : 2;
};
struct TimedHitsDifficultyStruct
{
u8 difficulty : 5;
u8 alwaysA : 1;
u8 off : 1;
u8 cheats : 1;
};
struct GrowthBonusValues
{
u8 player : 4;
u8 enemy : 4;
u8 ForcedCharTable : 5;
u8 pad : 3;
};
extern struct TimedHitsDifficultyStruct * TimedHitsDifficultyRam;
extern struct RecruitmentValues * RecruitValues;
extern struct RandomizerSettings * RandBitflags;
extern struct RandomizerValues * RandValues;
extern struct GrowthBonusValues * GrowthValues;
extern u8 * MaxItems;
extern int MaxItems_Link;
extern u8 * MaxClasses;
extern int MaxClasses_Link;
struct ExceptionsStruct
{
u8 NeverChangeFrom;
u8 NeverChangeInto;
};
extern struct ExceptionsStruct ItemExceptions[];
extern struct ExceptionsStruct ClassExceptions[];
extern struct ExceptionsStruct CharExceptions[];
extern struct ExceptionsStruct SkillExceptions[];
extern int SkillSysInstalled;
extern int StrMagInstalled;
extern int DefaultConfigToVanilla;
#define SET_TEXT_USED
// #define STRINGS_IN_ROM // faster if defined, but gotta write all the names in the installer
#define TempTextBufferSize 14
typedef struct
{
/* 00 */ PROC_HEADER;
u16 count;
u8 id[0x40];
} RecruitmentProc;
RecruitmentProc * InitRandomRecruitmentProc(int procID);
void LoopRandomRecruitmentProc(RecruitmentProc * proc)
{
return;
}
const struct ProcCmd RecruitmentProcCmd1[] = {
PROC_NAME("ReorderedRecruitment_One"),
PROC_YIELD,
PROC_REPEAT(LoopRandomRecruitmentProc),
PROC_END,
};
const struct ProcCmd RecruitmentProcCmd2[] = {
PROC_NAME("ReorderedRecruitment_Two"),
PROC_YIELD,
PROC_REPEAT(LoopRandomRecruitmentProc),
PROC_END,
};
const struct ProcCmd RecruitmentProcCmd3[] = {
PROC_NAME("ReorderedRecruitment_Three"),
PROC_YIELD,
PROC_REPEAT(LoopRandomRecruitmentProc),
PROC_END,
};
const struct ProcCmd RecruitmentProcCmd4[] = {
PROC_NAME("ReorderedRecruitment_Four"),
PROC_YIELD,
PROC_REPEAT(LoopRandomRecruitmentProc),
PROC_END,
};
extern void ForceHardModeFE8(void);
void MaybeForceHardModeFE8(void)
{
#ifndef FE8
return;
#endif
ForceHardModeFE8();
}
int ShouldRandomizeRecruitment(void)
{
return RecruitValues->recruitment;
}
int ShouldRandomizeRecruitmentForUnitID(int id)
{
if (!GetCharacterData(id)->portraitId)
{
return false;
}
return ShouldRandomizeRecruitment();
}
int ShouldRandomizeRecruitmentForPortraitID(int id)
{
if (!id)
{
return false;
}
// if (id > PlayerPortraitSize) { return false; } // players only atm
return ShouldRandomizeRecruitment();
}
u16 HashByte_Global(int number, int max, int noise[], int offset);
u32 GetNthRN_Simple(int n, int seed, u32 currentRN);
u32 HashByte_Simple(u32 rn, int max)
{
if (max == 0)
return 0;
return Mod((rn >> 3), max);
};
extern u8 VanillaSkill[];
extern int NumberOfSkills;
extern u8 * AlwaysSkill;
int RandomizeSkill(int id, struct Unit * unit)
{
if (!id)
{
return 0;
}
if (SkillExceptions[id].NeverChangeFrom)
{
return id;
}
if (!RandValues->skills)
{
if (!VanillaSkill[id])
{
return 0;
}
else
{
return id;
}
}
if (RandValues->skills == 2)
{
return id;
}
const struct CharacterData * table = unit->pCharacterData;
int noise[4] = { table->number, id, id, table->portraitId };
id = HashByte_Global(id, NumberOfSkills - 1, noise, 12) + 1; // never 0
if (SkillExceptions[id].NeverChangeInto)
{
return 0;
}
return id;
}
int GetAlwaysSkill(struct Unit * unit)
{
if (UNIT_FACTION(unit) == FACTION_RED)
{
return 0;
}
if (RandValues->skills != 3)
{
return 0;
}
return *AlwaysSkill;
}
extern u8 AlwaysSkillTable[];
int GetNextAlwaysSkill(int id)
{
id++;
for (int i = id; i < NumberOfSkills; ++i)
{
if (AlwaysSkillTable[i])
{
return i;
}
}
for (int i = 0; i < NumberOfSkills; ++i)
{
if (AlwaysSkillTable[i])
{
return i;
}
}
return 0;
}
int GetPreviousAlwaysSkill(int id)
{
id--;
for (int i = id; i > 0; --i)
{
if (AlwaysSkillTable[i])
{
return i;
}
}
for (int i = NumberOfSkills; i > 0; --i)
{
if (AlwaysSkillTable[i])
{
return i;
}
}
return 0;
}
#ifdef FE6
#define MAX_CHAR_ID 0xE2
#endif
#ifdef FE7
#define MAX_CHAR_ID 0xFD
#endif
#ifdef FE8
#define MAX_CHAR_ID 0xFF
#endif
#ifdef FE8
#define ListSize 120 // 0x22
#define PlayerPortraitSize 0x2C
#endif
#ifdef FE7
#define ListSize MAX_CHAR_ID // 0x28
#define PlayerPortraitSize 0x4a
#endif
#ifdef FE6
#define ListSize MAX_CHAR_ID // 0x3f // 0x44 but max is 0x3f atm?
#define PlayerPortraitSize 0x35
#endif
extern const struct CharacterData gCharacterData[];
#ifdef FE6
extern const struct FE8CharacterData gCharacterDataFE1[];
extern const struct FE8CharacterData gCharacterDataFE4[];
extern const struct FE8CharacterData gCharacterDataFE5[];
extern const struct FE8CharacterData gCharacterDataFE6[];
extern const struct FE8CharacterData gCharacterDataFE7[];
extern const struct FE8CharacterData gCharacterDataFE8[];
extern const struct FE8CharacterData gCharacterDataFE10[];
extern const struct FE8CharacterData gCharacterDataFE13[];
extern const struct FE8CharacterData gCharacterDataFE14[];
extern const struct FE8CharacterData gCharacterDataFE15[];
extern const struct FE8CharacterData gCharacterDataFE16[];
extern const struct FE8CharacterData gCharacterDataFE17[];
#endif
#ifndef FE6
extern const struct CharacterData gCharacterDataFE1[];
extern const struct CharacterData gCharacterDataFE4[];
extern const struct CharacterData gCharacterDataFE5[];
extern const struct CharacterData gCharacterDataFE6[];
extern const struct CharacterData gCharacterDataFE7[];
extern const struct CharacterData gCharacterDataFE8[];
extern const struct CharacterData gCharacterDataFE10[];
extern const struct CharacterData gCharacterDataFE13[];
extern const struct CharacterData gCharacterDataFE14[];
extern const struct CharacterData gCharacterDataFE15[];
extern const struct CharacterData gCharacterDataFE16[];
extern const struct CharacterData gCharacterDataFE17[];
#endif
#ifdef FE6
const struct FE8CharacterData
#endif
#ifndef FE6
const struct CharacterData
#endif
* const cData[] = {
#ifdef FE6
gCharacterDataFE6,
#else
gCharacterData,
#endif
gCharacterDataFE1, gCharacterDataFE4, gCharacterDataFE5,
#ifdef FE8
gCharacterDataFE6, gCharacterDataFE7,
#endif
#ifdef FE7
gCharacterDataFE6, gCharacterDataFE8,
#endif
#ifdef FE6
gCharacterDataFE7, gCharacterDataFE8,
#endif
gCharacterDataFE10, gCharacterDataFE13, gCharacterDataFE14,
gCharacterDataFE15, gCharacterDataFE16, gCharacterDataFE17,
};
const int NumberOfCharTables = 12;
int ShouldRandomizeUsedCharTable(void)
{
return (GrowthValues->ForcedCharTable <= NumberOfCharTables);
}
int GetForcedCharTable(void)
{
return GrowthValues->ForcedCharTable;
}
int GetCharTableID(int portraitID)
{
// if (!ShouldRandomizeUsedCharTable())
// {
// return 0;
// } // vanilla table only
int result = GetForcedCharTable();
if (result < NumberOfCharTables)
{
return result;
}
int noise[4] = { 5, 7, 9, 11 };
result = HashByte_Global(portraitID, NumberOfCharTables, noise, portraitID);
// randomize
return result;
}
#ifdef FE6
const struct FE8CharacterData *
#endif
#ifndef FE6
const struct CharacterData *
#endif
NewGetCharacterData(int charId, int tableID)
{
if (charId < 1)
return NULL;
if (!tableID)
{
#ifdef FE6
return (const struct FE8CharacterData *)GetCharacterData(charId);
#else
return GetCharacterData(charId);
#endif
}
// 1 - 3a, 6e - 7f, 95 - a6: use new char tables
// otherwise, use vanilla one
// fe6: 1-0x44 because vanilla playables go up to 0x44, otherwise
// it wants to randomize into 0x3b - 0x44 which are non-playables
// in our new char tables
#ifdef FE7 // use vanilla table for non-playables eg. bosses
if ((charId > 0x3a && charId < 0x6e) || (charId > 0x7f && charId < 0x95) || (charId > 0xA6))
{
return GetCharacterData(charId);
}
#endif
#ifdef FE6 // use vanilla table for non-playables eg. bosses
if ((charId > 0x44 && charId < 0x6e) || (charId > 0x7f && charId < 0x95) || (charId > 0xA6))
{
return (const struct FE8CharacterData *)GetCharacterData(charId);
}
#endif
if (!((cData[tableID] + (charId - 1))->number))
return NULL;
return cData[tableID] + (charId - 1);
}
extern u8 ReplacePortraitTable[];
int GetUnitIdOfPortrait(int portraitID)
{
if (portraitID < 0x100) // vanilla closed eyes etc portraits to replace
{
if (ReplacePortraitTable[portraitID])
{
portraitID = ReplacePortraitTable[portraitID];
}
}
const struct CharacterData * table; // = GetCharacterData(1);
// int bankID = 0;
// while (bankID < NumberOfCharTables)
// {
for (int i = 1; i <= MAX_CHAR_ID; i++)
{
table = GetCharacterData(i);
if (table->portraitId == portraitID)
{
return table->number;
}
table++;
}
// bankID++;
// }
return 0;
}
const struct CharacterData * GetReorderedCharacter(const struct CharacterData * table)
{
if (!table->portraitId)
{
return table;
}
RecruitmentProc * proc = NULL;
int id = table->number;
if (!ShouldRandomizeRecruitmentForUnitID(id))
{
return GetCharacterData(id);
}
int tableID = GetCharTableID(table->portraitId);
int procID = id >> 6; // 0, 1, 2, or 3
switch (procID)
{
case 0:
{
proc = Proc_Find(RecruitmentProcCmd1);
break;
}
case 1:
{
proc = Proc_Find(RecruitmentProcCmd2);
break;
}
case 2:
{
proc = Proc_Find(RecruitmentProcCmd3);
break;
}
case 3:
{
proc = Proc_Find(RecruitmentProcCmd4);
break;
}
default:
}
if (!proc)
{
proc = InitRandomRecruitmentProc(procID);
}
int unitID = proc->id[(id & 0x3F) - 1];
if (!unitID)
{
unitID = id;
}
const struct CharacterData * result = (struct CharacterData *)NewGetCharacterData(unitID, tableID);
if (!result->portraitId)
{
result = table;
}
return result;
}
// each vanilla portrait is assigned to a new portrait from any char table
// text replace must search all tables
const struct CharacterData * GetReorderedUnit(struct Unit * unit)
{
return GetReorderedCharacter(unit->pCharacterData);
}
int GetReorderedUnitID(struct Unit * unit)
{
return GetReorderedCharacter(unit->pCharacterData)->number;
}
int GetReorderedCharacterPortraitByPortrait(int portraitID)
{
// int tableID = GetCharTableID(portraitID);
int result = GetUnitIdOfPortrait(portraitID);
if (!result)
{
return portraitID;
}
return GetReorderedCharacter(GetCharacterData(result))->portraitId;
}
// also GetAdjustedPortraitId exists
int GetRandomizedPortrait(int portraitID, int seed)
{
if (portraitID < 0)
{
return portraitID;
}
if (!ShouldRandomizeRecruitmentForPortraitID(portraitID))
{
return portraitID;
}
int result = GetReorderedCharacterPortraitByPortrait(portraitID);
if (!result)
{
return portraitID;
}
// if no unitID with this portrait, show a random one (before class cards)
#ifdef FE8
if (!result)
{
return HashByte_Simple(GetNthRN_Simple(portraitID, seed, 0), 0x71) + 2;
}
#endif
#ifdef FE7
if (!result)
{
return HashByte_Simple(GetNthRN_Simple(portraitID, seed, 0), 0xBD) + 2;
}
#endif
#ifdef FE6
if (!result)
{
return HashByte_Simple(GetNthRN_Simple(portraitID, seed, 0), 0x98) + 2;
}
#endif
//
return result;
}
int GetNameTextIdOfRandomizedPortrait(int portraitID, int seed)
{
portraitID = GetRandomizedPortrait(portraitID, seed);
#ifdef FE6
const struct FE8CharacterData * table; // = GetCharacterData(1);
#endif
#ifndef FE6
const struct CharacterData * table; // = GetCharacterData(1);
#endif
int bankID = 0;
while (bankID < NumberOfCharTables)
{
for (int i = 1; i <= MAX_CHAR_ID; i++)
{
table = NewGetCharacterData(i, bankID);
if (table->portraitId == portraitID)
{
return table->nameTextId;
}
// table++;
}
bankID++;
}
return 1; // "Yes"
}
int CanCharacterBecomeBoss(const struct CharacterData * table)
{
// if (table->number > 0x40
int boss;
boss = table->attributes & (CA_BOSS);
if ((RecruitValues->recruitment == 5))
{
return false;
}
if ((!boss) && (RecruitValues->recruitment == 4))
{
return true;
} // players become bosses and vice versa
if (boss)
{
return true;
}
return false;
}
int MustCharacterBecomeBoss(const struct CharacterData * table)
{
int boss;
boss = table->attributes & (CA_BOSS);
if ((RecruitValues->recruitment == 5))
{
return false;
}
// if ((!boss) && (RecruitValues->recruitment == 4)) { return true; } // players become bosses and vice
// versa if ((boss) && (RecruitValues->recruitment == 4)) { return false; } // players become bosses and
// vice versa
if (boss)
{
return true;
}
return false;
}
int GetAdjustedCharacterID(const struct CharacterData * table)
{
int portraitID = table->portraitId;
if (!portraitID)
{
return table->number;
}
const struct CharacterData * table2 = GetCharacterData(1);
for (int i = 0; i < MAX_CHAR_ID; ++i)
{ // replace duplicate unit IDs (eg. Lyn without supports and Lyn with supports becomes the same char)
if ((portraitID == table2->portraitId) && (table2->pSupportData))
{
return table2->number;
}
table2++;
}
#ifdef FE7
if ((table->attributes & CA_MAXLEVEL10) && (!(table->attributes & CA_BOSS)))
{ // Replace morphs
int nameTextId = table->nameTextId;
table2 = GetCharacterData(1);
for (int i = 0; i < MAX_CHAR_ID; ++i)
{
if ((nameTextId == table2->nameTextId))
{
return table2->number;
}
// if ((nameTextId == table2->nameTextId) && (!(table2->attributes & CA_MAXLEVEL10))) { return
// table2->number; }
table2++;
}
}
#endif
return table->number;
}
// lyn mode units have no support pointers, so perhaps use that?
int GetUnitListToUse(const struct CharacterData * table, int boss, int excludeNoSupports)
{
int result = 0;
if (table->number > MAX_CHAR_ID)
{
return result;
}
if (!table->portraitId)
{
return result;
}
// look for duplicate units
#ifndef FE8
if (excludeNoSupports)
{
if (!table->pSupportData)
{
if (table->number != GetAdjustedCharacterID(table))
{
return 0;
}
}
}
#endif
result = 1;
// if (boss && (CanCharacterBecomeBoss(table))) { result = 1; }
if (boss && (MustCharacterBecomeBoss(table)))
{
result = 2;
}
if (result == 1)
{
if (RecruitValues->recruitment == 2)
{
result = 0;
}
}
if (result == 2)
{
if (RecruitValues->recruitment == 1)
{
result = 0;
}
}
if (RecruitValues->recruitment < 4)
{
if (result == 1) // players reordered
{
// there are some non-bosses with portraits below
// these need to be manually excluded
// these IDs would be excluded automatically in certain games
// so it's okay to manually exclude them in all the games
// issue: copy fe8 stuff to fix
if (table->number == 0x65) // Idunn, also 0x66
{
return 0;
}
if (table->number == 0x5a) // Maxime fe7
{
return 0;
}
// 0x7A Zephiel, 0x7B Elbert, 0x9E Natalie are now valid in fe7 *shrugs*
if (table->number == 0x54) // Pablo fe8
{
return 0;
}
if (table->number == 0x66) // bandit with portrait / Idunn
{
return 0;
}
if (table->number == 0x67) // bandit with portrait
{
return 0;
}
if (table->number > 0xA6) // playables are below 0xA6 unit ID
{
return 0;
}
}
}
if (RecruitValues->recruitment == 5)
{
result = 1;
}
// if (!boss && (MustCharacterBecomeBoss(table))) { result = false; }
return result;
}
int CallGetUnitListToUse(const struct CharacterData * table, int boss, int excludeNoSupports)
{
int result = GetUnitListToUse(table, boss, excludeNoSupports);
if (RecruitValues->recruitment == 4)
{
if (result == 1)
{
return 2;
}
else if (result == 2)
{
return 1;
}
}
return result;
}
// #define REVERSE_ORDER
RecruitmentProc * InitRandomRecruitmentProc(int procID)
{
u8 unit[80];
u8 bosses[80];
const struct CharacterData * table = GetCharacterData(1);
int c = 0;
int b = 0; // bosses count
int seed = RandValues->seed;
RecruitmentProc * proc1 = Proc_Start(RecruitmentProcCmd1, PROC_TREE_3);
RecruitmentProc * proc2 = Proc_Start(RecruitmentProcCmd2, PROC_TREE_3);
RecruitmentProc * proc3 = Proc_Start(RecruitmentProcCmd3, PROC_TREE_3);
RecruitmentProc * proc4 = Proc_Start(RecruitmentProcCmd4, PROC_TREE_3);
RecruitmentProc * proc = proc1;
int boss;
proc->id[0] = 0;
// table--;
for (int i = 1; i <= MAX_CHAR_ID; ++i)
{ // all available units
table = GetCharacterData(i);
table = (const struct CharacterData *)NewGetCharacterData(i, GetCharTableID(table->portraitId));
// table++;
if (i == 0x40)
{
proc = proc2;
}
if (i == 0x80)
{
proc = proc3;
}
if (i == 0xC0)
{
proc = proc4;
}
proc->id[i & 0x3F] = 0x0;
#ifdef FE7
if ((table->attributes & CA_MAXLEVEL10) && (!(table->attributes & CA_BOSS)))
{
continue;
} // Morphs
#endif
boss = table->attributes & (CA_BOSS);
switch (GetUnitListToUse(table, boss, true))
{
case 0: // eg no portrait
{
continue;
break;
}
case 1:
{
unit[c] = i;
c++;
break;
}
case 2:
{
bosses[b] = i;
b++;
break;
}
default:
}
}
// proc->count = c;
int c_max = c; // count of characters to randomize from
int b_max = b;
int num;
u32 rn = 0;
#ifdef REVERSE_ORDER
proc = proc4;
// table = GetCharacterData(MAX_CHAR_ID);
for (int i = MAX_CHAR_ID; i > 0; --i)
{ // reordered at random
// table--;
if (i <= 0xBF)
{
proc = proc3;
}
if (i <= 0x7F)
{
proc = proc2;
}
if (i <= 0x3F)
{
proc = proc1;
}
#else
proc = proc1;
for (int i = 1; i < MAX_CHAR_ID; ++i)
{
if (i >= 0x40)
{
proc = proc2;
}
if (i >= 0x80)
{
proc = proc3;
}
if (i >= 0xC0)
{
proc = proc4;
}
#endif
table = GetCharacterData(i);
#ifdef FE7
if ((table->attributes & CA_MAXLEVEL10) && (!(table->attributes & CA_BOSS)))
{
continue;
} // Morphs
#endif
// table = (const struct CharacterData *)NewGetCharacterData(i, GetCharTableID(table->portraitId));
// don't use NewGetCharacterData - just replace vanilla chars now
boss = table->attributes & (CA_BOSS);
switch (CallGetUnitListToUse(table, boss, true))
{
case 0:
{
continue;
break;
}
case 1:
{
rn = GetNthRN_Simple(i - 1, seed, rn);
c--;
if (c < 0)
{
c = c_max - 1;
}
num = HashByte_Simple(rn, c);
proc->id[(i & 0x3F) - 1] = unit[num]; // proc + offset set to nth char
unit[num] = unit[c]; // move last entry to one we just used
unit[c] = proc->id[(i & 0x3F) - 1];
break;
}
case 2:
{
rn = GetNthRN_Simple(i - 1, seed, rn);
b--;
if (b < 0)
{
b = b_max - 1;
}
// if (b < 0) { proc->id[(i&0x3F)-1] = 0xFD; continue; }
num = HashByte_Simple(rn, b);
proc->id[(i & 0x3F) - 1] = bosses[num];
bosses[num] = bosses[b]; // move last entry to one we just used
bosses[b] = proc->id[(i & 0x3F) - 1];
break;
}
default:
}
}
// #ifndef FE8 // breaks with skillsys atm
#ifdef REVERSE_ORDER
proc = proc4;
for (int i = MAX_CHAR_ID; i > 0; --i)
{
// table--;
if (i <= 0xBF)
{
proc = proc3;
}
if (i <= 0x7F)
{
proc = proc2;
}
if (i <= 0x3F)
{
proc = proc1;
}
#else
proc = proc1;
for (int i = 1; i < MAX_CHAR_ID; ++i)
{
if (i >= 0x40)
{
proc = proc2;
}
if (i >= 0x80)