From 53db5eb4911bddf3f5288685a27205148ea15693 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Mon, 9 Nov 2009 18:53:06 +1300 Subject: [PATCH] stripped dead code from move; added rally point support --- OpenRa.Game/Controller.cs | 2 +- OpenRa.Game/OpenRa.Game.csproj | 1 + OpenRa.Game/Order.cs | 5 ++++ OpenRa.Game/Traits/Activities/Move.cs | 25 +++--------------- OpenRa.Game/Traits/RallyPoint.cs | 38 +++++++++++++++++++++++++++ OpenRa.Game/UnitOrders.cs | 6 +++++ sequences.xml | 3 +++ units.ini | 2 +- 8 files changed, 58 insertions(+), 24 deletions(-) create mode 100644 OpenRa.Game/Traits/RallyPoint.cs diff --git a/OpenRa.Game/Controller.cs b/OpenRa.Game/Controller.cs index f82e68ca83..21aae21331 100644 --- a/OpenRa.Game/Controller.cs +++ b/OpenRa.Game/Controller.cs @@ -25,7 +25,7 @@ namespace OpenRa.Game if (order.Subject != null && order.Player == Game.LocalPlayer) doVoice = order.Subject; } - if (doVoice != null) + if (doVoice != null && doVoice.traits.Contains()) Game.PlaySound(Game.SovietVoices.First.GetNext() + GetVoiceSuffix(doVoice), false); } diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 36dddba6b3..09dd890e54 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -144,6 +144,7 @@ + diff --git a/OpenRa.Game/Order.cs b/OpenRa.Game/Order.cs index 1ee5847d00..184a4f71f9 100644 --- a/OpenRa.Game/Order.cs +++ b/OpenRa.Game/Order.cs @@ -133,5 +133,10 @@ namespace OpenRa.Game { return new Order( subject, "CancelProduction", null, null, int2.Zero, item, Cursor.Default ); } + + public static Order SetRallyPoint(Actor subject, int2 target) + { + return new Order(subject.Owner, "SetRallyPoint", subject, null, target, null, Cursor.Move); + } } } diff --git a/OpenRa.Game/Traits/Activities/Move.cs b/OpenRa.Game/Traits/Activities/Move.cs index 8cca93d5cb..c1c55245c0 100755 --- a/OpenRa.Game/Traits/Activities/Move.cs +++ b/OpenRa.Game/Traits/Activities/Move.cs @@ -116,31 +116,12 @@ namespace OpenRa.Game.Traits.Activities Game.UnitInfluence.Remove( mobile ); var newPath = getPath(self, mobile).TakeWhile(a => a != self.Location).ToList(); - //var newPath = Game.PathFinder.FindPathToPath( self.Location, path, mobile.GetMovementType() ) - // .TakeWhile( a => a != self.Location ) - // .ToList(); + Game.UnitInfluence.Add( mobile ); - if (newPath.Count == 0) - return null; - else - { + if (newPath.Count != 0) path = newPath; - return null; - } - //while( path.Count != 0 && path[ path.Count - 1 ] != newPath[ 0 ] ) - // path.RemoveAt( path.Count - 1 ); - //for( int i = 1 ; i < newPath.Count ; i++ ) - // path.Add( newPath[ i ] ); - - if( path.Count == 0 ) - return null; - nextCell = path[ path.Count - 1 ]; - if( !CanEnterCell( nextCell, self ) ) - { - path.Clear(); - return null; - } + return null; } path.RemoveAt( path.Count - 1 ); return nextCell; diff --git a/OpenRa.Game/Traits/RallyPoint.cs b/OpenRa.Game/Traits/RallyPoint.cs new file mode 100644 index 0000000000..22c1b0d63a --- /dev/null +++ b/OpenRa.Game/Traits/RallyPoint.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using IjwFramework.Types; +using OpenRa.Game.Graphics; + +namespace OpenRa.Game.Traits +{ + class RallyPoint : IRender, IOrder, ITick + { + public int2 rallyPoint; + public Animation anim; + + public RallyPoint(Actor self) + { + rallyPoint = self.Location + new int2(1, 3); //self.unitInfo.RallyPoint; + anim = new Animation("flagfly"); + anim.PlayRepeating("idle"); + } + + public IEnumerable> Render(Actor self) + { + var uog = Game.controller.orderGenerator as UnitOrderGenerator; + if (uog != null && self.Owner == Game.LocalPlayer && uog.selection.Contains(self)) + yield return Util.Centered( + anim.Image, Game.CellSize * (new float2(.5f, .5f) + rallyPoint.ToFloat2())); + } + + public Order Order(Actor self, int2 xy, bool lmb, Actor underCursor) + { + if (lmb || underCursor != null) return null; + return OpenRa.Game.Order.SetRallyPoint(self, xy); + } + + public void Tick(Actor self) { anim.Tick(); } + } +} diff --git a/OpenRa.Game/UnitOrders.cs b/OpenRa.Game/UnitOrders.cs index 95ea9bdf6b..577dc58f35 100755 --- a/OpenRa.Game/UnitOrders.cs +++ b/OpenRa.Game/UnitOrders.cs @@ -123,6 +123,12 @@ namespace OpenRa.Game order.Player.CancelProduction( Rules.UnitCategory[ order.TargetString ] ); break; } + case "SetRallyPoint": + { + var pt = order.Subject.traits.Get(); + pt.rallyPoint = order.TargetLocation; + break; + } default: throw new NotImplementedException(); } diff --git a/sequences.xml b/sequences.xml index 789edd2a4f..078f0152ee 100644 --- a/sequences.xml +++ b/sequences.xml @@ -507,4 +507,7 @@ + + + \ No newline at end of file diff --git a/units.ini b/units.ini index 2a4dbdcf59..e28bcdb3b4 100755 --- a/units.ini +++ b/units.ini @@ -204,7 +204,7 @@ Dimensions=2,2 Footprint=xx xx [WEAP] Description=War Factory -Traits=Building, RenderWarFactory +Traits=Building, RenderWarFactory, RallyPoint Dimensions=3,2 Footprint=xxx xxx Produces=Vehicle