Fix free units with a build limit not spawning (#10091)

* Fix free units with a build limit not spawning

* Flip the amount when at the limit

* Unrelated linting
This commit is contained in:
SeventhM 2023-09-10 23:29:18 -07:00 committed by GitHub
parent fbb516f90f
commit 2061b2cc03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -88,10 +88,13 @@ object UniqueTriggerActivation {
val limit = unit.getMatchingUniques(UniqueType.MaxNumberBuildable)
.map { it.params[0].toInt() }.minOrNull()
val unitCount = civInfo.units.getCivUnits().count { it.name == unitName }
val amountFromTriggerable = unique.params[0].toInt()
val actualAmount =
if (limit==null) amountFromTriggerable
else civInfo.units.getCivUnits().count { it.name==unitName } - limit
val actualAmount = when {
limit == null -> amountFromTriggerable
amountFromTriggerable + unitCount > limit -> limit - unitCount
else -> amountFromTriggerable
}
if (actualAmount <= 0) return false