doCitadelDamage minor optimization (#5565)

This commit is contained in:
SomeTroglodyte 2021-10-26 11:16:06 +02:00 committed by GitHub
parent 693cf97849
commit eaa765a619
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1013,20 +1013,19 @@ class MapUnit {
private fun doCitadelDamage() {
// Check for Citadel damage - note: 'Damage does not stack with other Citadels'
val citadelTile = currentTile.neighbors
val (citadelTile, damage) = currentTile.neighbors
.filter {
it.getOwner() != null
&& it.improvement != null
&& civInfo.isAtWarWith(it.getOwner()!!)
&& it.getTileImprovement()!!.hasUnique(UniqueType.DamagesAdjacentEnemyUnits)
}.maxByOrNull { tile ->
tile.getTileImprovement()!!
}.map { tile ->
tile to tile.getTileImprovement()!!
.getMatchingUniques(UniqueType.DamagesAdjacentEnemyUnits)
.sumOf { it.params[0].toInt() }
}
if (citadelTile != null) {
health -= citadelTile.getTileImprovement()!!.getMatchingUniques(UniqueType.DamagesAdjacentEnemyUnits).sumOf { it.params[0].toInt() }
}.maxByOrNull { it.second }
?: return
if (damage == 0) return
health -= damage
val locations = LocationAction(listOf(citadelTile.position, currentTile.position))
if (health <= 0) {
civInfo.addNotification(
@ -1046,7 +1045,6 @@ class MapUnit {
NotificationIcon.Citadel, NotificationIcon.War, name
)
}
}
fun matchesFilter(filter: String): Boolean {
if (filter.contains('{')) // multiple types at once - AND logic. Looks like:"{Military} {Land}"