Core/Battlefield: Cleanup of Wintergrasp script and battlefield system:

- Standards: Moved all statics to cpps where they belong.
- Changed spawn position container from fixed size array to std::vector (not all positions were used in every case)
- Removed unused parameter teamId from Battlefield::SpawnCreature
- Removed workaround for GO rotation, added in a69cbeb9d5
- Added rotation parameter to Battlefield:SpawnGameObject
- Added sniffed rotation to existing script spawns.
- Implemented Archavon's Log (Closes #16880)
This commit is contained in:
ariel-
2016-08-20 21:40:43 -03:00
parent eb9bf314c4
commit 1deb7d2df1
5 changed files with 576 additions and 686 deletions

View File

@@ -39,7 +39,7 @@ Battlefield::Battlefield()
m_TypeId = 0;
m_BattleId = 0;
m_ZoneId = 0;
m_Map = NULL;
m_Map = nullptr;
m_MapId = 0;
m_MaxPlayer = 0;
m_MinPlayer = 0;
@@ -79,7 +79,7 @@ void Battlefield::HandlePlayerEnterZone(Player* player, uint32 /*zone*/)
else // No more vacant places
{
/// @todo Send a packet to announce it to player
m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = time(NULL) + 10;
m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = time(nullptr) + 10;
InvitePlayerToQueue(player);
}
}
@@ -158,14 +158,14 @@ bool Battlefield::Update(uint32 diff)
// Kick players who chose not to accept invitation to the battle
if (m_uiKickDontAcceptTimer <= diff)
{
time_t now = time(NULL);
for (int team = 0; team < 2; team++)
time_t now = time(nullptr);
for (uint8 team = 0; team < BG_TEAMS_COUNT; ++team)
for (PlayerTimerMap::iterator itr = m_InvitedPlayers[team].begin(); itr != m_InvitedPlayers[team].end(); ++itr)
if (itr->second <= now)
KickPlayerFromBattlefield(itr->first);
InvitePlayersInZoneToWar();
for (int team = 0; team < 2; team++)
for (uint8 team = 0; team < BG_TEAMS_COUNT; ++team)
for (PlayerTimerMap::iterator itr = m_PlayersWillBeKick[team].begin(); itr != m_PlayersWillBeKick[team].end(); ++itr)
if (itr->second <= now)
KickPlayerFromBattlefield(itr->first);
@@ -196,7 +196,7 @@ bool Battlefield::Update(uint32 diff)
void Battlefield::InvitePlayersInZoneToQueue()
{
for (uint8 team = 0; team < 2; ++team)
for (uint8 team = 0; team < BG_TEAMS_COUNT; ++team)
for (GuidSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr)
if (Player* player = ObjectAccessor::FindPlayer(*itr))
InvitePlayerToQueue(player);
@@ -243,7 +243,7 @@ void Battlefield::InvitePlayersInZoneToWar()
if (m_PlayersInWar[player->GetTeamId()].size() + m_InvitedPlayers[player->GetTeamId()].size() < m_MaxPlayer)
InvitePlayerToWar(player);
else // Battlefield is full of players
m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = time(NULL) + 10;
m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = time(nullptr) + 10;
}
}
}
@@ -267,7 +267,7 @@ void Battlefield::InvitePlayerToWar(Player* player)
if (player->getLevel() < m_MinLevel)
{
if (m_PlayersWillBeKick[player->GetTeamId()].count(player->GetGUID()) == 0)
m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = time(NULL) + 10;
m_PlayersWillBeKick[player->GetTeamId()][player->GetGUID()] = time(nullptr) + 10;
return;
}
@@ -276,13 +276,13 @@ void Battlefield::InvitePlayerToWar(Player* player)
return;
m_PlayersWillBeKick[player->GetTeamId()].erase(player->GetGUID());
m_InvitedPlayers[player->GetTeamId()][player->GetGUID()] = time(NULL) + m_TimeForAcceptInvite;
m_InvitedPlayers[player->GetTeamId()][player->GetGUID()] = time(nullptr) + m_TimeForAcceptInvite;
player->GetSession()->SendBfInvitePlayerToWar(m_BattleId, m_ZoneId, m_TimeForAcceptInvite);
}
void Battlefield::InitStalker(uint32 entry, Position const& pos)
{
if (Creature* creature = SpawnCreature(entry, pos, TEAM_NEUTRAL))
if (Creature* creature = SpawnCreature(entry, pos))
StalkerGuid = creature->GetGUID();
else
TC_LOG_ERROR("bg.battlefield", "Battlefield::InitStalker: Could not spawn Stalker (Creature entry %u), zone messages will be unavailable!", entry);
@@ -309,7 +309,7 @@ void Battlefield::StartBattle()
if (m_isActive)
return;
for (int team = 0; team < BG_TEAMS_COUNT; team++)
for (uint8 team = 0; team < BG_TEAMS_COUNT; ++team)
{
m_PlayersInWar[team].clear();
m_Groups[team].clear();
@@ -487,7 +487,7 @@ Group* Battlefield::GetFreeBfRaid(TeamId TeamId)
if (!group->IsFull())
return group;
return NULL;
return nullptr;
}
Group* Battlefield::GetGroupPlayer(ObjectGuid guid, TeamId TeamId)
@@ -497,7 +497,7 @@ Group* Battlefield::GetGroupPlayer(ObjectGuid guid, TeamId TeamId)
if (group->IsMember(guid))
return group;
return NULL;
return nullptr;
}
bool Battlefield::AddOrSetPlayerToCorrectBfGroup(Player* player)
@@ -549,12 +549,12 @@ BfGraveyard* Battlefield::GetGraveyardById(uint32 id) const
else
TC_LOG_ERROR("bg.battlefield", "Battlefield::GetGraveyardById Id:%u could not be found.", id);
return NULL;
return nullptr;
}
WorldSafeLocsEntry const* Battlefield::GetClosestGraveYard(Player* player)
{
BfGraveyard* closestGY = NULL;
BfGraveyard* closestGY = nullptr;
float maxdist = -1;
for (uint8 i = 0; i < m_GraveyardList.size(); i++)
{
@@ -575,7 +575,7 @@ WorldSafeLocsEntry const* Battlefield::GetClosestGraveYard(Player* player)
if (closestGY)
return sWorldSafeLocsStore.LookupEntry(closestGY->GetGraveyardId());
return NULL;
return nullptr;
}
void Battlefield::AddPlayerToResurrectQueue(ObjectGuid npcGuid, ObjectGuid playerGuid)
@@ -625,8 +625,6 @@ BfGraveyard::BfGraveyard(Battlefield* battlefield)
m_Bf = battlefield;
m_GraveyardId = 0;
m_ControlTeam = TEAM_NEUTRAL;
m_SpiritGuide[0].Clear();
m_SpiritGuide[1].Clear();
}
void BfGraveyard::Initialize(TeamId startControl, uint32 graveyardId)
@@ -649,7 +647,7 @@ void BfGraveyard::SetSpirit(Creature* spirit, TeamId team)
float BfGraveyard::GetDistance(Player* player)
{
const WorldSafeLocsEntry* safeLoc = sWorldSafeLocsStore.LookupEntry(m_GraveyardId);
WorldSafeLocsEntry const* safeLoc = sWorldSafeLocsStore.LookupEntry(m_GraveyardId);
return player->GetDistance2d(safeLoc->x, safeLoc->y);
}
@@ -718,7 +716,7 @@ void BfGraveyard::GiveControlTo(TeamId team)
void BfGraveyard::RelocateDeadPlayers()
{
WorldSafeLocsEntry const* closestGrave = NULL;
WorldSafeLocsEntry const* closestGrave = nullptr;
for (GuidSet::const_iterator itr = m_ResurrectQueue.begin(); itr != m_ResurrectQueue.end(); ++itr)
{
Player* player = ObjectAccessor::FindPlayer(*itr);
@@ -738,14 +736,14 @@ void BfGraveyard::RelocateDeadPlayers()
bool BfGraveyard::HasNpc(ObjectGuid guid)
{
if (!m_SpiritGuide[0] || !m_SpiritGuide[1])
if (!m_SpiritGuide[TEAM_ALLIANCE] || !m_SpiritGuide[TEAM_HORDE])
return false;
if (!m_Bf->GetCreature(m_SpiritGuide[0]) ||
!m_Bf->GetCreature(m_SpiritGuide[1]))
if (!m_Bf->GetCreature(m_SpiritGuide[TEAM_ALLIANCE]) ||
!m_Bf->GetCreature(m_SpiritGuide[TEAM_HORDE]))
return false;
return (m_SpiritGuide[0] == guid || m_SpiritGuide[1] == guid);
return (m_SpiritGuide[TEAM_ALLIANCE] == guid || m_SpiritGuide[TEAM_HORDE] == guid);
}
// *******************************************************
@@ -754,12 +752,7 @@ bool BfGraveyard::HasNpc(ObjectGuid guid)
// ********************** Misc ***************************
// *******************************************************
Creature* Battlefield::SpawnCreature(uint32 entry, Position const& pos, TeamId teamId)
{
return SpawnCreature(entry, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation(), teamId);
}
Creature* Battlefield::SpawnCreature(uint32 entry, float x, float y, float z, float o, TeamId /*teamId*/)
Creature* Battlefield::SpawnCreature(uint32 entry, Position const& pos)
{
//Get map object
Map* map = sMapMgr->CreateBaseMap(m_MapId);
@@ -769,6 +762,9 @@ Creature* Battlefield::SpawnCreature(uint32 entry, float x, float y, float z, fl
return nullptr;
}
float x, y, z, o;
pos.GetPosition(x, y, z, o);
Creature* creature = new Creature();
if (!creature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map, PHASEMASK_NORMAL, entry, x, y, z, o))
{
@@ -779,13 +775,6 @@ Creature* Battlefield::SpawnCreature(uint32 entry, float x, float y, float z, fl
creature->SetHomePosition(x, y, z, o);
CreatureTemplate const* cinfo = sObjectMgr->GetCreatureTemplate(entry);
if (!cinfo)
{
TC_LOG_ERROR("bg.battlefield", "Battlefield::SpawnCreature: Entry %u does not exist.", entry);
return nullptr;
}
// Set creature in world
map->AddToMap(creature);
creature->setActive(true);
@@ -794,19 +783,16 @@ Creature* Battlefield::SpawnCreature(uint32 entry, float x, float y, float z, fl
}
// Method for spawning gameobject on map
GameObject* Battlefield::SpawnGameObject(uint32 entry, float x, float y, float z, float o)
GameObject* Battlefield::SpawnGameObject(uint32 entry, Position const& pos, G3D::Quat const& rot)
{
// Get map object
Map* map = sMapMgr->CreateBaseMap(m_MapId);
if (!map)
return 0;
// Calculate rotation
G3D::Quat rot = G3D::Matrix3::fromEulerAnglesZYX(o, 0.f, 0.f);
return nullptr;
// Create gameobject
GameObject* go = new GameObject;
if (!go->Create(map->GenerateLowGuid<HighGuid::GameObject>(), entry, map, PHASEMASK_NORMAL, Position(x, y, z, o), rot, 255, GO_STATE_READY))
if (!go->Create(map->GenerateLowGuid<HighGuid::GameObject>(), entry, map, PHASEMASK_NORMAL, pos, rot, 255, GO_STATE_READY))
{
TC_LOG_ERROR("bg.battlefield", "Battlefield::SpawnGameObject: Gameobject template %u could not be found in the database! Battlefield has not been created!", entry);
TC_LOG_ERROR("bg.battlefield", "Battlefield::SpawnGameObject: Could not create gameobject template %u! Battlefield has not been created!", entry);
@@ -824,14 +810,14 @@ GameObject* Battlefield::SpawnGameObject(uint32 entry, float x, float y, float z
Creature* Battlefield::GetCreature(ObjectGuid guid)
{
if (!m_Map)
return NULL;
return nullptr;
return m_Map->GetCreature(guid);
}
GameObject* Battlefield::GetGameObject(ObjectGuid guid)
{
if (!m_Map)
return NULL;
return nullptr;
return m_Map->GetGameObject(guid);
}
@@ -947,7 +933,7 @@ bool BfCapturePoint::DelCapturePoint()
{
capturePoint->SetRespawnTime(0); // not save respawn time
capturePoint->Delete();
capturePoint = NULL;
capturePoint = nullptr;
}
m_capturePointGUID.Clear();
}
@@ -964,7 +950,7 @@ bool BfCapturePoint::Update(uint32 diff)
{
float radius = capturePoint->GetGOInfo()->capturePoint.radius;
for (uint8 team = 0; team < 2; ++team)
for (uint8 team = 0; team < BG_TEAMS_COUNT; ++team)
{
for (GuidSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end();)
{
@@ -992,7 +978,7 @@ bool BfCapturePoint::Update(uint32 diff)
}
// get the difference of numbers
float fact_diff = ((float) m_activePlayers[0].size() - (float) m_activePlayers[1].size()) * diff / BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL;
float fact_diff = ((float) m_activePlayers[TEAM_ALLIANCE].size() - (float) m_activePlayers[TEAM_HORDE].size()) * diff / BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL;
if (G3D::fuzzyEq(fact_diff, 0.0f))
return false;
@@ -1079,7 +1065,7 @@ bool BfCapturePoint::Update(uint32 diff)
void BfCapturePoint::SendUpdateWorldState(uint32 field, uint32 value)
{
for (uint8 team = 0; team < 2; ++team)
for (uint8 team = 0; team < BG_TEAMS_COUNT; ++team)
for (GuidSet::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))
player->SendUpdateWorldState(field, value);
@@ -1091,10 +1077,10 @@ void BfCapturePoint::SendObjectiveComplete(uint32 id, ObjectGuid guid)
switch (m_State)
{
case BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE:
team = 0;
team = TEAM_ALLIANCE;
break;
case BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE:
team = 1;
team = TEAM_HORDE;
break;
default:
return;