From 461bea0cbc245ac9a221a9e346343d839502cce7 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 5 Apr 2018 11:04:40 +0300 Subject: [PATCH] Healing units now attempt to go to better tiles to heal there Fixed bug where units moving from A to B would move multiple times between turns, effectively "jumping" distances --- android/build.gradle | 4 +-- core/src/com/unciv/logic/GameInfo.kt | 36 ++++++++++++++++++++---- core/src/com/unciv/logic/map/MapUnit.kt | 3 +- core/src/com/unciv/logic/map/TileInfo.kt | 3 -- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index a26a948f81..a1ea484f86 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,8 +21,8 @@ android { applicationId "com.unciv.game" minSdkVersion 14 targetSdkVersion 26 - versionCode 33 - versionName "1.4" + versionCode 34 + versionName "1.4.1" } buildTypes { release { diff --git a/core/src/com/unciv/logic/GameInfo.kt b/core/src/com/unciv/logic/GameInfo.kt index c5c7d4ccd6..e2cd0cbf3c 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -32,8 +32,7 @@ class GameInfo { for (civInfo in civilizations) civInfo.nextTurn() - for (tile in tileMap.values) - tile.nextTurn() + tileMap.values.filter { it.unit!=null }.map { it.unit!! }.forEach { it.nextTurn() } // We need to update the stats after ALL the cities are done updating because // maybe one of them has a wonder that affects the stats of all the rest of the cities @@ -80,10 +79,32 @@ class GameInfo { private fun automateMoves(civInfo: CivilizationInfo) { for(unit in civInfo.getCivUnits()){ - // If we're low on health then heal - // todo: go to a more defensible place if there is one - if(unit.health < 50) continue // do nothing but heal + fun healUnit(){ + // If we're low on health then heal + // todo: go to a more defensible place if there is one + val tilesInDistance = unit.getDistanceToTiles().keys + val unitTile=unit.getTile() + + // Go to friendly tile if within distance - better healing! + val friendlyTile = tilesInDistance.firstOrNull { it.owner==unit.owner && it.unit==null } + if(unitTile.owner!=unit.owner && friendlyTile!=null){ + unit.moveToTile(friendlyTile) + return + } + + // Or at least get out of enemy territory yaknow + val neutralTile = tilesInDistance.firstOrNull { it.owner==null && it.unit==null } + if(unitTile.owner!=unit.owner && unitTile.owner!=null && neutralTile!=null){ + unit.moveToTile(neutralTile) + return + } + } + + if(unit.health < 50) { + healUnit() + continue + } // do nothing but heal // if there is an attackable unit in the vicinity, attack! val attackableTiles = civInfo.getViewableTiles() @@ -109,7 +130,10 @@ class GameInfo { } } - if(unit.health < 80) continue // do nothing but heal until 80 health + if(unit.health < 80){ + healUnit() + continue + } // do nothing but heal until 80 health diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 6e460682d4..2d17087a5f 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -196,5 +196,4 @@ class MapUnit { doPreTurnAction(tile) } -} - +} \ No newline at end of file diff --git a/core/src/com/unciv/logic/map/TileInfo.kt b/core/src/com/unciv/logic/map/TileInfo.kt index 4f44832660..0705953d57 100644 --- a/core/src/com/unciv/logic/map/TileInfo.kt +++ b/core/src/com/unciv/logic/map/TileInfo.kt @@ -139,9 +139,6 @@ class TileInfo { improvementInProgress = null } - fun nextTurn() { - if (unit != null) unit!!.nextTurn() - } override fun toString(): String { val SB = StringBuilder()