Fixed natural wonders not being considered 'impassible' for certain things (e.g. ancient ruins spawn)

This commit is contained in:
Yair Morgenstern 2020-06-27 23:40:40 +03:00
parent 3a42be7b77
commit cba9995f99
9 changed files with 16 additions and 16 deletions

View file

@ -183,9 +183,8 @@ class GameInfo {
val tilesWithin3ofExistingEncampment = existingEncampments.asSequence()
.flatMap { it.getTilesInDistance(3) }.toSet()
val viableTiles = tileMap.values.filter {
!it.getBaseTerrain().impassable && it.isLand
&& it.terrainFeature == null
&& it.naturalWonder == null
it.isLand && it.terrainFeature == null
&& !it.isImpassible()
&& it !in tilesWithin3ofExistingEncampment
&& it !in allViewableTiles
}

View file

@ -156,11 +156,11 @@ object GameStarter {
private fun getStartingLocations(civs: List<CivilizationInfo>, tileMap: TileMap): HashMap<CivilizationInfo, TileInfo> {
var landTiles = tileMap.values
// Games starting on snow might as well start over...
.filter { it.isLand && !it.getBaseTerrain().impassable && it.baseTerrain!=Constants.snow }
.filter { it.isLand && !it.isImpassible() && it.baseTerrain!=Constants.snow }
val landTilesInBigEnoughGroup = ArrayList<TileInfo>()
while (landTiles.any()) {
val bfs = BFS(landTiles.random()) { it.isLand && !it.getBaseTerrain().impassable }
val bfs = BFS(landTiles.random()) { it.isLand && !it.isImpassible() }
bfs.stepToEnd()
val tilesInGroup = bfs.tilesReached.keys
landTiles = landTiles.filter { it !in tilesInGroup }

View file

@ -429,7 +429,7 @@ object NextTurnAutomation{
val landPathBFS = BFS(ourCity.getCenterTile()) {
val owner = it.getOwner();
it.isLand && !it.getBaseTerrain().impassable
it.isLand && !it.isImpassible()
&& (owner == otherCiv || owner == null || civInfo.canEnterTiles(owner))
}

View file

@ -139,7 +139,7 @@ class WorkerAutomation(val unit: MapUnit) {
}
private fun tileCanBeImproved(tile: TileInfo, civInfo: CivilizationInfo): Boolean {
if (!tile.isLand || tile.getBaseTerrain().impassable || tile.isCityCenter())
if (!tile.isLand || tile.isImpassible() || tile.isCityCenter())
return false
val city=tile.getCity()
if (city == null || city.civInfo != civInfo)

View file

@ -111,6 +111,7 @@ open class TileInfo {
fun isCityCenter(): Boolean = getCity()?.location == position
fun isNaturalWonder(): Boolean = naturalWonder != null
fun isImpassible() = getLastTerrain().impassable
fun getTileImprovement(): TileImprovement? = if (improvement == null) null else ruleset.tileImprovements[improvement!!]
@ -400,7 +401,7 @@ open class TileInfo {
if (!defencePercentString.startsWith("-")) defencePercentString = "+$defencePercentString"
lineList += "[$defencePercentString] to unit defence".tr()
}
if (getBaseTerrain().impassable) lineList += Constants.impassable.tr()
if (isImpassible()) lineList += Constants.impassable.tr()
return lineList.joinToString("\n")
}

View file

@ -327,7 +327,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
// so multiple callees of this function have been optimized,
// because optimization on this function results in massive benefits!
fun canPassThrough(tile: TileInfo): Boolean {
if (tile.getBaseTerrain().impassable) return false
if (tile.isImpassible()) return false
if (tile.isLand
&& unit.type.isWaterUnit()
// Check that the tile is not a coastal city's center

View file

@ -104,7 +104,7 @@ class MapGenerator(val ruleset: Ruleset) {
private fun spreadAncientRuins(map: TileMap) {
if(map.mapParameters.noRuins)
return
val suitableTiles = map.values.filter { it.isLand && !it.getBaseTerrain().impassable }
val suitableTiles = map.values.filter { it.isLand && !it.isImpassible() }
val locations = randomness.chooseSpreadOutLocations(suitableTiles.size/100,
suitableTiles, 10)
for(tile in locations)
@ -126,7 +126,7 @@ class MapGenerator(val ruleset: Ruleset) {
private fun spreadStrategicResources(tileMap: TileMap, distance: Int) {
val strategicResources = ruleset.tileResources.values.filter { it.resourceType == ResourceType.Strategic }
// passable land tiles (no mountains, no wonders) without resources yet
val candidateTiles = tileMap.values.filter { it.resource == null && !it.getLastTerrain().impassable }
val candidateTiles = tileMap.values.filter { it.resource == null && !it.isImpassible() }
val totalNumberOfResources = candidateTiles.size * tileMap.mapParameters.resourceRichness
val resourcesPerType = (totalNumberOfResources/strategicResources.size).toInt()
for (resource in strategicResources) {
@ -150,7 +150,7 @@ class MapGenerator(val ruleset: Ruleset) {
val suitableTiles = tileMap.values
.filter { it.resource == null && resourcesOfType.any { r -> r.terrainsCanBeFoundOn.contains(it.getLastTerrain().name) } }
val numberOfResources = tileMap.values.count { it.isLand && !it.getBaseTerrain().impassable } *
val numberOfResources = tileMap.values.count { it.isLand && !it.isImpassible() } *
tileMap.mapParameters.resourceRichness
val locations = randomness.chooseSpreadOutLocations(numberOfResources.toInt(), suitableTiles, distance)

View file

@ -503,18 +503,18 @@ class TileEditorOptionsTable(val mapEditorScreen: MapEditorScreen): Table(Camera
if (tileInfo.improvement!=null) {
normalizeTileImprovement(tileInfo)
}
if (tileInfo.getBaseTerrain().impassable || tileInfo.isWater)
if (tileInfo.isWater || tileInfo.isImpassible())
tileInfo.roadStatus= RoadStatus.None
}
private fun normalizeTileImprovement(tileInfo: TileInfo) {
val topTerrain = tileInfo.getLastTerrain()
if (tileInfo.improvement!!.startsWith("StartingLocation")) {
if (!tileInfo.isLand || tileInfo.getBaseTerrain().impassable)
if (!tileInfo.isLand || topTerrain.impassable)
tileInfo.improvement = null
return
}
val improvement = tileInfo.getTileImprovement()!!
val topTerrain = tileInfo.getLastTerrain()
val resource = if (tileInfo.resource!=null) tileInfo.getTileResource() else null
when {
// Precedence, simplified: terrainsCanBeBuiltOn, then improves-resource, then 'everywhere', default to false

View file

@ -376,7 +376,7 @@ object UnitActions {
addGoldPerGreatPersonUsage(unit.civInfo)
unit.destroy()
}.takeIf { unit.currentMovement > 0f && !tile.isWater &&
!tile.isCityCenter() && !tile.getLastTerrain().impassable &&
!tile.isCityCenter() && !tile.isImpassible() &&
tile.improvement != improvementName &&
// citadel can be built only next to or within own borders
(improvementName != Constants.citadel ||