This commit is contained in:
Matthias Mailänder
2014-07-03 18:35:11 +02:00
parent 0ffe88753c
commit b02ca7695f

View File

@@ -23,13 +23,13 @@ namespace OpenRA.Mods.RA.Buildings
var footprint = buildingInfo.Footprint.Where(x => !char.IsWhiteSpace(x)); var footprint = buildingInfo.Footprint.Where(x => !char.IsWhiteSpace(x));
var buildingTraits = rules.Actors[name].Traits; var buildingTraits = rules.Actors[name].Traits;
if (buildingTraits.Contains<BibInfo>() && !(buildingTraits.Get<BibInfo>().HasMinibib)) if (buildingTraits.Contains<BibInfo>() && !buildingTraits.Get<BibInfo>().HasMinibib)
{ {
dim += new CVec(0, 1); dim += new CVec(0, 1);
footprint = footprint.Concat(new char[dim.X]); footprint = footprint.Concat(new char[dim.X]);
} }
return TilesWhere( name, dim, footprint.ToArray(), a => a != '_' ).Select( t => t + topLeft ); return TilesWhere(name, dim, footprint.ToArray(), a => a != '_').Select(t => t + topLeft);
} }
public static IEnumerable<CPos> Tiles(Actor a) public static IEnumerable<CPos> Tiles(Actor a)
@@ -39,20 +39,20 @@ namespace OpenRA.Mods.RA.Buildings
public static IEnumerable<CPos> UnpathableTiles(string name, BuildingInfo buildingInfo, CPos position) public static IEnumerable<CPos> UnpathableTiles(string name, BuildingInfo buildingInfo, CPos position)
{ {
var footprint = buildingInfo.Footprint.Where( x => !char.IsWhiteSpace( x ) ).ToArray(); var footprint = buildingInfo.Footprint.Where(x => !char.IsWhiteSpace(x)).ToArray();
foreach( var tile in TilesWhere( name, (CVec)buildingInfo.Dimensions, footprint, a => a == 'x' ) ) foreach (var tile in TilesWhere(name, (CVec)buildingInfo.Dimensions, footprint, a => a == 'x'))
yield return tile + position; yield return tile + position;
} }
static IEnumerable<CVec> TilesWhere(string name, CVec dim, char[] footprint, Func<char, bool> cond) static IEnumerable<CVec> TilesWhere(string name, CVec dim, char[] footprint, Func<char, bool> cond)
{ {
if( footprint.Length != dim.X * dim.Y ) if (footprint.Length != dim.X * dim.Y)
throw new InvalidOperationException( "Invalid footprint for " + name ); throw new InvalidOperationException("Invalid footprint for " + name);
var index = 0; var index = 0;
for( var y = 0 ; y < dim.Y ; y++ ) for (var y = 0; y < dim.Y; y++)
for( var x = 0 ; x < dim.X ; x++ ) for (var x = 0; x < dim.X; x++)
if( cond( footprint[ index++ ] ) ) if (cond(footprint[index++]))
yield return new CVec(x, y); yield return new CVec(x, y);
} }