mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-24 13:41:08 +07:00
Maintain Fortify bonus after Fortify until Healed (#6991)
* Maintain Fortify bonus after Fortify until Healed * add in backward compatibility * attempt * Add in proper backwards compatibility * Convert Fortify in BackwardCompatibility.kt instead * Remove debug code * Now with Regex * remove unnecessary import
This commit is contained in:
parent
e4ab1eabc7
commit
38b6770e84
@ -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<Any>
|
||||
val iterator = keys.iterator()
|
||||
|
@ -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
|
||||
|
@ -174,6 +174,7 @@ class MapUnit {
|
||||
var promotions = UnitPromotions()
|
||||
var due: Boolean = true
|
||||
var isTransported: Boolean = false
|
||||
var turnsFortified = 0
|
||||
|
||||
var abilityUsesLeft: HashMap<String, Int> = hashMapOf()
|
||||
var maxAbilityUses: HashMap<String, Int> = 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)
|
||||
|
Loading…
Reference in New Issue
Block a user