mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 05:14:32 -04:00
Allow AI to consider production bonuses when building (#11254)
* Allow AI to consider production bonuses when building * Optimization
This commit is contained in:
parent
8100d0bf73
commit
60d93e5ff9
@ -81,10 +81,12 @@ class ConstructionAutomation(val cityConstructions: CityConstructions) {
|
|||||||
|
|
||||||
private val relativeCostEffectiveness = ArrayList<ConstructionChoice>()
|
private val relativeCostEffectiveness = ArrayList<ConstructionChoice>()
|
||||||
|
|
||||||
private data class ConstructionChoice(val choice: String, var choiceModifier: Float, val remainingWork: Int)
|
private data class ConstructionChoice(val choice: String, var choiceModifier: Float,
|
||||||
|
val remainingWork: Int, val production: Int)
|
||||||
|
|
||||||
private fun addChoice(choices: ArrayList<ConstructionChoice>, choice: String, choiceModifier: Float) {
|
private fun addChoice(choices: ArrayList<ConstructionChoice>, choice: String, choiceModifier: Float) {
|
||||||
choices.add(ConstructionChoice(choice, choiceModifier, cityConstructions.getRemainingWork(choice)))
|
choices.add(ConstructionChoice(choice, choiceModifier,
|
||||||
|
cityConstructions.getRemainingWork(choice), cityConstructions.productionForConstruction(choice)))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Sequence<INonPerpetualConstruction>.filterBuildable(): Sequence<INonPerpetualConstruction> {
|
private fun Sequence<INonPerpetualConstruction>.filterBuildable(): Sequence<INonPerpetualConstruction> {
|
||||||
@ -120,8 +122,6 @@ class ConstructionAutomation(val cityConstructions: CityConstructions) {
|
|||||||
addMilitaryUnitChoice()
|
addMilitaryUnitChoice()
|
||||||
}
|
}
|
||||||
|
|
||||||
val production = city.cityStats.currentCityStats.production
|
|
||||||
|
|
||||||
val chosenConstruction: String =
|
val chosenConstruction: String =
|
||||||
if (relativeCostEffectiveness.isEmpty()) { // choose one of the special constructions instead
|
if (relativeCostEffectiveness.isEmpty()) { // choose one of the special constructions instead
|
||||||
// add science!
|
// add science!
|
||||||
@ -130,13 +130,13 @@ class ConstructionAutomation(val cityConstructions: CityConstructions) {
|
|||||||
PerpetualConstruction.gold.isBuildable(cityConstructions) -> PerpetualConstruction.gold.name
|
PerpetualConstruction.gold.isBuildable(cityConstructions) -> PerpetualConstruction.gold.name
|
||||||
else -> PerpetualConstruction.idle.name
|
else -> PerpetualConstruction.idle.name
|
||||||
}
|
}
|
||||||
} else if (relativeCostEffectiveness.any { it.remainingWork < production * 30 }) {
|
} else if (relativeCostEffectiveness.any { it.remainingWork < it.production * 30 }) {
|
||||||
relativeCostEffectiveness.removeAll { it.remainingWork >= production * 30 }
|
relativeCostEffectiveness.removeAll { it.remainingWork >= it.production * 30 }
|
||||||
relativeCostEffectiveness.minByOrNull { it.remainingWork / it.choiceModifier }!!.choice
|
relativeCostEffectiveness.minByOrNull { it.remainingWork / it.choiceModifier / it.production }!!.choice
|
||||||
}
|
}
|
||||||
// it's possible that this is a new city and EVERYTHING is way expensive - ignore modifiers, go for the cheapest.
|
// it's possible that this is a new city and EVERYTHING is way expensive - ignore modifiers, go for the cheapest.
|
||||||
// Nobody can plan 30 turns ahead, I don't care how cost-efficient you are.
|
// Nobody can plan 30 turns ahead, I don't care how cost-efficient you are.
|
||||||
else relativeCostEffectiveness.minByOrNull { it.remainingWork }!!.choice
|
else relativeCostEffectiveness.minByOrNull { it.remainingWork / it.production}!!.choice
|
||||||
|
|
||||||
civInfo.addNotification(
|
civInfo.addNotification(
|
||||||
"Work has started on [$chosenConstruction]",
|
"Work has started on [$chosenConstruction]",
|
||||||
|
@ -267,6 +267,10 @@ class CityConstructions : IsPartOfGameInfoSerialization {
|
|||||||
if (workLeft <= productionOverflow) // if we already have stored up enough production to finish it directly
|
if (workLeft <= productionOverflow) // if we already have stored up enough production to finish it directly
|
||||||
return 1 // we'll finish this next turn
|
return 1 // we'll finish this next turn
|
||||||
|
|
||||||
|
return ceil((workLeft-productionOverflow) / productionForConstruction(constructionName).toDouble()).toInt()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun productionForConstruction(constructionName: String): Int {
|
||||||
val cityStatsForConstruction: Stats
|
val cityStatsForConstruction: Stats
|
||||||
if (currentConstructionFromQueue == constructionName) cityStatsForConstruction = city.cityStats.currentCityStats
|
if (currentConstructionFromQueue == constructionName) cityStatsForConstruction = city.cityStats.currentCityStats
|
||||||
else {
|
else {
|
||||||
@ -288,9 +292,7 @@ class CityConstructions : IsPartOfGameInfoSerialization {
|
|||||||
cityStatsForConstruction = cityStats.currentCityStats
|
cityStatsForConstruction = cityStats.currentCityStats
|
||||||
}
|
}
|
||||||
|
|
||||||
val production = cityStatsForConstruction.production.roundToInt()
|
return cityStatsForConstruction.production.roundToInt()
|
||||||
|
|
||||||
return ceil((workLeft-productionOverflow) / production.toDouble()).toInt()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cheapestStatBuilding(stat: Stat): Building? {
|
fun cheapestStatBuilding(stat: Stat): Building? {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user