mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-10 15:59:33 +07:00
Replaced hardcoded Settler references with unique
Tech uniques now saved in tech object for less regex parsing per turn
This commit is contained in:
@ -15,7 +15,7 @@
|
||||
"unitType": "Civilian",
|
||||
"movement": 2,
|
||||
"cost": 106,
|
||||
"uniques": ["Founds a new city"],
|
||||
"uniques": ["Founds a new city", "Excess Food converted to Production when under construction"],
|
||||
"hurryCostModifier": 20
|
||||
},
|
||||
{
|
||||
|
@ -18,6 +18,7 @@ class CityStats {
|
||||
|
||||
@Transient
|
||||
var baseStatList = LinkedHashMap<String, Stats>()
|
||||
|
||||
@Transient
|
||||
var statPercentBonusList = LinkedHashMap<String, Stats>()
|
||||
|
||||
@ -27,11 +28,13 @@ class CityStats {
|
||||
|
||||
@Transient
|
||||
var happinessList = LinkedHashMap<String, Float>()
|
||||
|
||||
@Transient
|
||||
var foodEaten = 0f
|
||||
|
||||
@Transient
|
||||
var currentCityStats: Stats = Stats() // This is so we won't have to calculate this multiple times - takes a lot of time, especially on phones
|
||||
|
||||
@Transient
|
||||
lateinit var cityInfo: CityInfo
|
||||
|
||||
@ -527,7 +530,9 @@ class CityStats {
|
||||
newFinalStatList["Maintenance"] = Stats().apply { gold -= buildingsMaintenance.toInt() }
|
||||
|
||||
|
||||
if (cityInfo.cityConstructions.currentConstructionFromQueue == Constants.settler && totalFood > 0) {
|
||||
val currentconstruction = cityInfo.cityConstructions.currentConstructionFromQueue
|
||||
if (totalFood > 0 && cityInfo.getRuleset().units[currentconstruction]
|
||||
.let { it != null && it.uniques.contains("Excess Food converted to Production when under construction") }) {
|
||||
newFinalStatList["Excess food to production"] =
|
||||
Stats().apply { production = totalFood; food = -totalFood }
|
||||
}
|
||||
@ -541,7 +546,7 @@ class CityStats {
|
||||
}
|
||||
|
||||
private fun updateFoodEaten() {
|
||||
foodEaten = (cityInfo.population.population * 2).toFloat()
|
||||
foodEaten = cityInfo.population.population.toFloat() * 2
|
||||
if (cityInfo.civInfo.hasUnique("-50% food consumption by specialists"))
|
||||
foodEaten -= cityInfo.population.getNumberOfSpecialists()
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ class CivilizationInfo {
|
||||
return nation.uniqueObjects.asSequence().filter { it.placeholderText == uniqueTemplate } +
|
||||
cities.asSequence().flatMap { it.cityConstructions.builtBuildingUniqueMap.getUniques(uniqueTemplate).asSequence() } +
|
||||
policies.policyUniques.getUniques(uniqueTemplate) +
|
||||
tech.getTechUniques()
|
||||
tech.getTechUniques().filter { it.placeholderText == uniqueTemplate }
|
||||
}
|
||||
|
||||
//region Units
|
||||
|
@ -122,7 +122,7 @@ class TechManager {
|
||||
return tech.prerequisites.all { isResearched(it) }
|
||||
}
|
||||
|
||||
fun getTechUniques() = researchedTechUniques
|
||||
fun getTechUniques() = researchedTechUniques.asSequence()
|
||||
|
||||
//endregion
|
||||
|
||||
@ -231,9 +231,9 @@ class TechManager {
|
||||
if (!newTech.isContinuallyResearchable())
|
||||
techsToResearch.remove(techName)
|
||||
researchedTechnologies = researchedTechnologies.withItem(newTech)
|
||||
for (unique in newTech.uniques) {
|
||||
researchedTechUniques = researchedTechUniques.withItem(Unique(unique))
|
||||
UniqueTriggerActivation.triggerCivwideUnique(Unique(unique), civInfo)
|
||||
for (unique in newTech.uniqueObjects) {
|
||||
researchedTechUniques = researchedTechUniques.withItem(unique)
|
||||
UniqueTriggerActivation.triggerCivwideUnique(unique, civInfo)
|
||||
}
|
||||
updateTransientBooleans()
|
||||
|
||||
@ -296,7 +296,7 @@ class TechManager {
|
||||
|
||||
fun setTransients() {
|
||||
researchedTechnologies.addAll(techsResearched.map { getRuleset().technologies[it]!! })
|
||||
researchedTechUniques.addAll(researchedTechnologies.asSequence().flatMap { it.uniques.asSequence() }.map { Unique(it) })
|
||||
researchedTechUniques.addAll(researchedTechnologies.asSequence().flatMap { it.uniqueObjects.asSequence() })
|
||||
updateTransientBooleans()
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import com.unciv.UncivGame
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.ruleset.Building
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.Unique
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.models.ruleset.unit.BaseUnit
|
||||
import java.util.*
|
||||
@ -15,6 +16,7 @@ class Technology {
|
||||
var cost: Int = 0
|
||||
var prerequisites = HashSet<String>()
|
||||
var uniques = ArrayList<String>()
|
||||
val uniqueObjects: List<Unique> by lazy { uniques.map { Unique(it) } }
|
||||
|
||||
var column: TechColumn? = null // The column that this tech is in the tech tree
|
||||
var row: Int = 0
|
||||
|
@ -67,7 +67,9 @@ class CityStatsTable(val cityScreen: CityScreen): Table() {
|
||||
when {
|
||||
cityInfo.isGrowing() -> "[${cityInfo.getNumTurnsToNewPopulation()}] turns to new population".tr()
|
||||
cityInfo.isStarving() -> "[${cityInfo.getNumTurnsToStarvation()}] turns to lose population".tr()
|
||||
cityInfo.cityConstructions.currentConstructionFromQueue == Constants.settler -> "Food converts to production".tr()
|
||||
cityInfo.getRuleset().units[cityInfo.cityConstructions.currentConstructionFromQueue]
|
||||
.let { it != null && it.uniques.contains("Excess Food converted to Production when under construction") }
|
||||
-> "Food converts to production".tr()
|
||||
else -> "Stopped population growth".tr()
|
||||
}
|
||||
turnsToPopString += " (" + cityInfo.population.foodStored + "/" + cityInfo.population.getFoodToNextPopulation() + ")"
|
||||
|
Reference in New Issue
Block a user