mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-04 22:50:50 +07:00
chore: More civinfo cleanup
This commit is contained in:
parent
e4fd6ff069
commit
a5a50a30e1
@ -651,13 +651,7 @@ class CivilizationInfo : IsPartOfGameInfoSerialization {
|
||||
questManager.justMet(otherCiv) // Include them in war with major pseudo-quest
|
||||
}
|
||||
|
||||
fun discoverNaturalWonder(naturalWonderName: String) {
|
||||
naturalWonders.add(naturalWonderName)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return civName
|
||||
} // for debug
|
||||
override fun toString(): String = civName // for debug
|
||||
|
||||
/**
|
||||
* Determine loss conditions.
|
||||
@ -689,15 +683,6 @@ class CivilizationInfo : IsPartOfGameInfoSerialization {
|
||||
|
||||
fun isAtWar() = diplomacy.values.any { it.diplomaticStatus == DiplomaticStatus.War && !it.otherCiv().isDefeated() }
|
||||
|
||||
fun canEnterBordersOf(otherCiv: CivilizationInfo): Boolean {
|
||||
if (otherCiv == this) return true // own borders are always open
|
||||
if (otherCiv.isBarbarian() || isBarbarian()) return false // barbarians blocks the routes
|
||||
val diplomacyManager = diplomacy[otherCiv.civName]
|
||||
?: return false // not encountered yet
|
||||
if (otherCiv.isCityState() && diplomacyManager.diplomaticStatus != DiplomaticStatus.War) return true
|
||||
return diplomacyManager.hasOpenBorders
|
||||
}
|
||||
|
||||
fun getEnemyMovementPenalty(enemyUnit: MapUnit): Float {
|
||||
if (enemyMovementPenaltyUniques != null && enemyMovementPenaltyUniques!!.any()) {
|
||||
return enemyMovementPenaltyUniques!!.sumOf {
|
||||
@ -784,16 +769,6 @@ class CivilizationInfo : IsPartOfGameInfoSerialization {
|
||||
return sum
|
||||
}
|
||||
|
||||
|
||||
fun getGreatPeople(): HashSet<BaseUnit> {
|
||||
val greatPeople = gameInfo.ruleSet.units.values.asSequence()
|
||||
.filter { it.isGreatPerson() }
|
||||
.map { getEquivalentUnit(it.name) }
|
||||
return if (!gameInfo.isReligionEnabled())
|
||||
greatPeople.filter { !it.hasUnique(UniqueType.HiddenWithoutReligion) }.toHashSet()
|
||||
else greatPeople.toHashSet()
|
||||
}
|
||||
|
||||
fun hasTechOrPolicy(techOrPolicyName: String) =
|
||||
tech.isResearched(techOrPolicyName) || policies.isAdopted(techOrPolicyName)
|
||||
|
||||
|
@ -3,6 +3,8 @@ package com.unciv.logic.civilization.managers
|
||||
import com.unciv.logic.IsPartOfGameInfoSerialization
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.Counter
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import com.unciv.models.ruleset.unit.BaseUnit
|
||||
|
||||
// todo: Great Admiral?
|
||||
// todo: Free GP from policies and wonders should increase threshold according to the wiki
|
||||
@ -62,4 +64,13 @@ class GreatPersonManager : IsPartOfGameInfoSerialization {
|
||||
}
|
||||
|
||||
|
||||
fun getGreatPeople(): HashSet<BaseUnit> {
|
||||
val greatPeople = civInfo.gameInfo.ruleSet.units.values.asSequence()
|
||||
.filter { it.isGreatPerson() }
|
||||
.map { civInfo.getEquivalentUnit(it.name) }
|
||||
return if (!civInfo.gameInfo.isReligionEnabled())
|
||||
greatPeople.filter { !it.hasUnique(UniqueType.HiddenWithoutReligion) }.toHashSet()
|
||||
else greatPeople.toHashSet()
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -755,7 +755,7 @@ class QuestManager : IsPartOfGameInfoSerialization {
|
||||
val challengerGreatPeople = challenger.getCivGreatPeople().map { it.baseUnit.getReplacedUnit(ruleSet) }
|
||||
val cityStateGreatPeople = civInfo.getCivGreatPeople().map { it.baseUnit.getReplacedUnit(ruleSet) }
|
||||
|
||||
val greatPeople = challenger.getGreatPeople()
|
||||
val greatPeople = challenger.greatPeople.getGreatPeople()
|
||||
.map { it.getReplacedUnit(ruleSet) }
|
||||
.distinct()
|
||||
.filterNot { challengerGreatPeople.contains(it)
|
||||
|
@ -2,6 +2,7 @@ package com.unciv.logic.civilization.transients
|
||||
|
||||
import com.unciv.logic.city.CityInfo
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
||||
import com.unciv.logic.map.BFS
|
||||
import com.unciv.logic.map.RoadStatus
|
||||
import com.unciv.logic.map.TileInfo
|
||||
@ -13,7 +14,7 @@ class CapitalConnectionsFinder(private val civInfo: CivilizationInfo) {
|
||||
private var citiesToCheck = mutableListOf(civInfo.getCapital()!!)
|
||||
private lateinit var newCitiesToCheck: MutableList<CityInfo>
|
||||
|
||||
private val openBordersCivCities = civInfo.gameInfo.getCities().filter { civInfo.canEnterBordersOf(it.civInfo) }
|
||||
private val openBordersCivCities = civInfo.gameInfo.getCities().filter { canEnterBordersOf(it.civInfo) }
|
||||
|
||||
private val harbor = "Harbor" // hardcoding at least centralized for this class for now
|
||||
private val road = RoadStatus.Road.name
|
||||
@ -96,7 +97,7 @@ class CapitalConnectionsFinder(private val civInfo: CivilizationInfo) {
|
||||
|
||||
val bfs = BFS(cityToConnectFrom.getCenterTile()) {
|
||||
val owner = it.getOwner()
|
||||
(it.isCityCenter() || tileFilter(it)) && (owner == null || civInfo.canEnterBordersOf(owner))
|
||||
(it.isCityCenter() || tileFilter(it)) && (owner == null || canEnterBordersOf(owner))
|
||||
}
|
||||
bfs.stepToEnd()
|
||||
val reachedCities = openBordersCivCities.filter {
|
||||
@ -126,4 +127,14 @@ class CapitalConnectionsFinder(private val civInfo: CivilizationInfo) {
|
||||
citiesReachedToMediums[this]!!.add(transportType)
|
||||
}
|
||||
|
||||
|
||||
private fun canEnterBordersOf(otherCiv: CivilizationInfo): Boolean {
|
||||
if (otherCiv == civInfo) return true // own borders are always open
|
||||
if (otherCiv.isBarbarian() || civInfo.isBarbarian()) return false // barbarians blocks the routes
|
||||
val diplomacyManager = civInfo.diplomacy[otherCiv.civName]
|
||||
?: return false // not encountered yet
|
||||
if (otherCiv.isCityState() && diplomacyManager.diplomaticStatus != DiplomaticStatus.War) return true
|
||||
return diplomacyManager.hasOpenBorders
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ class CivInfoTransientCache(val civInfo: CivilizationInfo) {
|
||||
// GBR could be discovered twice otherwise!
|
||||
if (civInfo.naturalWonders.contains(tile.naturalWonder))
|
||||
continue
|
||||
civInfo.discoverNaturalWonder(tile.naturalWonder!!)
|
||||
civInfo.naturalWonders.add(tile.naturalWonder!!)
|
||||
civInfo.addNotification("We have discovered [${tile.naturalWonder}]!",
|
||||
tile.position, NotificationCategory.General, "StatIcons/Happiness")
|
||||
|
||||
|
@ -175,7 +175,7 @@ object UniqueTriggerActivation {
|
||||
|
||||
OneTimeFreeGreatPerson, MayanGainGreatPerson -> {
|
||||
if (civInfo.isSpectator()) return false
|
||||
val greatPeople = civInfo.getGreatPeople()
|
||||
val greatPeople = civInfo.greatPeople.getGreatPeople()
|
||||
if (unique.type == MayanGainGreatPerson && civInfo.greatPeople.longCountGPPool.isEmpty())
|
||||
civInfo.greatPeople.longCountGPPool = greatPeople.map { it.name }.toHashSet()
|
||||
if (civInfo.isHuman()) {
|
||||
|
@ -16,7 +16,7 @@ class GreatPersonPickerScreen(val civInfo:CivilizationInfo) : PickerScreen() {
|
||||
closeButton.isVisible = false
|
||||
rightSideButton.setText("Choose a free great person".tr())
|
||||
|
||||
val greatPersonUnits = civInfo.getGreatPeople()
|
||||
val greatPersonUnits = civInfo.greatPeople.getGreatPeople()
|
||||
val useMayaLongCount = civInfo.greatPeople.mayaLimitedFreeGP > 0
|
||||
|
||||
for (unit in greatPersonUnits) {
|
||||
|
Loading…
Reference in New Issue
Block a user