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 { init {
// Duration needs to be part of the variables defined in the primary constructor, // 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() // 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 val gameSpeed = UncivGame.Current.gameInfo.gameParameters.gameSpeed
duration = when { when {
type.isImmediate -> -1 // -1 for offers that are immediate (e.g. gold transfer)
name == Constants.peaceTreaty -> 10 name == Constants.peaceTreaty -> 10
gameSpeed == GameSpeed.Quick -> 25 gameSpeed == GameSpeed.Quick -> 25
else -> (30 * gameSpeed.modifier).toInt() else -> (30 * gameSpeed.modifier).toInt()
} }
} }
}
constructor() : this("", TradeType.Gold) // so that the json deserializer can work constructor() : this("", TradeType.Gold) // so that the json deserializer can work