diff --git a/core/src/com/unciv/logic/BackwardCompatibility.kt b/core/src/com/unciv/logic/BackwardCompatibility.kt index 5631341293..cde9ae266d 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,20 +193,6 @@ 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 3cf107771f..cd437eae74 100644 --- a/core/src/com/unciv/logic/GameInfo.kt +++ b/core/src/com/unciv/logic/GameInfo.kt @@ -2,7 +2,6 @@ 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 @@ -436,8 +435,6 @@ 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 ffac2e530b..6190da6282 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -174,7 +174,6 @@ class MapUnit { var promotions = UnitPromotions() var due: Boolean = true var isTransported: Boolean = false - var turnsFortified = 0 var abilityUsesLeft: HashMap = hashMapOf() var maxAbilityUses: HashMap = hashMapOf() @@ -235,7 +234,6 @@ 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) @@ -452,7 +450,7 @@ class MapUnit { fun getFortificationTurns(): Int { if (!isFortified()) return 0 - return turnsFortified + return action!!.split(" ")[1].toInt() } // debug helper (please update comment if you see some "$unit" using this) @@ -641,11 +639,11 @@ class MapUnit { } fun fortify() { - action = "Fortify" + action = "Fortify 0" } fun fortifyUntilHealed() { - action = "Fortify until healed" + action = "Fortify 0 until healed" } fun fortifyIfCan() { @@ -674,7 +672,6 @@ class MapUnit { } fun useMovementPoints(amount: Float) { - turnsFortified = 0 currentMovement -= amount if (currentMovement < 0) currentMovement = 0f } @@ -845,11 +842,15 @@ class MapUnit { && getTile().improvementInProgress != null && canBuildImprovement(getTile().getTileImprovementInProgress()!!) ) workOnImprovement() - if (currentMovement == getMaxMovement().toFloat() && isFortified() && turnsFortified < 2) { - turnsFortified++ + if (currentMovement == getMaxMovement().toFloat() && isFortified()) { + val currentTurnsFortified = getFortificationTurns() + if (currentTurnsFortified < 2) + action = action!!.replace( + currentTurnsFortified.toString(), + (currentTurnsFortified + 1).toString(), + true + ) } - if (!isFortified()) - turnsFortified = 0 if (currentMovement == getMaxMovement().toFloat() // didn't move this turn || hasUnique(UniqueType.HealsEvenAfterAction)