feat(Core/Spawns): introduce SpawnData base struct and spawn group infrastructure (#25152)

Co-authored-by: r00ty-tc <r00ty-tc@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Andrew 2026-03-23 01:30:22 -03:00 committed by GitHub
parent 27b0ecc6dc
commit 9757174460
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 120 additions and 27 deletions

View file

@ -22,6 +22,7 @@
#include "DatabaseEnv.h"
#include "ItemTemplate.h"
#include "LootMgr.h"
#include "SpawnData.h"
#include "Unit.h"
#include <list>
@ -365,32 +366,23 @@ typedef std::unordered_map<uint8, EquipmentInfo> EquipmentInfoContainerInternal;
typedef std::unordered_map<uint32, EquipmentInfoContainerInternal> 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

View file

@ -19,6 +19,7 @@
#define GAMEOBJECTDATA_H
#include "SharedDefines.h"
#include "SpawnData.h"
#include <array>
#include <vector>
#include <string>
@ -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__

View file

@ -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<uint32>();
data.dynamicflags = fields[22].Get<uint32>();
data.ScriptId = GetScriptId(fields[23].Get<std::string>());
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<uint32>();
creatureData.dynamicflags = fields[20].Get<uint32>();
creatureData.ScriptId = GetScriptId(fields[21].Get<std::string>());
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<float>();
data.spawntimesecs = fields[11].Get<int32>();
data.ScriptId = GetScriptId(fields[18].Get<std::string>());
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();

View file

@ -506,6 +506,7 @@ struct AcoreString
typedef std::map<ObjectGuid, ObjectGuid> LinkedRespawnContainer;
typedef std::unordered_map<ObjectGuid::LowType, CreatureData> CreatureDataContainer;
typedef std::unordered_map<ObjectGuid::LowType, GameObjectData> GameObjectDataContainer;
typedef std::unordered_map<uint32, SpawnGroupTemplateData> SpawnGroupDataContainer;
typedef std::map<TempSummonGroupKey, std::vector<TempSummonData> > TempSummonDataContainer;
typedef std::map<TempSummonGroupKey, std::vector<GameObjectSummonData> > GameObjectSummonDataContainer;
typedef std::unordered_map<uint32, CreatureLocale> 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;

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef AZEROTHCORE_SPAWNDATA_H
#define AZEROTHCORE_SPAWNDATA_H
#include "Define.h"
#include <string>
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