Files
OpenRA/OpenRA.Mods.TS/Effects/AnimatedBeacon.cs
reaperrr 871576b300 Add delay and full duration support to beacons
Previously, support power beacons were hardcoded to unlimited duration and
then cleaned up directly by the support power. This is problematic if we
want the beacon to remove itself after a certain delay, though.
2016-12-27 17:13:53 +01:00

82 lines
2.2 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2016 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Effects;
using OpenRA.Graphics;
using OpenRA.Scripting;
namespace OpenRA.Mods.TS.Effects
{
public class AnimatedBeacon : IEffect, IEffectAboveShroud
{
readonly Player owner;
readonly WPos position;
readonly string beaconPalette;
readonly bool isPlayerPalette;
readonly Animation beacon;
readonly int duration;
int delay;
int tick;
public AnimatedBeacon(Player owner, WPos position, int duration, string beaconPalette, bool isPlayerPalette, string beaconImage, string beaconSequence, int delay = 0)
{
this.owner = owner;
this.position = position;
this.beaconPalette = beaconPalette;
this.isPlayerPalette = isPlayerPalette;
this.duration = duration;
this.delay = delay;
if (!string.IsNullOrEmpty(beaconSequence))
{
beacon = new Animation(owner.World, beaconImage);
beacon.PlayRepeating(beaconSequence);
}
if (duration > 0)
owner.World.Add(new DelayedAction(duration, () => owner.World.Remove(this)));
}
void IEffect.Tick(World world)
{
if (delay-- > 0)
return;
if (beacon != null)
beacon.Tick();
if (duration > 0 && duration <= tick++)
owner.World.AddFrameEndTask(w => w.Remove(this));
}
IEnumerable<IRenderable> IEffect.Render(WorldRenderer r) { return SpriteRenderable.None; }
IEnumerable<IRenderable> IEffectAboveShroud.RenderAboveShroud(WorldRenderer r)
{
if (delay > 0)
return SpriteRenderable.None;
if (beacon == null)
return SpriteRenderable.None;
if (!owner.IsAlliedWith(owner.World.RenderPlayer))
return SpriteRenderable.None;
var palette = r.Palette(isPlayerPalette ? beaconPalette + owner.InternalName : beaconPalette);
return beacon.Render(position, palette);
}
}
}