Fixed mod compatibility autochanges

Tested by forcing a new Deciv game to load with a much older mod version
This commit is contained in:
Yair Morgenstern 2023-09-21 14:37:21 +03:00
parent ebfdbb8c4a
commit 92b71102e1
4 changed files with 6 additions and 4 deletions

View File

@ -39,7 +39,7 @@ object BackwardCompatibility {
private fun GameInfo.removeUnitsAndPromotions() {
for (tile in tileMap.values) {
for (unit in tile.getUnits()) {
for (unit in tile.getUnits().toList()) {
if (!ruleset.units.containsKey(unit.name)) tile.removeUnit(unit)
for (promotion in unit.promotions.promotions.toList())

View File

@ -564,8 +564,8 @@ object UnitAutomation {
// Our main attack target is the closest city, but we're fine with deviating from that a bit
var enemyCitiesByPriority = closestEnemyCity.civ.cities
.associateWith { it.getCenterTile().aerialDistanceTo(closestEnemyCity.getCenterTile()) }
.filterNot { it.value > 10 } // anything 10 tiles away from the target is irrelevant
.asSequence().sortedBy { it.value }.map { it.key } // sort the list by closeness to target - least is best!
.asSequence().filterNot { it.value > 10 } // anything 10 tiles away from the target is irrelevant
.sortedBy { it.value }.map { it.key } // sort the list by closeness to target - least is best!
if (unit.baseUnit.isRanged()) // ranged units don't harm capturable cities, waste of a turn
enemyCitiesByPriority = enemyCitiesByPriority.filterNot { it.health == 1 }

View File

@ -883,7 +883,7 @@ open class Tile : IsPartOfGameInfoSerialization {
if (resource != null && resource !in ruleset.tileResources)
resource = null
if (improvement != null && improvement !in ruleset.tileImprovements)
removeImprovement()
improvement = null
}
/** If the unit isn't in the ruleset we can't even know what type of unit this is! So check each place

View File

@ -62,6 +62,8 @@ object ImageGetter {
atlases["game"] = atlas
}
/** Required every time the ruleset changes, in order to load mod-specific images */
fun setNewRuleset(ruleset: Ruleset) {
ImageGetter.ruleset = ruleset