don't use Move directly
This commit is contained in:
@@ -15,7 +15,7 @@ using System.Linq;
|
||||
|
||||
namespace OpenRA.Traits.Activities
|
||||
{
|
||||
public class Move : CancelableActivity
|
||||
class Move : CancelableActivity
|
||||
{
|
||||
int2? destination;
|
||||
int nearEnough;
|
||||
|
||||
@@ -391,5 +391,12 @@ namespace OpenRA.Traits
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public IActivity MoveTo( int2 cell ) { return new Move( cell ); }
|
||||
public IActivity MoveTo( int2 cell, int range ) { return new Move( cell, range ); }
|
||||
public IActivity MoveTo( int2 cell, Actor ignoredActor ) { return new Move( cell, ignoredActor ); }
|
||||
public IActivity MoveTo( Actor target, int range ) { return new Move( target, range ); }
|
||||
public IActivity MoveTo( Target target, int range ) { return new Move( target, range ); }
|
||||
public IActivity MoveTo( Func<List<int2>> pathFunc ) { return new Move( pathFunc ); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,9 +97,10 @@ namespace OpenRA.Mods.Cnc
|
||||
new FacingInit( 0 ),
|
||||
new LocationInit ( Map.Waypoints["nod0"] ),
|
||||
});
|
||||
a.QueueActivity( new Move( Map.Waypoints["nod1"], 2 ) );
|
||||
a.QueueActivity( new Move( Map.Waypoints["nod2"], 2 ) );
|
||||
a.QueueActivity( new Move( Map.Waypoints["nod3"], 2 ) );
|
||||
var mobile = a.Trait<Mobile>();
|
||||
a.QueueActivity( mobile.MoveTo( Map.Waypoints["nod1"], 2 ) );
|
||||
a.QueueActivity( mobile.MoveTo( Map.Waypoints["nod2"], 2 ) );
|
||||
a.QueueActivity( mobile.MoveTo( Map.Waypoints["nod3"], 2 ) );
|
||||
// Todo: Queue hunt order
|
||||
}
|
||||
});
|
||||
@@ -162,9 +163,11 @@ namespace OpenRA.Mods.Cnc
|
||||
|
||||
void SetGunboatPath()
|
||||
{
|
||||
Actors["Gunboat"].QueueActivity(new Move( Map.Waypoints["gunboatLeft"] ));
|
||||
Actors["Gunboat"].QueueActivity(new Move( Map.Waypoints["gunboatRight"] ));
|
||||
Actors["Gunboat"].QueueActivity(new CallFunc(() => SetGunboatPath()));
|
||||
var self = Actors[ "Gunboat" ];
|
||||
var mobile = self.Trait<Mobile>();
|
||||
self.QueueActivity(mobile.MoveTo( Map.Waypoints["gunboatLeft"] ));
|
||||
self.QueueActivity(mobile.MoveTo( Map.Waypoints["gunboatRight"] ));
|
||||
self.QueueActivity(new CallFunc(() => SetGunboatPath()));
|
||||
}
|
||||
|
||||
void ReinforceFromSea(World world, int2 startPos, int2 endPos, int2 unload, string[] items)
|
||||
@@ -180,6 +183,7 @@ namespace OpenRA.Mods.Cnc
|
||||
new FacingInit( 0 ),
|
||||
});
|
||||
|
||||
var mobile = a.Trait<Mobile>();
|
||||
var cargo = a.Trait<Cargo>();
|
||||
foreach (var i in items)
|
||||
cargo.Load(a, world.CreateActor(false, i.ToLowerInvariant(), new TypeDictionary
|
||||
@@ -189,7 +193,7 @@ namespace OpenRA.Mods.Cnc
|
||||
}));
|
||||
|
||||
a.CancelActivity();
|
||||
a.QueueActivity(new Move(endPos));
|
||||
a.QueueActivity(mobile.MoveTo(endPos));
|
||||
a.QueueActivity(new CallFunc(() =>
|
||||
{
|
||||
while (!cargo.IsEmpty(a))
|
||||
@@ -200,12 +204,12 @@ namespace OpenRA.Mods.Cnc
|
||||
if (b.Destroyed) return;
|
||||
w2.Add(b);
|
||||
b.TraitsImplementing<IMove>().FirstOrDefault().SetPosition(b, a.Location);
|
||||
b.QueueActivity(new Move(unload, 2));
|
||||
b.QueueActivity(mobile.MoveTo(unload, 2));
|
||||
});
|
||||
}
|
||||
}));
|
||||
a.QueueActivity(new Wait(25));
|
||||
a.QueueActivity(new Move(startPos));
|
||||
a.QueueActivity(mobile.MoveTo(startPos));
|
||||
a.QueueActivity(new RemoveSelf());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace OpenRA.Mods.Cnc
|
||||
{
|
||||
int2 startDock = harv.Trait<IHasLocation>().PxPosition;
|
||||
int2 endDock = self.Trait<IHasLocation>().PxPosition + new int2(-15,8);
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var harvester = harv.Trait<Harvester>();
|
||||
|
||||
harv.QueueActivity( new Turn(112) );
|
||||
@@ -53,7 +54,7 @@ namespace OpenRA.Mods.Cnc
|
||||
harv.QueueActivity( new CallFunc( () => dockedHarv = null, false ) );
|
||||
if (harvester.LastHarvestedCell != int2.Zero)
|
||||
{
|
||||
harv.QueueActivity( new Move(harvester.LastHarvestedCell, 5) );
|
||||
harv.QueueActivity( mobile.MoveTo(harvester.LastHarvestedCell, 5) );
|
||||
if (harv.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask( w =>
|
||||
{
|
||||
|
||||
@@ -41,10 +41,11 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if (!Target.IsValid)
|
||||
return NextActivity;
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var targetCell = Util.CellContaining(Target.CenterLocation);
|
||||
|
||||
if ((targetCell - self.Location).LengthSquared >= Range * Range)
|
||||
return Util.SequenceActivities( new Move( Target, Range ), this );
|
||||
return Util.SequenceActivities( mobile.MoveTo( Target, Range ), this );
|
||||
|
||||
var desiredFacing = Util.GetFacing((targetCell - self.Location).ToFloat2(), 0);
|
||||
var renderUnit = self.TraitOrDefault<RenderUnit>();
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if( NextActivity != null )
|
||||
return NextActivity;
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var harv = self.Trait<Harvester>();
|
||||
|
||||
if (harv.LinkedProc == null || !harv.LinkedProc.IsInWorld)
|
||||
@@ -39,7 +40,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
if( self.Location != proc.Location + proc.Trait<IAcceptOre>().DeliverOffset )
|
||||
{
|
||||
return Util.SequenceActivities( new Move(proc.Location + proc.Trait<IAcceptOre>().DeliverOffset, 0), this );
|
||||
return Util.SequenceActivities( mobile.MoveTo(proc.Location + proc.Trait<IAcceptOre>().DeliverOffset, 0), this );
|
||||
}
|
||||
else if (!isDocking)
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -15,20 +16,21 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
class Demolish : CancelableActivity
|
||||
{
|
||||
Target target;
|
||||
Actor target;
|
||||
|
||||
public Demolish( Actor target ) { this.target = Target.FromActor(target); }
|
||||
public Demolish( Actor target ) { this.target = target; }
|
||||
|
||||
public override IActivity Tick(Actor self)
|
||||
{
|
||||
if( IsCanceled ) return NextActivity;
|
||||
if (!target.IsValid) return NextActivity;
|
||||
if ((target.Actor.Location - self.Location).Length > 1)
|
||||
if (IsCanceled) return NextActivity;
|
||||
if (target == null || !target.IsInWorld || target.IsDead()) return NextActivity;
|
||||
if (target.Owner == self.Owner) return NextActivity;
|
||||
|
||||
if( !target.Trait<IOccupySpace>().OccupiedCells().Any( x => x == self.Location ) )
|
||||
return NextActivity;
|
||||
|
||||
|
||||
self.World.AddFrameEndTask(w => w.Add(new DelayedAction(25 * 2,
|
||||
() => { if (target.IsValid) target.Actor.Kill(self); })));
|
||||
() => { if (target.IsInWorld) target.Kill(self); })));
|
||||
return NextActivity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var nearest = target.Trait<IOccupySpace>().NearestCellTo( mobile.toCell );
|
||||
if( ( nearest - mobile.toCell ).LengthSquared >= 2 )
|
||||
if( ( nearest - mobile.toCell ).LengthSquared > 2 )
|
||||
return Util.SequenceActivities( new MoveAdjacentTo( target ), this );
|
||||
|
||||
return Util.SequenceActivities( new Move( nearest, target ), NextActivity );
|
||||
return Util.SequenceActivities( mobile.MoveTo( nearest, target ), NextActivity );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,8 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
if( inRange ) return this;
|
||||
|
||||
var ret = new Move( Target, Range );
|
||||
ret.Queue( this );
|
||||
return ret;
|
||||
var mobile = self.Trait<Mobile>();
|
||||
return Util.SequenceActivities( mobile.MoveTo( Target, Range ), this );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,10 +60,11 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
void FindMoreResource(Actor self)
|
||||
{
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var res = self.World.WorldActor.Trait<ResourceLayer>();
|
||||
var harv = self.Info.Traits.Get<HarvesterInfo>();
|
||||
var mobileInfo = self.Info.Traits.Get<MobileInfo>();
|
||||
self.QueueActivity(new Move(
|
||||
self.QueueActivity(mobile.MoveTo(
|
||||
() =>
|
||||
{
|
||||
return self.World.PathFinder.FindPath(PathSearch.Search(self.World, mobileInfo, true)
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
if (IsCanceled) return NextActivity;
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
|
||||
if (!limitedAmmo.HasAmmo())
|
||||
{
|
||||
@@ -54,7 +55,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
var p = ml.minefield.Random(self.World.SharedRandom);
|
||||
if (ShouldLayMine(self, p))
|
||||
return Util.SequenceActivities( new Move(p, 0), this );
|
||||
return Util.SequenceActivities( mobile.MoveTo(p, 0), this );
|
||||
}
|
||||
|
||||
// todo: return somewhere likely to be safe (near fix) so we're not sitting out in the minefield.
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
var ret = self.World.PathFinder.FindBidiPath( ps1, ps2 );
|
||||
if( ret.Count > 0 )
|
||||
ret.RemoveAt( 0 );
|
||||
return Util.SequenceActivities( new Move( () => ret ), this );
|
||||
return Util.SequenceActivities( mobile.MoveTo( () => ret ), this );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,9 +67,11 @@ namespace OpenRA.Mods.RA.Activities
|
||||
{
|
||||
if (actor.Destroyed) return;
|
||||
w.Add(actor);
|
||||
actor.TraitsImplementing<IMove>().FirstOrDefault().SetPosition(actor, self.Location);
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
mobile.SetPosition(actor, self.Location);
|
||||
actor.CancelActivity();
|
||||
actor.QueueActivity(new Move(exitTile.Value, 0));
|
||||
actor.QueueActivity(mobile.MoveTo(exitTile.Value, 0));
|
||||
if (actor.Owner == self.World.LocalPlayer)
|
||||
{
|
||||
var line = actor.TraitOrDefault<DrawLineToTarget>();
|
||||
|
||||
@@ -53,11 +53,12 @@ namespace OpenRA.Mods.RA
|
||||
line.SetTarget(self, Target.FromOrder(order), Color.Red);
|
||||
});
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Enter(order.TargetActor));
|
||||
//self.QueueActivity(new Move(order.TargetActor.Location, order.TargetActor));
|
||||
self.QueueActivity(new Demolish(order.TargetActor));
|
||||
self.QueueActivity(new Move(self.Location, 0));
|
||||
self.QueueActivity(mobile.MoveTo(self.Location, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -133,8 +133,9 @@ namespace OpenRA.Mods.RA
|
||||
line.SetTarget(self, Target.FromOrder(order), Color.Red);
|
||||
});
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Move(order.TargetLocation, 0));
|
||||
self.QueueActivity(mobile.MoveTo(order.TargetLocation, 0));
|
||||
self.QueueActivity(new Harvest());
|
||||
}
|
||||
else if (order.OrderString == "Deliver")
|
||||
|
||||
@@ -41,7 +41,8 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
if (harvester.LastHarvestedCell != int2.Zero)
|
||||
{
|
||||
harv.QueueActivity( new Move(harvester.LastHarvestedCell, 5) );
|
||||
var mobile = harv.Trait<Mobile>();
|
||||
harv.QueueActivity( mobile.MoveTo(harvester.LastHarvestedCell, 5) );
|
||||
if (harv.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask( w =>
|
||||
{
|
||||
|
||||
@@ -87,8 +87,9 @@ namespace OpenRA.Mods.RA
|
||||
line.SetTarget(self, Target.FromOrder(order), Color.Green);
|
||||
});
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Move(order.TargetActor.Location, 1));
|
||||
self.QueueActivity(mobile.MoveTo(order.TargetActor.Location, 1));
|
||||
self.QueueActivity(new EnterTransport(self, order.TargetActor));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,8 +72,7 @@ namespace OpenRA.Mods.RA
|
||||
if (rp != null)
|
||||
{
|
||||
target = rp.rallyPoint;
|
||||
// Todo: Move implies unit has Mobile
|
||||
newUnit.QueueActivity(new Move(target, 1));
|
||||
newUnit.QueueActivity(mobile.MoveTo(target, 1));
|
||||
}
|
||||
|
||||
if (newUnit.Owner == self.World.LocalPlayer)
|
||||
|
||||
@@ -72,6 +72,7 @@ namespace OpenRA.Mods.RA
|
||||
if( !CanRepairAt( order.TargetActor ) || !CanRepair() )
|
||||
return;
|
||||
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var rp = order.TargetActor.TraitOrDefault<RallyPoint>();
|
||||
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
@@ -85,13 +86,13 @@ namespace OpenRA.Mods.RA
|
||||
});
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Move(Util.CellContaining(order.TargetActor.CenterLocation), order.TargetActor));
|
||||
self.QueueActivity(mobile.MoveTo(Util.CellContaining(order.TargetActor.CenterLocation), order.TargetActor));
|
||||
self.QueueActivity(new Rearm());
|
||||
self.QueueActivity(new Repair(order.TargetActor));
|
||||
|
||||
if (rp != null)
|
||||
self.QueueActivity(new CallFunc(
|
||||
() => self.QueueActivity(new Move(rp.rallyPoint, order.TargetActor))));
|
||||
() => self.QueueActivity(mobile.MoveTo(rp.rallyPoint, order.TargetActor))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,8 +63,9 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
if (order.OrderString == "RepairNear" && CanRepairAt(order.TargetActor) && ShouldRepair())
|
||||
{
|
||||
var mobile = self.Trait<Mobile>();
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Move(order.TargetActor, 1));
|
||||
self.QueueActivity(mobile.MoveTo(order.TargetActor, 1));
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
self.World.AddFrameEndTask( w =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user