From c48584868d8a5fe3a794953c754046eb796802df Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 2 Dec 2023 22:33:54 +0200 Subject: [PATCH] Converted Great Person actions to new format --- .../worldscreen/unit/actions/UnitActions.kt | 7 +- .../unit/actions/UnitActionsGreatPerson.kt | 180 +++++++++--------- 2 files changed, 98 insertions(+), 89 deletions(-) diff --git a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActions.kt b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActions.kt index 24f8559e5a..223f1dab93 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActions.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActions.kt @@ -39,7 +39,11 @@ object UnitActions { UnitActionType.SetUp to UnitActionsFromUniques::getSetupActions, UnitActionType.FoundCity to UnitActionsFromUniques::getFoundCityActions, UnitActionType.ConstructImprovement to UnitActionsFromUniques::getBuildingImprovementsActions, - UnitActionType.Repair to UnitActionsFromUniques::getRepairActions + UnitActionType.Repair to UnitActionsFromUniques::getRepairActions, + UnitActionType.HurryResearch to UnitActionsGreatPerson::getHurryResearchActions, + UnitActionType.HurryWonder to UnitActionsGreatPerson::getHurryWonderActions, + UnitActionType.HurryBuilding to UnitActionsGreatPerson::getHurryBuildingActions, + UnitActionType.ConductTradeMission to UnitActionsGreatPerson::getConductTradeMissionActions ) private fun getNormalActions(unit: MapUnit): List { @@ -50,7 +54,6 @@ object UnitActions { actionList.addAll(getActionsFunction(unit, tile)) // Determined by unit uniques - UnitActionsGreatPerson.addGreatPersonActions(unit, actionList, tile) UnitActionsReligion.addFoundReligionAction(unit, actionList) UnitActionsReligion.addEnhanceReligionAction(unit, actionList) UnitActionsFromUniques.addCreateWaterImprovements(unit, actionList) diff --git a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsGreatPerson.kt b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsGreatPerson.kt index 76569c9fa1..ad2aed18b9 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsGreatPerson.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsGreatPerson.kt @@ -13,94 +13,100 @@ import kotlin.math.min object UnitActionsGreatPerson { - internal fun addGreatPersonActions(unit: MapUnit, actionList: ArrayList, tile: Tile) { - - if (unit.currentMovement <= 0) return - for (unique in unit.getUniques()) when (unique.type) { - UniqueType.CanHurryResearch -> { - actionList += UnitAction( - UnitActionType.HurryResearch, - action = { - unit.civ.tech.addScience(unit.civ.tech.getScienceFromGreatScientist()) - unit.consume() - }.takeIf { unit.civ.tech.currentTechnologyName() != null - && !unit.civ.tech.currentTechnology()!!.hasUnique(UniqueType.CannotBeHurried) } - ) - } - UniqueType.CanSpeedupWonderConstruction -> { - val canHurryWonder = - if (!tile.isCityCenter()) false - else tile.getCity()!!.cityConstructions.isBuildingWonder() - && tile.getCity()!!.cityConstructions.canBeHurried() - - actionList += UnitAction( - UnitActionType.HurryWonder, - action = { - tile.getCity()!!.cityConstructions.apply { - //http://civilization.wikia.com/wiki/Great_engineer_(Civ5) - addProductionPoints(((300 + 30 * tile.getCity()!!.population.population) * unit.civ.gameInfo.speed.productionCostModifier).toInt()) - constructIfEnough() - } - - unit.consume() - }.takeIf { canHurryWonder } - ) - } - - UniqueType.CanSpeedupConstruction -> { - if (!tile.isCityCenter()) { - actionList += UnitAction(UnitActionType.HurryBuilding, action = null) - continue + fun getHurryResearchActions(unit:MapUnit, tile: Tile) = sequence { + for (unique in unit.getMatchingUniques(UniqueType.CanHurryResearch)){ + yield(UnitAction( + UnitActionType.HurryResearch, + action = { + unit.civ.tech.addScience(unit.civ.tech.getScienceFromGreatScientist()) + unit.consume() + }.takeIf { + unit.currentMovement > 0 + && unit.civ.tech.currentTechnologyName() != null + && !unit.civ.tech.currentTechnology()!!.hasUnique(UniqueType.CannotBeHurried) } - - val cityConstructions = tile.getCity()!!.cityConstructions - val canHurryConstruction = cityConstructions.getCurrentConstruction() is Building - && cityConstructions.canBeHurried() - - //http://civilization.wikia.com/wiki/Great_engineer_(Civ5) - val productionPointsToAdd = min( - (300 + 30 * tile.getCity()!!.population.population) * unit.civ.gameInfo.speed.productionCostModifier, - cityConstructions.getRemainingWork(cityConstructions.currentConstructionFromQueue).toFloat() - 1 - ).toInt() - if (productionPointsToAdd <= 0) continue - - actionList += UnitAction( - UnitActionType.HurryBuilding, - title = "Hurry Construction (+[$productionPointsToAdd]⚙)", - action = { - cityConstructions.apply { - addProductionPoints(productionPointsToAdd) - constructIfEnough() - } - - unit.consume() - }.takeIf { canHurryConstruction } - ) - } - UniqueType.CanTradeWithCityStateForGoldAndInfluence -> { - val canConductTradeMission = tile.owningCity?.civ?.isCityState() == true - && tile.owningCity?.civ != unit.civ - && tile.owningCity?.civ?.isAtWarWith(unit.civ) == false - val influenceEarned = unique.params[0].toFloat() - actionList += UnitAction( - UnitActionType.ConductTradeMission, - action = { - // http://civilization.wikia.com/wiki/Great_Merchant_(Civ5) - var goldEarned = (350 + 50 * unit.civ.getEraNumber()) * unit.civ.gameInfo.speed.goldCostModifier - for (goldUnique in unit.civ.getMatchingUniques(UniqueType.PercentGoldFromTradeMissions)) - goldEarned *= goldUnique.params[0].toPercent() - unit.civ.addGold(goldEarned.toInt()) - val tileOwningCiv = tile.owningCity!!.civ - - tileOwningCiv.getDiplomacyManager(unit.civ).addInfluence(influenceEarned) - unit.civ.addNotification("Your trade mission to [$tileOwningCiv] has earned you [$goldEarned] gold and [$influenceEarned] influence!", - NotificationCategory.General, tileOwningCiv.civName, NotificationIcon.Gold, NotificationIcon.Culture) - unit.consume() - }.takeIf { canConductTradeMission } - ) - } - else -> {} + )) } - } + }.asIterable() + fun getHurryWonderActions(unit: MapUnit, tile: Tile) = sequence { + for (unique in unit.getMatchingUniques(UniqueType.CanSpeedupWonderConstruction)) { + val canHurryWonder = + if (!tile.isCityCenter()) false + else tile.getCity()!!.cityConstructions.isBuildingWonder() + && tile.getCity()!!.cityConstructions.canBeHurried() + + yield(UnitAction( + UnitActionType.HurryWonder, + action = { + tile.getCity()!!.cityConstructions.apply { + //http://civilization.wikia.com/wiki/Great_engineer_(Civ5) + addProductionPoints(((300 + 30 * tile.getCity()!!.population.population) * unit.civ.gameInfo.speed.productionCostModifier).toInt()) + constructIfEnough() + } + + unit.consume() + }.takeIf { unit.currentMovement > 0 && canHurryWonder } + )) + } + }.asIterable() + + fun getHurryBuildingActions(unit:MapUnit, tile: Tile) = sequence { + for (unique in unit.getMatchingUniques(UniqueType.CanSpeedupConstruction)) { + if (!tile.isCityCenter()) { + yield(UnitAction(UnitActionType.HurryBuilding, action = null)) + continue + } + + val cityConstructions = tile.getCity()!!.cityConstructions + val canHurryConstruction = cityConstructions.getCurrentConstruction() is Building + && cityConstructions.canBeHurried() + + //http://civilization.wikia.com/wiki/Great_engineer_(Civ5) + val productionPointsToAdd = min( + (300 + 30 * tile.getCity()!!.population.population) * unit.civ.gameInfo.speed.productionCostModifier, + cityConstructions.getRemainingWork(cityConstructions.currentConstructionFromQueue).toFloat() - 1 + ).toInt() + if (productionPointsToAdd <= 0) continue + + yield(UnitAction( + UnitActionType.HurryBuilding, + title = "Hurry Construction (+[$productionPointsToAdd]⚙)", + action = { + cityConstructions.apply { + addProductionPoints(productionPointsToAdd) + constructIfEnough() + } + + unit.consume() + }.takeIf { unit.currentMovement > 0 && canHurryConstruction } + )) + } + }.asIterable() + + fun getConductTradeMissionActions(unit:MapUnit, tile: Tile) = sequence { + for (unique in unit.getMatchingUniques(UniqueType.CanTradeWithCityStateForGoldAndInfluence)) { + val canConductTradeMission = tile.owningCity?.civ?.isCityState() == true + && tile.owningCity?.civ != unit.civ + && tile.owningCity?.civ?.isAtWarWith(unit.civ) == false + val influenceEarned = unique.params[0].toFloat() + + yield(UnitAction( + UnitActionType.ConductTradeMission, + action = { + // http://civilization.wikia.com/wiki/Great_Merchant_(Civ5) + var goldEarned = (350 + 50 * unit.civ.getEraNumber()) * unit.civ.gameInfo.speed.goldCostModifier + for (goldUnique in unit.civ.getMatchingUniques(UniqueType.PercentGoldFromTradeMissions)) + goldEarned *= goldUnique.params[0].toPercent() + unit.civ.addGold(goldEarned.toInt()) + val tileOwningCiv = tile.owningCity!!.civ + + tileOwningCiv.getDiplomacyManager(unit.civ).addInfluence(influenceEarned) + unit.civ.addNotification("Your trade mission to [$tileOwningCiv] has earned you [$goldEarned] gold and [$influenceEarned] influence!", + NotificationCategory.General, tileOwningCiv.civName, NotificationIcon.Gold, NotificationIcon.Culture) + unit.consume() + }.takeIf { unit.currentMovement > 0 && canConductTradeMission } + )) + } + }.asIterable() }