removeImprovement convenience function

This commit is contained in:
Yair Morgenstern 2023-08-08 19:29:33 +03:00
parent 55b4191be3
commit 417b6ff798
10 changed files with 22 additions and 22 deletions

View File

@ -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
}
}
}

View File

@ -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),

View File

@ -53,7 +53,7 @@ class CityFounder {
})
tile.removeTerrainFeature(terrainFeature)
tile.changeImprovement(null)
tile.removeImprovement()
tile.improvementInProgress = null
val ruleset = civInfo.gameInfo.ruleset

View File

@ -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()

View File

@ -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()
}

View File

@ -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)
}

View File

@ -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 }) {

View File

@ -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 {

View File

@ -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)
}

View File

@ -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()