Skip to content

Commit

Permalink
AI_FLAG_SETUP_FIRST_TURN Rename and Clarifications (#5310)
Browse files Browse the repository at this point in the history
* Rename AI_FLAG_SETUP_FIRST_TURN

* Update all AI flags with comments
  • Loading branch information
Pawkkie authored Sep 4, 2024
1 parent 7c7fd90 commit 720bc64
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 50 deletions.
4 changes: 2 additions & 2 deletions docs/ai_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ This flag is divided into two components to calculate the best available move fo

This is different to `AI_FLAG_CHECK_BAD_MOVE` as it calculates how poor a move is and not whether it will fail or not.

## `AI_FLAG_SETUP_FIRST_TURN`
AI will prioritize using setup moves on the first turn. These include stat buffs, field effects, status moves, etc.
## `AI_FLAG_FORCE_SETUP_FIRST_TURN`
AI will prioritize using setup moves on the first turn at the expense of all else. These include stat buffs, field effects, status moves, etc. AI_FLAG_CHECK_VIABILITY will instead do this when the AI determines it makes sense.

This is just a flat increase without any consideration of whether it makes sense to use the move or not. For better move choice quality for those moves, `AI_FLAG_CHECK_VIABILITY` should be used.

Expand Down
35 changes: 18 additions & 17 deletions include/constants/battle_ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,29 @@
#define AI_EFFECTIVENESS_x0 0

// AI Flags. Most run specific functions to update score, new flags are used for internal logic in other scripts
#define AI_FLAG_CHECK_BAD_MOVE (1 << 0)
#define AI_FLAG_TRY_TO_FAINT (1 << 1)
#define AI_FLAG_CHECK_VIABILITY (1 << 2)
#define AI_FLAG_SETUP_FIRST_TURN (1 << 3)
#define AI_FLAG_RISKY (1 << 4)
#define AI_FLAG_PREFER_STRONGEST_MOVE (1 << 5)
#define AI_FLAG_PREFER_BATON_PASS (1 << 6)
#define AI_FLAG_DOUBLE_BATTLE (1 << 7) // Automatically set for double battles, handles AI behaviour with partner
#define AI_FLAG_HP_AWARE (1 << 8)
#define AI_FLAG_POWERFUL_STATUS (1 << 9) // AI prefers moves that set up field effects or side statuses, even if the user can faint the target
// See docs/ai_flags.md for more details.
#define AI_FLAG_CHECK_BAD_MOVE (1 << 0) // AI will avoid using moves that are likely to fail or be ineffective in the current situation.
#define AI_FLAG_TRY_TO_FAINT (1 << 1) // AI will prioritize KOing the player's mon if able.
#define AI_FLAG_CHECK_VIABILITY (1 << 2) // AI damaging moves and move effects to determine the best available move in the current situation.
#define AI_FLAG_FORCE_SETUP_FIRST_TURN (1 << 3) // AI will prioritize using setup moves on the first turn at the expensve of all else. AI_FLAG_CHECK_VIABILITY will instead do this when the AI determines it makes sense.
#define AI_FLAG_RISKY (1 << 4) // AI will generally behave more recklessly, prioritizing damage over accuracy, explosions, etc.
#define AI_FLAG_PREFER_STRONGEST_MOVE (1 << 5) // AI adds score bonus to any move the AI has that either OHKOs or 2HKOs the player.
#define AI_FLAG_PREFER_BATON_PASS (1 << 6) // AI prefers raising its own stats and setting for / using Baton Pass.
#define AI_FLAG_DOUBLE_BATTLE (1 << 7) // Automatically set for double battles, handles AI behaviour with partner.
#define AI_FLAG_HP_AWARE (1 << 8) // AI will favour certain move effects based on how much remaining HP it and the player's mon have.
#define AI_FLAG_POWERFUL_STATUS (1 << 9) // AI prefers moves that set up field effects or side statuses, even if the user can faint the target.
// New, Trainer Handicap Flags
#define AI_FLAG_NEGATE_UNAWARE (1 << 10) // AI is NOT aware of negating effects like wonder room, mold breaker, etc
#define AI_FLAG_WILL_SUICIDE (1 << 11) // AI will use explosion / self destruct / final gambit / etc
#define AI_FLAG_NEGATE_UNAWARE (1 << 10) // AI is NOT aware of negating effects like wonder room, mold breaker, etc.
#define AI_FLAG_WILL_SUICIDE (1 << 11) // AI will use explosion / self destruct / final gambit / etc.
// New, Trainer Strategy Flags
#define AI_FLAG_PREFER_STATUS_MOVES (1 << 12) // AI gets a score bonus for status moves. Should be combined with AI_FLAG_CHECK_BAD_MOVE to prevent using only status moves
#define AI_FLAG_STALL (1 << 13) // AI stalls battle and prefers secondary damage/trapping/etc. TODO not finished
#define AI_FLAG_PREFER_STATUS_MOVES (1 << 12) // AI gets a score bonus for status moves. Should be combined with AI_FLAG_CHECK_BAD_MOVE to prevent using only status moves.
#define AI_FLAG_STALL (1 << 13) // AI stalls battle and prefers secondary damage/trapping/etc. TODO not finished.
#define AI_FLAG_SMART_SWITCHING (1 << 14) // AI includes a lot more switching checks. Automatically includes AI_FLAG_SMART_MON_CHOICES.
#define AI_FLAG_ACE_POKEMON (1 << 15) // 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 << 16) // AI has full knowledge of player moves, abilities, hold items
#define AI_FLAG_OMNISCIENT (1 << 16) // AI has full knowledge of player moves, abilities, hold items.
#define AI_FLAG_SMART_MON_CHOICES (1 << 17) // AI will make smarter decisions when choosing which mon to send out mid-battle and after a KO, which are separate decisions. Automatically included by AI_FLAG_SMART_SWITCHING.
#define AI_FLAG_CONSERVATIVE (1 << 18) // AI assumes all moves will low roll damage
#define AI_FLAG_SEQUENCE_SWITCHING (1 << 19) // AI switches in mons in exactly party order, and never switches mid-battle
#define AI_FLAG_CONSERVATIVE (1 << 18) // AI assumes all moves will low roll damage.
#define AI_FLAG_SEQUENCE_SWITCHING (1 << 19) // AI switches in mons in exactly party order, and never switches mid-battle.

#define AI_FLAG_COUNT 20

Expand Down
6 changes: 3 additions & 3 deletions src/battle_ai_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ EWRAM_DATA AiScoreFunc sDynamicAiFunc = NULL;
static s32 AI_CheckBadMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score);
static s32 AI_TryToFaint(u32 battlerAtk, u32 battlerDef, u32 move, s32 score);
static s32 AI_CheckViability(u32 battlerAtk, u32 battlerDef, u32 move, s32 score);
static s32 AI_SetupFirstTurn(u32 battlerAtk, u32 battlerDef, u32 move, s32 score);
static s32 AI_ForceSetupFirstTurn(u32 battlerAtk, u32 battlerDef, u32 move, s32 score);
static s32 AI_Risky(u32 battlerAtk, u32 battlerDef, u32 move, s32 score);
static s32 AI_PreferStrongestMove(u32 battlerAtk, u32 battlerDef, u32 move, s32 score);
static s32 AI_PreferBatonPass(u32 battlerAtk, u32 battlerDef, u32 move, s32 score);
Expand All @@ -64,7 +64,7 @@ static s32 (*const sBattleAiFuncTable[])(u32, u32, u32, s32) =
[0] = AI_CheckBadMove, // AI_FLAG_CHECK_BAD_MOVE
[1] = AI_TryToFaint, // AI_FLAG_TRY_TO_FAINT
[2] = AI_CheckViability, // AI_FLAG_CHECK_VIABILITY
[3] = AI_SetupFirstTurn, // AI_FLAG_SETUP_FIRST_TURN
[3] = AI_ForceSetupFirstTurn, // AI_FLAG_FORCE_SETUP_FIRST_TURN
[4] = AI_Risky, // AI_FLAG_RISKY
[5] = AI_PreferStrongestMove, // AI_FLAG_PREFER_STRONGEST_MOVE
[6] = AI_PreferBatonPass, // AI_FLAG_PREFER_BATON_PASS
Expand Down Expand Up @@ -4821,7 +4821,7 @@ static s32 AI_CheckViability(u32 battlerAtk, u32 battlerDef, u32 move, s32 score
}

// Effects that are encouraged on the first turn of battle
static s32 AI_SetupFirstTurn(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
static s32 AI_ForceSetupFirstTurn(u32 battlerAtk, u32 battlerDef, u32 move, s32 score)
{
u8 i;
if (IS_TARGETING_PARTNER(battlerAtk, battlerDef)
Expand Down
28 changes: 14 additions & 14 deletions src/data/trainers.h
Original file line number Diff line number Diff line change
Expand Up @@ -4044,7 +4044,7 @@ F_TRAINER_FEMALE |
#line 1692
.doubleBattle = FALSE,
#line 1693
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_SETUP_FIRST_TURN,
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_FORCE_SETUP_FIRST_TURN,
.partySize = 1,
.party = (const struct TrainerMon[])
{
Expand Down Expand Up @@ -4085,7 +4085,7 @@ F_TRAINER_FEMALE |
#line 1708
.doubleBattle = FALSE,
#line 1709
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_SETUP_FIRST_TURN,
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_FORCE_SETUP_FIRST_TURN,
.partySize = 3,
.party = (const struct TrainerMon[])
{
Expand Down Expand Up @@ -4164,7 +4164,7 @@ F_TRAINER_FEMALE |
#line 1742
.doubleBattle = FALSE,
#line 1743
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_SETUP_FIRST_TURN,
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_FORCE_SETUP_FIRST_TURN,
.partySize = 2,
.party = (const struct TrainerMon[])
{
Expand Down Expand Up @@ -11394,7 +11394,7 @@ F_TRAINER_FEMALE |
#line 4594
.doubleBattle = FALSE,
#line 4595
.aiFlags = AI_FLAG_BASIC_TRAINER | AI_FLAG_SETUP_FIRST_TURN,
.aiFlags = AI_FLAG_BASIC_TRAINER | AI_FLAG_FORCE_SETUP_FIRST_TURN,
#line 4596
.mugshotEnabled = TRUE,
.mugshotColor = MUGSHOT_COLOR_PURPLE,
Expand Down Expand Up @@ -23880,7 +23880,7 @@ F_TRAINER_FEMALE |
#line 9565
.doubleBattle = FALSE,
#line 9566
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_SETUP_FIRST_TURN,
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_FORCE_SETUP_FIRST_TURN,
.partySize = 1,
.party = (const struct TrainerMon[])
{
Expand Down Expand Up @@ -25772,7 +25772,7 @@ F_TRAINER_FEMALE |
#line 10290
.doubleBattle = FALSE,
#line 10291
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_SETUP_FIRST_TURN,
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_FORCE_SETUP_FIRST_TURN,
.partySize = 1,
.party = (const struct TrainerMon[])
{
Expand Down Expand Up @@ -25840,7 +25840,7 @@ F_TRAINER_FEMALE |
#line 10318
.doubleBattle = FALSE,
#line 10319
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_SETUP_FIRST_TURN,
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_FORCE_SETUP_FIRST_TURN,
.partySize = 1,
.party = (const struct TrainerMon[])
{
Expand Down Expand Up @@ -25921,7 +25921,7 @@ F_TRAINER_FEMALE |
#line 10350
.doubleBattle = FALSE,
#line 10351
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_SETUP_FIRST_TURN,
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_FORCE_SETUP_FIRST_TURN,
.partySize = 2,
.party = (const struct TrainerMon[])
{
Expand Down Expand Up @@ -25968,7 +25968,7 @@ F_TRAINER_FEMALE |
#line 10368
.doubleBattle = FALSE,
#line 10369
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_SETUP_FIRST_TURN,
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_FORCE_SETUP_FIRST_TURN,
.partySize = 3,
.party = (const struct TrainerMon[])
{
Expand Down Expand Up @@ -26073,7 +26073,7 @@ F_TRAINER_FEMALE |
#line 10408
.doubleBattle = FALSE,
#line 10409
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_SETUP_FIRST_TURN,
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_FORCE_SETUP_FIRST_TURN,
.partySize = 2,
.party = (const struct TrainerMon[])
{
Expand Down Expand Up @@ -26167,7 +26167,7 @@ F_TRAINER_FEMALE |
#line 10444
.doubleBattle = FALSE,
#line 10445
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_SETUP_FIRST_TURN,
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_FORCE_SETUP_FIRST_TURN,
.partySize = 2,
.party = (const struct TrainerMon[])
{
Expand Down Expand Up @@ -27472,7 +27472,7 @@ F_TRAINER_FEMALE |
#line 10958
.doubleBattle = FALSE,
#line 10959
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_SETUP_FIRST_TURN,
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_FORCE_SETUP_FIRST_TURN,
.partySize = 2,
.party = (const struct TrainerMon[])
{
Expand Down Expand Up @@ -27560,7 +27560,7 @@ F_TRAINER_FEMALE |
#line 10992
.doubleBattle = FALSE,
#line 10993
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_SETUP_FIRST_TURN,
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_FORCE_SETUP_FIRST_TURN,
.partySize = 2,
.party = (const struct TrainerMon[])
{
Expand Down Expand Up @@ -31937,7 +31937,7 @@ F_TRAINER_FEMALE |
#line 12747
.doubleBattle = TRUE,
#line 12748
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_SETUP_FIRST_TURN,
.aiFlags = AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_FORCE_SETUP_FIRST_TURN,
.partySize = 2,
.party = (const struct TrainerMon[])
{
Expand Down
28 changes: 14 additions & 14 deletions src/data/trainers.party
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ Gender: Female
Music: Cool
Items: Hyper Potion
Double Battle: No
AI: Check Bad Move / Try To Faint / Setup First Turn
AI: Check Bad Move / Try To Faint / Force Setup First Turn

Zangoose
Level: 26
Expand All @@ -1706,7 +1706,7 @@ Gender: Female
Music: Cool
Items: Full Restore
Double Battle: No
AI: Check Bad Move / Try To Faint / Setup First Turn
AI: Check Bad Move / Try To Faint / Force Setup First Turn

Mawile
Level: 29
Expand Down Expand Up @@ -1740,7 +1740,7 @@ Gender: Female
Music: Cool
Items: Full Restore
Double Battle: No
AI: Check Bad Move / Try To Faint / Setup First Turn
AI: Check Bad Move / Try To Faint / Force Setup First Turn

Lairon
Level: 45
Expand Down Expand Up @@ -4592,7 +4592,7 @@ Gender: Male
Music: Elite Four
Items: Full Restore / Full Restore
Double Battle: No
AI: Basic Trainer / Setup First Turn
AI: Basic Trainer / Force Setup First Turn
Mugshot: Purple

Mightyena
Expand Down Expand Up @@ -9563,7 +9563,7 @@ Pic: Brendan
Gender: Male
Music: Male
Double Battle: No
AI: Check Bad Move / Try To Faint / Setup First Turn
AI: Check Bad Move / Try To Faint / Force Setup First Turn

Torchic
Level: 5
Expand Down Expand Up @@ -10288,7 +10288,7 @@ Gender: Male
Music: Cool
Items: Full Restore
Double Battle: No
AI: Check Bad Move / Try To Faint / Setup First Turn
AI: Check Bad Move / Try To Faint / Force Setup First Turn

Breloom
Level: 31
Expand Down Expand Up @@ -10316,7 +10316,7 @@ Gender: Male
Music: Cool
Items: Full Restore
Double Battle: No
AI: Check Bad Move / Try To Faint / Setup First Turn
AI: Check Bad Move / Try To Faint / Force Setup First Turn

Breloom
Level: 37
Expand Down Expand Up @@ -10348,7 +10348,7 @@ Gender: Female
Music: Cool
Items: Full Restore
Double Battle: No
AI: Check Bad Move / Try To Faint / Setup First Turn
AI: Check Bad Move / Try To Faint / Force Setup First Turn

Gloom
Level: 26
Expand All @@ -10366,7 +10366,7 @@ Gender: Female
Music: Cool
Items: Full Restore
Double Battle: No
AI: Check Bad Move / Try To Faint / Setup First Turn
AI: Check Bad Move / Try To Faint / Force Setup First Turn

Lotad
Level: 28
Expand Down Expand Up @@ -10406,7 +10406,7 @@ Gender: Female
Music: Cool
Items: Full Restore
Double Battle: No
AI: Check Bad Move / Try To Faint / Setup First Turn
AI: Check Bad Move / Try To Faint / Force Setup First Turn

Gloom
Level: 30
Expand Down Expand Up @@ -10442,7 +10442,7 @@ Gender: Female
Music: Cool
Items: Full Restore
Double Battle: No
AI: Check Bad Move / Try To Faint / Setup First Turn
AI: Check Bad Move / Try To Faint / Force Setup First Turn

Gloom
Level: 36
Expand Down Expand Up @@ -10956,7 +10956,7 @@ Gender: Male
Music: Cool
Items: Hyper Potion
Double Battle: No
AI: Check Bad Move / Try To Faint / Setup First Turn
AI: Check Bad Move / Try To Faint / Force Setup First Turn

Kecleon
Level: 33
Expand Down Expand Up @@ -10990,7 +10990,7 @@ Pic: May
Gender: Female
Music: Female
Double Battle: No
AI: Check Bad Move / Try To Faint / Setup First Turn
AI: Check Bad Move / Try To Faint / Force Setup First Turn

Wingull
Level: 13
Expand Down Expand Up @@ -12745,7 +12745,7 @@ Pic: Old Couple
Gender: Male
Music: Intense
Double Battle: Yes
AI: Check Bad Move / Try To Faint / Setup First Turn
AI: Check Bad Move / Try To Faint / Force Setup First Turn

Medicham
Level: 49
Expand Down

0 comments on commit 720bc64

Please sign in to comment.