Limit training queue size

(Fixes #613)

This was SVN commit r8382.
This commit is contained in:
WhiteTreePaladin 2010-10-16 21:53:50 +00:00
parent 1f4eb955ee
commit 5ca46883e6

View File

@ -1,4 +1,5 @@
var g_ProgressInterval = 1000; var g_ProgressInterval = 1000;
const MAX_QUEUE_SIZE = 16;
function TrainingQueue() {} function TrainingQueue() {}
@ -54,7 +55,10 @@ TrainingQueue.prototype.AddBatch = function(templateName, count)
// TODO: there should probably be a limit on the number of queued batches // TODO: there should probably be a limit on the number of queued batches
// TODO: there should be a way for the GUI to determine whether it's going // TODO: there should be a way for the GUI to determine whether it's going
// to be possible to add a batch (based on resource costs and length limits) // to be possible to add a batch (based on resource costs and length limits)
var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
if (this.queue.length < MAX_QUEUE_SIZE)
{
// Find the template data so we can determine the build costs // Find the template data so we can determine the build costs
var cmpTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); var cmpTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
var template = cmpTempMan.GetTemplate(templateName); var template = cmpTempMan.GetTemplate(templateName);
@ -75,13 +79,9 @@ TrainingQueue.prototype.AddBatch = function(templateName, count)
var population = template.Cost.Population * count; var population = template.Cost.Population * count;
var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
if (!cmpPlayer.TrySubtractResources(costs))
{
// TrySubtractResources should report error to player (they ran out of resources) // TrySubtractResources should report error to player (they ran out of resources)
if (!cmpPlayer.TrySubtractResources(costs))
return; return;
}
this.queue.push({ this.queue.push({
"id": this.nextID++, "id": this.nextID++,
@ -101,6 +101,13 @@ TrainingQueue.prototype.AddBatch = function(templateName, count)
var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
this.timer = cmpTimer.SetTimeout(this.entity, IID_TrainingQueue, "ProgressTimeout", g_ProgressInterval, {}); this.timer = cmpTimer.SetTimeout(this.entity, IID_TrainingQueue, "ProgressTimeout", g_ProgressInterval, {});
} }
}
else
{
var notification = {"player": cmpPlayer.GetPlayerID(), "message": "The training queue is full."};
var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
cmpGUIInterface.PushNotification(notification);
}
}; };
TrainingQueue.prototype.RemoveBatch = function(id) TrainingQueue.prototype.RemoveBatch = function(id)