From 620a6a5e90c343eb9e45b51909f7c39105f8a88c Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Mon, 9 Jan 2023 13:41:48 -0300 Subject: [PATCH] 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))