diff --git a/OpenRA.Mods.RA/Player/ProductionQueue.cs b/OpenRA.Mods.RA/Player/ProductionQueue.cs index 2c11fcedd3..2a8817d179 100755 --- a/OpenRA.Mods.RA/Player/ProductionQueue.cs +++ b/OpenRA.Mods.RA/Player/ProductionQueue.cs @@ -196,27 +196,21 @@ namespace OpenRA.Mods.RA protected void CancelProduction(string itemName, int numberToCancel) { - if (Queue.Count == 0) - return; // Nothing to do here + for (var i = 0; i < numberToCancel; i++) + CancelProductionInner(itemName); + } + void CancelProductionInner(string itemName) + { var lastIndex = Queue.FindLastIndex(a => a.Item == itemName); - while (lastIndex > 0) - { - + if (lastIndex > 0) Queue.RemoveAt(lastIndex); - lastIndex = Queue.FindLastIndex(a => a.Item == itemName); - if (numberToCancel > 0) - --numberToCancel; - if (numberToCancel == 0) - break; - //else negative, continue deleting all orders - } - - if (lastIndex == 0) + else if (lastIndex == 0) { var item = Queue[0]; - self.Owner.PlayerActor.Trait().GiveCash(item.TotalCost - item.RemainingCost); // refund what's been paid so far. + self.Owner.PlayerActor.Trait().GiveCash( + item.TotalCost - item.RemainingCost); // refund what has been paid FinishProduction(); } }