From 939ec0408ee55ebbc0ad9fcdf2709fc78c2a24b2 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 31 Mar 2010 18:00:27 +1300 Subject: [PATCH] range circles for base defenses --- OpenRA.Game/Graphics/WorldRenderer.cs | 27 +++++++++++++++++++ OpenRA.Game/Orders/UnitOrderGenerator.cs | 8 ++++-- .../Traits/Render/RenderUnitTurreted.cs | 3 +++ mods/ra/rules.yaml | 7 +++++ shaders/line.fx | 4 +-- 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index e38f64f4f1..d9b4f9f6cf 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -339,5 +339,32 @@ namespace OpenRA.Graphics } } } + + public void DrawRangeCircle(Actor selectedUnit) + { + if (selectedUnit.Owner != world.LocalPlayer) + return; + + var range = (int)selectedUnit.GetPrimaryWeapon().Range; + var r2 = range * range; + + var c = Color.FromArgb(128, Color.Yellow); + + foreach (var t in world.FindTilesInCircle(selectedUnit.Location, range)) + { + if ((selectedUnit.Location - t - new int2(-1, 0)).LengthSquared > r2) + lineRenderer.DrawLine(Game.CellSize * t, Game.CellSize * (t + new int2(0, 1)), + c,c); + if ((selectedUnit.Location - t - new int2(1, 0)).LengthSquared > r2) + lineRenderer.DrawLine(Game.CellSize * (t + new int2(1,0)), Game.CellSize * (t + new int2(1, 1)), + c,c); + if ((selectedUnit.Location - t - new int2(0,-1)).LengthSquared > r2) + lineRenderer.DrawLine(Game.CellSize * t, Game.CellSize * (t + new int2(1,0)), + c,c); + if ((selectedUnit.Location - t - new int2(0,1)).LengthSquared > r2) + lineRenderer.DrawLine(Game.CellSize * (t + new int2(0,1)), Game.CellSize * (t + new int2(1, 1)), + c,c); + } + } } } diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index 9231fa4557..6e57f27e23 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -42,8 +42,12 @@ namespace OpenRA.Orders public void Render( World world ) { - foreach( var a in Game.controller.selection.Actors ) - world.WorldRenderer.DrawSelectionBox( a, Color.White, true ); + foreach (var a in Game.controller.selection.Actors) + { + world.WorldRenderer.DrawSelectionBox(a, Color.White, true); + if (a.traits.Contains()) + world.WorldRenderer.DrawRangeCircle(a); + } } public string GetCursor( World world, int2 xy, MouseInput mi ) diff --git a/OpenRA.Game/Traits/Render/RenderUnitTurreted.cs b/OpenRA.Game/Traits/Render/RenderUnitTurreted.cs index af7ec971af..275c77692a 100644 --- a/OpenRA.Game/Traits/Render/RenderUnitTurreted.cs +++ b/OpenRA.Game/Traits/Render/RenderUnitTurreted.cs @@ -64,4 +64,7 @@ namespace OpenRA.Traits } } } + + class RenderRangeCircleInfo : StatelessTraitInfo { } + class RenderRangeCircle { } } diff --git a/mods/ra/rules.yaml b/mods/ra/rules.yaml index 1dbf21a277..b95877f9c3 100755 --- a/mods/ra/rules.yaml +++ b/mods/ra/rules.yaml @@ -568,6 +568,7 @@ TSLA: AutoTarget: IronCurtainable: -RenderBuilding: + RenderRangeCircle: AGUN: RequiresPower: @@ -598,6 +599,7 @@ AGUN: AutoTarget: IronCurtainable: -RenderBuilding: + RenderRangeCircle: DOME: RequiresPower: @@ -1304,6 +1306,7 @@ PBOX: PrimaryWeapon: Vulcan AutoTarget: IronCurtainable: + RenderRangeCircle: HBOX: Inherits: ^Building @@ -1324,6 +1327,7 @@ HBOX: PrimaryWeapon: Vulcan AutoTarget: IronCurtainable: + RenderRangeCircle: GUN: Inherits: ^Building @@ -1349,6 +1353,7 @@ GUN: AutoTarget: IronCurtainable: -RenderBuilding: + RenderRangeCircle: FTUR: Inherits: ^Building @@ -1370,6 +1375,7 @@ FTUR: PrimaryOffset: 0,0,12,8 AutoTarget: IronCurtainable: + RenderRangeCircle: SAM: Inherits: ^Building @@ -1397,6 +1403,7 @@ SAM: AutoTarget: IronCurtainable: -RenderBuilding: + RenderRangeCircle: ATEK: Inherits: ^Building diff --git a/shaders/line.fx b/shaders/line.fx index 71e69cd9e5..1d547dcb1b 100644 --- a/shaders/line.fx +++ b/shaders/line.fx @@ -37,7 +37,7 @@ technique high_quality { VertexProgram = compile latest Simple_vp(); FragmentProgram = compile latest Simple_fp(); - //SrcBlend = SrcAlpha; - //DestBlend = InvSrcAlpha; + BlendEquation = FuncAdd; + BlendFunc = int2( SrcAlpha, OneMinusSrcAlpha ); } }