Skip to content

Commit

Permalink
Prevent carryalls picking up non-existent units.
Browse files Browse the repository at this point in the history
  • Loading branch information
tovl committed Jul 7, 2019
1 parent af407a1 commit 7421429
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions OpenRA.Mods.Common/Activities/PickupUnit.cs
Expand Up @@ -97,11 +97,10 @@ public override bool Tick(Actor self)
QueueChild(new Land(self, Target.FromActor(cargo), -carryableBody.LocalToWorld(localOffset), carryableFacing.Facing));

// Pause briefly before attachment for visual effect
if (delay > 0)
QueueChild(new Wait(delay, false));
QueueChild(new Wait(delay, false));

// Remove our carryable from world
QueueChild(new CallFunc(() => Attach(self)));
QueueChild(new AttachUnit(self, cargo));
QueueChild(new TakeOff(self));
return false;
}
Expand All @@ -110,14 +109,32 @@ public override bool Tick(Actor self)
return true;
}

void Attach(Actor self)
class AttachUnit : Activity
{
self.World.AddFrameEndTask(w =>
readonly Actor cargo;
readonly Carryable carryable;
readonly Carryall carryall;

public AttachUnit(Actor self, Actor cargo)
{
this.cargo = cargo;
carryable = cargo.Trait<Carryable>();
carryall = self.Trait<Carryall>();
}

protected override void OnFirstRun(Actor self)
{
cargo.World.Remove(cargo);
carryable.Attached(cargo);
carryall.AttachCarryable(self, cargo);
});
// The cargo might have become invalid while we were moving towards it.
if (cargo == null || cargo.IsDead || carryable.IsTraitDisabled || !cargo.AppearsFriendlyTo(self))
return;

self.World.AddFrameEndTask(w =>
{
cargo.World.Remove(cargo);
carryable.Attached(cargo);
carryall.AttachCarryable(self, cargo);
});
}
}
}
}

0 comments on commit 7421429

Please sign in to comment.