Try to avoid adding duplicate values through upgrade rules

This commit is contained in:
abcdefg30
2015-11-28 14:53:32 +01:00
parent 1695627ffc
commit 5c6c44ba7b

View File

@@ -1908,25 +1908,30 @@ namespace OpenRA.Mods.Common.UtilityCommands
// This will only do roughly the right thing and probably require the modder to do some manual cleanup // This will only do roughly the right thing and probably require the modder to do some manual cleanup
if (depth == 0) if (depth == 0)
{ {
var inftraits = node.Value.Nodes.FirstOrDefault(n => // Check if the upgrade rule ran already before
n.Key.StartsWith("WithInfantryBody") var qffs = node.Value.Nodes.FirstOrDefault(n => n.Key == "QuantizeFacingsFromSequence");
|| n.Key.StartsWith("WithDisguisingInfantryBody")); if (qffs == null)
if (inftraits != null)
{ {
node.Value.Nodes.Add(new MiniYamlNode("QuantizeFacingsFromSequence", null, new List<MiniYamlNode> var inftraits = node.Value.Nodes.FirstOrDefault(n =>
n.Key.StartsWith("WithInfantryBody")
|| n.Key.StartsWith("WithDisguisingInfantryBody"));
if (inftraits != null)
{ {
new MiniYamlNode("Sequence", "stand"), node.Value.Nodes.Add(new MiniYamlNode("QuantizeFacingsFromSequence", null, new List<MiniYamlNode>
})); {
} new MiniYamlNode("Sequence", "stand"),
}));
}
var other = node.Value.Nodes.FirstOrDefault(x => var other = node.Value.Nodes.FirstOrDefault(x =>
x.Key.StartsWith("RenderBuilding") x.Key.StartsWith("RenderBuilding")
|| x.Key.StartsWith("RenderSimple") || x.Key.StartsWith("RenderSimple")
|| x.Key.StartsWith("WithCrateBody") || x.Key.StartsWith("WithCrateBody")
|| x.Key.StartsWith("WithSpriteBody") || x.Key.StartsWith("WithSpriteBody")
|| x.Key.StartsWith("WithFacingSpriteBody")); || x.Key.StartsWith("WithFacingSpriteBody"));
if (other != null) if (other != null)
node.Value.Nodes.Add(new MiniYamlNode("QuantizeFacingsFromSequence", "")); node.Value.Nodes.Add(new MiniYamlNode("QuantizeFacingsFromSequence", ""));
}
} }
} }
@@ -2123,7 +2128,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
// Add `WhileCloakedUpgrades: underwater` to Cloak trait if `CloakTypes: Underwater` // Add `WhileCloakedUpgrades: underwater` to Cloak trait if `CloakTypes: Underwater`
var cloak = node.Value.Nodes.FirstOrDefault(n => (n.Key == "Cloak" || n.Key.StartsWith("Cloak@")) var cloak = node.Value.Nodes.FirstOrDefault(n => (n.Key == "Cloak" || n.Key.StartsWith("Cloak@"))
&& n.Value.Nodes.Any(p => p.Key == "CloakTypes" && p.Value.Value == "Underwater")); && n.Value.Nodes.Any(p => p.Key == "CloakTypes" && p.Value.Value == "Underwater"));
if (cloak != null) if (cloak != null && !cloak.Value.Nodes.Any(n => n.Key == "WhileCloakedUpgrades"))
cloak.Value.Nodes.Add(new MiniYamlNode("WhileCloakedUpgrades", "underwater")); cloak.Value.Nodes.Add(new MiniYamlNode("WhileCloakedUpgrades", "underwater"));
// Remove split traits if TargetableSubmarine was removed // Remove split traits if TargetableSubmarine was removed
@@ -2213,12 +2218,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
// Make Range WDist for all traits with circular ranges. // Make Range WDist for all traits with circular ranges.
if (engineVersion < 20150920 && depth == 2 && node.Key == "Range") if (engineVersion < 20150920 && depth == 2 && node.Key == "Range")
{ {
if (parentKey == "DetectCloaked" if ((parentKey == "DetectCloaked"
|| parentKey == "JamsMissiles" || parentKey == "JamsMissiles"
|| parentKey == "JamsRadar" || parentKey == "JamsRadar"
|| parentKey == "Guardable" || parentKey == "Guardable"
|| parentKey == "BaseProvider" || parentKey == "BaseProvider"
|| parentKey == "ProximityCapturable") || parentKey == "ProximityCapturable")
&& !node.Value.Value.Contains("c0"))
node.Value.Value = node.Value.Value + "c0"; node.Value.Value = node.Value.Value + "c0";
} }
@@ -2401,7 +2407,8 @@ namespace OpenRA.Mods.Common.UtilityCommands
if (depth == 1 && node.Key == "AutoTarget") if (depth == 1 && node.Key == "AutoTarget")
{ {
var stance = node.Value.Nodes.FirstOrDefault(n => n.Key == "InitialStance"); var stance = node.Value.Nodes.FirstOrDefault(n => n.Key == "InitialStance");
if (stance != null) var aiStance = node.Value.Nodes.FirstOrDefault(n => n.Key == "InitialStanceAI");
if (stance != null && aiStance == null)
node.Value.Nodes.Add(new MiniYamlNode("InitialStanceAI", stance.Value.Value)); node.Value.Nodes.Add(new MiniYamlNode("InitialStanceAI", stance.Value.Value));
} }
} }