diff --git a/OpenRA.Mods.RA/CrateDrop.cs b/OpenRA.Mods.RA/CrateDrop.cs index eb4a4e2c0b..dad39bf1de 100644 --- a/OpenRA.Mods.RA/CrateDrop.cs +++ b/OpenRA.Mods.RA/CrateDrop.cs @@ -48,45 +48,45 @@ namespace OpenRA.Mods.RA for (var n = 0; n < toSpawn; n++) SpawnCrate(self, info); } - } - - void SpawnCrate(Actor self, CrateDropInfo info) - { - var threshold = 100; - var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance; - - for (var n = 0; n < threshold; n++ ) - { - var p = self.World.ChooseRandomCell(self.World.SharedRandom); - - // Is this valid terrain? - var terrainType = self.World.GetTerrainType(p); - if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrainType)) continue; - - // Don't drop on any actors - if (self.World.WorldActor.Trait().GetBuildingAt(p) != null) continue; - if (self.World.WorldActor.Trait().GetUnitsAt(p).Any()) continue; - - self.World.AddFrameEndTask(w => - { - var crate = w.CreateActor(false, "crate", new TypeDictionary { new OwnerInit(w.WorldActor.Owner) }); - crates.Add(crate); - - var startPos = w.ChooseRandomEdgeCell(); + } + + void SpawnCrate(Actor self, CrateDropInfo info) + { + var threshold = 100; + var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance; + + for (var n = 0; n < threshold; n++) + { + var p = self.World.ChooseRandomCell(self.World.SharedRandom); + + // Is this valid terrain? + var terrainType = self.World.GetTerrainType(p); + if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrainType)) continue; + + // Don't drop on any actors + if (self.World.WorldActor.Trait().GetBuildingAt(p) != null) continue; + if (self.World.WorldActor.Trait().GetUnitsAt(p).Any()) continue; + + self.World.AddFrameEndTask(w => + { + var crate = w.CreateActor(false, "crate", new TypeDictionary { new OwnerInit(w.WorldActor.Owner) }); + crates.Add(crate); + + var startPos = w.ChooseRandomEdgeCell(); var plane = w.CreateActor("badr", new TypeDictionary { new LocationInit( startPos ), new OwnerInit( w.WorldActor.Owner), new FacingInit( Util.GetFacing(p - startPos, 0) ), new AltitudeInit( Rules.Info["badr"].Traits.Get().CruiseAltitude ), - }); - plane.CancelActivity(); - plane.QueueActivity(new FlyCircle(p)); - plane.Trait().SetLZ(p, null); - plane.Trait().Load(plane, crate); - }); - return; - } + }); + plane.CancelActivity(); + plane.QueueActivity(new FlyCircle(p)); + plane.Trait().SetLZ(p); + plane.Trait().Load(plane, crate); + }); + return; + } } } } diff --git a/OpenRA.Mods.RA/ParaDrop.cs b/OpenRA.Mods.RA/ParaDrop.cs index d850c6dc89..0c3aec892d 100644 --- a/OpenRA.Mods.RA/ParaDrop.cs +++ b/OpenRA.Mods.RA/ParaDrop.cs @@ -6,99 +6,75 @@ * as published by the Free Software Foundation. For more information, * see COPYING. */ -#endregion - -using System.Collections.Generic; -using OpenRA.Mods.RA.Activities; -using OpenRA.Mods.RA.Effects; -using OpenRA.Traits; -using OpenRA.Mods.RA.Air; - -namespace OpenRA.Mods.RA -{ - public class ParaDropInfo : TraitInfo - { - public readonly int LZRange = 4; - public readonly string ChuteSound = "chute1.aud"; - } - - public class ParaDrop : ITick, INotifyDamage - { - readonly List droppedAt = new List(); - int2 lz; - Actor flare; - - public void SetLZ( int2 lz, Actor flare ) - { - this.lz = lz; - this.flare = flare; - droppedAt.Clear(); - } - - public void Tick(Actor self) - { - var info = self.Info.Traits.Get(); - var r = info.LZRange; - - if ((self.Location - lz).LengthSquared <= r * r && !droppedAt.Contains(self.Location)) - { - var cargo = self.Trait(); - if (cargo.IsEmpty(self)) - FinishedDropping(self); - else - { - if (!IsSuitableCell(cargo.Peek(self), self.Location)) - return; - - // unload a dude here - droppedAt.Add(self.Location); - - var a = cargo.Unload(self); - var rs = a.Trait(); - - var aircraft = self.Trait(); - self.World.AddFrameEndTask(w => w.Add( - new Parachute(self.Owner, rs.anim.Name, - Util.CenterOfCell(Util.CellContaining(self.CenterLocation)), - aircraft.Altitude, a))); - - Sound.Play(info.ChuteSound, self.CenterLocation); - } - } - } - - bool IsSuitableCell(Actor actorToDrop, int2 p) - { - return actorToDrop.Trait().CanEnterCell(p); - } - - void FinishedDropping(Actor self) - { - self.CancelActivity(); - self.QueueActivity(new FlyOffMap { Interruptible = false }); - self.QueueActivity(new RemoveSelf()); - - if (flare != null) - { - flare.CancelActivity(); - flare.QueueActivity(new Wait(300)); - flare.QueueActivity(new RemoveSelf()); - flare = null; - } - } - - public void Damaged(Actor self, AttackInfo e) - { - if (e.DamageStateChanged && e.DamageState == DamageState.Dead) - { - if (flare != null) - { - flare.CancelActivity(); - flare.QueueActivity(new Wait(300)); - flare.QueueActivity(new RemoveSelf()); - flare = null; - } - } - } - } +#endregion + +using System.Collections.Generic; +using OpenRA.Mods.RA.Activities; +using OpenRA.Mods.RA.Air; +using OpenRA.Mods.RA.Effects; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA +{ + public class ParaDropInfo : TraitInfo + { + public readonly int LZRange = 4; + public readonly string ChuteSound = "chute1.aud"; + } + + public class ParaDrop : ITick + { + readonly List droppedAt = new List(); + int2 lz; + + public void SetLZ(int2 lz) + { + this.lz = lz; + droppedAt.Clear(); + } + + public void Tick(Actor self) + { + var info = self.Info.Traits.Get(); + var r = info.LZRange; + + if ((self.Location - lz).LengthSquared <= r * r && !droppedAt.Contains(self.Location)) + { + var cargo = self.Trait(); + if (cargo.IsEmpty(self)) + FinishedDropping(self); + else + { + if (!IsSuitableCell(cargo.Peek(self), self.Location)) + return; + + // unload a dude here + droppedAt.Add(self.Location); + + var a = cargo.Unload(self); + var rs = a.Trait(); + + var aircraft = self.Trait(); + self.World.AddFrameEndTask(w => w.Add( + new Parachute(self.Owner, rs.anim.Name, + Util.CenterOfCell(Util.CellContaining(self.CenterLocation)), + aircraft.Altitude, a))); + + Sound.Play(info.ChuteSound, self.CenterLocation); + } + } + } + + bool IsSuitableCell(Actor actorToDrop, int2 p) + { + return actorToDrop.Trait().CanEnterCell(p); + } + + void FinishedDropping(Actor self) + { + self.CancelActivity(); + self.QueueActivity(new FlyOffMap { Interruptible = false }); + self.QueueActivity(new RemoveSelf()); + } + } } diff --git a/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs b/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs index 1c28c071ae..bbd276f943 100755 --- a/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs @@ -10,8 +10,7 @@ using OpenRA.FileFormats; using OpenRA.Mods.RA.Activities; -using OpenRA.Mods.RA.Air; -using OpenRA.Orders; +using OpenRA.Mods.RA.Air; using OpenRA.Traits; namespace OpenRA.Mods.RA @@ -21,7 +20,9 @@ namespace OpenRA.Mods.RA [ActorReference] public readonly string UnitType = "badr.bomber"; [ActorReference] - public readonly string FlareType = null; + public readonly string FlareType = null; + + public readonly int FlareTime = 25 * 60 * 2; // 2 minutes public override object Create(ActorInitializer init) { return new AirstrikePower(init.self, this); } } @@ -39,7 +40,13 @@ namespace OpenRA.Mods.RA { new LocationInit( order.TargetLocation ), new OwnerInit( self.Owner ), - }) : null; + }) : null; + + if (flare != null) + { + flare.QueueActivity(new Wait(info.FlareTime)); + flare.QueueActivity(new RemoveSelf()); + } var a = w.CreateActor(info.UnitType, new TypeDictionary { diff --git a/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs b/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs index df6fab3347..a126f24fd5 100755 --- a/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs @@ -6,13 +6,12 @@ * as published by the Free Software Foundation. For more information, * see COPYING. */ -#endregion - -using OpenRA.Mods.RA.Activities; -using OpenRA.Orders; +#endregion + +using OpenRA.FileFormats; +using OpenRA.Mods.RA.Activities; +using OpenRA.Mods.RA.Air; using OpenRA.Traits; -using OpenRA.FileFormats; -using OpenRA.Mods.RA.Air; namespace OpenRA.Mods.RA { @@ -23,7 +22,9 @@ namespace OpenRA.Mods.RA [ActorReference] public string UnitType = "badr"; [ActorReference] - public string FlareType = "flare"; + public string FlareType = "flare"; + + public readonly int FlareTime = 25 * 60 * 2; // 2 minutes public override object Create(ActorInitializer init) { return new ParatroopersPower(init.self, this); } } @@ -44,7 +45,13 @@ namespace OpenRA.Mods.RA { new LocationInit( order.TargetLocation ), new OwnerInit( self.Owner ), - }) : null; + }) : null; + + if (flare != null) + { + flare.QueueActivity(new Wait(info.FlareTime)); + flare.QueueActivity(new RemoveSelf()); + } var a = w.CreateActor(info.UnitType, new TypeDictionary { @@ -56,7 +63,7 @@ namespace OpenRA.Mods.RA a.CancelActivity(); a.QueueActivity(new FlyCircle(order.TargetLocation)); - a.Trait().SetLZ(order.TargetLocation, flare); + a.Trait().SetLZ(order.TargetLocation); var cargo = a.Trait(); foreach (var i in items)