#region Copyright & License Information /* * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * 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 * as published by the Free Software Foundation. For more information, * see COPYING. */ #endregion using System; using System.Collections.Generic; using OpenRA.Traits; namespace OpenRA.Mods.RA.Air { public class Fly : Activity { public readonly int2 Pos; Fly( int2 px ) { Pos = px; } public static Fly ToPx( int2 px ) { return new Fly( px ); } public static Fly ToCell( int2 pos ) { return new Fly( Util.CenterOfCell( pos ) ); } public override Activity Tick(Actor self) { var cruiseAltitude = self.Info.Traits.Get().CruiseAltitude; if (IsCanceled) return NextActivity; var d = Pos - self.CenterLocation; if (d.LengthSquared < 50) /* close enough */ return NextActivity; var aircraft = self.Trait(); var desiredFacing = Util.GetFacing(d, aircraft.Facing); if (aircraft.Altitude == cruiseAltitude) aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT); if (aircraft.Altitude < cruiseAltitude) ++aircraft.Altitude; FlyUtil.Fly(self, cruiseAltitude); return this; } public override IEnumerable GetTargets( Actor self ) { yield return Target.FromPos(Pos); } } public static class FlyUtil { public static void Fly(Actor self, int desiredAltitude ) { var aircraft = self.Trait(); aircraft.TickMove( 1024 * aircraft.MovementSpeed, aircraft.Facing ); aircraft.Altitude += Math.Sign(desiredAltitude - aircraft.Altitude); } } }