mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-13 12:27:40 +07:00
Moved updateProximity to civ transient updater
This commit is contained in:
parent
b8da124263
commit
515bfcbb6f
@ -2,6 +2,7 @@ package com.unciv.logic.civilization
|
|||||||
|
|
||||||
import com.unciv.Constants
|
import com.unciv.Constants
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
|
import com.unciv.logic.map.MapShape
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
import com.unciv.models.ruleset.tile.ResourceSupplyList
|
import com.unciv.models.ruleset.tile.ResourceSupplyList
|
||||||
import com.unciv.models.ruleset.unique.UniqueType
|
import com.unciv.models.ruleset.unique.UniqueType
|
||||||
@ -70,7 +71,7 @@ class CivInfoTransientUpdater(val civInfo: CivilizationInfo) {
|
|||||||
if (civInfo.isSpectator() || UncivGame.Current.viewEntireMapForDebug) {
|
if (civInfo.isSpectator() || UncivGame.Current.viewEntireMapForDebug) {
|
||||||
val allTiles = civInfo.gameInfo.tileMap.values.toSet()
|
val allTiles = civInfo.gameInfo.tileMap.values.toSet()
|
||||||
civInfo.viewableTiles = allTiles
|
civInfo.viewableTiles = allTiles
|
||||||
civInfo.addExploredTiles(allTiles.map { it.position }.toHashSet()
|
civInfo.addExploredTiles(allTiles.asSequence().map { it.position })
|
||||||
civInfo.viewableInvisibleUnitsTiles = allTiles
|
civInfo.viewableInvisibleUnitsTiles = allTiles
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -204,4 +205,79 @@ class CivInfoTransientUpdater(val civInfo: CivilizationInfo) {
|
|||||||
|
|
||||||
civInfo.updateStatsForNextTurn() // More or less resources = more or less happiness, with potential domino effects
|
civInfo.updateStatsForNextTurn() // More or less resources = more or less happiness, with potential domino effects
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun updateProximity(otherCiv: CivilizationInfo, preCalculated: Proximity? = null): Proximity {
|
||||||
|
if (otherCiv == civInfo) return Proximity.None
|
||||||
|
if (preCalculated != null) {
|
||||||
|
// We usually want to update this for a pair of civs at the same time
|
||||||
|
// Since this function *should* be symmetrical for both civs, we can just do it once
|
||||||
|
civInfo.proximity[otherCiv.civName] = preCalculated
|
||||||
|
return preCalculated
|
||||||
|
}
|
||||||
|
if (civInfo.cities.isEmpty() || otherCiv.cities.isEmpty()) {
|
||||||
|
civInfo.proximity[otherCiv.civName] = Proximity.None
|
||||||
|
return Proximity.None
|
||||||
|
}
|
||||||
|
|
||||||
|
val mapParams = civInfo.gameInfo.tileMap.mapParameters
|
||||||
|
var minDistance = 100000 // a long distance
|
||||||
|
var totalDistance = 0
|
||||||
|
var connections = 0
|
||||||
|
|
||||||
|
var proximity = Proximity.None
|
||||||
|
|
||||||
|
for (ourCity in civInfo.cities) {
|
||||||
|
for (theirCity in otherCiv.cities) {
|
||||||
|
val distance = ourCity.getCenterTile().aerialDistanceTo(theirCity.getCenterTile())
|
||||||
|
totalDistance += distance
|
||||||
|
connections++
|
||||||
|
if (minDistance > distance) minDistance = distance
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minDistance <= 7) {
|
||||||
|
proximity = Proximity.Neighbors
|
||||||
|
} else if (connections > 0) {
|
||||||
|
val averageDistance = totalDistance / connections
|
||||||
|
val mapFactor = if (mapParams.shape == MapShape.rectangular)
|
||||||
|
(mapParams.mapSize.height + mapParams.mapSize.width) / 2
|
||||||
|
else (mapParams.mapSize.radius * 3) / 2 // slightly less area than equal size rect
|
||||||
|
|
||||||
|
val closeDistance = ((mapFactor * 25) / 100).coerceIn(10, 20)
|
||||||
|
val farDistance = ((mapFactor * 45) / 100).coerceIn(20, 50)
|
||||||
|
|
||||||
|
proximity = if (minDistance <= 11 && averageDistance <= closeDistance)
|
||||||
|
Proximity.Close
|
||||||
|
else if (averageDistance <= farDistance)
|
||||||
|
Proximity.Far
|
||||||
|
else
|
||||||
|
Proximity.Distant
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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()
|
||||||
|
) {
|
||||||
|
// Different continents - increase separation by one step
|
||||||
|
proximity = when (proximity) {
|
||||||
|
Proximity.Far -> Proximity.Distant
|
||||||
|
Proximity.Close -> Proximity.Far
|
||||||
|
Proximity.Neighbors -> Proximity.Close
|
||||||
|
else -> proximity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there aren't many players (left) we can't be that far
|
||||||
|
val numMajors = civInfo.gameInfo.getAliveMajorCivs().size
|
||||||
|
if (numMajors <= 2 && proximity > Proximity.Close)
|
||||||
|
proximity = Proximity.Close
|
||||||
|
if (numMajors <= 4 && proximity > Proximity.Far)
|
||||||
|
proximity = Proximity.Far
|
||||||
|
|
||||||
|
civInfo.proximity[otherCiv.civName] = proximity
|
||||||
|
|
||||||
|
return proximity
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import com.unciv.logic.civilization.RuinsManager.RuinsManager
|
|||||||
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
|
import com.unciv.logic.civilization.diplomacy.DiplomacyFlags
|
||||||
import com.unciv.logic.civilization.diplomacy.DiplomacyManager
|
import com.unciv.logic.civilization.diplomacy.DiplomacyManager
|
||||||
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
||||||
import com.unciv.logic.map.MapShape
|
|
||||||
import com.unciv.logic.map.MapUnit
|
import com.unciv.logic.map.MapUnit
|
||||||
import com.unciv.logic.map.TileInfo
|
import com.unciv.logic.map.TileInfo
|
||||||
import com.unciv.logic.map.UnitMovementAlgorithms
|
import com.unciv.logic.map.UnitMovementAlgorithms
|
||||||
@ -1321,78 +1320,7 @@ class CivilizationInfo : IsPartOfGameInfoSerialization {
|
|||||||
).toInt()
|
).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateProximity(otherCiv: CivilizationInfo, preCalculated: Proximity? = null): Proximity {
|
fun updateProximity(otherCiv: CivilizationInfo, preCalculated: Proximity? = null): Proximity = transients().updateProximity(otherCiv, preCalculated)
|
||||||
if (otherCiv == this) return Proximity.None
|
|
||||||
if (preCalculated != null) {
|
|
||||||
// We usually want to update this for a pair of civs at the same time
|
|
||||||
// Since this function *should* be symmetrical for both civs, we can just do it once
|
|
||||||
this.proximity[otherCiv.civName] = preCalculated
|
|
||||||
return preCalculated
|
|
||||||
}
|
|
||||||
if (cities.isEmpty() || otherCiv.cities.isEmpty()) {
|
|
||||||
proximity[otherCiv.civName] = Proximity.None
|
|
||||||
return Proximity.None
|
|
||||||
}
|
|
||||||
|
|
||||||
val mapParams = gameInfo.tileMap.mapParameters
|
|
||||||
var minDistance = 100000 // a long distance
|
|
||||||
var totalDistance = 0
|
|
||||||
var connections = 0
|
|
||||||
|
|
||||||
var proximity = Proximity.None
|
|
||||||
|
|
||||||
for (ourCity in cities) {
|
|
||||||
for (theirCity in otherCiv.cities) {
|
|
||||||
val distance = ourCity.getCenterTile().aerialDistanceTo(theirCity.getCenterTile())
|
|
||||||
totalDistance += distance
|
|
||||||
connections++
|
|
||||||
if (minDistance > distance) minDistance = distance
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (minDistance <= 7) {
|
|
||||||
proximity = Proximity.Neighbors
|
|
||||||
} else if (connections > 0) {
|
|
||||||
val averageDistance = totalDistance / connections
|
|
||||||
val mapFactor = if (mapParams.shape == MapShape.rectangular)
|
|
||||||
(mapParams.mapSize.height + mapParams.mapSize.width) / 2
|
|
||||||
else (mapParams.mapSize.radius * 3) / 2 // slightly less area than equal size rect
|
|
||||||
|
|
||||||
val closeDistance = ((mapFactor * 25) / 100).coerceIn(10, 20)
|
|
||||||
val farDistance = ((mapFactor * 45) / 100).coerceIn(20, 50)
|
|
||||||
|
|
||||||
proximity = if (minDistance <= 11 && averageDistance <= closeDistance)
|
|
||||||
Proximity.Close
|
|
||||||
else if (averageDistance <= farDistance)
|
|
||||||
Proximity.Far
|
|
||||||
else
|
|
||||||
Proximity.Distant
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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()
|
|
||||||
) {
|
|
||||||
// Different continents - increase separation by one step
|
|
||||||
proximity = when (proximity) {
|
|
||||||
Proximity.Far -> Proximity.Distant
|
|
||||||
Proximity.Close -> Proximity.Far
|
|
||||||
Proximity.Neighbors -> Proximity.Close
|
|
||||||
else -> proximity
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there aren't many players (left) we can't be that far
|
|
||||||
val numMajors = gameInfo.getAliveMajorCivs().size
|
|
||||||
if (numMajors <= 2 && proximity > Proximity.Close)
|
|
||||||
proximity = Proximity.Close
|
|
||||||
if (numMajors <= 4 && proximity > Proximity.Far)
|
|
||||||
proximity = Proximity.Far
|
|
||||||
|
|
||||||
this.proximity[otherCiv.civName] = proximity
|
|
||||||
|
|
||||||
return proximity
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes current capital then moves capital to argument city if not null
|
* Removes current capital then moves capital to argument city if not null
|
||||||
|
Loading…
Reference in New Issue
Block a user