mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 22:00:24 +07:00
Update all improvement and road writes to use TileInfo setters (#8136)
This commit is contained in:
@ -132,7 +132,7 @@ class BarbarianManager : IsPartOfGameInfoSerialization {
|
||||
} else
|
||||
tile = viableTiles.random()
|
||||
|
||||
tile.improvement = Constants.barbarianEncampment
|
||||
tile.changeImprovement(Constants.barbarianEncampment)
|
||||
val newCamp = Encampment(tile.position)
|
||||
newCamp.gameInfo = gameInfo
|
||||
camps[newCamp.position] = newCamp
|
||||
|
@ -316,7 +316,7 @@ object GameStarter {
|
||||
if (tile.improvement != null
|
||||
&& tile.getTileImprovement()!!.isAncientRuinsEquivalent()
|
||||
) {
|
||||
tile.improvement = null // Remove ancient ruins in immediate vicinity
|
||||
tile.changeImprovement(null) // Remove ancient ruins in immediate vicinity
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -779,7 +779,7 @@ object Battle {
|
||||
// Pillage improvements, pillage roads, add fallout
|
||||
if (tile.getUnpillagedImprovement() != null && !tile.getTileImprovement()!!.hasUnique(UniqueType.Irremovable)) {
|
||||
if (tile.getTileImprovement()!!.hasUnique(UniqueType.Unpillagable)) {
|
||||
tile.improvement = null
|
||||
tile.changeImprovement(null)
|
||||
} else {
|
||||
tile.setPillaged()
|
||||
}
|
||||
@ -1106,7 +1106,7 @@ object Battle {
|
||||
&& attackedTile.getTileImprovement()?.isAncientRuinsEquivalent() != true
|
||||
&& attacker.hasUnique(UniqueType.DestroysImprovementUponAttack, conditionalState)
|
||||
) {
|
||||
attackedTile.improvement = null
|
||||
attackedTile.changeImprovement(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -665,7 +665,7 @@ class CityConstructions : IsPartOfGameInfoSerialization {
|
||||
tileForImprovement.stopWorkingOnImprovement() // clears mark
|
||||
if (removeOnly) return
|
||||
/**todo unify with [UnitActions.getImprovementConstructionActions] and [MapUnit.workOnImprovement] - this won't allow e.g. a building to place a road */
|
||||
tileForImprovement.improvement = improvement.name
|
||||
tileForImprovement.changeImprovement(improvement.name)
|
||||
cityInfo.civInfo.lastSeenImprovement[tileForImprovement.position] = improvement.name
|
||||
cityInfo.cityStats.update()
|
||||
cityInfo.civInfo.updateDetailedCivResources()
|
||||
|
@ -186,7 +186,7 @@ class CityInfo : IsPartOfGameInfoSerialization {
|
||||
})
|
||||
tile.removeTerrainFeature(terrainFeature)
|
||||
|
||||
tile.improvement = null
|
||||
tile.changeImprovement(null)
|
||||
tile.improvementInProgress = null
|
||||
|
||||
val ruleset = civInfo.gameInfo.ruleSet
|
||||
@ -770,7 +770,7 @@ class CityInfo : IsPartOfGameInfoSerialization {
|
||||
expansion.relinquishOwnership(tile)
|
||||
}
|
||||
civInfo.cities = civInfo.cities.toMutableList().apply { remove(this@CityInfo) }
|
||||
getCenterTile().improvement = "City ruins"
|
||||
getCenterTile().changeImprovement("City ruins")
|
||||
|
||||
// Edge case! What if a water unit is in a city, and you raze the city?
|
||||
// Well, the water unit has to return to the water!
|
||||
|
@ -727,8 +727,7 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
||||
&& !tileImprovement.terrainsCanBeBuiltOn.contains(tile.baseTerrain)
|
||||
) {
|
||||
// We removed a terrain (e.g. Forest) and the improvement (e.g. Lumber mill) requires it!
|
||||
tile.improvement = null
|
||||
tile.improvementIsPillaged = false
|
||||
tile.changeImprovement(null)
|
||||
if (tile.resource != null) civInfo.updateDetailedCivResources() // unlikely, but maybe a mod makes a resource improvement dependent on a terrain feature
|
||||
}
|
||||
if (RoadStatus.values().any { tile.improvementInProgress == it.removeAction }) {
|
||||
@ -747,8 +746,7 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
||||
else -> {
|
||||
val improvement = civInfo.gameInfo.ruleSet.tileImprovements[tile.improvementInProgress]!!
|
||||
improvement.handleImprovementCompletion(this)
|
||||
tile.improvement = tile.improvementInProgress
|
||||
tile.improvementIsPillaged = false
|
||||
tile.changeImprovement(tile.improvementInProgress)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1023,7 +1021,7 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
||||
}
|
||||
|
||||
private fun clearEncampment(tile: TileInfo) {
|
||||
tile.improvement = null
|
||||
tile.changeImprovement(null)
|
||||
|
||||
// Notify City-States that this unit cleared a Barbarian Encampment, required for quests
|
||||
civInfo.gameInfo.getAliveCityStates()
|
||||
@ -1073,7 +1071,7 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
||||
}
|
||||
|
||||
private fun getAncientRuinBonus(tile: TileInfo) {
|
||||
tile.improvement = null
|
||||
tile.changeImprovement(null)
|
||||
civInfo.ruinsManager.selectNextRuinsReward(this)
|
||||
}
|
||||
|
||||
|
@ -273,6 +273,11 @@ open class TileInfo : IsPartOfGameInfoSerialization {
|
||||
roadStatus
|
||||
}
|
||||
|
||||
fun changeImprovement(improvementStr: String?) {
|
||||
improvementIsPillaged = false
|
||||
improvement = improvementStr
|
||||
}
|
||||
|
||||
// function handling when adding a road to the tile
|
||||
fun addRoad(roadType: RoadStatus, unitCivInfo: CivilizationInfo) {
|
||||
roadStatus = roadType
|
||||
@ -1291,7 +1296,7 @@ open class TileInfo : IsPartOfGameInfoSerialization {
|
||||
return
|
||||
// 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) { improvement = null; return }
|
||||
if (!isLand) { changeImprovement(null); return }
|
||||
|
||||
// Setting turnsToImprovement might interfere with UniqueType.CreatesOneImprovement
|
||||
removeCreatesOneImprovementMarker()
|
||||
@ -1300,9 +1305,9 @@ open class TileInfo : IsPartOfGameInfoSerialization {
|
||||
// if no Repair action, destroy improvements instead
|
||||
if (ruleset.tileImprovements[Constants.repair] == null) {
|
||||
if (canPillageTileImprovement())
|
||||
improvement = null
|
||||
changeImprovement(null)
|
||||
else
|
||||
roadStatus = RoadStatus.None
|
||||
removeRoad()
|
||||
} else {
|
||||
// otherwise use pillage/repair systems
|
||||
if (canPillageTileImprovement()) {
|
||||
@ -1346,7 +1351,7 @@ open class TileInfo : IsPartOfGameInfoSerialization {
|
||||
baseTerrain = this.getNaturalWonder().turnsInto!!
|
||||
setTerrainFeatures(listOf())
|
||||
resource = null
|
||||
improvement = null
|
||||
changeImprovement(null)
|
||||
}
|
||||
|
||||
if (!ruleset.terrains.containsKey(baseTerrain))
|
||||
@ -1373,18 +1378,18 @@ open class TileInfo : IsPartOfGameInfoSerialization {
|
||||
// If we're checking this at gameInfo.setTransients, we can't check the top terrain
|
||||
if (improvement != null && ::baseTerrainObject.isInitialized) normalizeTileImprovement(ruleset)
|
||||
if (isWater || isImpassible())
|
||||
roadStatus = RoadStatus.None
|
||||
removeRoad()
|
||||
}
|
||||
|
||||
private fun normalizeTileImprovement(ruleset: Ruleset) {
|
||||
val improvementObject = ruleset.tileImprovements[improvement]
|
||||
if (improvementObject == null) {
|
||||
improvement = null
|
||||
changeImprovement(null)
|
||||
return
|
||||
}
|
||||
improvement = null // Unset, and check if it can be reset. If so, do it, if not, invalid.
|
||||
changeImprovement(null) // Unset, and check if it can be reset. If so, do it, if not, invalid.
|
||||
if (canImprovementBeBuiltHere(improvementObject, stateForConditionals = StateForConditionals.IgnoreConditionals))
|
||||
improvement = improvementObject.name
|
||||
changeImprovement(improvementObject.name)
|
||||
}
|
||||
|
||||
private fun convertHillToTerrainFeature() {
|
||||
|
@ -466,7 +466,7 @@ class TileMap : IsPartOfGameInfoSerialization {
|
||||
if (tile.resource != null && !ruleSet.tileResources.containsKey(tile.resource!!))
|
||||
tile.resource = null
|
||||
if (tile.improvement != null && !ruleSet.tileImprovements.containsKey(tile.improvement!!))
|
||||
tile.improvement = null
|
||||
tile.changeImprovement(null)
|
||||
}
|
||||
for (startingLocation in startingLocations.toList())
|
||||
if (startingLocation.nation !in ruleSet.nations.keys)
|
||||
@ -608,7 +608,7 @@ class TileMap : 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.improvement = null
|
||||
tile.changeImprovement(null)
|
||||
startingLocations.add(startingLocation)
|
||||
}
|
||||
setStartingLocationsTransients()
|
||||
|
@ -271,7 +271,7 @@ class MapGenerator(val ruleset: Ruleset) {
|
||||
suitableTiles,
|
||||
map.mapParameters.mapSize.radius)
|
||||
for (tile in locations)
|
||||
tile.improvement = ruinsEquivalents.keys.random()
|
||||
tile.changeImprovement(ruinsEquivalents.keys.random())
|
||||
}
|
||||
|
||||
private fun spreadResources(tileMap: TileMap) {
|
||||
|
@ -203,7 +203,7 @@ class NaturalWonderGenerator(val ruleset: Ruleset, val randomness: MapGeneration
|
||||
private fun clearTile(tile: TileInfo){
|
||||
tile.setTerrainFeatures(listOf())
|
||||
tile.resource = null
|
||||
tile.improvement = null
|
||||
tile.changeImprovement(null)
|
||||
tile.setTerrainTransients()
|
||||
}
|
||||
|
||||
|
@ -199,8 +199,8 @@ 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.improvement = null
|
||||
tile.roadStatus = RoadStatus.None
|
||||
tile.changeImprovement(null)
|
||||
tile.removeRoad()
|
||||
}
|
||||
} }).padBottom(0f).row()
|
||||
add(MarkupRenderer.render(
|
||||
@ -214,7 +214,7 @@ class MapEditorEditImprovementsTab(
|
||||
}
|
||||
else
|
||||
editTab.setBrush(it, "Improvement/$it") { tile ->
|
||||
tile.improvement = it
|
||||
tile.changeImprovement(it)
|
||||
}
|
||||
}).padTop(0f).row()
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ fun debugTab() = Table(BaseScreen.skin).apply {
|
||||
tile.resourceAmount = 999
|
||||
// Debug option, so if it crashes on this that's relatively fine
|
||||
// If this becomes a problem, check if such an improvement exists and otherwise plop down a great improvement or so
|
||||
tile.improvement = resource.getImprovements().first()
|
||||
tile.changeImprovement(resource.getImprovements().first())
|
||||
}
|
||||
curGameInfo.getCurrentPlayerCivilization().updateSightAndResources()
|
||||
if (worldScreen != null) worldScreen.shouldUpdate = true
|
||||
|
@ -551,7 +551,7 @@ class DiplomacyScreen(
|
||||
improveTileButton.onClick {
|
||||
viewingCiv.addGold(-200)
|
||||
improvableTile.stopWorkingOnImprovement()
|
||||
improvableTile.improvement = tileImprovement.name
|
||||
improvableTile.changeImprovement(tileImprovement.name)
|
||||
otherCiv.updateDetailedCivResources()
|
||||
rightSideTable.clear()
|
||||
rightSideTable.add(ScrollPane(getCityStateDiplomacyTable(otherCiv)))
|
||||
|
@ -150,7 +150,7 @@ object UnitActions {
|
||||
|
||||
return UnitAction(UnitActionType.Create, "Create [$improvementName]",
|
||||
action = {
|
||||
tile.improvement = improvementName
|
||||
tile.changeImprovement(improvementName)
|
||||
val city = tile.getCity()
|
||||
if (city != null) {
|
||||
city.cityStats.update()
|
||||
@ -188,9 +188,8 @@ object UnitActions {
|
||||
UncivGame.Current.settings.addCompletedTutorialTask("Found city")
|
||||
unit.civInfo.addCity(tile.position)
|
||||
if (tile.ruleset.tileImprovements.containsKey("City center"))
|
||||
tile.improvement = "City center"
|
||||
tile.improvementIsPillaged = false
|
||||
tile.roadIsPillaged = false
|
||||
tile.changeImprovement("City center")
|
||||
tile.removeRoad()
|
||||
unit.destroy()
|
||||
UncivGame.Current.worldScreen!!.shouldUpdate = true
|
||||
}
|
||||
@ -775,7 +774,7 @@ object UnitActions {
|
||||
action = {
|
||||
val unitTile = unit.getTile()
|
||||
unitTile.removeCreatesOneImprovementMarker()
|
||||
unitTile.improvement = improvementName
|
||||
unitTile.changeImprovement(improvementName)
|
||||
unitTile.stopWorkingOnImprovement()
|
||||
improvement.handleImprovementCompletion(unit)
|
||||
unit.consume()
|
||||
|
@ -75,7 +75,7 @@ class SerializationTests {
|
||||
val tile = unit.getTile()
|
||||
unit.civInfo.addCity(tile.position)
|
||||
if (tile.ruleset.tileImprovements.containsKey("City center"))
|
||||
tile.improvement = "City center"
|
||||
tile.changeImprovement("City center")
|
||||
unit.destroy()
|
||||
|
||||
// Ensure some diplomacy objects are instantiated
|
||||
|
@ -316,7 +316,7 @@ class GlobalUniquesTests {
|
||||
city.cityConstructions.addBuilding(faithBuilding.name)
|
||||
|
||||
val tile2 = game.setTileFeatures(Vector2(0f,1f), Constants.grassland)
|
||||
tile2.improvement = "Farm"
|
||||
tile2.changeImprovement("Farm")
|
||||
Assert.assertTrue(tile2.getTileStats(city, civInfo).faith == 9f)
|
||||
|
||||
city.cityConstructions.addBuilding(emptyBuilding.name)
|
||||
@ -341,7 +341,7 @@ class GlobalUniquesTests {
|
||||
city.cityConstructions.addBuilding(faithBuilding.name)
|
||||
|
||||
val tile2 = game.setTileFeatures(Vector2(0f,1f), Constants.grassland)
|
||||
tile2.improvement = "Farm"
|
||||
tile2.changeImprovement("Farm")
|
||||
Assert.assertTrue(tile2.getTileStats(city, civInfo).faith == 9f)
|
||||
|
||||
city.cityConstructions.addBuilding(emptyBuilding.name)
|
||||
@ -551,7 +551,7 @@ class GlobalUniquesTests {
|
||||
civInfo.addGold(-civInfo.gold) // reset gold just to be sure
|
||||
|
||||
val testImprovement = game.createTileImprovement("Pillaging this improvement yields [+20 Gold, +11 Food]")
|
||||
tile.improvement = testImprovement.name
|
||||
tile.changeImprovement(testImprovement.name)
|
||||
val unit = game.addUnit("Warrior", civInfo, tile)
|
||||
unit.currentMovement = 2f
|
||||
|
||||
|
Reference in New Issue
Block a user