Files
OpenRA/OpenRA.Mods.Common/Projectiles/InstantHit.cs
reaperrr 1d2361cdd3 Change default and auto-calc of victim scans to -1
For all projectiles and warheads.

Not really a must for everything else, but for CreateEffectWarhead, the
ImpactTypes refactor (separate PR) makes it a bit harder to make the
warhead valid in every situation, so setting the victim scan to zero is the easiest way to disable scanning for actors completely.
2017-06-25 22:40:12 +02:00

92 lines
2.9 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2017 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.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Projectiles
{
[Desc("Simple, invisible, usually direct-on-target projectile.")]
public class InstantHitInfo : IProjectileInfo, IRulesetLoaded<WeaponInfo>
{
[Desc("Maximum offset at the maximum range.")]
public readonly WDist Inaccuracy = WDist.Zero;
[Desc("Projectile can be blocked.")]
public readonly bool Blockable = false;
[Desc("The width of the projectile.")]
public readonly WDist Width = new WDist(1);
[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 InstantHit(this, args); }
void IRulesetLoaded<WeaponInfo>.RulesetLoaded(Ruleset rules, WeaponInfo wi)
{
if (BlockerScanRadius < WDist.Zero)
BlockerScanRadius = Util.MinimumRequiredBlockerScanRadius(rules);
}
}
public class InstantHit : IProjectile
{
readonly ProjectileArgs args;
readonly InstantHitInfo info;
Target target;
WPos source;
public InstantHit(InstantHitInfo info, ProjectileArgs args)
{
this.args = args;
this.info = info;
source = args.Source;
if (args.Weapon.TargetActorCenter)
target = args.GuidedTarget;
else if (info.Inaccuracy.Length > 0)
{
var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
var maxOffset = inaccuracy * (args.PassiveTarget - source).Length / args.Weapon.Range.Length;
target = Target.FromPos(args.PassiveTarget + WVec.FromPDF(args.SourceActor.World.SharedRandom, 2) * maxOffset / 1024);
}
else
target = Target.FromPos(args.PassiveTarget);
}
public void Tick(World world)
{
// Check for blocking actors
WPos blockedPos;
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, source, target.CenterPosition,
info.Width, info.BlockerScanRadius, out blockedPos))
{
target = Target.FromPos(blockedPos);
}
args.Weapon.Impact(target, args.SourceActor, args.DamageModifiers);
world.AddFrameEndTask(w => w.Remove(this));
}
public IEnumerable<IRenderable> Render(WorldRenderer wr)
{
return Enumerable.Empty<IRenderable>();
}
}
}