mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-04 23:40:01 +07:00
Resolved #5668 - Changing base ruleset in map editor removes all terrain references that are no longer viable, including starting locations for nations not in new ruleset
This commit is contained in:
@ -22,14 +22,9 @@ object BackwardCompatibility {
|
||||
* This function removes them so the game doesn't crash when it tries to access them.
|
||||
*/
|
||||
fun GameInfo.removeMissingModReferences() {
|
||||
for (tile in tileMap.values) {
|
||||
for (terrainFeature in tile.terrainFeatures.filter{ !ruleSet.terrains.containsKey(it) })
|
||||
tile.terrainFeatures.remove(terrainFeature)
|
||||
if (tile.resource != null && !ruleSet.tileResources.containsKey(tile.resource!!))
|
||||
tile.resource = null
|
||||
if (tile.improvement != null && !ruleSet.tileImprovements.containsKey(tile.improvement!!))
|
||||
tile.improvement = null
|
||||
tileMap.removeMissingTerrainModReferences(ruleSet)
|
||||
|
||||
for (tile in tileMap.values) {
|
||||
for (unit in tile.getUnits()) {
|
||||
if (!ruleSet.units.containsKey(unit.name)) tile.removeUnit(unit)
|
||||
|
||||
|
@ -429,6 +429,20 @@ class TileMap {
|
||||
}
|
||||
}
|
||||
|
||||
fun removeMissingTerrainModReferences(ruleSet: Ruleset) {
|
||||
for (tile in this.values) {
|
||||
for (terrainFeature in tile.terrainFeatures.filter { !ruleSet.terrains.containsKey(it) })
|
||||
tile.terrainFeatures.remove(terrainFeature)
|
||||
if (tile.resource != null && !ruleSet.tileResources.containsKey(tile.resource!!))
|
||||
tile.resource = null
|
||||
if (tile.improvement != null && !ruleSet.tileImprovements.containsKey(tile.improvement!!))
|
||||
tile.improvement = null
|
||||
}
|
||||
for (startingLocation in startingLocations.toList())
|
||||
if (startingLocation.nation !in ruleSet.nations.keys)
|
||||
startingLocations.remove(startingLocation)
|
||||
}
|
||||
|
||||
/** Tries to place the [unitName] into the [TileInfo] closest to the given [position]
|
||||
* @param position where to try to place the unit (or close - max 10 tiles distance)
|
||||
* @param unitName name of the [BaseUnit][com.unciv.models.ruleset.unit.BaseUnit] to create and place
|
||||
|
@ -169,6 +169,9 @@ class MapEditorMenuPopup(var mapEditorScreen: MapEditorScreen): Popup(mapEditorS
|
||||
ruleset.mods += mapParameters.mods
|
||||
ruleset.modOptions = newRuleset.modOptions
|
||||
|
||||
mapEditorScreen.tileMap.removeMissingTerrainModReferences(ruleset)
|
||||
mapEditorScreen.mapHolder.updateTileGroups()
|
||||
|
||||
ImageGetter.setNewRuleset(ruleset)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user