Make Aircraft actually pausable/disableable

This commit makes aircraft
- ignore any aircraft-specific orders while disabled
- show blocked move cursor while paused
- set speeds to zero while paused or disabled
This commit is contained in:
reaperrr
2019-09-21 21:04:12 +02:00
committed by Paul Chote
parent 4b006bc484
commit 4499343ed2
2 changed files with 27 additions and 13 deletions

View File

@@ -117,6 +117,13 @@ namespace OpenRA.Mods.Common.Activities
Cancel(self); Cancel(self);
var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition); var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition);
var isLanded = dat <= aircraft.LandAltitude;
// HACK: Prevent paused (for example, EMP'd) aircraft from taking off.
// This is necessary until the TODOs in the IsCanceling block below are adressed.
if (isLanded && aircraft.IsTraitPaused)
return false;
if (IsCanceling) if (IsCanceling)
{ {
// We must return the actor to a sensible height before continuing. // We must return the actor to a sensible height before continuing.
@@ -128,7 +135,7 @@ namespace OpenRA.Mods.Common.Activities
var skipHeightAdjustment = landWhenIdle && self.CurrentActivity.IsCanceling && self.CurrentActivity.NextActivity == null; var skipHeightAdjustment = landWhenIdle && self.CurrentActivity.IsCanceling && self.CurrentActivity.NextActivity == null;
if (aircraft.Info.CanHover && !skipHeightAdjustment && dat != aircraft.Info.CruiseAltitude) if (aircraft.Info.CanHover && !skipHeightAdjustment && dat != aircraft.Info.CruiseAltitude)
{ {
if (dat <= aircraft.LandAltitude) if (isLanded)
QueueChild(new TakeOff(self)); QueueChild(new TakeOff(self));
else else
VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude); VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude);
@@ -138,7 +145,7 @@ namespace OpenRA.Mods.Common.Activities
return true; return true;
} }
else if (dat <= aircraft.LandAltitude) else if (isLanded)
{ {
QueueChild(new TakeOff(self)); QueueChild(new TakeOff(self));
return false; return false;

View File

@@ -213,7 +213,7 @@ namespace OpenRA.Mods.Common.Traits
public WPos CenterPosition { get; private set; } public WPos CenterPosition { get; private set; }
public CPos TopLeft { get { return self.World.Map.CellContaining(CenterPosition); } } public CPos TopLeft { get { return self.World.Map.CellContaining(CenterPosition); } }
public int TurnSpeed { get { return Info.TurnSpeed; } } public int TurnSpeed { get { return !IsTraitDisabled && !IsTraitPaused ? Info.TurnSpeed : 0; } }
public Actor ReservedActor { get; private set; } public Actor ReservedActor { get; private set; }
public bool MayYieldReservation { get; private set; } public bool MayYieldReservation { get; private set; }
public bool ForceLanding { get; private set; } public bool ForceLanding { get; private set; }
@@ -548,7 +548,7 @@ namespace OpenRA.Mods.Common.Traits
public int MovementSpeed public int MovementSpeed
{ {
get { return Util.ApplyPercentageModifiers(Info.Speed, speedModifiers); } get { return !IsTraitDisabled && !IsTraitPaused ? Util.ApplyPercentageModifiers(Info.Speed, speedModifiers) : 0; }
} }
public Pair<CPos, SubCell>[] OccupiedCells() public Pair<CPos, SubCell>[] OccupiedCells()
@@ -953,7 +953,8 @@ namespace OpenRA.Mods.Common.Traits
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued) public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
{ {
if (order.OrderID == "Enter" || order.OrderID == "Move" || order.OrderID == "Land" || order.OrderID == "ForceEnter") if (!IsTraitDisabled &&
(order.OrderID == "Enter" || order.OrderID == "Move" || order.OrderID == "Land" || order.OrderID == "ForceEnter"))
return new Order(order.OrderID, self, target, queued); return new Order(order.OrderID, self, target, queued);
return null; return null;
@@ -961,7 +962,7 @@ namespace OpenRA.Mods.Common.Traits
Order IIssueDeployOrder.IssueDeployOrder(Actor self, bool queued) Order IIssueDeployOrder.IssueDeployOrder(Actor self, bool queued)
{ {
if (rearmable == null || !rearmable.Info.RearmActors.Any()) if (IsTraitDisabled || rearmable == null || !rearmable.Info.RearmActors.Any())
return null; return null;
return new Order("ReturnToBase", self, queued); return new Order("ReturnToBase", self, queued);
@@ -971,6 +972,9 @@ namespace OpenRA.Mods.Common.Traits
public string VoicePhraseForOrder(Actor self, Order order) public string VoicePhraseForOrder(Actor self, Order order)
{ {
if (IsTraitDisabled)
return null;
switch (order.OrderString) switch (order.OrderString)
{ {
case "Land": case "Land":
@@ -996,6 +1000,9 @@ namespace OpenRA.Mods.Common.Traits
public void ResolveOrder(Actor self, Order order) public void ResolveOrder(Actor self, Order order)
{ {
if (IsTraitDisabled)
return;
var orderString = order.OrderString; var orderString = order.OrderString;
if (orderString == "Move") if (orderString == "Move")
{ {
@@ -1085,6 +1092,9 @@ namespace OpenRA.Mods.Common.Traits
void Nudge(Actor self) void Nudge(Actor self)
{ {
if (IsTraitDisabled || IsTraitPaused || requireForceMove)
return;
// Disable nudging if the aircraft is outside the map // Disable nudging if the aircraft is outside the map
if (!self.World.Map.Contains(self.Location)) if (!self.World.Map.Contains(self.Location))
return; return;
@@ -1204,15 +1214,12 @@ namespace OpenRA.Mods.Common.Traits
OrderID = "Land"; OrderID = "Land";
} }
var explored = self.Owner.Shroud.IsExplored(location);
cursor = self.World.Map.Contains(location) ?
(self.World.Map.GetTerrainInfo(location).CustomCursor ?? "move") :
"move-blocked";
IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue); IsQueued = modifiers.HasModifier(TargetModifiers.ForceQueue);
if (!explored && !aircraft.Info.MoveIntoShroud) var explored = self.Owner.Shroud.IsExplored(location);
cursor = "move-blocked"; cursor = !aircraft.IsTraitPaused && (explored || aircraft.Info.MoveIntoShroud) && self.World.Map.Contains(location) ?
(self.World.Map.GetTerrainInfo(location).CustomCursor ?? "move") :
"move-blocked";
return true; return true;
} }