From 13636e9c5418f7b03fb56259479b2c193fa8f42f Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 20 Dec 2009 19:19:03 +1300 Subject: [PATCH] some basic plane behavior on Yak --- OpenRa.Game/OpenRa.Game.csproj | 3 + OpenRa.Game/Traits/Activities/Fly.cs | 97 +++++++++++++++++++++++++++ OpenRa.Game/Traits/Plane.cs | 32 +++++++++ OpenRa.Game/Traits/RenderUnitPlane.cs | 23 +++++++ units.ini | 2 +- 5 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 OpenRa.Game/Traits/Activities/Fly.cs create mode 100644 OpenRa.Game/Traits/Plane.cs create mode 100644 OpenRa.Game/Traits/RenderUnitPlane.cs diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index d04f047518..417e091eec 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -106,6 +106,7 @@ + @@ -169,6 +170,7 @@ + @@ -184,6 +186,7 @@ + diff --git a/OpenRa.Game/Traits/Activities/Fly.cs b/OpenRa.Game/Traits/Activities/Fly.cs new file mode 100644 index 0000000000..62c4ab2ab7 --- /dev/null +++ b/OpenRa.Game/Traits/Activities/Fly.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenRa.Game.Traits.Activities +{ + class Fly : IActivity + { + readonly int2 Cell; + bool isCanceled; + + public Fly(int2 cell) { Cell = cell; } + + public IActivity NextActivity { get; set; } + + const int CruiseAltitude = 20; + + public IActivity Tick(Actor self) + { + if (isCanceled) return NextActivity; + + var d = Util.CenterOfCell(Cell) - self.CenterLocation; + if (d.LengthSquared < 50) /* close enough */ + return NextActivity; + + var unit = self.traits.Get(); + + if (unit.Altitude < CruiseAltitude) + ++unit.Altitude; + + var desiredFacing = Util.GetFacing(d, unit.Facing); + if (unit.Altitude == CruiseAltitude) + Util.TickFacing(ref unit.Facing, desiredFacing, self.Info.ROT); + var speed = .2f * Util.GetEffectiveSpeed(self); + var angle = unit.Facing / 128f * Math.PI; + + self.CenterLocation += speed * -float2.FromAngle((float)angle); + self.Location = ((1 / 24f) * self.CenterLocation).ToInt2(); + + return null; + } + + public void Cancel(Actor self) { isCanceled = true; NextActivity = null; } + } + + class FlyTimed : IActivity + { + public IActivity NextActivity { get; set; } + int remainingTicks; + + public FlyTimed(int ticks) { remainingTicks = ticks; } + + public IActivity Tick(Actor self) + { + if (remainingTicks == 0) + return NextActivity; + + --remainingTicks; + + var unit = self.traits.Get(); + var speed = .2f * Util.GetEffectiveSpeed(self); + var angle = unit.Facing / 128f * Math.PI; + + self.CenterLocation += speed * -float2.FromAngle((float)angle); + self.Location = ((1 / 24f) * self.CenterLocation).ToInt2(); + + return null; + } + + public void Cancel(Actor self) { remainingTicks = 0; NextActivity = null; } + } + + class Circle : IActivity + { + public IActivity NextActivity { get; set; } + bool isCanceled; + readonly int2 Cell; + + public Circle(int2 cell) { Cell = cell; } + + public IActivity Tick(Actor self) + { + if (isCanceled) return NextActivity; + return new Fly(Cell) + { + NextActivity = + new FlyTimed(50) + { + NextActivity = this + } + }; + } + + public void Cancel(Actor self) { isCanceled = true; NextActivity = null; } + } +} diff --git a/OpenRa.Game/Traits/Plane.cs b/OpenRa.Game/Traits/Plane.cs new file mode 100644 index 0000000000..5398111df3 --- /dev/null +++ b/OpenRa.Game/Traits/Plane.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenRa.Game.Traits.Activities; + +namespace OpenRa.Game.Traits +{ + class Plane : IOrder + { + public Plane(Actor self) + { + } + + public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) + { + if (mi.Button == MouseButton.Left) return null; + if (underCursor == null) + return Order.Move(self, xy); + return null; + } + + public void ResolveOrder(Actor self, Order order) + { + if (order.OrderString == "Move") + { + self.CancelActivity(); + self.QueueActivity(new Circle(order.TargetLocation)); + } + } + } +} diff --git a/OpenRa.Game/Traits/RenderUnitPlane.cs b/OpenRa.Game/Traits/RenderUnitPlane.cs new file mode 100644 index 0000000000..88463ee066 --- /dev/null +++ b/OpenRa.Game/Traits/RenderUnitPlane.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenRa.Game.Graphics; + +namespace OpenRa.Game.Traits +{ + class RenderUnitPlane : RenderUnit + { + public RenderUnitPlane(Actor self) + : base(self) {} + + public override IEnumerable> Render(Actor self) + { + var unit = self.traits.Get(); + + yield return Util.CenteredShadow(self, anim.Image, self.CenterLocation); + var p = self.CenterLocation - new float2(0, unit.Altitude); + yield return Util.Centered(self, anim.Image, p); + } + } +} diff --git a/units.ini b/units.ini index 84f54896b8..d08b485d37 100755 --- a/units.ini +++ b/units.ini @@ -161,7 +161,7 @@ LongDesc=Fast Ground-Attack Plane.\n Strong vs Buildings\n Weak vs Infantry, L [YAK] Description=Yak Attack Plane BuiltAt=afld -Traits=Unit, Mobile, RenderUnit +Traits=Unit, Plane, RenderUnitPlane InitialFacing=192 LongDesc=Anti-Tanks & Anti-Infantry Plane.\n Strong vs Infantry, Tanks\n Weak vs Buildings [TRAN]