Replace Airfield/Helipad references with generic Resupplier in RTB activities
More generalization to prepare for possible future activity merger.
This commit is contained in:
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
this.dest = dest;
|
this.dest = dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Actor ChooseHelipad(Actor self, bool unreservedOnly)
|
public Actor ChooseResupplier(Actor self, bool unreservedOnly)
|
||||||
{
|
{
|
||||||
var rearmBuildings = aircraft.Info.RearmBuildings;
|
var rearmBuildings = aircraft.Info.RearmBuildings;
|
||||||
return self.World.Actors.Where(a => a.Owner == self.Owner
|
return self.World.Actors.Where(a => a.Owner == self.Owner
|
||||||
@@ -51,36 +51,36 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
if (dest == null || dest.IsDead || Reservable.IsReserved(dest))
|
if (dest == null || dest.IsDead || Reservable.IsReserved(dest))
|
||||||
dest = ChooseHelipad(self, true);
|
dest = ChooseResupplier(self, true);
|
||||||
|
|
||||||
var initialFacing = aircraft.Info.InitialFacing;
|
var initialFacing = aircraft.Info.InitialFacing;
|
||||||
|
|
||||||
if (dest == null || dest.IsDead)
|
if (dest == null || dest.IsDead)
|
||||||
{
|
{
|
||||||
var nearestHpad = ChooseHelipad(self, false);
|
var nearestResupplier = ChooseResupplier(self, false);
|
||||||
|
|
||||||
// If a heli was told to return and there's no (available) RearmBuilding, going to the probable next queued activity (HeliAttack)
|
// If a heli was told to return and there's no (available) RearmBuilding, going to the probable next queued activity (HeliAttack)
|
||||||
// would be pointless (due to lack of ammo), and possibly even lead to an infinite loop due to HeliAttack.cs:L79.
|
// would be pointless (due to lack of ammo), and possibly even lead to an infinite loop due to HeliAttack.cs:L79.
|
||||||
if (nearestHpad == null && aircraft.Info.LandWhenIdle)
|
if (nearestResupplier == null && aircraft.Info.LandWhenIdle)
|
||||||
{
|
{
|
||||||
if (aircraft.Info.TurnToLand)
|
if (aircraft.Info.TurnToLand)
|
||||||
return ActivityUtils.SequenceActivities(new Turn(self, initialFacing), new HeliLand(self, true));
|
return ActivityUtils.SequenceActivities(new Turn(self, initialFacing), new HeliLand(self, true));
|
||||||
|
|
||||||
return new HeliLand(self, true);
|
return new HeliLand(self, true);
|
||||||
}
|
}
|
||||||
else if (nearestHpad == null && !aircraft.Info.LandWhenIdle)
|
else if (nearestResupplier == null && !aircraft.Info.LandWhenIdle)
|
||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var distanceFromHelipad = (nearestHpad.CenterPosition - self.CenterPosition).HorizontalLength;
|
var distanceFromResupplier = (nearestResupplier.CenterPosition - self.CenterPosition).HorizontalLength;
|
||||||
var distanceLength = aircraft.Info.WaitDistanceFromResupplyBase.Length;
|
var distanceLength = aircraft.Info.WaitDistanceFromResupplyBase.Length;
|
||||||
|
|
||||||
// If no pad is available, move near one and wait
|
// If no pad is available, move near one and wait
|
||||||
if (distanceFromHelipad > distanceLength)
|
if (distanceFromResupplier > distanceLength)
|
||||||
{
|
{
|
||||||
var randomPosition = WVec.FromPDF(self.World.SharedRandom, 2) * distanceLength / 1024;
|
var randomPosition = WVec.FromPDF(self.World.SharedRandom, 2) * distanceLength / 1024;
|
||||||
|
|
||||||
var target = Target.FromPos(nearestHpad.CenterPosition + randomPosition);
|
var target = Target.FromPos(nearestResupplier.CenterPosition + randomPosition);
|
||||||
|
|
||||||
return ActivityUtils.SequenceActivities(new HeliFly(self, target, WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase), this);
|
return ActivityUtils.SequenceActivities(new HeliFly(self, target, WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase), this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
aircraftInfo = self.Info.TraitInfo<AircraftInfo>();
|
aircraftInfo = self.Info.TraitInfo<AircraftInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Actor ChooseAirfield(Actor self, bool unreservedOnly)
|
public static Actor ChooseResupplier(Actor self, bool unreservedOnly)
|
||||||
{
|
{
|
||||||
var rearmBuildings = self.Info.TraitInfo<AircraftInfo>().RearmBuildings;
|
var rearmBuildings = self.Info.TraitInfo<AircraftInfo>().RearmBuildings;
|
||||||
return self.World.ActorsHavingTrait<Reservable>()
|
return self.World.ActorsHavingTrait<Reservable>()
|
||||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
void Calculate(Actor self)
|
void Calculate(Actor self)
|
||||||
{
|
{
|
||||||
if (dest == null || dest.IsDead || Reservable.IsReserved(dest))
|
if (dest == null || dest.IsDead || Reservable.IsReserved(dest))
|
||||||
dest = ChooseAirfield(self, true);
|
dest = ChooseResupplier(self, true);
|
||||||
|
|
||||||
if (dest == null)
|
if (dest == null)
|
||||||
return;
|
return;
|
||||||
@@ -123,11 +123,11 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
if (dest == null || dest.IsDead)
|
if (dest == null || dest.IsDead)
|
||||||
{
|
{
|
||||||
var nearestAfld = ChooseAirfield(self, false);
|
var nearestResupplier = ChooseResupplier(self, false);
|
||||||
|
|
||||||
if (nearestAfld != null)
|
if (nearestResupplier != null)
|
||||||
return ActivityUtils.SequenceActivities(
|
return ActivityUtils.SequenceActivities(
|
||||||
new Fly(self, Target.FromActor(nearestAfld), WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase),
|
new Fly(self, Target.FromActor(nearestResupplier), WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase),
|
||||||
new FlyCircle(self, aircraft.Info.NumberOfTicksToVerifyAvailableAirport),
|
new FlyCircle(self, aircraft.Info.NumberOfTicksToVerifyAvailableAirport),
|
||||||
this);
|
this);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -36,10 +36,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length < aircraftInfo.MinAirborneAltitude)
|
if (self.World.Map.DistanceAboveTerrain(self.CenterPosition).Length < aircraftInfo.MinAirborneAltitude)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var airfield = ReturnToBase.ChooseAirfield(self, true);
|
var resupplier = ReturnToBase.ChooseResupplier(self, true);
|
||||||
if (airfield != null)
|
if (resupplier != null)
|
||||||
{
|
{
|
||||||
self.QueueActivity(new ReturnToBase(self, aircraftInfo.AbortOnResupply, airfield));
|
self.QueueActivity(new ReturnToBase(self, aircraftInfo.AbortOnResupply, resupplier));
|
||||||
self.QueueActivity(new ResupplyAircraft(self));
|
self.QueueActivity(new ResupplyAircraft(self));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user