Change GET_MOVE_TYPE to a function (#5090)
* Change GET_MOVE_TYPE to a function * add in battle check to GetMoveType function, move it to battle_util.c * Update src/battle_util.c Co-authored-by: Eduardo Quezada <eduardo602002@gmail.com> * Update src/battle_util.c --------- Co-authored-by: Eduardo Quezada <eduardo602002@gmail.com>
This commit is contained in:
parent
745db06dc8
commit
dbb9ee874b
9 changed files with 41 additions and 64 deletions
|
@ -811,13 +811,6 @@ STATIC_ASSERT(sizeof(((struct BattleStruct *)0)->palaceFlags) * 8 >= MAX_BATTLER
|
|||
#define F_DYNAMIC_TYPE_IGNORE_PHYSICALITY (1 << 6) // If set, the dynamic type's physicality won't be used for certain move effects.
|
||||
#define F_DYNAMIC_TYPE_SET (1 << 7) // Set for all dynamic types to distinguish a dynamic type of Normal (0) from no dynamic type.
|
||||
|
||||
#define GET_MOVE_TYPE(move, typeArg) do { \
|
||||
if (gBattleStruct->dynamicMoveType) \
|
||||
typeArg = gBattleStruct->dynamicMoveType & DYNAMIC_TYPE_MASK; \
|
||||
else \
|
||||
typeArg = gMovesInfo[move].type; \
|
||||
} while(0)
|
||||
|
||||
#define IS_MOVE_PHYSICAL(move)(GetBattleMoveCategory(move) == DAMAGE_CATEGORY_PHYSICAL)
|
||||
#define IS_MOVE_SPECIAL(move)(GetBattleMoveCategory(move) == DAMAGE_CATEGORY_SPECIAL)
|
||||
#define IS_MOVE_STATUS(move)(gMovesInfo[move].category == DAMAGE_CATEGORY_STATUS)
|
||||
|
|
|
@ -268,5 +268,6 @@ u8 GetBattlerType(u32 battler, u8 typeIndex, bool32 ignoreTera);
|
|||
bool8 CanMonParticipateInSkyBattle(struct Pokemon *mon);
|
||||
bool8 IsMonBannedFromSkyBattles(u16 species);
|
||||
void RemoveBattlerType(u32 battler, u8 type);
|
||||
u32 GetMoveType(u32 move);
|
||||
|
||||
#endif // GUARD_BATTLE_UTIL_H
|
||||
|
|
|
@ -826,7 +826,7 @@ static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
|
|||
return score;
|
||||
|
||||
SetTypeBeforeUsingMove(move, battlerAtk);
|
||||
GET_MOVE_TYPE(move, moveType);
|
||||
moveType = GetMoveType(move);
|
||||
|
||||
if (gMovesInfo[move].powderMove && !IsAffectedByPowder(battlerDef, aiData->abilities[battlerDef], aiData->holdEffects[battlerDef]))
|
||||
RETURN_SCORE_MINUS(10);
|
||||
|
@ -2749,7 +2749,7 @@ static s32 AI_DoubleBattle(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
|
|||
u32 predictedMove = aiData->predictedMoves[battlerDef];
|
||||
|
||||
SetTypeBeforeUsingMove(move, battlerAtk);
|
||||
GET_MOVE_TYPE(move, moveType);
|
||||
moveType = GetMoveType(move);
|
||||
|
||||
// check what effect partner is using
|
||||
if (aiData->partnerMove != 0)
|
||||
|
@ -5047,10 +5047,10 @@ static s32 AI_PreferBatonPass(u32 battlerAtk, u32 battlerDef, u32 move, s32 scor
|
|||
static s32 AI_HPAware(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
|
||||
{
|
||||
u32 effect = gMovesInfo[move].effect;
|
||||
u32 moveType = gMovesInfo[move].type;
|
||||
u32 moveType = 0;
|
||||
|
||||
SetTypeBeforeUsingMove(move, battlerAtk);
|
||||
GET_MOVE_TYPE(move, moveType);
|
||||
moveType = GetMoveType(move);
|
||||
|
||||
if (IS_TARGETING_PARTNER(battlerAtk, battlerDef))
|
||||
{
|
||||
|
|
|
@ -354,7 +354,7 @@ bool32 MovesWithCategoryUnusable(u32 attacker, u32 target, u32 category)
|
|||
&& !(unusable & gBitTable[i]))
|
||||
{
|
||||
SetTypeBeforeUsingMove(moves[i], attacker);
|
||||
GET_MOVE_TYPE(moves[i], moveType);
|
||||
moveType = GetMoveType(moves[i]);
|
||||
if (CalcTypeEffectivenessMultiplier(moves[i], moveType, attacker, target, AI_DATA->abilities[target], FALSE) != 0)
|
||||
usable |= gBitTable[i];
|
||||
}
|
||||
|
@ -400,10 +400,9 @@ static inline s32 DmgRoll(s32 dmg)
|
|||
|
||||
bool32 IsDamageMoveUnusable(u32 move, u32 battlerAtk, u32 battlerDef)
|
||||
{
|
||||
s32 moveType;
|
||||
struct AiLogicData *aiData = AI_DATA;
|
||||
u32 battlerDefAbility;
|
||||
GET_MOVE_TYPE(move, moveType);
|
||||
u32 moveType = GetMoveType(move);
|
||||
|
||||
if (DoesBattlerIgnoreAbilityChecks(aiData->abilities[battlerAtk], move))
|
||||
battlerDefAbility = ABILITY_NONE;
|
||||
|
@ -547,7 +546,7 @@ struct SimulatedDamage AI_CalcDamage(u32 move, u32 battlerAtk, u32 battlerDef, u
|
|||
gBattleStruct->dynamicMoveType = 0;
|
||||
|
||||
SetTypeBeforeUsingMove(move, battlerAtk);
|
||||
GET_MOVE_TYPE(move, moveType);
|
||||
moveType = GetMoveType(move);
|
||||
effectivenessMultiplier = CalcTypeEffectivenessMultiplier(move, moveType, battlerAtk, battlerDef, aiData->abilities[battlerDef], FALSE);
|
||||
|
||||
if (gMovesInfo[move].power)
|
||||
|
@ -993,7 +992,7 @@ uq4_12_t AI_GetTypeEffectiveness(u32 move, u32 battlerAtk, u32 battlerDef)
|
|||
|
||||
gBattleStruct->dynamicMoveType = 0;
|
||||
SetTypeBeforeUsingMove(move, battlerAtk);
|
||||
GET_MOVE_TYPE(move, moveType);
|
||||
moveType = GetMoveType(move);
|
||||
typeEffectiveness = CalcTypeEffectivenessMultiplier(move, moveType, battlerAtk, battlerDef, AI_DATA->abilities[battlerDef], FALSE);
|
||||
|
||||
RestoreBattlerData(battlerAtk);
|
||||
|
|
|
@ -798,7 +798,7 @@ static void Cmd_end(void)
|
|||
// Debugging - ensure no hanging mon bg tasks
|
||||
if (FuncIsActiveTask(Task_UpdateMonBg))
|
||||
DebugPrintf("Move %d animation still has Task_UpdateMonBg active at the end!", gAnimMoveIndex);
|
||||
|
||||
|
||||
m4aMPlayVolumeControl(&gMPlayInfo_BGM, TRACKS_ALL, 256);
|
||||
if (!IsContest())
|
||||
{
|
||||
|
@ -2145,12 +2145,9 @@ static void Cmd_stopsound(void)
|
|||
|
||||
static void Cmd_jumpifmovetypeequal(void)
|
||||
{
|
||||
u8 moveType;
|
||||
const u8 *type = sBattleAnimScriptPtr + 1;
|
||||
sBattleAnimScriptPtr += 2;
|
||||
GET_MOVE_TYPE(gCurrentMove, moveType);
|
||||
|
||||
if (*type != moveType)
|
||||
if (*type != GetMoveType(gCurrentMove))
|
||||
sBattleAnimScriptPtr += 4;
|
||||
else
|
||||
sBattleAnimScriptPtr = T2_READ_PTR(sBattleAnimScriptPtr);
|
||||
|
|
|
@ -5905,13 +5905,13 @@ void SetTypeBeforeUsingMove(u32 move, u32 battlerAtk)
|
|||
gBattleStruct->dynamicMoveType = TYPE_DARK | F_DYNAMIC_TYPE_SET;
|
||||
}
|
||||
|
||||
GET_MOVE_TYPE(move, moveType);
|
||||
moveType = GetMoveType(move);
|
||||
if ((gFieldStatuses & STATUS_FIELD_ION_DELUGE && moveType == TYPE_NORMAL)
|
||||
|| gStatuses4[battlerAtk] & STATUS4_ELECTRIFIED)
|
||||
gBattleStruct->dynamicMoveType = TYPE_ELECTRIC | F_DYNAMIC_TYPE_SET;
|
||||
|
||||
// Check if a gem should activate.
|
||||
GET_MOVE_TYPE(move, moveType);
|
||||
moveType = GetMoveType(move);
|
||||
if (holdEffect == HOLD_EFFECT_GEMS
|
||||
&& moveType == ItemId_GetSecondaryId(gBattleMons[battlerAtk].item))
|
||||
{
|
||||
|
|
|
@ -1193,9 +1193,9 @@ static void Cmd_attackcanceler(void)
|
|||
{
|
||||
CMD_ARGS();
|
||||
|
||||
s32 i, moveType;
|
||||
s32 i;
|
||||
u16 attackerAbility = GetBattlerAbility(gBattlerAttacker);
|
||||
GET_MOVE_TYPE(gCurrentMove, moveType);
|
||||
u32 moveType = GetMoveType(gCurrentMove);
|
||||
|
||||
// Weight-based moves are blocked by Dynamax.
|
||||
if ((GetActiveGimmick(gBattlerTarget) == GIMMICK_DYNAMAX) && IsMoveBlockedByDynamax(gCurrentMove))
|
||||
|
@ -1689,7 +1689,6 @@ u32 GetTotalAccuracy(u32 battlerAtk, u32 battlerDef, u32 move, u32 atkAbility, u
|
|||
|
||||
static void AccuracyCheck(bool32 recalcDragonDarts, const u8 *nextInstr, const u8 *failInstr, u16 move)
|
||||
{
|
||||
u32 type;
|
||||
u32 moveTarget = GetBattlerMoveTargetType(gBattlerAttacker, move);
|
||||
u32 abilityAtk = GetBattlerAbility(gBattlerAttacker);
|
||||
u32 abilityDef = GetBattlerAbility(gBattlerTarget);
|
||||
|
@ -1718,8 +1717,8 @@ static void AccuracyCheck(bool32 recalcDragonDarts, const u8 *nextInstr, const u
|
|||
else
|
||||
{
|
||||
u32 accuracy;
|
||||
u32 type = GetMoveType(move);
|
||||
|
||||
GET_MOVE_TYPE(move, type);
|
||||
if (JumpIfMoveAffectedByProtect(move))
|
||||
return;
|
||||
if (AccuracyCalcHelper(move))
|
||||
|
@ -1959,9 +1958,7 @@ static void Cmd_damagecalc(void)
|
|||
{
|
||||
CMD_ARGS();
|
||||
|
||||
u8 moveType;
|
||||
|
||||
GET_MOVE_TYPE(gCurrentMove, moveType);
|
||||
u32 moveType = GetMoveType(gCurrentMove);
|
||||
if (gMovesInfo[gCurrentMove].effect == EFFECT_SHELL_SIDE_ARM)
|
||||
gBattleStruct->swapDamageCategory = (gBattleStruct->shellSideArmCategory[gBattlerAttacker][gBattlerTarget] != gMovesInfo[gCurrentMove].category);
|
||||
gBattleMoveDamage = CalculateMoveDamage(gCurrentMove, gBattlerAttacker, gBattlerTarget, moveType, 0, gIsCriticalHit, TRUE, TRUE);
|
||||
|
@ -1972,9 +1969,7 @@ static void Cmd_typecalc(void)
|
|||
{
|
||||
CMD_ARGS();
|
||||
|
||||
u8 moveType;
|
||||
|
||||
GET_MOVE_TYPE(gCurrentMove, moveType);
|
||||
u32 moveType = GetMoveType(gCurrentMove);
|
||||
CalcTypeEffectivenessMultiplier(gCurrentMove, moveType, gBattlerAttacker, gBattlerTarget, GetBattlerAbility(gBattlerTarget), TRUE);
|
||||
|
||||
gBattlescriptCurrInstr = cmd->nextInstr;
|
||||
|
@ -1985,11 +1980,9 @@ static void Cmd_adjustdamage(void)
|
|||
CMD_ARGS();
|
||||
|
||||
u8 holdEffect, param;
|
||||
u32 moveType;
|
||||
u32 affectionScore = GetBattlerAffectionHearts(gBattlerTarget);
|
||||
u32 rand = Random() % 100;
|
||||
|
||||
GET_MOVE_TYPE(gCurrentMove, moveType);
|
||||
u32 moveType = GetMoveType(gCurrentMove);
|
||||
|
||||
if (DoesSubstituteBlockMove(gBattlerAttacker, gBattlerTarget, gCurrentMove))
|
||||
goto END;
|
||||
|
@ -2937,8 +2930,7 @@ void SetMoveEffect(bool32 primary, bool32 certain)
|
|||
|
||||
if (B_STATUS_TYPE_IMMUNITY == GEN_1)
|
||||
{
|
||||
u8 moveType = 0;
|
||||
GET_MOVE_TYPE(gCurrentMove, moveType);
|
||||
u32 moveType = GetMoveType(gCurrentMove);
|
||||
if (primary == FALSE && certain == FALSE && IS_BATTLER_OF_TYPE(gEffectBattler, moveType))
|
||||
break;
|
||||
}
|
||||
|
@ -2951,8 +2943,7 @@ void SetMoveEffect(bool32 primary, bool32 certain)
|
|||
case STATUS1_FREEZE:
|
||||
if (B_STATUS_TYPE_IMMUNITY == GEN_1)
|
||||
{
|
||||
u8 moveType = 0;
|
||||
GET_MOVE_TYPE(gCurrentMove, moveType);
|
||||
u32 moveType = GetMoveType(gCurrentMove);
|
||||
if (primary == FALSE && certain == FALSE && IS_BATTLER_OF_TYPE(gEffectBattler, moveType))
|
||||
break;
|
||||
}
|
||||
|
@ -2991,8 +2982,7 @@ void SetMoveEffect(bool32 primary, bool32 certain)
|
|||
}
|
||||
if (B_STATUS_TYPE_IMMUNITY == GEN_1)
|
||||
{
|
||||
u8 moveType = 0;
|
||||
GET_MOVE_TYPE(gCurrentMove, moveType);
|
||||
u32 moveType = GetMoveType(gCurrentMove);
|
||||
if (primary == FALSE && certain == FALSE && IS_BATTLER_OF_TYPE(gEffectBattler, moveType))
|
||||
break;
|
||||
}
|
||||
|
@ -3062,8 +3052,7 @@ void SetMoveEffect(bool32 primary, bool32 certain)
|
|||
case STATUS1_FROSTBITE:
|
||||
if (B_STATUS_TYPE_IMMUNITY == GEN_1)
|
||||
{
|
||||
u8 moveType = 0;
|
||||
GET_MOVE_TYPE(gCurrentMove, moveType);
|
||||
u32 moveType = GetMoveType(gCurrentMove);
|
||||
if (primary == FALSE && certain == FALSE && IS_BATTLER_OF_TYPE(gEffectBattler, moveType))
|
||||
break;
|
||||
}
|
||||
|
@ -5405,7 +5394,7 @@ static void Cmd_moveend(void)
|
|||
endState = cmd->endState;
|
||||
|
||||
holdEffectAtk = GetBattlerHoldEffect(gBattlerAttacker, TRUE);
|
||||
GET_MOVE_TYPE(gCurrentMove, moveType);
|
||||
moveType = GetMoveType(gCurrentMove);
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -5896,7 +5885,7 @@ static void Cmd_moveend(void)
|
|||
else
|
||||
{
|
||||
gLastLandedMoves[gBattlerTarget] = gCurrentMove;
|
||||
GET_MOVE_TYPE(gCurrentMove, gLastHitByType[gBattlerTarget]);
|
||||
gLastHitByType[gBattlerTarget] = GetMoveType(gCurrentMove);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -196,7 +196,7 @@ void HandleAction_UseMove(void)
|
|||
|
||||
// Set dynamic move type.
|
||||
SetTypeBeforeUsingMove(gChosenMove, gBattlerAttacker);
|
||||
GET_MOVE_TYPE(gChosenMove, moveType);
|
||||
moveType = GetMoveType(gCurrentMove);
|
||||
|
||||
// check Z-Move used
|
||||
if (GetActiveGimmick(gBattlerAttacker) == GIMMICK_Z_MOVE && !IS_MOVE_STATUS(gCurrentMove) && !IsZMove(gCurrentMove))
|
||||
|
@ -722,7 +722,8 @@ void HandleAction_ActionFinished(void)
|
|||
| HITMARKER_CHARGING | HITMARKER_NEVER_SET | HITMARKER_IGNORE_DISGUISE);
|
||||
|
||||
// check if Stellar type boost should be used up
|
||||
GET_MOVE_TYPE(gCurrentMove, moveType);
|
||||
moveType = GetMoveType(gCurrentMove);
|
||||
|
||||
if (GetActiveGimmick(gBattlerAttacker) == GIMMICK_TERA
|
||||
&& GetBattlerTeraType(gBattlerAttacker) == TYPE_STELLAR
|
||||
&& gMovesInfo[gCurrentMove].category != DAMAGE_CATEGORY_STATUS
|
||||
|
@ -4086,7 +4087,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32
|
|||
else
|
||||
move = gCurrentMove;
|
||||
|
||||
GET_MOVE_TYPE(move, moveType);
|
||||
moveType = GetMoveType(move);
|
||||
|
||||
switch (caseID)
|
||||
{
|
||||
|
@ -4459,7 +4460,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32
|
|||
for (j = 0; j < MAX_MON_MOVES; j++)
|
||||
{
|
||||
move = gBattleMons[i].moves[j];
|
||||
GET_MOVE_TYPE(move, moveType);
|
||||
moveType = GetMoveType(move);
|
||||
if (CalcTypeEffectivenessMultiplier(move, moveType, i, battler, ABILITY_ANTICIPATION, FALSE) >= UQ_4_12(2.0))
|
||||
{
|
||||
effect++;
|
||||
|
@ -7999,7 +8000,7 @@ u8 ItemBattleEffects(u8 caseID, u32 battler, bool32 moveTurn)
|
|||
case ITEMEFFECT_TARGET:
|
||||
if (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT))
|
||||
{
|
||||
GET_MOVE_TYPE(gCurrentMove, moveType);
|
||||
moveType = GetMoveType(gCurrentMove);
|
||||
switch (battlerHoldEffect)
|
||||
{
|
||||
case HOLD_EFFECT_AIR_BALLOON:
|
||||
|
@ -11074,7 +11075,6 @@ static u32 SwapMoveDamageCategory(u32 move)
|
|||
|
||||
u8 GetBattleMoveCategory(u32 moveId)
|
||||
{
|
||||
u8 moveType;
|
||||
if (gBattleStruct != NULL && gBattleStruct->swapDamageCategory) // Photon Geyser, Shell Side Arm, Light That Burns the Sky, Tera Blast
|
||||
return SwapMoveDamageCategory(moveId);
|
||||
if (gBattleStruct != NULL && (IsZMove(moveId) || IsMaxMove(moveId))) // TODO: Might be buggy depending on when this is called.
|
||||
|
@ -11084,11 +11084,7 @@ u8 GetBattleMoveCategory(u32 moveId)
|
|||
|
||||
if (IS_MOVE_STATUS(moveId))
|
||||
return DAMAGE_CATEGORY_STATUS;
|
||||
else if (gMain.inBattle)
|
||||
GET_MOVE_TYPE(moveId, moveType);
|
||||
else
|
||||
moveType = gMovesInfo[moveId].type;
|
||||
return gTypesInfo[moveType].damageCategory;
|
||||
return gTypesInfo[GetMoveType(gCurrentMove)].damageCategory;
|
||||
}
|
||||
|
||||
static bool32 TryRemoveScreens(u32 battler)
|
||||
|
@ -11805,11 +11801,15 @@ static inline bool32 DoesCurrentTargetHaveAbilityImmunity(void)
|
|||
|
||||
bool32 TargetFullyImmuneToCurrMove(u32 BattlerAtk, u32 battlerDef)
|
||||
{
|
||||
u32 moveType = 0;
|
||||
GET_MOVE_TYPE(gCurrentMove, moveType);
|
||||
|
||||
return ((CalcTypeEffectivenessMultiplier(gCurrentMove, moveType, BattlerAtk, battlerDef, GetBattlerAbility(battlerDef), FALSE) == UQ_4_12(0.0))
|
||||
return ((CalcTypeEffectivenessMultiplier(gCurrentMove, GetMoveType(gCurrentMove), BattlerAtk, battlerDef, GetBattlerAbility(battlerDef), FALSE) == UQ_4_12(0.0))
|
||||
|| IsBattlerProtected(BattlerAtk, battlerDef, gCurrentMove)
|
||||
|| IsSemiInvulnerable(battlerDef, gCurrentMove)
|
||||
|| DoesCurrentTargetHaveAbilityImmunity());
|
||||
}
|
||||
|
||||
u32 GetMoveType(u32 move)
|
||||
{
|
||||
if (gMain.inBattle && gBattleStruct->dynamicMoveType)
|
||||
return gBattleStruct->dynamicMoveType & DYNAMIC_TYPE_MASK;
|
||||
return gMovesInfo[move].type;
|
||||
}
|
||||
|
|
|
@ -415,9 +415,7 @@ static void ZMoveSelectionDisplayPpNumber(u32 battler)
|
|||
static void ZMoveSelectionDisplayMoveType(u16 zMove, u32 battler)
|
||||
{
|
||||
u8 *txtPtr, *end;
|
||||
u8 zMoveType;
|
||||
|
||||
GET_MOVE_TYPE(zMove, zMoveType);
|
||||
u32 zMoveType = GetMoveType(zMove);
|
||||
|
||||
txtPtr = StringCopy(gDisplayedStringBattle, gText_MoveInterfaceType);
|
||||
*(txtPtr)++ = EXT_CTRL_CODE_BEGIN;
|
||||
|
|
Loading…
Reference in a new issue