moved paradrop crap into mod dll

This commit is contained in:
Chris Forbes
2010-01-29 19:24:30 +13:00
parent f89a40f2ca
commit 3cf1ec5b45
12 changed files with 26 additions and 42 deletions

View File

@@ -0,0 +1,62 @@
using System.Collections.Generic;
using OpenRa.Effects;
using OpenRa.Graphics;
using OpenRa.Traits;
namespace OpenRa.Mods.RA.Effects
{
class Parachute : IEffect
{
readonly Animation anim;
readonly Animation paraAnim;
readonly float2 location;
readonly Actor cargo;
readonly Player owner;
float altitude;
const float fallRate = .3f;
public Parachute(Player owner, string image, float2 location, int altitude, Actor cargo)
{
this.location = location;
this.altitude = altitude;
this.cargo = cargo;
this.owner = owner;
anim = new Animation(image);
if (anim.HasSequence("idle"))
anim.PlayFetchIndex("idle", () => 0);
else
anim.PlayFetchIndex("stand", () => 0);
anim.Tick();
paraAnim = new Animation("parach");
paraAnim.PlayThen("open", () => paraAnim.PlayRepeating("idle"));
}
public void Tick(World world)
{
paraAnim.Tick();
altitude -= fallRate;
if (altitude <= 0)
world.AddFrameEndTask(w =>
{
w.Remove(this);
w.Add(cargo);
cargo.CancelActivity();
cargo.traits.Get<Mobile>().TeleportTo(cargo, ((1 / 24f) * location).ToInt2());
});
}
public IEnumerable<Renderable> Render()
{
var pos = location - new float2(0, altitude);
yield return new Renderable(anim.Image, location - .5f * anim.Image.size, PaletteType.Shadow, 0);
yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, owner.Palette, 2);
yield return new Renderable(paraAnim.Image, pos - .5f * paraAnim.Image.size, owner.Palette, 3);
}
}
}

View File

@@ -53,8 +53,11 @@
<Compile Include="Activities\Steal.cs" />
<Compile Include="C4Demolition.cs" />
<Compile Include="Effects\CrateEffectSpeedUpgrade.cs" />
<Compile Include="Effects\Parachute.cs" />
<Compile Include="EngineerCapture.cs" />
<Compile Include="InfiltrateForSonarPulse.cs" />
<Compile Include="ParaDrop.cs" />
<Compile Include="ParatroopersPower.cs" />
<Compile Include="RequiresPower.cs" />
<Compile Include="Mine.cs" />
<Compile Include="MineImmune.cs" />

View File

@@ -0,0 +1,62 @@
using System.Collections.Generic;
using OpenRa.Mods.RA.Effects;
using OpenRa.Traits;
using OpenRa.Traits.Activities;
namespace OpenRa.Mods.RA
{
class ParaDropInfo : ITraitInfo
{
public readonly int LZRange = 4;
public object Create(Actor self) { return new ParaDrop(); }
}
class ParaDrop : ITick
{
readonly List<int2> droppedAt = new List<int2>();
int2 lz;
public void SetLZ( int2 lz )
{
this.lz = lz;
droppedAt.Clear();
}
public void Tick(Actor self)
{
var r = self.Info.Traits.Get<ParaDropInfo>().LZRange;
if ((self.Location - lz).LengthSquared <= r * r && !droppedAt.Contains(self.Location))
{
// todo: check is this is a good drop cell.
// unload a dude here
droppedAt.Add(self.Location);
var cargo = self.traits.Get<Cargo>();
if (cargo.IsEmpty(self))
FinishedDropping(self);
else
{
var a = cargo.Unload(self);
var rs = a.traits.Get<RenderSimple>();
self.World.AddFrameEndTask(w => w.Add(
new Parachute(self.Owner, rs.anim.Name,
self.CenterLocation,
self.traits.Get<Unit>().Altitude, a)));
Sound.Play("chute1.aud");
}
}
}
void FinishedDropping(Actor self)
{
// this kindof sucks, actually.
self.CancelActivity();
self.QueueActivity(new Fly(Util.CenterOfCell(self.World.ChooseRandomEdgeCell())));
self.QueueActivity(new RemoveSelf());
}
}
}

View File

@@ -0,0 +1,72 @@
using System.Collections.Generic;
using OpenRa.Traits;
using OpenRa.Traits.Activities;
namespace OpenRa.Mods.RA
{
class ParatroopersPowerInfo : SupportPowerInfo
{
public string[] DropItems = { };
public override object Create(Actor self) { return new ParatroopersPower(self,this); }
}
class ParatroopersPower : SupportPower, IResolveOrder
{
public ParatroopersPower(Actor self, ParatroopersPowerInfo info) : base(self, info) { }
protected override void OnActivate()
{
Game.controller.orderGenerator = new SelectTarget();
Sound.Play("slcttgt1.aud");
}
class SelectTarget : IOrderGenerator
{
public IEnumerable<Order> Order(World world, int2 xy, MouseInput mi)
{
if (mi.Button == MouseButton.Left)
yield return new Order("ParatroopersActivate", world.LocalPlayer.PlayerActor, xy);
}
public void Tick(World world) {}
public void Render(World world) {}
public Cursor GetCursor(World world, int2 xy, MouseInput mi)
{
return Cursor.Ability;
}
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "ParatroopersActivate")
{
if (self.Owner == self.World.LocalPlayer)
Game.controller.CancelInputMode();
DoParadrop(Owner, order.TargetLocation,
self.Info.Traits.Get<ParatroopersPowerInfo>().DropItems);
FinishActivate();
}
}
static void DoParadrop(Player owner, int2 p, string[] items)
{
var startPos = owner.World.ChooseRandomEdgeCell();
owner.World.AddFrameEndTask(w =>
{
var a = w.CreateActor("BADR", startPos, owner);
a.CancelActivity();
a.QueueActivity(new FlyCircle(p));
a.traits.Get<ParaDrop>().SetLZ(p);
var cargo = a.traits.Get<Cargo>();
foreach (var i in items)
cargo.Load(a, new Actor(owner.World, i.ToLowerInvariant(),
new int2(0,0), a.Owner));
});
}
}
}