mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-28 22:37:02 -04:00
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:
parent
86cde678b3
commit
afb30fb1ca
@ -213,7 +213,7 @@ object Automation {
|
|||||||
|
|
||||||
// If we have vision of our entire starting continent (ish) we are not afraid
|
// If we have vision of our entire starting continent (ish) we are not afraid
|
||||||
civInfo.gameInfo.tileMap.assignContinents(TileMap.AssignContinentsMode.Ensure)
|
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]
|
val startingContinentSize = civInfo.gameInfo.tileMap.continentSizes[startingContinent]
|
||||||
if (startingContinentSize != null && startingContinentSize < civInfo.viewableTiles.size * multiplier)
|
if (startingContinentSize != null && startingContinentSize < civInfo.viewableTiles.size * multiplier)
|
||||||
return false
|
return false
|
||||||
|
@ -838,8 +838,10 @@ object NextTurnAutomation {
|
|||||||
val closestCities = getClosestCities(civInfo, otherCiv) ?: return 0
|
val closestCities = getClosestCities(civInfo, otherCiv) ?: return 0
|
||||||
val baseForce = 30f
|
val baseForce = 30f
|
||||||
|
|
||||||
val ourCombatStrength = civInfo.getStatForRanking(RankingType.Force).toFloat() + baseForce + CityCombatant(civInfo.getCapital()!!).getCityStrength()
|
var ourCombatStrength = civInfo.getStatForRanking(RankingType.Force).toFloat() + baseForce
|
||||||
var theirCombatStrength = otherCiv.getStatForRanking(RankingType.Force).toFloat() + baseForce + CityCombatant(otherCiv.getCapital()!!).getCityStrength()
|
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
|
//for city-states, also consider their protectors
|
||||||
if (otherCiv.isCityState() and otherCiv.cityStateFunctions.getProtectorCivs().isNotEmpty()) {
|
if (otherCiv.isCityState() and otherCiv.cityStateFunctions.getProtectorCivs().isNotEmpty()) {
|
||||||
@ -942,7 +944,7 @@ object NextTurnAutomation {
|
|||||||
return motivationSoFar
|
return motivationSoFar
|
||||||
}
|
}
|
||||||
|
|
||||||
val reachableEnemyCitiesBfs = BFS(civInfo.getCapital()!!.getCenterTile()) { isTileCanMoveThrough(it) }
|
val reachableEnemyCitiesBfs = BFS(civInfo.getCapital(true)!!.getCenterTile()) { isTileCanMoveThrough(it) }
|
||||||
reachableEnemyCitiesBfs.stepToEnd()
|
reachableEnemyCitiesBfs.stepToEnd()
|
||||||
val reachableEnemyCities = otherCiv.cities.filter { reachableEnemyCitiesBfs.hasReachedTile(it.getCenterTile()) }
|
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.
|
if (reachableEnemyCities.isEmpty()) return 0 // Can't even reach the enemy city, no point in war.
|
||||||
|
@ -58,7 +58,8 @@ class WorkerAutomation(
|
|||||||
private val citiesThatNeedConnecting: List<City> by lazy {
|
private val citiesThatNeedConnecting: List<City> by lazy {
|
||||||
val result = civInfo.cities.asSequence()
|
val result = civInfo.cities.asSequence()
|
||||||
.filter {
|
.filter {
|
||||||
it.population.population > 3
|
civInfo.getCapital() != null
|
||||||
|
&& it.population.population > 3
|
||||||
&& !it.isCapital() && !it.isBeingRazed // Cities being razed should not be connected.
|
&& !it.isCapital() && !it.isBeingRazed // Cities being razed should not be connected.
|
||||||
&& !it.cityStats.isConnectedToCapital(bestRoadAvailable)
|
&& !it.cityStats.isConnectedToCapital(bestRoadAvailable)
|
||||||
}.sortedBy {
|
}.sortedBy {
|
||||||
|
@ -320,7 +320,8 @@ class Civilization : IsPartOfGameInfoSerialization {
|
|||||||
fun knows(otherCivName: String) = diplomacy.containsKey(otherCivName)
|
fun knows(otherCivName: String) = diplomacy.containsKey(otherCivName)
|
||||||
fun knows(otherCiv: Civilization) = knows(otherCiv.civName)
|
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 isHuman() = playerType == PlayerType.Human
|
||||||
fun isAI() = playerType == PlayerType.AI
|
fun isAI() = playerType == PlayerType.AI
|
||||||
fun isOneCityChallenger() = playerType == PlayerType.Human && gameInfo.gameParameters.oneCityChallenge
|
fun isOneCityChallenger() = playerType == PlayerType.Human && gameInfo.gameParameters.oneCityChallenge
|
||||||
|
@ -521,7 +521,7 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!civInfo.isDefeated()) { // don't display city state relationship notifications when the city state is currently defeated
|
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) {
|
if (getTurnsToRelationshipChange() == 1) {
|
||||||
val text = "Your relationship with [${civInfo.civName}] is about to degrade"
|
val text = "Your relationship with [${civInfo.civName}] is about to degrade"
|
||||||
if (civCapitalLocation != null) otherCiv().addNotification(text,
|
if (civCapitalLocation != null) otherCiv().addNotification(text,
|
||||||
|
@ -248,7 +248,7 @@ class CivInfoTransientCache(val civInfo: Civilization) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateCitiesConnectedToCapital(initialSetup: Boolean = false) {
|
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)
|
val oldConnectedCities = if (initialSetup)
|
||||||
civInfo.cities.filter { it.connectedToCapitalStatus == City.ConnectedToCapitalStatus.`true` }
|
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` }
|
civInfo.cities.filter { it.connectedToCapitalStatus != City.ConnectedToCapitalStatus.`false` }
|
||||||
else citiesConnectedToCapitalToMediums.keys
|
else citiesConnectedToCapitalToMediums.keys
|
||||||
|
|
||||||
citiesConnectedToCapitalToMediums = CapitalConnectionsFinder(civInfo).find()
|
citiesConnectedToCapitalToMediums = if(civInfo.getCapital() == null) mapOf()
|
||||||
|
else CapitalConnectionsFinder(civInfo).find()
|
||||||
|
|
||||||
val newConnectedCities = citiesConnectedToCapitalToMediums.keys
|
val newConnectedCities = citiesConnectedToCapitalToMediums.keys
|
||||||
|
|
||||||
for (city in newConnectedCities)
|
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!",
|
civInfo.addNotification("[${city.name}] has been connected to your capital!",
|
||||||
city.location, NotificationCategory.Cities, NotificationIcon.Gold
|
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)
|
// Check if different continents (unless already max distance, or water map)
|
||||||
if (connections > 0 && proximity != Proximity.Distant && !civInfo.gameInfo.tileMap.isWaterMap()
|
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
|
// Different continents - increase separation by one step
|
||||||
proximity = when (proximity) {
|
proximity = when (proximity) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user