From 584a6b2e75f4d7afb6ebdf357adc7e31c3d795b9 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Wed, 10 Dec 2014 22:56:46 +0100 Subject: [PATCH] Splits AttackMove into trait and activity. Moves them to subfolders/namespaces accordingly. --- OpenRA.Mods.RA/Activities/Air/TakeOff.cs | 2 +- .../Activities/AttackMoveActivity.cs | 82 +++++++++++++++++++ OpenRA.Mods.RA/Activities/Hunt.cs | 2 +- OpenRA.Mods.RA/Attack/AttackWander.cs | 1 + OpenRA.Mods.RA/Guard.cs | 3 +- OpenRA.Mods.RA/Move/Move.cs | 1 + OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 5 +- OpenRA.Mods.RA/Production.cs | 3 +- .../Scripting/Properties/CombatProperties.cs | 5 +- OpenRA.Mods.RA/{ => Traits}/AttackMove.cs | 68 +-------------- 10 files changed, 98 insertions(+), 74 deletions(-) create mode 100644 OpenRA.Mods.RA/Activities/AttackMoveActivity.cs rename OpenRA.Mods.RA/{ => Traits}/AttackMove.cs (58%) diff --git a/OpenRA.Mods.RA/Activities/Air/TakeOff.cs b/OpenRA.Mods.RA/Activities/Air/TakeOff.cs index 85d53dbce3..157b498f07 100644 --- a/OpenRA.Mods.RA/Activities/Air/TakeOff.cs +++ b/OpenRA.Mods.RA/Activities/Air/TakeOff.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA.Activities var destination = rp != null ? rp.Location : (hasHost ? self.World.Map.CellContaining(host.CenterPosition) : self.Location); - return new AttackMove.AttackMoveActivity(self, self.Trait().MoveTo(destination, 1)); + return new AttackMoveActivity(self, self.Trait().MoveTo(destination, 1)); } } } diff --git a/OpenRA.Mods.RA/Activities/AttackMoveActivity.cs b/OpenRA.Mods.RA/Activities/AttackMoveActivity.cs new file mode 100644 index 0000000000..1fd70bb875 --- /dev/null +++ b/OpenRA.Mods.RA/Activities/AttackMoveActivity.cs @@ -0,0 +1,82 @@ +#region Copyright & License Information +/* + * Copyright 2007-2014 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 COPYING. + */ +#endregion + +using System.Collections.Generic; +using OpenRA.Mods.RA.Move; +using OpenRA.Mods.RA.Traits; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA.Activities +{ + public class AttackMoveActivity : Activity + { + const int ScanInterval = 7; + + int scanTicks; + bool hasMoved; + Activity inner; + AutoTarget autoTarget; + + public AttackMoveActivity(Actor self, Activity inner) + { + this.inner = inner; + autoTarget = self.TraitOrDefault(); + hasMoved = false; + } + + public override Activity Tick(Actor self) + { + if (autoTarget != null) + { + // If the actor hasn't moved since the activity was issued + if (!hasMoved) + autoTarget.ResetScanTimer(); + + if (--scanTicks <= 0) + { + var attackActivity = autoTarget.ScanAndAttack(self); + if (attackActivity != null) + { + if (!hasMoved) + return attackActivity; + + self.QueueActivity(false, attackActivity); + } + scanTicks = ScanInterval; + } + } + + hasMoved = true; + + if (inner == null) + return NextActivity; + + inner = Util.RunActivity(self, inner); + + return this; + } + + public override void Cancel(Actor self) + { + if (inner != null) + inner.Cancel(self); + + base.Cancel(self); + } + + public override IEnumerable GetTargets(Actor self) + { + if (inner != null) + return inner.GetTargets(self); + + return Target.None; + } + } +} diff --git a/OpenRA.Mods.RA/Activities/Hunt.cs b/OpenRA.Mods.RA/Activities/Hunt.cs index a4352b5de9..69d2a78feb 100644 --- a/OpenRA.Mods.RA/Activities/Hunt.cs +++ b/OpenRA.Mods.RA/Activities/Hunt.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Activities return this; return Util.SequenceActivities( - new AttackMove.AttackMoveActivity(self, new Move.Move(self, target.Location, WRange.FromCells(2))), + new AttackMoveActivity(self, new Move.Move(self, target.Location, WRange.FromCells(2))), new Wait(25), this); } diff --git a/OpenRA.Mods.RA/Attack/AttackWander.cs b/OpenRA.Mods.RA/Attack/AttackWander.cs index a3f96f7983..bb173f1509 100644 --- a/OpenRA.Mods.RA/Attack/AttackWander.cs +++ b/OpenRA.Mods.RA/Attack/AttackWander.cs @@ -8,6 +8,7 @@ */ #endregion +using OpenRA.Mods.RA.Traits; using OpenRA.Traits; namespace OpenRA.Mods.RA diff --git a/OpenRA.Mods.RA/Guard.cs b/OpenRA.Mods.RA/Guard.cs index c5efd43180..96b24c002f 100644 --- a/OpenRA.Mods.RA/Guard.cs +++ b/OpenRA.Mods.RA/Guard.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using OpenRA.Graphics; +using OpenRA.Mods.RA.Activities; using OpenRA.Traits; namespace OpenRA.Mods.RA @@ -36,7 +37,7 @@ namespace OpenRA.Mods.RA self.SetTargetLine(target, Color.Yellow); var range = WRange.FromCells(target.Actor.Info.Traits.Get().Range); - self.QueueActivity(false, new AttackMove.AttackMoveActivity(self, self.Trait().MoveFollow(self, target, WRange.Zero, range))); + self.QueueActivity(false, new AttackMoveActivity(self, self.Trait().MoveFollow(self, target, WRange.Zero, range))); } public string VoicePhraseForOrder(Actor self, Order order) diff --git a/OpenRA.Mods.RA/Move/Move.cs b/OpenRA.Mods.RA/Move/Move.cs index b974c6f7e9..7e0073fb94 100644 --- a/OpenRA.Mods.RA/Move/Move.cs +++ b/OpenRA.Mods.RA/Move/Move.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using OpenRA.Mods.RA.Activities; +using OpenRA.Mods.RA.Traits; using OpenRA.Primitives; using OpenRA.Traits; diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index c67ec758cc..c7542fea3a 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -99,6 +99,7 @@ + @@ -141,7 +142,7 @@ - + @@ -494,4 +495,4 @@ copy "FuzzyLogicLibrary.dll" "$(SolutionDir)" cd "$(SolutionDir)" - \ No newline at end of file + diff --git a/OpenRA.Mods.RA/Production.cs b/OpenRA.Mods.RA/Production.cs index 94a9b3f573..78b239b3b9 100755 --- a/OpenRA.Mods.RA/Production.cs +++ b/OpenRA.Mods.RA/Production.cs @@ -13,6 +13,7 @@ using System.Drawing; using System.Linq; using OpenRA.Mods.Common; using OpenRA.Mods.Common.Traits; +using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Move; using OpenRA.Mods.RA.Traits; using OpenRA.Primitives; @@ -89,7 +90,7 @@ namespace OpenRA.Mods.RA if (exitinfo.MoveIntoWorld) { newUnit.QueueActivity(move.MoveIntoWorld(newUnit, exit)); - newUnit.QueueActivity(new AttackMove.AttackMoveActivity( + newUnit.QueueActivity(new AttackMoveActivity( newUnit, move.MoveTo(exitLocation, 1))); } } diff --git a/OpenRA.Mods.RA/Scripting/Properties/CombatProperties.cs b/OpenRA.Mods.RA/Scripting/Properties/CombatProperties.cs index 6f864728e8..6e355f9389 100644 --- a/OpenRA.Mods.RA/Scripting/Properties/CombatProperties.cs +++ b/OpenRA.Mods.RA/Scripting/Properties/CombatProperties.cs @@ -12,6 +12,7 @@ using Eluant; using System; using System.Linq; using OpenRA.Mods.RA.Activities; +using OpenRA.Mods.RA.Traits; using OpenRA.Scripting; using OpenRA.Traits; @@ -41,7 +42,7 @@ namespace OpenRA.Mods.RA.Scripting "close enough to complete the activity.")] public void AttackMove(CPos cell, int closeEnough = 0) { - self.QueueActivity(new AttackMove.AttackMoveActivity(self, move.MoveTo(cell, closeEnough))); + self.QueueActivity(new AttackMoveActivity(self, move.MoveTo(cell, closeEnough))); } [ScriptActorPropertyActivity] @@ -51,7 +52,7 @@ namespace OpenRA.Mods.RA.Scripting { foreach (var wpt in waypoints) { - self.QueueActivity(new AttackMove.AttackMoveActivity(self, move.MoveTo(wpt, 2))); + self.QueueActivity(new AttackMoveActivity(self, move.MoveTo(wpt, 2))); self.QueueActivity(new Wait(wait)); } diff --git a/OpenRA.Mods.RA/AttackMove.cs b/OpenRA.Mods.RA/Traits/AttackMove.cs similarity index 58% rename from OpenRA.Mods.RA/AttackMove.cs rename to OpenRA.Mods.RA/Traits/AttackMove.cs index ed0fd3cb09..8be8e7b75d 100644 --- a/OpenRA.Mods.RA/AttackMove.cs +++ b/OpenRA.Mods.RA/Traits/AttackMove.cs @@ -10,9 +10,10 @@ using System.Collections.Generic; using System.Drawing; +using OpenRA.Mods.RA.Activities; using OpenRA.Traits; -namespace OpenRA.Mods.RA +namespace OpenRA.Mods.RA.Traits { [Desc("Provides access to the attack-move command, which will make the actor automatically engage viable targets while moving to the destination.")] class AttackMoveInfo : ITraitInfo @@ -63,70 +64,5 @@ namespace OpenRA.Mods.RA Activate(self); } } - - public class AttackMoveActivity : Activity - { - const int ScanInterval = 7; - - int scanTicks; - bool hasMoved; - Activity inner; - AutoTarget autoTarget; - - public AttackMoveActivity(Actor self, Activity inner) - { - this.inner = inner; - autoTarget = self.TraitOrDefault(); - hasMoved = false; - } - - public override Activity Tick(Actor self) - { - if (autoTarget != null) - { - // If the actor hasn't moved since the activity was issued - if (!hasMoved) - autoTarget.ResetScanTimer(); - - if (--scanTicks <= 0) - { - var attackActivity = autoTarget.ScanAndAttack(self); - if (attackActivity != null) - { - if (!hasMoved) - return attackActivity; - - self.QueueActivity(false, attackActivity); - } - scanTicks = ScanInterval; - } - } - - hasMoved = true; - - if (inner == null) - return NextActivity; - - inner = Util.RunActivity(self, inner); - - return this; - } - - public override void Cancel(Actor self) - { - if (inner != null) - inner.Cancel(self); - - base.Cancel(self); - } - - public override IEnumerable GetTargets(Actor self) - { - if (inner != null) - return inner.GetTargets(self); - - return Target.None; - } - } } }