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

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