[9597] create battleground map at bg creation

when a bg gets created it will also get it's map
(old behaviour was, that map got's created when first player entered the instance)

the reason why battlegroundmaps aren't instantiated with a player object:
    * the only information from player-class we need is player->GetBattleGround()
      also we can't use anything else
      (e.g. playerlevel can be outside of bg-levelrange)
      -> cause bgs depend pretty much on their maps this caused circualr dependencies between map,bg,player
    * battlegroundmaps will _always_ be prepared by the bgsystem to set the proper data
    * there is not much shared in the creational process with dungeonmaps
      even the functioncall is different since players need to enqueue first for bgs,
      therefore again the player's way to that instance is only through the bgMgr
This commit is contained in:
balrok 2010-03-16 13:53:20 +01:00
parent db51c29235
commit 24d45c6a08
8 changed files with 24 additions and 21 deletions

View file

@ -208,7 +208,6 @@ void BattleGround::BroadcastWorker(Do& _do)
BattleGround::BattleGround() BattleGround::BattleGround()
{ {
m_TypeID = BattleGroundTypeId(0); m_TypeID = BattleGroundTypeId(0);
m_InstanceID = 0;
m_Status = STATUS_NONE; m_Status = STATUS_NONE;
m_ClientInstanceID = 0; m_ClientInstanceID = 0;
m_EndTime = 0; m_EndTime = 0;
@ -1326,10 +1325,9 @@ void BattleGround::RemoveFromBGFreeSlotQueue()
{ {
// set to be able to re-add if needed // set to be able to re-add if needed
m_InBGFreeSlotQueue = false; m_InBGFreeSlotQueue = false;
// uncomment this code when battlegrounds will work like instances
for (BGFreeSlotQueueType::iterator itr = sBattleGroundMgr.BGFreeSlotQueue[m_TypeID].begin(); itr != sBattleGroundMgr.BGFreeSlotQueue[m_TypeID].end(); ++itr) for (BGFreeSlotQueueType::iterator itr = sBattleGroundMgr.BGFreeSlotQueue[m_TypeID].begin(); itr != sBattleGroundMgr.BGFreeSlotQueue[m_TypeID].end(); ++itr)
{ {
if ((*itr)->GetInstanceID() == m_InstanceID) if ((*itr)->GetInstanceID() == GetInstanceID())
{ {
sBattleGroundMgr.BGFreeSlotQueue[m_TypeID].erase(itr); sBattleGroundMgr.BGFreeSlotQueue[m_TypeID].erase(itr);
return; return;

View file

@ -21,6 +21,7 @@
#include "Common.h" #include "Common.h"
#include "SharedDefines.h" #include "SharedDefines.h"
#include "Map.h"
// magic event-numbers // magic event-numbers
#define BG_EVENT_NONE 255 #define BG_EVENT_NONE 255
@ -298,7 +299,9 @@ class BattleGround
char const* GetName() const { return m_Name; } char const* GetName() const { return m_Name; }
BattleGroundTypeId GetTypeID() const { return m_TypeID; } BattleGroundTypeId GetTypeID() const { return m_TypeID; }
BattleGroundBracketId GetBracketId() const { return m_BracketId; } BattleGroundBracketId GetBracketId() const { return m_BracketId; }
uint32 GetInstanceID() const { return m_InstanceID; } // the instanceId check is also used to determine a bg-template
// that's why the m_map hack is here..
uint32 GetInstanceID() { return m_Map?GetBgMap()->GetInstanceId():0; }
BattleGroundStatus GetStatus() const { return m_Status; } BattleGroundStatus GetStatus() const { return m_Status; }
uint32 GetClientInstanceID() const { return m_ClientInstanceID; } uint32 GetClientInstanceID() const { return m_ClientInstanceID; }
uint32 GetStartTime() const { return m_StartTime; } uint32 GetStartTime() const { return m_StartTime; }
@ -323,7 +326,6 @@ class BattleGround
void SetTypeID(BattleGroundTypeId TypeID) { m_TypeID = TypeID; } void SetTypeID(BattleGroundTypeId TypeID) { m_TypeID = TypeID; }
//here we can count minlevel and maxlevel for players //here we can count minlevel and maxlevel for players
void SetBracket(PvPDifficultyEntry const* bracketEntry); void SetBracket(PvPDifficultyEntry const* bracketEntry);
void SetInstanceID(uint32 InstanceID) { m_InstanceID = InstanceID; }
void SetStatus(BattleGroundStatus Status) { m_Status = Status; } void SetStatus(BattleGroundStatus Status) { m_Status = Status; }
void SetClientInstanceID(uint32 InstanceID) { m_ClientInstanceID = InstanceID; } void SetClientInstanceID(uint32 InstanceID) { m_ClientInstanceID = InstanceID; }
void SetStartTime(uint32 Time) { m_StartTime = Time; } void SetStartTime(uint32 Time) { m_StartTime = Time; }
@ -562,7 +564,6 @@ class BattleGround
private: private:
/* Battleground */ /* Battleground */
BattleGroundTypeId m_TypeID; BattleGroundTypeId m_TypeID;
uint32 m_InstanceID; //BattleGround Instance's GUID!
BattleGroundStatus m_Status; BattleGroundStatus m_Status;
uint32 m_ClientInstanceID; //the instance-id which is sent to the client and without any other internal use uint32 m_ClientInstanceID; //the instance-id which is sent to the client and without any other internal use
uint32 m_StartTime; uint32 m_StartTime;

View file

@ -1576,8 +1576,9 @@ BattleGround * BattleGroundMgr::CreateNewBattleGround(BattleGroundTypeId bgTypeI
return 0; return 0;
} }
// generate a new instance id // will also set m_bgMap, instanceid
bg->SetInstanceID(sMapMgr.GenerateInstanceId()); // set instance id sMapMgr.CreateBgMap(bg->GetMapId(), bg);
bg->SetClientInstanceID(CreateClientVisibleInstanceId(bgTypeId, bracketEntry->GetBracketId())); bg->SetClientInstanceID(CreateClientVisibleInstanceId(bgTypeId, bracketEntry->GetBracketId()));
// reset the new bg (set status to status_wait_queue from status_none) // reset the new bg (set status to status_wait_queue from status_none)
@ -1617,7 +1618,6 @@ uint32 BattleGroundMgr::CreateBattleGround(BattleGroundTypeId bgTypeId, bool IsA
bg->SetMapId(MapID); bg->SetMapId(MapID);
bg->SetTypeID(bgTypeId); bg->SetTypeID(bgTypeId);
bg->SetInstanceID(0);
bg->SetArenaorBGType(IsArena); bg->SetArenaorBGType(IsArena);
bg->SetMinPlayersPerTeam(MinPlayersPerTeam); bg->SetMinPlayersPerTeam(MinPlayersPerTeam);
bg->SetMaxPlayersPerTeam(MaxPlayersPerTeam); bg->SetMaxPlayersPerTeam(MaxPlayersPerTeam);

View file

@ -104,11 +104,8 @@ void MapInstanced::UnloadAll(bool pForce)
Map::UnloadAll(pForce); Map::UnloadAll(pForce);
} }
/* /// returns a new or existing Instance
- return the right instance for the object, based on its InstanceId /// in case of battlegrounds it will only return an existing map, those maps are created by bg-system
- create the instance if it's not created already
- the player is not actually added to the instance (only in InstanceMap::Add)
*/
Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player) Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player)
{ {
if(GetId() != mapId || !player) if(GetId() != mapId || !player)
@ -119,13 +116,11 @@ Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player)
if(IsBattleGroundOrArena()) if(IsBattleGroundOrArena())
{ {
// instantiate or find existing bg map for player // find existing bg map for player
// the instance id is set in battlegroundid
NewInstanceId = player->GetBattleGroundId(); NewInstanceId = player->GetBattleGroundId();
ASSERT(NewInstanceId); ASSERT(NewInstanceId);
map = _FindMap(NewInstanceId); map = _FindMap(NewInstanceId);
if(!map) ASSERT(map);
map = CreateBattleGroundMap(NewInstanceId, player->GetBattleGround());
} }
else else
{ {

View file

@ -58,11 +58,11 @@ class MANGOS_DLL_DECL MapInstanced : public Map
InstancedMaps &GetInstancedMaps() { return m_InstancedMaps; } InstancedMaps &GetInstancedMaps() { return m_InstancedMaps; }
virtual void InitVisibilityDistance(); virtual void InitVisibilityDistance();
BattleGroundMap* CreateBattleGroundMap(uint32 InstanceId, BattleGround* bg);
private: private:
InstanceMap* CreateInstance(uint32 InstanceId, InstanceSave *save, Difficulty difficulty); InstanceMap* CreateInstance(uint32 InstanceId, InstanceSave *save, Difficulty difficulty);
BattleGroundMap* CreateBattleGroundMap(uint32 InstanceId, BattleGround* bg);
InstancedMaps m_InstancedMaps; InstancedMaps m_InstancedMaps;

View file

@ -138,6 +138,13 @@ Map* MapManager::CreateMap(uint32 id, const WorldObject* obj)
return m; return m;
} }
Map* MapManager::CreateBgMap(uint32 mapid, BattleGround* bg)
{
Map *m = _createBaseMap(mapid);
((MapInstanced*)m)->CreateBattleGroundMap(sMapMgr.GenerateInstanceId(), bg);
return m;
}
Map* MapManager::FindMap(uint32 mapid, uint32 instanceId) const Map* MapManager::FindMap(uint32 mapid, uint32 instanceId) const
{ {
Map *map = _findMap(mapid); Map *map = _findMap(mapid);

View file

@ -27,6 +27,7 @@
#include "GridStates.h" #include "GridStates.h"
class Transport; class Transport;
class BattleGround;
class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::ClassLevelLockable<MapManager, ACE_Thread_Mutex> > class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::ClassLevelLockable<MapManager, ACE_Thread_Mutex> >
{ {
@ -38,6 +39,7 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::
public: public:
Map* CreateMap(uint32, const WorldObject* obj); Map* CreateMap(uint32, const WorldObject* obj);
Map* CreateBgMap(uint32 mapid, BattleGround* bg);
Map const* CreateBaseMap(uint32 id) const { return const_cast<MapManager*>(this)->_createBaseMap(id); } Map const* CreateBaseMap(uint32 id) const { return const_cast<MapManager*>(this)->_createBaseMap(id); }
Map* FindMap(uint32 mapid, uint32 instanceId = 0) const; Map* FindMap(uint32 mapid, uint32 instanceId = 0) const;

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "9596" #define REVISION_NR "9597"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__