Resolved #9058 - Mods that remove 'repair' improvement no longer cause crashes down the line

This commit is contained in:
Yair Morgenstern 2023-03-29 10:17:20 +03:00
parent 6000232eac
commit d3305e680a
3 changed files with 19 additions and 4 deletions

View File

@ -1,10 +1,12 @@
package com.unciv.logic
import com.unciv.Constants
import com.unciv.logic.city.CityConstructions
import com.unciv.logic.city.PerpetualConstruction
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
import com.unciv.logic.civilization.diplomacy.DiplomacyManager
import com.unciv.logic.civilization.managers.TechManager
import com.unciv.logic.map.tile.RoadStatus
import com.unciv.models.ruleset.ModOptions
import com.unciv.models.ruleset.Ruleset
@ -35,6 +37,20 @@ object BackwardCompatibility {
}
}
// Mod decided you can't repair things anymore - get rid of old pillaged improvements
if (!ruleset.tileImprovements.containsKey(Constants.repair))
for (tile in tileMap.values) {
if (tile.roadIsPillaged) {
tile.roadStatus = RoadStatus.None
tile.roadIsPillaged = false
}
if (tile.improvementIsPillaged){
tile.improvement = null
tile.improvementIsPillaged = false
}
}
for (city in civilizations.asSequence().flatMap { it.cities.asSequence() }) {
changeBuildingNameIfNotInRuleset(ruleset, city.cityConstructions, "Hanse", "Bank")

View File

@ -883,11 +883,10 @@ open class Tile : IsPartOfGameInfoSerialization {
removeRoad()
} else {
// otherwise use pillage/repair systems
if (canPillageTileImprovement()) {
if (canPillageTileImprovement())
improvementIsPillaged = true
} else {
else
roadIsPillaged = true
}
}
}

View File

@ -412,7 +412,7 @@ object UnitActions {
}
private fun addRepairAction(unit: MapUnit, actionList: ArrayList<UnitAction>) {
if (unit.currentTile.ruleset.tileImprovements[Constants.repair] == null) return
if (!unit.currentTile.ruleset.tileImprovements.containsKey(Constants.repair)) return
if (!unit.cache.hasUniqueToBuildImprovements) return
if (unit.isEmbarked()) return
val tile = unit.getTile()