aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorccrs <ccrs@users.noreply.github.com>2019-05-01 14:08:52 +0200
committerccrs <ccrs@users.noreply.github.com>2019-05-01 14:08:52 +0200
commit69c15f5ae769612c89346c6a308655d0987caae7 (patch)
tree12001111cfd6871bae23b73766bbd1fe97958ef1 /src
parent2dffb85762b89327818b5172e410a9bf5c497c73 (diff)
Core/Creature: couple refactors/renaming
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp104
-rw-r--r--src/server/game/Entities/Creature/Creature.h15
-rw-r--r--src/server/game/Entities/Creature/CreatureData.h5
3 files changed, 66 insertions, 58 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index 638e824c0de..c567e8f73f2 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -309,11 +309,6 @@ void Creature::RemoveFromWorld()
}
}
-void Creature::DisappearAndDie()
-{
- ForcedDespawn(0);
-}
-
bool Creature::IsReturningHome() const
{
if (GetMotionMaster()->GetCurrentMovementGeneratorType() == HOME_MOTION_TYPE)
@@ -610,13 +605,12 @@ bool Creature::UpdateEntry(uint32 entry, CreatureData const* data /*= nullptr*/,
ApplySpellImmune(0, IMMUNITY_EFFECT, SPELL_EFFECT_ATTACK_ME, true);
}
- if (GetMovementTemplate().IsRooted())
- SetControlled(true, UNIT_STATE_ROOT);
+ LoadTemplateRoot();
+ InitializeMovementFlags();
- UpdateMovementFlags();
LoadCreaturesAddon();
-
LoadTemplateImmunities();
+
GetThreatManager().EvaluateSuppressed();
//We must update last scriptId or it looks like we reloaded a script, breaking some things such as gossip temporarily
@@ -1684,6 +1678,12 @@ void Creature::SetSpawnHealth()
SetHealth((m_deathState == ALIVE || m_deathState == JUST_RESPAWNED) ? curhealth : 0);
}
+void Creature::LoadTemplateRoot()
+{
+ if (GetMovementTemplate().IsRooted())
+ SetControlled(true, UNIT_STATE_ROOT);
+}
+
bool Creature::hasQuest(uint32 quest_id) const
{
QuestRelationBounds qr = sObjectMgr->GetCreatureQuestRelationBounds(GetEntry());
@@ -2583,6 +2583,52 @@ void Creature::GetRespawnPosition(float &x, float &y, float &z, float* ori, floa
}
}
+void Creature::InitializeMovementFlags()
+{
+ // It does the same, for now
+ UpdateMovementFlags();
+}
+
+void Creature::UpdateMovementFlags()
+{
+ // Do not update movement flags if creature is controlled by a player (charm/vehicle)
+ if (m_playerMovingMe)
+ return;
+
+ // Creatures with CREATURE_FLAG_EXTRA_NO_MOVE_FLAGS_UPDATE should control MovementFlags in your own scripts
+ if (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_NO_MOVE_FLAGS_UPDATE)
+ return;
+
+ // Set the movement flags if the creature is in that mode. (Only fly if actually in air, only swim if in water, etc)
+ float ground = GetFloorZ();
+
+ bool canHover = CanHover();
+ bool isInAir = (G3D::fuzzyGt(GetPositionZ(), ground + (canHover ? GetFloatValue(UNIT_FIELD_HOVERHEIGHT) : 0.0f) + GROUND_HEIGHT_TOLERANCE) || G3D::fuzzyLt(GetPositionZ(), ground - GROUND_HEIGHT_TOLERANCE)); // Can be underground too, prevent the falling
+
+ if (GetMovementTemplate().IsFlightAllowed() && isInAir && !IsFalling())
+ {
+ if (GetMovementTemplate().Flight == CreatureFlightMovementType::CanFly)
+ SetCanFly(true);
+ else
+ SetDisableGravity(true);
+
+ if (!HasAuraType(SPELL_AURA_HOVER))
+ SetHover(false);
+ }
+ else
+ {
+ SetCanFly(false);
+ SetDisableGravity(false);
+ if (IsAlive() && (CanHover() || HasAuraType(SPELL_AURA_HOVER)))
+ SetHover(true);
+ }
+
+ if (!isInAir)
+ RemoveUnitMovementFlag(MOVEMENTFLAG_FALLING);
+
+ SetSwim(GetMovementTemplate().IsSwimAllowed() && IsInWater());
+}
+
CreatureMovementData const& Creature::GetMovementTemplate() const
{
if (CreatureMovementData const* movementOverride = sObjectMgr->GetCreatureMovementOverride(m_spawnId))
@@ -2927,46 +2973,6 @@ Unit* Creature::SelectNearestHostileUnitInAggroRange(bool useLOS) const
return target;
}
-void Creature::UpdateMovementFlags()
-{
- // Do not update movement flags if creature is controlled by a player (charm/vehicle)
- if (m_playerMovingMe)
- return;
-
- // Creatures with CREATURE_FLAG_EXTRA_NO_MOVE_FLAGS_UPDATE should control MovementFlags in your own scripts
- if (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_NO_MOVE_FLAGS_UPDATE)
- return;
-
- // Set the movement flags if the creature is in that mode. (Only fly if actually in air, only swim if in water, etc)
- float ground = GetFloorZ();
-
- bool canHover = CanHover();
- bool isInAir = (G3D::fuzzyGt(GetPositionZ(), ground + (canHover ? GetFloatValue(UNIT_FIELD_HOVERHEIGHT) : 0.0f) + GROUND_HEIGHT_TOLERANCE) || G3D::fuzzyLt(GetPositionZ(), ground - GROUND_HEIGHT_TOLERANCE)); // Can be underground too, prevent the falling
-
- if (GetMovementTemplate().IsFlightAllowed() && isInAir && !IsFalling())
- {
- if (GetMovementTemplate().Flight == CreatureFlightMovementType::CanFly)
- SetCanFly(true);
- else
- SetDisableGravity(true);
-
- if (!HasAuraType(SPELL_AURA_HOVER))
- SetHover(false);
- }
- else
- {
- SetCanFly(false);
- SetDisableGravity(false);
- if (IsAlive() && (CanHover() || HasAuraType(SPELL_AURA_HOVER)))
- SetHover(true);
- }
-
- if (!isInAir)
- RemoveUnitMovementFlag(MOVEMENTFLAG_FALLING);
-
- SetSwim(GetMovementTemplate().IsSwimAllowed() && IsInWater());
-}
-
void Creature::SetObjectScale(float scale)
{
Unit::SetObjectScale(scale);
diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h
index 9b393471532..9b414e5846c 100644
--- a/src/server/game/Entities/Creature/Creature.h
+++ b/src/server/game/Entities/Creature/Creature.h
@@ -69,7 +69,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
void SetObjectScale(float scale) override;
void SetDisplayId(uint32 modelId) override;
- void DisappearAndDie();
+ void DisappearAndDie() { ForcedDespawn(0); }
bool Create(ObjectGuid::LowType guidlow, Map* map, uint32 phaseMask, uint32 entry, Position const& pos, CreatureData const* data = nullptr, uint32 vehId = 0, bool dynamic = false);
bool LoadCreaturesAddon();
@@ -77,6 +77,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
void UpdateLevelDependantStats();
void LoadEquipment(int8 id = 1, bool force = false);
void SetSpawnHealth();
+ void LoadTemplateRoot();
ObjectGuid::LowType GetSpawnId() const { return m_spawnId; }
@@ -90,12 +91,19 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
bool IsCivilian() const { return (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_CIVILIAN) != 0; }
bool IsTrigger() const { return (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER) != 0; }
bool IsGuard() const { return (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_GUARD) != 0; }
+
+ void InitializeMovementFlags();
+ void UpdateMovementFlags();
+
CreatureMovementData const& GetMovementTemplate() const;
bool CanWalk() const { return GetMovementTemplate().IsGroundAllowed(); }
bool CanSwim() const override { return GetMovementTemplate().IsSwimAllowed() || IsPet(); }
bool CanFly() const override { return GetMovementTemplate().IsFlightAllowed(); }
bool CanHover() const { return GetMovementTemplate().Ground == CreatureGroundMovementType::Hover; }
+ MovementGeneratorType GetDefaultMovementType() const override { return m_defaultMovementType; }
+ void SetDefaultMovementType(MovementGeneratorType mgt) { m_defaultMovementType = mgt; }
+
bool IsDungeonBoss() const { return (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_DUNGEON_BOSS) != 0; }
bool IsAffectedByDiminishingReturns() const override { return Unit::IsAffectedByDiminishingReturns() || (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_ALL_DIMINISH) != 0; }
@@ -155,8 +163,6 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
bool UpdateEntry(uint32 entry, CreatureData const* data = nullptr, bool updateLevel = true);
- void UpdateMovementFlags();
-
bool UpdateStats(Stats stat) override;
bool UpdateAllStats() override;
void UpdateResistances(uint32 school) override;
@@ -237,9 +243,6 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
bool CanAssistTo(Unit const* u, Unit const* enemy, bool checkfaction = true) const;
bool _IsTargetAcceptable(Unit const* target) const;
- MovementGeneratorType GetDefaultMovementType() const override { return m_defaultMovementType; }
- void SetDefaultMovementType(MovementGeneratorType mgt) { m_defaultMovementType = mgt; }
-
void RemoveCorpse(bool setSpawnTime = true, bool destroyForNearbyPlayers = true);
void DespawnOrUnsummon(uint32 msTimeToDespawn = 0, Seconds forceRespawnTime = 0s);
diff --git a/src/server/game/Entities/Creature/CreatureData.h b/src/server/game/Entities/Creature/CreatureData.h
index c031c76d8ca..0e7bd1544da 100644
--- a/src/server/game/Entities/Creature/CreatureData.h
+++ b/src/server/game/Entities/Creature/CreatureData.h
@@ -113,9 +113,8 @@ enum class CreatureRandomMovementType : uint8
struct TC_GAME_API CreatureMovementData
{
- CreatureMovementData() : Ground(CreatureGroundMovementType::Run), Flight(CreatureFlightMovementType::None),
- Swim(true), Rooted(false), Chase(CreatureChaseMovementType::Run),
- Random(CreatureRandomMovementType::Walk) { }
+ CreatureMovementData() : Ground(CreatureGroundMovementType::Run), Flight(CreatureFlightMovementType::None), Swim(true), Rooted(false), Chase(CreatureChaseMovementType::Run),
+ Random(CreatureRandomMovementType::Walk) { }
CreatureGroundMovementType Ground;
CreatureFlightMovementType Flight;