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:
@@ -224,17 +224,17 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static Order StartProduction(Actor subject, string item, int count)
|
public static Order StartProduction(Actor subject, string item, int count)
|
||||||
{
|
{
|
||||||
return new Order("StartProduction", subject, false) { TargetLocation = new CPos(count, 0), TargetString = item };
|
return new Order("StartProduction", subject, false) { ExtraData = (uint)count, TargetString = item };
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Order PauseProduction(Actor subject, string item, bool pause)
|
public static Order PauseProduction(Actor subject, string item, bool pause)
|
||||||
{
|
{
|
||||||
return new Order("PauseProduction", subject, false) { TargetLocation = new CPos(pause ? 1 : 0, 0), TargetString = item };
|
return new Order("PauseProduction", subject, false) { ExtraData = pause ? 1u : 0u, TargetString = item };
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Order CancelProduction(Actor subject, string item, int count)
|
public static Order CancelProduction(Actor subject, string item, int count)
|
||||||
{
|
{
|
||||||
return new Order("CancelProduction", subject, false) { TargetLocation = new CPos(count, 0), TargetString = item };
|
return new Order("CancelProduction", subject, false) { ExtraData = (uint)count, TargetString = item };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,15 +221,20 @@ namespace OpenRA.Mods.RA
|
|||||||
return; /* you can't build that!! */
|
return; /* you can't build that!! */
|
||||||
|
|
||||||
// Check if the player is trying to build more units that they are allowed
|
// Check if the player is trying to build more units that they are allowed
|
||||||
|
var fromLimit = int.MaxValue;
|
||||||
if (bi.BuildLimit > 0)
|
if (bi.BuildLimit > 0)
|
||||||
{
|
{
|
||||||
var inQueue = Queue.Count(pi => pi.Item == order.TargetString);
|
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);
|
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;
|
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;
|
bool hasPlayedSound = false;
|
||||||
BeginProduction(new ProductionItem(this, order.TargetString, cost, PlayerPower,
|
BeginProduction(new ProductionItem(this, order.TargetString, cost, PlayerPower,
|
||||||
@@ -256,12 +261,12 @@ namespace OpenRA.Mods.RA
|
|||||||
case "PauseProduction":
|
case "PauseProduction":
|
||||||
{
|
{
|
||||||
if (Queue.Count > 0 && Queue[0].Item == order.TargetString)
|
if (Queue.Count > 0 && Queue[0].Item == order.TargetString)
|
||||||
Queue[0].Paused = ( order.TargetLocation.X != 0 );
|
Queue[0].Paused = ( order.ExtraData != 0 );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "CancelProduction":
|
case "CancelProduction":
|
||||||
{
|
{
|
||||||
CancelProduction(order.TargetString, order.TargetLocation.X);
|
CancelProduction(order.TargetString, order.ExtraData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,7 +286,7 @@ namespace OpenRA.Mods.RA
|
|||||||
return (int) time;
|
return (int) time;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void CancelProduction(string itemName, int numberToCancel)
|
protected void CancelProduction(string itemName, uint numberToCancel)
|
||||||
{
|
{
|
||||||
for (var i = 0; i < numberToCancel; i++)
|
for (var i = 0; i < numberToCancel; i++)
|
||||||
CancelProductionInner(itemName);
|
CancelProductionInner(itemName);
|
||||||
|
|||||||
Reference in New Issue
Block a user