More usage of existing Uniques
This commit is contained in:
parent
93435948d6
commit
97916e15a1
5 changed files with 38 additions and 38 deletions
|
@ -175,7 +175,6 @@ class CityStats {
|
|||
|
||||
// needs to be a separate function because we need to know the global happiness state
|
||||
// in order to determine how much food is produced in a city!
|
||||
// -3 happiness per city
|
||||
fun updateCityHappiness() {
|
||||
val civInfo = cityInfo.civInfo
|
||||
val newHappinessList = LinkedHashMap<String, Float>()
|
||||
|
@ -183,7 +182,7 @@ class CityStats {
|
|||
if (!civInfo.isPlayerCivilization())
|
||||
unhappinessModifier *= civInfo.gameInfo.getDifficulty().aiUnhappinessModifier
|
||||
|
||||
var unhappinessFromCity = -3f
|
||||
var unhappinessFromCity = -3f // -3 happiness per city
|
||||
if (civInfo.nation.unique == UniqueAbility.POPULATION_GROWTH)
|
||||
unhappinessFromCity *= 2f//doubled for the Indian
|
||||
|
||||
|
@ -217,9 +216,8 @@ class CityStats {
|
|||
happinessFromPolicies += 1f
|
||||
|
||||
if (cityInfo.getCenterTile().militaryUnit != null)
|
||||
for (unique in civInfo.policies.policyEffects)
|
||||
if (unique.equalsPlaceholderText("[] in all cities with a garrison"))
|
||||
happinessFromPolicies += Stats.parse(unique.getPlaceholderParameters()[0]).happiness
|
||||
for (unique in civInfo.getMatchingUniques("[] in all cities with a garrison"))
|
||||
happinessFromPolicies += Stats.parse(unique.params[0]).happiness
|
||||
|
||||
newHappinessList["Policies"] = happinessFromPolicies
|
||||
|
||||
|
|
|
@ -134,10 +134,10 @@ class PolicyManager {
|
|||
|
||||
val hasCapital = civInfo.cities.any { it.isCapital() }
|
||||
|
||||
for(effect in policy.uniques)
|
||||
when (effect.getPlaceholderText()) {
|
||||
for (unique in policy.uniqueObjects)
|
||||
when (unique.placeholderText) {
|
||||
"Free [] appears" -> {
|
||||
val unitName = effect.getPlaceholderParameters()[0]
|
||||
val unitName = unique.params[0]
|
||||
if (hasCapital && (unitName != Constants.settler || !civInfo.isOneCityChallenger()))
|
||||
civInfo.addUnit(unitName, civInfo.getCapital())
|
||||
}
|
||||
|
|
|
@ -7,31 +7,9 @@ import com.unciv.logic.civilization.CivilizationInfo
|
|||
import com.unciv.models.stats.NamedStats
|
||||
import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.stats.Stats
|
||||
import com.unciv.models.translations.equalsPlaceholderText
|
||||
import com.unciv.models.translations.getPlaceholderParameters
|
||||
import com.unciv.models.translations.getPlaceholderText
|
||||
import com.unciv.models.translations.tr
|
||||
import kotlin.math.pow
|
||||
|
||||
class Unique(val text:String){
|
||||
val placeholderText = text.getPlaceholderText()
|
||||
val params = text.getPlaceholderParameters()
|
||||
}
|
||||
|
||||
class UniqueMap:HashMap<String, ArrayList<Unique>>() {
|
||||
fun addUnique(unique: Unique) {
|
||||
if (!containsKey(unique.placeholderText)) this[unique.placeholderText] = ArrayList()
|
||||
this[unique.placeholderText]!!.add(unique)
|
||||
}
|
||||
|
||||
fun getUniques(placeholderText: String): List<Unique> {
|
||||
val result = this.get(placeholderText)
|
||||
if (result == null) return listOf()
|
||||
else return result
|
||||
}
|
||||
|
||||
fun getAllUniques() = this.asSequence().flatMap { it.value.asSequence() }
|
||||
}
|
||||
|
||||
class Building : NamedStats(), IConstruction {
|
||||
|
||||
|
@ -254,10 +232,10 @@ class Building : NamedStats(), IConstruction {
|
|||
|
||||
val cityCenter = construction.cityInfo.getCenterTile()
|
||||
|
||||
for(unique in uniques)
|
||||
if(unique.equalsPlaceholderText("Must be next to []")
|
||||
&& !cityCenter.getTilesInDistance(1).any { it.baseTerrain == unique.getPlaceholderParameters()[0] })
|
||||
return unique
|
||||
for(unique in uniqueObjects)
|
||||
if(unique.placeholderText == "Must be next to []"
|
||||
&& !cityCenter.getTilesInDistance(1).any { it.baseTerrain == unique.params[0] })
|
||||
return unique.text
|
||||
|
||||
if ("Must be next to river" in uniques && !cityCenter.isAdjacentToRiver())
|
||||
return "Must be next to river"
|
||||
|
@ -375,8 +353,8 @@ class Building : NamedStats(), IConstruction {
|
|||
}
|
||||
|
||||
if ("Empire enters golden age" in uniques) civInfo.goldenAges.enterGoldenAge()
|
||||
for(unique in uniques) if(unique.equalsPlaceholderText("Free [] appears")){
|
||||
val unitName = unique.getPlaceholderParameters()[0]
|
||||
for(unique in uniqueObjects.filter { it.placeholderText == "Free [] appears" }) {
|
||||
val unitName = unique.params[0]
|
||||
civInfo.addUnit(unitName, cityConstructions.cityInfo)
|
||||
}
|
||||
if ("2 free Great Artists appear" in uniques) {
|
||||
|
|
24
core/src/com/unciv/models/ruleset/Unique.kt
Normal file
24
core/src/com/unciv/models/ruleset/Unique.kt
Normal file
|
@ -0,0 +1,24 @@
|
|||
package com.unciv.models.ruleset
|
||||
|
||||
import com.unciv.models.translations.getPlaceholderParameters
|
||||
import com.unciv.models.translations.getPlaceholderText
|
||||
|
||||
class Unique(val text:String){
|
||||
val placeholderText = text.getPlaceholderText()
|
||||
val params = text.getPlaceholderParameters()
|
||||
}
|
||||
|
||||
class UniqueMap:HashMap<String, ArrayList<Unique>>() {
|
||||
fun addUnique(unique: Unique) {
|
||||
if (!containsKey(unique.placeholderText)) this[unique.placeholderText] = ArrayList()
|
||||
this[unique.placeholderText]!!.add(unique)
|
||||
}
|
||||
|
||||
fun getUniques(placeholderText: String): List<Unique> {
|
||||
val result = this.get(placeholderText)
|
||||
if (result == null) return listOf()
|
||||
else return result
|
||||
}
|
||||
|
||||
fun getAllUniques() = this.asSequence().flatMap { it.value.asSequence() }
|
||||
}
|
|
@ -107,7 +107,7 @@ class Translations : LinkedHashMap<String, TranslationEntry>(){
|
|||
targetTranslations: Translations = this) {
|
||||
for (translation in languageTranslations) {
|
||||
val hashKey = if (translation.key.contains('['))
|
||||
translation.key.replace(squareBraceRegex, "[]")
|
||||
translation.key.getPlaceholderText()
|
||||
else translation.key
|
||||
if (!containsKey(hashKey))
|
||||
targetTranslations[hashKey] = TranslationEntry(translation.key)
|
||||
|
@ -241,7 +241,7 @@ fun String.tr(): String {
|
|||
*/
|
||||
|
||||
// Convert "work on [building] has completed in [city]" to "work on [] has completed in []"
|
||||
val translationStringWithSquareBracketsOnly = this.replace(squareBraceRegex, "[]")
|
||||
val translationStringWithSquareBracketsOnly = this.getPlaceholderText()
|
||||
// That is now the key into the translation HashMap!
|
||||
val translationEntry = UncivGame.Current.translations
|
||||
.get(translationStringWithSquareBracketsOnly, UncivGame.Current.settings.language, activeMods)
|
||||
|
|
Loading…
Reference in a new issue