Reference SubCells directly from MapGrid.
This commit is contained in:
@@ -74,10 +74,6 @@ namespace OpenRA
|
||||
public readonly MapGrid Grid;
|
||||
readonly ModData modData;
|
||||
|
||||
[FieldLoader.Ignore] public readonly WVec[] SubCellOffsets;
|
||||
public readonly SubCell DefaultSubCell;
|
||||
public readonly SubCell LastSubCell;
|
||||
|
||||
public IReadOnlyPackage Package { get; private set; }
|
||||
|
||||
// Yaml map data
|
||||
@@ -93,14 +89,6 @@ namespace OpenRA
|
||||
public bool LockPreview;
|
||||
public bool InvalidCustomRules { get; private set; }
|
||||
|
||||
public WVec OffsetOfSubCell(SubCell subCell)
|
||||
{
|
||||
if (subCell == SubCell.Invalid || subCell == SubCell.Any)
|
||||
return WVec.Zero;
|
||||
|
||||
return SubCellOffsets[(int)subCell];
|
||||
}
|
||||
|
||||
public static string ComputeUID(IReadOnlyPackage package)
|
||||
{
|
||||
// UID is calculated by taking an SHA1 of the yaml and binary data
|
||||
@@ -274,10 +262,6 @@ namespace OpenRA
|
||||
|
||||
Grid = modData.Manifest.Get<MapGrid>();
|
||||
|
||||
SubCellOffsets = Grid.SubCellOffsets;
|
||||
LastSubCell = (SubCell)(SubCellOffsets.Length - 1);
|
||||
DefaultSubCell = (SubCell)Grid.SubCellDefaultIndex;
|
||||
|
||||
PostInit();
|
||||
|
||||
Uid = ComputeUID(Package);
|
||||
@@ -760,8 +744,8 @@ namespace OpenRA
|
||||
public WPos CenterOfSubCell(CPos cell, SubCell subCell)
|
||||
{
|
||||
var index = (int)subCell;
|
||||
if (index >= 0 && index <= SubCellOffsets.Length)
|
||||
return CenterOfCell(cell) + SubCellOffsets[index];
|
||||
if (index >= 0 && index <= Grid.SubCellOffsets.Length)
|
||||
return CenterOfCell(cell) + Grid.SubCellOffsets[index];
|
||||
return CenterOfCell(cell);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
@@ -22,7 +23,8 @@ namespace OpenRA
|
||||
public readonly MapGridType Type = MapGridType.Rectangular;
|
||||
public readonly Size TileSize = new Size(24, 24);
|
||||
public readonly byte MaximumTerrainHeight = 0;
|
||||
public readonly byte SubCellDefaultIndex = byte.MaxValue;
|
||||
public readonly SubCell DefaultSubCell = (SubCell)byte.MaxValue;
|
||||
|
||||
public readonly WVec[] SubCellOffsets =
|
||||
{
|
||||
new WVec(0, 0, 0), // full cell - index 0
|
||||
@@ -76,9 +78,10 @@ namespace OpenRA
|
||||
FieldLoader.Load(this, yaml);
|
||||
|
||||
// The default subcell index defaults to the middle entry
|
||||
if (SubCellDefaultIndex == byte.MaxValue)
|
||||
SubCellDefaultIndex = (byte)(SubCellOffsets.Length / 2);
|
||||
else if (SubCellDefaultIndex < (SubCellOffsets.Length > 1 ? 1 : 0) || SubCellDefaultIndex >= SubCellOffsets.Length)
|
||||
var defaultSubCellIndex = (byte)DefaultSubCell;
|
||||
if (defaultSubCellIndex == byte.MaxValue)
|
||||
DefaultSubCell = (SubCell)(SubCellOffsets.Length / 2);
|
||||
else if (defaultSubCellIndex < (SubCellOffsets.Length > 1 ? 1 : 0) || defaultSubCellIndex >= SubCellOffsets.Length)
|
||||
throw new InvalidDataException("Subcell default index must be a valid index into the offset triples and must be greater than 0 for mods with subcells");
|
||||
|
||||
var leftDelta = Type == MapGridType.RectangularIsometric ? new WVec(-512, 0, 0) : new WVec(-512, -512, 0);
|
||||
@@ -93,5 +96,13 @@ namespace OpenRA
|
||||
bottomDelta + new WVec(0, 0, 512 * ramp[3])
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
public WVec OffsetOfSubCell(SubCell subCell)
|
||||
{
|
||||
if (subCell == SubCell.Invalid || subCell == SubCell.Any)
|
||||
return WVec.Zero;
|
||||
|
||||
return SubCellOffsets[(int)subCell];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user