Fix build palette showing too many queued items when BuildLimit is reached

When a BuildLimit on an actor type is set and nearly reached, you could
shift-click the build palette and it would show it had five more items
queued when really less are allowed to be built. This fixes it so that
only the allowed number of items is enqueued, and thus showing the
correct number on the build palette.
This commit is contained in:
Oliver Brakmann
2014-04-26 16:14:48 +02:00
parent e572c0dcb6
commit 63f4a0646f
2 changed files with 13 additions and 8 deletions

View File

@@ -221,15 +221,20 @@ namespace OpenRA.Mods.RA
return; /* you can't build that!! */
// Check if the player is trying to build more units that they are allowed
var fromLimit = int.MaxValue;
if (bi.BuildLimit > 0)
{
var inQueue = Queue.Count(pi => pi.Item == order.TargetString);
var owned = self.Owner.World.ActorsWithTrait<Buildable>().Count(a => a.Actor.Info.Name == order.TargetString && a.Actor.Owner == self.Owner);
if (inQueue + owned >= bi.BuildLimit)
fromLimit = bi.BuildLimit - (inQueue + owned);
if (fromLimit <= 0)
return;
}
for (var n = 0; n < order.TargetLocation.X; n++) // repeat count
var amountToBuild = Math.Min(fromLimit, order.ExtraData);
for (var n = 0; n < amountToBuild; n++) // repeat count
{
bool hasPlayedSound = false;
BeginProduction(new ProductionItem(this, order.TargetString, cost, PlayerPower,
@@ -256,12 +261,12 @@ namespace OpenRA.Mods.RA
case "PauseProduction":
{
if (Queue.Count > 0 && Queue[0].Item == order.TargetString)
Queue[0].Paused = ( order.TargetLocation.X != 0 );
Queue[0].Paused = ( order.ExtraData != 0 );
break;
}
case "CancelProduction":
{
CancelProduction(order.TargetString, order.TargetLocation.X);
CancelProduction(order.TargetString, order.ExtraData);
break;
}
}
@@ -281,7 +286,7 @@ namespace OpenRA.Mods.RA
return (int) time;
}
protected void CancelProduction(string itemName, int numberToCancel)
protected void CancelProduction(string itemName, uint numberToCancel)
{
for (var i = 0; i < numberToCancel; i++)
CancelProductionInner(itemName);