From 221cde6ef476594ea7bad9e415a01299270a6963 Mon Sep 17 00:00:00 2001 From: lhearachel Date: Sun, 29 Oct 2023 13:58:26 -0700 Subject: [PATCH 1/3] Document battle script commands 0x90 - 0xA6 --- include/battle/btlcmd.h | 31 +- include/battle/common.h | 1 + include/overlay016/ov16_0225177C.h | 11 +- src/overlay014/ov14_0221FC20.c | 2 +- src/overlay016/battle_script.c | 1348 +++++++++++++++++----------- src/overlay016/ov16_0225177C.c | 15 +- 6 files changed, 858 insertions(+), 550 deletions(-) diff --git a/include/battle/btlcmd.h b/include/battle/btlcmd.h index 25c8910828..f3bb701065 100644 --- a/include/battle/btlcmd.h +++ b/include/battle/btlcmd.h @@ -127,9 +127,9 @@ enum OpCode { VALOP_AND, }; -enum CheckAbilityOp { - CHECK_ABILITY_HAVE, - CHECK_ABILITY_NONE, +enum CheckHaveOp { + CHECK_HAVE, + CHECK_NOT_HAVE, }; enum StatusEffect { @@ -161,5 +161,30 @@ enum MessageStatusCondition { MSGCOND_INFATUATION, }; +enum TurnFlag { + TURN_FLAG_STRUGGLING = 0, + TURN_FLAG_PP_DECREMENTED, + TURN_FLAG_PROTECTING, + TURN_FLAG_HELPING_HAND, + TURN_FLAG_MAGIC_COAT, + TURN_FLAG_SNATCHING, + TURN_FLAG_ROOSTING, +}; + +enum CheckSideConditionOp { + CHECK_SIDE_COND_VAL_ZERO = 0, + CHECK_SIDE_COND_VAL_NOT_ZERO, + CHECK_SIDE_COND_CLEAR, +}; + +enum SideCondition { + SIDE_COND_REFLECT_TURNS = 0, + SIDE_COND_LIGHT_SCREEN_TURNS, + SIDE_COND_MIST_TURNS, + SIDE_COND_SAFEGUARD_TURNS, + SIDE_COND_SPIKES_LAYERS, + SIDE_COND_TOXIC_SPIKES_LAYERS, +}; + #endif // POKEPLATINUM_BATTLE_BTLCMD_H diff --git a/include/battle/common.h b/include/battle/common.h index 99528f35e8..75c011cf0b 100644 --- a/include/battle/common.h +++ b/include/battle/common.h @@ -7,6 +7,7 @@ #define ATTACKER_MOVE_SLOT (battleCtx->moveSlot[battleCtx->attacker]) #define ATTACKER_ACTION (battleCtx->battlerActions[battleCtx->attacker]) +#define DEFENDER_ACTION (battleCtx->battlerActions[battleCtx->defender]) #define ATTACKER_TURN_FLAGS (battleCtx->turnFlags[battleCtx->attacker]) #define DEFENDER_TURN_FLAGS (battleCtx->turnFlags[battleCtx->defender]) diff --git a/include/overlay016/ov16_0225177C.h b/include/overlay016/ov16_0225177C.h index 19a53f1472..405e57bb2f 100644 --- a/include/overlay016/ov16_0225177C.h +++ b/include/overlay016/ov16_0225177C.h @@ -469,7 +469,16 @@ void BattleSystem_SortMonsBySpeed(BattleSystem * param0, BattleContext * param1) BOOL BattleSystem_FailsInHighGravity(BattleSystem * param0, BattleContext * param1, int param2, int param3); BOOL BattleSystem_HealBlocked(BattleSystem * param0, BattleContext * param1, int param2, int param3); void BattleSystem_UpdateLastResort(BattleSystem * param0, BattleContext * param1); -int ov16_02256128(BattleSystem * param0, BattleContext * param1, int param2); + +/** + * @brief Count the number of moves known by a battler. + * + * @param battleSys + * @param battleCtx + * @param battler + * @return The number of moves known. + */ +int Battler_CountMoves(BattleSystem *battleSys, BattleContext *battleCtx, int battler); int BattleSystem_CheckImmunityAbilities(BattleContext * param0, int param1, int param2); BOOL BattleSystem_TriggerTurnEndAbility(BattleSystem * param0, BattleContext * param1, int param2); diff --git a/src/overlay014/ov14_0221FC20.c b/src/overlay014/ov14_0221FC20.c index a563d63e3d..1fcd1f031f 100644 --- a/src/overlay014/ov14_0221FC20.c +++ b/src/overlay014/ov14_0221FC20.c @@ -2307,7 +2307,7 @@ static void ov14_02221F1C (BattleSystem * param0, BattleContext * param1) v1 = ov14_02222CF0(param1); v2 = ov14_02222CF0(param1); v0 = ov14_02222D34(param1, v1); - v3 = ov16_02256128(param0, param1, v0); + v3 = Battler_CountMoves(param0, param1, v0); if ((param1->battleMons[v0].moveEffectsData.lastResortCount >= (v3 - 1)) && (v3 > 1)) { ov14_02222D24(param1, v2); diff --git a/src/overlay016/battle_script.c b/src/overlay016/battle_script.c index aa729af075..2410926456 100644 --- a/src/overlay016/battle_script.c +++ b/src/overlay016/battle_script.c @@ -248,29 +248,29 @@ static BOOL BtlCmd_CalcWeightBasedPower(BattleSystem *battleSys, BattleContext * static BOOL BtlCmd_CalcWeatherBallPower(BattleSystem *battleSys, BattleContext *battleCtx); static BOOL BtlCmd_CheckForPursuit(BattleSystem *battleSys, BattleContext *battleCtx); static BOOL BtlCmd_ApplyTypeMatchup(BattleSystem *battleSys, BattleContext *battleCtx); -static BOOL ov16_02246BB0(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02246CB4(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02246DAC(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02246DF0(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02246EE4(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02246F2C(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02246F70(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02246FA8(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247064(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_022470C0(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247118(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247194(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247378(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_022473A8(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_022473F4(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247440(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_022474C4(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247570(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247698(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_022476F8(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_0224787C(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_022478A4(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_022478E4(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_IfTurnFlag(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_SetTurnFlag(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_CalcGyroBallPower(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_TryMetalBurst(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_CalcPaybackPower(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_CalcTrumpCardPower(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_CalcWringOutPower(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_TryMeFirst(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_TryCopycat(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_CalcPunishmentPower(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_TrySuckerPunch(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_CheckSideCondition(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_CheckDefenderProtecting(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_CheckCanShareStatus(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_TryLastResort(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_TryToxicSpikes(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_CheckToxicSpikes(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_CheckIgnorableAbility(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_IfSameSide(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_GenerateEndOfBattleItem(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_SetTrickRoom(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_IfMovedThisTurn(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_IfItemEffect(BattleSystem * param0, BattleContext * param1); static BOOL ov16_02247950(BattleSystem * param0, BattleContext * param1); static BOOL ov16_0224799C(BattleSystem * param0, BattleContext * param1); static BOOL ov16_022479E8(BattleSystem * param0, BattleContext * param1); @@ -508,29 +508,29 @@ static const BtlCmd sBattleCommands[] = { BtlCmd_CalcWeatherBallPower, BtlCmd_CheckForPursuit, BtlCmd_ApplyTypeMatchup, - ov16_02246BB0, - ov16_02246CB4, - ov16_02246DAC, - ov16_02246DF0, - ov16_02246EE4, - ov16_02246F2C, - ov16_02246F70, - ov16_02246FA8, - ov16_02247064, - ov16_022470C0, - ov16_02247118, - ov16_02247194, - ov16_02247378, - ov16_022473A8, - ov16_022473F4, - ov16_02247440, - ov16_022474C4, - ov16_02247570, - ov16_02247698, - ov16_022476F8, - ov16_0224787C, - ov16_022478A4, - ov16_022478E4, + BtlCmd_IfTurnFlag, + BtlCmd_SetTurnFlag, + BtlCmd_CalcGyroBallPower, + BtlCmd_TryMetalBurst, + BtlCmd_CalcPaybackPower, + BtlCmd_CalcTrumpCardPower, + BtlCmd_CalcWringOutPower, + BtlCmd_TryMeFirst, + BtlCmd_TryCopycat, + BtlCmd_CalcPunishmentPower, + BtlCmd_TrySuckerPunch, + BtlCmd_CheckSideCondition, + BtlCmd_CheckDefenderProtecting, + BtlCmd_CheckCanShareStatus, + BtlCmd_TryLastResort, + BtlCmd_TryToxicSpikes, + BtlCmd_CheckToxicSpikes, + BtlCmd_CheckIgnorableAbility, + BtlCmd_IfSameSide, + BtlCmd_GenerateEndOfBattleItem, + BtlCmd_SetTrickRoom, + BtlCmd_IfMovedThisTurn, + BtlCmd_IfItemEffect, ov16_02247950, ov16_0224799C, ov16_022479E8, @@ -2354,7 +2354,7 @@ static BOOL BtlCmd_JumpToMove(BattleSystem *battleSys, BattleContext *battleCtx) if (targetIsSet == FALSE) { battleCtx->defender = BattleSystem_Defender(battleSys, battleCtx, battleCtx->attacker, battleCtx->msgMoveTemp, TRUE, 0); BattleSystem_RedirectTarget(battleSys, battleCtx, battleCtx->attacker, battleCtx->msgMoveTemp); - battleCtx->battlerActions[battleCtx->attacker][BATTLE_ACTION_CHOOSE_TARGET] = battleCtx->defender; + ATTACKER_ACTION[BATTLE_ACTION_CHOOSE_TARGET] = battleCtx->defender; } if (battleCtx->defender == BATTLER_NONE) { @@ -3350,7 +3350,7 @@ static BOOL BtlCmd_ToggleVanish(BattleSystem *battleSys, BattleContext *battleCt * @brief Check the ability of a battler or set of battlers. * * Inputs: - * 1. Op-code which controls the behavior. See enum CheckAbilityOp + * 1. Op-code which controls the behavior. See enum CheckHaveOp * 2. Input battler (or set of battlers) whose ability should be checked * 3. The ability to check for any battler to have (or not have) * 4. Jump distance if a battler in the input set meets the criteria @@ -3377,7 +3377,7 @@ static BOOL BtlCmd_CheckAbility(BattleSystem *battleSys, BattleContext *battleCt int maxBattlers = BattleSystem_MaxBattlers(battleSys); for (battler = 0; battler < maxBattlers; battler++) { - if (op == CHECK_ABILITY_HAVE) { + if (op == CHECK_HAVE) { if (Battler_Ability(battleCtx, battler) == ability) { BattleScript_Iter(battleCtx, jump); battleCtx->abilityMon = battler; @@ -3390,7 +3390,7 @@ static BOOL BtlCmd_CheckAbility(BattleSystem *battleSys, BattleContext *battleCt } else { battler = BattleScript_Battler(battleSys, battleCtx, inBattler); - if (op == CHECK_ABILITY_HAVE) { + if (op == CHECK_HAVE) { if (Battler_Ability(battleCtx, battler) == ability) { BattleScript_Iter(battleCtx, jump); battleCtx->abilityMon = battler; @@ -3736,7 +3736,7 @@ static BOOL BtlCmd_SetMirrorMove(BattleSystem *battleSys, BattleContext *battleC battleCtx->commandNext = BATTLE_CONTROL_UPDATE_MOVE_BUFFERS; BattleScript_Jump(battleCtx, NARC_INDEX_BATTLE__SKILL__SUB_SEQ, BATTLE_SUBSEQ_NO_TARGET); } else { - battleCtx->battlerActions[battleCtx->attacker][1] = battleCtx->defender; + ATTACKER_ACTION[BATTLE_ACTION_CHOOSE_TARGET] = battleCtx->defender; BattleScript_Jump(battleCtx, NARC_INDEX_BATTLE__SKILL__WAZA_SEQ, move); } } else { @@ -7319,740 +7319,1014 @@ static BOOL BtlCmd_ApplyTypeMatchup(BattleSystem *battleSys, BattleContext *batt return FALSE; } -static BOOL ov16_02246BB0 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Checks if the value in a given turn flag matches a static input value. + * + * Inputs: + * 1. The battler whose turn flags should be checked. + * 2. The turn flag to check. + * 3. The static value to compare against. + * 4. The distance to jump if the turn flag value matches. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_IfTurnFlag(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - int v2; - int v3; - int v4; - int v5 = 0; + BOOL result = FALSE; - BattleScript_Iter(param1, 1); + BattleScript_Iter(battleCtx, 1); + int inBattler = BattleScript_Read(battleCtx); + int flagID = BattleScript_Read(battleCtx); + int compareTo = BattleScript_Read(battleCtx); + int jumpIfTrue = BattleScript_Read(battleCtx); - v0 = BattleScript_Read(param1); - v1 = BattleScript_Read(param1); - v2 = BattleScript_Read(param1); - v3 = BattleScript_Read(param1); - v4 = BattleScript_Battler(param0, param1, v0); + int battler = BattleScript_Battler(battleSys, battleCtx, inBattler); - switch (v1) { - case 0: - if (param1->turnFlags[v4].struggling == v2) { - v5 = 1; + switch (flagID) { + case TURN_FLAG_STRUGGLING: + if (battleCtx->turnFlags[battler].struggling == compareTo) { + result = TRUE; } break; - case 1: - if (param1->turnFlags[v4].ppDecremented == v2) { - v5 = 1; + + case TURN_FLAG_PP_DECREMENTED: + if (battleCtx->turnFlags[battler].ppDecremented == compareTo) { + result = TRUE; } break; - case 2: - if (param1->turnFlags[v4].protecting == v2) { - v5 = 1; + + case TURN_FLAG_PROTECTING: + if (battleCtx->turnFlags[battler].protecting == compareTo) { + result = TRUE; } break; - case 3: - if (param1->turnFlags[v4].helpingHand == v2) { - v5 = 1; + + case TURN_FLAG_HELPING_HAND: + if (battleCtx->turnFlags[battler].helpingHand == compareTo) { + result = TRUE; } break; - case 4: - if (param1->turnFlags[v4].magicCoat == v2) { - v5 = 1; + + case TURN_FLAG_MAGIC_COAT: + if (battleCtx->turnFlags[battler].magicCoat == compareTo) { + result = TRUE; } break; - case 5: - if (param1->turnFlags[v4].snatching == v2) { - v5 = 1; + + case TURN_FLAG_SNATCHING: + if (battleCtx->turnFlags[battler].snatching == compareTo) { + result = TRUE; } break; - case 6: - if (param1->turnFlags[v4].roosting == v2) { - v5 = 1; + + case TURN_FLAG_ROOSTING: + if (battleCtx->turnFlags[battler].roosting == compareTo) { + result = TRUE; } break; } - if (v5) { - BattleScript_Iter(param1, v3); + if (result) { + BattleScript_Iter(battleCtx, jumpIfTrue); } - return 0; + return FALSE; } -static BOOL ov16_02246CB4 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Set a battler's turn flag to a given static value. + * + * Inputs: + * 1. The battler whose turn flags should be modified. + * 2. The turn flag to be set. + * 3. The static value to set. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_SetTurnFlag(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - int v2; - int v3; - - BattleScript_Iter(param1, 1); + BattleScript_Iter(battleCtx, 1); + int inBattler = BattleScript_Read(battleCtx); + int flagID = BattleScript_Read(battleCtx); + int val = BattleScript_Read(battleCtx); - v0 = BattleScript_Read(param1); - v1 = BattleScript_Read(param1); - v2 = BattleScript_Read(param1); - v3 = BattleScript_Battler(param0, param1, v0); + int battler = BattleScript_Battler(battleSys, battleCtx, inBattler); - switch (v1) { - case 0: - param1->turnFlags[v3].struggling = v2; + switch (flagID) { + case TURN_FLAG_STRUGGLING: + battleCtx->turnFlags[battler].struggling = val; break; - case 1: - param1->turnFlags[v3].ppDecremented = v2; + + case TURN_FLAG_PP_DECREMENTED: + battleCtx->turnFlags[battler].ppDecremented = val; break; - case 2: - param1->turnFlags[v3].protecting = v2; + + case TURN_FLAG_PROTECTING: + battleCtx->turnFlags[battler].protecting = val; break; - case 3: - param1->turnFlags[v3].helpingHand = v2; + + case TURN_FLAG_HELPING_HAND: + battleCtx->turnFlags[battler].helpingHand = val; break; - case 4: - param1->turnFlags[v3].magicCoat = v2; + + case TURN_FLAG_MAGIC_COAT: + battleCtx->turnFlags[battler].magicCoat = val; break; - case 5: - param1->turnFlags[v3].snatching = v2; + + case TURN_FLAG_SNATCHING: + battleCtx->turnFlags[battler].snatching = val; break; - case 6: - param1->turnFlags[v3].roosting = v2; + + case TURN_FLAG_ROOSTING: + battleCtx->turnFlags[battler].roosting = val; break; } - return 0; + return FALSE; } -static BOOL ov16_02246DAC (BattleSystem * param0, BattleContext * param1) +/** + * @brief Calculates the base power of Gyro Ball. + * + * Gyro Ball has greater power if the attacker has lower speed than its target. + * Specifically, it computes the following formula: + * + * ( 25 * defenderSpeed ) + * min( 150, ------------------ + 1 ) + * ( attackerSpeed ) + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_CalcGyroBallPower(BattleSystem *battleSys, BattleContext *battleCtx) { - BattleScript_Iter(param1, 1); - - param1->movePower = 1 + 25 * param1->monSpeedValues[param1->defender] / param1->monSpeedValues[param1->attacker]; + BattleScript_Iter(battleCtx, 1); - if (param1->movePower > 150) { - param1->movePower = 150; + battleCtx->movePower = 1 + 25 * battleCtx->monSpeedValues[battleCtx->defender] / battleCtx->monSpeedValues[battleCtx->attacker]; + if (battleCtx->movePower > 150) { + battleCtx->movePower = 150; } - return 0; + return FALSE; } -static BOOL ov16_02246DF0 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Try to execute Metal Burst. + * + * Inputs: + * 1. The distance to jump if the attacker has not yet taken damage this turn, + * or the last damage source is an ally. + * + * Side effects: + * - battleCtx->damage will be set to 1.5x the attacker's last damage taken. + * - battleCtx->defender will be set to the last battler to deal damage to the + * attacker, or to the defending side's Follow Me user (if one exists), or to + * either's partner (if the former has fainted). + * - If there is no valid target, the "no target" subsequence will be executed. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_TryMetalBurst(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - int v2; - - BattleScript_Iter(param1, 1); - - v0 = BattleScript_Read(param1); - v1 = Battler_Side(param0, param1->attacker); - v2 = Battler_Side(param0, param1->turnFlags[param1->attacker].lastAttacker); + BattleScript_Iter(battleCtx, 1); + int jumpOnFail = BattleScript_Read(battleCtx); + int attacking = Battler_Side(battleSys, battleCtx->attacker); + int defending = Battler_Side(battleSys, ATTACKER_TURN_FLAGS.lastAttacker); - if ((param1->turnFlags[param1->attacker].lastDamageTaken) && (v1 != v2) && (param1->battleMons[param1->turnFlags[param1->attacker].lastAttacker].curHP)) { - param1->damage = param1->turnFlags[param1->attacker].lastDamageTaken * 15 / 10; + if (ATTACKER_TURN_FLAGS.lastDamageTaken + && attacking != defending + && battleCtx->battleMons[ATTACKER_TURN_FLAGS.lastAttacker].curHP) { + battleCtx->damage = ATTACKER_TURN_FLAGS.lastDamageTaken * 15 / 10; - if ((param1->sideConditions[v2].followMe) && (param1->battleMons[param1->sideConditions[v2].followMeUser].curHP)) { - param1->defender = param1->sideConditions[v2].followMeUser; + if (battleCtx->sideConditions[defending].followMe && FOLLOW_ME_MON(defending).curHP) { + battleCtx->defender = FOLLOW_ME_USER(defending); } else { - param1->defender = param1->turnFlags[param1->attacker].lastAttacker; + battleCtx->defender = ATTACKER_TURN_FLAGS.lastAttacker; } - if (param1->battleMons[param1->defender].curHP == 0) { - param1->defender = BattleSystem_RandomOpponent(param0, param1, param1->attacker); + if (DEFENDING_MON.curHP == 0) { + battleCtx->defender = BattleSystem_RandomOpponent(battleSys, battleCtx, battleCtx->attacker); - if (param1->battleMons[param1->defender].curHP == 0) { - param1->commandNext = 38; - BattleScript_Jump(param1, 1, (0 + 281)); + if (DEFENDING_MON.curHP == 0) { + battleCtx->commandNext = BATTLE_CONTROL_UPDATE_MOVE_BUFFERS; + BattleScript_Jump(battleCtx, NARC_INDEX_BATTLE__SKILL__SUB_SEQ, BATTLE_SUBSEQ_NO_TARGET); } } - BattleSystem_DecPPForPressure(param1, param1->attacker, param1->defender); + BattleSystem_DecPPForPressure(battleCtx, battleCtx->attacker, battleCtx->defender); } else { - BattleScript_Iter(param1, v0); + BattleScript_Iter(battleCtx, jumpOnFail); } - return 0; + return FALSE; } -static BOOL ov16_02246EE4 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Calculates the power for Payback. + * + * Payback has doubled power if the user moves after the target, if the target + * switches out, or if the opponent uses an item. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_CalcPaybackPower(BattleSystem *battleSys, BattleContext *battleCtx) { - BattleScript_Iter(param1, 1); + BattleScript_Iter(battleCtx, 1); - if (param1->battlerActions[param1->defender][0] == 39) { - param1->movePower = param1->aiContext.moveTable[param1->moveCur].power * 2; + if (DEFENDER_ACTION[BATTLE_ACTION_PICK_COMMAND] == BATTLE_CONTROL_MOVE_END) { + battleCtx->movePower = CURRENT_MOVE_DATA.power * 2; } else { - param1->movePower = param1->aiContext.moveTable[param1->moveCur].power; + battleCtx->movePower = CURRENT_MOVE_DATA.power; } - return 0; + return FALSE; } -static const u8 Unk_ov16_0226E574[] = { - 0xC8, - 0x50, - 0x3C, - 0x32, - 0x28 +static const u8 sCurrentPPScaledPower[] = { + 200, + 80, + 60, + 50, + 40, }; -static BOOL ov16_02246F2C (BattleSystem * param0, BattleContext * param1) +/** + * @brief Calculates the base power of Trump Card. + * + * Trump Card's base power scales according to its remaining PP. + * - 0: 200 + * - 1: 80 + * - 2: 60 + * - 3: 50 + * - 4+: 40 + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_CalcTrumpCardPower(BattleSystem *battleSys, BattleContext *battleCtx) { - u8 v0; - - BattleScript_Iter(param1, 1); - - v0 = param1->battleMons[param1->attacker].ppCur[param1->moveSlot[param1->attacker]]; + BattleScript_Iter(battleCtx, 1); - if (v0 > 4) { - v0 = 4; + u8 ppCur = ATTACKING_MON.ppCur[ATTACKER_MOVE_SLOT]; + if (ppCur > 4) { + ppCur = 4; } - param1->movePower = Unk_ov16_0226E574[v0]; + battleCtx->movePower = sCurrentPPScaledPower[ppCur]; - return 0; + return FALSE; } -static BOOL ov16_02246F70 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Calculates the base power of Wring Out. + * + * Wring Out's base power scales according to the defender's remaining HP. + * Specifically, it computes the following formula: + * + * 120 * currentHP + * 1 + --------------- + * maxHP + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_CalcWringOutPower(BattleSystem *battleSys, BattleContext *battleCtx) { - u8 v0; - - BattleScript_Iter(param1, 1); + BattleScript_Iter(battleCtx, 1); - param1->movePower = 1 + (120 * param1->battleMons[param1->defender].curHP) / param1->battleMons[param1->defender].maxHP; + battleCtx->movePower = 1 + (120 * DEFENDING_MON.curHP) / DEFENDING_MON.maxHP; - return 0; + return FALSE; } -static BOOL ov16_02246FA8 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Try to execute Me First. + * + * Inputs: + * 1. The distance to jump if the defender has already taken their turn, if the + * defender is struggling, if the move to be stolen cannot be copied by Me First, + * or if the move to be stolen has no base power. + * + * Side effects: + * - The Me First flag will be set on the attacker's move effects. + * - battleCtx->msgMoveTemp will be set to the stolen move. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_TryMeFirst(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - u16 v1; - - BattleScript_Iter(param1, 1); - - v0 = BattleScript_Read(param1); + BattleScript_Iter(battleCtx, 1); + int jumpOnFail = BattleScript_Read(battleCtx); - if ((param1->battleMons[param1->defender].moveEffectsData.encoredMove) && (param1->battleMons[param1->defender].moveEffectsData.encoredMove == param1->battleMons[param1->defender].moves[param1->battleMons[param1->defender].moveEffectsData.encoredMoveSlot])) { - v1 = param1->battleMons[param1->defender].moveEffectsData.encoredMove; + u16 move; + if (DEFENDING_MON.moveEffectsData.encoredMove + && DEFENDING_MON.moveEffectsData.encoredMove == DEFENDING_MON.moves[DEFENDING_MON.moveEffectsData.encoredMoveSlot]) { + move = DEFENDING_MON.moveEffectsData.encoredMove; } else { - v1 = Battler_SelectedMove(param1, param1->defender); + move = Battler_SelectedMove(battleCtx, battleCtx->defender); } - if ((param1->battlerActions[param1->defender][0] != 39) && (param1->turnFlags[param1->defender].struggling == 0) && (Move_MeFirstCanCopy(param1, v1) == 1) && (param1->aiContext.moveTable[v1].power)) { - param1->battleMons[param1->attacker].moveEffectsData.meFirst = 1; - param1->battleMons[param1->attacker].moveEffectsData.meFirstTurnNumber = param1->meFirstTurnOrder; - param1->msgMoveTemp = v1; + if (DEFENDER_ACTION[BATTLE_ACTION_PICK_COMMAND] != BATTLE_CONTROL_MOVE_END + && DEFENDER_TURN_FLAGS.struggling == FALSE + && Move_MeFirstCanCopy(battleCtx, move) == TRUE + && MOVE_DATA(move).power) { + ATTACKING_MON.moveEffectsData.meFirst = TRUE; + ATTACKING_MON.moveEffectsData.meFirstTurnNumber = battleCtx->meFirstTurnOrder; + battleCtx->msgMoveTemp = move; } else { - BattleScript_Iter(param1, v0); + BattleScript_Iter(battleCtx, jumpOnFail); } - return 0; + return FALSE; } -static BOOL ov16_02247064 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Try to execute Copycat. + * + * Inputs: + * 1. The distace to jump if the move to be copied is invoker-class, if a move + * has yet to be used this turn, or if the move to be copied cannot be invoked + * by Metronome. + * + * Side effects: + * - battleCtx->msgMoveTemp will be set to the most-recently used move. + * + * @param battleSys + * @param battleCtx + * @return BOOL + */ +static BOOL BtlCmd_TryCopycat(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - - BattleScript_Iter(param1, 1); - - v0 = BattleScript_Read(param1); + BattleScript_Iter(battleCtx, 1); + int jumpOnFail = BattleScript_Read(battleCtx); - if ((Move_IsInvoker(param1->movePrev) == 0) && (param1->movePrev) && (Move_CanBeMetronomed(param0, param1, param1->attacker, param1->movePrev) == 1)) { - param1->msgMoveTemp = param1->movePrev; + if (Move_IsInvoker(battleCtx->movePrev) == FALSE + && battleCtx->movePrev + && Move_CanBeMetronomed(battleSys, battleCtx, battleCtx->attacker, battleCtx->movePrev) == TRUE) { + battleCtx->msgMoveTemp = battleCtx->movePrev; } else { - BattleScript_Iter(param1, v0); + BattleScript_Iter(battleCtx, jumpOnFail); } - return 0; + return FALSE; } -static BOOL ov16_022470C0 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Calculate the base power for Punishment. + * + * Punishment's base power scales according to the sum of stat boosts that the + * target has accrued. Stat reductions are not considered. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_CalcPunishmentPower(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - - BattleScript_Iter(param1, 1); - - v1 = 0; + BattleScript_Iter(battleCtx, 1); - for (v0 = 0x0; v0 < 0x8; v0++) { - if (param1->battleMons[param1->defender].statBoosts[v0] > 6) { - v1 += (param1->battleMons[param1->defender].statBoosts[v0] - 6); + // must declare i first to match + int i, sumBoosts = 0; + for (i = BATTLE_STAT_HP; i < BATTLE_STAT_MAX; i++) { + if (DEFENDING_MON.statBoosts[i] > 6) { + sumBoosts += DEFENDING_MON.statBoosts[i] - 6; } } - param1->movePower = 60 + 20 * v1; - - if (param1->movePower > 200) { - param1->movePower = 200; + battleCtx->movePower = 60 + 20 * sumBoosts; + if (battleCtx->movePower > 200) { + battleCtx->movePower = 200; } - return 0; + return FALSE; } -static BOOL ov16_02247118 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Try to execute Sucker Punch. + * + * Inputs: + * 1. The distance to jump if the target has already taken their turn, or if + * the target's chosen move has no power. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_TrySuckerPunch(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - - BattleScript_Iter(param1, 1); - - v0 = BattleScript_Read(param1); + BattleScript_Iter(battleCtx, 1); + int jumpOnFail = BattleScript_Read(battleCtx); - if ((param1->battleMons[param1->defender].moveEffectsData.encoredMove) && (param1->battleMons[param1->defender].moveEffectsData.encoredMove == param1->battleMons[param1->defender].moves[param1->battleMons[param1->defender].moveEffectsData.encoredMoveSlot])) { - v1 = param1->battleMons[param1->defender].moveEffectsData.encoredMove; + int move; + if (DEFENDING_MON.moveEffectsData.encoredMove + && DEFENDING_MON.moveEffectsData.encoredMove == DEFENDING_MON.moves[DEFENDING_MON.moveEffectsData.encoredMoveSlot]) { + move = DEFENDING_MON.moveEffectsData.encoredMove; } else { - v1 = Battler_SelectedMove(param1, param1->defender); + move = Battler_SelectedMove(battleCtx, battleCtx->defender); } - if ((param1->battlerActions[param1->defender][0] == 39) || ((param1->aiContext.moveTable[v1].power == 0) && (param1->turnFlags[param1->defender].struggling == 0))) { - BattleScript_Iter(param1, v0); + if (DEFENDER_ACTION[BATTLE_ACTION_PICK_COMMAND] == BATTLE_CONTROL_MOVE_END + || (MOVE_DATA(move).power == 0 && DEFENDER_TURN_FLAGS.struggling == FALSE)) { + BattleScript_Iter(battleCtx, jumpOnFail); } - return 0; + return FALSE; } -static BOOL ov16_02247194 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Check the side conditions for a particular side of the battle, or + * clear them. + * + * Inputs: + * 1. The battler for whom the side conditions should be checked/cleared. + * 2. The op code for this command (see: enum CheckSideConditionOp). + * 3. The specific side condition to check/modify (see: enum SideCondition). + * 4. The distance to jump if a check operation is not fulfilled. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_CheckSideCondition(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - int v2; - int v3; - int v4; - int v5; - int v6; - - BattleScript_Iter(param1, 1); + BattleScript_Iter(battleCtx, 1); + int inBattler = BattleScript_Read(battleCtx); + int op = BattleScript_Read(battleCtx); + int sidecond = BattleScript_Read(battleCtx); + int jump = BattleScript_Read(battleCtx); - v0 = BattleScript_Read(param1); - v1 = BattleScript_Read(param1); - v2 = BattleScript_Read(param1); - v3 = BattleScript_Read(param1); - v4 = BattleScript_Battler(param0, param1, v0); - v5 = Battler_Side(param0, v4); + int battler = BattleScript_Battler(battleSys, battleCtx, inBattler); + int side = Battler_Side(battleSys, battler); + int val; - switch (v1) { - case 0: - case 1: - switch (v2) { - case 0: - v6 = param1->sideConditions[v5].reflectTurns; + switch (op) { + case CHECK_SIDE_COND_VAL_ZERO: + case CHECK_SIDE_COND_VAL_NOT_ZERO: + switch (sidecond) { + case SIDE_COND_REFLECT_TURNS: + val = battleCtx->sideConditions[side].reflectTurns; break; - case 1: - v6 = param1->sideConditions[v5].lightScreenTurns; + + case SIDE_COND_LIGHT_SCREEN_TURNS: + val = battleCtx->sideConditions[side].lightScreenTurns; break; - case 2: - v6 = param1->sideConditions[v5].mistTurns; + + case SIDE_COND_MIST_TURNS: + val = battleCtx->sideConditions[side].mistTurns; break; - case 3: - v6 = param1->sideConditions[v5].safeguardTurns; + + case SIDE_COND_SAFEGUARD_TURNS: + val = battleCtx->sideConditions[side].safeguardTurns; break; - case 4: - v6 = param1->sideConditions[v5].spikesLayers; + + case SIDE_COND_SPIKES_LAYERS: + val = battleCtx->sideConditions[side].spikesLayers; break; - case 5: - v6 = param1->sideConditions[v5].toxicSpikesLayers; + + case SIDE_COND_TOXIC_SPIKES_LAYERS: + val = battleCtx->sideConditions[side].toxicSpikesLayers; break; } break; - case 2: - switch (v2) { - case 0: - param1->sideConditions[v5].reflectTurns = 0; - param1->sideConditionsMask[v5] &= (0x1 ^ 0xffffffff); + + case CHECK_SIDE_COND_CLEAR: + switch (sidecond) { + case SIDE_COND_REFLECT_TURNS: + battleCtx->sideConditions[side].reflectTurns = 0; + battleCtx->sideConditionsMask[side] &= ~SIDE_CONDITION_REFLECT; break; - case 1: - param1->sideConditions[v5].lightScreenTurns = 0; - param1->sideConditionsMask[v5] &= (0x2 ^ 0xffffffff); + + case SIDE_COND_LIGHT_SCREEN_TURNS: + battleCtx->sideConditions[side].lightScreenTurns = 0; + battleCtx->sideConditionsMask[side] &= ~SIDE_CONDITION_LIGHT_SCREEN; break; - case 2: - param1->sideConditions[v5].mistTurns = 0; - param1->sideConditionsMask[v5] &= (0x40 ^ 0xffffffff); + + case SIDE_COND_MIST_TURNS: + battleCtx->sideConditions[side].mistTurns = 0; + battleCtx->sideConditionsMask[side] &= ~SIDE_CONDITION_MIST; break; - case 3: - param1->sideConditions[v5].safeguardTurns = 0; - param1->sideConditionsMask[v5] &= (0x8 ^ 0xffffffff); + + case SIDE_COND_SAFEGUARD_TURNS: + battleCtx->sideConditions[side].safeguardTurns = 0; + battleCtx->sideConditionsMask[side] &= ~SIDE_CONDITION_SAFEGUARD; break; - case 4: - param1->sideConditions[v5].spikesLayers = 0; - param1->sideConditionsMask[v5] &= (0x4 ^ 0xffffffff); + + case SIDE_COND_SPIKES_LAYERS: + battleCtx->sideConditions[side].spikesLayers = 0; + battleCtx->sideConditionsMask[side] &= ~SIDE_CONDITION_SPIKES; break; - case 5: - param1->sideConditions[v5].toxicSpikesLayers = 0; - param1->sideConditionsMask[v5] &= (0x400 ^ 0xffffffff); + + case SIDE_COND_TOXIC_SPIKES_LAYERS: + battleCtx->sideConditions[side].toxicSpikesLayers = 0; + battleCtx->sideConditionsMask[side] &= ~SIDE_CONDITION_TOXIC_SPIKES; break; } break; } - if ((v1 == 0) && (v6 == 0)) { - BattleScript_Iter(param1, v3); + if (op == CHECK_SIDE_COND_VAL_ZERO && val == 0) { + BattleScript_Iter(battleCtx, jump); } - if ((v1 == 1) && (v6)) { - BattleScript_Iter(param1, v3); + if (op == CHECK_SIDE_COND_VAL_NOT_ZERO && val) { + BattleScript_Iter(battleCtx, jump); } - return 0; + return FALSE; } -static BOOL ov16_02247378 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Check if the current move's target is Protecting itself. + * + * Inputs: + * 1. The distance to jump if the target is not Protecting itself. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_CheckDefenderProtecting(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - - BattleScript_Iter(param1, 1); - - v0 = BattleScript_Read(param1); + BattleScript_Iter(battleCtx, 1); + int jumpOnFail = BattleScript_Read(battleCtx); - if (param1->turnFlags[param1->defender].protecting == 0) { - BattleScript_Iter(param1, v0); + if (DEFENDER_TURN_FLAGS.protecting == FALSE) { + BattleScript_Iter(battleCtx, jumpOnFail); } - return 0; + return FALSE; } -static BOOL ov16_022473A8 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Check if the defending battler can be given a non-volatile status + * condition from the attacker. + * + * Inputs: + * 1. The distance to jump if the defender is already statused, if the defender + * is behind a Substitute, or if the attacker does not have a status condition. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_CheckCanShareStatus(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - - BattleScript_Iter(param1, 1); - - v0 = BattleScript_Read(param1); + BattleScript_Iter(battleCtx, 1); + int jumpOnFail = BattleScript_Read(battleCtx); - if ((param1->battleMons[param1->defender].status) || (param1->battleMons[param1->defender].statusVolatile & 0x1000000) || (param1->battleMons[param1->attacker].status == 0)) { - BattleScript_Iter(param1, v0); + if (DEFENDING_MON.status + || (DEFENDING_MON.statusVolatile & VOLATILE_CONDITION_SUBSTITUTE) + || ATTACKING_MON.status == MON_CONDITION_NONE) { + BattleScript_Iter(battleCtx, jumpOnFail); } - return 0; + return FALSE; } -static BOOL ov16_022473F4 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Try to execute Last Resort. + * + * Inputs: + * 1. The distance to jump if the battler has yet to use all of its other + * known moves, or if it ONLY knows Last Resort. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_TryLastResort(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - - BattleScript_Iter(param1, 1); - - v0 = BattleScript_Read(param1); - v1 = ov16_02256128(param0, param1, param1->attacker); + BattleScript_Iter(battleCtx, 1); + int jumpOnFail = BattleScript_Read(battleCtx); + int numMoves = Battler_CountMoves(battleSys, battleCtx, battleCtx->attacker); - if ((param1->battleMons[param1->attacker].moveEffectsData.lastResortCount < (v1 - 1)) || (v1 < 2)) { - BattleScript_Iter(param1, v0); + if (ATTACKING_MON.moveEffectsData.lastResortCount < numMoves - 1 + || numMoves < 2) { + BattleScript_Iter(battleCtx, jumpOnFail); } - return 0; + return FALSE; } -static BOOL ov16_02247440 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Try to execute the Toxic Spikes effect. + * + * Inputs: + * 1. The distance to jump if there are already 2 layers of Toxic Spikes on + * the targeted side of the field. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_TryToxicSpikes(BattleSystem * battleSys, BattleContext * battleCtx) { - int v0; - int v1; - - BattleScript_Iter(param1, 1); - - v0 = BattleScript_Read(param1); - v1 = Battler_Side(param0, param1->attacker) ^ 1; + BattleScript_Iter(battleCtx, 1); + int jumpOnFail = BattleScript_Read(battleCtx); + int defending = Battler_Side(battleSys, battleCtx->attacker) ^ 1; - if (param1->sideConditions[v1].toxicSpikesLayers == 2) { - param1->selfTurnFlags[param1->attacker].skipPressureCheck = 1; - BattleScript_Iter(param1, v0); + if (battleCtx->sideConditions[defending].toxicSpikesLayers == 2) { + ATTACKER_SELF_TURN_FLAGS.skipPressureCheck = TRUE; + BattleScript_Iter(battleCtx, jumpOnFail); } else { - param1->sideConditionsMask[v1] |= 0x400; - param1->sideConditions[v1].toxicSpikesLayers++; + battleCtx->sideConditionsMask[defending] |= SIDE_CONDITION_TOXIC_SPIKES; + battleCtx->sideConditions[defending].toxicSpikesLayers++; } return 0; } -static BOOL ov16_022474C4 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Check for the Toxic Spikes entry effect. + * + * Inputs: + * 1. The battler who is switching in and should be subject to Toxic Spikes. + * 2. The distance to jump if there are no layers of Toxic Spikes. + * + * Side effects: + * - battleCtx->calcTemp will be set to the number of layers of Toxic Spikes on + * the switched-in battler's side of the field. If the switched-in battler has + * the Poison type, then this will instead be set to 0. + * - battleCtx->sideEffectType will be set to SIDE_EFFECT_SOURCE_TOXIC_SPIKES. + * - battleCtx->sideEffectMon will be set to the switched-in battler. + * - If the switched-in battler has the Poison type, then Toxic Spikes will be + * cleared from its side of the field. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_CheckToxicSpikes(BattleSystem * battleSys, BattleContext * battleCtx) { - int v0; - int v1; - int v2; - int v3; - - BattleScript_Iter(param1, 1); + BattleScript_Iter(battleCtx, 1); + int inBattler = BattleScript_Read(battleCtx); + int jumpIfNoToxicSpikes = BattleScript_Read(battleCtx); - v0 = BattleScript_Read(param1); - v1 = BattleScript_Read(param1); - v2 = BattleScript_Battler(param0, param1, v0); - v3 = Battler_Side(param0, v2); + int battler = BattleScript_Battler(battleSys, battleCtx, inBattler); + int side = Battler_Side(battleSys, battler); - if (param1->sideConditions[v3].toxicSpikesLayers) { - param1->calcTemp = param1->sideConditions[v3].toxicSpikesLayers; - param1->sideEffectType = 6; - param1->sideEffectMon = v2; + if (battleCtx->sideConditions[side].toxicSpikesLayers) { + battleCtx->calcTemp = battleCtx->sideConditions[side].toxicSpikesLayers; + battleCtx->sideEffectType = SIDE_EFFECT_SOURCE_TOXIC_SPIKES; + battleCtx->sideEffectMon = battler; - if ((BattleMon_Get(param1, param1->switchedMon, 27, NULL) == 3) || (BattleMon_Get(param1, param1->switchedMon, 28, NULL) == 3)) { - param1->sideConditionsMask[v3] &= (0x400 ^ 0xffffffff); - param1->sideConditions[v3].toxicSpikesLayers = 0; - param1->calcTemp = 0; + if (MON_HAS_TYPE(battleCtx->switchedMon, TYPE_POISON)) { + battleCtx->sideConditionsMask[side] &= ~SIDE_CONDITION_TOXIC_SPIKES; + battleCtx->sideConditions[side].toxicSpikesLayers = 0; + battleCtx->calcTemp = 0; } } else { - BattleScript_Iter(param1, v1); + BattleScript_Iter(battleCtx, jumpIfNoToxicSpikes); } - return 0; + return FALSE; } -static BOOL ov16_02247570 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Check the ability of a battler or set of battlers, accounting for + * effects which ignore that ability. + * + * Inputs: + * 1. Op-code which controls the behavior. See enum CheckHaveOp + * 2. Input battler (or set of battlers) whose ability should be checked + * 3. The ability to check for any battler to have (or not have) + * 4. Jump distance if a battler in the input set meets the criteria + * + * Side effects: + * - If any battler matches the criteria, battleCtx->abilityMon will be set + * to their identifier. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_CheckIgnorableAbility(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - int v2; - int v3; - int v4; - - BattleScript_Iter(param1, 1); - - v0 = BattleScript_Read(param1); - v1 = BattleScript_Read(param1); - v2 = BattleScript_Read(param1); - v3 = BattleScript_Read(param1); - - if (v1 == 0x0) { - { - int v5; - int v6; + BattleScript_Iter(battleCtx, 1); + int op = BattleScript_Read(battleCtx); + int inBattler = BattleScript_Read(battleCtx); + int ability = BattleScript_Read(battleCtx); + int jump = BattleScript_Read(battleCtx); - v6 = BattleSystem_MaxBattlers(param0); + int battler; + if (inBattler == BTLSCR_ALL_BATTLERS) { + int maxBattlers = BattleSystem_MaxBattlers(battleSys); - for (v5 = 0; v5 < v6; v5++) { - v4 = param1->monSpeedOrder[v5]; + for (int i = 0; i < maxBattlers; i++) { + battler = battleCtx->monSpeedOrder[i]; - if (v0 == 0) { - if ((Battler_IgnorableAbility(param1, param1->attacker, v4, v2) == 1) && (param1->battleMons[v4].curHP)) { - BattleScript_Iter(param1, v3); - param1->abilityMon = v4; - break; - } - } else { - if ((Battler_IgnorableAbility(param1, param1->attacker, v4, v2) == 0) || (param1->battleMons[v4].curHP == 0)) { - BattleScript_Iter(param1, v3); - param1->abilityMon = v4; - break; - } + if (op == CHECK_HAVE) { + if (Battler_IgnorableAbility(battleCtx, battleCtx->attacker, battler, ability) == TRUE + && battleCtx->battleMons[battler].curHP) { + BattleScript_Iter(battleCtx, jump); + battleCtx->abilityMon = battler; + break; } + } else if (Battler_IgnorableAbility(battleCtx, battleCtx->attacker, battler, ability) == FALSE + || battleCtx->battleMons[battler].curHP == 0) { + BattleScript_Iter(battleCtx, jump); + battleCtx->abilityMon = battler; + break; } } } else { - v4 = BattleScript_Battler(param0, param1, v1); + battler = BattleScript_Battler(battleSys, battleCtx, inBattler); - if (v0 == 0) { - if ((Battler_IgnorableAbility(param1, param1->attacker, v4, v2) == 1) && (param1->battleMons[v4].curHP)) { - BattleScript_Iter(param1, v3); - param1->abilityMon = v4; - } - } else { - if ((Battler_IgnorableAbility(param1, param1->attacker, v4, v2) == 0) || (param1->battleMons[v4].curHP == 0)) { - BattleScript_Iter(param1, v3); - param1->abilityMon = v4; + if (op == CHECK_HAVE) { + if (Battler_IgnorableAbility(battleCtx, battleCtx->attacker, battler, ability) == TRUE + && battleCtx->battleMons[battler].curHP) { + BattleScript_Iter(battleCtx, jump); + battleCtx->abilityMon = battler; } + } else if (Battler_IgnorableAbility(battleCtx, battleCtx->attacker, battler, ability) == FALSE + || battleCtx->battleMons[battler].curHP == 0) { + BattleScript_Iter(battleCtx, jump); + battleCtx->abilityMon = battler; } } - return 0; + return FALSE; } -static BOOL ov16_02247698 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Jump forward a certain distance if two battlers are on the same + * side of the field. + * + * Inputs: + * 1. The first battler. + * 2. The second battler. + * 3. The distance to jump if the two battlers are teammates. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_IfSameSide(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - int v2; - int v3; - int v4; - - BattleScript_Iter(param1, 1); + BattleScript_Iter(battleCtx, 1); + int inBattler1 = BattleScript_Read(battleCtx); + int inBattler2 = BattleScript_Read(battleCtx); + int jumpIfSameSide = BattleScript_Read(battleCtx); - v0 = BattleScript_Read(param1); - v1 = BattleScript_Read(param1); - v2 = BattleScript_Read(param1); - v3 = BattleScript_Battler(param0, param1, v0); - v4 = BattleScript_Battler(param0, param1, v1); + int battler1 = BattleScript_Battler(battleSys, battleCtx, inBattler1); + int battler2 = BattleScript_Battler(battleSys, battleCtx, inBattler2); - if (Battler_Side(param0, v3) == Battler_Side(param0, v4)) { - BattleScript_Iter(param1, v2); + if (Battler_Side(battleSys, battler1) == Battler_Side(battleSys, battler2)) { + BattleScript_Iter(battleCtx, jumpIfSameSide); } - return 0; + return FALSE; } -static const u16 Unk_ov16_0226E66C[] = { - 0x11, - 0x12, - 0x1A, - 0x3, - 0x4F, - 0x4E, - 0x1B, - 0x19, - 0x2, - 0x1C, - 0x32, - 0x6C, - 0x6B, - 0x6D, - 0x17, - 0x1D, - 0x33, - 0x29 +static const u16 sCommonPickupItems[] = { + ITEM_POTION, + ITEM_ANTIDOTE, + ITEM_SUPER_POTION, + ITEM_GREAT_BALL, + ITEM_REPEL, + ITEM_ESCAPE_ROPE, + ITEM_FULL_HEAL, + ITEM_HYPER_POTION, + ITEM_ULTRA_BALL, + ITEM_REVIVE, + ITEM_RARE_CANDY, + ITEM_DUSK_STONE, + ITEM_SHINY_STONE, + ITEM_DAWN_STONE, + ITEM_FULL_RESTORE, + ITEM_MAX_REVIVE, + ITEM_PP_UP, + ITEM_MAX_ELIXIR, }; -static const u16 Unk_ov16_0226E590[] = { - 0x19, - 0x5C, - 0xDD, - 0x17, - 0x26, - 0xD6, - 0x173, - 0x28, - 0x148, - 0xEA, - 0x161 +static const u16 sRarePickupItems[] = { + ITEM_HYPER_POTION, + ITEM_NUGGET, + ITEM_KINGS_ROCK, + ITEM_FULL_RESTORE, + ITEM_ETHER, + ITEM_WHITE_HERB, + ITEM_TM44, + ITEM_ELIXIR, + ITEM_TM01, + ITEM_LEFTOVERS, + ITEM_TM26, }; -static const u8 Unk_ov16_0226EAA8[] = { - 0x1E, - 0x28, - 0x32, - 0x3C, - 0x46, - 0x50, - 0x5A, - 0x5E, - 0x62 +#define COMMON_PICKUP_ENTRIES 9 + +static const u8 sCommonPickupRate[] = { + 30, + 40, + 50, + 60, + 70, + 80, + 90, + 94, + 98, }; -static const u8 Unk_ov16_0226EAB4[] = { - 0x5, - 0xA, - 0xF, - 0x14, - 0x19, - 0x1E, - 0x23, - 0x28, - 0x2D, - 0x32 +static const u8 sHoneyGatherRate[] = { + 5, + 10, + 15, + 20, + 25, + 30, + 35, + 40, + 45, + 50, }; -static BOOL ov16_022476F8 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Generates an end-of-battle item, if applicable. + * + * This command encompasses two abilities: Pickup and Honey Gather. + * + * Pickup has a 10% chance to generate a semi-random item pulled from a table + * of eligible values. The generated item has a 98% chance to be a "common" + * item, and a 2% chance to be a "rare" item. The exact items which can be + * generated vary using a sliding window on table of all possible entries; the + * window used shifts forward 1 entry for every 10 levels that the Pokemon has + * (1-10, 11-20, etc.). + * + * 9 slots are viewed for the common items window, and 2 slots are viewed for + * the rare items window. Items in the rare window have an equal chance of + * being generated (1% each). Items in the common window have a sliding + * probability: + * 1: 30% + * 2 - 7: 10% each + * 8, 9: 4% each + * + * Honey Gather has a 5% chance to generate Honey at the end of the battle, + * scaling upwards by 5% for every 10 levels that the Pokemon has (5% for + * levels 1-10, 10% for levels 11-20, etc., capping at 50%). + * + * @param battleSys + * @param battleCtx + * @return BOOL + */ +static BOOL BtlCmd_GenerateEndOfBattleItem(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1, v2, v3; - u16 v4; - u16 v5; - u8 v6; - u8 v7; - Pokemon * v8; + // Declare C89-style to match + int rnd, i, j, max; + u16 species, item; + u8 ability, level; + Pokemon *mon; - BattleScript_Iter(param1, 1); + BattleScript_Iter(battleCtx, 1); + + for (i = 0; i < BattleSystem_PartyCount(battleSys, BATTLER_US); i++) { + mon = BattleSystem_PartyPokemon(battleSys, BATTLER_US, i); + species = Pokemon_GetValue(mon, MON_DATA_SPECIES_EGG, NULL); + item = Pokemon_GetValue(mon, MON_DATA_HELD_ITEM, NULL); + ability = Pokemon_GetValue(mon, MON_DATA_ABILITY, NULL); - for (v1 = 0; v1 < BattleSystem_PartyCount(param0, 0); v1++) { - v8 = BattleSystem_PartyPokemon(param0, 0, v1); - v4 = Pokemon_GetValue(v8, MON_DATA_SPECIES_EGG, NULL); - v5 = Pokemon_GetValue(v8, MON_DATA_HELD_ITEM, NULL); - v6 = Pokemon_GetValue(v8, MON_DATA_ABILITY, NULL); + if (ability == ABILITY_PICKUP + && species != SPECIES_NONE + && species != SPECIES_EGG + && item == ITEM_NONE + && BattleSystem_RandNext(battleSys) % 10 == 0) { + rnd = BattleSystem_RandNext(battleSys) % 100; - if ((v6 == 53) && (v4 != 0) && (v4 != 494) && (v5 == 0) && ((BattleSystem_RandNext(param0) % 10) == 0)) { - v0 = BattleSystem_RandNext(param0) % 100; - v7 = (Pokemon_GetValue(v8, MON_DATA_LEVEL, NULL) - 1) / 10; + // determine what offset of the sliding table to start from + level = (Pokemon_GetValue(mon, MON_DATA_LEVEL, NULL) - 1) / 10; - if (v7 >= 10) { - v7 = 9; + if (level >= COMMON_PICKUP_ENTRIES + 1) { // must use GTE to match; does not match with GT + level = COMMON_PICKUP_ENTRIES; } - for (v2 = 0; v2 < 9; v2++) { - if (Unk_ov16_0226EAA8[v2] > v0) { - Pokemon_SetValue(v8, 6, (u8 *)&Unk_ov16_0226E66C[v7 + v2]); + // find the item to generate + for (j = 0; j < COMMON_PICKUP_ENTRIES; j++) { + if (sCommonPickupRate[j] > rnd) { + Pokemon_SetValue(mon, MON_DATA_HELD_ITEM, &sCommonPickupItems[level + j]); break; - } else if ((v0 >= 98) && (v0 <= 99)) { - Pokemon_SetValue(v8, 6, (u8 *)&Unk_ov16_0226E590[v7 + (99 - v0)]); + } + + if (rnd >= 98 && rnd <= 99) { + Pokemon_SetValue(mon, MON_DATA_HELD_ITEM, &sRarePickupItems[level + (99 - rnd)]); break; } } } - if ((v6 == 118) && (v4 != 0) && (v4 != 494) && (v5 == 0)) { - v2 = 0; - v3 = 10; - v7 = Pokemon_GetValue(v8, MON_DATA_LEVEL, NULL); + if (ability == ABILITY_HONEY_GATHER + && species != SPECIES_NONE + && species != SPECIES_EGG + && item == ITEM_NONE) { + j = 0; + max = 10; + level = Pokemon_GetValue(mon, MON_DATA_LEVEL, NULL); - while (v7 > v3) { - v2++; - v3 += 10; + // floor the Pokemon's level by ranges of 10 + // e.g., levels 1-10 eval to 0, levels 21-30 eval to 2, etc. + while (level > max) { + j++; + max += 10; } - GF_ASSERT(v2 < 10); + GF_ASSERT(j < 10); - if (BattleSystem_RandNext(param0) % 100 < Unk_ov16_0226EAB4[v2]) { - v2 = 94; - Pokemon_SetValue(v8, 6, (u8 *)&v2); + if (BattleSystem_RandNext(battleSys) % 100 < sHoneyGatherRate[j]) { + j = ITEM_HONEY; + Pokemon_SetValue(mon, MON_DATA_HELD_ITEM, &j); } } } - return 0; + return FALSE; } -static BOOL ov16_0224787C (BattleSystem * param0, BattleContext * param1) +/** + * @brief Set the Trick Room activation flag for the attacker. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_SetTrickRoom(BattleSystem *battleSys, BattleContext *battleCtx) { - BattleScript_Iter(param1, 1); + BattleScript_Iter(battleCtx, 1); - param1->selfTurnFlags[param1->attacker].trickRoomActivated = 1; + ATTACKER_SELF_TURN_FLAGS.trickRoomActivated = TRUE; - return 0; + return FALSE; } -static BOOL ov16_022478A4 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Jump ahead if a given battler has already moved this turn. + * + * Inputs: + * 1. The battler to check. + * 2. The distance to jump if the battler has already moved this turn. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_IfMovedThisTurn(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - int v2; - - BattleScript_Iter(param1, 1); - - v1 = BattleScript_Read(param1); - v2 = BattleScript_Read(param1); - v0 = BattleScript_Battler(param0, param1, v1); + BattleScript_Iter(battleCtx, 1); + int inBattler = BattleScript_Read(battleCtx); + int jump = BattleScript_Read(battleCtx); + int battler = BattleScript_Battler(battleSys, battleCtx, inBattler); - if (Battler_MovedThisTurn(param1, v0) == 1) { - BattleScript_Iter(param1, v2); + if (Battler_MovedThisTurn(battleCtx, battler) == TRUE) { + BattleScript_Iter(battleCtx, jump); } - return 0; + return FALSE; } -static BOOL ov16_022478E4 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Jump ahead if a given battler has (or does not have) an item with the + * given hold effect. + * + * Inputs: + * 1. Opcode. See enum CheckHaveOp. + * 2. The battler whose held item is to be checked. + * 3. The effect to check for. + * 4. The distance to jump if the battler has (or does not have) an item with + * the given hold effect. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_IfItemEffect(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - int v2; - int v3; - u16 v4; - int v5; - - BattleScript_Iter(param1, 1); + BattleScript_Iter(battleCtx, 1); + int op = BattleScript_Read(battleCtx); + int inBattler = BattleScript_Read(battleCtx); + int effect = BattleScript_Read(battleCtx); + int jumpIfTrue = BattleScript_Read(battleCtx); - v1 = BattleScript_Read(param1); - v2 = BattleScript_Read(param1); - v5 = BattleScript_Read(param1); - v3 = BattleScript_Read(param1); - v0 = BattleScript_Battler(param0, param1, v2); + int battler = BattleScript_Battler(battleSys, battleCtx, inBattler); - if (v1 == 0) { - if (Battler_HeldItemEffect(param1, v0) == v5) { - BattleScript_Iter(param1, v3); - } - } else { - if (Battler_HeldItemEffect(param1, v0) != v5) { - BattleScript_Iter(param1, v3); + if (op == CHECK_HAVE) { + if (Battler_HeldItemEffect(battleCtx, battler) == effect) { + BattleScript_Iter(battleCtx, jumpIfTrue); } + } else if (Battler_HeldItemEffect(battleCtx, battler) != effect) { + BattleScript_Iter(battleCtx, jumpIfTrue); } - return 0; + return FALSE; } static BOOL ov16_02247950 (BattleSystem * param0, BattleContext * param1) diff --git a/src/overlay016/ov16_0225177C.c b/src/overlay016/ov16_0225177C.c index c39239ff03..ca330e9ae7 100644 --- a/src/overlay016/ov16_0225177C.c +++ b/src/overlay016/ov16_0225177C.c @@ -112,7 +112,7 @@ void BattleSystem_SortMonsBySpeed(BattleSystem * param0, BattleContext * param1) BOOL BattleSystem_FailsInHighGravity(BattleSystem * param0, BattleContext * param1, int param2, int param3); BOOL BattleSystem_HealBlocked(BattleSystem * param0, BattleContext * param1, int param2, int param3); void BattleSystem_UpdateLastResort(BattleSystem * param0, BattleContext * param1); -int ov16_02256128(BattleSystem * param0, BattleContext * param1, int param2); +int Battler_CountMoves(BattleSystem *battleSys, BattleContext *battleCtx, int battler); int BattleSystem_CheckImmunityAbilities(BattleContext * param0, int param1, int param2); BOOL BattleSystem_TriggerTurnEndAbility(BattleSystem * param0, BattleContext * param1, int param2); int BattleSystem_Divide(int dividend, int divisor); @@ -3525,17 +3525,16 @@ void BattleSystem_UpdateLastResort (BattleSystem * param0, BattleContext * param param1->battleMons[param1->attacker].moveEffectsData.lastResortCount++; } -int ov16_02256128 (BattleSystem * param0, BattleContext * param1, int param2) +int Battler_CountMoves(BattleSystem *battleSys, BattleContext *battleCtx, int battler) { - int v0; - - for (v0 = 0; v0 < 4; v0++) { - if (param1->battleMons[param2].moves[v0] == 0) { + int i; + for (i = 0; i < LEARNED_MOVES_MAX; i++) { + if (battleCtx->battleMons[battler].moves[i] == MOVE_NONE) { break; } } - return v0; + return i; } static u16 Unk_ov16_02270B8C[] = { @@ -3994,7 +3993,7 @@ int BattleSystem_ShowMonChecks (BattleSystem * param0, BattleContext * param1) v3 = 1; } else if (v20) { v15 = BattleSystem_RandomOpponent(param0, param1, v4); - v16 = ov16_02256128(param0, param1, v15); + v16 = Battler_CountMoves(param0, param1, v15); param1->msgMoveTemp = param1->battleMons[v15].moves[BattleSystem_RandNext(param0) % v16]; param1->msgBattlerTemp = v4; From 4926316055ea705fc1e1d5c7cfa5f8c6b8f469a2 Mon Sep 17 00:00:00 2001 From: lhearachel Date: Sun, 29 Oct 2023 20:18:36 -0700 Subject: [PATCH 2/3] Document BattleSystem_PluckBerry + _FlingItem and related functions --- include/constants/flavor.h | 14 + include/constants/items.h | 57 + .../narc_files/battle_skill_subseq.h | 24 +- include/overlay016/ov16_0225177C.h | 104 +- res/items/pl_item_data.csv | 6 +- src/overlay014/ov14_0221FC20.c | 2 +- src/overlay016/battle_script.c | 4 +- src/overlay016/ov16_0225177C.c | 1123 +++++++++-------- 8 files changed, 786 insertions(+), 548 deletions(-) create mode 100644 include/constants/flavor.h diff --git a/include/constants/flavor.h b/include/constants/flavor.h new file mode 100644 index 0000000000..bb74fbdb6c --- /dev/null +++ b/include/constants/flavor.h @@ -0,0 +1,14 @@ +#ifndef POKEPLATINUM_CONSTANTS_FLAVOR_H +#define POKEPLATINUM_CONSTANTS_FLAVOR_H + +enum { + FLAVOR_SPICY = 0, + FLAVOR_DRY, + FLAVOR_SWEET, + FLAVOR_BITTER, + FLAVOR_SOUR, + + FLAVOR_MAX, +}; + +#endif // POKEPLATINUM_CONSTANTS_FLAVOR_H diff --git a/include/constants/items.h b/include/constants/items.h index 323ff90711..e2b9012a8a 100644 --- a/include/constants/items.h +++ b/include/constants/items.h @@ -190,6 +190,63 @@ enum { #define HOLD_EFFECT_EVOLVE_PORYGON2 145 #define HOLD_EFFECT_EVOLVE_DUSCLOPS 146 +#define FLING_EFFECT_NONE 0 +#define FLING_EFFECT_PRZ_RESTORE 1 +#define FLING_EFFECT_SLP_RESTORE 2 +#define FLING_EFFECT_PSN_RESTORE 3 +#define FLING_EFFECT_BRN_RESTORE 4 +#define FLING_EFFECT_FRZ_RESTORE 5 +#define FLING_EFFECT_PP_RESTORE 6 +#define FLING_EFFECT_HP_RESTORE 7 +#define FLING_EFFECT_CNF_RESTORE 8 +#define FLING_EFFECT_ALL_RESTORE 9 +#define FLING_EFFECT_HP_PCT_RESTORE 10 +#define FLING_EFFECT_HP_RESTORE_SPICY 11 +#define FLING_EFFECT_HP_RESTORE_DRY 12 +#define FLING_EFFECT_HP_RESTORE_SWEET 13 +#define FLING_EFFECT_HP_RESTORE_BITTER 14 +#define FLING_EFFECT_HP_RESTORE_SOUR 15 +#define FLING_EFFECT_ATK_UP 16 +#define FLING_EFFECT_DEF_UP 17 +#define FLING_EFFECT_SPEED_UP 18 +#define FLING_EFFECT_SPATK_UP 19 +#define FLING_EFFECT_SPDEF_UP 20 +#define FLING_EFFECT_CRIT_UP 21 +#define FLING_EFFECT_RANDOM_UP2 22 +#define FLING_EFFECT_TEMP_ACC_UP 23 +#define FLING_EFFECT_STATDOWN_RESTORE 24 +#define FLING_EFFECT_HEAL_INFATUATION 25 +#define FLING_EFFECT_FLINCH 26 +#define FLING_EFFECT_PARALYZE 27 +#define FLING_EFFECT_POISON 28 +#define FLING_EFFECT_BADLY_POISON 29 +#define FLING_EFFECT_BURN 30 + +#define PLUCK_EFFECT_NONE 0 +#define PLUCK_EFFECT_PRZ_RESTORE 1 +#define PLUCK_EFFECT_SLP_RESTORE 2 +#define PLUCK_EFFECT_PSN_RESTORE 3 +#define PLUCK_EFFECT_BRN_RESTORE 4 +#define PLUCK_EFFECT_FRZ_RESTORE 5 +#define PLUCK_EFFECT_PP_RESTORE 6 +#define PLUCK_EFFECT_HP_RESTORE 7 +#define PLUCK_EFFECT_CNF_RESTORE 8 +#define PLUCK_EFFECT_ALL_RESTORE 9 +#define PLUCK_EFFECT_HP_PCT_RESTORE 10 +#define PLUCK_EFFECT_HP_RESTORE_SPICY 11 +#define PLUCK_EFFECT_HP_RESTORE_DRY 12 +#define PLUCK_EFFECT_HP_RESTORE_SWEET 13 +#define PLUCK_EFFECT_HP_RESTORE_BITTER 14 +#define PLUCK_EFFECT_HP_RESTORE_SOUR 15 +#define PLUCK_EFFECT_ATK_UP 16 +#define PLUCK_EFFECT_DEF_UP 17 +#define PLUCK_EFFECT_SPEED_UP 18 +#define PLUCK_EFFECT_SPATK_UP 19 +#define PLUCK_EFFECT_SPDEF_UP 20 +#define PLUCK_EFFECT_CRIT_UP 21 +#define PLUCK_EFFECT_RANDOM_UP2 22 +#define PLUCK_EFFECT_TEMP_ACC_UP 23 + #define ITEM_NONE 0 // Balls diff --git a/include/constants/narc_files/battle_skill_subseq.h b/include/constants/narc_files/battle_skill_subseq.h index 3c33321a69..3d65cd9357 100644 --- a/include/constants/narc_files/battle_skill_subseq.h +++ b/include/constants/narc_files/battle_skill_subseq.h @@ -43,6 +43,8 @@ enum NARCFilesBattleSubSeq { BATTLE_SUBSEQ_TRAINER_MESSAGE, BATTLE_SUBSEQ_NO_PP, + BATTLE_SUBSEQ_BADLY_POISON = 47, + BATTLE_SUBSEQ_MOVE_EFFECT_END = 50, BATTLE_SUBSEQ_THRASH_END, @@ -108,9 +110,22 @@ enum NARCFilesBattleSubSeq { BATTLE_SUBSEQ_AFTERMATH = 193, - BATTLE_SUBSEQ_HELD_ITEM_RESTORE_HP = 198, - - BATTLE_SUBSEQ_RESTORE_A_LITTLE_HP = 213, + BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE = 198, + BATTLE_SUBSEQ_HELD_ITEM_PRZ_RESTORE, + BATTLE_SUBSEQ_HELD_ITEM_SLP_RESTORE, + BATTLE_SUBSEQ_HELD_ITEM_PSN_RESTORE, + BATTLE_SUBSEQ_HELD_ITEM_BRN_RESTORE, + BATTLE_SUBSEQ_HELD_ITEM_FRZ_RESTORE, + BATTLE_SUBSEQ_HELD_ITEM_PP_RESTORE, + BATTLE_SUBSEQ_HELD_ITEM_CNF_RESTORE, + BATTLE_SUBSEQ_HELD_ITEM_MULTI_RESTORE, + BATTLE_SUBSEQ_HELD_ITEM_DISLIKE_FLAVOR, + BATTLE_SUBSEQ_HELD_ITEM_RAISE_STAT, + BATTLE_SUBSEQ_HELD_ITEM_RAISE_CRIT, + BATTLE_SUBSEQ_HELD_ITEM_SHARPLY_RAISE_STAT, + BATTLE_SUBSEQ_HELD_ITEM_STATDOWN_RESTORE, + BATTLE_SUBSEQ_HELD_ITEM_HEAL_INFATUATION, + BATTLE_SUBSEQ_RESTORE_A_LITTLE_HP, BATTLE_SUBSEQ_LOSE_HP_FROM_ITEM, BATTLE_SUBSEQ_TRANSFER_STICKY_BARB = 216, @@ -149,7 +164,8 @@ enum NARCFilesBattleSubSeq { BATTLE_SUBSEQ_BAD_DREAMS = 263, - BATTLE_SUBSEQ_HELD_ITEM_RECOIL_WHEN_HIT = 266, + BATTLE_SUBSEQ_HELD_ITEM_TEMP_ACC_UP = 265, + BATTLE_SUBSEQ_HELD_ITEM_RECOIL_WHEN_HIT, BATTLE_SUBSEQ_USE_POTION, BATTLE_SUBSEQ_USE_STATUS_RECOVERY, BATTLE_SUBSEQ_USE_STAT_BOOSTER, diff --git a/include/overlay016/ov16_0225177C.h b/include/overlay016/ov16_0225177C.h index 405e57bb2f..0cdf8d7aeb 100644 --- a/include/overlay016/ov16_0225177C.h +++ b/include/overlay016/ov16_0225177C.h @@ -238,7 +238,15 @@ int BattleMon_Get(BattleContext *battleCtx, int battler, enum BattleMonParam par */ void BattleMon_Set(BattleContext *battleCtx, int battler, enum BattleMonParam paramID, const void *buf); void ov16_02252A14(BattleContext * param0, int param1, int param2, int param3); -void ov16_02252A2C(BattleMon * param0, int param1, int param2); + +/** + * @brief Add a value to a Pokemon's data field. + * + * @param mon + * @param paramID ID of the field which should be modified + * @param val Value to be added to the Pokemon's data field + */ +void BattleMon_AddVal(BattleMon *mon, enum BattleMonParam paramID, int val); u8 BattleSystem_CompareBattlerSpeed(BattleSystem * param0, BattleContext * param1, int param2, int param3, int param4); void BattleSystem_NoExpGain(BattleContext * param0, int param1); void BattleSystem_FlagExpGain(BattleSystem * param0, BattleContext * param1, int param2); @@ -529,22 +537,102 @@ u16 Battler_HeldItem(BattleContext *battleCtx, int battler); BOOL Battler_MovedThisTurn(BattleContext * param0, int param1); BOOL BattleSystem_TriggerHeldItemOnHit(BattleSystem * param0, BattleContext * param1, int * param2); s32 Battler_HeldItemEffect(BattleContext * param0, int param1); -s32 Battler_HeldItemPower(BattleContext * param0, int param1, int param2); + +enum HeldItemPowerOp { + ITEM_POWER_CHECK_ALL = 0, //< Check all possible effects which would suppress a battler's held item. + ITEM_POWER_CHECK_NONE, //< Perform no suppression checks; always return the item's power. + ITEM_POWER_CHECK_EMBARGO, //< Check if Embargo is active; if so, return 0 power. +}; + +/** + * @brief Get the power of the battler's held item. + * + * This routine optionally can perform a series of checks for effects which + * would suppress the held item. + * + * @param battleCtx + * @param battler + * @param opcode Opcode controlling the behavior of this subroutine. + * @return The power of the battler's held item. + */ +s32 Battler_HeldItemPower(BattleContext *battleCtx, int battler, enum HeldItemPowerOp opcode); s32 ov16_02258B18(BattleContext * param0, int param1); s32 ov16_02258B2C(BattleContext * param0, int param1); -s32 ov16_02258B40(BattleContext * param0, int param1); -s32 ov16_02258B58(BattleContext * param0, int param1); -s32 ov16_02258B80(BattleContext * param0, int param1); + +/** + * @brief Get the Pluck effect of the battler's held item. + * + * @param battleCtx + * @param battler + * @return Pluck effect of the battler's held item. + */ +s32 Battler_ItemPluckEffect(BattleContext *battleCtx, int battler); + +/** + * @brief Get the Fling effect of the battler's held item. + * + * @param battleCtx + * @param battler + * @return Fling effect of the battler's held item. + */ +s32 Battler_ItemFlingEffect(BattleContext *battleCtx, int battler); + +/** + * @brief Get the Fling power of the battler's held item. + * + * @param battleCtx + * @param battler + * @return Fling power of the battler's held item. + */ +s32 Battler_ItemFlingPower(BattleContext *battleCtx, int battler); int BattleSystem_CanSwitch(BattleSystem *battleSys, BattleContext *battleCtx, int battler); -BOOL ov16_02258CB4(BattleSystem * param0, BattleContext * param1, int param2); -BOOL ov16_02259204(BattleSystem * param0, BattleContext * param1, int param2); + +/** + * @brief Try to Pluck the given battler's berry. + * + * This routine will determine what subsequence should be run as the stolen + * effect (if any) and store it in battleCtx->scriptTemp. It will also update + * the attacker's self-turn status flags to denote that the attacker has + * Plucked a berry. + * + * @param battleSys + * @param battleCtx + * @param battler The battler whose berry is to be Plucked. + * @return TRUE if a follow-up subsequence should be run to apply the berry's + * Pluck effect; FALSE if no such follow-up is needed. + */ +BOOL BattleSystem_PluckBerry(BattleSystem *battleSys, BattleContext *battleCtx, int battler); + +/** + * @brief Try to Fling the attacker's item at the given battler. + * + * This routine will determine what subsequence should be run as the flung + * effect (if any) and store it in battleCtx->flingScript. It will also + * determine the base power of Fling, as specified in the item data, and + * store it in battleCtx->movePower. + * + * @param battleSys + * @param battleCtx + * @param battler The target of the flung item. + * @return TRUE if a follow-up subsequence should be run to apply the item's + * Fling effect; FALSE if no such follow-up is needed. + */ +BOOL BattleSystem_FlingItem(BattleSystem * param0, BattleContext * param1, int param2); void BattleSystem_UpdateMetronomeCount(BattleSystem * param0, BattleContext * param1); void BattleSystem_VerifyMetronomeCount(BattleSystem * param0, BattleContext * param1); int ov16_022599D0(BattleContext * param0, int param1, int param2, int param3); BOOL BattleSystem_CanPickCommand(BattleContext *battleSys, int battler); void ov16_02259A5C(BattleSystem * param0, BattleContext * param1, Pokemon * param2); u8 BattleContext_IOBufferVal(BattleContext *battleCtx, int battler); -BOOL Battler_BehindSubstitute(BattleContext * param0, int param1); + +/** + * @brief Check if a battler's substitute was hit. + * + * @param battleCtx + * @param battler + * @return TRUE if the battler's substitute was hit, FALSE if not. + */ +BOOL Battler_SubstituteWasHit(BattleContext *battleCtx, int battler); BOOL BattleSystem_TrainerIsOT(BattleSystem * param0, BattleContext * param1); BOOL BattleSystem_PokemonIsOT(BattleSystem * param0, Pokemon * param1); BOOL BattleSystem_UpdateWeatherForms(BattleSystem * param0, BattleContext * param1, int * param2); diff --git a/res/items/pl_item_data.csv b/res/items/pl_item_data.csv index 9aad7fdef6..358ea89afd 100644 --- a/res/items/pl_item_data.csv +++ b/res/items/pl_item_data.csv @@ -50,11 +50,11 @@ ITEM_IRON,9800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0, ITEM_CARBOS,9800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,0,false,false,false,false,false,false,false,false,true,false,false,true,true,true,0,0,0,10,0,0,0,0,5,3,2 ITEM_CALCIUM,9800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,0,false,false,false,false,false,false,false,false,false,true,false,true,true,true,0,0,0,0,10,0,0,0,5,3,2 ITEM_RARE_CANDY,4800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,1,false,false,false,false,false,false,false,false,true,false,true,false,0,0,0,0,0,0,0,false,false,false,false,false,false,false,false,false,false,false,true,true,true,0,0,0,0,0,0,0,0,5,3,2 -ITEM_ppUp,9800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,0,true,false,false,false,false,false,false,false,false,false,false,true,true,true,0,0,0,0,0,0,0,0,5,3,2 +ITEM_PP_UP,9800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,0,true,false,false,false,false,false,false,false,false,false,false,true,true,true,0,0,0,0,0,0,0,0,5,3,2 ITEM_ZINC,9800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,0,false,false,false,false,false,false,false,false,false,false,true,true,true,true,0,0,0,0,0,10,0,0,5,3,2 -ITEM_ppMax,9800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,0,false,true,false,false,false,false,false,false,false,false,false,true,true,true,0,0,0,0,0,0,0,0,5,3,2 +ITEM_PP_MAX,9800,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,0,1,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,0,false,true,false,false,false,false,false,false,false,false,false,true,true,true,0,0,0,0,0,0,0,0,5,3,2 ITEM_OLD_GATEAU,200,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_MEDICINE,8,1,2,1,true,true,true,true,true,true,false,false,false,false,false,false,0,0,0,0,0,0,0,false,false,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,0,0,0,0,0 -ITEM_guardSpec_,700,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_BATTLE_ITEMS,2,0,0,1,false,false,false,false,false,false,false,true,false,false,false,false,0,0,0,0,0,0,0,false,false,false,false,false,false,false,false,false,false,false,true,true,false,0,0,0,0,0,0,0,0,1,1,0 +ITEM_GUARD_SPEC,700,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_BATTLE_ITEMS,2,0,0,1,false,false,false,false,false,false,false,true,false,false,false,false,0,0,0,0,0,0,0,false,false,false,false,false,false,false,false,false,false,false,true,true,false,0,0,0,0,0,0,0,0,1,1,0 ITEM_DIRE_HIT,650,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_BATTLE_ITEMS,2,0,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,0,0,0,0,0,1,false,false,false,false,false,false,false,false,false,false,false,true,true,false,0,0,0,0,0,0,0,0,1,1,0 ITEM_X_ATTACK,500,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_BATTLE_ITEMS,2,0,0,1,false,false,false,false,false,false,false,false,false,false,false,false,1,0,0,0,0,0,0,false,false,false,false,false,false,false,false,false,false,false,true,true,false,0,0,0,0,0,0,0,0,1,1,0 ITEM_X_DEFENSE,550,HOLD_EFFECT_NONE,0,0,0,30,0,31,false,false,POCKET_BATTLE_ITEMS,2,0,0,1,false,false,false,false,false,false,false,false,false,false,false,false,0,1,0,0,0,0,0,false,false,false,false,false,false,false,false,false,false,false,true,true,false,0,0,0,0,0,0,0,0,1,1,0 diff --git a/src/overlay014/ov14_0221FC20.c b/src/overlay014/ov14_0221FC20.c index 1fcd1f031f..3d86667f39 100644 --- a/src/overlay014/ov14_0221FC20.c +++ b/src/overlay014/ov14_0221FC20.c @@ -2286,7 +2286,7 @@ static void ov14_02221EBC (BattleSystem * param0, BattleContext * param1) v1 = ov14_02222CF0(param1); v0 = ov14_02222D34(param1, v1); - param1->aiContext.calcTemp = ov16_02258B80(param1, v0); + param1->aiContext.calcTemp = Battler_ItemFlingPower(param1, v0); } static void ov14_02221EEC (BattleSystem * param0, BattleContext * param1) diff --git a/src/overlay016/battle_script.c b/src/overlay016/battle_script.c index 2410926456..3168f7fe9a 100644 --- a/src/overlay016/battle_script.c +++ b/src/overlay016/battle_script.c @@ -8518,7 +8518,7 @@ static BOOL ov16_02247B28 (BattleSystem * param0, BattleContext * param1) if ((param1->battleMons[param1->defender].heldItem) && (Battler_IgnorableAbility(param1, param1->attacker, param1->defender, 60) == 1)) { BattleScript_Iter(param1, v0); - } else if (((param1->battleMons[param1->defender].heldItem) && (param1->battleMons[param1->defender].moveEffectsData.custapBerry)) || (ov16_02258CB4(param0, param1, param1->defender) != 1)) { + } else if (((param1->battleMons[param1->defender].heldItem) && (param1->battleMons[param1->defender].moveEffectsData.custapBerry)) || (BattleSystem_PluckBerry(param0, param1, param1->defender) != 1)) { BattleScript_Iter(param1, v1); } @@ -8533,7 +8533,7 @@ static BOOL ov16_02247BA4 (BattleSystem * param0, BattleContext * param1) v0 = BattleScript_Read(param1); - if (ov16_02259204(param0, param1, param1->attacker) != 1) { + if (BattleSystem_FlingItem(param0, param1, param1->attacker) != 1) { BattleScript_Iter(param1, v0); } diff --git a/src/overlay016/ov16_0225177C.c b/src/overlay016/ov16_0225177C.c index ca330e9ae7..55b15e2b70 100644 --- a/src/overlay016/ov16_0225177C.c +++ b/src/overlay016/ov16_0225177C.c @@ -3,6 +3,7 @@ #include "constants/abilities.h" #include "constants/battle.h" +#include "constants/flavor.h" #include "constants/gender.h" #include "constants/heap.h" #include "constants/items.h" @@ -62,7 +63,7 @@ void BattleIO_ClearBuffer(BattleContext *battleCtx, int battler); int BattleMon_Get(BattleContext *battleCtx, int battler, enum BattleMonParam paramID, void *buf); void BattleMon_Set(BattleContext *battleCtx, int battler, enum BattleMonParam param, const void *buf); void ov16_02252A14(BattleContext * param0, int param1, int param2, int param3); -void ov16_02252A2C(BattleMon * param0, int param1, int param2); +void BattleMon_AddVal(BattleMon *mon, enum BattleMonParam paramID, int val); u8 BattleSystem_CompareBattlerSpeed(BattleSystem * param0, BattleContext * param1, int param2, int param3, int param4); void BattleSystem_NoExpGain(BattleContext * param0, int param1); void BattleSystem_FlagExpGain(BattleSystem * param0, BattleContext * param1, int param2); @@ -130,22 +131,22 @@ u16 Battler_HeldItem(BattleContext *battleCtx, int battler); BOOL Battler_MovedThisTurn(BattleContext * param0, int param1); BOOL BattleSystem_TriggerHeldItemOnHit(BattleSystem * param0, BattleContext * param1, int * param2); s32 Battler_HeldItemEffect(BattleContext * param0, int param1); -s32 Battler_HeldItemPower(BattleContext * param0, int param1, int param2); +s32 Battler_HeldItemPower(BattleContext *battleCtx, int battler, enum HeldItemPowerOp opcode); s32 ov16_02258B18(BattleContext * param0, int param1); s32 ov16_02258B2C(BattleContext * param0, int param1); -s32 ov16_02258B40(BattleContext * param0, int param1); -s32 ov16_02258B58(BattleContext * param0, int param1); -s32 ov16_02258B80(BattleContext * param0, int param1); +s32 Battler_ItemPluckEffect(BattleContext *battleCtx, int battler); +s32 Battler_ItemFlingEffect(BattleContext *battleCtx, int battler); +s32 Battler_ItemFlingPower(BattleContext *battleCtx, int battler); int BattleSystem_CanSwitch(BattleSystem *battleSys, BattleContext *battleCtx, int battler); -BOOL ov16_02258CB4(BattleSystem * param0, BattleContext * param1, int param2); -BOOL ov16_02259204(BattleSystem * param0, BattleContext * param1, int param2); +BOOL BattleSystem_PluckBerry(BattleSystem *battleSys, BattleContext *battleCtx, int battler); +BOOL BattleSystem_FlingItem(BattleSystem * param0, BattleContext * param1, int param2); void BattleSystem_UpdateMetronomeCount(BattleSystem * param0, BattleContext * param1); void BattleSystem_VerifyMetronomeCount(BattleSystem * param0, BattleContext * param1); int ov16_022599D0(BattleContext * param0, int param1, int param2, int param3); BOOL BattleSystem_CanPickCommand(BattleContext *battleSys, int battler); void ov16_02259A5C(BattleSystem * param0, BattleContext * param1, Pokemon * param2); u8 BattleContext_IOBufferVal(BattleContext *battleCtx, int battler); -BOOL Battler_BehindSubstitute(BattleContext * param0, int param1); +BOOL Battler_SubstituteWasHit(BattleContext *battleCtx, int battler); BOOL BattleSystem_TrainerIsOT(BattleSystem * param0, BattleContext * param1); BOOL BattleSystem_PokemonWasTraded(BattleSystem * param0, Pokemon * param1); BOOL BattleSystem_UpdateWeatherForms(BattleSystem * param0, BattleContext * param1, int * param2); @@ -1061,189 +1062,220 @@ void BattleMon_Set(BattleContext *battleCtx, int battler, enum BattleMonParam pa void ov16_02252A14 (BattleContext * param0, int param1, int param2, int param3) { - ov16_02252A2C(¶m0->battleMons[param1], param2, param3); + BattleMon_AddVal(¶m0->battleMons[param1], param2, param3); } -void ov16_02252A2C (BattleMon * param0, int param1, int param2) +void BattleMon_AddVal(BattleMon *mon, enum BattleMonParam paramID, int val) { - int v0; - - switch (param1) { - case 1: - param0->attack += param2; + switch (paramID) { + case BATTLEMON_ATTACK: + mon->attack += val; break; - case 2: - param0->defense += param2; + + case BATTLEMON_DEFENSE: + mon->defense += val; break; - case 3: - param0->speed += param2; + + case BATTLEMON_SPEED: + mon->speed += val; break; - case 4: - param0->spAttack += param2; + + case BATTLEMON_SP_ATTACK: + mon->spAttack += val; break; - case 5: - param0->spDefense += param2; + + case BATTLEMON_SP_DEFENSE: + mon->spDefense += val; break; - case 10: - param0->hpIV += param2; + + case BATTLEMON_HP_IV: + mon->hpIV += val; break; - case 11: - param0->attackIV += param2; + + case BATTLEMON_ATTACK_IV: + mon->attackIV += val; break; - case 12: - param0->defenseIV += param2; + + case BATTLEMON_DEFENSE_IV: + mon->defenseIV += val; break; - case 13: - param0->speedIV += param2; + + case BATTLEMON_SPEED_IV: + mon->speedIV += val; break; - case 14: - param0->spAttackIV += param2; + + case BATTLEMON_SP_ATTACK_IV: + mon->spAttackIV += val; break; - case 15: - param0->spDefenseIV += param2; + + case BATTLEMON_SP_DEFENSE_IV: + mon->spDefenseIV += val; break; - case 18: - case 19: - case 20: - case 21: - case 22: - case 23: - case 24: - case 25: - if (param0->statBoosts[param1 - 18] + param2 < 0) { - param0->statBoosts[param1 - 18] = 0; - } else if (param0->statBoosts[param1 - 18] + param2 > 12) { - param0->statBoosts[param1 - 18] = 12; + + case BATTLEMON_HP_STAGE: + case BATTLEMON_ATTACK_STAGE: + case BATTLEMON_DEFENSE_STAGE: + case BATTLEMON_SPEED_STAGE: + case BATTLEMON_SP_ATTACK_STAGE: + case BATTLEMON_SP_DEFENSE_STAGE: + case BATTLEMON_ACCURACY_STAGE: + case BATTLEMON_EVASION_STAGE: + if (mon->statBoosts[paramID - BATTLEMON_HP_STAGE] + val < 0) { + mon->statBoosts[paramID - BATTLEMON_HP_STAGE] = 0; + } else if (mon->statBoosts[paramID - BATTLEMON_HP_STAGE] + val > 12) { + mon->statBoosts[paramID - BATTLEMON_HP_STAGE] = 12; } else { - param0->statBoosts[param1 - 18] += param2; + mon->statBoosts[paramID - BATTLEMON_HP_STAGE] += val; } break; - case 31: - case 32: - case 33: - case 34: - { - int v1; - v1 = MoveTable_CalcMaxPP(param0->moves[param1 - 31], param0->ppUps[param1 - 31]); - - if (param0->ppCur[param1 - 31] + param2 > v1) { - param0->ppCur[param1 - 31] = v1; + case BATTLEMON_CUR_PP_1: + case BATTLEMON_CUR_PP_2: + case BATTLEMON_CUR_PP_3: + case BATTLEMON_CUR_PP_4: + int maxPP = MoveTable_CalcMaxPP(mon->moves[paramID - BATTLEMON_CUR_PP_1], mon->ppUps[paramID - BATTLEMON_CUR_PP_1]); + if (mon->ppCur[paramID - BATTLEMON_CUR_PP_1] + val > maxPP) { + mon->ppCur[paramID - BATTLEMON_CUR_PP_1] = maxPP; } else { - param0->ppCur[param1 - 31] += param2; + mon->ppCur[paramID - BATTLEMON_CUR_PP_1] += val; } - } - break; - case 35: - case 36: - case 37: - case 38: - param0->ppUps[param1 - 35] += param2; break; - case 43: - param0->level += param2; + + case BATTLEMON_PP_UPS_1: + case BATTLEMON_PP_UPS_2: + case BATTLEMON_PP_UPS_3: + case BATTLEMON_PP_UPS_4: + mon->ppUps[paramID - BATTLEMON_PP_UPS_1] += val; + break; + + case BATTLEMON_LEVEL: + mon->level += val; break; - case 44: - { - int v2; - v2 = param0->friendship; + case BATTLEMON_FRIENDSHIP: + int friendship = mon->friendship; - if ((v2 + param2) > 255) { - v2 = 255; - } else if ((v2 + param2) < 0) { - v2 = 0; + if (friendship + val > 255) { + friendship = 255; + } else if (friendship + val < 0) { + friendship = 0; } else { - v2 += param2; + friendship += val; } - param0->friendship = v2; - } - break; - case 47: - if (param0->curHP + param2 > param0->maxHP) { - param0->curHP = param0->maxHP; + mon->friendship = friendship; + break; + + case BATTLEMON_CUR_HP: + if (mon->curHP + val > mon->maxHP) { + mon->curHP = mon->maxHP; } else { - param0->curHP += param2; + mon->curHP += val; } break; - case 48: - param0->maxHP += param2; + + case BATTLEMON_MAX_HP: + mon->maxHP += val; break; - case 50: - param0->exp += param2; + + case BATTLEMON_EXP: + mon->exp += val; break; - case 51: - param0->personality += param2; + + case BATTLEMON_PERSONALITY: + mon->personality += val; break; - case 61: - param0->moveEffectsData.disabledTurns += param2; + + case BATTLEMON_DISABLED_TURNS: + mon->moveEffectsData.disabledTurns += val; break; - case 62: - param0->moveEffectsData.encoredTurns += param2; + + case BATTLEMON_ENCORED_TURNS: + mon->moveEffectsData.encoredTurns += val; break; - case 63: - param0->moveEffectsData.chargedTurns += param2; + + case BATTLEMON_CHARGED_TURNS: + mon->moveEffectsData.chargedTurns += val; break; - case 64: - param0->moveEffectsData.tauntedTurns += param2; + + case BATTLEMON_TAUNTED_TURNS: + mon->moveEffectsData.tauntedTurns += val; break; - case 65: - param0->moveEffectsData.protectSuccessTurns += param2; + + case BATTLEMON_SUCCESSFUL_PROTECT_TURNS: + mon->moveEffectsData.protectSuccessTurns += val; break; - case 66: - param0->moveEffectsData.perishSongTurns += param2; + + case BATTLEMON_PERISH_SONG_TURNS: + mon->moveEffectsData.perishSongTurns += val; break; - case 67: - param0->moveEffectsData.rolloutCount += param2; + + case BATTLEMON_ROLLOUT_COUNT: + mon->moveEffectsData.rolloutCount += val; break; - case 68: - param0->moveEffectsData.furyCutterCount += param2; + + case BATTLEMON_FURY_CUTTER_COUNT: + mon->moveEffectsData.furyCutterCount += val; break; - case 69: - param0->moveEffectsData.stockpileCount += param2; + + case BATTLEMON_STOCKPILE_COUNT: + mon->moveEffectsData.stockpileCount += val; break; - case 70: - param0->moveEffectsData.stockpileDefBoosts += param2; + + case BATTLEMON_STOCKPILE_DEF_BOOSTS: + mon->moveEffectsData.stockpileDefBoosts += val; break; - case 71: - param0->moveEffectsData.stockpileSpDefBoosts += param2; + + case BATTLEMON_STOCKPILE_SPDEF_BOOSTS: + mon->moveEffectsData.stockpileSpDefBoosts += val; break; - case 78: - param0->moveEffectsData.lastResortCount += param2; + + case BATTLEMON_LAST_RESORT_COUNT: + mon->moveEffectsData.lastResortCount += val; break; - case 79: - param0->moveEffectsData.magnetRiseTurns += param2; + + case BATTLEMON_MAGNET_RISE_TURNS: + mon->moveEffectsData.magnetRiseTurns += val; break; - case 80: - param0->moveEffectsData.healBlockTurns += param2; + + case BATTLEMON_HEAL_BLOCK_TURNS: + mon->moveEffectsData.healBlockTurns += val; break; - case 87: - param0->moveEffectsData.rechargeTurnNumber += param2; + + case BATTLEMON_RECHARGE_TURN_NUMBER: + mon->moveEffectsData.rechargeTurnNumber += val; break; - case 88: - param0->moveEffectsData.fakeOutTurnNumber += param2; + + case BATTLEMON_FAKE_OUT_TURN_NUMBER: + mon->moveEffectsData.fakeOutTurnNumber += val; break; - case 89: - param0->moveEffectsData.slowStartTurnNumber += param2; + + case BATTLEMON_SLOW_START_TURN_NUMBER: + mon->moveEffectsData.slowStartTurnNumber += val; break; - case 90: - param0->moveEffectsData.substituteHP += param2; + + case BATTLEMON_SUBSTITUTE_HP: + mon->moveEffectsData.substituteHP += val; break; - case 95: - param0->moveEffectsData.itemHPRecovery += param2; + + case BATTLEMON_ITEM_HP_RECOVERY: + mon->moveEffectsData.itemHPRecovery += val; break; - case 96: - param0->slowStartAnnounced += param2; + + case BATTLEMON_SLOW_START_ANNOUNCED: + mon->slowStartAnnounced += val; break; - case 97: - param0->slowStartFinished += param2; + + case BATTLEMON_SLOW_START_FINISHED: + mon->slowStartFinished += val; break; - case 98: - param0->formNum += param2; + + case BATTLEMON_FORM_NUM: + mon->formNum += val; break; + default: - GF_ASSERT(0); + GF_ASSERT(FALSE); break; } } @@ -1624,7 +1656,7 @@ BOOL BattleSystem_TriggerSecondaryEffect(BattleSystem *battleSys, BattleContext } else if (battleCtx->sideEffectIndirectFlags & MOVE_SIDE_EFFECT_CHECK_SUBSTITUTE) { SetupSideEffect(battleCtx, nextSeq, SIDE_EFFECT_SOURCE_INDIRECT); - if (Battler_BehindSubstitute(battleCtx, battleCtx->sideEffectMon) == FALSE + if (Battler_SubstituteWasHit(battleCtx, battleCtx->sideEffectMon) == FALSE && (battleCtx->moveStatusFlags & MOVE_STATUS_NO_EFFECTS) == FALSE) { result = TRUE; } @@ -1632,7 +1664,7 @@ BOOL BattleSystem_TriggerSecondaryEffect(BattleSystem *battleSys, BattleContext SetupSideEffect(battleCtx, nextSeq, SIDE_EFFECT_SOURCE_INDIRECT); if (battleCtx->battleMons[battleCtx->sideEffectMon].curHP - && Battler_BehindSubstitute(battleCtx, battleCtx->sideEffectMon) == FALSE + && Battler_SubstituteWasHit(battleCtx, battleCtx->sideEffectMon) == FALSE && (battleCtx->moveStatusFlags & MOVE_STATUS_NO_EFFECTS) == FALSE) { result = TRUE; } @@ -1674,7 +1706,7 @@ BOOL BattleSystem_TriggerSecondaryEffect(BattleSystem *battleSys, BattleContext SetupSideEffect(battleCtx, nextSeq, SIDE_EFFECT_SOURCE_INDIRECT); if (battleCtx->battleMons[battleCtx->sideEffectMon].curHP - && Battler_BehindSubstitute(battleCtx, battleCtx->sideEffectMon) == FALSE + && Battler_SubstituteWasHit(battleCtx, battleCtx->sideEffectMon) == FALSE && (battleCtx->moveStatusFlags & MOVE_STATUS_NO_EFFECTS) == FALSE) { result = TRUE; } @@ -4203,7 +4235,7 @@ BOOL BattleSystem_TriggerAbilityOnHit(BattleSystem *battleSys, BattleContext *ba return result; } - if (Battler_BehindSubstitute(battleCtx, battleCtx->defender) == TRUE) { + if (Battler_SubstituteWasHit(battleCtx, battleCtx->defender) == TRUE) { return result; } @@ -4633,7 +4665,7 @@ BOOL BattleSystem_TriggerHeldItem (BattleSystem * param0, BattleContext * param1 } if (v4 != 4) { - ov16_02252A2C(¶m1->battleMons[param2], 31 + v4, v3); + BattleMon_AddVal(¶m1->battleMons[param2], 31 + v4, v3); BattleMon_CopyToParty(param0, param1, param2); param1->msgMoveTemp = param1->battleMons[param2].moves[v4]; v1 = (0 + 204); @@ -5009,7 +5041,7 @@ BOOL BattleSystem_TriggerHeldItemOnStatus (BattleSystem * param0, BattleContext } if (v4 != 4) { - ov16_02252A2C(¶m1->battleMons[param2], 31 + v4, v3); + BattleMon_AddVal(¶m1->battleMons[param2], 31 + v4, v3); BattleMon_CopyToParty(param0, param1, param2); param1->msgMoveTemp = param1->battleMons[param2].moves[v4]; param3[0] = (0 + 204); @@ -5338,7 +5370,7 @@ BOOL BattleSystem_TriggerHeldItemOnHit (BattleSystem * battleSys, BattleContext return result; } - if (Battler_BehindSubstitute(battleCtx, battleCtx->defender) == TRUE) { + if (Battler_SubstituteWasHit(battleCtx, battleCtx->defender) == TRUE) { return result; } @@ -5384,7 +5416,7 @@ BOOL BattleSystem_TriggerHeldItemOnHit (BattleSystem * battleSys, BattleContext case HOLD_EFFECT_HP_RESTORE_SE: if (DEFENDING_MON.curHP && (battleCtx->moveStatusFlags & MOVE_STATUS_SUPER_EFFECTIVE)) { battleCtx->hpCalcTemp = BattleSystem_Divide(DEFENDING_MON.maxHP, itemPower); - *nextSeq = BATTLE_SUBSEQ_HELD_ITEM_RESTORE_HP; + *nextSeq = BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE; battleCtx->msgBattlerTemp = battleCtx->defender; battleCtx->msgItemTemp = battleCtx->battleMons[battleCtx->defender].heldItem; result = TRUE; @@ -5406,24 +5438,25 @@ s32 Battler_HeldItemEffect (BattleContext * param0, int param1) return BattleSystem_GetItemData(param0, v0, 1); } -s32 Battler_HeldItemPower (BattleContext * param0, int param1, int param2) +s32 Battler_HeldItemPower(BattleContext *battleCtx, int battler, enum HeldItemPowerOp opcode) { - u16 v0; - - switch (param2) { - case 0: - v0 = Battler_HeldItem(param0, param1); + u16 item; + switch (opcode) { + case ITEM_POWER_CHECK_ALL: + item = Battler_HeldItem(battleCtx, battler); break; - case 2: - if (param0->battleMons[param1].moveEffectsData.embargoTurns) { + + case ITEM_POWER_CHECK_EMBARGO: + if (battleCtx->battleMons[battler].moveEffectsData.embargoTurns) { return 0; } - case 1: - v0 = param0->battleMons[param1].heldItem; + + case ITEM_POWER_CHECK_NONE: + item = battleCtx->battleMons[battler].heldItem; break; } - return BattleSystem_GetItemData(param0, v0, 2); + return BattleSystem_GetItemData(battleCtx, item, ITEM_PARAM_HOLD_EFFECT_PARAM); } s32 ov16_02258B18 (BattleContext * param0, int param1) @@ -5442,33 +5475,27 @@ s32 ov16_02258B2C (BattleContext * param0, int param1) return BattleSystem_GetItemData(param0, v0, 12); } -s32 ov16_02258B40 (BattleContext * param0, int param1) +s32 Battler_ItemPluckEffect(BattleContext *battleCtx, int battler) { - u16 v0; - int v1; - - v0 = param0->battleMons[param1].heldItem; - v1 = BattleSystem_GetItemData(param0, v0, 8); - - return v1; + return BattleSystem_GetItemData(battleCtx, battleCtx->battleMons[battler].heldItem, ITEM_PARAM_PLUCK_EFFECT); } -s32 ov16_02258B58 (BattleContext * param0, int param1) +s32 Battler_ItemFlingEffect(BattleContext *battleCtx, int battler) { - if (param0->battleMons[param1].moveEffectsData.embargoTurns) { - return 0; + if (battleCtx->battleMons[battler].moveEffectsData.embargoTurns) { + return FLING_EFFECT_NONE; } - return BattleSystem_GetItemData(param0, param0->battleMons[param1].heldItem, 9); + return BattleSystem_GetItemData(battleCtx, battleCtx->battleMons[battler].heldItem, ITEM_PARAM_FLING_EFFECT); } -s32 ov16_02258B80 (BattleContext * param0, int param1) +s32 Battler_ItemFlingPower(BattleContext *battleCtx, int battler) { - if (param0->battleMons[param1].moveEffectsData.embargoTurns) { + if (battleCtx->battleMons[battler].moveEffectsData.embargoTurns) { return 0; } - return BattleSystem_GetItemData(param0, param0->battleMons[param1].heldItem, 10); + return BattleSystem_GetItemData(battleCtx, battleCtx->battleMons[battler].heldItem, ITEM_PARAM_FLING_POWER); } int BattleSystem_CanSwitch (BattleSystem *battleSys, BattleContext *battleCtx, int battler) @@ -5496,589 +5523,625 @@ int BattleSystem_CanSwitch (BattleSystem *battleSys, BattleContext *battleCtx, i return v0; } -BOOL ov16_02258CB4 (BattleSystem * param0, BattleContext * param1, int param2) +BOOL BattleSystem_PluckBerry(BattleSystem *battleSys, BattleContext *battleCtx, int battler) { - BOOL v0; - int v1; - int v2; - int v3; - - v0 = 0; - v1 = 0; - v2 = ov16_02258B40(param1, param2); - v3 = Battler_HeldItemPower(param1, param2, 1); + BOOL result = FALSE; + int nextSeq = 0; + int effect = Battler_ItemPluckEffect(battleCtx, battler); + int power = Battler_HeldItemPower(battleCtx, battler, 1); - if (Battler_BehindSubstitute(param1, param1->defender) == 1) { - return v0; + if (Battler_SubstituteWasHit(battleCtx, battleCtx->defender) == TRUE) { + return result; } - switch (v2) { - case 7: - if (param1->battleMons[param1->attacker].curHP != param1->battleMons[param1->attacker].maxHP) { - param1->hpCalcTemp = v3; - v1 = (0 + 198); + switch (effect) { + case PLUCK_EFFECT_HP_RESTORE: + if (ATTACKING_MON.curHP != ATTACKING_MON.maxHP) { + battleCtx->hpCalcTemp = power; + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE; } - v0 = 1; + result = TRUE; break; - case 10: - if (param1->battleMons[param1->attacker].curHP != param1->battleMons[param1->attacker].maxHP) { - param1->hpCalcTemp = BattleSystem_Divide(param1->battleMons[param1->attacker].maxHP * v3, 100); - v1 = (0 + 198); + + case PLUCK_EFFECT_HP_PCT_RESTORE: + if (ATTACKING_MON.curHP != ATTACKING_MON.maxHP) { + battleCtx->hpCalcTemp = BattleSystem_Divide(ATTACKING_MON.maxHP * power, 100); + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE; } - v0 = 1; + result = TRUE; break; - case 1: - if (param1->battleMons[param1->attacker].status & 0x40) { - v1 = (0 + 199); + + case PLUCK_EFFECT_PRZ_RESTORE: + if (ATTACKING_MON.status & MON_CONDITION_PARALYSIS) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_PRZ_RESTORE; } - v0 = 1; + result = TRUE; break; - case 2: - if (param1->battleMons[param1->attacker].status & 0x7) { - v1 = (0 + 200); + + case PLUCK_EFFECT_SLP_RESTORE: + if (ATTACKING_MON.status & MON_CONDITION_SLEEP) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_SLP_RESTORE; } - v0 = 1; + result = TRUE; break; - case 3: - if (param1->battleMons[param1->attacker].status & 0xf88) { - v1 = (0 + 201); + + case PLUCK_EFFECT_PSN_RESTORE: + if (ATTACKING_MON.status & MON_CONDITION_ANY_POISON) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_PSN_RESTORE; } - v0 = 1; + result = TRUE; break; - case 4: - if (param1->battleMons[param1->attacker].status & 0x10) { - v1 = (0 + 202); + + case PLUCK_EFFECT_BRN_RESTORE: + if (ATTACKING_MON.status & MON_CONDITION_BURN) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_BRN_RESTORE; } - v0 = 1; + result = TRUE; break; - case 5: - if (param1->battleMons[param1->attacker].status & 0x20) { - v1 = (0 + 203); + + case PLUCK_EFFECT_FRZ_RESTORE: + if (ATTACKING_MON.status & MON_CONDITION_FREEZE) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_FRZ_RESTORE; } - v0 = 1; + result = TRUE; break; - case 6: - { - int v4; - int v5; - int v6; - int v7; - v6 = 0; + case PLUCK_EFFECT_PP_RESTORE: { + int diff, i, maxDiff, slot; // must declare in this order to match. - for (v5 = 0; v5 < 4; v5++) { - if (param1->battleMons[param1->attacker].moves[v5]) { - v4 = MoveTable_CalcMaxPP(param1->battleMons[param1->attacker].moves[v5], param1->battleMons[param1->attacker].ppUps[v5]) - param1->battleMons[param1->attacker].ppCur[v5]; + // Find the move that has the highest difference between its current + // and maximum PP. + maxDiff = 0; + for (i = 0; i < LEARNED_MOVES_MAX; i++) { + if (ATTACKING_MON.moves[i]) { + diff = MoveTable_CalcMaxPP(ATTACKING_MON.moves[i], ATTACKING_MON.ppUps[i]) - ATTACKING_MON.ppCur[i]; - if (v4 > v6) { - v6 = v4; - v7 = v5; + if (diff > maxDiff) { + maxDiff = diff; + slot = i; } } } - ov16_02252A2C(¶m1->battleMons[param1->attacker], 31 + v7, v3); - BattleMon_CopyToParty(param0, param1, param1->attacker); - param1->msgMoveTemp = param1->battleMons[param1->attacker].moves[v7]; - v1 = (0 + 204); - } - v0 = 1; + BattleMon_AddVal(&ATTACKING_MON, BATTLEMON_CUR_PP_1 + slot, power); + BattleMon_CopyToParty(battleSys, battleCtx, battleCtx->attacker); + battleCtx->msgMoveTemp = ATTACKING_MON.moves[slot]; + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_PP_RESTORE; + + result = TRUE; break; - case 8: - if (param1->battleMons[param1->attacker].statusVolatile & 0x7) { - v1 = (0 + 205); + } + + case PLUCK_EFFECT_CNF_RESTORE: + if (ATTACKING_MON.statusVolatile & VOLATILE_CONDITION_CONFUSION) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_CNF_RESTORE; } - v0 = 1; + result = TRUE; break; - case 9: - if ((param1->battleMons[param1->attacker].status & 0xff) || (param1->battleMons[param1->attacker].statusVolatile & 0x7)) { - if (param1->battleMons[param1->attacker].status & 0x40) { - v1 = (0 + 199); + + case PLUCK_EFFECT_ALL_RESTORE: + if ((ATTACKING_MON.status & MON_CONDITION_ANY) || (ATTACKING_MON.statusVolatile & VOLATILE_CONDITION_CONFUSION)) { + if (ATTACKING_MON.status & MON_CONDITION_PARALYSIS) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_PRZ_RESTORE; } - if (param1->battleMons[param1->attacker].status & 0x7) { - v1 = (0 + 200); + if (ATTACKING_MON.status & MON_CONDITION_SLEEP) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_SLP_RESTORE; } - if (param1->battleMons[param1->attacker].status & 0xf88) { - v1 = (0 + 201); + if (ATTACKING_MON.status & MON_CONDITION_ANY_POISON) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_PSN_RESTORE; } - if (param1->battleMons[param1->attacker].status & 0x10) { - v1 = (0 + 202); + if (ATTACKING_MON.status & MON_CONDITION_BURN) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_BRN_RESTORE; } - if (param1->battleMons[param1->attacker].status & 0x20) { - v1 = (0 + 203); + if (ATTACKING_MON.status & MON_CONDITION_FREEZE) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_FRZ_RESTORE; } - if (param1->battleMons[param1->attacker].statusVolatile & 0x7) { - v1 = (0 + 205); + if (ATTACKING_MON.statusVolatile & VOLATILE_CONDITION_CONFUSION) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_CNF_RESTORE; } - if ((param1->battleMons[param1->attacker].status & 0xff) && (param1->battleMons[param1->attacker].statusVolatile & 0x7)) { - v1 = (0 + 206); + if ((ATTACKING_MON.status & MON_CONDITION_ANY) + && (ATTACKING_MON.statusVolatile & VOLATILE_CONDITION_CONFUSION)) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_MULTI_RESTORE; } } - v0 = 1; + result = TRUE; break; - case 11: - if (param1->battleMons[param1->attacker].curHP != param1->battleMons[param1->attacker].maxHP) { - param1->hpCalcTemp = BattleSystem_Divide(param1->battleMons[param1->attacker].maxHP, v3); - param1->msgTemp = 0; - if (Pokemon_GetFlavorAffinityOf(param1->battleMons[param1->attacker].personality, 0) == -1) { - v1 = (0 + 207); + case PLUCK_EFFECT_HP_RESTORE_SPICY: + if (ATTACKING_MON.curHP != ATTACKING_MON.maxHP) { + battleCtx->hpCalcTemp = BattleSystem_Divide(ATTACKING_MON.maxHP, power); + battleCtx->msgTemp = FLAVOR_SPICY; + + if (Pokemon_GetFlavorAffinityOf(ATTACKING_MON.personality, FLAVOR_SPICY) == -1) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_DISLIKE_FLAVOR; } else { - v1 = (0 + 198); + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE; } } - v0 = 1; + result = TRUE; break; - case 12: - if (param1->battleMons[param1->attacker].curHP != param1->battleMons[param1->attacker].maxHP) { - param1->hpCalcTemp = BattleSystem_Divide(param1->battleMons[param1->attacker].maxHP, v3); - param1->msgTemp = 1; - if (Pokemon_GetFlavorAffinityOf(param1->battleMons[param1->attacker].personality, 1) == -1) { - v1 = (0 + 207); + case PLUCK_EFFECT_HP_RESTORE_DRY: + if (ATTACKING_MON.curHP != ATTACKING_MON.maxHP) { + battleCtx->hpCalcTemp = BattleSystem_Divide(ATTACKING_MON.maxHP, power); + battleCtx->msgTemp = FLAVOR_DRY; + + if (Pokemon_GetFlavorAffinityOf(ATTACKING_MON.personality, FLAVOR_DRY) == -1) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_DISLIKE_FLAVOR; } else { - v1 = (0 + 198); + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE; } } - v0 = 1; + result = TRUE; break; - case 13: - if (param1->battleMons[param1->attacker].curHP != param1->battleMons[param1->attacker].maxHP) { - param1->hpCalcTemp = BattleSystem_Divide(param1->battleMons[param1->attacker].maxHP, v3); - param1->msgTemp = 2; - if (Pokemon_GetFlavorAffinityOf(param1->battleMons[param1->attacker].personality, 2) == -1) { - v1 = (0 + 207); + case PLUCK_EFFECT_HP_RESTORE_SWEET: + if (ATTACKING_MON.curHP != ATTACKING_MON.maxHP) { + battleCtx->hpCalcTemp = BattleSystem_Divide(ATTACKING_MON.maxHP, power); + battleCtx->msgTemp = FLAVOR_SWEET; + + if (Pokemon_GetFlavorAffinityOf(ATTACKING_MON.personality, FLAVOR_SWEET) == -1) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_DISLIKE_FLAVOR; } else { - v1 = (0 + 198); + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE; } } - v0 = 1; + result = TRUE; break; - case 14: - if (param1->battleMons[param1->attacker].curHP != param1->battleMons[param1->attacker].maxHP) { - param1->hpCalcTemp = BattleSystem_Divide(param1->battleMons[param1->attacker].maxHP, v3); - param1->msgTemp = 3; - if (Pokemon_GetFlavorAffinityOf(param1->battleMons[param1->attacker].personality, 3) == -1) { - v1 = (0 + 207); + case PLUCK_EFFECT_HP_RESTORE_BITTER: + if (ATTACKING_MON.curHP != ATTACKING_MON.maxHP) { + battleCtx->hpCalcTemp = BattleSystem_Divide(ATTACKING_MON.maxHP, power); + battleCtx->msgTemp = FLAVOR_BITTER; + + if (Pokemon_GetFlavorAffinityOf(ATTACKING_MON.personality, FLAVOR_BITTER) == -1) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_DISLIKE_FLAVOR; } else { - v1 = (0 + 198); + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE; } } - v0 = 1; + result = TRUE; break; - case 15: - if (param1->battleMons[param1->attacker].curHP != param1->battleMons[param1->attacker].maxHP) { - param1->hpCalcTemp = BattleSystem_Divide(param1->battleMons[param1->attacker].maxHP, v3); - param1->msgTemp = 4; - if (Pokemon_GetFlavorAffinityOf(param1->battleMons[param1->attacker].personality, 4) == -1) { - v1 = (0 + 207); + case PLUCK_EFFECT_HP_RESTORE_SOUR: + if (ATTACKING_MON.curHP != ATTACKING_MON.maxHP) { + battleCtx->hpCalcTemp = BattleSystem_Divide(ATTACKING_MON.maxHP, power); + battleCtx->msgTemp = FLAVOR_SOUR; + + if (Pokemon_GetFlavorAffinityOf(ATTACKING_MON.personality, FLAVOR_SOUR) == -1) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_DISLIKE_FLAVOR; } else { - v1 = (0 + 198); + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE; } } - v0 = 1; + result = TRUE; break; - case 16: - if (param1->battleMons[param1->attacker].statBoosts[0x1] < 12) { - param1->msgTemp = 0x1; - v1 = (0 + 208); + + case PLUCK_EFFECT_ATK_UP: + if (ATTACKING_MON.statBoosts[BATTLE_STAT_ATTACK] < 12) { + battleCtx->msgTemp = BATTLE_STAT_ATTACK; + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_RAISE_STAT; } - v0 = 1; + result = TRUE; break; - case 17: - if (param1->battleMons[param1->attacker].statBoosts[0x2] < 12) { - param1->msgTemp = 0x2; - v1 = (0 + 208); + + case PLUCK_EFFECT_DEF_UP: + if (ATTACKING_MON.statBoosts[BATTLE_STAT_DEFENSE] < 12) { + battleCtx->msgTemp = BATTLE_STAT_DEFENSE; + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_RAISE_STAT; } - v0 = 1; + result = TRUE; break; - case 18: - if (param1->battleMons[param1->attacker].statBoosts[0x3] < 12) { - param1->msgTemp = 0x3; - v1 = (0 + 208); + + case PLUCK_EFFECT_SPEED_UP: + if (ATTACKING_MON.statBoosts[BATTLE_STAT_SPEED] < 12) { + battleCtx->msgTemp = BATTLE_STAT_SPEED; + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_RAISE_STAT; } - v0 = 1; + result = TRUE; break; - case 19: - if (param1->battleMons[param1->attacker].statBoosts[0x4] < 12) { - param1->msgTemp = 0x4; - v1 = (0 + 208); + + case PLUCK_EFFECT_SPATK_UP: + if (ATTACKING_MON.statBoosts[BATTLE_STAT_SP_ATTACK] < 12) { + battleCtx->msgTemp = BATTLE_STAT_SP_ATTACK; + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_RAISE_STAT; } - v0 = 1; + result = TRUE; break; - case 20: - if (param1->battleMons[param1->attacker].statBoosts[0x5] < 12) { - param1->msgTemp = 0x5; - v1 = (0 + 208); + + case PLUCK_EFFECT_SPDEF_UP: + if (ATTACKING_MON.statBoosts[BATTEL_STAT_SP_DEFENSE] < 12) { + battleCtx->msgTemp = BATTEL_STAT_SP_DEFENSE; + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_RAISE_STAT; } - v0 = 1; + result = TRUE; break; - case 22: - { - int v8; - for (v8 = 0; v8 < 5; v8++) { - if (param1->battleMons[param1->attacker].statBoosts[0x1 + v8] < 12) { + case PLUCK_EFFECT_RANDOM_UP2: { + int stat; + for (stat = 0; stat < 5; stat++) { + if (ATTACKING_MON.statBoosts[BATTLE_STAT_ATTACK + stat] < 12) { break; } } - if (v8 != 5) { + if (stat != 5) { do { - v8 = BattleSystem_RandNext(param0) % 5; - } while (param1->battleMons[param1->attacker].statBoosts[0x1 + v8] == 12); + stat = BattleSystem_RandNext(battleSys) % 5; + } while (ATTACKING_MON.statBoosts[BATTLE_STAT_ATTACK + stat] == 12); - param1->msgTemp = 0x1 + v8; - v1 = (0 + 210); + battleCtx->msgTemp = BATTLE_STAT_ATTACK + stat; + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_SHARPLY_RAISE_STAT; } - } - v0 = 1; + + result = TRUE; break; - case 21: - if ((param1->battleMons[param1->attacker].statusVolatile & 0x100000) == 0) { - v1 = (0 + 209); + } + + case PLUCK_EFFECT_CRIT_UP: + if ((ATTACKING_MON.statusVolatile & VOLATILE_CONDITION_FOCUS_ENERGY) == FALSE) { + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_RAISE_CRIT; } - v0 = 1; + result = TRUE; break; - case 23: - v1 = (0 + 265); - v0 = 1; + + case PLUCK_EFFECT_TEMP_ACC_UP: + nextSeq = BATTLE_SUBSEQ_HELD_ITEM_TEMP_ACC_UP; + result = TRUE; break; - default: - if (Item_IsBerry(param1->battleMons[param2].heldItem) == 1) { - v0 = 1; + default: + if (Item_IsBerry(battleCtx->battleMons[battler].heldItem) == TRUE) { + result = TRUE; } break; } - if (v0 == 1) { - if (((Battler_Ability(param1, param1->attacker) == 103)) || (param1->battleMons[param1->attacker].moveEffectsMask & 0x4000000)) { - param1->scriptTemp = 0; + if (result == TRUE) { + if (Battler_Ability(battleCtx, battleCtx->attacker) == ABILITY_KLUTZ + || (ATTACKING_MON.moveEffectsMask & MOVE_EFFECT_EMBARGO)) { + battleCtx->scriptTemp = 0; } else { - param1->scriptTemp = v1; + battleCtx->scriptTemp = nextSeq; } - param1->msgItemTemp = param1->battleMons[param2].heldItem; - param1->selfTurnFlags[param1->attacker].statusFlags |= 0x2; + battleCtx->msgItemTemp = battleCtx->battleMons[battler].heldItem; + ATTACKER_SELF_TURN_FLAGS.statusFlags |= SELF_TURN_FLAG_PLUCK_BERRY; } - return v0; + return result; } -BOOL ov16_02259204 (BattleSystem * param0, BattleContext * param1, int param2) +BOOL BattleSystem_FlingItem(BattleSystem *battleSys, BattleContext *battleCtx, int battler) { - int v0; - int v1; - int v2; - - v1 = ov16_02258B58(param1, param2); - v2 = Battler_HeldItemPower(param1, param2, 2); + int effect = Battler_ItemFlingEffect(battleCtx, battler); + int effectPower = Battler_HeldItemPower(battleCtx, battler, ITEM_PARAM_HOLD_EFFECT_PARAM); - param1->movePower = ov16_02258B80(param1, param2); - param1->flingScript = 0; - param1->sideEffectType = 0; + battleCtx->movePower = Battler_ItemFlingPower(battleCtx, battler); + battleCtx->flingScript = 0; + battleCtx->sideEffectType = SIDE_EFFECT_SOURCE_NONE; - if (param1->movePower == 0) { - return 0; + if (battleCtx->movePower == 0) { + return FALSE; } - switch (v1) { - case 7: - param1->flingTemp = v2; - param1->flingScript = (0 + 198); + switch (effect) { + case FLING_EFFECT_HP_RESTORE: + battleCtx->flingTemp = effectPower; + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE; break; - case 10: - param1->flingTemp = BattleSystem_Divide(param1->battleMons[param1->defender].maxHP * v2, 100); - param1->flingScript = (0 + 198); + + case FLING_EFFECT_HP_PCT_RESTORE: + battleCtx->flingTemp = BattleSystem_Divide(DEFENDING_MON.maxHP * effectPower, 100); + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE; break; - case 1: - if (param1->battleMons[param1->defender].status & 0x40) { - param1->flingScript = (0 + 199); + + case FLING_EFFECT_PRZ_RESTORE: + if (DEFENDING_MON.status & MON_CONDITION_PARALYSIS) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_PRZ_RESTORE; } break; - case 2: - if (param1->battleMons[param1->defender].status & 0x7) { - param1->flingScript = (0 + 200); + + case FLING_EFFECT_SLP_RESTORE: + if (DEFENDING_MON.status & MON_CONDITION_SLEEP) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_SLP_RESTORE; } break; - case 3: - if (param1->battleMons[param1->defender].status & 0xf88) { - param1->flingScript = (0 + 201); + + case FLING_EFFECT_PSN_RESTORE: + if (DEFENDING_MON.status & MON_CONDITION_ANY_POISON) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_PSN_RESTORE; } break; - case 4: - if (param1->battleMons[param1->defender].status & 0x10) { - param1->flingScript = (0 + 202); + + case FLING_EFFECT_BRN_RESTORE: + if (DEFENDING_MON.status & MON_CONDITION_BURN) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_BRN_RESTORE; } break; - case 5: - if (param1->battleMons[param1->defender].status & 0x20) { - param1->flingScript = (0 + 203); + + case FLING_EFFECT_FRZ_RESTORE: + if (DEFENDING_MON.status & MON_CONDITION_FREEZE) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_FRZ_RESTORE; } break; - case 6: - { - int v3; - int v4; - int v5; - int v6; - v5 = 0; + case FLING_EFFECT_PP_RESTORE: { + int diff, i, maxDiff, slot; // must declare in this order to match. - for (v4 = 0; v4 < 4; v4++) { - if (param1->battleMons[param1->defender].moves[v4]) { - v3 = MoveTable_CalcMaxPP(param1->battleMons[param1->defender].moves[v4], param1->battleMons[param1->defender].ppUps[v4]) - param1->battleMons[param1->defender].ppCur[v4]; + // Find the move that has the highest difference between its current + // and maximum PP. + maxDiff = 0; + for (i = 0; i < LEARNED_MOVES_MAX; i++) { + if (DEFENDING_MON.moves[i]) { + diff = MoveTable_CalcMaxPP(DEFENDING_MON.moves[i], DEFENDING_MON.ppUps[i]) - DEFENDING_MON.ppCur[i]; - if (v3 > v5) { - v5 = v3; - v6 = v4; + if (diff > maxDiff) { + maxDiff = diff; + slot = i; } } } - if (v5) { - ov16_02252A2C(¶m1->battleMons[param1->defender], 31 + v6, v2); - BattleMon_CopyToParty(param0, param1, param1->defender); - - param1->msgMoveTemp = param1->battleMons[param1->defender].moves[v6]; - param1->flingScript = (0 + 204); + if (maxDiff) { + BattleMon_AddVal(&DEFENDING_MON, BATTLEMON_CUR_PP_1 + slot, effectPower); + BattleMon_CopyToParty(battleSys, battleCtx, battleCtx->defender); + battleCtx->msgMoveTemp = DEFENDING_MON.moves[slot]; + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_PP_RESTORE; } + + break; } - break; - case 8: - if (param1->battleMons[param1->defender].statusVolatile & 0x7) { - param1->flingScript = (0 + 205); + + case FLING_EFFECT_CNF_RESTORE: + if (DEFENDING_MON.statusVolatile & VOLATILE_CONDITION_CONFUSION) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_CNF_RESTORE; } break; - case 9: - if ((param1->battleMons[param1->defender].status & 0xff) || (param1->battleMons[param1->defender].statusVolatile & 0x7)) { - if (param1->battleMons[param1->defender].status & 0x40) { - param1->flingScript = (0 + 199); + + case FLING_EFFECT_ALL_RESTORE: + if ((DEFENDING_MON.status & MON_CONDITION_ANY) || (DEFENDING_MON.statusVolatile & VOLATILE_CONDITION_CONFUSION)) { + if (DEFENDING_MON.status & MON_CONDITION_PARALYSIS) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_PRZ_RESTORE; } - if (param1->battleMons[param1->defender].status & 0x7) { - param1->flingScript = (0 + 200); + if (DEFENDING_MON.status & MON_CONDITION_SLEEP) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_SLP_RESTORE; } - if (param1->battleMons[param1->defender].status & 0xf88) { - param1->flingScript = (0 + 201); + if (DEFENDING_MON.status & MON_CONDITION_ANY_POISON) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_PSN_RESTORE; } - if (param1->battleMons[param1->defender].status & 0x10) { - param1->flingScript = (0 + 202); + if (DEFENDING_MON.status & MON_CONDITION_BURN) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_BRN_RESTORE; } - if (param1->battleMons[param1->defender].status & 0x20) { - param1->flingScript = (0 + 203); + if (DEFENDING_MON.status & MON_CONDITION_FREEZE) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_FRZ_RESTORE; } - if (param1->battleMons[param1->defender].statusVolatile & 0x7) { - param1->flingScript = (0 + 205); + if (DEFENDING_MON.statusVolatile & VOLATILE_CONDITION_CONFUSION) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_CNF_RESTORE; } - if ((param1->battleMons[param1->defender].status & 0xff) && (param1->battleMons[param1->defender].statusVolatile & 0x7)) { - param1->flingScript = (0 + 206); + if ((DEFENDING_MON.status & MON_CONDITION_ANY) + && (DEFENDING_MON.statusVolatile & VOLATILE_CONDITION_CONFUSION)) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_MULTI_RESTORE; } } break; - case 11: - param1->flingTemp = BattleSystem_Divide(param1->battleMons[param1->defender].maxHP, v2); - param1->msgTemp = 0; - if (Pokemon_GetFlavorAffinityOf(param1->battleMons[param1->defender].personality, 0) == -1) { - param1->flingScript = (0 + 207); + case FLING_EFFECT_HP_RESTORE_SPICY: + battleCtx->flingTemp = BattleSystem_Divide(DEFENDING_MON.maxHP, effectPower); + battleCtx->msgTemp = FLAVOR_SPICY; + + if (Pokemon_GetFlavorAffinityOf(DEFENDING_MON.personality, FLAVOR_SPICY) == -1) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_DISLIKE_FLAVOR; } else { - param1->flingScript = (0 + 198); + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE; } break; - case 12: - param1->flingTemp = BattleSystem_Divide(param1->battleMons[param1->defender].maxHP, v2); - param1->msgTemp = 1; - if (Pokemon_GetFlavorAffinityOf(param1->battleMons[param1->defender].personality, 1) == -1) { - param1->flingScript = (0 + 207); + case FLING_EFFECT_HP_RESTORE_DRY: + battleCtx->flingTemp = BattleSystem_Divide(DEFENDING_MON.maxHP, effectPower); + battleCtx->msgTemp = FLAVOR_DRY; + + if (Pokemon_GetFlavorAffinityOf(DEFENDING_MON.personality, FLAVOR_DRY) == -1) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_DISLIKE_FLAVOR; } else { - param1->flingScript = (0 + 198); + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE; } break; - case 13: - param1->flingTemp = BattleSystem_Divide(param1->battleMons[param1->defender].maxHP, v2); - param1->msgTemp = 2; - if (Pokemon_GetFlavorAffinityOf(param1->battleMons[param1->defender].personality, 2) == -1) { - param1->flingScript = (0 + 207); + case FLING_EFFECT_HP_RESTORE_SWEET: + battleCtx->flingTemp = BattleSystem_Divide(DEFENDING_MON.maxHP, effectPower); + battleCtx->msgTemp = FLAVOR_SWEET; + + if (Pokemon_GetFlavorAffinityOf(DEFENDING_MON.personality, FLAVOR_SWEET) == -1) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_DISLIKE_FLAVOR; } else { - param1->flingScript = (0 + 198); + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE; } break; - case 14: - param1->flingTemp = BattleSystem_Divide(param1->battleMons[param1->defender].maxHP, v2); - param1->msgTemp = 3; - if (Pokemon_GetFlavorAffinityOf(param1->battleMons[param1->defender].personality, 3) == -1) { - param1->flingScript = (0 + 207); + case FLING_EFFECT_HP_RESTORE_BITTER: + battleCtx->flingTemp = BattleSystem_Divide(DEFENDING_MON.maxHP, effectPower); + battleCtx->msgTemp = FLAVOR_BITTER; + + if (Pokemon_GetFlavorAffinityOf(DEFENDING_MON.personality, FLAVOR_BITTER) == -1) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_DISLIKE_FLAVOR; } else { - param1->flingScript = (0 + 198); + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE; } break; - case 15: - param1->flingTemp = BattleSystem_Divide(param1->battleMons[param1->defender].maxHP, v2); - param1->msgTemp = 4; - if (Pokemon_GetFlavorAffinityOf(param1->battleMons[param1->defender].personality, 4) == -1) { - param1->flingScript = (0 + 207); + case FLING_EFFECT_HP_RESTORE_SOUR: + battleCtx->flingTemp = BattleSystem_Divide(DEFENDING_MON.maxHP, effectPower); + battleCtx->msgTemp = FLAVOR_SOUR; + + if (Pokemon_GetFlavorAffinityOf(DEFENDING_MON.personality, FLAVOR_SOUR) == -1) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_DISLIKE_FLAVOR; } else { - param1->flingScript = (0 + 198); + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_HP_RESTORE; } break; - case 24: - { - int v7; - for (v7 = 0; v7 < 0x8; v7++) { - if (param1->battleMons[param1->defender].statBoosts[v7] < 6) { - param1->battleMons[param1->defender].statBoosts[v7] = 6; - param1->flingScript = (0 + 211); + case FLING_EFFECT_STATDOWN_RESTORE: + for (int i = BATTLE_STAT_HP; i < BATTLE_STAT_MAX; i++) { + if (DEFENDING_MON.statBoosts[i] < 6) { + DEFENDING_MON.statBoosts[i] = 6; + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_STATDOWN_RESTORE; } } - } - break; - case 25: - if (param1->battleMons[param1->defender].statusVolatile & 0xf0000) { - param1->msgTemp = 6; - param1->flingScript = (0 + 212); + break; + + case FLING_EFFECT_HEAL_INFATUATION: + if (DEFENDING_MON.statusVolatile & VOLATILE_CONDITION_ATTRACT) { + battleCtx->msgTemp = MSGCOND_INFATUATION; + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_HEAL_INFATUATION; } break; - case 26: - param1->sideEffectMon = param2; - param1->sideEffectType = 2; - param1->flingScript = (0 + 14); + + case FLING_EFFECT_FLINCH: + battleCtx->sideEffectMon = battler; + battleCtx->sideEffectType = SIDE_EFFECT_SOURCE_INDIRECT; + battleCtx->flingScript = BATTLE_SUBSEQ_FLINCH_MON; break; - case 27: - param1->sideEffectMon = param2; - param1->sideEffectType = 2; - param1->flingScript = (0 + 31); + + case FLING_EFFECT_PARALYZE: + battleCtx->sideEffectMon = battler; + battleCtx->sideEffectType = SIDE_EFFECT_SOURCE_INDIRECT; + battleCtx->flingScript = BATTLE_SUBSEQ_PARALYZE; break; - case 28: - param1->sideEffectMon = param2; - param1->sideEffectType = 2; - param1->flingScript = (0 + 22); + + case FLING_EFFECT_POISON: + battleCtx->sideEffectMon = battler; + battleCtx->sideEffectType = SIDE_EFFECT_SOURCE_INDIRECT; + battleCtx->flingScript = BATTLE_SUBSEQ_POISON; break; - case 29: - param1->sideEffectMon = param2; - param1->sideEffectType = 2; - param1->flingScript = (0 + 47); + + case FLING_EFFECT_BADLY_POISON: + battleCtx->sideEffectMon = battler; + battleCtx->sideEffectType = SIDE_EFFECT_SOURCE_INDIRECT; + battleCtx->flingScript = BATTLE_SUBSEQ_BADLY_POISON; break; - case 30: - param1->sideEffectMon = param2; - param1->sideEffectType = 2; - param1->flingScript = (0 + 25); + + case FLING_EFFECT_BURN: + battleCtx->sideEffectMon = battler; + battleCtx->sideEffectType = SIDE_EFFECT_SOURCE_INDIRECT; + battleCtx->flingScript = BATTLE_SUBSEQ_BURN; break; - case 16: - if (param1->battleMons[param1->defender].statBoosts[0x1] < 12) { - param1->msgTemp = 0x1; - param1->flingScript = (0 + 208); + + case FLING_EFFECT_ATK_UP: + if (DEFENDING_MON.statBoosts[BATTLE_STAT_ATTACK] < 12) { + battleCtx->msgTemp = BATTLE_STAT_ATTACK; + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_RAISE_STAT; } break; - case 17: - if (param1->battleMons[param1->defender].statBoosts[0x2] < 12) { - param1->msgTemp = 0x2; - param1->flingScript = (0 + 208); + + case FLING_EFFECT_DEF_UP: + if (DEFENDING_MON.statBoosts[BATTLE_STAT_DEFENSE] < 12) { + battleCtx->msgTemp = BATTLE_STAT_DEFENSE; + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_RAISE_STAT; } break; - case 18: - if (param1->battleMons[param1->defender].statBoosts[0x3] < 12) { - param1->msgTemp = 0x3; - param1->flingScript = (0 + 208); + + case FLING_EFFECT_SPEED_UP: + if (DEFENDING_MON.statBoosts[BATTLE_STAT_SPEED] < 12) { + battleCtx->msgTemp = BATTLE_STAT_SPEED; + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_RAISE_STAT; } break; - case 19: - if (param1->battleMons[param1->defender].statBoosts[0x4] < 12) { - param1->msgTemp = 0x4; - param1->flingScript = (0 + 208); + + case FLING_EFFECT_SPATK_UP: + if (DEFENDING_MON.statBoosts[BATTLE_STAT_SP_ATTACK] < 12) { + battleCtx->msgTemp = BATTLE_STAT_SP_ATTACK; + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_RAISE_STAT; } break; - case 20: - if (param1->battleMons[param1->defender].statBoosts[0x5] < 12) { - param1->msgTemp = 0x5; - param1->flingScript = (0 + 208); + + case FLING_EFFECT_SPDEF_UP: + if (DEFENDING_MON.statBoosts[BATTEL_STAT_SP_DEFENSE] < 12) { + battleCtx->msgTemp = BATTEL_STAT_SP_DEFENSE; + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_RAISE_STAT; } break; - case 22: - { - int v8; - for (v8 = 0; v8 < 5; v8++) { - if (param1->battleMons[param1->defender].statBoosts[0x1 + v8] < 12) { + case FLING_EFFECT_RANDOM_UP2: { + int stat; + + for (stat = 0; stat < 5; stat++) { + if (DEFENDING_MON.statBoosts[BATTLE_STAT_ATTACK + stat] < 12) { break; } } - if (v8 != 5) { + if (stat != 5) { do { - v8 = BattleSystem_RandNext(param0) % 5; - } while (param1->battleMons[param1->defender].statBoosts[0x1 + v8] == 12); + stat = BattleSystem_RandNext(battleSys) % 5; + } while (DEFENDING_MON.statBoosts[BATTLE_STAT_ATTACK + stat] == 12); - param1->msgTemp = 0x1 + v8; - param1->flingScript = (0 + 210); + battleCtx->msgTemp = BATTLE_STAT_ATTACK + stat; + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_SHARPLY_RAISE_STAT; } + + break; } - break; - case 21: - if ((param1->battleMons[param1->defender].statusVolatile & 0x100000) == 0) { - param1->flingScript = (0 + 209); + + case FLING_EFFECT_CRIT_UP: + if ((DEFENDING_MON.statusVolatile & VOLATILE_CONDITION_FOCUS_ENERGY) == FALSE) { + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_RAISE_CRIT; } break; - case 23: - param1->flingScript = (0 + 265); + + case FLING_EFFECT_TEMP_ACC_UP: + battleCtx->flingScript = BATTLE_SUBSEQ_HELD_ITEM_TEMP_ACC_UP; break; + default: break; } - if (param1->battleMons[param1->defender].moveEffectsMask & 0x4000000) { - param1->flingScript = 0; + if (DEFENDING_MON.moveEffectsMask & MOVE_EFFECT_EMBARGO) { + battleCtx->flingScript = 0; } else { - param1->msgItemTemp = param1->battleMons[param2].heldItem; + battleCtx->msgItemTemp = battleCtx->battleMons[battler].heldItem; - if ((param1->sideEffectType == 0) && (param1->flingScript)) { - param1->selfTurnFlags[param1->attacker].statusFlags |= 0x2; + if (battleCtx->sideEffectType == SIDE_EFFECT_SOURCE_NONE && battleCtx->flingScript) { + ATTACKER_SELF_TURN_FLAGS.statusFlags |= SELF_TURN_FLAG_PLUCK_BERRY; } - param1->msgBattlerTemp = param1->defender; + battleCtx->msgBattlerTemp = battleCtx->defender; } - return 1; + return TRUE; } void BattleSystem_UpdateMetronomeCount (BattleSystem * param0, BattleContext * param1) @@ -6180,15 +6243,15 @@ u8 BattleContext_IOBufferVal (BattleContext *battleCtx, int battler) return battleCtx->ioBuffer[battler][0]; } -BOOL Battler_BehindSubstitute (BattleContext * param0, int param1) +BOOL Battler_SubstituteWasHit(BattleContext *battleCtx, int battler) { - BOOL v0 = 0; + BOOL result = FALSE; - if (param0->selfTurnFlags[param1].statusFlags & 0x8) { - v0 = 1; + if (battleCtx->selfTurnFlags[battler].statusFlags & SELF_TURN_FLAG_SUBSTITUTE_HIT) { + result = TRUE; } - return v0; + return result; } BOOL BattleSystem_TrainerIsOT (BattleSystem * param0, BattleContext * param1) From c9f1f1607b9387c739b98358c9ca7dd68696465e Mon Sep 17 00:00:00 2001 From: lhearachel Date: Sun, 29 Oct 2023 22:58:17 -0700 Subject: [PATCH 3/3] Document battle script commands 0xA7 - 0xBA --- include/constants/battle.h | 6 + include/constants/battle/side_effects.h | 4 + include/constants/battle/terrain.h | 3 +- include/overlay016/ov16_0223DF00.h | 4 +- include/overlay016/ov16_0225177C.h | 41 +- include/overlay016/ov16_0226485C.h | 8 +- include/unk_02006224.h | 2 +- src/overlay014/ov14_0221FC20.c | 2 +- src/overlay016/battle_script.c | 922 ++++++++++++++---------- src/overlay016/ov16_0223DF00.c | 8 +- src/overlay016/ov16_0225177C.c | 54 +- src/overlay016/ov16_0225CBB8.c | 26 +- src/overlay016/ov16_0226485C.c | 16 +- src/unk_02006224.c | 4 +- src/unk_0202F1D4.c | 2 +- 15 files changed, 650 insertions(+), 452 deletions(-) diff --git a/include/constants/battle.h b/include/constants/battle.h index 3898ebaaca..3e2ece270d 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -123,6 +123,12 @@ #define TYPE_MULTI_NOT_VERY_EFF 5 #define TYPE_MULTI_SUPER_EFF 20 +#define TYPE_MULTI_QUARTER_DAMAGE 10 +#define TYPE_MULTI_HALF_DAMAGE 20 +#define TYPE_MULTI_BASE_DAMAGE 40 +#define TYPE_MULTI_DOUBLE_DAMAGE 80 +#define TYPE_MULTI_QUADRUPLE_DAMAGE 160 + #define SOUNDPROOF_SLOT_1 (1 << 0) #define SOUNDPROOF_SLOT_2 (1 << 1) #define NO_PARTNER_SLOT_1 (1 << 2) diff --git a/include/constants/battle/side_effects.h b/include/constants/battle/side_effects.h index f3d0092d1e..22c7a41b80 100644 --- a/include/constants/battle/side_effects.h +++ b/include/constants/battle/side_effects.h @@ -1,6 +1,10 @@ #ifndef POKEPLATINUM_CONSTANTS_BATTLE_SIDE_EFFECTS_H #define POKEPLATINUM_CONSTANTS_BATTLE_SIDE_EFFECTS_H +#define MOVE_SIDE_EFFECT_SLEEP 0x00000001 +#define MOVE_SIDE_EFFECT_FREEZE 0x00000004 +#define MOVE_SIDE_EFFECT_PARALYZE 0x00000005 +#define MOVE_SIDE_EFFECT_FLINCH 0x00000008 #define MOVE_SIDE_EFFECT_ATTACK_UP_1_STAGE 0x0000000F #define MOVE_SIDE_EFFECT_DEFENSE_UP_1_STAGE 0x00000010 #define MOVE_SIDE_EFFECT_SPEED_UP_1_STAGE 0x00000011 diff --git a/include/constants/battle/terrain.h b/include/constants/battle/terrain.h index 9f0a242bd4..ae163f6159 100644 --- a/include/constants/battle/terrain.h +++ b/include/constants/battle/terrain.h @@ -14,8 +14,9 @@ enum Terrain { TERRAIN_BUILDING, TERRAIN_GREAT_MARSH, TERRAIN_BRIDGE, + TERRAIN_SPECIAL, - TERRAIN_AARON, + TERRAIN_AARON = TERRAIN_SPECIAL, TERRAIN_BERTHA, TERRAIN_FLINT, TERRAIN_LUCIAN, diff --git a/include/overlay016/ov16_0223DF00.h b/include/overlay016/ov16_0223DF00.h index 62d7b557e7..3114aab225 100644 --- a/include/overlay016/ov16_0223DF00.h +++ b/include/overlay016/ov16_0223DF00.h @@ -185,7 +185,7 @@ int ov16_0223EDE0(BattleSystem * param0); u8 BattleSystem_TextSpeed(BattleSystem * param0); int BattleSystem_Ruleset(BattleSystem * param0); UnkStruct_02015F84 * ov16_0223EE28(BattleSystem * param0); -UnkStruct_0202CC84 * ov16_0223EE30(BattleSystem * param0, int param1); +UnkStruct_0202CC84 * BattleSystem_ChatotVoice(BattleSystem * param0, int param1); void ov16_0223EE70(BattleSystem * param0); void ov16_0223EF2C(BattleSystem * param0, int param1, int param2); void ov16_0223EF48(BattleSystem * param0, Pokemon * param1); @@ -243,7 +243,7 @@ u32 ov16_0223F710(BattleSystem * param0); void BattleSystem_SetStopRecording(BattleSystem *battleSys, int flag); BOOL ov16_0223F7A4(BattleSystem * param0); void BattleSystem_ShowStopPlaybackButton(BattleSystem *battleSys); -u8 ov16_0223F810(BattleSystem * param0, int param1); +u8 BattleSystem_RecordedChatter(BattleSystem * param0, int param1); void ov16_0223F858(BattleSystem * param0, u8 * param1); void ov16_0223F87C(BattleSystem * param0, u8 * param1); void ov16_0223F8AC(BattleSystem * param0, UnkStruct_02007C7C ** param1); diff --git a/include/overlay016/ov16_0225177C.h b/include/overlay016/ov16_0225177C.h index 0cdf8d7aeb..cba4658732 100644 --- a/include/overlay016/ov16_0225177C.h +++ b/include/overlay016/ov16_0225177C.h @@ -384,7 +384,26 @@ BOOL BattleMove_IsMultiTurn(BattleContext * param0, int param1); * entry falls outside the bounds of the table. */ BOOL BattleSystem_TypeMatchup(BattleSystem *battleSys, int idx, u8 *moveType, u8 *vsType, u8 *multi); -int ov16_022558CC(u8 param0, u8 param1, u8 param2); + +/** + * @brief Determine the total multiplier classification to use for an attacking + * type against a pair of defending types. + * + * This routine centers 1x damage as a return value of 40. From there, the + * multiplier varies by powers of 2: + * - 1/4x -> 10 + * - 1/2x -> 20 + * - 1x -> 40 + * - 2x -> 80 + * - 4x -> 160 + * + * @param attackingType + * @param defendingType1 + * @param defendingType2 + * @return The total multiplier of the attacking type against a defender with + * the pair of types. + */ +int BattleSystem_TypeMatchupMultiplier(u8 attackingType, u8 defendingType1, u8 defendingType2); /** * @brief Determines if a move is an invoker-class move. @@ -556,8 +575,24 @@ enum HeldItemPowerOp { * @return The power of the battler's held item. */ s32 Battler_HeldItemPower(BattleContext *battleCtx, int battler, enum HeldItemPowerOp opcode); -s32 ov16_02258B18(BattleContext * param0, int param1); -s32 ov16_02258B2C(BattleContext * param0, int param1); + +/** + * @brief Get the Natural Gift base power for a battler's held item. + * + * @param battleCtx + * @param battler + * @return Base power for Natural Gift. + */ +s32 Battler_NaturalGiftPower(BattleContext *battleCtx, int battler); + +/** + * @brief Get the Natural Gift type for a battler's held item. + * + * @param battleCtx + * @param battler + * @return Type for Natural Gift. + */ +s32 Battler_NaturalGiftType(BattleContext *battleCtx, int battler); /** * @brief Get the Pluck effect of the battler's held item. diff --git a/include/overlay016/ov16_0226485C.h b/include/overlay016/ov16_0226485C.h index 6d8fe441ce..f2b31bb179 100644 --- a/include/overlay016/ov16_0226485C.h +++ b/include/overlay016/ov16_0226485C.h @@ -60,9 +60,9 @@ void ov16_02266460(BattleSystem * param0, int param1); void BattleIO_StopGaugeAnimation(BattleSystem *battleSys, int battler); void BattleIO_RefreshPartyStatus(BattleSystem * param0, BattleContext * param1, int param2, int param3); void BattleIO_ForgetMove(BattleSystem * param0, int param1, int param2, int param3); -void ov16_022664F8(BattleSystem * param0, int param1, int param2, int param3); -void ov16_0226651C(BattleSystem * param0, int param1); -void ov16_022665AC(BattleSystem * param0, int param1); +void BattleIO_SetMosaic(BattleSystem * param0, int param1, int param2, int param3); +void BattleIO_ChangeWeatherForm(BattleSystem * param0, int param1); +void BattleIO_UpdateBG(BattleSystem * param0, int param1); void BattleIO_ClearTouchScreen(BattleSystem * param0, int param1); void ov16_022665E4(BattleSystem * param0, int param1); void ov16_0226660C(BattleSystem * param0, int param1); @@ -81,7 +81,7 @@ void ov16_022668D0(BattleSystem * param0); void ov16_0226692C(BattleSystem * param0, BattleContext * param1, int param2); void ov16_022669D8(BattleSystem * param0, BattleContext * param1, int param2); void ov16_02266A18(BattleSystem * param0, int param1, int param2); -void ov16_02266A38(BattleSystem * param0); +void BattleIO_SubmitResult(BattleSystem * param0); void BattleIO_ClearMessageBox(BattleSystem * param0); void ov16_02266ABC(BattleSystem * param0, int param1, int param2); BOOL ov16_02266AE4(BattleSystem * param0, void * param1); diff --git a/include/unk_02006224.h b/include/unk_02006224.h index cbf27374e8..e59d2b18d6 100644 --- a/include/unk_02006224.h +++ b/include/unk_02006224.h @@ -15,7 +15,7 @@ void sub_020063C0(UnkStruct_0202CC84 * param0); void sub_020063D4(u8 param0); BOOL sub_020063E4(UnkStruct_0202CC84 * param0, u32 param1, int param2, int param3); BOOL sub_02006438(UnkStruct_0202CC84 * param0, u32 param1, int param2, int param3, u8 param4); -int sub_02006494(UnkStruct_0202CC84 * param0); +int Sound_Chatter(UnkStruct_0202CC84 * param0); BOOL sub_020064C8(int param0); #endif // POKEPLATINUM_UNK_02006224_H diff --git a/src/overlay014/ov14_0221FC20.c b/src/overlay014/ov14_0221FC20.c index 3d86667f39..7c07a43839 100644 --- a/src/overlay014/ov14_0221FC20.c +++ b/src/overlay014/ov14_0221FC20.c @@ -3290,7 +3290,7 @@ static int ov14_0222327C (BattleSystem * param0, BattleContext * param1, int par switch (param3) { case 363: - v0 = ov16_02258B2C(param1, param2); + v0 = Battler_NaturalGiftType(param1, param2); break; case 449: switch (Battler_HeldItemEffect(param1, param2)) { diff --git a/src/overlay016/battle_script.c b/src/overlay016/battle_script.c index 3168f7fe9a..33f5e65b36 100644 --- a/src/overlay016/battle_script.c +++ b/src/overlay016/battle_script.c @@ -223,7 +223,7 @@ static BOOL BtlCmd_CalcMagnitudePower(BattleSystem *battleSys, BattleContext *ba static BOOL BtlCmd_TryReplaceBattler(BattleSystem *battleSys, BattleContext *battleCtx); static BOOL BtlCmd_RapidSpin(BattleSystem *battleSys, BattleContext *battleCtx); static BOOL BtlCmd_WeatherHPRecovery(BattleSystem *battleSys, BattleContext *battleCtx); -static BOOL BtlCmd_CalcHiddenPower(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_CalcHiddenPowerParams(BattleSystem *battleSys, BattleContext *battleCtx); static BOOL BtlCmd_CopyStatStages(BattleSystem *battleSys, BattleContext *battleCtx); static BOOL BtlCmd_TrySetupFutureSight(BattleSystem *battleSys, BattleContext *battleCtx); static BOOL BtlCmd_CheckMoveHit(BattleSystem *battleSys, BattleContext *battleCtx); @@ -248,49 +248,49 @@ static BOOL BtlCmd_CalcWeightBasedPower(BattleSystem *battleSys, BattleContext * static BOOL BtlCmd_CalcWeatherBallPower(BattleSystem *battleSys, BattleContext *battleCtx); static BOOL BtlCmd_CheckForPursuit(BattleSystem *battleSys, BattleContext *battleCtx); static BOOL BtlCmd_ApplyTypeMatchup(BattleSystem *battleSys, BattleContext *battleCtx); -static BOOL BtlCmd_IfTurnFlag(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_SetTurnFlag(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_CalcGyroBallPower(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_TryMetalBurst(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_CalcPaybackPower(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_CalcTrumpCardPower(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_CalcWringOutPower(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_TryMeFirst(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_TryCopycat(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_CalcPunishmentPower(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_TrySuckerPunch(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_CheckSideCondition(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_CheckDefenderProtecting(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_CheckCanShareStatus(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_TryLastResort(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_TryToxicSpikes(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_CheckToxicSpikes(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_CheckIgnorableAbility(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_IfSameSide(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_GenerateEndOfBattleItem(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_SetTrickRoom(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_IfMovedThisTurn(BattleSystem * param0, BattleContext * param1); -static BOOL BtlCmd_IfItemEffect(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247950(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_0224799C(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_022479E8(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247A80(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247AB0(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247AE0(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247B28(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247BA4(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247BD4(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247C04(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247C64(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247C94(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247CE0(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247D04(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247E10(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247E98(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247F44(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247F7C(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247FBC(BattleSystem * param0, BattleContext * param1); -static BOOL ov16_02247FE8(BattleSystem * param0, BattleContext * param1); +static BOOL BtlCmd_IfTurnFlag(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_SetTurnFlag(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_CalcGyroBallPower(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_TryMetalBurst(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_CalcPaybackPower(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_CalcTrumpCardPower(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_CalcWringOutPower(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_TryMeFirst(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_TryCopycat(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_CalcPunishmentPower(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_TrySuckerPunch(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_CheckSideCondition(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_CheckDefenderProtecting(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_CheckCanShareStatus(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_TryLastResort(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_TryToxicSpikes(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_CheckToxicSpikes(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_CheckIgnorableAbility(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_IfSameSide(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_GenerateEndOfBattleItem(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_SetTrickRoom(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_IfMovedThisTurn(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_IfItemEffect(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_GetItemEffect(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_GetItemEffectPower(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_TryCamouflage(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_GetTerrainMove(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_GetTerrainSecondaryEffect(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_CalcNaturalGiftParams(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_TryPluckBerry(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_TryFlingItem(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_ShowYesNoScreen(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_WaitYesNoResult(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_ShowPartyScreen(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_WaitPartyScreenResult(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_SubmitResult(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_CheckStealthRock(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_CheckActivateSecondaryEffect(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_CheckActivateChatterEffect(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_GetCurrentMoveData(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_SetMosaic(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_ChangeWeatherForm(BattleSystem *battleSys, BattleContext *battleCtx); +static BOOL BtlCmd_UpdateBG(BattleSystem *battleSys, BattleContext *battleCtx); static BOOL ov16_02248000(BattleSystem * param0, BattleContext * param1); static BOOL ov16_02248040(BattleSystem * param0, BattleContext * param1); static BOOL ov16_02248084(BattleSystem * param0, BattleContext * param1); @@ -483,7 +483,7 @@ static const BtlCmd sBattleCommands[] = { BtlCmd_TryReplaceBattler, BtlCmd_RapidSpin, BtlCmd_WeatherHPRecovery, - BtlCmd_CalcHiddenPower, + BtlCmd_CalcHiddenPowerParams, BtlCmd_CopyStatStages, BtlCmd_TrySetupFutureSight, BtlCmd_CheckMoveHit, @@ -531,26 +531,26 @@ static const BtlCmd sBattleCommands[] = { BtlCmd_SetTrickRoom, BtlCmd_IfMovedThisTurn, BtlCmd_IfItemEffect, - ov16_02247950, - ov16_0224799C, - ov16_022479E8, - ov16_02247A80, - ov16_02247AB0, - ov16_02247AE0, - ov16_02247B28, - ov16_02247BA4, - ov16_02247BD4, - ov16_02247C04, - ov16_02247C64, - ov16_02247C94, - ov16_02247CE0, - ov16_02247D04, - ov16_02247E10, - ov16_02247E98, - ov16_02247F44, - ov16_02247F7C, - ov16_02247FBC, - ov16_02247FE8, + BtlCmd_GetItemEffect, + BtlCmd_GetItemEffectPower, + BtlCmd_TryCamouflage, + BtlCmd_GetTerrainMove, + BtlCmd_GetTerrainSecondaryEffect, + BtlCmd_CalcNaturalGiftParams, + BtlCmd_TryPluckBerry, + BtlCmd_TryFlingItem, + BtlCmd_ShowYesNoScreen, + BtlCmd_WaitYesNoResult, + BtlCmd_ShowPartyScreen, + BtlCmd_WaitPartyScreenResult, + BtlCmd_SubmitResult, + BtlCmd_CheckStealthRock, + BtlCmd_CheckActivateSecondaryEffect, + BtlCmd_CheckActivateChatterEffect, + BtlCmd_GetCurrentMoveData, + BtlCmd_SetMosaic, + BtlCmd_ChangeWeatherForm, + BtlCmd_UpdateBG, ov16_02248000, ov16_02248040, ov16_02248084, @@ -6342,7 +6342,7 @@ static BOOL BtlCmd_WeatherHPRecovery(BattleSystem *battleSys, BattleContext *bat * @param battleCtx * @return FALSE */ -static BOOL BtlCmd_CalcHiddenPower(BattleSystem *battleSys, BattleContext *battleCtx) +static BOOL BtlCmd_CalcHiddenPowerParams(BattleSystem *battleSys, BattleContext *battleCtx) { BattleScript_Iter(battleCtx, 1); @@ -8329,475 +8329,633 @@ static BOOL BtlCmd_IfItemEffect(BattleSystem *battleSys, BattleContext *battleCt return FALSE; } -static BOOL ov16_02247950 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Get a battler's held item and store its effect into the + * specified variable. + * + * Inputs: + * 1. The battler whose item is to be accessed. + * 2. The variable in which to store the item effect. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_GetItemEffect(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - int v2; - int * v3; - u16 v4; - - BattleScript_Iter(param1, 1); + BattleScript_Iter(battleCtx, 1); + int inBattler = BattleScript_Read(battleCtx); + int dstVar = BattleScript_Read(battleCtx); - v1 = BattleScript_Read(param1); - v2 = BattleScript_Read(param1); - v3 = BattleScript_VarAddress(param0, param1, v2); - v0 = BattleScript_Battler(param0, param1, v1); - v4 = Battler_HeldItem(param1, v0); + int *var = BattleScript_VarAddress(battleSys, battleCtx, dstVar); + int battler = BattleScript_Battler(battleSys, battleCtx, inBattler); + u16 item = Battler_HeldItem(battleCtx, battler); - v3[0] = BattleSystem_GetItemData(param1, v4, 1); + *var = BattleSystem_GetItemData(battleCtx, item, ITEM_PARAM_HOLD_EFFECT); - return 0; + return FALSE; } -static BOOL ov16_0224799C (BattleSystem * param0, BattleContext * param1) +/** + * @brief Get a battler's held item and store its effect power into the + * specified variable. + * + * Inputs: + * 1. The battler whose item is to be accessed. + * 2. The variable in which to store the item effect power. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_GetItemEffectPower(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - int v2; - int * v3; - u16 v4; - - BattleScript_Iter(param1, 1); + BattleScript_Iter(battleCtx, 1); + int inBattler = BattleScript_Read(battleCtx); + int dstVar = BattleScript_Read(battleCtx); - v1 = BattleScript_Read(param1); - v2 = BattleScript_Read(param1); - v3 = BattleScript_VarAddress(param0, param1, v2); - v0 = BattleScript_Battler(param0, param1, v1); - v4 = Battler_HeldItem(param1, v0); + int *var = BattleScript_VarAddress(battleSys, battleCtx, dstVar); + int battler = BattleScript_Battler(battleSys, battleCtx, inBattler); + u16 item = Battler_HeldItem(battleCtx, battler); - v3[0] = BattleSystem_GetItemData(param1, v4, 2); + *var = BattleSystem_GetItemData(battleCtx, item, ITEM_PARAM_HOLD_EFFECT_PARAM); - return 0; + return FALSE; } -static const u8 Unk_ov16_0226EAC0[] = { - 0x4, - 0x4, - 0xC, - 0xC, - 0x5, - 0x5, - 0xF, - 0xB, - 0xF, - 0x0, - 0x4, - 0x2, - 0x0 +static const u8 sTerrainCamouflageType[] = { + [TERRAIN_PLAIN] = TYPE_GROUND, + [TERRAIN_SAND] = TYPE_GROUND, + [TERRAIN_GRASS] = TYPE_GRASS, + [TERRAIN_PUDDLE] = TYPE_GRASS, + [TERRAIN_MOUNTAIN] = TYPE_ROCK, + [TERRAIN_CAVE] = TYPE_ROCK, + [TERRAIN_SNOW] = TYPE_ICE, + [TERRAIN_WATER] = TYPE_WATER, + [TERRAIN_ICE] = TYPE_ICE, + [TERRAIN_BUILDING] = TYPE_NORMAL, + [TERRAIN_GREAT_MARSH] = TYPE_GROUND, + [TERRAIN_BRIDGE] = TYPE_FLYING, + [TERRAIN_SPECIAL] = TYPE_NORMAL, }; -static BOOL ov16_022479E8 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Try to change the battler's type to one according to the battle + * terrain. + * + * @param battleSys + * @param battleCtx + * @return BOOL + */ +static BOOL BtlCmd_TryCamouflage(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - int v2; - - BattleScript_Iter(param1, 1); - - v0 = BattleScript_Read(param1); + BattleScript_Iter(battleCtx, 1); + int jumpOnFail = BattleScript_Read(battleCtx); - if (Battler_Ability(param1, param1->attacker) == 121) { - BattleScript_Iter(param1, v0); - return 0; + if (Battler_Ability(battleCtx, battleCtx->attacker) == ABILITY_MULTITYPE) { + BattleScript_Iter(battleCtx, jumpOnFail); + return FALSE; } - v1 = BattleSystem_Terrain(param0); - - if (v1 > 12) { - v1 = 12; + int terrain = BattleSystem_Terrain(battleSys); + if (terrain > TERRAIN_SPECIAL) { + terrain = TERRAIN_SPECIAL; } - v2 = Unk_ov16_0226EAC0[v1]; - - if ((BattleMon_Get(param1, param1->attacker, 27, NULL) != v2) && (BattleMon_Get(param1, param1->attacker, 28, NULL) != v2)) { - param1->battleMons[param1->attacker].type1 = v2; - param1->battleMons[param1->attacker].type2 = v2; - param1->msgTemp = v2; + int type = sTerrainCamouflageType[terrain]; + if (MON_IS_NOT_TYPE(battleCtx->attacker, type)) { + ATTACKING_MON.type1 = type; + ATTACKING_MON.type2 = type; + battleCtx->msgTemp = type; } else { - BattleScript_Iter(param1, v0); + BattleScript_Iter(battleCtx, jumpOnFail); } return 0; } -static const u16 Unk_ov16_0226E652[] = { - 0x59, - 0x59, - 0x192, - 0x192, - 0x9D, - 0x9D, - 0x3B, - 0x38, - 0x3A, - 0xA1, - 0x1AA, - 0x193, - 0xA1 +static const u16 sTerrainMove[] = { + [TERRAIN_PLAIN] = MOVE_EARTHQUAKE, + [TERRAIN_SAND] = MOVE_EARTHQUAKE, + [TERRAIN_GRASS] = MOVE_SEED_BOMB, + [TERRAIN_PUDDLE] = MOVE_SEED_BOMB, + [TERRAIN_MOUNTAIN] = MOVE_ROCK_SLIDE, + [TERRAIN_CAVE] = MOVE_ROCK_SLIDE, + [TERRAIN_SNOW] = MOVE_BLIZZARD, + [TERRAIN_WATER] = MOVE_HYDRO_PUMP, + [TERRAIN_ICE] = MOVE_ICE_BEAM, + [TERRAIN_BUILDING] = MOVE_TRI_ATTACK, + [TERRAIN_GREAT_MARSH] = MOVE_MUD_BOMB, + [TERRAIN_BRIDGE] = MOVE_AIR_SLASH, + [TERRAIN_SPECIAL] = MOVE_TRI_ATTACK, }; -static BOOL ov16_02247A80 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Get the move which corresponding to this battle's terrain. + * + * Side effects: + * - battleCtx->msgMoveTemp will be set to the terrain's corresponding move. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_GetTerrainMove(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - BattleScript_Iter(param1, 1); - v0 = BattleSystem_Terrain(param0); + BattleScript_Iter(battleCtx, 1); - if (v0 > 12) { - v0 = 12; + int terrain = BattleSystem_Terrain(battleSys); + if (terrain > TERRAIN_SPECIAL) { + terrain = TERRAIN_SPECIAL; } - param1->msgMoveTemp = Unk_ov16_0226E652[v0]; + battleCtx->msgMoveTemp = sTerrainMove[terrain]; - return 0; + return FALSE; } -static const u32 Unk_ov16_0226E690[] = { - 0x8000001B, - 0x8000001B, - 0x80000001, - 0x80000001, - 0x80000008, - 0x80000008, - 0x80000004, - 0x80000016, - 0x80000004, - 0x80000005, - 0x80000018, - 0x8000001C, - 0x80000005 +static const u32 sTerrainSideEffect[] = { + [TERRAIN_PLAIN] = MOVE_SIDE_EFFECT_TO_DEFENDER | MOVE_SIDE_EFFECT_ACCURACY_DOWN_1_STAGE, + [TERRAIN_SAND] = MOVE_SIDE_EFFECT_TO_DEFENDER | MOVE_SIDE_EFFECT_ACCURACY_DOWN_1_STAGE, + [TERRAIN_GRASS] = MOVE_SIDE_EFFECT_TO_DEFENDER | MOVE_SIDE_EFFECT_SLEEP, + [TERRAIN_PUDDLE] = MOVE_SIDE_EFFECT_TO_DEFENDER | MOVE_SIDE_EFFECT_SLEEP, + [TERRAIN_MOUNTAIN] = MOVE_SIDE_EFFECT_TO_DEFENDER | MOVE_SIDE_EFFECT_FLINCH, + [TERRAIN_CAVE] = MOVE_SIDE_EFFECT_TO_DEFENDER | MOVE_SIDE_EFFECT_FLINCH, + [TERRAIN_SNOW] = MOVE_SIDE_EFFECT_TO_DEFENDER | MOVE_SIDE_EFFECT_FREEZE, + [TERRAIN_WATER] = MOVE_SIDE_EFFECT_TO_DEFENDER | MOVE_SIDE_EFFECT_ATTACK_DOWN_1_STAGE, + [TERRAIN_ICE] = MOVE_SIDE_EFFECT_TO_DEFENDER | MOVE_SIDE_EFFECT_FREEZE, + [TERRAIN_BUILDING] = MOVE_SIDE_EFFECT_TO_DEFENDER | MOVE_SIDE_EFFECT_PARALYZE, + [TERRAIN_GREAT_MARSH] = MOVE_SIDE_EFFECT_TO_DEFENDER | MOVE_SIDE_EFFECT_SPEED_DOWN_1_STAGE, + [TERRAIN_BRIDGE] = MOVE_SIDE_EFFECT_TO_DEFENDER | MOVE_SIDE_EFFECT_EVASION_DOWN_1_STAGE, + [TERRAIN_SPECIAL] = MOVE_SIDE_EFFECT_TO_DEFENDER | MOVE_SIDE_EFFECT_PARALYZE, }; -static BOOL ov16_02247AB0 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Get the secondary effect corresponding to this battle's terrain. + * + * Side effects: + * - battleCtx->sideEffectIndirectFlags will be set to the terrain's + * corresponding secondary effect flags. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_GetTerrainSecondaryEffect(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - - BattleScript_Iter(param1, 1); - - v0 = BattleSystem_Terrain(param0); + BattleScript_Iter(battleCtx, 1); - if (v0 > 12) { - v0 = 12; + int terrain = BattleSystem_Terrain(battleSys); + if (terrain > TERRAIN_SPECIAL) { + terrain = TERRAIN_SPECIAL; } - param1->sideEffectIndirectFlags = Unk_ov16_0226E690[v0]; + battleCtx->sideEffectIndirectFlags = sTerrainSideEffect[terrain]; - return 0; + return FALSE; } -static BOOL ov16_02247AE0 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Calculate the type and base power of Natural Gift. + * + * Inputs: + * 1. The distance to jump if the attacker's item cannot be used with Natural + * Gift. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_CalcNaturalGiftParams(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - - BattleScript_Iter(param1, 1); - - v0 = BattleScript_Read(param1); - v1 = ov16_02258B18(param1, param1->attacker); + BattleScript_Iter(battleCtx, 1); + int jumpInvalidItem = BattleScript_Read(battleCtx); - if (v1) { - param1->movePower = v1; - param1->moveType = ov16_02258B2C(param1, param1->attacker); + int power = Battler_NaturalGiftPower(battleCtx, battleCtx->attacker); + if (power) { + battleCtx->movePower = power; + battleCtx->moveType = Battler_NaturalGiftType(battleCtx, battleCtx->attacker); } else { - BattleScript_Iter(param1, v0); + BattleScript_Iter(battleCtx, jumpInvalidItem); } - return 0; + return FALSE; } -static BOOL ov16_02247B28 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Try to Pluck the defender's berry and grant its effect to the attacker. + * + * Inputs: + * 1. The distance to jump if the defender has Sticky Hold. + * 2. The distance to jump if the defender's berry does not have a Pluckable + * effect, or if the defender used their Custap Berry this turn. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_TryPluckBerry(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - - BattleScript_Iter(param1, 1); - - v0 = BattleScript_Read(param1); - v1 = BattleScript_Read(param1); + BattleScript_Iter(battleCtx, 1); + int jumpStickyHold = BattleScript_Read(battleCtx); + int jumpNoEffect = BattleScript_Read(battleCtx); - if ((param1->battleMons[param1->defender].heldItem) && (Battler_IgnorableAbility(param1, param1->attacker, param1->defender, 60) == 1)) { - BattleScript_Iter(param1, v0); - } else if (((param1->battleMons[param1->defender].heldItem) && (param1->battleMons[param1->defender].moveEffectsData.custapBerry)) || (BattleSystem_PluckBerry(param0, param1, param1->defender) != 1)) { - BattleScript_Iter(param1, v1); + if (DEFENDING_MON.heldItem + && Battler_IgnorableAbility(battleCtx, battleCtx->attacker, battleCtx->defender, ABILITY_STICKY_HOLD) == TRUE) { + BattleScript_Iter(battleCtx, jumpStickyHold); + } else if ((DEFENDING_MON.heldItem && DEFENDING_MON.moveEffectsData.custapBerry) + || BattleSystem_PluckBerry(battleSys, battleCtx, battleCtx->defender) != TRUE) { + BattleScript_Iter(battleCtx, jumpNoEffect); } - return 0; + return FALSE; } -static BOOL ov16_02247BA4 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Try to Fling the attacker's item and enact its effect on the defender. + * + * Inputs: + * 1. The distance to jump if the attacker's item does not have a Flingable + * effect. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_TryFlingItem(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - - BattleScript_Iter(param1, 1); - - v0 = BattleScript_Read(param1); + BattleScript_Iter(battleCtx, 1); + int jumpNoEffect = BattleScript_Read(battleCtx); - if (BattleSystem_FlingItem(param0, param1, param1->attacker) != 1) { - BattleScript_Iter(param1, v0); + if (BattleSystem_FlingItem(battleSys, battleCtx, battleCtx->attacker) != TRUE) { + BattleScript_Iter(battleCtx, jumpNoEffect); } - return 0; + return FALSE; } -static BOOL ov16_02247BD4 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Show a Yes/No option-select on the bottom screen. + * + * Inputs: + * 1. The type of Yes/No option-select to be shown. + * + * @param battleSys + * @param battleCtx + * @return BOOL + */ +static BOOL BtlCmd_ShowYesNoScreen(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; + BattleScript_Iter(battleCtx, 1); + int type = BattleScript_Read(battleCtx); - BattleScript_Iter(param1, 1); - v0 = BattleScript_Read(param1); - BattleIO_ShowYesNoScreen(param0, param1, 0, NULL, v0, NULL, NULL); + BattleIO_ShowYesNoScreen(battleSys, battleCtx, BATTLER_US, NULL, type, NULL, NULL); - return 0; + return FALSE; } -static BOOL ov16_02247C04 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Wait for a result from a displayed Yes/No option-select. + * + * This command will NOT modify the sequence cursor until an input is made. + * + * Inputs: + * 1. The distance to jump if the player selected Yes. + * 2. The distance to jump if the player selected No. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_WaitYesNoResult(BattleSystem *battleSys, BattleContext *battleCtx) { - u8 v0; - int v1; - int v2; - - v0 = BattleContext_IOBufferVal(param1, 0); + u8 input = BattleContext_IOBufferVal(battleCtx, 0); - if (v0) { - BattleScript_Iter(param1, 1); - - v1 = BattleScript_Read(param1); - v2 = BattleScript_Read(param1); + if (input) { + BattleScript_Iter(battleCtx, 1); + int jumpIfYes = BattleScript_Read(battleCtx); + int jumpIfNo = BattleScript_Read(battleCtx); - if (v0 == 0xff) { - BattleScript_Iter(param1, v2); + if (input == 0xFF) { + BattleScript_Iter(battleCtx, jumpIfNo); } else { - BattleScript_Iter(param1, v1); + BattleScript_Iter(battleCtx, jumpIfYes); } - BattleSystem_Record(param0, 0, v0); + BattleSystem_Record(battleSys, 0, input); } - param1->battleProgressFlag = 1; - - return 0; + battleCtx->battleProgressFlag = TRUE; + return FALSE; } -static BOOL ov16_02247C64 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Show the Party menu on the bottom screen. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_ShowPartyScreen(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1 = BattleSystem_MaxBattlers(param0); - - BattleScript_Iter(param1, 1); - BattleIO_ShowPartyScreen(param0, param1, 0, 0, 0, 6); - - param1->switchedMon = 0; + BattleSystem_MaxBattlers(battleSys); // must stay to match + BattleScript_Iter(battleCtx, 1); + + BattleIO_ShowPartyScreen(battleSys, battleCtx, BATTLER_US, 0, 0, 6); + battleCtx->switchedMon = BATTLER_US; - return 0; + return FALSE; } -static BOOL ov16_02247C94 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Wait for a result from a displayed Party menu. + * + * This command will NOT modify the sequence cursor until an input is made. + * + * Inputs: + * 1. The distance to jump if the player selected Cancel. + * + * Side effects: + * - battleCtx->switchedPartySlot will be updated to reflect the chosen + * party slot for a switch. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_WaitPartyScreenResult(BattleSystem *battleSys, BattleContext *battleCtx) { - u8 v0; - int v1; - - v0 = BattleContext_IOBufferVal(param1, 0); + u8 input = BattleContext_IOBufferVal(battleCtx, 0); - if (v0) { - BattleScript_Iter(param1, 1); - - v1 = BattleScript_Read(param1); + if (input) { + BattleScript_Iter(battleCtx, 1); + int jumpIfCancel = BattleScript_Read(battleCtx); - if (v0 == 0xff) { - BattleScript_Iter(param1, v1); + if (input == 0xFF) { + BattleScript_Iter(battleCtx, jumpIfCancel); } else { - param1->switchedPartySlot[0] = v0 - 1; + battleCtx->switchedPartySlot[BATTLER_US] = input - 1; } } - param1->battleProgressFlag = 1; - - return 0; + battleCtx->battleProgressFlag = TRUE; + return FALSE; } -static BOOL ov16_02247CE0 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Submit the battle result flag to other Wi-fi battlers, if this is + * a Wi-fi battle. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_SubmitResult(BattleSystem *battleSys, BattleContext *battleCtx) { - BattleScript_Iter(param1, 1); + BattleScript_Iter(battleCtx, 1); - if (BattleSystem_BattleType(param0) & 0x4) { - ov16_02266A38(param0); + if (BattleSystem_BattleType(battleSys) & BATTLE_TYPE_LINK) { + BattleIO_SubmitResult(battleSys); } - return 0; + return FALSE; } -static BOOL ov16_02247D04 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Check for Stealth Rock on a battler's side of the field. + * + * Inputs: + * 1. The battler for whom Stealth Rock should be checked. + * 2. The distance to jump if there is no effect to apply. + * + * Side effects: + * - battleCtx->hpCalcTemp will be set to the HP deduction to apply to the + * input battler from Stealth Rock. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_CheckStealthRock(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - int v2; - int v3; - int v4; - int v5; + BattleScript_Iter(battleCtx, 1); + int inBattler = BattleScript_Read(battleCtx); + int jumpNoEffect = BattleScript_Read(battleCtx); - BattleScript_Iter(param1, 1); + int battler = BattleScript_Battler(battleSys, battleCtx, inBattler); + int side = Battler_Side(battleSys, battler); + int type1 = BattleMon_Get(battleCtx, battler, BATTLEMON_TYPE_1, NULL); + int type2 = BattleMon_Get(battleCtx, battler, BATTLEMON_TYPE_2, NULL); - v0 = BattleScript_Read(param1); - v1 = BattleScript_Read(param1); - v2 = BattleScript_Battler(param0, param1, v0); - v3 = Battler_Side(param0, v2); - v4 = BattleMon_Get(param1, v2, 27, NULL); - v5 = BattleMon_Get(param1, v2, 28, NULL); - - if ((param1->sideConditionsMask[v3] & 0x80) && (param1->battleMons[v2].curHP)) { - switch (ov16_022558CC(5, v4, v5)) { - case 160: - param1->hpCalcTemp = 2; + if ((battleCtx->sideConditionsMask[side] & SIDE_CONDITION_STEALTH_ROCK) + && battleCtx->battleMons[battler].curHP) { + switch (BattleSystem_TypeMatchupMultiplier(TYPE_ROCK, type1, type2)) { + case TYPE_MULTI_QUADRUPLE_DAMAGE: + battleCtx->hpCalcTemp = 2; break; - case 80: - param1->hpCalcTemp = 4; + + case TYPE_MULTI_DOUBLE_DAMAGE: + battleCtx->hpCalcTemp = 4; break; - case 40: - param1->hpCalcTemp = 8; + + case TYPE_MULTI_BASE_DAMAGE: + battleCtx->hpCalcTemp = 8; break; - case 20: - param1->hpCalcTemp = 16; + + case TYPE_MULTI_HALF_DAMAGE: + battleCtx->hpCalcTemp = 16; break; - case 10: - param1->hpCalcTemp = 32; + + case TYPE_MULTI_QUARTER_DAMAGE: + battleCtx->hpCalcTemp = 32; break; - case 0: - BattleScript_Iter(param1, v1); - return 0; + + case TYPE_MULTI_IMMUNE: + BattleScript_Iter(battleCtx, jumpNoEffect); + return FALSE; + default: - GF_ASSERT(0); + GF_ASSERT(FALSE); break; } - param1->hpCalcTemp = BattleSystem_Divide(param1->battleMons[v2].maxHP * -1, param1->hpCalcTemp); + battleCtx->hpCalcTemp = BattleSystem_Divide(battleCtx->battleMons[battler].maxHP * -1, battleCtx->hpCalcTemp); } else { - BattleScript_Iter(param1, v1); + BattleScript_Iter(battleCtx, jumpNoEffect); } - return 0; + return FALSE; } -static BOOL ov16_02247E10 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Check if a secondary effect should activate. + * + * Inputs: + * 1. The distance to jump ahead if the secondary effect should NOT activate. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_CheckActivateSecondaryEffect(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - u16 v1; - - BattleScript_Iter(param1, 1); - v0 = BattleScript_Read(param1); + BattleScript_Iter(battleCtx, 1); + int jumpNoEffect = BattleScript_Read(battleCtx); - if (Battler_Ability(param1, param1->attacker) == 32) { - v1 = param1->aiContext.moveTable[param1->moveCur].effectChance * 2; + u16 effectChance; + if (Battler_Ability(battleCtx, battleCtx->attacker) == ABILITY_SERENE_GRACE) { + effectChance = CURRENT_MOVE_DATA.effectChance * 2; } else { - v1 = param1->aiContext.moveTable[param1->moveCur].effectChance; + effectChance = CURRENT_MOVE_DATA.effectChance; } - GF_ASSERT(v1 != 0); + GF_ASSERT(effectChance != 0); - if (((BattleSystem_RandNext(param0) % 100) < v1) && (param1->battleMons[param1->sideEffectMon].curHP)) { - return 0; + if (BattleSystem_RandNext(battleSys) % 100 < effectChance + && battleCtx->battleMons[battleCtx->sideEffectMon].curHP) { + return FALSE; } - BattleScript_Iter(param1, v0); - - return 0; + BattleScript_Iter(battleCtx, jumpNoEffect); + return FALSE; } -static BOOL ov16_02247E98 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Check if Chatter's secondary effect should activate based on Chatot's + * sound data. + * + * Inputs: + * 1. The distance to jump ahead if the secondary effect should NOT activate. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_CheckActivateChatterEffect(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - u16 v1; - - BattleScript_Iter(param1, 1); + BattleScript_Iter(battleCtx, 1); + int jumpNoEffect = BattleScript_Read(battleCtx); - v0 = BattleScript_Read(param1); + if (ATTACKING_MON.species == SPECIES_CHATOT + && DEFENDING_MON.curHP + && (ATTACKING_MON.statusVolatile & VOLATILE_CONDITION_TRANSFORM) == FALSE) { + int chatter; + if ((BattleSystem_BattleStatus(battleSys) & BATTLE_STATUS_RECORDING) == FALSE) { + chatter = Sound_Chatter(BattleSystem_ChatotVoice(battleSys, battleCtx->attacker)); + } else { + chatter = BattleSystem_RecordedChatter(battleSys, battleCtx->attacker); + } - { - int v2; + u16 effectChance; + switch (chatter) { + default: + case 0: + effectChance = 0; + break; - if ((param1->battleMons[param1->attacker].species == 441) && (param1->battleMons[param1->defender].curHP) && ((param1->battleMons[param1->attacker].statusVolatile & 0x200000) == 0)) { - if ((BattleSystem_BattleStatus(param0) & 0x10) == 0) { - v2 = sub_02006494(ov16_0223EE30(param0, param1->attacker)); - } else { - v2 = ov16_0223F810(param0, param1->attacker); - } + case 1: + effectChance = 10; + break; - switch (v2) { - default: - case 0: - v1 = 0; - break; - case 1: - v1 = 10; - break; - case 2: - v1 = 30; - break; - } + case 2: + effectChance = 30; + break; + } - if ((BattleSystem_RandNext(param0) % 100) > v1) { - BattleScript_Iter(param1, v0); - } - } else { - BattleScript_Iter(param1, v0); + if (BattleSystem_RandNext(battleSys) % 100 > effectChance) { + BattleScript_Iter(battleCtx, jumpNoEffect); } + } else { + BattleScript_Iter(battleCtx, jumpNoEffect); } - return 0; + return FALSE; } -static BOOL ov16_02247F44 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Gets a parameter from the current move's data table entry. + * + * Inputs: + * 1. The parameter to be retrieved from the current move. + * + * Side effects: + * - battleCtx->calcTemp will be set to the value of the requested parameter. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_GetCurrentMoveData(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - - BattleScript_Iter(param1, 1); + BattleScript_Iter(battleCtx, 1); + int param = BattleScript_Read(battleCtx); - v0 = BattleScript_Read(param1); - param1->calcTemp = MoveTable_Get(¶m1->aiContext.moveTable[param1->moveCur], v0); + battleCtx->calcTemp = MoveTable_Get(&CURRENT_MOVE_DATA, param); - return 0; + return FALSE; } -static BOOL ov16_02247F7C (BattleSystem * param0, BattleContext * param1) +/** + * @brief Sets the mosaic effect on a battler's sprite. + * + * Inputs: + * 1. The battler on which to apply the effect. + * 2. The target distortion level to be applied. + * 3. The time to wait between individual distortion levels. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_SetMosaic(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - int v2; - int v3; - - BattleScript_Iter(param1, 1); - - v0 = BattleScript_Read(param1); - v1 = BattleScript_Read(param1); - v2 = BattleScript_Read(param1); - v3 = BattleScript_Battler(param0, param1, v0); + BattleScript_Iter(battleCtx, 1); + int inBattler = BattleScript_Read(battleCtx); + int param = BattleScript_Read(battleCtx); + int wait = BattleScript_Read(battleCtx); - ov16_022664F8(param0, v3, v1, v2); + int battler = BattleScript_Battler(battleSys, battleCtx, inBattler); + BattleIO_SetMosaic(battleSys, battler, param, wait); - return 0; + return FALSE; } -static BOOL ov16_02247FBC (BattleSystem * param0, BattleContext * param1) +/** + * @brief Signals that a form change should occur due to the field's weather. + * + * Inputs: + * 1. The battler whose form should be changed. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_ChangeWeatherForm(BattleSystem *battleSys, BattleContext *battleCtx) { - int v0; - int v1; - - BattleScript_Iter(param1, 1); - - v0 = BattleScript_Read(param1); - v1 = BattleScript_Battler(param0, param1, v0); + BattleScript_Iter(battleCtx, 1); + int inBattler = BattleScript_Read(battleCtx); - ov16_0226651C(param0, v1); + int battler = BattleScript_Battler(battleSys, battleCtx, inBattler); + BattleIO_ChangeWeatherForm(battleSys, battler); - return 0; + return FALSE; } -static BOOL ov16_02247FE8 (BattleSystem * param0, BattleContext * param1) +/** + * @brief Issue a signal to shift all terrain graphics into the BG. + * + * @param battleSys + * @param battleCtx + * @return FALSE + */ +static BOOL BtlCmd_UpdateBG(BattleSystem *battleSys, BattleContext *battleCtx) { - BattleScript_Iter(param1, 1); - ov16_022665AC(param0, 0); + BattleScript_Iter(battleCtx, 1); + + BattleIO_UpdateBG(battleSys, BATTLER_US); - return 0; + return FALSE; } static BOOL ov16_02248000 (BattleSystem * param0, BattleContext * param1) diff --git a/src/overlay016/ov16_0223DF00.c b/src/overlay016/ov16_0223DF00.c index bc2b14e5cb..44baa7b36d 100644 --- a/src/overlay016/ov16_0223DF00.c +++ b/src/overlay016/ov16_0223DF00.c @@ -141,7 +141,7 @@ int ov16_0223EDE0(BattleSystem * param0); u8 BattleSystem_TextSpeed(BattleSystem * param0); int BattleSystem_Ruleset(BattleSystem * param0); UnkStruct_02015F84 * ov16_0223EE28(BattleSystem * param0); -UnkStruct_0202CC84 * ov16_0223EE30(BattleSystem * param0, int param1); +UnkStruct_0202CC84 * BattleSystem_ChatotVoice(BattleSystem * param0, int param1); void ov16_0223EE70(BattleSystem * param0); void ov16_0223EF2C(BattleSystem * param0, int param1, int param2); void ov16_0223EF48(BattleSystem * param0, Pokemon * param1); @@ -197,7 +197,7 @@ u32 ov16_0223F710(BattleSystem * param0); void BattleSystem_SetStopRecording(BattleSystem *battleSys, int flag); BOOL ov16_0223F7A4(BattleSystem * param0); void BattleSystem_ShowStopPlaybackButton(BattleSystem * param0); -u8 ov16_0223F810(BattleSystem * param0, int param1); +u8 BattleSystem_RecordedChatter(BattleSystem * param0, int param1); void ov16_0223F858(BattleSystem * param0, u8 * param1); void ov16_0223F87C(BattleSystem * param0, u8 * param1); void ov16_0223F8AC(BattleSystem * param0, UnkStruct_02007C7C ** param1); @@ -1074,7 +1074,7 @@ UnkStruct_02015F84 * ov16_0223EE28 (BattleSystem * param0) return param0->unk_1C4; } -UnkStruct_0202CC84 * ov16_0223EE30 (BattleSystem * param0, int param1) +UnkStruct_0202CC84 * BattleSystem_ChatotVoice (BattleSystem * param0, int param1) { if ((param0->battleType & 0x8) || ((param0->battleType & 0x10) && (BattleSystem_BattlerSlot(param0, param1) & 0x1))) { return param0->unk_78[param1]; @@ -1622,7 +1622,7 @@ void BattleSystem_ShowStopPlaybackButton (BattleSystem *battleSys) battleSys->playbackStopButton = ov16_0226E148(battleSys); } -u8 ov16_0223F810 (BattleSystem * param0, int param1) +u8 BattleSystem_RecordedChatter (BattleSystem * param0, int param1) { if ((param0->battleType & 0x8) || ((param0->battleType & 0x10) && (BattleSystem_BattlerSlot(param0, param1) & 0x1))) { return param0->unk_247C[param1]; diff --git a/src/overlay016/ov16_0225177C.c b/src/overlay016/ov16_0225177C.c index 55b15e2b70..991eba0135 100644 --- a/src/overlay016/ov16_0225177C.c +++ b/src/overlay016/ov16_0225177C.c @@ -94,7 +94,7 @@ u16 Battler_SelectedMove(BattleContext * param0, int param1); int BattleSystem_CountAbility(BattleSystem *battleSys, BattleContext *battleCtx, enum CountAbilityMode mode, int battler, int ability); BOOL BattleMove_IsMultiTurn(BattleContext * param0, int param1); BOOL BattleSystem_TypeMatchup(BattleSystem *battleSys, int idx, u8 *moveType, u8 *vsType, u8 *multi); -int ov16_022558CC(u8 param0, u8 param1, u8 param2); +int BattleSystem_TypeMatchupMultiplier(u8 attackingType, u8 defendingType1, u8 defendingType2); BOOL Move_IsInvoker(u16 move); BOOL BattleSystem_IsGhostCurse(BattleContext * param0, u16 param1, int param2); BOOL BattleSystem_CanStealItem(BattleSystem *battleSys, BattleContext *battleCtx, int battler); @@ -132,8 +132,8 @@ BOOL Battler_MovedThisTurn(BattleContext * param0, int param1); BOOL BattleSystem_TriggerHeldItemOnHit(BattleSystem * param0, BattleContext * param1, int * param2); s32 Battler_HeldItemEffect(BattleContext * param0, int param1); s32 Battler_HeldItemPower(BattleContext *battleCtx, int battler, enum HeldItemPowerOp opcode); -s32 ov16_02258B18(BattleContext * param0, int param1); -s32 ov16_02258B2C(BattleContext * param0, int param1); +s32 Battler_NaturalGiftPower(BattleContext *battleCtx, int battler); +s32 Battler_NaturalGiftType(BattleContext *battleCtx, int battler); s32 Battler_ItemPluckEffect(BattleContext *battleCtx, int battler); s32 Battler_ItemFlingEffect(BattleContext *battleCtx, int battler); s32 Battler_ItemFlingPower(BattleContext *battleCtx, int battler); @@ -3092,29 +3092,27 @@ BOOL BattleSystem_TypeMatchup(BattleSystem *battleSys, int idx, u8 *moveType, u8 return result; } -int ov16_022558CC (u8 param0, u8 param1, u8 param2) +int BattleSystem_TypeMatchupMultiplier(u8 attackingType, u8 defendingType1, u8 defendingType2) { - int v0; - int v1; - - v0 = 0; - v1 = 40; + int i = 0; + int mul = 40; - while (sTypeMatchupMultipliers[v0][0] != 0xff) { - if (sTypeMatchupMultipliers[v0][0] == param0) { - if (sTypeMatchupMultipliers[v0][1] == param1) { - v1 = v1 * sTypeMatchupMultipliers[v0][2] / 10; + while (sTypeMatchupMultipliers[i][0] != 0xFF) { + if (sTypeMatchupMultipliers[i][0] == attackingType) { + if (sTypeMatchupMultipliers[i][1] == defendingType1) { + mul = mul * sTypeMatchupMultipliers[i][2] / 10; } - if ((sTypeMatchupMultipliers[v0][1] == param2) && (param1 != param2)) { - v1 = v1 * sTypeMatchupMultipliers[v0][2] / 10; + if (sTypeMatchupMultipliers[i][1] == defendingType2 + && defendingType1 != defendingType2) { + mul = mul * sTypeMatchupMultipliers[i][2] / 10; } } - v0++; + i++; } - return v1; + return mul; } BOOL Move_IsInvoker(u16 move) @@ -5459,20 +5457,16 @@ s32 Battler_HeldItemPower(BattleContext *battleCtx, int battler, enum HeldItemPo return BattleSystem_GetItemData(battleCtx, item, ITEM_PARAM_HOLD_EFFECT_PARAM); } -s32 ov16_02258B18 (BattleContext * param0, int param1) +s32 Battler_NaturalGiftPower(BattleContext *battleCtx, int battler) { - u16 v0; - - v0 = Battler_HeldItem(param0, param1); - return BattleSystem_GetItemData(param0, v0, 11); + u16 item = Battler_HeldItem(battleCtx, battler); + return BattleSystem_GetItemData(battleCtx, item, ITEM_PARAM_NATURAL_GIFT_POWER); } -s32 ov16_02258B2C (BattleContext * param0, int param1) +s32 Battler_NaturalGiftType(BattleContext *battleCtx, int battler) { - u16 v0; - - v0 = Battler_HeldItem(param0, param1); - return BattleSystem_GetItemData(param0, v0, 12); + u16 item = Battler_HeldItem(battleCtx, battler); + return BattleSystem_GetItemData(battleCtx, item, ITEM_PARAM_NATURAL_GIFT_TYPE); } s32 Battler_ItemPluckEffect(BattleContext *battleCtx, int battler) @@ -7873,7 +7867,7 @@ static int BattleMove_Type (BattleSystem * param0, BattleContext * param1, int p switch (param3) { case 363: - v0 = ov16_02258B2C(param1, param2); + v0 = Battler_NaturalGiftType(param1, param2); break; case 449: switch (Battler_HeldItemEffect(param1, param2)) { @@ -8015,8 +8009,8 @@ int ov16_0225BA88 (BattleSystem * param0, int param1) v4 = BattleMon_Get(v20, v2, 28, NULL); v5 = Pokemon_GetValue(v19, MON_DATA_TYPE_1, NULL); v6 = Pokemon_GetValue(v19, MON_DATA_TYPE_2, NULL); - v11 = ov16_022558CC(v5, v3, v4); - v11 += ov16_022558CC(v6, v3, v4); + v11 = BattleSystem_TypeMatchupMultiplier(v5, v3, v4); + v11 += BattleSystem_TypeMatchupMultiplier(v6, v3, v4); if (v12 < v11) { v12 = v11; diff --git a/src/overlay016/ov16_0225CBB8.c b/src/overlay016/ov16_0225CBB8.c index 9e9a1505c8..7450bf9ab3 100644 --- a/src/overlay016/ov16_0225CBB8.c +++ b/src/overlay016/ov16_0225CBB8.c @@ -1625,7 +1625,7 @@ static void ov16_0225E4E8 (SysTask * param0, void * param1) { u8 v4; sub_02078A4C(v0->unk_04->unk_1A0, &v4, v0->unk_16, v0->unk_1C); - sub_02077DB4(ov16_0223EE30(v0->unk_00, v0->unk_11), v0->unk_18, v0->unk_16, v0->unk_2C, 117, 127, NULL, 5, v4); + sub_02077DB4(BattleSystem_ChatotVoice(v0->unk_00, v0->unk_11), v0->unk_18, v0->unk_16, v0->unk_2C, 117, 127, NULL, 5, v4); } if ((v0->unk_1C == 1) || (v0->unk_1C == 3)) { @@ -1668,7 +1668,7 @@ static void ov16_0225E4E8 (SysTask * param0, void * param1) u8 v5; sub_02078A4C(v0->unk_04->unk_1A0, &v5, v0->unk_16, v0->unk_1C); - sub_02077DB4(ov16_0223EE30(v0->unk_00, v0->unk_11), v0->unk_18, v0->unk_16, v0->unk_2C, -117, 127, NULL, 5, v5); + sub_02077DB4(BattleSystem_ChatotVoice(v0->unk_00, v0->unk_11), v0->unk_18, v0->unk_16, v0->unk_2C, -117, 127, NULL, 5, v5); } if ((v0->unk_1C == 0) || (v0->unk_1C == 2)) { @@ -1752,7 +1752,7 @@ static void ov16_0225E894 (SysTask * param0, void * param1) u8 v4; sub_02078A4C(v0->unk_04->unk_1A0, &v4, v0->unk_16, v0->unk_1C); - sub_02077DB4(ov16_0223EE30(v0->unk_00, v0->unk_11), v0->unk_18, v0->unk_16, v0->unk_2C, 117, 127, NULL, 5, v4); + sub_02077DB4(BattleSystem_ChatotVoice(v0->unk_00, v0->unk_11), v0->unk_18, v0->unk_16, v0->unk_2C, 117, 127, NULL, 5, v4); } sub_0200D4C4(v0->unk_0C->unk_00, (24 * 8), (8 * 11)); @@ -1913,7 +1913,7 @@ static void ov16_0225EA80 (SysTask * param0, void * param1) u8 v4; sub_02078A4C(v0->unk_04->unk_1A0, &v4, v0->unk_86, v0->unk_82); - sub_02077DB4(ov16_0223EE30(v0->unk_00, v0->unk_81), v0->unk_88, v0->unk_86, v0->unk_97, 117, 127, NULL, 5, v4); + sub_02077DB4(BattleSystem_ChatotVoice(v0->unk_00, v0->unk_81), v0->unk_88, v0->unk_86, v0->unk_97, 117, 127, NULL, 5, v4); } } else { sub_02007B98(v0->unk_04->unk_20, 1); @@ -1922,7 +1922,7 @@ static void ov16_0225EA80 (SysTask * param0, void * param1) u8 v5; sub_02078A4C(v0->unk_04->unk_1A0, &v5, v0->unk_86, v0->unk_82); - sub_02077DB4(ov16_0223EE30(v0->unk_00, v0->unk_81), v0->unk_88, v0->unk_86, v0->unk_97, -117, 127, NULL, 5, v5); + sub_02077DB4(BattleSystem_ChatotVoice(v0->unk_00, v0->unk_81), v0->unk_88, v0->unk_86, v0->unk_97, -117, 127, NULL, 5, v5); } } @@ -1942,7 +1942,7 @@ static void ov16_0225EA80 (SysTask * param0, void * param1) u8 v6; sub_02078A4C(v0->unk_04->unk_1A0, &v6, v0->unk_86, v0->unk_82); - sub_02077DB4(ov16_0223EE30(v0->unk_00, v0->unk_81), v0->unk_88, v0->unk_86, v0->unk_97, 117, 127, NULL, 5, v6); + sub_02077DB4(BattleSystem_ChatotVoice(v0->unk_00, v0->unk_81), v0->unk_88, v0->unk_86, v0->unk_97, 117, 127, NULL, 5, v6); } } else { sub_02007B98(v0->unk_04->unk_20, 1); @@ -1951,7 +1951,7 @@ static void ov16_0225EA80 (SysTask * param0, void * param1) u8 v7; sub_02078A4C(v0->unk_04->unk_1A0, &v7, v0->unk_86, v0->unk_82); - sub_02077DB4(ov16_0223EE30(v0->unk_00, v0->unk_81), v0->unk_88, v0->unk_86, v0->unk_97, -117, 127, NULL, 5, v7); + sub_02077DB4(BattleSystem_ChatotVoice(v0->unk_00, v0->unk_81), v0->unk_88, v0->unk_86, v0->unk_97, -117, 127, NULL, 5, v7); } } @@ -2109,7 +2109,7 @@ static void ov16_0225F0C0 (SysTask * param0, void * param1) u8 v6; sub_02078A4C(v0->unk_04->unk_1A0, &v6, v0->unk_86, v0->unk_82); - sub_02077DB4(ov16_0223EE30(v0->unk_00, v0->unk_81), v0->unk_88, v0->unk_86, v0->unk_97, 117, 127, NULL, 5, v6); + sub_02077DB4(BattleSystem_ChatotVoice(v0->unk_00, v0->unk_81), v0->unk_88, v0->unk_86, v0->unk_97, 117, 127, NULL, 5, v6); } } else { sub_02007B98(v0->unk_04->unk_20, 1); @@ -2118,7 +2118,7 @@ static void ov16_0225F0C0 (SysTask * param0, void * param1) u8 v7; sub_02078A4C(v0->unk_04->unk_1A0, &v7, v0->unk_86, v0->unk_82); - sub_02077DB4(ov16_0223EE30(v0->unk_00, v0->unk_81), v0->unk_88, v0->unk_86, v0->unk_97, -117, 127, NULL, 5, v7); + sub_02077DB4(BattleSystem_ChatotVoice(v0->unk_00, v0->unk_81), v0->unk_88, v0->unk_86, v0->unk_97, -117, 127, NULL, 5, v7); } } @@ -2137,7 +2137,7 @@ static void ov16_0225F0C0 (SysTask * param0, void * param1) u8 v8; sub_02078A4C(v0->unk_04->unk_1A0, &v8, v0->unk_86, v0->unk_82); - sub_02077DB4(ov16_0223EE30(v0->unk_00, v0->unk_81), v0->unk_88, v0->unk_86, v0->unk_97, 117, 127, NULL, 5, v8); + sub_02077DB4(BattleSystem_ChatotVoice(v0->unk_00, v0->unk_81), v0->unk_88, v0->unk_86, v0->unk_97, 117, 127, NULL, 5, v8); } } else { sub_02007B98(v0->unk_04->unk_20, 1); @@ -2146,7 +2146,7 @@ static void ov16_0225F0C0 (SysTask * param0, void * param1) u8 v9; sub_02078A4C(v0->unk_04->unk_1A0, &v9, v0->unk_86, v0->unk_82); - sub_02077DB4(ov16_0223EE30(v0->unk_00, v0->unk_81), v0->unk_88, v0->unk_86, v0->unk_97, -117, 127, NULL, 5, v9); + sub_02077DB4(BattleSystem_ChatotVoice(v0->unk_00, v0->unk_81), v0->unk_88, v0->unk_86, v0->unk_97, -117, 127, NULL, 5, v9); } } @@ -4911,7 +4911,7 @@ static void ov16_02262A9C (SysTask * param0, void * param1) v7 = -117; } - sub_02077DB4(ov16_0223EE30(v0->unk_00, v0->unk_65), 5, v0->unk_68, v0->unk_6B, v7, 127, v0->unk_72, 5, 0); + sub_02077DB4(BattleSystem_ChatotVoice(v0->unk_00, v0->unk_65), 5, v0->unk_68, v0->unk_6B, v7, 127, v0->unk_72, 5, 0); v0->unk_66++; } case 5: @@ -6270,7 +6270,7 @@ static void ov16_02264408 (BattleSystem * param0, BattlerData * param1, UnkStruc ov16_0223F8AC(param0, &(v0.unk_20[0])); v0.unk_30 = BattleSystem_BattleType(param0); - v0.unk_6C = ov16_0223EE30(param0, param1->unk_190); + v0.unk_6C = BattleSystem_ChatotVoice(param0, param1->unk_190); v0.unk_70 = ov16_0223F1E8(param0); v0.unk_74 = ov16_0223F1F0(param0); v0.unk_54.unk_00 = 7; diff --git a/src/overlay016/ov16_0226485C.c b/src/overlay016/ov16_0226485C.c index ff6f024412..4f67a7338f 100644 --- a/src/overlay016/ov16_0226485C.c +++ b/src/overlay016/ov16_0226485C.c @@ -121,9 +121,9 @@ void ov16_02266460(BattleSystem * param0, int param1); void BattleIO_StopGaugeAnimation(BattleSystem *battleSys, int battler); void BattleIO_RefreshPartyStatus(BattleSystem * param0, BattleContext * param1, int param2, int param3); void BattleIO_ForgetMove(BattleSystem * param0, int param1, int param2, int param3); -void ov16_022664F8(BattleSystem * param0, int param1, int param2, int param3); -void ov16_0226651C(BattleSystem * param0, int param1); -void ov16_022665AC(BattleSystem * param0, int param1); +void BattleIO_SetMosaic(BattleSystem * param0, int param1, int param2, int param3); +void BattleIO_ChangeWeatherForm(BattleSystem * param0, int param1); +void BattleIO_UpdateBG(BattleSystem * param0, int param1); void BattleIO_ClearTouchScreen(BattleSystem * param0, int param1); void ov16_022665E4(BattleSystem * param0, int param1); void ov16_0226660C(BattleSystem * param0, int param1); @@ -142,7 +142,7 @@ void ov16_022668D0(BattleSystem * param0); void ov16_0226692C(BattleSystem * param0, BattleContext * param1, int param2); void ov16_022669D8(BattleSystem * param0, BattleContext * param1, int param2); void ov16_02266A18(BattleSystem * param0, int param1, int param2); -void ov16_02266A38(BattleSystem * param0); +void BattleIO_SubmitResult(BattleSystem * param0); void ov16_02266ABC(BattleSystem * param0, int param1, int param2); BOOL ov16_02266AE4(BattleSystem * param0, void * param1); void ov16_02266B78(BattleSystem * param0, BattleContext * param1, UnkStruct_ov16_02265BBC * param2, int param3, int param4, int param5, int param6, u16 param7); @@ -1338,7 +1338,7 @@ void BattleIO_ForgetMove (BattleSystem * param0, int param1, int param2, int par ov16_02264A04(param0, 1, param1, &v0, sizeof(UnkStruct_ov16_02266498)); } -void ov16_022664F8 (BattleSystem * param0, int param1, int param2, int param3) +void BattleIO_SetMosaic (BattleSystem * param0, int param1, int param2, int param3) { UnkStruct_ov16_022664F8 v0; @@ -1349,7 +1349,7 @@ void ov16_022664F8 (BattleSystem * param0, int param1, int param2, int param3) ov16_02264A04(param0, 1, param1, &v0, sizeof(UnkStruct_ov16_022664F8)); } -void ov16_0226651C (BattleSystem * param0, int param1) +void BattleIO_ChangeWeatherForm (BattleSystem * param0, int param1) { UnkStruct_ov16_0225C684 v0; @@ -1370,7 +1370,7 @@ void ov16_0226651C (BattleSystem * param0, int param1) ov16_02264A04(param0, 1, param1, &v0, sizeof(UnkStruct_ov16_0225C684)); } -void ov16_022665AC (BattleSystem * param0, int param1) +void BattleIO_UpdateBG (BattleSystem * param0, int param1) { int v0 = 46; ov16_02264A04(param0, 1, param1, &v0, 4); @@ -1585,7 +1585,7 @@ void ov16_02266A18 (BattleSystem * param0, int param1, int param2) ov16_02264A04(param0, 1, param1, &v0, sizeof(UnkStruct_ov16_0225CA60)); } -void ov16_02266A38 (BattleSystem * param0) +void BattleIO_SubmitResult (BattleSystem * param0) { UnkStruct_ov16_02266A38 v0; u32 v1 = BattleSystem_BattleType(param0); diff --git a/src/unk_02006224.c b/src/unk_02006224.c index f7eab59e2b..148f5796bf 100644 --- a/src/unk_02006224.c +++ b/src/unk_02006224.c @@ -21,7 +21,7 @@ void sub_020063C0(UnkStruct_0202CC84 * param0); void sub_020063D4(u8 param0); BOOL sub_020063E4(UnkStruct_0202CC84 * param0, u32 param1, int param2, int param3); BOOL sub_02006438(UnkStruct_0202CC84 * param0, u32 param1, int param2, int param3, u8 param4); -int sub_02006494(UnkStruct_0202CC84 * param0); +int Sound_Chatter(UnkStruct_0202CC84 * param0); BOOL sub_020064C8(int param0); BOOL sub_02006224 (void) @@ -204,7 +204,7 @@ BOOL sub_02006438 (UnkStruct_0202CC84 * param0, u32 param1, int param2, int para return v0; } -int sub_02006494 (UnkStruct_0202CC84 * param0) +int Sound_Chatter (UnkStruct_0202CC84 * param0) { const s8 * v0; s8 v1; diff --git a/src/unk_0202F1D4.c b/src/unk_0202F1D4.c index 170bc97c81..0629403b8f 100644 --- a/src/unk_0202F1D4.c +++ b/src/unk_0202F1D4.c @@ -490,7 +490,7 @@ void sub_0202F8AC (BattleParams * param0) sub_0202FCE8(param0->parties[v0], &v1->unk_1150[v0]); TrainerInfo_Copy(param0->unk_D0[v0], &v1->unk_1B68[v0]); - v2->unk_14C[v0] = sub_02006494(param0->unk_F0[v0]); + v2->unk_14C[v0] = Sound_Chatter(param0->unk_F0[v0]); } sub_02027A10(param0->unk_108, &v1->unk_1BE8);