From 9a1e904b6697f2333a69b55bdfeb71a49b07dcd3 Mon Sep 17 00:00:00 2001 From: yairm210 Date: Tue, 10 Dec 2024 11:06:53 +0200 Subject: [PATCH] Added river mirroring --- core/src/com/unciv/logic/map/MapParameters.kt | 2 +- .../logic/map/mapgenerator/MapGenerator.kt | 37 ++++++++++++------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/core/src/com/unciv/logic/map/MapParameters.kt b/core/src/com/unciv/logic/map/MapParameters.kt index 04769cada2..063bdd9799 100644 --- a/core/src/com/unciv/logic/map/MapParameters.kt +++ b/core/src/com/unciv/logic/map/MapParameters.kt @@ -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! diff --git a/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt b/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt index 72a6707b2a..fc69d9ec5f 100644 --- a/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt +++ b/core/src/com/unciv/logic/map/mapgenerator/MapGenerator.kt @@ -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) } }