Core/Collision: Replaced phasemask with proper phases in GameObject c…
…ollision calculation
This commit is contained in:
1 parent
27683014f2
commit
0fbcdca05e
29 files changed
+120
-152
No files matched your search
@@ -1426,7 +1426,7 @@ bool WorldObject::IsWithinDistInMap(WorldObject const* obj, float dist2compare,
|
||||
return obj && IsInMap(obj) && IsInPhase(obj) && _IsWithinDist(obj, dist2compare, is3D);
|
||||
}
|
||||
|
||||
bool WorldObject::IsWithinLOS(float ox, float oy, float oz, VMAP::ModelIgnoreFlags ignoreFlags) const
|
||||
bool WorldObject::IsWithinLOS(float ox, float oy, float oz) const
|
||||
{
|
||||
/*float x, y, z;
|
||||
GetPosition(x, y, z);
|
||||
@@ -1440,7 +1440,7 @@ bool WorldObject::IsWithinLOS(float ox, float oy, float oz, VMAP::ModelIgnoreFla
|
||||
else
|
||||
GetHitSpherePointFor({ ox, oy, oz }, x, y, z);
|
||||
|
||||
return GetMap()->isInLineOfSight(x, y, z + 2.0f, ox, oy, oz + 2.0f, GetPhaseMask(), ignoreFlags);
|
||||
return GetMap()->isInLineOfSight(x, y, z + 2.0f, ox, oy, oz + 2.0f, GetPhases());
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -1610,7 +1610,7 @@ Position WorldObject::GetRandomPoint(const Position &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);
|
||||
float new_z = GetMap()->GetHeight(GetPhases(), 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
|
||||
}
|
||||
@@ -1632,8 +1632,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)));
|
||||
? GetMap()->GetWaterOrGroundLevel(GetPhases(), x, y, z, &ground_z, !ToUnit()->HasAuraType(SPELL_AURA_WATER_WALK))
|
||||
: ((ground_z = GetMap()->GetHeight(GetPhases(), x, y, z, true)));
|
||||
if (max_z > INVALID_HEIGHT)
|
||||
{
|
||||
if (z > max_z)
|
||||
@@ -1644,7 +1644,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 = GetMap()->GetHeight(GetPhases(), x, y, z, true);
|
||||
if (z < ground_z)
|
||||
z = ground_z;
|
||||
}
|
||||
@@ -1656,7 +1656,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 = GetMap()->GetWaterOrGroundLevel(GetPhases(), x, y, z, &ground_z, !ToUnit()->HasAuraType(SPELL_AURA_WATER_WALK));
|
||||
if (max_z > INVALID_HEIGHT)
|
||||
{
|
||||
if (z > max_z)
|
||||
@@ -1667,7 +1667,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 = GetMap()->GetHeight(GetPhases(), x, y, z, true);
|
||||
if (z < ground_z)
|
||||
z = ground_z;
|
||||
}
|
||||
@@ -1675,7 +1675,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 = GetMap()->GetHeight(GetPhases(), x, y, z, true);
|
||||
if (ground_z > INVALID_HEIGHT)
|
||||
z = ground_z;
|
||||
break;
|
||||
@@ -2431,8 +2431,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 = GetMap()->GetHeight(GetPhases(), destx, desty, MAX_HEIGHT, true);
|
||||
floor = GetMap()->GetHeight(GetPhases(), destx, desty, pos.m_positionZ, true);
|
||||
destz = std::fabs(ground - pos.m_positionZ) <= std::fabs(floor - pos.m_positionZ) ? ground : floor;
|
||||
|
||||
float step = dist/10.0f;
|
||||
@@ -2444,8 +2444,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 = GetMap()->GetHeight(GetPhases(), destx, desty, MAX_HEIGHT, true);
|
||||
floor = GetMap()->GetHeight(GetPhases(), destx, desty, pos.m_positionZ, true);
|
||||
destz = std::fabs(ground - pos.m_positionZ) <= std::fabs(floor - pos.m_positionZ) ? ground : floor;
|
||||
}
|
||||
// we have correct destz now
|
||||
@@ -2465,8 +2465,8 @@ void WorldObject::MovePosition(Position &pos, float dist, float angle)
|
||||
// @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 ground = obj->GetMap()->GetHeight(obj->GetPhases(), x, y, MAX_HEIGHT, true);
|
||||
float floor = obj->GetMap()->GetHeight(obj->GetPhases(), 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
|
||||
{
|
||||
@@ -2515,7 +2515,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(GetPhases(), 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)
|
||||
@@ -2692,22 +2692,27 @@ void WorldObject::ClearPhases(bool update)
|
||||
UpdateObjectVisibility();
|
||||
}
|
||||
|
||||
bool WorldObject::IsInPhase(WorldObject const* obj) const
|
||||
bool WorldObject::IsInPhase(std::set<uint32> const& phases) const
|
||||
{
|
||||
// PhaseId 169 is the default fallback phase
|
||||
if (_phases.empty() && obj->GetPhases().empty())
|
||||
if (_phases.empty() && phases.empty())
|
||||
return true;
|
||||
|
||||
if (_phases.empty() && obj->IsInPhase(DEFAULT_PHASE))
|
||||
if (_phases.empty() && phases.count(DEFAULT_PHASE) > 0)
|
||||
return true;
|
||||
|
||||
if (obj->GetPhases().empty() && IsInPhase(DEFAULT_PHASE))
|
||||
if (phases.empty() && _phases.count(DEFAULT_PHASE) > 0)
|
||||
return true;
|
||||
|
||||
return Trinity::Containers::Intersects(_phases.begin(), _phases.end(), phases.begin(), phases.end());
|
||||
}
|
||||
|
||||
bool WorldObject::IsInPhase(WorldObject const* obj) const
|
||||
{
|
||||
if (GetTypeId() == TYPEID_PLAYER && ToPlayer()->IsGameMaster())
|
||||
return true;
|
||||
|
||||
return Trinity::Containers::Intersects(_phases.begin(), _phases.end(), obj->GetPhases().begin(), obj->GetPhases().end());
|
||||
return IsInPhase(obj->GetPhases());
|
||||
}
|
||||
|
||||
void WorldObject::PlayDistanceSound(uint32 sound_id, Player* target /*= NULL*/)
|
||||
|
||||
Reference in new issue
Block a user