add Util.RunActivity, and have Actor.Tick use it. fix medic autoheal
This commit is contained in:
@@ -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,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<AttackBase>();
|
||||
var range = attack.GetMaximumRange();
|
||||
var attack = self.Trait<AttackBase>();
|
||||
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<AttackBase>().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<AttackBase>();
|
||||
if (target != null)
|
||||
attack.AttackTarget(Target.FromActor( target), false, true );
|
||||
else
|
||||
if (attack.IsAttacking)
|
||||
self.CancelActivity();
|
||||
}
|
||||
|
||||
bool NeedsNewTarget(Actor self)
|
||||
{
|
||||
var attack = self.Trait<AttackBase>();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user