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 all 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
8 changes: 8 additions & 0 deletions include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ struct AIPartyData // Opposing battlers - party mons.
u8 count[NUM_BATTLE_SIDES];
};

struct SwitchinCandidate
{
struct BattlePokemon battleMon;
bool8 hypotheticalStatus;
};

// Ai Data used when deciding which move to use, computed only once before each turn's start.
struct AiLogicData
{
Expand All @@ -308,6 +314,8 @@ struct AiLogicData
bool8 shouldSwitchMon; // Because all available moves have no/little effect. Each bit per battler.
u8 monToSwitchId[MAX_BATTLERS_COUNT]; // ID of the mon to switch.
bool8 weatherHasEffect; // The same as WEATHER_HAS_EFFECT. Stored here, so it's called only once.
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 SwitchinCandidate switchinCandidate; // Struct used for deciding which mon to switch to in battle_ai_switch_items.c
};

struct AI_ThinkingStruct
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(u32 battler);
u8 GetMostSuitableMonToSwitchInto(u32 battler);
u8 GetMostSuitableMonToSwitchInto(u32 battler, bool32 switchAfterMonKOd);
bool32 ShouldSwitch(u32 battler);

#endif // GUARD_BATTLE_AI_SWITCH_ITEMS_H
3 changes: 2 additions & 1 deletion include/battle_ai_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ bool32 ShouldUseWishAromatherapy(u32 battlerAtk, u32 battlerDef, u32 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(u32 battlerId);
bool32 IsPartyFullyHealedExceptBattler(u32 battler);
bool32 PartyHasMoveSplit(u32 battlerId, u32 split);
Expand All @@ -189,4 +188,6 @@ void IncreaseSleepScore(u32 battlerAtk, u32 battlerDef, u32 move, s32 *score);
void IncreaseConfusionScore(u32 battlerAtk, u32 battlerDef, u32 move, s32 *score);
void IncreaseFrostbiteScore(u32 battlerAtk, u32 battlerDef, u32 move, s32 *score);

s32 AI_CalcPartyMonDamage(u32 move, u32 battlerAtk, u32 battlerDef, struct BattlePokemon switchinCandidate, bool8 isPartyMonAttacker);

#endif //GUARD_BATTLE_AI_UTIL_H
1 change: 1 addition & 0 deletions include/constants/battle_ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#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 and after a KO, which are separate decisions. Pairs very well with AI_FLAG_SMART_SWITCHING.

#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
2 changes: 1 addition & 1 deletion src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ void SetAiLogicDataForTurn(struct AiLogicData *aiData)

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