mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 05:14:32 -04: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] =
|
Provides [amount] [resource] =
|
||||||
Replaces [improvement] =
|
Replaces [improvement] =
|
||||||
Pick now! =
|
Pick now! =
|
||||||
|
Remove [feature] first =
|
||||||
Build [building] =
|
Build [building] =
|
||||||
Train [unit] =
|
Train [unit] =
|
||||||
Produce [thingToProduce] =
|
Produce [thingToProduce] =
|
||||||
|
@ -92,6 +92,14 @@ open class TileInfo {
|
|||||||
|
|
||||||
fun clone(): TileInfo {
|
fun clone(): TileInfo {
|
||||||
val toReturn = 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 (militaryUnit != null) toReturn.militaryUnit = militaryUnit!!.clone()
|
||||||
if (civilianUnit != null) toReturn.civilianUnit = civilianUnit!!.clone()
|
if (civilianUnit != null) toReturn.civilianUnit = civilianUnit!!.clone()
|
||||||
for (airUnit in airUnits) toReturn.airUnits.add(airUnit.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()
|
val regularImprovements = Table()
|
||||||
regularImprovements.defaults().pad(5f)
|
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) {
|
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
|
// 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.turnsToBuild == 0 && improvement.name != Constants.cancelImprovementOrder) continue
|
||||||
if (improvement.name == tileInfo.improvement) continue // also checked by canImprovementBeBuiltHere, but after more expensive tests
|
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
|
if (!unit.canBuildImprovement(improvement)) continue
|
||||||
|
|
||||||
val image = ImageGetter.getImprovementIcon(improvement.name, 30f)
|
val image = ImageGetter.getImprovementIcon(improvement.name, 30f)
|
||||||
@ -89,9 +104,12 @@ class ImprovementPickerScreen(val tileInfo: TileInfo, unit: MapUnit, val onAccep
|
|||||||
&& improvement.name != Constants.cancelImprovementOrder)
|
&& improvement.name != Constants.cancelImprovementOrder)
|
||||||
if (tileInfo.improvement != null && removeImprovement) labelText += "\n" + "Replaces [${tileInfo.improvement}]".tr()
|
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) }
|
"Pick now!".toLabel().onClick { accept(improvement) }
|
||||||
else "Current construction".toLabel()
|
else
|
||||||
|
"Current construction".toLabel()
|
||||||
|
|
||||||
val statIcons = getStatIconsTable(provideResource, removeImprovement)
|
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 (improvement.name == tileInfo.improvementInProgress) improvementButton.color = Color.GREEN
|
||||||
|
if (suggestRemoval){
|
||||||
|
improvementButton.disable()
|
||||||
|
}
|
||||||
regularImprovements.add(improvementButton)
|
regularImprovements.add(improvementButton)
|
||||||
|
|
||||||
if (shortcutKey != null) {
|
if (shortcutKey != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user