mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-06 08:21:36 +07:00
Resolves #11193 - update uniques upon taking damage and other situations
This commit is contained in:
@ -750,6 +750,7 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
|||||||
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
|
||||||
|
cache.updateUniques()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun takeDamage(amount: Int) {
|
fun takeDamage(amount: Int) {
|
||||||
@ -757,6 +758,7 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
|||||||
if (health > 100) health = 100 // For cheating modders, e.g. negative tile damage
|
if (health > 100) health = 100 // For cheating modders, e.g. negative tile damage
|
||||||
if (health < 0) health = 0
|
if (health < 0) health = 0
|
||||||
if (health == 0) destroy()
|
if (health == 0) destroy()
|
||||||
|
else cache.updateUniques()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun destroy(destroyTransportedUnit: Boolean = true) {
|
fun destroy(destroyTransportedUnit: Boolean = true) {
|
||||||
@ -879,6 +881,7 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
|||||||
// this check is here in order to not load the fresh built unit into carrier right after the build
|
// this check is here in order to not load the fresh built unit into carrier right after the build
|
||||||
isTransported = !tile.isCityCenter() && baseUnit.movesLikeAirUnits() // not moving civilians
|
isTransported = !tile.isCityCenter() && baseUnit.movesLikeAirUnits() // not moving civilians
|
||||||
moveThroughTile(tile)
|
moveThroughTile(tile)
|
||||||
|
cache.updateUniques()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startEscorting() {
|
fun startEscorting() {
|
||||||
@ -957,6 +960,7 @@ class MapUnit : IsPartOfGameInfoSerialization {
|
|||||||
owner = civInfo.civName
|
owner = civInfo.civName
|
||||||
this.civ = civInfo
|
this.civ = civInfo
|
||||||
civInfo.units.addUnit(this, updateCivInfo)
|
civInfo.units.addUnit(this, updateCivInfo)
|
||||||
|
cache.updateUniques()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun capturedBy(captor: Civilization) {
|
fun capturedBy(captor: Civilization) {
|
||||||
|
@ -281,7 +281,7 @@ class UnitMovement(val unit: MapUnit) {
|
|||||||
includeOtherEscortUnit && unit.isEscorting() -> {
|
includeOtherEscortUnit && unit.isEscorting() -> {
|
||||||
val otherUnitTiles = unit.getOtherEscortUnit()!!.movement.getReachableTilesInCurrentTurn(false).toSet()
|
val otherUnitTiles = unit.getOtherEscortUnit()!!.movement.getReachableTilesInCurrentTurn(false).toSet()
|
||||||
unit.movement.getDistanceToTiles().filter { otherUnitTiles.contains(it.key) }.keys.asSequence()
|
unit.movement.getDistanceToTiles().filter { otherUnitTiles.contains(it.key) }.keys.asSequence()
|
||||||
}
|
}
|
||||||
else -> unit.movement.getDistanceToTiles().keys.asSequence()
|
else -> unit.movement.getDistanceToTiles().keys.asSequence()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -581,8 +581,8 @@ class UnitMovement(val unit: MapUnit) {
|
|||||||
if (isCityCenterCannotEnter(tile))
|
if (isCityCenterCannotEnter(tile))
|
||||||
return false
|
return false
|
||||||
|
|
||||||
if (includeOtherEscortUnit && unit.isEscorting()
|
if (includeOtherEscortUnit && unit.isEscorting()
|
||||||
&& !unit.getOtherEscortUnit()!!.movement.canMoveTo(tile, assumeCanPassThrough,canSwap, includeOtherEscortUnit = false))
|
&& !unit.getOtherEscortUnit()!!.movement.canMoveTo(tile, assumeCanPassThrough,canSwap, includeOtherEscortUnit = false))
|
||||||
return false
|
return false
|
||||||
|
|
||||||
return if (unit.isCivilian())
|
return if (unit.isCivilian())
|
||||||
@ -676,7 +676,7 @@ class UnitMovement(val unit: MapUnit) {
|
|||||||
if (unit.civ.isAtWarWith(firstUnit.civ))
|
if (unit.civ.isAtWarWith(firstUnit.civ))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (includeOtherEscortUnit && unit.isEscorting() && !unit.getOtherEscortUnit()!!.movement.canPassThrough(tile,false))
|
if (includeOtherEscortUnit && unit.isEscorting() && !unit.getOtherEscortUnit()!!.movement.canPassThrough(tile,false))
|
||||||
return false
|
return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -684,7 +684,7 @@ class UnitMovement(val unit: MapUnit) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param includeOtherEscortUnit determines whether or not this method will also check if the other escort units [getDistanceToTiles] if it has one.
|
* @param includeOtherEscortUnit determines whether or not this method will also check if the other escort units [getDistanceToTiles] if it has one.
|
||||||
* Leave it as default unless you know what [getDistanceToTiles] does.
|
* Leave it as default unless you know what [getDistanceToTiles] does.
|
||||||
*/
|
*/
|
||||||
fun getDistanceToTiles(
|
fun getDistanceToTiles(
|
||||||
considerZoneOfControl: Boolean = true,
|
considerZoneOfControl: Boolean = true,
|
||||||
@ -704,7 +704,7 @@ class UnitMovement(val unit: MapUnit) {
|
|||||||
passThroughCache,
|
passThroughCache,
|
||||||
movementCostCache
|
movementCostCache
|
||||||
)
|
)
|
||||||
|
|
||||||
if (includeOtherEscortUnit) {
|
if (includeOtherEscortUnit) {
|
||||||
// Only save to cache only if we are the original call and not the subsequent escort unit call
|
// Only save to cache only if we are the original call and not the subsequent escort unit call
|
||||||
pathfindingCache.setDistanceToTiles(considerZoneOfControl, distanceToTiles)
|
pathfindingCache.setDistanceToTiles(considerZoneOfControl, distanceToTiles)
|
||||||
|
Reference in New Issue
Block a user