Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Forecast and Flower Gift #2978

Merged
merged 8 commits into from
May 23, 2023
4 changes: 4 additions & 0 deletions asm/macros/battle_script.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,10 @@
callnative BS_ItemRestorePP
.endm

.macro tryrevertweatherform
callnative BS_TryRevertWeatherForm
.endm

.macro setsnow
callnative BS_SetSnow
.endm
Expand Down
46 changes: 30 additions & 16 deletions data/battle_scripts_1.s
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,7 @@ BattleScript_MoveEffectCoreEnforcer::
printstring STRINGID_PKMNSABILITYSUPPRESSED
waitmessage B_WAIT_TIME_LONG
trytoclearprimalweather
tryrevertweatherform
printstring STRINGID_EMPTYSTRING3
waitmessage 1
BattleScript_CoreEnforcerRet:
Expand Down Expand Up @@ -2729,6 +2730,7 @@ BattleScript_EffectSimpleBeam:
printstring STRINGID_PKMNACQUIREDSIMPLE
waitmessage B_WAIT_TIME_LONG
trytoclearprimalweather
tryrevertweatherform
printstring STRINGID_EMPTYSTRING3
waitmessage 1
tryendneutralizinggas BS_TARGET
Expand Down Expand Up @@ -2828,6 +2830,7 @@ BattleScript_EffectWorrySeed:
printstring STRINGID_PKMNACQUIREDABILITY
waitmessage B_WAIT_TIME_LONG
trytoclearprimalweather
tryrevertweatherform
printstring STRINGID_EMPTYSTRING3
waitmessage 1
goto BattleScript_MoveEnd
Expand Down Expand Up @@ -2959,6 +2962,7 @@ BattleScript_EffectGastroAcid:
printstring STRINGID_PKMNSABILITYSUPPRESSED
waitmessage B_WAIT_TIME_LONG
trytoclearprimalweather
tryrevertweatherform
printstring STRINGID_EMPTYSTRING3
waitmessage 1
tryendneutralizinggas BS_TARGET
Expand Down Expand Up @@ -6848,6 +6852,7 @@ BattleScript_RainContinuesOrEnds::
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::
Expand Down Expand Up @@ -6881,22 +6886,26 @@ BattleScript_DamagingWeatherLoopIncrement::
jumpifbytenotequal gBattleCommunication, gBattlersCount, BattleScript_DamagingWeatherLoop
BattleScript_DamagingWeatherContinuesEnd::
bicword gHitMarker, HITMARKER_SKIP_DMG_TRACK | HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_PASSIVE_DAMAGE | HITMARKER_GRUDGE
call BattleScript_ActivateWeatherAbilities
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_OverworldWeatherStarts::
Expand Down Expand Up @@ -7995,9 +8004,7 @@ BattleScript_CudChewActivates::
setbyte sBERRY_OVERRIDE, 0
end3

BattleScript_TargetFormChange::
pause 5
call BattleScript_AbilityPopUpTarget
BattleScript_TargetFormChangeNoPopup:
printstring STRINGID_EMPTYSTRING3
waitmessage 1
handleformchange BS_TARGET, 0
Expand All @@ -8007,16 +8014,22 @@ BattleScript_TargetFormChange::
handleformchange BS_TARGET, 2
return

BattleScript_TargetFormChange::
pause 5
call BattleScript_AbilityPopUpTarget
call BattleScript_TargetFormChangeNoPopup
return

BattleScript_TargetFormChangeWithString::
pause 5
call BattleScript_AbilityPopUpTarget
printstring STRINGID_EMPTYSTRING3
waitmessage 1
handleformchange BS_TARGET, 0
handleformchange BS_TARGET, 1
playanimation BS_TARGET, B_ANIM_FORM_CHANGE, NULL
waitanimation
handleformchange BS_TARGET, 2
call BattleScript_TargetFormChangeNoPopup
printstring STRINGID_PKMNTRANSFORMED
waitmessage B_WAIT_TIME_LONG
return

BattleScript_TargetFormChangeWithStringNoPopup::
call BattleScript_TargetFormChangeNoPopup
printstring STRINGID_PKMNTRANSFORMED
waitmessage B_WAIT_TIME_LONG
return
Expand Down Expand Up @@ -8664,14 +8677,15 @@ BattleScript_ShedSkinActivates::
end3

BattleScript_ActivateWeatherAbilities:
copybyte sBATTLER, gBattlerAttacker
setbyte gBattlerAttacker, 0
savetarget
setbyte gBattlerTarget, 0
BattleScript_ActivateWeatherAbilities_Loop:
activateweatherchangeabilities BS_ATTACKER
copybyte sBATTLER, gBattlerTarget
activateweatherchangeabilities BS_TARGET
BattleScript_ActivateWeatherAbilities_Increment:
addbyte gBattlerAttacker, 1
jumpifbytenotequal gBattlerAttacker, gBattlersCount, BattleScript_ActivateWeatherAbilities_Loop
copybyte gBattlerAttacker, sBATTLER
addbyte gBattlerTarget, 1
jumpifbytenotequal gBattlerTarget, gBattlersCount, BattleScript_ActivateWeatherAbilities_Loop
restoretarget
AgustinGDLV marked this conversation as resolved.
Show resolved Hide resolved
return

BattleScript_TryAdrenalineOrb:
Expand Down
1 change: 1 addition & 0 deletions include/battle_scripts.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ extern const u8 BattleScript_MoveEffectStockpileWoreOff[];
extern const u8 BattleScript_StealthRockActivates[];
extern const u8 BattleScript_SpikesActivates[];
extern const u8 BattleScript_BerserkGeneRet[];
extern const u8 BattleScript_TargetFormChangeWithStringNoPopup[];

// zmoves
extern const u8 BattleScript_ZMoveActivateDamaging[];
Expand Down
1 change: 0 additions & 1 deletion include/battle_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ void TryClearRageAndFuryCutter(void);
u8 AtkCanceller_UnableToUseMove(void);
u8 AtkCanceller_UnableToUseMove2(void);
bool8 HasNoMonsToSwitch(u8 battlerId, u8 r1, u8 r2);
u8 TryWeatherFormChange(u8 battlerId);
bool32 TryChangeBattleWeather(u8 battler, u32 weatherEnumId, bool32 viaAbility);
u8 AbilityBattleEffects(u8 caseID, u8 battlerId, u16 ability, u8 special, u16 moveArg);
bool32 IsNeutralizingGasOnField(void);
Expand Down
1 change: 1 addition & 0 deletions include/constants/form_change_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@

// Form change that activates when a specific weather is set during battle.
// param1: weather to check
// param2: (optional) revert if specified ability is lost
#define FORM_CHANGE_BATTLE_WEATHER 14

// Form change that activates automatically when the turn ends.
Expand Down
25 changes: 21 additions & 4 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -16448,7 +16448,8 @@ u8 GetFirstFaintedPartyIndex(u8 battlerId)
return PARTY_SIZE;
}

void BS_ItemRestoreHP(void) {
void BS_ItemRestoreHP(void)
{
NATIVE_ARGS();
u16 healAmount;
u32 battlerId = MAX_BATTLERS_COUNT;
Expand Down Expand Up @@ -16510,7 +16511,8 @@ void BS_ItemRestoreHP(void) {
gBattlescriptCurrInstr = cmd->nextInstr;
}

void BS_ItemCureStatus(void) {
void BS_ItemCureStatus(void)
{
NATIVE_ARGS();
struct Pokemon *party = GetBattlerParty(gBattlerAttacker);

Expand Down Expand Up @@ -16538,15 +16540,17 @@ void BS_ItemCureStatus(void) {
gBattlescriptCurrInstr = cmd->nextInstr;
}

void BS_ItemIncreaseStat(void) {
void BS_ItemIncreaseStat(void)
{
NATIVE_ARGS();
u16 statId = GetItemEffect(gLastUsedItem)[1];
u16 stages = ItemId_GetHoldEffectParam(gLastUsedItem);
SET_STATCHANGER(statId, stages, FALSE);
gBattlescriptCurrInstr = cmd->nextInstr;
}

void BS_ItemRestorePP(void) {
void BS_ItemRestorePP(void)
{
NATIVE_ARGS();
const u8 *effect = GetItemEffect(gLastUsedItem);
u32 i, pp, maxPP, moveId, loopEnd;
Expand Down Expand Up @@ -16598,6 +16602,19 @@ void BS_ItemRestorePP(void) {
gBattlescriptCurrInstr = cmd->nextInstr;
}

void BS_TryRevertWeatherForm(void)
{
NATIVE_ARGS();
if (TryBattleFormChange(gBattlerTarget, FORM_CHANGE_BATTLE_WEATHER))
{
gBattleScripting.battler = gBattlerTarget;
BattleScriptPush(cmd->nextInstr);
gBattlescriptCurrInstr = BattleScript_TargetFormChangeWithStringNoPopup;
return;
}
gBattlescriptCurrInstr = cmd->nextInstr;
}

void BS_SetSnow(void)
{
NATIVE_ARGS();
Expand Down
122 changes: 25 additions & 97 deletions src/battle_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -4006,96 +4006,6 @@ bool8 HasNoMonsToSwitch(u8 battler, u8 partyIdBattlerOn1, u8 partyIdBattlerOn2)
}
}

u8 TryWeatherFormChange(u8 battler)
{
u8 ret = 0;
bool32 weatherEffect = WEATHER_HAS_EFFECT;
u16 holdEffect = GetBattlerHoldEffect(battler, TRUE);

switch (gBattleMons[battler].species)
{
case SPECIES_CASTFORM:
/* Placeholder
case SPECIES_CASTFORM_RAINY:
case SPECIES_CASTFORM_SNOWY:
case SPECIES_CASTFORM_SUNNY:*/
#if B_WEATHER_FORMS >= GEN_5
if (gBattleMons[battler].hp == 0)
{
ret = 0; // No change
}
else if (GetBattlerAbility(battler) != ABILITY_FORECAST || !weatherEffect)
{
if (!IS_BATTLER_OF_TYPE(battler, TYPE_NORMAL))
{
SET_BATTLER_TYPE(battler, TYPE_NORMAL);
ret = CASTFORM_NORMAL + 1;
}
else
{
ret = 0; // No change
}
}
#else
if (GetBattlerAbility(battler) != ABILITY_FORECAST || gBattleMons[battler].hp == 0)
{
ret = 0; // No change
}
else if (!weatherEffect)
{
if (!IS_BATTLER_OF_TYPE(battler, TYPE_NORMAL))
{
SET_BATTLER_TYPE(battler, TYPE_NORMAL);
ret = CASTFORM_NORMAL + 1;
}
else
{
ret = 0; // No change
}
}
#endif
else if (holdEffect == HOLD_EFFECT_UTILITY_UMBRELLA || (!(gBattleWeather & (B_WEATHER_RAIN | B_WEATHER_SUN | B_WEATHER_HAIL | B_WEATHER_SNOW)) && !IS_BATTLER_OF_TYPE(battler, TYPE_NORMAL)))
{
SET_BATTLER_TYPE(battler, TYPE_NORMAL);
ret = CASTFORM_NORMAL + 1;
}
else if (gBattleWeather & B_WEATHER_SUN && holdEffect != HOLD_EFFECT_UTILITY_UMBRELLA && !IS_BATTLER_OF_TYPE(battler, TYPE_FIRE))
{
SET_BATTLER_TYPE(battler, TYPE_FIRE);
ret = CASTFORM_FIRE + 1;
}
else if (gBattleWeather & B_WEATHER_RAIN && holdEffect != HOLD_EFFECT_UTILITY_UMBRELLA && !IS_BATTLER_OF_TYPE(battler, TYPE_WATER))
{
SET_BATTLER_TYPE(battler, TYPE_WATER);
ret = CASTFORM_WATER + 1;
}
else if (gBattleWeather & (B_WEATHER_HAIL | B_WEATHER_SNOW) && !IS_BATTLER_OF_TYPE(battler, TYPE_ICE))
{
SET_BATTLER_TYPE(battler, TYPE_ICE);
ret = CASTFORM_ICE + 1;
}
break;
case SPECIES_CHERRIM:
// case SPECIES_CHERRIM_SUNSHINE:
if (gBattleMons[battler].hp == 0)
ret = 0; // No change
#if B_WEATHER_FORMS >= GEN_5
if (GetBattlerAbility(battler) != ABILITY_FLOWER_GIFT)
if (gBattleMonForms[battler] != 0)
ret = CHERRIM_OVERCAST + 1;
else
ret = 0; // No change
#endif
else if (gBattleMonForms[battler] == 0 && weatherEffect && holdEffect != HOLD_EFFECT_UTILITY_UMBRELLA && gBattleWeather & B_WEATHER_SUN)
ret = CHERRIM_SUNSHINE + 1;
else if (gBattleMonForms[battler] != 0 && (!weatherEffect || holdEffect == HOLD_EFFECT_UTILITY_UMBRELLA || !(gBattleWeather & B_WEATHER_SUN)))
ret = CHERRIM_OVERCAST + 1;
break;
}

return ret;
}

static const u16 sWeatherFlagsInfo[][3] =
{
[ENUM_WEATHER_RAIN] = {B_WEATHER_RAIN_TEMPORARY, B_WEATHER_RAIN_PERMANENT, HOLD_EFFECT_DAMP_ROCK},
Expand Down Expand Up @@ -6132,8 +6042,10 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u16 ability, u8 special, u16 move
#else
TRY_WEATHER_FORM:
#endif
if ((IsBattlerWeatherAffected(battler, gBattleWeather) || gBattleWeather == B_WEATHER_NONE)
&& TryBattleFormChange(battler, FORM_CHANGE_BATTLE_WEATHER))
if ((IsBattlerWeatherAffected(battler, gBattleWeather)
|| gBattleWeather == B_WEATHER_NONE
|| !WEATHER_HAS_EFFECT) // Air Lock active
&& TryBattleFormChange(battler, FORM_CHANGE_BATTLE_WEATHER))
{
BattleScriptPushCursorAndCallback(BattleScript_BattlerFormChangeWithStringEnd3);
effect++;
Expand Down Expand Up @@ -9325,7 +9237,7 @@ static u32 CalcAttackStat(u16 move, u8 battlerAtk, u8 battlerDef, u8 moveType, b
break;
#endif
case ABILITY_FLOWER_GIFT:
if (gBattleMons[battlerAtk].species == SPECIES_CHERRIM && IsBattlerWeatherAffected(battlerAtk, B_WEATHER_SUN) && IS_MOVE_PHYSICAL(move))
if (gBattleMons[battlerAtk].species == SPECIES_CHERRIM_SUNSHINE && IsBattlerWeatherAffected(battlerAtk, B_WEATHER_SUN) && IS_MOVE_PHYSICAL(move))
MulModifier(&modifier, UQ_4_12(1.5));
break;
case ABILITY_HUSTLE:
Expand Down Expand Up @@ -9365,7 +9277,7 @@ static u32 CalcAttackStat(u16 move, u8 battlerAtk, u8 battlerDef, u8 moveType, b
switch (GetBattlerAbility(BATTLE_PARTNER(battlerAtk)))
{
case ABILITY_FLOWER_GIFT:
if (gBattleMons[BATTLE_PARTNER(battlerAtk)].species == SPECIES_CHERRIM && IsBattlerWeatherAffected(BATTLE_PARTNER(battlerAtk), B_WEATHER_SUN) && IS_MOVE_PHYSICAL(move))
if (gBattleMons[BATTLE_PARTNER(battlerAtk)].species == SPECIES_CHERRIM_SUNSHINE && IsBattlerWeatherAffected(BATTLE_PARTNER(battlerAtk), B_WEATHER_SUN) && IS_MOVE_PHYSICAL(move))
MulModifier(&modifier, UQ_4_12(1.5));
break;
}
Expand Down Expand Up @@ -9499,7 +9411,7 @@ static u32 CalcDefenseStat(u16 move, u8 battlerAtk, u8 battlerDef, u8 moveType,
}
break;
case ABILITY_FLOWER_GIFT:
if (gBattleMons[battlerDef].species == SPECIES_CHERRIM && IsBattlerWeatherAffected(battlerDef, B_WEATHER_SUN) && !usesDefStat)
if (gBattleMons[battlerDef].species == SPECIES_CHERRIM_SUNSHINE && IsBattlerWeatherAffected(battlerDef, B_WEATHER_SUN) && !usesDefStat)
MulModifier(&modifier, UQ_4_12(1.5));
break;
case ABILITY_PUNK_ROCK:
Expand All @@ -9518,7 +9430,7 @@ static u32 CalcDefenseStat(u16 move, u8 battlerAtk, u8 battlerDef, u8 moveType,
switch (GetBattlerAbility(BATTLE_PARTNER(battlerDef)))
{
case ABILITY_FLOWER_GIFT:
if (gBattleMons[BATTLE_PARTNER(battlerDef)].species == SPECIES_CHERRIM && IsBattlerWeatherAffected(BATTLE_PARTNER(battlerDef), B_WEATHER_SUN) && !usesDefStat)
if (gBattleMons[BATTLE_PARTNER(battlerDef)].species == SPECIES_CHERRIM_SUNSHINE && IsBattlerWeatherAffected(BATTLE_PARTNER(battlerDef), B_WEATHER_SUN) && !usesDefStat)
MulModifier(&modifier, UQ_4_12(1.5));
break;
}
Expand Down Expand Up @@ -10246,9 +10158,25 @@ u16 GetBattleFormChangeTargetSpecies(u8 battlerId, u16 method)
}
break;
case FORM_CHANGE_BATTLE_WEATHER:
if (gBattleWeather & formChanges[i].param1
// Check if there is a required ability and if the battler's ability does not match it
// or is suppressed. If so, revert to the no weather form.
if (formChanges[i].param2
&& GetBattlerAbility(battlerId) != formChanges[i].param2
&& formChanges[i].param1 == B_WEATHER_NONE)
{
targetSpecies = formChanges[i].targetSpecies;
}
// We need to revert the weather form if the field is under Air Lock, too.
else if (!WEATHER_HAS_EFFECT && formChanges[i].param1 == B_WEATHER_NONE)
{
targetSpecies = formChanges[i].targetSpecies;
}
// Otherwise, just check for a match between the weather and the form change table.
else if (gBattleWeather & formChanges[i].param1
|| (gBattleWeather == B_WEATHER_NONE && formChanges[i].param1 == B_WEATHER_NONE))
{
targetSpecies = formChanges[i].targetSpecies;
}
break;
case FORM_CHANGE_BATTLE_TURN_END:
if (formChanges[i].param1 == GetBattlerAbility(battlerId))
Expand Down
Loading