mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-22 13:49:54 +07:00
"Unavailable" promotions are unavailable in UI as well
This commit is contained in:
@ -121,6 +121,7 @@ class UnitPromotions : IsPartOfGameInfoSerialization {
|
||||
if (promotion.name in promotions) return false
|
||||
if (unit.type.name !in promotion.unitTypes) return false
|
||||
if (promotion.prerequisites.isNotEmpty() && promotion.prerequisites.none { it in promotions }) return false
|
||||
|
||||
val stateForConditionals = StateForConditionals(unit.civ, unit = unit)
|
||||
if (promotion.hasUnique(UniqueType.Unavailable, stateForConditionals)) return false
|
||||
if (promotion.getMatchingUniques(UniqueType.OnlyAvailable, StateForConditionals.IgnoreConditionals)
|
||||
|
@ -59,18 +59,26 @@ internal class ConsoleUnitCommands : ConsoleCommandNode {
|
||||
"setmovement" to ConsoleAction("unit setmovement [amount]") { console, params ->
|
||||
// Note amount defaults to maxMovement, but is not limited by it - it's an arbitrary choice to allow that
|
||||
val unit = console.getSelectedUnit()
|
||||
val movement = params.firstOrNull()?.takeUnless { it.isEmpty() }?.toFloat() ?: unit.getMaxMovement().toFloat()
|
||||
val movement = params.firstOrNull()?.takeIf { !it.isEmpty() }?.toFloat() ?: unit.getMaxMovement().toFloat()
|
||||
if (movement < 0f) throw ConsoleErrorException("Number out of range")
|
||||
unit.currentMovement = movement
|
||||
DevConsoleResponse.OK
|
||||
},
|
||||
|
||||
"sethealth" to ConsoleAction("unit sethealth [amount]") { console, params ->
|
||||
val health = params.firstOrNull()?.takeUnless { it.isEmpty() }?.toInt() ?: 100
|
||||
val health = params.firstOrNull()?.takeIf { !it.isEmpty() }?.toInt() ?: 100
|
||||
if (health !in 1..100) throw ConsoleErrorException("Number out of range")
|
||||
val unit = console.getSelectedUnit()
|
||||
unit.health = health
|
||||
DevConsoleResponse.OK
|
||||
},
|
||||
|
||||
"setxp" to ConsoleAction("unit setxp [amount]") { console, params ->
|
||||
val xp = params.firstOrNull()?.toInt() ?: throw ConsoleErrorException("No XP provided")
|
||||
if (xp < 0) throw ConsoleErrorException("Number out of range")
|
||||
val unit = console.getSelectedUnit()
|
||||
unit.promotions.XP = xp
|
||||
DevConsoleResponse.OK
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -104,14 +104,17 @@ class PromotionTree(val unit: MapUnit) {
|
||||
}
|
||||
|
||||
// Determine unreachable / disabled nodes
|
||||
val state = StateForConditionals(unit.civ, unit = unit, tile = unit.getTile())
|
||||
val state = StateForConditionals(unit.civ, unit = unit)
|
||||
for (node in nodes.values) {
|
||||
// defensive - I don't know how to provoke the situation, but if it ever occurs, disallow choosing that promotion
|
||||
if (node.promotion.prerequisites.isNotEmpty() && node.parents.isEmpty())
|
||||
node.unreachable = true
|
||||
|
||||
// Slight copy from UnitPromotions.isAvailable
|
||||
if (node.promotion.getMatchingUniques(UniqueType.OnlyAvailable, StateForConditionals.IgnoreConditionals)
|
||||
.any { !it.conditionalsApply(state) })
|
||||
node.unreachable = true
|
||||
if (node.promotion.hasUnique(UniqueType.Unavailable, state)) node.unreachable = true
|
||||
}
|
||||
|
||||
// Calculate depth and distanceToAdopted - nonrecursively, shallows first.
|
||||
|
Reference in New Issue
Block a user