Fix medic promotion healing enemies (#7074)

This commit is contained in:
OptimizedForDensity 2022-06-06 02:30:38 -04:00 committed by GitHub
parent bbe74854b4
commit 7ae54aceb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -106,10 +106,10 @@ class MapUnit {
@Transient @Transient
var canEnterForeignTerrain: Boolean = false var canEnterForeignTerrain: Boolean = false
@Transient @Transient
var costToDisembark: Float? = null var costToDisembark: Float? = null
@Transient @Transient
var costToEmbark: Float? = null var costToEmbark: Float? = null
@ -282,8 +282,8 @@ class MapUnit {
} }
fun hasUnique( fun hasUnique(
uniqueType: UniqueType, uniqueType: UniqueType,
stateForConditionals: StateForConditionals = StateForConditionals(civInfo, unit=this), stateForConditionals: StateForConditionals = StateForConditionals(civInfo, unit=this),
checkCivInfoUniques: Boolean = false checkCivInfoUniques: Boolean = false
): Boolean { ): Boolean {
return getMatchingUniques(uniqueType, stateForConditionals, checkCivInfoUniques).any() return getMatchingUniques(uniqueType, stateForConditionals, checkCivInfoUniques).any()
@ -376,12 +376,12 @@ class MapUnit {
movement += getMatchingUniques(UniqueType.Movement, checkCivInfoUniques = true) movement += getMatchingUniques(UniqueType.Movement, checkCivInfoUniques = true)
.sumOf { it.params[0].toInt() } .sumOf { it.params[0].toInt() }
if (movement < 1) movement = 1 if (movement < 1) movement = 1
return movement return movement
} }
/** /**
* Determines this (land or sea) unit's current maximum vision range from unit properties, civ uniques and terrain. * Determines this (land or sea) unit's current maximum vision range from unit properties, civ uniques and terrain.
* @return Maximum distance of tiles this unit may possibly see * @return Maximum distance of tiles this unit may possibly see
@ -394,18 +394,18 @@ class MapUnit {
if (isEmbarked() && !hasUnique(UniqueType.NormalVisionWhenEmbarked, conditionalState, checkCivInfoUniques = true)) { if (isEmbarked() && !hasUnique(UniqueType.NormalVisionWhenEmbarked, conditionalState, checkCivInfoUniques = true)) {
return 1 return 1
} }
visibilityRange += getMatchingUniques(UniqueType.Sight, conditionalState, checkCivInfoUniques = true) visibilityRange += getMatchingUniques(UniqueType.Sight, conditionalState, checkCivInfoUniques = true)
.sumOf { it.params[0].toInt() } .sumOf { it.params[0].toInt() }
visibilityRange += getTile().getMatchingUniques(UniqueType.Sight, conditionalState) visibilityRange += getTile().getMatchingUniques(UniqueType.Sight, conditionalState)
.sumOf { it.params[0].toInt() } .sumOf { it.params[0].toInt() }
if (visibilityRange < 1) visibilityRange = 1 if (visibilityRange < 1) visibilityRange = 1
return visibilityRange return visibilityRange
} }
/** /**
* Update this unit's cache of viewable tiles and its civ's as well. * Update this unit's cache of viewable tiles and its civ's as well.
*/ */
@ -418,7 +418,7 @@ class MapUnit {
getTile().getTilesInDistance(getVisibilityRange()).toHashSet() // it's that simple getTile().getTilesInDistance(getVisibilityRange()).toHashSet() // it's that simple
else -> getTile().getViewableTilesList(getVisibilityRange()).toHashSet() else -> getTile().getViewableTilesList(getVisibilityRange()).toHashSet()
} }
// Set equality automatically determines if anything changed - https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-abstract-set/equals.html // Set equality automatically determines if anything changed - https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-abstract-set/equals.html
if (updateCivViewableTiles && oldViewableTiles != viewableTiles) if (updateCivViewableTiles && oldViewableTiles != viewableTiles)
civInfo.updateViewableTiles() // for the civ civInfo.updateViewableTiles() // for the civ
@ -551,7 +551,7 @@ class MapUnit {
/** Check whether this unit can upgrade to [unitToUpgradeTo]. This does not check or follow the /** Check whether this unit can upgrade to [unitToUpgradeTo]. This does not check or follow the
* normal upgrade chain defined by [BaseUnit.upgradesTo], unless [unitToUpgradeTo] is left at default. * normal upgrade chain defined by [BaseUnit.upgradesTo], unless [unitToUpgradeTo] is left at default.
* @param maxSteps only used for default of [unitToUpgradeTo], ignored otherwise. * @param maxSteps only used for default of [unitToUpgradeTo], ignored otherwise.
* @param ignoreRequirements Ignore possible tech/policy/building requirements (e.g. resource requirements still count). * @param ignoreRequirements Ignore possible tech/policy/building requirements (e.g. resource requirements still count).
* Used for upgrading units via ancient ruins. * Used for upgrading units via ancient ruins.
* @param ignoreResources Ignore resource requirements (tech still counts) * @param ignoreResources Ignore resource requirements (tech still counts)
* Used to display disabled Upgrade button * Used to display disabled Upgrade button
@ -727,13 +727,13 @@ class MapUnit {
val removedFeatureName = tile.improvementInProgress!!.removePrefix(Constants.remove) val removedFeatureName = tile.improvementInProgress!!.removePrefix(Constants.remove)
val tileImprovement = tile.getTileImprovement() val tileImprovement = tile.getTileImprovement()
if (tileImprovement != null if (tileImprovement != null
&& tile.terrainFeatures.any { && tile.terrainFeatures.any {
tileImprovement.terrainsCanBeBuiltOn.contains(it) && it == removedFeatureName tileImprovement.terrainsCanBeBuiltOn.contains(it) && it == removedFeatureName
} }
&& !tileImprovement.terrainsCanBeBuiltOn.contains(tile.baseTerrain) && !tileImprovement.terrainsCanBeBuiltOn.contains(tile.baseTerrain)
) { ) {
// We removed a terrain (e.g. Forest) and the improvement (e.g. Lumber mill) requires it! // We removed a terrain (e.g. Forest) and the improvement (e.g. Lumber mill) requires it!
tile.improvement = null tile.improvement = null
if (tile.resource != null) civInfo.updateDetailedCivResources() // unlikely, but maybe a mod makes a resource improvement dependent on a terrain feature if (tile.resource != null) civInfo.updateDetailedCivResources() // unlikely, but maybe a mod makes a resource improvement dependent on a terrain feature
} }
if (RoadStatus.values().any { tile.improvementInProgress == it.removeAction }) if (RoadStatus.values().any { tile.improvementInProgress == it.removeAction })
@ -754,7 +754,7 @@ class MapUnit {
tile.improvement = tile.improvementInProgress tile.improvement = tile.improvementInProgress
} }
} }
tile.improvementInProgress = null tile.improvementInProgress = null
tile.getCity()?.updateCitizens = true tile.getCity()?.updateCitizens = true
} }
@ -778,7 +778,7 @@ class MapUnit {
) )
} }
} }
private fun heal() { private fun heal() {
if (isEmbarked()) return // embarked units can't heal if (isEmbarked()) return // embarked units can't heal
if (health >= 100) return // No need to heal if at max health if (health >= 100) return // No need to heal if at max health
@ -791,7 +791,7 @@ class MapUnit {
} }
fun healBy(amount: Int) { fun healBy(amount: Int) {
health += amount * health += amount *
if (hasUnique(UniqueType.HealingEffectsDoubled, checkCivInfoUniques = true)) 2 if (hasUnique(UniqueType.HealingEffectsDoubled, checkCivInfoUniques = true)) 2
else 1 else 1
if (health > 100) health = 100 if (health > 100) health = 100
@ -814,7 +814,7 @@ class MapUnit {
if (!mayHeal) return healing if (!mayHeal) return healing
healing += getMatchingUniques(UniqueType.Heal, checkCivInfoUniques = true).sumOf { it.params[0].toInt() } healing += getMatchingUniques(UniqueType.Heal, checkCivInfoUniques = true).sumOf { it.params[0].toInt() }
val healingCity = tileInfo.getTilesInDistance(1).firstOrNull { val healingCity = tileInfo.getTilesInDistance(1).firstOrNull {
it.isCityCenter() && it.getCity()!!.getMatchingUniques(UniqueType.CityHealingUnits).any() it.isCityCenter() && it.getCity()!!.getMatchingUniques(UniqueType.CityHealingUnits).any()
}?.getCity() }?.getCity()
@ -826,7 +826,8 @@ class MapUnit {
} }
val maxAdjacentHealingBonus = currentTile.neighbors val maxAdjacentHealingBonus = currentTile.neighbors
.flatMap { it.getUnits().asSequence() }.map { it.adjacentHealingBonus() }.maxOrNull() .flatMap { it.getUnits().asSequence() }.filter { it.civInfo == civInfo }
.map { it.adjacentHealingBonus() }.maxOrNull()
if (maxAdjacentHealingBonus != null) if (maxAdjacentHealingBonus != null)
healing += maxAdjacentHealingBonus healing += maxAdjacentHealingBonus
@ -943,7 +944,7 @@ class MapUnit {
assignOwner(recipient) assignOwner(recipient)
recipient.updateViewableTiles() recipient.updateViewableTiles()
} }
/** Destroys the unit and gives stats if its a great person */ /** Destroys the unit and gives stats if its a great person */
fun consume() { fun consume() {
addStatsPerGreatPersonUsage() addStatsPerGreatPersonUsage()
@ -975,7 +976,7 @@ class MapUnit {
// getAncientRuinBonus, if it places a new unit, does too // getAncientRuinBonus, if it places a new unit, does too
currentTile = tile currentTile = tile
if (civInfo.isMajorCiv() if (civInfo.isMajorCiv()
&& tile.improvement != null && tile.improvement != null
&& tile.getTileImprovement()!!.isAncientRuinsEquivalent() && tile.getTileImprovement()!!.isAncientRuinsEquivalent()
) { ) {
@ -1205,7 +1206,7 @@ class MapUnit {
} else civInfo.addNotification( } else civInfo.addNotification(
"An enemy [Citadel] has attacked our [$name]", "An enemy [Citadel] has attacked our [$name]",
locations, locations,
NotificationIcon.Citadel, NotificationIcon.War, name NotificationIcon.Citadel, NotificationIcon.War, name
) )
} }
@ -1232,8 +1233,8 @@ class MapUnit {
fun canBuildImprovement(improvement: TileImprovement, tile: TileInfo = currentTile): Boolean { fun canBuildImprovement(improvement: TileImprovement, tile: TileInfo = currentTile): Boolean {
// Workers (and similar) should never be able to (instantly) construct things, only build them // Workers (and similar) should never be able to (instantly) construct things, only build them
// HOWEVER, they should be able to repair such things if they are pillaged // HOWEVER, they should be able to repair such things if they are pillaged
if (improvement.turnsToBuild == 0 if (improvement.turnsToBuild == 0
&& improvement.name != Constants.cancelImprovementOrder && improvement.name != Constants.cancelImprovementOrder
&& tile.improvementInProgress != improvement.name && tile.improvementInProgress != improvement.name
) return false ) return false