EjectOnDeath works with air & ground vehicles, updated defaults.yaml

This commit is contained in:
Taryn Hill
2013-10-10 22:34:54 -04:00
parent 61a26a636b
commit e9652db486
2 changed files with 38 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2013 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,
@@ -8,6 +8,7 @@
*/
#endregion
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Mods.RA.Effects;
using OpenRA.Traits;
@@ -20,33 +21,45 @@ namespace OpenRA.Mods.RA
public readonly string PilotActor = "E1";
public readonly int SuccessRate = 50;
public readonly string ChuteSound = "chute1.aud";
public readonly WRange MinimumEjectHeight = new WRange(427);
public readonly bool EjectInAir = false;
public readonly bool EjectOnGround = false;
}
public class EjectOnDeath : INotifyKilled
{
public void Killed(Actor self, AttackInfo e)
{
var info = self.Info.Traits.Get<EjectOnDeathInfo>();
var pilot = self.World.CreateActor(false, info.PilotActor.ToLowerInvariant(),
new TypeDictionary { new OwnerInit(self.Owner) });
var r = self.World.SharedRandom.Next(1, 100);
var cp = self.CenterPosition;
var info = self.Info.Traits.Get<EjectOnDeathInfo>();
var r = self.World.SharedRandom.Next(1, 100);
if (IsSuitableCell(pilot, self.Location) && r > 100 - info.SuccessRate && cp.Z > info.MinimumEjectHeight.Range
&& self.Owner.WinState != WinState.Lost)
if (r <= 100 - info.SuccessRate || self.Owner.WinState == WinState.Lost)
return;
if ((!info.EjectInAir && cp.Z > 0) || (!info.EjectOnGround && cp.Z == 0))
return;
var pilot = self.World.CreateActor(false, info.PilotActor.ToLowerInvariant(),
new TypeDictionary { new OwnerInit(self.Owner), new LocationInit(self.Location) });
if (IsSuitableCell(self, pilot, self.Location))
{
self.World.AddFrameEndTask(w => w.Add(new Parachute(pilot, cp)));
Sound.Play(info.ChuteSound, cp);
if (cp.Z > 0 && info.EjectInAir)
{
self.World.AddFrameEndTask(w => w.Add(new Parachute(pilot, cp)));
Sound.Play(info.ChuteSound, cp);
}
else if (cp.Z == 0 && info.EjectOnGround)
self.World.AddFrameEndTask(w => w.Add(pilot));
}
else
pilot.Destroy();
}
bool IsSuitableCell(Actor actorToDrop, CPos p)
bool IsSuitableCell(Actor self, Actor actorToDrop, CPos p)
{
return actorToDrop.Trait<IPositionable>().CanEnterCell(p);
return actorToDrop.Trait<IPositionable>().CanEnterCell(self.Location, self, true);
}
}
}

View File

@@ -37,6 +37,11 @@
Guard:
Guardable:
BodyOrientation:
EjectOnDeath:
PilotActor: e1
SuccessRate: 20
EjectOnGround: yes
EjectInAir: no
^Tank:
AppearsOnRadar:
@@ -77,6 +82,11 @@
Guard:
Guardable:
BodyOrientation:
EjectOnDeath:
PilotActor: e1
SuccessRate: 20
EjectOnGround: yes
EjectInAir: no
^Infantry:
AppearsOnRadar:
@@ -185,6 +195,8 @@
EjectOnDeath:
PilotActor: E1
SuccessRate: 50
EjectOnDeath: no
EjectInAir: yes
GivesBounty:
GpsDot:
String:Plane