TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PoolGroup< T > Class Template Reference

#include <PoolMgr.h>

Public Member Functions

 PoolGroup ()
 
void SetPoolId (uint32 pool_id)
 
 ~PoolGroup ()
 
bool isEmpty () const
 
void AddEntry (PoolObject &poolitem, uint32 maxentries)
 
bool CheckPool () const
 
PoolObjectRollOne (ActivePoolData &spawns, uint64 triggerFrom)
 
void DespawnObject (ActivePoolData &spawns, uint64 guid=0)
 
void Despawn1Object (uint64 guid)
 
void SpawnObject (ActivePoolData &spawns, uint32 limit, uint64 triggerFrom)
 
void Spawn1Object (PoolObject *obj)
 
void ReSpawn1Object (PoolObject *obj)
 
void RemoveOneRelation (uint32 child_pool_id)
 
uint64 GetFirstEqualChancedObjectId ()
 
uint32 GetPoolId () const
 

Private Types

typedef std::vector< PoolObjectPoolObjectList
 

Private Attributes

uint32 poolId
 
PoolObjectList ExplicitlyChanced
 
PoolObjectList EqualChanced
 

Member Typedef Documentation

template<class T>
typedef std::vector<PoolObject> PoolGroup< T >::PoolObjectList
private

Constructor & Destructor Documentation

template<class T>
PoolGroup< T >::PoolGroup ( )
inlineexplicit
73 : poolId(0) { }
uint32 poolId
Definition: PoolMgr.h:95
template<class T>
PoolGroup< T >::~PoolGroup ( )
inline
75 { };

Member Function Documentation

template<class T >
void PoolGroup< T >::AddEntry ( PoolObject poolitem,
uint32  maxentries 
)
138 {
139  if (poolitem.chance != 0 && maxentries == 1)
140  ExplicitlyChanced.push_back(poolitem);
141  else
142  EqualChanced.push_back(poolitem);
143 }
PoolObjectList EqualChanced
Definition: PoolMgr.h:97
PoolObjectList ExplicitlyChanced
Definition: PoolMgr.h:96
float chance
Definition: PoolMgr.h:35

+ Here is the caller graph for this function:

template<class T >
bool PoolGroup< T >::CheckPool ( ) const
148 {
149  if (EqualChanced.empty())
150  {
151  float chance = 0;
152  for (uint32 i = 0; i < ExplicitlyChanced.size(); ++i)
153  chance += ExplicitlyChanced[i].chance;
154  if (chance != 100 && chance != 0)
155  return false;
156  }
157  return true;
158 }
PoolObjectList EqualChanced
Definition: PoolMgr.h:97
PoolObjectList ExplicitlyChanced
Definition: PoolMgr.h:96
uint32_t uint32
Definition: Define.h:150
template<class T>
void PoolGroup< T >::Despawn1Object ( uint64  guid)
template<class T >
void PoolGroup< T >::DespawnObject ( ActivePoolData spawns,
uint64  guid = 0 
)
193 {
194  for (size_t i=0; i < EqualChanced.size(); ++i)
195  {
196  // if spawned
197  if (spawns.IsActiveObject<T>(EqualChanced[i].guid))
198  {
199  if (!guid || EqualChanced[i].guid == guid)
200  {
201  Despawn1Object(EqualChanced[i].guid);
202  spawns.RemoveObject<T>(EqualChanced[i].guid, poolId);
203  }
204  }
205  }
206 
207  for (size_t i = 0; i < ExplicitlyChanced.size(); ++i)
208  {
209  // spawned
210  if (spawns.IsActiveObject<T>(ExplicitlyChanced[i].guid))
211  {
212  if (!guid || ExplicitlyChanced[i].guid == guid)
213  {
215  spawns.RemoveObject<T>(ExplicitlyChanced[i].guid, poolId);
216  }
217  }
218  }
219 }
bool IsActiveObject(uint64 db_guid_or_pool_id) const
PoolObjectList EqualChanced
Definition: PoolMgr.h:97
PoolObjectList ExplicitlyChanced
Definition: PoolMgr.h:96
void Despawn1Object(uint64 guid)
void RemoveObject(uint64 db_guid_or_pool_id, uint32 pool_id)
uint32 poolId
Definition: PoolMgr.h:95

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T>
uint64 PoolGroup< T >::GetFirstEqualChancedObjectId ( )
inline
88  {
89  if (EqualChanced.empty())
90  return 0;
91  return EqualChanced.front().guid;
92  }
PoolObjectList EqualChanced
Definition: PoolMgr.h:97
template<class T>
uint32 PoolGroup< T >::GetPoolId ( ) const
inline
93 { return poolId; }
uint32 poolId
Definition: PoolMgr.h:95
template<class T>
bool PoolGroup< T >::isEmpty ( ) const
inline
76 { return ExplicitlyChanced.empty() && EqualChanced.empty(); }
PoolObjectList EqualChanced
Definition: PoolMgr.h:97
PoolObjectList ExplicitlyChanced
Definition: PoolMgr.h:96
template<class T>
void PoolGroup< T >::RemoveOneRelation ( uint32  child_pool_id)
template<class T>
void PoolGroup< T >::ReSpawn1Object ( PoolObject obj)
template<class T >
PoolObject * PoolGroup< T >::RollOne ( ActivePoolData spawns,
uint64  triggerFrom 
)
162 {
163  if (!ExplicitlyChanced.empty())
164  {
165  float roll = (float)rand_chance();
166 
167  for (uint32 i = 0; i < ExplicitlyChanced.size(); ++i)
168  {
169  roll -= ExplicitlyChanced[i].chance;
170  // Triggering object is marked as spawned at this time and can be also rolled (respawn case)
171  // so this need explicit check for this case
172  if (roll < 0 && (ExplicitlyChanced[i].guid == triggerFrom || !spawns.IsActiveObject<T>(ExplicitlyChanced[i].guid)))
173  return &ExplicitlyChanced[i];
174  }
175  }
176  if (!EqualChanced.empty())
177  {
178  uint32 index = urand(0, EqualChanced.size()-1);
179  // Triggering object is marked as spawned at this time and can be also rolled (respawn case)
180  // so this need explicit check for this case
181  if (EqualChanced[index].guid == triggerFrom || !spawns.IsActiveObject<T>(EqualChanced[index].guid))
182  return &EqualChanced[index];
183  }
184 
185  return NULL;
186 }
bool IsActiveObject(uint64 db_guid_or_pool_id) const
PoolObjectList EqualChanced
Definition: PoolMgr.h:97
PoolObjectList ExplicitlyChanced
Definition: PoolMgr.h:96
arena_t NULL
Definition: jemalloc_internal.h:624
double rand_chance()
Definition: Random.cpp:74
uint32 urand(uint32 min, uint32 max)
Definition: Random.cpp:45
uint32_t uint32
Definition: Define.h:150

+ Here is the call graph for this function:

template<class T>
void PoolGroup< T >::SetPoolId ( uint32  pool_id)
inline
74 { poolId = pool_id; }
uint32 poolId
Definition: PoolMgr.h:95

+ Here is the caller graph for this function:

template<class T>
void PoolGroup< T >::Spawn1Object ( PoolObject obj)

+ Here is the caller graph for this function:

template<class T >
void PoolGroup< T >::SpawnObject ( ActivePoolData spawns,
uint32  limit,
uint64  triggerFrom 
)
339 {
340  uint32 lastDespawned = 0;
341  int count = limit - spawns.GetActiveObjectCount(poolId);
342 
343  // If triggered from some object respawn this object is still marked as spawned
344  // and also counted into m_SpawnedPoolAmount so we need increase count to be
345  // spawned by 1
346  if (triggerFrom)
347  ++count;
348 
349  // This will try to spawn the rest of pool, not guaranteed
350  for (int i = 0; i < count; ++i)
351  {
352  PoolObject* obj = RollOne(spawns, triggerFrom);
353  if (!obj)
354  continue;
355  if (obj->guid == lastDespawned)
356  continue;
357 
358  if (obj->guid == triggerFrom)
359  {
360  ReSpawn1Object(obj);
361  triggerFrom = 0;
362  continue;
363  }
364  spawns.ActivateObject<T>(obj->guid, poolId);
365  Spawn1Object(obj);
366 
367  if (triggerFrom)
368  {
369  // One spawn one despawn no count increase
370  DespawnObject(spawns, triggerFrom);
371  lastDespawned = triggerFrom;
372  triggerFrom = 0;
373  }
374  }
375 }
void ReSpawn1Object(PoolObject *obj)
void ActivateObject(uint64 db_guid_or_pool_id, uint32 pool_id)
void DespawnObject(ActivePoolData &spawns, uint64 guid=0)
Definition: PoolMgr.cpp:192
Definition: PoolMgr.h:32
void Spawn1Object(PoolObject *obj)
uint32_t uint32
Definition: Define.h:150
PoolObject * RollOne(ActivePoolData &spawns, uint64 triggerFrom)
Definition: PoolMgr.cpp:161
uint32 GetActiveObjectCount(uint32 pool_id) const
Definition: PoolMgr.cpp:29
uint64 guid
Definition: PoolMgr.h:34
uint32 poolId
Definition: PoolMgr.h:95

+ Here is the call graph for this function:

Member Data Documentation

template<class T>
PoolObjectList PoolGroup< T >::EqualChanced
private
template<class T>
PoolObjectList PoolGroup< T >::ExplicitlyChanced
private
template<class T>
uint32 PoolGroup< T >::poolId
private

The documentation for this class was generated from the following files: