forked from rh-hideout/pokeemerald-expansion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbattle_debug.c
2593 lines (2418 loc) · 94.6 KB
/
battle_debug.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 "global.h"
#include "battle.h"
#include "battle_anim.h"
#include "battle_message.h"
#include "main.h"
#include "menu.h"
#include "menu_helpers.h"
#include "scanline_effect.h"
#include "palette.h"
#include "party_menu.h"
#include "pokemon_icon.h"
#include "sprite.h"
#include "item.h"
#include "task.h"
#include "bg.h"
#include "gpu_regs.h"
#include "window.h"
#include "text.h"
#include "text_window.h"
#include "international_string_util.h"
#include "strings.h"
#include "battle_ai_main.h"
#include "battle_ai_util.h"
#include "list_menu.h"
#include "decompress.h"
#include "trainer_pokemon_sprites.h"
#include "malloc.h"
#include "string_util.h"
#include "util.h"
#include "data.h"
#include "reset_rtc_screen.h"
#include "reshow_battle_screen.h"
#include "constants/abilities.h"
#include "constants/party_menu.h"
#include "constants/moves.h"
#include "constants/items.h"
#include "constants/rgb.h"
#include "constants/hold_effects.h"
#define MAX_MODIFY_DIGITS 4
struct BattleDebugModifyArrows
{
u8 arrowSpriteId[2];
u16 minValue;
u16 maxValue;
int currValue;
u8 currentDigit:4;
u8 maxDigits:4;
u8 charDigits[MAX_MODIFY_DIGITS];
void *modifiedValPtr;
u8 typeOfVal;
};
struct BattleDebugMenu
{
u8 battlerId:2;
u8 aiBattlerId:2;
u8 battlerWindowId;
u8 mainListWindowId;
u8 mainListTaskId;
u8 currentMainListItemId;
u8 secondaryListWindowId;
u8 secondaryListTaskId;
u8 currentSecondaryListItemId;
u8 secondaryListItemCount;
u8 modifyWindowId;
u8 activeWindow;
struct BattleDebugModifyArrows modifyArrows;
const struct BitfieldInfo *bitfield;
bool8 battlerWasChanged[MAX_BATTLERS_COUNT];
u8 aiViewState;
u8 aiMonSpriteId;
u8 aiMovesWindowId;
union
{
u8 aiIconSpriteIds[MAX_BATTLERS_COUNT];
u8 aiPartyIcons[PARTY_SIZE];
} spriteIds;
};
struct __attribute__((__packed__)) BitfieldInfo
{
u8 bitsCount;
u8 currBit;
};
enum
{
LIST_ITEM_MOVES,
LIST_ITEM_ABILITY,
LIST_ITEM_HELD_ITEM,
LIST_ITEM_PP,
LIST_ITEM_TYPES,
LIST_ITEM_STATS,
LIST_ITEM_STAT_STAGES,
LIST_ITEM_STATUS1,
LIST_ITEM_STATUS2,
LIST_ITEM_STATUS3,
LIST_ITEM_STATUS4,
LIST_ITEM_SIDE_STATUS,
LIST_ITEM_AI,
LIST_ITEM_AI_MOVES_PTS,
LIST_ITEM_AI_INFO,
LIST_ITEM_AI_PARTY,
LIST_ITEM_VARIOUS,
LIST_ITEM_COUNT
};
enum
{
LIST_STAT_HP_CURRENT,
LIST_STAT_HP_MAX,
LIST_STAT_ATTACK,
LIST_STAT_DEFENSE,
LIST_STAT_SPEED,
LIST_STAT_SP_ATK,
LIST_STAT_SP_DEF,
};
enum
{
LIST_STATUS1_SLEEP,
LIST_STATUS1_POISON,
LIST_STATUS1_BURN,
LIST_STATUS1_FREEZE,
LIST_STATUS1_PARALYSIS,
LIST_STATUS1_TOXIC_POISON,
LIST_STATUS1_TOXIC_COUNTER,
LIST_STATUS1_FROSTBITE,
};
enum
{
LIST_STATUS2_CONFUSION,
LIST_STATUS2_FLINCHED,
LIST_STATUS2_TORMENT,
LIST_STATUS2_POWDER,
LIST_STATUS2_DEFENSE_CURL,
LIST_STATUS2_RECHARGE,
LIST_STATUS2_RAGE,
LIST_STATUS2_DESTINY_BOND,
LIST_STATUS2_ESCAPE_PREVENTION,
LIST_STATUS2_CURSED,
LIST_STATUS2_FORESIGHT,
LIST_STATUS2_DRAGON_CHEER,
LIST_STATUS2_FOCUS_ENERGY
};
enum
{
LIST_STATUS3_LEECH_SEED_HEALER,
LIST_STATUS3_LEECH_SEEDED,
LIST_STATUS3_ALWAYS_HITS,
LIST_STATUS3_PERISH_SONG,
LIST_STATUS3_ON_AIR,
LIST_STATUS3_UNDERGROUND,
LIST_STATUS3_MINIMIZED,
LIST_STATUS3_CHARGED_UP,
LIST_STATUS3_ROOTED,
LIST_STATUS3_YAWN,
LIST_STATUS3_IMPRISONED_OTHERS,
LIST_STATUS3_GRUDGE,
LIST_STATUS3_GASTRO_ACID,
LIST_STATUS3_EMBARGO,
LIST_STATUS3_UNDERWATER,
LIST_STATUS3_SMACKED_DOWN,
LIST_STATUS3_TELEKINESIS,
LIST_STATUS3_MIRACLE_EYED,
LIST_STATUS3_MAGNET_RISE,
LIST_STATUS3_HEAL_BLOCK,
LIST_STATUS3_AQUA_RING,
LIST_STATUS3_LASER_FOCUS,
LIST_STATUS3_POWER_TRICK,
};
enum
{
LIST_STATUS4_ELECTRIFIED,
LIST_STATUS4_MUD_SPORT,
LIST_STATUS4_WATER_SPORT,
LIST_STATUS4_SALT_CURE,
LIST_STATUS4_SYRUP_BOMB,
LIST_STATUS4_GLAIVE_RUSH,
};
enum
{
LIST_SIDE_REFLECT,
LIST_SIDE_LIGHTSCREEN,
LIST_SIDE_STICKY_WEB,
LIST_SIDE_SPIKES,
LIST_SIDE_SAFEGUARD,
LIST_SIDE_MIST,
LIST_SIDE_TAILWIND,
LIST_SIDE_AURORA_VEIL,
LIST_SIDE_LUCKY_CHANT,
LIST_SIDE_TOXIC_SPIKES,
LIST_SIDE_STEALTH_ROCK,
LIST_SIDE_STEELSURGE,
LIST_SIDE_DAMAGE_NON_TYPES,
LIST_SIDE_RAINBOW,
LIST_SIDE_SEA_OF_FIRE,
LIST_SIDE_SWAMP,
};
enum
{
LIST_AI_CHECK_BAD_MOVE,
LIST_AI_TRY_TO_FAINT,
LIST_AI_CHECK_VIABILITY,
LIST_AI_SETUP_FIRST_TURN,
LIST_AI_RISKY,
LIST_AI_TRY_TO_2HKO,
LIST_AI_PREFER_BATON_PASS,
LIST_AI_DOUBLE_BATTLE,
LIST_AI_HP_AWARE,
LIST_AI_POWERFUL_STATUS,
LIST_AI_NEGATE_UNAWARE,
LIST_AI_WILL_SUICIDE,
LIST_AI_HELP_PARTNER,
LIST_AI_PREFER_STATUS_MOVES,
LIST_AI_STALL,
LIST_AI_SMART_SWITCHING,
LIST_AI_ACE_POKEMON,
LIST_AI_OMNISCIENT,
LIST_AI_SMART_MON_CHOICES,
LIST_AI_ROAMING,
LIST_AI_SAFARI,
LIST_AI_FIRST_BATTLE,
};
enum
{
VARIOUS_SHOW_HP,
VARIOUS_SUBSTITUTE_HP,
VARIOUS_IN_LOVE,
};
enum
{
ACTIVE_WIN_MAIN,
ACTIVE_WIN_SECONDARY,
ACTIVE_WIN_MODIFY
};
enum
{
VAL_U8,
VAL_U16,
VAL_U32,
VAL_BITFIELD_8,
VAL_BITFIELD_16,
VAL_BITFIELD_32,
VAR_SIDE_STATUS,
VAR_SHOW_HP,
VAR_SUBSTITUTE,
VAR_IN_LOVE,
VAR_U16_4_ENTRIES,
VAL_S8,
VAL_ALL_STAT_STAGES,
};
// Static Declarations
static const u8 *GetHoldEffectName(u16 holdEffect);
// const rom data
static const u8 sText_Moves[] = _("Moves");
static const u8 sText_Ability[] = _("Ability");
static const u8 sText_HeldItem[] = _("Held Item");
static const u8 sText_HoldEffect[] = _("Hold Effect");
static const u8 sText_PP[] = _("PP");
static const u8 sText_Types[] = _("Types");
static const u8 sText_Stats[] = _("Stats");
static const u8 sText_StatStages[] = _("Stat Stages");
static const u8 sText_Status1[] = _("Status1");
static const u8 sText_Status2[] = _("Status2");
static const u8 sText_Status3[] = _("Status3");
static const u8 sText_Status4[] = _("Status4");
static const u8 sText_SideStatus[] = _("Side Status");
static const u8 sText_AI[] = _("AI");
static const u8 sText_AIMovePts[] = _("AI Pts/Dmg");
static const u8 sText_AiKnowledge[] = _("AI Info");
static const u8 sText_AiParty[] = _("AI Party");
static const u8 sText_Various[] = _("Various");
static const u8 sText_CurrHp[] = _("HP Current");
static const u8 sText_MaxHp[] = _("HP Max");
static const u8 sText_Attack[] = _("Attack");
static const u8 sText_Defense[] = _("Defense");
static const u8 sText_Speed[] = _("Speed");
static const u8 sText_SpAtk[] = _("Sp. Atk");
static const u8 sText_SpDef[] = _("Sp. Def");
static const u8 sText_Sleep[] = _("Sleep");
static const u8 sText_Poison[] = _("Poison");
static const u8 sText_Burn[] = _("Burn");
static const u8 sText_Freeze[] = _("Freeze");
static const u8 sText_Paralysis[] = _("Paralysis");
static const u8 sText_ToxicPoison[] = _("Toxic Poison");
static const u8 sText_ToxicCounter[] = _("Toxic Counter");
static const u8 sText_Frostbite[] = _("Frostbite");
static const u8 sText_Confusion[] = _("Confusion");
static const u8 sText_Flinched[] = _("Flinched");
static const u8 sText_Uproar[] = _("Uproar");
static const u8 sText_Torment[] = _("Torment");
static const u8 sText_Bide[] = _("Bide");
static const u8 sText_LockConfuse[] = _("Lock Confuse");
static const u8 sText_MultipleTurns[] = _("Multiple Turns");
static const u8 sText_Wrapped[] = _("Wrapped");
static const u8 sText_Powder[] = _("Powder");
static const u8 sText_Infatuation[] = _("Infatuation");
static const u8 sText_DefenseCurl[] = _("Defense Curl");
static const u8 sText_Transformed[] = _("Transformed");
static const u8 sText_Recharge[] = _("Recharge");
static const u8 sText_Rage[] = _("Rage");
static const u8 sText_Substitute[] = _("Substitute");
static const u8 sText_DestinyBond[] = _("Destiny Bond");
static const u8 sText_EscapePrevention[] = _("Escape Prevention");
static const u8 sText_Nightmare[] = _("Nightmare");
static const u8 sText_Cursed[] = _("Cursed");
static const u8 sText_Foresight[] = _("Foresight");
static const u8 sText_DragonCheer[] = _("Dragon Cheer");
static const u8 sText_FocusEnergy[] = _("Focus Energy");
static const u8 sText_LeechSeedHealer[] = _("Leech Seed Healer");
static const u8 sText_LeechSeeded[] = _("Leech Seeded");
static const u8 sText_AlwaysHits[] = _("Always Hits");
static const u8 sText_PerishSong[] = _("Perish Song");
static const u8 sText_OnAir[] = _("On Air");
static const u8 sText_Underground[] = _("Underground");
static const u8 sText_Minimized[] = _("Minimized");
static const u8 sText_ChargedUp[] = _("Charged Up");
static const u8 sText_Rooted[] = _("Rooted");
static const u8 sText_Yawn[] = _("Yawn");
static const u8 sText_ImprisonedOthers[] = _("Imprisoned Others");
static const u8 sText_Grudge[] = _("Grudge");
static const u8 sText_GastroAcid[] = _("Gastro Acid");
static const u8 sText_Embargo[] = _("Embargo");
static const u8 sText_Underwater[] = _("Underwater");
static const u8 sText_Trace[] = _("Trace");
static const u8 sText_SmackedDown[] = _("Smacked Down");
static const u8 sText_MeFirst[] = _("Me First");
static const u8 sText_Telekinesis[] = _("Telekinesis");
static const u8 sText_PhantomForce[] = _("Phantom Force");
static const u8 sText_MiracleEyed[] = _("Miracle Eyed");
static const u8 sText_MagnetRise[] = _("Magnet Rise");
static const u8 sText_HealBlock[] = _("Heal Block");
static const u8 sText_AquaRing[] = _("Aqua Ring");
static const u8 sText_LaserFocus[] = _("Laser Focus");
static const u8 sText_PowerTrick[] = _("Power Trick");
static const u8 sText_SkyDropped[] = _("Sky Dropped");
static const u8 sText_Electrified[] = _("Electrified");
static const u8 sText_MudSport[] = _("Mud Sport");
static const u8 sText_WaterSport[] = _("Water Sport");
static const u8 sText_InfiniteConfusion[] = _("Infinite Confusion");
static const u8 sText_SaltCure[] = _("Salt Cure");
static const u8 sText_SyrupBomb[] = _("Syrup Bomb");
static const u8 sText_GlaiveRush[] = _("Glaive Rush");
static const u8 sText_Reflect[] = _("Reflect");
static const u8 sText_LightScreen[] = _("Light Screen");
static const u8 sText_StickyWeb[] = _("Sticky Web");
static const u8 sText_Spikes[] = _("Spikes");
static const u8 sText_Safeguard[] = _("Safeguard");
static const u8 sText_FutureAttack[] = _("Future Attack");
static const u8 sText_Mist[] = _("Mist");
static const u8 sText_Tailwind[] = _("Tailwind");
static const u8 sText_AuroraVeil[] = _("Aurora Veil");
static const u8 sText_LuckyChant[] = _("Lucky Chant");
static const u8 sText_ToxicSpikes[] = _("Toxic Spikes");
static const u8 sText_StealthRock[] = _("Stealth Rock");
static const u8 sText_Steelsurge[] = _("Steelsurge");
static const u8 sText_DamageNonTypes[] = _("Damage Non-Types");
static const u8 sText_Rainbow[] = _("Rainbow");
static const u8 sText_SeaOfFire[] = _("Sea of Fire");
static const u8 sText_Swamp[] = _("Swamp");
static const u8 sText_CheckBadMove[] = _("Check Bad Move");
static const u8 sText_TryToFaint[] = _("Try to Faint");
static const u8 sText_CheckViability[] = _("Check Viability");
static const u8 sText_SetUpFirstTurn[] = _("Setup First Turn");
static const u8 sText_Risky[] = _("Risky");
static const u8 sText_TryTo2HKO[] = _("Try to 2HKO");
static const u8 sText_PreferBatonPass[] = _("Prefer Baton Pass");
static const u8 sText_DoubleBattle[] = _("Double Battle");
static const u8 sText_HpAware[] = _("HP Aware");
static const u8 sText_PowerfulStatus[] = _("Powerful Status");
static const u8 sText_NegateUnaware[] = _("Negate Unaware");
static const u8 sText_WillSuicide[] = _("Will Suicide");
static const u8 sText_HelpPartner[] = _("Help Partner");
static const u8 sText_PreferStatusMoves[] = _("Prefer Status Moves");
static const u8 sText_Stall[] = _("Stall");
static const u8 sText_SmartSwitching[] = _("Smart Switching");
static const u8 sText_AcePokemon[] = _("Ace Pokemon");
static const u8 sText_Omniscient[] = _("Omniscient");
static const u8 sText_SmartMonChoices[] = _("Smart Mon Choices");
static const u8 sText_Roaming[] = _("Roaming");
static const u8 sText_Safari[] = _("Safari");
static const u8 sText_FirstBattle[] = _("First Battle");
static const u8 sText_ShowHP[] = _("Show HP");
static const u8 sText_SubstituteHp[] = _("Substitute HP");
static const u8 sText_InLove[] = _("In Love");
static const u8 sText_Unknown[] = _("Unknown");
static const u8 sText_EmptyString[] = _("");
static const struct BitfieldInfo sStatus1Bitfield[] =
{
{/*Sleep*/ 3, 0},
{/*Poison*/ 1, 3},
{/*Burn*/ 1, 4},
{/*Freeze*/ 1, 5},
{/*Paralysis*/1, 6},
{/*Toxic Poison*/ 1, 7},
{/*Toxic Counter*/ 4, 8},
{/*Frostbite*/ 1, 12},
};
static const struct BitfieldInfo sStatus2Bitfield[] =
{
{/*Confusion*/ 3, 0},
{/*Flinched*/ 1, 3},
{/*Torment*/ 1, 7},
{/*Powder*/ 1, 14},
{/*Defense Curl*/ 1, 20},
{/*Recharge*/ 1, 22},
{/*Rage*/ 1, 23},
{/*Destiny Bond*/ 1, 25},
{/*Escape Prevention*/ 1, 26},
{/*Cursed*/ 1, 28},
{/*Foresight*/ 1, 29},
{/*Dragon Cheer*/ 1, 30},
{/*Focus Energy*/ 1, 31},
};
static const struct BitfieldInfo sStatus3Bitfield[] =
{
{/*Leech Seed Battler*/ 2, 0},
{/*Leech Seed*/ 1, 2},
{/*Always Hits*/ 2, 3},
{/*Perish Song*/ 1, 5},
{/*On Air*/ 1, 6},
{/*Underground*/ 1, 7},
{/*Minimized*/ 1, 8},
{/*Charged Up*/ 1, 9},
{/*Rooted*/ 1, 10},
{/*Yawn*/ 2, 11},
{/*Imprisoned Others*/ 1, 13},
{/*Grudge*/ 1, 14},
{/*Gastro Acid*/ 1, 16},
{/*Embargo*/ 1, 17},
{/*Underwater*/ 1, 18},
{/*Smacked Down*/ 1, 21},
{/*Telekinesis*/ 1, 23},
{/*Miracle Eyed*/ 1, 25},
{/*Magnet Rise*/ 1, 26},
{/*Heal Blocked*/ 1, 27},
{/*Aqua Ring*/ 1, 28},
{/*Laser Focus*/ 1, 29},
{/*Power Trick*/ 1, 30},
};
static const struct BitfieldInfo sStatus4Bitfield[] =
{
{/*Electrified*/ 1, 0},
{/*Mud Sport*/ 1, 1},
{/*Water Sport*/ 1, 2},
{/*Salt Cure*/ 1, 4},
{/*Syrup Bomb*/ 1, 5},
{/*Glaive Rush*/ 1, 6},
};
static const struct BitfieldInfo sAIBitfield[] =
{
{/*Check Bad Move*/ 1, 0},
{/*Try to Faint*/ 1, 1},
{/*Check Viability*/ 1, 2},
{/*Setup First Turn*/ 1, 3},
{/*Risky*/ 1, 4},
{/*Prefer Strongest Move*/ 1, 5},
{/*Prefer Baton Pass*/ 1, 6},
{/*Double Battle*/ 1, 7},
{/*HP Aware*/ 1, 8},
{/*Powerful Status*/ 1, 9},
{/*Negate Unaware*/ 1, 10},
{/*Will Suicide*/ 1, 11},
{/*Help Partner*/ 1, 12},
{/*Prefer Status Moves*/ 1, 13},
{/*Stall*/ 1, 14},
{/*Smart Switching*/ 1, 15},
{/*Ace Pokemon*/ 1, 16},
{/*Omniscient*/ 1, 17},
{/*Smart Mon Choices*/ 1, 18},
{/*Ace Pokemon*/ 1, 16},
{/*Omniscient*/ 1, 17},
{/*Smart Mon Choices*/ 1, 18},
{/*Roaming*/ 1, 29},
{/*Safari*/ 1, 30},
{/*First Battle*/ 1, 31},
};
static const struct ListMenuItem sMainListItems[] =
{
{sText_Moves, LIST_ITEM_MOVES},
{sText_Ability, LIST_ITEM_ABILITY},
{sText_HeldItem, LIST_ITEM_HELD_ITEM},
{sText_PP, LIST_ITEM_PP},
{sText_Types, LIST_ITEM_TYPES},
{sText_Stats, LIST_ITEM_STATS},
{sText_StatStages, LIST_ITEM_STAT_STAGES},
{sText_Status1, LIST_ITEM_STATUS1},
{sText_Status2, LIST_ITEM_STATUS2},
{sText_Status3, LIST_ITEM_STATUS3},
{sText_Status4, LIST_ITEM_STATUS4},
{sText_SideStatus, LIST_ITEM_SIDE_STATUS},
{sText_AI, LIST_ITEM_AI},
{sText_AIMovePts, LIST_ITEM_AI_MOVES_PTS},
{sText_AiKnowledge, LIST_ITEM_AI_INFO},
{sText_AiParty, LIST_ITEM_AI_PARTY},
{sText_Various, LIST_ITEM_VARIOUS},
};
static const struct ListMenuItem sStatsListItems[] =
{
{sText_CurrHp, LIST_STAT_HP_CURRENT},
{sText_MaxHp, LIST_STAT_HP_MAX},
{sText_Attack, LIST_STAT_ATTACK},
{sText_Defense, LIST_STAT_DEFENSE},
{sText_Speed, LIST_STAT_SPEED},
{sText_SpAtk, LIST_STAT_SP_ATK},
{sText_SpDef, LIST_STAT_SP_DEF},
};
static const struct ListMenuItem sStatus1ListItems[] =
{
{sText_Sleep, LIST_STATUS1_SLEEP},
{sText_Poison, LIST_STATUS1_POISON},
{sText_Burn, LIST_STATUS1_BURN},
{sText_Freeze, LIST_STATUS1_FREEZE},
{sText_Paralysis, LIST_STATUS1_PARALYSIS},
{sText_ToxicPoison, LIST_STATUS1_TOXIC_POISON},
{sText_ToxicCounter, LIST_STATUS1_TOXIC_COUNTER},
{sText_Frostbite, LIST_STATUS1_FROSTBITE},
};
static const struct ListMenuItem sStatus2ListItems[] =
{
{sText_Confusion, LIST_STATUS2_CONFUSION},
{sText_Flinched, LIST_STATUS2_FLINCHED},
{sText_Torment, LIST_STATUS2_TORMENT},
{sText_Powder, LIST_STATUS2_POWDER},
{sText_DefenseCurl, LIST_STATUS2_DEFENSE_CURL},
{sText_Recharge, LIST_STATUS2_RECHARGE},
{sText_Rage, LIST_STATUS2_RAGE},
{sText_DestinyBond, LIST_STATUS2_DESTINY_BOND},
{sText_EscapePrevention, LIST_STATUS2_ESCAPE_PREVENTION},
{sText_Cursed, LIST_STATUS2_CURSED},
{sText_Foresight, LIST_STATUS2_FORESIGHT},
{sText_DragonCheer, LIST_STATUS2_DRAGON_CHEER},
{sText_FocusEnergy, LIST_STATUS2_FOCUS_ENERGY},
};
static const struct ListMenuItem sStatus3ListItems[] =
{
{sText_LeechSeedHealer, LIST_STATUS3_LEECH_SEED_HEALER},
{sText_LeechSeeded, LIST_STATUS3_LEECH_SEEDED},
{sText_AlwaysHits, LIST_STATUS3_ALWAYS_HITS},
{sText_PerishSong, LIST_STATUS3_PERISH_SONG},
{sText_OnAir, LIST_STATUS3_ON_AIR},
{sText_Underground, LIST_STATUS3_UNDERGROUND},
{sText_Minimized, LIST_STATUS3_MINIMIZED},
{sText_ChargedUp, LIST_STATUS3_CHARGED_UP},
{sText_Rooted, LIST_STATUS3_ROOTED},
{sText_Yawn, LIST_STATUS3_YAWN},
{sText_ImprisonedOthers, LIST_STATUS3_IMPRISONED_OTHERS},
{sText_Grudge, LIST_STATUS3_GRUDGE},
{sText_GastroAcid, LIST_STATUS3_GASTRO_ACID},
{sText_Embargo, LIST_STATUS3_EMBARGO},
{sText_Underwater, LIST_STATUS3_UNDERWATER},
{sText_SmackedDown, LIST_STATUS3_SMACKED_DOWN},
{sText_Telekinesis, LIST_STATUS3_TELEKINESIS},
{sText_MiracleEyed, LIST_STATUS3_MIRACLE_EYED},
{sText_MagnetRise, LIST_STATUS3_MAGNET_RISE},
{sText_HealBlock, LIST_STATUS3_HEAL_BLOCK},
{sText_AquaRing, LIST_STATUS3_AQUA_RING},
{sText_LaserFocus, LIST_STATUS3_LASER_FOCUS},
{sText_PowerTrick, LIST_STATUS3_POWER_TRICK},
};
static const struct ListMenuItem sStatus4ListItems[] =
{
{sText_Electrified, LIST_STATUS4_ELECTRIFIED},
{sText_MudSport, LIST_STATUS4_MUD_SPORT},
{sText_WaterSport, LIST_STATUS4_WATER_SPORT},
{sText_SaltCure, LIST_STATUS4_SALT_CURE},
{sText_SyrupBomb, LIST_STATUS4_SYRUP_BOMB},
{sText_GlaiveRush, LIST_STATUS4_GLAIVE_RUSH},
};
static const struct ListMenuItem sSideStatusListItems[] =
{
{sText_Reflect, LIST_SIDE_REFLECT},
{sText_LightScreen, LIST_SIDE_LIGHTSCREEN},
{sText_StickyWeb, LIST_SIDE_STICKY_WEB},
{sText_Spikes, LIST_SIDE_SPIKES},
{sText_Safeguard, LIST_SIDE_SAFEGUARD},
{sText_Mist, LIST_SIDE_MIST},
{sText_Tailwind, LIST_SIDE_TAILWIND},
{sText_AuroraVeil, LIST_SIDE_AURORA_VEIL},
{sText_LuckyChant, LIST_SIDE_LUCKY_CHANT},
{sText_ToxicSpikes, LIST_SIDE_TOXIC_SPIKES},
{sText_StealthRock, LIST_SIDE_STEALTH_ROCK},
{sText_Steelsurge, LIST_SIDE_STEELSURGE},
{sText_DamageNonTypes, LIST_SIDE_DAMAGE_NON_TYPES},
{sText_Rainbow, LIST_SIDE_RAINBOW},
{sText_SeaOfFire, LIST_SIDE_SEA_OF_FIRE},
{sText_Swamp, LIST_SIDE_SWAMP},
};
static const struct ListMenuItem sAIListItems[] =
{
{sText_CheckBadMove, LIST_AI_CHECK_BAD_MOVE},
{sText_TryToFaint, LIST_AI_TRY_TO_FAINT},
{sText_CheckViability, LIST_AI_CHECK_VIABILITY},
{sText_SetUpFirstTurn, LIST_AI_SETUP_FIRST_TURN},
{sText_Risky, LIST_AI_RISKY},
{sText_TryTo2HKO, LIST_AI_TRY_TO_2HKO},
{sText_PreferBatonPass, LIST_AI_PREFER_BATON_PASS},
{sText_DoubleBattle, LIST_AI_DOUBLE_BATTLE},
{sText_HpAware, LIST_AI_HP_AWARE},
{sText_PowerfulStatus, LIST_AI_POWERFUL_STATUS},
{sText_NegateUnaware, LIST_AI_NEGATE_UNAWARE},
{sText_WillSuicide, LIST_AI_WILL_SUICIDE},
{sText_HelpPartner, LIST_AI_HELP_PARTNER},
{sText_PreferStatusMoves, LIST_AI_PREFER_STATUS_MOVES},
{sText_Stall, LIST_AI_STALL},
{sText_SmartSwitching, LIST_AI_SMART_SWITCHING},
{sText_AcePokemon, LIST_AI_ACE_POKEMON},
{sText_Omniscient, LIST_AI_OMNISCIENT},
{sText_SmartMonChoices, LIST_AI_SMART_MON_CHOICES},
{sText_Roaming, LIST_AI_ROAMING},
{sText_Safari, LIST_AI_SAFARI},
{sText_FirstBattle, LIST_AI_FIRST_BATTLE},
};
static const struct ListMenuItem sVariousListItems[] =
{
{sText_ShowHP, VARIOUS_SHOW_HP},
{sText_SubstituteHp, VARIOUS_SUBSTITUTE_HP},
{sText_InLove, VARIOUS_IN_LOVE},
};
static const struct ListMenuItem sSecondaryListItems[] =
{
{sText_EmptyString, 0},
{sText_EmptyString, 1},
{sText_EmptyString, 2},
{sText_EmptyString, 3},
{sText_EmptyString, 4},
{sText_EmptyString, 5},
{sText_EmptyString, 6},
{sText_EmptyString, 7},
{sText_EmptyString, 8},
};
static const struct ListMenuTemplate sMainListTemplate =
{
.items = sMainListItems,
.moveCursorFunc = NULL,
.itemPrintFunc = NULL,
.totalItems = ARRAY_COUNT(sMainListItems),
.maxShowed = 6,
.windowId = 0,
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
.upText_Y = 1,
.cursorPal = 2,
.fillValue = 1,
.cursorShadowPal = 3,
.lettersSpacing = 1,
.itemVerticalPadding = 0,
.scrollMultiple = LIST_NO_MULTIPLE_SCROLL,
.fontId = 1,
.cursorKind = 0
};
static const struct ListMenuTemplate sSecondaryListTemplate =
{
.items = sSecondaryListItems,
.moveCursorFunc = NULL,
.itemPrintFunc = NULL,
.totalItems = 0,
.maxShowed = 0,
.windowId = 0,
.header_X = 0,
.item_X = 8,
.cursor_X = 0,
.upText_Y = 1,
.cursorPal = 2,
.fillValue = 1,
.cursorShadowPal = 3,
.lettersSpacing = 1,
.itemVerticalPadding = 0,
.scrollMultiple = LIST_NO_MULTIPLE_SCROLL,
.fontId = 1,
.cursorKind = 0
};
static const struct WindowTemplate sMainListWindowTemplate =
{
.bg = 0,
.tilemapLeft = 1,
.tilemapTop = 3,
.width = 9,
.height = 12,
.paletteNum = 0xF,
.baseBlock = 0x1
};
static const struct WindowTemplate sSecondaryListWindowTemplate =
{
.bg = 0,
.tilemapLeft = 12,
.tilemapTop = 3,
.width = 20,
.height = 16,
.paletteNum = 0xF,
.baseBlock = 0x6D
};
static const struct WindowTemplate sModifyWindowTemplate =
{
.bg = 0,
.tilemapLeft = 25,
.tilemapTop = 2,
.width = 4,
.height = 2,
.paletteNum = 0xF,
.baseBlock = 0x1AD
};
static const struct WindowTemplate sBattlerWindowTemplate =
{
.bg = 0,
.tilemapLeft = 10,
.tilemapTop = 0,
.width = 14,
.height = 2,
.paletteNum = 0xF,
.baseBlock = 0x1B5
};
static const struct BgTemplate sBgTemplates[] =
{
{
.bg = 0,
.charBaseIndex = 0,
.mapBaseIndex = 31,
.screenSize = 0,
.paletteMode = 0,
.priority = 1,
.baseTile = 0
},
{
.bg = 1,
.charBaseIndex = 2,
.mapBaseIndex = 20,
.screenSize = 0,
.paletteMode = 0,
.priority = 0,
.baseTile = 0
}
};
static const u8 sBitsToMaxDigit[] =
{
[0] = 0,
[1] = 1, // max 1
[2] = 1, // max 3
[3] = 1, // max 7
[4] = 2, // max 15
[5] = 2, // max 31
[6] = 2, // max 63
[7] = 3, // max 127
[8] = 3, // max 255
};
static const bool8 sHasChangeableEntries[LIST_ITEM_COUNT] =
{
[LIST_ITEM_MOVES] = TRUE,
[LIST_ITEM_AI_MOVES_PTS] = TRUE,
[LIST_ITEM_PP] = TRUE,
[LIST_ITEM_ABILITY] = TRUE,
[LIST_ITEM_TYPES] = TRUE,
[LIST_ITEM_HELD_ITEM] = TRUE,
[LIST_ITEM_STAT_STAGES] = TRUE,
};
static const u16 sBgColor[] = {RGB_WHITE};
// this file's functions
static void Task_DebugMenuFadeOut(u8 taskId);
static void Task_DebugMenuProcessInput(u8 taskId);
static void Task_DebugMenuFadeIn(u8 taskId);
static void PrintOnBattlerWindow(u8 windowId, u8 battlerId);
static void UpdateWindowsOnChangedBattler(struct BattleDebugMenu *data);
static void CreateSecondaryListMenu(struct BattleDebugMenu *data);
static void PrintSecondaryEntries(struct BattleDebugMenu *data);
static void DestroyModifyArrows(struct BattleDebugMenu *data);
static void PrintDigitChars(struct BattleDebugMenu *data);
static void SetUpModifyArrows(struct BattleDebugMenu *data);
static void UpdateBattlerValue(struct BattleDebugMenu *data);
static void UpdateMonData(struct BattleDebugMenu *data);
static u16 *GetSideStatusValue(struct BattleDebugMenu *data, bool32 changeStatus, bool32 statusTrue);
static bool32 TryMoveDigit(struct BattleDebugModifyArrows *modArrows, bool32 moveUp);
static void SwitchToDebugView(u8 taskId);
static void SwitchToDebugViewFromAiParty(u8 taskId);
// code
static struct BattleDebugMenu *GetStructPtr(u8 taskId)
{
u8 *taskDataPtr = (u8 *)(&gTasks[taskId].data[0]);
return (struct BattleDebugMenu*)(T1_READ_PTR(taskDataPtr));
}
static void SetStructPtr(u8 taskId, void *ptr)
{
u32 structPtr = (u32)(ptr);
u8 *taskDataPtr = (u8 *)(&gTasks[taskId].data[0]);
taskDataPtr[0] = structPtr >> 0;
taskDataPtr[1] = structPtr >> 8;
taskDataPtr[2] = structPtr >> 16;
taskDataPtr[3] = structPtr >> 24;
}
static void MainCB2(void)
{
RunTasks();
AnimateSprites();
BuildOamBuffer();
UpdatePaletteFade();
}
static void VBlankCB(void)
{
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
}
void CB2_BattleDebugMenu(void)
{
u8 taskId;
struct BattleDebugMenu *data;
switch (gMain.state)
{
default:
case 0:
SetVBlankCallback(NULL);
gMain.state++;
break;
case 1:
ResetVramOamAndBgCntRegs();
SetGpuReg(REG_OFFSET_DISPCNT, 0);
ResetBgsAndClearDma3BusyFlags(0);
InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates));
ResetAllBgsCoordinates();
FreeAllWindowBuffers();
DeactivateAllTextPrinters();
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
ShowBg(0);
ShowBg(1);
gMain.state++;
break;
case 2:
ResetPaletteFade();
ScanlineEffect_Stop();
ResetTasks();
ResetSpriteData();
gMain.state++;
break;
case 3:
LoadPalette(sBgColor, 0, 2);
LoadPalette(GetOverworldTextboxPalettePtr(), 0xf0, 16);
gMain.state++;
break;
case 4:
taskId = CreateTask(Task_DebugMenuFadeIn, 0);
data = AllocZeroed(sizeof(struct BattleDebugMenu));
SetStructPtr(taskId, data);
data->battlerId = gBattleStruct->debugBattler;
data->battlerWindowId = AddWindow(&sBattlerWindowTemplate);
PutWindowTilemap(data->battlerWindowId);
PrintOnBattlerWindow(data->battlerWindowId, data->battlerId);
data->mainListWindowId = AddWindow(&sMainListWindowTemplate);
gMultiuseListMenuTemplate = sMainListTemplate;
gMultiuseListMenuTemplate.windowId = data->mainListWindowId;
data->mainListTaskId = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0);
data->currentMainListItemId = 0;
data->activeWindow = ACTIVE_WIN_MAIN;
data->secondaryListTaskId = 0xFF;
CopyWindowToVram(data->mainListWindowId, COPYWIN_FULL);
gMain.state++;
break;
case 5:
BeginNormalPaletteFade(-1, 0, 0x10, 0, 0);
SetVBlankCallback(VBlankCB);
SetMainCallback2(MainCB2);
return;
}
}
static void PutMovesPointsText(struct BattleDebugMenu *data)
{
u32 i, j, count, battlerDef;
u8 *text = Alloc(0x50);
FillWindowPixelBuffer(data->aiMovesWindowId, 0x11);
for (i = 0; i < MAX_MON_MOVES; i++)
{
text[0] = CHAR_SPACE;
StringCopy(text + 1, GetMoveName(gBattleMons[data->aiBattlerId].moves[i]));
AddTextPrinterParameterized(data->aiMovesWindowId, FONT_NORMAL, text, 0, i * 15, 0, NULL);
for (count = 0, j = 0; j < MAX_BATTLERS_COUNT; j++)
{
if (data->spriteIds.aiIconSpriteIds[j] == 0xFF)
continue;
battlerDef = gSprites[data->spriteIds.aiIconSpriteIds[j]].data[0];
ConvertIntToDecimalStringN(text,
gBattleStruct->aiFinalScore[data->aiBattlerId][battlerDef][i],
STR_CONV_MODE_RIGHT_ALIGN, 3);
AddTextPrinterParameterized(data->aiMovesWindowId, FONT_NORMAL, text, 83 + count * 54, i * 15, 0, NULL);
ConvertIntToDecimalStringN(text,
AI_DATA->simulatedDmg[data->aiBattlerId][battlerDef][i].expected,
STR_CONV_MODE_RIGHT_ALIGN, 3);
AddTextPrinterParameterized(data->aiMovesWindowId, FONT_NORMAL, text, 110 + count * 54, i * 15, 0, NULL);
count++;
}
}
CopyWindowToVram(data->aiMovesWindowId, COPYWIN_FULL);
Free(text);
}
static void CleanUpAiInfoWindow(u8 taskId)
{
u32 i;
struct BattleDebugMenu *data = GetStructPtr(taskId);
FreeMonIconPalettes();
for (i = 0; i < MAX_BATTLERS_COUNT; i++)
{
if (data->spriteIds.aiIconSpriteIds[i] != 0xFF)
FreeAndDestroyMonIconSprite(&gSprites[data->spriteIds.aiIconSpriteIds[i]]);
}
FreeAndDestroyMonPicSprite(data->aiMonSpriteId);
ClearWindowTilemap(data->aiMovesWindowId);
RemoveWindow(data->aiMovesWindowId);
}
static void Task_ShowAiPoints(u8 taskId)
{
u32 i, count;
struct WindowTemplate winTemplate;
struct BattleDebugMenu *data = GetStructPtr(taskId);
struct Pokemon *mon;
switch (data->aiViewState)
{
case 0:
HideBg(0);
ShowBg(1);
// Swap battler if it's player mon
data->aiBattlerId = data->battlerId;
while (!BattlerHasAi(data->aiBattlerId))
{
if (++data->aiBattlerId >= gBattlersCount)
data->aiBattlerId = 0;
}
data->battlerId = data->aiBattlerId;
LoadMonIconPalettes();
for (count = 0, i = 0; i < MAX_BATTLERS_COUNT; i++)