mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-12 19:10:12 +07:00
Fix turns to construction (#1767)
Fix #1759: the stored production is used only for the first construction of its kind in the construction queue
This commit is contained in:
parent
8469956f91
commit
59e815c30e
@ -116,6 +116,7 @@ class CityConstructions {
|
||||
fun isBuilt(buildingName: String): Boolean = builtBuildings.contains(buildingName)
|
||||
fun isBeingConstructed(constructionName: String): Boolean = currentConstruction == constructionName
|
||||
fun isEnqueued(constructionName: String): Boolean = constructionQueue.contains(constructionName)
|
||||
fun isBeingConstructedOrEnqueued(constructionName: String): Boolean = isBeingConstructed(constructionName) || isEnqueued(constructionName)
|
||||
|
||||
fun isQueueFull(): Boolean = constructionQueue.size == queueMaxSize
|
||||
fun isQueueEmpty(): Boolean = constructionQueue.isEmpty()
|
||||
@ -125,6 +126,17 @@ class CityConstructions {
|
||||
return currentConstruction is Building && currentConstruction.isWonder
|
||||
}
|
||||
|
||||
fun isFirstOfItsKind(idx: Int, name: String): Boolean {
|
||||
// idx = 1 is the currentConstruction, so it is the first
|
||||
if (idx == -1)
|
||||
return true
|
||||
|
||||
// if the construction name is the same as the current construction, it isn't the first
|
||||
return !isBeingConstructed(name) &&
|
||||
idx == constructionQueue.indexOfFirst{it == name}
|
||||
}
|
||||
|
||||
|
||||
internal fun getConstruction(constructionName: String): IConstruction {
|
||||
val gameBasics = cityInfo.getRuleset()
|
||||
if (gameBasics.buildings.containsKey(constructionName))
|
||||
@ -151,14 +163,17 @@ class CityConstructions {
|
||||
else return 0
|
||||
}
|
||||
|
||||
fun getRemainingWork(constructionName: String): Int {
|
||||
fun getRemainingWork(constructionName: String, useStoredProduction: Boolean = true): Int {
|
||||
val constr = getConstruction(constructionName)
|
||||
if (constr is SpecialConstruction) return 0
|
||||
return constr.getProductionCost(cityInfo.civInfo) - getWorkDone(constructionName)
|
||||
return when {
|
||||
constr is SpecialConstruction -> 0
|
||||
useStoredProduction -> constr.getProductionCost(cityInfo.civInfo) - getWorkDone(constructionName)
|
||||
else -> constr.getProductionCost(cityInfo.civInfo)
|
||||
}
|
||||
}
|
||||
|
||||
fun turnsToConstruction(constructionName: String): Int {
|
||||
val workLeft = getRemainingWork(constructionName)
|
||||
fun turnsToConstruction(constructionName: String, useStoredProduction: Boolean = true): Int {
|
||||
val workLeft = getRemainingWork(constructionName, useStoredProduction)
|
||||
if(workLeft < 0) // we've done more work than actually necessary - possible if circumstances cause buildings to be cheaper later
|
||||
return 1 // we'll finish this next turn
|
||||
|
||||
|
@ -131,7 +131,8 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
||||
val specialConstructions = ArrayList<Table>()
|
||||
|
||||
for (unit in city.getRuleset().units.values.filter { it.shouldBeDisplayed(cityConstructions) }) {
|
||||
val turnsToUnit = cityConstructions.turnsToConstruction(unit.name)
|
||||
val useStoredProduction = !cityConstructions.isBeingConstructedOrEnqueued(unit.name)
|
||||
val turnsToUnit = cityConstructions.turnsToConstruction(unit.name, useStoredProduction)
|
||||
val productionButton = getProductionButton(unit.name,
|
||||
unit.name.tr() + "\r\n" + turnsToUnit + turnOrTurns(turnsToUnit),
|
||||
unit.getRejectionReason(cityConstructions))
|
||||
@ -139,6 +140,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
||||
}
|
||||
|
||||
for (building in city.getRuleset().buildings.values.filter { it.shouldBeDisplayed(cityConstructions)}) {
|
||||
val useStoredProduction = !cityConstructions.isBeingConstructedOrEnqueued(building.name)
|
||||
val turnsToBuilding = cityConstructions.turnsToConstruction(building.name)
|
||||
val productionTextButton = getProductionButton(building.name,
|
||||
building.name.tr() + "\r\n" + turnsToBuilding + turnOrTurns(turnsToBuilding),
|
||||
@ -163,6 +165,8 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
||||
|
||||
private fun getQueueEntry(idx: Int, name: String, isLast: Boolean, isSelected: Boolean): Table {
|
||||
val city = cityScreen.city
|
||||
val cityConstructions = city.cityConstructions
|
||||
|
||||
val table = Table()
|
||||
table.align(Align.left).pad(5f)
|
||||
table.background = ImageGetter.getBackground(Color.BLACK)
|
||||
@ -170,7 +174,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
||||
if (isSelected)
|
||||
table.background = ImageGetter.getBackground(Color.GREEN.cpy().lerp(Color.BLACK, 0.5f))
|
||||
|
||||
val turnsToComplete = cityScreen.city.cityConstructions.turnsToConstruction(name)
|
||||
val turnsToComplete = cityConstructions.turnsToConstruction(name, cityConstructions.isFirstOfItsKind(idx, name))
|
||||
val text = name.tr() + "\r\n" + turnsToComplete + turnOrTurns(turnsToComplete)
|
||||
|
||||
table.defaults().pad(2f).minWidth(40f)
|
||||
@ -192,7 +196,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
||||
return table
|
||||
}
|
||||
|
||||
private fun getProductionButton(construction: String, buttonText: String, rejectionReason: String = "", isSelectable: Boolean = true): Table {
|
||||
private fun getProductionButton(construction: String, buttonText: String, rejectionReason: String = ""): Table {
|
||||
val pickProductionButton = Table()
|
||||
|
||||
pickProductionButton.align(Align.left).pad(5f)
|
||||
|
Loading…
Reference in New Issue
Block a user