mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 19:37:02 +00:00
[9147] More code cleanup in poolmgr.
* Use normal result pointer instead args pair in pool roll. * Send PoolObject pointer into (Re)Spawn1Object and set internaly spawned field.
This commit is contained in:
parent
4d90a2e1f2
commit
197ebb6bfd
3 changed files with 54 additions and 56 deletions
|
|
@ -68,7 +68,7 @@ bool PoolGroup<T>::IsSpawnedObject(uint32 guid) const
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void PoolGroup<T>::RollOne(int32& index, PoolObjectList** store, uint32 triggerFrom)
|
PoolObject* PoolGroup<T>::RollOne(uint32 triggerFrom)
|
||||||
{
|
{
|
||||||
if (!ExplicitlyChanced.empty())
|
if (!ExplicitlyChanced.empty())
|
||||||
{
|
{
|
||||||
|
|
@ -80,27 +80,20 @@ void PoolGroup<T>::RollOne(int32& index, PoolObjectList** store, uint32 triggerF
|
||||||
// Triggering object is marked as spawned at this time and can be also rolled (respawn case)
|
// Triggering object is marked as spawned at this time and can be also rolled (respawn case)
|
||||||
// so this need explicit check for this case
|
// so this need explicit check for this case
|
||||||
if (roll < 0 && (!ExplicitlyChanced[i].spawned || ExplicitlyChanced[i].guid == triggerFrom))
|
if (roll < 0 && (!ExplicitlyChanced[i].spawned || ExplicitlyChanced[i].guid == triggerFrom))
|
||||||
{
|
return &ExplicitlyChanced[i];
|
||||||
index = i;
|
|
||||||
*store = &ExplicitlyChanced;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EqualChanced.empty())
|
if (!EqualChanced.empty())
|
||||||
{
|
{
|
||||||
index = irand(0, EqualChanced.size()-1);
|
int32 index = irand(0, EqualChanced.size()-1);
|
||||||
// Triggering object is marked as spawned at this time and can be also rolled (respawn case)
|
// Triggering object is marked as spawned at this time and can be also rolled (respawn case)
|
||||||
// so this need explicit check for this case
|
// so this need explicit check for this case
|
||||||
if (!EqualChanced[index].spawned || EqualChanced[index].guid == triggerFrom)
|
if (!EqualChanced[index].spawned || EqualChanced[index].guid == triggerFrom)
|
||||||
{
|
return &EqualChanced[index];
|
||||||
*store = &EqualChanced;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
index = -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main method to despawn a creature or gameobject in a pool
|
// Main method to despawn a creature or gameobject in a pool
|
||||||
|
|
@ -210,23 +203,20 @@ void PoolGroup<T>::SpawnObject(uint32 limit, uint32 triggerFrom)
|
||||||
// This will try to spawn the rest of pool, not guaranteed
|
// This will try to spawn the rest of pool, not guaranteed
|
||||||
for (int i = 0; i < count; ++i)
|
for (int i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
int index;
|
PoolObject* obj = RollOne(triggerFrom);
|
||||||
PoolObjectList* store;
|
if (!obj)
|
||||||
|
|
||||||
RollOne(index, &store, triggerFrom);
|
|
||||||
if (index == -1)
|
|
||||||
continue;
|
continue;
|
||||||
if ((*store)[index].guid == lastDespawned)
|
if (obj->guid == lastDespawned)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((*store)[index].guid == triggerFrom)
|
if (obj->guid == triggerFrom)
|
||||||
{
|
{
|
||||||
(*store)[index].spawned = ReSpawn1Object(triggerFrom);
|
ReSpawn1Object(obj);
|
||||||
triggerFrom = 0;
|
triggerFrom = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
(*store)[index].spawned = Spawn1Object((*store)[index].guid);
|
Spawn1Object(obj);
|
||||||
|
|
||||||
if (triggerFrom)
|
if (triggerFrom)
|
||||||
{
|
{
|
||||||
|
|
@ -242,11 +232,11 @@ void PoolGroup<T>::SpawnObject(uint32 limit, uint32 triggerFrom)
|
||||||
|
|
||||||
// Method that is actualy doing the spawn job on 1 creature
|
// Method that is actualy doing the spawn job on 1 creature
|
||||||
template <>
|
template <>
|
||||||
bool PoolGroup<Creature>::Spawn1Object(uint32 guid)
|
void PoolGroup<Creature>::Spawn1Object(PoolObject* obj)
|
||||||
{
|
{
|
||||||
if (CreatureData const* data = sObjectMgr.GetCreatureData(guid))
|
if (CreatureData const* data = sObjectMgr.GetCreatureData(obj->guid))
|
||||||
{
|
{
|
||||||
sObjectMgr.AddCreatureToGrid(guid, data);
|
sObjectMgr.AddCreatureToGrid(obj->guid, data);
|
||||||
|
|
||||||
// Spawn if necessary (loaded grids only)
|
// Spawn if necessary (loaded grids only)
|
||||||
Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(data->mapid));
|
Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(data->mapid));
|
||||||
|
|
@ -254,27 +244,29 @@ bool PoolGroup<Creature>::Spawn1Object(uint32 guid)
|
||||||
if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY))
|
if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY))
|
||||||
{
|
{
|
||||||
Creature* pCreature = new Creature;
|
Creature* pCreature = new Creature;
|
||||||
//sLog.outDebug("Spawning creature %u",guid);
|
//sLog.outDebug("Spawning creature %u",obj->guid);
|
||||||
if (!pCreature->LoadFromDB(guid, map))
|
if (!pCreature->LoadFromDB(obj->guid, map))
|
||||||
{
|
{
|
||||||
delete pCreature;
|
delete pCreature;
|
||||||
return false;
|
obj->spawned = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
map->Add(pCreature);
|
map->Add(pCreature);
|
||||||
}
|
}
|
||||||
return true;
|
obj->spawned = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return false;
|
obj->spawned = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Same for 1 gameobject
|
// Same for 1 gameobject
|
||||||
template <>
|
template <>
|
||||||
bool PoolGroup<GameObject>::Spawn1Object(uint32 guid)
|
void PoolGroup<GameObject>::Spawn1Object(PoolObject* obj)
|
||||||
{
|
{
|
||||||
if (GameObjectData const* data = sObjectMgr.GetGOData(guid))
|
if (GameObjectData const* data = sObjectMgr.GetGOData(obj->guid))
|
||||||
{
|
{
|
||||||
sObjectMgr.AddGameobjectToGrid(guid, data);
|
sObjectMgr.AddGameobjectToGrid(obj->guid, data);
|
||||||
// Spawn if necessary (loaded grids only)
|
// Spawn if necessary (loaded grids only)
|
||||||
// this base map checked as non-instanced and then only existed
|
// this base map checked as non-instanced and then only existed
|
||||||
Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(data->mapid));
|
Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(data->mapid));
|
||||||
|
|
@ -282,11 +274,12 @@ bool PoolGroup<GameObject>::Spawn1Object(uint32 guid)
|
||||||
if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY))
|
if (!map->Instanceable() && map->IsLoaded(data->posX, data->posY))
|
||||||
{
|
{
|
||||||
GameObject* pGameobject = new GameObject;
|
GameObject* pGameobject = new GameObject;
|
||||||
//sLog.outDebug("Spawning gameobject %u", guid);
|
//sLog.outDebug("Spawning gameobject %u", obj->guid);
|
||||||
if (!pGameobject->LoadFromDB(guid, map))
|
if (!pGameobject->LoadFromDB(obj->guid, map))
|
||||||
{
|
{
|
||||||
delete pGameobject;
|
delete pGameobject;
|
||||||
return false;
|
obj->spawned = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -294,50 +287,55 @@ bool PoolGroup<GameObject>::Spawn1Object(uint32 guid)
|
||||||
map->Add(pGameobject);
|
map->Add(pGameobject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
obj->spawned = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return false;
|
obj->spawned = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Same for 1 pool
|
// Same for 1 pool
|
||||||
template <>
|
template <>
|
||||||
bool PoolGroup<Pool>::Spawn1Object(uint32 child_pool_id)
|
void PoolGroup<Pool>::Spawn1Object(PoolObject* obj)
|
||||||
{
|
{
|
||||||
sPoolMgr.SpawnPool(child_pool_id);
|
sPoolMgr.SpawnPool(obj->guid);
|
||||||
return true;
|
obj->spawned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method that does the respawn job on the specified creature
|
// Method that does the respawn job on the specified creature
|
||||||
template <>
|
template <>
|
||||||
bool PoolGroup<Creature>::ReSpawn1Object(uint32 guid)
|
void PoolGroup<Creature>::ReSpawn1Object(PoolObject* obj)
|
||||||
{
|
{
|
||||||
if (CreatureData const* data = sObjectMgr.GetCreatureData(guid))
|
if (CreatureData const* data = sObjectMgr.GetCreatureData(obj->guid))
|
||||||
{
|
{
|
||||||
if (Creature* pCreature = ObjectAccessor::GetCreatureInWorld(MAKE_NEW_GUID(guid, data->id, HIGHGUID_UNIT)))
|
if (Creature* pCreature = ObjectAccessor::GetCreatureInWorld(MAKE_NEW_GUID(obj->guid, data->id, HIGHGUID_UNIT)))
|
||||||
pCreature->GetMap()->Add(pCreature);
|
pCreature->GetMap()->Add(pCreature);
|
||||||
return true;
|
obj->spawned = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
obj->spawned = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Same for 1 gameobject
|
// Same for 1 gameobject
|
||||||
template <>
|
template <>
|
||||||
bool PoolGroup<GameObject>::ReSpawn1Object(uint32 guid)
|
void PoolGroup<GameObject>::ReSpawn1Object(PoolObject* obj)
|
||||||
{
|
{
|
||||||
if (GameObjectData const* data = sObjectMgr.GetGOData(guid))
|
if (GameObjectData const* data = sObjectMgr.GetGOData(obj->guid))
|
||||||
{
|
{
|
||||||
if (GameObject* pGameobject = ObjectAccessor::GetGameObjectInWorld(MAKE_NEW_GUID(guid, data->id, HIGHGUID_GAMEOBJECT)))
|
if (GameObject* pGameobject = ObjectAccessor::GetGameObjectInWorld(MAKE_NEW_GUID(obj->guid, data->id, HIGHGUID_GAMEOBJECT)))
|
||||||
pGameobject->GetMap()->Add(pGameobject);
|
pGameobject->GetMap()->Add(pGameobject);
|
||||||
return true;
|
obj->spawned = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
obj->spawned = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nothing to do for a child Pool
|
// Nothing to do for a child Pool
|
||||||
template <>
|
template <>
|
||||||
bool PoolGroup<Pool>::ReSpawn1Object(uint32 /*guid*/)
|
void PoolGroup<Pool>::ReSpawn1Object(PoolObject* obj)
|
||||||
{
|
{
|
||||||
return true;
|
obj->spawned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,13 +47,13 @@ class PoolGroup
|
||||||
bool isEmpty() const { return ExplicitlyChanced.empty() && EqualChanced.empty(); }
|
bool isEmpty() const { return ExplicitlyChanced.empty() && EqualChanced.empty(); }
|
||||||
void AddEntry(PoolObject& poolitem, uint32 maxentries);
|
void AddEntry(PoolObject& poolitem, uint32 maxentries);
|
||||||
bool CheckPool() const;
|
bool CheckPool() const;
|
||||||
void RollOne(int32& index, PoolObjectList** store, uint32 triggerFrom);
|
PoolObject* RollOne(uint32 triggerFrom);
|
||||||
bool IsSpawnedObject(uint32 guid) const;
|
bool IsSpawnedObject(uint32 guid) const;
|
||||||
void DespawnObject(uint32 guid=0);
|
void DespawnObject(uint32 guid=0);
|
||||||
void Despawn1Object(uint32 guid);
|
void Despawn1Object(uint32 guid);
|
||||||
void SpawnObject(uint32 limit, uint32 triggerFrom);
|
void SpawnObject(uint32 limit, uint32 triggerFrom);
|
||||||
bool Spawn1Object(uint32 guid);
|
void Spawn1Object(PoolObject* obj);
|
||||||
bool ReSpawn1Object(uint32 guid);
|
void ReSpawn1Object(PoolObject* obj);
|
||||||
void RemoveOneRelation(uint16 child_pool_id);
|
void RemoveOneRelation(uint16 child_pool_id);
|
||||||
private:
|
private:
|
||||||
PoolObjectList ExplicitlyChanced;
|
PoolObjectList ExplicitlyChanced;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "9146"
|
#define REVISION_NR "9147"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue