Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent bogus attackmove on take-off. #17017

Merged
merged 4 commits into from Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Activities/Air/Fly.cs
Expand Up @@ -129,7 +129,7 @@ public override bool Tick(Actor self)
if (aircraft.Info.CanHover && !skipHeightAdjustment && dat != aircraft.Info.CruiseAltitude)
{
if (dat <= aircraft.LandAltitude)
QueueChild(new TakeOff(self, target));
QueueChild(new TakeOff(self));
else
VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude);

Expand All @@ -140,7 +140,7 @@ public override bool Tick(Actor self)
}
else if (dat <= aircraft.LandAltitude)
{
QueueChild(new TakeOff(self, target));
QueueChild(new TakeOff(self));
return false;
}

Expand Down
28 changes: 2 additions & 26 deletions OpenRA.Mods.Common/Activities/Air/TakeOff.cs
Expand Up @@ -21,19 +21,13 @@ public class TakeOff : Activity
{
readonly Aircraft aircraft;
readonly IMove move;
Target fallbackTarget;
bool movedToTarget = false;

public TakeOff(Actor self, Target fallbackTarget)
public TakeOff(Actor self)
{
aircraft = self.Trait<Aircraft>();
move = self.Trait<IMove>();
this.fallbackTarget = fallbackTarget;
}

public TakeOff(Actor self)
: this(self, Target.Invalid) { }

protected override void OnFirstRun(Actor self)
{
if (aircraft.ForceLanding)
Expand All @@ -42,8 +36,7 @@ protected override void OnFirstRun(Actor self)
if (self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition).Length >= aircraft.Info.MinAirborneAltitude)
return;

// We are taking off, so remove reservation and influence in ground cells.
aircraft.UnReserve();
// We are taking off, so remove influence in ground cells.
aircraft.RemoveInfluence();

if (aircraft.Info.TakeoffSounds.Length > 0)
Expand Down Expand Up @@ -73,24 +66,7 @@ public override bool Tick(Actor self)
return false;
}

// Only move to the fallback target if we don't have anything better to do
if (NextActivity == null && fallbackTarget.IsValidFor(self) && !movedToTarget)
{
QueueChild(new AttackMoveActivity(self, () => move.MoveToTarget(self, fallbackTarget, targetLineColor: Color.OrangeRed)));
movedToTarget = true;
return false;
}

return true;
}

public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (ChildActivity != null)
foreach (var n in ChildActivity.TargetLineNodes(self))
yield return n;
else
yield return new TargetLineNode(fallbackTarget, Color.OrangeRed);
}
}
}
6 changes: 4 additions & 2 deletions OpenRA.Mods.Common/Activities/Resupply.cs
Expand Up @@ -187,10 +187,12 @@ void OnResupplyEnding(Actor self, bool isHostInvalid = false)
{
if (wasRepaired || isHostInvalid || (!stayOnResupplier && aircraft.Info.TakeOffOnResupply))
{
if (rp != null)
QueueChild(move.MoveTo(rp.Location, repairableNear != null ? null : host.Actor));
if (self.CurrentActivity.NextActivity == null && rp != null)
QueueChild(move.MoveTo(rp.Location, repairableNear != null ? null : host.Actor, targetLineColor: Color.Green));
else
QueueChild(new TakeOff(self));

aircraft.UnReserve();
}

// Aircraft without TakeOffOnResupply remain on the resupplier until something else needs it
Expand Down
13 changes: 1 addition & 12 deletions OpenRA.Mods.Common/Traits/Air/Aircraft.cs
Expand Up @@ -506,26 +506,15 @@ public void AllowYieldingReservation()
MayYieldReservation = true;
}

public void UnReserve(bool takeOff = false)
public void UnReserve()
{
if (reservation == null)
return;

// Move to the host's rally point if it has one
var rp = ReservedActor != null ? ReservedActor.TraitOrDefault<RallyPoint>() : null;

reservation.Dispose();
reservation = null;
ReservedActor = null;
MayYieldReservation = false;

if (takeOff && self.World.Map.DistanceAboveTerrain(CenterPosition).Length <= LandAltitude.Length)
{
if (rp != null)
self.QueueActivity(new TakeOff(self, Target.FromCell(self.World, rp.Location)));
else
self.QueueActivity(new TakeOff(self));
}
}

bool AircraftCanEnter(Actor a, TargetModifiers modifiers)
Expand Down
33 changes: 25 additions & 8 deletions OpenRA.Mods.Common/Traits/Buildings/Reservable.cs
Expand Up @@ -10,6 +10,7 @@
#endregion

using System;
using OpenRA.Mods.Common.Activities;
using OpenRA.Primitives;
using OpenRA.Traits;

Expand All @@ -18,10 +19,16 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Reserve landing places for aircraft.")]
class ReservableInfo : TraitInfo<Reservable> { }

public class Reservable : ITick, INotifyOwnerChanged, INotifySold, INotifyActorDisposing
public class Reservable : ITick, INotifyOwnerChanged, INotifySold, INotifyActorDisposing, INotifyCreated
{
Actor reservedFor;
Aircraft reservedForAircraft;
RallyPoint rallyPoint;

void INotifyCreated.Created(Actor self)
{
rallyPoint = self.TraitOrDefault<RallyPoint>();
}

void ITick.Tick(Actor self)
{
Expand All @@ -41,7 +48,7 @@ void ITick.Tick(Actor self)
public IDisposable Reserve(Actor self, Actor forActor, Aircraft forAircraft)
{
if (reservedForAircraft != null && reservedForAircraft.MayYieldReservation)
reservedForAircraft.UnReserve(true);
UnReserve(self);

reservedFor = forActor;
reservedForAircraft = forAircraft;
Expand Down Expand Up @@ -71,17 +78,27 @@ public static bool IsAvailableFor(Actor reservable, Actor forActor)
return res == null || res.reservedForAircraft == null || res.reservedForAircraft.MayYieldReservation || res.reservedFor == forActor;
}

private void UnReserve()
void UnReserve(Actor self)
{
if (reservedForAircraft != null)
reservedForAircraft.UnReserve(true);
{
if (reservedForAircraft.GetActorBelow() == self)
{
if (rallyPoint != null)
reservedFor.QueueActivity(reservedForAircraft.MoveTo(rallyPoint.Location, null, targetLineColor: Color.Green));
abcdefg30 marked this conversation as resolved.
Show resolved Hide resolved
else
reservedFor.QueueActivity(new TakeOff(reservedFor));
}

reservedForAircraft.UnReserve();
}
}

void INotifyActorDisposing.Disposing(Actor self) { UnReserve(); }
void INotifyActorDisposing.Disposing(Actor self) { UnReserve(self); }

void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) { UnReserve(); }
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) { UnReserve(self); }

void INotifySold.Selling(Actor self) { UnReserve(); }
void INotifySold.Sold(Actor self) { UnReserve(); }
void INotifySold.Selling(Actor self) { UnReserve(self); }
void INotifySold.Sold(Actor self) { UnReserve(self); }
}
}