mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 21:35:14 -04:00
Added improvement-constructing buildings
This commit is contained in:
parent
e56fa6559f
commit
9d647447bc
@ -504,6 +504,8 @@ Start Golden Age =
|
||||
Yes =
|
||||
No =
|
||||
Acquire =
|
||||
Under construction =
|
||||
|
||||
Science =
|
||||
Happiness =
|
||||
Production =
|
||||
@ -517,6 +519,7 @@ Golden Age =
|
||||
[year] BC =
|
||||
[year] AD =
|
||||
Civilopedia =
|
||||
|
||||
Start new game =
|
||||
Save game =
|
||||
Load game =
|
||||
|
@ -413,7 +413,17 @@ class CityConstructions {
|
||||
|
||||
/** If this was done automatically, we should automatically try to choose a new construction and treat it as such */
|
||||
fun removeFromQueue(constructionQueueIndex: Int, automatic: Boolean) {
|
||||
constructionQueue.removeAt(constructionQueueIndex)
|
||||
val constructionName = constructionQueue.removeAt(constructionQueueIndex)
|
||||
val construction = getConstruction(constructionName)
|
||||
if (construction is Building) {
|
||||
val improvement = construction.getImprovement(cityInfo.getRuleset())
|
||||
if (improvement != null) {
|
||||
val tileWithImprovement = cityInfo.getTiles().firstOrNull { it.improvementInProgress == improvement.name }
|
||||
tileWithImprovement?.improvementInProgress = null
|
||||
tileWithImprovement?.turnsToImprovement = 0
|
||||
}
|
||||
}
|
||||
|
||||
if (constructionQueue.isEmpty()) {
|
||||
if (automatic) chooseNextConstruction()
|
||||
else constructionQueue.add("Nothing") // To prevent Construction Automation
|
||||
|
@ -85,8 +85,10 @@ class CivilizationInfo {
|
||||
private var allyCivName = ""
|
||||
var naturalWonders = ArrayList<String>()
|
||||
|
||||
//** for trades here, ourOffers is the current civ's offers, and theirOffers is what the requesting civ offers */
|
||||
/** for trades here, ourOffers is the current civ's offers, and theirOffers is what the requesting civ offers */
|
||||
val tradeRequests = ArrayList<TradeRequest>()
|
||||
/** See DiplomacyManager.flagsCountdown to why not eEnum */
|
||||
private var flagsCountdown = HashMap<String,Int>()
|
||||
|
||||
// if we only use lists, and change the list each time the cities are changed,
|
||||
// we won't get concurrent modification exceptions.
|
||||
@ -128,6 +130,7 @@ class CivilizationInfo {
|
||||
toReturn.tradeRequests.addAll(tradeRequests)
|
||||
toReturn.naturalWonders.addAll(naturalWonders)
|
||||
toReturn.cityStatePersonality = cityStatePersonality
|
||||
toReturn.flagsCountdown.putAll(flagsCountdown)
|
||||
return toReturn
|
||||
}
|
||||
|
||||
|
@ -442,10 +442,14 @@ open class TileInfo {
|
||||
if (terrainFeature != null) lineList += terrainFeature!!.tr()
|
||||
if (resource != null && (viewingCiv == null || hasViewableResource(viewingCiv))) lineList += resource!!.tr()
|
||||
if (naturalWonder != null) lineList += naturalWonder!!.tr()
|
||||
if (roadStatus !== RoadStatus.None && !isCityCenter()) lineList += roadStatus.toString().tr()
|
||||
if (roadStatus !== RoadStatus.None && !isCityCenter()) lineList += roadStatus.name.tr()
|
||||
if (improvement != null) lineList += improvement!!.tr()
|
||||
if (improvementInProgress != null && isViewableToPlayer)
|
||||
lineList += "{$improvementInProgress} - $turnsToImprovement${Fonts.turn}".tr()
|
||||
if (improvementInProgress != null && isViewableToPlayer) {
|
||||
var line = "{$improvementInProgress}"
|
||||
if (turnsToImprovement > 0) line += " - $turnsToImprovement${Fonts.turn}"
|
||||
else line += " ({Under construction})"
|
||||
lineList += line.tr()
|
||||
}
|
||||
if (civilianUnit != null && isViewableToPlayer)
|
||||
lineList += civilianUnit!!.name.tr() + " - " + civilianUnit!!.civInfo.civName.tr()
|
||||
if (militaryUnit != null && isViewableToPlayer) {
|
||||
|
@ -5,6 +5,7 @@ import com.unciv.logic.city.CityConstructions
|
||||
import com.unciv.logic.city.IConstruction
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.models.Counter
|
||||
import com.unciv.models.ruleset.tile.TileImprovement
|
||||
import com.unciv.models.stats.NamedStats
|
||||
import com.unciv.models.stats.Stat
|
||||
import com.unciv.models.stats.Stats
|
||||
@ -404,6 +405,18 @@ class Building : NamedStats(), IConstruction {
|
||||
}
|
||||
cityConstructions.addBuilding(name)
|
||||
|
||||
|
||||
val improvement = getImprovement(civInfo.gameInfo.ruleSet)
|
||||
if (improvement != null) {
|
||||
val tileWithImprovement = cityConstructions.cityInfo.getTiles().firstOrNull { it.improvementInProgress == improvement.name }
|
||||
if (tileWithImprovement != null) {
|
||||
tileWithImprovement.turnsToImprovement = 0
|
||||
tileWithImprovement.improvementInProgress = null
|
||||
tileWithImprovement.improvement = improvement.name
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (providesFreeBuilding != null && !cityConstructions.containsBuildingOrEquivalent(providesFreeBuilding!!)) {
|
||||
var buildingToAdd = providesFreeBuilding!!
|
||||
|
||||
@ -444,4 +457,13 @@ class Building : NamedStats(), IConstruction {
|
||||
if (replaces == null) return this
|
||||
else return ruleset.buildings[replaces!!]!!
|
||||
}
|
||||
|
||||
fun getImprovement(ruleset: Ruleset): TileImprovement? {
|
||||
val improvementUnique = uniqueObjects
|
||||
.firstOrNull { it.placeholderText == "Creates a [] improvement on a specific tile" }
|
||||
if (improvementUnique == null) return null
|
||||
return ruleset.tileImprovements[improvementUnique.params[0]]!!
|
||||
}
|
||||
|
||||
fun isSellable() = !isWonder && !isNationalWonder
|
||||
}
|
@ -96,7 +96,7 @@ class CityInfoTable(private val cityScreen: CityScreen) : Table(CameraStageBaseS
|
||||
cityScreen.city.civInfo, cityScreen.city.civInfo.gameInfo.ruleSet)
|
||||
wonderDetailsTable.add(detailsString.toLabel().apply { wrap = true })
|
||||
.width(cityScreen.stage.width / 4 - 2 * pad).row() // when you set wrap, then you need to manually set the size of the label
|
||||
if (!building.isWonder && !building.isNationalWonder) {
|
||||
if (building.isSellable()) {
|
||||
val sellAmount = cityScreen.city.getGoldForSellingBuilding(building.name)
|
||||
val sellBuildingButton = "Sell for [$sellAmount] gold".toTextButton()
|
||||
wonderDetailsTable.add(sellBuildingButton).pad(5f).row()
|
||||
|
@ -11,6 +11,8 @@ import com.unciv.logic.HexMath
|
||||
import com.unciv.logic.city.CityInfo
|
||||
import com.unciv.logic.city.IConstruction
|
||||
import com.unciv.logic.map.TileInfo
|
||||
import com.unciv.models.ruleset.Building
|
||||
import com.unciv.models.ruleset.tile.TileImprovement
|
||||
import com.unciv.ui.map.TileGroupMap
|
||||
import com.unciv.ui.tilegroups.TileSetStrings
|
||||
import com.unciv.ui.utils.*
|
||||
@ -120,6 +122,14 @@ class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() {
|
||||
val nextTile = city.expansion.chooseNewTileToOwn()
|
||||
for (tileGroup in tileGroups) {
|
||||
tileGroup.update()
|
||||
tileGroup.hideCircle()
|
||||
if (city.tiles.contains(tileGroup.tileInfo.position)
|
||||
&& constructionsTable.improvementBuildingToConstruct != null) {
|
||||
val improvement = constructionsTable.improvementBuildingToConstruct!!.getImprovement(city.getRuleset())!!
|
||||
if (tileGroup.tileInfo.canBuildImprovement(improvement, city.civInfo))
|
||||
tileGroup.showCircle(Color.GREEN)
|
||||
else tileGroup.showCircle(Color.RED)
|
||||
}
|
||||
if (tileGroup.tileInfo == nextTile) {
|
||||
tileGroup.showCircle(Color.PURPLE)
|
||||
tileGroup.setColor(0f, 0f, 0f, 0.7f)
|
||||
@ -175,6 +185,21 @@ class CityScreen(internal val city: CityInfo): CameraStageBaseScreen() {
|
||||
tileGroup.onClick {
|
||||
if (city.isPuppet) return@onClick
|
||||
|
||||
if (constructionsTable.improvementBuildingToConstruct != null) {
|
||||
val improvement = constructionsTable.improvementBuildingToConstruct!!.getImprovement(city.getRuleset())!!
|
||||
if (tileInfo.canBuildImprovement(improvement, cityInfo.civInfo)) {
|
||||
tileInfo.improvementInProgress = improvement.name
|
||||
tileInfo.turnsToImprovement = -1
|
||||
constructionsTable.improvementBuildingToConstruct = null
|
||||
cityInfo.cityConstructions.addToQueue(improvement.name)
|
||||
update()
|
||||
} else {
|
||||
constructionsTable.improvementBuildingToConstruct = null
|
||||
update()
|
||||
}
|
||||
return@onClick
|
||||
}
|
||||
|
||||
selectedTile = tileInfo
|
||||
selectedConstruction = null
|
||||
if (tileGroup.isWorkable && canChangeState) {
|
||||
|
@ -31,9 +31,11 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
||||
private val constructionsQueueTable = Table()
|
||||
private val availableConstructionsTable = Table()
|
||||
private val buttons = Table()
|
||||
|
||||
private val pad = 10f
|
||||
|
||||
var improvementBuildingToConstruct:Building?=null
|
||||
|
||||
|
||||
init {
|
||||
showCityInfoTableButton = "Show stats drilldown".toTextButton()
|
||||
showCityInfoTableButton.onClick {
|
||||
@ -347,8 +349,15 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
||||
}
|
||||
|
||||
fun addConstructionToQueue(construction: IConstruction, cityConstructions: CityConstructions) {
|
||||
if (construction is Building && construction.uniqueObjects.any { it.placeholderText=="Creates a [] improvement on a specific tile" }){
|
||||
cityScreen.selectedTile
|
||||
improvementBuildingToConstruct = construction
|
||||
return
|
||||
}
|
||||
|
||||
cityConstructions.addToQueue(construction.name)
|
||||
if (!construction.shouldBeDisplayed(cityConstructions)) cityScreen.selectedConstruction = null
|
||||
if (!construction.shouldBeDisplayed(cityConstructions)) // For buildings - unlike units which can be queued multiple times
|
||||
cityScreen.selectedConstruction = null
|
||||
cityScreen.update()
|
||||
cityScreen.game.settings.addCompletedTutorialTask("Pick construction")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user