ShapeProvider shapeProvider = generator.shapeProvider;
// backfill with buildings and parks
for (int x = 0; x < PlatMap.Width; x++) {
for (int z = 0; z < PlatMap.Width; z++) {
PlatLot current = platmap.getLot(x, z);
if (current == null) {
//TODO I need to come up with a more elegant way of doing this!
if (generator.settings.includeBuildings) {
// what to build?
boolean buildPark = platmapOdds.playOdds(oddsOfParks);
if (buildPark)
current = getPark(generator, platmap, platmapOdds, platmap.originX + x, platmap.originZ + z);
else
current = getBackfillLot(generator, platmap, platmapOdds, platmap.originX + x, platmap.originZ + z);
// see if the previous chunk is the same type
PlatLot previous = null;
if (x > 0 && current.isConnectable(platmap.getLot(x - 1, z))) {
previous = platmap.getLot(x - 1, z);
} else if (z > 0 && current.isConnectable(platmap.getLot(x, z - 1))) {
previous = platmap.getLot(x, z - 1);
}
// if there was a similar previous one then copy it... maybe
if (previous != null && !shapeProvider.isIsolatedLotAt(platmap.originX + x, platmap.originZ + z, oddsOfIsolatedLots)) {
current.makeConnected(previous);
// 2 by 2 at a minimum if at all possible
} else if (!buildPark && x < PlatMap.Width - 1 && z < PlatMap.Width - 1) {
// is there room?
PlatLot toEast = platmap.getLot(x + 1, z);
PlatLot toSouth = platmap.getLot(x, z + 1);
PlatLot toSouthEast = platmap.getLot(x + 1, z + 1);
if (toEast == null && toSouth == null && toSouthEast == null) {
toEast = current.newLike(platmap, platmap.originX + x + 1, platmap.originZ + z);
toEast.makeConnected(current);
platmap.setLot(x + 1, z, toEast);
toSouth = current.newLike(platmap, platmap.originX + x, platmap.originZ + z + 1);
toSouth.makeConnected(current);
platmap.setLot(x, z + 1, toSouth);
toSouthEast = current.newLike(platmap, platmap.originX + x + 1, platmap.originZ + z + 1);
toSouthEast.makeConnected(current);
platmap.setLot(x + 1, z + 1, toSouthEast);
}
}
}
// remember what we did
if (current != null)
platmap.setLot(x, z, current);
}
}
}
// validate each lot
for (int x = 0; x < PlatMap.Width; x++) {
for (int z = 0; z < PlatMap.Width; z++) {
PlatLot current = platmap.getLot(x, z);
if (current != null) {
PlatLot replacement = current.validateLot(platmap, x, z);
if (replacement != null)
platmap.setLot(x, z, replacement);
}
}
}