make order queuing work for buildings and turreted units, too
This commit is contained in:
@@ -24,9 +24,10 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
class AttackTurreted : AttackBase, INotifyBuildComplete
|
||||
{
|
||||
protected Target target;
|
||||
public AttackTurreted(Actor self) : base(self) { }
|
||||
|
||||
protected override bool CanAttack( Actor self )
|
||||
protected override bool CanAttack( Actor self, Target target )
|
||||
{
|
||||
if( self.HasTrait<Building>() && !buildComplete )
|
||||
return false;
|
||||
@@ -37,7 +38,7 @@ namespace OpenRA.Mods.RA
|
||||
if( turreted.desiredFacing != turreted.turretFacing )
|
||||
return false;
|
||||
|
||||
return base.CanAttack( self );
|
||||
return base.CanAttack( self, target );
|
||||
}
|
||||
|
||||
public override void Tick(Actor self)
|
||||
@@ -56,26 +57,27 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
class AttackActivity : CancelableActivity
|
||||
{
|
||||
readonly Target newTarget;
|
||||
public AttackActivity( Target newTarget ) { this.newTarget = newTarget; }
|
||||
readonly Target target;
|
||||
public AttackActivity( Target newTarget ) { this.target = newTarget; }
|
||||
|
||||
public override IActivity Tick( Actor self )
|
||||
{
|
||||
if( IsCanceled ) return NextActivity;
|
||||
if( IsCanceled || !target.IsValid ) return NextActivity;
|
||||
|
||||
if (self.TraitsImplementing<IDisable>().Any(d => d.Disabled))
|
||||
return this;
|
||||
|
||||
var attack = self.Trait<AttackTurreted>();
|
||||
const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */
|
||||
var weapon = attack.ChooseWeaponForTarget(newTarget);
|
||||
var weapon = attack.ChooseWeaponForTarget(target);
|
||||
if (weapon != null)
|
||||
{
|
||||
attack.target = newTarget;
|
||||
attack.target = target;
|
||||
|
||||
if (self.HasTrait<Mobile>() && !self.Info.Traits.Get<MobileInfo>().OnRails)
|
||||
self.QueueActivity( new Follow( newTarget,
|
||||
Math.Max( 0, (int)weapon.Info.Range - RangeTolerance ) ) );
|
||||
return Util.SequenceActivities(
|
||||
new Follow( target, Math.Max( 0, (int)weapon.Info.Range - RangeTolerance ) ),
|
||||
this );
|
||||
}
|
||||
return NextActivity;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user