mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-27 13:55:54 -04:00
cityInfo.getMAtchingUniques accepts uniqueType
This commit is contained in:
parent
ef7676183d
commit
bdefb7894c
@ -711,11 +711,32 @@ class CityInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Finds matching uniques provided from both local and non-local sources.
|
||||||
|
fun getMatchingUniques(
|
||||||
|
uniqueType: UniqueType,
|
||||||
|
// We might have this cached to avoid concurrency problems. If we don't, just get it directly
|
||||||
|
localUniques: Sequence<Unique> = getLocalMatchingUniques(uniqueType),
|
||||||
|
): Sequence<Unique> {
|
||||||
|
// The localUniques might not be filtered when passed as a parameter, so we filter it anyway
|
||||||
|
// The time loss shouldn't be that large I don't think
|
||||||
|
return civInfo.getMatchingUniques(uniqueType, this) +
|
||||||
|
localUniques.filter {
|
||||||
|
it.isOfType(uniqueType)
|
||||||
|
&& it.params.none { param -> param == "in other cities" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Matching uniques provided by sources in the city itself
|
// Matching uniques provided by sources in the city itself
|
||||||
fun getLocalMatchingUniques(placeholderText: String): Sequence<Unique> {
|
fun getLocalMatchingUniques(placeholderText: String): Sequence<Unique> {
|
||||||
return cityConstructions.builtBuildingUniqueMap.getUniques(placeholderText)
|
return cityConstructions.builtBuildingUniqueMap.getUniques(placeholderText)
|
||||||
.filter { it.params.none { param -> param == "in other cities" } } +
|
.filter { it.params.none { param -> param == "in other cities" } } +
|
||||||
religion.getMatchingUniques(placeholderText)
|
religion.getUniques().filter { it.placeholderText == placeholderText }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getLocalMatchingUniques(uniqueType: UniqueType): Sequence<Unique> {
|
||||||
|
return cityConstructions.builtBuildingUniqueMap.getUniques(uniqueType)
|
||||||
|
.filter { it.params.none { param -> param == "in other cities" } } +
|
||||||
|
religion.getUniques().filter { it.isOfType(uniqueType) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all uniques that originate from this city
|
// Get all uniques that originate from this city
|
||||||
@ -731,7 +752,7 @@ class CityInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun getMatchingUniquesWithNonLocalEffectsByEnum(uniqueType: UniqueType): Sequence<Unique> {
|
fun getMatchingUniquesWithNonLocalEffects(uniqueType: UniqueType): Sequence<Unique> {
|
||||||
return cityConstructions.builtBuildingUniqueMap.getUniques(uniqueType)
|
return cityConstructions.builtBuildingUniqueMap.getUniques(uniqueType)
|
||||||
.filter { it.params.none { param -> param == "in this city" } }
|
.filter { it.params.none { param -> param == "in this city" } }
|
||||||
// Note that we don't query religion here, as those only have local effects (for now at least)
|
// Note that we don't query religion here, as those only have local effects (for now at least)
|
||||||
|
@ -63,13 +63,8 @@ class CityInfoReligionManager {
|
|||||||
return majorityReligion.getFollowerUniques()
|
return majorityReligion.getFollowerUniques()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMatchingUniques(unique: String): Sequence<Unique> {
|
|
||||||
return getUniques().filter { it.placeholderText == unique }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getPressures(): Counter<String> {
|
fun getPressures(): Counter<String> = pressures.clone()
|
||||||
return pressures.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun clearAllPressures() {
|
private fun clearAllPressures() {
|
||||||
pressures.clear()
|
pressures.clear()
|
||||||
|
@ -21,7 +21,7 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
|
|||||||
private fun getUnitMaintenance(): Int {
|
private fun getUnitMaintenance(): Int {
|
||||||
val baseUnitCost = 0.5f
|
val baseUnitCost = 0.5f
|
||||||
var freeUnits = 3
|
var freeUnits = 3
|
||||||
for (unique in civInfo.getMatchingUniquesByEnum(UniqueType.FreeUnits)) {
|
for (unique in civInfo.getMatchingUniques(UniqueType.FreeUnits)) {
|
||||||
if (!unique.conditionalsApply(civInfo)) continue
|
if (!unique.conditionalsApply(civInfo)) continue
|
||||||
freeUnits += unique.params[0].toInt()
|
freeUnits += unique.params[0].toInt()
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
|
|||||||
|
|
||||||
var numberOfUnitsToPayFor = max(0f, unitsToPayFor.count().toFloat() - freeUnits)
|
var numberOfUnitsToPayFor = max(0f, unitsToPayFor.count().toFloat() - freeUnits)
|
||||||
|
|
||||||
for (unique in civInfo.getMatchingUniquesByEnum(UniqueType.UnitMaintenanceDiscount)) {
|
for (unique in civInfo.getMatchingUniques(UniqueType.UnitMaintenanceDiscount)) {
|
||||||
if (!unique.conditionalsApply(civInfo)) continue
|
if (!unique.conditionalsApply(civInfo)) continue
|
||||||
val numberOfUnitsWithDiscount = min(
|
val numberOfUnitsWithDiscount = min(
|
||||||
numberOfUnitsToPayFor,
|
numberOfUnitsToPayFor,
|
||||||
@ -45,14 +45,14 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
|
|||||||
numberOfUnitsToPayFor -= numberOfUnitsWithDiscount * unique.params[0].toFloat() / 100f
|
numberOfUnitsToPayFor -= numberOfUnitsWithDiscount * unique.params[0].toFloat() / 100f
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unique in civInfo.getMatchingUniquesByEnum(UniqueType.DecreasedUnitMaintenanceCostsByFilter)) {
|
for (unique in civInfo.getMatchingUniques(UniqueType.DecreasedUnitMaintenanceCostsByFilter)) {
|
||||||
val numberOfUnitsWithDiscount = min(
|
val numberOfUnitsWithDiscount = min(
|
||||||
numberOfUnitsToPayFor,
|
numberOfUnitsToPayFor,
|
||||||
unitsToPayFor.count { it.matchesFilter(unique.params[1]) }.toFloat()
|
unitsToPayFor.count { it.matchesFilter(unique.params[1]) }.toFloat()
|
||||||
)
|
)
|
||||||
numberOfUnitsToPayFor -= numberOfUnitsWithDiscount * unique.params[0].toFloat() / 100f
|
numberOfUnitsToPayFor -= numberOfUnitsWithDiscount * unique.params[0].toFloat() / 100f
|
||||||
}
|
}
|
||||||
for (unique in civInfo.getMatchingUniquesByEnum(UniqueType.DecreasedUnitMaintenanceCostsGlobally)) {
|
for (unique in civInfo.getMatchingUniques(UniqueType.DecreasedUnitMaintenanceCostsGlobally)) {
|
||||||
numberOfUnitsToPayFor *= 1f - unique.params[0].toFloat() / 100f
|
numberOfUnitsToPayFor *= 1f - unique.params[0].toFloat() / 100f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,11 +317,11 @@ class CivilizationInfo {
|
|||||||
fun hasUnique(unique: String) = getMatchingUniques(unique).any()
|
fun hasUnique(unique: String) = getMatchingUniques(unique).any()
|
||||||
|
|
||||||
/** Destined to replace getMatchingUniques, gradually, as we fill the enum */
|
/** Destined to replace getMatchingUniques, gradually, as we fill the enum */
|
||||||
fun getMatchingUniquesByEnum(uniqueType: UniqueType, cityToIgnore: CityInfo?=null): Sequence<Unique> {
|
fun getMatchingUniques(uniqueType: UniqueType, cityToIgnore: CityInfo?=null): Sequence<Unique> {
|
||||||
val ruleset = gameInfo.ruleSet
|
val ruleset = gameInfo.ruleSet
|
||||||
return nation.uniqueObjects.asSequence().filter { it.matches(uniqueType, ruleset) } +
|
return nation.uniqueObjects.asSequence().filter { it.matches(uniqueType, ruleset) } +
|
||||||
cities.asSequence().filter { it != cityToIgnore }.flatMap { city ->
|
cities.asSequence().filter { it != cityToIgnore }.flatMap { city ->
|
||||||
city.getMatchingUniquesWithNonLocalEffectsByEnum(uniqueType)
|
city.getMatchingUniquesWithNonLocalEffects(uniqueType)
|
||||||
} +
|
} +
|
||||||
policies.policyUniques.getUniques(uniqueType) +
|
policies.policyUniques.getUniques(uniqueType) +
|
||||||
tech.techUniques.getUniques(uniqueType) +
|
tech.techUniques.getUniques(uniqueType) +
|
||||||
|
Loading…
x
Reference in New Issue
Block a user