New unit triggers to gain/lose movement points

This commit is contained in:
yairm210 2024-07-25 00:20:25 +03:00
parent 7f6eaacf3f
commit 5e10698abc
3 changed files with 17 additions and 9 deletions

View File

@ -55,6 +55,7 @@ class MapUnit : IsPartOfGameInfoSerialization {
*/
var instanceName: String? = null
/** Should not be changed directly - instead use [useMovementPoints] */
var currentMovement: Float = 0f
var health: Int = 100
var id: Int = Constants.NO_ID
@ -701,10 +702,15 @@ class MapUnit : IsPartOfGameInfoSerialization {
}
}
/** Can accept a negative number to gain movement points */
fun useMovementPoints(amount: Float) {
turnsFortified = 0
currentMovement -= amount
if (currentMovement < 0) currentMovement = 0f
if (amount < 0) {
val maxMovement = getMaxMovement().toFloat()
if (currentMovement > maxMovement) currentMovement = maxMovement
}
}
fun fortify() {

View File

@ -971,7 +971,6 @@ object UniqueTriggerActivation {
}
UniqueType.OneTimeUnitGainXP -> {
if (unit == null) return null
if (!unit.baseUnit.isMilitary) return null
return {
unit.promotions.XP += unique.params[0].toInt()
if (notification != null)
@ -979,20 +978,21 @@ object UniqueTriggerActivation {
true
}
}
UniqueType.OneTimeUnitUpgrade -> {
UniqueType.OneTimeUnitGainMovement, UniqueType.OneTimeUnitLoseMovement -> {
if (unit == null) return null
val upgradeAction = UnitActionsUpgrade.getFreeUpgradeAction(unit)
if (upgradeAction.none()) return null
return {
(upgradeAction.minBy { (it as UpgradeUnitAction).unitToUpgradeTo.cost }).action!!()
if (notification != null)
unit.civ.addNotification(notification, MapUnitAction(unit), NotificationCategory.Units)
val movementToUse =
if (unique.type == UniqueType.OneTimeUnitLoseMovement) unique.params[0].toFloat()
else -unique.params[0].toFloat()
unit.useMovementPoints(movementToUse)
true
}
}
UniqueType.OneTimeUnitSpecialUpgrade -> {
UniqueType.OneTimeUnitUpgrade, UniqueType.OneTimeUnitSpecialUpgrade -> {
if (unit == null) return null
val upgradeAction = UnitActionsUpgrade.getAncientRuinsUpgradeAction(unit)
val upgradeAction =
if (unique.type == UniqueType.OneTimeUnitSpecialUpgrade) UnitActionsUpgrade.getAncientRuinsUpgradeAction(unit)
else UnitActionsUpgrade.getFreeUpgradeAction(unit)
if (upgradeAction.none()) return null
return {
(upgradeAction.minBy { (it as UpgradeUnitAction).unitToUpgradeTo.cost }).action!!()

View File

@ -836,6 +836,8 @@ enum class UniqueType(
OneTimeUnitSpecialUpgrade("This Unit upgrades for free including special upgrades", UniqueTarget.UnitTriggerable),
OneTimeUnitGainPromotion("This Unit gains the [promotion] promotion", UniqueTarget.UnitTriggerable), // Not used in Vanilla
OneTimeUnitRemovePromotion("This Unit loses the [promotion] promotion", UniqueTarget.UnitTriggerable),
OneTimeUnitGainMovement("This Unit gains [amount] movement", UniqueTarget.UnitTriggerable),
OneTimeUnitLoseMovement("This Unit loses [amount] movement", UniqueTarget.UnitTriggerable),
SkipPromotion("Doing so will consume this opportunity to choose a Promotion", UniqueTarget.Promotion),
FreePromotion("This Promotion is free", UniqueTarget.Promotion),