Added "Incompatible with [promotionName]" unique (#5128)

This commit is contained in:
Xander Lenstra 2021-09-08 20:12:57 +02:00 committed by GitHub
parent e2a1e44282
commit 4cfdfee301
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View File

@ -618,8 +618,8 @@ object NextTurnAutomation {
for (unit in civInfo.getCivUnits()) { for (unit in civInfo.getCivUnits()) {
if (unit.promotions.canBePromoted()) { if (unit.promotions.canBePromoted()) {
val availablePromotions = unit.promotions.getAvailablePromotions() val availablePromotions = unit.promotions.getAvailablePromotions()
if (availablePromotions.isNotEmpty()) if (availablePromotions.any())
unit.promotions.addPromotion(availablePromotions.random().name) unit.promotions.addPromotion(availablePromotions.toList().random().name)
} }
when { when {

View File

@ -2,6 +2,7 @@ package com.unciv.logic.map
import com.unciv.models.ruleset.UniqueTriggerActivation import com.unciv.models.ruleset.UniqueTriggerActivation
import com.unciv.models.ruleset.unit.Promotion import com.unciv.models.ruleset.unit.Promotion
import com.unciv.models.translations.equalsPlaceholderText
class UnitPromotions { class UnitPromotions {
// Having this as mandatory constructor parameter would be safer, but this class is part of a // Having this as mandatory constructor parameter would be safer, but this class is part of a
@ -27,7 +28,7 @@ class UnitPromotions {
fun xpForNextPromotion() = (numberOfPromotions+1)*10 fun xpForNextPromotion() = (numberOfPromotions+1)*10
fun canBePromoted(): Boolean { fun canBePromoted(): Boolean {
if (XP < xpForNextPromotion()) return false if (XP < xpForNextPromotion()) return false
if (getAvailablePromotions().isEmpty()) return false if (getAvailablePromotions().none()) return false
return true return true
} }
@ -57,10 +58,17 @@ class UnitPromotions {
} }
} }
fun getAvailablePromotions(): List<Promotion> { fun getAvailablePromotions(): Sequence<Promotion> {
return unit.civInfo.gameInfo.ruleSet.unitPromotions.values return unit.civInfo.gameInfo.ruleSet.unitPromotions.values
.filter { unit.type.name in it.unitTypes && it.name !in promotions } .asSequence()
.filter { it.prerequisites.isEmpty() || it.prerequisites.any { p->p in promotions } } .filter { unit.type.name in it.unitTypes && it.name !in promotions }
.filter { it.prerequisites.isEmpty() || it.prerequisites.any { p->p in promotions } }
.filter {
it.uniqueObjects.none {
unique -> unique.placeholderText == "Incompatible with []"
&& promotions.any { chosenPromotions -> chosenPromotions == unique.params[0] }
}
}
} }
fun clone(): UnitPromotions { fun clone(): UnitPromotions {

View File

@ -12,7 +12,9 @@ import com.unciv.ui.civilopedia.ICivilopediaText
class Promotion : INamed, ICivilopediaText, IHasUniques { class Promotion : INamed, ICivilopediaText, IHasUniques {
override lateinit var name: String override lateinit var name: String
var prerequisites = listOf<String>() var prerequisites = listOf<String>()
var effect = "" // effect deprecated since 3.16.12, use uniques instead
var effect = ""
//
var unitTypes = listOf<String>() // The json parser wouldn't agree to deserialize this as a list of UnitTypes. =( var unitTypes = listOf<String>() // The json parser wouldn't agree to deserialize this as a list of UnitTypes. =(
override var uniques = ArrayList<String>() override var uniques = ArrayList<String>()