We now remove resources and improvements that are not in the ruleset from the map when loading the game

This commit is contained in:
Yair Morgenstern 2020-11-06 11:43:49 +02:00
parent 1f1a2fe7bc
commit 4f344b65f8
2 changed files with 18 additions and 84 deletions

View File

@ -254,17 +254,14 @@ class GameInfo {
throw UncivShowableException("Missing mods: [$missingMods]") throw UncivShowableException("Missing mods: [$missingMods]")
} }
// TODO: Scheduled for removal 3.10.14 // Mods can change, leading to things on the map that are no longer defined in the mod.
// Renames as of version 3.1.8, because of translation conflicts with the property "Range" and the difficulty "Immortal" // So we remove them so the game doesn't crash when it tries to access them.
// Needs to be BEFORE tileMap.setTransients, because the units' setTransients is called from there for (tile in tileMap.values) {
// for (tile in tileMap.values) if (tile.resource != null && !ruleSet.tileResources.containsKey(tile.resource!!))
// for (unit in tile.getUnits()) { tile.resource = null
// if (unit.name == "Immortal") unit.name = "Persian Immortal" if (tile.improvement != null && !ruleSet.tileImprovements.containsKey(tile.improvement!!))
// if (unit.promotions.promotions.contains("Range")) { tile.improvement = null
// unit.promotions.promotions.remove("Range") }
// unit.promotions.promotions.add("Extended Range")
// }
// }
tileMap.setTransients(ruleSet) tileMap.setTransients(ruleSet)
@ -291,68 +288,6 @@ class GameInfo {
// This doesn't HAVE to go here, but why not. // This doesn't HAVE to go here, but why not.
// As of version 3.1.3, trade offers of "Declare war on X" and "Introduction to X" were changed to X,
// with the extra text being added only on UI display (solved a couple of problems).
// TODO: Scheduled for removal 3.10.14
// for (trade in civInfo.tradeRequests.map { it.trade }) {
// for (offer in trade.theirOffers.union(trade.ourOffers)) {
// offer.name = offer.name.removePrefix("Declare war on ")
// offer.name = offer.name.removePrefix("Introduction to ")
// }
// }
// TODO: Scheduled for removal 3.10.14
// As of 3.4.9 cities are referenced by id, not by name
// So try to update every tradeRequest (if there are no conflicting names)
// for (tradeRequest in civInfo.tradeRequests) {
// val trade = tradeRequest.trade
// val toRemove = ArrayList<TradeOffer>()
// for (offer in trade.ourOffers) {
// if (offer.type == TradeType.City) {
// val countNames = civInfo.cities.count { it.name == offer.name }
//
// if (countNames == 1)
// offer.name = civInfo.cities.first { it.name == offer.name }.id
// // There are conflicting names: we can't guess what city was being offered
// else if (countNames > 1)
// toRemove.add(offer)
// }
// }
//
// trade.ourOffers.removeAll(toRemove)
// toRemove.clear()
//
// val themCivInfo = getCivilization(tradeRequest.requestingCiv)
// for (offer in trade.theirOffers) {
// if (offer.type == TradeType.City) {
// val countNames = themCivInfo.cities.count { it.name == offer.name }
//
// if (countNames == 1)
// offer.name = themCivInfo.cities.first { it.name == offer.name }.id
// // There are conflicting names: we can't guess what city was being offered
// else if (countNames > 1)
// toRemove.add(offer)
// }
// }
//
// trade.theirOffers.removeAll(toRemove)
// }
// TODO: Scheduled for removal 3.10.14
// As of 3.4.9 cities are referenced by id, not by name
// val toRemove = ArrayList<PopupAlert>()
// for (popupAlert in civInfo.popupAlerts.filter { it.type == AlertType.CityConquered }) {
// val countNames = getCities().count { it.name == popupAlert.value }
//
// if (countNames == 1)
// popupAlert.value = getCities().first { it.name == popupAlert.value }.id
// else if (countNames > 1) {
// // Sorry again, conflicting names: who knows what city you conquered?
// toRemove.add(popupAlert)
// }
// }
// civInfo.popupAlerts.removeAll(toRemove)
// }
for (civInfo in civilizations) civInfo.setNationTransient() for (civInfo in civilizations) civInfo.setNationTransient()
for (civInfo in civilizations) civInfo.setTransients() for (civInfo in civilizations) civInfo.setTransients()

View File

@ -201,29 +201,28 @@ object ImageGetter {
} }
fun getImprovementIcon(improvementName:String, size:Float=20f):Actor{ fun getImprovementIcon(improvementName:String, size:Float=20f):Actor {
if(improvementName.startsWith("Remove") || improvementName == Constants.cancelImprovementOrder) if (improvementName.startsWith("Remove") || improvementName == Constants.cancelImprovementOrder)
return getImage("OtherIcons/Stop") return getImage("OtherIcons/Stop")
if(improvementName.startsWith("StartingLocation ")){ if (improvementName.startsWith("StartingLocation ")) {
val nationName = improvementName.removePrefix("StartingLocation ") val nationName = improvementName.removePrefix("StartingLocation ")
val nation = ruleset.nations[nationName]!! val nation = ruleset.nations[nationName]!!
return getNationIndicator(nation,size) return getNationIndicator(nation, size)
} }
val iconGroup = getImage("ImprovementIcons/$improvementName").surroundWithCircle(size) val iconGroup = getImage("ImprovementIcons/$improvementName").surroundWithCircle(size)
val improvement = ruleset.tileImprovements[improvementName] val improvement = ruleset.tileImprovements[improvementName]
if(improvement==null) if (improvement != null)
throw Exception("No improvement $improvementName found in ruleset!")
iconGroup.circle.color = getColorFromStats(improvement) iconGroup.circle.color = getColorFromStats(improvement)
return iconGroup return iconGroup
} }
fun getConstructionImage(construction: String): Image { fun getConstructionImage(construction: String): Image {
if(ruleset.buildings.containsKey(construction)) return getImage("BuildingIcons/$construction") if (ruleset.buildings.containsKey(construction)) return getImage("BuildingIcons/$construction")
if(ruleset.units.containsKey(construction)) return getUnitIcon(construction) if (ruleset.units.containsKey(construction)) return getUnitIcon(construction)
if(construction=="Nothing") return getImage("OtherIcons/Sleep") if (construction == "Nothing") return getImage("OtherIcons/Sleep")
return getStatIcon(construction) return getStatIcon(construction)
} }