From 5d408fe3c7154a73895faa45c8a4ad312cdf46e7 Mon Sep 17 00:00:00 2001 From: Bob Date: Sun, 24 Oct 2010 02:06:07 +1300 Subject: [PATCH] make AttackMove use an activity --- OpenRA.Mods.RA/Activities/FlyAttack.cs | 4 +- OpenRA.Mods.RA/AttackMove.cs | 52 +++++++++++++++----------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/OpenRA.Mods.RA/Activities/FlyAttack.cs b/OpenRA.Mods.RA/Activities/FlyAttack.cs index 43d2d8aa9d..2c31128714 100644 --- a/OpenRA.Mods.RA/Activities/FlyAttack.cs +++ b/OpenRA.Mods.RA/Activities/FlyAttack.cs @@ -29,10 +29,10 @@ namespace OpenRA.Mods.RA.Activities self.Trait().DoAttack( self, Target ); - if( IsCanceled && inner == null ) return NextActivity; - if( inner == null ) { + if( IsCanceled ) + return NextActivity; inner = Util.SequenceActivities( Fly.ToPx(Target.CenterLocation), new FlyTimed(50)); diff --git a/OpenRA.Mods.RA/AttackMove.cs b/OpenRA.Mods.RA/AttackMove.cs index 77ae56e5eb..91f2f4af36 100644 --- a/OpenRA.Mods.RA/AttackMove.cs +++ b/OpenRA.Mods.RA/AttackMove.cs @@ -20,10 +20,8 @@ namespace OpenRA.Mods.RA public readonly bool JustMove = false; } - class AttackMove : ITick, IResolveOrder, IOrderVoice + class AttackMove : IResolveOrder, IOrderVoice { - public bool AttackMoving { get; set; } - public string VoicePhraseForOrder(Actor self, Order order) { if (order.OrderString == "AttackMove") @@ -38,12 +36,10 @@ namespace OpenRA.Mods.RA { self.CancelActivity(); //if we are just moving, we don't turn on attackmove and this becomes a regular move order - if (!self.Info.Traits.Get().JustMove) - { - AttackMoving = true; - } - Order newOrder = new Order("Move", order.Subject, order.TargetLocation); - self.Trait().ResolveOrder(self, newOrder); + if (self.Info.Traits.Get().JustMove) + self.QueueActivity( self.Trait().MoveTo( order.TargetLocation, 1 )); + else + self.QueueActivity( new AttackMoveActivity(order.TargetLocation)); if (self.Owner == self.World.LocalPlayer) self.World.AddFrameEndTask(w => @@ -58,23 +54,35 @@ namespace OpenRA.Mods.RA else line.SetTarget(self, Target.FromOrder(order), Color.Red); }); } - else - { - AttackMoving = false; //cancel attack move state for other orders - } } - public void Tick(Actor self) + class AttackMoveActivity : CancelableActivity { - if (self.Info.Traits.Get().JustMove) return; - if (!self.HasTrait()) - { - Game.Debug("AttackMove: {0} has no AttackBase trait".F(self.ToString())); - return; - } - if (!self.IsIdle && (self.HasTrait() && !(self.Trait().AttackMoving))) return; + readonly int2 target; + IActivity inner; + public AttackMoveActivity( int2 target ) { this.target = target; } - self.Trait().ScanAndAttack(self, true); + public override IActivity Tick( Actor self ) + { + self.Trait().ScanAndAttack(self, true); + + if( inner == null ) + { + if( IsCanceled ) + return NextActivity; + inner = self.Trait().MoveTo( target, 1 ); + } + inner = inner.Tick( self ); + return this; + } + + protected override bool OnCancel( Actor self ) + { + if( inner != null ) + inner.Cancel( self ); + return base.OnCancel( self ); + } } + } }