From 1201d9b54b3424d6a32865254f4f34bb39a668dd Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Wed, 3 Jul 2019 18:39:59 +0300 Subject: [PATCH] More AI tweaks --- .../unciv/logic/automation/ConstructionAutomation.kt | 12 +++++++----- core/src/com/unciv/models/gamebasics/Building.kt | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/src/com/unciv/logic/automation/ConstructionAutomation.kt b/core/src/com/unciv/logic/automation/ConstructionAutomation.kt index d901719416..3495f433b7 100644 --- a/core/src/com/unciv/logic/automation/ConstructionAutomation.kt +++ b/core/src/com/unciv/logic/automation/ConstructionAutomation.kt @@ -10,6 +10,7 @@ import com.unciv.models.gamebasics.Building import com.unciv.models.gamebasics.VictoryType import com.unciv.models.stats.Stat import kotlin.math.min +import kotlin.math.sqrt class ConstructionAutomation(val cityConstructions: CityConstructions){ @@ -82,12 +83,13 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){ } private fun addMilitaryUnitChoice() { + if(!isAtWar && !cityIsOverAverageProduction) return // don't make any military units here. Infrastructure first! if ((!isAtWar && civInfo.statsForNextTurn.gold > 0 && militaryUnits < cities * 2) || (isAtWar && civInfo.gold > -50)) { val militaryUnit = Automation().chooseMilitaryUnit(cityInfo) val unitsToCitiesRatio = cities.toFloat() / (militaryUnits + 1) // most buildings and civ units contribute the the civ's growth, military units are anti-growth - var modifier = unitsToCitiesRatio / 2 + var modifier = sqrt(unitsToCitiesRatio) / 2 if (preferredVictoryType == VictoryType.Domination) modifier *= 3 else if (isAtWar) modifier *= unitsToCitiesRatio * 2 if (!cityIsOverAverageProduction) modifier /= 5 // higher production cities will deal with this @@ -108,7 +110,7 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){ private fun addWorkerChoice() { val citiesCountedTowardsWorkers = min(5, cities) // above 5 cities, extra cities won't make us want more workers - if (workers < citiesCountedTowardsWorkers * 0.6f) { + if (workers < citiesCountedTowardsWorkers * 0.6f && civUnits.none { it.name==Constants.worker && it.isIdle() }) { var modifier = citiesCountedTowardsWorkers / (workers + 0.1f) if (!cityIsOverAverageProduction) modifier /= 5 // higher production cities will deal with this addChoice(relativeCostEffectiveness, Constants.worker, modifier) @@ -145,7 +147,7 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){ val citiesBuildingWonders = civInfo.cities .count { it.cityConstructions.isBuildingWonder() } - var modifier = 3.5f * getWonderPriority(wonder) / (citiesBuildingWonders + 1) + var modifier = 2f * getWonderPriority(wonder) / (citiesBuildingWonders + 1) if (!cityIsOverAverageProduction) modifier /= 5 // higher production cities will deal with this addChoice(relativeCostEffectiveness, wonder.name, modifier) } @@ -192,7 +194,7 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){ } private fun addScienceBuildingChoice() { - val scienceBuilding = buildableNotWonders.filter { it.isStatRelated(Stat.Science) } + val scienceBuilding = buildableNotWonders.filter { it.isStatRelated(Stat.Science) || it.name=="Library" } // only stat related in unique .minBy { it.cost } if (scienceBuilding != null) { var modifier = 1.1f @@ -220,7 +222,7 @@ class ConstructionAutomation(val cityConstructions: CityConstructions){ } private fun addFoodBuildingChoice() { - val foodBuilding = buildableNotWonders.filter { it.isStatRelated(Stat.Food) } + val foodBuilding = buildableNotWonders.filter { it.isStatRelated(Stat.Food) } // only stat related in unique .minBy { it.cost } if (foodBuilding != null) { var modifier = 1f diff --git a/core/src/com/unciv/models/gamebasics/Building.kt b/core/src/com/unciv/models/gamebasics/Building.kt index 258f2d406e..c96b0e4b04 100644 --- a/core/src/com/unciv/models/gamebasics/Building.kt +++ b/core/src/com/unciv/models/gamebasics/Building.kt @@ -346,6 +346,7 @@ class Building : NamedStats(), IConstruction{ if (get(stat) > 0) return true if (getStatPercentageBonuses(null).get(stat)>0) return true if (specialistSlots!=null && specialistSlots!!.get(stat)>0) return true + if(resourceBonusStats!=null && resourceBonusStats!!.get(stat)>0) return true return false }