diff --git a/src/server/game/Entities/Creature/CreatureData.h b/src/server/game/Entities/Creature/CreatureData.h index 1ba2226a7..a79d7f8f0 100644 --- a/src/server/game/Entities/Creature/CreatureData.h +++ b/src/server/game/Entities/Creature/CreatureData.h @@ -22,6 +22,7 @@ #include "DatabaseEnv.h" #include "ItemTemplate.h" #include "LootMgr.h" +#include "SpawnData.h" #include "Unit.h" #include @@ -365,32 +366,23 @@ typedef std::unordered_map EquipmentInfoContainerInternal; typedef std::unordered_map EquipmentInfoContainer; // from `creature` table -struct CreatureData +struct CreatureData : public SpawnData { - CreatureData() = default; + CreatureData() : SpawnData(SPAWN_TYPE_CREATURE) {} uint32 id1{0}; // entry in creature_template uint32 id2{0}; // entry in creature_template uint32 id3{0}; // entry in creature_template - uint16 mapid{0}; - uint32 phaseMask{0}; uint32 displayid{0}; int8 equipmentId{0}; - float posX{0.0f}; - float posY{0.0f}; - float posZ{0.0f}; - float orientation{0.0f}; uint32 spawntimesecs{0}; float wander_distance{0.0f}; uint32 currentwaypoint{0}; uint32 curhealth{0}; uint32 curmana{0}; uint8 movementType{0}; - uint8 spawnMask{0}; uint32 npcflag{0}; uint32 unit_flags{0}; // enum UnitFlags mask values uint32 dynamicflags{0}; - uint32 ScriptId; - bool dbData{true}; }; struct CreatureModelInfo diff --git a/src/server/game/Entities/GameObject/GameObjectData.h b/src/server/game/Entities/GameObject/GameObjectData.h index 39c1a6e28..ab03b0098 100644 --- a/src/server/game/Entities/GameObject/GameObjectData.h +++ b/src/server/game/Entities/GameObject/GameObjectData.h @@ -19,6 +19,7 @@ #define GAMEOBJECTDATA_H #include "SharedDefines.h" +#include "SpawnData.h" #include #include #include @@ -710,24 +711,15 @@ enum GOState }; // from `gameobject` -struct GameObjectData +struct GameObjectData : public SpawnData { - explicit GameObjectData() = default; - uint32 id{ 0 }; // entry in gamobject_template - uint16 mapid{ 0 }; - uint32 phaseMask{ 0 }; - float posX{ 0.0f }; - float posY{ 0.0f }; - float posZ{ 0.0f }; - float orientation{ 0.0f }; + GameObjectData() : SpawnData(SPAWN_TYPE_GAMEOBJECT) {} + uint32 id{0}; // entry in gameobject_template G3D::Quat rotation; - int32 spawntimesecs{ 0 }; - uint32 ScriptId; - uint32 animprogress{ 0 }; - GOState go_state{ GO_STATE_ACTIVE }; - uint8 spawnMask{ 0 }; - uint8 artKit{ 0 }; - bool dbData{ true }; + int32 spawntimesecs{0}; + uint32 animprogress{0}; + GOState go_state{GO_STATE_ACTIVE}; + uint8 artKit{0}; }; #endif // GameObjectData_h__ diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 5d9ca3dc8..f1e100bba 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -310,6 +310,9 @@ ObjectMgr::ObjectMgr(): { _playerClassInfo[i] = nullptr; } + + // Initialize default spawn group + _spawnGroupDataStore[0] = {0, "Default Group", 0, SpawnGroupFlags(SPAWNGROUP_FLAG_SYSTEM)}; } ObjectMgr::~ObjectMgr() @@ -2400,6 +2403,7 @@ void ObjectMgr::LoadCreatures() data.unit_flags = fields[21].Get(); data.dynamicflags = fields[22].Get(); data.ScriptId = GetScriptId(fields[23].Get()); + data.spawnGroupId = 0; if (!data.ScriptId) data.ScriptId = cInfo->ScriptID; @@ -2578,6 +2582,7 @@ CreatureData const* ObjectMgr::LoadCreatureDataFromDB(ObjectGuid::LowType spawnI creatureData.unit_flags = fields[19].Get(); creatureData.dynamicflags = fields[20].Get(); creatureData.ScriptId = GetScriptId(fields[21].Get()); + creatureData.spawnGroupId = 0; if (!creatureData.ScriptId) creatureData.ScriptId = cInfo->ScriptID; @@ -2760,6 +2765,7 @@ ObjectGuid::LowType ObjectMgr::AddGOData(uint32 entry, uint32 mapId, float x, fl data.phaseMask = PHASEMASK_NORMAL; data.artKit = goinfo->type == GAMEOBJECT_TYPE_CAPTURE_POINT ? 21 : 0; data.dbData = false; + data.spawnGroupId = 0; AddGameobjectToGrid(spawnId, &data); @@ -2915,6 +2921,7 @@ void ObjectMgr::LoadGameobjects() data.rotation.w = fields[10].Get(); data.spawntimesecs = fields[11].Get(); data.ScriptId = GetScriptId(fields[18].Get()); + data.spawnGroupId = 0; if (!data.ScriptId) data.ScriptId = gInfo->ScriptId; @@ -8683,6 +8690,19 @@ void ObjectMgr::DeleteGOData(ObjectGuid::LowType guid) _gameObjectDataStore.erase(guid); } +SpawnData const* ObjectMgr::GetSpawnData(SpawnObjectType type, ObjectGuid::LowType spawnId) const +{ + switch (type) + { + case SPAWN_TYPE_CREATURE: + return GetCreatureData(spawnId); + case SPAWN_TYPE_GAMEOBJECT: + return GetGameObjectData(spawnId); + default: + return nullptr; + } +} + void ObjectMgr::LoadQuestRelationsHelper(QuestRelations& map, std::string const& table, bool starter, bool go) { uint32 oldMSTime = getMSTime(); diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index cbf2ff4e8..39bdbe59f 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -506,6 +506,7 @@ struct AcoreString typedef std::map LinkedRespawnContainer; typedef std::unordered_map CreatureDataContainer; typedef std::unordered_map GameObjectDataContainer; +typedef std::unordered_map SpawnGroupDataContainer; typedef std::map > TempSummonDataContainer; typedef std::map > GameObjectSummonDataContainer; typedef std::unordered_map CreatureLocaleContainer; @@ -1269,6 +1270,14 @@ public: if (itr == _gameObjectDataStore.end()) return nullptr; return &itr->second; } + [[nodiscard]] SpawnData const* GetSpawnData(SpawnObjectType type, ObjectGuid::LowType spawnId) const; + + [[nodiscard]] SpawnGroupTemplateData const* GetSpawnGroupData(uint32 groupId) const + { + auto itr = _spawnGroupDataStore.find(groupId); + return itr != _spawnGroupDataStore.end() ? &itr->second : nullptr; + } + [[nodiscard]] CreatureLocale const* GetCreatureLocale(uint32 entry) const { CreatureLocaleContainer::const_iterator itr = _creatureLocaleStore.find(entry); @@ -1643,6 +1652,7 @@ private: LinkedRespawnContainer _linkedRespawnStore; CreatureLocaleContainer _creatureLocaleStore; GameObjectDataContainer _gameObjectDataStore; + SpawnGroupDataContainer _spawnGroupDataStore; GameObjectLocaleContainer _gameObjectLocaleStore; GameObjectTemplateContainer _gameObjectTemplateStore; GameObjectTemplateAddonContainer _gameObjectTemplateAddonStore; diff --git a/src/server/game/Maps/SpawnData.h b/src/server/game/Maps/SpawnData.h new file mode 100644 index 000000000..b1136203d --- /dev/null +++ b/src/server/game/Maps/SpawnData.h @@ -0,0 +1,79 @@ +/* + * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef AZEROTHCORE_SPAWNDATA_H +#define AZEROTHCORE_SPAWNDATA_H + +#include "Define.h" +#include + +enum SpawnObjectType : uint8 +{ + SPAWN_TYPE_CREATURE = 0, + SPAWN_TYPE_GAMEOBJECT = 1, + + SPAWN_TYPE_MAX +}; + +enum SpawnObjectTypeMask : uint8 +{ + SPAWN_TYPEMASK_CREATURE = (1 << SPAWN_TYPE_CREATURE), + SPAWN_TYPEMASK_GAMEOBJECT = (1 << SPAWN_TYPE_GAMEOBJECT), + + SPAWN_TYPEMASK_ALL = SPAWN_TYPEMASK_CREATURE | SPAWN_TYPEMASK_GAMEOBJECT +}; + +enum SpawnGroupFlags : uint32 +{ + SPAWNGROUP_FLAG_NONE = 0x00, + SPAWNGROUP_FLAG_SYSTEM = 0x01, + SPAWNGROUP_FLAG_MANUAL_SPAWN = 0x04, + SPAWNGROUP_FLAG_DYNAMIC_SPAWN_RATE = 0x08, + SPAWNGROUP_FLAG_ESCORTQUESTNPC = 0x10, + + SPAWNGROUP_FLAG_ALL = SPAWNGROUP_FLAG_SYSTEM | + SPAWNGROUP_FLAG_MANUAL_SPAWN | SPAWNGROUP_FLAG_DYNAMIC_SPAWN_RATE | + SPAWNGROUP_FLAG_ESCORTQUESTNPC +}; + +struct SpawnGroupTemplateData +{ + uint32 groupId; + std::string name; + uint16 mapid; + SpawnGroupFlags flags; +}; + +struct SpawnData +{ + SpawnObjectType const type; + uint16 mapid{0}; + uint32 phaseMask{0}; + float posX{0.0f}; + float posY{0.0f}; + float posZ{0.0f}; + float orientation{0.0f}; + uint8 spawnMask{0}; + uint32 ScriptId{0}; + bool dbData{true}; + uint32 spawnGroupId{0}; + +protected: + SpawnData(SpawnObjectType t) : type(t) {} +}; + +#endif // AZEROTHCORE_SPAWNDATA_H