diff --git a/src/game/AI/BaseAI/GameObjectAI.cpp b/src/game/AI/BaseAI/GameObjectAI.cpp new file mode 100644 index 00000000000..4a6ab7884e4 --- /dev/null +++ b/src/game/AI/BaseAI/GameObjectAI.cpp @@ -0,0 +1,12 @@ +#include "AI/BaseAI/GameObjectAI.h" +#include "Entities/GameObject.h" + + +GameObjectAI::GameObjectAI(GameObject* go) : m_go(go) +{ +} + + +GameObjectAI::~GameObjectAI() +{ +} \ No newline at end of file diff --git a/src/game/AI/BaseAI/GameObjectAI.h b/src/game/AI/BaseAI/GameObjectAI.h new file mode 100644 index 00000000000..f909f1dc515 --- /dev/null +++ b/src/game/AI/BaseAI/GameObjectAI.h @@ -0,0 +1,21 @@ +#ifndef DEF_GAMEOBJECT_AI_H +#define DEF_GAMEOBJECT_AI_H + +#include "Platform/Define.h" + +class GameObject; + +class GameObjectAI +{ +public: + explicit GameObjectAI(GameObject* go); + virtual ~GameObjectAI(); + + virtual void UpdateAI(const uint32 /*diff*/) {} + +protected: + GameObject* m_go; +}; + +#endif + diff --git a/src/game/AI/ScriptDevAI/ScriptDevAIMgr.cpp b/src/game/AI/ScriptDevAI/ScriptDevAIMgr.cpp index 1a4710059dd..3e14ed9912a 100644 --- a/src/game/AI/ScriptDevAI/ScriptDevAIMgr.cpp +++ b/src/game/AI/ScriptDevAI/ScriptDevAIMgr.cpp @@ -333,6 +333,16 @@ CreatureAI* ScriptDevAIMgr::GetCreatureAI(Creature* pCreature) return pTempScript->GetAI(pCreature); } +GameObjectAI * ScriptDevAIMgr::GetGameObjectAI(GameObject * gameobject) +{ + Script* pTempScript = GetScript(gameobject->GetScriptId()); + + if (!pTempScript || !pTempScript->GetGameObjectAI) + return nullptr; + + return pTempScript->GetGameObjectAI(gameobject); +} + bool ScriptDevAIMgr::OnItemUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets) { Script* pTempScript = GetScript(pItem->GetProto()->ScriptId); diff --git a/src/game/AI/ScriptDevAI/ScriptDevAIMgr.h b/src/game/AI/ScriptDevAI/ScriptDevAIMgr.h index 9cb972d2180..a4ed13e9843 100644 --- a/src/game/AI/ScriptDevAI/ScriptDevAIMgr.h +++ b/src/game/AI/ScriptDevAI/ScriptDevAIMgr.h @@ -23,6 +23,7 @@ class WorldObject; class Aura; class Object; class ObjectGuid; +class GameObjectAI; // ********************************************************* // ************** Some defines used globally *************** @@ -63,14 +64,14 @@ enum EscortFaction struct Script { Script() : - pGossipHello(NULL), pGossipHelloGO(NULL), pGossipSelect(NULL), pGossipSelectGO(NULL), - pGossipSelectWithCode(NULL), pGossipSelectGOWithCode(NULL), - pDialogStatusNPC(NULL), pDialogStatusGO(NULL), - pQuestAcceptNPC(NULL), pQuestAcceptGO(NULL), pQuestAcceptItem(NULL), - pQuestRewardedNPC(NULL), pQuestRewardedGO(NULL), - pGOUse(NULL), pItemUse(NULL), pAreaTrigger(NULL), pNpcSpellClick(NULL), pProcessEventId(NULL), - pEffectDummyNPC(NULL), pEffectDummyGO(NULL), pEffectDummyItem(NULL), pEffectScriptEffectNPC(NULL), - pEffectAuraDummy(NULL), GetAI(NULL), GetInstanceData(NULL) + pGossipHello(nullptr), pGossipHelloGO(nullptr), pGossipSelect(nullptr), pGossipSelectGO(nullptr), + pGossipSelectWithCode(nullptr), pGossipSelectGOWithCode(nullptr), + pDialogStatusNPC(nullptr), pDialogStatusGO(nullptr), + pQuestAcceptNPC(nullptr), pQuestAcceptGO(nullptr), pQuestAcceptItem(nullptr), + pQuestRewardedNPC(nullptr), pQuestRewardedGO(nullptr), + pGOUse(nullptr), pItemUse(nullptr), pAreaTrigger(nullptr), pNpcSpellClick(nullptr), pProcessEventId(nullptr), + pEffectDummyNPC(nullptr), pEffectDummyGO(nullptr), pEffectDummyItem(nullptr), pEffectScriptEffectNPC(nullptr), + pEffectAuraDummy(nullptr), GetGameObjectAI(nullptr), GetAI(nullptr), GetInstanceData(nullptr) {} std::string Name; @@ -99,6 +100,7 @@ struct Script bool (*pEffectScriptEffectNPC)(Unit*, uint32, SpellEffectIndex, Creature*, ObjectGuid); bool (*pEffectAuraDummy)(const Aura*, bool); + GameObjectAI* (*GetGameObjectAI)(GameObject*); CreatureAI* (*GetAI)(Creature*); InstanceData* (*GetInstanceData)(Map*); @@ -145,6 +147,7 @@ class ScriptDevAIMgr uint32 GetScriptIdsCount() const { return m_scriptNames.size(); } CreatureAI* GetCreatureAI(Creature* creature); + GameObjectAI* GetGameObjectAI(GameObject* gameobject); InstanceData* CreateInstanceData(Map* pMap); uint32 GetAreaTriggerScriptId(uint32 triggerId) const; diff --git a/src/game/Entities/GameObject.cpp b/src/game/Entities/GameObject.cpp index 453aee2f984..41e1c113949 100644 --- a/src/game/Entities/GameObject.cpp +++ b/src/game/Entities/GameObject.cpp @@ -47,7 +47,8 @@ GameObject::GameObject() : WorldObject(), m_captureSlider(0), m_captureState(), m_goInfo(nullptr), - m_displayInfo(nullptr) + m_displayInfo(nullptr), + m_AI(nullptr) { m_objectType |= TYPEMASK_GAMEOBJECT; m_objectTypeId = TYPEID_GAMEOBJECT; @@ -543,6 +544,9 @@ void GameObject::Update(uint32 update_diff, uint32 p_time) break; } } + + if (m_AI) + m_AI->UpdateAI(update_diff); } void GameObject::Refresh() @@ -2470,3 +2474,13 @@ void GameObject::SetInUse(bool use) else SetGoState(GO_STATE_READY); } + +uint32 GameObject::GetScriptId() const +{ + return ObjectMgr::GetGameObjectInfo(GetEntry())->ScriptId; +} + +void GameObject::AIM_Initialize() +{ + m_AI.reset(sScriptDevAIMgr.GetGameObjectAI(this)); +} diff --git a/src/game/Entities/GameObject.h b/src/game/Entities/GameObject.h index d69fd8746b2..5dc0748805d 100644 --- a/src/game/Entities/GameObject.h +++ b/src/game/Entities/GameObject.h @@ -23,6 +23,7 @@ #include "Globals/SharedDefines.h" #include "Entities/Object.h" #include "Util.h" +#include "AI/BaseAI/GameObjectAI.h" // GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push,N), also any gcc version not support it at some platform #if defined( __GNUC__ ) @@ -796,6 +797,9 @@ class GameObject : public WorldObject GridReference& GetGridRef() { return m_gridRef; } + uint32 GetScriptId() const; + void AIM_Initialize(); + GameObjectModel* m_model; protected: @@ -833,6 +837,8 @@ class GameObject : public WorldObject time_t m_reStockTimer; // timer to refill the chest time_t m_despawnTimer; // timer to despawn the chest if something changed in it + std::unique_ptr m_AI; + private: void SwitchDoorOrButton(bool activate, bool alternative = false); void TickCapturePoint();