From 0d1f9d96136ac32702632eecad2a3d233bf9af48 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Thu, 8 Dec 2022 22:29:07 -0300 Subject: [PATCH 1/6] Reimplemented Mimicry --- asm/macros/battle_script.inc | 9 +-- data/battle_scripts_1.s | 38 ++++----- include/battle.h | 7 ++ include/battle_scripts.h | 1 + include/battle_util.h | 4 +- include/constants/battle_script_commands.h | 1 + src/battle_script_commands.c | 19 +---- src/battle_util.c | 94 ++++++++++------------ 8 files changed, 78 insertions(+), 95 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 27c5a86c4..bc688855f 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -1899,11 +1899,6 @@ various \battler, VARIOUS_TRY_END_NEUTRALIZING_GAS .endm - .macro trytoapplymimicry battler:req, ptr:req - various \battler, VARIOUS_TRY_TO_APPLY_MIMICRY - .4byte \ptr - .endm - .macro trynoretreat battler:req, ptr:req various \battler, VARIOUS_TRY_NO_RETREAT .4byte \ptr @@ -2000,6 +1995,10 @@ .4byte \ptr .endm + .macro applymimicry battler:req + various \battler, VARIOUS_APPLY_MIMICRY + .endm + @ helpful macros .macro setstatchanger stat:req, stages:req, down:req setbyte sSTATCHANGER, \stat | \stages << 3 | \down << 7 diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 6b8067721..736d0d914 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -2404,24 +2404,25 @@ BattleScript_EffectPsychicTerrain: waitmessage B_WAIT_TIME_LONG playanimation BS_ATTACKER, B_ANIM_RESTORE_BG call BattleScript_TerrainSeedLoop - jumpifabilitypresent ABILITY_MIMICRY, BattleScript_ApplyMimicry + call BattleScript_TryToApplyMimicry goto BattleScript_MoveEnd -BattleScript_ApplyMimicry:: +BattleScript_TryToApplyMimicry: savetarget setbyte gBattlerTarget, 0 -BattleScript_MimicryLoopIter: - copybyte sBATTLER, gBattlerTarget - trytoapplymimicry BS_TARGET, BattleScript_MimicryLoop_NextBattler - copybyte gBattlerAbility, sBATTLER +BattleScript_TryToApplyMimicry_Loop: + jumpifword CMP_NOT_EQUAL, gFieldStatuses, STATUS_FIELD_TERRAIN_ANY, BattleScript_TryToApplyMimicry_Increment + jumpifability BS_TARGET, ABILITY_MIMICRY, BattleScript_TryToApplyMimicry_Effect +BattleScript_TryToApplyMimicry_Effect: + pause B_WAIT_TIME_SHORT call BattleScript_AbilityPopUp + applymimicry BS_TARGET printstring STRINGID_BATTLERTYPECHANGEDTO - waitmessage B_WAIT_TIME_LONG -BattleScript_MimicryLoop_NextBattler: - addbyte gBattlerTarget, 0x1 - jumpifbytenotequal gBattlerTarget, gBattlersCount, BattleScript_MimicryLoopIter - restoretarget - goto BattleScript_MoveEnd + waitmessage B_WAIT_TIME_SHORT +BattleScript_TryToApplyMimicry_Increment: + addbyte gBattlerTarget, 1 + jumpifbytenotequal gBattlerTarget, gBattlersCount, BattleScript_TryToApplyMimicry_Loop + return BattleScript_EffectTopsyTurvy: attackcanceler @@ -8305,6 +8306,13 @@ BattleScript_AttackWeakenedByStrongWinds:: waitmessage B_WAIT_TIME_LONG return +BattleScript_MimicryActivates_End3:: + pause B_WAIT_TIME_SHORT + call BattleScript_AbilityPopUp + printstring STRINGID_BATTLERTYPECHANGEDTO + waitmessage B_WAIT_TIME_SHORT + end3 + BattleScript_SnowWarningActivates:: pause B_WAIT_TIME_SHORT call BattleScript_AbilityPopUp @@ -8590,12 +8598,6 @@ BattleScript_ColorChangeActivates:: waitmessage B_WAIT_TIME_LONG return -BattleScript_MimicryActivatesEnd3:: - call BattleScript_AbilityPopUp - printstring STRINGID_BATTLERTYPECHANGEDTO - waitmessage B_WAIT_TIME_LONG - end3 - BattleScript_ProteanActivates:: pause B_WAIT_TIME_SHORTEST call BattleScript_AbilityPopUp diff --git a/include/battle.h b/include/battle.h index ebc8be057..eb31507c9 100644 --- a/include/battle.h +++ b/include/battle.h @@ -681,6 +681,13 @@ struct BattleStruct gBattleMons[battlerId].type2 = type; \ gBattleMons[battlerId].type3 = TYPE_MYSTERY; \ } +#define RESTORE_BATTLER_TYPE(battlerId) \ +{ \ + gBattleMons[battlerId].type1 = gSpeciesInfo[gBattleMons[battlerId].species].type1; \ + gBattleMons[battlerId].type2 = gSpeciesInfo[gBattleMons[battlerId].species].type2; \ + gBattleMons[battlerId].type3 = TYPE_MYSTERY; \ +} + #define IS_BATTLER_PROTECTED(battlerId)(gProtectStructs[battlerId].protected \ || gSideStatuses[GetBattlerSide(battlerId)] & SIDE_STATUS_WIDE_GUARD \ diff --git a/include/battle_scripts.h b/include/battle_scripts.h index 23f18e3be..654d21f00 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -433,6 +433,7 @@ extern const u8 BattleScript_SymbiosisActivates[]; extern const u8 BattleScript_MultiHitPrintStrings[]; extern const u8 BattleScript_BurnUpRemoveType[]; extern const u8 BattleScript_TargetAbilityStatRaiseRet[]; +extern const u8 BattleScript_MimicryActivates_End3[]; // zmoves extern const u8 BattleScript_ZMoveActivateDamaging[]; diff --git a/include/battle_util.h b/include/battle_util.h index 3f516daba..b3e1fe132 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -181,9 +181,6 @@ void DoBurmyFormChange(u32 monId); bool32 BlocksPrankster(u16 move, u8 battlerPrankster, u8 battlerDef, bool32 checkTarget); u16 GetUsedHeldItem(u8 battler); bool32 IsBattlerWeatherAffected(u8 battlerId, u32 weatherFlags); -void TryToApplyMimicry(u8 battlerId, bool8 various); -void TryToRevertMimicry(void); -void RestoreBattlerOriginalTypes(u8 battlerId); u32 GetBattlerMoveTargetType(u8 battlerId, u16 move); bool32 CanTargetBattler(u8 battlerAtk, u8 battlerDef, u16 move); bool8 IsMoveAffectedByParentalBond(u16 move, u8 battlerId); @@ -204,5 +201,6 @@ bool32 CanBeFrozen(u8 battlerId); bool32 CanBeConfused(u8 battlerId); bool32 IsBattlerTerrainAffected(u8 battlerId, u32 terrainFlag); u32 GetBattlerFriendshipScore(u8 battlerId); +void ChangeTypeBasedOnTerrain(u8 battlerId); #endif // GUARD_BATTLE_UTIL_H diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index 06a09fc17..91a471162 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -246,6 +246,7 @@ #define VARIOUS_CAN_TELEPORT 155 #define VARIOUS_GET_BATTLER_SIDE 156 #define VARIOUS_CHECK_PARENTAL_BOND_COUNTER 157 +#define VARIOUS_APPLY_MIMICRY 158 // Cmd_manipulatedamage #define DMG_CHANGE_SIGN 0 diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 09ef738df..55e0146e2 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -9590,7 +9590,6 @@ static void Cmd_various(void) break; } gFieldStatuses &= ~STATUS_FIELD_TERRAIN_ANY; // remove the terrain - TryToRevertMimicry(); // restore the types of Pokémon with Mimicry break; case VARIOUS_JUMP_IF_UNDER_200: // If the Pokemon is less than 200 kg, or weighing less than 441 lbs, then Sky Drop will work. Otherwise, it will fail. @@ -9939,21 +9938,6 @@ static void Cmd_various(void) else gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3); return; - case VARIOUS_TRY_TO_APPLY_MIMICRY: - { - bool8 isMimicryDone = FALSE; - - if (GetBattlerAbility(gActiveBattler) == ABILITY_MIMICRY) - { - TryToApplyMimicry(gActiveBattler, TRUE); - isMimicryDone = TRUE; - } - if (!isMimicryDone) - gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3); - else - gBattlescriptCurrInstr += 7; - return; - } case VARIOUS_JUMP_IF_CANT_FLING: if (!CanFling(gActiveBattler)) gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3); @@ -10070,6 +10054,9 @@ static void Cmd_various(void) return; } break; + case VARIOUS_APPLY_MIMICRY: + ChangeTypeBasedOnTerrain(gActiveBattler); + break; } // End of switch (gBattlescriptCurrInstr[2]) gBattlescriptCurrInstr += 3; diff --git a/src/battle_util.c b/src/battle_util.c index d8ec3f079..7e7ce212f 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -2073,57 +2073,6 @@ u8 GetImprisonedMovesCount(u8 battlerId, u16 move) return imprisonedMoves; } -void RestoreBattlerOriginalTypes(u8 battlerId) -{ - gBattleMons[battlerId].type1 = gSpeciesInfo[gBattleMons[battlerId].species].type1; - gBattleMons[battlerId].type2 = gSpeciesInfo[gBattleMons[battlerId].species].type2; -} - -void TryToApplyMimicry(u8 battlerId, bool8 various) -{ - u32 moveType, move; - - GET_MOVE_TYPE(move, moveType); - switch (gFieldStatuses) - { - case STATUS_FIELD_ELECTRIC_TERRAIN: - moveType = TYPE_ELECTRIC; - break; - case STATUS_FIELD_MISTY_TERRAIN: - moveType = TYPE_FAIRY; - break; - case STATUS_FIELD_GRASSY_TERRAIN: - moveType = TYPE_GRASS; - break; - case STATUS_FIELD_PSYCHIC_TERRAIN: - moveType = TYPE_PSYCHIC; - break; - default: - moveType = 0; - break; - } - - if (moveType != 0 && !IS_BATTLER_OF_TYPE(battlerId, moveType)) - { - SET_BATTLER_TYPE(battlerId, moveType); - PREPARE_MON_NICK_WITH_PREFIX_BUFFER(gBattleTextBuff1, battlerId, gBattlerPartyIndexes[battlerId]) - PREPARE_TYPE_BUFFER(gBattleTextBuff2, moveType); - if (!various) - BattleScriptPushCursorAndCallback(BattleScript_MimicryActivatesEnd3); - } -} - -void TryToRevertMimicry(void) -{ - s32 i; - - for (i = 0; i < MAX_BATTLERS_COUNT; i++) - { - if (GetBattlerAbility(i) == ABILITY_MIMICRY) - RestoreBattlerOriginalTypes(i); - } -} - u32 GetBattlerFriendshipScore(u8 battlerId) { u8 side = GetBattlerSide(battlerId); @@ -2143,6 +2092,17 @@ u32 GetBattlerFriendshipScore(u8 battlerId) return GetMonFriendshipScore(&party[gBattlerPartyIndexes[battlerId]]); } +static void TryToRevertMimicry(void) +{ + u8 i; + + for (i = 0; i < gBattlersCount; i++) + { + if (GetBattlerAbility(i) == ABILITY_MIMICRY) + RESTORE_BATTLER_TYPE(i); + } +} + enum { ENDTURN_ORDER, @@ -4355,6 +4315,32 @@ static u8 ForewarnChooseMove(u32 battler) Free(data); } +void ChangeTypeBasedOnTerrain(u8 battlerId) +{ + u16 moveType, move; + u16 terrainFlags = VarGet(VAR_TERRAIN) & STATUS_FIELD_TERRAIN_ANY; + + if (terrainFlags && gFieldStatuses & STATUS_FIELD_TERRAIN_ANY) + gFieldStatuses = terrainFlags | STATUS_FIELD_TERRAIN_PERMANENT; // terrain is permanent + + GET_MOVE_TYPE(move, moveType); + { + if (gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN) + moveType = TYPE_ELECTRIC; + else if (gFieldStatuses & STATUS_FIELD_GRASSY_TERRAIN) + moveType = TYPE_GRASS; + else if (gFieldStatuses & STATUS_FIELD_MISTY_TERRAIN) + moveType = TYPE_FAIRY; + else if (gFieldStatuses & STATUS_FIELD_PSYCHIC_TERRAIN) + moveType = TYPE_PSYCHIC; + else // failsafe + moveType = gSpeciesInfo[battlerId].type1; + } + SET_BATTLER_TYPE(battlerId, moveType); + PREPARE_MON_NICK_WITH_PREFIX_BUFFER(gBattleTextBuff1, battlerId, gBattlerPartyIndexes[battlerId]) + PREPARE_TYPE_BUFFER(gBattleTextBuff2, moveType); +} + u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 moveArg) { u8 effect = 0; @@ -4866,9 +4852,11 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move } break; case ABILITY_MIMICRY: - if (gBattleMons[battler].hp != 0 && gFieldStatuses & STATUS_FIELD_TERRAIN_ANY) + if (gFieldStatuses & STATUS_FIELD_TERRAIN_ANY && !gSpecialStatuses[battler].switchInAbilityDone) { - TryToApplyMimicry(battler, FALSE); + ChangeTypeBasedOnTerrain(battler); + BattleScriptPushCursorAndCallback(BattleScript_MimicryActivates_End3); + gSpecialStatuses[battler].switchInAbilityDone = TRUE; effect++; } break; From f1ca254c28d85f563f66bc7bdd33f441135ceec9 Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Mon, 2 Jan 2023 18:37:27 -0300 Subject: [PATCH 2/6] Updated the Mimicry reimplementation Mimicry is now a proud member of ABILITYEFFECT_ON_TERRAIN. Misc. changes: -Ditched the dependency on and usage of gBattlerAttacker for the effects inside ABILITYEFFECT_ON_WEATHER and ABILITYEFFECT_ON_TERRAIN. -Made Cmd_switchineffects activate ABILITYEFFECT_ON_TERRAIN to take into account overworld weather-induced field terrains. -Updated the text strings printed by the battle scripts inside the aforementioned AbilityBattleEffects caseIDs. -Removed constant label of unused VARIOUS_TRY_TO_APPLY_MIMICRY which I forgot about. -Updated ChangeTypeBasedOnTerrain, partly as a result of the aforementioned changes but also for optimization purposes. -There was never a reason to establish an empty scope, or to use GET_MOVE_TYPE and the variables that complemented it. -Removed case ABILITY_QUARK_DRIVE from AbilityBattleEffects' case ABILITYEFFECT_ON_SWITCHIN. --- asm/macros/battle_script.inc | 4 -- data/battle_scripts_1.s | 18 ----- include/battle.h | 1 + include/constants/battle_script_commands.h | 78 +++++++++++----------- src/battle_message.c | 8 +-- src/battle_script_commands.c | 10 ++- src/battle_util.c | 66 ++++++++---------- 7 files changed, 74 insertions(+), 111 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index d97dcb825..c29d8f7c4 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -2037,10 +2037,6 @@ various \battler, VARIOUS_ACTIVATE_TERRAIN_CHANGE_ABILITIES .endm - .macro applymimicry battler:req - various \battler, VARIOUS_APPLY_MIMICRY - .endm - @ helpful macros .macro setstatchanger stat:req, stages:req, down:req setbyte sSTATCHANGER, \stat | \stages << 3 | \down << 7 diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 21f424fe1..f9320a77d 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -2526,26 +2526,8 @@ BattleScript_EffectPsychicTerrain: playanimation BS_ATTACKER, B_ANIM_RESTORE_BG call BattleScript_ActivateTerrainAbilities call BattleScript_TerrainSeedLoop - call BattleScript_TryToApplyMimicry goto BattleScript_MoveEnd -BattleScript_TryToApplyMimicry: - savetarget - setbyte gBattlerTarget, 0 -BattleScript_TryToApplyMimicry_Loop: - jumpifword CMP_NOT_EQUAL, gFieldStatuses, STATUS_FIELD_TERRAIN_ANY, BattleScript_TryToApplyMimicry_Increment - jumpifability BS_TARGET, ABILITY_MIMICRY, BattleScript_TryToApplyMimicry_Effect -BattleScript_TryToApplyMimicry_Effect: - pause B_WAIT_TIME_SHORT - call BattleScript_AbilityPopUp - applymimicry BS_TARGET - printstring STRINGID_BATTLERTYPECHANGEDTO - waitmessage B_WAIT_TIME_SHORT -BattleScript_TryToApplyMimicry_Increment: - addbyte gBattlerTarget, 1 - jumpifbytenotequal gBattlerTarget, gBattlersCount, BattleScript_TryToApplyMimicry_Loop - return - BattleScript_EffectTopsyTurvy: attackcanceler attackstring diff --git a/include/battle.h b/include/battle.h index 8242d91d4..71eb3b1a8 100644 --- a/include/battle.h +++ b/include/battle.h @@ -192,6 +192,7 @@ struct SpecialStatus u8 dancerUsedMove:1; u8 dancerOriginalTarget:3; // End of byte + u8 terrainAbilityDone:1; }; struct SideTimer diff --git a/include/constants/battle_script_commands.h b/include/constants/battle_script_commands.h index e295609e0..a13423bcb 100644 --- a/include/constants/battle_script_commands.h +++ b/include/constants/battle_script_commands.h @@ -216,46 +216,44 @@ #define VARIOUS_JUMP_IF_WEATHER_AFFECTED 125 #define VARIOUS_JUMP_IF_LEAF_GUARD_PROTECTED 126 #define VARIOUS_SET_ATTACKER_STICKY_WEB_USER 127 -#define VARIOUS_TRY_TO_APPLY_MIMICRY 128 -#define VARIOUS_PHOTON_GEYSER_CHECK 129 -#define VARIOUS_SHELL_SIDE_ARM_CHECK 130 -#define VARIOUS_TRY_NO_RETREAT 131 -#define VARIOUS_TRY_TAR_SHOT 132 -#define VARIOUS_CAN_TAR_SHOT_WORK 133 -#define VARIOUS_CHECK_POLTERGEIST 134 -#define VARIOUS_SET_OCTOLOCK 135 -#define VARIOUS_CUT_1_3_HP_RAISE_STATS 136 -#define VARIOUS_TRY_END_NEUTRALIZING_GAS 137 -#define VARIOUS_JUMP_IF_UNDER_200 138 -#define VARIOUS_SET_SKY_DROP 139 -#define VARIOUS_CLEAR_SKY_DROP 140 -#define VARIOUS_SKY_DROP_YAWN 141 -#define VARIOUS_JUMP_IF_CANT_FLING 142 -#define VARIOUS_JUMP_IF_HOLD_EFFECT 143 -#define VARIOUS_CURE_CERTAIN_STATUSES 144 -#define VARIOUS_TRY_RESET_NEGATIVE_STAT_STAGES 145 -#define VARIOUS_JUMP_IF_LAST_USED_ITEM_BERRY 146 -#define VARIOUS_JUMP_IF_LAST_USED_ITEM_HOLD_EFFECT 147 -#define VARIOUS_SAVE_BATTLER_ITEM 148 -#define VARIOUS_RESTORE_BATTLER_ITEM 149 -#define VARIOUS_BATTLER_ITEM_TO_LAST_USED_ITEM 150 -#define VARIOUS_SET_BEAK_BLAST 151 -#define VARIOUS_SWAP_SIDE_STATUSES 152 -#define VARIOUS_SET_Z_EFFECT 153 -#define VARIOUS_TRY_SYMBIOSIS 154 -#define VARIOUS_CAN_TELEPORT 155 -#define VARIOUS_GET_BATTLER_SIDE 156 -#define VARIOUS_CHECK_PARENTAL_BOND_COUNTER 157 -#define VARIOUS_SWAP_STATS 158 -#define VARIOUS_JUMP_IF_ROD 159 -#define VARIOUS_JUMP_IF_ABSORB 160 -#define VARIOUS_JUMP_IF_MOTOR 161 -#define VARIOUS_TEATIME_INVUL 162 -#define VARIOUS_TEATIME_TARGETS 163 -#define VARIOUS_TRY_WIND_RIDER_POWER 164 -#define VARIOUS_ACTIVATE_WEATHER_CHANGE_ABILITIES 165 -#define VARIOUS_ACTIVATE_TERRAIN_CHANGE_ABILITIES 166 -#define VARIOUS_APPLY_MIMICRY 167 +#define VARIOUS_PHOTON_GEYSER_CHECK 128 +#define VARIOUS_SHELL_SIDE_ARM_CHECK 129 +#define VARIOUS_TRY_NO_RETREAT 130 +#define VARIOUS_TRY_TAR_SHOT 131 +#define VARIOUS_CAN_TAR_SHOT_WORK 132 +#define VARIOUS_CHECK_POLTERGEIST 133 +#define VARIOUS_SET_OCTOLOCK 134 +#define VARIOUS_CUT_1_3_HP_RAISE_STATS 135 +#define VARIOUS_TRY_END_NEUTRALIZING_GAS 136 +#define VARIOUS_JUMP_IF_UNDER_200 137 +#define VARIOUS_SET_SKY_DROP 138 +#define VARIOUS_CLEAR_SKY_DROP 139 +#define VARIOUS_SKY_DROP_YAWN 140 +#define VARIOUS_JUMP_IF_CANT_FLING 141 +#define VARIOUS_JUMP_IF_HOLD_EFFECT 142 +#define VARIOUS_CURE_CERTAIN_STATUSES 143 +#define VARIOUS_TRY_RESET_NEGATIVE_STAT_STAGES 144 +#define VARIOUS_JUMP_IF_LAST_USED_ITEM_BERRY 145 +#define VARIOUS_JUMP_IF_LAST_USED_ITEM_HOLD_EFFECT 146 +#define VARIOUS_SAVE_BATTLER_ITEM 147 +#define VARIOUS_RESTORE_BATTLER_ITEM 148 +#define VARIOUS_BATTLER_ITEM_TO_LAST_USED_ITEM 149 +#define VARIOUS_SET_BEAK_BLAST 150 +#define VARIOUS_SWAP_SIDE_STATUSES 151 +#define VARIOUS_SET_Z_EFFECT 152 +#define VARIOUS_TRY_SYMBIOSIS 153 +#define VARIOUS_CAN_TELEPORT 154 +#define VARIOUS_GET_BATTLER_SIDE 155 +#define VARIOUS_CHECK_PARENTAL_BOND_COUNTER 156 +#define VARIOUS_SWAP_STATS 157 +#define VARIOUS_JUMP_IF_ROD 158 +#define VARIOUS_JUMP_IF_ABSORB 159 +#define VARIOUS_JUMP_IF_MOTOR 160 +#define VARIOUS_TEATIME_INVUL 161 +#define VARIOUS_TEATIME_TARGETS 162 +#define VARIOUS_TRY_WIND_RIDER_POWER 163 +#define VARIOUS_ACTIVATE_WEATHER_CHANGE_ABILITIES 164 +#define VARIOUS_ACTIVATE_TERRAIN_CHANGE_ABILITIES 165 // Cmd_manipulatedamage #define DMG_CHANGE_SIGN 0 diff --git a/src/battle_message.c b/src/battle_message.c index 1189cf3e1..c1ebe8d79 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -740,7 +740,7 @@ static const u8 sText_AbilityAllowsOnlyMove[] = _("{B_ATK_ABILITY} allows the\nu static const u8 sText_SwappedAbilities[] = _("{B_DEF_NAME_WITH_PREFIX} swapped Abilities\nwith its target!"); static const u8 sText_PastelVeilProtected[] = _("{B_DEF_NAME_WITH_PREFIX} is protected\nby a pastel veil!"); static const u8 sText_PastelVeilEnters[] = _("{B_DEF_NAME_WITH_PREFIX} was cured\nof its poisoning!"); -static const u8 sText_BattlerTypeChangedTo[] = _("{B_BUFF1}'s type\nchanged to {B_BUFF2}!"); +static const u8 sText_BattlerTypeChangedTo[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX}'s type\nchanged to {B_BUFF1}!"); static const u8 sText_BothCanNoLongerEscape[] = _("Neither Pokémon can run away!"); static const u8 sText_CantEscapeDueToUsedMove[] = _("{B_ATK_NAME_WITH_PREFIX} can no longer escape\nbecause it used {B_CURRENT_MOVE}!"); static const u8 sText_PkmnBecameWeakerToFire[] = _("{B_DEF_NAME_WITH_PREFIX} became\nweaker to fire!"); @@ -762,9 +762,9 @@ static const u8 sText_TargetToughedItOut[] = _("{B_DEF_NAME_WITH_PREFIX} toughed static const u8 sText_AttackerLostElectricType[] = _("{B_ATK_NAME_WITH_PREFIX} used up all\nof its electricity!"); static const u8 sText_AttackerSwitchedStatWithTarget[] = _("{B_ATK_NAME_WITH_PREFIX} switched {B_BUFF1}\nwith its target!"); static const u8 sText_BeingHitChargedPkmnWithPower[] = _("Being hit by {B_CURRENT_MOVE}\ncharged {B_ATK_NAME_WITH_PREFIX} with power!"); -static const u8 sText_SunlightActivatedAbility[] = _("The harsh sunlight activated\n{B_ATK_NAME_WITH_PREFIX}'s {B_ATK_ABILITY}!"); -static const u8 sText_StatWasHeightened[] = _("{B_ATK_NAME_WITH_PREFIX}'s {B_BUFF1} was heightened!"); -static const u8 sText_ElectricTerrainActivatedAbility[] = _("The Electric Terrain activated\n{B_ATK_NAME_WITH_PREFIX}'s {B_ATK_ABILITY}!"); +static const u8 sText_SunlightActivatedAbility[] = _("The harsh sunlight activated\n{B_SCR_ACTIVE_NAME_WITH_PREFIX}'s {B_LAST_ABILITY}!"); +static const u8 sText_StatWasHeightened[] = _("{B_SCR_ACTIVE_NAME_WITH_PREFIX}'s {B_BUFF1} was heightened!"); +static const u8 sText_ElectricTerrainActivatedAbility[] = _("The Electric Terrain activated\n{B_SCR_ACTIVE_NAME_WITH_PREFIX}'s {B_LAST_ABILITY}!"); static const u8 sText_AbilityWeakenedSurroundingMonsStat[] = _("{B_ATK_NAME_WITH_PREFIX}'s {B_ATK_ABILITY}\nweakened the {B_BUFF1} of\lall surrounding Pokémon!\p"); static const u8 sText_AttackerGainedStrengthFromTheFallen[] = _("{B_ATK_NAME_WITH_PREFIX} gained strength\nfrom the fallen!"); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index d03d04cb6..26c82fc74 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -6785,9 +6785,10 @@ static void Cmd_switchineffects(void) gDisableStructs[gActiveBattler].truantSwitchInHack = 0; if (AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, gActiveBattler, 0, 0, 0) - || ItemBattleEffects(ITEMEFFECT_ON_SWITCH_IN, gActiveBattler, FALSE) - || AbilityBattleEffects(ABILITYEFFECT_TRACE2, 0, 0, 0, 0) - || AbilityBattleEffects(ABILITYEFFECT_WEATHER_FORM, 0, 0, 0, 0)) + || (gFieldStatuses & STATUS_FIELD_TERRAIN_ANY && AbilityBattleEffects(ABILITYEFFECT_ON_TERRAIN, gActiveBattler, 0, 0, 0)) + || ItemBattleEffects(ITEMEFFECT_ON_SWITCH_IN, gActiveBattler, FALSE) + || AbilityBattleEffects(ABILITYEFFECT_TRACE2, 0, 0, 0, 0) + || AbilityBattleEffects(ABILITYEFFECT_WEATHER_FORM, 0, 0, 0, 0)) return; gSideStatuses[GetBattlerSide(gActiveBattler)] &= ~(SIDE_STATUS_SPIKES_DAMAGED | SIDE_STATUS_TOXIC_SPIKES_DAMAGED | SIDE_STATUS_STEALTH_ROCK_DAMAGED | SIDE_STATUS_STICKY_WEB_DAMAGED); @@ -10209,9 +10210,6 @@ static void Cmd_various(void) gBattlescriptCurrInstr += 3; AbilityBattleEffects(ABILITYEFFECT_ON_TERRAIN, gActiveBattler, 0, 0, 0); return; - case VARIOUS_APPLY_MIMICRY: - ChangeTypeBasedOnTerrain(gActiveBattler); - break; } // End of switch (gBattlescriptCurrInstr[2]) gBattlescriptCurrInstr += 3; diff --git a/src/battle_util.c b/src/battle_util.c index 85f9e73bf..dac4e00f5 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -4297,28 +4297,24 @@ static u8 ForewarnChooseMove(u32 battler) void ChangeTypeBasedOnTerrain(u8 battlerId) { - u16 moveType, move; + u8 battlerType; u16 terrainFlags = VarGet(VAR_TERRAIN) & STATUS_FIELD_TERRAIN_ANY; if (terrainFlags && gFieldStatuses & STATUS_FIELD_TERRAIN_ANY) gFieldStatuses = terrainFlags | STATUS_FIELD_TERRAIN_PERMANENT; // terrain is permanent - GET_MOVE_TYPE(move, moveType); - { - if (gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN) - moveType = TYPE_ELECTRIC; - else if (gFieldStatuses & STATUS_FIELD_GRASSY_TERRAIN) - moveType = TYPE_GRASS; - else if (gFieldStatuses & STATUS_FIELD_MISTY_TERRAIN) - moveType = TYPE_FAIRY; - else if (gFieldStatuses & STATUS_FIELD_PSYCHIC_TERRAIN) - moveType = TYPE_PSYCHIC; - else // failsafe - moveType = gSpeciesInfo[battlerId].type1; - } - SET_BATTLER_TYPE(battlerId, moveType); - PREPARE_MON_NICK_WITH_PREFIX_BUFFER(gBattleTextBuff1, battlerId, gBattlerPartyIndexes[battlerId]) - PREPARE_TYPE_BUFFER(gBattleTextBuff2, moveType); + if (gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN) + battlerType = TYPE_ELECTRIC; + else if (gFieldStatuses & STATUS_FIELD_GRASSY_TERRAIN) + battlerType = TYPE_GRASS; + else if (gFieldStatuses & STATUS_FIELD_MISTY_TERRAIN) + battlerType = TYPE_FAIRY; + else if (gFieldStatuses & STATUS_FIELD_PSYCHIC_TERRAIN) + battlerType = TYPE_PSYCHIC; + else // failsafe + battlerType = gSpeciesInfo[battlerId].type1; + SET_BATTLER_TYPE(battlerId, battlerType); + PREPARE_TYPE_BUFFER(gBattleTextBuff1, battlerType); } u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 moveArg) @@ -4821,15 +4817,6 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move effect++; } break; - case ABILITY_MIMICRY: - if (gFieldStatuses & STATUS_FIELD_TERRAIN_ANY && !gSpecialStatuses[battler].switchInAbilityDone) - { - ChangeTypeBasedOnTerrain(battler); - BattleScriptPushCursorAndCallback(BattleScript_MimicryActivates_End3); - gSpecialStatuses[battler].switchInAbilityDone = TRUE; - effect++; - } - break; case ABILITY_PROTOSYNTHESIS: if (!gSpecialStatuses[battler].switchInAbilityDone && gBattleWeather & B_WEATHER_SUN) { @@ -4839,15 +4826,6 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move effect++; } break; - case ABILITY_QUARK_DRIVE: - if (!gSpecialStatuses[battler].switchInAbilityDone && gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN) - { - gSpecialStatuses[battler].switchInAbilityDone = TRUE; - PREPARE_STAT_BUFFER(gBattleTextBuff1, GetHighestStatId(battler)); - BattleScriptPushCursorAndCallback(BattleScript_QuarkDriveActivates); - effect++; - } - break; case ABILITY_VESSEL_OF_RUIN: if (!gSpecialStatuses[battler].switchInAbilityDone) { @@ -6197,7 +6175,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move } break; case ABILITYEFFECT_ON_WEATHER: // For ability effects that activate when the battle weather changes. - battler = gBattlerAbility = gBattlerAttacker = gBattleScripting.battler; + battler = gBattlerAbility = gBattleScripting.battler; switch (GetBattlerAbility(battler)) { case ABILITY_FORECAST: @@ -6224,12 +6202,22 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move } break; case ABILITYEFFECT_ON_TERRAIN: // For ability effects that activate when the field terrain changes. - battler = gBattlerAbility = gBattlerAttacker = gBattleScripting.battler; + battler = gBattlerAbility = gBattleScripting.battler; switch (GetBattlerAbility(battler)) { - case ABILITY_QUARK_DRIVE: - if (IsBattlerTerrainAffected(battler, STATUS_FIELD_ELECTRIC_TERRAIN)) + case ABILITY_MIMICRY: + if (!gSpecialStatuses[battler].terrainAbilityDone) { + gSpecialStatuses[battler].terrainAbilityDone = TRUE; + ChangeTypeBasedOnTerrain(battler); + BattleScriptPushCursorAndCallback(BattleScript_MimicryActivates_End3); + effect++; + } + break; + case ABILITY_QUARK_DRIVE: + if (!gSpecialStatuses[battler].terrainAbilityDone && IsBattlerTerrainAffected(battler, STATUS_FIELD_ELECTRIC_TERRAIN)) + { + gSpecialStatuses[battler].terrainAbilityDone = TRUE; PREPARE_STAT_BUFFER(gBattleTextBuff1, GetHighestStatId(battler)); BattleScriptPushCursorAndCallback(BattleScript_QuarkDriveActivates); effect++; From c32f5849400483772a9f40b36f7342d42c3dd4ff Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Sun, 8 Jan 2023 19:50:27 -0300 Subject: [PATCH 3/6] Applied review changes --- include/battle_util.h | 2 +- src/battle_util.c | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/battle_util.h b/include/battle_util.h index a1f0ad0e8..2c81a361d 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -204,6 +204,6 @@ bool32 IsBattlerTerrainAffected(u8 battlerId, u32 terrainFlag); u32 GetBattlerFriendshipScore(u8 battlerId); u32 CountBattlerStatIncreases(u8 battlerId, bool32 countEvasionAcc); bool32 IsMyceliumMightOnField(void); -void ChangeTypeBasedOnTerrain(u8 battlerId); +bool8 ChangeTypeBasedOnTerrain(u8 battlerId); #endif // GUARD_BATTLE_UTIL_H diff --git a/src/battle_util.c b/src/battle_util.c index dac4e00f5..0145babc7 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -2069,7 +2069,7 @@ u32 GetBattlerFriendshipScore(u8 battlerId) static void TryToRevertMimicry(void) { - u8 i; + u32 i; for (i = 0; i < gBattlersCount; i++) { @@ -4295,7 +4295,7 @@ static u8 ForewarnChooseMove(u32 battler) Free(data); } -void ChangeTypeBasedOnTerrain(u8 battlerId) +bool8 ChangeTypeBasedOnTerrain(u8 battlerId) { u8 battlerType; u16 terrainFlags = VarGet(VAR_TERRAIN) & STATUS_FIELD_TERRAIN_ANY; @@ -4312,9 +4312,11 @@ void ChangeTypeBasedOnTerrain(u8 battlerId) else if (gFieldStatuses & STATUS_FIELD_PSYCHIC_TERRAIN) battlerType = TYPE_PSYCHIC; else // failsafe - battlerType = gSpeciesInfo[battlerId].type1; + return FALSE; + SET_BATTLER_TYPE(battlerId, battlerType); PREPARE_TYPE_BUFFER(gBattleTextBuff1, battlerType); + return TRUE; } u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 moveArg) @@ -6206,7 +6208,7 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move switch (GetBattlerAbility(battler)) { case ABILITY_MIMICRY: - if (!gSpecialStatuses[battler].terrainAbilityDone) + if (!gSpecialStatuses[battler].terrainAbilityDone && ChangeTypeBasedOnTerrain(battler)) { gSpecialStatuses[battler].terrainAbilityDone = TRUE; ChangeTypeBasedOnTerrain(battler); From 91b2e1bb50288cc56e2a10c30b1a452b4c736eab Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Mon, 9 Jan 2023 07:53:59 -0300 Subject: [PATCH 4/6] More review changes and added lackings -Removed unnecessary special handling of terrain-inducing overworld weather states from ChangeTypeBasedOnTerrain. -Mimicry now activates normally for terrain-inducing overworld weather states. -Weather abilities now activate normally when switchineffects is called, and at the beginning of a battle. -Terrain abilities now activate normally at the beginning of a battle. --- data/battle_scripts_1.s | 1 + src/battle_main.c | 4 ++++ src/battle_script_commands.c | 1 + src/battle_util.c | 4 ---- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index f9320a77d..1c4b82883 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -8629,6 +8629,7 @@ BattleScript_TerrainSeedLoop_NextBattler: addbyte gBattlerTarget, 0x1 jumpifbytenotequal gBattlerTarget, gBattlersCount, BattleScript_TerrainSeedLoopIter restoretarget + call BattleScript_ActivateSwitchInAbilities return BattleScript_ActivateSwitchInAbilities: diff --git a/src/battle_main.c b/src/battle_main.c index 56b009cbb..ab3ce58be 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3720,6 +3720,10 @@ static void TryDoEventsBeforeFirstTurn(void) gBattlerAttacker = gBattlerByTurnOrder[gBattleStruct->switchInAbilitiesCounter++]; if (AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, gBattlerAttacker, 0, 0, 0) != 0) return; + if (gBattleWeather & B_WEATHER_ANY && WEATHER_HAS_EFFECT && AbilityBattleEffects(ABILITYEFFECT_ON_WEATHER, gActiveBattler, 0, 0, 0) != 0) + return; + if (gFieldStatuses & STATUS_FIELD_TERRAIN_ANY && AbilityBattleEffects(ABILITYEFFECT_ON_TERRAIN, gActiveBattler, 0, 0, 0) != 0) + return; } if (AbilityBattleEffects(ABILITYEFFECT_TRACE1, 0, 0, 0, 0) != 0) return; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 26c82fc74..aad5b763a 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -6785,6 +6785,7 @@ static void Cmd_switchineffects(void) gDisableStructs[gActiveBattler].truantSwitchInHack = 0; if (AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, gActiveBattler, 0, 0, 0) + || (gBattleWeather & B_WEATHER_ANY && WEATHER_HAS_EFFECT && AbilityBattleEffects(ABILITYEFFECT_ON_WEATHER, gActiveBattler, 0, 0, 0)) || (gFieldStatuses & STATUS_FIELD_TERRAIN_ANY && AbilityBattleEffects(ABILITYEFFECT_ON_TERRAIN, gActiveBattler, 0, 0, 0)) || ItemBattleEffects(ITEMEFFECT_ON_SWITCH_IN, gActiveBattler, FALSE) || AbilityBattleEffects(ABILITYEFFECT_TRACE2, 0, 0, 0, 0) diff --git a/src/battle_util.c b/src/battle_util.c index 0145babc7..b3b1379f1 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -4298,10 +4298,6 @@ static u8 ForewarnChooseMove(u32 battler) bool8 ChangeTypeBasedOnTerrain(u8 battlerId) { u8 battlerType; - u16 terrainFlags = VarGet(VAR_TERRAIN) & STATUS_FIELD_TERRAIN_ANY; - - if (terrainFlags && gFieldStatuses & STATUS_FIELD_TERRAIN_ANY) - gFieldStatuses = terrainFlags | STATUS_FIELD_TERRAIN_PERMANENT; // terrain is permanent if (gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN) battlerType = TYPE_ELECTRIC; From 620a6a5e90c343eb9e45b51909f7c39105f8a88c Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Mon, 9 Jan 2023 13:41:48 -0300 Subject: [PATCH 5/6] Extra review changes -Foolproofed the ability checks in ABILITYEFFECT_ON_WEATHER and ABILITYEFFECT_ON_TERRAIN -Made BattleScript_OverworldWeatherStarts and BattleScript_OverworldTerrain call the battle scripts that handle weather form changes, weather abilities, terrain seeds and terrain abilities. -Consequentially, I removed the activation for weather and terrain abilities that I added to TryDoEventsBeforeFirstTurn, and the activation of Protosynthesis in ABILITYEFFECT_ON_SWITCHIN. -Added a weatherAbilityDone to prevent abilities that lack self-checks like Protosynthesis from getting stuck in a loop. -Removed now pointless ABILITYEFFECT_WEATHER_FORM. I think Duke/Sneed69 added it to fix Castform's form change, but it no longer serves a purpose. --- data/battle_scripts_1.s | 2 ++ include/battle.h | 1 + include/battle_util.h | 19 ++++++++------- src/battle_main.c | 4 ---- src/battle_script_commands.c | 3 +-- src/battle_util.c | 45 ++++++------------------------------ 6 files changed, 20 insertions(+), 54 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 1c4b82883..08da49fd0 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -6708,12 +6708,14 @@ BattleScript_OverworldWeatherStarts:: printfromtable gWeatherStartsStringIds waitmessage B_WAIT_TIME_LONG playanimation_var BS_ATTACKER, sB_ANIM_ARG1 + call BattleScript_WeatherFormChanges end3 BattleScript_OverworldTerrain:: printfromtable gTerrainStringIds waitmessage B_WAIT_TIME_LONG playanimation BS_SCRIPTING, B_ANIM_RESTORE_BG + call BattleScript_TerrainSeedLoop end3 BattleScript_SideStatusWoreOff:: diff --git a/include/battle.h b/include/battle.h index 71eb3b1a8..8af8be77c 100644 --- a/include/battle.h +++ b/include/battle.h @@ -192,6 +192,7 @@ struct SpecialStatus u8 dancerUsedMove:1; u8 dancerOriginalTarget:3; // End of byte + u8 weatherAbilityDone:1; u8 terrainAbilityDone:1; }; diff --git a/include/battle_util.h b/include/battle_util.h index 2c81a361d..1c3f486cd 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -26,16 +26,15 @@ #define ABILITYEFFECT_MOVE_END_ATTACKER 4 #define ABILITYEFFECT_MOVE_END 5 #define ABILITYEFFECT_IMMUNITY 6 -#define ABILITYEFFECT_WEATHER_FORM 7 -#define ABILITYEFFECT_SYNCHRONIZE 8 -#define ABILITYEFFECT_ATK_SYNCHRONIZE 9 -#define ABILITYEFFECT_TRACE1 10 -#define ABILITYEFFECT_TRACE2 11 -#define ABILITYEFFECT_MOVE_END_OTHER 12 -#define ABILITYEFFECT_NEUTRALIZINGGAS 13 -#define ABILITYEFFECT_FIELD_SPORT 14 // Only used if B_SPORT_TURNS < GEN_6 -#define ABILITYEFFECT_ON_WEATHER 15 -#define ABILITYEFFECT_ON_TERRAIN 16 +#define ABILITYEFFECT_SYNCHRONIZE 7 +#define ABILITYEFFECT_ATK_SYNCHRONIZE 8 +#define ABILITYEFFECT_TRACE1 9 +#define ABILITYEFFECT_TRACE2 10 +#define ABILITYEFFECT_MOVE_END_OTHER 11 +#define ABILITYEFFECT_NEUTRALIZINGGAS 12 +#define ABILITYEFFECT_FIELD_SPORT 13 // Only used if B_SPORT_TURNS < GEN_6 +#define ABILITYEFFECT_ON_WEATHER 14 +#define ABILITYEFFECT_ON_TERRAIN 15 // Special cases #define ABILITYEFFECT_MUD_SPORT 252 // Only used if B_SPORT_TURNS < GEN_6 #define ABILITYEFFECT_WATER_SPORT 253 // Only used if B_SPORT_TURNS < GEN_6 diff --git a/src/battle_main.c b/src/battle_main.c index ab3ce58be..56b009cbb 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3720,10 +3720,6 @@ static void TryDoEventsBeforeFirstTurn(void) gBattlerAttacker = gBattlerByTurnOrder[gBattleStruct->switchInAbilitiesCounter++]; if (AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, gBattlerAttacker, 0, 0, 0) != 0) return; - if (gBattleWeather & B_WEATHER_ANY && WEATHER_HAS_EFFECT && AbilityBattleEffects(ABILITYEFFECT_ON_WEATHER, gActiveBattler, 0, 0, 0) != 0) - return; - if (gFieldStatuses & STATUS_FIELD_TERRAIN_ANY && AbilityBattleEffects(ABILITYEFFECT_ON_TERRAIN, gActiveBattler, 0, 0, 0) != 0) - return; } if (AbilityBattleEffects(ABILITYEFFECT_TRACE1, 0, 0, 0, 0) != 0) return; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index aad5b763a..5f79c0779 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -6788,8 +6788,7 @@ static void Cmd_switchineffects(void) || (gBattleWeather & B_WEATHER_ANY && WEATHER_HAS_EFFECT && AbilityBattleEffects(ABILITYEFFECT_ON_WEATHER, gActiveBattler, 0, 0, 0)) || (gFieldStatuses & STATUS_FIELD_TERRAIN_ANY && AbilityBattleEffects(ABILITYEFFECT_ON_TERRAIN, gActiveBattler, 0, 0, 0)) || ItemBattleEffects(ITEMEFFECT_ON_SWITCH_IN, gActiveBattler, FALSE) - || AbilityBattleEffects(ABILITYEFFECT_TRACE2, 0, 0, 0, 0) - || AbilityBattleEffects(ABILITYEFFECT_WEATHER_FORM, 0, 0, 0, 0)) + || AbilityBattleEffects(ABILITYEFFECT_TRACE2, 0, 0, 0, 0)) return; gSideStatuses[GetBattlerSide(gActiveBattler)] &= ~(SIDE_STATUS_SPIKES_DAMAGED | SIDE_STATUS_TOXIC_SPIKES_DAMAGED | SIDE_STATUS_STEALTH_ROCK_DAMAGED | SIDE_STATUS_STICKY_WEB_DAMAGED); diff --git a/src/battle_util.c b/src/battle_util.c index b3b1379f1..75460df9f 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -2556,7 +2556,7 @@ u8 DoFieldEndTurnEffects(void) gBattleStruct->turnCountersTracker++; break; case ENDTURN_WEATHER_FORM: - AbilityBattleEffects(ABILITYEFFECT_WEATHER_FORM, 0, 0, 0, 0); + AbilityBattleEffects(ABILITYEFFECT_ON_WEATHER, 0, 0, 0, 0); gBattleStruct->turnCountersTracker++; break; case ENDTURN_STATUS_HEAL: @@ -4815,15 +4815,6 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move effect++; } break; - case ABILITY_PROTOSYNTHESIS: - if (!gSpecialStatuses[battler].switchInAbilityDone && gBattleWeather & B_WEATHER_SUN) - { - gSpecialStatuses[battler].switchInAbilityDone = TRUE; - PREPARE_STAT_BUFFER(gBattleTextBuff1, GetHighestStatId(battler)); - BattleScriptPushCursorAndCallback(BattleScript_ProtosynthesisActivates); - effect++; - } - break; case ABILITY_VESSEL_OF_RUIN: if (!gSpecialStatuses[battler].switchInAbilityDone) { @@ -6008,31 +5999,6 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move } } break; - case ABILITYEFFECT_WEATHER_FORM: // 6 - for (battler = 0; battler < gBattlersCount; battler++) - { - switch (gBattleMons[battler].species) - { - case SPECIES_CASTFORM: - case SPECIES_CHERRIM: -#ifdef POKEMON_EXPANSION - case SPECIES_CASTFORM_RAINY: - case SPECIES_CASTFORM_SNOWY: - case SPECIES_CASTFORM_SUNNY: - case SPECIES_CHERRIM_SUNSHINE: -#endif - effect = TryWeatherFormChange(battler); - if (effect != 0) - { - BattleScriptPushCursorAndCallback(BattleScript_WeatherFormChange); - gBattleScripting.battler = battler; - gBattleStruct->formToChangeInto = effect - 1; - return effect; - } - break; - } - } - break; case ABILITYEFFECT_SYNCHRONIZE: if (gLastUsedAbility == ABILITY_SYNCHRONIZE && (gHitMarker & HITMARKER_SYNCHRONISE_EFFECT)) { @@ -6174,7 +6140,8 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move break; case ABILITYEFFECT_ON_WEATHER: // For ability effects that activate when the battle weather changes. battler = gBattlerAbility = gBattleScripting.battler; - switch (GetBattlerAbility(battler)) + gLastUsedAbility = GetBattlerAbility(battler); + switch (gLastUsedAbility) { case ABILITY_FORECAST: #if B_WEATHER_FORMS >= GEN_5 @@ -6190,8 +6157,9 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move } break; case ABILITY_PROTOSYNTHESIS: - if (IsBattlerWeatherAffected(battler, B_WEATHER_SUN)) + if (!gSpecialStatuses[battler].terrainAbilityDone && IsBattlerWeatherAffected(battler, B_WEATHER_SUN)) { + gSpecialStatuses[battler].terrainAbilityDone = TRUE; PREPARE_STAT_BUFFER(gBattleTextBuff1, GetHighestStatId(battler)); BattleScriptPushCursorAndCallback(BattleScript_ProtosynthesisActivates); effect++; @@ -6201,7 +6169,8 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move break; case ABILITYEFFECT_ON_TERRAIN: // For ability effects that activate when the field terrain changes. battler = gBattlerAbility = gBattleScripting.battler; - switch (GetBattlerAbility(battler)) + gLastUsedAbility = GetBattlerAbility(battler); + switch (gLastUsedAbility) { case ABILITY_MIMICRY: if (!gSpecialStatuses[battler].terrainAbilityDone && ChangeTypeBasedOnTerrain(battler)) From ba21ffb3f27d3e3599d99caff150ed796452d29a Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Mon, 9 Jan 2023 14:37:18 -0300 Subject: [PATCH 6/6] Oopsie. Protosynthesis is NOT a terrain ability --- src/battle_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/battle_util.c b/src/battle_util.c index 75460df9f..2782e55e0 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -6157,9 +6157,9 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move } break; case ABILITY_PROTOSYNTHESIS: - if (!gSpecialStatuses[battler].terrainAbilityDone && IsBattlerWeatherAffected(battler, B_WEATHER_SUN)) + if (!gSpecialStatuses[battler].weatherAbilityDone && IsBattlerWeatherAffected(battler, B_WEATHER_SUN)) { - gSpecialStatuses[battler].terrainAbilityDone = TRUE; + gSpecialStatuses[battler].weatherAbilityDone = TRUE; PREPARE_STAT_BUFFER(gBattleTextBuff1, GetHighestStatId(battler)); BattleScriptPushCursorAndCallback(BattleScript_ProtosynthesisActivates); effect++;