aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp13
-rw-r--r--src/server/game/Entities/Creature/Creature.h2
-rw-r--r--src/server/game/Scripting/ScriptMgr.cpp3
3 files changed, 16 insertions, 2 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index c7b25d610a2..4036a8743e0 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -981,7 +981,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)
@@ -995,12 +995,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 84d00777e9b..0aa74aabf58 100644
--- a/src/server/game/Entities/Creature/Creature.h
+++ b/src/server/game/Entities/Creature/Creature.h
@@ -130,6 +130,8 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
bool IsEvadingAttacks() const { return IsInEvadeMode() || CanNotReachTarget(); }
bool AIM_Destroy();
+ bool AIM_Create(CreatureAI* ai = nullptr);
+ void AI_InitializeAndEnable();
bool AIM_Initialize(CreatureAI* ai = nullptr);
void Motion_Initialize();
diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp
index 2b8acfa67d1..cbee458c9a0 100644
--- a/src/server/game/Scripting/ScriptMgr.cpp
+++ b/src/server/game/Scripting/ScriptMgr.cpp
@@ -421,7 +421,7 @@ class CreatureGameObjectScriptRegistrySwapHooks
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;
@@ -432,6 +432,7 @@ class CreatureGameObjectScriptRegistrySwapHooks
if (!creature->IsAlive())
return;
+ creature->AI_InitializeAndEnable();
creature->AI()->EnterEvadeMode();
// Cast a dummy visual spell asynchronously here to signal