From 1a53154324b5b5a7338c2832c3497eb1c46c0214 Mon Sep 17 00:00:00 2001 From: ghoulslash <41651341+ghoulslash@users.noreply.github.com> Date: Wed, 5 Jul 2023 14:59:42 -0400 Subject: [PATCH] Beat Up AI Damage Calc (#3104) * add specific AI dmg calc for new beat up * beat up ai calc optimizations --------- Co-authored-by: ghoulslash --- include/pokemon.h | 1 + src/battle_ai_util.c | 14 ++++++++++++++ src/pokemon.c | 31 +++++++++++++++---------------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/include/pokemon.h b/include/pokemon.h index f20b23e79..022c155ae 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -611,5 +611,6 @@ bool32 TryFormChange(u32 monId, u32 side, u16 method); void TryToSetBattleFormChangeMoves(struct Pokemon *mon, u16 method); u32 GetMonFriendshipScore(struct Pokemon *pokemon); void UpdateMonPersonality(struct BoxPokemon *boxMon, u32 personality); +u8 CalculatePartyCount(struct Pokemon *party); #endif // GUARD_POKEMON_H diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index 81b6e9cbd..3deabc5f5 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -833,6 +833,20 @@ s32 AI_CalcDamage(u16 move, u8 battlerAtk, u8 battlerDef, u8 *typeEffectiveness, case EFFECT_FINAL_GAMBIT: dmg = gBattleMons[battlerAtk].hp; break; + #if B_BEAT_UP >= GEN_5 + case EFFECT_BEAT_UP: + { + u32 partyCount = CalculatePartyCount(GetBattlerParty(battlerAtk)); + u32 i; + gBattleStruct->beatUpSlot = 0; + dmg = 0; + for (i = 0; i < partyCount; i++) { + dmg += CalculateMoveDamage(move, battlerAtk, battlerDef, moveType, 0, FALSE, FALSE, FALSE); + } + gBattleStruct->beatUpSlot = 0; + } + break; + #endif } // Handle other multi-strike moves diff --git a/src/pokemon.c b/src/pokemon.c index 748fcdfb0..fca93e67e 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -5432,29 +5432,28 @@ u8 SendMonToPC(struct Pokemon* mon) return MON_CANT_GIVE; } +u8 CalculatePartyCount(struct Pokemon *party) +{ + u32 partyCount = 0; + + while (partyCount < PARTY_SIZE + && GetMonData(&party[partyCount], MON_DATA_SPECIES, NULL) != SPECIES_NONE) + { + partyCount++; + } + + return partyCount; +} + u8 CalculatePlayerPartyCount(void) { - gPlayerPartyCount = 0; - - while (gPlayerPartyCount < PARTY_SIZE - && GetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_SPECIES, NULL) != SPECIES_NONE) - { - gPlayerPartyCount++; - } - + gPlayerPartyCount = CalculatePartyCount(gPlayerParty); return gPlayerPartyCount; } u8 CalculateEnemyPartyCount(void) { - gEnemyPartyCount = 0; - - while (gEnemyPartyCount < PARTY_SIZE - && GetMonData(&gEnemyParty[gEnemyPartyCount], MON_DATA_SPECIES, NULL) != SPECIES_NONE) - { - gEnemyPartyCount++; - } - + gEnemyPartyCount = CalculatePartyCount(gEnemyParty); return gEnemyPartyCount; }