diff options
-rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 13 | ||||
-rw-r--r-- | src/server/game/Entities/Creature/Creature.h | 4 | ||||
-rw-r--r-- | src/server/game/Scripting/ScriptMgr.cpp | 3 |
3 files changed, 17 insertions, 3 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index e6b604d074a..8e9f41296f7 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -811,7 +811,7 @@ bool Creature::AIM_Destroy() return true; } -bool Creature::AIM_Initialize(CreatureAI* ai) +bool Creature::AIM_Create(CreatureAI* ai /*= nullptr*/) { // make sure nothing can change the AI during AI update if (m_AI_locked) @@ -825,12 +825,23 @@ bool Creature::AIM_Initialize(CreatureAI* ai) Motion_Initialize(); i_AI = ai ? ai : FactorySelector::selectAI(this); +} +void Creature::AI_InitializeAndEnable() +{ IsAIEnabled = true; i_AI->InitializeAI(); // Initialize vehicle if (GetVehicleKit()) GetVehicleKit()->Reset(); +} + +bool Creature::AIM_Initialize(CreatureAI* ai) +{ + if (!AIM_Create(ai)) + return false; + + AI_InitializeAndEnable(); return true; } diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index b5ee31479b8..8b4a6a9b0ab 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -131,7 +131,9 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma bool IsEvadingAttacks() const { return IsInEvadeMode() || CanNotReachTarget(); } bool AIM_Destroy(); - bool AIM_Initialize(CreatureAI* ai = NULL); + bool AIM_Create(CreatureAI* ai = nullptr); + void AI_InitializeAndEnable(); + bool AIM_Initialize(CreatureAI* ai = nullptr); void Motion_Initialize(); CreatureAI* AI() const { return reinterpret_cast<CreatureAI*>(i_AI); } diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index f8ef25e7b57..2367e26218c 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -453,7 +453,7 @@ class CreatureGameObjectAreaTriggerScriptRegistrySwapHooks if (creature->IsAlive()) creature->ClearUnitState(UNIT_STATE_EVADE); - bool const created = creature->AIM_Initialize(); + bool const created = creature->AIM_Create(); ASSERT(created, "Creating the AI should never fail here!"); (void)created; @@ -464,6 +464,7 @@ class CreatureGameObjectAreaTriggerScriptRegistrySwapHooks if (!creature->IsAlive()) return; + creature->AI_InitializeAndEnable(); creature->AI()->EnterEvadeMode(); // Cast a dummy visual spell asynchronously here to signal |