more for Activity

This commit is contained in:
alzeih
2011-04-05 20:45:58 +12:00
committed by Paul Chote
parent 255bac6aff
commit 820f67e46b
2 changed files with 73 additions and 83 deletions

View File

@@ -1,51 +1,41 @@
#region Copyright & License Information using System;
/* using System.Collections.Generic;
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS) using System.Linq;
* This file is part of OpenRA, which is free software. It is made using System.Text;
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, namespace OpenRA.Traits.Activities
* see COPYING. {
*/ public class Activity
#endregion {
public Activity NextActivity { get; set; }
using System; protected bool IsCanceled { get; private set; }
using System.Collections.Generic;
using System.Linq; public virtual Activity Tick( Actor self )
using System.Text; {
return this;
namespace OpenRA.Traits.Activities }
{ protected virtual bool OnCancel( Actor self ) { return true; }
public class Activity
{ public virtual void Cancel( Actor self )
public Activity NextActivity { get; set; } {
protected bool IsCanceled { get; private set; } IsCanceled = OnCancel( self );
if( IsCanceled )
public virtual Activity Tick( Actor self ) NextActivity = null;
{ else if (NextActivity != null)
return this; NextActivity.Cancel( self );
} }
protected virtual bool OnCancel( Actor self ) { return true; }
public virtual void Queue( Activity activity )
public void Cancel( Actor self ) {
{ if( NextActivity != null )
IsCanceled = OnCancel( self ); NextActivity.Queue( activity );
if( IsCanceled ) else
NextActivity = null; NextActivity = activity;
else if (NextActivity != null) }
NextActivity.Cancel( self );
} public virtual IEnumerable<Target> GetTargetQueue( Actor self )
{
public virtual void Queue( Activity activity ) yield break;
{ }
if( NextActivity != null ) }
NextActivity.Queue( activity ); }
else
NextActivity = activity;
}
public virtual IEnumerable<Target> GetTargetQueue( Actor self )
{
yield break;
}
}
}

View File

@@ -1,38 +1,38 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License * available to you under the terms of the GNU General Public License
* 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 System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities; using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA.Air namespace OpenRA.Mods.RA.Air
{ {
public class FlyCircle : Activity public class FlyCircle : Activity
{ {
public override Activity Tick(Actor self) public override Activity Tick(Actor self)
{ {
var cruiseAltitude = self.Info.Traits.Get<PlaneInfo>().CruiseAltitude; var cruiseAltitude = self.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
if (IsCanceled) return NextActivity; if (IsCanceled) return NextActivity;
var aircraft = self.Trait<Aircraft>(); var aircraft = self.Trait<Aircraft>();
var desiredFacing = aircraft.Facing + 64; // we can't possibly turn this fast. var desiredFacing = aircraft.Facing + 64; // we can't possibly turn this fast.
if (aircraft.Altitude == cruiseAltitude) if (aircraft.Altitude == cruiseAltitude)
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT); aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT);
if (aircraft.Altitude < cruiseAltitude) if (aircraft.Altitude < cruiseAltitude)
++aircraft.Altitude; ++aircraft.Altitude;
FlyUtil.Fly(self, cruiseAltitude); FlyUtil.Fly(self, cruiseAltitude);
return this; return this;
} }
} }
} }