From baf58f53b38567fe43f51ffd87b568a34edc568c Mon Sep 17 00:00:00 2001 From: reaperrr Date: Wed, 22 Apr 2020 00:24:04 +0200 Subject: [PATCH] Adapt SpreadDamageWH to ImpactOrientation The ImpactOrientation needs to be computed from point of impact to target if the target wasn't hit directly. Also adapted warhead code to use WarheadArgs consistently, as well as pass HitShape instead of just HitShapeInfo (both needed for future and/or downstream features). --- OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs b/OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs index 41552e4ba5..29ef61f008 100644 --- a/OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/SpreadDamageWarhead.cs @@ -87,9 +87,21 @@ namespace OpenRA.Mods.Common.Warheads continue; var localModifiers = args.DamageModifiers.Append(GetDamageFalloff(falloffDistance)); + var impactOrientation = args.ImpactOrientation; + + // If a warhead lands outside the victim's HitShape, we need to calculate the vertical and horizontal impact angles + // from impact position, rather than last projectile facing/angle. + if (falloffDistance > 0) + { + var towardsTargetYaw = (victim.CenterPosition - args.ImpactPosition).Yaw; + var impactAngle = Util.GetVerticalAngle(args.ImpactPosition, victim.CenterPosition); + impactOrientation = new WRot(WAngle.Zero, impactAngle, towardsTargetYaw); + } + var updatedWarheadArgs = new WarheadArgs(args) { DamageModifiers = localModifiers.ToArray(), + ImpactOrientation = impactOrientation, }; InflictDamage(victim, firedBy, closestActiveShape.First, updatedWarheadArgs);