From 75a4f06d038985336360eba8f136a44048958186 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sat, 2 Dec 2023 22:45:18 +0200 Subject: [PATCH] Converted create/enhance religion actions to new format --- .../automation/unit/CivilianUnitAutomation.kt | 4 +-- .../civilization/managers/ReligionManager.kt | 19 +++++++------- .../worldscreen/unit/actions/UnitActions.kt | 6 ++--- .../unit/actions/UnitActionsReligion.kt | 25 ++++++++++--------- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/core/src/com/unciv/logic/automation/unit/CivilianUnitAutomation.kt b/core/src/com/unciv/logic/automation/unit/CivilianUnitAutomation.kt index fed8e78f93..a4bd0a61b8 100644 --- a/core/src/com/unciv/logic/automation/unit/CivilianUnitAutomation.kt +++ b/core/src/com/unciv/logic/automation/unit/CivilianUnitAutomation.kt @@ -51,7 +51,7 @@ object CivilianUnitAutomation { if (unit.hasUnique(UniqueType.MayEnhanceReligion) && unit.civ.religionManager.religionState < ReligionState.EnhancedReligion - && unit.civ.religionManager.mayEnhanceReligionAtAll(unit) + && unit.civ.religionManager.mayEnhanceReligionAtAll() ) return ReligiousUnitAutomation.enhanceReligion(unit) @@ -170,5 +170,5 @@ object CivilianUnitAutomation { ?: return // can't move anywhere! unit.movement.moveToTile(tileFurthestFromEnemy) } - + } diff --git a/core/src/com/unciv/logic/civilization/managers/ReligionManager.kt b/core/src/com/unciv/logic/civilization/managers/ReligionManager.kt index c4803adb6e..2997593632 100644 --- a/core/src/com/unciv/logic/civilization/managers/ReligionManager.kt +++ b/core/src/com/unciv/logic/civilization/managers/ReligionManager.kt @@ -5,6 +5,7 @@ import com.unciv.logic.IsPartOfGameInfoSerialization import com.unciv.logic.city.City import com.unciv.logic.civilization.Civilization import com.unciv.logic.map.mapunit.MapUnit +import com.unciv.logic.map.tile.Tile import com.unciv.models.Counter import com.unciv.models.Religion import com.unciv.models.ruleset.Belief @@ -271,16 +272,16 @@ class ReligionManager : IsPartOfGameInfoSerialization { return true } - fun mayFoundReligionNow(prophet: MapUnit): Boolean { + fun mayFoundReligionHere(tile: Tile): Boolean { if (!mayFoundReligionAtAll()) return false - if (!prophet.getTile().isCityCenter()) return false - if (prophet.getTile().getCity()!!.isHolyCity()) return false + if (!tile.isCityCenter()) return false + if (tile.getCity()!!.isHolyCity()) return false // No double holy cities. Not sure if these were allowed in the base game return true } fun foundReligion(prophet: MapUnit) { - if (!mayFoundReligionNow(prophet)) return // How did you do this? + if (!mayFoundReligionHere(prophet.getTile())) return // How did you do this? if (religionState == ReligionState.None) shouldChoosePantheonBelief = true religionState = ReligionState.FoundingReligion civInfo.religionManager.foundingCityId = prophet.getTile().getCity()!!.id @@ -289,7 +290,7 @@ class ReligionManager : IsPartOfGameInfoSerialization { UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo) } - fun mayEnhanceReligionAtAll(prophet: MapUnit): Boolean { + fun mayEnhanceReligionAtAll(): Boolean { if (!civInfo.gameInfo.isReligionEnabled()) return false if (religion == null) return false // First found a pantheon if (religionState != ReligionState.Religion) return false // First found an actual religion @@ -304,14 +305,14 @@ class ReligionManager : IsPartOfGameInfoSerialization { return true } - fun mayEnhanceReligionNow(prophet: MapUnit): Boolean { - if (!mayEnhanceReligionAtAll(prophet)) return false - if (!prophet.getTile().isCityCenter()) return false + fun mayEnhanceReligionHere(tile: Tile): Boolean { + if (!mayEnhanceReligionAtAll()) return false + if (!tile.isCityCenter()) return false return true } fun useProphetForEnhancingReligion(prophet: MapUnit) { - if (!mayEnhanceReligionNow(prophet)) return // How did you do this? + if (!mayEnhanceReligionHere(prophet.getTile())) return // How did you do this? religionState = ReligionState.EnhancingReligion for (unique in civInfo.getTriggeredUniques(UniqueType.TriggerUponEnhancingReligion)) 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 223f1dab93..24da90d4bd 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 @@ -43,7 +43,9 @@ object UnitActions { UnitActionType.HurryResearch to UnitActionsGreatPerson::getHurryResearchActions, UnitActionType.HurryWonder to UnitActionsGreatPerson::getHurryWonderActions, UnitActionType.HurryBuilding to UnitActionsGreatPerson::getHurryBuildingActions, - UnitActionType.ConductTradeMission to UnitActionsGreatPerson::getConductTradeMissionActions + UnitActionType.ConductTradeMission to UnitActionsGreatPerson::getConductTradeMissionActions, + UnitActionType.FoundReligion to UnitActionsReligion::getFoundReligionActions, + UnitActionType.EnhanceReligion to UnitActionsReligion::getEnhanceReligionActions ) private fun getNormalActions(unit: MapUnit): List { @@ -54,8 +56,6 @@ object UnitActions { actionList.addAll(getActionsFunction(unit, tile)) // Determined by unit uniques - UnitActionsReligion.addFoundReligionAction(unit, actionList) - UnitActionsReligion.addEnhanceReligionAction(unit, actionList) UnitActionsFromUniques.addCreateWaterImprovements(unit, actionList) actionList += UnitActionsFromUniques.getImprovementConstructionActions(unit, tile) UnitActionsReligion.addSpreadReligionActions(unit, actionList) diff --git a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsReligion.kt b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsReligion.kt index 3796ffd1f1..e406eedce6 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsReligion.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/unit/actions/UnitActionsReligion.kt @@ -3,6 +3,7 @@ package com.unciv.ui.screens.worldscreen.unit.actions import com.unciv.Constants import com.unciv.logic.civilization.NotificationCategory import com.unciv.logic.map.mapunit.MapUnit +import com.unciv.logic.map.tile.Tile import com.unciv.models.UnitAction import com.unciv.models.UnitActionType import com.unciv.models.ruleset.unique.UniqueTarget @@ -13,17 +14,17 @@ import com.unciv.ui.components.extensions.toPercent object UnitActionsReligion { - internal fun addFoundReligionAction(unit: MapUnit, actionList: ArrayList) { - if (!unit.civ.religionManager.mayFoundReligionAtAll()) return + internal fun getFoundReligionActions(unit: MapUnit, tile:Tile): List { + if (!unit.civ.religionManager.mayFoundReligionAtAll()) return listOf() val unique = UnitActionModifiers.getUsableUnitActionUniques(unit, UniqueType.MayFoundReligion) - .firstOrNull() ?: return + .firstOrNull() ?: return listOf() val hasActionModifiers = unique.conditionals.any { it.type?.targetTypes?.contains( UniqueTarget.UnitActionModifier ) == true } - actionList += UnitAction( + return listOf(UnitAction( UnitActionType.FoundReligion, if (hasActionModifiers) UnitActionModifiers.actionTextWithSideEffects( @@ -37,22 +38,22 @@ object UnitActionsReligion { if (hasActionModifiers) UnitActionModifiers.activateSideEffects(unit, unique) else unit.consume() - }.takeIf { unit.civ.religionManager.mayFoundReligionNow(unit) } - ) + }.takeIf { unit.civ.religionManager.mayFoundReligionHere(tile) } + )) } - internal fun addEnhanceReligionAction(unit: MapUnit, actionList: ArrayList) { - if (!unit.civ.religionManager.mayEnhanceReligionAtAll(unit)) return + internal fun getEnhanceReligionActions(unit: MapUnit, tile: Tile): List { + if (!unit.civ.religionManager.mayEnhanceReligionAtAll()) return listOf() val unique = UnitActionModifiers.getUsableUnitActionUniques(unit, UniqueType.MayEnhanceReligion) - .firstOrNull() ?: return + .firstOrNull() ?: return listOf() val hasActionModifiers = unique.conditionals.any { it.type?.targetTypes?.contains( UniqueTarget.UnitActionModifier ) == true } val baseTitle = "Enhance [${unit.civ.religionManager.religion!!.getReligionDisplayName()}]" - actionList += UnitAction( + return listOf(UnitAction( UnitActionType.EnhanceReligion, title = if (hasActionModifiers) UnitActionModifiers.actionTextWithSideEffects( baseTitle, @@ -64,8 +65,8 @@ object UnitActionsReligion { unit.civ.religionManager.useProphetForEnhancingReligion(unit) if (hasActionModifiers) UnitActionModifiers.activateSideEffects(unit, unique) else unit.consume() - }.takeIf { unit.civ.religionManager.mayEnhanceReligionNow(unit) } - ) + }.takeIf { unit.civ.religionManager.mayEnhanceReligionHere(tile) } + )) } private fun useActionWithLimitedUses(unit: MapUnit, action: String) {