Improve handling of finished/cancelled Resupply
This commit is contained in:
@@ -120,9 +120,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
aircraft.MakeReservation(dest);
|
aircraft.MakeReservation(dest);
|
||||||
QueueChild(new Land(self, Target.FromActor(dest), offset, facing));
|
QueueChild(new Land(self, Target.FromActor(dest), offset, facing));
|
||||||
QueueChild(new Resupply(self, dest, WDist.Zero));
|
QueueChild(new Resupply(self, dest, WDist.Zero, alwaysLand));
|
||||||
if (aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.TakeOffOnResupply) && !alwaysLand)
|
|
||||||
QueueChild(new TakeOff(self));
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,16 +32,18 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
readonly ICallForTransport[] transportCallers;
|
readonly ICallForTransport[] transportCallers;
|
||||||
readonly IMove move;
|
readonly IMove move;
|
||||||
readonly Aircraft aircraft;
|
readonly Aircraft aircraft;
|
||||||
|
readonly bool stayOnResupplier;
|
||||||
|
|
||||||
int remainingTicks;
|
int remainingTicks;
|
||||||
bool played;
|
bool played;
|
||||||
bool actualResupplyStarted;
|
bool actualResupplyStarted;
|
||||||
ResupplyType activeResupplyTypes = ResupplyType.None;
|
ResupplyType activeResupplyTypes = ResupplyType.None;
|
||||||
|
|
||||||
public Resupply(Actor self, Actor host, WDist closeEnough)
|
public Resupply(Actor self, Actor host, WDist closeEnough, bool stayOnResupplier = false)
|
||||||
{
|
{
|
||||||
this.host = Target.FromActor(host);
|
this.host = Target.FromActor(host);
|
||||||
this.closeEnough = closeEnough;
|
this.closeEnough = closeEnough;
|
||||||
|
this.stayOnResupplier = stayOnResupplier;
|
||||||
allRepairsUnits = host.TraitsImplementing<RepairsUnits>().ToArray();
|
allRepairsUnits = host.TraitsImplementing<RepairsUnits>().ToArray();
|
||||||
health = self.TraitOrDefault<IHealth>();
|
health = self.TraitOrDefault<IHealth>();
|
||||||
repairable = self.TraitOrDefault<Repairable>();
|
repairable = self.TraitOrDefault<Repairable>();
|
||||||
@@ -75,21 +77,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
foreach (var notifyResupply in notifyResupplies)
|
foreach (var notifyResupply in notifyResupplies)
|
||||||
notifyResupply.ResupplyTick(host.Actor, self, ResupplyType.None);
|
notifyResupply.ResupplyTick(host.Actor, self, ResupplyType.None);
|
||||||
|
|
||||||
if (aircraft != null)
|
OnResupplyEnding(self);
|
||||||
{
|
return true;
|
||||||
aircraft.AllowYieldingReservation();
|
|
||||||
if (aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.TakeOffOnResupply))
|
|
||||||
Queue(new TakeOff(self));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (repairableNear != null)
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QueueChild(move.MoveToTarget(self, host));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (IsCanceling || host.Type != TargetType.Actor || !host.Actor.IsInWorld || host.Actor.IsDead)
|
else if (IsCanceling || host.Type != TargetType.Actor || !host.Actor.IsInWorld || host.Actor.IsDead)
|
||||||
{
|
{
|
||||||
@@ -148,24 +137,39 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
if (activeResupplyTypes == 0)
|
if (activeResupplyTypes == 0)
|
||||||
{
|
{
|
||||||
if (aircraft != null)
|
OnResupplyEnding(self);
|
||||||
aircraft.AllowYieldingReservation();
|
|
||||||
|
|
||||||
if (self.CurrentActivity.NextActivity == null)
|
|
||||||
{
|
|
||||||
var rp = host.Actor.TraitOrDefault<RallyPoint>();
|
|
||||||
if (rp != null)
|
|
||||||
Queue(move.MoveTo(rp.Location, repairableNear != null ? null : host.Actor));
|
|
||||||
else if (repairableNear == null)
|
|
||||||
Queue(move.MoveToTarget(self, host));
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnResupplyEnding(Actor self)
|
||||||
|
{
|
||||||
|
if (aircraft != null)
|
||||||
|
{
|
||||||
|
aircraft.AllowYieldingReservation();
|
||||||
|
if (!stayOnResupplier && aircraft.Info.FlightDynamics.HasFlag(FlightDynamic.TakeOffOnResupply))
|
||||||
|
QueueChild(new TakeOff(self));
|
||||||
|
}
|
||||||
|
else if (!stayOnResupplier)
|
||||||
|
{
|
||||||
|
// If there's no next activity, move to rallypoint if available, else just leave host if Repairable.
|
||||||
|
// Do nothing if RepairableNear (RepairableNear actors don't enter their host and will likely remain within closeEnough).
|
||||||
|
// If there's a next activity and we're not RepairableNear, first leave host if the next activity is not a Move.
|
||||||
|
if (self.CurrentActivity.NextActivity == null)
|
||||||
|
{
|
||||||
|
var rp = host.Actor.TraitOrDefault<RallyPoint>();
|
||||||
|
if (rp != null)
|
||||||
|
QueueChild(move.MoveTo(rp.Location, repairableNear != null ? null : host.Actor));
|
||||||
|
else if (repairableNear == null)
|
||||||
|
QueueChild(move.MoveToTarget(self, host));
|
||||||
|
}
|
||||||
|
else if (repairableNear == null && !(self.CurrentActivity.NextActivity is Move))
|
||||||
|
QueueChild(move.MoveToTarget(self, host));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RepairTick(Actor self)
|
void RepairTick(Actor self)
|
||||||
{
|
{
|
||||||
// First active.
|
// First active.
|
||||||
|
|||||||
Reference in New Issue
Block a user