normalize the handling of flares in paradrop and airstrike cases

This commit is contained in:
Chris Forbes
2011-03-02 23:05:58 +13:00
parent 9b2fe9fead
commit d1b632a4a0
4 changed files with 131 additions and 141 deletions

View File

@@ -48,45 +48,45 @@ namespace OpenRA.Mods.RA
for (var n = 0; n < toSpawn; n++) for (var n = 0; n < toSpawn; n++)
SpawnCrate(self, info); SpawnCrate(self, info);
} }
} }
void SpawnCrate(Actor self, CrateDropInfo info) void SpawnCrate(Actor self, CrateDropInfo info)
{ {
var threshold = 100; var threshold = 100;
var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance; var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance;
for (var n = 0; n < threshold; n++ ) for (var n = 0; n < threshold; n++)
{ {
var p = self.World.ChooseRandomCell(self.World.SharedRandom); var p = self.World.ChooseRandomCell(self.World.SharedRandom);
// Is this valid terrain? // Is this valid terrain?
var terrainType = self.World.GetTerrainType(p); var terrainType = self.World.GetTerrainType(p);
if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrainType)) continue; if (!(inWater ? info.ValidWater : info.ValidGround).Contains(terrainType)) continue;
// Don't drop on any actors // Don't drop on any actors
if (self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(p) != null) continue; if (self.World.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(p) != null) continue;
if (self.World.WorldActor.Trait<UnitInfluence>().GetUnitsAt(p).Any()) continue; if (self.World.WorldActor.Trait<UnitInfluence>().GetUnitsAt(p).Any()) continue;
self.World.AddFrameEndTask(w => self.World.AddFrameEndTask(w =>
{ {
var crate = w.CreateActor(false, "crate", new TypeDictionary { new OwnerInit(w.WorldActor.Owner) }); var crate = w.CreateActor(false, "crate", new TypeDictionary { new OwnerInit(w.WorldActor.Owner) });
crates.Add(crate); crates.Add(crate);
var startPos = w.ChooseRandomEdgeCell(); var startPos = w.ChooseRandomEdgeCell();
var plane = w.CreateActor("badr", new TypeDictionary var plane = w.CreateActor("badr", new TypeDictionary
{ {
new LocationInit( startPos ), new LocationInit( startPos ),
new OwnerInit( w.WorldActor.Owner), new OwnerInit( w.WorldActor.Owner),
new FacingInit( Util.GetFacing(p - startPos, 0) ), new FacingInit( Util.GetFacing(p - startPos, 0) ),
new AltitudeInit( Rules.Info["badr"].Traits.Get<AircraftInfo>().CruiseAltitude ), new AltitudeInit( Rules.Info["badr"].Traits.Get<AircraftInfo>().CruiseAltitude ),
}); });
plane.CancelActivity(); plane.CancelActivity();
plane.QueueActivity(new FlyCircle(p)); plane.QueueActivity(new FlyCircle(p));
plane.Trait<ParaDrop>().SetLZ(p, null); plane.Trait<ParaDrop>().SetLZ(p);
plane.Trait<Cargo>().Load(plane, crate); plane.Trait<Cargo>().Load(plane, crate);
}); });
return; return;
} }
} }
} }
} }

View File

@@ -6,99 +6,75 @@
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
* see COPYING. * see COPYING.
*/ */
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Effects; using OpenRA.Mods.RA.Air;
using OpenRA.Traits; using OpenRA.Mods.RA.Effects;
using OpenRA.Mods.RA.Air; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
public class ParaDropInfo : TraitInfo<ParaDrop> public class ParaDropInfo : TraitInfo<ParaDrop>
{ {
public readonly int LZRange = 4; public readonly int LZRange = 4;
public readonly string ChuteSound = "chute1.aud"; public readonly string ChuteSound = "chute1.aud";
} }
public class ParaDrop : ITick, INotifyDamage public class ParaDrop : ITick
{ {
readonly List<int2> droppedAt = new List<int2>(); readonly List<int2> droppedAt = new List<int2>();
int2 lz; int2 lz;
Actor flare;
public void SetLZ(int2 lz)
public void SetLZ( int2 lz, Actor flare ) {
{ this.lz = lz;
this.lz = lz; droppedAt.Clear();
this.flare = flare; }
droppedAt.Clear();
} public void Tick(Actor self)
{
public void Tick(Actor self) var info = self.Info.Traits.Get<ParaDropInfo>();
{ var r = info.LZRange;
var info = self.Info.Traits.Get<ParaDropInfo>();
var r = info.LZRange; if ((self.Location - lz).LengthSquared <= r * r && !droppedAt.Contains(self.Location))
{
if ((self.Location - lz).LengthSquared <= r * r && !droppedAt.Contains(self.Location)) var cargo = self.Trait<Cargo>();
{ if (cargo.IsEmpty(self))
var cargo = self.Trait<Cargo>(); FinishedDropping(self);
if (cargo.IsEmpty(self)) else
FinishedDropping(self); {
else if (!IsSuitableCell(cargo.Peek(self), self.Location))
{ return;
if (!IsSuitableCell(cargo.Peek(self), self.Location))
return; // unload a dude here
droppedAt.Add(self.Location);
// unload a dude here
droppedAt.Add(self.Location); var a = cargo.Unload(self);
var rs = a.Trait<RenderSimple>();
var a = cargo.Unload(self);
var rs = a.Trait<RenderSimple>(); var aircraft = self.Trait<IMove>();
self.World.AddFrameEndTask(w => w.Add(
var aircraft = self.Trait<IMove>(); new Parachute(self.Owner, rs.anim.Name,
self.World.AddFrameEndTask(w => w.Add( Util.CenterOfCell(Util.CellContaining(self.CenterLocation)),
new Parachute(self.Owner, rs.anim.Name, aircraft.Altitude, a)));
Util.CenterOfCell(Util.CellContaining(self.CenterLocation)),
aircraft.Altitude, a))); Sound.Play(info.ChuteSound, self.CenterLocation);
}
Sound.Play(info.ChuteSound, self.CenterLocation); }
} }
}
} bool IsSuitableCell(Actor actorToDrop, int2 p)
{
bool IsSuitableCell(Actor actorToDrop, int2 p) return actorToDrop.Trait<ITeleportable>().CanEnterCell(p);
{ }
return actorToDrop.Trait<ITeleportable>().CanEnterCell(p);
} void FinishedDropping(Actor self)
{
void FinishedDropping(Actor self) self.CancelActivity();
{ self.QueueActivity(new FlyOffMap { Interruptible = false });
self.CancelActivity(); self.QueueActivity(new RemoveSelf());
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;
}
}
}
}
} }

View File

@@ -10,8 +10,7 @@
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Air; using OpenRA.Mods.RA.Air;
using OpenRA.Orders;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
@@ -21,7 +20,9 @@ namespace OpenRA.Mods.RA
[ActorReference] [ActorReference]
public readonly string UnitType = "badr.bomber"; public readonly string UnitType = "badr.bomber";
[ActorReference] [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); } 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 LocationInit( order.TargetLocation ),
new OwnerInit( self.Owner ), 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 var a = w.CreateActor(info.UnitType, new TypeDictionary
{ {

View File

@@ -6,13 +6,12 @@
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
* see COPYING. * see COPYING.
*/ */
#endregion #endregion
using OpenRA.Mods.RA.Activities; using OpenRA.FileFormats;
using OpenRA.Orders; using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Air;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.FileFormats;
using OpenRA.Mods.RA.Air;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
@@ -23,7 +22,9 @@ namespace OpenRA.Mods.RA
[ActorReference] [ActorReference]
public string UnitType = "badr"; public string UnitType = "badr";
[ActorReference] [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); } 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 LocationInit( order.TargetLocation ),
new OwnerInit( self.Owner ), 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 var a = w.CreateActor(info.UnitType, new TypeDictionary
{ {
@@ -56,7 +63,7 @@ namespace OpenRA.Mods.RA
a.CancelActivity(); a.CancelActivity();
a.QueueActivity(new FlyCircle(order.TargetLocation)); a.QueueActivity(new FlyCircle(order.TargetLocation));
a.Trait<ParaDrop>().SetLZ(order.TargetLocation, flare); a.Trait<ParaDrop>().SetLZ(order.TargetLocation);
var cargo = a.Trait<Cargo>(); var cargo = a.Trait<Cargo>();
foreach (var i in items) foreach (var i in items)