[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

@ -1514,3 +1514,8 @@ void BattleGround::SetBgRaid( uint32 TeamID, Group *bg_raid )
if(bg_raid) bg_raid->SetBattlegroundGroup(this); if(bg_raid) bg_raid->SetBattlegroundGroup(this);
old_raid = bg_raid; old_raid = bg_raid;
} }
WorldSafeLocsEntry const* BattleGround::GetClosestGraveYard( Player* player )
{
return objmgr.GetClosestGraveYard( player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), player->GetTeam() );
}

View file

@ -426,7 +426,7 @@ class BattleGround
virtual void EventPlayerCapturedFlag(Player* /*player*/) {} virtual void EventPlayerCapturedFlag(Player* /*player*/) {}
/* Death related */ /* Death related */
virtual WorldSafeLocsEntry const* GetClosestGraveYard(float /*x*/, float /*y*/, float /*z*/, uint32 /*team*/) { return NULL; } virtual WorldSafeLocsEntry const* GetClosestGraveYard(Player* player);
virtual void AddPlayer(Player *plr); // must be implemented in BG subclass virtual void AddPlayer(Player *plr); // must be implemented in BG subclass

View file

@ -409,20 +409,21 @@ void BattleGroundAB::_NodeDeOccupied(uint8 node)
if( !ghost_list.empty() ) if( !ghost_list.empty() )
{ {
WorldSafeLocsEntry const *ClosestGrave = NULL; WorldSafeLocsEntry const *ClosestGrave = NULL;
Player *plr;
for (std::vector<uint64>::const_iterator itr = ghost_list.begin(); itr != ghost_list.end(); ++itr) for (std::vector<uint64>::const_iterator itr = ghost_list.begin(); itr != ghost_list.end(); ++itr)
{ {
plr = objmgr.GetPlayer(*itr); Player* plr = objmgr.GetPlayer(*itr);
if( !plr ) if (!plr)
continue; 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); DelCreature(node);
// buff object isn't despawned // buff object isn't despawned
@ -603,9 +604,9 @@ void BattleGroundAB::Reset()
DelCreature(i); 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? // Is there any occupied node for this team?
std::vector<uint8> nodes; 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 so, select the closest node to place ghost on
if( !nodes.empty() ) if( !nodes.empty() )
{ {
float plr_x = player->GetPositionX();
float plr_y = player->GetPositionY();
float mindist = 999999.0f; float mindist = 999999.0f;
for (uint8 i = 0; i < nodes.size(); ++i) for (uint8 i = 0; i < nodes.size(); ++i)
{ {
WorldSafeLocsEntry const*entry = sWorldSafeLocsStore.LookupEntry( BG_AB_GraveyardIds[nodes[i]] ); WorldSafeLocsEntry const*entry = sWorldSafeLocsStore.LookupEntry( BG_AB_GraveyardIds[nodes[i]] );
if( !entry ) if( !entry )
continue; 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 ) if( mindist > dist )
{ {
mindist = dist; mindist = dist;

View file

@ -242,7 +242,7 @@ class BattleGroundAB : public BattleGround
void HandleAreaTrigger(Player *Source, uint32 Trigger); void HandleAreaTrigger(Player *Source, uint32 Trigger);
virtual bool SetupBattleGround(); virtual bool SetupBattleGround();
virtual void Reset(); virtual void Reset();
virtual WorldSafeLocsEntry const* GetClosestGraveYard(float x, float y, float z, uint32 team); virtual WorldSafeLocsEntry const* GetClosestGraveYard(Player* player);
/* Scorekeeping */ /* Scorekeeping */
virtual void UpdatePlayerScore(Player *Source, uint32 type, uint32 value); virtual void UpdatePlayerScore(Player *Source, uint32 type, uint32 value);

View file

@ -885,16 +885,16 @@ void BattleGroundEY::FillInitialWorldStates(WorldPacket& data)
data << uint32(0xc0d) << uint32(0x17b); data << uint32(0xc0d) << uint32(0x17b);
} }
WorldSafeLocsEntry const *BattleGroundEY::GetClosestGraveYard(float x, float y, float z, uint32 team) WorldSafeLocsEntry const *BattleGroundEY::GetClosestGraveYard(Player* player)
{ {
uint32 g_id = 0; uint32 g_id = 0;
if(team == ALLIANCE) switch(player->GetTeam())
g_id = EY_GRAVEYARD_MAIN_ALLIANCE; {
else if(team == HORDE) case ALLIANCE: g_id = EY_GRAVEYARD_MAIN_ALLIANCE; break;
g_id = EY_GRAVEYARD_MAIN_HORDE; case HORDE: g_id = EY_GRAVEYARD_MAIN_HORDE; break;
else default: return NULL;
return NULL; }
float distance, nearestDistance; float distance, nearestDistance;
@ -909,19 +909,24 @@ WorldSafeLocsEntry const *BattleGroundEY::GetClosestGraveYard(float x, float y,
return NULL; return NULL;
} }
distance = (entry->x - x)*(entry->x - x) + (entry->y - y)*(entry->y - y) + (entry->z - z)*(entry->z - z); float plr_x = player->GetPositionX();
float plr_y = player->GetPositionY();
float plr_z = player->GetPositionZ();
distance = (entry->x - plr_x)*(entry->x - plr_x) + (entry->y - plr_y)*(entry->y - plr_y) + (entry->z - plr_z)*(entry->z - plr_z);
nearestDistance = distance; nearestDistance = distance;
for(uint8 i = 0; i < EY_POINTS_MAX; ++i) for(uint8 i = 0; i < EY_POINTS_MAX; ++i)
{ {
if(m_PointOwnedByTeam[i]==team && m_PointState[i]==EY_POINT_UNDER_CONTROL) if(m_PointOwnedByTeam[i]==player->GetTeam() && m_PointState[i]==EY_POINT_UNDER_CONTROL)
{ {
entry = sWorldSafeLocsStore.LookupEntry(m_CapturingPointTypes[i].GraveYardId); entry = sWorldSafeLocsStore.LookupEntry(m_CapturingPointTypes[i].GraveYardId);
if(!entry) if(!entry)
sLog.outError("BattleGroundEY: Not found graveyard: %u",m_CapturingPointTypes[i].GraveYardId); sLog.outError("BattleGroundEY: Not found graveyard: %u",m_CapturingPointTypes[i].GraveYardId);
else else
{ {
distance = (entry->x - x)*(entry->x - x) + (entry->y - y)*(entry->y - y) + (entry->z - z)*(entry->z - z); distance = (entry->x - plr_x)*(entry->x - plr_x) + (entry->y - plr_y)*(entry->y - plr_y) + (entry->z - plr_z)*(entry->z - plr_z);
if(distance < nearestDistance) if(distance < nearestDistance)
{ {
nearestDistance = distance; nearestDistance = distance;

View file

@ -315,7 +315,7 @@ class BattleGroundEY : public BattleGround
void HandleBuffUse(uint64 const& buff_guid); void HandleBuffUse(uint64 const& buff_guid);
void HandleAreaTrigger(Player *Source, uint32 Trigger); void HandleAreaTrigger(Player *Source, uint32 Trigger);
void HandleKillPlayer(Player *player, Player *killer); void HandleKillPlayer(Player *player, Player *killer);
virtual WorldSafeLocsEntry const* GetClosestGraveYard(float x, float y, float z, uint32 team); virtual WorldSafeLocsEntry const* GetClosestGraveYard(Player* player);
virtual bool SetupBattleGround(); virtual bool SetupBattleGround();
virtual void Reset(); virtual void Reset();
void UpdateTeamScore(uint32 Team); void UpdateTeamScore(uint32 Team);

View file

@ -4261,11 +4261,9 @@ void Player::RepopAtGraveyard()
WorldSafeLocsEntry const *ClosestGrave = NULL; WorldSafeLocsEntry const *ClosestGrave = NULL;
// Special handle for battleground maps // Special handle for battleground maps
if( GetBattleGroundTypeId() == BATTLEGROUND_AB || GetBattleGroundTypeId() == BATTLEGROUND_EY ) if( BattleGround *bg = GetBattleGround() )
if( BattleGround *bg = GetBattleGround() ) ClosestGrave = bg->GetClosestGraveYard(this);
ClosestGrave = bg->GetClosestGraveYard(GetPositionX(), GetPositionY(), GetPositionZ(), GetTeam()); else
if(!ClosestGrave)
ClosestGrave = objmgr.GetClosestGraveYard( GetPositionX(), GetPositionY(), GetPositionZ(), GetMapId(), GetTeam() ); ClosestGrave = objmgr.GetClosestGraveYard( GetPositionX(), GetPositionY(), GetPositionZ(), GetMapId(), GetTeam() );
// stop countdown until repop // stop countdown until repop

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "7371" #define REVISION_NR "7372"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__