Typed denmarks unique and generalized it (#6463)

* Typed denmarks unique and generalized it

* Added support for deprecated unique
This commit is contained in:
Xander Lenstra 2022-03-31 22:05:37 +02:00 committed by GitHub
parent 90a172ab02
commit 72b4d2069e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 10 deletions

View File

@ -689,7 +689,7 @@
"innerColor": [255,255,102], "innerColor": [255,255,102],
"favoredReligion": "Christianity", "favoredReligion": "Christianity",
"uniqueName": "Viking Fury", "uniqueName": "Viking Fury",
"uniques": ["[+1] Movement <for [Embarked] units>", "Units pay only 1 movement point to disembark", "uniques": ["[+1] Movement <for [Embarked] units>", "[1] Movement point cost to disembark <for [All] units>",
"No movement cost to pillage <for [Melee] units>"], "No movement cost to pillage <for [Melee] units>"],
"cities": ["Copenhagen","Aarhus","Kaupang","Ribe","Viborg","Tunsberg","Roskilde","Hedeby","Oslo","Jelling","Truso", "cities": ["Copenhagen","Aarhus","Kaupang","Ribe","Viborg","Tunsberg","Roskilde","Hedeby","Oslo","Jelling","Truso",
"Bergen","Faeroerne","Reykjavik","Trondheim","Godthab","Helluland","Lillehammer","Markland","Elsinore", "Bergen","Faeroerne","Reykjavik","Trondheim","Godthab","Helluland","Lillehammer","Markland","Elsinore",

View File

@ -662,7 +662,7 @@
"outerColor": [51,25,0], "outerColor": [51,25,0],
"innerColor": [255,255,102], "innerColor": [255,255,102],
"uniqueName": "Viking Fury", "uniqueName": "Viking Fury",
"uniques": ["[+1] Movement <for [Embarked] units>", "Units pay only 1 movement point to disembark", "uniques": ["[+1] Movement <for [Embarked] units>", "[1] Movement point cost to disembark <for [All] units>",
"No movement cost to pillage <for [Melee] units>"], "No movement cost to pillage <for [Melee] units>"],
"cities": ["Copenhagen","Aarhus","Kaupang","Ribe","Viborg","Tunsberg","Roskilde","Hedeby","Oslo","Jelling","Truso", "cities": ["Copenhagen","Aarhus","Kaupang","Ribe","Viborg","Tunsberg","Roskilde","Hedeby","Oslo","Jelling","Truso",
"Bergen","Faeroerne","Reykjavik","Trondheim","Godthab","Helluland","Lillehammer","Markland","Elsinore", "Bergen","Faeroerne","Reykjavik","Trondheim","Godthab","Helluland","Lillehammer","Markland","Elsinore",

View File

@ -108,6 +108,12 @@ class MapUnit {
@Transient @Transient
var canEnterForeignTerrain: Boolean = false var canEnterForeignTerrain: Boolean = false
@Transient
var costToDisembark: Float? = null
@Transient
var costToEmbark: Float? = null
@Transient @Transient
var paradropRange = 0 var paradropRange = 0
@ -326,6 +332,13 @@ class MapUnit {
.none { it.value != DoubleMovementTerrainTarget.Feature } .none { it.value != DoubleMovementTerrainTarget.Feature }
noFilteredDoubleMovementUniques = doubleMovementInTerrain noFilteredDoubleMovementUniques = doubleMovementInTerrain
.none { it.value == DoubleMovementTerrainTarget.Filter } .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: //todo: consider parameterizing [terrainFilter] in some of the following:
canEnterIceTiles = hasUnique(UniqueType.CanEnterIceTiles) canEnterIceTiles = hasUnique(UniqueType.CanEnterIceTiles)

View File

@ -18,8 +18,8 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
): Float { ): Float {
if (from.isLand != to.isLand && unit.baseUnit.isLandUnit()) if (from.isLand != to.isLand && unit.baseUnit.isLandUnit())
return if (unit.civInfo.nation.disembarkCosts1 && from.isWater && to.isLand) 1f return if (from.isWater && to.isLand) unit.costToDisembark ?: 100f
else 100f // this is embarkment or disembarkment, and will take the entire turn else unit.costToEmbark ?: 100f
// If the movement is affected by a Zone of Control, all movement points are expended // If the movement is affected by a Zone of Control, all movement points are expended
if (considerZoneOfControl && isMovementAffectedByZoneOfControl(from, to, civInfo)) if (considerZoneOfControl && isMovementAffectedByZoneOfControl(from, to, civInfo))
@ -40,7 +40,10 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
if (from.roadStatus == RoadStatus.Railroad && to.roadStatus == RoadStatus.Railroad) if (from.roadStatus == RoadStatus.Railroad && to.roadStatus == RoadStatus.Railroad)
return RoadStatus.Railroad.movement + extraCost 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 areConnectedByRoad = from.hasConnection(civInfo) && to.hasConnection(civInfo)
val areConnectedByRiver = from.isAdjacentToRiver() && to.isAdjacentToRiver() && from.isConnectedByRiver(to) val areConnectedByRiver = from.isAdjacentToRiver() && to.isAdjacentToRiver() && from.isConnectedByRiver(to)
if (areConnectedByRoad && (!areConnectedByRiver || civInfo.tech.roadsConnectAcrossRivers)) if (areConnectedByRoad && (!areConnectedByRiver || civInfo.tech.roadsConnectAcrossRivers))

View File

@ -78,9 +78,6 @@ class Nation : RulesetObject() {
@Transient @Transient
var ignoreHillMovementCost = false var ignoreHillMovementCost = false
@Transient
var disembarkCosts1 = false
fun setTransients() { fun setTransients() {
outerColorObject = colorFromRGB(outerColor) 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.") 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") 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<String> = arrayListOf() var cities: ArrayList<String> = arrayListOf()

View File

@ -488,6 +488,10 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
CannotEnterOcean("Cannot enter ocean tiles", UniqueTarget.Unit), CannotEnterOcean("Cannot enter ocean tiles", UniqueTarget.Unit),
CanEnterForeignTiles("May enter foreign tiles without open borders", 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), 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 <for [All] units>"))
DisembarkCostDeprecated("Units pay only 1 movement point to disembark", UniqueTarget.Global),
CannotBeBarbarian("Never appears as a Barbarian unit", UniqueTarget.Unit, flags = UniqueFlag.setOfHiddenToUsers), CannotBeBarbarian("Never appears as a Barbarian unit", UniqueTarget.Unit, flags = UniqueFlag.setOfHiddenToUsers),

View File

@ -751,6 +751,16 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
Applicable to: Global, Unit 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" ??? example "This Unit upgrades for free"
Applicable to: Global Applicable to: Global