From 6900e286713e2ef66342bbc21fd9091e5a025b6c Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 16 Jun 2020 20:24:11 +0300 Subject: [PATCH] Resolved #2735 - Diplomatic "Friends with friend/enemy" modifiers are recalculated every turn --- buildSrc/src/main/kotlin/BuildConfig.kt | 4 +- .../diplomacy/DiplomacyManager.kt | 38 ++++++++++++------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/buildSrc/src/main/kotlin/BuildConfig.kt b/buildSrc/src/main/kotlin/BuildConfig.kt index 51cf4c66..caa8fad5 100644 --- a/buildSrc/src/main/kotlin/BuildConfig.kt +++ b/buildSrc/src/main/kotlin/BuildConfig.kt @@ -3,8 +3,8 @@ package com.unciv.build object BuildConfig { const val kotlinVersion = "1.3.71" const val appName = "Unciv" - const val appCodeNumber = 438 - const val appVersion = "3.9.3" + const val appCodeNumber = 439 + const val appVersion = "3.9.3-patch1" const val gdxVersion = "1.9.10" const val roboVMVersion = "2.3.1" diff --git a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt index 3e559970..36ec9930 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt @@ -256,19 +256,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(){ + fun updateHasOpenBorders() { val newHasOpenBorders = trades.flatMap { it.theirOffers } .any { it.name == Constants.openBorders && it.duration > 0 } val bordersWereClosed = hasOpenBorders && !newHasOpenBorders - hasOpenBorders=newHasOpenBorders + hasOpenBorders = newHasOpenBorders - if(bordersWereClosed){ // borders were closed, get out! - for(unit in civInfo.getCivUnits().filter { it.currentTile.getOwner()?.civName == otherCivName }){ + if (bordersWereClosed) { // borders were closed, get out! + for (unit in civInfo.getCivUnits().filter { it.currentTile.getOwner()?.civName == otherCivName }) { unit.movement.teleportToClosestMoveableTile() } } - } fun nextTurn(){ @@ -366,6 +365,8 @@ class DiplomacyManager() { revertToZero(DiplomaticModifiers.UnacceptableDemands, 1 / 4f) revertToZero(DiplomaticModifiers.LiberatedCity, 1 / 8f) + setFriendshipBasedModifier() + if (!hasFlag(DiplomacyFlags.DeclarationOfFriendship)) revertToZero(DiplomaticModifiers.DeclarationOfFriendship, 1 / 2f) //decreases slowly and will revert to full if it is declared later @@ -417,11 +418,11 @@ class DiplomacyManager() { else thirdCiv.getDiplomacyManager(civInfo).addModifier(DiplomaticModifiers.WarMongerer,-5f) } - if(hasFlag(DiplomacyFlags.DeclarationOfFriendship)){ + if(hasFlag(DiplomacyFlags.DeclarationOfFriendship)) { removeFlag(DiplomacyFlags.DeclarationOfFriendship) otherCivDiplomacy.removeModifier(DiplomaticModifiers.DeclarationOfFriendship) - for(knownCiv in civInfo.getKnownCivs()){ - val amount = if(knownCiv==otherCiv) -40f else -20f + for (knownCiv in civInfo.getKnownCivs()) { + val amount = if (knownCiv == otherCiv) -40f else -20f val diploManager = knownCiv.getDiplomacyManager(civInfo) diploManager.addModifier(DiplomaticModifiers.BetrayedDeclarationOfFriendship, amount) diploManager.removeModifier(DiplomaticModifiers.DeclaredFriendshipWithOurAllies) // obviously this guy's declarations of friendship aren't worth much. @@ -520,12 +521,21 @@ class DiplomacyManager() { for (thirdCiv in getCommonKnownCivs().filter { it.isMajorCiv() }) { thirdCiv.addNotification("[${civInfo.civName}] and [${otherCiv().civName}] have signed the Declaration of Friendship!", null, Color.WHITE) - val thirdCivRelationshipWithOtherCiv = thirdCiv.getDiplomacyManager(otherCiv()).relationshipLevel() - when(thirdCivRelationshipWithOtherCiv){ - RelationshipLevel.Unforgivable -> addModifier(DiplomaticModifiers.DeclaredFriendshipWithOurEnemies,-15f) - RelationshipLevel.Enemy -> addModifier(DiplomaticModifiers.DeclaredFriendshipWithOurEnemies,-5f) - RelationshipLevel.Friend -> addModifier(DiplomaticModifiers.DeclaredFriendshipWithOurAllies,5f) - RelationshipLevel.Ally -> addModifier(DiplomaticModifiers.DeclaredFriendshipWithOurAllies,15f) + thirdCiv.getDiplomacyManager(civInfo).setFriendshipBasedModifier() + } + } + + fun setFriendshipBasedModifier(){ + removeModifier(DiplomaticModifiers.DeclaredFriendshipWithOurAllies) + removeModifier(DiplomaticModifiers.DeclaredFriendshipWithOurEnemies) + for(thirdCiv in getCommonKnownCivs() + .filter { it.getDiplomacyManager(civInfo).hasFlag(DiplomacyFlags.DeclarationOfFriendship) }) { + val otherCivRelationshipWithThirdCiv = otherCiv().getDiplomacyManager(thirdCiv).relationshipLevel() + when (otherCivRelationshipWithThirdCiv) { + RelationshipLevel.Unforgivable -> addModifier(DiplomaticModifiers.DeclaredFriendshipWithOurEnemies, -15f) + RelationshipLevel.Enemy -> addModifier(DiplomaticModifiers.DeclaredFriendshipWithOurEnemies, -5f) + RelationshipLevel.Friend -> addModifier(DiplomaticModifiers.DeclaredFriendshipWithOurAllies, 5f) + RelationshipLevel.Ally -> addModifier(DiplomaticModifiers.DeclaredFriendshipWithOurAllies, 15f) } } }