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.
This commit is contained in:
@@ -32,18 +32,21 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
readonly Animation clock;
|
readonly Animation clock;
|
||||||
readonly int duration;
|
readonly int duration;
|
||||||
|
|
||||||
|
int delay;
|
||||||
int arrowHeight = MaxArrowHeight;
|
int arrowHeight = MaxArrowHeight;
|
||||||
int arrowSpeed = 50;
|
int arrowSpeed = 50;
|
||||||
int tick;
|
int tick;
|
||||||
|
|
||||||
// Player-placed beacons are removed after a delay
|
// Player-placed beacons are removed after a delay
|
||||||
public Beacon(Player owner, WPos position, int duration, string beaconPalette, bool isPlayerPalette, string beaconCollection, string arrowSprite, string circleSprite)
|
public Beacon(Player owner, WPos position, int duration, string beaconPalette, bool isPlayerPalette,
|
||||||
|
string beaconCollection, string arrowSprite, string circleSprite, int delay = 0)
|
||||||
{
|
{
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.beaconPalette = beaconPalette;
|
this.beaconPalette = beaconPalette;
|
||||||
this.isPlayerPalette = isPlayerPalette;
|
this.isPlayerPalette = isPlayerPalette;
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
|
this.delay = delay;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(arrowSprite))
|
if (!string.IsNullOrEmpty(arrowSprite))
|
||||||
{
|
{
|
||||||
@@ -58,10 +61,10 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Support power beacons are expected to clean themselves up
|
// By default, support power beacons are expected to clean themselves up
|
||||||
public Beacon(Player owner, WPos position, bool isPlayerPalette, string palette, string posterCollection, string posterType, string posterPalette,
|
public Beacon(Player owner, WPos position, bool isPlayerPalette, string palette, string posterCollection, string posterType, string posterPalette,
|
||||||
string arrowSequence, string circleSequence, string clockSequence, Func<float> clockFraction)
|
string arrowSequence, string circleSequence, string clockSequence, Func<float> clockFraction, int delay = 0, int duration = -1)
|
||||||
: this(owner, position, -1, palette, isPlayerPalette, posterCollection, arrowSequence, circleSequence)
|
: this(owner, position, duration, palette, isPlayerPalette, posterCollection, arrowSequence, circleSequence, delay)
|
||||||
{
|
{
|
||||||
this.posterPalette = posterPalette;
|
this.posterPalette = posterPalette;
|
||||||
|
|
||||||
@@ -80,6 +83,9 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
|
|
||||||
void IEffect.Tick(World world)
|
void IEffect.Tick(World world)
|
||||||
{
|
{
|
||||||
|
if (delay-- > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
arrowHeight += arrowSpeed;
|
arrowHeight += arrowSpeed;
|
||||||
var clamped = arrowHeight.Clamp(0, MaxArrowHeight);
|
var clamped = arrowHeight.Clamp(0, MaxArrowHeight);
|
||||||
if (arrowHeight != clamped)
|
if (arrowHeight != clamped)
|
||||||
@@ -105,6 +111,9 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
|
|
||||||
IEnumerable<IRenderable> IEffectAboveShroud.RenderAboveShroud(WorldRenderer r)
|
IEnumerable<IRenderable> IEffectAboveShroud.RenderAboveShroud(WorldRenderer r)
|
||||||
{
|
{
|
||||||
|
if (delay > 0)
|
||||||
|
yield break;
|
||||||
|
|
||||||
if (!owner.IsAlliedWith(owner.World.RenderPlayer))
|
if (!owner.IsAlliedWith(owner.World.RenderPlayer))
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
Info.ArrowSequence,
|
Info.ArrowSequence,
|
||||||
Info.CircleSequence,
|
Info.CircleSequence,
|
||||||
Info.ClockSequence,
|
Info.ClockSequence,
|
||||||
() => 1 - ((distanceTestActor.CenterPosition - target).HorizontalLength - info.BeaconDistanceOffset.Length) * 1f / distance);
|
() => 1 - ((distanceTestActor.CenterPosition - target).HorizontalLength - info.BeaconDistanceOffset.Length) * 1f / distance);
|
||||||
|
|
||||||
w.Add(beacon);
|
w.Add(beacon);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,15 +27,17 @@ namespace OpenRA.Mods.TS.Effects
|
|||||||
readonly Animation beacon;
|
readonly Animation beacon;
|
||||||
readonly int duration;
|
readonly int duration;
|
||||||
|
|
||||||
|
int delay;
|
||||||
int tick;
|
int tick;
|
||||||
|
|
||||||
public AnimatedBeacon(Player owner, WPos position, int duration, string beaconPalette, bool isPlayerPalette, string beaconImage, string beaconSequence)
|
public AnimatedBeacon(Player owner, WPos position, int duration, string beaconPalette, bool isPlayerPalette, string beaconImage, string beaconSequence, int delay = 0)
|
||||||
{
|
{
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.beaconPalette = beaconPalette;
|
this.beaconPalette = beaconPalette;
|
||||||
this.isPlayerPalette = isPlayerPalette;
|
this.isPlayerPalette = isPlayerPalette;
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
|
this.delay = delay;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(beaconSequence))
|
if (!string.IsNullOrEmpty(beaconSequence))
|
||||||
{
|
{
|
||||||
@@ -49,6 +51,9 @@ namespace OpenRA.Mods.TS.Effects
|
|||||||
|
|
||||||
void IEffect.Tick(World world)
|
void IEffect.Tick(World world)
|
||||||
{
|
{
|
||||||
|
if (delay-- > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (beacon != null)
|
if (beacon != null)
|
||||||
beacon.Tick();
|
beacon.Tick();
|
||||||
|
|
||||||
@@ -60,6 +65,9 @@ namespace OpenRA.Mods.TS.Effects
|
|||||||
|
|
||||||
IEnumerable<IRenderable> IEffectAboveShroud.RenderAboveShroud(WorldRenderer r)
|
IEnumerable<IRenderable> IEffectAboveShroud.RenderAboveShroud(WorldRenderer r)
|
||||||
{
|
{
|
||||||
|
if (delay > 0)
|
||||||
|
return SpriteRenderable.None;
|
||||||
|
|
||||||
if (beacon == null)
|
if (beacon == null)
|
||||||
return SpriteRenderable.None;
|
return SpriteRenderable.None;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user