Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/globalscripts/Technologies.js
/** | /** | ||||
* This file contains shared logic for applying tech modifications in GUI, AI, | * This file contains shared logic for applying tech modifications in GUI, AI, | ||||
* and simulation scripts. As such it must be fully deterministic and not store | * and simulation scripts. As such it must be fully deterministic and not store | ||||
* any global state, but each context should do its own caching as needed. | * any global state, but each context should do its own caching as needed. | ||||
* Also it cannot directly access the simulation and requires data passed to it. | * Also it cannot directly access the simulation and requires data passed to it. | ||||
*/ | */ | ||||
/** | /** | ||||
* Returns modified property value modified by the applicable tech | * Returns modified property value modified by the applicable tech | ||||
* modifications. | * modifications. | ||||
* | * | ||||
* @param currentTechModifications Object with mapping of property names to | * @param currentTechModifications array of modificiations | ||||
* modification arrays, retrieved from the intended player's TechnologyManager. | * @param classes Array containing the class list of the template. | ||||
* @param classes Array contianing the class list of the template. | * @param originalValue Number storing the original value. Can also be | ||||
* @param propertyName String encoding the name of the value. | |||||
* @param propertyValue Number storing the original value. Can also be | |||||
* non-numberic, but then only "replace" techs can be supported. | * non-numberic, but then only "replace" techs can be supported. | ||||
*/ | */ | ||||
function GetTechModifiedProperty(currentTechModifications, classes, propertyName, propertyValue) | function GetTechModifiedProperty(modifications, classes, originalValue) | ||||
{ | { | ||||
let modifications = currentTechModifications[propertyName] || []; | |||||
let multiply = 1; | let multiply = 1; | ||||
let add = 0; | let add = 0; | ||||
for (let modification of modifications) | for (let modification of modifications) | ||||
{ | { | ||||
if (!DoesModificationApply(modification, classes)) | if (!DoesModificationApply(modification, classes)) | ||||
continue; | continue; | ||||
if (modification.replace !== undefined) | if (modification.replace !== undefined) | ||||
return modification.replace; | return modification.replace; | ||||
if (modification.multiply) | if (modification.multiply) | ||||
multiply *= modification.multiply; | multiply *= modification.multiply; | ||||
else if (modification.add) | else if (modification.add) | ||||
add += modification.add; | add += modification.add; | ||||
else | else | ||||
warn("GetTechModifiedProperty: modification format not recognised (modifying " + propertyName + "): " + uneval(modification)); | warn("GetTechModifiedProperty: modification format not recognised!: " + uneval(modification)); | ||||
Stan: Something wrong here ? | |||||
wraitiiAuthorUnsubmitted Done Inline ActionsThink I had a non-breaking space there. wraitii: Think I had a non-breaking space there. | |||||
} | } | ||||
// Note, some components pass non-numeric values (for which only the "replace" modification makes sense) | // Note, some components pass non-numeric values (for which only the "replace" modification makes sense) | ||||
if (typeof propertyValue == "number") | if (typeof originalValue == "number") | ||||
return propertyValue * multiply + add; | return originalValue * multiply + add; | ||||
return propertyValue; | return originalValue; | ||||
StanUnsubmitted Not Done Inline ActionsTernary ? Stan: Ternary ? | |||||
} | } | ||||
/** | /** | ||||
* Derives modifications (to be applied to entities) from a given technology. | * Derives modifications (to be applied to entities) from a given technology. | ||||
* | * | ||||
* @param {Object} techTemplate - The technology template to derive the modifications from. | * @param {Object} techTemplate - The technology template to derive the modifications from. | ||||
* @return {Object} containing the relevant modifications. | * @return {Object} containing the relevant modifications. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 335 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Something wrong here ?