add parameter to ReturnToBase.ChooseAirfield for whether the building must be unreserved

This commit is contained in:
Chris Forbes
2012-09-14 23:14:02 +12:00
parent 605a1eacf6
commit a641c7a87d
3 changed files with 5 additions and 5 deletions

View File

@@ -68,7 +68,7 @@ namespace OpenRA.Mods.RA.Air
} }
else if (order.OrderString == "ReturnToBase") else if (order.OrderString == "ReturnToBase")
{ {
var airfield = ReturnToBase.ChooseAirfield(self); var airfield = ReturnToBase.ChooseAirfield(self, true);
if (airfield == null) return; if (airfield == null) return;
UnReserve(); UnReserve();

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Air
var altitude = self.Trait<Aircraft>().Altitude; var altitude = self.Trait<Aircraft>().Altitude;
if (altitude == 0) return; // we're on the ground, let's stay there. if (altitude == 0) return; // we're on the ground, let's stay there.
var airfield = ReturnToBase.ChooseAirfield(self); var airfield = ReturnToBase.ChooseAirfield(self, true);
if (airfield != null) if (airfield != null)
{ {
self.QueueActivity(new ReturnToBase(self, airfield)); self.QueueActivity(new ReturnToBase(self, airfield));

View File

@@ -22,20 +22,20 @@ namespace OpenRA.Mods.RA.Air
PPos w1, w2, w3; /* tangent points to turn circles */ PPos w1, w2, w3; /* tangent points to turn circles */
public static Actor ChooseAirfield(Actor self) public static Actor ChooseAirfield(Actor self, bool unreservedOnly)
{ {
var rearmBuildings = self.Info.Traits.Get<PlaneInfo>().RearmBuildings; var rearmBuildings = self.Info.Traits.Get<PlaneInfo>().RearmBuildings;
return self.World.ActorsWithTrait<Reservable>() return self.World.ActorsWithTrait<Reservable>()
.Where(a => a.Actor.Owner == self.Owner) .Where(a => a.Actor.Owner == self.Owner)
.Where(a => rearmBuildings.Contains(a.Actor.Info.Name) .Where(a => rearmBuildings.Contains(a.Actor.Info.Name)
&& !Reservable.IsReserved(a.Actor)) && (!unreservedOnly || !Reservable.IsReserved(a.Actor)))
.Select(a => a.Actor) .Select(a => a.Actor)
.ClosestTo( self.CenterLocation ); .ClosestTo( self.CenterLocation );
} }
void Calculate(Actor self) void Calculate(Actor self)
{ {
if (dest == null || Reservable.IsReserved(dest)) dest = ChooseAirfield(self); if (dest == null || Reservable.IsReserved(dest)) dest = ChooseAirfield(self, true);
if (dest == null) return; if (dest == null) return;