Simplify HeliFly interface.
This commit is contained in:
@@ -15,10 +15,14 @@ namespace OpenRA.Mods.RA.Air
|
||||
{
|
||||
class HeliFly : Activity
|
||||
{
|
||||
readonly Helicopter helicopter;
|
||||
readonly WPos pos;
|
||||
|
||||
public HeliFly(WPos pos) { this.pos = pos; }
|
||||
public HeliFly(CPos pos) { this.pos = pos.CenterPosition; }
|
||||
public HeliFly(Actor self, Target t)
|
||||
{
|
||||
helicopter = self.Trait<Helicopter>();
|
||||
pos = t.CenterPosition;
|
||||
}
|
||||
|
||||
public static bool AdjustAltitude(Actor self, Helicopter helicopter, WRange targetAltitude)
|
||||
{
|
||||
@@ -38,8 +42,6 @@ namespace OpenRA.Mods.RA.Air
|
||||
if (IsCanceled)
|
||||
return NextActivity;
|
||||
|
||||
var helicopter = self.Trait<Helicopter>();
|
||||
|
||||
if (AdjustAltitude(self, helicopter, helicopter.Info.CruiseAltitude))
|
||||
return this;
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA.Air
|
||||
if (nearestHpad == null)
|
||||
return Util.SequenceActivities(new Turn(initialFacing), new HeliLand(true), NextActivity);
|
||||
else
|
||||
return Util.SequenceActivities(new HeliFly(nearestHpad.CenterPosition));
|
||||
return Util.SequenceActivities(new HeliFly(self, Target.FromActor(nearestHpad)));
|
||||
}
|
||||
|
||||
var res = dest.TraitOrDefault<Reservable>();
|
||||
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Air
|
||||
var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero;
|
||||
|
||||
return Util.SequenceActivities(
|
||||
new HeliFly(dest.CenterPosition + offset),
|
||||
new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)),
|
||||
new Turn(initialFacing),
|
||||
new HeliLand(false),
|
||||
new Rearm(self),
|
||||
|
||||
@@ -28,11 +28,13 @@ namespace OpenRA.Mods.RA.Air
|
||||
class Helicopter : Aircraft, ITick, IResolveOrder, IMove
|
||||
{
|
||||
public HelicopterInfo Info;
|
||||
Actor self;
|
||||
bool firstTick = true;
|
||||
|
||||
public Helicopter(ActorInitializer init, HelicopterInfo info)
|
||||
: base(init, info)
|
||||
{
|
||||
self = init.self;
|
||||
Info = info;
|
||||
}
|
||||
|
||||
@@ -46,11 +48,12 @@ namespace OpenRA.Mods.RA.Air
|
||||
|
||||
if (order.OrderString == "Move")
|
||||
{
|
||||
var target = self.World.ClampToWorld(order.TargetLocation);
|
||||
var cell = self.World.ClampToWorld(order.TargetLocation);
|
||||
var t = Target.FromCell(cell);
|
||||
|
||||
self.SetTargetLine(Target.FromCell(target), Color.Green);
|
||||
self.SetTargetLine(t, Color.Green);
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new HeliFly(target));
|
||||
self.QueueActivity(new HeliFly(self, t));
|
||||
|
||||
if (Info.LandWhenIdle)
|
||||
{
|
||||
@@ -78,7 +81,7 @@ namespace OpenRA.Mods.RA.Air
|
||||
self.SetTargetLine(Target.FromActor(order.TargetActor), Color.Green);
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new HeliFly(order.TargetActor.CenterPosition + offset));
|
||||
self.QueueActivity(new HeliFly(self, Target.FromPos(order.TargetActor.CenterPosition + offset)));
|
||||
self.QueueActivity(new Turn(Info.InitialFacing));
|
||||
self.QueueActivity(new HeliLand(false));
|
||||
self.QueueActivity(new ResupplyAircraft());
|
||||
@@ -149,9 +152,9 @@ namespace OpenRA.Mods.RA.Air
|
||||
return (d * 1024 * 8) / (int)distSq;
|
||||
}
|
||||
|
||||
public Activity MoveTo(CPos cell, int nearEnough) { return new HeliFly(cell); }
|
||||
public Activity MoveTo(CPos cell, Actor ignoredActor) { return new HeliFly(cell); }
|
||||
public Activity MoveWithinRange(Target target, WRange range) { return new HeliFly(target.CenterPosition); }
|
||||
public Activity MoveTo(CPos cell, int nearEnough) { return new HeliFly(self, Target.FromCell(cell)); }
|
||||
public Activity MoveTo(CPos cell, Actor ignoredActor) { return new HeliFly(self, Target.FromCell(cell)); }
|
||||
public Activity MoveWithinRange(Target target, WRange range) { return new HeliFly(self, target); }
|
||||
public CPos NearestMoveableCell(CPos cell) { return cell; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,12 +221,12 @@ namespace OpenRA.Mods.RA.Missions
|
||||
var exit = lz.Info.Traits.WithInterface<ExitInfo>().FirstOrDefault();
|
||||
var offset = (exit != null) ? exit.SpawnOffset : WVec.Zero;
|
||||
|
||||
chinook.QueueActivity(new HeliFly(lz.CenterPosition + offset)); // no reservation of hpad but it's not needed
|
||||
chinook.QueueActivity(new HeliFly(chinook, Target.FromPos(lz.CenterPosition + offset))); // no reservation of hpad but it's not needed
|
||||
chinook.QueueActivity(new Turn(0));
|
||||
chinook.QueueActivity(new HeliLand(false));
|
||||
chinook.QueueActivity(new UnloadCargo(true));
|
||||
chinook.QueueActivity(new Wait(150));
|
||||
chinook.QueueActivity(new HeliFly(entry));
|
||||
chinook.QueueActivity(new HeliFly(chinook, Target.FromCell(entry)));
|
||||
chinook.QueueActivity(new RemoveSelf());
|
||||
}
|
||||
|
||||
|
||||
@@ -45,12 +45,12 @@ namespace OpenRA.Mods.RA.Missions
|
||||
public static Actor ExtractUnitWithChinook(World world, Player owner, Actor unit, CPos entry, CPos lz, CPos exit)
|
||||
{
|
||||
var chinook = world.CreateActor("tran", new TypeDictionary { new OwnerInit(owner), new LocationInit(entry) });
|
||||
chinook.QueueActivity(new HeliFly(lz));
|
||||
chinook.QueueActivity(new HeliFly(chinook, Target.FromCell(lz)));
|
||||
chinook.QueueActivity(new Turn(0));
|
||||
chinook.QueueActivity(new HeliLand(true));
|
||||
chinook.QueueActivity(new WaitFor(() => chinook.Trait<Cargo>().Passengers.Contains(unit)));
|
||||
chinook.QueueActivity(new Wait(150));
|
||||
chinook.QueueActivity(new HeliFly(exit));
|
||||
chinook.QueueActivity(new HeliFly(chinook, Target.FromCell(exit)));
|
||||
chinook.QueueActivity(new RemoveSelf());
|
||||
return chinook;
|
||||
}
|
||||
@@ -60,13 +60,13 @@ namespace OpenRA.Mods.RA.Missions
|
||||
var unit = world.CreateActor(false, unitName, new TypeDictionary { new OwnerInit(owner) });
|
||||
var chinook = world.CreateActor("tran", new TypeDictionary { new OwnerInit(owner), new LocationInit(entry) });
|
||||
chinook.Trait<Cargo>().Load(chinook, unit);
|
||||
chinook.QueueActivity(new HeliFly(lz));
|
||||
chinook.QueueActivity(new HeliFly(chinook, Target.FromCell(lz)));
|
||||
chinook.QueueActivity(new Turn(0));
|
||||
chinook.QueueActivity(new HeliLand(true));
|
||||
chinook.QueueActivity(new UnloadCargo(true));
|
||||
chinook.QueueActivity(new CallFunc(() => afterUnload(unit)));
|
||||
chinook.QueueActivity(new Wait(150));
|
||||
chinook.QueueActivity(new HeliFly(exit));
|
||||
chinook.QueueActivity(new HeliFly(chinook, Target.FromCell(exit)));
|
||||
chinook.QueueActivity(new RemoveSelf());
|
||||
return Pair.New(chinook, unit);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user