From 2d60fe45654191c932cb21cd67dc279729c93fa9 Mon Sep 17 00:00:00 2001 From: itanasi <44038014+itanasi@users.noreply.github.com> Date: Sat, 19 Feb 2022 08:37:38 -0800 Subject: [PATCH] Prevent Civilians from capturing Civilians (#6185) * Initial attempt * Allow Ranged to move into unguarded Civilian Unit * Comment for clarity * Fix unit test so that it doesn't segfault and checks you can't move into military units * Unify that all units can move on to (and through) unguarded civilians that you are at war with Add TileInfo.getUnguardedCivilian() to quickly respond if there is an unguarded Civilian on the tile Something is bugged in movement code * Fix MapUnit.moveThroughTile() so that it doesn't segfault by fixing getUnguardedCivilian() * captureCivilianUnit() call is now redundant in postBattleMoveToAttackedTile() since canMoveTo() will now return true and capture will happen during the moveToTile() call * Add check so Civilian Units don't capture other Civilians * Change logic to isMilitary() Co-authored-by: temurakami --- core/src/com/unciv/logic/map/MapUnit.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 696669784e..8e503216bd 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -429,6 +429,7 @@ class MapUnit { /** For display in Unit Overview */ fun getActionLabel() = if (action == null) "" else if (isFortified()) UnitActionType.Fortify.value else action!! + fun isMilitary() = baseUnit.isMilitary() fun isCivilian() = baseUnit.isCivilian() fun getFortificationTurns(): Int { @@ -561,7 +562,7 @@ class MapUnit { } // Only military land units can truly "garrison" - fun canGarrison() = baseUnit.isMilitary() && baseUnit.isLandUnit() + fun canGarrison() = isMilitary() && baseUnit.isLandUnit() fun isGreatPerson() = baseUnit.isGreatPerson() @@ -815,7 +816,7 @@ class MapUnit { // Wake sleeping units if there's an enemy in vision range: // Military units always but civilians only if not protected. - if (isSleeping() && (baseUnit.isMilitary() || currentTile.militaryUnit == null) && + if (isSleeping() && (isMilitary() || currentTile.militaryUnit == null) && this.viewableTiles.any { it.militaryUnit != null && it.militaryUnit!!.civInfo.isAtWarWith(civInfo) } @@ -870,7 +871,7 @@ class MapUnit { if (tile.improvement == Constants.barbarianEncampment && !civInfo.isBarbarian()) clearEncampment(tile) // Capture Enemy Civilian Unit if you move on top of it - if (tile.getUnguardedCivilian() != null && civInfo.isAtWarWith(tile.getUnguardedCivilian()!!.civInfo)) { + if (isMilitary() && tile.getUnguardedCivilian() != null && civInfo.isAtWarWith(tile.getUnguardedCivilian()!!.civInfo)) { Battle.captureCivilianUnit(MapUnitCombatant(this), MapUnitCombatant(tile.civilianUnit!!)) }