From 2c428f8269ff5ee8f248a95baefa7e972bc48187 Mon Sep 17 00:00:00 2001 From: Xander Lenstra <71121390+xlenstra@users.noreply.github.com> Date: Wed, 4 Aug 2021 12:55:12 +0200 Subject: [PATCH] Bugfixes from unitTypes so promotions work again (#4744) --- android/assets/game.atlas | 28 +++++++++---------- .../jsons/Civ V - Vanilla/UnitTypes.json | 2 +- .../src/com/unciv/logic/map/UnitPromotions.kt | 2 +- .../com/unciv/models/ruleset/unit/UnitType.kt | 22 +++++++-------- .../ui/pickerscreens/PromotionPickerScreen.kt | 2 +- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/android/assets/game.atlas b/android/assets/game.atlas index 4a140c198c..a0a40fca86 100644 --- a/android/assets/game.atlas +++ b/android/assets/game.atlas @@ -214,20 +214,6 @@ ImprovementIcons/Quarry orig: 100, 100 offset: 0, 0 index: -1 -ImprovementIcons/Railroad - rotate: false - xy: 1508, 1184 - size: 100, 100 - orig: 100, 100 - offset: 0, 0 - index: -1 -TileSets/Default/Railroad - rotate: false - xy: 1508, 1184 - size: 100, 100 - orig: 100, 100 - offset: 0, 0 - index: -1 ImprovementIcons/Road rotate: false xy: 1832, 1400 @@ -2167,6 +2153,20 @@ TileSets/Default/OasisOverlay orig: 100, 100 offset: 0, 0 index: -1 +TileSets/Default/Railroad + rotate: false + xy: 1508, 1184 + size: 100, 100 + orig: 100, 100 + offset: 0, 0 + index: -1 +ImprovementIcons/Railroad + rotate: false + xy: 1508, 1184 + size: 100, 100 + orig: 100, 100 + offset: 0, 0 + index: -1 TileSets/Default/Road rotate: false xy: 190, 565 diff --git a/android/assets/jsons/Civ V - Vanilla/UnitTypes.json b/android/assets/jsons/Civ V - Vanilla/UnitTypes.json index 38bab47e29..ba5e371ded 100644 --- a/android/assets/jsons/Civ V - Vanilla/UnitTypes.json +++ b/android/assets/jsons/Civ V - Vanilla/UnitTypes.json @@ -118,6 +118,6 @@ }, { "name": "AtomicBomber", - "Domain": "Air" + "movementType": "Air" } ] diff --git a/core/src/com/unciv/logic/map/UnitPromotions.kt b/core/src/com/unciv/logic/map/UnitPromotions.kt index c9666aee5b..ca79136e10 100644 --- a/core/src/com/unciv/logic/map/UnitPromotions.kt +++ b/core/src/com/unciv/logic/map/UnitPromotions.kt @@ -46,7 +46,7 @@ class UnitPromotions{ fun getAvailablePromotions(): List { return unit.civInfo.gameInfo.ruleSet.unitPromotions.values - .filter { unit.type.toString() in it.unitTypes && it.name !in promotions } + .filter { unit.type.name in it.unitTypes && it.name !in promotions } .filter { it.prerequisites.isEmpty() || it.prerequisites.any { p->p in promotions } } } diff --git a/core/src/com/unciv/models/ruleset/unit/UnitType.kt b/core/src/com/unciv/models/ruleset/unit/UnitType.kt index 96b9bf50cc..79a4a1ef6c 100644 --- a/core/src/com/unciv/models/ruleset/unit/UnitType.kt +++ b/core/src/com/unciv/models/ruleset/unit/UnitType.kt @@ -16,23 +16,24 @@ enum class UnitMovementType { // The types of tiles the unit can by default ente Air // Only city tiles and carrying units } -class UnitType( - val movementType: String? = null -) : INamed { +class UnitType() : INamed { override lateinit var name: String - val uniques: ArrayList = ArrayList() + private var movementType: String? = null + private val unitMovementType: UnitMovementType? by lazy { if (movementType == null) null else UnitMovementType.valueOf(movementType!!) } + val uniques: ArrayList = ArrayList() val uniqueObjects: List by lazy { uniques.map { Unique(it) } } - constructor(name: String, domain: String? = null) : this(domain) { + constructor(name: String, domain: String? = null) : this() { this.name = name + this.movementType = domain } - fun getMovementType() = if (movementType == null) null else UnitMovementType.valueOf(movementType) + fun getMovementType() = unitMovementType - fun isLandUnit() = getMovementType() == UnitMovementType.Land - fun isWaterUnit() = getMovementType() == UnitMovementType.Water - fun isAirUnit() = getMovementType() == UnitMovementType.Air + fun isLandUnit() = unitMovementType == UnitMovementType.Land + fun isWaterUnit() = unitMovementType == UnitMovementType.Water + fun isAirUnit() = unitMovementType == UnitMovementType.Air fun matchesFilter(filter: String): Boolean { return when (filter) { @@ -40,8 +41,7 @@ class UnitType( "Water" -> isWaterUnit() "Air" -> isAirUnit() else -> { - if (uniques.contains(filter)) true - else false + uniques.contains(filter) } } } diff --git a/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt index 07e0f6e124..56d80ed465 100644 --- a/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt @@ -47,7 +47,7 @@ class PromotionPickerScreen(val unit: MapUnit) : PickerScreen() { val unitType = unit.type val promotionsForUnitType = unit.civInfo.gameInfo.ruleSet.unitPromotions.values.filter { - it.unitTypes.contains(unitType.toString()) + it.unitTypes.contains(unitType.name) || unit.promotions.promotions.contains(it.name) } val unitAvailablePromotions = unit.promotions.getAvailablePromotions()