diff --git a/OpenRA.Mods.RA/Air/ReturnOnIdle.cs b/OpenRA.Mods.RA/Air/ReturnOnIdle.cs index 7561749da4..5ee94a9c87 100755 --- a/OpenRA.Mods.RA/Air/ReturnOnIdle.cs +++ b/OpenRA.Mods.RA/Air/ReturnOnIdle.cs @@ -6,11 +6,12 @@ * as published by the Free Software Foundation. For more information, * see COPYING. */ -#endregion - -using OpenRA.Mods.RA.Activities; +#endregion + +using System.Linq; +using OpenRA.Mods.RA.Activities; +using OpenRA.Mods.RA.Buildings; using OpenRA.Traits; -using OpenRA.Traits.Activities; namespace OpenRA.Mods.RA.Air { @@ -32,10 +33,30 @@ namespace OpenRA.Mods.RA.Air self.QueueActivity(new Rearm()); } else - { - //Game.Debug("Plane has nowhere to land; flying away"); - self.QueueActivity(new FlyOffMap()); - self.QueueActivity(new RemoveSelf()); + { + // nowhere to land, pick something friendly and circle over it. + + // i'd prefer something we own + var someBuilding = self.World.ActorsWithTrait() + .Select( a => a.Actor ) + .FirstOrDefault(a => a.Owner == self.Owner); + + // failing that, something unlikely to shoot at us + if (someBuilding == null) + someBuilding = self.World.ActorsWithTrait() + .Select( a => a.Actor ) + .FirstOrDefault(a => self.Owner.Stances[a.Owner] == Stance.Ally); + + if (someBuilding == null) + { + // ... going down the garden to eat worms ... + self.QueueActivity(new FlyOffMap()); + self.QueueActivity(new RemoveSelf()); + return; + } + + self.QueueActivity(Fly.ToCell(someBuilding.Location)); + self.QueueActivity(new FlyCircle()); } } }