saner planes, part 1

This commit is contained in:
Chris Forbes
2010-03-27 00:23:24 +13:00
parent 092c9bede0
commit d2ad90aa5b
4 changed files with 54 additions and 2 deletions

View File

@@ -65,11 +65,20 @@ namespace OpenRA
public void Tick() public void Tick()
{ {
while (currentActivity != null) while (currentActivity != null && !(currentActivity is Idle))
{ {
var a = currentActivity; var a = currentActivity;
currentActivity = a.Tick(this) ?? new Idle(); 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<INotifyIdle>())
ni.Idle(this);
break;
}
} }
} }

View File

@@ -75,6 +75,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Chat.cs" /> <Compile Include="Chat.cs" />
<Compile Include="Chrome.cs" /> <Compile Include="Chrome.cs" />
<Compile Include="Traits\AI\ReturnOnIdle.cs" />
<Compile Include="Widgets\Delegates\ConnectionDialogsDelegate.cs" /> <Compile Include="Widgets\Delegates\ConnectionDialogsDelegate.cs" />
<Compile Include="Widgets\Delegates\CreateServerMenuDelegate.cs" /> <Compile Include="Widgets\Delegates\CreateServerMenuDelegate.cs" />
<Compile Include="Widgets\Delegates\MainMenuButtonsDelegate.cs" /> <Compile Include="Widgets\Delegates\MainMenuButtonsDelegate.cs" />

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using OpenRA.Traits.Activities;
namespace OpenRA.Traits.AI
{
class ReturnOnIdleInfo : StatelessTraitInfo<ReturnOnIdle> { }
// fly home or fly-off-map behavior for idle planes
class ReturnOnIdle : INotifyIdle
{
public void Idle(Actor self)
{
var altitude = self.traits.Get<Unit>().Altitude;
if (altitude == 0) return; // we're on the ground, let's stay there.
self.QueueActivity(new ReturnToBase(self, null));
self.QueueActivity(new Rearm());
}
}
}

View File

@@ -137,4 +137,5 @@ namespace OpenRA.Traits
} }
public interface IRenderOverlay { void Render(); } public interface IRenderOverlay { void Render(); }
public interface INotifyIdle { void Idle(Actor self); }
} }