diff --git a/include/battle.h b/include/battle.h index 67663261b4..ee91a75c56 100644 --- a/include/battle.h +++ b/include/battle.h @@ -353,7 +353,7 @@ struct AI_ThinkingStruct u16 moveConsidered; s32 score[MAX_MON_MOVES]; u32 funcResult; - u32 aiFlags[MAX_BATTLERS_COUNT]; + u64 aiFlags[MAX_BATTLERS_COUNT]; u8 aiAction; u8 aiLogicId; struct AI_SavedBattleMon saved[MAX_BATTLERS_COUNT]; diff --git a/include/battle_factory.h b/include/battle_factory.h index d414bdb3b1..c266cc32c5 100644 --- a/include/battle_factory.h +++ b/include/battle_factory.h @@ -6,7 +6,7 @@ bool8 InBattleFactory(void); u8 GetFactoryMonFixedIV(u8 challengeNum, bool8 isLastBattle); void FillFactoryBrainParty(void); u8 GetNumPastRentalsRank(u8 battleMode, u8 lvlMode); -u32 GetAiScriptsInBattleFactory(void); +u64 GetAiScriptsInBattleFactory(void); void SetMonMoveAvoidReturn(struct Pokemon *mon, u16 moveArg, u8 moveSlot); #endif // GUARD_BATTLE_FACTORY_H diff --git a/include/constants/battle_ai.h b/include/constants/battle_ai.h index c8dd9bd1f9..f1f1f083a3 100644 --- a/include/constants/battle_ai.h +++ b/include/constants/battle_ai.h @@ -32,6 +32,9 @@ #define AI_FLAG_PREDICT_INCOMING_MON (1 << 24) // AI will score against the predicting incoming mon if it predicts the player to switch. Requires AI_FLAG_PREDICT_SWITCH #define AI_FLAG_PP_STALL_PREVENTION (1 << 25) // AI keeps track of the player's switches where the incoming mon is immune to the chosen move +// Flags at and after 32 need different formatting, as in +// #define AI_FLAG_PLACEHOLDER ((u64)1 << 32) + #define AI_FLAG_COUNT 26 // The following options are enough to have a basic/smart trainer. Any other addtion could make the trainer worse/better depending on the flag @@ -40,10 +43,10 @@ #define AI_FLAG_PREDICTION (AI_FLAG_PREDICT_SWITCH | AI_FLAG_PREDICT_INCOMING_MON) // 'other' ai logic flags -#define AI_FLAG_DYNAMIC_FUNC (1 << 28) // Create custom AI functions for specific battles via "setdynamicaifunc" cmd -#define AI_FLAG_ROAMING (1 << 29) -#define AI_FLAG_SAFARI (1 << 30) -#define AI_FLAG_FIRST_BATTLE (1 << 31) +#define AI_FLAG_DYNAMIC_FUNC ((u64)1 << 60) // Create custom AI functions for specific battles via "setdynamicaifunc" cmd +#define AI_FLAG_ROAMING ((u64)1 << 61) +#define AI_FLAG_SAFARI ((u64)1 << 62) +#define AI_FLAG_FIRST_BATTLE ((u64)1 << 63) #define AI_SCORE_DEFAULT 100 // Default score for all AI moves. diff --git a/include/data.h b/include/data.h index d5202f756e..07511f1d7f 100644 --- a/include/data.h +++ b/include/data.h @@ -83,7 +83,7 @@ struct TrainerMon struct Trainer { - /*0x00*/ u32 aiFlags; + /*0x00*/ u64 aiFlags; /*0x04*/ const struct TrainerMon *party; /*0x08*/ u16 items[MAX_TRAINER_ITEMS]; /*0x10*/ u8 trainerClass; @@ -295,7 +295,7 @@ static inline const struct TrainerMon *GetTrainerPartyFromId(u16 trainerId) return gTrainers[difficulty][sanitizedTrainerId].party; } -static inline const bool32 GetTrainerAIFlagsFromId(u16 trainerId) +static inline const u64 GetTrainerAIFlagsFromId(u16 trainerId) { u32 sanitizedTrainerId = SanitizeTrainerId(trainerId); enum DifficultyLevel difficulty = GetTrainerDifficultyLevel(sanitizedTrainerId); diff --git a/include/debug.h b/include/debug.h index a009ce2e2a..1a48e9f6cd 100644 --- a/include/debug.h +++ b/include/debug.h @@ -6,6 +6,6 @@ extern const u8 Debug_FlagsAndVarNotSetBattleConfigMessage[]; const u8 *GetWeatherName(u32 weatherId); extern EWRAM_DATA bool8 gIsDebugBattle; -extern EWRAM_DATA u32 gDebugAIFlags; +extern EWRAM_DATA u64 gDebugAIFlags; #endif // GUARD_DEBUG_H diff --git a/include/recorded_battle.h b/include/recorded_battle.h index 0945eefe92..15a3a05286 100644 --- a/include/recorded_battle.h +++ b/include/recorded_battle.h @@ -27,7 +27,7 @@ struct RecordedBattleSave u8 frontierBrainSymbol; u8 battleScene:1; u8 textSpeed:3; - u32 AI_scripts; + u64 AI_scripts; u8 recordMixFriendName[PLAYER_NAME_LENGTH + 1]; u8 recordMixFriendClass; u8 apprenticeId; @@ -81,7 +81,7 @@ u8 GetBattleSceneInRecordedBattle(void); u8 GetTextSpeedInRecordedBattle(void); void RecordedBattle_CopyBattlerMoves(u32 battler); void RecordedBattle_CheckMovesetChanges(u8 mode); -u32 GetAiScriptsInRecordedBattle(void); +u64 GetAiScriptsInRecordedBattle(void); void RecordedBattle_SetPlaybackFinished(void); bool8 RecordedBattle_CanStopPlayback(void); void GetRecordedBattleRecordMixFriendName(u8 *dst); diff --git a/include/test/battle.h b/include/test/battle.h index b524b47a7b..16b492ccad 100644 --- a/include/test/battle.h +++ b/include/test/battle.h @@ -873,7 +873,7 @@ void OpenPokemon(u32 sourceLine, u32 side, u32 species); void ClosePokemon(u32 sourceLine); void RNGSeed_(u32 sourceLine, rng_value_t seed); -void AIFlags_(u32 sourceLine, u32 flags); +void AIFlags_(u32 sourceLine, u64 flags); void AILogScores(u32 sourceLine); void Gender_(u32 sourceLine, u32 gender); void Nature_(u32 sourceLine, u32 nature); diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index 490f1b5786..4bd1be1b4b 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -125,10 +125,10 @@ void BattleAI_SetupItems(void) } } -static u32 GetWildAiFlags(void) +static u64 GetWildAiFlags(void) { u32 avgLevel = GetMonData(&gEnemyParty[0], MON_DATA_LEVEL); - u32 flags = 0; + u64 flags = 0; if (IsDoubleBattle()) avgLevel = (GetMonData(&gEnemyParty[0], MON_DATA_LEVEL) + GetMonData(&gEnemyParty[1], MON_DATA_LEVEL)) / 2; @@ -147,9 +147,9 @@ static u32 GetWildAiFlags(void) return flags; } -static u32 GetAiFlags(u16 trainerId) +static u64 GetAiFlags(u16 trainerId) { - u32 flags = 0; + u64 flags = 0; if (!(gBattleTypeFlags & BATTLE_TYPE_HAS_AI) && !IsWildMonSmart()) return 0; @@ -240,12 +240,12 @@ void BattleAI_SetupFlags(void) void BattleAI_SetupAIData(u8 defaultScoreMoves, u32 battler) { u32 moveLimitations; - u32 flags[MAX_BATTLERS_COUNT]; + u64 flags[MAX_BATTLERS_COUNT]; // Clear AI data but preserve the flags. - memcpy(&flags[0], &AI_THINKING_STRUCT->aiFlags[0], sizeof(u32) * MAX_BATTLERS_COUNT); + memcpy(&flags[0], &AI_THINKING_STRUCT->aiFlags[0], sizeof(u64) * MAX_BATTLERS_COUNT); memset(AI_THINKING_STRUCT, 0, sizeof(struct AI_ThinkingStruct)); - memcpy(&AI_THINKING_STRUCT->aiFlags[0], &flags[0], sizeof(u32) * MAX_BATTLERS_COUNT); + memcpy(&AI_THINKING_STRUCT->aiFlags[0], &flags[0], sizeof(u64) * MAX_BATTLERS_COUNT); moveLimitations = AI_DATA->moveLimitations[battler]; @@ -607,7 +607,7 @@ static u32 ChooseMoveOrAction_Singles(u32 battlerAi) u8 consideredMoveArray[MAX_MON_MOVES]; u32 numOfBestMoves; s32 i; - u32 flags = AI_THINKING_STRUCT->aiFlags[battlerAi]; + u64 flags = AI_THINKING_STRUCT->aiFlags[battlerAi]; AI_DATA->partnerMove = 0; // no ally while (flags != 0) @@ -619,7 +619,7 @@ static u32 ChooseMoveOrAction_Singles(u32 battlerAi) else BattleAI_DoAIProcessing(AI_THINKING_STRUCT, battlerAi, gBattlerTarget); } - flags >>= 1; + flags >>= (u64)1; AI_THINKING_STRUCT->aiLogicId++; } @@ -656,7 +656,7 @@ static u32 ChooseMoveOrAction_Singles(u32 battlerAi) static u32 ChooseMoveOrAction_Doubles(u32 battlerAi) { s32 i, j; - u32 flags; + u64 flags; s32 bestMovePointsForTarget[MAX_BATTLERS_COUNT]; u8 mostViableTargetsArray[MAX_BATTLERS_COUNT]; u8 actionOrMoveIndex[MAX_BATTLERS_COUNT]; @@ -696,7 +696,7 @@ static u32 ChooseMoveOrAction_Doubles(u32 battlerAi) else BattleAI_DoAIProcessing(AI_THINKING_STRUCT, battlerAi, gBattlerTarget); } - flags >>= 1; + flags >>= (u64)1; AI_THINKING_STRUCT->aiLogicId++; } diff --git a/src/battle_factory.c b/src/battle_factory.c index 4ae2310c17..b1f2619366 100644 --- a/src/battle_factory.c +++ b/src/battle_factory.c @@ -817,7 +817,7 @@ u8 GetNumPastRentalsRank(u8 battleMode, u8 lvlMode) return ret; } -u32 GetAiScriptsInBattleFactory(void) +u64 GetAiScriptsInBattleFactory(void) { int lvlMode = gSaveBlock2Ptr->frontier.lvlMode; diff --git a/src/debug.c b/src/debug.c index ad0cf449d4..147246ec1a 100644 --- a/src/debug.c +++ b/src/debug.c @@ -337,7 +337,7 @@ static EWRAM_DATA struct DebugMonData *sDebugMonData = NULL; static EWRAM_DATA struct DebugMenuListData *sDebugMenuListData = NULL; static EWRAM_DATA struct DebugBattleData *sDebugBattleData = NULL; EWRAM_DATA bool8 gIsDebugBattle = FALSE; -EWRAM_DATA u32 gDebugAIFlags = 0; +EWRAM_DATA u64 gDebugAIFlags = 0; // ******************************* // Define functions diff --git a/src/recorded_battle.c b/src/recorded_battle.c index 0b385c017c..d2bd9c9156 100644 --- a/src/recorded_battle.c +++ b/src/recorded_battle.c @@ -49,7 +49,7 @@ EWRAM_DATA static u8 sFrontierPassFlag = 0; EWRAM_DATA static u8 sBattleScene = 0; EWRAM_DATA static u8 sTextSpeed = 0; EWRAM_DATA static u32 sBattleFlags = 0; -EWRAM_DATA static u32 sAI_Scripts = 0; +EWRAM_DATA static u64 sAI_Scripts = 0; EWRAM_DATA static struct Pokemon sSavedPlayerParty[PARTY_SIZE] = {0}; EWRAM_DATA static struct Pokemon sSavedOpponentParty[PARTY_SIZE] = {0}; EWRAM_DATA static u16 sPlayerMonMoves[MAX_BATTLERS_COUNT / 2][MAX_MON_MOVES] = {0}; @@ -785,7 +785,7 @@ void RecordedBattle_CheckMovesetChanges(u8 mode) } } -u32 GetAiScriptsInRecordedBattle(void) +u64 GetAiScriptsInRecordedBattle(void) { return sAI_Scripts; } diff --git a/src/trainer_hill.c b/src/trainer_hill.c index ce2b894bf0..344e1fa215 100644 --- a/src/trainer_hill.c +++ b/src/trainer_hill.c @@ -935,7 +935,7 @@ void FillHillTrainersParties(void) // This function is unused, but my best guess is // it was supposed to return AI scripts for trainer // hill trainers. -u32 GetTrainerHillAIFlags(void) +u64 GetTrainerHillAIFlags(void) { return (AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_TRY_TO_FAINT | AI_FLAG_CHECK_VIABILITY); } diff --git a/test/test_runner_battle.c b/test/test_runner_battle.c index db49155e18..531804d7cc 100644 --- a/test/test_runner_battle.c +++ b/test/test_runner_battle.c @@ -1485,7 +1485,7 @@ void RNGSeed_(u32 sourceLine, rng_value_t seed) DATA.recordedBattle.rngSeed = seed; } -void AIFlags_(u32 sourceLine, u32 flags) +void AIFlags_(u32 sourceLine, u64 flags) { INVALID_IF(!IsAITest(), "AI_FLAGS is usable only in AI_SINGLE_BATTLE_TEST & AI_DOUBLE_BATTLE_TEST"); DATA.recordedBattle.AI_scripts = flags; diff --git a/tools/trainerproc/main.c b/tools/trainerproc/main.c index b301ddf552..274f1f8dae 100644 --- a/tools/trainerproc/main.c +++ b/tools/trainerproc/main.c @@ -14,7 +14,7 @@ #include #include -#define MAX_TRAINER_AI_FLAGS 32 +#define MAX_TRAINER_AI_FLAGS 64 #define MAX_TRAINER_ITEMS 4 #define PARTY_SIZE 255 #define MAX_MON_MOVES 4