From 6f538d840c9cd35ddce1899b9448ca9a3585756e Mon Sep 17 00:00:00 2001 From: Alex <93446519+AlexOn1ine@users.noreply.github.com> Date: Wed, 24 Apr 2024 20:10:25 +0200 Subject: [PATCH] Combine weather set commands (#4434) * Combine Weather set commands * further tests * minor error * update test names --- asm/macros/battle_script.inc | 13 ++-- data/battle_scripts_1.s | 12 ++-- src/battle_script_commands.c | 107 +++++++++++---------------------- test/battle/weather/hail.c | 24 ++++++++ test/battle/weather/rain.c | 22 +++++++ test/battle/weather/snow.c | 24 ++++++++ test/battle/weather/sunlight.c | 22 +++++++ 7 files changed, 139 insertions(+), 85 deletions(-) diff --git a/asm/macros/battle_script.inc b/asm/macros/battle_script.inc index 25e0110a51..69e4dd8d97 100644 --- a/asm/macros/battle_script.inc +++ b/asm/macros/battle_script.inc @@ -710,8 +710,9 @@ .byte 0x7c .endm - .macro setrain + .macro setfieldweather weather:req .byte 0x7d + .byte \weather .endm .macro setreflect @@ -833,7 +834,7 @@ .byte 0x94 .endm - .macro setsandstorm + .macro unused_95 .byte 0x95 .endm @@ -1005,7 +1006,7 @@ .4byte \jumpInstr .endm - .macro setsunny + .macro unused_bb .byte 0xbb .endm @@ -1080,7 +1081,7 @@ .byte 0xc7 .endm - .macro sethail + .macro unused_c8 .byte 0xc8 .endm @@ -1409,10 +1410,6 @@ callnative BS_TryRevertWeatherForm .endm - .macro setsnow - callnative BS_SetSnow - .endm - .macro applysaltcure battler:req callnative BS_ApplySaltCure .byte \battler diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index 5e36241c9a..9da79c38d8 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -187,7 +187,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 - setsnow + setfieldweather ENUM_WEATHER_SNOW call BattleScript_MoveWeatherChangeRet goto BattleScript_MoveSwitch BattleScript_EffectChillyReceptionPlayAnimation: @@ -4335,7 +4335,7 @@ BattleScript_EffectSandstorm:: attackstring ppreduce call BattleScript_CheckPrimalWeather - setsandstorm + setfieldweather ENUM_WEATHER_SANDSTORM goto BattleScript_MoveWeatherChange BattleScript_EffectRollout:: @@ -4501,7 +4501,7 @@ BattleScript_EffectRainDance:: attackstring ppreduce call BattleScript_CheckPrimalWeather - setrain + setfieldweather ENUM_WEATHER_RAIN BattleScript_MoveWeatherChange:: attackanimation waitanimation @@ -4519,7 +4519,7 @@ BattleScript_EffectSunnyDay:: attackstring ppreduce call BattleScript_CheckPrimalWeather - setsunny + setfieldweather ENUM_WEATHER_SUN goto BattleScript_MoveWeatherChange BattleScript_ExtremelyHarshSunlightWasNotLessened: @@ -4877,7 +4877,7 @@ BattleScript_EffectHail:: attackstring ppreduce call BattleScript_CheckPrimalWeather - sethail + setfieldweather ENUM_WEATHER_HAIL goto BattleScript_MoveWeatherChange BattleScript_EffectTorment:: @@ -9996,5 +9996,5 @@ BattleScript_EffectSnow:: attackstring ppreduce call BattleScript_CheckPrimalWeather - setsnow + setfieldweather ENUM_WEATHER_SNOW goto BattleScript_MoveWeatherChange diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index ddcbeee78c..21dcf57f6b 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -452,7 +452,7 @@ static void Cmd_setatkhptozero(void); static void Cmd_jumpifnexttargetvalid(void); static void Cmd_tryhealhalfhealth(void); static void Cmd_trymirrormove(void); -static void Cmd_setrain(void); +static void Cmd_setfieldweather(void); static void Cmd_setreflect(void); static void Cmd_setseeded(void); static void Cmd_manipulatedamage(void); @@ -476,7 +476,7 @@ static void Cmd_givepaydaymoney(void); static void Cmd_setlightscreen(void); static void Cmd_tryKO(void); static void Cmd_damagetohalftargethp(void); -static void Cmd_setsandstorm(void); +static void Cmd_unused_95(void); static void Cmd_weatherdamage(void); static void Cmd_tryinfatuating(void); static void Cmd_updatestatusicon(void); @@ -514,7 +514,7 @@ static void Cmd_presentdamagecalculation(void); static void Cmd_setsafeguard(void); static void Cmd_magnitudedamagecalculation(void); static void Cmd_jumpifnopursuitswitchdmg(void); -static void Cmd_setsunny(void); +static void Cmd_unused_bb(void); static void Cmd_halvehp(void); static void Cmd_copyfoestats(void); static void Cmd_rapidspinfree(void); @@ -527,7 +527,7 @@ static void Cmd_trydobeatup(void); static void Cmd_setsemiinvulnerablebit(void); static void Cmd_tryfiretwoturnmovenowbyeffect(void); static void Cmd_setminimize(void); -static void Cmd_sethail(void); +static void Cmd_unused_c8(void); static void Cmd_trymemento(void); static void Cmd_setforcedtarget(void); static void Cmd_setcharge(void); @@ -650,7 +650,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = Cmd_end, //0x3D Cmd_end2, //0x3E Cmd_end3, //0x3F - Cmd_unused5, //0x40 + Cmd_unused5, //0x40 Cmd_call, //0x41 Cmd_setroost, //0x42 Cmd_jumpifabilitypresent, //0x43 @@ -711,7 +711,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = Cmd_jumpifnexttargetvalid, //0x7A Cmd_tryhealhalfhealth, //0x7B Cmd_trymirrormove, //0x7C - Cmd_setrain, //0x7D + Cmd_setfieldweather, //0x7D Cmd_setreflect, //0x7E Cmd_setseeded, //0x7F Cmd_manipulatedamage, //0x80 @@ -735,7 +735,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = Cmd_setlightscreen, //0x92 Cmd_tryKO, //0x93 Cmd_damagetohalftargethp, //0x94 - Cmd_setsandstorm, //0x95 + Cmd_unused_95, //0x95 Cmd_weatherdamage, //0x96 Cmd_tryinfatuating, //0x97 Cmd_updatestatusicon, //0x98 @@ -773,7 +773,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = Cmd_setsafeguard, //0xB8 Cmd_magnitudedamagecalculation, //0xB9 Cmd_jumpifnopursuitswitchdmg, //0xBA - Cmd_setsunny, //0xBB + Cmd_unused_bb, //0xBB Cmd_halvehp, //0xBC Cmd_copyfoestats, //0xBD Cmd_rapidspinfree, //0xBE @@ -786,7 +786,7 @@ void (* const gBattleScriptingCommandsTable[])(void) = Cmd_setsemiinvulnerablebit, //0xC5 Cmd_tryfiretwoturnmovenowbyeffect, //0xC6 Cmd_setminimize, //0xC7 - Cmd_sethail, //0xC8 + Cmd_unused_c8, //0xC8 Cmd_trymemento, //0xC9 Cmd_setforcedtarget, //0xCA Cmd_setcharge, //0xCB @@ -11085,19 +11085,39 @@ static void Cmd_trymirrormove(void) } } -static void Cmd_setrain(void) +static void Cmd_setfieldweather(void) { - CMD_ARGS(); + CMD_ARGS(u8 weather); - if (!TryChangeBattleWeather(gBattlerAttacker, ENUM_WEATHER_RAIN, FALSE)) + u8 weather = cmd->weather; + + if (!TryChangeBattleWeather(gBattlerAttacker, weather, FALSE)) { gMoveResultFlags |= MOVE_RESULT_MISSED; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_WEATHER_FAILED; + gBattlescriptCurrInstr = cmd->nextInstr; + return; } - else + + switch (weather) { + case ENUM_WEATHER_RAIN: gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STARTED_RAIN; + break; + case ENUM_WEATHER_SUN: + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STARTED_SUNLIGHT; + break; + case ENUM_WEATHER_SANDSTORM: + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STARTED_SANDSTORM; + break; + case ENUM_WEATHER_HAIL: + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STARTED_HAIL; + break; + case ENUM_WEATHER_SNOW: + gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STARTED_SNOW; + break; } + gBattlescriptCurrInstr = cmd->nextInstr; } @@ -12300,20 +12320,8 @@ static void Cmd_damagetohalftargethp(void) gBattlescriptCurrInstr = cmd->nextInstr; } -static void Cmd_setsandstorm(void) +static void Cmd_unused_95(void) { - CMD_ARGS(); - - if (!TryChangeBattleWeather(gBattlerAttacker, ENUM_WEATHER_SANDSTORM, FALSE)) - { - gMoveResultFlags |= MOVE_RESULT_MISSED; - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_WEATHER_FAILED; - } - else - { - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STARTED_SANDSTORM; - } - gBattlescriptCurrInstr = cmd->nextInstr; } static void Cmd_weatherdamage(void) @@ -13519,21 +13527,8 @@ static void Cmd_jumpifnopursuitswitchdmg(void) } } -static void Cmd_setsunny(void) +static void Cmd_unused_bb(void) { - CMD_ARGS(); - - if (!TryChangeBattleWeather(gBattlerAttacker, ENUM_WEATHER_SUN, FALSE)) - { - gMoveResultFlags |= MOVE_RESULT_MISSED; - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_WEATHER_FAILED; - } - else - { - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STARTED_SUNLIGHT; - } - - gBattlescriptCurrInstr = cmd->nextInstr; } // Belly Drum, Fillet Away @@ -13850,21 +13845,8 @@ static void Cmd_setminimize(void) gBattlescriptCurrInstr = cmd->nextInstr; } -static void Cmd_sethail(void) +static void Cmd_unused_c8(void) { - CMD_ARGS(); - - if (!TryChangeBattleWeather(gBattlerAttacker, ENUM_WEATHER_HAIL, FALSE)) - { - gMoveResultFlags |= MOVE_RESULT_MISSED; - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_WEATHER_FAILED; - } - else - { - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STARTED_HAIL; - } - - gBattlescriptCurrInstr = cmd->nextInstr; } static void Cmd_trymemento(void) @@ -16212,23 +16194,6 @@ void BS_TryRevertWeatherForm(void) gBattlescriptCurrInstr = cmd->nextInstr; } -void BS_SetSnow(void) -{ - NATIVE_ARGS(); - - if (!TryChangeBattleWeather(gBattlerAttacker, ENUM_WEATHER_SNOW, FALSE)) - { - gMoveResultFlags |= MOVE_RESULT_MISSED; - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_WEATHER_FAILED; - - } - else - { - gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STARTED_SNOW; - } - gBattlescriptCurrInstr = cmd->nextInstr; -} - void BS_HandleMegaEvolution(void) { NATIVE_ARGS(u8 battler, u8 caseId); diff --git a/test/battle/weather/hail.c b/test/battle/weather/hail.c index 8908e17a79..567037ccaa 100644 --- a/test/battle/weather/hail.c +++ b/test/battle/weather/hail.c @@ -29,3 +29,27 @@ SINGLE_BATTLE_TEST("Hail damage does not affect Ice-type Pokémon") NOT MESSAGE("Foe Glalie is pelted by HAIL!"); } } + +SINGLE_BATTLE_TEST("Hail fails if Desolate Land or Primordial Sea are active") +{ + u32 species; + u32 item; + + PARAMETRIZE { species = SPECIES_WOBBUFFET; item = ITEM_NONE; } + PARAMETRIZE { species = SPECIES_GROUDON; item = ITEM_RED_ORB; } + PARAMETRIZE { species = SPECIES_KYOGRE; item = ITEM_BLUE_ORB; } + + GIVEN { + PLAYER(species) { Item(item); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(opponent, MOVE_HAIL); } + } SCENE { + if (item == ITEM_RED_ORB || item == ITEM_BLUE_ORB) { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_PRIMAL_REVERSION, player); + NOT ANIMATION(ANIM_TYPE_MOVE, MOVE_HAIL, opponent); + } else { + ANIMATION(ANIM_TYPE_MOVE, MOVE_HAIL, opponent); + } + } +} diff --git a/test/battle/weather/rain.c b/test/battle/weather/rain.c index ce05870290..3359d25a81 100644 --- a/test/battle/weather/rain.c +++ b/test/battle/weather/rain.c @@ -45,3 +45,25 @@ SINGLE_BATTLE_TEST("Rain multiplies the power of Water-type moves by 1.5x", s16 EXPECT_MUL_EQ(results[0].damage, Q_4_12(1.5), results[1].damage); } } + +SINGLE_BATTLE_TEST("Drizzle fails if Desolate Land is active") +{ + u32 item; + + PARAMETRIZE { item = ITEM_NONE; } + PARAMETRIZE { item = ITEM_RED_ORB; } + + GIVEN { + PLAYER(SPECIES_GROUDON) { Item(item); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(opponent, MOVE_RAIN_DANCE); } + } SCENE { + if (item == ITEM_RED_ORB) { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_PRIMAL_REVERSION, player); + NOT ANIMATION(ANIM_TYPE_MOVE, MOVE_RAIN_DANCE, opponent); + } else { + ANIMATION(ANIM_TYPE_MOVE, MOVE_RAIN_DANCE, opponent); + } + } +} diff --git a/test/battle/weather/snow.c b/test/battle/weather/snow.c index c617f651c4..3aceaf2f85 100644 --- a/test/battle/weather/snow.c +++ b/test/battle/weather/snow.c @@ -27,3 +27,27 @@ SINGLE_BATTLE_TEST("Snow multiplies the defense of Ice-types by 1.5x", s16 damag EXPECT_MUL_EQ(results[0].damage, Q_4_12(1.5), results[1].damage); } } + +SINGLE_BATTLE_TEST("Snowscape fails if Desolate Land or Primordial Sea are active") +{ + u32 species; + u32 item; + + PARAMETRIZE { species = SPECIES_WOBBUFFET; item = ITEM_NONE; } + PARAMETRIZE { species = SPECIES_GROUDON; item = ITEM_RED_ORB; } + PARAMETRIZE { species = SPECIES_KYOGRE; item = ITEM_BLUE_ORB; } + + GIVEN { + PLAYER(species) { Item(item); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(opponent, MOVE_SNOWSCAPE); } + } SCENE { + if (item == ITEM_RED_ORB || item == ITEM_BLUE_ORB) { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_PRIMAL_REVERSION, player); + NOT ANIMATION(ANIM_TYPE_MOVE, MOVE_SNOWSCAPE, opponent); + } else { + ANIMATION(ANIM_TYPE_MOVE, MOVE_SNOWSCAPE, opponent); + } + } +} diff --git a/test/battle/weather/sunlight.c b/test/battle/weather/sunlight.c index 4c8ea5cb19..6cf6348987 100644 --- a/test/battle/weather/sunlight.c +++ b/test/battle/weather/sunlight.c @@ -45,3 +45,25 @@ SINGLE_BATTLE_TEST("Sunlight multiplies the power of Water-type moves by 0.5x", EXPECT_MUL_EQ(results[0].damage, Q_4_12(0.5), results[1].damage); } } + +SINGLE_BATTLE_TEST("Sunny Day fails if Primordial Sea is active") +{ + u32 item; + + PARAMETRIZE { item = ITEM_NONE; } + PARAMETRIZE { item = ITEM_BLUE_ORB; } + + GIVEN { + PLAYER(SPECIES_KYOGRE) { Item(item); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(opponent, MOVE_SUNNY_DAY); } + } SCENE { + if (item == ITEM_BLUE_ORB) { + ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_PRIMAL_REVERSION, player); + NOT ANIMATION(ANIM_TYPE_MOVE, MOVE_SUNNY_DAY, opponent); + } else { + ANIMATION(ANIM_TYPE_MOVE, MOVE_SUNNY_DAY, opponent); + } + } +}