From 537654510c439e4f5db8b02d5f52d2e101b57ba7 Mon Sep 17 00:00:00 2001 From: Cyberium Date: Fri, 16 Jan 2015 22:58:29 +0100 Subject: [PATCH] [12817] Improve GetHeightInRange, now we handle the case of two near value of vmap and map height in better way. --- src/game/Map.cpp | 44 +++++++++++++++++++++++++++++++--------- src/shared/revision_nr.h | 2 +- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/game/Map.cpp b/src/game/Map.cpp index 94a0f3a0a13..4f104b8aee7 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -2027,7 +2027,8 @@ bool Map::GetHitPosition(float srcX, float srcY, float srcZ, float& destX, float // Find an height within a reasonable range of provided Z. This method may fail so we have to handle that case. bool Map::GetHeightInRange(uint32 phasemask, float x, float y, float &z, float maxSearchDist /*= 4.0f*/) const { - float height; + float height, vmapHeight, mapHeight; + vmapHeight = VMAP_INVALID_HEIGHT_VALUE; VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager(); if (!vmgr->isLineOfSightCalcEnabled()) @@ -2035,20 +2036,43 @@ bool Map::GetHeightInRange(uint32 phasemask, float x, float y, float &z, float m if (vmgr) { - height = VMAP_INVALID_HEIGHT_VALUE; - // pure vmap search - height = vmgr->getHeight(i_id, x, y, z + 1.0f, maxSearchDist); + vmapHeight = vmgr->getHeight(i_id, x, y, z + 2.0f, maxSearchDist + 2.0f); } - if (height < INVALID_HEIGHT || fabs(fabs(z) - fabs(height)) > maxSearchDist) + // find raw height from .map file on X,Y coordinates + if (GridMap* gmap = const_cast(m_TerrainData)->GetGrid(x, y)) // TODO:: find a way to remove that const_cast + mapHeight = gmap->getHeight(x, y); + + float diffMaps = fabs(fabs(z) - fabs(mapHeight)); + float diffVmaps = fabs(fabs(z) - fabs(vmapHeight)); + if (diffVmaps < maxSearchDist) { - // find raw height from .map file on X,Y coordinates - if (GridMap* gmap = const_cast(m_TerrainData)->GetGrid(x, y)) // TODO:: find a way to remove that const_cast - height = gmap->getHeight(x, y); + if (diffMaps < maxSearchDist) + { + // here we often have to take vmap value but sometime we have to take map value. + if (vmapHeight > mapHeight || diffMaps > diffVmaps) + height = vmapHeight; + else + height = mapHeight; - if (fabs(fabs(z) - fabs(height)) > maxSearchDist) - return false; // not found any good height + //sLog.outString("vmap %5.4f, map %5.4f, height %5.4f", vmapHeight, mapHeight, height); + } + else + { + //sLog.outString("vmap %5.4f", vmapHeight); + height = vmapHeight; + } + } + else + { + if (diffMaps < maxSearchDist) + { + //sLog.outString("map %5.4f", mapHeight); + height = mapHeight; + } + else + return false; } z = std::max(height, m_dyn_tree.getHeight(x, y, height + 1.0f, maxSearchDist, phasemask)); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index ffc36c980da..2a8d81dfc61 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "12816" + #define REVISION_NR "12817" #endif // __REVISION_NR_H__