mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-30 22:58:50 +07:00
Fixed rare bug where captured civilian disappears before you can return it
This commit is contained in:
@ -143,7 +143,7 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
|
||||
else {
|
||||
onClick(function = razeAction)
|
||||
keyPressDispatcher['r'] = razeAction
|
||||
}
|
||||
}
|
||||
}).row()
|
||||
addGoodSizedLabel("Razing the city annexes it, and starts razing the city to the ground.").row()
|
||||
addGoodSizedLabel("The population will gradually dwindle until the city is destroyed.").row()
|
||||
@ -323,52 +323,61 @@ class AlertPopup(val worldScreen: WorldScreen, val popupAlert: PopupAlert): Popu
|
||||
cityState.removeProtectorCiv(player, forced = true)
|
||||
}).row()
|
||||
}
|
||||
AlertType.RecapturedCivilian -> {
|
||||
val position = Vector2().fromString(popupAlert.value)
|
||||
val tile = worldScreen.gameInfo.tileMap[position]
|
||||
val capturedUnit = tile.civilianUnit!! // This has got to be it
|
||||
val originalOwner = worldScreen.gameInfo.getCivilization(capturedUnit.originalOwner!!)
|
||||
val captor = worldScreen.viewingCiv
|
||||
|
||||
addGoodSizedLabel("Return [${capturedUnit.name}] to [${originalOwner.civName}]?")
|
||||
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.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) }
|
||||
if (closestCity != null) {
|
||||
// Attempt to place the unit near their nearest city
|
||||
originalOwner.placeUnitNearTile(closestCity.location, unitName)
|
||||
}
|
||||
|
||||
if (originalOwner.isCityState()) {
|
||||
originalOwner.getDiplomacyManager(captor).addInfluence(45f)
|
||||
} else if (originalOwner.isMajorCiv()) {
|
||||
// No extra bonus from doing it several times
|
||||
originalOwner.getDiplomacyManager(captor).setModifier(DiplomaticModifiers.ReturnedCapturedUnits, 20f)
|
||||
}
|
||||
})
|
||||
responseTable.add(getCloseButton("No", 'n') {
|
||||
// Take it for ourselves
|
||||
// Settlers become workers at this point
|
||||
if (capturedUnit.hasUnique("Founds a new city")) {
|
||||
capturedUnit.destroy()
|
||||
// This is so that future checks which check if a unit has been captured are caught give the right answer
|
||||
// For example, in postBattleMoveToAttackedTile
|
||||
capturedUnit.civInfo = captor
|
||||
captor.placeUnitNearTile(tile.position, Constants.worker)
|
||||
} else
|
||||
capturedUnit.capturedBy(captor)
|
||||
}).row()
|
||||
add(responseTable)
|
||||
}
|
||||
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
|
||||
if (capturedUnit == null) { // the unit disappeared somehow? maybe a modded action?
|
||||
close()
|
||||
return
|
||||
}
|
||||
val originalOwner = worldScreen.gameInfo.getCivilization(capturedUnit.originalOwner!!)
|
||||
val captor = worldScreen.viewingCiv
|
||||
|
||||
addGoodSizedLabel("Return [${capturedUnit.name}] to [${originalOwner.civName}]?")
|
||||
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.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) }
|
||||
if (closestCity != null) {
|
||||
// Attempt to place the unit near their nearest city
|
||||
originalOwner.placeUnitNearTile(closestCity.location, unitName)
|
||||
}
|
||||
|
||||
if (originalOwner.isCityState()) {
|
||||
originalOwner.getDiplomacyManager(captor).addInfluence(45f)
|
||||
} else if (originalOwner.isMajorCiv()) {
|
||||
// No extra bonus from doing it several times
|
||||
originalOwner.getDiplomacyManager(captor)
|
||||
.setModifier(DiplomaticModifiers.ReturnedCapturedUnits, 20f)
|
||||
}
|
||||
})
|
||||
responseTable.add(getCloseButton("No", 'n') {
|
||||
// Take it for ourselves
|
||||
// Settlers become workers at this point
|
||||
if (capturedUnit.hasUnique("Founds a new city")) {
|
||||
capturedUnit.destroy()
|
||||
// This is so that future checks which check if a unit has been captured are caught give the right answer
|
||||
// For example, in postBattleMoveToAttackedTile
|
||||
capturedUnit.civInfo = captor
|
||||
captor.placeUnitNearTile(tile.position, Constants.worker)
|
||||
} else
|
||||
capturedUnit.capturedBy(captor)
|
||||
}).row()
|
||||
add(responseTable)
|
||||
}
|
||||
|
||||
private fun addDestroyOption(destroyAction: () -> Unit) {
|
||||
add("Destroy".toTextButton().onClick(function = destroyAction)).row()
|
||||
keyPressDispatcher['d'] = destroyAction
|
||||
|
Reference in New Issue
Block a user