Merge pull request #6612 from pchote/fix-warheads

Fix a loop closure bug in the weapons code.
This commit is contained in:
Chris Forbes
2014-09-30 07:20:42 +13:00

View File

@@ -62,6 +62,7 @@ namespace OpenRA.GameRules
[FieldLoader.LoadUsing("LoadProjectile")] [FieldLoader.LoadUsing("LoadProjectile")]
public readonly IProjectileInfo Projectile; public readonly IProjectileInfo Projectile;
[FieldLoader.LoadUsing("LoadWarheads")] [FieldLoader.LoadUsing("LoadWarheads")]
public readonly List<Warhead> Warheads = new List<Warhead>(); public readonly List<Warhead> Warheads = new List<Warhead>();
@@ -150,14 +151,13 @@ namespace OpenRA.GameRules
/// <summary>Applies all the weapon's warheads to the target.</summary> /// <summary>Applies all the weapon's warheads to the target.</summary>
public void Impact(Target target, Actor firedBy, IEnumerable<int> damageModifiers) public void Impact(Target target, Actor firedBy, IEnumerable<int> damageModifiers)
{ {
foreach (var wh in Warheads) foreach (var warhead in Warheads)
{ {
Action a; var wh = warhead; // force the closure to bind to the current warhead
a = () => wh.DoImpact(target, firedBy, damageModifiers); Action a = () => wh.DoImpact(target, firedBy, damageModifiers);
if (wh.Delay > 0) if (wh.Delay > 0)
firedBy.World.AddFrameEndTask( firedBy.World.AddFrameEndTask(w => w.Add(new DelayedAction(wh.Delay, a)));
w => w.Add(new DelayedAction(wh.Delay, a)));
else else
a(); a();
} }