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")]
public readonly IProjectileInfo Projectile;
[FieldLoader.LoadUsing("LoadWarheads")]
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>
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)
firedBy.World.AddFrameEndTask(
w => w.Add(new DelayedAction(wh.Delay, a)));
firedBy.World.AddFrameEndTask(w => w.Add(new DelayedAction(wh.Delay, a)));
else
a();
}