Simplify FlashTarget.

Now defined in terms of a flash count, interval, and delay.
Broken FlashDuration parameter removed from Demolition.
This commit is contained in:
Paul Chote
2018-10-28 11:34:07 +00:00
committed by abcdefg30
parent 1b9f23eca0
commit 0901a7d9de
4 changed files with 16 additions and 18 deletions

View File

@@ -25,11 +25,10 @@ namespace OpenRA.Mods.Common.Activities
readonly int flashes;
readonly int flashesDelay;
readonly int flashInterval;
readonly int flashDuration;
readonly INotifyDemolition[] notifiers;
public Demolish(Actor self, Actor target, EnterBehaviour enterBehaviour, int delay,
int flashes, int flashesDelay, int flashInterval, int flashDuration)
int flashes, int flashesDelay, int flashInterval)
: base(self, target, enterBehaviour)
{
this.target = target;
@@ -39,7 +38,6 @@ namespace OpenRA.Mods.Common.Activities
this.flashes = flashes;
this.flashesDelay = flashesDelay;
this.flashInterval = flashInterval;
this.flashDuration = flashDuration;
}
protected override bool CanReserve(Actor self)
@@ -57,9 +55,7 @@ namespace OpenRA.Mods.Common.Activities
foreach (var ind in notifiers)
ind.Demolishing(self);
for (var f = 0; f < flashes; f++)
w.Add(new DelayedAction(flashesDelay + f * flashInterval, () =>
w.Add(new FlashTarget(target, ticks: flashDuration))));
w.Add(new FlashTarget(target, count: flashes, delay: flashesDelay, interval: flashInterval));
w.Add(new DelayedAction(delay, () =>
{

View File

@@ -18,15 +18,20 @@ namespace OpenRA.Mods.Common.Effects
{
public class FlashTarget : IEffect
{
Actor target;
Player player;
int remainingTicks;
readonly Actor target;
readonly Player player;
readonly int count;
readonly int interval;
int tick;
public FlashTarget(Actor target, Player asPlayer = null, int ticks = 4)
public FlashTarget(Actor target, Player asPlayer = null, int count = 2, int interval = 2, int delay = 0)
{
this.target = target;
player = asPlayer;
remainingTicks = ticks;
this.count = count;
this.interval = interval;
tick = -delay;
target.World.RemoveAll(effect =>
{
var flashTarget = effect as FlashTarget;
@@ -36,13 +41,13 @@ namespace OpenRA.Mods.Common.Effects
public void Tick(World world)
{
if (--remainingTicks == 0 || !target.IsInWorld)
if (++tick >= count * interval || !target.IsInWorld)
world.AddFrameEndTask(w => w.Remove(this));
}
public IEnumerable<IRenderable> Render(WorldRenderer wr)
{
if (target.IsInWorld && remainingTicks % 2 == 0)
if (target.IsInWorld && tick >= 0 && tick % interval == 0)
{
var palette = wr.Palette(player == null ? "highlight" : "highlight" + player.InternalName);
return target.Render(wr)

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Scripting
public void Demolish(Actor target)
{
Self.QueueActivity(new Demolish(Self, target, info.EnterBehaviour, info.DetonationDelay,
info.Flashes, info.FlashesDelay, info.FlashInterval, info.FlashDuration));
info.Flashes, info.FlashesDelay, info.FlashInterval));
}
}
}

View File

@@ -33,9 +33,6 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Interval between each flash.")]
public readonly int FlashInterval = 4;
[Desc("Duration of each flash.")]
public readonly int FlashDuration = 3;
[Desc("Behaviour when entering the structure.",
"Possible values are Exit, Suicide, Dispose.")]
public readonly EnterBehaviour EnterBehaviour = EnterBehaviour.Exit;
@@ -88,7 +85,7 @@ namespace OpenRA.Mods.Common.Traits
self.SetTargetLine(target, Color.Red);
self.QueueActivity(new Demolish(self, target.Actor, info.EnterBehaviour, info.DetonationDelay,
info.Flashes, info.FlashesDelay, info.FlashInterval, info.FlashDuration));
info.Flashes, info.FlashesDelay, info.FlashInterval));
}
public string VoicePhraseForOrder(Actor self, Order order)