add Util.RunActivity, and have Actor.Tick use it. fix medic autoheal
This commit is contained in:
@@ -69,27 +69,11 @@ namespace OpenRA
|
||||
public void Tick()
|
||||
{
|
||||
var wasIdle = currentActivity is Idle;
|
||||
while (currentActivity != null)
|
||||
{
|
||||
var a = currentActivity;
|
||||
currentActivity = Util.RunActivity( this, currentActivity ) ?? new Idle();
|
||||
|
||||
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;
|
||||
|
||||
if (currentActivity is Idle)
|
||||
{
|
||||
if (!wasIdle)
|
||||
if (currentActivity is Idle && !wasIdle)
|
||||
foreach (var ni in TraitsImplementing<INotifyIdle>())
|
||||
ni.Idle(this);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsIdle
|
||||
|
||||
@@ -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(); }
|
||||
|
||||
@@ -17,18 +17,15 @@ namespace OpenRA.Mods.RA.Activities
|
||||
public class QueuedActivity : IActivity
|
||||
{
|
||||
public QueuedActivity(Action<QueuedActivity> a) { this.a = a; }
|
||||
public QueuedActivity(bool runChildOnFirstTick, Action<QueuedActivity> a) : this(a, true, runChildOnFirstTick) { }
|
||||
|
||||
public QueuedActivity(Action<QueuedActivity> a, bool interruptable, bool runChildOnFirstTick)
|
||||
public QueuedActivity(Action<QueuedActivity> a, bool interruptable)
|
||||
{
|
||||
this.a = a;
|
||||
this.interruptable = interruptable;
|
||||
runChildOnFirstTick = runChildOnFirstTick;
|
||||
}
|
||||
|
||||
Action<QueuedActivity> 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;
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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); }
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace OpenRA.Mods.RA
|
||||
return NextActivity;
|
||||
inner = self.Trait<Mobile>().MoveTo( target, 1 );
|
||||
}
|
||||
inner = inner.Tick( self );
|
||||
inner = Util.RunActivity( self, inner );
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA
|
||||
timeToRecharge = self.Info.Traits.Get<AttackTeslaInfo>().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 );
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -27,8 +27,11 @@ namespace OpenRA.Mods.RA
|
||||
class IdleHealActivity : Idle
|
||||
{
|
||||
Actor currentTarget;
|
||||
IActivity inner;
|
||||
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if( inner == null )
|
||||
{
|
||||
if( NextActivity != null )
|
||||
return NextActivity;
|
||||
@@ -37,19 +40,20 @@ namespace OpenRA.Mods.RA
|
||||
var range = attack.GetMaximumRange();
|
||||
|
||||
if (NeedsNewTarget(self))
|
||||
AttackTarget(self, ChooseTarget(self, range));
|
||||
|
||||
return this;
|
||||
{
|
||||
currentTarget = ChooseTarget(self, range);
|
||||
if( currentTarget != null )
|
||||
inner = self.Trait<AttackBase>().GetAttackActivity(self, Target.FromActor( currentTarget ), false );
|
||||
}
|
||||
}
|
||||
if( inner != null )
|
||||
{
|
||||
if( currentTarget.GetDamageState() == DamageState.Undamaged )
|
||||
inner.Cancel( self );
|
||||
inner = Util.RunActivity( self, inner );
|
||||
}
|
||||
|
||||
void AttackTarget(Actor self, Actor target)
|
||||
{
|
||||
var attack = self.Trait<AttackBase>();
|
||||
if (target != null)
|
||||
attack.AttackTarget(Target.FromActor( target), false, true );
|
||||
else
|
||||
if (attack.IsAttacking)
|
||||
self.CancelActivity();
|
||||
return this;
|
||||
}
|
||||
|
||||
bool NeedsNewTarget(Actor self)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -259,8 +259,8 @@ MEDI:
|
||||
-AutoTarget:
|
||||
AttackMove:
|
||||
JustMove: true
|
||||
IdleAnimation:
|
||||
Animations: idle1,idle2
|
||||
# IdleAnimation:
|
||||
# Animations: idle1,idle2
|
||||
|
||||
C1:
|
||||
Inherits: ^Infantry
|
||||
|
||||
Reference in New Issue
Block a user