Rework airstrike flare and camera spawning.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2013 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
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
@@ -9,6 +9,8 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Air;
|
||||
@@ -27,8 +29,18 @@ namespace OpenRA.Mods.RA
|
||||
public readonly WRange Cordon = new WRange(5120);
|
||||
|
||||
[ActorReference]
|
||||
public readonly string FlareType = null;
|
||||
public readonly int FlareTime = 3000; // 2 minutes
|
||||
[Desc("Actor to spawn when the aircraft first enter the map")]
|
||||
public readonly string FlareActor = null;
|
||||
|
||||
[Desc("Amount of time to keep the flare alive after the aircraft have finished attacking")]
|
||||
public readonly int FlareRemoveDelay = 25;
|
||||
|
||||
[ActorReference]
|
||||
[Desc("Actor to spawn when the aircraft start attacking")]
|
||||
public readonly string CameraActor = null;
|
||||
|
||||
[Desc("Amount of time to keep the camera alive after the aircraft have finished attacking")]
|
||||
public readonly int CameraRemoveDelay = 25;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new AirstrikePower(init.self, this); }
|
||||
}
|
||||
@@ -51,24 +63,65 @@ namespace OpenRA.Mods.RA
|
||||
var startEdge = target - (self.World.DistanceToMapEdge(target, -delta) + info.Cordon).Range * delta / 1024;
|
||||
var finishEdge = target + (self.World.DistanceToMapEdge(target, delta) + info.Cordon).Range * delta / 1024;
|
||||
|
||||
Actor flare = null;
|
||||
Actor camera = null;
|
||||
Dictionary<Actor, bool> aircraftInRange = new Dictionary<Actor, bool>();
|
||||
|
||||
Action<Actor> onEnterRange = a =>
|
||||
{
|
||||
// Spawn a camera 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),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
if (flare != null)
|
||||
{
|
||||
flare.QueueActivity(new Wait(info.FlareRemoveDelay));
|
||||
flare.QueueActivity(new RemoveSelf());
|
||||
}
|
||||
|
||||
camera = flare = null;
|
||||
}
|
||||
};
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
var notification = self.Owner.IsAlliedWith(self.World.RenderPlayer) ? Info.LaunchSound : Info.IncomingSound;
|
||||
Sound.Play(notification);
|
||||
|
||||
Actor flare = null;
|
||||
if (info.FlareType != null)
|
||||
if (info.FlareActor != null)
|
||||
{
|
||||
flare = w.CreateActor(info.FlareType, new TypeDictionary
|
||||
flare = w.CreateActor(info.FlareActor, new TypeDictionary
|
||||
{
|
||||
new LocationInit(order.TargetLocation),
|
||||
new OwnerInit(self.Owner),
|
||||
});
|
||||
|
||||
flare.QueueActivity(new Wait(info.FlareTime));
|
||||
flare.QueueActivity(new RemoveSelf());
|
||||
}
|
||||
|
||||
var notification = self.Owner.IsAlliedWith(self.World.RenderPlayer) ? Info.LaunchSound : Info.IncomingSound;
|
||||
Sound.Play(notification);
|
||||
|
||||
for (var i = -info.SquadSize / 2; i <= info.SquadSize / 2; i++)
|
||||
{
|
||||
// Even-sized squads skip the lead plane
|
||||
@@ -77,8 +130,8 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
// 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(attackRotation);
|
||||
var targetOffset = new WVec(i*so.Y, 0, 0).Rotate(attackRotation);
|
||||
var spawnOffset = new WVec(i * so.Y, -Math.Abs(i) * so.X, 0).Rotate(attackRotation);
|
||||
var targetOffset = new WVec(i * so.Y, 0, 0).Rotate(attackRotation);
|
||||
|
||||
var a = w.CreateActor(info.UnitType, new TypeDictionary
|
||||
{
|
||||
@@ -87,13 +140,15 @@ namespace OpenRA.Mods.RA
|
||||
new FacingInit(attackFacing),
|
||||
});
|
||||
|
||||
a.Trait<AttackBomber>().SetTarget(target + targetOffset);
|
||||
|
||||
if (flare != null)
|
||||
a.QueueActivity(new CallFunc(() => flare.Destroy()));
|
||||
var attack = a.Trait<AttackBomber>();
|
||||
attack.SetTarget(target + targetOffset);
|
||||
attack.OnEnteredAttackRange += onEnterRange;
|
||||
attack.OnExitedAttackRange += onExitRange;
|
||||
attack.OnRemovedFromWorld += onExitRange;
|
||||
|
||||
a.QueueActivity(new Fly(a, Target.FromPos(finishEdge + spawnOffset)));
|
||||
a.QueueActivity(new RemoveSelf());
|
||||
aircraftInRange.Add(a, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user