Skip to content

Commit

Permalink
Fixed bug where units would not enter a city upon capture
Browse files Browse the repository at this point in the history
As listed in yairm210#4697.
  • Loading branch information
avdstaaij committed Aug 11, 2021
1 parent 2a2cc34 commit 3e3ada8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 3 additions & 4 deletions core/src/com/unciv/logic/battle/Battle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ object Battle {

// check if unit is captured by the attacker (prize ships unique)
// As ravignir clarified in issue #4374, this only works for aggressor
val captureSuccess = defender is MapUnitCombatant && attacker is MapUnitCombatant
val captureMilitaryUnitSuccess = defender is MapUnitCombatant && attacker is MapUnitCombatant
&& defender.isDefeated() && !defender.unit.isCivilian()
&& tryCaptureUnit(attacker, defender)

if (!captureSuccess) // capture creates a new unit, but `defender` still is the original, so this function would still show a kill message
if (!captureMilitaryUnitSuccess) // capture creates a new unit, but `defender` still is the original, so this function would still show a kill message
postBattleNotifications(attacker, defender, attackedTile, attacker.getTile())

postBattleNationUniques(defender, attackedTile, attacker)
Expand Down Expand Up @@ -104,9 +104,8 @@ object Battle {
attacker.unit.action = null
}

// we're a melee unit and we destroyed\captured an enemy unit
// Should be called after tryCaptureUnit(), as that might spawn a unit on the tile we go to
if (!captureSuccess)
if (!captureMilitaryUnitSuccess)
postBattleMoveToAttackedTile(attacker, defender, attackedTile)

reduceAttackerMovementPointsAndAttacks(attacker, defender)
Expand Down
11 changes: 7 additions & 4 deletions core/src/com/unciv/logic/map/UnitMovementAlgorithms.kt
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,14 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
if (!canPassThrough(tile))
return false

if (tile.isCityCenter() && tile.getOwner() != unit.civInfo) return false // even if they'll let us pass through, we can't enter their city
// even if they'll let us pass through, we can't enter their city - unless we just captured it
if (tile.isCityCenter() && tile.getOwner() != unit.civInfo && !tile.getCity()!!.hasJustBeenConquered)
return false

if (unit.isCivilian())
return tile.civilianUnit == null && (tile.militaryUnit == null || tile.militaryUnit!!.owner == unit.owner)
else return tile.militaryUnit == null && (tile.civilianUnit == null || tile.civilianUnit!!.owner == unit.owner)
return if (unit.isCivilian())
tile.civilianUnit == null && (tile.militaryUnit == null || tile.militaryUnit!!.owner == unit.owner)
else
tile.militaryUnit == null && (tile.civilianUnit == null || tile.civilianUnit!!.owner == unit.owner)
}

private fun canAirUnitMoveTo(tile: TileInfo, unit: MapUnit): Boolean {
Expand Down

0 comments on commit 3e3ada8

Please sign in to comment.