From 72b4d2069eccabc336e501f06597deaf7e5b5841 Mon Sep 17 00:00:00 2001 From: Xander Lenstra <71121390+xlenstra@users.noreply.github.com> Date: Thu, 31 Mar 2022 22:05:37 +0200 Subject: [PATCH] Typed denmarks unique and generalized it (#6463) * Typed denmarks unique and generalized it * Added support for deprecated unique --- .../jsons/Civ V - Gods & Kings/Nations.json | 2 +- android/assets/jsons/Civ V - Vanilla/Nations.json | 2 +- core/src/com/unciv/logic/map/MapUnit.kt | 15 ++++++++++++++- .../com/unciv/logic/map/UnitMovementAlgorithms.kt | 9 ++++++--- core/src/com/unciv/models/ruleset/Nation.kt | 4 ---- .../com/unciv/models/ruleset/unique/UniqueType.kt | 4 ++++ docs/Modders/uniques.md | 10 ++++++++++ 7 files changed, 36 insertions(+), 10 deletions(-) diff --git a/android/assets/jsons/Civ V - Gods & Kings/Nations.json b/android/assets/jsons/Civ V - Gods & Kings/Nations.json index afd7727ab3..271fec53c5 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 @@ "innerColor": [255,255,102], "favoredReligion": "Christianity", "uniqueName": "Viking Fury", - "uniques": ["[+1] Movement ", "Units pay only 1 movement point to disembark", + "uniques": ["[+1] Movement ", "[1] Movement point cost to disembark ", "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", diff --git a/android/assets/jsons/Civ V - Vanilla/Nations.json b/android/assets/jsons/Civ V - Vanilla/Nations.json index d5e813a6d8..b660c65f13 100644 --- a/android/assets/jsons/Civ V - Vanilla/Nations.json +++ b/android/assets/jsons/Civ V - Vanilla/Nations.json @@ -662,7 +662,7 @@ "outerColor": [51,25,0], "innerColor": [255,255,102], "uniqueName": "Viking Fury", - "uniques": ["[+1] Movement ", "Units pay only 1 movement point to disembark", + "uniques": ["[+1] Movement ", "[1] Movement point cost to disembark ", "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", diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 801a8cd1c5..2584b47171 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -107,6 +107,12 @@ class MapUnit { @Transient var canEnterForeignTerrain: Boolean = false + + @Transient + var costToDisembark: Float? = null + + @Transient + var costToEmbark: Float? = null @Transient var paradropRange = 0 @@ -261,7 +267,7 @@ class MapUnit { fun getMatchingUniques( uniqueType: UniqueType, stateForConditionals: StateForConditionals = StateForConditionals(civInfo, unit=this), - checkCivInfoUniques:Boolean = false + checkCivInfoUniques: Boolean = false ) = sequence { val tempUniques = tempUniquesMap[uniqueType] if (tempUniques != null) @@ -326,6 +332,13 @@ class MapUnit { .none { it.value != DoubleMovementTerrainTarget.Feature } noFilteredDoubleMovementUniques = doubleMovementInTerrain .none { it.value == DoubleMovementTerrainTarget.Filter } + costToDisembark = (getMatchingUniques(UniqueType.ReducedDisembarkCost, checkCivInfoUniques = true) + // Deprecated as of 4.0.3 + + getMatchingUniques(UniqueType.DisembarkCostDeprecated, checkCivInfoUniques = true) + // + ).minOfOrNull { it.params[0].toFloat() } + costToEmbark = getMatchingUniques(UniqueType.ReducedEmbarkCost, checkCivInfoUniques = true) + .minOfOrNull { it.params[0].toFloat() } //todo: consider parameterizing [terrainFilter] in some of the following: canEnterIceTiles = hasUnique(UniqueType.CanEnterIceTiles) diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index c8ab5348f5..9d666b4a5e 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -7,7 +7,7 @@ import com.unciv.logic.civilization.CivilizationInfo import com.unciv.models.helpers.UnitMovementMemoryType import com.unciv.models.ruleset.unique.UniqueType -class UnitMovementAlgorithms(val unit:MapUnit) { +class UnitMovementAlgorithms(val unit: MapUnit) { // This function is called ALL THE TIME and should be as time-optimal as possible! private fun getMovementCostBetweenAdjacentTiles( @@ -18,8 +18,8 @@ class UnitMovementAlgorithms(val unit:MapUnit) { ): Float { if (from.isLand != to.isLand && unit.baseUnit.isLandUnit()) - return if (unit.civInfo.nation.disembarkCosts1 && from.isWater && to.isLand) 1f - else 100f // this is embarkment or disembarkment, and will take the entire turn + return if (from.isWater && to.isLand) unit.costToDisembark ?: 100f + else unit.costToEmbark ?: 100f // If the movement is affected by a Zone of Control, all movement points are expended if (considerZoneOfControl && isMovementAffectedByZoneOfControl(from, to, civInfo)) @@ -40,7 +40,10 @@ class UnitMovementAlgorithms(val unit:MapUnit) { if (from.roadStatus == RoadStatus.Railroad && to.roadStatus == RoadStatus.Railroad) return RoadStatus.Railroad.movement + extraCost + // Each of these two function calls `hasUnique(UniqueType.CityStateTerritoryAlwaysFriendly)` + // when entering territory of a city state val areConnectedByRoad = from.hasConnection(civInfo) && to.hasConnection(civInfo) + val areConnectedByRiver = from.isAdjacentToRiver() && to.isAdjacentToRiver() && from.isConnectedByRiver(to) if (areConnectedByRoad && (!areConnectedByRiver || civInfo.tech.roadsConnectAcrossRivers)) diff --git a/core/src/com/unciv/models/ruleset/Nation.kt b/core/src/com/unciv/models/ruleset/Nation.kt index 0ae7a209a3..379a4f9240 100644 --- a/core/src/com/unciv/models/ruleset/Nation.kt +++ b/core/src/com/unciv/models/ruleset/Nation.kt @@ -78,9 +78,6 @@ class Nation : RulesetObject() { @Transient var ignoreHillMovementCost = false - @Transient - var disembarkCosts1 = false - fun setTransients() { outerColorObject = colorFromRGB(outerColor) @@ -89,7 +86,6 @@ class Nation : RulesetObject() { forestsAndJunglesAreRoads = uniques.contains("All units move through Forest and Jungle Tiles in friendly territory as if they have roads. These tiles can be used to establish City Connections upon researching the Wheel.") ignoreHillMovementCost = uniques.contains("Units ignore terrain costs when moving into any tile with Hills") - disembarkCosts1 = uniques.contains("Units pay only 1 movement point to disembark") } var cities: ArrayList = arrayListOf() diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index 406506bc98..c2379340ad 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -488,6 +488,10 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: CannotEnterOcean("Cannot enter ocean tiles", UniqueTarget.Unit), CanEnterForeignTiles("May enter foreign tiles without open borders", UniqueTarget.Unit), CanEnterForeignTilesButLosesReligiousStrength("May enter foreign tiles without open borders, but loses [amount] religious strength each turn it ends there", UniqueTarget.Unit), + ReducedDisembarkCost("[amount] Movement point cost to disembark", UniqueTarget.Global, UniqueTarget.Unit), + ReducedEmbarkCost("[amount] Movement point cost to embark", UniqueTarget.Global, UniqueTarget.Unit), + @Deprecated("as of 4.0.3", ReplaceWith("[1] Movement point cost to disembark ")) + DisembarkCostDeprecated("Units pay only 1 movement point to disembark", UniqueTarget.Global), CannotBeBarbarian("Never appears as a Barbarian unit", UniqueTarget.Unit, flags = UniqueFlag.setOfHiddenToUsers), diff --git a/docs/Modders/uniques.md b/docs/Modders/uniques.md index 7889466c52..abea6afbc6 100644 --- a/docs/Modders/uniques.md +++ b/docs/Modders/uniques.md @@ -751,6 +751,16 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl Applicable to: Global, Unit +??? example "[amount] Movement point cost to disembark" + Example: "[20] Movement point cost to disembark" + + Applicable to: Global, Unit + +??? example "[amount] Movement point cost to embark" + Example: "[20] Movement point cost to embark" + + Applicable to: Global, Unit + ??? example "This Unit upgrades for free" Applicable to: Global