From 20f34eb5f5be0580796d5695d6ca1f1ba019847a Mon Sep 17 00:00:00 2001 From: itanasi <44038014+itanasi@users.noreply.github.com> Date: Sat, 5 Mar 2022 10:06:06 -0800 Subject: [PATCH] Block Embarked from capturing Civilians on Water (#6224) * Correct logic for blocking Naval Melee from capturing Civilians on Land * Even better solution now that we can move on to unguarded Civilian tiles. But still won't let us capture Civilians if we can't get there * Make Embarked unable to capture Civilians * Embarked can't capture Water Civilians * Fix Gradle Test * Better unit test without making variable not internal * attempt not working * Just make currentTile not internal * remove debug * erronious import Co-authored-by: itanasi --- core/src/com/unciv/logic/map/MapUnit.kt | 2 +- core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt | 6 ++++-- .../src/com/unciv/logic/map/UnitMovementAlgorithmsTests.kt | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 3809c1f5f3..e902e20bd2 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -40,7 +40,7 @@ class MapUnit { lateinit var baseUnit: BaseUnit @Transient - internal lateinit var currentTile: TileInfo + lateinit var currentTile: TileInfo @Transient val movement = UnitMovementAlgorithms(this) diff --git a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt index 86ba5f22fb..c8ab5348f5 100644 --- a/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt +++ b/core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt @@ -630,8 +630,10 @@ class UnitMovementAlgorithms(val unit:MapUnit) { val firstUnit = tile.getFirstUnit() // Moving to non-empty tile if (firstUnit != null && unit.civInfo != firstUnit.civInfo) { - // Allow movement through unguarded, at-war Civilian Unit. Capture on the way - if (tile.getUnguardedCivilian() != null && unit.civInfo.isAtWarWith(tile.civilianUnit!!.civInfo)) + // Allow movement through unguarded, at-war Civilian Unit. Capture on the way + // But not for Embarked Units capturing on Water + if (!(unit.isEmbarked() && tile.isWater) + && tile.getUnguardedCivilian() != null && unit.civInfo.isAtWarWith(tile.civilianUnit!!.civInfo)) return true // Cannot enter hostile tile with any unit in there if (unit.civInfo.isAtWarWith(firstUnit.civInfo)) diff --git a/tests/src/com/unciv/logic/map/UnitMovementAlgorithmsTests.kt b/tests/src/com/unciv/logic/map/UnitMovementAlgorithmsTests.kt index a97148c7ba..78ce5e2418 100644 --- a/tests/src/com/unciv/logic/map/UnitMovementAlgorithmsTests.kt +++ b/tests/src/com/unciv/logic/map/UnitMovementAlgorithmsTests.kt @@ -208,6 +208,8 @@ class UnitMovementAlgorithmsTests { fun canNOTPassThroughTileWithEnemyUnits() { tile.baseTerrain = Constants.grassland tile.setTransients() + + unit.currentTile = tile val otherCiv = CivilizationInfo() otherCiv.civName = Constants.barbarians // they are always enemies