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

Add ai delay timer #3302

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -679,6 +679,8 @@ struct BattleStruct
bool8 trainerSlideMegaEvolutionMsgDone;
bool8 trainerSlideZMoveMsgDone;
bool8 trainerSlideBeforeFirstTurnMsgDone;
u32 aiDelayTimer; // Counts number of frames AI takes to choose an action.
u32 aiDelayFrames; // Number of frames it took to choose an action.
};

// The palaceFlags member of struct BattleStruct contains 1 flag per move to indicate which moves the AI should consider,
Expand Down
2 changes: 1 addition & 1 deletion include/battle_ai_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ u8 BattleAI_ChooseMoveOrAction(void);
void Ai_InitPartyStruct(void);
void Ai_UpdateSwitchInData(u32 battler);
void Ai_UpdateFaintData(u32 battler);
void GetAiLogicData(void);
void SetAiLogicDataForTurn(void);

extern u8 sBattler_AI;

Expand Down
1 change: 1 addition & 0 deletions include/config/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

// Battle Debug Menu
#define DEBUG_BATTLE_MENU TRUE // If set to TRUE, enables a debug menu to use in battles by pressing the Select button.
#define DEBUG_AI_DELAY_TIMER FALSE // If set to TRUE, displays the number of frames it takes for the AI to choose a move. Replaces the "What will PKMN do" text. Useful for devs or anyone who modifies the AI code and wants to see if it doesn't take too long to run.

// Pokémon Debug
#define DEBUG_POKEMON_MENU TRUE // Enables a debug menu for pokemon sprites and icons, accessed by pressing SELECT in the summary screen.
Expand Down
7 changes: 5 additions & 2 deletions src/battle_ai_main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "global.h"
#include "main.h"
#include "malloc.h"
#include "battle.h"
#include "battle_anim.h"
Expand Down Expand Up @@ -335,7 +336,7 @@ void Ai_UpdateFaintData(u32 battler)
aiMon->isFainted = TRUE;
}

static void SetBattlerAiData(u8 battler)
static void SetBattlerAiData(u32 battler)
{
AI_DATA->abilities[battler] = AI_GetAbility(battler);
AI_DATA->items[battler] = gBattleMons[battler].item;
Expand All @@ -346,7 +347,7 @@ static void SetBattlerAiData(u8 battler)
AI_DATA->moveLimitations[battler] = CheckMoveLimitations(battler, 0, MOVE_LIMITATIONS_ALL);
}

void GetAiLogicData(void)
void SetAiLogicDataForTurn(void)
{
u32 battlerAtk, battlerDef, i, move;
u8 effectiveness;
Expand All @@ -357,6 +358,8 @@ void GetAiLogicData(void)
if (!(gBattleTypeFlags & BATTLE_TYPE_HAS_AI) && !IsWildMonSmart())
return;

gBattleStruct->aiDelayTimer = gMain.vblankCounter1;

// get/assume all battler data
for (i = 0; i < gBattlersCount; i++)
{
Expand Down
13 changes: 13 additions & 0 deletions src/battle_controller_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,19 @@ static void HandleChooseActionAfterDma3(u32 battler)
{
gBattle_BG0_X = 0;
gBattle_BG0_Y = DISPLAY_HEIGHT;
if (gBattleStruct->aiDelayTimer != 0)
ghoulslash marked this conversation as resolved.
Show resolved Hide resolved
{
gBattleStruct->aiDelayFrames = gMain.vblankCounter1 - gBattleStruct->aiDelayTimer;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on adding the frames counter to the battle debug menu?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AI one or in more general sense?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was thinking just adding the value to the AI Info page but that can just be a separate PR if desired. Otherwise I think this looks good now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it in a separate PR then

gBattleStruct->aiDelayTimer = 0;
#if DEBUG_AI_DELAY_TIMER
{
static const u8 sText_AIDelay[] = _("AI delay:\n{B_BUFF1} frames");
ghoulslash marked this conversation as resolved.
Show resolved Hide resolved
PREPARE_HWORD_NUMBER_BUFFER(gBattleTextBuff1, 3, gBattleStruct->aiDelayFrames);
BattleStringExpandPlaceholdersToDisplayedString(sText_AIDelay);
BattlePutTextOnWindow(gDisplayedStringBattle, B_WIN_ACTION_PROMPT);
}
#endif // DEBUG_AI_DELAY_TIMER
}
gBattlerControllerFuncs[battler] = HandleInputChooseAction;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3724,7 +3724,7 @@ static void DoBattleIntro(void)
gBattleStruct->switchInAbilitiesCounter = 0;
gBattleStruct->switchInItemsCounter = 0;
gBattleStruct->overworldWeatherDone = FALSE;
GetAiLogicData(); // get assumed abilities, hold effects, etc of all battlers
SetAiLogicDataForTurn(); // get assumed abilities, hold effects, etc of all battlers
Ai_InitPartyStruct(); // Save mons party counts, and first 2/4 mons on the battlefield.
gBattleMainFunc = TryDoEventsBeforeFirstTurn;
}
Expand Down Expand Up @@ -3857,7 +3857,7 @@ static void TryDoEventsBeforeFirstTurn(void)

gRandomTurnNumber = Random();

GetAiLogicData(); // get assumed abilities, hold effects, etc of all battlers
SetAiLogicDataForTurn(); // get assumed abilities, hold effects, etc of all battlers

if (gBattleTypeFlags & BATTLE_TYPE_ARENA)
{
Expand Down Expand Up @@ -3949,7 +3949,7 @@ void BattleTurnPassed(void)

*(&gBattleStruct->absentBattlerFlags) = gAbsentBattlerFlags;
BattlePutTextOnWindow(gText_EmptyString3, B_WIN_MSG);
GetAiLogicData(); // get assumed abilities, hold effects, etc of all battlers
SetAiLogicDataForTurn(); // get assumed abilities, hold effects, etc of all battlers
gBattleMainFunc = HandleTurnActionSelectionState;
gRandomTurnNumber = Random();

Expand Down