Skip to content

Commit

Permalink
Add IdleBehavior enum to Aircraft
Browse files Browse the repository at this point in the history
  • Loading branch information
reaperrr committed Jun 11, 2019
1 parent 522c833 commit 82b14ba
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 125 deletions.
3 changes: 2 additions & 1 deletion OpenRA.Mods.Common/Activities/Air/Fly.cs
Expand Up @@ -122,7 +122,8 @@ public override Activity Tick(Actor self)
// TODO: It would be better to not take off at all, but we lack the plumbing to detect current airborne/landed state.
// 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;
var shouldLand = aircraft.Info.IdleBehavior == IdleBehaviorType.Land;
var skipHeightAdjustment = shouldLand && self.CurrentActivity.IsCanceling && self.CurrentActivity.NextActivity == null;
if (aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.Hover) && !skipHeightAdjustment && dat != aircraft.Info.CruiseAltitude)
{
if (dat <= aircraft.LandAltitude)
Expand Down
3 changes: 2 additions & 1 deletion OpenRA.Mods.Common/Activities/Air/Land.cs
Expand Up @@ -52,7 +52,8 @@ public override Activity Tick(Actor self)
// If the aircraft lands when idle and is idle, continue landing,
// otherwise climb back to CruiseAltitude.
// TODO: Remove this after fixing all activities to work properly with arbitrary starting altitudes.
var continueLanding = aircraft.Info.LandWhenIdle && self.CurrentActivity.IsCanceling && self.CurrentActivity.NextActivity == null;
var shouldLand = aircraft.Info.IdleBehavior == IdleBehaviorType.Land;
var continueLanding = shouldLand && self.CurrentActivity.IsCanceling && self.CurrentActivity.NextActivity == null;
if (!continueLanding)
{
var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition);
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs
Expand Up @@ -186,9 +186,9 @@ public override Activity Tick(Actor self)
return this;
}
}
else if (nearestResupplier == null && isVTOL && aircraft.Info.LandWhenIdle)
else if (nearestResupplier == null && isVTOL && aircraft.Info.IdleBehavior == IdleBehaviorType.Land)
{
// Using Queue instead of QueueChild here is intentional, as we want VTOLs with LandWhenIdle to land and stay there in this situation
// Using Queue instead of QueueChild here is intentional, as we want VTOLs that land on idle to land and stay there in this situation
Cancel(self);
if (aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.TurnToLand))
Queue(self, new Turn(self, aircraft.Info.InitialFacing));
Expand Down
53 changes: 44 additions & 9 deletions OpenRA.Mods.Common/Traits/Air/Aircraft.cs
Expand Up @@ -35,6 +35,14 @@ public enum FlightDynamic
MoveIntoShroud = 128,
}

public enum IdleBehaviorType
{
None, // Aircraft will hover or fly in circles, depending on FlightDynamics. This is also the fallback if one of the below fails.
Land,
ReturnToBase,
LeaveMap,
}

public class AircraftInfo : ITraitInfo, IPositionableInfo, IFacingInfo, IMoveInfo, ICruiseAltitudeInfo,
IActorPreviewInitInfo, IEditorActorOptions, IObservesVariablesInfo
{
Expand All @@ -44,6 +52,10 @@ public class AircraftInfo : ITraitInfo, IPositionableInfo, IFacingInfo, IMoveInf
"Hover = Able to statically hover in air while idle or waiting. Without this flag, aircraft will fly in circles.")]
public readonly FlightDynamic FlightDynamics = FlightDynamic.TakeOffOnCreation | FlightDynamic.MoveIntoShroud;

[Desc("Behavior when aircraft becomes idle. Options are Land, ReturnToBase, LeaveMap, and None.",
"'None' will make the aircraft hover (if it has Hover FlightDynamic) or fly in circles and also serves as fallback.")]
public readonly IdleBehaviorType IdleBehavior = IdleBehaviorType.None;

public readonly WDist CruiseAltitude = new WDist(1280);

[Desc("Whether the aircraft can be repulsed.")]
Expand Down Expand Up @@ -86,9 +98,6 @@ public class AircraftInfo : ITraitInfo, IPositionableInfo, IFacingInfo, IMoveInf
[Desc("The condition to grant to self while at cruise altitude.")]
public readonly string CruisingCondition = null;

[Desc("Will this actor try to land after it has no more commands?")]
public readonly bool LandWhenIdle = true;

[Desc("Does this actor cancel its previous activity after resupplying?")]
public readonly bool AbortOnResupply = true;

Expand Down Expand Up @@ -350,7 +359,7 @@ protected virtual void Tick(Actor self)
{
ForceLanding = false;

if (!Info.LandWhenIdle)
if (Info.IdleBehavior != IdleBehaviorType.Land)
{
self.CancelActivity();

Expand Down Expand Up @@ -637,19 +646,45 @@ protected virtual void OnBecomingIdle(Actor self)
}
}

var isCircler = !Info.FlightDynamics.HasFlag(FlightDynamic.Hover);
if (!atLandAltitude && Info.LandWhenIdle)
if (atLandAltitude && !CanLand(self.Location) && ReservedActor == null)
{
self.QueueActivity(new TakeOff(self));
return;
}

if (Info.IdleBehavior == IdleBehaviorType.Land)
{
if (atLandAltitude)
return;

var shouldTurn = Info.FlightDynamics.HasFlag(FlightDynamic.VTOL) && Info.FlightDynamics.HasFlag(FlightDynamic.TurnToLand);
if (shouldTurn)
self.QueueActivity(new Turn(self, Info.InitialFacing));

self.QueueActivity(new Land(self));
return;
}
else if (isCircler && !atLandAltitude)
else if (Info.IdleBehavior == IdleBehaviorType.ReturnToBase)
{
// If we're already on a resupplier, do nothing
if (GetActorBelow() != null)
return;

// 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, though.
self.QueueActivity(new ReturnToBase(self, Info.AbortOnResupply, null, !Info.FlightDynamics.HasFlag(FlightDynamic.TakeOffOnResupply)));
return;
}
else if (Info.IdleBehavior == IdleBehaviorType.LeaveMap)
{
self.QueueActivity(new FlyOffMap(self));
self.QueueActivity(new RemoveSelf());
return;
}

var isCircler = !Info.FlightDynamics.HasFlag(FlightDynamic.Hover);
if (isCircler && !atLandAltitude)
self.QueueActivity(new FlyCircle(self, -1, Info.IdleTurnSpeed > -1 ? Info.IdleTurnSpeed : TurnSpeed));
else if (atLandAltitude && !CanLand(self.Location) && ReservedActor == null)
self.QueueActivity(new TakeOff(self));
}

#region Implement IPositionable
Expand Down
28 changes: 0 additions & 28 deletions OpenRA.Mods.Common/Traits/Air/FlyAwayOnIdle.cs

This file was deleted.

68 changes: 0 additions & 68 deletions OpenRA.Mods.Common/Traits/Air/ReturnOnIdle.cs

This file was deleted.

2 changes: 1 addition & 1 deletion mods/cnc/rules/aircraft.yaml
Expand Up @@ -12,7 +12,7 @@ TRAN:
Queue: Aircraft.GDI, Aircraft.Nod
Description: Fast Infantry Transport Helicopter.\n Unarmed
Aircraft:
LandWhenIdle: true
IdleBehavior: Land
TurnSpeed: 5
Speed: 150
LandableTerrainTypes: Clear, Rough, Road, Beach, Tiberium, BlueTiberium
Expand Down
3 changes: 1 addition & 2 deletions mods/cnc/rules/defaults.yaml
Expand Up @@ -312,7 +312,6 @@
Repairable:
RepairActors: hpad
Aircraft:
LandWhenIdle: false
AirborneCondition: airborne
CruisingCondition: cruising
FlightDynamics: VTOL, Slide, Hover, MoveIntoShroud, TakeOffOnCreation, TakeOffOnResupply, TurnToDock
Expand Down Expand Up @@ -641,10 +640,10 @@
Offset: 43, 128, 0
ZOffset: -129
WithFacingSpriteBody:
FlyAwayOnIdle:
RejectsOrders:
Aircraft:
CruiseAltitude: 2560
IdleBehavior: LeaveMap
MapEditorData:
Categories: Aircraft

Expand Down
3 changes: 1 addition & 2 deletions mods/d2k/rules/aircraft.yaml
Expand Up @@ -17,7 +17,6 @@ carryall.reinforce:
TurnSpeed: 4
LandableTerrainTypes: Sand, Rock, Transition, Spice, SpiceSand, Dune, Concrete
Repulsable: False
LandWhenIdle: False
AirborneCondition: airborne
IdleTurnSpeed: 1
Targetable@GROUND:
Expand Down Expand Up @@ -77,6 +76,7 @@ frigate:
Name: Frigate
Aircraft:
FlightDynamics: VTOL, Hover, MoveIntoShroud, TakeOffOnCreation
IdleBehavior: LeaveMap
Speed: 189
TurnSpeed: 1
Repulsable: False
Expand All @@ -87,7 +87,6 @@ frigate:
Cargo:
MaxWeight: 20
PipCount: 10
FlyAwayOnIdle:
RejectsOrders:

ornithopter:
Expand Down
5 changes: 1 addition & 4 deletions mods/ra/rules/aircraft.yaml
Expand Up @@ -125,7 +125,6 @@ MIG:
AmmoPool:
Ammo: 8
AmmoCondition: ammo
ReturnOnIdle:
Selectable:
Bounds: 36,28,0,2
DecorationBounds: 40,29,0,1
Expand Down Expand Up @@ -197,7 +196,6 @@ YAK:
PipCount: 6
ReloadDelay: 11
AmmoCondition: ammo
ReturnOnIdle:
SelectionDecorations:
WithMuzzleOverlay:
Contrail:
Expand Down Expand Up @@ -243,6 +241,7 @@ TRAN:
LandableTerrainTypes: Clear,Rough,Road,Ore,Beach,Gems
Crushes: crate, mine, infantry
AltitudeVelocity: 0c58
IdleBehavior: Land
WithIdleOverlay@ROTOR1AIR:
Offset: 597,0,213
Sequence: rotor
Expand Down Expand Up @@ -307,7 +306,6 @@ HELI:
PersistentTargeting: false
AttackType: Hover
Aircraft:
LandWhenIdle: false
TurnSpeed: 4
Speed: 149
AutoTarget:
Expand Down Expand Up @@ -376,7 +374,6 @@ HIND:
PersistentTargeting: false
AttackType: Hover
Aircraft:
LandWhenIdle: false
TurnSpeed: 4
Speed: 112
AutoTarget:
Expand Down
11 changes: 5 additions & 6 deletions mods/ts/rules/aircraft.yaml
Expand Up @@ -6,7 +6,7 @@ DPOD:
Tooltip:
Name: Drop Pod
Aircraft:
LandWhenIdle: true
IdleBehavior: Land
TurnSpeed: 5
Speed: 149
InitialFacing: 0
Expand Down Expand Up @@ -42,7 +42,6 @@ DSHP:
UpdatesPlayerStatistics:
AddToArmyValue: true
Aircraft:
LandWhenIdle: true
TurnSpeed: 5
Speed: 168
InitialFacing: 0
Expand Down Expand Up @@ -94,6 +93,8 @@ ORCA:
TakeoffSounds: orcaup1.aud
LandingSounds: orcadwn1.aud
AltitudeVelocity: 128
FlightDynamics: VTOL, Hover, TakeOffOnCreation, TakeOffOnResupply, TurnToDock
IdleBehavior: None
Health:
HP: 20000
Armor:
Expand Down Expand Up @@ -147,7 +148,6 @@ ORCAB:
CruisingCondition: cruising
TakeoffSounds: orcaup1.aud
LandingSounds: orcadwn1.aud
ReturnOnIdle:
Health:
HP: 26000
Armor:
Expand Down Expand Up @@ -193,7 +193,6 @@ ORCATRAN:
Prerequisites: ~disabled
RenderSprites:
Aircraft:
LandWhenIdle: true
TurnSpeed: 5
Speed: 84
LandableTerrainTypes: Clear,Road,Rail,DirtRoad,Rough,Tiberium,BlueTiberium,Veins
Expand Down Expand Up @@ -232,7 +231,6 @@ TRNSPORT:
Prerequisites: ~gahpad, gadept
Description: VTOL aircraft capable of lifting\nand transporting vehicles.\n Unarmed
Aircraft:
LandWhenIdle: true
TurnSpeed: 5
Speed: 149
InitialFacing: 0
Expand Down Expand Up @@ -283,7 +281,6 @@ SCRIN:
AirborneCondition: airborne
TakeoffSounds: dropup1.aud
LandingSounds: dropdwn1.aud
ReturnOnIdle:
Health:
HP: 28000
Armor:
Expand Down Expand Up @@ -334,6 +331,8 @@ APACHE:
Aircraft:
TurnSpeed: 5
Speed: 130
FlightDynamics: VTOL, Hover, TakeOffOnCreation, TakeOffOnResupply, TurnToDock
IdleBehavior: None
Health:
HP: 22500
Armor:
Expand Down
3 changes: 2 additions & 1 deletion mods/ts/rules/defaults.yaml
Expand Up @@ -861,9 +861,10 @@
Aircraft:
AirborneCondition: airborne
CruisingCondition: cruising
InitialFacing: 224
CruiseAltitude: 4c704
AltitudeVelocity: 96
LandWhenIdle: false
IdleBehavior: Land
Voice: Move
IdealSeparation: 853
MaximumPitch: 120
Expand Down

0 comments on commit 82b14ba

Please sign in to comment.