Solved bug where land units that upgrade to water units would attempt to upgrade where the upgraded unit could not be placed.

This was such a cool idea that I decided to let it live :)
This commit is contained in:
yairm210 2021-11-08 21:35:11 +02:00
parent b87a3b9ace
commit 367e0b940d
2 changed files with 16 additions and 6 deletions

View File

@ -80,7 +80,9 @@ class LoadGameScreen(previousScreen:CameraStageBaseScreen) : PickerScreen(disabl
loadFromClipboardButton.onClick {
try {
val clipboardContentsString = Gdx.app.clipboard.contents.trim()
val decoded = Gzip.unzip(clipboardContentsString)
val decoded =
if (clipboardContentsString.startsWith("{")) clipboardContentsString
else Gzip.unzip(clipboardContentsString)
val loadedGame = GameSaver.gameInfoFromString(decoded)
UncivGame.Current.loadGame(loadedGame)
} catch (ex: Exception) {

View File

@ -320,13 +320,21 @@ object UnitActions {
return UnitAction(UnitActionType.Upgrade,
title = "Upgrade to [${upgradedUnit.name}] ([$goldCostOfUpgrade] gold)",
action = {
unit.civInfo.addGold(-goldCostOfUpgrade)
val unitTile = unit.getTile()
unit.destroy()
val newUnit = unit.civInfo.placeUnitNearTile(unitTile.position, upgradedUnit.name)!!
unit.copyStatisticsTo(newUnit)
newUnit.currentMovement = 0f
val newUnit = unit.civInfo.placeUnitNearTile(unitTile.position, upgradedUnit.name)
/** We were UNABLE to place the new unit, which means that the unit failed to upgrade!
* The only known cause of this currently is "land units upgrading to water units" which fail to be placed.
*/
if (newUnit == null) {
val readdedUnit = unit.civInfo.placeUnitNearTile(unitTile.position, unit.name)
unit.copyStatisticsTo(readdedUnit!!)
} else { // Managed to upgrade
unit.civInfo.addGold(-goldCostOfUpgrade)
unit.copyStatisticsTo(newUnit)
newUnit.currentMovement = 0f
}
}.takeIf {
isFree ||
(