From 23f575d150efef78a1a425d8c79ceb8373dea107 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 18 Aug 2019 22:57:20 +0300 Subject: [PATCH] Resolved #963 - Units wouldn't leave enemy tiles after war was declared, unlike original Civ --- .../civilization/diplomacy/DiplomacyManager.kt | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt index 97ef45cd..c4b193ff 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt @@ -200,23 +200,18 @@ class DiplomacyManager() { // for performance reasons we don't want to call this every time we want to see if a unit can move through a tile fun updateHasOpenBorders(){ - var newHasOpenBorders = false - for(trade in trades) { - for (offer in trade.theirOffers) - if (offer.name == "Open Borders" && offer.duration > 0) { - newHasOpenBorders = true - break - } - if(newHasOpenBorders) break - } + val newHasOpenBorders = trades.flatMap { it.theirOffers } + .any { it.name == "Open Borders" && it.duration > 0 } - if(hasOpenBorders && !newHasOpenBorders){ // borders were closed, get out! + val bordersWereClosed = hasOpenBorders && !newHasOpenBorders + hasOpenBorders=newHasOpenBorders + + if(bordersWereClosed){ // borders were closed, get out! for(unit in civInfo.getCivUnits().filter { it.currentTile.getOwner()?.civName == otherCivName }){ unit.movement.teleportToClosestMoveableTile() } } - hasOpenBorders=newHasOpenBorders } fun nextTurn(){