mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
Fixed rare bug where captured civilian disappears before you can return it
This commit is contained in:
parent
bd70500685
commit
9266ddc5d0
@ -323,10 +323,18 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
|
||||
cityState.removeProtectorCiv(player, forced = true)
|
||||
}).row()
|
||||
}
|
||||
AlertType.RecapturedCivilian -> {
|
||||
AlertType.RecapturedCivilian -> addRecapturedCivilianTable()
|
||||
}
|
||||
}
|
||||
|
||||
private fun addRecapturedCivilianTable() {
|
||||
val position = Vector2().fromString(popupAlert.value)
|
||||
val tile = worldScreen.gameInfo.tileMap[position]
|
||||
val capturedUnit = tile.civilianUnit!! // This has got to be it
|
||||
val capturedUnit = tile.civilianUnit // This has got to be it
|
||||
if (capturedUnit == null) { // the unit disappeared somehow? maybe a modded action?
|
||||
close()
|
||||
return
|
||||
}
|
||||
val originalOwner = worldScreen.gameInfo.getCivilization(capturedUnit.originalOwner!!)
|
||||
val captor = worldScreen.viewingCiv
|
||||
|
||||
@ -334,12 +342,14 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
|
||||
addSeparator()
|
||||
addGoodSizedLabel("The [${capturedUnit.name}] we liberated originally belonged to [${originalOwner.civName}]. They will be grateful if we return it to them.").row()
|
||||
val responseTable = Table()
|
||||
responseTable.defaults().pad(0f, 30f) // Small buttons, plenty of pad so we don't fat-finger it
|
||||
responseTable.defaults()
|
||||
.pad(0f, 30f) // Small buttons, plenty of pad so we don't fat-finger it
|
||||
responseTable.add(getCloseButton("Yes", 'y') {
|
||||
// Return it to original owner
|
||||
val unitName = capturedUnit.baseUnit.name
|
||||
capturedUnit.destroy()
|
||||
val closestCity = originalOwner.cities.minByOrNull { it.getCenterTile().aerialDistanceTo(tile) }
|
||||
val closestCity =
|
||||
originalOwner.cities.minByOrNull { it.getCenterTile().aerialDistanceTo(tile) }
|
||||
if (closestCity != null) {
|
||||
// Attempt to place the unit near their nearest city
|
||||
originalOwner.placeUnitNearTile(closestCity.location, unitName)
|
||||
@ -349,7 +359,8 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
|
||||
originalOwner.getDiplomacyManager(captor).addInfluence(45f)
|
||||
} else if (originalOwner.isMajorCiv()) {
|
||||
// No extra bonus from doing it several times
|
||||
originalOwner.getDiplomacyManager(captor).setModifier(DiplomaticModifiers.ReturnedCapturedUnits, 20f)
|
||||
originalOwner.getDiplomacyManager(captor)
|
||||
.setModifier(DiplomaticModifiers.ReturnedCapturedUnits, 20f)
|
||||
}
|
||||
})
|
||||
responseTable.add(getCloseButton("No", 'n') {
|
||||
@ -366,8 +377,6 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
|
||||
}).row()
|
||||
add(responseTable)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addDestroyOption(destroyAction: () -> Unit) {
|
||||
add("Destroy".toTextButton().onClick(function = destroyAction)).row()
|
||||
|
Loading…
x
Reference in New Issue
Block a user