Revise AttackMoveActivity.

This commit is contained in:
tovl
2019-03-09 16:06:03 +01:00
committed by Oliver Brakmann
parent 01f6f98097
commit 64cec4a0ad
10 changed files with 82 additions and 65 deletions

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
@@ -18,31 +19,75 @@ namespace OpenRA.Mods.Common.Activities
{
public class AttackMoveActivity : Activity
{
const int ScanInterval = 7;
readonly Func<Activity> getInner;
public readonly bool IsAssaultMove;
Activity inner;
int scanTicks;
Activity attack;
AutoTarget autoTarget;
bool moving;
public AttackMoveActivity(Actor self, Activity inner)
public AttackMoveActivity(Actor self, Func<Activity> getInner, bool assaultMoving = false)
{
this.inner = inner;
this.getInner = getInner;
autoTarget = self.TraitOrDefault<AutoTarget>();
moving = false;
IsAssaultMove = assaultMoving;
}
public override Activity Tick(Actor self)
{
if (autoTarget != null && --scanTicks <= 0)
if (IsCanceling)
{
autoTarget.ScanAndAttack(self, true);
scanTicks = ScanInterval;
if (attack != null)
{
attack = ActivityUtils.RunActivity(self, attack);
return this;
}
if (inner != null)
{
inner = ActivityUtils.RunActivity(self, inner);
return this;
}
return NextActivity;
}
if (attack == null && autoTarget != null)
{
var target = autoTarget.ScanForTarget(self, true);
if (target.Type != TargetType.Invalid)
{
if (inner != null)
inner.Cancel(self);
var attackBases = autoTarget.ActiveAttackBases;
foreach (var ab in attackBases)
{
if (attack == null)
attack = ab.GetAttackActivity(self, target, true, false);
else
attack = ActivityUtils.SequenceActivities(self, attack, ab.GetAttackActivity(self, target, true, false));
ab.OnQueueAttackActivity(self, target, false, true, false);
}
moving = false;
}
}
if (attack == null && inner == null)
{
if (moving)
return NextActivity;
inner = getInner();
moving = true;
}
if (inner == null)
return NextActivity;
attack = ActivityUtils.RunActivity(self, attack);
inner = ActivityUtils.RunActivity(self, inner);
return this;
}
@@ -51,6 +96,9 @@ namespace OpenRA.Mods.Common.Activities
if (!IsCanceling && inner != null)
inner.Cancel(self);
if (!IsCanceling && attack != null)
attack.Cancel(self);
base.Cancel(self, keepQueue);
}