Add missile jamming to MRJ
This commit is contained in:
@@ -41,8 +41,9 @@ namespace OpenRA.Mods.RA.Effects
|
||||
public readonly Color ContrailColor = Color.White;
|
||||
public readonly bool ContrailUsePlayerColor = false;
|
||||
public readonly int ContrailDelay = 1;
|
||||
public readonly bool Jammable = true;
|
||||
|
||||
public IEffect Create(ProjectileArgs args) { return new Missile( this, args ); }
|
||||
public IEffect Create(ProjectileArgs args) { return new Missile(this, args); }
|
||||
}
|
||||
|
||||
class Missile : IEffect
|
||||
@@ -90,27 +91,44 @@ namespace OpenRA.Mods.RA.Effects
|
||||
const int MissileCloseEnough = 7;
|
||||
int ticksToNextSmoke;
|
||||
|
||||
public void Tick( World world )
|
||||
public void Tick(World world)
|
||||
{
|
||||
t += 40;
|
||||
|
||||
// In pixels
|
||||
var dist = Args.target.CenterLocation + offset - PxPosition;
|
||||
|
||||
var targetAltitude = 0;
|
||||
var targetAltitude = 0;
|
||||
if (Args.target.IsValid && Args.target.IsActor && Args.target.Actor.HasTrait<IMove>())
|
||||
targetAltitude = Args.target.Actor.Trait<IMove>().Altitude;
|
||||
targetAltitude = Args.target.Actor.Trait<IMove>().Altitude;
|
||||
|
||||
Altitude += Math.Sign(targetAltitude - Altitude);
|
||||
var jammed = Info.Jammable && world.ActorsWithTrait<JamsMissiles>().Any(tp =>
|
||||
(tp.Actor.CenterLocation - PxPosition).ToCVec().Length <= tp.Trait.Range
|
||||
|
||||
if (Args.target.IsValid)
|
||||
&& (tp.Actor.Owner.Stances[Args.firedBy.Owner] != Stance.Ally
|
||||
|| (tp.Actor.Owner.Stances[Args.firedBy.Owner] == Stance.Ally && tp.Trait.AlliedMissiles))
|
||||
|
||||
&& world.SharedRandom.Next(100 / tp.Trait.Chance) == 0);
|
||||
|
||||
if (!jammed)
|
||||
{
|
||||
Altitude += Math.Sign(targetAltitude - Altitude);
|
||||
if (Args.target.IsValid)
|
||||
Facing = Traits.Util.TickFacing(Facing,
|
||||
Traits.Util.GetFacing(dist, Facing),
|
||||
Info.ROT);
|
||||
}
|
||||
else
|
||||
{
|
||||
Altitude += world.SharedRandom.Next(-1, 2);
|
||||
Facing = Traits.Util.TickFacing(Facing,
|
||||
Traits.Util.GetFacing(dist, Facing),
|
||||
Facing + world.SharedRandom.Next(-20, 21),
|
||||
Info.ROT);
|
||||
}
|
||||
|
||||
anim.Tick();
|
||||
|
||||
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough && Args.target.IsValid )
|
||||
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough && Args.target.IsValid)
|
||||
Explode(world);
|
||||
|
||||
// TODO: Replace this with a lookup table
|
||||
|
||||
Reference in New Issue
Block a user