From 15c4b67781070f8eb3fe7ca79ea2f032cc75ef2a Mon Sep 17 00:00:00 2001 From: Xander Lenstra <71121390+xlenstra@users.noreply.github.com> Date: Mon, 23 Aug 2021 19:21:28 +0200 Subject: [PATCH] Implemented a cap for the production boost of great engineers (#4966) * Implemented a cap for the production boost of great engineers * Added a hybrid solution * Adding production now shows the amount of production added --- .../assets/jsons/Civ V - Vanilla/Units.json | 2 +- .../jsons/translations/Dutch.properties | 1 + .../jsons/translations/template.properties | 2 + .../com/unciv/logic/city/CityConstructions.kt | 2 +- core/src/com/unciv/models/UnitAction.kt | 2 + .../unciv/ui/worldscreen/unit/UnitActions.kt | 48 +++++++++++++++---- 6 files changed, 47 insertions(+), 10 deletions(-) diff --git a/android/assets/jsons/Civ V - Vanilla/Units.json b/android/assets/jsons/Civ V - Vanilla/Units.json index f78a0e51c9..184cb3b551 100644 --- a/android/assets/jsons/Civ V - Vanilla/Units.json +++ b/android/assets/jsons/Civ V - Vanilla/Units.json @@ -1494,7 +1494,7 @@ { "name": "Great Engineer", "unitType": "Civilian", - "uniques": ["Can speed up construction of a wonder", "Can construct [Manufactory]", "Great Person - [Production]", "Unbuildable", "Uncapturable"], + "uniques": ["Can speed up construction of a building", "Can construct [Manufactory]", "Great Person - [Production]", "Unbuildable", "Uncapturable"], "movement": 2 }, { diff --git a/android/assets/jsons/translations/Dutch.properties b/android/assets/jsons/translations/Dutch.properties index f7925e59b2..cc8c594dbb 100644 --- a/android/assets/jsons/translations/Dutch.properties +++ b/android/assets/jsons/translations/Dutch.properties @@ -824,6 +824,7 @@ Hurry Research = Versnel Onderzoek Conduct Trade Mission = Voer handelsmissie uit Your trade mission to [civName] has earned you [goldAmount] gold and [influenceAmount] influence! = Jouw handelsmissie naar [civName] heeft je [goldAmount] goud en [influenceAmount] invloed opgeleverd! Hurry Wonder = Versnel Wonder +Hurry Construction = Versnel Constructie Spread Religion = Verkondig Religie Spread [religionName] = Verkondig [religionName] Found a Religion = Begin een religie diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index 53f010b296..ed9b35b416 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -731,6 +731,8 @@ Hurry Research = Conduct Trade Mission = Your trade mission to [civName] has earned you [goldAmount] gold and [influenceAmount] influence! = Hurry Wonder = +Hurry Construction = +Hurry Construction (+[productionAmount]) = Spread Religion = Spread [religionName] = Found a Religion = diff --git a/core/src/com/unciv/logic/city/CityConstructions.kt b/core/src/com/unciv/logic/city/CityConstructions.kt index 7849b2662a..3aa054b5d9 100644 --- a/core/src/com/unciv/logic/city/CityConstructions.kt +++ b/core/src/com/unciv/logic/city/CityConstructions.kt @@ -25,7 +25,7 @@ import kotlin.math.roundToInt * City constructions manager. * * @property cityInfo the city it refers to - * @property currentConstructionFromQueue the name of the construction is currently worked + * @property currentConstructionFromQueue name of the construction that is currently being produced * @property currentConstructionIsUserSet a flag indicating if the [currentConstructionFromQueue] has been set by the user or by the AI * @property constructionQueue a list of constructions names enqueued */ diff --git a/core/src/com/unciv/models/UnitAction.kt b/core/src/com/unciv/models/UnitAction.kt index 72bbd24f5d..10b6eb3318 100644 --- a/core/src/com/unciv/models/UnitAction.kt +++ b/core/src/com/unciv/models/UnitAction.kt @@ -122,6 +122,8 @@ enum class UnitActionType( { ImageGetter.getUnitIcon("Great Artist") }, 'g', UncivSound.Chimes), HurryWonder("Hurry Wonder", { ImageGetter.getUnitIcon("Great Engineer") }, 'g', UncivSound.Chimes), + HurryBuilding("Hurry Construction", + { ImageGetter.getUnitIcon("Great Engineer") }, 'g', UncivSound.Chimes), ConductTradeMission("Conduct Trade Mission", { ImageGetter.getUnitIcon("Great Merchant") }, 'g', UncivSound.Chimes), FoundReligion("Found a Religion", diff --git a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt index 5ec96070dc..9cd89ca745 100644 --- a/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt +++ b/core/src/com/unciv/ui/worldscreen/unit/UnitActions.kt @@ -22,6 +22,7 @@ import com.unciv.ui.pickerscreens.PromotionPickerScreen import com.unciv.ui.utils.YesNoPopup import com.unciv.ui.utils.hasOpenPopups import com.unciv.ui.worldscreen.WorldScreen +import kotlin.math.min object UnitActions { @@ -406,24 +407,55 @@ object UnitActions { }.takeIf { unit.currentTile.getOwner() != null && unit.currentTile.getOwner() == unit.civInfo } ) } - "Can speed up construction of a wonder" -> { - val canHurryWonder = if (!tile.isCityCenter()) false - else { - val currentConstruction = tile.getCity()!!.cityConstructions.getCurrentConstruction() - if (currentConstruction !is Building) false - else currentConstruction.isAnyWonder() - } + "Can speed up the construction of a wonder" -> { + val canHurryWonder = + if (!tile.isCityCenter()) false + else tile.getCity()!!.cityConstructions.isBuildingWonder() + + actionList += UnitAction(UnitActionType.HurryWonder, action = { tile.getCity()!!.cityConstructions.apply { - addProductionPoints(300 + 30 * tile.getCity()!!.population.population) //http://civilization.wikia.com/wiki/Great_engineer_(Civ5) + //http://civilization.wikia.com/wiki/Great_engineer_(Civ5) + addProductionPoints(((300 + 30 * tile.getCity()!!.population.population) * unit.civInfo.gameInfo.gameParameters.gameSpeed.modifier).toInt()) constructIfEnough() } + addGoldPerGreatPersonUsage(unit.civInfo) unit.destroy() }.takeIf { canHurryWonder } ) } + + "Can speed up construction of a building" -> { + if (!tile.isCityCenter()) { + actionList += UnitAction(UnitActionType.HurryBuilding, action = null) + continue + } + + val canHurryConstruction = tile.getCity()!!.cityConstructions.getCurrentConstruction() is Building + + val cityConstructions = tile.getCity()!!.cityConstructions + + //http://civilization.wikia.com/wiki/Great_engineer_(Civ5) + val productionPointsToAdd = min( + (300 + 30 * tile.getCity()!!.population.population) * unit.civInfo.gameInfo.gameParameters.gameSpeed.modifier, + cityConstructions.getRemainingWork(cityConstructions.currentConstructionFromQueue).toFloat() - 1 + ).toInt() + + actionList += UnitAction(UnitActionType.HurryBuilding, + title = "Hurry Construction (+[$productionPointsToAdd]⚙)", + action = { + cityConstructions.apply { + addProductionPoints(productionPointsToAdd) + constructIfEnough() + } + + addGoldPerGreatPersonUsage(unit.civInfo) + unit.destroy() + }.takeIf { canHurryConstruction } + ) + } "Can undertake a trade mission with City-State, giving a large sum of gold and [] Influence" -> { val canConductTradeMission = tile.owningCity?.civInfo?.isCityState() == true && tile.owningCity?.civInfo?.isAtWarWith(unit.civInfo) == false