-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
party_menu.c
executable file
·6430 lines (5848 loc) · 202 KB
/
party_menu.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 "battle.h"
#include "battle_anim.h"
#include "battle_controllers.h"
#include "battle_gfx_sfx_util.h"
#include "battle_interface.h"
#include "battle_pike.h"
#include "battle_pyramid.h"
#include "battle_pyramid_bag.h"
#include "bg.h"
#include "contest.h"
#include "data.h"
#include "decompress.h"
#include "easy_chat.h"
#include "event_data.h"
#include "evolution_scene.h"
#include "field_control_avatar.h"
#include "field_effect.h"
#include "field_player_avatar.h"
#include "field_screen_effect.h"
#include "field_specials.h"
#include "field_weather.h"
#include "fieldmap.h"
#include "fldeff.h"
#include "fldeff_misc.h"
#include "frontier_util.h"
#include "gpu_regs.h"
#include "graphics.h"
#include "international_string_util.h"
#include "item.h"
#include "item_menu.h"
#include "item_use.h"
#include "link.h"
#include "link_rfu.h"
#include "mail.h"
#include "main.h"
#include "menu.h"
#include "menu_helpers.h"
#include "menu_specialized.h"
#include "metatile_behavior.h"
#include "overworld.h"
#include "palette.h"
#include "party_menu.h"
#include "player_pc.h"
#include "pokemon.h"
#include "pokemon_icon.h"
#include "pokemon_jump.h"
#include "pokemon_storage_system.h"
#include "pokemon_summary_screen.h"
#include "region_map.h"
#include "reshow_battle_screen.h"
#include "scanline_effect.h"
#include "script.h"
#include "sound.h"
#include "sprite.h"
#include "start_menu.h"
#include "string_util.h"
#include "strings.h"
#include "task.h"
#include "text.h"
#include "text_window.h"
#include "trade.h"
#include "union_room.h"
#include "window.h"
#include "constants/battle.h"
#include "constants/battle_frontier.h"
#include "constants/field_effects.h"
#include "constants/item_effects.h"
#include "constants/items.h"
#include "constants/moves.h"
#include "constants/party_menu.h"
#include "constants/rgb.h"
#include "constants/songs.h"
enum {
MENU_SUMMARY,
MENU_SWITCH,
MENU_CANCEL1,
MENU_ITEM,
MENU_GIVE,
MENU_TAKE_ITEM,
MENU_MAIL,
MENU_TAKE_MAIL,
MENU_READ,
MENU_CANCEL2,
MENU_SHIFT,
MENU_SEND_OUT,
MENU_ENTER,
MENU_NO_ENTRY,
MENU_STORE,
MENU_REGISTER,
MENU_TRADE1,
MENU_TRADE2,
MENU_TOSS,
MENU_FIELD_MOVES
};
// IDs for the action lists that appear when a party mon is selected
enum {
ACTIONS_NONE,
ACTIONS_SWITCH,
ACTIONS_SHIFT,
ACTIONS_SEND_OUT,
ACTIONS_ENTER,
ACTIONS_NO_ENTRY,
ACTIONS_STORE,
ACTIONS_SUMMARY_ONLY,
ACTIONS_ITEM,
ACTIONS_MAIL,
ACTIONS_REGISTER,
ACTIONS_TRADE,
ACTIONS_SPIN_TRADE,
ACTIONS_TAKEITEM_TOSS,
};
// In CursorCb_FieldMove, field moves <= FIELD_MOVE_WATERFALL are assumed to line up with the badge flags.
// Badge flag names are commented here for people searching for references to remove the badge requirement.
enum {
FIELD_MOVE_CUT, // FLAG_BADGE01_GET
FIELD_MOVE_FLASH, // FLAG_BADGE02_GET
FIELD_MOVE_ROCK_SMASH, // FLAG_BADGE03_GET
FIELD_MOVE_STRENGTH, // FLAG_BADGE04_GET
FIELD_MOVE_SURF, // FLAG_BADGE05_GET
FIELD_MOVE_FLY, // FLAG_BADGE06_GET
FIELD_MOVE_DIVE, // FLAG_BADGE07_GET
FIELD_MOVE_WATERFALL, // FLAG_BADGE08_GET
FIELD_MOVE_TELEPORT,
FIELD_MOVE_DIG,
FIELD_MOVE_SECRET_POWER,
FIELD_MOVE_MILK_DRINK,
FIELD_MOVE_SOFT_BOILED,
FIELD_MOVE_SWEET_SCENT,
FIELD_MOVES_COUNT
};
enum {
PARTY_BOX_LEFT_COLUMN,
PARTY_BOX_RIGHT_COLUMN,
};
enum {
TAG_POKEBALL = 1200,
TAG_POKEBALL_SMALL,
TAG_STATUS_ICONS,
};
#define TAG_HELD_ITEM 55120
#define PARTY_PAL_SELECTED (1 << 0)
#define PARTY_PAL_FAINTED (1 << 1)
#define PARTY_PAL_TO_SWITCH (1 << 2)
#define PARTY_PAL_MULTI_ALT (1 << 3)
#define PARTY_PAL_SWITCHING (1 << 4)
#define PARTY_PAL_TO_SOFTBOIL (1 << 5)
#define PARTY_PAL_NO_MON (1 << 6)
#define PARTY_PAL_UNUSED (1 << 7)
#define MENU_DIR_DOWN 1
#define MENU_DIR_UP -1
#define MENU_DIR_RIGHT 2
#define MENU_DIR_LEFT -2
enum {
CAN_LEARN_MOVE,
CANNOT_LEARN_MOVE,
ALREADY_KNOWS_MOVE,
CANNOT_LEARN_MOVE_IS_EGG
};
enum {
// Window ids 0-5 are implicitly assigned to each party Pokémon in InitPartyMenuBoxes
WIN_MSG = PARTY_SIZE,
};
struct PartyMenuBoxInfoRects
{
void (*blitFunc)(u8, u8, u8, u8, u8, bool8);
u8 dimensions[24];
u8 descTextLeft;
u8 descTextTop;
u8 descTextWidth;
u8 descTextHeight;
};
struct PartyMenuInternal
{
TaskFunc task;
MainCallback exitCallback;
u32 chooseHalf:1;
u32 lastSelectedSlot:3; // Used to return to same slot when going left/right bewtween columns
u32 spriteIdConfirmPokeball:7;
u32 spriteIdCancelPokeball:7;
u32 messageId:14;
u8 windowId[3];
u8 actions[8];
u8 numActions;
// In vanilla Emerald, only the first 0xB0 hwords (0x160 bytes) are actually used.
// However, a full 0x100 hwords (0x200 bytes) are allocated.
// It is likely that the 0x160 value used below is a constant defined by
// bin2c, the utility used to encode the compressed palette data.
u16 palBuffer[BG_PLTT_SIZE / sizeof(u16)];
s16 data[16];
};
struct PartyMenuBox
{
const struct PartyMenuBoxInfoRects *infoRects;
const u8 *spriteCoords;
u8 windowId;
u8 monSpriteId;
u8 itemSpriteId;
u8 pokeballSpriteId;
u8 statusSpriteId;
};
// EWRAM vars
static EWRAM_DATA struct PartyMenuInternal *sPartyMenuInternal = NULL;
EWRAM_DATA struct PartyMenu gPartyMenu = {0};
static EWRAM_DATA struct PartyMenuBox *sPartyMenuBoxes = NULL;
static EWRAM_DATA u8 *sPartyBgGfxTilemap = NULL;
static EWRAM_DATA u8 *sPartyBgTilemapBuffer = NULL;
EWRAM_DATA bool8 gPartyMenuUseExitCallback = 0;
EWRAM_DATA u8 gSelectedMonPartyId = 0;
EWRAM_DATA MainCallback gPostMenuFieldCallback = NULL;
static EWRAM_DATA u16 *sSlot1TilemapBuffer = 0; // for switching party slots
static EWRAM_DATA u16 *sSlot2TilemapBuffer = 0; //
EWRAM_DATA u8 gSelectedOrderFromParty[MAX_FRONTIER_PARTY_SIZE] = {0};
static EWRAM_DATA u16 sPartyMenuItemId = 0;
static EWRAM_DATA u16 sUnused = 0;
EWRAM_DATA u8 gBattlePartyCurrentOrder[PARTY_SIZE / 2] = {0}; // bits 0-3 are the current pos of Slot 1, 4-7 are Slot 2, and so on
// IWRAM common
COMMON_DATA void (*gItemUseCB)(u8, TaskFunc) = NULL;
static void ResetPartyMenu(void);
static void CB2_InitPartyMenu(void);
static bool8 ShowPartyMenu(void);
static void SetPartyMonsAllowedInMinigame(void);
static void ExitPartyMenu(void);
static bool8 AllocPartyMenuBg(void);
static bool8 AllocPartyMenuBgGfx(void);
static void InitPartyMenuWindows(u8);
static void InitPartyMenuBoxes(u8);
static void LoadPartyMenuPokeballGfx(void);
static void LoadPartyMenuAilmentGfx(void);
static bool8 CreatePartyMonSpritesLoop(void);
static bool8 RenderPartyMenuBoxes(void);
static void CreateCancelConfirmPokeballSprites(void);
static void CreateCancelConfirmWindows(u8);
static void Task_ExitPartyMenu(u8);
static void FreePartyPointers(void);
static void PartyPaletteBufferCopy(u8);
static void DisplayPartyPokemonDataForMultiBattle(u8);
static void LoadPartyBoxPalette(struct PartyMenuBox *, u8);
static void DrawEmptySlot(u8 windowId);
static void DisplayPartyPokemonDataForRelearner(u8);
static void DisplayPartyPokemonDataForContest(u8);
static void DisplayPartyPokemonDataForChooseHalf(u8);
static void DisplayPartyPokemonDataForWirelessMinigame(u8);
static void DisplayPartyPokemonDataForBattlePyramidHeldItem(u8);
static bool8 DisplayPartyPokemonDataForMoveTutorOrEvolutionItem(u8);
static void DisplayPartyPokemonData(u8);
static void DisplayPartyPokemonNickname(struct Pokemon *, struct PartyMenuBox *, u8);
static void DisplayPartyPokemonLevelCheck(struct Pokemon *, struct PartyMenuBox *, u8);
static void DisplayPartyPokemonGenderNidoranCheck(struct Pokemon *, struct PartyMenuBox *, u8);
static void DisplayPartyPokemonHPCheck(struct Pokemon *, struct PartyMenuBox *, u8);
static void DisplayPartyPokemonMaxHPCheck(struct Pokemon *, struct PartyMenuBox *, u8);
static void DisplayPartyPokemonHPBarCheck(struct Pokemon *, struct PartyMenuBox *);
static void DisplayPartyPokemonDescriptionText(u8, struct PartyMenuBox *, u8);
static bool8 IsMonAllowedInMinigame(u8);
static void DisplayPartyPokemonDataToTeachMove(u8, u16, u8);
static u8 CanMonLearnTMTutor(struct Pokemon *, u16, u8);
static void DisplayPartyPokemonBarDetail(u8, const u8 *, u8, const u8 *);
static void DisplayPartyPokemonLevel(u8, struct PartyMenuBox *);
static void DisplayPartyPokemonGender(u8, u16, u8 *, struct PartyMenuBox *);
static void DisplayPartyPokemonHP(u16, struct PartyMenuBox *);
static void DisplayPartyPokemonMaxHP(u16, struct PartyMenuBox *);
static void DisplayPartyPokemonHPBar(u16, u16, struct PartyMenuBox *);
static void CreatePartyMonIconSpriteParameterized(u16, u32, struct PartyMenuBox *, u8, u32);
static void CreatePartyMonHeldItemSpriteParameterized(u16, u16, struct PartyMenuBox *);
static void CreatePartyMonPokeballSpriteParameterized(u16, struct PartyMenuBox *);
static void CreatePartyMonStatusSpriteParameterized(u16, u8, struct PartyMenuBox *);
// These next 4 functions are essentially redundant with the above 4
// The only difference is that rather than receive the data directly they retrieve it from the mon struct
static void CreatePartyMonHeldItemSprite(struct Pokemon *, struct PartyMenuBox *);
static void CreatePartyMonPokeballSprite(struct Pokemon *, struct PartyMenuBox *);
static void CreatePartyMonIconSprite(struct Pokemon *, struct PartyMenuBox *, u32);
static void CreatePartyMonStatusSprite(struct Pokemon *, struct PartyMenuBox *);
static u8 CreateSmallPokeballButtonSprite(u8, u8);
static void DrawCancelConfirmButtons(void);
static u8 CreatePokeballButtonSprite(u8, u8);
static void AnimateSelectedPartyIcon(u8, u8);
static void PartyMenuStartSpriteAnim(u8, u8);
static u8 GetPartyBoxPaletteFlags(u8, u8);
static bool8 PartyBoxPal_ParnterOrDisqualifiedInArena(u8);
static u8 GetPartyIdFromBattleSlot(u8);
static void Task_ClosePartyMenuAndSetCB2(u8);
static void UpdatePartyToFieldOrder(void);
static void MoveCursorToConfirm(void);
static void HandleChooseMonCancel(u8, s8 *);
static void HandleChooseMonSelection(u8, s8 *);
static u16 PartyMenuButtonHandler(s8 *);
static s8 *GetCurrentPartySlotPtr(void);
static bool8 IsSelectedMonNotEgg(u8 *);
static void PartyMenuRemoveWindow(u8 *);
static void CB2_SetUpExitToBattleScreen(void);
static void Task_ClosePartyMenuAfterText(u8);
static void TryTutorSelectedMon(u8);
static void TryGiveMailToSelectedMon(u8);
static void TryGiveItemOrMailToSelectedMon(u8);
static void SwitchSelectedMons(u8);
static void TryEnterMonForMinigame(u8, u8);
static void Task_TryCreateSelectionWindow(u8);
static void FinishTwoMonAction(u8);
static void CancelParticipationPrompt(u8);
static bool8 DisplayCancelChooseMonYesNo(u8);
static const u8 *GetFacilityCancelString(void);
static void Task_CancelChooseMonYesNo(u8);
static void PartyMenuDisplayYesNoMenu(void);
static void Task_HandleCancelChooseMonYesNoInput(u8);
static void Task_ReturnToChooseMonAfterText(u8);
static void UpdateCurrentPartySelection(s8 *, s8);
static void UpdatePartySelectionSingleLayout(s8 *, s8);
static void UpdatePartySelectionDoubleLayout(s8 *, s8);
static s8 GetNewSlotDoubleLayout(s8, s8);
static void PrintMessage(const u8 *);
static void Task_PrintAndWaitForText(u8);
static bool16 IsMonAllowedInPokemonJump(struct Pokemon *);
static bool16 IsMonAllowedInDodrioBerryPicking(struct Pokemon *);
static void Task_CancelParticipationYesNo(u8);
static void Task_HandleCancelParticipationYesNoInput(u8);
static bool8 CanLearnTutorMove(u16, u8);
static u16 GetTutorMove(u8);
static bool8 ShouldUseChooseMonText(void);
static void SetPartyMonFieldSelectionActions(struct Pokemon *, u8);
static u8 GetPartyMenuActionsTypeInBattle(struct Pokemon *);
static u8 GetPartySlotEntryStatus(s8);
static void Task_UpdateHeldItemSprite(u8);
static void Task_HandleSelectionMenuInput(u8);
static void CB2_ShowPokemonSummaryScreen(void);
static void UpdatePartyToBattleOrder(void);
static void CB2_ReturnToPartyMenuFromSummaryScreen(void);
static void SlidePartyMenuBoxOneStep(u8);
static void Task_SlideSelectedSlotsOffscreen(u8);
static void SwitchPartyMon(void);
static void Task_SlideSelectedSlotsOnscreen(u8);
static void CB2_SelectBagItemToGive(void);
static void CB2_GiveHoldItem(void);
static void CB2_WriteMailToGiveMon(void);
static void Task_SwitchHoldItemsPrompt(u8);
static void Task_GiveHoldItem(u8);
static void Task_SwitchItemsYesNo(u8);
static void Task_HandleSwitchItemsYesNoInput(u8);
static void Task_WriteMailToGiveMonAfterText(u8);
static void CB2_ReturnToPartyMenuFromWritingMail(void);
static void Task_DisplayGaveMailFromPartyMessage(u8);
static void UpdatePartyMonHeldItemSprite(struct Pokemon *, struct PartyMenuBox *);
static void Task_TossHeldItemYesNo(u8 taskId);
static void Task_HandleTossHeldItemYesNoInput(u8);
static void Task_TossHeldItem(u8);
static void CB2_ReadHeldMail(void);
static void CB2_ReturnToPartyMenuFromReadingMail(void);
static void Task_SendMailToPCYesNo(u8);
static void Task_HandleSendMailToPCYesNoInput(u8);
static void Task_LoseMailMessageYesNo(u8);
static void Task_HandleLoseMailMessageYesNoInput(u8);
static bool8 TrySwitchInPokemon(void);
static void Task_SpinTradeYesNo(u8);
static void Task_HandleSpinTradeYesNoInput(u8);
static void Task_CancelAfterAorBPress(u8);
static void DisplayFieldMoveExitAreaMessage(u8);
static void DisplayCantUseFlashMessage(void);
static void DisplayCantUseSurfMessage(void);
static void Task_FieldMoveExitAreaYesNo(u8);
static void Task_HandleFieldMoveExitAreaYesNoInput(u8);
static void Task_FieldMoveWaitForFade(u8);
static u16 GetFieldMoveMonSpecies(void);
static void UpdatePartyMonHPBar(u8, struct Pokemon *);
static void SpriteCB_UpdatePartyMonIcon(struct Sprite *);
static void SpriteCB_BouncePartyMonIcon(struct Sprite *);
static void ShowOrHideHeldItemSprite(u16, struct PartyMenuBox *);
static void CreateHeldItemSpriteForTrade(u8, bool8);
static void SpriteCB_HeldItem(struct Sprite *);
static void SetPartyMonAilmentGfx(struct Pokemon *, struct PartyMenuBox *);
static void UpdatePartyMonAilmentGfx(u8, struct PartyMenuBox *);
static u8 GetPartyLayoutFromBattleType(void);
static void Task_SetSacredAshCB(u8);
static void CB2_ReturnToBagMenu(void);
static void Task_DisplayHPRestoredMessage(u8);
static u16 ItemEffectToMonEv(struct Pokemon *, u8);
static void ItemEffectToStatString(u8, u8 *);
static void ReturnToUseOnWhichMon(u8);
static void SetSelectedMoveForPPItem(u8);
static void TryUsePPItem(u8);
static void Task_LearnedMove(u8);
static void Task_ReplaceMoveYesNo(u8);
static void Task_DoLearnedMoveFanfareAfterText(u8);
static void Task_LearnNextMoveOrClosePartyMenu(u8);
static void Task_TryLearningNextMove(u8);
static void Task_HandleReplaceMoveYesNoInput(u8);
static void Task_ShowSummaryScreenToForgetMove(u8);
static void StopLearningMovePrompt(u8);
static void CB2_ShowSummaryScreenToForgetMove(void);
static void CB2_ReturnToPartyMenuWhileLearningMove(void);
static void Task_ReturnToPartyMenuWhileLearningMove(u8);
static void DisplayPartyMenuForgotMoveMessage(u8);
static void Task_PartyMenuReplaceMove(u8);
static void Task_StopLearningMoveYesNo(u8);
static void Task_HandleStopLearningMoveYesNoInput(u8);
static void Task_TryLearningNextMoveAfterText(u8);
static void BufferMonStatsToTaskData(struct Pokemon *, s16 *);
static void UpdateMonDisplayInfoAfterRareCandy(u8, struct Pokemon *);
static void Task_DisplayLevelUpStatsPg1(u8);
static void DisplayLevelUpStatsPg1(u8);
static void Task_DisplayLevelUpStatsPg2(u8);
static void DisplayLevelUpStatsPg2(u8);
static void Task_TryLearnNewMoves(u8);
static void PartyMenuTryEvolution(u8);
static void DisplayMonNeedsToReplaceMove(u8);
static void DisplayMonLearnedMove(u8, u16);
static void UseSacredAsh(u8);
static void Task_SacredAshLoop(u8);
static void Task_SacredAshDisplayHPRestored(u8);
static void GiveItemOrMailToSelectedMon(u8);
static void DisplayItemMustBeRemovedFirstMessage(u8);
static void Task_SwitchItemsFromBagYesNo(u8);
static void RemoveItemToGiveFromBag(u16);
static void CB2_WriteMailToGiveMonFromBag(void);
static void GiveItemToSelectedMon(u8);
static void Task_UpdateHeldItemSpriteAndClosePartyMenu(u8);
static void CB2_ReturnToPartyOrBagMenuFromWritingMail(void);
static bool8 ReturnGiveItemToBagOrPC(u16);
static void Task_DisplayGaveMailFromBagMessage(u8);
static void Task_HandleSwitchItemsFromBagYesNoInput(u8);
static void Task_ValidateChosenHalfParty(u8);
static bool8 GetBattleEntryEligibility(struct Pokemon *);
static bool8 HasPartySlotAlreadyBeenSelected(u8);
static u8 GetBattleEntryLevelCap(void);
static u8 GetMaxBattleEntries(void);
static u8 GetMinBattleEntries(void);
static void Task_ContinueChoosingHalfParty(u8);
static void BufferBattlePartyOrder(u8 *, bool8);
static void BufferBattlePartyOrderBySide(u8 *, u8, u8);
static void Task_InitMultiPartnerPartySlideIn(u8);
static void Task_MultiPartnerPartySlideIn(u8);
static void SlideMultiPartyMenuBoxSpritesOneStep(u8);
static void Task_WaitAfterMultiPartnerPartySlideIn(u8);
static void BufferMonSelection(void);
static void Task_PartyMenuWaitForFade(u8 taskId);
static void Task_ChooseContestMon(u8 taskId);
static void CB2_ChooseContestMon(void);
static void Task_ChoosePartyMon(u8 taskId);
static void Task_ChooseMonForMoveRelearner(u8);
static void CB2_ChooseMonForMoveRelearner(void);
static void Task_BattlePyramidChooseMonHeldItems(u8);
static void ShiftMoveSlot(struct Pokemon *, u8, u8);
static void BlitBitmapToPartyWindow_LeftColumn(u8, u8, u8, u8, u8, bool8);
static void BlitBitmapToPartyWindow_RightColumn(u8, u8, u8, u8, u8, bool8);
static void CursorCb_Summary(u8);
static void CursorCb_Switch(u8);
static void CursorCb_Cancel1(u8);
static void CursorCb_Item(u8);
static void CursorCb_Give(u8);
static void CursorCb_TakeItem(u8);
static void CursorCb_Mail(u8);
static void CursorCb_Read(u8);
static void CursorCb_TakeMail(u8);
static void CursorCb_Cancel2(u8);
static void CursorCb_SendMon(u8);
static void CursorCb_Enter(u8);
static void CursorCb_NoEntry(u8);
static void CursorCb_Store(u8);
static void CursorCb_Register(u8);
static void CursorCb_Trade1(u8);
static void CursorCb_Trade2(u8);
static void CursorCb_Toss(u8);
static void CursorCb_FieldMove(u8);
static bool8 SetUpFieldMove_Surf(void);
static bool8 SetUpFieldMove_Fly(void);
static bool8 SetUpFieldMove_Waterfall(void);
static bool8 SetUpFieldMove_Dive(void);
// static const data
#include "data/pokemon/tutor_learnsets.h"
#include "data/party_menu.h"
// code
static void InitPartyMenu(u8 menuType, u8 layout, u8 partyAction, bool8 keepCursorPos, u8 messageId, TaskFunc task, MainCallback callback)
{
u16 i;
ResetPartyMenu();
sPartyMenuInternal = Alloc(sizeof(struct PartyMenuInternal));
if (sPartyMenuInternal == NULL)
{
SetMainCallback2(callback);
}
else
{
gPartyMenu.menuType = menuType;
gPartyMenu.exitCallback = callback;
gPartyMenu.action = partyAction;
sPartyMenuInternal->messageId = messageId;
sPartyMenuInternal->task = task;
sPartyMenuInternal->exitCallback = NULL;
sPartyMenuInternal->lastSelectedSlot = 0;
sPartyMenuInternal->spriteIdConfirmPokeball = 0x7F;
sPartyMenuInternal->spriteIdCancelPokeball = 0x7F;
if (menuType == PARTY_MENU_TYPE_CHOOSE_HALF)
sPartyMenuInternal->chooseHalf = TRUE;
else
sPartyMenuInternal->chooseHalf = FALSE;
if (layout != KEEP_PARTY_LAYOUT)
gPartyMenu.layout = layout;
for (i = 0; i < ARRAY_COUNT(sPartyMenuInternal->data); i++)
sPartyMenuInternal->data[i] = 0;
for (i = 0; i < ARRAY_COUNT(sPartyMenuInternal->windowId); i++)
sPartyMenuInternal->windowId[i] = WINDOW_NONE;
if (!keepCursorPos)
gPartyMenu.slotId = 0;
else if (gPartyMenu.slotId > PARTY_SIZE - 1 || GetMonData(&gPlayerParty[gPartyMenu.slotId], MON_DATA_SPECIES) == SPECIES_NONE)
gPartyMenu.slotId = 0;
gTextFlags.autoScroll = 0;
CalculatePlayerPartyCount();
SetMainCallback2(CB2_InitPartyMenu);
}
}
static void CB2_UpdatePartyMenu(void)
{
RunTasks();
AnimateSprites();
BuildOamBuffer();
DoScheduledBgTilemapCopiesToVram();
UpdatePaletteFade();
}
static void VBlankCB_PartyMenu(void)
{
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
}
static void CB2_InitPartyMenu(void)
{
while (TRUE)
{
if (MenuHelpers_ShouldWaitForLinkRecv() == TRUE || ShowPartyMenu() == TRUE || MenuHelpers_IsLinkActive() == TRUE)
break;
}
}
static bool8 ShowPartyMenu(void)
{
switch (gMain.state)
{
case 0:
SetVBlankHBlankCallbacksToNull();
ResetVramOamAndBgCntRegs();
ClearScheduledBgCopiesToVram();
gMain.state++;
break;
case 1:
ScanlineEffect_Stop();
gMain.state++;
break;
case 2:
ResetPaletteFade();
gPaletteFade.bufferTransferDisabled = TRUE;
gMain.state++;
break;
case 3:
ResetSpriteData();
gMain.state++;
break;
case 4:
FreeAllSpritePalettes();
gMain.state++;
break;
case 5:
if (!MenuHelpers_IsLinkActive())
ResetTasks();
gMain.state++;
break;
case 6:
SetPartyMonsAllowedInMinigame();
gMain.state++;
break;
case 7:
if (!AllocPartyMenuBg())
{
ExitPartyMenu();
return TRUE;
}
else
{
sPartyMenuInternal->data[0] = 0;
gMain.state++;
}
break;
case 8:
if (AllocPartyMenuBgGfx())
gMain.state++;
break;
case 9:
InitPartyMenuWindows(gPartyMenu.layout);
gMain.state++;
break;
case 10:
InitPartyMenuBoxes(gPartyMenu.layout);
sPartyMenuInternal->data[0] = 0;
gMain.state++;
break;
case 11:
LoadHeldItemIcons();
gMain.state++;
break;
case 12:
LoadPartyMenuPokeballGfx();
gMain.state++;
break;
case 13:
LoadPartyMenuAilmentGfx();
gMain.state++;
break;
case 14:
LoadMonIconPalettes();
gMain.state++;
break;
case 15:
if (CreatePartyMonSpritesLoop())
{
sPartyMenuInternal->data[0] = 0;
gMain.state++;
}
break;
case 16:
if (RenderPartyMenuBoxes())
{
sPartyMenuInternal->data[0] = 0;
gMain.state++;
}
break;
case 17:
CreateCancelConfirmPokeballSprites();
gMain.state++;
break;
case 18:
CreateCancelConfirmWindows(sPartyMenuInternal->chooseHalf);
gMain.state++;
break;
case 19:
gMain.state++;
break;
case 20:
CreateTask(sPartyMenuInternal->task, 0);
DisplayPartyMenuStdMessage(sPartyMenuInternal->messageId);
gMain.state++;
break;
case 21:
BlendPalettes(PALETTES_ALL, 16, 0);
gPaletteFade.bufferTransferDisabled = FALSE;
gMain.state++;
break;
case 22:
BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
gMain.state++;
break;
default:
SetVBlankCallback(VBlankCB_PartyMenu);
SetMainCallback2(CB2_UpdatePartyMenu);
return TRUE;
}
return FALSE;
}
static void ExitPartyMenu(void)
{
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
CreateTask(Task_ExitPartyMenu, 0);
SetVBlankCallback(VBlankCB_PartyMenu);
SetMainCallback2(CB2_UpdatePartyMenu);
}
static void Task_ExitPartyMenu(u8 taskId)
{
if (!gPaletteFade.active)
{
SetMainCallback2(gPartyMenu.exitCallback);
FreePartyPointers();
DestroyTask(taskId);
}
}
static void ResetPartyMenu(void)
{
sPartyMenuInternal = NULL;
sPartyBgTilemapBuffer = NULL;
sPartyMenuBoxes = NULL;
sPartyBgGfxTilemap = NULL;
}
static bool8 AllocPartyMenuBg(void)
{
sPartyBgTilemapBuffer = Alloc(0x800);
if (sPartyBgTilemapBuffer == NULL)
return FALSE;
memset(sPartyBgTilemapBuffer, 0, 0x800);
ResetBgsAndClearDma3BusyFlags(0);
InitBgsFromTemplates(0, sPartyMenuBgTemplates, ARRAY_COUNT(sPartyMenuBgTemplates));
SetBgTilemapBuffer(1, sPartyBgTilemapBuffer);
ResetAllBgsCoordinates();
ScheduleBgCopyTilemapToVram(1);
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
SetGpuReg(REG_OFFSET_BLDCNT, 0);
ShowBg(0);
ShowBg(1);
ShowBg(2);
return TRUE;
}
static bool8 AllocPartyMenuBgGfx(void)
{
u32 sizeout;
switch (sPartyMenuInternal->data[0])
{
case 0:
sPartyBgGfxTilemap = malloc_and_decompress(gPartyMenuBg_Gfx, &sizeout);
LoadBgTiles(1, sPartyBgGfxTilemap, sizeout, 0);
sPartyMenuInternal->data[0]++;
break;
case 1:
if (!IsDma3ManagerBusyWithBgCopy())
{
LZDecompressWram(gPartyMenuBg_Tilemap, sPartyBgTilemapBuffer);
sPartyMenuInternal->data[0]++;
}
break;
case 2:
LoadCompressedPalette(gPartyMenuBg_Pal, BG_PLTT_ID(0), 11 * PLTT_SIZE_4BPP);
CpuCopy16(gPlttBufferUnfaded, sPartyMenuInternal->palBuffer, 11 * PLTT_SIZE_4BPP);
sPartyMenuInternal->data[0]++;
break;
case 3:
PartyPaletteBufferCopy(4);
sPartyMenuInternal->data[0]++;
break;
case 4:
PartyPaletteBufferCopy(5);
sPartyMenuInternal->data[0]++;
break;
case 5:
PartyPaletteBufferCopy(6);
sPartyMenuInternal->data[0]++;
break;
case 6:
PartyPaletteBufferCopy(7);
sPartyMenuInternal->data[0]++;
break;
case 7:
PartyPaletteBufferCopy(8);
sPartyMenuInternal->data[0]++;
break;
default:
return TRUE;
}
return FALSE;
}
static void PartyPaletteBufferCopy(u8 palNum)
{
u8 offset = PLTT_ID(palNum);
CpuCopy16(&gPlttBufferUnfaded[BG_PLTT_ID(3)], &gPlttBufferUnfaded[offset], PLTT_SIZE_4BPP);
CpuCopy16(&gPlttBufferUnfaded[BG_PLTT_ID(3)], &gPlttBufferFaded[offset], PLTT_SIZE_4BPP);
}
static void FreePartyPointers(void)
{
if (sPartyMenuInternal)
Free(sPartyMenuInternal);
if (sPartyBgTilemapBuffer)
Free(sPartyBgTilemapBuffer);
if (sPartyBgGfxTilemap)
Free(sPartyBgGfxTilemap);
if (sPartyMenuBoxes)
Free(sPartyMenuBoxes);
FreeAllWindowBuffers();
}
static void InitPartyMenuBoxes(u8 layout)
{
u8 i;
sPartyMenuBoxes = Alloc(sizeof(struct PartyMenuBox[PARTY_SIZE]));
for (i = 0; i < PARTY_SIZE; i++)
{
sPartyMenuBoxes[i].infoRects = &sPartyBoxInfoRects[PARTY_BOX_RIGHT_COLUMN];
sPartyMenuBoxes[i].spriteCoords = sPartyMenuSpriteCoords[layout][i];
sPartyMenuBoxes[i].windowId = i;
sPartyMenuBoxes[i].monSpriteId = SPRITE_NONE;
sPartyMenuBoxes[i].itemSpriteId = SPRITE_NONE;
sPartyMenuBoxes[i].pokeballSpriteId = SPRITE_NONE;
sPartyMenuBoxes[i].statusSpriteId = SPRITE_NONE;
}
// The first party mon goes in the left column
sPartyMenuBoxes[0].infoRects = &sPartyBoxInfoRects[PARTY_BOX_LEFT_COLUMN];
if (layout == PARTY_LAYOUT_MULTI_SHOWCASE)
sPartyMenuBoxes[3].infoRects = &sPartyBoxInfoRects[PARTY_BOX_LEFT_COLUMN];
else if (layout != PARTY_LAYOUT_SINGLE)
sPartyMenuBoxes[1].infoRects = &sPartyBoxInfoRects[PARTY_BOX_LEFT_COLUMN];
}
static void RenderPartyMenuBox(u8 slot)
{
if (gPartyMenu.menuType == PARTY_MENU_TYPE_MULTI_SHOWCASE && slot >= MULTI_PARTY_SIZE)
{
DisplayPartyPokemonDataForMultiBattle(slot);
if (gMultiPartnerParty[slot - MULTI_PARTY_SIZE].species == SPECIES_NONE)
LoadPartyBoxPalette(&sPartyMenuBoxes[slot], PARTY_PAL_NO_MON);
else
LoadPartyBoxPalette(&sPartyMenuBoxes[slot], PARTY_PAL_MULTI_ALT);
CopyWindowToVram(sPartyMenuBoxes[slot].windowId, COPYWIN_GFX);
PutWindowTilemap(sPartyMenuBoxes[slot].windowId);
ScheduleBgCopyTilemapToVram(2);
}
else
{
if (GetMonData(&gPlayerParty[slot], MON_DATA_SPECIES) == SPECIES_NONE)
{
DrawEmptySlot(sPartyMenuBoxes[slot].windowId);
LoadPartyBoxPalette(&sPartyMenuBoxes[slot], PARTY_PAL_NO_MON);
CopyWindowToVram(sPartyMenuBoxes[slot].windowId, COPYWIN_GFX);
}
else
{
if (gPartyMenu.menuType == PARTY_MENU_TYPE_MOVE_RELEARNER)
DisplayPartyPokemonDataForRelearner(slot);
else if (gPartyMenu.menuType == PARTY_MENU_TYPE_CONTEST)
DisplayPartyPokemonDataForContest(slot);
else if (gPartyMenu.menuType == PARTY_MENU_TYPE_CHOOSE_HALF)
DisplayPartyPokemonDataForChooseHalf(slot);
else if (gPartyMenu.menuType == PARTY_MENU_TYPE_MINIGAME)
DisplayPartyPokemonDataForWirelessMinigame(slot);
else if (gPartyMenu.menuType == PARTY_MENU_TYPE_STORE_PYRAMID_HELD_ITEMS)
DisplayPartyPokemonDataForBattlePyramidHeldItem(slot);
else if (!DisplayPartyPokemonDataForMoveTutorOrEvolutionItem(slot))
DisplayPartyPokemonData(slot);
if (gPartyMenu.menuType == PARTY_MENU_TYPE_MULTI_SHOWCASE)
AnimatePartySlot(slot, 0);
else if (gPartyMenu.slotId == slot)
AnimatePartySlot(slot, 1);
else
AnimatePartySlot(slot, 0);
}
PutWindowTilemap(sPartyMenuBoxes[slot].windowId);
ScheduleBgCopyTilemapToVram(0);
}
}
static void DisplayPartyPokemonData(u8 slot)
{
if (GetMonData(&gPlayerParty[slot], MON_DATA_IS_EGG))
{
sPartyMenuBoxes[slot].infoRects->blitFunc(sPartyMenuBoxes[slot].windowId, 0, 0, 0, 0, TRUE);
DisplayPartyPokemonNickname(&gPlayerParty[slot], &sPartyMenuBoxes[slot], 0);
}
else
{
sPartyMenuBoxes[slot].infoRects->blitFunc(sPartyMenuBoxes[slot].windowId, 0, 0, 0, 0, FALSE);
DisplayPartyPokemonNickname(&gPlayerParty[slot], &sPartyMenuBoxes[slot], 0);
DisplayPartyPokemonLevelCheck(&gPlayerParty[slot], &sPartyMenuBoxes[slot], 0);
DisplayPartyPokemonGenderNidoranCheck(&gPlayerParty[slot], &sPartyMenuBoxes[slot], 0);
DisplayPartyPokemonHPCheck(&gPlayerParty[slot], &sPartyMenuBoxes[slot], 0);
DisplayPartyPokemonMaxHPCheck(&gPlayerParty[slot], &sPartyMenuBoxes[slot], 0);
DisplayPartyPokemonHPBarCheck(&gPlayerParty[slot], &sPartyMenuBoxes[slot]);
}
}
static void DisplayPartyPokemonDescriptionData(u8 slot, u8 stringID)
{
struct Pokemon *mon = &gPlayerParty[slot];
sPartyMenuBoxes[slot].infoRects->blitFunc(sPartyMenuBoxes[slot].windowId, 0, 0, 0, 0, TRUE);
DisplayPartyPokemonNickname(mon, &sPartyMenuBoxes[slot], 0);
if (!GetMonData(mon, MON_DATA_IS_EGG))
{
DisplayPartyPokemonLevelCheck(mon, &sPartyMenuBoxes[slot], 0);
DisplayPartyPokemonGenderNidoranCheck(mon, &sPartyMenuBoxes[slot], 0);
}
DisplayPartyPokemonDescriptionText(stringID, &sPartyMenuBoxes[slot], 0);
}
static void DisplayPartyPokemonDataForChooseHalf(u8 slot)
{
u8 i;
struct Pokemon *mon = &gPlayerParty[slot];
u8 *order = gSelectedOrderFromParty;
if (!GetBattleEntryEligibility(mon))
{
DisplayPartyPokemonDescriptionData(slot, PARTYBOX_DESC_NOT_ABLE);
return;
}
else
{
for (i = 0; i < GetMaxBattleEntries(); i++)
{
if (order[i] != 0 && (order[i] - 1) == slot)
{
DisplayPartyPokemonDescriptionData(slot, i + PARTYBOX_DESC_FIRST);
return;
}
}
DisplayPartyPokemonDescriptionData(slot, PARTYBOX_DESC_ABLE_3);
}
}
static void DisplayPartyPokemonDataForContest(u8 slot)
{
switch (GetContestEntryEligibility(&gPlayerParty[slot]))
{
case CANT_ENTER_CONTEST:
case CANT_ENTER_CONTEST_EGG:
case CANT_ENTER_CONTEST_FAINTED:
DisplayPartyPokemonDescriptionData(slot, PARTYBOX_DESC_NOT_ABLE);
break;
case CAN_ENTER_CONTEST_EQUAL_RANK:
case CAN_ENTER_CONTEST_HIGH_RANK:
DisplayPartyPokemonDescriptionData(slot, PARTYBOX_DESC_ABLE);
break;
}
}
static void DisplayPartyPokemonDataForRelearner(u8 slot)
{
if (GetNumberOfRelearnableMoves(&gPlayerParty[slot]) == 0)
DisplayPartyPokemonDescriptionData(slot, PARTYBOX_DESC_NOT_ABLE_2);
else
DisplayPartyPokemonDescriptionData(slot, PARTYBOX_DESC_ABLE_2);
}
static void DisplayPartyPokemonDataForWirelessMinigame(u8 slot)
{
if (IsMonAllowedInMinigame(slot) == TRUE)
DisplayPartyPokemonDescriptionData(slot, PARTYBOX_DESC_ABLE);
else
DisplayPartyPokemonDescriptionData(slot, PARTYBOX_DESC_NOT_ABLE);
}
static void DisplayPartyPokemonDataForBattlePyramidHeldItem(u8 slot)
{
if (GetMonData(&gPlayerParty[slot], MON_DATA_HELD_ITEM))
DisplayPartyPokemonDescriptionData(slot, PARTYBOX_DESC_HAVE);
else
DisplayPartyPokemonDescriptionData(slot, PARTYBOX_DESC_DONT_HAVE);
}
// Returns TRUE if teaching move or cant evolve with item (i.e. description data is shown), FALSE otherwise
static bool8 DisplayPartyPokemonDataForMoveTutorOrEvolutionItem(u8 slot)
{
struct Pokemon *currentPokemon = &gPlayerParty[slot];
u16 item = gSpecialVar_ItemId;
if (gPartyMenu.action == PARTY_ACTION_MOVE_TUTOR)
{
gSpecialVar_Result = FALSE;
DisplayPartyPokemonDataToTeachMove(slot, 0, gSpecialVar_0x8005);
}
else
{
if (gPartyMenu.action != PARTY_ACTION_USE_ITEM)
return FALSE;
switch (CheckIfItemIsTMHMOrEvolutionStone(item))
{
default:
return FALSE;
case 1: // TM/HM
DisplayPartyPokemonDataToTeachMove(slot, item, 0);
break;
case 2: // Evolution stone
if (!GetMonData(currentPokemon, MON_DATA_IS_EGG) && GetEvolutionTargetSpecies(currentPokemon, EVO_MODE_ITEM_CHECK, item) != SPECIES_NONE)
return FALSE;
DisplayPartyPokemonDescriptionData(slot, PARTYBOX_DESC_NO_USE);
break;
}
}
return TRUE;