Add plumbing for notifying traits of movement
More precisely, about start and stop of movement.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user