Fixed bug where production from cutting down forests could apply to perpetual constructions (#4694)

This commit is contained in:
Xander Lenstra 2021-07-31 22:46:18 +02:00 committed by GitHub
parent 96aad7b087
commit 5324eb96b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,7 +24,7 @@ import kotlin.math.roundToInt
* City constructions manager. * City constructions manager.
* *
* @property cityInfo the city it refers to * @property cityInfo the city it refers to
* @property currentConstructionFromQueue the name of the construction is currently worked, default = "Monument" * @property currentConstructionFromQueue the name of the construction is currently worked
* @property currentConstructionIsUserSet a flag indicating if the [currentConstructionFromQueue] has been set by the user or by the AI * @property currentConstructionIsUserSet a flag indicating if the [currentConstructionFromQueue] has been set by the user or by the AI
* @property constructionQueue a list of constructions names enqueued * @property constructionQueue a list of constructions names enqueued
*/ */
@ -100,8 +100,7 @@ class CityConstructions {
// all non-local uniques with this placeholderText from other cities belong to wonders, // all non-local uniques with this placeholderText from other cities belong to wonders,
// while the local uniques with this placeholderText are from buildings, but this is in no // while the local uniques with this placeholderText are from buildings, but this is in no
// way a given. In reality, there should be functions getBuildingStats and getWonderStats, // way a given. In reality, there should be functions getBuildingStats and getWonderStats,
// to solve this, with getStats merely adding these two together. Implementing this is on // to solve this, with getStats merely adding these two together.
// my ToDoList, but this PR is already large enough as it is.
for (unique in cityInfo.getLocalMatchingUniques("[] per [] population []") for (unique in cityInfo.getLocalMatchingUniques("[] per [] population []")
.filter { cityInfo.matchesFilter(it.params[2])} .filter { cityInfo.matchesFilter(it.params[2])}
) { ) {
@ -215,7 +214,7 @@ class CityConstructions {
// if the construction name is the same as the current construction, it isn't the first // if the construction name is the same as the current construction, it isn't the first
return constructionQueueIndex == constructionQueue.indexOfFirst { it == name } return constructionQueueIndex == constructionQueue.indexOfFirst { it == name }
} }
internal fun getConstruction(constructionName: String): IConstruction { internal fun getConstruction(constructionName: String): IConstruction {
val gameBasics = cityInfo.getRuleset() val gameBasics = cityInfo.getRuleset()
@ -297,6 +296,11 @@ class CityConstructions {
} }
fun addProductionPoints(productionToAdd: Int) { fun addProductionPoints(productionToAdd: Int) {
val construction = getConstruction(currentConstructionFromQueue)
if (construction is PerpetualConstruction) {
productionOverflow += productionToAdd
return
}
if (!inProgressConstructions.containsKey(currentConstructionFromQueue)) if (!inProgressConstructions.containsKey(currentConstructionFromQueue))
inProgressConstructions[currentConstructionFromQueue] = 0 inProgressConstructions[currentConstructionFromQueue] = 0
inProgressConstructions[currentConstructionFromQueue] = inProgressConstructions[currentConstructionFromQueue]!! + productionToAdd inProgressConstructions[currentConstructionFromQueue] = inProgressConstructions[currentConstructionFromQueue]!! + productionToAdd