From 6c6da12dd667a88181e5ecc2b834a1bee114188c Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sat, 31 Jul 2010 23:01:56 +1200 Subject: [PATCH] fix local offset -> screen space transform to work as advertised --- OpenRA.Mods.RA/AttackBase.cs | 10 +++------- OpenRA.Mods.RA/Combat.cs | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.RA/AttackBase.cs b/OpenRA.Mods.RA/AttackBase.cs index 7412385ebe..8965f819fe 100644 --- a/OpenRA.Mods.RA/AttackBase.cs +++ b/OpenRA.Mods.RA/AttackBase.cs @@ -195,12 +195,6 @@ namespace OpenRA.Mods.RA if (!w.IsValidAgainst(target)) return false; var barrel = w.Barrels[w.Burst % w.Barrels.Length]; - - var fireOffset = new[] { - w.Turret.UnitSpacePosition.X + barrel.Position.X, - w.Turret.UnitSpacePosition.Y + barrel.Position.Y, - w.Turret.ScreenSpacePosition.X, - w.Turret.ScreenSpacePosition.Y }; // todo: retardage. var destUnit = target.IsActor ? target.Actor.traits.GetOrDefault() : null; @@ -211,7 +205,9 @@ namespace OpenRA.Mods.RA firedBy = self, target = this.target, - src = self.CenterLocation.ToInt2() + Combat.GetTurretPosition(self, unit, new Turret(fireOffset)).ToInt2(), + src = (self.CenterLocation + + Combat.GetTurretPosition(self, unit, w.Turret) + + Combat.GetBarrelPosition(self, unit, w.Turret, barrel)).ToInt2(), srcAltitude = unit != null ? unit.Altitude : 0, dest = target.CenterLocation.ToInt2(), destAltitude = destUnit != null ? destUnit.Altitude : 0, diff --git a/OpenRA.Mods.RA/Combat.cs b/OpenRA.Mods.RA/Combat.cs index f2096a2b07..8ea3ffb06a 100755 --- a/OpenRA.Mods.RA/Combat.cs +++ b/OpenRA.Mods.RA/Combat.cs @@ -199,8 +199,22 @@ namespace OpenRA.Mods.RA var bodyFacing = unit.Facing; var quantizedFacing = Util.QuantizeFacing(bodyFacing, numDirs) * (256 / numDirs); - return (Util.RotateVectorByFacing(turret.UnitSpacePosition, quantizedFacing, .7f) + GetRecoil(self, turret.Recoil)) + return (Util.RotateVectorByFacing(turret.UnitSpacePosition, quantizedFacing, .7f) + + GetRecoil(self, turret.Recoil)) + turret.ScreenSpacePosition; } + + // gets the screen-space position of a barrel. + public static float2 GetBarrelPosition(Actor self, Unit unit, Turret turret, Barrel barrel) + { + var turreted = self.traits.GetOrDefault(); + + if (turreted == null && unit == null) + return float2.Zero; + + var turretFacing = turreted != null ? turreted.turretFacing : unit.Facing; + + return Util.RotateVectorByFacing(barrel.Position, turretFacing, .7f); + } } }