Core/Cleanup: reformated and refactored code in Battleground.cpp/h:
* added proper formatting; * moved identical code into separate method (have I already said that I hate copy/paste?); * fixed several leaks; * added more informative error messages. More to come...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -409,13 +409,7 @@ class Battleground
|
|||||||
void IncreaseInvitedCount(uint32 team) { (team == ALLIANCE) ? ++m_InvitedAlliance : ++m_InvitedHorde; }
|
void IncreaseInvitedCount(uint32 team) { (team == ALLIANCE) ? ++m_InvitedAlliance : ++m_InvitedHorde; }
|
||||||
|
|
||||||
void SetRandom(bool isRandom) { m_IsRandom = isRandom; }
|
void SetRandom(bool isRandom) { m_IsRandom = isRandom; }
|
||||||
uint32 GetInvitedCount(uint32 team) const
|
uint32 GetInvitedCount(uint32 team) const { return (team == ALLIANCE) ? m_InvitedAlliance : m_InvitedHorde; }
|
||||||
{
|
|
||||||
if (team == ALLIANCE)
|
|
||||||
return m_InvitedAlliance;
|
|
||||||
else
|
|
||||||
return m_InvitedHorde;
|
|
||||||
}
|
|
||||||
bool HasFreeSlots() const;
|
bool HasFreeSlots() const;
|
||||||
uint32 GetFreeSlotsForTeam(uint32 Team) const;
|
uint32 GetFreeSlotsForTeam(uint32 Team) const;
|
||||||
|
|
||||||
@@ -434,18 +428,19 @@ class Battleground
|
|||||||
|
|
||||||
uint32 GetReviveQueueSize() const { return m_ReviveQueue.size(); }
|
uint32 GetReviveQueueSize() const { return m_ReviveQueue.size(); }
|
||||||
|
|
||||||
void AddPlayerToResurrectQueue(uint64 npc_guid, uint64 player_guid);
|
void AddPlayerToResurrectQueue(const uint64& npc_guid, const uint64& player_guid);
|
||||||
void RemovePlayerFromResurrectQueue(uint64 player_guid);
|
void RemovePlayerFromResurrectQueue(const uint64& player_guid);
|
||||||
|
|
||||||
void StartBattleground();
|
void StartBattleground();
|
||||||
|
|
||||||
GameObject* GetBGObject(uint32 type);
|
GameObject* GetBGObject(uint32 type);
|
||||||
Creature* GetBGCreature(uint32 type);
|
Creature* GetBGCreature(uint32 type);
|
||||||
/* Location */
|
|
||||||
|
// Location
|
||||||
void SetMapId(uint32 MapID) { m_MapId = MapID; }
|
void SetMapId(uint32 MapID) { m_MapId = MapID; }
|
||||||
uint32 GetMapId() const { return m_MapId; }
|
uint32 GetMapId() const { return m_MapId; }
|
||||||
|
|
||||||
/* Map pointers */
|
// Map pointers
|
||||||
void SetBgMap(BattlegroundMap* map) { m_Map = map; }
|
void SetBgMap(BattlegroundMap* map) { m_Map = map; }
|
||||||
BattlegroundMap* GetBgMap()
|
BattlegroundMap* GetBgMap()
|
||||||
{
|
{
|
||||||
@@ -463,11 +458,11 @@ class Battleground
|
|||||||
O = m_TeamStartLocO[idx];
|
O = m_TeamStartLocO[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Packet Transfer */
|
// Packet Transfer
|
||||||
// method that should fill worldpacket with actual world states (not yet implemented for all battlegrounds!)
|
// method that should fill worldpacket with actual world states (not yet implemented for all battlegrounds!)
|
||||||
virtual void FillInitialWorldStates(WorldPacket& /*data*/) {}
|
virtual void FillInitialWorldStates(WorldPacket& /*data*/) {}
|
||||||
void SendPacketToTeam(uint32 TeamID, WorldPacket *packet, Player *sender = NULL, bool self = true);
|
void SendPacketToTeam(uint32 TeamID, WorldPacket* packet, Player* sender = NULL, bool self = true);
|
||||||
void SendPacketToAll(WorldPacket *packet);
|
void SendPacketToAll(WorldPacket* packet);
|
||||||
void YellToAll(Creature* creature, const char* text, uint32 language);
|
void YellToAll(Creature* creature, const char* text, uint32 language);
|
||||||
|
|
||||||
template<class Do>
|
template<class Do>
|
||||||
@@ -480,9 +475,9 @@ class Battleground
|
|||||||
void RewardHonorToTeam(uint32 Honor, uint32 TeamID);
|
void RewardHonorToTeam(uint32 Honor, uint32 TeamID);
|
||||||
void RewardReputationToTeam(uint32 faction_id, uint32 Reputation, uint32 TeamID);
|
void RewardReputationToTeam(uint32 faction_id, uint32 Reputation, uint32 TeamID);
|
||||||
void UpdateWorldState(uint32 Field, uint32 Value);
|
void UpdateWorldState(uint32 Field, uint32 Value);
|
||||||
void UpdateWorldStateForPlayer(uint32 Field, uint32 Value, Player *Source);
|
void UpdateWorldStateForPlayer(uint32 Field, uint32 Value, Player* Source);
|
||||||
void EndBattleground(uint32 winner);
|
void EndBattleground(uint32 winner);
|
||||||
void BlockMovement(Player *plr);
|
void BlockMovement(Player* plr);
|
||||||
|
|
||||||
void SendWarningToAll(int32 entry, ...);
|
void SendWarningToAll(int32 entry, ...);
|
||||||
void SendMessageToAll(int32 entry, ChatMsg type, Player const* source = NULL);
|
void SendMessageToAll(int32 entry, ChatMsg type, Player const* source = NULL);
|
||||||
@@ -491,7 +486,7 @@ class Battleground
|
|||||||
// specialized version with 2 string id args
|
// specialized version with 2 string id args
|
||||||
void SendMessage2ToAll(int32 entry, ChatMsg type, Player const* source, int32 strId1 = 0, int32 strId2 = 0);
|
void SendMessage2ToAll(int32 entry, ChatMsg type, Player const* source, int32 strId1 = 0, int32 strId2 = 0);
|
||||||
|
|
||||||
/* Raid Group */
|
// Raid Group
|
||||||
Group *GetBgRaid(uint32 TeamID) const { return TeamID == ALLIANCE ? m_BgRaids[BG_TEAM_ALLIANCE] : m_BgRaids[BG_TEAM_HORDE]; }
|
Group *GetBgRaid(uint32 TeamID) const { return TeamID == ALLIANCE ? m_BgRaids[BG_TEAM_ALLIANCE] : m_BgRaids[BG_TEAM_HORDE]; }
|
||||||
void SetBgRaid(uint32 TeamID, Group *bg_raid);
|
void SetBgRaid(uint32 TeamID, Group *bg_raid);
|
||||||
|
|
||||||
@@ -519,14 +514,14 @@ class Battleground
|
|||||||
void CheckArenaWinConditions();
|
void CheckArenaWinConditions();
|
||||||
void UpdateArenaWorldState();
|
void UpdateArenaWorldState();
|
||||||
|
|
||||||
/* Triggers handle */
|
// Triggers handle
|
||||||
// must be implemented in BG subclass
|
// must be implemented in BG subclass
|
||||||
virtual void HandleAreaTrigger(Player* /*Source*/, uint32 /*Trigger*/) {}
|
virtual void HandleAreaTrigger(Player* /*Source*/, uint32 /*Trigger*/) {}
|
||||||
// must be implemented in BG subclass if need AND call base class generic code
|
// must be implemented in BG subclass if need AND call base class generic code
|
||||||
virtual void HandleKillPlayer(Player *player, Player *killer);
|
virtual void HandleKillPlayer(Player *player, Player *killer);
|
||||||
virtual void HandleKillUnit(Creature* /*unit*/, Player* /*killer*/);
|
virtual void HandleKillUnit(Creature* /*unit*/, Player* /*killer*/);
|
||||||
|
|
||||||
/* Battleground events */
|
// Battleground events
|
||||||
virtual void EventPlayerDroppedFlag(Player* /*player*/) {}
|
virtual void EventPlayerDroppedFlag(Player* /*player*/) {}
|
||||||
virtual void EventPlayerClickedOnFlag(Player* /*player*/, GameObject* /*target_obj*/) {}
|
virtual void EventPlayerClickedOnFlag(Player* /*player*/, GameObject* /*target_obj*/) {}
|
||||||
virtual void EventPlayerCapturedFlag(Player* /*player*/) {}
|
virtual void EventPlayerCapturedFlag(Player* /*player*/) {}
|
||||||
@@ -536,21 +531,21 @@ class Battleground
|
|||||||
virtual void EventPlayerUsedGO(Player* /*player*/, GameObject* /*go*/){}
|
virtual void EventPlayerUsedGO(Player* /*player*/, GameObject* /*go*/){}
|
||||||
|
|
||||||
// this function can be used by spell to interact with the BG map
|
// this function can be used by spell to interact with the BG map
|
||||||
virtual void DoAction(uint32 /*action*/, uint64 /*var*/) {}
|
virtual void DoAction(uint32 /*action*/, const uint64& /*var*/) {}
|
||||||
|
|
||||||
virtual void HandlePlayerResurrect(Player* /*player*/) {}
|
virtual void HandlePlayerResurrect(Player* /*player*/) {}
|
||||||
|
|
||||||
/* Death related */
|
// Death related
|
||||||
virtual WorldSafeLocsEntry const* GetClosestGraveYard(Player* player);
|
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
|
||||||
|
|
||||||
void AddOrSetPlayerToCorrectBgGroup(Player *player, uint32 team);
|
void AddOrSetPlayerToCorrectBgGroup(Player* player, uint32 team);
|
||||||
|
|
||||||
virtual void RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPacket);
|
virtual void RemovePlayerAtLeave(const uint64& guid, bool Transport, bool SendPacket);
|
||||||
// can be extended in in BG subclass
|
// can be extended in in BG subclass
|
||||||
|
|
||||||
void HandleTriggerBuff(uint64 const& go_guid);
|
void HandleTriggerBuff(const uint64& go_guid);
|
||||||
void SetHoliday(bool is_holiday);
|
void SetHoliday(bool is_holiday);
|
||||||
|
|
||||||
// TODO: make this protected:
|
// TODO: make this protected:
|
||||||
@@ -560,55 +555,62 @@ class Battleground
|
|||||||
BGCreatures m_BgCreatures;
|
BGCreatures m_BgCreatures;
|
||||||
void SpawnBGObject(uint32 type, uint32 respawntime);
|
void SpawnBGObject(uint32 type, uint32 respawntime);
|
||||||
bool AddObject(uint32 type, uint32 entry, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime = 0);
|
bool AddObject(uint32 type, uint32 entry, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime = 0);
|
||||||
// void SpawnBGCreature(uint32 type, uint32 respawntime);
|
|
||||||
Creature* AddCreature(uint32 entry, uint32 type, uint32 teamval, float x, float y, float z, float o, uint32 respawntime = 0);
|
Creature* AddCreature(uint32 entry, uint32 type, uint32 teamval, float x, float y, float z, float o, uint32 respawntime = 0);
|
||||||
bool DelCreature(uint32 type);
|
bool DelCreature(uint32 type);
|
||||||
bool DelObject(uint32 type);
|
bool DelObject(uint32 type);
|
||||||
bool AddSpiritGuide(uint32 type, float x, float y, float z, float o, uint32 team);
|
bool AddSpiritGuide(uint32 type, float x, float y, float z, float o, uint32 team);
|
||||||
int32 GetObjectType(uint64 guid);
|
int32 GetObjectType(const uint64& guid);
|
||||||
|
|
||||||
void DoorOpen(uint32 type);
|
void DoorOpen(uint32 type);
|
||||||
void DoorClose(uint32 type);
|
void DoorClose(uint32 type);
|
||||||
//to be removed
|
//to be removed
|
||||||
const char *GetTrinityString(int32 entry);
|
const char* GetTrinityString(int32 entry);
|
||||||
|
|
||||||
virtual bool HandlePlayerUnderMap(Player * /*plr*/) { return false; }
|
virtual bool HandlePlayerUnderMap(Player * /*plr*/) { return false; }
|
||||||
|
|
||||||
// since arenas can be AvA or Hvh, we have to get the "temporary" team of a player
|
// since arenas can be AvA or Hvh, we have to get the "temporary" team of a player
|
||||||
uint32 GetPlayerTeam(uint64 guid) const;
|
uint32 GetPlayerTeam(const uint64& guid) const;
|
||||||
uint32 GetOtherTeam(uint32 teamId) const;
|
uint32 GetOtherTeam(uint32 teamId) const;
|
||||||
bool IsPlayerInBattleground(uint64 guid) const;
|
bool IsPlayerInBattleground(const uint64& guid) const;
|
||||||
|
|
||||||
void SetDeleteThis() {m_SetDeleteThis = true;}
|
void SetDeleteThis() { m_SetDeleteThis = true; }
|
||||||
|
|
||||||
/* virtual score-array - get's used in bg-subclasses */
|
// virtual score-array - get's used in bg-subclasses
|
||||||
int32 m_TeamScores[BG_TEAMS_COUNT];
|
int32 m_TeamScores[BG_TEAMS_COUNT];
|
||||||
|
|
||||||
void RewardXPAtKill(Player* killer, Player* victim);
|
void RewardXPAtKill(Player* killer, Player* victim);
|
||||||
bool CanAwardArenaPoints() const { return m_LevelMin >= BG_AWARD_ARENA_POINTS_MIN_LEVEL; }
|
bool CanAwardArenaPoints() const { return m_LevelMin >= BG_AWARD_ARENA_POINTS_MIN_LEVEL; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//this method is called, when BG cannot spawn its own spirit guide, or something is wrong, It correctly ends Battleground
|
// this method is called, when BG cannot spawn its own spirit guide, or something is wrong, It correctly ends Battleground
|
||||||
void EndNow();
|
void EndNow();
|
||||||
void PlayerAddedToBGCheckIfBGIsRunning(Player* plr);
|
void PlayerAddedToBGCheckIfBGIsRunning(Player* plr);
|
||||||
|
|
||||||
/* Scorekeeping */
|
Player* _GetPlayer(const uint64& guid, bool offlineRemove, const char* context) const;
|
||||||
|
Player* _GetPlayer(BattlegroundPlayerMap::iterator itr, const char* context);
|
||||||
|
Player* _GetPlayer(BattlegroundPlayerMap::const_iterator itr, const char* context) const;
|
||||||
|
Player* _GetPlayerForTeam(uint32 teamId, BattlegroundPlayerMap::const_iterator itr, const char* context) const;
|
||||||
|
|
||||||
|
void _ProcessOfflineQueue();
|
||||||
|
void _ProcessRessurect(uint32 diff);
|
||||||
|
void _ProcessProgress(uint32 diff);
|
||||||
|
void _ProcessLeave(uint32 diff);
|
||||||
|
void _ProcessJoin(uint32 diff);
|
||||||
|
|
||||||
|
// Scorekeeping
|
||||||
BattlegroundScoreMap m_PlayerScores; // Player scores
|
BattlegroundScoreMap m_PlayerScores; // Player scores
|
||||||
// must be implemented in BG subclass
|
// must be implemented in BG subclass
|
||||||
virtual void RemovePlayer(Player * /*player*/, uint64 /*guid*/) {}
|
virtual void RemovePlayer(Player * /*player*/, uint64 /*guid*/) {}
|
||||||
|
|
||||||
/* Player lists, those need to be accessible by inherited classes */
|
// Player lists, those need to be accessible by inherited classes
|
||||||
BattlegroundPlayerMap m_Players;
|
BattlegroundPlayerMap m_Players;
|
||||||
// Spirit Guide guid + Player list GUIDS
|
// Spirit Guide guid + Player list GUIDS
|
||||||
std::map<uint64, std::vector<uint64> > m_ReviveQueue;
|
std::map<uint64, std::vector<uint64> > m_ReviveQueue;
|
||||||
|
|
||||||
/*
|
// these are important variables used for starting messages
|
||||||
these are important variables used for starting messages
|
|
||||||
*/
|
|
||||||
uint8 m_Events;
|
uint8 m_Events;
|
||||||
BattlegroundStartTimeIntervals m_StartDelayTimes[BG_STARTING_EVENT_COUNT];
|
BattlegroundStartTimeIntervals m_StartDelayTimes[BG_STARTING_EVENT_COUNT];
|
||||||
//this must be filled in constructors!
|
// this must be filled in constructors!
|
||||||
uint32 m_StartMessageIds[BG_STARTING_EVENT_COUNT];
|
uint32 m_StartMessageIds[BG_STARTING_EVENT_COUNT];
|
||||||
|
|
||||||
bool m_BuffChange;
|
bool m_BuffChange;
|
||||||
@@ -616,12 +618,12 @@ class Battleground
|
|||||||
|
|
||||||
BGHonorMode m_HonorMode;
|
BGHonorMode m_HonorMode;
|
||||||
private:
|
private:
|
||||||
/* Battleground */
|
// Battleground
|
||||||
BattlegroundTypeId m_TypeID;
|
BattlegroundTypeId m_TypeID;
|
||||||
BattlegroundTypeId m_RandomTypeID;
|
BattlegroundTypeId m_RandomTypeID;
|
||||||
uint32 m_InstanceID; //Battleground Instance's GUID!
|
uint32 m_InstanceID; // Battleground Instance's GUID!
|
||||||
BattlegroundStatus m_Status;
|
BattlegroundStatus m_Status;
|
||||||
uint32 m_ClientInstanceID; //the instance-id which is sent to the client and without any other internal use
|
uint32 m_ClientInstanceID; // the instance-id which is sent to the client and without any other internal use
|
||||||
uint32 m_StartTime;
|
uint32 m_StartTime;
|
||||||
uint32 m_ResetStatTimer;
|
uint32 m_ResetStatTimer;
|
||||||
int32 m_EndTime; // it is set to 120000 when bg is ending and it decreases itself
|
int32 m_EndTime; // it is set to 120000 when bg is ending and it decreases itself
|
||||||
@@ -638,29 +640,29 @@ class Battleground
|
|||||||
uint32 m_PrematureCountDownTimer;
|
uint32 m_PrematureCountDownTimer;
|
||||||
char const *m_Name;
|
char const *m_Name;
|
||||||
|
|
||||||
/* Player lists */
|
// Player lists
|
||||||
std::vector<uint64> m_ResurrectQueue; // Player GUID
|
std::vector<uint64> m_ResurrectQueue; // Player GUID
|
||||||
std::deque<uint64> m_OfflineQueue; // Player GUID
|
std::deque<uint64> m_OfflineQueue; // Player GUID
|
||||||
|
|
||||||
/* Invited counters are useful for player invitation to BG - do not allow, if BG is started to one faction to have 2 more players than another faction */
|
// Invited counters are useful for player invitation to BG - do not allow, if BG is started to one faction to have 2 more players than another faction
|
||||||
/* Invited counters will be changed only when removing already invited player from queue, removing player from battleground and inviting player to BG */
|
// Invited counters will be changed only when removing already invited player from queue, removing player from battleground and inviting player to BG
|
||||||
/* Invited players counters*/
|
// Invited players counters
|
||||||
uint32 m_InvitedAlliance;
|
uint32 m_InvitedAlliance;
|
||||||
uint32 m_InvitedHorde;
|
uint32 m_InvitedHorde;
|
||||||
|
|
||||||
/* Raid Group */
|
// Raid Group
|
||||||
Group *m_BgRaids[BG_TEAMS_COUNT]; // 0 - alliance, 1 - horde
|
Group *m_BgRaids[BG_TEAMS_COUNT]; // 0 - alliance, 1 - horde
|
||||||
|
|
||||||
/* Players count by team */
|
// Players count by team
|
||||||
uint32 m_PlayersCount[BG_TEAMS_COUNT];
|
uint32 m_PlayersCount[BG_TEAMS_COUNT];
|
||||||
|
|
||||||
/* Arena team ids by team */
|
// Arena team ids by team
|
||||||
uint32 m_ArenaTeamIds[BG_TEAMS_COUNT];
|
uint32 m_ArenaTeamIds[BG_TEAMS_COUNT];
|
||||||
|
|
||||||
int32 m_ArenaTeamRatingChanges[BG_TEAMS_COUNT];
|
int32 m_ArenaTeamRatingChanges[BG_TEAMS_COUNT];
|
||||||
uint32 m_ArenaTeamMMR[BG_TEAMS_COUNT];
|
uint32 m_ArenaTeamMMR[BG_TEAMS_COUNT];
|
||||||
|
|
||||||
/* Limits */
|
// Limits
|
||||||
uint32 m_LevelMin;
|
uint32 m_LevelMin;
|
||||||
uint32 m_LevelMax;
|
uint32 m_LevelMax;
|
||||||
uint32 m_MaxPlayersPerTeam;
|
uint32 m_MaxPlayersPerTeam;
|
||||||
@@ -668,7 +670,7 @@ class Battleground
|
|||||||
uint32 m_MinPlayersPerTeam;
|
uint32 m_MinPlayersPerTeam;
|
||||||
uint32 m_MinPlayers;
|
uint32 m_MinPlayers;
|
||||||
|
|
||||||
/* Start location */
|
// Start location
|
||||||
uint32 m_MapId;
|
uint32 m_MapId;
|
||||||
BattlegroundMap* m_Map;
|
BattlegroundMap* m_Map;
|
||||||
float m_TeamStartLocX[BG_TEAMS_COUNT];
|
float m_TeamStartLocX[BG_TEAMS_COUNT];
|
||||||
|
|||||||
Reference in New Issue
Block a user