From 88b59d5033f69a386438b57ef9e31b57edf192c1 Mon Sep 17 00:00:00 2001 From: Scott_NZ Date: Sat, 20 Apr 2013 00:43:51 +1200 Subject: [PATCH] Add missile jamming to MRJ --- OpenRA.Mods.RA/Effects/Missile.cs | 34 +++++++++++++++++++++------- OpenRA.Mods.RA/JamsMissiles.cs | 32 ++++++++++++++++++++++++++ OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 3 ++- mods/ra/rules/vehicles.yaml | 12 ++++++---- 4 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 OpenRA.Mods.RA/JamsMissiles.cs diff --git a/OpenRA.Mods.RA/Effects/Missile.cs b/OpenRA.Mods.RA/Effects/Missile.cs index 88bedf524a..82af5b8151 100755 --- a/OpenRA.Mods.RA/Effects/Missile.cs +++ b/OpenRA.Mods.RA/Effects/Missile.cs @@ -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()) - targetAltitude = Args.target.Actor.Trait().Altitude; + targetAltitude = Args.target.Actor.Trait().Altitude; - Altitude += Math.Sign(targetAltitude - Altitude); + var jammed = Info.Jammable && world.ActorsWithTrait().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 diff --git a/OpenRA.Mods.RA/JamsMissiles.cs b/OpenRA.Mods.RA/JamsMissiles.cs new file mode 100644 index 0000000000..34c8f0be15 --- /dev/null +++ b/OpenRA.Mods.RA/JamsMissiles.cs @@ -0,0 +1,32 @@ +#region Copyright & License Information +/* + * Copyright 2007-2013 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, + * see COPYING. + */ +#endregion + +using OpenRA; +using OpenRA.Traits; + +class JamsMissilesInfo : ITraitInfo +{ + public readonly int Range = 0; + public readonly bool AlliedMissiles = true; + public readonly int Chance = 100; + + public object Create(ActorInitializer init) { return new JamsMissiles(this); } +} + +class JamsMissiles +{ + readonly JamsMissilesInfo info; + + public int Range { get { return info.Range; } } + public bool AlliedMissiles { get { return info.AlliedMissiles; } } + public int Chance { get { return info.Chance; } } + + public JamsMissiles(JamsMissilesInfo info) { this.info = info; } +} \ No newline at end of file diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 7f6c9ee5d3..737680152a 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -1,4 +1,4 @@ - + Debug @@ -233,6 +233,7 @@ + diff --git a/mods/ra/rules/vehicles.yaml b/mods/ra/rules/vehicles.yaml index d00df0b815..90bc492d64 100644 --- a/mods/ra/rules/vehicles.yaml +++ b/mods/ra/rules/vehicles.yaml @@ -490,7 +490,7 @@ MGG: Inherits: ^Vehicle Buildable: Queue: Vehicle - BuildPaletteOrder: 150 + BuildPaletteOrder: 160 Prerequisites: atek Owner: allies Hotkey: y @@ -537,11 +537,13 @@ MRJ: Cost: 1000 Tooltip: Name: Mobile Radar Jammer - Description: Jams nearby enemy radar domes. + Description: Jams enemy radar and deflects missiles.\n Unarmed Buildable: Queue: Vehicle - BuildPaletteOrder: 1000 - Owner: None + BuildPaletteOrder: 150 + Prerequisites: atek + Owner: allies + Hotkey: m Health: HP: 200 Armor: @@ -560,6 +562,8 @@ MRJ: EmptyWeapon: UnitExplodeSmall JamsRadar: Range: 15 + JamsMissiles: + Range: 3 1TNK.Husk: Inherits: ^Husk