mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 14:24:43 -04:00
Tested and reworked the 'unit upgrades for free' unique till it worked (#6555)
This commit is contained in:
parent
d3b17117da
commit
0230575473
@ -513,8 +513,9 @@ class MapUnit {
|
|||||||
if (name == unitToUpgradeTo.name) return false
|
if (name == unitToUpgradeTo.name) return false
|
||||||
val rejectionReasons = unitToUpgradeTo.getRejectionReasons(civInfo)
|
val rejectionReasons = unitToUpgradeTo.getRejectionReasons(civInfo)
|
||||||
if (rejectionReasons.isEmpty()) return true
|
if (rejectionReasons.isEmpty()) return true
|
||||||
|
if (ignoreRequired && rejectionReasons.filterTechPolicyEraWonderRequirements().isEmpty()) return true
|
||||||
|
|
||||||
if (rejectionReasons.size == 1 && rejectionReasons.contains(RejectionReason.ConsumesResources)) {
|
if (rejectionReasons.contains(RejectionReason.ConsumesResources)) {
|
||||||
// We need to remove the unit from the civ for this check,
|
// We need to remove the unit from the civ for this check,
|
||||||
// because if the unit requires, say, horses, and so does its upgrade,
|
// because if the unit requires, say, horses, and so does its upgrade,
|
||||||
// and the civ currently has 0 horses, we need to see if the upgrade will be buildable
|
// and the civ currently has 0 horses, we need to see if the upgrade will be buildable
|
||||||
|
@ -494,7 +494,7 @@ object UniqueTriggerActivation {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
OneTimeUnitUpgrade -> {
|
OneTimeUnitUpgrade -> {
|
||||||
val upgradeAction = UnitActions.getUpgradeAction(unit, true)
|
val upgradeAction = UnitActions.getFreeUpgradeAction(unit)
|
||||||
?: return false
|
?: return false
|
||||||
upgradeAction.action!!()
|
upgradeAction.action!!()
|
||||||
if (notification != null)
|
if (notification != null)
|
||||||
|
@ -311,14 +311,14 @@ object UnitActions {
|
|||||||
if (upgradeAction != null) actionList += upgradeAction
|
if (upgradeAction != null) actionList += upgradeAction
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUpgradeAction(unit: MapUnit, isFree: Boolean = false): UnitAction? {
|
fun getUpgradeAction(unit: MapUnit): UnitAction? {
|
||||||
val tile = unit.currentTile
|
val tile = unit.currentTile
|
||||||
if (unit.baseUnit().upgradesTo == null || !unit.canUpgrade()) return null
|
if (unit.baseUnit().upgradesTo == null) return null
|
||||||
if (tile.getOwner() != unit.civInfo && !isFree) return null
|
if (!unit.canUpgrade()) return null
|
||||||
val goldCostOfUpgrade =
|
if (tile.getOwner() != unit.civInfo) return null
|
||||||
if (isFree) 0
|
|
||||||
else unit.getCostOfUpgrade()
|
|
||||||
val upgradedUnit = unit.getUnitToUpgradeTo()
|
val upgradedUnit = unit.getUnitToUpgradeTo()
|
||||||
|
val goldCostOfUpgrade = unit.getCostOfUpgrade()
|
||||||
|
|
||||||
return UnitAction(UnitActionType.Upgrade,
|
return UnitAction(UnitActionType.Upgrade,
|
||||||
title = "Upgrade to [${upgradedUnit.name}] ([$goldCostOfUpgrade] gold)",
|
title = "Upgrade to [${upgradedUnit.name}] ([$goldCostOfUpgrade] gold)",
|
||||||
@ -339,13 +339,36 @@ object UnitActions {
|
|||||||
newUnit.currentMovement = 0f
|
newUnit.currentMovement = 0f
|
||||||
}
|
}
|
||||||
}.takeIf {
|
}.takeIf {
|
||||||
isFree ||
|
|
||||||
(
|
|
||||||
unit.civInfo.gold >= goldCostOfUpgrade
|
unit.civInfo.gold >= goldCostOfUpgrade
|
||||||
&& unit.currentMovement > 0
|
&& unit.currentMovement > 0
|
||||||
&& !unit.isEmbarked()
|
&& !unit.isEmbarked()
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getFreeUpgradeAction(unit: MapUnit): UnitAction? {
|
||||||
|
if (unit.baseUnit().upgradesTo == null) return null
|
||||||
|
val upgradedUnit = unit.civInfo.getEquivalentUnit(unit.baseUnit().upgradesTo!!)
|
||||||
|
if (!unit.canUpgrade(upgradedUnit, true)) return null
|
||||||
|
|
||||||
|
return UnitAction(UnitActionType.Upgrade,
|
||||||
|
title = "Upgrade to [${upgradedUnit.name}] (FREE)",
|
||||||
|
action = {
|
||||||
|
val unitTile = unit.getTile()
|
||||||
|
unit.destroy()
|
||||||
|
val newUnit = unit.civInfo.placeUnitNearTile(unitTile.position, upgradedUnit.name)
|
||||||
|
|
||||||
|
/** 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 readdedUnit = unit.civInfo.placeUnitNearTile(unitTile.position, unit.name)
|
||||||
|
unit.copyStatisticsTo(readdedUnit!!)
|
||||||
|
} else { // Managed to upgrade
|
||||||
|
unit.copyStatisticsTo(newUnit)
|
||||||
|
newUnit.currentMovement = 0f
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,9 +380,8 @@ object UnitActions {
|
|||||||
else -> return null
|
else -> return null
|
||||||
}
|
}
|
||||||
val upgradedUnit =
|
val upgradedUnit =
|
||||||
unit.civInfo.getEquivalentUnit(
|
unit.civInfo.getEquivalentUnit(unit.civInfo.gameInfo.ruleSet.units[upgradedUnitName]!!)
|
||||||
unit.civInfo.gameInfo.ruleSet.units[upgradedUnitName]!!
|
|
||||||
)
|
|
||||||
if (!unit.canUpgrade(upgradedUnit,true)) return null
|
if (!unit.canUpgrade(upgradedUnit,true)) return null
|
||||||
|
|
||||||
return UnitAction(UnitActionType.Upgrade,
|
return UnitAction(UnitActionType.Upgrade,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user