mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-16 02:40:41 +07:00
Specialist information is now hybrid
This commit is contained in:
@ -252,19 +252,14 @@ class CityStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getStatsOfSpecialist(specialistName:String): Stats {
|
fun getStatsOfSpecialist(specialistName:String): Stats {
|
||||||
val stats = cityInfo.getRuleset().specialists[specialistName]!!.clone()
|
val specialist = cityInfo.getRuleset().specialists[specialistName]
|
||||||
|
if (specialist == null) return Stats()
|
||||||
|
val stats = specialist.clone()
|
||||||
for (unique in cityInfo.civInfo.getMatchingUniques("[] from every specialist"))
|
for (unique in cityInfo.civInfo.getMatchingUniques("[] from every specialist"))
|
||||||
stats.add(Stats.parse(unique.params[0]))
|
stats.add(Stats.parse(unique.params[0]))
|
||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getStatsFromSpecialists(specialists: Stats): Stats {
|
|
||||||
val stats = Stats()
|
|
||||||
for (entry in specialists.toHashMap().filter { it.value > 0 })
|
|
||||||
stats.add(getStatsOfSpecialist(entry.key) * entry.value)
|
|
||||||
return stats
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getStatsFromSpecialists(specialists: HashMap<String, Int>): Stats {
|
private fun getStatsFromSpecialists(specialists: HashMap<String, Int>): Stats {
|
||||||
val stats = Stats()
|
val stats = Stats()
|
||||||
for (entry in specialists.filter { it.value > 0 })
|
for (entry in specialists.filter { it.value > 0 })
|
||||||
|
@ -7,6 +7,8 @@ import com.unciv.models.stats.Stat
|
|||||||
import com.unciv.models.stats.Stats
|
import com.unciv.models.stats.Stats
|
||||||
import com.unciv.ui.utils.withItem
|
import com.unciv.ui.utils.withItem
|
||||||
import com.unciv.ui.utils.withoutItem
|
import com.unciv.ui.utils.withoutItem
|
||||||
|
import kotlin.math.floor
|
||||||
|
import kotlin.math.pow
|
||||||
|
|
||||||
class PopulationManager {
|
class PopulationManager {
|
||||||
@Transient
|
@Transient
|
||||||
@ -18,17 +20,13 @@ class PopulationManager {
|
|||||||
// Being deprecated out
|
// Being deprecated out
|
||||||
val specialists = Stats()
|
val specialists = Stats()
|
||||||
|
|
||||||
fun getNewSpecialists(): HashMap<String, Int> {
|
fun getNewSpecialists() = convertStatsToSpecialistHashmap(specialists)
|
||||||
|
|
||||||
|
fun convertStatsToSpecialistHashmap(stats: Stats):HashMap<String,Int> {
|
||||||
val specialistHashmap = HashMap<String, Int>()
|
val specialistHashmap = HashMap<String, Int>()
|
||||||
for ((stat, amount) in specialists.toHashMap()) {
|
for ((stat, amount) in stats.toHashMap()) {
|
||||||
if (amount == 0f) continue
|
if (amount == 0f) continue
|
||||||
val specialistName = when (stat) {
|
val specialistName = specialistNameByStat(stat)
|
||||||
Stat.Production -> "Engineer"
|
|
||||||
Stat.Gold -> "Merchant"
|
|
||||||
Stat.Science -> "Scientist"
|
|
||||||
Stat.Culture -> "Artist"
|
|
||||||
else -> TODO()
|
|
||||||
}
|
|
||||||
specialistHashmap[specialistName] = amount.toInt()
|
specialistHashmap[specialistName] = amount.toInt()
|
||||||
}
|
}
|
||||||
return specialistHashmap
|
return specialistHashmap
|
||||||
@ -43,9 +41,7 @@ class PopulationManager {
|
|||||||
return toReturn
|
return toReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getNumberOfSpecialists(): Int {
|
fun getNumberOfSpecialists() = getNewSpecialists().values.sum()
|
||||||
return getNewSpecialists().values.sum()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getFreePopulation(): Int {
|
fun getFreePopulation(): Int {
|
||||||
val workingPopulation = cityInfo.workedTiles.size
|
val workingPopulation = cityInfo.workedTiles.size
|
||||||
@ -54,7 +50,7 @@ class PopulationManager {
|
|||||||
|
|
||||||
fun getFoodToNextPopulation(): Int {
|
fun getFoodToNextPopulation(): Int {
|
||||||
// civ v math, civilization.wikia
|
// civ v math, civilization.wikia
|
||||||
var foodRequired = 15 + 6 * (population - 1) + Math.floor(Math.pow((population - 1).toDouble(), 1.8))
|
var foodRequired = 15 + 6 * (population - 1) + floor((population - 1).toDouble().pow(1.8))
|
||||||
if(!cityInfo.civInfo.isPlayerCivilization())
|
if(!cityInfo.civInfo.isPlayerCivilization())
|
||||||
foodRequired *= cityInfo.civInfo.gameInfo.getDifficulty().aiCityGrowthModifier
|
foodRequired *= cityInfo.civInfo.gameInfo.getDifficulty().aiCityGrowthModifier
|
||||||
return foodRequired.toInt()
|
return foodRequired.toInt()
|
||||||
@ -70,7 +66,7 @@ class PopulationManager {
|
|||||||
if (population > 1) population--
|
if (population > 1) population--
|
||||||
foodStored = 0
|
foodStored = 0
|
||||||
}
|
}
|
||||||
if (foodStored >= getFoodToNextPopulation()){ // growth!
|
if (foodStored >= getFoodToNextPopulation()) { // growth!
|
||||||
foodStored -= getFoodToNextPopulation()
|
foodStored -= getFoodToNextPopulation()
|
||||||
val percentOfFoodCarriedOver = cityInfo.cityConstructions.builtBuildingUniqueMap
|
val percentOfFoodCarriedOver = cityInfo.cityConstructions.builtBuildingUniqueMap
|
||||||
.getUniques("[]% of food is carried over after population increases")
|
.getUniques("[]% of food is carried over after population increases")
|
||||||
@ -84,6 +80,16 @@ class PopulationManager {
|
|||||||
|
|
||||||
internal fun getStatsOfSpecialist(stat: Stat) = cityInfo.cityStats.getStatsOfSpecialist(stat)
|
internal fun getStatsOfSpecialist(stat: Stat) = cityInfo.cityStats.getStatsOfSpecialist(stat)
|
||||||
|
|
||||||
|
internal fun getStatsOfSpecialist(name:String) = cityInfo.cityStats.getStatsOfSpecialist(name)
|
||||||
|
|
||||||
|
internal fun specialistNameByStat(stat: Stat) = when (stat) {
|
||||||
|
Stat.Production -> "Engineer"
|
||||||
|
Stat.Gold -> "Merchant"
|
||||||
|
Stat.Science -> "Scientist"
|
||||||
|
Stat.Culture -> "Artist"
|
||||||
|
else -> TODO()
|
||||||
|
}
|
||||||
|
|
||||||
// todo - change tile choice according to city!
|
// todo - change tile choice according to city!
|
||||||
// if small city, favor production above all, ignore gold!
|
// if small city, favor production above all, ignore gold!
|
||||||
// if larger city, food should be worth less!
|
// if larger city, food should be worth less!
|
||||||
@ -118,7 +124,7 @@ class PopulationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun unassignExtraPopulation() {
|
fun unassignExtraPopulation() {
|
||||||
for(tile in cityInfo.workedTiles.map { cityInfo.tileMap[it] }) {
|
for (tile in cityInfo.workedTiles.map { cityInfo.tileMap[it] }) {
|
||||||
if (tile.getOwner() != cityInfo.civInfo || tile.getWorkingCity() != cityInfo)
|
if (tile.getOwner() != cityInfo.civInfo || tile.getWorkingCity() != cityInfo)
|
||||||
cityInfo.workedTiles = cityInfo.workedTiles.withoutItem(tile.position)
|
cityInfo.workedTiles = cityInfo.workedTiles.withoutItem(tile.position)
|
||||||
if (tile.aerialDistanceTo(cityInfo.getCenterTile()) > 3)
|
if (tile.aerialDistanceTo(cityInfo.getCenterTile()) > 3)
|
||||||
@ -128,27 +134,29 @@ class PopulationManager {
|
|||||||
// unassign specialists that cannot be (e.g. the city was captured and one of the specialist buildings was destroyed)
|
// unassign specialists that cannot be (e.g. the city was captured and one of the specialist buildings was destroyed)
|
||||||
val maxSpecialists = getMaxSpecialists().toHashMap()
|
val maxSpecialists = getMaxSpecialists().toHashMap()
|
||||||
val specialistsHashmap = specialists.toHashMap()
|
val specialistsHashmap = specialists.toHashMap()
|
||||||
for(entry in maxSpecialists)
|
for (entry in maxSpecialists)
|
||||||
if(specialistsHashmap[entry.key]!! > entry.value)
|
if (specialistsHashmap[entry.key]!! > entry.value)
|
||||||
specialists.add(entry.key,maxSpecialists[entry.key]!! - specialistsHashmap[entry.key]!!)
|
specialists.add(entry.key, maxSpecialists[entry.key]!! - specialistsHashmap[entry.key]!!)
|
||||||
|
|
||||||
while (getFreePopulation()<0) {
|
while (getFreePopulation() < 0) {
|
||||||
//evaluate tiles
|
//evaluate tiles
|
||||||
val worstWorkedTile: TileInfo? = if(cityInfo.workedTiles.isEmpty()) null
|
val worstWorkedTile: TileInfo? = if (cityInfo.workedTiles.isEmpty()) null
|
||||||
else {
|
else {
|
||||||
cityInfo.workedTiles.asSequence()
|
cityInfo.workedTiles.asSequence()
|
||||||
.map { cityInfo.tileMap[it] }
|
.map { cityInfo.tileMap[it] }
|
||||||
.minBy { Automation.rankTileForCityWork(it, cityInfo)
|
.minBy {
|
||||||
+ (if(it.isLocked()) 10 else 0) }!!
|
Automation.rankTileForCityWork(it, cityInfo)
|
||||||
|
+(if (it.isLocked()) 10 else 0)
|
||||||
|
}!!
|
||||||
}
|
}
|
||||||
val valueWorstTile = if(worstWorkedTile==null) 0f
|
val valueWorstTile = if (worstWorkedTile == null) 0f
|
||||||
else Automation.rankTileForCityWork(worstWorkedTile, cityInfo)
|
else Automation.rankTileForCityWork(worstWorkedTile, cityInfo)
|
||||||
|
|
||||||
|
|
||||||
//evaluate specialists
|
//evaluate specialists
|
||||||
val worstJob: Stat? = specialists.toHashMap()
|
val worstJob: Stat? = specialists.toHashMap()
|
||||||
.filter { it.value > 0 }
|
.filter { it.value > 0 }
|
||||||
.map {it.key}
|
.map { it.key }
|
||||||
.minBy { Automation.rankSpecialist(getStatsOfSpecialist(it), cityInfo) }
|
.minBy { Automation.rankSpecialist(getStatsOfSpecialist(it), cityInfo) }
|
||||||
var valueWorstSpecialist = 0f
|
var valueWorstSpecialist = 0f
|
||||||
if (worstJob != null)
|
if (worstJob != null)
|
||||||
@ -158,9 +166,7 @@ class PopulationManager {
|
|||||||
if ((worstWorkedTile != null && valueWorstTile < valueWorstSpecialist)
|
if ((worstWorkedTile != null && valueWorstTile < valueWorstSpecialist)
|
||||||
|| worstJob == null) {
|
|| worstJob == null) {
|
||||||
cityInfo.workedTiles = cityInfo.workedTiles.withoutItem(worstWorkedTile!!.position)
|
cityInfo.workedTiles = cityInfo.workedTiles.withoutItem(worstWorkedTile!!.position)
|
||||||
} else {
|
} else specialists.add(worstJob, -1f)
|
||||||
specialists.add(worstJob, -1f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user