From 27992058845babaf23fe2bfe4a9b37dcafb95fea Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 29 Jul 2019 17:03:24 +0300 Subject: [PATCH] Demands now work between human players! --- .../jsons/Translations/Notifications.json | 3 +++ .../logic/automation/NextTurnAutomation.kt | 4 ++-- core/src/com/unciv/logic/city/CityInfo.kt | 2 +- .../unciv/logic/civilization/PopupAlert.kt | 4 +++- .../diplomacy/DiplomacyManager.kt | 4 +++- .../src/com/unciv/ui/trade/DiplomacyScreen.kt | 19 ++++++++----------- .../com/unciv/ui/worldscreen/AlertPopup.kt | 2 +- .../com/unciv/ui/worldscreen/WorldScreen.kt | 7 +------ 8 files changed, 22 insertions(+), 23 deletions(-) diff --git a/android/assets/jsons/Translations/Notifications.json b/android/assets/jsons/Translations/Notifications.json index 5668720061..d461ae9dcc 100644 --- a/android/assets/jsons/Translations/Notifications.json +++ b/android/assets/jsons/Translations/Notifications.json @@ -491,6 +491,9 @@ French:"[civName] nous offre un(e) [untiName] prĂȘt de [cityName]!" } + "[civName] has denounced us!":{ + } + // Trade "[civName] has accepted your trade request":{ } diff --git a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt index 6b343e474a..7a66f73124 100644 --- a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt @@ -60,7 +60,7 @@ class NextTurnAutomation{ private fun respondToDemands(civInfo: CivilizationInfo) { for(popupAlert in civInfo.popupAlerts){ - if(popupAlert.type==AlertType.CitySettledNearOtherCiv){ // we're called upon to make a decision + 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) @@ -472,7 +472,7 @@ class NextTurnAutomation{ else -> { val threatLevel = Automation().threatAssessment(civInfo,otherCiv) if(threatLevel addModifier(DiplomaticModifiers.DenouncedOurAllies,-15f) } } - otherCiv().addNotification("[${civInfo.civName}] has denounced us!", Color.RED) // todo translation + otherCiv().addNotification("[${civInfo.civName}] has denounced us!", Color.RED) } fun agreeNotToSettleNear(){ otherCivDiplomacy().setFlag(DiplomacyFlags.AgreedToNotSettleNearUs,100) addModifier(DiplomaticModifiers.UnacceptableDemands,-10f) + otherCiv().addNotification("[${civInfo.civName}] agreed to stop settling cities near us!", Color.MAROON) } fun refuseDemandNotToSettleNear(){ addModifier(DiplomaticModifiers.UnacceptableDemands,-20f) otherCivDiplomacy().setFlag(DiplomacyFlags.IgnoreThemSettlingNearUs,100) otherCivDiplomacy().addModifier(DiplomaticModifiers.RefusedToNotSettleCitiesNearUs,-15f) + otherCiv().addNotification("[${civInfo.civName}] refused to stop settling cities near us!", Color.MAROON) } //endregion diff --git a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt index fda04ebcca..a598cd2f45 100644 --- a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt +++ b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt @@ -7,10 +7,10 @@ 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.automation.Automation -import com.unciv.logic.automation.ThreatLevel +import com.unciv.logic.civilization.AlertType import com.unciv.logic.civilization.CityStateType import com.unciv.logic.civilization.CivilizationInfo +import com.unciv.logic.civilization.PopupAlert import com.unciv.logic.civilization.diplomacy.DiplomacyFlags import com.unciv.logic.civilization.diplomacy.DiplomacyManager import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers.* @@ -268,19 +268,16 @@ class DiplomacyScreen:CameraStageBaseScreen() { private fun getDemandsTable(currentPlayerCiv: CivilizationInfo, otherCiv: CivilizationInfo): Table { val demandsTable = Table() demandsTable.defaults().pad(10f) + val dontSettleCitiesButton = TextButton("Please don't settle new cities near us.".tr(),skin) + if(otherCiv.popupAlerts.any { it.type==AlertType.DemandToStopSettlingCitiesNear && it.value==currentPlayerCiv.civName }) + dontSettleCitiesButton.disable() dontSettleCitiesButton.onClick { - val threatLevel = Automation().threatAssessment(otherCiv,currentPlayerCiv) - if(threatLevel>ThreatLevel.Medium){ - otherCiv.getDiplomacyManager(currentPlayerCiv).agreeNotToSettleNear() - setRightSideFlavorText(otherCiv,"Very well, we shall look for new lands to settle.","Excellent!") - } - else { - otherCiv.getDiplomacyManager(currentPlayerCiv).refuseDemandNotToSettleNear() - setRightSideFlavorText(otherCiv,"We shall do as we please.","Very well.") - } + otherCiv.popupAlerts.add(PopupAlert(AlertType.DemandToStopSettlingCitiesNear, currentPlayerCiv.civName)) + dontSettleCitiesButton.disable() } demandsTable.add(dontSettleCitiesButton).row() + demandsTable.add(TextButton("Close".tr(),skin).onClick { updateRightSide(otherCiv) }) return demandsTable } diff --git a/core/src/com/unciv/ui/worldscreen/AlertPopup.kt b/core/src/com/unciv/ui/worldscreen/AlertPopup.kt index adeeb48adf..056c1cb150 100644 --- a/core/src/com/unciv/ui/worldscreen/AlertPopup.kt +++ b/core/src/com/unciv/ui/worldscreen/AlertPopup.kt @@ -77,7 +77,7 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu responseTable.add(getCloseButton("Never!")) add(responseTable) } - AlertType.CitySettledNearOtherCiv -> { + AlertType.DemandToStopSettlingCitiesNear -> { val otherciv= worldScreen.gameInfo.getCivilization(popupAlert.value) val playerDiploManager = worldScreen.currentPlayerCiv.getDiplomacyManager(otherciv) val translatedNation = otherciv.getTranslatedNation() diff --git a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt index d03c9f6da3..20ff4413e9 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldScreen.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldScreen.kt @@ -95,12 +95,7 @@ class WorldScreen : CameraStageBaseScreen() { } tileMapHolder.setCenterPosition(tileToCenterOn,true) - - // On the one hand, all updates to e.g. TileGroups need to happen on the main rendering thread. - // On the other hand, the initial setup requires setting up a lot of items on the map, - // and we would sometimes get an "Input dispatching timed out" ANR when doing so. - // Putting it in a postRunnnable is our way of attempting to avoid this. - Gdx.app.postRunnable { render(0f) } + update() } // This is private so that we will set the shouldUpdate to true instead.