From f4dc5e931f7acf667178f6da84cbd55a0c256ee0 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 18 Jul 2023 12:01:25 +0200 Subject: [PATCH] some more stuff --- include/battle_ai_util.h | 2 ++ src/battle_ai_switch_items.c | 25 +++++++++++++++++-------- src/battle_ai_util.c | 28 ++++++++++++++++++---------- src/data/trainer_parties.h | 34 ++++++++++------------------------ src/data/trainers.h | 2 +- 5 files changed, 48 insertions(+), 43 deletions(-) diff --git a/include/battle_ai_util.h b/include/battle_ai_util.h index 0800e1cfb..fd55a99f7 100644 --- a/include/battle_ai_util.h +++ b/include/battle_ai_util.h @@ -168,6 +168,8 @@ bool32 PartnerMoveIsSameNoTarget(u8 battlerAtkPartner, u16 move, u16 partnerMove bool32 ShouldUseWishAromatherapy(u8 battlerAtk, u8 battlerDef, u16 move); // party logic +struct BattlePokemon *AllocSaveBattleMons(void); +void FreeRestoreBattleMons(struct BattlePokemon *savedBattleMons); s32 AI_CalcPartyMonBestMoveDamage(u32 battlerAtk, u32 battlerDef, struct Pokemon *attackerMon, struct Pokemon *targetMon); s32 CountUsablePartyMons(u8 battlerId); bool32 IsPartyFullyHealedExceptBattler(u8 battler); diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 2418dbab8..625634af4 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -788,7 +788,7 @@ void AI_TrySwitchOrUseItem(void) // If there are two(or more) mons to choose from, always choose one that has baton pass // as most often it can't do much on its own. -static u32 GetBestMonBatonPass(struct Pokemon *party, int firstId, int lastId, u8 invalidMons, int aliveCount) +static u32 GetBestMonBatonPass(struct Pokemon *party, int firstId, int lastId, u8 invalidMons, int aliveCount, u32 opposingBattler) { int i, j, bits = 0; @@ -796,7 +796,7 @@ static u32 GetBestMonBatonPass(struct Pokemon *party, int firstId, int lastId, u { if (invalidMons & gBitTable[i]) continue; - if (IsAiPartyMonOHKOBy(BATTLE_OPPOSITE(gActiveBattler), &party[i])) + if (IsAiPartyMonOHKOBy(opposingBattler, &party[i])) continue; for (j = 0; j < MAX_MON_MOVES; j++) @@ -980,7 +980,7 @@ u8 GetMostSuitableMonToSwitchInto(void) } } - bestMonId = GetBestMonBatonPass(party, firstId, lastId, invalidMons, aliveCount); + bestMonId = GetBestMonBatonPass(party, firstId, lastId, invalidMons, aliveCount, opposingBattler); if (bestMonId != PARTY_SIZE) return bestMonId; @@ -1161,17 +1161,26 @@ static bool32 AI_OpponentCanFaintAiWithMod(u32 healAmount) static bool32 IsAiPartyMonOHKOBy(u32 battlerAtk, struct Pokemon *aiMon) { - struct BattlePokemon *battleMon; + bool32 ret = FALSE; + struct BattlePokemon *savedBattleMons; s32 hp = GetMonData(aiMon, MON_DATA_HP); s32 bestDmg = AI_CalcPartyMonBestMoveDamage(battlerAtk, gActiveBattler, NULL, aiMon); switch (GetNoOfHitsToKO(bestDmg, hp)) { case 1: - return TRUE; - case 2: // TODO: Compare speeds, if AI mon is faster allow 2 turns - return TRUE; + ret = TRUE; + break; + case 2: // if AI mon is faster allow 2 turns + savedBattleMons = AllocSaveBattleMons(); + PokemonToBattleMon(aiMon, &gBattleMons[gActiveBattler]); + if (AI_WhoStrikesFirst(gActiveBattler, battlerAtk, 0) == AI_IS_SLOWER) + ret = TRUE; + else + ret = FALSE; + FreeRestoreBattleMons(savedBattleMons); + break; } - return FALSE; + return ret; } diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index 036e9e4f6..66acaacfb 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -3368,16 +3368,27 @@ bool32 ShouldUseWishAromatherapy(u8 battlerAtk, u8 battlerDef, u16 move) return FALSE; } +#define SIZE_G_BATTLE_MONS (sizeof(struct BattlePokemon) * MAX_BATTLERS_COUNT) + +struct BattlePokemon *AllocSaveBattleMons(void) +{ + struct BattlePokemon *savedBattleMons = Alloc(SIZE_G_BATTLE_MONS); + memcpy(savedBattleMons, gBattleMons, SIZE_G_BATTLE_MONS); + return savedBattleMons; +} + +void FreeRestoreBattleMons(struct BattlePokemon *savedBattleMons) +{ + memcpy(gBattleMons, savedBattleMons, SIZE_G_BATTLE_MONS); + Free(savedBattleMons); +} + // party logic s32 AI_CalcPartyMonBestMoveDamage(u32 battlerAtk, u32 battlerDef, struct Pokemon *attackerMon, struct Pokemon *targetMon) { - s32 bestDmg, dmg; - u32 i, move; + s32 i, move, bestDmg, dmg; u8 effectiveness; - struct BattlePokemon *battleMons = Alloc(sizeof(struct BattlePokemon) * MAX_BATTLERS_COUNT); - - for (i = 0; i < MAX_BATTLERS_COUNT; i++) - battleMons[i] = gBattleMons[i]; + struct BattlePokemon *savedBattleMons = AllocSaveBattleMons(); if (attackerMon != NULL) PokemonToBattleMon(attackerMon, &gBattleMons[battlerAtk]); @@ -3399,10 +3410,7 @@ s32 AI_CalcPartyMonBestMoveDamage(u32 battlerAtk, u32 battlerDef, struct Pokemon } } - for (i = 0; i < MAX_BATTLERS_COUNT; i++) - gBattleMons[i] = battleMons[i]; - - Free(battleMons); + FreeRestoreBattleMons(savedBattleMons); return dmg; } diff --git a/src/data/trainer_parties.h b/src/data/trainer_parties.h index a0e45ca0c..1759120b7 100644 --- a/src/data/trainer_parties.h +++ b/src/data/trainer_parties.h @@ -3366,39 +3366,25 @@ static const struct TrainerMonItemCustomMoves sParty_Drake[] = { static const struct TrainerMonItemCustomMoves sParty_Roxanne1[] = { { - .iv = 46, - .lvl = 46, - .species = SPECIES_SKARMORY, + .iv = 100, + .lvl = 12, + .species = SPECIES_GEODUDE, .heldItem = ITEM_NONE, - .moves = {MOVE_SPIKES, MOVE_TOXIC, MOVE_WHIRLWIND, MOVE_ROOST} + .moves = {MOVE_TACKLE, MOVE_DEFENSE_CURL, MOVE_ROCK_THROW, MOVE_ROCK_TOMB} }, { .iv = 100, - .lvl = 46, - .species = SPECIES_TROPIUS, + .lvl = 12, + .species = SPECIES_GEODUDE, .heldItem = ITEM_NONE, - .moves = {MOVE_LEAF_TORNADO, MOVE_BODY_SLAM, MOVE_PROTECT, MOVE_ROOST} - }, - { - .iv = 47, - .lvl = 47, - .species = SPECIES_HAWLUCHA, - .heldItem = ITEM_ORAN_BERRY, - .moves = {MOVE_SUPERPOWER, MOVE_ACROBATICS, MOVE_U_TURN, MOVE_ROOST} - }, - { - .iv = 47, - .lvl = 47, - .species = SPECIES_MANTINE, - .heldItem = ITEM_ORAN_BERRY, - .moves = {MOVE_CONFUSE_RAY, MOVE_WATER_PULSE, MOVE_AIR_SLASH, MOVE_ROOST} + .moves = {MOVE_TACKLE, MOVE_DEFENSE_CURL, MOVE_ROCK_THROW, MOVE_ROCK_TOMB} }, { .iv = 200, - .lvl = 48, - .species = SPECIES_ALTARIA, + .lvl = 15, + .species = SPECIES_NOSEPASS, .heldItem = ITEM_ORAN_BERRY, - .moves = {MOVE_DRAGON_PULSE, MOVE_TOXIC, MOVE_COTTON_GUARD, MOVE_ROOST} + .moves = {MOVE_BLOCK, MOVE_HARDEN, MOVE_TACKLE, MOVE_ROCK_TOMB} } }; diff --git a/src/data/trainers.h b/src/data/trainers.h index 22d4a4880..75f7edc8b 100644 --- a/src/data/trainers.h +++ b/src/data/trainers.h @@ -3189,7 +3189,7 @@ const struct Trainer gTrainers[] = { .trainerName = _("ROXANNE"), .items = {ITEM_POTION, ITEM_POTION, ITEM_NONE, ITEM_NONE}, .doubleBattle = FALSE, - .aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_CHECK_VIABILITY | AI_FLAG_RISKY, + .aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_CHECK_VIABILITY, .party = ITEM_CUSTOM_MOVES(sParty_Roxanne1), },