fix(Core/Maps): Include collision height in underwater status calculations. (#4855)
This commit is contained in:
@@ -3041,7 +3041,7 @@ bool Player::IsInWater(bool allowAbove) const
|
|||||||
bool Player::IsUnderWater() const
|
bool Player::IsUnderWater() const
|
||||||
{
|
{
|
||||||
return IsInWater() &&
|
return IsInWater() &&
|
||||||
GetPositionZ() < (GetBaseMap()->GetWaterLevel(GetPositionX(), GetPositionY()) - 2);
|
GetPositionZ() < GetBaseMap()->GetWaterLevel(GetPositionX(), GetPositionY()) - GetCollisionHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Player::IsFalling() const
|
bool Player::IsFalling() const
|
||||||
@@ -24769,13 +24769,14 @@ void Player::UpdateUnderwaterState(Map* m, float x, float y, float z)
|
|||||||
// pussywizard: optimization
|
// pussywizard: optimization
|
||||||
if (GetExactDistSq(&m_last_underwaterstate_position) < 3.0f * 3.0f)
|
if (GetExactDistSq(&m_last_underwaterstate_position) < 3.0f * 3.0f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_last_underwaterstate_position.Relocate(m_positionX, m_positionY, m_positionZ);
|
m_last_underwaterstate_position.Relocate(m_positionX, m_positionY, m_positionZ);
|
||||||
|
|
||||||
if (!IsPositionValid()) // pussywizard: crashfix if calculated grid coords would be out of range 0-64
|
if (!IsPositionValid()) // pussywizard: crashfix if calculated grid coords would be out of range 0-64
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LiquidData liquid_status;
|
LiquidData liquid_status;
|
||||||
ZLiquidStatus res = m->getLiquidStatus(x, y, z, MAP_ALL_LIQUIDS, &liquid_status);
|
ZLiquidStatus res = m->getLiquidStatus(x, y, z, MAP_ALL_LIQUIDS, &liquid_status, GetCollisionHeight());
|
||||||
if (!res)
|
if (!res)
|
||||||
{
|
{
|
||||||
m_MirrorTimerFlags &= ~(UNDERWATER_INWATER | UNDERWATER_INLAVA | UNDERWATER_INSLIME | UNDERWARER_INDARKWATER);
|
m_MirrorTimerFlags &= ~(UNDERWATER_INWATER | UNDERWATER_INLAVA | UNDERWATER_INSLIME | UNDERWARER_INDARKWATER);
|
||||||
|
|||||||
@@ -1802,7 +1802,7 @@ uint8 GridMap::getTerrainType(float x, float y) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get water state on map
|
// Get water state on map
|
||||||
inline ZLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData* data)
|
inline ZLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, float collisionHeight, LiquidData* data)
|
||||||
{
|
{
|
||||||
// Check water type (if no water return)
|
// Check water type (if no water return)
|
||||||
if (!_liquidType && !_liquidFlags)
|
if (!_liquidType && !_liquidFlags)
|
||||||
@@ -1887,11 +1887,11 @@ inline ZLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 R
|
|||||||
// For speed check as int values
|
// For speed check as int values
|
||||||
float delta = liquid_level - z;
|
float delta = liquid_level - z;
|
||||||
|
|
||||||
if (delta > 2.0f) // Under water
|
if (delta > collisionHeight) // Under water
|
||||||
return LIQUID_MAP_UNDER_WATER;
|
return LIQUID_MAP_UNDER_WATER;
|
||||||
if (delta > 0.0f) // In water
|
if (delta > 0.0f) // In water
|
||||||
return LIQUID_MAP_IN_WATER;
|
return LIQUID_MAP_IN_WATER;
|
||||||
if (delta > -0.1f) // Walk on water
|
if (delta > -0.1f) // Walk on water
|
||||||
return LIQUID_MAP_WATER_WALK;
|
return LIQUID_MAP_WATER_WALK;
|
||||||
// Above water
|
// Above water
|
||||||
return LIQUID_MAP_ABOVE_WATER;
|
return LIQUID_MAP_ABOVE_WATER;
|
||||||
@@ -2218,7 +2218,7 @@ ZLiquidStatus Map::getLiquidStatus(float x, float y, float z, uint8 ReqLiquidTyp
|
|||||||
if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(x, y))
|
if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(x, y))
|
||||||
{
|
{
|
||||||
LiquidData map_data;
|
LiquidData map_data;
|
||||||
ZLiquidStatus map_result = gmap->getLiquidStatus(x, y, z, ReqLiquidType, &map_data);
|
ZLiquidStatus map_result = gmap->getLiquidStatus(x, y, z, ReqLiquidType, collisionHeight, &map_data);
|
||||||
// Not override LIQUID_MAP_ABOVE_WATER with LIQUID_MAP_NO_WATER:
|
// Not override LIQUID_MAP_ABOVE_WATER with LIQUID_MAP_NO_WATER:
|
||||||
if (map_result != LIQUID_MAP_NO_WATER && (map_data.level > ground_level))
|
if (map_result != LIQUID_MAP_NO_WATER && (map_data.level > ground_level))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ public:
|
|||||||
[[nodiscard]] float getMinHeight(float x, float y) const;
|
[[nodiscard]] float getMinHeight(float x, float y) const;
|
||||||
[[nodiscard]] float getLiquidLevel(float x, float y) const;
|
[[nodiscard]] float getLiquidLevel(float x, float y) const;
|
||||||
[[nodiscard]] uint8 getTerrainType(float x, float y) const;
|
[[nodiscard]] uint8 getTerrainType(float x, float y) const;
|
||||||
ZLiquidStatus getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData* data = nullptr);
|
ZLiquidStatus getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, float collisionHeight, LiquidData* data = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
// GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push, N), also any gcc version not support it at some platform
|
// GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push, N), also any gcc version not support it at some platform
|
||||||
|
|||||||
Reference in New Issue
Block a user