public void TileMapGeneration()
{
int size = this.rows * this.roomSide;
// Generate list of points with a biome number associated
this.regions = new List<Region>();
int randomPointsRegion = (int)(size / Mathf.Sqrt(this.biomeNumber));
for (int i = 0; i < size; i += randomPointsRegion) {
for (int j = 0; j < size; j += randomPointsRegion) {
int randomX = Random.Range (0, randomPointsRegion) + j;
int randomY = Random.Range (0, randomPointsRegion) + i;
int biomeIndex = Random.Range (0, 6);
int altitude = Random.Range (0, 2);
// Don't put a forest or plains in the last biome
if ((i / randomPointsRegion + j / randomPointsRegion) == 9) {
while (biomeIndex == 0 || biomeIndex == 2) {
biomeIndex = Random.Range (0, 6);
}
// Don't put a mountain or desert in the first biome
} else if (i + j == 0) {
while (biomeIndex == 1 || biomeIndex == 3) {
biomeIndex = Random.Range (0, 6);
}
}
BiomeTile biome;
if (biomeIndex == 0) {
biome = this.ForestTile;
} else if (biomeIndex == 1) {
biome = this.DesertTile;
} else if (biomeIndex == 2) {
biome = this.PlainsTile;
} else if (biomeIndex == 3) {
biome = this.MountainTile;
} else if (biomeIndex == 4) {
biome = this.SnowTile;
} else {
biome = this.BeachTile;
}
this.regions.Add(new Region(randomX, randomY, biome, altitude));
}
}
// For each Tile, check for closest biome point
int skip = 15;
for (int i = 0; i < size; i+=skip) {
for (int j = 0; j < size; j+=skip) {
this.getBiome(i, j);
}
}
for (int i = 0; i < size; i+=skip) {
for (int j = 0; j < size; j+=skip) {
Tile topLeft = tileMap[i, j];
Tile topRight = (i + skip < size) ? tileMap[i + skip, j] : topLeft;
Tile bottemLeft = (j + skip < size) ? tileMap[i, j + skip] : topLeft;
Tile bottemRight = (j + skip < size && i + skip < size) ? tileMap[i + skip, j + skip] : topLeft;
if (topLeft.biome != topRight.biome ||
topLeft.biome != bottemLeft.biome ||
topLeft.biome != bottemRight.biome ||
topLeft.elevation != topRight.elevation ||
topLeft.elevation != bottemLeft.elevation ||
topLeft.elevation != bottemRight.elevation) {
for (int y = j; y < Mathf.Min(j + skip, size); y++) {
this.getBiome(i, y);
}
for (int y = j; y < Mathf.Min(j + skip, size); y++) {
this.getBiome(i, y);
if (i + skip < size) {
this.getBiome(i + skip, y);
}
Tile left = tileMap[i, y];
Tile right = (i + skip < size) ? tileMap[i + skip, y] : left;
if (left.biome != right.biome ||
left.elevation != right.elevation) {
for (int x = i + 1; x < Mathf.Min(i + skip, size); x++) {
this.getBiome(x, y);
}
} else {
for (int x = i + 1; x < Mathf.Min(i + skip, size); x++) {
tileMap[x, y] = new Tile (left, x, y);
this.regions[tileMap[x, y].regionIndex].tiles.Add(tileMap[x, y]);
}
}
}
} else {
for (int x = i; x < Mathf.Min(i + skip, size); x++) {
for (int y = j; y < Mathf.Min(j + skip, size); y++) {
tileMap[x, y] = new Tile (topLeft, x, y);
this.regions[tileMap[x, y].regionIndex].tiles.Add(tileMap[x, y]);
}
}
}
}
}
foreach (Region region in this.regions) {
region.ShuffleRegion();
}
}