Resolved #3347 - units spawned by buildings are spawned in the city the building was built in

This commit is contained in:
Yair Morgenstern
2020-11-24 22:12:03 +02:00
parent eb0776005f
commit fd646f6b06
2 changed files with 21 additions and 31 deletions

View File

@ -9,6 +9,8 @@ import com.unciv.models.stats.NamedStats
import com.unciv.models.stats.Stat
import com.unciv.models.stats.Stats
import com.unciv.models.translations.tr
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.pow
@ -25,7 +27,7 @@ class Building : NamedStats(), IConstruction {
// Could have old specialist values of "gold", "science" etc - change them to the new specialist names
val counter = Counter<String>()
for ((entry, amount) in specialistSlots!!) {
val equivalentStat = Stat.values().firstOrNull { it.name.toLowerCase() == entry }
val equivalentStat = Stat.values().firstOrNull { it.name.toLowerCase(Locale.ENGLISH) == entry }
if (equivalentStat != null)
counter[Specialist.specialistNameByStat(equivalentStat)] = amount
@ -143,21 +145,22 @@ class Building : NamedStats(), IConstruction {
for (unique in civInfo.getMatchingUniques("[] from every []")) {
if (unique.params[1] != baseBuildingName) continue
stats.add(unique.stats!!)
stats.add(unique.stats)
}
for (unique in uniqueObjects)
if (unique.placeholderText == "[] with []" && civInfo.hasResource(unique.params[1]) && Stats.isStats(unique.params[0]))
stats.add(unique.stats!!)
if (unique.placeholderText == "[] with []" && civInfo.hasResource(unique.params[1])
&& Stats.isStats(unique.params[0]))
stats.add(unique.stats)
if (!isWonder)
for (unique in civInfo.getMatchingUniques("[] from all [] buildings")) {
if (isStatRelated(Stat.valueOf(unique.params[1])))
stats.add(unique.stats!!)
stats.add(unique.stats)
}
else
for (unique in civInfo.getMatchingUniques("[] from every Wonder"))
stats.add(unique.stats!!)
stats.add(unique.stats)
}
return stats
@ -367,22 +370,7 @@ class Building : NamedStats(), IConstruction {
}
for (unique in uniqueObjects)
UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo)
// ALL these are deprecated as of 3.10.10 and are currently here to not break mods relying on them
if ("2 free Great Artists appear" in uniques) {
civInfo.addUnit("Great Artist", cityConstructions.cityInfo)
civInfo.addUnit("Great Artist", cityConstructions.cityInfo)
}
if ("2 free great scientists appear" in uniques) {
civInfo.addUnit("Great Scientist", cityConstructions.cityInfo)
civInfo.addUnit("Great Scientist", cityConstructions.cityInfo)
}
if ("Provides 2 free workers" in uniques) {
civInfo.addUnit(Constants.worker, cityConstructions.cityInfo)
civInfo.addUnit(Constants.worker, cityConstructions.cityInfo)
}
UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo, cityConstructions.cityInfo)
if ("Enemy land units must spend 1 extra movement point when inside your territory (obsolete upon Dynamite)" in uniques)
civInfo.updateHasActiveGreatWall()
@ -404,7 +392,7 @@ class Building : NamedStats(), IConstruction {
}
fun getBaseBuilding(ruleset: Ruleset): Building {
if(replaces==null) return this
if (replaces == null) return this
else return ruleset.buildings[replaces!!]!!
}
}

View File

@ -1,6 +1,7 @@
package com.unciv.models.ruleset
import com.unciv.Constants
import com.unciv.logic.city.CityInfo
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.stats.Stats
import com.unciv.models.translations.getPlaceholderParameters
@ -35,18 +36,19 @@ class UniqueMap:HashMap<String, ArrayList<Unique>>() {
// Buildings, techs and policies can have 'triggered' effects
object UniqueTriggerActivation {
fun triggerCivwideUnique(unique: Unique, civInfo: CivilizationInfo) {
fun triggerCivwideUnique(unique: Unique, civInfo: CivilizationInfo, cityInfo:CityInfo?=null) {
val chosenCity = if(cityInfo!=null) cityInfo else civInfo.cities.firstOrNull { it.isCapital() }
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())
if (chosenCity != null && (unitName != Constants.settler || !civInfo.isOneCityChallenger()))
civInfo.addUnit(unitName, chosenCity)
}
"[] free [] units appear" -> {
val unitName = unique.params[1]
if (civInfo.cities.any { it.isCapital() } && (unitName != Constants.settler || !civInfo.isOneCityChallenger()))
if (chosenCity!=null && (unitName != Constants.settler || !civInfo.isOneCityChallenger()))
for (i in 1..unique.params[0].toInt())
civInfo.addUnit(unitName, civInfo.getCapital())
civInfo.addUnit(unitName, chosenCity)
}
// spectators get all techs at start of game, and if (in a mod) a tech gives a free policy, the game stucks on the policy picker screen
"Free Social Policy" -> if(!civInfo.isSpectator()) civInfo.policies.freePolicies++
@ -59,10 +61,10 @@ object UniqueTriggerActivation {
val greatPerson = when (preferredVictoryType) {
VictoryType.Cultural -> "Great Artist"
VictoryType.Scientific -> "Great Scientist"
else ->
civInfo.gameInfo.ruleSet.units.keys.filter { it.startsWith("Great") }.random()
else -> civInfo.gameInfo.ruleSet.units.values
.filter { it.uniqueObjects.any { it.placeholderText == "Great Person - []" } }.map { it.name }.random()
}
civInfo.addUnit(greatPerson)
civInfo.addUnit(greatPerson, chosenCity)
}
}
"+1 population in each city" ->