mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-16 18:59:15 +07:00
chore: separated tile description into a separate file
This commit is contained in:
@ -528,7 +528,7 @@ class CityConstructions : IsPartOfGameInfoSerialization {
|
||||
val finalTile = tile
|
||||
?: Automation.getTileForConstructionImprovement(city, improvementToPlace)
|
||||
?: return false // This was never reached in testing
|
||||
finalTile.markForCreatesOneImprovement(improvementToPlace.name)
|
||||
finalTile.improvementFunctions.markForCreatesOneImprovement(improvementToPlace.name)
|
||||
// postBuildEvent does the rest by calling cityConstructions.applyCreateOneImprovement
|
||||
}
|
||||
|
||||
@ -599,7 +599,7 @@ class CityConstructions : IsPartOfGameInfoSerialization {
|
||||
val improvement = building.getImprovementToCreate(city.getRuleset()) ?: return
|
||||
if (getTileForImprovement(improvement.name) != null) return
|
||||
val newTile = Automation.getTileForConstructionImprovement(city, improvement) ?: return
|
||||
newTile.markForCreatesOneImprovement(improvement.name)
|
||||
newTile.improvementFunctions.markForCreatesOneImprovement(improvement.name)
|
||||
}
|
||||
|
||||
fun addToQueue(constructionName: String) {
|
||||
|
@ -136,7 +136,7 @@ class CityExpansionManager : IsPartOfGameInfoSerialization {
|
||||
city.lockedTiles.remove(tile.position)
|
||||
}
|
||||
|
||||
tile.removeCreatesOneImprovementMarker()
|
||||
tile.improvementFunctions.removeCreatesOneImprovementMarker()
|
||||
|
||||
tile.setOwningCity(null)
|
||||
|
||||
|
@ -21,9 +21,6 @@ import com.unciv.models.ruleset.unique.StateForConditionals
|
||||
import com.unciv.models.ruleset.unique.Unique
|
||||
import com.unciv.models.ruleset.unique.UniqueMap
|
||||
import com.unciv.models.ruleset.unique.UniqueType
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.civilopedia.FormattedLine
|
||||
import com.unciv.ui.utils.Fonts
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.min
|
||||
import kotlin.random.Random
|
||||
@ -646,82 +643,6 @@ open class Tile : IsPartOfGameInfoSerialization {
|
||||
return true
|
||||
}
|
||||
|
||||
/** Get info on a selected tile, used on WorldScreen (right side above minimap), CityScreen or MapEditorViewTab. */
|
||||
fun toMarkup(viewingCiv: Civilization?): ArrayList<FormattedLine> {
|
||||
val lineList = ArrayList<FormattedLine>()
|
||||
val isViewableToPlayer = viewingCiv == null || UncivGame.Current.viewEntireMapForDebug
|
||||
|| viewingCiv.viewableTiles.contains(this)
|
||||
|
||||
if (isCityCenter()) {
|
||||
val city = getCity()!!
|
||||
var cityString = city.name.tr()
|
||||
if (isViewableToPlayer) cityString += " (${city.health})"
|
||||
lineList += FormattedLine(cityString)
|
||||
if (UncivGame.Current.viewEntireMapForDebug || city.civ == viewingCiv)
|
||||
lineList += city.cityConstructions.getProductionMarkup(ruleset)
|
||||
}
|
||||
|
||||
lineList += FormattedLine(baseTerrain, link="Terrain/$baseTerrain")
|
||||
for (terrainFeature in terrainFeatures)
|
||||
lineList += FormattedLine(terrainFeature, link="Terrain/$terrainFeature")
|
||||
if (resource != null && (viewingCiv == null || hasViewableResource(viewingCiv)))
|
||||
lineList += if (tileResource.resourceType == ResourceType.Strategic)
|
||||
FormattedLine("{$resource} ($resourceAmount)", link="Resource/$resource")
|
||||
else
|
||||
FormattedLine(resource!!, link="Resource/$resource")
|
||||
if (resource != null && viewingCiv != null && hasViewableResource(viewingCiv)) {
|
||||
val resourceImprovement = tileResource.getImprovements().firstOrNull { improvementFunctions.canBuildImprovement(ruleset.tileImprovements[it]!!, viewingCiv) }
|
||||
val tileImprovement = ruleset.tileImprovements[resourceImprovement]
|
||||
if (tileImprovement?.techRequired != null
|
||||
&& !viewingCiv.tech.isResearched(tileImprovement.techRequired!!)) {
|
||||
lineList += FormattedLine(
|
||||
"Requires [${tileImprovement.techRequired}]",
|
||||
link="Technology/${tileImprovement.techRequired}",
|
||||
color= "#FAA"
|
||||
)
|
||||
}
|
||||
}
|
||||
if (naturalWonder != null)
|
||||
lineList += FormattedLine(naturalWonder!!, link="Terrain/$naturalWonder")
|
||||
if (roadStatus !== RoadStatus.None && !isCityCenter()) {
|
||||
val pillageText = if (roadIsPillaged) " (Pillaged!)" else ""
|
||||
lineList += FormattedLine("[${roadStatus.name}]$pillageText", link = "Improvement/${roadStatus.name}")
|
||||
}
|
||||
val shownImprovement = getShownImprovement(viewingCiv)
|
||||
if (shownImprovement != null) {
|
||||
val pillageText = if (improvementIsPillaged) " (Pillaged!)" else ""
|
||||
lineList += FormattedLine("[$shownImprovement]$pillageText", link = "Improvement/$shownImprovement")
|
||||
}
|
||||
|
||||
if (improvementInProgress != null && isViewableToPlayer) {
|
||||
// Negative turnsToImprovement is used for UniqueType.CreatesOneImprovement
|
||||
val line = "{$improvementInProgress}" +
|
||||
if (turnsToImprovement > 0) " - $turnsToImprovement${Fonts.turn}" else " ({Under construction})"
|
||||
lineList += FormattedLine(line, link="Improvement/$improvementInProgress")
|
||||
}
|
||||
|
||||
if (civilianUnit != null && isViewableToPlayer)
|
||||
lineList += FormattedLine(civilianUnit!!.name.tr() + " - " + civilianUnit!!.civ.civName.tr(),
|
||||
link="Unit/${civilianUnit!!.name}")
|
||||
if (militaryUnit != null && isViewableToPlayer && (viewingCiv == null || !militaryUnit!!.isInvisible(viewingCiv))) {
|
||||
val milUnitString = militaryUnit!!.name.tr() +
|
||||
(if (militaryUnit!!.health < 100) "(" + militaryUnit!!.health + ")" else "") +
|
||||
" - " + militaryUnit!!.civ.civName.tr()
|
||||
lineList += FormattedLine(milUnitString, link="Unit/${militaryUnit!!.name}")
|
||||
}
|
||||
|
||||
val defenceBonus = getDefensiveBonus()
|
||||
if (defenceBonus != 0f) {
|
||||
var defencePercentString = (defenceBonus * 100).toInt().toString() + "%"
|
||||
if (!defencePercentString.startsWith("-")) defencePercentString = "+$defencePercentString"
|
||||
lineList += FormattedLine("[$defencePercentString] to unit defence")
|
||||
}
|
||||
if (isImpassible()) lineList += FormattedLine(Constants.impassable)
|
||||
if (isLand && isAdjacentTo(Constants.freshWater)) lineList += FormattedLine(Constants.freshWater)
|
||||
|
||||
return lineList
|
||||
}
|
||||
|
||||
fun hasEnemyInvisibleUnit(viewingCiv: Civilization): Boolean {
|
||||
val unitsInTile = getUnits()
|
||||
if (unitsInTile.none()) return false
|
||||
@ -909,7 +830,7 @@ open class Tile : IsPartOfGameInfoSerialization {
|
||||
if (!isLand) { changeImprovement(null); return }
|
||||
|
||||
// Setting turnsToImprovement might interfere with UniqueType.CreatesOneImprovement
|
||||
removeCreatesOneImprovementMarker()
|
||||
improvementFunctions.removeCreatesOneImprovementMarker()
|
||||
improvementInProgress = null // remove any in progress work as well
|
||||
turnsToImprovement = 0
|
||||
// if no Repair action, destroy improvements instead
|
||||
@ -941,20 +862,6 @@ open class Tile : IsPartOfGameInfoSerialization {
|
||||
roadIsPillaged = false
|
||||
}
|
||||
|
||||
/** Marks tile as target tile for a building with a [UniqueType.CreatesOneImprovement] unique */
|
||||
fun markForCreatesOneImprovement(improvement: String) {
|
||||
improvementInProgress = improvement
|
||||
turnsToImprovement = -1
|
||||
}
|
||||
|
||||
/** Un-Marks a tile as target tile for a building with a [UniqueType.CreatesOneImprovement] unique,
|
||||
* and ensures that matching queued buildings are removed. */
|
||||
fun removeCreatesOneImprovementMarker() {
|
||||
if (!isMarkedForCreatesOneImprovement()) return
|
||||
owningCity?.cityConstructions?.removeCreateOneImprovementConstruction(improvementInProgress!!)
|
||||
stopWorkingOnImprovement()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Assign a continent ID to this tile.
|
||||
|
89
core/src/com/unciv/logic/map/tile/TileDescription.kt
Normal file
89
core/src/com/unciv/logic/map/tile/TileDescription.kt
Normal file
@ -0,0 +1,89 @@
|
||||
package com.unciv.logic.map.tile
|
||||
|
||||
import com.unciv.Constants
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.models.ruleset.tile.ResourceType
|
||||
import com.unciv.models.translations.tr
|
||||
import com.unciv.ui.civilopedia.FormattedLine
|
||||
import com.unciv.ui.utils.Fonts
|
||||
|
||||
object TileDescription {
|
||||
|
||||
/** Get info on a selected tile, used on WorldScreen (right side above minimap), CityScreen or MapEditorViewTab. */
|
||||
fun toMarkup(tile: Tile, viewingCiv: Civilization?): ArrayList<FormattedLine> {
|
||||
val lineList = ArrayList<FormattedLine>()
|
||||
val isViewableToPlayer = viewingCiv == null || UncivGame.Current.viewEntireMapForDebug
|
||||
|| viewingCiv.viewableTiles.contains(tile)
|
||||
|
||||
if (tile.isCityCenter()) {
|
||||
val city = tile.getCity()!!
|
||||
var cityString = city.name.tr()
|
||||
if (isViewableToPlayer) cityString += " (${city.health})"
|
||||
lineList += FormattedLine(cityString)
|
||||
if (UncivGame.Current.viewEntireMapForDebug || city.civ == viewingCiv)
|
||||
lineList += city.cityConstructions.getProductionMarkup(tile.ruleset)
|
||||
}
|
||||
|
||||
lineList += FormattedLine(tile.baseTerrain, link="Terrain/${tile.baseTerrain}")
|
||||
for (terrainFeature in tile.terrainFeatures)
|
||||
lineList += FormattedLine(terrainFeature, link="Terrain/$terrainFeature")
|
||||
if (tile.resource != null && (viewingCiv == null || tile.hasViewableResource(viewingCiv)))
|
||||
lineList += if (tile.tileResource.resourceType == ResourceType.Strategic)
|
||||
FormattedLine("{${tile.resource}} (${tile.resourceAmount})", link="Resource/${tile.resource}")
|
||||
else
|
||||
FormattedLine(tile.resource!!, link="Resource/${tile.resource}")
|
||||
if (tile.resource != null && viewingCiv != null && tile.hasViewableResource(viewingCiv)) {
|
||||
val resourceImprovement = tile.tileResource.getImprovements().firstOrNull { tile.improvementFunctions.canBuildImprovement(tile.ruleset.tileImprovements[it]!!, viewingCiv) }
|
||||
val tileImprovement = tile.ruleset.tileImprovements[resourceImprovement]
|
||||
if (tileImprovement?.techRequired != null
|
||||
&& !viewingCiv.tech.isResearched(tileImprovement.techRequired!!)) {
|
||||
lineList += FormattedLine(
|
||||
"Requires [${tileImprovement.techRequired}]",
|
||||
link="Technology/${tileImprovement.techRequired}",
|
||||
color= "#FAA"
|
||||
)
|
||||
}
|
||||
}
|
||||
if (tile.naturalWonder != null)
|
||||
lineList += FormattedLine(tile.naturalWonder!!, link="Terrain/${tile.naturalWonder}")
|
||||
if (tile.roadStatus !== RoadStatus.None && !tile.isCityCenter()) {
|
||||
val pillageText = if (tile.roadIsPillaged) " (Pillaged!)" else ""
|
||||
lineList += FormattedLine("[${tile.roadStatus.name}]$pillageText", link = "Improvement/${tile.roadStatus.name}")
|
||||
}
|
||||
val shownImprovement = tile.getShownImprovement(viewingCiv)
|
||||
if (shownImprovement != null) {
|
||||
val pillageText = if (tile.improvementIsPillaged) " (Pillaged!)" else ""
|
||||
lineList += FormattedLine("[$shownImprovement]$pillageText", link = "Improvement/$shownImprovement")
|
||||
}
|
||||
|
||||
if (tile.improvementInProgress != null && isViewableToPlayer) {
|
||||
// Negative turnsToImprovement is used for UniqueType.CreatesOneImprovement
|
||||
val line = "{${tile.improvementInProgress}}" +
|
||||
if (tile.turnsToImprovement > 0) " - ${tile.turnsToImprovement}${Fonts.turn}" else " ({Under construction})"
|
||||
lineList += FormattedLine(line, link="Improvement/${tile.improvementInProgress}")
|
||||
}
|
||||
|
||||
if (tile.civilianUnit != null && isViewableToPlayer)
|
||||
lineList += FormattedLine(tile.civilianUnit!!.name.tr() + " - " + tile.civilianUnit!!.civ.civName.tr(),
|
||||
link="Unit/${tile.civilianUnit!!.name}")
|
||||
if (tile.militaryUnit != null && isViewableToPlayer && (viewingCiv == null || !tile.militaryUnit!!.isInvisible(viewingCiv))) {
|
||||
val milUnitString = tile.militaryUnit!!.name.tr() +
|
||||
(if (tile.militaryUnit!!.health < 100) "(" + tile.militaryUnit!!.health + ")" else "") +
|
||||
" - " + tile.militaryUnit!!.civ.civName.tr()
|
||||
lineList += FormattedLine(milUnitString, link="Unit/${tile.militaryUnit!!.name}")
|
||||
}
|
||||
|
||||
val defenceBonus = tile.getDefensiveBonus()
|
||||
if (defenceBonus != 0f) {
|
||||
var defencePercentString = (defenceBonus * 100).toInt().toString() + "%"
|
||||
if (!defencePercentString.startsWith("-")) defencePercentString = "+$defencePercentString"
|
||||
lineList += FormattedLine("[$defencePercentString] to unit defence")
|
||||
}
|
||||
if (tile.isImpassible()) lineList += FormattedLine(Constants.impassable)
|
||||
if (tile.isLand && tile.isAdjacentTo(Constants.freshWater)) lineList += FormattedLine(Constants.freshWater)
|
||||
|
||||
return lineList
|
||||
}
|
||||
|
||||
}
|
@ -306,4 +306,19 @@ class TileInfoImprovementFunctions(val tile: Tile) {
|
||||
}
|
||||
|
||||
|
||||
/** Marks tile as target tile for a building with a [UniqueType.CreatesOneImprovement] unique */
|
||||
fun markForCreatesOneImprovement(improvement: String) {
|
||||
tile.improvementInProgress = improvement
|
||||
tile.turnsToImprovement = -1
|
||||
}
|
||||
|
||||
/** Un-Marks a tile as target tile for a building with a [UniqueType.CreatesOneImprovement] unique,
|
||||
* and ensures that matching queued buildings are removed. */
|
||||
fun removeCreatesOneImprovementMarker() {
|
||||
if (!tile.isMarkedForCreatesOneImprovement()) return
|
||||
tile.owningCity?.cityConstructions?.removeCreateOneImprovementConstruction(tile.improvementInProgress!!)
|
||||
tile.stopWorkingOnImprovement()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ class CityScreen(
|
||||
// might get a bit fragile if several buildings constructing the same improvement type
|
||||
// were to be allowed in the queue - or a little nontransparent to the user why they
|
||||
// won't reorder - maybe one day redesign to have the target tiles attached to queue entries.
|
||||
tileInfo.markForCreatesOneImprovement(improvement.name)
|
||||
tileInfo.improvementFunctions.markForCreatesOneImprovement(improvement.name)
|
||||
city.cityConstructions.addToQueue(pickTileData.building.name)
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.map.tile.Tile
|
||||
import com.unciv.logic.map.tile.TileDescription
|
||||
import com.unciv.models.UncivSound
|
||||
import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.stats.Stats
|
||||
@ -52,7 +53,7 @@ class CityScreenTileTable(private val cityScreen: CityScreen): Table() {
|
||||
val stats = selectedTile.stats.getTileStats(city, city.civ)
|
||||
innerTable.pad(5f)
|
||||
|
||||
innerTable.add( MarkupRenderer.render(selectedTile.toMarkup(city.civ), iconDisplay = IconDisplay.None) {
|
||||
innerTable.add(MarkupRenderer.render(TileDescription.toMarkup(selectedTile, city.civ), iconDisplay = IconDisplay.None) {
|
||||
UncivGame.Current.pushScreen(CivilopediaScreen(city.getRuleset(), link = it))
|
||||
} )
|
||||
innerTable.row()
|
||||
|
@ -8,6 +8,7 @@ import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.logic.map.tile.Tile
|
||||
import com.unciv.logic.map.tile.TileDescription
|
||||
import com.unciv.models.Counter
|
||||
import com.unciv.models.ruleset.Ruleset
|
||||
import com.unciv.models.ruleset.nation.Nation
|
||||
@ -167,7 +168,7 @@ class MapEditorViewTab(
|
||||
lines += FormattedLine("Position: [${tile.position.toString().replace(".0","")}]")
|
||||
lines += FormattedLine()
|
||||
|
||||
lines.addAll(tile.toMarkup(null))
|
||||
lines.addAll(TileDescription.toMarkup(tile, null))
|
||||
|
||||
val stats = try {
|
||||
tile.stats.getTileStats(null, mockCiv)
|
||||
|
@ -6,6 +6,7 @@ import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.civilization.Civilization
|
||||
import com.unciv.logic.map.tile.Tile
|
||||
import com.unciv.logic.map.tile.TileDescription
|
||||
import com.unciv.ui.civilopedia.CivilopediaScreen
|
||||
import com.unciv.ui.civilopedia.FormattedLine.IconDisplay
|
||||
import com.unciv.ui.civilopedia.MarkupRenderer
|
||||
@ -28,7 +29,7 @@ class TileInfoTable(private val viewingCiv :Civilization) : Table(BaseScreen.ski
|
||||
|
||||
if (tile != null && (UncivGame.Current.viewEntireMapForDebug || viewingCiv.hasExplored(tile)) ) {
|
||||
add(getStatsTable(tile))
|
||||
add( MarkupRenderer.render(tile.toMarkup(viewingCiv), padding = 0f, iconDisplay = IconDisplay.None) {
|
||||
add(MarkupRenderer.render(TileDescription.toMarkup(tile, viewingCiv), padding = 0f, iconDisplay = IconDisplay.None) {
|
||||
UncivGame.Current.pushScreen(CivilopediaScreen(viewingCiv.gameInfo.ruleSet, link = it))
|
||||
} ).pad(5f).row()
|
||||
if (UncivGame.Current.viewEntireMapForDebug)
|
||||
|
@ -468,7 +468,7 @@ object UnitActions {
|
||||
title = "Create [$improvementName]",
|
||||
action = {
|
||||
val unitTile = unit.getTile()
|
||||
unitTile.removeCreatesOneImprovementMarker()
|
||||
unitTile.improvementFunctions.removeCreatesOneImprovementMarker()
|
||||
unitTile.changeImprovement(improvementName)
|
||||
unitTile.stopWorkingOnImprovement()
|
||||
improvement.handleImprovementCompletion(unit)
|
||||
|
Reference in New Issue
Block a user