void CPrivilagedInfoCallback::getTilesInRange( boost::unordered_set<int3, ShashInt3> &tiles, int3 pos, int radious, int player/*=-1*/, int mode/*=0*/ ) const { if(player >= GameConstants::PLAYER_LIMIT) { tlog1 << "Illegal call to getTilesInRange!\n"; return; } if (radious == -1) //reveal entire map getAllTiles (tiles, player, -1, 0); else { const TeamState * team = gs->getPlayerTeam(player); for (int xd = std::max<int>(pos.x - radious , 0); xd <= std::min<int>(pos.x + radious, gs->map->width - 1); xd++) { 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; if(distance <= radious) { if(player < 0 || (mode == 1 && team->fogOfWarMap[xd][yd][pos.z]==0) || (mode == -1 && team->fogOfWarMap[xd][yd][pos.z]==1) ) tiles.insert(int3(xd,yd,pos.z)); } } } } }
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) { logGlobal->errorStream() << "Illegal call to getTilesInRange!"; return; } if (radious == -1) //reveal entire map getAllTiles (tiles, player, -1, 0); else { const TeamState * team = !player ? nullptr : gs->getPlayerTeam(*player); for (int xd = std::max<int>(pos.x - radious , 0); xd <= std::min<int>(pos.x + radious, gs->map->width - 1); xd++) { for (int yd = std::max<int>(pos.y - radious, 0); yd <= std::min<int>(pos.y + radious, gs->map->height - 1); yd++) { 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 || (mode == 1 && team->fogOfWarMap[xd][yd][pos.z]==0) || (mode == -1 && team->fogOfWarMap[xd][yd][pos.z]==1) ) tiles.insert(int3(xd,yd,pos.z)); } } } } }
bool boundaryBetweenTwoPoints (int3 pos1, int3 pos2) //determines if two points are separated by known barrier { int xMin = std::min (pos1.x, pos2.x); int xMax = std::max (pos1.x, pos2.x); int yMin = std::min (pos1.y, pos2.y); int yMax = std::max (pos1.y, pos2.y); for (int x = xMin; x <= xMax; ++x) { for (int y = yMin; y <= yMax; ++y) { int3 tile = int3(x, y, pos1.z); //use only on same level, ofc if (abs(pos1.dist2d(tile) - pos2.dist2d(tile)) < 1.5) { if (!(cb->isVisible(tile) && cb->getTile(tile)->blocked)) //if there's invisible or unblocked tile inbetween, it's good return false; } } } return true; //if all are visible and blocked, we're at dead end }
int howManyTilesWillBeDiscovered(const int3 &pos, int radious) { //TODO: do not explore dead-end boundaries int ret = 0; for(int x = pos.x - radious; x <= pos.x + radious; x++) { for(int y = pos.y - radious; y <= pos.y + radious; y++) { int3 npos = int3(x,y,pos.z); if(cb->isInTheMap(npos) && pos.dist2d(npos) - 0.5 < radious && !cb->isVisible(npos)) { if (!boundaryBetweenTwoPoints (pos, npos)) ret++; } } } return ret; }