Clean up redundant stuff found in save files (#2192)

This commit is contained in:
rh-github-2015 2020-03-19 08:43:05 +01:00 committed by GitHub
parent f1968af3e8
commit 497ce2366a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import com.unciv.logic.automation.ConstructionAutomation
import com.unciv.logic.civilization.AlertType
import com.unciv.logic.civilization.PopupAlert
import com.unciv.models.ruleset.Building
import com.unciv.models.ruleset.unit.BaseUnit
import com.unciv.models.stats.Stats
import com.unciv.models.translations.tr
import com.unciv.ui.cityscreen.ConstructionInfoTable
@ -262,6 +263,23 @@ class CityConstructions {
if (getConstruction(construction).isBuildable(this))
constructionQueue.add(construction)
}
// remove obsolete stuff from in progress constructions - happens often and leaves clutter in memory and save files
// should have NO visible consequences - any accumulated points that may be reused later should stay (nukes when manhattan project city lost, nat wonder when conquered an empty city...)
val inProgressSnapshot = inProgressConstructions.keys.filter { it != currentConstruction }
for (constructionName in inProgressSnapshot) {
val rejectionReason:String =
when (val construction = getConstruction(constructionName)) {
is Building -> construction.getRejectionReason(this)
is BaseUnit -> construction.getRejectionReason(this)
else -> ""
}
if (!( rejectionReason.endsWith("lready built")
|| rejectionReason.startsWith("Cannot be built with")
|| rejectionReason.startsWith("Don't need to build any more")
|| rejectionReason.startsWith("Obsolete")
)) continue
inProgressConstructions.remove(constructionName)
}
}
private fun constructionComplete(construction: IConstruction) {

View File

@ -152,6 +152,8 @@ class BaseUnit : INamed, IConstruction {
val unit = construction.cityInfo.civInfo.placeUnitNearTile(construction.cityInfo.location, name)
if(unit==null) return false // couldn't place the unit, so there's actually no unit =(
if(this.unitType.isCivilian()) return true // tiny optimization makes save files a few bytes smaller
var XP = construction.getBuiltBuildings().sumBy { it.xpForNewUnits }
if(construction.cityInfo.civInfo.policies.isAdopted("Total War")) XP += 15
unit.promotions.XP = XP