add smart wild AI
This commit is contained in:
parent
e6a2d2226f
commit
0a0687ae78
5 changed files with 40 additions and 1 deletions
|
@ -70,6 +70,7 @@ void RunBattleScriptCommands(void);
|
||||||
bool8 TryRunFromBattle(u8 battlerId);
|
bool8 TryRunFromBattle(u8 battlerId);
|
||||||
void SpecialStatusesClear(void);
|
void SpecialStatusesClear(void);
|
||||||
void SetTypeBeforeUsingMove(u16 move, u8 battlerAtk);
|
void SetTypeBeforeUsingMove(u16 move, u8 battlerAtk);
|
||||||
|
bool32 IsWildMonSmart(void);
|
||||||
|
|
||||||
extern struct UnknownPokemonStruct4 gMultiPartnerParty[MULTI_PARTY_SIZE];
|
extern struct UnknownPokemonStruct4 gMultiPartnerParty[MULTI_PARTY_SIZE];
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,10 @@
|
||||||
#define B_CRITICAL_CAPTURE TRUE // If set to TRUE, Critical Capture will be enabled.
|
#define B_CRITICAL_CAPTURE TRUE // If set to TRUE, Critical Capture will be enabled.
|
||||||
#define B_CATCHING_CHARM_BOOST 20 // % boost in Critical Capture odds if player has the Catching Charm.
|
#define B_CATCHING_CHARM_BOOST 20 // % boost in Critical Capture odds if player has the Catching Charm.
|
||||||
|
|
||||||
|
// AI Settings
|
||||||
|
#define B_SMART_WILD_AI_FLAG 0x1DE // If not 0, you can set this flag in a script to enable smart wild pokemon
|
||||||
|
#define B_VAR_WILD_AI_FLAGS 0x40F7 // If not 0, you can use this var to add to default wild AI flags. NOT usable with flags above (1 << 15)
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
#define B_DOUBLE_WILD_CHANCE 0 // % chance of encountering two Pokémon in a Wild Encounter.
|
#define B_DOUBLE_WILD_CHANCE 0 // % chance of encountering two Pokémon in a Wild Encounter.
|
||||||
#define B_SLEEP_TURNS GEN_7 // In Gen5+, sleep lasts for 1-3 turns instead of 2-5 turns.
|
#define B_SLEEP_TURNS GEN_7 // In Gen5+, sleep lasts for 1-3 turns instead of 2-5 turns.
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "battle_factory.h"
|
#include "battle_factory.h"
|
||||||
#include "battle_setup.h"
|
#include "battle_setup.h"
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
|
#include "event_data.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "pokemon.h"
|
#include "pokemon.h"
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
|
@ -123,6 +124,29 @@ void BattleAI_SetupItems(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static u32 GetWildAiFlags(void)
|
||||||
|
{
|
||||||
|
u8 avgLevel = GetMonData(&gEnemyParty[0], MON_DATA_LEVEL);
|
||||||
|
u32 flags;
|
||||||
|
|
||||||
|
if (IsDoubleBattle())
|
||||||
|
avgLevel = (GetMonData(&gEnemyParty[0], MON_DATA_LEVEL) + GetMonData(&gEnemyParty[1], MON_DATA_LEVEL)) / 2;
|
||||||
|
|
||||||
|
if (avgLevel < 20)
|
||||||
|
flags |= AI_FLAG_CHECK_BAD_MOVE;
|
||||||
|
if (avgLevel < 40)
|
||||||
|
flags |= AI_FLAG_CHECK_VIABILITY;
|
||||||
|
if (avgLevel < 60)
|
||||||
|
flags |= AI_FLAG_PREFER_STRONGEST_MOVE;
|
||||||
|
if (avgLevel < 100)
|
||||||
|
flags |= AI_FLAG_HP_AWARE;
|
||||||
|
|
||||||
|
if (B_VAR_WILD_AI_FLAGS != 0 && VarGet(B_VAR_WILD_AI_FLAGS) != 0)
|
||||||
|
flags |= VarGet(B_VAR_WILD_AI_FLAGS);
|
||||||
|
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
void BattleAI_SetupFlags(void)
|
void BattleAI_SetupFlags(void)
|
||||||
{
|
{
|
||||||
if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
|
if (gBattleTypeFlags & BATTLE_TYPE_RECORDED)
|
||||||
|
@ -142,6 +166,10 @@ void BattleAI_SetupFlags(void)
|
||||||
else
|
else
|
||||||
AI_THINKING_STRUCT->aiFlags = gTrainers[gTrainerBattleOpponent_A].aiFlags;
|
AI_THINKING_STRUCT->aiFlags = gTrainers[gTrainerBattleOpponent_A].aiFlags;
|
||||||
|
|
||||||
|
// check smart wild AI
|
||||||
|
if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_TRAINER)) && IsWildMonSmart())
|
||||||
|
AI_THINKING_STRUCT->aiFlags |= GetWildAiFlags();
|
||||||
|
|
||||||
if (gBattleTypeFlags & (BATTLE_TYPE_DOUBLE | BATTLE_TYPE_TWO_OPPONENTS) || gTrainers[gTrainerBattleOpponent_A].doubleBattle)
|
if (gBattleTypeFlags & (BATTLE_TYPE_DOUBLE | BATTLE_TYPE_TWO_OPPONENTS) || gTrainers[gTrainerBattleOpponent_A].doubleBattle)
|
||||||
AI_THINKING_STRUCT->aiFlags |= AI_FLAG_DOUBLE_BATTLE; // Act smart in doubles and don't attack your partner.
|
AI_THINKING_STRUCT->aiFlags |= AI_FLAG_DOUBLE_BATTLE; // Act smart in doubles and don't attack your partner.
|
||||||
}
|
}
|
||||||
|
|
|
@ -1558,7 +1558,8 @@ static void OpponentHandleChooseMove(void)
|
||||||
u8 chosenMoveId;
|
u8 chosenMoveId;
|
||||||
struct ChooseMoveStruct *moveInfo = (struct ChooseMoveStruct*)(&gBattleResources->bufferA[gActiveBattler][4]);
|
struct ChooseMoveStruct *moveInfo = (struct ChooseMoveStruct*)(&gBattleResources->bufferA[gActiveBattler][4]);
|
||||||
|
|
||||||
if (gBattleTypeFlags & (BATTLE_TYPE_TRAINER | BATTLE_TYPE_FIRST_BATTLE | BATTLE_TYPE_SAFARI | BATTLE_TYPE_ROAMER))
|
if (gBattleTypeFlags & (BATTLE_TYPE_TRAINER | BATTLE_TYPE_FIRST_BATTLE | BATTLE_TYPE_SAFARI | BATTLE_TYPE_ROAMER)
|
||||||
|
|| IsWildMonSmart())
|
||||||
{
|
{
|
||||||
BattleAI_SetupAIData(0xF);
|
BattleAI_SetupAIData(0xF);
|
||||||
chosenMoveId = BattleAI_ChooseMoveOrAction();
|
chosenMoveId = BattleAI_ChooseMoveOrAction();
|
||||||
|
|
|
@ -5130,3 +5130,8 @@ void SetTotemBoost(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool32 IsWildMonSmart(void)
|
||||||
|
{
|
||||||
|
return (B_SMART_WILD_AI_FLAG != 0 && FlagGet(B_SMART_WILD_AI_FLAG));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue