Ticket #4079: upgradeEntity_v2.patch

File upgradeEntity_v2.patch, 8.4 KB (added by s0600204, 7 years ago)

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

  • 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..19832ba94 100644
    a b function GetTemplateDataHelper(template, player, auraTemplates, resources)  
    312312            ret.speed.run = getEntityValue("UnitMotion/Run/Speed");
    313313    }
    314314
     315    if (template.Upgrade)
     316    {
     317        ret.upgrades = [];
     318        for (let upKey in template.Upgrade)
     319        {
     320            let upgrade = {
     321                "name": upKey,
     322                "entity": template.Upgrade[upKey].Entity,
     323                "tooltip": template.Upgrade[upKey].Tooltip,
     324                "cost": {},
     325            };
     326
     327            for (let res in template.Upgrade[upKey].Cost)
     328                upgrade.cost[res] = getEntityValue("Upgrade/" + upKey + "/Cost/" + res);
     329
     330            if (template.Upgrade[upKey].Time)
     331                upgrade.cost.time = getEntityValue("Upgrade/" + upKey + "/Time");
     332
     333            if (template.Upgrade[upKey].Icon)
     334                upgrade.icon = template.Upgrade[upKey].Icon;
     335
     336            if (template.RequiredTechnology)
     337                upgrade.requiredTechnology = template.RequiredTechnology;
     338
     339            ret.upgrades.push(upgrade);
     340        }
     341    }
     342
    315343    if (template.ProductionQueue)
    316344    {
    317345        ret.techCostMultiplier = {};
  • binaries/data/mods/public/gui/structree/draw.js

    diff --git a/binaries/data/mods/public/gui/structree/draw.js b/binaries/data/mods/public/gui/structree/draw.js
    index 44be50783..91a96e0f7 100644
    a b function draw()  
    8383                        prod = g_ParsedData.units[prod];
    8484                        if (!drawProdIcon(i, s, r, p, prod))
    8585                            break;
    86                         p++;
     86                        ++p;
     87                    }
     88
     89                if (stru.upgrades[prod_pha])
     90                    for (let upgrade of stru.upgrades[prod_pha])
     91                    {
     92                        if (!drawProdIcon(i, s, r, p, upgrade.data))
     93                            break;
     94                        ++p;
    8795                    }
    8896
    8997                if (stru.wallset && prod_pha == pha)
    90                     for (let prod of [stru.wallset.gate, stru.wallset.tower])
     98                    for (let prod of [stru.wallset.tower])
    9199                    {
    92100                        if (!drawProdIcon(i, s, r, p, prod))
    93101                            break;
    94                         p++;
     102                        ++p;
    95103                    }
    96104
    97105                if (stru.production.technology[prod_pha])
    function draw()  
    173181        thisEle.hidden = false;
    174182
    175183        let p = 0;
    176         for (let prodType in trainer.production)
    177         {
    178             for (let prod of trainer.production[prodType])
     184        if (trainer.production)
     185            for (let prodType in trainer.production)
    179186            {
    180                 switch (prodType)
     187                for (let prod of trainer.production[prodType])
    181188                {
    182                 case "units":
    183                     prod = g_ParsedData.units[prod];
    184                     break;
    185                 case "techs":
    186                     prod = clone(g_ParsedData.techs[civCode][prod]);
    187                     for (let res in trainer.techCostMultiplier)
    188                         if (prod.cost[res])
    189                             prod.cost[res] *= trainer.techCostMultiplier[res];
    190                     break;
    191                 default:
    192                     continue;
     189                    switch (prodType)
     190                    {
     191                    case "units":
     192                        prod = g_ParsedData.units[prod];
     193                        break;
     194                    case "techs":
     195                        prod = clone(g_ParsedData.techs[civCode][prod]);
     196                        for (let res in trainer.techCostMultiplier)
     197                            if (prod.cost[res])
     198                                prod.cost[res] *= trainer.techCostMultiplier[res];
     199                        break;
     200                    default:
     201                        continue;
     202                    }
     203                    if (!drawProdIcon(null, t, null, p, prod))
     204                        break;
     205                    ++p;
    193206                }
    194                 if (!drawProdIcon(null, t, null, p, prod))
     207            }
     208        if (trainer.upgrades)
     209            for (let upgrade of trainer.upgrades)
     210            {
     211                if (!drawProdIcon(null, t, null, p, upgrade.data))
    195212                    break;
    196213                ++p;
    197214            }
    198         }
    199215        hideRemaining("trainer["+t+"]_row", p);
    200216
    201217        let size = thisEle.size;
  • 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..f5f68afea 100644
    a b function loadAuraData(templateName)  
    4949}
    5050
    5151/**
     52 * Function is used to move attribute values from an Upgrade component
     53 * entry to its designated entity data object, overriding current values.
     54 */
     55function transferUpgradeData(from, to)
     56{
     57    to.cost = from.cost;
     58    to.icon = from.icon || to.icon;
     59    to.tooltip = from.tooltip || to.tooltip;
     60    to.requiredTechnology = from.requiredTechnology || to.requiredTechnology;
     61    return to;
     62}
     63
     64/**
    5265 * This is needed because getEntityCostTooltip in tooltip.js needs to get
    5366 * the template data of the different wallSet pieces. In the session this
    5467 * function does some caching, but here we do that in loadTemplate already.
  • binaries/data/mods/public/gui/structree/load.js

    diff --git a/binaries/data/mods/public/gui/structree/load.js b/binaries/data/mods/public/gui/structree/load.js
    index 2d6b58b77..6b041eb15 100644
    a b function loadUnit(templateName)  
    4040                g_Lists.structures.push(build);
    4141        }
    4242
     43    if (unit.upgrades)
     44        for (let idx in unit.upgrades)
     45        {
     46            unit.upgrades[idx].entity = unit.upgrades[idx].entity.replace("{civ}", g_SelectedCiv);
     47
     48            let data = loadUnit(unit.upgrades[idx].entity);
     49            data = transferUpgradeData(unit.upgrades[idx], data);
     50            unit.upgrades[idx].data = data;
     51        }
     52
    4353    return unit;
    4454}
    4555
    function loadStructure(templateName)  
    7383            }
    7484    }
    7585
     86    if (structure.upgrades)
     87        for (let idx in structure.upgrades)
     88        {
     89            structure.upgrades[idx].entity = structure.upgrades[idx].entity.replace("{civ}", g_SelectedCiv);
     90
     91            let data = loadStructure(structure.upgrades[idx].entity);
     92            data = transferUpgradeData(structure.upgrades[idx], data);
     93            structure.upgrades[idx].data = data;
     94        }
     95
    7696    if (structure.wallSet)
    7797    {
    7898        structure.wallset = {};
    7999
     100        if (!structure.upgrades)
     101            structure.upgrades = [];
     102
    80103        // Note: Assume wall segments of all lengths have the same armor and auras
    81104        let struct = loadStructure(structure.wallSet.templates.long);
    82105        structure.armour = struct.armour;
    function loadStructure(templateName)  
    96119            for (let research of wPart.production.technology)
    97120                structure.production.technology.push(research);
    98121
     122            if (wPart.upgrades)
     123                structure.upgrades = structure.upgrades.concat(wPart.upgrades);
     124
    99125            if (["gate", "tower"].indexOf(wSegm) != -1)
    100126                continue;
    101127
  • 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..8e65d09a3 100644
    a b function selectCiv(civCode)  
    171171        }
    172172    }
    173173
    174     // Group production lists of structures by phase
     174    // Group production and upgrade lists of structures by phase
    175175    for (let structCode of g_Lists.structures)
    176176    {
    177177        let structInfo = g_ParsedData.structures[structCode];
    function selectCiv(civCode)  
    232232            "technology": newProdTech,
    233233            "units": newProdUnits
    234234        };
     235
     236        // Sort upgrades by phase
     237        let newUpgrades = {};
     238        if (structInfo.upgrades)
     239            for (let upgrade of structInfo.upgrades)
     240            {
     241                let phase = GetPhaseOfTemplate(upgrade.data);
     242
     243                if (g_ParsedData.phaseList.indexOf(phase) < structPhaseIdx)
     244                    phase = structInfo.phase;
     245
     246                if (!newUpgrades[phase])
     247                    newUpgrades[phase] = [];
     248                newUpgrades[phase].push(upgrade);
     249            }
     250        g_ParsedData.structures[structCode].upgrades = newUpgrades;
    235251    }
    236252
    237253    // Determine the buildList for the civ (grouped by phase)
    function selectCiv(civCode)  
    244260        let phase = g_ParsedData.structures[structCode].phase;
    245261        buildList[phase].push(structCode);
    246262    }
     263
    247264    for (let unitCode of g_Lists.units)
    248         if (g_ParsedData.units[unitCode] && g_ParsedData.units[unitCode].production)
     265        if (g_ParsedData.units[unitCode] && (g_ParsedData.units[unitCode].production || g_ParsedData.units[unitCode].upgrades))
    249266            trainerList.push(unitCode);
    250267
    251268    g_CivData[g_SelectedCiv].buildList = buildList;
  • binaries/data/mods/public/simulation/templates/template_structure_defense_wall_gate.xml

    diff --git a/binaries/data/mods/public/simulation/templates/template_structure_defense_wall_gate.xml b/binaries/data/mods/public/simulation/templates/template_structure_defense_wall_gate.xml
    index 60de615b3..d66e26df7 100644
    a b  
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_structure_defense_wall_long">
    33  <Auras disable=""/>
     4  <Cost>
     5    <Resources>
     6      <stone>0</stone>
     7    </Resources>
     8  </Cost>
    49  <GarrisonHolder disable=""/>
    510  <Gate>
    611    <PassRange>20</PassRange>