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