Merge pull request #12605 from reaperrr/ts-weapon-inheritance

Introduce TargetDamageWarhead + some TS weapon fixes
This commit is contained in:
abcdefg30
2017-02-04 00:59:14 +01:00
committed by GitHub
6 changed files with 96 additions and 39 deletions

View File

@@ -574,6 +574,7 @@
<Compile Include="Warheads\HealthPercentageDamageWarhead.cs" />
<Compile Include="Warheads\LeaveSmudgeWarhead.cs" />
<Compile Include="Warheads\SpreadDamageWarhead.cs" />
<Compile Include="Warheads\TargetDamageWarhead.cs" />
<Compile Include="Warheads\Warhead.cs" />
<Compile Include="Widgets\ActorPreviewWidget.cs" />
<Compile Include="Widgets\ColorMixerWidget.cs" />

View File

@@ -10,6 +10,7 @@
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits;
@@ -40,46 +41,42 @@ namespace OpenRA.Mods.Common.Projectiles
readonly ProjectileArgs args;
readonly InstantHitInfo info;
bool doneDamage;
WPos target;
Target target;
WPos source;
public InstantHit(InstantHitInfo info, ProjectileArgs args)
{
this.args = args;
this.info = info;
target = args.PassiveTarget;
source = args.Source;
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 = args.GuidedTarget;
}
public void Tick(World world)
{
// Check for blocking actors
WPos blockedPos;
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, source, target,
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, source, target.CenterPosition,
info.Width, info.TargetExtraSearchRadius, out blockedPos))
{
target = blockedPos;
target = Target.FromPos(blockedPos);
}
if (info.Inaccuracy.Length > 0)
{
var inaccuracy = OpenRA.Mods.Common.Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
var maxOffset = inaccuracy * (target - source).Length / args.Weapon.Range.Length;
target += WVec.FromPDF(args.SourceActor.World.SharedRandom, 2) * maxOffset / 1024;
}
if (!doneDamage)
{
args.Weapon.Impact(Target.FromPos(target), args.SourceActor, args.DamageModifiers);
doneDamage = true;
world.AddFrameEndTask(w => w.Remove(this));
}
args.Weapon.Impact(target, args.SourceActor, args.DamageModifiers);
world.AddFrameEndTask(w => w.Remove(this));
}
public IEnumerable<IRenderable> Render(WorldRenderer wr)
{
yield break;
return Enumerable.Empty<IRenderable>();
}
}
}

View File

@@ -0,0 +1,62 @@
#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 OpenRA.GameRules;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Warheads
{
public class TargetDamageWarhead : DamageWarhead
{
public override void DoImpact(Target target, Actor firedBy, IEnumerable<int> damageModifiers)
{
// Damages a single actor, rather than a position. Only support by InstantHit for now.
// TODO: Add support for 'area of damage'
if (target.Type == TargetType.Actor)
DoImpact(target.Actor, firedBy, damageModifiers);
}
public override void DoImpact(WPos pos, Actor firedBy, IEnumerable<int> damageModifiers)
{
// For now this only displays debug overlay
// TODO: Add support for 'area of effect' / multiple targets
var world = firedBy.World;
var debugOverlayRange = new[] { WDist.Zero, new WDist(128) };
if (world.LocalPlayer != null)
{
var devMode = world.LocalPlayer.PlayerActor.TraitOrDefault<DeveloperMode>();
if (devMode != null && devMode.ShowCombatGeometry)
world.WorldActor.Trait<WarheadDebugOverlay>().AddImpact(pos, debugOverlayRange, DebugOverlayColor);
}
}
public override void DoImpact(Actor victim, Actor firedBy, IEnumerable<int> damageModifiers)
{
if (!IsValidAgainst(victim, firedBy))
return;
var damage = Util.ApplyPercentageModifiers(Damage, damageModifiers.Append(DamageVersus(victim)));
victim.InflictDamage(firedBy, new Damage(damage, DamageTypes));
var world = firedBy.World;
if (world.LocalPlayer != null)
{
var debugOverlayRange = new[] { WDist.Zero, new WDist(128) };
var devMode = world.LocalPlayer.PlayerActor.TraitOrDefault<DeveloperMode>();
if (devMode != null && devMode.ShowCombatGeometry)
world.WorldActor.Trait<WarheadDebugOverlay>().AddImpact(victim.CenterPosition, debugOverlayRange, DebugOverlayColor);
}
}
}
}