Add delay support to NukeLaunch

And use that to remove the remaining DelayedAction from NukePower.
This commit is contained in:
reaperrr
2019-01-06 04:20:51 +01:00
committed by Paul Chote
parent d0c2dbcbb0
commit fa3bf5cefe
2 changed files with 27 additions and 16 deletions

View File

@@ -25,6 +25,7 @@ namespace OpenRA.Mods.Common.Effects
readonly Animation anim; readonly Animation anim;
readonly WeaponInfo weapon; readonly WeaponInfo weapon;
readonly string weaponPalette; readonly string weaponPalette;
readonly string upSequence;
readonly string downSequence; readonly string downSequence;
readonly string flashType; readonly string flashType;
@@ -32,44 +33,51 @@ namespace OpenRA.Mods.Common.Effects
readonly WPos ascendTarget; readonly WPos ascendTarget;
readonly WPos descendSource; readonly WPos descendSource;
readonly WPos descendTarget; readonly WPos descendTarget;
readonly int delay; readonly int impactDelay;
readonly int turn; readonly int turn;
WPos pos; WPos pos;
int ticks; int ticks;
bool isAddedToScreenMap; int launchDelay;
bool isLaunched;
public NukeLaunch(Player firedBy, string name, WeaponInfo weapon, string weaponPalette, string upSequence, string downSequence, public NukeLaunch(Player firedBy, string name, WeaponInfo weapon, string weaponPalette, string upSequence, string downSequence,
WPos launchPos, WPos targetPos, WDist velocity, int delay, bool skipAscent, string flashType) WPos launchPos, WPos targetPos, WDist velocity, int launchDelay, int impactDelay, bool skipAscent, string flashType)
{ {
this.firedBy = firedBy; this.firedBy = firedBy;
this.weapon = weapon; this.weapon = weapon;
this.weaponPalette = weaponPalette; this.weaponPalette = weaponPalette;
this.upSequence = upSequence;
this.downSequence = downSequence; this.downSequence = downSequence;
this.delay = delay; this.launchDelay = launchDelay;
turn = skipAscent ? 0 : delay / 2; this.impactDelay = impactDelay;
turn = skipAscent ? 0 : impactDelay / 2;
this.flashType = flashType; this.flashType = flashType;
var offset = new WVec(WDist.Zero, WDist.Zero, velocity * (delay - turn)); var offset = new WVec(WDist.Zero, WDist.Zero, velocity * (impactDelay - turn));
ascendSource = launchPos; ascendSource = launchPos;
ascendTarget = launchPos + offset; ascendTarget = launchPos + offset;
descendSource = targetPos + offset; descendSource = targetPos + offset;
descendTarget = targetPos; descendTarget = targetPos;
anim = new Animation(firedBy.World, name); anim = new Animation(firedBy.World, name);
anim.PlayRepeating(upSequence);
pos = skipAscent ? descendSource : ascendSource; pos = skipAscent ? descendSource : ascendSource;
if (weapon.Report != null && weapon.Report.Any())
Game.Sound.Play(SoundType.World, weapon.Report.Random(firedBy.World.SharedRandom), pos);
} }
public void Tick(World world) public void Tick(World world)
{ {
if (!isAddedToScreenMap) if (launchDelay-- > 0)
return;
if (!isLaunched)
{ {
anim.PlayRepeating(upSequence);
if (weapon.Report != null && weapon.Report.Any())
Game.Sound.Play(SoundType.World, weapon.Report.Random(firedBy.World.SharedRandom), pos);
world.ScreenMap.Add(this, pos, anim.Image); world.ScreenMap.Add(this, pos, anim.Image);
isAddedToScreenMap = true; isLaunched = true;
} }
anim.Tick(); anim.Tick();
@@ -80,9 +88,9 @@ namespace OpenRA.Mods.Common.Effects
if (ticks < turn) if (ticks < turn)
pos = WPos.LerpQuadratic(ascendSource, ascendTarget, WAngle.Zero, ticks, turn); pos = WPos.LerpQuadratic(ascendSource, ascendTarget, WAngle.Zero, ticks, turn);
else else
pos = WPos.LerpQuadratic(descendSource, descendTarget, WAngle.Zero, ticks - turn, delay - turn); pos = WPos.LerpQuadratic(descendSource, descendTarget, WAngle.Zero, ticks - turn, impactDelay - turn);
if (ticks == delay) if (ticks == impactDelay)
Explode(world); Explode(world);
world.ScreenMap.Update(this, pos, anim.Image); world.ScreenMap.Update(this, pos, anim.Image);
@@ -103,9 +111,12 @@ namespace OpenRA.Mods.Common.Effects
public IEnumerable<IRenderable> Render(WorldRenderer wr) public IEnumerable<IRenderable> Render(WorldRenderer wr)
{ {
if (!isLaunched)
return Enumerable.Empty<IRenderable>();
return anim.Render(pos, wr.Palette(weaponPalette)); return anim.Render(pos, wr.Palette(weaponPalette));
} }
public float FractionComplete { get { return ticks * 1f / delay; } } public float FractionComplete { get { return ticks * 1f / impactDelay; } }
} }
} }

View File

@@ -116,10 +116,10 @@ namespace OpenRA.Mods.Common.Traits
var missile = new NukeLaunch(self.Owner, info.MissileWeapon, info.WeaponInfo, palette, info.MissileUp, info.MissileDown, var missile = new NukeLaunch(self.Owner, info.MissileWeapon, info.WeaponInfo, palette, info.MissileUp, info.MissileDown,
self.CenterPosition + body.LocalToWorld(info.SpawnOffset), self.CenterPosition + body.LocalToWorld(info.SpawnOffset),
targetPosition, targetPosition,
info.FlightVelocity, info.FlightDelay, info.SkipAscent, info.FlightVelocity, info.MissileDelay, info.FlightDelay, info.SkipAscent,
info.FlashType); info.FlashType);
self.World.AddFrameEndTask(w => w.Add(new DelayedAction(info.MissileDelay, () => self.World.Add(missile)))); self.World.AddFrameEndTask(w => w.Add(missile));
if (info.CameraRange != WDist.Zero) if (info.CameraRange != WDist.Zero)
{ {