Fix incorrect relationship level comparison (#9156)

This commit is contained in:
SomeTroglodyte
2023-04-11 10:04:31 +02:00
committed by GitHub
parent 6efb4926af
commit 46a9a7251e

View File

@ -18,6 +18,7 @@ import com.unciv.ui.components.extensions.toPercent
import kotlin.math.ceil import kotlin.math.ceil
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
import kotlin.math.sign
enum class RelationshipLevel(val color: Color) { enum class RelationshipLevel(val color: Color) {
// War is tested separately for the Diplomacy Screen. Colored RED. // War is tested separately for the Diplomacy Screen. Colored RED.
@ -185,7 +186,7 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
*/ */
private fun compareRelationshipLevel(level: RelationshipLevel, comparesAs: Int): Boolean { private fun compareRelationshipLevel(level: RelationshipLevel, comparesAs: Int): Boolean {
if (!civInfo.isCityState()) if (!civInfo.isCityState())
return relationshipLevel().compareTo(level) == comparesAs return relationshipLevel().compareTo(level).sign == comparesAs
return when(level) { return when(level) {
RelationshipLevel.Afraid -> when { RelationshipLevel.Afraid -> when {
comparesAs < 0 -> getInfluence() < 0 comparesAs < 0 -> getInfluence() < 0
@ -199,7 +200,9 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
} }
else -> else ->
// Outside the potentially expensive questions, do it the easy way // Outside the potentially expensive questions, do it the easy way
relationshipLevel().compareTo(level) == comparesAs // Except - Enum.compareTo does not behave quite like other compareTo's
// or like kotlinlang.org says, thus the `sign`
relationshipLevel().compareTo(level).sign == comparesAs
} }
} }
/** @see compareRelationshipLevel */ /** @see compareRelationshipLevel */