mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-13 01:08:25 +07:00
Fix off-by-one error in autoAssignPopulation (#9411)
* Fix off-by-one error in autoAssignPopulation * Fix more off-by-one errors from for-repeat conversions * Linting: Use Actions.forever shortcut where appropriate
This commit is contained in:
@ -688,7 +688,7 @@ object NextTurnAutomation {
|
||||
// not have used a great prophet to found/enhance our religion.
|
||||
for (belief in BeliefType.values()) {
|
||||
if (belief == BeliefType.None) continue
|
||||
repeat((beliefsToChoose[belief] ?: 0) - 1) {
|
||||
repeat(beliefsToChoose[belief] ?: 0) {
|
||||
chosenBeliefs.add(
|
||||
chooseBeliefOfType(civInfo, belief, chosenBeliefs) ?: return@repeat
|
||||
)
|
||||
|
@ -154,42 +154,37 @@ class CityPopulationManager : IsPartOfGameInfoSerialization {
|
||||
specialistFoodBonus *= unique.params[0].toPercent()
|
||||
specialistFoodBonus = 2f - specialistFoodBonus
|
||||
|
||||
val currentCiv = city.civ
|
||||
|
||||
val tilesToEvaluate = city.getCenterTile().getTilesInDistance(3)
|
||||
.filter { it.getOwner() == currentCiv && !it.isBlockaded() }.toList().asSequence()
|
||||
val tilesToEvaluate = city.getWorkableTiles()
|
||||
.filter { !it.isBlockaded() }.toList().asSequence()
|
||||
|
||||
val localUniqueCache = LocalUniqueCache()
|
||||
repeat(getFreePopulation() - 1) {
|
||||
repeat(getFreePopulation()) {
|
||||
//evaluate tiles
|
||||
val (bestTile, valueBestTile) = tilesToEvaluate
|
||||
val bestTileAndRank = tilesToEvaluate
|
||||
.filterNot { it.providesYield() }
|
||||
.associateWith { Automation.rankTileForCityWork(it, city, cityStats, localUniqueCache) }
|
||||
.maxByOrNull { it.value }
|
||||
?: object : Map.Entry<Tile?, Float> {
|
||||
override val key: Tile? = null
|
||||
override val value = 0f
|
||||
}
|
||||
val bestTile = bestTileAndRank?.key
|
||||
val valueBestTile = bestTileAndRank?.value ?: 0f
|
||||
|
||||
val bestJob: String? = if (city.manualSpecialists) null else getMaxSpecialists()
|
||||
val bestJobAndRank = if (city.manualSpecialists) null
|
||||
else getMaxSpecialists().asSequence()
|
||||
.filter { specialistAllocations[it.key]!! < it.value }
|
||||
.map { it.key }
|
||||
.maxByOrNull { Automation.rankSpecialist(it, city, cityStats, localUniqueCache) }
|
||||
|
||||
var valueBestSpecialist = 0f
|
||||
if (bestJob != null) {
|
||||
valueBestSpecialist = Automation.rankSpecialist(bestJob, city, cityStats, localUniqueCache)
|
||||
}
|
||||
.associateWith { Automation.rankSpecialist(it, city, cityStats, localUniqueCache) }
|
||||
.maxByOrNull { it.value }
|
||||
val bestJob = bestJobAndRank?.key
|
||||
val valueBestSpecialist = bestJobAndRank?.value ?: 0f
|
||||
|
||||
//assign population
|
||||
if (valueBestTile > valueBestSpecialist) {
|
||||
if (bestTile != null) {
|
||||
city.workedTiles = city.workedTiles.withItem(bestTile.position)
|
||||
cityStats[Stat.Food] += bestTile.stats.getTileStats(city, city.civ, localUniqueCache)[Stat.Food]
|
||||
cityStats.food += bestTile.stats.getTileStats(city, city.civ, localUniqueCache).food
|
||||
}
|
||||
} else if (bestJob != null) {
|
||||
specialistAllocations.add(bestJob, 1)
|
||||
cityStats[Stat.Food] += specialistFoodBonus
|
||||
cityStats.food += specialistFoodBonus
|
||||
}
|
||||
}
|
||||
city.cityStats.update()
|
||||
|
@ -46,7 +46,7 @@ object Perlin {
|
||||
var amp = 1.0
|
||||
var max = 0.0
|
||||
var total = 0.0
|
||||
repeat(nOctaves - 1) {
|
||||
repeat(nOctaves) {
|
||||
total += amp * noise(x * freq / scale, y * freq / scale, z * freq / scale)
|
||||
max += amp
|
||||
freq *= lacunarity
|
||||
|
Reference in New Issue
Block a user