From 41f37f5ee7d9f03bb02be481868d60236eaf9ec9 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 11 May 2018 16:26:09 +0300 Subject: [PATCH] Units in the middle of a preordered action (automate, move) don't do it if there's an enemy withing walking distance --- core/src/com/unciv/logic/automation/UnitAutomation.kt | 1 - core/src/com/unciv/logic/map/MapUnit.kt | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index 90eacfe5..37dc8d71 100644 --- a/core/src/com/unciv/logic/automation/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/UnitAutomation.kt @@ -115,7 +115,6 @@ class UnitAutomation{ unit.moveToTile(distanceToTiles.keys.filter { it.unit == null }.toList().getRandom()) } - fun rankTileAsCityCenter(tileInfo: TileInfo, nearbyTileRankings: Map): Float { val bestTilesFromOuterLayer = tileInfo.tileMap.getTilesAtDistance(tileInfo.position,2) .sortedByDescending { nearbyTileRankings[it] }.take(2) diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 527c1e7d..f169fb4f 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -32,6 +32,11 @@ class MapUnit { fun doPreTurnAction() { val currentTile = getTile() if (currentMovement == 0f) return // We've already done stuff this turn, and can't do any more stuff + + val enemyUnitsInWalkingDistance = getDistanceToTiles().keys + .filter { it.unit!=null && it.unit!!.civInfo!=civInfo } + if(enemyUnitsInWalkingDistance.isNotEmpty()) return // Don't you dare move. + if (action != null && action!!.startsWith("moveTo")) { val destination = action!!.replace("moveTo ", "").split(",").dropLastWhile { it.isEmpty() }.toTypedArray() val destinationVector = Vector2(Integer.parseInt(destination[0]).toFloat(), Integer.parseInt(destination[1]).toFloat())