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

@@ -1907,6 +1907,10 @@ namespace OpenRA.Mods.Common.UtilityCommands
// Introduce QuantizeFacingsFromSequence // Introduce QuantizeFacingsFromSequence
// 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)
{
// Check if the upgrade rule ran already before
var qffs = node.Value.Nodes.FirstOrDefault(n => n.Key == "QuantizeFacingsFromSequence");
if (qffs == null)
{ {
var inftraits = node.Value.Nodes.FirstOrDefault(n => var inftraits = node.Value.Nodes.FirstOrDefault(n =>
n.Key.StartsWith("WithInfantryBody") n.Key.StartsWith("WithInfantryBody")
@@ -1929,6 +1933,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
node.Value.Nodes.Add(new MiniYamlNode("QuantizeFacingsFromSequence", "")); node.Value.Nodes.Add(new MiniYamlNode("QuantizeFacingsFromSequence", ""));
} }
} }
}
if (engineVersion < 20150920) if (engineVersion < 20150920)
{ {
@@ -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));
} }
} }