Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smarter SwitchAI Mon Choices | HasBadOdds Switch Check #3253

Merged
merged 52 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
9f39074
SwitchAI makes much smarter mon choices
Pawkkie Aug 25, 2023
e07bbed
Add HasHadOdds check to ShouldSwitch decision
Pawkkie Aug 25, 2023
f00a741
Remove early return
Pawkkie Aug 25, 2023
5ca7d39
Rework Baton Pass check as per discussion with Alex
Pawkkie Aug 25, 2023
4fb99b4
Forgot to adjust a comment
Pawkkie Aug 25, 2023
0afce4c
Don't program before breakfast lol (if / else if fix)
Pawkkie Aug 25, 2023
5f838b4
Switch AI_CalcDamage for AI_DATA->simulatedDmg in HasBadOdds
Pawkkie Aug 25, 2023
838f1ba
Typo in a hitToKO comparison
Pawkkie Aug 25, 2023
ebb8c7a
Remove and replace AI_CalcPartyMonBestMoveDamage and IsAiPartyMonOHKO…
Pawkkie Aug 26, 2023
3414c8f
Major refactor, new struct, switchin considers damage / healing from …
Pawkkie Aug 28, 2023
c33ab70
Forgot Snow exists and heals Ice Body, haven't played Switch games lol
Pawkkie Aug 28, 2023
8487482
Merge remote-tracking branch 'upstream/master' into release
Pawkkie Aug 29, 2023
3b4785a
(https://github.com/rh-hideout/pokeemerald-expansion/commit/766a1a27a…
Pawkkie Aug 29, 2023
cc7312e
Fixing oversight from previous upstream merge
Pawkkie Aug 29, 2023
1dd6df2
Improve TSpikes handling to make GetSwitchinHazardDamage more applicable
Pawkkie Aug 29, 2023
13c7cb8
Forgot to uncomment blocks disabled for debugging what turned out to …
Pawkkie Aug 29, 2023
eb310ab
Remove another holdover from debugging, sorry :/
Pawkkie Aug 29, 2023
8b30988
Lastly, undoing my debug trainer
Pawkkie Aug 29, 2023
b4a8348
Type matchup based on species type rather than current type
Pawkkie Aug 31, 2023
675ead3
Merge remote-tracking branch 'upstream/master' into switchAI-smart-mo…
Pawkkie Sep 1, 2023
9cc05a9
Merge remote-tracking branch 'upstream/upcoming' into switchAI-smart-…
Pawkkie Sep 1, 2023
3afad86
Merge remote-tracking branch 'upstream/upcoming' into switchAI-smart-…
Pawkkie Sep 4, 2023
7d3c2ff
gActiveBattler upcoming merge fixes
Pawkkie Sep 4, 2023
f18ce21
Egg changes part 1
Pawkkie Sep 4, 2023
b3f0271
Egg changes part 2, just need to address EWRAM still
Pawkkie Sep 8, 2023
5ac6057
Merge remote-tracking branch 'upstream/upcoming' into switchAI-smart-…
Pawkkie Sep 8, 2023
a901e75
Move SwitchinCandidate struct to AiLogicData
Pawkkie Sep 10, 2023
6f27811
Merge remote-tracking branch 'upstream/upcoming' into switchAI-smart-…
Pawkkie Sep 10, 2023
403b523
Consider Steel type when checking TSpikes
Pawkkie Sep 10, 2023
9e91950
Merge remote-tracking branch 'upstream/upcoming' into switchAI-smart-…
Pawkkie Sep 11, 2023
9b37a68
Comment about CanBePoisoned compatibility
Pawkkie Sep 11, 2023
a93a9cd
Changes for Egg's 2nd review
Pawkkie Sep 11, 2023
7c20d15
Put period back in comment, whoops lol
Pawkkie Sep 12, 2023
743b604
Merge remote-tracking branch 'upstream/upcoming' into switchAI-smart-…
Pawkkie Sep 26, 2023
07de6ce
Latest upcoming merge fixes
Pawkkie Sep 26, 2023
cf0151a
Missed a few u32 updates
Pawkkie Sep 27, 2023
3587fa7
Merge remote-tracking branch 'upstream/upcoming' into switchAI-smart-…
Pawkkie Oct 1, 2023
bedb1f4
Merge remote-tracking branch 'upstream/upcoming' into switchAI-smart-…
Pawkkie Oct 3, 2023
27c057f
Combine GetBestMonIntegrate functions / flags, some modularization
Pawkkie Oct 5, 2023
2d749a7
Merge remote-tracking branch 'upstream/upcoming' into switchAI-smart-…
Pawkkie Oct 5, 2023
d4cdd2f
Merge remote-tracking branch 'upstream/upcoming' into switchAI-smart-…
Pawkkie Oct 13, 2023
2946db9
Merge remote-tracking branch 'upstream/upcoming' into switchAI-smart-…
Pawkkie Oct 13, 2023
1d9ba79
Fix merge error
Pawkkie Oct 13, 2023
9053285
Make modern fixes
Pawkkie Oct 13, 2023
9dceb91
Merge remote-tracking branch 'upstream/upcoming' into switchAI-smart-…
Pawkkie Oct 23, 2023
8c458fc
Merge remote-tracking branch 'upstream/upcoming' into switchAI-smart-…
Pawkkie Oct 25, 2023
cfb92ba
Two tests done, two to go
Pawkkie Oct 29, 2023
2fda5ab
Accidentally pushed reference test, removing it
Pawkkie Oct 29, 2023
1c0c28e
Type matchup switching tests
Pawkkie Nov 6, 2023
9178f7b
Tests for defensive vs offense switches
Pawkkie Nov 6, 2023
864f057
Merge remote-tracking branch 'upstream/upcoming' into switchAI-smart-…
Pawkkie Nov 6, 2023
7e07985
Merge branch 'upcoming' into switchAI-smart-mon-choices
DizzyEggg Nov 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ struct AI_ThinkingStruct
u32 aiFlags;
u8 aiAction;
u8 aiLogicId;
u8 mostSuitableMonId; // Stores result of GetMostSuitableMonToSwitchInto, which decides which generic mon the AI would switch into if they decide to switch. This can be overruled by specific mons found in ShouldSwitch; the final resulting mon is stored in AI_monToSwitchIntoId.
struct AI_SavedBattleMon saved[MAX_BATTLERS_COUNT];
bool8 switchMon; // Because all available moves have no/little effect.
Pawkkie marked this conversation as resolved.
Show resolved Hide resolved
};

#define AI_MOVE_HISTORY_COUNT 3
Expand Down
2 changes: 1 addition & 1 deletion include/battle_ai_switch_items.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

void GetAIPartyIndexes(u32 battlerId, s32 *firstId, s32 *lastId);
void AI_TrySwitchOrUseItem(void);
u8 GetMostSuitableMonToSwitchInto(void);
u8 GetMostSuitableMonToSwitchInto(bool8 switchAfterMonKOd);
bool32 ShouldSwitch(void);

#endif // GUARD_BATTLE_AI_SWITCH_ITEMS_H
45 changes: 44 additions & 1 deletion include/battle_ai_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ 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);
bool32 PartyHasMoveSplit(u8 battlerId, u8 split);
Expand All @@ -186,4 +185,48 @@ void IncreaseSleepScore(u8 battlerAtk, u8 battlerDef, u16 move, s16 *score);
void IncreaseConfusionScore(u8 battlerAtk, u8 battlerDef, u16 move, s16 *score);
void IncreaseFrostbiteScore(u8 battlerAtk, u8 battlerDef, u16 move, s16 *score);

struct SwitchinCandidate
{
u16 species;
u16 attack;
u16 defense;
u16 speed;
u16 spAttack;
u16 spDefense;
u16 moves[MAX_MON_MOVES];
u32 hpIV:5;
u32 attackIV:5;
u32 defenseIV:5;
u32 speedIV:5;
u32 spAttackIV:5;
u32 spDefenseIV:5;
u32 abilityNum:2;
s8 statStages[NUM_BATTLE_STATS];
u16 ability;
u8 type1;
u8 type2;
u8 type3;
u8 pp[MAX_MON_MOVES];
u16 hp;
u8 level;
u8 friendship;
u16 maxHP;
u16 item;
u8 nickname[POKEMON_NAME_LENGTH + 1];
u8 ppBonuses;
u8 otName[PLAYER_NAME_LENGTH + 1];
u32 experience;
u32 personality;
u32 status1;
u32 status2;
u32 otId;
u8 metLevel;
bool8 hypotheticalStatus;
};

extern struct SwitchinCandidate switchinCandidate;

void SwitchinCandidateToBattleMon(struct SwitchinCandidate *switchinCandidate, struct BattlePokemon *dst);
s32 AI_CalcPartyMonDamage(u16 move, u8 battlerAtk, u8 battlerDef, struct SwitchinCandidate *switchinCandidate, bool8 isPartyMonAttacker);

#endif //GUARD_BATTLE_AI_UTIL_H
2 changes: 2 additions & 0 deletions include/constants/battle_ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
#define AI_FLAG_SMART_SWITCHING (1 << 15) // AI includes a lot more switching checks
#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.
#define AI_FLAG_OMNISCIENT (1 << 17) // AI has full knowledge of player moves, abilities, hold items
#define AI_FLAG_SMART_MON_CHOICES (1 << 18) // AI will make smarter decisions when choosing which mon to send out mid-battle. Pairs very well with AI_FLAG_SMART_SWITCHING.
Pawkkie marked this conversation as resolved.
Show resolved Hide resolved
#define AI_FLAG_SMART_MON_CHOICES_KO (1 << 19) // AI will make smarter decisions when choosing which mon to send out after previous mon was KO'd. Functions just fine on its own, but pairs well with the other smart AI flags for more challenging AI overall.

#define AI_FLAG_COUNT 18

Expand Down
14 changes: 14 additions & 0 deletions include/constants/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,20 @@
#define ITEM_UTILITY_UMBRELLA 513

// Berries
#if B_CONFUSE_BERRIES_HEAL >= GEN_8
#define CONFUSE_BERRY_HEAL_FRACTION 3
#elif B_CONFUSE_BERRIES_HEAL == GEN_7
#define CONFUSE_BERRY_HEAL_FRACTION 2
#else
#define CONFUSE_BERRY_HEAL_FRACTION 8
#endif

#if B_CONFUSE_BERRIES_HEAL >= GEN_7
#define CONFUSE_BERRY_HP_FRACTION 4
#else
#define CONFUSE_BERRY_HP_FRACTION 2
#endif

#define ITEM_CHERI_BERRY 514
#define ITEM_CHESTO_BERRY 515
#define ITEM_PECHA_BERRY 516
Expand Down
6 changes: 4 additions & 2 deletions src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,12 @@ void BattleAI_SetupAIData(u8 defaultScoreMoves)
s32 i, move, dmg;
u8 moveLimitations;

// Clear AI data but preserve the flags.
// Clear AI data but preserve the flags and most suitable mon (pre-calculated in HandleTurnActionSelectionState).
Pawkkie marked this conversation as resolved.
Show resolved Hide resolved
u8 mostSuitableMonId = AI_THINKING_STRUCT->mostSuitableMonId;
Pawkkie marked this conversation as resolved.
Show resolved Hide resolved
u32 flags = AI_THINKING_STRUCT->aiFlags;
memset(AI_THINKING_STRUCT, 0, sizeof(struct AI_ThinkingStruct));
AI_THINKING_STRUCT->aiFlags = flags;
AI_THINKING_STRUCT->mostSuitableMonId = mostSuitableMonId;

// Conditional score reset, unlike Ruby.
for (i = 0; i < MAX_MON_MOVES; i++)
Expand Down Expand Up @@ -401,7 +403,7 @@ void GetAiLogicData(void)

static bool32 AI_SwitchMonIfSuitable(u32 battlerId)
{
u32 monToSwitchId = GetMostSuitableMonToSwitchInto();
u32 monToSwitchId = AI_THINKING_STRUCT->mostSuitableMonId;
if (monToSwitchId != PARTY_SIZE)
{
AI_DATA->shouldSwitchMon |= gBitTable[battlerId];
Expand Down
Loading
Loading