Work around a crash.

This commit is contained in:
Paul Chote
2011-02-04 18:10:18 +13:00
parent b69388b5e7
commit 45e89491d7

View File

@@ -59,10 +59,24 @@ namespace OpenRA.Traits
SubCell.BottomLeft, SubCell.BottomRight}.Any(b => !AnyUnitsAt(a,b)); SubCell.BottomLeft, SubCell.BottomRight}.Any(b => !AnyUnitsAt(a,b));
} }
// This is only used inside Move, when we *know* that we can enter the cell.
// If the cell contains something crushable, a naive check of 'is it empty' will fail.
// Infantry can currently only crush crates/mines which take a whole cell, so we will ignore
// the SubCell.FullCell case and hope that someone doesn't introduce subcell units
// crushing other subcell units in the future.
public SubCell GetFreeSubcell(int2 a, SubCell preferred) public SubCell GetFreeSubcell(int2 a, SubCell preferred)
{ {
return new[]{ preferred, SubCell.TopLeft, SubCell.TopRight, SubCell.Center, return new[]{ preferred, SubCell.TopLeft, SubCell.TopRight, SubCell.Center,
SubCell.BottomLeft, SubCell.BottomRight}.First(b => !AnyUnitsAt(a,b)); SubCell.BottomLeft, SubCell.BottomRight}.First(b =>
{
var node = influence[ a.X, a.Y ];
while (node != null)
{
if (node.subCell == b) return false;
node = node.next;
}
return true;
});
} }
public bool AnyUnitsAt(int2 a) public bool AnyUnitsAt(int2 a)