From 284e6ea061086fbab9f67185c7b903b313d60843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Thu, 31 Dec 2015 10:20:03 +0100 Subject: [PATCH 1/3] Add a resize map command. --- OpenRA.Game/Map/Map.cs | 2 +- OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 1 + .../UtilityCommands/ResizeMapCommand.cs | 52 +++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 OpenRA.Mods.Common/UtilityCommands/ResizeMapCommand.cs diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 868fd757ae..55c7379290 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -838,7 +838,7 @@ namespace OpenRA return delta.Yaw.Facing; } - public void Resize(int width, int height) // editor magic. + public void Resize(int width, int height) { var oldMapTiles = MapTiles.Value; var oldMapResources = MapResources.Value; diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 28d3202018..3c0306b728 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -731,6 +731,7 @@ + diff --git a/OpenRA.Mods.Common/UtilityCommands/ResizeMapCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ResizeMapCommand.cs new file mode 100644 index 0000000000..2a5f088211 --- /dev/null +++ b/OpenRA.Mods.Common/UtilityCommands/ResizeMapCommand.cs @@ -0,0 +1,52 @@ +#region Copyright & License Information +/* + * Copyright 2007-2015 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; + +namespace OpenRA.Mods.Common.UtilityCommands +{ + public class ResizeMapCommand : IUtilityCommand + { + public string Name { get { return "--resize-map"; } } + + int width; + int height; + + public bool ValidateArguments(string[] args) + { + if (args.Length < 4) + return false; + + if (!int.TryParse(args[2], out width) && width > 0) + { + Console.WriteLine("Invalid WIDTH"); + return false; + } + + if (!int.TryParse(args[3], out height) && height > 0) + { + Console.WriteLine("Invalid HEIGHT"); + return false; + } + + return true; + } + + [Desc("MAPFILE", "WIDTH", "HEIGHT", "Resize the map at the bottom corners.")] + public void Run(ModData modData, string[] args) + { + Game.ModData = modData; + var map = new Map(args[1]); + Console.WriteLine("Resizing map {0} from {1} to {2},{3}", map.Title, map.MapSize, width, height); + map.Resize(width, height); + map.Save(map.Path); + } + } +} From 8b9e60ba8286c7f77335e60e71bef56493e7520d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 13 Feb 2016 21:55:09 +0100 Subject: [PATCH 2/3] Set the bounds when resizing maps. --- OpenRA.Game/Map/Map.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 55c7379290..176208499a 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -850,9 +850,10 @@ namespace OpenRA MapHeight = Exts.Lazy(() => CellLayer.Resize(oldMapHeight, newSize, oldMapHeight[MPos.Zero])); MapSize = new int2(newSize); - var tl = new MPos(0, 0).ToCPos(this); - var br = new MPos(MapSize.X - 1, MapSize.Y - 1).ToCPos(this); - AllCells = new CellRegion(Grid.Type, tl, br); + var tl = new MPos(0, 0); + var br = new MPos(MapSize.X - 1, MapSize.Y - 1); + AllCells = new CellRegion(Grid.Type, tl.ToCPos(this), br.ToCPos(this)); + SetBounds(new PPos(tl.U + 1, tl.V + 1), new PPos(br.U - 1, br.V - 1)); } public void SetBounds(PPos tl, PPos br) From 3a8d28e508cc249e9fe6aed1d32df31420a35adb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 13 Feb 2016 21:56:24 +0100 Subject: [PATCH 3/3] Check for out of bounds map actors and remove them if so. --- .../UtilityCommands/ResizeMapCommand.cs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/UtilityCommands/ResizeMapCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ResizeMapCommand.cs index 2a5f088211..96ffa3c2ef 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ResizeMapCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ResizeMapCommand.cs @@ -9,6 +9,8 @@ #endregion using System; +using System.Collections.Generic; +using System.Linq; namespace OpenRA.Mods.Common.UtilityCommands { @@ -19,6 +21,8 @@ namespace OpenRA.Mods.Common.UtilityCommands int width; int height; + Map map; + public bool ValidateArguments(string[] args) { if (args.Length < 4) @@ -43,9 +47,26 @@ namespace OpenRA.Mods.Common.UtilityCommands public void Run(ModData modData, string[] args) { Game.ModData = modData; - var map = new Map(args[1]); + map = new Map(args[1]); Console.WriteLine("Resizing map {0} from {1} to {2},{3}", map.Title, map.MapSize, width, height); map.Resize(width, height); + + var forRemoval = new List(); + + foreach (var kv in map.ActorDefinitions) + { + var actor = new ActorReference(kv.Value.Value, kv.Value.ToDictionary()); + var location = actor.InitDict.Get().Value(null); + if (!map.Contains(location)) + { + Console.WriteLine("Removing actor {0} located at {1} due being outside of the new map boundaries.".F(actor.Type, location)); + forRemoval.Add(kv); + } + } + + foreach (var kv in forRemoval) + map.ActorDefinitions.Remove(kv); + map.Save(map.Path); } }