some basic plane behavior on Yak

This commit is contained in:
Chris Forbes
2009-12-20 19:19:03 +13:00
parent effc642c04
commit 13636e9c54
5 changed files with 156 additions and 1 deletions

View File

@@ -106,6 +106,7 @@
<Compile Include="Support\PerfHistory.cs" />
<Compile Include="Traits\AcceptsOre.cs" />
<Compile Include="Traits\Activities\Attack.cs" />
<Compile Include="Traits\Activities\Fly.cs" />
<Compile Include="Traits\Activities\IActivity.cs" />
<Compile Include="Traits\Activities\DeliverOre.cs" />
<Compile Include="Traits\Activities\DeployMcv.cs" />
@@ -169,6 +170,7 @@
<Compile Include="Traits\Fake.cs" />
<Compile Include="Traits\Harvester.cs" />
<Compile Include="Traits\Helicopter.cs" />
<Compile Include="Traits\Plane.cs" />
<Compile Include="Traits\ProductionQueue.cs" />
<Compile Include="Traits\RenderBuildingCharge.cs" />
<Compile Include="Traits\RenderInfantry.cs" />
@@ -184,6 +186,7 @@
<Compile Include="Traits\Cloak.cs" />
<Compile Include="Traits\RenderUnit.cs" />
<Compile Include="Traits\RenderUnitMuzzleFlash.cs" />
<Compile Include="Traits\RenderUnitPlane.cs" />
<Compile Include="Traits\RenderUnitReload.cs" />
<Compile Include="Traits\RenderUnitRotor.cs" />
<Compile Include="Traits\RenderUnitSpinner.cs" />

View File

@@ -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<Unit>();
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<Unit>();
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; }
}
}

View File

@@ -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));
}
}
}
}

View File

@@ -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<Tuple<Sprite, float2, int>> Render(Actor self)
{
var unit = self.traits.Get<Unit>();
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);
}
}
}

View File

@@ -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]