Skip to content

Commit

Permalink
Movement: Improve handling of hover
Browse files Browse the repository at this point in the history
Closes #454
  • Loading branch information
insunaa authored and killerwife committed Jan 8, 2024
1 parent 5995e66 commit 133d0a6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
23 changes: 21 additions & 2 deletions src/game/Entities/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13250,8 +13250,8 @@ void Unit::UpdateAllowedPositionZ(float x, float y, float& z, Map* atMap /*=null
if (!atMap)
atMap = GetMap();

// non fly unit don't must be in air
// non swim unit must be at ground (mostly speedup, because it don't must be in water and water level check less fast
// non flying unit must not be in the air
// non swimming unit must be on the ground (mostly speedup, because it can't be in water and water level check less fast)
if (!CanFly())
{
bool canSwim = CanSwim();
Expand All @@ -13274,6 +13274,8 @@ void Unit::UpdateAllowedPositionZ(float x, float y, float& z, Map* atMap /*=null
if (z < groundZ)
z = groundZ;
}

z += GetHoverOffset();
}

void Unit::AdjustZForCollision(float x, float y, float& z, float halfHeight) const
Expand Down Expand Up @@ -14004,6 +14006,23 @@ void Unit::SetHover(bool enable)
m_movementInfo.RemoveMovementFlag(MOVEFLAG_HOVER);
}

float hoverHeight = GetHoverHeight();

if (enable)
{
if (hoverHeight && GetPositionZ() - GetMap()->GetHeight(GetPhaseMask(), GetPositionX(), GetPositionY(), GetPositionZ()) < hoverHeight)
Relocate(GetPositionX(), GetPositionY(), GetPositionZ() + hoverHeight);
}
else
{
if (IsAlive() || !IsUnit())
{
float newZ = std::max<float>(GetMap()->GetHeight(GetPhaseMask(), GetPositionX(), GetPositionY(), GetPositionZ()), GetPositionZ() - hoverHeight);
UpdateAllowedPositionZ(GetPositionX(), GetPositionY(), newZ);
Relocate(GetPositionX(), GetPositionY(), newZ);
}
}

if (!IsInWorld()) // is sent on add to map
return;

Expand Down
18 changes: 18 additions & 0 deletions src/game/Entities/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,11 @@ enum UnitVisFlags
// These flags seem to be related to miscellaneous animations
enum UnitMiscFlags
{
UNIT_BYTE1_FLAG_GROUND = 0x00,
UNIT_BYTE1_FLAG_ALWAYS_STAND = 0x01,
UNIT_BYTE1_FLAG_FLY_ANIM = 0x02, // Creature that can fly and are not on the ground appear to have this flag. If they are on the ground, flag is not present.
UNIT_BYTE1_FLAG_REAL_FLY_ANIM= 0x03,
UNIT_BYTE1_FLAG_SUBMERGED = 0x04,
UNIT_BYTE1_FLAG_ALL = 0xFF
};

Expand Down Expand Up @@ -2493,6 +2496,16 @@ class Unit : public WorldObject
virtual bool CanWalk() const = 0;
virtual bool IsFlying() const { return m_movementInfo.HasMovementFlag(MOVEFLAG_FLYING); }

float GetHoverOffset() const
{
return m_movementInfo.HasMovementFlag(MOVEFLAG_HOVER) ? GetFloatValue(UNIT_FIELD_HOVERHEIGHT) : 0.0f;
}

float GetHoverHeight() const
{
return GetFloatValue(UNIT_FIELD_HOVERHEIGHT);
}

// Take possession of an unit (pet, creature, ...)
bool TakePossessOf(Unit* possessed);

Expand Down Expand Up @@ -2540,6 +2553,11 @@ class Unit : public WorldObject
virtual void SetBaseRunSpeed(float speed, bool /*force*/ = true) { m_baseSpeedRun = speed; }
float GetBaseRunSpeed() { return m_baseSpeedRun; }

void SetHoverHeight(float hoverHeight)
{
SetFloatValue(UNIT_FIELD_HOVERHEIGHT, hoverHeight);
}

bool IsSpellProccingHappening() const { return m_spellProcsHappening; }
void AddDelayedHolderDueToProc(SpellAuraHolder* holder) { m_delayedSpellAuraHolders.push_back(holder); }

Expand Down
1 change: 0 additions & 1 deletion src/game/MotionGenerators/MotionMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ bool MotionMaster::MoveFall(ObjectGuid guid/* = ObjectGuid()*/, uint32 relayId/*

// use larger distance for vmap height search than in most other cases
float tz = m_owner->GetMap()->GetHeight(m_owner->GetPhaseMask(), x, y, z);

if (tz <= INVALID_HEIGHT)
{
DEBUG_LOG("MotionMaster::MoveFall: unable retrive a proper height at map %u (x: %f, y: %f, z: %f).", m_owner->GetMap()->GetId(), x, y, z);
Expand Down
4 changes: 2 additions & 2 deletions src/game/Movement/MoveSplineInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ namespace Movement
MoveSplineInit::MoveSplineInit(Unit& m) : unit(m)
{
// mix existing state into new
args.flags.walkmode = unit.m_movementInfo.HasMovementFlag(MOVEFLAG_WALK_MODE);
args.flags.flying = unit.m_movementInfo.HasMovementFlag((MovementFlags)(MOVEFLAG_CAN_FLY | MOVEFLAG_HOVER | MOVEFLAG_FLYING | MOVEFLAG_LEVITATING));
args.flags.walkmode = unit.m_movementInfo.HasMovementFlag((MovementFlags)(MOVEFLAG_WALK_MODE | MOVEFLAG_HOVER));
args.flags.flying = unit.m_movementInfo.HasMovementFlag((MovementFlags)(MOVEFLAG_CAN_FLY | MOVEFLAG_FLYING | MOVEFLAG_LEVITATING));
}

void MoveSplineInit::SetFacing(const WorldObject* target)
Expand Down

0 comments on commit 133d0a6

Please sign in to comment.