Comments (6)
Same with sleep I noticed recently. Upgrade should "wake up" any unit, and likely even clear all orders except automation?? I remember - was that earlier Unciv of Civ4? - that even if the new unit can fortify you had to re-fortify. Even promoting IMHO should wake up and thus force you to have 2 turns with reduced fortification bonus?
from unciv.
Not sure if units upgrading should cause wakeup in any case. Promoting - definitely no.
from unciv.
Not sure if units upgrading should cause wakeup in any case
Pretty sure it did in the original Civs I played - up to IV. Also, easiest solution for upgrade changing the ability to fortify (how tempting that word to introduce a typo is).
from unciv.
This ddg hit pretty much corroborates Civ5 does wake up too:
https://forums.civfanatics.com/threads/civ-5-unit-upgrades.354720/
from unciv.
Since that link I cited pretty much disparaged the original's wakeup...
patch???
Index: core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsUpgrade.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsUpgrade.kt b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsUpgrade.kt
--- a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsUpgrade.kt (revision 52eae2a3f9f443a95c9fffbaa65ea5909bb6b266)
+++ b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsUpgrade.kt (date 1708694455534)
@@ -60,20 +60,7 @@
goldCostOfUpgrade = goldCostOfUpgrade,
newResourceRequirements = resourceRequirementsDelta,
action = {
- unit.destroy(destroyTransportedUnit = false)
- val newUnit = civInfo.units.placeUnitNearTile(unitTile.position, upgradedUnit)
-
- /** We were UNABLE to place the new unit, which means that the unit failed to upgrade!
- * The only known cause of this currently is "land units upgrading to water units" which fail to be placed.
- */
- if (newUnit == null) {
- val resurrectedUnit = civInfo.units.placeUnitNearTile(unitTile.position, unit.baseUnit)!!
- unit.copyStatisticsTo(resurrectedUnit)
- } else { // Managed to upgrade
- if (!isFree) civInfo.addGold(-goldCostOfUpgrade)
- unit.copyStatisticsTo(newUnit)
- newUnit.currentMovement = 0f
- }
+ unit.upgrade.performUpgrade(upgradedUnit, isFree, goldCostOfUpgrade)
}.takeIf {
isFree || (
unit.civ.gold >= goldCostOfUpgrade
Index: core/src/com/unciv/logic/map/mapunit/UnitUpgradeManager.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/core/src/com/unciv/logic/map/mapunit/UnitUpgradeManager.kt b/core/src/com/unciv/logic/map/mapunit/UnitUpgradeManager.kt
--- a/core/src/com/unciv/logic/map/mapunit/UnitUpgradeManager.kt (revision 52eae2a3f9f443a95c9fffbaa65ea5909bb6b266)
+++ b/core/src/com/unciv/logic/map/mapunit/UnitUpgradeManager.kt (date 1708694455552)
@@ -1,6 +1,5 @@
package com.unciv.logic.map.mapunit
-import com.unciv.logic.UncivShowableException
import com.unciv.models.ruleset.RejectionReasonType
import com.unciv.models.ruleset.unique.StateForConditionals
import com.unciv.models.ruleset.unique.UniqueType
@@ -26,7 +25,7 @@
val rejectionReasons = unitToUpgradeTo.getRejectionReasons(unit.civ, additionalResources = unit.getResourceRequirementsPerTurn())
- var relevantRejectionReasons = rejectionReasons.filterNot {
+ var relevantRejectionReasons = rejectionReasons.filterNot {
it.isConstructionRejection() || it.type == RejectionReasonType.Obsoleted
}
if (ignoreRequirements)
@@ -68,9 +67,31 @@
cost = (cost * civModifier).pow(constants.exponent)
cost *= unit.civ.gameInfo.speed.modifier
goldCostOfUpgrade += (cost / constants.roundTo).toInt() * constants.roundTo
-
+
return goldCostOfUpgrade
}
+ fun performUpgrade(upgradedUnit: BaseUnit, isFree: Boolean, goldCostOfUpgrade: Int? = null) {
+ unit.destroy(destroyTransportedUnit = false)
+ val civ = unit.civ
+ val position = unit.currentTile.position
+ val newUnit = civ.units.placeUnitNearTile(position, upgradedUnit)
+ /** We were UNABLE to place the new unit, which means that the unit failed to upgrade!
+ * The only known cause of this currently is "land units upgrading to water units" which fail to be placed.
+ */
+ if (newUnit == null) {
+ val resurrectedUnit = civ.units.placeUnitNearTile(position, unit.baseUnit)!!
+ unit.copyStatisticsTo(resurrectedUnit)
+ return
+ }
+
+ // Managed to upgrade
+ if (!isFree) civ.addGold(-(goldCostOfUpgrade ?: getCostOfUpgrade(upgradedUnit)))
+ unit.copyStatisticsTo(newUnit)
+ newUnit.currentMovement = 0f
+ // wake up if lost ability to fortify
+ if (newUnit.isFortified() && !newUnit.canFortify(ignoreAlreadyFortified = true))
+ newUnit.action = null
+ }
}
Index: core/src/com/unciv/logic/map/mapunit/MapUnit.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt
--- a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt (revision 52eae2a3f9f443a95c9fffbaa65ea5909bb6b266)
+++ b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt (date 1708694455543)
@@ -377,14 +377,15 @@
}
- fun canFortify(): Boolean {
- if (baseUnit.isWaterUnit()) return false
- if (isCivilian()) return false
- if (baseUnit.movesLikeAirUnits()) return false
- if (isEmbarked()) return false
- if (hasUnique(UniqueType.NoDefensiveTerrainBonus)) return false
- if (isFortified()) return false
- return true
+ fun canFortify(ignoreAlreadyFortified: Boolean = false) = when {
+ baseUnit.isWaterUnit() -> false
+ isCivilian() -> false
+ baseUnit.movesLikeAirUnits() -> false
+ isEmbarked() -> false
+ hasUnique(UniqueType.NoDefensiveTerrainBonus) -> false
+ ignoreAlreadyFortified -> true
+ isFortified() -> false
+ else -> true
}
private fun adjacentHealingBonus(): Int {
Wrong save up there - we need the state before the upgrade to test!
That larger patch boils down to if (newUnit.isFortified() && !newUnit.canFortify(ignoreAlreadyFortified = true)) wake up!
- meaning chooses the least intrusive of the above discussion. The rest is "WTF is there an UnitUpgradeManager that does not actually manage an upgrade?", and one "redundant if" warning workaround. There's four more such warnings in MapUnit, all could copy that approach...
from unciv.
OK, that patch tests out fine. Sleeping artillery stays asleep on upgrade, fortified anti-tank-thingys wake up when helicopterized, fortified musketmen re-fortify from zero "automatically".
But - where did that upgrade several steps all the way to the most modern one go? Must have missed or forgotten some aspects of those multi-upgrade-to unique PR's. Is a rule change unless we re-offer the one-step in the right-click menu... Anyone can provide a multi-upgrade-path mod and save to test that on?
from unciv.
Related Issues (20)
- Escorted movement crash HOT 2
- City-state condemnation mechanics
- RFC: Fly-by observations (and mini-bugs) concerning Espionage HOT 8
- Culture order error in declear war notification. HOT 1
- Trigger "Enemy City" tutorial when I disbanded all my units. HOT 2
- Unit automation uses defunct `UnitActionType.StartGoldenAge` HOT 2
- Unable to start on custom map HOT 3
- AI players ignore the One City Challenge HOT 1
- Mods broken since 4.11.12 HOT 5
- Atlas and game.png file generation should make exceptions accessible to a Modder HOT 9
- Feature Request: Implement the remaining countables HOT 1
- Notifications of Science building in puppet cities HOT 4
- Feature Request: Support for Civ4-like non-permanent civics HOT 12
- Feature Request: Add buildingFilter values support for cityFilter HOT 1
- Rename Kawanai -> Kānāwai HOT 2
- Feature request: Enable OR when specifying multiple Tech Requirements HOT 4
- Suppress online cheating HOT 5
- Suppress online cheating HOT 1
- "when below [amount] [resource]" causing crash with city-level resources HOT 6
- 'Unavailable" is not valid for Tech
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unciv.