mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-04 23:40:01 +07:00
Added "Incompatible with [promotionName]" unique (#5128)
This commit is contained in:
@ -618,8 +618,8 @@ object NextTurnAutomation {
|
||||
for (unit in civInfo.getCivUnits()) {
|
||||
if (unit.promotions.canBePromoted()) {
|
||||
val availablePromotions = unit.promotions.getAvailablePromotions()
|
||||
if (availablePromotions.isNotEmpty())
|
||||
unit.promotions.addPromotion(availablePromotions.random().name)
|
||||
if (availablePromotions.any())
|
||||
unit.promotions.addPromotion(availablePromotions.toList().random().name)
|
||||
}
|
||||
|
||||
when {
|
||||
|
@ -2,6 +2,7 @@ package com.unciv.logic.map
|
||||
|
||||
import com.unciv.models.ruleset.UniqueTriggerActivation
|
||||
import com.unciv.models.ruleset.unit.Promotion
|
||||
import com.unciv.models.translations.equalsPlaceholderText
|
||||
|
||||
class UnitPromotions {
|
||||
// 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 canBePromoted(): Boolean {
|
||||
if (XP < xpForNextPromotion()) return false
|
||||
if (getAvailablePromotions().isEmpty()) return false
|
||||
if (getAvailablePromotions().none()) return false
|
||||
return true
|
||||
}
|
||||
|
||||
@ -57,10 +58,17 @@ class UnitPromotions {
|
||||
}
|
||||
}
|
||||
|
||||
fun getAvailablePromotions(): List<Promotion> {
|
||||
fun getAvailablePromotions(): Sequence<Promotion> {
|
||||
return unit.civInfo.gameInfo.ruleSet.unitPromotions.values
|
||||
.filter { unit.type.name in it.unitTypes && it.name !in promotions }
|
||||
.filter { it.prerequisites.isEmpty() || it.prerequisites.any { p->p in promotions } }
|
||||
.asSequence()
|
||||
.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 {
|
||||
|
@ -12,7 +12,9 @@ import com.unciv.ui.civilopedia.ICivilopediaText
|
||||
class Promotion : INamed, ICivilopediaText, IHasUniques {
|
||||
override lateinit var name: 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. =(
|
||||
|
||||
override var uniques = ArrayList<String>()
|
||||
|
Reference in New Issue
Block a user