Fixed spearman not being to be able to upgrade to anything after Gunpowder and before Metallurgy

This commit is contained in:
Yair Morgenstern 2022-10-24 20:51:52 +03:00
parent 3246b82531
commit 2f693547b4
3 changed files with 36 additions and 20 deletions

View File

@ -147,7 +147,7 @@
"rangedStrength": 7,
"cost": 40,
"requiredTech": "Archery",
"obsoleteTech": "Construction",
"obsoleteTech": "Machinery",
"upgradesTo": "Crossbowman",
"attackSound": "arrow"
},
@ -540,7 +540,7 @@
"requiredTech": "Civil Service",
"uniques": ["[+50]% Strength <vs [Mounted] units>"],
"upgradesTo": "Lancer",
"obsoleteTech": "Gunpowder",
"obsoleteTech": "Metallurgy",
"attackSound": "metalhit"
},
{
@ -554,7 +554,7 @@
"requiredTech": "Civil Service",
"uniques": ["[+50]% Strength <vs [Mounted] units>", "Can move immediately once bought" ],
"upgradesTo": "Lancer",
"obsoleteTech": "Gunpowder",
"obsoleteTech": "Metallurgy",
"attackSound": "metalhit"
//"Requires [Mercenary Army]" in BNW
},

View File

@ -407,7 +407,7 @@
"requiredTech": "Civil Service",
"uniques": ["[+50]% Strength <vs [Mounted] units>"],
"upgradesTo": "Lancer",
"obsoleteTech": "Gunpowder",
"obsoleteTech": "Metallurgy",
"attackSound": "metalhit"
},
{
@ -421,7 +421,7 @@
"requiredTech": "Civil Service",
"uniques": ["[+50]% Strength <vs [Mounted] units>", "Can move immediately once bought" ],
"upgradesTo": "Lancer",
"obsoleteTech": "Gunpowder",
"obsoleteTech": "Metallurgy",
"attackSound": "metalhit"
//"Requires [Mercenary Army]" in BNW
},
@ -921,7 +921,7 @@
"cost": 320,
"requiredTech": "Rifling",
"upgradesTo": "Infantry",
"obsoleteTech": "Plastics",
"obsoleteTech": "Replaceable Parts",
"uniques": ["[+20]% Strength <when fighting in [Foreign Land] tiles>"],
"attackSound": "shot"
},

View File

@ -565,6 +565,19 @@ class Ruleset {
}
fun checkModLinks(tryFixUnknownUniques: Boolean = false): RulesetErrorList {
val prereqsHashMap = HashMap<String,HashSet<String>>()
fun getPrereqTree(technologyName: String): Set<String> {
if (prereqsHashMap.containsKey(technologyName)) return prereqsHashMap[technologyName]!!
val technology = technologies[technologyName]
?: return emptySet()
val techHashSet = HashSet<String>()
techHashSet += technology.prerequisites
prereqsHashMap[technologyName] = techHashSet
for (prerequisite in technology.prerequisites)
techHashSet += getPrereqTree(prerequisite)
return techHashSet
}
val lines = RulesetErrorList()
// Checks for all mods - only those that can succeed without loading a base ruleset
@ -631,11 +644,26 @@ class Ruleset {
lines += "${unit.name} requires tech ${unit.requiredTech} which does not exist!"
if (unit.obsoleteTech != null && !technologies.containsKey(unit.obsoleteTech!!))
lines += "${unit.name} obsoletes at tech ${unit.obsoleteTech} which does not exist!"
if (unit.upgradesTo != null && !units.containsKey(unit.upgradesTo!!))
lines += "${unit.name} upgrades to unit ${unit.upgradesTo} which does not exist!"
// Check that we don't obsolete ourselves before we can upgrade
if (unit.upgradesTo!=null && units.containsKey(unit.upgradesTo!!)
&& unit.obsoleteTech!=null && technologies.containsKey(unit.obsoleteTech!!)) {
val upgradedUnit = units[unit.upgradesTo!!]!!
if (upgradedUnit.requiredTech != null && upgradedUnit.requiredTech != unit.obsoleteTech
&& !getPrereqTree(unit.obsoleteTech!!).contains(upgradedUnit.requiredTech)
)
lines.add(
"${unit.name} obsoletes at tech ${unit.obsoleteTech}," +
" and therefore ${upgradedUnit.requiredTech} for its upgrade ${upgradedUnit.name} may not yet be researched!",
RulesetErrorSeverity.Warning
)
}
for (resource in unit.getResourceRequirements().keys)
if (!tileResources.containsKey(resource))
lines += "${unit.name} requires resource $resource which does not exist!"
if (unit.upgradesTo != null && !units.containsKey(unit.upgradesTo!!))
lines += "${unit.name} upgrades to unit ${unit.upgradesTo} which does not exist!"
if (unit.replaces != null && !units.containsKey(unit.replaces!!))
lines += "${unit.name} replaces ${unit.replaces} which does not exist!"
for (promotion in unit.promotions)
@ -739,23 +767,11 @@ class Ruleset {
checkUniques(terrain, lines, rulesetSpecific, tryFixUnknownUniques)
}
val prereqsHashMap = HashMap<String,HashSet<String>>()
for (tech in technologies.values) {
for (prereq in tech.prerequisites) {
if (!technologies.containsKey(prereq))
lines += "${tech.name} requires tech $prereq which does not exist!"
fun getPrereqTree(technologyName: String): Set<String> {
if (prereqsHashMap.containsKey(technologyName)) return prereqsHashMap[technologyName]!!
val technology = technologies[technologyName]
?: return emptySet()
val techHashSet = HashSet<String>()
techHashSet += technology.prerequisites
prereqsHashMap[technologyName] = techHashSet
for (prerequisite in technology.prerequisites)
techHashSet += getPrereqTree(prerequisite)
return techHashSet
}
if (tech.prerequisites.asSequence().filterNot { it == prereq }
.any { getPrereqTree(it).contains(prereq) }){