diff --git a/lib/CPathfinder.cpp b/lib/CPathfinder.cpp index 8046f461d..7f77683e9 100644 --- a/lib/CPathfinder.cpp +++ b/lib/CPathfinder.cpp @@ -596,7 +596,7 @@ void CPathfinder::initializePatrol() if(hero->patrol.patrolRadious) { state = PATROL_RADIUS; - gs->getTilesInRange(patrolTiles, hero->patrol.initialPos, hero->patrol.patrolRadious); + gs->getTilesInRange(patrolTiles, hero->patrol.initialPos, hero->patrol.patrolRadious, hero->tempOwner, 0, true); } else state = PATROL_LOCKED; diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index 8f8f3b30c..cf335ba1b 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -45,7 +45,7 @@ void CPrivilagedInfoCallback::getFreeTiles (std::vector &tiles) const } } -void CPrivilagedInfoCallback::getTilesInRange( std::unordered_set &tiles, int3 pos, int radious, boost::optional player/*=uninit*/, int mode/*=0*/ ) const +void CPrivilagedInfoCallback::getTilesInRange( std::unordered_set &tiles, int3 pos, int radious, boost::optional player/*=uninit*/, int mode/*=0*/, bool patrolDistance/*=false*/) const { if(!!player && *player >= PlayerColor::PLAYER_LIMIT) { @@ -61,7 +61,13 @@ void CPrivilagedInfoCallback::getTilesInRange( std::unordered_set(pos.y - radious, 0); yd <= std::min(pos.y + radious, gs->map->height - 1); yd++) { - double distance = pos.dist2d(int3(xd,yd,pos.z)) - 0.5; + int3 tilePos(xd,yd,pos.z); + double distance; + if(patrolDistance) + distance = pos.mandist2d(tilePos); + else + distance = pos.dist2d(tilePos) - 0.5; + if(distance <= radious) { if(!player diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index b2ca42030..43c24d05c 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -30,7 +30,7 @@ class DLL_LINKAGE CPrivilagedInfoCallback : public CGameInfoCallback public: CGameState * gameState(); void getFreeTiles (std::vector &tiles) const; //used for random spawns - void getTilesInRange(std::unordered_set &tiles, int3 pos, int radious, boost::optional player = boost::optional(), int mode=0) const; //mode 1 - only unrevealed tiles; mode 0 - all, mode -1 - only unrevealed + void getTilesInRange(std::unordered_set &tiles, int3 pos, int radious, boost::optional player = boost::optional(), int mode = 0, bool patrolDistance = false) const; //mode 1 - only unrevealed tiles; mode 0 - all, mode -1 - only unrevealed void getAllTiles (std::unordered_set &tiles, boost::optional player = boost::optional(), int level=-1, int surface=0) const; //returns all tiles on given level (-1 - both levels, otherwise number of level); surface: 0 - land and water, 1 - only land, 2 - only water void pickAllowedArtsSet(std::vector &out); //gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant void getAllowedSpells(std::vector &out, ui16 level); diff --git a/lib/int3.h b/lib/int3.h index 7ac595183..a1b40ce55 100644 --- a/lib/int3.h +++ b/lib/int3.h @@ -105,6 +105,11 @@ public: { return std::sqrt((double)dist2dSQ(o)); } + //manhattan distance used for patrol radius (z coord is not used) + double mandist2d(const int3 & o) const + { + return abs(o.x - x) + abs(o.y - y); + } bool areNeighbours(const int3 & o) const { @@ -175,4 +180,4 @@ int3 findClosestTile (Container & container, int3 dest) } } return result; -} \ No newline at end of file +}