mirror of
https://github.com/rh-hideout/pokeemerald-expansion.git
synced 2026-09-13 04:56:13 -05:00
Replaced / Removed some battlerAbsent checks in favor of IsBattlerAlive
This commit is contained in:
@@ -804,7 +804,7 @@ void GiveBoxMonDefaultMove(struct BoxPokemon *boxMon, u32 slot);
|
||||
enum Move MonTryLearningNewMoveAtLevel(struct Pokemon *mon, bool32 firstMove, u32 level);
|
||||
enum Move MonTryLearningNewMove(struct Pokemon *mon, bool8 firstMove);
|
||||
void DeleteFirstMoveAndGiveMoveToMon(struct Pokemon *mon, enum Move move);
|
||||
u8 CountAliveMonsInBattle(u8 caseId, enum BattlerId battler);
|
||||
u32 CountAliveMonsInBattle(u8 caseId, enum BattlerId battler);
|
||||
u8 GetDefaultMoveTarget(enum BattlerId battler);
|
||||
u8 GetMonGender(struct Pokemon *mon);
|
||||
u8 GetBoxMonGender(struct BoxPokemon *boxMon);
|
||||
|
||||
@@ -2636,7 +2636,7 @@ u32 AI_SelectRevivalBlessingMon(enum BattlerId battler)
|
||||
if (IsDoubleBattle())
|
||||
{
|
||||
opposingBattler = BATTLE_OPPOSITE(battler);
|
||||
if (gAbsentBattlerFlags & (1u << opposingBattler))
|
||||
if (!IsBattlerAlive(opposingBattler))
|
||||
opposingBattler ^= BIT_FLANK;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -368,7 +368,7 @@ static void HandleInputChooseAction(enum BattlerId battler)
|
||||
{
|
||||
if (IsDoubleBattle()
|
||||
&& GetBattlerPosition(battler) == B_POSITION_PLAYER_RIGHT
|
||||
&& !(gAbsentBattlerFlags & (1u << GetBattlerAtPosition(B_POSITION_PLAYER_LEFT)))
|
||||
&& IsBattlerAlive(GetBattlerAtPosition(B_POSITION_PLAYER_LEFT))
|
||||
&& !(gBattleTypeFlags & BATTLE_TYPE_MULTI))
|
||||
{
|
||||
// Return item to bag if partner had selected one (if consumable).
|
||||
@@ -509,7 +509,7 @@ void HandleInputChooseTarget(enum BattlerId battler)
|
||||
break;
|
||||
}
|
||||
|
||||
if (gAbsentBattlerFlags & (1u << gMultiUsePlayerCursor)
|
||||
if (!IsBattlerAlive(gMultiUsePlayerCursor)
|
||||
|| !CanTargetBattler(battler, gMultiUsePlayerCursor, move)
|
||||
|| (moveTarget == TARGET_OPPONENT && IsOnPlayerSide(gMultiUsePlayerCursor)))
|
||||
validTarget = FALSE;
|
||||
@@ -566,7 +566,7 @@ void HandleInputChooseTarget(enum BattlerId battler)
|
||||
if (B_SHOW_EFFECTIVENESS)
|
||||
MoveSelectionDisplayMoveEffectiveness(CheckTypeEffectiveness(battler, gMultiUsePlayerCursor), battler);
|
||||
|
||||
if (gAbsentBattlerFlags & (1u << gMultiUsePlayerCursor)
|
||||
if (!IsBattlerAlive(gMultiUsePlayerCursor)
|
||||
|| !CanTargetBattler(battler, gMultiUsePlayerCursor, move)
|
||||
|| (moveTarget == TARGET_OPPONENT && IsOnPlayerSide(gMultiUsePlayerCursor)))
|
||||
i = 0;
|
||||
@@ -780,7 +780,7 @@ void HandleInputChooseMove(enum BattlerId battler)
|
||||
|
||||
if (moveTarget == TARGET_USER || moveTarget == TARGET_USER_OR_ALLY)
|
||||
gMultiUsePlayerCursor = battler;
|
||||
else if (gAbsentBattlerFlags & (1u << GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT)))
|
||||
else if (!IsBattlerAlive(GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT)))
|
||||
gMultiUsePlayerCursor = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT);
|
||||
else
|
||||
gMultiUsePlayerCursor = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT);
|
||||
|
||||
@@ -3078,10 +3078,6 @@ void FaintClearSetData(enum BattlerId battler)
|
||||
}
|
||||
}
|
||||
|
||||
gBattleMons[battler].types[0] = GetSpeciesType(gBattleMons[battler].species, 0);
|
||||
gBattleMons[battler].types[1] = GetSpeciesType(gBattleMons[battler].species, 1);
|
||||
gBattleMons[battler].types[2] = TYPE_MYSTERY;
|
||||
|
||||
Ai_UpdateFaintData(battler);
|
||||
TryBattleFormChange(battler, FORM_CHANGE_FAINT, GetBattlerAbility(battler));
|
||||
}
|
||||
@@ -3818,10 +3814,10 @@ static void HandleTurnActionSelectionState(void)
|
||||
gBattleStruct->monToSwitchIntoId[battler] = PARTY_SIZE;
|
||||
if (gBattleTypeFlags & BATTLE_TYPE_MULTI
|
||||
|| (position & BIT_FLANK) == B_FLANK_LEFT
|
||||
|| gAbsentBattlerFlags & 1u << GetBattlerAtPosition(BATTLE_PARTNER(position))
|
||||
|| !IsBattlerAlive(GetBattlerAtPosition(BATTLE_PARTNER(position)))
|
||||
|| gBattleCommunication[GetBattlerAtPosition(BATTLE_PARTNER(position))] == STATE_WAIT_ACTION_CONFIRMED)
|
||||
{
|
||||
if (gAbsentBattlerFlags & 1u << battler || gBattleStruct->battlerState[battler].commandingDondozo)
|
||||
if (!IsBattlerAlive(battler) || gBattleStruct->battlerState[battler].commandingDondozo)
|
||||
{
|
||||
gChosenActionByBattler[battler] = B_ACTION_NOTHING_FAINTED;
|
||||
if (!(gBattleTypeFlags & BATTLE_TYPE_MULTI))
|
||||
@@ -4234,7 +4230,7 @@ static void HandleTurnActionSelectionState(void)
|
||||
|
||||
if (((gBattleTypeFlags & BATTLE_TYPE_MULTI) || !IsDoubleBattle())
|
||||
|| (position & BIT_FLANK) != B_FLANK_LEFT
|
||||
|| gAbsentBattlerFlags & 1u << GetBattlerAtPosition(BATTLE_PARTNER(position)))
|
||||
|| !IsBattlerAlive(GetBattlerAtPosition(BATTLE_PARTNER(position))))
|
||||
{
|
||||
BtlController_EmitLinkStandbyMsg(battler, B_COMM_TO_CONTROLLER, LINK_STANDBY_MSG_STOP_BOUNCE, i);
|
||||
}
|
||||
|
||||
@@ -913,8 +913,7 @@ static enum CancelerResult CancelerSetTargets(struct BattleCalcValues *cv)
|
||||
if (IsDoubleBattle() && moveTarget == TARGET_RANDOM)
|
||||
{
|
||||
cv->battlerDef = SetRandomTarget(cv->battlerAtk);
|
||||
if (gAbsentBattlerFlags & (1u << cv->battlerAtk)
|
||||
&& !IsBattlerAlly(cv->battlerAtk, cv->battlerDef))
|
||||
if (!IsBattlerAlive(cv->battlerAtk) && !IsBattlerAlly(cv->battlerAtk, cv->battlerDef))
|
||||
{
|
||||
cv->battlerDef = GetPartnerBattler(cv->battlerDef);
|
||||
}
|
||||
|
||||
@@ -7191,7 +7191,7 @@ static void Cmd_updatestatusicon(void)
|
||||
{
|
||||
for (battler = gBattleControllerExecFlags; battler < gBattlersCount; battler++)
|
||||
{
|
||||
if (!(gAbsentBattlerFlags & (1u << battler)))
|
||||
if (IsBattlerAlive(battler))
|
||||
{
|
||||
BtlController_EmitStatusIconUpdate(battler, B_COMM_TO_CONTROLLER, gBattleMons[battler].status1);
|
||||
MarkBattlerForControllerExec(battler);
|
||||
@@ -7202,7 +7202,7 @@ static void Cmd_updatestatusicon(void)
|
||||
else if (cmd->battler == BS_ATTACKER_WITH_PARTNER)
|
||||
{
|
||||
battler = gBattlerAttacker;
|
||||
if (!(gAbsentBattlerFlags & (1u << battler)))
|
||||
if (IsBattlerAlive(battler))
|
||||
{
|
||||
BtlController_EmitStatusIconUpdate(battler, B_COMM_TO_CONTROLLER, gBattleMons[battler].status1);
|
||||
MarkBattlerForControllerExec(battler);
|
||||
@@ -7210,7 +7210,7 @@ static void Cmd_updatestatusicon(void)
|
||||
if ((IsDoubleBattle()))
|
||||
{
|
||||
battler = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerAttacker)));
|
||||
if (!(gAbsentBattlerFlags & (1u << battler)))
|
||||
if (IsBattlerAlive(battler))
|
||||
{
|
||||
BtlController_EmitStatusIconUpdate(battler, B_COMM_TO_CONTROLLER, gBattleMons[battler].status1);
|
||||
MarkBattlerForControllerExec(battler);
|
||||
@@ -7251,8 +7251,9 @@ static void Cmd_setfocusenergy(void)
|
||||
enum BattlerId battler = GetBattlerForBattleScript(cmd->battler);
|
||||
enum BattleMoveEffects effect = GetMoveEffect(gCurrentMove);
|
||||
|
||||
if ((effect == EFFECT_DRAGON_CHEER && (!(IsDoubleBattle()) || (gAbsentBattlerFlags & (1u << battler))))
|
||||
|| gBattleMons[battler].volatiles.dragonCheer || gBattleMons[battler].volatiles.focusEnergy)
|
||||
if ((effect == EFFECT_DRAGON_CHEER && (!IsDoubleBattle() || !IsBattlerAlive(battler)))
|
||||
|| gBattleMons[battler].volatiles.dragonCheer
|
||||
|| gBattleMons[battler].volatiles.focusEnergy)
|
||||
{
|
||||
gBattleStruct->moveResultFlags[gBattlerTarget] |= MOVE_RESULT_FAILED;
|
||||
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_FOCUS_ENERGY_FAILED;
|
||||
@@ -8139,7 +8140,7 @@ static void Cmd_recoverbasedonsunlight(void)
|
||||
{
|
||||
if (attackerWeather & B_WEATHER_SUN)
|
||||
{
|
||||
recoverAmount = 20 * GetNonDynamaxMaxHP(gBattlerAttacker) / 30;
|
||||
recoverAmount = 20 * GetNonDynamaxMaxHP(gBattlerAttacker) / 30;
|
||||
if (ability == ABILITY_MEGA_SOL && !(weather & B_WEATHER_SUN))
|
||||
isAffectedByMegaSol = TRUE;
|
||||
}
|
||||
|
||||
@@ -421,9 +421,8 @@ static bool32 IsUnnerveAbilityOnOpposingSide(enum BattlerId battler)
|
||||
void HandleAction_UseMove(void)
|
||||
{
|
||||
gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber];
|
||||
if (gAbsentBattlerFlags & 1u << gBattlerAttacker
|
||||
|| gBattleStruct->battlerState[gBattlerAttacker].commandingDondozo
|
||||
|| !IsBattlerAlive(gBattlerAttacker))
|
||||
if (!IsBattlerAlive(gBattlerAttacker)
|
||||
|| gBattleStruct->battlerState[gBattlerAttacker].commandingDondozo)
|
||||
{
|
||||
gCurrentActionFuncId = B_ACTION_FINISHED;
|
||||
return;
|
||||
@@ -545,8 +544,7 @@ void HandleAction_Switch(void)
|
||||
gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber];
|
||||
|
||||
// if switching to a mon that is already on field, cancel switch
|
||||
if (!(gAbsentBattlerFlags & (1u << BATTLE_PARTNER(gBattlerAttacker)))
|
||||
&& IsBattlerAlive(BATTLE_PARTNER(gBattlerAttacker))
|
||||
if (IsBattlerAlive(BATTLE_PARTNER(gBattlerAttacker))
|
||||
&& gBattlerPartyIndexes[BATTLE_PARTNER(gBattlerAttacker)] == gBattleStruct->monToSwitchIntoId[gBattlerAttacker]
|
||||
&& BattlersShareParty(gBattlerAttacker, BATTLE_PARTNER(gBattlerAttacker)))
|
||||
{
|
||||
@@ -6006,28 +6004,24 @@ bool32 BattlerHasCopyableChanges(enum BattlerId battler)
|
||||
|
||||
u32 GetMoveTargetCount(struct DamageContext *ctx)
|
||||
{
|
||||
enum BattlerId battlerAtk = ctx->battlerAtk;
|
||||
enum BattlerId battlerDef = ctx->battlerDef;
|
||||
enum Move move = ctx->move;
|
||||
|
||||
switch (GetBattlerMoveTargetType(battlerAtk, move))
|
||||
switch (GetBattlerMoveTargetType(ctx->battlerAtk, ctx->move))
|
||||
{
|
||||
case TARGET_BOTH:
|
||||
return !(gAbsentBattlerFlags & (1u << battlerDef))
|
||||
+ !(gAbsentBattlerFlags & (1u << BATTLE_PARTNER(battlerDef)));
|
||||
return IsBattlerAlive(ctx->battlerDef)
|
||||
+ IsBattlerAlive(BATTLE_PARTNER(ctx->battlerDef));
|
||||
case TARGET_FOES_AND_ALLY:
|
||||
return !(gAbsentBattlerFlags & (1u << battlerDef))
|
||||
+ !(gAbsentBattlerFlags & (1u << BATTLE_PARTNER(battlerDef)))
|
||||
+ !(gAbsentBattlerFlags & (1u << BATTLE_PARTNER(battlerAtk)));
|
||||
return IsBattlerAlive(ctx->battlerDef)
|
||||
+ IsBattlerAlive(BATTLE_PARTNER(ctx->battlerDef))
|
||||
+ IsBattlerAlive(BATTLE_PARTNER(ctx->battlerAtk));
|
||||
case TARGET_OPPONENTS_FIELD:
|
||||
return 1;
|
||||
case TARGET_DEPENDS:
|
||||
case TARGET_SELECTED:
|
||||
case TARGET_RANDOM:
|
||||
case TARGET_OPPONENT:
|
||||
return IsBattlerAlive(battlerDef);
|
||||
return IsBattlerAlive(ctx->battlerDef);
|
||||
case TARGET_USER:
|
||||
return IsBattlerAlive(battlerAtk);
|
||||
return IsBattlerAlive(ctx->battlerAtk);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1742,37 +1742,37 @@ void DeleteFirstMoveAndGiveMoveToMon(struct Pokemon *mon, enum Move move)
|
||||
SetMonData(mon, MON_DATA_PP_BONUSES, &ppBonuses);
|
||||
}
|
||||
|
||||
u8 CountAliveMonsInBattle(u8 caseId, enum BattlerId battler)
|
||||
u32 CountAliveMonsInBattle(u8 caseId, enum BattlerId battler)
|
||||
{
|
||||
enum BattlerId i;
|
||||
u32 retVal = 0;
|
||||
u32 aliveMonCount = 0;
|
||||
|
||||
switch (caseId)
|
||||
{
|
||||
case BATTLE_ALIVE_EXCEPT_BATTLER:
|
||||
for (i = 0; i < gBattlersCount; i++)
|
||||
{
|
||||
if (i != battler && !(gAbsentBattlerFlags & (1u << i)))
|
||||
retVal++;
|
||||
if (i != battler && IsBattlerAlive(i))
|
||||
aliveMonCount++;
|
||||
}
|
||||
break;
|
||||
case BATTLE_ALIVE_EXCEPT_BATTLER_SIDE:
|
||||
for (i = 0; i < gBattlersCount; i++)
|
||||
{
|
||||
if (i != battler && i != BATTLE_PARTNER(battler) && !(gAbsentBattlerFlags & (1u << i)))
|
||||
retVal++;
|
||||
if (i != battler && i != BATTLE_PARTNER(battler) && IsBattlerAlive(i))
|
||||
aliveMonCount++;
|
||||
}
|
||||
break;
|
||||
case BATTLE_ALIVE_SIDE:
|
||||
for (i = 0; i < gBattlersCount; i++)
|
||||
{
|
||||
if (IsBattlerAlly(i, battler) && !(gAbsentBattlerFlags & (1u << i)))
|
||||
retVal++;
|
||||
if (IsBattlerAlly(i, battler) && IsBattlerAlive(i))
|
||||
aliveMonCount++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
return aliveMonCount;
|
||||
}
|
||||
|
||||
u8 GetDefaultMoveTarget(enum BattlerId battlerId)
|
||||
@@ -1794,7 +1794,7 @@ u8 GetDefaultMoveTarget(enum BattlerId battlerId)
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((gAbsentBattlerFlags & (1u << opposing)))
|
||||
if (!IsBattlerAlive(opposing))
|
||||
return GetBattlerAtPosition(BATTLE_PARTNER(opposing));
|
||||
else
|
||||
return GetBattlerAtPosition(opposing);
|
||||
|
||||
@@ -149,7 +149,7 @@ AI_MULTI_BATTLE_TEST("Partner will not steal your pokemon when running out")
|
||||
TURN { EXPECT_MOVE(playerRight, MOVE_MEMENTO, target:opponentLeft); }
|
||||
TURN {}
|
||||
} THEN {
|
||||
EXPECT_EQ(gAbsentBattlerFlags, (1u << GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT)));
|
||||
EXPECT_EQ(!IsBattlerAlive(GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT)), TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user