diff options
author | megamage <none@none> | 2009-03-02 17:13:12 -0600 |
---|---|---|
committer | megamage <none@none> | 2009-03-02 17:13:12 -0600 |
commit | 55dffa8409b309b215cdf1f5d31c791b5f02825b (patch) | |
tree | 4f3620d1050f9f9664ab52d90929d3e0f8d3695a /src/game | |
parent | 27cf8127b463a0592e8dc095e8d76189e27935b5 (diff) |
[7372] Cleanup BattleGround::GetClosestGraveYard related code. Author: VladimirMangos
--HG--
branch : trunk
Diffstat (limited to 'src/game')
-rw-r--r-- | src/game/BattleGround.cpp | 5 | ||||
-rw-r--r-- | src/game/BattleGround.h | 2 | ||||
-rw-r--r-- | src/game/BattleGroundAB.cpp | 24 | ||||
-rw-r--r-- | src/game/BattleGroundAB.h | 2 | ||||
-rw-r--r-- | src/game/BattleGroundEY.cpp | 25 | ||||
-rw-r--r-- | src/game/BattleGroundEY.h | 2 | ||||
-rw-r--r-- | src/game/Player.cpp | 8 |
7 files changed, 40 insertions, 28 deletions
diff --git a/src/game/BattleGround.cpp b/src/game/BattleGround.cpp index 8733fd86497..24f83eb751f 100644 --- a/src/game/BattleGround.cpp +++ b/src/game/BattleGround.cpp @@ -1577,3 +1577,8 @@ void BattleGround::SetBgRaid( uint32 TeamID, Group *bg_raid ) if(bg_raid) bg_raid->SetBattlegroundGroup(this); old_raid = bg_raid; } + +WorldSafeLocsEntry const* BattleGround::GetClosestGraveYard( Player* player ) +{ + return objmgr.GetClosestGraveYard( player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), player->GetTeam() ); +}
\ No newline at end of file diff --git a/src/game/BattleGround.h b/src/game/BattleGround.h index c0019c4a147..a8f6364ff0d 100644 --- a/src/game/BattleGround.h +++ b/src/game/BattleGround.h @@ -440,7 +440,7 @@ class BattleGround virtual void EventPlayerCapturedFlag(Player* /*player*/) {} /* 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 diff --git a/src/game/BattleGroundAB.cpp b/src/game/BattleGroundAB.cpp index 7aecb33af8e..21a6583537d 100644 --- a/src/game/BattleGroundAB.cpp +++ b/src/game/BattleGroundAB.cpp @@ -425,20 +425,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 @@ -619,9 +620,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; @@ -633,13 +634,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; diff --git a/src/game/BattleGroundAB.h b/src/game/BattleGroundAB.h index 5f05d182bee..3c080621033 100644 --- a/src/game/BattleGroundAB.h +++ b/src/game/BattleGroundAB.h @@ -244,7 +244,7 @@ class BattleGroundAB : public BattleGround void HandleAreaTrigger(Player *Source, uint32 Trigger); virtual bool SetupBattleGround(); virtual void Reset(); - virtual WorldSafeLocsEntry const* GetClosestGraveYard(float x, float y, float z, uint32 team); + virtual WorldSafeLocsEntry const* GetClosestGraveYard(Player* player); /* Scorekeeping */ virtual void UpdatePlayerScore(Player *Source, uint32 type, uint32 value); diff --git a/src/game/BattleGroundEY.cpp b/src/game/BattleGroundEY.cpp index 40d55ea6f18..78027b532bc 100644 --- a/src/game/BattleGroundEY.cpp +++ b/src/game/BattleGroundEY.cpp @@ -896,16 +896,16 @@ void BattleGroundEY::FillInitialWorldStates(WorldPacket& data) 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; - if(team == ALLIANCE) - g_id = EY_GRAVEYARD_MAIN_ALLIANCE; - else if(team == HORDE) - g_id = EY_GRAVEYARD_MAIN_HORDE; - else - return NULL; + switch(player->GetTeam()) + { + case ALLIANCE: g_id = EY_GRAVEYARD_MAIN_ALLIANCE; break; + case HORDE: g_id = EY_GRAVEYARD_MAIN_HORDE; break; + default: return NULL; + } float distance, nearestDistance; @@ -920,19 +920,24 @@ WorldSafeLocsEntry const *BattleGroundEY::GetClosestGraveYard(float x, float y, 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; 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); if(!entry) sLog.outError("BattleGroundEY: Not found graveyard: %u",m_CapturingPointTypes[i].GraveYardId); 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) { nearestDistance = distance; diff --git a/src/game/BattleGroundEY.h b/src/game/BattleGroundEY.h index 653de4fc6cc..fd5cf7ce763 100644 --- a/src/game/BattleGroundEY.h +++ b/src/game/BattleGroundEY.h @@ -317,7 +317,7 @@ class BattleGroundEY : public BattleGround void HandleBuffUse(uint64 const& buff_guid); void HandleAreaTrigger(Player *Source, uint32 Trigger); 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 void Reset(); void UpdateTeamScore(uint32 Team); diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 5290e2521b0..c5ba2f3d6db 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -4366,11 +4366,9 @@ void Player::RepopAtGraveyard() WorldSafeLocsEntry const *ClosestGrave = NULL; // Special handle for battleground maps - if( GetBattleGroundTypeId() == BATTLEGROUND_AB || GetBattleGroundTypeId() == BATTLEGROUND_EY || GetBattleGroundTypeId() == BATTLEGROUND_AV) - if( BattleGround *bg = GetBattleGround() ) - ClosestGrave = bg->GetClosestGraveYard(GetPositionX(), GetPositionY(), GetPositionZ(), GetTeam()); - - if(!ClosestGrave) + if( BattleGround *bg = GetBattleGround() ) + ClosestGrave = bg->GetClosestGraveYard(this); + else ClosestGrave = objmgr.GetClosestGraveYard( GetPositionX(), GetPositionY(), GetPositionZ(), GetMapId(), GetTeam() ); // stop countdown until repop |