From e8adc357e9aedb3784ad04b3ce5de1d7d76e7b33 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 26 Jul 2010 12:01:13 +1200 Subject: [PATCH] Draw targeting lines for player-issued orders. Can force-display targets with [alt]. --- OpenRA.Game/OpenRA.Game.csproj | 3 +- OpenRA.Game/Traits/DrawLineToTarget.cs | 69 ++++++++++++++++++++++++++ OpenRA.Game/Traits/Mobile.cs | 11 +++- OpenRA.Mods.RA/AttackBase.cs | 14 +++++- OpenRA.Mods.RA/C4Demolition.cs | 9 +++- OpenRA.Mods.RA/EngineerCapture.cs | 9 +++- OpenRA.Mods.RA/EngineerRepair.cs | 9 +++- OpenRA.Mods.RA/Harvester.cs | 19 +++++-- OpenRA.Mods.RA/Helicopter.cs | 17 ++++++- OpenRA.Mods.RA/Passenger.cs | 9 +++- OpenRA.Mods.RA/Plane.cs | 19 +++++-- OpenRA.Mods.RA/Repairable.cs | 9 +++- mods/cnc/defaults.yaml | 5 ++ mods/ra/defaults.yaml | 5 ++ 14 files changed, 189 insertions(+), 18 deletions(-) create mode 100644 OpenRA.Game/Traits/DrawLineToTarget.cs diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 41486cd242..7692185abb 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -1,4 +1,4 @@ - + Debug @@ -228,6 +228,7 @@ + diff --git a/OpenRA.Game/Traits/DrawLineToTarget.cs b/OpenRA.Game/Traits/DrawLineToTarget.cs new file mode 100644 index 0000000000..c1b65c5ee6 --- /dev/null +++ b/OpenRA.Game/Traits/DrawLineToTarget.cs @@ -0,0 +1,69 @@ +#region Copyright & License Information +/* + * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see LICENSE. + */ +#endregion + +using System.Drawing; + +namespace OpenRA.Traits +{ + public class DrawLineToTargetInfo : ITraitInfo + { + public readonly int Ticks = 60; + + public virtual object Create(ActorInitializer init) { return new DrawLineToTarget(this); } + } + + public class DrawLineToTarget :IRenderSelection + { + DrawLineToTargetInfo Info; + public DrawLineToTarget(DrawLineToTargetInfo info) + { + this.Info = info; + } + + Actor target; + float2 pos; + int lifetime; + Color c; + public void SetTarget(Actor self, int2 cell, Color c) + { + pos = Game.CellSize * (cell + new float2(0.5f, 0.5f)); + lifetime = Info.Ticks; + target = null; + this.c = c; + } + + public void SetTarget(Actor self, Actor target, Color c) + { + this.target = target; + lifetime = Info.Ticks; + this.c = c; + } + + public void Render (Actor self) + { + var force = Game.controller.GetModifiers().HasModifier(Modifiers.Alt); + if ((lifetime <= 0 || --lifetime <= 0) && !force) + return; + + var p = (target != null) ? target.CenterLocation : pos; + + Game.Renderer.LineRenderer.DrawLine(self.CenterLocation, p, c, c); + for (bool b = false; !b; p = self.CenterLocation, b = true) + { + Game.Renderer.LineRenderer.DrawLine(p + new float2(-1, -1), p + new float2(-1, 1), c, c); + Game.Renderer.LineRenderer.DrawLine(p + new float2(-1, 1), p + new float2(1, 1), c, c); + Game.Renderer.LineRenderer.DrawLine(p + new float2(1, 1), p + new float2(1, -1), c, c); + Game.Renderer.LineRenderer.DrawLine(p + new float2(1, -1), p + new float2(-1, -1), c, c); + } + Game.Renderer.LineRenderer.Flush(); + } + } +} + diff --git a/OpenRA.Game/Traits/Mobile.cs b/OpenRA.Game/Traits/Mobile.cs index e08dc2f7b7..899e39b071 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -14,6 +14,7 @@ using System.Linq; using OpenRA.Effects; using OpenRA.Traits.Activities; using OpenRA.FileFormats; +using System.Drawing; namespace OpenRA.Traits { @@ -111,7 +112,13 @@ namespace OpenRA.Traits if (self.traits.GetOrDefault().CanEnterCell(order.TargetLocation)) { if (self.Owner == self.World.LocalPlayer) - self.World.AddFrameEndTask(w => w.Add(new MoveFlash(self.World, order.TargetLocation))); + self.World.AddFrameEndTask(w => + { + w.Add(new MoveFlash(self.World, order.TargetLocation)); + var line = self.traits.GetOrDefault(); + if (line != null) + line.SetTarget(self, order.TargetLocation, Color.Green); + }); if( !order.Queued ) self.CancelActivity(); self.QueueActivity(new Activities.Move(order.TargetLocation, 8)); @@ -201,7 +208,7 @@ namespace OpenRA.Traits b.OnCrush(self); } } - + public virtual float MovementCostForCell(Actor self, int2 cell) { if (!self.World.Map.IsInMap(cell.X,cell.Y)) diff --git a/OpenRA.Mods.RA/AttackBase.cs b/OpenRA.Mods.RA/AttackBase.cs index c61937462d..45e1ec587f 100755 --- a/OpenRA.Mods.RA/AttackBase.cs +++ b/OpenRA.Mods.RA/AttackBase.cs @@ -15,6 +15,7 @@ using OpenRA.Effects; using OpenRA.FileFormats; using OpenRA.GameRules; using OpenRA.Traits; +using System.Drawing; namespace OpenRA.Mods.RA { @@ -246,8 +247,17 @@ namespace OpenRA.Mods.RA self.CancelActivity(); QueueAttack(self, order); - if (self.Owner == self.World.LocalPlayer && order.TargetActor != null) - self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor))); + if (self.Owner == self.World.LocalPlayer) + self.World.AddFrameEndTask(w => + { + if (order.TargetActor != null) + w.Add(new FlashTarget(order.TargetActor)); + + var line = self.traits.GetOrDefault(); + if (line != null) + if (order.TargetActor != null) line.SetTarget(self, order.TargetActor, Color.Red); + else line.SetTarget(self, order.TargetLocation, Color.Red); + }); } else target = Target.None; diff --git a/OpenRA.Mods.RA/C4Demolition.cs b/OpenRA.Mods.RA/C4Demolition.cs index 603e2af541..49b0c4eb8f 100644 --- a/OpenRA.Mods.RA/C4Demolition.cs +++ b/OpenRA.Mods.RA/C4Demolition.cs @@ -12,6 +12,7 @@ using OpenRA.Effects; using OpenRA.Mods.RA.Activities; using OpenRA.Traits; using OpenRA.Traits.Activities; +using System.Drawing; namespace OpenRA.Mods.RA { @@ -37,7 +38,13 @@ namespace OpenRA.Mods.RA if (order.OrderString == "C4") { if (self.Owner == self.World.LocalPlayer) - self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor))); + self.World.AddFrameEndTask(w => + { + w.Add(new FlashTarget(order.TargetActor)); + var line = self.traits.GetOrDefault(); + if (line != null) + line.SetTarget(self, order.TargetActor, Color.Red); + }); self.CancelActivity(); self.QueueActivity(new Move(order.TargetActor.Location, order.TargetActor)); diff --git a/OpenRA.Mods.RA/EngineerCapture.cs b/OpenRA.Mods.RA/EngineerCapture.cs index 947726219a..98c447692c 100644 --- a/OpenRA.Mods.RA/EngineerCapture.cs +++ b/OpenRA.Mods.RA/EngineerCapture.cs @@ -12,6 +12,7 @@ using OpenRA.Mods.RA.Activities; using OpenRA.Effects; using OpenRA.Traits; using OpenRA.Traits.Activities; +using System.Drawing; namespace OpenRA.Mods.RA { @@ -43,7 +44,13 @@ namespace OpenRA.Mods.RA if (order.OrderString == "CaptureBuilding") { if (self.Owner == self.World.LocalPlayer) - self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor))); + self.World.AddFrameEndTask(w => + { + w.Add(new FlashTarget(order.TargetActor)); + var line = self.traits.GetOrDefault(); + if (line != null) + line.SetTarget(self, order.TargetActor, Color.Red); + }); self.CancelActivity(); self.QueueActivity(new Move(order.TargetActor.Location, order.TargetActor)); diff --git a/OpenRA.Mods.RA/EngineerRepair.cs b/OpenRA.Mods.RA/EngineerRepair.cs index 1dfa79a126..f07f88c0cc 100644 --- a/OpenRA.Mods.RA/EngineerRepair.cs +++ b/OpenRA.Mods.RA/EngineerRepair.cs @@ -12,6 +12,7 @@ using OpenRA.Mods.RA.Activities; using OpenRA.Traits; using OpenRA.Traits.Activities; using OpenRA.Effects; +using System.Drawing; namespace OpenRA.Mods.RA { @@ -53,7 +54,13 @@ namespace OpenRA.Mods.RA if (order.OrderString == "EngineerRepair" && order.TargetActor.Health < order.TargetActor.GetMaxHP()) { if (self.Owner == self.World.LocalPlayer) - self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor))); + self.World.AddFrameEndTask(w => + { + w.Add(new FlashTarget(order.TargetActor)); + var line = self.traits.GetOrDefault(); + if (line != null) + line.SetTarget(self, order.TargetActor, Color.Yellow); + }); self.CancelActivity(); self.QueueActivity(new Move(order.TargetActor.Location, order.TargetActor)); diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs index c4ac895ac8..485f2b9805 100755 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -13,7 +13,8 @@ using System.Linq; using OpenRA.Effects; using OpenRA.Mods.RA.Activities; using OpenRA.Traits; -using OpenRA.Traits.Activities; +using OpenRA.Traits.Activities; +using System.Drawing; namespace OpenRA.Mods.RA { @@ -122,7 +123,13 @@ namespace OpenRA.Mods.RA if (order.OrderString == "Harvest") { if (self.Owner == self.World.LocalPlayer) - self.World.AddFrameEndTask(w => w.Add(new MoveFlash(self.World, order.TargetLocation))); + self.World.AddFrameEndTask(w => + { + w.Add(new MoveFlash(self.World, order.TargetLocation)); + var line = self.traits.GetOrDefault(); + if (line != null) + line.SetTarget(self, order.TargetLocation, Color.Red); + }); self.CancelActivity(); self.QueueActivity(new Move(order.TargetLocation, 0)); @@ -142,7 +149,13 @@ namespace OpenRA.Mods.RA return; if (self.Owner == self.World.LocalPlayer) - self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor))); + self.World.AddFrameEndTask(w => + { + w.Add(new FlashTarget(order.TargetActor)); + var line = self.traits.GetOrDefault(); + if (line != null) + line.SetTarget(self, order.TargetActor, Color.Green); + }); self.CancelActivity(); self.QueueActivity(new DeliverResources()); diff --git a/OpenRA.Mods.RA/Helicopter.cs b/OpenRA.Mods.RA/Helicopter.cs index 551827d33f..6ae4f56263 100644 --- a/OpenRA.Mods.RA/Helicopter.cs +++ b/OpenRA.Mods.RA/Helicopter.cs @@ -15,6 +15,7 @@ using OpenRA.Effects; using OpenRA.Mods.RA.Activities; using OpenRA.Traits; using OpenRA.Traits.Activities; +using System.Drawing; namespace OpenRA.Mods.RA { @@ -74,7 +75,13 @@ namespace OpenRA.Mods.RA if (order.OrderString == "Move") { if (self.Owner == self.World.LocalPlayer) - self.World.AddFrameEndTask(w => w.Add(new MoveFlash(self.World, order.TargetLocation))); + self.World.AddFrameEndTask(w => + { + w.Add(new MoveFlash(self.World, order.TargetLocation)); + var line = self.traits.GetOrDefault(); + if (line != null) + line.SetTarget(self, order.TargetLocation, Color.Green); + }); self.CancelActivity(); self.QueueActivity(new HeliFly(Util.CenterOfCell(order.TargetLocation))); @@ -98,7 +105,13 @@ namespace OpenRA.Mods.RA var offsetVec = offset != null ? new float2(offset[0], offset[1]) : float2.Zero; if (self.Owner == self.World.LocalPlayer) - self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor))); + self.World.AddFrameEndTask(w => + { + w.Add(new FlashTarget(order.TargetActor)); + var line = self.traits.GetOrDefault(); + if (line != null) + line.SetTarget(self, order.TargetActor, Color.Green); + }); self.CancelActivity(); self.QueueActivity(new HeliFly(order.TargetActor.CenterLocation + offsetVec)); diff --git a/OpenRA.Mods.RA/Passenger.cs b/OpenRA.Mods.RA/Passenger.cs index 28784c46aa..f99c7c0fb0 100644 --- a/OpenRA.Mods.RA/Passenger.cs +++ b/OpenRA.Mods.RA/Passenger.cs @@ -12,6 +12,7 @@ using OpenRA.Effects; using OpenRA.Mods.RA.Activities; using OpenRA.Traits; using OpenRA.Traits.Activities; +using System.Drawing; namespace OpenRA.Mods.RA { @@ -67,7 +68,13 @@ namespace OpenRA.Mods.RA if (!CanEnter(self, order.TargetActor)) return; if (self.Owner == self.World.LocalPlayer) - self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor))); + self.World.AddFrameEndTask(w => + { + w.Add(new FlashTarget(order.TargetActor)); + var line = self.traits.GetOrDefault(); + if (line != null) + line.SetTarget(self, order.TargetActor, Color.Green); + }); self.CancelActivity(); self.QueueActivity(new Move(order.TargetActor.Location, 1)); diff --git a/OpenRA.Mods.RA/Plane.cs b/OpenRA.Mods.RA/Plane.cs index b0d7412715..dfb9821d47 100644 --- a/OpenRA.Mods.RA/Plane.cs +++ b/OpenRA.Mods.RA/Plane.cs @@ -13,6 +13,7 @@ using System.Linq; using OpenRA.Effects; using OpenRA.Mods.RA.Activities; using OpenRA.Traits; +using System.Drawing; namespace OpenRA.Mods.RA { @@ -90,7 +91,13 @@ namespace OpenRA.Mods.RA UnReserve(); if (self.Owner == self.World.LocalPlayer) - self.World.AddFrameEndTask(w => w.Add(new MoveFlash(self.World, order.TargetLocation))); + self.World.AddFrameEndTask(w => + { + w.Add(new MoveFlash(self.World, order.TargetLocation)); + var line = self.traits.GetOrDefault(); + if (line != null) + line.SetTarget(self, order.TargetLocation, Color.Green); + }); self.CancelActivity(); self.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation))); @@ -109,8 +116,14 @@ namespace OpenRA.Mods.RA var info = self.Info.Traits.Get(); if (self.Owner == self.World.LocalPlayer) - self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor))); - + self.World.AddFrameEndTask(w => + { + w.Add(new FlashTarget(order.TargetActor)); + var line = self.traits.GetOrDefault(); + if (line != null) + line.SetTarget(self, order.TargetActor, Color.Green); + }); + self.CancelActivity(); self.QueueActivity(new ReturnToBase(self, order.TargetActor)); self.QueueActivity( diff --git a/OpenRA.Mods.RA/Repairable.cs b/OpenRA.Mods.RA/Repairable.cs index 32a7d2d11c..5330b204b3 100644 --- a/OpenRA.Mods.RA/Repairable.cs +++ b/OpenRA.Mods.RA/Repairable.cs @@ -13,6 +13,7 @@ using OpenRA.Mods.RA.Activities; using OpenRA.Effects; using OpenRA.Traits; using OpenRA.Traits.Activities; +using System.Drawing; namespace OpenRA.Mods.RA { @@ -59,7 +60,13 @@ namespace OpenRA.Mods.RA var rp = order.TargetActor.traits.GetOrDefault(); if (self.Owner == self.World.LocalPlayer) - self.World.AddFrameEndTask(w => w.Add(new FlashTarget(order.TargetActor))); + self.World.AddFrameEndTask(w => + { + w.Add(new FlashTarget(order.TargetActor)); + var line = self.traits.GetOrDefault(); + if (line != null) + line.SetTarget(self, order.TargetActor, Color.Green); + }); self.CancelActivity(); self.QueueActivity(new Move(Util.CellContaining(order.TargetActor.CenterLocation), order.TargetActor)); diff --git a/mods/cnc/defaults.yaml b/mods/cnc/defaults.yaml index 2992e59599..ea398abbd0 100644 --- a/mods/cnc/defaults.yaml +++ b/mods/cnc/defaults.yaml @@ -15,6 +15,7 @@ RevealsShroud: GainsExperience: GivesExperience: + DrawLineToTarget: ^Tank: Category: Vehicle @@ -34,6 +35,7 @@ RevealsShroud: GainsExperience: GivesExperience: + DrawLineToTarget: ^Helicopter: Category: Plane @@ -49,6 +51,7 @@ TerrainTypes: Clear, Rough, Road, Tree, Water, Rock, Wall, Ore, Beach, River TerrainSpeeds: 100%, 100%, 100%, 100%, 100%, 100%, 100%, 100%, 100%, 100% AvoidsAA: + DrawLineToTarget: ^Infantry: Category: Infantry @@ -69,6 +72,7 @@ GainsExperience: GivesExperience: # SharesCell: + DrawLineToTarget: ^Plane: Category: Plane @@ -80,6 +84,7 @@ RevealsShroud: GainsExperience: GivesExperience: + DrawLineToTarget: ^Building: Category: Building diff --git a/mods/ra/defaults.yaml b/mods/ra/defaults.yaml index aeb974dc42..95b3acb689 100644 --- a/mods/ra/defaults.yaml +++ b/mods/ra/defaults.yaml @@ -16,6 +16,7 @@ RevealsShroud: GainsExperience: GivesExperience: + DrawLineToTarget: ^Tank: Category: Vehicle @@ -35,6 +36,7 @@ RevealsShroud: GainsExperience: GivesExperience: + DrawLineToTarget: ^Infantry: Category: Infantry @@ -55,6 +57,7 @@ TeslaInstantKills: GainsExperience: GivesExperience: + DrawLineToTarget: ^Ship: Category: Ship @@ -68,6 +71,7 @@ RevealsShroud: GainsExperience: GivesExperience: + DrawLineToTarget: ^Plane: Category: Plane @@ -79,6 +83,7 @@ RevealsShroud: GainsExperience: GivesExperience: + DrawLineToTarget: ^Building: Category: Building