mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-23 03:23:17 -04:00
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:
parent
1721fb605d
commit
e348b7c388
@ -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
|
||||
|
@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user