Skip to content

Commit

Permalink
Refactors argument into a union (#5853)
Browse files Browse the repository at this point in the history
Co-authored-by: Eduardo Quezada <[email protected]>
  • Loading branch information
AlexOn1ine and AsparagusEduardo authored Dec 23, 2024
1 parent caa35be commit 8edf144
Show file tree
Hide file tree
Showing 38 changed files with 271 additions and 260 deletions.
2 changes: 1 addition & 1 deletion include/battle_ai_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ bool32 HasOnlyMovesWithCategory(u32 battlerId, u32 category, bool32 onlyOffensiv
bool32 HasMoveWithCategory(u32 battler, u32 category);
bool32 HasMoveWithType(u32 battler, u32 type);
bool32 HasMoveEffect(u32 battlerId, u32 moveEffect);
bool32 HasMoveEffectANDArg(u32 battlerId, u32 effect, u32 argument);
bool32 IsPowerBasedOnStatus(u32 battlerId, u32 effect, u32 argument);
bool32 HasMoveWithAdditionalEffect(u32 battlerId, u32 moveEffect);
bool32 HasMoveWithCriticalHitChance(u32 battlerId);
bool32 HasMoveWithMoveEffectExcept(u32 battlerId, u32 moveEffect, u32 exception);
Expand Down
2 changes: 1 addition & 1 deletion include/battle_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ bool32 IsGen6ExpShareEnabled(void);
bool32 MoveHasAdditionalEffect(u32 move, u32 moveEffect);
bool32 MoveHasAdditionalEffectWithChance(u32 move, u32 moveEffect, u32 chance);
bool32 MoveHasAdditionalEffectSelf(u32 move, u32 moveEffect);
bool32 MoveHasAdditionalEffectSelfArg(u32 move, u32 moveEffect, u32 argument);
bool32 IsMoveEffectRemoveSpeciesType(u32 move, u32 moveEffect, u32 argument);
bool32 MoveHasChargeTurnAdditionalEffect(u32 move);
bool32 CanTargetPartner(u32 battlerAtk, u32 battlerDef);
bool32 TargetFullyImmuneToCurrMove(u32 battlerAtk, u32 battlerDef);
Expand Down
20 changes: 18 additions & 2 deletions include/pokemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,24 @@ struct MoveInfo
u8 powerOverride;
} zMove;

union {
struct {
u16 stringId;
u16 status;
} twoTurnAttack;
struct {
u16 side;
u16 property; // can be used to remove the hardcoded values
} protect;
u32 status;
u16 moveProperty;
u16 holdEffect;
u16 type;
u16 fixedDamage;
u16 absorbPercentage;
u16 maxEffect;
} argument;

s32 priority:4;
u32 recoil:7;
u32 strikeCount:4; // Max 15 hits. Defaults to 1 if not set. May apply its effect on each hit.
Expand Down Expand Up @@ -548,8 +566,6 @@ struct MoveInfo
u32 sketchBanned:1;
u32 padding:5; // end of word

u32 argument;

// primary/secondary effects
const struct AdditionalEffect *additionalEffects;

Expand Down
2 changes: 1 addition & 1 deletion src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4327,7 +4327,7 @@ static u32 AI_CalcMoveEffectScore(u32 battlerAtk, u32 battlerDef, u32 move)
ADJUST_SCORE(DECENT_EFFECT);
break;
case EFFECT_SOAK:
if (HasMoveWithType(battlerAtk, TYPE_ELECTRIC) || HasMoveWithType(battlerAtk, TYPE_GRASS) || (HasMoveEffect(battlerAtk, EFFECT_SUPER_EFFECTIVE_ON_ARG) && gMovesInfo[move].argument == TYPE_WATER) )
if (HasMoveWithType(battlerAtk, TYPE_ELECTRIC) || HasMoveWithType(battlerAtk, TYPE_GRASS) || (HasMoveEffect(battlerAtk, EFFECT_SUPER_EFFECTIVE_ON_ARG) && gMovesInfo[move].argument.type == TYPE_WATER) )
ADJUST_SCORE(DECENT_EFFECT); // Get some super effective moves
break;
case EFFECT_THIRD_TYPE:
Expand Down
30 changes: 15 additions & 15 deletions src/battle_ai_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,11 @@ bool32 IsDamageMoveUnusable(u32 battlerAtk, u32 battlerDef, u32 move, u32 moveTy
return TRUE;
break;
case EFFECT_FAIL_IF_NOT_ARG_TYPE:
if (!IS_BATTLER_OF_TYPE(battlerAtk, gMovesInfo[move].argument))
if (!IS_BATTLER_OF_TYPE(battlerAtk, gMovesInfo[move].argument.type))
return TRUE;
break;
case EFFECT_HIT_SET_REMOVE_TERRAIN:
if (!(gFieldStatuses & STATUS_FIELD_TERRAIN_ANY) && gMovesInfo[move].argument == ARG_TRY_REMOVE_TERRAIN_FAIL)
if (!(gFieldStatuses & STATUS_FIELD_TERRAIN_ANY) && gMovesInfo[move].argument.moveProperty == ARG_TRY_REMOVE_TERRAIN_FAIL)
return TRUE;
break;
case EFFECT_POLTERGEIST:
Expand Down Expand Up @@ -566,7 +566,7 @@ static inline void CalcDynamicMoveDamage(struct DamageCalculationData *damageCal
expected = minimum = gBattleMons[damageCalcData->battlerAtk].level * (abilityAtk == ABILITY_PARENTAL_BOND ? 2 : 1);
break;
case EFFECT_FIXED_DAMAGE_ARG:
expected = minimum = gMovesInfo[move].argument * (abilityAtk == ABILITY_PARENTAL_BOND ? 2 : 1);
expected = minimum = gMovesInfo[move].argument.fixedDamage * (abilityAtk == ABILITY_PARENTAL_BOND ? 2 : 1);
break;
case EFFECT_MULTI_HIT:
if (move == MOVE_WATER_SHURIKEN && gBattleMons[damageCalcData->battlerAtk].species == SPECIES_GRENINJA_ASH)
Expand Down Expand Up @@ -2027,7 +2027,7 @@ bool32 HasMoveEffect(u32 battlerId, u32 effect)
return FALSE;
}

bool32 HasMoveEffectANDArg(u32 battlerId, u32 effect, u32 argument)
bool32 IsPowerBasedOnStatus(u32 battlerId, u32 effect, u32 argument)
{
s32 i;
u16 *moves = GetMovesArray(battlerId);
Expand All @@ -2036,7 +2036,7 @@ bool32 HasMoveEffectANDArg(u32 battlerId, u32 effect, u32 argument)
{
if (moves[i] != MOVE_NONE && moves[i] != MOVE_UNAVAILABLE
&& gMovesInfo[moves[i]].effect == effect
&& (gMovesInfo[moves[i]].argument & argument))
&& (gMovesInfo[moves[i]].argument.status & argument))
return TRUE;
}

Expand Down Expand Up @@ -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.twoTurnAttack.status));
default:
return FALSE;
}
Expand Down Expand Up @@ -3229,7 +3229,7 @@ bool32 ShouldAbsorb(u32 battlerAtk, u32 battlerDef, u32 move, s32 damage)
if (move == 0xFFFF || AI_IsFaster(battlerAtk, battlerDef, move))
{
// using item or user goes first
u32 healPercent = (gMovesInfo[move].argument == 0) ? 50 : gMovesInfo[move].argument;
u32 healPercent = (gMovesInfo[move].argument.absorbPercentage == 0) ? 50 : gMovesInfo[move].argument.absorbPercentage;
s32 healDmg = (healPercent * damage) / 100;

if (gStatuses3[battlerAtk] & STATUS3_HEAL_BLOCK)
Expand Down Expand Up @@ -3847,7 +3847,7 @@ void IncreasePoisonScore(u32 battlerAtk, u32 battlerDef, u32 move, s32 *score)
if (AI_THINKING_STRUCT->aiFlags[battlerAtk] & AI_FLAG_STALL && HasMoveEffect(battlerAtk, EFFECT_PROTECT))
ADJUST_SCORE_PTR(WEAK_EFFECT); // stall tactic

if (HasMoveEffectANDArg(battlerAtk, EFFECT_DOUBLE_POWER_ON_ARG_STATUS, STATUS1_PSN_ANY)
if (IsPowerBasedOnStatus(battlerAtk, EFFECT_DOUBLE_POWER_ON_ARG_STATUS, STATUS1_PSN_ANY)
|| HasMoveEffect(battlerAtk, EFFECT_VENOM_DRENCH)
|| AI_DATA->abilities[battlerAtk] == ABILITY_MERCILESS)
ADJUST_SCORE_PTR(DECENT_EFFECT);
Expand All @@ -3874,8 +3874,8 @@ void IncreaseBurnScore(u32 battlerAtk, u32 battlerDef, u32 move, s32 *score)
ADJUST_SCORE_PTR(WEAK_EFFECT);
}

if (HasMoveEffectANDArg(battlerAtk, EFFECT_DOUBLE_POWER_ON_ARG_STATUS, STATUS1_BURN)
|| HasMoveEffectANDArg(BATTLE_PARTNER(battlerAtk), EFFECT_DOUBLE_POWER_ON_ARG_STATUS, STATUS1_BURN))
if (IsPowerBasedOnStatus(battlerAtk, EFFECT_DOUBLE_POWER_ON_ARG_STATUS, STATUS1_BURN)
|| IsPowerBasedOnStatus(BATTLE_PARTNER(battlerAtk), EFFECT_DOUBLE_POWER_ON_ARG_STATUS, STATUS1_BURN))
ADJUST_SCORE_PTR(WEAK_EFFECT);
}
}
Expand All @@ -3892,7 +3892,7 @@ void IncreaseParalyzeScore(u32 battlerAtk, u32 battlerDef, u32 move, s32 *score)
u32 defSpeed = AI_DATA->speedStats[battlerDef];

if ((defSpeed >= atkSpeed && defSpeed / 2 < atkSpeed) // You'll go first after paralyzing foe
|| HasMoveEffectANDArg(battlerAtk, EFFECT_DOUBLE_POWER_ON_ARG_STATUS, STATUS1_PARALYSIS)
|| IsPowerBasedOnStatus(battlerAtk, EFFECT_DOUBLE_POWER_ON_ARG_STATUS, STATUS1_PARALYSIS)
|| (HasMoveWithMoveEffectExcept(battlerAtk, MOVE_EFFECT_FLINCH, EFFECT_FIRST_TURN_ONLY)) // filter out Fake Out
|| gBattleMons[battlerDef].status2 & STATUS2_INFATUATION
|| gBattleMons[battlerDef].status2 & STATUS2_CONFUSION)
Expand All @@ -3917,8 +3917,8 @@ void IncreaseSleepScore(u32 battlerAtk, u32 battlerDef, u32 move, s32 *score)
&& !(HasMoveEffect(battlerDef, EFFECT_SNORE) || HasMoveEffect(battlerDef, EFFECT_SLEEP_TALK)))
ADJUST_SCORE_PTR(WEAK_EFFECT);

if (HasMoveEffectANDArg(battlerAtk, EFFECT_DOUBLE_POWER_ON_ARG_STATUS, STATUS1_SLEEP)
|| HasMoveEffectANDArg(BATTLE_PARTNER(battlerAtk), EFFECT_DOUBLE_POWER_ON_ARG_STATUS, STATUS1_SLEEP))
if (IsPowerBasedOnStatus(battlerAtk, EFFECT_DOUBLE_POWER_ON_ARG_STATUS, STATUS1_SLEEP)
|| IsPowerBasedOnStatus(BATTLE_PARTNER(battlerAtk), EFFECT_DOUBLE_POWER_ON_ARG_STATUS, STATUS1_SLEEP))
ADJUST_SCORE_PTR(WEAK_EFFECT);
}

Expand Down Expand Up @@ -3958,8 +3958,8 @@ void IncreaseFrostbiteScore(u32 battlerAtk, u32 battlerDef, u32 move, s32 *score
ADJUST_SCORE_PTR(WEAK_EFFECT);
}

if (HasMoveEffectANDArg(battlerAtk, EFFECT_DOUBLE_POWER_ON_ARG_STATUS, STATUS1_FROSTBITE)
|| HasMoveEffectANDArg(BATTLE_PARTNER(battlerAtk), EFFECT_DOUBLE_POWER_ON_ARG_STATUS, STATUS1_FROSTBITE))
if (IsPowerBasedOnStatus(battlerAtk, EFFECT_DOUBLE_POWER_ON_ARG_STATUS, STATUS1_FROSTBITE)
|| IsPowerBasedOnStatus(BATTLE_PARTNER(battlerAtk), EFFECT_DOUBLE_POWER_ON_ARG_STATUS, STATUS1_FROSTBITE))
ADJUST_SCORE_PTR(WEAK_EFFECT);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/battle_anim_new.c
Original file line number Diff line number Diff line change
Expand Up @@ -9244,7 +9244,7 @@ void AnimTask_DynamaxGrowth(u8 taskId) // from CFRU

void AnimTask_GetWeatherToSet(u8 taskId)
{
switch (gMovesInfo[gCurrentMove].argument)
switch (gMovesInfo[gCurrentMove].argument.maxEffect)
{
case MAX_EFFECT_SUN:
gBattleAnimArgs[ARG_RET_ID] = 1;
Expand Down
12 changes: 6 additions & 6 deletions src/battle_dynamax.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ u8 GetMaxMovePower(u32 move)
{
u8 tier;
// G-Max Drum Solo, G-Max Hydrosnipe, and G-Max Fireball always have 160 base power.
if (gMovesInfo[GetMaxMove(gBattlerAttacker, move)].argument == MAX_EFFECT_FIXED_POWER)
if (gMovesInfo[GetMaxMove(gBattlerAttacker, move)].argument.maxEffect == MAX_EFFECT_FIXED_POWER)
return 160;

// Exceptions to all other rules below:
Expand Down Expand Up @@ -470,7 +470,7 @@ void ChooseDamageNonTypesString(u8 type)
// Returns the status effect that should be applied by a G-Max Move.
static u32 GetMaxMoveStatusEffect(u32 move)
{
u8 maxEffect = gMovesInfo[move].argument;
u8 maxEffect = gMovesInfo[move].argument.maxEffect;
switch (maxEffect)
{
// Status 1
Expand Down Expand Up @@ -522,7 +522,7 @@ void BS_SetMaxMoveEffect(void)
{
NATIVE_ARGS();
u16 effect = 0;
u8 maxEffect = gMovesInfo[gCurrentMove].argument;
u8 maxEffect = gMovesInfo[gCurrentMove].argument.maxEffect;

// Don't continue if the move didn't land.
if (gBattleStruct->moveResultFlags[gBattlerTarget] & MOVE_RESULT_NO_EFFECT)
Expand All @@ -541,7 +541,7 @@ void BS_SetMaxMoveEffect(void)
if (!NoAliveMonsForEitherParty())
{
// Max Effects are ordered by stat ID.
SET_STATCHANGER(gMovesInfo[gCurrentMove].argument, 1, FALSE);
SET_STATCHANGER(gMovesInfo[gCurrentMove].argument.maxEffect, 1, FALSE);
BattleScriptPush(gBattlescriptCurrInstr + 1);
gBattlescriptCurrInstr = BattleScript_EffectRaiseStatAllies;
effect++;
Expand Down Expand Up @@ -569,7 +569,7 @@ void BS_SetMaxMoveEffect(void)
break;
default:
// Max Effects are ordered by stat ID.
statId = gMovesInfo[gCurrentMove].argument - MAX_EFFECT_LOWER_ATTACK + 1;
statId = gMovesInfo[gCurrentMove].argument.maxEffect - MAX_EFFECT_LOWER_ATTACK + 1;
break;
}
SET_STATCHANGER(statId, stage, TRUE);
Expand Down Expand Up @@ -618,7 +618,7 @@ void BS_SetMaxMoveEffect(void)
case MAX_EFFECT_PSYCHIC_TERRAIN:
{
u32 statusFlag = 0;
switch (gMovesInfo[gCurrentMove].argument)
switch (gMovesInfo[gCurrentMove].argument.moveProperty)
{
case MAX_EFFECT_MISTY_TERRAIN:
statusFlag = STATUS_FIELD_MISTY_TERRAIN;
Expand Down
2 changes: 1 addition & 1 deletion src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5957,7 +5957,7 @@ u32 GetDynamicMoveType(struct Pokemon *mon, u32 move, u32 battler, u8 *ateBoost)
}
break;
case EFFECT_CHANGE_TYPE_ON_ITEM:
if (holdEffect == gMovesInfo[move].argument)
if (holdEffect == gMovesInfo[move].argument.holdEffect)
return ItemId_GetSecondaryId(heldItem);
break;
case EFFECT_REVELATION_DANCE:
Expand Down
Loading

0 comments on commit 8edf144

Please sign in to comment.