aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Entities/Unit
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2019-06-23 16:44:37 +0200
committerTreeston <treeston.mmoc@gmail.com>2019-06-23 16:44:37 +0200
commit396f87c30dff1b50f1eb0d924778a7fbab7e8d11 (patch)
tree6dda1fbf143a6a49cc0afa00e110d3fea34137ba /src/server/game/Entities/Unit
parentb3ee407707db01a5bc49f544a56b1db381687f65 (diff)
Entities/Unit: Cleanup all the direct accesses to m_unitMovedByMe. Refactor the field to be protected. Add assertions to catch dangling pointers.
Diffstat (limited to 'src/server/game/Entities/Unit')
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp29
-rw-r--r--src/server/game/Entities/Unit/Unit.h12
2 files changed, 19 insertions, 22 deletions
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index 29a34e48ddf..4c36de9b22e 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -289,9 +289,9 @@ bool DispelableAura::RollDispel() const
}
Unit::Unit(bool isWorldObject) :
- WorldObject(isWorldObject), m_playerMovingMe(nullptr), m_lastSanctuaryTime(0), LastCharmerGUID(),
- movespline(new Movement::MoveSpline()), m_ControlledByPlayer(false), m_AutoRepeatFirstCast(false),
- m_procDeep(0), m_transformSpell(0), m_removedAurasCount(0), m_charmer(nullptr), m_charmed(nullptr),
+ WorldObject(isWorldObject), m_lastSanctuaryTime(0), LastCharmerGUID(), movespline(new Movement::MoveSpline()),
+ m_ControlledByPlayer(false), m_AutoRepeatFirstCast(false), m_procDeep(0), m_transformSpell(0),
+ m_removedAurasCount(0), m_unitMovedByMe(nullptr), m_playerMovingMe(nullptr), m_charmer(nullptr), m_charmed(nullptr),
i_motionMaster(new MotionMaster(this)), m_regenTimer(0), m_vehicle(nullptr), m_vehicleKit(nullptr),
m_unitTypeMask(UNIT_MASK_NONE), m_Diminishing(), m_isEngaged(false), m_combatManager(this), m_threatManager(this),
m_aiLocked(false), m_comboTarget(nullptr), m_comboPoints(0), m_spellHistory(new SpellHistory(this))
@@ -412,6 +412,7 @@ Unit::~Unit()
ASSERT(m_removedAuras.empty());
ASSERT(m_gameObj.empty());
ASSERT(m_dynObj.empty());
+ ASSERT(!m_playerMovingMe);
}
void Unit::Update(uint32 p_time)
@@ -8561,7 +8562,7 @@ void Unit::SetSpeedRate(UnitMoveType mtype, float rate)
pet->SetSpeedRate(mtype, m_speed_rate[mtype]);
}
- if (Player* playerMover = GetPlayerBeingMoved()) // unit controlled by a player.
+ if (Player* playerMover = Unit::ToPlayer(GetUnitBeingMoved())) // unit controlled by a player.
{
// Send notification to self. this packet is only sent to one client (the client of the player concerned by the change).
WorldPacket self;
@@ -9841,18 +9842,11 @@ void CharmInfo::SetSpellAutocast(SpellInfo const* spellInfo, bool state)
}
}
-Unit* Unit::GetUnitBeingMoved() const
+void Unit::SetMovedUnit(Unit* target)
{
- if (Player const* player = ToPlayer())
- return player->m_unitMovedByMe;
- return nullptr;
-}
-
-Player* Unit::GetPlayerBeingMoved() const
-{
- if (Unit* mover = GetUnitBeingMoved())
- return mover->ToPlayer();
- return nullptr;
+ m_unitMovedByMe->m_playerMovingMe = nullptr;
+ m_unitMovedByMe = ASSERT_NOTNULL(target);
+ m_unitMovedByMe->m_playerMovingMe = ASSERT_NOTNULL(ToPlayer());
}
uint32 createProcHitMask(SpellNonMeleeDamage* damageInfo, SpellMissInfo missCondition)
@@ -12003,7 +11997,7 @@ void Unit::KnockbackFrom(float x, float y, float speedXY, float speedZ)
if (Unit* charmer = GetCharmer())
{
player = charmer->ToPlayer();
- if (player && player->m_unitMovedByMe != this)
+ if (player && player->GetUnitBeingMoved() != this)
player = nullptr;
}
}
@@ -12744,7 +12738,8 @@ void Unit::SendTeleportPacket(Position const& pos, bool teleportingTransport /*=
moveUpdateTeleport << GetPackGUID();
Unit* broadcastSource = this;
- if (Player* playerMover = GetPlayerBeingMoved())
+ // should this really be the unit _being_ moved? not the unit doing the moving?
+ if (Player* playerMover = Unit::ToPlayer(GetUnitBeingMoved()))
{
WorldPacket moveTeleport(MSG_MOVE_TELEPORT_ACK, 41);
moveTeleport << GetPackGUID();
diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h
index 26a7c52f002..557de4a2b89 100644
--- a/src/server/game/Entities/Unit/Unit.h
+++ b/src/server/game/Entities/Unit/Unit.h
@@ -1190,14 +1190,14 @@ class TC_GAME_API Unit : public WorldObject
CharmInfo* GetCharmInfo() { return m_charmInfo; }
CharmInfo* InitCharmInfo();
void DeleteCharmInfo();
+
+ // all of these are for DIRECT CLIENT CONTROL only
+ void SetMovedUnit(Unit* target);
// returns the unit that this player IS CONTROLLING
- Unit* GetUnitBeingMoved() const;
- // returns the player that this player IS CONTROLLING
- Player* GetPlayerBeingMoved() const;
+ Unit* GetUnitBeingMoved() const { return m_unitMovedByMe; }
// returns the player that this unit is BEING CONTROLLED BY
Player* GetPlayerMovingMe() const { return m_playerMovingMe; }
- // only set for direct client control (possess effects, vehicles and similar)
- Player* m_playerMovingMe;
+
SharedVisionList const& GetSharedVisionList() { return m_sharedVision; }
void AddPlayerToVision(Player* player);
void RemovePlayerFromVision(Player* player);
@@ -1739,6 +1739,8 @@ class TC_GAME_API Unit : public WorldObject
float m_speed_rate[MAX_MOVE_TYPE];
+ Unit* m_unitMovedByMe; // only ever set for players, and only for direct client control
+ Player* m_playerMovingMe; // only set for direct client control (possess effects, vehicles and similar)
Unit* m_charmer; // Unit that is charming ME
Unit* m_charmed; // Unit that is being charmed BY ME
CharmInfo* m_charmInfo;