Convert Parachute to world coords.

This commit is contained in:
Paul Chote
2013-05-14 21:53:26 +12:00
parent fe716e76a7
commit 79cbb7f729
5 changed files with 28 additions and 40 deletions

View File

@@ -35,9 +35,7 @@ namespace OpenRA.Mods.RA
if (IsSuitableCell(pilot, self.Location) && r > 100 - info.SuccessRate && aircraft.Altitude > 10
&& self.Owner.WinState != WinState.Lost)
{
self.World.AddFrameEndTask(w => w.Add(new Parachute(pilot,
Util.CenterOfCell(self.CenterLocation.ToCPos()), aircraft.Altitude)));
self.World.AddFrameEndTask(w => w.Add(new Parachute(pilot, self.CenterPosition)));
Sound.Play(info.ChuteSound, self.CenterLocation);
}
else

View File

@@ -19,48 +19,46 @@ namespace OpenRA.Mods.RA.Effects
public class Parachute : IEffect
{
readonly Animation paraAnim;
readonly PPos location;
readonly WVec parachuteOffset;
readonly Actor cargo;
WPos pos;
WVec fallRate = new WVec(0, 0, 13);
int2 offset;
float altitude;
const float fallRate = .3f;
public Parachute(Actor cargo, PPos location, int altitude)
public Parachute(Actor cargo, WPos dropPosition)
{
this.location = location;
this.altitude = altitude;
this.cargo = cargo;
var pai = cargo.Info.Traits.GetOrDefault<ParachuteAttachmentInfo>();
paraAnim = new Animation(pai != null ? pai.ParachuteSprite : "parach");
paraAnim.PlayThen("open", () => paraAnim.PlayRepeating("idle"));
if (pai != null) offset = pai.Offset;
if (pai != null)
parachuteOffset = pai.Offset;
cargo.Trait<ITeleportable>().SetPxPosition(cargo, location);
// Adjust x,y to match the target subcell
cargo.Trait<ITeleportable>().SetPosition(cargo, new CPos(dropPosition));
var cp = cargo.CenterPosition;
pos = new WPos(cp.X, cp.Y, dropPosition.Z);
}
public void Tick(World world)
{
paraAnim.Tick();
altitude -= fallRate;
pos -= fallRate;
if (altitude <= 0)
if (pos.Z <= 0)
{
world.AddFrameEndTask(w =>
{
w.Remove(cargo);
w.Remove(this);
var loc = location.ToCPos();
cargo.CancelActivity();
cargo.Trait<ITeleportable>().SetPosition(cargo, loc);
w.Add(cargo);
{
w.Remove(this);
cargo.CancelActivity();
w.Add(cargo);
foreach( var npl in cargo.TraitsImplementing<INotifyParachuteLanded>() )
npl.OnLanded();
});
foreach (var npl in cargo.TraitsImplementing<INotifyParachuteLanded>())
npl.OnLanded();
});
}
}
public IEnumerable<Renderable> Render(WorldRenderer wr)
@@ -74,12 +72,11 @@ namespace OpenRA.Mods.RA.Effects
var shadow = wr.Palette("shadow");
foreach (var c in rc)
{
yield return c.WithPalette(shadow);
yield return c.WithPxOffset(new float2(0, -altitude)).WithZOffset(c.ZOffset + (int)altitude + 2);
yield return c.WithPalette(shadow).WithZOffset(-1);
yield return c.WithPos(pos);
}
var pos = location.ToFloat2() - new float2(0, altitude);
yield return new Renderable(paraAnim.Image, pos + offset, rc.First().Palette, 3);
yield return new Renderable(paraAnim.Image, pos + parachuteOffset, 1, rc.First().Palette, 1f);
}
}
}

View File

@@ -52,14 +52,7 @@ namespace OpenRA.Mods.RA
droppedAt.Add(self.Location);
var a = cargo.Unload(self);
var aircraft = self.Trait<IMove>();
self.World.AddFrameEndTask(w => w.Add(
new Parachute(a,
Util.CenterOfCell(self.CenterLocation.ToCPos()),
aircraft.Altitude)
));
self.World.AddFrameEndTask(w => w.Add(new Parachute(a, self.CenterPosition)));
Sound.Play(info.ChuteSound, self.CenterLocation);
}
}

View File

@@ -15,7 +15,7 @@ namespace OpenRA.Mods.RA
class ParachuteAttachmentInfo : TraitInfo<ParachuteAttachment>
{
public readonly string ParachuteSprite = "parach";
public readonly int2 Offset = new int2(0,0);
public readonly WVec Offset = WVec.Zero;
}
class ParachuteAttachment {}

View File

@@ -116,7 +116,7 @@
GpsDot:
String:Infantry
ParachuteAttachment:
Offset: 0,-10
Offset: 0,0,427
CrushableInfantry:
CrushSound: squishy2.aud
RepairableNear: