From e8f27c4ef4301ffa191617fcc6649f01b9ede705 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 2 May 2019 00:11:32 +0300 Subject: [PATCH] Diplomacy is ready to be unleashed upon the unsuspecting public! --- android/assets/jsons/Translations.json | 21 +++++++++++-- android/build.gradle | 4 +-- .../logic/automation/NextTurnAutomation.kt | 6 ++++ core/src/com/unciv/logic/battle/Battle.kt | 2 +- .../diplomacy/DiplomacyManager.kt | 15 ++++++++-- .../com/unciv/logic/trade/TradeEvaluation.kt | 8 ++++- core/src/com/unciv/logic/trade/TradeLogic.kt | 9 ++++-- .../src/com/unciv/ui/trade/DiplomacyScreen.kt | 30 +++++++++++++++++-- 8 files changed, 83 insertions(+), 12 deletions(-) diff --git a/android/assets/jsons/Translations.json b/android/assets/jsons/Translations.json index bd0cbeba06..36a45e8d78 100644 --- a/android/assets/jsons/Translations.json +++ b/android/assets/jsons/Translations.json @@ -4869,6 +4869,23 @@ Simplified_Chinese:"很高兴见到你." } + "Our relationship: ":{} + + "Unforgivable":{} + "Enemy":{} + "Competitor":{} + "Neutral":{} + "Favorable":{} + "Friend":{} + "Ally":{} + + // Diplomatic modifiers + "You declared war on us!":{} + "Your warmongering ways are unacceptable to us.":{} + "You have captured our cities!":{} + "Years of peace have strengthened our relations.":{} + "Our mutual military struggle brings us closer together.":{} + // Overview screen "Overview":{ Italian:"Panoramica" @@ -8830,7 +8847,7 @@ "Provides a free [buildingName] in the city":{ Italian:"Dona l'edificio gratuito [buildingName] nella città" French:"Construit un(e) [buildingName] gratuit(e) dans la ville" - Simplified_Chinese:"城市获得一座免费的建筑:[buildingName]" + Simplified_Chinese:"城市获得一座免费的建筑:[buildingName]" } "Requires worked [resource] near city":{ Italian:"Richiede che la città sfrutti [resource]" @@ -8840,7 +8857,7 @@ "Required tech: [requiredTech]":{ Italian:"Tecnologie propedeutiche: [requiredTech]" French:"Nécessite la technologie: [requiredTech]" -Simplified_Chinese:"需要科技:[requiredTech]" + Simplified_Chinese:"需要科技:[requiredTech]" } "Upgrades to [upgradedUnit]":{ Italian:"Aggiorna a [upgradedUnit]" diff --git a/android/build.gradle b/android/build.gradle index b09cb5dcb2..ed4e4367ab 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,8 +21,8 @@ android { applicationId "com.unciv.app" minSdkVersion 14 targetSdkVersion 28 - versionCode 233 - versionName "2.15.0-patch2" + versionCode 234 + versionName "2.16.0" } // Had to add this crap for Travis to build, it wanted to sign the app diff --git a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt index aecc7e8cc4..8bb86743dc 100644 --- a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt @@ -5,6 +5,7 @@ import com.unciv.logic.civilization.PlayerType import com.unciv.logic.civilization.TradeRequest import com.unciv.logic.civilization.diplomacy.DiplomacyFlags import com.unciv.logic.civilization.diplomacy.DiplomaticStatus +import com.unciv.logic.civilization.diplomacy.RelationshipLevel import com.unciv.logic.map.MapUnit import com.unciv.logic.trade.* import com.unciv.models.gamebasics.GameBasics @@ -166,6 +167,11 @@ class NextTurnAutomation{ for (otherCiv in knownCivs.filter { it.isPlayerCivilization() && !it.isAtWarWith(civInfo) && !civInfo.getDiplomacyManager(it).flagsCountdown.containsKey(DiplomacyFlags.DeclinedLuxExchange.toString())}) { + + val relationshipLevel = civInfo.getDiplomacyManager(otherCiv).relationshipLevel() + if(relationshipLevel==RelationshipLevel.Enemy || relationshipLevel == RelationshipLevel.Unforgivable) + continue + val trades = potentialLuxuryTrades(civInfo,otherCiv) for(trade in trades){ val tradeRequest = TradeRequest(civInfo.civName, trade.reverse()) diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index f1e0458ec6..267b3258c7 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -188,7 +188,7 @@ class Battle(val gameInfo:GameInfo) { val aggroGeneratedForOtherCivs = (aggroGenerated/10).roundToInt().toFloat() if(thirdPartyCiv.isAtWarWith(cityCiv)) // You annoyed our enemy? thirdPartyCiv.getDiplomacyManager(attackerCiv) - .addModifier(DiplomaticModifiers.CapturedOurEnemiesCities,aggroGeneratedForOtherCivs) // Cool, keep at at! =D + .addModifier(DiplomaticModifiers.SharedEnemy, aggroGeneratedForOtherCivs) // Cool, keep at at! =D else thirdPartyCiv.getDiplomacyManager(attackerCiv) .addModifier(DiplomaticModifiers.WarMongerer, -aggroGeneratedForOtherCivs) // Uncool bro. } diff --git a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt index 929e82ac79..6c05bd141c 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt @@ -31,7 +31,7 @@ enum class DiplomaticModifiers{ WarMongerer, CapturedOurCities, YearsOfPeace, - CapturedOurEnemiesCities + SharedEnemy } class DiplomacyManager() { @@ -86,6 +86,15 @@ class DiplomacyManager() { fun opinionOfOtherCiv() = diplomaticModifiers.values.sum() fun relationshipLevel(): RelationshipLevel { + if(civInfo.isPlayerCivilization() && otherCiv().isPlayerCivilization()) + return RelationshipLevel.Neutral // People make their own choices. + + if(civInfo.isPlayerCivilization()) + return otherCiv().getDiplomacyManager(civInfo).relationshipLevel() + + // not entirely sure what to do between AI civs, because they probably have different views of each other, + // maybe we need to average their views of each other? That makes sense to me. + val opinion = opinionOfOtherCiv() if(opinion>80) return RelationshipLevel.Ally if(opinion>40) return RelationshipLevel.Friend @@ -227,7 +236,9 @@ class DiplomacyManager() { otherCivDiplomacy.diplomaticModifiers[DiplomaticModifiers.DeclaredWarOnUs.toString()] = -20f for(thirdCiv in civInfo.getKnownCivs()){ - thirdCiv.getDiplomacyManager(civInfo).addModifier(DiplomaticModifiers.WarMongerer,-5f) + if(thirdCiv.isAtWarWith(otherCiv)) + thirdCiv.getDiplomacyManager(civInfo).addModifier(DiplomaticModifiers.WarMongerer,5f) + else thirdCiv.getDiplomacyManager(civInfo).addModifier(DiplomaticModifiers.WarMongerer,-5f) } } diff --git a/core/src/com/unciv/logic/trade/TradeEvaluation.kt b/core/src/com/unciv/logic/trade/TradeEvaluation.kt index 840da90e3a..c11ee4886d 100644 --- a/core/src/com/unciv/logic/trade/TradeEvaluation.kt +++ b/core/src/com/unciv/logic/trade/TradeEvaluation.kt @@ -4,6 +4,7 @@ import com.unciv.logic.automation.Automation import com.unciv.logic.automation.ThreatLevel import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.diplomacy.DiplomaticStatus +import com.unciv.logic.civilization.diplomacy.RelationshipLevel import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.tile.ResourceType import kotlin.math.min @@ -11,9 +12,14 @@ import kotlin.math.sqrt class TradeEvaluation{ fun isTradeAcceptable(trade: Trade, evaluator: CivilizationInfo, tradePartner: CivilizationInfo): Boolean { - val sumOfTheirOffers = trade.theirOffers.asSequence() + var sumOfTheirOffers = trade.theirOffers.asSequence() .filter { it.type!= TradeType.Treaty } // since treaties should only be evaluated once for 2 sides .map { evaluateBuyCost(it,evaluator,tradePartner) }.sum() + + val relationshipLevel = evaluator.getDiplomacyManager(tradePartner).relationshipLevel() + if(relationshipLevel==RelationshipLevel.Enemy) sumOfTheirOffers = (sumOfTheirOffers*1.5).toInt() + else if(relationshipLevel==RelationshipLevel.Unforgivable) sumOfTheirOffers *= 2 + val sumOfOurOffers = trade.ourOffers.map { evaluateSellCost(it, evaluator, tradePartner)}.sum() return sumOfOurOffers <= sumOfTheirOffers } diff --git a/core/src/com/unciv/logic/trade/TradeLogic.kt b/core/src/com/unciv/logic/trade/TradeLogic.kt index 6c21bc6ce0..3dfacfd27f 100644 --- a/core/src/com/unciv/logic/trade/TradeLogic.kt +++ b/core/src/com/unciv/logic/trade/TradeLogic.kt @@ -2,6 +2,7 @@ package com.unciv.logic.trade import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.diplomacy.DiplomaticStatus +import com.unciv.logic.civilization.diplomacy.RelationshipLevel import com.unciv.models.gamebasics.tile.ResourceType import com.unciv.models.gamebasics.tr @@ -21,8 +22,12 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci if(!otherCivilization.getDiplomacyManager(civInfo).hasOpenBorders && !otherCivilization.isCityState() && civInfo.tech.getTechUniques().contains("Enables Open Borders agreements") - && otherCivilization.tech.getTechUniques().contains("Enables Open Borders agreements")) - offers.add(TradeOffer("Open Borders", TradeType.Agreement, 30)) + && otherCivilization.tech.getTechUniques().contains("Enables Open Borders agreements")) { + val relationshipLevel = otherCivilization.getDiplomacyManager(civInfo).relationshipLevel() + + if(relationshipLevel!=RelationshipLevel.Enemy && relationshipLevel!=RelationshipLevel.Unforgivable) + offers.add(TradeOffer("Open Borders", TradeType.Agreement, 30)) + } for(entry in civInfo.getCivResources().filterNot { it.key.resourceType == ResourceType.Bonus }) { val resourceTradeType = if(entry.key.resourceType== ResourceType.Luxury) TradeType.Luxury_Resource diff --git a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt index b7dc48d0d9..eba595f261 100644 --- a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt +++ b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt @@ -7,6 +7,8 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.unciv.UnCivGame import com.unciv.logic.civilization.CivilizationInfo +import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers +import com.unciv.logic.civilization.diplomacy.RelationshipLevel import com.unciv.models.gamebasics.tr import com.unciv.ui.utils.* import com.unciv.ui.worldscreen.optionstable.PopupTable @@ -116,10 +118,34 @@ class DiplomacyScreen:CameraStageBaseScreen() { if(!otherCiv.isCityState()){ val diplomacyModifiersTable = Table() val otherCivDiplomacyManager = otherCiv.getDiplomacyManager(currentPlayerCiv) - val relationshipText = "Our relationship: "+otherCivDiplomacyManager.relationshipLevel()+" ("+otherCivDiplomacyManager.opinionOfOtherCiv()+")" + + val relationshipTable = Table() + relationshipTable.add("Our relationship: ".toLabel()) + val relationshipLevel = otherCivDiplomacyManager.relationshipLevel() + val relationshipText = otherCivDiplomacyManager.relationshipLevel().toString().tr()+" ("+otherCivDiplomacyManager.opinionOfOtherCiv().toInt()+")" + val relationshipColor = when{ + relationshipLevel==RelationshipLevel.Neutral -> Color.WHITE + relationshipLevel==RelationshipLevel.Favorable || relationshipLevel==RelationshipLevel.Friend + || relationshipLevel==RelationshipLevel.Ally -> Color.GREEN + else -> Color.RED + } + relationshipTable.add(relationshipText.toLabel().setFontColor(relationshipColor)) diplomacyModifiersTable.add(relationshipText.toLabel()).row() + for(modifier in otherCivDiplomacyManager.diplomaticModifiers){ - diplomacyModifiersTable.add((modifier.key+" "+modifier.value).toLabel()).row() + var text = when(DiplomaticModifiers.valueOf(modifier.key)){ + DiplomaticModifiers.DeclaredWarOnUs -> "You declared war on us!" + DiplomaticModifiers.WarMongerer -> "Your warmongering ways are unacceptable to us." + DiplomaticModifiers.CapturedOurCities -> "You have captured our cities!" + DiplomaticModifiers.YearsOfPeace -> "Years of peace have strengthened our relations." + DiplomaticModifiers.SharedEnemy -> "Our mutual military struggle brings us closer together." + } + text = text.tr() + text += " " + if(modifier.value>0) text += "+" + text += modifier.value.toInt() + val color = if(modifier.value<0) Color.RED else Color.GREEN + diplomacyModifiersTable.add(text.toLabel().setFontColor(color)).row() } diplomacyTable.add(diplomacyModifiersTable).row() }