mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 23:10:39 -04:00
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:
parent
650a43aa3b
commit
bc3f1341e1
@ -4,6 +4,7 @@
|
|||||||
"era": "Ancient era",
|
"era": "Ancient era",
|
||||||
"techCost": 20,
|
"techCost": 20,
|
||||||
"buildingCost": 40,
|
"buildingCost": 40,
|
||||||
|
"wonderCost": 185,
|
||||||
"techs": [
|
"techs": [
|
||||||
{
|
{
|
||||||
"name": "Agriculture",
|
"name": "Agriculture",
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
"era": "Ancient era",
|
"era": "Ancient era",
|
||||||
"techCost": 20,
|
"techCost": 20,
|
||||||
"buildingCost": 40,
|
"buildingCost": 40,
|
||||||
|
"wonderCost": 185,
|
||||||
"techs": [
|
"techs": [
|
||||||
{
|
{
|
||||||
"name": "Agriculture",
|
"name": "Agriculture",
|
||||||
|
@ -91,6 +91,7 @@ class Ruleset {
|
|||||||
val quests = LinkedHashMap<String, Quest>()
|
val quests = LinkedHashMap<String, Quest>()
|
||||||
val specialists = LinkedHashMap<String, Specialist>()
|
val specialists = LinkedHashMap<String, Specialist>()
|
||||||
val technologies = LinkedHashMap<String, Technology>()
|
val technologies = LinkedHashMap<String, Technology>()
|
||||||
|
val techColumns = ArrayList<TechColumn>()
|
||||||
val terrains = LinkedHashMap<String, Terrain>()
|
val terrains = LinkedHashMap<String, Terrain>()
|
||||||
val tileImprovements = LinkedHashMap<String, TileImprovement>()
|
val tileImprovements = LinkedHashMap<String, TileImprovement>()
|
||||||
val tileResources = LinkedHashMap<String, TileResource>()
|
val tileResources = LinkedHashMap<String, TileResource>()
|
||||||
@ -152,6 +153,7 @@ class Ruleset {
|
|||||||
technologies.remove(it)
|
technologies.remove(it)
|
||||||
}
|
}
|
||||||
technologies.putAll(ruleset.technologies)
|
technologies.putAll(ruleset.technologies)
|
||||||
|
techColumns.addAll(ruleset.techColumns)
|
||||||
terrains.putAll(ruleset.terrains)
|
terrains.putAll(ruleset.terrains)
|
||||||
tileImprovements.putAll(ruleset.tileImprovements)
|
tileImprovements.putAll(ruleset.tileImprovements)
|
||||||
tileResources.putAll(ruleset.tileResources)
|
tileResources.putAll(ruleset.tileResources)
|
||||||
@ -212,6 +214,7 @@ class Ruleset {
|
|||||||
ruinRewards.clear()
|
ruinRewards.clear()
|
||||||
specialists.clear()
|
specialists.clear()
|
||||||
technologies.clear()
|
technologies.clear()
|
||||||
|
techColumns.clear()
|
||||||
terrains.clear()
|
terrains.clear()
|
||||||
tileImprovements.clear()
|
tileImprovements.clear()
|
||||||
tileResources.clear()
|
tileResources.clear()
|
||||||
@ -264,6 +267,7 @@ class Ruleset {
|
|||||||
if (techFile.exists()) {
|
if (techFile.exists()) {
|
||||||
val techColumns = json().fromJsonFile(Array<TechColumn>::class.java, techFile)
|
val techColumns = json().fromJsonFile(Array<TechColumn>::class.java, techFile)
|
||||||
for (techColumn in techColumns) {
|
for (techColumn in techColumns) {
|
||||||
|
this.techColumns.add(techColumn)
|
||||||
for (tech in techColumn.techs) {
|
for (tech in techColumn.techs) {
|
||||||
if (tech.cost == 0) tech.cost = techColumn.techCost
|
if (tech.cost == 0) tech.cost = techColumn.techCost
|
||||||
tech.column = techColumn
|
tech.column = techColumn
|
||||||
@ -458,11 +462,12 @@ class Ruleset {
|
|||||||
for (building in buildings.values) {
|
for (building in buildings.values) {
|
||||||
if (building.cost == -1 && building.getMatchingUniques(UniqueType.Unbuildable).none { it.conditionals.isEmpty() }) {
|
if (building.cost == -1 && building.getMatchingUniques(UniqueType.Unbuildable).none { it.conditionals.isEmpty() }) {
|
||||||
val column = technologies[building.requiredTech]?.column
|
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.")
|
if (column != null) {
|
||||||
building.cost = if (building.isAnyWonder()) column.wonderCost else column.buildingCost
|
building.cost = if (building.isAnyWonder()) column.wonderCost else column.buildingCost
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Used for displaying a RuleSet's name */
|
/** Used for displaying a RuleSet's name */
|
||||||
override fun toString() = when {
|
override fun toString() = when {
|
||||||
|
@ -51,17 +51,27 @@ class RulesetValidator(val ruleset: Ruleset) {
|
|||||||
|
|
||||||
for (tech in ruleset.technologies.values) {
|
for (tech in ruleset.technologies.values) {
|
||||||
for (otherTech in ruleset.technologies.values) {
|
for (otherTech in ruleset.technologies.values) {
|
||||||
if (tech != otherTech && otherTech.column == tech.column && otherTech.row == tech.row)
|
if (tech != otherTech && otherTech.column?.columnNumber == tech.column?.columnNumber && otherTech.row == tech.row)
|
||||||
lines += "${tech.name} is in the same row as ${otherTech.name}!"
|
lines += "${tech.name} is in the same row and column as ${otherTech.name}!"
|
||||||
}
|
}
|
||||||
|
|
||||||
checkUniques(tech, lines, rulesetInvariant, tryFixUnknownUniques)
|
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) {
|
for (building in ruleset.buildings.values) {
|
||||||
if (building.requiredTech == null && building.cost == -1 && !building.hasUnique(
|
if (building.requiredTech == null && building.cost == -1 && !building.hasUnique(
|
||||||
UniqueType.Unbuildable))
|
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)
|
checkUniques(building, lines, rulesetInvariant, tryFixUnknownUniques)
|
||||||
|
|
||||||
|
@ -5,6 +5,6 @@ class TechColumn {
|
|||||||
lateinit var era: String
|
lateinit var era: String
|
||||||
var techs = ArrayList<Technology>()
|
var techs = ArrayList<Technology>()
|
||||||
var techCost: Int = 0
|
var techCost: Int = 0
|
||||||
var buildingCost: Int = 0
|
var buildingCost: Int = -1
|
||||||
var wonderCost: Int = 0
|
var wonderCost: Int = -1
|
||||||
}
|
}
|
||||||
|
@ -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 */
|
in contrast to MapUnit, which is a specific unit of a certain type that appears on the map */
|
||||||
class BaseUnit : RulesetObject(), INonPerpetualConstruction {
|
class BaseUnit : RulesetObject(), INonPerpetualConstruction {
|
||||||
|
|
||||||
override var cost: Int = 0
|
override var cost: Int = -1
|
||||||
override var hurryCostModifier: Int = 0
|
override var hurryCostModifier: Int = 0
|
||||||
var movement: Int = 0
|
var movement: Int = 0
|
||||||
var strength: Int = 0
|
var strength: Int = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user