diff --git a/core/src/com/unciv/logic/GameStarter.kt b/core/src/com/unciv/logic/GameStarter.kt index 8519de358b..c24f03604d 100644 --- a/core/src/com/unciv/logic/GameStarter.kt +++ b/core/src/com/unciv/logic/GameStarter.kt @@ -404,7 +404,7 @@ object GameStarter { if (tile.improvement != null && tile.getTileImprovement()!!.isAncientRuinsEquivalent() ) { - tile.changeImprovement(null) // Remove ancient ruins in immediate vicinity + tile.removeImprovement() // Remove ancient ruins in immediate vicinity } } } diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index 2c0180d422..e8c0a25b1e 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -892,7 +892,7 @@ object Battle { fun applyPillageAndFallout() { if (tile.getUnpillagedImprovement() != null && !tile.getTileImprovement()!!.hasUnique(UniqueType.Irremovable)) { if (tile.getTileImprovement()!!.hasUnique(UniqueType.Unpillagable)) { - tile.changeImprovement(null) + tile.removeImprovement() } else { tile.setPillaged() } @@ -1202,7 +1202,7 @@ object Battle { && attacker.hasUnique(UniqueType.DestroysImprovementUponAttack, conditionalState) ) { val currentTileImprovement = attackedTile.improvement - attackedTile.changeImprovement(null) + attackedTile.removeImprovement() defender.getCivInfo().addNotification( "An enemy [${attacker.unit.baseUnit.name}] has destroyed our tile improvement [${currentTileImprovement}]", LocationAction(attackedTile.position, attacker.getTile().position), diff --git a/core/src/com/unciv/logic/city/managers/CityFounder.kt b/core/src/com/unciv/logic/city/managers/CityFounder.kt index 686c116ddf..e21219b086 100644 --- a/core/src/com/unciv/logic/city/managers/CityFounder.kt +++ b/core/src/com/unciv/logic/city/managers/CityFounder.kt @@ -53,7 +53,7 @@ class CityFounder { }) tile.removeTerrainFeature(terrainFeature) - tile.changeImprovement(null) + tile.removeImprovement() tile.improvementInProgress = null val ruleset = civInfo.gameInfo.ruleset diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index 632b8237fa..54eeb96fe8 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -615,7 +615,7 @@ class TileMap(initialCapacity: Int = 10) : IsPartOfGameInfoSerialization { .map { it to StartingLocation(it.position, it.improvement!!.removePrefix(startingLocationPrefix)) } .sortedBy { it.second.nation } // vanity, or to make diffs between un-gzipped map files easier .forEach { (tile, startingLocation) -> - tile.changeImprovement(null) + tile.removeImprovement() startingLocations.add(startingLocation) } setStartingLocationsTransients() diff --git a/core/src/com/unciv/logic/map/mapgenerator/NaturalWonderGenerator.kt b/core/src/com/unciv/logic/map/mapgenerator/NaturalWonderGenerator.kt index 81e42f0f7c..736d20c8ae 100644 --- a/core/src/com/unciv/logic/map/mapgenerator/NaturalWonderGenerator.kt +++ b/core/src/com/unciv/logic/map/mapgenerator/NaturalWonderGenerator.kt @@ -1,14 +1,14 @@ package com.unciv.logic.map.mapgenerator import com.unciv.Constants -import com.unciv.utils.debug -import com.unciv.logic.map.tile.Tile import com.unciv.logic.map.TileMap +import com.unciv.logic.map.tile.Tile import com.unciv.models.ruleset.Ruleset import com.unciv.models.ruleset.tile.Terrain import com.unciv.models.ruleset.tile.TerrainType import com.unciv.models.ruleset.unique.Unique import com.unciv.models.ruleset.unique.UniqueType +import com.unciv.utils.debug import kotlin.math.abs import kotlin.math.roundToInt @@ -204,7 +204,7 @@ class NaturalWonderGenerator(val ruleset: Ruleset, val randomness: MapGeneration private fun clearTile(tile: Tile){ tile.setTerrainFeatures(listOf()) tile.resource = null - tile.changeImprovement(null) + tile.removeImprovement() tile.setTerrainTransients() } diff --git a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt index 6fa1673bb7..c571ad693a 100644 --- a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt +++ b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt @@ -648,7 +648,7 @@ class MapUnit : IsPartOfGameInfoSerialization { } private fun clearEncampment(tile: Tile) { - tile.changeImprovement(null) + tile.removeImprovement() // Notify City-States that this unit cleared a Barbarian Encampment, required for quests civ.gameInfo.getAliveCityStates() @@ -699,7 +699,7 @@ class MapUnit : IsPartOfGameInfoSerialization { } private fun getAncientRuinBonus(tile: Tile) { - tile.changeImprovement(null) + tile.removeImprovement() civ.ruinsManager.selectNextRuinsReward(this) } diff --git a/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt b/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt index 76ce97598a..eb7c1fd1eb 100644 --- a/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt +++ b/core/src/com/unciv/logic/map/mapunit/UnitTurnManager.kt @@ -189,7 +189,7 @@ class UnitTurnManager(val unit: MapUnit) { && !tileImprovement.terrainsCanBeBuiltOn.contains(tile.baseTerrain) ) { // We removed a terrain (e.g. Forest) and the improvement (e.g. Lumber mill) requires it! - tile.changeImprovement(null) + tile.removeImprovement() if (tile.resource != null) unit.civ.cache.updateCivResources() // unlikely, but maybe a mod makes a resource improvement dependent on a terrain feature } if (RoadStatus.values().any { tile.improvementInProgress == it.removeAction }) { diff --git a/core/src/com/unciv/logic/map/tile/Tile.kt b/core/src/com/unciv/logic/map/tile/Tile.kt index 250d00e6a0..4cd142126b 100644 --- a/core/src/com/unciv/logic/map/tile/Tile.kt +++ b/core/src/com/unciv/logic/map/tile/Tile.kt @@ -308,6 +308,9 @@ open class Tile : IsPartOfGameInfoSerialization { else ruleset.tileImprovements[getUnpillagedRoad().name] } + /** Does not remove roads */ + fun removeImprovement() = changeImprovement(null) + fun changeImprovement(improvementStr: String?) { improvementIsPillaged = false improvement = improvementStr @@ -893,7 +896,7 @@ open class Tile : IsPartOfGameInfoSerialization { if (resource != null && resource !in ruleset.tileResources) resource = null if (improvement != null && improvement !in ruleset.tileImprovements) - changeImprovement(null) + removeImprovement() } /** If the unit isn't in the ruleset we can't even know what type of unit this is! So check each place @@ -927,7 +930,7 @@ open class Tile : IsPartOfGameInfoSerialization { // http://well-of-souls.com/civ/civ5_improvements.html says that naval improvements are destroyed upon pillage // and I can't find any other sources so I'll go with that if (!isLand) { - changeImprovement(null) + removeImprovement() owningCity?.reassignPopulationDeferred() return } @@ -939,7 +942,7 @@ open class Tile : IsPartOfGameInfoSerialization { // if no Repair action, destroy improvements instead if (ruleset.tileImprovements[Constants.repair] == null) { if (canPillageTileImprovement()) - changeImprovement(null) + removeImprovement() else removeRoad() } else { diff --git a/core/src/com/unciv/ui/screens/mapeditorscreen/TileInfoNormalizer.kt b/core/src/com/unciv/ui/screens/mapeditorscreen/TileInfoNormalizer.kt index 10486a6025..b9f6242dc5 100644 --- a/core/src/com/unciv/ui/screens/mapeditorscreen/TileInfoNormalizer.kt +++ b/core/src/com/unciv/ui/screens/mapeditorscreen/TileInfoNormalizer.kt @@ -15,7 +15,7 @@ object TileInfoNormalizer { tile.baseTerrain = tile.getNaturalWonder().turnsInto!! tile.setTerrainFeatures(listOf()) tile.resource = null - tile.changeImprovement(null) + tile.removeImprovement() } if (!ruleset.terrains.containsKey(tile.baseTerrain)) @@ -47,11 +47,8 @@ object TileInfoNormalizer { private fun normalizeTileImprovement(tile: Tile, ruleset: Ruleset) { val improvementObject = ruleset.tileImprovements[tile.improvement] - if (improvementObject == null) { - tile.changeImprovement(null) - return - } - tile.changeImprovement(null) // Unset, and check if it can be reset. If so, do it, if not, invalid. + tile.removeImprovement() // Unset, and check if it can be reset. If so, do it, if not, invalid. + if (improvementObject == null) return if (tile.improvementFunctions.canImprovementBeBuiltHere(improvementObject, stateForConditionals = StateForConditionals.IgnoreConditionals)) tile.changeImprovement(improvementObject.name) } diff --git a/core/src/com/unciv/ui/screens/mapeditorscreen/tabs/MapEditorEditSubTabs.kt b/core/src/com/unciv/ui/screens/mapeditorscreen/tabs/MapEditorEditSubTabs.kt index 1923346d31..933dccfd80 100644 --- a/core/src/com/unciv/ui/screens/mapeditorscreen/tabs/MapEditorEditSubTabs.kt +++ b/core/src/com/unciv/ui/screens/mapeditorscreen/tabs/MapEditorEditSubTabs.kt @@ -20,8 +20,8 @@ import com.unciv.ui.audio.MusicMood import com.unciv.ui.audio.MusicTrackChooserFlags import com.unciv.ui.components.TabbedPager import com.unciv.ui.components.extensions.center -import com.unciv.ui.components.input.onClick import com.unciv.ui.components.extensions.toLabel +import com.unciv.ui.components.input.onClick import com.unciv.ui.components.tilegroups.TileGroup import com.unciv.ui.components.tilegroups.TileSetStrings import com.unciv.ui.images.ImageGetter @@ -208,7 +208,7 @@ class MapEditorEditImprovementsTab( val eraser = FormattedLine("Remove improvement", icon = eraserIcon, size = 32, iconCrossed = true) add(eraser.render(0f).apply { onClick { editTab.setBrush("Remove improvement", eraserIcon, true) { tile -> - tile.changeImprovement(null) + tile.removeImprovement() tile.removeRoad() } } }).padBottom(0f).row()