AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
BfCapturePoint Class Reference

#include "Battlefield.h"

Inheritance diagram for BfCapturePoint:
WintergraspCapturePoint

Public Member Functions

 BfCapturePoint (Battlefield *bf)
 
virtual ~BfCapturePoint ()
 
virtual void FillInitialWorldStates (WorldPackets::WorldState::InitWorldStates &)
 
void SendUpdateWorldState (uint32 field, uint32 value)
 
void SendObjectiveComplete (uint32 id, ObjectGuid guid)
 
virtual bool HandlePlayerEnter (Player *player)
 
virtual GuidUnorderedSet::iterator HandlePlayerLeave (Player *player)
 
bool IsInsideObjective (Player *player) const
 
virtual bool Update (uint32 diff)
 
virtual void ChangeTeam (TeamId)
 
virtual void SendChangePhase ()
 
bool SetCapturePointData (GameObject *capturePoint, TeamId team)
 
GameObjectGetCapturePointGo ()
 
GameObjectGetCapturePointGo (WorldObject *obj)
 
TeamId GetTeamId ()
 

Protected Member Functions

bool DelCapturePoint ()
 

Protected Attributes

GuidUnorderedSet m_activePlayers [2]
 
float m_maxValue
 
float m_minValue
 
float m_maxSpeed
 
float m_value
 
TeamId m_team
 
BattlefieldObjectiveStates m_OldState
 
BattlefieldObjectiveStates m_State
 
uint32 m_neutralValuePct
 
Battlefieldm_Bf
 
uint32 m_capturePointEntry
 
ObjectGuid m_capturePoint
 

Detailed Description

Constructor & Destructor Documentation

◆ BfCapturePoint()

BfCapturePoint::BfCapturePoint ( Battlefield bf)
878 : m_Bf(battlefield)
879{
881 m_value = 0;
882 m_minValue = 0.0f;
883 m_maxValue = 0.0f;
888 m_maxSpeed = 0;
889}
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL
Definition Battlefield.h:40
@ TEAM_NEUTRAL
Definition SharedDefines.h:762
Battlefield * m_Bf
Definition Battlefield.h:136
float m_minValue
Definition Battlefield.h:119
BattlefieldObjectiveStates m_OldState
Definition Battlefield.h:129
float m_maxSpeed
Definition Battlefield.h:122
float m_value
Definition Battlefield.h:125
float m_maxValue
Definition Battlefield.h:118
uint32 m_capturePointEntry
Definition Battlefield.h:139
uint32 m_neutralValuePct
Definition Battlefield.h:133
TeamId m_team
Definition Battlefield.h:126
BattlefieldObjectiveStates m_State
Definition Battlefield.h:130

References BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL, m_capturePointEntry, m_maxSpeed, m_maxValue, m_minValue, m_neutralValuePct, m_OldState, m_State, m_team, m_value, and TEAM_NEUTRAL.

◆ ~BfCapturePoint()

virtual BfCapturePoint::~BfCapturePoint ( )
inlinevirtual
82{ }

Member Function Documentation

◆ ChangeTeam()

virtual void BfCapturePoint::ChangeTeam ( TeamId  )
inlinevirtual

Reimplemented in WintergraspCapturePoint.

102{}

Referenced by Update().

◆ DelCapturePoint()

bool BfCapturePoint::DelCapturePoint ( )
protected
975{
976 if (GameObject* capturePoint = GetCapturePointGo())
977 {
978 capturePoint->SetRespawnTime(0); // not save respawn time
979 capturePoint->Delete();
981 }
982
983 return true;
984}
ObjectGuid m_capturePoint
Definition Battlefield.h:142
GameObject * GetCapturePointGo()
Definition Battlefield.cpp:986
Definition GameObject.h:120
void Clear()
Definition ObjectGuid.h:138

References ObjectGuid::Clear(), GetCapturePointGo(), and m_capturePoint.

◆ FillInitialWorldStates()

virtual void BfCapturePoint::FillInitialWorldStates ( WorldPackets::WorldState::InitWorldStates )
inlinevirtual
84{ }

◆ GetCapturePointGo() [1/2]

GameObject * BfCapturePoint::GetCapturePointGo ( )
987{
989}
GameObject * GetGameObject(ObjectGuid const guid)
Definition Battlefield.cpp:866

References Battlefield::GetGameObject(), m_Bf, and m_capturePoint.

Referenced by DelCapturePoint(), HandlePlayerEnter(), HandlePlayerLeave(), SendChangePhase(), and Update().

◆ GetCapturePointGo() [2/2]

GameObject * BfCapturePoint::GetCapturePointGo ( WorldObject obj)
992{
994}
GameObject * GetGameObject(WorldObject const &u, ObjectGuid const guid)
Definition ObjectAccessor.cpp:184

References ObjectAccessor::GetGameObject(), and m_capturePoint.

◆ GetTeamId()

TeamId BfCapturePoint::GetTeamId ( )
inline
110{ return m_team; }

References m_team.

◆ HandlePlayerEnter()

bool BfCapturePoint::HandlePlayerEnter ( Player player)
virtual
892{
893 if (GameObject* go = GetCapturePointGo(player))
894 {
895 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldState1, 1);
896 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate2, uint32(std::ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f)));
897 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate3, m_neutralValuePct);
898 }
899 return m_activePlayers[player->GetTeamId()].insert(player->GetGUID()).second;
900}
std::uint32_t uint32
Definition Define.h:107
GuidUnorderedSet m_activePlayers[2]
Definition Battlefield.h:115
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:112
void SendUpdateWorldState(uint32 variable, uint32 value) const
Definition PlayerUpdates.cpp:2243
TeamId GetTeamId(bool original=false) const
Definition Player.h:2116

References GetCapturePointGo(), Object::GetGUID(), Player::GetTeamId(), m_activePlayers, m_maxValue, m_neutralValuePct, m_value, and Player::SendUpdateWorldState().

Referenced by Update().

◆ HandlePlayerLeave()

GuidUnorderedSet::iterator BfCapturePoint::HandlePlayerLeave ( Player player)
virtual
903{
904 if (GameObject* go = GetCapturePointGo(player))
905 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldState1, 0);
906
907 GuidUnorderedSet::iterator current = m_activePlayers[player->GetTeamId()].find(player->GetGUID());
908
909 if (current == m_activePlayers[player->GetTeamId()].end())
910 return current; // return end()
911
912 current = m_activePlayers[player->GetTeamId()].erase(current);
913 return current;
914}

References GetCapturePointGo(), Object::GetGUID(), Player::GetTeamId(), m_activePlayers, and Player::SendUpdateWorldState().

Referenced by Update().

◆ IsInsideObjective()

bool BfCapturePoint::IsInsideObjective ( Player player) const
1145{
1146 return m_activePlayers[player->GetTeamId()].find(player->GetGUID()) != m_activePlayers[player->GetTeamId()].end();
1147}

References Object::GetGUID(), Player::GetTeamId(), and m_activePlayers.

◆ SendChangePhase()

void BfCapturePoint::SendChangePhase ( )
virtual
917{
918 GameObject* capturePoint = GetCapturePointGo();
919 if (!capturePoint)
920 return;
921
922 for (uint8 team = 0; team < 2; ++team)
923 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr) // send to all players present in the area
924 if (Player* player = ObjectAccessor::FindPlayer(*itr))
925 {
926 // send this too, sometimes the slider disappears, dunno why :(
927 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldState1, 1);
928 // send these updates to only the ones in this objective
929 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate2, (uint32) std::ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f));
930 // send this too, sometimes it resets :S
931 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate3, m_neutralValuePct);
932 }
933}
std::uint8_t uint8
Definition Define.h:109
GameObjectTemplate const * GetGOInfo() const
Definition GameObject.h:136
Definition Player.h:1081
Player * FindPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:245
uint32 worldstate3
Definition GameObjectData.h:315
uint32 worldstate2
Definition GameObjectData.h:305
uint32 worldState1
Definition GameObjectData.h:223
struct GameObjectTemplate::@231::@255 capturePoint

References GameObjectTemplate::capturePoint, ObjectAccessor::FindPlayer(), GetCapturePointGo(), GameObject::GetGOInfo(), m_activePlayers, m_maxValue, m_neutralValuePct, m_value, GameObjectTemplate::worldState1, GameObjectTemplate::worldstate2, and GameObjectTemplate::worldstate3.

Referenced by Update().

◆ SendObjectiveComplete()

void BfCapturePoint::SendObjectiveComplete ( uint32  id,
ObjectGuid  guid 
)
1124{
1125 uint8 team;
1126 switch (m_State)
1127 {
1129 team = 0;
1130 break;
1132 team = 1;
1133 break;
1134 default:
1135 return;
1136 }
1137
1138 // send to all players present in the area
1139 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr)
1140 if (Player* player = ObjectAccessor::FindPlayer(*itr))
1141 player->KilledMonsterCredit(id, guid);
1142}
@ BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE
Definition Battlefield.h:42
@ BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE
Definition Battlefield.h:41

References BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE, BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE, ObjectAccessor::FindPlayer(), m_activePlayers, and m_State.

◆ SendUpdateWorldState()

void BfCapturePoint::SendUpdateWorldState ( uint32  field,
uint32  value 
)
1116{
1117 for (uint8 team = 0; team < 2; ++team)
1118 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr) // send to all players present in the area
1119 if (Player* player = ObjectAccessor::FindPlayer(*itr))
1120 player->SendUpdateWorldState(field, value);
1121}

References ObjectAccessor::FindPlayer(), and m_activePlayers.

◆ SetCapturePointData()

bool BfCapturePoint::SetCapturePointData ( GameObject capturePoint,
TeamId  team 
)
936{
937 ASSERT(capturePoint);
938
939 //At first call using TEAM_NEUTRAL as a checker but never using it, after first call we reset the capturepoints to the new winner of the last WG war
940 if (team == TEAM_NEUTRAL)
941 team = m_team;
942 LOG_DEBUG("bg.battlefield", "Creating capture point {}", capturePoint->GetEntry());
943
944 m_capturePoint = capturePoint->GetGUID();
945
946 // check info existence
947 GameObjectTemplate const* goinfo = capturePoint->GetGOInfo();
948 if (goinfo->type != GAMEOBJECT_TYPE_CAPTURE_POINT)
949 {
950 LOG_ERROR("bg.battlefield", "OutdoorPvP: GO {} is not capture point!", capturePoint->GetEntry());
951 return false;
952 }
953
954 // get the needed values from goinfo
956 m_maxSpeed = m_maxValue / (goinfo->capturePoint.minTime ? goinfo->capturePoint.minTime : 60);
959 m_capturePointEntry = capturePoint->GetEntry();
960 if (team == TEAM_ALLIANCE)
961 {
964 }
965 else
966 {
969 }
970
971 return true;
972}
#define ASSERT
Definition Errors.h:68
#define LOG_ERROR(filterType__,...)
Definition Log.h:157
#define LOG_DEBUG(filterType__,...)
Definition Log.h:169
@ GAMEOBJECT_TYPE_CAPTURE_POINT
Definition SharedDefines.h:1589
@ TEAM_ALLIANCE
Definition SharedDefines.h:760
uint32 GetEntry() const
Definition Object.h:115
Definition GameObjectData.h:31
uint32 type
Definition GameObjectData.h:33
uint32 minTime
Definition GameObjectData.h:318
uint32 neutralPercent
Definition GameObjectData.h:314
uint32 maxTime
Definition GameObjectData.h:319

References ASSERT, BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE, BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE, GameObjectTemplate::capturePoint, GAMEOBJECT_TYPE_CAPTURE_POINT, Object::GetEntry(), GameObject::GetGOInfo(), Object::GetGUID(), LOG_DEBUG, LOG_ERROR, m_capturePoint, m_capturePointEntry, m_maxSpeed, m_maxValue, m_minValue, m_neutralValuePct, m_State, m_team, m_value, GameObjectTemplate::maxTime, GameObjectTemplate::minTime, GameObjectTemplate::neutralPercent, TEAM_ALLIANCE, TEAM_NEUTRAL, and GameObjectTemplate::type.

Referenced by BattlefieldWG::OnGameObjectCreate().

◆ Update()

bool BfCapturePoint::Update ( uint32  diff)
virtual
997{
998 GameObject* capturePoint = GetCapturePointGo();
999 if (!capturePoint)
1000 return false;
1001
1002 float radius = capturePoint->GetGOInfo()->capturePoint.radius;
1003
1004 for (uint8 team = 0; team < 2; ++team)
1005 {
1006 for (GuidUnorderedSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end();)
1007 {
1008 if (Player* player = ObjectAccessor::FindPlayer(*itr))
1009 if (!capturePoint->IsWithinDistInMap(player, radius) || !player->IsOutdoorPvPActive())
1010 {
1011 itr = HandlePlayerLeave(player);
1012 continue;
1013 }
1014
1015 ++itr;
1016 }
1017 }
1018
1019 std::list<Player*> players;
1020 Acore::AnyPlayerInObjectRangeCheck checker(capturePoint, radius);
1021 Acore::PlayerListSearcher<Acore::AnyPlayerInObjectRangeCheck> searcher(capturePoint, players, checker);
1022 Cell::VisitWorldObjects(capturePoint, searcher, radius);
1023
1024 for (std::list<Player*>::iterator itr = players.begin(); itr != players.end(); ++itr)
1025 if ((*itr)->IsOutdoorPvPActive())
1026 if (m_activePlayers[(*itr)->GetTeamId()].insert((*itr)->GetGUID()).second)
1027 HandlePlayerEnter(*itr);
1028
1029 // get the difference of numbers
1030 float fact_diff = ((float) m_activePlayers[0].size() - (float) m_activePlayers[1].size()) * diff / BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL;
1031 if (G3D::fuzzyEq(fact_diff, 0.0f))
1032 return false;
1033
1034 TeamId ChallengerId = TEAM_NEUTRAL;
1035 float maxDiff = m_maxSpeed * diff;
1036
1037 if (fact_diff < 0)
1038 {
1039 // horde is in majority, but it's already horde-controlled -> no change
1041 return false;
1042
1043 if (fact_diff < -maxDiff)
1044 fact_diff = -maxDiff;
1045
1046 ChallengerId = TEAM_HORDE;
1047 }
1048 else
1049 {
1050 // ally is in majority, but it's already ally-controlled -> no change
1052 return false;
1053
1054 if (fact_diff > maxDiff)
1055 fact_diff = maxDiff;
1056
1057 ChallengerId = TEAM_ALLIANCE;
1058 }
1059
1060 float oldValue = m_value;
1061 TeamId oldTeam = m_team;
1062
1064
1065 m_value += fact_diff;
1066
1067 if (m_value < -m_minValue) // red
1068 {
1069 if (m_value < -m_maxValue)
1073 }
1074 else if (m_value > m_minValue) // blue
1075 {
1076 if (m_value > m_maxValue)
1080 }
1081 else if (oldValue * m_value <= 0) // grey, go through mid point
1082 {
1083 // if challenger is ally, then n->a challenge
1084 if (ChallengerId == TEAM_ALLIANCE)
1086 // if challenger is horde, then n->h challenge
1087 else if (ChallengerId == TEAM_HORDE)
1090 }
1091 else // grey, did not go through mid point
1092 {
1093 // old phase and current are on the same side, so one team challenges the other
1099 }
1100
1101 if (G3D::fuzzyNe(m_value, oldValue))
1103
1104 if (m_OldState != m_State)
1105 {
1106 //LOG_ERROR("bg.battlefield", "{}->{}", m_OldState, m_State);
1107 if (oldTeam != m_team)
1108 ChangeTeam(oldTeam);
1109 return true;
1110 }
1111
1112 return false;
1113}
constexpr auto BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL
Definition Battlefield.h:56
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE
Definition Battlefield.h:44
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE
Definition Battlefield.h:43
@ BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE
Definition Battlefield.h:45
@ BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE
Definition Battlefield.h:46
TeamId
Definition SharedDefines.h:759
@ TEAM_HORDE
Definition SharedDefines.h:761
Definition GridNotifiers.h:1354
virtual GuidUnorderedSet::iterator HandlePlayerLeave(Player *player)
Definition Battlefield.cpp:902
virtual bool HandlePlayerEnter(Player *player)
Definition Battlefield.cpp:891
virtual void ChangeTeam(TeamId)
Definition Battlefield.h:102
virtual void SendChangePhase()
Definition Battlefield.cpp:916
bool IsWithinDistInMap(Player const *player) const
Definition GameObject.cpp:2988
Definition GridNotifiers.h:525
static void VisitWorldObjects(WorldObject const *obj, T &visitor, float radius)
Definition CellImpl.h:175
uint32 radius
Definition GameObjectData.h:196

References BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL, BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE, BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE, BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE, BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE, BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE, BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE, GameObjectTemplate::capturePoint, ChangeTeam(), ObjectAccessor::FindPlayer(), GetCapturePointGo(), GameObject::GetGOInfo(), HandlePlayerEnter(), HandlePlayerLeave(), GameObject::IsWithinDistInMap(), m_activePlayers, m_maxSpeed, m_maxValue, m_minValue, m_OldState, m_State, m_team, m_value, GameObjectTemplate::radius, SendChangePhase(), TEAM_ALLIANCE, TEAM_HORDE, TEAM_NEUTRAL, and Cell::VisitWorldObjects().

Member Data Documentation

◆ m_activePlayers

◆ m_Bf

Battlefield* BfCapturePoint::m_Bf
protected

◆ m_capturePoint

ObjectGuid BfCapturePoint::m_capturePoint
protected

◆ m_capturePointEntry

uint32 BfCapturePoint::m_capturePointEntry
protected

◆ m_maxSpeed

float BfCapturePoint::m_maxSpeed
protected

◆ m_maxValue

float BfCapturePoint::m_maxValue
protected

◆ m_minValue

float BfCapturePoint::m_minValue
protected

◆ m_neutralValuePct

uint32 BfCapturePoint::m_neutralValuePct
protected

◆ m_OldState

BattlefieldObjectiveStates BfCapturePoint::m_OldState
protected

Referenced by BfCapturePoint(), and Update().

◆ m_State

◆ m_team

◆ m_value

float BfCapturePoint::m_value
protected

The documentation for this class was generated from the following files: