UnitMovementAlgorithms -> UnitMovement and modernized city connections tests

This commit is contained in:
Yair Morgenstern
2023-03-20 00:20:34 +02:00
parent 61f7b14f04
commit a37eb28964
8 changed files with 101 additions and 150 deletions

View File

@ -375,8 +375,8 @@ class City : IsPartOfGameInfoSerialization {
expansion.city = this
expansion.setTransients()
cityConstructions.city = this
cityConstructions.setTransients()
religion.setTransients(this)
cityConstructions.setTransients()
espionage.setTransients(this)
}

View File

@ -43,7 +43,7 @@ class CityFounder {
city.expansion.reset()
city.tryUpdateRoadStatus()
civInfo.cache.updateCitiesConnectedToCapital() // Carthage cities can connect immediately
// civInfo.cache.updateCitiesConnectedToCapital() // Carthage cities can connect immediately
val tile = city.getCenterTile()
for (terrainFeature in tile.terrainFeatures.filter {

View File

@ -7,7 +7,7 @@ import com.unciv.logic.civilization.NotificationCategory
import com.unciv.logic.civilization.NotificationIcon
import com.unciv.logic.civilization.PopupAlert
import com.unciv.logic.map.tile.Tile
import com.unciv.logic.map.mapunit.UnitMovementAlgorithms
import com.unciv.logic.map.mapunit.UnitMovement
import com.unciv.models.ruleset.unique.UniqueType
import com.unciv.models.stats.Stat
import com.unciv.models.stats.Stats
@ -129,7 +129,7 @@ class DiplomacyFunctions(val civInfo:Civilization){
* considering only civ-wide filters.
* Use [Tile.canCivPassThrough] to check whether units of a civilization can pass through
* a specific tile, considering only civ-wide filters.
* Use [UnitMovementAlgorithms.canPassThrough] to check whether a specific unit can pass through
* Use [UnitMovement.canPassThrough] to check whether a specific unit can pass through
* a specific tile.
*/
fun canPassThroughTiles(otherCiv: Civilization): Boolean {

View File

@ -42,7 +42,7 @@ class MapUnit : IsPartOfGameInfoSerialization {
lateinit var currentTile: Tile
@Transient
val movement = UnitMovementAlgorithms(this)
val movement = UnitMovement(this)
@Transient
val upgrade = UnitUpgradeManager(this)

View File

@ -10,7 +10,7 @@ import com.unciv.logic.map.tile.Tile
import com.unciv.models.helpers.UnitMovementMemoryType
import com.unciv.models.ruleset.unique.UniqueType
class UnitMovementAlgorithms(val unit: MapUnit) {
class UnitMovement(val unit: MapUnit) {
private val pathfindingCache = PathfindingCache(unit)
@ -815,11 +815,11 @@ class UnitMovementAlgorithms(val unit: MapUnit) {
}
/**
* Cache for the results of [UnitMovementAlgorithms.getDistanceToTiles] accounting for zone of control.
* [UnitMovementAlgorithms.getDistanceToTiles] is called in numerous places for AI pathfinding so
* Cache for the results of [UnitMovement.getDistanceToTiles] accounting for zone of control.
* [UnitMovement.getDistanceToTiles] is called in numerous places for AI pathfinding so
* being able to skip redundant calculations helps out over a long game (especially with high level
* AI or a big map). Same thing with [UnitMovementAlgorithms.getShortestPath] which is called in
* [UnitMovementAlgorithms.canReach] and in [UnitMovementAlgorithms.headTowards]. Often, the AI will
* AI or a big map). Same thing with [UnitMovement.getShortestPath] which is called in
* [UnitMovement.canReach] and in [UnitMovement.headTowards]. Often, the AI will
* see if it can reach a tile using canReach then if it can, it will headTowards it. We can cache
* the result since otherwise this is a redundant calculation that will find the same path.
*/
@ -875,7 +875,7 @@ class PathfindingCache(private val unit: MapUnit) {
}
}
class PathsToTilesWithinTurn : LinkedHashMap<Tile, UnitMovementAlgorithms.ParentTileAndTotalDistance>() {
class PathsToTilesWithinTurn : LinkedHashMap<Tile, UnitMovement.ParentTileAndTotalDistance>() {
fun getPathToTile(tile: Tile): List<Tile> {
if (!containsKey(tile))
throw Exception("Can't reach this tile!")

View File

@ -98,7 +98,7 @@ class TileStatFunctions(val tile: Tile) {
stats.add(terrain)
}
}
return stats!!
return stats ?: Stats.ZERO // For tests
}
// Only gets the tile percentage bonus, not the improvement percentage bonus