From 5f74781a7d540036e2ba20d7cc7b028bccb80b40 Mon Sep 17 00:00:00 2001 From: Ct11217 Date: Sat, 17 Sep 2022 17:44:50 -0600 Subject: [PATCH 1/3] Remove ACE_POKEMON_FUNCTIONALITY --- include/constants/battle_ai.h | 2 +- src/battle_ai_switch_items.c | 28 ++++++++++++++-------------- src/battle_controller_opponent.c | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/constants/battle_ai.h b/include/constants/battle_ai.h index 5dbbccf48..e45ce035c 100644 --- a/include/constants/battle_ai.h +++ b/include/constants/battle_ai.h @@ -56,7 +56,7 @@ #define AI_FLAG_STALL (1 << 13) // AI stalls battle and prefers secondary damage/trapping/etc. TODO not finished #define AI_FLAG_SCREENER (1 << 14) // AI prefers screening effects like reflect, mist, etc. TODO unfinished #define AI_FLAG_SMART_SWITCHING (1 << 15) // AI includes a lot more switching checks -#define AI_FLAG_ACE_POKEMON (1 << 16) // AI has Ace Pokemon. The last Pokemon in the party will not used until last remaining. +//#define AI_FLAG_ACE_POKEMON (1 << 16) // AI has Ace Pokemon. The last Pokemon in the party will not used until last remaining. // 'other' ai logic flags #define AI_FLAG_ROAMING (1 << 29) diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 7493be32b..6642810cf 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -109,9 +109,9 @@ static bool8 ShouldSwitchIfWonderGuard(void) continue; if (i == gBattlerPartyIndexes[gActiveBattler]) continue; - if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON + /*if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON && i == (CalculateEnemyPartyCount()-1)) - continue; + continue;*/ for (opposingBattler = GetBattlerAtPosition(opposingPosition), j = 0; j < MAX_MON_MOVES; j++) { @@ -202,9 +202,9 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) continue; if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; - if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON + /*if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON && i == (CalculateEnemyPartyCount()-1)) - continue; + continue;*/ species = GetMonData(&party[i], MON_DATA_SPECIES); @@ -283,9 +283,9 @@ static bool8 ShouldSwitchIfGameStatePrompt(void) for (i = firstId; i < lastId; i++) { - if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON + /*if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON && i == (CalculateEnemyPartyCount()-1)) - break; + break;*/ //Look for mon in party that is able to be switched into and has ability that sets terrain if (GetMonData(&party[i], MON_DATA_HP) != 0 @@ -574,9 +574,9 @@ static bool8 FindMonWithFlagsAndSuperEffective(u16 flags, u8 moduloPercent) continue; if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; - if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON + /*if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON && i == (CalculateEnemyPartyCount()-1)) - continue; + continue;*/ species = GetMonData(&party[i], MON_DATA_SPECIES); @@ -666,9 +666,9 @@ bool32 ShouldSwitch(void) continue; if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; - if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON + /*if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON && i == (CalculateEnemyPartyCount()-1)) - continue; + continue;*/ availableToSwitch++; } @@ -756,9 +756,9 @@ void AI_TrySwitchOrUseItem(void) continue; if (monToSwitchId == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; - if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON + /*if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON && monToSwitchId == (CalculateEnemyPartyCount()-1)) - continue; + continue;*/ break; } @@ -957,8 +957,8 @@ u8 GetMostSuitableMonToSwitchInto(void) || i == *(gBattleStruct->monToSwitchIntoId + battlerIn1) || i == *(gBattleStruct->monToSwitchIntoId + battlerIn2) || (GetMonAbility(&party[i]) == ABILITY_TRUANT && IsTruantMonVulnerable(gActiveBattler, opposingBattler)) // While not really invalid per say, not really wise to switch into this mon. - || (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON - && i == (CalculateEnemyPartyCount()-1))) //Save Ace Pokemon for last + /*|| (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON + && i == (CalculateEnemyPartyCount()-1))*/) //Save Ace Pokemon for last invalidMons |= gBitTable[i]; else aliveCount++; diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 07cf95589..7cd44d709 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -1699,9 +1699,9 @@ static void OpponentHandleChoosePokemon(void) if (GetMonData(&gEnemyParty[chosenMonId], MON_DATA_HP) != 0 && chosenMonId != gBattlerPartyIndexes[battler1] && chosenMonId != gBattlerPartyIndexes[battler2] - && (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON + /*&& (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON && (!(chosenMonId == (CalculateEnemyPartyCount()-1)) - || CountAIAliveNonEggMonsExcept(PARTY_SIZE) == pokemonInBattle))) + || CountAIAliveNonEggMonsExcept(PARTY_SIZE) == pokemonInBattle))*/) { break; } From 293a880238b6e8707f43fd0d5d7dea3eeb4b9c7a Mon Sep 17 00:00:00 2001 From: Eduardo Quezada D'Ottone Date: Sun, 18 Sep 2022 00:50:21 -0300 Subject: [PATCH 2/3] Apply suggestions from code review --- include/constants/battle_ai.h | 2 +- src/battle_ai_switch_items.c | 28 ++++++++++++++-------------- src/battle_controller_opponent.c | 6 +++--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/constants/battle_ai.h b/include/constants/battle_ai.h index e45ce035c..1cfb9cd4d 100644 --- a/include/constants/battle_ai.h +++ b/include/constants/battle_ai.h @@ -56,7 +56,7 @@ #define AI_FLAG_STALL (1 << 13) // AI stalls battle and prefers secondary damage/trapping/etc. TODO not finished #define AI_FLAG_SCREENER (1 << 14) // AI prefers screening effects like reflect, mist, etc. TODO unfinished #define AI_FLAG_SMART_SWITCHING (1 << 15) // AI includes a lot more switching checks -//#define AI_FLAG_ACE_POKEMON (1 << 16) // AI has Ace Pokemon. The last Pokemon in the party will not used until last remaining. +#define AI_FLAG_ACE_POKEMON (1 << 16) // AI has an Ace Pokemon. The last Pokemon in the party will not be used until it's the last one remaining. // 'other' ai logic flags #define AI_FLAG_ROAMING (1 << 29) diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 6642810cf..6f5de84c4 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -109,9 +109,9 @@ static bool8 ShouldSwitchIfWonderGuard(void) continue; if (i == gBattlerPartyIndexes[gActiveBattler]) continue; - /*if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON + if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON && i == (CalculateEnemyPartyCount()-1)) - continue;*/ + continue; for (opposingBattler = GetBattlerAtPosition(opposingPosition), j = 0; j < MAX_MON_MOVES; j++) { @@ -202,9 +202,9 @@ static bool8 FindMonThatAbsorbsOpponentsMove(void) continue; if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; - /*if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON + if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON && i == (CalculateEnemyPartyCount()-1)) - continue;*/ + continue; species = GetMonData(&party[i], MON_DATA_SPECIES); @@ -283,9 +283,9 @@ static bool8 ShouldSwitchIfGameStatePrompt(void) for (i = firstId; i < lastId; i++) { - /*if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON + if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON && i == (CalculateEnemyPartyCount()-1)) - break;*/ + break; //Look for mon in party that is able to be switched into and has ability that sets terrain if (GetMonData(&party[i], MON_DATA_HP) != 0 @@ -574,9 +574,9 @@ static bool8 FindMonWithFlagsAndSuperEffective(u16 flags, u8 moduloPercent) continue; if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; - /*if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON + if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON && i == (CalculateEnemyPartyCount()-1)) - continue;*/ + continue; species = GetMonData(&party[i], MON_DATA_SPECIES); @@ -666,9 +666,9 @@ bool32 ShouldSwitch(void) continue; if (i == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; - /*if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON + if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON && i == (CalculateEnemyPartyCount()-1)) - continue;*/ + continue; availableToSwitch++; } @@ -756,9 +756,9 @@ void AI_TrySwitchOrUseItem(void) continue; if (monToSwitchId == *(gBattleStruct->monToSwitchIntoId + battlerIn2)) continue; - /*if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON + if (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON && monToSwitchId == (CalculateEnemyPartyCount()-1)) - continue;*/ + continue; break; } @@ -957,8 +957,8 @@ u8 GetMostSuitableMonToSwitchInto(void) || i == *(gBattleStruct->monToSwitchIntoId + battlerIn1) || i == *(gBattleStruct->monToSwitchIntoId + battlerIn2) || (GetMonAbility(&party[i]) == ABILITY_TRUANT && IsTruantMonVulnerable(gActiveBattler, opposingBattler)) // While not really invalid per say, not really wise to switch into this mon. - /*|| (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON - && i == (CalculateEnemyPartyCount()-1))*/) //Save Ace Pokemon for last + || ((AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON) + && i == (CalculateEnemyPartyCount() - 1))) //Save Ace Pokemon for last invalidMons |= gBitTable[i]; else aliveCount++; diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 7cd44d709..bf8f7f869 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -1699,9 +1699,9 @@ static void OpponentHandleChoosePokemon(void) if (GetMonData(&gEnemyParty[chosenMonId], MON_DATA_HP) != 0 && chosenMonId != gBattlerPartyIndexes[battler1] && chosenMonId != gBattlerPartyIndexes[battler2] - /*&& (AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON - && (!(chosenMonId == (CalculateEnemyPartyCount()-1)) - || CountAIAliveNonEggMonsExcept(PARTY_SIZE) == pokemonInBattle))*/) + && (!(AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON) + || chosenMonId != CalculateEnemyPartyCount() - 1 + || CountAIAliveNonEggMonsExcept(PARTY_SIZE) == pokemonInBattle)) { break; } From 41ae8ecdb7625c80c42ebf3a74e23cb12ae7124b Mon Sep 17 00:00:00 2001 From: Eduardo Quezada D'Ottone Date: Sun, 18 Sep 2022 00:51:34 -0300 Subject: [PATCH 3/3] Update src/battle_controller_opponent.c --- src/battle_controller_opponent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index bf8f7f869..5a307cfc9 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -1701,7 +1701,7 @@ static void OpponentHandleChoosePokemon(void) && chosenMonId != gBattlerPartyIndexes[battler2] && (!(AI_THINKING_STRUCT->aiFlags & AI_FLAG_ACE_POKEMON) || chosenMonId != CalculateEnemyPartyCount() - 1 - || CountAIAliveNonEggMonsExcept(PARTY_SIZE) == pokemonInBattle)) + || CountAIAliveNonEggMonsExcept(PARTY_SIZE) == pokemonInBattle)) { break; }