Overhaul ParatroopersPower:

- Adds support for multiple drop planes.
- Adds support a beacon and camera.
- Prevents the plane from circling if it can’t unload.
This commit is contained in:
Paul Chote
2014-07-07 21:11:41 +12:00
parent fa83507a62
commit ab26d4b0ad
10 changed files with 219 additions and 66 deletions

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -8,6 +8,7 @@
*/ */
#endregion #endregion
using System;
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Air; using OpenRA.Mods.RA.Air;
@@ -16,48 +17,71 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
public class ParaDropInfo : TraitInfo<ParaDrop> public class ParaDropInfo : ITraitInfo, Requires<CargoInfo>
{ {
public readonly int LZRange = 4; [Desc("Distance around the drop-point to unload troops")]
public readonly WRange DropRange = WRange.FromCells(4);
[Desc("Sound to play when dropping")]
public readonly string ChuteSound = "chute1.aud"; public readonly string ChuteSound = "chute1.aud";
public object Create(ActorInitializer init) { return new ParaDrop(init.self, this); }
} }
public class ParaDrop : ITick public class ParaDrop : ITick, INotifyRemovedFromWorld
{ {
readonly ParaDropInfo info;
readonly Actor self;
readonly Cargo cargo;
readonly HashSet<CPos> droppedAt = new HashSet<CPos>();
public event Action<Actor> OnRemovedFromWorld = self => { };
public event Action<Actor> OnEnteredDropRange = self => { };
public event Action<Actor> OnExitedDropRange = self => { };
[Sync] bool inDropRange;
[Sync] Target target;
bool checkForSuitableCell; bool checkForSuitableCell;
readonly List<CPos> droppedAt = new List<CPos>();
CPos lz; public ParaDrop(Actor self, ParaDropInfo info)
{
this.info = info;
this.self = self;
cargo = self.Trait<Cargo>();
}
public void SetLZ(CPos lz, bool checkLandingCell) public void SetLZ(CPos lz, bool checkLandingCell)
{ {
this.lz = lz;
droppedAt.Clear(); droppedAt.Clear();
target = Target.FromCell(self.World, lz);
checkForSuitableCell = checkLandingCell; checkForSuitableCell = checkLandingCell;
} }
public void Tick(Actor self) public void Tick(Actor self)
{ {
var info = self.Info.Traits.Get<ParaDropInfo>(); var wasInDropRange = inDropRange;
var r = info.LZRange; inDropRange = target.IsInRange(self.CenterPosition, info.DropRange);
if ((self.Location - lz).LengthSquared <= r * r && !droppedAt.Contains(self.Location)) if (inDropRange && !wasInDropRange)
{ OnEnteredDropRange(self);
var cargo = self.Trait<Cargo>();
if (cargo.IsEmpty(self))
FinishedDropping(self);
else
{
if (checkForSuitableCell && !IsSuitableCell(cargo.Peek(self), self.Location))
return;
// unload a dude here if (!inDropRange && wasInDropRange)
droppedAt.Add(self.Location); OnExitedDropRange(self);
var a = cargo.Unload(self); // Are we able to drop the next trooper?
self.World.AddFrameEndTask(w => w.Add(new Parachute(a, self.CenterPosition))); if (!inDropRange || cargo.IsEmpty(self))
Sound.Play(info.ChuteSound, self.CenterPosition); return;
}
} if (droppedAt.Contains(self.Location) || checkForSuitableCell && !IsSuitableCell(cargo.Peek(self), self.Location))
return;
// unload a dude here
droppedAt.Add(self.Location);
var a = cargo.Unload(self);
self.World.AddFrameEndTask(w => w.Add(new Parachute(a, self.CenterPosition)));
Sound.Play(info.ChuteSound, self.CenterPosition);
} }
static bool IsSuitableCell(Actor actorToDrop, CPos p) static bool IsSuitableCell(Actor actorToDrop, CPos p)
@@ -65,11 +89,9 @@ namespace OpenRA.Mods.RA
return actorToDrop.Trait<IPositionable>().CanEnterCell(p); return actorToDrop.Trait<IPositionable>().CanEnterCell(p);
} }
static void FinishedDropping(Actor self) public void RemovedFromWorld(Actor self)
{ {
self.CancelActivity(); OnRemovedFromWorld(self);
self.QueueActivity(new FlyOffMap());
self.QueueActivity(new RemoveSelf());
} }
} }
} }

View File

@@ -8,8 +8,12 @@
*/ */
#endregion #endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Air; using OpenRA.Mods.RA.Air;
using OpenRA.Mods.RA.Effects;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
@@ -18,18 +22,33 @@ namespace OpenRA.Mods.RA
public class ParatroopersPowerInfo : SupportPowerInfo public class ParatroopersPowerInfo : SupportPowerInfo
{ {
[ActorReference] [ActorReference]
public string[] DropItems = { }; public readonly string UnitType = "badr";
[ActorReference] public readonly int SquadSize = 1;
public string UnitType = "badr"; public readonly WVec SquadOffset = new WVec(-1536, 1536, 0);
[ActorReference]
public string FlareType = "flare";
[Desc("In game ticks. Default value equates to 2 minutes.")] [Desc("Number of facings that the delivery aircraft may approach from.")]
public readonly int FlareTime = 25 * 60 * 2; public readonly int QuantizedFacings = 32;
[Desc("Spawn and remove the plane this far outside the map.")]
public readonly WRange Cordon = new WRange(5120);
[ActorReference]
[Desc("Troops to be delivered. They will be distributed between the planes if SquadSize > 1.")]
public string[] DropItems = { };
[Desc("Risks stuck units when they don't have the Paratrooper trait.")] [Desc("Risks stuck units when they don't have the Paratrooper trait.")]
public readonly bool AllowImpassableCells = false; public readonly bool AllowImpassableCells = false;
[ActorReference]
[Desc("Actor to spawn when the paradrop starts.")]
public readonly string CameraActor = null;
[Desc("Amount of time (in ticks) to keep the camera alive while the passengers drop.")]
public readonly int CameraRemoveDelay = 85;
[Desc("Weapon range offset to apply during the beacon clock calculation.")]
public readonly WRange BeaconDistanceOffset = WRange.FromCells(4);
public override object Create(ActorInitializer init) { return new ParatroopersPower(init.self, this); } public override object Create(ActorInitializer init) { return new ParatroopersPower(init.self, this); }
} }
@@ -41,40 +60,126 @@ namespace OpenRA.Mods.RA
{ {
base.Activate(self, order, manager); base.Activate(self, order, manager);
var info = (ParatroopersPowerInfo)Info; var info = Info as ParatroopersPowerInfo;
var items = info.DropItems; var dropFacing = Util.QuantizeFacing(self.World.SharedRandom.Next(256), info.QuantizedFacings) * (256 / info.QuantizedFacings);
var startPos = self.World.Map.ChooseRandomEdgeCell(self.World.SharedRandom); var dropRotation = WRot.FromFacing(dropFacing);
var delta = new WVec(0, -1024, 0).Rotate(dropRotation);
var altitude = self.World.Map.Rules.Actors[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude.Range;
var target = self.World.Map.CenterOfCell(order.TargetLocation) + new WVec(0, 0, altitude);
var startEdge = target - (self.World.Map.DistanceToEdge(target, -delta) + info.Cordon).Range * delta / 1024;
var finishEdge = target + (self.World.Map.DistanceToEdge(target, delta) + info.Cordon).Range * delta / 1024;
Actor camera = null;
Beacon beacon = null;
var aircraftInRange = new Dictionary<Actor, bool>();
Action<Actor> onEnterRange = a =>
{
// Spawn a camera and remove the beacon when the first plane enters the target area
if (info.CameraActor != null && !aircraftInRange.Any(kv => kv.Value))
{
self.World.AddFrameEndTask(w =>
{
camera = w.CreateActor(info.CameraActor, new TypeDictionary
{
new LocationInit(order.TargetLocation),
new OwnerInit(self.Owner),
});
});
}
if (beacon != null)
{
self.World.AddFrameEndTask(w =>
{
w.Remove(beacon);
beacon = null;
});
}
aircraftInRange[a] = true;
};
Action<Actor> onExitRange = a =>
{
aircraftInRange[a] = false;
// Remove the camera when the final plane leaves the target area
if (!aircraftInRange.Any(kv => kv.Value))
{
if (camera != null)
{
camera.QueueActivity(new Wait(info.CameraRemoveDelay));
camera.QueueActivity(new RemoveSelf());
}
camera = null;
}
};
self.World.AddFrameEndTask(w => self.World.AddFrameEndTask(w =>
{ {
var flare = info.FlareType != null ? w.CreateActor(info.FlareType, new TypeDictionary var notification = self.Owner.IsAlliedWith(self.World.RenderPlayer) ? Info.LaunchSound : Info.IncomingSound;
{ Sound.Play(notification);
new LocationInit(order.TargetLocation),
new OwnerInit(self.Owner),
}) : null;
if (flare != null) Actor distanceTestActor = null;
var passengersPerPlane = (info.DropItems.Length + info.SquadSize - 1) / info.SquadSize;
var added = 0;
for (var i = -info.SquadSize / 2; i <= info.SquadSize / 2; i++)
{ {
flare.QueueActivity(new Wait(info.FlareTime)); // Even-sized squads skip the lead plane
flare.QueueActivity(new RemoveSelf()); if (i == 0 && (info.SquadSize & 1) == 0)
continue;
// Includes the 90 degree rotation between body and world coordinates
var so = info.SquadOffset;
var spawnOffset = new WVec(i * so.Y, -Math.Abs(i) * so.X, 0).Rotate(dropRotation);
var targetOffset = new WVec(i * so.Y, 0, 0).Rotate(dropRotation);
var a = w.CreateActor(info.UnitType, new TypeDictionary
{
new CenterPositionInit(startEdge + spawnOffset),
new OwnerInit(self.Owner),
new FacingInit(dropFacing),
});
var drop = a.Trait<ParaDrop>();
drop.SetLZ(w.Map.CellContaining(target + targetOffset), !info.AllowImpassableCells);
drop.OnEnteredDropRange += onEnterRange;
drop.OnExitedDropRange += onExitRange;
drop.OnRemovedFromWorld += onExitRange;
var cargo = a.Trait<Cargo>();
var passengers = info.DropItems.Skip(added).Take(passengersPerPlane);
added += passengersPerPlane;
foreach (var p in passengers)
cargo.Load(a, self.World.CreateActor(false, p.ToLowerInvariant(),
new TypeDictionary { new OwnerInit(a.Owner) }));
a.QueueActivity(new Fly(a, Target.FromPos(finishEdge + spawnOffset)));
a.QueueActivity(new RemoveSelf());
aircraftInRange.Add(a, false);
distanceTestActor = a;
} }
var altitude = self.World.Map.Rules.Actors[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude; if (Info.DisplayBeacon)
var a = w.CreateActor(info.UnitType, new TypeDictionary
{ {
new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WRange.Zero, WRange.Zero, altitude)), var distance = (target - startEdge).HorizontalLength;
new OwnerInit(self.Owner),
new FacingInit(w.Map.FacingBetween(startPos, order.TargetLocation, 0))
});
a.CancelActivity(); beacon = new Beacon(
a.QueueActivity(new FlyAttack(Target.FromOrder(self.World, order))); order.Player,
a.Trait<ParaDrop>().SetLZ(order.TargetLocation, !info.AllowImpassableCells); self.World.Map.CenterOfCell(order.TargetLocation),
Info.BeaconPalettePrefix,
Info.BeaconPoster,
Info.BeaconPosterPalette,
() => 1 - ((distanceTestActor.CenterPosition - target).HorizontalLength - info.BeaconDistanceOffset.Range) * 1f / distance
);
var cargo = a.Trait<Cargo>(); w.Add(beacon);
foreach (var i in items) }
cargo.Load(a, self.World.CreateActor(false, i.ToLowerInvariant(),
new TypeDictionary { new OwnerInit(a.Owner) }));
}); });
} }
} }

View File

@@ -282,9 +282,9 @@ namespace OpenRA.Utility
node.Key = "ParachuteSequence"; node.Key = "ParachuteSequence";
} }
// SpyPlanePower was removed (use AirstrikePower instead)
if (engineVersion < 20140707) if (engineVersion < 20140707)
{ {
// SpyPlanePower was removed (use AirstrikePower instead)
if (depth == 1 && node.Key == "SpyPlanePower") if (depth == 1 && node.Key == "SpyPlanePower")
{ {
node.Key = "AirstrikePower"; node.Key = "AirstrikePower";
@@ -301,6 +301,12 @@ namespace OpenRA.Utility
node.Value.Nodes.Add(new MiniYamlNode("CameraRemoveDelay", new MiniYaml(revealTime.ToString()))); node.Value.Nodes.Add(new MiniYamlNode("CameraRemoveDelay", new MiniYaml(revealTime.ToString())));
node.Value.Nodes.Add(new MiniYamlNode("UnitType", new MiniYaml("u2"))); node.Value.Nodes.Add(new MiniYamlNode("UnitType", new MiniYaml("u2")));
} }
if (depth == 2 && node.Key == "LZRange" && parentKey == "ParaDrop")
{
node.Key = "DropRange";
ConvertFloatToRange(ref node.Value.Value);
}
} }
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);

View File

@@ -32,7 +32,7 @@
FRIGATE: FRIGATE:
ParaDrop: ParaDrop:
LZRange: 1 DropRange: 1c0
Inherits: ^Plane Inherits: ^Plane
Tooltip: Tooltip:
Name: Frigate Name: Frigate
@@ -121,7 +121,7 @@ ORNI.bomber:
CARRYALL.infantry: CARRYALL.infantry:
ParaDrop: ParaDrop:
LZRange: 5 DropRange: 5c0
ChuteSound: ChuteSound:
Inherits: ^Plane Inherits: ^Plane
Health: Health:
@@ -152,7 +152,7 @@ CARRYALL.infantry:
BADR: BADR:
Inherits: CARRYALL.infantry Inherits: CARRYALL.infantry
ParaDrop: ParaDrop:
LZRange: 4 DropRange: 4c0
Tooltip: Tooltip:
Name: Crate Carryall Name: Crate Carryall
LeavesHusk: LeavesHusk:

Binary file not shown.

View File

@@ -1,6 +1,6 @@
BADR: BADR:
ParaDrop: ParaDrop:
LZRange: 4 DropRange: 4c0
Inherits: ^Plane Inherits: ^Plane
Health: Health:
HP: 300 HP: 300

View File

@@ -140,6 +140,17 @@ CAMERA:
DetectCloaked: DetectCloaked:
Range: 10 Range: 10
camera.paradrop:
Immobile:
OccupiesSpace: false
Health:
HP: 1000
RevealsShroud:
Range: 6c0
ProximityCaptor:
Types: Camera
BodyOrientation:
FLARE: FLARE:
Immobile: Immobile:
OccupiesSpace: false OccupiesSpace: false

View File

@@ -901,7 +901,7 @@ AFLD:
CameraRemoveDelay: 150 CameraRemoveDelay: 150
UnitType: u2 UnitType: u2
QuantizedFacings: 8 QuantizedFacings: 8
DisplayBeacon: True DisplayBeacon: true
BeaconPoster: camicon BeaconPoster: camicon
ParatroopersPower: ParatroopersPower:
Icon: paratroopers Icon: paratroopers
@@ -911,6 +911,10 @@ AFLD:
DropItems: E1,E1,E1,E3,E3 DropItems: E1,E1,E1,E3,E3
SelectTargetSound: slcttgt1.aud SelectTargetSound: slcttgt1.aud
AllowImpassableCells: false AllowImpassableCells: false
QuantizedFacings: 8
CameraActor: camera.paradrop
DisplayBeacon: true
BeaconPoster: pinficon
ProductionBar: ProductionBar:
SupportPowerChargeBar: SupportPowerChargeBar:
PrimaryBuilding: PrimaryBuilding:

View File

@@ -21,6 +21,7 @@ World:
Bridges: bridge1, bridge2, br1, br2, br3, sbridge1, sbridge2, sbridge3, sbridge4 Bridges: bridge1, bridge2, br1, br2, br3, sbridge1, sbridge2, sbridge3, sbridge4
CrateSpawner: CrateSpawner:
DeliveryAircraft: badr DeliveryAircraft: badr
QuantizedFacings: 16
Minimum: 1 Minimum: 1
Maximum: 3 Maximum: 3
SpawnInterval: 120 SpawnInterval: 120

View File

@@ -137,6 +137,10 @@ beacon:
Start: 0 Start: 0
Length: * Length: *
Offset: 0,-42 Offset: 0,-42
pinficon: lores-pinficon
Start: 0
Length: *
Offset: 0,-42
clock: beaconclock clock: beaconclock
Start: 0 Start: 0
Length: * Length: *