Resolved #2789 - losing a resource no longer cancells all trades with that resource, only as many as is necessary to reach equilibrium

This commit is contained in:
Yair Morgenstern 2020-07-02 19:43:01 +03:00
parent 20772a5b6d
commit e1aaa88e3d
2 changed files with 15 additions and 8 deletions

View File

@ -124,6 +124,8 @@ class UncivGame(parameters: UncivGameParameters) : Game() {
fun loadGame(gameInfo: GameInfo) {
this.gameInfo = gameInfo
ImageGetter.ruleset = gameInfo.ruleSet
Gdx.input.inputProcessor = null // Since we will set the world screen when we're ready,
// This is to avoid ANRs when loading.
ImageGetter.refreshAtlas()
worldScreen = WorldScreen(gameInfo.getPlayerToViewAs())
setWorldScreen()

View File

@ -237,19 +237,24 @@ class DiplomacyManager() {
//endregion
//region state-changing functions
fun removeUntenebleTrades(){
val negativeCivResources = civInfo.getCivResources()
.filter { it.amount<0 }.map { it.resource.name }
fun removeUntenebleTrades() {
for (trade in trades.toList()) {
// 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)
val negativeCivResources = civInfo.getCivResources()
.filter { it.amount < 0 }.map { it.resource.name }
for(trade in trades.toList()) {
for (offer in trade.ourOffers) {
if (offer.type in listOf(TradeType.Luxury_Resource, TradeType.Strategic_Resource)
&& offer.name in negativeCivResources){
&& offer.name in negativeCivResources) {
trades.remove(trade)
val otherCivTrades = otherCiv().getDiplomacyManager(civInfo).trades
otherCivTrades.removeAll{ it.equals(trade.reverse()) }
civInfo.addNotification("One of our trades with [$otherCivName] has been cut short",null, Color.GOLD)
otherCiv().addNotification("One of our trades with [${civInfo.civName}] has been cut short",null, Color.GOLD)
otherCivTrades.removeAll { it.equals(trade.reverse()) }
civInfo.addNotification("One of our trades with [$otherCivName] has been cut short", null, Color.GOLD)
otherCiv().addNotification("One of our trades with [${civInfo.civName}] has been cut short", null, Color.GOLD)
civInfo.updateDetailedCivResources()
}
}
}