Resolved #5495 - Removed "matches" function with runtime-compliance checks entirely

All unique checks should be on load
This commit is contained in:
yairm210 2021-10-19 22:59:53 +03:00
parent 96c69cf1e9
commit b0b9ef04fd
8 changed files with 19 additions and 33 deletions

View File

@ -227,19 +227,17 @@ object HexMath {
return minOf(left, right, top, bottom)
} else {
val radius = mapParameters.mapSize.radius
if (mapParameters.worldWrap) {
// The non-wrapping method holds in the upper two and lower two 'triangles' of the hexagon
// but needs special casing for left and right 'wedges', where only distance from the
// 'choke points' counts (upper and lower hex at the 'seam' where height is smallest).
// These are at (radius,0) and (0,-radius)
if (x.sign == y.sign) return radius - getDistance(vector, Vector2.Zero)
// left wedge - the 'choke points' are not wrapped relative to us
if (x > 0) return min(getDistance(vector, Vector2(radius.toFloat(),0f)), getDistance(vector, Vector2(0f, -radius.toFloat())))
// right wedge - compensate wrap by using a hex 1 off along the edge - same result
return min(getDistance(vector, Vector2(1f, radius.toFloat())), getDistance(vector, Vector2(-radius.toFloat(), -1f)))
} else {
return radius - getDistance(vector, Vector2.Zero)
}
if (!mapParameters.worldWrap) return radius - getDistance(vector, Vector2.Zero)
// The non-wrapping method holds in the upper two and lower two 'triangles' of the hexagon
// but needs special casing for left and right 'wedges', where only distance from the
// 'choke points' counts (upper and lower hex at the 'seam' where height is smallest).
// These are at (radius,0) and (0,-radius)
if (x.sign == y.sign) return radius - getDistance(vector, Vector2.Zero)
// left wedge - the 'choke points' are not wrapped relative to us
if (x > 0) return min(getDistance(vector, Vector2(radius.toFloat(),0f)), getDistance(vector, Vector2(0f, -radius.toFloat())))
// right wedge - compensate wrap by using a hex 1 off along the edge - same result
return min(getDistance(vector, Vector2(1f, radius.toFloat())), getDistance(vector, Vector2(-radius.toFloat(), -1f)))
}
}
}

View File

@ -282,7 +282,7 @@ class CityInfo {
if (tileInfo.improvement == null) continue
val tileImprovement = tileInfo.getTileImprovement()
for (unique in tileImprovement!!.uniqueObjects) {
if (unique.matches(UniqueType.ProvidesResources, getRuleset())) {
if (unique.isOfType(UniqueType.ProvidesResources)) {
if (!unique.conditionalsApply(civInfo, this)) continue
val resource = getRuleset().tileResources[unique.params[1]] ?: continue
cityResources.add(
@ -291,7 +291,7 @@ class CityInfo {
"Improvements"
)
}
if (unique.matches(UniqueType.ConsumesResources, getRuleset())) {
if (unique.isOfType(UniqueType.ConsumesResources)) {
val resource = getRuleset().tileResources[unique.params[1]] ?: continue
cityResources.add(
resource,

View File

@ -244,14 +244,6 @@ class CityStats(val cityInfo: CityInfo) {
// "[stats] in cities on [tileFilter] tiles"
if (unique.placeholderText == "[] in cities on [] tiles" && cityInfo.getCenterTile().matchesTerrainFilter(unique.params[1]))
stats.add(unique.stats)
// Deprecated since 3.16.16
// "[stats] if this city has at least [amount] specialists"
if (unique.matches(UniqueType.StatBonusForNumberOfSpecialists, cityInfo.getRuleset())
&& cityInfo.population.getNumberOfSpecialists() >= unique.params[1].toInt()
)
stats.add(unique.stats)
//
if (unique.placeholderText == "[] per turn from cities before []" && !cityInfo.civInfo.hasTechOrPolicy(unique.params[1]))
stats.add(unique.stats)

View File

@ -352,8 +352,7 @@ class CivilizationInfo {
// Does not return local uniques, only global ones.
/** Destined to replace getMatchingUniques, gradually, as we fill the enum */
fun getMatchingUniques(uniqueType: UniqueType, stateForConditionals: StateForConditionals? = null, cityToIgnore: CityInfo? = null) = sequence {
val ruleset = gameInfo.ruleSet
yieldAll(nation.uniqueObjects.asSequence().filter {it.matches(uniqueType, ruleset) })
yieldAll(nation.uniqueObjects.asSequence().filter {it.isOfType(uniqueType) })
yieldAll(cities.asSequence()
.filter { it != cityToIgnore }
.flatMap { city -> city.getMatchingUniquesWithNonLocalEffects(uniqueType) }
@ -362,7 +361,7 @@ class CivilizationInfo {
yieldAll(tech.techUniques.getUniques(uniqueType))
yieldAll(temporaryUniques.asSequence()
.map { it.first }
.filter { it.matches(uniqueType, ruleset) }
.filter { it.isOfType(uniqueType) }
)
yieldAll(getEra().getMatchingUniques(uniqueType))
if (religionManager.religion != null)

View File

@ -413,7 +413,7 @@ open class TileInfo {
matchesTerrainFilter(it.params[0]) && !civInfo.tech.isResearched(it.params[1])
} -> false
improvement.uniqueObjects.any {
it.matches(UniqueType.ConsumesResources, ruleset)
it.isOfType(UniqueType.ConsumesResources)
&& civInfo.getCivResourcesByName()[it.params[1]]!! < it.params[0].toInt()
} -> false
else -> canImprovementBeBuiltHere(improvement, hasViewableResource(civInfo))

View File

@ -24,10 +24,6 @@ class Unique(val text: String, val sourceObjectType: UniqueTarget? = null, val s
fun isOfType(uniqueType: UniqueType) = uniqueType == type
/** We can't save compliance errors in the unique, since it's ruleset-dependant */
fun matches(uniqueType: UniqueType, ruleset: Ruleset) = isOfType(uniqueType)
&& uniqueType.getComplianceErrors(this, ruleset).isEmpty()
fun conditionalsApply(civInfo: CivilizationInfo? = null, city: CityInfo? = null): Boolean {
return conditionalsApply(StateForConditionals(civInfo, city))
}
@ -112,3 +108,4 @@ class UniqueMap: HashMap<String, ArrayList<Unique>>() {
fun getAllUniques() = this.asSequence().flatMap { it.value.asSequence() }
}

View File

@ -64,7 +64,7 @@ enum class UniqueType(val text:String, vararg targets: UniqueTarget) {
Stats("[stats]", UniqueTarget.Global, UniqueTarget.FollowerBelief),
StatsPerCity("[stats] [cityFilter]", UniqueTarget.Global),
@Deprecated("As of 3.16.16", ReplaceWith("[stats] <if this city has at least [amount] specialists>"), DeprecationLevel.WARNING)
@Deprecated("As of 3.16.16", ReplaceWith("[stats] <if this city has at least [amount] specialists>"), DeprecationLevel.ERROR)
StatBonusForNumberOfSpecialists("[stats] if this city has at least [amount] specialists", UniqueTarget.Global),
StatPercentBonus("[amount]% [stat]", UniqueTarget.Global),

View File

@ -595,7 +595,7 @@ object UnitActions {
var resourcesAvailable = true
if (improvement.uniqueObjects.any {
it.matches(UniqueType.ConsumesResources, tile.ruleset) && civResources[unique.params[1]] ?: 0 < unique.params[0].toInt()
it.isOfType(UniqueType.ConsumesResources, tile.ruleset) && civResources[unique.params[1]] ?: 0 < unique.params[0].toInt()
})
resourcesAvailable = false