From 651dcff5813a45208e41f8256ba964bf4f310f9b Mon Sep 17 00:00:00 2001 From: SomeTroglodyte <63000004+SomeTroglodyte@users.noreply.github.com> Date: Mon, 28 Feb 2022 18:41:22 +0100 Subject: [PATCH] Fix Polynesia's Wayfinding (#6238) * Fix Polynesia's Wayfinding * Fix mod option to use other unit filters with UnitsMayEnterOcean --- .../jsons/Civ V - Gods & Kings/Nations.json | 2 +- .../jsons/Civ V - Gods & Kings/Techs.json | 2 +- .../assets/jsons/Civ V - Vanilla/Nations.json | 2 +- .../assets/jsons/Civ V - Vanilla/Techs.json | 2 +- .../unciv/logic/civilization/TechManager.kt | 22 +++++++++++++------ .../unciv/logic/map/UnitMovementAlgorithms.kt | 12 ++++++---- .../unciv/models/ruleset/unique/UniqueType.kt | 10 +++++---- docs/Modders/uniques.md | 4 +++- 8 files changed, 36 insertions(+), 20 deletions(-) diff --git a/android/assets/jsons/Civ V - Gods & Kings/Nations.json b/android/assets/jsons/Civ V - Gods & Kings/Nations.json index c98f736967..e951f9a6e9 100644 --- a/android/assets/jsons/Civ V - Gods & Kings/Nations.json +++ b/android/assets/jsons/Civ V - Gods & Kings/Nations.json @@ -488,7 +488,7 @@ "innerColor": [255,255,78], "favoredReligion": "Christianity", "uniqueName": "Wayfinding", - "uniques": ["Enables embarkation for land units ", "Enables embarked units to enter ocean tiles ", "Normal vision when embarked ", "+[10]% Strength if within [2] tiles of a [Moai]"], + "uniques": ["Enables embarkation for land units ", "Enables [All] units to enter ocean tiles ", "Normal vision when embarked ", "+[10]% Strength if within [2] tiles of a [Moai]"], "cities": ["Honolulu","Samoa","Tonga","Nuku Hiva","Raiatea","Aotearoa","Tahiti","Hilo","Te Wai Pounamu","Rapa Nui", "Tuamotu","Rarotonga","Tuvalu","Tubuai","Mangareva","Oahu","Kiritimati","Ontong Java","Niue","Rekohu", "Rakahanga","Bora Bora","Kailua","Uvea","Futuna","Rotuma","Tokelau","Lahaina","Bellona","Mungava","Tikopia", diff --git a/android/assets/jsons/Civ V - Gods & Kings/Techs.json b/android/assets/jsons/Civ V - Gods & Kings/Techs.json index e0a324139c..ad22e0a0ca 100644 --- a/android/assets/jsons/Civ V - Gods & Kings/Techs.json +++ b/android/assets/jsons/Civ V - Gods & Kings/Techs.json @@ -266,7 +266,7 @@ { "name": "Astronomy", "row": 2, - "uniques": ["[+1] Movement ","Enables embarked units to enter ocean tiles"], + "uniques": ["[+1] Movement ","Enables [Embarked] units to enter ocean tiles"], "prerequisites": ["Compass","Education"], "quote": "'Joyfully to the breeze royal Odysseus spread his sail, and with his rudder skillfully he steered.' - Homer" }, diff --git a/android/assets/jsons/Civ V - Vanilla/Nations.json b/android/assets/jsons/Civ V - Vanilla/Nations.json index dc80ae012c..8dce146691 100644 --- a/android/assets/jsons/Civ V - Vanilla/Nations.json +++ b/android/assets/jsons/Civ V - Vanilla/Nations.json @@ -468,7 +468,7 @@ "outerColor": [225,105,0], "innerColor": [255,255,78], "uniqueName": "Wayfinding", - "uniques": ["Enables embarkation for land units ", "Enables embarked units to enter ocean tiles ", "Normal vision when embarked ", "+[10]% Strength if within [2] tiles of a [Moai]"], + "uniques": ["Enables embarkation for land units ", "Enables [All] units to enter ocean tiles ", "Normal vision when embarked ", "+[10]% Strength if within [2] tiles of a [Moai]"], "cities": ["Honolulu","Samoa","Tonga","Nuku Hiva","Raiatea","Aotearoa","Tahiti","Hilo","Te Wai Pounamu","Rapa Nui", "Tuamotu","Rarotonga","Tuvalu","Tubuai","Mangareva","Oahu","Kiritimati","Ontong Java","Niue","Rekohu", "Rakahanga","Bora Bora","Kailua","Uvea","Futuna","Rotuma","Tokelau","Lahaina","Bellona","Mungava","Tikopia", diff --git a/android/assets/jsons/Civ V - Vanilla/Techs.json b/android/assets/jsons/Civ V - Vanilla/Techs.json index a5af71b88e..989ad3a36e 100644 --- a/android/assets/jsons/Civ V - Vanilla/Techs.json +++ b/android/assets/jsons/Civ V - Vanilla/Techs.json @@ -246,7 +246,7 @@ { "name": "Astronomy", "row": 2, - "uniques": ["[+1] Movement ","Enables embarked units to enter ocean tiles"], + "uniques": ["[+1] Movement ","Enables [Embarked] units to enter ocean tiles"], "prerequisites": ["Compass","Education"], "quote": "'Joyfully to the breeze royal Odysseus spread his sail, and with his rudder skillfully he steered.' - Homer" }, diff --git a/core/src/com/unciv/logic/civilization/TechManager.kt b/core/src/com/unciv/logic/civilization/TechManager.kt index 8c4078c821..2862a6f57e 100644 --- a/core/src/com/unciv/logic/civilization/TechManager.kt +++ b/core/src/com/unciv/logic/civilization/TechManager.kt @@ -3,7 +3,6 @@ package com.unciv.logic.civilization import com.unciv.logic.city.CityInfo import com.unciv.logic.map.MapSize import com.unciv.logic.map.RoadStatus -import com.unciv.logic.map.TileInfo import com.unciv.models.ruleset.Era import com.unciv.models.ruleset.unique.UniqueMap import com.unciv.models.ruleset.unique.UniqueTriggerActivation @@ -34,11 +33,13 @@ class TechManager { // MapUnit.canPassThrough is the most called function in the game, and having these extremely specific booleans is one way of improving the time cost @Transient - var wayfinding = false - @Transient var unitsCanEmbark = false @Transient var embarkedUnitsCanEnterOcean = false + @Transient + var allUnitsCanEnterOcean = false + @Transient + var specificUnitsCanEnterOcean = false // UnitMovementAlgorithms.getMovementCostBetweenAdjacentTiles is a close second =) @Transient @@ -373,15 +374,22 @@ class TechManager { fun setTransients() { researchedTechnologies.addAll(techsResearched.map { getRuleset().technologies[it]!! }) researchedTechnologies.forEach { addTechToTransients(it) } + updateEra() // before updateTransientBooleans so era-based conditionals can work updateTransientBooleans() - updateEra() } private fun updateTransientBooleans() { - wayfinding = civInfo.hasUnique(UniqueType.EmbarkAndEnterOcean) - unitsCanEmbark = wayfinding || civInfo.hasUnique(UniqueType.LandUnitEmbarkation) + val wayfinding = civInfo.hasUnique(UniqueType.EmbarkAndEnterOcean) + unitsCanEmbark = wayfinding || + civInfo.hasUnique(UniqueType.LandUnitEmbarkation) + val enterOceanUniques = civInfo.getMatchingUniques(UniqueType.UnitsMayEnterOcean) + allUnitsCanEnterOcean = enterOceanUniques.any { it.params[0] == "All" } + embarkedUnitsCanEnterOcean = wayfinding || + allUnitsCanEnterOcean || + enterOceanUniques.any { it.params[0] == "Embarked" } || + civInfo.hasUnique(UniqueType.EmbarkedUnitsMayEnterOcean) + specificUnitsCanEnterOcean = enterOceanUniques.any { it.params[0] != "All" && it.params[0] != "Embarked" } - embarkedUnitsCanEnterOcean = wayfinding || civInfo.hasUnique(UniqueType.EmbarkedUnitsMayEnterOcean) movementSpeedOnRoads = if (civInfo.hasUnique(UniqueType.RoadMovementSpeed)) RoadStatus.Road.movementImproved else RoadStatus.Road.movement roadsConnectAcrossRivers = civInfo.hasUnique(UniqueType.RoadsConnectAcrossRivers) diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index 6bfacacdc7..86ba5f22fb 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -610,14 +610,18 @@ class UnitMovementAlgorithms(val unit:MapUnit) { && !tile.isCityCenter()) return false - + val unitSpecificAllowOcean: Boolean by lazy { + unit.civInfo.tech.specificUnitsCanEnterOcean && + unit.civInfo.getMatchingUniques(UniqueType.UnitsMayEnterOcean) + .any { unit.matchesFilter(it.params[0]) } + } if (tile.isWater && unit.baseUnit.isLandUnit()) { if (!unit.civInfo.tech.unitsCanEmbark) return false - if (tile.isOcean && !unit.civInfo.tech.embarkedUnitsCanEnterOcean) + if (tile.isOcean && !unit.civInfo.tech.embarkedUnitsCanEnterOcean && !unitSpecificAllowOcean) return false } - if (tile.isOcean && !unit.civInfo.tech.wayfinding) { // Apparently all Polynesian naval units can enter oceans - if (unit.cannotEnterOceanTiles) return false + if (tile.isOcean && !unit.civInfo.tech.allUnitsCanEnterOcean) { // Apparently all Polynesian naval units can enter oceans + if (!unitSpecificAllowOcean && unit.cannotEnterOceanTiles) return false } if (tile.naturalWonder != null) return false diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index 097378877d..1111e4b36d 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -279,20 +279,22 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: CityHealingUnits("[mapUnitFilter] Units adjacent to this city heal [amount] HP per turn when healing", UniqueTarget.Global, UniqueTarget.FollowerBelief), GoldenAgeLength("[amount]% Golden Age length", UniqueTarget.Global), - + StrengthForCities("[amount]% Strength for cities", UniqueTarget.Global, UniqueTarget.FollowerBelief), @Deprecated("as of 3.19.1", ReplaceWith("[+amount]% Strength for cities ")) StrengthForGarrisonedCitiesAttacking("+[amount]% attacking strength for cities with garrisoned units", UniqueTarget.Global), - + UnitStartingExperience("New [baseUnitFilter] units start with [amount] Experience [cityFilter]", UniqueTarget.Global, UniqueTarget.FollowerBelief), UnitStartingPromotions("All newly-trained [baseUnitFilter] units [cityFilter] receive the [promotion] promotion", UniqueTarget.Global, UniqueTarget.FollowerBelief), UnitStartingActions("[baseUnitFilter] units built [cityFilter] can [action] [amount] extra times", UniqueTarget.Global, UniqueTarget.FollowerBelief), // ToDo: make per unit and use unit filters? LandUnitEmbarkation("Enables embarkation for land units", UniqueTarget.Global), + UnitsMayEnterOcean("Enables [mapUnitFilter] units to enter ocean tiles", UniqueTarget.Global), + @Deprecated("as of 3.19.13", ReplaceWith("Enables [Embarked] units to enter ocean tiles ")) EmbarkedUnitsMayEnterOcean("Enables embarked units to enter ocean tiles", UniqueTarget.Global), - @Deprecated("as of 3.19.9", ReplaceWith("Enables embarkation for land units \", \"Enables embarked units to enter ocean tiles ")) + @Deprecated("as of 3.19.9", ReplaceWith("Enables embarkation for land units \", \"Enables [All] units to enter ocean tiles ")) EmbarkAndEnterOcean("Can embark and move over Coasts and Oceans immediately", UniqueTarget.Global), - + PopulationLossFromNukes("Population loss from nuclear attacks [amount]% [cityFilter]", UniqueTarget.Global), @Deprecated("as of 3.19.2", ReplaceWith("Population loss from nuclear attacks [-amount]% [in this city]")) PopulationLossFromNukesDeprecated("Population loss from nuclear attacks -[amount]%", UniqueTarget.Global), diff --git a/docs/Modders/uniques.md b/docs/Modders/uniques.md index f3bd089397..d6ca6530ba 100644 --- a/docs/Modders/uniques.md +++ b/docs/Modders/uniques.md @@ -551,7 +551,9 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl ??? example "Enables embarkation for land units" Applicable to: Global -??? example "Enables embarked units to enter ocean tiles" +??? example "Enables [mapUnitFilter] units to enter ocean tiles" + Example: "Enables [Wounded] units to enter ocean tiles" + Applicable to: Global ??? example "Population loss from nuclear attacks [amount]% [cityFilter]"