mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 06:16:37 -04:00
Fix unit being captured two times (#7141)
This commit is contained in:
parent
9ffd9b817b
commit
c3268126ee
@ -348,9 +348,12 @@ object Battle {
|
|||||||
addedUnit.currentMovement = 0f
|
addedUnit.currentMovement = 0f
|
||||||
addedUnit.health = 50
|
addedUnit.health = 50
|
||||||
attacker.getCivInfo().addNotification(notification, addedUnit.getTile().position, attacker.getName(), unitName)
|
attacker.getCivInfo().addNotification(notification, addedUnit.getTile().position, attacker.getName(), unitName)
|
||||||
// Also capture any civilians on the same tile
|
|
||||||
if (tile.civilianUnit != null)
|
val civilianUnit = tile.civilianUnit
|
||||||
captureCivilianUnit(attacker, MapUnitCombatant(tile.civilianUnit!!))
|
// placeUnitNearTile might not have spawned the unit in exactly this tile, in which case no capture would have happened on this tile. So we need to do that here.
|
||||||
|
if (addedUnit.getTile() != tile && civilianUnit != null) {
|
||||||
|
captureCivilianUnit(attacker, MapUnitCombatant(civilianUnit))
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -559,7 +562,14 @@ object Battle {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws IllegalArgumentException if the [attacker] and [defender] belong to the same civ.
|
||||||
|
*/
|
||||||
fun captureCivilianUnit(attacker: ICombatant, defender: MapUnitCombatant, checkDefeat: Boolean = true) {
|
fun captureCivilianUnit(attacker: ICombatant, defender: MapUnitCombatant, checkDefeat: Boolean = true) {
|
||||||
|
if (attacker.getCivInfo() == defender.getCivInfo()) {
|
||||||
|
throw IllegalArgumentException("Can't capture our own unit!")
|
||||||
|
}
|
||||||
|
|
||||||
// need to save this because if the unit is captured its owner wil be overwritten
|
// need to save this because if the unit is captured its owner wil be overwritten
|
||||||
val defenderCiv = defender.getCivInfo()
|
val defenderCiv = defender.getCivInfo()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user