Skip to content

Commit

Permalink
Core/Maps: Parse MFBO adt chunk to properly handle height where playe…
Browse files Browse the repository at this point in the history
…r counts as falling under the map

* This fixes the height at which player is instantly killed when falling from The Frozen Throne
* Set PLAYER_FLAGS_IS_OUT_OF_BOUNDS on players under the map to enable release spirit button while still falling

Note: Extracting new maps is required
(cherry picked from commit 4f78efd)

# Conflicts:
#	dep/PackageList.txt
#	src/server/game/DataStores/DBCStructure.h
#	src/server/game/Entities/Player/Player.cpp
#	src/server/game/Handlers/MovementHandler.cpp
#	src/tools/map_extractor/CMakeLists.txt
#	src/tools/map_extractor/System.cpp
#	src/tools/map_extractor/adt.h
#	src/tools/map_extractor/loadlib.cpp
  • Loading branch information
Shauren committed Feb 9, 2016
1 parent aa432db commit 25cdc5d
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 41 deletions.
7 changes: 5 additions & 2 deletions src/server/game/Entities/Player/Player.cpp
Expand Up @@ -4682,6 +4682,7 @@ void Player::ResurrectPlayer(float restore_percent, bool applySickness)

// remove death flag + set aura
SetByteValue(UNIT_FIELD_BYTES_1, 3, 0x00);
RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_IS_OUT_OF_BOUNDS);

// This must be called always even on Players with race != RACE_NIGHTELF in case of faction change
RemoveAurasDueToSpell(20584); // RACE_NIGHTELF speed bonuses
Expand Down Expand Up @@ -5105,7 +5106,7 @@ void Player::RepopAtGraveyard()
AreaTableEntry const* zone = sAreaTableStore.LookupEntry(GetAreaId());

// Such zones are considered unreachable as a ghost and the player must be automatically revived
if ((!IsAlive() && zone && zone->flags & AREA_FLAG_NEED_FLY) || GetTransport() || GetPositionZ() < -500.0f)
if ((!IsAlive() && zone && zone->flags & AREA_FLAG_NEED_FLY) || GetTransport() || GetPositionZ() < GetMap()->GetMinHeight(GetPositionX(), GetPositionY()))
{
ResurrectPlayer(0.5f);
SpawnCorpseBones();
Expand Down Expand Up @@ -5142,8 +5143,10 @@ void Player::RepopAtGraveyard()
GetSession()->SendPacket(&data);
}
}
else if (GetPositionZ() < -500.0f)
else if (GetPositionZ() < GetMap()->GetMinHeight(GetPositionX(), GetPositionY()))
TeleportTo(m_homebindMapId, m_homebindX, m_homebindY, m_homebindZ, GetOrientation());

RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_IS_OUT_OF_BOUNDS);
}

bool Player::CanJoinConstantChannelInZone(ChatChannelsEntry const* channel, AreaTableEntry const* zone)
Expand Down
3 changes: 2 additions & 1 deletion src/server/game/Handlers/MovementHandler.cpp
Expand Up @@ -386,7 +386,7 @@ void WorldSession::HandleMovementOpcodes(WorldPacket& recvData)

plrMover->UpdateFallInformationIfNeed(movementInfo, opcode);

if (movementInfo.pos.GetPositionZ() < -500.0f)
if (movementInfo.pos.GetPositionZ() < plrMover->GetMap()->GetMinHeight(movementInfo.pos.GetPositionX(), movementInfo.pos.GetPositionY()))
{
if (!(plrMover->GetBattleground() && plrMover->GetBattleground()->HandlePlayerUnderMap(_player)))
{
Expand All @@ -395,6 +395,7 @@ void WorldSession::HandleMovementOpcodes(WorldPacket& recvData)
/// @todo discard movement packets after the player is rooted
if (plrMover->IsAlive())
{
plrMover->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_IS_OUT_OF_BOUNDS);
plrMover->EnvironmentalDamage(DAMAGE_FALL_TO_VOID, GetPlayer()->GetMaxHealth());
// player can be alive if GM/etc
// change the death state to CORPSE to prevent the death timer from
Expand Down
62 changes: 49 additions & 13 deletions src/server/game/Maps/Map.cpp
Expand Up @@ -37,7 +37,7 @@
#include "VMapFactory.h"

u_map_magic MapMagic = { {'M','A','P','S'} };
u_map_magic MapVersionMagic = { {'v','1','.','6'} };
u_map_magic MapVersionMagic = { {'v','1','.','7'} };
u_map_magic MapAreaMagic = { {'A','R','E','A'} };
u_map_magic MapHeightMagic = { {'M','H','G','T'} };
u_map_magic MapLiquidMagic = { {'M','L','I','Q'} };
Expand Down Expand Up @@ -1644,23 +1644,25 @@ GridMap::GridMap()
_flags = 0;
// Area data
_gridArea = 0;
_areaMap = NULL;
_areaMap = nullptr;
// Height level data
_gridHeight = INVALID_HEIGHT;
_gridGetHeight = &GridMap::getHeightFromFlat;
_gridIntHeightMultiplier = 0;
m_V9 = NULL;
m_V8 = NULL;
m_V9 = nullptr;
m_V8 = nullptr;
_maxHeight = nullptr;
_minHeight = nullptr;
// Liquid data
_liquidType = 0;
_liquidOffX = 0;
_liquidOffY = 0;
_liquidWidth = 0;
_liquidHeight = 0;
_liquidLevel = INVALID_HEIGHT;
_liquidEntry = NULL;
_liquidFlags = NULL;
_liquidMap = NULL;
_liquidEntry = nullptr;
_liquidFlags = nullptr;
_liquidMap = nullptr;
}

GridMap::~GridMap()
Expand Down Expand Up @@ -1723,15 +1725,19 @@ void GridMap::unloadData()
delete[] _areaMap;
delete[] m_V9;
delete[] m_V8;
delete[] _maxHeight;
delete[] _minHeight;
delete[] _liquidEntry;
delete[] _liquidFlags;
delete[] _liquidMap;
_areaMap = NULL;
m_V9 = NULL;
m_V8 = NULL;
_liquidEntry = NULL;
_liquidFlags = NULL;
_liquidMap = NULL;
_areaMap = nullptr;
m_V9 = nullptr;
m_V8 = nullptr;
_maxHeight = nullptr;
_minHeight = nullptr;
_liquidEntry = nullptr;
_liquidFlags = nullptr;
_liquidMap = nullptr;
_gridGetHeight = &GridMap::getHeightFromFlat;
}

Expand Down Expand Up @@ -1796,6 +1802,16 @@ bool GridMap::loadHeightData(FILE* in, uint32 offset, uint32 /*size*/)
}
else
_gridGetHeight = &GridMap::getHeightFromFlat;

if (header.flags & MAP_HEIGHT_HAS_FLIGHT_BOUNDS)
{
_maxHeight = new float[16 * 16];
_minHeight = new float[16 * 16];
if (fread(_maxHeight, sizeof(float), 16 * 16, in) != 16 * 16 ||
fread(_minHeight, sizeof(float), 16 * 16, in) != 16 * 16)
return false;
}

return true;
}

Expand Down Expand Up @@ -2066,6 +2082,18 @@ float GridMap::getHeightFromUint16(float x, float y) const
return (float)((a * x) + (b * y) + c)*_gridIntHeightMultiplier + _gridHeight;
}

float GridMap::getMinHeight(float x, float y) const
{
if (!_minHeight)
return -500.0f;

x = 16 * (CENTER_GRID_ID - x / SIZE_OF_GRIDS);
y = 16 * (CENTER_GRID_ID - y / SIZE_OF_GRIDS);
int lx = (int)x & 15;
int ly = (int)y & 15;
return _minHeight[lx * 16 + ly];
}

float GridMap::getLiquidLevel(float x, float y) const
{
if (!_liquidMap)
Expand Down Expand Up @@ -2266,6 +2294,14 @@ float Map::GetHeight(float x, float y, float z, bool checkVMap /*= true*/, float
return mapHeight; // explicitly use map data
}

float Map::GetMinHeight(float x, float y) const
{
if (GridMap const* grid = const_cast<Map*>(this)->GetGrid(x, y))
return grid->getMinHeight(x, y);

return -500.0f;
}

inline bool IsOutdoorWMO(uint32 mogpFlags, int32 /*adtId*/, int32 /*rootId*/, int32 /*groupId*/, WMOAreaTableEntry const* wmoEntry, AreaTableEntry const* atEntry)
{
bool outdoor = true;
Expand Down
11 changes: 8 additions & 3 deletions src/server/game/Maps/Map.h
Expand Up @@ -98,9 +98,10 @@ struct map_areaHeader
uint16 gridArea;
};

#define MAP_HEIGHT_NO_HEIGHT 0x0001
#define MAP_HEIGHT_AS_INT16 0x0002
#define MAP_HEIGHT_AS_INT8 0x0004
#define MAP_HEIGHT_NO_HEIGHT 0x0001
#define MAP_HEIGHT_AS_INT16 0x0002
#define MAP_HEIGHT_AS_INT8 0x0004
#define MAP_HEIGHT_HAS_FLIGHT_BOUNDS 0x0008

struct map_heightHeader
{
Expand Down Expand Up @@ -166,6 +167,8 @@ class GridMap
uint16* m_uint16_V8;
uint8* m_uint8_V8;
};
float* _maxHeight;
float* _minHeight;
// Height level data
float _gridHeight;
float _gridIntHeightMultiplier;
Expand Down Expand Up @@ -206,6 +209,7 @@ class GridMap

uint16 getArea(float x, float y) const;
inline float getHeight(float x, float y) const {return (this->*_gridGetHeight)(x, y);}
float getMinHeight(float x, float y) const;
float getLiquidLevel(float x, float y) const;
uint8 getTerrainType(float x, float y) const;
ZLiquidStatus getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData* data = 0);
Expand Down Expand Up @@ -326,6 +330,7 @@ class Map : public GridRefManager<NGridType>
// some calls like isInWater should not use vmaps due to processor power
// can return INVALID_HEIGHT if under z+2 z coord not found height
float GetHeight(float x, float y, float z, bool checkVMap = true, float maxSearchDist = DEFAULT_HEIGHT_SEARCH) const;
float GetMinHeight(float x, float y) const;

ZLiquidStatus getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData* data = nullptr) const;

Expand Down
2 changes: 2 additions & 0 deletions src/tools/map_extractor/CMakeLists.txt
Expand Up @@ -14,6 +14,7 @@ file(GLOB_RECURSE mapextractor_SRCS *.cpp *.h)
set(include_Dirs
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/dep/cppformat
${CMAKE_SOURCE_DIR}/dep/g3dlite/include
${CMAKE_SOURCE_DIR}/dep/libmpq
${CMAKE_SOURCE_DIR}/src/common
${CMAKE_SOURCE_DIR}/src/common/Utilities
Expand All @@ -37,6 +38,7 @@ add_executable(mapextractor
target_link_libraries(mapextractor
common
format
g3dlib
mpq
${BZIP2_LIBRARIES}
${ZLIB_LIBRARIES}
Expand Down
101 changes: 97 additions & 4 deletions src/tools/map_extractor/System.cpp
Expand Up @@ -31,6 +31,7 @@
#include "adt.h"
#include "wdt.h"

#include <G3D/Plane.h>
#include <boost/filesystem.hpp>

extern ArchiveSet gOpenArchives;
Expand Down Expand Up @@ -256,7 +257,7 @@ void ReadLiquidTypeTableDBC()

// Map file format data
static char const* MAP_MAGIC = "MAPS";
static char const* MAP_VERSION_MAGIC = "v1.6";
static char const* MAP_VERSION_MAGIC = "v1.7";
static char const* MAP_AREA_MAGIC = "AREA";
static char const* MAP_HEIGHT_MAGIC = "MHGT";
static char const* MAP_LIQUID_MAGIC = "MLIQ";
Expand Down Expand Up @@ -285,9 +286,10 @@ struct map_areaHeader
uint16 gridArea;
};

#define MAP_HEIGHT_NO_HEIGHT 0x0001
#define MAP_HEIGHT_AS_INT16 0x0002
#define MAP_HEIGHT_AS_INT8 0x0004
#define MAP_HEIGHT_NO_HEIGHT 0x0001
#define MAP_HEIGHT_AS_INT16 0x0002
#define MAP_HEIGHT_AS_INT8 0x0004
#define MAP_HEIGHT_HAS_FLIGHT_BOUNDS 0x0008

struct map_heightHeader
{
Expand Down Expand Up @@ -346,6 +348,9 @@ uint8 liquid_flags[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
bool liquid_show[ADT_GRID_SIZE][ADT_GRID_SIZE];
float liquid_height[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1];

float flight_box_max[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
float flight_box_min[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];

bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int /*cell_y*/, int /*cell_x*/, uint32 build)
{
ADT_file adt;
Expand Down Expand Up @@ -521,6 +526,82 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
maxHeight = CONF_use_minHeight;
}

bool hasFlightBox = false;
if (adt_MFBO* mfbo = adt.a_grid->getMFBO())
{
static uint32 const indices[] =
{
3, 0, 4,
0, 1, 4,
1, 2, 4,
2, 5, 4,
5, 8, 4,
8, 7, 4,
7, 6, 4,
6, 3, 4
};

static float const boundGridCoords[] =
{
0.0f, 0.0f,
0.0f, -266.66666f,
0.0f, -533.33331f,
-266.66666f, 0.0f,
-266.66666f, -266.66666f,
-266.66666f, -533.33331f,
-533.33331f, 0.0f,
-533.33331f, -266.66666f,
-533.33331f, -533.33331f
};

for (int gy = 0; gy < ADT_CELLS_PER_GRID; ++gy)
{
for (int gx = 0; gx < ADT_CELLS_PER_GRID; ++gx)
{
int32 quarterIndex = 0;
if (gy > ADT_CELLS_PER_GRID / 2)
{
if (gx > ADT_CELLS_PER_GRID / 2)
{
quarterIndex = 4 + gx < gy;
}
else
quarterIndex = 2;
}
else if (gx > ADT_CELLS_PER_GRID / 2)
{
quarterIndex = 7;
}
else
quarterIndex = gx > gy;

quarterIndex *= 3;
G3D::Plane planeMax(
G3D::Vector3(boundGridCoords[indices[quarterIndex + 0] * 2 + 0], boundGridCoords[indices[quarterIndex + 0] * 2 + 1], mfbo->max.coords[indices[quarterIndex + 0]]),
G3D::Vector3(boundGridCoords[indices[quarterIndex + 1] * 2 + 0], boundGridCoords[indices[quarterIndex + 1] * 2 + 1], mfbo->max.coords[indices[quarterIndex + 1]]),
G3D::Vector3(boundGridCoords[indices[quarterIndex + 2] * 2 + 0], boundGridCoords[indices[quarterIndex + 2] * 2 + 1], mfbo->max.coords[indices[quarterIndex + 2]])
);

G3D::Plane planeMin(
G3D::Vector3(boundGridCoords[indices[quarterIndex + 0] * 2 + 0], boundGridCoords[indices[quarterIndex + 0] * 2 + 1], mfbo->min.coords[indices[quarterIndex + 0]]),
G3D::Vector3(boundGridCoords[indices[quarterIndex + 1] * 2 + 0], boundGridCoords[indices[quarterIndex + 1] * 2 + 1], mfbo->min.coords[indices[quarterIndex + 1]]),
G3D::Vector3(boundGridCoords[indices[quarterIndex + 2] * 2 + 0], boundGridCoords[indices[quarterIndex + 2] * 2 + 1], mfbo->min.coords[indices[quarterIndex + 2]])
);

auto non_nan_distance = [](G3D::Plane const& plane) {
auto d = plane.distance(G3D::Vector3(0.0f, 0.0f, 0.0f));
assert(!G3D::isNaN(d));
return d;
};

flight_box_max[gy][gx] = non_nan_distance(planeMax);
flight_box_min[gy][gx] = non_nan_distance(planeMin);
}
}

hasFlightBox = true;
}

map.heightMapOffset = map.areaMapOffset + map.areaMapSize;
map.heightMapSize = sizeof(map_heightHeader);

Expand All @@ -537,6 +618,12 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
if (CONF_allow_float_to_int && (maxHeight - minHeight) < CONF_flat_height_delta_limit)
heightHeader.flags |= MAP_HEIGHT_NO_HEIGHT;

if (hasFlightBox)
{
heightHeader.flags |= MAP_HEIGHT_HAS_FLIGHT_BOUNDS;
map.heightMapSize += sizeof(flight_box_max) + sizeof(flight_box_min);
}

// Try store as packed in uint16 or uint8 values
if (!(heightHeader.flags & MAP_HEIGHT_NO_HEIGHT))
{
Expand Down Expand Up @@ -859,6 +946,12 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int
}
}

if (heightHeader.flags & MAP_HEIGHT_HAS_FLIGHT_BOUNDS)
{
outFile.write(reinterpret_cast<char*>(flight_box_max), sizeof(flight_box_max));
outFile.write(reinterpret_cast<char*>(flight_box_min), sizeof(flight_box_min));
}

// Store liquid data if need
if (map.liquidMapOffset)
{
Expand Down

0 comments on commit 25cdc5d

Please sign in to comment.