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 <spellman23@gmail.com>
This commit is contained in:
itanasi 2022-02-19 08:37:38 -08:00 committed by GitHub
parent 4e338ae4f3
commit 2d60fe4565
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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!!))
}