diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 8820ceecf6..458111700d 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -65,11 +65,20 @@ namespace OpenRA public void Tick() { - while (currentActivity != null) + while (currentActivity != null && !(currentActivity is Idle)) { var a = currentActivity; currentActivity = a.Tick(this) ?? new Idle(); - if (a == currentActivity || currentActivity is Idle) break; + + if (a == currentActivity) break; + + if (currentActivity is Idle) + { + foreach (var ni in traits.WithInterface()) + ni.Idle(this); + + break; + } } } diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 8d12013379..04a14a7862 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -75,6 +75,7 @@ + diff --git a/OpenRA.Game/Traits/AI/ReturnOnIdle.cs b/OpenRA.Game/Traits/AI/ReturnOnIdle.cs new file mode 100644 index 0000000000..072c1a09f3 --- /dev/null +++ b/OpenRA.Game/Traits/AI/ReturnOnIdle.cs @@ -0,0 +1,41 @@ +#region Copyright & License Information +/* + * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. + * This file is part of OpenRA. + * + * OpenRA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * OpenRA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OpenRA. If not, see . + */ +#endregion + +using System; +using OpenRA.Traits.Activities; + +namespace OpenRA.Traits.AI +{ + class ReturnOnIdleInfo : StatelessTraitInfo { } + + // fly home or fly-off-map behavior for idle planes + + class ReturnOnIdle : INotifyIdle + { + public void Idle(Actor self) + { + var altitude = self.traits.Get().Altitude; + if (altitude == 0) return; // we're on the ground, let's stay there. + + self.QueueActivity(new ReturnToBase(self, null)); + self.QueueActivity(new Rearm()); + } + } +} diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 90839dab3a..1824b5586f 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -137,4 +137,5 @@ namespace OpenRA.Traits } public interface IRenderOverlay { void Render(); } + public interface INotifyIdle { void Idle(Actor self); } }