From 827a6f787172e63bdb8dd4c6351cb9095a03cafc Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 5 Jun 2019 23:14:52 +0300 Subject: [PATCH] Fixed bug where injured units would try to heal by pillaging barbarian encampments --- .../ui/pickerscreens/PromotionPickerScreen.kt | 21 ++++++++++--------- .../optionstable/WorldScreenOptionsTable.kt | 2 +- .../unciv/ui/worldscreen/unit/UnitActions.kt | 2 ++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt b/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt index ec09972d08..4bf0a02a5e 100644 --- a/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/PromotionPickerScreen.kt @@ -14,25 +14,26 @@ import com.unciv.models.gamebasics.tr import com.unciv.models.gamebasics.unit.Promotion import com.unciv.ui.utils.* -class PromotionPickerScreen(mapUnit: MapUnit) : PickerScreen() { +class PromotionPickerScreen(val mapUnit: MapUnit) : PickerScreen() { private var selectedPromotion: Promotion? = null + fun acceptPromotion(promotion: Promotion?) { + mapUnit.promotions.addPromotion(promotion!!.name) + if(mapUnit.promotions.canBePromoted()) game.screen = PromotionPickerScreen(mapUnit) + else game.setWorldScreen() + dispose() + game.worldScreen.shouldUpdate=true + } + init { onBackButtonClicked { UnCivGame.Current.setWorldScreen() } setDefaultCloseAction() - fun accept(promotion: Promotion?) { - mapUnit.promotions.addPromotion(promotion!!.name) - if(mapUnit.promotions.canBePromoted()) game.screen = PromotionPickerScreen(mapUnit) - else game.setWorldScreen() - dispose() - game.worldScreen.shouldUpdate=true - } rightSideButton.setText("Pick promotion".tr()) rightSideButton.onClick("promote") { - accept(selectedPromotion) + acceptPromotion(selectedPromotion) } val availablePromotionsGroup = VerticalGroup() @@ -76,7 +77,7 @@ class PromotionPickerScreen(mapUnit: MapUnit) : PickerScreen() { val pickNow = "Pick now!".toLabel() pickNow.setAlignment(Align.center) pickNow.onClick { - accept(promotion) + acceptPromotion(promotion) } diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt index 8d566dd039..6e21039690 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt @@ -75,7 +75,7 @@ class WorldScreenOptionsTable(screen:WorldScreen) : PopupTable(screen){ add("Version".toLabel()) add(UnCivGame.Current.version.toLabel()).row() - addButton("Close"){ remove() } + addButton("Close"){ remove() }.colspan(2) pack() // Needed to show the background. center(UnCivGame.Current.worldScreen.stage) diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index a1c07b06d3..f210cf8fb6 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -1,6 +1,7 @@ package com.unciv.ui.worldscreen.unit import com.badlogic.gdx.graphics.Color +import com.unciv.Constants import com.unciv.UnCivGame import com.unciv.logic.automation.UnitAutomation import com.unciv.logic.automation.WorkerAutomation @@ -257,6 +258,7 @@ class UnitActions { } fun canPillage(unit: MapUnit, tile: TileInfo): Boolean { + if(tile.improvement==null || tile.improvement==Constants.barbarianEncampment) return false val tileOwner = tile.getOwner() // Can't pillage friendly tiles, just like you can't attack them - it's an 'act of war' thing return tileOwner==null || tileOwner==unit.civInfo || unit.civInfo.isAtWarWith(tileOwner)