Skip to content

Commit 4c27329

Browse files
committed
Core/Entities: implement IsInAir
1 parent aa8c287 commit 4c27329

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/server/game/Entities/Creature/Creature.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,10 +2663,7 @@ void Creature::UpdateMovementFlags()
26632663
return;
26642664

26652665
// Set the movement flags if the creature is in that mode. (Only fly if actually in air, only swim if in water, etc)
2666-
float ground = GetFloorZ();
2667-
2668-
bool canHover = CanHover();
2669-
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
2666+
bool isInAir = IsInAir(*this, GetFloorZ() + GROUND_HEIGHT_TOLERANCE) || IsInAir(*this, GetFloorZ() - GROUND_HEIGHT_TOLERANCE);
26702667

26712668
if (GetMovementTemplate().IsFlightAllowed() && isInAir && !IsFalling())
26722669
{

src/server/game/Entities/Unit/Unit.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3164,6 +3164,11 @@ bool Unit::IsUnderWater() const
31643164
return GetLiquidStatus() & LIQUID_MAP_UNDER_WATER;
31653165
}
31663166

3167+
bool Unit::IsInAir(Position const destination, float destinationFloor, bool honorHover/* = true*/) const
3168+
{
3169+
return std::fabs(destination.GetPositionZ() - (honorHover ? GetHoverOffset() : 0.f) - destinationFloor) > 0.1f;
3170+
}
3171+
31673172
void Unit::ProcessPositionDataChanged(PositionFullTerrainStatus const& data)
31683173
{
31693174
ZLiquidStatus oldLiquidStatus = GetLiquidStatus();

src/server/game/Entities/Unit/Unit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ class TC_GAME_API Unit : public WorldObject
11711171

11721172
bool IsInWater() const;
11731173
bool IsUnderWater() const;
1174+
bool IsInAir(Position const destination, float destinationFloor, bool honorHover = true) const;
11741175
bool isInAccessiblePlaceFor(Creature const* c) const;
11751176

11761177
void SendHealSpellLog(HealInfo& healInfo, bool critical = false);

0 commit comments

Comments
 (0)