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:
@@ -18,7 +18,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Warheads
|
||||
{
|
||||
public class CreateEffectWarhead : Warhead, IRulesetLoaded<WeaponInfo>
|
||||
public class CreateEffectWarhead : Warhead
|
||||
{
|
||||
[Desc("List of explosion sequences that can be used.")]
|
||||
[SequenceReference("Image")] public readonly string[] Explosions = new string[0];
|
||||
@@ -45,22 +45,15 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
"If that's the case, this warhead will consider the explosion position to have the 'Air' TargetType (in addition to any nearby actor's TargetTypes).")]
|
||||
public readonly WDist AirThreshold = new WDist(128);
|
||||
|
||||
[Desc("Scan radius for victims around impact. If set to a negative value (default), it will automatically scale to the largest health shape.",
|
||||
"Custom overrides should not be necessary under normal circumstances.")]
|
||||
public WDist VictimScanRadius = new WDist(-1);
|
||||
|
||||
void IRulesetLoaded<WeaponInfo>.RulesetLoaded(Ruleset rules, WeaponInfo info)
|
||||
{
|
||||
if (VictimScanRadius < WDist.Zero)
|
||||
VictimScanRadius = Util.MinimumRequiredVictimScanRadius(rules);
|
||||
}
|
||||
[Desc("Whether to consider actors in determining whether the explosion should happen. If false, only terrain will be considered.")]
|
||||
public readonly bool ImpactActors = true;
|
||||
|
||||
static readonly string[] TargetTypeAir = new string[] { "Air" };
|
||||
|
||||
public ImpactType GetImpactType(World world, CPos cell, WPos pos, Actor firedBy)
|
||||
{
|
||||
// Matching target actor
|
||||
if (VictimScanRadius > WDist.Zero)
|
||||
if (ImpactActors)
|
||||
{
|
||||
var targetType = GetDirectHitTargetType(world, cell, pos, firedBy, true);
|
||||
if (targetType == ImpactTargetType.ValidActor)
|
||||
@@ -78,7 +71,7 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
|
||||
public ImpactTargetType GetDirectHitTargetType(World world, CPos cell, WPos pos, Actor firedBy, bool checkTargetValidity = false)
|
||||
{
|
||||
var victims = world.FindActorsInCircle(pos, VictimScanRadius);
|
||||
var victims = world.FindActorsOnCircle(pos, WDist.Zero);
|
||||
var invalidHit = false;
|
||||
|
||||
foreach (var victim in victims)
|
||||
|
||||
@@ -28,15 +28,8 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
[Desc("Ranges at which each Falloff step is defined. Overrides Spread.")]
|
||||
public WDist[] Range = null;
|
||||
|
||||
[Desc("Extra search radius beyond maximum spread. If set to a negative value (default), it will automatically scale to the largest health shape.",
|
||||
"Custom overrides should not be necessary under normal circumstances.")]
|
||||
public WDist VictimScanRadius = new WDist(-1);
|
||||
|
||||
void IRulesetLoaded<WeaponInfo>.RulesetLoaded(Ruleset rules, WeaponInfo info)
|
||||
{
|
||||
if (VictimScanRadius < WDist.Zero)
|
||||
VictimScanRadius = Util.MinimumRequiredVictimScanRadius(rules);
|
||||
|
||||
if (Range != null)
|
||||
{
|
||||
if (Range.Length != 1 && Range.Length != Falloff.Length)
|
||||
@@ -58,9 +51,7 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
if (debugVis != null && debugVis.CombatGeometry)
|
||||
world.WorldActor.Trait<WarheadDebugOverlay>().AddImpact(pos, Range, DebugOverlayColor);
|
||||
|
||||
// This only finds actors where the center is within the search radius,
|
||||
// so we need to search beyond the maximum spread to account for actors with large health radius
|
||||
var hitActors = world.FindActorsInCircle(pos, Range[Range.Length - 1] + VictimScanRadius);
|
||||
var hitActors = world.FindActorsOnCircle(pos, Range[Range.Length - 1]);
|
||||
|
||||
foreach (var victim in hitActors)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user