mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 22:06:05 -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)
|
cityState.removeProtectorCiv(player, forced = true)
|
||||||
}).row()
|
}).row()
|
||||||
}
|
}
|
||||||
AlertType.RecapturedCivilian -> {
|
AlertType.RecapturedCivilian -> addRecapturedCivilianTable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addRecapturedCivilianTable() {
|
||||||
val position = Vector2().fromString(popupAlert.value)
|
val position = Vector2().fromString(popupAlert.value)
|
||||||
val tile = worldScreen.gameInfo.tileMap[position]
|
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 originalOwner = worldScreen.gameInfo.getCivilization(capturedUnit.originalOwner!!)
|
||||||
val captor = worldScreen.viewingCiv
|
val captor = worldScreen.viewingCiv
|
||||||
|
|
||||||
@ -334,12 +342,14 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
|
|||||||
addSeparator()
|
addSeparator()
|
||||||
addGoodSizedLabel("The [${capturedUnit.name}] we liberated originally belonged to [${originalOwner.civName}]. They will be grateful if we return it to them.").row()
|
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()
|
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') {
|
responseTable.add(getCloseButton("Yes", 'y') {
|
||||||
// Return it to original owner
|
// Return it to original owner
|
||||||
val unitName = capturedUnit.baseUnit.name
|
val unitName = capturedUnit.baseUnit.name
|
||||||
capturedUnit.destroy()
|
capturedUnit.destroy()
|
||||||
val closestCity = originalOwner.cities.minByOrNull { it.getCenterTile().aerialDistanceTo(tile) }
|
val closestCity =
|
||||||
|
originalOwner.cities.minByOrNull { it.getCenterTile().aerialDistanceTo(tile) }
|
||||||
if (closestCity != null) {
|
if (closestCity != null) {
|
||||||
// Attempt to place the unit near their nearest city
|
// Attempt to place the unit near their nearest city
|
||||||
originalOwner.placeUnitNearTile(closestCity.location, unitName)
|
originalOwner.placeUnitNearTile(closestCity.location, unitName)
|
||||||
@ -349,7 +359,8 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
|
|||||||
originalOwner.getDiplomacyManager(captor).addInfluence(45f)
|
originalOwner.getDiplomacyManager(captor).addInfluence(45f)
|
||||||
} else if (originalOwner.isMajorCiv()) {
|
} else if (originalOwner.isMajorCiv()) {
|
||||||
// No extra bonus from doing it several times
|
// 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') {
|
responseTable.add(getCloseButton("No", 'n') {
|
||||||
@ -366,8 +377,6 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
|
|||||||
}).row()
|
}).row()
|
||||||
add(responseTable)
|
add(responseTable)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun addDestroyOption(destroyAction: () -> Unit) {
|
private fun addDestroyOption(destroyAction: () -> Unit) {
|
||||||
add("Destroy".toTextButton().onClick(function = destroyAction)).row()
|
add("Destroy".toTextButton().onClick(function = destroyAction)).row()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user