From 57ff4822fcbe8eb1e55976b0ae58955c2ab1b016 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Mon, 30 May 2016 22:55:20 +0200 Subject: [PATCH] Add support for custom locations to legacy map importer For example, to place actors with changed footprint correctly. Use it to ensure correct positioning of several RA and TD structures as well as TD tiberium trees. --- .../ImportTiberianDawnLegacyMapCommand.cs | 11 +++++++++++ .../UtilityCommands/ImportLegacyMapCommand.cs | 19 ++++++++++++++----- .../ImportRedAlertLegacyMapCommand.cs | 11 +++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.Cnc/ImportTiberianDawnLegacyMapCommand.cs b/OpenRA.Mods.Cnc/ImportTiberianDawnLegacyMapCommand.cs index f7280b7aed..dd9e04576e 100644 --- a/OpenRA.Mods.Cnc/ImportTiberianDawnLegacyMapCommand.cs +++ b/OpenRA.Mods.Cnc/ImportTiberianDawnLegacyMapCommand.cs @@ -116,6 +116,17 @@ namespace OpenRA.Mods.Cnc.UtilityCommands return input.Split(',')[0].ToLowerInvariant(); } + public override CPos ParseActorLocation(string input, int loc) + { + var newLoc = new CPos(loc % MapSize, loc / MapSize); + var vectorDown = new CVec(0, 1); + + if (input == "obli" || input == "atwr" || input == "weap" || input == "hand" || input == "tmpl" || input == "split2" || input == "split3") + newLoc += vectorDown; + + return newLoc; + } + public override void LoadPlayer(IniFile file, string section) { string color; diff --git a/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs index 0d0b54e610..241c8bf152 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs @@ -365,7 +365,12 @@ namespace OpenRA.Mods.Common.UtilityCommands mapPlayers.Players[section] = pr; } - public static void LoadActors(IniFile file, string section, List 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 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") }; diff --git a/OpenRA.Mods.RA/ImportRedAlertLegacyMapCommand.cs b/OpenRA.Mods.RA/ImportRedAlertLegacyMapCommand.cs index cd4db44f71..b37e785996 100644 --- a/OpenRA.Mods.RA/ImportRedAlertLegacyMapCommand.cs +++ b/OpenRA.Mods.RA/ImportRedAlertLegacyMapCommand.cs @@ -126,6 +126,17 @@ namespace OpenRA.Mods.RA.UtilityCommands return input.ToLowerInvariant(); } + public override CPos ParseActorLocation(string input, int loc) + { + var newLoc = new CPos(loc % MapSize, loc / MapSize); + var vectorDown = new CVec(0, 1); + + if (input == "tsla" || input == "agun" || input == "gap" || input == "apwr" || input == "iron") + newLoc += vectorDown; + + return newLoc; + } + public override void LoadPlayer(IniFile file, string section) { string color;