diff --git a/OpenRA.Game/GameRules/WeaponInfo.cs b/OpenRA.Game/GameRules/WeaponInfo.cs index 247a770fb3..92ae3fdd07 100644 --- a/OpenRA.Game/GameRules/WeaponInfo.cs +++ b/OpenRA.Game/GameRules/WeaponInfo.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using OpenRA.Effects; using OpenRA.FileFormats; +using OpenRA.Traits; namespace OpenRA.GameRules { @@ -55,7 +56,7 @@ namespace OpenRA.GameRules public int2 src; public int srcAltitude; public int facing; - public Actor target; + public Target target; public int2 dest; public int destAltitude; } diff --git a/OpenRA.Mods.Aftermath/DemoTruck.cs b/OpenRA.Mods.Aftermath/DemoTruck.cs index 4ed88f28a8..8aac0de1a1 100644 --- a/OpenRA.Mods.Aftermath/DemoTruck.cs +++ b/OpenRA.Mods.Aftermath/DemoTruck.cs @@ -36,11 +36,10 @@ namespace OpenRA.Mods.Aftermath var unit = self.traits.GetOrDefault(); var info = self.Info.Traits.Get(); var altitude = unit != null ? unit.Altitude : 0; - int2 detonateLocation = self.CenterLocation.ToInt2(); self.World.AddFrameEndTask( w => { - Combat.DoExplosion(self, info.PrimaryWeapon, detonateLocation, altitude); + Combat.DoExplosion(self, info.PrimaryWeapon, Target.FromActor(self), altitude); var report = self.GetPrimaryWeapon().Report; if (report != null) Sound.Play(report + ".aud", self.CenterLocation); diff --git a/OpenRA.Mods.Cnc/Effects/IonCannon.cs b/OpenRA.Mods.Cnc/Effects/IonCannon.cs index cee0248242..703aae6572 100644 --- a/OpenRA.Mods.Cnc/Effects/IonCannon.cs +++ b/OpenRA.Mods.Cnc/Effects/IonCannon.cs @@ -18,14 +18,14 @@ namespace OpenRA.Mods.Cnc.Effects { class IonCannon : IEffect { - int2 Target; + Target target; Animation anim; Actor firedBy; public IonCannon(Actor firedBy, World world, int2 location) { this.firedBy = firedBy; - Target = location; + target = Target.FromPos(OpenRA.Traits.Util.CenterOfCell(location)); anim = new Animation("ionsfx"); anim.PlayThen("idle", () => Finish(world)); } @@ -35,14 +35,14 @@ namespace OpenRA.Mods.Cnc.Effects public IEnumerable Render() { yield return new Renderable(anim.Image, - Traits.Util.CenterOfCell(Target) - new float2(.5f * anim.Image.size.X, anim.Image.size.Y - Game.CellSize), + target.CenterLocation - new float2(.5f * anim.Image.size.X, anim.Image.size.Y - Game.CellSize), "effect"); } void Finish( World world ) { world.AddFrameEndTask(w => w.Remove(this)); - Combat.DoExplosion(firedBy, "IonCannon", Target, 0); + Combat.DoExplosion(firedBy, "IonCannon", target, 0); } } } diff --git a/OpenRA.Mods.Cnc/PoisonedByTiberium.cs b/OpenRA.Mods.Cnc/PoisonedByTiberium.cs index fc3a708cf6..690b88a788 100644 --- a/OpenRA.Mods.Cnc/PoisonedByTiberium.cs +++ b/OpenRA.Mods.Cnc/PoisonedByTiberium.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.Cnc destAltitude = 0, facing = 0, firedBy = self, - target = self, + target = Target.FromActor(self), weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()] }); diff --git a/OpenRA.Mods.RA/AttackLeap.cs b/OpenRA.Mods.RA/AttackLeap.cs index d16cabcd9a..53c62339d6 100644 --- a/OpenRA.Mods.RA/AttackLeap.cs +++ b/OpenRA.Mods.RA/AttackLeap.cs @@ -30,7 +30,8 @@ namespace OpenRA.Mods.RA if (self.GetCurrentActivity() is Leap) return; var weapon = self.GetPrimaryWeapon(); - if (weapon.Range * weapon.Range < (target.CenterLocation - self.Location).LengthSquared) return; + if (weapon.Range * Game.CellSize * weapon.Range * Game.CellSize + < (target.CenterLocation - self.CenterLocation).LengthSquared) return; self.CancelActivity(); self.QueueActivity(new Leap(self, target)); diff --git a/OpenRA.Mods.RA/Combat.cs b/OpenRA.Mods.RA/Combat.cs index 3833f5edcd..18ecd0c68c 100755 --- a/OpenRA.Mods.RA/Combat.cs +++ b/OpenRA.Mods.RA/Combat.cs @@ -113,16 +113,16 @@ namespace OpenRA.Mods.RA } } - public static void DoExplosion(Actor attacker, string weapontype, int2 location, int altitude) + public static void DoExplosion(Actor attacker, string weapontype, Target _target, int altitude) { var args = new ProjectileArgs { - src = location, - dest = location, + src = Util.CellContaining(_target.CenterLocation), + dest = Util.CellContaining(_target.CenterLocation), srcAltitude = altitude, destAltitude = altitude, firedBy = attacker, - target = null, + target = _target, weapon = Rules.Weapons[ weapontype.ToLowerInvariant() ], facing = 0 }; diff --git a/OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs b/OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs index 2c5731fb89..9401f9b244 100644 --- a/OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/ExplodeCrateAction.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA public override void Activate(Actor collector) { - Combat.DoExplosion(self, (info as ExplodeCrateActionInfo).Weapon, collector.CenterLocation.ToInt2(), 0); + Combat.DoExplosion(self, (info as ExplodeCrateActionInfo).Weapon, Target.FromActor(collector), 0); base.Activate(collector); } } diff --git a/OpenRA.Mods.RA/Effects/Missile.cs b/OpenRA.Mods.RA/Effects/Missile.cs index 34cfc85270..c6aec1871c 100755 --- a/OpenRA.Mods.RA/Effects/Missile.cs +++ b/OpenRA.Mods.RA/Effects/Missile.cs @@ -75,8 +75,9 @@ namespace OpenRA.Mods.RA.Effects var targetPosition = Args.target.CenterLocation + offset; - var targetUnit = Args.target.traits.GetOrDefault(); - var targetAltitude = targetUnit != null ? targetUnit.Altitude : 0; + var targetAltitude = 0; + if (Args.target.IsActor && Args.target.Actor.traits.GetOrDefault() != null) + targetAltitude = Args.target.Actor.traits.GetOrDefault().Altitude; Altitude += Math.Sign(targetAltitude - Altitude); Traits.Util.TickFacing(ref Facing, @@ -86,7 +87,7 @@ namespace OpenRA.Mods.RA.Effects anim.Tick(); var dist = targetPosition - Pos; - if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || Args.target.IsDead) + if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || !Args.target.IsValid ) Explode(world); var speed = Scale * Info.Speed * ((targetAltitude > 0 && Info.TurboBoost) ? 1.5f : 1f); diff --git a/OpenRA.Mods.RA/Effects/NukeLaunch.cs b/OpenRA.Mods.RA/Effects/NukeLaunch.cs index 29a7acfb2a..6a2a771e02 100755 --- a/OpenRA.Mods.RA/Effects/NukeLaunch.cs +++ b/OpenRA.Mods.RA/Effects/NukeLaunch.cs @@ -76,7 +76,7 @@ namespace OpenRA.Mods.RA.Effects void Explode(World world) { world.AddFrameEndTask(w => w.Remove(this)); - Combat.DoExplosion(silo.Owner.PlayerActor, weapon, pos.ToInt2(), 0); + Combat.DoExplosion(silo.Owner.PlayerActor, weapon, Target.FromPos(pos), 0); world.WorldActor.traits.Get().AddEffect(20, pos, 5); } diff --git a/OpenRA.Mods.RA/Explodes.cs b/OpenRA.Mods.RA/Explodes.cs index c75e2d5b25..3cb8183f34 100644 --- a/OpenRA.Mods.RA/Explodes.cs +++ b/OpenRA.Mods.RA/Explodes.cs @@ -32,8 +32,7 @@ namespace OpenRA.Mods.RA { var unit = self.traits.GetOrDefault(); var altitude = unit != null ? unit.Altitude : 0; - Combat.DoExplosion(e.Attacker, weapon, - self.CenterLocation.ToInt2(), altitude); + Combat.DoExplosion(e.Attacker, weapon, Target.FromActor(self), altitude); } } } diff --git a/OpenRA.Mods.RA/Mine.cs b/OpenRA.Mods.RA/Mine.cs index 91edd10116..02553bb1af 100644 --- a/OpenRA.Mods.RA/Mine.cs +++ b/OpenRA.Mods.RA/Mine.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA return; var info = self.Info.Traits.Get(); - Combat.DoExplosion(self, info.Weapon, crusher.CenterLocation.ToInt2(), 0); + Combat.DoExplosion(self, info.Weapon, Target.FromActor(crusher), 0); self.QueueActivity(new RemoveSelf()); }