IOrderGenerator now renders itself (Removed various cast and is fails.). - Fixed silly bug in prev.

This commit is contained in:
Bob
2009-11-14 03:09:27 +13:00
parent c285f1d210
commit 5e3f2aa861
6 changed files with 140 additions and 132 deletions

View File

@@ -92,10 +92,8 @@ namespace OpenRa.Game.Graphics
DrawSelectionBox(u, Color.Yellow, false); DrawSelectionBox(u, Color.Yellow, false);
} }
var uog = Game.controller.orderGenerator as UnitOrderGenerator; if( Game.controller.orderGenerator != null )
if (uog != null) Game.controller.orderGenerator.Render();
foreach (var a in uog.selection)
DrawSelectionBox(a, Color.White, true);
lineRenderer.Flush(); lineRenderer.Flush();
@@ -111,7 +109,7 @@ namespace OpenRa.Game.Graphics
PerfHistory.Render(renderer, lineRenderer); PerfHistory.Render(renderer, lineRenderer);
} }
void DrawSelectionBox(Actor selectedUnit, Color c, bool drawHealthBar) public void DrawSelectionBox(Actor selectedUnit, Color c, bool drawHealthBar)
{ {
var center = selectedUnit.CenterLocation; var center = selectedUnit.CenterLocation;
var size = selectedUnit.SelectedSize; var size = selectedUnit.SelectedSize;

View File

@@ -8,5 +8,6 @@ namespace OpenRa.Game
{ {
IEnumerable<Order> Order( int2 xy, bool lmb ); IEnumerable<Order> Order( int2 xy, bool lmb );
void Tick(); void Tick();
void Render();
} }
} }

View File

@@ -43,5 +43,10 @@ namespace OpenRa.Game
if( producing == null || producing.Item != Building.Name || producing.RemainingTime != 0 ) if( producing == null || producing.Item != Building.Name || producing.RemainingTime != 0 )
Game.world.AddFrameEndTask( _ => { Game.controller.orderGenerator = null; } ); Game.world.AddFrameEndTask( _ => { Game.controller.orderGenerator = null; } );
} }
public void Render()
{
Game.worldRenderer.uiOverlay.DrawBuildingGrid( Building );
}
} }
} }

View File

@@ -42,7 +42,7 @@ namespace OpenRa.Game.Traits.Activities
umt = mobile.GetMovementType(), umt = mobile.GetMovementType(),
checkForBlocked = false, checkForBlocked = false,
}; };
var refineries = Game.world.Actors.Where( x => x.unitInfo.Name == "proc" ).ToList(); var refineries = Game.world.Actors.Where( x => x.unitInfo != null && x.unitInfo.Name == "proc" ).ToList();
if( refinery != null ) if( refinery != null )
search.AddInitialCell( refinery.Location + refineryDeliverOffset ); search.AddInitialCell( refinery.Location + refineryDeliverOffset );
else else

View File

@@ -41,30 +41,28 @@ namespace OpenRa.Game
for (var i = 0; i < 128; i++) for (var i = 0; i < 128; i++)
if (Game.UnitInfluence.GetUnitAt(new int2(i, j)) != null) if (Game.UnitInfluence.GetUnitAt(new int2(i, j)) != null)
spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0); spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0);
}
var placeBuilding = Game.controller.orderGenerator as PlaceBuilding; public void DrawBuildingGrid( UnitInfo.BuildingInfo bi )
if (placeBuilding == null) return; {
var position = Game.controller.MousePosition.ToInt2(); var position = Game.controller.MousePosition.ToInt2();
var bi = placeBuilding.Building;
var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */ var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */
if (ShowBuildDebug) if( ShowBuildDebug )
for (var j = 0; j < 128; j++) for( var j = 0 ; j < 128 ; j++ )
for (var i = 0; i < 128; i++) for( var i = 0 ; i < 128 ; i++ )
if (Game.GetDistanceToBase(new int2(i, j), Game.LocalPlayer) < maxDistance) if( Game.GetDistanceToBase( new int2( i, j ), Game.LocalPlayer ) < maxDistance )
if (Game.IsCellBuildable(new int2(i, j), bi.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel)) if( Game.IsCellBuildable( new int2( i, j ), bi.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel ) )
if (!Game.map.ContainsResource(new int2(i,j))) if( !Game.map.ContainsResource( new int2( i, j ) ) )
spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0); spriteRenderer.DrawSprite( unitDebug, Game.CellSize * new float2( i, j ), 0 );
var tooFarFromBase = !Footprint.Tiles(bi, position).Any( var tooFarFromBase = !Footprint.Tiles( bi, position ).Any(
t => Game.GetDistanceToBase(t, Game.LocalPlayer) < maxDistance); t => Game.GetDistanceToBase( t, Game.LocalPlayer ) < maxDistance );
foreach( var t in Footprint.Tiles( bi, position ) ) foreach( var t in Footprint.Tiles( bi, position ) )
spriteRenderer.DrawSprite( (!tooFarFromBase && Game.IsCellBuildable( t, bi.WaterBound spriteRenderer.DrawSprite( ( !tooFarFromBase && Game.IsCellBuildable( t, bi.WaterBound
? UnitMovementType.Float : UnitMovementType.Wheel ) && !Game.map.ContainsResource(t)) ? UnitMovementType.Float : UnitMovementType.Wheel ) && !Game.map.ContainsResource( t ) )
? buildOk : buildBlocked, Game.CellSize * t, 0 ); ? buildOk : buildBlocked, Game.CellSize * t, 0 );
spriteRenderer.Flush(); spriteRenderer.Flush();

View File

@@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Linq; using System.Linq;
using System.Text;
namespace OpenRa.Game namespace OpenRa.Game
{ {
@@ -28,5 +28,11 @@ namespace OpenRa.Game
{ {
selection.RemoveAll(a => a.IsDead); selection.RemoveAll(a => a.IsDead);
} }
public void Render()
{
foreach( var a in selection )
Game.worldRenderer.DrawSelectionBox( a, Color.White, true );
}
} }
} }