[7372] Cleanup BattleGround::GetClosestGraveYard related code.

This commit is contained in:
VladimirMangos 2009-03-02 15:35:41 +03:00
parent f454ddf6d0
commit 9983286280
8 changed files with 41 additions and 29 deletions

View file

@ -409,20 +409,21 @@ void BattleGroundAB::_NodeDeOccupied(uint8 node)
if( !ghost_list.empty() )
{
WorldSafeLocsEntry const *ClosestGrave = NULL;
Player *plr;
for (std::vector<uint64>::const_iterator itr = ghost_list.begin(); itr != ghost_list.end(); ++itr)
{
plr = objmgr.GetPlayer(*itr);
if( !plr )
Player* plr = objmgr.GetPlayer(*itr);
if (!plr)
continue;
if( !ClosestGrave )
ClosestGrave = GetClosestGraveYard(plr->GetPositionX(), plr->GetPositionY(), plr->GetPositionZ(), plr->GetTeam());
plr->TeleportTo(GetMapId(), ClosestGrave->x, ClosestGrave->y, ClosestGrave->z, plr->GetOrientation());
if (!ClosestGrave) // cache
ClosestGrave = GetClosestGraveYard(plr);
if (ClosestGrave)
plr->TeleportTo(GetMapId(), ClosestGrave->x, ClosestGrave->y, ClosestGrave->z, plr->GetOrientation());
}
}
if( m_BgCreatures[node] )
if( m_BgCreatures[node] )
DelCreature(node);
// buff object isn't despawned
@ -603,9 +604,9 @@ void BattleGroundAB::Reset()
DelCreature(i);
}
WorldSafeLocsEntry const* BattleGroundAB::GetClosestGraveYard(float x, float y, float /*z*/, uint32 team)
WorldSafeLocsEntry const* BattleGroundAB::GetClosestGraveYard(Player* player)
{
uint8 teamIndex = GetTeamIndexByTeamId(team);
uint8 teamIndex = GetTeamIndexByTeamId(player->GetTeam());
// Is there any occupied node for this team?
std::vector<uint8> nodes;
@ -617,13 +618,16 @@ WorldSafeLocsEntry const* BattleGroundAB::GetClosestGraveYard(float x, float y,
// If so, select the closest node to place ghost on
if( !nodes.empty() )
{
float plr_x = player->GetPositionX();
float plr_y = player->GetPositionY();
float mindist = 999999.0f;
for (uint8 i = 0; i < nodes.size(); ++i)
{
WorldSafeLocsEntry const*entry = sWorldSafeLocsStore.LookupEntry( BG_AB_GraveyardIds[nodes[i]] );
if( !entry )
continue;
float dist = (entry->x - x)*(entry->x - x)+(entry->y - y)*(entry->y - y);
float dist = (entry->x - plr_x)*(entry->x - plr_x)+(entry->y - plr_y)*(entry->y - plr_y);
if( mindist > dist )
{
mindist = dist;