Replace pseudo-childactivities in AttackMoveActivity.
This commit is contained in:
@@ -20,92 +20,80 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
public class AttackMoveActivity : Activity
|
public class AttackMoveActivity : Activity
|
||||||
{
|
{
|
||||||
readonly Func<Activity> getInner;
|
readonly Func<Activity> getInner;
|
||||||
public readonly bool IsAssaultMove;
|
readonly bool isAssaultMove;
|
||||||
Activity inner;
|
|
||||||
Activity attack;
|
|
||||||
AutoTarget autoTarget;
|
AutoTarget autoTarget;
|
||||||
bool moving;
|
ConditionManager conditionManager;
|
||||||
|
AttackMove attackMove;
|
||||||
|
int token = ConditionManager.InvalidConditionToken;
|
||||||
|
|
||||||
public AttackMoveActivity(Actor self, Func<Activity> getInner, bool assaultMoving = false)
|
public AttackMoveActivity(Actor self, Func<Activity> getInner, bool assaultMoving = false)
|
||||||
{
|
{
|
||||||
this.getInner = getInner;
|
this.getInner = getInner;
|
||||||
autoTarget = self.TraitOrDefault<AutoTarget>();
|
autoTarget = self.TraitOrDefault<AutoTarget>();
|
||||||
moving = false;
|
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||||
IsAssaultMove = assaultMoving;
|
attackMove = self.TraitOrDefault<AttackMove>();
|
||||||
|
isAssaultMove = assaultMoving;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnFirstRun(Actor self)
|
||||||
|
{
|
||||||
|
// Start moving.
|
||||||
|
QueueChild(self, getInner());
|
||||||
|
|
||||||
|
if (conditionManager == null || attackMove == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!isAssaultMove && !string.IsNullOrEmpty(attackMove.Info.AttackMoveScanCondition))
|
||||||
|
token = conditionManager.GrantCondition(self, attackMove.Info.AttackMoveScanCondition);
|
||||||
|
else if (isAssaultMove && !string.IsNullOrEmpty(attackMove.Info.AssaultMoveScanCondition))
|
||||||
|
token = conditionManager.GrantCondition(self, attackMove.Info.AssaultMoveScanCondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (IsCanceling)
|
// We are not currently attacking a target, so scan for new targets.
|
||||||
{
|
if (!IsCanceling && ChildActivity != null && ChildActivity.NextActivity == null && autoTarget != null)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
|
// ScanForTarget already limits the scanning rate for performance so we don't need to do that here.
|
||||||
var target = autoTarget.ScanForTarget(self, true, true);
|
var target = autoTarget.ScanForTarget(self, true, true);
|
||||||
if (target.Type != TargetType.Invalid)
|
if (target.Type != TargetType.Invalid)
|
||||||
{
|
{
|
||||||
if (inner != null)
|
// We have found a target so cancel the current move activity and queue attack activities.
|
||||||
inner.Cancel(self);
|
ChildActivity.Cancel(self);
|
||||||
|
|
||||||
var attackBases = autoTarget.ActiveAttackBases;
|
var attackBases = autoTarget.ActiveAttackBases;
|
||||||
foreach (var ab in attackBases)
|
foreach (var ab in attackBases)
|
||||||
{
|
{
|
||||||
if (attack == null)
|
QueueChild(self, ab.GetAttackActivity(self, target, true, false));
|
||||||
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);
|
ab.OnQueueAttackActivity(self, target, false, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
moving = false;
|
// Make sure to continue moving when the attack activities have finished.
|
||||||
|
QueueChild(self, getInner());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attack == null && inner == null)
|
if (ChildActivity != null)
|
||||||
{
|
{
|
||||||
if (moving)
|
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
|
||||||
return NextActivity;
|
if (ChildActivity != null)
|
||||||
|
|
||||||
inner = getInner();
|
|
||||||
moving = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inner == null)
|
|
||||||
attack = ActivityUtils.RunActivity(self, attack);
|
|
||||||
|
|
||||||
inner = ActivityUtils.RunActivity(self, inner);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Cancel(Actor self, bool keepQueue = false)
|
// The last queued childactivity is guaranteed to be the inner move, so if we get here it means
|
||||||
|
// we have reached our destination and there are no more enemies on our path.
|
||||||
|
return NextActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnLastRun(Actor self)
|
||||||
{
|
{
|
||||||
if (!IsCanceling && inner != null)
|
if (conditionManager != null && token != ConditionManager.InvalidConditionToken)
|
||||||
inner.Cancel(self);
|
token = conditionManager.RevokeCondition(self, token);
|
||||||
|
|
||||||
if (!IsCanceling && attack != null)
|
|
||||||
attack.Cancel(self);
|
|
||||||
|
|
||||||
base.Cancel(self, keepQueue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<Target> GetTargets(Actor self)
|
public override IEnumerable<Target> GetTargets(Actor self)
|
||||||
{
|
{
|
||||||
if (inner != null)
|
if (ChildActivity != null)
|
||||||
return inner.GetTargets(self);
|
return ChildActivity.GetTargets(self);
|
||||||
|
|
||||||
return Target.None;
|
return Target.None;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,46 +38,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public object Create(ActorInitializer init) { return new AttackMove(init.Self, this); }
|
public object Create(ActorInitializer init) { return new AttackMove(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class AttackMove : INotifyCreated, ITick, IResolveOrder, IOrderVoice
|
class AttackMove : IResolveOrder, IOrderVoice
|
||||||
{
|
{
|
||||||
public readonly AttackMoveInfo Info;
|
public readonly AttackMoveInfo Info;
|
||||||
readonly IMove move;
|
readonly IMove move;
|
||||||
|
|
||||||
ConditionManager conditionManager;
|
|
||||||
int attackMoveToken = ConditionManager.InvalidConditionToken;
|
|
||||||
int assaultMoveToken = ConditionManager.InvalidConditionToken;
|
|
||||||
|
|
||||||
public AttackMove(Actor self, AttackMoveInfo info)
|
public AttackMove(Actor self, AttackMoveInfo info)
|
||||||
{
|
{
|
||||||
move = self.Trait<IMove>();
|
move = self.Trait<IMove>();
|
||||||
Info = info;
|
Info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyCreated.Created(Actor self)
|
|
||||||
{
|
|
||||||
conditionManager = self.TraitOrDefault<ConditionManager>();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ITick.Tick(Actor self)
|
|
||||||
{
|
|
||||||
if (conditionManager == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var activity = self.CurrentActivity as AttackMoveActivity;
|
|
||||||
var attackActive = activity != null && !activity.IsAssaultMove;
|
|
||||||
var assaultActive = activity != null && activity.IsAssaultMove;
|
|
||||||
|
|
||||||
if (attackActive && attackMoveToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.AttackMoveScanCondition))
|
|
||||||
attackMoveToken = conditionManager.GrantCondition(self, Info.AttackMoveScanCondition);
|
|
||||||
else if (!attackActive && attackMoveToken != ConditionManager.InvalidConditionToken)
|
|
||||||
attackMoveToken = conditionManager.RevokeCondition(self, attackMoveToken);
|
|
||||||
|
|
||||||
if (assaultActive && assaultMoveToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.AssaultMoveScanCondition))
|
|
||||||
assaultMoveToken = conditionManager.GrantCondition(self, Info.AssaultMoveScanCondition);
|
|
||||||
else if (!assaultActive && assaultMoveToken != ConditionManager.InvalidConditionToken)
|
|
||||||
assaultMoveToken = conditionManager.RevokeCondition(self, assaultMoveToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)
|
string IOrderVoice.VoicePhraseForOrder(Actor self, Order order)
|
||||||
{
|
{
|
||||||
if (!Info.MoveIntoShroud && order.Target.Type != TargetType.Invalid)
|
if (!Info.MoveIntoShroud && order.Target.Type != TargetType.Invalid)
|
||||||
|
|||||||
Reference in New Issue
Block a user