Differential D2459 Diff 10601 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 344 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. | ||||
let cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); | let 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, false); | cmpTechnologyManager.StartedResearch(templateName, false); | ||||
this.SetAnimation("researching"); | |||||
} | |||||
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 | 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, true); | cmpTechnologyManager.StoppedResearch(item.technologyTemplate, true); | ||||
this.SetAnimation("idle"); | |||||
} | } | ||||
// 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; | ||||
} | } | ||||
}; | }; | ||||
ProductionQueue.prototype.SetAnimation = function(name) | |||||
{ | |||||
let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual); | |||||
if (cmpVisual) | |||||
cmpVisual.SelectAnimation(name, false, 1); | |||||
} | |||||
/* | /* | ||||
* Returns basic data from all batches in the production queue. | * Returns basic data from all batches in the production queue. | ||||
*/ | */ | ||||
ProductionQueue.prototype.GetQueue = function() | ProductionQueue.prototype.GetQueue = function() | ||||
{ | { | ||||
var out = []; | var out = []; | ||||
for (var item of this.queue) | for (var item of this.queue) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 230 Lines • ▼ Show 20 Lines | if (!item.productionStarted) | ||||
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, true); | cmpTechnologyManager.StartedResearch(item.technologyTemplate, true); | ||||
this.SetAnimation("researching"); | |||||
} | } | ||||
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 43 Lines • ▼ Show 20 Lines | if (item.unitTemplate) | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
else if (item.technologyTemplate) | else if (item.technologyTemplate) | ||||
{ | { | ||||
var cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); | var cmpTechnologyManager = QueryOwnerInterface(this.entity, IID_TechnologyManager); | ||||
cmpTechnologyManager.ResearchTechnology(item.technologyTemplate); | cmpTechnologyManager.ResearchTechnology(item.technologyTemplate); | ||||
this.SetAnimation("idle"); | |||||
let template = TechnologyTemplates.Get(item.technologyTemplate); | let template = TechnologyTemplates.Get(item.technologyTemplate); | ||||
if (template && template.soundComplete) | if (template && template.soundComplete) | ||||
{ | { | ||||
var cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager); | var cmpSoundManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_SoundManager); | ||||
if (cmpSoundManager) | if (cmpSoundManager) | ||||
cmpSoundManager.PlaySoundGroup(template.soundComplete, this.entity); | cmpSoundManager.PlaySoundGroup(template.soundComplete, this.entity); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator