prefer to circle over something friendly than leave the map

This commit is contained in:
Chris Forbes
2011-03-19 18:36:49 +13:00
parent 73a34886ec
commit 18e1de1d4b

View File

@@ -6,11 +6,12 @@
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
* see COPYING. * see COPYING.
*/ */
#endregion #endregion
using OpenRA.Mods.RA.Activities; using System.Linq;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {
@@ -32,10 +33,30 @@ namespace OpenRA.Mods.RA.Air
self.QueueActivity(new Rearm()); self.QueueActivity(new Rearm());
} }
else else
{ {
//Game.Debug("Plane has nowhere to land; flying away"); // nowhere to land, pick something friendly and circle over it.
self.QueueActivity(new FlyOffMap());
self.QueueActivity(new RemoveSelf()); // i'd prefer something we own
var someBuilding = self.World.ActorsWithTrait<Building>()
.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<Building>()
.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());
} }
} }
} }