forked from pret/pokeemerald
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpokemon_storage_system.c
10059 lines (9072 loc) · 281 KB
/
pokemon_storage_system.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 "malloc.h"
#include "bg.h"
#include "data.h"
#include "decompress.h"
#include "dma3.h"
#include "dynamic_placeholder_text_util.h"
#include "event_data.h"
#include "field_screen_effect.h"
#include "field_weather.h"
#include "fldeff_misc.h"
#include "gpu_regs.h"
#include "graphics.h"
#include "international_string_util.h"
#include "item.h"
#include "item_icon.h"
#include "item_menu.h"
#include "mail.h"
#include "main.h"
#include "menu.h"
#include "mon_markings.h"
#include "naming_screen.h"
#include "overworld.h"
#include "palette.h"
#include "pc_screen_effect.h"
#include "pokemon.h"
#include "pokemon_icon.h"
#include "pokemon_summary_screen.h"
#include "pokemon_storage_system.h"
#include "script.h"
#include "sound.h"
#include "string_util.h"
#include "strings.h"
#include "text.h"
#include "text_window.h"
#include "trig.h"
#include "walda_phrase.h"
#include "window.h"
#include "constants/items.h"
#include "constants/moves.h"
#include "constants/rgb.h"
#include "constants/songs.h"
#include "constants/pokemon_icon.h"
/*
NOTE: This file is large. Some general groups of functions have
been labeled with commented headers to make navigation easier.
Search for "SECTION:" to locate them. These sections are not
hard and fast rules, but give a basic idea of where certain
types of functions are likely located.
*/
// PC main menu options
enum {
OPTION_WITHDRAW,
OPTION_DEPOSIT,
OPTION_MOVE_MONS,
OPTION_MOVE_ITEMS,
OPTION_EXIT,
OPTIONS_COUNT
};
// IDs for messages to print with PrintMessage
enum {
MSG_EXIT_BOX,
MSG_WHAT_YOU_DO,
MSG_PICK_A_THEME,
MSG_PICK_A_WALLPAPER,
MSG_IS_SELECTED,
MSG_JUMP_TO_WHICH_BOX,
MSG_DEPOSIT_IN_WHICH_BOX,
MSG_WAS_DEPOSITED,
MSG_BOX_IS_FULL,
MSG_RELEASE_POKE,
MSG_WAS_RELEASED,
MSG_BYE_BYE,
MSG_MARK_POKE,
MSG_LAST_POKE,
MSG_PARTY_FULL,
MSG_HOLDING_POKE,
MSG_WHICH_ONE_WILL_TAKE,
MSG_CANT_RELEASE_EGG,
MSG_CONTINUE_BOX,
MSG_CAME_BACK,
MSG_WORRIED,
MSG_SURPRISE,
MSG_PLEASE_REMOVE_MAIL,
MSG_IS_SELECTED2,
MSG_GIVE_TO_MON,
MSG_PLACED_IN_BAG,
MSG_BAG_FULL,
MSG_PUT_IN_BAG,
MSG_ITEM_IS_HELD,
MSG_CHANGED_TO_ITEM,
MSG_CANT_STORE_MAIL,
};
// IDs for how to resolve variables in the above messages
enum {
MSG_VAR_NONE,
MSG_VAR_MON_NAME_1,
MSG_VAR_MON_NAME_2, // Unused
MSG_VAR_MON_NAME_3, // Unused
MSG_VAR_RELEASE_MON_1,
MSG_VAR_RELEASE_MON_2, // Unused
MSG_VAR_RELEASE_MON_3,
MSG_VAR_ITEM_NAME,
};
// IDs for menu selection items. See SetMenuText, HandleMenuInput, etc
enum {
MENU_CANCEL,
MENU_STORE,
MENU_WITHDRAW,
MENU_MOVE,
MENU_SHIFT,
MENU_PLACE,
MENU_SUMMARY,
MENU_RELEASE,
MENU_MARK,
MENU_JUMP,
MENU_WALLPAPER,
MENU_NAME,
MENU_TAKE,
MENU_GIVE,
MENU_GIVE_2,
MENU_SWITCH,
MENU_BAG,
MENU_INFO,
MENU_SCENERY_1,
MENU_SCENERY_2,
MENU_SCENERY_3,
MENU_ETCETERA,
MENU_FRIENDS,
MENU_FOREST,
MENU_CITY,
MENU_DESERT,
MENU_SAVANNA,
MENU_CRAG,
MENU_VOLCANO,
MENU_SNOW,
MENU_CAVE,
MENU_BEACH,
MENU_SEAFLOOR,
MENU_RIVER,
MENU_SKY,
MENU_POLKADOT,
MENU_POKECENTER,
MENU_MACHINE,
MENU_SIMPLE,
};
#define MENU_WALLPAPER_SETS_START MENU_SCENERY_1
#define MENU_WALLPAPERS_START MENU_FOREST
// Return IDs for input handlers
enum {
INPUT_NONE,
INPUT_MOVE_CURSOR,
INPUT_2, // Unused
INPUT_3, // Unused
INPUT_CLOSE_BOX,
INPUT_SHOW_PARTY,
INPUT_HIDE_PARTY,
INPUT_BOX_OPTIONS,
INPUT_IN_MENU,
INPUT_SCROLL_RIGHT,
INPUT_SCROLL_LEFT,
INPUT_DEPOSIT,
INPUT_WITHDRAW,
INPUT_MOVE_MON,
INPUT_SHIFT_MON,
INPUT_PLACE_MON,
INPUT_TAKE_ITEM,
INPUT_GIVE_ITEM,
INPUT_SWITCH_ITEMS,
INPUT_PRESSED_B,
INPUT_MULTIMOVE_START,
INPUT_MULTIMOVE_CHANGE_SELECTION,
INPUT_MULTIMOVE_SINGLE,
INPUT_MULTIMOVE_GRAB_SELECTION,
INPUT_MULTIMOVE_UNABLE,
INPUT_MULTIMOVE_MOVE_MONS,
INPUT_MULTIMOVE_PLACE_MONS,
};
enum {
SCREEN_CHANGE_EXIT_BOX,
SCREEN_CHANGE_SUMMARY_SCREEN,
SCREEN_CHANGE_NAME_BOX,
SCREEN_CHANGE_ITEM_FROM_BAG,
};
enum {
MODE_PARTY,
MODE_BOX,
MODE_MOVE,
};
enum {
CURSOR_AREA_IN_BOX,
CURSOR_AREA_IN_PARTY,
CURSOR_AREA_BOX_TITLE,
CURSOR_AREA_BUTTONS, // Party Pokémon and Close Box
};
#define CURSOR_AREA_IN_HAND CURSOR_AREA_BOX_TITLE // Alt name for cursor area used by Move Items
enum {
CURSOR_ANIM_BOUNCE,
CURSOR_ANIM_STILL,
CURSOR_ANIM_OPEN,
CURSOR_ANIM_FIST,
};
// Special box ids for the choose box menu
#define BOXID_NONE_CHOSEN 200
#define BOXID_CANCELED 201
enum {
PALTAG_MON_ICON_0 = POKE_ICON_BASE_PAL_TAG,
PALTAG_MON_ICON_1, // Used implicitly in CreateMonIconSprite
PALTAG_MON_ICON_2, // Used implicitly in CreateMonIconSprite
PALTAG_3, // Unused
PALTAG_4, // Unused
PALTAG_5, // Unused
PALTAG_DISPLAY_MON,
PALTAG_MISC_1,
PALTAG_MARKING_COMBO,
PALTAG_BOX_TITLE,
PALTAG_MISC_2,
PALTAG_ITEM_ICON_0,
PALTAG_ITEM_ICON_1, // Used implicitly in CreateItemIconSprites
PALTAG_ITEM_ICON_2, // Used implicitly in CreateItemIconSprites
PALTAG_MARKING_MENU,
};
enum {
GFXTAG_CURSOR,
GFXTAG_CURSOR_SHADOW,
GFXTAG_DISPLAY_MON,
GFXTAG_BOX_TITLE,
GFXTAG_BOX_TITLE_ALT,
GFXTAG_WAVEFORM,
GFXTAG_ARROW,
GFXTAG_ITEM_ICON_0,
GFXTAG_ITEM_ICON_1, // Used implicitly in CreateItemIconSprites
GFXTAG_ITEM_ICON_2, // Used implicitly in CreateItemIconSprites
GFXTAG_CHOOSE_BOX_MENU,
GFXTAG_CHOOSE_BOX_MENU_SIDES, // Used implicitly in LoadChooseBoxMenuGfx
GFXTAG_12, // Unused
GFXTAG_MARKING_MENU,
GFXTAG_14, // Unused
GFXTAG_15, // Unused
GFXTAG_MARKING_COMBO,
GFXTAG_17, // Unused
GFXTAG_MON_ICON,
};
// The maximum number of Pokémon icons that can appear on-screen.
// By default the limit is 40 (though in practice only 37 can be).
#define MAX_MON_ICONS max(IN_BOX_COUNT + PARTY_SIZE + 1, 40)
// The maximum number of item icons that can appear on-screen while
// moving held items. 1 in the cursor, and 2 more while switching
// between 2 Pokémon with held items
#define MAX_ITEM_ICONS 3
// IDs for the item icons affine anims
enum {
ITEM_ANIM_NONE,
ITEM_ANIM_APPEAR,
ITEM_ANIM_DISAPPEAR,
ITEM_ANIM_PICK_UP,
ITEM_ANIM_PUT_DOWN,
ITEM_ANIM_PUT_AWAY,
ITEM_ANIM_LARGE,
};
// IDs for the item icon sprite callbacks
enum {
ITEM_CB_WAIT_ANIM,
ITEM_CB_TO_HAND,
ITEM_CB_TO_MON,
ITEM_CB_SWAP_TO_HAND,
ITEM_CB_SWAP_TO_MON,
ITEM_CB_UNUSED_1,
ITEM_CB_UNUSED_2,
ITEM_CB_HIDE_PARTY,
};
enum {
RELEASE_ANIM_RELEASE,
RELEASE_ANIM_CAME_BACK,
};
// IDs for InitMonPlaceChange
enum {
CHANGE_GRAB,
CHANGE_PLACE,
CHANGE_SHIFT,
};
// Modes for selecting and moving Pokémon in the box.
// "MULTIPLE" mode allows up to an entire box to be
// picked up at once by pressing Select then holding
// down the A button. While holding A down, the player
// may move the cursor around to select multiple Pokémon.
// This is MOVE_MODE_MULTIPLE_SELECTING. After releasing A
// those Pokémon will be picked up and can be moved around
// as a single unit. This is MOVE_MODE_MULTIPLE_MOVING
enum {
MOVE_MODE_NORMAL,
MOVE_MODE_MULTIPLE_SELECTING,
MOVE_MODE_MULTIPLE_MOVING,
};
// IDs for the main functions for moving multiple Pokémon.
// Given as arguments to MultiMove_SetFunction
enum {
MULTIMOVE_START,
MULTIMOVE_CANCEL, // If only 1 Pokémon is grabbed
MULTIMOVE_CHANGE_SELECTION,
MULTIMOVE_GRAB_SELECTION,
MULTIMOVE_MOVE_MONS,
MULTIMOVE_PLACE_MONS,
};
// IDs for TilemapUtil
enum {
TILEMAPID_PKMN_DATA, // The "Pkmn Data" text at the top of the display
TILEMAPID_PARTY_MENU,
TILEMAPID_CLOSE_BUTTON,
TILEMAPID_COUNT
};
// Window IDs for sWindowTemplates
enum {
WIN_DISPLAY_INFO,
WIN_MESSAGE,
WIN_ITEM_DESC,
};
struct Wallpaper
{
const u32 *tiles;
const u32 *tilemap;
const u16 *palettes;
};
struct StorageMessage
{
const u8 *text;
u8 format;
};
struct StorageMenu
{
const u8 *text;
int textId;
};
struct UnkUtilData
{
const u8 *src;
u8 *dest;
u16 size;
u16 unk;
u16 height;
void (*func)(struct UnkUtilData *data);
};
struct UnkUtil
{
struct UnkUtilData *data;
u8 numActive;
u8 max;
};
struct ChooseBoxMenu
{
struct Sprite *menuSprite;
struct Sprite *menuSideSprites[4];
u32 unused1[3];
struct Sprite *arrowSprites[2];
u8 unused2[0x214];
bool32 loadedPalette;
u16 tileTag;
u16 paletteTag;
u8 curBox;
u8 unused3;
u8 subpriority;
};
struct ItemIcon
{
struct Sprite *sprite;
u8 *tiles;
u16 palIndex;
u8 area;
u8 pos;
bool8 active;
};
struct PokemonStorageSystemData
{
u8 state;
u8 boxOption;
u8 screenChangeType;
bool8 isReopening;
u8 taskId;
struct UnkUtil unkUtil;
struct UnkUtilData unkUtilData[8];
u16 partyMenuTilemapBuffer[0x108];
u16 partyMenuUnused1; // Never read
u16 partyMenuY;
u8 partyMenuUnused2; // Unused
u8 partyMenuMoveTimer;
u8 showPartyMenuState;
bool8 closeBoxFlashing;
u8 closeBoxFlashTimer;
bool8 closeBoxFlashState;
s16 newCurrBoxId;
u16 bg2_X;
s16 scrollSpeed;
u16 scrollTimer;
u8 wallpaperOffset;
u8 scrollUnused1; // Never read
u8 scrollToBoxIdUnused; // Never read
u16 scrollUnused2; // Never read
s16 scrollDirectionUnused; // Never read.
u16 scrollUnused3; // Never read
u16 scrollUnused4; // Never read
u16 scrollUnused5; // Never read
u16 scrollUnused6; // Never read
u8 filler1[22];
u8 boxTitleTiles[1024];
u8 boxTitleCycleId;
u8 wallpaperLoadState; // Written to, but never read.
u8 wallpaperLoadBoxId;
s8 wallpaperLoadDir;
u16 boxTitlePal[16];
u16 boxTitlePalOffset;
u16 boxTitleAltPalOffset;
struct Sprite *curBoxTitleSprites[2];
struct Sprite *nextBoxTitleSprites[2];
struct Sprite *arrowSprites[2];
u32 wallpaperPalBits;
u8 filler2[80]; // Unused
u16 unkUnused1; // Never read.
s16 wallpaperSetId;
s16 wallpaperId;
u16 wallpaperTilemap[360];
u8 wallpaperChangeState;
u8 scrollState;
u8 scrollToBoxId;
s8 scrollDirection;
u8 *wallpaperTiles;
struct Sprite *movingMonSprite;
struct Sprite *partySprites[PARTY_SIZE];
struct Sprite *boxMonsSprites[IN_BOX_COUNT];
struct Sprite **shiftMonSpritePtr;
struct Sprite **releaseMonSpritePtr;
u16 numIconsPerSpecies[MAX_MON_ICONS];
u16 iconSpeciesList[MAX_MON_ICONS];
u16 boxSpecies[IN_BOX_COUNT];
u32 boxPersonalities[IN_BOX_COUNT];
u8 incomingBoxId;
u8 shiftTimer;
u8 numPartyToCompact;
u16 iconScrollDistance;
s16 iconScrollPos;
s16 iconScrollSpeed;
u16 iconScrollNumIncoming;
u8 iconScrollCurColumn;
s8 iconScrollDirection; // Unnecessary duplicate of scrollDirection
u8 iconScrollState;
u8 iconScrollToBoxId; // Unused duplicate of scrollToBoxId
struct WindowTemplate menuWindow;
struct StorageMenu menuItems[7];
u8 menuItemsCount;
u8 menuWidth;
u8 menuUnusedField; // Never read.
u16 menuWindowId;
struct Sprite *cursorSprite;
struct Sprite *cursorShadowSprite;
s32 cursorNewX;
s32 cursorNewY;
u32 cursorSpeedX;
u32 cursorSpeedY;
s16 cursorTargetX;
s16 cursorTargetY;
u16 cursorMoveSteps;
s8 cursorVerticalWrap;
s8 cursorHorizontalWrap;
u8 newCursorArea;
u8 newCursorPosition;
u8 cursorPrevHorizPos;
u8 cursorFlipTimer;
u8 cursorPalNums[2];
const u32 *displayMonPalette;
u32 displayMonPersonality;
u16 displayMonSpecies;
u16 displayMonItemId;
u16 displayUnusedVar;
bool8 setMosaic;
u8 displayMonMarkings;
u8 displayMonLevel;
bool8 displayMonIsEgg;
u8 displayMonName[POKEMON_NAME_LENGTH + 1];
u8 displayMonNameText[36];
u8 displayMonSpeciesName[36];
u8 displayMonGenderLvlText[36];
u8 displayMonItemName[36];
bool8 (*monPlaceChangeFunc)(void);
u8 monPlaceChangeState;
u8 shiftBoxId;
struct Sprite *markingComboSprite;
struct Sprite *waveformSprites[2];
u16 *markingComboTilesPtr;
struct MonMarkingsMenu markMenu;
struct ChooseBoxMenu chooseBoxMenu;
struct Pokemon movingMon;
struct Pokemon tempMon;
s8 canReleaseMon;
bool8 releaseStatusResolved;
s8 releaseCheckBoxId;
s8 releaseCheckBoxPos;
s8 releaseBoxId;
s8 releaseBoxPos;
u16 releaseCheckState;
u16 restrictedReleaseMonMoves;
u16 restrictedMoveList[8];
u8 summaryMaxPos;
u8 summaryStartPos;
u8 summaryScreenMode;
union
{
struct Pokemon *mon;
struct BoxPokemon *box;
} summaryMon;
u8 messageText[40];
u8 boxTitleText[40];
u8 releaseMonName[POKEMON_NAME_LENGTH + 1];
u8 itemName[20];
u8 inBoxMovingMode;
u16 multiMoveWindowId;
struct ItemIcon itemIcons[MAX_ITEM_ICONS];
u16 movingItemId;
u16 itemInfoWindowOffset;
u8 unkUnused2; // Unused
u16 displayMonPalOffset;
u16 *displayMonTilePtr;
struct Sprite *displayMonSprite;
u16 displayMonPalBuffer[0x40];
u8 ALIGNED(4) tileBuffer[MON_PIC_SIZE * MAX_MON_PIC_FRAMES];
u8 ALIGNED(4) itemIconBuffer[0x800];
u8 wallpaperBgTilemapBuffer[0x1000];
u8 displayMenuTilemapBuffer[0x800];
};
static u32 sItemIconGfxBuffer[98];
EWRAM_DATA static u8 sPreviousBoxOption = 0;
EWRAM_DATA static struct ChooseBoxMenu *sChooseBoxMenu = NULL;
EWRAM_DATA static struct PokemonStorageSystemData *sStorage = NULL;
EWRAM_DATA static bool8 sInPartyMenu = 0;
EWRAM_DATA static u8 sCurrentBoxOption = 0;
EWRAM_DATA static u8 sDepositBoxId = 0;
EWRAM_DATA static u8 sWhichToReshow = 0;
EWRAM_DATA static u8 sLastUsedBox = 0;
EWRAM_DATA static u16 sMovingItemId = 0;
EWRAM_DATA static struct Pokemon sSavedMovingMon = {0};
EWRAM_DATA static s8 sCursorArea = 0;
EWRAM_DATA static s8 sCursorPosition = 0;
EWRAM_DATA static bool8 sIsMonBeingMoved = 0;
EWRAM_DATA static u8 sMovingMonOrigBoxId = 0;
EWRAM_DATA static u8 sMovingMonOrigBoxPos = 0;
EWRAM_DATA static bool8 sAutoActionOn = 0;
// Main tasks
static void EnterPokeStorage(u8);
static void Task_InitPokeStorage(u8);
static void Task_PlaceMon(u8);
static void Task_ChangeScreen(u8);
static void Task_ShowPokeStorage(u8);
static void Task_OnBPressed(u8);
static void Task_HandleBoxOptions(u8);
static void Task_OnSelectedMon(u8);
static void Task_OnCloseBoxPressed(u8);
static void Task_HidePartyPokemon(u8);
static void Task_DepositMenu(u8);
static void Task_MoveMon(u8);
static void Task_GiveMovingItemToMon(u8);
static void Task_SwitchSelectedItem(u8);
static void Task_TakeItemForMoving(u8);
static void Task_WithdrawMon(u8);
static void Task_ShiftMon(u8);
static void Task_ShowPartyPokemon(u8);
static void Task_ShowItemInfo(u8);
static void Task_GiveItemFromBag(u8);
static void Task_ItemToBag(u8);
static void Task_TakeItemForMoving(u8);
static void Task_ShowMarkMenu(u8);
static void Task_ShowMonSummary(u8);
static void Task_ReleaseMon(u8);
static void Task_ReshowPokeStorage(u8);
static void Task_PokeStorageMain(u8);
static void Task_JumpBox(u8);
static void Task_HandleWallpapers(u8);
static void Task_NameBox(u8);
static void Task_PrintCantStoreMail(u8);
static void Task_HandleMovingMonFromParty(u8);
// Input handlers
static u8 InBoxInput_Normal(void);
static u8 InBoxInput_MovingMultiple(void);
static u8 InBoxInput_SelectingMultiple(void);
static u8 HandleInput(void);
static void AddBoxOptionsMenu(void);
static u8 SetSelectionMenuTexts(void);
static bool8 SetMenuTexts_Mon(void);
static bool8 SetMenuTexts_Item(void);
// Choose box menu
static void ChooseBoxMenu_CreateSprites(u8);
static void ChooseBoxMenu_DestroySprites(void);
static void ChooseBoxMenu_MoveLeft(void);
static void ChooseBoxMenu_MoveRight(void);
static void ChooseBoxMenu_PrintInfo(void);
static void SpriteCB_ChooseBoxArrow(struct Sprite *);
// Options menus
static void InitMenu(void);
static void SetMenuText(u8);
static s8 GetMenuItemTextId(u8);
static void AddMenu(void);
static bool8 IsMenuLoading(void);
static s16 HandleMenuInput(void);
static void RemoveMenu(void);
// Pokémon sprites
static void InitMonIconFields(void);
static void SpriteCB_BoxMonIconScrollOut(struct Sprite *);
static void GetIncomingBoxMonData(u8);
static void CreatePartyMonsSprites(bool8);
static void CompactPartySprites(void);
static u8 GetNumPartySpritesCompacting(void);
static void MovePartySpriteToNextSlot(struct Sprite *, u16);
static void SpriteCB_MovePartyMonToNextSlot(struct Sprite *);
static void MovePartySprites(s16);
static void DestroyAllPartyMonIcons(void);
static void ReshowReleaseMon(void);
static bool8 ResetReleaseMonSpritePtr(void);
static void SetMovingMonPriority(u8);
static void SpriteCB_HeldMon(struct Sprite *);
static struct Sprite *CreateMonIconSprite(u16, u32, s16, s16, u8, u8);
static void DestroyBoxMonIcon(struct Sprite *);
// Pokémon data
static void MoveMon(void);
static void PlaceMon(void);
static void RefreshDisplayMon(void);
static void SetMovingMonData(u8, u8);
static void SetPlacedMonData(u8, u8);
static void PurgeMonOrBoxMon(u8, u8);
static void SetShiftedMonData(u8, u8);
static bool8 TryStorePartyMonInBox(u8);
static void ResetSelectionAfterDeposit(void);
static void InitReleaseMon(void);
static bool8 TryHideReleaseMon(void);
static void InitCanReleaseMonVars(void);
static void ReleaseMon(void);
static bool32 AtLeastThreeUsableMons(void);
static s8 RunCanReleaseMon(void);
static void SaveMovingMon(void);
static void LoadSavedMovingMon(void);
static void InitSummaryScreenData(void);
static void SetSelectionAfterSummaryScreen(void);
static void SetMonMarkings(u8);
static bool8 IsRemovingLastPartyMon(void);
static bool8 CanShiftMon(void);
static bool8 IsMonBeingMoved(void);
static void TryRefreshDisplayMon(void);
static void ReshowDisplayMon(void);
static void SetDisplayMonData(void *, u8);
// Moving multiple Pokémon at once
static void MultiMove_Free(void);
static bool8 MultiMove_Init(void);
static bool8 MultiMove_RunFunction(void);
static bool8 MultiMove_TryMoveGroup(u8);
static bool8 MultiMove_CanPlaceSelection(void);
static void MultiMove_SetFunction(u8);
static u8 MultiMove_GetOrigin(void);
static bool8 MultiMove_Start(void);
static bool8 MultiMove_Cancel(void);
static bool8 MultiMove_ChangeSelection(void);
static bool8 MultiMove_GrabSelection(void);
static bool8 MultiMove_MoveMons(void);
static bool8 MultiMove_PlaceMons(void);
static void MultiMove_SetIconToBg(u8, u8);
static void MultiMove_ClearIconFromBg(u8, u8);
static void MultiMove_ResetBg(void);
static void MultiMove_UpdateSelectedIcons(void);
static void MultiMove_InitMove(u16, u16, u16);
static void MultiMove_GetMonsFromSelection(void);
static void MultiMove_RemoveMonsFromBox(void);
static void MultiMove_CreatePlacedMonIcons(void);
static void MultiMove_SetPlacedMonData(void);
static u8 MultiMove_UpdateMove(void);
static void MultiMove_DeselectRow(u8, u8, u8);
static void MultiMove_SelectRow(u8, u8, u8);
static void MultiMove_SelectColumn(u8, u8, u8);
static void MultiMove_DeselectColumn(u8, u8, u8);
// Move Items mode
static bool32 IsItemIconAtPosition(u8, u8);
static const u32 *GetItemIconPic(u16);
static const u32 *GetItemIconPalette(u16);
static u8 GetNewItemIconIdx(void);
static void SetItemIconPosition(u8, u8, u8);
static void LoadItemIconGfx(u8, const u32 *, const u32 *);
static void SetItemIconAffineAnim(u8, u8);
static void SetItemIconActive(u8, bool8);
static u8 GetItemIconIdxByPosition(u8, u8);
static void CreateItemIconSprites(void);
static void TryLoadItemIconAtPos(u8, u8);
static void TryHideItemIconAtPos(u8, u8);
static void TakeItemFromMon(u8, u8);
static void InitItemIconInCursor(u16);
static void SwapItemsWithMon(u8, u8);
static void GiveItemToMon(u8, u8);
static void MoveItemFromMonToBag(u8, u8);
static void MoveItemFromCursorToBag(void);
static void MoveHeldItemWithPartyMenu(void);
static bool8 IsItemIconAnimActive(void);
static bool8 IsMovingItem(void);
static const u8 *GetMovingItemName(void);
static u16 GetMovingItemId(void);
static void PrintItemDescription(void);
static void InitItemInfoWindow(void);
static bool8 UpdateItemInfoWindowSlideIn(void);
static bool8 UpdateItemInfoWindowSlideOut(void);
static void DrawItemInfoWindow(u32);
static void SetItemIconCallback(u8, u8, u8, u8);
static void SpriteCB_ItemIcon_SetPosToCursor(struct Sprite *);
static void SpriteCB_ItemIcon_WaitAnim(struct Sprite *);
static void SpriteCB_ItemIcon_ToHand(struct Sprite *);
static void SpriteCB_ItemIcon_ToMon(struct Sprite *);
static void SpriteCB_ItemIcon_SwapToHand(struct Sprite *);
static void SpriteCB_ItemIcon_HideParty(struct Sprite *);
static void SpriteCB_ItemIcon_SwapToMon(struct Sprite *);
// Cursor
static void CreateCursorSprites(void);
static void ToggleCursorAutoAction(void);
static u8 GetCursorPosition(void);
static void StartCursorAnim(u8);
static void TryHideItemAtCursor(void);
static void TryShowItemAtCursor(void);
static void InitCursor(void);
static void InitCursorOnReopen(void);
static void GetCursorCoordsByPos(u8, u8, u16 *, u16 *);
static bool8 UpdateCursorPos(void);
static void DoCursorNewPosUpdate(void);
static void SetCursorInParty(void);
static void SetCursorBoxPosition(u8);
static void ClearSavedCursorPos(void);
static void SaveCursorPos(void);
static u8 GetSavedCursorPos(void);
static void InitMonPlaceChange(u8);
static bool8 DoMonPlaceChange(void);
static bool8 MonPlaceChange_Shift(void);
static bool8 MonPlaceChange_Grab(void);
static bool8 MonPlaceChange_Place(void);
static bool8 MultiMonPlaceChange_Up(void);
static bool8 MultiMonPlaceChange_Down(void);
static bool8 MonPlaceChange_CursorDown(void);
static bool8 MonPlaceChange_CursorUp(void);
static void TrySetCursorFistAnim(void);
static bool8 IsCursorOnCloseBox(void);
static bool8 IsCursorOnBoxTitle(void);
static bool8 IsCursorInBox(void);
// Scroll arrows
static void CreateBoxScrollArrows(void);
static void StartBoxScrollArrowsSlide(s8);
static void StopBoxScrollArrowsSlide(void);
static void AnimateBoxScrollArrows(bool8);
static void SpriteCB_Arrow(struct Sprite *);
static struct Sprite *CreateChooseBoxArrows(u16, u16, u8, u8, u8);
// Box title
static void InitBoxTitle(u8);
static void CreateIncomingBoxTitle(u8, s8);
static void CycleBoxTitleSprites(void);
static void SpriteCB_IncomingBoxTitle(struct Sprite *);
static void SpriteCB_OutgoingBoxTitle(struct Sprite *);
static void CycleBoxTitleColor(void);
static s16 GetBoxTitleBaseX(const u8 *);
// Wallpaper
static void SetWallpaperForCurrentBox(u8);
static bool8 DoWallpaperGfxChange(void);
static void LoadWallpaperGfx(u8, s8);
static bool32 WaitForWallpaperGfxLoad(void);
static void DrawWallpaper(const void *, s8, u8);
static void TrimOldWallpaper(void *);
static void AddWallpaperSetsMenu(void);
static void AddWallpapersMenu(u8);
static u8 GetBoxWallpaper(u8);
static void SetBoxWallpaper(u8, u8);
// General box
static void CreateInitBoxTask(u8);
static bool8 IsInitBoxActive(void);
static void Task_InitBox(u8);
static void SetUpScrollToBox(u8);
static bool8 ScrollToBox(void);
static s8 DetermineBoxScrollDirection(u8);
static void SetCurrentBox(u8);
// Misc
static void CreateMainMenu(u8, s16 *);
static u8 GetCurrentBoxOption(void);
static void ScrollBackground(void);
static void UpdateCloseBoxButtonFlash(void);
static void GiveChosenBagItem(void);
static void SetUpHidePartyMenu(void);
static void LoadPokeStorageMenuGfx(void);
static void LoadWaveformSpritePalette(void);
static void InitPokeStorageBg0(void);
static void SetScrollingBackground(void);
static void UpdateBoxToSendMons(void);
static void InitCursorItemIcon(void);
static void InitPalettesAndSprites(void);
static void RefreshDisplayMonData(void);
static void CreateDisplayMonSprite(void);
static void CreateMarkingComboSprite(void);
static void CreateWaveformSprites(void);
static void ClearBottomWindow(void);
static void InitSupplementalTilemaps(void);
static void PrintDisplayMonInfo(void);
static void UpdateWaveformAnimation(void);
static void SetPartySlotTilemaps(void);
static void StopFlashingCloseBoxButton(void);
static void FreePokeStorageData(void);
static void UpdatePartySlotColors(void);
static void StartFlashingCloseBoxButton(void);
static void SetUpDoShowPartyMenu(void);
static void StartDisplayMonMosaicEffect(void);
static bool8 InitPokeStorageWindows(void);
static bool8 DoShowPartyMenu(void);
static bool8 HidePartyMenu(void);
static bool8 IsDisplayMosaicActive(void);
static void ShowYesNoWindow(s8);
static void UpdateCloseBoxButtonTilemap(bool8);
static void PrintMessage(u8 id);
static void LoadDisplayMonGfx(u16, u32);
static void SpriteCB_DisplayMonMosaic(struct Sprite *);
static void SetPartySlotTilemap(u8, bool8);
// Tilemap utility
static void TilemapUtil_SetRect(u8, u16, u16, u16, u16);
static void TilemapUtil_Move(u8, u8, s8);
static void TilemapUtil_SetMap(u8, u8, const void *, u16, u16);
static void TilemapUtil_SetPos(u8, u16, u16);
static void TilemapUtil_Init(u8);
static void TilemapUtil_Free(void);
static void TilemapUtil_Update(u8);
static void TilemapUtil_DrawPrev(u8);
static void TilemapUtil_Draw(u8);
// Unknown utility
static void UnkUtil_Init(struct UnkUtil *, struct UnkUtilData *, u32);
static void UnkUtil_Run(void);
static void UnkUtil_CpuRun(struct UnkUtilData *);
static void UnkUtil_DmaRun(struct UnkUtilData *);
struct {
const u8 *text;
const u8 *desc;
} static const sMainMenuTexts[OPTIONS_COUNT] =
{
[OPTION_WITHDRAW] = {gText_WithdrawPokemon, gText_WithdrawMonDescription},
[OPTION_DEPOSIT] = {gText_DepositPokemon, gText_DepositMonDescription},
[OPTION_MOVE_MONS] = {gText_MovePokemon, gText_MoveMonDescription},
[OPTION_MOVE_ITEMS] = {gText_MoveItems, gText_MoveItemsDescription},
[OPTION_EXIT] = {gText_SeeYa, gText_SeeYaDescription}
};
static const struct WindowTemplate sWindowTemplate_MainMenu =
{
.bg = 0,
.tilemapLeft = 1,
.tilemapTop = 1,
.width = 17,
.height = 10,
.paletteNum = 15,
.baseBlock = 0x1,
};
static const union AnimCmd sAnim_ChooseBoxMenu_TopLeft[] =
{
ANIMCMD_FRAME(0, 5),
ANIMCMD_END
};
static const union AnimCmd sAnim_ChooseBoxMenu_BottomLeft[] =
{
ANIMCMD_FRAME(4, 5),
ANIMCMD_END
};
static const union AnimCmd sAnim_ChooseBoxMenu_TopRight[] =
{
ANIMCMD_FRAME(6, 5),
ANIMCMD_END
};
static const union AnimCmd sAnim_ChooseBoxMenu_BottomRight[] =
{
ANIMCMD_FRAME(10, 5),
ANIMCMD_END
};
static const union AnimCmd *const sAnims_ChooseBoxMenu[] =
{
sAnim_ChooseBoxMenu_TopLeft,
sAnim_ChooseBoxMenu_BottomLeft,
sAnim_ChooseBoxMenu_TopRight,
sAnim_ChooseBoxMenu_BottomRight
};
static const union AffineAnimCmd sAffineAnim_ChooseBoxMenu[] =
{
AFFINEANIMCMD_FRAME(0xE0, 0xE0, 0, 0),
AFFINEANIMCMD_END
};
// Unused
static const union AffineAnimCmd *const sAffineAnims_ChooseBoxMenu[] =
{
sAffineAnim_ChooseBoxMenu
};
static const u8 sChooseBoxMenu_TextColors[] = {TEXT_COLOR_RED, TEXT_DYNAMIC_COLOR_6, TEXT_DYNAMIC_COLOR_5};
static const u8 sText_OutOf30[] = _("/30");
static const u16 sChooseBoxMenu_Pal[] = INCBIN_U16("graphics/pokemon_storage/box_selection_popup.gbapal");
static const u8 sChooseBoxMenuCenter_Gfx[] = INCBIN_U8("graphics/pokemon_storage/box_selection_popup_center.4bpp");
static const u8 sChooseBoxMenuSides_Gfx[] = INCBIN_U8("graphics/pokemon_storage/box_selection_popup_sides.4bpp");
static const u32 sScrollingBg_Gfx[] = INCBIN_U32("graphics/pokemon_storage/scrolling_bg.4bpp.lz");
static const u32 sScrollingBg_Tilemap[] = INCBIN_U32("graphics/pokemon_storage/scrolling_bg.bin.lz");
static const u16 sDisplayMenu_Pal[] = INCBIN_U16("graphics/pokemon_storage/display_menu.gbapal"); // Unused
static const u32 sDisplayMenu_Tilemap[] = INCBIN_U32("graphics/pokemon_storage/display_menu.bin.lz");
static const u16 sPkmnData_Tilemap[] = INCBIN_U16("graphics/pokemon_storage/pkmn_data.bin");
// sInterface_Pal - parts of the display frame, "PkmnData"'s normal color, Close Box
static const u16 sInterface_Pal[] = INCBIN_U16("graphics/pokemon_storage/interface.gbapal");
static const u16 sPkmnDataGray_Pal[] = INCBIN_U16("graphics/pokemon_storage/pkmn_data_gray.gbapal");
static const u16 sScrollingBg_Pal[] = INCBIN_U16("graphics/pokemon_storage/scrolling_bg.gbapal");
static const u16 sScrollingBgMoveItems_Pal[] = INCBIN_U16("graphics/pokemon_storage/scrolling_bg_move_items.gbapal");
static const u16 sCloseBoxButton_Tilemap[] = INCBIN_U16("graphics/pokemon_storage/close_box_button.bin");
static const u16 sPartySlotFilled_Tilemap[] = INCBIN_U16("graphics/pokemon_storage/party_slot_filled.bin");
static const u16 sPartySlotEmpty_Tilemap[] = INCBIN_U16("graphics/pokemon_storage/party_slot_empty.bin");
static const u16 sWaveform_Pal[] = INCBIN_U16("graphics/pokemon_storage/waveform.gbapal");
static const u32 sWaveform_Gfx[] = INCBIN_U32("graphics/pokemon_storage/waveform.4bpp");
static const u16 sUnused_Pal[] = INCBIN_U16("graphics/pokemon_storage/unused.gbapal");
static const u16 sTextWindows_Pal[] = INCBIN_U16("graphics/pokemon_storage/text_windows.gbapal");
static const struct WindowTemplate sWindowTemplates[] =
{
// The panel below the currently displayed Pokémon
[WIN_DISPLAY_INFO] = {
.bg = 1,
.tilemapLeft = 0,
.tilemapTop = 11,
.width = 9,
.height = 7,
.paletteNum = 3,
.baseBlock = 0xC0,
},
[WIN_MESSAGE] = {
.bg = 0,
.tilemapLeft = 11,
.tilemapTop = 17,
.width = 18,
.height = 2,
.paletteNum = 15,
.baseBlock = 0x14,
},
[WIN_ITEM_DESC] = {
.bg = 0,
.tilemapLeft = 0,
.tilemapTop = 13,
.width = 21,
.height = 7,
.paletteNum = 15,
.baseBlock = 0x14,
},
DUMMY_WIN_TEMPLATE