Added river mirroring

This commit is contained in:
yairm210 2024-12-10 11:06:53 +02:00
parent 4160f343bf
commit 9a1e904b66
2 changed files with 24 additions and 15 deletions

View File

@ -54,7 +54,7 @@ class MapParameters : IsPartOfGameInfoSerialization {
var shape = MapShape.hexagonal
var mapSize = MapSize.Medium
var mapResources = MapResourceSetting.default.label
var mirroring: String = MirroringType.none
var mirroring: String = MirroringType.fourway
var noRuins = false
var noNaturalWonders = false
// DO NOT CHANGE DEFAULTS since that changes all existing games to new default!

View File

@ -185,33 +185,42 @@ class MapGenerator(val ruleset: Ruleset, private val coroutineScope: CoroutineSc
private fun flipLeftRight(vector: Vector2): Vector2 = Vector2(vector.y, vector.x)
private fun mirror(map: TileMap) {
if (map.mapParameters.mirroring == MirroringType.none) return
fun copyTile(tile: Tile, mirroringType: String) {
val mirrorTileVector = when (mirroringType){
MirroringType.topbottom -> if (tile.getRow() <= 0) return else flipTopBottom(tile.position)
MirroringType.leftright -> if (tile.getColumn() <= 0) return else flipLeftRight(tile.position)
MirroringType.aroundCenterTile -> if (tile.getRow() <= 0) return else flipLeftRight(flipTopBottom(tile.position))
fun getMirrorTile(tile: Tile, mirroringType: String): Tile? {
val mirrorTileVector = when (mirroringType) {
MirroringType.topbottom -> if (tile.getRow() <= 0) return null else flipTopBottom(tile.position)
MirroringType.leftright -> if (tile.getColumn() <= 0) return null else flipLeftRight(tile.position)
MirroringType.aroundCenterTile -> if (tile.getRow() <= 0) return null else flipLeftRight(flipTopBottom(tile.position))
MirroringType.fourway -> when {
tile.getRow() < 0 && tile.getColumn() < 0 -> return
tile.getRow() < 0 -> flipTopBottom(tile.position)
tile.getColumn() < 0 -> flipLeftRight(tile.position)
tile.getRow() < 0 && tile.getColumn() < 0 -> return null
tile.getRow() < 0 && tile.getColumn() >= 0 -> flipLeftRight(tile.position)
tile.getRow() >= 0 && tile.getColumn() < 0 -> flipTopBottom(tile.position)
else -> flipLeftRight(flipTopBottom(tile.position))
}
else -> return
else -> return null
}
return map.getIfTileExistsOrNull(mirrorTileVector.x.toInt(), mirrorTileVector.y.toInt())
}
fun copyTile(tile: Tile, mirroringType: String) {
val mirrorTile = getMirrorTile(tile, mirroringType) ?: return
val mirrorTile = map.getIfTileExistsOrNull(mirrorTileVector.x.toInt(), mirrorTileVector.y.toInt()) ?: return
tile.setBaseTerrain(mirrorTile.getBaseTerrain())
// todo rivers are a bitch
tile.naturalWonder = mirrorTile.naturalWonder
tile.setTerrainFeatures(mirrorTile.terrainFeatures)
tile.resource = mirrorTile.resource
tile.improvement = mirrorTile.improvement
for (neighbor in tile.neighbors){
val neighborMirror = getMirrorTile(neighbor, mirroringType) ?: continue
if (neighborMirror !in mirrorTile.neighbors) continue // we landed on the edge here
tile.setConnectedByRiver(neighbor, mirrorTile.isConnectedByRiver(neighborMirror))
}
}
if (map.mapParameters.mirroring == MirroringType.none) return
for (tile in map.values) {
copyTile(tile, MirroringType.topbottom)
copyTile(tile, map.mapParameters.mirroring)
}
}