Skip to content

Commit

Permalink
Replace WEATHER_HAS_EFFECT with HasWeatherEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexOn1ine committed Jan 20, 2025
1 parent 27c8ec0 commit 880c8f0
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 40 deletions.
2 changes: 1 addition & 1 deletion include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ struct AiLogicData
u8 monToSwitchInId[MAX_BATTLERS_COUNT]; // ID of the mon to switch in.
u8 mostSuitableMonId[MAX_BATTLERS_COUNT]; // Stores result of GetMostSuitableMonToSwitchInto, which decides which generic mon the AI would switch into if they decide to switch. This can be overruled by specific mons found in ShouldSwitch; the final resulting mon is stored in AI_monToSwitchIntoId.
struct SwitchinCandidate switchinCandidate; // Struct used for deciding which mon to switch to in battle_ai_switch_items.c
u8 weatherHasEffect:1; // The same as WEATHER_HAS_EFFECT. Stored here, so it's called only once.
u8 weatherHasEffect:1; // The same as HasWeatherEffect(). Stored here, so it's called only once.
u8 ejectButtonSwitch:1; // Tracks whether current switch out was from Eject Button
u8 ejectPackSwitch:1; // Tracks whether current switch out was from Eject Pack
u8 predictingSwitch:1; // Determines whether AI will use predictions this turn or not
Expand Down
3 changes: 1 addition & 2 deletions include/battle_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ enum ItemEffect
ITEMEFFECT_STATS_CHANGED, // For White Herb and Eject Pack
};

#define WEATHER_HAS_EFFECT ((!IsAbilityOnField(ABILITY_CLOUD_NINE) && !IsAbilityOnField(ABILITY_AIR_LOCK)))

#define IS_WHOLE_SIDE_ALIVE(battler) ((IsBattlerAlive(battler) && IsBattlerAlive(BATTLE_PARTNER(battler))))
#define IS_ALIVE_AND_PRESENT(battler) (IsBattlerAlive(battler) && IsBattlerSpritePresent(battler))

Expand Down Expand Up @@ -343,5 +341,6 @@ u32 NumAffectedSpreadMoveTargets(void);
bool32 IsPursuitTargetSet(void);
void ClearPursuitValuesIfSet(u32 battler);
void ClearPursuitValues(void);
bool32 HasWeatherEffect(void);

#endif // GUARD_BATTLE_UTIL_H
6 changes: 3 additions & 3 deletions src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ void SetAiLogicDataForTurn(struct AiLogicData *aiData)
// Set delay timer to count how long it takes for AI to choose action/move
gBattleStruct->aiDelayTimer = gMain.vblankCounter1;

aiData->weatherHasEffect = WEATHER_HAS_EFFECT;
aiData->weatherHasEffect = HasWeatherEffect();
weather = AI_GetWeather(aiData);

// get/assume all battler data and simulate AI damage
Expand Down Expand Up @@ -794,7 +794,7 @@ void BattleAI_DoAIProcessing_PredictedSwitchin(struct AI_ThinkingStruct *aiThink
aiData->effectiveness[battlerAtk][battlerDef][aiThink->movesetIndex] = effectivenessSwitchin[aiThink->movesetIndex];
aiData->moveAccuracy[battlerAtk][battlerDef][aiThink->movesetIndex] = moveAccuracySwitchin[aiThink->movesetIndex];
}

else
{
if (aiThink->aiLogicId < ARRAY_COUNT(sBattleAiFuncTable)
Expand Down Expand Up @@ -824,7 +824,7 @@ void BattleAI_DoAIProcessing_PredictedSwitchin(struct AI_ThinkingStruct *aiThink
for (moveIndex = 0; moveIndex < MAX_MON_MOVES; moveIndex++)
{
aiData->simulatedDmg[battlerAtk][battlerDef][moveIndex] = simulatedDamageSwitchout[moveIndex];
aiData->effectiveness[battlerAtk][battlerDef][moveIndex] = effectivenessSwitchout[moveIndex];
aiData->effectiveness[battlerAtk][battlerDef][moveIndex] = effectivenessSwitchout[moveIndex];
aiData->moveAccuracy[battlerAtk][battlerDef][moveIndex] = moveAccuracySwitchout[moveIndex];
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/battle_ai_switch_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ static s32 GetSwitchinWeatherImpact(void)
s32 weatherImpact = 0, maxHP = AI_DATA->switchinCandidate.battleMon.maxHP, ability = AI_DATA->switchinCandidate.battleMon.ability;
u32 holdEffect = ItemId_GetHoldEffect(AI_DATA->switchinCandidate.battleMon.item);

if (WEATHER_HAS_EFFECT)
if (HasWeatherEffect())
{
// Damage
if (holdEffect != HOLD_EFFECT_SAFETY_GOGGLES && ability != ABILITY_MAGIC_GUARD && ability != ABILITY_OVERCOAT)
Expand Down
2 changes: 1 addition & 1 deletion src/battle_controllers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ void BtlController_EmitMoveAnimation(u32 battler, u32 bufferId, u16 move, u8 tur
gBattleResources->transferBuffer[9] = (dmg & 0xFF000000) >> 24;
gBattleResources->transferBuffer[10] = friendship;
gBattleResources->transferBuffer[11] = multihit;
if (WEATHER_HAS_EFFECT)
if (HasWeatherEffect())
{
gBattleResources->transferBuffer[12] = gBattleWeather;
gBattleResources->transferBuffer[13] = (gBattleWeather & 0xFF00) >> 8;
Expand Down
8 changes: 4 additions & 4 deletions src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4204,7 +4204,7 @@ enum
void SetupAISwitchingData(u32 battler, bool32 isAiRisky)
{
s32 opposingBattler = GetBattlerAtPosition(BATTLE_OPPOSITE(GetBattlerPosition(battler)));

// AI's predicting data
if ((AI_THINKING_STRUCT->aiFlags[battler] & AI_FLAG_PREDICT_SWITCH))
{
Expand Down Expand Up @@ -4785,7 +4785,7 @@ u32 GetBattlerTotalSpeedStatArgs(u32 battler, u32 ability, u32 holdEffect)
u32 speed = gBattleMons[battler].speed;

// weather abilities
if (WEATHER_HAS_EFFECT)
if (HasWeatherEffect())
{
if (ability == ABILITY_SWIFT_SWIM && holdEffect != HOLD_EFFECT_UTILITY_UMBRELLA && gBattleWeather & B_WEATHER_RAIN)
speed *= 2;
Expand All @@ -4804,7 +4804,7 @@ u32 GetBattlerTotalSpeedStatArgs(u32 battler, u32 ability, u32 holdEffect)
speed *= 2;
else if (ability == ABILITY_SLOW_START && gDisableStructs[battler].slowStartTimer != 0)
speed /= 2;
else if (ability == ABILITY_PROTOSYNTHESIS && !(gBattleMons[battler].status2 & STATUS2_TRANSFORMED) && ((gBattleWeather & B_WEATHER_SUN && WEATHER_HAS_EFFECT) || gDisableStructs[battler].boosterEnergyActivates))
else if (ability == ABILITY_PROTOSYNTHESIS && !(gBattleMons[battler].status2 & STATUS2_TRANSFORMED) && ((gBattleWeather & B_WEATHER_SUN && HasWeatherEffect()) || gDisableStructs[battler].boosterEnergyActivates))
speed = (GetHighestStatId(battler) == STAT_SPEED) ? (speed * 150) / 100 : speed;
else if (ability == ABILITY_QUARK_DRIVE && !(gBattleMons[battler].status2 & STATUS2_TRANSFORMED) && (gFieldStatuses & STATUS_FIELD_ELECTRIC_TERRAIN || gDisableStructs[battler].boosterEnergyActivates))
speed = (GetHighestStatId(battler) == STAT_SPEED) ? (speed * 150) / 100 : speed;
Expand Down Expand Up @@ -5911,7 +5911,7 @@ u32 GetDynamicMoveType(struct Pokemon *mon, u32 move, u32 battler, u8 *ateBoost)
switch (moveEffect)
{
case EFFECT_WEATHER_BALL:
if (gMain.inBattle && WEATHER_HAS_EFFECT)
if (gMain.inBattle && HasWeatherEffect())
{
if (gBattleWeather & B_WEATHER_RAIN && holdEffect != HOLD_EFFECT_UTILITY_UMBRELLA)
return TYPE_WATER;
Expand Down
18 changes: 9 additions & 9 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ static bool32 AccuracyCalcHelper(u32 move, u32 battler)
effect = TRUE;
}

if (WEATHER_HAS_EFFECT)
if (HasWeatherEffect())
{
if ((moveEffect == EFFECT_THUNDER || moveEffect == EFFECT_RAIN_ALWAYS_HIT)
&& IsBattlerWeatherAffected(battler, B_WEATHER_RAIN))
Expand Down Expand Up @@ -1539,11 +1539,11 @@ u32 GetTotalAccuracy(u32 battlerAtk, u32 battlerDef, u32 move, u32 atkAbility, u
switch (defAbility)
{
case ABILITY_SAND_VEIL:
if (WEATHER_HAS_EFFECT && gBattleWeather & B_WEATHER_SANDSTORM)
if (HasWeatherEffect() && gBattleWeather & B_WEATHER_SANDSTORM)
calc = (calc * 80) / 100; // 1.2 sand veil loss
break;
case ABILITY_SNOW_CLOAK:
if (WEATHER_HAS_EFFECT && (gBattleWeather & (B_WEATHER_HAIL | B_WEATHER_SNOW)))
if (HasWeatherEffect() && (gBattleWeather & (B_WEATHER_HAIL | B_WEATHER_SNOW)))
calc = (calc * 80) / 100; // 1.2 snow cloak loss
break;
case ABILITY_TANGLED_FEET:
Expand Down Expand Up @@ -1595,7 +1595,7 @@ u32 GetTotalAccuracy(u32 battlerAtk, u32 battlerDef, u32 move, u32 atkAbility, u
if (B_AFFECTION_MECHANICS == TRUE && GetBattlerAffectionHearts(battlerDef) == AFFECTION_FIVE_HEARTS)
calc = (calc * 90) / 100;

if (WEATHER_HAS_EFFECT && gBattleWeather & B_WEATHER_FOG)
if (HasWeatherEffect() && gBattleWeather & B_WEATHER_FOG)
calc = (calc * 60) / 100; // modified by 3/5

return calc;
Expand Down Expand Up @@ -2307,7 +2307,7 @@ static u32 UpdateEffectivenessResultFlagsForDoubleSpreadMoves(u32 resultFlags)

static inline bool32 TryStrongWindsWeakenAttack(u32 battlerDef, u32 moveType)
{
if (gBattleWeather & B_WEATHER_STRONG_WINDS && WEATHER_HAS_EFFECT)
if (gBattleWeather & B_WEATHER_STRONG_WINDS && HasWeatherEffect())
{
if (GetMoveCategory(gCurrentMove) != DAMAGE_CATEGORY_STATUS
&& IS_BATTLER_OF_TYPE(battlerDef, TYPE_FLYING)
Expand Down Expand Up @@ -7692,7 +7692,7 @@ bool32 DoSwitchInAbilities(u32 battler)
{
return (TryPrimalReversion(battler)
|| AbilityBattleEffects(ABILITYEFFECT_ON_SWITCHIN, battler, 0, 0, 0)
|| (gBattleWeather & B_WEATHER_ANY && WEATHER_HAS_EFFECT && AbilityBattleEffects(ABILITYEFFECT_ON_WEATHER, battler, 0, 0, 0))
|| (gBattleWeather & B_WEATHER_ANY && HasWeatherEffect() && AbilityBattleEffects(ABILITYEFFECT_ON_WEATHER, battler, 0, 0, 0))
|| (gFieldStatuses & STATUS_FIELD_TERRAIN_ANY && AbilityBattleEffects(ABILITYEFFECT_ON_TERRAIN, battler, 0, 0, 0)));
}

Expand Down Expand Up @@ -10721,7 +10721,7 @@ static void Cmd_various(void)
{
VARIOUS_ARGS();
if (gSideStatuses[GetBattlerSide(battler)] & SIDE_STATUS_AURORA_VEIL
|| !(WEATHER_HAS_EFFECT && gBattleWeather & (B_WEATHER_HAIL | B_WEATHER_SNOW)))
|| !(HasWeatherEffect() && gBattleWeather & (B_WEATHER_HAIL | B_WEATHER_SNOW)))
{
gBattleStruct->moveResultFlags[gBattlerTarget] |= MOVE_RESULT_MISSED;
gBattleCommunication[MULTISTRING_CHOOSER] = 0;
Expand Down Expand Up @@ -14161,14 +14161,14 @@ static void Cmd_recoverbasedonsunlight(void)
{
if (gCurrentMove == MOVE_SHORE_UP)
{
if (WEATHER_HAS_EFFECT && gBattleWeather & B_WEATHER_SANDSTORM)
if (HasWeatherEffect() && gBattleWeather & B_WEATHER_SANDSTORM)
gBattleStruct->moveDamage[gBattlerAttacker] = 20 * GetNonDynamaxMaxHP(gBattlerAttacker) / 30;
else
gBattleStruct->moveDamage[gBattlerAttacker] = GetNonDynamaxMaxHP(gBattlerAttacker) / 2;
}
else
{
if (!(gBattleWeather & B_WEATHER_ANY) || !WEATHER_HAS_EFFECT || GetBattlerHoldEffect(gBattlerAttacker, TRUE) == HOLD_EFFECT_UTILITY_UMBRELLA)
if (!(gBattleWeather & B_WEATHER_ANY) || !HasWeatherEffect() || GetBattlerHoldEffect(gBattlerAttacker, TRUE) == HOLD_EFFECT_UTILITY_UMBRELLA)
gBattleStruct->moveDamage[gBattlerAttacker] = GetNonDynamaxMaxHP(gBattlerAttacker) / 2;
else if (gBattleWeather & B_WEATHER_SUN)
gBattleStruct->moveDamage[gBattlerAttacker] = 20 * GetNonDynamaxMaxHP(gBattlerAttacker) / 30;
Expand Down
Loading

0 comments on commit 880c8f0

Please sign in to comment.