mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-15 10:18:26 +07:00
Performance - Great general automation was taking 40% (!) of nextTurn time - decreased to 6%, which is still A LOT but much, much less
This commit is contained in:
@ -61,15 +61,16 @@ object SpecificUnitAutomation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// try to revenge and capture their tiles
|
// try to revenge and capture their tiles
|
||||||
val enemyCities = unit.civInfo.gameInfo.civilizations
|
val enemyCities = unit.civInfo.getKnownCivs()
|
||||||
.filter { unit.civInfo.knows(it) &&
|
.filter { unit.civInfo.getDiplomacyManager(it).hasModifier(DiplomaticModifiers.StealingTerritory) }
|
||||||
unit.civInfo.getDiplomacyManager(it).hasModifier(DiplomaticModifiers.StealingTerritory) }
|
|
||||||
.flatMap { it.cities }.asSequence()
|
.flatMap { it.cities }.asSequence()
|
||||||
// find the suitable tiles (or their neigbours)
|
// find the suitable tiles (or their neigbours)
|
||||||
val tileToSteal = enemyCities.flatMap { it.getTiles() }.flatMap { it.neighbors.asSequence() }
|
val tileToSteal = enemyCities.flatMap { it.getTiles() } // City tiles
|
||||||
|
.filter { it.neighbors.any { it.getOwner()!=unit.civInfo } } // Edge city tiles
|
||||||
|
.flatMap { it.neighbors.asSequence() } // Neighbors of edge city tiles
|
||||||
.filter { it in unit.civInfo.viewableTiles // we can see them
|
.filter { it in unit.civInfo.viewableTiles // we can see them
|
||||||
&& unit.movement.canReach(it) // we can reach it
|
&& it.neighbors.any { tile -> tile.getOwner() == unit.civInfo}// they are close to our borders
|
||||||
&& it.neighbors.any { tile -> tile.getOwner() == unit.civInfo} } // they are close to our borders
|
}
|
||||||
.sortedBy {
|
.sortedBy {
|
||||||
// get closest tiles
|
// get closest tiles
|
||||||
val distance = it.aerialDistanceTo(unit.currentTile)
|
val distance = it.aerialDistanceTo(unit.currentTile)
|
||||||
@ -77,7 +78,8 @@ object SpecificUnitAutomation {
|
|||||||
val owner = it.getOwner()
|
val owner = it.getOwner()
|
||||||
if (owner != null)
|
if (owner != null)
|
||||||
distance - WorkerAutomation(unit).getPriority(it, owner)
|
distance - WorkerAutomation(unit).getPriority(it, owner)
|
||||||
else distance }.firstOrNull()
|
else distance }
|
||||||
|
.firstOrNull{ unit.movement.canReach(it) } // canReach is perfrmance-heavy and always a last resort
|
||||||
// if there is a good tile to steal - go there
|
// if there is a good tile to steal - go there
|
||||||
if (tileToSteal != null) {
|
if (tileToSteal != null) {
|
||||||
unit.movement.headTowards(tileToSteal)
|
unit.movement.headTowards(tileToSteal)
|
||||||
|
@ -189,6 +189,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
|||||||
return destinationTileThisTurn
|
return destinationTileThisTurn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** This is performance-heavy - use as last resort, only after checking everything else! */
|
||||||
fun canReach(destination: TileInfo): Boolean {
|
fun canReach(destination: TileInfo): Boolean {
|
||||||
if (unit.type.isAirUnit())
|
if (unit.type.isAirUnit())
|
||||||
return unit.currentTile.aerialDistanceTo(destination) <= unit.getRange()*2
|
return unit.currentTile.aerialDistanceTo(destination) <= unit.getRange()*2
|
||||||
|
Reference in New Issue
Block a user