Merge pull request #3474 from chrisforbes/movement-equiv-classes

movement equivalence classes
This commit is contained in:
Paul Chote
2013-06-26 01:56:25 -07:00
2 changed files with 23 additions and 0 deletions

View File

@@ -225,6 +225,20 @@ namespace OpenRA
}
public static Rectangle Bounds(this Bitmap b) { return new Rectangle(0, 0, b.Width, b.Height); }
public static int ToBits(this IEnumerable<bool> bits)
{
var i = 0;
var result = 0;
foreach (var b in bits)
if (b)
result |= (1 << i++);
else
i++;
if (i > 33)
throw new InvalidOperationException("ToBits only accepts up to 32 values.");
return result;
}
}
public static class Enum<T>

View File

@@ -72,6 +72,15 @@ namespace OpenRA.Mods.RA.Move
return TerrainSpeeds[type].Cost;
}
public int GetMovementClass(TileSet tileset)
{
/* collect our ability to cross *all* terraintypes, in a bitvector */
var passability = tileset.Terrain.OrderBy(t => t.Key)
.Select(t => TerrainSpeeds.ContainsKey(t.Key) && TerrainSpeeds[t.Key].Cost < int.MaxValue);
return passability.ToBits();
}
public readonly Dictionary<SubCell, PVecInt> SubCellOffsets = new Dictionary<SubCell, PVecInt>()
{
{SubCell.TopLeft, new PVecInt(-7,-6)},