mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 01:37:00 +00:00
Various Cleanups (game F-K)
This commit is contained in:
parent
c5c09cee3c
commit
2bd41afb3e
44 changed files with 1903 additions and 1881 deletions
|
|
@ -66,21 +66,21 @@ GridMap::~GridMap()
|
|||
unloadData();
|
||||
}
|
||||
|
||||
bool GridMap::loadData(char *filename)
|
||||
bool GridMap::loadData(char* filename)
|
||||
{
|
||||
// Unload old data if exist
|
||||
unloadData();
|
||||
|
||||
GridMapFileHeader header;
|
||||
// Not return error if file not found
|
||||
FILE *in = fopen(filename, "rb");
|
||||
FILE* in = fopen(filename, "rb");
|
||||
if (!in)
|
||||
return true;
|
||||
|
||||
fread(&header, sizeof(header),1,in);
|
||||
if (header.mapMagic == *((uint32 const*)(MAP_MAGIC)) &&
|
||||
header.versionMagic == *((uint32 const*)(MAP_VERSION_MAGIC)) &&
|
||||
IsAcceptableClientBuild(header.buildMagic))
|
||||
header.versionMagic == *((uint32 const*)(MAP_VERSION_MAGIC)) &&
|
||||
IsAcceptableClientBuild(header.buildMagic))
|
||||
{
|
||||
// loadup area data
|
||||
if (header.areaMapOffset && !loadAreaData(in, header.areaMapOffset, header.areaMapSize))
|
||||
|
|
@ -140,7 +140,7 @@ void GridMap::unloadData()
|
|||
m_gridGetHeight = &GridMap::getHeightFromFlat;
|
||||
}
|
||||
|
||||
bool GridMap::loadAreaData(FILE *in, uint32 offset, uint32 /*size*/)
|
||||
bool GridMap::loadAreaData(FILE* in, uint32 offset, uint32 /*size*/)
|
||||
{
|
||||
GridMapAreaHeader header;
|
||||
fseek(in, offset, SEEK_SET);
|
||||
|
|
@ -158,7 +158,7 @@ bool GridMap::loadAreaData(FILE *in, uint32 offset, uint32 /*size*/)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GridMap::loadHeightData(FILE *in, uint32 offset, uint32 /*size*/)
|
||||
bool GridMap::loadHeightData(FILE* in, uint32 offset, uint32 /*size*/)
|
||||
{
|
||||
GridMapHeightHeader header;
|
||||
fseek(in, offset, SEEK_SET);
|
||||
|
|
@ -202,7 +202,7 @@ bool GridMap::loadHeightData(FILE *in, uint32 offset, uint32 /*size*/)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool GridMap::loadGridMapLiquidData(FILE *in, uint32 offset, uint32 /*size*/)
|
||||
bool GridMap::loadGridMapLiquidData(FILE* in, uint32 offset, uint32 /*size*/)
|
||||
{
|
||||
GridMapLiquidHeader header;
|
||||
fseek(in, offset, SEEK_SET);
|
||||
|
|
@ -286,7 +286,7 @@ float GridMap::getHeightFromFloat(float x, float y) const
|
|||
if (x > y)
|
||||
{
|
||||
// 1 triangle (h1, h2, h5 points)
|
||||
float h1 = m_V9[(x_int )*129 + y_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;
|
||||
|
|
@ -319,7 +319,7 @@ float GridMap::getHeightFromFloat(float x, float y) const
|
|||
else
|
||||
{
|
||||
// 4 triangle (h3, h4, h5 points)
|
||||
float h3 = m_V9[(x_int )*129 + y_int+1];
|
||||
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;
|
||||
|
|
@ -347,7 +347,7 @@ float GridMap::getHeightFromUint8(float x, float y) const
|
|||
y_int &= (MAP_RESOLUTION - 1);
|
||||
|
||||
int32 a, b, c;
|
||||
uint8 *V9_h1_ptr = &m_uint8_V9[x_int*128 + x_int + y_int];
|
||||
uint8* V9_h1_ptr = &m_uint8_V9[x_int*128 + x_int + y_int];
|
||||
if (x+y < 1)
|
||||
{
|
||||
if (x > y)
|
||||
|
|
@ -415,7 +415,7 @@ float GridMap::getHeightFromUint16(float x, float y) const
|
|||
y_int &= (MAP_RESOLUTION - 1);
|
||||
|
||||
int32 a, b, c;
|
||||
uint16 *V9_h1_ptr = &m_uint16_V9[x_int*128 + x_int + y_int];
|
||||
uint16* V9_h1_ptr = &m_uint16_V9[x_int*128 + x_int + y_int];
|
||||
if (x+y < 1)
|
||||
{
|
||||
if (x > y)
|
||||
|
|
@ -481,7 +481,7 @@ float GridMap::getLiquidLevel(float x, float y)
|
|||
if (cx_int < 0 || cx_int >=m_liquid_height)
|
||||
return INVALID_HEIGHT_VALUE;
|
||||
|
||||
if (cy_int < 0 || cy_int >=m_liquid_width )
|
||||
if (cy_int < 0 || cy_int >=m_liquid_width)
|
||||
return INVALID_HEIGHT_VALUE;
|
||||
|
||||
return m_liquid_map[cx_int*m_liquid_width + cy_int];
|
||||
|
|
@ -500,7 +500,7 @@ uint8 GridMap::getTerrainType(float x, float y)
|
|||
}
|
||||
|
||||
// Get water state on map
|
||||
GridMapLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, GridMapLiquidData *data)
|
||||
GridMapLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, GridMapLiquidData* data)
|
||||
{
|
||||
// Check water type (if no water return)
|
||||
if (!m_liquid_type && !m_liquidType)
|
||||
|
|
@ -529,7 +529,7 @@ GridMapLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 Re
|
|||
return LIQUID_MAP_NO_WATER;
|
||||
|
||||
int ly_int = y_int - m_liquid_offX;
|
||||
if (ly_int < 0 || ly_int >=m_liquid_width )
|
||||
if (ly_int < 0 || ly_int >=m_liquid_width)
|
||||
return LIQUID_MAP_NO_WATER;
|
||||
|
||||
// Get water level
|
||||
|
|
@ -557,12 +557,12 @@ GridMapLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 Re
|
|||
if (delta > 20) // Under water
|
||||
return LIQUID_MAP_UNDER_WATER;
|
||||
|
||||
if (delta > 0 ) // In water
|
||||
if (delta > 0) // In water
|
||||
return LIQUID_MAP_IN_WATER;
|
||||
|
||||
if (delta > -1) // Walk on water
|
||||
return LIQUID_MAP_WATER_WALK;
|
||||
// Above water
|
||||
// Above water
|
||||
return LIQUID_MAP_ABOVE_WATER;
|
||||
}
|
||||
|
||||
|
|
@ -570,11 +570,11 @@ bool GridMap::ExistMap(uint32 mapid,int gx,int gy)
|
|||
{
|
||||
int len = sWorld.GetDataPath().length()+strlen("maps/%03u%02u%02u.map")+1;
|
||||
char* tmp = new char[len];
|
||||
snprintf(tmp, len, (char *)(sWorld.GetDataPath()+"maps/%03u%02u%02u.map").c_str(),mapid,gx,gy);
|
||||
snprintf(tmp, len, (char*)(sWorld.GetDataPath()+"maps/%03u%02u%02u.map").c_str(),mapid,gx,gy);
|
||||
|
||||
FILE *pf=fopen(tmp,"rb");
|
||||
FILE* pf=fopen(tmp,"rb");
|
||||
|
||||
if(!pf)
|
||||
if (!pf)
|
||||
{
|
||||
sLog.outError("Check existing of map file '%s': not exist!",tmp);
|
||||
delete[] tmp;
|
||||
|
|
@ -584,8 +584,8 @@ bool GridMap::ExistMap(uint32 mapid,int gx,int gy)
|
|||
GridMapFileHeader header;
|
||||
fread(&header, sizeof(header), 1, pf);
|
||||
if (header.mapMagic != *((uint32 const*)(MAP_MAGIC)) ||
|
||||
header.versionMagic != *((uint32 const*)(MAP_VERSION_MAGIC)) ||
|
||||
!IsAcceptableClientBuild(header.buildMagic))
|
||||
header.versionMagic != *((uint32 const*)(MAP_VERSION_MAGIC)) ||
|
||||
!IsAcceptableClientBuild(header.buildMagic))
|
||||
{
|
||||
sLog.outError("Map file '%s' is non-compatible version (outdated?). Please, create new using ad.exe program.",tmp);
|
||||
delete [] tmp;
|
||||
|
|
@ -600,13 +600,13 @@ bool GridMap::ExistMap(uint32 mapid,int gx,int gy)
|
|||
|
||||
bool GridMap::ExistVMap(uint32 mapid,int gx,int gy)
|
||||
{
|
||||
if(VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager())
|
||||
if (VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager())
|
||||
{
|
||||
if(vmgr->isMapLoadingEnabled())
|
||||
if (vmgr->isMapLoadingEnabled())
|
||||
{
|
||||
// x and y are swapped !! => fixed now
|
||||
// x and y are swapped !! => fixed now
|
||||
bool exists = vmgr->existsMap((sWorld.GetDataPath()+ "vmaps").c_str(), mapid, gx,gy);
|
||||
if(!exists)
|
||||
if (!exists)
|
||||
{
|
||||
std::string name = vmgr->getDirFileName(mapid,gx,gy);
|
||||
sLog.outError("VMap file '%s' is missing or point to wrong version vmap file, redo vmaps with latest vmap_assembler.exe program", (sWorld.GetDataPath()+"vmaps/"+name).c_str());
|
||||
|
|
@ -649,7 +649,7 @@ TerrainInfo::~TerrainInfo()
|
|||
MMAP::MMapFactory::createOrGetMMapManager()->unloadMap(m_mapId);
|
||||
}
|
||||
|
||||
GridMap * TerrainInfo::Load(const uint32 x, const uint32 y)
|
||||
GridMap* TerrainInfo::Load(const uint32 x, const uint32 y)
|
||||
{
|
||||
MANGOS_ASSERT(x < MAX_NUMBER_OF_GRIDS);
|
||||
MANGOS_ASSERT(y < MAX_NUMBER_OF_GRIDS);
|
||||
|
|
@ -658,8 +658,8 @@ GridMap * TerrainInfo::Load(const uint32 x, const uint32 y)
|
|||
RefGrid(x, y);
|
||||
|
||||
//quick check if GridMap already loaded
|
||||
GridMap * pMap = m_GridMaps[x][y];
|
||||
if(!pMap)
|
||||
GridMap* pMap = m_GridMaps[x][y];
|
||||
if (!pMap)
|
||||
pMap = LoadMapAndVMap(x, y);
|
||||
|
||||
return pMap;
|
||||
|
|
@ -671,10 +671,10 @@ void TerrainInfo::Unload(const uint32 x, const uint32 y)
|
|||
MANGOS_ASSERT(x < MAX_NUMBER_OF_GRIDS);
|
||||
MANGOS_ASSERT(y < MAX_NUMBER_OF_GRIDS);
|
||||
|
||||
if(m_GridMaps[x][y])
|
||||
if (m_GridMaps[x][y])
|
||||
{
|
||||
//decrease grid reference count...
|
||||
if(UnrefGrid(x, y) == 0)
|
||||
if (UnrefGrid(x, y) == 0)
|
||||
{
|
||||
//TODO: add your additional logic here
|
||||
|
||||
|
|
@ -687,7 +687,7 @@ void TerrainInfo::Unload(const uint32 x, const uint32 y)
|
|||
void TerrainInfo::CleanUpGrids(const uint32 diff)
|
||||
{
|
||||
i_timer.Update(diff);
|
||||
if( !i_timer.Passed() )
|
||||
if (!i_timer.Passed())
|
||||
return;
|
||||
|
||||
for (int y = 0; y < MAX_NUMBER_OF_GRIDS; ++y)
|
||||
|
|
@ -695,10 +695,10 @@ void TerrainInfo::CleanUpGrids(const uint32 diff)
|
|||
for (int x = 0; x < MAX_NUMBER_OF_GRIDS; ++x)
|
||||
{
|
||||
const int16& iRef = m_GridRef[x][y];
|
||||
GridMap * pMap = m_GridMaps[x][y];
|
||||
GridMap* pMap = m_GridMaps[x][y];
|
||||
|
||||
//delete those GridMap objects which have refcount = 0
|
||||
if(pMap && iRef == 0 )
|
||||
if (pMap && iRef == 0)
|
||||
{
|
||||
m_GridMaps[x][y] = NULL;
|
||||
//delete grid data if reference count == 0
|
||||
|
|
@ -734,7 +734,7 @@ int TerrainInfo::UnrefGrid(const uint32& x, const uint32& y)
|
|||
int16& iRef = m_GridRef[x][y];
|
||||
|
||||
LOCK_GUARD _lock(m_refMutex);
|
||||
if(iRef > 0)
|
||||
if (iRef > 0)
|
||||
return (iRef -= 1);
|
||||
|
||||
return 0;
|
||||
|
|
@ -745,7 +745,7 @@ float TerrainInfo::GetHeight(float x, float y, float z, bool pUseVmaps, float ma
|
|||
// find raw .map surface under Z coordinates
|
||||
float mapHeight;
|
||||
float z2 = z + 2.f;
|
||||
if (GridMap *gmap = const_cast<TerrainInfo*>(this)->GetGrid(x, y))
|
||||
if (GridMap* gmap = const_cast<TerrainInfo*>(this)->GetGrid(x, y))
|
||||
{
|
||||
float _mapheight = gmap->getHeight(x,y);
|
||||
|
||||
|
|
@ -804,26 +804,26 @@ float TerrainInfo::GetHeight(float x, float y, float z, bool pUseVmaps, float ma
|
|||
}
|
||||
|
||||
inline bool IsOutdoorWMO(uint32 mogpFlags, int32 adtId, int32 rootId, int32 groupId,
|
||||
WMOAreaTableEntry const* wmoEntry, AreaTableEntry const* atEntry)
|
||||
WMOAreaTableEntry const* wmoEntry, AreaTableEntry const* atEntry)
|
||||
{
|
||||
bool outdoor = true;
|
||||
|
||||
if(wmoEntry && atEntry)
|
||||
if (wmoEntry && atEntry)
|
||||
{
|
||||
if(atEntry->flags & AREA_FLAG_OUTSIDE)
|
||||
if (atEntry->flags & AREA_FLAG_OUTSIDE)
|
||||
return true;
|
||||
if(atEntry->flags & AREA_FLAG_INSIDE)
|
||||
if (atEntry->flags & AREA_FLAG_INSIDE)
|
||||
return false;
|
||||
}
|
||||
|
||||
outdoor = mogpFlags&0x8;
|
||||
|
||||
if(wmoEntry)
|
||||
if (wmoEntry)
|
||||
{
|
||||
if(wmoEntry->Flags & 4)
|
||||
if (wmoEntry->Flags & 4)
|
||||
return true;
|
||||
|
||||
if((wmoEntry->Flags & 2)!=0)
|
||||
if ((wmoEntry->Flags & 2)!=0)
|
||||
outdoor = false;
|
||||
}
|
||||
return outdoor;
|
||||
|
|
@ -835,12 +835,12 @@ bool TerrainInfo::IsOutdoors(float x, float y, float z) const
|
|||
int32 adtId, rootId, groupId;
|
||||
|
||||
// no wmo found? -> outside by default
|
||||
if(!GetAreaInfo(x, y, z, mogpFlags, adtId, rootId, groupId))
|
||||
if (!GetAreaInfo(x, y, z, mogpFlags, adtId, rootId, groupId))
|
||||
return true;
|
||||
|
||||
AreaTableEntry const* atEntry = 0;
|
||||
WMOAreaTableEntry const* wmoEntry= GetWMOAreaTableEntryByTripple(rootId, adtId, groupId);
|
||||
if(wmoEntry)
|
||||
if (wmoEntry)
|
||||
{
|
||||
DEBUG_LOG("Got WMOAreaTableEntry! flag %u, areaid %u", wmoEntry->Flags, wmoEntry->areaId);
|
||||
|
||||
|
|
@ -850,18 +850,18 @@ bool TerrainInfo::IsOutdoors(float x, float y, float z) const
|
|||
return IsOutdoorWMO(mogpFlags, adtId, rootId, groupId, wmoEntry, atEntry);
|
||||
}
|
||||
|
||||
bool TerrainInfo::GetAreaInfo(float x, float y, float z, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const
|
||||
bool TerrainInfo::GetAreaInfo(float x, float y, float z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const
|
||||
{
|
||||
float vmap_z = z;
|
||||
VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager();
|
||||
if (vmgr->getAreaInfo(GetMapId(), x, y, vmap_z, flags, adtId, rootId, groupId))
|
||||
{
|
||||
// check if there's terrain between player height and object height
|
||||
if(GridMap *gmap = const_cast<TerrainInfo*>(this)->GetGrid(x, y))
|
||||
if (GridMap* gmap = const_cast<TerrainInfo*>(this)->GetGrid(x, y))
|
||||
{
|
||||
float _mapheight = gmap->getHeight(x,y);
|
||||
// z + 2.0f condition taken from GetHeight(), not sure if it's such a great choice...
|
||||
if(z + 2.0f > _mapheight && _mapheight > vmap_z)
|
||||
if (z + 2.0f > _mapheight && _mapheight > vmap_z)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -869,7 +869,7 @@ bool TerrainInfo::GetAreaInfo(float x, float y, float z, uint32 &flags, int32 &a
|
|||
return false;
|
||||
}
|
||||
|
||||
uint16 TerrainInfo::GetAreaFlag(float x, float y, float z, bool *isOutdoors) const
|
||||
uint16 TerrainInfo::GetAreaFlag(float x, float y, float z, bool* isOutdoors) const
|
||||
{
|
||||
uint32 mogpFlags;
|
||||
int32 adtId, rootId, groupId;
|
||||
|
|
@ -877,11 +877,11 @@ uint16 TerrainInfo::GetAreaFlag(float x, float y, float z, bool *isOutdoors) con
|
|||
AreaTableEntry const* atEntry = 0;
|
||||
bool haveAreaInfo = false;
|
||||
|
||||
if(GetAreaInfo(x, y, z, mogpFlags, adtId, rootId, groupId))
|
||||
if (GetAreaInfo(x, y, z, mogpFlags, adtId, rootId, groupId))
|
||||
{
|
||||
haveAreaInfo = true;
|
||||
wmoEntry = GetWMOAreaTableEntryByTripple(rootId, adtId, groupId);
|
||||
if(wmoEntry)
|
||||
if (wmoEntry)
|
||||
atEntry = GetAreaEntryByAreaID(wmoEntry->areaId);
|
||||
}
|
||||
|
||||
|
|
@ -890,7 +890,7 @@ uint16 TerrainInfo::GetAreaFlag(float x, float y, float z, bool *isOutdoors) con
|
|||
areaflag = atEntry->exploreFlag;
|
||||
else
|
||||
{
|
||||
if(GridMap *gmap = const_cast<TerrainInfo*>(this)->GetGrid(x, y))
|
||||
if (GridMap* gmap = const_cast<TerrainInfo*>(this)->GetGrid(x, y))
|
||||
areaflag = gmap->getArea(x, y);
|
||||
// this used while not all *.map files generated (instances)
|
||||
else
|
||||
|
|
@ -907,9 +907,9 @@ uint16 TerrainInfo::GetAreaFlag(float x, float y, float z, bool *isOutdoors) con
|
|||
return areaflag;
|
||||
}
|
||||
|
||||
uint8 TerrainInfo::GetTerrainType(float x, float y ) const
|
||||
uint8 TerrainInfo::GetTerrainType(float x, float y) const
|
||||
{
|
||||
if(GridMap *gmap = const_cast<TerrainInfo*>(this)->GetGrid(x, y))
|
||||
if (GridMap* gmap = const_cast<TerrainInfo*>(this)->GetGrid(x, y))
|
||||
return gmap->getTerrainType(x, y);
|
||||
else
|
||||
return 0;
|
||||
|
|
@ -931,7 +931,7 @@ void TerrainInfo::GetZoneAndAreaId(uint32& zoneid, uint32& areaid, float x, floa
|
|||
}
|
||||
|
||||
|
||||
GridMapLiquidStatus TerrainInfo::getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, GridMapLiquidData *data) const
|
||||
GridMapLiquidStatus TerrainInfo::getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, GridMapLiquidData* data) const
|
||||
{
|
||||
GridMapLiquidStatus result = LIQUID_MAP_NO_WATER;
|
||||
VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager();
|
||||
|
|
@ -957,14 +957,14 @@ GridMapLiquidStatus TerrainInfo::getLiquidStatus(float x, float y, float z, uint
|
|||
// Get position delta
|
||||
if (delta > 20) // Under water
|
||||
return LIQUID_MAP_UNDER_WATER;
|
||||
if (delta > 0 ) // In water
|
||||
if (delta > 0) // In water
|
||||
return LIQUID_MAP_IN_WATER;
|
||||
if (delta > -1) // Walk on water
|
||||
return LIQUID_MAP_WATER_WALK;
|
||||
result = LIQUID_MAP_ABOVE_WATER;
|
||||
}
|
||||
}
|
||||
if(GridMap* gmap = const_cast<TerrainInfo*>(this)->GetGrid(x, y))
|
||||
if (GridMap* gmap = const_cast<TerrainInfo*>(this)->GetGrid(x, y))
|
||||
{
|
||||
GridMapLiquidData map_data;
|
||||
GridMapLiquidStatus map_result = gmap->getLiquidStatus(x, y, z, ReqLiquidType, &map_data);
|
||||
|
|
@ -979,17 +979,17 @@ GridMapLiquidStatus TerrainInfo::getLiquidStatus(float x, float y, float z, uint
|
|||
return result;
|
||||
}
|
||||
|
||||
bool TerrainInfo::IsInWater(float x, float y, float pZ, GridMapLiquidData *data) const
|
||||
bool TerrainInfo::IsInWater(float x, float y, float pZ, GridMapLiquidData* data) const
|
||||
{
|
||||
// Check surface in x, y point for liquid
|
||||
if (const_cast<TerrainInfo*>(this)->GetGrid(x, y))
|
||||
{
|
||||
GridMapLiquidData liquid_status;
|
||||
GridMapLiquidData *liquid_ptr = data ? data : &liquid_status;
|
||||
GridMapLiquidData* liquid_ptr = data ? data : &liquid_status;
|
||||
if (getLiquidStatus(x, y, pZ, MAP_ALL_LIQUIDS, liquid_ptr))
|
||||
{
|
||||
//if (liquid_prt->level - liquid_prt->depth_level > 2) //???
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -1029,45 +1029,45 @@ float TerrainInfo::GetWaterOrGroundLevel(float x, float y, float z, float* pGrou
|
|||
GridMapLiquidData liquid_status;
|
||||
|
||||
GridMapLiquidStatus res = getLiquidStatus(x, y, ground_z, MAP_ALL_LIQUIDS, &liquid_status);
|
||||
return res ? ( swim ? liquid_status.level - 2.0f : liquid_status.level) : ground_z;
|
||||
return res ? (swim ? liquid_status.level - 2.0f : liquid_status.level) : ground_z;
|
||||
}
|
||||
|
||||
return VMAP_INVALID_HEIGHT_VALUE;
|
||||
}
|
||||
|
||||
GridMap * TerrainInfo::GetGrid( const float x, const float y )
|
||||
GridMap* TerrainInfo::GetGrid(const float x, const 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
|
||||
|
||||
//quick check if GridMap already loaded
|
||||
GridMap * pMap = m_GridMaps[gx][gy];
|
||||
if(!pMap)
|
||||
pMap = LoadMapAndVMap(gx, gy);
|
||||
GridMap* pMap = m_GridMaps[gx][gy];
|
||||
if (!pMap)
|
||||
pMap = LoadMapAndVMap(gx, gy);
|
||||
|
||||
return pMap;
|
||||
}
|
||||
|
||||
GridMap * TerrainInfo::LoadMapAndVMap( const uint32 x, const uint32 y )
|
||||
GridMap* TerrainInfo::LoadMapAndVMap(const uint32 x, const uint32 y)
|
||||
{
|
||||
//double checked lock pattern
|
||||
if(!m_GridMaps[x][y])
|
||||
if (!m_GridMaps[x][y])
|
||||
{
|
||||
LOCK_GUARD lock(m_mutex);
|
||||
|
||||
if(!m_GridMaps[x][y])
|
||||
if (!m_GridMaps[x][y])
|
||||
{
|
||||
GridMap * map = new GridMap();
|
||||
GridMap* map = new GridMap();
|
||||
|
||||
// map file name
|
||||
char *tmp=NULL;
|
||||
char* tmp=NULL;
|
||||
int len = sWorld.GetDataPath().length()+strlen("maps/%03u%02u%02u.map")+1;
|
||||
tmp = new char[len];
|
||||
snprintf(tmp, len, (char *)(sWorld.GetDataPath()+"maps/%03u%02u%02u.map").c_str(),m_mapId, x, y);
|
||||
snprintf(tmp, len, (char*)(sWorld.GetDataPath()+"maps/%03u%02u%02u.map").c_str(),m_mapId, x, y);
|
||||
sLog.outDetail("Loading map %s",tmp);
|
||||
|
||||
if(!map->loadData(tmp))
|
||||
if (!map->loadData(tmp))
|
||||
{
|
||||
sLog.outError("Error load map file: \n %s\n", tmp);
|
||||
//ASSERT(false);
|
||||
|
|
@ -1077,21 +1077,21 @@ GridMap * TerrainInfo::LoadMapAndVMap( const uint32 x, const uint32 y )
|
|||
m_GridMaps[x][y] = map;
|
||||
|
||||
//load VMAPs for current map/grid...
|
||||
const MapEntry * i_mapEntry = sMapStore.LookupEntry(m_mapId);
|
||||
const MapEntry* i_mapEntry = sMapStore.LookupEntry(m_mapId);
|
||||
const char* mapName = i_mapEntry ? i_mapEntry->name[sWorld.GetDefaultDbcLocale()] : "UNNAMEDMAP\x0";
|
||||
|
||||
int vmapLoadResult = VMAP::VMapFactory::createOrGetVMapManager()->loadMap((sWorld.GetDataPath()+ "vmaps").c_str(), m_mapId, x, y);
|
||||
switch(vmapLoadResult)
|
||||
switch (vmapLoadResult)
|
||||
{
|
||||
case VMAP::VMAP_LOAD_RESULT_OK:
|
||||
sLog.outDetail("VMAP loaded name:%s, id:%d, x:%d, y:%d (vmap rep.: x:%d, y:%d)", mapName, m_mapId, x,y,x,y);
|
||||
break;
|
||||
case VMAP::VMAP_LOAD_RESULT_ERROR:
|
||||
sLog.outDetail("Could not load VMAP name:%s, id:%d, x:%d, y:%d (vmap rep.: x:%d, y:%d)", mapName, m_mapId, x,y,x,y);
|
||||
break;
|
||||
case VMAP::VMAP_LOAD_RESULT_IGNORED:
|
||||
DEBUG_LOG("Ignored VMAP name:%s, id:%d, x:%d, y:%d (vmap rep.: x:%d, y:%d)", mapName, m_mapId, x,y,x,y);
|
||||
break;
|
||||
case VMAP::VMAP_LOAD_RESULT_OK:
|
||||
sLog.outDetail("VMAP loaded name:%s, id:%d, x:%d, y:%d (vmap rep.: x:%d, y:%d)", mapName, m_mapId, x,y,x,y);
|
||||
break;
|
||||
case VMAP::VMAP_LOAD_RESULT_ERROR:
|
||||
sLog.outDetail("Could not load VMAP name:%s, id:%d, x:%d, y:%d (vmap rep.: x:%d, y:%d)", mapName, m_mapId, x,y,x,y);
|
||||
break;
|
||||
case VMAP::VMAP_LOAD_RESULT_IGNORED:
|
||||
DEBUG_LOG("Ignored VMAP name:%s, id:%d, x:%d, y:%d (vmap rep.: x:%d, y:%d)", mapName, m_mapId, x,y,x,y);
|
||||
break;
|
||||
}
|
||||
|
||||
// load navmesh
|
||||
|
|
@ -1139,13 +1139,13 @@ TerrainManager::~TerrainManager()
|
|||
delete it->second;
|
||||
}
|
||||
|
||||
TerrainInfo * TerrainManager::LoadTerrain(const uint32 mapId)
|
||||
TerrainInfo* TerrainManager::LoadTerrain(const uint32 mapId)
|
||||
{
|
||||
Guard _guard(*this);
|
||||
|
||||
TerrainInfo * ptr = NULL;
|
||||
TerrainInfo* ptr = NULL;
|
||||
TerrainDataMap::const_iterator iter = i_TerrainMap.find(mapId);
|
||||
if(iter == i_TerrainMap.end())
|
||||
if (iter == i_TerrainMap.end())
|
||||
{
|
||||
ptr = new TerrainInfo(mapId);
|
||||
i_TerrainMap[mapId] = ptr;
|
||||
|
|
@ -1158,17 +1158,17 @@ TerrainInfo * TerrainManager::LoadTerrain(const uint32 mapId)
|
|||
|
||||
void TerrainManager::UnloadTerrain(const uint32 mapId)
|
||||
{
|
||||
if(sWorld.getConfig(CONFIG_BOOL_GRID_UNLOAD) == 0)
|
||||
if (sWorld.getConfig(CONFIG_BOOL_GRID_UNLOAD) == 0)
|
||||
return;
|
||||
|
||||
Guard _guard(*this);
|
||||
|
||||
TerrainDataMap::iterator iter = i_TerrainMap.find(mapId);
|
||||
if(iter != i_TerrainMap.end())
|
||||
if (iter != i_TerrainMap.end())
|
||||
{
|
||||
TerrainInfo * ptr = (*iter).second;
|
||||
TerrainInfo* ptr = (*iter).second;
|
||||
//lets check if this object can be actually freed
|
||||
if(ptr->IsReferenced() == false)
|
||||
if (ptr->IsReferenced() == false)
|
||||
{
|
||||
i_TerrainMap.erase(iter);
|
||||
delete ptr;
|
||||
|
|
@ -1193,7 +1193,7 @@ void TerrainManager::UnloadAll()
|
|||
|
||||
uint32 TerrainManager::GetAreaIdByAreaFlag(uint16 areaflag,uint32 map_id)
|
||||
{
|
||||
AreaTableEntry const *entry = GetAreaEntryByAreaFlagAndMap(areaflag,map_id);
|
||||
AreaTableEntry const* entry = GetAreaEntryByAreaFlagAndMap(areaflag,map_id);
|
||||
|
||||
if (entry)
|
||||
return entry->ID;
|
||||
|
|
@ -1203,18 +1203,18 @@ uint32 TerrainManager::GetAreaIdByAreaFlag(uint16 areaflag,uint32 map_id)
|
|||
|
||||
uint32 TerrainManager::GetZoneIdByAreaFlag(uint16 areaflag,uint32 map_id)
|
||||
{
|
||||
AreaTableEntry const *entry = GetAreaEntryByAreaFlagAndMap(areaflag,map_id);
|
||||
AreaTableEntry const* entry = GetAreaEntryByAreaFlagAndMap(areaflag,map_id);
|
||||
|
||||
if( entry )
|
||||
return ( entry->zone != 0 ) ? entry->zone : entry->ID;
|
||||
if (entry)
|
||||
return (entry->zone != 0) ? entry->zone : entry->ID;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void TerrainManager::GetZoneAndAreaIdByAreaFlag(uint32& zoneid, uint32& areaid, uint16 areaflag,uint32 map_id)
|
||||
{
|
||||
AreaTableEntry const *entry = GetAreaEntryByAreaFlagAndMap(areaflag,map_id);
|
||||
AreaTableEntry const* entry = GetAreaEntryByAreaFlagAndMap(areaflag,map_id);
|
||||
|
||||
areaid = entry ? entry->ID : 0;
|
||||
zoneid = entry ? (( entry->zone != 0 ) ? entry->zone : entry->ID) : 0;
|
||||
zoneid = entry ? ((entry->zone != 0) ? entry->zone : entry->ID) : 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue