AIs demand of each other not to settle near them, and they respond accordingly

This commit is contained in:
Yair Morgenstern 2019-06-10 16:44:06 +03:00
parent 96ee91cb08
commit f8cf9392fb
4 changed files with 30 additions and 9 deletions

View file

@ -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

View file

@ -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
}

View file

@ -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()

View file

@ -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 -> {