mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-26 07:39:44 +07:00
Fix-Workers-Second-Turn (#4929)
* Fix-Workers-Second-Turn * Fix-Workers-Second-Turn
This commit is contained in:
@ -91,7 +91,7 @@ class WorkerAutomation(
|
||||
* value: The [BFS] searching from that city, whether successful or not.
|
||||
*/
|
||||
//todo: If BFS were to deal in vectors instead of TileInfos, we could copy this on cloning
|
||||
private val bfsCache = HashMap<Vector2, BFS?>()
|
||||
private val bfsCache = HashMap<Vector2, BFS>()
|
||||
|
||||
//todo: UnitMovementAlgorithms.canReach still very expensive and could benefit from caching, it's not using BFS
|
||||
|
||||
@ -118,20 +118,6 @@ class WorkerAutomation(
|
||||
private fun MapUnit.label() = toString() + " " + getTile().position.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A complete, or partial clone, or null - meaning any missing information should be regenerated
|
||||
*/
|
||||
fun clone(): WorkerAutomation {
|
||||
// This is a tricky one - we'd like to continue using the cached knowledge stored while the turn was
|
||||
// interactive at the moment nextTurn clones the GameInfo - but would a shallow copy work? No.
|
||||
// Also, AutoSave pulls another clone of GameInfo where any extra work would be wasted.
|
||||
//
|
||||
// Is a deep clone by looking up cloned objects by their primary keys worthwhile?
|
||||
// Current answer: NO. But we still allow this method to carry the decision.
|
||||
//
|
||||
// The following is cheap and does not convert the lazies, forcing a rebuild:
|
||||
return WorkerAutomation(civInfo, cachedForTurn, this)
|
||||
}
|
||||
|
||||
///////////////////////////////////////// Methods /////////////////////////////////////////
|
||||
/**
|
||||
|
@ -44,7 +44,7 @@ class CivilizationInfo {
|
||||
val currentTurn = if (UncivGame.Current.isInitialized && UncivGame.Current.isGameInfoInitialized())
|
||||
UncivGame.Current.gameInfo.turns else 0
|
||||
if (workerAutomationCache == null || workerAutomationCache!!.cachedForTurn != currentTurn)
|
||||
workerAutomationCache = workerAutomationCache?.clone() ?: WorkerAutomation(this, currentTurn)
|
||||
workerAutomationCache = WorkerAutomation(this, currentTurn)
|
||||
return workerAutomationCache!!
|
||||
}
|
||||
|
||||
@ -169,7 +169,6 @@ class CivilizationInfo {
|
||||
toReturn.flagsCountdown.putAll(flagsCountdown)
|
||||
toReturn.temporaryUniques.addAll(temporaryUniques)
|
||||
toReturn.hasEverOwnedOriginalCapital = hasEverOwnedOriginalCapital
|
||||
toReturn.workerAutomationCache = workerAutomationCache?.clone()
|
||||
return toReturn
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user