From 24a71b16f224a024702d5c4bf658c98df3906149 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 11 May 2019 23:32:12 +0300 Subject: [PATCH] Trade button changed to "Negotiate Peace" when at war, and peace treaties are a must when "trading" in this situation --- android/assets/jsons/Translations/Other.json | 2 ++ android/build.gradle | 4 +-- core/src/com/unciv/Constants.kt | 1 + core/src/com/unciv/GameStarter.kt | 2 +- .../logic/automation/NextTurnAutomation.kt | 4 +-- .../diplomacy/DiplomacyManager.kt | 3 +- .../com/unciv/logic/trade/TradeEvaluation.kt | 5 ++-- core/src/com/unciv/logic/trade/TradeLogic.kt | 5 ++-- core/src/com/unciv/ui/NewGameScreen.kt | 4 +-- .../src/com/unciv/ui/trade/DiplomacyScreen.kt | 29 ++++++++++++++----- .../com/unciv/ui/trade/OffersListScroll.kt | 3 +- .../com/unciv/ui/worldscreen/TradePopup.kt | 3 +- 12 files changed, 44 insertions(+), 21 deletions(-) diff --git a/android/assets/jsons/Translations/Other.json b/android/assets/jsons/Translations/Other.json index cfaf7986..b2043b74 100644 --- a/android/assets/jsons/Translations/Other.json +++ b/android/assets/jsons/Translations/Other.json @@ -2488,6 +2488,8 @@ Portuguese:"Você vai pagar por isso!" Simplified_Chinese:"你会为此付出代价的!" } + + "Negotiate Peace":{} "Very well.":{ Italian:"Molto bene." diff --git a/android/build.gradle b/android/build.gradle index a4df959d..e74db30e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,8 +21,8 @@ android { applicationId "com.unciv.app" minSdkVersion 14 targetSdkVersion 28 - versionCode 238 - versionName "2.16.2" + versionCode 240 + versionName "2.16.4" } // Had to add this crap for Travis to build, it wanted to sign the app diff --git a/core/src/com/unciv/Constants.kt b/core/src/com/unciv/Constants.kt index 5f1da6b6..5961e055 100644 --- a/core/src/com/unciv/Constants.kt +++ b/core/src/com/unciv/Constants.kt @@ -9,5 +9,6 @@ class Constants{ const val forest = "Forest" const val jungle = "Jungle" const val hill = "Hill" + const val peaceTreaty = "Peace Treaty" } } \ No newline at end of file diff --git a/core/src/com/unciv/GameStarter.kt b/core/src/com/unciv/GameStarter.kt index d9a08f14..96c611dd 100644 --- a/core/src/com/unciv/GameStarter.kt +++ b/core/src/com/unciv/GameStarter.kt @@ -17,7 +17,7 @@ class GameParameters{ var difficulty="Prince" var mapRadius=20 var numberOfHumanPlayers=1 - var humanNations=ArrayList().apply { add("Babylon") } + var humanNations=ArrayList().apply { add("Babylon") } // Good default starting civ var numberOfEnemies=3 var numberOfCityStates=0 var mapType= MapType.Perlin diff --git a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt index 58a3de86..566ea223 100644 --- a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt @@ -216,8 +216,8 @@ class NextTurnAutomation{ // pay for peace val tradeLogic = TradeLogic(civInfo, enemy) - tradeLogic.currentTrade.ourOffers.add(TradeOffer("Peace Treaty", TradeType.Treaty, 20)) - tradeLogic.currentTrade.theirOffers.add(TradeOffer("Peace Treaty", TradeType.Treaty, 20)) + tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30)) + tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30)) var moneyWeNeedToPay = -TradeEvaluation().evaluatePeaceCostForThem(civInfo,enemy) if(moneyWeNeedToPay>0) { diff --git a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt index a38a00bc..6c75f14e 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt @@ -1,6 +1,7 @@ package com.unciv.logic.civilization.diplomacy import com.badlogic.gdx.graphics.Color +import com.unciv.Constants import com.unciv.logic.civilization.AlertType import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.PopupAlert @@ -89,7 +90,7 @@ class DiplomacyManager() { fun turnsToPeaceTreaty(): Int { for(trade in trades) for(offer in trade.ourOffers) - if(offer.name=="Peace Treaty" && offer.duration > 0) return offer.duration + if(offer.name == Constants.peaceTreaty && offer.duration > 0) return offer.duration return 0 } diff --git a/core/src/com/unciv/logic/trade/TradeEvaluation.kt b/core/src/com/unciv/logic/trade/TradeEvaluation.kt index c11ee488..2defdaea 100644 --- a/core/src/com/unciv/logic/trade/TradeEvaluation.kt +++ b/core/src/com/unciv/logic/trade/TradeEvaluation.kt @@ -1,5 +1,6 @@ package com.unciv.logic.trade +import com.unciv.Constants import com.unciv.logic.automation.Automation import com.unciv.logic.automation.ThreatLevel import com.unciv.logic.civilization.CivilizationInfo @@ -29,7 +30,7 @@ class TradeEvaluation{ TradeType.Gold -> return offer.amount TradeType.Gold_Per_Turn -> return offer.amount * offer.duration TradeType.Treaty -> { - if (offer.name == "Peace Treaty") + if (offer.name == Constants.peaceTreaty) return evaluatePeaceCostForThem(civInfo,tradePartner) // Since it will be evaluated twice, once when they evaluate our offer and once when they evaluate theirs else return 1000 } @@ -119,7 +120,7 @@ class TradeEvaluation{ TradeType.Gold -> return offer.amount TradeType.Gold_Per_Turn -> return offer.amount * offer.duration TradeType.Treaty -> { - if (offer.name == "Peace Treaty") + if (offer.name == Constants.peaceTreaty) return evaluatePeaceCostForThem(civInfo,tradePartner) // Since it will be evaluated twice, once when they evaluate our offer and once when they evaluate theirs else return 1000 } diff --git a/core/src/com/unciv/logic/trade/TradeLogic.kt b/core/src/com/unciv/logic/trade/TradeLogic.kt index 71510a1e..99835ffc 100644 --- a/core/src/com/unciv/logic/trade/TradeLogic.kt +++ b/core/src/com/unciv/logic/trade/TradeLogic.kt @@ -1,5 +1,6 @@ package com.unciv.logic.trade +import com.unciv.Constants import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.diplomacy.DiplomaticStatus import com.unciv.logic.civilization.diplomacy.RelationshipLevel @@ -17,7 +18,7 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci val offers = TradeOffersList() if (civInfo.isCityState() && otherCivilization.isCityState()) return offers if(civInfo.isAtWarWith(otherCivilization)) - offers.add(TradeOffer("Peace Treaty", TradeType.Treaty, 20)) + offers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30)) if(!otherCivilization.getDiplomacyManager(civInfo).hasOpenBorders && !otherCivilization.isCityState() @@ -101,7 +102,7 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci from.updateViewableTiles() } if(offer.type== TradeType.Treaty){ - if(offer.name=="Peace Treaty") to.getDiplomacyManager(from).makePeace() + if(offer.name==Constants.peaceTreaty) to.getDiplomacyManager(from).makePeace() } if(offer.type==TradeType.Introduction) to.meetCivilization(to.gameInfo.getCivilization(offer.name.split(" ")[2])) diff --git a/core/src/com/unciv/ui/NewGameScreen.kt b/core/src/com/unciv/ui/NewGameScreen.kt index a3f9c702..9fd5de11 100644 --- a/core/src/com/unciv/ui/NewGameScreen.kt +++ b/core/src/com/unciv/ui/NewGameScreen.kt @@ -177,8 +177,8 @@ class NewGameScreen: PickerScreen(){ newGameOptionsTable.add(enemiesSelectBox).pad(10f).row() // Todo - re-enable this when city states are fit for players - addCityStatesSelectBox(newGameOptionsTable) - //newGameParameters.numberOfCityStates = 0 +// addCityStatesSelectBox(newGameOptionsTable) + newGameParameters.numberOfCityStates = 0 humanPlayers.addListener(object : ChangeListener() { override fun changed(event: ChangeEvent?, actor: Actor?) { diff --git a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt index e0030801..6ee04be1 100644 --- a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt +++ b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt @@ -5,6 +5,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane import com.badlogic.gdx.scenes.scene2d.ui.SplitPane import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.TextButton +import com.unciv.Constants import com.unciv.UnCivGame import com.unciv.logic.civilization.CityStateType import com.unciv.logic.civilization.CivilizationInfo @@ -122,8 +123,8 @@ class DiplomacyScreen:CameraStageBaseScreen() { PeaceButton.onClick { YesNoPopupTable("Peace with [${otherCiv.civName}]?".tr(), { val tradeLogic = TradeLogic(currentPlayerCiv, otherCiv) - tradeLogic.currentTrade.ourOffers.add(TradeOffer("Peace Treaty", TradeType.Treaty, 20)) - tradeLogic.currentTrade.theirOffers.add(TradeOffer("Peace Treaty", TradeType.Treaty, 20)) + tradeLogic.currentTrade.ourOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30)) + tradeLogic.currentTrade.theirOffers.add(TradeOffer(Constants.peaceTreaty, TradeType.Treaty, 30)) tradeLogic.acceptTrade() updateLeftSideTable() }, this) @@ -144,11 +145,25 @@ class DiplomacyScreen:CameraStageBaseScreen() { diplomacyTable.add(otherCiv.getNation().getLeaderDisplayName().toLabel()) diplomacyTable.addSeparator() - val tradeButton = TextButton("Trade".tr(), skin) - tradeButton.onClick { setTrade(otherCiv) } - if(otherCiv.getDiplomacyManager(currentPlayerCiv).hasFlag(DiplomacyFlags.DeclaredWar)) - tradeButton.disable() // Can't trade for 10 turns after war was declared - diplomacyTable.add(tradeButton).row() + if(!currentPlayerCiv.isAtWarWith(otherCiv)) { + val tradeButton = TextButton("Trade".tr(), skin) + tradeButton.onClick { setTrade(otherCiv) } + diplomacyTable.add(tradeButton).row() + } + else{ + val negotiatePeaceButton = TextButton("Negotiate Peace".tr(),skin) + negotiatePeaceButton.onClick { + val tradeTable = setTrade(otherCiv) + val peaceTreaty = TradeOffer(Constants.peaceTreaty,TradeType.Treaty,30) + tradeTable.tradeLogic.currentTrade.theirOffers.add(peaceTreaty) + tradeTable.tradeLogic.currentTrade.ourOffers.add(peaceTreaty) + tradeTable.offerColumnsTable.update() + } + if (otherCiv.getDiplomacyManager(currentPlayerCiv).hasFlag(DiplomacyFlags.DeclaredWar)) + negotiatePeaceButton.disable() // Can't trade for 10 turns after war was declared + + diplomacyTable.add(negotiatePeaceButton).row() + } val diplomacyManager = currentPlayerCiv.getDiplomacyManager(otherCiv) diff --git a/core/src/com/unciv/ui/trade/OffersListScroll.kt b/core/src/com/unciv/ui/trade/OffersListScroll.kt index 573e32e5..9ebb6d28 100644 --- a/core/src/com/unciv/ui/trade/OffersListScroll.kt +++ b/core/src/com/unciv/ui/trade/OffersListScroll.kt @@ -3,6 +3,7 @@ package com.unciv.ui.trade import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.TextButton +import com.unciv.Constants import com.unciv.logic.trade.TradeOffer import com.unciv.logic.trade.TradeOffersList import com.unciv.logic.trade.TradeType @@ -52,7 +53,7 @@ class OffersListScroll(val onOfferClicked: (TradeOffer) -> Unit) : ScrollPane(nu val amountPerClick = if (offer.type == Gold) 50 else 1 - if (offer.amount > 0) + if (offer.amount > 0 && offer.name != Constants.peaceTreaty) // can't disable peace treaty! tradeButton.onClick { val amountTransferred = min(amountPerClick, offer.amount) onOfferClicked(offer.copy(amount = amountTransferred)) diff --git a/core/src/com/unciv/ui/worldscreen/TradePopup.kt b/core/src/com/unciv/ui/worldscreen/TradePopup.kt index 8059df44..1d4a00a6 100644 --- a/core/src/com/unciv/ui/worldscreen/TradePopup.kt +++ b/core/src/com/unciv/ui/worldscreen/TradePopup.kt @@ -1,6 +1,7 @@ package com.unciv.ui.worldscreen import com.badlogic.gdx.scenes.scene2d.ui.Table +import com.unciv.Constants import com.unciv.logic.civilization.diplomacy.DiplomacyFlags import com.unciv.logic.trade.TradeLogic import com.unciv.logic.trade.TradeType @@ -62,7 +63,7 @@ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){ if(trade.ourOffers.all { it.type==TradeType.Luxury_Resource } && trade.theirOffers.all { it.type==TradeType.Luxury_Resource }) diplomacyManager.setFlag(DiplomacyFlags.DeclinedLuxExchange,20) // offer again in 20 turns - if(trade.ourOffers.any{ it.type==TradeType.Treaty && it.name=="Peace Treaty" }) + if(trade.ourOffers.any{ it.type==TradeType.Treaty && it.name== Constants.peaceTreaty }) diplomacyManager.setFlag(DiplomacyFlags.DeclinedPeace,5) remove()