Ticket #3747: 3747_alternate_v2.patch

File 3747_alternate_v2.patch, 9.5 KB (added by s0600204, 8 years ago)

Rebased, and requires v4 patch of #3993

  • binaries/data/mods/public/globalscripts/Technologies.js

    diff --git a/binaries/data/mods/public/globalscripts/Technologies.js b/binaries/data/mods/public/globalscripts/Technologies.js
    index ce75e28..4cf0b42 100644
    a b function GetTechModifiedProperty(currentTechModifications, classes, propertyName  
    4444}
    4545
    4646/**
     47 * Derives modifications (to be applied to entities) from a given technology
     48 *
     49 * @param techTemplate The technology template to derive the modifications from.
     50 * @return Object containing the relevant modifications.
     51 */
     52function DeriveModificationsFromTech(techTemplate)
     53{
     54    if (!techTemplate.modifications)
     55        return {};
     56
     57    let techMods = {};
     58    let techAffects = [];
     59    if (techTemplate.affects && techTemplate.affects.length)
     60        for (let affected of techTemplate.affects)
     61            techAffects.push(affected.split(/\s+/));
     62    else
     63        techAffects.push([]);
     64
     65    for (let mod of techTemplate.modifications)
     66    {
     67        let affects = techAffects.slice();
     68        if (mod.affects)
     69        {
     70            let specAffects = mod.affects.split(/\s+/);
     71            for (let a in affects)
     72                affects[a] = affects[a].concat(specAffects);
     73        }
     74
     75        let newModifier = {
     76            "affects": affects
     77        };
     78        for (let idx in mod)
     79            if (idx !== "value" && idx !== "affects")
     80                newModifier[idx] = mod[idx];
     81
     82        if (!techMods[mod.value])
     83            techMods[mod.value] = [];
     84        techMods[mod.value].push(newModifier);
     85    }
     86    return techMods;
     87}
     88
     89/**
    4790 * Returns whether the given modification applies to the entity containing the given class list
    4891 */
    4992function DoesModificationApply(modification, classes)
  • binaries/data/mods/public/globalscripts/Templates.js

    diff --git a/binaries/data/mods/public/globalscripts/Templates.js b/binaries/data/mods/public/globalscripts/Templates.js
    index 8f76311..e0a936c 100644
    a b function GetTemplateDataHelper(template, player, auraTemplates)  
    8686            current_value = current_value[property] || 0;
    8787        current_value = +current_value;
    8888
    89         if (!player)
    90             return current_value;
     89        if (player)
     90            return ApplyValueModificationsToTemplate(tech_type, current_value, player, template);
    9191
    92         return ApplyValueModificationsToTemplate(tech_type, current_value, player, template);
     92        if (typeof g_CurrentModifiers !== "undefined")
     93            return GetTechModifiedProperty(g_CurrentModifiers, GetIdentityClasses(template.Identity), tech_type, current_value);
     94
     95        return current_value;
    9396    };
    9497
    9598    let ret = {};
    function GetTemplateDataHelper(template, player, auraTemplates)  
    335338}
    336339
    337340/**
    338  * Get information about a technology template.
     341 * Get basic information about a technology template.
    339342 * @param template A valid template as obtained by loading the tech JSON file.
    340  * @param civ Civilization for which the specific name should be returned.
    341343 */
    342 function GetTechnologyDataHelper(template, civ)
     344function GetTechnologyBasicDataHelper(template)
    343345{
    344     var ret = {};
    345 
    346     // Get specific name for this civ or else the generic specific name
    347     var specific;
    348     if (template.specificName)
    349     {
    350         if (template.specificName[civ])
    351             specific = template.specificName[civ];
    352         else
    353             specific = template.specificName['generic'];
    354     }
     346    let ret = {};
    355347
    356348    ret.name = {
    357         "specific": specific,
    358349        "generic": template.genericName,
    359350    };
    360351
    361     ret.icon = template.icon ? "technologies/" + template.icon : null;
     352    if (template.icon)
     353        ret.icon = "technologies/" + template.icon;
     354    else
     355        ret.icon = null;
     356
     357    ret.description = template.description;
     358    ret.reqs = DeriveTechnologyRequirements(template);
     359
     360    return ret;
     361}
     362
     363/**
     364 * Get information about a technology template.
     365 * @param template A valid template as obtained by loading the tech JSON file.
     366 * @param civ Civilization for which the specific name should be returned.
     367 */
     368function GetTechnologyDataHelper(template, civ)
     369{
     370    let ret = GetTechnologyBasicDataHelper(template);
     371
     372    if (template.specificName)
     373        ret.name.specific = template.specificName[civ] || template.specificName.generic;
    362374
    363375    ret.cost = {
    364376        "food": template.cost ? +template.cost.food : 0,
    function GetTechnologyDataHelper(template, civ)  
    371383    ret.tooltip = template.tooltip;
    372384    ret.requirementsTooltip = template.requirementsTooltip || "";
    373385
    374     ret.reqs = DeriveTechnologyRequirements(template);
    375 
    376     ret.description = template.description;
    377 
    378386    return ret;
    379387}
  • binaries/data/mods/public/gui/structree/helper.js

    diff --git a/binaries/data/mods/public/gui/structree/helper.js b/binaries/data/mods/public/gui/structree/helper.js
    index 7d2f706..bc7180f 100644
    a b function loadTechData(templateName)  
    2424{
    2525    if (!(templateName in g_TechnologyData))
    2626    {
    27         var filename = "simulation/data/technologies/" + templateName + ".json";
    28         var data = Engine.ReadJSONFile(filename);
    29         translateObjectKeys(data, ["genericName", "tooltip"]);
    30        
     27        let filename = "simulation/data/technologies/" + templateName + ".json";
     28        let data = Engine.ReadJSONFile(filename);
     29        translateObjectKeys(data, ["genericName", "tooltip", "description"]);
     30
    3131        g_TechnologyData[templateName] = data;
    3232    }
    3333
    function loadAuraData(templateName)  
    4848    return g_AuraData[templateName];
    4949}
    5050
     51function loadAllAutoResearchedTechs()
     52{
     53    let path = "simulation/data/technologies/";
     54    let techFiles = Engine.BuildDirEntList(path, "*.json", true);
     55
     56    for (let filename of techFiles)
     57    {
     58        let templateName = filename.slice(path.length, -5);
     59        let data = loadTechData(templateName);
     60
     61        if (!data || !data.autoResearch)
     62            continue;
     63
     64        let tech = GetTechnologyBasicDataHelper(data);
     65
     66        tech.modifications = data.modifications;
     67        tech.affects = data.affects;
     68
     69        g_ParsedData.modifiers[templateName] = tech;
     70    }
     71}
     72
    5173/**
    5274 * Fetch a value from an entity's template
    5375 *
  • binaries/data/mods/public/gui/structree/structree.js

    diff --git a/binaries/data/mods/public/gui/structree/structree.js b/binaries/data/mods/public/gui/structree/structree.js
    index 1415022..509ffce 100644
    a b var g_ParsedData = {  
    22    "units": {},
    33    "structures": {},
    44    "techs": {},
    5     "phases": {}
     5    "phases": {},
     6    "modifiers": {}
    67};
    78
    89var g_Lists = {};
    910var g_CivData = {};
    1011var g_SelectedCiv = "";
     12var g_CurrentModifiers = {};
    1113var g_CallbackSet = false;
    1214
    1315/**
    function init(data = {})  
    2527    if (!civList.length)
    2628        return;
    2729
     30    loadAllAutoResearchedTechs();
     31
    2832    var civSelection = Engine.GetGUIObjectByName("civSelection");
    2933    civSelection.list = civList.map(c => c.name);
    3034    civSelection.list_data = civList.map(c => c.code);
    function selectCiv(civCode)  
    5559        return;
    5660    }
    5761
     62    // Derive modifications
     63    g_CurrentModifiers = {};
     64    for (let modifier in g_ParsedData.modifiers)
     65    {
     66        modifier = g_ParsedData.modifiers[modifier];
     67        if (modifier.reqs && !modifier.reqs[g_SelectedCiv])
     68            continue;
     69
     70        let derivedModifiers = DeriveModificationsFromTech(modifier);
     71        for (let modPath in derivedModifiers)
     72        {
     73            if (!g_CurrentModifiers[modPath])
     74                g_CurrentModifiers[modPath] = [];
     75            g_CurrentModifiers[modPath] = g_CurrentModifiers[modPath].concat(derivedModifiers[modPath]);
     76        }
     77    }
     78
    5879    g_Lists = {
    5980        "units": [],
    6081        "structures": [],
  • binaries/data/mods/public/simulation/components/TechnologyManager.js

    diff --git a/binaries/data/mods/public/simulation/components/TechnologyManager.js b/binaries/data/mods/public/simulation/components/TechnologyManager.js
    index 610e3bc..f190ee9 100644
    a b TechnologyManager.prototype.ResearchTechnology = function(tech)  
    264264    // store the modifications in an easy to access structure
    265265    if (template.modifications)
    266266    {
    267         var affects = [];
    268         if (template.affects && template.affects.length > 0)
     267        let derivedModifiers = DeriveModificationsFromTech(template);
     268        for (let modifierPath in derivedModifiers)
    269269        {
    270             for (let affect of template.affects)
    271             {
    272                 // Put the list of classes into an array for convenient access
    273                 affects.push(affect.split(/\s+/));
    274             }
    275         }
    276         else
    277         {
    278             affects.push([]);
    279         }
    280 
    281         // We add an item to this.modifications for every modification in the template.modifications array
    282         for (var i in template.modifications)
    283         {
    284             var modification = template.modifications[i];
    285             if (!this.modifications[modification.value])
    286                 this.modifications[modification.value] = [];
    287            
    288             var modAffects = affects.slice();
    289             if (modification.affects)
    290             {
    291                 var extraAffects = modification.affects.split(/\s+/);
    292                 for (var a in modAffects)
    293                     modAffects[a] = modAffects[a].concat(extraAffects);
    294             }
    295 
    296             var mod = {"affects": modAffects};
    297 
    298             // copy the modification data into our new data structure
    299             for (var j in modification)
    300                 if (j !== "value" && j !== "affects")
    301                     mod[j] = modification[j];
     270            if (!this.modifications[modifierPath])
     271                this.modifications[modifierPath] = [];
     272            this.modifications[modifierPath] = this.modifications[modifierPath].concat(derivedModifiers[modifierPath]);
    302273
    303             this.modifications[modification.value].push(mod);
    304             var component = modification.value.split("/")[0];
     274            let component = modifierPath.split("/")[0];
    305275            if (!modifiedComponents[component])
    306276                modifiedComponents[component] = [];
    307             modifiedComponents[component].push(modification.value);
    308             this.modificationCache[modification.value] = {};
     277            modifiedComponents[component].push(modifierPath);
     278            this.modificationCache[modifierPath] = {};
    309279        }
    310280    }
    311281