// Creates a list of Spawn Zones of varrying sizes in the map private void GenerateSpawnZones() { regions = mapGenerator.getRegions(); List <Pos> regionTiles = new List <Pos>(); int[,] grid = new int[width, height]; int distanceBetweenZones = 0; int spawnZoneRadius = 0; int radiusAndDistance = 0; int numOfSpawnZonesInRegion = 0; // Iterates through each region foreach (Region region in regions) { numOfSpawnZonesInRegion = 0; regionTiles = region.GetRegionTiles(); // Checks through each tile in the region foreach (Pos tile in regionTiles) { distanceBetweenZones = rng.Next(Mathf.Max(1, Mathf.RoundToInt(this.distanceBetweenZones / 2f)), Mathf.RoundToInt(this.distanceBetweenZones)); spawnZoneRadius = rng.Next(Mathf.RoundToInt(lowerRadius), Mathf.RoundToInt(upperRadius + 1)); radiusAndDistance = distanceBetweenZones + spawnZoneRadius; bool valid = true; while (!IsValid(tile, spawnZones, grid, spawnZoneRadius)) { // If smallest radius doesn't work, then it isn't a valid spawn point if (spawnZoneRadius == lowerRadius) { valid = false; break; } else { // Try a smaller radius spawnZoneRadius--; } } if (valid) { SpawnZone spawnZone = CreateSpawnZone(tile, spawnZoneRadius); // Checks if the number of zone tiles is acceptable if (spawnZone.GetNumberOfUnpopulatedTilesInZone() >= minimumNumberOfTilesInSpawnZone && spawnZone.GetNumberOfUnpopulatedTilesInZone() <= maximumNumberOfTilesInSpawnZone) { // Spawn Zone is accepted and added to the list spawnZones.Add(spawnZone); grid[tile.x, tile.y] = spawnZones.Count; numOfSpawnZonesInRegion++; } } } region.numOfSpawnZones = numOfSpawnZonesInRegion; } }