From 968a2363ebbc43acece00be24d8ab55920824668 Mon Sep 17 00:00:00 2001 From: Andrew <47818697+Nyeriah@users.noreply.github.com> Date: Fri, 13 Mar 2026 19:32:06 -0300 Subject: [PATCH] refactor(Core/Battlefield): remove Hungarian notation and modernize code (#25070) Co-authored-by: Claude Sonnet 4.6 --- src/server/game/Battlefield/Battlefield.cpp | 649 ++++++++---------- src/server/game/Battlefield/Battlefield.h | 277 ++++---- .../game/Battlefield/BattlefieldHandler.cpp | 128 ++-- .../game/Battlefield/BattlefieldMgr.cpp | 91 +-- src/server/game/Battlefield/BattlefieldMgr.h | 27 +- .../game/Battlefield/Zones/BattlefieldWG.cpp | 369 +++++----- .../game/Battlefield/Zones/BattlefieldWG.h | 68 +- 7 files changed, 765 insertions(+), 844 deletions(-) diff --git a/src/server/game/Battlefield/Battlefield.cpp b/src/server/game/Battlefield/Battlefield.cpp index 63f72c3aa..b9d9d43e8 100644 --- a/src/server/game/Battlefield/Battlefield.cpp +++ b/src/server/game/Battlefield/Battlefield.cpp @@ -40,46 +40,42 @@ // see: https://github.com/azerothcore/azerothcore-wotlk/issues/9766 #include "GridNotifiersImpl.h" -Battlefield::Battlefield() +Battlefield::Battlefield() : + Timer(0), + Enabled(true), + Active(false), + DefenderTeam(TEAM_NEUTRAL), + TypeId(0), + BattleId(0), + ZoneId(0), + MapId(0), + BfMap(nullptr), + MaxPlayer(0), + MinPlayer(0), + MinLevel(0), + BattleTime(0), + NoWarBattleTime(0), + RestartAfterCrash(0), + TimeForAcceptInvite(20), + KickDontAcceptTimer(1000), + KickAfkPlayersTimer(1000), + LastResurrectTimer(RESURRECTION_INTERVAL), + StartGroupingTimer(0), + StartGrouping(false) { - m_Timer = 0; - m_IsEnabled = true; - m_isActive = false; - m_DefenderTeam = TEAM_NEUTRAL; - - m_TypeId = 0; - m_BattleId = 0; - m_ZoneId = 0; - m_Map = nullptr; - m_MapId = 0; - m_MaxPlayer = 0; - m_MinPlayer = 0; - m_MinLevel = 0; - m_BattleTime = 0; - m_NoWarBattleTime = 0; - m_RestartAfterCrash = 0; - m_TimeForAcceptInvite = 20; - m_uiKickDontAcceptTimer = 1000; - - m_uiKickAfkPlayersTimer = 1000; - - m_LastResurectTimer = RESURRECTION_INTERVAL; - m_StartGroupingTimer = 0; - m_StartGrouping = false; } Battlefield::~Battlefield() { - for (BfCapturePointVector::iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr) - delete *itr; + for (BfCapturePoint* cp : CapturePoints) + delete cp; - for (GraveyardVect::const_iterator itr = m_GraveyardList.begin(); itr != m_GraveyardList.end(); ++itr) - delete *itr; + for (BfGraveyard* gy : GraveyardList) + delete gy; - m_capturePoints.clear(); + CapturePoints.clear(); } -// Called when a player enters the zone void Battlefield::HandlePlayerEnterZone(Player* player, uint32 /*zone*/) { // Allow scripts to adjust the player's effective team or appearance before @@ -91,41 +87,38 @@ void Battlefield::HandlePlayerEnterZone(Player* player, uint32 /*zone*/) { // If battle is started, // If not full of players > invite player to join the war - // If full of players > announce to player that BF is full and kick him after a few second if he desn't leave + // If full of players > announce to player that BF is full and kick him after a few second if he doesn't leave if (IsWarTime()) { - if (m_PlayersInWar[player->GetTeamId()].size() + m_InvitedPlayers[player->GetTeamId()].size() < m_MaxPlayer) // Vacant spaces + if (HasWarVacancy(player->GetTeamId())) InvitePlayerToWar(player); - else // No more vacant places + else { /// @todo: Send a packet to announce it to player - m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + (player->IsGameMaster() ? 30 * MINUTE : 10); + PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + (player->IsGameMaster() ? 30 * MINUTE : 10); InvitePlayerToQueue(player); } } else { // If time left is < 15 minutes invite player to join queue - if (m_Timer <= m_StartGroupingTimer) + if (Timer <= StartGroupingTimer) InvitePlayerToQueue(player); } } - // Add player in the list of player in zone - m_players[player->GetTeamId()].insert(player->GetGUID()); + Players[player->GetTeamId()].insert(player->GetGUID()); OnPlayerEnterZone(player); } -// Called when a player leave the zone void Battlefield::HandlePlayerLeaveZone(Player* player, uint32 /*zone*/) { if (IsWarTime()) { // If the player is participating to the battle - if (m_PlayersInWar[player->GetTeamId()].find(player->GetGUID()) != m_PlayersInWar[player->GetTeamId()].end()) + if (PlayersInWar[player->GetTeamId()].erase(player->GetGUID())) { - m_PlayersInWar[player->GetTeamId()].erase(player->GetGUID()); - player->GetSession()->SendBfLeaveMessage(m_BattleId); + player->GetSession()->SendBfLeaveMessage(BattleId); if (Group* group = player->GetGroup()) // Remove the player from the raid group if (group->isBFGroup()) group->RemoveMember(player->GetGUID()); @@ -135,12 +128,12 @@ void Battlefield::HandlePlayerLeaveZone(Player* player, uint32 /*zone*/) } } - for (BfCapturePointVector::iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr) - (*itr)->HandlePlayerLeave(player); + for (BfCapturePoint* cp : CapturePoints) + cp->HandlePlayerLeave(player); - m_InvitedPlayers[player->GetTeamId()].erase(player->GetGUID()); - m_PlayersWillBeKick[player->GetTeamId()].erase(player->GetGUID()); - m_players[player->GetTeamId()].erase(player->GetGUID()); + InvitedPlayers[player->GetTeamId()].erase(player->GetGUID()); + PlayersWillBeKick[player->GetTeamId()].erase(player->GetGUID()); + Players[player->GetTeamId()].erase(player->GetGUID()); SendRemoveWorldStates(player); RemovePlayerFromResurrectQueue(player->GetGUID()); OnPlayerLeaveZone(player); @@ -152,11 +145,11 @@ void Battlefield::HandlePlayerLeaveZone(Player* player, uint32 /*zone*/) bool Battlefield::Update(uint32 diff) { - if (m_Timer <= diff) + if (Timer <= diff) { - if (!IsEnabled() || (!IsWarTime() && sWorldSessionMgr->GetActiveSessionCount() > 3500)) // if WG is disabled or there is more than 3500 connections, switch automaticly + if (!IsEnabled() || (!IsWarTime() && sWorldSessionMgr->GetActiveSessionCount() > 3500)) // if WG is disabled or there is more than 3500 connections, switch automatically { - m_isActive = true; + Active = true; EndBattle(false); return false; } @@ -167,122 +160,108 @@ bool Battlefield::Update(uint32 diff) StartBattle(); } else - m_Timer -= diff; + Timer -= diff; if (!IsEnabled()) return false; // Invite players a few minutes before the battle's beginning - if (!IsWarTime() && !m_StartGrouping && m_Timer <= m_StartGroupingTimer) + if (!IsWarTime() && !StartGrouping && Timer <= StartGroupingTimer) { - m_StartGrouping = true; + StartGrouping = true; InvitePlayersInZoneToQueue(); OnStartGrouping(); SendUpdateWorldStates(); } - bool objective_changed = false; + bool objectiveChanged = false; if (IsWarTime()) { - if (m_uiKickAfkPlayersTimer <= diff) + if (KickAfkPlayersTimer <= diff) { - m_uiKickAfkPlayersTimer = 20000; + KickAfkPlayersTimer = 20000; KickAfkPlayers(); } else - m_uiKickAfkPlayersTimer -= diff; + KickAfkPlayersTimer -= diff; // Kick players who chose not to accept invitation to the battle - if (m_uiKickDontAcceptTimer <= diff) + if (KickDontAcceptTimer <= diff) { time_t now = GameTime::GetGameTime().count(); - for (int team = 0; team < 2; team++) - for (PlayerTimerMap::iterator itr = m_InvitedPlayers[team].begin(); itr != m_InvitedPlayers[team].end(); ++itr) - if (itr->second <= now) - KickPlayerFromBattlefield(itr->first); + for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team) + for (PlayerTimerMap::value_type const& pair : InvitedPlayers[team]) + if (pair.second <= now) + KickPlayerFromBattlefield(pair.first); InvitePlayersInZoneToWar(); - for (int team = 0; team < 2; team++) - for (PlayerTimerMap::iterator itr = m_PlayersWillBeKick[team].begin(); itr != m_PlayersWillBeKick[team].end(); ++itr) - if (itr->second <= now) - KickPlayerFromBattlefield(itr->first); + for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team) + for (PlayerTimerMap::value_type const& pair : PlayersWillBeKick[team]) + if (pair.second <= now) + KickPlayerFromBattlefield(pair.first); - m_uiKickDontAcceptTimer = 5000; + KickDontAcceptTimer = 5000; } else - m_uiKickDontAcceptTimer -= diff; + KickDontAcceptTimer -= diff; - for (BfCapturePointVector::iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr) - if ((*itr)->Update(diff)) - objective_changed = true; + for (BfCapturePoint* cp : CapturePoints) + if (cp->Update(diff)) + objectiveChanged = true; } - if (m_LastResurectTimer <= diff) + if (LastResurrectTimer <= diff) { - for (uint8 i = 0; i < m_GraveyardList.size(); i++) - if (GetGraveyardById(i)) - m_GraveyardList[i]->Resurrect(); - m_LastResurectTimer = RESURRECTION_INTERVAL; + for (BfGraveyard* gy : GraveyardList) + if (gy) + gy->Resurrect(); + LastResurrectTimer = RESURRECTION_INTERVAL; } else - m_LastResurectTimer -= diff; + LastResurrectTimer -= diff; - return objective_changed; + return objectiveChanged; } void Battlefield::InvitePlayersInZoneToQueue() { - for (uint8 team = 0; team < 2; ++team) - for (GuidUnorderedSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) - InvitePlayerToQueue(player); + ForEachPlayerInZone([this](Player* player) { InvitePlayerToQueue(player); }); } void Battlefield::InvitePlayerToQueue(Player* player) { - if (m_PlayersInQueue[player->GetTeamId()].count(player->GetGUID())) + if (PlayersInQueue[player->GetTeamId()].count(player->GetGUID())) return; - if (m_PlayersInQueue[player->GetTeamId()].size() <= m_MinPlayer || m_PlayersInQueue[GetOtherTeam(player->GetTeamId())].size() >= m_MinPlayer) - player->GetSession()->SendBfInvitePlayerToQueue(m_BattleId); + if (PlayersInQueue[player->GetTeamId()].size() <= MinPlayer || PlayersInQueue[GetOtherTeam(player->GetTeamId())].size() >= MinPlayer) + player->GetSession()->SendBfInvitePlayerToQueue(BattleId); } void Battlefield::InvitePlayersInQueueToWar() { for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team) { - GuidUnorderedSet copy(m_PlayersInQueue[team]); - for (GuidUnorderedSet::const_iterator itr = copy.begin(); itr != copy.end(); ++itr) - { - if (Player* player = ObjectAccessor::FindPlayer(*itr)) - { - if (m_PlayersInWar[player->GetTeamId()].size() + m_InvitedPlayers[player->GetTeamId()].size() < m_MaxPlayer) + GuidUnorderedSet copy(PlayersInQueue[team]); + for (ObjectGuid const& guid : copy) + if (Player* player = ObjectAccessor::FindPlayer(guid)) + if (HasWarVacancy(player->GetTeamId())) InvitePlayerToWar(player); - else - { - //Full - } - } - } - m_PlayersInQueue[team].clear(); + PlayersInQueue[team].clear(); } } void Battlefield::InvitePlayersInZoneToWar() { - for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team) - for (GuidUnorderedSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr) - { - if (Player* player = ObjectAccessor::FindPlayer(*itr)) - { - if (m_PlayersInWar[player->GetTeamId()].count(player->GetGUID()) || m_InvitedPlayers[player->GetTeamId()].count(player->GetGUID())) - continue; - if (m_PlayersInWar[player->GetTeamId()].size() + m_InvitedPlayers[player->GetTeamId()].size() < m_MaxPlayer) - InvitePlayerToWar(player); - else if (m_PlayersWillBeKick[player->GetTeamId()].count(player->GetGUID()) == 0)// Battlefield is full of players - m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + 10; - } - } + ForEachPlayerInZone([this](Player* player) + { + if (IsPlayerInWarOrInvited(player)) + return; + + if (HasWarVacancy(player->GetTeamId())) + InvitePlayerToWar(player); + else if (!PlayersWillBeKick[player->GetTeamId()].count(player->GetGUID())) // Battlefield is full of players + PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + 10; + }); } void Battlefield::InvitePlayerToWar(Player* player) @@ -296,27 +275,27 @@ void Battlefield::InvitePlayerToWar(Player* player) if (player->InBattleground()) { - m_PlayersInQueue[player->GetTeamId()].erase(player->GetGUID()); + PlayersInQueue[player->GetTeamId()].erase(player->GetGUID()); return; } // If the player does not match minimal level requirements for the battlefield, kick him - if (player->GetLevel() < m_MinLevel) + if (player->GetLevel() < MinLevel) { - if (m_PlayersWillBeKick[player->GetTeamId()].count(player->GetGUID()) == 0) - m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + 10; + if (!PlayersWillBeKick[player->GetTeamId()].count(player->GetGUID())) + PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + 10; return; } // Check if player is not already in war - if (m_PlayersInWar[player->GetTeamId()].count(player->GetGUID()) || m_InvitedPlayers[player->GetTeamId()].count(player->GetGUID())) + if (IsPlayerInWarOrInvited(player)) return; sScriptMgr->OnBattlefieldBeforeInvitePlayerToWar(this, player); - m_PlayersWillBeKick[player->GetTeamId()].erase(player->GetGUID()); - m_InvitedPlayers[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + m_TimeForAcceptInvite; - player->GetSession()->SendBfInvitePlayerToWar(m_BattleId, m_ZoneId, m_TimeForAcceptInvite); + PlayersWillBeKick[player->GetTeamId()].erase(player->GetGUID()); + InvitedPlayers[player->GetTeamId()][player->GetGUID()] = GameTime::GetGameTime().count() + TimeForAcceptInvite; + player->GetSession()->SendBfInvitePlayerToWar(BattleId, ZoneId, TimeForAcceptInvite); } void Battlefield::InitStalker(uint32 entry, float x, float y, float z, float o) @@ -324,41 +303,44 @@ void Battlefield::InitStalker(uint32 entry, float x, float y, float z, float o) if (Creature* creature = SpawnCreature(entry, x, y, z, o, TEAM_NEUTRAL)) StalkerGuid = creature->GetGUID(); else - LOG_ERROR("bg.battlefield", "Battlefield::InitStalker: could not spawn Stalker (Creature entry {}), zone messeges will be un-available", entry); + LOG_ERROR("bg.battlefield", "Battlefield::InitStalker: could not spawn Stalker (Creature entry {}), zone messages will be unavailable", entry); +} + +bool Battlefield::IsPlayerInWarOrInvited(Player* player) const +{ + TeamId teamId = player->GetTeamId(); + return PlayersInWar[teamId].count(player->GetGUID()) || InvitedPlayers[teamId].count(player->GetGUID()); } void Battlefield::KickAfkPlayers() { - // xinef: optimization, dont lookup player twice - for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team) - for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) - if (player->isAFK() && player->GetZoneId() == GetZoneId() && !player->IsGameMaster()) - player->TeleportTo(KickPosition); + ForEachPlayerInWar([this](Player* player) + { + if (player->isAFK() && player->GetZoneId() == GetZoneId() && !player->IsGameMaster()) + player->TeleportTo(KickPosition); + }); } void Battlefield::KickPlayerFromBattlefield(ObjectGuid guid) { if (Player* player = ObjectAccessor::FindPlayer(guid)) - { if (player->GetZoneId() == GetZoneId() && !player->IsGameMaster()) player->TeleportTo(KickPosition); - } } void Battlefield::StartBattle() { - if (m_isActive) + if (Active) return; - for (int team = 0; team < PVP_TEAMS_COUNT; team++) + for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team) { - m_PlayersInWar[team].clear(); - m_Groups[team].clear(); + PlayersInWar[team].clear(); + Groups[team].clear(); } - m_Timer = m_BattleTime; - m_isActive = true; + Timer = BattleTime; + Active = true; InvitePlayersInZoneToWar(); InvitePlayersInQueueToWar(); @@ -372,12 +354,12 @@ void Battlefield::StartBattle() void Battlefield::EndBattle(bool endByTimer) { - if (!m_isActive) + if (!Active) return; - m_isActive = false; + Active = false; - m_StartGrouping = false; + StartGrouping = false; if (!endByTimer) SetDefenderTeam(GetAttackerTeam()); @@ -390,43 +372,43 @@ void Battlefield::EndBattle(bool endByTimer) OnBattleEnd(endByTimer); // Reset battlefield timer - m_Timer = m_NoWarBattleTime; + Timer = NoWarBattleTime; SendInitWorldStatesToAll(); SendUpdateWorldStates(); } -void Battlefield::DoPlaySoundToAll(uint32 SoundID) +void Battlefield::DoPlaySoundToAll(uint32 soundId) { - BroadcastPacketToWar(WorldPackets::Misc::Playsound(SoundID).Write()); + BroadcastPacketToWar(WorldPackets::Misc::Playsound(soundId).Write()); } bool Battlefield::HasPlayer(Player* player) const { - return m_players[player->GetTeamId()].find(player->GetGUID()) != m_players[player->GetTeamId()].end(); + return Players[player->GetTeamId()].find(player->GetGUID()) != Players[player->GetTeamId()].end(); } // Called in WorldSession::HandleBfQueueInviteResponse void Battlefield::PlayerAcceptInviteToQueue(Player* player) { // Add player in queue - m_PlayersInQueue[player->GetTeamId()].insert(player->GetGUID()); + PlayersInQueue[player->GetTeamId()].insert(player->GetGUID()); // Send notification - player->GetSession()->SendBfQueueInviteResponse(m_BattleId, m_ZoneId); + player->GetSession()->SendBfQueueInviteResponse(BattleId, ZoneId); } // Called in WorldSession::HandleBfExitRequest void Battlefield::AskToLeaveQueue(Player* player) { // Remove player from queue - m_PlayersInQueue[player->GetTeamId()].erase(player->GetGUID()); + PlayersInQueue[player->GetTeamId()].erase(player->GetGUID()); // Send notification - player->GetSession()->SendBfLeaveMessage(m_BattleId, BF_LEAVE_REASON_CLOSE); + player->GetSession()->SendBfLeaveMessage(BattleId, BF_LEAVE_REASON_CLOSE); } // Called in WorldSession::HandleHearthAndResurrect void Battlefield::PlayerAskToLeave(Player* player) { - // Player leaving Wintergrasp, teleport to homebind possition. + // Player leaving Wintergrasp, teleport to homebind position. player->TeleportTo(player->m_homebindMapId, player->m_homebindX, player->m_homebindY, player->m_homebindZ, player->GetOrientation()); } @@ -440,55 +422,41 @@ void Battlefield::PlayerAcceptInviteToWar(Player* player) if (AddOrSetPlayerToCorrectBfGroup(player)) { - player->GetSession()->SendBfEntered(m_BattleId); - m_PlayersInWar[player->GetTeamId()].insert(player->GetGUID()); - m_InvitedPlayers[player->GetTeamId(true)].erase(player->GetGUID()); + player->GetSession()->SendBfEntered(BattleId); + PlayersInWar[player->GetTeamId()].insert(player->GetGUID()); + InvitedPlayers[player->GetTeamId(true)].erase(player->GetGUID()); if (player->isAFK()) player->ToggleAFK(); - OnPlayerJoinWar(player); //for scripting + OnPlayerJoinWar(player); } } void Battlefield::TeamCastSpell(TeamId team, int32 spellId) { - if (spellId > 0) + ForEachPlayerInWar(team, [spellId](Player* player) { - for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) - player->CastSpell(player, uint32(spellId), true); - } - else - { - for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) - player->RemoveAuraFromStack(uint32(-spellId)); - } + if (spellId > 0) + player->CastSpell(player, uint32(spellId), true); + else + player->RemoveAuraFromStack(uint32(-spellId)); + }); } void Battlefield::BroadcastPacketToZone(WorldPacket const* data) const { - for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team) - for (GuidUnorderedSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) - player->SendDirectMessage(data); + ForEachPlayerInZone([data](Player* player) { player->SendDirectMessage(data); }); } void Battlefield::BroadcastPacketToQueue(WorldPacket const* data) const { - for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team) - for (GuidUnorderedSet::const_iterator itr = m_PlayersInQueue[team].begin(); itr != m_PlayersInQueue[team].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) - player->SendDirectMessage(data); + ForEachPlayerInQueue([data](Player* player) { player->SendDirectMessage(data); }); } void Battlefield::BroadcastPacketToWar(WorldPacket const* data) const { - for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team) - for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) - player->SendDirectMessage(data); + ForEachPlayerInWar([data](Player* player) { player->SendDirectMessage(data); }); } void Battlefield::SendWarning(uint8 id, WorldObject const* target /*= nullptr*/) @@ -499,10 +467,7 @@ void Battlefield::SendWarning(uint8 id, WorldObject const* target /*= nullptr*/) void Battlefield::SendUpdateWorldState(uint32 field, uint32 value) { - for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i) - for (GuidUnorderedSet::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) - player->SendUpdateWorldState(field, value); + ForEachPlayerInZone([field, value](Player* player) { player->SendUpdateWorldState(field, value); }); } void Battlefield::RegisterZone(uint32 zoneId) @@ -536,23 +501,20 @@ void Battlefield::ShowNpc(Creature* creature, bool aggressive) } } -// **************************************************** -// ******************* Group System ******************* -// **************************************************** -Group* Battlefield::GetFreeBfRaid(TeamId TeamId) +Group* Battlefield::GetFreeBfRaid(TeamId teamId) { - for (GuidUnorderedSet::const_iterator itr = m_Groups[TeamId].begin(); itr != m_Groups[TeamId].end(); ++itr) - if (Group* group = sGroupMgr->GetGroupByGUID(itr->GetCounter())) + for (ObjectGuid const& guid : Groups[teamId]) + if (Group* group = sGroupMgr->GetGroupByGUID(guid.GetCounter())) if (!group->IsFull()) return group; return nullptr; } -Group* Battlefield::GetGroupPlayer(ObjectGuid guid, TeamId TeamId) +Group* Battlefield::GetGroupPlayer(ObjectGuid guid, TeamId teamId) { - for (GuidUnorderedSet::const_iterator itr = m_Groups[TeamId].begin(); itr != m_Groups[TeamId].end(); ++itr) - if (Group* group = sGroupMgr->GetGroupByGUID(itr->GetCounter())) + for (ObjectGuid const& groupGuid : Groups[teamId]) + if (Group* group = sGroupMgr->GetGroupByGUID(groupGuid.GetCounter())) if (group->IsMember(guid)) return group; @@ -577,7 +539,7 @@ bool Battlefield::AddOrSetPlayerToCorrectBfGroup(Player* player) group->SetBattlefieldGroup(this); group->Create(player); sGroupMgr->AddGroup(group); - m_Groups[player->GetTeamId()].insert(group->GetGUID()); + Groups[player->GetTeamId()].insert(group->GetGUID()); } else if (group->IsMember(player->GetGUID())) { @@ -590,21 +552,12 @@ bool Battlefield::AddOrSetPlayerToCorrectBfGroup(Player* player) return true; } -//***************End of Group System******************* - -//***************************************************** -//***************Spirit Guide System******************* -//***************************************************** - -//-------------------- -//-Battlefield Method- -//-------------------- BfGraveyard* Battlefield::GetGraveyardById(uint32 id) const { - if (id < m_GraveyardList.size()) + if (id < GraveyardList.size()) { - if (m_GraveyardList[id]) - return m_GraveyardList[id]; + if (GraveyardList[id]) + return GraveyardList[id]; else LOG_ERROR("bg.battlefield", "Battlefield::GetGraveyardById Id:{} not existed", id); } @@ -618,19 +571,19 @@ GraveyardStruct const* Battlefield::GetClosestGraveyard(Player* player) { BfGraveyard* closestGY = nullptr; float maxdist = -1; - for (uint8 i = 0; i < m_GraveyardList.size(); i++) + for (BfGraveyard* gy : GraveyardList) { - if (m_GraveyardList[i]) - { - if (m_GraveyardList[i]->GetControlTeamId() != player->GetTeamId()) - continue; + if (!gy) + continue; - float dist = m_GraveyardList[i]->GetDistance(player); - if (dist < maxdist || maxdist < 0) - { - closestGY = m_GraveyardList[i]; - maxdist = dist; - } + if (gy->GetControlTeamId() != player->GetTeamId()) + continue; + + float dist = gy->GetDistance(player); + if (dist < maxdist || maxdist < 0) + { + closestGY = gy; + maxdist = dist; } } @@ -642,14 +595,14 @@ GraveyardStruct const* Battlefield::GetClosestGraveyard(Player* player) void Battlefield::AddPlayerToResurrectQueue(ObjectGuid npcGuid, ObjectGuid playerGuid) { - for (uint8 i = 0; i < m_GraveyardList.size(); i++) + for (BfGraveyard* gy : GraveyardList) { - if (!m_GraveyardList[i]) + if (!gy) continue; - if (m_GraveyardList[i]->HasNpc(npcGuid)) + if (gy->HasNpc(npcGuid)) { - m_GraveyardList[i]->AddPlayer(playerGuid); + gy->AddPlayer(playerGuid); break; } } @@ -657,44 +610,40 @@ void Battlefield::AddPlayerToResurrectQueue(ObjectGuid npcGuid, ObjectGuid playe void Battlefield::RemovePlayerFromResurrectQueue(ObjectGuid playerGuid) { - for (uint8 i = 0; i < m_GraveyardList.size(); i++) + for (BfGraveyard* gy : GraveyardList) { - if (!m_GraveyardList[i]) + if (!gy) continue; - if (m_GraveyardList[i]->HasPlayer(playerGuid)) + if (gy->HasPlayer(playerGuid)) { - m_GraveyardList[i]->RemovePlayer(playerGuid); + gy->RemovePlayer(playerGuid); break; } } } -void Battlefield::SendAreaSpiritHealerQueryOpcode(Player* player, const ObjectGuid& guid) +void Battlefield::SendAreaSpiritHealerQueryOpcode(Player* player, ObjectGuid const& guid) { WorldPacket data(SMSG_AREA_SPIRIT_HEALER_TIME, 12); - uint32 time = m_LastResurectTimer; // resurrect every 30 seconds + uint32 time = LastResurrectTimer; // resurrect every 30 seconds data << guid << time; ASSERT(player); player->SendDirectMessage(&data); } -// ---------------------- -// - BfGraveyard Method - -// ---------------------- -BfGraveyard::BfGraveyard(Battlefield* battlefield) +BfGraveyard::BfGraveyard(Battlefield* bf) : + ControlTeam(TEAM_NEUTRAL), + GraveyardId(0), + Bf(bf) { - m_Bf = battlefield; - m_GraveyardId = 0; - m_ControlTeam = TEAM_NEUTRAL; - m_ResurrectQueue.clear(); } void BfGraveyard::Initialize(TeamId startControl, uint32 graveyardId) { - m_ControlTeam = startControl; - m_GraveyardId = graveyardId; + ControlTeam = startControl; + GraveyardId = graveyardId; } void BfGraveyard::SetSpirit(Creature* spirit, TeamId team) @@ -705,21 +654,21 @@ void BfGraveyard::SetSpirit(Creature* spirit, TeamId team) return; } - m_SpiritGuide[team] = spirit->GetGUID(); + SpiritGuide[team] = spirit->GetGUID(); spirit->SetReactState(REACT_PASSIVE); } float BfGraveyard::GetDistance(Player* player) { - const GraveyardStruct* safeLoc = sGraveyard->GetGraveyard(m_GraveyardId); + GraveyardStruct const* safeLoc = sGraveyard->GetGraveyard(GraveyardId); return player->GetDistance2d(safeLoc->x, safeLoc->y); } void BfGraveyard::AddPlayer(ObjectGuid playerGuid) { - if (!m_ResurrectQueue.count(playerGuid)) + if (!ResurrectQueue.count(playerGuid)) { - m_ResurrectQueue.insert(playerGuid); + ResurrectQueue.insert(playerGuid); if (Player* player = ObjectAccessor::FindPlayer(playerGuid)) player->CastSpell(player, SPELL_WAITING_FOR_RESURRECT, true); @@ -728,7 +677,7 @@ void BfGraveyard::AddPlayer(ObjectGuid playerGuid) void BfGraveyard::RemovePlayer(ObjectGuid playerGuid) { - m_ResurrectQueue.erase(m_ResurrectQueue.find(playerGuid)); + ResurrectQueue.erase(ResurrectQueue.find(playerGuid)); if (Player* player = ObjectAccessor::FindPlayer(playerGuid)) player->RemoveAurasDueToSpell(SPELL_WAITING_FOR_RESURRECT); @@ -736,22 +685,22 @@ void BfGraveyard::RemovePlayer(ObjectGuid playerGuid) void BfGraveyard::Resurrect() { - if (m_ResurrectQueue.empty()) + if (ResurrectQueue.empty()) return; - for (GuidUnorderedSet::const_iterator itr = m_ResurrectQueue.begin(); itr != m_ResurrectQueue.end(); ++itr) + for (ObjectGuid const& guid : ResurrectQueue) { // Get player object from his guid - Player* player = ObjectAccessor::FindPlayer(*itr); + Player* player = ObjectAccessor::FindPlayer(guid); if (!player) continue; - // Check if the player is in world and on the good graveyard + // Check if the player is in world and on the good graveyard if (player->IsInWorld()) - if (Unit* spirit = ObjectAccessor::GetCreature(*player, m_SpiritGuide[m_ControlTeam])) + if (Unit* spirit = ObjectAccessor::GetCreature(*player, SpiritGuide[ControlTeam])) spirit->CastSpell(spirit, SPELL_SPIRIT_HEAL, true); - // Resurect player + // Resurrect player player->CastSpell(player, SPELL_RESURRECTION_VISUAL, true); player->ResurrectPlayer(1.0f); player->CastSpell(player, 6962, true); @@ -760,23 +709,23 @@ void BfGraveyard::Resurrect() player->SpawnCorpseBones(false); } - m_ResurrectQueue.clear(); + ResurrectQueue.clear(); } // For changing graveyard control void BfGraveyard::GiveControlTo(TeamId team) { - m_ControlTeam = team; - // Teleport to other graveyard, player witch were on this graveyard + ControlTeam = team; + // Teleport to other graveyard, players which were on this graveyard RelocateDeadPlayers(); } void BfGraveyard::RelocateDeadPlayers() { GraveyardStruct const* closestGrave = nullptr; - for (GuidUnorderedSet::const_iterator itr = m_ResurrectQueue.begin(); itr != m_ResurrectQueue.end(); ++itr) + for (ObjectGuid const& guid : ResurrectQueue) { - Player* player = ObjectAccessor::FindPlayer(*itr); + Player* player = ObjectAccessor::FindPlayer(guid); if (!player) continue; @@ -784,19 +733,13 @@ void BfGraveyard::RelocateDeadPlayers() player->TeleportTo(player->GetMapId(), closestGrave->x, closestGrave->y, closestGrave->z, player->GetOrientation()); else { - closestGrave = m_Bf->GetClosestGraveyard(player); + closestGrave = Bf->GetClosestGraveyard(player); if (closestGrave) player->TeleportTo(player->GetMapId(), closestGrave->x, closestGrave->y, closestGrave->z, player->GetOrientation()); } } } -// ******************************************************* -// *************** End Spirit Guide system *************** -// ******************************************************* -// ********************** Misc *************************** -// ******************************************************* - Creature* Battlefield::SpawnCreature(uint32 entry, Position pos, TeamId teamId) { return SpawnCreature(entry, pos.m_positionX, pos.m_positionY, pos.m_positionZ, pos.m_orientation, teamId); @@ -804,8 +747,7 @@ Creature* Battlefield::SpawnCreature(uint32 entry, Position pos, TeamId teamId) Creature* Battlefield::SpawnCreature(uint32 entry, float x, float y, float z, float o, TeamId teamId) { - //Get map object - Map* map = sMapMgr->CreateBaseMap(m_MapId); + Map* map = sMapMgr->CreateBaseMap(MapId); if (!map) { LOG_ERROR("bg.battlefield", "Battlefield::SpawnCreature: Can't create creature entry: {} map not found", entry); @@ -837,22 +779,18 @@ Creature* Battlefield::SpawnCreature(uint32 entry, float x, float y, float z, fl creature->SetSpeed(MOVE_WALK, cinfo->speed_walk); creature->SetSpeed(MOVE_RUN, cinfo->speed_run); - // Set creature in world map->AddToMap(creature); creature->setActive(true); return creature; } -// Method for spawning gameobject on map GameObject* Battlefield::SpawnGameObject(uint32 entry, float x, float y, float z, float o) { - // Get map object - Map* map = sMapMgr->CreateBaseMap(m_MapId); + Map* map = sMapMgr->CreateBaseMap(MapId); if (!map) - return 0; + return nullptr; - // Create gameobject GameObject* go = sObjectMgr->IsGameObjectStaticTransport(entry) ? new StaticTransport() : new GameObject(); G3D::Quat rotation = G3D::Quat::fromAxisAngleRotation(G3D::Vector3::unitZ(), o); if (!go->Create(map->GenerateLowGuid(), entry, map, PHASEMASK_NORMAL, x, y, z, o, rotation, 100, GO_STATE_READY)) @@ -863,7 +801,6 @@ GameObject* Battlefield::SpawnGameObject(uint32 entry, float x, float y, float z return nullptr; } - // Add to world map->AddToMap(go); go->setActive(true); @@ -872,35 +809,32 @@ GameObject* Battlefield::SpawnGameObject(uint32 entry, float x, float y, float z Creature* Battlefield::GetCreature(ObjectGuid const& guid) { - if (!m_Map) + if (!BfMap) return nullptr; - return m_Map->GetCreature(guid); + return BfMap->GetCreature(guid); } GameObject* Battlefield::GetGameObject(ObjectGuid const& guid) { - if (!m_Map) + if (!BfMap) return nullptr; - return m_Map->GetGameObject(guid); + return BfMap->GetGameObject(guid); } -// ******************************************************* -// ******************* CapturePoint ********************** -// ******************************************************* - -BfCapturePoint::BfCapturePoint(Battlefield* battlefield) : m_Bf(battlefield) +BfCapturePoint::BfCapturePoint(Battlefield* bf) : + MaxValue(0.0f), + MinValue(0.0f), + MaxSpeed(0), + Value(0), + Team(TEAM_NEUTRAL), + OldState(BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL), + State(BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL), + NeutralValuePct(0), + Bf(bf), + CapturePointEntry(0) { - m_team = TEAM_NEUTRAL; - m_value = 0; - m_minValue = 0.0f; - m_maxValue = 0.0f; - m_State = BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL; - m_OldState = BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL; - m_capturePointEntry = 0; - m_neutralValuePct = 0; - m_maxSpeed = 0; } bool BfCapturePoint::HandlePlayerEnter(Player* player) @@ -908,10 +842,10 @@ bool BfCapturePoint::HandlePlayerEnter(Player* player) if (GameObject* go = GetCapturePointGo(player)) { player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldState1, 1); - player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate2, uint32(std::ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f))); - player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate3, m_neutralValuePct); + player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate2, uint32(std::ceil((Value + MaxValue) / (2 * MaxValue) * 100.0f))); + player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate3, NeutralValuePct); } - return m_activePlayers[player->GetTeamId()].insert(player->GetGUID()).second; + return ActivePlayers[player->GetTeamId()].insert(player->GetGUID()).second; } GuidUnorderedSet::iterator BfCapturePoint::HandlePlayerLeave(Player* player) @@ -919,12 +853,12 @@ GuidUnorderedSet::iterator BfCapturePoint::HandlePlayerLeave(Player* player) if (GameObject* go = GetCapturePointGo(player)) player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldState1, 0); - GuidUnorderedSet::iterator current = m_activePlayers[player->GetTeamId()].find(player->GetGUID()); + GuidUnorderedSet::iterator current = ActivePlayers[player->GetTeamId()].find(player->GetGUID()); - if (current == m_activePlayers[player->GetTeamId()].end()) + if (current == ActivePlayers[player->GetTeamId()].end()) return current; // return end() - current = m_activePlayers[player->GetTeamId()].erase(current); + current = ActivePlayers[player->GetTeamId()].erase(current); return current; } @@ -935,15 +869,15 @@ void BfCapturePoint::SendChangePhase() return; for (uint8 team = 0; team < 2; ++team) - for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr) // send to all players present in the area - if (Player* player = ObjectAccessor::FindPlayer(*itr)) + for (ObjectGuid const& guid : ActivePlayers[team]) // send to all players present in the area + if (Player* player = ObjectAccessor::FindPlayer(guid)) { // send this too, sometimes the slider disappears, dunno why :( player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldState1, 1); // send these updates to only the ones in this objective - player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate2, (uint32) std::ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f)); + player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate2, (uint32) std::ceil((Value + MaxValue) / (2 * MaxValue) * 100.0f)); // send this too, sometimes it resets :S - player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate3, m_neutralValuePct); + player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate3, NeutralValuePct); } } @@ -953,10 +887,10 @@ bool BfCapturePoint::SetCapturePointData(GameObject* capturePoint, TeamId team) //At first call using TEAM_NEUTRAL as a checker but never using it, after first call we reset the capturepoints to the new winner of the last WG war if (team == TEAM_NEUTRAL) - team = m_team; + team = Team; LOG_DEBUG("bg.battlefield", "Creating capture point {}", capturePoint->GetEntry()); - m_capturePoint = capturePoint->GetGUID(); + CapturePoint = capturePoint->GetGUID(); // check info existence GameObjectTemplate const* goinfo = capturePoint->GetGOInfo(); @@ -967,20 +901,20 @@ bool BfCapturePoint::SetCapturePointData(GameObject* capturePoint, TeamId team) } // get the needed values from goinfo - m_maxValue = goinfo->capturePoint.maxTime; - m_maxSpeed = m_maxValue / (goinfo->capturePoint.minTime ? goinfo->capturePoint.minTime : 60); - m_neutralValuePct = goinfo->capturePoint.neutralPercent; - m_minValue = m_maxValue * goinfo->capturePoint.neutralPercent / 100; - m_capturePointEntry = capturePoint->GetEntry(); + MaxValue = goinfo->capturePoint.maxTime; + MaxSpeed = MaxValue / (goinfo->capturePoint.minTime ? goinfo->capturePoint.minTime : 60); + NeutralValuePct = goinfo->capturePoint.neutralPercent; + MinValue = MaxValue * goinfo->capturePoint.neutralPercent / 100; + CapturePointEntry = capturePoint->GetEntry(); if (team == TEAM_ALLIANCE) { - m_value = m_maxValue; - m_State = BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE; + Value = MaxValue; + State = BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE; } else { - m_value = -m_maxValue; - m_State = BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE; + Value = -MaxValue; + State = BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE; } return true; @@ -992,7 +926,7 @@ bool BfCapturePoint::DelCapturePoint() { capturePoint->SetRespawnTime(0); // not save respawn time capturePoint->Delete(); - m_capturePoint.Clear(); + CapturePoint.Clear(); } return true; @@ -1000,12 +934,12 @@ bool BfCapturePoint::DelCapturePoint() GameObject* BfCapturePoint::GetCapturePointGo() { - return m_Bf->GetGameObject(m_capturePoint); + return Bf->GetGameObject(CapturePoint); } GameObject* BfCapturePoint::GetCapturePointGo(WorldObject* obj) { - return ObjectAccessor::GetGameObject(*obj, m_capturePoint); + return ObjectAccessor::GetGameObject(*obj, CapturePoint); } bool BfCapturePoint::Update(uint32 diff) @@ -1018,7 +952,7 @@ bool BfCapturePoint::Update(uint32 diff) for (uint8 team = 0; team < 2; ++team) { - for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end();) + for (auto itr = ActivePlayers[team].begin(); itr != ActivePlayers[team].end();) { if (Player* player = ObjectAccessor::FindPlayer(*itr)) if (!capturePoint->IsWithinDistInMap(player, radius) || !player->IsOutdoorPvPActive()) @@ -1036,90 +970,89 @@ bool BfCapturePoint::Update(uint32 diff) Acore::PlayerListSearcher searcher(capturePoint, players, checker); Cell::VisitObjects(capturePoint, searcher, radius); - for (std::list::iterator itr = players.begin(); itr != players.end(); ++itr) - if ((*itr)->IsOutdoorPvPActive()) - if (m_activePlayers[(*itr)->GetTeamId()].insert((*itr)->GetGUID()).second) - HandlePlayerEnter(*itr); + for (Player* player : players) + if (player->IsOutdoorPvPActive()) + if (ActivePlayers[player->GetTeamId()].insert(player->GetGUID()).second) + HandlePlayerEnter(player); // get the difference of numbers - float fact_diff = ((float) m_activePlayers[0].size() - (float) m_activePlayers[1].size()) * diff / BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL; - if (G3D::fuzzyEq(fact_diff, 0.0f)) + float factDiff = ((float) ActivePlayers[0].size() - (float) ActivePlayers[1].size()) * diff / BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL; + if (G3D::fuzzyEq(factDiff, 0.0f)) return false; - TeamId ChallengerId = TEAM_NEUTRAL; - float maxDiff = m_maxSpeed * diff; + TeamId challengerId = TEAM_NEUTRAL; + float maxDiff = MaxSpeed * diff; - if (fact_diff < 0) + if (factDiff < 0) { // horde is in majority, but it's already horde-controlled -> no change - if (m_State == BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE && m_value <= -m_maxValue) + if (State == BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE && Value <= -MaxValue) return false; - if (fact_diff < -maxDiff) - fact_diff = -maxDiff; + if (factDiff < -maxDiff) + factDiff = -maxDiff; - ChallengerId = TEAM_HORDE; + challengerId = TEAM_HORDE; } else { // ally is in majority, but it's already ally-controlled -> no change - if (m_State == BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE && m_value >= m_maxValue) + if (State == BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE && Value >= MaxValue) return false; - if (fact_diff > maxDiff) - fact_diff = maxDiff; + if (factDiff > maxDiff) + factDiff = maxDiff; - ChallengerId = TEAM_ALLIANCE; + challengerId = TEAM_ALLIANCE; } - float oldValue = m_value; - TeamId oldTeam = m_team; + float oldValue = Value; + TeamId oldTeam = Team; - m_OldState = m_State; + OldState = State; - m_value += fact_diff; + Value += factDiff; - if (m_value < -m_minValue) // red + if (Value < -MinValue) // red { - if (m_value < -m_maxValue) - m_value = -m_maxValue; - m_State = BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE; - m_team = TEAM_HORDE; + if (Value < -MaxValue) + Value = -MaxValue; + State = BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE; + Team = TEAM_HORDE; } - else if (m_value > m_minValue) // blue + else if (Value > MinValue) // blue { - if (m_value > m_maxValue) - m_value = m_maxValue; - m_State = BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE; - m_team = TEAM_ALLIANCE; + if (Value > MaxValue) + Value = MaxValue; + State = BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE; + Team = TEAM_ALLIANCE; } - else if (oldValue * m_value <= 0) // grey, go through mid point + else if (oldValue * Value <= 0) // grey, go through mid point { // if challenger is ally, then n->a challenge - if (ChallengerId == TEAM_ALLIANCE) - m_State = BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE; + if (challengerId == TEAM_ALLIANCE) + State = BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE; // if challenger is horde, then n->h challenge - else if (ChallengerId == TEAM_HORDE) - m_State = BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE; - m_team = TEAM_NEUTRAL; + else if (challengerId == TEAM_HORDE) + State = BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE; + Team = TEAM_NEUTRAL; } - else // grey, did not go through mid point + else // grey, did not go through mid point { // old phase and current are on the same side, so one team challenges the other - if (ChallengerId == TEAM_ALLIANCE && (m_OldState == BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE || m_OldState == BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE)) - m_State = BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE; - else if (ChallengerId == TEAM_HORDE && (m_OldState == BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE || m_OldState == BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE)) - m_State = BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE; - m_team = TEAM_NEUTRAL; + if (challengerId == TEAM_ALLIANCE && (OldState == BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE || OldState == BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE)) + State = BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE; + else if (challengerId == TEAM_HORDE && (OldState == BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE || OldState == BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE)) + State = BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE; + Team = TEAM_NEUTRAL; } - if (G3D::fuzzyNe(m_value, oldValue)) + if (G3D::fuzzyNe(Value, oldValue)) SendChangePhase(); - if (m_OldState != m_State) + if (OldState != State) { - //LOG_ERROR("bg.battlefield", "{}->{}", m_OldState, m_State); - if (oldTeam != m_team) + if (oldTeam != Team) ChangeTeam(oldTeam); return true; } @@ -1130,15 +1063,15 @@ bool BfCapturePoint::Update(uint32 diff) void BfCapturePoint::SendUpdateWorldState(uint32 field, uint32 value) { for (uint8 team = 0; team < 2; ++team) - for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr) // send to all players present in the area - if (Player* player = ObjectAccessor::FindPlayer(*itr)) + for (ObjectGuid const& guid : ActivePlayers[team]) // send to all players present in the area + if (Player* player = ObjectAccessor::FindPlayer(guid)) player->SendUpdateWorldState(field, value); } void BfCapturePoint::SendObjectiveComplete(uint32 id, ObjectGuid guid) { uint8 team; - switch (m_State) + switch (State) { case BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE: team = 0; @@ -1151,12 +1084,12 @@ void BfCapturePoint::SendObjectiveComplete(uint32 id, ObjectGuid guid) } // send to all players present in the area - for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) + for (ObjectGuid const& playerGuid : ActivePlayers[team]) + if (Player* player = ObjectAccessor::FindPlayer(playerGuid)) player->KilledMonsterCredit(id, guid); } bool BfCapturePoint::IsInsideObjective(Player* player) const { - return m_activePlayers[player->GetTeamId()].find(player->GetGUID()) != m_activePlayers[player->GetTeamId()].end(); + return ActivePlayers[player->GetTeamId()].find(player->GetGUID()) != ActivePlayers[player->GetTeamId()].end(); } diff --git a/src/server/game/Battlefield/Battlefield.h b/src/server/game/Battlefield/Battlefield.h index b8f853266..ad2a3394c 100644 --- a/src/server/game/Battlefield/Battlefield.h +++ b/src/server/game/Battlefield/Battlefield.h @@ -71,8 +71,8 @@ class Unit; class Battlefield; class BfGraveyard; -typedef std::vector GraveyardVect; -typedef std::map PlayerTimerMap; +using GraveyardVect = std::vector; +using PlayerTimerMap = std::map; class BfCapturePoint { @@ -92,7 +92,6 @@ public: // Used when player is activated/inactivated in the area virtual bool HandlePlayerEnter(Player* player); virtual GuidUnorderedSet::iterator HandlePlayerLeave(Player* player); - //virtual void HandlePlayerActivityChanged(Player* player); // Checks if player is in range of a capture credit marker bool IsInsideObjective(Player* player) const; @@ -102,70 +101,71 @@ public: virtual void ChangeTeam(TeamId /*oldTeam*/) {} virtual void SendChangePhase(); - //Added team to reset capturepoints on sliders after warTime + // Added team to reset capturepoints on sliders after warTime bool SetCapturePointData(GameObject* capturePoint, TeamId team); GameObject* GetCapturePointGo(); GameObject* GetCapturePointGo(WorldObject* obj); - TeamId GetTeamId() { return m_team; } + TeamId GetTeamId() const { return Team; } + protected: bool DelCapturePoint(); - // active Players in the area of the objective, 0 - alliance, 1 - horde - GuidUnorderedSet m_activePlayers[2]; + // Active players in the area of the objective, 0 - alliance, 1 - horde + GuidUnorderedSet ActivePlayers[2]; // Total shift needed to capture the objective - float m_maxValue; - float m_minValue; + float MaxValue; + float MinValue; // Maximum speed of capture - float m_maxSpeed; + float MaxSpeed; // The status of the objective - float m_value; - TeamId m_team; + float Value; + TeamId Team; // Objective states - BattlefieldObjectiveStates m_OldState; - BattlefieldObjectiveStates m_State; + BattlefieldObjectiveStates OldState; + BattlefieldObjectiveStates State; // Neutral value on capture bar - uint32 m_neutralValuePct; + uint32 NeutralValuePct; // Pointer to the Battlefield this objective belongs to - Battlefield* m_Bf; + Battlefield* Bf; // Capture point entry - uint32 m_capturePointEntry; + uint32 CapturePointEntry; // Gameobject related to that capture point - ObjectGuid m_capturePoint; + ObjectGuid CapturePoint; }; class BfGraveyard { public: - BfGraveyard(Battlefield* Bf); + BfGraveyard(Battlefield* bf); virtual ~BfGraveyard() = default; // Method to changing who controls the graveyard void GiveControlTo(TeamId team); - TeamId GetControlTeamId() const { return m_ControlTeam; } + TeamId GetControlTeamId() const { return ControlTeam; } // Find the nearest graveyard to a player float GetDistance(Player* player); // Initialize the graveyard - void Initialize(TeamId startcontrol, uint32 gy); + void Initialize(TeamId startControl, uint32 graveyardId); // Set spirit service for the graveyard void SetSpirit(Creature* spirit, TeamId team); // Add a player to the graveyard - void AddPlayer(ObjectGuid player_guid); + void AddPlayer(ObjectGuid playerGuid); // Remove a player from the graveyard - void RemovePlayer(ObjectGuid player_guid); + void RemovePlayer(ObjectGuid playerGuid); // Resurrect players void Resurrect(); @@ -176,29 +176,24 @@ public: // Check if this graveyard has a spirit guide bool HasNpc(ObjectGuid guid) { - if (!m_SpiritGuide[0] && !m_SpiritGuide[1]) + if (!SpiritGuide[0] && !SpiritGuide[1]) return false; - // performance - /*if (!ObjectAccessor::FindUnit(m_SpiritGuide[0]) && - !ObjectAccessor::FindUnit(m_SpiritGuide[1])) - return false;*/ - - return (m_SpiritGuide[0] == guid || m_SpiritGuide[1] == guid); + return (SpiritGuide[0] == guid || SpiritGuide[1] == guid); } // Check if a player is in this graveyard's resurrect queue - bool HasPlayer(ObjectGuid guid) const { return m_ResurrectQueue.find(guid) != m_ResurrectQueue.end(); } + bool HasPlayer(ObjectGuid guid) const { return ResurrectQueue.find(guid) != ResurrectQueue.end(); } // Get the graveyard's ID. - uint32 GetGraveyardId() const { return m_GraveyardId; } + uint32 GetGraveyardId() const { return GraveyardId; } protected: - TeamId m_ControlTeam; - uint32 m_GraveyardId; - ObjectGuid m_SpiritGuide[2]; - GuidUnorderedSet m_ResurrectQueue; - Battlefield* m_Bf; + TeamId ControlTeam; + uint32 GraveyardId; + ObjectGuid SpiritGuide[2]; + GuidUnorderedSet ResurrectQueue; + Battlefield* Bf; }; class Battlefield : public ZoneScript @@ -211,8 +206,8 @@ public: /// Destructor ~Battlefield() override; - /// typedef of map witch store capturepoint and the associate gameobject entry - typedef std::vector BfCapturePointVector; + /// Vector of capture points belonging to this battlefield + using BfCapturePointVector = std::vector; /// Call this to init the Battlefield virtual bool SetupBattlefield() { return true; } @@ -223,9 +218,9 @@ public: /** * \brief Called every time for update bf data and time * - Update timer for start/end battle - * - Invite player in zone to queue m_StartGroupingTimer minutes before start + * - Invite player in zone to queue StartGroupingTimer minutes before start * - Kick Afk players - * \param diff : time ellapsed since last call (in ms) + * \param diff : time elapsed since last call (in ms) */ virtual bool Update(uint32 diff); @@ -236,56 +231,56 @@ public: /// Invite all players in zone to join battle on battle start void InvitePlayersInZoneToWar(); - /// Called when a Unit is kill in battlefield zone + /// Called when a Unit is killed in battlefield zone virtual void HandleKill(Player* /*killer*/, Unit* /*killed*/) {}; - uint32 GetTypeId() { return m_TypeId; } - uint32 GetZoneId() { return m_ZoneId; } + uint32 GetTypeId() const { return TypeId; } + uint32 GetZoneId() const { return ZoneId; } void TeamApplyBuff(TeamId team, uint32 spellId, uint32 spellId2 = 0); - /// Return true if battle is start, false if battle is not started - bool IsWarTime() { return m_isActive; } + /// Return true if battle is started, false if battle is not started + bool IsWarTime() const { return Active; } /// Enable or Disable battlefield - void ToggleBattlefield(bool enable) { m_IsEnabled = enable; } - /// Return if battlefield is enable - bool IsEnabled() { return m_IsEnabled; } + void ToggleBattlefield(bool enable) { Enabled = enable; } + /// Return if battlefield is enabled + bool IsEnabled() const { return Enabled; } /** * \brief Kick player from battlefield and teleport him to kick-point location - * \param guid : guid of player who must be kick + * \param guid : guid of player who must be kicked */ void KickPlayerFromBattlefield(ObjectGuid guid); - /// Called when player (player) enter in zone + /// Called when player (player) enters the zone void HandlePlayerEnterZone(Player* player, uint32 zone); - /// Called when player (player) leave the zone + /// Called when player (player) leaves the zone void HandlePlayerLeaveZone(Player* player, uint32 zone); // All-purpose data storage 64 bit - uint64 GetData64(uint32 dataId) const override { return m_Data64[dataId]; } - void SetData64(uint32 dataId, uint64 value) override { m_Data64[dataId] = value; } + uint64 GetData64(uint32 dataId) const override { return Data64[dataId]; } + void SetData64(uint32 dataId, uint64 value) override { Data64[dataId] = value; } // All-purpose data storage 32 bit - uint32 GetData(uint32 dataId) const override { return m_Data32[dataId]; } - void SetData(uint32 dataId, uint32 value) override { m_Data32[dataId] = value; } - virtual void UpdateData(uint32 index, int32 pad) { m_Data32[index] += pad; } + uint32 GetData(uint32 dataId) const override { return Data32[dataId]; } + void SetData(uint32 dataId, uint32 value) override { Data32[dataId] = value; } + virtual void UpdateData(uint32 index, int32 pad) { Data32[index] += pad; } // Battlefield - generic methods - TeamId GetDefenderTeam() { return m_DefenderTeam; } - TeamId GetAttackerTeam() { return TeamId(1 - m_DefenderTeam); } - TeamId GetOtherTeam(TeamId team) { return (team == TEAM_HORDE ? TEAM_ALLIANCE : TEAM_HORDE); } - void SetDefenderTeam(TeamId team) { m_DefenderTeam = team; } + TeamId GetDefenderTeam() const { return DefenderTeam; } + TeamId GetAttackerTeam() const { return TeamId(1 - DefenderTeam); } + TeamId GetOtherTeam(TeamId team) const { return (team == TEAM_HORDE ? TEAM_ALLIANCE : TEAM_HORDE); } + void SetDefenderTeam(TeamId team) { DefenderTeam = team; } // Group methods /** * \brief Find a not full battlefield group, if there is no, create one - * \param TeamId : Id of player team for who we search a group (player->GetTeamId()) + * \param teamId : Id of player team for who we search a group (player->GetTeamId()) */ - Group* GetFreeBfRaid(TeamId TeamId); + Group* GetFreeBfRaid(TeamId teamId); /// Return battlefield group where player is. - Group* GetGroupPlayer(ObjectGuid guid, TeamId TeamId); + Group* GetGroupPlayer(ObjectGuid guid, TeamId teamId); /// Force player to join a battlefield group bool AddOrSetPlayerToCorrectBfGroup(Player* player); @@ -293,9 +288,9 @@ public: // Find which graveyard the player must be teleported to to be resurrected by spiritguide GraveyardStruct const* GetClosestGraveyard(Player* player); - virtual void AddPlayerToResurrectQueue(ObjectGuid npc_guid, ObjectGuid player_guid); - void RemovePlayerFromResurrectQueue(ObjectGuid player_guid); - void SetGraveyardNumber(uint32 number) { m_GraveyardList.resize(number); } + virtual void AddPlayerToResurrectQueue(ObjectGuid npcGuid, ObjectGuid playerGuid); + void RemovePlayerFromResurrectQueue(ObjectGuid playerGuid); + void SetGraveyardNumber(uint32 number) { GraveyardList.resize(number); } BfGraveyard* GetGraveyardById(uint32 id) const; // Misc methods @@ -312,36 +307,34 @@ public: virtual void OnBattleStart() {}; /// Called at the end of battle virtual void OnBattleEnd(bool /*endByTimer*/) {}; - /// Called x minutes before battle start when player in zone are invite to join queue + /// Called x minutes before battle start when players in zone are invited to join queue virtual void OnStartGrouping() {}; - /// Called when a player accept to join the battle + /// Called when a player accepts to join the battle virtual void OnPlayerJoinWar(Player* /*player*/) {}; - /// Called when a player leave the battle + /// Called when a player leaves the battle virtual void OnPlayerLeaveWar(Player* /*player*/) {}; - /// Called when a player leave battlefield zone + /// Called when a player leaves the battlefield zone virtual void OnPlayerLeaveZone(Player* /*player*/) {}; - /// Called when a player enter in battlefield zone + /// Called when a player enters the battlefield zone virtual void OnPlayerEnterZone(Player* /*player*/) {}; void SendWarning(uint8 id, WorldObject const* target = nullptr); void PlayerAcceptInviteToQueue(Player* player); void PlayerAcceptInviteToWar(Player* player); - uint32 GetBattleId() { return m_BattleId; } + uint32 GetBattleId() const { return BattleId; } void AskToLeaveQueue(Player* player); void PlayerAskToLeave(Player* player); - //virtual void DoCompleteOrIncrementAchievement(uint32 /*achievement*/, Player* /*player*/, uint8 /*incrementNumber = 1*/) {}; - - /// Send all worldstate data to all player in zone. + /// Send all worldstate data to all players in zone. virtual void SendInitWorldStatesToAll() = 0; virtual void FillInitialWorldStates(WorldPackets::WorldState::InitWorldStates& /*packet*/) = 0; virtual void SendUpdateWorldStates(Player* player = nullptr) = 0; /// Return if we can use mount in battlefield - bool CanFlyIn() { return !m_isActive; } + bool CanFlyIn() const { return !Active; } - void SendAreaSpiritHealerQueryOpcode(Player* player, const ObjectGuid& guid); + void SendAreaSpiritHealerQueryOpcode(Player* player, ObjectGuid const& guid); void StartBattle(); void EndBattle(bool endByTimer); @@ -349,27 +342,29 @@ public: void HideNpc(Creature* creature); void ShowNpc(Creature* creature, bool aggressive); - GraveyardVect GetGraveyardVector() { return m_GraveyardList; } + GraveyardVect const& GetGraveyardVector() const { return GraveyardList; } - uint32 GetTimer() { return m_Timer; } - void SetTimer(uint32 timer) { m_Timer = timer; } + uint32 GetTimer() const { return Timer; } + void SetTimer(uint32 timer) { Timer = timer; } // Returns combined count of players in war + invited (per team) for balance checking - uint32 GetPlayersInWarCount(TeamId teamId) const { return static_cast(m_PlayersInWar[teamId].size() + m_InvitedPlayers[teamId].size()); } + uint32 GetPlayersInWarCount(TeamId teamId) const { return static_cast(PlayersInWar[teamId].size() + InvitedPlayers[teamId].size()); } // Returns total count of players in the battlefield zone per team - uint32 GetPlayersInZoneCount(TeamId teamId) const { return static_cast(m_players[teamId].size()); } + uint32 GetPlayersInZoneCount(TeamId teamId) const { return static_cast(Players[teamId].size()); } // Returns the maximum players allowed per team - uint32 GetMaxPlayersPerTeam() const { return m_MaxPlayer; } + uint32 GetMaxPlayersPerTeam() const { return MaxPlayer; } + /// Returns true if there is still room for another player on the given team in the active war. + bool HasWarVacancy(TeamId teamId) const { return GetPlayersInWarCount(teamId) < MaxPlayer; } /// Returns the set of players waiting in the pre-battle queue (per team, read-only). - GuidUnorderedSet const& GetPlayersQueueSet(TeamId teamId) const { return m_PlayersInQueue[teamId]; } + GuidUnorderedSet const& GetPlayersQueueSet(TeamId teamId) const { return PlayersInQueue[teamId]; } /// Returns the map of players invited to join the active war, value is invite expiry /// timestamp (per team, read-only). - PlayerTimerMap const& GetInvitedPlayersMap(TeamId teamId) const { return m_InvitedPlayers[teamId]; } + PlayerTimerMap const& GetInvitedPlayersMap(TeamId teamId) const { return InvitedPlayers[teamId]; } /// Returns the set of players actively fighting in the war (per team, read-only). - GuidUnorderedSet const& GetPlayersInWarSet(TeamId teamId) const { return m_PlayersInWar[teamId]; } + GuidUnorderedSet const& GetPlayersInWarSet(TeamId teamId) const { return PlayersInWar[teamId]; } - void DoPlaySoundToAll(uint32 SoundID); + void DoPlaySoundToAll(uint32 soundId); void InvitePlayerToQueue(Player* player); void InvitePlayerToWar(Player* player); @@ -378,50 +373,50 @@ public: protected: ObjectGuid StalkerGuid; - uint32 m_Timer; // Global timer for event - bool m_IsEnabled; - bool m_isActive; - TeamId m_DefenderTeam; + uint32 Timer; // Global timer for event + bool Enabled; + bool Active; + TeamId DefenderTeam; // Map of the objectives belonging to this OutdoorPvP - BfCapturePointVector m_capturePoints; + BfCapturePointVector CapturePoints; // Players info maps - GuidUnorderedSet m_players[PVP_TEAMS_COUNT]; // Players in zone - GuidUnorderedSet m_PlayersInQueue[PVP_TEAMS_COUNT]; // Players in the queue - GuidUnorderedSet m_PlayersInWar[PVP_TEAMS_COUNT]; // Players in WG combat - PlayerTimerMap m_InvitedPlayers[PVP_TEAMS_COUNT]; - PlayerTimerMap m_PlayersWillBeKick[PVP_TEAMS_COUNT]; + GuidUnorderedSet Players[PVP_TEAMS_COUNT]; // Players in zone + GuidUnorderedSet PlayersInQueue[PVP_TEAMS_COUNT]; // Players in the queue + GuidUnorderedSet PlayersInWar[PVP_TEAMS_COUNT]; // Players in WG combat + PlayerTimerMap InvitedPlayers[PVP_TEAMS_COUNT]; + PlayerTimerMap PlayersWillBeKick[PVP_TEAMS_COUNT]; // Variables that must exist for each battlefield - uint32 m_TypeId; // See enum BattlefieldTypes - uint32 m_BattleId; // BattleID (for packet) - uint32 m_ZoneId; // ZoneID of Wintergrasp = 4197 - uint32 m_MapId; // MapId where is Battlefield - Map* m_Map; - uint32 m_MaxPlayer; // Maximum number of players per team that participated to Battlefield - uint32 m_MinPlayer; // Minimum number of players per team for Battlefield start - uint32 m_MinLevel; // Required level to participate at Battlefield - uint32 m_BattleTime; // Length of a battle - uint32 m_NoWarBattleTime; // Time between two battles - uint32 m_RestartAfterCrash; // Delay to restart Wintergrasp if the server crashed during a running battle. - uint32 m_TimeForAcceptInvite; - uint32 m_uiKickDontAcceptTimer; + uint32 TypeId; // See enum BattlefieldTypes + uint32 BattleId; // BattleID (for packet) + uint32 ZoneId; // ZoneID of Wintergrasp = 4197 + uint32 MapId; // MapId where is Battlefield + Map* BfMap; + uint32 MaxPlayer; // Maximum number of players per team that participated to Battlefield + uint32 MinPlayer; // Minimum number of players per team for Battlefield start + uint32 MinLevel; // Required level to participate at Battlefield + uint32 BattleTime; // Length of a battle + uint32 NoWarBattleTime; // Time between two battles + uint32 RestartAfterCrash; // Delay to restart Wintergrasp if the server crashed during a running battle + uint32 TimeForAcceptInvite; + uint32 KickDontAcceptTimer; WorldLocation KickPosition; // Position where players are teleported if they switch to afk during the battle or if they don't accept invitation - uint32 m_uiKickAfkPlayersTimer; // Timer for check Afk in war + uint32 KickAfkPlayersTimer; // Timer for check Afk in war // Graveyard variables - GraveyardVect m_GraveyardList; // Vector witch contain the different GY of the battle - uint32 m_LastResurectTimer; // Timer for resurect player every 30 sec + GraveyardVect GraveyardList; // Vector which contains the different GY of the battle + uint32 LastResurrectTimer; // Timer for resurrect player every 30 sec - uint32 m_StartGroupingTimer; // Timer for invite players in area 15 minute before start battle - bool m_StartGrouping; // bool for know if all players in area has been invited + uint32 StartGroupingTimer; // Timer for invite players in area 15 minutes before start battle + bool StartGrouping; // bool for knowing if all players in area have been invited - GuidUnorderedSet m_Groups[PVP_TEAMS_COUNT]; // Contain different raid group + GuidUnorderedSet Groups[PVP_TEAMS_COUNT]; // Contains different raid groups - std::vector m_Data64; - std::vector m_Data32; + std::vector Data64; + std::vector Data32; void KickAfkPlayers(); @@ -434,11 +429,51 @@ protected: void BroadcastPacketToWar(WorldPacket const* data) const; // CapturePoint system - void AddCapturePoint(BfCapturePoint* cp) { m_capturePoints.push_back(cp); } + void AddCapturePoint(BfCapturePoint* cp) { CapturePoints.push_back(cp); } - void RegisterZone(uint32 zoneid); + void RegisterZone(uint32 zoneId); bool HasPlayer(Player* player) const; void TeamCastSpell(TeamId team, int32 spellId); + + /// Returns true if the player is already tracked as actively in the war or invited to join it. + bool IsPlayerInWarOrInvited(Player* player) const; + + // Player-iteration helpers: resolve each GUID to a live Player* and call fn(player). + // Using templates avoids std::function overhead and works naturally with lambdas. + template + void ForEachPlayerInZone(Func&& fn) const + { + for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team) + for (ObjectGuid const& guid : Players[team]) + if (Player* player = ObjectAccessor::FindPlayer(guid)) + fn(player); + } + + template + void ForEachPlayerInQueue(Func&& fn) const + { + for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team) + for (ObjectGuid const& guid : PlayersInQueue[team]) + if (Player* player = ObjectAccessor::FindPlayer(guid)) + fn(player); + } + + template + void ForEachPlayerInWar(Func&& fn) const + { + for (uint8 team = 0; team < PVP_TEAMS_COUNT; ++team) + for (ObjectGuid const& guid : PlayersInWar[team]) + if (Player* player = ObjectAccessor::FindPlayer(guid)) + fn(player); + } + + template + void ForEachPlayerInWar(TeamId team, Func&& fn) const + { + for (ObjectGuid const& guid : PlayersInWar[team]) + if (Player* player = ObjectAccessor::FindPlayer(guid)) + fn(player); + } }; #endif diff --git a/src/server/game/Battlefield/BattlefieldHandler.cpp b/src/server/game/Battlefield/BattlefieldHandler.cpp index 6d90c7ec1..5fc4eb9ea 100644 --- a/src/server/game/Battlefield/BattlefieldHandler.cpp +++ b/src/server/game/Battlefield/BattlefieldHandler.cpp @@ -24,125 +24,113 @@ #include "WorldPacket.h" #include "WorldSession.h" -//This send to player windows for invite player to join the war -//Param1:(BattleId) the BattleId of Bf -//Param2:(ZoneId) the zone where the battle is (4197 for wg) -//Param3:(time) Time in second that the player have for accept -void WorldSession::SendBfInvitePlayerToWar(uint32 BattleId, uint32 ZoneId, uint32 p_time) +// Sends to player the window to invite them to join the war +// Param1:(battleId) the BattleId of Bf +// Param2:(zoneId) the zone where the battle is (4197 for wg) +// Param3:(time) Time in seconds that the player has to accept +void WorldSession::SendBfInvitePlayerToWar(uint32 battleId, uint32 zoneId, uint32 time) { - //Send packet WorldPacket data(SMSG_BATTLEFIELD_MGR_ENTRY_INVITE, 12); - data << uint32(BattleId); - data << uint32(ZoneId); - data << uint32((GameTime::GetGameTime().count() + p_time)); - - //Sending the packet to player + data << uint32(battleId); + data << uint32(zoneId); + data << uint32(GameTime::GetGameTime().count() + time); SendPacket(&data); } -//This send invitation to player to join the queue -//Param1:(BattleId) the BattleId of Bf -void WorldSession::SendBfInvitePlayerToQueue(uint32 BattleId) +// Sends invitation to player to join the queue +// Param1:(battleId) the BattleId of Bf +void WorldSession::SendBfInvitePlayerToQueue(uint32 battleId) { WorldPacket data(SMSG_BATTLEFIELD_MGR_QUEUE_INVITE, 5); - - data << uint32(BattleId); - data << uint8(1); //warmup ? used ? - - //Sending packet to player + data << uint32(battleId); + data << uint8(1); // warmup ? used ? SendPacket(&data); } -//This send packet for inform player that he join queue -//Param1:(BattleId) the BattleId of Bf -//Param2:(ZoneId) the zone where the battle is (4197 for wg) -//Param3:(CanQueue) if able to queue -//Param4:(Full) on log in is full -void WorldSession::SendBfQueueInviteResponse(uint32 BattleId, uint32 ZoneId, bool CanQueue, bool Full) +// Sends packet to inform player that they joined the queue +// Param1:(battleId) the BattleId of Bf +// Param2:(zoneId) the zone where the battle is (4197 for wg) +// Param3:(canQueue) if able to queue +// Param4:(full) on log in is full +void WorldSession::SendBfQueueInviteResponse(uint32 battleId, uint32 zoneId, bool canQueue, bool full) { WorldPacket data(SMSG_BATTLEFIELD_MGR_QUEUE_REQUEST_RESPONSE, 11); - data << uint32(BattleId); - data << uint32(ZoneId); - data << uint8((CanQueue ? 1 : 0)); //Accepted //0 you cannot queue wg //1 you are queued - data << uint8((Full ? 0 : 1)); //Logging In //0 wg full //1 queue for upcoming + data << uint32(battleId); + data << uint32(zoneId); + data << uint8((canQueue ? 1 : 0)); //Accepted //0 you cannot queue wg //1 you are queued + data << uint8((full ? 0 : 1)); //Logging In //0 wg full //1 queue for upcoming data << uint8(1); //Warmup SendPacket(&data); } -//This is call when player accept to join war -//Param1:(BattleId) the BattleId of Bf -void WorldSession::SendBfEntered(uint32 BattleId) +// Called when player accepts to join war +// Param1:(battleId) the BattleId of Bf +void WorldSession::SendBfEntered(uint32 battleId) { - // m_PlayerInWar[player->GetTeamId()].insert(player->GetGUID()); WorldPacket data(SMSG_BATTLEFIELD_MGR_ENTERED, 7); - data << uint32(BattleId); - data << uint8(1); //unk - data << uint8(1); //unk - data << uint8(_player->isAFK() ? 1 : 0); //Clear AFK + data << uint32(battleId); + data << uint8(1); // unk + data << uint8(1); // unk + data << uint8(_player->isAFK() ? 1 : 0); // Clear AFK SendPacket(&data); } -void WorldSession::SendBfLeaveMessage(uint32 BattleId, BFLeaveReason reason) +void WorldSession::SendBfLeaveMessage(uint32 battleId, BFLeaveReason reason) { WorldPacket data(SMSG_BATTLEFIELD_MGR_EJECTED, 7); - data << uint32(BattleId); - data << uint8(reason);//byte Reason - data << uint8(2);//byte BattleStatus - data << uint8(0);//bool Relocated + data << uint32(battleId); + data << uint8(reason); // byte Reason + data << uint8(2); // byte BattleStatus + data << uint8(0); // bool Relocated SendPacket(&data); } -//Send by client when he click on accept for queue +// Sent by client when they click accept for queue void WorldSession::HandleBfQueueInviteResponse(WorldPacket& recvData) { - uint32 BattleId; - uint8 Accepted; + uint32 battleId; + uint8 accepted; - recvData >> BattleId >> Accepted; + recvData >> battleId >> accepted; - Battlefield* Bf = sBattlefieldMgr->GetBattlefieldByBattleId(BattleId); - if (!Bf) + Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId); + if (!bf) return; - if (Accepted) - { - Bf->PlayerAcceptInviteToQueue(_player); - } + if (accepted) + bf->PlayerAcceptInviteToQueue(_player); } -//Send by client on clicking in accept or refuse of invitation windows for join game +// Sent by client on clicking accept or refuse of invitation window to join game void WorldSession::HandleBfEntryInviteResponse(WorldPacket& recvData) { - uint32 BattleId; - uint8 Accepted; + uint32 battleId; + uint8 accepted; - recvData >> BattleId >> Accepted; + recvData >> battleId >> accepted; - Battlefield* Bf = sBattlefieldMgr->GetBattlefieldByBattleId(BattleId); - if (!Bf) + Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId); + if (!bf) return; - //If player accept invitation - if (Accepted) - { - Bf->PlayerAcceptInviteToWar(_player); - } + if (accepted) + bf->PlayerAcceptInviteToWar(_player); else { - if (_player->GetZoneId() == Bf->GetZoneId()) - Bf->KickPlayerFromBattlefield(_player->GetGUID()); + if (_player->GetZoneId() == bf->GetZoneId()) + bf->KickPlayerFromBattlefield(_player->GetGUID()); } } void WorldSession::HandleBfExitRequest(WorldPacket& recvData) { - uint32 BattleId; + uint32 battleId; - recvData >> BattleId; + recvData >> battleId; - Battlefield* Bf = sBattlefieldMgr->GetBattlefieldByBattleId(BattleId); - if (!Bf) + Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId); + if (!bf) return; - Bf->AskToLeaveQueue(_player); + bf->AskToLeaveQueue(_player); } diff --git a/src/server/game/Battlefield/BattlefieldMgr.cpp b/src/server/game/Battlefield/BattlefieldMgr.cpp index 3993d0bc7..dcf60edb7 100644 --- a/src/server/game/Battlefield/BattlefieldMgr.cpp +++ b/src/server/game/Battlefield/BattlefieldMgr.cpp @@ -19,17 +19,14 @@ #include "Player.h" #include "Zones/BattlefieldWG.h" -BattlefieldMgr::BattlefieldMgr() +BattlefieldMgr::BattlefieldMgr() : _updateTimer(0) { - m_UpdateTimer = 0; - //LOG_DEBUG("bg.battlefield", "Instantiating BattlefieldMgr"); } BattlefieldMgr::~BattlefieldMgr() { - //LOG_DEBUG("bg.battlefield", "Deleting BattlefieldMgr"); - for (BattlefieldSet::iterator itr = m_BattlefieldSet.begin(); itr != m_BattlefieldSet.end(); ++itr) - delete *itr; + for (Battlefield* bf : _battlefieldSet) + delete bf; } BattlefieldMgr* BattlefieldMgr::instance() @@ -46,107 +43,89 @@ void BattlefieldMgr::InitBattlefield() LOG_INFO("server.loading", " "); return; } - Battlefield* pBf = new BattlefieldWG; + Battlefield* bf = new BattlefieldWG; // respawn, init variables - if (!pBf->SetupBattlefield()) + if (!bf->SetupBattlefield()) { LOG_ERROR("server.loading", "Battlefield: Wintergrasp init failed."); LOG_INFO("server.loading", " "); - delete pBf; + delete bf; } else { - m_BattlefieldSet.push_back(pBf); + _battlefieldSet.push_back(bf); LOG_INFO("server.loading", "Battlefield: Wintergrasp successfully initiated."); LOG_INFO("server.loading", " "); } - - /* For Cataclysm: Tol Barad - pBf = new BattlefieldTB; - // respawn, init variables - if (!pBf->SetupBattlefield()) - { - LOG_DEBUG("bg.battlefield", "Battlefield : Tol Barad init failed."); - delete pBf; - } - else - { - m_BattlefieldSet.push_back(pBf); - LOG_DEBUG("bg.battlefield", "Battlefield : Tol Barad successfully initiated."); - } */ } -void BattlefieldMgr::AddZone(uint32 zoneid, Battlefield* handle) +void BattlefieldMgr::AddZone(uint32 zoneId, Battlefield* handle) { - m_BattlefieldMap[zoneid] = handle; + _battlefieldMap[zoneId] = handle; } -void BattlefieldMgr::HandlePlayerEnterZone(Player* player, uint32 zoneid) +void BattlefieldMgr::HandlePlayerEnterZone(Player* player, uint32 zoneId) { - BattlefieldMap::iterator itr = m_BattlefieldMap.find(zoneid); - if (itr == m_BattlefieldMap.end()) + auto itr = _battlefieldMap.find(zoneId); + if (itr == _battlefieldMap.end()) return; if (itr->second->HasPlayer(player) || !itr->second->IsEnabled()) return; - itr->second->HandlePlayerEnterZone(player, zoneid); + itr->second->HandlePlayerEnterZone(player, zoneId); LOG_DEBUG("bg.battlefield", "Player {} entered outdoorpvp id {}", player->GetGUID().ToString(), itr->second->GetTypeId()); } -void BattlefieldMgr::HandlePlayerLeaveZone(Player* player, uint32 zoneid) +void BattlefieldMgr::HandlePlayerLeaveZone(Player* player, uint32 zoneId) { - BattlefieldMap::iterator itr = m_BattlefieldMap.find(zoneid); - if (itr == m_BattlefieldMap.end()) + auto itr = _battlefieldMap.find(zoneId); + if (itr == _battlefieldMap.end()) return; // teleport: remove once in removefromworld, once in updatezone if (!itr->second->HasPlayer(player)) return; - itr->second->HandlePlayerLeaveZone(player, zoneid); + itr->second->HandlePlayerLeaveZone(player, zoneId); LOG_DEBUG("bg.battlefield", "Player {} left outdoorpvp id {}", player->GetGUID().ToString(), itr->second->GetTypeId()); } -Battlefield* BattlefieldMgr::GetBattlefieldToZoneId(uint32 zoneid) +Battlefield* BattlefieldMgr::GetBattlefieldToZoneId(uint32 zoneId) { - BattlefieldMap::iterator itr = m_BattlefieldMap.find(zoneid); - if (itr == m_BattlefieldMap.end()) - { - // no handle for this zone, return + auto itr = _battlefieldMap.find(zoneId); + if (itr == _battlefieldMap.end()) return nullptr; - } + if (!itr->second->IsEnabled()) return nullptr; return itr->second; } -Battlefield* BattlefieldMgr::GetBattlefieldByBattleId(uint32 battleid) +Battlefield* BattlefieldMgr::GetBattlefieldByBattleId(uint32 battleId) { - for (BattlefieldSet::iterator itr = m_BattlefieldSet.begin(); itr != m_BattlefieldSet.end(); ++itr) - { - if ((*itr)->GetBattleId() == battleid) - return (*itr); - } + for (Battlefield* bf : _battlefieldSet) + if (bf->GetBattleId() == battleId) + return bf; + return nullptr; } void BattlefieldMgr::Update(uint32 diff) { - m_UpdateTimer += diff; - if (m_UpdateTimer > BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL) + _updateTimer += diff; + if (_updateTimer > BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL) { - for (BattlefieldSet::iterator itr = m_BattlefieldSet.begin(); itr != m_BattlefieldSet.end(); ++itr) - //if ((*itr)->IsEnabled()) - (*itr)->Update(m_UpdateTimer); - m_UpdateTimer = 0; + for (Battlefield* bf : _battlefieldSet) + bf->Update(_updateTimer); + _updateTimer = 0; } } ZoneScript* BattlefieldMgr::GetZoneScript(uint32 zoneId) { - BattlefieldMap::iterator itr = m_BattlefieldMap.find(zoneId); - if (itr != m_BattlefieldMap.end()) + auto itr = _battlefieldMap.find(zoneId); + if (itr != _battlefieldMap.end()) return itr->second; - else - return nullptr; + + return nullptr; } diff --git a/src/server/game/Battlefield/BattlefieldMgr.h b/src/server/game/Battlefield/BattlefieldMgr.h index 3cb79d355..c15bfa2cc 100644 --- a/src/server/game/Battlefield/BattlefieldMgr.h +++ b/src/server/game/Battlefield/BattlefieldMgr.h @@ -30,48 +30,47 @@ struct GossipMenuItems; class BattlefieldMgr { public: - // ctor BattlefieldMgr(); - // dtor ~BattlefieldMgr(); static BattlefieldMgr* instance(); // create battlefield events void InitBattlefield(); - // called when a player enters an battlefield area + // called when a player enters a battlefield area void HandlePlayerEnterZone(Player* player, uint32 areaflag); - // called when player leaves an battlefield area + // called when player leaves a battlefield area void HandlePlayerLeaveZone(Player* player, uint32 areaflag); // called when player resurrects void HandlePlayerResurrects(Player* player, uint32 areaflag); // return assigned battlefield - Battlefield* GetBattlefieldToZoneId(uint32 zoneid); - Battlefield* GetBattlefieldByBattleId(uint32 battleid); + Battlefield* GetBattlefieldToZoneId(uint32 zoneId); + Battlefield* GetBattlefieldByBattleId(uint32 battleId); ZoneScript* GetZoneScript(uint32 zoneId); - void AddZone(uint32 zoneid, Battlefield* handle); + void AddZone(uint32 zoneId, Battlefield* handle); void Update(uint32 diff); - void HandleGossipOption(Player* player, ObjectGuid guid, uint32 gossipid); + void HandleGossipOption(Player* player, ObjectGuid guid, uint32 gossipId); bool CanTalkTo(Player* player, Creature* creature, GossipMenuItems gso); void HandleDropFlag(Player* player, uint32 spellId); - typedef std::vector < Battlefield* >BattlefieldSet; - typedef std::map < uint32 /* zoneid */, Battlefield* >BattlefieldMap; + using BattlefieldSet = std::vector; + using BattlefieldMap = std::map; + private: // contains all initiated battlefield events // used when initing / cleaning up - BattlefieldSet m_BattlefieldSet; - // maps the zone ids to an battlefield event + BattlefieldSet _battlefieldSet; + // maps the zone ids to a battlefield event // used in player event handling - BattlefieldMap m_BattlefieldMap; + BattlefieldMap _battlefieldMap; // update interval - uint32 m_UpdateTimer; + uint32 _updateTimer; }; #define sBattlefieldMgr BattlefieldMgr::instance() diff --git a/src/server/game/Battlefield/Zones/BattlefieldWG.cpp b/src/server/game/Battlefield/Zones/BattlefieldWG.cpp index 64ddbecf1..2478162d7 100644 --- a/src/server/game/Battlefield/Zones/BattlefieldWG.cpp +++ b/src/server/game/Battlefield/Zones/BattlefieldWG.cpp @@ -36,47 +36,48 @@ BattlefieldWG::~BattlefieldWG() { - for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr) - delete *itr; + for (WGWorkshop* workshop : WorkshopsList) + delete workshop; - for (GameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr) - delete *itr; + for (BfWGGameObjectBuilding* building : BuildingsInZone) + delete building; } bool BattlefieldWG::SetupBattlefield() { - m_TypeId = BATTLEFIELD_WG; // See enum BattlefieldTypes - m_BattleId = BATTLEFIELD_BATTLEID_WG; - m_ZoneId = AREA_WINTERGRASP; - m_MapId = MAP_NORTHREND; - m_Map = sMapMgr->FindMap(m_MapId, 0); + TypeId = BATTLEFIELD_WG; // See enum BattlefieldTypes + BattleId = BATTLEFIELD_BATTLEID_WG; + ZoneId = AREA_WINTERGRASP; + MapId = MAP_NORTHREND; + BfMap = sMapMgr->FindMap(MapId, 0); // init stalker AFTER setting map id... we spawn it at map=random memory value?... InitStalker(BATTLEFIELD_WG_NPC_STALKER, WintergraspStalkerPos[0], WintergraspStalkerPos[1], WintergraspStalkerPos[2], WintergraspStalkerPos[3]); - m_MaxPlayer = sWorld->getIntConfig(CONFIG_WINTERGRASP_PLR_MAX); - m_IsEnabled = sWorld->getIntConfig(CONFIG_WINTERGRASP_ENABLE) == 1; - m_MinPlayer = sWorld->getIntConfig(CONFIG_WINTERGRASP_PLR_MIN); - m_MinLevel = sWorld->getIntConfig(CONFIG_WINTERGRASP_PLR_MIN_LVL); - m_BattleTime = sWorld->getIntConfig(CONFIG_WINTERGRASP_BATTLETIME) * MINUTE * IN_MILLISECONDS; - m_NoWarBattleTime = sWorld->getIntConfig(CONFIG_WINTERGRASP_NOBATTLETIME) * MINUTE * IN_MILLISECONDS; - m_RestartAfterCrash = sWorld->getIntConfig(CONFIG_WINTERGRASP_RESTART_AFTER_CRASH) * MINUTE * IN_MILLISECONDS; + MaxPlayer = sWorld->getIntConfig(CONFIG_WINTERGRASP_PLR_MAX); + Enabled = sWorld->getIntConfig(CONFIG_WINTERGRASP_ENABLE) == 1; + MinPlayer = sWorld->getIntConfig(CONFIG_WINTERGRASP_PLR_MIN); + MinLevel = sWorld->getIntConfig(CONFIG_WINTERGRASP_PLR_MIN_LVL); + BattleTime = sWorld->getIntConfig(CONFIG_WINTERGRASP_BATTLETIME) * MINUTE * IN_MILLISECONDS; + NoWarBattleTime = sWorld->getIntConfig(CONFIG_WINTERGRASP_NOBATTLETIME) * MINUTE * IN_MILLISECONDS; + RestartAfterCrash = sWorld->getIntConfig(CONFIG_WINTERGRASP_RESTART_AFTER_CRASH) * MINUTE * IN_MILLISECONDS; - m_TimeForAcceptInvite = 20; - m_StartGroupingTimer = 15 * MINUTE * IN_MILLISECONDS; - m_StartGrouping = false; + TimeForAcceptInvite = 20; + StartGroupingTimer = 15 * MINUTE * IN_MILLISECONDS; + StartGrouping = false; - m_tenacityStack = 0; - m_titansRelic.Clear(); + TenacityStack = 0; + TitansRelic.Clear(); + IsRelicInteractible = false; KickPosition.Relocate(5728.117f, 2714.346f, 697.733f, 0); - KickPosition.m_mapId = m_MapId; + KickPosition.m_mapId = MapId; - RegisterZone(m_ZoneId); + RegisterZone(ZoneId); - m_Data32.resize(BATTLEFIELD_WG_DATA_MAX); + Data32.resize(BATTLEFIELD_WG_DATA_MAX); - m_saveTimer = 60000; + SaveTimer = 60000; // Init Graveyards SetGraveyardNumber(BATTLEFIELD_WG_GRAVEYARD_MAX); @@ -88,17 +89,17 @@ bool BattlefieldWG::SetupBattlefield() { sWorldState->setWorldState(WORLD_STATE_BATTLEFIELD_WG_ACTIVE, uint64(false)); sWorldState->setWorldState(WORLD_STATE_BATTLEFIELD_WG_DEFENDER, uint64(urand(0, 1))); - sWorldState->setWorldState(ClockWorldState[0], uint64(m_NoWarBattleTime)); + sWorldState->setWorldState(ClockWorldState[0], uint64(NoWarBattleTime)); } - m_isActive = bool(sWorldState->getWorldState(WORLD_STATE_BATTLEFIELD_WG_ACTIVE)); - m_DefenderTeam = TeamId(sWorldState->getWorldState(WORLD_STATE_BATTLEFIELD_WG_DEFENDER)); + Active = bool(sWorldState->getWorldState(WORLD_STATE_BATTLEFIELD_WG_ACTIVE)); + DefenderTeam = TeamId(sWorldState->getWorldState(WORLD_STATE_BATTLEFIELD_WG_DEFENDER)); - m_Timer = sWorldState->getWorldState(ClockWorldState[0]); - if (m_isActive) + Timer = sWorldState->getWorldState(ClockWorldState[0]); + if (Active) { - m_isActive = false; - m_Timer = m_RestartAfterCrash; + Active = false; + Timer = RestartAfterCrash; } for (uint8 i = 0; i < BATTLEFIELD_WG_GRAVEYARD_MAX; i++) @@ -107,12 +108,12 @@ bool BattlefieldWG::SetupBattlefield() // When between games, the graveyard is controlled by the defending team if (WGGraveyard[i].startcontrol == TEAM_NEUTRAL) - graveyard->Initialize(WGGraveyard[i].gyid == BATTLEFIELD_WG_GY_WORKSHOP_SE || WGGraveyard[i].gyid == BATTLEFIELD_WG_GY_WORKSHOP_SW ? GetAttackerTeam() : m_DefenderTeam, WGGraveyard[i].gyid); + graveyard->Initialize(WGGraveyard[i].gyid == BATTLEFIELD_WG_GY_WORKSHOP_SE || WGGraveyard[i].gyid == BATTLEFIELD_WG_GY_WORKSHOP_SW ? GetAttackerTeam() : DefenderTeam, WGGraveyard[i].gyid); else graveyard->Initialize(WGGraveyard[i].startcontrol, WGGraveyard[i].gyid); graveyard->SetTextId(WGGraveyard[i].textid); - m_GraveyardList[i] = graveyard; + GraveyardList[i] = graveyard; } // Spawn workshop creatures and gameobjects @@ -140,8 +141,8 @@ bool BattlefieldWG::SetupBattlefield() } // Hide NPCs from the Attacker's team in the keep - for (GuidUnorderedSet::const_iterator itr = KeepCreature[GetAttackerTeam()].begin(); itr != KeepCreature[GetAttackerTeam()].end(); ++itr) - if (Creature* creature = GetCreature(*itr)) + for (ObjectGuid const& guid : KeepCreature[GetAttackerTeam()]) + if (Creature* creature = GetCreature(guid)) HideNpc(creature); // Spawn Horde NPCs outside the keep @@ -155,8 +156,8 @@ bool BattlefieldWG::SetupBattlefield() OutsideCreature[TEAM_ALLIANCE].insert(creature->GetGUID()); // Hide units outside the keep that are defenders - for (GuidUnorderedSet::const_iterator itr = OutsideCreature[GetDefenderTeam()].begin(); itr != OutsideCreature[GetDefenderTeam()].end(); ++itr) - if (Creature* creature = GetCreature(*itr)) + for (ObjectGuid const& guid : OutsideCreature[GetDefenderTeam()]) + if (Creature* creature = GetCreature(guid)) HideNpc(creature); // Spawn turrets and hide them per default @@ -193,32 +194,32 @@ bool BattlefieldWG::SetupBattlefield() bool BattlefieldWG::Update(uint32 diff) { - bool m_return = Battlefield::Update(diff); - if (m_saveTimer <= diff) + bool result = Battlefield::Update(diff); + if (SaveTimer <= diff) { - sWorldState->setWorldState(WORLD_STATE_BATTLEFIELD_WG_ACTIVE, m_isActive); - sWorldState->setWorldState(WORLD_STATE_BATTLEFIELD_WG_DEFENDER, m_DefenderTeam); - sWorldState->setWorldState(ClockWorldState[0], m_Timer); - m_saveTimer = 60 * IN_MILLISECONDS; + sWorldState->setWorldState(WORLD_STATE_BATTLEFIELD_WG_ACTIVE, Active); + sWorldState->setWorldState(WORLD_STATE_BATTLEFIELD_WG_DEFENDER, DefenderTeam); + sWorldState->setWorldState(ClockWorldState[0], Timer); + SaveTimer = 60 * IN_MILLISECONDS; } else - m_saveTimer -= diff; + SaveTimer -= diff; // Update Tenacity if (IsWarTime()) { - if (m_tenacityUpdateTimer <= diff) + if (TenacityUpdateTimer <= diff) { - m_tenacityUpdateTimer = 10000; - if (!m_updateTenacityList.empty()) + TenacityUpdateTimer = 10000; + if (!UpdateTenacityList.empty()) UpdateTenacity(); - m_updateTenacityList.clear(); + UpdateTenacityList.clear(); } else - m_tenacityUpdateTimer -= diff; + TenacityUpdateTimer -= diff; } - return m_return; + return result; } void BattlefieldWG::OnBattleStart() @@ -233,15 +234,15 @@ void BattlefieldWG::OnBattleStart() go->SetGameObjectFlag(GO_FLAG_NOT_SELECTABLE); // save guid - m_titansRelic = go->GetGUID(); + TitansRelic = go->GetGUID(); } else LOG_ERROR("bg.battlefield", "WG: Failed to spawn titan relic."); // Update tower visibility and update faction - for (GuidUnorderedSet::const_iterator itr = CanonList.begin(); itr != CanonList.end(); ++itr) + for (ObjectGuid const& guid : CanonList) { - if (Creature* creature = GetCreature(*itr)) + if (Creature* creature = GetCreature(guid)) { ShowNpc(creature, true); creature->SetFaction(WintergraspFaction[GetDefenderTeam()]); @@ -249,12 +250,12 @@ void BattlefieldWG::OnBattleStart() } // Rebuild all wall - for (GameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr) + for (BfWGGameObjectBuilding* building : BuildingsInZone) { - if (*itr) + if (building) { - (*itr)->Rebuild(); - (*itr)->UpdateTurretAttack(false); + building->Rebuild(); + building->UpdateTurretAttack(false); } } @@ -263,20 +264,20 @@ void BattlefieldWG::OnBattleStart() SetData(BATTLEFIELD_WG_DATA_DAMAGED_TOWER_ATT, 0); // Update graveyard (in no war time all graveyard is to deffender, in war time, depend of base) - for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr) - if (*itr) - (*itr)->UpdateGraveyardAndWorkshop(); + for (WGWorkshop* workshop : WorkshopsList) + if (workshop) + workshop->UpdateGraveyardAndWorkshop(); // Set Sliders capture points data to his owners when battle start - for (BfCapturePointVector::const_iterator itr = m_capturePoints.begin(); itr != m_capturePoints.end(); ++itr) - (*itr)->SetCapturePointData((*itr)->GetCapturePointGo(), - (*itr)->GetCapturePointGo()->GetEntry() == GO_WINTERGRASP_FACTORY_BANNER_SE || (*itr)->GetCapturePointGo()->GetEntry() == GO_WINTERGRASP_FACTORY_BANNER_SW ? GetAttackerTeam() : GetDefenderTeam()); + for (BfCapturePoint* capturePoint : CapturePoints) + capturePoint->SetCapturePointData(capturePoint->GetCapturePointGo(), + capturePoint->GetCapturePointGo()->GetEntry() == GO_WINTERGRASP_FACTORY_BANNER_SE || capturePoint->GetCapturePointGo()->GetEntry() == GO_WINTERGRASP_FACTORY_BANNER_SW ? GetAttackerTeam() : GetDefenderTeam()); for (uint8 team = 0; team < 2; ++team) - for (GuidUnorderedSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr) + for (ObjectGuid const& guid : Players[team]) { // Kick player in orb room, TODO: offline player ? - if (Player* player = ObjectAccessor::FindPlayer(*itr)) + if (Player* player = ObjectAccessor::FindPlayer(guid)) { float x, y, z; player->GetPosition(x, y, z); @@ -291,8 +292,8 @@ void BattlefieldWG::OnBattleStart() SendWarning(BATTLEFIELD_WG_TEXT_START); // Xinef: reset tenacity counter - m_tenacityStack = 0; - m_tenacityUpdateTimer = 20000; + TenacityStack = 0; + TenacityUpdateTimer = 20000; if (sWorld->getBoolConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_ENABLE)) ChatHandler(nullptr).SendWorldText(BATTLEFIELD_WG_WORLD_START_MESSAGE); @@ -308,9 +309,9 @@ void BattlefieldWG::UpdateCounterVehicle(bool init) SetData(BATTLEFIELD_WG_DATA_MAX_VEHICLE_H, 0); SetData(BATTLEFIELD_WG_DATA_MAX_VEHICLE_A, 0); - for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr) + for (WGWorkshop* workshop : WorkshopsList) { - if (WGWorkshop* workshop = (*itr)) + if (workshop) { if (workshop->teamControl == TEAM_ALLIANCE) UpdateData(BATTLEFIELD_WG_DATA_MAX_VEHICLE_A, 4); @@ -326,8 +327,8 @@ void BattlefieldWG::UpdateCounterVehicle(bool init) void BattlefieldWG::UpdateVehicleCountWG() { for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i) - for (GuidUnorderedSet::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) + for (ObjectGuid const& guid : Players[i]) + if (Player* player = ObjectAccessor::FindPlayer(guid)) { player->SendUpdateWorldState(WORLD_STATE_BATTLEFIELD_WG_VEHICLE_H, GetData(BATTLEFIELD_WG_DATA_VEHICLE_H)); player->SendUpdateWorldState(WORLD_STATE_BATTLEFIELD_WG_MAX_VEHICLE_H, GetData(BATTLEFIELD_WG_DATA_MAX_VEHICLE_H)); @@ -339,8 +340,8 @@ void BattlefieldWG::UpdateVehicleCountWG() void BattlefieldWG::CapturePointTaken(uint32 areaId) { for (uint8 i = 0; i < PVP_TEAMS_COUNT; ++i) - for (GuidUnorderedSet::iterator itr = m_players[i].begin(); itr != m_players[i].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) + for (ObjectGuid const& guid : Players[i]) + if (Player* player = ObjectAccessor::FindPlayer(guid)) if (player->GetAreaId() == areaId) player->UpdateAreaDependentAuras(areaId); } @@ -351,12 +352,12 @@ void BattlefieldWG::OnBattleEnd(bool endByTimer) if (GameObject* go = GetRelic()) go->RemoveFromWorld(); - m_titansRelic.Clear(); + TitansRelic.Clear(); // Remove turret - for (GuidUnorderedSet::const_iterator itr = CanonList.begin(); itr != CanonList.end(); ++itr) + for (ObjectGuid const& guid : CanonList) { - if (Creature* creature = GetCreature(*itr)) + if (Creature* creature = GetCreature(guid)) { if (!endByTimer) creature->SetFaction(WintergraspFaction[GetDefenderTeam()]); @@ -365,21 +366,21 @@ void BattlefieldWG::OnBattleEnd(bool endByTimer) } // Change all npc in keep - for (GuidUnorderedSet::const_iterator itr = KeepCreature[GetAttackerTeam()].begin(); itr != KeepCreature[GetAttackerTeam()].end(); ++itr) - if (Creature* creature = GetCreature(*itr)) + for (ObjectGuid const& guid : KeepCreature[GetAttackerTeam()]) + if (Creature* creature = GetCreature(guid)) HideNpc(creature); - for (GuidUnorderedSet::const_iterator itr = KeepCreature[GetDefenderTeam()].begin(); itr != KeepCreature[GetDefenderTeam()].end(); ++itr) - if (Creature* creature = GetCreature(*itr)) + for (ObjectGuid const& guid : KeepCreature[GetDefenderTeam()]) + if (Creature* creature = GetCreature(guid)) ShowNpc(creature, true); // Change all npc out of keep - for (GuidUnorderedSet::const_iterator itr = OutsideCreature[GetDefenderTeam()].begin(); itr != OutsideCreature[GetDefenderTeam()].end(); ++itr) - if (Creature* creature = GetCreature(*itr)) + for (ObjectGuid const& guid : OutsideCreature[GetDefenderTeam()]) + if (Creature* creature = GetCreature(guid)) HideNpc(creature); - for (GuidUnorderedSet::const_iterator itr = OutsideCreature[GetAttackerTeam()].begin(); itr != OutsideCreature[GetAttackerTeam()].end(); ++itr) - if (Creature* creature = GetCreature(*itr)) + for (ObjectGuid const& guid : OutsideCreature[GetAttackerTeam()]) + if (Creature* creature = GetCreature(guid)) ShowNpc(creature, true); // Update all graveyard, control is to defender when no wartime @@ -387,37 +388,37 @@ void BattlefieldWG::OnBattleEnd(bool endByTimer) if (BfGraveyard* graveyard = GetGraveyardById(i)) graveyard->GiveControlTo(i == BATTLEFIELD_WG_GY_WORKSHOP_SE || i == BATTLEFIELD_WG_GY_WORKSHOP_SW ? GetAttackerTeam() : GetDefenderTeam()); - for (GameObjectSet::const_iterator itr = m_KeepGameObject[GetDefenderTeam()].begin(); itr != m_KeepGameObject[GetDefenderTeam()].end(); ++itr) - (*itr)->SetRespawnTime(RESPAWN_IMMEDIATELY); + for (GameObject* go : KeepGameObject[GetDefenderTeam()]) + go->SetRespawnTime(RESPAWN_IMMEDIATELY); - for (GameObjectSet::const_iterator itr = m_KeepGameObject[GetAttackerTeam()].begin(); itr != m_KeepGameObject[GetAttackerTeam()].end(); ++itr) - (*itr)->SetRespawnTime(RESPAWN_ONE_DAY); + for (GameObject* go : KeepGameObject[GetAttackerTeam()]) + go->SetRespawnTime(RESPAWN_ONE_DAY); // Update portal defender faction - for (GameObjectSet::const_iterator itr = DefenderPortalList.begin(); itr != DefenderPortalList.end(); ++itr) - (*itr)->SetUInt32Value(GAMEOBJECT_FACTION, WintergraspFaction[GetDefenderTeam()]); + for (GameObject* go : DefenderPortalList) + go->SetUInt32Value(GAMEOBJECT_FACTION, WintergraspFaction[GetDefenderTeam()]); // Saving data - for (GameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr) + for (BfWGGameObjectBuilding* building : BuildingsInZone) { - (*itr)->Rebuild(); - (*itr)->Save(); - (*itr)->UpdateTurretAttack(true); + building->Rebuild(); + building->Save(); + building->UpdateTurretAttack(true); } - for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr) + for (WGWorkshop* workshop : WorkshopsList) { - (*itr)->GiveControlTo((*itr)->workshopId == BATTLEFIELD_WG_WORKSHOP_SE || (*itr)->workshopId == BATTLEFIELD_WG_WORKSHOP_SW ? GetAttackerTeam() : GetDefenderTeam(), true); - (*itr)->Save(); + workshop->GiveControlTo(workshop->workshopId == BATTLEFIELD_WG_WORKSHOP_SE || workshop->workshopId == BATTLEFIELD_WG_WORKSHOP_SW ? GetAttackerTeam() : GetDefenderTeam(), true); + workshop->Save(); } for (uint8 team = 0; team < 2; ++team) { - for (GuidUnorderedSet::const_iterator itr = m_vehicles[team].begin(); itr != m_vehicles[team].end(); ++itr) - if (Creature* creature = GetCreature(*itr)) + for (ObjectGuid const& guid : Vehicles[team]) + if (Creature* creature = GetCreature(guid)) creature->DespawnOrUnsummon(1ms); - m_vehicles[team].clear(); + Vehicles[team].clear(); } uint8 damagedTowersDef = GetData(BATTLEFIELD_WG_DATA_DAMAGED_TOWER_ATT); @@ -439,9 +440,9 @@ void BattlefieldWG::OnBattleEnd(bool endByTimer) spellFullAtt = SPELL_DESTROYED_TOWER; } - for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[GetDefenderTeam()].begin(); itr != m_PlayersInWar[GetDefenderTeam()].end(); ++itr) + for (ObjectGuid const& guid : PlayersInWar[GetDefenderTeam()]) { - if (Player* player = ObjectAccessor::FindPlayer(*itr)) + if (Player* player = ObjectAccessor::FindPlayer(guid)) { // Victory in Wintergrasp player->AreaExploredOrEventHappens(GetDefenderTeam() ? 13183 : 13181); // HORDE / ALLY win wg quest id @@ -457,8 +458,8 @@ void BattlefieldWG::OnBattleEnd(bool endByTimer) } } - for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[GetAttackerTeam()].begin(); itr != m_PlayersInWar[GetAttackerTeam()].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) + for (ObjectGuid const& guid : PlayersInWar[GetAttackerTeam()]) + if (Player* player = ObjectAccessor::FindPlayer(guid)) { player->CastSpell(player, SPELL_DEFEAT_REWARD, true); RemoveAurasFromPlayer(player); @@ -473,20 +474,20 @@ void BattlefieldWG::OnBattleEnd(bool endByTimer) { for (uint8 team = 0; team < 2; ++team) { - for (GuidUnorderedSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr) + for (ObjectGuid const& guid : Players[team]) { - if (Player* player = ObjectAccessor::FindPlayer(*itr)) + if (Player* player = ObjectAccessor::FindPlayer(guid)) { - player->RemoveAurasDueToSpell(m_DefenderTeam == TEAM_ALLIANCE ? SPELL_HORDE_CONTROL_PHASE_SHIFT : SPELL_ALLIANCE_CONTROL_PHASE_SHIFT, player->GetGUID()); - player->AddAura(m_DefenderTeam == TEAM_HORDE ? SPELL_HORDE_CONTROL_PHASE_SHIFT : SPELL_ALLIANCE_CONTROL_PHASE_SHIFT, player); + player->RemoveAurasDueToSpell(DefenderTeam == TEAM_ALLIANCE ? SPELL_HORDE_CONTROL_PHASE_SHIFT : SPELL_ALLIANCE_CONTROL_PHASE_SHIFT, player->GetGUID()); + player->AddAura(DefenderTeam == TEAM_HORDE ? SPELL_HORDE_CONTROL_PHASE_SHIFT : SPELL_ALLIANCE_CONTROL_PHASE_SHIFT, player); } } } } // Clear players in war list at the end. - m_PlayersInWar[TEAM_ALLIANCE].clear(); - m_PlayersInWar[TEAM_HORDE].clear(); + PlayersInWar[TEAM_ALLIANCE].clear(); + PlayersInWar[TEAM_HORDE].clear(); if (!endByTimer) // win alli/horde { @@ -504,10 +505,6 @@ void BattlefieldWG::OnBattleEnd(bool endByTimer) } } -// ******************************************************* -// ******************* Reward System ********************* -// ******************************************************* - void BattlefieldWG::OnStartGrouping() { if (!IsWarTime()) @@ -571,8 +568,8 @@ void BattlefieldWG::OnCreatureCreate(Creature* creature) if (creature->IsWithinDist2d(5103.0f, 3461.5f, 5.0f)) graveyardId = BATTLEFIELD_WG_GY_WORKSHOP_NW; - if (m_GraveyardList[graveyardId]) - m_GraveyardList[graveyardId]->SetSpirit(creature, teamId); + if (GraveyardList[graveyardId]) + GraveyardList[graveyardId]->SetSpirit(creature, teamId); break; } } @@ -601,7 +598,7 @@ void BattlefieldWG::OnCreatureCreate(Creature* creature) { UpdateData(BATTLEFIELD_WG_DATA_VEHICLE_H, 1); creature->CastSpell(creature, SPELL_HORDE_FLAG, true); - m_vehicles[team].insert(creature->GetGUID()); + Vehicles[team].insert(creature->GetGUID()); UpdateVehicleCountWG(); } else @@ -616,7 +613,7 @@ void BattlefieldWG::OnCreatureCreate(Creature* creature) { UpdateData(BATTLEFIELD_WG_DATA_VEHICLE_A, 1); creature->CastSpell(creature, SPELL_ALLIANCE_FLAG, true); - m_vehicles[team].insert(creature->GetGUID()); + Vehicles[team].insert(creature->GetGUID()); UpdateVehicleCountWG(); } else @@ -661,7 +658,7 @@ void BattlefieldWG::OnCreatureRemove(Creature* /*creature*/) else return; - m_vehicles[team].erase(creature->GetGUID()); + Vehicles[team].erase(creature->GetGUID()); if (team == TEAM_HORDE) UpdateData(BATTLEFIELD_WG_DATA_VEHICLE_H, -1); else @@ -696,9 +693,9 @@ void BattlefieldWG::OnGameObjectCreate(GameObject* go) return; } - for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr) + for (WGWorkshop* workshop : WorkshopsList) { - if (WGWorkshop* workshop = (*itr)) + if (workshop) { if (workshop->workshopId == workshopId) { @@ -729,7 +726,7 @@ void BattlefieldWG::HandleKill(Player* killer, Unit* victim) if (victim->IsPlayer() && victim->HasAura(SPELL_LIEUTENANT)) { // Quest - Wintergrasp - PvP Kill - Horde/Alliance - for (auto& playerGuid : m_PlayersInWar[killerTeam]) + for (ObjectGuid const& playerGuid : PlayersInWar[killerTeam]) { if (Player* player = ObjectAccessor::FindPlayer(playerGuid)) { @@ -741,7 +738,7 @@ void BattlefieldWG::HandleKill(Player* killer, Unit* victim) } } - for (auto& playerGuid : m_PlayersInWar[killerTeam]) + for (ObjectGuid const& playerGuid : PlayersInWar[killerTeam]) { if (Player* player = ObjectAccessor::FindPlayer(playerGuid)) { @@ -761,7 +758,7 @@ void BattlefieldWG::HandleKill(Player* killer, Unit* victim) else if (victim->IsVehicle() && !killer->IsFriendlyTo(victim)) { // Quest - Wintergrasp - PvP Kill - Vehicle - for (auto& playerGuid : m_PlayersInWar[killerTeam]) + for (ObjectGuid const& playerGuid : PlayersInWar[killerTeam]) { if (Player* player = ObjectAccessor::FindPlayer(playerGuid)) { @@ -776,12 +773,12 @@ void BattlefieldWG::HandleKill(Player* killer, Unit* victim) bool BattlefieldWG::FindAndRemoveVehicleFromList(Unit* vehicle) { - for (uint32 itr = 0; itr < 2; ++itr) + for (uint32 i = 0; i < 2; ++i) { - if (m_vehicles[itr].find(vehicle->GetGUID()) != m_vehicles[itr].end()) + if (Vehicles[i].find(vehicle->GetGUID()) != Vehicles[i].end()) { - //m_vehicles[itr].erase(vehicle->GetGUID()); - if (itr == TEAM_HORDE) + //Vehicles[i].erase(vehicle->GetGUID()); + if (i == TEAM_HORDE) UpdateData(BATTLEFIELD_WG_DATA_VEHICLE_H, -1); else UpdateData(BATTLEFIELD_WG_DATA_VEHICLE_A, -1); @@ -802,7 +799,7 @@ void BattlefieldWG::OnUnitDeath(Unit* unit) // Update rank for player void BattlefieldWG::PromotePlayer(Player* killer) { - if (!m_isActive) + if (!Active) return; // Updating rank of player if (Aura* recruitAura = killer->GetAura(SPELL_RECRUIT)) @@ -890,7 +887,7 @@ void BattlefieldWG::OnPlayerLeaveWar(Player* player) void BattlefieldWG::OnPlayerLeaveZone(Player* player) { - if (!m_isActive) + if (!Active) RemoveAurasFromPlayer(player); player->RemoveAurasDueToSpell(SPELL_HORDE_CONTROLS_FACTORY_PHASE_SHIFT); @@ -901,10 +898,10 @@ void BattlefieldWG::OnPlayerLeaveZone(Player* player) void BattlefieldWG::OnPlayerEnterZone(Player* player) { - if (!m_isActive) + if (!Active) RemoveAurasFromPlayer(player); - player->AddAura(m_DefenderTeam == TEAM_HORDE ? SPELL_HORDE_CONTROL_PHASE_SHIFT : SPELL_ALLIANCE_CONTROL_PHASE_SHIFT, player); + player->AddAura(DefenderTeam == TEAM_HORDE ? SPELL_HORDE_CONTROL_PHASE_SHIFT : SPELL_ALLIANCE_CONTROL_PHASE_SHIFT, player); // Send worldstate to player SendInitWorldStatesTo(player); @@ -949,7 +946,7 @@ void BattlefieldWG::FillInitialWorldStates(WorldPackets::WorldState::InitWorldSt // Note: cleanup these two, their names look awkward packet.Worldstates.emplace_back(WORLD_STATE_BATTLEFIELD_WG_ACTIVE, IsWarTime() ? 0 : 1); packet.Worldstates.emplace_back(WORLD_STATE_BATTLEFIELD_WG_SHOW, IsWarTime() ? 1 : 0); - packet.Worldstates.emplace_back(WORLD_STATE_BATTLEFIELD_WG_CONTROL, m_DefenderTeam == TEAM_ALLIANCE ? 2 : 1); // Alliance 2, Hord 1 + packet.Worldstates.emplace_back(WORLD_STATE_BATTLEFIELD_WG_CONTROL, DefenderTeam == TEAM_ALLIANCE ? 2 : 1); // Alliance 2, Hord 1 packet.Worldstates.emplace_back(WORLD_STATE_BATTLEFIELD_WG_ICON_ACTIVE, iconActive ? 1 : 0); for (uint32 i = 0; i < 2; ++i) @@ -965,19 +962,19 @@ void BattlefieldWG::FillInitialWorldStates(WorldPackets::WorldState::InitWorldSt packet.Worldstates.emplace_back(WORLD_STATE_BATTLEFIELD_WG_HORDE_KEEP_DEFENDED, uint32(sWorldState->getWorldState(WORLD_STATE_BATTLEFIELD_WG_HORDE_KEEP_DEFENDED))); packet.Worldstates.emplace_back(WORLD_STATE_BATTLEFIELD_WG_ALLIANCE_KEEP_CAPTURED, uint32(sWorldState->getWorldState(WORLD_STATE_BATTLEFIELD_WG_ALLIANCE_KEEP_CAPTURED))); - for (GameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr) - packet.Worldstates.emplace_back((*itr)->m_WorldState, (*itr)->m_State); + for (BfWGGameObjectBuilding* building : BuildingsInZone) + packet.Worldstates.emplace_back(building->m_WorldState, building->m_State); - for (Workshop::const_iterator itr = WorkshopsList.begin(); itr != WorkshopsList.end(); ++itr) - if (*itr) - packet.Worldstates.emplace_back(WorkshopsData[(*itr)->workshopId].worldstate, (*itr)->state); + for (WGWorkshop* workshop : WorkshopsList) + if (workshop) + packet.Worldstates.emplace_back(WorkshopsData[workshop->workshopId].worldstate, workshop->state); } void BattlefieldWG::SendInitWorldStatesTo(Player* player) { WorldPackets::WorldState::InitWorldStates packet; - packet.MapID = m_MapId; - packet.ZoneID = m_ZoneId; + packet.MapID = MapId; + packet.ZoneID = ZoneId; packet.AreaID = player->GetAreaId(); FillInitialWorldStates(packet); @@ -987,8 +984,8 @@ void BattlefieldWG::SendInitWorldStatesTo(Player* player) void BattlefieldWG::SendInitWorldStatesToAll() { for (uint8 team = 0; team < 2; team++) - for (GuidUnorderedSet::iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) + for (ObjectGuid const& guid : Players[team]) + if (Player* player = ObjectAccessor::FindPlayer(guid)) SendInitWorldStatesTo(player); } @@ -1025,9 +1022,9 @@ void BattlefieldWG::BrokenWallOrTower(TeamId /*team*/) // might be some use for this in the future. old code commented out below. KL /* if (team == GetDefenderTeam()) { - for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[GetAttackerTeam()].begin(); itr != m_PlayersInWar[GetAttackerTeam()].end(); ++itr) + for (ObjectGuid const& guid : PlayersInWar[GetAttackerTeam()]) { - if (Player* player = ObjectAccessor::FindPlayer(*itr)) + if (Player* player = ObjectAccessor::FindPlayer(guid)) IncrementQuest(player, WGQuest[player->GetTeamId()][2], true); } }*/ @@ -1044,13 +1041,13 @@ void BattlefieldWG::UpdatedDestroyedTowerCount(TeamId team, GameObject* go) UpdateData(BATTLEFIELD_WG_DATA_BROKEN_TOWER_ATT, 1); // Remove buff stack on attackers - for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[GetAttackerTeam()].begin(); itr != m_PlayersInWar[GetAttackerTeam()].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) + for (ObjectGuid const& guid : PlayersInWar[GetAttackerTeam()]) + if (Player* player = ObjectAccessor::FindPlayer(guid)) player->RemoveAuraFromStack(SPELL_TOWER_CONTROL); // Add buff stack to defenders - for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[GetDefenderTeam()].begin(); itr != m_PlayersInWar[GetDefenderTeam()].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) + for (ObjectGuid const& guid : PlayersInWar[GetDefenderTeam()]) + if (Player* player = ObjectAccessor::FindPlayer(guid)) { // Quest - Wintergrasp - Southern Tower Kill if (go && player->GetDistance2d(go) < 200.0f) @@ -1063,18 +1060,18 @@ void BattlefieldWG::UpdatedDestroyedTowerCount(TeamId team, GameObject* go) // If all three south towers are destroyed (ie. all attack towers), remove ten minutes from battle time if (GetData(BATTLEFIELD_WG_DATA_BROKEN_TOWER_ATT) == 3) { - if (int32(m_Timer - 600000) < 0) - m_Timer = 0; + if (int32(Timer - 600000) < 0) + Timer = 0; else - m_Timer -= 600000; + Timer -= 600000; SendInitWorldStatesToAll(); } } else { // Xinef: rest of structures, quest credit - for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[GetAttackerTeam()].begin(); itr != m_PlayersInWar[GetAttackerTeam()].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) + for (ObjectGuid const& guid : PlayersInWar[GetAttackerTeam()]) + if (Player* player = ObjectAccessor::FindPlayer(guid)) { // Quest - Wintergrasp - Vehicle Protected if (go && player->GetDistance2d(go) < 100.0f) @@ -1107,17 +1104,17 @@ void BattlefieldWG::ProcessEvent(WorldObject* obj, uint32 eventId) } // if destroy or damage event, search the wall/tower and update worldstate/send warning message - for (GameObjectBuilding::const_iterator itr = BuildingsInZone.begin(); itr != BuildingsInZone.end(); ++itr) + for (BfWGGameObjectBuilding* building : BuildingsInZone) { - if (GameObject* build = ObjectAccessor::GetGameObject(*obj, (*itr)->m_Build)) + if (GameObject* build = ObjectAccessor::GetGameObject(*obj, building->m_Build)) { if (go->GetEntry() == build->GetEntry()) { if (build->GetGOInfo()->building.damagedEvent == eventId) - (*itr)->Damaged(); + building->Damaged(); if (build->GetGOInfo()->building.destroyedEvent == eventId) - (*itr)->Destroyed(); + building->Destroyed(); break; } @@ -1148,20 +1145,20 @@ uint32 BattlefieldWG::GetHonorBuff(int32 stack) const void BattlefieldWG::AddUpdateTenacity(Player* player) { - m_updateTenacityList.insert(player->GetGUID()); + UpdateTenacityList.insert(player->GetGUID()); } void BattlefieldWG::RemoveUpdateTenacity(Player* player) { - m_updateTenacityList.erase(player->GetGUID()); - m_updateTenacityList.insert(ObjectGuid::Empty); + UpdateTenacityList.erase(player->GetGUID()); + UpdateTenacityList.insert(ObjectGuid::Empty); } void BattlefieldWG::UpdateTenacity() { TeamId team = TEAM_NEUTRAL; - uint32 alliancePlayers = m_PlayersInWar[TEAM_ALLIANCE].size(); - uint32 hordePlayers = m_PlayersInWar[TEAM_HORDE].size(); + uint32 alliancePlayers = PlayersInWar[TEAM_ALLIANCE].size(); + uint32 hordePlayers = PlayersInWar[TEAM_HORDE].size(); int32 newStack = 0; if (alliancePlayers && hordePlayers) @@ -1173,11 +1170,11 @@ void BattlefieldWG::UpdateTenacity() } // Return if no change in stack and apply tenacity to new player - if (newStack == m_tenacityStack) + if (newStack == TenacityStack) { - for (GuidUnorderedSet::const_iterator itr = m_updateTenacityList.begin(); itr != m_updateTenacityList.end(); ++itr) - if (Player* newPlayer = ObjectAccessor::FindPlayer(*itr)) - if ((newPlayer->GetTeamId() == TEAM_ALLIANCE && m_tenacityStack > 0) || (newPlayer->GetTeamId() == TEAM_HORDE && m_tenacityStack < 0)) + for (ObjectGuid const& guid : UpdateTenacityList) + if (Player* newPlayer = ObjectAccessor::FindPlayer(guid)) + if ((newPlayer->GetTeamId() == TEAM_ALLIANCE && TenacityStack > 0) || (newPlayer->GetTeamId() == TEAM_HORDE && TenacityStack < 0)) { newStack = std::min(std::abs(newStack), 20); uint32 buff_honor = GetHonorBuff(newStack); @@ -1188,24 +1185,24 @@ void BattlefieldWG::UpdateTenacity() return; } - if (m_tenacityStack != 0) + if (TenacityStack != 0) { - if (m_tenacityStack > 0 && newStack <= 0) // old buff was on alliance + if (TenacityStack > 0 && newStack <= 0) // old buff was on alliance team = TEAM_ALLIANCE; - else if (m_tenacityStack < 0 && newStack >= 0) // old buff was on horde + else if (TenacityStack < 0 && newStack >= 0) // old buff was on horde team = TEAM_HORDE; } - m_tenacityStack = newStack; + TenacityStack = newStack; // Remove old buff if (team != TEAM_NEUTRAL) { - for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) + for (ObjectGuid const& guid : PlayersInWar[team]) + if (Player* player = ObjectAccessor::FindPlayer(guid)) player->RemoveAurasDueToSpell(SPELL_TENACITY); - for (GuidUnorderedSet::const_iterator itr = m_vehicles[team].begin(); itr != m_vehicles[team].end(); ++itr) - if (Creature* creature = GetCreature(*itr)) + for (ObjectGuid const& guid : Vehicles[team]) + if (Creature* creature = GetCreature(guid)) creature->RemoveAurasDueToSpell(SPELL_TENACITY_VEHICLE); } @@ -1216,16 +1213,16 @@ void BattlefieldWG::UpdateTenacity() newStack = std::min(std::abs(newStack), 20); uint32 buff_honor = GetHonorBuff(newStack); - for (GuidUnorderedSet::const_iterator itr = m_PlayersInWar[team].begin(); itr != m_PlayersInWar[team].end(); ++itr) - if (Player* player = ObjectAccessor::FindPlayer(*itr)) + for (ObjectGuid const& guid : PlayersInWar[team]) + if (Player* player = ObjectAccessor::FindPlayer(guid)) { player->SetAuraStack(SPELL_TENACITY, player, newStack); if (buff_honor) player->CastSpell(player, buff_honor, true); } - for (GuidUnorderedSet::const_iterator itr = m_vehicles[team].begin(); itr != m_vehicles[team].end(); ++itr) - if (Creature* creature = GetCreature(*itr)) + for (ObjectGuid const& guid : Vehicles[team]) + if (Creature* creature = GetCreature(guid)) { creature->SetAuraStack(SPELL_TENACITY_VEHICLE, creature, newStack); if (buff_honor) @@ -1236,19 +1233,19 @@ void BattlefieldWG::UpdateTenacity() WintergraspCapturePoint::WintergraspCapturePoint(BattlefieldWG* battlefield, TeamId teamInControl) : BfCapturePoint(battlefield) { - m_Bf = battlefield; - m_team = teamInControl; - m_Workshop = nullptr; + Bf = battlefield; + Team = teamInControl; + LinkedWorkshop = nullptr; } void WintergraspCapturePoint::ChangeTeam(TeamId /*oldTeam*/) { - ASSERT(m_Workshop); - m_Workshop->GiveControlTo(m_team, false); + ASSERT(LinkedWorkshop); + LinkedWorkshop->GiveControlTo(Team, false); } BfGraveyardWG::BfGraveyardWG(BattlefieldWG* battlefield) : BfGraveyard(battlefield) { - m_Bf = battlefield; - m_GossipTextId = 0; + Bf = battlefield; + GossipTextId = 0; } diff --git a/src/server/game/Battlefield/Zones/BattlefieldWG.h b/src/server/game/Battlefield/Zones/BattlefieldWG.h index ae0f0b371..58d39e55f 100644 --- a/src/server/game/Battlefield/Zones/BattlefieldWG.h +++ b/src/server/game/Battlefield/Zones/BattlefieldWG.h @@ -32,11 +32,11 @@ class WintergraspCapturePoint; struct BfWGGameObjectBuilding; struct WGWorkshop; -typedef std::set GameObjectSet; -typedef std::set GameObjectBuilding; -typedef std::set Workshop; -typedef std::set GroupSet; -//typedef std::set CapturePointSet; unused ? +using GameObjectSet = std::set; +using GameObjectBuilding = std::set; +using Workshop = std::set; +using GroupSet = std::set; +//using CapturePointSet = std::set; unused ? uint32 const VehNumWorldState[2] = { WORLD_STATE_BATTLEFIELD_WG_VEHICLE_A, WORLD_STATE_BATTLEFIELD_WG_VEHICLE_H }; uint32 const MaxVehNumWorldState[2] = { WORLD_STATE_BATTLEFIELD_WG_MAX_VEHICLE_A, WORLD_STATE_BATTLEFIELD_WG_MAX_VEHICLE_H }; @@ -110,10 +110,10 @@ class BfGraveyardWG : public BfGraveyard public: BfGraveyardWG(BattlefieldWG* Bf); - void SetTextId(uint32 textid) { m_GossipTextId = textid; } - uint32 GetTextId() { return m_GossipTextId; } + void SetTextId(uint32 textid) { GossipTextId = textid; } + uint32 GetTextId() const { return GossipTextId; } protected: - uint32 m_GossipTextId; + uint32 GossipTextId; }; enum WGGraveyardId @@ -236,13 +236,13 @@ class WintergraspCapturePoint : public BfCapturePoint public: WintergraspCapturePoint(BattlefieldWG* battlefield, TeamId teamInControl); - void LinkToWorkshop(WGWorkshop* workshop) { m_Workshop = workshop; } + void LinkToWorkshop(WGWorkshop* workshop) { LinkedWorkshop = workshop; } void ChangeTeam(TeamId oldteam) override; - TeamId GetTeam() const { return m_team; } + TeamId GetTeam() const { return Team; } protected: - WGWorkshop* m_Workshop; + WGWorkshop* LinkedWorkshop; }; /* ######################### * @@ -363,16 +363,16 @@ public: bool SetupBattlefield() override; /// Return pointer to relic object - GameObject* GetRelic() { return GetGameObject(m_titansRelic); } + GameObject* GetRelic() { return GetGameObject(TitansRelic); } /// Define relic object - //void SetRelic(GameObject* relic) { m_titansRelic = relic; } + //void SetRelic(GameObject* relic) { TitansRelic = relic; } /// Check if players can interact with the relic (Only if the last door has been broken) - bool CanInteractWithRelic() { return m_isRelicInteractible; } + bool CanInteractWithRelic() { return IsRelicInteractible; } /// Define if player can interact with the relic - void SetRelicInteractible(bool allow) { m_isRelicInteractible = allow; } + void SetRelicInteractible(bool allow) { IsRelicInteractible = allow; } /// Vehicle world states update void UpdateCounterVehicle(bool init); @@ -434,25 +434,25 @@ public: return false; } protected: - bool m_isRelicInteractible; + bool IsRelicInteractible; Workshop WorkshopsList; GameObjectSet DefenderPortalList; - GameObjectSet m_KeepGameObject[2]; + GameObjectSet KeepGameObject[2]; GameObjectBuilding BuildingsInZone; - GuidUnorderedSet m_vehicles[2]; + GuidUnorderedSet Vehicles[2]; GuidUnorderedSet CanonList; GuidUnorderedSet KeepCreature[2]; GuidUnorderedSet OutsideCreature[2]; - GuidUnorderedSet m_updateTenacityList; + GuidUnorderedSet UpdateTenacityList; - int32 m_tenacityStack; - uint32 m_tenacityUpdateTimer; - uint32 m_saveTimer; + int32 TenacityStack; + uint32 TenacityUpdateTimer; + uint32 SaveTimer; - ObjectGuid m_titansRelic; + ObjectGuid TitansRelic; }; uint8 const WG_MAX_OBJ = 32; @@ -558,10 +558,7 @@ struct WintergraspObjectPositionData uint32 entryAlliance; }; -// ***************************************************** -// ************ Destructible (Wall,Tower..) ************ -// ***************************************************** - +// Destructible buildings (walls, towers, etc.) struct WintergraspBuildingSpawnData { uint32 entry; @@ -748,10 +745,7 @@ WintergraspTeleporterData const WGPortalDefenderData[WG_MAX_TELEPORTER] = { 192951, 5316.25f, 2977.04f, 408.539f, -0.820f }, }; -// ********************************************************* -// **********Tower Element(GameObject,Creature)************* -// ********************************************************* - +// Tower elements (GameObjects and Creatures) struct WintergraspTowerData { uint32 towerEntry; // Gameobject id of tower @@ -1022,10 +1016,7 @@ WintergraspTowerCannonData const TowerCannon[WG_MAX_TOWER_CANNON] = }, }; -// ********************************************************* -// *****************WorkShop Data & Element***************** -// ********************************************************* - +// Workshop data and elements uint8 const WG_MAX_WORKSHOP = 6; struct WGWorkshopData @@ -1052,10 +1043,9 @@ WGWorkshopData const WorkshopsData[WG_MAX_WORKSHOP] = {BATTLEFIELD_WG_WORKSHOP_KEEP_EAST, WORLD_STATE_BATTLEFIELD_WG_WORKSHOP_K_E, 0, BATTLEFIELD_WG_TEXT_WORKSHOP_NE_TAKEN} }; -// ******************************************************************** -// * Structs using for Building,Graveyard,Workshop * -// ******************************************************************** -// Structure for different buildings that can be destroyed during battle +// Structs for Building, Graveyard, and Workshop runtime objects + +// Buildings that can be destroyed during battle struct BfWGGameObjectBuilding { BfWGGameObjectBuilding(BattlefieldWG* WG)