Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/ProductionQueue.js
Show All 17 Lines | "<optional>" + | ||||
"<element name='Entities' a:help='Space-separated list of entity template names that this entity can train. The special string \"{civ}\" will be automatically replaced by the civ code of the entity's owner, while the string \"{native}\" will be automatically replaced by the entity's civ code.'>" + | "<element name='Entities' a:help='Space-separated list of entity template names that this entity can train. The special string \"{civ}\" will be automatically replaced by the civ code of the entity's owner, while the string \"{native}\" will be automatically replaced by the entity's civ code.'>" + | ||||
"<attribute name='datatype'>" + | "<attribute name='datatype'>" + | ||||
"<value>tokens</value>" + | "<value>tokens</value>" + | ||||
"</attribute>" + | "</attribute>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"</optional>" + | "</optional>" + | ||||
"<optional>" + | "<optional>" + | ||||
"<element name='ResearchVariant' a:help='The name of the variant to switch to when researching.'>" + | |||||
"<text/>" + | |||||
"</element>" + | |||||
"</optional>" + | |||||
"<optional>" + | |||||
"<element name='Technologies' a:help='Space-separated list of technology names that this building can research. When present, the special string \"{civ}\" will be automatically replaced either by the civ code of the building's owner if such a tech exists, or by \"generic\".'>" + | "<element name='Technologies' a:help='Space-separated list of technology names that this building can research. When present, the special string \"{civ}\" will be automatically replaced either by the civ code of the building's owner if such a tech exists, or by \"generic\".'>" + | ||||
"<attribute name='datatype'>" + | "<attribute name='datatype'>" + | ||||
"<value>tokens</value>" + | "<value>tokens</value>" + | ||||
"</attribute>" + | "</attribute>" + | ||||
"<text/>" + | "<text/>" + | ||||
"</element>" + | "</element>" + | ||||
"</optional>" + | "</optional>" + | ||||
"<element name='TechCostMultiplier' a:help='Multiplier to modify ressources cost and research time of technologies searched in this building.'>" + | "<element name='TechCostMultiplier' a:help='Multiplier to modify ressources cost and research time of technologies searched in this building.'>" + | ||||
Show All 29 Lines | ProductionQueue.prototype.Init = function() | ||||
// "timeRemaining": 10000, // msecs | // "timeRemaining": 10000, // msecs | ||||
// } | // } | ||||
this.timer = undefined; // g_ProgressInterval msec timer, active while the queue is non-empty | this.timer = undefined; // g_ProgressInterval msec timer, active while the queue is non-empty | ||||
this.paused = false; | this.paused = false; | ||||
this.entityCache = []; | this.entityCache = []; | ||||
this.spawnNotified = false; | this.spawnNotified = false; | ||||
this.researchVariant = this.template.ResearchVariant || "researching"; | |||||
}; | }; | ||||
/* | /* | ||||
* Returns list of entities that can be trained by this building. | * Returns list of entities that can be trained by this building. | ||||
*/ | */ | ||||
ProductionQueue.prototype.GetEntitiesList = function() | ProductionQueue.prototype.GetEntitiesList = function() | ||||
{ | { | ||||
return this.entitiesList; | return this.entitiesList; | ||||
▲ Show 20 Lines • Show All 266 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(this.researchVariant); | |||||
} | |||||
Silier: you are starting research here as well | |||||
Done Inline Actions1.0 -> 1 (and other related places) Silier: 1.0 -> 1 (and other related places) | |||||
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, | ||||
"timeTotal": time*1000, | "timeTotal": time*1000, | ||||
▲ Show 20 Lines • Show All 79 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"); | |||||
Done Inline Actionsmissing ; Silier: missing ; | |||||
} | } | ||||
// 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(this.researchVariant); | |||||
Done Inline Actionsthis does not exist here Silier: this does not exist here | |||||
Done Inline Actionsmissing ; Silier: missing ; | |||||
} | } | ||||
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"); | |||||
Done Inline Actionsmissing ; Silier: missing ; | |||||
let template = TechnologyTemplates.Get(item.technologyTemplate); | let template = TechnologyTemplates.Get(item.technologyTemplate); | ||||
Done Inline Actionshere you finished research, you need to switch back to idle animation Silier: here you finished research, you need to switch back to idle animation | |||||
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
you are starting research here as well