Skip to content

Commit

Permalink
fix linebuild bugs (1/2)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisforbes committed Apr 4, 2010
1 parent 3caa0a3 commit 8501083
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions OpenRA.Game/UiOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,23 @@ public void DrawBuildingGrid( World world, string name, BuildingInfo bi )
{
var position = Game.controller.MousePosition.ToInt2();
var topLeft = position - Footprint.AdjustForBuildingSize( bi );
var isCloseEnough = world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, topLeft);
var res = world.WorldActor.traits.Get<ResourceLayer>();

foreach( var t in Footprint.Tiles( name, bi, topLeft ) )
spriteRenderer.DrawSprite( ( isCloseEnough && world.IsCellBuildable( t, bi.WaterBound) && res.GetResource(t) == null )
? buildOk : buildBlocked, Game.CellSize * t, "terrain" );

// Linebuild for walls.
// Assumes a 1x1 footprint; weird things will happen for other footprints
if (Rules.Info[ name ].Traits.Contains<LineBuildInfo>())
foreach( var t in LineBuildUtils.GetLineBuildCells(world, topLeft, name, bi ) )
spriteRenderer.DrawSprite(world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, t)
if (Rules.Info[name].Traits.Contains<LineBuildInfo>())
{
foreach (var t in LineBuildUtils.GetLineBuildCells(world, topLeft, name, bi))
spriteRenderer.DrawSprite(world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, t)
? buildOk : buildBlocked, Game.CellSize * t, "terrain");
}
else
{
var res = world.WorldActor.traits.Get<ResourceLayer>();
var isCloseEnough = world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, topLeft);
foreach (var t in Footprint.Tiles(name, bi, topLeft))
spriteRenderer.DrawSprite((isCloseEnough && world.IsCellBuildable(t, bi.WaterBound) && res.GetResource(t) == null)
? buildOk : buildBlocked, Game.CellSize * t, "terrain");
}

spriteRenderer.Flush();
}
Expand All @@ -90,6 +94,9 @@ public static IEnumerable<int2> GetLineBuildCells(World world, int2 location, st
int range = Rules.Info[name].Traits.Get<LineBuildInfo>().Range;
var topLeft = location; // 1x1 assumption!

if (world.IsCellBuildable(topLeft, bi.WaterBound))
yield return topLeft;

// Start at place location, search outwards
// TODO: First make it work, then make it nice
var vecs = new[] { new int2(1, 0), new int2(0, 1), new int2(-1, 0), new int2(0, -1) };
Expand Down

0 comments on commit 8501083

Please sign in to comment.