feat(Core/Movement): Improved pathfinding, collisions and movements (#4220)

Npc positioning
Implemented slope check to avoid unwanted climbing for some kind of movements (backwards, repositioning etc.)
Implemented backwards movement
Re-implemented circle repositioning algorithm (smartest than retail, but with the same feeling)
Fixed random position of summoned minions
Improved pet following movement. Also, they attack NPC from behind now. Thanks to @Footman

Swimming creatures
Fixed max_z coordinate for swimming creatures. Now only part of their body is allowed to be out of the water level
Fixed pathfinder for swimming creatures creating shortcuts for specific segments, now they swim underwater to reach the seashore instead of flying above the water level.
Creatures with water InhabitType but no swimming flag now, when not in combat, will walk on water depth instead of swimming. Thanks @jackpoz for the original code
UNIT_FLAG_SWIMMING in UpdateEnvironmentIfNeeded to show the swimming animation correctly when underwater
Implemented HasEnoughWater check to avoid swimming creatures to go where the water level is too low but also to properly enable swimming animation only when a creature has enough water to swim.

Walking creatures
Extended the DetourNavMeshQuery adding area cost based on walkability (slope angle + source height) to find better paths at runtime instead of completely remove them from mmaps
improve Z height in certain conditions (see #4205, #4203, #4247 )

Flying creatures
Rewriting of the hover system
Removed hacks and improved the UpdateEnvironmentIfNeeded. Now creatures can properly switch from flying to walk etc.
Spells
LOS on spell effect must be calculated on CollisionHeight and HitSpherePoint instead of position coords.
Improved position for object/creature spawned via spells
Improved checks for Fleeing movements (fear spells)

Other improvements
Implemented method to calculate the CollisionWidth from dbc (used by repositioning algorithm etc.)
Improved raycast and collision checks

Co-authored-by: Footman <p.alexej@freenet.de>
Co-authored-by: Helias <stefanoborzi32@gmail.com>
Co-authored-by: Francesco Borzì <borzifrancesco@gmail.com>
Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
This commit is contained in:
Yehonal
2021-02-01 01:34:27 +01:00
committed by GitHub
parent fcad2b56ae
commit c8f43d8584
79 changed files with 3025 additions and 2199 deletions

View File

@@ -24,26 +24,6 @@ class ElunaEventProcessor;
#include <string>
#include <sstream>
#define CONTACT_DISTANCE 0.5f
#define INTERACTION_DISTANCE 5.5f
#define ATTACK_DISTANCE 5.0f
#define MAX_SEARCHER_DISTANCE 150.0f // pussywizard: replace the use of MAX_VISIBILITY_DISTANCE in searchers, because MAX_VISIBILITY_DISTANCE is quite too big for this purpose
#define MAX_VISIBILITY_DISTANCE 250.0f // max distance for visible objects, experimental
#define VISIBILITY_INC_FOR_GOBJECTS 30.0f // pussywizard
#define VISIBILITY_COMPENSATION 15.0f // increase searchers
#define SPELL_SEARCHER_COMPENSATION 30.0f // increase searchers size in case we have large npc near cell border
#define VISIBILITY_DIST_WINTERGRASP 175.0f
#define SIGHT_RANGE_UNIT 50.0f
#define DEFAULT_VISIBILITY_DISTANCE 90.0f // default visible distance, 90 yards on continents
#define DEFAULT_VISIBILITY_INSTANCE 120.0f // default visible distance in instances, 120 yards
#define DEFAULT_VISIBILITY_BGARENAS 150.0f // default visible distance in BG/Arenas, 150 yards
#define DEFAULT_WORLD_OBJECT_SIZE 0.388999998569489f // player size, also currently used (correctly?) for any non Unit world objects
#define DEFAULT_COMBAT_REACH 1.5f
#define MIN_MELEE_REACH 2.0f
#define NOMINAL_MELEE_RANGE 5.0f
#define MELEE_RANGE (NOMINAL_MELEE_RANGE - MIN_MELEE_REACH * 2) //center to center for players
enum TypeMask
{
TYPEMASK_OBJECT = 0x0001,
@@ -138,6 +118,7 @@ public:
[[nodiscard]] uint32 GetEntry() const { return GetUInt32Value(OBJECT_FIELD_ENTRY); }
void SetEntry(uint32 entry) { SetUInt32Value(OBJECT_FIELD_ENTRY, entry); }
float GetObjectScale() const { return GetFloatValue(OBJECT_FIELD_SCALE_X); }
virtual void SetObjectScale(float scale) { SetFloatValue(OBJECT_FIELD_SCALE_X, scale); }
[[nodiscard]] TypeID GetTypeId() const { return m_objectTypeId; }
@@ -540,11 +521,19 @@ struct Position
float GetAngle(const Position* pos) const;
[[nodiscard]] float GetAngle(float x, float y) const;
float GetAbsoluteAngle(float x, float y) const
{
float dx = x - m_positionX;
float dy = y - m_positionY;
return NormalizeOrientation(std::atan2(dy, dx));
}
float GetRelativeAngle(const Position* pos) const
{
return GetAngle(pos) - m_orientation;
}
[[nodiscard]] float GetRelativeAngle(float x, float y) const { return GetAngle(x, y) - m_orientation; }
float ToAbsoluteAngle(float relAngle) const { return NormalizeOrientation(relAngle + m_orientation); }
void GetSinCos(float x, float y, float& vsin, float& vcos) const;
[[nodiscard]] bool IsInDist2d(float x, float y, float dist) const
@@ -782,6 +771,7 @@ public:
ElunaEventProcessor* elunaEvents;
#endif
void GetNearPoint2D(WorldObject const* searcher, float& x, float& y, float distance, float absAngle) const;
void GetNearPoint2D(float& x, float& y, float distance, float absAngle) const;
void GetNearPoint(WorldObject const* searcher, float& x, float& y, float& z, float searcher_size, float distance2d, float absAngle, float controlZ = 0) const;
void GetVoidClosePoint(float& x, float& y, float& z, float size, float distance2d = 0, float relAngle = 0, float controlZ = 0) const;
@@ -793,17 +783,14 @@ public:
MovePosition(pos, dist, angle);
}
void MovePositionToFirstCollision(Position& pos, float dist, float angle);
Position GetFirstCollisionPosition(float startX, float startY, float startZ, float destX, float destY);
Position GetFirstCollisionPosition(float destX, float destY, float destZ);
Position GetFirstCollisionPosition(float dist, float angle);
void GetFirstCollisionPosition(Position& pos, float dist, float angle)
{
GetPosition(&pos);
MovePositionToFirstCollision(pos, dist, angle);
}
void MovePositionToFirstCollisionForTotem(Position& pos, float dist, float angle, bool forGameObject);
void GetFirstCollisionPositionForTotem(Position& pos, float dist, float angle, bool forGameObject)
{
GetPosition(&pos);
MovePositionToFirstCollisionForTotem(pos, dist, angle, forGameObject);
}
void GetRandomNearPosition(Position& pos, float radius)
{
GetPosition(&pos);
@@ -815,12 +802,12 @@ public:
[[nodiscard]] float GetObjectSize() const
{
return (m_valuesCount > UNIT_FIELD_COMBATREACH) ? m_floatValues[UNIT_FIELD_COMBATREACH] : DEFAULT_WORLD_OBJECT_SIZE;
return (m_valuesCount > UNIT_FIELD_COMBATREACH) ? m_floatValues[UNIT_FIELD_COMBATREACH] : DEFAULT_WORLD_OBJECT_SIZE * GetObjectScale();
}
[[nodiscard]] virtual float GetCombatReach() const { return 0.0f; } // overridden (only) in Unit
void UpdateGroundPositionZ(float x, float y, float& z) const;
void UpdateAllowedPositionZ(float x, float y, float& z) const;
void UpdateAllowedPositionZ(float x, float y, float& z, float* groundZ = nullptr) const;
void GetRandomPoint(const Position& srcPos, float distance, float& rand_x, float& rand_y, float& rand_z) const;
void GetRandomPoint(const Position& srcPos, float distance, Position& pos) const
@@ -1057,6 +1044,16 @@ public:
[[nodiscard]] virtual float GetStationaryZ() const { return GetPositionZ(); }
[[nodiscard]] virtual float GetStationaryO() const { return GetOrientation(); }
[[nodiscard]] float GetMapWaterOrGroundLevel(float x, float y, float z, float* ground = nullptr) const;
[[nodiscard]] float GetMapHeight(float x, float y, float z, bool vmap = true, float distanceToSearch = 50.0f) const; // DEFAULT_HEIGHT_SEARCH in map.h
[[nodiscard]] float GetFloorZ() const;
[[nodiscard]] float GetMinHeightInWater() const;
[[nodiscard]] virtual float GetCollisionHeight() const { return 0.0f; }
[[nodiscard]] virtual float GetCollisionWidth() const { return GetObjectSize(); }
[[nodiscard]] virtual float GetCollisionRadius() const { return GetObjectSize() / 2; }
protected:
std::string m_name;
bool m_isActive;
@@ -1064,6 +1061,8 @@ protected:
const bool m_isWorldObject;
ZoneScript* m_zoneScript;
float m_staticFloorZ;
// transports
Transport* m_transport;