aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp57
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp25
2 files changed, 61 insertions, 21 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index 8d39e459187..00ef3d32a06 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -433,27 +433,26 @@ bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData* data)
ApplySpellImmune(0, IMMUNITY_EFFECT, SPELL_EFFECT_ATTACK_ME, true);
}
- //! Suspect it works this way:
- //! If creature can walk and fly (usually with pathing)
- //! Set MOVEMENTFLAG_CAN_FLY. Otherwise if it can only fly
- //! Set MOVEMENTFLAG_DISABLE_GRAVITY
- //! The only time I saw Movement Flags: DisableGravity, CanFly, Flying (50332672) on the same unit
- //! it was a vehicle
- if (cInfo->InhabitType & INHABIT_AIR && cInfo->InhabitType & INHABIT_GROUND)
- SetCanFly(true);
- else if (cInfo->InhabitType & INHABIT_AIR)
- SetDisableGravity(true);
- /*! Implemented in LoadCreatureAddon. Suspect there's a rule for UNIT_BYTE_1_FLAG_HOVER
- in relation to DisableGravity also.
+ // 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);
- else if (GetByteValue(UNIT_FIELD_BYTES_1, 3) & UNIT_BYTE_1_FLAG_HOVER)
- SetHover(true);
+ bool isInAir = G3D::fuzzyGt(GetPositionZ(), ground);
- */
+ 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);
+ }
- // TODO: Shouldn't we check whether or not the creature is in water first?
- if (cInfo->InhabitType & INHABIT_WATER)
- AddUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
+ if (cInfo->InhabitType & INHABIT_WATER && IsInWater())
+ AddUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
+ else
+ RemoveUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
return true;
}
@@ -1553,12 +1552,28 @@ void Creature::setDeathState(DeathState s)
ResetPlayerDamageReq();
CreatureTemplate const* cinfo = GetCreatureTemplate();
SetWalk(true);
- if (cinfo->InhabitType & INHABIT_AIR && cinfo->InhabitType & INHABIT_GROUND)
+
+ // 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);
+
+ if (cinfo->InhabitType & INHABIT_AIR && cinfo->InhabitType & INHABIT_GROUND && isInAir)
SetCanFly(true);
- else if (cinfo->InhabitType & INHABIT_AIR)
+ else if (cinfo->InhabitType & INHABIT_AIR && isInAir)
SetDisableGravity(true);
- if (cinfo->InhabitType & INHABIT_WATER)
+ 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));
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index 4148e3177fe..dd3ebb48ebf 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -17375,6 +17375,31 @@ bool Unit::UpdatePosition(float x, float y, float z, float orientation, bool tel
else if (turn)
UpdateOrientation(orientation);
+ if (Creature* creature = ToCreature())
+ {
+ // 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 = z;
+ GetMap()->GetWaterOrGroundLevel(x, y, z, &ground);
+
+ bool isInAir = G3D::fuzzyGt(z, ground);
+ CreatureTemplate const* cinfo = creature->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);
+ }
+
+ if (cinfo->InhabitType & INHABIT_WATER && GetMap()->IsInWater(x, y, z))
+ AddUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
+ else
+ RemoveUnitMovementFlag(MOVEMENTFLAG_SWIMMING);
+ }
+
// code block for underwater state update
UpdateUnderwaterState(GetMap(), x, y, z);