diff --git a/OpenRA.Game/CPos.cs b/OpenRA.Game/CPos.cs index 94a610a52b..23dedcdae6 100644 --- a/OpenRA.Game/CPos.cs +++ b/OpenRA.Game/CPos.cs @@ -47,9 +47,9 @@ namespace OpenRA return ToMPos(map.Grid.Type); } - public MPos ToMPos(TileShape shape) + public MPos ToMPos(MapGridType gridType) { - if (shape == TileShape.Rectangle) + if (gridType == MapGridType.Rectangle) return new MPos(X, Y); // Convert from diamond cell (x, y) position to rectangular map position (u, v) diff --git a/OpenRA.Game/Graphics/Minimap.cs b/OpenRA.Game/Graphics/Minimap.cs index 9a881fe104..f446f2ac14 100644 --- a/OpenRA.Game/Graphics/Minimap.cs +++ b/OpenRA.Game/Graphics/Minimap.cs @@ -20,7 +20,7 @@ namespace OpenRA.Graphics { public static Bitmap TerrainBitmap(TileSet tileset, Map map, bool actualSize = false) { - var isDiamond = map.Grid.Type == TileShape.Diamond; + var isDiamond = map.Grid.Type == MapGridType.Diamond; var b = map.Bounds; // Fudge the heightmap offset by adding as much extra as we need / can. @@ -81,7 +81,7 @@ namespace OpenRA.Graphics static Bitmap AddStaticResources(TileSet tileset, Map map, Ruleset resourceRules, Bitmap terrainBitmap) { var terrain = new Bitmap(terrainBitmap); - var isDiamond = map.Grid.Type == TileShape.Diamond; + var isDiamond = map.Grid.Type == MapGridType.Diamond; var b = map.Bounds; // Fudge the heightmap offset by adding as much extra as we need / can diff --git a/OpenRA.Game/Graphics/Theater.cs b/OpenRA.Game/Graphics/Theater.cs index 8adbd2ff24..02c2edaf84 100644 --- a/OpenRA.Game/Graphics/Theater.cs +++ b/OpenRA.Game/Graphics/Theater.cs @@ -108,7 +108,7 @@ namespace OpenRA.Graphics return template.Sprites[start * template.Stride + r.Index]; } - public Rectangle TemplateBounds(TerrainTemplateInfo template, Size tileSize, TileShape tileShape) + public Rectangle TemplateBounds(TerrainTemplateInfo template, Size tileSize, MapGridType mapGrid) { Rectangle? templateRect = null; @@ -125,8 +125,8 @@ namespace OpenRA.Graphics continue; var sprite = TileSprite(tile); - var u = tileShape == TileShape.Rectangle ? x : (x - y) / 2f; - var v = tileShape == TileShape.Rectangle ? y : (x + y) / 2f; + var u = mapGrid == MapGridType.Rectangle ? x : (x - y) / 2f; + var v = mapGrid == MapGridType.Rectangle ? y : (x + y) / 2f; var tl = new float2(u * tileSize.Width, (v - 0.5f * tileInfo.Height) * tileSize.Height) - 0.5f * sprite.Size; var rect = new Rectangle((int)(tl.X + sprite.Offset.X), (int)(tl.Y + sprite.Offset.Y), (int)sprite.Size.X, (int)sprite.Size.Y); diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index df9332a557..08b4652506 100644 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -100,7 +100,7 @@ namespace OpenRA.Graphics // The full map is visible in the editor var width = map.MapSize.X * grid.TileSize.Width; var height = map.MapSize.Y * grid.TileSize.Height; - if (wr.World.Map.Grid.Type == TileShape.Diamond) + if (wr.World.Map.Grid.Type == MapGridType.Diamond) height /= 2; mapBounds = new Rectangle(0, 0, width, height); @@ -243,7 +243,7 @@ namespace OpenRA.Graphics // Diamond tile shapes don't have straight edges, and so we need // an additional cell margin to include the cells that are half // visible on each edge. - if (map.Grid.Type == TileShape.Diamond) + if (map.Grid.Type == MapGridType.Diamond) { tl = new PPos(tl.U - 1, tl.V - 1); br = new PPos(br.U + 1, br.V + 1); diff --git a/OpenRA.Game/MPos.cs b/OpenRA.Game/MPos.cs index ba97cba0dc..90968c3f60 100644 --- a/OpenRA.Game/MPos.cs +++ b/OpenRA.Game/MPos.cs @@ -41,9 +41,9 @@ namespace OpenRA return ToCPos(map.Grid.Type); } - public CPos ToCPos(TileShape shape) + public CPos ToCPos(MapGridType gridType) { - if (shape == TileShape.Rectangle) + if (gridType == MapGridType.Rectangle) return new CPos(U, V); // Convert from rectangular map position to diamond cell position diff --git a/OpenRA.Game/Map/CellLayer.cs b/OpenRA.Game/Map/CellLayer.cs index e497259208..4982a01f5b 100644 --- a/OpenRA.Game/Map/CellLayer.cs +++ b/OpenRA.Game/Map/CellLayer.cs @@ -20,7 +20,7 @@ namespace OpenRA { public readonly Size Size; readonly Rectangle bounds; - public readonly TileShape Shape; + public readonly MapGridType GridType; public event Action CellEntryChanged = null; readonly T[] entries; @@ -28,28 +28,28 @@ namespace OpenRA public CellLayer(Map map) : this(map.Grid.Type, new Size(map.MapSize.X, map.MapSize.Y)) { } - public CellLayer(TileShape shape, Size size) + public CellLayer(MapGridType gridType, Size size) { Size = size; bounds = new Rectangle(0, 0, Size.Width, Size.Height); - Shape = shape; + GridType = gridType; entries = new T[size.Width * size.Height]; } public void CopyValuesFrom(CellLayer anotherLayer) { - if (Size != anotherLayer.Size || Shape != anotherLayer.Shape) + if (Size != anotherLayer.Size || GridType != anotherLayer.GridType) throw new ArgumentException( - "layers must have a matching size and shape.", "anotherLayer"); + "layers must have a matching size and shape (grid type).", "anotherLayer"); if (CellEntryChanged != null) throw new InvalidOperationException( "Cannot copy values when there are listeners attached to the CellEntryChanged event."); Array.Copy(anotherLayer.entries, entries, entries.Length); } - public static CellLayer CreateInstance(Func initialCellValueFactory, Size size, TileShape tileShape) + public static CellLayer CreateInstance(Func initialCellValueFactory, Size size, MapGridType mapGridType) { - var cellLayer = new CellLayer(tileShape, size); + var cellLayer = new CellLayer(mapGridType, size); for (var v = 0; v < size.Height; v++) { for (var u = 0; u < size.Width; u++) @@ -65,7 +65,7 @@ namespace OpenRA // Resolve an array index from cell coordinates int Index(CPos cell) { - return Index(cell.ToMPos(Shape)); + return Index(cell.ToMPos(GridType)); } // Resolve an array index from map coordinates @@ -104,7 +104,7 @@ namespace OpenRA entries[Index(uv)] = value; if (CellEntryChanged != null) - CellEntryChanged(uv.ToCPos(Shape)); + CellEntryChanged(uv.ToCPos(GridType)); } } @@ -130,10 +130,10 @@ namespace OpenRA // .ToMPos() returns the same result if the X and Y coordinates // are switched. X < Y is invalid in the Diamond coordinate system, // so we pre-filter these to avoid returning the wrong result - if (Shape == TileShape.Diamond && cell.X < cell.Y) + if (GridType == MapGridType.Diamond && cell.X < cell.Y) return false; - return Contains(cell.ToMPos(Shape)); + return Contains(cell.ToMPos(GridType)); } public bool Contains(MPos uv) @@ -143,7 +143,7 @@ namespace OpenRA public CPos Clamp(CPos uv) { - return Clamp(uv.ToMPos(Shape)).ToCPos(Shape); + return Clamp(uv.ToMPos(GridType)).ToCPos(GridType); } public MPos Clamp(MPos uv) @@ -158,7 +158,7 @@ namespace OpenRA /// Create a new layer by resizing another layer. New cells are filled with defaultValue. public static CellLayer Resize(CellLayer layer, Size newSize, T defaultValue) { - var result = new CellLayer(layer.Shape, newSize); + var result = new CellLayer(layer.GridType, newSize); var width = Math.Min(layer.Size.Width, newSize.Width); var height = Math.Min(layer.Size.Height, newSize.Height); diff --git a/OpenRA.Game/Map/CellRegion.cs b/OpenRA.Game/Map/CellRegion.cs index fb41ed60a9..c0a5ffa2c2 100644 --- a/OpenRA.Game/Map/CellRegion.cs +++ b/OpenRA.Game/Map/CellRegion.cs @@ -22,33 +22,33 @@ namespace OpenRA // Corners of the region public readonly CPos TopLeft; public readonly CPos BottomRight; - readonly TileShape shape; + readonly MapGridType gridType; // Corners in map coordinates - // These will only equal TopLeft and BottomRight for TileShape.Rectangular + // These will only equal TopLeft and BottomRight for MapGridType.Rectangular readonly MPos mapTopLeft; readonly MPos mapBottomRight; - public CellRegion(TileShape shape, CPos topLeft, CPos bottomRight) + public CellRegion(MapGridType gridType, CPos topLeft, CPos bottomRight) { - this.shape = shape; + this.gridType = gridType; TopLeft = topLeft; BottomRight = bottomRight; - mapTopLeft = TopLeft.ToMPos(shape); - mapBottomRight = BottomRight.ToMPos(shape); + mapTopLeft = TopLeft.ToMPos(gridType); + mapBottomRight = BottomRight.ToMPos(gridType); } /// Expand the specified region with an additional cordon. This may expand the region outside the map borders. public static CellRegion Expand(CellRegion region, int cordon) { - var tl = new MPos(region.mapTopLeft.U - cordon, region.mapTopLeft.V - cordon).ToCPos(region.shape); - var br = new MPos(region.mapBottomRight.U + cordon, region.mapBottomRight.V + cordon).ToCPos(region.shape); - return new CellRegion(region.shape, tl, br); + var tl = new MPos(region.mapTopLeft.U - cordon, region.mapTopLeft.V - cordon).ToCPos(region.gridType); + var br = new MPos(region.mapBottomRight.U + cordon, region.mapBottomRight.V + cordon).ToCPos(region.gridType); + return new CellRegion(region.gridType, tl, br); } /// Returns the minimal region that covers at least the specified cells. - public static CellRegion BoundingRegion(TileShape shape, IEnumerable cells) + public static CellRegion BoundingRegion(MapGridType shape, IEnumerable cells) { if (cells == null || !cells.Any()) throw new ArgumentException("cells must not be null or empty.", "cells"); @@ -81,7 +81,7 @@ namespace OpenRA public bool Contains(CPos cell) { - var uv = cell.ToMPos(shape); + var uv = cell.ToMPos(gridType); return uv.U >= mapTopLeft.U && uv.U <= mapBottomRight.U && uv.V >= mapTopLeft.V && uv.V <= mapBottomRight.V; } @@ -136,7 +136,7 @@ namespace OpenRA return false; } - current = new MPos(u, v).ToCPos(r.shape); + current = new MPos(u, v).ToCPos(r.gridType); return true; } diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index ce918d7cc8..a7bebe43c1 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -9,10 +9,8 @@ #endregion using System; -using System.Collections; using System.Collections.Generic; using System.Drawing; -using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Security.Cryptography; @@ -428,10 +426,10 @@ namespace OpenRA foreach (var uv in AllCells.MapCoords) CustomTerrain[uv] = byte.MaxValue; - var leftDelta = Grid.Type == TileShape.Diamond ? new WVec(-512, 0, 0) : new WVec(-512, -512, 0); - var topDelta = Grid.Type == TileShape.Diamond ? new WVec(0, -512, 0) : new WVec(512, -512, 0); - var rightDelta = Grid.Type == TileShape.Diamond ? new WVec(512, 0, 0) : new WVec(512, 512, 0); - var bottomDelta = Grid.Type == TileShape.Diamond ? new WVec(0, 512, 0) : new WVec(-512, 512, 0); + var leftDelta = Grid.Type == MapGridType.Diamond ? new WVec(-512, 0, 0) : new WVec(-512, -512, 0); + var topDelta = Grid.Type == MapGridType.Diamond ? new WVec(0, -512, 0) : new WVec(512, -512, 0); + var rightDelta = Grid.Type == MapGridType.Diamond ? new WVec(512, 0, 0) : new WVec(512, 512, 0); + var bottomDelta = Grid.Type == MapGridType.Diamond ? new WVec(0, 512, 0) : new WVec(-512, 512, 0); CellCorners = CellCornerHalfHeights.Select(ramp => new WVec[] { leftDelta + new WVec(0, 0, 512 * ramp[0]), @@ -756,7 +754,7 @@ namespace OpenRA // .ToMPos() returns the same result if the X and Y coordinates // are switched. X < Y is invalid in the Diamond coordinate system, // so we pre-filter these to avoid returning the wrong result - if (Grid.Type == TileShape.Diamond && cell.X < cell.Y) + if (Grid.Type == MapGridType.Diamond && cell.X < cell.Y) return false; return Contains(cell.ToMPos(this)); @@ -788,7 +786,7 @@ namespace OpenRA public WPos CenterOfCell(CPos cell) { - if (Grid.Type == TileShape.Rectangle) + if (Grid.Type == MapGridType.Rectangle) return new WPos(1024 * cell.X + 512, 1024 * cell.Y + 512, 0); // Convert from diamond cell position (x, y) to world position (u, v): @@ -820,7 +818,7 @@ namespace OpenRA public CPos CellContaining(WPos pos) { - if (Grid.Type == TileShape.Rectangle) + if (Grid.Type == MapGridType.Rectangle) return new CPos(pos.X / 1024, pos.Y / 1024); // Convert from world position to diamond cell position: @@ -901,7 +899,7 @@ namespace OpenRA // for diamond cells. var wtop = tl.V * 1024; var wbottom = (br.V + 1) * 1024; - if (Grid.Type == TileShape.Diamond) + if (Grid.Type == MapGridType.Diamond) { wtop /= 2; wbottom /= 2; diff --git a/OpenRA.Game/Map/MapCache.cs b/OpenRA.Game/Map/MapCache.cs index 7c1f50a3ac..02b141e998 100644 --- a/OpenRA.Game/Map/MapCache.cs +++ b/OpenRA.Game/Map/MapCache.cs @@ -23,7 +23,7 @@ namespace OpenRA { public sealed class MapCache : IEnumerable, IDisposable { - public static readonly MapPreview UnknownMap = new MapPreview(null, TileShape.Rectangle, null); + public static readonly MapPreview UnknownMap = new MapPreview(null, MapGridType.Rectangle, null); readonly Cache previews; readonly ModData modData; readonly SheetBuilder sheetBuilder; diff --git a/OpenRA.Game/Map/MapGrid.cs b/OpenRA.Game/Map/MapGrid.cs index fcad1641a9..09be0ac32b 100644 --- a/OpenRA.Game/Map/MapGrid.cs +++ b/OpenRA.Game/Map/MapGrid.cs @@ -13,11 +13,11 @@ using System.IO; namespace OpenRA { - public enum TileShape { Rectangle, Diamond } + public enum MapGridType { Rectangle, Diamond } public class MapGrid : IGlobalModData { - public readonly TileShape Type = TileShape.Rectangle; + public readonly MapGridType Type = MapGridType.Rectangle; public readonly Size TileSize = new Size(24, 24); public readonly byte MaximumTerrainHeight = 0; public readonly byte SubCellDefaultIndex = byte.MaxValue; diff --git a/OpenRA.Game/Map/MapPreview.cs b/OpenRA.Game/Map/MapPreview.cs index 27a9d61e38..f5fc318bc1 100644 --- a/OpenRA.Game/Map/MapPreview.cs +++ b/OpenRA.Game/Map/MapPreview.cs @@ -47,7 +47,7 @@ namespace OpenRA public readonly int players; public readonly Rectangle bounds; public readonly int[] spawnpoints = { }; - public readonly TileShape map_grid_type; + public readonly MapGridType map_grid_type; public readonly string minimap; public readonly bool downloading; } @@ -63,7 +63,7 @@ namespace OpenRA public string Author { get; private set; } public int PlayerCount { get; private set; } public CPos[] SpawnPoints { get; private set; } - public TileShape GridType { get; private set; } + public MapGridType GridType { get; private set; } public Rectangle Bounds { get; private set; } public Bitmap CustomPreview { get; private set; } public Map Map { get; private set; } @@ -99,7 +99,7 @@ namespace OpenRA generatingMinimap = false; } - public MapPreview(string uid, TileShape gridType, MapCache cache) + public MapPreview(string uid, MapGridType gridType, MapCache cache) { this.cache = cache; Uid = uid; diff --git a/OpenRA.Game/Map/ProjectedCellRegion.cs b/OpenRA.Game/Map/ProjectedCellRegion.cs index d8a21cc467..c40ba94c98 100644 --- a/OpenRA.Game/Map/ProjectedCellRegion.cs +++ b/OpenRA.Game/Map/ProjectedCellRegion.cs @@ -8,10 +8,8 @@ */ #endregion -using System; using System.Collections; using System.Collections.Generic; -using System.Linq; namespace OpenRA { @@ -43,7 +41,7 @@ namespace OpenRA // Each height step is equivalent to 512 WRange units, which is one MPos // step for diamond cells, but only half a MPos step for classic cells. Doh! var maxHeight = map.Grid.MaximumTerrainHeight; - var heightOffset = map.Grid.Type == TileShape.Diamond ? maxHeight : maxHeight / 2; + var heightOffset = map.Grid.Type == MapGridType.Diamond ? maxHeight : maxHeight / 2; // Use the MapHeight data array to clamp the bottom coordinate so it doesn't overflow the map mapBottomRight = map.MapHeight.Value.Clamp(new MPos(bottomRight.U, bottomRight.V + heightOffset)); diff --git a/OpenRA.Mods.Common/Pathfinder/CellInfoLayerPool.cs b/OpenRA.Mods.Common/Pathfinder/CellInfoLayerPool.cs index 305769b8e5..88b862e144 100644 --- a/OpenRA.Mods.Common/Pathfinder/CellInfoLayerPool.cs +++ b/OpenRA.Mods.Common/Pathfinder/CellInfoLayerPool.cs @@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Pathfinder layer = pool.Pop(); if (layer == null) - layer = new CellLayer(defaultLayer.Shape, defaultLayer.Size); + layer = new CellLayer(defaultLayer.GridType, defaultLayer.Size); layer.CopyValuesFrom(defaultLayer); return layer; } diff --git a/OpenRA.Mods.Common/Widgets/MapPreviewWidget.cs b/OpenRA.Mods.Common/Widgets/MapPreviewWidget.cs index 7452566cdb..fe77fe1422 100644 --- a/OpenRA.Mods.Common/Widgets/MapPreviewWidget.cs +++ b/OpenRA.Mods.Common/Widgets/MapPreviewWidget.cs @@ -130,11 +130,11 @@ namespace OpenRA.Mods.Common.Widgets tooltipContainer.Value.RemoveTooltip(); } - public int2 ConvertToPreview(CPos cell, TileShape gridType) + public int2 ConvertToPreview(CPos cell, MapGridType gridType) { var preview = Preview(); var point = cell.ToMPos(gridType); - var cellWidth = gridType == TileShape.Diamond ? 2 : 1; + var cellWidth = gridType == MapGridType.Diamond ? 2 : 1; var dx = (int)(previewScale * cellWidth * (point.U - preview.Bounds.Left)); var dy = (int)(previewScale * (point.V - preview.Bounds.Top)); diff --git a/OpenRA.Mods.Common/Widgets/RadarWidget.cs b/OpenRA.Mods.Common/Widgets/RadarWidget.cs index b58dc7a92b..9d4c19aaf6 100644 --- a/OpenRA.Mods.Common/Widgets/RadarWidget.cs +++ b/OpenRA.Mods.Common/Widgets/RadarWidget.cs @@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Widgets this.worldRenderer = worldRenderer; radarPings = world.WorldActor.TraitOrDefault(); - isDiamond = world.Map.Grid.Type == TileShape.Diamond; + isDiamond = world.Map.Grid.Type == MapGridType.Diamond; cellWidth = isDiamond ? 2 : 1; previewWidth = world.Map.MapSize.X; previewHeight = world.Map.MapSize.Y; diff --git a/OpenRA.Mods.Common/Widgets/TerrainTemplatePreviewWidget.cs b/OpenRA.Mods.Common/Widgets/TerrainTemplatePreviewWidget.cs index bc91d7e7e4..b9752c022e 100644 --- a/OpenRA.Mods.Common/Widgets/TerrainTemplatePreviewWidget.cs +++ b/OpenRA.Mods.Common/Widgets/TerrainTemplatePreviewWidget.cs @@ -10,8 +10,6 @@ using System; using System.Drawing; -using System.Linq; -using OpenRA.FileFormats; using OpenRA.Graphics; using OpenRA.Widgets; @@ -42,9 +40,7 @@ namespace OpenRA.Mods.Common.Widgets return; var grid = Game.ModData.Manifest.Get(); - var ts = grid.TileSize; - var shape = grid.Type; - bounds = worldRenderer.Theater.TemplateBounds(template, ts, shape); + bounds = worldRenderer.Theater.TemplateBounds(template, grid.TileSize, grid.Type); } } @@ -73,7 +69,7 @@ namespace OpenRA.Mods.Common.Widgets var grid = Game.ModData.Manifest.Get(); var ts = grid.TileSize; - var shape = grid.Type; + var gridType = grid.Type; var scale = GetScale(); var sb = new Rectangle((int)(scale * bounds.X), (int)(scale * bounds.Y), (int)(scale * bounds.Width), (int)(scale * bounds.Height)); @@ -94,8 +90,8 @@ namespace OpenRA.Mods.Common.Widgets var sprite = worldRenderer.Theater.TileSprite(tile, 0); var size = new float2(sprite.Size.X * scale, sprite.Size.Y * scale); - var u = shape == TileShape.Rectangle ? x : (x - y) / 2f; - var v = shape == TileShape.Rectangle ? y : (x + y) / 2f; + var u = gridType == MapGridType.Rectangle ? x : (x - y) / 2f; + var v = gridType == MapGridType.Rectangle ? y : (x + y) / 2f; var pos = origin + scale * (new float2(u * ts.Width, (v - 0.5f * tileInfo.Height) * ts.Height) - 0.5f * sprite.Size); Game.Renderer.SpriteRenderer.DrawSprite(sprite, pos, worldRenderer.Palette(Palette), size); } diff --git a/OpenRA.Test/OpenRA.Game/CoordinateTest.cs b/OpenRA.Test/OpenRA.Game/CoordinateTest.cs index 1e1431e750..11bfc2eb02 100644 --- a/OpenRA.Test/OpenRA.Game/CoordinateTest.cs +++ b/OpenRA.Test/OpenRA.Game/CoordinateTest.cs @@ -20,7 +20,7 @@ namespace OpenRA.Test [TestCase(TestName = "Test CPos and MPos conversion and back again.")] public void CoarseToMapProjection() { - foreach (var shape in Enum.GetValues(typeof(TileShape)).Cast()) + foreach (var gridType in Enum.GetValues(typeof(MapGridType)).Cast()) { for (var x = 0; x < 12; x++) { @@ -29,15 +29,15 @@ namespace OpenRA.Test var cell = new CPos(x, y); try { - Assert.That(cell, Is.EqualTo(cell.ToMPos(shape).ToCPos(shape))); + Assert.That(cell, Is.EqualTo(cell.ToMPos(gridType).ToCPos(gridType))); } catch (Exception e) { // Known problem on isometric mods that shouldn't be visible to players as these are outside the map. - if (shape == TileShape.Diamond && y > x) + if (gridType == MapGridType.Diamond && y > x) continue; - Console.WriteLine("Coordinate {0} on shape {1} failed to convert back.".F(cell, shape)); + Console.WriteLine("Coordinate {0} on grid type {1} failed to convert back.".F(cell, gridType)); throw e; } }