diff --git a/core/src/com/unciv/logic/battle/GreatGeneralImplementation.kt b/core/src/com/unciv/logic/battle/GreatGeneralImplementation.kt index 7cef3d4418..6d4f29763e 100644 --- a/core/src/com/unciv/logic/battle/GreatGeneralImplementation.kt +++ b/core/src/com/unciv/logic/battle/GreatGeneralImplementation.kt @@ -20,7 +20,7 @@ object GreatGeneralImplementation { } /** - * Determine the "Great General" bonus for [unit] by searching for units carrying the [UniqueType.StrengthBonusInRadius] in the vicinity. + * Determine the "Great General" bonus for [ourUnitCombatant] by searching for units carrying the [UniqueType.StrengthBonusInRadius] in the vicinity. * * Used by [BattleDamage.getGeneralModifiers]. * @@ -89,16 +89,20 @@ object GreatGeneralImplementation { // rank tiles and find best val unitBonusRadius = generalBonusData.maxOfOrNull { it.radius } ?: return null + + val militaryUnitToHasAttackableEnemies = HashMap() return militaryUnitTilesInDistance .maxByOrNull { unitTile -> - unitTile.getTilesInDistance(unitBonusRadius).sumOf { auraTile -> - val militaryUnit = auraTile.militaryUnit + unitTile.getTilesInDistance(unitBonusRadius).sumOf { affectedTile -> + val militaryUnit = affectedTile.militaryUnit if (militaryUnit == null || militaryUnit.civ != general.civ || militaryUnit.isEmbarked()) 0 - else if (TargetHelper.getAttackableEnemies(militaryUnit, militaryUnit.movement.getDistanceToTiles()).isEmpty()) 0 + else if (militaryUnitToHasAttackableEnemies.getOrPut(militaryUnit) { + TargetHelper.getAttackableEnemies(militaryUnit, militaryUnit.movement.getDistanceToTiles()).isEmpty() + }) 0 else generalBonusData.firstOrNull { // "Military" as commented above only a small optimization - auraTile.aerialDistanceTo(unitTile) <= it.radius + affectedTile.aerialDistanceTo(unitTile) <= it.radius && (it.filter == "Military" || militaryUnit.matchesFilter(it.filter)) }?.bonus ?: 0 } diff --git a/core/src/com/unciv/models/ruleset/unique/Unique.kt b/core/src/com/unciv/models/ruleset/unique/Unique.kt index 3801250a7d..ada7df7e42 100644 --- a/core/src/com/unciv/models/ruleset/unique/Unique.kt +++ b/core/src/com/unciv/models/ruleset/unique/Unique.kt @@ -64,17 +64,18 @@ class Unique(val text: String, val sourceObjectType: UniqueTarget? = null, val s return conditionalsApply(StateForConditionals(civInfo, city)) } - fun conditionalsApply(state: StateForConditionals = StateForConditionals()): Boolean { + fun conditionalsApply(state: StateForConditionals): Boolean { if (state.ignoreConditionals) return true // Always allow Timed conditional uniques. They are managed elsewhere if (isTimedTriggerable) return true + if (modifiers.isEmpty()) return true for (modifier in modifiers) { if (!Conditionals.conditionalApplies(this, modifier, state)) return false } return true } - private fun getUniqueMultiplier(stateForConditionals: StateForConditionals = StateForConditionals()): Int { + private fun getUniqueMultiplier(stateForConditionals: StateForConditionals): Int { val forEveryModifiers = getModifiers(UniqueType.ForEveryCountable) val forEveryAmountModifiers = getModifiers(UniqueType.ForEveryAmountCountable) var amount = 1 @@ -92,7 +93,7 @@ class Unique(val text: String, val sourceObjectType: UniqueTarget? = null, val s } /** Multiplies the unique according to the multiplication conditionals */ - fun getMultiplied(stateForConditionals: StateForConditionals = StateForConditionals()): Sequence { + fun getMultiplied(stateForConditionals: StateForConditionals): Sequence { val multiplier = getUniqueMultiplier(stateForConditionals) return EndlessSequenceOf(this).take(multiplier) }