mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 14:24:43 -04:00
AIs demand of each other not to settle near them, and they respond accordingly
This commit is contained in:
parent
96ee91cb08
commit
f8cf9392fb
@ -17,6 +17,8 @@ class NextTurnAutomation{
|
|||||||
|
|
||||||
/** Top-level AI turn tasklist */
|
/** Top-level AI turn tasklist */
|
||||||
fun automateCivMoves(civInfo: CivilizationInfo) {
|
fun automateCivMoves(civInfo: CivilizationInfo) {
|
||||||
|
respondToDemands(civInfo)
|
||||||
|
|
||||||
if(civInfo.isMajorCiv()) {
|
if(civInfo.isMajorCiv()) {
|
||||||
offerPeaceTreaty(civInfo)
|
offerPeaceTreaty(civInfo)
|
||||||
exchangeTechs(civInfo)
|
exchangeTechs(civInfo)
|
||||||
@ -36,6 +38,18 @@ class NextTurnAutomation{
|
|||||||
civInfo.popupAlerts.clear() // AIs don't care about popups.
|
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) {
|
private fun buyBuildingOrUnit(civInfo: CivilizationInfo) {
|
||||||
//allow AI spending money to purchase building & unit
|
//allow AI spending money to purchase building & unit
|
||||||
|
@ -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
|
//endregion
|
||||||
}
|
}
|
||||||
|
@ -278,12 +278,12 @@ class DiplomacyScreen:CameraStageBaseScreen() {
|
|||||||
dontSettleCitiesButton.onClick {
|
dontSettleCitiesButton.onClick {
|
||||||
val threatLevel = Automation().threatAssessment(otherCiv,currentPlayerCiv)
|
val threatLevel = Automation().threatAssessment(otherCiv,currentPlayerCiv)
|
||||||
if(threatLevel>ThreatLevel.Medium){
|
if(threatLevel>ThreatLevel.Medium){
|
||||||
|
otherCiv.getDiplomacyManager(currentPlayerCiv).agreeNotToSettleNear()
|
||||||
setRightSideFlavorText(otherCiv,"Very well, we shall look for new lands to settle.","Excellent!")
|
setRightSideFlavorText(otherCiv,"Very well, we shall look for new lands to settle.","Excellent!")
|
||||||
currentPlayerCiv.getDiplomacyManager(otherCiv).setFlag(DiplomacyFlags.AgreedToNotSettleNearUs,100)
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
otherCiv.getDiplomacyManager(currentPlayerCiv).refuseDemandNotToSettleNear()
|
||||||
setRightSideFlavorText(otherCiv,"We shall do as we please.","Very well.")
|
setRightSideFlavorText(otherCiv,"We shall do as we please.","Very well.")
|
||||||
otherCiv.getDiplomacyManager(currentPlayerCiv).addModifier(UnacceptableDemands,-20f)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
demandsTable.add(dontSettleCitiesButton).row()
|
demandsTable.add(dontSettleCitiesButton).row()
|
||||||
|
@ -4,15 +4,12 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
|
|||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||||
import com.unciv.logic.civilization.AlertType
|
import com.unciv.logic.civilization.AlertType
|
||||||
import com.unciv.logic.civilization.PopupAlert
|
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.Nation
|
||||||
import com.unciv.models.gamebasics.tr
|
import com.unciv.models.gamebasics.tr
|
||||||
import com.unciv.ui.utils.addSeparator
|
import com.unciv.ui.utils.addSeparator
|
||||||
import com.unciv.ui.utils.onClick
|
import com.unciv.ui.utils.onClick
|
||||||
import com.unciv.ui.utils.toLabel
|
import com.unciv.ui.utils.toLabel
|
||||||
import com.unciv.ui.worldscreen.optionstable.PopupTable
|
import com.unciv.ui.worldscreen.optionstable.PopupTable
|
||||||
import kotlin.random.Random
|
|
||||||
|
|
||||||
class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): PopupTable(worldScreen){
|
class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): PopupTable(worldScreen){
|
||||||
fun getCloseButton(text: String, action: (() -> Unit)?=null): TextButton {
|
fun getCloseButton(text: String, action: (() -> Unit)?=null): TextButton {
|
||||||
@ -82,16 +79,15 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
|
|||||||
}
|
}
|
||||||
AlertType.CitySettledNearOtherCiv -> {
|
AlertType.CitySettledNearOtherCiv -> {
|
||||||
val otherciv= worldScreen.gameInfo.getCivilization(popupAlert.value)
|
val otherciv= worldScreen.gameInfo.getCivilization(popupAlert.value)
|
||||||
val otherCivDiploManager = otherciv.getDiplomacyManager(worldScreen.currentPlayerCiv)
|
val playerDiploManager = worldScreen.currentPlayerCiv.getDiplomacyManager(otherciv)
|
||||||
val translatedNation = otherciv.getTranslatedNation()
|
val translatedNation = otherciv.getTranslatedNation()
|
||||||
addLeaderName(translatedNation)
|
addLeaderName(translatedNation)
|
||||||
addGoodSizedLabel("Please don't settle new cities near us.").row()
|
addGoodSizedLabel("Please don't settle new cities near us.").row()
|
||||||
add(getCloseButton("Very well, we shall look for new lands to settle."){
|
add(getCloseButton("Very well, we shall look for new lands to settle."){
|
||||||
otherCivDiploManager.setFlag(DiplomacyFlags.AgreedToNotSettleNearUs,100+ Random.nextInt(-20,20))
|
playerDiploManager.agreeNotToSettleNear()
|
||||||
}).row()
|
}).row()
|
||||||
add(getCloseButton("We shall do as we please.") {
|
add(getCloseButton("We shall do as we please.") {
|
||||||
otherCivDiploManager.addModifier(DiplomaticModifiers.RefusedToNotSettleCitiesNearUs,-10f)
|
playerDiploManager.refuseDemandNotToSettleNear()
|
||||||
otherCivDiploManager.setFlag(DiplomacyFlags.IgnoreThemSettlingNearUs,100)
|
|
||||||
}).row()
|
}).row()
|
||||||
}
|
}
|
||||||
AlertType.CitySettledNearOtherCivDespiteOurPromise -> {
|
AlertType.CitySettledNearOtherCivDespiteOurPromise -> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user