Revert FlightDynamics

This needs more thought and most parts might get superseded
by other approaches.

Kept CanSlide separation from CanHover.
This commit is contained in:
reaperrr
2019-07-12 23:10:05 +02:00
committed by abcdefg30
parent aa5c8b4efa
commit cf4d73ab91
9 changed files with 58 additions and 57 deletions

View File

@@ -53,8 +53,7 @@ namespace OpenRA.Mods.Common.Activities
public static void FlyTick(Actor self, Aircraft aircraft, int desiredFacing, WDist desiredAltitude, WVec moveOverride, int turnSpeedOverride = -1)
{
var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition);
var isSlider = aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.Slide);
var move = isSlider ? aircraft.FlyStep(desiredFacing) : aircraft.FlyStep(aircraft.Facing);
var move = aircraft.Info.CanSlide ? aircraft.FlyStep(desiredFacing) : aircraft.FlyStep(aircraft.Facing);
if (moveOverride != WVec.Zero)
move = moveOverride;
@@ -116,7 +115,7 @@ namespace OpenRA.Mods.Common.Activities
// If the aircraft lands when idle and is idle, we let the default idle handler manage this.
// TODO: Remove this after fixing all activities to work properly with arbitrary starting altitudes.
var skipHeightAdjustment = aircraft.Info.LandWhenIdle && self.CurrentActivity.IsCanceling && self.CurrentActivity.NextActivity == null;
if (aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.Hover) && !skipHeightAdjustment && dat != aircraft.Info.CruiseAltitude)
if (aircraft.Info.CanHover && !skipHeightAdjustment && dat != aircraft.Info.CruiseAltitude)
{
if (dat <= aircraft.LandAltitude)
QueueChild(new TakeOff(self, target));
@@ -161,22 +160,22 @@ namespace OpenRA.Mods.Common.Activities
if (insideMaxRange && !insideMinRange)
return true;
var isSlider = aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.Slide);
var isSlider = aircraft.Info.CanSlide;
var move = isSlider ? aircraft.FlyStep(desiredFacing) : aircraft.FlyStep(aircraft.Facing);
// Inside the minimum range, so reverse if we have Slide flag
// Inside the minimum range, so reverse if we CanSlide
if (isSlider && insideMinRange)
{
FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude, -move);
return false;
}
// The next move would overshoot, so consider it close enough or set final position if we have Slide flag
// The next move would overshoot, so consider it close enough or set final position if we CanSlide
if (delta.HorizontalLengthSquared < move.HorizontalLengthSquared)
{
// For VTOL landing to succeed, it must reach the exact target position,
// so for the final move it needs to behave as if it had the Slide flag.
if (isSlider || aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.VTOL))
// so for the final move it needs to behave as if it had CanSlide.
if (isSlider || aircraft.Info.VTOL)
{
// Set final (horizontal) position
if (delta.HorizontalLengthSquared != 0)

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Activities
// We can't possibly turn this fast
var desiredFacing = aircraft.Facing + 64;
// This override is necessary, otherwise aircraft with Slide flag would circle sideways
// This override is necessary, otherwise aircraft with CanSlide would circle sideways
var move = aircraft.FlyStep(aircraft.Facing);
Fly.FlyTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude, move, turnSpeedOverride);

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Activities
// otherwise if it is hidden or dead we give up
if (checkTarget.IsInRange(pos, maxRange) && !checkTarget.IsInRange(pos, minRange))
{
if (!aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.Hover))
if (!aircraft.Info.CanHover)
Fly.FlyTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude);
return useLastVisibleTarget;

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Activities
// NOTE: desiredFacing = -1 means we should not prefer any particular facing and instead just
// use whatever facing gives us the most direct path to the landing site.
if (facing == -1 && aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.TurnToLand))
if (facing == -1 && aircraft.Info.TurnToLand)
desiredFacing = aircraft.Info.InitialFacing;
else
desiredFacing = facing;
@@ -130,7 +130,7 @@ namespace OpenRA.Mods.Common.Activities
}
// Move towards landing location
if (aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.VTOL) && (pos - targetPosition).HorizontalLengthSquared != 0)
if (aircraft.Info.VTOL && (pos - targetPosition).HorizontalLengthSquared != 0)
{
QueueChild(new Fly(self, Target.FromPos(targetPosition)));
@@ -140,7 +140,7 @@ namespace OpenRA.Mods.Common.Activities
return false;
}
if (!aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.VTOL) && !finishedApproach)
if (!aircraft.Info.VTOL && !finishedApproach)
{
// Calculate approach trajectory
var altitude = aircraft.Info.CruiseAltitude.Length;
@@ -207,7 +207,7 @@ namespace OpenRA.Mods.Common.Activities
if (!aircraft.CanLand(blockingCells, target.Actor))
{
// Maintain holding pattern.
if (aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.Hover))
if (aircraft.Info.CanHover)
QueueChild(new Wait(25));
else
QueueChild(new FlyCircle(self, 25));
@@ -226,7 +226,7 @@ namespace OpenRA.Mods.Common.Activities
}
// Final descent.
if (aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.VTOL))
if (aircraft.Info.VTOL)
{
var landAltitude = self.World.Map.DistanceAboveTerrain(targetPosition) + aircraft.LandAltitude;
if (Fly.VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, landAltitude))

View File

@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Activities
if (nearestResupplier != null)
{
if (aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.Hover))
if (aircraft.Info.CanHover)
{
var distanceFromResupplier = (nearestResupplier.CenterPosition - self.CenterPosition).HorizontalLength;
var distanceLength = aircraft.Info.WaitDistanceFromResupplyBase.Length;
@@ -113,9 +113,9 @@ namespace OpenRA.Mods.Common.Activities
{
var exit = dest.FirstExitOrDefault(null);
var offset = exit != null ? exit.Info.SpawnOffset : WVec.Zero;
if (aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.TurnToDock))
if (aircraft.Info.TurnToDock)
facing = aircraft.Info.InitialFacing;
if (!aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.VTOL))
if (!aircraft.Info.VTOL)
facing = 192;
aircraft.MakeReservation(dest);

View File

@@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.Activities
if (dat < aircraft.Info.CruiseAltitude)
{
// If we're a VTOL, rise before flying forward
if (aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.VTOL))
if (aircraft.Info.VTOL)
{
Fly.VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude);
return false;
@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Activities
// Checking for NextActivity == null again in case another activity was queued while taking off
if (moveToRallyPoint && NextActivity == null)
{
if (!aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.VTOL) && assignTargetOnFirstRun)
if (!aircraft.Info.VTOL && assignTargetOnFirstRun)
return true;
QueueChild(new AttackMoveActivity(self, () => move.MoveToTarget(self, target)));

View File

@@ -157,7 +157,7 @@ namespace OpenRA.Mods.Common.Activities
{
aircraft.AllowYieldingReservation();
if (wasRepaired ||
(!stayOnResupplier && aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.TakeOffOnResupply)))
(!stayOnResupplier && aircraft.Info.TakeOffOnResupply))
QueueChild(new TakeOff(self));
}
else if (!stayOnResupplier)

View File

@@ -21,34 +21,9 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Flags]
public enum FlightDynamic
{
None = 0,
MoveIntoShroud = 1,
Slide = 2,
Hover = 4,
VTOL = 8,
TurnToLand = 16,
TurnToDock = 32,
TakeOffOnResupply = 64,
TakeOffOnCreation = 128,
}
public class AircraftInfo : ITraitInfo, IPositionableInfo, IFacingInfo, IMoveInfo, ICruiseAltitudeInfo,
IActorPreviewInitInfo, IEditorActorOptions, IObservesVariablesInfo
{
[Desc("List of flags that alter the movement behavior. Options:",
"MoveIntoShroud = Can be ordered to move into shroud.",
"Slide = Changes direction immediately, independently of current facing. Without this flag, needs to fly a curve.",
"Hover = Able to statically hover in air while idle or waiting. Without this flag, aircraft will fly in circles.",
"VTOL = Vertical-only take-off/land. Without this flag, lands/takes off diagonally.",
"TurnToLand = Does the aircraft need to turn towards InitialFacing before landing on terrain? No effect if VTOL flag is missing.",
"TurnToDock = Does the aircraft need to turn towards InitialFacing before landing on dock? No effect if VTOL flag is missing.",
"TakeOffOnResupply = Take off as soon as resupplies/repairs are finished.",
"TakeOffOnCreation = Take off from creator when spawned.")]
public readonly FlightDynamic FlightDynamics = FlightDynamic.TakeOffOnCreation | FlightDynamic.MoveIntoShroud;
public readonly WDist CruiseAltitude = new WDist(1280);
[Desc("Whether the aircraft can be repulsed.")]
@@ -74,6 +49,9 @@ namespace OpenRA.Mods.Common.Traits
public readonly HashSet<string> LandableTerrainTypes = new HashSet<string>();
[Desc("Can the actor be ordered to move in to shroud?")]
public readonly bool MoveIntoShroud = true;
[Desc("e.g. crate, wall, infantry")]
public readonly BitSet<CrushClass> Crushes = default(BitSet<CrushClass>);
@@ -91,9 +69,33 @@ namespace OpenRA.Mods.Common.Traits
[Desc("The condition to grant to self while at cruise altitude.")]
public readonly string CruisingCondition = null;
[Desc("Can the actor hover in place mid-air? If not, then the actor will have to remain in motion (circle around).")]
public readonly bool CanHover = false;
[Desc("Can the actor immediately change direction without turning first (doesn't need to fly in a curve)?")]
public readonly bool CanSlide = false;
[Desc("Does the actor land and take off vertically?")]
public readonly bool VTOL = false;
[Desc("Will this actor try to land after it has no more commands?")]
public readonly bool LandWhenIdle = true;
[Desc("Does this VTOL actor need to turn before landing (on terrain)?")]
public readonly bool TurnToLand = false;
[Desc("Does this VTOL actor need to turn before landing on a resupplier?")]
public readonly bool TurnToDock = true;
[Desc("Does this actor cancel its previous activity after resupplying?")]
public readonly bool AbortOnResupply = true;
[Desc("Does this actor automatically take off after resupplying?")]
public readonly bool TakeOffOnResupply = false;
[Desc("Does this actor automatically take off after creation?")]
public readonly bool TakeOffOnCreation = true;
[Desc("Altitude at which the aircraft considers itself landed.")]
public readonly WDist LandAltitude = WDist.Zero;
@@ -345,7 +347,7 @@ namespace OpenRA.Mods.Common.Traits
MakeReservation(host);
if (Info.FlightDynamics.HasFlag(FlightDynamic.TakeOffOnCreation))
if (Info.TakeOffOnCreation)
self.QueueActivity(new TakeOff(self));
}
@@ -441,7 +443,7 @@ namespace OpenRA.Mods.Common.Traits
repulsionForce += new WVec(1024, 0, 0).Rotate(WRot.FromYaw((self.CenterPosition - center).Yaw));
}
if (Info.FlightDynamics.HasFlag(FlightDynamic.Slide))
if (Info.CanSlide)
return repulsionForce;
// Non-hovering actors mush always keep moving forward, so they need extra calculations.
@@ -682,7 +684,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
var isCircler = !Info.FlightDynamics.HasFlag(FlightDynamic.Hover);
var isCircler = !Info.CanHover;
if (!atLandAltitude && Info.LandWhenIdle && Info.LandableTerrainTypes.Count > 0)
self.QueueActivity(new Land(self));
else if (isCircler && !atLandAltitude)
@@ -935,7 +937,7 @@ namespace OpenRA.Mods.Common.Traits
{
case "Land":
case "Move":
if (!Info.FlightDynamics.HasFlag(FlightDynamic.MoveIntoShroud) && order.Target.Type != TargetType.Invalid)
if (!Info.MoveIntoShroud && order.Target.Type != TargetType.Invalid)
{
var cell = self.World.Map.CellContaining(order.Target.CenterPosition);
if (!self.Owner.Shroud.IsExplored(cell))
@@ -960,7 +962,7 @@ namespace OpenRA.Mods.Common.Traits
if (orderString == "Move")
{
var cell = self.World.Map.Clamp(self.World.Map.CellContaining(order.Target.CenterPosition));
if (!Info.FlightDynamics.HasFlag(FlightDynamic.MoveIntoShroud) && !self.Owner.Shroud.IsExplored(cell))
if (!Info.MoveIntoShroud && !self.Owner.Shroud.IsExplored(cell))
return;
if (!order.Queued)
@@ -973,7 +975,7 @@ namespace OpenRA.Mods.Common.Traits
else if (orderString == "Land")
{
var cell = self.World.Map.Clamp(self.World.Map.CellContaining(order.Target.CenterPosition));
if (!Info.FlightDynamics.HasFlag(FlightDynamic.MoveIntoShroud) && !self.Owner.Shroud.IsExplored(cell))
if (!Info.MoveIntoShroud && !self.Owner.Shroud.IsExplored(cell))
return;
if (!order.Queued)
@@ -1003,7 +1005,7 @@ namespace OpenRA.Mods.Common.Traits
// Aircraft with TakeOffOnResupply would immediately take off again, so there's no point in automatically forcing
// them to land on a resupplier. For aircraft without it, it makes more sense to land than to idle above a
// free resupplier.
var forceLand = orderString == "ForceEnter" || !Info.FlightDynamics.HasFlag(FlightDynamic.TakeOffOnResupply);
var forceLand = orderString == "ForceEnter" || !Info.TakeOffOnResupply;
self.QueueActivity(order.Queued, new ReturnToBase(self, targetActor, forceLand));
}
else if (orderString == "Stop")
@@ -1028,7 +1030,7 @@ namespace OpenRA.Mods.Common.Traits
// Aircraft with TakeOffOnResupply would immediately take off again, so there's no point in forcing them to land
// on a resupplier. For aircraft without it, it makes more sense to land than to idle above a free resupplier.
self.QueueActivity(order.Queued, new ReturnToBase(self, null, !Info.FlightDynamics.HasFlag(FlightDynamic.TakeOffOnResupply)));
self.QueueActivity(order.Queued, new ReturnToBase(self, null, !Info.TakeOffOnResupply));
}
else if (orderString == "Scatter")
Nudge(self);
@@ -1146,7 +1148,7 @@ namespace OpenRA.Mods.Common.Traits
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
if (!explored && !aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.MoveIntoShroud))
if (!explored && !aircraft.Info.MoveIntoShroud)
cursor = "move-blocked";
return true;

View File

@@ -293,7 +293,7 @@ namespace OpenRA.Mods.Common.Traits
if (order.OrderString == "DeliverUnit")
{
var cell = self.World.Map.Clamp(self.World.Map.CellContaining(order.Target.CenterPosition));
if (!aircraftInfo.FlightDynamics.HasFlag(FlightDynamic.MoveIntoShroud) && !self.Owner.Shroud.IsExplored(cell))
if (!aircraftInfo.MoveIntoShroud && !self.Owner.Shroud.IsExplored(cell))
return;
var targetLocation = move.NearestMoveableCell(cell);
@@ -406,7 +406,7 @@ namespace OpenRA.Mods.Common.Traits
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
if (!explored && !aircraftInfo.FlightDynamics.HasFlag(FlightDynamic.MoveIntoShroud))
if (!explored && !aircraftInfo.MoveIntoShroud)
cursor = info.DropOffBlockedCursor;
return true;