From b83a87c8e878e02a5382dd6880187c46462cd785 Mon Sep 17 00:00:00 2001 From: Aaron B-D Date: Mon, 19 Oct 2020 14:47:32 -0400 Subject: [PATCH 1/2] Added scripted double wild battles --- asm/macros/event.inc | 18 ++++++++++++++++++ data/script_cmd_table.inc | 2 ++ include/battle_setup.h | 1 + include/script_pokemon_util.h | 1 + src/battle_setup.c | 12 ++++++++++++ src/scrcmd.c | 20 ++++++++++++++++++++ src/script_pokemon_util.c | 23 +++++++++++++++++++++++ 7 files changed, 77 insertions(+) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index eafd19b1c2..4186666c7c 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -1778,3 +1778,21 @@ setfieldeffectargument 2, \priority dofieldeffect FLDEFF_SPARKLE .endm + + @ Prepares to start a double wild battle against a species1 at Level level1 holding item1 and a species2 at Level level2 holding item2. + @ Running this command will not affect normal wild battles. You start the prepared battle with dodoublewildbattle. + @ BUG: If the player only has one pokemon, the scripted double battle has undefined behaviours... + .macro setdoublewildbattle species1:req, level1:req, item1:req, species2:req, level2:req, item2:req + .byte 0xe3 + .2byte \species1 + .byte \level1 + .2byte \item1 + .2byte \species2 + .byte \level2 + .2byte \item2 + .endm + + @ Starts a wild battle against the Pokemon generated by setdoublewildbattle. Blocks script execution until the battle finishes. + .macro dodoublewildbattle + .byte 0xe4 + .endm diff --git a/data/script_cmd_table.inc b/data/script_cmd_table.inc index 0971358a14..6911d8e82b 100644 --- a/data/script_cmd_table.inc +++ b/data/script_cmd_table.inc @@ -227,6 +227,8 @@ gScriptCmdTable:: @ 81DB67C .4byte ScrCmd_warpsootopolislegend @ 0xe0 .4byte ScrCmd_buffercontesttype @ 0xe1 .4byte ScrCmd_bufferitemnameplural @ 0xe2 + .4byte ScrCmd_setdoublewildbattle @ 0xe3 + .4byte ScrCmd_dodoublewildbattle @ 0xe4 gScriptCmdTableEnd:: @ 81DBA08 .4byte ScrCmd_nop diff --git a/include/battle_setup.h b/include/battle_setup.h index 1d1a35fa19..4099d5f150 100644 --- a/include/battle_setup.h +++ b/include/battle_setup.h @@ -24,6 +24,7 @@ void BattleSetup_StartBattlePikeWildBattle(void); void BattleSetup_StartRoamerBattle(void); void StartWallyTutorialBattle(void); void BattleSetup_StartScriptedWildBattle(void); +void BattleSetup_StartScriptedDoubleWildBattle(void); void BattleSetup_StartLatiBattle(void); void BattleSetup_StartLegendaryBattle(void); void StartGroudonKyogreBattle(void); diff --git a/include/script_pokemon_util.h b/include/script_pokemon_util.h index 120c28a637..024f2579e5 100644 --- a/include/script_pokemon_util.h +++ b/include/script_pokemon_util.h @@ -4,6 +4,7 @@ u8 ScriptGiveMon(u16, u8, u16, u32, u32, u8); u8 ScriptGiveEgg(u16); void CreateScriptedWildMon(u16, u8, u16); +void CreateScriptedDoubleWildMon(u16, u8, u16, u16, u8, u16); void ScriptSetMonMoveSlot(u8, u16, u8); void ReducePlayerPartyToSelectedMons(void); void HealPlayerParty(void); diff --git a/src/battle_setup.c b/src/battle_setup.c index afa82680f5..1edbbd45f2 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -499,6 +499,18 @@ void BattleSetup_StartScriptedWildBattle(void) TryUpdateGymLeaderRematchFromWild(); } +void BattleSetup_StartScriptedDoubleWildBattle(void) +{ + ScriptContext2_Enable(); + gMain.savedCallback = CB2_EndScriptedWildBattle; + gBattleTypeFlags = BATTLE_TYPE_DOUBLE; + CreateBattleStartTask(GetWildBattleTransition(), 0); + IncrementGameStat(GAME_STAT_TOTAL_BATTLES); + IncrementGameStat(GAME_STAT_WILD_BATTLES); + IncrementDailyWildBattles(); + TryUpdateGymLeaderRematchFromWild(); +} + void BattleSetup_StartLatiBattle(void) { ScriptContext2_Enable(); diff --git a/src/scrcmd.c b/src/scrcmd.c index 578e357fa5..f099e24add 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -2302,3 +2302,23 @@ bool8 ScrCmd_warpsootopolislegend(struct ScriptContext *ctx) ResetInitialPlayerAvatarState(); return TRUE; } + +bool8 ScrCmd_setdoublewildbattle(struct ScriptContext *ctx) +{ + u16 species1 = ScriptReadHalfword(ctx); + u8 level1 = ScriptReadByte(ctx); + u16 item1 = ScriptReadHalfword(ctx); + u16 species2 = ScriptReadHalfword(ctx); + u8 level2 = ScriptReadByte(ctx); + u16 item2 = ScriptReadHalfword(ctx); + + CreateScriptedDoubleWildMon(species1, level1, item1, species2, level2, item2); + return FALSE; +} + +bool8 ScrCmd_dodoublewildbattle(struct ScriptContext *ctx) +{ + BattleSetup_StartScriptedDoubleWildBattle(); + ScriptContext1_Stop(); + return TRUE; +} diff --git a/src/script_pokemon_util.c b/src/script_pokemon_util.c index c9a2127acb..5d79ecae7b 100755 --- a/src/script_pokemon_util.c +++ b/src/script_pokemon_util.c @@ -147,6 +147,29 @@ void CreateScriptedWildMon(u16 species, u8 level, u16 item) SetMonData(&gEnemyParty[0], MON_DATA_HELD_ITEM, heldItem); } } +void CreateScriptedDoubleWildMon(u16 species1, u8 level1, u16 item1, u16 species2, u8 level2, u16 item2) +{ + u8 heldItem1[2]; + u8 heldItem2[2]; + + ZeroEnemyPartyMons(); + + CreateMon(&gEnemyParty[0], species1, level1, 32, 0, 0, OT_ID_PLAYER_ID, 0); + if (item1) + { + heldItem1[0] = item1; + heldItem1[1] = item1 >> 8; + SetMonData(&gEnemyParty[0], MON_DATA_HELD_ITEM, heldItem1); + } + + CreateMon(&gEnemyParty[3], species2, level2, 32, 0, 0, OT_ID_PLAYER_ID, 0); + if (item2) + { + heldItem2[0] = item2; + heldItem2[1] = item2 >> 8; + SetMonData(&gEnemyParty[3], MON_DATA_HELD_ITEM, heldItem2); + } +} void ScriptSetMonMoveSlot(u8 monIndex, u16 move, u8 slot) { From 151aca83650fb37dc889b08fdca990f3939ec549 Mon Sep 17 00:00:00 2001 From: Aaron B-D Date: Tue, 17 Nov 2020 03:13:00 -0500 Subject: [PATCH 2/2] Changed how scripted wild encounters work to include double battles Removed the old commands for scripted wild double encounters --- asm/macros/event.inc | 30 +++++++----------------- data/script_cmd_table.inc | 2 -- src/scrcmd.c | 49 +++++++++++++++++++++------------------ 3 files changed, 35 insertions(+), 46 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 4186666c7c..d0600a97b9 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -1327,13 +1327,19 @@ .2byte \count .endm - @ Prepares to start a wild battle against a species at Level level holding item. Running this command will not affect - @ normal wild battles. You start the prepared battle with dowildbattle. - .macro setwildbattle species:req, level:req, item:req + @ Prepares to start a wild battle against a species at Level level holding item. + @ If species2 is something other than SPECIES_NONE, then the battle is a double battle with another pokemon + @ with species species2 at Level level2 holding item2. + @ Running this command will not affect normal wild battles. You start the prepared battle with dowildbattle. + @ If the player only has one pokemon, a scripted double battle will be buggy. + .macro setwildbattle species:req, level:req, item:req, species2=SPECIES_NONE, level2=0, item2=ITEM_NONE .byte 0xb6 .2byte \species .byte \level .2byte \item + .2byte \species2 + .byte \level2 + .2byte \item2 .endm @ Starts a wild battle against the Pokemon generated by setwildbattle. Blocks script execution until the battle finishes. @@ -1778,21 +1784,3 @@ setfieldeffectargument 2, \priority dofieldeffect FLDEFF_SPARKLE .endm - - @ Prepares to start a double wild battle against a species1 at Level level1 holding item1 and a species2 at Level level2 holding item2. - @ Running this command will not affect normal wild battles. You start the prepared battle with dodoublewildbattle. - @ BUG: If the player only has one pokemon, the scripted double battle has undefined behaviours... - .macro setdoublewildbattle species1:req, level1:req, item1:req, species2:req, level2:req, item2:req - .byte 0xe3 - .2byte \species1 - .byte \level1 - .2byte \item1 - .2byte \species2 - .byte \level2 - .2byte \item2 - .endm - - @ Starts a wild battle against the Pokemon generated by setdoublewildbattle. Blocks script execution until the battle finishes. - .macro dodoublewildbattle - .byte 0xe4 - .endm diff --git a/data/script_cmd_table.inc b/data/script_cmd_table.inc index 6911d8e82b..0971358a14 100644 --- a/data/script_cmd_table.inc +++ b/data/script_cmd_table.inc @@ -227,8 +227,6 @@ gScriptCmdTable:: @ 81DB67C .4byte ScrCmd_warpsootopolislegend @ 0xe0 .4byte ScrCmd_buffercontesttype @ 0xe1 .4byte ScrCmd_bufferitemnameplural @ 0xe2 - .4byte ScrCmd_setdoublewildbattle @ 0xe3 - .4byte ScrCmd_dodoublewildbattle @ 0xe4 gScriptCmdTableEnd:: @ 81DBA08 .4byte ScrCmd_nop diff --git a/src/scrcmd.c b/src/scrcmd.c index f099e24add..df6e0ea50e 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -62,6 +62,7 @@ static EWRAM_DATA u16 sMovingNpcMapId = 0; static EWRAM_DATA u16 sFieldEffectScriptId = 0; static u8 gBrailleWindowId; +static bool8 gIsScriptedWildDouble; extern const SpecialFunc gSpecials[]; extern const u8 *gStdScripts[]; @@ -1870,15 +1871,37 @@ bool8 ScrCmd_setwildbattle(struct ScriptContext *ctx) u16 species = ScriptReadHalfword(ctx); u8 level = ScriptReadByte(ctx); u16 item = ScriptReadHalfword(ctx); + u16 species2 = ScriptReadHalfword(ctx); + u8 level2 = ScriptReadByte(ctx); + u16 item2 = ScriptReadHalfword(ctx); + + if(species2 == SPECIES_NONE) + { + CreateScriptedWildMon(species, level, item); + gIsScriptedWildDouble = FALSE; + } + else + { + CreateScriptedDoubleWildMon(species, level, item, species2, level2, item2); + gIsScriptedWildDouble = TRUE; + } - CreateScriptedWildMon(species, level, item); return FALSE; } bool8 ScrCmd_dowildbattle(struct ScriptContext *ctx) { - BattleSetup_StartScriptedWildBattle(); - ScriptContext1_Stop(); + if(gIsScriptedWildDouble == FALSE) + { + BattleSetup_StartScriptedWildBattle(); + ScriptContext1_Stop(); + } + else + { + BattleSetup_StartScriptedDoubleWildBattle(); + ScriptContext1_Stop(); + } + return TRUE; } @@ -2302,23 +2325,3 @@ bool8 ScrCmd_warpsootopolislegend(struct ScriptContext *ctx) ResetInitialPlayerAvatarState(); return TRUE; } - -bool8 ScrCmd_setdoublewildbattle(struct ScriptContext *ctx) -{ - u16 species1 = ScriptReadHalfword(ctx); - u8 level1 = ScriptReadByte(ctx); - u16 item1 = ScriptReadHalfword(ctx); - u16 species2 = ScriptReadHalfword(ctx); - u8 level2 = ScriptReadByte(ctx); - u16 item2 = ScriptReadHalfword(ctx); - - CreateScriptedDoubleWildMon(species1, level1, item1, species2, level2, item2); - return FALSE; -} - -bool8 ScrCmd_dodoublewildbattle(struct ScriptContext *ctx) -{ - BattleSetup_StartScriptedDoubleWildBattle(); - ScriptContext1_Stop(); - return TRUE; -}