Ticket #3747: 3747_alternate_v3.patch

File 3747_alternate_v3.patch, 10.2 KB (added by s0600204, 7 years ago)

Rebase after Tech Reqs work (#4263) was merged into main trunk

  • 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 8361d0630..a1f60ed84 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 db54ca469..4374e8041 100644
    a b function GetTemplateDataHelper(template, player, auraTemplates, resources)  
    8787            current_value = current_value[property] || 0;
    8888        current_value = +current_value;
    8989
    90         if (!player)
    91             return current_value;
     90        if (player)
     91            return ApplyValueModificationsToTemplate(tech_type, current_value, player, template);
    9292
    93         return ApplyValueModificationsToTemplate(tech_type, current_value, player, template);
     93        if (typeof g_CurrentModifiers !== "undefined")
     94            return GetTechModifiedProperty(g_CurrentModifiers, GetIdentityClasses(template.Identity), tech_type, current_value);
     95
     96        return current_value;
    9497    };
    9598
    9699    let ret = {};
    function GetTemplateDataHelper(template, player, auraTemplates, resources)  
    298301            "generic": template.Identity.GenericName
    299302        };
    300303        ret.icon = template.Identity.Icon;
    301         ret.tooltip =  template.Identity.Tooltip;
     304        ret.tooltip = template.Identity.Tooltip;
    302305        ret.requiredTechnology = template.Identity.RequiredTechnology;
    303306        ret.visibleIdentityClasses = GetVisibleIdentityClasses(template.Identity);
    304307    }
    function GetTemplateDataHelper(template, player, auraTemplates, resources)  
    344347}
    345348
    346349/**
    347  * Get information about a technology template.
     350 * Get basic information about a technology template.
    348351 * @param template A valid template as obtained by loading the tech JSON file.
    349  * @param civ Civilization for which the specific name should be returned.
    350  * @param resources An instance of the Resources prototype.
    351352 */
    352 function GetTechnologyDataHelper(template, civ, resources)
     353function GetTechnologyBasicDataHelper(template, civ)
    353354{
    354355    let ret = {};
    355356
    356     // Get specific name for this civ or else the generic specific name
    357     let specific;
    358     if (template.specificName)
    359         specific = template.specificName[civ] || template.specificName.generic;
    360 
    361357    ret.name = {
    362         "specific": specific,
    363358        "generic": template.genericName,
    364359    };
    365360
    366     ret.icon = template.icon ? "technologies/" + template.icon : null;
     361    if (template.icon)
     362        ret.icon = "technologies/" + template.icon;
     363    else
     364        ret.icon = null;
     365
     366    ret.description = template.description;
     367    ret.reqs = DeriveTechnologyRequirements(template, civ);
     368
     369    return ret;
     370}
     371
     372/**
     373 * Get information about a technology template.
     374 * @param template A valid template as obtained by loading the tech JSON file.
     375 * @param civ Civilization for which the specific name should be returned.
     376 */
     377function GetTechnologyDataHelper(template, civ, resources)
     378{
     379    let ret = GetTechnologyBasicDataHelper(template, civ);
     380
     381    if (template.specificName)
     382        ret.name.specific = template.specificName[civ] || template.specificName.generic;
    367383
    368384    ret.cost = { "time": template.researchTime ? +template.researchTime : 0 };
    369385    for (let type of resources.GetCodes())
    function GetTechnologyDataHelper(template, civ, resources)  
    372388    ret.tooltip = template.tooltip;
    373389    ret.requirementsTooltip = template.requirementsTooltip || "";
    374390
    375     ret.reqs = DeriveTechnologyRequirements(template, civ);
    376 
    377     ret.description = template.description;
    378 
    379391    return ret;
    380392}
    381393
  • 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 da01b79e1..ca2c3dbb7 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"]);
     27        let filename = "simulation/data/technologies/" + templateName + ".json";
     28        let data = Engine.ReadJSONFile(filename);
     29        translateObjectKeys(data, ["genericName", "tooltip", "description"]);
    3030
    3131        g_TechnologyData[templateName] = data;
    3232    }
    function loadAuraData(templateName)  
    4848    return g_AuraData[templateName];
    4949}
    5050
     51function findAllAutoResearchedTechs()
     52{
     53    let path = "simulation/data/technologies/";
     54    let techFiles = Engine.BuildDirEntList(path, "*.json", true);
     55    let techList = [];
     56
     57    for (let filename of techFiles)
     58    {
     59        let templateName = filename.slice(path.length, -5);
     60        let data = loadTechData(templateName);
     61
     62        if (!data || !data.autoResearch)
     63            continue;
     64
     65        techList.push(templateName);
     66    }
     67
     68    return techList;
     69}
     70
     71function deriveCurrentModifications()
     72{
     73    g_CurrentModifiers = {};
     74    for (let templateName of g_AutoResearchTechList)
     75    {
     76        let data = loadTechData(templateName);
     77        let modifier = GetTechnologyBasicDataHelper(data, g_SelectedCiv);
     78
     79        if (!modifier.reqs)
     80            continue;
     81
     82        modifier.modifications = data.modifications;
     83        modifier.affects = data.affects;
     84
     85        let derivedModifiers = DeriveModificationsFromTech(modifier);
     86        for (let modPath in derivedModifiers)
     87        {
     88            if (!g_CurrentModifiers[modPath])
     89                g_CurrentModifiers[modPath] = [];
     90            g_CurrentModifiers[modPath] = g_CurrentModifiers[modPath].concat(derivedModifiers[modPath]);
     91        }
     92    }
     93}
     94
    5195/**
    5296 * This is needed because getEntityCostTooltip in tooltip.js needs to get
    5397 * the template data of the different wallSet pieces. In the session this
  • 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 20f20fdcb..a79f480e5 100644
    a b var g_ParsedData = {  
    88var g_Lists = {};
    99var g_CivData = {};
    1010var g_SelectedCiv = "";
     11var g_CurrentModifiers = {};
    1112var g_CallbackSet = false;
    1213var g_ResourceData = new Resources();
     14var g_AutoResearchTechList = [];
    1315
    1416/**
    1517 * Initialize the dropdown containing all the available civs
    function init(data = {})  
    2628    if (!civList.length)
    2729        return;
    2830
     31    g_AutoResearchTechList = findAllAutoResearchedTechs();
     32
    2933    var civSelection = Engine.GetGUIObjectByName("civSelection");
    3034    civSelection.list = civList.map(c => c.name);
    3135    civSelection.list_data = civList.map(c => c.code);
    function selectCiv(civCode)  
    5660        return;
    5761    }
    5862
     63    deriveCurrentModifications();
     64
    5965    g_Lists = {
    6066        "units": [],
    6167        "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 33a372df6..356864313 100644
    a b TechnologyManager.prototype.ResearchTechnology = function(tech)  
    270270    // store the modifications in an easy to access structure
    271271    if (template.modifications)
    272272    {
    273         var affects = [];
    274         if (template.affects && template.affects.length > 0)
     273        let derivedModifiers = DeriveModificationsFromTech(template);
     274        for (let modifierPath in derivedModifiers)
    275275        {
    276             for (let affect of template.affects)
    277             {
    278                 // Put the list of classes into an array for convenient access
    279                 affects.push(affect.split(/\s+/));
    280             }
    281         }
    282         else
    283         {
    284             affects.push([]);
    285         }
    286 
    287         // We add an item to this.modifications for every modification in the template.modifications array
    288         for (var i in template.modifications)
    289         {
    290             var modification = template.modifications[i];
    291             if (!this.modifications[modification.value])
    292                 this.modifications[modification.value] = [];
    293 
    294             var modAffects = affects.slice();
    295             if (modification.affects)
    296             {
    297                 var extraAffects = modification.affects.split(/\s+/);
    298                 for (var a in modAffects)
    299                     modAffects[a] = modAffects[a].concat(extraAffects);
    300             }
    301 
    302             var mod = {"affects": modAffects};
    303 
    304             // copy the modification data into our new data structure
    305             for (var j in modification)
    306                 if (j !== "value" && j !== "affects")
    307                     mod[j] = modification[j];
     276            if (!this.modifications[modifierPath])
     277                this.modifications[modifierPath] = [];
     278            this.modifications[modifierPath] = this.modifications[modifierPath].concat(derivedModifiers[modifierPath]);
    308279
    309             this.modifications[modification.value].push(mod);
    310             var component = modification.value.split("/")[0];
     280            let component = modifierPath.split("/")[0];
    311281            if (!modifiedComponents[component])
    312282                modifiedComponents[component] = [];
    313             modifiedComponents[component].push(modification.value);
    314             this.modificationCache[modification.value] = {};
     283            modifiedComponents[component].push(modifierPath);
     284            this.modificationCache[modifierPath] = {};
    315285        }
    316286    }
    317287