Skip to content

Commit f507a6f

Browse files
OvahlordXenphis
authored andcommitted
Core/Maps: implement LIQUID_MAP_OCEAN_FLOOR to identify units that are on the bottom of a liquid (#29545)
1 parent 1d353b6 commit f507a6f

5 files changed

Lines changed: 48 additions & 19 deletions

File tree

src/common/Collision/Maps/MapDefines.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ enum ZLiquidStatus : uint32
128128
LIQUID_MAP_WATER_WALK = 0x00000002,
129129
LIQUID_MAP_IN_WATER = 0x00000004,
130130
LIQUID_MAP_UNDER_WATER = 0x00000008,
131+
LIQUID_MAP_OCEAN_FLOOR = 0x00000010
131132
};
132133

133134
#define MAP_LIQUID_STATUS_SWIMMING (LIQUID_MAP_IN_WATER | LIQUID_MAP_UNDER_WATER)

src/server/game/Entities/Unit/Unit.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3193,6 +3193,11 @@ bool Unit::IsUnderWater() const
31933193
return GetLiquidStatus() & LIQUID_MAP_UNDER_WATER;
31943194
}
31953195

3196+
bool Unit::IsOnOceanFloor() const
3197+
{
3198+
return GetLiquidStatus() & LIQUID_MAP_OCEAN_FLOOR;
3199+
}
3200+
31963201
void Unit::ProcessPositionDataChanged(PositionFullTerrainStatus const& data)
31973202
{
31983203
ZLiquidStatus oldLiquidStatus = GetLiquidStatus();

src/server/game/Entities/Unit/Unit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,7 @@ class TC_GAME_API Unit : public WorldObject
11881188

11891189
bool IsInWater() const;
11901190
bool IsUnderWater() const;
1191+
bool IsOnOceanFloor() const;
11911192
bool isInAccessiblePlaceFor(Creature const* c) const;
11921193

11931194
void SendHealSpellLog(HealInfo& healInfo, bool critical = false);

src/server/game/Maps/GridMap.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -679,12 +679,18 @@ ZLiquidStatus GridMap::GetLiquidStatus(float x, float y, float z, Optional<map_l
679679
// For speed check as int values
680680
float delta = liquid_level - z;
681681

682-
if (delta > collisionHeight) // Under water
683-
return LIQUID_MAP_UNDER_WATER;
684-
if (delta > 0.0f) // In water
685-
return LIQUID_MAP_IN_WATER;
686-
if (delta > -0.1f) // Walk on water
687-
return LIQUID_MAP_WATER_WALK;
688-
// Above water
689-
return LIQUID_MAP_ABOVE_WATER;
682+
uint32 status = LIQUID_MAP_ABOVE_WATER; // Above water
683+
684+
if (delta > collisionHeight) // Under water
685+
status = LIQUID_MAP_UNDER_WATER;
686+
else if (delta > 0.0f) // In water
687+
status = LIQUID_MAP_IN_WATER;
688+
else if (delta > -0.1f) // Walk on water
689+
status = LIQUID_MAP_WATER_WALK;
690+
691+
if (status != LIQUID_MAP_ABOVE_WATER)
692+
if (std::fabs(ground_level - z) <= GROUND_HEIGHT_TOLERANCE)
693+
status |= LIQUID_MAP_OCEAN_FLOOR;
694+
695+
return static_cast<ZLiquidStatus>(status);
690696
}

src/server/game/Maps/TerrainMgr.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,19 @@ void TerrainInfo::GetFullTerrainStatusForPosition(uint32 phaseMask, float x, flo
355355
data.liquidInfo->type_flags = map_liquidHeaderTypeFlags(1 << liquidFlagType);
356356

357357
float delta = wmoData->liquidInfo->level - z;
358+
uint32 status = LIQUID_MAP_ABOVE_WATER;
358359
if (delta > collisionHeight)
359-
data.liquidStatus = LIQUID_MAP_UNDER_WATER;
360+
status = LIQUID_MAP_UNDER_WATER;
360361
else if (delta > 0.0f)
361-
data.liquidStatus = LIQUID_MAP_IN_WATER;
362+
status = LIQUID_MAP_IN_WATER;
362363
else if (delta > -0.1f)
363-
data.liquidStatus = LIQUID_MAP_WATER_WALK;
364-
else
365-
data.liquidStatus = LIQUID_MAP_ABOVE_WATER;
364+
status = LIQUID_MAP_WATER_WALK;
365+
366+
if (status != LIQUID_MAP_ABOVE_WATER)
367+
if (std::fabs(wmoData->floorZ - z) <= GROUND_HEIGHT_TOLERANCE)
368+
status |= LIQUID_MAP_OCEAN_FLOOR;
369+
370+
data.liquidStatus = static_cast<ZLiquidStatus>(status);
366371
}
367372
// look up liquid data from grid map
368373
if (gmap && useGridLiquid)
@@ -433,12 +438,23 @@ ZLiquidStatus TerrainInfo::GetLiquidStatus(uint32 phaseMask, float x, float y, f
433438
float delta = vmapData.liquidInfo->level - z;
434439

435440
// Get position delta
436-
if (delta > collisionHeight) // Under water
437-
return LIQUID_MAP_UNDER_WATER;
438-
if (delta > 0.0f) // In water
439-
return LIQUID_MAP_IN_WATER;
440-
if (delta > -0.1f) // Walk on water
441-
return LIQUID_MAP_WATER_WALK;
441+
uint32 status = LIQUID_MAP_ABOVE_WATER;
442+
if (delta > collisionHeight) // Under water
443+
status = LIQUID_MAP_UNDER_WATER;
444+
else if (delta > 0.0f) // In water
445+
status = LIQUID_MAP_IN_WATER;
446+
else if (delta > -0.1f) // Walk on water
447+
status = LIQUID_MAP_WATER_WALK;
448+
449+
if (status != LIQUID_MAP_ABOVE_WATER)
450+
{
451+
if (status != LIQUID_MAP_ABOVE_WATER)
452+
if (std::fabs(ground_level - z) <= GROUND_HEIGHT_TOLERANCE)
453+
status |= LIQUID_MAP_OCEAN_FLOOR;
454+
455+
return static_cast<ZLiquidStatus>(status);
456+
}
457+
442458
result = LIQUID_MAP_ABOVE_WATER;
443459
}
444460
}

0 commit comments

Comments
 (0)