1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Patrol: use manhattan distance for getting tiles in radius

This commit is contained in:
ArseniyShestakov 2015-12-04 21:08:09 +03:00
parent 6bb205b15b
commit bdc369ffba
4 changed files with 16 additions and 5 deletions

View File

@ -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;

View File

@ -45,7 +45,7 @@ void CPrivilagedInfoCallback::getFreeTiles (std::vector<int3> &tiles) const
}
}
void CPrivilagedInfoCallback::getTilesInRange( std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, boost::optional<PlayerColor> player/*=uninit*/, int mode/*=0*/ ) const
void CPrivilagedInfoCallback::getTilesInRange( std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, boost::optional<PlayerColor> 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<int3, ShashInt
{
for (int yd = std::max<int>(pos.y - radious, 0); yd <= std::min<int>(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

View File

@ -30,7 +30,7 @@ class DLL_LINKAGE CPrivilagedInfoCallback : public CGameInfoCallback
public:
CGameState * gameState();
void getFreeTiles (std::vector<int3> &tiles) const; //used for random spawns
void getTilesInRange(std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, boost::optional<PlayerColor> player = boost::optional<PlayerColor>(), int mode=0) const; //mode 1 - only unrevealed tiles; mode 0 - all, mode -1 - only unrevealed
void getTilesInRange(std::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, boost::optional<PlayerColor> player = boost::optional<PlayerColor>(), int mode = 0, bool patrolDistance = false) const; //mode 1 - only unrevealed tiles; mode 0 - all, mode -1 - only unrevealed
void getAllTiles (std::unordered_set<int3, ShashInt3> &tiles, boost::optional<PlayerColor> player = boost::optional<PlayerColor>(), 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<const CArtifact*> &out); //gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant
void getAllowedSpells(std::vector<SpellID> &out, ui16 level);

View File

@ -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;
}
}