Differential D354 Diff 1439 ps/trunk/binaries/data/mods/public/simulation/components/ProductionQueue.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/ProductionQueue.js
Show First 20 Lines • Show All 352 Lines • ▼ Show 20 Lines | else if (type == "technology") | ||||
if (!cmpPlayer.TrySubtractResources(cost)) | if (!cmpPlayer.TrySubtractResources(cost)) | ||||
return; | return; | ||||
// Tell the technology manager that we have started researching this so that people can't research the same | // Tell the technology manager that we have started researching this so that people can't research the same | ||||
// thing twice. | // thing twice. | ||||
var cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); | var cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); | ||||
cmpTechnologyManager.QueuedResearch(templateName, this.entity); | cmpTechnologyManager.QueuedResearch(templateName, this.entity); | ||||
if (this.queue.length == 0) | if (this.queue.length == 0) | ||||
cmpTechnologyManager.StartedResearch(templateName); | cmpTechnologyManager.StartedResearch(templateName, false); | ||||
this.queue.push({ | this.queue.push({ | ||||
"id": this.nextID++, | "id": this.nextID++, | ||||
"player": cmpPlayer.GetPlayerID(), | "player": cmpPlayer.GetPlayerID(), | ||||
"count": 1, | "count": 1, | ||||
"technologyTemplate": templateName, | "technologyTemplate": templateName, | ||||
"resources": cost, | "resources": cost, | ||||
"productionStarted": false, | "productionStarted": false, | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | for (var i = 0; i < this.queue.length; ++i) | ||||
if (item.productionStarted && item.unitTemplate) | if (item.productionStarted && item.unitTemplate) | ||||
cmpPlayer.UnReservePopulationSlots(item.population * item.count); | cmpPlayer.UnReservePopulationSlots(item.population * item.count); | ||||
// Mark the research as stopped if we cancel it | // Mark the research as stopped if we cancel it | ||||
if (item.technologyTemplate) | if (item.technologyTemplate) | ||||
{ | { | ||||
// item.player is used as this.entity's owner may be invalid (deletion, etc.) | // item.player is used as this.entity's owner may be invalid (deletion, etc.) | ||||
var cmpTechnologyManager = QueryPlayerIDInterface(item.player, IID_TechnologyManager); | var cmpTechnologyManager = QueryPlayerIDInterface(item.player, IID_TechnologyManager); | ||||
cmpTechnologyManager.StoppedResearch(item.technologyTemplate); | cmpTechnologyManager.StoppedResearch(item.technologyTemplate, true); | ||||
} | } | ||||
// Remove from the queue | // Remove from the queue | ||||
// (We don't need to remove the timer - it'll expire if it discovers the queue is empty) | // (We don't need to remove the timer - it'll expire if it discovers the queue is empty) | ||||
this.queue.splice(i, 1); | this.queue.splice(i, 1); | ||||
Engine.PostMessage(this.entity, MT_ProductionQueueChanged, { }); | Engine.PostMessage(this.entity, MT_ProductionQueueChanged, { }); | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 249 Lines • ▼ Show 20 Lines | if (!item.productionStarted) | ||||
// Unset flag that training is blocked | // Unset flag that training is blocked | ||||
cmpPlayer.UnBlockTraining(); | cmpPlayer.UnBlockTraining(); | ||||
} | } | ||||
if (item.technologyTemplate) | if (item.technologyTemplate) | ||||
{ | { | ||||
// Mark the research as started. | // Mark the research as started. | ||||
var cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); | var cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); | ||||
cmpTechnologyManager.StartedResearch(item.technologyTemplate); | cmpTechnologyManager.StartedResearch(item.technologyTemplate, true); | ||||
} | } | ||||
item.productionStarted = true; | item.productionStarted = true; | ||||
if (item.unitTemplate) | if (item.unitTemplate) | ||||
Engine.PostMessage(this.entity, MT_TrainingStarted, {"entity": this.entity}); | Engine.PostMessage(this.entity, MT_TrainingStarted, {"entity": this.entity}); | ||||
} | } | ||||
// If we won't finish the batch now, just update its timer | // If we won't finish the batch now, just update its timer | ||||
▲ Show 20 Lines • Show All 115 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator