mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 23:10:39 -04:00
More usage of existing Uniques
This commit is contained in:
parent
93435948d6
commit
97916e15a1
@ -175,7 +175,6 @@ class CityStats {
|
|||||||
|
|
||||||
// needs to be a separate function because we need to know the global happiness state
|
// 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!
|
// in order to determine how much food is produced in a city!
|
||||||
// -3 happiness per city
|
|
||||||
fun updateCityHappiness() {
|
fun updateCityHappiness() {
|
||||||
val civInfo = cityInfo.civInfo
|
val civInfo = cityInfo.civInfo
|
||||||
val newHappinessList = LinkedHashMap<String, Float>()
|
val newHappinessList = LinkedHashMap<String, Float>()
|
||||||
@ -183,7 +182,7 @@ class CityStats {
|
|||||||
if (!civInfo.isPlayerCivilization())
|
if (!civInfo.isPlayerCivilization())
|
||||||
unhappinessModifier *= civInfo.gameInfo.getDifficulty().aiUnhappinessModifier
|
unhappinessModifier *= civInfo.gameInfo.getDifficulty().aiUnhappinessModifier
|
||||||
|
|
||||||
var unhappinessFromCity = -3f
|
var unhappinessFromCity = -3f // -3 happiness per city
|
||||||
if (civInfo.nation.unique == UniqueAbility.POPULATION_GROWTH)
|
if (civInfo.nation.unique == UniqueAbility.POPULATION_GROWTH)
|
||||||
unhappinessFromCity *= 2f//doubled for the Indian
|
unhappinessFromCity *= 2f//doubled for the Indian
|
||||||
|
|
||||||
@ -217,9 +216,8 @@ class CityStats {
|
|||||||
happinessFromPolicies += 1f
|
happinessFromPolicies += 1f
|
||||||
|
|
||||||
if (cityInfo.getCenterTile().militaryUnit != null)
|
if (cityInfo.getCenterTile().militaryUnit != null)
|
||||||
for (unique in civInfo.policies.policyEffects)
|
for (unique in civInfo.getMatchingUniques("[] in all cities with a garrison"))
|
||||||
if (unique.equalsPlaceholderText("[] in all cities with a garrison"))
|
happinessFromPolicies += Stats.parse(unique.params[0]).happiness
|
||||||
happinessFromPolicies += Stats.parse(unique.getPlaceholderParameters()[0]).happiness
|
|
||||||
|
|
||||||
newHappinessList["Policies"] = happinessFromPolicies
|
newHappinessList["Policies"] = happinessFromPolicies
|
||||||
|
|
||||||
|
@ -134,10 +134,10 @@ class PolicyManager {
|
|||||||
|
|
||||||
val hasCapital = civInfo.cities.any { it.isCapital() }
|
val hasCapital = civInfo.cities.any { it.isCapital() }
|
||||||
|
|
||||||
for(effect in policy.uniques)
|
for (unique in policy.uniqueObjects)
|
||||||
when (effect.getPlaceholderText()) {
|
when (unique.placeholderText) {
|
||||||
"Free [] appears" -> {
|
"Free [] appears" -> {
|
||||||
val unitName = effect.getPlaceholderParameters()[0]
|
val unitName = unique.params[0]
|
||||||
if (hasCapital && (unitName != Constants.settler || !civInfo.isOneCityChallenger()))
|
if (hasCapital && (unitName != Constants.settler || !civInfo.isOneCityChallenger()))
|
||||||
civInfo.addUnit(unitName, civInfo.getCapital())
|
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.NamedStats
|
||||||
import com.unciv.models.stats.Stat
|
import com.unciv.models.stats.Stat
|
||||||
import com.unciv.models.stats.Stats
|
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 com.unciv.models.translations.tr
|
||||||
import kotlin.math.pow
|
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 {
|
class Building : NamedStats(), IConstruction {
|
||||||
|
|
||||||
@ -254,10 +232,10 @@ class Building : NamedStats(), IConstruction {
|
|||||||
|
|
||||||
val cityCenter = construction.cityInfo.getCenterTile()
|
val cityCenter = construction.cityInfo.getCenterTile()
|
||||||
|
|
||||||
for(unique in uniques)
|
for(unique in uniqueObjects)
|
||||||
if(unique.equalsPlaceholderText("Must be next to []")
|
if(unique.placeholderText == "Must be next to []"
|
||||||
&& !cityCenter.getTilesInDistance(1).any { it.baseTerrain == unique.getPlaceholderParameters()[0] })
|
&& !cityCenter.getTilesInDistance(1).any { it.baseTerrain == unique.params[0] })
|
||||||
return unique
|
return unique.text
|
||||||
|
|
||||||
if ("Must be next to river" in uniques && !cityCenter.isAdjacentToRiver())
|
if ("Must be next to river" in uniques && !cityCenter.isAdjacentToRiver())
|
||||||
return "Must be next to river"
|
return "Must be next to river"
|
||||||
@ -375,8 +353,8 @@ class Building : NamedStats(), IConstruction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ("Empire enters golden age" in uniques) civInfo.goldenAges.enterGoldenAge()
|
if ("Empire enters golden age" in uniques) civInfo.goldenAges.enterGoldenAge()
|
||||||
for(unique in uniques) if(unique.equalsPlaceholderText("Free [] appears")){
|
for(unique in uniqueObjects.filter { it.placeholderText == "Free [] appears" }) {
|
||||||
val unitName = unique.getPlaceholderParameters()[0]
|
val unitName = unique.params[0]
|
||||||
civInfo.addUnit(unitName, cityConstructions.cityInfo)
|
civInfo.addUnit(unitName, cityConstructions.cityInfo)
|
||||||
}
|
}
|
||||||
if ("2 free Great Artists appear" in uniques) {
|
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) {
|
targetTranslations: Translations = this) {
|
||||||
for (translation in languageTranslations) {
|
for (translation in languageTranslations) {
|
||||||
val hashKey = if (translation.key.contains('['))
|
val hashKey = if (translation.key.contains('['))
|
||||||
translation.key.replace(squareBraceRegex, "[]")
|
translation.key.getPlaceholderText()
|
||||||
else translation.key
|
else translation.key
|
||||||
if (!containsKey(hashKey))
|
if (!containsKey(hashKey))
|
||||||
targetTranslations[hashKey] = TranslationEntry(translation.key)
|
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 []"
|
// 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!
|
// That is now the key into the translation HashMap!
|
||||||
val translationEntry = UncivGame.Current.translations
|
val translationEntry = UncivGame.Current.translations
|
||||||
.get(translationStringWithSquareBracketsOnly, UncivGame.Current.settings.language, activeMods)
|
.get(translationStringWithSquareBracketsOnly, UncivGame.Current.settings.language, activeMods)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user