mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Made it impossible to cut short peace treaties (#5450)
This commit is contained in:
parent
24d7a57c1f
commit
2bd8132b8d
@ -357,20 +357,27 @@ class DiplomacyManager() {
|
|||||||
|
|
||||||
//region state-changing functions
|
//region state-changing functions
|
||||||
fun removeUntenableTrades() {
|
fun removeUntenableTrades() {
|
||||||
|
|
||||||
for (trade in trades.toList()) {
|
for (trade in trades.toList()) {
|
||||||
|
|
||||||
// Every cancelled trade can change this - if 1 resource is missing,
|
// Every cancelled trade can change this - if 1 resource is missing,
|
||||||
// don't cancel all trades of that resource, only cancel one (the first one, as it happens, since they're added chronologically)
|
// don't cancel all trades of that resource, only cancel one (the first one, as it happens, since they're added chronologically)
|
||||||
val negativeCivResources = civInfo.getCivResources()
|
val negativeCivResources = civInfo.getCivResources()
|
||||||
.filter { it.amount < 0 }.map { it.resource.name }
|
.filter { it.amount < 0 }.map { it.resource.name }
|
||||||
|
|
||||||
for (offer in trade.ourOffers) {
|
for (offer in trade.ourOffers) {
|
||||||
if (offer.type in listOf(TradeType.Luxury_Resource, TradeType.Strategic_Resource)
|
if (offer.type in listOf(TradeType.Luxury_Resource, TradeType.Strategic_Resource)
|
||||||
&& (offer.name in negativeCivResources || !civInfo.gameInfo.ruleSet.tileResources.containsKey(offer.name))) {
|
&& (offer.name in negativeCivResources || !civInfo.gameInfo.ruleSet.tileResources.containsKey(offer.name))
|
||||||
|
) {
|
||||||
|
|
||||||
trades.remove(trade)
|
trades.remove(trade)
|
||||||
val otherCivTrades = otherCiv().getDiplomacyManager(civInfo).trades
|
val otherCivTrades = otherCiv().getDiplomacyManager(civInfo).trades
|
||||||
otherCivTrades.removeAll { it.equals(trade.reverse()) }
|
otherCivTrades.removeAll { it.equals(trade.reverse()) }
|
||||||
|
|
||||||
|
// Can't cut short peace treaties!
|
||||||
|
if (trade.theirOffers.any { it.name == Constants.peaceTreaty }) {
|
||||||
|
remakePeaceTreaty(trade.theirOffers.first { it.name == Constants.peaceTreaty }.duration)
|
||||||
|
}
|
||||||
|
|
||||||
civInfo.addNotification("One of our trades with [$otherCivName] has been cut short", NotificationIcon.Trade, otherCivName)
|
civInfo.addNotification("One of our trades with [$otherCivName] has been cut short", NotificationIcon.Trade, otherCivName)
|
||||||
otherCiv().addNotification("One of our trades with [${civInfo.civName}] has been cut short", NotificationIcon.Trade, civInfo.civName)
|
otherCiv().addNotification("One of our trades with [${civInfo.civName}] has been cut short", NotificationIcon.Trade, civInfo.civName)
|
||||||
civInfo.updateDetailedCivResources()
|
civInfo.updateDetailedCivResources()
|
||||||
@ -378,6 +385,18 @@ class DiplomacyManager() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun remakePeaceTreaty(durationLeft: Int) {
|
||||||
|
val treaty = Trade()
|
||||||
|
treaty.ourOffers.add(
|
||||||
|
TradeOffer(Constants.peaceTreaty, TradeType.Treaty, duration = durationLeft)
|
||||||
|
)
|
||||||
|
treaty.theirOffers.add(
|
||||||
|
TradeOffer(Constants.peaceTreaty, TradeType.Treaty, duration = durationLeft)
|
||||||
|
)
|
||||||
|
trades.add(treaty)
|
||||||
|
otherCiv().getDiplomacyManager(civInfo).trades.add(treaty)
|
||||||
|
}
|
||||||
|
|
||||||
// for performance reasons we don't want to call this every time we want to see if a unit can move through a tile
|
// for performance reasons we don't want to call this every time we want to see if a unit can move through a tile
|
||||||
fun updateHasOpenBorders() {
|
fun updateHasOpenBorders() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user