Fix air unit resupply #5966

This commit is contained in:
PedroFerreiraRamos
2016-06-02 18:22:21 -03:00
parent 60d7ef99d4
commit 958e35d61f
8 changed files with 94 additions and 9 deletions

View File

@@ -44,13 +44,28 @@ namespace OpenRA.Mods.Common.Activities
{
var rearmBuildings = heli.Info.RearmBuildings;
var nearestHpad = self.World.ActorsHavingTrait<Reservable>()
.Where(a => a.Owner == self.Owner && rearmBuildings.Contains(a.Info.Name))
.ClosestTo(self);
.Where(a => a.Owner == self.Owner && rearmBuildings.Contains(a.Info.Name))
.ClosestTo(self);
if (nearestHpad == null)
return ActivityUtils.SequenceActivities(new Turn(self, initialFacing), new HeliLand(self, true), NextActivity);
else
return ActivityUtils.SequenceActivities(new HeliFly(self, Target.FromActor(nearestHpad)));
{
var distanceFromHelipad = (nearestHpad.CenterPosition - self.CenterPosition).HorizontalLength;
var distanceLength = heli.Info.WaitDistanceFromResupplyBase.Length;
// If no pad is available, move near one and wait
if (distanceFromHelipad > distanceLength)
{
var randomPosition = WVec.FromPDF(self.World.SharedRandom, 2) * distanceLength / 1024;
var target = Target.FromPos(nearestHpad.CenterPosition + randomPosition);
return ActivityUtils.SequenceActivities(new HeliFly(self, target, WDist.Zero, heli.Info.WaitDistanceFromResupplyBase), this);
}
return this;
}
}
heli.MakeReservation(dest);
@@ -62,7 +77,8 @@ namespace OpenRA.Mods.Common.Activities
new HeliFly(self, Target.FromPos(dest.CenterPosition + offset)),
new Turn(self, initialFacing),
new HeliLand(self, false),
new ResupplyAircraft(self));
new ResupplyAircraft(self),
NextActivity);
}
}
}