Core/Creatures

* Refactored setting movement flags into separate method
* Falling creatures are no longer treated as flying for movement flag setting purposes
This commit is contained in:
Shauren
2013-06-07 16:05:39 +02:00
parent e21b94c25c
commit 88bbff2236
5 changed files with 41 additions and 71 deletions

View File

@@ -438,27 +438,7 @@ bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData* data)
ApplySpellImmune(0, IMMUNITY_EFFECT, SPELL_EFFECT_ATTACK_ME, true);
}
// 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 = GetPositionZ();
GetMap()->GetWaterOrGroundLevel(GetPositionX(), GetPositionY(), GetPositionZ(), &ground);
bool isInAir = G3D::fuzzyGt(GetPositionZ(), ground + 0.05f) || G3D::fuzzyLt(GetPositionZ(), ground - 0.05f); // Can be underground too, prevent the falling
if (cInfo->InhabitType & INHABIT_AIR && cInfo->InhabitType & INHABIT_GROUND && isInAir)
SetCanFly(true);
else if (cInfo->InhabitType & INHABIT_AIR && isInAir)
SetDisableGravity(true);
else
{
SetCanFly(false);
SetDisableGravity(false);
}
if (cInfo->InhabitType & INHABIT_WATER && IsInWater())
AddUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
else
RemoveUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
UpdateMovementFlags();
return true;
}
@@ -472,33 +452,7 @@ void Creature::Update(uint32 diff)
m_vehicleKit->Reset();
}
if (IsInWater())
{
if (canSwim())
AddUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
}
else
{
if (canWalk())
RemoveUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
}
// 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 = GetPositionZ();
GetMap()->GetWaterOrGroundLevel(GetPositionX(), GetPositionY(), GetPositionZ(), &ground);
bool isInAir = G3D::fuzzyGt(GetPositionZ(), ground + 0.05f) || G3D::fuzzyLt(GetPositionZ(), ground - 0.05f); // Can be underground too, prevent the falling
CreatureTemplate const* cinfo = GetCreatureTemplate();
if (cinfo->InhabitType & INHABIT_AIR && cinfo->InhabitType & INHABIT_GROUND && isInAir)
SetCanFly(true);
else if (cinfo->InhabitType & INHABIT_AIR && isInAir)
SetDisableGravity(true);
else
{
SetCanFly(false);
SetDisableGravity(false);
}
UpdateMovementFlags();
switch (m_deathState)
{
@@ -1495,30 +1449,10 @@ void Creature::setDeathState(DeathState s)
SetFullHealth();
SetLootRecipient(NULL);
ResetPlayerDamageReq();
UpdateMovementFlags();
CreatureTemplate const* cinfo = GetCreatureTemplate();
SetWalk(true);
// 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 = GetPositionZ();
GetMap()->GetWaterOrGroundLevel(GetPositionX(), GetPositionY(), GetPositionZ(), &ground);
bool isInAir = G3D::fuzzyGt(GetPositionZ(), ground + 0.05f) || G3D::fuzzyLt(GetPositionZ(), ground - 0.05f); // Can be underground too, prevent the falling
if (cinfo->InhabitType & INHABIT_AIR && cinfo->InhabitType & INHABIT_GROUND && isInAir)
SetCanFly(true);
else if (cinfo->InhabitType & INHABIT_AIR && isInAir)
SetDisableGravity(true);
else
{
SetCanFly(false);
SetDisableGravity(false);
}
if (cinfo->InhabitType & INHABIT_WATER && IsInWater())
AddUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
else
RemoveUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
SetUInt32Value(UNIT_NPC_FLAGS, cinfo->npcflag);
ClearUnitState(uint32(UNIT_STATE_ALL_STATE));
SetMeleeDamageSchool(SpellSchools(cinfo->dmgschool));
@@ -2588,3 +2522,29 @@ Unit* Creature::SelectNearestHostileUnitInAggroRange(bool useLOS) const
return target;
}
void Creature::UpdateMovementFlags()
{
// 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 = GetMap()->GetHeight(GetPositionX(), GetPositionY(), GetPositionZMinusOffset());
bool isInAir = !IsFalling() && (G3D::fuzzyGt(GetPositionZMinusOffset(), ground + 0.05f) || G3D::fuzzyLt(GetPositionZMinusOffset(), ground - 0.05f)); // Can be underground too, prevent the falling
if (GetCreatureTemplate()->InhabitType & INHABIT_AIR && isInAir)
{
if (GetCreatureTemplate()->InhabitType & INHABIT_GROUND)
SetCanFly(true);
else
SetDisableGravity(true);
}
else
{
SetCanFly(false);
SetDisableGravity(false);
}
if (GetCreatureTemplate()->InhabitType & INHABIT_WATER && IsInWater())
AddUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
else
RemoveUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
}

View File

@@ -520,6 +520,9 @@ class Creature : public Unit, public GridObject<Creature>, public MapCreature
bool HasSpell(uint32 spellID) const;
bool UpdateEntry(uint32 entry, uint32 team=ALLIANCE, const CreatureData* data=NULL);
void UpdateMovementFlags();
bool UpdateStats(Stats stat);
bool UpdateAllStats();
void UpdateResistances(uint32 school);

View File

@@ -17019,6 +17019,11 @@ void Unit::BuildMovementPacket(ByteBuffer *data) const
*data << (float)m_movementInfo.splineElevation;
}
bool Unit::IsFalling() const
{
return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_FALLING | MOVEMENTFLAG_FALLING_FAR) || movespline->isFalling();
}
void Unit::SetCanFly(bool apply)
{
if (apply)

View File

@@ -2113,6 +2113,7 @@ class Unit : public WorldObject
bool isTurning() const { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_MASK_TURNING); }
virtual bool CanFly() const = 0;
bool IsFlying() const { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_FLYING | MOVEMENTFLAG_DISABLE_GRAVITY); }
bool IsFalling() const;
void SetCanFly(bool apply);
void RewardRage(uint32 damage, uint32 weaponSpeedHitFactor, bool attacker);

View File

@@ -115,6 +115,7 @@ namespace Movement
uint32 GetId() const { return m_Id; }
bool Finalized() const { return splineflags.done; }
bool isCyclic() const { return splineflags.cyclic; }
bool isFalling() const { return splineflags.falling; }
const Vector3 FinalDestination() const { return Initialized() ? spline.getPoint(spline.last()) : Vector3(); }
const Vector3 CurrentDestination() const { return Initialized() ? spline.getPoint(point_Idx+1) : Vector3(); }
int32 currentPathIdx() const;