There is only one true source of removing constructions from the queue, to which all other functions lead
This commit is contained in:
parent
4fc5c5de64
commit
1d2ec21210
5 changed files with 26 additions and 29 deletions
|
@ -217,7 +217,8 @@ class CityConstructions {
|
|||
}
|
||||
|
||||
fun addProductionPoints(productionToAdd: Int) {
|
||||
if (!inProgressConstructions.containsKey(currentConstructionFromQueue)) inProgressConstructions[currentConstructionFromQueue] = 0
|
||||
if (!inProgressConstructions.containsKey(currentConstructionFromQueue))
|
||||
inProgressConstructions[currentConstructionFromQueue] = 0
|
||||
inProgressConstructions[currentConstructionFromQueue] = inProgressConstructions[currentConstructionFromQueue]!! + productionToAdd
|
||||
}
|
||||
|
||||
|
@ -351,11 +352,7 @@ class CityConstructions {
|
|||
return cultureBuildingToBuild
|
||||
}
|
||||
|
||||
private fun cancelCurrentConstruction() {
|
||||
currentConstructionIsUserSet = false
|
||||
constructionQueue.removeAt(0)
|
||||
chooseNextConstruction()
|
||||
}
|
||||
private fun cancelCurrentConstruction() = removeFromQueue(0,true)
|
||||
|
||||
fun chooseNextConstruction() {
|
||||
if(currentConstructionIsUserSet) return
|
||||
|
@ -381,17 +378,18 @@ class CityConstructions {
|
|||
|
||||
fun removeFromQueue(constructionName: String) {
|
||||
if (constructionName in constructionQueue)
|
||||
constructionQueue.remove(constructionName)
|
||||
removeFromQueue(constructionQueue.indexOf(constructionName), true)
|
||||
}
|
||||
|
||||
fun removeFromQueue(constructionQueueIndex: Int) {
|
||||
// constructionQueueIndex -1 is the current construction
|
||||
if (constructionQueueIndex < 0) {
|
||||
// To prevent Construction Automation
|
||||
if (constructionQueue.isEmpty()) constructionQueue.add("Nothing")
|
||||
cancelCurrentConstruction()
|
||||
} else
|
||||
constructionQueue.removeAt(constructionQueueIndex)
|
||||
/** 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)
|
||||
if (constructionQueue.isEmpty()){
|
||||
if(automatic) chooseNextConstruction()
|
||||
else constructionQueue.add("Nothing") // To prevent Construction Automation
|
||||
currentConstructionIsUserSet = false
|
||||
}
|
||||
else currentConstructionIsUserSet = true // we're just continuing the regular queue
|
||||
}
|
||||
|
||||
fun raisePriority(constructionQueueIndex: Int) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import kotlin.math.roundToInt
|
|||
interface IConstruction : INamed {
|
||||
fun getProductionCost(civInfo: CivilizationInfo): Int
|
||||
fun getGoldCost(civInfo: CivilizationInfo): Int
|
||||
fun isBuildable(construction: CityConstructions): Boolean
|
||||
fun isBuildable(cityConstructions: CityConstructions): Boolean
|
||||
fun shouldBeDisplayed(cityConstructions: CityConstructions): Boolean
|
||||
fun postBuildEvent(construction: CityConstructions, wasBought: Boolean = false): Boolean // Yes I'm hilarious.
|
||||
fun getResource(): String?
|
||||
|
@ -27,17 +27,17 @@ open class PerpetualConstruction(override var name: String, val description: Str
|
|||
companion object {
|
||||
const val CONVERSION_RATE: Int = 4
|
||||
val science = object : PerpetualConstruction("Science", "Convert production to science at a rate of $CONVERSION_RATE to 1") {
|
||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||
return construction.cityInfo.civInfo.tech.getTechUniques().contains("Enables conversion of city production to science")
|
||||
override fun isBuildable(cityConstructions: CityConstructions): Boolean {
|
||||
return cityConstructions.cityInfo.civInfo.tech.getTechUniques().contains("Enables conversion of city production to science")
|
||||
}
|
||||
}
|
||||
val gold = object : PerpetualConstruction("Gold", "Convert production to gold at a rate of $CONVERSION_RATE to 1") {
|
||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||
return construction.cityInfo.civInfo.tech.getTechUniques().contains("Enables conversion of city production to gold")
|
||||
override fun isBuildable(cityConstructions: CityConstructions): Boolean {
|
||||
return cityConstructions.cityInfo.civInfo.tech.getTechUniques().contains("Enables conversion of city production to gold")
|
||||
}
|
||||
}
|
||||
val idle = object : PerpetualConstruction("Nothing", "The city will not produce anything.") {
|
||||
override fun isBuildable(construction: CityConstructions): Boolean = true
|
||||
override fun isBuildable(cityConstructions: CityConstructions): Boolean = true
|
||||
|
||||
override fun getProductionTooltip(cityInfo: CityInfo): String = ""
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ open class PerpetualConstruction(override var name: String, val description: Str
|
|||
throw Exception("Impossible!")
|
||||
}
|
||||
|
||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||
override fun isBuildable(cityConstructions: CityConstructions): Boolean {
|
||||
throw Exception("Impossible!")
|
||||
}
|
||||
|
||||
|
|
|
@ -334,8 +334,8 @@ class Building : NamedStats(), IConstruction{
|
|||
return ""
|
||||
}
|
||||
|
||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||
return getRejectionReason(construction)==""
|
||||
override fun isBuildable(cityConstructions: CityConstructions): Boolean {
|
||||
return getRejectionReason(cityConstructions)==""
|
||||
}
|
||||
|
||||
override fun postBuildEvent(cityConstructions: CityConstructions, wasBought: Boolean): Boolean {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.unciv.models.ruleset.unit
|
||||
|
||||
import com.unciv.Constants
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.city.CityConstructions
|
||||
import com.unciv.logic.city.IConstruction
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
|
@ -149,8 +148,8 @@ class BaseUnit : INamed, IConstruction {
|
|||
|
||||
fun isBuildable(civInfo: CivilizationInfo) = getRejectionReason(civInfo)==""
|
||||
|
||||
override fun isBuildable(construction: CityConstructions): Boolean {
|
||||
return getRejectionReason(construction) == ""
|
||||
override fun isBuildable(cityConstructions: CityConstructions): Boolean {
|
||||
return getRejectionReason(cityConstructions) == ""
|
||||
}
|
||||
|
||||
override fun postBuildEvent(construction: CityConstructions, wasBought: Boolean): Boolean {
|
||||
|
|
|
@ -269,7 +269,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||
if (!UncivGame.Current.worldScreen.isPlayersTurn || city.isPuppet) button.disable()
|
||||
else {
|
||||
button.onClick {
|
||||
cityConstructions.removeFromQueue(selectedQueueEntry)
|
||||
cityConstructions.removeFromQueue(selectedQueueEntry,false)
|
||||
cityScreen.selectedConstruction = null
|
||||
selectedQueueEntry = -2
|
||||
cityScreen.update()
|
||||
|
@ -318,7 +318,7 @@ class ConstructionsTable(val cityScreen: CityScreen) : Table(CameraStageBaseScre
|
|||
// currentConstruction is removed from the queue by purchaseConstruction
|
||||
// to avoid conflicts with NextTurnAutomation
|
||||
if (!constructionIsCurrentConstruction && cityConstructions.constructionQueue[selectedQueueEntry] == construction.name)
|
||||
cityConstructions.removeFromQueue(selectedQueueEntry)
|
||||
cityConstructions.removeFromQueue(selectedQueueEntry,false)
|
||||
selectedQueueEntry = -2
|
||||
cityScreen.selectedConstruction = null
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue