aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Entities
diff options
context:
space:
mode:
authorJeremy <Golrag@users.noreply.github.com>2017-12-29 22:32:07 +0100
committerjackpoz <giacomopoz@gmail.com>2017-12-29 22:32:07 +0100
commite42903ec16f4849b71bc8736e3151a1e11d3cd25 (patch)
tree80bfb40b6e9f0c8acd8fa842b8af803ed5734a0d /src/server/game/Entities
parente2a97ba7e789748aaa46ace153382573fd7d7df5 (diff)
Core/Entities: Fix some weird movement due to los issues (#21125)
* Core/Entities: Fix some weird movement due to los issues - Made LoS check use collisionHeight instead of midsection. Value was too low. - Gnomes will now have a breath bar more quickly than for example a tauren. - Changes have been made to checking for ground z as well, some tweeking might be needed but removed most of the scattered +2.0f/+0.5f/we * Add 0.05f to isInAir check in Creature::UpdateMovementFlags
Diffstat (limited to 'src/server/game/Entities')
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp2
-rw-r--r--src/server/game/Entities/Object/Object.cpp105
-rw-r--r--src/server/game/Entities/Object/Object.h6
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp11
4 files changed, 65 insertions, 59 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index 7a8cce89778..c1ef094f769 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -2896,7 +2896,7 @@ void Creature::UpdateMovementFlags()
// 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 = GetFloorZ();
- bool isInAir = (G3D::fuzzyGt(GetPositionZMinusOffset(), ground + 0.05f) || G3D::fuzzyLt(GetPositionZMinusOffset(), ground - 0.05f)); // Can be underground too, prevent the falling
+ bool isInAir = (G3D::fuzzyGt(GetPositionZMinusOffset(), ground + GROUND_HEIGHT_TOLERANCE) || G3D::fuzzyLt(GetPositionZMinusOffset(), ground - GROUND_HEIGHT_TOLERANCE)); // Can be underground too, prevent the falling
if (GetCreatureTemplate()->InhabitType & INHABIT_AIR && isInAir && !IsFalling())
{
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp
index e9269b64e39..b37c7f9b45f 100644
--- a/src/server/game/Entities/Object/Object.cpp
+++ b/src/server/game/Entities/Object/Object.cpp
@@ -1105,7 +1105,7 @@ void WorldObject::_Create(ObjectGuid::LowType guidlow, HighGuid guidhigh, uint32
void WorldObject::UpdatePositionData()
{
PositionFullTerrainStatus data;
- GetMap()->GetFullTerrainStatusForPosition(GetPositionX(), GetPositionY(), GetPositionZ(), data);
+ GetMap()->GetFullTerrainStatusForPosition(GetPositionX(), GetPositionY(), GetPositionZ(), data, MAP_ALL_LIQUIDS);
ProcessPositionDataChanged(data);
}
@@ -1246,7 +1246,7 @@ bool WorldObject::IsWithinDistInMap(WorldObject const* obj, float dist2compare,
Position WorldObject::GetHitSpherePointFor(Position const& dest) const
{
- G3D::Vector3 vThis(GetPositionX(), GetPositionY(), GetPositionZ() + GetMidsectionHeight());
+ 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(GetPosition()), GetCombatReach());
@@ -1257,11 +1257,12 @@ 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 += GetMidsectionHeight();
+ z += GetCollisionHeight();
}
else
GetHitSpherePointFor({ ox, oy, oz }, x, y, z);
@@ -1277,16 +1278,25 @@ bool WorldObject::IsWithinLOSInMap(WorldObject const* obj, LineOfSightChecks che
if (!IsInMap(obj))
return false;
- float x, y, z;
+ float ox, oy, oz;
if (obj->GetTypeId() == TYPEID_PLAYER)
{
- obj->GetPosition(x, y, z);
- z += GetMidsectionHeight();
+ obj->GetPosition(ox, oy, oz);
+ oz += GetCollisionHeight();
+ }
+ else
+ obj->GetHitSpherePointFor({ GetPositionX(), GetPositionY(), GetPositionZ() + GetCollisionHeight() }, ox, oy, oz);
+
+ float x, y, z;
+ if (GetTypeId() == TYPEID_PLAYER)
+ {
+ GetPosition(x, y, z);
+ z += GetCollisionHeight();
}
else
- obj->GetHitSpherePointFor({ GetPositionX(), GetPositionY(), GetPositionZ() + GetMidsectionHeight() }, x, y, z);
+ GetHitSpherePointFor({ obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ() + obj->GetCollisionHeight() }, x, y, z);
- return IsWithinLOS(x, y, z, checks, ignoreFlags);
+ return GetMap()->isInLineOfSight(x, y, z, ox, oy, oz, GetPhaseMask(), checks, ignoreFlags);
}
void WorldObject::GetHitSpherePointFor(Position const& dest, float& x, float& y, float& z) const
@@ -1444,9 +1454,7 @@ Position WorldObject::GetRandomPoint(Position const& srcPos, float distance) con
void WorldObject::UpdateGroundPositionZ(float x, float y, float &z) const
{
- float new_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z + 2.0f, true);
- 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 = GetMapHeight(x, y, z);
}
void WorldObject::UpdateAllowedPositionZ(float x, float y, float &z) const
@@ -1466,8 +1474,8 @@ void WorldObject::UpdateAllowedPositionZ(float x, float y, float &z) const
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)));
+ ? GetMapWaterOrGroundLevel(x, y, z, &ground_z)
+ : (ground_z = GetMapHeight(x, y, z));
if (max_z > INVALID_HEIGHT)
{
if (z > max_z)
@@ -1478,7 +1486,7 @@ void WorldObject::UpdateAllowedPositionZ(float x, float y, float &z) const
}
else
{
- float ground_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z, true);
+ float ground_z = GetMapHeight(x, y, z);
if (z < ground_z)
z = ground_z;
}
@@ -1490,7 +1498,7 @@ void WorldObject::UpdateAllowedPositionZ(float x, float y, float &z) const
if (!ToPlayer()->CanFly())
{
float ground_z = z;
- float max_z = GetMap()->GetWaterOrGroundLevel(GetPhaseMask(), x, y, z, &ground_z, !ToUnit()->HasAuraType(SPELL_AURA_WATER_WALK));
+ float max_z = GetMapWaterOrGroundLevel(x, y, z, &ground_z);
if (max_z > INVALID_HEIGHT)
{
if (z > max_z)
@@ -1501,7 +1509,7 @@ void WorldObject::UpdateAllowedPositionZ(float x, float y, float &z) const
}
else
{
- float ground_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z, true);
+ float ground_z = GetMapHeight(x, y, z);
if (z < ground_z)
z = ground_z;
}
@@ -1509,7 +1517,7 @@ void WorldObject::UpdateAllowedPositionZ(float x, float y, float &z) const
}
default:
{
- float ground_z = GetMap()->GetHeight(GetPhaseMask(), x, y, z, true);
+ float ground_z = GetMapHeight(x, y, z);
if (ground_z > INVALID_HEIGHT)
z = ground_z;
break;
@@ -2266,8 +2274,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 = std::fabs(ground - pos.m_positionZ) <= std::fabs(floor - pos.m_positionZ) ? ground : floor;
float step = dist/10.0f;
@@ -2279,8 +2287,8 @@ void WorldObject::MovePosition(Position &pos, float dist, float angle)
{
destx -= step * std::cos(angle);
desty -= step * std::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 = std::fabs(ground - pos.m_positionZ) <= std::fabs(floor - pos.m_positionZ) ? ground : floor;
}
// we have correct destz now
@@ -2297,38 +2305,13 @@ void WorldObject::MovePosition(Position &pos, float dist, float angle)
pos.SetOrientation(GetOrientation());
}
-// @todo: replace with WorldObject::UpdateAllowedPositionZ
-float NormalizeZforCollision(WorldObject* obj, float x, float y, float z)
-{
- float ground = obj->GetMap()->GetHeight(obj->GetPhaseMask(), x, y, MAX_HEIGHT, true);
- float floor = obj->GetMap()->GetHeight(obj->GetPhaseMask(), x, y, z + 2.0f, true);
- float helper = std::fabs(ground - z) <= std::fabs(floor - z) ? ground : floor;
- if (z > helper) // must be above ground
- {
- if (Unit* unit = obj->ToUnit())
- {
- if (unit->CanFly())
- return z;
- }
- LiquidData liquid_status;
- ZLiquidStatus res = obj->GetMap()->GetLiquidStatus(x, y, z, MAP_ALL_LIQUIDS, &liquid_status);
- if (res && liquid_status.level > helper) // water must be above ground
- {
- if (liquid_status.level > z) // z is underwater
- return z;
- else
- return std::fabs(liquid_status.level - z) <= std::fabs(helper - z) ? liquid_status.level : helper;
- }
- }
- return helper;
-}
-
void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float angle)
{
angle += GetOrientation();
float destx, desty, destz;
destx = pos.m_positionX + dist * std::cos(angle);
desty = pos.m_positionY + dist * std::sin(angle);
+ destz = pos.m_positionZ;
// Prevent invalid coordinates here, position is unchanged
if (!Trinity::IsValidMapCoord(destx, desty))
@@ -2337,8 +2320,8 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float
return;
}
- destz = NormalizeZforCollision(this, destx, desty, pos.GetPositionZ());
- bool col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(GetMapId(), pos.m_positionX, pos.m_positionY, pos.m_positionZ + 0.5f, destx, desty, destz + 0.5f, destx, desty, destz, -0.5f);
+ UpdateAllowedPositionZ(destx, desty, destz);
+ 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)
@@ -2350,7 +2333,7 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float
}
// 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);
+ col = GetMap()->getObjectHitPos(GetPhaseMask(), pos.m_positionX, pos.m_positionY, pos.m_positionZ, destx, desty, destz, destx, desty, destz, -0.5f);
// Collided with a gameobject
if (col)
@@ -2369,7 +2352,7 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float
{
destx -= step * std::cos(angle);
desty -= step * std::sin(angle);
- destz = NormalizeZforCollision(this, destx, desty, pos.GetPositionZ());
+ UpdateAllowedPositionZ(destx, desty, destz);
}
// we have correct destz now
else
@@ -2381,7 +2364,7 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float
Trinity::NormalizeMapCoord(pos.m_positionX);
Trinity::NormalizeMapCoord(pos.m_positionY);
- pos.m_positionZ = NormalizeZforCollision(this, destx, desty, pos.GetPositionZ());
+ UpdateAllowedPositionZ(destx, desty, pos.m_positionZ);
pos.SetOrientation(GetOrientation());
}
@@ -2567,7 +2550,23 @@ float WorldObject::GetFloorZ() const
{
if (!IsInWorld())
return m_staticFloorZ;
- return std::max<float>(m_staticFloorZ, GetMap()->GetGameObjectFloor(GetPhaseMask(), GetPositionX(), GetPositionY(), GetPositionZ()));
+ return std::max<float>(m_staticFloorZ, GetMap()->GetGameObjectFloor(GetPhaseMask(), GetPositionX(), GetPositionY(), GetPositionZ() + GetCollisionHeight()));
+}
+
+float WorldObject::GetMapWaterOrGroundLevel(float x, float y, float z, float* ground/* = nullptr*/) const
+{
+ if (Unit const* unit = ToUnit())
+ return GetMap()->GetWaterOrGroundLevel(GetPhaseMask(), x, y, z, ground, !unit->HasAuraType(SPELL_AURA_WATER_WALK), GetCollisionHeight());
+
+ return z;
+}
+
+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);
}
template TC_GAME_API void WorldObject::GetGameObjectListWithEntryInGrid(std::list<GameObject*>&, uint32, float) const;
diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h
index 66f1c67fa51..a573c4e84a6 100644
--- a/src/server/game/Entities/Object/Object.h
+++ b/src/server/game/Entities/Object/Object.h
@@ -55,6 +55,8 @@ struct QuaternionData;
typedef std::unordered_map<Player*, UpdateData> UpdateDataMapType;
+float const DEFAULT_COLLISION_HEIGHT = 2.03128f; // Most common value in dbc
+
class TC_GAME_API Object
{
public:
@@ -445,7 +447,9 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
float GetFloorZ() const;
virtual float GetCollisionHeight() const { return 0.0f; }
- float GetMidsectionHeight() const { return GetCollisionHeight() / 2.0f; }
+
+ float GetMapWaterOrGroundLevel(float x, float y, float z, float* ground = nullptr) const;
+ float GetMapHeight(float x, float y, float z, bool vmap = true, float distanceToSearch = 50.0f) const; // DEFAULT_HEIGHT_SEARCH in map.h
protected:
std::string m_name;
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index 7fd73ed4d8d..b67406eba74 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -13819,12 +13819,12 @@ void Unit::_ExitVehicle(Position const* exitPosition)
SendMessageToSet(&data, false);
}
- float height = pos.GetPositionZ();
+ float height = pos.GetPositionZ() + vehicle->GetBase()->GetCollisionHeight();
Movement::MoveSplineInit init(this);
// Creatures without inhabit type air should begin falling after exiting the vehicle
- if (GetTypeId() == TYPEID_UNIT && !CanFly() && height > GetMap()->GetWaterOrGroundLevel(GetPhaseMask(), pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), &height) + 0.1f)
+ if (GetTypeId() == TYPEID_UNIT && !CanFly() && height > GetMap()->GetWaterOrGroundLevel(GetPhaseMask(), pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ() + vehicle->GetBase()->GetCollisionHeight(), &height))
init.SetFall();
init.MoveTo(pos.GetPositionX(), pos.GetPositionY(), height, false);
@@ -14749,6 +14749,7 @@ void Unit::Whisper(uint32 textId, Player* target, bool isBossWhisper /*= false*/
target->SendDirectMessage(&data);
}
+// Returns collisionheight of the unit. If it is 0, it returns DEFAULT_COLLISION_HEIGHT.
float Unit::GetCollisionHeight() const
{
float scaleMod = GetObjectScale(); // 99% sure about this
@@ -14761,7 +14762,8 @@ float Unit::GetCollisionHeight() const
{
CreatureDisplayInfoEntry const* displayInfo = sCreatureDisplayInfoStore.AssertEntry(GetNativeDisplayId());
CreatureModelDataEntry const* modelData = sCreatureModelDataStore.AssertEntry(displayInfo->ModelId);
- return scaleMod * (mountModelData->MountHeight + modelData->CollisionHeight * 0.5f);
+ float const collisionHeight = scaleMod * (mountModelData->MountHeight + modelData->CollisionHeight * modelData->Scale * displayInfo->scale * 0.5f);
+ return collisionHeight == 0.0f ? DEFAULT_COLLISION_HEIGHT : collisionHeight;
}
}
}
@@ -14770,5 +14772,6 @@ float Unit::GetCollisionHeight() const
CreatureDisplayInfoEntry const* displayInfo = sCreatureDisplayInfoStore.AssertEntry(GetNativeDisplayId());
CreatureModelDataEntry const* modelData = sCreatureModelDataStore.AssertEntry(displayInfo->ModelId);
- return scaleMod * modelData->CollisionHeight;
+ float const collisionHeight = scaleMod * modelData->CollisionHeight * modelData->Scale * displayInfo->scale;
+ return collisionHeight == 0.0f ? DEFAULT_COLLISION_HEIGHT : collisionHeight;
}