mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-06 00:09:23 +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
|
||||
|
@ -60,7 +60,7 @@ class VerticalFileListScrollPane(
|
||||
val loadImage = ImageGetter.getImage("OtherIcons/Load")
|
||||
loadImage.setSize(50f, 50f) // So the origin sets correctly
|
||||
loadImage.setOrigin(Align.center)
|
||||
val loadAnimation = Actions.repeat(Int.MAX_VALUE, Actions.rotateBy(360f, 2f))
|
||||
val loadAnimation = Actions.forever(Actions.rotateBy(360f, 2f))
|
||||
loadImage.addAction(loadAnimation)
|
||||
existingSavesTable.add(loadImage).size(50f).center()
|
||||
|
||||
|
@ -237,11 +237,11 @@ object BattleTableHelpers {
|
||||
|
||||
val damagedHealth = ImageGetter.getDot(Color.FIREBRICK)
|
||||
if (UncivGame.Current.settings.continuousRendering) {
|
||||
damagedHealth.addAction(Actions.repeat(
|
||||
RepeatAction.FOREVER, Actions.sequence(
|
||||
damagedHealth.addAction(Actions.forever(Actions.sequence(
|
||||
Actions.color(Color.BLACK, 0.7f),
|
||||
Actions.color(Color.FIREBRICK, 0.7f)
|
||||
))) }
|
||||
)))
|
||||
}
|
||||
|
||||
val maybeDamagedHealth = ImageGetter.getDot(Color.ORANGE)
|
||||
|
||||
|
@ -82,7 +82,7 @@ class MultiplayerStatusButton(
|
||||
|
||||
if (UncivGame.Current.settings.continuousRendering) {
|
||||
loadingImage.clearActions()
|
||||
loadingImage.addAction(Actions.repeat(RepeatAction.FOREVER,Actions.rotateBy(-90f, 1f)))
|
||||
loadingImage.addAction(Actions.forever(Actions.rotateBy(-90f, 1f)))
|
||||
}
|
||||
|
||||
loadingImage.isVisible = true
|
||||
|
Reference in New Issue
Block a user