diff options
| author | Shauren <shauren.trinity@gmail.com> | 2013-06-07 16:05:39 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2013-06-07 16:05:39 +0200 |
| commit | 88bbff2236d105bd17d7bc67bd915159c3e9a054 (patch) | |
| tree | 8c7736ed61296ff5948cefe0ffc42314bbaa5699 /src/server/game/Entities/Creature | |
| parent | e21b94c25c90299517732fa4f2522adfc6e0cc38 (diff) | |
Core/Creatures
* Refactored setting movement flags into separate method
* Falling creatures are no longer treated as flying for movement flag setting purposes
Diffstat (limited to 'src/server/game/Entities/Creature')
| -rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 100 | ||||
| -rw-r--r-- | src/server/game/Entities/Creature/Creature.h | 3 |
2 files changed, 33 insertions, 70 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index b3deb7ae7de..4a2408b7f0a 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -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(); - 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); + UpdateMovementFlags(); + CreatureTemplate const* cinfo = GetCreatureTemplate(); 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); +} diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 6459b80a063..6b6edd7454f 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -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); |
