From 6e95a07572ed263bc5ba4cd879a670b37f6be355 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 14 Jan 2022 10:43:13 +0200 Subject: [PATCH] More unit unique typing (#5952) * There are so many of these my gosh * Fixed, good thing we have tests :) * Fixed --- android/assets/jsons/Civ V - Gods & Kings/Nations.json | 2 +- android/assets/jsons/Civ V - Vanilla/Nations.json | 2 +- core/src/com/unciv/logic/automation/UnitAutomation.kt | 2 +- core/src/com/unciv/logic/battle/Battle.kt | 2 +- core/src/com/unciv/logic/map/MapUnit.kt | 2 +- core/src/com/unciv/models/ruleset/unique/UniqueType.kt | 6 ++++++ core/src/com/unciv/models/ruleset/unit/BaseUnit.kt | 2 +- core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt | 7 ++++--- 8 files changed, 16 insertions(+), 9 deletions(-) diff --git a/android/assets/jsons/Civ V - Gods & Kings/Nations.json b/android/assets/jsons/Civ V - Gods & Kings/Nations.json index 3c8a7bf226..2985dd9948 100644 --- a/android/assets/jsons/Civ V - Gods & Kings/Nations.json +++ b/android/assets/jsons/Civ V - Gods & Kings/Nations.json @@ -689,7 +689,7 @@ "favoredReligion": "Christianity", "uniqueName": "Viking Fury", "uniques": ["[+1] Movement ", "Units pay only 1 movement point to disembark", - "Melee units pay no movement cost to pillage"], + "No movement cost to pillage "], "cities": ["Copenhagen","Aarhus","Kaupang","Ribe","Viborg","Tunsberg","Roskilde","Hedeby","Oslo","Jelling","Truso", "Bergen","Faeroerne","Reykjavik","Trondheim","Godthab","Helluland","Lillehammer","Markland","Elsinore", "Sarpsborg","Odense","Aalborg","Stavanger","Vorbasse","Schleswig","Kristiansand","Halogaland","Randers", diff --git a/android/assets/jsons/Civ V - Vanilla/Nations.json b/android/assets/jsons/Civ V - Vanilla/Nations.json index 9660905e96..3eb3a02de5 100644 --- a/android/assets/jsons/Civ V - Vanilla/Nations.json +++ b/android/assets/jsons/Civ V - Vanilla/Nations.json @@ -662,7 +662,7 @@ "innerColor": [255,255,102], "uniqueName": "Viking Fury", "uniques": ["[+1] Movement ", "Units pay only 1 movement point to disembark", - "Melee units pay no movement cost to pillage"], + "No movement cost to pillage "], "cities": ["Copenhagen","Aarhus","Kaupang","Ribe","Viborg","Tunsberg","Roskilde","Hedeby","Oslo","Jelling","Truso", "Bergen","Faeroerne","Reykjavik","Trondheim","Godthab","Helluland","Lillehammer","Markland","Elsinore", "Sarpsborg","Odense","Aalborg","Stavanger","Vorbasse","Schleswig","Kristiansand","Halogaland","Randers", diff --git a/core/src/com/unciv/logic/automation/UnitAutomation.kt b/core/src/com/unciv/logic/automation/UnitAutomation.kt index 5dbe35eecb..6e055d0282 100644 --- a/core/src/com/unciv/logic/automation/UnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/UnitAutomation.kt @@ -243,7 +243,7 @@ object UnitAutomation { } private fun tryHealUnit(unit: MapUnit): Boolean { - if (unit.baseUnit.isRanged() && unit.hasUnique("Unit will heal every turn, even if it performs an action")) + if (unit.baseUnit.isRanged() && unit.hasUnique(UniqueType.HealsEvenAfterAction)) return false // will heal anyway, and attacks don't hurt val unitDistanceToTiles = unit.movement.getDistanceToTiles() diff --git a/core/src/com/unciv/logic/battle/Battle.kt b/core/src/com/unciv/logic/battle/Battle.kt index a9297ee88a..a679ac6f5e 100644 --- a/core/src/com/unciv/logic/battle/Battle.kt +++ b/core/src/com/unciv/logic/battle/Battle.kt @@ -399,7 +399,7 @@ object Battle { if (attacker is MapUnitCombatant) { val unit = attacker.unit unit.attacksThisTurn += 1 - if (unit.hasUnique("Can move after attacking") || unit.maxAttacksPerTurn() > unit.attacksThisTurn) { + if (unit.hasUnique(UniqueType.CanMoveAfterAttacking) || unit.maxAttacksPerTurn() > unit.attacksThisTurn) { // if it was a melee attack and we won, then the unit ALREADY got movement points deducted, // for the movement to the enemy's tile! // and if it's an air unit, it only has 1 movement anyway, so... diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index d26423a1b4..592ec0be67 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -760,7 +760,7 @@ class MapUnit { currentTile.neighbors.flatMap { it.getUnits() }.forEach { it.healBy(15) } if (currentMovement == getMaxMovement().toFloat() // didn't move this turn - || hasUnique("Unit will heal every turn, even if it performs an action") + || hasUnique(UniqueType.HealsEvenAfterAction) ) heal() if (action != null && health > 99) diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index 0795e4a474..102765aa48 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -310,6 +310,12 @@ enum class UniqueType(val text:String, vararg targets: UniqueTarget, val flags: NoDefensiveTerrainPenalty("No defensive terrain penalty", UniqueTarget.Unit, UniqueTarget.Global), Uncapturable("Uncapturable", UniqueTarget.Unit), SelfDestructs("Self-destructs when attacking", UniqueTarget.Unit), + HealsEvenAfterAction("Unit will heal every turn, even if it performs an action", UniqueTarget.Unit), + NoMovementToPillage("No movement cost to pillage", UniqueTarget.Unit, UniqueTarget.Global), + @Deprecated("As of 3.18.17", ReplaceWith("No movement cost to pillage "), DeprecationLevel.WARNING) + NoMovementToPillageMelee("Melee units pay no movement cost to pillage", UniqueTarget.Unit, UniqueTarget.Global), + CanMoveAfterAttacking("Can move after attacking", UniqueTarget.Unit), + MoveImmediatelyOnceBought("Can move immediately once bought", UniqueTarget.Unit), BlastRadius("Blast radius [amount]", UniqueTarget.Unit), HealsOutsideFriendlyTerritory("May heal outside of friendly territory", UniqueTarget.Unit, UniqueTarget.Global), diff --git a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt index b2935ba34f..3ba88f2d25 100644 --- a/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt +++ b/core/src/com/unciv/models/ruleset/unit/BaseUnit.kt @@ -471,7 +471,7 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction { ?: return false // couldn't place the unit, so there's actually no unit =( //movement penalty - if (boughtWith != null && !civInfo.gameInfo.gameParameters.godMode && !unit.hasUnique("Can move immediately once bought")) + if (boughtWith != null && !civInfo.gameInfo.gameParameters.godMode && !unit.hasUnique(UniqueType.MoveImmediatelyOnceBought)) unit.currentMovement = 0f // If this unit has special abilities that need to be kept track of, start doing so here diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index 8a1fd42e16..64fd404b73 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -285,9 +285,10 @@ object UnitActions { tile.improvement = null if (tile.resource != null) tile.getOwner()?.updateDetailedCivResources() // this might take away a resource - val freePillage = unit.hasUnique("No movement cost to pillage") - || unit.civInfo.hasUnique("No movement cost to pillage") - || (unit.baseUnit.isMelee() && unit.civInfo.hasUnique("Melee units pay no movement cost to pillage")) + val freePillage = unit.hasUnique(UniqueType.NoMovementToPillage) + || unit.civInfo.hasUnique(UniqueType.NoMovementToPillage) + // Deprecated 3.18.17 + || (unit.baseUnit.isMelee() && unit.civInfo.hasUnique(UniqueType.NoMovementToPillageMelee)) if (!freePillage) unit.useMovementPoints(1f) unit.healBy(25)