From ddfe62a34e7a77d1d2d655d64da1a0fb33f38f8a Mon Sep 17 00:00:00 2001 From: VicSevenT Date: Thu, 30 Jul 2026 16:14:32 -0500 Subject: [PATCH] Document Battle Factory logic --- asm/macros/frscrcmd.inc | 58 +- generated/game_records.txt | 2 +- .../frontier/battle_factory/main.h | 2 +- include/battle_factory_save.h | 16 +- include/constants/battle_factory_functions.h | 54 +- include/constants/battle_frontier.h | 10 + include/data/scripts/frscrcmd.h | 408 +++++------ include/overlay104/battle_factory.h | 81 +++ include/overlay104/battle_factory_helpers.h | 32 + include/overlay104/frontier_communication.h | 2 +- include/overlay104/frscrcmd_battle_factory.h | 20 +- include/overlay104/ov104_022339B4.h | 27 - include/overlay104/ov104_0223A7F4.h | 25 - include/overlay104/struct_battle_factory.h | 60 -- include/overlay104/struct_ov104_0224028C.h | 12 - platinum.us/main.lsf | 4 +- .../frontier_scripts_battle_factory.s | 206 +++--- .../frontier/battle_factory/main.c | 36 +- src/game_records.c | 2 +- src/meson.build | 4 +- src/overlay104/battle_factory.c | 556 +++++++++++++++ src/overlay104/battle_factory_helpers.c | 479 +++++++++++++ src/overlay104/frontier_communication.c | 49 +- src/overlay104/frscrcmd_battle_factory.c | 339 +++++---- src/overlay104/ov104_022339B4.c | 643 ------------------ src/overlay104/ov104_0223A7F4.c | 519 -------------- 26 files changed, 1752 insertions(+), 1894 deletions(-) create mode 100644 include/overlay104/battle_factory.h create mode 100644 include/overlay104/battle_factory_helpers.h delete mode 100644 include/overlay104/ov104_022339B4.h delete mode 100644 include/overlay104/ov104_0223A7F4.h delete mode 100644 include/overlay104/struct_battle_factory.h delete mode 100644 include/overlay104/struct_ov104_0224028C.h create mode 100644 src/overlay104/battle_factory.c create mode 100644 src/overlay104/battle_factory_helpers.c delete mode 100644 src/overlay104/ov104_022339B4.c delete mode 100644 src/overlay104/ov104_0223A7F4.c diff --git a/asm/macros/frscrcmd.inc b/asm/macros/frscrcmd.inc index 6ff15f003a3..6589a0982fd 100644 --- a/asm/macros/frscrcmd.inc +++ b/asm/macros/frscrcmd.inc @@ -518,20 +518,20 @@ .short \seqID .endm - .macro FrontierScrCmd_5C arg0, arg1, arg2 - .short FRSCRCMD_5C - .short \arg0 - .short \arg1 - .short \arg2 + .macro InitBattleFactory resumingFromSave, challengeType, isOpenLevel + .short FRSCRCMD_INITBATTLEFACTORY + .short \resumingFromSave + .short \challengeType + .short \isOpenLevel .endm - .macro FrontierScrCmd_5D arg0 - .short FRSCRCMD_5D - .short \arg0 + .macro BattleFactory_LoadTrainersForRound resumingFromSave + .short FRSCRCMD_BATTLEFACTORY_LOADTRAINERSFORROUND + .short \resumingFromSave .endm - .macro FrontierScrCmd_5E - .short FRSCRCMD_5E + .macro FreeBattleFactory + .short FRSCRCMD_FREEBATTLEFACTORY .endm .macro OpenBattleFactoryAppInitial @@ -550,20 +550,20 @@ .short FRSCRCMD_OPENBATTLEFACTORYAPPFORTRADE .endm - .macro FrontierScrCmd_63 - .short FRSCRCMD_63 + .macro AddSelectedRentalsToParty + .short FRSCRCMD_ADDSELECTEDRENTALSTOPARTY .endm - .macro FrontierScrCmd_64 - .short FRSCRCMD_64 + .macro BattleFactory_SetupNextOpponent + .short FRSCRCMD_BATTLEFACTORY_SETUPNEXTOPPONENT .endm - .macro FrontierScrCmd_65 - .short FRSCRCMD_65 + .macro BattleFactory_ApplyTrade + .short FRSCRCMD_BATTLEFACTORY_APPLYTRADE .endm - .macro FrontierScrCmd_66 - .short FRSCRCMD_66 + .macro BattleFactory_SetupNextOpponentsParty + .short FRSCRCMD_BATTLEFACTORY_SETUPNEXTOPPONENTSPARTY .endm .macro CallBattleFactoryFunction command, arg1, arg2, destVar @@ -579,21 +579,21 @@ .short \destVar .endm - .macro FrontierScrCmd_69 arg0, arg1, arg2 - .short FRSCRCMD_69 - .short \arg0 - .short \arg1 - .short \arg2 + .macro BattleFactory_SendCommMessage command, arg, success + .short FRSCRCMD_BATTLEFACTORY_SENDCOMMMESSAGE + .short \command + .short \arg + .short \success .endm - .macro FrontierScrCmd_6A arg0 - .short FRSCRCMD_6A - .short \arg0 + .macro BattleFactory_WaitForCommResponses unused + .short FRSCRCMD_BATTLEFACTORY_WAITFORCOMMRESPONSES + .short \unused .endm - .macro FrontierScrCmd_6B arg0 - .short FRSCRCMD_6B - .byte \arg0 + .macro BattleFactory_PrintTrainerIntro index + .short FRSCRCMD_BATTLEFACTORY_PRINTTRAINERINTRO + .byte \index .endm .macro InitNewBattleRecording diff --git a/generated/game_records.txt b/generated/game_records.txt index 25f8bb457c4..3b8b94fa65f 100644 --- a/generated/game_records.txt +++ b/generated/game_records.txt @@ -62,7 +62,7 @@ RECORD_BATTLE_FACTORY_VICTORIES RECORD_BATTLE_CASTLE_VICTORIES RECORD_BATTLE_HALL_VICTORIES RECORD_BATTLE_ARCADE_VICTORIES -RECORD_UNK_064 +RECORD_BATTLE_FACTORY_TRADES RECORD_CASTLE_POINTS_RECEIVED RECORD_UNK_066 RECORD_UNK_067 diff --git a/include/applications/frontier/battle_factory/main.h b/include/applications/frontier/battle_factory/main.h index 21aa677b8da..753605ec194 100644 --- a/include/applications/frontier/battle_factory/main.h +++ b/include/applications/frontier/battle_factory/main.h @@ -8,7 +8,7 @@ typedef struct BattleFactoryAppArgs { SaveData *saveData; u8 challengeType; - u8 unk_05; + u8 isOpenLevel; u8 isExchangeMode; u8 padding_07; Party *personalParty; diff --git a/include/battle_factory_save.h b/include/battle_factory_save.h index 946711c5e99..8ba05adb85b 100644 --- a/include/battle_factory_save.h +++ b/include/battle_factory_save.h @@ -1,6 +1,8 @@ #ifndef POKEPLATINUM_BATTLE_FACTORY_SAVE_H #define POKEPLATINUM_BATTLE_FACTORY_SAVE_H +#include "constants/battle_frontier.h" + #include "savedata.h" #define FACTORY_SAVE_OPEN_LEVEL 0 @@ -26,13 +28,13 @@ typedef struct BattleFactorySave { u8 didSave : 1; u8 currentBattleNum; u16 unused2; - u16 trainerIDs[14]; - u16 playerPartySets[4]; - u8 playerIVs[4]; - u32 playerPersonality[4]; - u16 opponentPartySets[4]; - u8 opponentIVs[4]; - u32 opponentPersonality[4]; + u16 trainerIDs[FACTORY_BATTLES_PER_ROUND * 2]; + u16 playerPartySets[FACTORY_MAX_PARTY_SIZE]; + u8 playerIVs[FACTORY_MAX_PARTY_SIZE]; + u32 playerPersonality[FACTORY_MAX_PARTY_SIZE]; + u16 opponentPartySets[FACTORY_MAX_PARTY_SIZE]; + u8 opponentIVs[FACTORY_MAX_PARTY_SIZE]; + u32 opponentPersonality[FACTORY_MAX_PARTY_SIZE]; } BattleFactorySave; void BattleFactorySave_Init(BattleFactorySave *save); diff --git a/include/constants/battle_factory_functions.h b/include/constants/battle_factory_functions.h index 76bff37c00b..b222b31bb20 100644 --- a/include/constants/battle_factory_functions.h +++ b/include/constants/battle_factory_functions.h @@ -3,47 +3,47 @@ enum BattleFactoryFunction { BF_FUNC_UNK_0 = 0, - BF_FUNC_UNK_1, + BF_FUNC_SET_IS_OPEN_LEVEL, BF_FUNC_SET_CHALLENGE_TYPE, - BF_FUNC_UNK_3, + BF_FUNC_GET_SELECTED_APP_SLOT, BF_FUNC_GET_CURRENT_STREAK, BF_FUNC_INCREMENT_CURRENT_STREAK, BF_FUNC_UNK_6, BF_FUNC_RESET_SYSTEM, BF_FUNC_UNK_8, - BF_FUNC_UNK_9, - BF_FUNC_UNK_10, + BF_FUNC_HAS_SAVED, + BF_FUNC_QUICKSAVE, BF_FUNC_UNK_11, BF_FUNC_UNK_12, BF_FUNC_UNK_13, - BF_FUNC_UNK_14, - BF_FUNC_UNK_15, - BF_FUNC_UNK_16, - BF_FUNC_UNK_17, - BF_FUNC_UNK_18, - BF_FUNC_UNK_19, - BF_FUNC_UNK_20, - BF_FUNC_UNK_21, - BF_FUNC_UNK_22, - BF_FUNC_UNK_23, + BF_FUNC_INCREMENT_CURRENT_BATTLE, + BF_FUNC_GET_MONS_SPECIES, + BF_FUNC_GET_MONS_MOVE, + BF_FUNC_GET_MONS_TYPE, + BF_FUNC_GET_COMMON_TYPE, + BF_FUNC_GET_CURRENT_ROUND, + BF_FUNC_GET_OPPONENT_OBJECT_ID, + BF_FUNC_SAVE_ON_LOSS, + BF_FUNC_SAVE_ON_COMPLETING_ROUND, + BF_FUNC_GET_CURRENT_BATTLE, BF_FUNC_UNK_24, BF_FUNC_UNK_25, BF_FUNC_UNK_26, - BF_FUNC_UNK_27, + BF_FUNC_INIT_COMM_MANAGER, BF_FUNC_IS_MULTIPLAYER_CHALLENGE, BF_FUNC_GET_CHALLENGE_TYPE, - BF_FUNC_UNK_30, - BF_FUNC_UNK_31, - BF_FUNC_UNK_32, - BF_FUNC_UNK_33, - BF_FUNC_UNK_34, - BF_FUNC_UNK_35, - BF_FUNC_UNK_36, - BF_FUNC_UNK_37, - BF_FUNC_UNK_38, - BF_FUNC_UNK_39, - BF_FUNC_UNK_40, - BF_FUNC_UNK_41, + BF_FUNC_UPDATE_BACKGROUND, + BF_FUNC_START_CORRIDOR_ANIMATION, + BF_FUNC_STOP_CORRIDOR_ANIMATION, + BF_FUNC_LOAD_TRAINERS, + BF_FUNC_SET_RENTED_MONS_IN_STRING, + BF_FUNC_GET_EARNED_BP, + BF_FUNC_INCREMENT_TRADE_COUNT, + BF_FUNC_GET_NEXT_BATTLE_TYPE, + BF_FUNC_UPDATE_PARTNERS_PARTY, + BF_FUNC_CREATE_OPPONENT_MONS, + BF_FUNC_CREATE_INITAL_PARTY, + BF_FUNC_CHECK_SEEN_HEAD_INTRO, }; #endif // POKEPLATINUM_CONSTANTS_BATTLE_FACTORY_FUNCTIONS_H diff --git a/include/constants/battle_frontier.h b/include/constants/battle_frontier.h index e313daa96c1..e942932dbf7 100644 --- a/include/constants/battle_frontier.h +++ b/include/constants/battle_frontier.h @@ -36,6 +36,16 @@ enum BattleFrontierScene { #define FRONTIER_RECORDS_APP_HALL 5 #define FRONTIER_RECORDS_APP_ARCADE 6 +#define FACTORY_BATTLES_PER_ROUND 7 +#define FACTORY_STREAK_SILVER_BATTLE 21 +#define FACTORY_STREAK_GOLD_BATTLE 49 +#define FACTORY_MAX_DISTINCT_ROUNDS ((FACTORY_STREAK_GOLD_BATTLE / FACTORY_BATTLES_PER_ROUND) + 1) + +#define FACTORY_INITIAL_RENTAL_OPTIONS 6 +#define FACTORY_PARTY_SIZE_SOLO 3 +#define FACTORY_PARTY_SIZE_MULTI 2 +#define FACTORY_MAX_PARTY_SIZE MATH_MAX(FACTORY_PARTY_SIZE_SOLO, 2 * FACTORY_PARTY_SIZE_MULTI) + #define HALL_BATTLES_PER_ROUND 10 #define HALL_STREAK_SILVER_BATTLE 50 #define HALL_STREAK_GOLD_BATTLE 170 diff --git a/include/data/scripts/frscrcmd.h b/include/data/scripts/frscrcmd.h index 51fe9882f28..c772f1837be 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_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_INITBATTLEARCADE, FrontierScrCmd_InitBattleArcade) -ScriptCommand(FRSCRCMD_BATTLEARCADE_LOADTRAINERSFORROUND, FrontierScrCmd_BattleArcade_LoadTrainersForRound) -ScriptCommand(FRSCRCMD_FREEBATTLEARCADE, FrontierScrCmd_FreeBattleArcade) -ScriptCommand(FRSCRCMD_BATTLEARCADE_CLEANUPBATTLE, FrontierScrCmd_BattleArcade_CleanupBattle) -ScriptCommand(FRSCRCMD_BATTLEARCADE_STARTBATTLE, FrontierScrCmd_BattleArcade_StartBattle) -ScriptCommand(FRSCRCMD_BATTLEARCADE_SETUPFIRSTOPPONENT, FrontierScrCmd_BattleArcade_SetupFirstOpponent) -ScriptCommand(FRSCRCMD_BATTLEARCADE_SETUPNEXTOPPONENT, FrontierScrCmd_BattleArcade_SetupNextOpponent) -ScriptCommand(FRSCRCMD_CALLBATTLEARCADEFUNCTION, FrontierScrCmd_CallBattleArcadeFunction) -ScriptCommand(FRSCRCMD_BATTLEARCADE_CHECKWONBATTLE, FrontierScrCmd_BattleArcade_CheckWonBattle) -ScriptCommand(FRSCRCMD_BATTLEARCADE_SENDCOMMMESSAGE, FrontierScrCmd_BattleArcade_SendCommMessage) -ScriptCommand(FRSCRCMD_BATTLEARCADE_WAITFORCOMMRESPONSES, FrontierScrCmd_BattleArcade_WaitForCommResponses) -ScriptCommand(FRSCRCMD_OPENBATTLEARCADEAPP, FrontierScrCmd_OpenBattleArcadeApp) -ScriptCommand(FRSCRCMD_BATTLEARCADE_PRINTTRAINERINFO, FrontierScrCmd_BattleArcade_PrintTrainerIntro) -ScriptCommand(FRSCRCMD_APPLYARCADEEFFECT, FrontierScrCmd_ApplyArcadeEffect) -ScriptCommand(FRSCRCMD_SETITEMDRAWFLAG, FrontierScrCmd_SetItemDrawFlag) -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_INITBATTLEFACTORY, FrontierScrCmd_InitBattleFactory) +ScriptCommand(FRSCRCMD_BATTLEFACTORY_LOADTRAINERSFORROUND, FrontierScrCmd_BattleFactory_LoadTrainersForRound) +ScriptCommand(FRSCRCMD_FREEBATTLEFACTORY, FrontierScrCmd_FreeBattleFactory) +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_ADDSELECTEDRENTALSTOPARTY, FrontierScrCmd_AddSelectedRentalsToParty) +ScriptCommand(FRSCRCMD_BATTLEFACTORY_SETUPNEXTOPPONENT, FrontierScrCmd_BattleFactory_SetupNextOpponent) +ScriptCommand(FRSCRCMD_BATTLEFACTORY_APPLYTRADE, FrontierScrCmd_BattleFactory_ApplyTrade) +ScriptCommand(FRSCRCMD_BATTLEFACTORY_SETUPNEXTOPPONENTSPARTY, FrontierScrCmd_BattleFactory_SetupNextOpponentsParty) +ScriptCommand(FRSCRCMD_CALLBATTLEFACTORYFUNCTION, FrontierScrCmd_CallBattleFactoryFunction) +ScriptCommand(FRSCRCMD_BATTLEFACTORY_CHECKWONBATTLE, FrontierScrCmd_BattleFactory_CheckWonBattle) +ScriptCommand(FRSCRCMD_BATTLEFACTORY_SENDCOMMMESSAGE, FrontierScrCmd_BattleFactory_SendCommMessage) +ScriptCommand(FRSCRCMD_BATTLEFACTORY_WAITFORCOMMRESPONSES, FrontierScrCmd_BattleFactory_WaitForCommResponses) +ScriptCommand(FRSCRCMD_BATTLEFACTORY_PRINTTRAINERINTRO, FrontierScrCmd_BattleFactory_PrintTrainerIntro) +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_INITBATTLEARCADE, FrontierScrCmd_InitBattleArcade) +ScriptCommand(FRSCRCMD_BATTLEARCADE_LOADTRAINERSFORROUND, FrontierScrCmd_BattleArcade_LoadTrainersForRound) +ScriptCommand(FRSCRCMD_FREEBATTLEARCADE, FrontierScrCmd_FreeBattleArcade) +ScriptCommand(FRSCRCMD_BATTLEARCADE_CLEANUPBATTLE, FrontierScrCmd_BattleArcade_CleanupBattle) +ScriptCommand(FRSCRCMD_BATTLEARCADE_STARTBATTLE, FrontierScrCmd_BattleArcade_StartBattle) +ScriptCommand(FRSCRCMD_BATTLEARCADE_SETUPFIRSTOPPONENT, FrontierScrCmd_BattleArcade_SetupFirstOpponent) +ScriptCommand(FRSCRCMD_BATTLEARCADE_SETUPNEXTOPPONENT, FrontierScrCmd_BattleArcade_SetupNextOpponent) +ScriptCommand(FRSCRCMD_CALLBATTLEARCADEFUNCTION, FrontierScrCmd_CallBattleArcadeFunction) +ScriptCommand(FRSCRCMD_BATTLEARCADE_CHECKWONBATTLE, FrontierScrCmd_BattleArcade_CheckWonBattle) +ScriptCommand(FRSCRCMD_BATTLEARCADE_SENDCOMMMESSAGE, FrontierScrCmd_BattleArcade_SendCommMessage) +ScriptCommand(FRSCRCMD_BATTLEARCADE_WAITFORCOMMRESPONSES, FrontierScrCmd_BattleArcade_WaitForCommResponses) +ScriptCommand(FRSCRCMD_OPENBATTLEARCADEAPP, FrontierScrCmd_OpenBattleArcadeApp) +ScriptCommand(FRSCRCMD_BATTLEARCADE_PRINTTRAINERINFO, FrontierScrCmd_BattleArcade_PrintTrainerIntro) +ScriptCommand(FRSCRCMD_APPLYARCADEEFFECT, FrontierScrCmd_ApplyArcadeEffect) +ScriptCommand(FRSCRCMD_SETITEMDRAWFLAG, FrontierScrCmd_SetItemDrawFlag) +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_factory.h b/include/overlay104/battle_factory.h new file mode 100644 index 00000000000..1da57abd4db --- /dev/null +++ b/include/overlay104/battle_factory.h @@ -0,0 +1,81 @@ +#ifndef POKEPLATINUM_BATTLE_FACTORY_H +#define POKEPLATINUM_BATTLE_FACTORY_H + +#include "constants/battle_frontier.h" + +#include "applications/frontier/battle_factory/main.h" +#include "overlay104/frontier_opponents.h" + +#include "battle_factory_save.h" +#include "field_battle_data_transfer.h" +#include "party.h" +#include "savedata.h" +#include "sys_task_manager.h" + +typedef struct BattleFactory { + int unused; + u8 challengeType; + u8 isOpenLevel; + u8 currentBattle; + u8 unused2; + u16 tradeCount; + u8 saveStreak; + u8 seenFactoryHeadIntro; + u16 currentStreak; + u16 currentRound; + u32 unused3; + int wonBattle; + u16 trainerIDs[FACTORY_BATTLES_PER_ROUND * 2]; + FrontierOpponent opponents[2]; + u16 initialRentalSetIDs[FACTORY_INITIAL_RENTAL_OPTIONS]; + u8 initialRentalIVs[FACTORY_INITIAL_RENTAL_OPTIONS]; + u32 initialRentalPersonalities[FACTORY_INITIAL_RENTAL_OPTIONS]; + FrontierPokemon initialRentalMons[FACTORY_INITIAL_RENTAL_OPTIONS]; + u16 unusd4; + u16 opponentMonSetIDs[FACTORY_MAX_PARTY_SIZE]; + u8 opponentMonIVs[FACTORY_MAX_PARTY_SIZE]; + u32 opponentMonPersonalities[FACTORY_MAX_PARTY_SIZE]; + FrontierPokemon opponentMons[FACTORY_MAX_PARTY_SIZE]; + u16 unused5; + Party *playersParty; + Party *opponentsParty; + u16 selectedAppSlots[6]; + u16 playerMonSetIDs[FACTORY_INITIAL_RENTAL_OPTIONS]; + BattleFactorySave *factorySave; + SaveData *saveData; + FieldBattleDTO *dto; + SysTask *corridorAnimation; + u16 commBuffer[60]; + u8 unk_57C; + u8 unk_57D; + u16 unk_57E; + u16 unk_580; + u16 unk_582; + u16 partnerRentalSetIDs[FACTORY_INITIAL_RENTAL_OPTIONS]; + u8 partnerRentalIVs[FACTORY_INITIAL_RENTAL_OPTIONS]; + u32 partnerRentalPersonalities[FACTORY_INITIAL_RENTAL_OPTIONS]; + FrontierPokemon partnerRentalMons[FACTORY_INITIAL_RENTAL_OPTIONS]; + u16 unk_700; + u8 msgsReceived; + u32 unk_704; +} BattleFactory; + +BattleFactory *BattleFactory_Init(SaveData *saveData, u16 resumingFromSave, u8 challengeType, u8 isOpenLevel); +void BattleFactory_LoadTrainersAndRentalsForRound(BattleFactory *factory, u16 resumingFromSave); +void BattleFactory_Free(BattleFactory *factory); +void BattleFactory_GetMonSelectionAppResult(BattleFactory *battleFactory, BattleFactoryAppArgs *args); +void BattleFactory_Save(BattleFactory *factory, u8 saveType); +u16 BattleFactory_IncrementCurrentBattle(BattleFactory *factory); +u16 BattleFactory_GetCurrentBattle(BattleFactory *factory); +u16 BattleFactory_GetNextOpponentObjectID(BattleFactory *factory, u8 trainerSlot); +void BattleFactory_SaveOnLoss(BattleFactory *factory); +void BattleFactory_SaveOnCompletingRound(BattleFactory *factory); +void BattleFactory_AddSelectedRentalsToParty(BattleFactory *factory); +void BattleFactory_SetupNextOpponent(BattleFactory *factory); +void BattleFactory_ApplyTrade(BattleFactory *factory); +void BattleFactory_SetupNextOpponentsParty(BattleFactory *factory); +void BattleFactory_IncrementTradeCount(BattleFactory *factory); +BOOL BattleFactory_SendCommMessage(BattleFactory *factory, u16 command, u16 arg); +u16 BattleFactory_GetEarnedBP(BattleFactory *factory); + +#endif // POKEPLATINUM_BATTLE_FACTORY_H diff --git a/include/overlay104/battle_factory_helpers.h b/include/overlay104/battle_factory_helpers.h new file mode 100644 index 00000000000..0e1565f7922 --- /dev/null +++ b/include/overlay104/battle_factory_helpers.h @@ -0,0 +1,32 @@ +#ifndef POKEPLATINUM_BATTLE_FACTORY_HELPERS_H +#define POKEPLATINUM_BATTLE_FACTORY_HELPERS_H + +#include "overlay104/battle_factory.h" +#include "overlay104/frontier_opponents.h" +#include "overlay104/struct_ov104_02230BE4.h" + +#include "field_battle_data_transfer.h" + +typedef struct { + u16 trainerIDMax; + u16 setIDMin; + u16 setIDMax; + u8 ivs; + u8 canBeUpgraded; +} BattleFactoryPokemonPool; + +void BattleFactory_PickOpponentTrainers(u8 challengeType, int currentRound, u16 trainerIDs[], u8 numTrainers); +const BattleFactoryPokemonPool *BattleFactory_GetPokemonPoolForTrainer(int trainerID, BOOL isOpenLevel); +BOOL BattleFactory_SelectPokemonFromPool(const u16 excludedSpecies[], const u16 excludedItems[], int numExcluded, int numMons, u16 monSetIDs[], int unused, const BattleFactoryPokemonPool *pool, u16 tradeCount, u8 ivList[]); +u8 BattleFactory_GetPlayerPartySize(u8 challengeType); +u8 BattleFactory_GetOpponentPartySize(u8 challengeType, BOOL param1); +void BattleFactory_SelectInitialRentalOptions(u16 round, u8 isOpenLevel, u16 *monSetIDs, FrontierPokemon *mons, u8 *ivs, u32 *personalities, u16 tradeCount, u16 *excludedSpecies, u16 *unused); +void BattleFactory_SelectInitialOpponentMons(u8 numMons, u16 trainerID, u8 isOpenLevel, FrontierPokemon *excludedMons, u16 *monSetIDs, FrontierPokemon *mons, u8 *ivList, u32 *personalities, int numExcluded); +FieldBattleDTO *BattleFactory_SetupBattle(BattleFactory *battleFactory, FieldFrontierDTO *fieldData); +u8 BattleFactory_GetPokemonLevel(BattleFactory *battleFactory); +void BattleFactory_CreateInitialRentalParty(BattleFactory *battleFactory); +void BattleFactory_UpdatePartnersParty(BattleFactory *battleFactory); +BOOL BattleFactory_IsMultiplayerChallenge(u8 challengeType); +u16 BattleFactory_GetCurrentRound(BattleFactory *battleFactory); + +#endif // POKEPLATINUM_BATTLE_FACTORY_HELPERS_H diff --git a/include/overlay104/frontier_communication.h b/include/overlay104/frontier_communication.h index b12884e19c3..d8d21afc5de 100644 --- a/include/overlay104/frontier_communication.h +++ b/include/overlay104/frontier_communication.h @@ -3,8 +3,8 @@ #include "overlay104/battle_arcade.h" #include "overlay104/battle_castle.h" +#include "overlay104/battle_factory.h" #include "overlay104/battle_hall.h" -#include "overlay104/struct_battle_factory.h" #define FRONTIER_COMMUNICATION_UNREACHABLE2 34 #define HALL_COMMUNICATION_SEND_TRAINERS 35 diff --git a/include/overlay104/frscrcmd_battle_factory.h b/include/overlay104/frscrcmd_battle_factory.h index 1b00e81cc63..0eec5804389 100644 --- a/include/overlay104/frscrcmd_battle_factory.h +++ b/include/overlay104/frscrcmd_battle_factory.h @@ -3,21 +3,21 @@ #include "overlay104/defs.h" -BOOL FrontierScrCmd_5C(FrontierScriptContext *param0); -BOOL FrontierScrCmd_5D(FrontierScriptContext *param0); -BOOL FrontierScrCmd_5E(FrontierScriptContext *param0); +BOOL FrontierScrCmd_InitBattleFactory(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_BattleFactory_LoadTrainersForRound(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_FreeBattleFactory(FrontierScriptContext *ctx); BOOL FrontierScrCmd_OpenBattleFactoryAppInitial(FrontierScriptContext *ctx); BOOL FrontierScrCmd_BattleFactory_CleanupBattle(FrontierScriptContext *ctx); BOOL FrontierScrCmd_BattleFactory_StartBattle(FrontierScriptContext *ctx); BOOL FrontierScrCmd_OpenBattleFactoryAppForTrade(FrontierScriptContext *ctx); -BOOL FrontierScrCmd_63(FrontierScriptContext *param0); -BOOL FrontierScrCmd_64(FrontierScriptContext *param0); -BOOL FrontierScrCmd_65(FrontierScriptContext *param0); -BOOL FrontierScrCmd_66(FrontierScriptContext *param0); +BOOL FrontierScrCmd_AddSelectedRentalsToParty(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_BattleFactory_SetupNextOpponent(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_BattleFactory_ApplyTrade(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_BattleFactory_SetupNextOpponentsParty(FrontierScriptContext *ctx); BOOL FrontierScrCmd_CallBattleFactoryFunction(FrontierScriptContext *ctx); BOOL FrontierScrCmd_BattleFactory_CheckWonBattle(FrontierScriptContext *ctx); -BOOL FrontierScrCmd_69(FrontierScriptContext *param0); -BOOL FrontierScrCmd_6A(FrontierScriptContext *param0); -BOOL FrontierScrCmd_6B(FrontierScriptContext *param0); +BOOL FrontierScrCmd_BattleFactory_SendCommMessage(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_BattleFactory_WaitForCommResponses(FrontierScriptContext *ctx); +BOOL FrontierScrCmd_BattleFactory_PrintTrainerIntro(FrontierScriptContext *ctx); #endif // POKEPLATINUM_FRSCRCMD_BATTLE_FACTORY_H diff --git a/include/overlay104/ov104_022339B4.h b/include/overlay104/ov104_022339B4.h deleted file mode 100644 index fe8ae4373d9..00000000000 --- a/include/overlay104/ov104_022339B4.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef POKEPLATINUM_OV104_022339B4_H -#define POKEPLATINUM_OV104_022339B4_H - -#include "applications/frontier/battle_factory/main.h" -#include "overlay104/struct_battle_factory.h" - -#include "savedata.h" - -BattleFactory *ov104_022339B4(SaveData *saveData, u16 param1, u8 param2, u8 param3); -void ov104_02233B98(BattleFactory *param0, u16 param1); -void ov104_022340D0(BattleFactory *param0); -void BattleFactory_GetMonSelectionAppResult(BattleFactory *battleFactory, BattleFactoryAppArgs *args); -void ov104_02234148(BattleFactory *param0, u8 param1); -u16 ov104_02234430(BattleFactory *param0); -u16 ov104_0223443C(BattleFactory *param0); -u16 ov104_02234440(BattleFactory *param0, u8 param1); -void ov104_02234474(BattleFactory *param0); -void ov104_02234480(BattleFactory *param0); -void ov104_0223449C(BattleFactory *param0); -void ov104_02234570(BattleFactory *param0); -void ov104_022346A4(BattleFactory *param0); -void ov104_0223470C(BattleFactory *param0); -void ov104_02234790(BattleFactory *param0); -BOOL ov104_022347A4(BattleFactory *param0, u16 param1, u16 param2); -u16 ov104_022347F8(BattleFactory *param0); - -#endif // POKEPLATINUM_OV104_022339B4_H diff --git a/include/overlay104/ov104_0223A7F4.h b/include/overlay104/ov104_0223A7F4.h deleted file mode 100644 index 8694ffd21b9..00000000000 --- a/include/overlay104/ov104_0223A7F4.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef POKEPLATINUM_OV104_0223A7F4_H -#define POKEPLATINUM_OV104_0223A7F4_H - -#include "overlay104/frontier_opponents.h" -#include "overlay104/struct_battle_factory.h" -#include "overlay104/struct_ov104_02230BE4.h" -#include "overlay104/struct_ov104_0224028C.h" - -#include "field_battle_data_transfer.h" - -void ov104_0223A860(u8 param0, int param1, u16 param2[], u8 param3); -const UnkStruct_ov104_0224028C *ov104_0223A8A8(int param0, int param1); -BOOL ov104_0223A918(const u16 param0[], const u16 param1[], int param2, int param3, u16 param4[], int param5, const UnkStruct_ov104_0224028C *param6, u16 param7, u8 param8[]); -u8 BattleFactory_GetPlayerPartySize(u8 challengeType); -u8 BattleFactory_GetOpponentPartySize(u8 challengeType, BOOL param1); -void ov104_0223AAA0(u16 param0, u8 param1, u16 *param2, FrontierPokemon *param3, u8 *param4, u32 *param5, u16 param6, u16 *param7, u16 *param8); -void ov104_0223AB0C(u8 param0, u16 param1, u8 param2, FrontierPokemon *param3, u16 *param4, FrontierPokemon *param5, u8 *param6, u32 *param7, int param8); -FieldBattleDTO *FieldBattleDTO_NewBattleFactory(BattleFactory *battleFactory, FieldFrontierDTO *fieldData); -u8 BattleFactory_GetPokemonLevel(BattleFactory *battleFactory); -void ov104_0223ADB0(BattleFactory *battleFactory); -void ov104_0223AE30(BattleFactory *battleFactory); -BOOL BattleFactory_IsMultiplayerChallenge(u8 challengeType); -u16 ov104_0223AF34(BattleFactory *battleFactory); - -#endif // POKEPLATINUM_OV104_0223A7F4_H diff --git a/include/overlay104/struct_battle_factory.h b/include/overlay104/struct_battle_factory.h deleted file mode 100644 index cf4351ebdc2..00000000000 --- a/include/overlay104/struct_battle_factory.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_BATTLE_FACTORY_H -#define POKEPLATINUM_STRUCT_BATTLE_FACTORY_H - -#include "overlay104/frontier_opponents.h" - -#include "battle_factory_save.h" -#include "field_battle_data_transfer.h" -#include "party.h" -#include "savedata.h" -#include "sys_task_manager.h" - -typedef struct BattleFactory { - int unk_00; - u8 challengeType; - u8 isOpenLevel; - u8 unk_06; - u8 unk_07; - u16 unk_08; - u8 unk_0A; - u8 unk_0B; - u16 currentStreak; - u16 unk_0E; - u32 unk_10; - int wonBattle; - u16 trainerIDs[14]; - FrontierOpponent unk_34[2]; - u16 unk_254[6]; - u8 unk_260[6]; - u32 unk_268[6]; - FrontierPokemon unk_280[6]; - u16 unk_3D0; - u16 unk_3D2[4]; - u8 unk_3DA[4]; - u32 unk_3E0[4]; - FrontierPokemon unk_3F0[4]; - u16 unk_4D0; - Party *playersParty; - Party *opponentsParty; - u16 unk_4DC[6]; - u16 unk_4E8[6]; - BattleFactorySave *factorySave; - SaveData *saveData; - FieldBattleDTO *dto; - SysTask *unk_500; - u16 commBuffer[60]; - u8 unk_57C; - u8 unk_57D; - u16 unk_57E; - u16 unk_580; - u16 unk_582; - u16 unk_584[6]; - u8 unk_590[6]; - u32 unk_598[6]; - FrontierPokemon unk_5B0[6]; - u16 unk_700; - u8 msgsReceived; - u32 unk_704; -} BattleFactory; - -#endif // POKEPLATINUM_STRUCT_BATTLE_FACTORY_H diff --git a/include/overlay104/struct_ov104_0224028C.h b/include/overlay104/struct_ov104_0224028C.h deleted file mode 100644 index 8ef7bc470f8..00000000000 --- a/include/overlay104/struct_ov104_0224028C.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef POKEPLATINUM_STRUCT_OV104_0224028C_H -#define POKEPLATINUM_STRUCT_OV104_0224028C_H - -typedef struct { - u16 unk_00; - u16 unk_02; - u16 unk_04; - u8 unk_06; - u8 unk_07; -} UnkStruct_ov104_0224028C; - -#endif // POKEPLATINUM_STRUCT_OV104_0224028C_H diff --git a/platinum.us/main.lsf b/platinum.us/main.lsf index 7a7d9325300..0068813ad1f 100644 --- a/platinum.us/main.lsf +++ b/platinum.us/main.lsf @@ -1542,7 +1542,7 @@ Overlay overlay104 Object main.nef.p/src_overlay104_frscrcmd.c.o Object main.nef.p/src_overlay104_ov104_02231F74.c.o Object main.nef.p/src_overlay104_frscrcmd_battle_factory.c.o - Object main.nef.p/src_overlay104_ov104_022339B4.c.o + Object main.nef.p/src_overlay104_battle_factory.c.o 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 @@ -1555,7 +1555,7 @@ Overlay overlay104 Object main.nef.p/src_overlay104_ov104_022395F0.c.o Object main.nef.p/src_overlay104_ov104_02239C58.c.o 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_factory_helpers.c.o Object main.nef.p/src_overlay104_battle_hall_helpers.c.o Object main.nef.p/src_overlay104_battle_castle_helpers.c.o Object main.nef.p/src_overlay104_battle_arcade_helpers.c.o diff --git a/res/field/frontier_scripts/frontier_scripts_battle_factory.s b/res/field/frontier_scripts/frontier_scripts_battle_factory.s index da4f27d2703..2677968c37b 100644 --- a/res/field/frontier_scripts/frontier_scripts_battle_factory.s +++ b/res/field/frontier_scripts/frontier_scripts_battle_factory.s @@ -451,8 +451,8 @@ _033E: FrontierScrCmd_22 _0020 FrontierScrCmd_24 _0088 InitNewBattleRecording - FrontierScrCmd_5C VAR_0x8003, VAR_0x8001, VAR_0x8002 - CallBattleFactoryFunction BF_FUNC_UNK_31, 0, 0, VAR_0x8008 + InitBattleFactory VAR_0x8003, VAR_0x8001, VAR_0x8002 + CallBattleFactoryFunction BF_FUNC_START_CORRIDOR_ANIMATION, 0, 0, VAR_0x8008 CallBattleFactoryFunction BF_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 1, _0377 GoTo _03B6 @@ -465,9 +465,9 @@ _0377: _0385: SetVar VAR_0x8002, 0 - FrontierScrCmd_69 VAR_0x8002, 0, VAR_0x8008 + BattleFactory_SendCommMessage VAR_0x8002, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _0385 - FrontierScrCmd_6A VAR_0x8002 + BattleFactory_WaitForCommResponses VAR_0x8002 ClearReceivedTempDataAllPlayers ClearReceivedTempDataAllPlayers SyncConnectedPlayers 230 @@ -476,7 +476,7 @@ _0385: End _03B6: - FrontierScrCmd_5D VAR_0x8003 + BattleFactory_LoadTrainersForRound VAR_0x8003 CallBattleFactoryFunction BF_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 1, _03D6 GoTo _0407 @@ -484,9 +484,9 @@ _03B6: _03D6: SetVar VAR_0x8002, 1 - FrontierScrCmd_69 VAR_0x8002, 0, VAR_0x8008 + BattleFactory_SendCommMessage VAR_0x8002, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _03D6 - FrontierScrCmd_6A VAR_0x8002 + BattleFactory_WaitForCommResponses VAR_0x8002 ClearReceivedTempDataAllPlayers ClearReceivedTempDataAllPlayers SyncConnectedPlayers 231 @@ -517,7 +517,7 @@ _0447: _0471: FrontierScrCmd_25 5 FrontierScrCmd_23 FR_VAR_0x800F - CallBattleFactoryFunction BF_FUNC_UNK_23, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_CURRENT_BATTLE, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _049B SetVar VAR_0x8003, 1 GoTo _0C29 @@ -543,15 +543,15 @@ _04C5: _04D5: SetVar VAR_0x8002, 3 - FrontierScrCmd_69 VAR_0x8002, 0, VAR_0x8008 + BattleFactory_SendCommMessage VAR_0x8002, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _04D5 - FrontierScrCmd_6A VAR_0x8002 + BattleFactory_WaitForCommResponses VAR_0x8002 ClearReceivedTempDataAllPlayers ClearReceivedTempDataAllPlayers SyncConnectedPlayers 232 ClearReceivedTempDataAllPlayers - CallBattleFactoryFunction BF_FUNC_UNK_39, 0, 0, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_19, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_CREATE_OPPONENT_MONS, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_CURRENT_ROUND, 0, 0, VAR_0x8008 SetVar VAR_0x8009, VAR_0x8008 CallIfEq VAR_0x8009, 0, _0555 CallIfEq VAR_0x8009, 1, _0597 @@ -561,35 +561,35 @@ _04D5: Return _0555: - CallBattleFactoryFunction BF_FUNC_UNK_15, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_SPECIES, 0, 0, VAR_0x8008 BufferSpeciesName 1, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_15, 1, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_SPECIES, 1, 0, VAR_0x8008 BufferSpeciesName 2, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_15, 2, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_SPECIES, 2, 0, VAR_0x8008 BufferSpeciesName 3, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_15, 3, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_SPECIES, 3, 0, VAR_0x8008 BufferSpeciesName 4, VAR_0x8008 Message BattleFactoryScene_Text_MultiOpponentInfo4Mon Return _0597: - CallBattleFactoryFunction BF_FUNC_UNK_15, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_SPECIES, 0, 0, VAR_0x8008 BufferSpeciesName 1, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_15, 2, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_SPECIES, 2, 0, VAR_0x8008 BufferSpeciesName 2, VAR_0x8008 Message BattleFactoryScene_Text_MultiOpponentInfo2Mon Return _05BB: - CallBattleFactoryFunction BF_FUNC_UNK_16, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_MOVE, 0, 0, VAR_0x8008 BufferMoveName 0, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_16, 2, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_MOVE, 2, 0, VAR_0x8008 BufferMoveName 1, VAR_0x8008 Message BattleFactoryScene_Text_MultiOpponentInfoFirstMoves Return _05D9: - CallBattleFactoryFunction BF_FUNC_UNK_16, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_MOVE, 0, 0, VAR_0x8008 BufferMoveName 0, VAR_0x8008 Message BattleFactoryScene_Text_MultiOpponentInfoCommonType Return @@ -599,7 +599,7 @@ _05EB: End _05F3: - CallBattleFactoryFunction BF_FUNC_UNK_19, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_CURRENT_ROUND, 0, 0, VAR_0x8008 SetVar VAR_0x8009, VAR_0x8008 CallIfEq VAR_0x8009, 0, _0643 CallIfEq VAR_0x8009, 1, _0676 @@ -609,39 +609,39 @@ _05F3: Return _0643: - CallBattleFactoryFunction BF_FUNC_UNK_15, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_SPECIES, 0, 0, VAR_0x8008 BufferSpeciesName 1, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_15, 1, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_SPECIES, 1, 0, VAR_0x8008 BufferSpeciesName 3, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_15, 2, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_SPECIES, 2, 0, VAR_0x8008 BufferSpeciesName 5, VAR_0x8008 Message BattleFactoryScene_Text_OpponentInfo3Mon Return _0676: - CallBattleFactoryFunction BF_FUNC_UNK_15, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_SPECIES, 0, 0, VAR_0x8008 BufferSpeciesName 1, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_15, 1, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_SPECIES, 1, 0, VAR_0x8008 BufferSpeciesName 3, VAR_0x8008 Message BattleFactoryScene_Text_OpponentInfo2Mon Return _069A: - CallBattleFactoryFunction BF_FUNC_UNK_16, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_MOVE, 0, 0, VAR_0x8008 BufferMoveName 0, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_15, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_SPECIES, 0, 0, VAR_0x8008 BufferSpeciesName 1, VAR_0x8008 Message BattleFactoryScene_Text_OpponentInfo1Mon Return _06BB: - CallBattleFactoryFunction BF_FUNC_UNK_16, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_MONS_MOVE, 0, 0, VAR_0x8008 BufferMoveName 0, VAR_0x8008 Message BattleFactoryScene_Text_OpponentInfoFirstMove Return _06CD: - CallBattleFactoryFunction BF_FUNC_UNK_18, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_COMMON_TYPE, 0, 0, VAR_0x8008 CallIfNe VAR_0x8008, 255, _06F0 CallIfEq VAR_0x8008, 255, _06FB Return @@ -669,11 +669,11 @@ _0721: _072D: SetVar VAR_0x8002, 2 - FrontierScrCmd_69 VAR_0x8002, 0, VAR_0x8008 + BattleFactory_SendCommMessage VAR_0x8002, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _072D - FrontierScrCmd_6A VAR_0x8002 + BattleFactory_WaitForCommResponses VAR_0x8002 ClearReceivedTempDataAllPlayers - CallBattleFactoryFunction BF_FUNC_UNK_40, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_CREATE_INITAL_PARTY, 0, 0, VAR_0x8008 ClearReceivedTempDataAllPlayers SyncConnectedPlayers 160 ClearReceivedTempDataAllPlayers @@ -683,13 +683,13 @@ _072D: _0765: FadeScreenOut CloseMessage - CallBattleFactoryFunction BF_FUNC_UNK_32, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_STOP_CORRIDOR_ANIMATION, 0, 0, VAR_0x8008 CallBattleFactoryFunction BF_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 CallIfEq VAR_0x8008, 1, _07D2 OpenBattleFactoryAppInitial - CallBattleFactoryFunction BF_FUNC_UNK_36, 0, 0, VAR_0x8008 - FrontierScrCmd_63 - CallBattleFactoryFunction BF_FUNC_UNK_31, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_INCREMENT_TRADE_COUNT, 0, 0, VAR_0x8008 + AddSelectedRentalsToParty + CallBattleFactoryFunction BF_FUNC_START_CORRIDOR_ANIMATION, 0, 0, VAR_0x8008 CallBattleFactoryFunction BF_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 CallIfEq VAR_0x8008, 1, _07C8 FadeScreenIn @@ -743,7 +743,7 @@ _084E: FrontierScrCmd_25 3 FrontierScrCmd_25 4 FrontierScrCmd_23 30 - CallBattleFactoryFunction BF_FUNC_UNK_32, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_STOP_CORRIDOR_ANIMATION, 0, 0, VAR_0x8008 FrontierScrCmd_03 FRONTIER_SCENE_FACTORY_BATTLE_ROOM GetPlayerObjEventGfx VAR_0x8007 FrontierScrCmd_22 _00F8 @@ -752,9 +752,9 @@ _084E: ApplyMovement 4, _01F4 WaitMovement Call _1471 - CallBattleFactoryFunction BF_FUNC_UNK_37, 0, 0, VAR_0x8008 - GoToIfEq VAR_0x8008, 1, _14E6 - GoToIfEq VAR_0x8008, 2, _150B + CallBattleFactoryFunction BF_FUNC_GET_NEXT_BATTLE_TYPE, 0, 0, VAR_0x8008 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_SILVER, _14E6 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_GOLD, _150B Call _1612 BufferNumber 0, VAR_0x8008 Call _09E4 @@ -763,8 +763,8 @@ _084E: WaitTime 15, VAR_0x8008 ApplyMovement 98, _01EC WaitMovement - CallBattleFactoryFunction BF_FUNC_UNK_33, 0, 0, VAR_0x8008 - FrontierScrCmd_6B 0 + CallBattleFactoryFunction BF_FUNC_LOAD_TRAINERS, 0, 0, VAR_0x8008 + BattleFactory_PrintTrainerIntro 0 WaitABPress CloseMessage GoTo _091F @@ -780,7 +780,7 @@ _0927: FrontierScrCmd_25 3 FrontierScrCmd_25 4 FrontierScrCmd_23 30 - CallBattleFactoryFunction BF_FUNC_UNK_32, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_STOP_CORRIDOR_ANIMATION, 0, 0, VAR_0x8008 FrontierScrCmd_03 FRONTIER_SCENE_FACTORY_BATTLE_ROOM GetPlayerObjEventGfx VAR_0x8007 FrontierScrCmd_22 _0100 @@ -798,14 +798,14 @@ _0927: WaitTime 15, VAR_0x8008 ApplyMovement 98, _01EC WaitMovement - CallBattleFactoryFunction BF_FUNC_UNK_33, 0, 0, VAR_0x8008 - FrontierScrCmd_6B 0 + CallBattleFactoryFunction BF_FUNC_LOAD_TRAINERS, 0, 0, VAR_0x8008 + BattleFactory_PrintTrainerIntro 0 WaitTime 30, VAR_0x8008 CloseMessage ApplyMovement 99, _01EC WaitMovement - CallBattleFactoryFunction BF_FUNC_UNK_33, 0, 0, VAR_0x8008 - FrontierScrCmd_6B 1 + CallBattleFactoryFunction BF_FUNC_LOAD_TRAINERS, 0, 0, VAR_0x8008 + BattleFactory_PrintTrainerIntro 1 WaitTime 30, VAR_0x8008 CloseMessage MessageNoSkip BattleFactoryScene_Text_PleaseWait @@ -813,17 +813,17 @@ _0927: End _09E4: - CallBattleFactoryFunction BF_FUNC_UNK_20, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_OPPONENT_OBJECT_ID, 0, 0, VAR_0x8008 SetVar VAR_0x800B, VAR_0x8008 FrontierScrCmd_22 _0150 FrontierScrCmd_24 _0160 Return _09FF: - CallBattleFactoryFunction BF_FUNC_UNK_20, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_OPPONENT_OBJECT_ID, 0, 0, VAR_0x8008 SetVar VAR_0x800B, VAR_0x8008 FrontierScrCmd_22 _0150 - CallBattleFactoryFunction BF_FUNC_UNK_20, 1, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_OPPONENT_OBJECT_ID, 1, 0, VAR_0x8008 SetVar VAR_0x800C, VAR_0x8008 FrontierScrCmd_22 _0158 FrontierScrCmd_24 _0170 @@ -838,9 +838,9 @@ _0A2D: _0A41: CallBattleFactoryFunction BF_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 1, _0A92 - CallBattleFactoryFunction BF_FUNC_UNK_37, 0, 0, VAR_0x8008 - GoToIfEq VAR_0x8008, 1, _0A82 - GoToIfEq VAR_0x8008, 2, _0A82 + CallBattleFactoryFunction BF_FUNC_GET_NEXT_BATTLE_TYPE, 0, 0, VAR_0x8008 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_SILVER, _0A82 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_GOLD, _0A82 FrontierScrCmd_3F 3 GoTo _0AD0 End @@ -853,11 +853,11 @@ _0A82: _0A92: SetVar VAR_0x8002, 6 - FrontierScrCmd_69 VAR_0x8002, 0, VAR_0x8008 + BattleFactory_SendCommMessage VAR_0x8002, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _0A92 - FrontierScrCmd_6A VAR_0x8002 + BattleFactory_WaitForCommResponses VAR_0x8002 ClearReceivedTempDataAllPlayers - CallBattleFactoryFunction BF_FUNC_UNK_38, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_UPDATE_PARTNERS_PARTY, 0, 0, VAR_0x8008 ClearReceivedTempDataAllPlayers SyncConnectedPlayers 161 ClearReceivedTempDataAllPlayers @@ -869,14 +869,14 @@ _0A92: _0AD0: BattleFactory_StartBattle BattleFactory_CleanupBattle - CallBattleFactoryFunction BF_FUNC_UNK_30, 4, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_UPDATE_BACKGROUND, 4, 0, VAR_0x8008 FadeScreenIn BattleFactory_CheckWonBattle VAR_0x8008 GoToIfEq VAR_0x8008, 0, _1233 IncrementRecordValue RECORD_BATTLE_FACTORY_VICTORIES - CallBattleFactoryFunction BF_FUNC_UNK_37, 0, 0, VAR_0x8008 - GoToIfEq VAR_0x8008, 1, _15AA - GoToIfEq VAR_0x8008, 2, _15DE + CallBattleFactoryFunction BF_FUNC_GET_NEXT_BATTLE_TYPE, 0, 0, VAR_0x8008 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_SILVER, _15AA + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_GOLD, _15DE Call _1612 BufferNumber 0, VAR_0x8008 GoTo _0B30 @@ -893,9 +893,9 @@ _0B3E: End _0B4C: - CallBattleFactoryFunction BF_FUNC_UNK_14, 1, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_INCREMENT_CURRENT_BATTLE, 1, 0, VAR_0x8008 CallBattleFactoryFunction BF_FUNC_INCREMENT_CURRENT_STREAK, 0, 0, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_23, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_CURRENT_BATTLE, 0, 0, VAR_0x8008 GoToIfNe VAR_0x8008, 7, _0C17 GoTo _0B76 End @@ -922,11 +922,11 @@ _0BCB: End _0BD9: - CallBattleFactoryFunction BF_FUNC_UNK_22, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_SAVE_ON_COMPLETING_ROUND, 0, 0, VAR_0x8008 SetSystemVar VAR_BATTLE_FACTORY_LOBBY_LOAD_ACTION, 1 Message BattleFactoryScene_Text_BPEarned BufferPlayerName 0 - CallBattleFactoryFunction BF_FUNC_UNK_35, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_EARNED_BP, 0, 0, VAR_0x8008 BufferNumber 1, VAR_0x8008 GiveBattlePoints VAR_0x8008 Message BattleFactoryScene_Text_ReceiveBP @@ -947,9 +947,9 @@ _0C17: End _0C29: - CallBattleFactoryFunction BF_FUNC_UNK_37, 0, 0, VAR_0x8008 - GoToIfEq VAR_0x8008, 1, _14AE - GoToIfEq VAR_0x8008, 2, _14AE + CallBattleFactoryFunction BF_FUNC_GET_NEXT_BATTLE_TYPE, 0, 0, VAR_0x8008 + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_SILVER, _14AE + GoToIfEq VAR_0x8008, FRONTIER_NEXT_BATTLE_GOLD, _14AE GoTo _0C52 End @@ -960,7 +960,7 @@ _0C52: End _0C65: - CallBattleFactoryFunction BF_FUNC_UNK_23, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_GET_CURRENT_BATTLE, 0, 0, VAR_0x8008 AddVar VAR_0x8008, 1 BufferNumber 0, VAR_0x8008 Message BattleFactoryScene_Text_AreYouReady @@ -1068,9 +1068,9 @@ _0E36: _0E45: SetVar VAR_0x8002, 4 - FrontierScrCmd_69 VAR_0x8002, 0, VAR_0x8008 + BattleFactory_SendCommMessage VAR_0x8002, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _0E45 - FrontierScrCmd_6A VAR_0x8002 + BattleFactory_WaitForCommResponses VAR_0x8002 ClearReceivedTempDataAllPlayers CallBattleFactoryFunction BF_FUNC_UNK_24, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 1, _0E8A @@ -1089,7 +1089,7 @@ _0E8A: _0E9F: SetVar VAR_0x8003, 0 - FrontierScrCmd_64 + BattleFactory_SetupNextOpponent Call _04A9 CallBattleFactoryFunction BF_FUNC_UNK_0, 1, 0, VAR_0x8008 Message BattleFactoryScene_Text_TradeQuestion @@ -1111,9 +1111,9 @@ _0EEE: _0EFA: SetVar VAR_0x8002, 5 - FrontierScrCmd_69 VAR_0x8002, 0, VAR_0x8008 + BattleFactory_SendCommMessage VAR_0x8002, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _0EFA - FrontierScrCmd_6A VAR_0x8002 + BattleFactory_WaitForCommResponses VAR_0x8002 ClearReceivedTempDataAllPlayers GoTo _0F23 End @@ -1134,12 +1134,12 @@ _0F4D: End _0F5D: - CallBattleFactoryFunction BF_FUNC_UNK_32, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_STOP_CORRIDOR_ANIMATION, 0, 0, VAR_0x8008 CallBattleFactoryFunction BF_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 CallIfEq VAR_0x8008, 1, _0FAB OpenBattleFactoryAppForTrade - FrontierScrCmd_65 - CallBattleFactoryFunction BF_FUNC_UNK_31, 0, 0, VAR_0x8008 + BattleFactory_ApplyTrade + CallBattleFactoryFunction BF_FUNC_START_CORRIDOR_ANIMATION, 0, 0, VAR_0x8008 CallBattleFactoryFunction BF_FUNC_IS_MULTIPLAYER_CHALLENGE, 0, 0, VAR_0x8008 CallIfEq VAR_0x8008, 1, _0FB5 FadeScreenIn @@ -1170,9 +1170,9 @@ _0FDB: _0FE5: SetVar VAR_0x8002, 5 - FrontierScrCmd_69 VAR_0x8002, 1, VAR_0x8008 + BattleFactory_SendCommMessage VAR_0x8002, 1, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _0FE5 - FrontierScrCmd_6A VAR_0x8002 + BattleFactory_WaitForCommResponses VAR_0x8002 ClearReceivedTempDataAllPlayers CallBattleFactoryFunction BF_FUNC_UNK_26, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _0F23 @@ -1185,7 +1185,7 @@ _1022: End _102C: - FrontierScrCmd_66 + BattleFactory_SetupNextOpponentsParty GoTo _07DC End @@ -1276,13 +1276,13 @@ _113E: _115C: SetSystemVar VAR_BATTLE_FACTORY_LOBBY_LOAD_ACTION, 2 - CallBattleFactoryFunction BF_FUNC_UNK_10, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_QUICKSAVE, 0, 0, VAR_0x8008 Call _137B CloseMessage FadeScreenOut - CallBattleFactoryFunction BF_FUNC_UNK_32, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_STOP_CORRIDOR_ANIMATION, 0, 0, VAR_0x8008 FreeBattleRecording - FrontierScrCmd_5E + FreeBattleFactory CallBattleFactoryFunction BF_FUNC_RESET_SYSTEM, 0, 0, VAR_0x8008 End @@ -1307,7 +1307,7 @@ _11CF: _11DB: SetVar VAR_0x8002, 4 - FrontierScrCmd_69 VAR_0x8002, 1, VAR_0x8008 + BattleFactory_SendCommMessage VAR_0x8002, 1, VAR_0x8008 GoToIfEq VAR_0x8008, 0, _11DB GoTo _11FE End @@ -1322,7 +1322,7 @@ _11FE: End _1216: - CallBattleFactoryFunction BF_FUNC_UNK_21, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_SAVE_ON_LOSS, 0, 0, VAR_0x8008 SetSystemVar VAR_BATTLE_FACTORY_LOBBY_LOAD_ACTION, 3 GoTo _12F3 End @@ -1359,7 +1359,7 @@ _12A2: End _12AA: - CallBattleFactoryFunction BF_FUNC_UNK_21, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_SAVE_ON_LOSS, 0, 0, VAR_0x8008 SetSystemVar VAR_BATTLE_FACTORY_LOBBY_LOAD_ACTION, 3 GoTo _12BF End @@ -1393,9 +1393,9 @@ _1303: CallIfEq VAR_0x8008, 2, _1358 CallBattleFactoryFunction BF_FUNC_GET_CHALLENGE_TYPE, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 3, _1368 - CallBattleFactoryFunction BF_FUNC_UNK_32, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_STOP_CORRIDOR_ANIMATION, 0, 0, VAR_0x8008 FreeBattleRecording - FrontierScrCmd_5E + FreeBattleFactory FrontierScrCmd_02 _1358: @@ -1409,9 +1409,9 @@ _135E: Return _1368: - CallBattleFactoryFunction BF_FUNC_UNK_32, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_STOP_CORRIDOR_ANIMATION, 0, 0, VAR_0x8008 FreeBattleRecording - FrontierScrCmd_5E + FreeBattleFactory FrontierScrCmd_04 FRONTIER_SCENE_14, 1 End @@ -1433,7 +1433,7 @@ _1391: FrontierScrCmd_25 0 FrontierScrCmd_25 4 FrontierScrCmd_03 FRONTIER_SCENE_FACTORY_CORRIDOR - CallBattleFactoryFunction BF_FUNC_UNK_31, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_START_CORRIDOR_ANIMATION, 0, 0, VAR_0x8008 GetPlayerObjEventGfx VAR_0x8007 FrontierScrCmd_22 _0008 FrontierScrCmd_24 _0098 @@ -1445,7 +1445,7 @@ _13EA: FrontierScrCmd_25 2 FrontierScrCmd_25 4 FrontierScrCmd_03 FRONTIER_SCENE_FACTORY_CORRIDOR - CallBattleFactoryFunction BF_FUNC_UNK_31, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_START_CORRIDOR_ANIMATION, 0, 0, VAR_0x8008 GetPlayerObjEventGfx VAR_0x8007 FrontierScrCmd_22 _0014 FrontierScrCmd_24 _00BC @@ -1473,20 +1473,20 @@ _1447: Return _1471: - CallBattleFactoryFunction BF_FUNC_UNK_30, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_UPDATE_BACKGROUND, 0, 0, VAR_0x8008 WaitTime 3, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_30, 1, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_UPDATE_BACKGROUND, 1, 0, VAR_0x8008 WaitTime 3, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_30, 2, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_UPDATE_BACKGROUND, 2, 0, VAR_0x8008 WaitTime 3, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_30, 3, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_UPDATE_BACKGROUND, 3, 0, VAR_0x8008 WaitTime 3, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_30, 4, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_UPDATE_BACKGROUND, 4, 0, VAR_0x8008 Return _14AE: GoToIfEq VAR_0x8003, 1, _0C52 - CallBattleFactoryFunction BF_FUNC_UNK_41, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_CHECK_SEEN_HEAD_INTRO, 0, 0, VAR_0x8008 GoToIfEq VAR_0x8008, 1, _0C52 Call _1612 BufferNumber 0, VAR_0x8008 @@ -1515,7 +1515,7 @@ _150B: End _1530: - CallBattleFactoryFunction BF_FUNC_UNK_34, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_SET_RENTED_MONS_IN_STRING, 0, 0, VAR_0x8008 GetRandom VAR_0x8008, 90 AddVar VAR_0x8008, 10 BufferNumber 3, VAR_0x8008 @@ -1580,7 +1580,7 @@ _162E: _1630: WaitTime 1, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_27, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_INIT_COMM_MANAGER, 0, 0, VAR_0x8008 WaitTime 1, VAR_0x8008 ClearReceivedTempDataAllPlayers SyncConnectedPlayers 195 @@ -1589,7 +1589,7 @@ _1630: _164D: WaitTime 1, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_27, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_INIT_COMM_MANAGER, 0, 0, VAR_0x8008 WaitTime 1, VAR_0x8008 ClearReceivedTempDataAllPlayers SyncConnectedPlayers 196 @@ -1598,7 +1598,7 @@ _164D: _166A: WaitTime 1, VAR_0x8008 - CallBattleFactoryFunction BF_FUNC_UNK_27, 0, 0, VAR_0x8008 + CallBattleFactoryFunction BF_FUNC_INIT_COMM_MANAGER, 0, 0, VAR_0x8008 WaitTime 1, VAR_0x8008 ClearReceivedTempDataAllPlayers SyncConnectedPlayers 197 diff --git a/src/applications/frontier/battle_factory/main.c b/src/applications/frontier/battle_factory/main.c index 94b48aef9f0..ced80bc78aa 100644 --- a/src/applications/frontier/battle_factory/main.c +++ b/src/applications/frontier/battle_factory/main.c @@ -13,8 +13,8 @@ #include "applications/frontier/battle_factory/sprite_manager.h" #include "applications/frontier/battle_factory/windows.h" #include "applications/pokemon_summary_screen/main.h" +#include "overlay104/battle_factory_helpers.h" #include "overlay104/frontier_opponents.h" -#include "overlay104/ov104_0223A7F4.h" #include "bg_window.h" #include "communication_information.h" @@ -61,10 +61,6 @@ FS_EXTERN_OVERLAY(overlay104); -#define NUM_INITIAL_SELECT_OPTIONS 6 -#define PARTY_SIZE_SOLO 3 -#define PARTY_SIZE_MULTI 2 - #define MENU_OPTION_SUMMARY 0 #define MENU_OPTION_RENT 1 #define MENU_OPTION_CANCEL 2 @@ -102,7 +98,7 @@ typedef struct BattleFactoryApp { ApplicationManager *monSummaryAppMan; u8 subState; u8 challengeType; - u8 unk_0A; + u8 isOpenLevel; u8 isExchangeMode; int conveyorXOffset; u8 printerID; @@ -135,12 +131,12 @@ typedef struct BattleFactoryApp { PaletteData *plttData; G3DPipelineBuffers *g3dPipeline; PokemonSpriteManager *monSpriteMan; - PokemonSprite *monSprites[MATH_MAX(PARTY_SIZE_SOLO, PARTY_SIZE_MULTI)]; + PokemonSprite *monSprites[MATH_MAX(FACTORY_PARTY_SIZE_SOLO, FACTORY_PARTY_SIZE_MULTI)]; Options *options; SaveData *saveData; PokemonSummary *monSummary; BattleFactoryAppSpriteManager spriteMan; - BattleFactoryAppPokeballSprite *ballSprites[NUM_INITIAL_SELECT_OPTIONS]; + BattleFactoryAppPokeballSprite *ballSprites[FACTORY_INITIAL_RENTAL_OPTIONS]; BattleFactoryAppCursor *monCursor; BattleFactoryAppCursor *menuCursor; BattleFactoryAppPanelSprite *bluePanelSprite; @@ -153,8 +149,8 @@ typedef struct BattleFactoryApp { NARC *narc; u16 commPayload[60]; u16 partnerTradedMon; - u16 partnerMonSpecies[PARTY_SIZE_MULTI]; - u16 partnenMonGenders[PARTY_SIZE_MULTI]; + u16 partnerMonSpecies[FACTORY_PARTY_SIZE_MULTI]; + u16 partnenMonGenders[FACTORY_PARTY_SIZE_MULTI]; u8 numTradeResultMsgReceived; u8 partnerListingUpdateNeeded; u32 unused3; @@ -256,7 +252,7 @@ static void DummyCreatePayload(BattleFactoryApp *app, u16 cmd); static void CreateUpdateSelectionPayload(BattleFactoryApp *app, u16 cmd, u16 unused); static void CreateTradeResultPayload(BattleFactoryApp *app, u16 cmd, u16 tradedMon); -static const CoordinatesU16 sInitialSelectionPokeballPositions[NUM_INITIAL_SELECT_OPTIONS] = { +static const CoordinatesU16 sInitialSelectionPokeballPositions[FACTORY_INITIAL_RENTAL_OPTIONS] = { { 24, 112 }, { 64, 112 }, { 104, 112 }, @@ -265,25 +261,25 @@ static const CoordinatesU16 sInitialSelectionPokeballPositions[NUM_INITIAL_SELEC { 224, 112 } }; -static const CoordinatesU16 sExchangeSelectPokeballPositions[PARTY_SIZE_SOLO] = { +static const CoordinatesU16 sExchangeSelectPokeballPositions[FACTORY_PARTY_SIZE_SOLO] = { { 64, 112 }, { 120, 112 }, { 176, 112 } }; -static const CoordinatesU16 sExchangeSelectMultiPokeballPositions[PARTY_SIZE_MULTI] = { +static const CoordinatesU16 sExchangeSelectMultiPokeballPositions[FACTORY_PARTY_SIZE_MULTI] = { { 96, 112 }, { 152, 112 } }; -static const CoordinatesU16 sReceiveSelectMultiPokeballPositions[PARTY_SIZE_MULTI * 2] = { +static const CoordinatesU16 sReceiveSelectMultiPokeballPositions[FACTORY_PARTY_SIZE_MULTI * 2] = { { 40, 112 }, { 96, 112 }, { 152, 112 }, { 208, 112 } }; -static const CoordinatesS16 sInitialSelectCursorPositions[NUM_INITIAL_SELECT_OPTIONS] = { +static const CoordinatesS16 sInitialSelectCursorPositions[FACTORY_INITIAL_RENTAL_OPTIONS] = { { 24, 112 }, { 64, 112 }, { 104, 112 }, @@ -292,7 +288,7 @@ static const CoordinatesS16 sInitialSelectCursorPositions[NUM_INITIAL_SELECT_OPT { 224, 112 } }; -static const CoordinatesS16 sExchangeSelectCursorPositions[PARTY_SIZE_SOLO + 1] = { +static const CoordinatesS16 sExchangeSelectCursorPositions[FACTORY_PARTY_SIZE_SOLO + 1] = { { 64, 112 }, { 120, 112 }, { 176, 112 }, @@ -306,7 +302,7 @@ static const u8 sExchangeSelectCursorAnimIDs[NELEMS(sExchangeSelectCursorPositio ANIM_ID_MENU_CURSOR }; -static const CoordinatesS16 sExchangeSelectMultiCursorPositions[PARTY_SIZE_MULTI + 1] = { +static const CoordinatesS16 sExchangeSelectMultiCursorPositions[FACTORY_PARTY_SIZE_MULTI + 1] = { { 96, 112 }, { 152, 112 }, { 212, 144 } @@ -318,7 +314,7 @@ static const u8 sExchangeSelectMultiCursorAnimIDs[NELEMS(sExchangeSelectMultiCur ANIM_ID_MENU_CURSOR }; -static const CoordinatesS16 sReceiveSelectCursorPositions[PARTY_SIZE_SOLO + 2] = { +static const CoordinatesS16 sReceiveSelectCursorPositions[FACTORY_PARTY_SIZE_SOLO + 2] = { { 64, 112 }, { 120, 112 }, { 176, 112 }, @@ -334,7 +330,7 @@ static const u8 sReceiveSelectCursorAnimIDs[NELEMS(sReceiveSelectCursorPositions ANIM_ID_MENU_CURSOR }; -static const CoordinatesS16 sReceiveSelectMultiCursorPositions[PARTY_SIZE_MULTI * 2 + 2] = { +static const CoordinatesS16 sReceiveSelectMultiCursorPositions[FACTORY_PARTY_SIZE_MULTI * 2 + 2] = { { 40, 112 }, { 96, 112 }, { 152, 112 }, @@ -389,7 +385,7 @@ int BattleFactoryApp_Init(ApplicationManager *appMan, int *state) app->saveData = args->saveData; app->challengeType = args->challengeType; - app->unk_0A = args->unk_05; + app->isOpenLevel = args->isOpenLevel; app->isExchangeMode = args->isExchangeMode; app->personalParty = args->personalParty; app->receivableParty = args->receivableParty; diff --git a/src/game_records.c b/src/game_records.c index f7274314a3e..e20ee4e1df8 100644 --- a/src/game_records.c +++ b/src/game_records.c @@ -151,7 +151,7 @@ static u8 sUsesHighLimit[MAX_RECORDS] = { [RECORD_BATTLE_CASTLE_VICTORIES] = TRUE, [RECORD_BATTLE_HALL_VICTORIES] = TRUE, [RECORD_BATTLE_ARCADE_VICTORIES] = TRUE, - [RECORD_UNK_064] = TRUE, + [RECORD_BATTLE_FACTORY_TRADES] = TRUE, [RECORD_CASTLE_POINTS_RECEIVED] = TRUE, [RECORD_UNK_066] = TRUE, [RECORD_UNK_067] = TRUE, diff --git a/src/meson.build b/src/meson.build index d3036511024..b18f5908cbb 100644 --- a/src/meson.build +++ b/src/meson.build @@ -926,7 +926,7 @@ pokeplatinum_c = files( 'overlay104/frscrcmd.c', 'overlay104/ov104_02231F74.c', 'overlay104/frscrcmd_battle_factory.c', - 'overlay104/ov104_022339B4.c', + 'overlay104/battle_factory.c', 'overlay104/frscrcmd_battle_hall.c', 'overlay104/battle_hall.c', 'overlay104/frscrcmd_battle_castle.c', @@ -939,7 +939,7 @@ pokeplatinum_c = files( 'overlay104/ov104_022395F0.c', 'overlay104/ov104_02239C58.c', 'overlay104/ov104_0223A0C4.c', - 'overlay104/ov104_0223A7F4.c', + 'overlay104/battle_factory_helpers.c', 'overlay104/battle_hall_helpers.c', 'overlay104/battle_castle_helpers.c', 'overlay104/battle_arcade_helpers.c', diff --git a/src/overlay104/battle_factory.c b/src/overlay104/battle_factory.c new file mode 100644 index 00000000000..e95c09e160d --- /dev/null +++ b/src/overlay104/battle_factory.c @@ -0,0 +1,556 @@ +#include "overlay104/battle_factory.h" + +#include + +#include "generated/game_records.h" + +#include "struct_defs/battle_frontier.h" + +#include "global/utility.h" +#include "overlay104/battle_factory_helpers.h" +#include "overlay104/frontier_communication.h" +#include "overlay104/frontier_opponents.h" + +#include "battle_factory_save.h" +#include "battle_frontier_save.h" +#include "battle_frontier_stats.h" +#include "game_records.h" +#include "heap.h" +#include "math_util.h" +#include "party.h" +#include "pokemon.h" +#include "savedata.h" +#include "system_vars.h" +#include "vars_flags.h" + +static void SetupTrainersAndInitialRentalOptions(BattleFactory *factory); +static void LoadTrainersAndMonsFromSave(BattleFactory *factory); +static u16 GetBattleFactoryAppSelectedIndices(BattleFactoryAppArgs *args, u8 i); +static void SwapMonIndices(BattleFactory *factory, u8 idx1, u8 isPartners); + +BattleFactory *BattleFactory_Init(SaveData *saveData, u16 resumingFromSave, u8 challengeType, u8 isOpenLevel) +{ + static BattleFactory *factory; + factory = Heap_Alloc(HEAP_ID_FIELD2, sizeof(BattleFactory)); + MI_CpuClear8(factory, sizeof(BattleFactory)); + + factory->factorySave = BattleFactorySave_Get(saveData); + factory->saveData = saveData; + factory->unused = 11; + factory->playersParty = Party_New(HEAP_ID_FIELD2); + factory->opponentsParty = Party_New(HEAP_ID_FIELD2); + + BattleFactorySave *factorySave = factory->factorySave; + BattleFactoryStreakFlags *streakFlags = BattleFactoryStreakFlags_Get(saveData); + + if (!resumingFromSave) { + factory->challengeType = challengeType; + factory->isOpenLevel = isOpenLevel; + factory->currentBattle = 0; + + BattleFactorySave_Init(factorySave); + + u8 streakActive; + if (factory->challengeType == FRONTIER_CHALLENGE_MULTI_WFC) { + streakActive = SystemVars_GetWiFiFrontierCleared(SaveData_GetVarsFlags(factory->saveData)); + } else { + streakActive = BattleFactoryStreakFlags_GetFlag(streakFlags, FACTORY_SAVE_STREAK_FLAGS, (factory->isOpenLevel * 4) + factory->challengeType, NULL); + } + + if (streakActive == TRUE) { + factory->currentStreak = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(factory->saveData), BattleFrontierStats_GetFactoryLatestStreakIdx(factory->isOpenLevel, factory->challengeType)); + factory->tradeCount = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(factory->saveData), BattleFrontierStats_GetFactoryLatestTradeCountIndex(factory->isOpenLevel, factory->challengeType)); + } else { + factory->currentStreak = 0; + factory->tradeCount = 0; + } + + factory->unused3 = 0; + } else { + factory->challengeType = BattleFactorySave_GetMember(factorySave, FACTORY_SAVE_CHALLENGE_TYPE, 0, NULL); + factory->isOpenLevel = BattleFactorySave_GetMember(factorySave, FACTORY_SAVE_OPEN_LEVEL, 0, NULL); + factory->currentBattle = BattleFactorySave_GetMember(factorySave, FACTORY_SAVE_CURRENT_BATTLE, 0, NULL); + factory->currentStreak = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(factory->saveData), BattleFrontierStats_GetFactoryLatestStreakIdx(factory->isOpenLevel, factory->challengeType)); + factory->tradeCount = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(factory->saveData), BattleFrontierStats_GetFactoryLatestTradeCountIndex(factory->isOpenLevel, factory->challengeType)); + } + + factory->currentRound = factory->currentStreak / FACTORY_BATTLES_PER_ROUND; + + if (BattleFactory_IsMultiplayerChallenge(factory->challengeType) == TRUE) { + BattleFrontier_FlagGeonetLinkInfo(factory->saveData); + } + + return factory; +} + +void BattleFactory_LoadTrainersAndRentalsForRound(BattleFactory *factory, u16 resumingFromSave) +{ + if (!resumingFromSave) { + SetupTrainersAndInitialRentalOptions(factory); + } else { + LoadTrainersAndMonsFromSave(factory); + } +} + +static void SetupTrainersAndInitialRentalOptions(BattleFactory *factory) +{ + int i; + FrontierPokemon usedMons[FACTORY_INITIAL_RENTAL_OPTIONS * 2]; + + BattleFactory_PickOpponentTrainers(factory->challengeType, BattleFactory_GetCurrentRound(factory), factory->trainerIDs, FACTORY_BATTLES_PER_ROUND * 2); + + BattleFactory_SelectInitialRentalOptions(BattleFactory_GetCurrentRound(factory), factory->isOpenLevel, factory->initialRentalSetIDs, factory->initialRentalMons, factory->initialRentalIVs, factory->initialRentalPersonalities, factory->tradeCount, NULL, NULL); + + SwapMonIndices(factory, 4, FALSE); + SwapMonIndices(factory, 5, FALSE); + + int numPokemonUsed = FACTORY_INITIAL_RENTAL_OPTIONS; + + for (i = 0; i < FACTORY_INITIAL_RENTAL_OPTIONS; i++) { + usedMons[i] = factory->initialRentalMons[i]; + } + + if (BattleFactory_IsMultiplayerChallenge(factory->challengeType) == TRUE) { + u16 partnersSpecies[FACTORY_INITIAL_RENTAL_OPTIONS]; + u16 partnersItems[FACTORY_INITIAL_RENTAL_OPTIONS]; + for (i = 0; i < FACTORY_INITIAL_RENTAL_OPTIONS; i++) { + partnersSpecies[i] = factory->initialRentalMons[i].species; + partnersItems[i] = factory->initialRentalMons[i].item; + } + + BattleFactory_SelectInitialRentalOptions(BattleFactory_GetCurrentRound(factory), factory->isOpenLevel, factory->partnerRentalSetIDs, factory->partnerRentalMons, factory->partnerRentalIVs, factory->partnerRentalPersonalities, factory->unk_580, partnersSpecies, partnersItems); + + SwapMonIndices(factory, 4, TRUE); + SwapMonIndices(factory, 5, TRUE); + + numPokemonUsed = FACTORY_INITIAL_RENTAL_OPTIONS * 2; + + for (i = 0; i < FACTORY_INITIAL_RENTAL_OPTIONS; i++) { + usedMons[i + FACTORY_INITIAL_RENTAL_OPTIONS] = factory->partnerRentalMons[i]; + } + } + + BattleFactory_SelectInitialOpponentMons(BattleFactory_GetOpponentPartySize(factory->challengeType, TRUE), factory->trainerIDs[factory->currentBattle], factory->isOpenLevel, usedMons, factory->opponentMonSetIDs, factory->opponentMons, factory->opponentMonIVs, factory->opponentMonPersonalities, numPokemonUsed); + + for (i = 0; i < FACTORY_INITIAL_RENTAL_OPTIONS; i++) { + Pokemon *mon = Pokemon_New(HEAP_ID_FIELD2); + FrontierPokemon_InitPokemon(&factory->initialRentalMons[i], mon, BattleFactory_GetPokemonLevel(factory)); + BattleFactory_AddRentalPokemonToParty(factory->saveData, factory->playersParty, mon); + Heap_Free(mon); + } + + for (i = 0; i < FACTORY_INITIAL_RENTAL_OPTIONS; i++) { + Party_GetPokemonBySlotIndex(factory->playersParty, i); + } +} + +static void SwapMonIndices(BattleFactory *factory, u8 idx1, u8 isPartners) +{ + u16 setID; + u8 ivs; + u32 personality; + + u16 idx2 = LCRNG_Next() % FACTORY_INITIAL_RENTAL_OPTIONS; + + if (!isPartners) { + setID = factory->initialRentalSetIDs[idx1]; + ivs = factory->initialRentalIVs[idx1]; + personality = factory->initialRentalPersonalities[idx1]; + FrontierPokemon mon = factory->initialRentalMons[idx1]; + + factory->initialRentalSetIDs[idx1] = factory->initialRentalSetIDs[idx2]; + factory->initialRentalIVs[idx1] = factory->initialRentalIVs[idx2]; + factory->initialRentalPersonalities[idx1] = factory->initialRentalPersonalities[idx2]; + factory->initialRentalMons[idx1] = factory->initialRentalMons[idx2]; + + factory->initialRentalSetIDs[idx2] = setID; + factory->initialRentalIVs[idx2] = ivs; + factory->initialRentalPersonalities[idx2] = personality; + factory->initialRentalMons[idx2] = mon; + } else { + setID = factory->partnerRentalSetIDs[idx1]; + ivs = factory->partnerRentalIVs[idx1]; + personality = factory->partnerRentalPersonalities[idx1]; + FrontierPokemon mon = factory->partnerRentalMons[idx1]; + + factory->partnerRentalSetIDs[idx1] = factory->partnerRentalSetIDs[idx2]; + factory->partnerRentalIVs[idx1] = factory->partnerRentalIVs[idx2]; + factory->partnerRentalPersonalities[idx1] = factory->partnerRentalPersonalities[idx2]; + factory->partnerRentalMons[idx1] = factory->partnerRentalMons[idx2]; + + factory->partnerRentalSetIDs[idx2] = setID; + factory->partnerRentalIVs[idx2] = ivs; + factory->partnerRentalPersonalities[idx2] = personality; + factory->partnerRentalMons[idx2] = mon; + } +} + +static void LoadTrainersAndMonsFromSave(BattleFactory *factory) +{ + FrontierPokemon mons[MAX_PARTY_SIZE]; + u8 ivs[MAX_PARTY_SIZE]; + u16 monSetIDs[MAX_PARTY_SIZE]; + u32 personalities[MAX_PARTY_SIZE]; + + UNUSED(BattleFactory_GetPlayerPartySize(factory->challengeType)); + + for (int i = 0; i < FACTORY_BATTLES_PER_ROUND * 2; i++) { + factory->trainerIDs[i] = BattleFactorySave_GetMember(factory->factorySave, FACTORY_SAVE_TRAINER_IDS, i, NULL); + } + + for (int i = 0; i < FACTORY_MAX_PARTY_SIZE; i++) { + monSetIDs[i] = BattleFactorySave_GetMember(factory->factorySave, FACTORY_SAVE_PLAYER_SETS, i, NULL); + personalities[i] = BattleFactorySave_GetMember(factory->factorySave, FACTORY_SAVE_PLAYER_PERSONALITY, i, NULL); + ivs[i] = BattleFactorySave_GetMember(factory->factorySave, FACTORY_SAVE_PLAYER_IVS, i, NULL); + + factory->playerMonSetIDs[i] = monSetIDs[i]; + } + + BattleFrontier_LoadFrontierPokemon(mons, monSetIDs, ivs, personalities, NULL, FACTORY_MAX_PARTY_SIZE, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); + + Pokemon *mon = Pokemon_New(HEAP_ID_FIELD2); + + for (int i = 0; i < FACTORY_MAX_PARTY_SIZE; i++) { + FrontierPokemon_InitPokemon(&mons[i], mon, BattleFactory_GetPokemonLevel(factory)); + BattleFactory_AddRentalPokemonToParty(factory->saveData, factory->playersParty, mon); + } + + Heap_Free(mon); + + for (int i = 0; i < FACTORY_MAX_PARTY_SIZE; i++) { + monSetIDs[i] = BattleFactorySave_GetMember(factory->factorySave, FACTORY_SAVE_OPPONENT_SETS, i, NULL); + personalities[i] = BattleFactorySave_GetMember(factory->factorySave, FACTORY_SAVE_OPPONENT_PERSONALITY, i, NULL); + ivs[i] = BattleFactorySave_GetMember(factory->factorySave, FACTORY_SAVE_OPPONENT_IVS, i, NULL); + + factory->opponentMonSetIDs[i] = monSetIDs[i]; + } + + BattleFrontier_LoadFrontierPokemon(mons, monSetIDs, ivs, personalities, NULL, FACTORY_MAX_PARTY_SIZE, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); + + mon = Pokemon_New(HEAP_ID_FIELD2); + + for (int i = 0; i < FACTORY_MAX_PARTY_SIZE; i++) { + FrontierPokemon_InitPokemon(&mons[i], mon, BattleFactory_GetPokemonLevel(factory)); + BattleFactory_AddRentalPokemonToParty(factory->saveData, factory->opponentsParty, mon); + } + + Heap_Free(mon); +} + +void BattleFactory_Free(BattleFactory *factory) +{ + if (factory == NULL) { + return; + } + + if (factory->playersParty != NULL) { + Heap_Free(factory->playersParty); + } + + if (factory->opponentsParty != NULL) { + Heap_Free(factory->opponentsParty); + } + + MI_CpuClear8(factory, sizeof(BattleFactory)); + + Heap_Free(factory); + factory = NULL; +} + +void BattleFactory_GetMonSelectionAppResult(BattleFactory *battleFactory, BattleFactoryAppArgs *args) +{ + for (int i = 0; i < 6; i++) { + battleFactory->selectedAppSlots[i] = GetBattleFactoryAppSelectedIndices(args, i); + } +} + +static u16 GetBattleFactoryAppSelectedIndices(BattleFactoryAppArgs *args, u8 i) +{ + if (i >= 6) { + GF_ASSERT(FALSE); + return 0; + } + + return args->selectedIndices[i]; +} + +void BattleFactory_Save(BattleFactory *factory, u8 saveType) +{ + u8 u8Ptr[4]; + u16 u16Ptr[4]; + u32 u32Ptr[4]; + BattleFactorySave *factorySave = factory->factorySave; + BattleFactoryStreakFlags *streakFlags = BattleFactoryStreakFlags_Get(factory->saveData); + + BattleFrontierSave *frontier = SaveData_GetBattleFrontier(factory->saveData); + UNUSED(BattleFactory_GetPlayerPartySize(factory->challengeType)); + UNUSED(BattleFactory_GetOpponentPartySize(factory->challengeType, TRUE)); + + u8Ptr[0] = factory->isOpenLevel; + BattleFactorySave_SetMember(factory->factorySave, FACTORY_SAVE_OPEN_LEVEL, 0, u8Ptr); + + u8Ptr[0] = factory->challengeType; + BattleFactorySave_SetMember(factory->factorySave, FACTORY_SAVE_CHALLENGE_TYPE, 0, u8Ptr); + BattleFactorySave_RecordSave(factory->factorySave, TRUE); + + u8Ptr[0] = factory->currentBattle; + BattleFactorySave_SetMember(factory->factorySave, FACTORY_SAVE_CURRENT_BATTLE, 0, u8Ptr); + BattleFrontierSave_SetStatAutoHostIdx(frontier, BattleFrontierStats_GetFactoryLatestTradeCountIndex(factory->isOpenLevel, factory->challengeType), factory->tradeCount); + BattleFrontierSave_SetStatAutoHostIdx(frontier, BattleFrontierStats_GetFactoryLatestStreakIdx(factory->isOpenLevel, factory->challengeType), factory->currentStreak); + + if (saveType != 2) { + u16 recordStreak = BattleFrontierSave_GetStatAutoHostIdx(frontier, BattleFrontierStats_GetFactoryRecordStreakIdx(factory->isOpenLevel, factory->challengeType)); + u32 newRecord = BattleFrontierSave_SetIfBetterAutoHostIdx(frontier, BattleFrontierStats_GetFactoryRecordStreakIdx(factory->isOpenLevel, factory->challengeType), factory->currentStreak); + u16 latestStreak = BattleFrontierSave_GetStatAutoHostIdx(frontier, BattleFrontierStats_GetFactoryRecordStreakIdx(factory->isOpenLevel, factory->challengeType)); + + if (factory->currentStreak == recordStreak) { + BattleFrontierSave_SetIfBetterAutoHostIdx(frontier, BattleFrontierStats_GetFactoryRecordTradeCountIndex(factory->isOpenLevel, factory->challengeType), factory->tradeCount); + } else if (recordStreak < latestStreak) { + BattleFrontierSave_SetStatAutoHostIdx(frontier, BattleFrontierStats_GetFactoryRecordTradeCountIndex(factory->isOpenLevel, factory->challengeType), factory->tradeCount); + } + + u8Ptr[0] = factory->saveStreak; + BattleFactoryStreakFlags_SetFlag(streakFlags, FACTORY_SAVE_STREAK_FLAGS, (factory->isOpenLevel * 4) + factory->challengeType, u8Ptr); + + if (factory->challengeType == FRONTIER_CHALLENGE_MULTI_WFC) { + u32 statIndex = !factory->isOpenLevel ? STAT_FACTORY_50_WFC_STREAK_ACTIVE : STAT_FACTORY_OPEN_WFC_STREAK_ACTIVE; + BattleFrontierSave_SetStatAutoHostIdx(frontier, statIndex, factory->saveStreak); + } + } + + for (u16 i = 0; i < FACTORY_BATTLES_PER_ROUND * 2; i++) { + u16Ptr[0] = factory->trainerIDs[i]; + BattleFactorySave_SetMember(factory->factorySave, FACTORY_SAVE_TRAINER_IDS, i, u16Ptr); + } + + u32 partySize = Party_GetCurrentCount(factory->playersParty); + + for (u16 i = 0; i < partySize; i++) { + Pokemon *mon = Party_GetPokemonBySlotIndex(factory->playersParty, i); + + u16Ptr[0] = factory->playerMonSetIDs[i]; + BattleFactorySave_SetMember(factory->factorySave, FACTORY_SAVE_PLAYER_SETS, i, u16Ptr); + + u8Ptr[0] = Pokemon_GetValue(mon, MON_DATA_ATK_IV, NULL); + BattleFactorySave_SetMember(factory->factorySave, FACTORY_SAVE_PLAYER_IVS, i, u8Ptr); + + u32Ptr[0] = Pokemon_GetValue(mon, MON_DATA_PERSONALITY, NULL); + BattleFactorySave_SetMember(factory->factorySave, FACTORY_SAVE_PLAYER_PERSONALITY, i, u32Ptr); + } + + partySize = Party_GetCurrentCount(factory->opponentsParty); + + for (u16 i = 0; i < partySize; i++) { + Pokemon *mon = Party_GetPokemonBySlotIndex(factory->opponentsParty, i); + + u16Ptr[0] = factory->opponentMonSetIDs[i]; + BattleFactorySave_SetMember(factory->factorySave, FACTORY_SAVE_OPPONENT_SETS, i, u16Ptr); + + u8Ptr[0] = Pokemon_GetValue(mon, MON_DATA_ATK_IV, NULL); + BattleFactorySave_SetMember(factory->factorySave, FACTORY_SAVE_OPPONENT_IVS, i, u8Ptr); + + u32Ptr[0] = Pokemon_GetValue(mon, MON_DATA_PERSONALITY, NULL); + BattleFactorySave_SetMember(factory->factorySave, FACTORY_SAVE_OPPONENT_PERSONALITY, i, u32Ptr); + } +} + +u16 BattleFactory_IncrementCurrentBattle(BattleFactory *factory) +{ + factory->currentBattle++; + return factory->currentBattle; +} + +u16 BattleFactory_GetCurrentBattle(BattleFactory *factory) +{ + return factory->currentBattle; +} + +u16 BattleFactory_GetNextOpponentObjectID(BattleFactory *factory, u8 trainerSlot) +{ + FrontierTrainer trainer; + u8 offset = factory->currentBattle + (trainerSlot * FACTORY_BATTLES_PER_ROUND); + + Heap_Free(BattleFrontier_GetTrainer(&trainer, factory->trainerIDs[offset], HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR)); + + return BattleFrontier_GetObjectIDFromTrainerClass(trainer.trainerType); +} + +void BattleFactory_SaveOnLoss(BattleFactory *factory) +{ + BattleFactory_Save(factory, 1); +} + +void BattleFactory_SaveOnCompletingRound(BattleFactory *factory) +{ + factory->saveStreak = TRUE; + + if (factory->currentRound < FACTORY_MAX_DISTINCT_ROUNDS) { + factory->currentRound++; + } + + factory->currentBattle = 0; + BattleFactory_Save(factory, 0); +} + +void BattleFactory_AddSelectedRentalsToParty(BattleFactory *factory) +{ + u8 playerPartySize = BattleFactory_GetPlayerPartySize(factory->challengeType); + u8 opponentPartySize = BattleFactory_GetOpponentPartySize(factory->challengeType, TRUE); + + Party_Init(factory->playersParty); + + Pokemon *mon = Pokemon_New(HEAP_ID_FIELD2); + + for (int i = 0; i < playerPartySize; i++) { + FrontierPokemon_InitPokemon(&factory->initialRentalMons[factory->selectedAppSlots[i]], mon, BattleFactory_GetPokemonLevel(factory)); + BattleFactory_AddRentalPokemonToParty(factory->saveData, factory->playersParty, mon); + factory->playerMonSetIDs[i] = factory->initialRentalSetIDs[factory->selectedAppSlots[i]]; + } + + for (int i = 0; i < opponentPartySize; i++) { + FrontierPokemon_InitPokemon(&factory->opponentMons[i], mon, BattleFactory_GetPokemonLevel(factory)); + BattleFactory_AddRentalPokemonToParty(factory->saveData, factory->opponentsParty, mon); + } + + Heap_Free(mon); +} + +void BattleFactory_SetupNextOpponent(BattleFactory *factory) +{ + int i, partySize, playersPartySize; + u16 usedSpecies[FACTORY_MAX_PARTY_SIZE * 2]; + u16 usedItems[FACTORY_MAX_PARTY_SIZE * 2]; + + for (i = 0; i < FACTORY_MAX_PARTY_SIZE * 2; i++) { + usedSpecies[i] = 0; + usedItems[i] = 0; + } + + u8 opponentPartySize = BattleFactory_GetOpponentPartySize(factory->challengeType, TRUE); + partySize = Party_GetCurrentCount(factory->playersParty); + + for (i = 0; i < partySize; i++) { + Pokemon *mon = Party_GetPokemonBySlotIndex(factory->playersParty, i); + usedSpecies[i] = Pokemon_GetValue(mon, MON_DATA_SPECIES, NULL); + usedItems[i] = Pokemon_GetValue(mon, MON_DATA_HELD_ITEM, NULL); + } + + playersPartySize = partySize; + partySize = Party_GetCurrentCount(factory->opponentsParty); + + for (i = 0; i < partySize; i++) { + Pokemon *mon = Party_GetPokemonBySlotIndex(factory->opponentsParty, i); + usedSpecies[i + playersPartySize] = Pokemon_GetValue(mon, MON_DATA_SPECIES, NULL); + usedItems[i + playersPartySize] = Pokemon_GetValue(mon, MON_DATA_HELD_ITEM, NULL); + + factory->initialRentalSetIDs[i] = factory->opponentMonSetIDs[i]; + } + + const BattleFactoryPokemonPool *pool = BattleFactory_GetPokemonPoolForTrainer(factory->trainerIDs[factory->currentBattle], factory->isOpenLevel); + + BattleFactory_SelectPokemonFromPool(usedSpecies, usedItems, playersPartySize + partySize, opponentPartySize, factory->opponentMonSetIDs, HEAP_ID_FIELD2, pool, 0, factory->opponentMonIVs); + BattleFrontier_LoadFrontierPokemon(factory->opponentMons, factory->opponentMonSetIDs, factory->opponentMonIVs, NULL, factory->opponentMonPersonalities, opponentPartySize, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); +} + +void BattleFactory_ApplyTrade(BattleFactory *factory) +{ + if (factory->selectedAppSlots[0] != 0xff) { + Pokemon *mon = Party_GetPokemonBySlotIndex(factory->opponentsParty, factory->selectedAppSlots[1]); + Party_AddPokemonBySlotIndex(factory->playersParty, factory->selectedAppSlots[0], mon); + + factory->playerMonSetIDs[factory->selectedAppSlots[0]] = factory->initialRentalSetIDs[factory->selectedAppSlots[1]]; + + BattleFactory_IncrementTradeCount(factory); + GameRecords_IncrementRecordValue(SaveData_GetGameRecords(factory->saveData), RECORD_BATTLE_FACTORY_TRADES); + } +} + +void BattleFactory_SetupNextOpponentsParty(BattleFactory *factory) +{ + UNUSED(BattleFactory_GetPlayerPartySize(factory->challengeType)); + u8 partySize = BattleFactory_GetOpponentPartySize(factory->challengeType, TRUE); + + Party_Init(factory->opponentsParty); + + Pokemon *mon = Pokemon_New(HEAP_ID_FIELD2); + + for (int i = 0; i < partySize; i++) { + FrontierPokemon_InitPokemon(&factory->opponentMons[i], mon, BattleFactory_GetPokemonLevel(factory)); + BattleFactory_AddRentalPokemonToParty(factory->saveData, factory->opponentsParty, mon); + } + + Heap_Free(mon); + + for (int i = 0; i < partySize; i++) { + UNUSED(Party_GetPokemonBySlotIndex(factory->opponentsParty, i)); + } +} + +void BattleFactory_IncrementTradeCount(BattleFactory *factory) +{ + if (factory->tradeCount < 9999) { + factory->tradeCount++; + } +} + +BOOL BattleFactory_SendCommMessage(BattleFactory *factory, u16 command, u16 arg) +{ + int success; + + switch (command) { + case 0: + success = ov104_0222EEF8(factory); + break; + case 1: + success = FactoryCommunication_SendTrainers(factory); + break; + case 2: + success = ov104_0222EFCC(factory); + break; + case 3: + success = ov104_0222F0B4(factory); + break; + case 4: + success = ov104_0222F1A0(factory, arg); + break; + case 5: + success = ov104_0222F1EC(factory, arg); + break; + case 6: + success = ov104_0222F238(factory); + break; + } + + return success; +} + +u16 BattleFactory_GetEarnedBP(BattleFactory *factory) +{ + u8 bp; + static const u8 sBPPerRoundSolo[FACTORY_MAX_DISTINCT_ROUNDS + 1] = { 0, 5, 5, 5, 5, 7, 7, 8, 9 }; + static const u8 sBPPerRoundWifi[FACTORY_MAX_DISTINCT_ROUNDS + 1] = { 0, 10, 11, 12, 13, 16, 17, 19, 21 }; + + u16 currentRound = factory->currentRound; + + if (factory->challengeType == FRONTIER_CHALLENGE_SINGLE || factory->challengeType == FRONTIER_CHALLENGE_DOUBLE) { + if (currentRound >= FACTORY_MAX_DISTINCT_ROUNDS) { + bp = sBPPerRoundSolo[FACTORY_MAX_DISTINCT_ROUNDS]; + } else { + bp = sBPPerRoundSolo[currentRound]; + } + } else { + if (currentRound >= FACTORY_MAX_DISTINCT_ROUNDS) { + bp = sBPPerRoundWifi[FACTORY_MAX_DISTINCT_ROUNDS]; + } else { + bp = sBPPerRoundWifi[currentRound]; + } + } + + if (factory->challengeType == FRONTIER_CHALLENGE_SINGLE) { + if (factory->currentStreak == FACTORY_STREAK_SILVER_BATTLE || factory->currentStreak == FACTORY_STREAK_GOLD_BATTLE) { + bp = 20; + } + } + + return bp; +} diff --git a/src/overlay104/battle_factory_helpers.c b/src/overlay104/battle_factory_helpers.c new file mode 100644 index 00000000000..c33c00774ff --- /dev/null +++ b/src/overlay104/battle_factory_helpers.c @@ -0,0 +1,479 @@ +#include "overlay104/battle_factory_helpers.h" + +#include + +#include "constants/battle_frontier.h" +#include "generated/ai_flags.h" +#include "generated/frontier_trainers.h" + +#include "struct_defs/frontier_pokemon_base.h" + +#include "overlay104/frontier_opponents.h" +#include "overlay104/struct_ov104_02230BE4.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 "trainer_info.h" + +static const struct { + u16 normalMin; + u16 normalMax; + u16 finalMin; + u16 finalMax; +} sBattleFactoryOpponentPools[] = { + { 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 const BattleFactoryPokemonPool sLevel50Pools[] = { + { .trainerIDMax = 100, .setIDMin = 1, .setIDMax = 150, .ivs = 0, .canBeUpgraded = TRUE }, + { .trainerIDMax = 120, .setIDMin = 151, .setIDMax = 250, .ivs = 4, .canBeUpgraded = TRUE }, + { .trainerIDMax = 140, .setIDMin = 251, .setIDMax = 350, .ivs = 8, .canBeUpgraded = TRUE }, + { .trainerIDMax = 160, .setIDMin = 351, .setIDMax = 486, .ivs = 12, .canBeUpgraded = TRUE }, + { .trainerIDMax = 180, .setIDMin = 487, .setIDMax = 622, .ivs = 16, .canBeUpgraded = TRUE }, + { .trainerIDMax = 200, .setIDMin = 623, .setIDMax = 758, .ivs = 20, .canBeUpgraded = TRUE }, + { .trainerIDMax = 220, .setIDMin = 759, .setIDMax = 894, .ivs = 24, .canBeUpgraded = TRUE }, + { .trainerIDMax = 300, .setIDMin = 351, .setIDMax = 950, .ivs = 31, .canBeUpgraded = FALSE }, + { .trainerIDMax = 310, .setIDMin = 351, .setIDMax = 486, .ivs = 12, .canBeUpgraded = FALSE }, + { .trainerIDMax = 311, .setIDMin = 351, .setIDMax = 486, .ivs = 31, .canBeUpgraded = FALSE } +}; + +static const BattleFactoryPokemonPool sOpenLevelOpponentPools[] = { + { .trainerIDMax = 100, .setIDMin = 351, .setIDMax = 486, .ivs = 0, .canBeUpgraded = TRUE }, + { .trainerIDMax = 120, .setIDMin = 487, .setIDMax = 622, .ivs = 4, .canBeUpgraded = TRUE }, + { .trainerIDMax = 140, .setIDMin = 623, .setIDMax = 758, .ivs = 8, .canBeUpgraded = TRUE }, + { .trainerIDMax = 160, .setIDMin = 759, .setIDMax = 894, .ivs = 12, .canBeUpgraded = TRUE }, + { .trainerIDMax = 180, .setIDMin = 351, .setIDMax = 950, .ivs = 16, .canBeUpgraded = TRUE }, + { .trainerIDMax = 200, .setIDMin = 351, .setIDMax = 950, .ivs = 20, .canBeUpgraded = TRUE }, + { .trainerIDMax = 220, .setIDMin = 351, .setIDMax = 950, .ivs = 24, .canBeUpgraded = TRUE }, + { .trainerIDMax = 300, .setIDMin = 351, .setIDMax = 950, .ivs = 31, .canBeUpgraded = FALSE }, + { .trainerIDMax = 310, .setIDMin = 759, .setIDMax = 950, .ivs = 12, .canBeUpgraded = FALSE }, + { .trainerIDMax = 311, .setIDMin = 759, .setIDMax = 950, .ivs = 31, .canBeUpgraded = FALSE } +}; + +static const BattleFactoryPokemonPool sOpenLevelPlayerPools[] = { + { .trainerIDMax = 100, .setIDMin = 351, .setIDMax = 486, .ivs = 0, .canBeUpgraded = TRUE }, + { .trainerIDMax = 120, .setIDMin = 487, .setIDMax = 622, .ivs = 4, .canBeUpgraded = TRUE }, + { .trainerIDMax = 140, .setIDMin = 623, .setIDMax = 758, .ivs = 8, .canBeUpgraded = TRUE }, + { .trainerIDMax = 160, .setIDMin = 759, .setIDMax = 894, .ivs = 12, .canBeUpgraded = TRUE }, + { .trainerIDMax = 180, .setIDMin = 623, .setIDMax = 950, .ivs = 16, .canBeUpgraded = TRUE }, + { .trainerIDMax = 200, .setIDMin = 623, .setIDMax = 950, .ivs = 20, .canBeUpgraded = TRUE }, + { .trainerIDMax = 220, .setIDMin = 623, .setIDMax = 950, .ivs = 24, .canBeUpgraded = TRUE }, + { .trainerIDMax = 300, .setIDMin = 351, .setIDMax = 950, .ivs = 31, .canBeUpgraded = FALSE }, + { .trainerIDMax = 310, .setIDMin = 759, .setIDMax = 950, .ivs = 12, .canBeUpgraded = FALSE }, + { .trainerIDMax = 311, .setIDMin = 759, .setIDMax = 950, .ivs = 31, .canBeUpgraded = FALSE } +}; + +static int BattleFactory_GetOpponentTrainerID(u8 challengeType, int currentRound, int trainerOffset); +static const BattleFactoryPokemonPool *GetPlayerPoolForRound(int round, int isOpenLevel); +static u32 BattleFactory_GetBattleType(u8 challengeType); +static u16 BattleFactory_GetAIMask(BattleFactory *battleFactory); + +static int BattleFactory_GetOpponentTrainerID(u8 challengeType, int currentRound, int trainerOffset) +{ + if (currentRound >= NELEMS(sBattleFactoryOpponentPools)) { + currentRound = NELEMS(sBattleFactoryOpponentPools) - 1; + } + + if (challengeType == FRONTIER_CHALLENGE_SINGLE) { + int currentStreak = (currentRound * FACTORY_BATTLES_PER_ROUND) + (trainerOffset + 1); + + if (currentStreak == FACTORY_STREAK_SILVER_BATTLE) { + return FRONTIER_TRAINER_FACTORY_HEAD_THORTON_SILVER; + } else if (currentStreak == FACTORY_STREAK_GOLD_BATTLE) { + return FRONTIER_TRAINER_FACTORY_HEAD_THORTON_GOLD; + } + } + + int spread, min; + if (trainerOffset == FACTORY_BATTLES_PER_ROUND - 1 || trainerOffset == (FACTORY_BATTLES_PER_ROUND * 2) - 1) { + spread = sBattleFactoryOpponentPools[currentRound].finalMax - sBattleFactoryOpponentPools[currentRound].finalMin; + min = sBattleFactoryOpponentPools[currentRound].finalMin; + } else { + spread = sBattleFactoryOpponentPools[currentRound].normalMax - sBattleFactoryOpponentPools[currentRound].normalMin; + min = sBattleFactoryOpponentPools[currentRound].normalMin; + } + + return min + LCRNG_Next() % spread; +} + +void BattleFactory_PickOpponentTrainers(u8 challengeType, int currentRound, u16 trainerIDs[], u8 numTrainers) +{ + int i = 0; + do { + trainerIDs[i] = BattleFactory_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); +} + +const BattleFactoryPokemonPool *BattleFactory_GetPokemonPoolForTrainer(int trainerID, BOOL isOpenLevel) +{ + static const BattleFactoryPokemonPool *pools; + int numPools; + if (!isOpenLevel) { + pools = sLevel50Pools; + numPools = NELEMS(sLevel50Pools); + } else { + pools = sOpenLevelOpponentPools; + numPools = NELEMS(sOpenLevelOpponentPools); + } + + int i; + for (i = 0; i < numPools; i++) { + if (trainerID < pools[i].trainerIDMax) { + break; + } + } + + if (i >= numPools) { + GF_ASSERT(FALSE); + i = numPools - 1; + } + + return &pools[i]; +} + +static const BattleFactoryPokemonPool *GetPlayerPoolForRound(int round, int isOpenLevel) +{ + if (round >= FACTORY_MAX_DISTINCT_ROUNDS) { + round = FACTORY_MAX_DISTINCT_ROUNDS - 1; + } + + if (!isOpenLevel) { + return &sLevel50Pools[round]; + } else { + return &sOpenLevelPlayerPools[round]; + } +} + +static const int sTradeCountsNeededForUpgrades[] = { 6, 13, 20, 27, 34 }; + +BOOL BattleFactory_SelectPokemonFromPool(const u16 excludedSpecies[], const u16 excludedItems[], int numExcluded, int numMons, u16 monSetIDs[], int unused, const BattleFactoryPokemonPool *pool, u16 tradeCount, u8 ivList[]) +{ + u8 ivs; + int slot, setIDRange, setID, i; + FrontierPokemonBase newMon[FACTORY_INITIAL_RENTAL_OPTIONS]; + + GF_ASSERT(numMons <= FACTORY_INITIAL_RENTAL_OPTIONS); + + setIDRange = pool->setIDMax - pool->setIDMin; + slot = 0; + + int numUpgradable = 0; + if (tradeCount != 0) { + numUpgradable = NELEMS(sTradeCountsNeededForUpgrades); + + for (i = 0; i < NELEMS(sTradeCountsNeededForUpgrades); i++) { + if (tradeCount <= sTradeCountsNeededForUpgrades[i]) { + numUpgradable = i; + break; + } + } + } + + while (slot != numMons) { + if (slot >= numMons - numUpgradable && pool->canBeUpgraded == TRUE) { + setIDRange = (pool + 1)->setIDMax - (pool + 1)->setIDMin; + setID = (pool + 1)->setIDMax - (LCRNG_Next() % (setIDRange + 1)); + ivs = (pool + 1)->ivs; + } else { + setID = pool->setIDMax - (LCRNG_Next() % (setIDRange + 1)); + ivs = pool->ivs; + } + + BattleFrontier_GetPokemonBase(&newMon[slot], setID, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); + + for (i = 0; i < slot; i++) { + if (newMon[i].species == newMon[slot].species || newMon[i].item == newMon[slot].item) { + break; + } + } + + if (i != slot) { + continue; + } + + for (i = 0; i < numExcluded; i++) { + if (newMon[slot].species == excludedSpecies[i] || newMon[slot].item == excludedItems[i]) { + break; + } + } + + if (i != numExcluded) { + continue; + } + + monSetIDs[slot] = setID; + ivList[slot] = ivs; + + slot++; + } + + return FALSE; +} + +u8 BattleFactory_GetPlayerPartySize(u8 challengeType) +{ + switch (challengeType) { + case FRONTIER_CHALLENGE_SINGLE: + case FRONTIER_CHALLENGE_DOUBLE: + return FACTORY_PARTY_SIZE_SOLO; + case FRONTIER_CHALLENGE_MULTI: + case FRONTIER_CHALLENGE_MULTI_WFC: + return FACTORY_PARTY_SIZE_MULTI; + } + + return 0; +} + +u8 BattleFactory_GetOpponentPartySize(u8 challengeType, BOOL includePartnersMons) +{ + switch (challengeType) { + case FRONTIER_CHALLENGE_SINGLE: + case FRONTIER_CHALLENGE_DOUBLE: + return FACTORY_PARTY_SIZE_SOLO; + case FRONTIER_CHALLENGE_MULTI: + case FRONTIER_CHALLENGE_MULTI_WFC: + if (includePartnersMons == 0) { + return FACTORY_PARTY_SIZE_MULTI; + } else { + return FACTORY_PARTY_SIZE_MULTI * 2; + } + } + + return 0; +} + +void BattleFactory_SelectInitialRentalOptions(u16 round, u8 isOpenLevel, u16 *monSetIDs, FrontierPokemon *mons, u8 *ivs, u32 *personalities, u16 tradeCount, u16 *excludedSpecies, u16 *unused) +{ + const BattleFactoryPokemonPool *pool = GetPlayerPoolForRound(round, isOpenLevel); + + if (excludedSpecies == NULL) { + BattleFactory_SelectPokemonFromPool(NULL, NULL, 0, FACTORY_INITIAL_RENTAL_OPTIONS, monSetIDs, HEAP_ID_FIELD2, pool, tradeCount, ivs); + } else { + BattleFactory_SelectPokemonFromPool(excludedSpecies, excludedSpecies, FACTORY_INITIAL_RENTAL_OPTIONS, FACTORY_INITIAL_RENTAL_OPTIONS, monSetIDs, HEAP_ID_FIELD2, pool, tradeCount, ivs); + } + + BattleFrontier_LoadFrontierPokemon(mons, monSetIDs, ivs, NULL, personalities, FACTORY_INITIAL_RENTAL_OPTIONS, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); +} + +void BattleFactory_SelectInitialOpponentMons(u8 numMons, u16 trainerID, u8 isOpenLevel, FrontierPokemon *excludedMons, u16 *monSetIDs, FrontierPokemon *mons, u8 *ivList, u32 *personalities, int numExcluded) +{ + int i; + FrontierPokemon mon; + u16 excludedSpecies[FACTORY_INITIAL_RENTAL_OPTIONS * 2]; + u16 excludedItems[FACTORY_INITIAL_RENTAL_OPTIONS * 2]; + + const BattleFactoryPokemonPool *pool = BattleFactory_GetPokemonPoolForTrainer(trainerID, isOpenLevel); + + for (i = 0; i < numExcluded; i++) { + mon = excludedMons[i]; + excludedSpecies[i] = mon.species; + excludedItems[i] = mon.item; + } + + BattleFactory_SelectPokemonFromPool(excludedSpecies, excludedItems, numExcluded, numMons, monSetIDs, HEAP_ID_FIELD2, pool, 0, ivList); + BattleFrontier_LoadFrontierPokemon(mons, monSetIDs, ivList, NULL, personalities, numMons, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); +} + +FieldBattleDTO *BattleFactory_SetupBattle(BattleFactory *battleFactory, FieldFrontierDTO *fieldData) +{ + int i; + FrontierTrainer trainer; + + u8 playerPartySize = BattleFactory_GetPlayerPartySize(battleFactory->challengeType); + u8 opponentPartySize = BattleFactory_GetOpponentPartySize(battleFactory->challengeType, 0); + + Party_HealAllMembers(battleFactory->playersParty); + Party_HealAllMembers(battleFactory->opponentsParty); + + FieldBattleDTO *battleDTO = FieldBattleDTO_New(HEAP_ID_FIELD2, BattleFactory_GetBattleType(battleFactory->challengeType)); + FieldBattleDTO_InitFromGameState(battleDTO, NULL, fieldData->saveData, fieldData->mapHeaderID, fieldData->journalEntry, fieldData->bagCursor, fieldData->subscreenCursorOn); + + battleDTO->background = BACKGROUND_BATTLE_FACTORY; + battleDTO->terrain = TERRAIN_BATTLE_FACTORY; + + Party_InitWithCapacity(battleDTO->parties[BATTLER_PLAYER_1], playerPartySize); + Pokemon *mon = Pokemon_New(HEAP_ID_FIELD2); + + for (i = 0; i < playerPartySize; i++) { + Pokemon_Copy(Party_GetPokemonBySlotIndex(battleFactory->playersParty, i), mon); + FieldBattleDTO_AddPokemonToBattler(battleDTO, mon, BATTLER_PLAYER_1); + } + + Heap_Free(mon); + FieldBattleDTO_CopyPlayerInfoToTrainerData(battleDTO); + + Heap_Free(BattleFrontier_GetTrainer(&trainer, battleFactory->trainerIDs[battleFactory->currentBattle], HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR)); + + FieldBattleDTO_InitFrontierTrainer(battleDTO, &trainer, opponentPartySize, BATTLER_ENEMY_1, HEAP_ID_FIELD2); + Party_InitWithCapacity(battleDTO->parties[BATTLER_ENEMY_1], BattleFactory_GetOpponentPartySize(battleFactory->challengeType, 0)); + + for (i = 0; i < MAX_BATTLERS; i++) { + battleDTO->trainer[i].header.aiMask = BattleFactory_GetAIMask(battleFactory); + } + + mon = Pokemon_New(HEAP_ID_FIELD2); + + for (i = 0; i < opponentPartySize; i++) { + Pokemon_Copy(Party_GetPokemonBySlotIndex(battleFactory->opponentsParty, i), mon); + FieldBattleDTO_AddPokemonToBattler(battleDTO, mon, BATTLER_ENEMY_1); + } + + Heap_Free(mon); + + switch (battleFactory->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_GetTrainer(&trainer, battleFactory->trainerIDs[battleFactory->currentBattle + 7], HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR)); + + FieldBattleDTO_InitFrontierTrainer(battleDTO, &trainer, opponentPartySize, BATTLER_ENEMY_2, HEAP_ID_FIELD2); + Party_InitWithCapacity(battleDTO->parties[BATTLER_ENEMY_2], BattleFactory_GetOpponentPartySize(battleFactory->challengeType, 0)); + + mon = Pokemon_New(HEAP_ID_FIELD2); + + for (i = 0; i < opponentPartySize; i++) { + Pokemon_Copy(Party_GetPokemonBySlotIndex(battleFactory->opponentsParty, opponentPartySize + i), mon); + FieldBattleDTO_AddPokemonToBattler(battleDTO, mon, BATTLER_ENEMY_2); + } + + Heap_Free(mon); + break; + } + + return battleDTO; +} + +static u32 BattleFactory_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 BattleFactory_GetPokemonLevel(BattleFactory *battleFactory) +{ + if (battleFactory->isOpenLevel == 0) { + return 50; + } + + return 100; +} + +void BattleFactory_CreateInitialRentalParty(BattleFactory *battleFactory) +{ + BattleFrontier_LoadFrontierPokemon(battleFactory->initialRentalMons, battleFactory->initialRentalSetIDs, battleFactory->initialRentalIVs, battleFactory->initialRentalPersonalities, NULL, FACTORY_INITIAL_RENTAL_OPTIONS, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); + Party_Init(battleFactory->playersParty); + + Pokemon *mon = Pokemon_New(HEAP_ID_FIELD2); + for (int i = 0; i < FACTORY_INITIAL_RENTAL_OPTIONS; i++) { + FrontierPokemon_InitPokemon(&battleFactory->initialRentalMons[i], mon, BattleFactory_GetPokemonLevel(battleFactory)); + BattleFactory_AddRentalPokemonToParty(battleFactory->saveData, battleFactory->playersParty, mon); + } + + Heap_Free(mon); +} + +void BattleFactory_UpdatePartnersParty(BattleFactory *battleFactory) +{ + FrontierPokemon mons[2]; + + int partySize = Party_GetCurrentCount(battleFactory->playersParty); + + for (int i = partySize; i > 2; i--) { + Party_RemovePokemonBySlotIndex(battleFactory->playersParty, i - 1); + } + + BattleFrontier_LoadFrontierPokemon(mons, battleFactory->partnerRentalSetIDs, battleFactory->partnerRentalIVs, battleFactory->partnerRentalPersonalities, NULL, 2, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); + + Pokemon *mon = Pokemon_New(HEAP_ID_FIELD2); + + for (int i = 0; i < 2; i++) { + FrontierPokemon_InitPokemon(&mons[i], mon, BattleFactory_GetPokemonLevel(battleFactory)); + BattleFactory_AddRentalPokemonToParty(battleFactory->saveData, battleFactory->playersParty, mon); + battleFactory->playerMonSetIDs[i + 2] = battleFactory->partnerRentalSetIDs[i]; + } + + Heap_Free(mon); +} + +BOOL BattleFactory_IsMultiplayerChallenge(u8 challengeType) +{ + return challengeType == FRONTIER_CHALLENGE_MULTI || challengeType == FRONTIER_CHALLENGE_MULTI_WFC; +} + +static u16 BattleFactory_GetAIMask(BattleFactory *battleFactory) +{ + if (battleFactory->challengeType == FRONTIER_CHALLENGE_SINGLE) { + if (battleFactory->trainerIDs[battleFactory->currentBattle] == FRONTIER_TRAINER_FACTORY_HEAD_THORTON_SILVER + || battleFactory->trainerIDs[battleFactory->currentBattle] == FRONTIER_TRAINER_FACTORY_HEAD_THORTON_GOLD) { + return AI_FLAG_BASIC | AI_FLAG_EVAL_ATTACK | AI_FLAG_EXPERT; + } + } + + u16 round = BattleFactory_GetCurrentRound(battleFactory); + 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 BattleFactory_GetCurrentRound(BattleFactory *battleFactory) +{ + u16 currentRound = battleFactory->currentRound; + + if (BattleFactory_IsMultiplayerChallenge(battleFactory->challengeType) == TRUE) { + if (battleFactory->unk_57E > battleFactory->currentRound) { + currentRound = battleFactory->unk_57E; + } + } + + return currentRound; +} diff --git a/src/overlay104/frontier_communication.c b/src/overlay104/frontier_communication.c index 416f74ef3f3..13b60e5b459 100644 --- a/src/overlay104/frontier_communication.c +++ b/src/overlay104/frontier_communication.c @@ -6,9 +6,8 @@ #include "overlay104/battle_arcade.h" #include "overlay104/battle_arcade_helpers.h" #include "overlay104/battle_castle_helpers.h" +#include "overlay104/battle_factory_helpers.h" #include "overlay104/battle_hall.h" -#include "overlay104/ov104_0223A7F4.h" -#include "overlay104/struct_battle_factory.h" #include "battle_arcade_save.h" #include "battle_castle_save.h" @@ -251,9 +250,9 @@ BOOL ov104_0222EEF8(BattleFactory *battleFactory) dummy1 = 0; dummy2 = SaveData_GetTrainerInfo(battleFactory->saveData); - data[1] = battleFactory->unk_08; + data[1] = battleFactory->tradeCount; data[2] = battleFactory->currentStreak; - data[3] = battleFactory->unk_0E; + data[3] = battleFactory->currentRound; dummy1 += 4; dummy1 += (7 + 1); @@ -340,20 +339,20 @@ BOOL ov104_0222EFCC(BattleFactory *battleFactory) offset = 0; for (i = 0; i < 6; i++) { - data[i] = battleFactory->unk_584[i]; + data[i] = battleFactory->partnerRentalSetIDs[i]; } offset += 6; for (i = 0; i < 6; i++) { - data[i + offset] = battleFactory->unk_590[i]; + data[i + offset] = battleFactory->partnerRentalIVs[i]; } offset += 6; for (i = 0; i < 6; i++) { - data[i + offset] = (battleFactory->unk_598[i] & 0xFFFF); - data[i + offset + 6] = ((battleFactory->unk_598[i] >> 16) & 0xFFFF); + data[i + offset] = (battleFactory->partnerRentalPersonalities[i] & 0xFFFF); + data[i + offset + 6] = ((battleFactory->partnerRentalPersonalities[i] >> 16) & 0xFFFF); } offset += (6 * 2); @@ -382,20 +381,20 @@ void ov104_0222F03C(int netID, int unused1, void *param2, void *battleFactory) } for (i = 0; i < 6; i++) { - battleFactory_dupe->unk_254[i] = param2_dupe[i]; + battleFactory_dupe->initialRentalSetIDs[i] = param2_dupe[i]; } offset += 6; for (i = 0; i < 6; i++) { - battleFactory_dupe->unk_260[i] = param2_dupe[i + offset]; + battleFactory_dupe->initialRentalIVs[i] = param2_dupe[i + offset]; } offset += 6; for (i = 0; i < 6; i++) { - battleFactory_dupe->unk_268[i] = param2_dupe[i + offset]; - battleFactory_dupe->unk_268[i] |= (param2_dupe[i + offset + 6] << 16); + battleFactory_dupe->initialRentalPersonalities[i] = param2_dupe[i + offset]; + battleFactory_dupe->initialRentalPersonalities[i] |= (param2_dupe[i + offset + 6] << 16); } offset += (6 * 2); @@ -410,20 +409,20 @@ BOOL ov104_0222F0B4(BattleFactory *battleFactory) offset = 0; for (i = 0; i < 4; i++) { - data[i] = battleFactory->unk_3D2[i]; + data[i] = battleFactory->opponentMonSetIDs[i]; } offset += 4; for (i = 0; i < 4; i++) { - data[i + offset] = battleFactory->unk_3DA[i]; + data[i + offset] = battleFactory->opponentMonIVs[i]; } offset += 4; for (i = 0; i < 4; i++) { - data[i + offset] = (battleFactory->unk_3E0[i] & 0xFFFF); - data[i + offset + 4] = ((battleFactory->unk_3E0[i] >> 16) & 0xFFFF); + data[i + offset] = (battleFactory->opponentMonPersonalities[i] & 0xFFFF); + data[i + offset + 4] = ((battleFactory->opponentMonPersonalities[i] >> 16) & 0xFFFF); } offset += (4 * 2); @@ -451,20 +450,20 @@ void ov104_0222F124(int netID, int unused, void *param2, void *battleFactory) } for (i = 0; i < 4; i++) { - battleFactory_dupe->unk_3D2[i] = param2_dupe[i]; + battleFactory_dupe->opponentMonSetIDs[i] = param2_dupe[i]; } offset += 4; for (i = 0; i < 4; i++) { - battleFactory_dupe->unk_3DA[i] = param2_dupe[i + offset]; + battleFactory_dupe->opponentMonIVs[i] = param2_dupe[i + offset]; } offset += 4; for (i = 0; i < 4; i++) { - battleFactory_dupe->unk_3E0[i] = param2_dupe[i + offset]; - battleFactory_dupe->unk_3E0[i] |= (param2_dupe[i + offset + 4] << 16); + battleFactory_dupe->opponentMonPersonalities[i] = param2_dupe[i + offset]; + battleFactory_dupe->opponentMonPersonalities[i] |= (param2_dupe[i + offset + 4] << 16); } offset += (4 * 2); @@ -554,7 +553,7 @@ BOOL ov104_0222F238(BattleFactory *battleFactory) } for (i = 0; i < partySize; i++) { - data[i] = battleFactory->unk_4E8[i]; + data[i] = battleFactory->playerMonSetIDs[i]; } offset += partySize; @@ -601,20 +600,20 @@ void ov104_0222F31C(int netID, int unused1, void *param2, void *battleFactory) partySize = BattleFactory_GetPlayerPartySize(battleFactory_dupe->challengeType); for (i = 0; i < partySize; i++) { - battleFactory_dupe->unk_584[i] = param2_dupe[i]; + battleFactory_dupe->partnerRentalSetIDs[i] = param2_dupe[i]; } offset += partySize; for (i = 0; i < partySize; i++) { - battleFactory_dupe->unk_590[i] = param2_dupe[i + offset]; + battleFactory_dupe->partnerRentalIVs[i] = param2_dupe[i + offset]; } offset += partySize; for (i = 0; i < partySize; i++) { - battleFactory_dupe->unk_598[i] = param2_dupe[i + offset]; - battleFactory_dupe->unk_598[i] |= (param2_dupe[i + offset + partySize] << 16); + battleFactory_dupe->partnerRentalPersonalities[i] = param2_dupe[i + offset]; + battleFactory_dupe->partnerRentalPersonalities[i] |= (param2_dupe[i + offset + partySize] << 16); } offset += (partySize * 2); diff --git a/src/overlay104/frscrcmd_battle_factory.c b/src/overlay104/frscrcmd_battle_factory.c index 1e240fe4b07..36e15253da8 100644 --- a/src/overlay104/frscrcmd_battle_factory.c +++ b/src/overlay104/frscrcmd_battle_factory.c @@ -3,17 +3,18 @@ #include #include "constants/battle_factory_functions.h" +#include "constants/battle_frontier.h" #include "constants/heap.h" #include "applications/frontier/battle_factory/main.h" +#include "global/utility.h" +#include "overlay104/battle_factory.h" +#include "overlay104/battle_factory_helpers.h" #include "overlay104/frontier_opponents.h" #include "overlay104/frontier_script_context.h" #include "overlay104/frontier_script_manager.h" #include "overlay104/frscrcmd.h" #include "overlay104/ov104_02231F74.h" -#include "overlay104/ov104_022339B4.h" -#include "overlay104/ov104_0223A7F4.h" -#include "overlay104/struct_battle_factory.h" #include "overlay104/struct_ov104_02230BE4.h" #include "battle_factory_save.h" @@ -34,43 +35,40 @@ FS_EXTERN_OVERLAY(battle_factory_app); #include -static BOOL ov104_0223394C(FrontierScriptContext *param0); -static void ov104_022338B4(SysTask *param0, void *param1); +static BOOL WaitForCommResponse(FrontierScriptContext *ctx); +static void UpdateCorridorFloorBG(SysTask *task, void *data); static void StoreBattleFactoryAppResult(void *data); -BOOL FrontierScrCmd_5C(FrontierScriptContext *param0) +BOOL FrontierScrCmd_InitBattleFactory(FrontierScriptContext *ctx) { - BattleFactory *v0; - FieldFrontierDTO *fieldData; - u16 v2 = FrontierScriptContext_GetVar(param0); - u16 v3 = FrontierScriptContext_GetVar(param0); - u16 v4 = FrontierScriptContext_GetVar(param0); + u16 resumingFromSave = FrontierScriptContext_GetVar(ctx); + u16 challengeType = FrontierScriptContext_GetVar(ctx); + u16 isOpenLevel = FrontierScriptContext_GetVar(ctx); - fieldData = BattleFrontier_GetFieldData(param0->scriptMan->frontier); - v0 = ov104_022339B4(fieldData->saveData, v2, v3, v4); + FieldFrontierDTO *fieldData = BattleFrontier_GetFieldData(ctx->scriptMan->frontier); + BattleFactory *factory = BattleFactory_Init(fieldData->saveData, resumingFromSave, challengeType, isOpenLevel); - BattleFrontier_SetFacilityStruct(param0->scriptMan->frontier, v0); + BattleFrontier_SetFacilityStruct(ctx->scriptMan->frontier, factory); - return 0; + return FALSE; } -BOOL FrontierScrCmd_5D(FrontierScriptContext *param0) +BOOL FrontierScrCmd_BattleFactory_LoadTrainersForRound(FrontierScriptContext *ctx) { - BattleFactory *v0; - u16 v1 = FrontierScriptContext_GetVar(param0); + u16 resumingFromSave = FrontierScriptContext_GetVar(ctx); - v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); - ov104_02233B98(v0, v1); + BattleFactory *factory = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); + BattleFactory_LoadTrainersAndRentalsForRound(factory, resumingFromSave); - return 0; + return FALSE; } -BOOL FrontierScrCmd_5E(FrontierScriptContext *param0) +BOOL FrontierScrCmd_FreeBattleFactory(FrontierScriptContext *ctx) { - BattleFactory *v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); - ov104_022340D0(v0); + BattleFactory *factory = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); + BattleFactory_Free(factory); - return 0; + return FALSE; } BOOL FrontierScrCmd_OpenBattleFactoryAppInitial(FrontierScriptContext *ctx) @@ -93,7 +91,7 @@ BOOL FrontierScrCmd_OpenBattleFactoryAppInitial(FrontierScriptContext *ctx) args->saveData = fieldData->saveData; args->challengeType = battleFactory->challengeType; - args->unk_05 = battleFactory->isOpenLevel; + args->isOpenLevel = battleFactory->isOpenLevel; args->isExchangeMode = FALSE; args->personalParty = battleFactory->playersParty; args->receivableParty = battleFactory->opponentsParty; @@ -119,7 +117,7 @@ BOOL FrontierScrCmd_BattleFactory_StartBattle(FrontierScriptContext *ctx) FieldFrontierDTO *fieldData = BattleFrontier_GetFieldData(ctx->scriptMan->frontier); BattleFactory *battleFactory = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); - FieldBattleDTO *dto = FieldBattleDTO_NewBattleFactory(battleFactory, fieldData); + FieldBattleDTO *dto = BattleFactory_SetupBattle(battleFactory, fieldData); battleFactory->dto = dto; sub_0209B988(ctx->scriptMan->frontier, &gBattleApplicationTemplate, dto, 0, NULL); @@ -143,7 +141,7 @@ BOOL FrontierScrCmd_OpenBattleFactoryAppForTrade(FrontierScriptContext *ctx) BattleFactory *battleFactory = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); for (int i = 0; i < 6; i++) { - battleFactory->unk_4DC[i] = 0; + battleFactory->selectedAppSlots[i] = 0; } BattleFactoryAppArgs *args = Heap_Alloc(HEAP_ID_FIELD2, sizeof(BattleFactoryAppArgs)); @@ -151,7 +149,7 @@ BOOL FrontierScrCmd_OpenBattleFactoryAppForTrade(FrontierScriptContext *ctx) args->saveData = fieldData->saveData; args->challengeType = battleFactory->challengeType; - args->unk_05 = battleFactory->isOpenLevel; + args->isOpenLevel = battleFactory->isOpenLevel; args->isExchangeMode = TRUE; args->personalParty = battleFactory->playersParty; args->receivableParty = battleFactory->opponentsParty; @@ -168,36 +166,36 @@ static void StoreBattleFactoryAppResult(void *data) Heap_Free(data); } -BOOL FrontierScrCmd_63(FrontierScriptContext *param0) +BOOL FrontierScrCmd_AddSelectedRentalsToParty(FrontierScriptContext *ctx) { - BattleFactory *v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); - ov104_0223449C(v0); + BattleFactory *factory = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); + BattleFactory_AddSelectedRentalsToParty(factory); - return 0; + return FALSE; } -BOOL FrontierScrCmd_64(FrontierScriptContext *param0) +BOOL FrontierScrCmd_BattleFactory_SetupNextOpponent(FrontierScriptContext *ctx) { - BattleFactory *v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); - ov104_02234570(v0); + BattleFactory *factory = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); + BattleFactory_SetupNextOpponent(factory); - return 0; + return FALSE; } -BOOL FrontierScrCmd_65(FrontierScriptContext *param0) +BOOL FrontierScrCmd_BattleFactory_ApplyTrade(FrontierScriptContext *ctx) { - BattleFactory *v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); - ov104_022346A4(v0); + BattleFactory *factory = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); + BattleFactory_ApplyTrade(factory); - return 0; + return FALSE; } -BOOL FrontierScrCmd_66(FrontierScriptContext *param0) +BOOL FrontierScrCmd_BattleFactory_SetupNextOpponentsParty(FrontierScriptContext *ctx) { - BattleFactory *v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); - ov104_0223470C(v0); + BattleFactory *factory = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); + BattleFactory_SetupNextOpponentsParty(factory); - return 0; + return FALSE; } BOOL FrontierScrCmd_CallBattleFactoryFunction(FrontierScriptContext *ctx) @@ -213,16 +211,16 @@ BOOL FrontierScrCmd_CallBattleFactoryFunction(FrontierScriptContext *ctx) switch (command) { case BF_FUNC_UNK_0: - battleFactory->unk_07 = arg1; + battleFactory->unused2 = arg1; break; - case BF_FUNC_UNK_1: + case BF_FUNC_SET_IS_OPEN_LEVEL: battleFactory->isOpenLevel = arg1; break; case BF_FUNC_SET_CHALLENGE_TYPE: battleFactory->challengeType = arg1; break; - case BF_FUNC_UNK_3: - *returnVar = battleFactory->unk_4DC[arg1]; + case BF_FUNC_GET_SELECTED_APP_SLOT: + *returnVar = battleFactory->selectedAppSlots[arg1]; break; case BF_FUNC_GET_CURRENT_STREAK: *returnVar = battleFactory->currentStreak; @@ -235,84 +233,84 @@ BOOL FrontierScrCmd_CallBattleFactoryFunction(FrontierScriptContext *ctx) case BF_FUNC_RESET_SYSTEM: OS_ResetSystem(0); break; - case BF_FUNC_UNK_9: + case BF_FUNC_HAS_SAVED: *returnVar = BattleFactorySave_HasSaved(battleFactory->factorySave); break; - case BF_FUNC_UNK_10: - ov104_02234148(battleFactory, 2); + case BF_FUNC_QUICKSAVE: + BattleFactory_Save(battleFactory, 2); break; - case BF_FUNC_UNK_14: - *returnVar = ov104_02234430(battleFactory); + case BF_FUNC_INCREMENT_CURRENT_BATTLE: + *returnVar = BattleFactory_IncrementCurrentBattle(battleFactory); break; - case BF_FUNC_UNK_15: - *returnVar = battleFactory->unk_3F0[arg1].species; + case BF_FUNC_GET_MONS_SPECIES: + *returnVar = battleFactory->opponentMons[arg1].species; break; - case BF_FUNC_UNK_16: - *returnVar = battleFactory->unk_3F0[arg1].moves[arg2]; + case BF_FUNC_GET_MONS_MOVE: + *returnVar = battleFactory->opponentMons[arg1].moves[arg2]; break; - case BF_FUNC_UNK_17: { - Pokemon *v3 = Pokemon_New(HEAP_ID_FIELD2); - FrontierPokemon_InitPokemon(&battleFactory->unk_3F0[arg1], v3, BattleFactory_GetPokemonLevel(battleFactory)); - *returnVar = Pokemon_GetValue(v3, MON_DATA_TYPE_1, NULL); - Heap_Free(v3); + case BF_FUNC_GET_MONS_TYPE: { + Pokemon *mon = Pokemon_New(HEAP_ID_FIELD2); + FrontierPokemon_InitPokemon(&battleFactory->opponentMons[arg1], mon, BattleFactory_GetPokemonLevel(battleFactory)); + *returnVar = Pokemon_GetValue(mon, MON_DATA_TYPE_1, NULL); + Heap_Free(mon); } break; - case BF_FUNC_UNK_18: { - int v0[18]; - u8 v5 = BattleFactory_GetOpponentPartySize(battleFactory->challengeType, 1); + case BF_FUNC_GET_COMMON_TYPE: { + int typeCounts[NUM_POKEMON_TYPES]; + u8 partySize = BattleFactory_GetOpponentPartySize(battleFactory->challengeType, TRUE); - for (i = 0; i < (17 + 1); i++) { - v0[i] = 0; + for (i = 0; i < NUM_POKEMON_TYPES; i++) { + typeCounts[i] = 0; } - Pokemon *v3 = Pokemon_New(HEAP_ID_FIELD2); + Pokemon *mon = Pokemon_New(HEAP_ID_FIELD2); - for (i = 0; i < v5; i++) { - FrontierPokemon_InitPokemon(&battleFactory->unk_3F0[i], v3, BattleFactory_GetPokemonLevel(battleFactory)); + for (i = 0; i < partySize; i++) { + FrontierPokemon_InitPokemon(&battleFactory->opponentMons[i], mon, BattleFactory_GetPokemonLevel(battleFactory)); - u32 v7 = Pokemon_GetValue(v3, MON_DATA_TYPE_1, NULL); - u32 v8 = Pokemon_GetValue(v3, MON_DATA_TYPE_2, NULL); + u32 type1 = Pokemon_GetValue(mon, MON_DATA_TYPE_1, NULL); + u32 type2 = Pokemon_GetValue(mon, MON_DATA_TYPE_2, NULL); - if (v7 == v8) { - v8 = 0xff; + if (type1 == type2) { + type2 = 0xff; } - v0[v7]++; + typeCounts[type1]++; - if (v8 != 0xff) { - v0[v8]++; + if (type2 != 0xff) { + typeCounts[type2]++; } } - Heap_Free(v3); + Heap_Free(mon); - u32 v9 = 0; + u32 commonType = 0; - for (i = 0; i < (17 + 1); i++) { - if (v0[v9] < v0[i]) { - v9 = i; + for (i = 0; i < NUM_POKEMON_TYPES; i++) { + if (typeCounts[commonType] < typeCounts[i]) { + commonType = i; } } - if (v0[v9] <= 1) { + if (typeCounts[commonType] <= 1) { *returnVar = 0xff; } else { - *returnVar = v9; + *returnVar = commonType; } } break; - case BF_FUNC_UNK_19: - *returnVar = ov104_0223AF34(battleFactory); + case BF_FUNC_GET_CURRENT_ROUND: + *returnVar = BattleFactory_GetCurrentRound(battleFactory); break; - case BF_FUNC_UNK_20: - *returnVar = ov104_02234440(battleFactory, arg1); + case BF_FUNC_GET_OPPONENT_OBJECT_ID: + *returnVar = BattleFactory_GetNextOpponentObjectID(battleFactory, arg1); break; - case BF_FUNC_UNK_21: - ov104_02234474(battleFactory); + case BF_FUNC_SAVE_ON_LOSS: + BattleFactory_SaveOnLoss(battleFactory); break; - case BF_FUNC_UNK_22: - ov104_02234480(battleFactory); + case BF_FUNC_SAVE_ON_COMPLETING_ROUND: + BattleFactory_SaveOnCompletingRound(battleFactory); break; - case BF_FUNC_UNK_23: - *returnVar = ov104_0223443C(battleFactory); + case BF_FUNC_GET_CURRENT_BATTLE: + *returnVar = BattleFactory_GetCurrentBattle(battleFactory); break; case BF_FUNC_UNK_24: *returnVar = battleFactory->unk_57C; @@ -320,7 +318,7 @@ BOOL FrontierScrCmd_CallBattleFactoryFunction(FrontierScriptContext *ctx) case BF_FUNC_UNK_26: *returnVar = battleFactory->unk_57D; break; - case BF_FUNC_UNK_27: + case BF_FUNC_INIT_COMM_MANAGER: sub_0209BA80(battleFactory); break; case BF_FUNC_IS_MULTIPLAYER_CHALLENGE: @@ -329,80 +327,77 @@ BOOL FrontierScrCmd_CallBattleFactoryFunction(FrontierScriptContext *ctx) case BF_FUNC_GET_CHALLENGE_TYPE: *returnVar = battleFactory->challengeType; break; - case BF_FUNC_UNK_30: - Bg_ChangeTilemapRectPalette(graphics->bgConfig, 3, 3, 10, 26, 11, arg1); - Bg_ScheduleTilemapTransfer(graphics->bgConfig, 3); + case BF_FUNC_UPDATE_BACKGROUND: + Bg_ChangeTilemapRectPalette(graphics->bgConfig, BG_LAYER_MAIN_3, 3, 10, 26, 11, arg1); + Bg_ScheduleTilemapTransfer(graphics->bgConfig, BG_LAYER_MAIN_3); break; - case BF_FUNC_UNK_31: - battleFactory->unk_500 = SysTask_Start(ov104_022338B4, FrontierScriptManager_GetGraphics(ctx->scriptMan), 5); + case BF_FUNC_START_CORRIDOR_ANIMATION: + battleFactory->corridorAnimation = SysTask_Start(UpdateCorridorFloorBG, FrontierScriptManager_GetGraphics(ctx->scriptMan), 5); break; - case BF_FUNC_UNK_32: - if (battleFactory->unk_500 != NULL) { - SysTask_Done(battleFactory->unk_500); - battleFactory->unk_500 = NULL; + case BF_FUNC_STOP_CORRIDOR_ANIMATION: + if (battleFactory->corridorAnimation != NULL) { + SysTask_Done(battleFactory->corridorAnimation); + battleFactory->corridorAnimation = NULL; } break; - case BF_FUNC_UNK_33: - BattleFrontier_LoadTrainer(&(battleFactory->unk_34[0]), battleFactory->trainerIDs[battleFactory->unk_06], HEAP_ID_FIELD2, 178); - BattleFrontier_LoadTrainer(&(battleFactory->unk_34[1]), battleFactory->trainerIDs[battleFactory->unk_06 + 7], HEAP_ID_FIELD2, 178); + case BF_FUNC_LOAD_TRAINERS: + BattleFrontier_LoadTrainer(&battleFactory->opponents[0], battleFactory->trainerIDs[battleFactory->currentBattle], HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR); + BattleFrontier_LoadTrainer(&battleFactory->opponents[1], battleFactory->trainerIDs[battleFactory->currentBattle + FACTORY_BATTLES_PER_ROUND], HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR); break; - case BF_FUNC_UNK_34: { - u8 v6 = BattleFactory_GetPlayerPartySize(battleFactory->challengeType); + case BF_FUNC_SET_RENTED_MONS_IN_STRING: { + u8 partySize = BattleFactory_GetPlayerPartySize(battleFactory->challengeType); - for (i = 0; i < v6; i++) { - Pokemon *v3 = Party_GetPokemonBySlotIndex(battleFactory->playersParty, i); - StringTemplate_SetSpeciesName(ctx->scriptMan->strTemplate, i, Pokemon_GetBoxPokemon(v3)); + for (i = 0; i < partySize; i++) { + Pokemon *mon = Party_GetPokemonBySlotIndex(battleFactory->playersParty, i); + StringTemplate_SetSpeciesName(ctx->scriptMan->strTemplate, i, Pokemon_GetBoxPokemon(mon)); } } break; - case BF_FUNC_UNK_35: - *returnVar = ov104_022347F8(battleFactory); + case BF_FUNC_GET_EARNED_BP: + *returnVar = BattleFactory_GetEarnedBP(battleFactory); break; - case BF_FUNC_UNK_36: - ov104_02234790(battleFactory); + case BF_FUNC_INCREMENT_TRADE_COUNT: + BattleFactory_IncrementTradeCount(battleFactory); break; - case BF_FUNC_UNK_37: - *returnVar = 0; + case BF_FUNC_GET_NEXT_BATTLE_TYPE: + *returnVar = FRONTIER_NEXT_BATTLE_NORMAL; - if (battleFactory->challengeType == 0) { - if ((battleFactory->currentStreak + 1) == 21) { - *returnVar = 1; - } else if ((battleFactory->currentStreak + 1) == 49) { - *returnVar = 2; + if (battleFactory->challengeType == FRONTIER_CHALLENGE_SINGLE) { + if (battleFactory->currentStreak + 1 == FACTORY_STREAK_SILVER_BATTLE) { + *returnVar = FRONTIER_NEXT_BATTLE_SILVER; + } else if (battleFactory->currentStreak + 1 == FACTORY_STREAK_GOLD_BATTLE) { + *returnVar = FRONTIER_NEXT_BATTLE_GOLD; } } break; - case BF_FUNC_UNK_38: - ov104_0223AE30(battleFactory); + case BF_FUNC_UPDATE_PARTNERS_PARTY: + BattleFactory_UpdatePartnersParty(battleFactory); break; - case BF_FUNC_UNK_39: - BattleFrontier_LoadFrontierPokemon(battleFactory->unk_3F0, battleFactory->unk_3D2, battleFactory->unk_3DA, battleFactory->unk_3E0, NULL, 4, 11, 179); + case BF_FUNC_CREATE_OPPONENT_MONS: + BattleFrontier_LoadFrontierPokemon(battleFactory->opponentMons, battleFactory->opponentMonSetIDs, battleFactory->opponentMonIVs, battleFactory->opponentMonPersonalities, NULL, FACTORY_MAX_PARTY_SIZE, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); break; - case BF_FUNC_UNK_40: - ov104_0223ADB0(battleFactory); + case BF_FUNC_CREATE_INITAL_PARTY: + BattleFactory_CreateInitialRentalParty(battleFactory); break; - case BF_FUNC_UNK_41: - *returnVar = battleFactory->unk_0B; - battleFactory->unk_0B = 1; + case BF_FUNC_CHECK_SEEN_HEAD_INTRO: + *returnVar = battleFactory->seenFactoryHeadIntro; + battleFactory->seenFactoryHeadIntro = TRUE; break; } return FALSE; } -void ov104_022338B4(SysTask *param0, void *param1) +void UpdateCorridorFloorBG(SysTask *task, void *data) { - int v0; - FrontierGraphics *v1 = param1; + FrontierGraphics *graphics = data; - v0 = Bg_GetYOffset(v1->bgConfig, 2); + int offset = Bg_GetYOffset(graphics->bgConfig, BG_LAYER_MAIN_2); - if (v0 >= 255) { - Bg_ScheduleScroll(v1->bgConfig, 2, 3, 0); + if (offset >= 255) { + Bg_ScheduleScroll(graphics->bgConfig, BG_LAYER_MAIN_2, BG_OFFSET_UPDATE_SET_Y, 0); } else { - Bg_ScheduleScroll(v1->bgConfig, 2, 4, 1); + Bg_ScheduleScroll(graphics->bgConfig, BG_LAYER_MAIN_2, BG_OFFSET_UPDATE_ADD_Y, 1); } - - return; } BOOL FrontierScrCmd_BattleFactory_CheckWonBattle(FrontierScriptContext *ctx) @@ -415,59 +410,53 @@ BOOL FrontierScrCmd_BattleFactory_CheckWonBattle(FrontierScriptContext *ctx) return FALSE; } -BOOL FrontierScrCmd_69(FrontierScriptContext *param0) +BOOL FrontierScrCmd_BattleFactory_SendCommMessage(FrontierScriptContext *ctx) { - BattleFactory *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_022347A4(v0, v1, v2); + BattleFactory *factory = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); + *success = BattleFactory_SendCommMessage(factory, command, arg); - return 1; + return TRUE; } -BOOL FrontierScrCmd_6A(FrontierScriptContext *param0) +BOOL FrontierScrCmd_BattleFactory_WaitForCommResponses(FrontierScriptContext *ctx) { - u16 v0 = FrontierScriptContext_ReadHalfWord(param0); + ctx->data[0] = FrontierScriptContext_ReadHalfWord(ctx); + FrontierScriptContext_Pause(ctx, WaitForCommResponse); - param0->data[0] = v0; - FrontierScriptContext_Pause(param0, ov104_0223394C); - - return 1; + return TRUE; } -static BOOL ov104_0223394C(FrontierScriptContext *param0) +static BOOL WaitForCommResponse(FrontierScriptContext *ctx) { - BattleFactory *v0; - u16 v1 = FrontierScriptContext_TryGetVar(param0, param0->data[0]); + UNUSED(FrontierScriptContext_TryGetVar(ctx, ctx->data[0])); - v0 = BattleFrontier_GetFacilityStruct(param0->scriptMan->frontier); + BattleFactory *factory = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); - if (v0->msgsReceived >= 2) { - v0->msgsReceived = 0; - return 1; + if (factory->msgsReceived >= 2) { + factory->msgsReceived = 0; + return TRUE; } - return 0; + return FALSE; } -BOOL FrontierScrCmd_6B(FrontierScriptContext *param0) +BOOL FrontierScrCmd_BattleFactory_PrintTrainerIntro(FrontierScriptContext *ctx) { - u16 *v0; - BattleFactory *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); + BattleFactory *factory = BattleFrontier_GetFacilityStruct(ctx->scriptMan->frontier); - if (v1 == NULL) { - return 0; + if (factory == NULL) { + return FALSE; } - v0 = v1->unk_34[v3].trainer.introMsg; + u16 *introMsg = factory->opponents[index].trainer.introMsg; - BattleFrontier_PrintNormalTrainerMessage(param0, v0); - return 1; + BattleFrontier_PrintNormalTrainerMessage(ctx, introMsg); + return TRUE; } diff --git a/src/overlay104/ov104_022339B4.c b/src/overlay104/ov104_022339B4.c deleted file mode 100644 index 7a5cf4ece05..00000000000 --- a/src/overlay104/ov104_022339B4.c +++ /dev/null @@ -1,643 +0,0 @@ -#include "overlay104/ov104_022339B4.h" - -#include - -#include "generated/game_records.h" - -#include "struct_defs/battle_frontier.h" - -#include "overlay104/frontier_communication.h" -#include "overlay104/frontier_opponents.h" -#include "overlay104/ov104_0223A7F4.h" -#include "overlay104/struct_battle_factory.h" -#include "overlay104/struct_ov104_0224028C.h" - -#include "battle_factory_save.h" -#include "battle_frontier_save.h" -#include "battle_frontier_stats.h" -#include "game_records.h" -#include "heap.h" -#include "math_util.h" -#include "party.h" -#include "pokemon.h" -#include "savedata.h" -#include "system_vars.h" -#include "vars_flags.h" - -void ov104_02233B98(BattleFactory *param0, u16 param1); -static void ov104_02233BAC(BattleFactory *param0); -static void ov104_02233F1C(BattleFactory *param0); -void ov104_022340D0(BattleFactory *param0); -static u16 ov104_02234130(BattleFactoryAppArgs *args, u8 i); -void ov104_0223449C(BattleFactory *param0); -void ov104_02234570(BattleFactory *param0); -void ov104_022346A4(BattleFactory *param0); -void ov104_0223470C(BattleFactory *param0); -void ov104_02234790(BattleFactory *param0); -static void ov104_02233D80(BattleFactory *param0, u8 param1, u8 param2); -BOOL ov104_022347A4(BattleFactory *param0, u16 param1, u16 param2); -void ov104_02234148(BattleFactory *param0, u8 param1); -u16 ov104_02234430(BattleFactory *param0); -u16 ov104_0223443C(BattleFactory *param0); -u16 ov104_02234440(BattleFactory *param0, u8 param1); -void ov104_02234474(BattleFactory *param0); -void ov104_02234480(BattleFactory *param0); -u16 ov104_022347F8(BattleFactory *param0); - -BattleFactory *ov104_022339B4(SaveData *saveData, u16 param1, u8 param2, u8 param3) -{ - BattleFactorySave *v0; - BattleFactoryStreakFlags *v1; - const UnkStruct_ov104_0224028C *v2; - u8 v3; - u16 v4, v5; - u32 v6; - static BattleFactory *v7; - - v7 = Heap_Alloc(HEAP_ID_FIELD2, sizeof(BattleFactory)); - MI_CpuClear8(v7, sizeof(BattleFactory)); - - v7->factorySave = BattleFactorySave_Get(saveData); - v7->saveData = saveData; - v7->unk_00 = 11; - v7->playersParty = Party_New(HEAP_ID_FIELD2); - v7->opponentsParty = Party_New(HEAP_ID_FIELD2); - - v0 = v7->factorySave; - v1 = BattleFactoryStreakFlags_Get(saveData); - - if (param1 == 0) { - v7->challengeType = param2; - v7->isOpenLevel = param3; - v7->unk_06 = 0; - - BattleFactorySave_Init(v0); - - if (v7->challengeType == 3) { - if (v7->isOpenLevel == 0) { - v6 = 102; - } else { - v6 = 104; - } - - v3 = SystemVars_GetWiFiFrontierCleared(SaveData_GetVarsFlags(v7->saveData)); - } else { - v3 = (u8)BattleFactoryStreakFlags_GetFlag(v1, 10, (v7->isOpenLevel * 4) + v7->challengeType, NULL); - } - - if (v3 == 1) { - v7->currentStreak = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(v7->saveData), BattleFrontierStats_GetFactoryLatestStreakIdx(v7->isOpenLevel, v7->challengeType)); - v7->unk_08 = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(v7->saveData), BattleFrontierStats_GetFactoryLatestTradeCountIndex(v7->isOpenLevel, v7->challengeType)); - } else { - v7->currentStreak = 0; - v7->unk_08 = 0; - } - - v7->unk_10 = 0; - } else { - v7->challengeType = (u8)BattleFactorySave_GetMember(v0, 1, 0, NULL); - v7->isOpenLevel = (u8)BattleFactorySave_GetMember(v0, 0, 0, NULL); - v7->unk_06 = (u8)BattleFactorySave_GetMember(v0, 2, 0, NULL); - v7->currentStreak = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(v7->saveData), BattleFrontierStats_GetFactoryLatestStreakIdx(v7->isOpenLevel, v7->challengeType)); - v7->unk_08 = BattleFrontierSave_GetStatAutoHostIdx(SaveData_GetBattleFrontier(v7->saveData), BattleFrontierStats_GetFactoryLatestTradeCountIndex(v7->isOpenLevel, v7->challengeType)); - } - - v7->unk_0E = (u16)(v7->currentStreak / 7); - - if (BattleFactory_IsMultiplayerChallenge(v7->challengeType) == 1) { - BattleFrontier_FlagGeonetLinkInfo(v7->saveData); - } - - return v7; -} - -void ov104_02233B98(BattleFactory *param0, u16 param1) -{ - if (param1 == 0) { - ov104_02233BAC(param0); - } else { - ov104_02233F1C(param0); - } - - return; -} - -static void ov104_02233BAC(BattleFactory *param0) -{ - int v0, v1; - FrontierPokemon v2[6 * 2]; - Pokemon *v4; - u16 v5[6]; - u16 v6[6]; - - ov104_0223A860(param0->challengeType, ov104_0223AF34(param0), param0->trainerIDs, 7 * 2); - - ov104_0223AAA0(ov104_0223AF34(param0), param0->isOpenLevel, param0->unk_254, param0->unk_280, param0->unk_260, param0->unk_268, param0->unk_08, NULL, NULL); - - ov104_02233D80(param0, 4, 0); - ov104_02233D80(param0, 5, 0); - - v1 = 6; - - for (v0 = 0; v0 < 6; v0++) { - v2[v0] = param0->unk_280[v0]; - } - - if (BattleFactory_IsMultiplayerChallenge(param0->challengeType) == 1) { - for (v0 = 0; v0 < 6; v0++) { - v5[v0] = param0->unk_280[v0].species; - v6[v0] = param0->unk_280[v0].item; - } - - ov104_0223AAA0(ov104_0223AF34(param0), param0->isOpenLevel, param0->unk_584, param0->unk_5B0, param0->unk_590, param0->unk_598, param0->unk_580, v5, v6); - - ov104_02233D80(param0, 4, 1); - ov104_02233D80(param0, 5, 1); - - v1 = (6 * 2); - - for (v0 = 0; v0 < 6; v0++) { - v2[v0 + 6] = param0->unk_5B0[v0]; - } - } - - ov104_0223AB0C(BattleFactory_GetOpponentPartySize(param0->challengeType, 1), param0->trainerIDs[param0->unk_06], param0->isOpenLevel, v2, param0->unk_3D2, param0->unk_3F0, param0->unk_3DA, param0->unk_3E0, v1); - - for (v0 = 0; v0 < 6; v0++) { - v4 = Pokemon_New(HEAP_ID_FIELD2); - FrontierPokemon_InitPokemon(¶m0->unk_280[v0], v4, BattleFactory_GetPokemonLevel(param0)); - BattleFactory_AddRentalPokemonToParty(param0->saveData, param0->playersParty, v4); - Heap_Free(v4); - } - - for (v0 = 0; v0 < 6; v0++) { - v4 = Party_GetPokemonBySlotIndex(param0->playersParty, v0); - } - - return; -} - -static void ov104_02233D80(BattleFactory *param0, u8 param1, u8 param2) -{ - u16 v0; - u16 v1; - u8 v2; - u32 v3; - FrontierPokemon v4; - - v0 = (LCRNG_Next() % 6); - - if (param2 == 0) { - v1 = param0->unk_254[param1]; - v2 = param0->unk_260[param1]; - v3 = param0->unk_268[param1]; - v4 = param0->unk_280[param1]; - - param0->unk_254[param1] = param0->unk_254[v0]; - param0->unk_260[param1] = param0->unk_260[v0]; - param0->unk_268[param1] = param0->unk_268[v0]; - param0->unk_280[param1] = param0->unk_280[v0]; - - param0->unk_254[v0] = v1; - param0->unk_260[v0] = v2; - param0->unk_268[v0] = v3; - param0->unk_280[v0] = v4; - } else { - v1 = param0->unk_584[param1]; - v2 = param0->unk_590[param1]; - v3 = param0->unk_598[param1]; - v4 = param0->unk_5B0[param1]; - - param0->unk_584[param1] = param0->unk_584[v0]; - param0->unk_590[param1] = param0->unk_590[v0]; - param0->unk_598[param1] = param0->unk_598[v0]; - param0->unk_5B0[param1] = param0->unk_5B0[v0]; - - param0->unk_584[v0] = v1; - param0->unk_590[v0] = v2; - param0->unk_598[v0] = v3; - param0->unk_5B0[v0] = v4; - } - - return; -} - -static void ov104_02233F1C(BattleFactory *param0) -{ - int v0; - FrontierPokemon v4[6]; - u8 v5[6]; - u16 v6[6]; - u32 v7[6]; - - u8 v3 = BattleFactory_GetPlayerPartySize(param0->challengeType); - - for (v0 = 0; v0 < (7 * 2); v0++) { - param0->trainerIDs[v0] = (u16)BattleFactorySave_GetMember(param0->factorySave, 3, v0, NULL); - } - - for (v0 = 0; v0 < 4; v0++) { - v6[v0] = (u16)BattleFactorySave_GetMember(param0->factorySave, 4, v0, NULL); - v7[v0] = (u32)BattleFactorySave_GetMember(param0->factorySave, 6, v0, NULL); - v5[v0] = (u8)BattleFactorySave_GetMember(param0->factorySave, 5, v0, NULL); - - param0->unk_4E8[v0] = v6[v0]; - } - - BattleFrontier_LoadFrontierPokemon(v4, v6, v5, v7, NULL, 4, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); - - Pokemon *v1 = Pokemon_New(HEAP_ID_FIELD2); - - for (v0 = 0; v0 < 4; v0++) { - FrontierPokemon_InitPokemon(&v4[v0], v1, BattleFactory_GetPokemonLevel(param0)); - BattleFactory_AddRentalPokemonToParty(param0->saveData, param0->playersParty, v1); - } - - Heap_Free(v1); - - for (v0 = 0; v0 < 4; v0++) { - v6[v0] = (u16)BattleFactorySave_GetMember(param0->factorySave, 7, v0, NULL); - v7[v0] = (u32)BattleFactorySave_GetMember(param0->factorySave, 9, v0, NULL); - v5[v0] = (u8)BattleFactorySave_GetMember(param0->factorySave, 8, v0, NULL); - - param0->unk_3D2[v0] = v6[v0]; - } - - BattleFrontier_LoadFrontierPokemon(v4, v6, v5, v7, NULL, 4, 11, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); - - v1 = Pokemon_New(HEAP_ID_FIELD2); - - for (v0 = 0; v0 < 4; v0++) { - FrontierPokemon_InitPokemon(&v4[v0], v1, BattleFactory_GetPokemonLevel(param0)); - BattleFactory_AddRentalPokemonToParty(param0->saveData, param0->opponentsParty, v1); - } - - Heap_Free(v1); - - return; -} - -void ov104_022340D0(BattleFactory *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(BattleFactory)); - - Heap_Free(param0); - param0 = NULL; - - return; -} - -void BattleFactory_GetMonSelectionAppResult(BattleFactory *battleFactory, BattleFactoryAppArgs *args) -{ - for (int i = 0; i < 6; i++) { - battleFactory->unk_4DC[i] = ov104_02234130(args, i); - } -} - -static u16 ov104_02234130(BattleFactoryAppArgs *args, u8 i) -{ - if (i >= 6) { - GF_ASSERT(FALSE); - return 0; - } - - return args->selectedIndices[i]; -} - -void ov104_02234148(BattleFactory *param0, u8 param1) -{ - u16 v0, v1, v2; - u8 v3, v4; - u8 v5[4]; - u16 v6[4]; - u32 v7[4]; - u32 v8, v9, v10; - BattleFrontierSave *frontier; - Pokemon *v12; - BattleFactorySave *v13 = param0->factorySave; - BattleFactoryStreakFlags *v14 = BattleFactoryStreakFlags_Get(param0->saveData); - - frontier = SaveData_GetBattleFrontier(param0->saveData); - v3 = BattleFactory_GetPlayerPartySize(param0->challengeType); - v4 = BattleFactory_GetOpponentPartySize(param0->challengeType, 1); - - v5[0] = param0->isOpenLevel; - BattleFactorySave_SetMember(param0->factorySave, 0, 0, v5); - - v5[0] = param0->challengeType; - BattleFactorySave_SetMember(param0->factorySave, 1, 0, v5); - BattleFactorySave_RecordSave(param0->factorySave, 1); - - v5[0] = param0->unk_06; - BattleFactorySave_SetMember(param0->factorySave, 2, 0, v5); - BattleFrontierSave_SetStatAutoHostIdx(frontier, BattleFrontierStats_GetFactoryLatestTradeCountIndex(param0->isOpenLevel, param0->challengeType), param0->unk_08); - BattleFrontierSave_SetStatAutoHostIdx(frontier, BattleFrontierStats_GetFactoryLatestStreakIdx(param0->isOpenLevel, param0->challengeType), param0->currentStreak); - - if (param1 != 2) { - v1 = BattleFrontierSave_GetStatAutoHostIdx(frontier, BattleFrontierStats_GetFactoryRecordStreakIdx(param0->isOpenLevel, param0->challengeType)); - v8 = BattleFrontierSave_SetIfBetterAutoHostIdx(frontier, BattleFrontierStats_GetFactoryRecordStreakIdx(param0->isOpenLevel, param0->challengeType), param0->currentStreak); - v2 = BattleFrontierSave_GetStatAutoHostIdx(frontier, BattleFrontierStats_GetFactoryRecordStreakIdx(param0->isOpenLevel, param0->challengeType)); - - if (param0->currentStreak == v1) { - BattleFrontierSave_SetIfBetterAutoHostIdx(frontier, BattleFrontierStats_GetFactoryRecordTradeCountIndex(param0->isOpenLevel, param0->challengeType), param0->unk_08); - } else if (v1 < v2) { - BattleFrontierSave_SetStatAutoHostIdx(frontier, BattleFrontierStats_GetFactoryRecordTradeCountIndex(param0->isOpenLevel, param0->challengeType), param0->unk_08); - } - - v5[0] = param0->unk_0A; - BattleFactoryStreakFlags_SetFlag(v14, 10, (param0->isOpenLevel * 4) + param0->challengeType, v5); - - if (param0->challengeType == 3) { - if (param0->isOpenLevel == 0) { - v10 = 102; - } else { - v10 = 104; - } - - BattleFrontierSave_SetStatAutoHostIdx(frontier, v10, param0->unk_0A); - } - } - - for (v0 = 0; v0 < (7 * 2); v0++) { - v6[0] = param0->trainerIDs[v0]; - BattleFactorySave_SetMember(param0->factorySave, 3, v0, v6); - } - - v9 = Party_GetCurrentCount(param0->playersParty); - - for (v0 = 0; v0 < v9; v0++) { - v12 = Party_GetPokemonBySlotIndex(param0->playersParty, v0); - - v6[0] = param0->unk_4E8[v0]; - BattleFactorySave_SetMember(param0->factorySave, 4, v0, v6); - - v5[0] = Pokemon_GetValue(v12, MON_DATA_ATK_IV, NULL); - BattleFactorySave_SetMember(param0->factorySave, 5, v0, v5); - - v7[0] = Pokemon_GetValue(v12, MON_DATA_PERSONALITY, NULL); - BattleFactorySave_SetMember(param0->factorySave, 6, v0, v7); - } - - v9 = Party_GetCurrentCount(param0->opponentsParty); - - for (v0 = 0; v0 < v9; v0++) { - v12 = Party_GetPokemonBySlotIndex(param0->opponentsParty, v0); - - v6[0] = param0->unk_3D2[v0]; - BattleFactorySave_SetMember(param0->factorySave, 7, v0, v6); - - v5[0] = Pokemon_GetValue(v12, MON_DATA_ATK_IV, NULL); - BattleFactorySave_SetMember(param0->factorySave, 8, v0, v5); - - v7[0] = Pokemon_GetValue(v12, MON_DATA_PERSONALITY, NULL); - BattleFactorySave_SetMember(param0->factorySave, 9, v0, v7); - } - - return; -} - -u16 ov104_02234430(BattleFactory *param0) -{ - param0->unk_06++; - return param0->unk_06; -} - -u16 ov104_0223443C(BattleFactory *param0) -{ - return param0->unk_06; -} - -u16 ov104_02234440(BattleFactory *param0, u8 param1) -{ - FrontierTrainer v0; - u8 v2 = param0->unk_06 + (param1 * 7); - - Heap_Free(BattleFrontier_GetTrainer(&v0, param0->trainerIDs[v2], HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDTR)); - - return BattleFrontier_GetObjectIDFromTrainerClass(v0.trainerType); -} - -void ov104_02234474(BattleFactory *param0) -{ - ov104_02234148(param0, 1); - return; -} - -void ov104_02234480(BattleFactory *param0) -{ - param0->unk_0A = 1; - - if (param0->unk_0E < 8) { - param0->unk_0E++; - } - - param0->unk_06 = 0; - ov104_02234148(param0, 0); - - return; -} - -void ov104_0223449C(BattleFactory *param0) -{ - int v0; - u8 v1, v2; - Pokemon *v3; - const UnkStruct_ov104_0224028C *v4; - - v1 = BattleFactory_GetPlayerPartySize(param0->challengeType); - v2 = BattleFactory_GetOpponentPartySize(param0->challengeType, 1); - - Party_Init(param0->playersParty); - - v3 = Pokemon_New(HEAP_ID_FIELD2); - - for (v0 = 0; v0 < v1; v0++) { - FrontierPokemon_InitPokemon(¶m0->unk_280[param0->unk_4DC[v0]], v3, BattleFactory_GetPokemonLevel(param0)); - BattleFactory_AddRentalPokemonToParty(param0->saveData, param0->playersParty, v3); - param0->unk_4E8[v0] = param0->unk_254[param0->unk_4DC[v0]]; - } - - for (v0 = 0; v0 < v2; v0++) { - FrontierPokemon_InitPokemon(¶m0->unk_3F0[v0], v3, BattleFactory_GetPokemonLevel(param0)); - BattleFactory_AddRentalPokemonToParty(param0->saveData, param0->opponentsParty, v3); - } - - Heap_Free(v3); - - return; -} - -void ov104_02234570(BattleFactory *param0) -{ - int v0, v1, v2; - u8 v3; - u16 v4[8]; - u16 v5[8]; - Pokemon *v6; - const UnkStruct_ov104_0224028C *v7; - - for (v0 = 0; v0 < (4 + 4); v0++) { - v4[v0] = 0; - v5[v0] = 0; - } - - v3 = BattleFactory_GetOpponentPartySize(param0->challengeType, 1); - v1 = Party_GetCurrentCount(param0->playersParty); - - for (v0 = 0; v0 < v1; v0++) { - v6 = Party_GetPokemonBySlotIndex(param0->playersParty, v0); - v4[v0] = Pokemon_GetValue(v6, MON_DATA_SPECIES, NULL); - v5[v0] = Pokemon_GetValue(v6, MON_DATA_HELD_ITEM, NULL); - } - - v2 = v1; - v1 = Party_GetCurrentCount(param0->opponentsParty); - - for (v0 = 0; v0 < v1; v0++) { - v6 = Party_GetPokemonBySlotIndex(param0->opponentsParty, v0); - v4[v0 + v2] = Pokemon_GetValue(v6, MON_DATA_SPECIES, NULL); - v5[v0 + v2] = Pokemon_GetValue(v6, MON_DATA_HELD_ITEM, NULL); - - param0->unk_254[v0] = param0->unk_3D2[v0]; - } - - v7 = ov104_0223A8A8(param0->trainerIDs[param0->unk_06], param0->isOpenLevel); - - ov104_0223A918(v4, v5, v2 + v1, v3, param0->unk_3D2, 11, v7, 0, param0->unk_3DA); - BattleFrontier_LoadFrontierPokemon(param0->unk_3F0, param0->unk_3D2, param0->unk_3DA, NULL, param0->unk_3E0, v3, 11, 179); - - return; -} - -void ov104_022346A4(BattleFactory *param0) -{ - Pokemon *v0; - - if (param0->unk_4DC[0] == 0xff) { - (void)0; - } else { - v0 = Party_GetPokemonBySlotIndex(param0->opponentsParty, param0->unk_4DC[1]); - Party_AddPokemonBySlotIndex(param0->playersParty, param0->unk_4DC[0], v0); - - param0->unk_4E8[param0->unk_4DC[0]] = param0->unk_254[param0->unk_4DC[1]]; - - ov104_02234790(param0); - GameRecords_IncrementRecordValue(SaveData_GetGameRecords(param0->saveData), RECORD_UNK_064); - } - - return; -} - -void ov104_0223470C(BattleFactory *param0) -{ - int v0; - u8 v1, v2; - Pokemon *v3; - int v4; - - v1 = BattleFactory_GetPlayerPartySize(param0->challengeType); - v2 = BattleFactory_GetOpponentPartySize(param0->challengeType, 1); - - Party_Init(param0->opponentsParty); - - v3 = Pokemon_New(HEAP_ID_FIELD2); - - for (v0 = 0; v0 < v2; v0++) { - FrontierPokemon_InitPokemon(¶m0->unk_3F0[v0], v3, BattleFactory_GetPokemonLevel(param0)); - BattleFactory_AddRentalPokemonToParty(param0->saveData, param0->opponentsParty, v3); - } - - Heap_Free(v3); - - for (v0 = 0; v0 < v2; v0++) { - v3 = Party_GetPokemonBySlotIndex(param0->opponentsParty, v0); - } - - return; -} - -void ov104_02234790(BattleFactory *param0) -{ - if (param0->unk_08 < 9999) { - param0->unk_08++; - } - - return; -} - -BOOL ov104_022347A4(BattleFactory *param0, u16 param1, u16 param2) -{ - int v0; - - switch (param1) { - case 0: - v0 = ov104_0222EEF8(param0); - break; - case 1: - v0 = FactoryCommunication_SendTrainers(param0); - break; - case 2: - v0 = ov104_0222EFCC(param0); - break; - case 3: - v0 = ov104_0222F0B4(param0); - break; - case 4: - v0 = ov104_0222F1A0(param0, param2); - break; - case 5: - v0 = ov104_0222F1EC(param0, param2); - break; - case 6: - v0 = ov104_0222F238(param0); - break; - } - - return v0; -} - -u16 ov104_022347F8(BattleFactory *param0) -{ - u8 v0; - u16 v1; - static const u8 v2[8 + 1] = { 0, 5, 5, 5, 5, 7, 7, 8, 9 }; - static const u8 v3[8 + 1] = { 0, 10, 11, 12, 13, 16, 17, 19, 21 }; - - v1 = param0->unk_0E; - - 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_0223A7F4.c b/src/overlay104/ov104_0223A7F4.c deleted file mode 100644 index 5f25fc99e76..00000000000 --- a/src/overlay104/ov104_0223A7F4.c +++ /dev/null @@ -1,519 +0,0 @@ -#include "overlay104/ov104_0223A7F4.h" - -#include - -#include "constants/battle_frontier.h" -#include "generated/ai_flags.h" -#include "generated/frontier_trainers.h" - -#include "struct_defs/frontier_pokemon_base.h" - -#include "overlay104/frontier_opponents.h" -#include "overlay104/struct_battle_factory.h" -#include "overlay104/struct_ov104_02230BE4.h" -#include "overlay104/struct_ov104_0224028C.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 "trainer_info.h" - -static const struct { - u16 unk_00; - u16 unk_02; - u16 unk_04; - u16 unk_06; -} Unk_ov104_022401FC[] = { - { 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 const UnkStruct_ov104_0224028C Unk_ov104_0224028C[] = { - { 0x64, 0x1, 0x96, 0x0, 0x1 }, - { 0x78, 0x97, 0xFA, 0x4, 0x1 }, - { 0x8C, 0xFB, 0x15E, 0x8, 0x1 }, - { 0xA0, 0x15F, 0x1E6, 0xC, 0x1 }, - { 0xB4, 0x1E7, 0x26E, 0x10, 0x1 }, - { 0xC8, 0x26F, 0x2F6, 0x14, 0x1 }, - { 0xDC, 0x2F7, 0x37E, 0x18, 0x1 }, - { 0x12C, 0x15F, 0x3B6, 0x1F, 0x0 }, - { 0x136, 0x15F, 0x1E6, 0xC, 0x0 }, - { 0x137, 0x15F, 0x1E6, 0x1F, 0x0 } -}; - -static const UnkStruct_ov104_0224028C Unk_ov104_022402DC[] = { - { 0x64, 0x15F, 0x1E6, 0x0, 0x1 }, - { 0x78, 0x1E7, 0x26E, 0x4, 0x1 }, - { 0x8C, 0x26F, 0x2F6, 0x8, 0x1 }, - { 0xA0, 0x2F7, 0x37E, 0xC, 0x1 }, - { 0xB4, 0x15F, 0x3B6, 0x10, 0x1 }, - { 0xC8, 0x15F, 0x3B6, 0x14, 0x1 }, - { 0xDC, 0x15F, 0x3B6, 0x18, 0x1 }, - { 0x12C, 0x15F, 0x3B6, 0x1F, 0x0 }, - { 0x136, 0x2F7, 0x3B6, 0xC, 0x0 }, - { 0x137, 0x2F7, 0x3B6, 0x1F, 0x0 } -}; - -static const UnkStruct_ov104_0224028C Unk_ov104_0224023C[] = { - { 0x64, 0x15F, 0x1E6, 0x0, 0x1 }, - { 0x78, 0x1E7, 0x26E, 0x4, 0x1 }, - { 0x8C, 0x26F, 0x2F6, 0x8, 0x1 }, - { 0xA0, 0x2F7, 0x37E, 0xC, 0x1 }, - { 0xB4, 0x26F, 0x3B6, 0x10, 0x1 }, - { 0xC8, 0x26F, 0x3B6, 0x14, 0x1 }, - { 0xDC, 0x26F, 0x3B6, 0x18, 0x1 }, - { 0x12C, 0x15F, 0x3B6, 0x1F, 0x0 }, - { 0x136, 0x2F7, 0x3B6, 0xC, 0x0 }, - { 0x137, 0x2F7, 0x3B6, 0x1F, 0x0 } -}; - -static int ov104_0223A7F4(u8 param0, int param1, int param2); -const UnkStruct_ov104_0224028C *ov104_0223A8A8(int param0, int param1); -const UnkStruct_ov104_0224028C *ov104_0223A8F4(int param0, int param1); -void ov104_0223A860(u8 param0, int param1, u16 param2[], u8 param3); -u8 BattleFactory_GetPlayerPartySize(u8 challengeType); -u8 BattleFactory_GetOpponentPartySize(u8 challengeType, BOOL param1); -static u32 BattleFactory_GetBattleType(u8 challengeType); -u8 BattleFactory_GetPokemonLevel(BattleFactory *battleFactory); -void ov104_0223ADB0(BattleFactory *battleFactory); -void ov104_0223AE30(BattleFactory *battleFactory); -static u16 BattleFactory_GetAIMask(BattleFactory *battleFactory); -u16 ov104_0223AF34(BattleFactory *battleFactory); -void FieldBattleDTO_CopyPlayerInfoToTrainerData(FieldBattleDTO *dto); - -static int ov104_0223A7F4(u8 param0, int param1, int param2) -{ - int v0, v1, v2, v3; - - if (param1 >= NELEMS(Unk_ov104_022401FC)) { - param1 = NELEMS(Unk_ov104_022401FC) - 1; - } - - if (param0 == 0) { - v3 = (param1 * 7) + (param2 + 1); - - if (v3 == 21) { - return FRONTIER_TRAINER_FACTORY_HEAD_THORTON_SILVER; - } else if (v3 == 49) { - return FRONTIER_TRAINER_FACTORY_HEAD_THORTON_GOLD; - } - } - - if ((param2 == 7 - 1) || (param2 == (7 * 2) - 1)) { - v1 = Unk_ov104_022401FC[param1].unk_06 - Unk_ov104_022401FC[param1].unk_04; - v2 = Unk_ov104_022401FC[param1].unk_04; - } else { - v1 = Unk_ov104_022401FC[param1].unk_02 - Unk_ov104_022401FC[param1].unk_00; - v2 = Unk_ov104_022401FC[param1].unk_00; - } - - v0 = v2 + (LCRNG_Next() % v1); - return v0; -} - -void ov104_0223A860(u8 param0, int param1, u16 param2[], u8 param3) -{ - int v0 = 0; - int v1; - - do { - param2[v0] = ov104_0223A7F4(param0, param1, v0); - - for (v1 = 0; v1 < v0; v1++) { - if (param2[v1] == param2[v0]) { - break; - } - } - - if (v1 != v0) { - continue; - } - - v0++; - } while (v0 < param3); -} - -const UnkStruct_ov104_0224028C *ov104_0223A8A8(int param0, int param1) -{ - int v0; - static const UnkStruct_ov104_0224028C *v1; - int v2; - - if (param1 == 0) { - v1 = Unk_ov104_0224028C; - v2 = NELEMS(Unk_ov104_0224028C); - } else { - v1 = Unk_ov104_022402DC; - v2 = NELEMS(Unk_ov104_022402DC); - } - - for (v0 = 0; v0 < v2; v0++) { - if (param0 < v1[v0].unk_00) { - break; - } - } - - if (v0 >= v2) { - GF_ASSERT(FALSE); - v0 = v2 - 1; - } - - return &v1[v0]; -} - -const UnkStruct_ov104_0224028C *ov104_0223A8F4(int param0, int param1) -{ - if (param0 >= 8) { - param0 = 8 - 1; - } - - if (param1 == 0) { - return &Unk_ov104_0224028C[param0]; - } else { - return &Unk_ov104_0224023C[param0]; - } -} - -static const int Unk_ov104_022401E8[] = { - 0x6, - 0xD, - 0x14, - 0x1B, - 0x22 -}; - -BOOL ov104_0223A918(const u16 param0[], const u16 param1[], int param2, int param3, u16 param4[], int param5, const UnkStruct_ov104_0224028C *param6, u16 param7, u8 param8[]) -{ - u8 v0; - int v1, v2, v3; - FrontierPokemonBase v4[6]; - int v5, v6; - const UnkStruct_ov104_0224028C *v7 = param6; - - GF_ASSERT(param3 <= 6); - - v2 = v7->unk_04 - v7->unk_02; - v1 = 0; - v6 = 0; - - if (param7 != 0) { - v6 = (NELEMS(Unk_ov104_022401E8)); - - for (v5 = 0; v5 < (NELEMS(Unk_ov104_022401E8)); v5++) { - if (param7 <= Unk_ov104_022401E8[v5]) { - v6 = v5; - break; - } - } - } - - while (v1 != param3) { - if ((v1 >= param3 - v6) && (v7->unk_07 == 1)) { - v2 = (v7 + 1)->unk_04 - (v7 + 1)->unk_02; - v3 = (v7 + 1)->unk_04 - (LCRNG_Next() % (v2 + 1)); - v0 = (v7 + 1)->unk_06; - } else { - v3 = v7->unk_04 - (LCRNG_Next() % (v2 + 1)); - v0 = v7->unk_06; - } - - BattleFrontier_GetPokemonBase(&v4[v1], v3, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); - - for (v5 = 0; v5 < v1; v5++) { - if ((v4[v5].species == v4[v1].species) || (v4[v5].item == v4[v1].item)) { - break; - } - } - - if (v5 != v1) { - continue; - } - - for (v5 = 0; v5 < param2; v5++) { - if ((v4[v1].species == param0[v5]) || (v4[v1].item == param1[v5])) { - break; - } - } - - if (v5 != param2) { - continue; - } - - param4[v1] = v3; - param8[v1] = v0; - - v1++; - } - - return 0; -} - -u8 BattleFactory_GetPlayerPartySize(u8 challengeType) -{ - switch (challengeType) { - case FRONTIER_CHALLENGE_SINGLE: - case FRONTIER_CHALLENGE_DOUBLE: - return 3; - case FRONTIER_CHALLENGE_MULTI: - case FRONTIER_CHALLENGE_MULTI_WFC: - return 2; - } - - return 0; -} - -u8 BattleFactory_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; - } - } - - return 0; -} - -void ov104_0223AAA0(u16 param0, u8 param1, u16 *param2, FrontierPokemon *param3, u8 *param4, u32 *param5, u16 param6, u16 *param7, u16 *param8) -{ - const UnkStruct_ov104_0224028C *v0; - int v1; - - v0 = ov104_0223A8F4(param0, param1); - - if (param7 == NULL) { - ov104_0223A918(NULL, NULL, 0, 6, param2, 11, v0, param6, param4); - } else { - ov104_0223A918(param7, param7, 6, 6, param2, 11, v0, param6, param4); - } - - BattleFrontier_LoadFrontierPokemon(param3, param2, param4, NULL, param5, 6, 11, 179); - return; -} - -void ov104_0223AB0C(u8 param0, u16 param1, u8 param2, FrontierPokemon *param3, u16 *param4, FrontierPokemon *param5, u8 *param6, u32 *param7, int param8) -{ - int v0; - FrontierPokemon v1; - u16 v3[6 * 2]; - u16 v4[6 * 2]; - - const UnkStruct_ov104_0224028C *v2 = ov104_0223A8A8(param1, param2); - - for (v0 = 0; v0 < param8; v0++) { - v1 = param3[v0]; - v3[v0] = v1.species; - v4[v0] = v1.item; - } - - ov104_0223A918(v3, v4, param8, param0, param4, 11, v2, 0, param6); - BattleFrontier_LoadFrontierPokemon(param5, param4, param6, NULL, param7, param0, HEAP_ID_FIELD2, NARC_INDEX_BATTLE__B_PL_TOWER__PL_BTDPM); - - return; -} - -FieldBattleDTO *FieldBattleDTO_NewBattleFactory(BattleFactory *battleFactory, FieldFrontierDTO *fieldData) -{ - int i; - FrontierTrainer trDataDTO; - - u8 playerPartySize = BattleFactory_GetPlayerPartySize(battleFactory->challengeType); - u8 opponentPartySize = BattleFactory_GetOpponentPartySize(battleFactory->challengeType, 0); - - Party_HealAllMembers(battleFactory->playersParty); - Party_HealAllMembers(battleFactory->opponentsParty); - - FieldBattleDTO *battleDTO = FieldBattleDTO_New(HEAP_ID_FIELD2, BattleFactory_GetBattleType(battleFactory->challengeType)); - FieldBattleDTO_InitFromGameState(battleDTO, NULL, fieldData->saveData, fieldData->mapHeaderID, fieldData->journalEntry, fieldData->bagCursor, fieldData->subscreenCursorOn); - - battleDTO->background = BACKGROUND_BATTLE_FACTORY; - battleDTO->terrain = TERRAIN_BATTLE_FACTORY; - - Party_InitWithCapacity(battleDTO->parties[BATTLER_PLAYER_1], playerPartySize); - Pokemon *mon = Pokemon_New(HEAP_ID_FIELD2); - - for (i = 0; i < playerPartySize; i++) { - Pokemon_Copy(Party_GetPokemonBySlotIndex(battleFactory->playersParty, i), mon); - FieldBattleDTO_AddPokemonToBattler(battleDTO, mon, BATTLER_PLAYER_1); - } - - Heap_Free(mon); - FieldBattleDTO_CopyPlayerInfoToTrainerData(battleDTO); - - Heap_Free(BattleFrontier_GetTrainer(&trDataDTO, battleFactory->trainerIDs[battleFactory->unk_06], 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], BattleFactory_GetOpponentPartySize(battleFactory->challengeType, 0)); - - for (i = 0; i < MAX_BATTLERS; i++) { - battleDTO->trainer[i].header.aiMask = BattleFactory_GetAIMask(battleFactory); - } - - mon = Pokemon_New(HEAP_ID_FIELD2); - - for (i = 0; i < opponentPartySize; i++) { - Pokemon_Copy(Party_GetPokemonBySlotIndex(battleFactory->opponentsParty, i), mon); - FieldBattleDTO_AddPokemonToBattler(battleDTO, mon, BATTLER_ENEMY_1); - } - - Heap_Free(mon); - - switch (battleFactory->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_GetTrainer(&trDataDTO, battleFactory->trainerIDs[battleFactory->unk_06 + 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], BattleFactory_GetOpponentPartySize(battleFactory->challengeType, 0)); - - mon = Pokemon_New(HEAP_ID_FIELD2); - - for (i = 0; i < opponentPartySize; i++) { - Pokemon_Copy(Party_GetPokemonBySlotIndex(battleFactory->opponentsParty, opponentPartySize + i), mon); - FieldBattleDTO_AddPokemonToBattler(battleDTO, mon, BATTLER_ENEMY_2); - } - - Heap_Free(mon); - break; - } - - return battleDTO; -} - -static u32 BattleFactory_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 BattleFactory_GetPokemonLevel(BattleFactory *battleFactory) -{ - if (battleFactory->isOpenLevel == 0) { - return 50; - } - - return 100; -} - -void ov104_0223ADB0(BattleFactory *battleFactory) -{ - int v0; - Pokemon *v1; - - BattleFrontier_LoadFrontierPokemon(battleFactory->unk_280, battleFactory->unk_254, battleFactory->unk_260, battleFactory->unk_268, NULL, 6, 11, 179); - Party_Init(battleFactory->playersParty); - - v1 = Pokemon_New(HEAP_ID_FIELD2); - - for (v0 = 0; v0 < 6; v0++) { - FrontierPokemon_InitPokemon(&battleFactory->unk_280[v0], v1, BattleFactory_GetPokemonLevel(battleFactory)); - BattleFactory_AddRentalPokemonToParty(battleFactory->saveData, battleFactory->playersParty, v1); - } - - Heap_Free(v1); - - return; -} - -void ov104_0223AE30(BattleFactory *battleFactory) -{ - int v0, v1; - Pokemon *v2; - FrontierPokemon v3[2]; - - v1 = Party_GetCurrentCount(battleFactory->playersParty); - - for (v0 = v1; v0 > 2; v0--) { - Party_RemovePokemonBySlotIndex(battleFactory->playersParty, v0 - 1); - } - - BattleFrontier_LoadFrontierPokemon(v3, battleFactory->unk_584, battleFactory->unk_590, battleFactory->unk_598, NULL, 2, 11, 179); - - v2 = Pokemon_New(HEAP_ID_FIELD2); - - for (v0 = 0; v0 < 2; v0++) { - FrontierPokemon_InitPokemon(&v3[v0], v2, BattleFactory_GetPokemonLevel(battleFactory)); - BattleFactory_AddRentalPokemonToParty(battleFactory->saveData, battleFactory->playersParty, v2); - battleFactory->unk_4E8[v0 + 2] = battleFactory->unk_584[v0]; - } - - Heap_Free(v2); - return; -} - -BOOL BattleFactory_IsMultiplayerChallenge(u8 challengeType) -{ - return challengeType == FRONTIER_CHALLENGE_MULTI || challengeType == FRONTIER_CHALLENGE_MULTI_WFC; -} - -static u16 BattleFactory_GetAIMask(BattleFactory *battleFactory) -{ - u16 aiMask, v1; - - if (battleFactory->challengeType == FRONTIER_CHALLENGE_SINGLE) { - if (battleFactory->trainerIDs[battleFactory->unk_06] == FRONTIER_TRAINER_FACTORY_HEAD_THORTON_SILVER - || battleFactory->trainerIDs[battleFactory->unk_06] == FRONTIER_TRAINER_FACTORY_HEAD_THORTON_GOLD) { - return AI_FLAG_BASIC | AI_FLAG_EVAL_ATTACK | AI_FLAG_EXPERT; - } - } - - v1 = ov104_0223AF34(battleFactory); - 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_0223AF34(BattleFactory *battleFactory) -{ - u16 v0 = battleFactory->unk_0E; - - if (BattleFactory_IsMultiplayerChallenge(battleFactory->challengeType) == TRUE) { - if (battleFactory->unk_57E > battleFactory->unk_0E) { - v0 = battleFactory->unk_57E; - } - } - - return v0; -}