TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BfCapturePoint Class Reference

#include <Battlefield.h>

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 GuidSet::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)
 
GameObjectGetCapturePointGo ()
 
uint32 GetCapturePointEntry () const
 
TeamId GetTeamId () const
 

Protected Member Functions

bool DelCapturePoint ()
 

Protected Attributes

GuidSet m_activePlayers [BG_TEAMS_COUNT]
 
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_capturePointGUID
 

Constructor & Destructor Documentation

BfCapturePoint::BfCapturePoint ( Battlefield bf)
863  : m_Bf(battlefield), m_capturePointGUID()
864 {
866  m_value = 0;
867  m_minValue = 0.0f;
868  m_maxValue = 0.0f;
872  m_neutralValuePct = 0;
873  m_maxSpeed = 0;
874 }
float m_maxSpeed
Definition: Battlefield.h:126
BattlefieldObjectiveStates m_State
Definition: Battlefield.h:134
ObjectGuid m_capturePointGUID
Definition: Battlefield.h:146
Definition: Battlefield.h:47
float m_minValue
Definition: Battlefield.h:123
Definition: SharedDefines.h:994
uint32 m_neutralValuePct
Definition: Battlefield.h:137
TeamId m_team
Definition: Battlefield.h:130
float m_maxValue
Definition: Battlefield.h:122
BattlefieldObjectiveStates m_OldState
Definition: Battlefield.h:133
Battlefield * m_Bf
Definition: Battlefield.h:140
uint32 m_capturePointEntry
Definition: Battlefield.h:143
float m_value
Definition: Battlefield.h:129
virtual BfCapturePoint::~BfCapturePoint ( )
inlinevirtual
86 { }

Member Function Documentation

virtual void BfCapturePoint::ChangeTeam ( TeamId  )
inlinevirtual

Reimplemented in WintergraspCapturePoint.

106 { }

+ Here is the caller graph for this function:

bool BfCapturePoint::DelCapturePoint ( )
protected
965 {
967  {
968  if (GameObject* capturePoint = m_Bf->GetGameObject(m_capturePointGUID))
969  {
970  capturePoint->SetRespawnTime(0); // not save respawn time
971  capturePoint->Delete();
972  capturePoint = NULL;
973  }
975  }
976 
977  return true;
978 }
arena_t NULL
Definition: jemalloc_internal.h:624
ObjectGuid m_capturePointGUID
Definition: Battlefield.h:146
Definition: GameObject.h:880
void Clear()
Definition: ObjectGuid.h:215
Battlefield * m_Bf
Definition: Battlefield.h:140
GameObject * GetGameObject(ObjectGuid guid)
Definition: Battlefield.cpp:852
bool IsEmpty() const
Definition: ObjectGuid.h:242

+ Here is the call graph for this function:

virtual void BfCapturePoint::FillInitialWorldStates ( WorldPackets::WorldState::InitWorldStates )
inlinevirtual
88 { }
uint32 BfCapturePoint::GetCapturePointEntry ( ) const
inline
111 { return m_capturePointEntry; }
uint32 m_capturePointEntry
Definition: Battlefield.h:143

+ Here is the caller graph for this function:

GameObject * BfCapturePoint::GetCapturePointGo ( )
960 {
962 }
ObjectGuid m_capturePointGUID
Definition: Battlefield.h:146
Battlefield * m_Bf
Definition: Battlefield.h:140
GameObject * GetGameObject(ObjectGuid guid)
Definition: Battlefield.cpp:852

+ Here is the call graph for this function:

TeamId BfCapturePoint::GetTeamId ( ) const
inline
113 { return m_team; }
TeamId m_team
Definition: Battlefield.h:130
bool BfCapturePoint::HandlePlayerEnter ( Player player)
virtual
877 {
879  {
880  if (GameObject* capturePoint = m_Bf->GetGameObject(m_capturePointGUID))
881  {
882  player->SendUpdateWorldState(capturePoint->GetGOInfo()->controlZone.worldState1, 1);
883  player->SendUpdateWorldState(capturePoint->GetGOInfo()->controlZone.worldstate2, uint32(ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f)));
884  player->SendUpdateWorldState(capturePoint->GetGOInfo()->controlZone.worldstate3, m_neutralValuePct);
885  }
886  }
887 
888  return m_activePlayers[player->GetTeamId()].insert(player->GetGUID()).second;
889 }
ObjectGuid m_capturePointGUID
Definition: Battlefield.h:146
uint32 m_neutralValuePct
Definition: Battlefield.h:137
Definition: GameObject.h:880
float m_maxValue
Definition: Battlefield.h:122
GuidSet m_activePlayers[BG_TEAMS_COUNT]
Definition: Battlefield.h:119
uint32_t uint32
Definition: g3dmath.h:168
Battlefield * m_Bf
Definition: Battlefield.h:140
static Vector3int16 ceil(const Vector3 &v)
Definition: Vector3int16.cpp:55
float m_value
Definition: Battlefield.h:129
GameObject * GetGameObject(ObjectGuid guid)
Definition: Battlefield.cpp:852
bool IsEmpty() const
Definition: ObjectGuid.h:242

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

GuidSet::iterator BfCapturePoint::HandlePlayerLeave ( Player player)
virtual
892 {
894  if (GameObject* capturePoint = m_Bf->GetGameObject(m_capturePointGUID))
895  player->SendUpdateWorldState(capturePoint->GetGOInfo()->controlZone.worldState1, 0);
896 
897  GuidSet::iterator current = m_activePlayers[player->GetTeamId()].find(player->GetGUID());
898 
899  if (current == m_activePlayers[player->GetTeamId()].end())
900  return current; // return end()
901 
902  m_activePlayers[player->GetTeamId()].erase(current++);
903  return current;
904 }
ObjectGuid m_capturePointGUID
Definition: Battlefield.h:146
Definition: GameObject.h:880
GuidSet m_activePlayers[BG_TEAMS_COUNT]
Definition: Battlefield.h:119
Battlefield * m_Bf
Definition: Battlefield.h:140
GameObject * GetGameObject(ObjectGuid guid)
Definition: Battlefield.cpp:852
bool IsEmpty() const
Definition: ObjectGuid.h:242

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool BfCapturePoint::IsInsideObjective ( Player player) const
1132 {
1133  return m_activePlayers[player->GetTeamId()].find(player->GetGUID()) != m_activePlayers[player->GetTeamId()].end();
1134 }
GuidSet m_activePlayers[BG_TEAMS_COUNT]
Definition: Battlefield.h:119
void BfCapturePoint::SendChangePhase ( )
virtual
907 {
908  if (!m_capturePointGUID)
909  return;
910 
911  if (GameObject* capturePoint = m_Bf->GetGameObject(m_capturePointGUID))
912  {
913  // send this too, sometimes the slider disappears, dunno why :(
914  SendUpdateWorldState(capturePoint->GetGOInfo()->controlZone.worldState1, 1);
915  // send these updates to only the ones in this objective
916  SendUpdateWorldState(capturePoint->GetGOInfo()->controlZone.worldstate2, (uint32)std::ceil((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f));
917  // send this too, sometimes it resets :S
918  SendUpdateWorldState(capturePoint->GetGOInfo()->controlZone.worldstate3, m_neutralValuePct);
919  }
920 }
ObjectGuid m_capturePointGUID
Definition: Battlefield.h:146
void SendUpdateWorldState(uint32 field, uint32 value)
Definition: Battlefield.cpp:1102
uint32 m_neutralValuePct
Definition: Battlefield.h:137
Definition: GameObject.h:880
float m_maxValue
Definition: Battlefield.h:122
uint32_t uint32
Definition: g3dmath.h:168
Battlefield * m_Bf
Definition: Battlefield.h:140
static Vector3int16 ceil(const Vector3 &v)
Definition: Vector3int16.cpp:55
float m_value
Definition: Battlefield.h:129
GameObject * GetGameObject(ObjectGuid guid)
Definition: Battlefield.cpp:852

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BfCapturePoint::SendObjectiveComplete ( uint32  id,
ObjectGuid  guid 
)
1111 {
1112  uint8 team;
1113  switch (m_State)
1114  {
1116  team = 0;
1117  break;
1119  team = 1;
1120  break;
1121  default:
1122  return;
1123  }
1124 
1125  // send to all players present in the area
1126  for (GuidSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr)
1127  if (Player* player = ObjectAccessor::FindPlayer(*itr))
1128  player->KilledMonsterCredit(id, guid);
1129 }
Definition: Battlefield.h:49
BattlefieldObjectiveStates m_State
Definition: Battlefield.h:134
TC_GAME_API Player * FindPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:209
uint8_t uint8
Definition: Define.h:152
GuidSet m_activePlayers[BG_TEAMS_COUNT]
Definition: Battlefield.h:119
Definition: Battlefield.h:48

+ Here is the call graph for this function:

void BfCapturePoint::SendUpdateWorldState ( uint32  field,
uint32  value 
)
1103 {
1104  for (uint8 team = 0; team < 2; ++team)
1105  for (GuidSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end(); ++itr) // send to all players present in the area
1106  if (Player* player = ObjectAccessor::FindPlayer(*itr))
1107  player->SendUpdateWorldState(field, value);
1108 }
TC_GAME_API Player * FindPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:209
uint8_t uint8
Definition: Define.h:152
GuidSet m_activePlayers[BG_TEAMS_COUNT]
Definition: Battlefield.h:119
const FieldDescriptor value
Definition: descriptor.h:1522

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool BfCapturePoint::SetCapturePointData ( GameObject capturePoint)
923 {
924  ASSERT(capturePoint);
925 
926  TC_LOG_DEBUG("bg.battlefield", "Creating capture point %u", capturePoint->GetEntry());
927 
928  m_capturePointGUID = capturePoint->GetGUID();
929  m_capturePointEntry = capturePoint->GetEntry();
930 
931  // check info existence
932  GameObjectTemplate const* goinfo = capturePoint->GetGOInfo();
933  if (goinfo->type != GAMEOBJECT_TYPE_CONTROL_ZONE)
934  {
935  TC_LOG_ERROR("misc", "OutdoorPvP: GO %u is not capture point!", capturePoint->GetEntry());
936  return false;
937  }
938 
939  // get the needed values from goinfo
940  m_maxValue = goinfo->controlZone.maxTime;
941  m_maxSpeed = m_maxValue / (goinfo->controlZone.minTime ? goinfo->controlZone.minTime : 60);
942  m_neutralValuePct = goinfo->controlZone.neutralPercent;
943  m_minValue = m_maxValue * goinfo->controlZone.neutralPercent / 100;
944 
945  if (m_team == TEAM_ALLIANCE)
946  {
949  }
950  else
951  {
952  m_value = -m_maxValue;
954  }
955 
956  return true;
957 }
Definition: Battlefield.h:49
float m_maxSpeed
Definition: Battlefield.h:126
Definition: SharedDefines.h:2094
Definition: GameObject.h:34
BattlefieldObjectiveStates m_State
Definition: Battlefield.h:134
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
ObjectGuid m_capturePointGUID
Definition: Battlefield.h:146
float m_minValue
Definition: Battlefield.h:123
uint32 m_neutralValuePct
Definition: Battlefield.h:137
TeamId m_team
Definition: Battlefield.h:130
GameObjectTemplate const * GetGOInfo() const
Definition: GameObject.h:894
Definition: SharedDefines.h:992
ObjectGuid const & GetGUID() const
Definition: Object.h:105
float m_maxValue
Definition: Battlefield.h:122
#define ASSERT
Definition: Errors.h:55
struct GameObjectTemplate::@221::@252 controlZone
uint32 GetEntry() const
Definition: Object.h:107
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
Definition: Battlefield.h:48
uint32 m_capturePointEntry
Definition: Battlefield.h:143
float m_value
Definition: Battlefield.h:129
uint32 type
Definition: GameObject.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool BfCapturePoint::Update ( uint32  diff)
virtual
981 {
982  if (!m_capturePointGUID)
983  return false;
984 
985  if (GameObject* capturePoint = m_Bf->GetGameObject(m_capturePointGUID))
986  {
987  float radius = capturePoint->GetGOInfo()->controlZone.radius;
988 
989  for (uint8 team = 0; team < 2; ++team)
990  {
991  for (GuidSet::iterator itr = m_activePlayers[team].begin(); itr != m_activePlayers[team].end();)
992  {
993  if (Player* player = ObjectAccessor::FindPlayer(*itr))
994  {
995  if (!capturePoint->IsWithinDistInMap(player, radius) || !player->IsOutdoorPvPActive())
996  itr = HandlePlayerLeave(player);
997  else
998  ++itr;
999  }
1000  else
1001  ++itr;
1002  }
1003  }
1004 
1005  std::list<Player*> players;
1006  Trinity::AnyPlayerInObjectRangeCheck checker(capturePoint, radius);
1007  Trinity::PlayerListSearcher<Trinity::AnyPlayerInObjectRangeCheck> searcher(capturePoint, players, checker);
1008  capturePoint->VisitNearbyWorldObject(radius, searcher);
1009 
1010  for (std::list<Player*>::iterator itr = players.begin(); itr != players.end(); ++itr)
1011  if ((*itr)->IsOutdoorPvPActive())
1012  if (m_activePlayers[(*itr)->GetTeamId()].insert((*itr)->GetGUID()).second)
1013  HandlePlayerEnter(*itr);
1014  }
1015 
1016  // get the difference of numbers
1017  float fact_diff = ((float) m_activePlayers[0].size() - (float) m_activePlayers[1].size()) * diff / BATTLEFIELD_OBJECTIVE_UPDATE_INTERVAL;
1018  if (G3D::fuzzyEq(fact_diff, 0.0f))
1019  return false;
1020 
1021  uint32 Challenger = 0;
1022  float maxDiff = m_maxSpeed * diff;
1023 
1024  if (fact_diff < 0)
1025  {
1026  // horde is in majority, but it's already horde-controlled -> no change
1028  return false;
1029 
1030  if (fact_diff < -maxDiff)
1031  fact_diff = -maxDiff;
1032 
1033  Challenger = HORDE;
1034  }
1035  else
1036  {
1037  // ally is in majority, but it's already ally-controlled -> no change
1039  return false;
1040 
1041  if (fact_diff > maxDiff)
1042  fact_diff = maxDiff;
1043 
1044  Challenger = ALLIANCE;
1045  }
1046 
1047  float oldValue = m_value;
1048  TeamId oldTeam = m_team;
1049 
1050  m_OldState = m_State;
1051 
1052  m_value += fact_diff;
1053 
1054  if (m_value < -m_minValue) // red
1055  {
1056  if (m_value < -m_maxValue)
1057  m_value = -m_maxValue;
1059  m_team = TEAM_HORDE;
1060  }
1061  else if (m_value > m_minValue) // blue
1062  {
1063  if (m_value > m_maxValue)
1064  m_value = m_maxValue;
1067  }
1068  else if (oldValue * m_value <= 0) // grey, go through mid point
1069  {
1070  // if challenger is ally, then n->a challenge
1071  if (Challenger == ALLIANCE)
1073  // if challenger is horde, then n->h challenge
1074  else if (Challenger == HORDE)
1076  m_team = TEAM_NEUTRAL;
1077  }
1078  else // grey, did not go through mid point
1079  {
1080  // old phase and current are on the same side, so one team challenges the other
1085  m_team = TEAM_NEUTRAL;
1086  }
1087 
1088  if (G3D::fuzzyNe(m_value, oldValue))
1089  SendChangePhase();
1090 
1091  if (m_OldState != m_State)
1092  {
1093  //TC_LOG_ERROR("bg.battlefield", "%u->%u", m_OldState, m_State);
1094  if (oldTeam != m_team)
1095  ChangeTeam(oldTeam);
1096  return true;
1097  }
1098 
1099  return false;
1100 }
virtual void SendChangePhase()
Definition: Battlefield.cpp:906
Definition: Battlefield.h:49
virtual GuidSet::iterator HandlePlayerLeave(Player *player)
Definition: Battlefield.cpp:891
float m_maxSpeed
Definition: Battlefield.h:126
Definition: GridNotifiers.h:1188
BattlefieldObjectiveStates m_State
Definition: Battlefield.h:134
bool fuzzyNe(double a, double b)
Definition: g3dmath.h:861
Definition: GridNotifiers.h:510
ObjectGuid m_capturePointGUID
Definition: Battlefield.h:146
float m_minValue
Definition: Battlefield.h:123
Definition: SharedDefines.h:994
Definition: SharedDefines.h:1000
virtual void ChangeTeam(TeamId)
Definition: Battlefield.h:106
TC_GAME_API Player * FindPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:209
Definition: Battlefield.h:65
TeamId m_team
Definition: Battlefield.h:130
uint32_t uint32
Definition: Define.h:150
Definition: SharedDefines.h:992
Definition: GameObject.h:880
TeamId
Definition: SharedDefines.h:990
Definition: SharedDefines.h:999
float m_maxValue
Definition: Battlefield.h:122
virtual bool HandlePlayerEnter(Player *player)
Definition: Battlefield.cpp:876
uint8_t uint8
Definition: Define.h:152
GuidSet m_activePlayers[BG_TEAMS_COUNT]
Definition: Battlefield.h:119
BattlefieldObjectiveStates m_OldState
Definition: Battlefield.h:133
Battlefield * m_Bf
Definition: Battlefield.h:140
Definition: Battlefield.h:48
Definition: SharedDefines.h:993
float m_value
Definition: Battlefield.h:129
bool fuzzyEq(double a, double b)
Definition: g3dmath.h:857
GameObject * GetGameObject(ObjectGuid guid)
Definition: Battlefield.cpp:852

+ Here is the call graph for this function:

Member Data Documentation

GuidSet BfCapturePoint::m_activePlayers[BG_TEAMS_COUNT]
protected
Battlefield* BfCapturePoint::m_Bf
protected
uint32 BfCapturePoint::m_capturePointEntry
protected
ObjectGuid BfCapturePoint::m_capturePointGUID
protected
float BfCapturePoint::m_maxSpeed
protected
float BfCapturePoint::m_maxValue
protected
float BfCapturePoint::m_minValue
protected
uint32 BfCapturePoint::m_neutralValuePct
protected
BattlefieldObjectiveStates BfCapturePoint::m_OldState
protected
BattlefieldObjectiveStates BfCapturePoint::m_State
protected
TeamId BfCapturePoint::m_team
protected
float BfCapturePoint::m_value
protected

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