Refactor handling of hit radii in projectiles.

penev discovered that the RulesetLoaded functions of projectiles were
never being called, meaning that their blocking calculations were not
properly accounting for actors with large hitboxes.

The best fix for this is to change FindActorsOnLine to always account
for the largest actor's hit radius, rather than forcing callers to pass
the largest radius. Per the comment in Util.cs, as a result, move this
computation to ActorMap. I decided to simplify by not making a separate
calculation for actors that block projectiles only; this may cause a
small performance degradation as the search space is a bit larger.

Similarly to this, I've removed the ability to specify a search radius
manually. Because this is only a search radius, setting a value smaller
than the largest eligible actor makes no sense; that would lead to
completely inconsistent blocking. Setting a larger value, on the other
hand, would make no difference.

CreateEffectWarhead was the only place in core code any of these search
radii were set, and that's because 0 was a mysterious magic value that
made the warhead incapable of hitting actors. I replaced it with a
boolean flag that more clearly indicates the actual behaviour.

Fixes #14151.
This commit is contained in:
Alexis Hunt
2018-01-17 20:50:26 -05:00
committed by reaperrr
parent c4b0ad45e3
commit 08ad7d7f4e
31 changed files with 106 additions and 180 deletions

View File

@@ -22,7 +22,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Projectiles
{
[Desc("Not a sprite, but an engine effect.")]
public class LaserZapInfo : IProjectileInfo, IRulesetLoaded<WeaponInfo>
public class LaserZapInfo : IProjectileInfo
{
[Desc("The width of the zap.")]
public readonly WDist Width = new WDist(86);
@@ -74,21 +74,11 @@ namespace OpenRA.Mods.Common.Projectiles
[PaletteReference] public readonly string HitAnimPalette = "effect";
[Desc("Scan radius for actors with projectile-blocking trait. If set to a negative value (default), it will automatically scale",
"to the blocker with the largest health shape. Only set custom values if you know what you're doing.")]
public WDist BlockerScanRadius = new WDist(-1);
public IProjectile Create(ProjectileArgs args)
{
var c = UsePlayerColor ? args.SourceActor.Owner.Color.RGB : Color;
return new LaserZap(this, args, c);
}
void IRulesetLoaded<WeaponInfo>.RulesetLoaded(Ruleset rules, WeaponInfo wi)
{
if (BlockerScanRadius < WDist.Zero)
BlockerScanRadius = Util.MinimumRequiredBlockerScanRadius(rules);
}
}
public class LaserZap : IProjectile, ISync
@@ -133,7 +123,7 @@ namespace OpenRA.Mods.Common.Projectiles
// Check for blocking actors
WPos blockedPos;
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, source, target,
info.Width, info.BlockerScanRadius, out blockedPos))
info.Width, out blockedPos))
{
target = blockedPos;
}