aboutsummaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2021-05-29 21:21:37 +0200
committerShauren <shauren.trinity@gmail.com>2021-05-29 21:21:37 +0200
commit6ecfe58cae6d9cfa7a3aef21a4a96aa00c513ba2 (patch)
treeff96897b193f6f78ad00fdf4100631705c2f010d /src/tools
parent2de6e56d29df8cebb358e10e5e452422588a3929 (diff)
Core/Maps & Extractors: Move copypasted map file headers into a single shared file and replace #defines with enums
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/map_extractor/System.cpp159
-rw-r--r--src/tools/mmaps_generator/TerrainBuilder.cpp94
-rw-r--r--src/tools/mmaps_generator/TerrainBuilder.h4
3 files changed, 71 insertions, 186 deletions
diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp
index 6876b58a7cc..c419d0bf806 100644
--- a/src/tools/map_extractor/System.cpp
+++ b/src/tools/map_extractor/System.cpp
@@ -22,6 +22,7 @@
#include "DB2Meta.h"
#include "DBFilesClientList.h"
#include "ExtractorDB2LoadInfo.h"
+#include "MapDefines.h"
#include "StringFormat.h"
#include "adt.h"
#include "wdt.h"
@@ -390,74 +391,6 @@ bool ReadCinematicCameraDBC()
// Adt file convertor function and data
//
-// Map file format data
-static char const* MAP_MAGIC = "MAPS";
-static char const* MAP_VERSION_MAGIC = "v1.9";
-static char const* MAP_AREA_MAGIC = "AREA";
-static char const* MAP_HEIGHT_MAGIC = "MHGT";
-static char const* MAP_LIQUID_MAGIC = "MLIQ";
-
-struct map_fileheader
-{
- uint32 mapMagic;
- uint32 versionMagic;
- uint32 buildMagic;
- uint32 areaMapOffset;
- uint32 areaMapSize;
- uint32 heightMapOffset;
- uint32 heightMapSize;
- uint32 liquidMapOffset;
- uint32 liquidMapSize;
- uint32 holesOffset;
- uint32 holesSize;
-};
-
-#define MAP_AREA_NO_AREA 0x0001
-
-struct map_areaHeader
-{
- uint32 fourcc;
- uint16 flags;
- uint16 gridArea;
-};
-
-#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
-{
- uint32 fourcc;
- uint32 flags;
- float gridHeight;
- float gridMaxHeight;
-};
-
-#define MAP_LIQUID_TYPE_NO_WATER 0x00
-#define MAP_LIQUID_TYPE_WATER 0x01
-#define MAP_LIQUID_TYPE_OCEAN 0x02
-#define MAP_LIQUID_TYPE_MAGMA 0x04
-#define MAP_LIQUID_TYPE_SLIME 0x08
-
-#define MAP_LIQUID_TYPE_DARK_WATER 0x10
-
-#define MAP_LIQUID_NO_TYPE 0x0001
-#define MAP_LIQUID_NO_HEIGHT 0x0002
-
-struct map_liquidHeader
-{
- uint32 fourcc;
- uint8 flags;
- uint8 liquidFlags;
- uint16 liquidType;
- uint8 offsetX;
- uint8 offsetY;
- uint8 width;
- uint8 height;
- float liquidLevel;
-};
-
float selectUInt8StepStore(float maxDiff)
{
return 255 / maxDiff;
@@ -478,7 +411,7 @@ uint8 uint8_V8[ADT_GRID_SIZE][ADT_GRID_SIZE];
uint8 uint8_V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1];
uint16 liquid_entry[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
-uint8 liquid_flags[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
+map_liquidHeaderTypeFlags 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];
uint8 holes[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID][8];
@@ -523,9 +456,9 @@ bool TransformToHighRes(uint16 lowResHoles, uint8 hiResHoles[8])
bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const& outputPath, int gx, int gy, uint32 build, bool ignoreDeepWater)
{
// Prepare map header
- map_fileheader map;
- map.mapMagic = *reinterpret_cast<uint32 const*>(MAP_MAGIC);
- map.versionMagic = *reinterpret_cast<uint32 const*>(MAP_VERSION_MAGIC);
+ map_fileheader map{};
+ map.mapMagic = MapMagic;
+ map.versionMagic = MapVersionMagic;
map.buildMagic = build;
// Get area flags data
@@ -630,7 +563,7 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
{
liquid_show[cy][cx] = true;
if (!ignoreDeepWater && liquid->flags[y][x] & (1 << 7))
- liquid_flags[mcnk->iy][mcnk->ix] |= MAP_LIQUID_TYPE_DARK_WATER;
+ liquid_flags[mcnk->iy][mcnk->ix] |= map_liquidHeaderTypeFlags::DarkWater;
++count;
}
}
@@ -640,20 +573,20 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
if (c_flag & (1 << 2))
{
liquid_entry[mcnk->iy][mcnk->ix] = 1;
- liquid_flags[mcnk->iy][mcnk->ix] |= MAP_LIQUID_TYPE_WATER; // water
+ liquid_flags[mcnk->iy][mcnk->ix] |= map_liquidHeaderTypeFlags::Water; // water
}
if (c_flag & (1 << 3))
{
liquid_entry[mcnk->iy][mcnk->ix] = 2;
- liquid_flags[mcnk->iy][mcnk->ix] |= MAP_LIQUID_TYPE_OCEAN; // ocean
+ liquid_flags[mcnk->iy][mcnk->ix] |= map_liquidHeaderTypeFlags::Ocean; // ocean
}
if (c_flag & (1 << 4))
{
liquid_entry[mcnk->iy][mcnk->ix] = 3;
- liquid_flags[mcnk->iy][mcnk->ix] |= MAP_LIQUID_TYPE_MAGMA; // magma/slime
+ liquid_flags[mcnk->iy][mcnk->ix] |= map_liquidHeaderTypeFlags::Magma; // magma/slime
}
- if (!count && liquid_flags[mcnk->iy][mcnk->ix])
+ if (!count && liquid_flags[mcnk->iy][mcnk->ix] != map_liquidHeaderTypeFlags::NoWater)
fprintf(stderr, "Wrong liquid detect in MCLQ chunk");
for (int y = 0; y <= ADT_CELL_SIZE; ++y)
@@ -717,16 +650,16 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
liquid_entry[i][j] = h2o->GetLiquidType(h);
switch (LiquidTypes.at(liquid_entry[i][j]).SoundBank)
{
- case LIQUID_TYPE_WATER: liquid_flags[i][j] |= MAP_LIQUID_TYPE_WATER; break;
- case LIQUID_TYPE_OCEAN: liquid_flags[i][j] |= MAP_LIQUID_TYPE_OCEAN; if (!ignoreDeepWater && attrs.Deep) liquid_flags[i][j] |= MAP_LIQUID_TYPE_DARK_WATER; break;
- case LIQUID_TYPE_MAGMA: liquid_flags[i][j] |= MAP_LIQUID_TYPE_MAGMA; break;
- case LIQUID_TYPE_SLIME: liquid_flags[i][j] |= MAP_LIQUID_TYPE_SLIME; break;
+ case LIQUID_TYPE_WATER: liquid_flags[i][j] |= map_liquidHeaderTypeFlags::Water; break;
+ case LIQUID_TYPE_OCEAN: liquid_flags[i][j] |= map_liquidHeaderTypeFlags::Ocean; if (!ignoreDeepWater && attrs.Deep) liquid_flags[i][j] |= map_liquidHeaderTypeFlags::DarkWater; break;
+ case LIQUID_TYPE_MAGMA: liquid_flags[i][j] |= map_liquidHeaderTypeFlags::Magma; break;
+ case LIQUID_TYPE_SLIME: liquid_flags[i][j] |= map_liquidHeaderTypeFlags::Slime; break;
default:
printf("\nCan't find Liquid type %u for map %s [%u,%u]\nchunk %d,%d\n", h->LiquidType, mapName.c_str(), gx, gy, i, j);
break;
}
- if (!count && liquid_flags[i][j])
+ if (!count && liquid_flags[i][j] != map_liquidHeaderTypeFlags::NoWater)
printf("Wrong liquid detect in MH2O chunk");
int32 pos = 0;
@@ -773,8 +706,8 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
map.areaMapSize = sizeof(map_areaHeader);
map_areaHeader areaHeader;
- areaHeader.fourcc = *reinterpret_cast<uint32 const*>(MAP_AREA_MAGIC);
- areaHeader.flags = 0;
+ areaHeader.areaMagic = MapAreaMagic;
+ areaHeader.flags = map_areaHeaderFlags::None;
if (fullAreaData)
{
areaHeader.gridArea = 0;
@@ -782,7 +715,7 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
}
else
{
- areaHeader.flags |= MAP_AREA_NO_AREA;
+ areaHeader.flags |= map_areaHeaderFlags::NoArea;
areaHeader.gridArea = static_cast<uint16>(areaId);
}
@@ -831,26 +764,26 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
map.heightMapSize = sizeof(map_heightHeader);
map_heightHeader heightHeader;
- heightHeader.fourcc = *reinterpret_cast<uint32 const*>(MAP_HEIGHT_MAGIC);
- heightHeader.flags = 0;
+ heightHeader.heightMagic = MapHeightMagic;
+ heightHeader.flags = map_heightHeaderFlags::None;
heightHeader.gridHeight = minHeight;
heightHeader.gridMaxHeight = maxHeight;
if (maxHeight == minHeight)
- heightHeader.flags |= MAP_HEIGHT_NO_HEIGHT;
+ heightHeader.flags |= map_heightHeaderFlags::NoHeight;
// Not need store if flat surface
if (CONF_allow_float_to_int && (maxHeight - minHeight) < CONF_flat_height_delta_limit)
- heightHeader.flags |= MAP_HEIGHT_NO_HEIGHT;
+ heightHeader.flags |= map_heightHeaderFlags::NoHeight;
if (hasFlightBox)
{
- heightHeader.flags |= MAP_HEIGHT_HAS_FLIGHT_BOUNDS;
+ heightHeader.flags |= map_heightHeaderFlags::HasFlightBounds;
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))
+ if (!heightHeader.flags.HasFlag(map_heightHeaderFlags::NoHeight))
{
float step = 0;
// Try Store as uint values
@@ -859,18 +792,18 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
float diff = maxHeight - minHeight;
if (diff < CONF_float_to_int8_limit) // As uint8 (max accuracy = CONF_float_to_int8_limit/256)
{
- heightHeader.flags |= MAP_HEIGHT_AS_INT8;
+ heightHeader.flags |= map_heightHeaderFlags::HeightAsInt8;
step = selectUInt8StepStore(diff);
}
else if (diff < CONF_float_to_int16_limit) // As uint16 (max accuracy = CONF_float_to_int16_limit/65536)
{
- heightHeader.flags |= MAP_HEIGHT_AS_INT16;
+ heightHeader.flags |= map_heightHeaderFlags::HeightAsInt16;
step = selectUInt16StepStore(diff);
}
}
// Pack it to int values if need
- if (heightHeader.flags&MAP_HEIGHT_AS_INT8)
+ if (heightHeader.flags.HasFlag(map_heightHeaderFlags::HeightAsInt8))
{
for (int y=0; y<ADT_GRID_SIZE; y++)
for(int x=0;x<ADT_GRID_SIZE;x++)
@@ -880,7 +813,7 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
uint8_V9[y][x] = uint8((V9[y][x] - minHeight) * step + 0.5f);
map.heightMapSize+= sizeof(uint8_V9) + sizeof(uint8_V8);
}
- else if (heightHeader.flags&MAP_HEIGHT_AS_INT16)
+ else if (heightHeader.flags.HasFlag(map_heightHeaderFlags::HeightAsInt16))
{
for (int y=0; y<ADT_GRID_SIZE; y++)
for(int x=0;x<ADT_GRID_SIZE;x++)
@@ -898,7 +831,7 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
// Pack liquid data
//============================================
uint16 firstLiquidType = liquid_entry[0][0];
- uint8 firstLiquidFlag = liquid_flags[0][0];
+ map_liquidHeaderTypeFlags firstLiquidFlag = liquid_flags[0][0];
bool fullType = false;
for (int y = 0; y < ADT_CELLS_PER_GRID; y++)
{
@@ -916,7 +849,7 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
map_liquidHeader liquidHeader;
// no water data (if all grid have 0 liquid type)
- if (firstLiquidFlag == 0 && !fullType)
+ if (firstLiquidFlag == map_liquidHeaderTypeFlags::NoWater && !fullType)
{
// No liquid data
map.liquidMapOffset = 0;
@@ -948,8 +881,8 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
}
map.liquidMapOffset = map.heightMapOffset + map.heightMapSize;
map.liquidMapSize = sizeof(map_liquidHeader);
- liquidHeader.fourcc = *reinterpret_cast<uint32 const*>(MAP_LIQUID_MAGIC);
- liquidHeader.flags = 0;
+ liquidHeader.liquidMagic = MapLiquidMagic;
+ liquidHeader.flags = map_liquidHeaderFlags::None;
liquidHeader.liquidType = 0;
liquidHeader.offsetX = minX;
liquidHeader.offsetY = minY;
@@ -958,16 +891,16 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
liquidHeader.liquidLevel = minHeight;
if (maxHeight == minHeight)
- liquidHeader.flags |= MAP_LIQUID_NO_HEIGHT;
+ liquidHeader.flags |= map_liquidHeaderFlags::NoHeight;
// Not need store if flat surface
if (CONF_allow_float_to_int && (maxHeight - minHeight) < CONF_flat_liquid_delta_limit)
- liquidHeader.flags |= MAP_LIQUID_NO_HEIGHT;
+ liquidHeader.flags |= map_liquidHeaderFlags::NoHeight;
if (!fullType)
- liquidHeader.flags |= MAP_LIQUID_NO_TYPE;
+ liquidHeader.flags |= map_liquidHeaderFlags::NoType;
- if (liquidHeader.flags & MAP_LIQUID_NO_TYPE)
+ if (liquidHeader.flags.HasFlag(map_liquidHeaderFlags::NoType))
{
liquidHeader.liquidFlags = firstLiquidFlag;
liquidHeader.liquidType = firstLiquidType;
@@ -975,7 +908,7 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
else
map.liquidMapSize += sizeof(liquid_entry) + sizeof(liquid_flags);
- if (!(liquidHeader.flags & MAP_LIQUID_NO_HEIGHT))
+ if (!liquidHeader.flags.HasFlag(map_liquidHeaderFlags::NoHeight))
map.liquidMapSize += sizeof(float)*liquidHeader.width*liquidHeader.height;
}
@@ -1005,19 +938,19 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
outFile.write(reinterpret_cast<char const*>(&map), sizeof(map));
// Store area data
outFile.write(reinterpret_cast<char const*>(&areaHeader), sizeof(areaHeader));
- if (!(areaHeader.flags & MAP_AREA_NO_AREA))
+ if (!areaHeader.flags.HasFlag(map_areaHeaderFlags::NoArea))
outFile.write(reinterpret_cast<char const*>(area_ids), sizeof(area_ids));
// Store height data
outFile.write(reinterpret_cast<char const*>(&heightHeader), sizeof(heightHeader));
- if (!(heightHeader.flags & MAP_HEIGHT_NO_HEIGHT))
+ if (!heightHeader.flags.HasFlag(map_heightHeaderFlags::NoHeight))
{
- if (heightHeader.flags & MAP_HEIGHT_AS_INT16)
+ if (heightHeader.flags.HasFlag(map_heightHeaderFlags::HeightAsInt16))
{
outFile.write(reinterpret_cast<char const*>(uint16_V9), sizeof(uint16_V9));
outFile.write(reinterpret_cast<char const*>(uint16_V8), sizeof(uint16_V8));
}
- else if (heightHeader.flags & MAP_HEIGHT_AS_INT8)
+ else if (heightHeader.flags.HasFlag(map_heightHeaderFlags::HeightAsInt8))
{
outFile.write(reinterpret_cast<char const*>(uint8_V9), sizeof(uint8_V9));
outFile.write(reinterpret_cast<char const*>(uint8_V8), sizeof(uint8_V8));
@@ -1029,7 +962,7 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
}
}
- if (heightHeader.flags & MAP_HEIGHT_HAS_FLIGHT_BOUNDS)
+ if (heightHeader.flags.HasFlag(map_heightHeaderFlags::HasFlightBounds))
{
outFile.write(reinterpret_cast<char*>(flight_box_max), sizeof(flight_box_max));
outFile.write(reinterpret_cast<char*>(flight_box_min), sizeof(flight_box_min));
@@ -1039,13 +972,13 @@ bool ConvertADT(ChunkedFile& adt, std::string const& mapName, std::string const&
if (map.liquidMapOffset)
{
outFile.write(reinterpret_cast<char const*>(&liquidHeader), sizeof(liquidHeader));
- if (!(liquidHeader.flags & MAP_LIQUID_NO_TYPE))
+ if (!liquidHeader.flags.HasFlag(map_liquidHeaderFlags::NoType))
{
outFile.write(reinterpret_cast<char const*>(liquid_entry), sizeof(liquid_entry));
outFile.write(reinterpret_cast<char const*>(liquid_flags), sizeof(liquid_flags));
}
- if (!(liquidHeader.flags & MAP_LIQUID_NO_HEIGHT))
+ if (!liquidHeader.flags.HasFlag(map_liquidHeaderFlags::NoHeight))
{
for (int y = 0; y < liquidHeader.height; y++)
outFile.write(reinterpret_cast<char const*>(&liquid_height[y + liquidHeader.offsetY][liquidHeader.offsetX]), sizeof(float) * liquidHeader.width);
@@ -1162,8 +1095,8 @@ void ExtractMaps(uint32 build)
if (FILE* tileList = fopen(Trinity::StringFormat("%s/maps/%04u.tilelist", output_path.string().c_str(), map_ids[z].Id).c_str(), "wb"))
{
- fwrite(MAP_MAGIC, 1, strlen(MAP_MAGIC), tileList);
- fwrite(MAP_VERSION_MAGIC, 1, strlen(MAP_VERSION_MAGIC), tileList);
+ fwrite(MapMagic.data(), 1, MapMagic.size(), tileList);
+ fwrite(MapVersionMagic.data(), 1, MapVersionMagic.size(), tileList);
fwrite(&build, sizeof(build), 1, tileList);
fwrite(existingTiles.to_string().c_str(), 1, existingTiles.size(), tileList);
fclose(tileList);
diff --git a/src/tools/mmaps_generator/TerrainBuilder.cpp b/src/tools/mmaps_generator/TerrainBuilder.cpp
index c9f0638fb1a..30981ec0f6e 100644
--- a/src/tools/mmaps_generator/TerrainBuilder.cpp
+++ b/src/tools/mmaps_generator/TerrainBuilder.cpp
@@ -17,65 +17,14 @@
#include "TerrainBuilder.h"
#include "MapBuilder.h"
+#include "MapDefines.h"
#include "MapTree.h"
#include "MMapDefines.h"
#include "ModelInstance.h"
+#include "Util.h"
#include "VMapFactory.h"
#include "VMapManager2.h"
-// ******************************************
-// Map file format defines
-// ******************************************
-struct map_fileheader
-{
- uint32 mapMagic;
- uint32 versionMagic;
- uint32 buildMagic;
- uint32 areaMapOffset;
- uint32 areaMapSize;
- uint32 heightMapOffset;
- uint32 heightMapSize;
- uint32 liquidMapOffset;
- uint32 liquidMapSize;
- uint32 holesOffset;
- uint32 holesSize;
-};
-
-#define MAP_HEIGHT_NO_HEIGHT 0x0001
-#define MAP_HEIGHT_AS_INT16 0x0002
-#define MAP_HEIGHT_AS_INT8 0x0004
-
-struct map_heightHeader
-{
- uint32 fourcc;
- uint32 flags;
- float gridHeight;
- float gridMaxHeight;
-};
-
-#define MAP_LIQUID_NO_TYPE 0x0001
-#define MAP_LIQUID_NO_HEIGHT 0x0002
-
-struct map_liquidHeader
-{
- uint32 fourcc;
- uint8 flags;
- uint8 liquidFlags;
- uint16 liquidType;
- uint8 offsetX;
- uint8 offsetY;
- uint8 width;
- uint8 height;
- float liquidLevel;
-};
-
-#define MAP_LIQUID_TYPE_NO_WATER 0x00
-#define MAP_LIQUID_TYPE_WATER 0x01
-#define MAP_LIQUID_TYPE_OCEAN 0x02
-#define MAP_LIQUID_TYPE_MAGMA 0x04
-#define MAP_LIQUID_TYPE_SLIME 0x08
-#define MAP_LIQUID_TYPE_DARK_WATER 0x10
-
namespace MMAP
{
char const* MAP_VERSION_MAGIC = "v1.9";
@@ -150,7 +99,7 @@ namespace MMAP
map_fileheader fheader;
if (fread(&fheader, sizeof(map_fileheader), 1, mapFile) != 1 ||
- fheader.versionMagic != *((uint32 const*)(MAP_VERSION_MAGIC)))
+ fheader.versionMagic != MapVersionMagic)
{
fclose(mapFile);
printf("%s is the wrong version, please extract new .map files\n", mapFileName);
@@ -164,7 +113,7 @@ namespace MMAP
bool haveLiquid = false;
if (fread(&hheader, sizeof(map_heightHeader), 1, mapFile) == 1)
{
- haveTerrain = !(hheader.flags & MAP_HEIGHT_NO_HEIGHT);
+ haveTerrain = !hheader.flags.HasFlag(map_heightHeaderFlags::NoHeight);
haveLiquid = fheader.liquidMapOffset && !m_skipLiquid;
}
@@ -180,7 +129,7 @@ namespace MMAP
memset(holes, 0, sizeof(holes));
uint16 liquid_entry[16][16];
memset(liquid_entry, 0, sizeof(liquid_entry));
- uint8 liquid_flags[16][16];
+ map_liquidHeaderTypeFlags liquid_flags[16][16];
memset(liquid_flags, 0, sizeof(liquid_flags));
G3D::Array<int> ltriangles;
G3D::Array<int> ttriangles;
@@ -192,7 +141,7 @@ namespace MMAP
float V9[V9_SIZE_SQ], V8[V8_SIZE_SQ];
int expected = V9_SIZE_SQ + V8_SIZE_SQ;
- if (hheader.flags & MAP_HEIGHT_AS_INT8)
+ if (hheader.flags.HasFlag(map_heightHeaderFlags::HeightAsInt8))
{
uint8 v9[V9_SIZE_SQ];
uint8 v8[V8_SIZE_SQ];
@@ -210,7 +159,7 @@ namespace MMAP
for (int i = 0; i < V8_SIZE_SQ; ++i)
V8[i] = (float)v8[i]*heightMultiplier + hheader.gridHeight;
}
- else if (hheader.flags & MAP_HEIGHT_AS_INT16)
+ else if (hheader.flags.HasFlag(map_heightHeaderFlags::HeightAsInt16))
{
uint16 v9[V9_SIZE_SQ];
uint16 v8[V8_SIZE_SQ];
@@ -291,7 +240,7 @@ namespace MMAP
float* liquid_map = nullptr;
- if (!(lheader.flags & MAP_LIQUID_NO_TYPE))
+ if (!lheader.flags.HasFlag(map_liquidHeaderFlags::NoType))
{
if (fread(liquid_entry, sizeof(liquid_entry), 1, mapFile) != 1)
printf("TerrainBuilder::loadMap: Failed to read some data expected 1, read 0\n");
@@ -304,7 +253,7 @@ namespace MMAP
std::fill_n(&liquid_flags[0][0], 16 * 16, lheader.liquidFlags);
}
- if (!(lheader.flags & MAP_LIQUID_NO_HEIGHT))
+ if (!lheader.flags.HasFlag(map_liquidHeaderFlags::NoHeight))
{
uint32 toRead = lheader.width * lheader.height;
liquid_map = new float [toRead];
@@ -324,7 +273,7 @@ namespace MMAP
int row, col;
// generate coordinates
- if (!(lheader.flags & MAP_LIQUID_NO_HEIGHT))
+ if (!lheader.flags.HasFlag(map_liquidHeaderFlags::NoHeight))
{
int j = 0;
for (int i = 0; i < V9_SIZE_SQ; ++i)
@@ -409,7 +358,8 @@ namespace MMAP
// default is true, will change to false if needed
useTerrain = true;
useLiquid = true;
- uint8 liquidType = MAP_LIQUID_TYPE_NO_WATER;
+ EnumFlag<map_liquidHeaderTypeFlags> liquidType = map_liquidHeaderTypeFlags::NoWater;
+ uint8 navLiquidType = NAV_AREA_EMPTY;
// if there is no liquid, don't use liquid
if (!meshData.liquidVerts.size() || !ltriangles.size())
@@ -417,16 +367,16 @@ namespace MMAP
else
{
liquidType = getLiquidType(i, liquid_flags);
- if (liquidType & MAP_LIQUID_TYPE_DARK_WATER)
+ if (liquidType.HasFlag(map_liquidHeaderTypeFlags::DarkWater))
{
// players should not be here, so logically neither should creatures
useTerrain = false;
useLiquid = false;
}
- else if ((liquidType & (MAP_LIQUID_TYPE_WATER | MAP_LIQUID_TYPE_OCEAN)) != 0)
- liquidType = NAV_AREA_WATER;
- else if ((liquidType & (MAP_LIQUID_TYPE_MAGMA | MAP_LIQUID_TYPE_SLIME)) != 0)
- liquidType = NAV_AREA_MAGMA_SLIME;
+ else if (liquidType.HasFlag(map_liquidHeaderTypeFlags::Water | map_liquidHeaderTypeFlags::Ocean))
+ navLiquidType = NAV_AREA_WATER;
+ else if (liquidType.HasFlag(map_liquidHeaderTypeFlags::Magma | map_liquidHeaderTypeFlags::Slime))
+ navLiquidType = NAV_AREA_MAGMA_SLIME;
else
useLiquid = false;
}
@@ -512,7 +462,7 @@ namespace MMAP
// store the result
if (useLiquid)
{
- meshData.liquidType.append(liquidType);
+ meshData.liquidType.append(navLiquidType);
for (int k = 0; k < 3; ++k)
meshData.liquidTris.append(ltris[k]);
}
@@ -624,7 +574,7 @@ namespace MMAP
}
/**************************************************************************/
- uint8 TerrainBuilder::getLiquidType(int square, const uint8 liquid_type[16][16])
+ map_liquidHeaderTypeFlags TerrainBuilder::getLiquidType(int square, map_liquidHeaderTypeFlags const (&liquid_type)[16][16])
{
int row = square / 128;
int col = square % 128;
@@ -716,10 +666,10 @@ namespace MMAP
uint8 type = NAV_AREA_EMPTY;
// convert liquid type to NavTerrain
- uint32 liquidFlags = vmapManager->GetLiquidFlagsPtr(liquid->GetType());
- if ((liquidFlags & (MAP_LIQUID_TYPE_WATER | MAP_LIQUID_TYPE_OCEAN)) != 0)
+ EnumFlag<map_liquidHeaderTypeFlags> liquidFlags = map_liquidHeaderTypeFlags(vmapManager->GetLiquidFlagsPtr(liquid->GetType()));
+ if (liquidFlags.HasFlag(map_liquidHeaderTypeFlags::Water | map_liquidHeaderTypeFlags::Ocean))
type = NAV_AREA_WATER;
- else if ((liquidFlags & (MAP_LIQUID_TYPE_MAGMA | MAP_LIQUID_TYPE_SLIME)) != 0)
+ else if (liquidFlags.HasFlag(map_liquidHeaderTypeFlags::Magma | map_liquidHeaderTypeFlags::Slime))
type = NAV_AREA_MAGMA_SLIME;
// indexing is weird...
diff --git a/src/tools/mmaps_generator/TerrainBuilder.h b/src/tools/mmaps_generator/TerrainBuilder.h
index 54f48098e09..a41cc705df5 100644
--- a/src/tools/mmaps_generator/TerrainBuilder.h
+++ b/src/tools/mmaps_generator/TerrainBuilder.h
@@ -25,6 +25,8 @@
#include <G3D/Vector3.h>
#include <G3D/Matrix3.h>
+enum class map_liquidHeaderTypeFlags : uint8;
+
namespace MMAP
{
enum Spot
@@ -119,7 +121,7 @@ namespace MMAP
void getLiquidCoord(int index, int index2, float xOffset, float yOffset, float* coord, float* v);
/// Get the liquid type for a specific position
- uint8 getLiquidType(int square, const uint8 liquid_type[16][16]);
+ map_liquidHeaderTypeFlags getLiquidType(int square, map_liquidHeaderTypeFlags const (&liquid_type)[16][16]);
// hide parameterless and copy constructor
TerrainBuilder() = delete;