normalize the handling of flares in paradrop and airstrike cases
This commit is contained in:
@@ -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<BuildingInfluence>().GetBuildingAt(p) != null) continue;
|
||||
if (self.World.WorldActor.Trait<UnitInfluence>().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<BuildingInfluence>().GetBuildingAt(p) != null) continue;
|
||||
if (self.World.WorldActor.Trait<UnitInfluence>().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<AircraftInfo>().CruiseAltitude ),
|
||||
});
|
||||
plane.CancelActivity();
|
||||
plane.QueueActivity(new FlyCircle(p));
|
||||
plane.Trait<ParaDrop>().SetLZ(p, null);
|
||||
plane.Trait<Cargo>().Load(plane, crate);
|
||||
});
|
||||
return;
|
||||
}
|
||||
});
|
||||
plane.CancelActivity();
|
||||
plane.QueueActivity(new FlyCircle(p));
|
||||
plane.Trait<ParaDrop>().SetLZ(p);
|
||||
plane.Trait<Cargo>().Load(plane, crate);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ParaDrop>
|
||||
{
|
||||
public readonly int LZRange = 4;
|
||||
public readonly string ChuteSound = "chute1.aud";
|
||||
}
|
||||
|
||||
public class ParaDrop : ITick, INotifyDamage
|
||||
{
|
||||
readonly List<int2> droppedAt = new List<int2>();
|
||||
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<ParaDropInfo>();
|
||||
var r = info.LZRange;
|
||||
|
||||
if ((self.Location - lz).LengthSquared <= r * r && !droppedAt.Contains(self.Location))
|
||||
{
|
||||
var cargo = self.Trait<Cargo>();
|
||||
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<RenderSimple>();
|
||||
|
||||
var aircraft = self.Trait<IMove>();
|
||||
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<ITeleportable>().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<ParaDrop>
|
||||
{
|
||||
public readonly int LZRange = 4;
|
||||
public readonly string ChuteSound = "chute1.aud";
|
||||
}
|
||||
|
||||
public class ParaDrop : ITick
|
||||
{
|
||||
readonly List<int2> droppedAt = new List<int2>();
|
||||
int2 lz;
|
||||
|
||||
public void SetLZ(int2 lz)
|
||||
{
|
||||
this.lz = lz;
|
||||
droppedAt.Clear();
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
var info = self.Info.Traits.Get<ParaDropInfo>();
|
||||
var r = info.LZRange;
|
||||
|
||||
if ((self.Location - lz).LengthSquared <= r * r && !droppedAt.Contains(self.Location))
|
||||
{
|
||||
var cargo = self.Trait<Cargo>();
|
||||
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<RenderSimple>();
|
||||
|
||||
var aircraft = self.Trait<IMove>();
|
||||
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<ITeleportable>().CanEnterCell(p);
|
||||
}
|
||||
|
||||
void FinishedDropping(Actor self)
|
||||
{
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new FlyOffMap { Interruptible = false });
|
||||
self.QueueActivity(new RemoveSelf());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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<ParaDrop>().SetLZ(order.TargetLocation, flare);
|
||||
a.Trait<ParaDrop>().SetLZ(order.TargetLocation);
|
||||
|
||||
var cargo = a.Trait<Cargo>();
|
||||
foreach (var i in items)
|
||||
|
||||
Reference in New Issue
Block a user