mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-24 03:53:12 -04:00
- Clear all unit movement caches upon a road being pillaged - Log when this happens - Minor whitespace fixes
This commit is contained in:
parent
01636c27f0
commit
70bbfe14d6
@ -275,7 +275,6 @@ object UnitAutomation {
|
|||||||
val ourDistanceToClosestEnemy = unit.civ.threatManager.getDistanceToClosestEnemyUnit(unit.getTile(),6, false)
|
val ourDistanceToClosestEnemy = unit.civ.threatManager.getDistanceToClosestEnemyUnit(unit.getTile(),6, false)
|
||||||
if (otherUnit.health > 80
|
if (otherUnit.health > 80
|
||||||
&& ourDistanceToClosestEnemy < otherUnit.civ.threatManager.getDistanceToClosestEnemyUnit(otherUnit.getTile(),6,false)) {
|
&& ourDistanceToClosestEnemy < otherUnit.civ.threatManager.getDistanceToClosestEnemyUnit(otherUnit.getTile(),6,false)) {
|
||||||
|
|
||||||
if (otherUnit.baseUnit.isRanged()) {
|
if (otherUnit.baseUnit.isRanged()) {
|
||||||
// Don't swap ranged units closer than they have to be
|
// Don't swap ranged units closer than they have to be
|
||||||
val range = otherUnit.baseUnit.range
|
val range = otherUnit.baseUnit.range
|
||||||
|
@ -27,6 +27,7 @@ import com.unciv.models.ruleset.unique.UniqueType
|
|||||||
import com.unciv.ui.components.extensions.withItem
|
import com.unciv.ui.components.extensions.withItem
|
||||||
import com.unciv.ui.components.extensions.withoutItem
|
import com.unciv.ui.components.extensions.withoutItem
|
||||||
import com.unciv.utils.DebugUtils
|
import com.unciv.utils.DebugUtils
|
||||||
|
import com.unciv.utils.Log
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
@ -895,8 +896,10 @@ open class Tile : IsPartOfGameInfoSerialization {
|
|||||||
// otherwise use pillage/repair systems
|
// otherwise use pillage/repair systems
|
||||||
if (canPillageTileImprovement())
|
if (canPillageTileImprovement())
|
||||||
improvementIsPillaged = true
|
improvementIsPillaged = true
|
||||||
else
|
else {
|
||||||
roadIsPillaged = true
|
roadIsPillaged = true
|
||||||
|
clearAllPathfindingCaches()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
owningCity?.reassignPopulationDeferred()
|
owningCity?.reassignPopulationDeferred()
|
||||||
@ -904,6 +907,16 @@ open class Tile : IsPartOfGameInfoSerialization {
|
|||||||
owningCity!!.civ.cache.updateCivResources()
|
owningCity!!.civ.cache.updateCivResources()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun clearAllPathfindingCaches() {
|
||||||
|
val units = tileMap.gameInfo.civilizations.asSequence()
|
||||||
|
.filter { it.isAlive() }
|
||||||
|
.flatMap { it.units.getCivUnits() }
|
||||||
|
Log.debug("%s: road pillaged, clearing cache for %d units", this, { units.count() })
|
||||||
|
for (otherUnit in units) {
|
||||||
|
otherUnit.movement.clearPathfindingCache()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun isPillaged(): Boolean = improvementIsPillaged || roadIsPillaged
|
fun isPillaged(): Boolean = improvementIsPillaged || roadIsPillaged
|
||||||
|
|
||||||
fun setRepaired() {
|
fun setRepaired() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user