Merged Building and Policy unique activations

Added Tech link checks for loaded mods
This commit is contained in:
Yair Morgenstern 2020-08-20 15:00:10 +03:00
parent e7c0710042
commit acf803de28
5 changed files with 60 additions and 46 deletions

View file

@ -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

View file

@ -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

View file

@ -247,6 +247,17 @@ object RulesetCache :HashMap<String,Ruleset>() {
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]!!

View file

@ -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<String, ArrayList<Unique>>() {
}
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
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 602 KiB