mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-01 10:25:57 +07:00
Fix uninitialized lateinit access in TradeOffer (#4159)
This commit is contained in:
parent
d0227a2306
commit
625c4c9139
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user