Reference SubCells directly from MapGrid.
This commit is contained in:
@@ -74,10 +74,6 @@ namespace OpenRA
|
|||||||
public readonly MapGrid Grid;
|
public readonly MapGrid Grid;
|
||||||
readonly ModData modData;
|
readonly ModData modData;
|
||||||
|
|
||||||
[FieldLoader.Ignore] public readonly WVec[] SubCellOffsets;
|
|
||||||
public readonly SubCell DefaultSubCell;
|
|
||||||
public readonly SubCell LastSubCell;
|
|
||||||
|
|
||||||
public IReadOnlyPackage Package { get; private set; }
|
public IReadOnlyPackage Package { get; private set; }
|
||||||
|
|
||||||
// Yaml map data
|
// Yaml map data
|
||||||
@@ -93,14 +89,6 @@ namespace OpenRA
|
|||||||
public bool LockPreview;
|
public bool LockPreview;
|
||||||
public bool InvalidCustomRules { get; private set; }
|
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)
|
public static string ComputeUID(IReadOnlyPackage package)
|
||||||
{
|
{
|
||||||
// UID is calculated by taking an SHA1 of the yaml and binary data
|
// UID is calculated by taking an SHA1 of the yaml and binary data
|
||||||
@@ -274,10 +262,6 @@ namespace OpenRA
|
|||||||
|
|
||||||
Grid = modData.Manifest.Get<MapGrid>();
|
Grid = modData.Manifest.Get<MapGrid>();
|
||||||
|
|
||||||
SubCellOffsets = Grid.SubCellOffsets;
|
|
||||||
LastSubCell = (SubCell)(SubCellOffsets.Length - 1);
|
|
||||||
DefaultSubCell = (SubCell)Grid.SubCellDefaultIndex;
|
|
||||||
|
|
||||||
PostInit();
|
PostInit();
|
||||||
|
|
||||||
Uid = ComputeUID(Package);
|
Uid = ComputeUID(Package);
|
||||||
@@ -760,8 +744,8 @@ namespace OpenRA
|
|||||||
public WPos CenterOfSubCell(CPos cell, SubCell subCell)
|
public WPos CenterOfSubCell(CPos cell, SubCell subCell)
|
||||||
{
|
{
|
||||||
var index = (int)subCell;
|
var index = (int)subCell;
|
||||||
if (index >= 0 && index <= SubCellOffsets.Length)
|
if (index >= 0 && index <= Grid.SubCellOffsets.Length)
|
||||||
return CenterOfCell(cell) + SubCellOffsets[index];
|
return CenterOfCell(cell) + Grid.SubCellOffsets[index];
|
||||||
return CenterOfCell(cell);
|
return CenterOfCell(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
@@ -22,7 +23,8 @@ namespace OpenRA
|
|||||||
public readonly MapGridType Type = MapGridType.Rectangular;
|
public readonly MapGridType Type = MapGridType.Rectangular;
|
||||||
public readonly Size TileSize = new Size(24, 24);
|
public readonly Size TileSize = new Size(24, 24);
|
||||||
public readonly byte MaximumTerrainHeight = 0;
|
public readonly byte MaximumTerrainHeight = 0;
|
||||||
public readonly byte SubCellDefaultIndex = byte.MaxValue;
|
public readonly SubCell DefaultSubCell = (SubCell)byte.MaxValue;
|
||||||
|
|
||||||
public readonly WVec[] SubCellOffsets =
|
public readonly WVec[] SubCellOffsets =
|
||||||
{
|
{
|
||||||
new WVec(0, 0, 0), // full cell - index 0
|
new WVec(0, 0, 0), // full cell - index 0
|
||||||
@@ -76,9 +78,10 @@ namespace OpenRA
|
|||||||
FieldLoader.Load(this, yaml);
|
FieldLoader.Load(this, yaml);
|
||||||
|
|
||||||
// The default subcell index defaults to the middle entry
|
// The default subcell index defaults to the middle entry
|
||||||
if (SubCellDefaultIndex == byte.MaxValue)
|
var defaultSubCellIndex = (byte)DefaultSubCell;
|
||||||
SubCellDefaultIndex = (byte)(SubCellOffsets.Length / 2);
|
if (defaultSubCellIndex == byte.MaxValue)
|
||||||
else if (SubCellDefaultIndex < (SubCellOffsets.Length > 1 ? 1 : 0) || SubCellDefaultIndex >= SubCellOffsets.Length)
|
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");
|
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);
|
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])
|
bottomDelta + new WVec(0, 0, 512 * ramp[3])
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WVec OffsetOfSubCell(SubCell subCell)
|
||||||
|
{
|
||||||
|
if (subCell == SubCell.Invalid || subCell == SubCell.Any)
|
||||||
|
return WVec.Zero;
|
||||||
|
|
||||||
|
return SubCellOffsets[(int)subCell];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -249,9 +249,9 @@ namespace OpenRA.Traits
|
|||||||
return preferredSubCell;
|
return preferredSubCell;
|
||||||
|
|
||||||
if (!AnyActorsAt(cell))
|
if (!AnyActorsAt(cell))
|
||||||
return map.DefaultSubCell;
|
return map.Grid.DefaultSubCell;
|
||||||
|
|
||||||
for (var i = (int)SubCell.First; i < map.SubCellOffsets.Length; i++)
|
for (var i = (int)SubCell.First; i < map.Grid.SubCellOffsets.Length; i++)
|
||||||
if (i != (int)preferredSubCell && !AnyActorsAt(cell, (SubCell)i, checkTransient))
|
if (i != (int)preferredSubCell && !AnyActorsAt(cell, (SubCell)i, checkTransient))
|
||||||
return (SubCell)i;
|
return (SubCell)i;
|
||||||
|
|
||||||
@@ -264,9 +264,9 @@ namespace OpenRA.Traits
|
|||||||
return preferredSubCell;
|
return preferredSubCell;
|
||||||
|
|
||||||
if (!AnyActorsAt(cell))
|
if (!AnyActorsAt(cell))
|
||||||
return map.DefaultSubCell;
|
return map.Grid.DefaultSubCell;
|
||||||
|
|
||||||
for (var i = (int)SubCell.First; i < map.SubCellOffsets.Length; i++)
|
for (var i = (int)SubCell.First; i < map.Grid.SubCellOffsets.Length; i++)
|
||||||
if (i != (int)preferredSubCell && !AnyActorsAt(cell, (SubCell)i, checkIfBlocker))
|
if (i != (int)preferredSubCell && !AnyActorsAt(cell, (SubCell)i, checkIfBlocker))
|
||||||
return (SubCell)i;
|
return (SubCell)i;
|
||||||
return SubCell.Invalid;
|
return SubCell.Invalid;
|
||||||
|
|||||||
@@ -190,8 +190,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
mobile.SetLocation(mobile.FromCell, mobile.FromSubCell, nextCell.Value.First, nextCell.Value.Second);
|
mobile.SetLocation(mobile.FromCell, mobile.FromSubCell, nextCell.Value.First, nextCell.Value.Second);
|
||||||
var from = self.World.Map.CenterOfSubCell(mobile.FromCell, mobile.FromSubCell);
|
var from = self.World.Map.CenterOfSubCell(mobile.FromCell, mobile.FromSubCell);
|
||||||
var to = Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) +
|
var to = Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) +
|
||||||
(self.World.Map.OffsetOfSubCell(mobile.FromSubCell) +
|
(self.World.Map.Grid.OffsetOfSubCell(mobile.FromSubCell) +
|
||||||
self.World.Map.OffsetOfSubCell(mobile.ToSubCell)) / 2;
|
self.World.Map.Grid.OffsetOfSubCell(mobile.ToSubCell)) / 2;
|
||||||
var move = new MoveFirstHalf(
|
var move = new MoveFirstHalf(
|
||||||
this,
|
this,
|
||||||
from,
|
from,
|
||||||
@@ -381,15 +381,15 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
|
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
|
||||||
{
|
{
|
||||||
var fromSubcellOffset = self.World.Map.OffsetOfSubCell(mobile.FromSubCell);
|
var fromSubcellOffset = self.World.Map.Grid.OffsetOfSubCell(mobile.FromSubCell);
|
||||||
var toSubcellOffset = self.World.Map.OffsetOfSubCell(mobile.ToSubCell);
|
var toSubcellOffset = self.World.Map.Grid.OffsetOfSubCell(mobile.ToSubCell);
|
||||||
|
|
||||||
var nextCell = parent.PopPath(self);
|
var nextCell = parent.PopPath(self);
|
||||||
if (nextCell != null)
|
if (nextCell != null)
|
||||||
{
|
{
|
||||||
if (IsTurn(mobile, nextCell.Value.First))
|
if (IsTurn(mobile, nextCell.Value.First))
|
||||||
{
|
{
|
||||||
var nextSubcellOffset = self.World.Map.OffsetOfSubCell(nextCell.Value.Second);
|
var nextSubcellOffset = self.World.Map.Grid.OffsetOfSubCell(nextCell.Value.Second);
|
||||||
var ret = new MoveFirstHalf(
|
var ret = new MoveFirstHalf(
|
||||||
Move,
|
Move,
|
||||||
Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
||||||
|
|||||||
@@ -368,7 +368,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
speedModifiers = Exts.Lazy(() => self.TraitsImplementing<ISpeedModifier>().ToArray().Select(x => x.GetSpeedModifier()));
|
speedModifiers = Exts.Lazy(() => self.TraitsImplementing<ISpeedModifier>().ToArray().Select(x => x.GetSpeedModifier()));
|
||||||
|
|
||||||
ToSubCell = FromSubCell = info.SharesCell ? init.World.Map.DefaultSubCell : SubCell.FullCell;
|
ToSubCell = FromSubCell = info.SharesCell ? init.World.Map.Grid.DefaultSubCell : SubCell.FullCell;
|
||||||
if (init.Contains<SubCellInit>())
|
if (init.Contains<SubCellInit>())
|
||||||
FromSubCell = ToSubCell = init.Get<SubCellInit, SubCell>();
|
FromSubCell = ToSubCell = init.Get<SubCellInit, SubCell>();
|
||||||
|
|
||||||
@@ -397,7 +397,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (Info.SharesCell)
|
if (Info.SharesCell)
|
||||||
{
|
{
|
||||||
if (preferred <= SubCell.FullCell)
|
if (preferred <= SubCell.FullCell)
|
||||||
return self.World.Map.DefaultSubCell;
|
return self.World.Map.Grid.DefaultSubCell;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -776,7 +776,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
// TODO: solve/reduce cell is full problem
|
// TODO: solve/reduce cell is full problem
|
||||||
if (subCell == SubCell.Invalid)
|
if (subCell == SubCell.Invalid)
|
||||||
subCell = self.World.Map.DefaultSubCell;
|
subCell = self.World.Map.Grid.DefaultSubCell;
|
||||||
|
|
||||||
// Reserve the exit cell
|
// Reserve the exit cell
|
||||||
SetPosition(self, cell, subCell);
|
SetPosition(self, cell, subCell);
|
||||||
|
|||||||
@@ -226,9 +226,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var map = worldRenderer.World.Map;
|
var map = worldRenderer.World.Map;
|
||||||
var previews = PreviewsAt(cell).ToList();
|
var previews = PreviewsAt(cell).ToList();
|
||||||
if (!previews.Any())
|
if (!previews.Any())
|
||||||
return map.DefaultSubCell;
|
return map.Grid.DefaultSubCell;
|
||||||
|
|
||||||
for (var i = (int)SubCell.First; i < map.SubCellOffsets.Length; i++)
|
for (var i = (int)SubCell.First; i < map.Grid.SubCellOffsets.Length; i++)
|
||||||
if (!previews.Any(p => p.Footprint[cell] == (SubCell)i))
|
if (!previews.Any(p => p.Footprint[cell] == (SubCell)i))
|
||||||
return (SubCell)i;
|
return (SubCell)i;
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var targetCell = world.Map.CellContaining(target);
|
var targetCell = world.Map.CellContaining(target);
|
||||||
|
|
||||||
// Correct for SubCell offset
|
// Correct for SubCell offset
|
||||||
target -= world.Map.OffsetOfSubCell(srcSub);
|
target -= world.Map.Grid.OffsetOfSubCell(srcSub);
|
||||||
|
|
||||||
// Select only the tiles that are within range from the requested SubCell
|
// Select only the tiles that are within range from the requested SubCell
|
||||||
// This assumes that the SubCell does not change during the path traversal
|
// This assumes that the SubCell does not change during the path traversal
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ MapGrid:
|
|||||||
Type: RectangularIsometric
|
Type: RectangularIsometric
|
||||||
MaximumTerrainHeight: 16
|
MaximumTerrainHeight: 16
|
||||||
SubCellOffsets: 0,0,0, -256,128,0, 0,-128,0, 256,128,0
|
SubCellOffsets: 0,0,0, -256,128,0, 0,-128,0, 256,128,0
|
||||||
SubCellDefaultIndex: 2
|
DefaultSubCell: 2
|
||||||
|
|
||||||
Cursors:
|
Cursors:
|
||||||
ts|cursors.yaml
|
ts|cursors.yaml
|
||||||
|
|||||||
Reference in New Issue
Block a user