diff --git a/OpenRA.FileFormats/Exts.cs b/OpenRA.FileFormats/Exts.cs index 9c071b73e0..af2e5d98ef 100755 --- a/OpenRA.FileFormats/Exts.cs +++ b/OpenRA.FileFormats/Exts.cs @@ -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 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 diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index 58180da219..f380906945 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -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 SubCellOffsets = new Dictionary() { {SubCell.TopLeft, new PVecInt(-7,-6)},