From 0888e0a24d96b8435e59ffc6ac25dd77bd49b9d6 Mon Sep 17 00:00:00 2001 From: lyrjie Date: Fri, 31 Jan 2020 15:04:44 +0300 Subject: [PATCH] Rewritten the MapUnit.rankTileForHealing() (#1811) --- .../diplomacy/DiplomacyManager.kt | 8 +++++ core/src/com/unciv/logic/map/MapUnit.kt | 36 ++++++++++++------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt index cb7d600629..2a0476ebc6 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt @@ -221,6 +221,14 @@ class DiplomacyManager() { /** Returns the [civilizations][CivilizationInfo] that know about both sides ([civInfo] and [otherCiv]) */ fun getCommonKnownCivs(): Set = civInfo.getKnownCivs().intersect(otherCiv().getKnownCivs()) + /** Returns true when the [civInfo]'s territory is considered allied for [otherCiv]. + * + * This includes friendly and allied city-states and the open border treaties. + */ + fun isConsideredAllyTerritory(): Boolean { + return (hasOpenBorders) + || (civInfo.isCityState() && relationshipLevel() >= RelationshipLevel.Friend) + } //endregion //region state-changing functions diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 65f2db8619..d311175263 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -386,19 +386,31 @@ class MapUnit { if(health>100) health=100 } - fun rankTileForHealing(tileInfo:TileInfo): Int { - return when{ - tileInfo.isWater && type.isLandUnit() -> 0 // Can't heal in water! - tileInfo.getOwner() == null -> 10 // no man's land (neutral) - tileInfo.isCityCenter() -> 20 - !civInfo.isAtWarWith(tileInfo.getOwner()!!) -> 15 // home or allied territory - else -> { // enemy territory - if(hasUnique("This unit and all others in adjacent tiles heal 5 additional HP. This unit heals 5 additional HP outside of friendly territory.")) 10 - else 5 - } - } - } + /** Returns the health points [MapUnit] will receive if healing on [tileInfo] */ + fun rankTileForHealing(tileInfo: TileInfo): Int { + val tileOwner = tileInfo.getOwner() + val isAlliedTerritory = if (tileOwner != null) + tileOwner == civInfo || tileOwner.getDiplomacyManager(civInfo).isConsideredAllyTerritory() + else + false + var healing = when { + tileInfo.isCityCenter() -> 20 + tileInfo.isWater && isAlliedTerritory && type.isWaterUnit() -> 15 // Water unit on friendly water + tileInfo.isWater -> 0 // All other water cases + tileOwner == null -> 10 // Neutral territory + isAlliedTerritory -> 15 // Allied territory + else -> 5 // Enemy territory + } + + if (hasUnique("This unit and all others in adjacent tiles heal 5 additional HP. This unit heals 5 additional HP outside of friendly territory.") + && !isAlliedTerritory + // Additional healing from medic is only applied when the unit is able to heal + && healing > 0) + healing += 5 + + return healing + } fun endTurn() { doPostTurnAction()