aboutsummaryrefslogtreecommitdiff
path: root/src/server/collision/Maps/MapTree.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/collision/Maps/MapTree.cpp')
-rw-r--r--src/server/collision/Maps/MapTree.cpp64
1 files changed, 37 insertions, 27 deletions
diff --git a/src/server/collision/Maps/MapTree.cpp b/src/server/collision/Maps/MapTree.cpp
index af92ec37ae7..e758581e2f8 100644
--- a/src/server/collision/Maps/MapTree.cpp
+++ b/src/server/collision/Maps/MapTree.cpp
@@ -1,19 +1,19 @@
/*
+ * Copyright (C) 2008-2010 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MapTree.h"
@@ -57,7 +57,7 @@ namespace VMAP
void operator()(const Vector3& point, uint32 entry)
{
#ifdef VMAP_DEBUG
- sLog.outDebug("trying to intersect '%s'", prims[entry].name.c_str());
+ sLog.outDebug("AreaInfoCallback: trying to intersect '%s'", prims[entry].name.c_str());
#endif
prims[entry].intersectPoint(point, aInfo);
}
@@ -73,7 +73,7 @@ namespace VMAP
void operator()(const Vector3& point, uint32 entry)
{
#ifdef VMAP_DEBUG
- sLog.outDebug("trying to intersect '%s'", prims[entry].name.c_str());
+ sLog.outDebug("LocationInfoCallback: trying to intersect '%s'", prims[entry].name.c_str());
#endif
if (prims[entry].GetLocationInfo(point, locInfo))
result = true;
@@ -121,7 +121,7 @@ namespace VMAP
}
StaticMapTree::StaticMapTree(uint32 mapID, const std::string &basePath):
- iMapID(mapID), /* iTree(0), */ iTreeValues(0), iBasePath(basePath)
+ iMapID(mapID), iTreeValues(0), iBasePath(basePath)
{
if (iBasePath.length() > 0 && (iBasePath[iBasePath.length()-1] != '/' || iBasePath[iBasePath.length()-1] != '\\'))
{
@@ -260,7 +260,11 @@ namespace VMAP
if (!tf)
success = false;
else
+ {
+ if (!readChunk(tf, chunk, VMAP_MAGIC, 8))
+ success = false;
fclose(tf);
+ }
}
fclose(rf);
return success;
@@ -270,7 +274,7 @@ namespace VMAP
bool StaticMapTree::InitMap(const std::string &fname, VMapManager2 *vm)
{
- sLog.outDebug("Initializing StaticMapTree '%s'", fname.c_str());
+ sLog.outDebug("StaticMapTree::InitMap() : initializing StaticMapTree '%s'", fname.c_str());
bool success = true;
std::string fullname = iBasePath + fname;
FILE *rf = fopen(fullname.c_str(), "rb");
@@ -298,12 +302,12 @@ namespace VMAP
// only non-tiled maps have them, and if so exactly one (so far at least...)
ModelSpawn spawn;
#ifdef VMAP_DEBUG
- sLog.outDebug("Map isTiled: %u", static_cast<uint32>(iIsTiled));
+ sLog.outDebug("StaticMapTree::InitMap() : map isTiled: %u", static_cast<uint32>(iIsTiled));
#endif
if (!iIsTiled && ModelSpawn::readFromFile(rf, spawn))
{
WorldModel *model = vm->acquireModelInstance(iBasePath, spawn.name);
- sLog.outDebug("StaticMapTree::InitMap(): loading %s", spawn.name.c_str());
+ sLog.outDebug("StaticMapTree::InitMap() : loading %s", spawn.name.c_str());
if (model)
{
// assume that global model always is the first and only tree value (could be improved...)
@@ -313,7 +317,7 @@ namespace VMAP
else
{
success = false;
- sLog.outError("Could not acquire WorldModel pointer!");
+ sLog.outError("StaticMapTree::InitMap() : could not acquire WorldModel pointer for '%s'", spawn.name.c_str());
}
}
@@ -349,7 +353,7 @@ namespace VMAP
}
if (!iTreeValues)
{
- sLog.outError("Tree has not been initialized! [%u,%u]", tileX, tileY);
+ sLog.outError("StaticMapTree::LoadMapTile() : tree has not been initialized [%u,%u]", tileX, tileY);
return false;
}
bool result = true;
@@ -358,8 +362,12 @@ namespace VMAP
FILE* tf = fopen(tilefile.c_str(), "rb");
if (tf)
{
+ char chunk[8];
+
+ if (!readChunk(tf, chunk, VMAP_MAGIC, 8))
+ result = false;
uint32 numSpawns;
- if (fread(&numSpawns, sizeof(uint32), 1, tf) != 1)
+ if (result && fread(&numSpawns, sizeof(uint32), 1, tf) != 1)
result = false;
for (uint32 i=0; i<numSpawns && result; ++i)
{
@@ -371,7 +379,7 @@ namespace VMAP
// acquire model instance
WorldModel *model = vm->acquireModelInstance(iBasePath, spawn.name);
if (!model)
- sLog.outError("error: could not acquire WorldModel pointer! [%u,%u]", tileX, tileY);
+ sLog.outError("StaticMapTree::LoadMapTile() : could not acquire WorldModel pointer [%u,%u]", tileX, tileY);
// update tree
uint32 referencedVal;
@@ -382,7 +390,7 @@ namespace VMAP
#ifdef VMAP_DEBUG
if (referencedVal > iNTreeValues)
{
- sLog.outDebug("invalid tree element! (%u/%u)", referencedVal, iNTreeValues);
+ sLog.outDebug("StaticMapTree::LoadMapTile() : invalid tree element (%u/%u)", referencedVal, iNTreeValues);
continue;
}
#endif
@@ -394,9 +402,9 @@ namespace VMAP
++iLoadedSpawns[referencedVal];
#ifdef VMAP_DEBUG
if (iTreeValues[referencedVal].ID != spawn.ID)
- sLog.outDebug("error: trying to load wrong spawn in node!");
+ sLog.outDebug("StaticMapTree::LoadMapTile() : trying to load wrong spawn in node");
else if (iTreeValues[referencedVal].name != spawn.name)
- sLog.outDebug("error: name collision on GUID=%u", spawn.ID);
+ sLog.outDebug("StaticMapTree::LoadMapTile() : name collision on GUID=%u", spawn.ID);
#endif
}
}
@@ -417,7 +425,7 @@ namespace VMAP
loadedTileMap::iterator tile = iLoadedTiles.find(tileID);
if (tile == iLoadedTiles.end())
{
- sLog.outError("WARNING: trying to unload non-loaded tile. Map:%u X:%u Y:%u", iMapID, tileX, tileY);
+ sLog.outError("StaticMapTree::UnloadMapTile() : trying to unload non-loaded tile - Map:%u X:%u Y:%u", iMapID, tileX, tileY);
return;
}
if (tile->second) // file associated with tile
@@ -427,6 +435,9 @@ namespace VMAP
if (tf)
{
bool result=true;
+ char chunk[8];
+ if (!readChunk(tf, chunk, VMAP_MAGIC, 8))
+ result = false;
uint32 numSpawns;
if (fread(&numSpawns, sizeof(uint32), 1, tf) != 1)
result = false;
@@ -446,11 +457,10 @@ namespace VMAP
fread(&referencedNode, sizeof(uint32), 1, tf);
if (!iLoadedSpawns.count(referencedNode))
{
- sLog.outError("Trying to unload non-referenced model '%s' (ID:%u)", spawn.name.c_str(), spawn.ID);
+ sLog.outError("StaticMapTree::UnloadMapTile() : trying to unload non-referenced model '%s' (ID:%u)", spawn.name.c_str(), spawn.ID);
}
else if (--iLoadedSpawns[referencedNode] == 0)
{
- //std::cout << "MapTree: removing '" << spawn.name << "' from tree\n";
iTreeValues[referencedNode].setUnloaded();
iLoadedSpawns.erase(referencedNode);
}