building footprints

This commit is contained in:
Chris Forbes
2009-10-11 15:21:19 +13:00
parent cdf56c278f
commit 3e0432464b
7 changed files with 78 additions and 15 deletions

View File

@@ -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"));

View File

@@ -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<string, string[]> 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<string,string[]> 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);
}
}
}

View File

@@ -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"));
}
}
}

View File

@@ -72,6 +72,7 @@
<ItemGroup>
<Compile Include="Actor.cs" />
<Compile Include="Controller.cs" />
<Compile Include="GameRules\Footprint.cs" />
<Compile Include="GameRules\Rules.cs" />
<Compile Include="GameRules\UnitInfo.cs" />
<Compile Include="Graphics\Animation.cs" />

View File

@@ -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);
}
}

View File

@@ -36,39 +36,47 @@ namespace OpenRa.Game
if (!hasOverlay)
return;
Func<int, int, bool> passableAt = (x, y) =>
Func<int2, bool> 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;
}
}
}

13
footprint.txt Normal file
View File

@@ -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