mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 07:37:01 +00:00
[7428] Add new .map file format use more compact data store and use
Rewrite .map extractor + extract more useful data + add "-f 0" option for disable size/accuracy optimisation + Compatability vs 2.4.3 client data More fast get .map data Implement fatigue timer Rewrite breath timer Allow absorb/resist for lava/slime environmental damage Need re-extract map for work. Signed-off-by: DiSlord <dislord@nomail.com>
This commit is contained in:
parent
95379309e5
commit
6a90d60327
22 changed files with 2280 additions and 877 deletions
724
src/game/Map.cpp
724
src/game/Map.cpp
|
|
@ -41,9 +41,6 @@
|
|||
#define DEFAULT_GRID_EXPIRY 300
|
||||
#define MAX_GRID_LOAD_TIME 50
|
||||
|
||||
// magic *.map header
|
||||
const char MAP_MAGIC[] = "MAP_3.00";
|
||||
|
||||
GridState* si_GridStates[MAX_GRID_STATE];
|
||||
|
||||
Map::~Map()
|
||||
|
|
@ -66,9 +63,9 @@ bool Map::ExistMap(uint32 mapid,int x,int y)
|
|||
return false;
|
||||
}
|
||||
|
||||
char magic[8];
|
||||
fread(magic,1,8,pf);
|
||||
if(strncmp(MAP_MAGIC,magic,8))
|
||||
map_fileheader header;
|
||||
fread(&header, sizeof(header), 1, pf);
|
||||
if (header.mapMagic != MAP_MAGIC || header.versionMagic != MAP_VERSION_MAGIC)
|
||||
{
|
||||
sLog.outError("Map file '%s' is non-compatible version (outdated?). Please, create new using ad.exe program.",tmp);
|
||||
delete [] tmp;
|
||||
|
|
@ -78,7 +75,6 @@ bool Map::ExistMap(uint32 mapid,int x,int y)
|
|||
|
||||
delete [] tmp;
|
||||
fclose(pf);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -157,29 +153,13 @@ void Map::LoadMap(uint32 mapid, uint32 instanceid, int x,int y)
|
|||
snprintf(tmp, len, (char *)(sWorld.GetDataPath()+"maps/%03u%02u%02u.map").c_str(),mapid,x,y);
|
||||
sLog.outDetail("Loading map %s",tmp);
|
||||
// loading data
|
||||
FILE *pf=fopen(tmp,"rb");
|
||||
if(!pf)
|
||||
GridMaps[x][y] = new GridMap();
|
||||
if (!GridMaps[x][y]->loadData(tmp))
|
||||
{
|
||||
delete [] tmp;
|
||||
return;
|
||||
sLog.outError("Error load map file: \n %s\n", tmp);
|
||||
}
|
||||
|
||||
char magic[8];
|
||||
fread(magic,1,8,pf);
|
||||
if(strncmp(MAP_MAGIC,magic,8))
|
||||
{
|
||||
sLog.outError("Map file '%s' is non-compatible version (outdated?). Please, create new using ad.exe program.",tmp);
|
||||
delete [] tmp;
|
||||
fclose(pf); //close file before return
|
||||
return;
|
||||
}
|
||||
delete [] tmp;
|
||||
|
||||
GridMap * buf= new GridMap;
|
||||
fread(buf,1,sizeof(GridMap),pf);
|
||||
fclose(pf);
|
||||
|
||||
GridMaps[x][y] = buf;
|
||||
delete [] tmp;
|
||||
return;
|
||||
}
|
||||
|
||||
void Map::LoadMapAndVMap(uint32 mapid, uint32 instanceid, int x,int y)
|
||||
|
|
@ -1031,7 +1011,11 @@ bool Map::UnloadGrid(const uint32 &x, const uint32 &y, bool pForce)
|
|||
{
|
||||
if (i_InstanceId == 0)
|
||||
{
|
||||
if(GridMaps[gx][gy]) delete (GridMaps[gx][gy]);
|
||||
if(GridMaps[gx][gy])
|
||||
{
|
||||
GridMaps[gx][gy]->unloadData();
|
||||
delete GridMaps[gx][gy];
|
||||
}
|
||||
// x and y are swapped
|
||||
VMAP::VMapFactory::createOrGetVMapManager()->unloadMap(GetId(), gy, gx);
|
||||
}
|
||||
|
|
@ -1056,94 +1040,527 @@ void Map::UnloadAll(bool pForce)
|
|||
}
|
||||
}
|
||||
|
||||
float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const
|
||||
//*****************************
|
||||
// Grid function
|
||||
//*****************************
|
||||
GridMap::GridMap()
|
||||
{
|
||||
GridPair p = MaNGOS::ComputeGridPair(x, y);
|
||||
m_flags = 0;
|
||||
// Area data
|
||||
m_gridArea = 0;
|
||||
m_area_map = NULL;
|
||||
// Height level data
|
||||
m_gridHeight = INVALID_HEIGHT;
|
||||
m_gridGetHeight = &GridMap::getHeightFromFlat;
|
||||
m_V9 = NULL;
|
||||
m_V8 = NULL;
|
||||
// Liquid data
|
||||
m_liquidType = 0;
|
||||
m_liquid_offX = 0;
|
||||
m_liquid_offY = 0;
|
||||
m_liquid_width = 0;
|
||||
m_liquid_height = 0;
|
||||
m_liquidLevel = INVALID_HEIGHT;
|
||||
m_liquid_type = NULL;
|
||||
m_liquid_map = NULL;
|
||||
}
|
||||
|
||||
GridMap::~GridMap()
|
||||
{
|
||||
unloadData();
|
||||
}
|
||||
|
||||
bool GridMap::loadData(char *filename)
|
||||
{
|
||||
// Unload old data if exist
|
||||
unloadData();
|
||||
|
||||
map_fileheader header;
|
||||
// Not return error if file not found
|
||||
FILE *in = fopen(filename, "rb");
|
||||
if (!in)
|
||||
return true;
|
||||
fread(&header, sizeof(header),1,in);
|
||||
if (header.mapMagic == MAP_MAGIC && header.versionMagic == MAP_VERSION_MAGIC)
|
||||
{
|
||||
// loadup area data
|
||||
if (header.areaMapOffset && !loadAreaData(in, header.areaMapOffset, header.areaMapSize))
|
||||
{
|
||||
sLog.outError("Error loading map area data\n");
|
||||
fclose(in);
|
||||
return false;
|
||||
}
|
||||
// loadup height data
|
||||
if (header.heightMapOffset && !loadHeihgtData(in, header.heightMapOffset, header.heightMapSize))
|
||||
{
|
||||
sLog.outError("Error loading map height data\n");
|
||||
fclose(in);
|
||||
return false;
|
||||
}
|
||||
// loadup liquid data
|
||||
if (header.liquidMapOffset && !loadLiquidData(in, header.liquidMapOffset, header.liquidMapSize))
|
||||
{
|
||||
sLog.outError("Error loading map liquids data\n");
|
||||
fclose(in);
|
||||
return false;
|
||||
}
|
||||
fclose(in);
|
||||
return true;
|
||||
}
|
||||
sLog.outError("Map file '%s' is non-compatible version (outdated?). Please, create new using ad.exe program.", filename);
|
||||
fclose(in);
|
||||
return false;
|
||||
}
|
||||
|
||||
void GridMap::unloadData()
|
||||
{
|
||||
if (m_area_map) delete[] m_area_map;
|
||||
if (m_V9) delete[] m_V9;
|
||||
if (m_V8) delete[] m_V8;
|
||||
if (m_liquid_type) delete[] m_liquid_type;
|
||||
if (m_liquid_map) delete[] m_liquid_map;
|
||||
m_area_map = NULL;
|
||||
m_V9 = NULL;
|
||||
m_V8 = NULL;
|
||||
m_liquid_type = NULL;
|
||||
m_liquid_map = NULL;
|
||||
m_gridGetHeight = &GridMap::getHeightFromFlat;
|
||||
}
|
||||
|
||||
bool GridMap::loadAreaData(FILE *in, uint32 offset, uint32 size)
|
||||
{
|
||||
map_areaHeader header;
|
||||
fseek(in, offset, SEEK_SET);
|
||||
fread(&header, sizeof(header), 1, in);
|
||||
if (header.fourcc != MAP_AREA_MAGIC)
|
||||
return false;
|
||||
|
||||
m_gridArea = header.gridArea;
|
||||
if (!(header.flags&MAP_AREA_NO_AREA))
|
||||
{
|
||||
m_area_map = new uint16 [16*16];
|
||||
fread(m_area_map, sizeof(uint16), 16*16, in);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GridMap::loadHeihgtData(FILE *in, uint32 offset, uint32 size)
|
||||
{
|
||||
map_heightHeader header;
|
||||
fseek(in, offset, SEEK_SET);
|
||||
fread(&header, sizeof(header), 1, in);
|
||||
if (header.fourcc != MAP_HEIGTH_MAGIC)
|
||||
return false;
|
||||
|
||||
m_gridHeight = header.gridHeight;
|
||||
if (!(header.flags&MAP_HEIGHT_NO_HIGHT))
|
||||
{
|
||||
if ((header.flags&MAP_HEIGHT_AS_INT16))
|
||||
{
|
||||
m_uint16_V9 = new uint16 [129*129];
|
||||
m_uint16_V8 = new uint16 [128*128];
|
||||
fread(m_uint16_V9, sizeof(uint16), 129*129, in);
|
||||
fread(m_uint16_V8, sizeof(uint16), 128*128, in);
|
||||
m_gridIntHeightMultiplier = (header.gridMaxHeight - header.gridHeight) / 65535;
|
||||
m_gridGetHeight = &GridMap::getHeightFromUint16;
|
||||
}
|
||||
else if ((header.flags&MAP_HEIGHT_AS_INT8))
|
||||
{
|
||||
m_uint8_V9 = new uint8 [129*129];
|
||||
m_uint8_V8 = new uint8 [128*128];
|
||||
fread(m_uint8_V9, sizeof(uint8), 129*129, in);
|
||||
fread(m_uint8_V8, sizeof(uint8), 128*128, in);
|
||||
m_gridIntHeightMultiplier = (header.gridMaxHeight - header.gridHeight) / 255;
|
||||
m_gridGetHeight = &GridMap::getHeightFromUint8;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_V9 = new float [129*129];
|
||||
m_V8 = new float [128*128];
|
||||
fread(m_V9, sizeof(float), 129*129, in);
|
||||
fread(m_V8, sizeof(float), 128*128, in);
|
||||
m_gridGetHeight = &GridMap::getHeightFromFloat;
|
||||
}
|
||||
}
|
||||
else
|
||||
m_gridGetHeight = &GridMap::getHeightFromFlat;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GridMap::loadLiquidData(FILE *in, uint32 offset, uint32 size)
|
||||
{
|
||||
map_liquidHeader header;
|
||||
fseek(in, offset, SEEK_SET);
|
||||
fread(&header, sizeof(header), 1, in);
|
||||
if (header.fourcc != MAP_LIQUID_MAGIC)
|
||||
return false;
|
||||
|
||||
m_liquidType = header.liquidType;
|
||||
m_liquid_offX = header.offsetX;
|
||||
m_liquid_offY = header.offsetY;
|
||||
m_liquid_width = header.width;
|
||||
m_liquid_height= header.height;
|
||||
m_liquidLevel = header.liquidLevel;
|
||||
|
||||
if (!(header.flags&MAP_LIQUID_NO_TYPE))
|
||||
{
|
||||
m_liquid_type = new uint8 [16*16];
|
||||
fread(m_liquid_type, sizeof(uint8), 16*16, in);
|
||||
}
|
||||
if (!(header.flags&MAP_LIQUID_NO_HIGHT))
|
||||
{
|
||||
m_liquid_map = new float [m_liquid_width*m_liquid_height];
|
||||
fread(m_liquid_map, sizeof(float), m_liquid_width*m_liquid_height, in);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16 GridMap::getArea(float x, float y)
|
||||
{
|
||||
if (!m_area_map)
|
||||
return m_gridArea;
|
||||
|
||||
x = 16 * (32 - x/SIZE_OF_GRIDS);
|
||||
y = 16 * (32 - y/SIZE_OF_GRIDS);
|
||||
int lx = (int)x & 15;
|
||||
int ly = (int)y & 15;
|
||||
return m_area_map[lx*16 + ly];
|
||||
}
|
||||
|
||||
float GridMap::getHeightFromFlat(float x, float y) const
|
||||
{
|
||||
return m_gridHeight;
|
||||
}
|
||||
|
||||
float GridMap::getHeightFromFloat(float x, float y) const
|
||||
{
|
||||
if (!m_V8 || !m_V9)
|
||||
return m_gridHeight;
|
||||
|
||||
x = MAP_RESOLUTION * (32 - x/SIZE_OF_GRIDS);
|
||||
y = MAP_RESOLUTION * (32 - y/SIZE_OF_GRIDS);
|
||||
|
||||
int x_int = (int)x;
|
||||
int y_int = (int)y;
|
||||
x -= x_int;
|
||||
y -= y_int;
|
||||
x_int&=(MAP_RESOLUTION - 1);
|
||||
y_int&=(MAP_RESOLUTION - 1);
|
||||
|
||||
// Height stored as: h5 - its v8 grid, h1-h4 - its v9 grid
|
||||
// +--------------> X
|
||||
// | h1-------h2 Coordinates is:
|
||||
// | | \ 1 / | h1 0,0
|
||||
// | | \ / | h2 0,1
|
||||
// | | 2 h5 3 | h3 1,0
|
||||
// | | / \ | h4 1,1
|
||||
// | | / 4 \ | h5 1/2,1/2
|
||||
// | h3-------h4
|
||||
// V Y
|
||||
// For find height need
|
||||
// 1 - detect triangle
|
||||
// 2 - solve linear equation from triangle points
|
||||
// Calculate coefficients for solve h = a*x + b*y + c
|
||||
|
||||
float a,b,c;
|
||||
// Select triangle:
|
||||
if (x+y < 1)
|
||||
{
|
||||
if (x > y)
|
||||
{
|
||||
// 1 triangle (h1, h2, h5 points)
|
||||
float h1 = m_V9[(x_int )*129 + y_int];
|
||||
float h2 = m_V9[(x_int+1)*129 + y_int];
|
||||
float h5 = 2 * m_V8[x_int*128 + y_int];
|
||||
a = h2-h1;
|
||||
b = h5-h1-h2;
|
||||
c = h1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2 triangle (h1, h3, h5 points)
|
||||
float h1 = m_V9[x_int*129 + y_int ];
|
||||
float h3 = m_V9[x_int*129 + y_int+1];
|
||||
float h5 = 2 * m_V8[x_int*128 + y_int];
|
||||
a = h5 - h1 - h3;
|
||||
b = h3 - h1;
|
||||
c = h1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x > y)
|
||||
{
|
||||
// 3 triangle (h2, h4, h5 points)
|
||||
float h2 = m_V9[(x_int+1)*129 + y_int ];
|
||||
float h4 = m_V9[(x_int+1)*129 + y_int+1];
|
||||
float h5 = 2 * m_V8[x_int*128 + y_int];
|
||||
a = h2 + h4 - h5;
|
||||
b = h4 - h2;
|
||||
c = h5 - h4;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 4 triangle (h3, h4, h5 points)
|
||||
float h3 = m_V9[(x_int )*129 + y_int+1];
|
||||
float h4 = m_V9[(x_int+1)*129 + y_int+1];
|
||||
float h5 = 2 * m_V8[x_int*128 + y_int];
|
||||
a = h4 - h3;
|
||||
b = h3 + h4 - h5;
|
||||
c = h5 - h4;
|
||||
}
|
||||
}
|
||||
// Calculate height
|
||||
return a * x + b * y + c;
|
||||
}
|
||||
|
||||
float GridMap::getHeightFromUint8(float x, float y) const
|
||||
{
|
||||
if (!m_uint8_V8 || !m_uint8_V9)
|
||||
return m_gridHeight;
|
||||
|
||||
x = MAP_RESOLUTION * (32 - x/SIZE_OF_GRIDS);
|
||||
y = MAP_RESOLUTION * (32 - y/SIZE_OF_GRIDS);
|
||||
|
||||
int x_int = (int)x;
|
||||
int y_int = (int)y;
|
||||
x -= x_int;
|
||||
y -= y_int;
|
||||
x_int&=(MAP_RESOLUTION - 1);
|
||||
y_int&=(MAP_RESOLUTION - 1);
|
||||
|
||||
int32 a, b, c;
|
||||
uint8 *V9_h1_ptr = &m_uint8_V9[x_int*128 + x_int + y_int];
|
||||
if (x+y < 1)
|
||||
{
|
||||
if (x > y)
|
||||
{
|
||||
// 1 triangle (h1, h2, h5 points)
|
||||
int32 h1 = V9_h1_ptr[ 0];
|
||||
int32 h2 = V9_h1_ptr[129];
|
||||
int32 h5 = 2 * m_uint8_V8[x_int*128 + y_int];
|
||||
a = h2-h1;
|
||||
b = h5-h1-h2;
|
||||
c = h1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2 triangle (h1, h3, h5 points)
|
||||
int32 h1 = V9_h1_ptr[0];
|
||||
int32 h3 = V9_h1_ptr[1];
|
||||
int32 h5 = 2 * m_uint8_V8[x_int*128 + y_int];
|
||||
a = h5 - h1 - h3;
|
||||
b = h3 - h1;
|
||||
c = h1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x > y)
|
||||
{
|
||||
// 3 triangle (h2, h4, h5 points)
|
||||
int32 h2 = V9_h1_ptr[129];
|
||||
int32 h4 = V9_h1_ptr[130];
|
||||
int32 h5 = 2 * m_uint8_V8[x_int*128 + y_int];
|
||||
a = h2 + h4 - h5;
|
||||
b = h4 - h2;
|
||||
c = h5 - h4;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 4 triangle (h3, h4, h5 points)
|
||||
int32 h3 = V9_h1_ptr[ 1];
|
||||
int32 h4 = V9_h1_ptr[130];
|
||||
int32 h5 = 2 * m_uint8_V8[x_int*128 + y_int];
|
||||
a = h4 - h3;
|
||||
b = h3 + h4 - h5;
|
||||
c = h5 - h4;
|
||||
}
|
||||
}
|
||||
// Calculate height
|
||||
return (float)((a * x) + (b * y) + c)*m_gridIntHeightMultiplier + m_gridHeight;
|
||||
}
|
||||
|
||||
float GridMap::getHeightFromUint16(float x, float y) const
|
||||
{
|
||||
if (!m_uint16_V8 || !m_uint16_V9)
|
||||
return m_gridHeight;
|
||||
|
||||
x = MAP_RESOLUTION * (32 - x/SIZE_OF_GRIDS);
|
||||
y = MAP_RESOLUTION * (32 - y/SIZE_OF_GRIDS);
|
||||
|
||||
int x_int = (int)x;
|
||||
int y_int = (int)y;
|
||||
x -= x_int;
|
||||
y -= y_int;
|
||||
x_int&=(MAP_RESOLUTION - 1);
|
||||
y_int&=(MAP_RESOLUTION - 1);
|
||||
|
||||
int32 a, b, c;
|
||||
uint16 *V9_h1_ptr = &m_uint16_V9[x_int*128 + x_int + y_int];
|
||||
if (x+y < 1)
|
||||
{
|
||||
if (x > y)
|
||||
{
|
||||
// 1 triangle (h1, h2, h5 points)
|
||||
int32 h1 = V9_h1_ptr[ 0];
|
||||
int32 h2 = V9_h1_ptr[129];
|
||||
int32 h5 = 2 * m_uint16_V8[x_int*128 + y_int];
|
||||
a = h2-h1;
|
||||
b = h5-h1-h2;
|
||||
c = h1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2 triangle (h1, h3, h5 points)
|
||||
int32 h1 = V9_h1_ptr[0];
|
||||
int32 h3 = V9_h1_ptr[1];
|
||||
int32 h5 = 2 * m_uint16_V8[x_int*128 + y_int];
|
||||
a = h5 - h1 - h3;
|
||||
b = h3 - h1;
|
||||
c = h1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x > y)
|
||||
{
|
||||
// 3 triangle (h2, h4, h5 points)
|
||||
int32 h2 = V9_h1_ptr[129];
|
||||
int32 h4 = V9_h1_ptr[130];
|
||||
int32 h5 = 2 * m_uint16_V8[x_int*128 + y_int];
|
||||
a = h2 + h4 - h5;
|
||||
b = h4 - h2;
|
||||
c = h5 - h4;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 4 triangle (h3, h4, h5 points)
|
||||
int32 h3 = V9_h1_ptr[ 1];
|
||||
int32 h4 = V9_h1_ptr[130];
|
||||
int32 h5 = 2 * m_uint16_V8[x_int*128 + y_int];
|
||||
a = h4 - h3;
|
||||
b = h3 + h4 - h5;
|
||||
c = h5 - h4;
|
||||
}
|
||||
}
|
||||
// Calculate height
|
||||
return (float)((a * x) + (b * y) + c)*m_gridIntHeightMultiplier + m_gridHeight;
|
||||
}
|
||||
|
||||
float GridMap::getLiquidLevel(float x, float y)
|
||||
{
|
||||
if (!m_liquid_map)
|
||||
return m_liquidLevel;
|
||||
|
||||
x = MAP_RESOLUTION * (32 - x/SIZE_OF_GRIDS);
|
||||
y = MAP_RESOLUTION * (32 - y/SIZE_OF_GRIDS);
|
||||
|
||||
int cx_int = ((int)x & (MAP_RESOLUTION-1)) - m_liquid_offY;
|
||||
int cy_int = ((int)y & (MAP_RESOLUTION-1)) - m_liquid_offX;
|
||||
|
||||
if (cx_int < 0 || cx_int >=m_liquid_height)
|
||||
return INVALID_HEIGHT;
|
||||
if (cy_int < 0 || cy_int >=m_liquid_width )
|
||||
return INVALID_HEIGHT;
|
||||
|
||||
return m_liquid_map[cx_int*m_liquid_width + cy_int];
|
||||
}
|
||||
|
||||
uint8 GridMap::getTerrainType(float x, float y)
|
||||
{
|
||||
if (!m_liquid_type)
|
||||
return m_liquidType;
|
||||
|
||||
x = 16 * (32 - x/SIZE_OF_GRIDS);
|
||||
y = 16 * (32 - y/SIZE_OF_GRIDS);
|
||||
int lx = (int)x & 15;
|
||||
int ly = (int)y & 15;
|
||||
return m_liquid_type[lx*16 + ly];
|
||||
}
|
||||
|
||||
// Get water state on map
|
||||
inline ZLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData *data)
|
||||
{
|
||||
// Check water type (if no water return)
|
||||
if (!m_liquid_type && !m_liquidType)
|
||||
return LIQUID_MAP_NO_WATER;
|
||||
|
||||
// Get cell
|
||||
float cx = MAP_RESOLUTION * (32 - x/SIZE_OF_GRIDS);
|
||||
float cy = MAP_RESOLUTION * (32 - y/SIZE_OF_GRIDS);
|
||||
|
||||
int x_int = (int)cx & (MAP_RESOLUTION-1);
|
||||
int y_int = (int)cy & (MAP_RESOLUTION-1);
|
||||
|
||||
// Check water type in cell
|
||||
uint8 type = m_liquid_type ? m_liquid_type[(x_int>>3)*16 + (y_int>>3)] : m_liquidType;
|
||||
if (type == 0)
|
||||
return LIQUID_MAP_NO_WATER;
|
||||
|
||||
// Check req liquid type mask
|
||||
if (ReqLiquidType && !(ReqLiquidType&type))
|
||||
return LIQUID_MAP_NO_WATER;
|
||||
|
||||
// Check water level:
|
||||
// Check water height map
|
||||
int lx_int = x_int - m_liquid_offY;
|
||||
int ly_int = y_int - m_liquid_offX;
|
||||
if (lx_int < 0 || lx_int >=m_liquid_height)
|
||||
return LIQUID_MAP_NO_WATER;
|
||||
if (ly_int < 0 || ly_int >=m_liquid_width )
|
||||
return LIQUID_MAP_NO_WATER;
|
||||
|
||||
// Get water level
|
||||
float liquid_level = m_liquid_map ? m_liquid_map[lx_int*m_liquid_width + ly_int] : m_liquidLevel;
|
||||
// Get ground level (sub 0.2 for fix some errors)
|
||||
float ground_level = getHeight(x, y);
|
||||
|
||||
// Check water level and ground level
|
||||
if (liquid_level < ground_level || z < ground_level - 2)
|
||||
return LIQUID_MAP_NO_WATER;
|
||||
|
||||
// All ok in water -> store data
|
||||
if (data)
|
||||
{
|
||||
data->type = type;
|
||||
data->level = liquid_level;
|
||||
data->depth_level = ground_level;
|
||||
}
|
||||
|
||||
// For speed check as int values
|
||||
int delta = (liquid_level - z) * 10;
|
||||
|
||||
// Get position delta
|
||||
if (delta > 20) // Under water
|
||||
return LIQUID_MAP_UNDER_WATER;
|
||||
if (delta > 0 ) // In water
|
||||
return LIQUID_MAP_IN_WATER;
|
||||
if (delta > -1) // Walk on water
|
||||
return LIQUID_MAP_WATER_WALK;
|
||||
// Above water
|
||||
return LIQUID_MAP_ABOVE_WATER;
|
||||
}
|
||||
|
||||
inline GridMap *Map::GetGrid(float x, float y)
|
||||
{
|
||||
// half opt method
|
||||
int gx=(int)(32-x/SIZE_OF_GRIDS); //grid x
|
||||
int gy=(int)(32-y/SIZE_OF_GRIDS); //grid y
|
||||
|
||||
float lx=MAP_RESOLUTION*(32 -x/SIZE_OF_GRIDS - gx);
|
||||
float ly=MAP_RESOLUTION*(32 -y/SIZE_OF_GRIDS - gy);
|
||||
|
||||
// ensure GridMap is loaded
|
||||
const_cast<Map*>(this)->EnsureGridCreated(GridPair(63-gx,63-gy));
|
||||
EnsureGridCreated(GridPair(63-gx,63-gy));
|
||||
|
||||
return GridMaps[gx][gy];
|
||||
}
|
||||
|
||||
float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const
|
||||
{
|
||||
// find raw .map surface under Z coordinates
|
||||
float mapHeight;
|
||||
if(GridMap* gmap = GridMaps[gx][gy])
|
||||
if(GridMap *gmap = const_cast<Map*>(this)->GetGrid(x, y))
|
||||
{
|
||||
int lx_int = (int)lx;
|
||||
int ly_int = (int)ly;
|
||||
lx -= lx_int;
|
||||
ly -= ly_int;
|
||||
|
||||
// Height stored as: h5 - its v8 grid, h1-h4 - its v9 grid
|
||||
// +--------------> X
|
||||
// | h1-------h2 Coordinates is:
|
||||
// | | \ 1 / | h1 0,0
|
||||
// | | \ / | h2 0,1
|
||||
// | | 2 h5 3 | h3 1,0
|
||||
// | | / \ | h4 1,1
|
||||
// | | / 4 \ | h5 1/2,1/2
|
||||
// | h3-------h4
|
||||
// V Y
|
||||
// For find height need
|
||||
// 1 - detect triangle
|
||||
// 2 - solve linear equation from triangle points
|
||||
|
||||
// Calculate coefficients for solve h = a*x + b*y + c
|
||||
float a,b,c;
|
||||
// Select triangle:
|
||||
if (lx+ly < 1)
|
||||
{
|
||||
if (lx > ly)
|
||||
{
|
||||
// 1 triangle (h1, h2, h5 points)
|
||||
float h1 = gmap->v9[lx_int][ly_int];
|
||||
float h2 = gmap->v9[lx_int+1][ly_int];
|
||||
float h5 = 2 * gmap->v8[lx_int][ly_int];
|
||||
a = h2-h1;
|
||||
b = h5-h1-h2;
|
||||
c = h1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 2 triangle (h1, h3, h5 points)
|
||||
float h1 = gmap->v9[lx_int][ly_int];
|
||||
float h3 = gmap->v9[lx_int][ly_int+1];
|
||||
float h5 = 2 * gmap->v8[lx_int][ly_int];
|
||||
a = h5 - h1 - h3;
|
||||
b = h3 - h1;
|
||||
c = h1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lx > ly)
|
||||
{
|
||||
// 3 triangle (h2, h4, h5 points)
|
||||
float h2 = gmap->v9[lx_int+1][ly_int];
|
||||
float h4 = gmap->v9[lx_int+1][ly_int+1];
|
||||
float h5 = 2 * gmap->v8[lx_int][ly_int];
|
||||
a = h2 + h4 - h5;
|
||||
b = h4 - h2;
|
||||
c = h5 - h4;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 4 triangle (h3, h4, h5 points)
|
||||
float h3 = gmap->v9[lx_int][ly_int+1];
|
||||
float h4 = gmap->v9[lx_int+1][ly_int+1];
|
||||
float h5 = 2 * gmap->v8[lx_int][ly_int];
|
||||
a = h4 - h3;
|
||||
b = h3 + h4 - h5;
|
||||
c = h5 - h4;
|
||||
}
|
||||
}
|
||||
// Calculate height
|
||||
float _mapheight = a * lx + b * ly + c;
|
||||
float _mapheight = gmap->getHeight(x,y);
|
||||
|
||||
// look from a bit higher pos to find the floor, ignore under surface case
|
||||
if(z + 2.0f > _mapheight)
|
||||
|
|
@ -1202,25 +1619,9 @@ float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const
|
|||
|
||||
uint16 Map::GetAreaFlag(float x, float y, float z) const
|
||||
{
|
||||
//local x,y coords
|
||||
float lx,ly;
|
||||
int gx,gy;
|
||||
GridPair p = MaNGOS::ComputeGridPair(x, y);
|
||||
|
||||
// half opt method
|
||||
gx=(int)(32-x/SIZE_OF_GRIDS) ; //grid x
|
||||
gy=(int)(32-y/SIZE_OF_GRIDS); //grid y
|
||||
|
||||
lx=16*(32 -x/SIZE_OF_GRIDS - gx);
|
||||
ly=16*(32 -y/SIZE_OF_GRIDS - gy);
|
||||
//DEBUG_LOG("my %d %d si %d %d",gx,gy,p.x_coord,p.y_coord);
|
||||
|
||||
// ensure GridMap is loaded
|
||||
const_cast<Map*>(this)->EnsureGridCreated(GridPair(63-gx,63-gy));
|
||||
|
||||
uint16 areaflag;
|
||||
if(GridMaps[gx][gy])
|
||||
areaflag = GridMaps[gx][gy]->area_flag[(int)(lx)][(int)(ly)];
|
||||
if(GridMap *gmap = const_cast<Map*>(this)->GetGrid(x, y))
|
||||
areaflag = gmap->getArea(x, y);
|
||||
// this used while not all *.map files generated (instances)
|
||||
else
|
||||
areaflag = GetAreaFlagByMapId(i_id);
|
||||
|
|
@ -1251,44 +1652,24 @@ uint16 Map::GetAreaFlag(float x, float y, float z) const
|
|||
|
||||
uint8 Map::GetTerrainType(float x, float y ) const
|
||||
{
|
||||
//local x,y coords
|
||||
float lx,ly;
|
||||
int gx,gy;
|
||||
|
||||
// half opt method
|
||||
gx=(int)(32-x/SIZE_OF_GRIDS) ; //grid x
|
||||
gy=(int)(32-y/SIZE_OF_GRIDS); //grid y
|
||||
|
||||
lx=16*(32 -x/SIZE_OF_GRIDS - gx);
|
||||
ly=16*(32 -y/SIZE_OF_GRIDS - gy);
|
||||
|
||||
// ensure GridMap is loaded
|
||||
const_cast<Map*>(this)->EnsureGridCreated(GridPair(63-gx,63-gy));
|
||||
|
||||
if(GridMaps[gx][gy])
|
||||
return GridMaps[gx][gy]->terrain_type[(int)(lx)][(int)(ly)];
|
||||
if(GridMap *gmap = const_cast<Map*>(this)->GetGrid(x, y))
|
||||
return gmap->getTerrainType(x, y);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
ZLiquidStatus Map::getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData *data) const
|
||||
{
|
||||
if(GridMap* gmap = const_cast<Map*>(this)->GetGrid(x, y))
|
||||
return gmap->getLiquidStatus(x, y, z, ReqLiquidType, data);
|
||||
else
|
||||
return LIQUID_MAP_NO_WATER;
|
||||
}
|
||||
|
||||
float Map::GetWaterLevel(float x, float y ) const
|
||||
{
|
||||
//local x,y coords
|
||||
float lx,ly;
|
||||
int gx,gy;
|
||||
|
||||
// half opt method
|
||||
gx=(int)(32-x/SIZE_OF_GRIDS) ; //grid x
|
||||
gy=(int)(32-y/SIZE_OF_GRIDS); //grid y
|
||||
|
||||
lx=128*(32 -x/SIZE_OF_GRIDS - gx);
|
||||
ly=128*(32 -y/SIZE_OF_GRIDS - gy);
|
||||
|
||||
// ensure GridMap is loaded
|
||||
const_cast<Map*>(this)->EnsureGridCreated(GridPair(63-gx,63-gy));
|
||||
|
||||
if(GridMaps[gx][gy])
|
||||
return GridMaps[gx][gy]->liquid_level[(int)(lx)][(int)(ly)];
|
||||
if(GridMap* gmap = const_cast<Map*>(this)->GetGrid(x, y))
|
||||
return gmap->getLiquidLevel(x, y);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1315,24 +1696,27 @@ uint32 Map::GetZoneId(uint16 areaflag,uint32 map_id)
|
|||
|
||||
bool Map::IsInWater(float x, float y, float pZ) const
|
||||
{
|
||||
// This method is called too often to use vamps for that (4. parameter = false).
|
||||
// The pZ pos is taken anyway for future use
|
||||
float z = GetHeight(x,y,pZ,false); // use .map base surface height
|
||||
|
||||
// underground or instance without vmap
|
||||
if(z <= INVALID_HEIGHT)
|
||||
return false;
|
||||
|
||||
float water_z = GetWaterLevel(x,y);
|
||||
uint8 flag = GetTerrainType(x,y);
|
||||
return (z < (water_z-2)) && (flag & 0x01);
|
||||
// Check surface in x, y point for liquid
|
||||
if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(x, y))
|
||||
{
|
||||
LiquidData liquid_status;
|
||||
if (getLiquidStatus(x, y, pZ, MAP_ALL_LIQUIDS, &liquid_status))
|
||||
{
|
||||
if (liquid_status.level - liquid_status.depth_level > 2)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Map::IsUnderWater(float x, float y, float z) const
|
||||
{
|
||||
float water_z = GetWaterLevel(x,y);
|
||||
uint8 flag = GetTerrainType(x,y);
|
||||
return (z < (water_z-2)) && (flag & 0x01);
|
||||
if (GridMap* gmap = const_cast<Map*>(this)->GetGrid(x, y))
|
||||
{
|
||||
if (getLiquidStatus(x, y, z, MAP_LIQUID_TYPE_WATER|MAP_LIQUID_TYPE_OCEAN)&LIQUID_MAP_UNDER_WATER)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Map::CheckGridIntegrity(Creature* c, bool moved) const
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue