Fix uninitialized lateinit access in TradeOffer (#4159)

This commit is contained in:
SomeTroglodyte 2021-06-16 06:33:37 +02:00 committed by GitHub
parent d0227a2306
commit 625c4c9139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,14 +12,19 @@ data class TradeOffer(val name:String, val type:TradeType, var amount:Int = 1, v
init {
// Duration needs to be part of the variables defined in the primary constructor,
// so that it will be copied over with the automatically generated copy()
duration =
if (type.isImmediate) -1 // -1 for offers that are immediate (e.g. gold transfer)
else {
// Do *not* access UncivGame.Current.gameInfo in the default constructor!
val gameSpeed = UncivGame.Current.gameInfo.gameParameters.gameSpeed
duration = when {
type.isImmediate -> -1 // -1 for offers that are immediate (e.g. gold transfer)
when {
name == Constants.peaceTreaty -> 10
gameSpeed == GameSpeed.Quick -> 25
else -> (30 * gameSpeed.modifier).toInt()
}
}
}
constructor() : this("", TradeType.Gold) // so that the json deserializer can work