call OnObjectDBLoad(Creature/GameObject) for battleground at object-loading

this is a virtual function and can be used to move gameobjects
and creatures from battlegroundcode to database

for this i also had to add a BattleGround-pointer to the map
so i renamed CreateBattleGround(instanceid) to CreateBattleGroundMap(instanceid, Battleground*)
This commit is contained in:
balrok 2008-12-06 18:52:47 +01:00 committed by balrok
parent 1665077dc4
commit bd87209498
5 changed files with 17 additions and 5 deletions

View file

@ -477,6 +477,9 @@ class BattleGround
virtual void RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPacket);
// can be extended in in BG subclass
virtual void OnObjectDBLoad(Creature* /*creature*/);
virtual void OnObjectDBLoad(GameObject* /*obj*/);
void HandleTriggerBuff(uint64 const& go_guid);
// TODO: make this protected:

View file

@ -43,6 +43,7 @@ class Group;
class InstanceSave;
struct ScriptInfo;
struct ScriptAction;
class BattleGround;
typedef ACE_RW_Thread_Mutex GridRWLock;
@ -585,6 +586,10 @@ class MANGOS_DLL_SPEC BattleGroundMap : public Map
void UnloadAll(bool pForce);
virtual void InitVisibilityDistance();
BattleGround* GetBG() { return m_bg; }
void SetBG(BattleGround* bg) { m_bg = bg; }
private:
BattleGround* m_bg;
};
/*inline

View file

@ -135,7 +135,7 @@ Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player)
ASSERT(NewInstanceId);
map = _FindMap(NewInstanceId);
if(!map)
map = CreateBattleGround(NewInstanceId);
map = CreateBattleGroundMap(NewInstanceId, player->GetBattleGround());
}
else
{
@ -208,15 +208,16 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave *save,
return map;
}
BattleGroundMap* MapInstanced::CreateBattleGround(uint32 InstanceId)
BattleGroundMap* MapInstanced::CreateBattleGroundMap(uint32 InstanceId, BattleGround* bg)
{
// load/create a map
Guard guard(*this);
sLog.outDebug("MapInstanced::CreateBattleGround: map bg %d for %d created.", InstanceId, GetId());
sLog.outDebug("MapInstanced::CreateBattleGroundMap: instance:%d for map:%d and bgType:%d created.", InstanceId, GetId(), bg->GetTypeID());
BattleGroundMap *map = new BattleGroundMap(GetId(), GetGridExpiry(), InstanceId, this);
ASSERT(map->IsBattleGroundOrArena());
map->SetBG(bg);
m_InstancedMaps[InstanceId] = map;
return map;

View file

@ -62,7 +62,7 @@ class MANGOS_DLL_DECL MapInstanced : public Map
private:
InstanceMap* CreateInstance(uint32 InstanceId, InstanceSave *save, uint8 difficulty);
BattleGroundMap* CreateBattleGround(uint32 InstanceId);
BattleGroundMap* CreateBattleGroundMap(uint32 InstanceId, BattleGround* bg);
InstancedMaps m_InstancedMaps;

View file

@ -109,6 +109,8 @@ template<> void addUnitState(Creature *obj, CellPair const& cell_pair)
template <class T>
void LoadHelper(CellGuidSet const& guid_set, CellPair &cell, GridRefManager<T> &m, uint32 &count, Map* map)
{
BattleGround* bg = map->IsBattleGroundOrArena() ? ((BattleGroundMap*)map)->GetBG() : NULL;
for(CellGuidSet::const_iterator i_guid = guid_set.begin(); i_guid != guid_set.end(); ++i_guid)
{
T* obj = new T;
@ -127,9 +129,10 @@ void LoadHelper(CellGuidSet const& guid_set, CellPair &cell, GridRefManager<T> &
obj->AddToWorld();
if(obj->isActiveObject())
map->AddToActive(obj);
if (bg)
bg->OnObjectDBLoad(obj);
++count;
}
}