From 91bb6fa89aff6c3d0d801a5443b0bd170ed8dba2 Mon Sep 17 00:00:00 2001 From: itanasi <44038014+itanasi@users.noreply.github.com> Date: Wed, 5 Oct 2022 11:29:56 -0700 Subject: [PATCH] Create Cannot Move Unique (#7855) * Create Cannot Move Unique * Covering other potential avenues of moving * Remove transient, fix Air Units movement range UI * Better fix for AirUnits --- core/src/com/unciv/logic/map/MapUnit.kt | 1 + core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt | 4 ++++ core/src/com/unciv/models/ruleset/unique/UniqueType.kt | 1 + core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt | 1 + 4 files changed, 7 insertions(+) diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 600c6b4dd4..47b0cf7546 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -487,6 +487,7 @@ class MapUnit : IsPartOfGameInfoSerialization { } fun getMaxMovementForAirUnits(): Int { + if (hasUnique(UniqueType.CannotMove)) return getRange() // also used for marking attack range return getRange() * 2 } diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index f1bff8cad8..d2393a0643 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -608,6 +608,7 @@ class UnitMovementAlgorithms(val unit: MapUnit) { * DOES NOT designate whether we can reach that tile in the current turn */ fun canMoveTo(tile: TileInfo, assumeCanPassThrough: Boolean = false): Boolean { + if (unit.hasUnique(UniqueType.CannotMove)) return false if (unit.baseUnit.movesLikeAirUnits()) return canAirUnitMoveTo(tile, unit) @@ -626,6 +627,7 @@ class UnitMovementAlgorithms(val unit: MapUnit) { } private fun canAirUnitMoveTo(tile: TileInfo, unit: MapUnit): Boolean { + if (unit.hasUnique(UniqueType.CannotMove)) return false // landing in the city if (tile.isCityCenter()) { if (tile.airUnits.filter { !it.isTransported }.size < 6 && tile.getCity()?.civInfo == unit.civInfo) @@ -641,6 +643,7 @@ class UnitMovementAlgorithms(val unit: MapUnit) { // Can a paratrooper land at this tile? fun canParadropOn(destination: TileInfo): Boolean { + if (unit.hasUnique(UniqueType.CannotMove)) return false // Can only move to land tiles within range that are visible and not impassible // Based on some testing done in the base game if (!destination.isLand || destination.isImpassible() || !unit.civInfo.viewableTiles.contains(destination)) return false @@ -657,6 +660,7 @@ class UnitMovementAlgorithms(val unit: MapUnit) { * because optimization on this function results in massive benefits! */ fun canPassThrough(tile: TileInfo): Boolean { + if (unit.hasUnique(UniqueType.CannotMove)) return false if (tile.isImpassible()) { // special exception - ice tiles are technically impassible, but some units can move through them anyway // helicopters can pass through impassable tiles like mountains diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index 0463f97165..b1b8a433ab 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -455,6 +455,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: DestroysImprovementUponAttack("Destroys tile improvements when attacking", UniqueTarget.Unit), // The following block gets cached in MapUnit for faster getMovementCostBetweenAdjacentTiles + CannotMove("Cannot move", UniqueTarget.Unit), DoubleMovementOnTerrain("Double movement in [terrainFilter]", UniqueTarget.Unit), AllTilesCost1Move("All tiles cost 1 movement", UniqueTarget.Unit), CanPassImpassable("Can pass through impassable tiles", UniqueTarget.Unit), diff --git a/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt b/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt index 1d61be7a06..77b3dc2c62 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt @@ -30,6 +30,7 @@ import com.unciv.models.AttackableTile import com.unciv.models.UncivSound import com.unciv.models.helpers.MapArrowType import com.unciv.models.helpers.MiscArrowTypes +import com.unciv.models.ruleset.unique.UniqueType import com.unciv.ui.UncivStage import com.unciv.ui.audio.SoundPlayer import com.unciv.ui.images.ImageGetter