mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-10 23:37:31 +07:00
Remove tile improvements not in the current ruleset on normalizeTile
Mitigated mysterious crash in WorldMapHolder.updateTiles()
This commit is contained in:
parent
57f6c99d86
commit
dc55d31a58
@ -80,8 +80,8 @@ open class TileInfo {
|
||||
//Note to Future GGGuenni
|
||||
//TODO Use the following when terrainFeature got changed everywhere to support old saves in the future
|
||||
//if (terrainFeature != null){
|
||||
//terrainFeatures.add(terrainFeature)
|
||||
//terrainFeature = null
|
||||
//terrainFeatures.add(terrainFeature)
|
||||
//terrainFeature = null
|
||||
//}
|
||||
}
|
||||
|
||||
@ -392,7 +392,7 @@ open class TileInfo {
|
||||
|| filter == "River" && isAdjacentToRiver()
|
||||
|| terrainFeatures.contains(filter)
|
||||
|| baseTerrainObject.uniques.contains(filter)
|
||||
|| getTerrainFeatures().any {it.uniques.contains(filter)}
|
||||
|| getTerrainFeatures().any { it.uniques.contains(filter) }
|
||||
|| improvement == filter
|
||||
|| civInfo != null && hasViewableResource(civInfo) && resource == filter
|
||||
|| filter == "Water" && isWater
|
||||
@ -643,11 +643,15 @@ open class TileInfo {
|
||||
|
||||
|
||||
private fun normalizeTileImprovement(ruleset: Ruleset) {
|
||||
if (improvement!!.startsWith("StartingLocation")) {
|
||||
if (improvement!!.startsWith("StartingLocation") == true) {
|
||||
if (!isLand || getLastTerrain().impassable) improvement = null
|
||||
return
|
||||
}
|
||||
val improvementObject = ruleset.tileImprovements[improvement]!!
|
||||
val improvementObject = ruleset.tileImprovements[improvement]
|
||||
if (improvementObject == null) {
|
||||
improvement = null
|
||||
return
|
||||
}
|
||||
improvement = null // Unset, and check if it can be reset. If so, do it, if not, invalid.
|
||||
if (canImprovementBeBuiltHere(improvementObject)
|
||||
// Allow building 'other' improvements like city ruins, barb encampments, Great Improvements etc
|
||||
|
@ -13,11 +13,13 @@ import kotlin.math.pow
|
||||
class MapLandmassGenerator(val randomness: MapGenerationRandomness) {
|
||||
|
||||
fun generateLand(tileMap: TileMap, ruleset: Ruleset) {
|
||||
// This is to accommodate land-only mods
|
||||
if (ruleset.terrains.values.none { it.type == TerrainType.Water }) {
|
||||
for (tile in tileMap.values)
|
||||
tile.baseTerrain = ruleset.terrains.keys.first()
|
||||
return
|
||||
}
|
||||
|
||||
when (tileMap.mapParameters.type) {
|
||||
MapType.pangaea -> createPangea(tileMap)
|
||||
MapType.continents -> createTwoContinents(tileMap)
|
||||
@ -100,6 +102,8 @@ class MapLandmassGenerator(val randomness: MapGenerationRandomness) {
|
||||
longitudeFactor = min(longitudeFactor,
|
||||
(tileMap.maxLongitude - abs(tileInfo.longitude)) / tileMap.maxLongitude) * 1.5f
|
||||
|
||||
// there's nothing magical about this, it's just what we got from playing around with a lot of different options -
|
||||
// the numbers can be changed if you find that something else creates better looking continents
|
||||
return min(0.2, -1.0 + (5.0 * longitudeFactor.pow(0.6f) + randomScale) / 3.0)
|
||||
}
|
||||
|
||||
@ -130,7 +134,7 @@ class MapLandmassGenerator(val randomness: MapGenerationRandomness) {
|
||||
private fun generateLandCellularAutomata(tileMap: TileMap) {
|
||||
val numSmooth = 4
|
||||
|
||||
//init
|
||||
// init
|
||||
for (tile in tileMap.values) {
|
||||
val terrainType = getInitialTerrainCellularAutomata(tile, tileMap.mapParameters)
|
||||
if (terrainType == TerrainType.Land) tile.baseTerrain = Constants.grassland
|
||||
@ -144,7 +148,6 @@ class MapLandmassGenerator(val randomness: MapGenerationRandomness) {
|
||||
|
||||
for (loop in 0..numSmooth) {
|
||||
for (tileInfo in tileMap.values) {
|
||||
//if (HexMath.getDistance(Vector2.Zero, tileInfo.position) < mapRadius) {
|
||||
val numberOfLandNeighbors = tileInfo.neighbors.count { it.baseTerrain == grassland }
|
||||
if (tileInfo.baseTerrain == grassland) { // land tile
|
||||
if (numberOfLandNeighbors < 3)
|
||||
@ -153,9 +156,6 @@ class MapLandmassGenerator(val randomness: MapGenerationRandomness) {
|
||||
if (numberOfLandNeighbors > 3)
|
||||
tileInfo.baseTerrain = grassland
|
||||
}
|
||||
/*} else {
|
||||
tileInfo.baseTerrain = ocean
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -374,9 +374,11 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
|
||||
}
|
||||
}
|
||||
|
||||
for (group in tileGroups[selectedTile]!!) {
|
||||
group.showCircle(Color.WHITE)
|
||||
}
|
||||
// Same as below - randomly, tileGroups doesn't seem to contain the selected tile, and this doesn't seem duplicatable
|
||||
val worldTileGroupsForSelectedTile = tileGroups[selectedTile]
|
||||
if (worldTileGroupsForSelectedTile != null)
|
||||
for (group in worldTileGroupsForSelectedTile)
|
||||
group.showCircle(Color.WHITE)
|
||||
|
||||
zoom(scaleX) // zoom to current scale, to set the size of the city buttons after "next turn"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user