From f78fd7e66567a29547156db86cafa529879b7237 Mon Sep 17 00:00:00 2001 From: SeventhM <127357473+SeventhM@users.noreply.github.com> Date: Thu, 22 Jun 2023 22:51:48 -0700 Subject: [PATCH] Move on water (#9622) * Add in Move on water unique * Small fixes * Remove redundant check --- core/src/com/unciv/logic/battle/BattleDamage.kt | 6 +++--- core/src/com/unciv/logic/map/mapunit/MapUnit.kt | 1 + core/src/com/unciv/logic/map/mapunit/MapUnitCache.kt | 4 ++++ core/src/com/unciv/logic/map/mapunit/UnitMovement.kt | 2 +- core/src/com/unciv/models/ruleset/unique/UniqueType.kt | 1 + 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/core/src/com/unciv/logic/battle/BattleDamage.kt b/core/src/com/unciv/logic/battle/BattleDamage.kt index b0a554e617..ee381f1580 100644 --- a/core/src/com/unciv/logic/battle/BattleDamage.kt +++ b/core/src/com/unciv/logic/battle/BattleDamage.kt @@ -119,11 +119,11 @@ object BattleDamage { modifiers["Landing"] = -50 // Land Melee Unit attacking to Water - if (attacker.unit.type.isLandUnit() && !attacker.unit.isEmbarked() && attacker.isMelee() && defender.getTile().isWater + if (attacker.unit.type.isLandUnit() && !attacker.getTile().isWater && attacker.isMelee() && defender.getTile().isWater && !attacker.unit.hasUnique(UniqueType.AttackAcrossCoast)) modifiers["Boarding"] = -50 - // Naval Unit Melee attacking to Land (not City) unit - if (attacker.unit.type.isWaterUnit() && attacker.isMelee() && !defender.getTile().isWater + // Melee Unit on water attacking to Land (not City) unit + if (!attacker.unit.type.isAirUnit() && attacker.isMelee() && attacker.getTile().isWater && !defender.getTile().isWater && !attacker.unit.hasUnique(UniqueType.AttackAcrossCoast) && !defender.isCity()) modifiers["Landing"] = -50 // Air unit attacking with Air Sweep diff --git a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt index bed2e656ed..68cbba2fe0 100644 --- a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt +++ b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt @@ -378,6 +378,7 @@ class MapUnit : IsPartOfGameInfoSerialization { fun isEmbarked(): Boolean { if (!baseUnit.isLandUnit()) return false + if (cache.canMoveOnWater) return false return currentTile.isWater } diff --git a/core/src/com/unciv/logic/map/mapunit/MapUnitCache.kt b/core/src/com/unciv/logic/map/mapunit/MapUnitCache.kt index 89dd387d09..367505965f 100644 --- a/core/src/com/unciv/logic/map/mapunit/MapUnitCache.kt +++ b/core/src/com/unciv/logic/map/mapunit/MapUnitCache.kt @@ -20,6 +20,9 @@ class MapUnitCache(private val mapUnit: MapUnit) { var allTilesCosts1 = false private set + var canMoveOnWater = false + private set + var canPassThroughImpassableTiles = false private set @@ -75,6 +78,7 @@ class MapUnitCache(private val mapUnit: MapUnit) { ignoresZoneOfControl = mapUnit.hasUnique(UniqueType.IgnoresZOC) roughTerrainPenalty = mapUnit.hasUnique(UniqueType.RoughTerrainPenalty) cannotMove = mapUnit.hasUnique(UniqueType.CannotMove) || mapUnit.baseUnit.movement == 0 + canMoveOnWater = mapUnit.hasUnique(UniqueType.CanMoveOnWater) doubleMovementInTerrain.clear() for (unique in mapUnit.getMatchingUniques(UniqueType.DoubleMovementOnTerrain, stateForConditionals = StateForConditionals.IgnoreConditionals)) { diff --git a/core/src/com/unciv/logic/map/mapunit/UnitMovement.kt b/core/src/com/unciv/logic/map/mapunit/UnitMovement.kt index aab14f0441..e6b6ca4b06 100644 --- a/core/src/com/unciv/logic/map/mapunit/UnitMovement.kt +++ b/core/src/com/unciv/logic/map/mapunit/UnitMovement.kt @@ -37,7 +37,7 @@ class UnitMovement(val unit: MapUnit) { ): Float { if (unit.cache.cannotMove) return 100f - if (from.isLand != to.isLand && unit.baseUnit.isLandUnit()) + if (from.isLand != to.isLand && unit.baseUnit.isLandUnit() && !unit.cache.canMoveOnWater) return if (from.isWater && to.isLand) unit.cache.costToDisembark ?: 100f else unit.cache.costToEmbark ?: 100f diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt index b28fa9f9fe..d79216f989 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueType.kt @@ -506,6 +506,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags: CannotMove("Cannot move", UniqueTarget.Unit), DoubleMovementOnTerrain("Double movement in [terrainFilter]", UniqueTarget.Unit), AllTilesCost1Move("All tiles cost 1 movement", UniqueTarget.Unit), + CanMoveOnWater("May travel on Water tiles without embarking", UniqueTarget.Unit), CanPassImpassable("Can pass through impassable tiles", UniqueTarget.Unit), IgnoresTerrainCost("Ignores terrain cost", UniqueTarget.Unit), IgnoresZOC("Ignores Zone of Control", UniqueTarget.Unit),