Workers now remove fallout and similar stat-hindering terrains
This commit is contained in:
Yair Morgenstern 2023-08-02 11:46:26 +03:00
parent ad75ad916b
commit 8de47b4a62
3 changed files with 11 additions and 2 deletions

View File

@ -342,12 +342,12 @@ class WorkerAutomation(
val junkImprovement = tile.getTileImprovement()?.hasUnique(UniqueType.AutomatedWorkersWillReplace) == true
|| (tile.improvement == Constants.fort && !evaluateFortSuroundings(tile, false) && !civInfo.isHuman())
if (tile.improvement != null && junkImprovement == false
if (tile.improvement != null && !junkImprovement
&& !UncivGame.Current.settings.automatedWorkersReplaceImprovements
&& unit.civ.isHuman())
return false
if (tile.improvement == null || junkImprovement == true) {
if (tile.improvement == null || junkImprovement) {
if (tile.improvementInProgress != null && unit.canBuildImprovement(tile.getTileImprovementInProgress()!!, tile)) return true
val chosenImprovement = chooseImprovement(unit, tile)
if (chosenImprovement != null && tile.improvementFunctions.canBuildImprovement(chosenImprovement, civInfo) && unit.canBuildImprovement(chosenImprovement, tile)) return true

View File

@ -201,6 +201,14 @@ class TileStatFunctions(val tile: Tile) {
city: City?,
cityUniqueCache: LocalUniqueCache = LocalUniqueCache(false)
): Stats {
if (improvement.name.startsWith(Constants.remove)){
val currentTileStats = getTileStats(city, observingCiv, cityUniqueCache)
val tileClone = tile.clone()
tileClone.removeTerrainFeature(improvement.name.removePrefix(Constants.remove))
val tileStatsAfterRemoval = tileClone.stats.getTileStats(city, observingCiv, cityUniqueCache)
return tileStatsAfterRemoval.minus(currentTileStats)
}
val stats = improvement.cloneStats()
if (tile.hasViewableResource(observingCiv) && tile.tileResource.isImprovedBy(improvement.name)
&& tile.tileResource.improvementStats != null

View File

@ -94,6 +94,7 @@ open class Stats(
/** @return a new [Stats] instance containing the sum of its operands value by value */
operator fun plus(stats: Stats) = clone().apply { add(stats) }
operator fun minus(stats: Stats) = clone().apply { add(stats.times(-1)) }
/** Adds the [value] parameter to the instance value specified by [stat] in place
* @return `this` to allow chaining */