mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-08 23:08:35 +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:
@ -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 {
|
private fun isOldFormat(manager: BarbarianManager): Boolean {
|
||||||
val keys = manager.camps.keys as Set<Any>
|
val keys = manager.camps.keys as Set<Any>
|
||||||
val iterator = keys.iterator()
|
val iterator = keys.iterator()
|
||||||
|
@ -2,6 +2,7 @@ package com.unciv.logic
|
|||||||
|
|
||||||
import com.unciv.Constants
|
import com.unciv.Constants
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
|
import com.unciv.logic.BackwardCompatibility.convertFortify
|
||||||
import com.unciv.utils.debug
|
import com.unciv.utils.debug
|
||||||
import com.unciv.logic.BackwardCompatibility.guaranteeUnitPromotions
|
import com.unciv.logic.BackwardCompatibility.guaranteeUnitPromotions
|
||||||
import com.unciv.logic.BackwardCompatibility.migrateBarbarianCamps
|
import com.unciv.logic.BackwardCompatibility.migrateBarbarianCamps
|
||||||
@ -435,6 +436,8 @@ class GameInfo {
|
|||||||
for (civInfo in civilizations) civInfo.setTransients()
|
for (civInfo in civilizations) civInfo.setTransients()
|
||||||
for (civInfo in civilizations) civInfo.updateSightAndResources()
|
for (civInfo in civilizations) civInfo.updateSightAndResources()
|
||||||
|
|
||||||
|
convertFortify()
|
||||||
|
|
||||||
for (civInfo in civilizations) {
|
for (civInfo in civilizations) {
|
||||||
for (unit in civInfo.getCivUnits())
|
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
|
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 promotions = UnitPromotions()
|
||||||
var due: Boolean = true
|
var due: Boolean = true
|
||||||
var isTransported: Boolean = false
|
var isTransported: Boolean = false
|
||||||
|
var turnsFortified = 0
|
||||||
|
|
||||||
var abilityUsesLeft: HashMap<String, Int> = hashMapOf()
|
var abilityUsesLeft: HashMap<String, Int> = hashMapOf()
|
||||||
var maxAbilityUses: HashMap<String, Int> = hashMapOf()
|
var maxAbilityUses: HashMap<String, Int> = hashMapOf()
|
||||||
@ -234,6 +235,7 @@ class MapUnit {
|
|||||||
toReturn.health = health
|
toReturn.health = health
|
||||||
toReturn.action = action
|
toReturn.action = action
|
||||||
toReturn.attacksThisTurn = attacksThisTurn
|
toReturn.attacksThisTurn = attacksThisTurn
|
||||||
|
toReturn.turnsFortified = turnsFortified
|
||||||
toReturn.promotions = promotions.clone()
|
toReturn.promotions = promotions.clone()
|
||||||
toReturn.isTransported = isTransported
|
toReturn.isTransported = isTransported
|
||||||
toReturn.abilityUsesLeft.putAll(abilityUsesLeft)
|
toReturn.abilityUsesLeft.putAll(abilityUsesLeft)
|
||||||
@ -450,7 +452,7 @@ class MapUnit {
|
|||||||
|
|
||||||
fun getFortificationTurns(): Int {
|
fun getFortificationTurns(): Int {
|
||||||
if (!isFortified()) return 0
|
if (!isFortified()) return 0
|
||||||
return action!!.split(" ")[1].toInt()
|
return turnsFortified
|
||||||
}
|
}
|
||||||
|
|
||||||
// debug helper (please update comment if you see some "$unit" using this)
|
// debug helper (please update comment if you see some "$unit" using this)
|
||||||
@ -639,11 +641,11 @@ class MapUnit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun fortify() {
|
fun fortify() {
|
||||||
action = "Fortify 0"
|
action = "Fortify"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fortifyUntilHealed() {
|
fun fortifyUntilHealed() {
|
||||||
action = "Fortify 0 until healed"
|
action = "Fortify until healed"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fortifyIfCan() {
|
fun fortifyIfCan() {
|
||||||
@ -672,6 +674,7 @@ class MapUnit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun useMovementPoints(amount: Float) {
|
fun useMovementPoints(amount: Float) {
|
||||||
|
turnsFortified = 0
|
||||||
currentMovement -= amount
|
currentMovement -= amount
|
||||||
if (currentMovement < 0) currentMovement = 0f
|
if (currentMovement < 0) currentMovement = 0f
|
||||||
}
|
}
|
||||||
@ -842,15 +845,11 @@ class MapUnit {
|
|||||||
&& getTile().improvementInProgress != null
|
&& getTile().improvementInProgress != null
|
||||||
&& canBuildImprovement(getTile().getTileImprovementInProgress()!!)
|
&& canBuildImprovement(getTile().getTileImprovementInProgress()!!)
|
||||||
) workOnImprovement()
|
) workOnImprovement()
|
||||||
if (currentMovement == getMaxMovement().toFloat() && isFortified()) {
|
if (currentMovement == getMaxMovement().toFloat() && isFortified() && turnsFortified < 2) {
|
||||||
val currentTurnsFortified = getFortificationTurns()
|
turnsFortified++
|
||||||
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
|
if (currentMovement == getMaxMovement().toFloat() // didn't move this turn
|
||||||
|| hasUnique(UniqueType.HealsEvenAfterAction)
|
|| hasUnique(UniqueType.HealsEvenAfterAction)
|
||||||
|
Reference in New Issue
Block a user