More UniqueType unit tests and correct some broken uniques in JSON files (#6965)

* Add ruin reward unique check plus fix broken unique
This commit is contained in:
OptimizedForDensity
2022-05-29 10:08:15 -04:00
committed by GitHub
parent ea31bd164f
commit 09195d6b62
9 changed files with 101 additions and 29 deletions

View File

@ -147,7 +147,7 @@ class GameInfo {
}
fun isReligionEnabled(): Boolean {
if (ruleSet.eras[gameParameters.startingEra]!!.hasUnique("Starting in this era disables religion")
if (ruleSet.eras[gameParameters.startingEra]!!.hasUnique(UniqueType.DisablesReligion)
|| ruleSet.modOptions.uniques.contains(ModOptionsConstants.disableReligion)
) return false
return gameParameters.religionEnabled

View File

@ -64,10 +64,10 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
// as game progresses Maintenance cost rises
val turnLimit = BASE_GAME_DURATION_TURNS * civInfo.gameInfo.gameParameters.gameSpeed.modifier
val gameProgress = min(civInfo.gameInfo.turns / turnLimit, 1f)
var cost = baseUnitCost * numberOfUnitsToPayFor * (1 + gameProgress)
cost = cost.pow(1 + gameProgress / 3) // Why 3? To spread 1 to 1.33
if (!civInfo.isPlayerCivilization())
cost *= civInfo.gameInfo.getDifficulty().aiUnitMaintenanceModifier
@ -110,16 +110,16 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
}
fun getBaseUnitSupply(): Int {
return civInfo.getDifficulty().unitSupplyBase +
return civInfo.getDifficulty().unitSupplyBase +
civInfo.getMatchingUniques(UniqueType.BaseUnitSupply).sumOf { it.params[0].toInt() }
}
fun getUnitSupplyFromCities(): Int {
return civInfo.cities.size *
(civInfo.getDifficulty().unitSupplyPerCity + civInfo.getMatchingUniques(UniqueType.UnitSupplyPerCity).sumOf { it.params[0].toInt() })
}
return civInfo.cities.size *
(civInfo.getDifficulty().unitSupplyPerCity + civInfo.getMatchingUniques(UniqueType.UnitSupplyPerCity).sumOf { it.params[0].toInt() })
}
fun getUnitSupplyFromPop(): Int {
var totalSupply = civInfo.cities.sumOf { it.population.population } * civInfo.gameInfo.ruleSet.modOptions.constants.unitSupplyPerPopulation
for (unique in civInfo.getMatchingUniques(UniqueType.UnitSupplyPerPop)) {
val applicablePopulation = civInfo.cities
.filter { it.matchesFilter(unique.params[1]) }
@ -309,7 +309,7 @@ class CivInfoStats(val civInfo: CivilizationInfo) {
civInfo.religionManager.numberOfCitiesFollowingThisReligion()
religionHappiness += unique.stats.happiness * followingCities
}
if (unique.placeholderText == "[] for every [] global followers []") {
if (unique.type == UniqueType.StatsFromGlobalFollowers) {
val followers =
civInfo.religionManager.numberOfFollowersFollowingThisReligion(unique.params[2])
religionHappiness +=

View File

@ -110,7 +110,7 @@ class PolicyManager {
// Should be deprecated together with TimedAttackStrength so
// I'm putting this here so the compiler will complain if we don't
val rememberToDeprecate = UniqueType.TimedAttackStrength
if (!unique.text.contains(turnCountRegex))
if (!unique.text.contains(turnCountRegex))
policyUniques.addUnique(unique)
}
}
@ -206,9 +206,9 @@ class PolicyManager {
}
}
for (unique in policy.uniques) {
if (unique.equalsPlaceholderText("Triggers the following global alert: []")) triggerGlobalAlerts(
policy, unique.getPlaceholderParameters()[0]
for (unique in policy.getMatchingUniques(UniqueType.OneTimeGlobalAlert)) {
triggerGlobalAlerts(
policy, unique.params[0]
)
}

View File

@ -155,12 +155,13 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
GrowthPercentBonus("[relativeAmount]% growth [cityFilter]", UniqueTarget.Global, UniqueTarget.FollowerBelief),
CarryOverFood("[relativeAmount]% Food is carried over after population increases [cityFilter]", UniqueTarget.Global, UniqueTarget.FollowerBelief),
GainFreeBuildings("Gain a free [buildingName] [cityFilter]", UniqueTarget.Global),
GreatPersonPointPercentage("[relativeAmount]% Great Person generation [cityFilter]", UniqueTarget.Global, UniqueTarget.FollowerBelief),
@Deprecated("As of 3.19.19", ReplaceWith("[relativeAmount]% Great Person generation [cityFilter]"))
GreatPersonPointPercentageDeprecated("[relativeAmount]% great person generation [cityFilter]", UniqueTarget.Global, UniqueTarget.FollowerBelief),
DisablesReligion("Starting in this era disables religion", UniqueTarget.Era),
FreeExtraBeliefs("May choose [amount] additional [beliefType] beliefs when [foundingOrEnhancing] a religion", UniqueTarget.Global),
FreeExtraAnyBeliefs("May choose [amount] additional belief(s) of any type when [foundingOrEnhancing] a religion", UniqueTarget.Global),
StatsWhenAdoptingReligionSpeed("[stats] when a city adopts this religion for the first time (modified by game speed)", UniqueTarget.Global),
@ -197,7 +198,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
BuyItemsDiscount("[stat] cost of purchasing items in cities [relativeAmount]%", UniqueTarget.Global, UniqueTarget.FollowerBelief),
BuyBuildingsDiscount("[stat] cost of purchasing [buildingFilter] buildings [relativeAmount]%", UniqueTarget.Global, UniqueTarget.FollowerBelief),
BuyUnitsDiscount("[stat] cost of purchasing [baseUnitFilter] units [relativeAmount]%", UniqueTarget.Global, UniqueTarget.FollowerBelief),
// Should be replaced with moddable improvements when roads become moddable
RoadMovementSpeed("Improves movement speed on roads",UniqueTarget.Global),
RoadsConnectAcrossRivers("Roads connect tiles across rivers", UniqueTarget.Global),
@ -278,7 +279,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
GoldenAgeLength("[relativeAmount]% Golden Age length", UniqueTarget.Global),
StrengthForCities("[relativeAmount]% Strength for cities", UniqueTarget.Global, UniqueTarget.FollowerBelief),
UnitStartingExperience("New [baseUnitFilter] units start with [amount] Experience [cityFilter]", UniqueTarget.Global, UniqueTarget.FollowerBelief),
UnitStartingPromotions("All newly-trained [baseUnitFilter] units [cityFilter] receive the [promotion] promotion", UniqueTarget.Global, UniqueTarget.FollowerBelief),
UnitStartingActions("[baseUnitFilter] units built [cityFilter] can [action] [amount] extra times", UniqueTarget.Global, UniqueTarget.FollowerBelief),
@ -291,7 +292,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
EmbarkAndEnterOcean("Can embark and move over Coasts and Oceans immediately", UniqueTarget.Global),
PopulationLossFromNukes("Population loss from nuclear attacks [relativeAmount]% [cityFilter]", UniqueTarget.Global),
NaturalReligionSpreadStrength("[relativeAmount]% Natural religion spread [cityFilter]", UniqueTarget.FollowerBelief, UniqueTarget.Global),
ReligionSpreadDistance("Religion naturally spreads to cities [amount] tiles away", UniqueTarget.Global, UniqueTarget.FollowerBelief),
@ -731,6 +732,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
OneTimeRevealSpecificMapTiles("Reveal up to [amount/'all'] [tileFilter] within a [amount] tile radius", UniqueTarget.Ruins),
OneTimeRevealCrudeMap("From a randomly chosen tile [amount] tiles away from the ruins, reveal tiles up to [amount] tiles away with [amount]% chance", UniqueTarget.Ruins),
OneTimeTriggerVoting("Triggers voting for the Diplomatic Victory", UniqueTarget.Triggerable), // used in Building
OneTimeGlobalAlert("Triggers the following global alert: [comment]", UniqueTarget.Triggerable), // used in Policy
OneTimeUnitHeal("Heal this unit by [amount] HP", UniqueTarget.Promotion),
OneTimeUnitGainXP("This Unit gains [amount] XP", UniqueTarget.Ruins),
@ -765,7 +767,7 @@ enum class UniqueType(val text: String, vararg targets: UniqueTarget, val flags:
BonusForUnitsInRadius("Bonus for units in 2 tile radius 15%", UniqueTarget.Unit),
@Deprecated("as of 4.0.15", ReplaceWith("Irremovable"), DeprecationLevel.ERROR)
Indestructible("Indestructible", UniqueTarget.Improvement),
@Deprecated("as of 3.19.1", ReplaceWith("[stats] from every [Wonder]"), DeprecationLevel.ERROR)
StatsFromWondersDeprecated("[stats] from every Wonder", UniqueTarget.Global, UniqueTarget.FollowerBelief),
@Deprecated("as of 3.19.3", ReplaceWith("[stats] from every [buildingFilter] <in cities where this religion has at least [amount] followers>"), DeprecationLevel.ERROR)