From 2f693547b4003de4d08f54003f25d3dc9cbb1f21 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Mon, 24 Oct 2022 20:51:52 +0300 Subject: [PATCH] Fixed spearman not being to be able to upgrade to anything after Gunpowder and before Metallurgy --- .../jsons/Civ V - Gods & Kings/Units.json | 6 +-- .../assets/jsons/Civ V - Vanilla/Units.json | 6 +-- core/src/com/unciv/models/ruleset/Ruleset.kt | 44 +++++++++++++------ 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/android/assets/jsons/Civ V - Gods & Kings/Units.json b/android/assets/jsons/Civ V - Gods & Kings/Units.json index 62595b983d..7431a5d4f9 100644 --- a/android/assets/jsons/Civ V - Gods & Kings/Units.json +++ b/android/assets/jsons/Civ V - Gods & Kings/Units.json @@ -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 "], "upgradesTo": "Lancer", - "obsoleteTech": "Gunpowder", + "obsoleteTech": "Metallurgy", "attackSound": "metalhit" }, { @@ -554,7 +554,7 @@ "requiredTech": "Civil Service", "uniques": ["[+50]% Strength ", "Can move immediately once bought" ], "upgradesTo": "Lancer", - "obsoleteTech": "Gunpowder", + "obsoleteTech": "Metallurgy", "attackSound": "metalhit" //"Requires [Mercenary Army]" in BNW }, diff --git a/android/assets/jsons/Civ V - Vanilla/Units.json b/android/assets/jsons/Civ V - Vanilla/Units.json index 4adf30ad47..d8921b77b5 100644 --- a/android/assets/jsons/Civ V - Vanilla/Units.json +++ b/android/assets/jsons/Civ V - Vanilla/Units.json @@ -407,7 +407,7 @@ "requiredTech": "Civil Service", "uniques": ["[+50]% Strength "], "upgradesTo": "Lancer", - "obsoleteTech": "Gunpowder", + "obsoleteTech": "Metallurgy", "attackSound": "metalhit" }, { @@ -421,7 +421,7 @@ "requiredTech": "Civil Service", "uniques": ["[+50]% Strength ", "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 "], "attackSound": "shot" }, diff --git a/core/src/com/unciv/models/ruleset/Ruleset.kt b/core/src/com/unciv/models/ruleset/Ruleset.kt index 1ce2448431..65a1143862 100644 --- a/core/src/com/unciv/models/ruleset/Ruleset.kt +++ b/core/src/com/unciv/models/ruleset/Ruleset.kt @@ -565,6 +565,19 @@ class Ruleset { } fun checkModLinks(tryFixUnknownUniques: Boolean = false): RulesetErrorList { + val prereqsHashMap = HashMap>() + fun getPrereqTree(technologyName: String): Set { + if (prereqsHashMap.containsKey(technologyName)) return prereqsHashMap[technologyName]!! + val technology = technologies[technologyName] + ?: return emptySet() + val techHashSet = HashSet() + 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>() 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 { - if (prereqsHashMap.containsKey(technologyName)) return prereqsHashMap[technologyName]!! - val technology = technologies[technologyName] - ?: return emptySet() - val techHashSet = HashSet() - 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) }){