From b6fc37aad89aa88b20d92526e0f275cb8d29ebef Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 20 Apr 2020 18:29:16 +0300 Subject: [PATCH] Resolved #1936 - can sign Declarations of Friendship in Multiplayer --- .../jsons/translations/template.properties | 10 +++- .../logic/automation/NextTurnAutomation.kt | 22 +++++--- .../unciv/logic/civilization/PopupAlert.kt | 3 +- .../src/com/unciv/ui/trade/DiplomacyScreen.kt | 50 +++++++++---------- .../com/unciv/ui/worldscreen/AlertPopup.kt | 37 ++++++++------ 5 files changed, 74 insertions(+), 48 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 055c956c..25cf5c5a 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -677,7 +677,7 @@ Tiles = Natural Wonders = Treasury deficit = -#Victory +# Victory Science victory = Cultural victory = @@ -723,6 +723,14 @@ Destroying the city instantly razes the city to the ground. = Remove your troops in our border immediately! = Sorry. = Never! = + +Offer Declaration of Friendship ([30] turns) = +My friend, shall we declare our friendship to the world? = +Sign Declaration of Friendship ([30] turns) = +We are not interested. = +We have signed a Declaration of Friendship with [otherCiv]! = +[otherCiv] has denied our Declaration of Friendship! = + Basics = Resources = Terrains = diff --git a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt index 6176754b..322e32a2 100644 --- a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt @@ -21,7 +21,7 @@ object NextTurnAutomation{ fun automateCivMoves(civInfo: CivilizationInfo) { if (civInfo.isBarbarian()) return BarbarianAutomation(civInfo).automate() - respondToDemands(civInfo) + respondToPopupAlerts(civInfo) respondToTradeRequests(civInfo) if(civInfo.isMajorCiv()) { @@ -45,7 +45,6 @@ object NextTurnAutomation{ reassignWorkedTiles(civInfo) trainSettler(civInfo) - civInfo.popupAlerts.clear() // AIs don't care about popups. } private fun respondToTradeRequests(civInfo: CivilizationInfo) { @@ -64,16 +63,27 @@ object NextTurnAutomation{ civInfo.tradeRequests.clear() } - private fun respondToDemands(civInfo: CivilizationInfo) { - for(popupAlert in civInfo.popupAlerts){ - if(popupAlert.type==AlertType.DemandToStopSettlingCitiesNear){ // we're called upon to make a decision + private fun respondToPopupAlerts(civInfo: CivilizationInfo) { + for(popupAlert in civInfo.popupAlerts) { + if (popupAlert.type == AlertType.DemandToStopSettlingCitiesNear) { // we're called upon to make a decision val demandingCiv = civInfo.gameInfo.getCivilization(popupAlert.value) val diploManager = civInfo.getDiplomacyManager(demandingCiv) - if(Automation.threatAssessment(civInfo,demandingCiv) >= ThreatLevel.High) + if (Automation.threatAssessment(civInfo, demandingCiv) >= ThreatLevel.High) diploManager.agreeNotToSettleNear() else diploManager.refuseDemandNotToSettleNear() } + if (popupAlert.type == AlertType.DeclarationOfFriendship) { + val requestingCiv = civInfo.gameInfo.getCivilization(popupAlert.value) + val diploManager = civInfo.getDiplomacyManager(requestingCiv) + if (diploManager.relationshipLevel() > RelationshipLevel.Neutral + && !diploManager.otherCivDiplomacy().hasFlag(DiplomacyFlags.Denunceation)) { + diploManager.signDeclarationOfFriendship() + requestingCiv.addNotification("We have signed a Declaration of Friendship with [${civInfo.civName}]!", Color.GOLD) + } else requestingCiv.addNotification("[${civInfo.civName}] has denied our Declaration of Friendship!", Color.GOLD) + } } + + civInfo.popupAlerts.clear() // AIs don't care about popups. } private fun tryGainInfluence(civInfo: CivilizationInfo, cityState:CivilizationInfo) { diff --git a/core/src/com/unciv/logic/civilization/PopupAlert.kt b/core/src/com/unciv/logic/civilization/PopupAlert.kt index 140df829..c85aa5ad 100644 --- a/core/src/com/unciv/logic/civilization/PopupAlert.kt +++ b/core/src/com/unciv/logic/civilization/PopupAlert.kt @@ -1,6 +1,6 @@ package com.unciv.logic.civilization -enum class AlertType{ +enum class AlertType { Defeated, WonderBuilt, TechResearched, @@ -11,6 +11,7 @@ enum class AlertType{ DemandToStopSettlingCitiesNear, CitySettledNearOtherCivDespiteOurPromise, GoldenAge, + DeclarationOfFriendship, } class PopupAlert { diff --git a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt index c21cdcb4..74616380 100644 --- a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt +++ b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt @@ -177,29 +177,28 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { diplomacyTable.defaults().pad(10f) diplomacyTable.add(otherCiv.getLeaderDisplayName().toLabel(fontSize = 24)).row() - if(otherCivDiplomacyManager.relationshipLevel()<=RelationshipLevel.Enemy) + if (otherCivDiplomacyManager.relationshipLevel() <= RelationshipLevel.Enemy) diplomacyTable.add(otherCiv.nation.hateHello.toLabel()).row() else diplomacyTable.add(otherCiv.nation.neutralHello.toLabel()).row() diplomacyTable.addSeparator() - if(!viewingCiv.isAtWarWith(otherCiv)) { + if (!viewingCiv.isAtWarWith(otherCiv)) { val tradeButton = "Trade".toTextButton() tradeButton.onClick { setTrade(otherCiv).apply { - tradeLogic.ourAvailableOffers.apply { remove(firstOrNull { it.type==TradeType.Treaty }) } - tradeLogic.theirAvailableOffers.apply { remove(firstOrNull { it.type==TradeType.Treaty }) } + tradeLogic.ourAvailableOffers.apply { remove(firstOrNull { it.type == TradeType.Treaty }) } + tradeLogic.theirAvailableOffers.apply { remove(firstOrNull { it.type == TradeType.Treaty }) } offerColumnsTable.update() } } diplomacyTable.add(tradeButton).row() - if(isNotPlayersTurn()) tradeButton.disable() - } - else{ + if (isNotPlayersTurn()) tradeButton.disable() + } else { val negotiatePeaceButton = "Negotiate Peace".toTextButton() negotiatePeaceButton.onClick { val tradeTable = setTrade(otherCiv) - val peaceTreaty = TradeOffer(Constants.peaceTreaty,TradeType.Treaty) + val peaceTreaty = TradeOffer(Constants.peaceTreaty, TradeType.Treaty) tradeTable.tradeLogic.currentTrade.theirOffers.add(peaceTreaty) tradeTable.tradeLogic.currentTrade.ourOffers.add(peaceTreaty) tradeTable.offerColumnsTable.update() @@ -212,22 +211,21 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { val diplomacyManager = viewingCiv.getDiplomacyManager(otherCiv) - - if (!viewingCiv.isAtWarWith(otherCiv)) { - if(otherCivDiplomacyManager.relationshipLevel() > RelationshipLevel.Neutral - && !diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship) - && !diplomacyManager.hasFlag(DiplomacyFlags.Denunceation)){ - val declareFriendshipButton = "Declare Friendship ([30] turns)".toTextButton() + if(!diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship)) { + val declareFriendshipButton = "Offer Declaration of Friendship ([30] turns)".toTextButton() declareFriendshipButton.onClick { - diplomacyManager.signDeclarationOfFriendship() - setRightSideFlavorText(otherCiv,"May our nations forever remain united!","Indeed!") + otherCiv.popupAlerts.add(PopupAlert(AlertType.DeclarationOfFriendship, viewingCiv.civName)) + declareFriendshipButton.disable() } diplomacyTable.add(declareFriendshipButton).row() - if(isNotPlayersTurn()) declareFriendshipButton.disable() + if (isNotPlayersTurn() || otherCiv.popupAlerts + .any { it.type == AlertType.DeclarationOfFriendship && it.value == viewingCiv.civName }) + declareFriendshipButton.disable() } - if(viewingCiv.canSignResearchAgreementsWith(otherCiv)){ + + if (viewingCiv.canSignResearchAgreementsWith(otherCiv)) { val researchAgreementButton = "Research Agreement".toTextButton() val requiredGold = viewingCiv.getResearchAgreementCost(otherCiv) @@ -248,31 +246,31 @@ class DiplomacyScreen(val viewingCiv:CivilizationInfo):CameraStageBaseScreen() { diplomacyTable.add(researchAgreementButton).row() } - if(!diplomacyManager.hasFlag(DiplomacyFlags.Denunceation) - && !diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship)){ + if (!diplomacyManager.hasFlag(DiplomacyFlags.Denunceation) + && !diplomacyManager.hasFlag(DiplomacyFlags.DeclarationOfFriendship)) { val denounceButton = "Denounce ([30] turns)".toTextButton() denounceButton.onClick { diplomacyManager.denounce() - setRightSideFlavorText(otherCiv,"We will remember this.","Very well.") + setRightSideFlavorText(otherCiv, "We will remember this.", "Very well.") } diplomacyTable.add(denounceButton).row() - if(isNotPlayersTurn()) denounceButton.disable() + if (isNotPlayersTurn()) denounceButton.disable() } val declareWarButton = getDeclareWarButton(diplomacyManager, otherCiv) diplomacyTable.add(declareWarButton).row() - if(isNotPlayersTurn()) declareWarButton.disable() + if (isNotPlayersTurn()) declareWarButton.disable() } val demandsButton = "Demands".toTextButton() demandsButton.onClick { rightSideTable.clear() - rightSideTable.add(getDemandsTable(viewingCiv,otherCiv)) + rightSideTable.add(getDemandsTable(viewingCiv, otherCiv)) } diplomacyTable.add(demandsButton).row() - if(isNotPlayersTurn()) demandsButton.disable() + if (isNotPlayersTurn()) demandsButton.disable() - if(!otherCiv.isPlayerCivilization()) { // human players make their own choices + if (!otherCiv.isPlayerCivilization()) { // human players make their own choices diplomacyTable.add(getRelationshipTable(otherCivDiplomacyManager)).row() diplomacyTable.add(getDiplomacyModifiersTable(otherCivDiplomacyManager)).row() } diff --git a/core/src/com/unciv/ui/worldscreen/AlertPopup.kt b/core/src/com/unciv/ui/worldscreen/AlertPopup.kt index 565c1d4a..403ec869 100644 --- a/core/src/com/unciv/ui/worldscreen/AlertPopup.kt +++ b/core/src/com/unciv/ui/worldscreen/AlertPopup.kt @@ -59,7 +59,7 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu } AlertType.CityConquered -> { val city = worldScreen.gameInfo.getCities().first { it.id == popupAlert.value } - addGoodSizedLabel("What would you like to do with the city?",24) + addGoodSizedLabel("What would you like to do with the city?", 24) .padBottom(20f).row() val conqueringCiv = worldScreen.gameInfo.currentPlayerCiv @@ -68,19 +68,19 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu && conqueringCiv.civName != city.foundingCiv) { // or belongs originally to us add("Liberate".toTextButton().onClick { city.liberateCity(conqueringCiv) - worldScreen.shouldUpdate=true + worldScreen.shouldUpdate = true close() }).row() addGoodSizedLabel("Liberating a city returns it to its original owner, giving you a massive relationship boost with them!") addSeparator() } - if (!conqueringCiv.isOneCityChallenger()){ + if (!conqueringCiv.isOneCityChallenger()) { add("Annex".toTextButton().onClick { city.puppetCity(conqueringCiv) city.annexCity() - worldScreen.shouldUpdate=true + worldScreen.shouldUpdate = true close() }).row() addGoodSizedLabel("Annexed cities become part of your regular empire.").row() @@ -89,7 +89,7 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu add("Puppet".toTextButton().onClick { city.puppetCity(conqueringCiv) - worldScreen.shouldUpdate=true + worldScreen.shouldUpdate = true close() }).row() addGoodSizedLabel("Puppeted cities do not increase your tech or policy cost, but their citizens generate 1.5x the regular unhappiness.").row() @@ -102,12 +102,13 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu add("Raze".toTextButton().apply { if (city.isOriginalCapital) disable() else onClick { - city.puppetCity(conqueringCiv) - city.annexCity() - city.isBeingRazed = true - worldScreen.shouldUpdate=true - close() - }}).row() + city.puppetCity(conqueringCiv) + city.annexCity() + city.isBeingRazed = true + worldScreen.shouldUpdate = true + close() + } + }).row() addGoodSizedLabel("Razing the city annexes it, and starts razing the city to the ground.").row() addGoodSizedLabel("The population will gradually dwindle until the city is destroyed.").row() } else { @@ -115,13 +116,11 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu add("Destroy".toTextButton().onClick { city.puppetCity(conqueringCiv) city.destroyCity() - worldScreen.shouldUpdate=true + worldScreen.shouldUpdate = true close() }).row() addGoodSizedLabel("Destroying the city instantly razes the city to the ground.").row() - } - } AlertType.BorderConflict -> { val civInfo = worldScreen.gameInfo.getCivilization(popupAlert.value) @@ -180,6 +179,16 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu addGoodSizedLabel("Your citizens have been happy with your rule for so long that the empire enters a Golden Age!").row() add(getCloseButton(Constants.close)) } + AlertType.DeclarationOfFriendship -> { + val otherciv = worldScreen.gameInfo.getCivilization(popupAlert.value) + val playerDiploManager = worldScreen.viewingCiv.getDiplomacyManager(otherciv) + addLeaderName(otherciv) + addGoodSizedLabel("My friend, shall we declare our friendship to the world?").row() + add(getCloseButton("We are not interested.")).row() + add(getCloseButton("Declare Friendship ([30] turns)") { + playerDiploManager.signDeclarationOfFriendship() + }).row() + } } }