From 24d45c6a08ff15679f0a472c653bfee82ac0b2a0 Mon Sep 17 00:00:00 2001 From: balrok Date: Tue, 16 Mar 2010 13:53:20 +0100 Subject: [PATCH] [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 --- src/game/BattleGround.cpp | 6 ++---- src/game/BattleGround.h | 7 ++++--- src/game/BattleGroundMgr.cpp | 6 +++--- src/game/MapInstanced.cpp | 13 ++++--------- src/game/MapInstanced.h | 2 +- src/game/MapManager.cpp | 7 +++++++ src/game/MapManager.h | 2 ++ src/shared/revision_nr.h | 2 +- 8 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/game/BattleGround.cpp b/src/game/BattleGround.cpp index 7bc403df5..42443db28 100644 --- a/src/game/BattleGround.cpp +++ b/src/game/BattleGround.cpp @@ -208,7 +208,6 @@ void BattleGround::BroadcastWorker(Do& _do) BattleGround::BattleGround() { m_TypeID = BattleGroundTypeId(0); - m_InstanceID = 0; m_Status = STATUS_NONE; m_ClientInstanceID = 0; m_EndTime = 0; @@ -1326,10 +1325,9 @@ void BattleGround::RemoveFromBGFreeSlotQueue() { // set to be able to re-add if needed 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) { - if ((*itr)->GetInstanceID() == m_InstanceID) + if ((*itr)->GetInstanceID() == GetInstanceID()) { sBattleGroundMgr.BGFreeSlotQueue[m_TypeID].erase(itr); return; @@ -1840,4 +1838,4 @@ void BattleGround::SetBracket( PvPDifficultyEntry const* bracketEntry ) { m_BracketId = bracketEntry->GetBracketId(); SetLevelRange(bracketEntry->minLevel,bracketEntry->maxLevel); -} \ No newline at end of file +} diff --git a/src/game/BattleGround.h b/src/game/BattleGround.h index da7523ac8..dae112979 100644 --- a/src/game/BattleGround.h +++ b/src/game/BattleGround.h @@ -21,6 +21,7 @@ #include "Common.h" #include "SharedDefines.h" +#include "Map.h" // magic event-numbers #define BG_EVENT_NONE 255 @@ -298,7 +299,9 @@ class BattleGround char const* GetName() const { return m_Name; } BattleGroundTypeId GetTypeID() const { return m_TypeID; } 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; } uint32 GetClientInstanceID() const { return m_ClientInstanceID; } uint32 GetStartTime() const { return m_StartTime; } @@ -323,7 +326,6 @@ class BattleGround void SetTypeID(BattleGroundTypeId TypeID) { m_TypeID = TypeID; } //here we can count minlevel and maxlevel for players void SetBracket(PvPDifficultyEntry const* bracketEntry); - void SetInstanceID(uint32 InstanceID) { m_InstanceID = InstanceID; } void SetStatus(BattleGroundStatus Status) { m_Status = Status; } void SetClientInstanceID(uint32 InstanceID) { m_ClientInstanceID = InstanceID; } void SetStartTime(uint32 Time) { m_StartTime = Time; } @@ -562,7 +564,6 @@ class BattleGround private: /* Battleground */ BattleGroundTypeId m_TypeID; - uint32 m_InstanceID; //BattleGround Instance's GUID! BattleGroundStatus m_Status; uint32 m_ClientInstanceID; //the instance-id which is sent to the client and without any other internal use uint32 m_StartTime; diff --git a/src/game/BattleGroundMgr.cpp b/src/game/BattleGroundMgr.cpp index b1cd408b3..c6adeb92a 100644 --- a/src/game/BattleGroundMgr.cpp +++ b/src/game/BattleGroundMgr.cpp @@ -1576,8 +1576,9 @@ BattleGround * BattleGroundMgr::CreateNewBattleGround(BattleGroundTypeId bgTypeI return 0; } - // generate a new instance id - bg->SetInstanceID(sMapMgr.GenerateInstanceId()); // set instance id + // will also set m_bgMap, instanceid + sMapMgr.CreateBgMap(bg->GetMapId(), bg); + bg->SetClientInstanceID(CreateClientVisibleInstanceId(bgTypeId, bracketEntry->GetBracketId())); // 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->SetTypeID(bgTypeId); - bg->SetInstanceID(0); bg->SetArenaorBGType(IsArena); bg->SetMinPlayersPerTeam(MinPlayersPerTeam); bg->SetMaxPlayersPerTeam(MaxPlayersPerTeam); diff --git a/src/game/MapInstanced.cpp b/src/game/MapInstanced.cpp index 7f0f0decd..7e59bfd36 100644 --- a/src/game/MapInstanced.cpp +++ b/src/game/MapInstanced.cpp @@ -104,11 +104,8 @@ void MapInstanced::UnloadAll(bool pForce) Map::UnloadAll(pForce); } -/* -- return the right instance for the object, based on its InstanceId -- create the instance if it's not created already -- the player is not actually added to the instance (only in InstanceMap::Add) -*/ +/// returns a new or existing Instance +/// in case of battlegrounds it will only return an existing map, those maps are created by bg-system Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player) { if(GetId() != mapId || !player) @@ -119,13 +116,11 @@ Map* MapInstanced::CreateInstance(const uint32 mapId, Player * player) if(IsBattleGroundOrArena()) { - // instantiate or find existing bg map for player - // the instance id is set in battlegroundid + // find existing bg map for player NewInstanceId = player->GetBattleGroundId(); ASSERT(NewInstanceId); map = _FindMap(NewInstanceId); - if(!map) - map = CreateBattleGroundMap(NewInstanceId, player->GetBattleGround()); + ASSERT(map); } else { diff --git a/src/game/MapInstanced.h b/src/game/MapInstanced.h index d9a8c66b7..df2bb9834 100644 --- a/src/game/MapInstanced.h +++ b/src/game/MapInstanced.h @@ -58,11 +58,11 @@ class MANGOS_DLL_DECL MapInstanced : public Map InstancedMaps &GetInstancedMaps() { return m_InstancedMaps; } virtual void InitVisibilityDistance(); + BattleGroundMap* CreateBattleGroundMap(uint32 InstanceId, BattleGround* bg); private: InstanceMap* CreateInstance(uint32 InstanceId, InstanceSave *save, Difficulty difficulty); - BattleGroundMap* CreateBattleGroundMap(uint32 InstanceId, BattleGround* bg); InstancedMaps m_InstancedMaps; diff --git a/src/game/MapManager.cpp b/src/game/MapManager.cpp index e3b37cdda..261d7a05b 100644 --- a/src/game/MapManager.cpp +++ b/src/game/MapManager.cpp @@ -138,6 +138,13 @@ Map* MapManager::CreateMap(uint32 id, const WorldObject* obj) 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 *map = _findMap(mapid); diff --git a/src/game/MapManager.h b/src/game/MapManager.h index e9046d2b5..a72e30185 100644 --- a/src/game/MapManager.h +++ b/src/game/MapManager.h @@ -27,6 +27,7 @@ #include "GridStates.h" class Transport; +class BattleGround; class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton > { @@ -38,6 +39,7 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton(this)->_createBaseMap(id); } Map* FindMap(uint32 mapid, uint32 instanceId = 0) const; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index aba8755b6..912805887 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "9596" + #define REVISION_NR "9597" #endif // __REVISION_NR_H__