From f80077a412c44b2d9c1a1d64c9ce6207786abb81 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 26 Jan 2019 22:39:48 +0200 Subject: [PATCH] Resolved #435 - profit from disbanding units --- android/assets/jsons/Translations.json | 2 ++ core/src/com/unciv/logic/map/MapUnit.kt | 6 ++++++ core/src/com/unciv/models/gamebasics/unit/BaseUnit.kt | 6 +++++- core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt | 7 +++++-- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/android/assets/jsons/Translations.json b/android/assets/jsons/Translations.json index 60378744..3eb93402 100644 --- a/android/assets/jsons/Translations.json +++ b/android/assets/jsons/Translations.json @@ -293,6 +293,8 @@ Portuguese:"Voçê realmente quer desfazer essa unidade?" German:"Wollen Sie diese Einheit wirklich auflösen?" } + "Disband this unit for [goldAmount] gold?":{} + "Yes":{ Italian:"Sì" Russian:"Да" diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index 910e4f28..d6830600 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -392,6 +392,12 @@ class MapUnit { civInfo.updateViewableTiles() } + fun disband(){ + destroy() + if(currentTile.isCityCenter() && currentTile.getOwner()==civInfo) + civInfo.gold += baseUnit.getDisbandGold() + } + private fun getAncientRuinBonus() { currentTile.improvement=null val actions: ArrayList<() -> Unit> = ArrayList() diff --git a/core/src/com/unciv/models/gamebasics/unit/BaseUnit.kt b/core/src/com/unciv/models/gamebasics/unit/BaseUnit.kt index f83c836f..e49c3151 100644 --- a/core/src/com/unciv/models/gamebasics/unit/BaseUnit.kt +++ b/core/src/com/unciv/models/gamebasics/unit/BaseUnit.kt @@ -87,12 +87,16 @@ class BaseUnit : INamed, IConstruction, ICivilopedia { override fun getProductionCost(adoptedPolicies: HashSet): Int = cost + fun getBaseGoldCost() = Math.pow((30 * cost).toDouble(), 0.75) * (1 + hurryCostModifier / 100) + override fun getGoldCost(adoptedPolicies: HashSet): Int { - var cost = Math.pow((30 * cost).toDouble(), 0.75) * (1 + hurryCostModifier / 100) + var cost = getBaseGoldCost() if(adoptedPolicies.contains("Militarism")) cost *= 0.66f return (cost / 10).toInt() * 10 // rounded down o nearest ten } + fun getDisbandGold() = getBaseGoldCost().toInt()/20 + fun isBuildable(civInfo:CivilizationInfo): Boolean { if (unbuildable) return false if (requiredTech!=null && !civInfo.tech.isResearched(requiredTech!!)) return false diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index fd68c723..0de35f75 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -200,8 +200,11 @@ class UnitActions { actionList += UnitAction("Disband unit",unit.currentMovement >0 ) { - YesNoPopupTable("Do you really want to disband this unit?".tr(), - {unit.destroy(); worldScreen.shouldUpdate=true} ) + val disbandText = if(unit.currentTile.getOwner()==unit.civInfo) + "Disband this unit for [${unit.baseUnit.getDisbandGold()}] gold?".tr() + else "Do you really want to disband this unit?".tr() + YesNoPopupTable(disbandText, + {unit.disband(); worldScreen.shouldUpdate=true} ) } return actionList