Skip to content

Commit

Permalink
[10800] Use ObjectGuid in some battleground structures.
Browse files Browse the repository at this point in the history
Also fix some catches bugs in code in result.
  • Loading branch information
VladimirMangos committed Dec 1, 2010
1 parent c5935f2 commit facf6e9
Show file tree
Hide file tree
Showing 33 changed files with 146 additions and 139 deletions.
51 changes: 28 additions & 23 deletions src/game/BattleGround.cpp
Expand Up @@ -202,7 +202,7 @@ template<class Do>
void BattleGround::BroadcastWorker(Do& _do)
{
for(BattleGroundPlayerMap::const_iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
if (Player *plr = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first)))
if (Player *plr = ObjectAccessor::FindPlayer(itr->first))
_do(plr);
}

Expand Down Expand Up @@ -457,7 +457,7 @@ void BattleGround::Update(uint32 diff)
{
//TODO : add arena sound PlaySoundToAll(SOUND_ARENA_START);

for(BattleGroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr)
for(BattleGroundPlayerMap::const_iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
if (Player *plr = sObjectMgr.GetPlayer(itr->first))
plr->RemoveAurasDueToSpell(SPELL_ARENA_PREPARATION);

Expand All @@ -468,7 +468,7 @@ void BattleGround::Update(uint32 diff)

PlaySoundToAll(SOUND_BG_START);

for(BattleGroundPlayerMap::const_iterator itr = GetPlayers().begin(); itr != GetPlayers().end(); ++itr)
for(BattleGroundPlayerMap::const_iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
if (Player* plr = sObjectMgr.GetPlayer(itr->first))
plr->RemoveAurasDueToSpell(SPELL_PREPARATION);
//Announce BG starting
Expand Down Expand Up @@ -522,11 +522,11 @@ void BattleGround::SendPacketToAll(WorldPacket *packet)
{
if (itr->second.OfflineRemoveTime)
continue;
Player *plr = sObjectMgr.GetPlayer(itr->first);
if (plr)

if (Player *plr = sObjectMgr.GetPlayer(itr->first))
plr->GetSession()->SendPacket(packet);
else
sLog.outError("BattleGround:SendPacketToAll: Player (GUID: %u) not found!", GUID_LOPART(itr->first));
sLog.outError("BattleGround:SendPacketToAll: %s not found!", itr->first.GetString().c_str());
}
}

Expand All @@ -536,10 +536,11 @@ void BattleGround::SendPacketToTeam(Team teamId, WorldPacket *packet, Player *se
{
if (itr->second.OfflineRemoveTime)
continue;

Player *plr = sObjectMgr.GetPlayer(itr->first);
if (!plr)
{
sLog.outError("BattleGround:SendPacketToTeam: Player (GUID: %u) not found!", GUID_LOPART(itr->first));
sLog.outError("BattleGround:SendPacketToTeam: %s not found!", itr->first.GetString().c_str());
continue;
}

Expand Down Expand Up @@ -569,11 +570,11 @@ void BattleGround::PlaySoundToTeam(uint32 SoundID, Team teamId)
{
if (itr->second.OfflineRemoveTime)
continue;
Player *plr = sObjectMgr.GetPlayer(itr->first);

Player *plr = sObjectMgr.GetPlayer(itr->first);
if (!plr)
{
sLog.outError("BattleGround:PlaySoundToTeam: Player (GUID: %u) not found!", GUID_LOPART(itr->first));
sLog.outError("BattleGround:PlaySoundToTeam: %s not found!", itr->first.GetString().c_str());
continue;
}

Expand All @@ -594,11 +595,12 @@ void BattleGround::CastSpellOnTeam(uint32 SpellID, Team teamId)
{
if (itr->second.OfflineRemoveTime)
continue;

Player *plr = sObjectMgr.GetPlayer(itr->first);

if (!plr)
{
sLog.outError("BattleGround:CastSpellOnTeam: Player (GUID: %u) not found!", GUID_LOPART(itr->first));
sLog.outError("BattleGround:CastSpellOnTeam: %s not found!", itr->first.GetString().c_str());
continue;
}

Expand All @@ -616,11 +618,12 @@ void BattleGround::RewardHonorToTeam(uint32 Honor, Team teamId)
{
if (itr->second.OfflineRemoveTime)
continue;

Player *plr = sObjectMgr.GetPlayer(itr->first);

if (!plr)
{
sLog.outError("BattleGround:RewardHonorToTeam: Player (GUID: %u) not found!", GUID_LOPART(itr->first));
sLog.outError("BattleGround:RewardHonorToTeam: %s not found!", itr->first.GetString().c_str());
continue;
}

Expand All @@ -643,11 +646,12 @@ void BattleGround::RewardReputationToTeam(uint32 faction_id, uint32 Reputation,
{
if (itr->second.OfflineRemoveTime)
continue;

Player *plr = sObjectMgr.GetPlayer(itr->first);

if (!plr)
{
sLog.outError("BattleGround:RewardReputationToTeam: Player (GUID: %u) not found!", GUID_LOPART(itr->first));
sLog.outError("BattleGround:RewardReputationToTeam: %s not found!", itr->first.GetString().c_str());
continue;
}

Expand Down Expand Up @@ -747,10 +751,11 @@ void BattleGround::EndBattleGround(Team winner)
}
continue;
}

Player *plr = sObjectMgr.GetPlayer(itr->first);
if (!plr)
{
sLog.outError("BattleGround:EndBattleGround Player (GUID: %u) not found!", GUID_LOPART(itr->first));
sLog.outError("BattleGround:EndBattleGround %s not found!", itr->first.GetString().c_str());
continue;
}

Expand Down Expand Up @@ -993,7 +998,7 @@ void BattleGround::BlockMovement(Player *plr)
plr->SetClientControl(plr, 0); // movement disabled NOTE: the effect will be automatically removed by client when the player is teleported from the battleground, so no need to send with uint8(1) in RemovePlayerAtLeave()
}

void BattleGround::RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPacket)
void BattleGround::RemovePlayerAtLeave(ObjectGuid guid, bool Transport, bool SendPacket)
{
Team team = GetPlayerTeam(guid);
bool participant = false;
Expand Down Expand Up @@ -1183,7 +1188,7 @@ void BattleGround::AddPlayer(Player *plr)
bp.PlayerTeam = team;

// Add to list/maps
m_Players[guid.GetRawValue()] = bp;
m_Players[guid] = bp;

UpdatePlayersCountByTeam(team, false); // +1 player

Expand Down Expand Up @@ -1267,10 +1272,10 @@ void BattleGround::AddOrSetPlayerToCorrectBgGroup(Player *plr, ObjectGuid plr_gu
}

// This method should be called when player logs into running battleground
void BattleGround::EventPlayerLoggedIn(Player* player, uint64 plr_guid)
void BattleGround::EventPlayerLoggedIn(Player* player, ObjectGuid plr_guid)
{
// player is correct pointer
for(std::deque<uint64>::iterator itr = m_OfflineQueue.begin(); itr != m_OfflineQueue.end(); ++itr)
for(OfflineQueue::iterator itr = m_OfflineQueue.begin(); itr != m_OfflineQueue.end(); ++itr)
{
if (*itr == plr_guid)
{
Expand All @@ -1288,12 +1293,12 @@ void BattleGround::EventPlayerLoggedIn(Player* player, uint64 plr_guid)
void BattleGround::EventPlayerLoggedOut(Player* player)
{
// player is correct pointer, it is checked in WorldSession::LogoutPlayer()
m_OfflineQueue.push_back(player->GetGUID());
m_Players[player->GetGUID()].OfflineRemoveTime = sWorld.GetGameTime() + MAX_OFFLINE_TIME;
m_OfflineQueue.push_back(player->GetObjectGuid());
m_Players[player->GetObjectGuid()].OfflineRemoveTime = sWorld.GetGameTime() + MAX_OFFLINE_TIME;
if (GetStatus() == STATUS_IN_PROGRESS)
{
// drop flag and handle other cleanups
RemovePlayer(player, player->GetGUID());
RemovePlayer(player, player->GetObjectGuid());

// 1 player is logging out, if it is the last, then end arena!
if (isArena())
Expand Down Expand Up @@ -1347,7 +1352,7 @@ bool BattleGround::HasFreeSlots() const
void BattleGround::UpdatePlayerScore(Player *Source, uint32 type, uint32 value)
{
//this procedure is called from virtual function implemented in bg subclass
BattleGroundScoreMap::const_iterator itr = m_PlayerScores.find(Source->GetGUID());
BattleGroundScoreMap::const_iterator itr = m_PlayerScores.find(Source->GetObjectGuid());

if(itr == m_PlayerScores.end()) // player not found...
return;
Expand Down Expand Up @@ -1751,15 +1756,15 @@ void BattleGround::HandleKillPlayer( Player *player, Player *killer )

// return the player's team based on battlegroundplayer info
// used in same faction arena matches mainly
Team BattleGround::GetPlayerTeam(uint64 guid)
Team BattleGround::GetPlayerTeam(ObjectGuid guid)
{
BattleGroundPlayerMap::const_iterator itr = m_Players.find(guid);
if (itr != m_Players.end())
return itr->second.PlayerTeam;
return TEAM_NONE;
}

bool BattleGround::IsPlayerInBattleGround(uint64 guid)
bool BattleGround::IsPlayerInBattleGround(ObjectGuid guid)
{
BattleGroundPlayerMap::const_iterator itr = m_Players.find(guid);
if (itr != m_Players.end())
Expand Down
18 changes: 9 additions & 9 deletions src/game/BattleGround.h
Expand Up @@ -375,11 +375,11 @@ class BattleGround
bool isBattleGround() const { return !m_IsArena; }
bool isRated() const { return m_IsRated; }

typedef std::map<uint64, BattleGroundPlayer> BattleGroundPlayerMap;
typedef std::map<ObjectGuid, BattleGroundPlayer> BattleGroundPlayerMap;
BattleGroundPlayerMap const& GetPlayers() const { return m_Players; }
uint32 GetPlayersSize() const { return m_Players.size(); }

typedef std::map<uint64, BattleGroundScore*> BattleGroundScoreMap;
typedef std::map<ObjectGuid, BattleGroundScore*> BattleGroundScoreMap;
BattleGroundScoreMap::const_iterator GetPlayerScoresBegin() const { return m_PlayerScores.begin(); }
BattleGroundScoreMap::const_iterator GetPlayerScoresEnd() const { return m_PlayerScores.end(); }
uint32 GetPlayerScoresSize() const { return m_PlayerScores.size(); }
Expand Down Expand Up @@ -475,7 +475,7 @@ class BattleGround
virtual void EventPlayerDroppedFlag(Player* /*player*/) {}
virtual void EventPlayerClickedOnFlag(Player* /*player*/, GameObject* /*target_obj*/) {}
virtual void EventPlayerCapturedFlag(Player* /*player*/) {}
void EventPlayerLoggedIn(Player* player, uint64 plr_guid);
void EventPlayerLoggedIn(Player* player, ObjectGuid plr_guid);
void EventPlayerLoggedOut(Player* player);

/* Death related */
Expand All @@ -485,7 +485,7 @@ class BattleGround

void AddOrSetPlayerToCorrectBgGroup(Player *plr, ObjectGuid plr_guid, Team team);

virtual void RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPacket);
virtual void RemovePlayerAtLeave(ObjectGuid guid, bool Transport, bool SendPacket);
// can be extended in in BG subclass

/* event related */
Expand Down Expand Up @@ -524,10 +524,10 @@ class BattleGround
virtual bool HandlePlayerUnderMap(Player * /*plr*/) { return false; }

// since arenas can be AvA or Hvh, we have to get the "temporary" team of a player
Team GetPlayerTeam(uint64 guid);
Team GetPlayerTeam(ObjectGuid guid);
static Team GetOtherTeam(Team team){ return team ? ((team == ALLIANCE) ? HORDE : ALLIANCE) : TEAM_NONE; }
static BattleGroundTeamIndex GetOtherTeamIndex(BattleGroundTeamIndex teamIdx){ return teamIdx == BG_TEAM_ALLIANCE ? BG_TEAM_HORDE : BG_TEAM_ALLIANCE; }
bool IsPlayerInBattleGround(uint64 guid);
bool IsPlayerInBattleGround(ObjectGuid guid);

/* virtual score-array - get's used in bg-subclasses */
int32 m_TeamScores[BG_TEAMS_COUNT];
Expand Down Expand Up @@ -557,7 +557,7 @@ class BattleGround

BattleGroundScoreMap m_PlayerScores; // Player scores
// must be implemented in BG subclass
virtual void RemovePlayer(Player * /*player*/, uint64 /*guid*/) {}
virtual void RemovePlayer(Player * /*player*/, ObjectGuid /*guid*/) {}

/* Player lists, those need to be accessible by inherited classes */
BattleGroundPlayerMap m_Players;
Expand Down Expand Up @@ -592,8 +592,8 @@ class BattleGround
char const *m_Name;

/* Player lists */
std::vector<uint64> m_ResurrectQueue; // Player GUID
std::deque<uint64> m_OfflineQueue; // Player GUID
typedef std::deque<ObjectGuid> OfflineQueue;
OfflineQueue m_OfflineQueue; // Player GUID

/* Invited counters are useful for player invitation to BG - do not allow, if BG is started to one faction to have 2 more players than another faction */
/* Invited counters will be changed only when removing already invited player from queue, removing player from battleground and inviting player to BG */
Expand Down
4 changes: 2 additions & 2 deletions src/game/BattleGroundAA.cpp
Expand Up @@ -59,10 +59,10 @@ void BattleGroundAA::AddPlayer(Player *plr)
//create score and add it to map, default values are set in constructor
BattleGroundAAScore* sc = new BattleGroundAAScore;

m_PlayerScores[plr->GetGUID()] = sc;
m_PlayerScores[plr->GetObjectGuid()] = sc;
}

void BattleGroundAA::RemovePlayer(Player * /*plr*/, uint64 /*guid*/)
void BattleGroundAA::RemovePlayer(Player * /*plr*/, ObjectGuid /*guid*/)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/BattleGroundAA.h
Expand Up @@ -42,7 +42,7 @@ class BattleGroundAA : public BattleGround
virtual void StartingEventCloseDoors();
virtual void StartingEventOpenDoors();

void RemovePlayer(Player *plr, uint64 guid);
void RemovePlayer(Player *plr, ObjectGuid guid);
void HandleAreaTrigger(Player *Source, uint32 Trigger);
bool SetupBattleGround();
void HandleKillPlayer(Player* player, Player *killer);
Expand Down
6 changes: 3 additions & 3 deletions src/game/BattleGroundAB.cpp
Expand Up @@ -182,10 +182,10 @@ void BattleGroundAB::AddPlayer(Player *plr)
//create score and add it to map, default values are set in the constructor
BattleGroundABScore* sc = new BattleGroundABScore;

m_PlayerScores[plr->GetGUID()] = sc;
m_PlayerScores[plr->GetObjectGuid()] = sc;
}

void BattleGroundAB::RemovePlayer(Player * /*plr*/, uint64 /*guid*/)
void BattleGroundAB::RemovePlayer(Player * /*plr*/, ObjectGuid /*guid*/)
{

}
Expand Down Expand Up @@ -539,7 +539,7 @@ WorldSafeLocsEntry const* BattleGroundAB::GetClosestGraveYard(Player* player)

void BattleGroundAB::UpdatePlayerScore(Player *Source, uint32 type, uint32 value)
{
BattleGroundScoreMap::iterator itr = m_PlayerScores.find(Source->GetGUID());
BattleGroundScoreMap::iterator itr = m_PlayerScores.find(Source->GetObjectGuid());
if( itr == m_PlayerScores.end() ) // player not found...
return;

Expand Down
2 changes: 1 addition & 1 deletion src/game/BattleGroundAB.h
Expand Up @@ -184,7 +184,7 @@ class BattleGroundAB : public BattleGround
void AddPlayer(Player *plr);
virtual void StartingEventCloseDoors();
virtual void StartingEventOpenDoors();
void RemovePlayer(Player *plr,uint64 guid);
void RemovePlayer(Player *plr, ObjectGuid guid);
void HandleAreaTrigger(Player *Source, uint32 Trigger);
virtual bool SetupBattleGround();
virtual void Reset();
Expand Down
6 changes: 3 additions & 3 deletions src/game/BattleGroundAV.cpp
Expand Up @@ -289,7 +289,7 @@ void BattleGroundAV::AddPlayer(Player *plr)
BattleGround::AddPlayer(plr);
// create score and add it to map, default values are set in constructor
BattleGroundAVScore* sc = new BattleGroundAVScore;
m_PlayerScores[plr->GetGUID()] = sc;
m_PlayerScores[plr->GetObjectGuid()] = sc;
}

void BattleGroundAV::EndBattleGround(Team winner)
Expand Down Expand Up @@ -349,7 +349,7 @@ void BattleGroundAV::EndBattleGround(Team winner)
BattleGround::EndBattleGround(winner);
}

void BattleGroundAV::RemovePlayer(Player* /*plr*/,uint64 /*guid*/)
void BattleGroundAV::RemovePlayer(Player* /*plr*/, ObjectGuid /*guid*/)
{
}

Expand Down Expand Up @@ -389,7 +389,7 @@ void BattleGroundAV::HandleAreaTrigger(Player *Source, uint32 Trigger)
void BattleGroundAV::UpdatePlayerScore(Player* Source, uint32 type, uint32 value)
{

BattleGroundScoreMap::iterator itr = m_PlayerScores.find(Source->GetGUID());
BattleGroundScoreMap::iterator itr = m_PlayerScores.find(Source->GetObjectGuid());
if(itr == m_PlayerScores.end()) // player not found...
return;

Expand Down
2 changes: 1 addition & 1 deletion src/game/BattleGroundAV.h
Expand Up @@ -326,7 +326,7 @@ class BattleGroundAV : public BattleGround
// world states
virtual void FillInitialWorldStates(WorldPacket& data, uint32& count);

void RemovePlayer(Player *plr,uint64 guid);
void RemovePlayer(Player *plr, ObjectGuid guid);
void HandleAreaTrigger(Player *Source, uint32 Trigger);
virtual void Reset();

Expand Down
8 changes: 4 additions & 4 deletions src/game/BattleGroundBE.cpp
Expand Up @@ -67,13 +67,13 @@ void BattleGroundBE::AddPlayer(Player *plr)
//create score and add it to map, default values are set in constructor
BattleGroundBEScore* sc = new BattleGroundBEScore;

m_PlayerScores[plr->GetGUID()] = sc;
m_PlayerScores[plr->GetObjectGuid()] = sc;

UpdateWorldState(0x9f1, GetAlivePlayersCountByTeam(ALLIANCE));
UpdateWorldState(0x9f0, GetAlivePlayersCountByTeam(HORDE));
}

void BattleGroundBE::RemovePlayer(Player* /*plr*/, uint64 /*guid*/)
void BattleGroundBE::RemovePlayer(Player* /*plr*/, ObjectGuid /*guid*/)
{
if (GetStatus() == STATUS_WAIT_LEAVE)
return;
Expand Down Expand Up @@ -156,12 +156,12 @@ bool BattleGroundBE::SetupBattleGround()
void BattleGroundBE::UpdatePlayerScore(Player* Source, uint32 type, uint32 value)
{

BattleGroundScoreMap::iterator itr = m_PlayerScores.find(Source->GetGUID());
BattleGroundScoreMap::iterator itr = m_PlayerScores.find(Source->GetObjectGuid());
if(itr == m_PlayerScores.end()) // player not found...
return;

//there is nothing special in this score
BattleGround::UpdatePlayerScore(Source,type,value);
BattleGround::UpdatePlayerScore(Source, type, value);

}

Expand Down
2 changes: 1 addition & 1 deletion src/game/BattleGroundBE.h
Expand Up @@ -41,7 +41,7 @@ class BattleGroundBE : public BattleGround
virtual void StartingEventCloseDoors();
virtual void StartingEventOpenDoors();

void RemovePlayer(Player *plr, uint64 guid);
void RemovePlayer(Player *plr, ObjectGuid guid);
void HandleAreaTrigger(Player *Source, uint32 Trigger);
bool SetupBattleGround();
virtual void Reset();
Expand Down

0 comments on commit facf6e9

Please sign in to comment.