[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.

Author: DiSlord

--HG--
branch : trunk
This commit is contained in:
megamage
2009-03-09 18:06:19 -06:00
parent e68bb30fd1
commit 5f7a2b4355
13 changed files with 1597 additions and 373 deletions
+7 -2
View File
@@ -12,10 +12,15 @@ cmake_minimum_required (VERSION 2.6)
project (MANGOS_MAP_EXTRACTOR)
add_subdirectory (libmpq)
add_subdirectory (loadlib)
include_directories (${MANGOS_MAP_EXTRACTOR_SOURCE_DIR}/libmpq)
link_directories (${MANGOS_MAP_EXTRACTOR_SOURCE_DIR}/libmpq)
include_directories (${MANGOS_MAP_EXTRACTOR_SOURCE_DIR}/loadlib)
add_executable (ad adt.cpp dbcfile.cpp mpq_libmpq.cpp System.cpp)
link_directories (${MANGOS_MAP_EXTRACTOR_SOURCE_DIR}/libmpq)
link_directories (${MANGOS_MAP_EXTRACTOR_SOURCE_DIR}/loadlib)
add_executable (ad dbcfile.cpp mpq_libmpq.cpp System.cpp)
target_link_libraries (ad libmpq)
target_link_libraries (ad loadlib)
+670 -47
View File
@@ -14,10 +14,10 @@
#include "dbcfile.h"
#include "mpq_libmpq.h"
extern unsigned int iRes;
extern ArchiveSet gOpenArchives;
#include "loadlib/adt.h"
#include "loadlib/wdt.h"
bool ConvertADT(char*, char*);
extern ArchiveSet gOpenArchives;
typedef struct
{
@@ -25,10 +25,6 @@ typedef struct
uint32 id;
} map_id;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
map_id *map_ids;
uint16 *areas;
uint16 *LiqType;
@@ -36,18 +32,44 @@ char output_path[128] = ".";
char input_path[128] = ".";
uint32 maxAreaId = 0;
//**************************************************
// Extractor options
//**************************************************
enum Extract
{
EXTRACT_MAP = 1,
EXTRACT_DBC = 2
};
int extract = EXTRACT_MAP | EXTRACT_DBC;
// Select data for extract
int CONF_extract = EXTRACT_MAP | EXTRACT_DBC;
// This option allow limit minimum height to some value (Allow save some memory)
bool CONF_allow_height_limit = true;
float CONF_use_minHeight = -500.0f;
// This option allow use float to int conversion
bool CONF_allow_float_to_int = true;
float CONF_float_to_int8_limit = 2.0f; // Max accuracy = val/256
float CONF_float_to_int16_limit = 2048.0f; // Max accuracy = val/65536
float CONF_flat_height_delta_limit = 0.005f; // If max - min less this value - surface is flat
float CONF_flat_liquid_delta_limit = 0.001f; // If max - min less this value - liquid surface is flat
// List MPQ for extract from
char *CONF_mpq_list[]={
"common.MPQ",
"common-2.MPQ",
"lichking.MPQ",
"expansion.MPQ",
"patch.MPQ",
"patch-2.MPQ",
"patch-3.MPQ",
"patch-4.MPQ",
"patch-5.MPQ",
};
static char* const langs[] = {"enGB", "enUS", "deDE", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" };
#define LANG_COUNT 12
#define ADT_RES 64
void CreateDir( const std::string& Path )
{
#ifdef WIN32
@@ -70,7 +92,14 @@ bool FileExists( const char* FileName )
void Usage(char* prg)
{
printf("Usage:\n%s -[var] [value]\n-i set input path\n-o set output path\n-e extract only MAP(1)/DBC(2) - standard: both(3)\nExample: %s -r 256 -i \"c:\\games\\game\"", prg, prg);
printf(
"Usage:\n"\
"%s -[var] [value]\n"\
"-i set input path\n"\
"-o set output path\n"\
"-e extract only MAP(1)/DBC(2) - standard: both(3)\n"\
"-f height stored as int (less map size but lost some accuracy) 1 by default\n"\
"Example: %s -f 0 -i \"c:\\games\\game\"", prg, prg);
exit(1);
}
@@ -80,8 +109,9 @@ void HandleArgs(int argc, char * arg[])
{
// i - input path
// o - output path
// r - resolution, array of (r * r) heights will be created
// e - extract only MAP(1)/DBC(2) - standard both(3)
// f - use float to int conversion
// h - limit minimum height
if(arg[c][0] != '-')
Usage(arg[0]);
@@ -99,11 +129,17 @@ void HandleArgs(int argc, char * arg[])
else
Usage(arg[0]);
break;
case 'f':
if(c + 1 < argc) // all ok
CONF_allow_float_to_int=atoi(arg[(c++) + 1])!=0;
else
Usage(arg[0]);
break;
case 'e':
if(c + 1 < argc) // all ok
{
extract=atoi(arg[(c++) + 1]);
if(!(extract > 0 && extract < 4))
CONF_extract=atoi(arg[(c++) + 1]);
if(!(CONF_extract > 0 && CONF_extract < 4))
Usage(arg[0]);
}
else
@@ -165,10 +201,602 @@ void ReadLiquidTypeTableDBC()
printf("Done! (%u LiqTypes loaded)\n", LiqType_count);
}
//
// Adt file convertor function and data
//
// Map file format data
#define MAP_MAGIC 'SPAM'
#define MAP_VERSION_MAGIC '0.1v'
#define MAP_AREA_MAGIC 'AERA'
#define MAP_HEIGTH_MAGIC 'TGHM'
#define MAP_LIQUID_MAGIC 'QILM'
struct map_fileheader{
uint32 mapMagic;
uint32 versionMagic;
uint32 areaMapOffset;
uint32 areaMapSize;
uint32 heightMapOffset;
uint32 heightMapSize;
uint32 liquidMapOffset;
uint32 liquidMapSize;
};
#define MAP_AREA_NO_AREA 0x0001
struct map_areaHeader{
uint32 fourcc;
uint16 flags;
uint16 gridArea;
};
#define MAP_HEIGHT_NO_HIGHT 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_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_TYPE_WMO_WATER 0x20
#define MAP_LIQUID_NO_TYPE 0x0001
#define MAP_LIQUID_NO_HIGHT 0x0002
struct map_liquidHeader{
uint32 fourcc;
uint16 flags;
uint16 liquidType;
uint8 offsetX;
uint8 offsetY;
uint8 width;
uint8 height;
float liquidLevel;
};
float selectUInt8StepStore(float maxDiff)
{
return 255 / maxDiff;
}
float selectUInt16StepStore(float maxDiff)
{
return 65535 / maxDiff;
}
// Temporary grid data store
uint16 area_flags[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
float V8[ADT_GRID_SIZE][ADT_GRID_SIZE];
float V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1];
uint16 uint16_V8[ADT_GRID_SIZE][ADT_GRID_SIZE];
uint16 uint16_V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1];
uint8 uint8_V8[ADT_GRID_SIZE][ADT_GRID_SIZE];
uint8 uint8_V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1];
uint8 liquid_type[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];
bool ConvertADT(char *filename, char *filename2, int cell_y, int cell_x)
{
ADT_file adt;
if (!adt.loadFile(filename))
return false;
adt_MCIN *cells = adt.a_grid->getMCIN();
if (!cells)
{
printf("Can't find cells in '%s'\n", filename);
return false;
}
memset(liquid_show, 0, sizeof(liquid_show));
memset(liquid_type, 0, sizeof(liquid_type));
memset(liquid_height, 0, sizeof(liquid_height));
// Prepare map header
map_fileheader map;
map.mapMagic = MAP_MAGIC;
map.versionMagic = MAP_VERSION_MAGIC;
// Get area flags data
for (int i=0;i<ADT_CELLS_PER_GRID;i++)
{
for(int j=0;j<ADT_CELLS_PER_GRID;j++)
{
adt_MCNK * cell = cells->getMCNK(i,j);
uint32 areaid = cell->areaid;
if(areaid && areaid <= maxAreaId)
{
if(areas[areaid] != 0xffff)
{
area_flags[i][j] = areas[areaid];
continue;
}
printf("File: filename\nCan't find area flag for areaid %u [%d, %d].\n", filename, areaid, cell->ix, cell->iy);
}
area_flags[i][j] = 0xffff;
}
}
//============================================
// Try pack area data
//============================================
bool fullAreaData = false;
uint32 areaflag = area_flags[0][0];
for (int y=0;y<ADT_CELLS_PER_GRID;y++)
{
for(int x=0;x<ADT_CELLS_PER_GRID;x++)
{
if(area_flags[y][x]!=areaflag)
{
fullAreaData = true;
break;
}
}
}
map.areaMapOffset = sizeof(map);
map.areaMapSize = sizeof(map_areaHeader);
map_areaHeader areaHeader;
areaHeader.fourcc = MAP_AREA_MAGIC;
areaHeader.flags = 0;
if (fullAreaData)
{
areaHeader.gridArea = 0;
map.areaMapSize+=sizeof(area_flags);
}
else
{
areaHeader.flags |= MAP_AREA_NO_AREA;
areaHeader.gridArea = (uint16)areaflag;
}
//
// Get Height map from grid
//
for (int i=0;i<ADT_CELLS_PER_GRID;i++)
{
for(int j=0;j<ADT_CELLS_PER_GRID;j++)
{
adt_MCNK * cell = cells->getMCNK(i,j);
if (!cell)
continue;
// Height values for triangles stored in order:
// 1 2 3 4 5 6 7 8 9
// 10 11 12 13 14 15 16 17
// 18 19 20 21 22 23 24 25 26
// 27 28 29 30 31 32 33 34
// . . . . . . . .
// For better get height values merge it to V9 and V8 map
// V9 height map:
// 1 2 3 4 5 6 7 8 9
// 18 19 20 21 22 23 24 25 26
// . . . . . . . .
// V8 height map:
// 10 11 12 13 14 15 16 17
// 27 28 29 30 31 32 33 34
// . . . . . . . .
// Set map height as grid height
for (int y=0; y <= ADT_CELL_SIZE; y++)
{
int cy = i*ADT_CELL_SIZE + y;
for (int x=0; x <= ADT_CELL_SIZE; x++)
{
int cx = j*ADT_CELL_SIZE + x;
V9[cy][cx]=cell->ypos;
}
}
for (int y=0; y < ADT_CELL_SIZE; y++)
{
int cy = i*ADT_CELL_SIZE + y;
for (int x=0; x < ADT_CELL_SIZE; x++)
{
int cx = j*ADT_CELL_SIZE + x;
V8[cy][cx]=cell->ypos;
}
}
// Get custom height
adt_MCVT *v = cell->getMCVT();
if (!v)
continue;
// get V9 height map
for (int y=0; y <= ADT_CELL_SIZE; y++)
{
int cy = i*ADT_CELL_SIZE + y;
for (int x=0; x <= ADT_CELL_SIZE; x++)
{
int cx = j*ADT_CELL_SIZE + x;
V9[cy][cx]+=v->height_map[y*(ADT_CELL_SIZE*2+1)+x];
}
}
// get V8 height map
for (int y=0; y < ADT_CELL_SIZE; y++)
{
int cy = i*ADT_CELL_SIZE + y;
for (int x=0; x < ADT_CELL_SIZE; x++)
{
int cx = j*ADT_CELL_SIZE + x;
V8[cy][cx]+=v->height_map[y*(ADT_CELL_SIZE*2+1)+ADT_CELL_SIZE+1+x];
}
}
}
}
//============================================
// Try pack height data
//============================================
float maxHeight = -20000;
float minHeight = 20000;
for (int y=0; y<ADT_GRID_SIZE; y++)
{
for(int x=0;x<ADT_GRID_SIZE;x++)
{
float h = V8[y][x];
if (maxHeight < h) maxHeight = h;
if (minHeight > h) minHeight = h;
}
}
for (int y=0; y<=ADT_GRID_SIZE; y++)
{
for(int x=0;x<=ADT_GRID_SIZE;x++)
{
float h = V9[y][x];
if (maxHeight < h) maxHeight = h;
if (minHeight > h) minHeight = h;
}
}
// Check for allow limit minimum height (not store height in deep ochean - allow save some memory)
if (CONF_allow_height_limit && minHeight < CONF_use_minHeight)
{
for (int y=0; y<ADT_GRID_SIZE; y++)
for(int x=0;x<ADT_GRID_SIZE;x++)
if (V8[y][x] < CONF_use_minHeight)
V8[y][x] = CONF_use_minHeight;
for (int y=0; y<=ADT_GRID_SIZE; y++)
for(int x=0;x<=ADT_GRID_SIZE;x++)
if (V9[y][x] < CONF_use_minHeight)
V9[y][x] = CONF_use_minHeight;
if (minHeight < CONF_use_minHeight)
minHeight = CONF_use_minHeight;
if (maxHeight < CONF_use_minHeight)
maxHeight = CONF_use_minHeight;
}
map.heightMapOffset = map.areaMapOffset + map.areaMapSize;
map.heightMapSize = sizeof(map_heightHeader);
map_heightHeader heightHeader;
heightHeader.fourcc = MAP_HEIGTH_MAGIC;
heightHeader.flags = 0;
heightHeader.gridHeight = minHeight;
heightHeader.gridMaxHeight = maxHeight;
if (maxHeight == minHeight)
heightHeader.flags |=MAP_HEIGHT_NO_HIGHT;
// Not need store if flat surface
if (CONF_allow_float_to_int && (maxHeight - minHeight) < CONF_flat_height_delta_limit)
heightHeader.flags |=MAP_HEIGHT_NO_HIGHT;
// Try store as packed in uint16 or uint8 values
if (!(heightHeader.flags&MAP_HEIGHT_NO_HIGHT))
{
float step;
// Try Store as uint values
if (CONF_allow_float_to_int)
{
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;
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;
step = selectUInt16StepStore(diff);
}
}
// Pack it to int values if need
if (heightHeader.flags&MAP_HEIGHT_AS_INT8)
{
for (int y=0; y<ADT_GRID_SIZE; y++)
for(int x=0;x<ADT_GRID_SIZE;x++)
uint8_V8[y][x] = uint8((V8[y][x] - minHeight) * step + 0.5f);
for (int y=0; y<=ADT_GRID_SIZE; y++)
for(int x=0;x<=ADT_GRID_SIZE;x++)
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)
{
for (int y=0; y<ADT_GRID_SIZE; y++)
for(int x=0;x<ADT_GRID_SIZE;x++)
uint16_V8[y][x] = uint16((V8[y][x] - minHeight) * step + 0.5f);
for (int y=0; y<=ADT_GRID_SIZE; y++)
for(int x=0;x<=ADT_GRID_SIZE;x++)
uint16_V9[y][x] = uint16((V9[y][x] - minHeight) * step + 0.5f);
map.heightMapSize+= sizeof(uint16_V9) + sizeof(uint16_V8);
}
else
map.heightMapSize+= sizeof(V9) + sizeof(V8);
}
// Get liquid map for grid (in WOTLK used MH2O chunk)
adt_MH2O * h2o = adt.a_grid->getMH2O();
if (h2o)
{
for (int i=0;i<ADT_CELLS_PER_GRID;i++)
{
for(int j=0;j<ADT_CELLS_PER_GRID;j++)
{
adt_liquid_header *h = h2o->getLiquidData(i,j);
if (!h)
continue;
int count = 0;
uint64 show = h2o->getLiquidShowMap(h);
for (int y=0; y < h->height;y++)
{
int cy = i*ADT_CELL_SIZE + y + h->yOffset;
for (int x=0; x < h->width; x++)
{
int cx = j*ADT_CELL_SIZE + x + h->xOffset;
if (show & 1)
{
liquid_show[cy][cx] = true;
++count;
}
show>>=1;
}
}
uint32 type = LiqType[h->liquidType];
switch (type)
{
case LIQUID_TYPE_WATER: liquid_type[i][j] |= MAP_LIQUID_TYPE_WATER; break;
case LIQUID_TYPE_OCEAN: liquid_type[i][j] |= MAP_LIQUID_TYPE_OCEAN; break;
case LIQUID_TYPE_MAGMA: liquid_type[i][j] |= MAP_LIQUID_TYPE_MAGMA; break;
case LIQUID_TYPE_SLIME: liquid_type[i][j] |= MAP_LIQUID_TYPE_SLIME; break;
default:
printf("\nCan't find Liquid type %u for map %s\nchunk %d,%d\n", h->liquidType, filename, i, j);
break;
}
// Dark water detect
if (type == LIQUID_TYPE_OCEAN)
{
uint8 *lm = h2o->getLiquidLightMap(h);
if (!lm)
liquid_type[i][j]|=MAP_LIQUID_TYPE_DARK_WATER;
}
if (!count && liquid_type[i][j])
printf("Wrong liquid detect in MH2O chunk");
float *height = h2o->getLiquidHeightMap(h);
int pos = 0;
for (int y=0; y<=h->height;y++)
{
int cy = i*ADT_CELL_SIZE + y + h->yOffset;
for (int x=0; x<= h->width; x++)
{
int cx = j*ADT_CELL_SIZE + x + h->xOffset;
if (height)
liquid_height[cy][cx] = height[pos];
else
liquid_height[cy][cx] = h->heightLevel1;
pos++;
}
}
}
}
}
else
{
// Get from MCLQ chunk (old)
for (int i=0;i<ADT_CELLS_PER_GRID;i++)
{
for(int j=0;j<ADT_CELLS_PER_GRID;j++)
{
adt_MCNK *cell = cells->getMCNK(i, j);
if (!cell)
continue;
adt_MCLQ *liquid = cell->getMCLQ();
int count = 0;
if (!liquid || cell->sizeMCLQ <= 8)
continue;
for (int y=0; y < ADT_CELL_SIZE; y++)
{
int cy = i*ADT_CELL_SIZE + y;
for (int x=0; x < ADT_CELL_SIZE; x++)
{
int cx = j*ADT_CELL_SIZE + x;
if (liquid->flags[y][x] != 0x0F)
{
liquid_show[cy][cx] = true;
if (liquid->flags[y][x]&(1<<7))
liquid_type[i][j]|=MAP_LIQUID_TYPE_DARK_WATER;
++count;
}
}
}
uint32 c_flag = cell->flags;
if(c_flag & (1<<2))
liquid_type[i][j]|=MAP_LIQUID_TYPE_WATER; // water
if(c_flag & (1<<3))
liquid_type[i][j]|=MAP_LIQUID_TYPE_OCEAN; // ochean
if(c_flag & (1<<4))
liquid_type[i][j]|=MAP_LIQUID_TYPE_MAGMA; // magma/slime
if (!count && liquid_type[i][j])
printf("Wrong liquid detect in MCLQ chunk");
for (int y=0; y <= ADT_CELL_SIZE; y++)
{
int cy = i*ADT_CELL_SIZE + y;
for (int x=0; x<= ADT_CELL_SIZE; x++)
{
int cx = j*ADT_CELL_SIZE + x;
liquid_height[cy][cx] = liquid->liquid[y][x].height;
}
}
}
}
}
//============================================
// Pack liquid data
//============================================
uint8 type = liquid_type[0][0];
bool fullType = false;
for (int y=0;y<ADT_CELLS_PER_GRID;y++)
{
for(int x=0;x<ADT_CELLS_PER_GRID;x++)
{
if (liquid_type[y][x]!=type)
{
fullType = true;
y = ADT_CELLS_PER_GRID;
break;
}
}
}
map_liquidHeader liquidHeader;
// no water data (if all grid have 0 liquid type)
if (type == 0 && !fullType)
{
// No liquid data
map.liquidMapOffset = 0;
map.liquidMapSize = 0;
}
else
{
int minX = 255, minY = 255;
int maxX = 0, maxY = 0;
maxHeight = -20000;
minHeight = 20000;
for (int y=0; y<ADT_GRID_SIZE; y++)
{
for(int x=0; x<ADT_GRID_SIZE; x++)
{
if (liquid_show[y][x])
{
if (minX > x) minX = x;
if (maxX < x) maxX = x;
if (minY > y) minY = y;
if (maxY < y) maxY = y;
float h = liquid_height[y][x];
if (maxHeight < h) maxHeight = h;
if (minHeight > h) minHeight = h;
}
}
}
map.liquidMapOffset = map.heightMapOffset + map.heightMapSize;
map.liquidMapSize = sizeof(map_liquidHeader);
liquidHeader.fourcc = MAP_LIQUID_MAGIC;
liquidHeader.flags = 0;
liquidHeader.liquidType = 0;
liquidHeader.offsetX = minX;
liquidHeader.offsetY = minY;
liquidHeader.width = maxX - minX + 1;
liquidHeader.height = maxY - minY + 1;
liquidHeader.liquidLevel = minHeight;
if (maxHeight == minHeight)
liquidHeader.flags|=MAP_LIQUID_NO_HIGHT;
// Not need store if flat surface
if (CONF_allow_float_to_int && (maxHeight - minHeight) < CONF_flat_liquid_delta_limit)
liquidHeader.flags|=MAP_LIQUID_NO_HIGHT;
if (!fullType)
liquidHeader.flags|=MAP_LIQUID_NO_TYPE;
if (liquidHeader.flags&MAP_LIQUID_NO_TYPE)
liquidHeader.liquidType = type;
else
map.liquidMapSize+=sizeof(liquid_type);
if (!(liquidHeader.flags&MAP_LIQUID_NO_HIGHT))
map.liquidMapSize+=sizeof(float)*liquidHeader.width*liquidHeader.height;
}
// Ok all data prepared - store it
FILE *output=fopen(filename2, "wb");
if(!output)
{
printf("Can't create the output file '%s'\n", filename2);
return false;
}
fwrite(&map, sizeof(map), 1, output);
// Store area data
fwrite(&areaHeader, sizeof(areaHeader), 1, output);
if (!(areaHeader.flags&MAP_AREA_NO_AREA))
fwrite(area_flags, sizeof(area_flags), 1, output);
// Store height data
fwrite(&heightHeader, sizeof(heightHeader), 1, output);
if (!(heightHeader.flags&MAP_HEIGHT_NO_HIGHT))
{
if (heightHeader.flags&MAP_HEIGHT_AS_INT16)
{
fwrite(uint16_V9, sizeof(uint16_V9), 1, output);
fwrite(uint16_V8, sizeof(uint16_V8), 1, output);
}
else if (heightHeader.flags&MAP_HEIGHT_AS_INT8)
{
fwrite(uint8_V9, sizeof(uint8_V9), 1, output);
fwrite(uint8_V8, sizeof(uint8_V8), 1, output);
}
else
{
fwrite(V9, sizeof(V9), 1, output);
fwrite(V8, sizeof(V8), 1, output);
}
}
// Store liquid data if need
if (map.liquidMapOffset)
{
fwrite(&liquidHeader, sizeof(liquidHeader), 1, output);
if (!(liquidHeader.flags&MAP_LIQUID_NO_TYPE))
fwrite(liquid_type, sizeof(liquid_type), 1, output);
if (!(liquidHeader.flags&MAP_LIQUID_NO_HIGHT))
{
for (int y=0; y<liquidHeader.height;y++)
fwrite(&liquid_height[y+liquidHeader.offsetY][liquidHeader.offsetX], sizeof(float), liquidHeader.width, output);
}
}
fclose(output);
return true;
}
void ExtractMapsFromMpq()
{
char mpq_filename[1024];
char output_filename[1024];
char mpq_map_name[1024];
printf("Extracting maps...\n");
@@ -177,35 +805,41 @@ void ExtractMapsFromMpq()
ReadAreaTableDBC();
ReadLiquidTypeTableDBC();
unsigned int total = map_count * ADT_RES * ADT_RES;
unsigned int done = 0;
std::string path = output_path;
path += "/maps/";
CreateDir(path);
for(uint32 x = 0; x < ADT_RES; ++x)
{
for(uint32 y = 0; y < ADT_RES; ++y)
{
printf("Convert map files\n");
for(uint32 z = 0; z < map_count; ++z)
{
sprintf(mpq_filename, "World\\Maps\\%s\\%s_%u_%u.adt", map_ids[z].name, map_ids[z].name, x, y);
sprintf(output_filename, "%s/maps/%03u%02u%02u.map", output_path, map_ids[z].id, y, x);
ConvertADT(mpq_filename, output_filename);
done++;
}
// draw progress bar
printf("Processing........................%d%%\r", (100 * done) / total);
}
printf("Extract %s (%d/%d) \n", map_ids[z].name, z, map_count);
// Loadup map grid data
sprintf(mpq_map_name, "World\\Maps\\%s\\%s.wdt", map_ids[z].name, map_ids[z].name);
WDT_file wdt;
if (!wdt.loadFile(mpq_map_name))
{
// printf("Error loading %s map wdt data\n", map_ids[z].name);
continue;
}
for(uint32 y = 0; y < WDT_MAP_SIZE; ++y)
{
for(uint32 x = 0; x < WDT_MAP_SIZE; ++x)
{
if (!wdt.main->adt_list[y][x].exist)
continue;
sprintf(mpq_filename, "World\\Maps\\%s\\%s_%u_%u.adt", map_ids[z].name, map_ids[z].name, x, y);
sprintf(output_filename, "%s/maps/%03u%02u%02u.map", output_path, map_ids[z].id, y, x);
ConvertADT(mpq_filename, output_filename, y, x);
}
// draw progress bar
printf("Processing........................%d%%\r", (100 * (y+1)) / WDT_MAP_SIZE);
}
}
delete [] areas;
delete [] map_ids;
}
//bool WMO(char* filename);
void ExtractDBCFiles(int locale, bool basicLocale)
{
printf("Extracting dbc files...\n");
@@ -277,21 +911,10 @@ void LoadLocaleMPQFiles(int const locale)
void LoadCommonMPQFiles()
{
char filename[512];
sprintf(filename,"%s/Data/common-2.MPQ", input_path);
new MPQArchive(filename);
sprintf(filename,"%s/Data/lichking.MPQ", input_path);
new MPQArchive(filename);
sprintf(filename,"%s/Data/expansion.MPQ", input_path);
new MPQArchive(filename);
for(int i = 1; i < 5; ++i)
int count = sizeof(CONF_mpq_list)/sizeof(char*);
for(int i = 0; i < count; ++i)
{
char ext[3] = "";
if(i > 1)
sprintf(ext, "-%i", i);
sprintf(filename, "%s/Data/patch%s.MPQ", input_path, ext);
sprintf(filename, "%s/Data/%s", input_path, CONF_mpq_list[i]);
if(FileExists(filename))
new MPQArchive(filename);
}
@@ -323,7 +946,7 @@ int main(int argc, char * arg[])
//Open MPQs
LoadLocaleMPQFiles(i);
if((extract & EXTRACT_DBC) == 0)
if((CONF_extract & EXTRACT_DBC) == 0)
{
FirstLocale = i;
break;
@@ -349,7 +972,7 @@ int main(int argc, char * arg[])
return 0;
}
if (extract & EXTRACT_MAP)
if (CONF_extract & EXTRACT_MAP)
{
printf("Using locale: %s\n", langs[FirstLocale]);
+9 -1
View File
@@ -213,7 +213,15 @@
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath=".\adt.cpp"
RelativePath=".\loadlib\loadlib.cpp"
>
</File>
<File
RelativePath=".\loadlib\adt.cpp"
>
</File>
<File
RelativePath=".\loadlib\wdt.cpp"
>
</File>
<File
+9 -1
View File
@@ -218,13 +218,17 @@
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath=".\adt.cpp"
RelativePath=".\loadlib\adt.cpp"
>
</File>
<File
RelativePath=".\dbcfile.cpp"
>
</File>
<File
RelativePath=".\loadlib\loadlib.cpp"
>
</File>
<File
RelativePath=".\mpq_libmpq.cpp"
>
@@ -253,6 +257,10 @@
/>
</FileConfiguration>
</File>
<File
RelativePath=".\loadlib\wdt.cpp"
>
</File>
<Filter
Name="libmpq"
>
+9 -1
View File
@@ -216,7 +216,15 @@
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath=".\adt.cpp"
RelativePath=".\loadlib\loadlib.cpp"
>
</File>
<File
RelativePath=".\loadlib\adt.cpp"
>
</File>
<File
RelativePath=".\loadlib\wdt.cpp"
>
</File>
<File
Binary file not shown.
+1 -1
View File
@@ -4,6 +4,7 @@
#ifndef MPQ_H
#define MPQ_H
#include "loadlib/loadlib.h"
#include "libmpq/mpq.h"
#include <string.h>
#include <ctype.h>
@@ -13,7 +14,6 @@
using namespace std;
typedef unsigned int uint32;
class MPQArchive
{
+507 -128
View File
@@ -43,9 +43,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()
@@ -68,9 +65,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;
@@ -80,7 +77,6 @@ bool Map::ExistMap(uint32 mapid,int x,int y)
delete [] tmp;
fclose(pf);
return true;
}
@@ -159,29 +155,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;
}
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;
sLog.outError("Error load map file: \n %s\n", tmp);
}
delete [] tmp;
GridMap * buf= new GridMap;
fread(buf,1,sizeof(GridMap),pf);
fclose(pf);
GridMaps[x][y] = buf;
return;
}
void Map::LoadMapAndVMap(uint32 mapid, uint32 instanceid, int x,int y)
@@ -1141,7 +1121,11 @@ bool Map::UnloadGrid(const uint32 &x, const uint32 &y, bool unloadAll)
{
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);
}
@@ -1166,33 +1150,212 @@ void Map::UnloadAll()
}
}
float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const
//*****************************
// Grid function
//*****************************
GridMap::GridMap()
{
GridPair p = Trinity::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;
}
// half opt method
int gx=(int)(32-x/SIZE_OF_GRIDS); //grid x
int gy=(int)(32-y/SIZE_OF_GRIDS); //grid y
GridMap::~GridMap()
{
unloadData();
}
float lx=MAP_RESOLUTION*(32 -x/SIZE_OF_GRIDS - gx);
float ly=MAP_RESOLUTION*(32 -y/SIZE_OF_GRIDS - gy);
bool GridMap::loadData(char *filename)
{
// Unload old data if exist
unloadData();
// ensure GridMap is loaded
const_cast<Map*>(this)->EnsureGridCreated(GridPair(63-gx,63-gy));
// find raw .map surface under Z coordinates
float mapHeight;
if(GridMap* gmap = GridMaps[gx][gy])
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)
{
int lx_int = (int)lx;
int ly_int = (int)ly;
// 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;
}
// In some very rare case this will happen. Need find a better way.
//if(lx_int == MAP_RESOLUTION) --lx_int;
//if(ly_int == MAP_RESOLUTION) --ly_int;
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;
}
lx -= lx_int;
ly -= ly_int;
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
@@ -1207,18 +1370,18 @@ float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const
// 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 (x+y < 1)
{
if (lx > ly)
if (x > y)
{
// 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];
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;
@@ -1226,9 +1389,9 @@ float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const
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];
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;
@@ -1236,12 +1399,12 @@ float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const
}
else
{
if (lx > ly)
if (x > y)
{
// 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];
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;
@@ -1249,16 +1412,265 @@ float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const
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];
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
float _mapheight = a * lx + b * ly + c;
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
// ensure GridMap is loaded
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 = const_cast<Map*>(this)->GetGrid(x, y))
{
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)
@@ -1337,25 +1749,9 @@ float Map::GetVmapHeight(float x, float y, float z, bool useMaps) const
uint16 Map::GetAreaFlag(float x, float y, float z) const
{
//local x,y coords
float lx,ly;
int gx,gy;
GridPair p = Trinity::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);
@@ -1386,44 +1782,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;
}
@@ -1450,24 +1826,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)
// 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;
float water_z = GetWaterLevel(x,y);
uint8 flag = GetTerrainType(x,y);
return (z < (water_z-2)) && (flag & 0x01);
}
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
+131 -7
View File
@@ -70,14 +70,135 @@ typedef RGuard<GridRWLock, ZThread::Lockable> GridReadGuard;
typedef WGuard<GridRWLock, ZThread::Lockable> GridWriteGuard;
typedef Trinity::SingleThreaded<GridRWLock>::Lock NullGuard;
typedef struct
//******************************************
// Map file format defines
//******************************************
#define MAP_MAGIC 'SPAM'
#define MAP_VERSION_MAGIC '0.1v'
#define MAP_AREA_MAGIC 'AERA'
#define MAP_HEIGTH_MAGIC 'TGHM'
#define MAP_LIQUID_MAGIC 'QILM'
struct map_fileheader{
uint32 mapMagic;
uint32 versionMagic;
uint32 areaMapOffset;
uint32 areaMapSize;
uint32 heightMapOffset;
uint32 heightMapSize;
uint32 liquidMapOffset;
uint32 liquidMapSize;
};
#define MAP_AREA_NO_AREA 0x0001
struct map_areaHeader{
uint32 fourcc;
uint16 flags;
uint16 gridArea;
};
#define MAP_HEIGHT_NO_HIGHT 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_HIGHT 0x0002
struct map_liquidHeader{
uint32 fourcc;
uint16 flags;
uint16 liquidType;
uint8 offsetX;
uint8 offsetY;
uint8 width;
uint8 height;
float liquidLevel;
};
enum ZLiquidStatus{
LIQUID_MAP_NO_WATER = 0x00000000,
LIQUID_MAP_ABOVE_WATER = 0x00000001,
LIQUID_MAP_WATER_WALK = 0x00000002,
LIQUID_MAP_IN_WATER = 0x00000004,
LIQUID_MAP_UNDER_WATER = 0x00000008
};
#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_ALL_LIQUIDS (MAP_LIQUID_TYPE_WATER | MAP_LIQUID_TYPE_OCEAN | MAP_LIQUID_TYPE_MAGMA | MAP_LIQUID_TYPE_SLIME)
#define MAP_LIQUID_TYPE_DARK_WATER 0x10
#define MAP_LIQUID_TYPE_WMO_WATER 0x20
struct LiquidData{
uint32 type;
float level;
float depth_level;
};
class GridMap
{
uint16 area_flag[16][16];
uint8 terrain_type[16][16];
float liquid_level[128][128];
float v9[MAP_RESOLUTION + 1][MAP_RESOLUTION + 1];
float v8[MAP_RESOLUTION][MAP_RESOLUTION];
}GridMap;
uint32 m_flags;
// Area data
uint16 m_gridArea;
uint16 *m_area_map;
// Height level data
float m_gridHeight;
float m_gridIntHeightMultiplier;
union{
float *m_V9;
uint16 *m_uint16_V9;
uint8 *m_uint8_V9;
};
union{
float *m_V8;
uint16 *m_uint16_V8;
uint8 *m_uint8_V8;
};
// Liquid data
uint16 m_liquidType;
uint8 m_liquid_offX;
uint8 m_liquid_offY;
uint8 m_liquid_width;
uint8 m_liquid_height;
float m_liquidLevel;
uint8 *m_liquid_type;
float *m_liquid_map;
bool loadAreaData(FILE *in, uint32 offset, uint32 size);
bool loadHeihgtData(FILE *in, uint32 offset, uint32 size);
bool loadLiquidData(FILE *in, uint32 offset, uint32 size);
// Get height functions and pointers
typedef float (GridMap::*pGetHeightPtr) (float x, float y) const;
pGetHeightPtr m_gridGetHeight;
float getHeightFromFloat(float x, float y) const;
float getHeightFromUint16(float x, float y) const;
float getHeightFromUint8(float x, float y) const;
float getHeightFromFlat(float x, float y) const;
public:
GridMap();
~GridMap();
bool loadData(char *filaname);
void unloadData();
uint16 getArea(float x, float y);
inline float getHeight(float x, float y) {return (this->*m_gridGetHeight)(x, y);}
float getLiquidLevel(float x, float y);
uint8 getTerrainType(float x, float y);
ZLiquidStatus getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData *data = 0);
};
struct CreatureMover
{
@@ -192,6 +313,8 @@ class TRINITY_DLL_SPEC Map : public GridRefManager<NGridType>, public Trinity::O
float GetVmapHeight(float x, float y, float z, bool useMaps) const;
bool IsInWater(float x, float y, float z) const; // does not use z pos. This is for future use
ZLiquidStatus getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData *data = 0) const;
uint16 GetAreaFlag(float x, float y, float z) const;
uint8 GetTerrainType(float x, float y ) const;
float GetWaterLevel(float x, float y ) const;
@@ -288,6 +411,7 @@ class TRINITY_DLL_SPEC Map : public GridRefManager<NGridType>, public Trinity::O
private:
void LoadVMap(int pX, int pY);
void LoadMap(uint32 mapid, uint32 instanceid, int x,int y);
GridMap *GetGrid(float x, float y);
void SetTimer(uint32 t) { i_gridExpiry = t < MIN_GRID_DELAY ? MIN_GRID_DELAY : t; }
//uint64 CalculateGridMask(const uint32 &y) const;
+197 -126
View File
@@ -355,8 +355,11 @@ Player::Player (WorldSession *session): Unit(), m_achievementMgr(this)
m_regenTimer = 0;
m_weaponChangeTimer = 0;
m_breathTimer = 0;
m_isunderwater = UNDERWATER_NONE;
for (int i=0; i<MAX_TIMERS; i++)
m_MirrorTimer[i] = DISABLED_MIRROR_TIMER;
m_MirrorTimerFlags = UNDERWATER_NONE;
m_MirrorTimerFlagsLast = UNDERWATER_NONE;
m_isInWater = false;
m_drunkTimer = 0;
m_drunk = 0;
@@ -856,25 +859,14 @@ bool Player::StoreNewItemInBestSlots(uint32 titem_id, uint32 titem_amount)
return false;
}
void Player::StartMirrorTimer(MirrorTimerType Type, uint32 MaxValue)
void Player::SendMirrorTimer(MirrorTimerType Type, uint32 MaxValue, uint32 CurrentValue, int32 Regen)
{
uint32 BreathRegen = (uint32)-1;
WorldPacket data(SMSG_START_MIRROR_TIMER, (21));
data << (uint32)Type;
data << MaxValue;
data << MaxValue;
data << BreathRegen;
data << (uint8)0;
data << (uint32)0; // spell id
GetSession()->SendPacket(&data);
}
void Player::ModifyMirrorTimer(MirrorTimerType Type, uint32 MaxValue, uint32 CurrentValue, uint32 Regen)
{
if(Type==BREATH_TIMER)
m_breathTimer = ((MaxValue + 1*IN_MILISECONDS) - CurrentValue) / Regen;
if (MaxValue == DISABLED_MIRROR_TIMER)
{
if (CurrentValue!=DISABLED_MIRROR_TIMER)
StopMirrorTimer(Type);
return;
}
WorldPacket data(SMSG_START_MIRROR_TIMER, (21));
data << (uint32)Type;
data << CurrentValue;
@@ -887,9 +879,7 @@ void Player::ModifyMirrorTimer(MirrorTimerType Type, uint32 MaxValue, uint32 Cur
void Player::StopMirrorTimer(MirrorTimerType Type)
{
if(Type==BREATH_TIMER)
m_breathTimer = 0;
m_MirrorTimer[Type] = DISABLED_MIRROR_TIMER;
WorldPacket data(SMSG_STOP_MIRROR_TIMER, 4);
data << (uint32)Type;
GetSession()->SendPacket( &data );
@@ -900,12 +890,22 @@ void Player::EnvironmentalDamage(uint64 guid, EnviromentalDamage type, uint32 da
if(!isAlive() || isGameMaster())
return;
// Absorb, resist some environmental damage type
uint32 absorb = 0;
uint32 resist = 0;
if (type == DAMAGE_LAVA)
CalcAbsorbResist(this, SPELL_SCHOOL_MASK_FIRE, DIRECT_DAMAGE, damage, &absorb, &resist);
else if (type == DAMAGE_SLIME)
CalcAbsorbResist(this, SPELL_SCHOOL_MASK_NATURE, DIRECT_DAMAGE, damage, &absorb, &resist);
damage-=absorb+resist;
WorldPacket data(SMSG_ENVIRONMENTALDAMAGELOG, (21));
data << (uint64)guid;
data << (uint8)(type!=DAMAGE_FALL_TO_VOID ? type : DAMAGE_FALL);
data << (uint32)damage;
data << (uint32)0;
data << (uint32)0;
data << (uint32)absorb; // absorb
data << (uint32)resist; // resist
SendMessageToSet(&data, true);
DealDamage(this, damage, NULL, SELF_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
@@ -925,96 +925,153 @@ void Player::EnvironmentalDamage(uint64 guid, EnviromentalDamage type, uint32 da
}
}
void Player::HandleDrowning()
int32 Player::getMaxTimer(MirrorTimerType timer)
{
if(!(m_isunderwater&~UNDERWATER_INLAVA))
return;
//if player is GM, have waterbreath, is dead or if breathing is disabled then return
if(isGameMaster() || !isAlive() || HasAuraType(SPELL_AURA_WATER_BREATHING) || GetSession()->GetSecurity() >= sWorld.getConfig(CONFIG_DISABLE_BREATHING))
switch (timer)
{
StopMirrorTimer(BREATH_TIMER);
// drop every flag _except_ LAVA - otherwise waterbreathing will prevent lava damage
m_isunderwater &= UNDERWATER_INLAVA;
return;
}
uint32 UnderWaterTime = 3*MINUTE*IN_MILISECONDS; // default duration
case FATIGUE_TIMER:
return MINUTE*IN_MILISECONDS;
case BREATH_TIMER:
{
if (!isAlive() || HasAuraType(SPELL_AURA_WATER_BREATHING) || GetSession()->GetSecurity() >= sWorld.getConfig(CONFIG_DISABLE_BREATHING))
return DISABLED_MIRROR_TIMER;
int32 UnderWaterTime = 3*MINUTE*IN_MILISECONDS;
AuraList const& mModWaterBreathing = GetAurasByType(SPELL_AURA_MOD_WATER_BREATHING);
for(AuraList::const_iterator i = mModWaterBreathing.begin(); i != mModWaterBreathing.end(); ++i)
UnderWaterTime = uint32(UnderWaterTime * (100.0f + (*i)->GetModifier()->m_amount) / 100.0f);
if ((m_isunderwater & UNDERWATER_INWATER) && !(m_isunderwater & UNDERWATER_INLAVA) && isAlive())
{
//single trigger timer
if (!(m_isunderwater & UNDERWATER_WATER_TRIGGER))
{
m_isunderwater|= UNDERWATER_WATER_TRIGGER;
m_breathTimer = UnderWaterTime + 1*IN_MILISECONDS;
return UnderWaterTime;
}
//single trigger "show Breathbar"
if ( m_breathTimer <= UnderWaterTime && !(m_isunderwater & UNDERWATER_WATER_BREATHB))
case FIRE_TIMER:
{
m_isunderwater|= UNDERWATER_WATER_BREATHB;
StartMirrorTimer(BREATH_TIMER, UnderWaterTime);
if (!isAlive())
return DISABLED_MIRROR_TIMER;
return 1*IN_MILISECONDS;
}
//continuous trigger drowning "Damage"
if ((m_breathTimer == 0) && (m_isunderwater & UNDERWATER_INWATER))
{
//TODO: Check this formula
uint64 guid = GetGUID();
uint32 damage = GetMaxHealth() / 5 + urand(0, getLevel()-1);
EnvironmentalDamage(guid, DAMAGE_DROWNING,damage);
m_breathTimer = 2000;
}
}
//single trigger retract bar
else if (!(m_isunderwater & UNDERWATER_INWATER) && (m_isunderwater & UNDERWATER_WATER_TRIGGER) && (m_breathTimer > 0) && isAlive())
{
uint32 BreathRegen = 10;
// m_breathTimer will be reduced in ModifyMirrorTimer
ModifyMirrorTimer(BREATH_TIMER, UnderWaterTime, m_breathTimer,BreathRegen);
m_isunderwater = UNDERWATER_WATER_BREATHB_RETRACTING;
}
//remove bar
else if ((m_breathTimer < 50) && !(m_isunderwater & UNDERWATER_INWATER) && (m_isunderwater == UNDERWATER_WATER_BREATHB_RETRACTING))
{
StopMirrorTimer(BREATH_TIMER);
m_isunderwater = UNDERWATER_NONE;
default:
return 0;
}
return 0;
}
void Player::HandleLava()
void Player::UpdateMirrorTimers()
{
if ((m_isunderwater & UNDERWATER_INLAVA) && isAlive())
{
/*
* arrai: how is this supposed to work? UNDERWATER_INLAVA is always set in this scope!
// Single trigger Set BreathTimer
if (!(m_isunderwater & UNDERWATER_INLAVA))
{
m_isunderwater|= UNDERWATER_WATER_BREATHB;
m_breathTimer = 1*IN_MILISECONDS;
}
*/
// Reset BreathTimer and still in the lava
if (!m_breathTimer)
{
uint64 guid = GetGUID();
uint32 damage = urand(600, 700); // TODO: Get more detailed information about lava damage
// Desync flags for update on next HandleDrowning
if (m_MirrorTimerFlags)
m_MirrorTimerFlagsLast = ~m_MirrorTimerFlags;
}
EnvironmentalDamage(guid, DAMAGE_LAVA, damage);
void Player::HandleDrowning(uint32 time_diff)
{
if (!m_MirrorTimerFlags)
return;
m_breathTimer = 1*IN_MILISECONDS;
}
}
else if (!isAlive()) // Disable breath timer and reset underwater flags
// In water
if (m_MirrorTimerFlags & UNDERWATER_INWATER)
{
m_breathTimer = 0;
m_isunderwater = UNDERWATER_NONE;
// Breath timer not activated - activate it
if (m_MirrorTimer[BREATH_TIMER] == DISABLED_MIRROR_TIMER)
{
m_MirrorTimer[BREATH_TIMER] = getMaxTimer(BREATH_TIMER);
SendMirrorTimer(BREATH_TIMER, m_MirrorTimer[BREATH_TIMER], m_MirrorTimer[BREATH_TIMER], -1);
}
else // If activated - do tick
{
m_MirrorTimer[BREATH_TIMER]-=time_diff;
// Timer limit - need deal damage
if (m_MirrorTimer[BREATH_TIMER] < 0)
{
m_MirrorTimer[BREATH_TIMER]+= 1*IN_MILISECONDS;
// Calculate and deal damage
// TODO: Check this formula
uint32 damage = GetMaxHealth() / 5 + urand(0, getLevel()-1);
EnvironmentalDamage(GetGUID(), DAMAGE_DROWNING, damage);
}
else if (!(m_MirrorTimerFlagsLast & UNDERWATER_INWATER)) // Update time in client if need
SendMirrorTimer(BREATH_TIMER, getMaxTimer(BREATH_TIMER), m_MirrorTimer[BREATH_TIMER], -1);
}
}
else if (m_MirrorTimer[BREATH_TIMER] != DISABLED_MIRROR_TIMER) // Regen timer
{
int32 UnderWaterTime = getMaxTimer(BREATH_TIMER);
// Need breath regen
m_MirrorTimer[BREATH_TIMER]+=10*time_diff;
if (m_MirrorTimer[BREATH_TIMER] >= UnderWaterTime || !isAlive())
StopMirrorTimer(BREATH_TIMER);
else if (m_MirrorTimerFlagsLast & UNDERWATER_INWATER)
SendMirrorTimer(BREATH_TIMER, UnderWaterTime, m_MirrorTimer[BREATH_TIMER], 10);
}
// In dark water
if (m_MirrorTimerFlags & UNDERWARER_INDARKWATER)
{
// Fatigue timer not activated - activate it
if (m_MirrorTimer[FATIGUE_TIMER] == DISABLED_MIRROR_TIMER)
{
m_MirrorTimer[FATIGUE_TIMER] = getMaxTimer(FATIGUE_TIMER);
SendMirrorTimer(FATIGUE_TIMER, m_MirrorTimer[FATIGUE_TIMER], m_MirrorTimer[FATIGUE_TIMER], -1);
}
else
{
m_MirrorTimer[FATIGUE_TIMER]-=time_diff;
// Timer limit - need deal damage or teleport ghost to graveyard
if (m_MirrorTimer[FATIGUE_TIMER] < 0)
{
m_MirrorTimer[FATIGUE_TIMER]+= 1*IN_MILISECONDS;
if (isAlive()) // Calculate and deal damage
{
uint32 damage = GetMaxHealth() / 5 + urand(0, getLevel()-1);
EnvironmentalDamage(GetGUID(), DAMAGE_EXHAUSTED, damage);
}
else if (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST)) // Teleport ghost to graveyard
RepopAtGraveyard();
}
else if (!(m_MirrorTimerFlagsLast & UNDERWARER_INDARKWATER))
SendMirrorTimer(FATIGUE_TIMER, getMaxTimer(FATIGUE_TIMER), m_MirrorTimer[FATIGUE_TIMER], -1);
}
}
else if (m_MirrorTimer[FATIGUE_TIMER] != DISABLED_MIRROR_TIMER) // Regen timer
{
int32 DarkWaterTime = getMaxTimer(FATIGUE_TIMER);
m_MirrorTimer[FATIGUE_TIMER]+=10*time_diff;
if (m_MirrorTimer[FATIGUE_TIMER] >= DarkWaterTime || !isAlive())
StopMirrorTimer(FATIGUE_TIMER);
else if (m_MirrorTimerFlagsLast & UNDERWARER_INDARKWATER)
SendMirrorTimer(FATIGUE_TIMER, DarkWaterTime, m_MirrorTimer[FATIGUE_TIMER], 10);
}
if (m_MirrorTimerFlags & (UNDERWATER_INLAVA|UNDERWATER_INSLIME))
{
// Breath timer not activated - activate it
if (m_MirrorTimer[FIRE_TIMER] == DISABLED_MIRROR_TIMER)
m_MirrorTimer[FIRE_TIMER] = getMaxTimer(FIRE_TIMER);
else
{
m_MirrorTimer[FIRE_TIMER]-=time_diff;
if (m_MirrorTimer[FIRE_TIMER] < 0)
{
m_MirrorTimer[FIRE_TIMER]+= 1*IN_MILISECONDS;
// Calculate and deal damage
// TODO: Check this formula
uint32 damage = urand(600, 700);
if (m_MirrorTimerFlags&UNDERWATER_INLAVA)
EnvironmentalDamage(GetGUID(), DAMAGE_LAVA, damage);
else
EnvironmentalDamage(GetGUID(), DAMAGE_SLIME, damage);
}
}
}
else
m_MirrorTimer[FIRE_TIMER] = DISABLED_MIRROR_TIMER;
// Recheck timers flag
m_MirrorTimerFlags&=~UNDERWATER_EXIST_TIMERS;
for (int i = 0; i< MAX_TIMERS; ++i)
if (m_MirrorTimer[i]!=DISABLED_MIRROR_TIMER)
{
m_MirrorTimerFlags|=UNDERWATER_EXIST_TIMERS;
break;
}
m_MirrorTimerFlagsLast = m_MirrorTimerFlags;
}
///The player sobers by 256 every 10 seconds
@@ -1279,21 +1336,8 @@ void Player::Update( uint32 p_time )
}
}
//Breathtimer
if(m_breathTimer > 0)
{
if(p_time >= m_breathTimer)
m_breathTimer = 0;
else
m_breathTimer -= p_time;
}
//Handle Water/drowning
HandleDrowning();
//Handle lava
HandleLava();
HandleDrowning(p_time);
//Handle detect stealth players
if (m_DetectInvTimer > 0)
@@ -19983,21 +20027,48 @@ PartyResult Player::CanUninviteFromGroup() const
void Player::UpdateUnderwaterState( Map* m, float x, float y, float z )
{
float water_z = m->GetWaterLevel(x,y);
float terrain_z = m->GetHeight(x,y,z, false); // use .map base surface height
uint8 flag1 = m->GetTerrainType(x,y);
LiquidData liquid_status;
ZLiquidStatus res = m->getLiquidStatus(x, y, z, MAP_ALL_LIQUIDS, &liquid_status);
if (!res)
{
m_MirrorTimerFlags &= ~(UNDERWATER_INWATER|UNDERWATER_INLAVA|UNDERWATER_INSLIME|UNDERWARER_INDARKWATER);
// Small hack for enable breath in WMO
if (IsInWater())
m_MirrorTimerFlags|=UNDERWATER_INWATER;
return;
}
//!Underwater check, not in water if underground or above water level - take UC royal quater for example
if (terrain_z <= INVALID_HEIGHT || z < (terrain_z-2) || z > (water_z - 2) )
m_isunderwater &= ~UNDERWATER_INWATER;
else if ((z < (water_z - 2)) && (flag1 & 0x01))
m_isunderwater |= UNDERWATER_INWATER;
//!in lava check, anywhere under lava level
if ((terrain_z <= INVALID_HEIGHT || z < (terrain_z - 0)) && (flag1 == 0x00) && IsInWater())
m_isunderwater |= UNDERWATER_INLAVA;
// All liquids type - check under water position
if (liquid_status.type&(MAP_LIQUID_TYPE_WATER|MAP_LIQUID_TYPE_OCEAN|MAP_LIQUID_TYPE_MAGMA|MAP_LIQUID_TYPE_SLIME))
{
if ( res & LIQUID_MAP_UNDER_WATER)
m_MirrorTimerFlags |= UNDERWATER_INWATER;
else
m_isunderwater &= ~UNDERWATER_INLAVA;
m_MirrorTimerFlags &= ~UNDERWATER_INWATER;
}
// Allow travel in dark water on taxi or transport
if (liquid_status.type & MAP_LIQUID_TYPE_DARK_WATER && !isInFlight() && !(GetUnitMovementFlags()&MOVEMENTFLAG_ONTRANSPORT))
m_MirrorTimerFlags |= UNDERWARER_INDARKWATER;
else
m_MirrorTimerFlags &= ~UNDERWARER_INDARKWATER;
// in lava check, anywhere in lava level
if (liquid_status.type&MAP_LIQUID_TYPE_MAGMA)
{
if (res & (LIQUID_MAP_UNDER_WATER|LIQUID_MAP_IN_WATER|LIQUID_MAP_WATER_WALK))
m_MirrorTimerFlags |= UNDERWATER_INLAVA;
else
m_MirrorTimerFlags &= ~UNDERWATER_INLAVA;
}
// in slime check, anywhere in slime level
if (liquid_status.type&MAP_LIQUID_TYPE_SLIME)
{
if (res & (LIQUID_MAP_UNDER_WATER|LIQUID_MAP_IN_WATER|LIQUID_MAP_WATER_WALK))
m_MirrorTimerFlags |= UNDERWATER_INSLIME;
else
m_MirrorTimerFlags &= ~UNDERWATER_INSLIME;
}
}
void Player::SetCanParry( bool value )
+14 -10
View File
@@ -72,10 +72,11 @@ enum PlayerUnderwaterState
{
UNDERWATER_NONE = 0x00,
UNDERWATER_INWATER = 0x01, // terrain type is water and player is afflicted by it
UNDERWATER_WATER_TRIGGER = 0x02, // m_breathTimer has been initialized
UNDERWATER_WATER_BREATHB = 0x04, // breathbar has been send to client
UNDERWATER_WATER_BREATHB_RETRACTING = 0x10, // breathbar is currently refilling - the player is above water level
UNDERWATER_INLAVA = 0x80 // terrain type is lava and player is afflicted by it
UNDERWATER_INLAVA = 0x02, // terrain type is lava and player is afflicted by it
UNDERWATER_INSLIME = 0x04, // terrain type is lava and player is afflicted by it
UNDERWARER_INDARKWATER = 0x08, // terrain type is dark water and player is afflicted by it
UNDERWATER_EXIST_TIMERS = 0x10
};
enum PlayerSpellState
@@ -501,6 +502,8 @@ enum MirrorTimerType
BREATH_TIMER = 1,
FIRE_TIMER = 2
};
#define MAX_TIMERS 3
#define DISABLED_MIRROR_TIMER -1
// 2^n values
enum PlayerExtraFlags
@@ -1722,6 +1725,7 @@ class TRINITY_DLL_SPEC Player : public Unit
uint32 DurabilityRepairAll(bool cost, float discountMod, bool guildBank);
uint32 DurabilityRepair(uint16 pos, bool cost, float discountMod, bool guildBank);
void UpdateMirrorTimers();
void StopMirrorTimers()
{
StopMirrorTimer(FATIGUE_TIMER);
@@ -2040,7 +2044,6 @@ class TRINITY_DLL_SPEC Player : public Unit
bool IsFlying() const { return HasUnitMovementFlag(MOVEMENTFLAG_FLYING); }
bool IsAllowUseFlyMountsHere() const;
void HandleDrowning();
void HandleFallUnderMap();
void SetClientControl(Unit* target, uint8 allowMove);
@@ -2268,12 +2271,14 @@ class TRINITY_DLL_SPEC Player : public Unit
/*********************************************************/
/*** ENVIRONMENTAL SYSTEM ***/
/*********************************************************/
void HandleLava();
void HandleSobering();
void StartMirrorTimer(MirrorTimerType Type, uint32 MaxValue);
void ModifyMirrorTimer(MirrorTimerType Type, uint32 MaxValue, uint32 CurrentValue, uint32 Regen);
void SendMirrorTimer(MirrorTimerType Type, uint32 MaxValue, uint32 CurrentValue, int32 Regen);
void StopMirrorTimer(MirrorTimerType Type);
uint8 m_isunderwater;
void HandleDrowning(uint32 time_diff);
int32 getMaxTimer(MirrorTimerType timer);
int32 m_MirrorTimer[MAX_TIMERS];
uint8 m_MirrorTimerFlags;
uint8 m_MirrorTimerFlagsLast;
bool m_isInWater;
/*********************************************************/
@@ -2357,7 +2362,6 @@ class TRINITY_DLL_SPEC Player : public Unit
bool m_DailyQuestChanged;
time_t m_lastDailyQuestTime;
uint32 m_breathTimer;
uint32 m_drunkTimer;
uint16 m_drunk;
uint32 m_weaponChangeTimer;
+3 -9
View File
@@ -2343,15 +2343,9 @@ void Aura::HandleAuraHover(bool apply, bool Real)
void Aura::HandleWaterBreathing(bool apply, bool Real)
{
if(!apply && !m_target->HasAuraType(SPELL_AURA_WATER_BREATHING))
{
// update for enable timer in case not moving target
if(m_target->GetTypeId()==TYPEID_PLAYER && m_target->IsInWorld())
{
((Player*)m_target)->UpdateUnderwaterState(m_target->GetMap(),m_target->GetPositionX(),m_target->GetPositionY(),m_target->GetPositionZ());
((Player*)m_target)->HandleDrowning();
}
}
// update timers in client
if(m_target->GetTypeId()==TYPEID_PLAYER)
((Player*)m_target)->UpdateMirrorTimers();
}
void Aura::HandleAuraModShapeshift(bool apply, bool Real)
+1 -1
View File
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "7427"
#define REVISION_NR "7428"
#endif // __REVISION_NR_H__