AI won't propose peace for 10 turns after war has been declared
This commit is contained in:
parent
11db5524dd
commit
0e8decfd07
4 changed files with 19 additions and 7 deletions
|
@ -3,6 +3,7 @@ package com.unciv.logic.automation
|
|||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.civilization.PlayerType
|
||||
import com.unciv.logic.civilization.TradeRequest
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.logic.trade.*
|
||||
|
@ -150,7 +151,7 @@ class NextTurnAutomation{
|
|||
// B. have a way for the AI to keep track of the "pending offers" - see DiplomacyManager.resourcesFromTrade
|
||||
|
||||
for (otherCiv in knownCivs.filter { it.isPlayerCivilization() && !it.isAtWarWith(civInfo)
|
||||
&& !civInfo.diplomacy[it.civName]!!.flagsCountdown.containsKey("DeclinedLuxExchange")}) {
|
||||
&& !civInfo.diplomacy[it.civName]!!.flagsCountdown.containsKey(DiplomacyFlags.DeclinedLuxExchange)}) {
|
||||
val trades = potentialLuxuryTrades(civInfo,otherCiv)
|
||||
for(trade in trades){
|
||||
val tradeRequest = TradeRequest(civInfo.civName, trade.reverse())
|
||||
|
@ -184,15 +185,15 @@ class NextTurnAutomation{
|
|||
val enemiesCiv = civInfo.diplomacy.filter{ it.value.diplomaticStatus == DiplomaticStatus.War }
|
||||
.map{ it.value.otherCiv() }
|
||||
.filterNot{ it == civInfo || it.isBarbarianCivilization() || it.cities.isEmpty() }
|
||||
.filter { !civInfo.diplomacy[it.civName]!!.flagsCountdown.containsKey("DeclinedPeace") }
|
||||
.filter { !civInfo.diplomacy[it.civName]!!.flagsCountdown.containsKey(DiplomacyFlags.DeclinedPeace) }
|
||||
|
||||
for (enemy in enemiesCiv) {
|
||||
val enemiesStrength = Automation().evaluteCombatStrength(enemy)
|
||||
if (enemiesStrength < ourCombatStrength * 2) {
|
||||
continue //Loser can still fight. Refuse peace.
|
||||
continue //We're losing, but can still fight. Refuse peace.
|
||||
}
|
||||
|
||||
//pay for peace
|
||||
// pay for peace
|
||||
val tradeLogic = TradeLogic(civInfo, enemy)
|
||||
|
||||
tradeLogic.currentTrade.ourOffers.add(TradeOffer("Peace Treaty", TradeType.Treaty, 20))
|
||||
|
|
|
@ -11,13 +11,18 @@ import com.unciv.models.gamebasics.GameBasics
|
|||
import com.unciv.models.gamebasics.tile.TileResource
|
||||
import com.unciv.models.gamebasics.tr
|
||||
|
||||
enum class DiplomacyFlags{
|
||||
DeclinedLuxExchange,
|
||||
DeclinedPeace
|
||||
}
|
||||
|
||||
class DiplomacyManager() {
|
||||
@Transient lateinit var civInfo: CivilizationInfo
|
||||
lateinit var otherCivName:String
|
||||
var trades = ArrayList<Trade>()
|
||||
var diplomaticStatus = DiplomaticStatus.War
|
||||
/** Contains various flags (declared war, promised to not settle, declined luxury trade) and the number of turns in which they will expire */
|
||||
var flagsCountdown = HashMap<String,Int>()
|
||||
var flagsCountdown = HashMap<DiplomacyFlags,Int>()
|
||||
|
||||
fun clone(): DiplomacyManager {
|
||||
val toReturn = DiplomacyManager()
|
||||
|
@ -117,6 +122,10 @@ class DiplomacyManager() {
|
|||
otherCiv.diplomacy[civInfo.civName]!!.diplomaticStatus = DiplomaticStatus.War
|
||||
otherCiv.addNotification("[${civInfo.civName}] has declared war on us!",null, Color.RED)
|
||||
otherCiv.popupAlerts.add(PopupAlert(AlertType.WarDeclaration,civInfo.civName))
|
||||
|
||||
/// AI won't propose peace for 10 turns
|
||||
flagsCountdown[DiplomacyFlags.DeclinedPeace]=10
|
||||
otherCiv.diplomacy[civInfo.civName]!!.flagsCountdown[DiplomacyFlags.DeclinedPeace]=10
|
||||
}
|
||||
//endregion
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.unciv.logic.trade
|
||||
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
||||
import com.unciv.models.gamebasics.tile.ResourceType
|
||||
import com.unciv.models.gamebasics.tr
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.unciv.ui.worldscreen
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
|
||||
import com.unciv.logic.trade.TradeLogic
|
||||
import com.unciv.logic.trade.TradeType
|
||||
import com.unciv.models.gamebasics.tr
|
||||
|
@ -58,10 +59,10 @@ class TradePopup(worldScreen: WorldScreen): PopupTable(worldScreen){
|
|||
currentPlayerCiv.tradeRequests.remove(tradeRequest)
|
||||
|
||||
if(trade.ourOffers.all { it.type==TradeType.Luxury_Resource } && trade.theirOffers.all { it.type==TradeType.Luxury_Resource })
|
||||
requestingCiv.diplomacy[currentPlayerCiv.civName]!!.flagsCountdown["DeclinedLuxExchange"]=20 // offer again in 20 turns
|
||||
requestingCiv.diplomacy[currentPlayerCiv.civName]!!.flagsCountdown[DiplomacyFlags.DeclinedLuxExchange]=20 // offer again in 20 turns
|
||||
|
||||
if(trade.ourOffers.any{ it.type==TradeType.Treaty && it.name=="Peace Treaty" })
|
||||
requestingCiv.diplomacy[currentPlayerCiv.civName]!!.flagsCountdown["DeclinedPeace"]=5 // offer again in 20 turns
|
||||
requestingCiv.diplomacy[currentPlayerCiv.civName]!!.flagsCountdown[DiplomacyFlags.DeclinedPeace]=5 // offer again in 20 turns
|
||||
|
||||
remove()
|
||||
worldScreen.shouldUpdate=true
|
||||
|
|
Loading…
Reference in a new issue