diff --git a/modules/acore/extractors/mmaps_generator/MapBuilder.cpp b/modules/acore/extractors/mmaps_generator/MapBuilder.cpp index 41cf8b5ca..ac802dd23 100644 --- a/modules/acore/extractors/mmaps_generator/MapBuilder.cpp +++ b/modules/acore/extractors/mmaps_generator/MapBuilder.cpp @@ -17,7 +17,6 @@ #include "DisableMgr.h" #include -uint32 GetLiquidFlags(uint32 /*liquidType*/) { return 0; } namespace DisableMgr { bool IsDisabledFor(DisableType /*type*/, uint32 /*entry*/, Unit const* /*unit*/, uint8 /*flags*/ /*= 0*/) { return false; } @@ -208,12 +207,14 @@ namespace MMAP } /**************************************************************************/ - void MapBuilder::getGridBounds(uint32 mapID, uint32 &minX, uint32 &minY, uint32 &maxX, uint32 &maxY) + void MapBuilder::getGridBounds(uint32 mapID, uint32 &minX, uint32 &minY, uint32 &maxX, uint32 &maxY) const { - maxX = INT_MAX; - maxY = INT_MAX; - minX = INT_MIN; - minY = INT_MIN; + // min and max are initialized to invalid values so the caller iterating the [min, max] range + // will never enter the loop unless valid min/max values are found + maxX = 0; + maxY = 0; + minX = std::numeric_limits::max(); + minY = std::numeric_limits::max(); float bmin[3] = { 0, 0, 0 }; float bmax[3] = { 0, 0, 0 }; @@ -354,7 +355,7 @@ namespace MMAP void MapBuilder::buildMap(uint32 mapID) { #ifndef __APPLE__ - printf("[Thread %u] Building map %03u:\n", uint32(ACE_Thread::self()), mapID); + //printf("[Thread %u] Building map %03u:\n", uint32(ACE_Thread::self()), mapID); #endif std::set* tiles = getTileList(mapID); @@ -458,7 +459,7 @@ namespace MMAP //if (tileBits < 1) tileBits = 1; // need at least one bit! //int polyBits = sizeof(dtPolyRef)*8 - SALT_MIN_BITS - tileBits; - int polyBits = STATIC_POLY_BITS; + int polyBits = DT_POLY_BITS; int maxTiles = tiles->size(); int maxPolysPerTile = 1 << polyBits; @@ -570,7 +571,9 @@ namespace MMAP config.borderSize = config.walkableRadius + 3; config.maxEdgeLen = VERTEX_PER_TILE + 1; // anything bigger than tileSize config.walkableHeight = m_bigBaseUnit ? 3 : 6; - config.walkableClimb = m_bigBaseUnit ? 2 : 4; // keep less than walkableHeight + // a value >= 3|6 allows npcs to walk over some fences + // a value >= 4|8 allows npcs to walk over all fences + config.walkableClimb = m_bigBaseUnit ? 2 : 4; config.minRegionArea = rcSqr(60); config.mergeRegionArea = rcSqr(50); config.maxSimplificationError = 1.8f; // eliminates most jagged edges (tiny polygons) @@ -694,7 +697,7 @@ namespace MMAP iv.polyMesh = rcAllocPolyMesh(); if (!iv.polyMesh) { - printf("%s alloc iv.polyMesh FIALED!\n", tileString); + printf("%s alloc iv.polyMesh FAILED!\n", tileString); delete[] pmmerge; delete[] dmmerge; delete[] tiles; @@ -705,7 +708,7 @@ namespace MMAP iv.polyMeshDetail = rcAllocPolyMeshDetail(); if (!iv.polyMeshDetail) { - printf("%s alloc m_dmesh FIALED!\n", tileString); + printf("%s alloc m_dmesh FAILED!\n", tileString); delete[] pmmerge; delete[] dmmerge; delete[] tiles; @@ -770,12 +773,12 @@ namespace MMAP if (params.nvp > DT_VERTS_PER_POLYGON) { printf("%s Invalid verts-per-polygon value! \n", tileString); - continue; + break; } if (params.vertCount >= 0xffff) { printf("%s Too many vertices! \n", tileString); - continue; + break; } if (!params.vertCount || !params.verts) { @@ -783,8 +786,8 @@ namespace MMAP // loaded but those models don't span into this tile // message is an annoyance - //printf("%sNo vertices to build tile! \n", tileString); - continue; + printf("%sNo vertices to build tile! \n", tileString); + break; } if (!params.polyCount || !params.polys || TILES_PER_MAP*TILES_PER_MAP == params.polyCount) @@ -793,19 +796,19 @@ namespace MMAP // keep in mind that we do output those into debug info // drop tiles with only exact count - some tiles may have geometry while having less tiles printf("%s No polygons to build on tile! \n", tileString); - continue; + break; } if (!params.detailMeshes || !params.detailVerts || !params.detailTris) { printf("%s No detail mesh to build tile! \n", tileString); - continue; + break; } printf("%s Building navmesh tile...\n", tileString); if (!dtCreateNavMeshData(¶ms, &navData, &navDataSize)) { printf("%s Failed building navmesh tile! \n", tileString); - continue; + break; } dtTileRef tileRef = 0; @@ -816,7 +819,7 @@ namespace MMAP if (!tileRef || dtResult != DT_SUCCESS) { printf("%s Failed adding tile to navmesh! \n", tileString); - continue; + break; } // file output @@ -829,7 +832,7 @@ namespace MMAP sprintf(message, "[Map %03i] Failed to open %s for writing!\n", mapID, fileName); perror(message); navMesh->removeTile(tileRef, NULL, NULL); - continue; + break; } printf("%s Writing to file...\n", tileString); diff --git a/modules/acore/extractors/mmaps_generator/MapBuilder.h b/modules/acore/extractors/mmaps_generator/MapBuilder.h index 4aefaede0..14d0316f2 100644 --- a/modules/acore/extractors/mmaps_generator/MapBuilder.h +++ b/modules/acore/extractors/mmaps_generator/MapBuilder.h @@ -110,7 +110,7 @@ namespace MMAP void getTileBounds(uint32 tileX, uint32 tileY, float* verts, int vertCount, float* bmin, float* bmax); - void getGridBounds(uint32 mapID, uint32 &minX, uint32 &minY, uint32 &maxX, uint32 &maxY); + void getGridBounds(uint32 mapID, uint32 &minX, uint32 &minY, uint32 &maxX, uint32 &maxY) const; bool shouldSkipMap(uint32 mapID); bool isTransportMap(uint32 mapID); diff --git a/modules/acore/extractors/mmaps_generator/PathCommon.h b/modules/acore/extractors/mmaps_generator/PathCommon.h index 586eeb7b5..e3f23b1a7 100644 --- a/modules/acore/extractors/mmaps_generator/PathCommon.h +++ b/modules/acore/extractors/mmaps_generator/PathCommon.h @@ -7,11 +7,10 @@ #ifndef _MMAP_COMMON_H #define _MMAP_COMMON_H +#include "Common.h" #include #include -#include "Common.h" - #ifndef _WIN32 #include #include @@ -52,7 +51,7 @@ namespace MMAP if (*++filter == '\0') // wildcard at end of filter means all remaing chars match return true; - while (true) + for (;;) { if (*filter == *str) break; diff --git a/modules/acore/extractors/mmaps_generator/PathGenerator.cpp b/modules/acore/extractors/mmaps_generator/PathGenerator.cpp index be02297d9..e302694b6 100644 --- a/modules/acore/extractors/mmaps_generator/PathGenerator.cpp +++ b/modules/acore/extractors/mmaps_generator/PathGenerator.cpp @@ -264,7 +264,7 @@ int main(int argc, char** argv) } if (!checkDirectories(debugOutput)) - return silent ? -3 : finish("Press any key to close...", -3); + return silent ? -3 : finish("Press ENTER to close...", -3); MapBuilder builder(maxAngle, skipLiquid, skipContinents, skipJunkMaps, skipBattlegrounds, debugOutput, bigBaseUnit, offMeshInputPath); diff --git a/modules/acore/extractors/mmaps_generator/TerrainBuilder.cpp b/modules/acore/extractors/mmaps_generator/TerrainBuilder.cpp index 47fe43b6c..3445013bd 100644 --- a/modules/acore/extractors/mmaps_generator/TerrainBuilder.cpp +++ b/modules/acore/extractors/mmaps_generator/TerrainBuilder.cpp @@ -700,7 +700,7 @@ namespace MMAP uint8 type = NAV_EMPTY; // convert liquid type to NavTerrain - switch (liquid->GetType()) + switch (liquid->GetType() & 3) { case 0: case 1: @@ -754,12 +754,12 @@ namespace MMAP } uint32 liqOffset = meshData.liquidVerts.size() / 3; - for (uint32 i = 0; i < liqVerts.size(); ++i) - meshData.liquidVerts.append(liqVerts[i].y, liqVerts[i].z, liqVerts[i].x); + for (uint32 j = 0; j < liqVerts.size(); ++j) + meshData.liquidVerts.append(liqVerts[j].y, liqVerts[j].z, liqVerts[j].x); - for (uint32 i = 0; i < liqTris.size() / 3; ++i) + for (uint32 j = 0; j < liqTris.size() / 3; ++j) { - meshData.liquidTris.append(liqTris[i*3+1] + liqOffset, liqTris[i*3+2] + liqOffset, liqTris[i*3] + liqOffset); + meshData.liquidTris.append(liqTris[j*3+1] + liqOffset, liqTris[j*3+2] + liqOffset, liqTris[j*3] + liqOffset); meshData.liquidType.append(type); } } @@ -894,7 +894,7 @@ namespace MMAP float p0[3], p1[3]; uint32 mid, tx, ty; float size; - if (sscanf(buf, "%d %d,%d (%f %f %f) (%f %f %f) %f", &mid, &tx, &ty, + if (sscanf(buf, "%u %u,%u (%f %f %f) (%f %f %f) %f", &mid, &tx, &ty, &p0[0], &p0[1], &p0[2], &p1[0], &p1[1], &p1[2], &size) != 10) continue; diff --git a/modules/acore/extractors/mmaps_generator/TerrainBuilder.h b/modules/acore/extractors/mmaps_generator/TerrainBuilder.h index d7f9a5a81..3e536fd14 100644 --- a/modules/acore/extractors/mmaps_generator/TerrainBuilder.h +++ b/modules/acore/extractors/mmaps_generator/TerrainBuilder.h @@ -69,11 +69,13 @@ namespace MMAP TerrainBuilder(bool skipLiquid); ~TerrainBuilder(); + TerrainBuilder(const TerrainBuilder &tb) = delete; + void loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData); bool loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData); void loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, const char* offMeshFilePath); - bool usesLiquids() { return !m_skipLiquid; } + bool usesLiquids() const { return !m_skipLiquid; } // vert and triangle methods static void transform(std::vector &original, std::vector &transformed, @@ -109,10 +111,6 @@ namespace MMAP /// Get the liquid type for a specific position uint8 getLiquidType(int square, const uint8 liquid_type[16][16]); - - // hide parameterless and copy constructor - TerrainBuilder(); - TerrainBuilder(const TerrainBuilder &tb); }; } diff --git a/modules/worldengine/lib-collision/src/Management/MMapManager.h b/modules/worldengine/lib-collision/src/Management/MMapManager.h index f12cd1184..842fe47fb 100644 --- a/modules/worldengine/lib-collision/src/Management/MMapManager.h +++ b/modules/worldengine/lib-collision/src/Management/MMapManager.h @@ -14,7 +14,7 @@ #include "World.h" // memory management -inline void* dtCustomAlloc(int size, dtAllocHint /*hint*/) +inline void* dtCustomAlloc(size_t size, dtAllocHint /*hint*/) { return (void*)new unsigned char[size]; } diff --git a/modules/worldengine/lib-collision/src/Management/VMapManager2.cpp b/modules/worldengine/lib-collision/src/Management/VMapManager2.cpp index 8dc9d770d..6897ffa56 100644 --- a/modules/worldengine/lib-collision/src/Management/VMapManager2.cpp +++ b/modules/worldengine/lib-collision/src/Management/VMapManager2.cpp @@ -1,7 +1,19 @@ /* - * Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license: http://github.com/azerothcore/azerothcore-wotlk/LICENSE-GPL2 - * Copyright (C) 2008-2016 TrinityCore - * Copyright (C) 2005-2009 MaNGOS + * Copyright (C) + * Copyright (C) + * + * 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. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . */ #include @@ -26,6 +38,7 @@ namespace VMAP { VMapManager2::VMapManager2() { + GetLiquidFlagsPtr = &GetLiquidFlagsDummy; } VMapManager2::~VMapManager2(void) @@ -76,7 +89,7 @@ namespace VMAP } // load one tile (internal use only) - bool VMapManager2::_loadMap(unsigned int mapId, const std::string& basePath, uint32 tileX, uint32 tileY) + bool VMapManager2::_loadMap(uint32 mapId, const std::string& basePath, uint32 tileX, uint32 tileY) { InstanceTreeMap::iterator instanceTree = iInstanceMapTrees.find(mapId); if (instanceTree == iInstanceMapTrees.end()) @@ -84,10 +97,10 @@ namespace VMAP std::string mapFileName = getMapFileName(mapId); StaticMapTree* newTree = new StaticMapTree(mapId, basePath); if (!newTree->InitMap(mapFileName, this)) - { - delete newTree; + { + delete newTree; return false; - } + } instanceTree = iInstanceMapTrees.insert(InstanceTreeMap::value_type(mapId, newTree)).first; } @@ -236,7 +249,7 @@ namespace VMAP floor = info.ground_Z; ASSERT(floor < std::numeric_limits::max()); type = info.hitModel->GetLiquidType(); // entry from LiquidType.dbc - if (reqLiquidType && !(GetLiquidFlags(type) & reqLiquidType)) + if (reqLiquidType && !(GetLiquidFlagsPtr(type) & reqLiquidType)) return false; if (info.hitInstance->GetLiquidLevel(pos, info, level)) return true; @@ -276,7 +289,6 @@ namespace VMAP { //! Critical section, thread safe access to iLoadedModelFiles TRINITY_GUARD(ACE_Thread_Mutex, LoadedModelFilesLock); - ModelFileMap::iterator model = iLoadedModelFiles.find(filename); if (model == iLoadedModelFiles.end()) { @@ -298,4 +310,4 @@ namespace VMAP return StaticMapTree::CanLoadMap(std::string(basePath), mapId, x, y); } -} // namespace VMAP +} // namespace VMAP \ No newline at end of file diff --git a/modules/worldengine/lib-collision/src/Management/VMapManager2.h b/modules/worldengine/lib-collision/src/Management/VMapManager2.h index f4455fc72..ac07d7945 100644 --- a/modules/worldengine/lib-collision/src/Management/VMapManager2.h +++ b/modules/worldengine/lib-collision/src/Management/VMapManager2.h @@ -1,7 +1,19 @@ /* - * Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license: http://github.com/azerothcore/azerothcore-wotlk/LICENSE-GPL2 - * Copyright (C) 2008-2016 TrinityCore - * Copyright (C) 2005-2009 MaNGOS + * Copyright (C) + * Copyright (C) + * + * 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. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . */ #ifndef _VMAPMANAGER2_H @@ -66,6 +78,8 @@ namespace VMAP bool _loadMap(uint32 mapId, const std::string& basePath, uint32 tileX, uint32 tileY); /* void _unloadMap(uint32 pMapId, uint32 x, uint32 y); */ + static uint32 GetLiquidFlagsDummy(uint32) { return 0; } + public: // public for debug G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const; @@ -102,7 +116,10 @@ namespace VMAP virtual bool existsMap(const char* basePath, unsigned int mapId, int x, int y); public: void getInstanceMapTree(InstanceTreeMap &instanceMapTree); + + typedef uint32(*GetLiquidFlagsFn)(uint32 liquidType); + GetLiquidFlagsFn GetLiquidFlagsPtr; }; } -#endif +#endif \ No newline at end of file diff --git a/src/game/Grids/GridDefines.h b/src/game/Grids/GridDefines.h index d6b4a36ca..5554a731e 100644 --- a/src/game/Grids/GridDefines.h +++ b/src/game/Grids/GridDefines.h @@ -213,7 +213,7 @@ namespace Trinity inline bool IsValidMapCoord(float x, float y, float z) { - return IsValidMapCoord(x, y) && isfinite(z); + return IsValidMapCoord(x, y) && IsValidMapCoord(z); } inline bool IsValidMapCoord(float x, float y, float z, float o) diff --git a/src/game/Maps/Map.cpp b/src/game/Maps/Map.cpp index a18ebf84e..4e6a595a5 100644 --- a/src/game/Maps/Map.cpp +++ b/src/game/Maps/Map.cpp @@ -2012,7 +2012,7 @@ uint32 Map::GetAreaId(float x, float y, float z, bool *isOutdoors) const atEntry = sAreaTableStore.LookupEntry(wmoEntry->areaId); } - uint16 areaId; + uint16 areaId = 0; if (atEntry) areaId = atEntry->ID; @@ -2021,7 +2021,7 @@ uint32 Map::GetAreaId(float x, float y, float z, bool *isOutdoors) const if (GridMap* gmap = const_cast(this)->GetGrid(x, y)) areaId = gmap->getArea(x, y); // this used while not all *.map files generated (instances) - else + if (!areaId) areaId = i_mapEntry->linked_zone; } diff --git a/src/game/Movement/MovementGenerators/PathGenerator.cpp b/src/game/Movement/MovementGenerators/PathGenerator.cpp index f5e9210b0..0a55b66d2 100644 --- a/src/game/Movement/MovementGenerators/PathGenerator.cpp +++ b/src/game/Movement/MovementGenerators/PathGenerator.cpp @@ -909,7 +909,7 @@ dtStatus PathGenerator::FindSmoothPath(float const* startPos, float const* endPo // Find movement delta. float delta[VERTEX_SIZE]; dtVsub(delta, steerPos, iterPos); - float len = dtMathSqrtf(dtVdot(delta,delta)); + float len = dtMathSqrtf(dtVdot(delta, delta)); // If the steer target is end of path or off-mesh link, do not move past the location. if ((endOfPath || offMeshConnection) && len < SMOOTH_PATH_STEP_SIZE) len = 1.0f; diff --git a/src/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp b/src/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp index 52323722f..97ffaa443 100644 --- a/src/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp +++ b/src/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp @@ -55,6 +55,9 @@ void TargetedMovementGeneratorMedium::_setTargetLocation(T* owner, bool ini if (!i_offset) { + if (i_target->IsWithinDistInMap(owner, CONTACT_DISTANCE)) + return; + float allowedRange = MELEE_RANGE; if ((!initial || (owner->movespline->Finalized() && this->GetMovementGeneratorType() == CHASE_MOTION_TYPE)) && i_target->IsWithinMeleeRange(owner, allowedRange) && i_target->IsWithinLOS(owner->GetPositionX(), owner->GetPositionY(), owner->GetPositionZ())) return; diff --git a/src/game/Spells/Spell.cpp b/src/game/Spells/Spell.cpp index d44e0556f..fda0183b9 100644 --- a/src/game/Spells/Spell.cpp +++ b/src/game/Spells/Spell.cpp @@ -5788,7 +5788,7 @@ SpellCastResult Spell::CheckCast(bool strict) m_pathFinder = new PathGenerator(m_caster); m_pathFinder->CalculatePath(pos.m_positionX, pos.m_positionY, pos.m_positionZ+0.15f, false); G3D::Vector3 endPos = m_pathFinder->GetEndPosition(); // also check distance between target and the point calculated by mmaps - if (m_pathFinder->GetPathType()&PATHFIND_NOPATH || target->GetExactDistSq(endPos.x, endPos.y, endPos.z) > maxdist*maxdist || m_pathFinder->getPathLength() > (40.0f + (m_caster->HasAura(58097) ? 5.0f : 0.0f))) + if (m_pathFinder->GetPathType() & (PATHFIND_NOPATH | PATHFIND_INCOMPLETE) || target->GetExactDistSq(endPos.x, endPos.y, endPos.z) > maxdist*maxdist || m_pathFinder->getPathLength() > (40.0f + (m_caster->HasAura(58097) ? 5.0f : 0.0f))) return SPELL_FAILED_NOPATH; } break; diff --git a/src/game/World/World.cpp b/src/game/World/World.cpp index 32da6e747..63150afb1 100644 --- a/src/game/World/World.cpp +++ b/src/game/World/World.cpp @@ -75,6 +75,7 @@ #include "WhoListCache.h" #include "AsyncAuctionListing.h" #include "SavingSystem.h" +#include ACE_Atomic_Op World::m_stopEvent = false; uint8 World::m_ExitCode = SHUTDOWN_EXIT_CODE; @@ -1276,6 +1277,12 @@ void World::SetInitialWorldSettings() sLog->outString("Initializing Scripts..."); sScriptMgr->Initialize(); + ///- Initialize VMapManager function pointers (to untangle game/collision circular deps) + if (VMAP::VMapManager2* vmmgr2 = dynamic_cast(VMAP::VMapFactory::createOrGetVMapManager())) + { + vmmgr2->GetLiquidFlagsPtr = &GetLiquidFlags; + } + ///- Initialize config settings LoadConfigSettings();