mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-30 07:21:34 -04:00
#9098 - getKnownCivs returns sequence
This commit is contained in:
parent
a37391781a
commit
d6f5e0badb
@ -199,9 +199,11 @@ class GameInfo : IsPartOfGameInfoSerialization, HasGameInfoSerializationVersion
|
||||
}
|
||||
}
|
||||
|
||||
@delegate:Transient
|
||||
val civMap by lazy { civilizations.associateBy { it.civName } }
|
||||
/** Get a civ by name
|
||||
* @throws NoSuchElementException if no civ of that name is in the game (alive or dead)! */
|
||||
fun getCivilization(civName: String) = civilizations.first { it.civName == civName }
|
||||
fun getCivilization(civName: String) = civMap.getValue(civName)
|
||||
fun getCurrentPlayerCivilization() = currentPlayerCiv
|
||||
fun getCivilizationsAsPreviews() = civilizations.map { it.asPreview() }.toMutableList()
|
||||
/** Get barbarian civ
|
||||
|
@ -303,7 +303,7 @@ object NextTurnAutomation {
|
||||
|
||||
if (!civInfo.isCityState()) {
|
||||
val potentialAllies = civInfo.getKnownCivs().filter { it.isCityState() }
|
||||
if (potentialAllies.isNotEmpty()) {
|
||||
if (potentialAllies.any()) {
|
||||
val cityState =
|
||||
potentialAllies.maxByOrNull { valueCityStateAlliance(civInfo, it) }!!
|
||||
if (cityState.getAllyCiv() != civInfo.civName && valueCityStateAlliance(civInfo, cityState) > 0) {
|
||||
@ -793,7 +793,7 @@ object NextTurnAutomation {
|
||||
// If the AI declares war on a civ without knowing the location of any cities, it'll just keep amassing an army and not sending it anywhere,
|
||||
// and end up at a massive disadvantage
|
||||
|
||||
if (enemyCivs.isEmpty()) return
|
||||
if (enemyCivs.none()) return
|
||||
|
||||
val civWithBestMotivationToAttack = enemyCivs
|
||||
.map { Pair(it, motivationToAttack(civInfo, it)) }
|
||||
@ -1014,7 +1014,7 @@ object NextTurnAutomation {
|
||||
}
|
||||
|
||||
if (highestOpinion == null) null
|
||||
else knownMajorCivs.filter { civInfo.getDiplomacyManager(it).opinionOfOtherCiv() == highestOpinion}.random().civName
|
||||
else knownMajorCivs.filter { civInfo.getDiplomacyManager(it).opinionOfOtherCiv() == highestOpinion}.toList().random().civName
|
||||
|
||||
} else {
|
||||
civInfo.getAllyCiv()
|
||||
|
@ -489,7 +489,7 @@ class WorkerAutomation(
|
||||
val enemyCivs = civInfo.getKnownCivs()
|
||||
.filterNot { it == civInfo || it.cities.isEmpty() || !civInfo.getDiplomacyManager(it).canAttack() }
|
||||
// no potential enemies
|
||||
if (enemyCivs.isEmpty()) return false
|
||||
if (enemyCivs.none()) return false
|
||||
|
||||
val threatMapping: (Civilization) -> Int = {
|
||||
// the war is already a good nudge to build forts
|
||||
@ -507,7 +507,7 @@ class WorkerAutomation(
|
||||
civInfo,
|
||||
it) <= threatMapping(it) }
|
||||
// no threat, let's not build fort
|
||||
if (enemyCivsIsCloseEnough.isEmpty()) return false
|
||||
if (enemyCivsIsCloseEnough.none()) return false
|
||||
|
||||
// make list of enemy cities as sources of threat
|
||||
val enemyCities = mutableListOf<Tile>()
|
||||
|
@ -310,7 +310,7 @@ class Civilization : IsPartOfGameInfoSerialization {
|
||||
fun getProximity(civName: String) = proximity[civName] ?: Proximity.None
|
||||
|
||||
/** Returns only undefeated civs, aka the ones we care about */
|
||||
fun getKnownCivs() = diplomacy.values.map { it.otherCiv() }.filter { !it.isDefeated() }
|
||||
fun getKnownCivs() = diplomacy.values.asSequence().map { it.otherCiv() }.filter { !it.isDefeated() }
|
||||
fun knows(otherCivName: String) = diplomacy.containsKey(otherCivName)
|
||||
fun knows(otherCiv: Civilization) = knows(otherCiv.civName)
|
||||
|
||||
|
@ -416,7 +416,7 @@ class DiplomacyManager() : IsPartOfGameInfoSerialization {
|
||||
}
|
||||
|
||||
/** Returns the [civilizations][Civilization] that know about both sides ([civInfo] and [otherCiv]) */
|
||||
fun getCommonKnownCivs(): Set<Civilization> = civInfo.getKnownCivs().intersect(otherCiv().getKnownCivs().toSet())
|
||||
fun getCommonKnownCivs(): Set<Civilization> = civInfo.getKnownCivs().toSet().intersect(otherCiv().getKnownCivs().toSet())
|
||||
|
||||
/** Returns true when the [civInfo]'s territory is considered allied for [otherCiv].
|
||||
* This includes friendly and allied city-states and the open border treaties.
|
||||
|
@ -3,7 +3,6 @@ package com.unciv.logic.civilization.managers
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.unciv.Constants
|
||||
import com.unciv.GUI
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.IsPartOfGameInfoSerialization
|
||||
import com.unciv.logic.civilization.CivFlags
|
||||
@ -779,8 +778,8 @@ class QuestManager : IsPartOfGameInfoSerialization {
|
||||
val civilizationsToFind = challenger.getKnownCivs()
|
||||
.filter { it.isAlive() && it.isMajorCiv() && !challenger.hasMetCivTerritory(it) }
|
||||
|
||||
if (civilizationsToFind.isNotEmpty())
|
||||
return civilizationsToFind.random()
|
||||
if (civilizationsToFind.any())
|
||||
return civilizationsToFind.toList().random()
|
||||
|
||||
return null
|
||||
}
|
||||
@ -798,7 +797,7 @@ class QuestManager : IsPartOfGameInfoSerialization {
|
||||
val validTargets = civInfo.getKnownCivs().filter { it.isCityState() && challenger.knows(it)
|
||||
&& civInfo.proximity[it.civName] == closestProximity }
|
||||
|
||||
return validTargets.randomOrNull()
|
||||
return validTargets.toList().randomOrNull()
|
||||
}
|
||||
|
||||
/** Returns a [Civilization] of the civ that most recently bullied [civInfo].
|
||||
|
@ -92,7 +92,7 @@ class TurnManager(val civInfo: Civilization) {
|
||||
|
||||
if (flag == CivFlags.CityStateGreatPersonGift.name) {
|
||||
val cityStateAllies: List<Civilization> =
|
||||
civInfo.getKnownCivs().filter { it.isCityState() && it.getAllyCiv() == civInfo.civName }
|
||||
civInfo.getKnownCivs().filter { it.isCityState() && it.getAllyCiv() == civInfo.civName }.toList()
|
||||
val givingCityState = cityStateAllies.filter { it.cities.isNotEmpty() }.randomOrNull()
|
||||
|
||||
if (cityStateAllies.isNotEmpty()) civInfo.flagsCountdown[flag] = civInfo.flagsCountdown[flag]!! - 1
|
||||
|
@ -97,7 +97,6 @@ open class Tile : IsPartOfGameInfoSerialization {
|
||||
private set
|
||||
|
||||
@Transient
|
||||
/** Saves a sequence of a list */
|
||||
lateinit var lastTerrain: Terrain
|
||||
private set
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user