mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-28 13:48:49 +07:00
Performance improvements for Next Turn
This commit is contained in:
@ -423,11 +423,11 @@
|
||||
|
||||
"[unit] finished exploring.": {
|
||||
Italian:"[unit] non sta più esplorando."
|
||||
"German": "[unit] hat die Erkundung abgeschlossen."
|
||||
German: "[unit] hat die Erkundung abgeschlossen."
|
||||
},
|
||||
|
||||
"[unit] has no work to do.": {
|
||||
Italian:"[unit] è ora inattivo."
|
||||
"German": "[unit] hat keine Arbeit mehr."
|
||||
German:"[unit] hat keine Arbeit mehr."
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,12 @@ import com.unciv.logic.civilization.LocationAction
|
||||
import com.unciv.logic.civilization.PlayerType
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.models.gamebasics.Difficulty
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
|
||||
class GameInfo {
|
||||
@Transient lateinit var difficultyObject: Difficulty // Since this is static game-wide, and was taking a large part of nextTurn
|
||||
|
||||
var civilizations = mutableListOf<CivilizationInfo>()
|
||||
var difficulty="Chieftain" // difficulty is game-wide, think what would happen if 2 human players could play on different difficulties?
|
||||
var tileMap: TileMap = TileMap()
|
||||
@ -35,7 +38,7 @@ class GameInfo {
|
||||
fun getCivilization(civName:String) = civilizations.first { it.civName==civName }
|
||||
fun getCurrentPlayerCivilization() = getCivilization(currentPlayer)
|
||||
fun getBarbarianCivilization() = getCivilization("Barbarians")
|
||||
fun getDifficulty() = GameBasics.Difficulties[difficulty]!!
|
||||
fun getDifficulty() = difficultyObject
|
||||
//endregion
|
||||
|
||||
fun nextTurn() {
|
||||
@ -146,6 +149,7 @@ class GameInfo {
|
||||
getCurrentPlayerCivilization().playerType=PlayerType.Human
|
||||
if(getCurrentPlayerCivilization().difficulty!="Chieftain")
|
||||
difficulty= getCurrentPlayerCivilization().difficulty
|
||||
difficultyObject = GameBasics.Difficulties[difficulty]!!
|
||||
|
||||
// We have to remove all deprecated buildings from all cities BEFORE we update a single one, or run setTransients on the civs,
|
||||
// because updating leads to getting the building uniques from the civ info,
|
||||
|
@ -10,7 +10,6 @@ import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.tr
|
||||
import com.unciv.ui.worldscreen.unit.UnitAction
|
||||
import com.unciv.ui.worldscreen.unit.UnitActions
|
||||
|
||||
@ -399,13 +398,10 @@ class UnitAutomation{
|
||||
}
|
||||
|
||||
internal fun explore(unit: MapUnit, unitDistanceToTiles: HashMap<TileInfo, Float>) {
|
||||
val distanceToTiles:HashMap<TileInfo, Float>
|
||||
if(tryGoToRuin(unit,unitDistanceToTiles))
|
||||
{
|
||||
if(unit.currentMovement==0f) return
|
||||
distanceToTiles = unit.getDistanceToTiles()
|
||||
}
|
||||
else distanceToTiles = unitDistanceToTiles
|
||||
|
||||
for(tile in unit.currentTile.getTilesInDistance(5))
|
||||
if(unit.canMoveTo(tile) && tile.position !in unit.civInfo.exploredTiles
|
||||
@ -413,14 +409,6 @@ class UnitAutomation{
|
||||
unit.movementAlgs().headTowards(tile)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
val reachableTiles= distanceToTiles
|
||||
.filter { unit.canMoveTo(it.key) && unit.movementAlgs().canReach(it.key) }
|
||||
|
||||
val reachableTilesMaxWalkingDistance = reachableTiles.filter { it.value == unit.currentMovement }
|
||||
if (reachableTilesMaxWalkingDistance.any()) unit.moveToTile(reachableTilesMaxWalkingDistance.toList().random().first)
|
||||
else if (reachableTiles.any()) unit.moveToTile(reachableTiles.toList().random().first)
|
||||
}
|
||||
|
||||
fun automatedExplore(unit:MapUnit){
|
||||
@ -441,7 +429,7 @@ class UnitAutomation{
|
||||
return
|
||||
}
|
||||
}
|
||||
unit.civInfo.addNotification("[${unit.name.tr()}] finished exploring.".tr(), unit.currentTile.position, Color.GRAY)
|
||||
unit.civInfo.addNotification("[${unit.name}] finished exploring.", unit.currentTile.position, Color.GRAY)
|
||||
}
|
||||
|
||||
}
|
@ -5,11 +5,9 @@ import com.unciv.Constants
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.map.BFS
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.logic.map.RoadStatus
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.models.gamebasics.tile.TileImprovement
|
||||
import com.unciv.models.gamebasics.tr
|
||||
|
||||
class WorkerAutomation(val unit: MapUnit) {
|
||||
|
||||
@ -43,7 +41,7 @@ class WorkerAutomation(val unit: MapUnit) {
|
||||
if(tile.improvementInProgress!=null) return // we're working!
|
||||
if(tryConnectingCities()) return //nothing to do, try again to connect cities
|
||||
|
||||
unit.civInfo.addNotification("[${unit.name.tr()}] has no work to do.".tr(), unit.currentTile.position, Color.GRAY)
|
||||
unit.civInfo.addNotification("[${unit.name}] has no work to do.", unit.currentTile.position, Color.GRAY)
|
||||
|
||||
}
|
||||
|
||||
|
@ -325,6 +325,7 @@ class CivilizationInfo {
|
||||
return baseBuilding
|
||||
}
|
||||
|
||||
// This is a big performance
|
||||
fun updateViewableTiles() {
|
||||
val newViewableTiles = HashSet<TileInfo>()
|
||||
newViewableTiles.addAll(cities.flatMap { it.getTiles() }.flatMap { it.neighbors }) // tiles adjacent to city tiles
|
||||
|
@ -84,7 +84,7 @@ class UnitMovementAlgorithms(val unit:MapUnit) {
|
||||
|
||||
fun getShortestPath(destination: TileInfo): List<TileInfo> {
|
||||
val currentTile = unit.getTile()
|
||||
if (currentTile.position == destination) return listOf(currentTile) // edge case that's needed, so that workers will know that they can reach their own tile. *sig
|
||||
if (currentTile.position == destination) return listOf(currentTile) // edge case that's needed, so that workers will know that they can reach their own tile. *sigh*
|
||||
|
||||
var tilesToCheck: List<TileInfo> = listOf(currentTile)
|
||||
val movementTreeParents = HashMap<TileInfo, TileInfo?>() // contains a map of "you can get from X to Y in that turn"
|
||||
|
Reference in New Issue
Block a user