mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 06:51:30 -04:00
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:
parent
b87a3b9ace
commit
367e0b940d
@ -80,7 +80,9 @@ class LoadGameScreen(previousScreen:CameraStageBaseScreen) : PickerScreen(disabl
|
|||||||
loadFromClipboardButton.onClick {
|
loadFromClipboardButton.onClick {
|
||||||
try {
|
try {
|
||||||
val clipboardContentsString = Gdx.app.clipboard.contents.trim()
|
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)
|
val loadedGame = GameSaver.gameInfoFromString(decoded)
|
||||||
UncivGame.Current.loadGame(loadedGame)
|
UncivGame.Current.loadGame(loadedGame)
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
|
@ -320,13 +320,21 @@ object UnitActions {
|
|||||||
return UnitAction(UnitActionType.Upgrade,
|
return UnitAction(UnitActionType.Upgrade,
|
||||||
title = "Upgrade to [${upgradedUnit.name}] ([$goldCostOfUpgrade] gold)",
|
title = "Upgrade to [${upgradedUnit.name}] ([$goldCostOfUpgrade] gold)",
|
||||||
action = {
|
action = {
|
||||||
unit.civInfo.addGold(-goldCostOfUpgrade)
|
|
||||||
val unitTile = unit.getTile()
|
val unitTile = unit.getTile()
|
||||||
unit.destroy()
|
unit.destroy()
|
||||||
val newUnit = unit.civInfo.placeUnitNearTile(unitTile.position, upgradedUnit.name)!!
|
val newUnit = unit.civInfo.placeUnitNearTile(unitTile.position, upgradedUnit.name)
|
||||||
unit.copyStatisticsTo(newUnit)
|
|
||||||
|
|
||||||
|
/** 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
|
newUnit.currentMovement = 0f
|
||||||
|
}
|
||||||
}.takeIf {
|
}.takeIf {
|
||||||
isFree ||
|
isFree ||
|
||||||
(
|
(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user