mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-11 16:29:48 +07:00
Modding: units can transform without limit on destination unit
This commit is contained in:
@ -327,30 +327,32 @@ object UnitActions {
|
|||||||
val transformList = ArrayList<UnitAction>()
|
val transformList = ArrayList<UnitAction>()
|
||||||
for (unique in unit.baseUnit().getMatchingUniques(UniqueType.CanTransform,
|
for (unique in unit.baseUnit().getMatchingUniques(UniqueType.CanTransform,
|
||||||
StateForConditionals(unit = unit, civInfo = civInfo, tile = unitTile))) {
|
StateForConditionals(unit = unit, civInfo = civInfo, tile = unitTile))) {
|
||||||
val upgradedUnit = civInfo.getEquivalentUnit(unique.params[0])
|
val unitToTransformTo = civInfo.getEquivalentUnit(unique.params[0])
|
||||||
// don't show if haven't researched/is obsolete
|
|
||||||
if (!unit.upgrade.canUpgrade(unitToUpgradeTo = upgradedUnit)) continue
|
val stateForConditionals = StateForConditionals(unit.civ, unit = unit)
|
||||||
|
if (unitToTransformTo.getMatchingUniques(UniqueType.OnlyAvailableWhen).any { !it.conditionalsApply(stateForConditionals) })
|
||||||
|
continue
|
||||||
|
|
||||||
// Check _new_ resource requirements
|
// Check _new_ resource requirements
|
||||||
// Using Counter to aggregate is a bit exaggerated, but - respect the mad modder.
|
// Using Counter to aggregate is a bit exaggerated, but - respect the mad modder.
|
||||||
val resourceRequirementsDelta = Counter<String>()
|
val resourceRequirementsDelta = Counter<String>()
|
||||||
for ((resource, amount) in unit.baseUnit().getResourceRequirementsPerTurn())
|
for ((resource, amount) in unit.baseUnit().getResourceRequirementsPerTurn())
|
||||||
resourceRequirementsDelta.add(resource, -amount)
|
resourceRequirementsDelta.add(resource, -amount)
|
||||||
for ((resource, amount) in upgradedUnit.getResourceRequirementsPerTurn())
|
for ((resource, amount) in unitToTransformTo.getResourceRequirementsPerTurn())
|
||||||
resourceRequirementsDelta.add(resource, amount)
|
resourceRequirementsDelta.add(resource, amount)
|
||||||
val newResourceRequirementsString = resourceRequirementsDelta.entries
|
val newResourceRequirementsString = resourceRequirementsDelta.entries
|
||||||
.filter { it.value > 0 }
|
.filter { it.value > 0 }
|
||||||
.joinToString { "${it.value} {${it.key}}".tr() }
|
.joinToString { "${it.value} {${it.key}}".tr() }
|
||||||
|
|
||||||
val title = if (newResourceRequirementsString.isEmpty())
|
val title = if (newResourceRequirementsString.isEmpty())
|
||||||
"Transform to [${upgradedUnit.name}]"
|
"Transform to [${unitToTransformTo.name}]"
|
||||||
else "Transform to [${upgradedUnit.name}]\n([$newResourceRequirementsString])"
|
else "Transform to [${unitToTransformTo.name}]\n([$newResourceRequirementsString])"
|
||||||
|
|
||||||
transformList.add(UnitAction(UnitActionType.Transform,
|
transformList.add(UnitAction(UnitActionType.Transform,
|
||||||
title = title,
|
title = title,
|
||||||
action = {
|
action = {
|
||||||
unit.destroy()
|
unit.destroy()
|
||||||
val newUnit = civInfo.units.placeUnitNearTile(unitTile.position, upgradedUnit.name)
|
val newUnit = civInfo.units.placeUnitNearTile(unitTile.position, unitToTransformTo.name)
|
||||||
|
|
||||||
/** We were UNABLE to place the new unit, which means that the unit failed to upgrade!
|
/** 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.
|
* The only known cause of this currently is "land units upgrading to water units" which fail to be placed.
|
||||||
@ -363,9 +365,7 @@ object UnitActions {
|
|||||||
newUnit.currentMovement = 0f
|
newUnit.currentMovement = 0f
|
||||||
}
|
}
|
||||||
}.takeIf {
|
}.takeIf {
|
||||||
unit.currentMovement > 0
|
unit.currentMovement > 0 && !unit.isEmbarked()
|
||||||
&& !unit.isEmbarked()
|
|
||||||
&& unit.upgrade.canUpgrade(unitToUpgradeTo = upgradedUnit)
|
|
||||||
}
|
}
|
||||||
) )
|
) )
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user