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 () const
 

Protected Member Functions

bool DelCapturePoint ()
 

Protected Attributes

GuidUnorderedSet ActivePlayers
 
float MaxValue
 
float MinValue
 
float MaxSpeed
 
float Value
 
TeamId Team
 
BattlefieldObjectiveStates OldState
 
BattlefieldObjectiveStates State
 
uint32 NeutralValuePct
 
BattlefieldBf
 
uint32 CapturePointEntry
 
ObjectGuid CapturePoint
 

Detailed Description

Constructor & Destructor Documentation

◆ BfCapturePoint()

BfCapturePoint::BfCapturePoint ( Battlefield bf)
861 :
862 MaxValue(0.0f),
863 MinValue(0.0f),
864 MaxSpeed(0),
865 Value(0),
870 Bf(bf),
872{
873}
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL
Definition Battlefield.h:41
@ TEAM_NEUTRAL
Definition SharedDefines.h:750
float MaxValue
Definition Battlefield.h:128
float MinValue
Definition Battlefield.h:129
BattlefieldObjectiveStates State
Definition Battlefield.h:140
float MaxSpeed
Definition Battlefield.h:132
uint32 NeutralValuePct
Definition Battlefield.h:143
float Value
Definition Battlefield.h:135
TeamId Team
Definition Battlefield.h:136
Battlefield * Bf
Definition Battlefield.h:146
uint32 CapturePointEntry
Definition Battlefield.h:149
BattlefieldObjectiveStates OldState
Definition Battlefield.h:139

◆ ~BfCapturePoint()

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

Member Function Documentation

◆ ChangeTeam()

virtual void BfCapturePoint::ChangeTeam ( TeamId  )
inlinevirtual

Reimplemented in WintergraspCapturePoint.

109{}

Referenced by Update().

◆ DelCapturePoint()

bool BfCapturePoint::DelCapturePoint ( )
protected
957{
958 if (GameObject* capturePoint = GetCapturePointGo())
959 {
960 capturePoint->SetRespawnTime(0); // not save respawn time
961 capturePoint->Delete();
963 }
964
965 return true;
966}
GameObject * GetCapturePointGo()
Definition Battlefield.cpp:968
ObjectGuid CapturePoint
Definition Battlefield.h:152
Definition GameObject.h:120
void Clear()
Definition ObjectGuid.h:138

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

◆ FillInitialWorldStates()

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

◆ GetCapturePointGo() [1/2]

GameObject * BfCapturePoint::GetCapturePointGo ( )
969{
971}
GameObject * GetGameObject(ObjectGuid const &guid)
Definition Battlefield.cpp:853

References Bf, CapturePoint, and Battlefield::GetGameObject().

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

◆ GetCapturePointGo() [2/2]

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

References CapturePoint, and ObjectAccessor::GetGameObject().

◆ GetTeamId()

TeamId BfCapturePoint::GetTeamId ( ) const
inline
117{ return Team; }

References Team.

◆ HandlePlayerEnter()

bool BfCapturePoint::HandlePlayerEnter ( Player player)
virtual
876{
877 if (GameObject* go = GetCapturePointGo(player))
878 {
879 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldState1, 1);
880 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate2, uint32(std::ceil((Value + MaxValue) / (2 * MaxValue) * 100.0f)));
881 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldstate3, NeutralValuePct);
882 }
883 return ActivePlayers.insert(player->GetGUID()).second;
884}
std::uint32_t uint32
Definition Define.h:107
GuidUnorderedSet ActivePlayers
Definition Battlefield.h:125
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:114
void SendUpdateWorldState(uint32 variable, uint32 value) const
Definition PlayerUpdates.cpp:2240

References ActivePlayers, GetCapturePointGo(), Object::GetGUID(), MaxValue, NeutralValuePct, Player::SendUpdateWorldState(), and Value.

Referenced by Update().

◆ HandlePlayerLeave()

GuidUnorderedSet::iterator BfCapturePoint::HandlePlayerLeave ( Player player)
virtual
887{
888 if (GameObject* go = GetCapturePointGo(player))
889 player->SendUpdateWorldState(go->GetGOInfo()->capturePoint.worldState1, 0);
890
891 GuidUnorderedSet::iterator current = ActivePlayers.find(player->GetGUID());
892
893 if (current == ActivePlayers.end())
894 return current; // return end()
895
896 return ActivePlayers.erase(current);
897}

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

Referenced by Update().

◆ IsInsideObjective()

bool BfCapturePoint::IsInsideObjective ( Player player) const
1131{
1132 return ActivePlayers.find(player->GetGUID()) != ActivePlayers.end();
1133}

References ActivePlayers, and Object::GetGUID().

◆ SendChangePhase()

void BfCapturePoint::SendChangePhase ( )
virtual
900{
901 GameObject* capturePoint = GetCapturePointGo();
902 if (!capturePoint)
903 return;
904
905 for (ObjectGuid const& guid : ActivePlayers) // send to all players present in the area
906 if (Player* player = ObjectAccessor::FindPlayer(guid))
907 {
908 // send this too, sometimes the slider disappears, dunno why :(
909 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldState1, 1);
910 // send these updates to only the ones in this objective
911 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate2, (uint32) std::ceil((Value + MaxValue) / (2 * MaxValue) * 100.0f));
912 // send this too, sometimes it resets :S
913 player->SendUpdateWorldState(capturePoint->GetGOInfo()->capturePoint.worldstate3, NeutralValuePct);
914 }
915}
GameObjectTemplate const * GetGOInfo() const
Definition GameObject.h:136
Definition ObjectGuid.h:118
Definition Player.h:1084
Definition ObjectAccessor.h:61
Player * FindPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:245
uint32 worldstate3
Definition GameObjectData.h:316
uint32 worldstate2
Definition GameObjectData.h:306
struct GameObjectTemplate::@235::@259 capturePoint
uint32 worldState1
Definition GameObjectData.h:224

References ActivePlayers, GameObjectTemplate::capturePoint, ObjectAccessor::FindPlayer(), GetCapturePointGo(), GameObject::GetGOInfo(), MaxValue, NeutralValuePct, Value, GameObjectTemplate::worldState1, GameObjectTemplate::worldstate2, and GameObjectTemplate::worldstate3.

Referenced by Update().

◆ SendObjectiveComplete()

void BfCapturePoint::SendObjectiveComplete ( uint32  id,
ObjectGuid  guid 
)
1107{
1108 TeamId winner;
1109 switch (State)
1110 {
1112 winner = TEAM_ALLIANCE;
1113 break;
1115 winner = TEAM_HORDE;
1116 break;
1117 default:
1118 return;
1119 }
1120
1121 // Credit only players on the controlling team. Team is read from the
1122 // player at iteration time, not at insert time, so players whose
1123 // GetTeamId() changed mid-stay get credit on their current side.
1124 for (ObjectGuid const& playerGuid : ActivePlayers)
1125 if (Player* player = ObjectAccessor::FindPlayer(playerGuid))
1126 if (player->GetTeamId() == winner)
1127 player->KilledMonsterCredit(id, guid);
1128}
@ BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE
Definition Battlefield.h:43
@ BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE
Definition Battlefield.h:42
TeamId
Definition SharedDefines.h:747
@ TEAM_ALLIANCE
Definition SharedDefines.h:748
@ TEAM_HORDE
Definition SharedDefines.h:749
TeamId GetTeamId() const
Definition Battlefield.h:117

References ActivePlayers, BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE, BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE, ObjectAccessor::FindPlayer(), State, TEAM_ALLIANCE, and TEAM_HORDE.

◆ SendUpdateWorldState()

void BfCapturePoint::SendUpdateWorldState ( uint32  field,
uint32  value 
)
1100{
1101 for (ObjectGuid const& guid : ActivePlayers) // send to all players present in the area
1102 if (Player* player = ObjectAccessor::FindPlayer(guid))
1103 player->SendUpdateWorldState(field, value);
1104}
void SendUpdateWorldState(uint32 field, uint32 value)
Definition Battlefield.cpp:1099

References ActivePlayers, and ObjectAccessor::FindPlayer().

◆ SetCapturePointData()

bool BfCapturePoint::SetCapturePointData ( GameObject capturePoint,
TeamId  team 
)
918{
919 ASSERT(capturePoint);
920
921 //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
922 if (team == TEAM_NEUTRAL)
923 team = Team;
924 LOG_DEBUG("bg.battlefield", "Creating capture point {}", capturePoint->GetEntry());
925
926 CapturePoint = capturePoint->GetGUID();
927
928 // check info existence
929 GameObjectTemplate const* goinfo = capturePoint->GetGOInfo();
930 if (goinfo->type != GAMEOBJECT_TYPE_CAPTURE_POINT)
931 {
932 LOG_ERROR("bg.battlefield", "OutdoorPvP: GO {} is not capture point!", capturePoint->GetEntry());
933 return false;
934 }
935
936 // get the needed values from goinfo
937 MaxValue = goinfo->capturePoint.maxTime;
938 MaxSpeed = MaxValue / (goinfo->capturePoint.minTime ? goinfo->capturePoint.minTime : 60);
941 CapturePointEntry = capturePoint->GetEntry();
942 if (team == TEAM_ALLIANCE)
943 {
944 Value = MaxValue;
946 }
947 else
948 {
949 Value = -MaxValue;
951 }
952
953 return true;
954}
#define ASSERT
Definition Errors.h:68
#define LOG_ERROR(filterType__,...)
Definition Log.h:145
#define LOG_DEBUG(filterType__,...)
Definition Log.h:157
@ GAMEOBJECT_TYPE_CAPTURE_POINT
Definition SharedDefines.h:1593
uint32 GetEntry() const
Definition Object.h:117
Definition GameObjectData.h:32
uint32 type
Definition GameObjectData.h:34
uint32 minTime
Definition GameObjectData.h:319
uint32 neutralPercent
Definition GameObjectData.h:315
uint32 maxTime
Definition GameObjectData.h:320

References ASSERT, BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE, BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE, CapturePoint, GameObjectTemplate::capturePoint, CapturePointEntry, GAMEOBJECT_TYPE_CAPTURE_POINT, Object::GetEntry(), GameObject::GetGOInfo(), Object::GetGUID(), LOG_DEBUG, LOG_ERROR, MaxSpeed, GameObjectTemplate::maxTime, MaxValue, GameObjectTemplate::minTime, MinValue, GameObjectTemplate::neutralPercent, NeutralValuePct, State, Team, TEAM_ALLIANCE, TEAM_NEUTRAL, GameObjectTemplate::type, and Value.

Referenced by BattlefieldWG::OnGameObjectCreate().

◆ Update()

bool BfCapturePoint::Update ( uint32  diff)
virtual
979{
980 GameObject* capturePoint = GetCapturePointGo();
981 if (!capturePoint)
982 return false;
983
984 float radius = capturePoint->GetGOInfo()->capturePoint.radius;
985
986 // Single pass over the existing set: drop leavers, count survivors per team.
987 uint32 counts[PVP_TEAMS_COUNT] = { 0, 0 };
988 for (auto itr = ActivePlayers.begin(); itr != ActivePlayers.end();)
989 {
990 Player* player = ObjectAccessor::FindPlayer(*itr);
991 if (player && capturePoint->IsWithinDistInMap(player, radius) && player->IsOutdoorPvPActive())
992 {
993 ++counts[player->GetTeamId()];
994 ++itr;
995 continue;
996 }
997
998 itr = (player ? HandlePlayerLeave(player) : ActivePlayers.erase(itr));
999 }
1000
1001 std::list<Player*> players;
1002 Acore::AnyPlayerInObjectRangeCheck checker(capturePoint, radius);
1003 Acore::PlayerListSearcher<Acore::AnyPlayerInObjectRangeCheck> searcher(capturePoint, players, checker);
1004 Cell::VisitObjects(capturePoint, searcher, radius);
1005
1006 for (Player* player : players)
1007 if (player->IsOutdoorPvPActive())
1008 if (ActivePlayers.insert(player->GetGUID()).second)
1009 {
1010 HandlePlayerEnter(player);
1011 ++counts[player->GetTeamId()];
1012 }
1013
1014 // get the difference of numbers
1015 float factDiff = ((float)counts[TEAM_ALLIANCE] - (float)counts[TEAM_HORDE]) * diff / BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL;
1016 if (G3D::fuzzyEq(factDiff, 0.0f))
1017 return false;
1018
1019 TeamId challengerId = TEAM_NEUTRAL;
1020 float maxDiff = MaxSpeed * diff;
1021
1022 if (factDiff < 0)
1023 {
1024 // horde is in majority, but it's already horde-controlled -> no change
1026 return false;
1027
1028 if (factDiff < -maxDiff)
1029 factDiff = -maxDiff;
1030
1031 challengerId = TEAM_HORDE;
1032 }
1033 else
1034 {
1035 // ally is in majority, but it's already ally-controlled -> no change
1037 return false;
1038
1039 if (factDiff > maxDiff)
1040 factDiff = maxDiff;
1041
1042 challengerId = TEAM_ALLIANCE;
1043 }
1044
1045 float oldValue = Value;
1046 TeamId oldTeam = Team;
1047
1048 OldState = State;
1049
1050 Value += factDiff;
1051
1052 if (Value < -MinValue) // red
1053 {
1054 if (Value < -MaxValue)
1055 Value = -MaxValue;
1057 Team = TEAM_HORDE;
1058 }
1059 else if (Value > MinValue) // blue
1060 {
1061 if (Value > MaxValue)
1062 Value = MaxValue;
1065 }
1066 else if (oldValue * Value <= 0) // grey, go through mid point
1067 {
1068 // if challenger is ally, then n->a challenge
1069 if (challengerId == TEAM_ALLIANCE)
1071 // if challenger is horde, then n->h challenge
1072 else if (challengerId == TEAM_HORDE)
1075 }
1076 else // grey, did not go through mid point
1077 {
1078 // old phase and current are on the same side, so one team challenges the other
1084 }
1085
1086 if (G3D::fuzzyNe(Value, oldValue))
1088
1089 if (OldState != State)
1090 {
1091 if (oldTeam != Team)
1092 ChangeTeam(oldTeam);
1093 return true;
1094 }
1095
1096 return false;
1097}
constexpr auto BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL
Definition Battlefield.h:57
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE
Definition Battlefield.h:45
@ BF_CAPTUREPOINT_OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE
Definition Battlefield.h:44
@ BF_CAPTUREPOINT_OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE
Definition Battlefield.h:46
@ BF_CAPTUREPOINT_OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE
Definition Battlefield.h:47
uint8 constexpr PVP_TEAMS_COUNT
Definition SharedDefines.h:3701
Team
Definition SharedDefines.h:754
Definition GridNotifiers.h:1378
virtual GuidUnorderedSet::iterator HandlePlayerLeave(Player *player)
Definition Battlefield.cpp:886
virtual bool HandlePlayerEnter(Player *player)
Definition Battlefield.cpp:875
virtual void ChangeTeam(TeamId)
Definition Battlefield.h:109
virtual void SendChangePhase()
Definition Battlefield.cpp:899
bool IsWithinDistInMap(Player const *player) const
Definition GameObject.cpp:3023
TeamId GetTeamId(bool original=false) const
Definition Player.h:2131
bool IsOutdoorPvPActive()
Definition Player.cpp:6430
Definition GridNotifiers.h:546
static void VisitObjects(WorldObject const *obj, T &visitor, float radius)
Definition CellImpl.h:165
uint32 radius
Definition GameObjectData.h:197

References ActivePlayers, 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(), Player::GetTeamId(), HandlePlayerEnter(), HandlePlayerLeave(), Player::IsOutdoorPvPActive(), GameObject::IsWithinDistInMap(), MaxSpeed, MaxValue, MinValue, OldState, PVP_TEAMS_COUNT, GameObjectTemplate::radius, SendChangePhase(), State, Team, TEAM_ALLIANCE, TEAM_HORDE, TEAM_NEUTRAL, Value, and Cell::VisitObjects().

Member Data Documentation

◆ ActivePlayers

◆ Bf

Battlefield* BfCapturePoint::Bf
protected

◆ CapturePoint

ObjectGuid BfCapturePoint::CapturePoint
protected

◆ CapturePointEntry

uint32 BfCapturePoint::CapturePointEntry
protected

Referenced by SetCapturePointData().

◆ MaxSpeed

float BfCapturePoint::MaxSpeed
protected

Referenced by SetCapturePointData(), and Update().

◆ MaxValue

float BfCapturePoint::MaxValue
protected

◆ MinValue

float BfCapturePoint::MinValue
protected

Referenced by SetCapturePointData(), and Update().

◆ NeutralValuePct

uint32 BfCapturePoint::NeutralValuePct
protected

◆ OldState

BattlefieldObjectiveStates BfCapturePoint::OldState
protected

Referenced by Update().

◆ State

BattlefieldObjectiveStates BfCapturePoint::State
protected

◆ Team

TeamId BfCapturePoint::Team
protected

◆ Value

float BfCapturePoint::Value
protected

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