Differential D1109 Diff 4640 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 34 Lines | this.modificationCache = {}; // Caches the values after technologies have been applied | ||||
// where 5 and 7 are entity id's | // where 5 and 7 are entity id's | ||||
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.autoResearchTech = {}; | this.unresearchedAutoResearchTechs = new Set(); | ||||
var allTechs = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager).GetAllTechs(); | var allTechs = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager).GetAllTechs(); | ||||
for (var key in allTechs) | for (var key in allTechs) | ||||
{ | |||||
if (allTechs[key].autoResearch || allTechs[key].top) | if (allTechs[key].autoResearch || allTechs[key].top) | ||||
this.autoResearchTech[key] = allTechs[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); | var cmpDataTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager); | ||||
for (var key in this.autoResearchTech) | for (let key of this.unresearchedAutoResearchTechs) | ||||
{ | { | ||||
var tech = cmpDataTempMan.GetTechnologyTemplate(key); | var tech = cmpDataTempMan.GetTechnologyTemplate(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)))) | ||||
{ | { | ||||
delete this.autoResearchTech[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) | TechnologyManager.prototype.GetTechnologyTemplate = function(tech) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 409 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator