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