diff --git a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt index ceedb2d5..b6e35363 100644 --- a/core/src/com/unciv/logic/automation/NextTurnAutomation.kt +++ b/core/src/com/unciv/logic/automation/NextTurnAutomation.kt @@ -17,6 +17,8 @@ class NextTurnAutomation{ /** Top-level AI turn tasklist */ fun automateCivMoves(civInfo: CivilizationInfo) { + respondToDemands(civInfo) + if(civInfo.isMajorCiv()) { offerPeaceTreaty(civInfo) exchangeTechs(civInfo) @@ -36,6 +38,18 @@ class NextTurnAutomation{ civInfo.popupAlerts.clear() // AIs don't care about popups. } + private fun respondToDemands(civInfo: CivilizationInfo) { + for(popupAlert in civInfo.popupAlerts){ + if(popupAlert.type==AlertType.CitySettledNearOtherCiv){ // 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) + diploManager.agreeNotToSettleNear() + else diploManager.refuseDemandNotToSettleNear() + } + } + } + private fun buyBuildingOrUnit(civInfo: CivilizationInfo) { //allow AI spending money to purchase building & unit diff --git a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt index d0d220b9..92774792 100644 --- a/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt +++ b/core/src/com/unciv/logic/civilization/diplomacy/DiplomacyManager.kt @@ -397,5 +397,16 @@ class DiplomacyManager() { } } + fun agreeNotToSettleNear(){ + otherCivDiplomacy().setFlag(DiplomacyFlags.AgreedToNotSettleNearUs,100) + addModifier(DiplomaticModifiers.UnacceptableDemands,-10f) + } + + fun refuseDemandNotToSettleNear(){ + addModifier(DiplomaticModifiers.UnacceptableDemands,-20f) + otherCivDiplomacy().setFlag(DiplomacyFlags.IgnoreThemSettlingNearUs,100) + otherCivDiplomacy().addModifier(DiplomaticModifiers.RefusedToNotSettleCitiesNearUs,-15f) + } + //endregion } diff --git a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt index fb61289c..be551c36 100644 --- a/core/src/com/unciv/ui/trade/DiplomacyScreen.kt +++ b/core/src/com/unciv/ui/trade/DiplomacyScreen.kt @@ -278,12 +278,12 @@ class DiplomacyScreen:CameraStageBaseScreen() { 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!") - currentPlayerCiv.getDiplomacyManager(otherCiv).setFlag(DiplomacyFlags.AgreedToNotSettleNearUs,100) } else { + otherCiv.getDiplomacyManager(currentPlayerCiv).refuseDemandNotToSettleNear() setRightSideFlavorText(otherCiv,"We shall do as we please.","Very well.") - otherCiv.getDiplomacyManager(currentPlayerCiv).addModifier(UnacceptableDemands,-20f) } } demandsTable.add(dontSettleCitiesButton).row() diff --git a/core/src/com/unciv/ui/worldscreen/AlertPopup.kt b/core/src/com/unciv/ui/worldscreen/AlertPopup.kt index 5b6af29c..adeeb48a 100644 --- a/core/src/com/unciv/ui/worldscreen/AlertPopup.kt +++ b/core/src/com/unciv/ui/worldscreen/AlertPopup.kt @@ -4,15 +4,12 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.TextButton import com.unciv.logic.civilization.AlertType import com.unciv.logic.civilization.PopupAlert -import com.unciv.logic.civilization.diplomacy.DiplomacyFlags -import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers import com.unciv.models.gamebasics.Nation import com.unciv.models.gamebasics.tr import com.unciv.ui.utils.addSeparator import com.unciv.ui.utils.onClick import com.unciv.ui.utils.toLabel import com.unciv.ui.worldscreen.optionstable.PopupTable -import kotlin.random.Random class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): PopupTable(worldScreen){ fun getCloseButton(text: String, action: (() -> Unit)?=null): TextButton { @@ -82,16 +79,15 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu } AlertType.CitySettledNearOtherCiv -> { val otherciv= worldScreen.gameInfo.getCivilization(popupAlert.value) - val otherCivDiploManager = otherciv.getDiplomacyManager(worldScreen.currentPlayerCiv) + val playerDiploManager = worldScreen.currentPlayerCiv.getDiplomacyManager(otherciv) val translatedNation = otherciv.getTranslatedNation() addLeaderName(translatedNation) addGoodSizedLabel("Please don't settle new cities near us.").row() add(getCloseButton("Very well, we shall look for new lands to settle."){ - otherCivDiploManager.setFlag(DiplomacyFlags.AgreedToNotSettleNearUs,100+ Random.nextInt(-20,20)) + playerDiploManager.agreeNotToSettleNear() }).row() add(getCloseButton("We shall do as we please.") { - otherCivDiploManager.addModifier(DiplomaticModifiers.RefusedToNotSettleCitiesNearUs,-10f) - otherCivDiploManager.setFlag(DiplomacyFlags.IgnoreThemSettlingNearUs,100) + playerDiploManager.refuseDemandNotToSettleNear() }).row() } AlertType.CitySettledNearOtherCivDespiteOurPromise -> {