Add clock overlay to support power beacons.

This commit is contained in:
Paul Chote
2014-05-31 18:17:48 +12:00
parent 91126b9c48
commit e1501d5b7c
9 changed files with 83 additions and 38 deletions

View File

@@ -43,6 +43,9 @@ namespace OpenRA.Mods.RA
[Desc("Amount of time to keep the camera alive after the aircraft have finished attacking")]
public readonly int CameraRemoveDelay = 25;
[Desc("Weapon range offset to apply during the beacon clock calculation")]
public readonly WRange BeaconDistanceOffset = WRange.FromCells(6);
public override object Create(ActorInitializer init) { return new AirstrikePower(init.self, this); }
}
@@ -55,20 +58,6 @@ namespace OpenRA.Mods.RA
{
base.Activate(self, order, manager);
Beacon beacon = null;
if (Info.DisplayBeacon)
{
beacon = new Beacon(
order.Player,
order.TargetLocation.CenterPosition,
-1,
Info.BeaconPalettePrefix,
Info.BeaconPoster,
Info.BeaconPosterPalette);
self.World.Add(beacon);
}
var info = Info as AirstrikePowerInfo;
var attackFacing = Util.QuantizeFacing(self.World.SharedRandom.Next(256), info.QuantizedFacings) * (256 / info.QuantizedFacings);
var attackRotation = WRot.FromFacing(attackFacing);
@@ -81,6 +70,7 @@ namespace OpenRA.Mods.RA
Actor flare = null;
Actor camera = null;
Beacon beacon = null;
Dictionary<Actor, bool> aircraftInRange = new Dictionary<Actor, bool>();
Action<Actor> onEnterRange = a =>
@@ -147,6 +137,7 @@ namespace OpenRA.Mods.RA
var notification = self.Owner.IsAlliedWith(self.World.RenderPlayer) ? Info.LaunchSound : Info.IncomingSound;
Sound.Play(notification);
Actor distanceTestActor = null;
for (var i = -info.SquadSize / 2; i <= info.SquadSize / 2; i++)
{
// Even-sized squads skip the lead plane
@@ -174,6 +165,23 @@ namespace OpenRA.Mods.RA
a.QueueActivity(new Fly(a, Target.FromPos(finishEdge + spawnOffset)));
a.QueueActivity(new RemoveSelf());
aircraftInRange.Add(a, false);
distanceTestActor = a;
}
if (Info.DisplayBeacon)
{
var distance = (target - startEdge).HorizontalLength;
beacon = new Beacon(
order.Player,
order.TargetLocation.CenterPosition,
Info.BeaconPalettePrefix,
Info.BeaconPoster,
Info.BeaconPosterPalette,
() => 1 - ((distanceTestActor.CenterPosition - target).HorizontalLength - info.BeaconDistanceOffset.Range) * 1f / distance
);
w.Add(beacon);
}
});
}

View File

@@ -68,20 +68,6 @@ namespace OpenRA.Mods.RA
{
base.Activate(self, order, manager);
Beacon beacon = null;
if (Info.DisplayBeacon)
{
beacon = new Beacon(
order.Player,
order.TargetLocation.CenterPosition,
-1,
Info.BeaconPalettePrefix,
Info.BeaconPoster,
Info.BeaconPosterPalette);
self.World.Add(beacon);
}
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
Sound.Play(Info.LaunchSound);
else
@@ -91,10 +77,12 @@ namespace OpenRA.Mods.RA
var rb = self.Trait<RenderSimple>();
rb.PlayCustomAnim(self, "active");
self.World.AddFrameEndTask(w => w.Add(new NukeLaunch(self.Owner, npi.MissileWeapon,
var missile = new NukeLaunch(self.Owner, npi.MissileWeapon,
self.CenterPosition + body.LocalToWorld(npi.SpawnOffset),
order.TargetLocation.CenterPosition,
npi.FlightVelocity, npi.FlightDelay, npi.SkipAscent)));
npi.FlightVelocity, npi.FlightDelay, npi.SkipAscent);
self.World.AddFrameEndTask(w => w.Add(missile));
if (npi.CameraActor != null)
{
@@ -111,15 +99,29 @@ namespace OpenRA.Mods.RA
self.World.AddFrameEndTask(w => w.Add(new DelayedAction(npi.FlightDelay - npi.CameraSpawnAdvance, addCamera)));
}
if (beacon != null)
if (Info.DisplayBeacon)
{
var beacon = new Beacon(
order.Player,
order.TargetLocation.CenterPosition,
Info.BeaconPalettePrefix,
Info.BeaconPoster,
Info.BeaconPosterPalette,
() => missile.FractionComplete
);
Action removeBeacon = () => self.World.AddFrameEndTask(w =>
{
w.Remove(beacon);
beacon = null;
});
self.World.AddFrameEndTask(w => w.Add(new DelayedAction(npi.FlightDelay - npi.BeaconRemoveAdvance, removeBeacon)));
self.World.AddFrameEndTask(w =>
{
w.Add(beacon);
w.Add(new DelayedAction(npi.FlightDelay - npi.BeaconRemoveAdvance, removeBeacon));
});
}
}
}