diff --git a/core/src/com/unciv/logic/civilization/PolicyManager.kt b/core/src/com/unciv/logic/civilization/PolicyManager.kt index e07b88b6c1..8ab5b39388 100644 --- a/core/src/com/unciv/logic/civilization/PolicyManager.kt +++ b/core/src/com/unciv/logic/civilization/PolicyManager.kt @@ -3,6 +3,7 @@ package com.unciv.logic.civilization import com.unciv.Constants import com.unciv.models.ruleset.Policy import com.unciv.models.ruleset.UniqueMap +import com.unciv.models.ruleset.UniqueTriggerActivation import com.unciv.models.ruleset.VictoryType import kotlin.math.min import kotlin.math.pow @@ -133,31 +134,8 @@ class PolicyManager { val hasCapital = civInfo.cities.any { it.isCapital() } for (unique in policy.uniqueObjects) - when (unique.placeholderText) { - "Free [] appears" -> { - val unitName = unique.params[0] - if (hasCapital && (unitName != Constants.settler || !civInfo.isOneCityChallenger())) - civInfo.addUnit(unitName, civInfo.getCapital()) - } - "Free Social Policy" -> freePolicies++ - "Empire enters golden age" -> - civInfo.goldenAges.enterGoldenAge() - "Free Great Person" -> { - if (civInfo.isPlayerCivilization()) civInfo.greatPeople.freeGreatPeople++ - else { - val preferredVictoryType = civInfo.victoryType() - val greatPerson = when (preferredVictoryType) { - VictoryType.Cultural -> "Great Artist" - VictoryType.Scientific -> "Great Scientist" - else -> - civInfo.gameInfo.ruleSet.units.keys.filter { it.startsWith("Great") }.random() - } - civInfo.addUnit(greatPerson) - } - } - "Quantity of strategic resources produced by the empire increased by 100%" -> civInfo.updateDetailedCivResources() - "+20% attack bonus to all Military Units for 30 turns" -> autocracyCompletedTurns = 30 - } + UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo) + tryAddLegalismBuildings() // This ALSO has the side-effect of updating the CivInfo statForNextTurn so we don't need to call it explicitly diff --git a/core/src/com/unciv/models/ruleset/Building.kt b/core/src/com/unciv/models/ruleset/Building.kt index c3d8543e6f..c6e13447c7 100644 --- a/core/src/com/unciv/models/ruleset/Building.kt +++ b/core/src/com/unciv/models/ruleset/Building.kt @@ -345,18 +345,16 @@ class Building : NamedStats(), IConstruction { if (providesFreeBuilding != null && !cityConstructions.containsBuildingOrEquivalent(providesFreeBuilding!!)) { var buildingToAdd = providesFreeBuilding!! - for(building in civInfo.gameInfo.ruleSet.buildings.values) - if(building.replaces == buildingToAdd && building.uniqueTo==civInfo.civName) + for (building in civInfo.gameInfo.ruleSet.buildings.values) + if (building.replaces == buildingToAdd && building.uniqueTo == civInfo.civName) buildingToAdd = building.name cityConstructions.addBuilding(buildingToAdd) } - if ("Empire enters golden age" in uniques) civInfo.goldenAges.enterGoldenAge() - for(unique in uniqueObjects.filter { it.placeholderText == "Free [] appears" }) { - val unitName = unique.params[0] - civInfo.addUnit(unitName, cityConstructions.cityInfo) - } + for (unique in uniqueObjects) + UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo) + if ("2 free Great Artists appear" in uniques) { civInfo.addUnit("Great Artist", cityConstructions.cityInfo) civInfo.addUnit("Great Artist", cityConstructions.cityInfo) @@ -369,23 +367,9 @@ class Building : NamedStats(), IConstruction { civInfo.addUnit(Constants.worker, cityConstructions.cityInfo) civInfo.addUnit(Constants.worker, cityConstructions.cityInfo) } - if ("Free Social Policy" in uniques) civInfo.policies.freePolicies++ - if ("Free Great Person" in uniques) { - if (civInfo.isPlayerCivilization()) civInfo.greatPeople.freeGreatPeople++ - else civInfo.addUnit(civInfo.gameInfo.ruleSet.units.keys.filter { it.startsWith("Great") }.random()) - } - if ("+1 population in each city" in uniques) { - for(city in civInfo.cities){ - city.population.population += 1 - city.population.autoAssignPopulation() - } - } if ("Enemy land units must spend 1 extra movement point when inside your territory (obsolete upon Dynamite)" in uniques) civInfo.updateHasActiveGreatWall() - if("Free Technology" in uniques) civInfo.tech.freeTechs += 1 - - cityConstructions.cityInfo.cityStats.update() // new building, new stats civInfo.updateDetailedCivResources() // this building/unit could be a resource-requiring one civInfo.transients().updateCitiesConnectedToCapital(false) // could be a connecting building, like a harbor diff --git a/core/src/com/unciv/models/ruleset/Ruleset.kt b/core/src/com/unciv/models/ruleset/Ruleset.kt index cb31ecb868..3b886b424b 100644 --- a/core/src/com/unciv/models/ruleset/Ruleset.kt +++ b/core/src/com/unciv/models/ruleset/Ruleset.kt @@ -247,6 +247,17 @@ object RulesetCache :HashMap() { println("${improvement.name} requires tech ${improvement.techRequired} which does not exist!") } + for (tech in modRuleset.technologies.values) { + for (prereq in tech.prerequisites) { + if (!modRuleset.technologies.containsKey(prereq)) + println("${tech.name} requires tech $prereq which does not exist!") + } + for (otherTech in tech.column!!.techs) { + if (tech != otherTech && otherTech.row == tech.row) + println("${tech.name} is in the same row as ${otherTech.name}!") + } + } + } fun getBaseRuleset() = this[BaseRuleset.Civ_V_Vanilla.fullName]!! diff --git a/core/src/com/unciv/models/ruleset/Unique.kt b/core/src/com/unciv/models/ruleset/Unique.kt index e4b5ad2354..ca78c1ea1d 100644 --- a/core/src/com/unciv/models/ruleset/Unique.kt +++ b/core/src/com/unciv/models/ruleset/Unique.kt @@ -1,5 +1,7 @@ package com.unciv.models.ruleset +import com.unciv.Constants +import com.unciv.logic.civilization.CivilizationInfo import com.unciv.models.translations.getPlaceholderParameters import com.unciv.models.translations.getPlaceholderText @@ -21,4 +23,43 @@ class UniqueMap:HashMap>() { } fun getAllUniques() = this.asSequence().flatMap { it.value.asSequence() } +} + +// Buildings and policies both have 'triggered' effects, and so may Techs in the future. +object UniqueTriggerActivation { + fun triggerCivwideUnique(unique: Unique, civInfo: CivilizationInfo) { + when (unique.placeholderText) { + "Free [] appears" -> { + val unitName = unique.params[0] + if (civInfo.cities.any { it.isCapital() } && (unitName != Constants.settler || !civInfo.isOneCityChallenger())) + civInfo.addUnit(unitName, civInfo.getCapital()) + } + "Free Social Policy" -> civInfo.policies.freePolicies++ + "Empire enters golden age" -> + civInfo.goldenAges.enterGoldenAge() + "Free Great Person" -> { + if (civInfo.isPlayerCivilization()) civInfo.greatPeople.freeGreatPeople++ + else { + val preferredVictoryType = civInfo.victoryType() + val greatPerson = when (preferredVictoryType) { + VictoryType.Cultural -> "Great Artist" + VictoryType.Scientific -> "Great Scientist" + else -> + civInfo.gameInfo.ruleSet.units.keys.filter { it.startsWith("Great") }.random() + } + civInfo.addUnit(greatPerson) + } + } + "+1 population in each city" -> + for (city in civInfo.cities) { + city.population.population += 1 + city.population.autoAssignPopulation() + } + "Free Technology" -> civInfo.tech.freeTechs += 1 + + "Quantity of strategic resources produced by the empire increased by 100%" -> civInfo.updateDetailedCivResources() + "+20% attack bonus to all Military Units for 30 turns" -> civInfo.policies.autocracyCompletedTurns = 30 + } + } + } \ No newline at end of file diff --git a/extraImages/GithubPreviewImage.png b/extraImages/GithubPreviewImage.png new file mode 100644 index 0000000000..1a42d11ce8 Binary files /dev/null and b/extraImages/GithubPreviewImage.png differ