From b28a247bd0490b80c7ce6487c86cbe8000048f1f Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 21 Mar 2020 21:27:11 +0200 Subject: [PATCH] Fixed "other civ doesn't get duration on timed trades" bug --- changelog.md | 2 ++ core/src/com/unciv/logic/trade/TradeOffer.kt | 17 ++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/changelog.md b/changelog.md index fc440a03..85e2eaa1 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,8 @@ By rh-github-2015: Unit purchasing limits - by EdinCitaku +Unit Action buttons stick to the left + Translation updates ## 3.6.9 diff --git a/core/src/com/unciv/logic/trade/TradeOffer.kt b/core/src/com/unciv/logic/trade/TradeOffer.kt index bc5265ff..60e35f06 100644 --- a/core/src/com/unciv/logic/trade/TradeOffer.kt +++ b/core/src/com/unciv/logic/trade/TradeOffer.kt @@ -5,16 +5,19 @@ import com.unciv.UncivGame import com.unciv.models.metadata.GameSpeed import com.unciv.models.translations.tr -data class TradeOffer(var name:String, var type: TradeType, var amount:Int=1) { +data class TradeOffer(var name:String, var type: TradeType, var amount:Int=1, var duration:Int=0) { - constructor() : this("", TradeType.Gold) // so that the json deserializer can work - var duration = when(type){ - TradeType.Gold, TradeType.Technology, TradeType.Introduction, TradeType.WarDeclaration, TradeType.City -> 0 /** 0 for offers that are immediate (e.g. gold transfer) */ - else -> when(UncivGame.Current.gameInfo.gameParameters.gameSpeed){ - GameSpeed.Quick -> if (name==Constants.peaceTreaty) 10 else 25 - else -> ((if (name==Constants.peaceTreaty) 10 else 30) * UncivGame.Current.gameInfo.gameParameters.gameSpeed.modifier).toInt() + init { + // Duration needs to be part of the variables defined at the top, so that it will be copied over with copy() + duration = when(type){ + TradeType.Gold, TradeType.Technology, TradeType.Introduction, TradeType.WarDeclaration, TradeType.City -> 0 /** 0 for offers that are immediate (e.g. gold transfer) */ + else -> when(UncivGame.Current.gameInfo.gameParameters.gameSpeed){ + GameSpeed.Quick -> if (name==Constants.peaceTreaty) 10 else 25 + else -> ((if (name==Constants.peaceTreaty) 10 else 30) * UncivGame.Current.gameInfo.gameParameters.gameSpeed.modifier).toInt() + } } } + constructor() : this("", TradeType.Gold) // so that the json deserializer can work fun equals(offer: TradeOffer): Boolean { return offer.name==name && offer.type==type