mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-23 05:36:23 +00:00
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:
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "Common.h"
|
||||
#include "Physics.h"
|
||||
#include "SharedDefines.h"
|
||||
#include "WorldPacket.h"
|
||||
#include "Opcodes.h"
|
||||
@@ -357,7 +358,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
|
||||
|
||||
*data << object->GetPositionX();
|
||||
*data << object->GetPositionY();
|
||||
*data << object->GetPositionZ() + (unit ? unit->GetHoverHeight() : 0.0f);
|
||||
*data << object->GetPositionZ();
|
||||
|
||||
if (transport)
|
||||
{
|
||||
@@ -369,7 +370,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
|
||||
{
|
||||
*data << object->GetPositionX();
|
||||
*data << object->GetPositionY();
|
||||
*data << object->GetPositionZ() + (unit ? unit->GetHoverHeight() : 0.0f);
|
||||
*data << object->GetPositionZ();
|
||||
}
|
||||
|
||||
*data << object->GetOrientation();
|
||||
@@ -386,7 +387,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
|
||||
{
|
||||
*data << object->GetStationaryX();
|
||||
*data << object->GetStationaryY();
|
||||
*data << object->GetStationaryZ() + (unit ? unit->GetHoverHeight() : 0.0f);
|
||||
*data << object->GetStationaryZ();
|
||||
*data << object->GetStationaryO();
|
||||
}
|
||||
}
|
||||
@@ -897,6 +898,15 @@ bool Object::PrintIndexError(uint32 index, bool set) const
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Position::operator==(Position const& a)
|
||||
{
|
||||
return (G3D::fuzzyEq(a.m_positionX, m_positionX) &&
|
||||
G3D::fuzzyEq(a.m_positionY, m_positionY) &&
|
||||
G3D::fuzzyEq(a.m_positionZ, m_positionZ) &&
|
||||
G3D::fuzzyEq(a.m_orientation, m_orientation));
|
||||
}
|
||||
|
||||
void Position::RelocatePolarOffset(float angle, float dist, float z /*= 0.0f*/)
|
||||
{
|
||||
SetOrientation(GetOrientation() + angle);
|
||||
@@ -988,7 +998,7 @@ WorldObject::WorldObject(bool isWorldObject) : WorldLocation(),
|
||||
elunaEvents(nullptr),
|
||||
#endif
|
||||
LastUsedScriptID(0), m_name(""), m_isActive(false), m_isVisibilityDistanceOverride(false), m_isWorldObject(isWorldObject), m_zoneScript(nullptr),
|
||||
m_transport(nullptr), m_currMap(nullptr), m_InstanceId(0),
|
||||
m_staticFloorZ(INVALID_HEIGHT), m_transport(nullptr), m_currMap(nullptr), m_InstanceId(0),
|
||||
m_phaseMask(PHASEMASK_NORMAL), m_useCombinedPhases(true), m_notifyflags(0), m_executed_notifies(0)
|
||||
{
|
||||
m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE | GHOST_VISIBILITY_GHOST);
|
||||
@@ -1139,7 +1149,7 @@ bool WorldObject::_IsWithinDist(WorldObject const* obj, float dist2compare, bool
|
||||
|
||||
Position WorldObject::GetHitSpherePointFor(Position const& dest) const
|
||||
{
|
||||
G3D::Vector3 vThis(GetPositionX(), GetPositionY(), GetPositionZ());
|
||||
G3D::Vector3 vThis(GetPositionX(), GetPositionY(), GetPositionZ() + GetCollisionHeight());
|
||||
G3D::Vector3 vObj(dest.GetPositionX(), dest.GetPositionY(), dest.GetPositionZ());
|
||||
G3D::Vector3 contactPoint = vThis + (vObj - vThis).directionOrZero() * std::min(dest.GetExactDist(this), GetObjectSize());
|
||||
|
||||
@@ -1150,29 +1160,47 @@ bool WorldObject::IsWithinLOS(float ox, float oy, float oz, LineOfSightChecks ch
|
||||
{
|
||||
if (IsInWorld())
|
||||
{
|
||||
oz += GetCollisionHeight();
|
||||
float x, y, z;
|
||||
if (GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
GetPosition(x, y, z);
|
||||
z += GetCollisionHeight();
|
||||
}
|
||||
else
|
||||
{
|
||||
GetHitSpherePointFor({ ox, oy, oz }, x, y, z);
|
||||
}
|
||||
|
||||
return GetMap()->isInLineOfSight(x, y, z + 2.0f, ox, oy, oz + 2.0f, GetPhaseMask(), checks);
|
||||
return GetMap()->isInLineOfSight(x, y, z, ox, oy, oz, GetPhaseMask(), checks);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WorldObject::IsWithinLOSInMap(const WorldObject* obj, LineOfSightChecks checks) const
|
||||
{
|
||||
if (!IsInMap(obj))
|
||||
if (!IsInMap(obj))
|
||||
return false;
|
||||
|
||||
float x, y, z;
|
||||
float ox, oy, oz;
|
||||
if (obj->GetTypeId() == TYPEID_PLAYER)
|
||||
obj->GetPosition(x, y, z);
|
||||
{
|
||||
obj->GetPosition(ox, oy, oz);
|
||||
oz += GetCollisionHeight();
|
||||
}
|
||||
else
|
||||
obj->GetHitSpherePointFor(GetPosition(), x, y, z);
|
||||
obj->GetHitSpherePointFor({ GetPositionX(), GetPositionY(), GetPositionZ() + GetCollisionHeight() }, ox, oy, oz);
|
||||
|
||||
return IsWithinLOS(x, y, z, checks);
|
||||
float x, y, z;
|
||||
if (GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
GetPosition(x, y, z);
|
||||
z += GetCollisionHeight();
|
||||
}
|
||||
else
|
||||
GetHitSpherePointFor({ obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ() + obj->GetCollisionHeight() }, x, y, z);
|
||||
|
||||
return GetMap()->isInLineOfSight(x, y, z, ox, oy, oz, GetPhaseMask(), checks);
|
||||
}
|
||||
|
||||
void WorldObject::GetHitSpherePointFor(Position const& dest, float& x, float& y, float& z) const
|
||||
@@ -1302,12 +1330,7 @@ float Position::GetAngle(const Position* obj) const
|
||||
// Return angle in range 0..2*pi
|
||||
float Position::GetAngle(const float x, const float y) const
|
||||
{
|
||||
float dx = x - GetPositionX();
|
||||
float dy = y - GetPositionY();
|
||||
|
||||
float ang = atan2(dy, dx);
|
||||
ang = (ang >= 0) ? ang : 2 * M_PI + ang;
|
||||
return ang;
|
||||
return getAngle(GetPositionX(), GetPositionY(), x, y);
|
||||
}
|
||||
|
||||
void Position::GetSinCos(const float x, const float y, float& vsin, float& vcos) const
|
||||
@@ -1446,78 +1469,95 @@ void WorldObject::GetRandomPoint(const Position& pos, float distance, float& ran
|
||||
UpdateGroundPositionZ(rand_x, rand_y, rand_z); // update to LOS height if available
|
||||
}
|
||||
|
||||
void WorldObject::UpdateGroundPositionZ(float x, float y, float& z) const
|
||||
void WorldObject::UpdateGroundPositionZ(float x, float y, float &z) const
|
||||
{
|
||||
float new_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z /*+ 2.0f*/, true); // pussywizard: +2.0f is added in all inner functions
|
||||
float new_z = GetMapHeight(x, y, z);
|
||||
if (new_z > INVALID_HEIGHT)
|
||||
z = new_z + 0.05f; // just to be sure that we are not a few pixel under the surface
|
||||
z = new_z + (isType(TYPEMASK_UNIT) ? static_cast<Unit const*>(this)->GetHoverHeight() : 0.0f);
|
||||
}
|
||||
|
||||
void WorldObject::UpdateAllowedPositionZ(float x, float y, float& z) const
|
||||
/**
|
||||
* @brief Get the minimum height of a object that should be in water
|
||||
* to start floating/swim
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
float WorldObject::GetMinHeightInWater() const
|
||||
{
|
||||
// TODO: Allow transports to be part of dynamic vmap tree
|
||||
//if (GetTransport())
|
||||
// return;
|
||||
// have a fun with Archimedes' formula
|
||||
auto height = GetCollisionHeight();
|
||||
auto width = GetCollisionWidth();
|
||||
auto weight = getWeight(height, width, 1040); // avg human specific weight
|
||||
auto heightOutOfWater = getOutOfWater(width, weight, 10202) * 4.0f; // avg human density
|
||||
auto heightInWater = height - heightOutOfWater;
|
||||
return (height > heightInWater ? heightInWater : (height - (height / 3)));
|
||||
}
|
||||
|
||||
switch (GetTypeId())
|
||||
void WorldObject::UpdateAllowedPositionZ(float x, float y, float& z, float* groundZ) const
|
||||
{
|
||||
if (GetTransport())
|
||||
{
|
||||
case TYPEID_UNIT:
|
||||
if (groundZ)
|
||||
*groundZ = z;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (Unit const* unit = ToUnit())
|
||||
{
|
||||
if (!unit->CanFly())
|
||||
{
|
||||
Creature const* c = unit->ToCreature();
|
||||
bool canSwim = c ? c->CanSwim() : true;
|
||||
float ground_z = z;
|
||||
float max_z;
|
||||
if (canSwim)
|
||||
max_z = GetMapWaterOrGroundLevel(x, y, z, &ground_z);
|
||||
else
|
||||
max_z = ground_z = GetMapHeight(x, y, z);
|
||||
|
||||
if (max_z > INVALID_HEIGHT)
|
||||
{
|
||||
// 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
|
||||
if (!ToCreature()->CanFly())
|
||||
{
|
||||
bool canSwim = ToCreature()->CanSwim();
|
||||
float ground_z = z;
|
||||
float max_z = canSwim
|
||||
? GetMap()->GetWaterOrGroundLevel(GetPhaseMask(), x, y, z, &ground_z, !ToUnit()->HasAuraType(SPELL_AURA_WATER_WALK))
|
||||
: ((ground_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z, true)));
|
||||
if (max_z > INVALID_HEIGHT)
|
||||
{
|
||||
if (z > max_z)
|
||||
z = max_z;
|
||||
else if (z < ground_z)
|
||||
z = ground_z;
|
||||
}
|
||||
if (canSwim && unit->GetMap()->IsInWater(x, y, max_z - WATER_HEIGHT_TOLERANCE)) {
|
||||
// do not allow creatures to walk on
|
||||
// water level while swimming
|
||||
max_z = max_z - GetMinHeightInWater();
|
||||
}
|
||||
else
|
||||
{
|
||||
float ground_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z, true);
|
||||
if (z < ground_z)
|
||||
z = ground_z;
|
||||
// hovering units cannot go below their hover height
|
||||
float hoverOffset = unit->GetHoverHeight();
|
||||
max_z += hoverOffset;
|
||||
ground_z += hoverOffset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TYPEID_PLAYER:
|
||||
{
|
||||
// for server controlled moves playr work same as creature (but it can always swim)
|
||||
if (!ToPlayer()->CanFly())
|
||||
{
|
||||
float ground_z = z;
|
||||
float max_z = GetMap()->GetWaterOrGroundLevel(GetPhaseMask(), x, y, z, &ground_z, !ToUnit()->HasAuraType(SPELL_AURA_WATER_WALK));
|
||||
if (max_z > INVALID_HEIGHT)
|
||||
{
|
||||
if (z > max_z)
|
||||
z = max_z;
|
||||
else if (z < ground_z)
|
||||
z = ground_z;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float ground_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z, true);
|
||||
if (z < ground_z)
|
||||
z = ground_z;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
float ground_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z, true);
|
||||
if (ground_z > INVALID_HEIGHT)
|
||||
|
||||
if (z > max_z)
|
||||
z = max_z;
|
||||
else if (z < ground_z)
|
||||
z = ground_z;
|
||||
break;
|
||||
}
|
||||
|
||||
if (groundZ)
|
||||
*groundZ = ground_z;
|
||||
}
|
||||
else
|
||||
{
|
||||
float ground_z = GetMapHeight(x, y, z) + unit->GetHoverHeight();
|
||||
if (z < ground_z)
|
||||
z = ground_z;
|
||||
|
||||
if (groundZ)
|
||||
*groundZ = ground_z;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float ground_z = GetMapHeight(x, y, z);
|
||||
if (ground_z > INVALID_HEIGHT)
|
||||
z = ground_z;
|
||||
|
||||
if (groundZ)
|
||||
*groundZ = ground_z;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2552,23 +2592,64 @@ namespace acore
|
||||
|
||||
//===================================================================================================
|
||||
|
||||
void WorldObject::GetNearPoint2D(float& x, float& y, float distance2d, float absAngle) const
|
||||
void WorldObject::GetNearPoint2D(WorldObject const* searcher, float& x, float& y, float distance2d, float absAngle) const
|
||||
{
|
||||
x = GetPositionX() + (GetObjectSize() + distance2d) * cos(absAngle);
|
||||
y = GetPositionY() + (GetObjectSize() + distance2d) * sin(absAngle);
|
||||
float effectiveReach = GetCombatReach();
|
||||
|
||||
if (searcher)
|
||||
{
|
||||
effectiveReach += searcher->GetCombatReach();
|
||||
|
||||
if (this != searcher)
|
||||
{
|
||||
float myHover = 0.0f, searcherHover = 0.0f;
|
||||
if (Unit const* unit = ToUnit())
|
||||
myHover = unit->GetHoverHeight();
|
||||
if (Unit const* searchUnit = searcher->ToUnit())
|
||||
searcherHover = searchUnit->GetHoverHeight();
|
||||
|
||||
float hoverDelta = myHover - searcherHover;
|
||||
if (hoverDelta != 0.0f)
|
||||
effectiveReach = std::sqrt(std::max(effectiveReach * effectiveReach - hoverDelta * hoverDelta, 0.0f));
|
||||
}
|
||||
}
|
||||
|
||||
x = GetPositionX() + (effectiveReach + distance2d) * std::cos(absAngle);
|
||||
y = GetPositionY() + (effectiveReach + distance2d) * std::sin(absAngle);
|
||||
|
||||
acore::NormalizeMapCoord(x);
|
||||
acore::NormalizeMapCoord(y);
|
||||
}
|
||||
|
||||
void WorldObject::GetNearPoint2D(float& x, float& y, float distance2d, float absAngle) const
|
||||
{
|
||||
GetNearPoint2D(nullptr, x, y, distance2d, absAngle);
|
||||
}
|
||||
|
||||
void WorldObject::GetNearPoint(WorldObject const* searcher, float& x, float& y, float& z, float searcher_size, float distance2d, float absAngle, float controlZ) const
|
||||
{
|
||||
GetNearPoint2D(x, y, distance2d + searcher_size, absAngle);
|
||||
z = GetPositionZ();
|
||||
if (searcher)
|
||||
|
||||
if (searcher) {
|
||||
if (Unit const* unit = searcher->ToUnit(); Unit const* target = ToUnit())
|
||||
{
|
||||
if (unit && target && unit->IsInWater() && target->IsInWater())
|
||||
{
|
||||
// if the searcher is in water
|
||||
// we have no ground so we can
|
||||
// set the target height to the
|
||||
// z-coord to keep the searcher
|
||||
// at the correct height (face to face)
|
||||
z += GetCollisionHeight() - unit->GetCollisionHeight();
|
||||
}
|
||||
}
|
||||
searcher->UpdateAllowedPositionZ(x, y, z);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateAllowedPositionZ(x, y, z);
|
||||
}
|
||||
|
||||
// if detection disabled, return first point
|
||||
if (!sWorld->getBoolConfig(CONFIG_DETECT_POS_COLLISION))
|
||||
@@ -2679,8 +2760,8 @@ void WorldObject::MovePosition(Position& pos, float dist, float angle)
|
||||
return;
|
||||
}
|
||||
|
||||
ground = GetMap()->GetHeight(GetPhaseMask(), destx, desty, MAX_HEIGHT, true);
|
||||
floor = GetMap()->GetHeight(GetPhaseMask(), destx, desty, pos.m_positionZ, true);
|
||||
ground = GetMapHeight(destx, desty, MAX_HEIGHT);
|
||||
floor = GetMapHeight(destx, desty, pos.m_positionZ);
|
||||
destz = fabs(ground - pos.m_positionZ) <= fabs(floor - pos.m_positionZ) ? ground : floor;
|
||||
|
||||
float step = dist / 10.0f;
|
||||
@@ -2692,215 +2773,74 @@ void WorldObject::MovePosition(Position& pos, float dist, float angle)
|
||||
{
|
||||
destx -= step * cos(angle);
|
||||
desty -= step * sin(angle);
|
||||
ground = GetMap()->GetHeight(GetPhaseMask(), destx, desty, MAX_HEIGHT, true);
|
||||
floor = GetMap()->GetHeight(GetPhaseMask(), destx, desty, pos.m_positionZ, true);
|
||||
ground = GetMapHeight(destx, desty, MAX_HEIGHT);
|
||||
floor = GetMapHeight(destx, desty, pos.m_positionZ);
|
||||
destz = fabs(ground - pos.m_positionZ) <= fabs(floor - pos.m_positionZ) ? ground : floor;
|
||||
}
|
||||
// we have correct destz now
|
||||
else
|
||||
{
|
||||
pos.Relocate(destx, desty, destz);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pos.Relocate(destx, desty, destz);
|
||||
|
||||
acore::NormalizeMapCoord(pos.m_positionX);
|
||||
acore::NormalizeMapCoord(pos.m_positionY);
|
||||
UpdateGroundPositionZ(pos.m_positionX, pos.m_positionY, pos.m_positionZ);
|
||||
pos.m_orientation = m_orientation;
|
||||
}
|
||||
|
||||
Position WorldObject::GetFirstCollisionPosition(float startX, float startY, float startZ, float destX, float destY)
|
||||
{
|
||||
auto dx = destX - startX;
|
||||
auto dy = destY - startY;
|
||||
|
||||
auto ang = atan2(dy, dx);
|
||||
ang = (ang >= 0) ? ang : 2 * M_PI + ang;
|
||||
Position pos = Position(startX, startY, startZ, ang);
|
||||
|
||||
auto distance = pos.GetExactDist2d(destX,destY);
|
||||
|
||||
MovePositionToFirstCollision(pos, distance, ang);
|
||||
return pos;
|
||||
};
|
||||
|
||||
Position WorldObject::GetFirstCollisionPosition(float destX, float destY, float destZ)
|
||||
{
|
||||
Position pos = GetPosition();
|
||||
auto distance = GetExactDistSq(destX,destY,destZ);
|
||||
|
||||
auto dx = destX - pos.GetPositionX();
|
||||
auto dy = destY - pos.GetPositionY();
|
||||
|
||||
auto ang = atan2(dy, dx);
|
||||
ang = (ang >= 0) ? ang : 2 * M_PI + ang;
|
||||
|
||||
MovePositionToFirstCollision(pos, distance, ang);
|
||||
return pos;
|
||||
};
|
||||
|
||||
Position WorldObject::GetFirstCollisionPosition(float dist, float angle)
|
||||
{
|
||||
Position pos = GetPosition();
|
||||
GetFirstCollisionPosition(pos, dist, angle);
|
||||
return pos;
|
||||
}
|
||||
|
||||
void WorldObject::MovePositionToFirstCollision(Position& pos, float dist, float angle)
|
||||
{
|
||||
angle += m_orientation;
|
||||
angle += GetOrientation();
|
||||
float destx, desty, destz;
|
||||
destx = pos.m_positionX + dist * cos(angle);
|
||||
desty = pos.m_positionY + dist * sin(angle);
|
||||
destz = pos.m_positionZ;
|
||||
if (isType(TYPEMASK_UNIT | TYPEMASK_PLAYER) && !ToUnit()->IsInWater())
|
||||
destz += 2.0f;
|
||||
|
||||
// Prevent invalid coordinates here, position is unchanged
|
||||
if (!acore::IsValidMapCoord(destx, desty))
|
||||
{
|
||||
sLog->outCrash("WorldObject::MovePositionToFirstCollision invalid coordinates X: %f and Y: %f were passed!", destx, desty);
|
||||
if (!GetMap()->CheckCollisionAndGetValidCoords(this, pos.m_positionX, pos.m_positionY, pos.m_positionZ, destx, desty, destz, false))
|
||||
return;
|
||||
}
|
||||
|
||||
// Xinef: ugly hack for dalaran arena
|
||||
float selfAddition = 1.5f;
|
||||
float allowedDiff = 6.0f;
|
||||
float newDist = dist;
|
||||
if (GetMapId() == 617)
|
||||
{
|
||||
allowedDiff = 3.5f;
|
||||
selfAddition = 1.0f;
|
||||
destz = pos.m_positionZ + 1.0f;
|
||||
}
|
||||
else
|
||||
UpdateAllowedPositionZ(destx, desty, destz);
|
||||
|
||||
bool col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(GetMapId(), pos.m_positionX, pos.m_positionY, pos.m_positionZ + selfAddition, destx, desty, destz + 0.5f, destx, desty, destz, -0.5f);
|
||||
|
||||
// collision occured
|
||||
if (col)
|
||||
{
|
||||
// move back a bit
|
||||
if (pos.GetExactDist2d(destx, desty) > CONTACT_DISTANCE)
|
||||
{
|
||||
destx -= CONTACT_DISTANCE * cos(angle);
|
||||
desty -= CONTACT_DISTANCE * sin(angle);
|
||||
}
|
||||
|
||||
newDist = sqrt((pos.m_positionX - destx) * (pos.m_positionX - destx) + (pos.m_positionY - desty) * (pos.m_positionY - desty));
|
||||
}
|
||||
|
||||
// check dynamic collision
|
||||
col = GetMap()->getObjectHitPos(GetPhaseMask(), pos.m_positionX, pos.m_positionY, pos.m_positionZ + selfAddition, destx, desty, destz + 0.5f, destx, desty, destz, -0.5f);
|
||||
|
||||
// Collided with a gameobject
|
||||
if (col)
|
||||
{
|
||||
// move back a bit
|
||||
if (pos.GetExactDist2d(destx, desty) > CONTACT_DISTANCE)
|
||||
{
|
||||
destx -= CONTACT_DISTANCE * cos(angle);
|
||||
desty -= CONTACT_DISTANCE * sin(angle);
|
||||
}
|
||||
newDist = sqrt((pos.m_positionX - destx) * (pos.m_positionX - destx) + (pos.m_positionY - desty) * (pos.m_positionY - desty));
|
||||
}
|
||||
|
||||
float step = newDist / 10.0f;
|
||||
|
||||
for (uint8 j = 0; j < 10; ++j)
|
||||
{
|
||||
// do not allow too big z changes
|
||||
if (fabs(pos.m_positionZ - destz) > allowedDiff)
|
||||
{
|
||||
destx -= step * cos(angle);
|
||||
desty -= step * sin(angle);
|
||||
UpdateAllowedPositionZ(destx, desty, destz);
|
||||
}
|
||||
// we have correct destz now
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
acore::NormalizeMapCoord(destx);
|
||||
acore::NormalizeMapCoord(desty);
|
||||
UpdateAllowedPositionZ(destx, desty, destz);
|
||||
|
||||
float ground = GetMap()->GetHeight(GetPhaseMask(), destx, desty, MAX_HEIGHT, true);
|
||||
float floor = GetMap()->GetHeight(GetPhaseMask(), destx, desty, destz, true);
|
||||
ground = fabs(ground - destz) <= fabs(floor - pos.m_positionZ) ? ground : floor;
|
||||
if (destz < ground)
|
||||
destz = ground;
|
||||
|
||||
// Xinef: check if last z updates did not move z too far away
|
||||
//newDist = pos.GetExactDist(destx, desty, destz);
|
||||
//float ratio = newDist / dist;
|
||||
//if (ratio > 1.3f)
|
||||
//{
|
||||
// ratio = (1 / ratio) + (0.3f / ratio);
|
||||
// destx = pos.GetPositionX() + (fabs(destx - pos.GetPositionX()) * cos(angle) * ratio);
|
||||
// desty = pos.GetPositionY() + (fabs(desty - pos.GetPositionY()) * sin(angle) * ratio);
|
||||
// destz = pos.GetPositionZ() + (fabs(destz - pos.GetPositionZ()) * ratio * (destz < pos.GetPositionZ() ? -1.0f : 1.0f));
|
||||
//}
|
||||
|
||||
pos.SetOrientation(GetOrientation());
|
||||
pos.Relocate(destx, desty, destz);
|
||||
pos.m_orientation = m_orientation;
|
||||
}
|
||||
|
||||
void WorldObject::MovePositionToFirstCollisionForTotem(Position& pos, float dist, float angle, bool forGameObject)
|
||||
{
|
||||
angle += m_orientation;
|
||||
float destx, desty, destz, ground, floor;
|
||||
pos.m_positionZ += 2.0f;
|
||||
destx = pos.m_positionX + dist * cos(angle);
|
||||
desty = pos.m_positionY + dist * sin(angle);
|
||||
destz = pos.GetPositionZ();
|
||||
|
||||
// Prevent invalid coordinates here, position is unchanged
|
||||
if (!acore::IsValidMapCoord(destx, desty))
|
||||
{
|
||||
sLog->outCrash("WorldObject::MovePositionToFirstCollision invalid coordinates X: %f and Y: %f were passed!", destx, desty);
|
||||
return;
|
||||
}
|
||||
|
||||
bool col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(GetMapId(), pos.m_positionX, pos.m_positionY, pos.m_positionZ, destx, desty, destz, destx, desty, destz, -0.5f);
|
||||
|
||||
// collision occured
|
||||
if (col)
|
||||
{
|
||||
// move back a bit
|
||||
if (pos.GetExactDist2d(destx, desty) > CONTACT_DISTANCE)
|
||||
{
|
||||
destx -= CONTACT_DISTANCE * cos(angle);
|
||||
desty -= CONTACT_DISTANCE * sin(angle);
|
||||
}
|
||||
|
||||
dist = sqrt((pos.m_positionX - destx) * (pos.m_positionX - destx) + (pos.m_positionY - desty) * (pos.m_positionY - desty));
|
||||
}
|
||||
|
||||
// check dynamic collision
|
||||
col = GetMap()->getObjectHitPos(GetPhaseMask(), pos.m_positionX, pos.m_positionY, pos.m_positionZ + 0.5f, destx, desty, destz + 0.5f, destx, desty, destz, -0.5f);
|
||||
|
||||
// Collided with a gameobject
|
||||
if (col)
|
||||
{
|
||||
// move back a bit
|
||||
if (pos.GetExactDist2d(destx, desty) > CONTACT_DISTANCE)
|
||||
{
|
||||
destx -= CONTACT_DISTANCE * cos(angle);
|
||||
desty -= CONTACT_DISTANCE * sin(angle);
|
||||
}
|
||||
dist = sqrt((pos.m_positionX - destx) * (pos.m_positionX - destx) + (pos.m_positionY - desty) * (pos.m_positionY - desty));
|
||||
}
|
||||
|
||||
float prevdx = destx, prevdy = desty, prevdz = destz;
|
||||
bool anyvalid = false;
|
||||
|
||||
ground = GetMap()->GetHeight(GetPhaseMask(), destx, desty, MAX_HEIGHT, true);
|
||||
floor = GetMap()->GetHeight(GetPhaseMask(), destx, desty, pos.m_positionZ, true);
|
||||
destz = fabs(ground - pos.m_positionZ) <= fabs(floor - pos.m_positionZ) ? ground : floor;
|
||||
|
||||
// xinef: if we have gameobject, store last valid ground position
|
||||
// xinef: I assume you wanted to spawn totem in air and allow it to fall down if no valid position was found
|
||||
if (forGameObject)
|
||||
prevdz = destz;
|
||||
|
||||
float step = dist / 10.0f;
|
||||
for (uint8 j = 0; j < 10; ++j)
|
||||
{
|
||||
// do not allow too big z changes
|
||||
if (fabs(pos.m_positionZ - destz) > 4.0f)
|
||||
{
|
||||
destx -= step * cos(angle);
|
||||
desty -= step * sin(angle);
|
||||
ground = GetMap()->GetHeight(GetPhaseMask(), destx, desty, MAX_HEIGHT, true);
|
||||
floor = GetMap()->GetHeight(GetPhaseMask(), destx, desty, pos.m_positionZ, true);
|
||||
destz = fabs(ground - pos.m_positionZ) <= fabs(floor - pos.m_positionZ) ? ground : floor;
|
||||
if (j == 9 && fabs(pos.m_positionZ - destz) <= 4.0f)
|
||||
anyvalid = true;
|
||||
}
|
||||
// we have correct destz now
|
||||
else
|
||||
{
|
||||
anyvalid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!anyvalid)
|
||||
{
|
||||
destx = prevdx;
|
||||
desty = prevdy;
|
||||
destz = prevdz;
|
||||
}
|
||||
|
||||
acore::NormalizeMapCoord(destx);
|
||||
acore::NormalizeMapCoord(desty);
|
||||
|
||||
pos.Relocate(destx, desty, destz);
|
||||
pos.m_orientation = m_orientation;
|
||||
}
|
||||
|
||||
void WorldObject::SetPhaseMask(uint32 newPhaseMask, bool update)
|
||||
@@ -3116,3 +3056,26 @@ uint64 WorldObject::GetTransGUID() const
|
||||
return GetTransport()->GetGUID();
|
||||
return 0;
|
||||
}
|
||||
|
||||
float WorldObject::GetMapHeight(float x, float y, float z, bool vmap/* = true*/, float distanceToSearch/* = DEFAULT_HEIGHT_SEARCH*/) const
|
||||
{
|
||||
if (z != MAX_HEIGHT)
|
||||
z += GetCollisionHeight();
|
||||
|
||||
return GetMap()->GetHeight(GetPhaseMask(), x, y, z, vmap, distanceToSearch);
|
||||
}
|
||||
|
||||
float WorldObject::GetMapWaterOrGroundLevel(float x, float y, float z, float* ground/* = nullptr*/) const
|
||||
{
|
||||
return GetMap()->GetWaterOrGroundLevel(GetPhaseMask(), x, y, z, ground,
|
||||
isType(TYPEMASK_UNIT) ? !static_cast<Unit const*>(this)->HasAuraType(SPELL_AURA_WATER_WALK) : false,
|
||||
GetCollisionHeight());
|
||||
}
|
||||
|
||||
float WorldObject::GetFloorZ() const
|
||||
{
|
||||
if (!IsInWorld())
|
||||
return m_staticFloorZ;
|
||||
|
||||
return std::max<float>(m_staticFloorZ, GetMap()->GetGameObjectFloor(GetPhaseMask(), GetPositionX(), GetPositionY(), GetPositionZ() + GetCollisionHeight()));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -9,6 +9,27 @@
|
||||
|
||||
#include "Define.h"
|
||||
|
||||
#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
|
||||
#define DEFAULT_COLLISION_HEIGHT 2.03128f // Most common value in dbc
|
||||
|
||||
enum HighGuid
|
||||
{
|
||||
HIGHGUID_ITEM = 0x4000, // blizz 4000
|
||||
|
||||
Reference in New Issue
Block a user