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.
161 lines
5.3 KiB
C#
161 lines
5.3 KiB
C#
#region Copyright & License Information
|
|
/*
|
|
* Copyright 2007-2018 The OpenRA Developers (see AUTHORS)
|
|
* This file is part of OpenRA, which is free software. It is made
|
|
* available to you under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation, either version 3 of
|
|
* the License, or (at your option) any later version. For more
|
|
* information, see COPYING.
|
|
*/
|
|
#endregion
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
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
|
|
{
|
|
[Desc("List of explosion sequences that can be used.")]
|
|
[SequenceReference("Image")] public readonly string[] Explosions = new string[0];
|
|
|
|
[Desc("Image containing explosion effect sequence.")]
|
|
public readonly string Image = "explosion";
|
|
|
|
[Desc("Palette to use for explosion effect."), PaletteReference("UsePlayerPalette")]
|
|
public readonly string ExplosionPalette = "effect";
|
|
|
|
[Desc("Remap explosion effect to player color, if art supports it.")]
|
|
public readonly bool UsePlayerPalette = false;
|
|
|
|
[Desc("Display explosion effect at ground level, regardless of explosion altitude.")]
|
|
public readonly bool ForceDisplayAtGroundLevel = false;
|
|
|
|
[Desc("List of sounds that can be played on impact.")]
|
|
public readonly string[] ImpactSounds = new string[0];
|
|
|
|
[Desc("Chance of impact sound to play.")]
|
|
public readonly int ImpactSoundChance = 100;
|
|
|
|
[Desc("Consider explosion above this altitude an air explosion.",
|
|
"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("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 (ImpactActors)
|
|
{
|
|
var targetType = GetDirectHitTargetType(world, cell, pos, firedBy, true);
|
|
if (targetType == ImpactTargetType.ValidActor)
|
|
return ImpactType.TargetHit;
|
|
if (targetType == ImpactTargetType.InvalidActor)
|
|
return ImpactType.None;
|
|
}
|
|
|
|
var dat = world.Map.DistanceAboveTerrain(pos);
|
|
if (dat > AirThreshold)
|
|
return ImpactType.Air;
|
|
|
|
return ImpactType.Ground;
|
|
}
|
|
|
|
public ImpactTargetType GetDirectHitTargetType(World world, CPos cell, WPos pos, Actor firedBy, bool checkTargetValidity = false)
|
|
{
|
|
var victims = world.FindActorsOnCircle(pos, WDist.Zero);
|
|
var invalidHit = false;
|
|
|
|
foreach (var victim in victims)
|
|
{
|
|
if (!AffectsParent && victim == firedBy)
|
|
continue;
|
|
|
|
if (!victim.Info.HasTraitInfo<HealthInfo>())
|
|
continue;
|
|
|
|
// If the impact position is within any HitShape, we have a direct hit
|
|
var activeShapes = victim.TraitsImplementing<HitShape>().Where(Exts.IsTraitEnabled);
|
|
var directHit = activeShapes.Any(i => i.Info.Type.DistanceFromEdge(pos, victim).Length <= 0);
|
|
|
|
// If the warhead landed outside the actor's hit-shape(s), we need to skip the rest so it won't be considered an invalidHit
|
|
if (!directHit)
|
|
continue;
|
|
|
|
if (!checkTargetValidity || IsValidAgainst(victim, firedBy))
|
|
return ImpactTargetType.ValidActor;
|
|
|
|
// If we got here, it must be an invalid target
|
|
invalidHit = true;
|
|
}
|
|
|
|
// If there was at least a single direct hit, but none on valid target(s), we return InvalidActor
|
|
return invalidHit ? ImpactTargetType.InvalidActor : ImpactTargetType.NoActor;
|
|
}
|
|
|
|
public override void DoImpact(Target target, Actor firedBy, IEnumerable<int> damageModifiers)
|
|
{
|
|
if (!target.IsValidFor(firedBy))
|
|
return;
|
|
|
|
var pos = target.CenterPosition;
|
|
var world = firedBy.World;
|
|
var targetTile = world.Map.CellContaining(pos);
|
|
var isValid = IsValidImpact(pos, firedBy);
|
|
|
|
if ((!world.Map.Contains(targetTile)) || (!isValid))
|
|
return;
|
|
|
|
var palette = ExplosionPalette;
|
|
if (UsePlayerPalette)
|
|
palette += firedBy.Owner.InternalName;
|
|
|
|
var explosion = Explosions.RandomOrDefault(Game.CosmeticRandom);
|
|
if (Image != null && explosion != null)
|
|
{
|
|
if (ForceDisplayAtGroundLevel)
|
|
{
|
|
var dat = world.Map.DistanceAboveTerrain(pos);
|
|
pos = new WPos(pos.X, pos.Y, pos.Z - dat.Length);
|
|
}
|
|
|
|
world.AddFrameEndTask(w => w.Add(new SpriteEffect(pos, w, Image, explosion, palette)));
|
|
}
|
|
|
|
var impactSound = ImpactSounds.RandomOrDefault(Game.CosmeticRandom);
|
|
if (impactSound != null && Game.CosmeticRandom.Next(0, 100) < ImpactSoundChance)
|
|
Game.Sound.Play(SoundType.World, impactSound, pos);
|
|
}
|
|
|
|
public bool IsValidImpact(WPos pos, Actor firedBy)
|
|
{
|
|
var world = firedBy.World;
|
|
var targetTile = world.Map.CellContaining(pos);
|
|
if (!world.Map.Contains(targetTile))
|
|
return false;
|
|
|
|
var impactType = GetImpactType(world, targetTile, pos, firedBy);
|
|
switch (impactType)
|
|
{
|
|
case ImpactType.TargetHit:
|
|
return true;
|
|
case ImpactType.Air:
|
|
return IsValidTarget(TargetTypeAir);
|
|
case ImpactType.Ground:
|
|
var tileInfo = world.Map.GetTerrainInfo(targetTile);
|
|
return IsValidTarget(tileInfo.TargetTypes);
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|