diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index a97f177de1..b3ec25dce4 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -30,7 +30,7 @@ namespace OpenRa.Game Rules.LoadRules(); for( int i = 0 ; i < 8 ; i++ ) - players.Add(i, new Player(i, string.Format("Multi{0}", i), OpenRa.TechTree.Race.Allies)); + players.Add(i, new Player(i, string.Format("Multi{0}", i), OpenRa.TechTree.Race.Soviet)); map = new Map(new IniFile(FileSystem.Open(mapName))); FileSystem.Mount(new Package(map.Theater + ".mix")); diff --git a/OpenRa.Game/GameRules/Footprint.cs b/OpenRa.Game/GameRules/Footprint.cs new file mode 100644 index 0000000000..5d6435f4b4 --- /dev/null +++ b/OpenRa.Game/GameRules/Footprint.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using OpenRa.Game.Graphics; + +namespace OpenRa.Game.GameRules +{ + class Footprint + { + Dictionary buildingFootprints; + + public string[] GetFootprint(string name) + { + string[] val; + if (!buildingFootprints.TryGetValue(name, out val)) + buildingFootprints.TryGetValue("*", out val); + return val; + } + + public Footprint(Stream s) + { + var lines = Util.ReadAllLines(s).Where(a => !a.StartsWith("#")); + + Func words = + b => b.Split( new[] { ' ', '\t' }, + StringSplitOptions.RemoveEmptyEntries ); + + var buildings = lines + .Select(a => a.Split(':')) + .SelectMany(a => words(a[1]) + .Select( b => new { Name=b, Pat=words(a[0]) } )); + + buildingFootprints = buildings + .ToDictionary(a => a.Name, a => a.Pat); + } + } +} diff --git a/OpenRa.Game/GameRules/Rules.cs b/OpenRa.Game/GameRules/Rules.cs index e0b3aef668..7bb949e4ec 100755 --- a/OpenRa.Game/GameRules/Rules.cs +++ b/OpenRa.Game/GameRules/Rules.cs @@ -9,11 +9,13 @@ namespace OpenRa.Game static class Rules { public static UnitInfo UnitInfo; + public static Footprint Footprint; // TODO: load rules from the map, where appropriate. public static void LoadRules() { UnitInfo = new UnitInfo( new IniFile( FileSystem.Open( "rules.ini" ) ) ); + Footprint = new Footprint(FileSystem.Open("footprint.txt")); } } } diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 24ddd6e70b..ead638dc3b 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -72,6 +72,7 @@ + diff --git a/OpenRa.Game/Sidebar.cs b/OpenRa.Game/Sidebar.cs index 9ff72ad2df..cb66832e27 100644 --- a/OpenRa.Game/Sidebar.cs +++ b/OpenRa.Game/Sidebar.cs @@ -192,7 +192,7 @@ namespace OpenRa.Game public void PrepareOverlay(Game game, int2 xy) { - game.worldRenderer.uiOverlay.SetCurrentOverlay(xy, 2, 3); + game.worldRenderer.uiOverlay.SetCurrentOverlay(xy, Name); } } diff --git a/OpenRa.Game/UiOverlay.cs b/OpenRa.Game/UiOverlay.cs index 3433535c8f..50b251fb78 100644 --- a/OpenRa.Game/UiOverlay.cs +++ b/OpenRa.Game/UiOverlay.cs @@ -36,39 +36,47 @@ namespace OpenRa.Game if (!hasOverlay) return; - Func passableAt = (x, y) => + Func passableAt = a => { - x += game.map.Offset.X; - y += game.map.Offset.Y; + a += game.map.Offset; - return game.map.IsInMap(x, y) && + return game.map.IsInMap(a.X, a.Y) && TerrainCosts.Cost(UnitMovementType.Wheel, - game.terrain.tileSet.GetWalkability(game.map.MapTiles[x, y])) < double.PositiveInfinity; + game.terrain.tileSet.GetWalkability(game.map.MapTiles[a.X, a.Y])) < double.PositiveInfinity; }; - for (int i = 0; i < width; i++) - for (int j = 0; j < height; j++) - spriteRenderer.DrawSprite(passableAt(position.X + i, position.Y + j) ? buildOk : buildBlocked, - 24 * (position + new int2(i, j)), 0); + var footprint = Rules.Footprint.GetFootprint(name); + var j = 0; + foreach (var row in footprint) + { + var i = 0; + foreach (var c in row) + { + if (c != '_') + spriteRenderer.DrawSprite(passableAt(position + new int2(i, j)) ? buildOk : buildBlocked, + 24 * (position + new int2(i, j)), 0); + ++i; + } + ++j; + } spriteRenderer.Flush(); } bool hasOverlay; int2 position; - int width, height; + string name; public void KillOverlay() { hasOverlay = false; } - public void SetCurrentOverlay(int2 cell, int width, int height) + public void SetCurrentOverlay(int2 cell, string name) { hasOverlay = true; position = cell; - this.width = width; - this.height = height; + this.name = name; } } } diff --git a/footprint.txt b/footprint.txt new file mode 100644 index 0000000000..5b2d1c7404 --- /dev/null +++ b/footprint.txt @@ -0,0 +1,13 @@ +# +# Building footprints +# + +# default is indicated by * + +x : ftur sbag brik fenc gun pbox hbox silo tsla agun gap kenn * +xx xx xx : powr dome barr tent domf hpad atek stek +xxx xxx xxx : fact facf syrf syrd weap weaf spen spef apwr +xx : sam mslo +_x_ xxx xxx xxx : proc +xxx xxx : afld +_x_ xxx _x_ : fix \ No newline at end of file