Merge pull request #11373 from reaperrr/fix-footprints

Fixed footprints of several RA and TD base structures
This commit is contained in:
Oliver Brakmann
2016-06-22 20:51:36 +02:00
committed by GitHub
51 changed files with 338 additions and 267 deletions

View File

@@ -365,7 +365,12 @@ namespace OpenRA.Mods.Common.UtilityCommands
mapPlayers.Players[section] = pr;
}
public static void LoadActors(IniFile file, string section, List<string> players, int mapSize, Map map)
public virtual CPos ParseActorLocation(string input, int loc)
{
return new CPos(loc % MapSize, loc / MapSize);
}
public void LoadActors(IniFile file, string section, List<string> players, int mapSize, Map map)
{
foreach (var s in file.GetSection(section, true))
{
@@ -385,8 +390,10 @@ namespace OpenRA.Mods.Common.UtilityCommands
var health = Exts.ParseIntegerInvariant(parts[2]) * 100 / 256;
var facing = (section == "INFANTRY") ? Exts.ParseIntegerInvariant(parts[6]) : Exts.ParseIntegerInvariant(parts[4]);
var actor = new ActorReference(parts[1].ToLowerInvariant()) {
new LocationInit(new CPos(loc % mapSize, loc / mapSize)),
var actorType = parts[1].ToLowerInvariant();
var actor = new ActorReference(actorType) {
new LocationInit(ParseActorLocation(actorType, loc)),
new OwnerInit(parts[0]),
};
@@ -424,9 +431,11 @@ namespace OpenRA.Mods.Common.UtilityCommands
foreach (var kv in terrain)
{
var loc = Exts.ParseIntegerInvariant(kv.Key);
var ar = new ActorReference(ParseTreeActor(kv.Value))
var treeActor = ParseTreeActor(kv.Value);
var ar = new ActorReference(treeActor)
{
new LocationInit(new CPos(loc % MapSize, loc / MapSize)),
new LocationInit(ParseActorLocation(treeActor, loc)),
new OwnerInit("Neutral")
};

View File

@@ -25,9 +25,9 @@ namespace OpenRA.Mods.Common.UtilityCommands
return args.Length >= 3;
}
delegate void UpgradeAction(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth);
delegate void UpgradeAction(ModData modData, int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth);
static void ProcessYaml(Map map, MiniYaml yaml, int engineDate, UpgradeAction processYaml)
static void ProcessYaml(ModData modData, Map map, MiniYaml yaml, int engineDate, UpgradeAction processYaml)
{
if (yaml == null)
return;
@@ -38,12 +38,12 @@ namespace OpenRA.Mods.Common.UtilityCommands
foreach (var filename in files)
{
var fileNodes = MiniYaml.FromStream(map.Package.GetStream(filename), filename);
processYaml(engineDate, ref fileNodes, null, 0);
processYaml(modData, engineDate, ref fileNodes, null, 0);
((IReadWritePackage)map.Package).Update(filename, Encoding.ASCII.GetBytes(fileNodes.WriteToString()));
}
}
processYaml(engineDate, ref yaml.Nodes, null, 1);
processYaml(modData, engineDate, ref yaml.Nodes, null, 1);
}
public static void UpgradeMap(ModData modData, IReadWritePackage package, int engineDate)
@@ -58,10 +58,10 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
var map = new Map(modData, package);
ProcessYaml(map, map.WeaponDefinitions, engineDate, UpgradeRules.UpgradeWeaponRules);
ProcessYaml(map, map.RuleDefinitions, engineDate, UpgradeRules.UpgradeActorRules);
UpgradeRules.UpgradePlayers(engineDate, ref map.PlayerDefinitions, null, 0);
UpgradeRules.UpgradeActors(engineDate, ref map.ActorDefinitions, null, 0);
ProcessYaml(modData, map, map.WeaponDefinitions, engineDate, UpgradeRules.UpgradeWeaponRules);
ProcessYaml(modData, map, map.RuleDefinitions, engineDate, UpgradeRules.UpgradeActorRules);
UpgradeRules.UpgradePlayers(modData, engineDate, ref map.PlayerDefinitions, null, 0);
UpgradeRules.UpgradeActors(modData, engineDate, ref map.ActorDefinitions, null, 0);
map.Save(package);
}

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
return args.Length >= 2;
}
delegate void UpgradeAction(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth);
delegate void UpgradeAction(ModData modData, int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth);
void ProcessYaml(string type, IEnumerable<string> files, ModData modData, int engineDate, UpgradeAction processFile)
{
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
var yaml = MiniYaml.FromStream(package.GetStream(name), name);
processFile(engineDate, ref yaml, null, 0);
processFile(modData, engineDate, ref yaml, null, 0);
// Generate the on-disk path
var path = Path.Combine(package.Name, name);

View File

@@ -92,7 +92,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
catch { }
}
internal static void UpgradeActorRules(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
internal static void UpgradeActorRules(ModData modData, int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
{
var addNodes = new List<MiniYamlNode>();
@@ -185,14 +185,14 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
}
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
}
foreach (var a in addNodes)
nodes.Add(a);
}
internal static void UpgradeWeaponRules(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
internal static void UpgradeWeaponRules(ModData modData, int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
{
foreach (var node in nodes)
{
@@ -240,61 +240,83 @@ namespace OpenRA.Mods.Common.UtilityCommands
node.Key = "Speed";
}
UpgradeWeaponRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
UpgradeWeaponRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
}
}
internal static void UpgradeTileset(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
internal static void UpgradeTileset(ModData modData, int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
{
foreach (var node in nodes)
{
// Add rules here
UpgradeTileset(engineVersion, ref node.Value.Nodes, node, depth + 1);
UpgradeTileset(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
}
}
internal static void UpgradeCursors(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
internal static void UpgradeCursors(ModData modData, int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
{
foreach (var node in nodes)
{
// Add rules here
UpgradeCursors(engineVersion, ref node.Value.Nodes, node, depth + 1);
UpgradeCursors(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
}
}
internal static void UpgradePlayers(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
internal static void UpgradePlayers(ModData modData, int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
{
foreach (var node in nodes)
{
// Add rules here
UpgradePlayers(engineVersion, ref node.Value.Nodes, node, depth + 1);
UpgradePlayers(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
}
}
internal static void UpgradeChromeMetrics(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
internal static void UpgradeChromeMetrics(ModData modData, int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
{
foreach (var node in nodes)
{
// Add rules here
UpgradeChromeMetrics(engineVersion, ref node.Value.Nodes, node, depth + 1);
UpgradeChromeMetrics(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
}
}
internal static void UpgradeChromeLayout(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
internal static void UpgradeChromeLayout(ModData modData, int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
{
foreach (var node in nodes)
{
// Add rules here
UpgradeChromeLayout(engineVersion, ref node.Value.Nodes, node, depth + 1);
UpgradeChromeLayout(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
}
}
internal static void UpgradeActors(int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
internal static void ModifyCPos(ref string input, CVec vector)
{
var oldCPos = FieldLoader.GetValue<CPos>("(value)", input);
var newCPos = oldCPos + vector;
input = newCPos.ToString();
}
internal static void UpgradeActors(ModData modData, int engineVersion, ref List<MiniYamlNode> nodes, MiniYamlNode parent, int depth)
{
foreach (var node in nodes)
{
// Add rules here
UpgradeActors(engineVersion, ref node.Value.Nodes, node, depth + 1);
// Fix RA building footprints to not use _ when it's not necessary
if (engineVersion < 20160619 && modData.Manifest.Mod.Id == "ra" && depth == 1)
{
var buildings = new List<string>() { "tsla", "gap", "agun", "apwr", "fapw" };
if (buildings.Contains(parent.Value.Value) && node.Key == "Location")
ModifyCPos(ref node.Value.Value, new CVec(0, 1));
}
// Fix TD building footprints to not use _ when it's not necessary
if (engineVersion < 20160619 && modData.Manifest.Mod.Id == "cnc" && depth == 1)
{
var buildings = new List<string>() { "atwr", "obli", "tmpl", "weap", "hand" };
if (buildings.Contains(parent.Value.Value) && node.Key == "Location")
ModifyCPos(ref node.Value.Value, new CVec(0, 1));
}
UpgradeActors(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
}
}