Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/TechnologyManager.js
Show All 17 Lines | |||||
/** | /** | ||||
* Prepare for the queue. | * Prepare for the queue. | ||||
* @param {Object} techCostMultiplier - The multipliers to use when calculating costs. | * @param {Object} techCostMultiplier - The multipliers to use when calculating costs. | ||||
* @return {boolean} - Whether the technology was successfully initiated. | * @return {boolean} - Whether the technology was successfully initiated. | ||||
*/ | */ | ||||
TechnologyManager.prototype.Technology.prototype.Queue = function(techCostMultiplier) | TechnologyManager.prototype.Technology.prototype.Queue = function(techCostMultiplier) | ||||
{ | { | ||||
const template = TechnologyTemplates.Get(this.templateName); | const template = GetTemplateDataHelper(TechnologyTemplates.Get(this.templateName)); | ||||
if (!template) | if (!template) | ||||
return false; | return false; | ||||
this.resources = {}; | this.resources = {}; | ||||
if (template.cost) | if (template.cost?.resources) | ||||
for (const res in template.cost) | for (const res in template.cost.resources) | ||||
this.resources[res] = Math.floor(techCostMultiplier[res] * template.cost[res]); | this.resources[res] = Math.floor(techCostMultiplier[res] * template.cost.resources[res]); | ||||
// ToDo: Subtract resources here or in cmpResearcher? | // ToDo: Subtract resources here or in cmpResearcher? | ||||
const cmpPlayer = Engine.QueryInterface(this.player, IID_Player); | const cmpPlayer = Engine.QueryInterface(this.player, IID_Player); | ||||
// 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(this.resources)) | if (!cmpPlayer?.TrySubtractResources(this.resources)) | ||||
return false; | return false; | ||||
const time = techCostMultiplier.time * (template.researchTime || 0) * 1000; | const time = techCostMultiplier.time * (template.cost.time || 0) * 1000; | ||||
this.timeRemaining = time; | this.timeRemaining = time; | ||||
this.timeTotal = time; | this.timeTotal = time; | ||||
const playerID = cmpPlayer.GetPlayerID(); | const playerID = cmpPlayer.GetPlayerID(); | ||||
Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger).CallEvent("OnResearchQueued", { | Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger).CallEvent("OnResearchQueued", { | ||||
"playerid": playerID, | "playerid": playerID, | ||||
"technologyTemplate": this.templateName, | "technologyTemplate": this.templateName, | ||||
"researcherEntity": this.researcher | "researcherEntity": this.researcher | ||||
▲ Show 20 Lines • Show All 207 Lines • ▼ Show 20 Lines | |||||
// This function checks if the requirements of any autoresearch techs are met and if they are it researches them | // This function checks if the requirements of any autoresearch techs are met and if they are it researches them | ||||
TechnologyManager.prototype.UpdateAutoResearch = function() | TechnologyManager.prototype.UpdateAutoResearch = function() | ||||
{ | { | ||||
for (let key of this.unresearchedAutoResearchTechs) | for (let key of this.unresearchedAutoResearchTechs) | ||||
{ | { | ||||
let tech = TechnologyTemplates.Get(key); | let tech = TechnologyTemplates.Get(key); | ||||
if ((tech.autoResearch && this.CanResearch(key)) || | if ((tech.autoResearch && this.CanResearch(key)) || | ||||
(tech.top && (this.IsTechnologyResearched(tech.top) || this.IsTechnologyResearched(tech.bottom)))) | (tech.top && (this.IsTechnologyResearched(tech.top) || this.IsTechnologyResearched(tech.bottom)))) | ||||
{ | { | ||||
Freagarach: If it is a `ChoiceRoot`, check that, else check whether it can be researched. | |||||
this.unresearchedAutoResearchTechs.delete(key); | this.unresearchedAutoResearchTechs.delete(key); | ||||
this.ResearchTechnology(key); | this.ResearchTechnology(key); | ||||
return; // We will have recursively handled any knock-on effects so can just return | return; // We will have recursively handled any knock-on effects so can just return | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
// Checks an entity template to see if its technology requirements have been met | // Checks an entity template to see if its technology requirements have been met | ||||
▲ Show 20 Lines • Show All 279 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
If it is a ChoiceRoot, check that, else check whether it can be researched.