From 231963f050b2cb3f770158b881811cedcdcc22c6 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 26 Jan 2022 18:20:21 +0200 Subject: [PATCH] Game can now handle improvements with no special stats from resources --- core/src/com/unciv/logic/map/TileInfo.kt | 17 ++++++++++------- .../unciv/logic/map/UnitMovementAlgorithms.kt | 14 +++++++------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index d60f09fa01..b9b38c7db0 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -382,7 +382,9 @@ open class TileInfo { fun getImprovementStats(improvement: TileImprovement, observingCiv: CivilizationInfo, city: CityInfo?): Stats { val stats = improvement.cloneStats() - if (hasViewableResource(observingCiv) && tileResource.improvement == improvement.name) + if (hasViewableResource(observingCiv) && tileResource.improvement == improvement.name + && tileResource.improvementStats != null + ) stats.add(tileResource.improvementStats!!.clone()) // resource-specific improvement val conditionalState = StateForConditionals(civInfo = observingCiv, cityInfo = city) @@ -395,14 +397,15 @@ open class TileInfo { .filter { city.matchesFilter(it.params[2]) } val improvementUniques = improvement.getMatchingUniques(UniqueType.ImprovementStatsOnTile, conditionalState) - + for (unique in tileUniques + improvementUniques) { if (improvement.matchesFilter(unique.params[1]) // Freshwater and non-freshwater cannot be moved to matchesUniqueFilter since that creates an endless feedback. // If you're attempting that, check that it works! || unique.params[1] == "Fresh water" && isAdjacentToFreshwater - || unique.params[1] == "non-fresh water" && !isAdjacentToFreshwater) - stats.add(unique.stats) + || unique.params[1] == "non-fresh water" && !isAdjacentToFreshwater + ) + stats.add(unique.stats) } for (unique in city.getMatchingUniques(UniqueType.StatsFromObject)) { @@ -416,13 +419,13 @@ open class TileInfo { val adjacent = unique.params[1] val numberOfBonuses = neighbors.count { it.matchesFilter(adjacent, observingCiv) - || it.roadStatus.name == adjacent + || it.roadStatus.name == adjacent } stats.add(unique.stats.times(numberOfBonuses.toFloat())) } - for (unique in observingCiv.getMatchingUniques(UniqueType.AllStatsPercentFromObject) + - observingCiv.getMatchingUniques(UniqueType.AllStatsSignedPercentFromObject) + for (unique in observingCiv.getMatchingUniques(UniqueType.AllStatsPercentFromObject) + + observingCiv.getMatchingUniques(UniqueType.AllStatsSignedPercentFromObject) ) if (improvement.matchesFilter(unique.params[1])) stats.timesInPlace(unique.params[0].toPercent()) diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index 895894c12b..673dd1d545 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -150,18 +150,18 @@ class UnitMovementAlgorithms(val unit:MapUnit) { val updatedTiles = ArrayList() for (tileToCheck in tilesToCheck) for (neighbor in tileToCheck.neighbors) { - var totalDistanceToTile: Float = if (unit.civInfo.exploredTiles.contains(neighbor.position)) { - if (!canPassThrough(neighbor)) - unitMovement // Can't go here. + var totalDistanceToTile: Float = when { + !unit.civInfo.exploredTiles.contains(neighbor.position) -> + distanceToTiles[tileToCheck]!!.totalDistance + 1f // If we don't know then we just guess it to be 1. + !canPassThrough(neighbor) -> unitMovement // Can't go here. // The reason that we don't just "return" is so that when calculating how to reach an enemy, // You need to assume his tile is reachable, otherwise all movement algorithms on reaching enemy // cities and units goes kaput. - - else { + else -> { val distanceBetweenTiles = getMovementCostBetweenAdjacentTiles(tileToCheck, neighbor, unit.civInfo, considerZoneOfControl) distanceToTiles[tileToCheck]!!.totalDistance + distanceBetweenTiles } - } else distanceToTiles[tileToCheck]!!.totalDistance + 1f // If we don't know then we just guess it to be 1. + } if (!distanceToTiles.containsKey(neighbor) || distanceToTiles[neighbor]!!.totalDistance > totalDistanceToTile) { // this is the new best path if (totalDistanceToTile < unitMovement) // We can still keep moving from here! @@ -592,7 +592,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) { if (tile.isImpassible()) { // special exception - ice tiles are technically impassible, but some units can move through them anyway // helicopters can pass through impassable tiles like mountains - if (!(tile.terrainFeatures.contains(Constants.ice) && unit.canEnterIceTiles) && !unit.canPassThroughImpassableTiles + if (!unit.canPassThroughImpassableTiles && !(unit.canEnterIceTiles && tile.terrainFeatures.contains(Constants.ice)) // carthage-like uniques sometimes allow passage through impassible tiles && !(unit.civInfo.passThroughImpassableUnlocked && unit.civInfo.passableImpassables.contains(tile.getLastTerrain().name))) return false