Skip to content

Commit

Permalink
Merge pull request #156 from dnqbob/bf-fix
Browse files Browse the repository at this point in the history
BackFireShrapnel: fix crash on beam weapon and code simplify
  • Loading branch information
MustaphaTR authored May 26, 2024
2 parents 3d42128 + ca51219 commit 5c19aea
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions OpenRA.Mods.AS/Warheads/BackFireShrapnelWarhead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
#endregion

using System;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;

namespace OpenRA.Mods.AS.Warheads
Expand All @@ -24,8 +22,6 @@ public class BackFireShrapnelWarhead : WarheadAS, IRulesetLoaded<WeaponInfo>
[Desc("Has to be defined in weapons.yaml as well.")]
public readonly string Weapon = null;

public readonly string WeaponName = "primary";

WeaponInfo weapon;

public void RulesetLoaded(Ruleset rules, WeaponInfo info)
Expand All @@ -44,33 +40,28 @@ public override void DoImpact(in Target target, WarheadArgs args)
var shrapnelTarget = Target.Invalid;

shrapnelTarget = Target.FromActor(firedBy);
var sourcepos = target.CenterPosition;
var facing = (shrapnelTarget.CenterPosition - sourcepos).Yaw;

if (shrapnelTarget.Type != TargetType.Invalid)
{
var pargs = new ProjectileArgs
{
Weapon = weapon,
Facing = (shrapnelTarget.CenterPosition - target.CenterPosition).Yaw,
Facing = facing,
CurrentMuzzleFacing = () => facing,

DamageModifiers = !firedBy.IsDead
? firedBy.TraitsImplementing<IFirepowerModifier>()
.Select(a => a.GetFirepowerModifier(WeaponName)).ToArray()
: Array.Empty<int>(),
DamageModifiers = args.DamageModifiers,

InaccuracyModifiers = !firedBy.IsDead
? firedBy.TraitsImplementing<IInaccuracyModifier>()
.Select(a => a.GetInaccuracyModifier()).ToArray()
: Array.Empty<int>(),
InaccuracyModifiers = Array.Empty<int>(),

RangeModifiers = !firedBy.IsDead
? firedBy.TraitsImplementing<IRangeModifier>()
.Select(a => a.GetRangeModifier()).ToArray()
: Array.Empty<int>(),
RangeModifiers = Array.Empty<int>(),

Source = target.CenterPosition,
Source = sourcepos,
CurrentSource = () => sourcepos,
SourceActor = firedBy,
GuidedTarget = shrapnelTarget,
PassiveTarget = shrapnelTarget.CenterPosition
PassiveTarget = shrapnelTarget.CenterPosition,
};

if (pargs.Weapon.Projectile != null)
Expand All @@ -81,9 +72,8 @@ public override void DoImpact(in Target target, WarheadArgs args)

if (pargs.Weapon.Report != null && pargs.Weapon.Report.Length > 0)
{
var pos = target.CenterPosition;
if (pargs.Weapon.AudibleThroughFog || (!firedBy.World.ShroudObscures(pos) && !firedBy.World.FogObscures(pos)))
Game.Sound.Play(SoundType.World, pargs.Weapon.Report, firedBy.World, pos, null, pargs.Weapon.SoundVolume);
if (pargs.Weapon.AudibleThroughFog || (!firedBy.World.ShroudObscures(sourcepos) && !firedBy.World.FogObscures(sourcepos)))
Game.Sound.Play(SoundType.World, pargs.Weapon.Report, firedBy.World, sourcepos, null, pargs.Weapon.SoundVolume);
}
}
}
Expand Down

0 comments on commit 5c19aea

Please sign in to comment.