diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 20c0dd0fe5..7b03e27de2 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -68,28 +68,12 @@ namespace OpenRA public void Tick() { - var wasIdle = currentActivity is Idle; - while (currentActivity != null) - { - var a = currentActivity; - - var sw = new Stopwatch(); - currentActivity = a.Tick(this) ?? new Idle(); - var dt = sw.ElapsedTime(); - if(dt > Game.Settings.Debug.LongTickThreshold) - Log.Write("perf", "[{2}] Activity: {0} ({1:0.000} ms)", a, dt * 1000, Game.LocalTick); - - if (a == currentActivity) break; + var wasIdle = currentActivity is Idle; + currentActivity = Util.RunActivity( this, currentActivity ) ?? new Idle(); - if (currentActivity is Idle) - { - if (!wasIdle) - foreach (var ni in TraitsImplementing()) - ni.Idle(this); - - break; - } - } + if (currentActivity is Idle && !wasIdle) + foreach (var ni in TraitsImplementing()) + ni.Idle(this); } public bool IsIdle diff --git a/OpenRA.Game/Traits/Util.cs b/OpenRA.Game/Traits/Util.cs index b39367255d..004477ec4a 100755 --- a/OpenRA.Game/Traits/Util.cs +++ b/OpenRA.Game/Traits/Util.cs @@ -12,6 +12,7 @@ using System; using System.Drawing; using System.Linq; using OpenRA.Graphics; +using OpenRA.Support; namespace OpenRA.Traits { @@ -115,6 +116,24 @@ namespace OpenRA.Traits (next, a) => { a.Queue( next ); return a; }); } + public static IActivity RunActivity( Actor self, IActivity act ) + { + while( act != null ) + { + var prev = act; + + var sw = new Stopwatch(); + act = act.Tick( self ); + var dt = sw.ElapsedTime(); + if(dt > Game.Settings.Debug.LongTickThreshold) + Log.Write("perf", "[{2}] Activity: {0} ({1:0.000} ms)", prev, dt * 1000, Game.LocalTick); + + if( prev == act ) + break; + } + return act; + } + public static Color ArrayToColor(int[] x) { return Color.FromArgb(x[0], x[1], x[2]); } public static int2 CellContaining(float2 pos) { return (1f / Game.CellSize * pos).ToInt2(); } diff --git a/OpenRA.Mods.RA/Activities/QueuedActivity.cs b/OpenRA.Mods.RA/Activities/QueuedActivity.cs index 37cef3dc9a..e67d58cf7a 100644 --- a/OpenRA.Mods.RA/Activities/QueuedActivity.cs +++ b/OpenRA.Mods.RA/Activities/QueuedActivity.cs @@ -17,18 +17,15 @@ namespace OpenRA.Mods.RA.Activities public class QueuedActivity : IActivity { public QueuedActivity(Action a) { this.a = a; } - public QueuedActivity(bool runChildOnFirstTick, Action a) : this(a, true, runChildOnFirstTick) { } - public QueuedActivity(Action a, bool interruptable, bool runChildOnFirstTick) + public QueuedActivity(Action a, bool interruptable) { this.a = a; this.interruptable = interruptable; - runChildOnFirstTick = runChildOnFirstTick; } Action a; private bool interruptable = true; - private bool runChild = false; public IActivity NextActivity { get; set; } public IActivity Tick(Actor self) { return Run(self); } @@ -37,8 +34,6 @@ namespace OpenRA.Mods.RA.Activities { if (a != null) a(this); - if (runChild && NextActivity != null) - return NextActivity.Tick(self); return NextActivity; } diff --git a/OpenRA.Mods.RA/Air/AttackHeli.cs b/OpenRA.Mods.RA/Air/AttackHeli.cs index d95665fc9b..27a3b85915 100755 --- a/OpenRA.Mods.RA/Air/AttackHeli.cs +++ b/OpenRA.Mods.RA/Air/AttackHeli.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Air { public AttackHeli(Actor self, AttackHeliInfo info) : base(self, info) { } - protected override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) + public override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) { return new HeliAttack( newTarget ); } diff --git a/OpenRA.Mods.RA/Air/AttackPlane.cs b/OpenRA.Mods.RA/Air/AttackPlane.cs index ee8500156d..04933fb4ce 100755 --- a/OpenRA.Mods.RA/Air/AttackPlane.cs +++ b/OpenRA.Mods.RA/Air/AttackPlane.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Air { public AttackPlane(Actor self, AttackPlaneInfo info) : base(self, info) { } - protected override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) + public override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) { return new FlyAttack( newTarget ); } diff --git a/OpenRA.Mods.RA/Air/FlyAttack.cs b/OpenRA.Mods.RA/Air/FlyAttack.cs index 8938e67a10..ef1aaeeeb0 100755 --- a/OpenRA.Mods.RA/Air/FlyAttack.cs +++ b/OpenRA.Mods.RA/Air/FlyAttack.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Air Fly.ToPx(Target.CenterLocation), new FlyTimed(50)); } - inner = inner.Tick( self ); + inner = Util.RunActivity( self, inner ); return this; } diff --git a/OpenRA.Mods.RA/AttackBase.cs b/OpenRA.Mods.RA/AttackBase.cs index 32a5c581b8..4c2a150d99 100644 --- a/OpenRA.Mods.RA/AttackBase.cs +++ b/OpenRA.Mods.RA/AttackBase.cs @@ -165,7 +165,7 @@ namespace OpenRA.Mods.RA return (order.OrderString == "Attack" || order.OrderString == "AttackHold") ? "Attack" : null; } - protected abstract IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove); + public abstract IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove); public bool HasAnyValidWeapons(Target t) { return Weapons.Any(w => w.IsValidAgainst(self.World, t)); } public float GetMaximumRange() { return Weapons.Max(w => w.Info.Range); } diff --git a/OpenRA.Mods.RA/AttackFrontal.cs b/OpenRA.Mods.RA/AttackFrontal.cs index 956653d0d6..78f2a47a49 100644 --- a/OpenRA.Mods.RA/AttackFrontal.cs +++ b/OpenRA.Mods.RA/AttackFrontal.cs @@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA return true; } - protected override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) + public override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) { var weapon = ChooseWeaponForTarget(newTarget); if( weapon == null ) diff --git a/OpenRA.Mods.RA/AttackLeap.cs b/OpenRA.Mods.RA/AttackLeap.cs index 07b4ee86b6..e864e8a1bd 100644 --- a/OpenRA.Mods.RA/AttackLeap.cs +++ b/OpenRA.Mods.RA/AttackLeap.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA self.QueueActivity(new Leap(self, target)); } - protected override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) + public override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) { var weapon = ChooseWeaponForTarget(newTarget); if( weapon == null ) diff --git a/OpenRA.Mods.RA/AttackMove.cs b/OpenRA.Mods.RA/AttackMove.cs index 24b7cbb19e..1fb140a071 100644 --- a/OpenRA.Mods.RA/AttackMove.cs +++ b/OpenRA.Mods.RA/AttackMove.cs @@ -89,7 +89,7 @@ namespace OpenRA.Mods.RA return NextActivity; inner = self.Trait().MoveTo( target, 1 ); } - inner = inner.Tick( self ); + inner = Util.RunActivity( self, inner ); return this; } diff --git a/OpenRA.Mods.RA/AttackOmni.cs b/OpenRA.Mods.RA/AttackOmni.cs index cddf62fd8e..b895194c9f 100644 --- a/OpenRA.Mods.RA/AttackOmni.cs +++ b/OpenRA.Mods.RA/AttackOmni.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA return base.CanAttack( self, target ) && !isBuilding; } - protected override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) + public override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) { return new SetTarget( newTarget ); } diff --git a/OpenRA.Mods.RA/AttackTesla.cs b/OpenRA.Mods.RA/AttackTesla.cs index e42a9805a5..e173d8b28d 100644 --- a/OpenRA.Mods.RA/AttackTesla.cs +++ b/OpenRA.Mods.RA/AttackTesla.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA timeToRecharge = self.Info.Traits.Get().ReloadTime; } - protected override IActivity GetAttackActivity( Actor self, Target newTarget, bool allowMove ) + public override IActivity GetAttackActivity( Actor self, Target newTarget, bool allowMove ) { return new TeslaAttack( newTarget ); } diff --git a/OpenRA.Mods.RA/AttackTurreted.cs b/OpenRA.Mods.RA/AttackTurreted.cs index 9c161ef62d..cfaf5e9b81 100644 --- a/OpenRA.Mods.RA/AttackTurreted.cs +++ b/OpenRA.Mods.RA/AttackTurreted.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA DoAttack( self, target ); } - protected override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) + public override IActivity GetAttackActivity(Actor self, Target newTarget, bool allowMove) { return new AttackActivity( newTarget ); } diff --git a/OpenRA.Mods.RA/AutoHeal.cs b/OpenRA.Mods.RA/AutoHeal.cs index 953670e6c5..e63736aecc 100644 --- a/OpenRA.Mods.RA/AutoHeal.cs +++ b/OpenRA.Mods.RA/AutoHeal.cs @@ -27,31 +27,35 @@ namespace OpenRA.Mods.RA class IdleHealActivity : Idle { Actor currentTarget; + IActivity inner; public override IActivity Tick( Actor self ) { - if( NextActivity != null ) - return NextActivity; + if( inner == null ) + { + if( NextActivity != null ) + return NextActivity; - var attack = self.Trait(); - var range = attack.GetMaximumRange(); + var attack = self.Trait(); + var range = attack.GetMaximumRange(); - if (NeedsNewTarget(self)) - AttackTarget(self, ChooseTarget(self, range)); + if (NeedsNewTarget(self)) + { + currentTarget = ChooseTarget(self, range); + if( currentTarget != null ) + inner = self.Trait().GetAttackActivity(self, Target.FromActor( currentTarget ), false ); + } + } + if( inner != null ) + { + if( currentTarget.GetDamageState() == DamageState.Undamaged ) + inner.Cancel( self ); + inner = Util.RunActivity( self, inner ); + } return this; } - void AttackTarget(Actor self, Actor target) - { - var attack = self.Trait(); - if (target != null) - attack.AttackTarget(Target.FromActor( target), false, true ); - else - if (attack.IsAttacking) - self.CancelActivity(); - } - bool NeedsNewTarget(Actor self) { var attack = self.Trait(); diff --git a/OpenRA.Mods.RA/Move/Move.cs b/OpenRA.Mods.RA/Move/Move.cs index 7cfe873ee6..b4236cc740 100755 --- a/OpenRA.Mods.RA/Move/Move.cs +++ b/OpenRA.Mods.RA/Move/Move.cs @@ -137,7 +137,7 @@ namespace OpenRA.Mods.RA.Move if( firstFacing != mobile.Facing ) { path.Add( nextCell.Value ); - return Util.SequenceActivities( new Turn( firstFacing ), this ).Tick( self ); + return Util.SequenceActivities( new Turn( firstFacing ), this ); } else { @@ -150,7 +150,7 @@ namespace OpenRA.Mods.RA.Move mobile.Facing, 0 ); - return move.Tick( self ); + return move; } } diff --git a/mods/ra/rules/infantry.yaml b/mods/ra/rules/infantry.yaml index 81da1ecf83..2458ce03e3 100644 --- a/mods/ra/rules/infantry.yaml +++ b/mods/ra/rules/infantry.yaml @@ -259,8 +259,8 @@ MEDI: -AutoTarget: AttackMove: JustMove: true - IdleAnimation: - Animations: idle1,idle2 +# IdleAnimation: +# Animations: idle1,idle2 C1: Inherits: ^Infantry