Set ProductionItem build time when building starts

The build time for a unit/structure was previously set at the time that
item was added to a production queue. This meant modifiers of the
production time (multiple production facilities in ClassicProductionQueue
or "instant build" in debug) were not applied to items already in a queue.

This change modifies ProductionQueue so that build time is set at the
instant an item starts building (reaches the front of it's queue). This was
done primarily to make the production bonuses in ClassicProductionQueue
more apparent, though it also makes the "instant build" debug option more
responsive when items are queued prior to enabling.
This commit is contained in:
Stephen Holdaway
2014-03-09 13:38:57 +12:00
parent c95114deff
commit bd077d337f
2 changed files with 13 additions and 6 deletions

View File

@@ -232,7 +232,7 @@ namespace OpenRA.Mods.RA
for (var n = 0; n < order.TargetLocation.X; n++) // repeat count
{
bool hasPlayedSound = false;
BeginProduction(new ProductionItem(this, order.TargetString, time, cost, PlayerPower,
BeginProduction(new ProductionItem(this, order.TargetString, cost, PlayerPower,
() => self.World.AddFrameEndTask(
_ =>
{
@@ -347,7 +347,7 @@ namespace OpenRA.Mods.RA
public readonly string Item;
public readonly ProductionQueue Queue;
readonly PowerManager pm;
public readonly int TotalTime;
public int TotalTime;
public readonly int TotalCost;
public int RemainingTime { get; private set; }
public int RemainingCost { get; private set; }
@@ -360,15 +360,14 @@ namespace OpenRA.Mods.RA
}
}
public bool Paused = false, Done = false;
public bool Paused = false, Done = false, Started = false;
public Action OnComplete;
public int slowdown = 0;
public ProductionItem(ProductionQueue queue, string item, int time, int cost, PowerManager pm, Action onComplete)
public ProductionItem(ProductionQueue queue, string item, int cost, PowerManager pm, Action onComplete)
{
if (time <= 0) time = 1;
Item = item;
RemainingTime = TotalTime = time;
RemainingTime = TotalTime = 1;
RemainingCost = TotalCost = cost;
OnComplete = onComplete;
Queue = queue;
@@ -378,6 +377,13 @@ namespace OpenRA.Mods.RA
public void Tick(PlayerResources pr)
{
if (!Started)
{
var time = Queue.GetBuildTime(Item);
if (time > 0) RemainingTime = TotalTime = time;
Started = true;
}
if (Done)
{
if (OnComplete != null) OnComplete();