diff --git a/include/battle_util.h b/include/battle_util.h index b1d0eeb1a..9976720ee 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -35,11 +35,11 @@ #define ABILITYEFFECT_FIELD_SPORT 13 // Only used if B_SPORT_TURNS < GEN_6 #define ABILITYEFFECT_ON_WEATHER 14 #define ABILITYEFFECT_ON_TERRAIN 15 +#define ABILITYEFFECT_SWITCH_IN_TERRAIN 16 +#define ABILITYEFFECT_SWITCH_IN_WEATHER 17 // 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 -#define ABILITYEFFECT_SWITCH_IN_TERRAIN 254 -#define ABILITYEFFECT_SWITCH_IN_WEATHER 255 // For the first argument of ItemBattleEffects, to deteremine which block of item effects to try #define ITEMEFFECT_ON_SWITCH_IN 0 diff --git a/src/battle_main.c b/src/battle_main.c index 758bc1cf8..6ba91a5bb 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -3823,13 +3823,13 @@ static void TryDoEventsBeforeFirstTurn(void) } } if (!gBattleStruct->overworldWeatherDone - && AbilityBattleEffects(0, 0, 0, ABILITYEFFECT_SWITCH_IN_WEATHER, 0) != 0) + && AbilityBattleEffects(ABILITYEFFECT_SWITCH_IN_WEATHER, 0, 0, ABILITYEFFECT_SWITCH_IN_WEATHER, 0) != 0) { gBattleStruct->overworldWeatherDone = TRUE; return; } - if (!gBattleStruct->terrainDone && AbilityBattleEffects(0, 0, 0, ABILITYEFFECT_SWITCH_IN_TERRAIN, 0) != 0) + if (!gBattleStruct->terrainDone && AbilityBattleEffects(ABILITYEFFECT_SWITCH_IN_TERRAIN, 0, 0, ABILITYEFFECT_SWITCH_IN_TERRAIN, 0) != 0) { gBattleStruct->terrainDone = TRUE; return; diff --git a/src/battle_util.c b/src/battle_util.c index a94f13bf2..06d6e4897 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -4157,84 +4157,86 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move switch (caseID) { + case ABILITYEFFECT_SWITCH_IN_TERRAIN: + gBattleScripting.battler = battler; + if (VarGet(VAR_TERRAIN) & STATUS_FIELD_TERRAIN_ANY) + { + u16 terrainFlags = VarGet(VAR_TERRAIN) & STATUS_FIELD_TERRAIN_ANY; // only works for status flag (1 << 15) + gFieldStatuses = terrainFlags | STATUS_FIELD_TERRAIN_PERMANENT; // terrain is permanent + switch (VarGet(VAR_TERRAIN) & STATUS_FIELD_TERRAIN_ANY) + { + case STATUS_FIELD_ELECTRIC_TERRAIN: + gBattleCommunication[MULTISTRING_CHOOSER] = 2; + break; + case STATUS_FIELD_MISTY_TERRAIN: + gBattleCommunication[MULTISTRING_CHOOSER] = 0; + break; + case STATUS_FIELD_GRASSY_TERRAIN: + gBattleCommunication[MULTISTRING_CHOOSER] = 1; + break; + case STATUS_FIELD_PSYCHIC_TERRAIN: + gBattleCommunication[MULTISTRING_CHOOSER] = 3; + break; + } + + BattleScriptPushCursorAndCallback(BattleScript_OverworldTerrain); + effect++; + } + #if B_THUNDERSTORM_TERRAIN == TRUE + else if (GetCurrentWeather() == WEATHER_RAIN_THUNDERSTORM && !(gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN)) + { + // overworld weather started rain, so just do electric terrain anim + gFieldStatuses = (STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_TERRAIN_PERMANENT); + gBattleCommunication[MULTISTRING_CHOOSER] = 2; + BattleScriptPushCursorAndCallback(BattleScript_OverworldTerrain); + effect++; + } + #endif + break; + case ABILITYEFFECT_SWITCH_IN_WEATHER: + gBattleScripting.battler = battler; + if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) + { + switch (GetCurrentWeather()) + { + case WEATHER_RAIN: + case WEATHER_RAIN_THUNDERSTORM: + case WEATHER_DOWNPOUR: + if (!(gBattleWeather & B_WEATHER_RAIN)) + { + gBattleWeather = (B_WEATHER_RAIN_TEMPORARY | B_WEATHER_RAIN_PERMANENT); + gBattleScripting.animArg1 = B_ANIM_RAIN_CONTINUES; + effect++; + } + break; + case WEATHER_SANDSTORM: + if (!(gBattleWeather & B_WEATHER_SANDSTORM)) + { + gBattleWeather = B_WEATHER_SANDSTORM; + gBattleScripting.animArg1 = B_ANIM_SANDSTORM_CONTINUES; + effect++; + } + break; + case WEATHER_DROUGHT: + if (!(gBattleWeather & B_WEATHER_SUN)) + { + gBattleWeather = (B_WEATHER_SUN_PERMANENT | B_WEATHER_SUN_TEMPORARY); + gBattleScripting.animArg1 = B_ANIM_SUN_CONTINUES; + effect++; + } + break; + } + } + if (effect != 0) + { + gBattleCommunication[MULTISTRING_CHOOSER] = GetCurrentWeather(); + BattleScriptPushCursorAndCallback(BattleScript_OverworldWeatherStarts); + } + break; case ABILITYEFFECT_ON_SWITCHIN: // 0 gBattleScripting.battler = battler; switch (gLastUsedAbility) { - case ABILITYEFFECT_SWITCH_IN_TERRAIN: - if (VarGet(VAR_TERRAIN) & STATUS_FIELD_TERRAIN_ANY) - { - u16 terrainFlags = VarGet(VAR_TERRAIN) & STATUS_FIELD_TERRAIN_ANY; // only works for status flag (1 << 15) - gFieldStatuses = terrainFlags | STATUS_FIELD_TERRAIN_PERMANENT; // terrain is permanent - switch (VarGet(VAR_TERRAIN) & STATUS_FIELD_TERRAIN_ANY) - { - case STATUS_FIELD_ELECTRIC_TERRAIN: - gBattleCommunication[MULTISTRING_CHOOSER] = 2; - break; - case STATUS_FIELD_MISTY_TERRAIN: - gBattleCommunication[MULTISTRING_CHOOSER] = 0; - break; - case STATUS_FIELD_GRASSY_TERRAIN: - gBattleCommunication[MULTISTRING_CHOOSER] = 1; - break; - case STATUS_FIELD_PSYCHIC_TERRAIN: - gBattleCommunication[MULTISTRING_CHOOSER] = 3; - break; - } - - BattleScriptPushCursorAndCallback(BattleScript_OverworldTerrain); - effect++; - } - #if B_THUNDERSTORM_TERRAIN == TRUE - else if (GetCurrentWeather() == WEATHER_RAIN_THUNDERSTORM && !(gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN)) - { - // overworld weather started rain, so just do electric terrain anim - gFieldStatuses = (STATUS_FIELD_ELECTRIC_TERRAIN | STATUS_FIELD_TERRAIN_PERMANENT); - gBattleCommunication[MULTISTRING_CHOOSER] = 2; - BattleScriptPushCursorAndCallback(BattleScript_OverworldTerrain); - effect++; - } - #endif - break; - case ABILITYEFFECT_SWITCH_IN_WEATHER: - if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) - { - switch (GetCurrentWeather()) - { - case WEATHER_RAIN: - case WEATHER_RAIN_THUNDERSTORM: - case WEATHER_DOWNPOUR: - if (!(gBattleWeather & B_WEATHER_RAIN)) - { - gBattleWeather = (B_WEATHER_RAIN_TEMPORARY | B_WEATHER_RAIN_PERMANENT); - gBattleScripting.animArg1 = B_ANIM_RAIN_CONTINUES; - effect++; - } - break; - case WEATHER_SANDSTORM: - if (!(gBattleWeather & B_WEATHER_SANDSTORM)) - { - gBattleWeather = B_WEATHER_SANDSTORM; - gBattleScripting.animArg1 = B_ANIM_SANDSTORM_CONTINUES; - effect++; - } - break; - case WEATHER_DROUGHT: - if (!(gBattleWeather & B_WEATHER_SUN)) - { - gBattleWeather = (B_WEATHER_SUN_PERMANENT | B_WEATHER_SUN_TEMPORARY); - gBattleScripting.animArg1 = B_ANIM_SUN_CONTINUES; - effect++; - } - break; - } - } - if (effect != 0) - { - gBattleCommunication[MULTISTRING_CHOOSER] = GetCurrentWeather(); - BattleScriptPushCursorAndCallback(BattleScript_OverworldWeatherStarts); - } - break; case ABILITY_IMPOSTER: if (IsBattlerAlive(BATTLE_OPPOSITE(battler)) && !(gBattleMons[BATTLE_OPPOSITE(battler)].status2 & (STATUS2_TRANSFORMED | STATUS2_SUBSTITUTE))