Resolved crash when mods make 2 techs require each other

This commit is contained in:
Yair Morgenstern
2022-10-13 22:55:12 +03:00
parent f3b4db9d64
commit f0ad7581bc
3 changed files with 35 additions and 1 deletions

View File

@ -751,9 +751,9 @@ class Ruleset {
?: return emptySet()
val techHashSet = HashSet<String>()
techHashSet += technology.prerequisites
prereqsHashMap[technologyName] = techHashSet
for (prerequisite in technology.prerequisites)
techHashSet += getPrereqTree(prerequisite)
prereqsHashMap[technologyName] = techHashSet
return techHashSet
}
@ -762,6 +762,9 @@ class Ruleset {
lines.add("No need to add $prereq as a prerequisite of ${tech.name} - it is already implicit from the other prerequisites!",
RulesetErrorSeverity.Warning)
}
if (getPrereqTree(prereq).contains(tech.name))
lines += "Techs ${tech.name} and $prereq require each other!"
}
if (tech.era() !in eras)
lines += "Unknown era ${tech.era()} referenced in column of tech ${tech.name}"

View File

@ -1724,6 +1724,11 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl
Applicable to: Conditional
??? example "&lt;upon discovering [tech]&gt;"
Example: "&lt;upon discovering [Agriculture]&gt;"
Applicable to: Conditional
??? example "&lt;after adopting [policy]&gt;"
Example: "&lt;after adopting [Oligarchy]&gt;"

View File

@ -0,0 +1,26 @@
package com.unciv.uniques
import com.unciv.models.ruleset.RulesetCache
import com.unciv.testing.GdxTestRunner
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(GdxTestRunner::class)
class UniqueErrorTests {
@Test
fun testCodependantTechs() {
RulesetCache.loadRulesets()
val ruleset = RulesetCache.getVanillaRuleset()
// Create a prerequisite loop
val techWithPrerequisites = ruleset.technologies.values.first { it.prerequisites.isNotEmpty() }
val prereq = ruleset.technologies[techWithPrerequisites.prerequisites.first()]!!
prereq.prerequisites.add(techWithPrerequisites.name)
ruleset.modOptions.isBaseRuleset = true
// Check mod links and ensure we don't get a crash, instead we get errors
val errors = ruleset.checkModLinks(false)
assert(errors.isNotOK())
}
}