Index: binaries/data/mods/public/simulation/components/ProductionQueue.js =================================================================== --- binaries/data/mods/public/simulation/components/ProductionQueue.js +++ binaries/data/mods/public/simulation/components/ProductionQueue.js @@ -383,12 +383,9 @@ Engine.PostMessage(this.entity, MT_ProductionQueueChanged, { }); - // If this is the first item in the queue, start the timer - if (!this.timer) - { - var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); - this.timer = cmpTimer.SetTimeout(this.entity, IID_ProductionQueue, "ProgressTimeout", g_ProgressInterval, {}); - } + // If this is the first item in the queue. + if (this.queue.length === 1 && !this.timer) + this.ProgressTimeout(); } else { @@ -718,28 +715,32 @@ // Unset flag that training is blocked cmpPlayer.UnBlockTraining(); } - - if (item.technologyTemplate) + else if (item.technologyTemplate) { // Mark the research as started. var cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); cmpTechnologyManager.StartedResearch(item.technologyTemplate, true); } item.productionStarted = true; if (item.unitTemplate) Engine.PostMessage(this.entity, MT_TrainingStarted, {"entity": this.entity}); + + break; } // If we won't finish the batch now, just update its timer - if (item.timeRemaining > time) + if (item.timeRemaining >= time) { item.timeRemaining -= time; + if (item.timeRemaining < time) + time = item.timeRemaining; + // send a message for the AIs. Engine.PostMessage(this.entity, MT_ProductionQueueChanged, { }); break; } if (item.unitTemplate) { var numSpawned = this.SpawnUnits(item.unitTemplate, item.count, item.metadata); @@ -747,7 +748,6 @@ { // All entities spawned, this batch finished cmpPlayer.UnReservePopulationSlots(item.population * numSpawned); - time -= item.timeRemaining; this.queue.shift(); // Unset flag that training is blocked cmpPlayer.UnBlockTraining(); @@ -794,18 +794,16 @@ cmpSoundManager.PlaySoundGroup(template.soundComplete, this.entity); } - time -= item.timeRemaining; - this.queue.shift(); Engine.PostMessage(this.entity, MT_ProductionQueueChanged, { }); } } // If the queue's empty, delete the timer, else repeat it if (this.queue.length == 0) { this.timer = undefined; // Unset flag that training is blocked // (This might happen when the player unqueues all batches) cmpPlayer.UnBlockTraining(); @@ -813,23 +811,23 @@ else { var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); - this.timer = cmpTimer.SetTimeout(this.entity, IID_ProductionQueue, "ProgressTimeout", g_ProgressInterval, data); + this.timer = cmpTimer.SetTimeout(this.entity, IID_ProductionQueue, "ProgressTimeout", time, {}); } }; ProductionQueue.prototype.PauseProduction = function() { this.timer = undefined; this.paused = true; }; ProductionQueue.prototype.UnpauseProduction = function() { this.paused = false; var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); this.timer = cmpTimer.SetTimeout(this.entity, IID_ProductionQueue, "ProgressTimeout", g_ProgressInterval, {}); }; ProductionQueue.prototype.OnValueModification = function(msg) { // if the promotion requirements of units is changed,