building footprints
This commit is contained in:
@@ -30,7 +30,7 @@ namespace OpenRa.Game
|
|||||||
Rules.LoadRules();
|
Rules.LoadRules();
|
||||||
|
|
||||||
for( int i = 0 ; i < 8 ; i++ )
|
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)));
|
map = new Map(new IniFile(FileSystem.Open(mapName)));
|
||||||
FileSystem.Mount(new Package(map.Theater + ".mix"));
|
FileSystem.Mount(new Package(map.Theater + ".mix"));
|
||||||
|
|||||||
39
OpenRa.Game/GameRules/Footprint.cs
Normal file
39
OpenRa.Game/GameRules/Footprint.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,11 +9,13 @@ namespace OpenRa.Game
|
|||||||
static class Rules
|
static class Rules
|
||||||
{
|
{
|
||||||
public static UnitInfo UnitInfo;
|
public static UnitInfo UnitInfo;
|
||||||
|
public static Footprint Footprint;
|
||||||
|
|
||||||
// TODO: load rules from the map, where appropriate.
|
// TODO: load rules from the map, where appropriate.
|
||||||
public static void LoadRules()
|
public static void LoadRules()
|
||||||
{
|
{
|
||||||
UnitInfo = new UnitInfo( new IniFile( FileSystem.Open( "rules.ini" ) ) );
|
UnitInfo = new UnitInfo( new IniFile( FileSystem.Open( "rules.ini" ) ) );
|
||||||
|
Footprint = new Footprint(FileSystem.Open("footprint.txt"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Actor.cs" />
|
<Compile Include="Actor.cs" />
|
||||||
<Compile Include="Controller.cs" />
|
<Compile Include="Controller.cs" />
|
||||||
|
<Compile Include="GameRules\Footprint.cs" />
|
||||||
<Compile Include="GameRules\Rules.cs" />
|
<Compile Include="GameRules\Rules.cs" />
|
||||||
<Compile Include="GameRules\UnitInfo.cs" />
|
<Compile Include="GameRules\UnitInfo.cs" />
|
||||||
<Compile Include="Graphics\Animation.cs" />
|
<Compile Include="Graphics\Animation.cs" />
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
public void PrepareOverlay(Game game, int2 xy)
|
public void PrepareOverlay(Game game, int2 xy)
|
||||||
{
|
{
|
||||||
game.worldRenderer.uiOverlay.SetCurrentOverlay(xy, 2, 3);
|
game.worldRenderer.uiOverlay.SetCurrentOverlay(xy, Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,39 +36,47 @@ namespace OpenRa.Game
|
|||||||
if (!hasOverlay)
|
if (!hasOverlay)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Func<int, int, bool> passableAt = (x, y) =>
|
Func<int2, bool> passableAt = a =>
|
||||||
{
|
{
|
||||||
x += game.map.Offset.X;
|
a += game.map.Offset;
|
||||||
y += game.map.Offset.Y;
|
|
||||||
|
|
||||||
return game.map.IsInMap(x, y) &&
|
return game.map.IsInMap(a.X, a.Y) &&
|
||||||
TerrainCosts.Cost(UnitMovementType.Wheel,
|
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++)
|
var footprint = Rules.Footprint.GetFootprint(name);
|
||||||
for (int j = 0; j < height; j++)
|
var j = 0;
|
||||||
spriteRenderer.DrawSprite(passableAt(position.X + i, position.Y + j) ? buildOk : buildBlocked,
|
foreach (var row in footprint)
|
||||||
24 * (position + new int2(i, j)), 0);
|
{
|
||||||
|
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();
|
spriteRenderer.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasOverlay;
|
bool hasOverlay;
|
||||||
int2 position;
|
int2 position;
|
||||||
int width, height;
|
string name;
|
||||||
|
|
||||||
public void KillOverlay()
|
public void KillOverlay()
|
||||||
{
|
{
|
||||||
hasOverlay = false;
|
hasOverlay = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCurrentOverlay(int2 cell, int width, int height)
|
public void SetCurrentOverlay(int2 cell, string name)
|
||||||
{
|
{
|
||||||
hasOverlay = true;
|
hasOverlay = true;
|
||||||
position = cell;
|
position = cell;
|
||||||
this.width = width;
|
this.name = name;
|
||||||
this.height = height;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
13
footprint.txt
Normal file
13
footprint.txt
Normal 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
|
||||||
Reference in New Issue
Block a user