diff --git a/OpenRA.Mods.RA/Air/EjectOnDeath.cs b/OpenRA.Mods.RA/Air/EjectOnDeath.cs new file mode 100644 index 0000000000..76ca9837f5 --- /dev/null +++ b/OpenRA.Mods.RA/Air/EjectOnDeath.cs @@ -0,0 +1,61 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 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, + * see COPYING. + */ +#endregion + +using OpenRA.FileFormats; +using OpenRA.Mods.RA.Effects; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA +{ + public class EjectOnDeathInfo : TraitInfo + { + public readonly string PilotActor = "E1"; + public readonly int SuccessRate = 50; + public readonly string ChuteSound = "chute1.aud"; + } + + public class EjectOnDeath : INotifyDamage + { + + public void Damaged(Actor self, AttackInfo e) + { + if (self.IsDead()) + { + var a = self; + var info = self.Info.Traits.Get(); + var pilot = a.World.CreateActor(false, info.PilotActor.ToLowerInvariant(), new TypeDictionary { new OwnerInit(a.Owner) }); + var r = self.World.SharedRandom.Next(1, 100); + var aircraft = a.Trait(); + + if (IsSuitableCell(pilot, a.Location) && r > 100 - info.SuccessRate && aircraft.Altitude > 10) + { + var rs = pilot.Trait(); + + + a.World.AddFrameEndTask(w => w.Add( + new Parachute(pilot.Owner, rs.anim.Name, + Util.CenterOfCell(Util.CellContaining(a.CenterLocation)), + aircraft.Altitude, pilot))); + + Sound.Play(info.ChuteSound, a.CenterLocation); + } + else + { + pilot.Destroy(); + } + } + } + + bool IsSuitableCell(Actor actorToDrop, int2 p) + { + return actorToDrop.Trait().CanEnterCell(p); + } + } +} \ No newline at end of file diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index f83da36810..456ad29eb7 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - 9.0.30729 + 9.0.21022 2.0 {4A8A43B5-A9EF-4ED0-99DD-4BAB10A0DB6E} Library @@ -63,6 +63,7 @@ + diff --git a/mods/ra/rules/defaults.yaml b/mods/ra/rules/defaults.yaml index 848df98cd1..8cdf83a20b 100644 --- a/mods/ra/rules/defaults.yaml +++ b/mods/ra/rules/defaults.yaml @@ -136,6 +136,9 @@ DebugAircraftAltitude: ProximityCaptor: Types:Plane + EjectOnDeath: + PilotActor: E1 + SuccessRate: 50 ^Building: AppearsOnRadar: diff --git a/mods/ra/rules/vehicles.yaml b/mods/ra/rules/vehicles.yaml index 19e36a0243..a01c91f7c6 100644 --- a/mods/ra/rules/vehicles.yaml +++ b/mods/ra/rules/vehicles.yaml @@ -34,6 +34,7 @@ BADR: SmokeTrailWhenDamaged@1: Offset: -11, -11 Interval: 2 + -EjectOnDeath: BADR.bomber: CarpetBomb: @@ -72,6 +73,7 @@ BADR.bomber: SmokeTrailWhenDamaged@1: Offset: -11, -11 Interval: 2 + -EjectOnDeath: V2RL: Inherits: ^Vehicle