From 7f744de746de3d91fea576cd9ff352851be0436a Mon Sep 17 00:00:00 2001 From: Discover- Date: Tue, 6 Aug 2013 13:25:22 +0200 Subject: Core/Misc: Implement reinterpret casts for all battleground classes and use them. --- src/server/game/Battlegrounds/Battleground.h | 44 ++++++++++++++++++++++ src/server/game/Entities/GameObject/GameObject.cpp | 2 +- src/server/game/Entities/Player/Player.cpp | 8 +++- src/server/game/Handlers/QuestHandler.cpp | 2 +- src/server/game/Spells/SpellMgr.cpp | 2 +- src/server/scripts/World/achievement_scripts.cpp | 14 +++---- 6 files changed, 61 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/server/game/Battlegrounds/Battleground.h b/src/server/game/Battlegrounds/Battleground.h index 52f86b98b79..ae095f0f740 100644 --- a/src/server/game/Battlegrounds/Battleground.h +++ b/src/server/game/Battlegrounds/Battleground.h @@ -29,6 +29,17 @@ class Group; class Player; class WorldPacket; class BattlegroundMap; +class BattlegroundAV; +class BattlegroundWS; +class BattlegroundAB; +class BattlegroundNA; +class BattlegroundBE; +class BattlegroundEY; +class BattlegroundRL; +class BattlegroundSA; +class BattlegroundDS; +class BattlegroundRV; +class BattlegroundIC; struct PvPDifficultyEntry; struct WorldSafeLocsEntry; @@ -534,6 +545,39 @@ class Battleground virtual uint32 GetPrematureWinner(); + BattlegroundAV* ToBattlegroundAV() { if (GetTypeID() == BATTLEGROUND_AV) return reinterpret_cast(this); else return NULL; } + BattlegroundAV const* ToBattlegroundAV() const { if (GetTypeID() == BATTLEGROUND_AV) return (BattlegroundAV const*)((BattlegroundAV*)this); else return NULL; } + + BattlegroundWS* ToBattlegroundWS() { if (GetTypeID() == BATTLEGROUND_WS) return reinterpret_cast(this); else return NULL; } + BattlegroundWS const* ToBattlegroundWS() const { if (GetTypeID() == BATTLEGROUND_WS) return (BattlegroundWS const*)((BattlegroundWS*)this); else return NULL; } + + BattlegroundAB* ToBattlegroundAB() { if (GetTypeID() == BATTLEGROUND_AB) return reinterpret_cast(this); else return NULL; } + BattlegroundAB const* ToBattlegroundAB() const { if (GetTypeID() == BATTLEGROUND_AB) return (BattlegroundAB const*)((BattlegroundAB*)this); else return NULL; } + + BattlegroundNA* ToBattlegroundNA() { if (GetTypeID() == BATTLEGROUND_NA) return reinterpret_cast(this); else return NULL; } + BattlegroundNA const* ToBattlegroundNA() const { if (GetTypeID() == BATTLEGROUND_NA) return (BattlegroundNA const*)((BattlegroundNA*)this); else return NULL; } + + BattlegroundBE* ToBattlegroundBE() { if (GetTypeID() == BATTLEGROUND_BE) return reinterpret_cast(this); else return NULL; } + BattlegroundBE const* ToBattlegroundBE() const { if (GetTypeID() == BATTLEGROUND_BE) return (BattlegroundBE const*)((BattlegroundBE*)this); else return NULL; } + + BattlegroundEY* ToBattlegroundEY() { if (GetTypeID() == BATTLEGROUND_EY) return reinterpret_cast(this); else return NULL; } + BattlegroundEY const* ToBattlegroundEY() const { if (GetTypeID() == BATTLEGROUND_EY) return (BattlegroundEY const*)((BattlegroundEY*)this); else return NULL; } + + BattlegroundRL* ToBattlegroundRL() { if (GetTypeID() == BATTLEGROUND_RL) return reinterpret_cast(this); else return NULL; } + BattlegroundRL const* ToBattlegroundRL() const { if (GetTypeID() == BATTLEGROUND_RL) return (BattlegroundRL const*)((BattlegroundRL*)this); else return NULL; } + + BattlegroundSA* ToBattlegroundSA() { if (GetTypeID() == BATTLEGROUND_SA) return reinterpret_cast(this); else return NULL; } + BattlegroundSA const* ToBattlegroundSA() const { if (GetTypeID() == BATTLEGROUND_SA) return (BattlegroundSA const*)((BattlegroundSA*)this); else return NULL; } + + BattlegroundDS* ToBattlegroundDS() { if (GetTypeID() == BATTLEGROUND_DS) return reinterpret_cast(this); else return NULL; } + BattlegroundDS const* ToBattlegroundDS() const { if (GetTypeID() == BATTLEGROUND_DS) return (BattlegroundDS const*)((BattlegroundDS*)this); else return NULL; } + + BattlegroundRV* ToBattlegroundRV() { if (GetTypeID() == BATTLEGROUND_RV) return reinterpret_cast(this); else return NULL; } + BattlegroundRV const* ToBattlegroundRV() const { if (GetTypeID() == BATTLEGROUND_RV) return (BattlegroundRV const*)((BattlegroundRV*)this); else return NULL; } + + BattlegroundIC* ToBattlegroundIC() { if (GetTypeID() == BATTLEGROUND_IC) return reinterpret_cast(this); else return NULL; } + BattlegroundIC const* ToBattlegroundIC() const { if (GetTypeID() == BATTLEGROUND_IC) return (BattlegroundIC const*)((BattlegroundIC*)this); else return NULL; } + protected: // this method is called, when BG cannot spawn its own spirit guide, or something is wrong, It correctly ends Battleground void EndNow(); diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 0915d19cdfa..31e625ae3e1 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -952,7 +952,7 @@ bool GameObject::ActivateToQuest(Player* target) const //look for battlegroundAV for some objects which are only activated after mine gots captured by own team if (GetEntry() == BG_AV_OBJECTID_MINE_N || GetEntry() == BG_AV_OBJECTID_MINE_S) if (Battleground* bg = target->GetBattleground()) - if (bg->GetTypeID(true) == BATTLEGROUND_AV && !(((BattlegroundAV*)bg)->PlayerCanDoMineQuest(GetEntry(), target->GetTeam()))) + if (bg->GetTypeID(true) == BATTLEGROUND_AV && !bg->ToBattlegroundAV()->PlayerCanDoMineQuest(GetEntry(), target->GetTeam())) return false; return true; } diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 8f1669910e7..3572222b74d 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -8773,13 +8773,19 @@ void Player::SendLoot(uint64 guid, LootType loot_type) /// @todo fix this big hack if ((go->GetEntry() == BG_AV_OBJECTID_MINE_N || go->GetEntry() == BG_AV_OBJECTID_MINE_S)) + { if (Battleground* bg = GetBattleground()) + { if (bg->GetTypeID(true) == BATTLEGROUND_AV) - if (!(((BattlegroundAV*)bg)->PlayerCanDoMineQuest(go->GetEntry(), GetTeam()))) + { + if (!bg->ToBattlegroundAV()->PlayerCanDoMineQuest(go->GetEntry(), GetTeam())) { SendLootRelease(guid); return; } + } + } + } if (lootid) { diff --git a/src/server/game/Handlers/QuestHandler.cpp b/src/server/game/Handlers/QuestHandler.cpp index 6cd999bc496..cee5b3d1164 100644 --- a/src/server/game/Handlers/QuestHandler.cpp +++ b/src/server/game/Handlers/QuestHandler.cpp @@ -530,7 +530,7 @@ void WorldSession::HandleQuestgiverCompleteQuest(WorldPacket& recvData) if (_player->InBattleground()) if (Battleground* bg = _player->GetBattleground()) if (bg->GetTypeID() == BATTLEGROUND_AV) - ((BattlegroundAV*)bg)->HandleQuestComplete(questId, _player); + bg->ToBattlegroundAV()->HandleQuestComplete(questId, _player); if (_player->GetQuestStatus(questId) != QUEST_STATUS_COMPLETE) { diff --git a/src/server/game/Spells/SpellMgr.cpp b/src/server/game/Spells/SpellMgr.cpp index 42d408ebbad..db0102f4307 100644 --- a/src/server/game/Spells/SpellMgr.cpp +++ b/src/server/game/Spells/SpellMgr.cpp @@ -1136,7 +1136,7 @@ bool SpellArea::IsFitToRequirements(Player const* player, uint32 newZone, uint32 uint8 nodeType = spellId == 68719 ? NODE_TYPE_REFINERY : NODE_TYPE_QUARRY; uint8 nodeState = player->GetTeamId() == TEAM_ALLIANCE ? NODE_STATE_CONTROLLED_A : NODE_STATE_CONTROLLED_H; - BattlegroundIC* pIC = static_cast(player->GetBattleground()); + BattlegroundIC* pIC = player->GetBattleground()->ToBattlegroundIC(); if (pIC->GetNodeState(nodeType) == nodeState) return true; diff --git a/src/server/scripts/World/achievement_scripts.cpp b/src/server/scripts/World/achievement_scripts.cpp index 774c4e63071..0243b08e80e 100644 --- a/src/server/scripts/World/achievement_scripts.cpp +++ b/src/server/scripts/World/achievement_scripts.cpp @@ -40,7 +40,7 @@ class achievement_resilient_victory : public AchievementCriteriaScript if (bg->GetTypeID(true) != BATTLEGROUND_AB) return false; - if (!static_cast(bg)->IsTeamScores500Disadvantage(source->GetTeam())) + if (!bg->ToBattlegroundAB()->IsTeamScores500Disadvantage(source->GetTeam())) return false; return true; @@ -84,7 +84,7 @@ class achievement_save_the_day : public AchievementCriteriaScript if (bg->GetTypeID(true) != BATTLEGROUND_WS) return false; - if (static_cast(bg)->GetFlagState(player->GetTeam()) == BG_WS_FLAG_STATE_ON_BASE) + if (bg->ToBattlegroundWS()->GetFlagState(player->GetTeam()) == BG_WS_FLAG_STATE_ON_BASE) return true; } return false; @@ -209,7 +209,7 @@ class achievement_everything_counts : public AchievementCriteriaScript if (bg->GetTypeID(true) != BATTLEGROUND_AV) return false; - if (static_cast(bg)->IsBothMinesControlledByTeam(source->GetTeam())) + if (bg->ToBattlegroundAV()->IsBothMinesControlledByTeam(source->GetTeam())) return true; return false; @@ -230,7 +230,7 @@ class achievement_bg_av_perfection : public AchievementCriteriaScript if (bg->GetTypeID(true) != BATTLEGROUND_AV) return false; - if (static_cast(bg)->IsAllTowersControlledAndCaptainAlive(source->GetTeam())) + if (bg->ToBattlegroundAV()->IsAllTowersControlledAndCaptainAlive(source->GetTeam())) return true; return false; @@ -253,10 +253,10 @@ class achievement_bg_sa_defense_of_ancients : public AchievementCriteriaScript if (!battleground) return false; - if (player->GetTeamId() == static_cast(battleground)->Attackers) + if (player->GetTeamId() == battleground->ToBattlegroundSA()->Attackers) return false; - if (!static_cast(battleground)->gateDestroyed) + if (!battleground->ToBattlegroundSA()->gateDestroyed) return true; return false; @@ -308,7 +308,7 @@ class achievement_not_even_a_scratch : public AchievementCriteriaScript if (!battleground) return false; - if (static_cast(battleground)->notEvenAScratch(source->GetTeam())) + if (battleground->ToBattlegroundSA()->notEvenAScratch(source->GetTeam())) return true; return false; -- cgit v1.2.3 From 233a154e77cc1c534c6c7fa80c9cec4c601c8d34 Mon Sep 17 00:00:00 2001 From: Discover- Date: Tue, 6 Aug 2013 17:30:23 +0200 Subject: Core/Misc: Update const casts of ToBattlegroundX to use reinterpret_cast as well. --- src/server/game/Battlegrounds/Battleground.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/server/game/Battlegrounds/Battleground.h b/src/server/game/Battlegrounds/Battleground.h index ae095f0f740..dcca0804977 100644 --- a/src/server/game/Battlegrounds/Battleground.h +++ b/src/server/game/Battlegrounds/Battleground.h @@ -546,37 +546,37 @@ class Battleground virtual uint32 GetPrematureWinner(); BattlegroundAV* ToBattlegroundAV() { if (GetTypeID() == BATTLEGROUND_AV) return reinterpret_cast(this); else return NULL; } - BattlegroundAV const* ToBattlegroundAV() const { if (GetTypeID() == BATTLEGROUND_AV) return (BattlegroundAV const*)((BattlegroundAV*)this); else return NULL; } + BattlegroundAV const* ToBattlegroundAV() const { if (GetTypeID() == BATTLEGROUND_AV) return reinterpret_cast(this); else return NULL; } BattlegroundWS* ToBattlegroundWS() { if (GetTypeID() == BATTLEGROUND_WS) return reinterpret_cast(this); else return NULL; } - BattlegroundWS const* ToBattlegroundWS() const { if (GetTypeID() == BATTLEGROUND_WS) return (BattlegroundWS const*)((BattlegroundWS*)this); else return NULL; } + BattlegroundWS const* ToBattlegroundWS() const { if (GetTypeID() == BATTLEGROUND_WS) return reinterpret_cast(this); else return NULL; } BattlegroundAB* ToBattlegroundAB() { if (GetTypeID() == BATTLEGROUND_AB) return reinterpret_cast(this); else return NULL; } - BattlegroundAB const* ToBattlegroundAB() const { if (GetTypeID() == BATTLEGROUND_AB) return (BattlegroundAB const*)((BattlegroundAB*)this); else return NULL; } + BattlegroundAB const* ToBattlegroundAB() const { if (GetTypeID() == BATTLEGROUND_AB) return reinterpret_cast(this); else return NULL; } BattlegroundNA* ToBattlegroundNA() { if (GetTypeID() == BATTLEGROUND_NA) return reinterpret_cast(this); else return NULL; } - BattlegroundNA const* ToBattlegroundNA() const { if (GetTypeID() == BATTLEGROUND_NA) return (BattlegroundNA const*)((BattlegroundNA*)this); else return NULL; } + BattlegroundNA const* ToBattlegroundNA() const { if (GetTypeID() == BATTLEGROUND_NA) return reinterpret_cast(this); else return NULL; } BattlegroundBE* ToBattlegroundBE() { if (GetTypeID() == BATTLEGROUND_BE) return reinterpret_cast(this); else return NULL; } - BattlegroundBE const* ToBattlegroundBE() const { if (GetTypeID() == BATTLEGROUND_BE) return (BattlegroundBE const*)((BattlegroundBE*)this); else return NULL; } + BattlegroundBE const* ToBattlegroundBE() const { if (GetTypeID() == BATTLEGROUND_BE) return reinterpret_cast(this); else return NULL; } BattlegroundEY* ToBattlegroundEY() { if (GetTypeID() == BATTLEGROUND_EY) return reinterpret_cast(this); else return NULL; } - BattlegroundEY const* ToBattlegroundEY() const { if (GetTypeID() == BATTLEGROUND_EY) return (BattlegroundEY const*)((BattlegroundEY*)this); else return NULL; } + BattlegroundEY const* ToBattlegroundEY() const { if (GetTypeID() == BATTLEGROUND_EY) return reinterpret_cast(this); else return NULL; } BattlegroundRL* ToBattlegroundRL() { if (GetTypeID() == BATTLEGROUND_RL) return reinterpret_cast(this); else return NULL; } - BattlegroundRL const* ToBattlegroundRL() const { if (GetTypeID() == BATTLEGROUND_RL) return (BattlegroundRL const*)((BattlegroundRL*)this); else return NULL; } + BattlegroundRL const* ToBattlegroundRL() const { if (GetTypeID() == BATTLEGROUND_RL) return reinterpret_cast(this); else return NULL; } BattlegroundSA* ToBattlegroundSA() { if (GetTypeID() == BATTLEGROUND_SA) return reinterpret_cast(this); else return NULL; } - BattlegroundSA const* ToBattlegroundSA() const { if (GetTypeID() == BATTLEGROUND_SA) return (BattlegroundSA const*)((BattlegroundSA*)this); else return NULL; } + BattlegroundSA const* ToBattlegroundSA() const { if (GetTypeID() == BATTLEGROUND_SA) return reinterpret_cast(this); else return NULL; } BattlegroundDS* ToBattlegroundDS() { if (GetTypeID() == BATTLEGROUND_DS) return reinterpret_cast(this); else return NULL; } - BattlegroundDS const* ToBattlegroundDS() const { if (GetTypeID() == BATTLEGROUND_DS) return (BattlegroundDS const*)((BattlegroundDS*)this); else return NULL; } + BattlegroundDS const* ToBattlegroundDS() const { if (GetTypeID() == BATTLEGROUND_DS) return reinterpret_cast(this); else return NULL; } BattlegroundRV* ToBattlegroundRV() { if (GetTypeID() == BATTLEGROUND_RV) return reinterpret_cast(this); else return NULL; } - BattlegroundRV const* ToBattlegroundRV() const { if (GetTypeID() == BATTLEGROUND_RV) return (BattlegroundRV const*)((BattlegroundRV*)this); else return NULL; } + BattlegroundRV const* ToBattlegroundRV() const { if (GetTypeID() == BATTLEGROUND_RV) return reinterpret_cast(this); else return NULL; } BattlegroundIC* ToBattlegroundIC() { if (GetTypeID() == BATTLEGROUND_IC) return reinterpret_cast(this); else return NULL; } - BattlegroundIC const* ToBattlegroundIC() const { if (GetTypeID() == BATTLEGROUND_IC) return (BattlegroundIC const*)((BattlegroundIC*)this); else return NULL; } + BattlegroundIC const* ToBattlegroundIC() const { if (GetTypeID() == BATTLEGROUND_IC) return reinterpret_cast(this); else return NULL; } protected: // this method is called, when BG cannot spawn its own spirit guide, or something is wrong, It correctly ends Battleground -- cgit v1.2.3