mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-24 21:51:14 +07:00
Show Improvements that are buildable after Removing TerrainFeature (#6149)
* Initial working version! * More comments * Add missing .tr() translation calls * add brackets * Fixed * Optimize checking for removable last feature More complete tileInfo.clone() Co-authored-by: itanasi <spellman23@gmail.com>
This commit is contained in:
parent
f9bab01a64
commit
402a9ba825
@ -809,6 +809,7 @@ Provides [resource] =
|
||||
Provides [amount] [resource] =
|
||||
Replaces [improvement] =
|
||||
Pick now! =
|
||||
Remove [feature] first =
|
||||
Build [building] =
|
||||
Train [unit] =
|
||||
Produce [thingToProduce] =
|
||||
|
@ -92,6 +92,14 @@ open class TileInfo {
|
||||
|
||||
fun clone(): TileInfo {
|
||||
val toReturn = TileInfo()
|
||||
toReturn.tileMap = tileMap
|
||||
toReturn.ruleset = ruleset
|
||||
toReturn.isCityCenterInternal = isCityCenterInternal
|
||||
toReturn.owningCity = owningCity
|
||||
toReturn.baseTerrainObject = baseTerrainObject
|
||||
toReturn.isLand = isLand
|
||||
toReturn.isWater = isWater
|
||||
toReturn.isOcean = isOcean
|
||||
if (militaryUnit != null) toReturn.militaryUnit = militaryUnit!!.clone()
|
||||
if (civilianUnit != null) toReturn.civilianUnit = civilianUnit!!.clone()
|
||||
for (airUnit in airUnits) toReturn.airUnits.add(airUnit.clone())
|
||||
|
@ -51,12 +51,27 @@ class ImprovementPickerScreen(val tileInfo: TileInfo, unit: MapUnit, val onAccep
|
||||
|
||||
val regularImprovements = Table()
|
||||
regularImprovements.defaults().pad(5f)
|
||||
|
||||
// clone tileInfo without "top" feature if it could be removed
|
||||
// Keep this copy around for speed
|
||||
val tileInfoNoLast:TileInfo = tileInfo.clone()
|
||||
if (ruleSet.tileImprovements.any{it.key == Constants.remove + tileInfoNoLast.getLastTerrain().name}) {
|
||||
tileInfoNoLast.terrainFeatures.remove(tileInfoNoLast.getLastTerrain().name)
|
||||
}
|
||||
|
||||
for (improvement in ruleSet.tileImprovements.values) {
|
||||
var suggestRemoval:Boolean = false
|
||||
// canBuildImprovement() would allow e.g. great improvements thus we need to exclude them - except cancel
|
||||
if (improvement.turnsToBuild == 0 && improvement.name != Constants.cancelImprovementOrder) continue
|
||||
if (improvement.name == tileInfo.improvement) continue // also checked by canImprovementBeBuiltHere, but after more expensive tests
|
||||
if (!tileInfo.canBuildImprovement(improvement, currentPlayerCiv)) continue
|
||||
if (!tileInfo.canBuildImprovement(improvement, currentPlayerCiv)){
|
||||
// if there is an improvement that could remove that terrain
|
||||
if(tileInfoNoLast.canBuildImprovement(improvement, currentPlayerCiv)) {
|
||||
suggestRemoval = true
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if (!unit.canBuildImprovement(improvement)) continue
|
||||
|
||||
val image = ImageGetter.getImprovementIcon(improvement.name, 30f)
|
||||
@ -89,9 +104,12 @@ class ImprovementPickerScreen(val tileInfo: TileInfo, unit: MapUnit, val onAccep
|
||||
&& improvement.name != Constants.cancelImprovementOrder)
|
||||
if (tileInfo.improvement != null && removeImprovement) labelText += "\n" + "Replaces [${tileInfo.improvement}]".tr()
|
||||
|
||||
val pickNow = if (tileInfo.improvementInProgress != improvement.name)
|
||||
val pickNow = if (suggestRemoval)
|
||||
(Constants.remove + "[" + tileInfo.getLastTerrain().name + "] first").toLabel()
|
||||
else if (tileInfo.improvementInProgress != improvement.name)
|
||||
"Pick now!".toLabel().onClick { accept(improvement) }
|
||||
else "Current construction".toLabel()
|
||||
else
|
||||
"Current construction".toLabel()
|
||||
|
||||
val statIcons = getStatIconsTable(provideResource, removeImprovement)
|
||||
|
||||
@ -118,6 +136,9 @@ class ImprovementPickerScreen(val tileInfo: TileInfo, unit: MapUnit, val onAccep
|
||||
}
|
||||
|
||||
if (improvement.name == tileInfo.improvementInProgress) improvementButton.color = Color.GREEN
|
||||
if (suggestRemoval){
|
||||
improvementButton.disable()
|
||||
}
|
||||
regularImprovements.add(improvementButton)
|
||||
|
||||
if (shortcutKey != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user