From 5fa6ce24f3e168ea1c7527b1d3d08b9e5f39be32 Mon Sep 17 00:00:00 2001 From: VicSevenT Date: Wed, 15 Jul 2026 18:39:05 -0500 Subject: [PATCH] Document Battle Castle logic (#1229) --- asm/macros/frscrcmd.inc | 94 +- generated/game_records.txt | 2 +- .../frontier/battle_castle/args.h | 2 +- .../frontier/battle_castle/helpers.h | 5 - include/battle_castle_save.h | 51 ++ include/constants/battle_castle_functions.h | 50 +- include/constants/battle_frontier.h | 23 +- include/data/scripts/frscrcmd.h | 408 ++++----- include/overlay104/battle_castle.h | 86 ++ include/overlay104/battle_castle_helpers.h | 30 + include/overlay104/defs.h | 4 +- include/overlay104/frscrcmd_battle_castle.h | 32 +- include/overlay104/ov104_0222DCE0.h | 8 +- include/overlay104/ov104_0222ECE8.h | 2 +- include/overlay104/ov104_022361B4.h | 31 - include/overlay104/ov104_0223B6F4.h | 29 - include/overlay104/struct_battle_castle.h | 65 -- include/pokemon.h | 10 +- include/struct_decls/struct_020302DC_decl.h | 6 - include/struct_decls/struct_0203041C_decl.h | 6 - include/struct_defs/battle_frontier.h | 9 +- include/struct_defs/struct_020302DC.h | 20 - include/struct_defs/struct_0203041C.h | 10 - include/unk_020302D0.h | 20 - platinum.us/main.lsf | 6 +- .../frontier_scripts_battle_castle.s | 176 ++-- .../frontier_scripts_battle_hall.s | 12 +- res/text/battle_castle_self_app.json | 2 +- .../frontier/battle_castle/opponent_app.c | 34 +- .../frontier/battle_castle/self_app.c | 28 +- src/applications/frontier/records/main.c | 4 +- src/battle_castle_save.c | 139 +++ src/battle_frontier_save.c | 4 +- src/game_records.c | 2 +- src/meson.build | 6 +- src/overlay104/battle_castle.c | 735 ++++++++++++++++ src/overlay104/battle_castle_helpers.c | 383 ++++++++ src/overlay104/battle_hall.c | 6 +- src/overlay104/battle_hall_helpers.c | 4 +- src/overlay104/frscrcmd_battle_arcade.c | 2 +- src/overlay104/frscrcmd_battle_castle.c | 372 ++++---- src/overlay104/frscrcmd_battle_hall.c | 6 +- src/overlay104/ov104_0222DCE0.c | 191 ++-- src/overlay104/ov104_0222ECE8.c | 40 +- src/overlay104/ov104_022361B4.c | 815 ------------------ src/overlay104/ov104_0223B6F4.c | 427 --------- src/pokemon.c | 20 +- src/unk_020302D0.c | 168 ---- src/unk_0204FAB4.c | 18 +- 49 files changed, 2198 insertions(+), 2405 deletions(-) create mode 100644 include/battle_castle_save.h create mode 100644 include/overlay104/battle_castle.h create mode 100644 include/overlay104/battle_castle_helpers.h delete mode 100644 include/overlay104/ov104_022361B4.h delete mode 100644 include/overlay104/ov104_0223B6F4.h delete mode 100644 include/overlay104/struct_battle_castle.h delete mode 100644 include/struct_decls/struct_020302DC_decl.h delete mode 100644 include/struct_decls/struct_0203041C_decl.h delete mode 100644 include/struct_defs/struct_020302DC.h delete mode 100644 include/struct_defs/struct_0203041C.h delete mode 100644 include/unk_020302D0.h create mode 100644 src/battle_castle_save.c create mode 100644 src/overlay104/battle_castle.c create mode 100644 src/overlay104/battle_castle_helpers.c delete mode 100644 src/overlay104/ov104_022361B4.c delete mode 100644 src/overlay104/ov104_0223B6F4.c delete mode 100644 src/unk_020302D0.c diff --git a/asm/macros/frscrcmd.inc b/asm/macros/frscrcmd.inc index 5efe157139..3000e61cfa 100644 --- a/asm/macros/frscrcmd.inc +++ b/asm/macros/frscrcmd.inc @@ -463,16 +463,16 @@ .short FRSCRCMD_4F .endm - .macro FrontierScrCmd_50 - .short FRSCRCMD_50 + .macro ShowCastlePointsWindows + .short FRSCRCMD_SHOWCASTLEPOINTSWINDOWS .endm - .macro FrontierScrCmd_51 - .short FRSCRCMD_51 + .macro ClearCastlePointsWindows + .short FRSCRCMD_CLEARCASTLEPOINTSWINDOWS .endm - .macro FrontierScrCmd_52 - .short FRSCRCMD_52 + .macro ReprintCastlePointsInfo + .short FRSCRCMD_REPRINTCASTLEPOINTSINFO .endm .macro FrontierScrCmd_53 arg0 @@ -822,23 +822,23 @@ .short \arg0 .endm - .macro FrontierScrCmd_97 arg0, arg1, arg2, arg3, arg4, arg5 - .short FRSCRCMD_97 - .short \arg0 - .short \arg1 - .short \arg2 - .short \arg3 - .short \arg4 + .macro InitBattleCastle resumingFromSave, challengeType, partySlot1, partySlot2, partySlot3, arg5 + .short FRSCRCMD_INITBATTLECASTLE + .short \resumingFromSave + .short \challengeType + .short \partySlot1 + .short \partySlot2 + .short \partySlot3 .short \arg5 .endm - .macro FrontierScrCmd_98 arg0 - .short FRSCRCMD_98 - .short \arg0 + .macro LoadTrainersForRound resumingFromSave + .short FRSCRCMD_LOADTRAINERSFORROUND + .short \resumingFromSave .endm - .macro FrontierScrCmd_99 - .short FRSCRCMD_99 + .macro FreeBattleCastle + .short FRSCRCMD_FREEBATTLECASTLE .endm .macro OpenBattleCastleSelfApp @@ -857,12 +857,12 @@ .short FRSCRCMD_OPENBATTLECASTLEOPPONENTAPP .endm - .macro FrontierScrCmd_9E - .short FRSCRCMD_9E + .macro BattleCastle_SetupFirstOpponent + .short FRSCRCMD_BATTLECASTLE_SETUPFIRSTOPPONENT .endm - .macro FrontierScrCmd_9F - .short FRSCRCMD_9F + .macro BattleCastle_SetupNextOpponent + .short FRSCRCMD_BATTLECASTLE_SETUPNEXTOPPONENT .endm .macro CallBattleCastleFunction command, arg1, arg2, destVar @@ -878,20 +878,20 @@ .short \destVar .endm - .macro FrontierScrCmd_A2 arg0, arg1, arg2 - .short FRSCRCMD_A2 - .short \arg0 - .short \arg1 - .short \arg2 + .macro BattleCastle_SendCommMessage command, arg, result + .short FRSCRCMD_BATTLECASTLE_SENDCOMMMESSAGE + .short \command + .short \arg + .short \result .endm - .macro FrontierScrCmd_A3 arg0 - .short FRSCRCMD_A3 - .short \arg0 + .macro BattleCastle_WaitForCommResponses unused + .short FRSCRCMD_BATTLECASTLE_WAITFORCOMMRESPONSES + .short \unused .endm - .macro FrontierScrCmd_A4 - .short FRSCRCMD_A4 + .macro DummyOpenBattleCastleApp + .short FRSCRCMD_DUMMYOPENBATTLECASTLEAPP .endm .macro FrontierScrCmd_A5 arg0 @@ -899,27 +899,27 @@ .short \arg0 .endm - .macro FrontierScrCmd_A6 arg0, arg1 - .short FRSCRCMD_A6 - .short \arg0 - .short \arg1 + .macro GetCurrentCastlePoints challengeType, result + .short FRSCRCMD_GETCURRENTCASTLEPOINTS + .short \challengeType + .short \result .endm - .macro FrontierScrCmd_A7 arg0, arg1 - .short FRSCRCMD_A7 - .short \arg0 - .short \arg1 + .macro SpendCastlePoints challengeType, cp + .short FRSCRCMD_SPENDCASTLEPOINTS + .short \challengeType + .short \cp .endm - .macro FrontierScrCmd_A8 arg0, arg1 - .short FRSCRCMD_A8 - .short \arg0 - .short \arg1 + .macro ReceiveCastlePoints challengeType, cp + .short FRSCRCMD_RECEIVECASTLEPOINTS + .short \challengeType + .short \cp .endm - .macro FrontierScrCmd_A9 arg0 - .short FRSCRCMD_A9 - .byte \arg0 + .macro BattleCastle_PrintTrainerIntro index + .short FRSCRCMD_BATTLECASTLE_PRINTRAINERINTRO + .byte \index .endm .macro FrontierScrCmd_AA diff --git a/generated/game_records.txt b/generated/game_records.txt index 7935847749..25f8bb457c 100644 --- a/generated/game_records.txt +++ b/generated/game_records.txt @@ -63,7 +63,7 @@ RECORD_BATTLE_CASTLE_VICTORIES RECORD_BATTLE_HALL_VICTORIES RECORD_BATTLE_ARCADE_VICTORIES RECORD_UNK_064 -RECORD_UNK_065 +RECORD_CASTLE_POINTS_RECEIVED RECORD_UNK_066 RECORD_UNK_067 RECORD_BATTLE_POINTS_RECEIVED diff --git a/include/applications/frontier/battle_castle/args.h b/include/applications/frontier/battle_castle/args.h index 2e62212102..9c47841890 100644 --- a/include/applications/frontier/battle_castle/args.h +++ b/include/applications/frontier/battle_castle/args.h @@ -9,7 +9,7 @@ typedef struct BattleCastleAppArgs { u8 challengeType; u8 unused[3]; u8 identityUnlocked[4]; - u8 levelAdjustmentUnlocked[4]; + u8 levelAdjustments[4]; u8 statsUnlocked[4]; u8 movesUnlocked[4]; Party *party; diff --git a/include/applications/frontier/battle_castle/helpers.h b/include/applications/frontier/battle_castle/helpers.h index 1124f5104d..6538105d0a 100644 --- a/include/applications/frontier/battle_castle/helpers.h +++ b/include/applications/frontier/battle_castle/helpers.h @@ -4,11 +4,6 @@ #include "savedata.h" #include "string_template.h" -#define BATTLE_CASTLE_RANK_HEALING 0 -#define BATTLE_CASTLE_RANK_RENTALS 1 -#define BATTLE_CASTLE_RANK_OPPONENT_SUMMARY 2 -#define BATTLE_CASTLE_NUM_RANK_TYPES 3 - u8 BattleCastleApp_GetSelectedSlot(u8 numSlots, u8 slot); u8 BattleCastleApp_GetSlotFromSlotID(u8 exitSlot, u8 slotID); u8 BattleCastleApp_GetRank(SaveData *saveData, u8 challengeType, u8 rankType); diff --git a/include/battle_castle_save.h b/include/battle_castle_save.h new file mode 100644 index 0000000000..4f15555155 --- /dev/null +++ b/include/battle_castle_save.h @@ -0,0 +1,51 @@ +#ifndef POKEPLATINUM_BATTLE_CASTLE_SAVE_H +#define POKEPLATINUM_BATTLE_CASTLE_SAVE_H + +#include "savedata.h" + +#define CASTLE_SAVE_CHALLENGE_TYPE 0 +#define CASTLE_SAVE_CURRENT_BATTLE 1 +#define CASTLE_SAVE_MON_HP 2 +#define CASTLE_SAVE_MON_PP 3 +#define CASTLE_SAVE_MON_STATUS 4 +#define CASTLE_SAVE_HELD_ITEMS 5 +#define CASTLE_SAVE_TRAINER_IDS 6 +#define CASTLE_SAVE_PARTY_SLOTS 7 +#define CASTLE_SAVE_MON_SET_IDS 8 +#define CASTLE_SAVE_STREAK_FLAGS 9 +#define CASTLE_SAVE_HAVE_HEARD_INTRO 10 + +typedef struct BattleCastleSave { + u8 challengeType : 3; + u8 didSave : 1; + u8 unk_00_4 : 4; + u8 currentBattleNum; + u8 unk_02; + u8 partySlots[3]; + u16 trainerIDs[14]; + u16 monHP[4]; + u8 monPP[4][4]; + u32 monStatus[4]; + u16 heldItems[4]; + u16 monSetIDs[14]; + u16 unk_70; +} BattleCastleSave; + +typedef struct UnkStruct_0203041C_t { + u8 streakActiveFlags; + u8 haveHeardIntro; + u8 unk_02[2]; +} BattleCastlePersistentSave; + +void BattleCastleSave_Init(BattleCastleSave *castleSave); +BattleCastleSave *BattleCastleSave_Get(SaveData *saveData); +BOOL BattleCastleSave_HasSaved(BattleCastleSave *save); +void BattleCastleSave_RecordSave(BattleCastleSave *save, BOOL didSave); +void BattleCastleSave_SetMember(BattleCastleSave *save, u8 field, u8 index, u8 index2, void *value); +u32 BattleCastleSave_GetMember(BattleCastleSave *svae, u8 field, u8 index, u8 unused, void *unused2); +void BattleCastlePersistentSave_Init(BattleCastlePersistentSave *save); +BattleCastlePersistentSave *BattleCastlePersistentSave_Get(SaveData *saveData); +void BattleCastlePersistentSave_SetFlag(BattleCastlePersistentSave *save, u8 field, u8 challengeType, u8 unused, u8 *value); +u32 BattleCastlePersistentSave_GetFlag(BattleCastlePersistentSave *save, u8 field, u8 challengeType, u8 unused, void *unused2); + +#endif // POKEPLATINUM_BATTLE_CASTLE_SAVE_H diff --git a/include/constants/battle_castle_functions.h b/include/constants/battle_castle_functions.h index b955390c93..42392402ae 100644 --- a/include/constants/battle_castle_functions.h +++ b/include/constants/battle_castle_functions.h @@ -5,48 +5,48 @@ enum BattleCastleFunction { BC_FUNC_UNK_0 = 0, BC_FUNC_UNK_1, BC_FUNC_SET_CHALLENGE_TYPE, - BC_FUNC_UNK_3, + BC_FUNC_GET_SELECTED_APP_SLOT, BC_FUNC_GET_CURRENT_STREAK, BC_FUNC_INCREMENT_CURRENT_STREAK, BC_FUNC_UNK_6, BC_FUNC_RESET_SYSTEM, BC_FUNC_UNK_8, - BC_FUNC_UNK_9, - BC_FUNC_UNK_10, + BC_FUNC_HAS_SAVED, + BC_FUNC_QUICKSAVE, BC_FUNC_UNK_11, BC_FUNC_UNK_12, BC_FUNC_UNK_13, - BC_FUNC_UNK_14, - BC_FUNC_UNK_15, - BC_FUNC_UNK_16, + BC_FUNC_INCREMENT_CURRENT_BATTLE, + BC_FUNC_GET_MONS_SPECIES, + BC_FUNC_GET_MONS_MOVE, BC_FUNC_GET_CHALLENGE_TYPE, - BC_FUNC_UNK_18, - BC_FUNC_UNK_19, - BC_FUNC_UNK_20, - BC_FUNC_UNK_21, - BC_FUNC_UNK_22, - BC_FUNC_UNK_23, + BC_FUNC_RESTORE_HELD_ITEMS, + BC_FUNC_GET_CURRENT_ROUND, + BC_FUNC_GET_OPPONENT_OBJECT_ID, + BC_FUNC_SAVE_ON_LOSS, + BC_FUNC_SAVE_ON_COMPLETING_ROUND, + BC_FUNC_GET_CURRENT_BATTLE, BC_FUNC_UNK_24, - BC_FUNC_UNK_25, + BC_FUNC_CHECK_IF_MON_FAINTED, BC_FUNC_UNK_26, - BC_FUNC_UNK_27, - BC_FUNC_UNK_28, - BC_FUNC_UNK_29, + BC_FUNC_GET_CP_FROM_BATTLE, + BC_FUNC_PREP_FOR_NEXT_BATTLE, + BC_FUNC_INIT_COMM_MANAGER, BC_FUNC_UNK_30, BC_FUNC_UNK_31, BC_FUNC_UNK_32, BC_FUNC_UNK_33, BC_FUNC_UNK_34, BC_FUNC_IS_MULTIPLAYER_CHALLENGE, - BC_FUNC_UNK_36, - BC_FUNC_UNK_37, - BC_FUNC_UNK_38, - BC_FUNC_UNK_39, - BC_FUNC_UNK_40, - BC_FUNC_UNK_41, - BC_FUNC_UNK_42, - BC_FUNC_UNK_43, - BC_FUNC_UNK_44, + BC_FUNC_UPDATE_EMBLEM_FRAME, + BC_FUNC_LOAD_TRAINERS, + BC_FUNC_GET_EARNED_BP, + BC_FUNC_CHECK_HAVE_HEARD_DARACHS_INTRO, + BC_FUNC_GET_NEXT_BATTLE_TYPE, + BC_FUNC_CREATE_OPPONENT_MONS, + BC_FUNC_SETUP_OPPONENTS_PARTY, + BC_FUNC_CHECK_SEEN_VALET_INTRO, + BC_FUNC_UPDATE_CP, }; #endif // POKEPLATINUM_CONSTANTS_BATTLE_CASTLE_FUNCTIONS_H diff --git a/include/constants/battle_frontier.h b/include/constants/battle_frontier.h index 0fb67c0c2b..48ec900f09 100644 --- a/include/constants/battle_frontier.h +++ b/include/constants/battle_frontier.h @@ -26,6 +26,10 @@ enum BattleFrontierScene { #define FRONTIER_CHALLENGE_MULTI 2 #define FRONTIER_CHALLENGE_MULTI_WFC 3 +#define FRONTIER_NEXT_BATTLE_NORMAL 0 +#define FRONTIER_NEXT_BATTLE_SILVER 1 +#define FRONTIER_NEXT_BATTLE_GOLD 2 + #define FRONTIER_RECORDS_APP_TOWER 1 #define FRONTIER_RECORDS_APP_FACTORY 2 #define FRONTIER_RECORDS_APP_CASTLE 4 @@ -37,12 +41,23 @@ enum BattleFrontierScene { #define HALL_STREAK_GOLD_BATTLE 170 #define HALL_MAX_DISTINCT_ROUNDS ((HALL_STREAK_GOLD_BATTLE / HALL_BATTLES_PER_ROUND) + 1) -#define HALL_NEXT_BATTLE_NORMAL 0 -#define HALL_NEXT_BATTLE_SILVER 1 -#define HALL_NEXT_BATTLE_GOLD 2 - #define HALL_MAX_TYPE_RANK 10 +#define CASTLE_BATTLES_PER_ROUND 7 +#define CASTLE_STREAK_SILVER_BATTLE 21 +#define CASTLE_STREAK_GOLD_BATTLE 49 +#define CASTLE_MAX_DISTINCT_ROUNDS ((CASTLE_STREAK_GOLD_BATTLE / CASTLE_BATTLES_PER_ROUND) + 1) + +#define CASTLE_PARTY_SIZE_SOLO 3 +#define CASTLE_PARTY_SIZE_MULTI 2 + +#define CASTLE_MAX_LEVEL 50 + +#define BATTLE_CASTLE_RANK_HEALING 0 +#define BATTLE_CASTLE_RANK_RENTALS 1 +#define BATTLE_CASTLE_RANK_OPPONENT_SUMMARY 2 +#define BATTLE_CASTLE_NUM_RANK_TYPES 3 + #define BATTLES_PER_ROUND_ARCADE 7 #define ARCADE_PARTY_SIZE_SOLO 3 diff --git a/include/data/scripts/frscrcmd.h b/include/data/scripts/frscrcmd.h index 9cad5d7f3c..c970013054 100644 --- a/include/data/scripts/frscrcmd.h +++ b/include/data/scripts/frscrcmd.h @@ -5,210 +5,210 @@ #include "data/scripts/cmd_table.h" -ScriptCommand(FRSCRCMD_NOOP, FrontierScrCmd_Noop) -ScriptCommand(FRSCRCMD_END, FrontierScrCmd_End) -ScriptCommand(FRSCRCMD_02, FrontierScrCmd_02) -ScriptCommand(FRSCRCMD_03, FrontierScrCmd_03) -ScriptCommand(FRSCRCMD_04, FrontierScrCmd_04) -ScriptCommand(FRSCRCMD_WAITTIME, FrontierScrCmd_WaitTime) -ScriptCommand(FRSCRCMD_SETVARFROMVALUE, FrontierScrCmd_SetVarFromValue) -ScriptCommand(FRSCRCMD_SETVARFROMVAR, FrontierScrCmd_SetVarFromVar) -ScriptCommand(FRSCRCMD_ADDVAR, FrontierScrCmd_AddVar) -ScriptCommand(FRSCRCMD_SUBVAR, FrontierScrCmd_SubVar) -ScriptCommand(FRSCRCMD_GOTO, FrontierScrCmd_GoTo) -ScriptCommand(FRSCRCMD_GOTOIF, FrontierScrCmd_GoToIf) -ScriptCommand(FRSCRCMD_CALL, FrontierScrCmd_Call) -ScriptCommand(FRSCRCMD_RETURN, FrontierScrCmd_Return) -ScriptCommand(FRSCRCMD_CALLIF, FrontierScrCmd_CallIf) -ScriptCommand(FRSCRCMD_MESSAGEINSTANT, FrontierScrCmd_MessageInstant) -ScriptCommand(FRSCRCMD_MESSAGENOSKIP, FrontierScrCmd_MessageNoSkip) -ScriptCommand(FRSCRCMD_MESSAGE, FrontierScrCmd_Message) -ScriptCommand(FRSCRCMD_CLOSEMESSAGE, FrontierScrCmd_CloseMessage) -ScriptCommand(FRSCRCMD_FADESCREEN, FrontierScrCmd_FadeScreen) -ScriptCommand(FRSCRCMD_WAITFADESCREEN, FrontierScrCmd_WaitFadeScreen) -ScriptCommand(FRSCRCMD_INITGLOBALTEXTMENU, FrontierScrCmd_InitGlobalTextMenu) -ScriptCommand(FRSCRCMD_INITLOCALTEXTMENU, FrontierScrCmd_InitLocalTextMenu) -ScriptCommand(FRSCRCMD_ADDMENUENTRY, FrontierScrCmd_AddMenuEntry) -ScriptCommand(FRSCRCMD_ADDMENUENTRYWITHDESC, FrontierScrCmd_AddMenuEntryWithDesc) -ScriptCommand(FRSCRCMD_SHOWMENU, FrontierScrCmd_ShowMenu) -ScriptCommand(FRSCRCMD_INITGLOBALTEXTLISTMENU, FrontierScrCmd_InitGlobalTextListMenu) -ScriptCommand(FRSCRCMD_INITLOCALTEXTLISTMENU, FrontierScrCmd_InitLocalTextListMenu) -ScriptCommand(FRSCRCMD_ADDLISTMENUENTRY, FrontierScrCmd_AddListMenuEntry) -ScriptCommand(FRSCRCMD_SHOWLISTMENU, FrontierScrCmd_ShowListMenu) -ScriptCommand(FRSCRCMD_FREELISTMENU, FrontierScrCmd_FreeListMenu) -ScriptCommand(FRSCRCMD_SHOWYESNOMENU, FrontierScrCmd_ShowYesNoMenu) -ScriptCommand(FRSCRCMD_COMPAREVARTOVALUE, FrontierScrCmd_CompareVarToValue) -ScriptCommand(FRSCRCMD_COMPAREVARTOVAR, FrontierScrCmd_CompareVarToVar) -ScriptCommand(FRSCRCMD_22, FrontierScrCmd_22) -ScriptCommand(FRSCRCMD_23, FrontierScrCmd_23) -ScriptCommand(FRSCRCMD_24, FrontierScrCmd_24) -ScriptCommand(FRSCRCMD_25, FrontierScrCmd_25) -ScriptCommand(FRSCRCMD_26, FrontierScrCmd_26) -ScriptCommand(FRSCRCMD_DUMMY27, FrontierScrCmd_Dummy27) -ScriptCommand(FRSCRCMD_APPLYMOVEMENT, FrontierScrCmd_ApplyMovement) -ScriptCommand(FRSCRCMD_WAITMOVEMENT, FrontierScrCmd_WaitMovement) -ScriptCommand(FRSCRCMD_2A, FrontierScrCmd_2A) -ScriptCommand(FRSCRCMD_2B, FrontierScrCmd_2B) -ScriptCommand(FRSCRCMD_2C, FrontierScrCmd_2C) -ScriptCommand(FRSCRCMD_2D, FrontierScrCmd_2D) -ScriptCommand(FRSCRCMD_2E, FrontierScrCmd_2E) -ScriptCommand(FRSCRCMD_2F, FrontierScrCmd_2F) -ScriptCommand(FRSCRCMD_30, FrontierScrCmd_30) -ScriptCommand(FRSCRCMD_31, FrontierScrCmd_31) -ScriptCommand(FRSCRCMD_32, FrontierScrCmd_32) -ScriptCommand(FRSCRCMD_33, FrontierScrCmd_33) -ScriptCommand(FRSCRCMD_34, FrontierScrCmd_34) -ScriptCommand(FRSCRCMD_SYNCCONNECTEDPLAYERS, FrontierScrCmd_SyncConnectedPlayers) -ScriptCommand(FRSCRCMD_CLEARRECEIVEDTEMPDATAALLPLAYERS, FrontierScrCmd_ClearReceivedTempDataAllPlayers) -ScriptCommand(FRSCRCMD_ENDCOMMUNICATION, FrontierScrCmd_EndCommunication) -ScriptCommand(FRSCRCMD_GETRANDOM, FrontierScrCmd_GetRandom) -ScriptCommand(FRSCRCMD_HEALPARTY, FrontierScrCmd_HealParty) -ScriptCommand(FRSCRCMD_WAITABPRESS, FrontierScrCmd_WaitABPress) -ScriptCommand(FRSCRCMD_WAITABPRESSTIME, FrontierScrCmd_WaitABPressTime) -ScriptCommand(FRSCRCMD_DUMMY3C, FrontierScrCmd_Dummy3C) -ScriptCommand(FRSCRCMD_SETSYSTEMVAR, FrontierScrCmd_SetSystemVar) -ScriptCommand(FRSCRCMD_GETSYSTEMVAR, FrontierScrCmd_GetSystemVar) -ScriptCommand(FRSCRCMD_3F, FrontierScrCmd_3F) -ScriptCommand(FRSCRCMD_GETPLAYEROBJEVENTGFX, FrontierScrCmd_GetPlayerObjEventGfx) -ScriptCommand(FRSCRCMD_INITPARTICLESYSTEM, FrontierScrCmd_InitParticleSystem) -ScriptCommand(FRSCRCMD_FREEPARTICLESYSTEM, FrontierScrCmd_FreeParticleSystem) -ScriptCommand(FRSCRCMD_CREATEPARTICLESYSTEMEMITTER, FrontierScrCmd_CreateParticleSystemEmitter) -ScriptCommand(FRSCRCMD_WAITFORPARTICLESYSTEMEMITTERS, FrontierScrCmd_WaitForParticleSystemEmitters) -ScriptCommand(FRSCRCMD_45, FrontierScrCmd_45) -ScriptCommand(FRSCRCMD_46, FrontierScrCmd_46) -ScriptCommand(FRSCRCMD_47, FrontierScrCmd_47) -ScriptCommand(FRSCRCMD_INCREMENTRECORDVALUE, FrontierScrCmd_IncrementRecordValue) -ScriptCommand(FRSCRCMD_ADDTORECORDVALUE, FrontierScrCmd_AddToRecordValue) -ScriptCommand(FRSCRCMD_INCREMENTTRAINERSCORE, FrontierScrCmd_IncrementTrainerScore) -ScriptCommand(FRSCRCMD_4B, FrontierScrCmd_4B) -ScriptCommand(FRSCRCMD_4C, FrontierScrCmd_4C) -ScriptCommand(FRSCRCMD_4D, FrontierScrCmd_4D) -ScriptCommand(FRSCRCMD_4E, FrontierScrCmd_4E) -ScriptCommand(FRSCRCMD_4F, FrontierScrCmd_4F) -ScriptCommand(FRSCRCMD_50, FrontierScrCmd_50) -ScriptCommand(FRSCRCMD_51, FrontierScrCmd_51) -ScriptCommand(FRSCRCMD_52, FrontierScrCmd_52) -ScriptCommand(FRSCRCMD_53, FrontierScrCmd_53) -ScriptCommand(FRSCRCMD_54, FrontierScrCmd_54) -ScriptCommand(FRSCRCMD_PLAYSOUNDEFFECT, FrontierScrCmd_PlaySoundEffect) -ScriptCommand(FRSCRCMD_STOPSOUNDEFFECT, FrontierScrCmd_StopSoundEffect) -ScriptCommand(FRSCRCMD_WAITSOUNDEFFECT, FrontierScrCmd_WaitSoundEffect) -ScriptCommand(FRSCRCMD_PLAYFANFARE, FrontierScrCmd_PlayFanfare) -ScriptCommand(FRSCRCMD_WAITFANFARE, FrontierScrCmd_WaitFanfare) -ScriptCommand(FRSCRCMD_PLAYBGM, FrontierScrCmd_PlayBGM) -ScriptCommand(FRSCRCMD_STOPBGM, FrontierScrCmd_StopBGM) -ScriptCommand(FRSCRCMD_5C, FrontierScrCmd_5C) -ScriptCommand(FRSCRCMD_5D, FrontierScrCmd_5D) -ScriptCommand(FRSCRCMD_5E, FrontierScrCmd_5E) -ScriptCommand(FRSCRCMD_OPENBATTLEFACTORYAPPINITIAL, FrontierScrCmd_OpenBattleFactoryAppInitial) -ScriptCommand(FRSCRCMD_BATTLEFACTORY_CLEANUPBATTLE, FrontierScrCmd_BattleFactory_CleanupBattle) -ScriptCommand(FRSCRCMD_BATTLEFACTORY_STARTBATTLE, FrontierScrCmd_BattleFactory_StartBattle) -ScriptCommand(FRSCRCMD_OPENBATTLEFACTORYAPPFORTRADE, FrontierScrCmd_OpenBattleFactoryAppForTrade) -ScriptCommand(FRSCRCMD_63, FrontierScrCmd_63) -ScriptCommand(FRSCRCMD_64, FrontierScrCmd_64) -ScriptCommand(FRSCRCMD_65, FrontierScrCmd_65) -ScriptCommand(FRSCRCMD_66, FrontierScrCmd_66) -ScriptCommand(FRSCRCMD_CALLBATTLEFACTORYFUNCTION, FrontierScrCmd_CallBattleFactoryFunction) -ScriptCommand(FRSCRCMD_BATTLEFACTORY_CHECKWONBATTLE, FrontierScrCmd_BattleFactory_CheckWonBattle) -ScriptCommand(FRSCRCMD_69, FrontierScrCmd_69) -ScriptCommand(FRSCRCMD_6A, FrontierScrCmd_6A) -ScriptCommand(FRSCRCMD_6B, FrontierScrCmd_6B) -ScriptCommand(FRSCRCMD_INITNEWBATTLERECORDING, FrontierScrCmd_InitNewBattleRecording) -ScriptCommand(FRSCRCMD_6D, FrontierScrCmd_6D) -ScriptCommand(FRSCRCMD_6E, FrontierScrCmd_6E) -ScriptCommand(FRSCRCMD_FREEBATTLERECORDING, FrontierScrCmd_FreeBattleRecording) -ScriptCommand(FRSCRCMD_70, FrontierScrCmd_70) -ScriptCommand(FRSCRCMD_71, FrontierScrCmd_71) -ScriptCommand(FRSCRCMD_72, FrontierScrCmd_72) -ScriptCommand(FRSCRCMD_73, FrontierScrCmd_73) -ScriptCommand(FRSCRCMD_SAVEDATAEXTRAINIT, FrontierScrCmd_SaveDataExtraInit) -ScriptCommand(FRSCRCMD_GETMISCSAVEBLOCKINITFLAG, FrontierScrCmd_GetMiscSaveBlockInitFlag) -ScriptCommand(FRSCRCMD_BATTLEHALL_UPDATEWINRECORD, FrontierScrCmd_BattleHall_UpdateWinRecord) -ScriptCommand(FRSCRCMD_SHOWSAVINGICON, FrontierScrCmd_ShowSavingIcon) -ScriptCommand(FRSCRCMD_HIDESAVINGICON, FrontierScrCmd_HideSavingIcon) -ScriptCommand(FRSCRCMD_BUFFERITEMNAME, FrontierScrCmd_BufferItemName) -ScriptCommand(FRSCRCMD_BUFFERNUMBER, FrontierScrCmd_BufferNumber) -ScriptCommand(FRSCRCMD_BUFFERPLAYERNAME, FrontierScrCmd_BufferPlayerName) -ScriptCommand(FRSCRCMD_BUFFERPARTNERNAME, FrontierScrCmd_BufferPartnerName) -ScriptCommand(FRSCRCMD_BUFFERMOVENAME, FrontierScrCmd_BufferMoveName) -ScriptCommand(FRSCRCMD_BUFFERSPECIESNAME, FrontierScrCmd_BufferSpeciesName) -ScriptCommand(FRSCRCMD_BUFFERTYPENAME, FrontierScrCmd_BufferTypeName) -ScriptCommand(FRSCRCMD_BUFFERRIVALNAME, FrontierScrCmd_BufferRivalName) -ScriptCommand(FRSCRCMD_GETNUMBATTLEPOINTS, FrontierScrCmd_GetNumBattlePoints) -ScriptCommand(FRSCRCMD_GIVEBATTLEPOINTS, FrontierScrCmd_GiveBattlePoints) -ScriptCommand(FRSCRCMD_REMOTEBATTLEPOINTS, FrontierScrCmd_RemoteBattlePoints) -ScriptCommand(FRSCRCMD_CALLBATTLETOWERFUNCTION, FrontierScrCmd_CallBattleTowerFunction) -ScriptCommand(FRSCRCMD_85, FrontierScrCmd_85) -ScriptCommand(FRSCRCMD_FREETOWERSTRUCT, FrontierScrCmd_FreeTowerStruct) -ScriptCommand(FRSCRCMD_BATTLETOWER_STARTBATTLE, FrontierScrCmd_BattleTower_StartBattle) -ScriptCommand(FRSCRCMD_BATTLETOWER_CHECKWONBATTLE, FrontierScrCmd_BattleTower_CheckWonBattle) -ScriptCommand(FRSCRCMD_89, FrontierScrCmd_89) -ScriptCommand(FRSCRCMD_8A, FrontierScrCmd_8A) -ScriptCommand(FRSCRCMD_INITBATTLEHALL, FrontierScrCmd_InitBattleHall) -ScriptCommand(FRSCRCMD_BATTLEHALL_SETUP_NEXT_OPPONENT, FrontierScrCmd_BattleHall_SetupNextOpponent) -ScriptCommand(FRSCRCMD_FREEBATTLEHALL, FrontierScrCmd_FreeBattleHall) -ScriptCommand(FRSCRCMD_OPENBATTLEHALLAPP, FrontierScrCmd_OpenBattleHallApp) -ScriptCommand(FRSCRCMD_BATTLEHALL_CLEANUPBATTLE, FrontierScrCmd_BattleHall_CleanupBattle) -ScriptCommand(FRSCRCMD_BATTLEHALL_STARTBATTLE, FrontierScrCmd_BattleHall_StartBattle) -ScriptCommand(FRSCRCMD_CALLBATTLEHALLFUNCTION, FrontierScrCmd_CallBattleHallFunction) -ScriptCommand(FRSCRCMD_BATTLEHALL_CHECKWONBATTLE, FrontierScrCmd_BattleHall_CheckWonBattle) -ScriptCommand(FRSCRCMD_BATTLEHALL_SENDCOMMMESSAGE, FrontierScrCmd_BattleHall_SendCommMessage) -ScriptCommand(FRSCRCMD_94, FrontierScrCmd_94) -ScriptCommand(FRSCRCMD_BATTLEHALL_PRINTTRAINERINTRO, FrontierScrCmd_BattleHall_PrintTrainerIntro) -ScriptCommand(FRSCRCMD_DUMMY96, FrontierScrCmd_Dummy96) -ScriptCommand(FRSCRCMD_97, FrontierScrCmd_97) -ScriptCommand(FRSCRCMD_98, FrontierScrCmd_98) -ScriptCommand(FRSCRCMD_99, FrontierScrCmd_99) -ScriptCommand(FRSCRCMD_OPENBATTLECASTLESELFAPP, FrontierScrCmd_OpenBattleCastleSelfApp) -ScriptCommand(FRSCRCMD_BATTLECASTLE_CLEANUPBATTLE, FrontierScrCmd_BattleCastle_CleanupBattle) -ScriptCommand(FRSCRCMD_BATTLECASTLE_STARTBATTLE, FrontierScrCmd_BattleCastle_StartBattle) -ScriptCommand(FRSCRCMD_OPENBATTLECASTLEOPPONENTAPP, FrontierScrCmd_OpenBattleCastleOpponentApp) -ScriptCommand(FRSCRCMD_9E, FrontierScrCmd_9E) -ScriptCommand(FRSCRCMD_9F, FrontierScrCmd_9F) -ScriptCommand(FRSCRCMD_CALLBATTLECASTLEFUNCTION, FrontierScrCmd_CallBattleCastleFunction) -ScriptCommand(FRSCRCMD_BATTLECASTLE_CHECKWONBATTLE, FrontierScrCmd_BattleCastle_CheckWonBattle) -ScriptCommand(FRSCRCMD_A2, FrontierScrCmd_A2) -ScriptCommand(FRSCRCMD_A3, FrontierScrCmd_A3) -ScriptCommand(FRSCRCMD_A4, FrontierScrCmd_A4) -ScriptCommand(FRSCRCMD_A5, FrontierScrCmd_A5) -ScriptCommand(FRSCRCMD_A6, FrontierScrCmd_A6) -ScriptCommand(FRSCRCMD_A7, FrontierScrCmd_A7) -ScriptCommand(FRSCRCMD_A8, FrontierScrCmd_A8) -ScriptCommand(FRSCRCMD_A9, FrontierScrCmd_A9) -ScriptCommand(FRSCRCMD_AA, FrontierScrCmd_AA) -ScriptCommand(FRSCRCMD_AB, FrontierScrCmd_AB) -ScriptCommand(FRSCRCMD_AC, FrontierScrCmd_AC) -ScriptCommand(FRSCRCMD_AD, FrontierScrCmd_AD) -ScriptCommand(FRSCRCMD_AE, FrontierScrCmd_AE) -ScriptCommand(FRSCRCMD_AF, FrontierScrCmd_AF) -ScriptCommand(FRSCRCMD_B0, FrontierScrCmd_B0) -ScriptCommand(FRSCRCMD_B1, FrontierScrCmd_B1) -ScriptCommand(FRSCRCMD_B2, FrontierScrCmd_B2) -ScriptCommand(FRSCRCMD_B3, FrontierScrCmd_B3) -ScriptCommand(FRSCRCMD_B4, FrontierScrCmd_B4) -ScriptCommand(FRSCRCMD_B5, FrontierScrCmd_B5) -ScriptCommand(FRSCRCMD_CLEARTOWERSTRUCT, FrontierScrCmd_ClearTowerStruct) -ScriptCommand(FRSCRCMD_SETWIFILISTHOSTFRIENDCURRENTDATE, FrontierScrCmd_SetWiFiListHostFriendCurrentDate) -ScriptCommand(FRSCRCMD_B8, FrontierScrCmd_B8) -ScriptCommand(FRSCRCMD_B9, FrontierScrCmd_B9) -ScriptCommand(FRSCRCMD_BA, FrontierScrCmd_BA) -ScriptCommand(FRSCRCMD_BATTLEARCADE_CLEANUPBATTLE, FrontierScrCmd_BattleArcade_CleanupBattle) -ScriptCommand(FRSCRCMD_BATTLEARCADE_STARTBATTLE, FrontierScrCmd_BattleArcade_StartBattle) -ScriptCommand(FRSCRCMD_BD, FrontierScrCmd_BD) -ScriptCommand(FRSCRCMD_BE, FrontierScrCmd_BE) -ScriptCommand(FRSCRCMD_CALLBATTLEARCADEFUNCTION, FrontierScrCmd_CallBattleArcadeFunction) -ScriptCommand(FRSCRCMD_BATTLEARCADE_CHECKWONBATTLE, FrontierScrCmd_BattleArcade_CheckWonBattle) -ScriptCommand(FRSCRCMD_C1, FrontierScrCmd_C1) -ScriptCommand(FRSCRCMD_C2, FrontierScrCmd_C2) -ScriptCommand(FRSCRCMD_OPENBATTLEARCADEAPP, FrontierScrCmd_OpenBattleArcadeApp) -ScriptCommand(FRSCRCMD_C4, FrontierScrCmd_C4) -ScriptCommand(FRSCRCMD_C5, FrontierScrCmd_C5) -ScriptCommand(FRSCRCMD_C6, FrontierScrCmd_C6) -ScriptCommand(FRSCRCMD_C7, FrontierScrCmd_C7) -ScriptCommand(FRSCRCMD_C8, FrontierScrCmd_C8) -ScriptCommand(FRSCRCMD_C9, FrontierScrCmd_C9) -ScriptCommand(FRSCRCMD_SETMENUXORIGINSIDE, FrontierScrCmd_SetMenuXOriginSide) -ScriptCommand(FRSCRCMD_SETMENUYORIGINSIDE, FrontierScrCmd_SetMenuYOriginSide) +ScriptCommand(FRSCRCMD_NOOP, FrontierScrCmd_Noop) +ScriptCommand(FRSCRCMD_END, FrontierScrCmd_End) +ScriptCommand(FRSCRCMD_02, FrontierScrCmd_02) +ScriptCommand(FRSCRCMD_03, FrontierScrCmd_03) +ScriptCommand(FRSCRCMD_04, FrontierScrCmd_04) +ScriptCommand(FRSCRCMD_WAITTIME, FrontierScrCmd_WaitTime) +ScriptCommand(FRSCRCMD_SETVARFROMVALUE, FrontierScrCmd_SetVarFromValue) +ScriptCommand(FRSCRCMD_SETVARFROMVAR, FrontierScrCmd_SetVarFromVar) +ScriptCommand(FRSCRCMD_ADDVAR, FrontierScrCmd_AddVar) +ScriptCommand(FRSCRCMD_SUBVAR, FrontierScrCmd_SubVar) +ScriptCommand(FRSCRCMD_GOTO, FrontierScrCmd_GoTo) +ScriptCommand(FRSCRCMD_GOTOIF, FrontierScrCmd_GoToIf) +ScriptCommand(FRSCRCMD_CALL, FrontierScrCmd_Call) +ScriptCommand(FRSCRCMD_RETURN, FrontierScrCmd_Return) +ScriptCommand(FRSCRCMD_CALLIF, FrontierScrCmd_CallIf) +ScriptCommand(FRSCRCMD_MESSAGEINSTANT, FrontierScrCmd_MessageInstant) +ScriptCommand(FRSCRCMD_MESSAGENOSKIP, FrontierScrCmd_MessageNoSkip) +ScriptCommand(FRSCRCMD_MESSAGE, FrontierScrCmd_Message) +ScriptCommand(FRSCRCMD_CLOSEMESSAGE, FrontierScrCmd_CloseMessage) +ScriptCommand(FRSCRCMD_FADESCREEN, FrontierScrCmd_FadeScreen) +ScriptCommand(FRSCRCMD_WAITFADESCREEN, FrontierScrCmd_WaitFadeScreen) +ScriptCommand(FRSCRCMD_INITGLOBALTEXTMENU, FrontierScrCmd_InitGlobalTextMenu) +ScriptCommand(FRSCRCMD_INITLOCALTEXTMENU, FrontierScrCmd_InitLocalTextMenu) +ScriptCommand(FRSCRCMD_ADDMENUENTRY, FrontierScrCmd_AddMenuEntry) +ScriptCommand(FRSCRCMD_ADDMENUENTRYWITHDESC, FrontierScrCmd_AddMenuEntryWithDesc) +ScriptCommand(FRSCRCMD_SHOWMENU, FrontierScrCmd_ShowMenu) +ScriptCommand(FRSCRCMD_INITGLOBALTEXTLISTMENU, FrontierScrCmd_InitGlobalTextListMenu) +ScriptCommand(FRSCRCMD_INITLOCALTEXTLISTMENU, FrontierScrCmd_InitLocalTextListMenu) +ScriptCommand(FRSCRCMD_ADDLISTMENUENTRY, FrontierScrCmd_AddListMenuEntry) +ScriptCommand(FRSCRCMD_SHOWLISTMENU, FrontierScrCmd_ShowListMenu) +ScriptCommand(FRSCRCMD_FREELISTMENU, FrontierScrCmd_FreeListMenu) +ScriptCommand(FRSCRCMD_SHOWYESNOMENU, FrontierScrCmd_ShowYesNoMenu) +ScriptCommand(FRSCRCMD_COMPAREVARTOVALUE, FrontierScrCmd_CompareVarToValue) +ScriptCommand(FRSCRCMD_COMPAREVARTOVAR, FrontierScrCmd_CompareVarToVar) +ScriptCommand(FRSCRCMD_22, FrontierScrCmd_22) +ScriptCommand(FRSCRCMD_23, FrontierScrCmd_23) +ScriptCommand(FRSCRCMD_24, FrontierScrCmd_24) +ScriptCommand(FRSCRCMD_25, FrontierScrCmd_25) +ScriptCommand(FRSCRCMD_26, FrontierScrCmd_26) +ScriptCommand(FRSCRCMD_DUMMY27, FrontierScrCmd_Dummy27) +ScriptCommand(FRSCRCMD_APPLYMOVEMENT, FrontierScrCmd_ApplyMovement) +ScriptCommand(FRSCRCMD_WAITMOVEMENT, FrontierScrCmd_WaitMovement) +ScriptCommand(FRSCRCMD_2A, FrontierScrCmd_2A) +ScriptCommand(FRSCRCMD_2B, FrontierScrCmd_2B) +ScriptCommand(FRSCRCMD_2C, FrontierScrCmd_2C) +ScriptCommand(FRSCRCMD_2D, FrontierScrCmd_2D) +ScriptCommand(FRSCRCMD_2E, FrontierScrCmd_2E) +ScriptCommand(FRSCRCMD_2F, FrontierScrCmd_2F) +ScriptCommand(FRSCRCMD_30, FrontierScrCmd_30) +ScriptCommand(FRSCRCMD_31, FrontierScrCmd_31) +ScriptCommand(FRSCRCMD_32, FrontierScrCmd_32) +ScriptCommand(FRSCRCMD_33, FrontierScrCmd_33) +ScriptCommand(FRSCRCMD_34, FrontierScrCmd_34) +ScriptCommand(FRSCRCMD_SYNCCONNECTEDPLAYERS, FrontierScrCmd_SyncConnectedPlayers) +ScriptCommand(FRSCRCMD_CLEARRECEIVEDTEMPDATAALLPLAYERS, FrontierScrCmd_ClearReceivedTempDataAllPlayers) +ScriptCommand(FRSCRCMD_ENDCOMMUNICATION, FrontierScrCmd_EndCommunication) +ScriptCommand(FRSCRCMD_GETRANDOM, FrontierScrCmd_GetRandom) +ScriptCommand(FRSCRCMD_HEALPARTY, FrontierScrCmd_HealParty) +ScriptCommand(FRSCRCMD_WAITABPRESS, FrontierScrCmd_WaitABPress) +ScriptCommand(FRSCRCMD_WAITABPRESSTIME, FrontierScrCmd_WaitABPressTime) +ScriptCommand(FRSCRCMD_DUMMY3C, FrontierScrCmd_Dummy3C) +ScriptCommand(FRSCRCMD_SETSYSTEMVAR, FrontierScrCmd_SetSystemVar) +ScriptCommand(FRSCRCMD_GETSYSTEMVAR, FrontierScrCmd_GetSystemVar) +ScriptCommand(FRSCRCMD_3F, FrontierScrCmd_3F) +ScriptCommand(FRSCRCMD_GETPLAYEROBJEVENTGFX, FrontierScrCmd_GetPlayerObjEventGfx) +ScriptCommand(FRSCRCMD_INITPARTICLESYSTEM, FrontierScrCmd_InitParticleSystem) +ScriptCommand(FRSCRCMD_FREEPARTICLESYSTEM, FrontierScrCmd_FreeParticleSystem) +ScriptCommand(FRSCRCMD_CREATEPARTICLESYSTEMEMITTER, FrontierScrCmd_CreateParticleSystemEmitter) +ScriptCommand(FRSCRCMD_WAITFORPARTICLESYSTEMEMITTERS, FrontierScrCmd_WaitForParticleSystemEmitters) +ScriptCommand(FRSCRCMD_45, FrontierScrCmd_45) +ScriptCommand(FRSCRCMD_46, FrontierScrCmd_46) +ScriptCommand(FRSCRCMD_47, FrontierScrCmd_47) +ScriptCommand(FRSCRCMD_INCREMENTRECORDVALUE, FrontierScrCmd_IncrementRecordValue) +ScriptCommand(FRSCRCMD_ADDTORECORDVALUE, FrontierScrCmd_AddToRecordValue) +ScriptCommand(FRSCRCMD_INCREMENTTRAINERSCORE, FrontierScrCmd_IncrementTrainerScore) +ScriptCommand(FRSCRCMD_4B, FrontierScrCmd_4B) +ScriptCommand(FRSCRCMD_4C, FrontierScrCmd_4C) +ScriptCommand(FRSCRCMD_4D, FrontierScrCmd_4D) +ScriptCommand(FRSCRCMD_4E, FrontierScrCmd_4E) +ScriptCommand(FRSCRCMD_4F, FrontierScrCmd_4F) +ScriptCommand(FRSCRCMD_SHOWCASTLEPOINTSWINDOWS, FrontierScrCmd_ShowCastlePointsWindows) +ScriptCommand(FRSCRCMD_CLEARCASTLEPOINTSWINDOWS, FrontierScrCmd_ClearCastlePointsWindows) +ScriptCommand(FRSCRCMD_REPRINTCASTLEPOINTSINFO, FrontierScrCmd_ReprintCastlePointsInfo) +ScriptCommand(FRSCRCMD_53, FrontierScrCmd_53) +ScriptCommand(FRSCRCMD_54, FrontierScrCmd_54) +ScriptCommand(FRSCRCMD_PLAYSOUNDEFFECT, FrontierScrCmd_PlaySoundEffect) +ScriptCommand(FRSCRCMD_STOPSOUNDEFFECT, FrontierScrCmd_StopSoundEffect) +ScriptCommand(FRSCRCMD_WAITSOUNDEFFECT, FrontierScrCmd_WaitSoundEffect) +ScriptCommand(FRSCRCMD_PLAYFANFARE, FrontierScrCmd_PlayFanfare) +ScriptCommand(FRSCRCMD_WAITFANFARE, FrontierScrCmd_WaitFanfare) +ScriptCommand(FRSCRCMD_PLAYBGM, FrontierScrCmd_PlayBGM) +ScriptCommand(FRSCRCMD_STOPBGM, FrontierScrCmd_StopBGM) +ScriptCommand(FRSCRCMD_5C, FrontierScrCmd_5C) +ScriptCommand(FRSCRCMD_5D, FrontierScrCmd_5D) +ScriptCommand(FRSCRCMD_5E, FrontierScrCmd_5E) +ScriptCommand(FRSCRCMD_OPENBATTLEFACTORYAPPINITIAL, FrontierScrCmd_OpenBattleFactoryAppInitial) +ScriptCommand(FRSCRCMD_BATTLEFACTORY_CLEANUPBATTLE, FrontierScrCmd_BattleFactory_CleanupBattle) +ScriptCommand(FRSCRCMD_BATTLEFACTORY_STARTBATTLE, FrontierScrCmd_BattleFactory_StartBattle) +ScriptCommand(FRSCRCMD_OPENBATTLEFACTORYAPPFORTRADE, FrontierScrCmd_OpenBattleFactoryAppForTrade) +ScriptCommand(FRSCRCMD_63, FrontierScrCmd_63) +ScriptCommand(FRSCRCMD_64, FrontierScrCmd_64) +ScriptCommand(FRSCRCMD_65, FrontierScrCmd_65) +ScriptCommand(FRSCRCMD_66, FrontierScrCmd_66) +ScriptCommand(FRSCRCMD_CALLBATTLEFACTORYFUNCTION, FrontierScrCmd_CallBattleFactoryFunction) +ScriptCommand(FRSCRCMD_BATTLEFACTORY_CHECKWONBATTLE, FrontierScrCmd_BattleFactory_CheckWonBattle) +ScriptCommand(FRSCRCMD_69, FrontierScrCmd_69) +ScriptCommand(FRSCRCMD_6A, FrontierScrCmd_6A) +ScriptCommand(FRSCRCMD_6B, FrontierScrCmd_6B) +ScriptCommand(FRSCRCMD_INITNEWBATTLERECORDING, FrontierScrCmd_InitNewBattleRecording) +ScriptCommand(FRSCRCMD_6D, FrontierScrCmd_6D) +ScriptCommand(FRSCRCMD_6E, FrontierScrCmd_6E) +ScriptCommand(FRSCRCMD_FREEBATTLERECORDING, FrontierScrCmd_FreeBattleRecording) +ScriptCommand(FRSCRCMD_70, FrontierScrCmd_70) +ScriptCommand(FRSCRCMD_71, FrontierScrCmd_71) +ScriptCommand(FRSCRCMD_72, FrontierScrCmd_72) +ScriptCommand(FRSCRCMD_73, FrontierScrCmd_73) +ScriptCommand(FRSCRCMD_SAVEDATAEXTRAINIT, FrontierScrCmd_SaveDataExtraInit) +ScriptCommand(FRSCRCMD_GETMISCSAVEBLOCKINITFLAG, FrontierScrCmd_GetMiscSaveBlockInitFlag) +ScriptCommand(FRSCRCMD_BATTLEHALL_UPDATEWINRECORD, FrontierScrCmd_BattleHall_UpdateWinRecord) +ScriptCommand(FRSCRCMD_SHOWSAVINGICON, FrontierScrCmd_ShowSavingIcon) +ScriptCommand(FRSCRCMD_HIDESAVINGICON, FrontierScrCmd_HideSavingIcon) +ScriptCommand(FRSCRCMD_BUFFERITEMNAME, FrontierScrCmd_BufferItemName) +ScriptCommand(FRSCRCMD_BUFFERNUMBER, FrontierScrCmd_BufferNumber) +ScriptCommand(FRSCRCMD_BUFFERPLAYERNAME, FrontierScrCmd_BufferPlayerName) +ScriptCommand(FRSCRCMD_BUFFERPARTNERNAME, FrontierScrCmd_BufferPartnerName) +ScriptCommand(FRSCRCMD_BUFFERMOVENAME, FrontierScrCmd_BufferMoveName) +ScriptCommand(FRSCRCMD_BUFFERSPECIESNAME, FrontierScrCmd_BufferSpeciesName) +ScriptCommand(FRSCRCMD_BUFFERTYPENAME, FrontierScrCmd_BufferTypeName) +ScriptCommand(FRSCRCMD_BUFFERRIVALNAME, FrontierScrCmd_BufferRivalName) +ScriptCommand(FRSCRCMD_GETNUMBATTLEPOINTS, FrontierScrCmd_GetNumBattlePoints) +ScriptCommand(FRSCRCMD_GIVEBATTLEPOINTS, FrontierScrCmd_GiveBattlePoints) +ScriptCommand(FRSCRCMD_REMOTEBATTLEPOINTS, FrontierScrCmd_RemoteBattlePoints) +ScriptCommand(FRSCRCMD_CALLBATTLETOWERFUNCTION, FrontierScrCmd_CallBattleTowerFunction) +ScriptCommand(FRSCRCMD_85, FrontierScrCmd_85) +ScriptCommand(FRSCRCMD_FREETOWERSTRUCT, FrontierScrCmd_FreeTowerStruct) +ScriptCommand(FRSCRCMD_BATTLETOWER_STARTBATTLE, FrontierScrCmd_BattleTower_StartBattle) +ScriptCommand(FRSCRCMD_BATTLETOWER_CHECKWONBATTLE, FrontierScrCmd_BattleTower_CheckWonBattle) +ScriptCommand(FRSCRCMD_89, FrontierScrCmd_89) +ScriptCommand(FRSCRCMD_8A, FrontierScrCmd_8A) +ScriptCommand(FRSCRCMD_INITBATTLEHALL, FrontierScrCmd_InitBattleHall) +ScriptCommand(FRSCRCMD_BATTLEHALL_SETUP_NEXT_OPPONENT, FrontierScrCmd_BattleHall_SetupNextOpponent) +ScriptCommand(FRSCRCMD_FREEBATTLEHALL, FrontierScrCmd_FreeBattleHall) +ScriptCommand(FRSCRCMD_OPENBATTLEHALLAPP, FrontierScrCmd_OpenBattleHallApp) +ScriptCommand(FRSCRCMD_BATTLEHALL_CLEANUPBATTLE, FrontierScrCmd_BattleHall_CleanupBattle) +ScriptCommand(FRSCRCMD_BATTLEHALL_STARTBATTLE, FrontierScrCmd_BattleHall_StartBattle) +ScriptCommand(FRSCRCMD_CALLBATTLEHALLFUNCTION, FrontierScrCmd_CallBattleHallFunction) +ScriptCommand(FRSCRCMD_BATTLEHALL_CHECKWONBATTLE, FrontierScrCmd_BattleHall_CheckWonBattle) +ScriptCommand(FRSCRCMD_BATTLEHALL_SENDCOMMMESSAGE, FrontierScrCmd_BattleHall_SendCommMessage) +ScriptCommand(FRSCRCMD_94, FrontierScrCmd_94) +ScriptCommand(FRSCRCMD_BATTLEHALL_PRINTTRAINERINTRO, FrontierScrCmd_BattleHall_PrintTrainerIntro) +ScriptCommand(FRSCRCMD_DUMMY96, FrontierScrCmd_Dummy96) +ScriptCommand(FRSCRCMD_INITBATTLECASTLE, FrontierScrCmd_InitBattleCastle) +ScriptCommand(FRSCRCMD_LOADTRAINERSFORROUND, FrontierScrCmd_LoadTrainersForRound) +ScriptCommand(FRSCRCMD_FREEBATTLECASTLE, FrontierScrCmd_FreeBattleCastle) +ScriptCommand(FRSCRCMD_OPENBATTLECASTLESELFAPP, FrontierScrCmd_OpenBattleCastleSelfApp) +ScriptCommand(FRSCRCMD_BATTLECASTLE_CLEANUPBATTLE, FrontierScrCmd_BattleCastle_CleanupBattle) +ScriptCommand(FRSCRCMD_BATTLECASTLE_STARTBATTLE, FrontierScrCmd_BattleCastle_StartBattle) +ScriptCommand(FRSCRCMD_OPENBATTLECASTLEOPPONENTAPP, FrontierScrCmd_OpenBattleCastleOpponentApp) +ScriptCommand(FRSCRCMD_BATTLECASTLE_SETUPFIRSTOPPONENT, FrontierScrCmd_BattleCastle_SetupFirstOpponent) +ScriptCommand(FRSCRCMD_BATTLECASTLE_SETUPNEXTOPPONENT, FrontierScrCmd_BattleCastle_SetupNextOpponent) +ScriptCommand(FRSCRCMD_CALLBATTLECASTLEFUNCTION, FrontierScrCmd_CallBattleCastleFunction) +ScriptCommand(FRSCRCMD_BATTLECASTLE_CHECKWONBATTLE, FrontierScrCmd_BattleCastle_CheckWonBattle) +ScriptCommand(FRSCRCMD_BATTLECASTLE_SENDCOMMMESSAGE, FrontierScrCmd_BattleCastle_SendCommMessage) +ScriptCommand(FRSCRCMD_BATTLECASTLE_WAITFORCOMMRESPONSES, FrontierScrCmd_BattleCastle_WaitForCommResponses) +ScriptCommand(FRSCRCMD_DUMMYOPENBATTLECASTLEAPP, FrontierScrCmd_DummyOpenBattleCastleApp) +ScriptCommand(FRSCRCMD_A5, FrontierScrCmd_A5) +ScriptCommand(FRSCRCMD_GETCURRENTCASTLEPOINTS, FrontierScrCmd_GetCurrentCastlePoints) +ScriptCommand(FRSCRCMD_SPENDCASTLEPOINTS, FrontierScrCmd_SpendCastlePoints) +ScriptCommand(FRSCRCMD_RECEIVECASTLEPOINTS, FrontierScrCmd_ReceiveCastlePoints) +ScriptCommand(FRSCRCMD_BATTLECASTLE_PRINTRAINERINTRO, FrontierScrCmd_BattleCastle_PrintTrainerIntro) +ScriptCommand(FRSCRCMD_AA, FrontierScrCmd_AA) +ScriptCommand(FRSCRCMD_AB, FrontierScrCmd_AB) +ScriptCommand(FRSCRCMD_AC, FrontierScrCmd_AC) +ScriptCommand(FRSCRCMD_AD, FrontierScrCmd_AD) +ScriptCommand(FRSCRCMD_AE, FrontierScrCmd_AE) +ScriptCommand(FRSCRCMD_AF, FrontierScrCmd_AF) +ScriptCommand(FRSCRCMD_B0, FrontierScrCmd_B0) +ScriptCommand(FRSCRCMD_B1, FrontierScrCmd_B1) +ScriptCommand(FRSCRCMD_B2, FrontierScrCmd_B2) +ScriptCommand(FRSCRCMD_B3, FrontierScrCmd_B3) +ScriptCommand(FRSCRCMD_B4, FrontierScrCmd_B4) +ScriptCommand(FRSCRCMD_B5, FrontierScrCmd_B5) +ScriptCommand(FRSCRCMD_CLEARTOWERSTRUCT, FrontierScrCmd_ClearTowerStruct) +ScriptCommand(FRSCRCMD_SETWIFILISTHOSTFRIENDCURRENTDATE, FrontierScrCmd_SetWiFiListHostFriendCurrentDate) +ScriptCommand(FRSCRCMD_B8, FrontierScrCmd_B8) +ScriptCommand(FRSCRCMD_B9, FrontierScrCmd_B9) +ScriptCommand(FRSCRCMD_BA, FrontierScrCmd_BA) +ScriptCommand(FRSCRCMD_BATTLEARCADE_CLEANUPBATTLE, FrontierScrCmd_BattleArcade_CleanupBattle) +ScriptCommand(FRSCRCMD_BATTLEARCADE_STARTBATTLE, FrontierScrCmd_BattleArcade_StartBattle) +ScriptCommand(FRSCRCMD_BD, FrontierScrCmd_BD) +ScriptCommand(FRSCRCMD_BE, FrontierScrCmd_BE) +ScriptCommand(FRSCRCMD_CALLBATTLEARCADEFUNCTION, FrontierScrCmd_CallBattleArcadeFunction) +ScriptCommand(FRSCRCMD_BATTLEARCADE_CHECKWONBATTLE, FrontierScrCmd_BattleArcade_CheckWonBattle) +ScriptCommand(FRSCRCMD_C1, FrontierScrCmd_C1) +ScriptCommand(FRSCRCMD_C2, FrontierScrCmd_C2) +ScriptCommand(FRSCRCMD_OPENBATTLEARCADEAPP, FrontierScrCmd_OpenBattleArcadeApp) +ScriptCommand(FRSCRCMD_C4, FrontierScrCmd_C4) +ScriptCommand(FRSCRCMD_C5, FrontierScrCmd_C5) +ScriptCommand(FRSCRCMD_C6, FrontierScrCmd_C6) +ScriptCommand(FRSCRCMD_C7, FrontierScrCmd_C7) +ScriptCommand(FRSCRCMD_C8, FrontierScrCmd_C8) +ScriptCommand(FRSCRCMD_C9, FrontierScrCmd_C9) +ScriptCommand(FRSCRCMD_SETMENUXORIGINSIDE, FrontierScrCmd_SetMenuXOriginSide) +ScriptCommand(FRSCRCMD_SETMENUYORIGINSIDE, FrontierScrCmd_SetMenuYOriginSide) // clang-format on diff --git a/include/overlay104/battle_castle.h b/include/overlay104/battle_castle.h new file mode 100644 index 0000000000..d30a4b9eeb --- /dev/null +++ b/include/overlay104/battle_castle.h @@ -0,0 +1,86 @@ +#ifndef POKEPLATINUM_BATTLE_CASTLE_H +#define POKEPLATINUM_BATTLE_CASTLE_H + +#include "applications/frontier/battle_castle/args.h" +#include "overlay104/defs.h" +#include "overlay104/frontier_data_transfer.h" + +#include "battle_castle_save.h" +#include "field_battle_data_transfer.h" +#include "party.h" +#include "savedata.h" + +typedef struct BattleCastle { + int unused; + SaveData *saveData; + BattleCastleSave *castleSave; + FieldBattleDTO *dto; + u8 challengeType; + u8 currentBattle; + u8 monFainted; + u8 seenCastleValetIntro; + u16 currentStreak; + u16 currentRound; + u32 unused2; + int wonBattle; + u16 initialCP; + u16 newCP; + u8 partySlots[3]; + u8 saveStreak; + Party *playersParty; + Party *opponentsParty; + u16 trainerIDs[14]; + FrontierDataDTO opponents[2]; + u16 monSetIDs[4]; + u8 opponentMonIVs[4]; + u32 opponentMonPersonalities[4]; + FrontierPokemonDataDTO opponentMons[4]; + u16 unused3; + u16 savedHeldItems[3]; + u8 appIdentityUnlocked[4]; + u8 levelAdjustments[4]; + u8 appStatsUnlocked[4]; + u8 appMovesUnlocked[4]; + u16 selectedAppSlots[6]; + u16 unused4[4]; + u16 startingPP[4][4]; + u16 unused5[6]; + u16 unk_3C0[40]; + u8 unk_410[512]; + u8 unk_610[2][512]; + u8 unk_A10; + u8 unk_A11; + u16 unk_A12; + u16 unused6; + u16 unk_A16; + u8 unk_A18; + u8 unk_A19; + u8 msgsReceived; + u8 unk_A1B; + u16 partnersCP; + u16 *unk_A20; + u32 unused7; +} BattleCastle; + +BattleCastle *BattleCastle_Init(SaveData *saveData, u16 resumingFromSave, u8 challengeType, u16 partySlot1, u16 partySlot2, u16 partySlot3, u16 *param6); +void BattleCastle_LoadTrainersForRound(BattleCastle *castle, u16 resumingFromSave); +void BattleCastle_Free(BattleCastle *castle); +void BattleCastle_StoreAppResults(BattleCastle *battleCastle, BattleCastleAppArgs *args); +void BattleCastle_Save(BattleCastle *castle, u8 saveType); +u16 BattleCastle_IncrementCurrentBattle(BattleCastle *castle); +u16 BattleCastle_GetCurrentBattle(BattleCastle *castle); +u16 BattleCastle_GetNextOpponentObjectID(BattleCastle *castle, u8 trainerSlot); +void BattleCastle_SaveOnLoss(BattleCastle *castle); +void BattleCastle_SaveOnCompletingRound(BattleCastle *castle); +void BattleCastle_SetupFirstOpponentsParty(BattleCastle *castle); +void BattleCastle_SetupNextOpponentsParty(BattleCastle *castle); +void BattleCastle_PrepForNextBattle(BattleCastle *castle); +int BattleCastle_CalcCPEarnedFromBattle(BattleCastle *castle); +void BattleCastle_ReceiveCastlePoints(SaveData *saveData, u8 challengeType, int newCP); +BOOL BattleCastle_SendCommMessage(BattleCastle *castle, u16 command, u16 arg); +void BattleCastle_ShowPlayerInfoWindows(FrontierScriptManager *scriptMan, BattleCastle *castle); +void BattleCastle_ClearPlayerInfoWindows(FrontierScriptManager *scriptMan, BattleCastle *castle); +void BattleCastle_PrintPlayersInfo(FrontierScriptManager *scriptMan, BattleCastle *castle); +u16 BattleCastle_GetEarnedBP(BattleCastle *castle); + +#endif // POKEPLATINUM_BATTLE_CASTLE_H diff --git a/include/overlay104/battle_castle_helpers.h b/include/overlay104/battle_castle_helpers.h new file mode 100644 index 0000000000..3c83182199 --- /dev/null +++ b/include/overlay104/battle_castle_helpers.h @@ -0,0 +1,30 @@ +#ifndef POKEPLATINUM_BATTLE_CASTLE_HELPERS_H +#define POKEPLATINUM_BATTLE_CASTLE_HELPERS_H + +#include "struct_defs/battle_frontier.h" + +#include "overlay104/battle_castle.h" +#include "overlay104/struct_ov104_02230BE4.h" + +#include "bg_window.h" +#include "field_battle_data_transfer.h" +#include "party.h" + +#define LEVEL_ADJUSTMENT_NONE 0 +#define LEVEL_ADJUSTMENT_UP_5 1 +#define LEVEL_ADJUSTMENT_DOWN_5 2 + +void BattleCastle_PickOpponentTrainers(u8 challengeType, int currentRound, u16 trainerIDs[], u8 numTrainers); +u8 BattleCastle_GetPlayerPartySize(u8 challengeType, BOOL includePartnersMons); +u8 BattleCastle_GetOpponentPartySize(u8 challengeType, BOOL includeBothOpponents); +FieldBattleDTO *BattleCastle_SetupBattle(BattleCastle *battleCastle, FieldFrontierDTO *fieldData); +u8 BattleCastle_GetOpponentLevel(BattleCastle *battleCastle); +BOOL BattleCastle_IsMultiPlayerChallenge(u8 challengeType); +void BattleCastle_RevivePokemon(Party *party); +void BattleCastle_AddMonToParty(BattleCastle *battleCastle, Party *party, Pokemon *mon); +void BattleCastle_SetupOpponentsParty(BattleCastle *battleCastle); +u16 BattleCastle_GetCurrentRound(BattleCastle *battleCastle); +void BattleCastle_UpdateEmblemFrame(BgConfig *bgConfig, BattleCastle *battleCastle, u32 bgLayer); +void BattleCastle_SpendCastlePoints(BattleFrontierSave *frontier, u8 challengeType, int castlePoints); + +#endif // POKEPLATINUM_BATTLE_CASTLE_HELPERS_H diff --git a/include/overlay104/defs.h b/include/overlay104/defs.h index 3d87f8e63f..58063ae1cd 100644 --- a/include/overlay104/defs.h +++ b/include/overlay104/defs.h @@ -97,8 +97,8 @@ struct FrontierScriptManager { u16 *unused3; void *savingIcon; int unused4[10]; - Window *unk_A8; - Window *unk_AC; + Window *castleHostInfoWin; + Window *castlePlayer2InfoWin; u16 unk_B0; u16 unk_B2; u16 unk_B4; diff --git a/include/overlay104/frscrcmd_battle_castle.h b/include/overlay104/frscrcmd_battle_castle.h index 46d9a2ce38..52ad81b331 100644 --- a/include/overlay104/frscrcmd_battle_castle.h +++ b/include/overlay104/frscrcmd_battle_castle.h @@ -3,27 +3,27 @@ #include "overlay104/defs.h" -BOOL FrontierScrCmd_97(FrontierScriptContext *param0); -BOOL FrontierScrCmd_98(FrontierScriptContext *param0); -BOOL FrontierScrCmd_99(FrontierScriptContext *param0); +BOOL FrontierScrCmd_InitBattleCastle(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_LoadTrainersForRound(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_FreeBattleCastle(FrontierScriptContext *param0); BOOL FrontierScrCmd_OpenBattleCastleSelfApp(FrontierScriptContext *ctx); -BOOL FrontierScrCmd_A4(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_DummyOpenBattleCastleApp(FrontierScriptContext *ctx); BOOL FrontierScrCmd_BattleCastle_CleanupBattle(FrontierScriptContext *ctx); BOOL FrontierScrCmd_BattleCastle_StartBattle(FrontierScriptContext *ctx); BOOL FrontierScrCmd_OpenBattleCastleOpponentApp(FrontierScriptContext *ctx); -BOOL FrontierScrCmd_9E(FrontierScriptContext *param0); -BOOL FrontierScrCmd_9F(FrontierScriptContext *param0); +BOOL FrontierScrCmd_BattleCastle_SetupFirstOpponent(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_BattleCastle_SetupNextOpponent(FrontierScriptContext *ctx); BOOL FrontierScrCmd_CallBattleCastleFunction(FrontierScriptContext *ctx); BOOL FrontierScrCmd_BattleCastle_CheckWonBattle(FrontierScriptContext *ctx); -BOOL FrontierScrCmd_A2(FrontierScriptContext *param0); -BOOL FrontierScrCmd_A3(FrontierScriptContext *param0); -BOOL FrontierScrCmd_A5(FrontierScriptContext *param0); -BOOL FrontierScrCmd_50(FrontierScriptContext *param0); -BOOL FrontierScrCmd_51(FrontierScriptContext *param0); -BOOL FrontierScrCmd_52(FrontierScriptContext *param0); -BOOL FrontierScrCmd_A6(FrontierScriptContext *param0); -BOOL FrontierScrCmd_A7(FrontierScriptContext *param0); -BOOL FrontierScrCmd_A8(FrontierScriptContext *param0); -BOOL FrontierScrCmd_A9(FrontierScriptContext *param0); +BOOL FrontierScrCmd_BattleCastle_SendCommMessage(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_BattleCastle_WaitForCommResponses(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_A5(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_ShowCastlePointsWindows(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_ClearCastlePointsWindows(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_ReprintCastlePointsInfo(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_GetCurrentCastlePoints(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_SpendCastlePoints(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_ReceiveCastlePoints(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_BattleCastle_PrintTrainerIntro(FrontierScriptContext *ctx); #endif // POKEPLATINUM_FRSCRCMD_BATTLE_CASTLE_H diff --git a/include/overlay104/ov104_0222DCE0.h b/include/overlay104/ov104_0222DCE0.h index 88c115ba3e..2b4d823d8a 100644 --- a/include/overlay104/ov104_0222DCE0.h +++ b/include/overlay104/ov104_0222DCE0.h @@ -19,7 +19,6 @@ BattleFrontierTrainerData *BattleFrontier_GetTrainerDataFromTrainerIDAndNarcID(u16 battleTowerTrainerID, enum HeapID heapID, enum NarcID narcID); void BattleTower_GetMonDataFromSetIDAndNarcID(BattleFrontierPokemonData *monData, int narcIdx, enum NarcID narcID); BattleFrontierTrainerData *BattleFrontier_GetTrainerData(FrontierTrainerDataDTO *trDataDTO, int battleTowerTrainerID, enum HeapID heapID, enum NarcID narcID); -u32 ov104_0222DD6C(FrontierPokemonDataDTO *param0, u16 narcIdx, u32 otID, u32 param3, u8 ivs, u8 param5, BOOL param6, int heapID, enum NarcID narcID); void FrontierPokemonDataDTO_InitPokemon(const FrontierPokemonDataDTO *pokemonDTO, Pokemon *mon, u8 param2); u16 BattleTower_GetObjectIDFromTrainerClass(u8 trainerClass); void ov104_0222E134(SaveData *saveData, Pokemon *param1); @@ -29,11 +28,10 @@ void BattleCastle_UpdateMonSpritePosition(Sprite *sprite, s16 x, s16 y, u8 isSel u8 BattleCastle_GetPokeIconAnimID(u16 hp, u16 maxHp); void BattleFrontier_LoadTrainer(FrontierDataDTO *opponent, u16 trainerID, enum HeapID heapID, enum NarcID narcID); void FieldBattleDTO_InitFrontierTrainer(FieldBattleDTO *battleDTO, FrontierTrainerDataDTO *trDataDTO, int unused, int battlerId, enum HeapID heapID); -u32 BattleFrontier_LoadOpponentMonData(FrontierPokemonDataDTO *mon, u16 narcIdx, int item, u8 ivs, u32 personality, int heapID, int narcID); -void ov104_0222E330(FrontierPokemonDataDTO *param0, u16 param1[], u8 param2[], u32 param3[], u32 param4[], int param5, int param6, int param7); -u8 ov104_0222E3A8(u16 param0); +u32 BattleFrontier_LoadOpponentMonData(FrontierPokemonDataDTO *frontierMon, u16 narcIdx, int unused, u8 ivs, u32 personality, int heapID, int narcID); +void ov104_0222E330(FrontierPokemonDataDTO *mons, u16 narcIdx[], u8 ivList[], u32 personalities[], u32 resultPersonalities[], int numMons, int heapID, int narcID); BOOL ov104_0222E3E4(BattleFrontierTrainerData *param0, const u16 param1[], const u16 param2[], int param3, int param4, u16 param5[], int param6); -void ov104_0222E4BC(u8 param0, u16 param1, u16 param2, u16 *param3, FrontierPokemonDataDTO *param4, u8 *param5, u32 *param6, u8 param7); +void ov104_0222E4BC(u8 numMons, u16 trainerID, u16 trainerID2, u16 *monSetIDs, FrontierPokemonDataDTO *param4, u8 *ivs, u32 *personalities, u8 isMultiplayerChallenge); void BattleFrontier_SetPartnerInStrTemplate(StringTemplate *template, u32 idx); enum ObjectEventGfx BattleFrontier_GetPlayerObjEventGfx(const TrainerInfo *playerInfo); void BattleFrontier_FlagGeonetLinkInfo(SaveData *saveData); diff --git a/include/overlay104/ov104_0222ECE8.h b/include/overlay104/ov104_0222ECE8.h index f762112206..b3ed099eaf 100644 --- a/include/overlay104/ov104_0222ECE8.h +++ b/include/overlay104/ov104_0222ECE8.h @@ -1,9 +1,9 @@ #ifndef POKEPLATINUM_OV104_0222ECE8_H #define POKEPLATINUM_OV104_0222ECE8_H +#include "overlay104/battle_castle.h" #include "overlay104/battle_hall.h" #include "overlay104/struct_battle_arcade.h" -#include "overlay104/struct_battle_castle.h" #include "overlay104/struct_battle_factory.h" void ov104_0222ECE8(int param0, int param1, void *param2, void *param3); diff --git a/include/overlay104/ov104_022361B4.h b/include/overlay104/ov104_022361B4.h deleted file mode 100644 index 64d5939031..0000000000 --- a/include/overlay104/ov104_022361B4.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef POKEPLATINUM_OV104_022361B4_H -#define POKEPLATINUM_OV104_022361B4_H - -#include "applications/frontier/battle_castle/args.h" -#include "overlay104/defs.h" -#include "overlay104/struct_battle_castle.h" - -#include "savedata.h" - -BattleCastle *ov104_022361B4(SaveData *saveData, u16 param1, u8 param2, u16 param3, u16 param4, u16 param5, u16 *param6); -void ov104_02236514(BattleCastle *param0, u16 param1); -void ov104_022367AC(BattleCastle *param0); -void BattleCastle_StoreAppResults(BattleCastle *battleCastle, BattleCastleAppArgs *args); -void ov104_02236848(BattleCastle *param0, u8 param1); -u16 ov104_02236B48(BattleCastle *param0); -u16 ov104_02236B54(BattleCastle *param0); -u16 ov104_02236B58(BattleCastle *param0, u8 param1); -void ov104_02236B8C(BattleCastle *param0); -void ov104_02236BD0(BattleCastle *param0); -void ov104_02236BF0(BattleCastle *param0); -void ov104_02236BF8(BattleCastle *param0); -void ov104_02236C50(BattleCastle *param0); -int ov104_02236D10(BattleCastle *param0); -void ov104_02236ED8(SaveData *saveData, u8 param1, int param2); -BOOL ov104_02236F70(BattleCastle *param0, u16 param1, u16 param2); -void ov104_02236FC0(FrontierScriptManager *param0, BattleCastle *param1); -void ov104_022370E0(FrontierScriptManager *param0, BattleCastle *param1); -void ov104_02237180(FrontierScriptManager *param0, BattleCastle *param1); -u16 ov104_02237338(BattleCastle *param0); - -#endif // POKEPLATINUM_OV104_022361B4_H diff --git a/include/overlay104/ov104_0223B6F4.h b/include/overlay104/ov104_0223B6F4.h deleted file mode 100644 index 06d998f388..0000000000 --- a/include/overlay104/ov104_0223B6F4.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef POKEPLATINUM_OV104_0223B6F4_H -#define POKEPLATINUM_OV104_0223B6F4_H - -#include "struct_defs/battle_frontier.h" - -#include "overlay104/struct_battle_castle.h" -#include "overlay104/struct_ov104_02230BE4.h" - -#include "bg_window.h" -#include "field_battle_data_transfer.h" -#include "party.h" -#include "pokemon.h" - -void ov104_0223B760(u8 param0, int param1, u16 param2[], u8 param3); -u8 BattleCastle_GetPlayerPartySize(u8 challengeType, BOOL includePartnersMons); -u8 BattleCastle_GetOpponentPartySize(u8 challengeType, BOOL param1); -FieldBattleDTO *FieldBattleDTO_NewBattleCastle(BattleCastle *battleCastle, FieldFrontierDTO *fieldData); -u8 BattleCastle_GetOpponentLevel(BattleCastle *battleCastle); -BOOL BattleCastle_IsMultiPlayerChallenge(u8 challengeType); -void ov104_0223BA24(Party *param0); -void ov104_0223BA7C(BattleCastle *battleCastle, Pokemon *param1); -void ov104_0223BAA0(BattleCastle *battleCastle, Party *param1, Pokemon *param2); -void ov104_0223BAB8(BattleCastle *battleCastle); -u16 ov104_0223BB60(BattleCastle *battleCastle); -void ov104_0223BB84(BgConfig *param0, BattleCastle *battleCastle, u32 param2); -u16 ov104_0223BC24(u16 param0); -void ov104_0223BC2C(BattleFrontierSave *frontier, u8 challengeType, int castlePoints); - -#endif // POKEPLATINUM_OV104_0223B6F4_H diff --git a/include/overlay104/struct_battle_castle.h b/include/overlay104/struct_battle_castle.h deleted file mode 100644 index 86ce4d4580..0000000000 --- a/include/overlay104/struct_battle_castle.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_BATTLE_CASTLE_H -#define POKEPLATINUM_STRUCT_BATTLE_CASTLE_H - -#include "struct_decls/struct_020302DC_decl.h" - -#include "overlay104/frontier_data_transfer.h" - -#include "field_battle_data_transfer.h" -#include "party.h" -#include "savedata.h" - -typedef struct BattleCastle { - int unk_00; - SaveData *saveData; - UnkStruct_020302DC *unk_08; - FieldBattleDTO *dto; - u8 challengeType; - u8 unk_11; - u8 unk_12; - u8 unk_13; - u16 currentStreak; - u16 unk_16; - u32 unk_18; - int wonBattle; - u16 unk_20; - u16 unk_22; - u8 unk_24[3]; - u8 unk_27; - Party *playersParty; - Party *opponentsParty; - u16 trainerIDs[14]; - FrontierDataDTO unk_4C[2]; - u16 unk_26C[4]; - u8 unk_274[4]; - u32 unk_278[4]; - FrontierPokemonDataDTO unk_288[4]; - u16 unk_368; - u16 unk_36A[3]; - u8 appIdentityUnlocked[4]; - u8 appLevelAdjustmentsUnlocked[4]; - u8 appStatsUnlocked[4]; - u8 appMovesUnlocked[4]; - u16 unk_380[6]; - u16 unk_38C[4]; - u16 unk_394[4][4]; - u8 unk_3B4[4]; - u16 unk_3B8[4]; - u16 unk_3C0[40]; - u8 unk_410[512]; - u8 unk_610[2][512]; - u8 unk_A10; - u8 unk_A11; - u16 unk_A12; - u16 unk_A14; - u16 unk_A16; - u8 unk_A18; - u8 unk_A19; - u8 unk_A1A; - u8 unk_A1B; - u16 partnersCP; - u16 *unk_A20; - u32 unk_A24; -} BattleCastle; - -#endif // POKEPLATINUM_STRUCT_BATTLE_CASTLE_H diff --git a/include/pokemon.h b/include/pokemon.h index f08e1b9860..d0a00bd974 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -129,8 +129,8 @@ BOOL BoxPokemon_ExitDecryptionContext(BoxPokemon *boxMon, BOOL encrypt); void Pokemon_InitWith(Pokemon *mon, int monSpecies, int monLevel, int monIVs, BOOL useMonPersonalityParam, u32 monPersonality, int monOTIDSource, u32 monOTID); void sub_02074044(Pokemon *mon, u16 monSpecies, u8 monLevel, u8 monIVs, u8 monNature); -void sub_02074088(Pokemon *mon, u16 monSpecies, u8 monLevel, u8 monIVs, u8 param4, u8 param5, u8 param6); -u32 sub_02074128(u16 monSpecies, u8 param1, u8 param2); +void sub_02074088(Pokemon *mon, u16 monSpecies, u8 monLevel, u8 monIVs, u8 gender, u8 param5, u8 param6); +u32 sub_02074128(u16 monSpecies, u8 gender, u8 param2); void Pokemon_InitAndCalcStats(Pokemon *mon, u16 monSpecies, u8 monLevel, u32 monCombinedIVs, u32 monPersonality); /** @@ -441,7 +441,7 @@ void Pokemon_BuildSpriteTemplateDP(PokemonSpriteTemplate *spriteTemplate, Pokemo * @param face Which face of the Pokemon the player sees * @param preferDP If TRUE, prefer sprites from Diamond/Pearl over Platinum */ -void BoxPokemon_BuildSpriteTemplate(PokemonSpriteTemplate *spriteTemplate, BoxPokemon *boxMon, u8 face, BOOL preferDP); +void BoxPokemon_BuildSpriteTemplate(PokemonSpriteTemplate *spriteTemplate, BoxPokemon *mon, u8 face, BOOL preferDP); /** * @brief Build a PokemonSpriteTemplate for a Pokemon sprite according to the input @@ -676,7 +676,7 @@ int Pokemon_LoadLevelUpMoveIdsOf(int monSpecies, int monForm, u16 *monLevelUpMov void Pokemon_ApplyPokerus(Party *party); u8 Pokemon_HasPokerus(Party *party, u8 param1); -void Party_UpdatePokerusStatus(Party *party, s32 param1); +void Party_UpdatePokerusStatus(Party *party, s32 daysPassed); void Pokemon_ValidatePokerus(Party *party); BOOL Pokemon_InfectedWithPokerus(Pokemon *mon); BOOL Pokemon_HasCuredPokerus(Pokemon *mon); @@ -830,7 +830,7 @@ void PlayCryWithParams(ChatotCry *chatotCry, enum PokemonCryMod cryMod, u16 spec void Species_PlayDelayedCry(ChatotCry *chatotCry, enum PokemonCryMod cryMod, u16 species, int form, int pan, int volume, int forceDefaultChatot, enum HeapID heapID, u8 delay); BOOL Pokemon_PlayCry(Pokemon *mon); void Pokemon_SetCatchData(Pokemon *mon, TrainerInfo *trainerInfo, int monPokeball, int metLocation, int metTerrain, enum HeapID heapID); -void Pokemon_UpdateAfterCatch(Pokemon *mon, TrainerInfo *param1, int monPokeball, int param3, int param4, int param5); +void Pokemon_UpdateAfterCatch(Pokemon *mon, TrainerInfo *trainer, int monPokeball, int metLocation, int metTerrain, int heapID); void Pokemon_GiveHeldItem(Pokemon *mon, u32 battleType, int itemRates); BOOL Pokemon_CanLearnTM(Pokemon *mon, u8 tmID); BOOL CanPokemonFormLearnTM(u16 monSpecies, int monForm, u8 tmID); diff --git a/include/struct_decls/struct_020302DC_decl.h b/include/struct_decls/struct_020302DC_decl.h deleted file mode 100644 index 0ae8a614ce..0000000000 --- a/include/struct_decls/struct_020302DC_decl.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_020302DC_DECL_H -#define POKEPLATINUM_STRUCT_020302DC_DECL_H - -typedef struct UnkStruct_020302DC_t UnkStruct_020302DC; - -#endif // POKEPLATINUM_STRUCT_020302DC_DECL_H diff --git a/include/struct_decls/struct_0203041C_decl.h b/include/struct_decls/struct_0203041C_decl.h deleted file mode 100644 index b445c8ca33..0000000000 --- a/include/struct_decls/struct_0203041C_decl.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_0203041C_DECL_H -#define POKEPLATINUM_STRUCT_0203041C_DECL_H - -typedef struct UnkStruct_0203041C_t UnkStruct_0203041C; - -#endif // POKEPLATINUM_STRUCT_0203041C_DECL_H diff --git a/include/struct_defs/battle_frontier.h b/include/struct_defs/battle_frontier.h index f6b494b21f..eb65a24a1b 100644 --- a/include/struct_defs/battle_frontier.h +++ b/include/struct_defs/battle_frontier.h @@ -6,12 +6,11 @@ #include "struct_defs/struct_0202D080.h" #include "struct_defs/struct_0202FF58.h" #include "struct_defs/struct_020300F4.h" -#include "struct_defs/struct_020302DC.h" -#include "struct_defs/struct_0203041C.h" #include "struct_defs/struct_020304A0.h" #include "struct_defs/struct_020305B8.h" #include "struct_defs/wifi_battle_tower_data.h" +#include "battle_castle_save.h" #include "battle_hall_save.h" #include "wifi_list.h" @@ -26,7 +25,7 @@ typedef struct BattleFrontierSave { WifiBattleTowerSave wifiBattleTowerSave; UnkStruct_0202FF58 unk_8E0_val2; BattleHallSave hallSave; - UnkStruct_020302DC unk_8E0_val4; + BattleCastleSave castleSave; UnkStruct_020304A0 unk_8E0_val5; }; struct { @@ -41,8 +40,8 @@ typedef struct BattleFrontierSave { BattleHallStreakFlags streakFlags; } hall; struct { - UnkStruct_0203041C unk_00; - } unk_161C; + BattleCastlePersistentSave persistentSave; + } castle; struct { UnkStruct_020305B8 unk_00; } unk_1620; diff --git a/include/struct_defs/struct_020302DC.h b/include/struct_defs/struct_020302DC.h deleted file mode 100644 index a2be7ef317..0000000000 --- a/include/struct_defs/struct_020302DC.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_020302DC_H -#define POKEPLATINUM_STRUCT_020302DC_H - -typedef struct UnkStruct_020302DC_t { - u8 unk_00_0 : 3; - u8 unk_00_3 : 1; - u8 unk_00_4 : 4; - u8 unk_01; - u8 unk_02; - u8 unk_03[3]; - u16 unk_06[14]; - u16 unk_22[4]; - u8 unk_2A[4][4]; - u32 unk_3C[4]; - u16 unk_4C[4]; - u16 unk_54[14]; - u16 unk_70; -} UnkStruct_020302DC; - -#endif // POKEPLATINUM_STRUCT_020302DC_H diff --git a/include/struct_defs/struct_0203041C.h b/include/struct_defs/struct_0203041C.h deleted file mode 100644 index 35b2e30f67..0000000000 --- a/include/struct_defs/struct_0203041C.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_0203041C_H -#define POKEPLATINUM_STRUCT_0203041C_H - -typedef struct UnkStruct_0203041C_t { - u8 unk_00; - u8 unk_01; - u8 unk_02[2]; -} UnkStruct_0203041C; - -#endif // POKEPLATINUM_STRUCT_0203041C_H diff --git a/include/unk_020302D0.h b/include/unk_020302D0.h deleted file mode 100644 index cb8e7fb2ee..0000000000 --- a/include/unk_020302D0.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef POKEPLATINUM_UNK_020302D0_H -#define POKEPLATINUM_UNK_020302D0_H - -#include "struct_decls/struct_020302DC_decl.h" -#include "struct_decls/struct_0203041C_decl.h" - -#include "savedata.h" - -void sub_020302D0(UnkStruct_020302DC *param0); -UnkStruct_020302DC *sub_020302DC(SaveData *saveData); -BOOL sub_020302EC(UnkStruct_020302DC *param0); -void sub_020302F4(UnkStruct_020302DC *param0, BOOL param1); -void sub_02030308(UnkStruct_020302DC *param0, u8 param1, u8 param2, u8 param3, const void *param4); -u32 sub_02030398(UnkStruct_020302DC *param0, u8 param1, u8 param2, u8 param3, void *param4); -void sub_02030410(UnkStruct_0203041C *param0); -UnkStruct_0203041C *sub_0203041C(SaveData *saveData); -void sub_02030430(UnkStruct_0203041C *param0, u8 param1, u8 param2, u8 param3, const void *param4); -u32 sub_02030470(UnkStruct_0203041C *param0, u8 param1, u8 param2, u8 param3, void *param4); - -#endif // POKEPLATINUM_UNK_020302D0_H diff --git a/platinum.us/main.lsf b/platinum.us/main.lsf index b8a5db11c5..cf63becc45 100644 --- a/platinum.us/main.lsf +++ b/platinum.us/main.lsf @@ -145,7 +145,7 @@ Static main Object main.nef.p/src_unk_0202F1D4.c.o Object main.nef.p/src_unk_0202FF4C.c.o Object main.nef.p/src_battle_hall_save.c.o - Object main.nef.p/src_unk_020302D0.c.o + Object main.nef.p/src_battle_castle_save.c.o Object main.nef.p/src_unk_02030494.c.o Object main.nef.p/src_battle_frontier_save.c.o Object main.nef.p/src_battle_hall_win_records.c.o @@ -1547,7 +1547,7 @@ Overlay overlay104 Object main.nef.p/src_overlay104_frscrcmd_battle_hall.c.o Object main.nef.p/src_overlay104_battle_hall.c.o Object main.nef.p/src_overlay104_frscrcmd_battle_castle.c.o - Object main.nef.p/src_overlay104_ov104_022361B4.c.o + Object main.nef.p/src_overlay104_battle_castle.c.o Object main.nef.p/src_overlay104_frscrcmd_battle_arcade.c.o Object main.nef.p/src_overlay104_ov104_02237DD8.c.o Object main.nef.p/src_overlay104_frscrcmd_sound.c.o @@ -1558,7 +1558,7 @@ Overlay overlay104 Object main.nef.p/src_overlay104_ov104_0223A0C4.c.o Object main.nef.p/src_overlay104_ov104_0223A7F4.c.o Object main.nef.p/src_overlay104_battle_hall_helpers.c.o - Object main.nef.p/src_overlay104_ov104_0223B6F4.c.o + Object main.nef.p/src_overlay104_battle_castle_helpers.c.o Object main.nef.p/src_overlay104_ov104_0223BCBC.c.o Object main.nef.p/src_overlay104_ov104_0223C164.c.o Object main.nef.p/src_overlay104_frontier_graphics.c.o diff --git a/res/field/frontier_scripts/frontier_scripts_battle_castle.s b/res/field/frontier_scripts/frontier_scripts_battle_castle.s index b9d3510f23..118572192e 100644 --- a/res/field/frontier_scripts/frontier_scripts_battle_castle.s +++ b/res/field/frontier_scripts/frontier_scripts_battle_castle.s @@ -594,7 +594,7 @@ _043C: FrontierScrCmd_24 _0078 FadeScreenIn InitNewBattleRecording - FrontierScrCmd_97 VAR_0x8003, VAR_0x8001, VAR_0x8004, VAR_0x8005, VAR_0x8006, VAR_0x8008 + InitBattleCastle VAR_0x8003, VAR_0x8001, VAR_0x8004, VAR_0x8005, VAR_0x8006, VAR_0x8008 CallBattleCastleFunction BC_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 1, _0480 GoTo _04F0 @@ -611,9 +611,9 @@ _0480: _049C: SetVar VAR_0x8002, 0 - FrontierScrCmd_A2 VAR_0x8002, 0, VAR_0x8008 + BattleCastle_SendCommMessage VAR_0x8002, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _049C - FrontierScrCmd_A3 VAR_0x8002 + BattleCastle_WaitForCommResponses VAR_0x8002 ClearReceivedTempDataAllPlayers GoTo _04F0 End @@ -624,14 +624,14 @@ _04C5: _04CD: SetVar VAR_0x8002, 0 - FrontierScrCmd_A2 VAR_0x8002, 0, VAR_0x8008 + BattleCastle_SendCommMessage VAR_0x8002, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _04CD - FrontierScrCmd_A3 VAR_0x8002 + BattleCastle_WaitForCommResponses VAR_0x8002 ClearReceivedTempDataAllPlayers Return _04F0: - FrontierScrCmd_98 VAR_0x8003 + LoadTrainersForRound VAR_0x8003 CallBattleCastleFunction BC_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 1, _0510 GoTo _058A @@ -646,9 +646,9 @@ _0510: _0520: SetVar VAR_0x8002, 1 - FrontierScrCmd_A2 VAR_0x8002, 0, VAR_0x8008 + BattleCastle_SendCommMessage VAR_0x8002, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _0520 - FrontierScrCmd_A3 VAR_0x8002 + BattleCastle_WaitForCommResponses VAR_0x8002 ClearReceivedTempDataAllPlayers ClearReceivedTempDataAllPlayers SyncConnectedPlayers 125 @@ -659,9 +659,9 @@ _0520: _0555: SetVar VAR_0x8002, 6 - FrontierScrCmd_A2 VAR_0x8002, 0, VAR_0x8008 + BattleCastle_SendCommMessage VAR_0x8002, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _0555 - FrontierScrCmd_A3 VAR_0x8002 + BattleCastle_WaitForCommResponses VAR_0x8002 ClearReceivedTempDataAllPlayers ClearReceivedTempDataAllPlayers SyncConnectedPlayers 210 @@ -691,7 +691,7 @@ _05C6: End _05F0: - CallBattleCastleFunction BC_FUNC_UNK_23, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_GET_CURRENT_BATTLE, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _0612 SetVar VAR_0x8003, 1 GoTo _1349 @@ -700,7 +700,7 @@ _05F0: _0612: CallBattleCastleFunction BC_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 CallIfEq VAR_0x8008, 1, _0630 - FrontierScrCmd_9E + BattleCastle_SetupFirstOpponent GoTo _0679 End @@ -713,19 +713,19 @@ _0630: _0640: SetVar VAR_0x8002, 3 - FrontierScrCmd_A2 VAR_0x8002, 0, VAR_0x8008 + BattleCastle_SendCommMessage VAR_0x8002, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _0640 - FrontierScrCmd_A3 VAR_0x8002 + BattleCastle_WaitForCommResponses VAR_0x8002 ClearReceivedTempDataAllPlayers ClearReceivedTempDataAllPlayers SyncConnectedPlayers 214 ClearReceivedTempDataAllPlayers - CallBattleCastleFunction BC_FUNC_UNK_41, 0, 0, VAR_0x8008 - CallBattleCastleFunction BC_FUNC_UNK_42, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_CREATE_OPPONENT_MONS, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_SETUP_OPPONENTS_PARTY, 0, 0, VAR_0x8008 Return _0679: - CallBattleCastleFunction BC_FUNC_UNK_39, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_CHECK_HAVE_HEARD_DARACHS_INTRO, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _0695 GoTo _06A1 End @@ -742,7 +742,7 @@ _06A1: End _06B0: - CallBattleCastleFunction BC_FUNC_UNK_19, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_GET_CURRENT_ROUND, 0, 0, VAR_0x8008 CallIfEq VAR_0x8008, 3, _06E4 Message BattleCastleScene_Text_Choose CallBattleCastleFunction BC_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 @@ -768,19 +768,19 @@ _06F6: _0706: MessageInstant BattleCastleScene_Text_HealOrRentItem - FrontierScrCmd_50 + ShowCastlePointsWindows GoTo _0714 End _0714: - CallBattleCastleFunction BC_FUNC_UNK_19, 0, 0, VAR_0x8006 + CallBattleCastleFunction BC_FUNC_GET_CURRENT_ROUND, 0, 0, VAR_0x8006 CallIfLt VAR_0x8006, 3, _07A2 CallIfGe VAR_0x8006, 3, _07AC SetMenuXOriginSide 1 AddListMenuEntry BattleCastleScene_Text_SelfOption, BattleCastleScene_Text_HealOrRentItem, 1 AddListMenuEntry BattleCastleScene_Text_OpponentOption, BattleCastleScene_Text_CheckOpponentsMons, 2 AddListMenuEntry BattleCastleScene_Text_BattleOption, BattleCastleScene_Text_BattleTrainer, 4 - CallBattleCastleFunction BC_FUNC_UNK_19, 0, 0, VAR_0x8006 + CallBattleCastleFunction BC_FUNC_GET_CURRENT_ROUND, 0, 0, VAR_0x8006 CallIfGe VAR_0x8006, 3, _07D7 ShowListMenu GoToIfEq VAR_0x8008, 1, _0804 @@ -795,16 +795,16 @@ _07A2: Return _07AC: - CallBattleCastleFunction BC_FUNC_UNK_40, 0, 0, VAR_0x8008 - GoToIfEq VAR_0x8008, 1, _07A2 - GoToIfEq VAR_0x8008, 2, _07A2 + CallBattleCastleFunction BC_FUNC_GET_NEXT_BATTLE_TYPE, 0, 0, VAR_0x8008 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_SILVER, _07A2 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_GOLD, _07A2 InitLocalTextListMenu 31, 9, 0, 0, VAR_0x8008 Return _07D7: - CallBattleCastleFunction BC_FUNC_UNK_40, 0, 0, VAR_0x800D - GoToIfEq VAR_0x800D, 1, _0802 - GoToIfEq VAR_0x800D, 2, _0802 + CallBattleCastleFunction BC_FUNC_GET_NEXT_BATTLE_TYPE, 0, 0, VAR_0x800D + GoToIfEq VAR_0x800D, FRONTIER_NEXT_BATTLE_SILVER, _0802 + GoToIfEq VAR_0x800D, FRONTIER_NEXT_BATTLE_GOLD, _0802 AddListMenuEntry BattleCastleScene_Text_PassOption, BattleCastleScene_Text_PassOnBattle, 5 Return @@ -828,7 +828,7 @@ _0833: CallBattleCastleFunction BC_FUNC_UNK_31, 0, 0, VAR_0x8008 FadeScreenOut CloseMessage - FrontierScrCmd_51 + ClearCastlePointsWindows CallBattleCastleFunction BC_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 CallIfEq VAR_0x8008, 1, _08AC OpenBattleCastleSelfApp @@ -868,7 +868,7 @@ _08E5: CallBattleCastleFunction BC_FUNC_UNK_31, 0, 0, VAR_0x8008 FadeScreenOut CloseMessage - FrontierScrCmd_51 + ClearCastlePointsWindows CallBattleCastleFunction BC_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 CallIfEq VAR_0x8008, 1, _095A OpenBattleCastleOpponentApp @@ -910,7 +910,7 @@ _099C: _09A8: WaitTime 1, VAR_0x8008 - CallBattleCastleFunction BC_FUNC_UNK_29, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_INIT_COMM_MANAGER, 0, 0, VAR_0x8008 WaitTime 1, VAR_0x8008 ClearReceivedTempDataAllPlayers SyncConnectedPlayers 190 @@ -919,7 +919,7 @@ _09A8: _09C5: WaitTime 1, VAR_0x8008 - CallBattleCastleFunction BC_FUNC_UNK_29, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_INIT_COMM_MANAGER, 0, 0, VAR_0x8008 WaitTime 1, VAR_0x8008 ClearReceivedTempDataAllPlayers SyncConnectedPlayers 191 @@ -928,7 +928,7 @@ _09C5: _09E2: WaitTime 1, VAR_0x8008 - CallBattleCastleFunction BC_FUNC_UNK_29, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_INIT_COMM_MANAGER, 0, 0, VAR_0x8008 WaitTime 1, VAR_0x8008 ClearReceivedTempDataAllPlayers SyncConnectedPlayers 192 @@ -937,7 +937,7 @@ _09E2: _09FF: WaitTime 1, VAR_0x8008 - CallBattleCastleFunction BC_FUNC_UNK_29, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_INIT_COMM_MANAGER, 0, 0, VAR_0x8008 WaitTime 1, VAR_0x8008 ClearReceivedTempDataAllPlayers SyncConnectedPlayers 193 @@ -948,8 +948,8 @@ _0A1C: BufferNumber 0, 50 Message BattleCastleScene_Text_ConfirmPurchase ShowYesNoMenu VAR_0x8008, MENU_YES - GoToIfEq VAR_0x8008, 1, _0714 - FrontierScrCmd_A6 VAR_0x8001, VAR_0x8008 + GoToIfEq VAR_0x8008, MENU_NO, _0714 + GetCurrentCastlePoints VAR_0x8001, VAR_0x8008 GoToIfLt VAR_0x8008, 50, _0A6D CallBattleCastleFunction BC_FUNC_UNK_32, 5, 0, VAR_0x8008 CallBattleCastleFunction BC_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 @@ -978,13 +978,13 @@ _0A9B: _0AB8: CallBattleCastleFunction BC_FUNC_GET_CHALLENGE_TYPE, 0, 0, VAR_0x8008 - FrontierScrCmd_A7 VAR_0x8008, 50 + SpendCastlePoints VAR_0x8008, 50 GoTo _0C47 End _0ACD: CloseMessage - FrontierScrCmd_51 + ClearCastlePointsWindows CallBattleCastleFunction BC_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 1, _0B0C ApplyMovement 0, _0248 @@ -1053,14 +1053,14 @@ _0BBA: _0C1E: Call _10CA - CallBattleCastleFunction BC_FUNC_UNK_28, 0, 0, VAR_0x8008 - CallBattleCastleFunction BC_FUNC_UNK_23, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_PREP_FOR_NEXT_BATTLE, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_GET_CURRENT_BATTLE, 0, 0, VAR_0x8008 GoToIfNe VAR_0x8008, 7, _1349 GoTo _12D3 End _0C47: - FrontierScrCmd_51 + ClearCastlePointsWindows CallBattleCastleFunction BC_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 1, _0C7F Message BattleCastleScene_Text_Proceed @@ -1104,9 +1104,9 @@ _0CAD: WaitMovement CreateParticleSystemEmitter 0, CASTLE_EMITTER_TWINKLE GoToIfEq VAR_0x8005, 1, _0E89 - CallBattleCastleFunction BC_FUNC_UNK_40, 0, 0, VAR_0x8008 - GoToIfEq VAR_0x8008, 1, _1A9B - GoToIfEq VAR_0x8008, 2, _1ABA + CallBattleCastleFunction BC_FUNC_GET_NEXT_BATTLE_TYPE, 0, 0, VAR_0x8008 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_SILVER, _1A9B + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_GOLD, _1ABA Call _1B75 BufferNumber 0, VAR_0x8008 Call _0ED1 @@ -1115,8 +1115,8 @@ _0CAD: WaitTime 15, VAR_0x8008 ApplyMovement 98, _0284 WaitMovement - CallBattleCastleFunction BC_FUNC_UNK_37, 0, 0, VAR_0x8008 - FrontierScrCmd_A9 0 + CallBattleCastleFunction BC_FUNC_LOAD_TRAINERS, 0, 0, VAR_0x8008 + BattleCastle_PrintTrainerIntro 0 WaitABPress CloseMessage GoTo _0D9B @@ -1149,14 +1149,14 @@ _0DA3: WaitTime 15, VAR_0x8008 ApplyMovement 98, _0284 WaitMovement - CallBattleCastleFunction BC_FUNC_UNK_37, 0, 0, VAR_0x8008 - FrontierScrCmd_A9 0 + CallBattleCastleFunction BC_FUNC_LOAD_TRAINERS, 0, 0, VAR_0x8008 + BattleCastle_PrintTrainerIntro 0 WaitTime 30, VAR_0x8008 CloseMessage ApplyMovement 99, _0284 WaitMovement - CallBattleCastleFunction BC_FUNC_UNK_37, 0, 0, VAR_0x8008 - FrontierScrCmd_A9 1 + CallBattleCastleFunction BC_FUNC_LOAD_TRAINERS, 0, 0, VAR_0x8008 + BattleCastle_PrintTrainerIntro 1 WaitTime 30, VAR_0x8008 CloseMessage MessageNoSkip BattleCastleScene_Text_PleaseWait @@ -1171,7 +1171,7 @@ _0E64: _0E74: InitParticleSystem 0, battle_castle_spa - CallBattleCastleFunction BC_FUNC_UNK_36, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_UPDATE_EMBLEM_FRAME, 0, 0, VAR_0x8008 GetPlayerObjEventGfx VAR_0x8007 Return @@ -1195,17 +1195,17 @@ _0EAD: End _0ED1: - CallBattleCastleFunction BC_FUNC_UNK_20, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_GET_OPPONENT_OBJECT_ID, 0, 0, VAR_0x8008 SetVar VAR_0x800B, VAR_0x8008 FrontierScrCmd_22 _0154 FrontierScrCmd_24 _0164 Return _0EEC: - CallBattleCastleFunction BC_FUNC_UNK_20, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_GET_OPPONENT_OBJECT_ID, 0, 0, VAR_0x8008 SetVar VAR_0x800B, VAR_0x8008 FrontierScrCmd_22 _0154 - CallBattleCastleFunction BC_FUNC_UNK_20, 1, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_GET_OPPONENT_OBJECT_ID, 1, 0, VAR_0x8008 SetVar VAR_0x800C, VAR_0x8008 FrontierScrCmd_22 _015C FrontierScrCmd_24 _0174 @@ -1221,9 +1221,9 @@ _0F2E: FreeParticleSystem 0 CallBattleCastleFunction BC_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 1, _0F83 - CallBattleCastleFunction BC_FUNC_UNK_40, 0, 0, VAR_0x8008 - GoToIfEq VAR_0x8008, 1, _0F73 - GoToIfEq VAR_0x8008, 2, _0F73 + CallBattleCastleFunction BC_FUNC_GET_NEXT_BATTLE_TYPE, 0, 0, VAR_0x8008 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_SILVER, _0F73 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_GOLD, _0F73 FrontierScrCmd_3F 4 GoTo _0F99 End @@ -1250,16 +1250,16 @@ _0F99: BattleCastle_CleanupBattle InitParticleSystem 0, battle_castle_spa CreateParticleSystemEmitter 0, CASTLE_EMITTER_TWINKLE - CallBattleCastleFunction BC_FUNC_UNK_36, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_UPDATE_EMBLEM_FRAME, 0, 0, VAR_0x8008 FadeScreenIn BattleCastle_CheckWonBattle VAR_0x8008 GoToIfEq VAR_0x8008, 0, _180E IncrementRecordValue RECORD_BATTLE_CASTLE_VICTORIES CallBattleCastleFunction BC_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 1, _1040 - CallBattleCastleFunction BC_FUNC_UNK_40, 0, 0, VAR_0x8008 - GoToIfEq VAR_0x8008, 1, _1AF8 - GoToIfEq VAR_0x8008, 2, _1B2F + CallBattleCastleFunction BC_FUNC_GET_NEXT_BATTLE_TYPE, 0, 0, VAR_0x8008 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_SILVER, _1AF8 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_GOLD, _1B2F Call _1B75 BufferNumber 0, VAR_0x8008 ApplyMovement 98, _0360 @@ -1312,13 +1312,13 @@ _10C2: End _10CA: - CallBattleCastleFunction BC_FUNC_UNK_14, 1, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_INCREMENT_CURRENT_BATTLE, 1, 0, VAR_0x8008 CallBattleCastleFunction BC_FUNC_INCREMENT_CURRENT_STREAK, 0, 0, VAR_0x8008 Return _10DA: BufferPlayerName 1 - CallBattleCastleFunction BC_FUNC_UNK_27, 0, 0, VAR_0x800D + CallBattleCastleFunction BC_FUNC_GET_CP_FROM_BATTLE, 0, 0, VAR_0x800D BufferNumber 0, VAR_0x800D ApplyMovement 5, _03BC WaitMovement @@ -1329,7 +1329,7 @@ _10DA: _110F: CloseMessage - CallBattleCastleFunction BC_FUNC_UNK_28, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_PREP_FOR_NEXT_BATTLE, 0, 0, VAR_0x8008 FrontierScrCmd_22 _00F8 FrontierScrCmd_24 _018C ApplyMovement 6, _03A4 @@ -1390,13 +1390,13 @@ _121C: Return _122A: - CallBattleCastleFunction BC_FUNC_UNK_28, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_PREP_FOR_NEXT_BATTLE, 0, 0, VAR_0x8008 CallBattleCastleFunction BC_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 CallIfEq VAR_0x8008, 1, _04C5 Return _1247: - CallBattleCastleFunction BC_FUNC_UNK_23, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_GET_CURRENT_BATTLE, 0, 0, VAR_0x8008 GoToIfNe VAR_0x8008, 7, _1314 GoTo _1263 End @@ -1424,12 +1424,12 @@ _12C5: End _12D3: - CallBattleCastleFunction BC_FUNC_UNK_22, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_SAVE_ON_COMPLETING_ROUND, 0, 0, VAR_0x8008 SetSystemVar VAR_BATTLE_CASTLE_LOBBY_LOAD_ACTION, 1 BufferPlayerName 0 Message BattleCastleScene_Text_BPEarned BufferPlayerName 0 - CallBattleCastleFunction BC_FUNC_UNK_38, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_GET_EARNED_BP, 0, 0, VAR_0x8008 BufferNumber 1, VAR_0x8008 GiveBattlePoints VAR_0x8008 Message BattleCastleScene_Text_ReceiveBP @@ -1444,7 +1444,7 @@ _130C: _1314: GoToIfEq VAR_0x8005, 1, _1349 - CallBattleCastleFunction BC_FUNC_UNK_25, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_CHECK_IF_MON_FAINTED, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _1349 Message BattleCastleScene_Text_RevivePokemon PlaySoundEffect SEQ_SE_DP_UG_020 @@ -1453,9 +1453,9 @@ _1314: End _1349: - CallBattleCastleFunction BC_FUNC_UNK_40, 0, 0, VAR_0x8008 - GoToIfEq VAR_0x8008, 1, _1A60 - GoToIfEq VAR_0x8008, 2, _1A60 + CallBattleCastleFunction BC_FUNC_GET_NEXT_BATTLE_TYPE, 0, 0, VAR_0x8008 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_SILVER, _1A60 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_GOLD, _1A60 GoTo _1372 End @@ -1464,7 +1464,7 @@ _1372: BufferNumber 0, VAR_0x8008 CallBattleCastleFunction BC_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 1, _13AF - CallBattleCastleFunction BC_FUNC_UNK_23, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_GET_CURRENT_BATTLE, 0, 0, VAR_0x8008 AddVar VAR_0x8008, 1 BufferNumber 0, VAR_0x8008 Message BattleCastleScene_Text_AreYouReady @@ -1478,7 +1478,7 @@ _13AF: ClearReceivedTempDataAllPlayers Call _1B75 BufferNumber 0, VAR_0x8008 - CallBattleCastleFunction BC_FUNC_UNK_23, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_GET_CURRENT_BATTLE, 0, 0, VAR_0x8008 AddVar VAR_0x8008, 1 BufferNumber 0, VAR_0x8008 MessageInstant BattleCastleScene_Text_AreYouReady @@ -1592,9 +1592,9 @@ _15B9: _15C8: SetVar VAR_0x8002, 4 - FrontierScrCmd_A2 VAR_0x8002, 0, VAR_0x8008 + BattleCastle_SendCommMessage VAR_0x8002, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _15C8 - FrontierScrCmd_A3 VAR_0x8002 + BattleCastle_WaitForCommResponses VAR_0x8002 ClearReceivedTempDataAllPlayers CallBattleCastleFunction BC_FUNC_UNK_24, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 1, _160D @@ -1613,7 +1613,7 @@ _160D: _1622: SetVar VAR_0x8003, 0 - FrontierScrCmd_9F + BattleCastle_SetupNextOpponent CallBattleCastleFunction BC_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 CallIfEq VAR_0x8008, 1, _0630 GoTo _0706 @@ -1658,13 +1658,13 @@ _16BF: _16C7: SetVar VAR_0x8003, 1 - CallBattleCastleFunction BC_FUNC_UNK_44, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_UPDATE_CP, 0, 0, VAR_0x8008 MessageInstant BattleCastleScene_Text_Saving CallBattleCastleFunction BC_FUNC_GET_CHALLENGE_TYPE, 0, 0, VAR_0x8008 ShowSavingIcon FrontierScrCmd_6D 4, VAR_0x8008, VAR_0x8009, VAR_0x8009 HideSavingIcon - CallBattleCastleFunction BC_FUNC_UNK_44, 1, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_UPDATE_CP, 1, 0, VAR_0x8008 GoToIfEq VAR_0x8009, 1, _1707 Message BattleCastleScene_Text_VideoSaveFailed Return @@ -1692,9 +1692,9 @@ _1720: _173E: SetSystemVar VAR_BATTLE_CASTLE_LOBBY_LOAD_ACTION, 2 - CallBattleCastleFunction BC_FUNC_UNK_10, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_QUICKSAVE, 0, 0, VAR_0x8008 FreeBattleRecording - FrontierScrCmd_99 + FreeBattleCastle Call _195E FadeScreenOut CloseMessage @@ -1722,7 +1722,7 @@ _17AA: _17B6: SetVar VAR_0x8002, 4 - FrontierScrCmd_A2 VAR_0x8002, 1, VAR_0x8008 + BattleCastle_SendCommMessage VAR_0x8002, 1, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _17B6 GoTo _17D9 End @@ -1737,7 +1737,7 @@ _17D9: End _17F1: - CallBattleCastleFunction BC_FUNC_UNK_21, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_SAVE_ON_LOSS, 0, 0, VAR_0x8008 SetSystemVar VAR_BATTLE_CASTLE_LOBBY_LOAD_ACTION, 3 GoTo _18E4 End @@ -1778,7 +1778,7 @@ _1893: End _189B: - CallBattleCastleFunction BC_FUNC_UNK_21, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_SAVE_ON_LOSS, 0, 0, VAR_0x8008 SetSystemVar VAR_BATTLE_CASTLE_LOBBY_LOAD_ACTION, 3 GoTo _18B0 End @@ -1813,7 +1813,7 @@ _18F4: CallBattleCastleFunction BC_FUNC_GET_CHALLENGE_TYPE, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 3, _1952 FreeBattleRecording - FrontierScrCmd_99 + FreeBattleCastle FrontierScrCmd_02 _1942: @@ -1828,7 +1828,7 @@ _1948: _1952: FreeBattleRecording - FrontierScrCmd_99 + FreeBattleCastle FrontierScrCmd_04 FRONTIER_SCENE_14, 1 End @@ -1843,9 +1843,9 @@ _195E: _1974: SetVar VAR_0x8002, 2 - FrontierScrCmd_A2 VAR_0x8002, 0, VAR_0x8008 + BattleCastle_SendCommMessage VAR_0x8002, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _1974 - FrontierScrCmd_A3 VAR_0x8002 + BattleCastle_WaitForCommResponses VAR_0x8002 ClearReceivedTempDataAllPlayers GoTo _199D End @@ -1889,7 +1889,7 @@ _1A30: _1A60: GoToIfEq VAR_0x8003, 1, _1372 - CallBattleCastleFunction BC_FUNC_UNK_43, 0, 0, VAR_0x8008 + CallBattleCastleFunction BC_FUNC_CHECK_SEEN_VALET_INTRO, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 1, _1372 Call _1B75 BufferNumber 0, VAR_0x8008 diff --git a/res/field/frontier_scripts/frontier_scripts_battle_hall.s b/res/field/frontier_scripts/frontier_scripts_battle_hall.s index 0ee17368bf..c1f45ea285 100644 --- a/res/field/frontier_scripts/frontier_scripts_battle_hall.s +++ b/res/field/frontier_scripts/frontier_scripts_battle_hall.s @@ -643,8 +643,8 @@ _0665: CallIfNe FR_VAR_0x800E, 0, _080D SetVar FR_VAR_0x800E, 1 CallBattleHallFunction BH_FUNC_GET_NEXT_BATTLE_TYPE, 0, 0, VAR_0x8008 - GoToIfEq VAR_0x8008, HALL_NEXT_BATTLE_SILVER, _1199 - GoToIfEq VAR_0x8008, HALL_NEXT_BATTLE_GOLD, _11BE + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_SILVER, _1199 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_GOLD, _11BE Call _13C3 BufferNumber 0, VAR_0x8008 Call _083D @@ -764,8 +764,8 @@ _08A0: CallBattleHallFunction BH_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 1, _08F1 CallBattleHallFunction BH_FUNC_GET_NEXT_BATTLE_TYPE, 0, 0, VAR_0x8008 - GoToIfEq VAR_0x8008, HALL_NEXT_BATTLE_SILVER, _08E1 - GoToIfEq VAR_0x8008, HALL_NEXT_BATTLE_GOLD, _08E1 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_SILVER, _08E1 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_GOLD, _08E1 FrontierScrCmd_3F 1 GoTo _0907 End @@ -800,8 +800,8 @@ _0907: CallBattleHallFunction BH_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 1, _09E3 CallBattleHallFunction BH_FUNC_GET_NEXT_BATTLE_TYPE, 0, 0, VAR_0x8008 - GoToIfEq VAR_0x8008, HALL_NEXT_BATTLE_SILVER, _1333 - GoToIfEq VAR_0x8008, HALL_NEXT_BATTLE_GOLD, _137B + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_SILVER, _1333 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_GOLD, _137B Call _13C3 BufferNumber 0, VAR_0x8008 InitParticleSystem 0, battle_hall_spa diff --git a/res/text/battle_castle_self_app.json b/res/text/battle_castle_self_app.json index 285d7de047..81998502a4 100644 --- a/res/text/battle_castle_self_app.json +++ b/res/text/battle_castle_self_app.json @@ -2,7 +2,7 @@ "key": 14690, "messages": [ { - "id": "pl_msg_00000199_00000", + "id": "BattleCastleSelfApp_Text_PlayerName", "en_US": "{STRVAR_1 3, 0, 0}" }, { diff --git a/src/applications/frontier/battle_castle/opponent_app.c b/src/applications/frontier/battle_castle/opponent_app.c index 0dd341016b..bdf1a2de4a 100644 --- a/src/applications/frontier/battle_castle/opponent_app.c +++ b/src/applications/frontier/battle_castle/opponent_app.c @@ -5,8 +5,6 @@ #include "constants/graphics.h" -#include "struct_decls/struct_020302DC_decl.h" -#include "struct_decls/struct_0203041C_decl.h" #include "struct_defs/battle_frontier.h" #include "applications/frontier/battle_castle/args.h" @@ -14,9 +12,10 @@ #include "applications/frontier/battle_castle/sprite_manager.h" #include "applications/frontier/battle_castle/sprites.h" #include "applications/frontier/battle_castle/windows.h" +#include "overlay104/battle_castle_helpers.h" #include "overlay104/ov104_0222DCE0.h" -#include "overlay104/ov104_0223B6F4.h" +#include "battle_castle_save.h" #include "battle_frontier_save.h" #include "battle_frontier_stats.h" #include "bg_window.h" @@ -53,7 +52,6 @@ #include "system.h" #include "text.h" #include "trainer_info.h" -#include "unk_020302D0.h" #include "unk_020363E8.h" #include "unk_0209BA80.h" #include "vram_transfer.h" @@ -65,10 +63,6 @@ FS_EXTERN_OVERLAY(overlay104); #define NUM_MONS_MAX 4 -#define LEVEL_ADJUSTMENT_NONE 0 -#define LEVEL_ADJUSTMENT_UP_5 1 -#define LEVEL_ADJUSTMENT_DOWN_5 2 - #define CP_COST_CHECK_IDENTITY 1 #define CP_COST_LEVEL_UP 1 #define CP_COST_LEVEL_DOWN 15 @@ -160,8 +154,8 @@ typedef struct BattleCastleOpponentApp { FontSpecialCharsContext *specialChars; Options *options; SaveData *saveData; - UnkStruct_020302DC *unk_150; - UnkStruct_0203041C *unk_154; + BattleCastleSave *castleSave; + BattleCastlePersistentSave *persistentSave; BattleCastleAppSpriteManager spriteMan; BattleCastleAppSprite *monSprites[NUM_MONS_MAX]; BattleCastleAppSprite *ballSprites[NUM_MONS_MAX]; @@ -302,14 +296,14 @@ BOOL BattleCastleOpponentApp_Init(ApplicationManager *appMan, int *state) BattleCastleAppArgs *args = ApplicationManager_Args(appMan); app->saveData = args->saveData; - app->unk_150 = sub_020302DC(app->saveData); - app->unk_154 = sub_0203041C(app->saveData); + app->castleSave = BattleCastleSave_Get(app->saveData); + app->persistentSave = BattleCastlePersistentSave_Get(app->saveData); app->challengeType = args->challengeType; app->selectedMonSlotPtr = &args->selectedMonSlot; app->options = SaveData_GetOptions(app->saveData); app->opponentsParty = args->opponentsParty; app->identityUnlockedForSlot = &args->identityUnlocked[0]; - app->levelAdjustmentForSlot = &args->levelAdjustmentUnlocked[0]; + app->levelAdjustmentForSlot = &args->levelAdjustments[0]; app->statsUnlockedForSlot = &args->statsUnlocked[0]; app->movesUnlockedForSlot = &args->movesUnlocked[0]; app->slotID = 0xff; @@ -633,7 +627,7 @@ static BOOL State_MainAppFlow(BattleCastleOpponentApp *app) } if (!BattleCastle_IsMultiPlayerChallenge(app->challengeType)) { - ov104_0223BC2C(app->frontier, app->challengeType, CP_COST_CHECK_IDENTITY); + BattleCastle_SpendCastlePoints(app->frontier, app->challengeType, CP_COST_CHECK_IDENTITY); PrintPlayersAndPartnersCastlePoints(app, &app->windows[OPPONENT_APP_WINDOW_HEADER]); RevealPokemonInSlot(app, app->selectedMonSlot); app->subState = MAIN_SUBSTATE_UPDATE_AFTER_OPTION_PURCHASE; @@ -717,7 +711,7 @@ static BOOL State_MainAppFlow(BattleCastleOpponentApp *app) if (!BattleCastle_IsMultiPlayerChallenge(app->challengeType)) { CloseMessageBox(&app->windows[OPPONENT_APP_WINDOW_MSG_BOX]); - ov104_0223BC2C(app->frontier, app->challengeType, GetCostOfLevelAdjustment(app->levelAdjustment)); + BattleCastle_SpendCastlePoints(app->frontier, app->challengeType, GetCostOfLevelAdjustment(app->levelAdjustment)); PrintPlayersAndPartnersCastlePoints(app, &app->windows[OPPONENT_APP_WINDOW_HEADER]); UpdateLevelAdjustment(app, app->selectedMonSlot, app->levelAdjustment); app->subState = MAIN_SUBSTATE_UPDATE_AFTER_OPTION_PURCHASE; @@ -2635,7 +2629,7 @@ static void SpendCastlePointsInSync(BattleCastleOpponentApp *app, u8 slotID, u8 if (CommSys_CurNetId() == 0) { if (slotID < exitSlot) { SetStringTemplatePlayerName(app, 5); - ov104_0223BC2C(app->frontier, app->challengeType, cost); + BattleCastle_SpendCastlePoints(app->frontier, app->challengeType, cost); } else { BattleCastleApp_SetPartnerName(app->strTemplate, 5); app->partnersCP -= cost; @@ -2646,7 +2640,7 @@ static void SpendCastlePointsInSync(BattleCastleOpponentApp *app, u8 slotID, u8 app->partnersCP -= cost; } else { SetStringTemplatePlayerName(app, 5); - ov104_0223BC2C(app->frontier, app->challengeType, cost); + BattleCastle_SpendCastlePoints(app->frontier, app->challengeType, cost); } } @@ -2785,7 +2779,7 @@ static BOOL TryToBuySummaryScreen(BattleCastleOpponentApp *app, u16 cost, u16 fa if (!BattleCastle_IsMultiPlayerChallenge(app->challengeType)) { CloseMessageBox(&app->windows[OPPONENT_APP_WINDOW_MSG_BOX]); - ov104_0223BC2C(app->frontier, app->challengeType, cost); + BattleCastle_SpendCastlePoints(app->frontier, app->challengeType, cost); PrintPlayersAndPartnersCastlePoints(app, &app->windows[OPPONENT_APP_WINDOW_HEADER]); if (cost == CP_COST_SHOW_STATS) { @@ -2830,7 +2824,7 @@ static void IncreaseRank(BattleCastleOpponentApp *app, u8 slot, u8 menuOption) SetStringTemplatePlayerName(app, 5); rank = BattleCastleApp_GetRank(app->saveData, app->challengeType, rankType); - ov104_0223BC2C(app->frontier, app->challengeType, CP_COST_RANK_UP); + BattleCastle_SpendCastlePoints(app->frontier, app->challengeType, CP_COST_RANK_UP); rank = BattleCastleApp_GetRank(app->saveData, app->challengeType, rankType); BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(app->saveData), BattleFrontierStats_GetCastleRankIndex(app->challengeType, rankType), rank + 1); @@ -2854,7 +2848,7 @@ static void IncreaseRank(BattleCastleOpponentApp *app, u8 slot, u8 menuOption) SetStringTemplatePlayerName(app, 5); rank = BattleCastleApp_GetRank(app->saveData, app->challengeType, rankType); - ov104_0223BC2C(app->frontier, app->challengeType, CP_COST_RANK_UP); + BattleCastle_SpendCastlePoints(app->frontier, app->challengeType, CP_COST_RANK_UP); rank = BattleCastleApp_GetRank(app->saveData, app->challengeType, rankType); BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(app->saveData), BattleFrontierStats_GetCastleRankIndex(app->challengeType, rankType), rank + 1); diff --git a/src/applications/frontier/battle_castle/self_app.c b/src/applications/frontier/battle_castle/self_app.c index 5e26f7c03c..276d2c0f7e 100644 --- a/src/applications/frontier/battle_castle/self_app.c +++ b/src/applications/frontier/battle_castle/self_app.c @@ -3,8 +3,6 @@ #include #include -#include "struct_decls/struct_020302DC_decl.h" -#include "struct_decls/struct_0203041C_decl.h" #include "struct_defs/battle_frontier.h" #include "applications/frontier/battle_castle/args.h" @@ -12,9 +10,10 @@ #include "applications/frontier/battle_castle/sprite_manager.h" #include "applications/frontier/battle_castle/sprites.h" #include "applications/frontier/battle_castle/windows.h" +#include "overlay104/battle_castle_helpers.h" #include "overlay104/ov104_0222DCE0.h" -#include "overlay104/ov104_0223B6F4.h" +#include "battle_castle_save.h" #include "battle_frontier_save.h" #include "battle_frontier_stats.h" #include "bg_window.h" @@ -53,7 +52,6 @@ #include "system.h" #include "text.h" #include "trainer_info.h" -#include "unk_020302D0.h" #include "unk_020363E8.h" #include "unk_0208C098.h" #include "unk_0209BA80.h" @@ -302,8 +300,8 @@ typedef struct BattleCastleSelfApp { FontSpecialCharsContext *specialChars; Options *options; SaveData *saveData; - UnkStruct_020302DC *unk_1D0; - UnkStruct_0203041C *unk_1D4; + BattleCastleSave *castleSave; + BattleCastlePersistentSave *persistentSave; BattleCastleAppSpriteManager spriteMan; BattleCastleAppSprite *upArrowSprite; BattleCastleAppSprite *downArrowSprite; @@ -508,8 +506,8 @@ BOOL BattleCastleSelfApp_Init(ApplicationManager *appMan, int *state) BattleCastleAppArgs *args = ApplicationManager_Args(appMan); app->saveData = args->saveData; - app->unk_1D0 = sub_020302DC(app->saveData); - app->unk_1D4 = sub_0203041C(app->saveData); + app->castleSave = BattleCastleSave_Get(app->saveData); + app->persistentSave = BattleCastlePersistentSave_Get(app->saveData); app->challengeType = args->challengeType; app->selectedMonSlotPtr = &args->selectedMonSlot; app->options = SaveData_GetOptions(app->saveData); @@ -911,7 +909,7 @@ static BOOL State_MainAppFlow(BattleCastleSelfApp *app) CloseMessageBox(&app->windows[SELF_APP_WINDOW_MSG_BOX]); if (!BattleCastle_IsMultiPlayerChallenge(app->challengeType)) { - ov104_0223BC2C(app->frontier, app->challengeType, sHealingCosts[app->selectedMenuEntry - 1]); + BattleCastle_SpendCastlePoints(app->frontier, app->challengeType, sHealingCosts[app->selectedMenuEntry - 1]); PrintPlayersAndPartnersCastlePoints(app, &app->windows[SELF_APP_WINDOW_HEADER]); HealPokemon(app, app->selectedMonSlot, app->selectedMenuEntry); app->subState = MAIN_SUBSTATE_UPDATE_AFTER_PURCHASE; @@ -1098,7 +1096,7 @@ static BOOL State_MainAppFlow(BattleCastleSelfApp *app) if (!BattleCastle_IsMultiPlayerChallenge(app->challengeType)) { FreeItemSelect(app); BattleCastleApp_DrawMessageBox(&app->windows[SELF_APP_WINDOW_MSG_BOX], Options_Frame(app->options)); - ov104_0223BC2C(app->frontier, app->challengeType, GetItemPriceFromListPos(app, app->menuPos, app->selectedMenuEntry)); + BattleCastle_SpendCastlePoints(app->frontier, app->challengeType, GetItemPriceFromListPos(app, app->menuPos, app->selectedMenuEntry)); PrintPlayersAndPartnersCastlePoints(app, &app->windows[SELF_APP_WINDOW_HEADER]); RentItem(app, app->selectedMonSlot, GetItemIDFromListPos(app, app->menuPos, app->selectedMenuEntry)); app->subState = MAIN_SUBSTATE_UPDATE_AFTER_PURCHASE; @@ -1211,7 +1209,7 @@ static BOOL State_MainAppFlow(BattleCastleSelfApp *app) if (!BattleCastle_IsMultiPlayerChallenge(app->challengeType)) { FreeItemSelect(app); BattleCastleApp_DrawMessageBox(&app->windows[SELF_APP_WINDOW_MSG_BOX], Options_Frame(app->options)); - ov104_0223BC2C(app->frontier, app->challengeType, GetItemPriceFromListPos(app, app->menuPos, app->selectedMenuEntry)); + BattleCastle_SpendCastlePoints(app->frontier, app->challengeType, GetItemPriceFromListPos(app, app->menuPos, app->selectedMenuEntry)); PrintPlayersAndPartnersCastlePoints(app, &app->windows[SELF_APP_WINDOW_HEADER]); RentItem(app, app->selectedMonSlot, GetItemIDFromListPos(app, app->menuPos, app->selectedMenuEntry)); app->subState = MAIN_SUBSTATE_UPDATE_AFTER_PURCHASE; @@ -3369,7 +3367,7 @@ static void SpendCastlePointsInSync(BattleCastleSelfApp *app, u8 slotID, u8 menu if (CommSys_CurNetId() == 0) { if (slotID < exitSlot) { SetStringTemplatePlayerName(app, 5); - ov104_0223BC2C(app->frontier, app->challengeType, cost); + BattleCastle_SpendCastlePoints(app->frontier, app->challengeType, cost); } else { BattleCastleApp_SetPartnerName(app->strTemplate, 5); app->partnersCP -= cost; @@ -3380,7 +3378,7 @@ static void SpendCastlePointsInSync(BattleCastleSelfApp *app, u8 slotID, u8 menu app->partnersCP -= cost; } else { SetStringTemplatePlayerName(app, 5); - ov104_0223BC2C(app->frontier, app->challengeType, cost); + BattleCastle_SpendCastlePoints(app->frontier, app->challengeType, cost); } } @@ -3487,7 +3485,7 @@ static void IncreaseRank(BattleCastleSelfApp *app, u8 slot, u8 menuOption) SetStringTemplatePlayerName(app, 5); rank = BattleCastleApp_GetRank(app->saveData, app->challengeType, rankType); - ov104_0223BC2C(app->frontier, app->challengeType, sRankUpCosts[rankType][rank]); + BattleCastle_SpendCastlePoints(app->frontier, app->challengeType, sRankUpCosts[rankType][rank]); rank = BattleCastleApp_GetRank(app->saveData, app->challengeType, rankType); BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(app->saveData), BattleFrontierStats_GetCastleRankIndex(app->challengeType, rankType), rank + 1); @@ -3515,7 +3513,7 @@ static void IncreaseRank(BattleCastleSelfApp *app, u8 slot, u8 menuOption) SetStringTemplatePlayerName(app, 5); rank = BattleCastleApp_GetRank(app->saveData, app->challengeType, rankType); - ov104_0223BC2C(app->frontier, app->challengeType, sRankUpCosts[rankType][rank]); + BattleCastle_SpendCastlePoints(app->frontier, app->challengeType, sRankUpCosts[rankType][rank]); rank = BattleCastleApp_GetRank(app->saveData, app->challengeType, rankType); BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(app->saveData), BattleFrontierStats_GetCastleRankIndex(app->challengeType, rankType), rank + 1); diff --git a/src/applications/frontier/records/main.c b/src/applications/frontier/records/main.c index e1a82d429d..82ba72a122 100644 --- a/src/applications/frontier/records/main.c +++ b/src/applications/frontier/records/main.c @@ -11,6 +11,7 @@ #include "applications/frontier/records/windows.h" +#include "battle_castle_save.h" #include "battle_frontier_save.h" #include "battle_frontier_stats.h" #include "battle_hall_win_records.h" @@ -33,7 +34,6 @@ #include "system.h" #include "text.h" #include "unk_0202FF4C.h" -#include "unk_020302D0.h" #include "unk_02030494.h" #include "wifi_battle_tower_save.h" @@ -679,7 +679,7 @@ static u32 GetBattleCastleLatestStreakEntryID(FrontierRecordsApp *app) if (app->challengeType == FRONTIER_CHALLENGE_MULTI_WFC) { isActive = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(app->saveData), STAT_CASTLE_WFC_STREAK_ACTIVE); } else { - isActive = sub_02030470(sub_0203041C(app->saveData), 9, app->challengeType, 0, NULL); + isActive = BattleCastlePersistentSave_GetFlag(BattleCastlePersistentSave_Get(app->saveData), 9, app->challengeType, 0, NULL); } if (isActive == 1) { diff --git a/src/battle_castle_save.c b/src/battle_castle_save.c new file mode 100644 index 0000000000..ce157aba29 --- /dev/null +++ b/src/battle_castle_save.c @@ -0,0 +1,139 @@ +#include "battle_castle_save.h" + +#include + +#include "struct_defs/battle_frontier.h" + +#include "savedata.h" + +void BattleCastleSave_Init(BattleCastleSave *castleSave) +{ + MI_CpuClear8(castleSave, sizeof(BattleCastleSave)); +} + +BattleCastleSave *BattleCastleSave_Get(SaveData *saveData) +{ + BattleFrontierSave *frontier = SaveData_SaveTable(saveData, SAVE_TABLE_ENTRY_FRONTIER); + return &frontier->castleSave; +} + +BOOL BattleCastleSave_HasSaved(BattleCastleSave *save) +{ + return save->didSave; +} + +void BattleCastleSave_RecordSave(BattleCastleSave *save, BOOL didSave) +{ + save->didSave = didSave; +} + +void BattleCastleSave_SetMember(BattleCastleSave *save, u8 field, u8 index, u8 index2, void *value) +{ + switch (field) { + case CASTLE_SAVE_CHALLENGE_TYPE: + save->challengeType = *(u8 *)value; + break; + case CASTLE_SAVE_CURRENT_BATTLE: + save->currentBattleNum = *(u8 *)value; + break; + case CASTLE_SAVE_MON_HP: + save->monHP[index] = *(u16 *)value; + break; + case CASTLE_SAVE_MON_PP: + save->monPP[index][index2] = *(u8 *)value; + break; + case CASTLE_SAVE_MON_STATUS: + save->monStatus[index] = *(u32 *)value; + break; + case CASTLE_SAVE_HELD_ITEMS: + save->heldItems[index] = *(u16 *)value; + break; + case CASTLE_SAVE_TRAINER_IDS: + save->trainerIDs[index] = *(u16 *)value; + break; + case CASTLE_SAVE_PARTY_SLOTS: + save->partySlots[index] = *(u8 *)value; + break; + case CASTLE_SAVE_MON_SET_IDS: + save->monSetIDs[index] = *(u16 *)value; + break; + default: + GF_ASSERT(FALSE); + break; + } +} + +u32 BattleCastleSave_GetMember(BattleCastleSave *svae, u8 field, u8 index, u8 unused, void *unused2) +{ + switch (field) { + case CASTLE_SAVE_CHALLENGE_TYPE: + return svae->challengeType; + case CASTLE_SAVE_CURRENT_BATTLE: + return svae->currentBattleNum; + case CASTLE_SAVE_MON_HP: + return svae->monHP[index]; + case CASTLE_SAVE_MON_PP: + return svae->monPP[index][unused]; + case CASTLE_SAVE_MON_STATUS: + return svae->monStatus[index]; + case CASTLE_SAVE_HELD_ITEMS: + return svae->heldItems[index]; + case CASTLE_SAVE_TRAINER_IDS: + return svae->trainerIDs[index]; + case CASTLE_SAVE_PARTY_SLOTS: + return svae->partySlots[index]; + case CASTLE_SAVE_MON_SET_IDS: + return svae->monSetIDs[index]; + default: + GF_ASSERT(FALSE); + break; + } + + return 0; +} + +void BattleCastlePersistentSave_Init(BattleCastlePersistentSave *save) +{ + MI_CpuClear8(save, sizeof(BattleCastlePersistentSave)); +} + +BattleCastlePersistentSave *BattleCastlePersistentSave_Get(SaveData *saveData) +{ + BattleFrontierSave *frontier = SaveData_SaveTable(saveData, SAVE_TABLE_ENTRY_FRONTIER); + return &frontier->castle.persistentSave; +} + +void BattleCastlePersistentSave_SetFlag(BattleCastlePersistentSave *save, u8 field, u8 challengeType, u8 unused, u8 *value) +{ + u8 *value_dupe = (u8 *)value; + switch (field) { + case CASTLE_SAVE_STREAK_FLAGS: + if (*value_dupe >= 1) { + save->streakActiveFlags |= 1 << challengeType; + } else { + save->streakActiveFlags &= 0xff ^ (1 << challengeType); + } + break; + case CASTLE_SAVE_HAVE_HEARD_INTRO: + save->haveHeardIntro = TRUE; + break; + default: + GF_ASSERT(FALSE); + break; + } +} + +u32 BattleCastlePersistentSave_GetFlag(BattleCastlePersistentSave *save, u8 field, u8 challengeType, u8 unused, void *unused2) +{ + switch (field) { + case CASTLE_SAVE_STREAK_FLAGS: + return (save->streakActiveFlags >> challengeType) & 0x1; + case CASTLE_SAVE_HAVE_HEARD_INTRO: + return save->haveHeardIntro; + default: + GF_ASSERT(FALSE); + break; + } + + return 0; +} diff --git a/src/battle_frontier_save.c b/src/battle_frontier_save.c index a7409a8603..b6898de3ce 100644 --- a/src/battle_frontier_save.c +++ b/src/battle_frontier_save.c @@ -4,10 +4,10 @@ #include "struct_defs/battle_frontier.h" +#include "battle_castle_save.h" #include "battle_hall_save.h" #include "savedata.h" #include "unk_0202FF4C.h" -#include "unk_020302D0.h" #include "unk_02030494.h" #include "wifi_battle_tower_save.h" #include "wifi_list.h" @@ -26,7 +26,7 @@ void BattleFrontier_Init(BattleFrontierSave *frontier) WifiBattleTowerDownloadData_Init(&frontier->unk_950.wifiBattleTowerDownloadData); sub_020300A4(&frontier->unk_1614.unk_00); BattleHallStreakFlags_Init(&frontier->hall.streakFlags); - sub_02030410(&frontier->unk_161C.unk_00); + BattleCastlePersistentSave_Init(&frontier->castle.persistentSave); sub_020305AC(&frontier->unk_1620.unk_00); } diff --git a/src/game_records.c b/src/game_records.c index 2794b3281b..f7274314a3 100644 --- a/src/game_records.c +++ b/src/game_records.c @@ -152,7 +152,7 @@ static u8 sUsesHighLimit[MAX_RECORDS] = { [RECORD_BATTLE_HALL_VICTORIES] = TRUE, [RECORD_BATTLE_ARCADE_VICTORIES] = TRUE, [RECORD_UNK_064] = TRUE, - [RECORD_UNK_065] = TRUE, + [RECORD_CASTLE_POINTS_RECEIVED] = TRUE, [RECORD_UNK_066] = TRUE, [RECORD_UNK_067] = TRUE, [RECORD_BATTLE_POINTS_RECEIVED] = TRUE, diff --git a/src/meson.build b/src/meson.build index 43f4f9609c..7c561f1b09 100644 --- a/src/meson.build +++ b/src/meson.build @@ -134,7 +134,7 @@ pokeplatinum_c = files( 'unk_0202F1D4.c', 'unk_0202FF4C.c', 'battle_hall_save.c', - 'unk_020302D0.c', + 'battle_castle_save.c', 'unk_02030494.c', 'battle_frontier_save.c', 'battle_hall_win_records.c', @@ -931,7 +931,7 @@ pokeplatinum_c = files( 'overlay104/frscrcmd_battle_hall.c', 'overlay104/battle_hall.c', 'overlay104/frscrcmd_battle_castle.c', - 'overlay104/ov104_022361B4.c', + 'overlay104/battle_castle.c', 'overlay104/frscrcmd_battle_arcade.c', 'overlay104/ov104_02237DD8.c', 'overlay104/frscrcmd_sound.c', @@ -942,7 +942,7 @@ pokeplatinum_c = files( 'overlay104/ov104_0223A0C4.c', 'overlay104/ov104_0223A7F4.c', 'overlay104/battle_hall_helpers.c', - 'overlay104/ov104_0223B6F4.c', + 'overlay104/battle_castle_helpers.c', 'overlay104/ov104_0223BCBC.c', 'overlay104/ov104_0223C164.c', 'overlay104/frontier_graphics.c', diff --git a/src/overlay104/battle_castle.c b/src/overlay104/battle_castle.c new file mode 100644 index 0000000000..3b7249e9b9 --- /dev/null +++ b/src/overlay104/battle_castle.c @@ -0,0 +1,735 @@ +#include "overlay104/battle_castle.h" + +#include + +#include "constants/heap.h" +#include "constants/moves.h" +#include "generated/game_records.h" + +#include "struct_defs/battle_frontier.h" + +#include "applications/frontier/battle_castle/args.h" +#include "global/utility.h" +#include "overlay104/battle_castle_helpers.h" +#include "overlay104/defs.h" +#include "overlay104/frontier_script_manager.h" +#include "overlay104/ov104_0222DCE0.h" +#include "overlay104/ov104_0222ECE8.h" + +#include "battle_castle_save.h" +#include "battle_frontier_save.h" +#include "battle_frontier_stats.h" +#include "bg_window.h" +#include "communication_information.h" +#include "communication_system.h" +#include "game_records.h" +#include "heap.h" +#include "message.h" +#include "party.h" +#include "pokemon.h" +#include "render_window.h" +#include "save_player.h" +#include "savedata.h" +#include "string_gf.h" +#include "string_template.h" +#include "system_vars.h" +#include "text.h" +#include "trainer_info.h" +#include "vars_flags.h" + +#include "res/text/bank/battle_castle_self_app.h" + +static void SelectTrainersAndFirstBattlesMons(BattleCastle *castle); +static void LoadTrainersAndMonsFromSave(BattleCastle *castle); +static void LoadPlayersPartyFromSave(BattleCastle *castle); +static u16 GetBattleCastleAppSelectedSlot(BattleCastleAppArgs *args, u8 i); +static void DrawPlayerInfoWindow(BgConfig *bgConfig, Window *window); +static void PrintPlayerNameandCP(FrontierScriptManager *scriptMan, Window *window, TrainerInfo *trainer, u16 castlePoints); + +BattleCastle *BattleCastle_Init(SaveData *saveData, u16 resumingFromSave, u8 challengeType, u16 partySlot1, u16 partySlot2, u16 partySlot3, u16 *param6) +{ + static BattleCastle *castle; + castle = Heap_Alloc(HEAP_ID_FIELD2, sizeof(BattleCastle)); + + MI_CpuClear8(castle, sizeof(BattleCastle)); + + castle->castleSave = BattleCastleSave_Get(saveData); + castle->saveData = saveData; + castle->unused = 11; + castle->playersParty = Party_New(HEAP_ID_FIELD2); + castle->opponentsParty = Party_New(HEAP_ID_FIELD2); + castle->unk_A20 = param6; + + BattleCastleSave *castleSave = castle->castleSave; + BattleCastlePersistentSave *persistentSave = BattleCastlePersistentSave_Get(saveData); + + if (!resumingFromSave) { + castle->challengeType = challengeType; + castle->currentBattle = 0; + + BattleCastleSave_Init(castleSave); + + u8 streakActive; + if (castle->challengeType == FRONTIER_CHALLENGE_MULTI_WFC) { + streakActive = SystemVars_GetWiFiFrontierCleared(SaveData_GetVarsFlags(castle->saveData)); + } else { + streakActive = BattleCastlePersistentSave_GetFlag(persistentSave, CASTLE_SAVE_STREAK_FLAGS, castle->challengeType, 0, NULL); + } + + if (streakActive == TRUE) { + castle->currentStreak = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(castle->saveData), BattleFrontierStats_GetCastleLatestStreakIndex(castle->challengeType)); + } else { + castle->currentStreak = 0; + + BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(castle->saveData), BattleFrontierStats_GetCastleLatestCPIndex(castle->challengeType), 0); + BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(castle->saveData), BattleFrontierStats_GetCastleSpentCPIndex(challengeType), 0); + + for (u16 rank = 0; rank < BATTLE_CASTLE_NUM_RANK_TYPES; rank++) { + BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(castle->saveData), BattleFrontierStats_GetCastleRankIndex(castle->challengeType, rank), 1); + } + } + + castle->currentRound = castle->currentStreak / CASTLE_BATTLES_PER_ROUND; + castle->unused2 = 0; + castle->partySlots[0] = partySlot1; + castle->partySlots[1] = partySlot2; + castle->partySlots[2] = partySlot3; + castle->initialCP = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(castle->saveData), BattleFrontierStats_GetCastleLatestCPIndex(castle->challengeType)); + + BattleFrontierSave_AddToStat(SaveData_GetBattleFrontier(castle->saveData), BattleFrontierStats_GetCastleLatestCPIndex(castle->challengeType), BattleFrontierStats_GetHostFriendIdx(BattleFrontierStats_GetCastleLatestCPIndex(castle->challengeType)), 10); + } else { + castle->challengeType = BattleCastleSave_GetMember(castleSave, CASTLE_SAVE_CHALLENGE_TYPE, 0, 0, NULL); + castle->currentBattle = BattleCastleSave_GetMember(castleSave, CASTLE_SAVE_CURRENT_BATTLE, 0, 0, NULL); + castle->currentStreak = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(castle->saveData), BattleFrontierStats_GetCastleLatestStreakIndex(castle->challengeType)); + castle->currentRound = castle->currentStreak / CASTLE_BATTLES_PER_ROUND; + + for (u16 i = 0; i < CASTLE_PARTY_SIZE_SOLO; i++) { + castle->partySlots[i] = BattleCastleSave_GetMember(castleSave, CASTLE_SAVE_PARTY_SLOTS, i, 0, NULL); + } + } + + for (u16 i = 0; i < CASTLE_PARTY_SIZE_SOLO; i++) { + Pokemon *mon = Party_GetPokemonBySlotIndex(SaveData_GetParty(castle->saveData), castle->partySlots[i]); + castle->savedHeldItems[i] = Pokemon_GetValue(mon, MON_DATA_HELD_ITEM, NULL); + } + + Party *fieldParty = SaveData_GetParty(castle->saveData); + u8 partySize = BattleCastle_GetPlayerPartySize(castle->challengeType, 0); + + for (u16 i = 0; i < partySize; i++) { + Party_AddPokemon(castle->playersParty, Party_GetPokemonBySlotIndex(fieldParty, castle->partySlots[i])); + + Pokemon *mon = Party_GetPokemonBySlotIndex(castle->playersParty, i); + + u32 noItem = ITEM_NONE; + Pokemon_SetValue(mon, MON_DATA_HELD_ITEM, &noItem); + + if (Pokemon_GetValue(mon, MON_DATA_LEVEL, NULL) > CASTLE_MAX_LEVEL) { + u32 exp = Pokemon_GetSpeciesBaseExpAt(Pokemon_GetValue(mon, MON_DATA_SPECIES, NULL), CASTLE_MAX_LEVEL); + Pokemon_SetValue(mon, MON_DATA_EXPERIENCE, &exp); + Pokemon_CalcLevelAndStats(mon); + } + } + + if (BattleCastle_IsMultiPlayerChallenge(castle->challengeType) == TRUE) { + BattleFrontier_FlagGeonetLinkInfo(castle->saveData); + } + + return castle; +} + +void BattleCastle_LoadTrainersForRound(BattleCastle *castle, u16 resumingFromSave) +{ + if (!resumingFromSave) { + SelectTrainersAndFirstBattlesMons(castle); + } else { + LoadTrainersAndMonsFromSave(castle); + } +} + +static void SelectTrainersAndFirstBattlesMons(BattleCastle *castle) +{ + u8 partySize = Party_GetCurrentCount(castle->playersParty); + + for (int i = 0; i < partySize; i++) { + Pokemon *mon = Party_GetPokemonBySlotIndex(castle->playersParty, i); + + castle->startingPP[i][0] = Pokemon_GetValue(mon, MON_DATA_MOVE1_PP, NULL); + castle->startingPP[i][1] = Pokemon_GetValue(mon, MON_DATA_MOVE2_PP, NULL); + castle->startingPP[i][2] = Pokemon_GetValue(mon, MON_DATA_MOVE3_PP, NULL); + castle->startingPP[i][3] = Pokemon_GetValue(mon, MON_DATA_MOVE4_PP, NULL); + } + + BattleCastle_PickOpponentTrainers(castle->challengeType, BattleCastle_GetCurrentRound(castle), castle->trainerIDs, CASTLE_BATTLES_PER_ROUND * 2); + + ov104_0222E4BC(BattleCastle_GetOpponentPartySize(castle->challengeType, TRUE), castle->trainerIDs[castle->currentBattle], castle->trainerIDs[castle->currentBattle + CASTLE_BATTLES_PER_ROUND], castle->monSetIDs, castle->opponentMons, castle->opponentMonIVs, castle->opponentMonPersonalities, BattleCastle_IsMultiPlayerChallenge(castle->challengeType)); +} + +static void LoadTrainersAndMonsFromSave(BattleCastle *castle) +{ + FrontierPokemonDataDTO mons[MAX_PARTY_SIZE]; + u8 ivs[MAX_PARTY_SIZE]; + u16 setIDs[MAX_PARTY_SIZE]; + u32 personalities[MAX_PARTY_SIZE]; + + LoadPlayersPartyFromSave(castle); + + for (int i = 0; i < CASTLE_BATTLES_PER_ROUND * 2; i++) { + castle->trainerIDs[i] = BattleCastleSave_GetMember(castle->castleSave, CASTLE_SAVE_TRAINER_IDS, i, 0, NULL); + } + + for (int i = 0; i < CASTLE_PARTY_SIZE_MULTI * 2; i++) { + setIDs[i] = BattleCastleSave_GetMember(castle->castleSave, CASTLE_SAVE_MON_SET_IDS, i, 0, NULL); + castle->monSetIDs[i] = setIDs[i]; + } + + ov104_0222E330(mons, setIDs, ivs, NULL, personalities, 4, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); + + Pokemon *mon = Pokemon_New(HEAP_ID_FIELD2); + for (int i = 0; i < CASTLE_PARTY_SIZE_MULTI * 2; i++) { + FrontierPokemonDataDTO_InitPokemon(&mons[i], mon, BattleCastle_GetOpponentLevel(castle)); + BattleCastle_AddMonToParty(castle, castle->opponentsParty, mon); + } + + Heap_Free(mon); +} + +static void LoadPlayersPartyFromSave(BattleCastle *castle) +{ + u32 u32Ptr; + u16 u16Ptr; + u8 u8Ptr; + + u8 partySize = Party_GetCurrentCount(castle->playersParty); + + for (int i = 0; i < partySize; i++) { + Pokemon *mon = Party_GetPokemonBySlotIndex(castle->playersParty, i); + + u16Ptr = BattleCastleSave_GetMember(castle->castleSave, CASTLE_SAVE_MON_HP, i, 0, NULL); + Pokemon_SetValue(mon, MON_DATA_HP, &u16Ptr); + + u8Ptr = BattleCastleSave_GetMember(castle->castleSave, CASTLE_SAVE_MON_PP, i, 0, NULL); + Pokemon_SetValue(mon, MON_DATA_MOVE1_PP, &u8Ptr); + + u8Ptr = BattleCastleSave_GetMember(castle->castleSave, CASTLE_SAVE_MON_PP, i, 1, NULL); + Pokemon_SetValue(mon, MON_DATA_MOVE2_PP, &u8Ptr); + + u8Ptr = BattleCastleSave_GetMember(castle->castleSave, CASTLE_SAVE_MON_PP, i, 2, NULL); + Pokemon_SetValue(mon, MON_DATA_MOVE3_PP, &u8Ptr); + + u8Ptr = BattleCastleSave_GetMember(castle->castleSave, CASTLE_SAVE_MON_PP, i, 3, NULL); + Pokemon_SetValue(mon, MON_DATA_MOVE4_PP, &u8Ptr); + + u32Ptr = BattleCastleSave_GetMember(castle->castleSave, CASTLE_SAVE_MON_STATUS, i, 0, NULL); + Pokemon_SetValue(mon, MON_DATA_STATUS, &u32Ptr); + + u16Ptr = BattleCastleSave_GetMember(castle->castleSave, CASTLE_SAVE_HELD_ITEMS, i, 0, NULL); + Pokemon_SetValue(mon, MON_DATA_HELD_ITEM, &u16Ptr); + } +} + +void BattleCastle_Free(BattleCastle *castle) +{ + if (castle == NULL) { + return; + } + + if (castle->playersParty != NULL) { + Heap_Free(castle->playersParty); + } + + if (castle->opponentsParty != NULL) { + Heap_Free(castle->opponentsParty); + } + + MI_CpuClear8(castle, sizeof(BattleCastle)); + Heap_Free(castle); + + castle = NULL; +} + +void BattleCastle_StoreAppResults(BattleCastle *battleCastle, BattleCastleAppArgs *args) +{ + for (int i = 0; i < 6; i++) { + battleCastle->selectedAppSlots[i] = GetBattleCastleAppSelectedSlot(args, i); + } + + for (int i = 0; i < CASTLE_PARTY_SIZE_MULTI * 2; i++) { + battleCastle->appIdentityUnlocked[i] = args->identityUnlocked[i]; + battleCastle->levelAdjustments[i] = args->levelAdjustments[i]; + battleCastle->appStatsUnlocked[i] = args->statsUnlocked[i]; + battleCastle->appMovesUnlocked[i] = args->movesUnlocked[i]; + } + + battleCastle->partnersCP = args->partnersCP; +} + +static u16 GetBattleCastleAppSelectedSlot(BattleCastleAppArgs *args, u8 i) +{ + if (i >= MAX_PARTY_SIZE) { + GF_ASSERT(FALSE); + return 0; + } + + return args->selectedMonSlot; +} + +void BattleCastle_Save(BattleCastle *castle, u8 saveType) +{ + u8 u8Ptr[4]; + u16 u16Ptr[4]; + u32 u32Ptr[4]; + u32 partySize; + BattleCastleSave *castleSave = castle->castleSave; + BattleCastlePersistentSave *persistentSave = BattleCastlePersistentSave_Get(castle->saveData); + + BattleFrontierSave *frontier = SaveData_GetBattleFrontier(castle->saveData); + UNUSED(BattleCastle_GetOpponentPartySize(castle->challengeType, TRUE)); + + *u8Ptr = castle->challengeType; + BattleCastleSave_SetMember(castle->castleSave, CASTLE_SAVE_CHALLENGE_TYPE, 0, 0, u8Ptr); + BattleCastleSave_RecordSave(castle->castleSave, TRUE); + + *u8Ptr = castle->currentBattle; + + BattleCastleSave_SetMember(castle->castleSave, CASTLE_SAVE_CURRENT_BATTLE, 0, 0, u8Ptr); + BattleFrontierSave_SetStatAutoHostIdx(frontier, BattleFrontierStats_GetCastleLatestStreakIndex(castle->challengeType), castle->currentStreak); + + if (saveType != 2) { + u16 recordStreak = BattleFrontierSave_GetStatAutoHostIdx(frontier, BattleFrontierStats_GetCastleRecordStreakIndex(castle->challengeType)); + BattleFrontierSave_SetIfBetterAutoHostIdx(frontier, BattleFrontierStats_GetCastleRecordStreakIndex(castle->challengeType), castle->currentStreak); + u16 newRecord = BattleFrontierSave_GetStatAutoHostIdx(frontier, BattleFrontierStats_GetCastleRecordStreakIndex(castle->challengeType)); + u32 latestStreak = BattleFrontierSave_GetStatAutoHostIdx(frontier, BattleFrontierStats_GetCastleLatestCPIndex(castle->challengeType)); + + if (castle->currentStreak == recordStreak) { + BattleFrontierSave_SetIfBetterAutoHostIdx(frontier, BattleFrontierStats_GetCastleRecordCPIndex(castle->challengeType), latestStreak); + } else if (recordStreak < newRecord) { + BattleFrontierSave_SetStatAutoHostIdx(frontier, BattleFrontierStats_GetCastleRecordCPIndex(castle->challengeType), latestStreak); + } + + *u8Ptr = castle->saveStreak; + BattleCastlePersistentSave_SetFlag(persistentSave, CASTLE_SAVE_STREAK_FLAGS, castle->challengeType, 0, u8Ptr); + + if (castle->challengeType == FRONTIER_CHALLENGE_MULTI_WFC) { + BattleFrontierSave_SetStatAutoHostIdx(frontier, STAT_CASTLE_WFC_STREAK_ACTIVE, castle->saveStreak); + } + } + + for (u16 i = 0; i < CASTLE_BATTLES_PER_ROUND * 2; i++) { + *u16Ptr = castle->trainerIDs[i]; + BattleCastleSave_SetMember(castle->castleSave, CASTLE_SAVE_TRAINER_IDS, i, 0, u16Ptr); + } + + for (u16 i = 0; i < CASTLE_PARTY_SIZE_SOLO; i++) { + *u8Ptr = castle->partySlots[i]; + BattleCastleSave_SetMember(castle->castleSave, CASTLE_SAVE_PARTY_SLOTS, i, 0, u8Ptr); + } + + partySize = Party_GetCurrentCount(castle->playersParty); + + for (u16 i = 0; i < partySize; i++) { + Pokemon *mon = Party_GetPokemonBySlotIndex(castle->playersParty, i); + + *u16Ptr = Pokemon_GetValue(mon, MON_DATA_HP, NULL); + BattleCastleSave_SetMember(castle->castleSave, CASTLE_SAVE_MON_HP, i, 0, u16Ptr); + + *u8Ptr = Pokemon_GetValue(mon, MON_DATA_MOVE1_PP, NULL); + BattleCastleSave_SetMember(castle->castleSave, CASTLE_SAVE_MON_PP, i, 0, u8Ptr); + + *u8Ptr = Pokemon_GetValue(mon, MON_DATA_MOVE2_PP, NULL); + BattleCastleSave_SetMember(castle->castleSave, CASTLE_SAVE_MON_PP, i, 1, u8Ptr); + + *u8Ptr = Pokemon_GetValue(mon, MON_DATA_MOVE3_PP, NULL); + BattleCastleSave_SetMember(castle->castleSave, CASTLE_SAVE_MON_PP, i, 2, u8Ptr); + + *u8Ptr = Pokemon_GetValue(mon, MON_DATA_MOVE4_PP, NULL); + BattleCastleSave_SetMember(castle->castleSave, CASTLE_SAVE_MON_PP, i, 3, u8Ptr); + + *u32Ptr = Pokemon_GetValue(mon, MON_DATA_STATUS, NULL); + BattleCastleSave_SetMember(castle->castleSave, CASTLE_SAVE_MON_STATUS, i, 0, u32Ptr); + + *u16Ptr = Pokemon_GetValue(mon, MON_DATA_HELD_ITEM, NULL); + BattleCastleSave_SetMember(castle->castleSave, CASTLE_SAVE_HELD_ITEMS, i, 0, u16Ptr); + } + + partySize = Party_GetCurrentCount(castle->opponentsParty); + + for (u16 i = 0; i < partySize; i++) { + UNUSED(Party_GetPokemonBySlotIndex(castle->opponentsParty, i)); + *u16Ptr = castle->monSetIDs[i]; + + BattleCastleSave_SetMember(castle->castleSave, CASTLE_SAVE_MON_SET_IDS, i, 0, u16Ptr); + } +} + +u16 BattleCastle_IncrementCurrentBattle(BattleCastle *castle) +{ + castle->currentBattle++; + return castle->currentBattle; +} + +u16 BattleCastle_GetCurrentBattle(BattleCastle *castle) +{ + return castle->currentBattle; +} + +u16 BattleCastle_GetNextOpponentObjectID(BattleCastle *castle, u8 trainerSlot) +{ + FrontierTrainerDataDTO trainer; + u8 offset = castle->currentBattle + (trainerSlot * CASTLE_BATTLES_PER_ROUND); + + Heap_Free(BattleFrontier_GetTrainerData(&trainer, castle->trainerIDs[offset], HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR)); + + return BattleTower_GetObjectIDFromTrainerClass(trainer.trainerType); +} + +void BattleCastle_SaveOnLoss(BattleCastle *castle) +{ + for (int i = 0; i < BATTLE_CASTLE_NUM_RANK_TYPES; i++) { + BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(castle->saveData), BattleFrontierStats_GetCastleRankIndex(castle->challengeType, i), 1); + } + + BattleCastle_Save(castle, 1); +} + +void BattleCastle_SaveOnCompletingRound(BattleCastle *castle) +{ + castle->saveStreak = TRUE; + + if (castle->currentRound < CASTLE_MAX_DISTINCT_ROUNDS) { + castle->currentRound++; + } + + castle->currentBattle = 0; + BattleCastle_Save(castle, 0); +} + +void BattleCastle_SetupFirstOpponentsParty(BattleCastle *castle) +{ + BattleCastle_SetupOpponentsParty(castle); +} + +void BattleCastle_SetupNextOpponentsParty(BattleCastle *castle) +{ + ov104_0222E4BC(BattleCastle_GetOpponentPartySize(castle->challengeType, TRUE), castle->trainerIDs[castle->currentBattle], castle->trainerIDs[castle->currentBattle + CASTLE_BATTLES_PER_ROUND], castle->monSetIDs, castle->opponentMons, castle->opponentMonIVs, castle->opponentMonPersonalities, BattleCastle_IsMultiPlayerChallenge(castle->challengeType)); + + BattleCastle_SetupOpponentsParty(castle); +} + +void BattleCastle_PrepForNextBattle(BattleCastle *castle) +{ + u8 partyOffset, playerPartySize; + + if (CommSys_CurNetId() == 0) { + partyOffset = 0; + } else { + partyOffset = CASTLE_PARTY_SIZE_MULTI; + } + + playerPartySize = BattleCastle_GetPlayerPartySize(castle->challengeType, FALSE); + UNUSED(Party_GetCurrentCount(castle->playersParty)); + + for (int i = partyOffset; i < (playerPartySize + partyOffset); i++) { + Pokemon *mon = Party_GetPokemonBySlotIndex(castle->playersParty, i); + + castle->startingPP[i - partyOffset][0] = Pokemon_GetValue(mon, MON_DATA_MOVE1_PP, NULL); + castle->startingPP[i - partyOffset][1] = Pokemon_GetValue(mon, MON_DATA_MOVE2_PP, NULL); + castle->startingPP[i - partyOffset][2] = Pokemon_GetValue(mon, MON_DATA_MOVE3_PP, NULL); + castle->startingPP[i - partyOffset][3] = Pokemon_GetValue(mon, MON_DATA_MOVE4_PP, NULL); + } + + BattleCastle_RevivePokemon(castle->playersParty); + + for (int i = 0; i < CASTLE_PARTY_SIZE_MULTI * 2; i++) { + castle->appIdentityUnlocked[i] = FALSE; + castle->levelAdjustments[i] = LEVEL_ADJUSTMENT_NONE; + castle->appStatsUnlocked[i] = FALSE; + castle->appMovesUnlocked[i] = FALSE; + } +} + +int BattleCastle_CalcCPEarnedFromBattle(BattleCastle *castle) +{ + int i, j; + u8 cpFactors[20]; + int earnedCP = 0; + + for (i = 0; i < 20; i++) { + cpFactors[i] = 0; + } + + castle->monFainted = FALSE; + int remainingPP = 0; + + u8 partyOffset; + if (CommSys_CurNetId() == 0) { + partyOffset = 0; + } else { + partyOffset = CASTLE_PARTY_SIZE_MULTI; + } + + u8 playerPartySize = BattleCastle_GetPlayerPartySize(castle->challengeType, FALSE); + u8 opponentPartySize = BattleCastle_GetOpponentPartySize(castle->challengeType, TRUE); + + for (i = partyOffset; i < playerPartySize + partyOffset; i++) { + Pokemon *mon = Party_GetPokemonBySlotIndex(castle->playersParty, i); + + if (Pokemon_GetValue(mon, MON_DATA_SPECIES_EXISTS, NULL) == 0) { + continue; + } + + u32 currentHP = Pokemon_GetValue(mon, MON_DATA_HP, NULL); + u32 maxHP = Pokemon_GetValue(mon, MON_DATA_MAX_HP, NULL); + + if (currentHP > 0) { + cpFactors[0]++; + + if (currentHP == maxHP) { + cpFactors[1]++; + } else { + if (currentHP >= maxHP / 2) { + cpFactors[2]++; + } else { + cpFactors[3]++; + } + } + + if (Pokemon_GetValue(mon, MON_DATA_STATUS, NULL) == 0) { + cpFactors[4]++; + } + } else { + castle->monFainted = TRUE; + } + + remainingPP += Pokemon_GetValue(mon, MON_DATA_MOVE1_PP, NULL); + remainingPP += Pokemon_GetValue(mon, MON_DATA_MOVE2_PP, NULL); + remainingPP += Pokemon_GetValue(mon, MON_DATA_MOVE3_PP, NULL); + remainingPP += Pokemon_GetValue(mon, MON_DATA_MOVE4_PP, NULL); + } + + for (i = 0; i < opponentPartySize; i++) { + if (castle->levelAdjustments[i] == LEVEL_ADJUSTMENT_UP_5) { + cpFactors[8]++; + } + } + + int startingPP = 0; + + for (i = 0; i < playerPartySize; i++) { + for (j = 0; j < LEARNED_MOVES_MAX; j++) { + startingPP += castle->startingPP[i][j]; + } + } + + if (startingPP - remainingPP <= 5) { + cpFactors[5]++; + } else if (startingPP - remainingPP <= 10) { + cpFactors[6]++; + } else if (startingPP - remainingPP <= 15) { + cpFactors[7]++; + } + + earnedCP += cpFactors[0] * 3; + earnedCP += cpFactors[1] * 3; + earnedCP += cpFactors[2] * 2; + earnedCP += cpFactors[3] * 1; + earnedCP += cpFactors[4] * 1; + earnedCP += cpFactors[5] * 8; + earnedCP += cpFactors[6] * 6; + earnedCP += cpFactors[7] * 4; + earnedCP += cpFactors[8] * 7; + + if (earnedCP <= 0) { + earnedCP = 1; + } + + return earnedCP; +} + +void BattleCastle_ReceiveCastlePoints(SaveData *saveData, u8 challengeType, int newCP) +{ + u16 currentCP = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(saveData), BattleFrontierStats_GetCastleLatestCPIndex(challengeType)); + + if (currentCP + newCP > 9999) { + BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(saveData), BattleFrontierStats_GetCastleLatestCPIndex(challengeType), 9999); + } else { + BattleFrontierSave_AddToStat(SaveData_GetBattleFrontier(saveData), BattleFrontierStats_GetCastleLatestCPIndex(challengeType), BattleFrontierStats_GetHostFriendIdx(BattleFrontierStats_GetCastleLatestCPIndex(challengeType)), newCP); + } + + GameRecords_AddToRecordValue(SaveData_GetGameRecords(saveData), RECORD_CASTLE_POINTS_RECEIVED, newCP); +} + +BOOL BattleCastle_SendCommMessage(BattleCastle *castle, u16 command, u16 arg) +{ + int success; + + switch (command) { + case 0: + success = ov104_0222F3B8(castle); + break; + case 1: + success = ov104_0222F44C(castle); + break; + case 2: + success = ov104_0222F4B8(castle); + break; + case 3: + success = ov104_0222F5D4(castle); + break; + case 4: + success = ov104_0222F6C8(castle, arg); + break; + case 5: + success = ov104_0222F710(castle, arg); + break; + case 6: + success = ov104_0222F758(castle); + break; + } + + return success; +} + +void BattleCastle_ShowPlayerInfoWindows(FrontierScriptManager *scriptMan, BattleCastle *castle) +{ + FrontierGraphics *graphics = FrontierScriptManager_GetGraphics(scriptMan); + + GF_ASSERT(scriptMan->castleHostInfoWin == NULL); + GF_ASSERT(scriptMan->castlePlayer2InfoWin == NULL); + + if (!BattleCastle_IsMultiPlayerChallenge(castle->challengeType)) { + scriptMan->castleHostInfoWin = Window_New(HEAP_ID_FIELD2, 1); + Window_Add(graphics->bgConfig, scriptMan->castleHostInfoWin, 1, 1, 1, 10, 4, 14, ((((1024 - (18 + 12)) - 9) - (27 * 4)) - (11 * 22)) - (10 * 4)); + DrawPlayerInfoWindow(graphics->bgConfig, scriptMan->castleHostInfoWin); + } else { + scriptMan->castleHostInfoWin = Window_New(HEAP_ID_FIELD2, 1); + scriptMan->castlePlayer2InfoWin = Window_New(HEAP_ID_FIELD2, 1); + + Window_Add(graphics->bgConfig, scriptMan->castleHostInfoWin, 1, 1, 1, 10, 4, 14, ((((1024 - (18 + 12)) - 9) - (27 * 4)) - (11 * 22)) - (10 * 4)); + Window_Add(graphics->bgConfig, scriptMan->castlePlayer2InfoWin, 1, 21, 1, 10, 4, 14, (((((1024 - (18 + 12)) - 9) - (27 * 4)) - (11 * 22)) - (10 * 4)) - (10 * 4)); + + DrawPlayerInfoWindow(graphics->bgConfig, scriptMan->castleHostInfoWin); + DrawPlayerInfoWindow(graphics->bgConfig, scriptMan->castlePlayer2InfoWin); + } + + BattleCastle_PrintPlayersInfo(scriptMan, castle); +} + +static void DrawPlayerInfoWindow(BgConfig *bgConfig, Window *window) +{ + Window_DrawStandardFrame(window, TRUE, (1024 - (18 + 12)) - 9, 12); + Window_FillTilemap(window, 15); +} + +void BattleCastle_ClearPlayerInfoWindows(FrontierScriptManager *scriptMan, BattleCastle *castle) +{ + Window *window1, *window2; + + if (!BattleCastle_IsMultiPlayerChallenge(castle->challengeType)) { + GF_ASSERT(scriptMan->castleHostInfoWin != NULL); + window1 = scriptMan->castleHostInfoWin; + Window_EraseStandardFrame(window1, FALSE); + Windows_Delete(window1, 1); + } else { + GF_ASSERT(scriptMan->castleHostInfoWin != NULL); + GF_ASSERT(scriptMan->castlePlayer2InfoWin != NULL); + + if (CommSys_CurNetId() == 0) { + window1 = scriptMan->castleHostInfoWin; + window2 = scriptMan->castlePlayer2InfoWin; + } else { + window1 = scriptMan->castlePlayer2InfoWin; + window2 = scriptMan->castleHostInfoWin; + } + + Window_EraseStandardFrame(window1, FALSE); + Windows_Delete(window1, 1); + Window_EraseStandardFrame(window2, FALSE); + Windows_Delete(window2, 1); + } + + scriptMan->castleHostInfoWin = NULL; + scriptMan->castlePlayer2InfoWin = NULL; +} + +void BattleCastle_PrintPlayersInfo(FrontierScriptManager *scriptMan, BattleCastle *castle) +{ + u16 hostsCP, player2CP; + + if (!BattleCastle_IsMultiPlayerChallenge(castle->challengeType)) { + GF_ASSERT(scriptMan->castleHostInfoWin != NULL); + hostsCP = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(castle->saveData), BattleFrontierStats_GetCastleLatestCPIndex(castle->challengeType)); + PrintPlayerNameandCP(scriptMan, scriptMan->castleHostInfoWin, SaveData_GetTrainerInfo(castle->saveData), hostsCP); + } else { + GF_ASSERT(scriptMan->castleHostInfoWin != NULL); + GF_ASSERT(scriptMan->castlePlayer2InfoWin != NULL); + + if (CommSys_CurNetId() == 0) { + hostsCP = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(castle->saveData), BattleFrontierStats_GetCastleLatestCPIndex(castle->challengeType)); + player2CP = castle->partnersCP; + } else { + hostsCP = castle->partnersCP; + player2CP = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(castle->saveData), BattleFrontierStats_GetCastleLatestCPIndex(castle->challengeType)); + } + + PrintPlayerNameandCP(scriptMan, scriptMan->castleHostInfoWin, CommInfo_TrainerInfo(0), hostsCP); + PrintPlayerNameandCP(scriptMan, scriptMan->castlePlayer2InfoWin, CommInfo_TrainerInfo(1), player2CP); + } +} + +static void PrintPlayerNameandCP(FrontierScriptManager *scriptMan, Window *window, TrainerInfo *trainer, u16 castlePoints) +{ + String *formatStr = String_Init(10 * 2, scriptMan->heapID); + String *displayStr = String_Init(10 * 2, scriptMan->heapID); + + MessageLoader *msgLoader = MessageLoader_Init(MSG_LOADER_PRELOAD_ENTIRE_BANK, NARC_INDEX_MSGDATA__PL_MSG, TEXT_BANK_BATTLE_CASTLE_SELF_APP, HEAP_ID_FIELD2); + + StringTemplate_SetNumber(scriptMan->strTemplate, 0, castlePoints, 4, PADDING_MODE_SPACES, CHARSET_MODE_EN); + MessageLoader_GetString(msgLoader, BattleCastleSelfApp_Text_CastlePoints, formatStr); + + StringTemplate_Format(scriptMan->strTemplate, displayStr, formatStr); + Text_AddPrinterWithParams(window, FONT_SYSTEM, displayStr, 16, 16, TEXT_SPEED_NO_TRANSFER, NULL); + StringTemplate_SetPlayerName(scriptMan->strTemplate, 0, trainer); + + MessageLoader_GetString(msgLoader, BattleCastleSelfApp_Text_PlayerName, formatStr); + + StringTemplate_Format(scriptMan->strTemplate, displayStr, formatStr); + Text_AddPrinterWithParams(window, FONT_SYSTEM, displayStr, 0, 0, TEXT_SPEED_INSTANT, NULL); + + String_Free(formatStr); + String_Free(displayStr); + MessageLoader_Free(msgLoader); + + Window_CopyToVRAM(window); +} + +u16 BattleCastle_GetEarnedBP(BattleCastle *castle) +{ + u8 bp; + static const u8 sBPPerRoundSolo[CASTLE_MAX_DISTINCT_ROUNDS + 1] = { 0, 3, 3, 4, 4, 5, 5, 7, 7 }; + static const u8 sBPPerRoundWifi[CASTLE_MAX_DISTINCT_ROUNDS + 1] = { 0, 8, 9, 11, 12, 14, 15, 18, 18 }; + + u16 currentRound = castle->currentRound; + + if (castle->challengeType == FRONTIER_CHALLENGE_SINGLE || castle->challengeType == FRONTIER_CHALLENGE_DOUBLE) { + if (currentRound >= CASTLE_MAX_DISTINCT_ROUNDS) { + bp = sBPPerRoundSolo[CASTLE_MAX_DISTINCT_ROUNDS]; + } else { + bp = sBPPerRoundSolo[currentRound]; + } + } else { + if (currentRound >= CASTLE_MAX_DISTINCT_ROUNDS) { + bp = sBPPerRoundWifi[CASTLE_MAX_DISTINCT_ROUNDS]; + } else { + bp = sBPPerRoundWifi[currentRound]; + } + } + + if (castle->challengeType == FRONTIER_CHALLENGE_SINGLE) { + if (castle->currentStreak == CASTLE_STREAK_SILVER_BATTLE || castle->currentStreak == CASTLE_STREAK_GOLD_BATTLE) { + bp = 20; + } + } + + return bp; +} diff --git a/src/overlay104/battle_castle_helpers.c b/src/overlay104/battle_castle_helpers.c new file mode 100644 index 0000000000..1b3788e5a4 --- /dev/null +++ b/src/overlay104/battle_castle_helpers.c @@ -0,0 +1,383 @@ +#include "overlay104/battle_castle_helpers.h" + +#include + +#include "constants/battle_frontier.h" +#include "generated/ai_flags.h" +#include "generated/frontier_trainers.h" + +#include "struct_defs/battle_frontier.h" + +#include "overlay104/ov104_0222DCE0.h" +#include "overlay104/struct_ov104_02230BE4.h" + +#include "battle_frontier_save.h" +#include "battle_frontier_stats.h" +#include "bg_window.h" +#include "communication_information.h" +#include "communication_system.h" +#include "field_battle_data_transfer.h" +#include "heap.h" +#include "item_use_pokemon.h" +#include "math_util.h" +#include "party.h" +#include "pokemon.h" +#include "save_player.h" + +#define EMBLEM_FRAME_HEIGHT 3 +#define EMBLEM_FRAME_WIDTH 10 +#define EMBLEM_FRAME_HALF (EMBLEM_FRAME_WIDTH / 2) + +static int BattleCastle_GetOpponentTrainerID(u8 challengeType, int currentRound, int trainerOffset); +static u32 BattleCastle_GetBattleType(u8 challengeType); +static u16 BattleCastle_GetAIMask(BattleCastle *battleCastle); +static void GetEmblemTiles(u16 *tiles, u16 currentRound); +static u16 CapCurrentRound(u16 currentRound); + +static const struct { + u16 normalMin; + u16 normalMax; + u16 finalMin; + u16 finalMax; +} sBattleCastleOpponentPools[] = { + { FRONTIER_TRAINER_YOUNGSTER_JIM, FRONTIER_TRAINER_REPORTER_GINGHAM, FRONTIER_TRAINER_CYCLIST_GASPAR, FRONTIER_TRAINER_SOCIALITE_CARMEN }, + { FRONTIER_TRAINER_HIKER_RAIDEN, FRONTIER_TRAINER_SOCIALITE_CARMEN, FRONTIER_TRAINER_PSYCHIC_ALPHA, FRONTIER_TRAINER_CLOWN_PRESCOT }, + { FRONTIER_TRAINER_CYCLIST_GASPAR, FRONTIER_TRAINER_CLOWN_PRESCOT, FRONTIER_TRAINER_ACE_TRAINER_YARDLEY, FRONTIER_TRAINER_ACE_TRAINER_DANIELA }, + { FRONTIER_TRAINER_PSYCHIC_ALPHA, FRONTIER_TRAINER_ACE_TRAINER_DANIELA, FRONTIER_TRAINER_YOUNGSTER_KADEN, FRONTIER_TRAINER_IDOL_UTAH }, + { FRONTIER_TRAINER_ACE_TRAINER_YARDLEY, FRONTIER_TRAINER_IDOL_UTAH, FRONTIER_TRAINER_JOGGER_COLT, FRONTIER_TRAINER_PI_SERGEI }, + { FRONTIER_TRAINER_YOUNGSTER_KADEN, FRONTIER_TRAINER_PI_SERGEI, FRONTIER_TRAINER_CAMPER_FREDDY, FRONTIER_TRAINER_BREEDER_ANTONIA }, + { FRONTIER_TRAINER_JOGGER_COLT, FRONTIER_TRAINER_BREEDER_ANTONIA, FRONTIER_TRAINER_ACE_TRAINER_SAWYER, FRONTIER_TRAINER_VETERAN_ALFRED }, + { FRONTIER_TRAINER_CAMPER_FREDDY, FRONTIER_TRAINER_IDOL_NISSA, FRONTIER_TRAINER_CAMPER_FREDDY, FRONTIER_TRAINER_IDOL_NISSA } +}; + +static int BattleCastle_GetOpponentTrainerID(u8 challengeType, int currentRound, int trainerOffset) +{ + if (challengeType == FRONTIER_CHALLENGE_SINGLE) { + int currentStreak = (currentRound * CASTLE_BATTLES_PER_ROUND) + (trainerOffset + 1); + + if (currentStreak == CASTLE_STREAK_SILVER_BATTLE) { + return FRONTIER_TRAINER_CASTLE_VALET_DARACH_SILVER; + } else if (currentStreak == CASTLE_STREAK_GOLD_BATTLE) { + return FRONTIER_TRAINER_CASTLE_VALET_DARACH_GOLD; + } + } + + if (currentRound >= NELEMS(sBattleCastleOpponentPools)) { + currentRound = NELEMS(sBattleCastleOpponentPools) - 1; + } + + int spread, min; + if (trainerOffset == CASTLE_BATTLES_PER_ROUND - 1 || trainerOffset == (CASTLE_BATTLES_PER_ROUND * 2) - 1) { + spread = sBattleCastleOpponentPools[currentRound].finalMax - sBattleCastleOpponentPools[currentRound].finalMin; + min = sBattleCastleOpponentPools[currentRound].finalMin; + } else { + spread = sBattleCastleOpponentPools[currentRound].normalMax - sBattleCastleOpponentPools[currentRound].normalMin; + min = sBattleCastleOpponentPools[currentRound].normalMin; + } + + return min + LCRNG_Next() % spread; +} + +void BattleCastle_PickOpponentTrainers(u8 challengeType, int currentRound, u16 trainerIDs[], u8 numTrainers) +{ + int i = 0; + do { + trainerIDs[i] = BattleCastle_GetOpponentTrainerID(challengeType, currentRound, i); + + int j; + for (j = 0; j < i; j++) { + if (trainerIDs[j] == trainerIDs[i]) { + break; + } + } + + if (j != i) { + continue; + } + + i++; + } while (i < numTrainers); +} + +u8 BattleCastle_GetPlayerPartySize(u8 challengeType, BOOL includePartnersMons) +{ + switch (challengeType) { + case FRONTIER_CHALLENGE_SINGLE: + case FRONTIER_CHALLENGE_DOUBLE: + return CASTLE_PARTY_SIZE_SOLO; + case FRONTIER_CHALLENGE_MULTI: + case FRONTIER_CHALLENGE_MULTI_WFC: + if (includePartnersMons == FALSE) { + return CASTLE_PARTY_SIZE_MULTI; + } else { + return CASTLE_PARTY_SIZE_MULTI * 2; + } + } + + GF_ASSERT(FALSE); + return CASTLE_PARTY_SIZE_SOLO; +} + +u8 BattleCastle_GetOpponentPartySize(u8 challengeType, BOOL includeBothOpponents) +{ + switch (challengeType) { + case FRONTIER_CHALLENGE_SINGLE: + case FRONTIER_CHALLENGE_DOUBLE: + return CASTLE_PARTY_SIZE_SOLO; + case FRONTIER_CHALLENGE_MULTI: + case FRONTIER_CHALLENGE_MULTI_WFC: + if (includeBothOpponents == FALSE) { + return CASTLE_PARTY_SIZE_MULTI; + } else { + return CASTLE_PARTY_SIZE_MULTI * 2; + } + } + + GF_ASSERT(FALSE); + return CASTLE_PARTY_SIZE_SOLO; +} + +FieldBattleDTO *BattleCastle_SetupBattle(BattleCastle *battleCastle, FieldFrontierDTO *fieldData) +{ + int i; + u8 baseSlotID; + FrontierTrainerDataDTO trDataDTO; + + u8 playerPartySize = BattleCastle_GetPlayerPartySize(battleCastle->challengeType, FALSE); + u8 opponentPartySize = BattleCastle_GetOpponentPartySize(battleCastle->challengeType, FALSE); + + Party_HealAllMembers(battleCastle->opponentsParty); + FieldBattleDTO *battleDTO = FieldBattleDTO_New(HEAP_ID_FIELD2, BattleCastle_GetBattleType(battleCastle->challengeType)); + FieldBattleDTO_InitFromGameState(battleDTO, NULL, fieldData->saveData, fieldData->mapHeaderID, fieldData->journalEntry, fieldData->bagCursor, fieldData->subscreenCursorOn); + + battleDTO->background = BACKGROUND_BATTLE_CASTLE; + battleDTO->terrain = TERRAIN_BATTLE_CASTLE; + + Party_InitWithCapacity(battleDTO->parties[BATTLER_PLAYER_1], playerPartySize); + + if (CommSys_CurNetId() == 0) { + baseSlotID = 0; + } else { + baseSlotID = CASTLE_PARTY_SIZE_MULTI; + } + + Pokemon *mon = Pokemon_New(HEAP_ID_FIELD2); + + for (i = 0; i < playerPartySize; i++) { + Pokemon_Copy(Party_GetPokemonBySlotIndex(battleCastle->playersParty, baseSlotID + i), mon); + + FieldBattleDTO_AddPokemonToBattler(battleDTO, mon, BATTLER_PLAYER_1); + } + + Heap_Free(mon); + FieldBattleDTO_CopyPlayerInfoToTrainerData(battleDTO); + + Heap_Free(BattleFrontier_GetTrainerData(&trDataDTO, battleCastle->trainerIDs[battleCastle->currentBattle], HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR)); + FieldBattleDTO_InitFrontierTrainer(battleDTO, &trDataDTO, opponentPartySize, BATTLER_ENEMY_1, HEAP_ID_FIELD2); + Party_InitWithCapacity(battleDTO->parties[BATTLER_ENEMY_1], BattleCastle_GetOpponentPartySize(battleCastle->challengeType, 0)); + + for (i = 0; i < MAX_BATTLERS; i++) { + battleDTO->trainer[i].header.aiMask = BattleCastle_GetAIMask(battleCastle); + } + + mon = Pokemon_New(HEAP_ID_FIELD2); + + for (i = 0; i < opponentPartySize; i++) { + Pokemon_Copy(Party_GetPokemonBySlotIndex(battleCastle->opponentsParty, i), mon); + FieldBattleDTO_AddPokemonToBattler(battleDTO, mon, BATTLER_ENEMY_1); + } + + Heap_Free(mon); + + switch (battleCastle->challengeType) { + case FRONTIER_CHALLENGE_MULTI: + case FRONTIER_CHALLENGE_MULTI_WFC: + FieldBattleDTO_CopyPlayerInfoToTrainerData(battleDTO); + + TrainerInfo_Copy(CommInfo_TrainerInfo(1 - CommSys_CurNetId()), battleDTO->trainerInfo[BATTLER_PLAYER_2]); + + Heap_Free(BattleFrontier_GetTrainerData(&trDataDTO, battleCastle->trainerIDs[battleCastle->currentBattle + CASTLE_BATTLES_PER_ROUND], HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR)); + + FieldBattleDTO_InitFrontierTrainer(battleDTO, &trDataDTO, opponentPartySize, BATTLER_ENEMY_2, HEAP_ID_FIELD2); + Party_InitWithCapacity(battleDTO->parties[BATTLER_ENEMY_2], BattleCastle_GetOpponentPartySize(battleCastle->challengeType, 0)); + + mon = Pokemon_New(HEAP_ID_FIELD2); + + for (i = 0; i < opponentPartySize; i++) { + Pokemon_Copy(Party_GetPokemonBySlotIndex(battleCastle->opponentsParty, opponentPartySize + i), mon); + FieldBattleDTO_AddPokemonToBattler(battleDTO, mon, BATTLER_ENEMY_2); + } + + Heap_Free(mon); + break; + } + + return battleDTO; +} + +static u32 BattleCastle_GetBattleType(u8 challengeType) +{ + switch (challengeType) { + case FRONTIER_CHALLENGE_SINGLE: + return BATTLE_TYPE_FRONTIER_SINGLES; + case FRONTIER_CHALLENGE_DOUBLE: + return BATTLE_TYPE_FRONTIER_DOUBLES; + case FRONTIER_CHALLENGE_MULTI: + return BATTLE_TYPE_FRONTIER_LINK | BATTLE_TYPE_TRAINER_DOUBLES | BATTLE_TYPE_2vs2; + case FRONTIER_CHALLENGE_MULTI_WFC: + return BATTLE_TYPE_FRONTIER_LINK | BATTLE_TYPE_TRAINER_DOUBLES | BATTLE_TYPE_2vs2; + } + + return BATTLE_TYPE_FRONTIER_SINGLES; +} + +u8 BattleCastle_GetOpponentLevel(BattleCastle *battleCastle) +{ + return CASTLE_MAX_LEVEL; +} + +BOOL BattleCastle_IsMultiPlayerChallenge(u8 challengeType) +{ + return challengeType == FRONTIER_CHALLENGE_MULTI || challengeType == FRONTIER_CHALLENGE_MULTI_WFC; +} + +void BattleCastle_RevivePokemon(Party *party) +{ + int partySize = Party_GetCurrentCount(party); + + for (int i = 0; i < partySize; i++) { + Pokemon *mon = Party_GetPokemonBySlotIndex(party, i); + + if (!Pokemon_GetValue(mon, MON_DATA_SPECIES_EXISTS, NULL)) { + continue; + } + + u32 value; + if (Pokemon_GetValue(mon, MON_DATA_HP, NULL) == 0) { + value = 1; + Pokemon_SetValue(mon, MON_DATA_HP, &value); + } + + value = 0; + Pokemon_SetValue(mon, MON_DATA_STATUS, &value); + } +} + +static void AddSummaryDetailsToMon(BattleCastle *battleCastle, Pokemon *mon) +{ + Pokemon_UpdateAfterCatch(mon, SaveData_GetTrainerInfo(battleCastle->saveData), ITEM_POKE_BALL, 0, 0, HEAP_ID_FIELD2); +} + +void BattleCastle_AddMonToParty(BattleCastle *battleCastle, Party *party, Pokemon *mon) +{ + AddSummaryDetailsToMon(battleCastle, mon); + Party_AddPokemon(party, mon); +} + +void BattleCastle_SetupOpponentsParty(BattleCastle *battleCastle) +{ + Party_Init(battleCastle->opponentsParty); + + u8 partySize = BattleCastle_GetOpponentPartySize(battleCastle->challengeType, TRUE); + Pokemon *mon = Pokemon_New(HEAP_ID_FIELD2); + + for (int i = 0; i < partySize; i++) { + FrontierPokemonDataDTO_InitPokemon(&battleCastle->opponentMons[i], mon, BattleCastle_GetOpponentLevel(battleCastle)); + BattleCastle_AddMonToParty(battleCastle, battleCastle->opponentsParty, mon); + } + + Heap_Free(mon); +} + +static u16 BattleCastle_GetAIMask(BattleCastle *battleCastle) +{ + if (battleCastle->challengeType == FRONTIER_CHALLENGE_SINGLE) { + if (battleCastle->trainerIDs[battleCastle->currentBattle] == FRONTIER_TRAINER_CASTLE_VALET_DARACH_SILVER + || battleCastle->trainerIDs[battleCastle->currentBattle] == FRONTIER_TRAINER_CASTLE_VALET_DARACH_GOLD) { + return AI_FLAG_BASIC | AI_FLAG_EVAL_ATTACK | AI_FLAG_EXPERT; + } + } + + u16 round = BattleCastle_GetCurrentRound(battleCastle); + u16 aiMask = AI_FLAG_BASIC | AI_FLAG_EVAL_ATTACK | AI_FLAG_EXPERT; + + switch (round + 1) { + case 1: + case 2: + aiMask = AI_FLAG_NONE; + break; + case 3: + case 4: + aiMask = AI_FLAG_BASIC; + break; + } + + return aiMask; +} + +u16 BattleCastle_GetCurrentRound(BattleCastle *battleCastle) +{ + u16 currentRound = battleCastle->currentRound; + + if (BattleCastle_IsMultiPlayerChallenge(battleCastle->challengeType) == TRUE) { + if (battleCastle->unk_A12 > battleCastle->currentRound) { + currentRound = battleCastle->unk_A12; + } + } + + return currentRound; +} + +void BattleCastle_UpdateEmblemFrame(BgConfig *bgConfig, BattleCastle *battleCastle, u32 bgLayer) +{ + u16 tiles[EMBLEM_FRAME_HEIGHT * EMBLEM_FRAME_WIDTH]; + + GetEmblemTiles(tiles, BattleCastle_GetCurrentRound(battleCastle)); + + Bg_LoadToTilemapRect(bgConfig, bgLayer, tiles, 11, 6, EMBLEM_FRAME_WIDTH, EMBLEM_FRAME_HEIGHT); + Bg_ScheduleTilemapTransfer(bgConfig, bgLayer); +} + +static void GetEmblemTiles(u16 *tiles, u16 currentRound) +{ + u8 baseTileOffset[EMBLEM_FRAME_WIDTH]; + u16 round = CapCurrentRound(currentRound); + + for (u32 i = 0; i < EMBLEM_FRAME_HALF; i++) { + baseTileOffset[i] = i; + baseTileOffset[EMBLEM_FRAME_HALF + i] = EMBLEM_FRAME_HALF - 1 - i; + } + + u32 startTile = (96 * round) + 16; + + for (u32 y = 0; y < EMBLEM_FRAME_HEIGHT; y++) { + for (u32 x = 0; x < EMBLEM_FRAME_WIDTH; x++) { + tiles[x + (y * EMBLEM_FRAME_WIDTH)] = startTile + (y * 32) + baseTileOffset[x]; + + if (x >= EMBLEM_FRAME_HALF) { + tiles[x + (y * EMBLEM_FRAME_WIDTH)] |= BG_TILE_FLIP_H; + } + } + } +} + +static u16 CapCurrentRound(u16 currentRound) +{ + if (currentRound >= CASTLE_MAX_DISTINCT_ROUNDS) { + return CASTLE_MAX_DISTINCT_ROUNDS - 1; + } + + return currentRound; +} + +void BattleCastle_SpendCastlePoints(BattleFrontierSave *frontier, u8 challengeType, int castlePoints) +{ + BattleFrontierSave_SubtractFromStat(frontier, BattleFrontierStats_GetCastleLatestCPIndex(challengeType), BattleFrontierStats_GetHostFriendIdx(BattleFrontierStats_GetCastleLatestCPIndex(challengeType)), castlePoints); + u16 totalSpent = BattleFrontierSave_GetStatAutoHostIdx(frontier, BattleFrontierStats_GetCastleSpentCPIndex(challengeType)); + + if (totalSpent + castlePoints > 9999) { + BattleFrontierSave_SetStatAutoHostIdx(frontier, BattleFrontierStats_GetCastleSpentCPIndex(challengeType), 9999); + } else { + BattleFrontierSave_AddToStat(frontier, BattleFrontierStats_GetCastleSpentCPIndex(challengeType), BattleFrontierStats_GetHostFriendIdx(BattleFrontierStats_GetCastleSpentCPIndex(challengeType)), castlePoints); + } +} diff --git a/src/overlay104/battle_hall.c b/src/overlay104/battle_hall.c index 562aebd702..fbbf789529 100644 --- a/src/overlay104/battle_hall.c +++ b/src/overlay104/battle_hall.c @@ -128,7 +128,7 @@ void BattleHall_SetupNextOpponent(BattleHall *battleHall, u16 unused) static void SetupNextOpponent(BattleHall *battleHall) { - u8 battleType = HALL_NEXT_BATTLE_NORMAL; + u8 battleType = FRONTIER_NEXT_BATTLE_NORMAL; u8 numOppTrainers = 1; if (battleHall->challengeType != FRONTIER_CHALLENGE_SINGLE) { @@ -148,11 +148,11 @@ static void SetupNextOpponent(BattleHall *battleHall) } if (battleHall->trainerIDs[offset] == FRONTIER_TRAINER_HALL_MATRON_ARGENTA_SILVER) { - battleType = HALL_NEXT_BATTLE_SILVER; + battleType = FRONTIER_NEXT_BATTLE_SILVER; } if (battleHall->trainerIDs[offset] == FRONTIER_TRAINER_HALL_MATRON_ARGENTA_GOLD) { - battleType = HALL_NEXT_BATTLE_GOLD; + battleType = FRONTIER_NEXT_BATTLE_GOLD; } Pokemon *playersMon = Party_GetPokemonBySlotIndex(battleHall->party, 0); diff --git a/src/overlay104/battle_hall_helpers.c b/src/overlay104/battle_hall_helpers.c index b63600b534..0fad8934be 100644 --- a/src/overlay104/battle_hall_helpers.c +++ b/src/overlay104/battle_hall_helpers.c @@ -1258,7 +1258,7 @@ void BattleHall_PickNextOpponentPokemon(u8 numOpponentsToPick, u8 selectedType, // For the Silver print battle, the opponent is selected from the group in // which the player's species is // For the Gold print battle, the opponent is from Group 4 - if (battleType != HALL_NEXT_BATTLE_NORMAL) { + if (battleType != FRONTIER_NEXT_BATTLE_NORMAL) { u16 i, playersMonIndex; for (i = 0; i < NELEMS(sBattleHallPotentialOpponents); i++) { if (playersSpecies == sBattleHallPotentialOpponents[i]) { @@ -1282,7 +1282,7 @@ void BattleHall_PickNextOpponentPokemon(u8 numOpponentsToPick, u8 selectedType, playersMonsGroup = NELEMS(sMatchupGroupRanges) - 1; } - if (battleType == HALL_NEXT_BATTLE_GOLD) { + if (battleType == FRONTIER_NEXT_BATTLE_GOLD) { matchupRange = &sMatchupGroupRanges[NELEMS(sMatchupGroupRanges) - 1]; } else { matchupRange = &sMatchupGroupRanges[playersMonsGroup]; diff --git a/src/overlay104/frscrcmd_battle_arcade.c b/src/overlay104/frscrcmd_battle_arcade.c index 05b72a4280..4b9c10f7c6 100644 --- a/src/overlay104/frscrcmd_battle_arcade.c +++ b/src/overlay104/frscrcmd_battle_arcade.c @@ -7,6 +7,7 @@ #include "applications/frontier/battle_arcade/main.h" #include "overlay063/ov63_0222CCE4.h" +#include "overlay104/battle_castle_helpers.h" #include "overlay104/defs.h" #include "overlay104/frontier_graphics.h" #include "overlay104/frontier_particle_system.h" @@ -16,7 +17,6 @@ #include "overlay104/ov104_0222DCE0.h" #include "overlay104/ov104_02231F74.h" #include "overlay104/ov104_02237DD8.h" -#include "overlay104/ov104_0223B6F4.h" #include "overlay104/ov104_0223BCBC.h" #include "overlay104/struct_battle_arcade.h" #include "overlay104/struct_ov104_02230BE4.h" diff --git a/src/overlay104/frscrcmd_battle_castle.c b/src/overlay104/frscrcmd_battle_castle.c index b8ed4a1430..5c836082d7 100644 --- a/src/overlay104/frscrcmd_battle_castle.c +++ b/src/overlay104/frscrcmd_battle_castle.c @@ -3,20 +3,22 @@ #include #include "constants/battle_castle_functions.h" +#include "constants/battle_frontier.h" #include "applications/frontier/battle_castle/args.h" #include "applications/frontier/battle_castle/opponent_app.h" #include "applications/frontier/battle_castle/self_app.h" +#include "global/utility.h" +#include "overlay104/battle_castle.h" +#include "overlay104/battle_castle_helpers.h" #include "overlay104/frontier_script_context.h" #include "overlay104/frontier_script_manager.h" #include "overlay104/frscrcmd.h" #include "overlay104/ov104_0222DCE0.h" #include "overlay104/ov104_02231F74.h" -#include "overlay104/ov104_022361B4.h" -#include "overlay104/ov104_0223B6F4.h" -#include "overlay104/struct_battle_castle.h" #include "overlay104/struct_ov104_02230BE4.h" +#include "battle_castle_save.h" #include "battle_frontier.h" #include "battle_frontier_save.h" #include "battle_frontier_stats.h" @@ -25,7 +27,6 @@ #include "heap.h" #include "party.h" #include "pokemon.h" -#include "unk_020302D0.h" #include "unk_0209BA80.h" #include "constdata/const_020EA358.h" @@ -34,47 +35,44 @@ FS_EXTERN_OVERLAY(battle_castle_app); #include -static BOOL ov104_02236008(FrontierScriptContext *param0); +static BOOL WaitForCommResponses(FrontierScriptContext *ctx); static void SetupBattleCastleAppArgs(BattleCastleAppArgs *args, BattleCastle *battleCastle); -static BOOL ov104_02236058(FrontierScriptContext *param0); +static BOOL ov104_02236058(FrontierScriptContext *ctx); static void StoreBattleCastleAppResult(void *data); -BOOL FrontierScrCmd_97(FrontierScriptContext *param0) +BOOL FrontierScrCmd_InitBattleCastle(FrontierScriptContext *ctx) { - BattleCastle *v0; - FieldFrontierDTO *fieldData; - u16 v2 = FrontierScriptContext_GetVar(param0); - u16 v3 = FrontierScriptContext_GetVar(param0); - u16 v4 = FrontierScriptContext_GetVar(param0); - u16 v5 = FrontierScriptContext_GetVar(param0); - u16 v6 = FrontierScriptContext_GetVar(param0); - u16 *v7 = FrontierScriptContext_TryGetVarPointer(param0); + u16 resumingFromSave = FrontierScriptContext_GetVar(ctx); + u16 challengeType = FrontierScriptContext_GetVar(ctx); + u16 partySlot1 = FrontierScriptContext_GetVar(ctx); + u16 partySlot2 = FrontierScriptContext_GetVar(ctx); + u16 partySlot3 = FrontierScriptContext_GetVar(ctx); + u16 *v7 = FrontierScriptContext_TryGetVarPointer(ctx); - fieldData = BattleFrontier_GetFieldData(param0->scriptMan->frontier); - v0 = ov104_022361B4(fieldData->saveData, v2, v3, v4, v5, v6, v7); + FieldFrontierDTO *fieldData = BattleFrontier_GetFieldData(ctx->scriptMan->frontier); + BattleCastle *castle = BattleCastle_Init(fieldData->saveData, resumingFromSave, challengeType, partySlot1, partySlot2, partySlot3, v7); - BattleFrontier_SetFacilityStruct(param0->scriptMan->frontier, v0); + BattleFrontier_SetFacilityStruct(ctx->scriptMan->frontier, castle); - return 0; + return FALSE; } -BOOL FrontierScrCmd_98(FrontierScriptContext *param0) +BOOL FrontierScrCmd_LoadTrainersForRound(FrontierScriptContext *ctx) { - BattleCastle *v0; - u16 v1 = FrontierScriptContext_GetVar(param0); + u16 resumingFromSave = FrontierScriptContext_GetVar(ctx); - v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); - ov104_02236514(v0, v1); + BattleCastle *castle = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); + BattleCastle_LoadTrainersForRound(castle, resumingFromSave); - return 0; + return FALSE; } -BOOL FrontierScrCmd_99(FrontierScriptContext *param0) +BOOL FrontierScrCmd_FreeBattleCastle(FrontierScriptContext *ctx) { - BattleCastle *v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); - ov104_022367AC(v0); + BattleCastle *castle = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); + BattleCastle_Free(castle); - return 0; + return FALSE; } BOOL FrontierScrCmd_OpenBattleCastleSelfApp(FrontierScriptContext *ctx) @@ -101,7 +99,7 @@ BOOL FrontierScrCmd_OpenBattleCastleSelfApp(FrontierScriptContext *ctx) return TRUE; } -BOOL FrontierScrCmd_A4(FrontierScriptContext *ctx) +BOOL FrontierScrCmd_DummyOpenBattleCastleApp(FrontierScriptContext *ctx) { FieldFrontierDTO *fieldData = BattleFrontier_GetFieldData(ctx->scriptMan->frontier); @@ -158,7 +156,7 @@ BOOL FrontierScrCmd_BattleCastle_StartBattle(FrontierScriptContext *ctx) FieldFrontierDTO *fieldData = BattleFrontier_GetFieldData(ctx->scriptMan->frontier); BattleCastle *battleCastle = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); - FieldBattleDTO *dto = FieldBattleDTO_NewBattleCastle(battleCastle, fieldData); + FieldBattleDTO *dto = BattleCastle_SetupBattle(battleCastle, fieldData); battleCastle->dto = dto; sub_0209B988(ctx->scriptMan->frontier, &gBattleApplicationTemplate, dto, 0, NULL); @@ -199,7 +197,7 @@ static void SetupBattleCastleAppArgs(BattleCastleAppArgs *args, BattleCastle *ba for (int i = 0; i < 4; i++) { args->identityUnlocked[i] = battleCastle->appIdentityUnlocked[i]; - args->levelAdjustmentUnlocked[i] = battleCastle->appLevelAdjustmentsUnlocked[i]; + args->levelAdjustments[i] = battleCastle->levelAdjustments[i]; args->statsUnlocked[i] = battleCastle->appStatsUnlocked[i]; args->movesUnlocked[i] = battleCastle->appMovesUnlocked[i]; } @@ -212,20 +210,20 @@ static void StoreBattleCastleAppResult(void *data) Heap_Free(data); } -BOOL FrontierScrCmd_9E(FrontierScriptContext *param0) +BOOL FrontierScrCmd_BattleCastle_SetupFirstOpponent(FrontierScriptContext *ctx) { - BattleCastle *v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); - ov104_02236BF0(v0); + BattleCastle *castle = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); + BattleCastle_SetupFirstOpponentsParty(castle); - return 0; + return FALSE; } -BOOL FrontierScrCmd_9F(FrontierScriptContext *param0) +BOOL FrontierScrCmd_BattleCastle_SetupNextOpponent(FrontierScriptContext *ctx) { - BattleCastle *v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); - ov104_02236BF8(v0); + BattleCastle *castle = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); + BattleCastle_SetupNextOpponentsParty(castle); - return 0; + return FALSE; } BOOL FrontierScrCmd_CallBattleCastleFunction(FrontierScriptContext *ctx) @@ -243,8 +241,8 @@ BOOL FrontierScrCmd_CallBattleCastleFunction(FrontierScriptContext *ctx) case BC_FUNC_SET_CHALLENGE_TYPE: battleCastle->challengeType = arg1; break; - case BC_FUNC_UNK_3: - *returnVar = battleCastle->unk_380[arg1]; + case BC_FUNC_GET_SELECTED_APP_SLOT: + *returnVar = battleCastle->selectedAppSlots[arg1]; break; case BC_FUNC_GET_CURRENT_STREAK: *returnVar = battleCastle->currentStreak; @@ -257,43 +255,43 @@ BOOL FrontierScrCmd_CallBattleCastleFunction(FrontierScriptContext *ctx) case BC_FUNC_RESET_SYSTEM: OS_ResetSystem(0); break; - case BC_FUNC_UNK_9: - *returnVar = sub_020302EC(battleCastle->unk_08); + case BC_FUNC_HAS_SAVED: + *returnVar = BattleCastleSave_HasSaved(battleCastle->castleSave); break; - case BC_FUNC_UNK_10: - ov104_02236848(battleCastle, 2); + case BC_FUNC_QUICKSAVE: + BattleCastle_Save(battleCastle, 2); break; - case BC_FUNC_UNK_14: - *returnVar = ov104_02236B48(battleCastle); + case BC_FUNC_INCREMENT_CURRENT_BATTLE: + *returnVar = BattleCastle_IncrementCurrentBattle(battleCastle); break; - case BC_FUNC_UNK_15: - *returnVar = battleCastle->unk_288[arg1].species; + case BC_FUNC_GET_MONS_SPECIES: + *returnVar = battleCastle->opponentMons[arg1].species; break; - case BC_FUNC_UNK_16: - *returnVar = battleCastle->unk_288[arg1].moves[arg2]; + case BC_FUNC_GET_MONS_MOVE: + *returnVar = battleCastle->opponentMons[arg1].moves[arg2]; break; - case BC_FUNC_UNK_18: { - Party *v2 = SaveData_GetParty(fieldData->saveData); + case BC_FUNC_RESTORE_HELD_ITEMS: { + Party *party = SaveData_GetParty(fieldData->saveData); - for (int v8 = 0; v8 < 3; v8++) { - Pokemon *v1 = Party_GetPokemonBySlotIndex(v2, battleCastle->unk_24[v8]); - Pokemon_SetValue(v1, MON_DATA_HELD_ITEM, &battleCastle->unk_36A[v8]); + for (int i = 0; i < 3; i++) { + Pokemon *mon = Party_GetPokemonBySlotIndex(party, battleCastle->partySlots[i]); + Pokemon_SetValue(mon, MON_DATA_HELD_ITEM, &battleCastle->savedHeldItems[i]); } } break; - case BC_FUNC_UNK_19: - *returnVar = ov104_0223BB60(battleCastle); + case BC_FUNC_GET_CURRENT_ROUND: + *returnVar = BattleCastle_GetCurrentRound(battleCastle); break; - case BC_FUNC_UNK_20: - *returnVar = ov104_02236B58(battleCastle, arg1); + case BC_FUNC_GET_OPPONENT_OBJECT_ID: + *returnVar = BattleCastle_GetNextOpponentObjectID(battleCastle, arg1); break; - case BC_FUNC_UNK_21: - ov104_02236B8C(battleCastle); + case BC_FUNC_SAVE_ON_LOSS: + BattleCastle_SaveOnLoss(battleCastle); break; - case BC_FUNC_UNK_22: - ov104_02236BD0(battleCastle); + case BC_FUNC_SAVE_ON_COMPLETING_ROUND: + BattleCastle_SaveOnCompletingRound(battleCastle); break; - case BC_FUNC_UNK_23: - *returnVar = ov104_02236B54(battleCastle); + case BC_FUNC_GET_CURRENT_BATTLE: + *returnVar = BattleCastle_GetCurrentBattle(battleCastle); break; case BC_FUNC_UNK_24: *returnVar = battleCastle->unk_A10; @@ -301,19 +299,19 @@ BOOL FrontierScrCmd_CallBattleCastleFunction(FrontierScriptContext *ctx) case BC_FUNC_UNK_26: *returnVar = battleCastle->unk_A11; break; - case BC_FUNC_UNK_27: - *returnVar = ov104_02236D10(battleCastle); - ov104_02236ED8(battleCastle->saveData, battleCastle->challengeType, *returnVar); + case BC_FUNC_GET_CP_FROM_BATTLE: + *returnVar = BattleCastle_CalcCPEarnedFromBattle(battleCastle); + BattleCastle_ReceiveCastlePoints(battleCastle->saveData, battleCastle->challengeType, *returnVar); break; - case BC_FUNC_UNK_28: - ov104_02236C50(battleCastle); + case BC_FUNC_PREP_FOR_NEXT_BATTLE: + BattleCastle_PrepForNextBattle(battleCastle); break; - case BC_FUNC_UNK_29: + case BC_FUNC_INIT_COMM_MANAGER: sub_0209BA80(battleCastle); break; case BC_FUNC_UNK_30: if (battleCastle->unk_A1B >= 6) { - *returnVar = (battleCastle->unk_A1B - 6); + *returnVar = battleCastle->unk_A1B - 6; } else { *returnVar = battleCastle->unk_A1B; } @@ -340,7 +338,7 @@ BOOL FrontierScrCmd_CallBattleCastleFunction(FrontierScriptContext *ctx) } if (v10 == 1) { - ov104_0223BC2C(SaveData_GetBattleFrontier(fieldData->saveData), battleCastle->challengeType, 50); + BattleCastle_SpendCastlePoints(SaveData_GetBattleFrontier(fieldData->saveData), battleCastle->challengeType, 50); } else { battleCastle->partnersCP -= 50; } @@ -348,7 +346,7 @@ BOOL FrontierScrCmd_CallBattleCastleFunction(FrontierScriptContext *ctx) case BC_FUNC_UNK_34: *returnVar = 0; - if (BattleCastle_IsMultiPlayerChallenge(battleCastle->challengeType) == 1) { + if (BattleCastle_IsMultiPlayerChallenge(battleCastle->challengeType) == TRUE) { if (battleCastle->unk_A1B >= 6) { if (CommSys_CurNetId() == 0) { *returnVar = 1; @@ -366,54 +364,54 @@ BOOL FrontierScrCmd_CallBattleCastleFunction(FrontierScriptContext *ctx) case BC_FUNC_GET_CHALLENGE_TYPE: *returnVar = battleCastle->challengeType; break; - case BC_FUNC_UNK_25: - *returnVar = battleCastle->unk_12; + case BC_FUNC_CHECK_IF_MON_FAINTED: + *returnVar = battleCastle->monFainted; break; - case BC_FUNC_UNK_36: { - FrontierGraphics *v12 = FrontierScriptManager_GetGraphics(ctx->scriptMan); - ov104_0223BB84(v12->bgConfig, battleCastle, 3); + case BC_FUNC_UPDATE_EMBLEM_FRAME: { + FrontierGraphics *graphics = FrontierScriptManager_GetGraphics(ctx->scriptMan); + BattleCastle_UpdateEmblemFrame(graphics->bgConfig, battleCastle, BG_LAYER_MAIN_3); } break; - case BC_FUNC_UNK_37: - BattleFrontier_LoadTrainer(&(battleCastle->unk_4C[0]), battleCastle->trainerIDs[battleCastle->unk_11], HEAP_ID_FIELD2, 178); - BattleFrontier_LoadTrainer(&(battleCastle->unk_4C[1]), battleCastle->trainerIDs[battleCastle->unk_11 + 7], HEAP_ID_FIELD2, 178); + case BC_FUNC_LOAD_TRAINERS: + BattleFrontier_LoadTrainer(&battleCastle->opponents[0], battleCastle->trainerIDs[battleCastle->currentBattle], HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR); + BattleFrontier_LoadTrainer(&battleCastle->opponents[1], battleCastle->trainerIDs[battleCastle->currentBattle + CASTLE_BATTLES_PER_ROUND], HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR); break; - case BC_FUNC_UNK_38: - *returnVar = ov104_02237338(battleCastle); + case BC_FUNC_GET_EARNED_BP: + *returnVar = BattleCastle_GetEarnedBP(battleCastle); break; - case BC_FUNC_UNK_39: { - u8 v13[4]; - *returnVar = (u16)sub_02030470(sub_0203041C(fieldData->saveData), 10, 0, 0, NULL); - v13[0] = 1; - sub_02030430(sub_0203041C(fieldData->saveData), 10, 0, 0, v13); + case BC_FUNC_CHECK_HAVE_HEARD_DARACHS_INTRO: { + u8 haveHeardIntro[4]; + *returnVar = BattleCastlePersistentSave_GetFlag(BattleCastlePersistentSave_Get(fieldData->saveData), CASTLE_SAVE_HAVE_HEARD_INTRO, 0, 0, NULL); + haveHeardIntro[0] = TRUE; + BattleCastlePersistentSave_SetFlag(BattleCastlePersistentSave_Get(fieldData->saveData), CASTLE_SAVE_HAVE_HEARD_INTRO, 0, 0, haveHeardIntro); } break; - case BC_FUNC_UNK_40: - *returnVar = 0; + case BC_FUNC_GET_NEXT_BATTLE_TYPE: + *returnVar = FRONTIER_NEXT_BATTLE_NORMAL; - if (battleCastle->challengeType == 0) { - if ((battleCastle->currentStreak + 1) == 21) { - *returnVar = 1; - } else if ((battleCastle->currentStreak + 1) == 49) { - *returnVar = 2; + if (battleCastle->challengeType == FRONTIER_CHALLENGE_SINGLE) { + if (battleCastle->currentStreak + 1 == CASTLE_STREAK_SILVER_BATTLE) { + *returnVar = FRONTIER_NEXT_BATTLE_SILVER; + } else if (battleCastle->currentStreak + 1 == CASTLE_STREAK_GOLD_BATTLE) { + *returnVar = FRONTIER_NEXT_BATTLE_GOLD; } } break; - case BC_FUNC_UNK_41: - ov104_0222E330(battleCastle->unk_288, battleCastle->unk_26C, battleCastle->unk_274, battleCastle->unk_278, NULL, 4, 11, 179); + case BC_FUNC_CREATE_OPPONENT_MONS: + ov104_0222E330(battleCastle->opponentMons, battleCastle->monSetIDs, battleCastle->opponentMonIVs, battleCastle->opponentMonPersonalities, NULL, 4, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); break; - case BC_FUNC_UNK_42: - ov104_0223BAB8(battleCastle); + case BC_FUNC_SETUP_OPPONENTS_PARTY: + BattleCastle_SetupOpponentsParty(battleCastle); break; - case BC_FUNC_UNK_43: - *returnVar = battleCastle->unk_13; - battleCastle->unk_13 = 1; + case BC_FUNC_CHECK_SEEN_VALET_INTRO: + *returnVar = battleCastle->seenCastleValetIntro; + battleCastle->seenCastleValetIntro = TRUE; break; - case BC_FUNC_UNK_44: - if (battleCastle->challengeType == 3) { + case BC_FUNC_UPDATE_CP: + if (battleCastle->challengeType == FRONTIER_CHALLENGE_MULTI_WFC) { if (arg1 == 0) { - battleCastle->unk_22 = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(fieldData->saveData), BattleFrontierStats_GetCastleLatestCPIndex(battleCastle->challengeType)); - BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(fieldData->saveData), BattleFrontierStats_GetCastleLatestCPIndex(battleCastle->challengeType), battleCastle->unk_20); + battleCastle->newCP = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(fieldData->saveData), BattleFrontierStats_GetCastleLatestCPIndex(battleCastle->challengeType)); + BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(fieldData->saveData), BattleFrontierStats_GetCastleLatestCPIndex(battleCastle->challengeType), battleCastle->initialCP); } else { - BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(fieldData->saveData), BattleFrontierStats_GetCastleLatestCPIndex(battleCastle->challengeType), battleCastle->unk_22); + BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(fieldData->saveData), BattleFrontierStats_GetCastleLatestCPIndex(battleCastle->challengeType), battleCastle->newCP); } } break; @@ -424,156 +422,144 @@ BOOL FrontierScrCmd_CallBattleCastleFunction(FrontierScriptContext *ctx) BOOL FrontierScrCmd_BattleCastle_CheckWonBattle(FrontierScriptContext *ctx) { - BattleCastle *battleCastle; u16 *destVar = FrontierScriptContext_TryGetVarPointer(ctx); - battleCastle = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); + BattleCastle *battleCastle = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); *destVar = battleCastle->wonBattle; return FALSE; } -BOOL FrontierScrCmd_A2(FrontierScriptContext *param0) +BOOL FrontierScrCmd_BattleCastle_SendCommMessage(FrontierScriptContext *ctx) { - BattleCastle *v0; - u16 v1 = FrontierScriptContext_GetVar(param0); - u16 v2 = FrontierScriptContext_GetVar(param0); - u16 *v3 = FrontierScriptContext_TryGetVarPointer(param0); + u16 command = FrontierScriptContext_GetVar(ctx); + u16 arg = FrontierScriptContext_GetVar(ctx); + u16 *success = FrontierScriptContext_TryGetVarPointer(ctx); - v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); - *v3 = ov104_02236F70(v0, v1, v2); + BattleCastle *castle = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); + *success = BattleCastle_SendCommMessage(castle, command, arg); - return 1; + return TRUE; } -BOOL FrontierScrCmd_A3(FrontierScriptContext *param0) +BOOL FrontierScrCmd_BattleCastle_WaitForCommResponses(FrontierScriptContext *ctx) { - u16 v0 = FrontierScriptContext_ReadHalfWord(param0); + ctx->data[0] = FrontierScriptContext_ReadHalfWord(ctx); + FrontierScriptContext_Pause(ctx, WaitForCommResponses); - param0->data[0] = v0; - FrontierScriptContext_Pause(param0, ov104_02236008); - - return 1; + return TRUE; } -static BOOL ov104_02236008(FrontierScriptContext *param0) +static BOOL WaitForCommResponses(FrontierScriptContext *ctx) { - BattleCastle *v0; - u16 v1 = FrontierScriptContext_TryGetVar(param0, param0->data[0]); + UNUSED(FrontierScriptContext_TryGetVar(ctx, ctx->data[0])); - v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); + BattleCastle *castle = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); - if (v0->unk_A1A >= 2) { - v0->unk_A1A = 0; - return 1; + if (castle->msgsReceived >= 2) { + castle->msgsReceived = 0; + return TRUE; } - return 0; + return FALSE; } -BOOL FrontierScrCmd_A5(FrontierScriptContext *param0) +BOOL FrontierScrCmd_A5(FrontierScriptContext *ctx) { - u16 v0 = FrontierScriptContext_ReadHalfWord(param0); + u16 v0 = FrontierScriptContext_ReadHalfWord(ctx); - param0->data[0] = v0; - FrontierScriptContext_Pause(param0, ov104_02236058); + ctx->data[0] = v0; + FrontierScriptContext_Pause(ctx, ov104_02236058); - return 1; + return TRUE; } -static BOOL ov104_02236058(FrontierScriptContext *param0) +static BOOL ov104_02236058(FrontierScriptContext *ctx) { - BattleCastle *v0; - u16 *v1 = FrontierScriptContext_GetVarPointer(param0, param0->data[0]); + u16 *v1 = FrontierScriptContext_GetVarPointer(ctx, ctx->data[0]); - v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); + BattleCastle *castle = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); - if (v0->unk_A1B == 0) { - return 0; + if (castle->unk_A1B == 0) { + return FALSE; } - v0->unk_A1A = 0; - *v1 = v0->unk_A1B; + castle->msgsReceived = 0; + *v1 = castle->unk_A1B; - return 1; + return TRUE; } -BOOL FrontierScrCmd_50(FrontierScriptContext *param0) +BOOL FrontierScrCmd_ShowCastlePointsWindows(FrontierScriptContext *ctx) { - BattleCastle *v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); - ov104_02236FC0(param0->scriptMan, v0); + BattleCastle *castle = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); + BattleCastle_ShowPlayerInfoWindows(ctx->scriptMan, castle); - return 0; + return FALSE; } -BOOL FrontierScrCmd_51(FrontierScriptContext *param0) +BOOL FrontierScrCmd_ClearCastlePointsWindows(FrontierScriptContext *ctx) { - BattleCastle *v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); - ov104_022370E0(param0->scriptMan, v0); + BattleCastle *castle = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); + BattleCastle_ClearPlayerInfoWindows(ctx->scriptMan, castle); - return 0; + return FALSE; } -BOOL FrontierScrCmd_52(FrontierScriptContext *param0) +BOOL FrontierScrCmd_ReprintCastlePointsInfo(FrontierScriptContext *ctx) { - BattleCastle *v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); - ov104_02237180(param0->scriptMan, v0); + BattleCastle *castle = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); + BattleCastle_PrintPlayersInfo(ctx->scriptMan, castle); - return 0; + return FALSE; } -BOOL FrontierScrCmd_A6(FrontierScriptContext *param0) +BOOL FrontierScrCmd_GetCurrentCastlePoints(FrontierScriptContext *ctx) { - FieldFrontierDTO *fieldData; - u16 v1 = FrontierScriptContext_GetVar(param0); - u16 *v2 = FrontierScriptContext_TryGetVarPointer(param0); + u16 challengeType = FrontierScriptContext_GetVar(ctx); + u16 *cp = FrontierScriptContext_TryGetVarPointer(ctx); - fieldData = BattleFrontier_GetFieldData(param0->scriptMan->frontier); - *v2 = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(fieldData->saveData), BattleFrontierStats_GetCastleLatestCPIndex(v1)); + FieldFrontierDTO *fieldData = BattleFrontier_GetFieldData(ctx->scriptMan->frontier); + *cp = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(fieldData->saveData), BattleFrontierStats_GetCastleLatestCPIndex(challengeType)); - return 0; + return FALSE; } -BOOL FrontierScrCmd_A7(FrontierScriptContext *param0) +BOOL FrontierScrCmd_SpendCastlePoints(FrontierScriptContext *ctx) { - FieldFrontierDTO *fieldData; - u16 v1 = FrontierScriptContext_GetVar(param0); - u16 v2 = FrontierScriptContext_GetVar(param0); + u16 challengeType = FrontierScriptContext_GetVar(ctx); + u16 cp = FrontierScriptContext_GetVar(ctx); - fieldData = BattleFrontier_GetFieldData(param0->scriptMan->frontier); - ov104_0223BC2C(SaveData_GetBattleFrontier(fieldData->saveData), v1, v2); + FieldFrontierDTO *fieldData = BattleFrontier_GetFieldData(ctx->scriptMan->frontier); + BattleCastle_SpendCastlePoints(SaveData_GetBattleFrontier(fieldData->saveData), challengeType, cp); - return 0; + return FALSE; } -BOOL FrontierScrCmd_A8(FrontierScriptContext *param0) +BOOL FrontierScrCmd_ReceiveCastlePoints(FrontierScriptContext *ctx) { - u16 v0; - FieldFrontierDTO *fieldData; - u16 v2 = FrontierScriptContext_GetVar(param0); - u16 v3 = FrontierScriptContext_GetVar(param0); + u16 challengeType = FrontierScriptContext_GetVar(ctx); + u16 cp = FrontierScriptContext_GetVar(ctx); - fieldData = BattleFrontier_GetFieldData(param0->scriptMan->frontier); - ov104_02236ED8(fieldData->saveData, v2, v3); + FieldFrontierDTO *fieldData = BattleFrontier_GetFieldData(ctx->scriptMan->frontier); + BattleCastle_ReceiveCastlePoints(fieldData->saveData, challengeType, cp); - return 0; + return FALSE; } -BOOL FrontierScrCmd_A9(FrontierScriptContext *param0) +BOOL FrontierScrCmd_BattleCastle_PrintTrainerIntro(FrontierScriptContext *ctx) { - u16 *v0; - BattleCastle *v1; - FieldFrontierDTO *fieldData = BattleFrontier_GetFieldData(param0->scriptMan->frontier); - u16 v3 = FrontierScriptContext_ReadByte(param0); + FieldFrontierDTO *fieldData = BattleFrontier_GetFieldData(ctx->scriptMan->frontier); + u16 index = FrontierScriptContext_ReadByte(ctx); - v1 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); + BattleCastle *castle = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); - if (v1 == NULL) { - return 0; + if (castle == NULL) { + return FALSE; } - v0 = v1->unk_4C[v3].trDataDTO.introMsg; + u16 *introMsg = castle->opponents[index].trDataDTO.introMsg; - BattleFrontier_PrintNormalTrainerMessage(param0, v0); - return 1; + BattleFrontier_PrintNormalTrainerMessage(ctx, introMsg); + return TRUE; } diff --git a/src/overlay104/frscrcmd_battle_hall.c b/src/overlay104/frscrcmd_battle_hall.c index c0cb50f48e..bea56c051a 100644 --- a/src/overlay104/frscrcmd_battle_hall.c +++ b/src/overlay104/frscrcmd_battle_hall.c @@ -263,13 +263,13 @@ BOOL FrontierScrCmd_CallBattleHallFunction(FrontierScriptContext *ctx) BattleHall_CalcPlayerLevelSqrt(battleHall); break; case BH_FUNC_GET_NEXT_BATTLE_TYPE: - *returnVar = HALL_NEXT_BATTLE_NORMAL; + *returnVar = FRONTIER_NEXT_BATTLE_NORMAL; if (battleHall->challengeType == FRONTIER_CHALLENGE_SINGLE) { if (battleHall->currentStreak + 1 == HALL_STREAK_SILVER_BATTLE) { - *returnVar = HALL_NEXT_BATTLE_SILVER; + *returnVar = FRONTIER_NEXT_BATTLE_SILVER; } else if (battleHall->currentStreak + 1 == HALL_STREAK_GOLD_BATTLE) { - *returnVar = HALL_NEXT_BATTLE_GOLD; + *returnVar = FRONTIER_NEXT_BATTLE_GOLD; } } break; diff --git a/src/overlay104/ov104_0222DCE0.c b/src/overlay104/ov104_0222DCE0.c index bc54b7709f..8bec32ecde 100644 --- a/src/overlay104/ov104_0222DCE0.c +++ b/src/overlay104/ov104_0222DCE0.c @@ -140,95 +140,93 @@ static const u16 Unk_ov104_0223F290[] = { ITEM_QUICK_CLAW }; -u32 ov104_0222DD6C(FrontierPokemonDataDTO *param0, u16 narcIdx, u32 otID, u32 param3, u8 ivs, u8 param5, BOOL param6, int heapID, enum NarcID narcID) +static u32 ov104_0222DD6C(FrontierPokemonDataDTO *mon, u16 narcIdx, u32 otID, u32 personality, u8 ivs, u8 itemIdx, BOOL alwaysFalse, int heapID, enum NarcID narcID) { - MI_CpuClear8(param0, sizeof(FrontierPokemonDataDTO)); + MI_CpuClear8(mon, sizeof(FrontierPokemonDataDTO)); BattleFrontierPokemonData v4; BattleTower_GetMonDataFromSetIDAndNarcID(&v4, narcIdx, narcID); - param0->species = v4.species; - param0->form = v4.form; + mon->species = v4.species; + mon->form = v4.form; - if (param6) { - if (param5 >= NELEMS(Unk_ov104_0223F290)) { - param5 %= NELEMS(Unk_ov104_0223F290); + if (alwaysFalse) { + if (itemIdx >= NELEMS(Unk_ov104_0223F290)) { + itemIdx %= NELEMS(Unk_ov104_0223F290); } - param0->item = Unk_ov104_0223F290[param5]; + mon->item = Unk_ov104_0223F290[itemIdx]; } else { - param0->item = v4.item; + mon->item = v4.item; } u8 friendship = MAX_FRIENDSHIP_VALUE; - for (int v0 = 0; v0 < LEARNED_MOVES_MAX; v0++) { - param0->moves[v0] = v4.moves[v0]; + for (int i = 0; i < LEARNED_MOVES_MAX; i++) { + mon->moves[i] = v4.moves[i]; - if (v4.moves[v0] == MOVE_FRUSTRATION) { + if (v4.moves[i] == MOVE_FRUSTRATION) { friendship = 0; } } - param0->otID = otID; + mon->otID = otID; - u32 v2; - if (param3 == 0) { + if (personality == 0) { do { - v2 = (LCRNG_Next() | LCRNG_Next() << 16); - } while ((v4.nature != Pokemon_GetNatureOf(v2)) || (Pokemon_IsPersonalityShiny(otID, v2) == TRUE)); + personality = LCRNG_Next() | LCRNG_Next() << 16; + } while (v4.nature != Pokemon_GetNatureOf(personality) || Pokemon_IsPersonalityShiny(otID, personality) == TRUE); - param0->personality = v2; + mon->personality = personality; } else { - param0->personality = param3; - v2 = param3; + mon->personality = personality; } - param0->hpIV = ivs; - param0->atkIV = ivs; - param0->defIV = ivs; - param0->speedIV = ivs; - param0->spAtkIV = ivs; - param0->spDefIV = ivs; + mon->hpIV = ivs; + mon->atkIV = ivs; + mon->defIV = ivs; + mon->speedIV = ivs; + mon->spAtkIV = ivs; + mon->spDefIV = ivs; int v1 = 0; - for (int v0 = 0; v0 < 6; v0++) { - if (v4.evFlags & FlagIndex(v0)) { + for (int i = 0; i < STAT_MAX; i++) { + if (v4.evFlags & FlagIndex(i)) { v1++; } } - if ((510 / v1) > 255) { + if (510 / v1 > 255) { v1 = 255; } else { v1 = 510 / v1; } - for (int v0 = 0; v0 < 6; v0++) { + for (int v0 = 0; v0 < STAT_MAX; v0++) { if (v4.evFlags & FlagIndex(v0)) { - param0->evList[v0] = v1; + mon->evList[v0] = v1; } } - param0->combinedPPUps = 0; - param0->language = gGameLanguage; + mon->combinedPPUps = 0; + mon->language = gGameLanguage; - int v0 = SpeciesData_GetSpeciesValue(param0->species, SPECIES_DATA_ABILITY_2); + int ability2 = SpeciesData_GetSpeciesValue(mon->species, SPECIES_DATA_ABILITY_2); - if (v0) { - if (param0->personality & 1) { - param0->ability = v0; + if (ability2) { + if (mon->personality & 1) { + mon->ability = ability2; } else { - param0->ability = SpeciesData_GetSpeciesValue(param0->species, SPECIES_DATA_ABILITY_1); + mon->ability = SpeciesData_GetSpeciesValue(mon->species, SPECIES_DATA_ABILITY_1); } } else { - param0->ability = SpeciesData_GetSpeciesValue(param0->species, SPECIES_DATA_ABILITY_1); + mon->ability = SpeciesData_GetSpeciesValue(mon->species, SPECIES_DATA_ABILITY_1); } - param0->friendship = friendship; - MessageLoader_GetSpeciesName(param0->species, heapID, &(param0->nickname[0])); + mon->friendship = friendship; + MessageLoader_GetSpeciesName(mon->species, heapID, &mon->nickname[0]); - return v2; + return personality; } void FrontierPokemonDataDTO_InitPokemon(const FrontierPokemonDataDTO *pokemonDTO, Pokemon *mon, u8 param2) @@ -424,58 +422,48 @@ void FieldBattleDTO_InitFrontierTrainer(FieldBattleDTO *battleDTO, FrontierTrain return; } -u32 BattleFrontier_LoadOpponentMonData(FrontierPokemonDataDTO *frontierMon, u16 narcIdx, int item, u8 ivs, u32 personality, int heapID, int narcID) +u32 BattleFrontier_LoadOpponentMonData(FrontierPokemonDataDTO *frontierMon, u16 narcIdx, int unused, u8 ivs, u32 personality, int heapID, int narcID) { u32 otID = LCRNG_Next() | (LCRNG_Next() << 16); - return ov104_0222DD6C(frontierMon, narcIdx, otID, personality, ivs, item, FALSE, heapID, narcID); + return ov104_0222DD6C(frontierMon, narcIdx, otID, personality, ivs, unused, FALSE, heapID, narcID); } -void ov104_0222E330(FrontierPokemonDataDTO *param0, u16 param1[], u8 param2[], u32 param3[], u32 param4[], int param5, int param6, int param7) +void ov104_0222E330(FrontierPokemonDataDTO *mons, u16 narcIdx[], u8 ivList[], u32 personalities[], u32 resultPersonalities[], int numMons, int heapID, int narcID) { - int v0; - u32 v1; - u8 v2; + for (int i = 0; i < numMons; i++) { + u8 ivs = ivList == NULL ? 0 : ivList[i]; + u32 personality = (personalities == NULL) ? 0 : personalities[i]; + personality = BattleFrontier_LoadOpponentMonData(&mons[i], narcIdx[i], i, ivs, personality, heapID, narcID); - if (param3 == NULL) { - v1 = 0; - } - - for (v0 = 0; v0 < param5; v0++) { - v2 = (param2 == NULL) ? 0 : param2[v0]; - v1 = (param3 == NULL) ? 0 : param3[v0]; - v1 = BattleFrontier_LoadOpponentMonData(¶m0[v0], param1[v0], v0, v2, v1, param6, param7); - - if (param4 != NULL) { - param4[v0] = v1; + if (resultPersonalities != NULL) { + resultPersonalities[i] = personality; } } - - return; } -u8 ov104_0222E3A8(u16 param0) +static u8 GetIVsForTrainer(u16 trainerID) { - u8 v0; + u8 ivs; - if (param0 < 100) { - v0 = (0x1f / 8) * 1; - } else if (param0 < 120) { - v0 = (0x1f / 8) * 2; - } else if (param0 < 140) { - v0 = (0x1f / 8) * 3; - } else if (param0 < 160) { - v0 = (0x1f / 8) * 4; - } else if (param0 < 180) { - v0 = (0x1f / 8) * 5; - } else if (param0 < 200) { - v0 = (0x1f / 8) * 6; - } else if (param0 < 220) { - v0 = (0x1f / 8) * 7; + if (trainerID < 100) { + ivs = (MAX_IVS_SINGLE_STAT / 8) * 1; + } else if (trainerID < 120) { + ivs = (MAX_IVS_SINGLE_STAT / 8) * 2; + } else if (trainerID < 140) { + ivs = (MAX_IVS_SINGLE_STAT / 8) * 3; + } else if (trainerID < 160) { + ivs = (MAX_IVS_SINGLE_STAT / 8) * 4; + } else if (trainerID < 180) { + ivs = (MAX_IVS_SINGLE_STAT / 8) * 5; + } else if (trainerID < 200) { + ivs = (MAX_IVS_SINGLE_STAT / 8) * 6; + } else if (trainerID < 220) { + ivs = (MAX_IVS_SINGLE_STAT / 8) * 7; } else { - v0 = 0x1f; + ivs = MAX_IVS_SINGLE_STAT; } - return v0; + return ivs; } BOOL ov104_0222E3E4(BattleFrontierTrainerData *param0, const u16 param1[], const u16 param2[], int param3, int param4, u16 param5[], int param6) @@ -529,50 +517,47 @@ BOOL ov104_0222E3E4(BattleFrontierTrainerData *param0, const u16 param1[], const return 0; } -void ov104_0222E4BC(u8 param0, u16 param1, u16 param2, u16 *param3, FrontierPokemonDataDTO *param4, u8 *param5, u32 *param6, u8 param7) +void ov104_0222E4BC(u8 numMons, u16 trainerID, u16 trainerID2, u16 *monSetIDs, FrontierPokemonDataDTO *param4, u8 *ivs, u32 *personalities, u8 isMultiplayerChallenge) { - int v0; + int i; u16 v2[4]; u16 v3[4]; - FrontierTrainerDataDTO v4; - BattleFrontierPokemonData v6; - BattleFrontierTrainerData *v5 = BattleFrontier_GetTrainerData(&v4, param1, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR); + FrontierTrainerDataDTO trainer; + BattleFrontierTrainerData *trainerSpec = BattleFrontier_GetTrainerData(&trainer, trainerID, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR); - for (v0 = 0; v0 < param0; v0++) { - param5[v0] = ov104_0222E3A8(param1); + for (i = 0; i < numMons; i++) { + ivs[i] = GetIVsForTrainer(trainerID); } - if (param7 == 0) { - ov104_0222E3E4(v5, v2, v3, 0, param0, param3, 11); + if (!isMultiplayerChallenge) { + ov104_0222E3E4(trainerSpec, v2, v3, 0, numMons, monSetIDs, 11); } else { - ov104_0222E3E4(v5, v2, v3, 0, (param0 / 2), param3, 11); + ov104_0222E3E4(trainerSpec, v2, v3, 0, (numMons / 2), monSetIDs, 11); - for (v0 = 0; v0 < (param0 / 2); v0++) { - BattleTower_GetMonDataFromSetIDAndNarcID(&v6, param3[v0], NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); - v2[v0] = v6.species; - v3[v0] = v6.item; + for (i = 0; i < (numMons / 2); i++) { + BattleFrontierPokemonData v6; + BattleTower_GetMonDataFromSetIDAndNarcID(&v6, monSetIDs[i], NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); + v2[i] = v6.species; + v3[i] = v6.item; } - Heap_Free(v5); - v5 = BattleFrontier_GetTrainerData(&v4, param2, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR); - ov104_0222E3E4(v5, v2, v3, (param0 / 2), (param0 / 2), ¶m3[param0 / 2], 11); + Heap_Free(trainerSpec); + trainerSpec = BattleFrontier_GetTrainerData(&trainer, trainerID2, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR); + ov104_0222E3E4(trainerSpec, v2, v3, (numMons / 2), (numMons / 2), &monSetIDs[numMons / 2], 11); - for (v0 = 0; v0 < (param0 / 2); v0++) { - param5[v0 + (param0 / 2)] = ov104_0222E3A8(param2); + for (i = 0; i < (numMons / 2); i++) { + ivs[i + (numMons / 2)] = GetIVsForTrainer(trainerID2); } } - Heap_Free(v5); - ov104_0222E330(param4, param3, param5, NULL, param6, param0, 11, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); - - return; + Heap_Free(trainerSpec); + ov104_0222E330(param4, monSetIDs, ivs, NULL, personalities, numMons, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); } void BattleFrontier_SetPartnerInStrTemplate(StringTemplate *template, u32 idx) { StringTemplate_SetPlayerName(template, idx, CommInfo_TrainerInfo(CommSys_CurNetId() ^ 1)); - return; } enum ObjectEventGfx BattleFrontier_GetPlayerObjEventGfx(const TrainerInfo *playerInfo) diff --git a/src/overlay104/ov104_0222ECE8.c b/src/overlay104/ov104_0222ECE8.c index c1ddb2c8b0..9cc0d3919a 100644 --- a/src/overlay104/ov104_0222ECE8.c +++ b/src/overlay104/ov104_0222ECE8.c @@ -3,17 +3,16 @@ #include #include -#include "struct_decls/struct_0203041C_decl.h" #include "struct_decls/struct_020305B8_decl.h" +#include "overlay104/battle_castle_helpers.h" #include "overlay104/battle_hall.h" #include "overlay104/ov104_0223A7F4.h" -#include "overlay104/ov104_0223B6F4.h" #include "overlay104/ov104_0223BCBC.h" #include "overlay104/struct_battle_arcade.h" -#include "overlay104/struct_battle_castle.h" #include "overlay104/struct_battle_factory.h" +#include "battle_castle_save.h" #include "battle_frontier_save.h" #include "battle_frontier_stats.h" #include "communication_system.h" @@ -22,7 +21,6 @@ #include "pokemon.h" #include "save_player.h" #include "trainer_info.h" -#include "unk_020302D0.h" #include "unk_02030494.h" BOOL ov104_0222EEF8(BattleFactory *param0); @@ -725,12 +723,12 @@ void ov104_0222F31C(int param0, int param1, void *param2, void *param3) BOOL ov104_0222F3B8(BattleCastle *param0) { int v0, v1, v2, v3; - UnkStruct_0203041C *v4 = sub_0203041C(param0->saveData); + BattleCastlePersistentSave *v4 = BattleCastlePersistentSave_Get(param0->saveData); v3 = 40; v1 = 0; param0->unk_3C0[1] = param0->currentStreak; - param0->unk_3C0[2] = param0->unk_16; + param0->unk_3C0[2] = param0->currentRound; v1 += 3; v1 += (7 + 1); @@ -754,7 +752,7 @@ void ov104_0222F418(int param0, int param1, void *param2, void *param3) const u16 *v3 = param2; v1 = 0; - v2->unk_A1A++; + v2->msgsReceived++; if (CommSys_CurNetId() == param0) { return; @@ -801,7 +799,7 @@ void ov104_0222F480(int param0, int param1, void *param2, void *param3) const u16 *v3 = param2; v1 = 0; - v2->unk_A1A++; + v2->msgsReceived++; if (CommSys_CurNetId() == param0) { return; @@ -867,7 +865,7 @@ void ov104_0222F530(int param0, int param1, void *param2, void *param3) const u16 *v4 = param2; v2 = 0; - v3->unk_A1A++; + v3->msgsReceived++; if (CommSys_CurNetId() == param0) { return; @@ -917,20 +915,20 @@ BOOL ov104_0222F5D4(BattleCastle *param0) v3 = 40; for (v0 = 0; v0 < 4; v0++) { - param0->unk_3C0[v0] = param0->unk_26C[v0]; + param0->unk_3C0[v0] = param0->monSetIDs[v0]; } v1 += 4; for (v0 = 0; v0 < 4; v0++) { - param0->unk_3C0[v0 + v1] = param0->unk_274[v0]; + param0->unk_3C0[v0 + v1] = param0->opponentMonIVs[v0]; } v1 += 4; for (v0 = 0; v0 < 4; v0++) { - param0->unk_3C0[v0 + v1] = (param0->unk_278[v0] & 0xffff); - param0->unk_3C0[v0 + v1 + 4] = ((param0->unk_278[v0] >> 16) & 0xffff); + param0->unk_3C0[v0 + v1] = (param0->opponentMonPersonalities[v0] & 0xffff); + param0->unk_3C0[v0 + v1 + 4] = ((param0->opponentMonPersonalities[v0] >> 16) & 0xffff); } v1 += (4 * 2); @@ -951,7 +949,7 @@ void ov104_0222F650(int param0, int param1, void *param2, void *param3) const u16 *v3 = param2; v1 = 0; - v2->unk_A1A++; + v2->msgsReceived++; if (CommSys_CurNetId() == param0) { return; @@ -962,20 +960,20 @@ void ov104_0222F650(int param0, int param1, void *param2, void *param3) } for (v0 = 0; v0 < 4; v0++) { - v2->unk_26C[v0] = v3[v0]; + v2->monSetIDs[v0] = v3[v0]; } v1 += 4; for (v0 = 0; v0 < 4; v0++) { - v2->unk_274[v0] = v3[v0 + v1]; + v2->opponentMonIVs[v0] = v3[v0 + v1]; } v1 += 4; for (v0 = 0; v0 < 4; v0++) { - v2->unk_278[v0] = v3[v0 + v1]; - v2->unk_278[v0] |= (v3[v0 + v1 + 4] << 16); + v2->opponentMonPersonalities[v0] = v3[v0 + v1]; + v2->opponentMonPersonalities[v0] |= (v3[v0 + v1 + 4] << 16); } v1 += (4 * 2); @@ -1004,7 +1002,7 @@ void ov104_0222F6E8(int param0, int param1, void *param2, void *param3) const u16 *v2 = param2; v0 = 0; - v1->unk_A1A++; + v1->msgsReceived++; if (CommSys_CurNetId() == param0) { return; @@ -1035,7 +1033,7 @@ void ov104_0222F730(int param0, int param1, void *param2, void *param3) const u16 *v2 = param2; v0 = 0; - v1->unk_A1A++; + v1->msgsReceived++; if (CommSys_CurNetId() == param0) { return; @@ -1079,7 +1077,7 @@ void ov104_0222F7BC(int param0, int param1, void *param2, void *param3) const u8 *v6 = param2; v2 = 0; - v5->unk_A1A++; + v5->msgsReceived++; if (CommSys_CurNetId() == param0) { return; diff --git a/src/overlay104/ov104_022361B4.c b/src/overlay104/ov104_022361B4.c deleted file mode 100644 index 53b974c1f3..0000000000 --- a/src/overlay104/ov104_022361B4.c +++ /dev/null @@ -1,815 +0,0 @@ -#include "overlay104/ov104_022361B4.h" - -#include - -#include "constants/heap.h" -#include "generated/game_records.h" - -#include "struct_decls/struct_020302DC_decl.h" -#include "struct_decls/struct_0203041C_decl.h" -#include "struct_defs/battle_frontier.h" - -#include "applications/frontier/battle_castle/args.h" -#include "overlay104/defs.h" -#include "overlay104/frontier_script_manager.h" -#include "overlay104/ov104_0222DCE0.h" -#include "overlay104/ov104_0222ECE8.h" -#include "overlay104/ov104_0223B6F4.h" -#include "overlay104/struct_battle_castle.h" - -#include "battle_frontier_save.h" -#include "battle_frontier_stats.h" -#include "bg_window.h" -#include "communication_information.h" -#include "communication_system.h" -#include "game_records.h" -#include "heap.h" -#include "message.h" -#include "party.h" -#include "pokemon.h" -#include "render_window.h" -#include "save_player.h" -#include "savedata.h" -#include "string_gf.h" -#include "string_template.h" -#include "system_vars.h" -#include "text.h" -#include "trainer_info.h" -#include "unk_020302D0.h" -#include "vars_flags.h" - -void ov104_02236514(BattleCastle *param0, u16 param1); -static void ov104_02236528(BattleCastle *param0); -static void ov104_022365F8(BattleCastle *param0); -static void ov104_022366A4(BattleCastle *param0); -void ov104_022367AC(BattleCastle *param0); -static u16 GetBattleCastleAppSelectedSlot(BattleCastleAppArgs *args, u8 i); -void ov104_02236BF0(BattleCastle *param0); -void ov104_02236BF8(BattleCastle *param0); -void ov104_02236C50(BattleCastle *param0); -int ov104_02236D10(BattleCastle *param0); -BOOL ov104_02236F70(BattleCastle *param0, u16 param1, u16 param2); -void ov104_02236FC0(FrontierScriptManager *param0, BattleCastle *param1); -void ov104_022370E0(FrontierScriptManager *param0, BattleCastle *param1); -void ov104_02237180(FrontierScriptManager *param0, BattleCastle *param1); -static void ov104_022370C0(BgConfig *param0, Window *param1); -static void ov104_02237284(FrontierScriptManager *param0, Window *param1, TrainerInfo *param2, u16 param3); -u16 ov104_02237338(BattleCastle *param0); - -BattleCastle *ov104_022361B4(SaveData *saveData, u16 param1, u8 param2, u16 param3, u16 param4, u16 param5, u16 *param6) -{ - u32 v0, v1; - Party *v2; - Pokemon *v3; - UnkStruct_020302DC *v4; - u8 v5, v6; - u16 v7, v8; - static BattleCastle *v9; - UnkStruct_0203041C *v10; - - v9 = Heap_Alloc(HEAP_ID_FIELD2, sizeof(BattleCastle)); - MI_CpuClear8(v9, sizeof(BattleCastle)); - - v9->unk_08 = sub_020302DC(saveData); - v9->saveData = saveData; - v9->unk_00 = 11; - v9->playersParty = Party_New(HEAP_ID_FIELD2); - v9->opponentsParty = Party_New(HEAP_ID_FIELD2); - v9->unk_A20 = param6; - - v4 = v9->unk_08; - v10 = sub_0203041C(saveData); - - if (param1 == 0) { - v9->challengeType = param2; - v9->unk_11 = 0; - - sub_020302D0(v4); - - if (v9->challengeType == 3) { - v5 = SystemVars_GetWiFiFrontierCleared(SaveData_GetVarsFlags(v9->saveData)); - } else { - v5 = (u8)sub_02030470(v10, 9, v9->challengeType, 0, NULL); - } - - if (v5 == 1) { - v9->currentStreak = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(v9->saveData), BattleFrontierStats_GetCastleLatestStreakIndex(v9->challengeType)); - } else { - v9->currentStreak = 0; - - BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(v9->saveData), BattleFrontierStats_GetCastleLatestCPIndex(v9->challengeType), 0); - BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(v9->saveData), BattleFrontierStats_GetCastleSpentCPIndex(param2), 0); - - for (v7 = 0; v7 < 3; v7++) { - BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(v9->saveData), BattleFrontierStats_GetCastleRankIndex(v9->challengeType, v7), 1); - } - } - - v9->unk_16 = (u16)(v9->currentStreak / 7); - v9->unk_18 = 0; - v9->unk_24[0] = param3; - v9->unk_24[1] = param4; - v9->unk_24[2] = param5; - v9->unk_20 = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(v9->saveData), BattleFrontierStats_GetCastleLatestCPIndex(v9->challengeType)); - - BattleFrontierSave_AddToStat(SaveData_GetBattleFrontier(v9->saveData), BattleFrontierStats_GetCastleLatestCPIndex(v9->challengeType), BattleFrontierStats_GetHostFriendIdx(BattleFrontierStats_GetCastleLatestCPIndex(v9->challengeType)), 10); - } else { - v9->challengeType = (u8)sub_02030398(v4, 0, 0, 0, NULL); - v9->unk_11 = (u8)sub_02030398(v4, 1, 0, 0, NULL); - v9->currentStreak = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(v9->saveData), BattleFrontierStats_GetCastleLatestStreakIndex(v9->challengeType)); - v9->unk_16 = (u16)(v9->currentStreak / 7); - - for (v7 = 0; v7 < 3; v7++) { - v9->unk_24[v7] = (u8)sub_02030398(v4, 7, v7, 0, NULL); - } - } - - for (v7 = 0; v7 < 3; v7++) { - v3 = Party_GetPokemonBySlotIndex(SaveData_GetParty(v9->saveData), v9->unk_24[v7]); - v9->unk_36A[v7] = Pokemon_GetValue(v3, MON_DATA_HELD_ITEM, NULL); - } - - v2 = SaveData_GetParty(v9->saveData); - v6 = BattleCastle_GetPlayerPartySize(v9->challengeType, 0); - - for (v7 = 0; v7 < v6; v7++) { - Party_AddPokemon(v9->playersParty, Party_GetPokemonBySlotIndex(v2, v9->unk_24[v7])); - - v3 = Party_GetPokemonBySlotIndex(v9->playersParty, v7); - v0 = 0; - - Pokemon_SetValue(v3, MON_DATA_HELD_ITEM, &v0); - - if (Pokemon_GetValue(v3, MON_DATA_LEVEL, NULL) > 50) { - v1 = Pokemon_GetSpeciesBaseExpAt(Pokemon_GetValue(v3, MON_DATA_SPECIES, NULL), 50); - Pokemon_SetValue(v3, MON_DATA_EXPERIENCE, &v1); - Pokemon_CalcLevelAndStats(v3); - } - } - - if (BattleCastle_IsMultiPlayerChallenge(v9->challengeType) == 1) { - BattleFrontier_FlagGeonetLinkInfo(v9->saveData); - } - - return v9; -} - -void ov104_02236514(BattleCastle *param0, u16 param1) -{ - if (param1 == 0) { - ov104_02236528(param0); - } else { - ov104_022365F8(param0); - } - - return; -} - -static void ov104_02236528(BattleCastle *param0) -{ - u8 v0 = Party_GetCurrentCount(param0->playersParty); - - for (int i = 0; i < v0; i++) { - Pokemon *mon = Party_GetPokemonBySlotIndex(param0->playersParty, i); - - param0->unk_394[i][0] = Pokemon_GetValue(mon, MON_DATA_MOVE1_PP, NULL); - param0->unk_394[i][1] = Pokemon_GetValue(mon, MON_DATA_MOVE2_PP, NULL); - param0->unk_394[i][2] = Pokemon_GetValue(mon, MON_DATA_MOVE3_PP, NULL); - param0->unk_394[i][3] = Pokemon_GetValue(mon, MON_DATA_MOVE4_PP, NULL); - } - - ov104_0223B760(param0->challengeType, ov104_0223BB60(param0), param0->trainerIDs, 7 * 2); - - ov104_0222E4BC(BattleCastle_GetOpponentPartySize(param0->challengeType, 1), param0->trainerIDs[param0->unk_11], param0->trainerIDs[param0->unk_11 + 7], param0->unk_26C, param0->unk_288, param0->unk_274, param0->unk_278, BattleCastle_IsMultiPlayerChallenge(param0->challengeType)); - - return; -} - -static void ov104_022365F8(BattleCastle *param0) -{ - u16 v0; - int v1; - Pokemon *v2; - u8 v3; - FrontierPokemonDataDTO v4[6]; - u8 v5[6]; - u16 v6[6]; - u32 v7[6]; - - ov104_022366A4(param0); - - for (v1 = 0; v1 < (7 * 2); v1++) { - param0->trainerIDs[v1] = (u16)sub_02030398(param0->unk_08, 6, v1, 0, NULL); - } - - for (v1 = 0; v1 < 4; v1++) { - v6[v1] = (u16)sub_02030398(param0->unk_08, 8, v1, 0, NULL); - param0->unk_26C[v1] = v6[v1]; - } - - ov104_0222E330(v4, v6, v5, NULL, v7, 4, 11, 179); - - v2 = Pokemon_New(HEAP_ID_FIELD2); - - for (v1 = 0; v1 < 4; v1++) { - FrontierPokemonDataDTO_InitPokemon(&v4[v1], v2, BattleCastle_GetOpponentLevel(param0)); - ov104_0223BAA0(param0, param0->opponentsParty, v2); - } - - Heap_Free(v2); - - return; -} - -static void ov104_022366A4(BattleCastle *param0) -{ - u8 v0; - u32 v1; - u16 v2; - u8 v3; - int v4; - Pokemon *v5; - - v0 = Party_GetCurrentCount(param0->playersParty); - - for (v4 = 0; v4 < v0; v4++) { - v5 = Party_GetPokemonBySlotIndex(param0->playersParty, v4); - - v2 = (u16)sub_02030398(param0->unk_08, 2, v4, 0, NULL); - Pokemon_SetValue(v5, MON_DATA_HP, &v2); - - v3 = (u8)sub_02030398(param0->unk_08, 3, v4, 0, NULL); - Pokemon_SetValue(v5, MON_DATA_MOVE1_PP, &v3); - - v3 = (u8)sub_02030398(param0->unk_08, 3, v4, 1, NULL); - Pokemon_SetValue(v5, MON_DATA_MOVE2_PP, &v3); - - v3 = (u8)sub_02030398(param0->unk_08, 3, v4, 2, NULL); - Pokemon_SetValue(v5, MON_DATA_MOVE3_PP, &v3); - - v3 = (u8)sub_02030398(param0->unk_08, 3, v4, 3, NULL); - Pokemon_SetValue(v5, MON_DATA_MOVE4_PP, &v3); - - v1 = (u32)sub_02030398(param0->unk_08, 4, v4, 0, NULL); - Pokemon_SetValue(v5, MON_DATA_STATUS, &v1); - - v2 = (u16)sub_02030398(param0->unk_08, 5, v4, 0, NULL); - Pokemon_SetValue(v5, MON_DATA_HELD_ITEM, &v2); - } - - return; -} - -void ov104_022367AC(BattleCastle *param0) -{ - int v0; - - if (param0 == NULL) { - return; - } - - if (param0->playersParty != NULL) { - Heap_Free(param0->playersParty); - } - - if (param0->opponentsParty != NULL) { - Heap_Free(param0->opponentsParty); - } - - MI_CpuClear8(param0, sizeof(BattleCastle)); - Heap_Free(param0); - - param0 = NULL; - - return; -} - -void BattleCastle_StoreAppResults(BattleCastle *battleCastle, BattleCastleAppArgs *args) -{ - for (int i = 0; i < 6; i++) { - battleCastle->unk_380[i] = GetBattleCastleAppSelectedSlot(args, i); - } - - for (int i = 0; i < 4; i++) { - battleCastle->appIdentityUnlocked[i] = args->identityUnlocked[i]; - battleCastle->appLevelAdjustmentsUnlocked[i] = args->levelAdjustmentUnlocked[i]; - battleCastle->appStatsUnlocked[i] = args->statsUnlocked[i]; - battleCastle->appMovesUnlocked[i] = args->movesUnlocked[i]; - } - - battleCastle->partnersCP = args->partnersCP; -} - -static u16 GetBattleCastleAppSelectedSlot(BattleCastleAppArgs *args, u8 i) -{ - if (i >= 6) { - GF_ASSERT(FALSE); - return 0; - } - - return args->selectedMonSlot; -} - -void ov104_02236848(BattleCastle *param0, u8 param1) -{ - u16 v0, v1, v2; - u8 v3; - u8 v4[4]; - u16 v5[4]; - u32 v6[4]; - u32 v7, v8, v9; - BattleFrontierSave *frontier; - Pokemon *v11; - UnkStruct_020302DC *v12 = param0->unk_08; - UnkStruct_0203041C *v13 = sub_0203041C(param0->saveData); - - frontier = SaveData_GetBattleFrontier(param0->saveData); - v3 = BattleCastle_GetOpponentPartySize(param0->challengeType, 1); - v4[0] = param0->challengeType; - - sub_02030308(param0->unk_08, 0, 0, 0, v4); - sub_020302F4(param0->unk_08, 1); - - v4[0] = param0->unk_11; - - sub_02030308(param0->unk_08, 1, 0, 0, v4); - BattleFrontierSave_SetStatAutoHostIdx(frontier, BattleFrontierStats_GetCastleLatestStreakIndex(param0->challengeType), param0->currentStreak); - - if (param1 != 2) { - v1 = BattleFrontierSave_GetStatAutoHostIdx(frontier, BattleFrontierStats_GetCastleRecordStreakIndex(param0->challengeType)); - v7 = BattleFrontierSave_SetIfBetterAutoHostIdx(frontier, BattleFrontierStats_GetCastleRecordStreakIndex(param0->challengeType), param0->currentStreak); - v2 = BattleFrontierSave_GetStatAutoHostIdx(frontier, BattleFrontierStats_GetCastleRecordStreakIndex(param0->challengeType)); - v9 = BattleFrontierSave_GetStatAutoHostIdx(frontier, BattleFrontierStats_GetCastleLatestCPIndex(param0->challengeType)); - - if (param0->currentStreak == v1) { - BattleFrontierSave_SetIfBetterAutoHostIdx(frontier, BattleFrontierStats_GetCastleRecordCPIndex(param0->challengeType), v9); - } else if (v1 < v2) { - BattleFrontierSave_SetStatAutoHostIdx(frontier, BattleFrontierStats_GetCastleRecordCPIndex(param0->challengeType), v9); - } - - v4[0] = param0->unk_27; - sub_02030430(v13, 9, param0->challengeType, 0, v4); - - if (param0->challengeType == 3) { - BattleFrontierSave_SetStatAutoHostIdx(frontier, STAT_CASTLE_WFC_STREAK_ACTIVE, param0->unk_27); - } - } - - for (v0 = 0; v0 < (7 * 2); v0++) { - v5[0] = param0->trainerIDs[v0]; - sub_02030308(param0->unk_08, 6, v0, 0, v5); - } - - for (v0 = 0; v0 < 3; v0++) { - v4[0] = param0->unk_24[v0]; - sub_02030308(param0->unk_08, 7, v0, 0, v4); - } - - v8 = Party_GetCurrentCount(param0->playersParty); - - for (v0 = 0; v0 < v8; v0++) { - v11 = Party_GetPokemonBySlotIndex(param0->playersParty, v0); - - v5[0] = Pokemon_GetValue(v11, MON_DATA_HP, NULL); - sub_02030308(param0->unk_08, 2, v0, 0, v5); - - v4[0] = Pokemon_GetValue(v11, MON_DATA_MOVE1_PP, NULL); - sub_02030308(param0->unk_08, 3, v0, 0, v4); - - v4[0] = Pokemon_GetValue(v11, MON_DATA_MOVE2_PP, NULL); - sub_02030308(param0->unk_08, 3, v0, 1, v4); - - v4[0] = Pokemon_GetValue(v11, MON_DATA_MOVE3_PP, NULL); - sub_02030308(param0->unk_08, 3, v0, 2, v4); - - v4[0] = Pokemon_GetValue(v11, MON_DATA_MOVE4_PP, NULL); - sub_02030308(param0->unk_08, 3, v0, 3, v4); - - v6[0] = Pokemon_GetValue(v11, MON_DATA_STATUS, NULL); - sub_02030308(param0->unk_08, 4, v0, 0, v6); - - v5[0] = Pokemon_GetValue(v11, MON_DATA_HELD_ITEM, NULL); - sub_02030308(param0->unk_08, 5, v0, 0, v5); - } - - v8 = Party_GetCurrentCount(param0->opponentsParty); - - for (v0 = 0; v0 < v8; v0++) { - v11 = Party_GetPokemonBySlotIndex(param0->opponentsParty, v0); - v5[0] = param0->unk_26C[v0]; - - sub_02030308(param0->unk_08, 8, v0, 0, v5); - } - - return; -} - -u16 ov104_02236B48(BattleCastle *param0) -{ - param0->unk_11++; - return param0->unk_11; -} - -u16 ov104_02236B54(BattleCastle *param0) -{ - return param0->unk_11; -} - -u16 ov104_02236B58(BattleCastle *param0, u8 param1) -{ - FrontierTrainerDataDTO v0; - u8 v2 = param0->unk_11 + (param1 * 7); - - Heap_Free(BattleFrontier_GetTrainerData(&v0, param0->trainerIDs[v2], HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR)); - - return BattleTower_GetObjectIDFromTrainerClass(v0.trainerType); -} - -void ov104_02236B8C(BattleCastle *param0) -{ - u16 v0[4]; - int v1; - - v0[0] = 1; - - for (v1 = 0; v1 < 3; v1++) { - BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(param0->saveData), BattleFrontierStats_GetCastleRankIndex(param0->challengeType, v1), 1); - } - - ov104_02236848(param0, 1); - - return; -} - -void ov104_02236BD0(BattleCastle *param0) -{ - param0->unk_27 = 1; - - if (param0->unk_16 < 8) { - param0->unk_16++; - } - - param0->unk_11 = 0; - ov104_02236848(param0, 0); - - return; -} - -void ov104_02236BF0(BattleCastle *param0) -{ - ov104_0223BAB8(param0); - return; -} - -void ov104_02236BF8(BattleCastle *param0) -{ - int v0, v1, v2; - - ov104_0222E4BC(BattleCastle_GetOpponentPartySize(param0->challengeType, 1), param0->trainerIDs[param0->unk_11], param0->trainerIDs[param0->unk_11 + 7], param0->unk_26C, param0->unk_288, param0->unk_274, param0->unk_278, BattleCastle_IsMultiPlayerChallenge(param0->challengeType)); - - for (v0 = 0; v0 < 4; v0++) { - (void)0; - } - - ov104_0223BAB8(param0); - return; -} - -void ov104_02236C50(BattleCastle *param0) -{ - u8 v0, v1; - int v2, v3; - Pokemon *v4; - - if (CommSys_CurNetId() == 0) { - v0 = 0; - } else { - v0 = 2; - } - - v1 = BattleCastle_GetPlayerPartySize(param0->challengeType, 0); - v3 = Party_GetCurrentCount(param0->playersParty); - - for (v2 = v0; v2 < (v1 + v0); v2++) { - v4 = Party_GetPokemonBySlotIndex(param0->playersParty, v2); - - param0->unk_394[v2 - v0][0] = Pokemon_GetValue(v4, MON_DATA_MOVE1_PP, NULL); - param0->unk_394[v2 - v0][1] = Pokemon_GetValue(v4, MON_DATA_MOVE2_PP, NULL); - param0->unk_394[v2 - v0][2] = Pokemon_GetValue(v4, MON_DATA_MOVE3_PP, NULL); - param0->unk_394[v2 - v0][3] = Pokemon_GetValue(v4, MON_DATA_MOVE4_PP, NULL); - } - - ov104_0223BA24(param0->playersParty); - - for (v2 = 0; v2 < 4; v2++) { - param0->appIdentityUnlocked[v2] = 0; - param0->appLevelAdjustmentsUnlocked[v2] = 0; - param0->appStatsUnlocked[v2] = 0; - param0->appMovesUnlocked[v2] = 0; - } - - return; -} - -int ov104_02236D10(BattleCastle *param0) -{ - u8 v0, v1, v2; - u32 v3, v4; - int v5, v6, v7, v8; - Pokemon *v9; - u8 v10[20]; - int v11 = 0; - - for (v5 = 0; v5 < 20; v5++) { - v10[v5] = 0; - } - - param0->unk_12 = 0; - v8 = 0; - - if (CommSys_CurNetId() == 0) { - v2 = 0; - } else { - v2 = 2; - } - - v0 = BattleCastle_GetPlayerPartySize(param0->challengeType, 0); - v1 = BattleCastle_GetOpponentPartySize(param0->challengeType, 1); - - for (v5 = v2; v5 < (v0 + v2); v5++) { - v9 = Party_GetPokemonBySlotIndex(param0->playersParty, v5); - - if (Pokemon_GetValue(v9, MON_DATA_SPECIES_EXISTS, NULL) == 0) { - continue; - } - - v3 = Pokemon_GetValue(v9, MON_DATA_HP, NULL); - v4 = Pokemon_GetValue(v9, MON_DATA_MAX_HP, NULL); - - if (v3 > 0) { - v10[0]++; - - if (v3 == v4) { - v10[1]++; - } else { - if (v3 >= (v4 / 2)) { - v10[2]++; - } else { - v10[3]++; - } - } - - if (Pokemon_GetValue(v9, MON_DATA_STATUS, NULL) == 0) { - v10[4]++; - } - } else { - param0->unk_12 = 1; - } - - v8 += Pokemon_GetValue(v9, MON_DATA_MOVE1_PP, NULL); - v8 += Pokemon_GetValue(v9, MON_DATA_MOVE2_PP, NULL); - v8 += Pokemon_GetValue(v9, MON_DATA_MOVE3_PP, NULL); - v8 += Pokemon_GetValue(v9, MON_DATA_MOVE4_PP, NULL); - } - - for (v5 = 0; v5 < v1; v5++) { - if (param0->appLevelAdjustmentsUnlocked[v5] == 1) { - v10[8]++; - } else if (param0->appLevelAdjustmentsUnlocked[v5] == 2) { - (void)0; - } - } - - v7 = 0; - - for (v5 = 0; v5 < v0; v5++) { - for (v6 = 0; v6 < 4; v6++) { - v7 += param0->unk_394[v5][v6]; - } - } - - if ((v7 - v8) <= 5) { - v10[5]++; - } else if ((v7 - v8) <= 10) { - v10[6]++; - } else if ((v7 - v8) <= 15) { - v10[7]++; - } - - v11 += v10[0] * 3; - v11 += v10[1] * 3; - v11 += v10[2] * 2; - v11 += v10[3] * 1; - v11 += v10[4] * 1; - v11 += v10[5] * 8; - v11 += v10[6] * 6; - v11 += v10[7] * 4; - v11 += v10[8] * 7; - - if (v11 <= 0) { - v11 = 1; - } - - return v11; -} - -void ov104_02236ED8(SaveData *saveData, u8 param1, int param2) -{ - u16 v0 = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(saveData), BattleFrontierStats_GetCastleLatestCPIndex(param1)); - - if (v0 + param2 > 9999) { - BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(saveData), BattleFrontierStats_GetCastleLatestCPIndex(param1), 9999); - } else { - BattleFrontierSave_AddToStat(SaveData_GetBattleFrontier(saveData), BattleFrontierStats_GetCastleLatestCPIndex(param1), BattleFrontierStats_GetHostFriendIdx(BattleFrontierStats_GetCastleLatestCPIndex(param1)), param2); - } - - GameRecords_AddToRecordValue(SaveData_GetGameRecords(saveData), RECORD_UNK_065, param2); - return; -} - -BOOL ov104_02236F70(BattleCastle *param0, u16 param1, u16 param2) -{ - int v0; - - switch (param1) { - case 0: - v0 = ov104_0222F3B8(param0); - break; - case 1: - v0 = ov104_0222F44C(param0); - break; - case 2: - v0 = ov104_0222F4B8(param0); - break; - case 3: - v0 = ov104_0222F5D4(param0); - break; - case 4: - v0 = ov104_0222F6C8(param0, param2); - break; - case 5: - v0 = ov104_0222F710(param0, param2); - break; - case 6: - v0 = ov104_0222F758(param0); - break; - } - - return v0; -} - -void ov104_02236FC0(FrontierScriptManager *param0, BattleCastle *param1) -{ - FrontierGraphics *v0 = FrontierScriptManager_GetGraphics(param0); - - GF_ASSERT(param0->unk_A8 == NULL); - GF_ASSERT(param0->unk_AC == NULL); - - if (BattleCastle_IsMultiPlayerChallenge(param1->challengeType) == 0) { - param0->unk_A8 = Window_New(HEAP_ID_FIELD2, 1); - Window_Add(v0->bgConfig, param0->unk_A8, 1, 1, 1, 10, 4, 14, ((((1024 - (18 + 12)) - 9) - (27 * 4)) - (11 * 22)) - (10 * 4)); - ov104_022370C0(v0->bgConfig, param0->unk_A8); - } else { - param0->unk_A8 = Window_New(HEAP_ID_FIELD2, 1); - param0->unk_AC = Window_New(HEAP_ID_FIELD2, 1); - - Window_Add(v0->bgConfig, param0->unk_A8, 1, 1, 1, 10, 4, 14, ((((1024 - (18 + 12)) - 9) - (27 * 4)) - (11 * 22)) - (10 * 4)); - Window_Add(v0->bgConfig, param0->unk_AC, 1, 21, 1, 10, 4, 14, (((((1024 - (18 + 12)) - 9) - (27 * 4)) - (11 * 22)) - (10 * 4)) - (10 * 4)); - - ov104_022370C0(v0->bgConfig, param0->unk_A8); - ov104_022370C0(v0->bgConfig, param0->unk_AC); - } - - ov104_02237180(param0, param1); - return; -} - -static void ov104_022370C0(BgConfig *param0, Window *param1) -{ - Window_DrawStandardFrame(param1, 1, (1024 - (18 + 12)) - 9, 12); - Window_FillTilemap(param1, 15); - - return; -} - -void ov104_022370E0(FrontierScriptManager *param0, BattleCastle *param1) -{ - Window *v0; - Window *v1; - - if (BattleCastle_IsMultiPlayerChallenge(param1->challengeType) == 0) { - GF_ASSERT(param0->unk_A8 != NULL); - v0 = param0->unk_A8; - Window_EraseStandardFrame(v0, 0); - Windows_Delete(v0, 1); - } else { - GF_ASSERT(param0->unk_A8 != NULL); - GF_ASSERT(param0->unk_AC != NULL); - - if (CommSys_CurNetId() == 0) { - v0 = param0->unk_A8; - v1 = param0->unk_AC; - } else { - v0 = param0->unk_AC; - v1 = param0->unk_A8; - } - - Window_EraseStandardFrame(v0, 0); - Windows_Delete(v0, 1); - Window_EraseStandardFrame(v1, 0); - Windows_Delete(v1, 1); - } - - param0->unk_A8 = NULL; - param0->unk_AC = NULL; - - return; -} - -void ov104_02237180(FrontierScriptManager *param0, BattleCastle *param1) -{ - u16 v0, v1; - - if (BattleCastle_IsMultiPlayerChallenge(param1->challengeType) == 0) { - GF_ASSERT(param0->unk_A8 != NULL); - v0 = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(param1->saveData), BattleFrontierStats_GetCastleLatestCPIndex(param1->challengeType)); - ov104_02237284(param0, param0->unk_A8, SaveData_GetTrainerInfo(param1->saveData), v0); - } else { - GF_ASSERT(param0->unk_A8 != NULL); - GF_ASSERT(param0->unk_AC != NULL); - - if (CommSys_CurNetId() == 0) { - v0 = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(param1->saveData), BattleFrontierStats_GetCastleLatestCPIndex(param1->challengeType)); - v1 = param1->partnersCP; - } else { - v0 = param1->partnersCP; - v1 = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(param1->saveData), BattleFrontierStats_GetCastleLatestCPIndex(param1->challengeType)); - } - - ov104_02237284(param0, param0->unk_A8, CommInfo_TrainerInfo(0), v0); - ov104_02237284(param0, param0->unk_AC, CommInfo_TrainerInfo(1), v1); - } - - return; -} - -static void ov104_02237284(FrontierScriptManager *param0, Window *param1, TrainerInfo *param2, u16 param3) -{ - MessageLoader *v0; - String *v1 = String_Init(10 * 2, param0->heapID); - String *v2 = String_Init(10 * 2, param0->heapID); - - v0 = MessageLoader_Init(MSG_LOADER_PRELOAD_ENTIRE_BANK, NARC_INDEX_MSGDATA__PL_MSG, TEXT_BANK_BATTLE_CASTLE_SELF_APP, HEAP_ID_FIELD2); - - StringTemplate_SetNumber(param0->strTemplate, 0, param3, 4, 1, 1); - MessageLoader_GetString(v0, 2, v1); - - StringTemplate_Format(param0->strTemplate, v2, v1); - Text_AddPrinterWithParams(param1, FONT_SYSTEM, v2, 16, 2 * 8, TEXT_SPEED_NO_TRANSFER, NULL); - StringTemplate_SetPlayerName(param0->strTemplate, 0, param2); - - MessageLoader_GetString(v0, 0, v1); - - StringTemplate_Format(param0->strTemplate, v2, v1); - Text_AddPrinterWithParams(param1, FONT_SYSTEM, v2, 0, 0, TEXT_SPEED_INSTANT, NULL); - - String_Free(v1); - String_Free(v2); - MessageLoader_Free(v0); - - Window_CopyToVRAM(param1); - - return; -} - -u16 ov104_02237338(BattleCastle *param0) -{ - u8 v0; - u16 v1; - static const u8 v2[8 + 1] = { 0, 3, 3, 4, 4, 5, 5, 7, 7 }; - static const u8 v3[8 + 1] = { 0, 8, 9, 11, 12, 14, 15, 18, 18 }; - - v1 = param0->unk_16; - - if ((param0->challengeType == 0) || (param0->challengeType == 1)) { - if (v1 >= 8) { - v0 = v2[8]; - } else { - v0 = v2[v1]; - } - } else { - if (v1 >= 8) { - v0 = v3[8]; - } else { - v0 = v3[v1]; - } - } - - if (param0->challengeType == 0) { - if ((param0->currentStreak == 21) || (param0->currentStreak == 49)) { - v0 = 20; - } - } - - return v0; -} diff --git a/src/overlay104/ov104_0223B6F4.c b/src/overlay104/ov104_0223B6F4.c deleted file mode 100644 index 3ba22b7fdb..0000000000 --- a/src/overlay104/ov104_0223B6F4.c +++ /dev/null @@ -1,427 +0,0 @@ -#include "overlay104/ov104_0223B6F4.h" - -#include -#include - -#include "constants/battle_frontier.h" -#include "generated/ai_flags.h" -#include "generated/frontier_trainers.h" - -#include "struct_defs/battle_frontier.h" - -#include "overlay104/ov104_0222DCE0.h" -#include "overlay104/struct_battle_castle.h" -#include "overlay104/struct_ov104_02230BE4.h" - -#include "battle_frontier_save.h" -#include "battle_frontier_stats.h" -#include "bg_window.h" -#include "communication_information.h" -#include "communication_system.h" -#include "field_battle_data_transfer.h" -#include "heap.h" -#include "item_use_pokemon.h" -#include "math_util.h" -#include "message.h" -#include "party.h" -#include "pokemon.h" -#include "save_player.h" -#include "string_gf.h" - -static int ov104_0223B6F4(u8 param0, int param1, int param2); -void ov104_0223B760(u8 param0, int param1, u16 param2[], u8 param3); -u8 BattleCastle_GetOpponentPartySize(u8 challengeType, BOOL param1); -static u32 BattleCastle_GetBattleType(u8 challengeType); -u8 BattleCastle_GetOpponentLevel(BattleCastle *battleCastle); -void ov104_0223BA24(Party *param0); -void ov104_0223BAB8(BattleCastle *battleCastle); -void ov104_0223BA7C(BattleCastle *battleCastle, Pokemon *param1); -void ov104_0223BAA0(BattleCastle *battleCastle, Party *param1, Pokemon *param2); -static u16 BattleCastle_GetAIMask(BattleCastle *battleCastle); -u16 ov104_0223BB60(BattleCastle *battleCastle); -u16 ov104_0223BC24(u16 param0); -void FieldBattleDTO_CopyPlayerInfoToTrainerData(FieldBattleDTO *param0); -void ov104_0223BB84(BgConfig *param0, BattleCastle *battleCastle, u32 param2); -static void ov104_0223BBC4(u16 *param0, u16 param1); - -static const struct { - u16 unk_00; - u16 unk_02; - u16 unk_04; - u16 unk_06; -} Unk_ov104_02241258[] = { - { 0x0, 0x63, 0x64, 0x77 }, - { 0x50, 0x77, 0x78, 0x8B }, - { 0x64, 0x8B, 0x8C, 0x9F }, - { 0x78, 0x9F, 0xA0, 0xB3 }, - { 0x8C, 0xB3, 0xB4, 0xC7 }, - { 0xA0, 0xC7, 0xC8, 0xDB }, - { 0xB4, 0xDB, 0xDC, 0xEF }, - { 0xC8, 0x12B, 0xC8, 0x12B } -}; - -static int ov104_0223B6F4(u8 param0, int param1, int param2) -{ - int v0, v1, v2, v3, v4; - - if (param0 == 0) { - v3 = (param1 * 7) + (param2 + 1); - - if (v3 == 21) { - return FRONTIER_TRAINER_CASTLE_VALET_DARACH_SILVER; - } else if (v3 == 49) { - return FRONTIER_TRAINER_CASTLE_VALET_DARACH_GOLD; - } - } - - v4 = param1; - - if (v4 >= NELEMS(Unk_ov104_02241258)) { - v4 = NELEMS(Unk_ov104_02241258) - 1; - } - - if ((param2 == 7 - 1) || (param2 == (7 * 2) - 1)) { - v1 = Unk_ov104_02241258[v4].unk_06 - Unk_ov104_02241258[v4].unk_04; - v2 = Unk_ov104_02241258[v4].unk_04; - } else { - v1 = Unk_ov104_02241258[v4].unk_02 - Unk_ov104_02241258[v4].unk_00; - v2 = Unk_ov104_02241258[v4].unk_00; - } - - v0 = v2 + (LCRNG_Next() % v1); - return v0; -} - -void ov104_0223B760(u8 param0, int param1, u16 param2[], u8 param3) -{ - int v0 = 0; - int v1; - - do { - param2[v0] = ov104_0223B6F4(param0, param1, v0); - - for (v1 = 0; v1 < v0; v1++) { - if (param2[v1] == param2[v0]) { - break; - } - } - - if (v1 != v0) { - continue; - } - - v0++; - } while (v0 < param3); -} - -u8 BattleCastle_GetPlayerPartySize(u8 challengeType, BOOL includePartnersMons) -{ - switch (challengeType) { - case FRONTIER_CHALLENGE_SINGLE: - case FRONTIER_CHALLENGE_DOUBLE: - return 3; - case FRONTIER_CHALLENGE_MULTI: - case FRONTIER_CHALLENGE_MULTI_WFC: - if (includePartnersMons == FALSE) { - return 2; - } else { - return 4; - } - } - - GF_ASSERT(FALSE); - return 3; -} - -u8 BattleCastle_GetOpponentPartySize(u8 challengeType, BOOL param1) -{ - switch (challengeType) { - case FRONTIER_CHALLENGE_SINGLE: - case FRONTIER_CHALLENGE_DOUBLE: - return 3; - case FRONTIER_CHALLENGE_MULTI: - case FRONTIER_CHALLENGE_MULTI_WFC: - if (param1 == 0) { - return 2; - } else { - return 4; - } - } - - GF_ASSERT(FALSE); - return 3; -} - -FieldBattleDTO *FieldBattleDTO_NewBattleCastle(BattleCastle *battleCastle, FieldFrontierDTO *fieldData) -{ - int i; - u8 baseSlotID; - Pokemon *mon; - FrontierTrainerDataDTO trDataDTO; - - u8 playerPartySize = BattleCastle_GetPlayerPartySize(battleCastle->challengeType, 0); - u8 opponentPartySize = BattleCastle_GetOpponentPartySize(battleCastle->challengeType, 0); - - Party_HealAllMembers(battleCastle->opponentsParty); - FieldBattleDTO *battleDTO = FieldBattleDTO_New(HEAP_ID_FIELD2, BattleCastle_GetBattleType(battleCastle->challengeType)); - FieldBattleDTO_InitFromGameState(battleDTO, NULL, fieldData->saveData, fieldData->mapHeaderID, fieldData->journalEntry, fieldData->bagCursor, fieldData->subscreenCursorOn); - - battleDTO->background = BACKGROUND_BATTLE_CASTLE; - battleDTO->terrain = TERRAIN_BATTLE_CASTLE; - - Party_InitWithCapacity(battleDTO->parties[BATTLER_PLAYER_1], playerPartySize); - - if (CommSys_CurNetId() == 0) { - baseSlotID = 0; - } else { - baseSlotID = 2; - } - - mon = Pokemon_New(HEAP_ID_FIELD2); - - for (i = 0; i < playerPartySize; i++) { - Pokemon_Copy(Party_GetPokemonBySlotIndex(battleCastle->playersParty, baseSlotID + i), mon); - - FieldBattleDTO_AddPokemonToBattler(battleDTO, mon, BATTLER_PLAYER_1); - } - - Heap_Free(mon); - FieldBattleDTO_CopyPlayerInfoToTrainerData(battleDTO); - - Heap_Free(BattleFrontier_GetTrainerData(&trDataDTO, battleCastle->trainerIDs[battleCastle->unk_11], HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR)); - FieldBattleDTO_InitFrontierTrainer(battleDTO, &trDataDTO, opponentPartySize, BATTLER_ENEMY_1, HEAP_ID_FIELD2); - Party_InitWithCapacity(battleDTO->parties[BATTLER_ENEMY_1], BattleCastle_GetOpponentPartySize(battleCastle->challengeType, 0)); - - for (i = 0; i < MAX_BATTLERS; i++) { - battleDTO->trainer[i].header.aiMask = BattleCastle_GetAIMask(battleCastle); - } - - mon = Pokemon_New(HEAP_ID_FIELD2); - - for (i = 0; i < opponentPartySize; i++) { - Pokemon_Copy(Party_GetPokemonBySlotIndex(battleCastle->opponentsParty, i), mon); - FieldBattleDTO_AddPokemonToBattler(battleDTO, mon, BATTLER_ENEMY_1); - } - - Heap_Free(mon); - - switch (battleCastle->challengeType) { - case FRONTIER_CHALLENGE_MULTI: - case FRONTIER_CHALLENGE_MULTI_WFC: - FieldBattleDTO_CopyPlayerInfoToTrainerData(battleDTO); - - TrainerInfo_Copy(CommInfo_TrainerInfo(1 - CommSys_CurNetId()), battleDTO->trainerInfo[BATTLER_PLAYER_2]); - - Heap_Free(BattleFrontier_GetTrainerData(&trDataDTO, battleCastle->trainerIDs[battleCastle->unk_11 + 7], HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR)); - - FieldBattleDTO_InitFrontierTrainer(battleDTO, &trDataDTO, opponentPartySize, BATTLER_ENEMY_2, HEAP_ID_FIELD2); - Party_InitWithCapacity(battleDTO->parties[BATTLER_ENEMY_2], BattleCastle_GetOpponentPartySize(battleCastle->challengeType, 0)); - - mon = Pokemon_New(HEAP_ID_FIELD2); - - for (i = 0; i < opponentPartySize; i++) { - Pokemon_Copy(Party_GetPokemonBySlotIndex(battleCastle->opponentsParty, opponentPartySize + i), mon); - FieldBattleDTO_AddPokemonToBattler(battleDTO, mon, BATTLER_ENEMY_2); - } - - Heap_Free(mon); - break; - } - - return battleDTO; -} - -static u32 BattleCastle_GetBattleType(u8 challengeType) -{ - switch (challengeType) { - case FRONTIER_CHALLENGE_SINGLE: - return BATTLE_TYPE_FRONTIER_SINGLES; - case FRONTIER_CHALLENGE_DOUBLE: - return BATTLE_TYPE_FRONTIER_DOUBLES; - case FRONTIER_CHALLENGE_MULTI: - return BATTLE_TYPE_FRONTIER_LINK | BATTLE_TYPE_TRAINER_DOUBLES | BATTLE_TYPE_2vs2; - case FRONTIER_CHALLENGE_MULTI_WFC: - return BATTLE_TYPE_FRONTIER_LINK | BATTLE_TYPE_TRAINER_DOUBLES | BATTLE_TYPE_2vs2; - } - - return BATTLE_TYPE_FRONTIER_SINGLES; -} - -u8 BattleCastle_GetOpponentLevel(BattleCastle *battleCastle) -{ - return 50; -} - -BOOL BattleCastle_IsMultiPlayerChallenge(u8 challengeType) -{ - return challengeType == FRONTIER_CHALLENGE_MULTI || challengeType == FRONTIER_CHALLENGE_MULTI_WFC; -} - -void ov104_0223BA24(Party *param0) -{ - int v0, v1, v2; - u32 v3; - Pokemon *mon; - - v2 = Party_GetCurrentCount(param0); - - for (v0 = 0; v0 < v2; v0++) { - mon = Party_GetPokemonBySlotIndex(param0, v0); - - if (Pokemon_GetValue(mon, MON_DATA_SPECIES_EXISTS, NULL) == 0) { - continue; - } - - if (Pokemon_GetValue(mon, MON_DATA_HP, NULL) == 0) { - v3 = 1; - Pokemon_SetValue(mon, MON_DATA_HP, &v3); - } - - v3 = 0; - Pokemon_SetValue(mon, MON_DATA_STATUS, &v3); - } - - return; -} - -void ov104_0223BA7C(BattleCastle *battleCastle, Pokemon *param1) -{ - Pokemon_UpdateAfterCatch(param1, SaveData_GetTrainerInfo(battleCastle->saveData), 4, 0, 0, 11); - return; -} - -void ov104_0223BAA0(BattleCastle *battleCastle, Party *param1, Pokemon *param2) -{ - ov104_0223BA7C(battleCastle, param2); - Party_AddPokemon(param1, param2); - return; -} - -void ov104_0223BAB8(BattleCastle *battleCastle) -{ - int v0, v1; - u8 v2; - Pokemon *v3; - - Party_Init(battleCastle->opponentsParty); - - v2 = BattleCastle_GetOpponentPartySize(battleCastle->challengeType, 1); - v3 = Pokemon_New(HEAP_ID_FIELD2); - - for (v0 = 0; v0 < v2; v0++) { - FrontierPokemonDataDTO_InitPokemon(&battleCastle->unk_288[v0], v3, BattleCastle_GetOpponentLevel(battleCastle)); - ov104_0223BAA0(battleCastle, battleCastle->opponentsParty, v3); - } - - Heap_Free(v3); - - return; -} - -static u16 BattleCastle_GetAIMask(BattleCastle *battleCastle) -{ - u16 aiMask, v1; - - if (battleCastle->challengeType == FRONTIER_CHALLENGE_SINGLE) { - if (battleCastle->trainerIDs[battleCastle->unk_11] == FRONTIER_TRAINER_CASTLE_VALET_DARACH_SILVER - || battleCastle->trainerIDs[battleCastle->unk_11] == FRONTIER_TRAINER_CASTLE_VALET_DARACH_GOLD) { - return AI_FLAG_BASIC | AI_FLAG_EVAL_ATTACK | AI_FLAG_EXPERT; - } - } - - v1 = ov104_0223BB60(battleCastle); - aiMask = AI_FLAG_BASIC | AI_FLAG_EVAL_ATTACK | AI_FLAG_EXPERT; - - switch (v1 + 1) { - case 1: - case 2: - aiMask = AI_FLAG_NONE; - break; - case 3: - case 4: - aiMask = AI_FLAG_BASIC; - break; - } - - return aiMask; -} - -u16 ov104_0223BB60(BattleCastle *battleCastle) -{ - u16 v0 = battleCastle->unk_16; - - if (BattleCastle_IsMultiPlayerChallenge(battleCastle->challengeType) == 1) { - if (battleCastle->unk_A12 > battleCastle->unk_16) { - v0 = battleCastle->unk_A12; - } - } - - return v0; -} - -void ov104_0223BB84(BgConfig *param0, BattleCastle *battleCastle, u32 param2) -{ - int v0; - u16 v1[30]; - - ov104_0223BBC4(v1, ov104_0223BB60(battleCastle)); - - Bg_LoadToTilemapRect(param0, param2, v1, 11, 6, 10, 3); - Bg_ScheduleTilemapTransfer(param0, param2); - - return; -} - -static void ov104_0223BBC4(u16 *param0, u16 param1) -{ - u8 v0[10]; - u16 v1; - u32 v2, v3, v4, v5; - - v1 = ov104_0223BC24(param1); - - for (v3 = 0; v3 < (10 / 2); v3++) { - v0[v3] = v3; - v0[(10 / 2) + v3] = (((10 / 2) - 1) - v3); - } - - v2 = (0x60 * v1) + 0x10; - - for (v3 = 0; v3 < 3; v3++) { - for (v4 = 0; v4 < 10; v4++) { - v5 = v2 + (v3 * 0x20) + v0[v4]; - param0[v4 + (v3 * 10)] = v5; - - if (v4 >= (10 / 2)) { - param0[v4 + (v3 * 10)] |= (1 << 10); - } - } - } - - return; -} - -u16 ov104_0223BC24(u16 param0) -{ - if (param0 >= 8) { - return 8 - 1; - } - - return param0; -} - -void ov104_0223BC2C(BattleFrontierSave *frontier, u8 challengeType, int castlePoints) -{ - u16 v0; - - BattleFrontierSave_SubtractFromStat(frontier, BattleFrontierStats_GetCastleLatestCPIndex(challengeType), BattleFrontierStats_GetHostFriendIdx(BattleFrontierStats_GetCastleLatestCPIndex(challengeType)), castlePoints); - v0 = BattleFrontierSave_GetStatAutoHostIdx(frontier, BattleFrontierStats_GetCastleSpentCPIndex(challengeType)); - - if (v0 + castlePoints > 9999) { - BattleFrontierSave_SetStatAutoHostIdx(frontier, BattleFrontierStats_GetCastleSpentCPIndex(challengeType), 9999); - } else { - BattleFrontierSave_AddToStat(frontier, BattleFrontierStats_GetCastleSpentCPIndex(challengeType), BattleFrontierStats_GetHostFriendIdx(BattleFrontierStats_GetCastleSpentCPIndex(challengeType)), castlePoints); - } - - return; -} diff --git a/src/pokemon.c b/src/pokemon.c index e0b69209d2..8b4348e204 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -265,8 +265,8 @@ static u32 Pokemon_GetExpRateBaseExpAt(enum ExpRate monExpRate, int monLevel); static u16 Pokemon_GetNatureStatValue(u8 monNature, u16 monStatValue, u8 statType); static u8 BoxPokemon_IsShiny(BoxPokemon *boxMon); static inline BOOL Pokemon_InlineIsPersonalityShiny(u32 monOTID, u32 monPersonality); -static void BuildPokemonSpriteTemplateDP(PokemonSpriteTemplate *spriteTemplate, u16 monSpecies, u8 monGender, u8 param3, u8 monShininess, u8 monForm, u32 monPersonality); -static u8 LoadPokemonDPSpriteHeight(u16 monSpecies, u8 monGender, u8 param2, u8 monForm, u32 monPersonality); +static void BuildPokemonSpriteTemplateDP(PokemonSpriteTemplate *spriteTemplate, u16 species, u8 gender, u8 face, u8 shiny, u8 form, u32 personality); +static u8 LoadPokemonDPSpriteHeight(u16 species, u8 gender, u8 face, u8 form, u32 personality); static void BoxPokemon_SetDefaultMoves(BoxPokemon *boxMon); static u16 BoxPokemon_AddMove(BoxPokemon *boxMon, u16 moveID); static void BoxPokemon_ReplaceMove(BoxPokemon *boxMon, u16 moveID); @@ -275,19 +275,19 @@ static BOOL Pokemon_HasMove(Pokemon *mon, u16 moveID); static s8 BoxPokemon_GetFlavorAffinity(BoxPokemon *boxMon, enum Flavor flavor); static BOOL IsBoxPokemonInfectedWithPokerus(BoxPokemon *boxMon); static BOOL BoxPokemonHasCuredPokerus(BoxPokemon *boxMon); -static void InitializeBoxPokemonAfterCapture(BoxPokemon *boxMon, TrainerInfo *trainerInfo, int monPokeball, int metLocation, int metTerrain, enum HeapID heapID); -static void PostCaptureBoxPokemonProcessing(BoxPokemon *boxMon, TrainerInfo *param1, int monPokeball, int param3, int param4, int param5); +static void InitializeBoxPokemonAfterCapture(BoxPokemon *boxMon, TrainerInfo *trainer, int monPokeball, int metLocation, int metTerrain, enum HeapID heapID); +static void PostCaptureBoxPokemonProcessing(BoxPokemon *boxMon, TrainerInfo *trainer, int monPokeball, int metLocation, int metTerrain, int heapID); static BOOL CanBoxPokemonLearnTM(BoxPokemon *boxMon, u8 tmID); static void BoxPokemon_CalcAbility(BoxPokemon *boxMon); static void SpeciesData_LoadSpecies(int monSpecies, SpeciesData *speciesData); static void SpeciesData_LoadForm(int monSpecies, int monForm, SpeciesData *speciesData); -static void LoadSpeciesEvolutions(int monSpecies, SpeciesEvolution speciesEvolution[MAX_EVOLUTIONS]); +static void LoadSpeciesEvolutions(int monSpecies, SpeciesEvolution speciesEvolutions[MAX_EVOLUTIONS]); static void Pokemon_EncryptData(void *data, u32 bytes, u32 seed); static void Pokemon_DecryptData(void *data, u32 bytes, u32 seed); static u16 Pokemon_GetDataChecksum(void *data, u32 bytes); static void *BoxPokemon_GetDataBlock(BoxPokemon *boxMon, u32 personality, enum PokemonDataBlockID dataBlockID); static int Pokemon_GetFormNarcIndex(int monSpecies, int monForm); -static inline int Pokemon_Face(int num); +static inline int Pokemon_Face(int clientType); void Pokemon_Init(Pokemon *mon) { @@ -4657,14 +4657,14 @@ static void InitializeBoxPokemonAfterCapture(BoxPokemon *boxMon, TrainerInfo *tr BoxPokemon_SetValue(boxMon, MON_DATA_MET_TERRAIN, &metTerrain); } -void Pokemon_UpdateAfterCatch(Pokemon *mon, TrainerInfo *param1, int monPokeball, int param3, int param4, int param5) +void Pokemon_UpdateAfterCatch(Pokemon *mon, TrainerInfo *trainer, int monPokeball, int metLocation, int metTerrain, int heapID) { - PostCaptureBoxPokemonProcessing(&mon->box, param1, monPokeball, param3, param4, param5); + PostCaptureBoxPokemonProcessing(&mon->box, trainer, monPokeball, metLocation, metTerrain, heapID); } -static void PostCaptureBoxPokemonProcessing(BoxPokemon *boxMon, TrainerInfo *param1, int monPokeball, int param3, int param4, int param5) +static void PostCaptureBoxPokemonProcessing(BoxPokemon *boxMon, TrainerInfo *trainer, int monPokeball, int metLocation, int metTerrain, int heapID) { - InitializeBoxPokemonAfterCapture(boxMon, param1, monPokeball, param3, param4, param5); + InitializeBoxPokemonAfterCapture(boxMon, trainer, monPokeball, metLocation, metTerrain, heapID); } static const u16 sHeldItemChance[][2] = { diff --git a/src/unk_020302D0.c b/src/unk_020302D0.c deleted file mode 100644 index a49bed8e5b..0000000000 --- a/src/unk_020302D0.c +++ /dev/null @@ -1,168 +0,0 @@ -#include "unk_020302D0.h" - -#include -#include - -#include "struct_defs/battle_frontier.h" -#include "struct_defs/struct_020302DC.h" -#include "struct_defs/struct_0203041C.h" - -#include "savedata.h" - -void sub_020302D0(UnkStruct_020302DC *param0); -BOOL sub_020302EC(UnkStruct_020302DC *param0); -void sub_020302F4(UnkStruct_020302DC *param0, BOOL param1); -void sub_02030308(UnkStruct_020302DC *param0, u8 param1, u8 param2, u8 param3, const void *param4); -u32 sub_02030398(UnkStruct_020302DC *param0, u8 param1, u8 param2, u8 param3, void *param4); -void sub_02030410(UnkStruct_0203041C *param0); -void sub_02030430(UnkStruct_0203041C *param0, u8 param1, u8 param2, u8 param3, const void *param4); -u32 sub_02030470(UnkStruct_0203041C *param0, u8 param1, u8 param2, u8 param3, void *param4); - -void sub_020302D0(UnkStruct_020302DC *param0) -{ - MI_CpuClear8(param0, sizeof(UnkStruct_020302DC)); - return; -} - -UnkStruct_020302DC *sub_020302DC(SaveData *saveData) -{ - BattleFrontierSave *frontier = SaveData_SaveTable(saveData, SAVE_TABLE_ENTRY_FRONTIER); - return &frontier->unk_8E0_val4; -} - -BOOL sub_020302EC(UnkStruct_020302DC *param0) -{ - return param0->unk_00_3; -} - -void sub_020302F4(UnkStruct_020302DC *param0, BOOL param1) -{ - param0->unk_00_3 = param1; - return; -} - -void sub_02030308(UnkStruct_020302DC *param0, u8 param1, u8 param2, u8 param3, const void *param4) -{ - u32 *v0 = (u32 *)param4; - u16 *v1 = (u16 *)param4; - u8 *v2 = (u8 *)param4; - - switch (param1) { - case 0: - param0->unk_00_0 = v2[0]; - break; - case 1: - param0->unk_01 = v2[0]; - break; - case 2: - param0->unk_22[param2] = v1[0]; - break; - case 3: - param0->unk_2A[param2][param3] = v2[0]; - break; - case 4: - param0->unk_3C[param2] = v0[0]; - break; - case 5: - param0->unk_4C[param2] = v1[0]; - break; - case 6: - param0->unk_06[param2] = v1[0]; - break; - case 7: - param0->unk_03[param2] = v2[0]; - break; - case 8: - param0->unk_54[param2] = v1[0]; - break; - default: - GF_ASSERT(FALSE); - break; - } - - return; -} - -u32 sub_02030398(UnkStruct_020302DC *param0, u8 param1, u8 param2, u8 param3, void *param4) -{ - switch (param1) { - case 0: - return (u32)param0->unk_00_0; - case 1: - return (u32)param0->unk_01; - case 2: - return (u32)param0->unk_22[param2]; - case 3: - return (u32)param0->unk_2A[param2][param3]; - case 4: - return (u32)param0->unk_3C[param2]; - case 5: - return (u32)param0->unk_4C[param2]; - case 6: - return (u32)param0->unk_06[param2]; - case 7: - return param0->unk_03[param2]; - case 8: - return param0->unk_54[param2]; - default: - GF_ASSERT(FALSE); - break; - } - - return 0; -} - -void sub_02030410(UnkStruct_0203041C *param0) -{ - int v0, v1; - - MI_CpuClear8(param0, sizeof(UnkStruct_0203041C)); - - return; -} - -UnkStruct_0203041C *sub_0203041C(SaveData *saveData) -{ - BattleFrontierSave *frontier = SaveData_SaveTable(saveData, SAVE_TABLE_ENTRY_FRONTIER); - return &frontier->unk_161C.unk_00; -} - -void sub_02030430(UnkStruct_0203041C *param0, u8 param1, u8 param2, u8 param3, const void *param4) -{ - u32 *v0 = (u32 *)param4; - u16 *v1 = (u16 *)param4; - u8 *v2 = (u8 *)param4; - - switch (param1) { - case 9: - if (v2[0] >= 1) { - param0->unk_00 |= (1 << param2); - } else { - param0->unk_00 &= (0xff ^ (1 << param2)); - } - break; - case 10: - param0->unk_01 = 1; - break; - default: - GF_ASSERT(FALSE); - break; - } - - return; -} - -u32 sub_02030470(UnkStruct_0203041C *param0, u8 param1, u8 param2, u8 param3, void *param4) -{ - switch (param1) { - case 9: - return (u32)((param0->unk_00 >> param2) & 0x1); - case 10: - return (u32)param0->unk_01; - default: - GF_ASSERT(FALSE); - break; - } - - return 0; -} diff --git a/src/unk_0204FAB4.c b/src/unk_0204FAB4.c index c3ebb8f827..1780e3b957 100644 --- a/src/unk_0204FAB4.c +++ b/src/unk_0204FAB4.c @@ -4,8 +4,6 @@ #include #include -#include "struct_decls/struct_020302DC_decl.h" -#include "struct_decls/struct_0203041C_decl.h" #include "struct_defs/battle_tower.h" #include "struct_defs/struct_0204FCF8.h" @@ -15,6 +13,7 @@ #include "field/field_system.h" #include "bag.h" +#include "battle_castle_save.h" #include "battle_frontier_save.h" #include "battle_frontier_stats.h" #include "communication_system.h" @@ -30,7 +29,6 @@ #include "savedata.h" #include "script_manager.h" #include "unk_0202D778.h" -#include "unk_020302D0.h" #include "unk_02049D08.h" #include "unk_02099500.h" @@ -46,7 +44,7 @@ typedef struct { BOOL ScrCmd_2D2(ScriptContext *param0); BOOL ScrCmd_2D5(ScriptContext *param0); -static void sub_0204FBEC(SaveData *saveData, UnkStruct_0203041C *param1, u8 param2); +static void sub_0204FBEC(SaveData *saveData, BattleCastlePersistentSave *param1, u8 param2); static void sub_0204FDB4(FieldTask *taskMan, void **param1, u8 param2); static BOOL sub_0204FDE8(FieldTask *taskMan); static int sub_0204FE50(UnkStruct_0204FE50 *param0, FieldSystem *fieldSystem, int param2); @@ -63,8 +61,8 @@ BOOL ScrCmd_2D2(ScriptContext *param0) u16 v4 = ScriptContext_GetVar(param0); u16 v5 = ScriptContext_ReadHalfWord(param0); u16 *v6 = FieldSystem_GetVarPointer(param0->fieldSystem, v5); - UnkStruct_020302DC *v10 = sub_020302DC(param0->fieldSystem->saveData); - UnkStruct_0203041C *v11 = sub_0203041C(param0->fieldSystem->saveData); + BattleCastleSave *v10 = BattleCastleSave_Get(param0->fieldSystem->saveData); + BattleCastlePersistentSave *v11 = BattleCastlePersistentSave_Get(param0->fieldSystem->saveData); void **v8 = FieldSystem_GetScriptMemberPtr(param0->fieldSystem, 19); u8 v0; @@ -76,7 +74,7 @@ BOOL ScrCmd_2D2(ScriptContext *param0) if (v4 == 3) { *v6 = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(param0->fieldSystem->saveData), STAT_CASTLE_WFC_STREAK_ACTIVE); } else { - *v6 = (u16)sub_02030470(v11, 9, v4, 0, NULL); + *v6 = (u16)BattleCastlePersistentSave_GetFlag(v11, 9, v4, 0, NULL); } break; case 3: @@ -108,19 +106,19 @@ BOOL ScrCmd_2D5(ScriptContext *param0) { u16 v1 = ScriptContext_GetVar(param0); - UnkStruct_0203041C *v0 = sub_0203041C(param0->fieldSystem->saveData); + BattleCastlePersistentSave *v0 = BattleCastlePersistentSave_Get(param0->fieldSystem->saveData); sub_0204FBEC(param0->fieldSystem->saveData, v0, v1); return 0; } -static void sub_0204FBEC(SaveData *saveData, UnkStruct_0203041C *param1, u8 param2) +static void sub_0204FBEC(SaveData *saveData, BattleCastlePersistentSave *param1, u8 param2) { u16 v1[4]; u8 v2[4]; v2[0] = 0; - sub_02030430(param1, 9, param2, 0, v2); + BattleCastlePersistentSave_SetFlag(param1, 9, param2, 0, v2); if (param2 == 3) { BattleFrontierSave_SetStatAutoHostIdx(SaveData_GetBattleFrontier(saveData), STAT_CASTLE_WFC_STREAK_ACTIVE, 0);