Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/components/TechnologyManager.js
function TechnologyManager() {} | function TechnologyManager() {} | ||||
TechnologyManager.prototype.Schema = | TechnologyManager.prototype.Schema = | ||||
"<empty/>"; | "<empty/>"; | ||||
TechnologyManager.prototype.Update = function() { | |||||
warn("TechnologyManager.Update: not implemented"); | |||||
} | |||||
/** | /** | ||||
* This object represents a technology under research. | * This object represents a technology under research. | ||||
* @param {string} templateName - The name of the template to research. | * @param {string} templateName - The name of the template to research. | ||||
* @param {number} player - The player ID researching. | * @param {number} player - The player ID researching. | ||||
* @param {number} researcher - The entity ID researching. | * @param {number} researcher - The entity ID researching. | ||||
*/ | */ | ||||
TechnologyManager.prototype.Technology = function(templateName, player, researcher) | TechnologyManager.prototype.Technology = function(templateName, player, researcher) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 404 Lines • ▼ Show 20 Lines | if (!Engine.QueryInterface(msg.entity, IID_Foundation)) | ||||
if (this.typeCountsByClass[cls][template] <= 0) | if (this.typeCountsByClass[cls][template] <= 0) | ||||
delete this.typeCountsByClass[cls][template]; | delete this.typeCountsByClass[cls][template]; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
TechnologyManager.prototype.OnGlobalIdentityClassesChanged = function(msg) | |||||
{ | |||||
const playerID = (Engine.QueryInterface(this.entity, IID_Player)).GetPlayerID(); | |||||
const cmpOwnership = Engine.QueryInterface(msg.entity, IID_Ownership); | |||||
if (!cmpOwnership || cmpOwnership.GetOwner() != playerID) | |||||
return; | |||||
var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | |||||
var template = cmpTemplateManager.GetCurrentTemplateName(msg.entity); | |||||
// don't use foundations for the class counts but check if techs apply (e.g. health increase) | |||||
if (Engine.QueryInterface(msg.entity, IID_Foundation)) | |||||
return; | |||||
let oldClasses = msg.from; | |||||
let newClasses = msg.to; | |||||
// Add first so we don't delete the old class if it's the same as the new one | |||||
for (let cls of newClasses) | |||||
{ | |||||
this.classCounts[cls] = this.classCounts[cls] || 0; | |||||
this.classCounts[cls] += 1; | |||||
this.typeCountsByClass[cls] = this.typeCountsByClass[cls] || {}; | |||||
this.typeCountsByClass[cls][template] = this.typeCountsByClass[cls][template] || 0; | |||||
this.typeCountsByClass[cls][template] += 1; | |||||
} | |||||
for (let cls of oldClasses) | |||||
{ | |||||
this.classCounts[cls] -= 1; | |||||
if (this.classCounts[cls] <= 0) | |||||
delete this.classCounts[cls]; | |||||
this.typeCountsByClass[cls][template] -= 1; | |||||
if (this.typeCountsByClass[cls][template] <= 0) | |||||
delete this.typeCountsByClass[cls][template]; | |||||
} | |||||
}; | |||||
TechnologyManager.prototype.OnGlobalTemplateChanged = function(msg) | |||||
{ | |||||
const playerID = (Engine.QueryInterface(this.entity, IID_Player)).GetPlayerID(); | |||||
const cmpOwnership = Engine.QueryInterface(msg.entity, IID_Ownership); | |||||
if (!cmpOwnership || cmpOwnership.GetOwner() != playerID) | |||||
return; | |||||
// don't use foundations for the class counts but check if techs apply (e.g. health increase) | |||||
if (Engine.QueryInterface(msg.entity, IID_Foundation)) | |||||
return; | |||||
const cmpIdentity = Engine.QueryInterface(msg.entity, IID_Identity); | |||||
if (!cmpIdentity) | |||||
return; | |||||
// We assume that the Identity changes are handled above. | |||||
const classes = cmpIdentity.GetClassesList(); | |||||
// Add first so we don't delete the old class if it's the same as the new one | |||||
for (let cls of classes) | |||||
{ | |||||
this.typeCountsByClass[cls] = this.typeCountsByClass[cls] || {}; | |||||
this.typeCountsByClass[cls][msg.to] = this.typeCountsByClass[cls][msg.to] || 0; | |||||
this.typeCountsByClass[cls][msg.to] += 1; | |||||
} | |||||
for (let cls of classes) | |||||
{ | |||||
this.typeCountsByClass[cls][msg.from] -= 1; | |||||
if (this.typeCountsByClass[cls][msg.from] <= 0) | |||||
delete this.typeCountsByClass[cls][msg.from]; | |||||
} | |||||
}; | |||||
/** | /** | ||||
* This does neither apply effects nor verify requirements. | * This does neither apply effects nor verify requirements. | ||||
* @param {string} tech - The name of the technology to mark as researched. | * @param {string} tech - The name of the technology to mark as researched. | ||||
*/ | */ | ||||
TechnologyManager.prototype.MarkTechnologyAsResearched = function(tech) | TechnologyManager.prototype.MarkTechnologyAsResearched = function(tech) | ||||
{ | { | ||||
this.researchedTechs.add(tech); | this.researchedTechs.add(tech); | ||||
this.UpdateAutoResearch(); | this.UpdateAutoResearch(); | ||||
▲ Show 20 Lines • Show All 119 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator