mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-15 10:18:26 +07:00
Fix incorrect relationship level comparison (#9156)
This commit is contained in:
@ -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 */
|
||||||
|
Reference in New Issue
Block a user