diff --git a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt index d6342f5de8..58a3de8681 100644 --- a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt @@ -169,7 +169,7 @@ class NextTurnAutomation{ && !civInfo.getDiplomacyManager(it).hasFlag(DiplomacyFlags.DeclinedLuxExchange)}) { val relationshipLevel = civInfo.getDiplomacyManager(otherCiv).relationshipLevel() - if(relationshipLevel==RelationshipLevel.Enemy || relationshipLevel == RelationshipLevel.Unforgivable) + if(relationshipLevel <= RelationshipLevel.Enemy) continue val trades = potentialLuxuryTrades(civInfo,otherCiv) diff --git a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt index b086665022..cda2d697c7 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt @@ -52,7 +52,7 @@ class DiplomacyManager() { /** Contains various flags (declared war, promised to not settle, declined luxury trade) and the number of turns in which they will expire. * The JSON serialize/deserialize REFUSES to deserialize hashmap keys as Enums, so I'm forced to use strings instead =( * This is so sad Alexa play Despacito */ - var flagsCountdown = HashMap() + private var flagsCountdown = HashMap() /** For AI. Positive is good relations, negative is bad. * Baseline is 1 point for each turn of peace - so declaring a war upends 40 years of peace, and e.g. capturing a city can be another 30 or 40. diff --git a/core/src/com/unciv/logic/trade/TradeLogic.kt b/core/src/com/unciv/logic/trade/TradeLogic.kt index 3dfacfd27f..71510a1e75 100644 --- a/core/src/com/unciv/logic/trade/TradeLogic.kt +++ b/core/src/com/unciv/logic/trade/TradeLogic.kt @@ -25,7 +25,7 @@ class TradeLogic(val ourCivilization:CivilizationInfo, val otherCivilization: Ci && otherCivilization.tech.getTechUniques().contains("Enables Open Borders agreements")) { val relationshipLevel = otherCivilization.getDiplomacyManager(civInfo).relationshipLevel() - if(relationshipLevel!=RelationshipLevel.Enemy && relationshipLevel!=RelationshipLevel.Unforgivable) + if(relationshipLevel >= RelationshipLevel.Neutral) offers.add(TradeOffer("Open Borders", TradeType.Agreement, 30)) } diff --git a/core/src/com/unciv/models/gamebasics/Nation.kt b/core/src/com/unciv/models/gamebasics/Nation.kt index 112031e085..c1cc67fc71 100644 --- a/core/src/com/unciv/models/gamebasics/Nation.kt +++ b/core/src/com/unciv/models/gamebasics/Nation.kt @@ -14,6 +14,9 @@ class Nation : INamed { } var leaderName="" + fun getLeaderDisplayName() = if(isCityState()) "City-state [${getNameTranslation()}]".tr() + else "[$leaderName] of [${getNameTranslation()}]" + var cityStateType: CityStateType?=null var declaringWar="" var attacked="" diff --git a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt index fbfcfd4d30..aca15f2e07 100644 --- a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt +++ b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt @@ -8,6 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.unciv.UnCivGame import com.unciv.logic.civilization.CityStateType import com.unciv.logic.civilization.CivilizationInfo +import com.unciv.logic.civilization.diplomacy.DiplomacyManager import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers.* import com.unciv.logic.civilization.diplomacy.RelationshipLevel import com.unciv.logic.trade.TradeLogic @@ -60,7 +61,8 @@ class DiplomacyScreen:CameraStageBaseScreen() { civIndicator.onClick { rightSideTable.clear() - rightSideTable.add(getDiplomacyTable(civ)) + if(civ.isCityState()) rightSideTable.add(getCityStateDiplomacyTable(civ)) + else rightSideTable.add(getMajorCivDiplomacyTable(civ)) } } } @@ -77,17 +79,16 @@ class DiplomacyScreen:CameraStageBaseScreen() { currentPlayerCiv.gold -= 100 otherCiv.getDiplomacyManager(currentPlayerCiv).influence += 10 rightSideTable.clear() - rightSideTable.add(getDiplomacyTable(otherCiv)) + rightSideTable.add(getCityStateDiplomacyTable(otherCiv)) } - private fun getDiplomacyTable(otherCiv: CivilizationInfo): Table { + + private fun getCityStateDiplomacyTable(otherCiv: CivilizationInfo): Table { val currentPlayerCiv = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization() val diplomacyTable = Table() diplomacyTable.defaults().pad(10f) - val leaderName: String if (otherCiv.isCityState()) { - leaderName = "City-state of [" + otherCiv.civName + "]" - diplomacyTable.add(leaderName.toLabel()).row() + diplomacyTable.add(otherCiv.getNation().getLeaderDisplayName().toLabel()) diplomacyTable.add(("Type : " + otherCiv.getCityStateType().toString()).toLabel()).row() diplomacyTable.add(("Influence : " + otherCiv.getDiplomacyManager(currentPlayerCiv).influence.toInt().toString()).toLabel()).row() if (otherCiv.getDiplomacyManager(currentPlayerCiv).influence > 60) { @@ -96,27 +97,19 @@ class DiplomacyScreen:CameraStageBaseScreen() { } } } else { - leaderName = "[" + otherCiv.getNation().leaderName + "] of [" + otherCiv.civName + "]" - diplomacyTable.add(leaderName.toLabel()) + diplomacyTable.add(otherCiv.getNation().getLeaderDisplayName().toLabel()) } diplomacyTable.addSeparator() - if(otherCiv.isCityState()) { - val giftButton = TextButton("Give 100 gold".tr(), skin) - giftButton.onClick{ giveGoldGift(otherCiv) } - diplomacyTable.add(giftButton).row() - if (currentPlayerCiv.gold < 1) giftButton.disable() - } else { - val tradeButton = TextButton("Trade".tr(), skin) - tradeButton.onClick { setTrade(otherCiv) } - diplomacyTable.add(tradeButton).row() - } + val giftButton = TextButton("Give 100 gold".tr(), skin) + giftButton.onClick{ giveGoldGift(otherCiv) } + diplomacyTable.add(giftButton).row() + if (currentPlayerCiv.gold < 1) giftButton.disable() val diplomacyManager = currentPlayerCiv.getDiplomacyManager(otherCiv) if (currentPlayerCiv.isAtWarWith(otherCiv)) { - if (otherCiv.isCityState()) { - val PeaceButton = TextButton("Negociate Peace".tr(), skin) + val PeaceButton = TextButton("Negotiate Peace".tr(), skin) PeaceButton.onClick { YesNoPopupTable("Peace with [${otherCiv.civName}]?".tr(), { val tradeLogic = TradeLogic(currentPlayerCiv, otherCiv) @@ -127,75 +120,94 @@ class DiplomacyScreen:CameraStageBaseScreen() { }, this) } diplomacyTable.add(PeaceButton).row() - } } else { - val declareWarButton = TextButton("Declare war".tr(), skin) - declareWarButton.color = Color.RED - val turnsToPeaceTreaty = diplomacyManager.turnsToPeaceTreaty() - if (turnsToPeaceTreaty > 0) { - declareWarButton.disable() - declareWarButton.setText(declareWarButton.text.toString() + " ($turnsToPeaceTreaty)") - } - declareWarButton.onClick { - YesNoPopupTable("Declare war on [${otherCiv.civName}]?".tr(), { - diplomacyManager.declareWar() - - val responsePopup = PopupTable(this) - val otherCivLeaderName: String - if (otherCiv.isCityState()) { - otherCivLeaderName = "City-state [" + otherCiv.civName + "]" - } else { - otherCivLeaderName = "[" + otherCiv.getNation().leaderName + "] of [" + otherCiv.civName + "]" - } - responsePopup.add(otherCivLeaderName.toLabel()) - responsePopup.addSeparator() - responsePopup.addGoodSizedLabel(otherCiv.getNation().attacked).row() - responsePopup.addButton("Very well.".tr()) { responsePopup.remove() } - responsePopup.open() - - updateLeftSideTable() - }, this) - } + val declareWarButton = getDeclareWarButton(diplomacyManager, otherCiv) diplomacyTable.add(declareWarButton).row() } - if(!otherCiv.isCityState()){ - val diplomacyModifiersTable = Table() - val otherCivDiplomacyManager = otherCiv.getDiplomacyManager(currentPlayerCiv) - - 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){ - var text = when(valueOf(modifier.key)){ - DeclaredWarOnUs -> "You declared war on us!" - WarMongerer -> "Your warmongering ways are unacceptable to us." - CapturedOurCities -> "You have captured our cities!" - YearsOfPeace -> "Years of peace have strengthened our relations." - SharedEnemy -> "Our mutual military struggle brings us closer together." - DeclarationOfFriendship -> "We have signed a public declaration of friendship" - DeclaredFriendshipWithOurEnemies -> "You have declared friendship with our enemies!" - DeclaredFriendshipWithOurAllies -> "You have declared friendship with our allies" - } - text = text.tr()+" " - 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() - } - return diplomacyTable } + + private fun getDeclareWarButton(diplomacyManager: DiplomacyManager, otherCiv: CivilizationInfo): TextButton { + val declareWarButton = TextButton("Declare war".tr(), skin) + declareWarButton.color = Color.RED + val turnsToPeaceTreaty = diplomacyManager.turnsToPeaceTreaty() + if (turnsToPeaceTreaty > 0) { + declareWarButton.disable() + declareWarButton.setText(declareWarButton.text.toString() + " ($turnsToPeaceTreaty)") + } + declareWarButton.onClick { + YesNoPopupTable("Declare war on [${otherCiv.civName}]?".tr(), { + diplomacyManager.declareWar() + + val responsePopup = PopupTable(this) + responsePopup.add(otherCiv.getTranslatedNation().getLeaderDisplayName().toLabel()) + responsePopup.addSeparator() + responsePopup.addGoodSizedLabel(otherCiv.getNation().attacked).row() + responsePopup.addButton("Very well.".tr()) { responsePopup.remove() } + responsePopup.open() + + updateLeftSideTable() + }, this) + } + return declareWarButton + } + + private fun getMajorCivDiplomacyTable(otherCiv: CivilizationInfo): Table { + val currentPlayerCiv = UnCivGame.Current.gameInfo.getCurrentPlayerCivilization() + val diplomacyTable = Table() + diplomacyTable.defaults().pad(10f) + diplomacyTable.add(otherCiv.getNation().getLeaderDisplayName().toLabel()) + diplomacyTable.addSeparator() + + val tradeButton = TextButton("Trade".tr(), skin) + tradeButton.onClick { setTrade(otherCiv) } + diplomacyTable.add(tradeButton).row() + + val diplomacyManager = currentPlayerCiv.getDiplomacyManager(otherCiv) + + if (!currentPlayerCiv.isAtWarWith(otherCiv)) { + val declareWarButton = getDeclareWarButton(diplomacyManager, otherCiv) + diplomacyTable.add(declareWarButton).row() + } + + + val diplomacyModifiersTable = Table() + val otherCivDiplomacyManager = otherCiv.getDiplomacyManager(currentPlayerCiv) + + 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) { + var text = when (valueOf(modifier.key)) { + DeclaredWarOnUs -> "You declared war on us!" + WarMongerer -> "Your warmongering ways are unacceptable to us." + CapturedOurCities -> "You have captured our cities!" + YearsOfPeace -> "Years of peace have strengthened our relations." + SharedEnemy -> "Our mutual military struggle brings us closer together." + DeclarationOfFriendship -> "We have signed a public declaration of friendship" + DeclaredFriendshipWithOurEnemies -> "You have declared friendship with our enemies!" + DeclaredFriendshipWithOurAllies -> "You have declared friendship with our allies" + } + text = text.tr() + " " + 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() + + return diplomacyTable + } + } \ No newline at end of file diff --git a/core/src/com/unciv/ui/worldscreen/AlertPopup.kt b/core/src/com/unciv/ui/worldscreen/AlertPopup.kt index 89cea6856f..3a74ef3941 100644 --- a/core/src/com/unciv/ui/worldscreen/AlertPopup.kt +++ b/core/src/com/unciv/ui/worldscreen/AlertPopup.kt @@ -19,13 +19,7 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu } fun addLeaderName(translatedNation: Nation){ - val otherCivLeaderName: String - if (translatedNation.isCityState()) { - otherCivLeaderName = "City-state [${translatedNation.getNameTranslation()}]".tr() - } else { - otherCivLeaderName = "[${translatedNation.leaderName}] of [${translatedNation.getNameTranslation()}]".tr() - } - + val otherCivLeaderName = translatedNation.getLeaderDisplayName() add(otherCivLeaderName.toLabel()) addSeparator() }