mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-15 04:14:44 +07:00
Fix crashes when a civ does not have a capital (#6889)
This commit is contained in:
parent
740886c890
commit
39bbb2de1c
@ -100,8 +100,8 @@ class BarbarianManager {
|
||||
if (campsToAdd <= 0) return
|
||||
|
||||
// Camps can't spawn within 7 tiles of each other or within 4 tiles of major civ capitals
|
||||
val tooCloseToCapitals = gameInfo.civilizations.filterNot { it.isBarbarian() || it.isSpectator() || it.cities.isEmpty() || it.isCityState() }
|
||||
.flatMap { it.getCapital().getCenterTile().getTilesInDistance(4) }.toSet()
|
||||
val tooCloseToCapitals = gameInfo.civilizations.filterNot { it.isBarbarian() || it.isSpectator() || it.cities.isEmpty() || it.isCityState() || it.getCapital() == null }
|
||||
.flatMap { it.getCapital()!!.getCenterTile().getTilesInDistance(4) }.toSet()
|
||||
val tooCloseToCamps = camps
|
||||
.flatMap { tileMap[it.key].getTilesInDistance(
|
||||
if (it.value.destroyed) 4 else 7
|
||||
|
@ -345,7 +345,7 @@ class GameInfo {
|
||||
getAliveCityStates()
|
||||
.asSequence()
|
||||
.filter { it.cityStateResource == resourceName }
|
||||
.map { it.getCapital().getCenterTile() }
|
||||
.map { it.getCapital()!!.getCenterTile() }
|
||||
} else {
|
||||
tileMap.values
|
||||
.asSequence()
|
||||
|
@ -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()!!.getCenterTile().getContinent()
|
||||
val startingContinentSize = civInfo.gameInfo.tileMap.continentSizes[startingContinent]
|
||||
if (startingContinentSize != null && startingContinentSize < civInfo.viewableTiles.size * multiplier)
|
||||
return false
|
||||
|
@ -722,7 +722,7 @@ object NextTurnAutomation {
|
||||
&& (owner == otherCiv || owner == null || civInfo.canPassThroughTiles(owner))
|
||||
}
|
||||
|
||||
val reachableEnemyCitiesBfs = BFS(civInfo.getCapital().getCenterTile()) { isTileCanMoveThrough(it) }
|
||||
val reachableEnemyCitiesBfs = BFS(civInfo.getCapital()!!.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.
|
||||
|
@ -279,7 +279,8 @@ object SpecificUnitAutomation {
|
||||
}
|
||||
|
||||
fun automateAddInCapital(unit: MapUnit) {
|
||||
val capitalTile = unit.civInfo.getCapital().getCenterTile()
|
||||
if (unit.civInfo.getCapital() == null) return // safeguard
|
||||
val capitalTile = unit.civInfo.getCapital()!!.getCenterTile()
|
||||
if (unit.movement.canReach(capitalTile))
|
||||
unit.movement.headTowards(capitalTile)
|
||||
if (unit.getTile() == capitalTile) {
|
||||
|
@ -57,7 +57,7 @@ class WorkerAutomation(
|
||||
&& !it.isCapital() && !it.isBeingRazed // Cities being razed should not be connected.
|
||||
&& !it.cityStats.isConnectedToCapital(bestRoadAvailable)
|
||||
}.sortedBy {
|
||||
it.getCenterTile().aerialDistanceTo(civInfo.getCapital().getCenterTile())
|
||||
it.getCenterTile().aerialDistanceTo(civInfo.getCapital()!!.getCenterTile())
|
||||
}.toList()
|
||||
if (WorkerAutomationConst.consoleOutput) {
|
||||
println("WorkerAutomation citiesThatNeedConnecting for ${civInfo.civName} turn $cachedForTurn:")
|
||||
|
@ -49,9 +49,9 @@ object BattleDamage {
|
||||
for (unique in combatant.getMatchingUniques(
|
||||
UniqueType.StrengthNearCapital, conditionalState, true
|
||||
)) {
|
||||
if (civInfo.cities.isEmpty()) break
|
||||
if (civInfo.cities.isEmpty() || civInfo.getCapital() == null) break
|
||||
val distance =
|
||||
combatant.getTile().aerialDistanceTo(civInfo.getCapital().getCenterTile())
|
||||
combatant.getTile().aerialDistanceTo(civInfo.getCapital()!!.getCenterTile())
|
||||
// https://steamcommunity.com/sharedfiles/filedetails/?id=326411722#464287
|
||||
val effect = unique.params[0].toInt() - 3 * distance
|
||||
if (effect <= 0) continue
|
||||
|
@ -83,7 +83,7 @@ class CityStats(val cityInfo: CityInfo) {
|
||||
val stats = Stats()
|
||||
if (!cityInfo.isCapital() && cityInfo.isConnectedToCapital()) {
|
||||
val civInfo = cityInfo.civInfo
|
||||
stats.gold = civInfo.getCapital().population.population * 0.15f + cityInfo.population.population * 1.1f - 1 // Calculated by http://civilization.wikia.com/wiki/Trade_route_(Civ5)
|
||||
stats.gold = civInfo.getCapital()!!.population.population * 0.15f + cityInfo.population.population * 1.1f - 1 // Calculated by http://civilization.wikia.com/wiki/Trade_route_(Civ5)
|
||||
for (unique in cityInfo.getMatchingUniques(UniqueType.StatsFromTradeRoute))
|
||||
stats.add(unique.stats)
|
||||
val percentageStats = Stats()
|
||||
@ -317,7 +317,8 @@ class CityStats(val cityInfo: CityInfo) {
|
||||
|
||||
if (currentConstruction is Building
|
||||
&& cityInfo.civInfo.cities.isNotEmpty()
|
||||
&& cityInfo.civInfo.getCapital().cityConstructions.builtBuildings.contains(currentConstruction.name)
|
||||
&& cityInfo.civInfo.getCapital() != null
|
||||
&& cityInfo.civInfo.getCapital()!!.cityConstructions.builtBuildings.contains(currentConstruction.name)
|
||||
) {
|
||||
for (unique in cityInfo.getMatchingUniques(UniqueType.PercentProductionBuildingsInCapital))
|
||||
addUniqueStats(unique, Stat.Production, unique.params[0].toFloat())
|
||||
|
@ -8,7 +8,7 @@ import kotlin.collections.set
|
||||
|
||||
class CapitalConnectionsFinder(private val civInfo: CivilizationInfo) {
|
||||
private val citiesReachedToMediums = HashMap<CityInfo, MutableSet<String>>()
|
||||
private var citiesToCheck = mutableListOf(civInfo.getCapital())
|
||||
private var citiesToCheck = mutableListOf(civInfo.getCapital()!!)
|
||||
private lateinit var newCitiesToCheck: MutableList<CityInfo>
|
||||
|
||||
private val openBordersCivCities = civInfo.gameInfo.getCities().filter { civInfo.canEnterBordersOf(it.civInfo) }
|
||||
@ -24,7 +24,7 @@ class CapitalConnectionsFinder(private val civInfo: CivilizationInfo) {
|
||||
private val railroadIsResearched = ruleset.tileImprovements.containsKey(railroad) && civInfo.tech.isResearched(ruleset.tileImprovements[railroad]!!.techRequired!!)
|
||||
|
||||
init {
|
||||
citiesReachedToMediums[civInfo.getCapital()] = hashSetOf("Start")
|
||||
citiesReachedToMediums[civInfo.getCapital()!!] = hashSetOf("Start")
|
||||
}
|
||||
|
||||
fun find(): Map<CityInfo, Set<String>> {
|
||||
|
@ -111,7 +111,7 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
|
||||
val placedUnit = receivingCiv.placeUnitNearTile(city.location, militaryUnit.name) ?: return
|
||||
|
||||
// The unit should have bonuses from Barracks, Alhambra etc as if it was built in the CS capital
|
||||
militaryUnit.addConstructionBonuses(placedUnit, civInfo.getCapital().cityConstructions)
|
||||
militaryUnit.addConstructionBonuses(placedUnit, civInfo.getCapital()!!.cityConstructions)
|
||||
|
||||
// Siam gets +10 XP for all CS units
|
||||
for (unique in receivingCiv.getMatchingUniques(UniqueType.CityStateGiftedUnitsStartWithXp)) {
|
||||
@ -236,7 +236,7 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
|
||||
|
||||
// If the city-state is captured by a civ, it stops being the ally of the civ it was previously an ally of.
|
||||
// This means that it will NOT HAVE a capital at that time, so if we run getCapital we'll get a crash!
|
||||
val capitalLocation = if (civInfo.cities.isNotEmpty()) civInfo.getCapital().location else null
|
||||
val capitalLocation = if (civInfo.cities.isNotEmpty() && civInfo.getCapital() != null) civInfo.getCapital()!!.location else null
|
||||
|
||||
if (newAllyName != null) {
|
||||
val newAllyCiv = civInfo.gameInfo.getCivilization(newAllyName)
|
||||
@ -300,10 +300,10 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
|
||||
|
||||
otherCiv.addGold(-getDiplomaticMarriageCost())
|
||||
otherCiv.addNotification("We have married into the ruling family of [${civInfo.civName}], bringing them under our control.",
|
||||
civInfo.getCapital().location, civInfo.civName, NotificationIcon.Diplomacy, otherCiv.civName)
|
||||
civInfo.getCapital()!!.location, civInfo.civName, NotificationIcon.Diplomacy, otherCiv.civName)
|
||||
for (civ in civInfo.gameInfo.civilizations.filter { it != otherCiv })
|
||||
civ.addNotification("[${otherCiv.civName}] has married into the ruling family of [${civInfo.civName}], bringing them under their control.",
|
||||
civInfo.getCapital().location, civInfo.civName, NotificationIcon.Diplomacy, otherCiv.civName)
|
||||
civInfo.getCapital()!!.location, civInfo.civName, NotificationIcon.Diplomacy, otherCiv.civName)
|
||||
for (unit in civInfo.getCivUnits())
|
||||
unit.gift(otherCiv)
|
||||
for (city in civInfo.cities) {
|
||||
@ -326,7 +326,7 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
|
||||
modifiers["Major Civ"] = -999
|
||||
return modifiers
|
||||
}
|
||||
if (civInfo.cities.isEmpty()) {
|
||||
if (civInfo.cities.isEmpty() || civInfo.getCapital() == null) {
|
||||
modifiers["No Cities"] = -999
|
||||
return modifiers
|
||||
}
|
||||
@ -343,7 +343,7 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
|
||||
modifiers["Has Protector"] = -20
|
||||
if (demandingWorker)
|
||||
modifiers["Demanding a Worker"] = -30
|
||||
if (demandingWorker && civInfo.getCapital().population.population < 4)
|
||||
if (demandingWorker && civInfo.getCapital()!!.population.population < 4)
|
||||
modifiers["Demanding a Worker from small City-State"] = -300
|
||||
val recentBullying = civInfo.getRecentBullyingCountdown()
|
||||
if (recentBullying != null && recentBullying > 10)
|
||||
@ -365,13 +365,13 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
|
||||
return modifiers
|
||||
|
||||
val bullyRange = (civInfo.gameInfo.tileMap.tileMatrix.size / 10).coerceIn(5, 10) // Longer range for larger maps
|
||||
val inRangeTiles = civInfo.getCapital().getCenterTile().getTilesInDistanceRange(1..bullyRange)
|
||||
val inRangeTiles = civInfo.getCapital()!!.getCenterTile().getTilesInDistanceRange(1..bullyRange)
|
||||
val forceNearCity = inRangeTiles
|
||||
.sumOf { if (it.militaryUnit?.civInfo == demandingCiv)
|
||||
it.militaryUnit!!.getForceEvaluation()
|
||||
else 0
|
||||
}
|
||||
val csForce = civInfo.getCapital().getForceEvaluation() + inRangeTiles
|
||||
val csForce = civInfo.getCapital()!!.getForceEvaluation() + inRangeTiles
|
||||
.sumOf { if (it.militaryUnit?.civInfo == civInfo)
|
||||
it.militaryUnit!!.getForceEvaluation()
|
||||
else 0
|
||||
@ -426,7 +426,7 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
|
||||
it.value.isCivilian() && it.value.isBuildable(civInfo)
|
||||
}
|
||||
if (buildableWorkerLikeUnits.isEmpty()) return // Bad luck?
|
||||
demandingCiv.placeUnitNearTile(civInfo.getCapital().location, buildableWorkerLikeUnits.keys.random())
|
||||
demandingCiv.placeUnitNearTile(civInfo.getCapital()!!.location, buildableWorkerLikeUnits.keys.random())
|
||||
|
||||
civInfo.getDiplomacyManager(demandingCiv).addInfluence(-50f)
|
||||
cityStateBullied(demandingCiv)
|
||||
@ -660,7 +660,7 @@ class CityStateFunctions(val civInfo: CivilizationInfo) {
|
||||
) {
|
||||
thirdCiv.addNotification(
|
||||
"[${civInfo.civName}] is being attacked by [${attacker.civName}] and asks all major civilizations to help them out by gifting them military units.",
|
||||
civInfo.getCapital().location,
|
||||
civInfo.getCapital()!!.location,
|
||||
civInfo.civName,
|
||||
"OtherIcons/Present",
|
||||
)
|
||||
|
@ -145,13 +145,13 @@ class CivInfoTransientUpdater(val civInfo: CivilizationInfo) {
|
||||
}
|
||||
|
||||
fun updateCitiesConnectedToCapital(initialSetup: Boolean = false) {
|
||||
if (civInfo.cities.isEmpty()) return // eg barbarians
|
||||
if (civInfo.cities.isEmpty() || civInfo.getCapital() == null) return // eg barbarians
|
||||
|
||||
val citiesReachedToMediums = CapitalConnectionsFinder(civInfo).find()
|
||||
|
||||
if (!initialSetup) { // In the initial setup we're loading an old game state, so it doesn't really count
|
||||
for (city in citiesReachedToMediums.keys)
|
||||
if (city !in civInfo.citiesConnectedToCapitalToMediums && city.civInfo == civInfo && city != civInfo.getCapital())
|
||||
if (city !in civInfo.citiesConnectedToCapitalToMediums && city.civInfo == civInfo && city != civInfo.getCapital()!!)
|
||||
civInfo.addNotification("[${city.name}] has been connected to your capital!", city.location, NotificationIcon.Gold)
|
||||
|
||||
// This may still contain cities that have just been destroyed by razing - thus the population test
|
||||
|
@ -303,7 +303,7 @@ class CivilizationInfo {
|
||||
compareByDescending<CivilizationInfo> { it.isMajorCiv() }
|
||||
.thenBy (UncivGame.Current.settings.getCollatorFromLocale()) { it.civName.tr() }
|
||||
)
|
||||
fun getCapital() = cities.first { it.isCapital() }
|
||||
fun getCapital() = cities.firstOrNull { it.isCapital() }
|
||||
fun isPlayerCivilization() = playerType == PlayerType.Human
|
||||
fun isOneCityChallenger() = (
|
||||
playerType == PlayerType.Human &&
|
||||
@ -536,7 +536,7 @@ class CivilizationInfo {
|
||||
if (!(isCityState() && otherCiv.isMajorCiv())) return
|
||||
if (warOnContact || otherCiv.isMinorCivAggressor()) return // No gift if they are bad people, or we are just about to be at war
|
||||
|
||||
val cityStateLocation = if (cities.isEmpty()) null else getCapital().location
|
||||
val cityStateLocation = if (cities.isEmpty()) null else getCapital()!!.location
|
||||
|
||||
val giftAmount = Stats(gold = 15f)
|
||||
val faithAmount = Stats(faith = 4f)
|
||||
@ -563,7 +563,7 @@ class CivilizationInfo {
|
||||
otherCiv.addStat(key, value.toInt())
|
||||
|
||||
if (cities.isNotEmpty())
|
||||
otherCiv.exploredTiles = otherCiv.exploredTiles.withItem(getCapital().location)
|
||||
otherCiv.exploredTiles = otherCiv.exploredTiles.withItem(getCapital()!!.location)
|
||||
|
||||
questManager.justMet(otherCiv) // Include them in war with major pseudo-quest
|
||||
}
|
||||
@ -1000,6 +1000,7 @@ class CivilizationInfo {
|
||||
flagsCountdown[CivFlags.ShowDiplomaticVotingResults.name] == 0
|
||||
&& gameInfo.civilizations.any { it.isMajorCiv() && !it.isDefeated() && it != this }
|
||||
|
||||
|
||||
private fun updateRevolts() {
|
||||
if (gameInfo.civilizations.none { it.isBarbarian() }) {
|
||||
// Can't spawn revolts without barbarians ¯\_(ツ)_/¯
|
||||
@ -1272,7 +1273,7 @@ class CivilizationInfo {
|
||||
|
||||
// Check if different continents (unless already max distance, or water map)
|
||||
if (connections > 0 && proximity != Proximity.Distant && !gameInfo.tileMap.isWaterMap()
|
||||
&& getCapital().getCenterTile().getContinent() != otherCiv.getCapital().getCenterTile().getContinent()
|
||||
&& getCapital()!!.getCenterTile().getContinent() != otherCiv.getCapital()!!.getCenterTile().getContinent()
|
||||
) {
|
||||
// Different continents - increase separation by one step
|
||||
proximity = when (proximity) {
|
||||
@ -1299,8 +1300,9 @@ class CivilizationInfo {
|
||||
* Removes current capital then moves capital to argument city if not null
|
||||
*/
|
||||
fun moveCapitalTo(city: CityInfo?) {
|
||||
if (cities.isNotEmpty()) {
|
||||
getCapital().cityConstructions.removeBuilding(getCapital().capitalCityIndicator())
|
||||
if (cities.isNotEmpty() && getCapital() != null) {
|
||||
val oldCapital = getCapital()!!
|
||||
oldCapital.cityConstructions.removeBuilding(oldCapital.capitalCityIndicator())
|
||||
}
|
||||
|
||||
if (city == null) return // can't move a non-existent city but we can always remove our old capital
|
||||
@ -1311,7 +1313,7 @@ class CivilizationInfo {
|
||||
|
||||
fun moveCapitalToNextLargest() {
|
||||
moveCapitalTo(cities
|
||||
.filterNot { it == getCapital() }
|
||||
.filterNot { it.isCapital() }
|
||||
.maxByOrNull { it.population.population})
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ class QuestManager {
|
||||
&& !it.isAtWarWith(civInfo)
|
||||
&& it.getProximity(civInfo) <= Proximity.Far }) {
|
||||
otherCiv.addNotification("[${civInfo.civName}] is being invaded by Barbarians! Destroy Barbarians near their territory to earn Influence.",
|
||||
civInfo.getCapital().location, civInfo.civName, NotificationIcon.War)
|
||||
civInfo.getCapital()!!.location, civInfo.civName, NotificationIcon.War)
|
||||
}
|
||||
civInfo.addFlag(CivFlags.TurnsTillCallForBarbHelp.name, 30)
|
||||
}
|
||||
@ -358,10 +358,10 @@ class QuestManager {
|
||||
return when (quest.name) {
|
||||
QuestName.ClearBarbarianCamp.value -> getBarbarianEncampmentForQuest() != null
|
||||
QuestName.Route.value -> !challenger.cities.none()
|
||||
&& !challenger.isCapitalConnectedToCity(civInfo.getCapital())
|
||||
&& !challenger.isCapitalConnectedToCity(civInfo.getCapital()!!)
|
||||
// Need to have a city within 7 tiles on the same continent
|
||||
&& challenger.cities.any { it.getCenterTile().aerialDistanceTo(civInfo.getCapital().getCenterTile()) <= 7
|
||||
&& it.getCenterTile().getContinent() == civInfo.getCapital().getCenterTile().getContinent() }
|
||||
&& challenger.cities.any { it.getCenterTile().aerialDistanceTo(civInfo.getCapital()!!.getCenterTile()) <= 7
|
||||
&& it.getCenterTile().getContinent() == civInfo.getCapital()!!.getCenterTile().getContinent() }
|
||||
QuestName.ConnectResource.value -> getResourceForQuest(challenger) != null
|
||||
QuestName.ConstructWonder.value -> getWonderToBuildForQuest(challenger) != null
|
||||
QuestName.GreatPerson.value -> getGreatPersonForQuest(challenger) != null
|
||||
@ -373,7 +373,7 @@ class QuestManager {
|
||||
&& !challenger.getDiplomacyManager(mostRecentBully).hasFlag(DiplomacyFlags.Denunciation)
|
||||
&& challenger.getDiplomacyManager(mostRecentBully).diplomaticStatus != DiplomaticStatus.War
|
||||
&& !( challenger.playerType == PlayerType.Human && civInfo.gameInfo.getCivilization(mostRecentBully).playerType == PlayerType.Human)
|
||||
QuestName.SpreadReligion.value -> playerReligion != null && civInfo.getCapital().religion.getMajorityReligion()?.name != playerReligion
|
||||
QuestName.SpreadReligion.value -> playerReligion != null && civInfo.getCapital()!!.religion.getMajorityReligion()?.name != playerReligion
|
||||
QuestName.ConquerCityState.value -> getCityStateTarget(challenger) != null && civInfo.cityStatePersonality != CityStatePersonality.Friendly
|
||||
QuestName.BullyCityState.value -> getCityStateTarget(challenger) != null
|
||||
QuestName.ContestFaith.value -> civInfo.gameInfo.isReligionEnabled()
|
||||
@ -385,7 +385,7 @@ class QuestManager {
|
||||
private fun isComplete(assignedQuest: AssignedQuest): Boolean {
|
||||
val assignee = civInfo.gameInfo.getCivilization(assignedQuest.assignee)
|
||||
return when (assignedQuest.questName) {
|
||||
QuestName.Route.value -> assignee.isCapitalConnectedToCity(civInfo.getCapital())
|
||||
QuestName.Route.value -> assignee.isCapitalConnectedToCity(civInfo.getCapital()!!)
|
||||
QuestName.ConnectResource.value -> assignee.detailedCivResources.map { it.resource }.contains(civInfo.gameInfo.ruleSet.tileResources[assignedQuest.data1])
|
||||
QuestName.ConstructWonder.value -> assignee.cities.any { it.cityConstructions.isBuilt(assignedQuest.data1) }
|
||||
QuestName.GreatPerson.value -> assignee.getCivGreatPeople().any { it.baseUnit.getReplacedUnit(civInfo.gameInfo.ruleSet).name == assignedQuest.data1 }
|
||||
@ -393,7 +393,7 @@ class QuestManager {
|
||||
QuestName.FindNaturalWonder.value -> assignee.naturalWonders.contains(assignedQuest.data1)
|
||||
QuestName.PledgeToProtect.value -> assignee in civInfo.getProtectorCivs()
|
||||
QuestName.DenounceCiv.value -> assignee.getDiplomacyManager(assignedQuest.data1).hasFlag(DiplomacyFlags.Denunciation)
|
||||
QuestName.SpreadReligion.value -> civInfo.getCapital().religion.getMajorityReligion() == civInfo.gameInfo.religions[assignedQuest.data2]
|
||||
QuestName.SpreadReligion.value -> civInfo.getCapital()!!.religion.getMajorityReligion() == civInfo.gameInfo.religions[assignedQuest.data2]
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
@ -421,7 +421,7 @@ class QuestManager {
|
||||
if (rewardInfluence > 0)
|
||||
assignee.addNotification(
|
||||
"[${civInfo.civName}] rewarded you with [${rewardInfluence.toInt()}] influence for completing the [${assignedQuest.questName}] quest.",
|
||||
civInfo.getCapital().location, civInfo.civName, "OtherIcons/Quest"
|
||||
civInfo.getCapital()!!.location, civInfo.civName, "OtherIcons/Quest"
|
||||
)
|
||||
|
||||
// We may have received bonuses from city-state friend-ness or ally-ness
|
||||
@ -436,11 +436,11 @@ class QuestManager {
|
||||
if (winners.isEmpty()) {
|
||||
assignee.addNotification(
|
||||
"[${civInfo.civName}] no longer needs your help with the [${assignedQuest.questName}] quest.",
|
||||
civInfo.getCapital().location, civInfo.civName, "OtherIcons/Quest")
|
||||
civInfo.getCapital()!!.location, civInfo.civName, "OtherIcons/Quest")
|
||||
} else {
|
||||
assignee.addNotification(
|
||||
"The [${assignedQuest.questName}] quest for [${civInfo.civName}] has ended. It was won by [${winners.joinToString { it.assignee.tr() }}].",
|
||||
civInfo.getCapital().location, civInfo.civName, "OtherIcons/Quest")
|
||||
civInfo.getCapital()!!.location, civInfo.civName, "OtherIcons/Quest")
|
||||
}
|
||||
}
|
||||
|
||||
@ -532,8 +532,8 @@ class QuestManager {
|
||||
unitsToKillForCiv[attacker.civName] = unitsToKill
|
||||
|
||||
|
||||
val location = if (civInfo.cities.isEmpty()) null
|
||||
else civInfo.getCapital().location
|
||||
val location = if (civInfo.cities.isEmpty() || civInfo.getCapital() == null) null
|
||||
else civInfo.getCapital()!!.location
|
||||
|
||||
// Ask for assistance
|
||||
for (thirdCiv in civInfo.getKnownCivs().filter { it.isAlive() && !it.isAtWarWith(civInfo) && it.isMajorCiv() }) {
|
||||
@ -571,8 +571,8 @@ class QuestManager {
|
||||
|
||||
/** Called when a major civ meets the city-state for the first time. Mainly for war with major pseudo-quest. */
|
||||
fun justMet(otherCiv: CivilizationInfo) {
|
||||
val location = if (civInfo.cities.isEmpty()) null
|
||||
else civInfo.getCapital().location
|
||||
val location = if (civInfo.cities.isEmpty() || civInfo.getCapital() == null) null
|
||||
else civInfo.getCapital()!!.location
|
||||
|
||||
for ((attackerName, unitsToKill) in unitsToKillForCiv) {
|
||||
if (location != null)
|
||||
@ -755,7 +755,7 @@ class QuestManager {
|
||||
* to be destroyed
|
||||
*/
|
||||
private fun getBarbarianEncampmentForQuest(): TileInfo? {
|
||||
val encampments = civInfo.getCapital().getCenterTile().getTilesInDistance(8)
|
||||
val encampments = civInfo.getCapital()!!.getCenterTile().getTilesInDistance(8)
|
||||
.filter { it.improvement == Constants.barbarianEncampment }.toList()
|
||||
|
||||
if (encampments.isNotEmpty())
|
||||
@ -923,7 +923,7 @@ class AssignedQuest(val questName: String = "",
|
||||
}
|
||||
QuestName.Route.value -> {
|
||||
game.resetToWorldScreen()
|
||||
game.worldScreen.mapHolder.setCenterPosition(gameInfo.getCivilization(assigner).getCapital().location, selectUnit = false)
|
||||
game.worldScreen.mapHolder.setCenterPosition(gameInfo.getCivilization(assigner).getCapital()!!.location, selectUnit = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -240,9 +240,9 @@ class DiplomacyManager() {
|
||||
for (unique in otherCiv().getMatchingUniques(UniqueType.CityStateRestingPoint))
|
||||
restingPoint += unique.params[0].toInt()
|
||||
|
||||
if (civInfo.cities.any()) // no capital if no cities
|
||||
if (civInfo.cities.any() && civInfo.getCapital() != null)
|
||||
for (unique in otherCiv().getMatchingUniques(UniqueType.RestingPointOfCityStatesFollowingReligionChange))
|
||||
if (otherCiv().religionManager.religion?.name == civInfo.getCapital().religion.getMajorityReligionName())
|
||||
if (otherCiv().religionManager.religion?.name == civInfo.getCapital()!!.religion.getMajorityReligionName())
|
||||
restingPoint += unique.params[0].toInt()
|
||||
|
||||
if (diplomaticStatus == DiplomaticStatus.Protector) restingPoint += 10
|
||||
@ -266,8 +266,8 @@ class DiplomacyManager() {
|
||||
for (unique in otherCiv().getMatchingUniques(UniqueType.CityStateInfluenceDegradation))
|
||||
modifierPercent += unique.params[0].toFloat()
|
||||
|
||||
val religion = if (civInfo.cities.isEmpty()) null
|
||||
else civInfo.getCapital().religion.getMajorityReligionName()
|
||||
val religion = if (civInfo.cities.isEmpty() || civInfo.getCapital() == null) null
|
||||
else civInfo.getCapital()!!.religion.getMajorityReligionName()
|
||||
if (religion != null && religion == otherCiv().religionManager.religion?.name)
|
||||
modifierPercent -= 25f // 25% slower degrade when sharing a religion
|
||||
|
||||
@ -291,8 +291,8 @@ class DiplomacyManager() {
|
||||
if (otherCiv().hasUnique(UniqueType.CityStateInfluenceRecoversTwiceNormalRate))
|
||||
modifierPercent += 100f
|
||||
|
||||
val religion = if (civInfo.cities.isEmpty()) null
|
||||
else civInfo.getCapital().religion.getMajorityReligionName()
|
||||
val religion = if (civInfo.cities.isEmpty() || civInfo.getCapital() == null) null
|
||||
else civInfo.getCapital()!!.religion.getMajorityReligionName()
|
||||
if (religion != null && religion == otherCiv().religionManager.religion?.name)
|
||||
modifierPercent += 50f // 50% quicker recovery when sharing a religion
|
||||
|
||||
@ -456,7 +456,7 @@ class DiplomacyManager() {
|
||||
}
|
||||
|
||||
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().location else null
|
||||
val civCapitalLocation = if (civInfo.cities.isNotEmpty() || 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, civCapitalLocation, civInfo.civName, NotificationIcon.Diplomacy)
|
||||
|
@ -230,7 +230,7 @@ class TradeEvaluation {
|
||||
val city = civInfo.cities.firstOrNull { it.id == offer.name }
|
||||
?: throw Exception("Got an offer to sell city id " + offer.name + " which does't seem to exist for this civ!")
|
||||
|
||||
val capitalcity = civInfo.getCapital()
|
||||
val capitalcity = civInfo.getCapital()!!
|
||||
val distanceCost = distanceCityTradeModifier(civInfo, capitalcity, city)
|
||||
val stats = city.cityStats.currentCityStats
|
||||
val sumOfStats =
|
||||
|
@ -219,8 +219,8 @@ class Unique(val text: String, val sourceObjectType: UniqueTarget? = null, val s
|
||||
}
|
||||
UniqueType.ConditionalForeignContinent ->
|
||||
state.civInfo != null && relevantTile != null
|
||||
&& (state.civInfo.cities.isEmpty()
|
||||
|| state.civInfo.getCapital().getCenterTile().getContinent()
|
||||
&& (state.civInfo.cities.isEmpty() || state.civInfo.getCapital() == null
|
||||
|| state.civInfo.getCapital()!!.getCenterTile().getContinent()
|
||||
!= relevantTile!!.getContinent()
|
||||
)
|
||||
UniqueType.ConditionalAdjacentUnit ->
|
||||
|
@ -491,7 +491,7 @@ class DiplomacyScreen(
|
||||
return diplomacyTable
|
||||
}
|
||||
|
||||
fun getImprovableResourceTiles(otherCiv:CivilizationInfo) = otherCiv.getCapital().getTiles().filter {
|
||||
fun getImprovableResourceTiles(otherCiv:CivilizationInfo) = otherCiv.getCapital()!!.getTiles().filter {
|
||||
it.hasViewableResource(otherCiv)
|
||||
&& it.tileResource.resourceType != ResourceType.Bonus
|
||||
&& (it.improvement == null || !it.tileResource.isImprovedBy(it.improvement!!))
|
||||
@ -751,7 +751,7 @@ class DiplomacyScreen(
|
||||
diplomacyTable.add(demandsButton).row()
|
||||
if (isNotPlayersTurn()) demandsButton.disable()
|
||||
|
||||
if (otherCiv.cities.isNotEmpty() && otherCiv.getCapital().location in viewingCiv.exploredTiles)
|
||||
if (otherCiv.cities.isNotEmpty() && otherCiv.getCapital() != null && otherCiv.getCapital()!!.location in viewingCiv.exploredTiles)
|
||||
diplomacyTable.add(getGoToOnMapButton(otherCiv)).row()
|
||||
|
||||
if (!otherCiv.isPlayerCivilization()) { // human players make their own choices
|
||||
@ -938,7 +938,7 @@ class DiplomacyScreen(
|
||||
val goToOnMapButton = "Go to on map".toTextButton()
|
||||
goToOnMapButton.onClick {
|
||||
UncivGame.Current.resetToWorldScreen()
|
||||
UncivGame.Current.worldScreen.mapHolder.setCenterPosition(civilization.getCapital().location, selectUnit = false)
|
||||
UncivGame.Current.worldScreen.mapHolder.setCenterPosition(civilization.getCapital()!!.location, selectUnit = false)
|
||||
}
|
||||
return goToOnMapButton
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Bas
|
||||
|
||||
val tileToCenterOn: Vector2 =
|
||||
when {
|
||||
viewingCiv.cities.isNotEmpty() -> viewingCiv.getCapital().location
|
||||
viewingCiv.cities.isNotEmpty() && viewingCiv.getCapital() != null -> viewingCiv.getCapital()!!.location
|
||||
viewingCiv.getCivUnits().any() -> viewingCiv.getCivUnits().first().getTile().position
|
||||
else -> Vector2.Zero
|
||||
}
|
||||
@ -282,7 +282,7 @@ class WorldScreen(val gameInfo: GameInfo, val viewingCiv:CivilizationInfo) : Bas
|
||||
keyPressDispatcher[Input.Keys.F12] = quickLoad // Quick Load
|
||||
keyPressDispatcher[Input.Keys.HOME] = { // Capital City View
|
||||
val capital = gameInfo.currentPlayerCiv.getCapital()
|
||||
if (!mapHolder.setCenterPosition(capital.location))
|
||||
if (capital != null && !mapHolder.setCenterPosition(capital.location))
|
||||
game.setScreen(CityScreen(capital))
|
||||
}
|
||||
keyPressDispatcher[KeyCharAndCode.ctrl('O')] = { // Game Options
|
||||
|
Loading…
Reference in New Issue
Block a user