Make warheads use the the most sensible victim scan radius

By default, but allow custom overrides.
This commit is contained in:
reaperrr
2017-01-20 15:21:44 +01:00
committed by Chris Forbes
parent 033268a7ba
commit d04c6275da
2 changed files with 21 additions and 9 deletions

View File

@@ -10,13 +10,14 @@
#endregion
using System.Collections.Generic;
using OpenRA.GameRules;
using OpenRA.Mods.Common.Effects;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Warheads
{
public class CreateEffectWarhead : Warhead
public class CreateEffectWarhead : Warhead, IRulesetLoaded<WeaponInfo>
{
[Desc("List of explosion sequences that can be used.")]
[SequenceReference("Image")] public readonly string[] Explosions = new string[0];
@@ -30,9 +31,6 @@ namespace OpenRA.Mods.Common.Warheads
[Desc("Remap explosion effect to player color, if art supports it.")]
public readonly bool UsePlayerPalette = false;
[Desc("Search radius around impact for 'direct hit' check.")]
public readonly WDist TargetSearchRadius = new WDist(2048);
[Desc("List of sounds that can be played on impact.")]
public readonly string[] ImpactSounds = new string[0];
@@ -42,6 +40,16 @@ namespace OpenRA.Mods.Common.Warheads
[Desc("What impact types should this effect NOT apply to.", "Overrides ValidImpactTypes.")]
public readonly ImpactType InvalidImpactTypes = ImpactType.None;
[Desc("Scan radius for victims around impact. If set to zero (default), it will automatically scale to the largest health shape.",
"Custom overrides should not be necessary under normal circumstances.")]
public WDist VictimScanRadius = WDist.Zero;
public void RulesetLoaded(Ruleset rules, WeaponInfo wi)
{
if (VictimScanRadius == WDist.Zero)
VictimScanRadius = Util.MinimumRequiredVictimScanRadius(rules);
}
public ImpactType GetImpactType(World world, CPos cell, WPos pos, Actor firedBy)
{
// Missiles need a margin because they sometimes explode a little above ground
@@ -75,7 +83,7 @@ namespace OpenRA.Mods.Common.Warheads
public bool GetDirectHit(World world, CPos cell, WPos pos, Actor firedBy, bool checkTargetType = false)
{
foreach (var victim in world.FindActorsInCircle(pos, TargetSearchRadius))
foreach (var victim in world.FindActorsInCircle(pos, VictimScanRadius))
{
if (checkTargetType && !IsValidAgainst(victim, firedBy))
continue;