Added Cancel() to Mobile.CurrentAction. Added QueueAction to Mobile. Made Order.Apply use queue rather than SetNextAction.
This commit is contained in:
@@ -192,7 +192,9 @@ namespace OpenRa.Game
|
||||
throw new InvalidOperationException("BuildUnit without suitable production structure!");
|
||||
|
||||
var unit = new Actor(name, (1/24f * producer.CenterLocation).ToInt2(), player);
|
||||
unit.Order(unit.Location + new int2(0, 3)).Apply(false);
|
||||
var mobile = unit.traits.Get<Mobile>();
|
||||
mobile.facing = 128;
|
||||
mobile.SetNextAction( new Traits.Mobile.MoveTo( unit.Location + new int2( 0, 3 ) ) );
|
||||
|
||||
world.AddFrameEndTask(_ => world.Add(unit));
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenRa.Game
|
||||
if (Game.LocalPlayer == Unit.Owner)
|
||||
Game.PlaySound("ackno.r00", false);
|
||||
var mobile = Unit.traits.Get<Traits.Mobile>();
|
||||
mobile.SetNextAction( new Traits.Mobile.MoveTo( Destination ) );
|
||||
mobile.QueueAction( new Traits.Mobile.MoveTo( Destination ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,9 @@ namespace OpenRa.Game.Traits
|
||||
public override void Apply( bool leftMouseButton )
|
||||
{
|
||||
if( leftMouseButton ) return;
|
||||
Unit.traits.Get<Mobile>().SetNextAction( new Mobile.Turn( 96 ) { NextAction = new DeployAction() } );
|
||||
var mobile = Unit.traits.Get<Mobile>();
|
||||
mobile.QueueAction( new Mobile.Turn( 96 ) );
|
||||
mobile.QueueAction( new DeployAction() );
|
||||
}
|
||||
|
||||
class DeployAction : Mobile.CurrentAction
|
||||
@@ -50,6 +52,12 @@ namespace OpenRa.Game.Traits
|
||||
Game.world.Add( new Actor( "fact", self.Location - new int2( 1, 1 ), self.Owner ) );
|
||||
} );
|
||||
}
|
||||
|
||||
public void Cancel( Actor self, Mobile mobile )
|
||||
{
|
||||
// Cancel can't happen between this being moved to the head of the list, and it being Ticked.
|
||||
throw new InvalidOperationException( "DeployMcvAction: Cancel() should never occur." );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,21 @@ namespace OpenRa.Game.Traits
|
||||
currentAction.NextAction = nextAction;
|
||||
}
|
||||
|
||||
public void QueueAction( CurrentAction nextAction )
|
||||
{
|
||||
if( currentAction == null )
|
||||
{
|
||||
currentAction = nextAction;
|
||||
return;
|
||||
}
|
||||
var act = currentAction;
|
||||
while( act.NextAction != null )
|
||||
{
|
||||
act = act.NextAction;
|
||||
}
|
||||
act.NextAction = nextAction;
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if( currentAction != null )
|
||||
@@ -51,15 +66,16 @@ namespace OpenRa.Game.Traits
|
||||
|
||||
public interface CurrentAction
|
||||
{
|
||||
CurrentAction NextAction { set; }
|
||||
CurrentAction NextAction { get; set; }
|
||||
void Tick( Actor self, Mobile mobile );
|
||||
void Cancel( Actor self, Mobile mobile );
|
||||
}
|
||||
|
||||
public class Turn : CurrentAction
|
||||
{
|
||||
public CurrentAction NextAction { get; set; }
|
||||
|
||||
public readonly int desiredFacing;
|
||||
public int desiredFacing;
|
||||
|
||||
public Turn( int desiredFacing )
|
||||
{
|
||||
@@ -77,6 +93,12 @@ namespace OpenRa.Game.Traits
|
||||
}
|
||||
Util.TickFacing( ref mobile.facing, desiredFacing, self.unitInfo.ROT );
|
||||
}
|
||||
|
||||
public void Cancel( Actor self, Mobile mobile )
|
||||
{
|
||||
desiredFacing = mobile.facing;
|
||||
NextAction = null;
|
||||
}
|
||||
}
|
||||
|
||||
public class MoveTo : CurrentAction
|
||||
@@ -211,6 +233,12 @@ namespace OpenRa.Game.Traits
|
||||
OnComplete = null;
|
||||
mobile.fromCell = mobile.toCell;
|
||||
}
|
||||
|
||||
public void Cancel( Actor self, Mobile mobile )
|
||||
{
|
||||
path.Clear();
|
||||
NextAction = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user