diff --git a/asm/macros/battle_frontier/battle_dome.inc b/asm/macros/battle_frontier/battle_dome.inc index 9adbcc54e7..fe21ca4308 100644 --- a/asm/macros/battle_frontier/battle_dome.inc +++ b/asm/macros/battle_frontier/battle_dome.inc @@ -57,7 +57,7 @@ special CallBattleDomeFunction .endm - @ Sets gTrainerBattleOpponent_A to the trainer ID of the next opponent + @ Sets gTrainerBattleParameter.params.opponentA to the trainer ID of the next opponent .macro dome_setopponent setvar VAR_0x8004, BATTLE_DOME_FUNC_SET_OPPONENT_ID special CallBattleDomeFunction diff --git a/asm/macros/battle_frontier/battle_tower.inc b/asm/macros/battle_frontier/battle_tower.inc index b3c86955dd..6c9e606dde 100644 --- a/asm/macros/battle_frontier/battle_tower.inc +++ b/asm/macros/battle_frontier/battle_tower.inc @@ -115,14 +115,13 @@ .macro multi_2_vs_2 trainer1Id:req, trainer1LoseText:req, trainer2Id:req, trainer2LoseText:req, partnerId:req special SavePlayerParty - trainerbattle TRAINER_BATTLE_SET_TRAINER_A, \trainer1Id, 0, NULL, \trainer1LoseText @ set first trainer mons - trainerbattle TRAINER_BATTLE_SET_TRAINER_B, \trainer2Id, 0, NULL, \trainer2LoseText @ set second trainer mons + trainerbattle TRAINER_BATTLE_SET_TRAINERS_FOR_MULTI_BATTLE, OBJ_ID_NONE, \trainer1Id, NULL, \trainer1LoseText, NULL, OBJ_ID_NONE, \trainer2Id, NULL, \trainer2LoseText, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE multi_do MULTI_BATTLE_2_VS_2, \partnerId .endm .macro multi_2_vs_1 trainer1Id:req, trainer1LoseText:req, partnerId:req special SavePlayerParty - trainerbattle TRAINER_BATTLE_SET_TRAINER_A, \trainer1Id, 0, NULL, \trainer1LoseText @ set first trainer mons + trainerbattle TRAINER_BATTLE_SET_TRAINERS_FOR_MULTI_BATTLE, OBJ_ID_NONE, \trainer1Id, NULL, \trainer1LoseText, NULL, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE multi_do MULTI_BATTLE_2_VS_1, \partnerId .endm @@ -145,14 +144,13 @@ .macro multi_fixed_2_vs_2 trainer1Id:req, trainer1LoseText:req, trainer2Id:req, trainer2LoseText:req, partnerId:req special SavePlayerParty - trainerbattle TRAINER_BATTLE_SET_TRAINER_A, \trainer1Id, 0, NULL, \trainer1LoseText @ set first trainer mons - trainerbattle TRAINER_BATTLE_SET_TRAINER_B, \trainer2Id, 0, NULL, \trainer2LoseText @ set second trainer mons + trainerbattle TRAINER_BATTLE_SET_TRAINERS_FOR_MULTI_BATTLE, OBJ_ID_NONE, \trainer1Id, NULL, \trainer1LoseText, NULL, OBJ_ID_NONE, \trainer2Id, NULL, \trainer2LoseText, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE multi_do_fixed MULTI_BATTLE_2_VS_2, \partnerId .endm .macro multi_fixed_2_vs_1 trainer1Id:req, trainer1LoseText:req, partnerId:req special SavePlayerParty - trainerbattle TRAINER_BATTLE_SET_TRAINER_A, \trainer1Id, 0, NULL, \trainer1LoseText @ set first trainer mons + trainerbattle TRAINER_BATTLE_SET_TRAINERS_FOR_MULTI_BATTLE, OBJ_ID_NONE, \trainer1Id, NULL, \trainer1LoseText, NULL, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE multi_do_fixed MULTI_BATTLE_2_VS_1, \partnerId .endm diff --git a/asm/macros/battle_frontier/frontier_util.inc b/asm/macros/battle_frontier/frontier_util.inc index e40eccb5e7..4913b0fc15 100644 --- a/asm/macros/battle_frontier/frontier_util.inc +++ b/asm/macros/battle_frontier/frontier_util.inc @@ -133,7 +133,7 @@ special CallFrontierUtilFunc .endm - @ Buffer the name of gTrainerBattleOpponent_A in STR_VAR_1 (0) or STR_VAR_2 (1) + @ Buffer the name of gTrainerBattleParameter.params.opponentA in STR_VAR_1 (0) or STR_VAR_2 (1) .macro frontier_gettrainername stringVar:req setvar VAR_0x8004, FRONTIER_UTIL_FUNC_BUFFER_TRAINER_NAME .if \stringVar == STR_VAR_1 diff --git a/asm/macros/event.inc b/asm/macros/event.inc index efc30cabae..01522ab048 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -694,59 +694,31 @@ .byte \direction .endm + NULL = 0 + OBJ_ID_NONE = 0 + @ Configures the arguments for a trainer battle, then jumps to the appropriate script in scripts/trainer_battle.inc - .macro trainerbattle type:req, trainer:req, local_id:req, pointer1:req, pointer2, pointer3, pointer4 + .macro trainerbattle type:req localIdA:req, trainer_a:req, intro_text_a:req, lose_text_a:req, event_script_a:req, localIdB:req, trainer_b:req, intro_text_b:req, lose_text_b:req, event_script_b:req, victory_text:req, cannot_battle:req, isDouble:req, playMusicA:req, playMusicB:req, isRematch:req .byte SCR_OP_TRAINERBATTLE - .byte \type - .2byte \trainer - .2byte \local_id - .if \type == TRAINER_BATTLE_SINGLE - .4byte \pointer1 @ text - .4byte \pointer2 @ text - .elseif \type == TRAINER_BATTLE_CONTINUE_SCRIPT_NO_MUSIC - .4byte \pointer1 @ text - .4byte \pointer2 @ text - .4byte \pointer3 @ event script - .elseif \type == TRAINER_BATTLE_CONTINUE_SCRIPT - .4byte \pointer1 @ text - .4byte \pointer2 @ text - .4byte \pointer3 @ event script - .elseif \type == TRAINER_BATTLE_SINGLE_NO_INTRO_TEXT - .4byte \pointer1 @ text - .elseif \type == TRAINER_BATTLE_DOUBLE - .4byte \pointer1 @ text - .4byte \pointer2 @ text - .4byte \pointer3 @ text - .elseif \type == TRAINER_BATTLE_REMATCH - .4byte \pointer1 @ text - .4byte \pointer2 @ text - .elseif \type == TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE - .4byte \pointer1 @ text - .4byte \pointer2 @ text - .4byte \pointer3 @ text - .4byte \pointer4 @ event script - .elseif \type == TRAINER_BATTLE_REMATCH_DOUBLE - .4byte \pointer1 @ text - .4byte \pointer2 @ text - .4byte \pointer3 @ text - .elseif \type == TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE_NO_MUSIC - .4byte \pointer1 @ text - .4byte \pointer2 @ text - .4byte \pointer3 @ text - .4byte \pointer4 @ event script - .elseif \type == TRAINER_BATTLE_PYRAMID - .4byte \pointer1 @ text - .4byte \pointer2 @ text - .elseif \type == TRAINER_BATTLE_SET_TRAINER_A - .4byte \pointer1 @ text - .4byte \pointer2 @ text - .elseif \type == TRAINER_BATTLE_SET_TRAINER_B - .4byte \pointer1 @ text - .4byte \pointer2 @ text - .elseif \type == TRAINER_BATTLE_HILL - .4byte \pointer1 @ text - .4byte \pointer2 @ text - .endif + .set trainerbattle_flags, 0 + .ifgt \isDouble; .set trainerbattle_flags, trainerbattle_flags | (1 << 0); .endif + .ifgt \isRematch; .set trainerbattle_flags, trainerbattle_flags | (1 << 1); .endif + .ifgt \playMusicA; .set trainerbattle_flags, trainerbattle_flags | (1 << 2); .endif + .ifgt \playMusicB; .set trainerBattle_flags, trainerbattle_flags | (1 << 3); .endif + .ifgt \type; .set trainerbattle_flags, trainerbattle_flags | (\type << 4); .endif + .byte trainerbattle_flags + .byte \localIdA @ objEventLocalIdA + .2byte \trainer_a @ opponentA + .4byte \intro_text_a @ introTextA + .4byte \lose_text_a @ defeatTextA + .4byte \event_script_a @ retAddrA + .byte \localIdB @ objEventLocalIdB + .2byte \trainer_b @ opponentB + .4byte \intro_text_b @ introTextB + .4byte \lose_text_b @ defeatTextB + .4byte \event_script_b @ retAddrB + .4byte \victory_text @ victoryText + .4byte \cannot_battle @ cannotBattle .endm NO_MUSIC = FALSE @@ -755,11 +727,11 @@ @ When used with an event script, you can also pass in an optional flag to disable music .macro trainerbattle_single trainer:req, intro_text:req, lose_text:req, event_script=FALSE, music=TRUE .if \event_script == FALSE - trainerbattle TRAINER_BATTLE_SINGLE, \trainer, 0, \intro_text, \lose_text + trainerbattle TRAINER_BATTLE_SINGLE, OBJ_ID_NONE, \trainer, \intro_text, \lose_text, NULL, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE .elseif \music == TRUE - trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, \trainer, 0, \intro_text, \lose_text, \event_script + trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, OBJ_ID_NONE, \trainer, \intro_text, \lose_text, \event_script, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE .else - trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT_NO_MUSIC, \trainer, 0, \intro_text, \lose_text, \event_script + trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT_NO_MUSIC, OBJ_ID_NONE, \trainer, \intro_text, \lose_text, \event_script, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE .endif .endm @@ -767,38 +739,33 @@ @ and an optional event script. When used with an event script you can pass in an optional flag to disable music .macro trainerbattle_double trainer:req, intro_text:req, lose_text:req, not_enough_pkmn_text:req, event_script=FALSE, music=TRUE .if \event_script == FALSE - trainerbattle TRAINER_BATTLE_DOUBLE, \trainer, 0, \intro_text, \lose_text, \not_enough_pkmn_text + trainerbattle TRAINER_BATTLE_DOUBLE, OBJ_ID_NONE, \trainer, \intro_text, \lose_text, NULL, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, \not_enough_pkmn_text, TRUE, TRUE, FALSE, FALSE .elseif \music == TRUE - trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE, \trainer, 0, \intro_text, \lose_text, \not_enough_pkmn_text, \event_script + trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE, OBJ_ID_NONE, \trainer, \intro_text, \lose_text, \event_script, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, \not_enough_pkmn_text, TRUE, TRUE, FALSE, FALSE .else - trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE_NO_MUSIC, \trainer, 0, \intro_text, \lose_text, \not_enough_pkmn_text, \event_script + trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE_NO_MUSIC, OBJ_ID_NONE, \trainer, \intro_text, \lose_text, \event_script, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, \not_enough_pkmn_text, TRUE, FALSE, FALSE, FALSE .endif .endm @ Starts a rematch battle. Takes a trainer, intro text and loss text .macro trainerbattle_rematch trainer:req, intro_text:req, lose_text:req - trainerbattle TRAINER_BATTLE_REMATCH, \trainer, 0, \intro_text, \lose_text + trainerbattle TRAINER_BATTLE_REMATCH, OBJ_ID_NONE, \trainer, \intro_text, \lose_text, NULL, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, TRUE, FALSE, TRUE .endm @ Starts a rematch double battle. Takes a trainer, intro text, loss text, and text for when you have too few pokemon .macro trainerbattle_rematch_double trainer:req, intro_text:req, lose_text:req, not_enough_pkmn_text:req - trainerbattle TRAINER_BATTLE_REMATCH_DOUBLE, \trainer, 0, \intro_text, \lose_text, \not_enough_pkmn_text + trainerbattle TRAINER_BATTLE_REMATCH_DOUBLE, OBJ_ID_NONE, \trainer, \intro_text, \lose_text, NULL, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, \not_enough_pkmn_text, FALSE, TRUE, FALSE, TRUE .endm @ Starts a trainer battle, skipping intro text. Takes a trainer and loss text .macro trainerbattle_no_intro trainer:req, lose_text:req - trainerbattle TRAINER_BATTLE_SINGLE_NO_INTRO_TEXT, \trainer, 0, \lose_text + trainerbattle TRAINER_BATTLE_SINGLE_NO_INTRO_TEXT, OBJ_ID_NONE, \trainer, NULL, \lose_text, NULL, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE .endm @ Starts a double battle with the player against two trainers @ Takes two trainers and defeat text for each .macro trainerbattle_two_trainers trainer_a:req, lose_text_a:req, trainer_b:req, lose_text_b:req - .byte 0x5c - .byte TRAINER_BATTLE_TWO_TRAINERS_NO_INTRO - .2byte \trainer_a - .4byte \lose_text_a - .2byte \trainer_b - .4byte \lose_text_b + trainerbattle TRAINER_BATTLE_TWO_TRAINERS_NO_INTRO, OBJ_ID_NONE, \trainer_a, NULL, \lose_text_a, NULL, OBJ_ID_NONE, \trainer_b, NULL, \lose_text_b, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE .endm @ Starts a trainer battle using the battle information stored in RAM (usually by the scripts in trainer_battle.inc, which diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 5f9d79dff0..a5c08e7bbe 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -5597,7 +5597,7 @@ BattleScript_LocalBattleLost:: jumpifbattletype BATTLE_TYPE_FRONTIER, BattleScript_LocalBattleLostPrintTrainersWinText jumpifbattletype BATTLE_TYPE_TRAINER_HILL, BattleScript_LocalBattleLostPrintTrainersWinText jumpifbattletype BATTLE_TYPE_EREADER_TRAINER, BattleScript_LocalBattleLostEnd - jumpifhalfword CMP_EQUAL, gTrainerBattleOpponent_A, TRAINER_SECRET_BASE, BattleScript_LocalBattleLostEnd + jumpifhalfword CMP_EQUAL, gTrainerBattleParameter + 2, TRAINER_SECRET_BASE, BattleScript_LocalBattleLostEnd BattleScript_LocalBattleLostPrintWhiteOut:: .if B_WHITEOUT_MONEY >= GEN_4 jumpifbattletype BATTLE_TYPE_TRAINER, BattleScript_LocalBattleLostEnd diff --git a/data/event_scripts.s b/data/event_scripts.s index b6b192f5f6..960a5fa084 100644 --- a/data/event_scripts.s +++ b/data/event_scripts.s @@ -89,7 +89,7 @@ gSpecialVars:: .4byte gSpecialVar_MonBoxId .4byte gSpecialVar_MonBoxPos .4byte gSpecialVar_Unused_0x8014 - .4byte gTrainerBattleOpponent_A + .4byte gTrainerBattleParameter + 2 // gTrainerBattleParameter.params.opponentA .include "data/specials.inc" diff --git a/data/maps/BattleFrontier_BattlePyramidFloor/scripts.inc b/data/maps/BattleFrontier_BattlePyramidFloor/scripts.inc index ba9d996706..2b0ed8b9c4 100644 --- a/data/maps/BattleFrontier_BattlePyramidFloor/scripts.inc +++ b/data/maps/BattleFrontier_BattlePyramidFloor/scripts.inc @@ -105,7 +105,7 @@ BattlePyramid_WarpToTop:: @ TRAINER_PHILLIP is used as a placeholder BattlePyramid_TrainerBattle:: - trainerbattle TRAINER_BATTLE_PYRAMID, TRAINER_PHILLIP, 0, BattleFacility_TrainerBattle_PlaceholderText, BattleFacility_TrainerBattle_PlaceholderText + trainerbattle TRAINER_BATTLE_HILL, OBJ_ID_NONE, TRAINER_PHILLIP, BattleFacility_TrainerBattle_PlaceholderText, BattleFacility_TrainerBattle_PlaceholderText, NULL, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE pyramid_showhint waitmessage waitbuttonpress diff --git a/data/maps/LavaridgeTown_Gym_1F/scripts.inc b/data/maps/LavaridgeTown_Gym_1F/scripts.inc index b7db13f54a..e211d08063 100644 --- a/data/maps/LavaridgeTown_Gym_1F/scripts.inc +++ b/data/maps/LavaridgeTown_Gym_1F/scripts.inc @@ -104,7 +104,7 @@ LavaridgeTown_Gym_1F_EventScript_FlanneryRematch:: end LavaridgeTown_Gym_1F_EventScript_Cole:: - trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, TRAINER_COLE, LOCALID_COLE, LavaridgeTown_Gym_1F_Text_ColeIntro, LavaridgeTown_Gym_1F_Text_ColeDefeat, LavaridgeTown_Gym_EventScript_CheckTrainerScript + trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, LOCALID_COLE, TRAINER_COLE, LavaridgeTown_Gym_1F_Text_ColeIntro, LavaridgeTown_Gym_1F_Text_ColeDefeat, LavaridgeTown_Gym_EventScript_CheckTrainerScript, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE msgbox LavaridgeTown_Gym_1F_Text_ColePostBattle, MSGBOX_AUTOCLOSE end @@ -116,37 +116,37 @@ LavaridgeTown_Gym_EventScript_CheckTrainerScript:: end LavaridgeTown_Gym_1F_EventScript_Axle:: - trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, TRAINER_AXLE, LOCALID_AXLE, LavaridgeTown_Gym_1F_Text_AxleIntro, LavaridgeTown_Gym_1F_Text_AxleDefeat, LavaridgeTown_Gym_EventScript_CheckTrainerScript + trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, LOCALID_AXLE, TRAINER_AXLE, LavaridgeTown_Gym_1F_Text_AxleIntro, LavaridgeTown_Gym_1F_Text_AxleDefeat, LavaridgeTown_Gym_EventScript_CheckTrainerScript, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE msgbox LavaridgeTown_Gym_1F_Text_AxlePostBattle, MSGBOX_AUTOCLOSE end LavaridgeTown_Gym_B1F_EventScript_Keegan:: - trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, TRAINER_KEEGAN, LOCALID_KEEGAN, LavaridgeTown_Gym_B1F_Text_KeeganIntro, LavaridgeTown_Gym_B1F_Text_KeeganDefeat, LavaridgeTown_Gym_EventScript_CheckTrainerScript + trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, LOCALID_KEEGAN, TRAINER_KEEGAN, LavaridgeTown_Gym_B1F_Text_KeeganIntro, LavaridgeTown_Gym_B1F_Text_KeeganDefeat, LavaridgeTown_Gym_EventScript_CheckTrainerScript, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE msgbox LavaridgeTown_Gym_B1F_Text_KeeganPostBattle, MSGBOX_AUTOCLOSE end LavaridgeTown_Gym_1F_EventScript_Danielle:: - trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, TRAINER_DANIELLE, LOCALID_DANIELLE, LavaridgeTown_Gym_1F_Text_DanielleIntro, LavaridgeTown_Gym_1F_Text_DanielleDefeat, LavaridgeTown_Gym_EventScript_CheckTrainerScript + trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, LOCALID_DANIELLE, TRAINER_DANIELLE, LavaridgeTown_Gym_1F_Text_DanielleIntro, LavaridgeTown_Gym_1F_Text_DanielleDefeat, LavaridgeTown_Gym_EventScript_CheckTrainerScript, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE msgbox LavaridgeTown_Gym_1F_Text_DaniellePostBattle, MSGBOX_AUTOCLOSE end LavaridgeTown_Gym_1F_EventScript_Gerald:: - trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, TRAINER_GERALD, LOCALID_GERALD, LavaridgeTown_Gym_1F_Text_GeraldIntro, LavaridgeTown_Gym_1F_Text_GeraldDefeat, LavaridgeTown_Gym_EventScript_CheckTrainerScript + trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, LOCALID_GERALD, TRAINER_GERALD, LavaridgeTown_Gym_1F_Text_GeraldIntro, LavaridgeTown_Gym_1F_Text_GeraldDefeat, LavaridgeTown_Gym_EventScript_CheckTrainerScript, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE msgbox LavaridgeTown_Gym_1F_Text_GeraldPostBattle, MSGBOX_AUTOCLOSE end LavaridgeTown_Gym_B1F_EventScript_Jace:: - trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, TRAINER_JACE, LOCALID_JACE, LavaridgeTown_Gym_B1F_Text_JaceIntro, LavaridgeTown_Gym_B1F_Text_JaceDefeat, LavaridgeTown_Gym_EventScript_CheckTrainerScript + trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, LOCALID_JACE, TRAINER_JACE, LavaridgeTown_Gym_B1F_Text_JaceIntro, LavaridgeTown_Gym_B1F_Text_JaceDefeat, LavaridgeTown_Gym_EventScript_CheckTrainerScript, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE msgbox LavaridgeTown_Gym_B1F_Text_JacePostBattle, MSGBOX_AUTOCLOSE end LavaridgeTown_Gym_B1F_EventScript_Jeff:: - trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, TRAINER_JEFF, LOCALID_JEFF, LavaridgeTown_Gym_B1F_Text_JeffIntro, LavaridgeTown_Gym_B1F_Text_JeffDefeat, LavaridgeTown_Gym_EventScript_CheckTrainerScript + trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, LOCALID_JEFF, TRAINER_JEFF, LavaridgeTown_Gym_B1F_Text_JeffIntro, LavaridgeTown_Gym_B1F_Text_JeffDefeat, LavaridgeTown_Gym_EventScript_CheckTrainerScript, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE msgbox LavaridgeTown_Gym_B1F_Text_JeffPostBattle, MSGBOX_AUTOCLOSE end LavaridgeTown_Gym_B1F_EventScript_Eli:: - trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, TRAINER_ELI, LOCALID_ELI, LavaridgeTown_Gym_B1F_Text_EliIntro, LavaridgeTown_Gym_B1F_Text_EliDefeat, LavaridgeTown_Gym_EventScript_CheckTrainerScript + trainerbattle TRAINER_BATTLE_CONTINUE_SCRIPT, LOCALID_ELI, TRAINER_ELI, LavaridgeTown_Gym_B1F_Text_EliIntro, LavaridgeTown_Gym_B1F_Text_EliDefeat, LavaridgeTown_Gym_EventScript_CheckTrainerScript, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE msgbox LavaridgeTown_Gym_B1F_Text_EliPostBattle, MSGBOX_AUTOCLOSE end diff --git a/data/scripts/trainer_hill.inc b/data/scripts/trainer_hill.inc index 04bbe05e5a..877b48c3db 100644 --- a/data/scripts/trainer_hill.inc +++ b/data/scripts/trainer_hill.inc @@ -60,7 +60,7 @@ TrainerHill_1F_Movement_SetInvisible:: @ TRAINER_PHILLIP is an actual Trainer on the SS Tidal, but is used as a placeholder here TrainerHill_EventScript_TrainerBattle:: - trainerbattle TRAINER_BATTLE_HILL, TRAINER_PHILLIP, 0, BattleFacility_TrainerBattle_PlaceholderText, BattleFacility_TrainerBattle_PlaceholderText + trainerbattle TRAINER_BATTLE_HILL, OBJ_ID_NONE, TRAINER_PHILLIP, BattleFacility_TrainerBattle_PlaceholderText, BattleFacility_TrainerBattle_PlaceholderText, NULL, OBJ_ID_NONE, TRAINER_NONE, NULL, NULL, NULL, NULL, NULL, FALSE, FALSE, FALSE, FALSE trainerhill_postbattletext waitmessage waitbuttonpress diff --git a/include/battle_setup.h b/include/battle_setup.h index a2009eea41..f8eda0d8dc 100644 --- a/include/battle_setup.h +++ b/include/battle_setup.h @@ -12,12 +12,43 @@ struct RematchTrainer u16 mapNum; }; +/* +the layout of the first byte can be confusing here +isDoubleBattle is the least lsb. msb is in the mode. +*/ +typedef union PACKED TrainerBattleParameter +{ + struct PACKED _TrainerBattleParameter + { + u8 isDoubleBattle:1; + u8 isRematch:1; + u8 playMusicA:1; + u8 playMusicB:1; + u8 mode:4; + u8 objEventLocalIdA; + u16 opponentA; + u8 *introTextA; + u8 *defeatTextA; + u8 *battleScriptRetAddrA; + u8 objEventLocalIdB; + u16 opponentB; + u8 *introTextB; + u8 *defeatTextB; + u8 *battleScriptRetAddrB; + u8 *victoryText; + u8 *cannotBattleText; + } params; + u8 data[sizeof(struct _TrainerBattleParameter)]; +} TrainerBattleParameter; + + extern const struct RematchTrainer gRematchTable[REMATCH_TABLE_ENTRIES]; -extern u16 gTrainerBattleOpponent_A; -extern u16 gTrainerBattleOpponent_B; +extern TrainerBattleParameter gTrainerBattleParameter; extern u16 gPartnerTrainerId; +#define TRAINER_BATTLE_PARAM gTrainerBattleParameter.params + void BattleSetup_StartWildBattle(void); void BattleSetup_StartDoubleWildBattle(void); void BattleSetup_StartBattlePikeWildBattle(void); @@ -35,7 +66,8 @@ u8 GetTrainerBattleTransition(void); u8 GetSpecialBattleTransition(s32 id); void ChooseStarter(void); void ResetTrainerOpponentIds(void); -void SetMapVarsToTrainer(void); +void SetMapVarsToTrainerA(void); +void SetMapVarsToTrainerB(void); const u8 *BattleSetup_ConfigureTrainerBattle(const u8 *data); void ConfigureAndSetUpOneTrainerBattle(u8 trainerObjEventId, const u8 *trainerScript); void ConfigureTwoTrainersBattle(u8 trainerObjEventId, const u8 *trainerScript); @@ -67,6 +99,10 @@ bool8 ShouldTryRematchBattle(void); bool8 IsTrainerReadyForRematch(void); void ShouldTryGetTrainerScript(void); u16 CountBattledRematchTeams(u16 trainerId); +void TrainerBattleLoadArgs(const u8 *data); +void TrainerBattleLoadArgsTrainerA(const u8 *data); +void TrainerBattleLoadArgsTrainerB(const u8 *data); +void TrainerBattleLoadArgsSecondTrainer(const u8 *data); void DoStandardWildBattle_Debug(void); void BattleSetup_StartTrainerBattle_Debug(void); diff --git a/include/constants/battle.h b/include/constants/battle.h index b361e90060..7f09e7f89b 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -86,7 +86,7 @@ #define WILD_DOUBLE_BATTLE ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE && !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_TRAINER)))) #define RECORDED_WILD_BATTLE ((gBattleTypeFlags & BATTLE_TYPE_RECORDED) && !(gBattleTypeFlags & (BATTLE_TYPE_TRAINER | BATTLE_TYPE_FRONTIER))) -#define BATTLE_TWO_VS_ONE_OPPONENT ((gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gTrainerBattleOpponent_B == 0xFFFF)) +#define BATTLE_TWO_VS_ONE_OPPONENT ((gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && TRAINER_BATTLE_PARAM.opponentB == 0xFFFF)) #define BATTLE_TYPE_HAS_AI (BATTLE_TYPE_TRAINER | BATTLE_TYPE_FIRST_BATTLE | BATTLE_TYPE_SAFARI | BATTLE_TYPE_ROAMER | BATTLE_TYPE_INGAME_PARTNER) // Battle Outcome defines diff --git a/include/constants/battle_setup.h b/include/constants/battle_setup.h index bb7f9adefa..91c89d0631 100644 --- a/include/constants/battle_setup.h +++ b/include/constants/battle_setup.h @@ -11,8 +11,7 @@ #define TRAINER_BATTLE_REMATCH_DOUBLE 7 #define TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE_NO_MUSIC 8 #define TRAINER_BATTLE_PYRAMID 9 -#define TRAINER_BATTLE_SET_TRAINER_A 10 -#define TRAINER_BATTLE_SET_TRAINER_B 11 +#define TRAINER_BATTLE_SET_TRAINERS_FOR_MULTI_BATTLE 10 #define TRAINER_BATTLE_HILL 12 #define TRAINER_BATTLE_TWO_TRAINERS_NO_INTRO 13 diff --git a/include/constants/vars.h b/include/constants/vars.h index 1b71134593..5ce02c1467 100644 --- a/include/constants/vars.h +++ b/include/constants/vars.h @@ -301,7 +301,7 @@ #define VAR_MON_BOX_ID 0x8012 #define VAR_MON_BOX_POS 0x8013 #define VAR_UNUSED_0x8014 0x8014 -#define VAR_TRAINER_BATTLE_OPPONENT_A 0x8015 // Alias of gTrainerBattleOpponent_A +#define VAR_TRAINER_BATTLE_OPPONENT_A 0x8015 // Alias of TRAINER_BATTLE_PARAM.opponentA #define SPECIAL_VARS_END 0x8015 diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index 7393617058..d40cf2968f 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -101,7 +101,7 @@ void BattleAI_SetupItems(void) { s32 i; u8 *data = (u8 *)BATTLE_HISTORY; - const u16 *items = GetTrainerItemsFromId(gTrainerBattleOpponent_A); + const u16 *items = GetTrainerItemsFromId(TRAINER_BATTLE_PARAM.opponentA); for (i = 0; i < sizeof(struct BattleHistory); i++) data[i] = 0; @@ -216,9 +216,9 @@ void BattleAI_SetupFlags(void) } else { - AI_THINKING_STRUCT->aiFlags[B_POSITION_OPPONENT_LEFT] = GetAiFlags(gTrainerBattleOpponent_A); - if (gTrainerBattleOpponent_B != 0) - AI_THINKING_STRUCT->aiFlags[B_POSITION_OPPONENT_RIGHT] = GetAiFlags(gTrainerBattleOpponent_B); + AI_THINKING_STRUCT->aiFlags[B_POSITION_OPPONENT_LEFT] = GetAiFlags(TRAINER_BATTLE_PARAM.opponentA); + if (TRAINER_BATTLE_PARAM.opponentB != 0) + AI_THINKING_STRUCT->aiFlags[B_POSITION_OPPONENT_RIGHT] = GetAiFlags(TRAINER_BATTLE_PARAM.opponentB); else AI_THINKING_STRUCT->aiFlags[B_POSITION_OPPONENT_RIGHT] = AI_THINKING_STRUCT->aiFlags[B_POSITION_OPPONENT_LEFT]; } diff --git a/src/battle_arena.c b/src/battle_arena.c index dd0f0c1bbd..d79602156f 100644 --- a/src/battle_arena.c +++ b/src/battle_arena.c @@ -472,7 +472,7 @@ static void InitArenaChallenge(void) gSaveBlock2Ptr->frontier.arenaWinStreaks[lvlMode] = 0; SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE); - gTrainerBattleOpponent_A = 0; + TRAINER_BATTLE_PARAM.opponentA = 0; } static void GetArenaData(void) @@ -562,7 +562,7 @@ static void GiveArenaPrize(void) static void BufferArenaOpponentName(void) { - GetFrontierTrainerName(gStringVar1, gTrainerBattleOpponent_A); + GetFrontierTrainerName(gStringVar1, TRAINER_BATTLE_PARAM.opponentA); } void DrawArenaRefereeTextBox(void) diff --git a/src/battle_bg.c b/src/battle_bg.c index 328f990653..24f2a55e8d 100644 --- a/src/battle_bg.c +++ b/src/battle_bg.c @@ -806,7 +806,7 @@ void DrawMainBattleBackground(void) { if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) { - u32 trainerClass = GetTrainerClassFromId(gTrainerBattleOpponent_A); + u32 trainerClass = GetTrainerClassFromId(TRAINER_BATTLE_PARAM.opponentA); if (trainerClass == TRAINER_CLASS_LEADER) { LZDecompressVram(gBattleTerrainTiles_Building, (void *)(BG_CHAR_ADDR(2))); @@ -1207,7 +1207,7 @@ void DrawBattleEntryBackground(void) { if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) { - u32 trainerClass = GetTrainerClassFromId(gTrainerBattleOpponent_A); + u32 trainerClass = GetTrainerClassFromId(TRAINER_BATTLE_PARAM.opponentA); if (trainerClass == TRAINER_CLASS_LEADER) { LZDecompressVram(gBattleTerrainAnimTiles_Building, (void *)(BG_CHAR_ADDR(1))); @@ -1272,7 +1272,7 @@ bool8 LoadChosenBattleElement(u8 caseId) { if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) { - u32 trainerClass = GetTrainerClassFromId(gTrainerBattleOpponent_A); + u32 trainerClass = GetTrainerClassFromId(TRAINER_BATTLE_PARAM.opponentA); if (trainerClass == TRAINER_CLASS_LEADER) { LZDecompressVram(gBattleTerrainTiles_Building, (void *)(BG_CHAR_ADDR(2))); @@ -1334,7 +1334,7 @@ bool8 LoadChosenBattleElement(u8 caseId) { if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) { - u32 trainerClass = GetTrainerClassFromId(gTrainerBattleOpponent_A); + u32 trainerClass = GetTrainerClassFromId(TRAINER_BATTLE_PARAM.opponentA); if (trainerClass == TRAINER_CLASS_LEADER) { LZDecompressVram(gBattleTerrainTilemap_Building, (void *)(BG_SCREEN_ADDR(26))); @@ -1396,7 +1396,7 @@ bool8 LoadChosenBattleElement(u8 caseId) { if (gBattleTypeFlags & BATTLE_TYPE_TRAINER) { - u32 trainerClass = GetTrainerClassFromId(gTrainerBattleOpponent_A); + u32 trainerClass = GetTrainerClassFromId(TRAINER_BATTLE_PARAM.opponentA); if (trainerClass == TRAINER_CLASS_LEADER) { LoadCompressedPalette(gBattleTerrainPalette_BuildingLeader, BG_PLTT_ID(2), 3 * PLTT_SIZE_4BPP); diff --git a/src/battle_controller_link_opponent.c b/src/battle_controller_link_opponent.c index c437a687bd..1e4bf628db 100644 --- a/src/battle_controller_link_opponent.c +++ b/src/battle_controller_link_opponent.c @@ -401,9 +401,9 @@ static void LinkOpponentHandleDrawTrainerPic(u32 battler) if (gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER) { if (battler == B_POSITION_OPPONENT_LEFT) - trainerPicId = GetFrontierTrainerFrontSpriteId(gTrainerBattleOpponent_A); + trainerPicId = GetFrontierTrainerFrontSpriteId(TRAINER_BATTLE_PARAM.opponentA); else - trainerPicId = GetFrontierTrainerFrontSpriteId(gTrainerBattleOpponent_B); + trainerPicId = GetFrontierTrainerFrontSpriteId(TRAINER_BATTLE_PARAM.opponentB); } else { @@ -432,7 +432,7 @@ static void LinkOpponentHandleDrawTrainerPic(u32 battler) else { xPos = 176; - if (gTrainerBattleOpponent_A == TRAINER_UNION_ROOM) + if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_UNION_ROOM) { trainerPicId = GetUnionRoomTrainerPic(); } @@ -466,9 +466,9 @@ static void LinkOpponentHandleTrainerSlide(u32 battler) u32 trainerPicId; if (battler == B_POSITION_OPPONENT_LEFT) - trainerPicId = GetFrontierTrainerFrontSpriteId(gTrainerBattleOpponent_A); + trainerPicId = GetFrontierTrainerFrontSpriteId(TRAINER_BATTLE_PARAM.opponentA); else - trainerPicId = GetFrontierTrainerFrontSpriteId(gTrainerBattleOpponent_B); + trainerPicId = GetFrontierTrainerFrontSpriteId(TRAINER_BATTLE_PARAM.opponentB); BtlController_HandleTrainerSlide(battler, trainerPicId); LinkOpponentBufferExecCompleted(battler); // Possibly a bug, because execution should be completed after the slide in finishes. See Controller_WaitForTrainerPic. diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index e87ee1a28d..adeae79652 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -432,7 +432,7 @@ static u32 OpponentGetTrainerPicId(u32 battlerId) { trainerPicId = GetSecretBaseTrainerPicIndex(); } - else if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) + else if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_FRONTIER_BRAIN) { trainerPicId = GetFrontierBrainTrainerPicIndex(); } @@ -441,13 +441,13 @@ static u32 OpponentGetTrainerPicId(u32 battlerId) if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) { if (battlerId == 1) - trainerPicId = GetTrainerHillTrainerFrontSpriteId(gTrainerBattleOpponent_A); + trainerPicId = GetTrainerHillTrainerFrontSpriteId(TRAINER_BATTLE_PARAM.opponentA); else - trainerPicId = GetTrainerHillTrainerFrontSpriteId(gTrainerBattleOpponent_B); + trainerPicId = GetTrainerHillTrainerFrontSpriteId(TRAINER_BATTLE_PARAM.opponentB); } else { - trainerPicId = GetTrainerHillTrainerFrontSpriteId(gTrainerBattleOpponent_A); + trainerPicId = GetTrainerHillTrainerFrontSpriteId(TRAINER_BATTLE_PARAM.opponentA); } } else if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER) @@ -455,13 +455,13 @@ static u32 OpponentGetTrainerPicId(u32 battlerId) if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_TOWER_LINK_MULTI)) { if (battlerId == 1) - trainerPicId = GetFrontierTrainerFrontSpriteId(gTrainerBattleOpponent_A); + trainerPicId = GetFrontierTrainerFrontSpriteId(TRAINER_BATTLE_PARAM.opponentA); else - trainerPicId = GetFrontierTrainerFrontSpriteId(gTrainerBattleOpponent_B); + trainerPicId = GetFrontierTrainerFrontSpriteId(TRAINER_BATTLE_PARAM.opponentB); } else { - trainerPicId = GetFrontierTrainerFrontSpriteId(gTrainerBattleOpponent_A); + trainerPicId = GetFrontierTrainerFrontSpriteId(TRAINER_BATTLE_PARAM.opponentA); } } else if (gBattleTypeFlags & BATTLE_TYPE_EREADER_TRAINER) @@ -471,13 +471,13 @@ static u32 OpponentGetTrainerPicId(u32 battlerId) else if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) { if (battlerId != 1) - trainerPicId = GetTrainerPicFromId(gTrainerBattleOpponent_B); + trainerPicId = GetTrainerPicFromId(TRAINER_BATTLE_PARAM.opponentB); else - trainerPicId = GetTrainerPicFromId(gTrainerBattleOpponent_A); + trainerPicId = GetTrainerPicFromId(TRAINER_BATTLE_PARAM.opponentA); } else { - trainerPicId = GetTrainerPicFromId(gTrainerBattleOpponent_A); + trainerPicId = GetTrainerPicFromId(TRAINER_BATTLE_PARAM.opponentA); } return trainerPicId; diff --git a/src/battle_controller_recorded_opponent.c b/src/battle_controller_recorded_opponent.c index af77dc11fc..38d2e0ea02 100644 --- a/src/battle_controller_recorded_opponent.c +++ b/src/battle_controller_recorded_opponent.c @@ -409,9 +409,9 @@ static void RecordedOpponentHandleDrawTrainerPic(u32 battler) if (gBattleTypeFlags & BATTLE_TYPE_BATTLE_TOWER) { if (battler == B_POSITION_OPPONENT_LEFT) - trainerPicId = GetFrontierTrainerFrontSpriteId(gTrainerBattleOpponent_A); + trainerPicId = GetFrontierTrainerFrontSpriteId(TRAINER_BATTLE_PARAM.opponentA); else - trainerPicId = GetFrontierTrainerFrontSpriteId(gTrainerBattleOpponent_B); + trainerPicId = GetFrontierTrainerFrontSpriteId(TRAINER_BATTLE_PARAM.opponentB); } else { @@ -421,7 +421,7 @@ static void RecordedOpponentHandleDrawTrainerPic(u32 battler) else { xPos = 176; - if (gTrainerBattleOpponent_A == TRAINER_UNION_ROOM) + if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_UNION_ROOM) { trainerPicId = GetUnionRoomTrainerPic(); } diff --git a/src/battle_dome.c b/src/battle_dome.c index 19c5086523..d374843573 100644 --- a/src/battle_dome.c +++ b/src/battle_dome.c @@ -1782,7 +1782,7 @@ static void InitDomeChallenge(void) gSaveBlock2Ptr->frontier.domeWinStreaks[battleMode][lvlMode] = 0; SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE); - gTrainerBattleOpponent_A = 0; + TRAINER_BATTLE_PARAM.opponentA = 0; } static void GetDomeData(void) @@ -2182,13 +2182,13 @@ static void BufferDomeRoundText(void) static void BufferDomeOpponentName(void) { StringCopy(gStringVar1, gRoundsStringTable[gSaveBlock2Ptr->frontier.curChallengeBattleNum]); - CopyDomeTrainerName(gStringVar2, gTrainerBattleOpponent_A); + CopyDomeTrainerName(gStringVar2, TRAINER_BATTLE_PARAM.opponentA); } static void InitDomeOpponentParty(void) { CalculatePlayerPartyCount(); - CreateDomeOpponentMons(TrainerIdToTournamentId(gTrainerBattleOpponent_A)); + CreateDomeOpponentMons(TrainerIdToTournamentId(TRAINER_BATTLE_PARAM.opponentA)); } static void CreateDomeOpponentMon(u8 monPartyId, u16 tournamentTrainerId, u8 tournamentMonId, u32 otId) @@ -2577,7 +2577,7 @@ static int TournamentIdOfOpponent(int roundId, int trainerId) static void SetDomeOpponentId(void) { - gTrainerBattleOpponent_A = TrainerIdOfPlayerOpponent(); + TRAINER_BATTLE_PARAM.opponentA = TrainerIdOfPlayerOpponent(); } // While not an issue in-game, this will overflow if called after the player's opponent for the current round has been eliminated @@ -2588,7 +2588,7 @@ static u16 TrainerIdOfPlayerOpponent(void) static void SetDomeOpponentGraphicsId(void) { - SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); + SetBattleFacilityTrainerGfxId(TRAINER_BATTLE_PARAM.opponentA, 0); } static void SaveDomeChallenge(void) @@ -5063,9 +5063,9 @@ static void ResolveDomeRoundWinners(void) if (gSpecialVar_0x8005 == DOME_PLAYER_WON_MATCH) { - DOME_TRAINERS[TrainerIdToTournamentId(gTrainerBattleOpponent_A)].isEliminated = TRUE; - DOME_TRAINERS[TrainerIdToTournamentId(gTrainerBattleOpponent_A)].eliminatedAt = gSaveBlock2Ptr->frontier.curChallengeBattleNum; - gSaveBlock2Ptr->frontier.domeWinningMoves[TrainerIdToTournamentId(gTrainerBattleOpponent_A)] = gBattleResults.lastUsedMovePlayer; + DOME_TRAINERS[TrainerIdToTournamentId(TRAINER_BATTLE_PARAM.opponentA)].isEliminated = TRUE; + DOME_TRAINERS[TrainerIdToTournamentId(TRAINER_BATTLE_PARAM.opponentA)].eliminatedAt = gSaveBlock2Ptr->frontier.curChallengeBattleNum; + gSaveBlock2Ptr->frontier.domeWinningMoves[TrainerIdToTournamentId(TRAINER_BATTLE_PARAM.opponentA)] = gBattleResults.lastUsedMovePlayer; // If the player's match was the final one, no NPC vs NPC matches to decide if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < DOME_FINAL) @@ -5693,7 +5693,7 @@ static void ReduceDomePlayerPartyToSelectedMons(void) static void GetPlayerSeededBeforeOpponent(void) { // A higher tournament ID is a worse seed - if (TrainerIdToTournamentId(gTrainerBattleOpponent_A) > TrainerIdToTournamentId(TRAINER_PLAYER)) + if (TrainerIdToTournamentId(TRAINER_BATTLE_PARAM.opponentA) > TrainerIdToTournamentId(TRAINER_PLAYER)) gSpecialVar_Result = 1; else gSpecialVar_Result = 2; diff --git a/src/battle_factory.c b/src/battle_factory.c index 8edd9a2ddf..4ae2310c17 100644 --- a/src/battle_factory.c +++ b/src/battle_factory.c @@ -218,7 +218,7 @@ static void InitFactoryChallenge(void) gFrontierTempParty[i] = 0xFFFF; SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE); - gTrainerBattleOpponent_A = 0; + TRAINER_BATTLE_PARAM.opponentA = 0; } static void GetBattleFactoryData(void) @@ -325,7 +325,7 @@ static void GenerateOpponentMons(void) } } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum); - gTrainerBattleOpponent_A = trainerId; + TRAINER_BATTLE_PARAM.opponentA = trainerId; if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < FRONTIER_STAGES_PER_CHALLENGE - 1) gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = trainerId; @@ -379,7 +379,7 @@ static void GenerateOpponentMons(void) static void SetOpponentGfxVar(void) { - SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); + SetBattleFacilityTrainerGfxId(TRAINER_BATTLE_PARAM.opponentA, 0); } static void SetRentalsToOpponentParty(void) @@ -830,7 +830,7 @@ u32 GetAiScriptsInBattleFactory(void) int battleMode = VarGet(VAR_FRONTIER_BATTLE_MODE); int challengeNum = gSaveBlock2Ptr->frontier.factoryWinStreaks[battleMode][lvlMode] / FRONTIER_STAGES_PER_CHALLENGE; - if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) + if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_FRONTIER_BRAIN) return AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_CHECK_VIABILITY; else if (challengeNum < 2) return 0; diff --git a/src/battle_gimmick.c b/src/battle_gimmick.c index 057619aec1..540b1af1f1 100644 --- a/src/battle_gimmick.c +++ b/src/battle_gimmick.c @@ -80,7 +80,7 @@ bool32 ShouldTrainerBattlerUseGimmick(u32 battler, enum Gimmick gimmick) else { bool32 isSecondTrainer = (GetBattlerPosition(battler) == B_POSITION_OPPONENT_RIGHT) && (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) && !BATTLE_TWO_VS_ONE_OPPONENT; - u16 trainerId = isSecondTrainer ? gTrainerBattleOpponent_B : gTrainerBattleOpponent_A; + u16 trainerId = isSecondTrainer ? TRAINER_BATTLE_PARAM.opponentB : TRAINER_BATTLE_PARAM.opponentA; const struct TrainerMon *mon = &GetTrainerPartyFromId(trainerId)[isSecondTrainer ? gBattlerPartyIndexes[battler] - MULTI_PARTY_SIZE : gBattlerPartyIndexes[battler]]; if (gimmick == GIMMICK_TERA && mon->teraType != TYPE_NONE) diff --git a/src/battle_main.c b/src/battle_main.c index 22d2cc32cf..d89c4cae65 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -515,7 +515,7 @@ static void CB2_InitBattleInternal(void) | BATTLE_TYPE_EREADER_TRAINER | BATTLE_TYPE_TRAINER_HILL))) { - gBattleTypeFlags |= (IsTrainerDoubleBattle(gTrainerBattleOpponent_A) ? BATTLE_TYPE_DOUBLE : 0); + gBattleTypeFlags |= (IsTrainerDoubleBattle(TRAINER_BATTLE_PARAM.opponentA) ? BATTLE_TYPE_DOUBLE : 0); } InitBattleBgsVideo(); @@ -542,9 +542,9 @@ static void CB2_InitBattleInternal(void) { if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED))) { - CreateNPCTrainerParty(&gEnemyParty[0], gTrainerBattleOpponent_A, TRUE); + CreateNPCTrainerParty(&gEnemyParty[0], TRAINER_BATTLE_PARAM.opponentA, TRUE); if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && !BATTLE_TWO_VS_ONE_OPPONENT) - CreateNPCTrainerParty(&gEnemyParty[PARTY_SIZE / 2], gTrainerBattleOpponent_B, FALSE); + CreateNPCTrainerParty(&gEnemyParty[PARTY_SIZE / 2], TRAINER_BATTLE_PARAM.opponentB, FALSE); SetWildMonHeldItem(); CalculateEnemyPartyCount(); } @@ -851,7 +851,7 @@ static void CB2_HandleStartBattle(void) BufferPartyVsScreenHealth_AtStart(); SetPlayerBerryDataInBattleStruct(); - if (gTrainerBattleOpponent_A == TRAINER_UNION_ROOM) + if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_UNION_ROOM) { gLinkPlayers[0].id = 0; gLinkPlayers[1].id = 1; @@ -1056,11 +1056,11 @@ static void CB2_HandleStartMultiPartnerBattle(void) gLinkPlayers[1].id = 2; gLinkPlayers[2].id = 1; gLinkPlayers[3].id = 3; - GetFrontierTrainerName(gLinkPlayers[2].name, gTrainerBattleOpponent_A); - GetFrontierTrainerName(gLinkPlayers[3].name, gTrainerBattleOpponent_B); - GetBattleTowerTrainerLanguage(&language, gTrainerBattleOpponent_A); + GetFrontierTrainerName(gLinkPlayers[2].name, TRAINER_BATTLE_PARAM.opponentA); + GetFrontierTrainerName(gLinkPlayers[3].name, TRAINER_BATTLE_PARAM.opponentB); + GetBattleTowerTrainerLanguage(&language, TRAINER_BATTLE_PARAM.opponentA); gLinkPlayers[2].language = language; - GetBattleTowerTrainerLanguage(&language, gTrainerBattleOpponent_B); + GetBattleTowerTrainerLanguage(&language, TRAINER_BATTLE_PARAM.opponentB); gLinkPlayers[3].language = language; if (IsLinkTaskFinished()) @@ -1711,7 +1711,7 @@ static void CB2_HandleStartMultiBattle(void) SetMainCallback2(BattleMainCB2); if (gBattleTypeFlags & BATTLE_TYPE_LINK) { - gTrainerBattleOpponent_A = TRAINER_LINK_OPPONENT; + TRAINER_BATTLE_PARAM.opponentA = TRAINER_LINK_OPPONENT; gBattleTypeFlags |= BATTLE_TYPE_LINK_IN_BATTLE; } } @@ -3719,14 +3719,14 @@ static void DoBattleIntro(void) // Try to set a status to start the battle with gBattleStruct->startingStatus = 0; - if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && GetTrainerStartingStatusFromId(gTrainerBattleOpponent_B)) + if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && GetTrainerStartingStatusFromId(TRAINER_BATTLE_PARAM.opponentB)) { - gBattleStruct->startingStatus = GetTrainerStartingStatusFromId(gTrainerBattleOpponent_B); + gBattleStruct->startingStatus = GetTrainerStartingStatusFromId(TRAINER_BATTLE_PARAM.opponentB); gBattleStruct->startingStatusTimer = 0; // infinite } - else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && GetTrainerStartingStatusFromId(gTrainerBattleOpponent_A)) + else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && GetTrainerStartingStatusFromId(TRAINER_BATTLE_PARAM.opponentA)) { - gBattleStruct->startingStatus = GetTrainerStartingStatusFromId(gTrainerBattleOpponent_A); + gBattleStruct->startingStatus = GetTrainerStartingStatusFromId(TRAINER_BATTLE_PARAM.opponentA); gBattleStruct->startingStatusTimer = 0; // infinite } else if (B_VAR_STARTING_STATUS != 0) @@ -5406,7 +5406,7 @@ static void HandleEndTurn_BattleWon(void) BattleStopLowHpSound(); gBattlescriptCurrInstr = BattleScript_FrontierTrainerBattleWon; - if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) + if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_FRONTIER_BRAIN) PlayBGM(MUS_VICTORY_GYM_LEADER); else PlayBGM(MUS_VICTORY_TRAINER); @@ -5416,7 +5416,7 @@ static void HandleEndTurn_BattleWon(void) BattleStopLowHpSound(); gBattlescriptCurrInstr = BattleScript_LocalTrainerBattleWon; - switch (GetTrainerClassFromId(gTrainerBattleOpponent_A)) + switch (GetTrainerClassFromId(TRAINER_BATTLE_PARAM.opponentA)) { case TRAINER_CLASS_ELITE_FOUR: case TRAINER_CLASS_CHAMPION: diff --git a/src/battle_message.c b/src/battle_message.c index e06aac8d7f..1538aec1c9 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -2099,7 +2099,7 @@ void BufferStringBattle(u16 stringID, u32 battler) } else { - if (gTrainerBattleOpponent_A == TRAINER_UNION_ROOM) + if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_UNION_ROOM) stringPtr = sText_Trainer1WantsToBattle; else if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) stringPtr = sText_LinkTrainerWantsToBattlePause; @@ -2171,7 +2171,7 @@ void BufferStringBattle(u16 stringID, u32 battler) { if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED_LINK))) stringPtr = sText_Trainer1SentOutPkmn; - else if (gTrainerBattleOpponent_A == TRAINER_UNION_ROOM) + else if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_UNION_ROOM) stringPtr = sText_Trainer1SentOutPkmn; else stringPtr = sText_LinkTrainerSentOutPkmn; @@ -2192,7 +2192,7 @@ void BufferStringBattle(u16 stringID, u32 battler) } else { - if (gTrainerBattleOpponent_A == TRAINER_LINK_OPPONENT || gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK) + if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_LINK_OPPONENT || gBattleTypeFlags & BATTLE_TYPE_RECORDED_LINK) { if (gBattleTypeFlags & BATTLE_TYPE_MULTI) stringPtr = sText_LinkTrainer2WithdrewPkmn; @@ -2232,7 +2232,7 @@ void BufferStringBattle(u16 stringID, u32 battler) { if (gBattleTypeFlags & BATTLE_TYPE_MULTI) stringPtr = sText_LinkTrainerMultiSentOutPkmn; - else if (gTrainerBattleOpponent_A == TRAINER_UNION_ROOM) + else if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_UNION_ROOM) stringPtr = sText_Trainer1SentOutPkmn2; else stringPtr = sText_LinkTrainerSentOutPkmn2; @@ -2300,7 +2300,7 @@ void BufferStringBattle(u16 stringID, u32 battler) break; } } - else if (gTrainerBattleOpponent_A == TRAINER_UNION_ROOM) + else if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_UNION_ROOM) { switch (gBattleTextBuff1[0]) { @@ -2502,13 +2502,13 @@ static const u8 *BattleStringGetOpponentName(u8 *text, u8 multiplayerId, u8 batt switch (GetBattlerPosition(battler)) { case B_POSITION_OPPONENT_LEFT: - toCpy = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_A, text, multiplayerId, battler); + toCpy = BattleStringGetOpponentNameByTrainerId(TRAINER_BATTLE_PARAM.opponentA, text, multiplayerId, battler); break; case B_POSITION_OPPONENT_RIGHT: if (gBattleTypeFlags & (BATTLE_TYPE_TWO_OPPONENTS | BATTLE_TYPE_MULTI) && !BATTLE_TWO_VS_ONE_OPPONENT) - toCpy = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_B, text, multiplayerId, battler); + toCpy = BattleStringGetOpponentNameByTrainerId(TRAINER_BATTLE_PARAM.opponentB, text, multiplayerId, battler); else - toCpy = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_A, text, multiplayerId, battler); + toCpy = BattleStringGetOpponentNameByTrainerId(TRAINER_BATTLE_PARAM.opponentA, text, multiplayerId, battler); break; } @@ -2800,14 +2800,14 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) toCpy = gAbilitiesInfo[sBattlerAbilities[gEffectBattler]].name; break; case B_TXT_TRAINER1_CLASS: // trainer class name - toCpy = BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A); + toCpy = BattleStringGetOpponentClassByTrainerId(TRAINER_BATTLE_PARAM.opponentA); break; case B_TXT_TRAINER1_NAME: // trainer1 name - toCpy = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_A, text, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT)); + toCpy = BattleStringGetOpponentNameByTrainerId(TRAINER_BATTLE_PARAM.opponentA, text, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT)); break; case B_TXT_TRAINER1_NAME_WITH_CLASS: // trainer1 name with trainer class toCpy = textStart; - classString = BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A); + classString = BattleStringGetOpponentClassByTrainerId(TRAINER_BATTLE_PARAM.opponentA); while (classString[classLength] != EOS) { textStart[classLength] = classString[classLength]; @@ -2815,7 +2815,7 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) } textStart[classLength] = CHAR_SPACE; textStart += classLength + 1; - nameString = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_A, textStart, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT)); + nameString = BattleStringGetOpponentNameByTrainerId(TRAINER_BATTLE_PARAM.opponentA, textStart, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT)); if (nameString != textStart) { while (nameString[nameLength] != EOS) @@ -2847,12 +2847,12 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) case B_TXT_TRAINER1_LOSE_TEXT: // trainerA lose text if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER) { - CopyFrontierTrainerText(FRONTIER_PLAYER_WON_TEXT, gTrainerBattleOpponent_A); + CopyFrontierTrainerText(FRONTIER_PLAYER_WON_TEXT, TRAINER_BATTLE_PARAM.opponentA); toCpy = gStringVar4; } else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER_HILL) { - CopyTrainerHillTrainerText(TRAINER_HILL_TEXT_PLAYER_WON, gTrainerBattleOpponent_A); + CopyTrainerHillTrainerText(TRAINER_HILL_TEXT_PLAYER_WON, TRAINER_BATTLE_PARAM.opponentA); toCpy = gStringVar4; } else @@ -2863,12 +2863,12 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) case B_TXT_TRAINER1_WIN_TEXT: // trainerA win text if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER) { - CopyFrontierTrainerText(FRONTIER_PLAYER_LOST_TEXT, gTrainerBattleOpponent_A); + CopyFrontierTrainerText(FRONTIER_PLAYER_LOST_TEXT, TRAINER_BATTLE_PARAM.opponentA); toCpy = gStringVar4; } else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER_HILL) { - CopyTrainerHillTrainerText(TRAINER_HILL_TEXT_PLAYER_LOST, gTrainerBattleOpponent_A); + CopyTrainerHillTrainerText(TRAINER_HILL_TEXT_PLAYER_LOST, TRAINER_BATTLE_PARAM.opponentA); toCpy = gStringVar4; } break; @@ -2937,14 +2937,14 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) toCpy = sText_FoePkmnPrefix4; break; case B_TXT_TRAINER2_CLASS: - toCpy = BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_B); + toCpy = BattleStringGetOpponentClassByTrainerId(TRAINER_BATTLE_PARAM.opponentB); break; case B_TXT_TRAINER2_NAME: - toCpy = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_B, text, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT)); + toCpy = BattleStringGetOpponentNameByTrainerId(TRAINER_BATTLE_PARAM.opponentB, text, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT)); break; case B_TXT_TRAINER2_NAME_WITH_CLASS: toCpy = textStart; - classString = BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_B); + classString = BattleStringGetOpponentClassByTrainerId(TRAINER_BATTLE_PARAM.opponentB); while (classString[classLength] != EOS) { textStart[classLength] = classString[classLength]; @@ -2952,7 +2952,7 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) } textStart[classLength] = CHAR_SPACE; textStart += classLength + 1; - nameString = BattleStringGetOpponentNameByTrainerId(gTrainerBattleOpponent_B, textStart, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT)); + nameString = BattleStringGetOpponentNameByTrainerId(TRAINER_BATTLE_PARAM.opponentB, textStart, multiplayerId, GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT)); if (nameString != textStart) { while (nameString[nameLength] != EOS) @@ -2966,12 +2966,12 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) case B_TXT_TRAINER2_LOSE_TEXT: if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER) { - CopyFrontierTrainerText(FRONTIER_PLAYER_WON_TEXT, gTrainerBattleOpponent_B); + CopyFrontierTrainerText(FRONTIER_PLAYER_WON_TEXT, TRAINER_BATTLE_PARAM.opponentB); toCpy = gStringVar4; } else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER_HILL) { - CopyTrainerHillTrainerText(TRAINER_HILL_TEXT_PLAYER_WON, gTrainerBattleOpponent_B); + CopyTrainerHillTrainerText(TRAINER_HILL_TEXT_PLAYER_WON, TRAINER_BATTLE_PARAM.opponentB); toCpy = gStringVar4; } else @@ -2982,12 +2982,12 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) case B_TXT_TRAINER2_WIN_TEXT: if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER) { - CopyFrontierTrainerText(FRONTIER_PLAYER_LOST_TEXT, gTrainerBattleOpponent_B); + CopyFrontierTrainerText(FRONTIER_PLAYER_LOST_TEXT, TRAINER_BATTLE_PARAM.opponentB); toCpy = gStringVar4; } else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER_HILL) { - CopyTrainerHillTrainerText(TRAINER_HILL_TEXT_PLAYER_LOST, gTrainerBattleOpponent_B); + CopyTrainerHillTrainerText(TRAINER_HILL_TEXT_PLAYER_LOST, TRAINER_BATTLE_PARAM.opponentB); toCpy = gStringVar4; } break; @@ -3029,13 +3029,13 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) toCpy = gTrainerClasses[GetFrontierOpponentClass(gPartnerTrainerId)].name; break; case B_POSITION_OPPONENT_LEFT: - toCpy = BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A); + toCpy = BattleStringGetOpponentClassByTrainerId(TRAINER_BATTLE_PARAM.opponentA); break; case B_POSITION_OPPONENT_RIGHT: if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && !BATTLE_TWO_VS_ONE_OPPONENT) - toCpy = BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_B); + toCpy = BattleStringGetOpponentClassByTrainerId(TRAINER_BATTLE_PARAM.opponentB); else - toCpy = BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A); + toCpy = BattleStringGetOpponentClassByTrainerId(TRAINER_BATTLE_PARAM.opponentA); break; } break; @@ -3055,13 +3055,13 @@ u32 BattleStringExpandPlaceholders(const u8 *src, u8 *dst, u32 dstSize) classString = gTrainerClasses[GetFrontierOpponentClass(gPartnerTrainerId)].name; break; case B_POSITION_OPPONENT_LEFT: - classString = BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A); + classString = BattleStringGetOpponentClassByTrainerId(TRAINER_BATTLE_PARAM.opponentA); break; case B_POSITION_OPPONENT_RIGHT: if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && !BATTLE_TWO_VS_ONE_OPPONENT) - classString = BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_B); + classString = BattleStringGetOpponentClassByTrainerId(TRAINER_BATTLE_PARAM.opponentB); else - classString = BattleStringGetOpponentClassByTrainerId(gTrainerBattleOpponent_A); + classString = BattleStringGetOpponentClassByTrainerId(TRAINER_BATTLE_PARAM.opponentA); break; } classLength = 0; diff --git a/src/battle_palace.c b/src/battle_palace.c index fdcb8d3903..68f01f84f7 100644 --- a/src/battle_palace.c +++ b/src/battle_palace.c @@ -94,7 +94,7 @@ static void InitPalaceChallenge(void) gSaveBlock2Ptr->frontier.palaceWinStreaks[battleMode][lvlMode] = 0; SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE); - gTrainerBattleOpponent_A = 0; + TRAINER_BATTLE_PARAM.opponentA = 0; } static void GetPalaceData(void) @@ -153,14 +153,14 @@ static void GetPalaceCommentId(void) static void SetPalaceOpponent(void) { - gTrainerBattleOpponent_A = 5 *(Random() % 255) / 64u; - SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); + TRAINER_BATTLE_PARAM.opponentA = 5 *(Random() % 255) / 64u; + SetBattleFacilityTrainerGfxId(TRAINER_BATTLE_PARAM.opponentA, 0); } static void BufferOpponentIntroSpeech(void) { - if (gTrainerBattleOpponent_A < FRONTIER_TRAINERS_COUNT) - FrontierSpeechToString(gFacilityTrainers[gTrainerBattleOpponent_A].speechBefore); + if (TRAINER_BATTLE_PARAM.opponentA < FRONTIER_TRAINERS_COUNT) + FrontierSpeechToString(gFacilityTrainers[TRAINER_BATTLE_PARAM.opponentA].speechBefore); } static void IncrementPalaceStreak(void) diff --git a/src/battle_pike.c b/src/battle_pike.c index 3ce3cd443a..9c93a164a9 100644 --- a/src/battle_pike.c +++ b/src/battle_pike.c @@ -1403,11 +1403,11 @@ static void PrepareOneTrainer(bool8 difficult) } } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1); - gTrainerBattleOpponent_A = trainerId; + TRAINER_BATTLE_PARAM.opponentA = trainerId; gFacilityTrainers = gBattleFrontierTrainers; - SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); + SetBattleFacilityTrainerGfxId(TRAINER_BATTLE_PARAM.opponentA, 0); if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < NUM_PIKE_ROOMS) - gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1] = gTrainerBattleOpponent_A; + gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1] = TRAINER_BATTLE_PARAM.opponentA; } static void PrepareTwoTrainers(void) @@ -1429,10 +1429,10 @@ static void PrepareTwoTrainers(void) } } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1); - gTrainerBattleOpponent_A = trainerId; - SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); + TRAINER_BATTLE_PARAM.opponentA = trainerId; + SetBattleFacilityTrainerGfxId(TRAINER_BATTLE_PARAM.opponentA, 0); if (gSaveBlock2Ptr->frontier.curChallengeBattleNum <= NUM_PIKE_ROOMS) - gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1] = gTrainerBattleOpponent_A; + gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum - 1] = TRAINER_BATTLE_PARAM.opponentA; do { @@ -1445,10 +1445,10 @@ static void PrepareTwoTrainers(void) } } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum); - gTrainerBattleOpponent_B = trainerId; - SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_B, 1); + TRAINER_BATTLE_PARAM.opponentB = trainerId; + SetBattleFacilityTrainerGfxId(TRAINER_BATTLE_PARAM.opponentB, 1); if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < NUM_PIKE_ROOMS) - gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum - 2] = gTrainerBattleOpponent_B; + gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum - 2] = TRAINER_BATTLE_PARAM.opponentB; } static void ClearPikeTrainerIds(void) @@ -1463,13 +1463,13 @@ static void BufferTrainerIntro(void) { if (gSpecialVar_0x8005 == 0) { - if (gTrainerBattleOpponent_A < FRONTIER_TRAINERS_COUNT) - FrontierSpeechToString(gFacilityTrainers[gTrainerBattleOpponent_A].speechBefore); + if (TRAINER_BATTLE_PARAM.opponentA < FRONTIER_TRAINERS_COUNT) + FrontierSpeechToString(gFacilityTrainers[TRAINER_BATTLE_PARAM.opponentA].speechBefore); } else if (gSpecialVar_0x8005 == 1) { - if (gTrainerBattleOpponent_B < FRONTIER_TRAINERS_COUNT) - FrontierSpeechToString(gFacilityTrainers[gTrainerBattleOpponent_B].speechBefore); + if (TRAINER_BATTLE_PARAM.opponentB < FRONTIER_TRAINERS_COUNT) + FrontierSpeechToString(gFacilityTrainers[TRAINER_BATTLE_PARAM.opponentB].speechBefore); } } @@ -1615,7 +1615,7 @@ static void InitPikeChallenge(void) if (!(gSaveBlock2Ptr->frontier.winStreakActiveFlags & sWinStreakFlags[lvlMode])) gSaveBlock2Ptr->frontier.pikeWinStreaks[lvlMode] = 0; - gTrainerBattleOpponent_A = 0; + TRAINER_BATTLE_PARAM.opponentA = 0; gBattleOutcome = 0; } diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c index a184c9160f..c881dab38f 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -864,7 +864,7 @@ static void InitPyramidChallenge(void) } InitBattlePyramidBagCursorPosition(); - gTrainerBattleOpponent_A = 0; + TRAINER_BATTLE_PARAM.opponentA = 0; gBattleOutcome = 0; } @@ -1324,11 +1324,11 @@ bool8 GetBattlePyramidTrainerFlag(u8 eventId) void MarkApproachingPyramidTrainersAsBattled(void) { - MarkPyramidTrainerAsBattled(gTrainerBattleOpponent_A); + MarkPyramidTrainerAsBattled(TRAINER_BATTLE_PARAM.opponentA); if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) { gSelectedObjectEvent = GetChosenApproachingTrainerObjectEventId(1); - MarkPyramidTrainerAsBattled(gTrainerBattleOpponent_B); + MarkPyramidTrainerAsBattled(TRAINER_BATTLE_PARAM.opponentB); } } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 420e5d3302..b9d07b9946 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -8301,9 +8301,9 @@ static void Cmd_getmoneyreward(void) if (gBattleOutcome == B_OUTCOME_WON) { - money = GetTrainerMoneyToGive(gTrainerBattleOpponent_A); + money = GetTrainerMoneyToGive(TRAINER_BATTLE_PARAM.opponentA); if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) - money += GetTrainerMoneyToGive(gTrainerBattleOpponent_B); + money += GetTrainerMoneyToGive(TRAINER_BATTLE_PARAM.opponentB); AddMoney(&gSaveBlock1Ptr->money, money); } else diff --git a/src/battle_setup.c b/src/battle_setup.c index 62eb192b75..f6fa1a8e9b 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -57,22 +57,6 @@ enum { TRANSITION_TYPE_WATER, }; -enum { - TRAINER_PARAM_LOAD_VAL_8BIT, - TRAINER_PARAM_LOAD_VAL_16BIT, - TRAINER_PARAM_LOAD_VAL_32BIT, - TRAINER_PARAM_CLEAR_VAL_8BIT, - TRAINER_PARAM_CLEAR_VAL_16BIT, - TRAINER_PARAM_CLEAR_VAL_32BIT, - TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR, -}; - -struct TrainerBattleParameter -{ - void *varPtr; - u8 ptrType; -}; - // this file's functions static void DoBattlePikeWildBattle(void); static void DoSafariBattle(void); @@ -96,20 +80,9 @@ static void HandleRematchVarsOnBattleEnd(void); static const u8 *GetIntroSpeechOfApproachingTrainer(void); static const u8 *GetTrainerCantBattleSpeech(void); -EWRAM_DATA static u16 sTrainerBattleMode = 0; -EWRAM_DATA u16 gTrainerBattleOpponent_A = 0; -EWRAM_DATA u16 gTrainerBattleOpponent_B = 0; +EWRAM_DATA TrainerBattleParameter gTrainerBattleParameter = {0}; EWRAM_DATA u16 gPartnerTrainerId = 0; -EWRAM_DATA static u16 sTrainerObjectEventLocalId = 0; -EWRAM_DATA static u8 *sTrainerAIntroSpeech = NULL; -EWRAM_DATA static u8 *sTrainerBIntroSpeech = NULL; -EWRAM_DATA static u8 *sTrainerADefeatSpeech = NULL; -EWRAM_DATA static u8 *sTrainerBDefeatSpeech = NULL; -EWRAM_DATA static u8 *sTrainerVictorySpeech = NULL; -EWRAM_DATA static u8 *sTrainerCannotBattleSpeech = NULL; EWRAM_DATA static u8 *sTrainerBattleEndScript = NULL; -EWRAM_DATA static u8 *sTrainerABattleScriptRetAddr = NULL; -EWRAM_DATA static u8 *sTrainerBBattleScriptRetAddr = NULL; EWRAM_DATA static bool8 sShouldCheckTrainerBScript = FALSE; EWRAM_DATA static u8 sNoOfPossibleTrainerRetScripts = 0; @@ -163,114 +136,6 @@ static const u8 sBattleTransitionTable_BattleDome[] = B_TRANSITION_FRONTIER_SQUARES_SPIRAL }; -static const struct TrainerBattleParameter sOrdinaryBattleParams[] = -{ - {&sTrainerBattleMode, TRAINER_PARAM_LOAD_VAL_8BIT}, - {&gTrainerBattleOpponent_A, TRAINER_PARAM_LOAD_VAL_16BIT}, - {&sTrainerObjectEventLocalId, TRAINER_PARAM_LOAD_VAL_16BIT}, - {&sTrainerAIntroSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerADefeatSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerVictorySpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerCannotBattleSpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerABattleScriptRetAddr, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerBattleEndScript, TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR}, -}; - -static const struct TrainerBattleParameter sContinueScriptBattleParams[] = -{ - {&sTrainerBattleMode, TRAINER_PARAM_LOAD_VAL_8BIT}, - {&gTrainerBattleOpponent_A, TRAINER_PARAM_LOAD_VAL_16BIT}, - {&sTrainerObjectEventLocalId, TRAINER_PARAM_LOAD_VAL_16BIT}, - {&sTrainerAIntroSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerADefeatSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerVictorySpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerCannotBattleSpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerABattleScriptRetAddr, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerBattleEndScript, TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR}, -}; - -static const struct TrainerBattleParameter sDoubleBattleParams[] = -{ - {&sTrainerBattleMode, TRAINER_PARAM_LOAD_VAL_8BIT}, - {&gTrainerBattleOpponent_A, TRAINER_PARAM_LOAD_VAL_16BIT}, - {&sTrainerObjectEventLocalId, TRAINER_PARAM_LOAD_VAL_16BIT}, - {&sTrainerAIntroSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerADefeatSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerVictorySpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerCannotBattleSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerABattleScriptRetAddr, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerBattleEndScript, TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR}, -}; - -static const struct TrainerBattleParameter sOrdinaryNoIntroBattleParams[] = -{ - {&sTrainerBattleMode, TRAINER_PARAM_LOAD_VAL_8BIT}, - {&gTrainerBattleOpponent_A, TRAINER_PARAM_LOAD_VAL_16BIT}, - {&sTrainerObjectEventLocalId, TRAINER_PARAM_LOAD_VAL_16BIT}, - {&sTrainerAIntroSpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerADefeatSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerVictorySpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerCannotBattleSpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerABattleScriptRetAddr, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerBattleEndScript, TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR}, -}; - -static const struct TrainerBattleParameter sContinueScriptDoubleBattleParams[] = -{ - {&sTrainerBattleMode, TRAINER_PARAM_LOAD_VAL_8BIT}, - {&gTrainerBattleOpponent_A, TRAINER_PARAM_LOAD_VAL_16BIT}, - {&sTrainerObjectEventLocalId, TRAINER_PARAM_LOAD_VAL_16BIT}, - {&sTrainerAIntroSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerADefeatSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerVictorySpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerCannotBattleSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerABattleScriptRetAddr, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerBattleEndScript, TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR}, -}; - -static const struct TrainerBattleParameter sTrainerBOrdinaryBattleParams[] = -{ - {&sTrainerBattleMode, TRAINER_PARAM_LOAD_VAL_8BIT}, - {&gTrainerBattleOpponent_B, TRAINER_PARAM_LOAD_VAL_16BIT}, - {&sTrainerObjectEventLocalId, TRAINER_PARAM_LOAD_VAL_16BIT}, - {&sTrainerBIntroSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerBDefeatSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerVictorySpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerCannotBattleSpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerBBattleScriptRetAddr, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerBattleEndScript, TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR}, -}; - -static const struct TrainerBattleParameter sTrainerBContinueScriptBattleParams[] = -{ - {&sTrainerBattleMode, TRAINER_PARAM_LOAD_VAL_8BIT}, - {&gTrainerBattleOpponent_B, TRAINER_PARAM_LOAD_VAL_16BIT}, - {&sTrainerObjectEventLocalId, TRAINER_PARAM_LOAD_VAL_16BIT}, - {&sTrainerBIntroSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerBDefeatSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerVictorySpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerCannotBattleSpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerBBattleScriptRetAddr, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerBattleEndScript, TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR}, -}; - -// two trainers, each with a defeat speech -static const struct TrainerBattleParameter sTrainerTwoTrainerBattleParams[] = -{ - {&sTrainerBattleMode, TRAINER_PARAM_LOAD_VAL_8BIT}, - {&sTrainerObjectEventLocalId, TRAINER_PARAM_CLEAR_VAL_16BIT}, - {&gTrainerBattleOpponent_A, TRAINER_PARAM_LOAD_VAL_16BIT}, - {&sTrainerAIntroSpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerADefeatSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&gTrainerBattleOpponent_B, TRAINER_PARAM_LOAD_VAL_16BIT}, - {&sTrainerBIntroSpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerBDefeatSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, - {&sTrainerVictorySpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerCannotBattleSpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerBBattleScriptRetAddr, TRAINER_PARAM_CLEAR_VAL_32BIT}, - {&sTrainerBattleEndScript, TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR}, -}; - #define REMATCH(trainer1, trainer2, trainer3, trainer4, trainer5, map) \ { \ .trainerIds = {trainer1, trainer2, trainer3, trainer4, trainer5}, \ @@ -890,8 +755,8 @@ u8 GetTrainerBattleTransition(void) u8 transitionType; u8 enemyLevel; u8 playerLevel; - u32 trainerId = SanitizeTrainerId(gTrainerBattleOpponent_A); - u32 trainerClass = GetTrainerClassFromId(gTrainerBattleOpponent_A); + u32 trainerId = SanitizeTrainerId(TRAINER_BATTLE_PARAM.opponentA); + u32 trainerClass = GetTrainerClassFromId(TRAINER_BATTLE_PARAM.opponentA); if (DoesTrainerHaveMugshot(trainerId)) return B_TRANSITION_MUGSHOT; @@ -1027,30 +892,14 @@ static void TryUpdateGymLeaderRematchFromTrainer(void) UpdateGymLeaderRematch(); } -// why not just use the macros? maybe its because they didnt want to uncast const every time? -static u32 TrainerBattleLoadArg32(const u8 *ptr) -{ - return T1_READ_32(ptr); -} - -static u16 TrainerBattleLoadArg16(const u8 *ptr) -{ - return T1_READ_16(ptr); -} - -static u8 TrainerBattleLoadArg8(const u8 *ptr) -{ - return T1_READ_8(ptr); -} - static u16 GetTrainerAFlag(void) { - return TRAINER_FLAGS_START + gTrainerBattleOpponent_A; + return TRAINER_FLAGS_START + TRAINER_BATTLE_PARAM.opponentA; } static u16 GetTrainerBFlag(void) { - return TRAINER_FLAGS_START + gTrainerBattleOpponent_B; + return TRAINER_FLAGS_START + TRAINER_BATTLE_PARAM.opponentB; } static bool32 IsPlayerDefeated(u32 battleOutcome) @@ -1073,188 +922,143 @@ static bool32 IsPlayerDefeated(u32 battleOutcome) void ResetTrainerOpponentIds(void) { - gTrainerBattleOpponent_A = 0; - gTrainerBattleOpponent_B = 0; + TRAINER_BATTLE_PARAM.opponentA = 0; + TRAINER_BATTLE_PARAM.opponentB = 0; } static void InitTrainerBattleVariables(void) { - sTrainerBattleMode = 0; - if (gApproachingTrainerId == 0) - { - sTrainerAIntroSpeech = NULL; - sTrainerADefeatSpeech = NULL; - sTrainerABattleScriptRetAddr = NULL; - } - else - { - sTrainerBIntroSpeech = NULL; - sTrainerBDefeatSpeech = NULL; - sTrainerBBattleScriptRetAddr = NULL; - } - sTrainerObjectEventLocalId = 0; - sTrainerVictorySpeech = NULL; - sTrainerCannotBattleSpeech = NULL; + memset(gTrainerBattleParameter.data, 0, sizeof(TrainerBattleParameter)); sTrainerBattleEndScript = NULL; } -static inline void SetU8(void *ptr, u8 value) +void TrainerBattleLoadArgs(const u8 *data) { - *(u8 *)(ptr) = value; + InitTrainerBattleVariables(); + memcpy(gTrainerBattleParameter.data, data, sizeof(TrainerBattleParameter)); + sTrainerBattleEndScript = (u8*)data + sizeof(TrainerBattleParameter); } -static inline void SetU16(void *ptr, u16 value) +void TrainerBattleLoadArgsTrainerA(const u8 *data) { - *(u16 *)(ptr) = value; + TrainerBattleParameter *temp = (TrainerBattleParameter*)data; + + TRAINER_BATTLE_PARAM.playMusicA = temp->params.playMusicA; + TRAINER_BATTLE_PARAM.objEventLocalIdA = temp->params.objEventLocalIdA; + TRAINER_BATTLE_PARAM.opponentA = temp->params.opponentA; + TRAINER_BATTLE_PARAM.introTextA = temp->params.introTextA; + TRAINER_BATTLE_PARAM.defeatTextA = temp->params.defeatTextA; + TRAINER_BATTLE_PARAM.battleScriptRetAddrA = temp->params.battleScriptRetAddrA; } -static inline void SetU32(void *ptr, u32 value) +void TrainerBattleLoadArgsTrainerB(const u8 *data) { - *(u32 *)(ptr) = value; + TrainerBattleParameter *temp = (TrainerBattleParameter*)data; + + TRAINER_BATTLE_PARAM.playMusicB = temp->params.playMusicB; + TRAINER_BATTLE_PARAM.objEventLocalIdB = temp->params.objEventLocalIdB; + TRAINER_BATTLE_PARAM.opponentB = temp->params.opponentB; + TRAINER_BATTLE_PARAM.introTextB = temp->params.introTextB; + TRAINER_BATTLE_PARAM.defeatTextB = temp->params.defeatTextB; + TRAINER_BATTLE_PARAM.battleScriptRetAddrB = temp->params.battleScriptRetAddrB; } -static inline void SetPtr(const void *ptr, const void *value) +// loads trainer A parameter to trainer B. Used for second trainer in trainer_see.c +void TrainerBattleLoadArgsSecondTrainer(const u8 *data) { - *(const void **)(ptr) = value; + TrainerBattleParameter *temp = (TrainerBattleParameter*)data; + + TRAINER_BATTLE_PARAM.playMusicB = temp->params.playMusicA; + TRAINER_BATTLE_PARAM.objEventLocalIdB = temp->params.objEventLocalIdA; + TRAINER_BATTLE_PARAM.opponentB = temp->params.opponentA; + TRAINER_BATTLE_PARAM.introTextB = temp->params.introTextA; + TRAINER_BATTLE_PARAM.defeatTextB = temp->params.defeatTextA; + TRAINER_BATTLE_PARAM.battleScriptRetAddrB = temp->params.battleScriptRetAddrA; } -static void TrainerBattleLoadArgs(const struct TrainerBattleParameter *specs, const u8 *data) +void SetMapVarsToTrainerA(void) { - while (1) + if (TRAINER_BATTLE_PARAM.objEventLocalIdA != 0) { - switch (specs->ptrType) - { - case TRAINER_PARAM_LOAD_VAL_8BIT: - SetU8(specs->varPtr, TrainerBattleLoadArg8(data)); - data += 1; - break; - case TRAINER_PARAM_LOAD_VAL_16BIT: - SetU16(specs->varPtr, TrainerBattleLoadArg16(data)); - data += 2; - break; - case TRAINER_PARAM_LOAD_VAL_32BIT: - SetU32(specs->varPtr, TrainerBattleLoadArg32(data)); - data += 4; - break; - case TRAINER_PARAM_CLEAR_VAL_8BIT: - SetU8(specs->varPtr, 0); - break; - case TRAINER_PARAM_CLEAR_VAL_16BIT: - SetU16(specs->varPtr, 0); - break; - case TRAINER_PARAM_CLEAR_VAL_32BIT: - SetU32(specs->varPtr, 0); - break; - case TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR: - SetPtr(specs->varPtr, data); - return; - } - specs++; + gSpecialVar_LastTalked = TRAINER_BATTLE_PARAM.objEventLocalIdA; + gSelectedObjectEvent = GetObjectEventIdByLocalIdAndMap(TRAINER_BATTLE_PARAM.objEventLocalIdA, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); } } -void SetMapVarsToTrainer(void) +void SetMapVarsToTrainerB(void) { - if (sTrainerObjectEventLocalId != 0) + if (TRAINER_BATTLE_PARAM.objEventLocalIdB != 0) { - gSpecialVar_LastTalked = sTrainerObjectEventLocalId; - gSelectedObjectEvent = GetObjectEventIdByLocalIdAndMap(sTrainerObjectEventLocalId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); + gSpecialVar_LastTalked = TRAINER_BATTLE_PARAM.objEventLocalIdB; + gSelectedObjectEvent = GetObjectEventIdByLocalIdAndMap(TRAINER_BATTLE_PARAM.objEventLocalIdB, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup); } } +// expects parameters have been loaded correctly with TrainerBattleLoadArgs const u8 *BattleSetup_ConfigureTrainerBattle(const u8 *data) { - if (TrainerBattleLoadArg8(data) != TRAINER_BATTLE_SET_TRAINER_B) - InitTrainerBattleVariables(); - sTrainerBattleMode = TrainerBattleLoadArg8(data); - - switch (sTrainerBattleMode) + switch (TRAINER_BATTLE_PARAM.mode) { case TRAINER_BATTLE_SINGLE_NO_INTRO_TEXT: - TrainerBattleLoadArgs(sOrdinaryNoIntroBattleParams, data); return EventScript_DoNoIntroTrainerBattle; case TRAINER_BATTLE_DOUBLE: - TrainerBattleLoadArgs(sDoubleBattleParams, data); - SetMapVarsToTrainer(); + SetMapVarsToTrainerA(); return EventScript_TryDoDoubleTrainerBattle; case TRAINER_BATTLE_CONTINUE_SCRIPT: if (gApproachingTrainerId == 0) { - TrainerBattleLoadArgs(sContinueScriptBattleParams, data); - SetMapVarsToTrainer(); - } - else - { - TrainerBattleLoadArgs(sTrainerBContinueScriptBattleParams, data); + SetMapVarsToTrainerA(); } return EventScript_TryDoNormalTrainerBattle; case TRAINER_BATTLE_CONTINUE_SCRIPT_NO_MUSIC: - TrainerBattleLoadArgs(sContinueScriptBattleParams, data); - SetMapVarsToTrainer(); + SetMapVarsToTrainerA(); return EventScript_TryDoNormalTrainerBattle; case TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE: case TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE_NO_MUSIC: - TrainerBattleLoadArgs(sContinueScriptDoubleBattleParams, data); - SetMapVarsToTrainer(); + SetMapVarsToTrainerA(); return EventScript_TryDoDoubleTrainerBattle; #if FREE_MATCH_CALL == FALSE case TRAINER_BATTLE_REMATCH_DOUBLE: - TrainerBattleLoadArgs(sDoubleBattleParams, data); - SetMapVarsToTrainer(); - gTrainerBattleOpponent_A = GetRematchTrainerId(gTrainerBattleOpponent_A); + SetMapVarsToTrainerA(); + TRAINER_BATTLE_PARAM.opponentA = GetRematchTrainerId(TRAINER_BATTLE_PARAM.opponentA); return EventScript_TryDoDoubleRematchBattle; case TRAINER_BATTLE_REMATCH: - TrainerBattleLoadArgs(sOrdinaryBattleParams, data); - SetMapVarsToTrainer(); - gTrainerBattleOpponent_A = GetRematchTrainerId(gTrainerBattleOpponent_A); + SetMapVarsToTrainerA(); + TRAINER_BATTLE_PARAM.opponentA = GetRematchTrainerId(TRAINER_BATTLE_PARAM.opponentA); return EventScript_TryDoRematchBattle; #endif //FREE_MATCH_CALL case TRAINER_BATTLE_PYRAMID: if (gApproachingTrainerId == 0) { - TrainerBattleLoadArgs(sOrdinaryBattleParams, data); - SetMapVarsToTrainer(); - gTrainerBattleOpponent_A = LocalIdToPyramidTrainerId(gSpecialVar_LastTalked); + SetMapVarsToTrainerA(); + TRAINER_BATTLE_PARAM.opponentA = LocalIdToPyramidTrainerId(gSpecialVar_LastTalked); } else { - TrainerBattleLoadArgs(sTrainerBOrdinaryBattleParams, data); - gTrainerBattleOpponent_B = LocalIdToPyramidTrainerId(gSpecialVar_LastTalked); + TRAINER_BATTLE_PARAM.opponentB = LocalIdToPyramidTrainerId(gSpecialVar_LastTalked); } return EventScript_TryDoNormalTrainerBattle; - case TRAINER_BATTLE_SET_TRAINER_A: - TrainerBattleLoadArgs(sOrdinaryBattleParams, data); - return sTrainerBattleEndScript; - case TRAINER_BATTLE_SET_TRAINER_B: - TrainerBattleLoadArgs(sTrainerBOrdinaryBattleParams, data); + case TRAINER_BATTLE_SET_TRAINERS_FOR_MULTI_BATTLE: return sTrainerBattleEndScript; case TRAINER_BATTLE_HILL: if (gApproachingTrainerId == 0) { - TrainerBattleLoadArgs(sOrdinaryBattleParams, data); - SetMapVarsToTrainer(); - gTrainerBattleOpponent_A = LocalIdToHillTrainerId(gSpecialVar_LastTalked); + SetMapVarsToTrainerA(); + TRAINER_BATTLE_PARAM.opponentA = LocalIdToHillTrainerId(gSpecialVar_LastTalked); } else { - TrainerBattleLoadArgs(sTrainerBOrdinaryBattleParams, data); - gTrainerBattleOpponent_B = LocalIdToHillTrainerId(gSpecialVar_LastTalked); + TRAINER_BATTLE_PARAM.opponentB = LocalIdToHillTrainerId(gSpecialVar_LastTalked); } return EventScript_TryDoNormalTrainerBattle; case TRAINER_BATTLE_TWO_TRAINERS_NO_INTRO: gNoOfApproachingTrainers = 2; // set TWO_OPPONENTS gBattleTypeFlags gApproachingTrainerId = 1; // prevent trainer approach - TrainerBattleLoadArgs(sTrainerTwoTrainerBattleParams, data); return EventScript_DoNoIntroTrainerBattle; default: if (gApproachingTrainerId == 0) { - TrainerBattleLoadArgs(sOrdinaryBattleParams, data); - SetMapVarsToTrainer(); - } - else - { - TrainerBattleLoadArgs(sTrainerBOrdinaryBattleParams, data); + SetMapVarsToTrainerA(); } return EventScript_TryDoNormalTrainerBattle; } @@ -1264,6 +1068,7 @@ void ConfigureAndSetUpOneTrainerBattle(u8 trainerObjEventId, const u8 *trainerSc { gSelectedObjectEvent = trainerObjEventId; gSpecialVar_LastTalked = gObjectEvents[trainerObjEventId].localId; + TrainerBattleLoadArgs(trainerScript + 1); BattleSetup_ConfigureTrainerBattle(trainerScript + 1); ScriptContext_SetupScript(EventScript_StartTrainerApproach); LockPlayerFieldControls(); @@ -1273,6 +1078,12 @@ void ConfigureTwoTrainersBattle(u8 trainerObjEventId, const u8 *trainerScript) { gSelectedObjectEvent = trainerObjEventId; gSpecialVar_LastTalked = gObjectEvents[trainerObjEventId].localId; + + if (gApproachingTrainerId == 0) + TrainerBattleLoadArgs(trainerScript + 1); + else + TrainerBattleLoadArgsSecondTrainer(trainerScript + 1); + BattleSetup_ConfigureTrainerBattle(trainerScript + 1); } @@ -1282,11 +1093,13 @@ void SetUpTwoTrainersBattle(void) LockPlayerFieldControls(); } +#define OPCODE_OFFSET 1 bool32 GetTrainerFlagFromScriptPointer(const u8 *data) { - u32 flag = TrainerBattleLoadArg16(data + 2); - return FlagGet(TRAINER_FLAGS_START + flag); + TrainerBattleParameter *temp = (TrainerBattleParameter*)(data + OPCODE_OFFSET); + return FlagGet(TRAINER_FLAGS_START + temp->params.opponentA); } +#undef OPCODE_OFFSET // Set trainer's movement type so they stop and remain facing that direction // Note: Only for trainers who are spoken to directly @@ -1299,7 +1112,7 @@ void SetTrainerFacingDirection(void) u8 GetTrainerBattleMode(void) { - return sTrainerBattleMode; + return TRAINER_BATTLE_PARAM.mode; } bool8 GetTrainerFlag(void) @@ -1314,7 +1127,7 @@ bool8 GetTrainerFlag(void) static void SetBattledTrainersFlags(void) { - if (gTrainerBattleOpponent_B != 0) + if (TRAINER_BATTLE_PARAM.opponentB != 0) FlagSet(GetTrainerBFlag()); FlagSet(GetTrainerAFlag()); } @@ -1434,7 +1247,7 @@ static void CB2_EndTrainerBattle(void) { HandleBattleVariantEndParty(); - if (gTrainerBattleOpponent_A == TRAINER_SECRET_BASE) + if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_SECRET_BASE) { DowngradeBadPoison(); SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic); @@ -1460,7 +1273,7 @@ static void CB2_EndTrainerBattle(void) static void CB2_EndRematchBattle(void) { - if (gTrainerBattleOpponent_A == TRAINER_SECRET_BASE) + if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_SECRET_BASE) { DowngradeBadPoison(); SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic); @@ -1526,18 +1339,18 @@ const u8 *BattleSetup_GetTrainerPostBattleScript(void) if (sShouldCheckTrainerBScript) { sShouldCheckTrainerBScript = FALSE; - if (sTrainerBBattleScriptRetAddr != NULL) + if (TRAINER_BATTLE_PARAM.battleScriptRetAddrB != NULL) { gWhichTrainerToFaceAfterBattle = 1; - return sTrainerBBattleScriptRetAddr; + return TRAINER_BATTLE_PARAM.battleScriptRetAddrB; } } else { - if (sTrainerABattleScriptRetAddr != NULL) + if (TRAINER_BATTLE_PARAM.battleScriptRetAddrA != NULL) { gWhichTrainerToFaceAfterBattle = 0; - return sTrainerABattleScriptRetAddr; + return TRAINER_BATTLE_PARAM.battleScriptRetAddrA; } } @@ -1555,12 +1368,12 @@ void PlayTrainerEncounterMusic(void) u16 music; if (gApproachingTrainerId == 0) - trainerId = gTrainerBattleOpponent_A; + trainerId = TRAINER_BATTLE_PARAM.opponentA; else - trainerId = gTrainerBattleOpponent_B; + trainerId = TRAINER_BATTLE_PARAM.opponentB; - if (sTrainerBattleMode != TRAINER_BATTLE_CONTINUE_SCRIPT_NO_MUSIC - && sTrainerBattleMode != TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE_NO_MUSIC) + if (TRAINER_BATTLE_PARAM.mode != TRAINER_BATTLE_CONTINUE_SCRIPT_NO_MUSIC + && TRAINER_BATTLE_PARAM.mode != TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE_NO_MUSIC) { switch (GetTrainerEncounterMusicId(trainerId)) { @@ -1621,19 +1434,19 @@ static const u8 *ReturnEmptyStringIfNull(const u8 *string) static const u8 *GetIntroSpeechOfApproachingTrainer(void) { if (gApproachingTrainerId == 0) - return ReturnEmptyStringIfNull(sTrainerAIntroSpeech); + return ReturnEmptyStringIfNull(TRAINER_BATTLE_PARAM.introTextA); else - return ReturnEmptyStringIfNull(sTrainerBIntroSpeech); + return ReturnEmptyStringIfNull(TRAINER_BATTLE_PARAM.introTextB); } const u8 *GetTrainerALoseText(void) { const u8 *string; - if (gTrainerBattleOpponent_A == TRAINER_SECRET_BASE) + if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_SECRET_BASE) string = GetSecretBaseTrainerLoseText(); else - string = sTrainerADefeatSpeech; + string = TRAINER_BATTLE_PARAM.defeatTextA; StringExpandPlaceholders(gStringVar4, ReturnEmptyStringIfNull(string)); return gStringVar4; @@ -1641,18 +1454,18 @@ const u8 *GetTrainerALoseText(void) const u8 *GetTrainerBLoseText(void) { - StringExpandPlaceholders(gStringVar4, ReturnEmptyStringIfNull(sTrainerBDefeatSpeech)); + StringExpandPlaceholders(gStringVar4, ReturnEmptyStringIfNull(TRAINER_BATTLE_PARAM.defeatTextB)); return gStringVar4; } const u8 *GetTrainerWonSpeech(void) { - return ReturnEmptyStringIfNull(sTrainerVictorySpeech); + return ReturnEmptyStringIfNull(TRAINER_BATTLE_PARAM.victoryText); } static const u8 *GetTrainerCantBattleSpeech(void) { - return ReturnEmptyStringIfNull(sTrainerCannotBattleSpeech); + return ReturnEmptyStringIfNull(TRAINER_BATTLE_PARAM.cannotBattleText); } s32 FirstBattleTrainerIdToRematchTableId(const struct RematchTrainer *table, u16 trainerId) @@ -1891,7 +1704,7 @@ static void RegisterTrainerInMatchCall(void) { if (FlagGet(FLAG_HAS_MATCH_CALL)) { - u32 matchCallFlagId = GetTrainerMatchCallFlag(gTrainerBattleOpponent_A); + u32 matchCallFlagId = GetTrainerMatchCallFlag(TRAINER_BATTLE_PARAM.opponentA); if (matchCallFlagId != 0xFFFF) FlagSet(matchCallFlagId); } @@ -1988,15 +1801,15 @@ u16 GetLastBeatenRematchTrainerId(u16 trainerId) bool8 ShouldTryRematchBattle(void) { - if (IsFirstTrainerIdReadyForRematch(gRematchTable, gTrainerBattleOpponent_A)) + if (IsFirstTrainerIdReadyForRematch(gRematchTable, TRAINER_BATTLE_PARAM.opponentA)) return TRUE; - return WasSecondRematchWon(gRematchTable, gTrainerBattleOpponent_A); + return WasSecondRematchWon(gRematchTable, TRAINER_BATTLE_PARAM.opponentA); } bool8 IsTrainerReadyForRematch(void) { - return IsTrainerReadyForRematch_(gRematchTable, gTrainerBattleOpponent_A); + return IsTrainerReadyForRematch_(gRematchTable, TRAINER_BATTLE_PARAM.opponentA); } static void HandleRematchVarsOnBattleEnd(void) @@ -2004,7 +1817,7 @@ static void HandleRematchVarsOnBattleEnd(void) if ((gBattleTypeFlags & BATTLE_TYPE_TRAINER) && (I_VS_SEEKER_CHARGING != 0)) ClearRematchMovementByTrainerId(); - ClearTrainerWantRematchState(gRematchTable, gTrainerBattleOpponent_A); + ClearTrainerWantRematchState(gRematchTable, TRAINER_BATTLE_PARAM.opponentA); SetBattledTrainersFlags(); } diff --git a/src/battle_tent.c b/src/battle_tent.c index 49df90ffd6..a5547da46b 100644 --- a/src/battle_tent.c +++ b/src/battle_tent.c @@ -127,14 +127,14 @@ static void SetVerdanturfTentPrize(void) static void SetVerdanturfTentTrainerGfx(void) { - gTrainerBattleOpponent_A = (u32)((Random() % 255) * 5) / 64; - SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); + TRAINER_BATTLE_PARAM.opponentA = (u32)((Random() % 255) * 5) / 64; + SetBattleFacilityTrainerGfxId(TRAINER_BATTLE_PARAM.opponentA, 0); } static void BufferVerdanturfTentTrainerIntro(void) { - if (gTrainerBattleOpponent_A < FRONTIER_TRAINERS_COUNT) - FrontierSpeechToString(gFacilityTrainers[gTrainerBattleOpponent_A].speechBefore); + if (TRAINER_BATTLE_PARAM.opponentA < FRONTIER_TRAINERS_COUNT) + FrontierSpeechToString(gFacilityTrainers[TRAINER_BATTLE_PARAM.opponentA].speechBefore); } static void SaveVerdanturfTentChallenge(void) @@ -218,7 +218,7 @@ static void GiveFallarborTentPrize(void) static void BufferFallarborTentTrainerName(void) { - GetFrontierTrainerName(gStringVar1, gTrainerBattleOpponent_A); + GetFrontierTrainerName(gStringVar1, TRAINER_BATTLE_PARAM.opponentA); } void CallSlateportTentFunction(void) @@ -375,8 +375,8 @@ static void GenerateOpponentMons(void) } } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum); - gTrainerBattleOpponent_A = trainerId; - monSet = gFacilityTrainers[gTrainerBattleOpponent_A].monSet; + TRAINER_BATTLE_PARAM.opponentA = trainerId; + monSet = gFacilityTrainers[TRAINER_BATTLE_PARAM.opponentA].monSet; while (monSet[numMons] != 0xFFFF) numMons++; if (numMons > 8) @@ -385,9 +385,9 @@ static void GenerateOpponentMons(void) } if (gSaveBlock2Ptr->frontier.curChallengeBattleNum < TENT_STAGES_PER_CHALLENGE - 1) - gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; + gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = TRAINER_BATTLE_PARAM.opponentA; - monSet = gFacilityTrainers[gTrainerBattleOpponent_A].monSet; + monSet = gFacilityTrainers[TRAINER_BATTLE_PARAM.opponentA].monSet; i = 0; while (i != FRONTIER_PARTY_SIZE) { diff --git a/src/battle_tower.c b/src/battle_tower.c index 7fcdf1b8dd..140d411843 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -823,7 +823,7 @@ static void InitTowerChallenge(void) ValidateBattleTowerRecordChecksums(); SetDynamicWarp(0, gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum, WARP_ID_NONE); - gTrainerBattleOpponent_A = 0; + TRAINER_BATTLE_PARAM.opponentA = 0; } static void GetTowerData(void) @@ -874,7 +874,7 @@ static void SetTowerData(void) static void SetTowerBattleWon(void) { #if FREE_BATTLE_TOWER_E_READER == FALSE - if (gTrainerBattleOpponent_A == TRAINER_EREADER) + if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_EREADER) ClearEReaderTrainer(&gSaveBlock2Ptr->frontier.ereaderTrainer); #endif //FREE_BATTLE_TOWER_E_READER @@ -946,7 +946,7 @@ static bool8 ChooseSpecialBattleTowerTrainer(void) if (idsCount != 0) { - gTrainerBattleOpponent_A = trainerIds[Random() % idsCount]; + TRAINER_BATTLE_PARAM.opponentA = trainerIds[Random() % idsCount]; return TRUE; } else @@ -973,15 +973,15 @@ static void SetNextFacilityOpponent(void) if (battleMode == FRONTIER_MODE_MULTIS || battleMode == FRONTIER_MODE_LINK_MULTIS) { id = gSaveBlock2Ptr->frontier.curChallengeBattleNum; - gTrainerBattleOpponent_A = gSaveBlock2Ptr->frontier.trainerIds[id * 2]; - gTrainerBattleOpponent_B = gSaveBlock2Ptr->frontier.trainerIds[id * 2 + 1]; - SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); - SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_B, 1); + TRAINER_BATTLE_PARAM.opponentA = gSaveBlock2Ptr->frontier.trainerIds[id * 2]; + TRAINER_BATTLE_PARAM.opponentB = gSaveBlock2Ptr->frontier.trainerIds[id * 2 + 1]; + SetBattleFacilityTrainerGfxId(TRAINER_BATTLE_PARAM.opponentA, 0); + SetBattleFacilityTrainerGfxId(TRAINER_BATTLE_PARAM.opponentB, 1); } else if (ChooseSpecialBattleTowerTrainer()) { - SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); - gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; + SetBattleFacilityTrainerGfxId(TRAINER_BATTLE_PARAM.opponentA, 0); + gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = TRAINER_BATTLE_PARAM.opponentA; } else { @@ -1000,10 +1000,10 @@ static void SetNextFacilityOpponent(void) break; } - gTrainerBattleOpponent_A = id; - SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); + TRAINER_BATTLE_PARAM.opponentA = id; + SetBattleFacilityTrainerGfxId(TRAINER_BATTLE_PARAM.opponentA, 0); if (gSaveBlock2Ptr->frontier.curChallengeBattleNum + 1 < FRONTIER_STAGES_PER_CHALLENGE) - gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; + gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = TRAINER_BATTLE_PARAM.opponentA; } } } @@ -1549,20 +1549,20 @@ static bool8 IsFrontierTrainerFemale(u16 trainerId) void FillFrontierTrainerParty(u8 monsCount) { ZeroEnemyPartyMons(); - FillTrainerParty(gTrainerBattleOpponent_A, 0, monsCount); + FillTrainerParty(TRAINER_BATTLE_PARAM.opponentA, 0, monsCount); } void FillFrontierTrainersParties(u8 monsCount) { ZeroEnemyPartyMons(); - FillTrainerParty(gTrainerBattleOpponent_A, 0, monsCount); - FillTrainerParty(gTrainerBattleOpponent_B, 3, monsCount); + FillTrainerParty(TRAINER_BATTLE_PARAM.opponentA, 0, monsCount); + FillTrainerParty(TRAINER_BATTLE_PARAM.opponentB, 3, monsCount); } static void FillTentTrainerParty(u8 monsCount) { ZeroEnemyPartyMons(); - FillTentTrainerParty_(gTrainerBattleOpponent_A, 0, monsCount); + FillTentTrainerParty_(TRAINER_BATTLE_PARAM.opponentA, 0, monsCount); } void CreateFacilityMon(const struct TrainerMon *fmon, u16 level, u8 fixedIV, u32 otID, u32 flags, struct Pokemon *dst) @@ -1667,7 +1667,7 @@ static void FillTrainerParty(u16 trainerId, u8 firstMonId, u8 monCount) { // Normal battle frontier trainer. fixedIV = GetFrontierTrainerFixedIvs(trainerId); - monSet = gFacilityTrainers[gTrainerBattleOpponent_A].monSet; + monSet = gFacilityTrainers[TRAINER_BATTLE_PARAM.opponentA].monSet; } else if (trainerId == TRAINER_EREADER) { @@ -1789,9 +1789,9 @@ static void FillFactoryTrainerParty(void) { ZeroEnemyPartyMons(); if (gSaveBlock2Ptr->frontier.lvlMode != FRONTIER_LVL_TENT) - FillFactoryFrontierTrainerParty(gTrainerBattleOpponent_A, 0); + FillFactoryFrontierTrainerParty(TRAINER_BATTLE_PARAM.opponentA, 0); else - FillFactoryTentTrainerParty(gTrainerBattleOpponent_A, 0); + FillFactoryTentTrainerParty(TRAINER_BATTLE_PARAM.opponentA, 0); } static void FillFactoryFrontierTrainerParty(u16 trainerId, u8 firstMonId) @@ -1886,9 +1886,9 @@ static void GetOpponentIntroSpeech(void) SetFacilityPtrsGetLevel(); if (gSpecialVar_0x8005) - trainerId = gTrainerBattleOpponent_B; + trainerId = TRAINER_BATTLE_PARAM.opponentB; else - trainerId = gTrainerBattleOpponent_A; + trainerId = TRAINER_BATTLE_PARAM.opponentA; #if FREE_BATTLE_TOWER_E_READER == FALSE if (trainerId == TRAINER_EREADER) @@ -2011,7 +2011,7 @@ void DoSpecialTrainerBattle(void) for (i = 0; i < (int)ARRAY_COUNT(gSaveBlock2Ptr->frontier.ereaderTrainer.party); i++) CreateBattleTowerMon(&gEnemyParty[i], &gSaveBlock2Ptr->frontier.ereaderTrainer.party[i]); gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_EREADER_TRAINER; - gTrainerBattleOpponent_A = 0; + TRAINER_BATTLE_PARAM.opponentA = 0; CreateTask(Task_StartBattleAfterTransition, 1); PlayMapChosenOrBattleBGM(0); BattleTransition_StartOnField(GetSpecialBattleTransition(B_TRANSITION_GROUP_E_READER)); @@ -2021,7 +2021,7 @@ void DoSpecialTrainerBattle(void) gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_DOME; if (VarGet(VAR_FRONTIER_BATTLE_MODE) == FRONTIER_MODE_DOUBLES) gBattleTypeFlags |= BATTLE_TYPE_DOUBLE; - if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) + if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_FRONTIER_BRAIN) FillFrontierTrainerParty(DOME_BATTLE_PARTY_SIZE); CreateTask(Task_StartBattleAfterTransition, 1); CreateTask_PlayMapChosenOrBattleBGM(0); @@ -2086,7 +2086,7 @@ void DoSpecialTrainerBattle(void) } else if (gSpecialVar_0x8005 & MULTI_BATTLE_2_VS_1) // Player + AI against one trainer { - gTrainerBattleOpponent_B = 0xFFFF; + TRAINER_BATTLE_PARAM.opponentB = 0xFFFF; gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_DOUBLE | BATTLE_TYPE_MULTI | BATTLE_TYPE_INGAME_PARTNER; } else // MULTI_BATTLE_2_VS_2 @@ -2607,10 +2607,10 @@ static void LoadLinkMultiOpponentsData(void) { ResetBlockReceivedFlags(); memcpy(&gSaveBlock2Ptr->frontier.trainerIds, gBlockRecvBuffer, sizeof(gSaveBlock2Ptr->frontier.trainerIds)); - gTrainerBattleOpponent_A = gSaveBlock2Ptr->frontier.trainerIds[battleNum * 2]; - gTrainerBattleOpponent_B = gSaveBlock2Ptr->frontier.trainerIds[battleNum * 2 + 1]; - SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); - SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_B, 1); + TRAINER_BATTLE_PARAM.opponentA = gSaveBlock2Ptr->frontier.trainerIds[battleNum * 2]; + TRAINER_BATTLE_PARAM.opponentB = gSaveBlock2Ptr->frontier.trainerIds[battleNum * 2 + 1]; + SetBattleFacilityTrainerGfxId(TRAINER_BATTLE_PARAM.opponentA, 0); + SetBattleFacilityTrainerGfxId(TRAINER_BATTLE_PARAM.opponentB, 1); if (gReceivedRemoteLinkPlayers && gWirelessCommType == 0) gSpecialVar_Result = 4; else @@ -2652,10 +2652,10 @@ static void SetTowerInterviewData(void) if (VarGet(VAR_FRONTIER_BATTLE_MODE) != FRONTIER_MODE_SINGLES) return; - GetFrontierTrainerName(text, gTrainerBattleOpponent_A); + GetFrontierTrainerName(text, TRAINER_BATTLE_PARAM.opponentA); StripExtCtrlCodes(text); StringCopy(gSaveBlock2Ptr->frontier.towerInterview.opponentName, text); - GetBattleTowerTrainerLanguage(&gSaveBlock2Ptr->frontier.towerInterview.opponentLanguage, gTrainerBattleOpponent_A); + GetBattleTowerTrainerLanguage(&gSaveBlock2Ptr->frontier.towerInterview.opponentLanguage, TRAINER_BATTLE_PARAM.opponentA); gSaveBlock2Ptr->frontier.towerInterview.opponentSpecies = GetMonData(&gEnemyParty[gBattlerPartyIndexes[1]], MON_DATA_SPECIES, NULL); gSaveBlock2Ptr->frontier.towerInterview.playerSpecies = GetMonData(&gPlayerParty[gBattlerPartyIndexes[0]], MON_DATA_SPECIES, NULL); for (i = 0; i < VANILLA_POKEMON_NAME_LENGTH + 1; i++) @@ -3418,10 +3418,10 @@ static void SetNextBattleTentOpponent(void) } } while (i != gSaveBlock2Ptr->frontier.curChallengeBattleNum); - gTrainerBattleOpponent_A = trainerId; - SetBattleFacilityTrainerGfxId(gTrainerBattleOpponent_A, 0); + TRAINER_BATTLE_PARAM.opponentA = trainerId; + SetBattleFacilityTrainerGfxId(TRAINER_BATTLE_PARAM.opponentA, 0); if (gSaveBlock2Ptr->frontier.curChallengeBattleNum + 1 < TENT_STAGES_PER_CHALLENGE) - gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = gTrainerBattleOpponent_A; + gSaveBlock2Ptr->frontier.trainerIds[gSaveBlock2Ptr->frontier.curChallengeBattleNum] = TRAINER_BATTLE_PARAM.opponentA; } static void FillTentTrainerParty_(u16 trainerId, u8 firstMonId, u8 monCount) @@ -3435,7 +3435,7 @@ static void FillTentTrainerParty_(u16 trainerId, u8 firstMonId, u8 monCount) u32 otID = 0; u16 monId; - monSet = gFacilityTrainers[gTrainerBattleOpponent_A].monSet; + monSet = gFacilityTrainers[TRAINER_BATTLE_PARAM.opponentA].monSet; bfMonCount = 0; monId = monSet[bfMonCount]; diff --git a/src/battle_transition.c b/src/battle_transition.c index 1afbe7a026..b131769ba4 100644 --- a/src/battle_transition.c +++ b/src/battle_transition.c @@ -2260,7 +2260,7 @@ static bool8 Mugshot_SetGfx(struct Task *task) s16 i, j; u16 *tilemap, *tileset; const u16 *mugshotsMap = sMugshotsTilemap; - u8 mugshotColor = GetTrainerMugshotColorFromId(gTrainerBattleOpponent_A); + u8 mugshotColor = GetTrainerMugshotColorFromId(TRAINER_BATTLE_PARAM.opponentA); GetBg0TilesDst(&tilemap, &tileset); CpuSet(sEliteFour_Tileset, tileset, 0xF0); @@ -2519,7 +2519,7 @@ static void Mugshots_CreateTrainerPics(struct Task *task) { struct Sprite *opponentSprite, *playerSprite; - u8 trainerPicId = GetTrainerPicFromId(gTrainerBattleOpponent_A); + u8 trainerPicId = GetTrainerPicFromId(TRAINER_BATTLE_PARAM.opponentA); s16 opponentRotationScales = 0; gReservedSpritePaletteCount = 10; diff --git a/src/battle_util.c b/src/battle_util.c index 21a0928bd2..d7b8d21741 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -11340,7 +11340,7 @@ bool32 ShouldGetStatBadgeBoost(u16 badgeFlag, u32 battler) return FALSE; else if (GetBattlerSide(battler) != B_SIDE_PLAYER) return FALSE; - else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && gTrainerBattleOpponent_A == TRAINER_SECRET_BASE) + else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER && TRAINER_BATTLE_PARAM.opponentA == TRAINER_SECRET_BASE) return FALSE; else if (FlagGet(badgeFlag)) return TRUE; diff --git a/src/cable_club.c b/src/cable_club.c index d6a2903fd4..1a115c31ef 100644 --- a/src/cable_club.c +++ b/src/cable_club.c @@ -867,7 +867,7 @@ static void Task_StartWiredCableClubBattle(u8 taskId) SetLinkBattleTypeFlags(gSpecialVar_0x8004); CleanupOverworldWindowsAndTilemaps(); - gTrainerBattleOpponent_A = TRAINER_LINK_OPPONENT; + TRAINER_BATTLE_PARAM.opponentA = TRAINER_LINK_OPPONENT; SetMainCallback2(CB2_InitBattle); gMain.savedCallback = CB2_ReturnFromCableClubBattle; DestroyTask(taskId); @@ -933,7 +933,7 @@ static void Task_StartWirelessCableClubBattle(u8 taskId) gLinkPlayers[0].linkType = LINKTYPE_BATTLE; SetLinkBattleTypeFlags(gSpecialVar_0x8004); CleanupOverworldWindowsAndTilemaps(); - gTrainerBattleOpponent_A = TRAINER_LINK_OPPONENT; + TRAINER_BATTLE_PARAM.opponentA = TRAINER_LINK_OPPONENT; SetMainCallback2(CB2_InitBattle); gMain.savedCallback = CB2_ReturnFromCableClubBattle; DestroyTask(taskId); diff --git a/src/frontier_util.c b/src/frontier_util.c index 30c22d4442..ab6dc867fd 100644 --- a/src/frontier_util.c +++ b/src/frontier_util.c @@ -1849,7 +1849,7 @@ void ResetFrontierTrainerIds(void) static void IsTrainerFrontierBrain(void) { - if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) + if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_FRONTIER_BRAIN) gSpecialVar_Result = TRUE; else gSpecialVar_Result = FALSE; @@ -1900,7 +1900,7 @@ static void GiveBattlePoints(void) challengeNum = ARRAY_COUNT(sBattlePointAwards[0][0]) - 1; points = sBattlePointAwards[facility][battleMode][challengeNum]; - if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) + if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_FRONTIER_BRAIN) points += 10; gSaveBlock2Ptr->frontier.battlePoints += points; ConvertIntToDecimalStringN(gStringVar1, points, STR_CONV_MODE_LEFT_ALIGN, 2); @@ -1910,7 +1910,7 @@ static void GiveBattlePoints(void) points = gSaveBlock2Ptr->frontier.cardBattlePoints; points += sBattlePointAwards[facility][battleMode][challengeNum]; IncrementDailyBattlePoints(sBattlePointAwards[facility][battleMode][challengeNum]); - if (gTrainerBattleOpponent_A == TRAINER_FRONTIER_BRAIN) + if (TRAINER_BATTLE_PARAM.opponentA == TRAINER_FRONTIER_BRAIN) { points += 10; IncrementDailyBattlePoints(10); @@ -2182,10 +2182,10 @@ static void BufferFrontierTrainerName(void) switch (gSpecialVar_0x8005) { case 0: - GetFrontierTrainerName(gStringVar1, gTrainerBattleOpponent_A); + GetFrontierTrainerName(gStringVar1, TRAINER_BATTLE_PARAM.opponentA); break; case 1: - GetFrontierTrainerName(gStringVar2, gTrainerBattleOpponent_A); + GetFrontierTrainerName(gStringVar2, TRAINER_BATTLE_PARAM.opponentA); break; } } @@ -2564,7 +2564,7 @@ u16 GetFrontierBrainMonSpecies(u8 monId) void SetFrontierBrainObjEventGfx(u8 facility) { - gTrainerBattleOpponent_A = TRAINER_FRONTIER_BRAIN; + TRAINER_BATTLE_PARAM.opponentA = TRAINER_FRONTIER_BRAIN; VarSet(VAR_OBJ_GFX_ID_0, gFrontierBrainInfo[facility].objEventGfx); } diff --git a/src/pokemon.c b/src/pokemon.c index 748a21d3f8..e89605e66c 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -5181,7 +5181,7 @@ void AdjustFriendship(struct Pokemon *mon, u8 event) { u8 friendshipLevel = 0; s16 friendship = GetMonData(mon, MON_DATA_FRIENDSHIP, 0); - u32 opponentTrainerClass = GetTrainerClassFromId(gTrainerBattleOpponent_A); + u32 opponentTrainerClass = GetTrainerClassFromId(TRAINER_BATTLE_PARAM.opponentA); if (friendship > 99) friendshipLevel++; @@ -5748,11 +5748,11 @@ u16 GetBattleBGM(void) u8 trainerClass; if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER) - trainerClass = GetFrontierOpponentClass(gTrainerBattleOpponent_A); + trainerClass = GetFrontierOpponentClass(TRAINER_BATTLE_PARAM.opponentA); else if (gBattleTypeFlags & BATTLE_TYPE_TRAINER_HILL) trainerClass = TRAINER_CLASS_EXPERT; else - trainerClass = GetTrainerClassFromId(gTrainerBattleOpponent_A); + trainerClass = GetTrainerClassFromId(TRAINER_BATTLE_PARAM.opponentA); switch (trainerClass) { @@ -5771,7 +5771,7 @@ u16 GetBattleBGM(void) case TRAINER_CLASS_RIVAL: if (gBattleTypeFlags & BATTLE_TYPE_FRONTIER) return MUS_VS_RIVAL; - if (!StringCompare(GetTrainerNameFromId(gTrainerBattleOpponent_A), gText_BattleWallyName)) + if (!StringCompare(GetTrainerNameFromId(TRAINER_BATTLE_PARAM.opponentA), gText_BattleWallyName)) return MUS_VS_TRAINER; return MUS_VS_RIVAL; case TRAINER_CLASS_ELITE_FOUR: diff --git a/src/recorded_battle.c b/src/recorded_battle.c index 6a1587930d..0b385c017c 100644 --- a/src/recorded_battle.c +++ b/src/recorded_battle.c @@ -349,8 +349,8 @@ bool32 MoveRecordedBattleToSaveData(void) battleSave->battleFlags = sBattleFlags; } - battleSave->opponentA = gTrainerBattleOpponent_A; - battleSave->opponentB = gTrainerBattleOpponent_B; + battleSave->opponentA = TRAINER_BATTLE_PARAM.opponentA; + battleSave->opponentB = TRAINER_BATTLE_PARAM.opponentB; battleSave->partnerId = gPartnerTrainerId; battleSave->multiplayerId = gRecordedBattleMultiplayerId; battleSave->lvlMode = gSaveBlock2Ptr->frontier.lvlMode; @@ -360,41 +360,41 @@ bool32 MoveRecordedBattleToSaveData(void) battleSave->textSpeed = gSaveBlock2Ptr->optionsTextSpeed; battleSave->AI_scripts = sAI_Scripts; - if (gTrainerBattleOpponent_A >= TRAINER_RECORD_MIXING_FRIEND && gTrainerBattleOpponent_A < TRAINER_RECORD_MIXING_APPRENTICE) + if (TRAINER_BATTLE_PARAM.opponentA >= TRAINER_RECORD_MIXING_FRIEND && TRAINER_BATTLE_PARAM.opponentA < TRAINER_RECORD_MIXING_APPRENTICE) { for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++) - battleSave->recordMixFriendName[i] = gSaveBlock2Ptr->frontier.towerRecords[gTrainerBattleOpponent_A - TRAINER_RECORD_MIXING_FRIEND].name[i]; - battleSave->recordMixFriendClass = gSaveBlock2Ptr->frontier.towerRecords[gTrainerBattleOpponent_A - TRAINER_RECORD_MIXING_FRIEND].facilityClass; + battleSave->recordMixFriendName[i] = gSaveBlock2Ptr->frontier.towerRecords[TRAINER_BATTLE_PARAM.opponentA - TRAINER_RECORD_MIXING_FRIEND].name[i]; + battleSave->recordMixFriendClass = gSaveBlock2Ptr->frontier.towerRecords[TRAINER_BATTLE_PARAM.opponentA - TRAINER_RECORD_MIXING_FRIEND].facilityClass; if (sBattleOutcome == B_OUTCOME_WON) { for (i = 0; i < EASY_CHAT_BATTLE_WORDS_COUNT; i++) - battleSave->easyChatSpeech[i] = gSaveBlock2Ptr->frontier.towerRecords[gTrainerBattleOpponent_A - TRAINER_RECORD_MIXING_FRIEND].speechLost[i]; + battleSave->easyChatSpeech[i] = gSaveBlock2Ptr->frontier.towerRecords[TRAINER_BATTLE_PARAM.opponentA - TRAINER_RECORD_MIXING_FRIEND].speechLost[i]; } else { for (i = 0; i < EASY_CHAT_BATTLE_WORDS_COUNT; i++) - battleSave->easyChatSpeech[i] = gSaveBlock2Ptr->frontier.towerRecords[gTrainerBattleOpponent_A - TRAINER_RECORD_MIXING_FRIEND].speechWon[i]; + battleSave->easyChatSpeech[i] = gSaveBlock2Ptr->frontier.towerRecords[TRAINER_BATTLE_PARAM.opponentA - TRAINER_RECORD_MIXING_FRIEND].speechWon[i]; } - battleSave->recordMixFriendLanguage = gSaveBlock2Ptr->frontier.towerRecords[gTrainerBattleOpponent_A - TRAINER_RECORD_MIXING_FRIEND].language; + battleSave->recordMixFriendLanguage = gSaveBlock2Ptr->frontier.towerRecords[TRAINER_BATTLE_PARAM.opponentA - TRAINER_RECORD_MIXING_FRIEND].language; } - else if (gTrainerBattleOpponent_B >= TRAINER_RECORD_MIXING_FRIEND && gTrainerBattleOpponent_B < TRAINER_RECORD_MIXING_APPRENTICE) + else if (TRAINER_BATTLE_PARAM.opponentB >= TRAINER_RECORD_MIXING_FRIEND && TRAINER_BATTLE_PARAM.opponentB < TRAINER_RECORD_MIXING_APPRENTICE) { for (i = 0; i < PLAYER_NAME_LENGTH + 1; i++) - battleSave->recordMixFriendName[i] = gSaveBlock2Ptr->frontier.towerRecords[gTrainerBattleOpponent_B - TRAINER_RECORD_MIXING_FRIEND].name[i]; - battleSave->recordMixFriendClass = gSaveBlock2Ptr->frontier.towerRecords[gTrainerBattleOpponent_B - TRAINER_RECORD_MIXING_FRIEND].facilityClass; + battleSave->recordMixFriendName[i] = gSaveBlock2Ptr->frontier.towerRecords[TRAINER_BATTLE_PARAM.opponentB - TRAINER_RECORD_MIXING_FRIEND].name[i]; + battleSave->recordMixFriendClass = gSaveBlock2Ptr->frontier.towerRecords[TRAINER_BATTLE_PARAM.opponentB - TRAINER_RECORD_MIXING_FRIEND].facilityClass; if (sBattleOutcome == B_OUTCOME_WON) { for (i = 0; i < EASY_CHAT_BATTLE_WORDS_COUNT; i++) - battleSave->easyChatSpeech[i] = gSaveBlock2Ptr->frontier.towerRecords[gTrainerBattleOpponent_B - TRAINER_RECORD_MIXING_FRIEND].speechLost[i]; + battleSave->easyChatSpeech[i] = gSaveBlock2Ptr->frontier.towerRecords[TRAINER_BATTLE_PARAM.opponentB - TRAINER_RECORD_MIXING_FRIEND].speechLost[i]; } else { for (i = 0; i < EASY_CHAT_BATTLE_WORDS_COUNT; i++) - battleSave->easyChatSpeech[i] = gSaveBlock2Ptr->frontier.towerRecords[gTrainerBattleOpponent_B - TRAINER_RECORD_MIXING_FRIEND].speechWon[i]; + battleSave->easyChatSpeech[i] = gSaveBlock2Ptr->frontier.towerRecords[TRAINER_BATTLE_PARAM.opponentB - TRAINER_RECORD_MIXING_FRIEND].speechWon[i]; } - battleSave->recordMixFriendLanguage = gSaveBlock2Ptr->frontier.towerRecords[gTrainerBattleOpponent_B - TRAINER_RECORD_MIXING_FRIEND].language; + battleSave->recordMixFriendLanguage = gSaveBlock2Ptr->frontier.towerRecords[TRAINER_BATTLE_PARAM.opponentB - TRAINER_RECORD_MIXING_FRIEND].language; } else if (gPartnerTrainerId >= TRAINER_RECORD_MIXING_FRIEND && gPartnerTrainerId < TRAINER_RECORD_MIXING_APPRENTICE) { @@ -405,19 +405,19 @@ bool32 MoveRecordedBattleToSaveData(void) battleSave->recordMixFriendLanguage = gSaveBlock2Ptr->frontier.towerRecords[gPartnerTrainerId - TRAINER_RECORD_MIXING_FRIEND].language; } - if (gTrainerBattleOpponent_A >= TRAINER_RECORD_MIXING_APPRENTICE) + if (TRAINER_BATTLE_PARAM.opponentA >= TRAINER_RECORD_MIXING_APPRENTICE) { - battleSave->apprenticeId = gSaveBlock2Ptr->apprentices[gTrainerBattleOpponent_A - TRAINER_RECORD_MIXING_APPRENTICE].id; + battleSave->apprenticeId = gSaveBlock2Ptr->apprentices[TRAINER_BATTLE_PARAM.opponentA - TRAINER_RECORD_MIXING_APPRENTICE].id; for (i = 0; i < EASY_CHAT_BATTLE_WORDS_COUNT; i++) - battleSave->easyChatSpeech[i] = gSaveBlock2Ptr->apprentices[gTrainerBattleOpponent_A - TRAINER_RECORD_MIXING_APPRENTICE].speechWon[i]; - battleSave->apprenticeLanguage = gSaveBlock2Ptr->apprentices[gTrainerBattleOpponent_A - TRAINER_RECORD_MIXING_APPRENTICE].language; + battleSave->easyChatSpeech[i] = gSaveBlock2Ptr->apprentices[TRAINER_BATTLE_PARAM.opponentA - TRAINER_RECORD_MIXING_APPRENTICE].speechWon[i]; + battleSave->apprenticeLanguage = gSaveBlock2Ptr->apprentices[TRAINER_BATTLE_PARAM.opponentA - TRAINER_RECORD_MIXING_APPRENTICE].language; } - else if (gTrainerBattleOpponent_B >= TRAINER_RECORD_MIXING_APPRENTICE) + else if (TRAINER_BATTLE_PARAM.opponentB >= TRAINER_RECORD_MIXING_APPRENTICE) { - battleSave->apprenticeId = gSaveBlock2Ptr->apprentices[gTrainerBattleOpponent_B - TRAINER_RECORD_MIXING_APPRENTICE].id; + battleSave->apprenticeId = gSaveBlock2Ptr->apprentices[TRAINER_BATTLE_PARAM.opponentB - TRAINER_RECORD_MIXING_APPRENTICE].id; for (i = 0; i < EASY_CHAT_BATTLE_WORDS_COUNT; i++) - battleSave->easyChatSpeech[i] = gSaveBlock2Ptr->apprentices[gTrainerBattleOpponent_B - TRAINER_RECORD_MIXING_APPRENTICE].speechWon[i]; - battleSave->apprenticeLanguage = gSaveBlock2Ptr->apprentices[gTrainerBattleOpponent_B - TRAINER_RECORD_MIXING_APPRENTICE].language; + battleSave->easyChatSpeech[i] = gSaveBlock2Ptr->apprentices[TRAINER_BATTLE_PARAM.opponentB - TRAINER_RECORD_MIXING_APPRENTICE].speechWon[i]; + battleSave->apprenticeLanguage = gSaveBlock2Ptr->apprentices[TRAINER_BATTLE_PARAM.opponentB - TRAINER_RECORD_MIXING_APPRENTICE].language; } else if (gPartnerTrainerId >= TRAINER_RECORD_MIXING_APPRENTICE) { @@ -472,8 +472,8 @@ static void CB2_RecordedBattleEnd(void) gSaveBlock2Ptr->frontier.lvlMode = sLvlMode; gBattleOutcome = 0; gBattleTypeFlags = 0; - gTrainerBattleOpponent_A = 0; - gTrainerBattleOpponent_B = 0; + TRAINER_BATTLE_PARAM.opponentA = 0; + TRAINER_BATTLE_PARAM.opponentB = 0; gPartnerTrainerId = 0; RecordedBattle_RestoreSavedParties(); @@ -530,8 +530,8 @@ void SetVariablesForRecordedBattle(struct RecordedBattleSave *src) gRecordedBattleRngSeed = src->rngSeed; gBattleTypeFlags = src->battleFlags | BATTLE_TYPE_RECORDED; - gTrainerBattleOpponent_A = src->opponentA; - gTrainerBattleOpponent_B = src->opponentB; + TRAINER_BATTLE_PARAM.opponentA = src->opponentA; + TRAINER_BATTLE_PARAM.opponentB = src->opponentB; gPartnerTrainerId = src->partnerId; gRecordedBattleMultiplayerId = src->multiplayerId; sLvlMode = gSaveBlock2Ptr->frontier.lvlMode; diff --git a/src/scrcmd.c b/src/scrcmd.c index f82ac3c38d..2ab23a1aa8 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -2376,7 +2376,8 @@ bool8 ScrCmd_updatecoinsbox(struct ScriptContext *ctx) bool8 ScrCmd_trainerbattle(struct ScriptContext *ctx) { Script_RequestEffects(SCREFF_V1 | SCREFF_TRAINERBATTLE); - + + TrainerBattleLoadArgs(ctx->scriptPtr); ctx->scriptPtr = BattleSetup_ConfigureTrainerBattle(ctx->scriptPtr); return FALSE; } diff --git a/src/secret_base.c b/src/secret_base.c index 7e0c1ae107..d4dc43c5bd 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -1163,7 +1163,7 @@ const u8 *GetSecretBaseTrainerLoseText(void) void PrepSecretBaseBattleFlags(void) { TryGainNewFanFromCounter(FANCOUNTER_BATTLED_AT_BASE); - gTrainerBattleOpponent_A = TRAINER_SECRET_BASE; + TRAINER_BATTLE_PARAM.opponentA = TRAINER_SECRET_BASE; gBattleTypeFlags = BATTLE_TYPE_TRAINER | BATTLE_TYPE_SECRET_BASE; } diff --git a/src/trainer_hill.c b/src/trainer_hill.c index dd8ae78aa7..ce2b894bf0 100644 --- a/src/trainer_hill.c +++ b/src/trainer_hill.c @@ -864,7 +864,7 @@ void SetHillTrainerFlag(void) for (i = 0; i < HILL_TRAINERS_PER_FLOOR; i++) { - if (gSaveBlock2Ptr->frontier.trainerIds[i] == gTrainerBattleOpponent_A) + if (gSaveBlock2Ptr->frontier.trainerIds[i] == TRAINER_BATTLE_PARAM.opponentA) { gSaveBlock2Ptr->frontier.trainerFlags |= 1u << (trainerIndexStart + i); break; @@ -875,7 +875,7 @@ void SetHillTrainerFlag(void) { for (i = 0; i < HILL_TRAINERS_PER_FLOOR; i++) { - if (gSaveBlock2Ptr->frontier.trainerIds[i] == gTrainerBattleOpponent_B) + if (gSaveBlock2Ptr->frontier.trainerIds[i] == TRAINER_BATTLE_PARAM.opponentB) { gSaveBlock2Ptr->frontier.trainerFlags |= 1u << (trainerIndexStart + i); break; @@ -922,14 +922,14 @@ static void CreateNPCTrainerHillParty(u16 trainerId, u8 firstMonId) void FillHillTrainerParty(void) { ZeroEnemyPartyMons(); - CreateNPCTrainerHillParty(gTrainerBattleOpponent_A, 0); + CreateNPCTrainerHillParty(TRAINER_BATTLE_PARAM.opponentA, 0); } void FillHillTrainersParties(void) { ZeroEnemyPartyMons(); - CreateNPCTrainerHillParty(gTrainerBattleOpponent_A, 0); - CreateNPCTrainerHillParty(gTrainerBattleOpponent_B, PARTY_SIZE / 2); + CreateNPCTrainerHillParty(TRAINER_BATTLE_PARAM.opponentA, 0); + CreateNPCTrainerHillParty(TRAINER_BATTLE_PARAM.opponentB, PARTY_SIZE / 2); } // This function is unused, but my best guess is diff --git a/src/trainer_see.c b/src/trainer_see.c index 12c6cba612..07eb46efdd 100644 --- a/src/trainer_see.c +++ b/src/trainer_see.c @@ -478,9 +478,10 @@ static u8 CheckTrainer(u8 objectEventId) if (trainerBattlePtr) { - if (trainerBattlePtr[1] == TRAINER_BATTLE_DOUBLE - || trainerBattlePtr[1] == TRAINER_BATTLE_REMATCH_DOUBLE - || trainerBattlePtr[1] == TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE) + TrainerBattleParameter *temp = (TrainerBattleParameter *)(trainerBattlePtr + 1); + if (temp->params.mode == TRAINER_BATTLE_DOUBLE + || temp->params.mode == TRAINER_BATTLE_REMATCH_DOUBLE + || temp->params.mode == TRAINER_BATTLE_CONTINUE_SCRIPT_DOUBLE) { if (GetMonsStateToDoubles_2() != PLAYER_HAS_TWO_USABLE_MONS) return 0; diff --git a/src/trainer_slide.c b/src/trainer_slide.c index 1606ae5155..074f6259d2 100644 --- a/src/trainer_slide.c +++ b/src/trainer_slide.c @@ -204,21 +204,21 @@ static void SetTrainerSlideParamters(u32 battler, u32* firstId, u32* lastId, u32 { *firstId = MULTI_PARTY_SIZE; *lastId = PARTY_SIZE; - *trainerId = SanitizeTrainerId(gTrainerBattleOpponent_B); + *trainerId = SanitizeTrainerId(TRAINER_BATTLE_PARAM.opponentB); *retValue = TRAINER_SLIDE_TARGET_TRAINER_B; } else { *firstId = 0; *lastId = MULTI_PARTY_SIZE; - *trainerId = SanitizeTrainerId(gTrainerBattleOpponent_A); + *trainerId = SanitizeTrainerId(TRAINER_BATTLE_PARAM.opponentA); } } else { *firstId = 0; *lastId = PARTY_SIZE; - *trainerId = SanitizeTrainerId(gTrainerBattleOpponent_A); + *trainerId = SanitizeTrainerId(TRAINER_BATTLE_PARAM.opponentA); } } diff --git a/src/union_room_battle.c b/src/union_room_battle.c index 4d5f7d8278..2bcbaef19c 100644 --- a/src/union_room_battle.c +++ b/src/union_room_battle.c @@ -69,7 +69,7 @@ static void CB2_SetUpPartiesAndStartBattle(void) } IncrementGameStat(GAME_STAT_NUM_UNION_ROOM_BATTLES); CalculatePlayerPartyCount(); - gTrainerBattleOpponent_A = TRAINER_UNION_ROOM; + TRAINER_BATTLE_PARAM.opponentA = TRAINER_UNION_ROOM; SetMainCallback2(CB2_InitBattle); } diff --git a/src/vs_seeker.c b/src/vs_seeker.c index 771c01dc72..15829c3bd5 100644 --- a/src/vs_seeker.c +++ b/src/vs_seeker.c @@ -513,7 +513,7 @@ void ClearRematchMovementByTrainerId(void) struct ObjectEventTemplate *objectEventTemplates = gSaveBlock1Ptr->objectEventTemplates; struct ObjectEvent *objectEvent; - int vsSeekerDataIdx = TrainerIdToRematchTableId(gRematchTable, gTrainerBattleOpponent_A); + int vsSeekerDataIdx = TrainerIdToRematchTableId(gRematchTable, TRAINER_BATTLE_PARAM.opponentA); if (!I_VS_SEEKER_CHARGING) return; diff --git a/test/text.c b/test/text.c index 781aaaed3e..7650c2dd59 100644 --- a/test/text.c +++ b/test/text.c @@ -612,8 +612,8 @@ TEST("Battle strings fit on the battle message window") sBattlerAbilities[j] = longAbilityID; // Set Trainers - gTrainerBattleOpponent_A = 1; - gTrainerBattleOpponent_B = 1; + TRAINER_BATTLE_PARAM.opponentA = 1; + TRAINER_BATTLE_PARAM.opponentB = 1; // Set battler to 1, so "The opposing " is prefixed when refering to battlers. gBattleTypeFlags |= BATTLE_TYPE_TRAINER;