Better support for lacking a capital (#9709)

* more getCapital null checks

* Move first city if no capital check to getCapital
This commit is contained in:
SeventhM
2023-07-03 13:47:49 -07:00
committed by GitHub
parent 86cde678b3
commit afb30fb1ca
6 changed files with 16 additions and 11 deletions

View File

@ -213,7 +213,7 @@ object Automation {
// If we have vision of our entire starting continent (ish) we are not afraid
civInfo.gameInfo.tileMap.assignContinents(TileMap.AssignContinentsMode.Ensure)
val startingContinent = civInfo.getCapital()!!.getCenterTile().getContinent()
val startingContinent = civInfo.getCapital(true)!!.getCenterTile().getContinent()
val startingContinentSize = civInfo.gameInfo.tileMap.continentSizes[startingContinent]
if (startingContinentSize != null && startingContinentSize < civInfo.viewableTiles.size * multiplier)
return false

View File

@ -838,8 +838,10 @@ object NextTurnAutomation {
val closestCities = getClosestCities(civInfo, otherCiv) ?: return 0
val baseForce = 30f
val ourCombatStrength = civInfo.getStatForRanking(RankingType.Force).toFloat() + baseForce + CityCombatant(civInfo.getCapital()!!).getCityStrength()
var theirCombatStrength = otherCiv.getStatForRanking(RankingType.Force).toFloat() + baseForce + CityCombatant(otherCiv.getCapital()!!).getCityStrength()
var ourCombatStrength = civInfo.getStatForRanking(RankingType.Force).toFloat() + baseForce
if (civInfo.getCapital()!= null) ourCombatStrength += CityCombatant(civInfo.getCapital()!!).getCityStrength()
var theirCombatStrength = otherCiv.getStatForRanking(RankingType.Force).toFloat() + baseForce
if(otherCiv.getCapital() != null) theirCombatStrength += CityCombatant(otherCiv.getCapital()!!).getCityStrength()
//for city-states, also consider their protectors
if (otherCiv.isCityState() and otherCiv.cityStateFunctions.getProtectorCivs().isNotEmpty()) {
@ -942,7 +944,7 @@ object NextTurnAutomation {
return motivationSoFar
}
val reachableEnemyCitiesBfs = BFS(civInfo.getCapital()!!.getCenterTile()) { isTileCanMoveThrough(it) }
val reachableEnemyCitiesBfs = BFS(civInfo.getCapital(true)!!.getCenterTile()) { isTileCanMoveThrough(it) }
reachableEnemyCitiesBfs.stepToEnd()
val reachableEnemyCities = otherCiv.cities.filter { reachableEnemyCitiesBfs.hasReachedTile(it.getCenterTile()) }
if (reachableEnemyCities.isEmpty()) return 0 // Can't even reach the enemy city, no point in war.

View File

@ -58,7 +58,8 @@ class WorkerAutomation(
private val citiesThatNeedConnecting: List<City> by lazy {
val result = civInfo.cities.asSequence()
.filter {
it.population.population > 3
civInfo.getCapital() != null
&& it.population.population > 3
&& !it.isCapital() && !it.isBeingRazed // Cities being razed should not be connected.
&& !it.cityStats.isConnectedToCapital(bestRoadAvailable)
}.sortedBy {

View File

@ -320,7 +320,8 @@ class Civilization : IsPartOfGameInfoSerialization {
fun knows(otherCivName: String) = diplomacy.containsKey(otherCivName)
fun knows(otherCiv: Civilization) = knows(otherCiv.civName)
fun getCapital() = cities.firstOrNull { it.isCapital() }
fun getCapital(firstCityIfNoCapital: Boolean = false) = cities.firstOrNull { it.isCapital() } ?:
if (firstCityIfNoCapital) cities.firstOrNull() else null
fun isHuman() = playerType == PlayerType.Human
fun isAI() = playerType == PlayerType.AI
fun isOneCityChallenger() = playerType == PlayerType.Human && gameInfo.gameParameters.oneCityChallenge

View File

@ -521,7 +521,7 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
}
if (!civInfo.isDefeated()) { // don't display city state relationship notifications when the city state is currently defeated
val civCapitalLocation = if (civInfo.cities.isNotEmpty() || civInfo.getCapital() != null) civInfo.getCapital()!!.location else null
val civCapitalLocation = if (civInfo.cities.any() && civInfo.getCapital() != null) civInfo.getCapital()!!.location else null
if (getTurnsToRelationshipChange() == 1) {
val text = "Your relationship with [${civInfo.civName}] is about to degrade"
if (civCapitalLocation != null) otherCiv().addNotification(text,

View File

@ -248,7 +248,7 @@ class CivInfoTransientCache(val civInfo: Civilization) {
}
fun updateCitiesConnectedToCapital(initialSetup: Boolean = false) {
if (civInfo.cities.isEmpty() || civInfo.getCapital() == null) return // eg barbarians
if (civInfo.cities.isEmpty()) return // No cities to connect
val oldConnectedCities = if (initialSetup)
civInfo.cities.filter { it.connectedToCapitalStatus == City.ConnectedToCapitalStatus.`true` }
@ -257,12 +257,13 @@ class CivInfoTransientCache(val civInfo: Civilization) {
civInfo.cities.filter { it.connectedToCapitalStatus != City.ConnectedToCapitalStatus.`false` }
else citiesConnectedToCapitalToMediums.keys
citiesConnectedToCapitalToMediums = CapitalConnectionsFinder(civInfo).find()
citiesConnectedToCapitalToMediums = if(civInfo.getCapital() == null) mapOf()
else CapitalConnectionsFinder(civInfo).find()
val newConnectedCities = citiesConnectedToCapitalToMediums.keys
for (city in newConnectedCities)
if (city !in oldMaybeConnectedCities && city.civ == civInfo && city != civInfo.getCapital()!!)
if (city !in oldMaybeConnectedCities && city.civ == civInfo && city != civInfo.getCapital())
civInfo.addNotification("[${city.name}] has been connected to your capital!",
city.location, NotificationCategory.Cities, NotificationIcon.Gold
)
@ -379,7 +380,7 @@ class CivInfoTransientCache(val civInfo: Civilization) {
// Check if different continents (unless already max distance, or water map)
if (connections > 0 && proximity != Proximity.Distant && !civInfo.gameInfo.tileMap.isWaterMap()
&& civInfo.getCapital()!!.getCenterTile().getContinent() != otherCiv.getCapital()!!.getCenterTile().getContinent()
&& civInfo.getCapital(true)!!.getCenterTile().getContinent() != otherCiv.getCapital(true)!!.getCenterTile().getContinent()
) {
// Different continents - increase separation by one step
proximity = when (proximity) {