Fix constructions that's always visible showing when belonging to another civ (#12346)

* Fix constructions that's always visible showing when belonging to another civ

* Almost forgot

* RequiresTech is common enough that it should be included as well

* Two more that's common enough and has no reason to always show
This commit is contained in:
SeventhM 2024-10-24 10:34:45 -07:00 committed by GitHub
parent 1721fb605d
commit e348b7c388
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 62 additions and 41 deletions

View File

@ -245,11 +245,13 @@ class Building : RulesetStatsObject(), INonPerpetualConstruction {
if (cityConstructions.city.civ.civConstructions.countConstructedObjects(this) >= unique.params[0].toInt())
return false
}
if (hasUnique(UniqueType.ShowsWhenUnbuilable, StateForConditionals(cityConstructions.city)))
return true
val rejectionReasons = getRejectionReasons(cityConstructions)
if (hasUnique(UniqueType.ShowsWhenUnbuilable, StateForConditionals(cityConstructions.city)) &&
rejectionReasons.none { it.isNeverVisible() })
return true
if (rejectionReasons.any { it.type == RejectionReasonType.RequiresBuildingInSomeCities }
&& cityConstructions.city.civ.gameInfo.gameParameters.oneCityChallenge)
return false // You will never be able to get more cities, this building is effectively disabled

View File

@ -145,49 +145,66 @@ class RejectionReason(val type: RejectionReasonType,
fun isConstructionRejection(): Boolean = type in constructionRejectionReasonType
fun isNeverVisible(): Boolean = type in neverVisible
/** Returns the index of [orderedImportantRejectionTypes] with the smallest index having the
* highest precedence */
fun getRejectionPrecedence(): Int {
return orderedImportantRejectionTypes.indexOf(type)
}
// Used for constant variables in the functions above
private val techPolicyEraWonderRequirements = hashSetOf(
RejectionReasonType.Obsoleted,
RejectionReasonType.RequiresTech,
RejectionReasonType.RequiresPolicy,
RejectionReasonType.MorePolicyBranches,
RejectionReasonType.RequiresBuildingInSomeCity,
)
private val reasonsToDefinitivelyRemoveFromQueue = hashSetOf(
RejectionReasonType.Obsoleted,
RejectionReasonType.WonderAlreadyBuilt,
RejectionReasonType.NationalWonderAlreadyBuilt,
RejectionReasonType.CannotBeBuiltWith,
RejectionReasonType.MaxNumberBuildable,
)
private val orderedImportantRejectionTypes = listOf(
RejectionReasonType.ShouldNotBeDisplayed,
RejectionReasonType.WonderBeingBuiltElsewhere,
RejectionReasonType.RequiresBuildingInAllCities,
RejectionReasonType.RequiresBuildingInThisCity,
RejectionReasonType.RequiresBuildingInSomeCity,
RejectionReasonType.RequiresBuildingInSomeCities,
RejectionReasonType.CanOnlyBeBuiltInSpecificCities,
RejectionReasonType.CannotBeBuiltUnhappiness,
RejectionReasonType.PopulationRequirement,
RejectionReasonType.ConsumesResources,
RejectionReasonType.CanOnlyBePurchased,
RejectionReasonType.MaxNumberBuildable,
RejectionReasonType.NoPlaceToPutUnit,
)
// Exceptions. Used for units spawned/upgrade path, not built
private val constructionRejectionReasonType = listOf(
RejectionReasonType.Unbuildable,
RejectionReasonType.CannotBeBuiltUnhappiness,
RejectionReasonType.CannotBeBuilt,
RejectionReasonType.CanOnlyBeBuiltInSpecificCities,
)
companion object {
// Used for constant variables in the functions above
private val techPolicyEraWonderRequirements = hashSetOf(
RejectionReasonType.Obsoleted,
RejectionReasonType.RequiresTech,
RejectionReasonType.RequiresPolicy,
RejectionReasonType.MorePolicyBranches,
RejectionReasonType.RequiresBuildingInSomeCity,
)
private val reasonsToDefinitivelyRemoveFromQueue = hashSetOf(
RejectionReasonType.Obsoleted,
RejectionReasonType.WonderAlreadyBuilt,
RejectionReasonType.NationalWonderAlreadyBuilt,
RejectionReasonType.CannotBeBuiltWith,
RejectionReasonType.MaxNumberBuildable,
)
private val orderedImportantRejectionTypes = listOf(
RejectionReasonType.ShouldNotBeDisplayed,
RejectionReasonType.WonderBeingBuiltElsewhere,
RejectionReasonType.RequiresBuildingInAllCities,
RejectionReasonType.RequiresBuildingInThisCity,
RejectionReasonType.RequiresBuildingInSomeCity,
RejectionReasonType.RequiresBuildingInSomeCities,
RejectionReasonType.CanOnlyBeBuiltInSpecificCities,
RejectionReasonType.CannotBeBuiltUnhappiness,
RejectionReasonType.PopulationRequirement,
RejectionReasonType.ConsumesResources,
RejectionReasonType.CanOnlyBePurchased,
RejectionReasonType.MaxNumberBuildable,
RejectionReasonType.NoPlaceToPutUnit,
)
// Exceptions. Used for units spawned/upgrade path, not built
private val constructionRejectionReasonType = listOf(
RejectionReasonType.Unbuildable,
RejectionReasonType.CannotBeBuiltUnhappiness,
RejectionReasonType.CannotBeBuilt,
RejectionReasonType.CanOnlyBeBuiltInSpecificCities,
)
private val neverVisible = listOf(
RejectionReasonType.AlreadyBuilt,
RejectionReasonType.WonderAlreadyBuilt,
RejectionReasonType.NationalWonderAlreadyBuilt,
RejectionReasonType.DisabledBySetting,
RejectionReasonType.UniqueToOtherNation,
RejectionReasonType.ReplacedByOurUnique,
RejectionReasonType.Obsoleted,
RejectionReasonType.WonderBeingBuiltElsewhere,
RejectionReasonType.RequiresTech,
RejectionReasonType.NoSettlerForOneCityPlayers,
RejectionReasonType.WaterUnitsInCoastalCities,
)
}
}

View File

@ -163,10 +163,12 @@ class BaseUnit : RulesetObject(), INonPerpetualConstruction {
fun getDisbandGold(civInfo: Civilization) = getBaseGoldCost(civInfo, null).toInt() / 20
override fun shouldBeDisplayed(cityConstructions: CityConstructions): Boolean {
if (hasUnique(UniqueType.ShowsWhenUnbuilable, StateForConditionals(cityConstructions.city)))
return true
val rejectionReasons = getRejectionReasons(cityConstructions)
if (hasUnique(UniqueType.ShowsWhenUnbuilable, StateForConditionals(cityConstructions.city)) &&
rejectionReasons.none { it.isNeverVisible() })
return true
if (rejectionReasons.none { !it.shouldShow }) return true
if (canBePurchasedWithAnyStat(cityConstructions.city)
&& rejectionReasons.all { it.type == RejectionReasonType.Unbuildable }) return true