[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:
DiSlord 2009-03-09 19:37:12 +03:00
parent 95379309e5
commit 6a90d60327
22 changed files with 2280 additions and 877 deletions

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)

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)
printf("Convert map files\n");
for(uint32 z = 0; z < map_count; ++z)
{
for(uint32 y = 0; y < ADT_RES; ++y)
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))
{
for(uint32 z = 0; z < map_count; ++z)
// 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);
done++;
ConvertADT(mpq_filename, output_filename, y, x);
}
// draw progress bar
printf("Processing........................%d%%\r", (100 * done) / total);
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]);

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

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"
>

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.

View file

@ -1,380 +0,0 @@
#define _CRT_SECURE_NO_DEPRECATE
#ifdef WIN32
#include <windows.h>
#endif
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <string>
#include <map>
#include <vector>
#include <set>
#include "adt.h"
#include "mpq_libmpq.h"
extern uint16 *areas;
extern uint16 *LiqType;
extern uint32 maxAreaId;
vec wmoc;
Cell *cell;
mcell *mcells;
int holetab_h[4] = {0x1111, 0x2222, 0x4444, 0x8888};
int holetab_v[4] = {0x000F, 0x00F0, 0x0F00, 0xF000};
bool LoadADT(char* filename)
{
size_t size;
MPQFile mf(filename);
if(mf.isEof())
{
//printf("No such file %s\n", filename);
return false;
}
MapLiqFlag = new uint8[256];
for(uint32 j = 0; j < 256; ++j)
MapLiqFlag[j] = 0; // no water
MapLiqHeight = new float[16384];
for(uint32 j = 0; j < 16384; ++j)
MapLiqHeight[j] = -999999; // no water
mcells = new mcell;
wmoc.x = 65 * TILESIZE;
wmoc.z = 65 * TILESIZE;
size_t mcnk_offsets[256], mcnk_sizes[256];
chunk_num = 0;
k = 0;
m = 0;
while (!mf.isEof())
{
uint32 fourcc;
mf.read(&fourcc, 4);
mf.read(&size, 4);
size_t nextpos = mf.getPos() + size;
//if(fourcc==0x4d484452) // MHDR header
//if(fourcc==0x4d564552) // MVER
if(fourcc == 0x4d43494e) // MCIN
{
for (uint32 i = 0; i < 256; ++i)
{
mf.read(&mcnk_offsets[i], 4);
mf.read(&mcnk_sizes[i], 4);
mf.seekRelative(8);
}
}
//if(fourcc == 0x4d544558) // MTEX textures (strings)
//if(fourcc == 0x4d4d4458) // MMDX m2 models (strings)
//if(fourcc == 0x4d4d4944) // MMID offsets for strings in MMDX
//if(fourcc == 0x4d574d4f) // MWMO
//if(fourcc == 0x4d574944) // MWID offsets for strings in MWMO
//if(fourcc == 0x4d444446) // MDDF
//if(fourcc == 0x4d4f4446) // MODF
if(fourcc == 0x4d48324f) // MH2O new in WotLK
{
// çäåñü íàäî çàïîìíèòü áàçîâóþ ïîçèöèþ â ôàéëå òê âñå ñìåùåíèÿ áóäóò îò íåãî
uint32 base_pos = mf.getPos();
uint32 header_pos = 0;
MH2O_offsData *LiqOffsData = new MH2O_offsData;
MH2O_Data1 *LiqChunkData1 = new MH2O_Data1;
float *ChunkLiqHeight = new float[81];
for(chunk_num = 0; chunk_num < 256; ++chunk_num)
{
mf.read(LiqOffsData, 0x0C);
header_pos = mf.getPos();
if(LiqOffsData->offsData1 != 0) // åñëè äàííûå â Data1 î âîäå åñòü, òî èõ íàäî êîíâåðòèðîâàòü
{
// ïåðåõîäèì ïî ñìåùåíèþ èç offsData1 ÎÒ ÍÀ×ÀËÀ êóñêà
mf.seek(base_pos + LiqOffsData->offsData1);
mf.read(LiqChunkData1, 0x18); // ñ÷èòûâàåì ñàìè äàííûå â ñòðóêòóðó òèïà MH2O_Data1
// çàíîñèì äàííûå ôëàãà äëÿ êóñêà
if(LiqType[LiqChunkData1->LiquidTypeId] == 0xffff)
printf("\nCan't find Liquid type for map %s\nchunk %d\n", filename, chunk_num);
else if(LiqType[LiqChunkData1->LiquidTypeId] == LIQUID_TYPE_WATER || LiqType[LiqChunkData1->LiquidTypeId] == LIQUID_TYPE_OCEAN)
MapLiqFlag[chunk_num] |= 1; // water/ocean
else if(LiqType[LiqChunkData1->LiquidTypeId] == LIQUID_TYPE_MAGMA || LiqType[LiqChunkData1->LiquidTypeId] == LIQUID_TYPE_SLIME)
MapLiqFlag[chunk_num] |= 2; // magma/slime
// ïðåäâàðèòåëüíî çàïîëíÿåì âåñü êóñîê äàííûìè - íåò âîäû
for(int j = 0; j < 81; ++j)
{
ChunkLiqHeight[j] = -999999; // no liquid/water
}
// òåïåðü âû÷èñëÿåì òå ÷òî ñ âîäîé è ïåðåçàïèñûâàåì èõ â êóñêå
for(int b = 0; b <= LiqChunkData1->height; ++b)
{
for(int c = LiqChunkData1->xOffset; c <= (LiqChunkData1->xOffset + LiqChunkData1->width); ++c)
{
int n = (9 * (LiqChunkData1->yOffset + b)) + c;
ChunkLiqHeight[n] = LiqChunkData1->heightLevel1;
}
}
mf.seek(header_pos); // è íå çàáûòü âåðíóòüñÿ íà èñõîäíóþ ïîçèöèþ èìåííî Â ÕÈÄÅÐÅ
}
else // åñëè äàííûõ â Data1 íåò, òî íàäî çàïîëíèòü âåñü êóñîê, íî äàííûìè - íåò âîäû
{
for(int j = 0; j < 81; ++j)
ChunkLiqHeight[j] = -999999; // no liquid/water
}
if(!(chunk_num % 16))
m = 1024 * (chunk_num / 16); // ñìåùåíèå ïî ðÿäàì êóñêîâ ñ ïåðåêðûòèåì = 1024
k = m + (chunk_num % 16) * 8; // óñòàíàâëèâàåìñÿ íà íà÷àëüíûé èíäåêñ äëÿ çàïîëíåíèÿ ðÿäà
// çàíîñèì äàííûå êóñêà â ìàññèâ äëÿ êàðòû, ñ ïåðåêðûòèåì è îáðåçàíèåì êóñêîâ òê äàííûõ 81
// ýòî àíàëîã ñòàðîãî îáðåçàíèÿ ãðàíè÷íûõ ïðàâûõ-áîêîâûõ è íèæíèõ äàííûõ
for(int p = 0; p < 72; p += 9) // íèæíèå 8 íå çàíîñèì òê îíè äóáëèðóåòñÿ ñëåä êóñêîì
{
for(int s = 0; s < 8; ++s) // 9 çíà÷åíèå â ñòðîêå íå çàíîñèì òê îíî äóáëèðóåòñÿ ñëåä êóñêîì, à â ïðàâûõ-áîêîâûõ îáðåçàåòñÿ äëÿ 128õ128
{
MapLiqHeight[k] = ChunkLiqHeight[p + s];
++k;
}
k = k + 120;
}
}
delete LiqOffsData;
delete LiqChunkData1;
delete []ChunkLiqHeight;
}
//case 0x4d434e4b: // MCNK
//case 0x4d46424f: // MFBO new in BC
//case 0x4d545846: // MTXF new in WotLK
mf.seek(nextpos);
}
//printf("Loading chunks info\n");
// read individual map chunks
chunk_num = 0;
k = 0;
m = 0;
for (int j = 0; j < 16; ++j)
{
for (int i = 0; i < 16; ++i)
{
mf.seek((int)mcnk_offsets[j * 16 + i]);
LoadMapChunk(mf, &(mcells->ch[i][j]));
++chunk_num;
}
}
mf.close();
return true;
}
bool isHole(int holes, int i, int j)
{
int testi = i / 2;
int testj = j / 4;
if(testi > 3) testi = 3;
if(testj > 3) testj = 3;
return (holes & holetab_h[testi] & holetab_v[testj]) != 0;
}
inline void LoadMapChunk(MPQFile &mf, chunk *_chunk)
{
float h;
uint32 fourcc;
uint32 size;
MapChunkHeader header;
mf.seekRelative(4);
mf.read(&size, 4);
size_t lastpos = mf.getPos() + size;
mf.read(&header, 0x80); // what if header size got changed?
_chunk->area_id = header.areaid;
float xbase = header.xpos;
float ybase = header.ypos;
float zbase = header.zpos;
zbase = TILESIZE * 32 - zbase;
xbase = TILESIZE * 32 - xbase;
if(wmoc.x > xbase) wmoc.x = xbase;
if(wmoc.z > zbase) wmoc.z = zbase;
int chunkflags = header.flags;
//printf("LMC: flags %X\n", chunkflags);
float zmin = 999999999.0f;
float zmax = -999999999.0f;
// must be there, bl!zz uses some crazy format
while (mf.getPos() < lastpos)
{
mf.read(&fourcc, 4);
mf.read(&size, 4);
size_t nextpos = mf.getPos() + size;
if(fourcc == 0x4d435654) // MCVT
{
for (int j = 0; j < 17; ++j)
{
for (int i = 0; i < ((j % 2) ? 8 : 9); ++i)
{
mf.read(&h, 4);
float z = h + ybase;
if (j % 2)
{
if(isHole(header.holes, i, j))
_chunk->v8[i][j / 2] = -1000;
else
_chunk->v8[i][j / 2] = z;
}
else
{
if(isHole(header.holes, i, j))
_chunk->v9[i][j / 2] = -1000;
else
_chunk->v9[i][j / 2] = z;
}
if(z > zmax) zmax = z;
//if(z < zmin) zmin = z;
}
}
}
else if(fourcc == 0x4d434e52) // MCNR
{
nextpos = mf.getPos() + 0x1C0; // size fix
}
else if(fourcc == 0x4d434c51) // íå áóäåì ó÷èòûâàòü åñëè óæå áûëè äàííûå â MH2O, ïåðåñòðàõîâêà :) // MCLQ
{
// liquid / water level
char fcc1[5];
mf.read(fcc1, 4);
flipcc(fcc1);
fcc1[4] = 0;
float *ChunkLiqHeight = new float[81];
if (!strcmp(fcc1, "MCSE"))
{
for(int j = 0; j < 81; ++j)
{
ChunkLiqHeight[j] = -999999; // no liquid/water
}
}
else
{
float maxheight;
mf.read(&maxheight, 4);
for(int j = 0; j < 81; ++j)
{
LiqData liq;
mf.read(&liq, 8);
if(liq.height > maxheight)
ChunkLiqHeight[j] = -999999;
else
ChunkLiqHeight[j] = h;
}
if(chunkflags & 4 || chunkflags & 8)
MapLiqFlag[chunk_num] |= 1; // water
if(chunkflags & 16)
MapLiqFlag[chunk_num] |= 2; // magma/slime
}
// çàïîëíåì òàê æå êàê â MH2O
if(!(chunk_num % 16))
m = 1024 * (chunk_num / 16);
k = m + (chunk_num % 16) * 8;
for(int p = 0; p < 72; p += 9)
{
for(int s = 0; s < 8; ++s)
{
MapLiqHeight[k] = ChunkLiqHeight[p + s];
++k;
}
k = k + 120;
}
delete []ChunkLiqHeight;
break;
}
mf.seek(nextpos);
}
}
inline void TransformData()
{
cell = new Cell;
for(uint32 x = 0; x < 128; ++x)
{
for(uint32 y = 0; y < 128; ++y)
{
cell->v8[y][x] = (float)mcells->ch[x / 8][y / 8].v8[x % 8][y % 8];
cell->v9[y][x] = (float)mcells->ch[x / 8][y / 8].v9[x % 8][y % 8];
}
// extra 1 point on bounds
cell->v9[128][x] = (float)mcells->ch[x / 8][15].v9[x % 8][8];
// x == y
cell->v9[x][128] = (float)mcells->ch[15][x / 8].v9[8][x % 8];
}
// and the last 1
cell->v9[128][128] = (float)mcells->ch[15][15].v9[8][8];
delete mcells;
}
const char MAP_MAGIC[] = "MAP_3.00";
bool ConvertADT(char *filename, char *filename2)
{
if(!LoadADT(filename))
return false;
FILE *output=fopen(filename2, "wb");
if(!output)
{
printf("Can't create the output file '%s'\n", filename2);
delete [] MapLiqHeight;
delete [] MapLiqFlag;
return false;
}
// write magic header
fwrite(MAP_MAGIC, 1, 8, output);
for(uint32 x = 0; x < 16; ++x)
{
for(uint32 y = 0; y < 16; ++y)
{
if(mcells->ch[y][x].area_id && mcells->ch[y][x].area_id <= maxAreaId)
{
if(areas[mcells->ch[y][x].area_id] == 0xffff)
printf("\nCan't find area flag for areaid %u.\n", mcells->ch[y][x].area_id);
fwrite(&areas[mcells->ch[y][x].area_id], 1, 2, output);
}
else
{
uint16 flag = 0xffff;
fwrite(&flag, 1, 2, output);
}
}
}
fwrite(MapLiqFlag, 1, 256, output);
delete [] MapLiqFlag;
fwrite(MapLiqHeight, sizeof(float), 16384, output);
delete [] MapLiqHeight;
TransformData();
fwrite(&cell->v9, 1, sizeof(cell->v9), output);
fwrite(&cell->v8, 1, sizeof(cell->v8), output);
fclose(output);
delete cell;
return true;
}

View file

@ -1,128 +0,0 @@
#ifndef ADT_H
#define ADT_H
#define TILESIZE (533.33333f)
#define CHUNKSIZE ((TILESIZE) / 16.0f)
#define UNITSIZE (CHUNKSIZE / 8.0f)
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
class Liquid;
typedef struct
{
float x;
float y;
float z;
} svec;
typedef struct
{
double x;
double y;
double z;
} vec;
typedef struct
{
vec v[3];
} triangle;
typedef struct
{
float v9[16 * 8 + 1][16 * 8 + 1];
float v8[16 * 8][16 * 8];
} Cell;
typedef struct
{
double v9[9][9];
double v8[8][8];
uint16 area_id;
} chunk;
typedef struct
{
chunk ch[16][16];
} mcell;
struct MapChunkHeader
{
uint32 flags;
uint32 ix;
uint32 iy;
uint32 nLayers;
uint32 nDoodadRefs;
uint32 ofsHeight;
uint32 ofsNormal;
uint32 ofsLayer;
uint32 ofsRefs;
uint32 ofsAlpha;
uint32 sizeAlpha;
uint32 ofsShadow;
uint32 sizeShadow;
uint32 areaid;
uint32 nMapObjRefs;
uint32 holes;
uint16 s1;
uint16 s2;
uint32 d1;
uint32 d2;
uint32 d3;
uint32 predTex;
uint32 nEffectDoodad;
uint32 ofsSndEmitters;
uint32 nSndEmitters;
uint32 ofsLiquid; // not use in WotLK
uint32 sizeLiquid; // not use in WotLK
float zpos;
float xpos;
float ypos;
uint32 textureId; // new offsColorValues in WotLK
uint32 props;
uint32 effectId;
};
typedef struct
{
uint32 offsData1;
uint32 used;
uint32 offsData2;
} MH2O_offsData;
typedef struct
{
uint16 LiquidTypeId;
uint16 type;
float heightLevel1;
float heightLevel2;
uint8 xOffset;
uint8 yOffset;
uint8 width;
uint8 height;
uint32 ofsData2a;
uint32 ofsData2b;
} MH2O_Data1;
typedef struct
{
uint16 unk1;
uint16 unk2;
float height;
} LiqData;
enum LiquidType
{
LIQUID_TYPE_WATER = 0,
LIQUID_TYPE_OCEAN = 1,
LIQUID_TYPE_MAGMA = 2,
LIQUID_TYPE_SLIME = 3
};
class MPQFile;
float *MapLiqHeight;
uint8 *MapLiqFlag;
uint32 k, m, chunk_num;
void LoadMapChunk(MPQFile &, chunk*);
#endif

View file

@ -0,0 +1,13 @@
# Copyright (C) 2005-2009 MaNGOS project <http://getmangos.com/>
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
add_library (loadlib loadlib.cpp adt.cpp wdt.cpp)
# link loadlib with zlib
target_link_libraries (loadlib z)

View file

@ -0,0 +1,131 @@
#define _CRT_SECURE_NO_DEPRECATE
#include "adt.h"
// Helper
int holetab_h[4] = {0x1111, 0x2222, 0x4444, 0x8888};
int holetab_v[4] = {0x000F, 0x00F0, 0x0F00, 0xF000};
bool isHole(int holes, int i, int j)
{
int testi = i / 2;
int testj = j / 4;
if(testi > 3) testi = 3;
if(testj > 3) testj = 3;
return (holes & holetab_h[testi] & holetab_v[testj]) != 0;
}
//
// Adt file loader class
//
ADT_file::ADT_file()
{
a_grid = 0;
}
ADT_file::~ADT_file()
{
free();
}
void ADT_file::free()
{
a_grid = 0;
FileLoader::free();
}
//
// Adt file check function
//
bool ADT_file::prepareLoadedData()
{
// Check parent
if (!FileLoader::prepareLoadedData())
return false;
// Check and prepare MHDR
a_grid = (adt_MHDR *)(GetData()+8+version->size);
if (!a_grid->prepareLoadedData())
return false;
return true;
}
bool adt_MHDR::prepareLoadedData()
{
if (fcc != 'MHDR')
return false;
if (size!=sizeof(adt_MHDR)-8)
return false;
// Check and prepare MCIN
if (offsMCIN && !getMCIN()->prepareLoadedData())
return false;
// Check and prepare MH2O
if (offsMH2O && !getMH2O()->prepareLoadedData())
return false;
return true;
}
bool adt_MCIN::prepareLoadedData()
{
if (fcc != 'MCIN')
return false;
// Check cells data
for (int i=0; i<ADT_CELLS_PER_GRID;i++)
for (int j=0; j<ADT_CELLS_PER_GRID;j++)
if (cells[i][j].offsMCNK && !getMCNK(i,j)->prepareLoadedData())
return false;
return true;
}
bool adt_MH2O::prepareLoadedData()
{
if (fcc != 'MH2O')
return false;
// Check liquid data
// for (int i=0; i<ADT_CELLS_PER_GRID;i++)
// for (int j=0; j<ADT_CELLS_PER_GRID;j++)
return true;
}
bool adt_MCNK::prepareLoadedData()
{
if (fcc != 'MCNK')
return false;
// Check height map
if (offsMCVT && !getMCVT()->prepareLoadedData())
return false;
// Check liquid data
if (offsMCLQ && !getMCLQ()->prepareLoadedData())
return false;
return true;
}
bool adt_MCVT::prepareLoadedData()
{
if (fcc != 'MCVT')
return false;
if (size != sizeof(adt_MCVT)-8)
return false;
return true;
}
bool adt_MCLQ::prepareLoadedData()
{
if (fcc != 'MCLQ')
return false;
return true;
}

View file

@ -0,0 +1,289 @@
#ifndef ADT_H
#define ADT_H
#include "loadlib.h"
#define TILESIZE (533.33333f)
#define CHUNKSIZE ((TILESIZE) / 16.0f)
#define UNITSIZE (CHUNKSIZE / 8.0f)
enum LiquidType
{
LIQUID_TYPE_WATER = 0,
LIQUID_TYPE_OCEAN = 1,
LIQUID_TYPE_MAGMA = 2,
LIQUID_TYPE_SLIME = 3
};
//**************************************************************************************
// ADT file class
//**************************************************************************************
#define ADT_CELLS_PER_GRID 16
#define ADT_CELL_SIZE 8
#define ADT_GRID_SIZE (ADT_CELLS_PER_GRID*ADT_CELL_SIZE)
//
// Adt file height map chunk
//
class adt_MCVT
{
union{
uint32 fcc;
char fcc_txt[4];
};
uint32 size;
public:
float height_map[(ADT_CELL_SIZE+1)*(ADT_CELL_SIZE+1)+ADT_CELL_SIZE*ADT_CELL_SIZE];
bool prepareLoadedData();
};
//
// Adt file liquid map chunk (old)
//
class adt_MCLQ
{
union{
uint32 fcc;
char fcc_txt[4];
};
uint32 size;
public:
float height1;
float height2;
struct liquid_data{
uint32 light;
float height;
} liquid[ADT_CELL_SIZE+1][ADT_CELL_SIZE+1];
// 1<<0 - ochen
// 1<<1 - lava/slime
// 1<<2 - water
// 1<<6 - all water
// 1<<7 - dark water
// == 0x0F - not show liquid
uint8 flags[ADT_CELL_SIZE][ADT_CELL_SIZE];
uint8 data[84];
bool prepareLoadedData();
};
//
// Adt file cell chunk
//
class adt_MCNK
{
union{
uint32 fcc;
char fcc_txt[4];
};
uint32 size;
public:
uint32 flags;
uint32 ix;
uint32 iy;
uint32 nLayers;
uint32 nDoodadRefs;
uint32 offsMCVT; // height map
uint32 offsMCNR; // Normal vectors for each vertex
uint32 offsMCLY; // Texture layer definitions
uint32 offsMCRF; // A list of indices into the parent file's MDDF chunk
uint32 offsMCAL; // Alpha maps for additional texture layers
uint32 sizeMCAL;
uint32 offsMCSH; // Shadow map for static shadows on the terrain
uint32 sizeMCSH;
uint32 areaid;
uint32 nMapObjRefs;
uint32 holes;
uint16 s[2];
uint32 data1;
uint32 data2;
uint32 data3;
uint32 predTex;
uint32 nEffectDoodad;
uint32 offsMCSE;
uint32 nSndEmitters;
uint32 offsMCLQ; // Liqid level (old)
uint32 sizeMCLQ; //
float zpos;
float xpos;
float ypos;
uint32 offsMCCV; // offsColorValues in WotLK
uint32 props;
uint32 effectId;
bool prepareLoadedData();
adt_MCVT *getMCVT()
{
if (offsMCVT)
return (adt_MCVT *)((uint8 *)this + offsMCVT);
return 0;
}
adt_MCLQ *getMCLQ()
{
if (offsMCLQ)
return (adt_MCLQ *)((uint8 *)this + offsMCLQ);
return 0;
}
};
//
// Adt file grid chunk
//
class adt_MCIN
{
union{
uint32 fcc;
char fcc_txt[4];
};
uint32 size;
public:
struct adt_CELLS{
uint32 offsMCNK;
uint32 size;
uint32 flags;
uint32 asyncId;
} cells[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
bool prepareLoadedData();
// offset from begin file (used this-84)
adt_MCNK *getMCNK(int x, int y)
{
if (cells[x][y].offsMCNK)
return (adt_MCNK *)((uint8 *)this + cells[x][y].offsMCNK - 84);
return 0;
}
};
#define ADT_LIQUID_HEADER_FULL_LIGHT 0x01
#define ADT_LIQUID_HEADER_NO_HIGHT 0x02
struct adt_liquid_header{
uint16 liquidType; // Index from LiquidType.dbc
uint16 formatFlags;
float heightLevel1;
float heightLevel2;
uint8 xOffset;
uint8 yOffset;
uint8 width;
uint8 height;
uint32 offsData2a;
uint32 offsData2b;
};
//
// Adt file liquid data chunk (new)
//
class adt_MH2O
{
public:
union{
uint32 fcc;
char fcc_txt[4];
};
uint32 size;
struct adt_LIQUID{
uint32 offsData1;
uint32 used;
uint32 offsData2;
} liquid[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
bool prepareLoadedData();
adt_liquid_header *getLiquidData(int x, int y)
{
if (liquid[x][y].used && liquid[x][y].offsData1)
return (adt_liquid_header *)((uint8*)this + 8 + liquid[x][y].offsData1);
return 0;
}
float *getLiquidHeightMap(adt_liquid_header *h)
{
if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT)
return 0;
if (h->offsData2b)
return (float *)((uint8*)this + 8 + h->offsData2b);
return 0;
}
uint8 *getLiquidLightMap(adt_liquid_header *h)
{
if (h->formatFlags&ADT_LIQUID_HEADER_FULL_LIGHT)
return 0;
if (h->offsData2b)
{
if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT)
return (uint8 *)((uint8*)this + 8 + h->offsData2b);
return (uint8 *)((uint8*)this + 8 + h->offsData2b + (h->width+1)*(h->height+1)*4);
}
return 0;
}
uint32 *getLiquidFullLightMap(adt_liquid_header *h)
{
if (!(h->formatFlags&ADT_LIQUID_HEADER_FULL_LIGHT))
return 0;
if (h->offsData2b)
{
if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT)
return (uint32 *)((uint8*)this + 8 + h->offsData2b);
return (uint32 *)((uint8*)this + 8 + h->offsData2b + (h->width+1)*(h->height+1)*4);
}
return 0;
}
uint64 getLiquidShowMap(adt_liquid_header *h)
{
if (h->offsData2a)
return *((uint64 *)((uint8*)this + 8 + h->offsData2a));
else
return 0xFFFFFFFFFFFFFFFFLL;
}
};
//
// Adt file header chunk
//
class adt_MHDR
{
union{
uint32 fcc;
char fcc_txt[4];
};
uint32 size;
uint32 pad;
uint32 offsMCIN; // MCIN
uint32 offsTex; // MTEX
uint32 offsModels; // MMDX
uint32 offsModelsIds; // MMID
uint32 offsMapObejcts; // MWMO
uint32 offsMapObejctsIds; // MWID
uint32 offsDoodsDef; // MDDF
uint32 offsObjectsDef; // MODF
uint32 offsMFBO; // MFBO
uint32 offsMH2O; // MH2O
uint32 data1;
uint32 data2;
uint32 data3;
uint32 data4;
uint32 data5;
public:
bool prepareLoadedData();
adt_MCIN *getMCIN(){ return (adt_MCIN *)((uint8 *)&pad+offsMCIN);}
adt_MH2O *getMH2O(){ return offsMH2O ? (adt_MH2O *)((uint8 *)&pad+offsMH2O) : 0;}
};
class ADT_file : public FileLoader{
public:
bool prepareLoadedData();
ADT_file();
~ADT_file();
void free();
adt_MHDR *a_grid;
};
#endif

View file

@ -0,0 +1,63 @@
#define _CRT_SECURE_NO_DEPRECATE
#include "loadlib.h"
#include "../mpq_libmpq.h"
class MPQFile;
FileLoader::FileLoader()
{
data = 0;
data_size = 0;
version = 0;
}
FileLoader::~FileLoader()
{
free();
}
bool FileLoader::loadFile(char *filename)
{
free();
MPQFile mf(filename);
if(mf.isEof())
{
printf("No such file %s\n", filename);
return false;
}
data_size = mf.getSize();
data = new uint8 [data_size];
if (data)
{
mf.read(data, data_size);
mf.close();
if (prepareLoadedData())
return true;
}
printf("Error loading %s", filename);
mf.close();
free();
return false;
}
bool FileLoader::prepareLoadedData()
{
// Check version
version = (file_MVER *) data;
if (version->fcc != 'MVER')
return false;
if (version->ver != FILE_FORMAT_VERSION)
return false;
return true;
}
void FileLoader::free()
{
if (data) delete[] data;
data = 0;
data_size = 0;
version = 0;
}

View file

@ -0,0 +1,57 @@
#ifndef LOAD_LIB_H
#define LOAD_LIB_H
#ifdef WIN32
typedef __int64 int64;
typedef long int32;
typedef short int16;
typedef char int8;
typedef unsigned __int64 uint64;
typedef unsigned long uint32;
typedef unsigned short uint16;
typedef unsigned char uint8;
#else
#include <stdint.h>
#ifndef uint64_t
#include <linux/types.h>
#endif
typedef int64_t int64;
typedef long int32;
typedef short int16;
typedef char int8;
typedef uint64_t uint64;
typedef unsigned long uint32;
typedef unsigned short uint16;
typedef unsigned char uint8;
#endif
#define FILE_FORMAT_VERSION 18
//
// File version chunk
//
struct file_MVER
{
union{
uint32 fcc;
char fcc_txt[4];
};
uint32 size;
uint32 ver;
};
class FileLoader{
uint8 *data;
uint32 data_size;
public:
virtual bool prepareLoadedData();
uint8 *GetData() {return data;}
uint32 GetDataSize() {return data_size;}
file_MVER *version;
FileLoader();
~FileLoader();
bool loadFile(char *filename);
virtual void free();
};
#endif

View file

@ -0,0 +1,62 @@
#define _CRT_SECURE_NO_DEPRECATE
#include "wdt.h"
bool wdt_MWMO::prepareLoadedData()
{
if (fcc != 'MWMO')
return false;
return true;
}
bool wdt_MPHD::prepareLoadedData()
{
if (fcc != 'MPHD')
return false;
return true;
}
bool wdt_MAIN::prepareLoadedData()
{
if (fcc != 'MAIN')
return false;
return true;
}
WDT_file::WDT_file()
{
mphd = 0;
main = 0;
wmo = 0;
}
WDT_file::~WDT_file()
{
free();
}
void WDT_file::free()
{
mphd = 0;
main = 0;
wmo = 0;
FileLoader::free();
}
bool WDT_file::prepareLoadedData()
{
// Check parent
if (!FileLoader::prepareLoadedData())
return false;
mphd = (wdt_MPHD *)((uint8*)version+version->size+8);
if (!mphd->prepareLoadedData())
return false;
main = (wdt_MAIN *)((uint8*)mphd + mphd->size+8);
if (!main->prepareLoadedData())
return false;
wmo = (wdt_MWMO *)((uint8*)main+ main->size+8);
if (!wmo->prepareLoadedData())
return false;
return true;
}

View file

@ -0,0 +1,68 @@
#ifndef WDT_H
#define WDT_H
#include "loadlib.h"
//**************************************************************************************
// WDT file class and structures
//**************************************************************************************
#define WDT_MAP_SIZE 64
class wdt_MWMO{
union{
uint32 fcc;
char fcc_txt[4];
};
public:
uint32 size;
bool prepareLoadedData();
};
class wdt_MPHD{
union{
uint32 fcc;
char fcc_txt[4];
};
public:
uint32 size;
uint32 data1;
uint32 data2;
uint32 data3;
uint32 data4;
uint32 data5;
uint32 data6;
uint32 data7;
uint32 data8;
bool prepareLoadedData();
};
class wdt_MAIN{
union{
uint32 fcc;
char fcc_txt[4];
};
public:
uint32 size;
struct adtData{
uint32 exist;
uint32 data1;
} adt_list[64][64];
bool prepareLoadedData();
};
class WDT_file : public FileLoader{
public:
bool prepareLoadedData();
WDT_file();
~WDT_file();
void free();
wdt_MPHD *mphd;
wdt_MAIN *main;
wdt_MWMO *wmo;
};
#endif

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
{

View file

@ -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

View file

@ -68,14 +68,135 @@ typedef RGuard<GridRWLock, ZThread::Lockable> GridReadGuard;
typedef WGuard<GridRWLock, ZThread::Lockable> GridWriteGuard;
typedef MaNGOS::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
{
@ -190,6 +311,8 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj
float GetHeight(float x, float y, float z, bool pCheckVMap=true) 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;
@ -277,6 +400,7 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj
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;

View file

@ -351,8 +351,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;
@ -797,25 +800,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;
@ -828,9 +820,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 );
@ -841,12 +831,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);
@ -866,96 +866,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
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))
case FATIGUE_TIMER:
return MINUTE*IN_MILISECONDS;
case BREATH_TIMER:
{
m_isunderwater|= UNDERWATER_WATER_TRIGGER;
m_breathTimer = UnderWaterTime + 1*IN_MILISECONDS;
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);
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);
}
//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;
if (!isAlive())
return DISABLED_MIRROR_TIMER;
return 1*IN_MILISECONDS;
}
default:
return 0;
}
//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;
}
return 0;
}
void Player::HandleLava()
void Player::UpdateMirrorTimers()
{
if ((m_isunderwater & UNDERWATER_INLAVA) && isAlive())
// Desync flags for update on next HandleDrowning
if (m_MirrorTimerFlags)
m_MirrorTimerFlagsLast = ~m_MirrorTimerFlags;
}
void Player::HandleDrowning(uint32 time_diff)
{
if (!m_MirrorTimerFlags)
return;
// In water
if (m_MirrorTimerFlags & UNDERWATER_INWATER)
{
/*
* arrai: how is this supposed to work? UNDERWATER_INLAVA is always set in this scope!
// Single trigger Set BreathTimer
if (!(m_isunderwater & UNDERWATER_INLAVA))
// Breath timer not activated - activate it
if (m_MirrorTimer[BREATH_TIMER] == DISABLED_MIRROR_TIMER)
{
m_isunderwater|= UNDERWATER_WATER_BREATHB;
m_breathTimer = 1*IN_MILISECONDS;
m_MirrorTimer[BREATH_TIMER] = getMaxTimer(BREATH_TIMER);
SendMirrorTimer(BREATH_TIMER, m_MirrorTimer[BREATH_TIMER], m_MirrorTimer[BREATH_TIMER], -1);
}
*/
// Reset BreathTimer and still in the lava
if (!m_breathTimer)
else // If activated - do tick
{
uint64 guid = GetGUID();
uint32 damage = urand(600, 700); // TODO: Get more detailed information about lava damage
EnvironmentalDamage(guid, DAMAGE_LAVA, damage);
m_breathTimer = 1*IN_MILISECONDS;
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 (!isAlive()) // Disable breath timer and reset underwater flags
else if (m_MirrorTimer[BREATH_TIMER] != DISABLED_MIRROR_TIMER) // Regen timer
{
m_breathTimer = 0;
m_isunderwater = UNDERWATER_NONE;
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
@ -1227,21 +1284,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)
@ -19352,21 +19396,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;
// 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_MirrorTimerFlags &= ~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;
// 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_isunderwater &= ~UNDERWATER_INLAVA;
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 )

View file

@ -69,10 +69,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
@ -500,6 +501,8 @@ enum MirrorTimerType
BREATH_TIMER = 1,
FIRE_TIMER = 2
};
#define MAX_TIMERS 3
#define DISABLED_MIRROR_TIMER -1
// 2^n values
enum PlayerExtraFlags
@ -1709,6 +1712,7 @@ class MANGOS_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);
@ -2020,8 +2024,6 @@ class MANGOS_DLL_SPEC Player : public Unit
bool IsFlying() const { return HasUnitMovementFlag(MOVEMENTFLAG_FLYING); }
bool IsAllowUseFlyMountsHere() const;
void HandleDrowning();
void SetClientControl(Unit* target, uint8 allowMove);
void EnterVehicle(Vehicle *vehicle);
@ -2236,12 +2238,14 @@ class MANGOS_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;
/*********************************************************/
@ -2325,7 +2329,6 @@ class MANGOS_DLL_SPEC Player : public Unit
bool m_DailyQuestChanged;
time_t m_lastDailyQuestTime;
uint32 m_breathTimer;
uint32 m_drunkTimer;
uint16 m_drunk;
uint32 m_weaponChangeTimer;

View file

@ -2490,15 +2490,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)

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__