Simplify Fly interface.

This commit is contained in:
Paul Chote
2014-01-16 22:32:08 +13:00
parent c781d4c2fe
commit 4eaaa052cc
11 changed files with 29 additions and 24 deletions

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Cnc
new FacingInit(64)
});
a.QueueActivity(Fly.ToCell(self.Location + new CVec(9, 0)));
a.QueueActivity(new Fly(a, Target.FromCell(self.Location + new CVec(9, 0))));
a.QueueActivity(new Land(Target.FromActor(self)));
a.QueueActivity(new CallFunc(() =>
{
@@ -71,7 +71,8 @@ namespace OpenRA.Mods.Cnc
self.World.AddFrameEndTask(ww => DoProduction(self, producee, exit));
Sound.PlayNotification(self.Owner, "Speech", (Info as ProductionAirdropInfo).ReadyAudio, self.Owner.Country.Race);
}));
a.QueueActivity(Fly.ToCell(endPos));
a.QueueActivity(new Fly(a, Target.FromCell(endPos)));
a.QueueActivity(new RemoveSelf());
});

View File

@@ -16,8 +16,13 @@ namespace OpenRA.Mods.RA.Air
public class Fly : Activity
{
readonly WPos pos;
readonly Plane plane;
Fly(WPos pos) { this.pos = pos; }
public Fly(Actor self, Target t)
{
plane = self.Trait<Plane>();
pos = t.CenterPosition;
}
public static void FlyToward(Actor self, Plane plane, int desiredFacing, WRange desiredAltitude)
{
@@ -36,9 +41,6 @@ namespace OpenRA.Mods.RA.Air
plane.SetPosition(self, plane.CenterPosition + move);
}
public static Fly ToPos(WPos pos) { return new Fly(pos); }
public static Fly ToCell(CPos pos) { return new Fly(pos.CenterPosition); }
public override Activity Tick(Actor self)
{
if (IsCanceled)
@@ -49,7 +51,6 @@ namespace OpenRA.Mods.RA.Air
if (d.HorizontalLengthSquared < 91022)
return NextActivity;
var plane = self.Trait<Plane>();
var desiredFacing = Util.GetFacing(d, plane.Facing);
// Don't turn until we've reached the cruise altitude

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Air
if (IsCanceled)
return NextActivity;
inner = Util.SequenceActivities(Fly.ToPos(target.CenterPosition), new FlyTimed(50));
inner = Util.SequenceActivities(new Fly(self, target), new FlyTimed(50));
}
inner = Util.RunActivity(self, inner);

View File

@@ -24,10 +24,12 @@ namespace OpenRA.Mods.RA.Air
{
public readonly PlaneInfo Info;
[Sync] public WPos RTBPathHash;
Actor self;
public Plane(ActorInitializer init, PlaneInfo info)
: base(init, info)
{
self = init.self;
Info = info;
}
@@ -48,10 +50,11 @@ namespace OpenRA.Mods.RA.Air
{
UnReserve();
var target = self.World.ClampToWorld(order.TargetLocation);
self.SetTargetLine(Target.FromCell(target), Color.Green);
var cell = self.World.ClampToWorld(order.TargetLocation);
var t = Target.FromCell(cell);
self.SetTargetLine(t, Color.Green);
self.CancelActivity();
self.QueueActivity(Fly.ToCell(target));
self.QueueActivity(new Fly(self, t));
self.QueueActivity(new FlyCircle());
}
else if (order.OrderString == "Enter")
@@ -89,9 +92,9 @@ namespace OpenRA.Mods.RA.Air
}
}
public Activity MoveTo(CPos cell, int nearEnough) { return Fly.ToCell(cell); }
public Activity MoveTo(CPos cell, Actor ignoredActor) { return Fly.ToCell(cell); }
public Activity MoveWithinRange(Target target, WRange range) { return Fly.ToPos(target.CenterPosition); }
public Activity MoveTo(CPos cell, int nearEnough) { return new Fly(self, Target.FromCell(cell)); }
public Activity MoveTo(CPos cell, Actor ignoredActor) { return new Fly(self, Target.FromCell(cell)); }
public Activity MoveWithinRange(Target target, WRange range) { return new Fly(self, target); }
public CPos NearestMoveableCell(CPos cell) { return cell; }
}
}

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Air
return;
}
self.QueueActivity(Fly.ToCell(someBuilding.Location));
self.QueueActivity(new Fly(self, Target.FromActor(someBuilding)));
self.QueueActivity(new FlyCircle());
}
}

View File

@@ -110,15 +110,15 @@ namespace OpenRA.Mods.RA.Air
self.CancelActivity();
if (nearestAfld != null)
return Util.SequenceActivities(Fly.ToCell(nearestAfld.Location), new FlyCircle());
return Util.SequenceActivities(new Fly(self, Target.FromActor(nearestAfld)), new FlyCircle());
else
return new FlyCircle();
}
return Util.SequenceActivities(
Fly.ToPos(w1),
Fly.ToPos(w2),
Fly.ToPos(w3),
new Fly(self, Target.FromPos(w1)),
new Fly(self, Target.FromPos(w2)),
new Fly(self, Target.FromPos(w3)),
new Land(Target.FromActor(dest)),
NextActivity);
}

View File

@@ -206,7 +206,7 @@ namespace OpenRA.Mods.RA.Missions
new FacingInit(Traits.Util.GetFacing(waypoints[1] - waypoints[0], 0))
});
foreach (var waypoint in waypoints)
m.QueueActivity(Fly.ToCell(waypoint));
m.QueueActivity(new Fly(m, Target.FromCell(waypoint)));
m.QueueActivity(new RemoveSelf());
}

View File

@@ -101,7 +101,7 @@ namespace OpenRA.Mods.RA.Missions
});
badger.Trait<AttackBomber>().SetTarget(location.CenterPosition);
badger.QueueActivity(Fly.ToCell(location));
badger.QueueActivity(new Fly(badger, Target.FromCell(location)));
badger.QueueActivity(new FlyOffMap());
badger.QueueActivity(new RemoveSelf());
}

View File

@@ -263,7 +263,7 @@ namespace OpenRA.Mods.RA.Scripting
[LuaGlobal]
public void FlyToPos(Actor actor, WPos pos)
{
actor.QueueActivity(Fly.ToPos(pos));
actor.QueueActivity(new Fly(actor, Target.FromPos(pos)));
}
[LuaGlobal]

View File

@@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA
if (flare != null)
a.QueueActivity(new CallFunc(() => flare.Destroy()));
a.QueueActivity(Fly.ToPos(finishEdge + spawnOffset));
a.QueueActivity(new Fly(a, Target.FromPos(finishEdge + spawnOffset)));
a.QueueActivity(new RemoveSelf());
}
});

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA
});
plane.CancelActivity();
plane.QueueActivity(Fly.ToCell(order.TargetLocation));
plane.QueueActivity(new Fly(plane, Target.FromCell(order.TargetLocation)));
plane.QueueActivity(new CallFunc(() => plane.World.AddFrameEndTask( w =>
{
var camera = w.CreateActor("camera", new TypeDictionary