diff --git a/core/src/com/unciv/logic/BackwardCompatibility.kt b/core/src/com/unciv/logic/BackwardCompatibility.kt index cde9ae266d..5631341293 100644 --- a/core/src/com/unciv/logic/BackwardCompatibility.kt +++ b/core/src/com/unciv/logic/BackwardCompatibility.kt @@ -15,7 +15,7 @@ import com.unciv.models.ruleset.Ruleset /** * Container for all temporarily used code managing transitions from deprecated elements to their replacements. - * + * * Please place ***all*** such code here and call it _only_ from [GameInfo.setTransients]. * Functions are allowed to remain once no longer used if you think they might serve as template for * similar usecases in the future. Please comment sufficiently :) @@ -43,9 +43,9 @@ object BackwardCompatibility { for (city in civilizations.asSequence().flatMap { it.cities.asSequence() }) { changeBuildingNameIfNotInRuleset(ruleSet, city.cityConstructions, "Hanse", "Bank") - + for (building in city.cityConstructions.builtBuildings.toHashSet()) { - + if (!ruleSet.buildings.containsKey(building)) city.cityConstructions.builtBuildings.remove(building) } @@ -193,6 +193,20 @@ object BackwardCompatibility { } } + /** Convert from Fortify X to Fortify and save off X */ + fun GameInfo.convertFortify() { + val reg = Regex("""^Fortify\s+(\d+)([\w\s]*)""") + for (civInfo in civilizations) { + for (unit in civInfo.getCivUnits()) { + if (unit.action != null && reg.matches(unit.action!!)) { + val (turns, heal) = reg.find(unit.action!!)!!.destructured + unit.turnsFortified = turns.toInt() + unit.action = "Fortify$heal" + } + } + } + } + private fun isOldFormat(manager: BarbarianManager): Boolean { val keys = manager.camps.keys as Set val iterator = keys.iterator() diff --git a/core/src/com/unciv/logic/GameInfo.kt b/core/src/com/unciv/logic/GameInfo.kt index cd437eae74..3cf107771f 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -2,6 +2,7 @@ package com.unciv.logic import com.unciv.Constants import com.unciv.UncivGame +import com.unciv.logic.BackwardCompatibility.convertFortify import com.unciv.utils.debug import com.unciv.logic.BackwardCompatibility.guaranteeUnitPromotions import com.unciv.logic.BackwardCompatibility.migrateBarbarianCamps @@ -435,6 +436,8 @@ class GameInfo { for (civInfo in civilizations) civInfo.setTransients() for (civInfo in civilizations) civInfo.updateSightAndResources() + convertFortify() + for (civInfo in civilizations) { for (unit in civInfo.getCivUnits()) unit.updateVisibleTiles(false) // this needs to be done after all the units are assigned to their civs and all other transients are set diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 6190da6282..ffac2e530b 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -174,6 +174,7 @@ class MapUnit { var promotions = UnitPromotions() var due: Boolean = true var isTransported: Boolean = false + var turnsFortified = 0 var abilityUsesLeft: HashMap = hashMapOf() var maxAbilityUses: HashMap = hashMapOf() @@ -234,6 +235,7 @@ class MapUnit { toReturn.health = health toReturn.action = action toReturn.attacksThisTurn = attacksThisTurn + toReturn.turnsFortified = turnsFortified toReturn.promotions = promotions.clone() toReturn.isTransported = isTransported toReturn.abilityUsesLeft.putAll(abilityUsesLeft) @@ -450,7 +452,7 @@ class MapUnit { fun getFortificationTurns(): Int { if (!isFortified()) return 0 - return action!!.split(" ")[1].toInt() + return turnsFortified } // debug helper (please update comment if you see some "$unit" using this) @@ -639,11 +641,11 @@ class MapUnit { } fun fortify() { - action = "Fortify 0" + action = "Fortify" } fun fortifyUntilHealed() { - action = "Fortify 0 until healed" + action = "Fortify until healed" } fun fortifyIfCan() { @@ -672,6 +674,7 @@ class MapUnit { } fun useMovementPoints(amount: Float) { + turnsFortified = 0 currentMovement -= amount if (currentMovement < 0) currentMovement = 0f } @@ -842,15 +845,11 @@ class MapUnit { && getTile().improvementInProgress != null && canBuildImprovement(getTile().getTileImprovementInProgress()!!) ) workOnImprovement() - if (currentMovement == getMaxMovement().toFloat() && isFortified()) { - val currentTurnsFortified = getFortificationTurns() - if (currentTurnsFortified < 2) - action = action!!.replace( - currentTurnsFortified.toString(), - (currentTurnsFortified + 1).toString(), - true - ) + if (currentMovement == getMaxMovement().toFloat() && isFortified() && turnsFortified < 2) { + turnsFortified++ } + if (!isFortified()) + turnsFortified = 0 if (currentMovement == getMaxMovement().toFloat() // didn't move this turn || hasUnique(UniqueType.HealsEvenAfterAction)