fix mishandled CancelProduction

This commit is contained in:
Chris Forbes
2010-10-11 19:36:10 +13:00
parent 024b564b8c
commit b905d343af

View File

@@ -196,27 +196,21 @@ namespace OpenRA.Mods.RA
protected void CancelProduction(string itemName, int numberToCancel) protected void CancelProduction(string itemName, int numberToCancel)
{ {
if (Queue.Count == 0) for (var i = 0; i < numberToCancel; i++)
return; // Nothing to do here CancelProductionInner(itemName);
var lastIndex = Queue.FindLastIndex(a => a.Item == itemName);
while (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) void CancelProductionInner(string itemName)
{
var lastIndex = Queue.FindLastIndex(a => a.Item == itemName);
if (lastIndex > 0)
Queue.RemoveAt(lastIndex);
else if (lastIndex == 0)
{ {
var item = Queue[0]; var item = Queue[0];
self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(item.TotalCost - item.RemainingCost); // refund what's been paid so far. self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(
item.TotalCost - item.RemainingCost); // refund what has been paid
FinishProduction(); FinishProduction();
} }
} }