public void AttemptToSpawnAnEnemy(int securityLevel) { List <MapSquare> squares = new List <MapSquare>(); foreach (MapSquareRow row in rows) { squares.AddRange(row.GetMapSquares()); } List <MapSquare> unexploredEnemylessSquares = new List <MapSquare>(); List <MapSquare> exploredEnemylessSquare = new List <MapSquare>(); int enemyCount = 0; foreach (MapSquare square in squares) { if (square.IsActive()) { if (square.GetEnemy() == null && square.GetIsExplored()) { exploredEnemylessSquare.Add(square); } else if (square.GetEnemy() == null && !square.GetIsExplored()) { unexploredEnemylessSquares.Add(square); } else { enemyCount++; } } } // We add the unexplored ones twice, so there's double the chance of an unexplored // space spawning an enemy List <MapSquare> possibleGenerationSquares = new List <MapSquare>(); possibleGenerationSquares.AddRange(exploredEnemylessSquare); possibleGenerationSquares.AddRange(unexploredEnemylessSquares); possibleGenerationSquares.AddRange(unexploredEnemylessSquares); if (possibleGenerationSquares.Count > 0) { MapSquare squareToSpawn = possibleGenerationSquares[Random.Range(0, possibleGenerationSquares.Count - 1)]; MapData mapData = FindObjectOfType <MapData>(); squareToSpawn.SpawnEnemy(mapType, mapData.GetSecurityLevel(), mapData.GetJob()); Debug.Log("Spawned a new enemy"); } }