FVector minPoint;
minPoint.x = firstTerritory->GetMinX();
minPoint.y = firstTerritory->GetMinY();
minPoint.z = firstTerritory->GetMinZ();
FVector maxPoint;
maxPoint.x = firstTerritory->GetMaxX();
maxPoint.y = firstTerritory->GetMaxY();
maxPoint.z = firstTerritory->GetMaxZ();
for (int i = 0; i < territorySize; ++i)
{
CTerritory* territory = GetTerritory(i);
minPoint.x = min(minPoint.x, territory->GetMinX());
maxPoint.x = max(maxPoint.x, territory->GetMaxX());
minPoint.y = min(minPoint.y, territory->GetMinY());
maxPoint.y = max(maxPoint.y, territory->GetMaxY());
minPoint.z = min(minPoint.z, territory->GetMinZ());
maxPoint.z = max(maxPoint.z, territory->GetMaxZ());
}
// There is always 20x20 points distributed per territory
// Then each point checks for correct and reachable coordinate
// If it's OK, then this point added to the list
int stepsX = int(maxPoint.x - minPoint.x) / 20;
int stepsY = int(maxPoint.y - minPoint.y) / 20;
if (stepsX <= 0)
{
stepsX = 1;
}
if (stepsY <= 0)
{
stepsY = 1;
}
m_lock.Enter(__FILEW__, __LINE__);
const CGeoData* geodata = g_readonlyWorld.GetGeoData();
for (int x = int(minPoint.x); x < int(maxPoint.x); x += stepsX)
{
for (int y = int(minPoint.y); y < int(maxPoint.y); y += stepsY)
{
FVector spawnPoint;
spawnPoint.x = x;
spawnPoint.y = y;
spawnPoint.z = geodata->GetFloorZ((int)spawnPoint.x, (int)spawnPoint.y, (int)maxPoint.z);
if (IsGoodRandomSpawn(spawnPoint))
{
m_positions.push_back(spawnPoint);
}
}
}