wire up missiles
This commit is contained in:
@@ -43,37 +43,32 @@ namespace OpenRA.Effects
|
|||||||
public readonly int RangeLimit = 0;
|
public readonly int RangeLimit = 0;
|
||||||
public readonly bool TurboBoost = false;
|
public readonly bool TurboBoost = false;
|
||||||
|
|
||||||
public IEffect Create(ProjectileArgs args) { return null; }
|
public IEffect Create(ProjectileArgs args) { return new Missile( this, args ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class Missile : IEffect
|
class Missile : IEffect
|
||||||
{
|
{
|
||||||
readonly Actor FiredBy;
|
readonly MissileInfo Info;
|
||||||
readonly WeaponInfo Weapon;
|
readonly ProjectileArgs Args;
|
||||||
readonly ProjectileInfo Projectile;
|
|
||||||
readonly WarheadInfo Warhead;
|
|
||||||
float2 Pos;
|
float2 Pos;
|
||||||
readonly Actor Target;
|
|
||||||
readonly Animation anim;
|
readonly Animation anim;
|
||||||
int Facing;
|
int Facing;
|
||||||
int t;
|
int t;
|
||||||
int Altitude;
|
int Altitude;
|
||||||
|
|
||||||
public Missile(WeaponInfo weapon, Player owner, Actor firedBy,
|
public Missile(MissileInfo info, ProjectileArgs args)
|
||||||
int2 src, Actor target, int altitude, int facing)
|
|
||||||
{
|
{
|
||||||
Weapon = weapon;
|
Info = info;
|
||||||
Projectile = Rules.ProjectileInfo[Weapon.Projectile];
|
Args = args;
|
||||||
Warhead = Rules.WarheadInfo[Weapon.Warhead];
|
|
||||||
FiredBy = firedBy;
|
|
||||||
Target = target;
|
|
||||||
Pos = src.ToFloat2();
|
|
||||||
Altitude = altitude;
|
|
||||||
Facing = facing;
|
|
||||||
|
|
||||||
if (Projectile.Image != null && Projectile.Image != "none")
|
Pos = Args.src;
|
||||||
|
Altitude = Args.srcAltitude;
|
||||||
|
Facing = Args.facing;
|
||||||
|
|
||||||
|
if (Info.Image != null)
|
||||||
{
|
{
|
||||||
anim = new Animation(Projectile.Image, () => Facing);
|
anim = new Animation(Info.Image, () => Facing);
|
||||||
anim.PlayRepeating("idle");
|
anim.PlayRepeating("idle");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,41 +80,40 @@ namespace OpenRA.Effects
|
|||||||
{
|
{
|
||||||
t += 40;
|
t += 40;
|
||||||
|
|
||||||
var targetUnit = Target.traits.GetOrDefault<Unit>();
|
var targetUnit = Args.target.traits.GetOrDefault<Unit>();
|
||||||
var targetAltitude = targetUnit != null ? targetUnit.Altitude : 0;
|
var targetAltitude = targetUnit != null ? targetUnit.Altitude : 0;
|
||||||
Altitude += Math.Sign(targetAltitude - Altitude);
|
Altitude += Math.Sign(targetAltitude - Altitude);
|
||||||
|
|
||||||
Traits.Util.TickFacing(ref Facing,
|
Traits.Util.TickFacing(ref Facing,
|
||||||
Traits.Util.GetFacing(Target.CenterLocation - Pos, Facing),
|
Traits.Util.GetFacing(Args.target.CenterLocation - Pos, Facing),
|
||||||
Projectile.ROT);
|
Info.ROT);
|
||||||
|
|
||||||
anim.Tick();
|
anim.Tick();
|
||||||
|
|
||||||
var dist = Target.CenterLocation - Pos;
|
var dist = Args.target.CenterLocation - Pos;
|
||||||
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || Target.IsDead)
|
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || Args.target.IsDead)
|
||||||
Explode(world);
|
Explode(world);
|
||||||
|
|
||||||
var speed = Scale * Weapon.Speed * ((targetAltitude > 0 && Weapon.TurboBoost) ? 1.5f : 1f);
|
var speed = Scale * Info.Speed * ((targetAltitude > 0 && Info.TurboBoost) ? 1.5f : 1f);
|
||||||
|
|
||||||
var angle = Facing / 128f * Math.PI;
|
var angle = Facing / 128f * Math.PI;
|
||||||
var move = speed * -float2.FromAngle((float)angle);
|
var move = speed * -float2.FromAngle((float)angle);
|
||||||
Pos += move;
|
Pos += move;
|
||||||
|
|
||||||
if (Projectile.Trail != null)
|
if (Info.Trail != null)
|
||||||
world.AddFrameEndTask(w => w.Add(
|
world.AddFrameEndTask(w => w.Add(
|
||||||
new Smoke(w, (Pos - 1.5f * move - new int2( 0, Altitude )).ToInt2(), Projectile.Trail)));
|
new Smoke(w, (Pos - 1.5f * move - new int2(0, Altitude)).ToInt2(), Info.Trail)));
|
||||||
|
|
||||||
if (Projectile.RangeLimit != 0 && t > Projectile.RangeLimit * 40)
|
if (Info.RangeLimit != 0 && t > Info.RangeLimit * 40)
|
||||||
Explode(world);
|
Explode(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Explode(World world)
|
void Explode(World world)
|
||||||
{
|
{
|
||||||
world.AddFrameEndTask(w => w.Remove(this));
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
|
Args.dest = Pos.ToInt2();
|
||||||
// if (t > Projectile.Arm * 40) /* don't blow up in our launcher's face! */
|
if (t > Info.Arm * 40) /* don't blow up in our launcher's face! */
|
||||||
// Combat.DoImpact(Pos.ToInt2(), Pos.ToInt2(), Weapon, Projectile, Warhead, FiredBy);
|
Combat.DoImpacts(Args, Pos.ToInt2());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Renderable> Render()
|
public IEnumerable<Renderable> Render()
|
||||||
|
|||||||
Reference in New Issue
Block a user