mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-03 13:30:51 +07:00
Fixed mod promotions conflicting with existing promotion locations
This commit is contained in:
parent
d748d489e2
commit
c475fb1d55
@ -122,11 +122,15 @@ class Ruleset {
|
||||
fun add(ruleset: Ruleset) {
|
||||
beliefs.putAll(ruleset.beliefs)
|
||||
buildings.putAll(ruleset.buildings)
|
||||
for (buildingToRemove in ruleset.modOptions.buildingsToRemove) buildings.remove(buildingToRemove)
|
||||
for (buildingToRemove in ruleset.modOptions.buildingsToRemove) buildings.remove(
|
||||
buildingToRemove
|
||||
)
|
||||
difficulties.putAll(ruleset.difficulties)
|
||||
eras.putAll(ruleset.eras)
|
||||
speeds.putAll(ruleset.speeds)
|
||||
globalUniques = GlobalUniques().apply { uniques.addAll(globalUniques.uniques); uniques.addAll(ruleset.globalUniques.uniques) }
|
||||
globalUniques = GlobalUniques().apply {
|
||||
uniques.addAll(globalUniques.uniques); uniques.addAll(ruleset.globalUniques.uniques)
|
||||
}
|
||||
nations.putAll(ruleset.nations)
|
||||
for (nationToRemove in ruleset.modOptions.nationsToRemove) nations.remove(nationToRemove)
|
||||
policyBranches.putAll(ruleset.policyBranches)
|
||||
@ -140,13 +144,33 @@ class Ruleset {
|
||||
terrains.putAll(ruleset.terrains)
|
||||
tileImprovements.putAll(ruleset.tileImprovements)
|
||||
tileResources.putAll(ruleset.tileResources)
|
||||
unitPromotions.putAll(ruleset.unitPromotions)
|
||||
units.putAll(ruleset.units)
|
||||
unitTypes.putAll(ruleset.unitTypes)
|
||||
victories.putAll(ruleset.victories)
|
||||
for (unitToRemove in ruleset.modOptions.unitsToRemove) units.remove(unitToRemove)
|
||||
modOptions.uniques.addAll(ruleset.modOptions.uniques)
|
||||
modOptions.constants.merge(ruleset.modOptions.constants)
|
||||
|
||||
// We should never be editing the original ruleset objects, only copies
|
||||
val addRulesetUnitPromotionClones = ruleset.unitPromotions.values.map { it.clone() }
|
||||
val existingPromotionLocations =
|
||||
unitPromotions.values.map { "${it.row}/${it.column}" }.toHashSet()
|
||||
val promotionsWithConflictingLocations = addRulesetUnitPromotionClones.filter {
|
||||
existingPromotionLocations.contains("${it.row}/${it.column}")
|
||||
}
|
||||
val columnsWithConflictingLocations =
|
||||
promotionsWithConflictingLocations.map { it.column }.distinct()
|
||||
|
||||
if (columnsWithConflictingLocations.isNotEmpty()) {
|
||||
var highestExistingColumn = unitPromotions.values.maxOf { it.column }
|
||||
for (column in columnsWithConflictingLocations) {
|
||||
highestExistingColumn += 1
|
||||
val newColumn = highestExistingColumn
|
||||
for (promotion in addRulesetUnitPromotionClones) promotion.column = newColumn
|
||||
}
|
||||
}
|
||||
unitPromotions.putAll(ruleset.unitPromotions)
|
||||
|
||||
mods += ruleset.mods
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,15 @@ class Promotion : RulesetObject() {
|
||||
var row = -1
|
||||
var column = 0
|
||||
|
||||
fun clone():Promotion {
|
||||
val newPromotion = Promotion()
|
||||
newPromotion.prerequisites = prerequisites
|
||||
newPromotion.unitTypes = unitTypes
|
||||
newPromotion.row = row
|
||||
newPromotion.column = column
|
||||
return newPromotion
|
||||
}
|
||||
|
||||
override fun getUniqueTarget() = UniqueTarget.Promotion
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user