Add plumbing for notifying traits of movement

More precisely, about start and stop of movement.
This commit is contained in:
reaperrr
2018-08-26 13:49:23 +02:00
committed by Paul Chote
parent 32ab822786
commit a10af382b4
15 changed files with 102 additions and 84 deletions

View File

@@ -19,32 +19,18 @@ namespace OpenRA.Mods.Common.Activities
{
readonly IDisabledTrait disablable;
readonly IFacing facing;
readonly Mobile mobile;
readonly int desiredFacing;
readonly bool setIsMoving;
public Turn(Actor self, int desiredFacing, bool setIsMoving = false, bool isInterruptible = true)
public Turn(Actor self, int desiredFacing)
{
disablable = self.TraitOrDefault<IMove>() as IDisabledTrait;
facing = self.Trait<IFacing>();
this.desiredFacing = desiredFacing;
this.setIsMoving = setIsMoving;
IsInterruptible = isInterruptible;
// This might look confusing, but the current implementation of Mobile is both IMove and IDisabledTrait,
// and this way we can save a separate Mobile trait look-up.
mobile = disablable as Mobile;
}
protected override void OnFirstRun(Actor self)
{
if (setIsMoving && mobile != null && !mobile.IsMoving)
mobile.IsMoving = true;
}
public override Activity Tick(Actor self)
{
if (IsInterruptible && IsCanceling)
if (IsCanceling)
return NextActivity;
if (disablable != null && disablable.IsTraitDisabled)
@@ -57,12 +43,5 @@ namespace OpenRA.Mods.Common.Activities
return this;
}
protected override void OnLastRun(Actor self)
{
// If Mobile.IsMoving was set to 'true' earlier, we want to reset it to 'false' before the next tick.
if (setIsMoving && mobile != null && mobile.IsMoving)
mobile.IsMoving = false;
}
}
}