mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
cs units wander (#5441)
This commit is contained in:
parent
81ebacc310
commit
185050bd9f
@ -62,14 +62,15 @@ object UnitAutomation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun wander(unit: MapUnit) {
|
fun wander(unit: MapUnit, stayInTerritory: Boolean = false) {
|
||||||
val unitDistanceToTiles = unit.movement.getDistanceToTiles()
|
val unitDistanceToTiles = unit.movement.getDistanceToTiles()
|
||||||
val reachableTiles = unitDistanceToTiles
|
val reachableTiles = unitDistanceToTiles
|
||||||
.filter { unit.movement.canMoveTo(it.key) && unit.movement.canReach(it.key) }
|
.filter { unit.movement.canMoveTo(it.key) && unit.movement.canReach(it.key) }
|
||||||
|
|
||||||
val reachableTilesMaxWalkingDistance = reachableTiles
|
val reachableTilesMaxWalkingDistance = reachableTiles
|
||||||
.filter { it.value.totalDistance == unit.currentMovement
|
.filter { it.value.totalDistance == unit.currentMovement
|
||||||
&& unit.getDamageFromTerrain(it.key) <= 0 } // Don't end turn on damaging terrain for no good reason
|
&& unit.getDamageFromTerrain(it.key) <= 0 // Don't end turn on damaging terrain for no good reason
|
||||||
|
&& (!stayInTerritory || it.key.getOwner() == unit.civInfo) }
|
||||||
if (reachableTilesMaxWalkingDistance.any()) unit.movement.moveToTile(reachableTilesMaxWalkingDistance.toList().random().first)
|
if (reachableTilesMaxWalkingDistance.any()) unit.movement.moveToTile(reachableTilesMaxWalkingDistance.toList().random().first)
|
||||||
else if (reachableTiles.any()) unit.movement.moveToTile(reachableTiles.keys.random())
|
else if (reachableTiles.any()) unit.movement.moveToTile(reachableTiles.keys.random())
|
||||||
}
|
}
|
||||||
@ -182,6 +183,10 @@ object UnitAutomation {
|
|||||||
|
|
||||||
// else, try to go to unreached tiles
|
// else, try to go to unreached tiles
|
||||||
if (tryExplore(unit)) return
|
if (tryExplore(unit)) return
|
||||||
|
|
||||||
|
// Idle CS units should wander so they don't obstruct players so much
|
||||||
|
if (unit.civInfo.isCityState())
|
||||||
|
wander(unit, stayInTerritory = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tryHeadTowardsEncampment(unit: MapUnit): Boolean {
|
private fun tryHeadTowardsEncampment(unit: MapUnit): Boolean {
|
||||||
|
@ -4,6 +4,7 @@ import com.badlogic.gdx.math.Vector2
|
|||||||
import com.unciv.Constants
|
import com.unciv.Constants
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
import com.unciv.logic.HexMath
|
import com.unciv.logic.HexMath
|
||||||
|
import com.unciv.logic.automation.UnitAutomation.wander
|
||||||
import com.unciv.logic.city.CityInfo
|
import com.unciv.logic.city.CityInfo
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.logic.map.BFS
|
import com.unciv.logic.map.BFS
|
||||||
@ -171,6 +172,10 @@ class WorkerAutomation(
|
|||||||
if (WorkerAutomationConst.consoleOutput)
|
if (WorkerAutomationConst.consoleOutput)
|
||||||
println("WorkerAutomation: ${unit.label()} -> nothing to do")
|
println("WorkerAutomation: ${unit.label()} -> nothing to do")
|
||||||
unit.civInfo.addNotification("${unit.shortDisplayName()} has no work to do.", currentTile.position, unit.name, "OtherIcons/Sleep")
|
unit.civInfo.addNotification("${unit.shortDisplayName()} has no work to do.", currentTile.position, unit.name, "OtherIcons/Sleep")
|
||||||
|
|
||||||
|
// Idle CS units should wander so they don't obstruct players so much
|
||||||
|
if (unit.civInfo.isCityState())
|
||||||
|
wander(unit, stayInTerritory = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user