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:
@@ -22,7 +22,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Projectiles
|
||||
{
|
||||
public class AreaBeamInfo : IProjectileInfo, IRulesetLoaded<WeaponInfo>
|
||||
public class AreaBeamInfo : IProjectileInfo
|
||||
{
|
||||
[Desc("Projectile speed in WDist / tick, two values indicate a randomly picked velocity per beam.")]
|
||||
public readonly WDist[] Speed = { new WDist(128) };
|
||||
@@ -69,28 +69,11 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
[Desc("Beam color is the player's color.")]
|
||||
public readonly bool UsePlayerColor = false;
|
||||
|
||||
[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);
|
||||
|
||||
[Desc("Scan radius for actors damaged by beam. If set to a negative value (default), it will automatically scale to the largest health shape.",
|
||||
"Only set custom values if you know what you're doing.")]
|
||||
public WDist AreaVictimScanRadius = new WDist(-1);
|
||||
|
||||
public IProjectile Create(ProjectileArgs args)
|
||||
{
|
||||
var c = UsePlayerColor ? args.SourceActor.Owner.Color.RGB : Color;
|
||||
return new AreaBeam(this, args, c);
|
||||
}
|
||||
|
||||
void IRulesetLoaded<WeaponInfo>.RulesetLoaded(Ruleset rules, WeaponInfo wi)
|
||||
{
|
||||
if (BlockerScanRadius < WDist.Zero)
|
||||
BlockerScanRadius = Util.MinimumRequiredBlockerScanRadius(rules);
|
||||
|
||||
if (AreaVictimScanRadius < WDist.Zero)
|
||||
AreaVictimScanRadius = Util.MinimumRequiredVictimScanRadius(rules);
|
||||
}
|
||||
}
|
||||
|
||||
public class AreaBeam : IProjectile, ISync
|
||||
@@ -225,7 +208,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
// Check for blocking actors
|
||||
WPos blockedPos;
|
||||
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, tailPos, headPos,
|
||||
info.Width, info.BlockerScanRadius, out blockedPos))
|
||||
info.Width, out blockedPos))
|
||||
{
|
||||
headPos = blockedPos;
|
||||
target = headPos;
|
||||
@@ -235,7 +218,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
// Damage is applied to intersected actors every DamageInterval ticks
|
||||
if (headTicks % info.DamageInterval == 0)
|
||||
{
|
||||
var actors = world.FindActorsOnLine(tailPos, headPos, info.Width, info.AreaVictimScanRadius);
|
||||
var actors = world.FindActorsOnLine(tailPos, headPos, info.Width);
|
||||
foreach (var a in actors)
|
||||
{
|
||||
var adjustedModifiers = args.DamageModifiers.Append(GetFalloff((args.Source - a.CenterPosition).Length));
|
||||
|
||||
@@ -23,7 +23,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Projectiles
|
||||
{
|
||||
public class BulletInfo : IProjectileInfo, IRulesetLoaded<WeaponInfo>
|
||||
public class BulletInfo : IProjectileInfo
|
||||
{
|
||||
[Desc("Projectile speed in WDist / tick, two values indicate variable velocity.")]
|
||||
public readonly WDist[] Speed = { new WDist(17) };
|
||||
@@ -96,24 +96,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
public readonly int ContrailDelay = 1;
|
||||
public readonly WDist ContrailWidth = new WDist(64);
|
||||
|
||||
[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);
|
||||
|
||||
[Desc("Extra search radius beyond path for actors with ValidBounceBlockerStances. If set to a negative value (default), ",
|
||||
"it will automatically scale to the largest health shape. Only set custom values if you know what you're doing.")]
|
||||
public WDist BounceBlockerScanRadius = new WDist(-1);
|
||||
|
||||
public IProjectile Create(ProjectileArgs args) { return new Bullet(this, args); }
|
||||
|
||||
void IRulesetLoaded<WeaponInfo>.RulesetLoaded(Ruleset rules, WeaponInfo wi)
|
||||
{
|
||||
if (BlockerScanRadius < WDist.Zero)
|
||||
BlockerScanRadius = Util.MinimumRequiredBlockerScanRadius(rules);
|
||||
|
||||
if (BounceBlockerScanRadius < WDist.Zero)
|
||||
BounceBlockerScanRadius = Util.MinimumRequiredVictimScanRadius(rules);
|
||||
}
|
||||
}
|
||||
|
||||
public class Bullet : IProjectile, ISync
|
||||
@@ -214,7 +197,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
var shouldExplode = false;
|
||||
WPos blockedPos;
|
||||
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width,
|
||||
info.BlockerScanRadius, out blockedPos))
|
||||
out blockedPos))
|
||||
{
|
||||
pos = blockedPos;
|
||||
shouldExplode = true;
|
||||
@@ -237,7 +220,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
|
||||
if (flightLengthReached && shouldBounce)
|
||||
{
|
||||
shouldExplode |= AnyValidTargetsInRadius(world, pos, info.Width + info.BounceBlockerScanRadius, args.SourceActor, true);
|
||||
shouldExplode |= AnyValidTargetsInRadius(world, pos, info.Width, args.SourceActor, true);
|
||||
target += (pos - source) * info.BounceRangeModifier / 100;
|
||||
var dat = world.Map.DistanceAboveTerrain(target);
|
||||
target += new WVec(0, 0, -dat.Length);
|
||||
@@ -255,7 +238,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
|
||||
// After first bounce, check for targets each tick
|
||||
if (remainingBounces < info.BounceCount)
|
||||
shouldExplode |= AnyValidTargetsInRadius(world, pos, info.Width + info.BounceBlockerScanRadius, args.SourceActor, true);
|
||||
shouldExplode |= AnyValidTargetsInRadius(world, pos, info.Width, args.SourceActor, true);
|
||||
|
||||
if (shouldExplode)
|
||||
Explode(world);
|
||||
@@ -298,7 +281,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
|
||||
bool AnyValidTargetsInRadius(World world, WPos pos, WDist radius, Actor firedBy, bool checkTargetType)
|
||||
{
|
||||
foreach (var victim in world.FindActorsInCircle(pos, radius))
|
||||
foreach (var victim in world.FindActorsOnCircle(pos, radius))
|
||||
{
|
||||
if (checkTargetType && !Target.FromActor(victim).IsValidFor(firedBy))
|
||||
continue;
|
||||
|
||||
@@ -19,7 +19,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Projectiles
|
||||
{
|
||||
[Desc("Simple, invisible, usually direct-on-target projectile.")]
|
||||
public class InstantHitInfo : IProjectileInfo, IRulesetLoaded<WeaponInfo>
|
||||
public class InstantHitInfo : IProjectileInfo
|
||||
{
|
||||
[Desc("Maximum offset at the maximum range.")]
|
||||
public readonly WDist Inaccuracy = WDist.Zero;
|
||||
@@ -35,12 +35,6 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
public WDist BlockerScanRadius = new WDist(-1);
|
||||
|
||||
public IProjectile Create(ProjectileArgs args) { return new InstantHit(this, args); }
|
||||
|
||||
void IRulesetLoaded<WeaponInfo>.RulesetLoaded(Ruleset rules, WeaponInfo wi)
|
||||
{
|
||||
if (BlockerScanRadius < WDist.Zero)
|
||||
BlockerScanRadius = Util.MinimumRequiredBlockerScanRadius(rules);
|
||||
}
|
||||
}
|
||||
|
||||
public class InstantHit : IProjectile
|
||||
@@ -74,7 +68,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
// Check for blocking actors
|
||||
WPos blockedPos;
|
||||
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, source, target.CenterPosition,
|
||||
info.Width, info.BlockerScanRadius, out blockedPos))
|
||||
info.Width, out blockedPos))
|
||||
{
|
||||
target = Target.FromPos(blockedPos);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Projectiles
|
||||
{
|
||||
public class MissileInfo : IProjectileInfo, IRulesetLoaded<WeaponInfo>
|
||||
public class MissileInfo : IProjectileInfo
|
||||
{
|
||||
[Desc("Name of the image containing the projectile sequence.")]
|
||||
public readonly string Image = null;
|
||||
@@ -148,17 +148,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
"not trigger fast enough, causing the missile to fly past the target.")]
|
||||
public readonly WDist CloseEnough = new WDist(298);
|
||||
|
||||
[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) { return new Missile(this, args); }
|
||||
|
||||
void IRulesetLoaded<WeaponInfo>.RulesetLoaded(Ruleset rules, WeaponInfo wi)
|
||||
{
|
||||
if (BlockerScanRadius < WDist.Zero)
|
||||
BlockerScanRadius = Util.MinimumRequiredBlockerScanRadius(rules);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: double check square roots!!!
|
||||
@@ -453,7 +443,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
}
|
||||
|
||||
// NOTE: It might be desirable to make lookahead more intelligent by outputting more information
|
||||
// than just the highest point in the lookahead distance
|
||||
// than just the highest point in the lookahead distance
|
||||
void InclineLookahead(World world, int distCheck, out int predClfHgt, out int predClfDist, out int lastHtChg, out int lastHt)
|
||||
{
|
||||
predClfHgt = 0; // Highest probed terrain height
|
||||
@@ -849,7 +839,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
var shouldExplode = false;
|
||||
WPos blockedPos;
|
||||
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width,
|
||||
info.BlockerScanRadius, out blockedPos))
|
||||
out blockedPos))
|
||||
{
|
||||
pos = blockedPos;
|
||||
shouldExplode = true;
|
||||
|
||||
@@ -90,29 +90,12 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
[PaletteReference]
|
||||
public readonly string HitAnimPalette = "effect";
|
||||
|
||||
[Desc("Scan radius for actors damaged by beam. If set to zero (default), it will automatically scale to the largest health shape.",
|
||||
"Only set custom values if you know what you're doing.")]
|
||||
public WDist AreaVictimScanRadius = WDist.Zero;
|
||||
|
||||
[Desc("Scan radius for actors with projectile-blocking trait. If set to zero (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 = WDist.Zero;
|
||||
|
||||
public IProjectile Create(ProjectileArgs args)
|
||||
{
|
||||
var bc = BeamPlayerColor ? Color.FromArgb(BeamColor.A, args.SourceActor.Owner.Color.RGB) : BeamColor;
|
||||
var hc = HelixPlayerColor ? Color.FromArgb(HelixColor.A, args.SourceActor.Owner.Color.RGB) : HelixColor;
|
||||
return new Railgun(args, this, bc, hc);
|
||||
}
|
||||
|
||||
public void RulesetLoaded(Ruleset rules, WeaponInfo wi)
|
||||
{
|
||||
if (BlockerScanRadius == WDist.Zero)
|
||||
BlockerScanRadius = Util.MinimumRequiredBlockerScanRadius(rules);
|
||||
|
||||
if (AreaVictimScanRadius == WDist.Zero)
|
||||
AreaVictimScanRadius = Util.MinimumRequiredVictimScanRadius(rules);
|
||||
}
|
||||
}
|
||||
|
||||
public class Railgun : IProjectile
|
||||
@@ -156,7 +139,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
// Check for blocking actors
|
||||
WPos blockedPos;
|
||||
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(args.SourceActor.World, target, args.Source,
|
||||
info.BeamWidth, info.BlockerScanRadius, out blockedPos))
|
||||
info.BeamWidth, out blockedPos))
|
||||
target = blockedPos;
|
||||
|
||||
// Note: WAngle.Sin(x) = 1024 * Math.Sin(2pi/1024 * x)
|
||||
@@ -205,7 +188,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
||||
args.Weapon.Impact(Target.FromPos(target), args.SourceActor, args.DamageModifiers);
|
||||
else
|
||||
{
|
||||
var actors = world.FindActorsOnLine(args.Source, target, info.BeamWidth, info.AreaVictimScanRadius);
|
||||
var actors = world.FindActorsOnLine(args.Source, target, info.BeamWidth);
|
||||
foreach (var a in actors)
|
||||
args.Weapon.Impact(Target.FromActor(a), args.SourceActor, args.DamageModifiers);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user