Make nuke flight time independent from map size.
This commit is contained in:
@@ -18,18 +18,33 @@ namespace OpenRA.Mods.RA.Effects
|
||||
{
|
||||
public class NukeLaunch : IEffect
|
||||
{
|
||||
readonly Player firedBy;
|
||||
Animation anim;
|
||||
WPos pos;
|
||||
CPos targetLocation;
|
||||
bool goingUp = true;
|
||||
string weapon;
|
||||
readonly Actor firedBy;
|
||||
readonly Animation anim;
|
||||
readonly string weapon;
|
||||
|
||||
public NukeLaunch(Player firedBy, Actor silo, string weapon, WPos launchPos, CPos targetLocation)
|
||||
readonly WPos ascendSource;
|
||||
readonly WPos ascendTarget;
|
||||
readonly WPos descendSource;
|
||||
readonly WPos descendTarget;
|
||||
readonly int delay;
|
||||
readonly int turn;
|
||||
|
||||
WPos pos;
|
||||
int ticks;
|
||||
|
||||
public NukeLaunch(Actor firedBy, string weapon, WPos launchPos, WPos targetPos, WRange velocity, int delay, bool skipAscent)
|
||||
{
|
||||
this.firedBy = firedBy;
|
||||
this.targetLocation = targetLocation;
|
||||
this.weapon = weapon;
|
||||
this.delay = delay;
|
||||
this.turn = delay / 2;
|
||||
|
||||
var offset = new WVec(WRange.Zero, WRange.Zero, velocity * turn);
|
||||
ascendSource = launchPos;
|
||||
ascendTarget = launchPos + offset;
|
||||
descendSource = targetPos + offset;
|
||||
descendTarget = targetPos;
|
||||
|
||||
anim = new Animation(weapon);
|
||||
anim.PlayRepeating("up");
|
||||
|
||||
@@ -37,40 +52,34 @@ namespace OpenRA.Mods.RA.Effects
|
||||
var weaponRules = Rules.Weapons[weapon.ToLowerInvariant()];
|
||||
if (weaponRules.Report != null && weaponRules.Report.Any())
|
||||
Sound.Play(weaponRules.Report.Random(firedBy.World.SharedRandom), pos);
|
||||
if (silo == null)
|
||||
StartDescent(firedBy.World);
|
||||
|
||||
if (skipAscent)
|
||||
ticks = turn;
|
||||
}
|
||||
|
||||
void StartDescent(World world)
|
||||
{
|
||||
pos = targetLocation.CenterPosition + new WVec(0, 0, 1024*firedBy.World.Map.Bounds.Height);
|
||||
anim.PlayRepeating("down");
|
||||
goingUp = false;
|
||||
}
|
||||
|
||||
public void Tick(World world)
|
||||
{
|
||||
anim.Tick();
|
||||
|
||||
var delta = new WVec(0,0,427);
|
||||
if (goingUp)
|
||||
{
|
||||
pos += delta;
|
||||
if (pos.Z >= world.Map.Bounds.Height*1024)
|
||||
StartDescent(world);
|
||||
}
|
||||
if (ticks == turn)
|
||||
anim.PlayRepeating("down");
|
||||
|
||||
if (ticks <= turn)
|
||||
pos = WPos.LerpQuadratic(ascendSource, ascendTarget, WAngle.Zero, ticks, turn);
|
||||
else
|
||||
{
|
||||
pos -= delta;
|
||||
if (pos.Z <= 0)
|
||||
Explode(world);
|
||||
}
|
||||
pos = WPos.LerpQuadratic(descendSource, descendTarget, WAngle.Zero, ticks - turn, delay - turn);
|
||||
|
||||
if (ticks == delay)
|
||||
Explode(world);
|
||||
|
||||
ticks++;
|
||||
}
|
||||
|
||||
void Explode(World world)
|
||||
{
|
||||
world.AddFrameEndTask(w => w.Remove(this));
|
||||
Combat.DoExplosion(firedBy.PlayerActor, weapon, pos);
|
||||
Combat.DoExplosion(firedBy, weapon, pos);
|
||||
world.WorldActor.Trait<ScreenShaker>().AddEffect(20, pos, 5);
|
||||
|
||||
foreach (var a in world.ActorsWithTrait<NukePaletteEffect>())
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 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,
|
||||
@@ -8,7 +8,11 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Effects;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
@@ -19,6 +23,15 @@ namespace OpenRA.Mods.RA
|
||||
public readonly string MissileWeapon = "";
|
||||
public readonly WVec SpawnOffset = WVec.Zero;
|
||||
|
||||
[Desc("Travel time - split equally between ascent and descent")]
|
||||
public readonly int FlightDelay = 400;
|
||||
|
||||
[Desc("Visual ascent velocity in WRange / tick")]
|
||||
public readonly WRange FlightVelocity = new WRange(512);
|
||||
|
||||
[Desc("Descend immediately on the target, with half the FlightDelay")]
|
||||
public readonly bool SkipAscent = false;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new NukePower(init.self, this); }
|
||||
}
|
||||
|
||||
@@ -50,8 +63,11 @@ namespace OpenRA.Mods.RA
|
||||
var npi = Info as NukePowerInfo;
|
||||
var rb = self.Trait<RenderSimple>();
|
||||
rb.PlayCustomAnim(self, "active");
|
||||
self.World.AddFrameEndTask(w => w.Add(
|
||||
new NukeLaunch(self.Owner, self, npi.MissileWeapon, self.CenterPosition + body.LocalToWorld(npi.SpawnOffset), order.TargetLocation)));
|
||||
|
||||
self.World.AddFrameEndTask(w => w.Add(new NukeLaunch(self, npi.MissileWeapon,
|
||||
self.CenterPosition + body.LocalToWorld(npi.SpawnOffset),
|
||||
order.TargetLocation.CenterPosition,
|
||||
npi.FlightVelocity, npi.FlightDelay, npi.SkipAscent)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user