Resolved #3115 - AI no longer congregates great people in cities where it can't improve tiles

This commit is contained in:
Yair Morgenstern 2020-09-10 21:00:53 +03:00
parent 9ba9dd6fcf
commit 3eee2bff78
3 changed files with 19 additions and 16 deletions

View file

@ -27,12 +27,13 @@ object Automation {
rank += stats.production rank += stats.production
rank += stats.science / 2 rank += stats.science / 2
rank += stats.culture / 2 rank += stats.culture / 2
rank += stats.gold / 5 // it's barely worth anything at this points rank += stats.gold / 5 // it's barely worth anything at this point
} else { } else {
if (stats.food <= 2 || city.civInfo.getHappiness() > 5) rank += stats.food * 1.2f * foodWeight //food get more value to keep city growing if (stats.food <= 2 || city.civInfo.getHappiness() > 5) rank += stats.food * 1.2f * foodWeight //food get more value to keep city growing
else rank += (2.4f + (stats.food - 2) / 2) * foodWeight // 1.2 point for each food up to 2, from there on half a point else rank += (2.4f + (stats.food - 2) / 2) * foodWeight // 1.2 point for each food up to 2, from there on half a point
if (city.civInfo.gold < 0 && city.civInfo.statsForNextTurn.gold <= 0) rank += stats.gold // we have a global problem if (city.civInfo.gold < 0 && city.civInfo.statsForNextTurn.gold <= 0)
rank += stats.gold // we have a global problem
else rank += stats.gold / 3 // 3 gold is worse than 2 production else rank += stats.gold / 3 // 3 gold is worse than 2 production
rank += stats.production rank += stats.production
@ -91,7 +92,7 @@ object Automation {
// Since units become exponentially stronger per combat strength increase, we square em all // Since units become exponentially stronger per combat strength increase, we square em all
fun square(x:Int) = x*x fun square(x:Int) = x*x
val unitStrength = civInfo.getCivUnits().map { square(max(it.baseUnit().strength, it.baseUnit().rangedStrength)) }.sum() val unitStrength = civInfo.getCivUnits().map { square(max(it.baseUnit().strength, it.baseUnit().rangedStrength)) }.sum()
return (sqrt(unitStrength.toDouble())).toInt() + 1 //avoid 0, becaus we divide by the result return sqrt(unitStrength.toDouble()).toInt() + 1 //avoid 0, because we divide by the result
} }
fun threatAssessment(assessor:CivilizationInfo, assessed: CivilizationInfo): ThreatLevel { fun threatAssessment(assessor:CivilizationInfo, assessed: CivilizationInfo): ThreatLevel {

View file

@ -18,7 +18,7 @@ import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.translations.tr import com.unciv.models.translations.tr
import kotlin.math.min import kotlin.math.min
object NextTurnAutomation{ object NextTurnAutomation {
/** Top-level AI turn tasklist */ /** Top-level AI turn tasklist */
fun automateCivMoves(civInfo: CivilizationInfo) { fun automateCivMoves(civInfo: CivilizationInfo) {
@ -30,8 +30,8 @@ object NextTurnAutomation{
if(civInfo.isMajorCiv()) { if(civInfo.isMajorCiv()) {
if(!civInfo.gameInfo.ruleSet.modOptions.uniques.contains(ModOptionsConstants.diplomaticRelationshipsCannotChange)) { if(!civInfo.gameInfo.ruleSet.modOptions.uniques.contains(ModOptionsConstants.diplomaticRelationshipsCannotChange)) {
declareWar(civInfo) declareWar(civInfo)
// offerDeclarationOfFriendship(civInfo)
offerPeaceTreaty(civInfo) offerPeaceTreaty(civInfo)
// offerDeclarationOfFriendship(civInfo)
} }
offerResearchAgreement(civInfo) offerResearchAgreement(civInfo)
exchangeLuxuries(civInfo) exchangeLuxuries(civInfo)

View file

@ -1,8 +1,8 @@
package com.unciv.logic.automation package com.unciv.logic.automation
import com.unciv.logic.battle.MapUnitCombatant import com.unciv.logic.battle.MapUnitCombatant
import com.unciv.logic.city.CityInfo
import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.civilization.GreatPersonManager
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers
import com.unciv.logic.map.MapUnit import com.unciv.logic.map.MapUnit
@ -10,8 +10,6 @@ import com.unciv.logic.map.TileInfo
import com.unciv.models.ruleset.tile.ResourceType import com.unciv.models.ruleset.tile.ResourceType
import com.unciv.models.ruleset.tile.TileResource import com.unciv.models.ruleset.tile.TileResource
import com.unciv.models.stats.Stats import com.unciv.models.stats.Stats
import com.unciv.models.translations.equalsPlaceholderText
import com.unciv.models.translations.getPlaceholderParameters
import com.unciv.ui.worldscreen.unit.UnitActions import com.unciv.ui.worldscreen.unit.UnitActions
object SpecificUnitAutomation { object SpecificUnitAutomation {
@ -204,7 +202,16 @@ object SpecificUnitAutomation {
for (bonus in it.cityStats.statPercentBonusList.values) stats.add(bonus) for (bonus in it.cityStats.statPercentBonusList.values) stats.add(bonus)
stats.toHashMap()[relatedStat]!! stats.toHashMap()[relatedStat]!!
} }
for (city in citiesByStatBoost) { for (city in citiesByStatBoost) {
val applicableTiles = city.getWorkableTiles().filter {
it.isLand && it.resource == null && !it.isCityCenter()
&& (unit.currentTile == it || unit.movement.canMoveTo(it))
&& !it.containsGreatImprovement()
}
if (applicableTiles.none()) continue
val pathToCity = unit.movement.getShortestPath(city.getCenterTile()) val pathToCity = unit.movement.getShortestPath(city.getCenterTile())
if (pathToCity.isEmpty()) continue if (pathToCity.isEmpty()) continue
@ -214,14 +221,9 @@ object SpecificUnitAutomation {
} }
// if we got here, we're pretty close, start looking! // if we got here, we're pretty close, start looking!
val chosenTile = city.getTiles() val chosenTile = applicableTiles.sortedByDescending { Automation.rankTile(it, unit.civInfo) }
.filter { .firstOrNull { unit.movement.canReach(it) }
it.isLand && it.resource == null && !it.isCityCenter() if (chosenTile == null) continue // to another city
&& (unit.currentTile == it || unit.movement.canMoveTo(it))
&& !it.containsGreatImprovement()
}.sortedByDescending { Automation.rankTile(it, unit.civInfo) }
.firstOrNull { unit.movement.canReach(it) } // to another city
if (chosenTile == null) continue
unit.movement.headTowards(chosenTile) unit.movement.headTowards(chosenTile)
if (unit.currentTile == chosenTile) if (unit.currentTile == chosenTile)