Split AI choice for construction of defensive and offensive buildings

This commit is contained in:
Yair Morgenstern 2019-07-02 00:27:24 +03:00
parent 4d5f3a51e3
commit b0b47d0a3a
2 changed files with 32 additions and 5 deletions

View file

@ -159,15 +159,30 @@ class Automation {
relativeCostEffectiveness.add(choice)
}
//War buildings
val wartimeBuilding = buildableNotWonders.filter { it.xpForNewUnits>0 || it.cityStrength>0 }
//Defensive building
val defensiveBuilding = buildableNotWonders.filter { it.cityStrength>0 }
.minBy { it.cost }
if (wartimeBuilding!=null && (preferredVictoryType!=VictoryType.Cultural || isAtWar)) {
if(defensiveBuilding!=null && (isAtWar || preferredVictoryType!=VictoryType.Cultural)){
var modifier = 0.2f
if(isAtWar) modifier = 0.5f
// If this city is the closest city to another civ, that makes it a likely candidate for attack
if(cityInfo.civInfo.getKnownCivs()
.any{ NextTurnAutomation().getClosestCities(cityInfo.civInfo,it).city1 == cityInfo })
modifier *= 1.5f
relativeCostEffectiveness.add(ConstructionChoice(defensiveBuilding.name, modifier))
}
val unitTrainingBuilding = buildableNotWonders.filter { it.xpForNewUnits>0}
.minBy { it.cost }
//cityInfo.civInfo.cities.sortedByDescending { } // todo don't build if this is a weak production city
if (unitTrainingBuilding!=null && (preferredVictoryType!=VictoryType.Cultural || isAtWar)) {
var modifier = 0.5f
if(isAtWar) modifier = 1f
if(preferredVictoryType==VictoryType.Domination)
modifier *= 1.3f
relativeCostEffectiveness.add(ConstructionChoice(wartimeBuilding.name,modifier))
relativeCostEffectiveness.add(ConstructionChoice(unitTrainingBuilding.name,modifier))
}
//Wonders

View file

@ -1,6 +1,7 @@
package com.unciv.logic.automation
import com.unciv.Constants
import com.unciv.logic.city.CityInfo
import com.unciv.logic.civilization.*
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
import com.unciv.logic.civilization.diplomacy.DiplomaticModifiers
@ -262,7 +263,18 @@ class NextTurnAutomation{
}
fun getMinDistanceBetweenCities(civ1: CivilizationInfo, civ2: CivilizationInfo): Int {
return civ1.cities.map { city -> civ2.cities.map { it.getCenterTile().arialDistanceTo(city.getCenterTile()) }.min()!! }.min()!!
return getClosestCities(civ1,civ2).arialDistance
}
data class CityDistance(val city1:CityInfo, val city2:CityInfo, val arialDistance: Int)
fun getClosestCities(civ1: CivilizationInfo, civ2: CivilizationInfo): CityDistance {
val cityDistances = arrayListOf<CityDistance>()
for(civ1city in civ1.cities)
for(civ2city in civ2.cities)
cityDistances.add(CityDistance(civ1city,civ2city,
civ1city.getCenterTile().arialDistanceTo(civ2city.getCenterTile())))
return cityDistances.minBy { it.arialDistance }!!
}
private fun offerPeaceTreaty(civInfo: CivilizationInfo) {