From 203ee77c8b85590bbbd71bef59cbc3c7c177624b Mon Sep 17 00:00:00 2001 From: SeventhM <127357473+SeventhM@users.noreply.github.com> Date: Sun, 30 Jul 2023 07:39:41 -0700 Subject: [PATCH] Clean up some differences between units that can move on water and other units (#9841) * Clean up some differences between units that can move on water, water units, and land units * Strangely no evidence this actually comes up? * refernce the cache in more places * Decided to change this back to match expected results * Remove unnecessary parenthesis --- core/src/com/unciv/logic/automation/unit/BattleHelper.kt | 4 ++-- core/src/com/unciv/logic/battle/BattleDamage.kt | 2 +- core/src/com/unciv/logic/map/TileMap.kt | 2 +- core/src/com/unciv/logic/map/mapunit/MapUnit.kt | 1 + core/src/com/unciv/logic/map/mapunit/UnitMovement.kt | 4 ++-- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/core/src/com/unciv/logic/automation/unit/BattleHelper.kt b/core/src/com/unciv/logic/automation/unit/BattleHelper.kt index 203ce6a292..063e740023 100644 --- a/core/src/com/unciv/logic/automation/unit/BattleHelper.kt +++ b/core/src/com/unciv/logic/automation/unit/BattleHelper.kt @@ -121,8 +121,8 @@ object BattleHelper { if (tileCombatant is CityCombatant && tileCombatant.city.hasJustBeenConquered) return false if (!combatant.getCivInfo().isAtWarWith(tileCombatant.getCivInfo())) return false - if (combatant is MapUnitCombatant && combatant.isLandUnit() && combatant.isMelee() && - !combatant.hasUnique(UniqueType.LandUnitEmbarkation) && tile.isWater + if (combatant is MapUnitCombatant && combatant.isLandUnit() && combatant.isMelee() && tile.isWater && + !combatant.getCivInfo().tech.unitsCanEmbark && !combatant.unit.cache.canMoveOnWater ) return false diff --git a/core/src/com/unciv/logic/battle/BattleDamage.kt b/core/src/com/unciv/logic/battle/BattleDamage.kt index ee381f1580..f76f25f727 100644 --- a/core/src/com/unciv/logic/battle/BattleDamage.kt +++ b/core/src/com/unciv/logic/battle/BattleDamage.kt @@ -114,7 +114,7 @@ object BattleDamage { val modifiers = getGeneralModifiers(attacker, defender, CombatAction.Attack, tileToAttackFrom) if (attacker is MapUnitCombatant) { - if (attacker.unit.isEmbarked() + if (attacker.unit.isEmbarked() && defender.getTile().isLand && !attacker.unit.hasUnique(UniqueType.AttackAcrossCoast)) modifiers["Landing"] = -50 diff --git a/core/src/com/unciv/logic/map/TileMap.kt b/core/src/com/unciv/logic/map/TileMap.kt index 2d27816ad6..632b8237fa 100644 --- a/core/src/com/unciv/logic/map/TileMap.kt +++ b/core/src/com/unciv/logic/map/TileMap.kt @@ -513,7 +513,7 @@ class TileMap(initialCapacity: Int = 10) : IsPartOfGameInfoSerialization { var potentialCandidates = getPassableNeighbours(currentTile) while (unitToPlaceTile == null && tryCount++ < 10) { unitToPlaceTile = potentialCandidates - .sortedByDescending { if (unit.baseUnit.isLandUnit()) it.isLand else true } // Land units should prefer to go into land tiles + .sortedByDescending { if (unit.baseUnit.isLandUnit() && !unit.cache.canMoveOnWater) it.isLand else true } // Land units should prefer to go into land tiles .firstOrNull { unit.movement.canMoveTo(it) } if (unitToPlaceTile != null) continue // if it's not found yet, let's check their neighbours diff --git a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt index 4e99ba1ae0..de58532944 100644 --- a/core/src/com/unciv/logic/map/mapunit/MapUnit.kt +++ b/core/src/com/unciv/logic/map/mapunit/MapUnit.kt @@ -509,6 +509,7 @@ class MapUnit : IsPartOfGameInfoSerialization { var healing = when { tile.isCityCenter() -> 25 tile.isWater && isFriendlyTerritory && (baseUnit.isWaterUnit() || isTransported) -> 20 // Water unit on friendly water + tile.isWater && isFriendlyTerritory && cache.canMoveOnWater -> 20 // Treated as a water unit on friendly water tile.isWater -> 0 // All other water cases isFriendlyTerritory -> 20 // Allied territory tile.getOwner() == null -> 10 // Neutral territory diff --git a/core/src/com/unciv/logic/map/mapunit/UnitMovement.kt b/core/src/com/unciv/logic/map/mapunit/UnitMovement.kt index e6b6ca4b06..374ec00a62 100644 --- a/core/src/com/unciv/logic/map/mapunit/UnitMovement.kt +++ b/core/src/com/unciv/logic/map/mapunit/UnitMovement.kt @@ -769,7 +769,7 @@ class UnitMovement(val unit: MapUnit) { unit.civ.getMatchingUniques(UniqueType.UnitsMayEnterOcean) .any { unit.matchesFilter(it.params[0]) } } - if (tile.isWater && unit.baseUnit.isLandUnit()) { + if (tile.isWater && unit.baseUnit.isLandUnit() && !unit.cache.canMoveOnWater) { if (!unit.civ.tech.unitsCanEmbark) return false if (tile.isOcean && !unit.civ.tech.embarkedUnitsCanEnterOcean && !unitSpecificAllowOcean) return false @@ -791,7 +791,7 @@ class UnitMovement(val unit: MapUnit) { if (firstUnit != null && unit.civ != firstUnit.civ) { // Allow movement through unguarded, at-war Civilian Unit. Capture on the way // But not for Embarked Units capturing on Water - if (!(unit.baseUnit.isLandUnit() && tile.isWater) + if (!(unit.baseUnit.isLandUnit() && tile.isWater && !unit.cache.canMoveOnWater) && firstUnit.isCivilian() && unit.civ.isAtWarWith(firstUnit.civ)) return true // Cannot enter hostile tile with any unit in there