Differential D1108 Diff 5010 ps/trunk/binaries/data/mods/public/simulation/components/TechnologyManager.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/TechnologyManager.js
Show All 40 Lines | TechnologyManager.prototype.Init = function() | ||||
this.classCounts = {}; // stores the number of entities of each Class | this.classCounts = {}; // stores the number of entities of each Class | ||||
this.typeCountsByClass = {}; // stores the number of entities of each type for each class i.e. | this.typeCountsByClass = {}; // stores the number of entities of each type for each class i.e. | ||||
// {"someClass": {"unit/spearman": 2, "unit/cav": 5} "someOtherClass":...} | // {"someClass": {"unit/spearman": 2, "unit/cav": 5} "someOtherClass":...} | ||||
// Some technologies are automatically researched when their conditions are met. They have no cost and are | // Some technologies are automatically researched when their conditions are met. They have no cost and are | ||||
// researched instantly. This allows civ bonuses and more complicated technologies. | // researched instantly. This allows civ bonuses and more complicated technologies. | ||||
this.unresearchedAutoResearchTechs = new Set(); | this.unresearchedAutoResearchTechs = new Set(); | ||||
var allTechs = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager).GetAllTechs(); | let allTechs = TechnologyTemplates.GetAll(); | ||||
for (var key in allTechs) | for (let key in allTechs) | ||||
if (allTechs[key].autoResearch || allTechs[key].top) | if (allTechs[key].autoResearch || allTechs[key].top) | ||||
this.unresearchedAutoResearchTechs.add(key); | this.unresearchedAutoResearchTechs.add(key); | ||||
}; | }; | ||||
TechnologyManager.prototype.OnUpdate = function() | TechnologyManager.prototype.OnUpdate = function() | ||||
{ | { | ||||
this.UpdateAutoResearch(); | this.UpdateAutoResearch(); | ||||
}; | }; | ||||
// 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() | ||||
{ | { | ||||
var cmpDataTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager); | |||||
for (let key of this.unresearchedAutoResearchTechs) | for (let key of this.unresearchedAutoResearchTechs) | ||||
{ | { | ||||
var tech = cmpDataTempMan.GetTechnologyTemplate(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)))) | ||||
{ | { | ||||
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 | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
TechnologyManager.prototype.GetTechnologyTemplate = function(tech) | |||||
{ | |||||
return Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager).GetTechnologyTemplate(tech); | |||||
}; | |||||
// 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 | ||||
TechnologyManager.prototype.CanProduce = function (templateName) | TechnologyManager.prototype.CanProduce = function (templateName) | ||||
{ | { | ||||
var cmpTempManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | var cmpTempManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | ||||
var template = cmpTempManager.GetTemplate(templateName); | var template = cmpTempManager.GetTemplate(templateName); | ||||
if (template.Identity && template.Identity.RequiredTechnology) | if (template.Identity && template.Identity.RequiredTechnology) | ||||
return this.IsTechnologyResearched(template.Identity.RequiredTechnology); | return this.IsTechnologyResearched(template.Identity.RequiredTechnology); | ||||
Show All 14 Lines | |||||
TechnologyManager.prototype.IsTechnologyStarted = function(tech) | TechnologyManager.prototype.IsTechnologyStarted = function(tech) | ||||
{ | { | ||||
return this.researchStarted.has(tech); | return this.researchStarted.has(tech); | ||||
}; | }; | ||||
// Checks the requirements for a technology to see if it can be researched at the current time | // Checks the requirements for a technology to see if it can be researched at the current time | ||||
TechnologyManager.prototype.CanResearch = function(tech) | TechnologyManager.prototype.CanResearch = function(tech) | ||||
{ | { | ||||
let template = this.GetTechnologyTemplate(tech); | let template = TechnologyTemplates.Get(tech); | ||||
if (!template) | if (!template) | ||||
{ | { | ||||
warn("Technology \"" + tech + "\" does not exist"); | warn("Technology \"" + tech + "\" does not exist"); | ||||
return false; | return false; | ||||
} | } | ||||
if (template.top && this.IsInProgress(template.top) || | if (template.top && this.IsInProgress(template.top) || | ||||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | TechnologyManager.prototype.OnGlobalOwnershipChanged = function(msg) | ||||
} | } | ||||
}; | }; | ||||
// Marks a technology as researched. Note that this does not verify that the requirements are met. | // Marks a technology as researched. Note that this does not verify that the requirements are met. | ||||
TechnologyManager.prototype.ResearchTechnology = function(tech) | TechnologyManager.prototype.ResearchTechnology = function(tech) | ||||
{ | { | ||||
this.StoppedResearch(tech, false); | this.StoppedResearch(tech, false); | ||||
var template = this.GetTechnologyTemplate(tech); | |||||
if (!template) | |||||
{ | |||||
error("Tried to research invalid technology: " + uneval(tech)); | |||||
return; | |||||
} | |||||
var modifiedComponents = {}; | var modifiedComponents = {}; | ||||
this.researchedTechs.add(tech); | this.researchedTechs.add(tech); | ||||
// store the modifications in an easy to access structure | // store the modifications in an easy to access structure | ||||
let template = TechnologyTemplates.Get(tech); | |||||
if (template.modifications) | if (template.modifications) | ||||
{ | { | ||||
let derivedModifiers = DeriveModificationsFromTech(template); | let derivedModifiers = DeriveModificationsFromTech(template); | ||||
for (let modifierPath in derivedModifiers) | for (let modifierPath in derivedModifiers) | ||||
{ | { | ||||
if (!this.modifications[modifierPath]) | if (!this.modifications[modifierPath]) | ||||
this.modifications[modifierPath] = []; | this.modifications[modifierPath] = []; | ||||
this.modifications[modifierPath] = this.modifications[modifierPath].concat(derivedModifiers[modifierPath]); | this.modifications[modifierPath] = this.modifications[modifierPath].concat(derivedModifiers[modifierPath]); | ||||
▲ Show 20 Lines • Show All 203 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator