Fixed sqrt of negative number (#5193)

This commit is contained in:
Xander Lenstra 2021-09-12 18:07:33 +02:00 committed by GitHub
parent 70c3b4bd65
commit 03a7288656
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,6 +29,7 @@ import com.unciv.ui.victoryscreen.RankingType
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.math.max
import kotlin.math.min
import kotlin.math.roundToInt
import kotlin.math.sqrt
@ -524,9 +525,8 @@ class CivilizationInfo {
else
unit.getForceEvaluation()
}
val goldBonus = sqrt(gold.toFloat()).toPercent() // 2f if gold == 10000
val goldBonus = sqrt(max(0f, gold.toFloat())).toPercent() // 2f if gold == 10000
sum = (sum * min(goldBonus, 2f)).toInt() // 2f is max bonus
return sum
}