Tech column validation and removing crashes from undefined building costs (#9664)

* Add in tech column validation

* Negative Columns

* Forgot to add techColumns to the add and clear functiond

* Remove restrictive cokumn check

* bugfixing
This commit is contained in:
SeventhM
2023-06-24 23:34:23 -07:00
committed by GitHub
parent 650a43aa3b
commit bc3f1341e1
6 changed files with 25 additions and 8 deletions

View File

@ -4,6 +4,7 @@
"era": "Ancient era",
"techCost": 20,
"buildingCost": 40,
"wonderCost": 185,
"techs": [
{
"name": "Agriculture",

View File

@ -4,6 +4,7 @@
"era": "Ancient era",
"techCost": 20,
"buildingCost": 40,
"wonderCost": 185,
"techs": [
{
"name": "Agriculture",

View File

@ -91,6 +91,7 @@ class Ruleset {
val quests = LinkedHashMap<String, Quest>()
val specialists = LinkedHashMap<String, Specialist>()
val technologies = LinkedHashMap<String, Technology>()
val techColumns = ArrayList<TechColumn>()
val terrains = LinkedHashMap<String, Terrain>()
val tileImprovements = LinkedHashMap<String, TileImprovement>()
val tileResources = LinkedHashMap<String, TileResource>()
@ -152,6 +153,7 @@ class Ruleset {
technologies.remove(it)
}
technologies.putAll(ruleset.technologies)
techColumns.addAll(ruleset.techColumns)
terrains.putAll(ruleset.terrains)
tileImprovements.putAll(ruleset.tileImprovements)
tileResources.putAll(ruleset.tileResources)
@ -212,6 +214,7 @@ class Ruleset {
ruinRewards.clear()
specialists.clear()
technologies.clear()
techColumns.clear()
terrains.clear()
tileImprovements.clear()
tileResources.clear()
@ -264,6 +267,7 @@ class Ruleset {
if (techFile.exists()) {
val techColumns = json().fromJsonFile(Array<TechColumn>::class.java, techFile)
for (techColumn in techColumns) {
this.techColumns.add(techColumn)
for (tech in techColumn.techs) {
if (tech.cost == 0) tech.cost = techColumn.techCost
tech.column = techColumn
@ -458,8 +462,9 @@ class Ruleset {
for (building in buildings.values) {
if (building.cost == -1 && building.getMatchingUniques(UniqueType.Unbuildable).none { it.conditionals.isEmpty() }) {
val column = technologies[building.requiredTech]?.column
?: throw UncivShowableException("Building '[${building.name}]' is buildable and therefore must either have an explicit cost or reference an existing tech.")
building.cost = if (building.isAnyWonder()) column.wonderCost else column.buildingCost
if (column != null) {
building.cost = if (building.isAnyWonder()) column.wonderCost else column.buildingCost
}
}
}
}

View File

@ -51,17 +51,27 @@ class RulesetValidator(val ruleset: Ruleset) {
for (tech in ruleset.technologies.values) {
for (otherTech in ruleset.technologies.values) {
if (tech != otherTech && otherTech.column == tech.column && otherTech.row == tech.row)
lines += "${tech.name} is in the same row as ${otherTech.name}!"
if (tech != otherTech && otherTech.column?.columnNumber == tech.column?.columnNumber && otherTech.row == tech.row)
lines += "${tech.name} is in the same row and column as ${otherTech.name}!"
}
checkUniques(tech, lines, rulesetInvariant, tryFixUnknownUniques)
}
for (techColumn in ruleset.techColumns){
if (techColumn.columnNumber < 0)
lines+= "Tech Column number ${techColumn.columnNumber} is negative"
if (techColumn.buildingCost == -1)
lines.add("Tech Column number ${techColumn.columnNumber} has no explicit building cost", RulesetErrorSeverity.Warning)
if (techColumn.wonderCost == -1)
lines.add("Tech Column number ${techColumn.columnNumber} has no explicit wonder cost", RulesetErrorSeverity.Warning)
}
for (building in ruleset.buildings.values) {
if (building.requiredTech == null && building.cost == -1 && !building.hasUnique(
UniqueType.Unbuildable))
lines += "${building.name} is buildable and therefore must either have an explicit cost or reference an existing tech!"
lines.add("${building.name} is buildable and therefore should either have an explicit cost or reference an existing tech!",
RulesetErrorSeverity.Warning)
checkUniques(building, lines, rulesetInvariant, tryFixUnknownUniques)

View File

@ -5,6 +5,6 @@ class TechColumn {
lateinit var era: String
var techs = ArrayList<Technology>()
var techCost: Int = 0
var buildingCost: Int = 0
var wonderCost: Int = 0
var buildingCost: Int = -1
var wonderCost: Int = -1
}

View File

@ -27,7 +27,7 @@ import kotlin.math.pow
in contrast to MapUnit, which is a specific unit of a certain type that appears on the map */
class BaseUnit : RulesetObject(), INonPerpetualConstruction {
override var cost: Int = 0
override var cost: Int = -1
override var hurryCostModifier: Int = 0
var movement: Int = 0
var strength: Int = 0