From f98f4e8c9bee1fa82146dfa73d959130b203026b Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 13 Apr 2023 16:55:16 +0300 Subject: [PATCH] Retreat chance is savescum-safe - #9178 --- core/src/com/unciv/logic/battle/Battle.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index 8accaa025c..6eb7412d53 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -1097,7 +1097,9 @@ object Battle { val percentChance = baseWithdrawChance - max(0, (attackBaseUnit.movement-2)) * 20 - fromTile.neighbors.filterNot { it == attTile || it in attTile.neighbors }.count { canNotWithdrawTo(it) } * 20 // Get a random number in [0,100) : if the number <= percentChance, defender will withdraw from melee - if (Random().nextInt(100) > percentChance) return false + if (Random( // 'randomness' is consistent for turn and tile, to avoid save-scumming + (attacker.getCivInfo().gameInfo.turns * defender.getTile().hashCode()).toLong() + ).nextInt(100) > percentChance) return false val firstCandidateTiles = fromTile.neighbors.filterNot { it == attTile || it in attTile.neighbors } .filterNot { canNotWithdrawTo(it) } val secondCandidateTiles = fromTile.neighbors.filter { it in attTile.neighbors }