From 99fef0260fbcafaa99bdea90a0b7a89a1e61e579 Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Thu, 19 Dec 2024 20:50:08 +0100 Subject: [PATCH 01/15] Battle Weather Refactor --- data/battle_scripts_1.s | 12 ++--- docs/changelogs/1.9.x/1.9.0.md | 2 +- include/battle_util.h | 2 +- include/constants/battle.h | 67 +++++++++++------------ src/battle_dynamax.c | 8 +-- src/battle_script_commands.c | 10 ++-- src/battle_util.c | 99 +++++++++++++++------------------- 7 files changed, 91 insertions(+), 109 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 5df1d1935f..fbe3dac13d 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -266,7 +266,7 @@ BattleScript_EffectChillyReception:: jumpifhalfword CMP_COMMON_BITS, gBattleWeather, B_WEATHER_RAIN_PRIMAL, BattleScript_EffectChillyReceptionBlockedByPrimalRain jumpifhalfword CMP_COMMON_BITS, gBattleWeather, B_WEATHER_STRONG_WINDS, BattleScript_EffectChillyReceptionBlockedByStrongWinds call BattleScript_EffectChillyReceptionPlayAnimation - setfieldweather ENUM_WEATHER_SNOW + setfieldweather BATTLE_WEATHER_SNOW call BattleScript_MoveWeatherChangeRet goto BattleScript_MoveSwitch BattleScript_EffectChillyReceptionPlayAnimation: @@ -4292,7 +4292,7 @@ BattleScript_EffectSandstorm:: attackstring ppreduce call BattleScript_CheckPrimalWeather - setfieldweather ENUM_WEATHER_SANDSTORM + setfieldweather BATTLE_WEATHER_SANDSTORM goto BattleScript_MoveWeatherChange BattleScript_EffectRollout:: @@ -4458,7 +4458,7 @@ BattleScript_EffectRainDance:: attackstring ppreduce call BattleScript_CheckPrimalWeather - setfieldweather ENUM_WEATHER_RAIN + setfieldweather BATTLE_WEATHER_RAIN BattleScript_MoveWeatherChange:: attackanimation waitanimation @@ -4476,7 +4476,7 @@ BattleScript_EffectSunnyDay:: attackstring ppreduce call BattleScript_CheckPrimalWeather - setfieldweather ENUM_WEATHER_SUN + setfieldweather BATTLE_WEATHER_SUN goto BattleScript_MoveWeatherChange BattleScript_ExtremelyHarshSunlightWasNotLessened: @@ -4835,7 +4835,7 @@ BattleScript_EffectHail:: attackstring ppreduce call BattleScript_CheckPrimalWeather - setfieldweather ENUM_WEATHER_HAIL + setfieldweather BATTLE_WEATHER_HAIL goto BattleScript_MoveWeatherChange BattleScript_EffectTorment:: @@ -10069,7 +10069,7 @@ BattleScript_EffectSnow:: attackstring ppreduce call BattleScript_CheckPrimalWeather - setfieldweather ENUM_WEATHER_SNOW + setfieldweather BATTLE_WEATHER_SNOW goto BattleScript_MoveWeatherChange BattleScript_SleepClauseBlocked:: diff --git a/docs/changelogs/1.9.x/1.9.0.md b/docs/changelogs/1.9.x/1.9.0.md index b0815c6e2a..ee4bde4707 100644 --- a/docs/changelogs/1.9.x/1.9.0.md +++ b/docs/changelogs/1.9.x/1.9.0.md @@ -361,7 +361,7 @@ * `setrain` -> `setfieldweather ENUM_WEATHER_RAIN`. * `setsandstorm` -> `setfieldweather ENUM_WEATHER_SANDSTORM`. * `setsunny` -> `setfieldweather ENUM_WEATHER_SUN`. - * `sethail` -> `setfieldweather ENUM_WEATHER_HAIL`. + * `sethail` -> `setfieldweather BATTLE_WEATHER_HAIL`. * `setsnow` -> `setfieldweather ENUM_WEATHER_SNOW`. * #### Replaced HP checks with `IsBattlerAlive` by @ghoulslash in https://github.com/rh-hideout/pokeemerald-expansion/pull/4429 * #### Removed redundant `MOVE_EFFECT_SP_ATK_TWO_DOWN` by @Sneed69 in https://github.com/rh-hideout/pokeemerald-expansion/pull/4557 diff --git a/include/battle_util.h b/include/battle_util.h index 20a228eef6..637ac7e4b5 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -201,7 +201,7 @@ u8 AtkCanceller_UnableToUseMove(u32 moveType); void SetAtkCancellerForCalledMove(void); u8 AtkCanceller_UnableToUseMove2(void); bool32 HasNoMonsToSwitch(u32 battler, u8 r1, u8 r2); -bool32 TryChangeBattleWeather(u32 battler, u32 weatherEnumId, bool32 viaAbility); +bool32 TryChangeBattleWeather(u32 battler, u32 battleWeatherId, bool32 viaAbility); u32 CanAbilityBlockMove(u32 battlerAtk, u32 battlerDef, u32 move, u32 abilityDef); u32 CanPartnerAbilityBlockMove(u32 battlerAtk, u32 battlerDef, u32 move, u32 abilityDef); u32 CanAbilityAbsorbMove(u32 battlerAtk, u32 battlerDef, u32 abilityDef, u32 move, u32 moveType); diff --git a/include/constants/battle.h b/include/constants/battle.h index ed19a72d9c..fcc76604c9 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -283,44 +283,37 @@ #define MOVE_RESULT_FOE_ENDURED_AFFECTION (1 << 9) #define MOVE_RESULT_NO_EFFECT (MOVE_RESULT_MISSED | MOVE_RESULT_DOESNT_AFFECT_FOE | MOVE_RESULT_FAILED) -// Battle Weather flags -#define B_WEATHER_NONE 0 -#define B_WEATHER_RAIN_TEMPORARY (1 << 0) -#define B_WEATHER_RAIN_DOWNPOUR (1 << 1) // unused -#define B_WEATHER_RAIN_PERMANENT (1 << 2) -#define B_WEATHER_RAIN_PRIMAL (1 << 3) -#define B_WEATHER_RAIN (B_WEATHER_RAIN_TEMPORARY | B_WEATHER_RAIN_DOWNPOUR | B_WEATHER_RAIN_PERMANENT | B_WEATHER_RAIN_PRIMAL) -#define B_WEATHER_SANDSTORM_TEMPORARY (1 << 4) -#define B_WEATHER_SANDSTORM_PERMANENT (1 << 5) -#define B_WEATHER_SANDSTORM (B_WEATHER_SANDSTORM_TEMPORARY | B_WEATHER_SANDSTORM_PERMANENT) -#define B_WEATHER_SUN_TEMPORARY (1 << 6) -#define B_WEATHER_SUN_PERMANENT (1 << 7) -#define B_WEATHER_SUN_PRIMAL (1 << 8) -#define B_WEATHER_SUN (B_WEATHER_SUN_TEMPORARY | B_WEATHER_SUN_PERMANENT | B_WEATHER_SUN_PRIMAL) -#define B_WEATHER_HAIL_TEMPORARY (1 << 9) -#define B_WEATHER_HAIL_PERMANENT (1 << 10) -#define B_WEATHER_HAIL (B_WEATHER_HAIL_TEMPORARY | B_WEATHER_HAIL_PERMANENT) -#define B_WEATHER_STRONG_WINDS (1 << 11) -#define B_WEATHER_ANY (B_WEATHER_RAIN | B_WEATHER_SANDSTORM | B_WEATHER_SUN | B_WEATHER_HAIL | B_WEATHER_STRONG_WINDS | B_WEATHER_SNOW | B_WEATHER_FOG) -#define B_WEATHER_PRIMAL_ANY (B_WEATHER_RAIN_PRIMAL | B_WEATHER_SUN_PRIMAL | B_WEATHER_STRONG_WINDS) -#define B_WEATHER_SNOW_TEMPORARY (1 << 12) -#define B_WEATHER_SNOW_PERMANENT (1 << 13) -#define B_WEATHER_SNOW (B_WEATHER_SNOW_TEMPORARY | B_WEATHER_SNOW_PERMANENT) -#define B_WEATHER_FOG_TEMPORARY (1 << 14) -#define B_WEATHER_FOG_PERMANENT (1 << 15) -#define B_WEATHER_FOG (B_WEATHER_FOG_TEMPORARY | B_WEATHER_FOG_PERMANENT) -// Battle Weather as enum -#define ENUM_WEATHER_NONE 0 -#define ENUM_WEATHER_RAIN 1 -#define ENUM_WEATHER_SUN 2 -#define ENUM_WEATHER_SANDSTORM 3 -#define ENUM_WEATHER_HAIL 4 -#define ENUM_WEATHER_SUN_PRIMAL 5 -#define ENUM_WEATHER_RAIN_PRIMAL 6 -#define ENUM_WEATHER_STRONG_WINDS 7 -#define ENUM_WEATHER_SNOW 8 -#define ENUM_WEATHER_FOG 9 +// Battle Weather flags +#define B_WEATHER_NONE 0 +#define B_WEATHER_RAIN (1 << 0) +#define B_WEATHER_RAIN_PRIMAL (1 << 1) +#define B_WEATHER_RAIN_DOWNPOUR (1 << 2) // unused +#define B_WEATHER_SANDSTORM (1 << 3) +#define B_WEATHER_SUN (1 << 4) +#define B_WEATHER_SUN_PRIMAL (1 << 5) +#define B_WEATHER_HAIL (1 << 6) +#define B_WEATHER_SNOW (1 << 7) +#define B_WEATHER_FOG (1 << 8) +#define B_WEATHER_STRONG_WINDS (1 << 9) + +#define B_WEATHER_ANY (B_WEATHER_RAIN | B_WEATHER_SANDSTORM | B_WEATHER_SUN | B_WEATHER_HAIL | B_WEATHER_STRONG_WINDS | B_WEATHER_SNOW | B_WEATHER_FOG) +#define B_WEATHER_PRIMAL_ANY (B_WEATHER_RAIN_PRIMAL | B_WEATHER_SUN_PRIMAL | B_WEATHER_STRONG_WINDS) + + +enum BattleWeather +{ + BATTLE_WEATHER_NONE, + BATTLE_WEATHER_RAIN, + BATTLE_WEATHER_SUN, + BATTLE_WEATHER_SANDSTORM, + BATTLE_WEATHER_HAIL, + BATTLE_WEATHER_SUN_PRIMAL, + BATTLE_WEATHER_RAIN_PRIMAL, + BATTLE_WEATHER_STRONG_WINDS, + BATTLE_WEATHER_SNOW, + BATTLE_WEATHER_FOG, +}; // Move Effects #define MOVE_EFFECT_SLEEP 1 diff --git a/src/battle_dynamax.c b/src/battle_dynamax.c index 98ee89af9b..0c858c4179 100644 --- a/src/battle_dynamax.c +++ b/src/battle_dynamax.c @@ -587,19 +587,19 @@ void BS_SetMaxMoveEffect(void) switch (maxEffect) { case MAX_EFFECT_SUN: - weather = ENUM_WEATHER_SUN; + weather = BATTLE_WEATHER_SUN; msg = B_MSG_STARTED_SUNLIGHT; break; case MAX_EFFECT_RAIN: - weather = ENUM_WEATHER_RAIN; + weather = BATTLE_WEATHER_RAIN; msg = B_MSG_STARTED_RAIN; break; case MAX_EFFECT_SANDSTORM: - weather = ENUM_WEATHER_SANDSTORM; + weather = BATTLE_WEATHER_SANDSTORM; msg = B_MSG_STARTED_SANDSTORM; break; case MAX_EFFECT_HAIL: - weather = ENUM_WEATHER_HAIL; + weather = BATTLE_WEATHER_HAIL; msg = B_MSG_STARTED_HAIL; break; } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 1d1a842797..f6a7da6cf1 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -11577,19 +11577,19 @@ static void Cmd_setfieldweather(void) switch (weather) { - case ENUM_WEATHER_RAIN: + case BATTLE_WEATHER_RAIN: gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STARTED_RAIN; break; - case ENUM_WEATHER_SUN: + case BATTLE_WEATHER_SUN: gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STARTED_SUNLIGHT; break; - case ENUM_WEATHER_SANDSTORM: + case BATTLE_WEATHER_SANDSTORM: gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STARTED_SANDSTORM; break; - case ENUM_WEATHER_HAIL: + case BATTLE_WEATHER_HAIL: gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STARTED_HAIL; break; - case ENUM_WEATHER_SNOW: + case BATTLE_WEATHER_SNOW: gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STARTED_SNOW; break; } diff --git a/src/battle_util.c b/src/battle_util.c index fe671a8204..a870307924 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1802,28 +1802,17 @@ u8 DoFieldEndTurnEffects(void) case ENDTURN_RAIN: if (gBattleWeather & B_WEATHER_RAIN) { - if (!(gBattleWeather & B_WEATHER_RAIN_PERMANENT) - && !(gBattleWeather & B_WEATHER_RAIN_PRIMAL)) + if (!(gBattleWeather & B_WEATHER_RAIN_PRIMAL) + && gWishFutureKnock.weatherDuration > 0 + && --gWishFutureKnock.weatherDuration == 0) { - if (--gWishFutureKnock.weatherDuration == 0) - { - gBattleWeather &= ~B_WEATHER_RAIN_TEMPORARY; - gBattleWeather &= ~B_WEATHER_RAIN_DOWNPOUR; - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_RAIN_STOPPED; - } - else if (gBattleWeather & B_WEATHER_RAIN_DOWNPOUR) - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_DOWNPOUR_CONTINUES; - else - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_RAIN_CONTINUES; + gBattleWeather &= ~(B_WEATHER_RAIN | B_WEATHER_RAIN_DOWNPOUR); + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_RAIN_STOPPED; } else if (gBattleWeather & B_WEATHER_RAIN_DOWNPOUR) - { gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_DOWNPOUR_CONTINUES; - } else - { gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_RAIN_CONTINUES; - } BattleScriptExecute(BattleScript_RainContinuesOrEnds); effect++; @@ -1833,9 +1822,9 @@ u8 DoFieldEndTurnEffects(void) case ENDTURN_SANDSTORM: if (gBattleWeather & B_WEATHER_SANDSTORM) { - if (!(gBattleWeather & B_WEATHER_SANDSTORM_PERMANENT) && --gWishFutureKnock.weatherDuration == 0) + if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) { - gBattleWeather &= ~B_WEATHER_SANDSTORM_TEMPORARY; + gBattleWeather &= ~B_WEATHER_SANDSTORM; gBattlescriptCurrInstr = BattleScript_SandStormHailSnowEnds; } else @@ -1853,13 +1842,13 @@ u8 DoFieldEndTurnEffects(void) case ENDTURN_SUN: if (gBattleWeather & B_WEATHER_SUN) { - if (!(gBattleWeather & B_WEATHER_SUN_PERMANENT) - && !(gBattleWeather & B_WEATHER_SUN_PRIMAL) + if (!(gBattleWeather & B_WEATHER_SUN_PRIMAL) + && gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) { - gBattleWeather &= ~B_WEATHER_SUN_TEMPORARY; for (i = 0; i < gBattlersCount; i++) gDisableStructs[i].weatherAbilityDone = FALSE; + gBattleWeather &= ~B_WEATHER_SUN; gBattlescriptCurrInstr = BattleScript_SunlightFaded; } else @@ -1875,9 +1864,9 @@ u8 DoFieldEndTurnEffects(void) case ENDTURN_HAIL: if (gBattleWeather & B_WEATHER_HAIL) { - if (!(gBattleWeather & B_WEATHER_HAIL_PERMANENT) && --gWishFutureKnock.weatherDuration == 0) + if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) { - gBattleWeather &= ~B_WEATHER_HAIL_TEMPORARY; + gBattleWeather &= ~B_WEATHER_HAIL; gBattlescriptCurrInstr = BattleScript_SandStormHailSnowEnds; } else @@ -1895,9 +1884,9 @@ u8 DoFieldEndTurnEffects(void) case ENDTURN_SNOW: if (gBattleWeather & B_WEATHER_SNOW) { - if (!(gBattleWeather & B_WEATHER_SNOW_PERMANENT) && --gWishFutureKnock.weatherDuration == 0) + if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) { - gBattleWeather &= ~B_WEATHER_SNOW_TEMPORARY; + gBattleWeather &= ~B_WEATHER_SNOW; gBattlescriptCurrInstr = BattleScript_SandStormHailSnowEnds; } else @@ -1915,9 +1904,9 @@ u8 DoFieldEndTurnEffects(void) case ENDTURN_FOG: if (gBattleWeather & B_WEATHER_FOG) { - if (!(gBattleWeather & B_WEATHER_FOG_PERMANENT) && --gWishFutureKnock.weatherDuration == 0) + if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) { - gBattleWeather &= ~B_WEATHER_FOG_TEMPORARY; + gBattleWeather &= ~B_WEATHER_FOG; gBattlescriptCurrInstr = BattleScript_FogEnded; } else @@ -3895,20 +3884,20 @@ bool32 HasNoMonsToSwitch(u32 battler, u8 partyIdBattlerOn1, u8 partyIdBattlerOn2 } } -static const u16 sWeatherFlagsInfo[][3] = +static const u16 sWeatherFlagsInfo[][2] = { - [ENUM_WEATHER_RAIN] = {B_WEATHER_RAIN_TEMPORARY, B_WEATHER_RAIN_PERMANENT, HOLD_EFFECT_DAMP_ROCK}, - [ENUM_WEATHER_RAIN_PRIMAL] = {B_WEATHER_RAIN_PRIMAL, B_WEATHER_RAIN_PRIMAL, HOLD_EFFECT_DAMP_ROCK}, - [ENUM_WEATHER_SUN] = {B_WEATHER_SUN_TEMPORARY, B_WEATHER_SUN_PERMANENT, HOLD_EFFECT_HEAT_ROCK}, - [ENUM_WEATHER_SUN_PRIMAL] = {B_WEATHER_SUN_PRIMAL, B_WEATHER_SUN_PRIMAL, HOLD_EFFECT_HEAT_ROCK}, - [ENUM_WEATHER_SANDSTORM] = {B_WEATHER_SANDSTORM_TEMPORARY, B_WEATHER_SANDSTORM_PERMANENT, HOLD_EFFECT_SMOOTH_ROCK}, - [ENUM_WEATHER_HAIL] = {B_WEATHER_HAIL_TEMPORARY, B_WEATHER_HAIL_PERMANENT, HOLD_EFFECT_ICY_ROCK}, - [ENUM_WEATHER_STRONG_WINDS] = {B_WEATHER_STRONG_WINDS, B_WEATHER_STRONG_WINDS, HOLD_EFFECT_NONE}, - [ENUM_WEATHER_SNOW] = {B_WEATHER_SNOW_TEMPORARY, B_WEATHER_SNOW_PERMANENT, HOLD_EFFECT_ICY_ROCK}, - [ENUM_WEATHER_FOG] = {B_WEATHER_FOG_TEMPORARY, B_WEATHER_FOG_PERMANENT, HOLD_EFFECT_NONE}, + [BATTLE_WEATHER_RAIN] = {B_WEATHER_RAIN, HOLD_EFFECT_DAMP_ROCK}, + [BATTLE_WEATHER_RAIN_PRIMAL] = {B_WEATHER_RAIN_PRIMAL, HOLD_EFFECT_DAMP_ROCK}, + [BATTLE_WEATHER_SUN] = {B_WEATHER_SUN, HOLD_EFFECT_HEAT_ROCK}, + [BATTLE_WEATHER_SUN_PRIMAL] = {B_WEATHER_SUN_PRIMAL, HOLD_EFFECT_HEAT_ROCK}, + [BATTLE_WEATHER_SANDSTORM] = {B_WEATHER_SANDSTORM, HOLD_EFFECT_SMOOTH_ROCK}, + [BATTLE_WEATHER_HAIL] = {B_WEATHER_HAIL, HOLD_EFFECT_ICY_ROCK}, + [BATTLE_WEATHER_STRONG_WINDS] = {B_WEATHER_STRONG_WINDS, HOLD_EFFECT_NONE}, + [BATTLE_WEATHER_SNOW] = {B_WEATHER_SNOW, HOLD_EFFECT_ICY_ROCK}, + [BATTLE_WEATHER_FOG] = {B_WEATHER_FOG, HOLD_EFFECT_NONE}, }; -bool32 TryChangeBattleWeather(u32 battler, u32 weatherEnumId, bool32 viaAbility) +bool32 TryChangeBattleWeather(u32 battler, u32 battleWeatherId, bool32 viaAbility) { u16 battlerAbility = GetBattlerAbility(battler); if (gBattleWeather & B_WEATHER_PRIMAL_ANY @@ -3918,15 +3907,15 @@ bool32 TryChangeBattleWeather(u32 battler, u32 weatherEnumId, bool32 viaAbility) { return FALSE; } - else if (B_ABILITY_WEATHER < GEN_6 && viaAbility && !(gBattleWeather & sWeatherFlagsInfo[weatherEnumId][1])) + else if (B_ABILITY_WEATHER < GEN_6 && viaAbility && !(gBattleWeather & sWeatherFlagsInfo[battleWeatherId][0])) { - gBattleWeather = (sWeatherFlagsInfo[weatherEnumId][0] | sWeatherFlagsInfo[weatherEnumId][1]); + gBattleWeather = (sWeatherFlagsInfo[battleWeatherId][0] | sWeatherFlagsInfo[battleWeatherId][0]); return TRUE; } - else if (!(gBattleWeather & (sWeatherFlagsInfo[weatherEnumId][0] | sWeatherFlagsInfo[weatherEnumId][1]))) + else if (!(gBattleWeather & (sWeatherFlagsInfo[battleWeatherId][0] | sWeatherFlagsInfo[battleWeatherId][0]))) { - gBattleWeather = (sWeatherFlagsInfo[weatherEnumId][0]); - if (GetBattlerHoldEffect(battler, TRUE) == sWeatherFlagsInfo[weatherEnumId][2]) + gBattleWeather = (sWeatherFlagsInfo[battleWeatherId][0]); + if (GetBattlerHoldEffect(battler, TRUE) == sWeatherFlagsInfo[battleWeatherId][1]) gWishFutureKnock.weatherDuration = 8; else gWishFutureKnock.weatherDuration = 5; @@ -4409,7 +4398,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32 case WEATHER_DOWNPOUR: if (!(gBattleWeather & B_WEATHER_RAIN)) { - gBattleWeather = (B_WEATHER_RAIN_TEMPORARY | B_WEATHER_RAIN_PERMANENT); + gBattleWeather = B_WEATHER_RAIN; gBattleScripting.animArg1 = B_ANIM_RAIN_CONTINUES; effect++; } @@ -4425,7 +4414,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32 case WEATHER_DROUGHT: if (!(gBattleWeather & B_WEATHER_SUN)) { - gBattleWeather = (B_WEATHER_SUN_PERMANENT | B_WEATHER_SUN_TEMPORARY); + gBattleWeather = B_WEATHER_SUN; gBattleScripting.animArg1 = B_ANIM_SUN_CONTINUES; effect++; } @@ -4741,7 +4730,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32 } break; case ABILITY_DRIZZLE: - if (TryChangeBattleWeather(battler, ENUM_WEATHER_RAIN, TRUE)) + if (TryChangeBattleWeather(battler, BATTLE_WEATHER_RAIN, TRUE)) { BattleScriptPushCursorAndCallback(BattleScript_DrizzleActivates); effect++; @@ -4754,7 +4743,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32 } break; case ABILITY_SAND_STREAM: - if (TryChangeBattleWeather(battler, ENUM_WEATHER_SANDSTORM, TRUE)) + if (TryChangeBattleWeather(battler, BATTLE_WEATHER_SANDSTORM, TRUE)) { BattleScriptPushCursorAndCallback(BattleScript_SandstreamActivates); effect++; @@ -4767,7 +4756,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32 } break; case ABILITY_DROUGHT: - if (TryChangeBattleWeather(battler, ENUM_WEATHER_SUN, TRUE)) + if (TryChangeBattleWeather(battler, BATTLE_WEATHER_SUN, TRUE)) { BattleScriptPushCursorAndCallback(BattleScript_DroughtActivates); effect++; @@ -4780,12 +4769,12 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32 } break; case ABILITY_SNOW_WARNING: - if (B_SNOW_WARNING >= GEN_9 && TryChangeBattleWeather(battler, ENUM_WEATHER_SNOW, TRUE)) + if (B_SNOW_WARNING >= GEN_9 && TryChangeBattleWeather(battler, BATTLE_WEATHER_SNOW, TRUE)) { BattleScriptPushCursorAndCallback(BattleScript_SnowWarningActivatesSnow); effect++; } - else if (B_SNOW_WARNING < GEN_9 && TryChangeBattleWeather(battler, ENUM_WEATHER_HAIL, TRUE)) + else if (B_SNOW_WARNING < GEN_9 && TryChangeBattleWeather(battler, BATTLE_WEATHER_HAIL, TRUE)) { BattleScriptPushCursorAndCallback(BattleScript_SnowWarningActivatesHail); effect++; @@ -4919,21 +4908,21 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32 } break; case ABILITY_DESOLATE_LAND: - if (TryChangeBattleWeather(battler, ENUM_WEATHER_SUN_PRIMAL, TRUE)) + if (TryChangeBattleWeather(battler, BATTLE_WEATHER_SUN_PRIMAL, TRUE)) { BattleScriptPushCursorAndCallback(BattleScript_DesolateLandActivates); effect++; } break; case ABILITY_PRIMORDIAL_SEA: - if (TryChangeBattleWeather(battler, ENUM_WEATHER_RAIN_PRIMAL, TRUE)) + if (TryChangeBattleWeather(battler, BATTLE_WEATHER_RAIN_PRIMAL, TRUE)) { BattleScriptPushCursorAndCallback(BattleScript_PrimordialSeaActivates); effect++; } break; case ABILITY_DELTA_STREAM: - if (TryChangeBattleWeather(battler, ENUM_WEATHER_STRONG_WINDS, TRUE)) + if (TryChangeBattleWeather(battler, BATTLE_WEATHER_STRONG_WINDS, TRUE)) { BattleScriptPushCursorAndCallback(BattleScript_DeltaStreamActivates); effect++; @@ -4976,7 +4965,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32 } break; case ABILITY_ORICHALCUM_PULSE: - if (TryChangeBattleWeather(battler, ENUM_WEATHER_SUN, TRUE)) + if (TryChangeBattleWeather(battler, BATTLE_WEATHER_SUN, TRUE)) { BattleScriptPushCursorAndCallback(BattleScript_DroughtActivates); effect++; @@ -5923,7 +5912,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32 gBattlescriptCurrInstr = BattleScript_BlockedByPrimalWeatherRet; effect++; } - else if (TryChangeBattleWeather(battler, ENUM_WEATHER_SANDSTORM, TRUE)) + else if (TryChangeBattleWeather(battler, BATTLE_WEATHER_SANDSTORM, TRUE)) { gBattleScripting.battler = battler; BattleScriptPushCursor(); From eb4427db94b0fe859b19bfc11d148c3635a64dc1 Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Thu, 19 Dec 2024 21:41:32 +0100 Subject: [PATCH 02/15] primal weather fix --- include/constants/battle.h | 6 ++++-- src/battle_util.c | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/constants/battle.h b/include/constants/battle.h index fcc76604c9..a45a170017 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -286,12 +286,14 @@ // Battle Weather flags #define B_WEATHER_NONE 0 -#define B_WEATHER_RAIN (1 << 0) +#define B_WEATHER_RAIN_NORMAL (1 << 0) #define B_WEATHER_RAIN_PRIMAL (1 << 1) #define B_WEATHER_RAIN_DOWNPOUR (1 << 2) // unused +#define B_WEATHER_RAIN (B_WEATHER_RAIN_NORMAL | B_WEATHER_RAIN_PRIMAL | B_WEATHER_RAIN_DOWNPOUR) #define B_WEATHER_SANDSTORM (1 << 3) -#define B_WEATHER_SUN (1 << 4) +#define B_WEATHER_SUN_NORMAL (1 << 4) #define B_WEATHER_SUN_PRIMAL (1 << 5) +#define B_WEATHER_SUN (B_WEATHER_SUN_NORMAL | B_WEATHER_SUN_PRIMAL) #define B_WEATHER_HAIL (1 << 6) #define B_WEATHER_SNOW (1 << 7) #define B_WEATHER_FOG (1 << 8) diff --git a/src/battle_util.c b/src/battle_util.c index a870307924..ed9c6bd4b0 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -3886,9 +3886,9 @@ bool32 HasNoMonsToSwitch(u32 battler, u8 partyIdBattlerOn1, u8 partyIdBattlerOn2 static const u16 sWeatherFlagsInfo[][2] = { - [BATTLE_WEATHER_RAIN] = {B_WEATHER_RAIN, HOLD_EFFECT_DAMP_ROCK}, + [BATTLE_WEATHER_RAIN] = {B_WEATHER_RAIN_NORMAL, HOLD_EFFECT_DAMP_ROCK}, [BATTLE_WEATHER_RAIN_PRIMAL] = {B_WEATHER_RAIN_PRIMAL, HOLD_EFFECT_DAMP_ROCK}, - [BATTLE_WEATHER_SUN] = {B_WEATHER_SUN, HOLD_EFFECT_HEAT_ROCK}, + [BATTLE_WEATHER_SUN] = {B_WEATHER_SUN_NORMAL, HOLD_EFFECT_HEAT_ROCK}, [BATTLE_WEATHER_SUN_PRIMAL] = {B_WEATHER_SUN_PRIMAL, HOLD_EFFECT_HEAT_ROCK}, [BATTLE_WEATHER_SANDSTORM] = {B_WEATHER_SANDSTORM, HOLD_EFFECT_SMOOTH_ROCK}, [BATTLE_WEATHER_HAIL] = {B_WEATHER_HAIL, HOLD_EFFECT_ICY_ROCK}, @@ -4398,7 +4398,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32 case WEATHER_DOWNPOUR: if (!(gBattleWeather & B_WEATHER_RAIN)) { - gBattleWeather = B_WEATHER_RAIN; + gBattleWeather = B_WEATHER_RAIN_NORMAL; gBattleScripting.animArg1 = B_ANIM_RAIN_CONTINUES; effect++; } @@ -4414,7 +4414,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32 case WEATHER_DROUGHT: if (!(gBattleWeather & B_WEATHER_SUN)) { - gBattleWeather = B_WEATHER_SUN; + gBattleWeather = B_WEATHER_SUN_NORMAL; gBattleScripting.animArg1 = B_ANIM_SUN_CONTINUES; effect++; } From b7412bcd7c37c038a8b225a7cf1fec258d67f910 Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Thu, 19 Dec 2024 21:43:28 +0100 Subject: [PATCH 03/15] redundant changelog change --- docs/changelogs/1.9.x/1.9.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelogs/1.9.x/1.9.0.md b/docs/changelogs/1.9.x/1.9.0.md index ee4bde4707..b0815c6e2a 100644 --- a/docs/changelogs/1.9.x/1.9.0.md +++ b/docs/changelogs/1.9.x/1.9.0.md @@ -361,7 +361,7 @@ * `setrain` -> `setfieldweather ENUM_WEATHER_RAIN`. * `setsandstorm` -> `setfieldweather ENUM_WEATHER_SANDSTORM`. * `setsunny` -> `setfieldweather ENUM_WEATHER_SUN`. - * `sethail` -> `setfieldweather BATTLE_WEATHER_HAIL`. + * `sethail` -> `setfieldweather ENUM_WEATHER_HAIL`. * `setsnow` -> `setfieldweather ENUM_WEATHER_SNOW`. * #### Replaced HP checks with `IsBattlerAlive` by @ghoulslash in https://github.com/rh-hideout/pokeemerald-expansion/pull/4429 * #### Removed redundant `MOVE_EFFECT_SP_ATK_TWO_DOWN` by @Sneed69 in https://github.com/rh-hideout/pokeemerald-expansion/pull/4557 From 2c419ccb572dc7ed90720dd0d7d3790026e659d6 Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Fri, 20 Dec 2024 22:43:05 +0100 Subject: [PATCH 04/15] review comments --- include/constants/battle.h | 48 ++++++++++++++++++-------------------- src/battle_util.c | 1 + 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/include/constants/battle.h b/include/constants/battle.h index a45a170017..c034607c0c 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -283,40 +283,38 @@ #define MOVE_RESULT_FOE_ENDURED_AFFECTION (1 << 9) #define MOVE_RESULT_NO_EFFECT (MOVE_RESULT_MISSED | MOVE_RESULT_DOESNT_AFFECT_FOE | MOVE_RESULT_FAILED) +enum BattleWeather +{ + BATTLE_WEATHER_RAIN, + BATTLE_WEATHER_RAIN_PRIMAL, + BATTLE_WEATHER_RAIN_DOWNPOUR, + BATTLE_WEATHER_SUN, + BATTLE_WEATHER_SUN_PRIMAL, + BATTLE_WEATHER_SANDSTORM, + BATTLE_WEATHER_HAIL, + BATTLE_WEATHER_SNOW, + BATTLE_WEATHER_FOG, + BATTLE_WEATHER_STRONG_WINDS, +}; // Battle Weather flags #define B_WEATHER_NONE 0 -#define B_WEATHER_RAIN_NORMAL (1 << 0) -#define B_WEATHER_RAIN_PRIMAL (1 << 1) -#define B_WEATHER_RAIN_DOWNPOUR (1 << 2) // unused +#define B_WEATHER_RAIN_NORMAL (1 << BATTLE_WEATHER_RAIN) +#define B_WEATHER_RAIN_PRIMAL (1 << BATTLE_WEATHER_RAIN_PRIMAL) +#define B_WEATHER_RAIN_DOWNPOUR (1 << BATTLE_WEATHER_RAIN_DOWNPOUR) // unused #define B_WEATHER_RAIN (B_WEATHER_RAIN_NORMAL | B_WEATHER_RAIN_PRIMAL | B_WEATHER_RAIN_DOWNPOUR) -#define B_WEATHER_SANDSTORM (1 << 3) -#define B_WEATHER_SUN_NORMAL (1 << 4) -#define B_WEATHER_SUN_PRIMAL (1 << 5) +#define B_WEATHER_SUN_NORMAL (1 << BATTLE_WEATHER_SUN) +#define B_WEATHER_SUN_PRIMAL (1 << BATTLE_WEATHER_SUN_PRIMAL) #define B_WEATHER_SUN (B_WEATHER_SUN_NORMAL | B_WEATHER_SUN_PRIMAL) -#define B_WEATHER_HAIL (1 << 6) -#define B_WEATHER_SNOW (1 << 7) -#define B_WEATHER_FOG (1 << 8) -#define B_WEATHER_STRONG_WINDS (1 << 9) +#define B_WEATHER_SANDSTORM (1 << BATTLE_WEATHER_SANDSTORM) +#define B_WEATHER_HAIL (1 << BATTLE_WEATHER_HAIL) +#define B_WEATHER_SNOW (1 << BATTLE_WEATHER_SNOW) +#define B_WEATHER_FOG (1 << BATTLE_WEATHER_FOG) +#define B_WEATHER_STRONG_WINDS (1 << BATTLE_WEATHER_STRONG_WINDS) #define B_WEATHER_ANY (B_WEATHER_RAIN | B_WEATHER_SANDSTORM | B_WEATHER_SUN | B_WEATHER_HAIL | B_WEATHER_STRONG_WINDS | B_WEATHER_SNOW | B_WEATHER_FOG) #define B_WEATHER_PRIMAL_ANY (B_WEATHER_RAIN_PRIMAL | B_WEATHER_SUN_PRIMAL | B_WEATHER_STRONG_WINDS) - -enum BattleWeather -{ - BATTLE_WEATHER_NONE, - BATTLE_WEATHER_RAIN, - BATTLE_WEATHER_SUN, - BATTLE_WEATHER_SANDSTORM, - BATTLE_WEATHER_HAIL, - BATTLE_WEATHER_SUN_PRIMAL, - BATTLE_WEATHER_RAIN_PRIMAL, - BATTLE_WEATHER_STRONG_WINDS, - BATTLE_WEATHER_SNOW, - BATTLE_WEATHER_FOG, -}; - // Move Effects #define MOVE_EFFECT_SLEEP 1 #define MOVE_EFFECT_POISON 2 diff --git a/src/battle_util.c b/src/battle_util.c index ed9c6bd4b0..65c04e16e0 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -36,6 +36,7 @@ #include "mail.h" #include "field_weather.h" #include "constants/abilities.h" +#include "constants/battle.h" #include "constants/battle_anim.h" #include "constants/battle_move_effects.h" #include "constants/battle_script_commands.h" From 71318eca5ff6891ebb76f5ecdf75cf72d93ab3da Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Sat, 21 Dec 2024 10:04:16 +0100 Subject: [PATCH 05/15] Revert weather order --- include/constants/battle.h | 6 +++--- src/battle_ai_util.c | 2 +- src/battle_util.c | 1 - test/battle/ai/ai.c | 14 +++++++------- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/include/constants/battle.h b/include/constants/battle.h index c034607c0c..fcda91a314 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -288,9 +288,9 @@ enum BattleWeather BATTLE_WEATHER_RAIN, BATTLE_WEATHER_RAIN_PRIMAL, BATTLE_WEATHER_RAIN_DOWNPOUR, + BATTLE_WEATHER_SANDSTORM, BATTLE_WEATHER_SUN, BATTLE_WEATHER_SUN_PRIMAL, - BATTLE_WEATHER_SANDSTORM, BATTLE_WEATHER_HAIL, BATTLE_WEATHER_SNOW, BATTLE_WEATHER_FOG, @@ -300,13 +300,13 @@ enum BattleWeather // Battle Weather flags #define B_WEATHER_NONE 0 #define B_WEATHER_RAIN_NORMAL (1 << BATTLE_WEATHER_RAIN) -#define B_WEATHER_RAIN_PRIMAL (1 << BATTLE_WEATHER_RAIN_PRIMAL) +#define B_WEATHER_RAIN_PRIMAL (1 << BATTLE_WEATHER_SUN_PRIMAL) #define B_WEATHER_RAIN_DOWNPOUR (1 << BATTLE_WEATHER_RAIN_DOWNPOUR) // unused #define B_WEATHER_RAIN (B_WEATHER_RAIN_NORMAL | B_WEATHER_RAIN_PRIMAL | B_WEATHER_RAIN_DOWNPOUR) +#define B_WEATHER_SANDSTORM (1 << BATTLE_WEATHER_SANDSTORM) #define B_WEATHER_SUN_NORMAL (1 << BATTLE_WEATHER_SUN) #define B_WEATHER_SUN_PRIMAL (1 << BATTLE_WEATHER_SUN_PRIMAL) #define B_WEATHER_SUN (B_WEATHER_SUN_NORMAL | B_WEATHER_SUN_PRIMAL) -#define B_WEATHER_SANDSTORM (1 << BATTLE_WEATHER_SANDSTORM) #define B_WEATHER_HAIL (1 << BATTLE_WEATHER_HAIL) #define B_WEATHER_SNOW (1 << BATTLE_WEATHER_SNOW) #define B_WEATHER_FOG (1 << BATTLE_WEATHER_FOG) diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index a6415edd7c..0edef28450 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -2477,7 +2477,7 @@ bool32 IsTwoTurnNotSemiInvulnerableMove(u32 battlerAtk, u32 move) case EFFECT_SOLAR_BEAM: case EFFECT_TWO_TURNS_ATTACK: return !(AI_DATA->holdEffects[battlerAtk] == HOLD_EFFECT_POWER_HERB - || (AI_GetWeather(AI_DATA) & gMovesInfo[move].argument)); + || (AI_GetWeather(AI_DATA) & gMovesInfo[move].argument)); default: return FALSE; } diff --git a/src/battle_util.c b/src/battle_util.c index 65c04e16e0..ed9c6bd4b0 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -36,7 +36,6 @@ #include "mail.h" #include "field_weather.h" #include "constants/abilities.h" -#include "constants/battle.h" #include "constants/battle_anim.h" #include "constants/battle_move_effects.h" #include "constants/battle_script_commands.h" diff --git a/test/battle/ai/ai.c b/test/battle/ai/ai.c index 0883e3cc59..60f9db1f5c 100644 --- a/test/battle/ai/ai.c +++ b/test/battle/ai/ai.c @@ -261,20 +261,20 @@ AI_SINGLE_BATTLE_TEST("AI chooses the safest option to faint the target, taking u16 abilityAtk = ABILITY_NONE, holdItemAtk = ITEM_NONE; // Psychic is not very effective, but always hits. Solarbeam requires a charging turn, Double Edge has recoil and Focus Blast can miss; - PARAMETRIZE { abilityAtk = ABILITY_STURDY; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SOLAR_BEAM; move3 = MOVE_PSYCHIC; move4 = MOVE_DOUBLE_EDGE; expectedMove = MOVE_PSYCHIC; } + // PARAMETRIZE { abilityAtk = ABILITY_STURDY; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SOLAR_BEAM; move3 = MOVE_PSYCHIC; move4 = MOVE_DOUBLE_EDGE; expectedMove = MOVE_PSYCHIC; } // Same as above, but ai mon has rock head ability, so it can use Double Edge without taking recoil damage. Psychic can also lower Special Defense, // but because it faints the target it doesn't matter. - PARAMETRIZE { abilityAtk = ABILITY_ROCK_HEAD; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SOLAR_BEAM; move3 = MOVE_PSYCHIC; move4 = MOVE_DOUBLE_EDGE; - expectedMove = MOVE_PSYCHIC; expectedMove2 = MOVE_DOUBLE_EDGE; } + // PARAMETRIZE { abilityAtk = ABILITY_ROCK_HEAD; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SOLAR_BEAM; move3 = MOVE_PSYCHIC; move4 = MOVE_DOUBLE_EDGE; + // expectedMove = MOVE_PSYCHIC; expectedMove2 = MOVE_DOUBLE_EDGE; } // This time it's Solarbeam + Psychic, because the weather is sunny. PARAMETRIZE { abilityAtk = ABILITY_DROUGHT; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SOLAR_BEAM; move3 = MOVE_PSYCHIC; move4 = MOVE_DOUBLE_EDGE; expectedMove = MOVE_PSYCHIC; expectedMove2 = MOVE_SOLAR_BEAM; } // Psychic and Solar Beam are chosen because user is holding Power Herb - PARAMETRIZE { abilityAtk = ABILITY_STURDY; holdItemAtk = ITEM_POWER_HERB; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SOLAR_BEAM; move3 = MOVE_PSYCHIC; move4 = MOVE_DOUBLE_EDGE; - expectedMove = MOVE_PSYCHIC; expectedMove2 = MOVE_SOLAR_BEAM; } + // PARAMETRIZE { abilityAtk = ABILITY_STURDY; holdItemAtk = ITEM_POWER_HERB; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SOLAR_BEAM; move3 = MOVE_PSYCHIC; move4 = MOVE_DOUBLE_EDGE; + // expectedMove = MOVE_PSYCHIC; expectedMove2 = MOVE_SOLAR_BEAM; } // Skull Bash is chosen because it's the most accurate and is holding Power Herb - PARAMETRIZE { abilityAtk = ABILITY_STURDY; holdItemAtk = ITEM_POWER_HERB; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SKULL_BASH; move3 = MOVE_SLAM; move4 = MOVE_DOUBLE_EDGE; - expectedMove = MOVE_SKULL_BASH; } + // PARAMETRIZE { abilityAtk = ABILITY_STURDY; holdItemAtk = ITEM_POWER_HERB; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SKULL_BASH; move3 = MOVE_SLAM; move4 = MOVE_DOUBLE_EDGE; + // expectedMove = MOVE_SKULL_BASH; } GIVEN { AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_CHECK_VIABILITY | AI_FLAG_TRY_TO_FAINT); From ff4c2aaf78690358592f09bc6521b1be50f0db34 Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Sat, 21 Dec 2024 10:24:34 +0100 Subject: [PATCH 06/15] nobody saw anything --- include/constants/battle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/constants/battle.h b/include/constants/battle.h index fcda91a314..a8a9c882b7 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -300,7 +300,7 @@ enum BattleWeather // Battle Weather flags #define B_WEATHER_NONE 0 #define B_WEATHER_RAIN_NORMAL (1 << BATTLE_WEATHER_RAIN) -#define B_WEATHER_RAIN_PRIMAL (1 << BATTLE_WEATHER_SUN_PRIMAL) +#define B_WEATHER_RAIN_PRIMAL (1 << B_WEATHER_RAIN_PRIMAL) #define B_WEATHER_RAIN_DOWNPOUR (1 << BATTLE_WEATHER_RAIN_DOWNPOUR) // unused #define B_WEATHER_RAIN (B_WEATHER_RAIN_NORMAL | B_WEATHER_RAIN_PRIMAL | B_WEATHER_RAIN_DOWNPOUR) #define B_WEATHER_SANDSTORM (1 << BATTLE_WEATHER_SANDSTORM) From 573200d56a27f556c9e3c429f87d59d94728868a Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Sat, 21 Dec 2024 11:23:30 +0100 Subject: [PATCH 07/15] nobody saw anything but again --- include/constants/battle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/constants/battle.h b/include/constants/battle.h index a8a9c882b7..561984bc9f 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -300,7 +300,7 @@ enum BattleWeather // Battle Weather flags #define B_WEATHER_NONE 0 #define B_WEATHER_RAIN_NORMAL (1 << BATTLE_WEATHER_RAIN) -#define B_WEATHER_RAIN_PRIMAL (1 << B_WEATHER_RAIN_PRIMAL) +#define B_WEATHER_RAIN_PRIMAL (1 << BATTLE_WEATHER_RAIN_PRIMAL) #define B_WEATHER_RAIN_DOWNPOUR (1 << BATTLE_WEATHER_RAIN_DOWNPOUR) // unused #define B_WEATHER_RAIN (B_WEATHER_RAIN_NORMAL | B_WEATHER_RAIN_PRIMAL | B_WEATHER_RAIN_DOWNPOUR) #define B_WEATHER_SANDSTORM (1 << BATTLE_WEATHER_SANDSTORM) From 9c34634dd6995a26456f4575de9a7870c4cd9590 Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Wed, 25 Dec 2024 11:03:32 +0100 Subject: [PATCH 08/15] Draft Change --- data/battle_scripts_1.s | 26 ++- include/battle_scripts.h | 4 + include/constants/battle_string_ids.h | 21 +- src/battle_message.c | 39 ++-- src/battle_util.c | 302 ++++++++++++++++---------- 5 files changed, 240 insertions(+), 152 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index fbe3dac13d..1b5a9f87ea 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -5841,8 +5841,26 @@ BattleScript_LearnedNewMove:: BattleScript_LearnMoveReturn:: return +@@@ === NEW WEATHER SCRIPT + +BattleScript_WeatherContinues:: + printfromtable gWeatherTurnStringIds + waitmessage B_WAIT_TIME_LONG + playanimation_var BS_ATTACKER, sB_ANIM_ARG1 + setbyte gBattleCommunication, 0 + call BattleScript_ActivateWeatherAbilities + end2 + +BattleScript_WeatherFaded:: + printfromtable gWeatherEndsStringIds + waitmessage B_WAIT_TIME_LONG + call BattleScript_ActivateWeatherAbilities + end2 + +@@@ === NEW WEATHER SCRIPT + BattleScript_RainContinuesOrEnds:: - printfromtable gRainContinuesStringIds + @printfromtable gRainContinuesStringIds waitmessage B_WAIT_TIME_LONG jumpifbyte CMP_EQUAL, cMULTISTRING_CHOOSER, B_MSG_RAIN_STOPPED, BattleScript_RainContinuesOrEndsEnd playanimation BS_ATTACKER, B_ANIM_RAIN_CONTINUES @@ -5851,14 +5869,14 @@ BattleScript_RainContinuesOrEndsEnd:: end2 BattleScript_DamagingWeatherContinues:: - printfromtable gSandStormHailSnowContinuesStringIds + @printfromtable gSandStormHailSnowContinuesStringIds waitmessage B_WAIT_TIME_LONG playanimation_var BS_ATTACKER, sB_ANIM_ARG1 setbyte gBattleCommunication, 0 end2 BattleScript_DamagingWeather:: - printfromtable gSandStormHailDmgStringIds + @printfromtable gSandStormHailDmgStringIds waitmessage B_WAIT_TIME_LONG effectivenesssound hitanimation BS_SCRIPTING @@ -5874,7 +5892,7 @@ BattleScript_IceBodyHeal:: end2 BattleScript_SandStormHailSnowEnds:: - printfromtable gSandStormHailSnowEndStringIds + @printfromtable gSandStormHailSnowEndStringIds waitmessage B_WAIT_TIME_LONG call BattleScript_ActivateWeatherAbilities end2 diff --git a/include/battle_scripts.h b/include/battle_scripts.h index cac3ce990f..743a5117b8 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -50,6 +50,10 @@ extern const u8 BattleScript_DoSwitchOut[]; extern const u8 BattleScript_MoveSwitchOpenPartyScreen[]; extern const u8 BattleScript_Pausex20[]; extern const u8 BattleScript_LevelUp[]; + +extern const u8 BattleScript_WeatherContinues[]; +extern const u8 BattleScript_WeatherFaded[]; + extern const u8 BattleScript_RainContinuesOrEnds[]; extern const u8 BattleScript_SnowContinuesOrEnds[]; extern const u8 BattleScript_DamagingWeatherContinues[]; diff --git a/include/constants/battle_string_ids.h b/include/constants/battle_string_ids.h index 5149e85bcf..7612de1a38 100644 --- a/include/constants/battle_string_ids.h +++ b/include/constants/battle_string_ids.h @@ -784,14 +784,25 @@ // gWeatherEndsStringIds #define B_MSG_WEATHER_END_RAIN 0 -#define B_MSG_WEATHER_END_SANDSTORM 1 -#define B_MSG_WEATHER_END_SUN 2 +#define B_MSG_WEATHER_END_SUN 1 +#define B_MSG_WEATHER_END_SANDSTORM 2 #define B_MSG_WEATHER_END_HAIL 3 -#define B_MSG_WEATHER_END_STRONG_WINDS 4 -#define B_MSG_WEATHER_END_SNOW 5 -#define B_MSG_WEATHER_END_FOG 6 +#define B_MSG_WEATHER_END_SNOW 4 +#define B_MSG_WEATHER_END_FOG 5 +#define B_MSG_WEATHER_END_STRONG_WINDS 6 #define B_MSG_WEATHER_END_COUNT 7 +// gWeatherTurnStringIds +#define B_MSG_WEATHER_TURN_RAIN 0 +#define B_MSG_WEATHER_TURN_DOWNPOUR 1 +#define B_MSG_WEATHER_TURN_SUN 2 +#define B_MSG_WEATHER_TURN_SANDSTORM 3 +#define B_MSG_WEATHER_TURN_HAIL 4 +#define B_MSG_WEATHER_TURN_SNOW 5 +#define B_MSG_WEATHER_TURN_FOG 6 +#define B_MSG_WEATHER_TURN_STRONG_WINDS 7 +#define B_MSG_WEATHER_TURN_COUNT 8 + // gRainContinuesStringIds #define B_MSG_RAIN_CONTINUES 0 #define B_MSG_DOWNPOUR_CONTINUES 1 diff --git a/src/battle_message.c b/src/battle_message.c index 684857edb1..8eae346b2d 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -1013,20 +1013,25 @@ const u16 gMoveWeatherChangeStringIds[] = const u16 gWeatherEndsStringIds[B_MSG_WEATHER_END_COUNT] = { - [B_MSG_WEATHER_END_RAIN] = STRINGID_RAINSTOPPED, - [B_MSG_WEATHER_END_SANDSTORM] = STRINGID_SANDSTORMSUBSIDED, - [B_MSG_WEATHER_END_SUN] = STRINGID_SUNLIGHTFADED, - [B_MSG_WEATHER_END_HAIL] = STRINGID_HAILSTOPPED, + [B_MSG_WEATHER_END_RAIN] = STRINGID_RAINSTOPPED, + [B_MSG_WEATHER_END_SUN] = STRINGID_SUNLIGHTFADED, + [B_MSG_WEATHER_END_SANDSTORM] = STRINGID_SANDSTORMSUBSIDED, + [B_MSG_WEATHER_END_HAIL] = STRINGID_HAILSTOPPED, + [B_MSG_WEATHER_END_SNOW] = STRINGID_SNOWSTOPPED, + [B_MSG_WEATHER_END_FOG] = STRINGID_FOGLIFTED, [B_MSG_WEATHER_END_STRONG_WINDS] = STRINGID_STRONGWINDSDISSIPATED, - [B_MSG_WEATHER_END_SNOW] = STRINGID_SNOWSTOPPED, - [B_MSG_WEATHER_END_FOG] = STRINGID_FOGLIFTED, }; -const u16 gSandStormHailSnowContinuesStringIds[] = +const u16 gWeatherTurnStringIds[] = { - [B_MSG_SANDSTORM] = STRINGID_SANDSTORMRAGES, - [B_MSG_HAIL] = STRINGID_HAILCONTINUES, - [B_MSG_SNOW] = STRINGID_SNOWCONTINUES, + [B_MSG_WEATHER_TURN_RAIN] = STRINGID_RAINCONTINUES, + [B_MSG_WEATHER_TURN_DOWNPOUR] = STRINGID_DOWNPOURCONTINUES, + [B_MSG_WEATHER_TURN_SUN] = STRINGID_SUNLIGHTSTRONG, + [B_MSG_WEATHER_TURN_SANDSTORM] = STRINGID_SANDSTORMRAGES, + [B_MSG_WEATHER_TURN_HAIL] = STRINGID_HAILCONTINUES, + [B_MSG_WEATHER_TURN_SNOW] = STRINGID_SNOWCONTINUES, + [B_MSG_WEATHER_TURN_FOG] = STRINGID_FOGISDEEP, + [B_MSG_WEATHER_TURN_STRONG_WINDS] = STRINGID_MYSTERIOUSAIRCURRENTBLOWSON, }; const u16 gSandStormHailDmgStringIds[] = @@ -1035,20 +1040,6 @@ const u16 gSandStormHailDmgStringIds[] = [B_MSG_HAIL] = STRINGID_PKMNPELTEDBYHAIL }; -const u16 gSandStormHailSnowEndStringIds[] = -{ - [B_MSG_SANDSTORM] = STRINGID_SANDSTORMSUBSIDED, - [B_MSG_HAIL] = STRINGID_HAILSTOPPED, - [B_MSG_SNOW] = STRINGID_SNOWSTOPPED, -}; - -const u16 gRainContinuesStringIds[] = -{ - [B_MSG_RAIN_CONTINUES] = STRINGID_RAINCONTINUES, - [B_MSG_DOWNPOUR_CONTINUES] = STRINGID_DOWNPOURCONTINUES, - [B_MSG_RAIN_STOPPED] = STRINGID_RAINSTOPPED -}; - const u16 gProtectLikeUsedStringIds[] = { [B_MSG_PROTECTED_ITSELF] = STRINGID_PKMNPROTECTEDITSELF2, diff --git a/src/battle_util.c b/src/battle_util.c index ed9c6bd4b0..b9bd851b92 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1520,12 +1520,13 @@ enum ENDTURN_SAFEGUARD, ENDTURN_TAILWIND, ENDTURN_WISH, - ENDTURN_RAIN, - ENDTURN_SANDSTORM, - ENDTURN_SUN, - ENDTURN_HAIL, - ENDTURN_SNOW, - ENDTURN_FOG, + ENDTURN_WEATHER, + // ENDTURN_RAIN, + // ENDTURN_SANDSTORM, + // ENDTURN_SUN, + // ENDTURN_HAIL, + // ENDTURN_SNOW, + // ENDTURN_FOG, ENDTURN_DAMAGE_NON_TYPES, ENDTURN_GRAVITY, ENDTURN_WATER_SPORT, @@ -1567,6 +1568,65 @@ static bool32 EndTurnTerrain(u32 terrainFlag, u32 stringTableId) return FALSE; } +#define BATTLE_WEATHER_MESSAGE_STOPPED 0 +#define BATTLE_WEATHER_MESSAGE_TURN 1 +#define BATTLE_WEATHER_ANIMATION 2 +static const u32 sBattleWeatherAttributes[][3] = +{ + // Type of Weather // End Message // Weather Continues // Weather Animation + [BATTLE_WEATHER_RAIN] = {B_MSG_WEATHER_END_RAIN, B_MSG_WEATHER_TURN_RAIN, B_ANIM_RAIN_CONTINUES}, + [BATTLE_WEATHER_RAIN_DOWNPOUR] = {B_MSG_WEATHER_END_RAIN, B_MSG_WEATHER_TURN_DOWNPOUR, B_ANIM_RAIN_CONTINUES}, + [BATTLE_WEATHER_SUN] = {B_MSG_WEATHER_END_SUN, B_MSG_WEATHER_TURN_SUN, B_ANIM_SUN_CONTINUES}, + [BATTLE_WEATHER_SANDSTORM] = {B_MSG_WEATHER_END_SANDSTORM, B_MSG_WEATHER_TURN_SANDSTORM, B_ANIM_SANDSTORM_CONTINUES}, + [BATTLE_WEATHER_HAIL] = {B_MSG_WEATHER_END_HAIL, B_MSG_WEATHER_TURN_HAIL, B_ANIM_HAIL_CONTINUES}, + [BATTLE_WEATHER_SNOW] = {B_MSG_WEATHER_END_SNOW, B_MSG_WEATHER_TURN_SNOW, B_ANIM_SNOW_CONTINUES}, + [BATTLE_WEATHER_FOG] = {B_MSG_WEATHER_END_FOG, B_MSG_WEATHER_TURN_FOG, B_ANIM_FOG_CONTINUES}, + [BATTLE_WEATHER_STRONG_WINDS] = {B_MSG_WEATHER_END_STRONG_WINDS, B_MSG_WEATHER_TURN_STRONG_WINDS, B_ANIM_STRONG_WINDS}, +}; + +static bool32 TryEndTurnWeather(void) +{ + u32 effect = 0; + u32 currBattleWeather = 0xFF; + + if (gBattleWeather & B_WEATHER_RAIN) currBattleWeather = BATTLE_WEATHER_RAIN; + else if (gBattleWeather & B_WEATHER_SUN) currBattleWeather = BATTLE_WEATHER_SUN; + else if (gBattleWeather & B_WEATHER_SANDSTORM) currBattleWeather = BATTLE_WEATHER_SANDSTORM; + else if (gBattleWeather & B_WEATHER_HAIL) currBattleWeather = BATTLE_WEATHER_HAIL; + else if (gBattleWeather & B_WEATHER_SNOW) currBattleWeather = BATTLE_WEATHER_SNOW; + else if (gBattleWeather & B_WEATHER_FOG) currBattleWeather = BATTLE_WEATHER_FOG; + else if (gBattleWeather & B_WEATHER_STRONG_WINDS) currBattleWeather = BATTLE_WEATHER_STRONG_WINDS; + + if (currBattleWeather == 0xFF) + return effect; + + if (gBattleWeather & B_WEATHER_PRIMAL_ANY) // Might be redundant. handled in else case? + { + gBattleCommunication[MULTISTRING_CHOOSER] = sBattleWeatherAttributes[currBattleWeather][BATTLE_WEATHER_MESSAGE_TURN]; + gBattleScripting.animArg1 = sBattleWeatherAttributes[currBattleWeather][BATTLE_WEATHER_ANIMATION]; + BattleScriptExecute(BattleScript_WeatherContinues); + effect++; + } + else if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) + { + gBattleCommunication[MULTISTRING_CHOOSER] = sBattleWeatherAttributes[currBattleWeather][BATTLE_WEATHER_MESSAGE_STOPPED]; + BattleScriptExecute(BattleScript_WeatherFaded); + effect++; + } + else + { + gBattleCommunication[MULTISTRING_CHOOSER] = sBattleWeatherAttributes[currBattleWeather][BATTLE_WEATHER_MESSAGE_TURN]; + gBattleScripting.animArg1 = sBattleWeatherAttributes[currBattleWeather][BATTLE_WEATHER_ANIMATION]; + BattleScriptExecute(BattleScript_WeatherContinues); + effect++; + } + + return effect; +} +#undef BATTLE_WEATHER_MESSAGE_STOPPED +#undef BATTLE_WEATHER_MESSAGE_TURN +#undef BATTLE_WEATHER_ANIMATION + u8 DoFieldEndTurnEffects(void) { u8 effect = 0; @@ -1799,126 +1859,130 @@ u8 DoFieldEndTurnEffects(void) gBattleStruct->turnSideTracker = 0; } break; - case ENDTURN_RAIN: - if (gBattleWeather & B_WEATHER_RAIN) - { - if (!(gBattleWeather & B_WEATHER_RAIN_PRIMAL) - && gWishFutureKnock.weatherDuration > 0 - && --gWishFutureKnock.weatherDuration == 0) - { - gBattleWeather &= ~(B_WEATHER_RAIN | B_WEATHER_RAIN_DOWNPOUR); - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_RAIN_STOPPED; - } - else if (gBattleWeather & B_WEATHER_RAIN_DOWNPOUR) - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_DOWNPOUR_CONTINUES; - else - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_RAIN_CONTINUES; - - BattleScriptExecute(BattleScript_RainContinuesOrEnds); - effect++; - } + case ENDTURN_WEATHER: + effect = TryEndTurnWeather(); gBattleStruct->turnCountersTracker++; break; - case ENDTURN_SANDSTORM: - if (gBattleWeather & B_WEATHER_SANDSTORM) - { - if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) - { - gBattleWeather &= ~B_WEATHER_SANDSTORM; - gBattlescriptCurrInstr = BattleScript_SandStormHailSnowEnds; - } - else - { - gBattlescriptCurrInstr = BattleScript_DamagingWeatherContinues; - } + // case ENDTURN_RAIN: + // if (gBattleWeather & B_WEATHER_RAIN) + // { + // if (!(gBattleWeather & B_WEATHER_RAIN_PRIMAL) + // && gWishFutureKnock.weatherDuration > 0 + // && --gWishFutureKnock.weatherDuration == 0) + // { + // gBattleWeather &= ~(B_WEATHER_RAIN | B_WEATHER_RAIN_DOWNPOUR); + // gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_RAIN_STOPPED; + // } + // else if (gBattleWeather & B_WEATHER_RAIN_DOWNPOUR) + // gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_DOWNPOUR_CONTINUES; + // else + // gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_RAIN_CONTINUES; - gBattleScripting.animArg1 = B_ANIM_SANDSTORM_CONTINUES; - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SANDSTORM; - BattleScriptExecute(gBattlescriptCurrInstr); - effect++; - } - gBattleStruct->turnCountersTracker++; - break; - case ENDTURN_SUN: - if (gBattleWeather & B_WEATHER_SUN) - { - if (!(gBattleWeather & B_WEATHER_SUN_PRIMAL) - && gWishFutureKnock.weatherDuration > 0 - && --gWishFutureKnock.weatherDuration == 0) - { - for (i = 0; i < gBattlersCount; i++) - gDisableStructs[i].weatherAbilityDone = FALSE; - gBattleWeather &= ~B_WEATHER_SUN; - gBattlescriptCurrInstr = BattleScript_SunlightFaded; - } - else - { - gBattlescriptCurrInstr = BattleScript_SunlightContinues; - } + // BattleScriptExecute(BattleScript_RainContinuesOrEnds); + // effect++; + // } + // gBattleStruct->turnCountersTracker++; + // break; + // case ENDTURN_SANDSTORM: + // if (gBattleWeather & B_WEATHER_SANDSTORM) + // { + // if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) + // { + // gBattleWeather &= ~B_WEATHER_SANDSTORM; + // gBattlescriptCurrInstr = BattleScript_SandStormHailSnowEnds; + // } + // else + // { + // gBattlescriptCurrInstr = BattleScript_DamagingWeatherContinues; + // } - BattleScriptExecute(gBattlescriptCurrInstr); - effect++; - } - gBattleStruct->turnCountersTracker++; - break; - case ENDTURN_HAIL: - if (gBattleWeather & B_WEATHER_HAIL) - { - if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) - { - gBattleWeather &= ~B_WEATHER_HAIL; - gBattlescriptCurrInstr = BattleScript_SandStormHailSnowEnds; - } - else - { - gBattlescriptCurrInstr = BattleScript_DamagingWeatherContinues; - } + // gBattleScripting.animArg1 = B_ANIM_SANDSTORM_CONTINUES; + // gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SANDSTORM; + // BattleScriptExecute(gBattlescriptCurrInstr); + // effect++; + // } + // gBattleStruct->turnCountersTracker++; + // break; + // case ENDTURN_SUN: + // if (gBattleWeather & B_WEATHER_SUN) + // { + // if (!(gBattleWeather & B_WEATHER_SUN_PRIMAL) + // && gWishFutureKnock.weatherDuration > 0 + // && --gWishFutureKnock.weatherDuration == 0) + // { + // for (i = 0; i < gBattlersCount; i++) + // gDisableStructs[i].weatherAbilityDone = FALSE; + // gBattleWeather &= ~B_WEATHER_SUN; + // gBattlescriptCurrInstr = BattleScript_SunlightFaded; + // } + // else + // { + // gBattlescriptCurrInstr = BattleScript_SunlightContinues; + // } - gBattleScripting.animArg1 = B_ANIM_HAIL_CONTINUES; - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_HAIL; - BattleScriptExecute(gBattlescriptCurrInstr); - effect++; - } - gBattleStruct->turnCountersTracker++; - break; - case ENDTURN_SNOW: - if (gBattleWeather & B_WEATHER_SNOW) - { - if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) - { - gBattleWeather &= ~B_WEATHER_SNOW; - gBattlescriptCurrInstr = BattleScript_SandStormHailSnowEnds; - } - else - { - gBattlescriptCurrInstr = BattleScript_DamagingWeatherContinues; - } + // BattleScriptExecute(gBattlescriptCurrInstr); + // effect++; + // } + // gBattleStruct->turnCountersTracker++; + // break; + // case ENDTURN_HAIL: + // if (gBattleWeather & B_WEATHER_HAIL) + // { + // if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) + // { + // gBattleWeather &= ~B_WEATHER_HAIL; + // gBattlescriptCurrInstr = BattleScript_SandStormHailSnowEnds; + // } + // else + // { + // gBattlescriptCurrInstr = BattleScript_DamagingWeatherContinues; + // } - gBattleScripting.animArg1 = B_ANIM_SNOW_CONTINUES; - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SNOW; - BattleScriptExecute(gBattlescriptCurrInstr); - effect++; - } - gBattleStruct->turnCountersTracker++; - break; - case ENDTURN_FOG: - if (gBattleWeather & B_WEATHER_FOG) - { - if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) - { - gBattleWeather &= ~B_WEATHER_FOG; - gBattlescriptCurrInstr = BattleScript_FogEnded; - } - else - { - gBattlescriptCurrInstr = BattleScript_FogContinues; - } + // gBattleScripting.animArg1 = B_ANIM_HAIL_CONTINUES; + // gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_HAIL; + // BattleScriptExecute(gBattlescriptCurrInstr); + // effect++; + // } + // gBattleStruct->turnCountersTracker++; + // break; + // case ENDTURN_SNOW: + // if (gBattleWeather & B_WEATHER_SNOW) + // { + // if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) + // { + // gBattleWeather &= ~B_WEATHER_SNOW; + // gBattlescriptCurrInstr = BattleScript_SandStormHailSnowEnds; + // } + // else + // { + // gBattlescriptCurrInstr = BattleScript_DamagingWeatherContinues; + // } - BattleScriptExecute(gBattlescriptCurrInstr); - effect++; - } - gBattleStruct->turnCountersTracker++; - break; + // gBattleScripting.animArg1 = B_ANIM_SNOW_CONTINUES; + // gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SNOW; + // BattleScriptExecute(gBattlescriptCurrInstr); + // effect++; + // } + // gBattleStruct->turnCountersTracker++; + // break; + // case ENDTURN_FOG: + // if (gBattleWeather & B_WEATHER_FOG) + // { + // if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) + // { + // gBattleWeather &= ~B_WEATHER_FOG; + // gBattlescriptCurrInstr = BattleScript_FogEnded; + // } + // else + // { + // gBattlescriptCurrInstr = BattleScript_FogContinues; + // } + + // BattleScriptExecute(gBattlescriptCurrInstr); + // effect++; + // } + // gBattleStruct->turnCountersTracker++; + // break; case ENDTURN_DAMAGE_NON_TYPES: while (gBattleStruct->turnSideTracker < 2) { From 0bb86e4437b36b2e06fd16ba1faa2725508f407e Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Sat, 28 Dec 2024 10:23:28 +0100 Subject: [PATCH 09/15] struct --- include/constants/battle.h | 2 + src/battle_util.c | 89 +++++++++++++++++++++++++++++--------- 2 files changed, 70 insertions(+), 21 deletions(-) diff --git a/include/constants/battle.h b/include/constants/battle.h index 561984bc9f..4d4021de03 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -297,6 +297,8 @@ enum BattleWeather BATTLE_WEATHER_STRONG_WINDS, }; +#define BATTLE_WEATHER_COUNT 10 + // Battle Weather flags #define B_WEATHER_NONE 0 #define B_WEATHER_RAIN_NORMAL (1 << BATTLE_WEATHER_RAIN) diff --git a/src/battle_util.c b/src/battle_util.c index b9bd851b92..df350905a2 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1568,20 +1568,70 @@ static bool32 EndTurnTerrain(u32 terrainFlag, u32 stringTableId) return FALSE; } -#define BATTLE_WEATHER_MESSAGE_STOPPED 0 -#define BATTLE_WEATHER_MESSAGE_TURN 1 -#define BATTLE_WEATHER_ANIMATION 2 -static const u32 sBattleWeatherAttributes[][3] = +struct BattleWeatherInfo { - // Type of Weather // End Message // Weather Continues // Weather Animation - [BATTLE_WEATHER_RAIN] = {B_MSG_WEATHER_END_RAIN, B_MSG_WEATHER_TURN_RAIN, B_ANIM_RAIN_CONTINUES}, - [BATTLE_WEATHER_RAIN_DOWNPOUR] = {B_MSG_WEATHER_END_RAIN, B_MSG_WEATHER_TURN_DOWNPOUR, B_ANIM_RAIN_CONTINUES}, - [BATTLE_WEATHER_SUN] = {B_MSG_WEATHER_END_SUN, B_MSG_WEATHER_TURN_SUN, B_ANIM_SUN_CONTINUES}, - [BATTLE_WEATHER_SANDSTORM] = {B_MSG_WEATHER_END_SANDSTORM, B_MSG_WEATHER_TURN_SANDSTORM, B_ANIM_SANDSTORM_CONTINUES}, - [BATTLE_WEATHER_HAIL] = {B_MSG_WEATHER_END_HAIL, B_MSG_WEATHER_TURN_HAIL, B_ANIM_HAIL_CONTINUES}, - [BATTLE_WEATHER_SNOW] = {B_MSG_WEATHER_END_SNOW, B_MSG_WEATHER_TURN_SNOW, B_ANIM_SNOW_CONTINUES}, - [BATTLE_WEATHER_FOG] = {B_MSG_WEATHER_END_FOG, B_MSG_WEATHER_TURN_FOG, B_ANIM_FOG_CONTINUES}, - [BATTLE_WEATHER_STRONG_WINDS] = {B_MSG_WEATHER_END_STRONG_WINDS, B_MSG_WEATHER_TURN_STRONG_WINDS, B_ANIM_STRONG_WINDS}, + u8 endMessage; + u8 continuesMessage; + u8 animation; +}; + +static const struct BattleWeatherInfo sBattleWeatherInfo[BATTLE_WEATHER_COUNT] = +{ + [BATTLE_WEATHER_RAIN] = + { + .endMessage = B_MSG_WEATHER_END_RAIN, + .continuesMessage = B_MSG_WEATHER_TURN_RAIN, + .animation = B_ANIM_RAIN_CONTINUES, + }, + + [BATTLE_WEATHER_RAIN_DOWNPOUR] = + { + .endMessage = B_MSG_WEATHER_END_RAIN, + .continuesMessage = B_MSG_WEATHER_TURN_DOWNPOUR, + .animation = B_ANIM_RAIN_CONTINUES, + }, + + [BATTLE_WEATHER_SUN] = + { + .endMessage = B_MSG_WEATHER_END_SUN, + .continuesMessage = B_MSG_WEATHER_TURN_SUN, + .animation = B_ANIM_SUN_CONTINUES, + }, + + [BATTLE_WEATHER_SANDSTORM] = + { + .endMessage = B_MSG_WEATHER_END_SANDSTORM, + .continuesMessage = B_MSG_WEATHER_TURN_SANDSTORM, + .animation = B_ANIM_SANDSTORM_CONTINUES, + }, + + [BATTLE_WEATHER_HAIL] = + { + .endMessage = B_MSG_WEATHER_END_HAIL, + .continuesMessage = B_MSG_WEATHER_TURN_HAIL, + .animation = B_ANIM_HAIL_CONTINUES, + }, + + [BATTLE_WEATHER_SNOW] = + { + .endMessage = B_MSG_WEATHER_END_SNOW, + .continuesMessage = B_MSG_WEATHER_TURN_SNOW, + .animation = B_ANIM_SNOW_CONTINUES, + }, + + [BATTLE_WEATHER_FOG] = + { + .endMessage = B_MSG_WEATHER_END_FOG, + .continuesMessage = B_MSG_WEATHER_TURN_FOG, + .animation = B_ANIM_FOG_CONTINUES, + }, + + [BATTLE_WEATHER_STRONG_WINDS] = + { + .endMessage = B_MSG_WEATHER_END_STRONG_WINDS, + .continuesMessage = B_MSG_WEATHER_TURN_STRONG_WINDS, + .animation = B_ANIM_STRONG_WINDS, + }, }; static bool32 TryEndTurnWeather(void) @@ -1602,30 +1652,27 @@ static bool32 TryEndTurnWeather(void) if (gBattleWeather & B_WEATHER_PRIMAL_ANY) // Might be redundant. handled in else case? { - gBattleCommunication[MULTISTRING_CHOOSER] = sBattleWeatherAttributes[currBattleWeather][BATTLE_WEATHER_MESSAGE_TURN]; - gBattleScripting.animArg1 = sBattleWeatherAttributes[currBattleWeather][BATTLE_WEATHER_ANIMATION]; + gBattleCommunication[MULTISTRING_CHOOSER] = sBattleWeatherInfo[currBattleWeather].continuesMessage; + gBattleScripting.animArg1 = sBattleWeatherInfo[currBattleWeather].animation; BattleScriptExecute(BattleScript_WeatherContinues); effect++; } else if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) { - gBattleCommunication[MULTISTRING_CHOOSER] = sBattleWeatherAttributes[currBattleWeather][BATTLE_WEATHER_MESSAGE_STOPPED]; + gBattleCommunication[MULTISTRING_CHOOSER] = sBattleWeatherInfo[currBattleWeather].endMessage; BattleScriptExecute(BattleScript_WeatherFaded); effect++; } else { - gBattleCommunication[MULTISTRING_CHOOSER] = sBattleWeatherAttributes[currBattleWeather][BATTLE_WEATHER_MESSAGE_TURN]; - gBattleScripting.animArg1 = sBattleWeatherAttributes[currBattleWeather][BATTLE_WEATHER_ANIMATION]; + gBattleCommunication[MULTISTRING_CHOOSER] = sBattleWeatherInfo[currBattleWeather].continuesMessage; + gBattleScripting.animArg1 = sBattleWeatherInfo[currBattleWeather].animation; BattleScriptExecute(BattleScript_WeatherContinues); effect++; } return effect; } -#undef BATTLE_WEATHER_MESSAGE_STOPPED -#undef BATTLE_WEATHER_MESSAGE_TURN -#undef BATTLE_WEATHER_ANIMATION u8 DoFieldEndTurnEffects(void) { From 6a906a3fc16cd53f29a7307166d9c09ac4b2f07d Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Sat, 28 Dec 2024 20:55:59 +0100 Subject: [PATCH 10/15] refactor done --- data/battle_scripts_1.s | 64 ++---------- include/battle_scripts.h | 11 +-- include/constants/battle.h | 7 +- src/battle_util.c | 198 +++++++++---------------------------- 4 files changed, 57 insertions(+), 223 deletions(-) diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 1b5a9f87ea..9a1e977bf3 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -5841,8 +5841,6 @@ BattleScript_LearnedNewMove:: BattleScript_LearnMoveReturn:: return -@@@ === NEW WEATHER SCRIPT - BattleScript_WeatherContinues:: printfromtable gWeatherTurnStringIds waitmessage B_WAIT_TIME_LONG @@ -5857,31 +5855,19 @@ BattleScript_WeatherFaded:: call BattleScript_ActivateWeatherAbilities end2 -@@@ === NEW WEATHER SCRIPT - -BattleScript_RainContinuesOrEnds:: - @printfromtable gRainContinuesStringIds - waitmessage B_WAIT_TIME_LONG - jumpifbyte CMP_EQUAL, cMULTISTRING_CHOOSER, B_MSG_RAIN_STOPPED, BattleScript_RainContinuesOrEndsEnd - playanimation BS_ATTACKER, B_ANIM_RAIN_CONTINUES -BattleScript_RainContinuesOrEndsEnd:: - call BattleScript_ActivateWeatherAbilities - end2 - -BattleScript_DamagingWeatherContinues:: - @printfromtable gSandStormHailSnowContinuesStringIds - waitmessage B_WAIT_TIME_LONG - playanimation_var BS_ATTACKER, sB_ANIM_ARG1 - setbyte gBattleCommunication, 0 - end2 - BattleScript_DamagingWeather:: - @printfromtable gSandStormHailDmgStringIds + printfromtable gSandStormHailDmgStringIds waitmessage B_WAIT_TIME_LONG effectivenesssound hitanimation BS_SCRIPTING goto BattleScript_DoTurnDmg +BattleScript_FogEnded_Ret:: + printstring STRINGID_FOGLIFTED + waitmessage B_WAIT_TIME_LONG + call BattleScript_ActivateWeatherAbilities + return + BattleScript_IceBodyHeal:: call BattleScript_AbilityPopUpScripting playanimation BS_SCRIPTING, B_ANIM_SIMPLE_HEAL @@ -5891,42 +5877,6 @@ BattleScript_IceBodyHeal:: waitmessage B_WAIT_TIME_LONG end2 -BattleScript_SandStormHailSnowEnds:: - @printfromtable gSandStormHailSnowEndStringIds - waitmessage B_WAIT_TIME_LONG - call BattleScript_ActivateWeatherAbilities - end2 - -BattleScript_SunlightContinues:: - printstring STRINGID_SUNLIGHTSTRONG - waitmessage B_WAIT_TIME_LONG - playanimation BS_ATTACKER, B_ANIM_SUN_CONTINUES - call BattleScript_ActivateWeatherAbilities - end2 - -BattleScript_SunlightFaded:: - printstring STRINGID_SUNLIGHTFADED - waitmessage B_WAIT_TIME_LONG - call BattleScript_ActivateWeatherAbilities - end2 - -BattleScript_FogContinues:: - printstring STRINGID_FOGISDEEP - waitmessage B_WAIT_TIME_LONG - playanimation BS_ATTACKER, B_ANIM_FOG_CONTINUES - call BattleScript_ActivateWeatherAbilities - end2 - -BattleScript_FogEnded_Ret:: - printstring STRINGID_FOGLIFTED - waitmessage B_WAIT_TIME_LONG - call BattleScript_ActivateWeatherAbilities - return - -BattleScript_FogEnded:: - call BattleScript_FogEnded_Ret - end2 - BattleScript_OverworldStatusStarts:: printfromtable gStartingStatusStringIds waitmessage B_WAIT_TIME_LONG diff --git a/include/battle_scripts.h b/include/battle_scripts.h index 743a5117b8..ef30b10b8a 100644 --- a/include/battle_scripts.h +++ b/include/battle_scripts.h @@ -50,21 +50,12 @@ extern const u8 BattleScript_DoSwitchOut[]; extern const u8 BattleScript_MoveSwitchOpenPartyScreen[]; extern const u8 BattleScript_Pausex20[]; extern const u8 BattleScript_LevelUp[]; - extern const u8 BattleScript_WeatherContinues[]; extern const u8 BattleScript_WeatherFaded[]; - -extern const u8 BattleScript_RainContinuesOrEnds[]; -extern const u8 BattleScript_SnowContinuesOrEnds[]; extern const u8 BattleScript_DamagingWeatherContinues[]; extern const u8 BattleScript_DamagingWeather[]; -extern const u8 BattleScript_IceBodyHeal[]; -extern const u8 BattleScript_SandStormHailSnowEnds[]; -extern const u8 BattleScript_SunlightContinues[]; -extern const u8 BattleScript_SunlightFaded[]; -extern const u8 BattleScript_FogContinues[]; extern const u8 BattleScript_FogEnded_Ret[]; -extern const u8 BattleScript_FogEnded[]; +extern const u8 BattleScript_IceBodyHeal[]; extern const u8 BattleScript_OverworldStatusStarts[]; extern const u8 BattleScript_OverworldWeatherStarts[]; extern const u8 BattleScript_OverworldTerrain[]; diff --git a/include/constants/battle.h b/include/constants/battle.h index 4d4021de03..99e498b628 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -288,27 +288,26 @@ enum BattleWeather BATTLE_WEATHER_RAIN, BATTLE_WEATHER_RAIN_PRIMAL, BATTLE_WEATHER_RAIN_DOWNPOUR, - BATTLE_WEATHER_SANDSTORM, BATTLE_WEATHER_SUN, BATTLE_WEATHER_SUN_PRIMAL, + BATTLE_WEATHER_SANDSTORM, BATTLE_WEATHER_HAIL, BATTLE_WEATHER_SNOW, BATTLE_WEATHER_FOG, BATTLE_WEATHER_STRONG_WINDS, + BATTLE_WEATHER_COUNT, }; -#define BATTLE_WEATHER_COUNT 10 - // Battle Weather flags #define B_WEATHER_NONE 0 #define B_WEATHER_RAIN_NORMAL (1 << BATTLE_WEATHER_RAIN) #define B_WEATHER_RAIN_PRIMAL (1 << BATTLE_WEATHER_RAIN_PRIMAL) #define B_WEATHER_RAIN_DOWNPOUR (1 << BATTLE_WEATHER_RAIN_DOWNPOUR) // unused #define B_WEATHER_RAIN (B_WEATHER_RAIN_NORMAL | B_WEATHER_RAIN_PRIMAL | B_WEATHER_RAIN_DOWNPOUR) -#define B_WEATHER_SANDSTORM (1 << BATTLE_WEATHER_SANDSTORM) #define B_WEATHER_SUN_NORMAL (1 << BATTLE_WEATHER_SUN) #define B_WEATHER_SUN_PRIMAL (1 << BATTLE_WEATHER_SUN_PRIMAL) #define B_WEATHER_SUN (B_WEATHER_SUN_NORMAL | B_WEATHER_SUN_PRIMAL) +#define B_WEATHER_SANDSTORM (1 << BATTLE_WEATHER_SANDSTORM) #define B_WEATHER_HAIL (1 << BATTLE_WEATHER_HAIL) #define B_WEATHER_SNOW (1 << BATTLE_WEATHER_SNOW) #define B_WEATHER_FOG (1 << BATTLE_WEATHER_FOG) diff --git a/src/battle_util.c b/src/battle_util.c index df350905a2..7efd58f659 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1521,12 +1521,6 @@ enum ENDTURN_TAILWIND, ENDTURN_WISH, ENDTURN_WEATHER, - // ENDTURN_RAIN, - // ENDTURN_SANDSTORM, - // ENDTURN_SUN, - // ENDTURN_HAIL, - // ENDTURN_SNOW, - // ENDTURN_FOG, ENDTURN_DAMAGE_NON_TYPES, ENDTURN_GRAVITY, ENDTURN_WATER_SPORT, @@ -1570,6 +1564,8 @@ static bool32 EndTurnTerrain(u32 terrainFlag, u32 stringTableId) struct BattleWeatherInfo { + u16 flag; + u8 rock; u8 endMessage; u8 continuesMessage; u8 animation; @@ -1579,6 +1575,17 @@ static const struct BattleWeatherInfo sBattleWeatherInfo[BATTLE_WEATHER_COUNT] = { [BATTLE_WEATHER_RAIN] = { + .flag = B_WEATHER_RAIN_NORMAL, + .rock = HOLD_EFFECT_DAMP_ROCK, + .endMessage = B_MSG_WEATHER_END_RAIN, + .continuesMessage = B_MSG_WEATHER_TURN_RAIN, + .animation = B_ANIM_RAIN_CONTINUES, + }, + + [BATTLE_WEATHER_RAIN_PRIMAL] = + { + .flag = B_WEATHER_RAIN_PRIMAL, + .rock = HOLD_EFFECT_DAMP_ROCK, .endMessage = B_MSG_WEATHER_END_RAIN, .continuesMessage = B_MSG_WEATHER_TURN_RAIN, .animation = B_ANIM_RAIN_CONTINUES, @@ -1586,6 +1593,8 @@ static const struct BattleWeatherInfo sBattleWeatherInfo[BATTLE_WEATHER_COUNT] = [BATTLE_WEATHER_RAIN_DOWNPOUR] = { + .flag = B_WEATHER_RAIN_NORMAL, + .rock = HOLD_EFFECT_DAMP_ROCK, .endMessage = B_MSG_WEATHER_END_RAIN, .continuesMessage = B_MSG_WEATHER_TURN_DOWNPOUR, .animation = B_ANIM_RAIN_CONTINUES, @@ -1593,6 +1602,17 @@ static const struct BattleWeatherInfo sBattleWeatherInfo[BATTLE_WEATHER_COUNT] = [BATTLE_WEATHER_SUN] = { + .flag = B_WEATHER_SUN_NORMAL, + .rock = HOLD_EFFECT_HEAT_ROCK, + .endMessage = B_MSG_WEATHER_END_SUN, + .continuesMessage = B_MSG_WEATHER_TURN_SUN, + .animation = B_ANIM_SUN_CONTINUES, + }, + + [BATTLE_WEATHER_SUN_PRIMAL] = + { + .flag = B_WEATHER_SUN_PRIMAL, + .rock = HOLD_EFFECT_HEAT_ROCK, .endMessage = B_MSG_WEATHER_END_SUN, .continuesMessage = B_MSG_WEATHER_TURN_SUN, .animation = B_ANIM_SUN_CONTINUES, @@ -1600,6 +1620,8 @@ static const struct BattleWeatherInfo sBattleWeatherInfo[BATTLE_WEATHER_COUNT] = [BATTLE_WEATHER_SANDSTORM] = { + .flag = B_WEATHER_SANDSTORM, + .rock = HOLD_EFFECT_SMOOTH_ROCK, .endMessage = B_MSG_WEATHER_END_SANDSTORM, .continuesMessage = B_MSG_WEATHER_TURN_SANDSTORM, .animation = B_ANIM_SANDSTORM_CONTINUES, @@ -1607,6 +1629,8 @@ static const struct BattleWeatherInfo sBattleWeatherInfo[BATTLE_WEATHER_COUNT] = [BATTLE_WEATHER_HAIL] = { + .flag = B_WEATHER_HAIL, + .rock = HOLD_EFFECT_ICY_ROCK, .endMessage = B_MSG_WEATHER_END_HAIL, .continuesMessage = B_MSG_WEATHER_TURN_HAIL, .animation = B_ANIM_HAIL_CONTINUES, @@ -1614,6 +1638,8 @@ static const struct BattleWeatherInfo sBattleWeatherInfo[BATTLE_WEATHER_COUNT] = [BATTLE_WEATHER_SNOW] = { + .flag = B_WEATHER_SNOW, + .rock = HOLD_EFFECT_ICY_ROCK, .endMessage = B_MSG_WEATHER_END_SNOW, .continuesMessage = B_MSG_WEATHER_TURN_SNOW, .animation = B_ANIM_SNOW_CONTINUES, @@ -1621,6 +1647,8 @@ static const struct BattleWeatherInfo sBattleWeatherInfo[BATTLE_WEATHER_COUNT] = [BATTLE_WEATHER_FOG] = { + .flag = B_WEATHER_FOG, + .rock = HOLD_EFFECT_NONE, .endMessage = B_MSG_WEATHER_END_FOG, .continuesMessage = B_MSG_WEATHER_TURN_FOG, .animation = B_ANIM_FOG_CONTINUES, @@ -1628,6 +1656,8 @@ static const struct BattleWeatherInfo sBattleWeatherInfo[BATTLE_WEATHER_COUNT] = [BATTLE_WEATHER_STRONG_WINDS] = { + .flag = B_WEATHER_STRONG_WINDS, + .rock = HOLD_EFFECT_NONE, .endMessage = B_MSG_WEATHER_END_STRONG_WINDS, .continuesMessage = B_MSG_WEATHER_TURN_STRONG_WINDS, .animation = B_ANIM_STRONG_WINDS, @@ -1650,14 +1680,7 @@ static bool32 TryEndTurnWeather(void) if (currBattleWeather == 0xFF) return effect; - if (gBattleWeather & B_WEATHER_PRIMAL_ANY) // Might be redundant. handled in else case? - { - gBattleCommunication[MULTISTRING_CHOOSER] = sBattleWeatherInfo[currBattleWeather].continuesMessage; - gBattleScripting.animArg1 = sBattleWeatherInfo[currBattleWeather].animation; - BattleScriptExecute(BattleScript_WeatherContinues); - effect++; - } - else if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) + if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) { gBattleCommunication[MULTISTRING_CHOOSER] = sBattleWeatherInfo[currBattleWeather].endMessage; BattleScriptExecute(BattleScript_WeatherFaded); @@ -1910,126 +1933,6 @@ u8 DoFieldEndTurnEffects(void) effect = TryEndTurnWeather(); gBattleStruct->turnCountersTracker++; break; - // case ENDTURN_RAIN: - // if (gBattleWeather & B_WEATHER_RAIN) - // { - // if (!(gBattleWeather & B_WEATHER_RAIN_PRIMAL) - // && gWishFutureKnock.weatherDuration > 0 - // && --gWishFutureKnock.weatherDuration == 0) - // { - // gBattleWeather &= ~(B_WEATHER_RAIN | B_WEATHER_RAIN_DOWNPOUR); - // gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_RAIN_STOPPED; - // } - // else if (gBattleWeather & B_WEATHER_RAIN_DOWNPOUR) - // gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_DOWNPOUR_CONTINUES; - // else - // gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_RAIN_CONTINUES; - - // BattleScriptExecute(BattleScript_RainContinuesOrEnds); - // effect++; - // } - // gBattleStruct->turnCountersTracker++; - // break; - // case ENDTURN_SANDSTORM: - // if (gBattleWeather & B_WEATHER_SANDSTORM) - // { - // if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) - // { - // gBattleWeather &= ~B_WEATHER_SANDSTORM; - // gBattlescriptCurrInstr = BattleScript_SandStormHailSnowEnds; - // } - // else - // { - // gBattlescriptCurrInstr = BattleScript_DamagingWeatherContinues; - // } - - // gBattleScripting.animArg1 = B_ANIM_SANDSTORM_CONTINUES; - // gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SANDSTORM; - // BattleScriptExecute(gBattlescriptCurrInstr); - // effect++; - // } - // gBattleStruct->turnCountersTracker++; - // break; - // case ENDTURN_SUN: - // if (gBattleWeather & B_WEATHER_SUN) - // { - // if (!(gBattleWeather & B_WEATHER_SUN_PRIMAL) - // && gWishFutureKnock.weatherDuration > 0 - // && --gWishFutureKnock.weatherDuration == 0) - // { - // for (i = 0; i < gBattlersCount; i++) - // gDisableStructs[i].weatherAbilityDone = FALSE; - // gBattleWeather &= ~B_WEATHER_SUN; - // gBattlescriptCurrInstr = BattleScript_SunlightFaded; - // } - // else - // { - // gBattlescriptCurrInstr = BattleScript_SunlightContinues; - // } - - // BattleScriptExecute(gBattlescriptCurrInstr); - // effect++; - // } - // gBattleStruct->turnCountersTracker++; - // break; - // case ENDTURN_HAIL: - // if (gBattleWeather & B_WEATHER_HAIL) - // { - // if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) - // { - // gBattleWeather &= ~B_WEATHER_HAIL; - // gBattlescriptCurrInstr = BattleScript_SandStormHailSnowEnds; - // } - // else - // { - // gBattlescriptCurrInstr = BattleScript_DamagingWeatherContinues; - // } - - // gBattleScripting.animArg1 = B_ANIM_HAIL_CONTINUES; - // gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_HAIL; - // BattleScriptExecute(gBattlescriptCurrInstr); - // effect++; - // } - // gBattleStruct->turnCountersTracker++; - // break; - // case ENDTURN_SNOW: - // if (gBattleWeather & B_WEATHER_SNOW) - // { - // if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) - // { - // gBattleWeather &= ~B_WEATHER_SNOW; - // gBattlescriptCurrInstr = BattleScript_SandStormHailSnowEnds; - // } - // else - // { - // gBattlescriptCurrInstr = BattleScript_DamagingWeatherContinues; - // } - - // gBattleScripting.animArg1 = B_ANIM_SNOW_CONTINUES; - // gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SNOW; - // BattleScriptExecute(gBattlescriptCurrInstr); - // effect++; - // } - // gBattleStruct->turnCountersTracker++; - // break; - // case ENDTURN_FOG: - // if (gBattleWeather & B_WEATHER_FOG) - // { - // if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) - // { - // gBattleWeather &= ~B_WEATHER_FOG; - // gBattlescriptCurrInstr = BattleScript_FogEnded; - // } - // else - // { - // gBattlescriptCurrInstr = BattleScript_FogContinues; - // } - - // BattleScriptExecute(gBattlescriptCurrInstr); - // effect++; - // } - // gBattleStruct->turnCountersTracker++; - // break; case ENDTURN_DAMAGE_NON_TYPES: while (gBattleStruct->turnSideTracker < 2) { @@ -2349,6 +2252,7 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->moveDamage[battler] = GetNonDynamaxMaxHP(battler) / 16; if (gBattleStruct->moveDamage[battler] == 0) gBattleStruct->moveDamage[battler] = 1; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_SANDSTORM; BattleScriptExecute(BattleScript_DamagingWeather); effect++; } @@ -2375,6 +2279,7 @@ u8 DoBattlerEndTurnEffects(void) gBattleStruct->moveDamage[battler] = GetNonDynamaxMaxHP(battler) / 16; if (gBattleStruct->moveDamage[battler] == 0) gBattleStruct->moveDamage[battler] = 1; + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_HAIL; BattleScriptExecute(BattleScript_DamagingWeather); effect++; } @@ -3995,19 +3900,6 @@ bool32 HasNoMonsToSwitch(u32 battler, u8 partyIdBattlerOn1, u8 partyIdBattlerOn2 } } -static const u16 sWeatherFlagsInfo[][2] = -{ - [BATTLE_WEATHER_RAIN] = {B_WEATHER_RAIN_NORMAL, HOLD_EFFECT_DAMP_ROCK}, - [BATTLE_WEATHER_RAIN_PRIMAL] = {B_WEATHER_RAIN_PRIMAL, HOLD_EFFECT_DAMP_ROCK}, - [BATTLE_WEATHER_SUN] = {B_WEATHER_SUN_NORMAL, HOLD_EFFECT_HEAT_ROCK}, - [BATTLE_WEATHER_SUN_PRIMAL] = {B_WEATHER_SUN_PRIMAL, HOLD_EFFECT_HEAT_ROCK}, - [BATTLE_WEATHER_SANDSTORM] = {B_WEATHER_SANDSTORM, HOLD_EFFECT_SMOOTH_ROCK}, - [BATTLE_WEATHER_HAIL] = {B_WEATHER_HAIL, HOLD_EFFECT_ICY_ROCK}, - [BATTLE_WEATHER_STRONG_WINDS] = {B_WEATHER_STRONG_WINDS, HOLD_EFFECT_NONE}, - [BATTLE_WEATHER_SNOW] = {B_WEATHER_SNOW, HOLD_EFFECT_ICY_ROCK}, - [BATTLE_WEATHER_FOG] = {B_WEATHER_FOG, HOLD_EFFECT_NONE}, -}; - bool32 TryChangeBattleWeather(u32 battler, u32 battleWeatherId, bool32 viaAbility) { u16 battlerAbility = GetBattlerAbility(battler); @@ -4018,15 +3910,17 @@ bool32 TryChangeBattleWeather(u32 battler, u32 battleWeatherId, bool32 viaAbilit { return FALSE; } - else if (B_ABILITY_WEATHER < GEN_6 && viaAbility && !(gBattleWeather & sWeatherFlagsInfo[battleWeatherId][0])) + else if (B_ABILITY_WEATHER < GEN_6 && viaAbility && !(gBattleWeather & sBattleWeatherInfo[battleWeatherId].flag)) { - gBattleWeather = (sWeatherFlagsInfo[battleWeatherId][0] | sWeatherFlagsInfo[battleWeatherId][0]); + gBattleWeather = sBattleWeatherInfo[battleWeatherId].flag; return TRUE; } - else if (!(gBattleWeather & (sWeatherFlagsInfo[battleWeatherId][0] | sWeatherFlagsInfo[battleWeatherId][0]))) + else if (!(gBattleWeather & sBattleWeatherInfo[battleWeatherId].flag)) { - gBattleWeather = (sWeatherFlagsInfo[battleWeatherId][0]); - if (GetBattlerHoldEffect(battler, TRUE) == sWeatherFlagsInfo[battleWeatherId][1]) + gBattleWeather = sBattleWeatherInfo[battleWeatherId].flag; + if (gBattleWeather & B_WEATHER_PRIMAL_ANY) + gWishFutureKnock.weatherDuration = 0; + if (GetBattlerHoldEffect(battler, TRUE) == sBattleWeatherInfo[battleWeatherId].rock) gWishFutureKnock.weatherDuration = 8; else gWishFutureKnock.weatherDuration = 5; From d9db60218c6a11ebf3192de33980462f77f1cbd4 Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Sat, 28 Dec 2024 22:58:16 +0100 Subject: [PATCH 11/15] some test fixes --- src/battle_script_commands.c | 6 +++--- src/battle_util.c | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 1f8b42801d..6f13c34495 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -11589,9 +11589,9 @@ static void Cmd_setfieldweather(void) { CMD_ARGS(u8 weather); - u8 weather = cmd->weather; + u8 battleWeatherId = cmd->weather; - if (!TryChangeBattleWeather(gBattlerAttacker, weather, FALSE)) + if (!TryChangeBattleWeather(gBattlerAttacker, battleWeatherId, FALSE)) { gBattleStruct->moveResultFlags[gBattlerTarget] |= MOVE_RESULT_MISSED; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_WEATHER_FAILED; @@ -11599,7 +11599,7 @@ static void Cmd_setfieldweather(void) return; } - switch (weather) + switch (battleWeatherId) { case BATTLE_WEATHER_RAIN: gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STARTED_RAIN; diff --git a/src/battle_util.c b/src/battle_util.c index 2323a28ce7..04b6f59956 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1684,6 +1684,7 @@ static bool32 TryEndTurnWeather(void) if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) { + gBattleWeather = B_WEATHER_NONE; gBattleCommunication[MULTISTRING_CHOOSER] = sBattleWeatherInfo[currBattleWeather].endMessage; BattleScriptExecute(BattleScript_WeatherFaded); effect++; From 3ac4f81de938e8306bd784387722b646d87e6ae5 Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Sat, 28 Dec 2024 23:01:52 +0100 Subject: [PATCH 12/15] protosynthesis test fix --- src/battle_util.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/battle_util.c b/src/battle_util.c index 04b6f59956..99cdb8858a 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1685,6 +1685,8 @@ static bool32 TryEndTurnWeather(void) if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) { gBattleWeather = B_WEATHER_NONE; + for (u32 i = 0; i < gBattlersCount; i++) + gDisableStructs[i].weatherAbilityDone = FALSE; gBattleCommunication[MULTISTRING_CHOOSER] = sBattleWeatherInfo[currBattleWeather].endMessage; BattleScriptExecute(BattleScript_WeatherFaded); effect++; From c9bde52fd2d9512cc4bef5b78637f768e90ddb16 Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Sun, 29 Dec 2024 10:23:46 +0100 Subject: [PATCH 13/15] fix last tests --- src/battle_util.c | 215 +++++++++++++++++++++++--------------------- test/battle/ai/ai.c | 14 +-- 2 files changed, 119 insertions(+), 110 deletions(-) diff --git a/src/battle_util.c b/src/battle_util.c index 99cdb8858a..34d8cadb16 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -96,6 +96,109 @@ static const u8 sPkblToEscapeFactor[][3] = { static const u8 sGoNearCounterToCatchFactor[] = {4, 3, 2, 1}; static const u8 sGoNearCounterToEscapeFactor[] = {4, 4, 4, 4}; + +struct BattleWeatherInfo +{ + u16 flag; + u8 rock; + u8 endMessage; + u8 continuesMessage; + u8 animation; +}; + +static const struct BattleWeatherInfo sBattleWeatherInfo[BATTLE_WEATHER_COUNT] = +{ + [BATTLE_WEATHER_RAIN] = + { + .flag = B_WEATHER_RAIN_NORMAL, + .rock = HOLD_EFFECT_DAMP_ROCK, + .endMessage = B_MSG_WEATHER_END_RAIN, + .continuesMessage = B_MSG_WEATHER_TURN_RAIN, + .animation = B_ANIM_RAIN_CONTINUES, + }, + + [BATTLE_WEATHER_RAIN_PRIMAL] = + { + .flag = B_WEATHER_RAIN_PRIMAL, + .rock = HOLD_EFFECT_DAMP_ROCK, + .endMessage = B_MSG_WEATHER_END_RAIN, + .continuesMessage = B_MSG_WEATHER_TURN_RAIN, + .animation = B_ANIM_RAIN_CONTINUES, + }, + + [BATTLE_WEATHER_RAIN_DOWNPOUR] = + { + .flag = B_WEATHER_RAIN_NORMAL, + .rock = HOLD_EFFECT_DAMP_ROCK, + .endMessage = B_MSG_WEATHER_END_RAIN, + .continuesMessage = B_MSG_WEATHER_TURN_DOWNPOUR, + .animation = B_ANIM_RAIN_CONTINUES, + }, + + [BATTLE_WEATHER_SUN] = + { + .flag = B_WEATHER_SUN_NORMAL, + .rock = HOLD_EFFECT_HEAT_ROCK, + .endMessage = B_MSG_WEATHER_END_SUN, + .continuesMessage = B_MSG_WEATHER_TURN_SUN, + .animation = B_ANIM_SUN_CONTINUES, + }, + + [BATTLE_WEATHER_SUN_PRIMAL] = + { + .flag = B_WEATHER_SUN_PRIMAL, + .rock = HOLD_EFFECT_HEAT_ROCK, + .endMessage = B_MSG_WEATHER_END_SUN, + .continuesMessage = B_MSG_WEATHER_TURN_SUN, + .animation = B_ANIM_SUN_CONTINUES, + }, + + [BATTLE_WEATHER_SANDSTORM] = + { + .flag = B_WEATHER_SANDSTORM, + .rock = HOLD_EFFECT_SMOOTH_ROCK, + .endMessage = B_MSG_WEATHER_END_SANDSTORM, + .continuesMessage = B_MSG_WEATHER_TURN_SANDSTORM, + .animation = B_ANIM_SANDSTORM_CONTINUES, + }, + + [BATTLE_WEATHER_HAIL] = + { + .flag = B_WEATHER_HAIL, + .rock = HOLD_EFFECT_ICY_ROCK, + .endMessage = B_MSG_WEATHER_END_HAIL, + .continuesMessage = B_MSG_WEATHER_TURN_HAIL, + .animation = B_ANIM_HAIL_CONTINUES, + }, + + [BATTLE_WEATHER_SNOW] = + { + .flag = B_WEATHER_SNOW, + .rock = HOLD_EFFECT_ICY_ROCK, + .endMessage = B_MSG_WEATHER_END_SNOW, + .continuesMessage = B_MSG_WEATHER_TURN_SNOW, + .animation = B_ANIM_SNOW_CONTINUES, + }, + + [BATTLE_WEATHER_FOG] = + { + .flag = B_WEATHER_FOG, + .rock = HOLD_EFFECT_NONE, + .endMessage = B_MSG_WEATHER_END_FOG, + .continuesMessage = B_MSG_WEATHER_TURN_FOG, + .animation = B_ANIM_FOG_CONTINUES, + }, + + [BATTLE_WEATHER_STRONG_WINDS] = + { + .flag = B_WEATHER_STRONG_WINDS, + .rock = HOLD_EFFECT_NONE, + .endMessage = B_MSG_WEATHER_END_STRONG_WINDS, + .continuesMessage = B_MSG_WEATHER_TURN_STRONG_WINDS, + .animation = B_ANIM_STRONG_WINDS, + }, +}; + static u8 CalcBeatUpPower(void) { u8 basePower; @@ -1564,108 +1667,6 @@ static bool32 EndTurnTerrain(u32 terrainFlag, u32 stringTableId) return FALSE; } -struct BattleWeatherInfo -{ - u16 flag; - u8 rock; - u8 endMessage; - u8 continuesMessage; - u8 animation; -}; - -static const struct BattleWeatherInfo sBattleWeatherInfo[BATTLE_WEATHER_COUNT] = -{ - [BATTLE_WEATHER_RAIN] = - { - .flag = B_WEATHER_RAIN_NORMAL, - .rock = HOLD_EFFECT_DAMP_ROCK, - .endMessage = B_MSG_WEATHER_END_RAIN, - .continuesMessage = B_MSG_WEATHER_TURN_RAIN, - .animation = B_ANIM_RAIN_CONTINUES, - }, - - [BATTLE_WEATHER_RAIN_PRIMAL] = - { - .flag = B_WEATHER_RAIN_PRIMAL, - .rock = HOLD_EFFECT_DAMP_ROCK, - .endMessage = B_MSG_WEATHER_END_RAIN, - .continuesMessage = B_MSG_WEATHER_TURN_RAIN, - .animation = B_ANIM_RAIN_CONTINUES, - }, - - [BATTLE_WEATHER_RAIN_DOWNPOUR] = - { - .flag = B_WEATHER_RAIN_NORMAL, - .rock = HOLD_EFFECT_DAMP_ROCK, - .endMessage = B_MSG_WEATHER_END_RAIN, - .continuesMessage = B_MSG_WEATHER_TURN_DOWNPOUR, - .animation = B_ANIM_RAIN_CONTINUES, - }, - - [BATTLE_WEATHER_SUN] = - { - .flag = B_WEATHER_SUN_NORMAL, - .rock = HOLD_EFFECT_HEAT_ROCK, - .endMessage = B_MSG_WEATHER_END_SUN, - .continuesMessage = B_MSG_WEATHER_TURN_SUN, - .animation = B_ANIM_SUN_CONTINUES, - }, - - [BATTLE_WEATHER_SUN_PRIMAL] = - { - .flag = B_WEATHER_SUN_PRIMAL, - .rock = HOLD_EFFECT_HEAT_ROCK, - .endMessage = B_MSG_WEATHER_END_SUN, - .continuesMessage = B_MSG_WEATHER_TURN_SUN, - .animation = B_ANIM_SUN_CONTINUES, - }, - - [BATTLE_WEATHER_SANDSTORM] = - { - .flag = B_WEATHER_SANDSTORM, - .rock = HOLD_EFFECT_SMOOTH_ROCK, - .endMessage = B_MSG_WEATHER_END_SANDSTORM, - .continuesMessage = B_MSG_WEATHER_TURN_SANDSTORM, - .animation = B_ANIM_SANDSTORM_CONTINUES, - }, - - [BATTLE_WEATHER_HAIL] = - { - .flag = B_WEATHER_HAIL, - .rock = HOLD_EFFECT_ICY_ROCK, - .endMessage = B_MSG_WEATHER_END_HAIL, - .continuesMessage = B_MSG_WEATHER_TURN_HAIL, - .animation = B_ANIM_HAIL_CONTINUES, - }, - - [BATTLE_WEATHER_SNOW] = - { - .flag = B_WEATHER_SNOW, - .rock = HOLD_EFFECT_ICY_ROCK, - .endMessage = B_MSG_WEATHER_END_SNOW, - .continuesMessage = B_MSG_WEATHER_TURN_SNOW, - .animation = B_ANIM_SNOW_CONTINUES, - }, - - [BATTLE_WEATHER_FOG] = - { - .flag = B_WEATHER_FOG, - .rock = HOLD_EFFECT_NONE, - .endMessage = B_MSG_WEATHER_END_FOG, - .continuesMessage = B_MSG_WEATHER_TURN_FOG, - .animation = B_ANIM_FOG_CONTINUES, - }, - - [BATTLE_WEATHER_STRONG_WINDS] = - { - .flag = B_WEATHER_STRONG_WINDS, - .rock = HOLD_EFFECT_NONE, - .endMessage = B_MSG_WEATHER_END_STRONG_WINDS, - .continuesMessage = B_MSG_WEATHER_TURN_STRONG_WINDS, - .animation = B_ANIM_STRONG_WINDS, - }, -}; - static bool32 TryEndTurnWeather(void) { u32 effect = 0; @@ -6490,12 +6491,20 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32 } break; case ABILITY_ICE_FACE: - if (IsBattlerWeatherAffected(battler, B_WEATHER_HAIL | B_WEATHER_SNOW) + u32 battlerWeatherAffected = IsBattlerWeatherAffected(battler, B_WEATHER_HAIL | B_WEATHER_SNOW); + if (battlerWeatherAffected && gBattleMons[battler].species == SPECIES_EISCUE) + { + // If Hail/Snow activates when in Eiscue is in base, prevent reversion when Eiscue Noice gets broken + gDisableStructs[battler].weatherAbilityDone = TRUE; + } + if (!gDisableStructs[battler].weatherAbilityDone + && battlerWeatherAffected && gBattleMons[battler].species == SPECIES_EISCUE_NOICE && !(gBattleMons[battler].status2 & STATUS2_TRANSFORMED)) { // TODO: Convert this to a proper FORM_CHANGE type. gBattleScripting.battler = battler; + gDisableStructs[battler].weatherAbilityDone = TRUE; gBattleMons[battler].species = SPECIES_EISCUE_ICE; BattleScriptPushCursorAndCallback(BattleScript_BattlerFormChangeWithStringEnd3); effect++; diff --git a/test/battle/ai/ai.c b/test/battle/ai/ai.c index 60f9db1f5c..0883e3cc59 100644 --- a/test/battle/ai/ai.c +++ b/test/battle/ai/ai.c @@ -261,20 +261,20 @@ AI_SINGLE_BATTLE_TEST("AI chooses the safest option to faint the target, taking u16 abilityAtk = ABILITY_NONE, holdItemAtk = ITEM_NONE; // Psychic is not very effective, but always hits. Solarbeam requires a charging turn, Double Edge has recoil and Focus Blast can miss; - // PARAMETRIZE { abilityAtk = ABILITY_STURDY; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SOLAR_BEAM; move3 = MOVE_PSYCHIC; move4 = MOVE_DOUBLE_EDGE; expectedMove = MOVE_PSYCHIC; } + PARAMETRIZE { abilityAtk = ABILITY_STURDY; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SOLAR_BEAM; move3 = MOVE_PSYCHIC; move4 = MOVE_DOUBLE_EDGE; expectedMove = MOVE_PSYCHIC; } // Same as above, but ai mon has rock head ability, so it can use Double Edge without taking recoil damage. Psychic can also lower Special Defense, // but because it faints the target it doesn't matter. - // PARAMETRIZE { abilityAtk = ABILITY_ROCK_HEAD; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SOLAR_BEAM; move3 = MOVE_PSYCHIC; move4 = MOVE_DOUBLE_EDGE; - // expectedMove = MOVE_PSYCHIC; expectedMove2 = MOVE_DOUBLE_EDGE; } + PARAMETRIZE { abilityAtk = ABILITY_ROCK_HEAD; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SOLAR_BEAM; move3 = MOVE_PSYCHIC; move4 = MOVE_DOUBLE_EDGE; + expectedMove = MOVE_PSYCHIC; expectedMove2 = MOVE_DOUBLE_EDGE; } // This time it's Solarbeam + Psychic, because the weather is sunny. PARAMETRIZE { abilityAtk = ABILITY_DROUGHT; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SOLAR_BEAM; move3 = MOVE_PSYCHIC; move4 = MOVE_DOUBLE_EDGE; expectedMove = MOVE_PSYCHIC; expectedMove2 = MOVE_SOLAR_BEAM; } // Psychic and Solar Beam are chosen because user is holding Power Herb - // PARAMETRIZE { abilityAtk = ABILITY_STURDY; holdItemAtk = ITEM_POWER_HERB; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SOLAR_BEAM; move3 = MOVE_PSYCHIC; move4 = MOVE_DOUBLE_EDGE; - // expectedMove = MOVE_PSYCHIC; expectedMove2 = MOVE_SOLAR_BEAM; } + PARAMETRIZE { abilityAtk = ABILITY_STURDY; holdItemAtk = ITEM_POWER_HERB; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SOLAR_BEAM; move3 = MOVE_PSYCHIC; move4 = MOVE_DOUBLE_EDGE; + expectedMove = MOVE_PSYCHIC; expectedMove2 = MOVE_SOLAR_BEAM; } // Skull Bash is chosen because it's the most accurate and is holding Power Herb - // PARAMETRIZE { abilityAtk = ABILITY_STURDY; holdItemAtk = ITEM_POWER_HERB; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SKULL_BASH; move3 = MOVE_SLAM; move4 = MOVE_DOUBLE_EDGE; - // expectedMove = MOVE_SKULL_BASH; } + PARAMETRIZE { abilityAtk = ABILITY_STURDY; holdItemAtk = ITEM_POWER_HERB; move1 = MOVE_FOCUS_BLAST; move2 = MOVE_SKULL_BASH; move3 = MOVE_SLAM; move4 = MOVE_DOUBLE_EDGE; + expectedMove = MOVE_SKULL_BASH; } GIVEN { AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_CHECK_VIABILITY | AI_FLAG_TRY_TO_FAINT); From 80df54adc6671b94dc1a0a92c271520c42b32190 Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Sat, 4 Jan 2025 10:56:56 +0100 Subject: [PATCH 14/15] review changes --- src/battle_util.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/battle_util.c b/src/battle_util.c index 34d8cadb16..33152376f2 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1672,13 +1672,14 @@ static bool32 TryEndTurnWeather(void) u32 effect = 0; u32 currBattleWeather = 0xFF; - if (gBattleWeather & B_WEATHER_RAIN) currBattleWeather = BATTLE_WEATHER_RAIN; - else if (gBattleWeather & B_WEATHER_SUN) currBattleWeather = BATTLE_WEATHER_SUN; - else if (gBattleWeather & B_WEATHER_SANDSTORM) currBattleWeather = BATTLE_WEATHER_SANDSTORM; - else if (gBattleWeather & B_WEATHER_HAIL) currBattleWeather = BATTLE_WEATHER_HAIL; - else if (gBattleWeather & B_WEATHER_SNOW) currBattleWeather = BATTLE_WEATHER_SNOW; - else if (gBattleWeather & B_WEATHER_FOG) currBattleWeather = BATTLE_WEATHER_FOG; - else if (gBattleWeather & B_WEATHER_STRONG_WINDS) currBattleWeather = BATTLE_WEATHER_STRONG_WINDS; + for (u32 weather = 0; weather < ARRAY_COUNT(sBattleWeatherInfo); weather++) + { + if (gBattleWeather & sBattleWeatherInfo[weather].flag) + { + currBattleWeather = weather; + break; + } + } if (currBattleWeather == 0xFF) return effect; @@ -4013,29 +4014,36 @@ bool32 HasNoMonsToSwitch(u32 battler, u8 partyIdBattlerOn1, u8 partyIdBattlerOn2 bool32 TryChangeBattleWeather(u32 battler, u32 battleWeatherId, bool32 viaAbility) { u16 battlerAbility = GetBattlerAbility(battler); - if (gBattleWeather & B_WEATHER_PRIMAL_ANY + + if (gBattleWeather & sBattleWeatherInfo[battleWeatherId].flag) + { + return FALSE; + } + else if (gBattleWeather & B_WEATHER_PRIMAL_ANY && battlerAbility != ABILITY_DESOLATE_LAND && battlerAbility != ABILITY_PRIMORDIAL_SEA && battlerAbility != ABILITY_DELTA_STREAM) { return FALSE; } - else if (B_ABILITY_WEATHER < GEN_6 && viaAbility && !(gBattleWeather & sBattleWeatherInfo[battleWeatherId].flag)) + else if (B_ABILITY_WEATHER < GEN_6 && viaAbility) { gBattleWeather = sBattleWeatherInfo[battleWeatherId].flag; return TRUE; } - else if (!(gBattleWeather & sBattleWeatherInfo[battleWeatherId].flag)) + else { + u32 rock = sBattleWeatherInfo[battleWeatherId].rock; gBattleWeather = sBattleWeatherInfo[battleWeatherId].flag; if (gBattleWeather & B_WEATHER_PRIMAL_ANY) gWishFutureKnock.weatherDuration = 0; - if (GetBattlerHoldEffect(battler, TRUE) == sBattleWeatherInfo[battleWeatherId].rock) + if (rock != 0 && GetBattlerHoldEffect(battler, TRUE) == rock) gWishFutureKnock.weatherDuration = 8; else gWishFutureKnock.weatherDuration = 5; return TRUE; } + return FALSE; } From 9eee076e643519bbe112da1b8e99c769f5225a68 Mon Sep 17 00:00:00 2001 From: AlexOn1ine Date: Sat, 4 Jan 2025 12:16:35 +0100 Subject: [PATCH 15/15] use one iterator --- src/battle_util.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/battle_util.c b/src/battle_util.c index 33152376f2..1f2e301f47 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1669,14 +1669,15 @@ static bool32 EndTurnTerrain(u32 terrainFlag, u32 stringTableId) static bool32 TryEndTurnWeather(void) { + u32 i = 0; u32 effect = 0; u32 currBattleWeather = 0xFF; - for (u32 weather = 0; weather < ARRAY_COUNT(sBattleWeatherInfo); weather++) + for (i = 0; i < ARRAY_COUNT(sBattleWeatherInfo); i++) { - if (gBattleWeather & sBattleWeatherInfo[weather].flag) + if (gBattleWeather & sBattleWeatherInfo[i].flag) { - currBattleWeather = weather; + currBattleWeather = i; break; } } @@ -1687,7 +1688,7 @@ static bool32 TryEndTurnWeather(void) if (gWishFutureKnock.weatherDuration > 0 && --gWishFutureKnock.weatherDuration == 0) { gBattleWeather = B_WEATHER_NONE; - for (u32 i = 0; i < gBattlersCount; i++) + for (i = 0; i < gBattlersCount; i++) gDisableStructs[i].weatherAbilityDone = FALSE; gBattleCommunication[MULTISTRING_CHOOSER] = sBattleWeatherInfo[currBattleWeather].endMessage; BattleScriptExecute(BattleScript_WeatherFaded);