Set Mobile.IsMoving to "true" if queueing a turn that takes only a single tick

At the end of L-turns, actors often end up with an internal facing not 100% matching the direction of the next cell on their path.
As a result, if they haven't reached their destination yet, Move queues a quick Turn as ChildActivity, which previously was not considered as IsMoving.
However, we don't want those mini-turns to interrupt move animations, so we now consider them a move as well. Additionally, to avoid any issues, we make these mini-turns non-interruptible, just like the MovePart activities already are.
This commit is contained in:
reaperrr
2018-06-10 00:24:51 +02:00
committed by Paul Chote
parent e167d1f848
commit 4c239d4ebc
2 changed files with 29 additions and 2 deletions

View File

@@ -19,14 +19,27 @@ 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 isInterruptible = true)
public Turn(Actor self, int desiredFacing, bool setIsMoving = false, bool isInterruptible = true)
{
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)
@@ -44,5 +57,12 @@ 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 (mobile != null && mobile.IsMoving)
mobile.IsMoving = false;
}
}
}