Files
OpenRA/OpenRA.Mods.Common/Activities/DeliverUnit.cs
RoosterDragon d2a3659078 Fix landed aircraft above ground level not removing influence on take off.
When the Land activity is run, the aircraft adds influence to the cell so it cannot be used by other actors. When the TakeOff activity runs, it removes the influence so the cell can be used by other actors.

However, when a Carryall picks up a unit, it is told to Land with a vertical offset - it never reaches ground level. When the TakeOff activity runs, it saw the aircraft was above ground level and bailed out. The means the influence is never removed. The cell is now unusable despite the fact the Carryall has left.

To fix this, TakeOff now checks if influence was applied instead of checking if the aircraft is above ground level. If so, we know the Land activity had decided that influence was required, even if the aircraft has not made it to ground level. When TakeOff runs, it will treat it as a proper take off event even though the aircraft is already above ground level. This means influence will be removed and the cell will become accessible as intended.

In ActorMap, we also fix a design flaw where disposed actors where excluded from queries. This caused cache inconsistencies with clients using ActorMap.CellUpdated event to rely on updates. This event will not get called when the actor was disposed, so the downsteam client may have cached the actors at that location, only for them to "change" when the actor is later disposed. This could cause the Locomotor and HierarchicalPathFInder to have inconsistent views of the actors on the map, causing crashes if the inconsistent state broken some internal invariants. The only reason to exclude disposed actors would be to cover up for the actors not being removed properly from the map, which is fixed now aircraft are handled correctly. If ever an actor isn't removed from the actor map, then the caller needs fixing rather than having the actor map exclude it.
2022-09-11 20:04:12 +03:00

115 lines
3.4 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2022 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities
{
public class DeliverUnit : Activity
{
readonly Carryall carryall;
readonly BodyOrientation body;
readonly bool assignTargetOnFirstRun;
readonly WDist deliverRange;
readonly Color? targetLineColor;
Target destination;
public DeliverUnit(Actor self, WDist deliverRange, Color? targetLineColor)
: this(self, Target.Invalid, deliverRange, targetLineColor)
{
assignTargetOnFirstRun = true;
}
public DeliverUnit(Actor self, in Target destination, WDist deliverRange, Color? targetLineColor)
{
this.destination = destination;
this.deliverRange = deliverRange;
this.targetLineColor = targetLineColor;
carryall = self.Trait<Carryall>();
body = self.Trait<BodyOrientation>();
}
protected override void OnFirstRun(Actor self)
{
// In case this activity was queued (either via queued order of via AutoCarryall)
// something might have happened to the cargo in the time between the activity being
// queued and being run, so short out if it is no longer valid.
if (carryall.Carryable == null)
return;
if (assignTargetOnFirstRun)
destination = Target.FromCell(self.World, self.Location);
QueueChild(new Land(self, destination, deliverRange));
QueueChild(new Wait(carryall.Info.BeforeUnloadDelay, false));
QueueChild(new ReleaseUnit(self));
QueueChild(new TakeOff(self));
}
public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
{
if (targetLineColor != null)
yield return new TargetLineNode(destination, targetLineColor.Value);
}
class ReleaseUnit : Activity
{
readonly Carryall carryall;
readonly BodyOrientation body;
readonly IFacing facing;
public ReleaseUnit(Actor self)
{
facing = self.Trait<IFacing>();
carryall = self.Trait<Carryall>();
body = self.Trait<BodyOrientation>();
}
protected override void OnFirstRun(Actor self)
{
// HACK: Activities still tick between the actor being killed and being disposed
// Thus the carryable might have changed since queuing because the death handler set it to null
if (carryall.Carryable == null)
return;
var localOffset = carryall.CarryableOffset.Rotate(body.QuantizeOrientation(self.Orientation));
var targetPosition = self.CenterPosition + body.LocalToWorld(localOffset);
var targetLocation = self.World.Map.CellContaining(targetPosition);
carryall.Carryable.Trait<IPositionable>().SetPosition(carryall.Carryable, targetLocation, SubCell.FullCell);
carryall.Carryable.Trait<IFacing>().Facing = facing.Facing;
// Put back into world
self.World.AddFrameEndTask(w =>
{
if (self.IsDead)
return;
var cargo = carryall.Carryable;
if (cargo == null)
return;
var carryable = cargo.Trait<Carryable>();
w.Add(cargo);
carryall.DetachCarryable(self);
carryable.UnReserve(cargo);
carryable.Detached(cargo);
});
}
}
}
}