cs units wander (#5441)

This commit is contained in:
SimonCeder 2021-10-09 19:11:52 +02:00 committed by GitHub
parent 81ebacc310
commit 185050bd9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -62,14 +62,15 @@ object UnitAutomation {
}
@JvmStatic
fun wander(unit: MapUnit) {
fun wander(unit: MapUnit, stayInTerritory: Boolean = false) {
val unitDistanceToTiles = unit.movement.getDistanceToTiles()
val reachableTiles = unitDistanceToTiles
.filter { unit.movement.canMoveTo(it.key) && unit.movement.canReach(it.key) }
val reachableTilesMaxWalkingDistance = reachableTiles
.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)
else if (reachableTiles.any()) unit.movement.moveToTile(reachableTiles.keys.random())
}
@ -182,6 +183,10 @@ object UnitAutomation {
// else, try to go to unreached tiles
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 {

View File

@ -4,6 +4,7 @@ import com.badlogic.gdx.math.Vector2
import com.unciv.Constants
import com.unciv.UncivGame
import com.unciv.logic.HexMath
import com.unciv.logic.automation.UnitAutomation.wander
import com.unciv.logic.city.CityInfo
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.map.BFS
@ -171,6 +172,10 @@ class WorkerAutomation(
if (WorkerAutomationConst.consoleOutput)
println("WorkerAutomation: ${unit.label()} -> nothing to do")
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)
}
/**