quash pr clean up

This commit is contained in:
DizzyEggg 2022-08-24 23:39:34 +02:00
parent 06b4548603
commit 91b76e2e4f
3 changed files with 72 additions and 73 deletions

View file

@ -147,9 +147,9 @@ struct ProtectStruct
u16 pranksterElevated:1; u16 pranksterElevated:1;
u16 quickDraw:1; u16 quickDraw:1;
u16 beakBlastCharge:1; u16 beakBlastCharge:1;
u16 quash:1;
u32 physicalDmg; u32 physicalDmg;
u32 specialDmg; u32 specialDmg;
u8 quash : 1;
u8 physicalBattlerId; u8 physicalBattlerId;
u8 specialBattlerId; u8 specialBattlerId;
}; };
@ -670,7 +670,7 @@ struct BattleStruct
#define SET_STATCHANGER(statId, stage, goesDown)(gBattleScripting.statChanger = (statId) + ((stage) << 3) + (goesDown << 7)) #define SET_STATCHANGER(statId, stage, goesDown)(gBattleScripting.statChanger = (statId) + ((stage) << 3) + (goesDown << 7))
#define SET_STATCHANGER2(dst, statId, stage, goesDown)(dst = (statId) + ((stage) << 3) + (goesDown << 7)) #define SET_STATCHANGER2(dst, statId, stage, goesDown)(dst = (statId) + ((stage) << 3) + (goesDown << 7))
// NOTE: The members of this struct have hard-coded offsets // NOTE: The members of this struct have hard-coded offsets
// in include/constants/battle_script_commands.h // in include/constants/battle_script_commands.h
struct BattleScripting struct BattleScripting
{ {

View file

@ -2981,10 +2981,10 @@ static void BattleStartClearSetData(void)
gBattleStruct->arenaLostOpponentMons = 0; gBattleStruct->arenaLostOpponentMons = 0;
gBattleStruct->mega.triggerSpriteId = 0xFF; gBattleStruct->mega.triggerSpriteId = 0xFF;
gBattleStruct->stickyWebUser = 0xFF; gBattleStruct->stickyWebUser = 0xFF;
gBattleStruct->appearedInBattle = 0; gBattleStruct->appearedInBattle = 0;
for (i = 0; i < PARTY_SIZE; i++) for (i = 0; i < PARTY_SIZE; i++)
{ {
gBattleStruct->usedHeldItems[i][0] = 0; gBattleStruct->usedHeldItems[i][0] = 0;
@ -3084,7 +3084,7 @@ void SwitchInClearSetData(void)
gBattleStruct->lastTakenMoveFrom[gActiveBattler][3] = 0; gBattleStruct->lastTakenMoveFrom[gActiveBattler][3] = 0;
gBattleStruct->lastMoveFailed &= ~(gBitTable[gActiveBattler]); gBattleStruct->lastMoveFailed &= ~(gBitTable[gActiveBattler]);
gBattleStruct->palaceFlags &= ~(gBitTable[gActiveBattler]); gBattleStruct->palaceFlags &= ~(gBitTable[gActiveBattler]);
if (gActiveBattler == gBattleStruct->stickyWebUser) if (gActiveBattler == gBattleStruct->stickyWebUser)
gBattleStruct->stickyWebUser = 0xFF; // Switched into sticky web user slot so reset it gBattleStruct->stickyWebUser = 0xFF; // Switched into sticky web user slot so reset it
@ -3100,7 +3100,7 @@ void SwitchInClearSetData(void)
gBattleResources->flags->flags[gActiveBattler] = 0; gBattleResources->flags->flags[gActiveBattler] = 0;
gCurrentMove = MOVE_NONE; gCurrentMove = MOVE_NONE;
gBattleStruct->arenaTurnCounter = 0xFF; gBattleStruct->arenaTurnCounter = 0xFF;
// Reset damage to prevent things like red card activating if the switched-in mon is holding it // Reset damage to prevent things like red card activating if the switched-in mon is holding it
gSpecialStatuses[gActiveBattler].physicalDmg = 0; gSpecialStatuses[gActiveBattler].physicalDmg = 0;
gSpecialStatuses[gActiveBattler].specialDmg = 0; gSpecialStatuses[gActiveBattler].specialDmg = 0;
@ -3184,7 +3184,7 @@ void FaintClearSetData(void)
gBattleStruct->lastTakenMoveFrom[gActiveBattler][3] = 0; gBattleStruct->lastTakenMoveFrom[gActiveBattler][3] = 0;
gBattleStruct->palaceFlags &= ~(gBitTable[gActiveBattler]); gBattleStruct->palaceFlags &= ~(gBitTable[gActiveBattler]);
if (gActiveBattler == gBattleStruct->stickyWebUser) if (gActiveBattler == gBattleStruct->stickyWebUser)
gBattleStruct->stickyWebUser = 0xFF; // User of sticky web fainted, so reset the stored battler ID gBattleStruct->stickyWebUser = 0xFF; // User of sticky web fainted, so reset the stored battler ID
@ -3696,7 +3696,7 @@ static void TryDoEventsBeforeFirstTurn(void)
gMoveResultFlags = 0; gMoveResultFlags = 0;
gRandomTurnNumber = Random(); gRandomTurnNumber = Random();
GetAiLogicData(); // get assumed abilities, hold effects, etc of all battlers GetAiLogicData(); // get assumed abilities, hold effects, etc of all battlers
if (gBattleTypeFlags & BATTLE_TYPE_ARENA) if (gBattleTypeFlags & BATTLE_TYPE_ARENA)
@ -3904,7 +3904,7 @@ static void HandleTurnActionSelectionState(void)
case STATE_TURN_START_RECORD: // Recorded battle related action on start of every turn. case STATE_TURN_START_RECORD: // Recorded battle related action on start of every turn.
RecordedBattle_CopyBattlerMoves(); RecordedBattle_CopyBattlerMoves();
gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN; gBattleCommunication[gActiveBattler] = STATE_BEFORE_ACTION_CHOSEN;
// Do AI score computations here so we can use them in AI_TrySwitchOrUseItem // Do AI score computations here so we can use them in AI_TrySwitchOrUseItem
if ((gBattleTypeFlags & BATTLE_TYPE_HAS_AI || IsWildMonSmart()) && IsBattlerAIControlled(gActiveBattler)) { if ((gBattleTypeFlags & BATTLE_TYPE_HAS_AI || IsWildMonSmart()) && IsBattlerAIControlled(gActiveBattler)) {
gBattleStruct->aiMoveOrAction[gActiveBattler] = ComputeBattleAiScores(gActiveBattler); gBattleStruct->aiMoveOrAction[gActiveBattler] = ComputeBattleAiScores(gActiveBattler);
@ -4515,10 +4515,9 @@ s8 GetMovePriority(u32 battlerId, u16 move)
break; break;
} }
} }
if (gProtectStructs[battlerId].quash == 1)
{ if (gProtectStructs[battlerId].quash)
priority = -8; priority = -8;
}
return priority; return priority;
} }
@ -4568,7 +4567,7 @@ u8 GetWhoStrikesFirst(u8 battler1, u8 battler2, bool8 ignoreChosenMoves)
// QUICK CLAW / CUSTAP - always first // QUICK CLAW / CUSTAP - always first
// LAGGING TAIL - always last // LAGGING TAIL - always last
// STALL - always last // STALL - always last
if (gProtectStructs[battler1].quickDraw && !gProtectStructs[battler2].quickDraw) if (gProtectStructs[battler1].quickDraw && !gProtectStructs[battler2].quickDraw)
strikesFirst = 0; strikesFirst = 0;
else if (!gProtectStructs[battler1].quickDraw && gProtectStructs[battler2].quickDraw) else if (!gProtectStructs[battler1].quickDraw && gProtectStructs[battler2].quickDraw)
@ -4740,7 +4739,7 @@ static void TurnValuesCleanUp(bool8 var0)
gProtectStructs[gActiveBattler].spikyShielded = FALSE; gProtectStructs[gActiveBattler].spikyShielded = FALSE;
gProtectStructs[gActiveBattler].kingsShielded = FALSE; gProtectStructs[gActiveBattler].kingsShielded = FALSE;
gProtectStructs[gActiveBattler].banefulBunkered = FALSE; gProtectStructs[gActiveBattler].banefulBunkered = FALSE;
gProtectStructs[gBattlerTarget].quash = FALSE; gProtectStructs[gBattlerTarget].quash = FALSE;
} }
else else
{ {

View file

@ -1422,7 +1422,7 @@ static void Cmd_attackcanceler(void)
return; return;
if (AbilityBattleEffects(ABILITYEFFECT_MOVES_BLOCK, gBattlerTarget, 0, 0, 0)) if (AbilityBattleEffects(ABILITYEFFECT_MOVES_BLOCK, gBattlerTarget, 0, 0, 0))
return; return;
if (!gBattleMons[gBattlerAttacker].pp[gCurrMovePos] && gCurrentMove != MOVE_STRUGGLE if (!gBattleMons[gBattlerAttacker].pp[gCurrMovePos] && gCurrentMove != MOVE_STRUGGLE
&& !(gHitMarker & (HITMARKER_ALLOW_NO_PP | HITMARKER_NO_ATTACKSTRING | HITMARKER_NO_PPDEDUCT)) && !(gHitMarker & (HITMARKER_ALLOW_NO_PP | HITMARKER_NO_ATTACKSTRING | HITMARKER_NO_PPDEDUCT))
&& !(gBattleMons[gBattlerAttacker].status2 & STATUS2_MULTIPLETURNS)) && !(gBattleMons[gBattlerAttacker].status2 & STATUS2_MULTIPLETURNS))
{ {
@ -1622,7 +1622,7 @@ static bool32 AccuracyCalcHelper(u16 move)
RecordAbilityBattle(gBattlerTarget, ABILITY_NO_GUARD); RecordAbilityBattle(gBattlerTarget, ABILITY_NO_GUARD);
return TRUE; return TRUE;
} }
if (gBattleStruct->zmove.active && !(gStatuses3[gBattlerTarget] & STATUS3_SEMI_INVULNERABLE)) if (gBattleStruct->zmove.active && !(gStatuses3[gBattlerTarget] & STATUS3_SEMI_INVULNERABLE))
{ {
JumpIfMoveFailed(7, move); JumpIfMoveFailed(7, move);
@ -1765,7 +1765,7 @@ static void Cmd_accuracycheck(void)
gMoveResultFlags |= MOVE_RESULT_MISSED; gMoveResultFlags |= MOVE_RESULT_MISSED;
if (GetBattlerHoldEffect(gBattlerAttacker, TRUE) == HOLD_EFFECT_BLUNDER_POLICY) if (GetBattlerHoldEffect(gBattlerAttacker, TRUE) == HOLD_EFFECT_BLUNDER_POLICY)
gBattleStruct->blunderPolicy = TRUE; // Only activates from missing through acc/evasion checks gBattleStruct->blunderPolicy = TRUE; // Only activates from missing through acc/evasion checks
if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE &&
(moveTarget == MOVE_TARGET_BOTH || moveTarget == MOVE_TARGET_FOES_AND_ALLY)) (moveTarget == MOVE_TARGET_BOTH || moveTarget == MOVE_TARGET_FOES_AND_ALLY))
gBattleCommunication[MISS_TYPE] = B_MSG_AVOIDED_ATK; gBattleCommunication[MISS_TYPE] = B_MSG_AVOIDED_ATK;
@ -2596,14 +2596,14 @@ static void CheckSetUnburden(u8 battlerId)
// battlerStealer steals the item of battlerItem // battlerStealer steals the item of battlerItem
void StealTargetItem(u8 battlerStealer, u8 battlerItem) void StealTargetItem(u8 battlerStealer, u8 battlerItem)
{ {
gLastUsedItem = gBattleMons[battlerItem].item; gLastUsedItem = gBattleMons[battlerItem].item;
gBattleMons[battlerItem].item = 0; gBattleMons[battlerItem].item = 0;
RecordItemEffectBattle(battlerItem, 0); RecordItemEffectBattle(battlerItem, 0);
RecordItemEffectBattle(battlerStealer, ItemId_GetHoldEffect(gLastUsedItem)); RecordItemEffectBattle(battlerStealer, ItemId_GetHoldEffect(gLastUsedItem));
gBattleMons[battlerStealer].item = gLastUsedItem; gBattleMons[battlerStealer].item = gLastUsedItem;
CheckSetUnburden(battlerItem); CheckSetUnburden(battlerItem);
gBattleResources->flags->flags[battlerStealer] &= ~RESOURCE_FLAG_UNBURDEN; gBattleResources->flags->flags[battlerStealer] &= ~RESOURCE_FLAG_UNBURDEN;
@ -2614,9 +2614,9 @@ void StealTargetItem(u8 battlerStealer, u8 battlerItem)
gActiveBattler = battlerItem; gActiveBattler = battlerItem;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].item), &gBattleMons[battlerItem].item); // remove target item BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gBattlerTarget].item), &gBattleMons[battlerItem].item); // remove target item
MarkBattlerForControllerExec(battlerItem); MarkBattlerForControllerExec(battlerItem);
gBattleStruct->choicedMove[battlerItem] = 0; gBattleStruct->choicedMove[battlerItem] = 0;
TrySaveExchangedItem(battlerItem, gLastUsedItem); TrySaveExchangedItem(battlerItem, gLastUsedItem);
} }
@ -2640,7 +2640,7 @@ void SetMoveEffect(bool32 primary, u32 certain)
bool32 mirrorArmorReflected = (GetBattlerAbility(gBattlerTarget) == ABILITY_MIRROR_ARMOR); bool32 mirrorArmorReflected = (GetBattlerAbility(gBattlerTarget) == ABILITY_MIRROR_ARMOR);
u32 flags = 0; u32 flags = 0;
u16 battlerAbility; u16 battlerAbility;
switch (gBattleScripting.moveEffect) // Set move effects which happen later on switch (gBattleScripting.moveEffect) // Set move effects which happen later on
{ {
case MOVE_EFFECT_KNOCK_OFF: case MOVE_EFFECT_KNOCK_OFF:
@ -2749,7 +2749,7 @@ void SetMoveEffect(bool32 primary, u32 certain)
case STATUS1_BURN: case STATUS1_BURN:
if (gCurrentMove == MOVE_BURNING_JEALOUSY && !gProtectStructs[gEffectBattler].statRaised) if (gCurrentMove == MOVE_BURNING_JEALOUSY && !gProtectStructs[gEffectBattler].statRaised)
break; break;
if ((battlerAbility == ABILITY_WATER_VEIL || battlerAbility == ABILITY_WATER_BUBBLE) if ((battlerAbility == ABILITY_WATER_VEIL || battlerAbility == ABILITY_WATER_BUBBLE)
&& (primary == TRUE || certain == MOVE_EFFECT_CERTAIN)) && (primary == TRUE || certain == MOVE_EFFECT_CERTAIN))
{ {
@ -2944,7 +2944,7 @@ void SetMoveEffect(bool32 primary, u32 certain)
else else
{ {
gBattleMons[gEffectBattler].status2 |= STATUS2_CONFUSION_TURN(((Random()) % 4) + 2); // 2-5 turns gBattleMons[gEffectBattler].status2 |= STATUS2_CONFUSION_TURN(((Random()) % 4) + 2); // 2-5 turns
// If the confusion is activating due to being released from Sky Drop, go to "confused due to fatigue" script. // If the confusion is activating due to being released from Sky Drop, go to "confused due to fatigue" script.
// Otherwise, do normal confusion script. // Otherwise, do normal confusion script.
if(gCurrentMove == MOVE_SKY_DROP) if(gCurrentMove == MOVE_SKY_DROP)
@ -2956,7 +2956,7 @@ void SetMoveEffect(bool32 primary, u32 certain)
else else
{ {
BattleScriptPush(gBattlescriptCurrInstr + 1); BattleScriptPush(gBattlescriptCurrInstr + 1);
gBattlescriptCurrInstr = sMoveEffectBS_Ptrs[gBattleScripting.moveEffect]; gBattlescriptCurrInstr = sMoveEffectBS_Ptrs[gBattleScripting.moveEffect];
} }
} }
break; break;
@ -3091,7 +3091,7 @@ void SetMoveEffect(bool32 primary, u32 certain)
flags = affectsUser; flags = affectsUser;
if (mirrorArmorReflected && !affectsUser) if (mirrorArmorReflected && !affectsUser)
flags |= STAT_CHANGE_ALLOW_PTR; flags |= STAT_CHANGE_ALLOW_PTR;
if (ChangeStatBuffs(SET_STAT_BUFF_VALUE(1) | STAT_BUFF_NEGATIVE, if (ChangeStatBuffs(SET_STAT_BUFF_VALUE(1) | STAT_BUFF_NEGATIVE,
gBattleScripting.moveEffect - MOVE_EFFECT_ATK_MINUS_1 + 1, gBattleScripting.moveEffect - MOVE_EFFECT_ATK_MINUS_1 + 1,
flags | STAT_CHANGE_UPDATE_MOVE_EFFECT, gBattlescriptCurrInstr + 1)) flags | STAT_CHANGE_UPDATE_MOVE_EFFECT, gBattlescriptCurrInstr + 1))
@ -3482,14 +3482,14 @@ void SetMoveEffect(bool32 primary, u32 certain)
gBattleMons[gEffectBattler].item = 0; gBattleMons[gEffectBattler].item = 0;
CheckSetUnburden(gEffectBattler); CheckSetUnburden(gEffectBattler);
gActiveBattler = gEffectBattler; gActiveBattler = gEffectBattler;
BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gEffectBattler].item), &gBattleMons[gEffectBattler].item); BtlController_EmitSetMonData(BUFFER_A, REQUEST_HELDITEM_BATTLE, 0, sizeof(gBattleMons[gEffectBattler].item), &gBattleMons[gEffectBattler].item);
MarkBattlerForControllerExec(gActiveBattler); MarkBattlerForControllerExec(gActiveBattler);
// attacker temporarily gains their item // attacker temporarily gains their item
gBattleStruct->changedItems[gBattlerAttacker] = gBattleMons[gBattlerAttacker].item; gBattleStruct->changedItems[gBattlerAttacker] = gBattleMons[gBattlerAttacker].item;
gBattleMons[gBattlerAttacker].item = gLastUsedItem; gBattleMons[gBattlerAttacker].item = gLastUsedItem;
BattleScriptPush(gBattlescriptCurrInstr + 1); BattleScriptPush(gBattlescriptCurrInstr + 1);
gBattlescriptCurrInstr = BattleScript_MoveEffectBugBite; gBattlescriptCurrInstr = BattleScript_MoveEffectBugBite;
} }
@ -5257,13 +5257,13 @@ static void Cmd_moveend(void)
if (gBattleStruct->skyDropTargets[targetId] == i) if (gBattleStruct->skyDropTargets[targetId] == i)
break; break;
} }
// Set gBattlerAttacker to the battler id of the target // Set gBattlerAttacker to the battler id of the target
gBattlerAttacker = targetId; gBattlerAttacker = targetId;
// Jump to "confused due to fatigue" script // Jump to "confused due to fatigue" script
gBattlescriptCurrInstr = BattleScript_ThrashConfuses; gBattlescriptCurrInstr = BattleScript_ThrashConfuses;
// Clear skyDropTargets data // Clear skyDropTargets data
gBattleStruct->skyDropTargets[i] = 0xFF; gBattleStruct->skyDropTargets[i] = 0xFF;
gBattleStruct->skyDropTargets[targetId] = 0xFF; gBattleStruct->skyDropTargets[targetId] = 0xFF;
@ -5380,7 +5380,7 @@ static void Cmd_moveend(void)
if (!(gHitMarker & HITMARKER_UNABLE_TO_USE_MOVE) if (!(gHitMarker & HITMARKER_UNABLE_TO_USE_MOVE)
&& !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT)) && !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT))
gProtectStructs[gBattlerAttacker].targetAffected = TRUE; gProtectStructs[gBattlerAttacker].targetAffected = TRUE;
if (!(gHitMarker & HITMARKER_UNABLE_TO_USE_MOVE) if (!(gHitMarker & HITMARKER_UNABLE_TO_USE_MOVE)
&& gBattleTypeFlags & BATTLE_TYPE_DOUBLE && gBattleTypeFlags & BATTLE_TYPE_DOUBLE
&& !gProtectStructs[gBattlerAttacker].chargingTurn && !gProtectStructs[gBattlerAttacker].chargingTurn
@ -5482,7 +5482,7 @@ static void Cmd_moveend(void)
&& GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_RED_CARD && GetBattlerHoldEffect(battler, TRUE) == HOLD_EFFECT_RED_CARD
&& (gSpecialStatuses[battler].physicalDmg != 0 || gSpecialStatuses[battler].specialDmg != 0) && (gSpecialStatuses[battler].physicalDmg != 0 || gSpecialStatuses[battler].specialDmg != 0)
&& CanBattlerSwitch(gBattlerAttacker)) && CanBattlerSwitch(gBattlerAttacker))
{ {
gLastUsedItem = gBattleMons[battler].item; gLastUsedItem = gBattleMons[battler].item;
gActiveBattler = gBattleStruct->savedBattlerTarget = gBattleScripting.battler = battler; // Battler with red card gActiveBattler = gBattleStruct->savedBattlerTarget = gBattleScripting.battler = battler; // Battler with red card
gEffectBattler = gBattlerAttacker; gEffectBattler = gBattlerAttacker;
@ -5554,7 +5554,7 @@ static void Cmd_moveend(void)
// Battle scripting is super brittle so we shall do the item exchange now (if possible) // Battle scripting is super brittle so we shall do the item exchange now (if possible)
if (GetBattlerAbility(gBattlerAttacker) != ABILITY_STICKY_HOLD) if (GetBattlerAbility(gBattlerAttacker) != ABILITY_STICKY_HOLD)
StealTargetItem(gBattlerTarget, gBattlerAttacker); // Target takes attacker's item StealTargetItem(gBattlerTarget, gBattlerAttacker); // Target takes attacker's item
gEffectBattler = gBattlerAttacker; gEffectBattler = gBattlerAttacker;
BattleScriptPushCursor(); BattleScriptPushCursor();
gBattlescriptCurrInstr = BattleScript_Pickpocket; // Includes sticky hold check to print separate string gBattlescriptCurrInstr = BattleScript_Pickpocket; // Includes sticky hold check to print separate string
@ -7109,7 +7109,7 @@ static void Cmd_removeitem(void)
// Popped Air Balloon cannot be restored by any means. // Popped Air Balloon cannot be restored by any means.
if (GetBattlerHoldEffect(gActiveBattler, TRUE) != HOLD_EFFECT_AIR_BALLOON) if (GetBattlerHoldEffect(gActiveBattler, TRUE) != HOLD_EFFECT_AIR_BALLOON)
gBattleStruct->usedHeldItems[gBattlerPartyIndexes[gActiveBattler]][GetBattlerSide(gActiveBattler)] = itemId; // Remember if switched out gBattleStruct->usedHeldItems[gBattlerPartyIndexes[gActiveBattler]][GetBattlerSide(gActiveBattler)] = itemId; // Remember if switched out
gBattleMons[gActiveBattler].item = ITEM_NONE; gBattleMons[gActiveBattler].item = ITEM_NONE;
CheckSetUnburden(gActiveBattler); CheckSetUnburden(gActiveBattler);
@ -8103,7 +8103,7 @@ static void Cmd_various(void)
break; break;
case VARIOUS_ARENA_JUDGMENT_WINDOW: case VARIOUS_ARENA_JUDGMENT_WINDOW:
i = BattleArena_ShowJudgmentWindow(&gBattleCommunication[0]); i = BattleArena_ShowJudgmentWindow(&gBattleCommunication[0]);
// BattleArena_ShowJudgmentWindow's last state was an intermediate step. // BattleArena_ShowJudgmentWindow's last state was an intermediate step.
// Return without advancing the current instruction so that it will be called again. // Return without advancing the current instruction so that it will be called again.
if (i == ARENA_RESULT_RUNNING) if (i == ARENA_RESULT_RUNNING)
@ -8454,13 +8454,13 @@ static void Cmd_various(void)
} }
return; return;
case VARIOUS_TRY_QUASH: case VARIOUS_TRY_QUASH:
if (GetBattlerTurnOrderNum(gBattlerAttacker) > GetBattlerTurnOrderNum(gBattlerTarget)) // is true if foe is faster, has a bigger priority, or switches if (GetBattlerTurnOrderNum(gBattlerAttacker) > GetBattlerTurnOrderNum(gBattlerTarget)) // It's true if foe is faster, has a bigger priority, or switches
{ {
gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3); // This replaces the current battlescript with the "fail" script, if the condition gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3); // This replaces the current battlescript with the "fail" script.
} // we checked is true }
else // If the condition is not true, it means we are faster than the foe, so we can set the quash bit else // If the condition is not true, it means we are faster than the foe, so we can set the quash bit
{ {
gProtectStructs[gBattlerTarget].quash = 1; gProtectStructs[gBattlerTarget].quash = TRUE;
gBattlescriptCurrInstr += 7; // and then we proceed with the rest of our battlescript gBattlescriptCurrInstr += 7; // and then we proceed with the rest of our battlescript
} }
return; return;
@ -8554,7 +8554,7 @@ static void Cmd_various(void)
} }
return; return;
case VARIOUS_TRY_SOAK: case VARIOUS_TRY_SOAK:
if (gBattleMons[gBattlerTarget].type1 == gBattleMoves[gCurrentMove].type if (gBattleMons[gBattlerTarget].type1 == gBattleMoves[gCurrentMove].type
&& gBattleMons[gBattlerTarget].type2 == gBattleMoves[gCurrentMove].type) && gBattleMons[gBattlerTarget].type2 == gBattleMoves[gCurrentMove].type)
{ {
gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3); gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3);
@ -9082,7 +9082,7 @@ static void Cmd_various(void)
case VARIOUS_MAKE_INVISIBLE: case VARIOUS_MAKE_INVISIBLE:
if (gBattleControllerExecFlags) if (gBattleControllerExecFlags)
break; break;
BtlController_EmitSpriteInvisibility(BUFFER_A, TRUE); BtlController_EmitSpriteInvisibility(BUFFER_A, TRUE);
MarkBattlerForControllerExec(gActiveBattler); MarkBattlerForControllerExec(gActiveBattler);
break; break;
@ -9123,10 +9123,10 @@ static void Cmd_various(void)
BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + i, 0, sizeof(gBattleMons[gActiveBattler].pp[i]), &gBattleMons[gActiveBattler].pp[i]); BtlController_EmitSetMonData(BUFFER_A, REQUEST_PPMOVE1_BATTLE + i, 0, sizeof(gBattleMons[gActiveBattler].pp[i]), &gBattleMons[gActiveBattler].pp[i]);
MarkBattlerForControllerExec(gActiveBattler); MarkBattlerForControllerExec(gActiveBattler);
} }
if (gBattleMons[gActiveBattler].pp[i] == 0 && gBattleStruct->skyDropTargets[gActiveBattler] == 0xFF) if (gBattleMons[gActiveBattler].pp[i] == 0 && gBattleStruct->skyDropTargets[gActiveBattler] == 0xFF)
CancelMultiTurnMoves(gActiveBattler); CancelMultiTurnMoves(gActiveBattler);
gBattlescriptCurrInstr += 7; // continue gBattlescriptCurrInstr += 7; // continue
} }
else else
@ -9200,19 +9200,19 @@ static void Cmd_various(void)
return; return;
case VARIOUS_SET_SKY_DROP: case VARIOUS_SET_SKY_DROP:
gStatuses3[gBattlerTarget] |= (STATUS3_SKY_DROPPED | STATUS3_ON_AIR); gStatuses3[gBattlerTarget] |= (STATUS3_SKY_DROPPED | STATUS3_ON_AIR);
/* skyDropTargets holds the information of who is in a particular instance of Sky Drop. /* skyDropTargets holds the information of who is in a particular instance of Sky Drop.
This is needed in the case that multiple Pokemon use Sky Drop in the same turn or if This is needed in the case that multiple Pokemon use Sky Drop in the same turn or if
the target of a Sky Drop faints while in the air.*/ the target of a Sky Drop faints while in the air.*/
gBattleStruct->skyDropTargets[gBattlerAttacker] = gBattlerTarget; gBattleStruct->skyDropTargets[gBattlerAttacker] = gBattlerTarget;
gBattleStruct->skyDropTargets[gBattlerTarget] = gBattlerAttacker; gBattleStruct->skyDropTargets[gBattlerTarget] = gBattlerAttacker;
// End any multiturn effects caused by the target except STATUS2_LOCK_CONFUSE // End any multiturn effects caused by the target except STATUS2_LOCK_CONFUSE
gBattleMons[gBattlerTarget].status2 &= ~(STATUS2_MULTIPLETURNS); gBattleMons[gBattlerTarget].status2 &= ~(STATUS2_MULTIPLETURNS);
gBattleMons[gBattlerTarget].status2 &= ~(STATUS2_UPROAR); gBattleMons[gBattlerTarget].status2 &= ~(STATUS2_UPROAR);
gBattleMons[gBattlerTarget].status2 &= ~(STATUS2_BIDE); gBattleMons[gBattlerTarget].status2 &= ~(STATUS2_BIDE);
gDisableStructs[gBattlerTarget].rolloutTimer = 0; gDisableStructs[gBattlerTarget].rolloutTimer = 0;
gDisableStructs[gBattlerTarget].furyCutterCounter = 0; gDisableStructs[gBattlerTarget].furyCutterCounter = 0;
// End any Follow Me/Rage Powder effects caused by the target // End any Follow Me/Rage Powder effects caused by the target
if (gSideTimers[GetBattlerSide(gBattlerTarget)].followmeTimer != 0 && gSideTimers[GetBattlerSide(gBattlerTarget)].followmeTarget == gBattlerTarget) if (gSideTimers[GetBattlerSide(gBattlerTarget)].followmeTimer != 0 && gSideTimers[GetBattlerSide(gBattlerTarget)].followmeTarget == gBattlerTarget)
gSideTimers[GetBattlerSide(gBattlerTarget)].followmeTimer = 0; gSideTimers[GetBattlerSide(gBattlerTarget)].followmeTimer = 0;
@ -9225,12 +9225,12 @@ static void Cmd_various(void)
gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3); gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3);
else else
{ {
gBattleStruct->skyDropTargets[gBattlerAttacker] = 0xFF; gBattleStruct->skyDropTargets[gBattlerAttacker] = 0xFF;
gBattleStruct->skyDropTargets[gBattlerTarget] = 0xFF; gBattleStruct->skyDropTargets[gBattlerTarget] = 0xFF;
gStatuses3[gBattlerTarget] &= ~(STATUS3_SKY_DROPPED | STATUS3_ON_AIR); gStatuses3[gBattlerTarget] &= ~(STATUS3_SKY_DROPPED | STATUS3_ON_AIR);
gBattlescriptCurrInstr += 7; gBattlescriptCurrInstr += 7;
} }
// Confuse target if they were in the middle of Petal Dance/Outrage/Thrash when targeted. // Confuse target if they were in the middle of Petal Dance/Outrage/Thrash when targeted.
if (gBattleMons[gBattlerTarget].status2 & STATUS2_LOCK_CONFUSE) if (gBattleMons[gBattlerTarget].status2 & STATUS2_LOCK_CONFUSE)
gBattleScripting.moveEffect = (MOVE_EFFECT_CONFUSION | MOVE_EFFECT_CERTAIN); gBattleScripting.moveEffect = (MOVE_EFFECT_CONFUSION | MOVE_EFFECT_CERTAIN);
@ -9244,7 +9244,7 @@ static void Cmd_various(void)
// Clear skyDropTargets data // Clear skyDropTargets data
gBattleStruct->skyDropTargets[gBattleStruct->skyDropTargets[gEffectBattler]] = 0xFF; gBattleStruct->skyDropTargets[gBattleStruct->skyDropTargets[gEffectBattler]] = 0xFF;
gBattleStruct->skyDropTargets[gEffectBattler] = 0xFF; gBattleStruct->skyDropTargets[gEffectBattler] = 0xFF;
// If the target was in the middle of Outrage/Thrash/etc. when targeted by Sky Drop, confuse them on release and do proper animation // If the target was in the middle of Outrage/Thrash/etc. when targeted by Sky Drop, confuse them on release and do proper animation
if (gBattleMons[gEffectBattler].status2 & STATUS2_LOCK_CONFUSE && CanBeConfused(gEffectBattler)) if (gBattleMons[gEffectBattler].status2 & STATUS2_LOCK_CONFUSE && CanBeConfused(gEffectBattler))
{ {
@ -9317,7 +9317,7 @@ static void Cmd_various(void)
count++; count++;
} }
} }
if (count == 0) if (count == 0)
gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3); // Rototiller fails gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 3); // Rototiller fails
else else
@ -9354,19 +9354,19 @@ static void Cmd_various(void)
gBattlescriptCurrInstr += 4; gBattlescriptCurrInstr += 4;
return; return;
} }
gBattleScripting.battler = gEffectBattler = gBattlerTarget = gActiveBattler; // Cover all berry effect battlerId cases. e.g. ChangeStatBuffs uses target ID gBattleScripting.battler = gEffectBattler = gBattlerTarget = gActiveBattler; // Cover all berry effect battlerId cases. e.g. ChangeStatBuffs uses target ID
// Do move end berry effects for just a single battler, instead of looping through all battlers // Do move end berry effects for just a single battler, instead of looping through all battlers
if (ItemBattleEffects(ITEMEFFECT_BATTLER_MOVE_END, gActiveBattler, FALSE)) if (ItemBattleEffects(ITEMEFFECT_BATTLER_MOVE_END, gActiveBattler, FALSE))
return; return;
if (gBattlescriptCurrInstr[3]) if (gBattlescriptCurrInstr[3])
{ {
gBattleMons[gActiveBattler].item = gBattleStruct->changedItems[gActiveBattler]; gBattleMons[gActiveBattler].item = gBattleStruct->changedItems[gActiveBattler];
gBattleStruct->changedItems[gActiveBattler] = ITEM_NONE; gBattleStruct->changedItems[gActiveBattler] = ITEM_NONE;
gBattleResources->flags->flags[gActiveBattler] &= ~RESOURCE_FLAG_UNBURDEN; gBattleResources->flags->flags[gActiveBattler] &= ~RESOURCE_FLAG_UNBURDEN;
} }
gBattlescriptCurrInstr += 4; gBattlescriptCurrInstr += 4;
return; return;
case VARIOUS_JUMP_IF_CANT_REVERT_TO_PRIMAL: case VARIOUS_JUMP_IF_CANT_REVERT_TO_PRIMAL:
@ -9538,7 +9538,7 @@ static void Cmd_various(void)
return; return;
case VARIOUS_CAN_TAR_SHOT_WORK: case VARIOUS_CAN_TAR_SHOT_WORK:
// Tar Shot will fail if it's already been used on the target and its speed can't be lowered further // Tar Shot will fail if it's already been used on the target and its speed can't be lowered further
if (!gDisableStructs[gActiveBattler].tarShot if (!gDisableStructs[gActiveBattler].tarShot
&& CompareStat(gActiveBattler, STAT_SPEED, MAX_STAT_STAGE, CMP_LESS_THAN)) && CompareStat(gActiveBattler, STAT_SPEED, MAX_STAT_STAGE, CMP_LESS_THAN))
gBattlescriptCurrInstr += 7; gBattlescriptCurrInstr += 7;
else else
@ -9636,7 +9636,7 @@ static void Cmd_various(void)
case VARIOUS_BATTLER_ITEM_TO_LAST_USED_ITEM: case VARIOUS_BATTLER_ITEM_TO_LAST_USED_ITEM:
gBattleMons[gActiveBattler].item = gLastUsedItem; gBattleMons[gActiveBattler].item = gLastUsedItem;
break; break;
case VARIOUS_SET_BEAK_BLAST: case VARIOUS_SET_BEAK_BLAST:
gProtectStructs[gBattlerAttacker].beakBlastCharge = TRUE; gProtectStructs[gBattlerAttacker].beakBlastCharge = TRUE;
break; break;
case VARIOUS_SWAP_SIDE_STATUSES: case VARIOUS_SWAP_SIDE_STATUSES:
@ -10254,7 +10254,7 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
gActiveBattler = gBattlerAttacker; gActiveBattler = gBattlerAttacker;
else else
gActiveBattler = gBattlerTarget; gActiveBattler = gBattlerTarget;
activeBattlerAbility = GetBattlerAbility(gActiveBattler); activeBattlerAbility = GetBattlerAbility(gActiveBattler);
gSpecialStatuses[gActiveBattler].changedStatsBattlerId = gBattlerAttacker; gSpecialStatuses[gActiveBattler].changedStatsBattlerId = gBattlerAttacker;
@ -10418,7 +10418,7 @@ static u32 ChangeStatBuffs(s8 statValue, u32 statId, u32 flags, const u8 *BS_ptr
gBattleTextBuff2[index++] = STRINGID_STATFELL; gBattleTextBuff2[index++] = STRINGID_STATFELL;
gBattleTextBuff2[index++] = STRINGID_STATFELL >> 8; gBattleTextBuff2[index++] = STRINGID_STATFELL >> 8;
gBattleTextBuff2[index] = B_BUFF_EOS; gBattleTextBuff2[index] = B_BUFF_EOS;
if (gBattleMons[gActiveBattler].statStages[statId] == MIN_STAT_STAGE) if (gBattleMons[gActiveBattler].statStages[statId] == MIN_STAT_STAGE)
{ {
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STAT_WONT_DECREASE; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_STAT_WONT_DECREASE;
@ -10605,9 +10605,9 @@ static void Cmd_forcerandomswitch(void)
struct Pokemon *party = NULL; struct Pokemon *party = NULL;
s32 validMons = 0; s32 validMons = 0;
s32 minNeeded; s32 minNeeded;
bool32 redCardForcedSwitch = FALSE; bool32 redCardForcedSwitch = FALSE;
// Red card checks against wild pokemon. If we have reached here, the player has a mon to switch into // Red card checks against wild pokemon. If we have reached here, the player has a mon to switch into
// Red card swaps attacker with target to get the animation correct, so here we check attacker which is really the target. Thanks GF... // Red card swaps attacker with target to get the animation correct, so here we check attacker which is really the target. Thanks GF...
if (gBattleScripting.switchCase == B_SWITCH_RED_CARD if (gBattleScripting.switchCase == B_SWITCH_RED_CARD
@ -10650,7 +10650,7 @@ static void Cmd_forcerandomswitch(void)
&& GetBattlerSide(gBattlerTarget) == B_SIDE_PLAYER) && GetBattlerSide(gBattlerTarget) == B_SIDE_PLAYER)
|| redCardForcedSwitch || redCardForcedSwitch
) )
{ {
if (GetBattlerSide(gBattlerTarget) == B_SIDE_PLAYER) if (GetBattlerSide(gBattlerTarget) == B_SIDE_PLAYER)
party = gPlayerParty; party = gPlayerParty;
else else
@ -12175,7 +12175,7 @@ static void Cmd_maxattackhalvehp(void)
if (!(gBattleMons[gBattlerAttacker].maxHP / 2)) if (!(gBattleMons[gBattlerAttacker].maxHP / 2))
halfHp = 1; halfHp = 1;
// Belly Drum fails if the user's current HP is less than half its maximum, or if the user's Attack is already at +6 (even if the user has Contrary). // Belly Drum fails if the user's current HP is less than half its maximum, or if the user's Attack is already at +6 (even if the user has Contrary).
if (gBattleMons[gBattlerAttacker].statStages[STAT_ATK] < MAX_STAT_STAGE if (gBattleMons[gBattlerAttacker].statStages[STAT_ATK] < MAX_STAT_STAGE
&& gBattleMons[gBattlerAttacker].hp > halfHp) && gBattleMons[gBattlerAttacker].hp > halfHp)
@ -12671,7 +12671,7 @@ static void Cmd_tryswapitems(void)
gBattleMons[gBattlerAttacker].item = ITEM_NONE; gBattleMons[gBattlerAttacker].item = ITEM_NONE;
gBattleMons[gBattlerTarget].item = oldItemAtk; gBattleMons[gBattlerTarget].item = oldItemAtk;
RecordItemEffectBattle(gBattlerAttacker, 0); RecordItemEffectBattle(gBattlerAttacker, 0);
RecordItemEffectBattle(gBattlerTarget, ItemId_GetHoldEffect(oldItemAtk)); RecordItemEffectBattle(gBattlerTarget, ItemId_GetHoldEffect(oldItemAtk));
@ -12690,7 +12690,7 @@ static void Cmd_tryswapitems(void)
PREPARE_ITEM_BUFFER(gBattleTextBuff1, *newItemAtk) PREPARE_ITEM_BUFFER(gBattleTextBuff1, *newItemAtk)
PREPARE_ITEM_BUFFER(gBattleTextBuff2, oldItemAtk) PREPARE_ITEM_BUFFER(gBattleTextBuff2, oldItemAtk)
if (!(sideAttacker == sideTarget && IsPartnerMonFromSameTrainer(gBattlerAttacker))) if (!(sideAttacker == sideTarget && IsPartnerMonFromSameTrainer(gBattlerAttacker)))
{ {
// if targeting your own side and you aren't in a multi battle, don't save items as stolen // if targeting your own side and you aren't in a multi battle, don't save items as stolen
@ -12767,7 +12767,7 @@ static void Cmd_trywish(void)
#else #else
gBattleMoveDamage = max(1, gBattleMons[gBattlerTarget].maxHP / 2); gBattleMoveDamage = max(1, gBattleMons[gBattlerTarget].maxHP / 2);
#endif #endif
gBattleMoveDamage *= -1; gBattleMoveDamage *= -1;
if (gBattleMons[gBattlerTarget].hp == gBattleMons[gBattlerTarget].maxHP) if (gBattleMons[gBattlerTarget].hp == gBattleMons[gBattlerTarget].maxHP)
gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 2); gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 2);
@ -13163,7 +13163,7 @@ u16 GetSecretPowerMoveEffect(void)
} }
} }
else else
{ {
switch (gBattleTerrain) switch (gBattleTerrain)
{ {
case BATTLE_TERRAIN_GRASS: case BATTLE_TERRAIN_GRASS:
@ -13386,7 +13386,7 @@ static void Cmd_settypebasedhalvers(void)
gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_WEAKEN_ELECTRIC; gBattleCommunication[MULTISTRING_CHOOSER] = B_MSG_WEAKEN_ELECTRIC;
worked = TRUE; worked = TRUE;
} }
#else #else
if (!(gStatuses4[gBattlerAttacker] & STATUS4_MUD_SPORT)) if (!(gStatuses4[gBattlerAttacker] & STATUS4_MUD_SPORT))
{ {
gStatuses4[gBattlerAttacker] |= STATUS4_MUD_SPORT; gStatuses4[gBattlerAttacker] |= STATUS4_MUD_SPORT;
@ -13561,20 +13561,20 @@ static void Cmd_removelightscreenreflect(void)
{ {
u8 side; u8 side;
bool32 failed; bool32 failed;
#if B_BRICK_BREAK >= GEN_4 #if B_BRICK_BREAK >= GEN_4
// From Gen 4 onwards, Brick Break can remove screens on the user's side if used on an ally // From Gen 4 onwards, Brick Break can remove screens on the user's side if used on an ally
side = GetBattlerSide(gBattlerTarget); side = GetBattlerSide(gBattlerTarget);
#else #else
side = GetBattlerSide(gBattlerAttacker) ^ BIT_SIDE; side = GetBattlerSide(gBattlerAttacker) ^ BIT_SIDE;
#endif #endif
#if B_BRICK_BREAK >= GEN_5 #if B_BRICK_BREAK >= GEN_5
failed = (gMoveResultFlags & MOVE_RESULT_NO_EFFECT); failed = (gMoveResultFlags & MOVE_RESULT_NO_EFFECT);
#else #else
failed = FALSE; failed = FALSE;
#endif #endif
if (!failed if (!failed
&& (gSideTimers[side].reflectTimer && (gSideTimers[side].reflectTimer
|| gSideTimers[side].lightscreenTimer || gSideTimers[side].lightscreenTimer
@ -13633,7 +13633,7 @@ static void Cmd_handleballthrow(void)
{ {
u32 odds, i; u32 odds, i;
u8 catchRate; u8 catchRate;
gLastThrownBall = gLastUsedItem; gLastThrownBall = gLastUsedItem;
if (gBattleTypeFlags & BATTLE_TYPE_SAFARI) if (gBattleTypeFlags & BATTLE_TYPE_SAFARI)
catchRate = gBattleStruct->safariCatchFactor * 1275 / 100; catchRate = gBattleStruct->safariCatchFactor * 1275 / 100;