Ticket #4079: upgradeEntity.patch

File upgradeEntity.patch, 8.1 KB (added by s0600204, 8 years ago)

Proposed patch. Requires #3993 patch v4.1

  • 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..e461f29 100644
    a b function GetTemplateDataHelper(template, player, auraTemplates)  
    303303            ret.speed.run = getEntityValue("UnitMotion/Run/Speed");
    304304    }
    305305
     306    if (template.Upgrade)
     307    {
     308        ret.upgrades = [];
     309        for (let upKey in template.Upgrade)
     310        {
     311            let upgrade = {
     312                "name": upKey,
     313                "entity": template.Upgrade[upKey].Entity,
     314                "tooltip": template.Upgrade[upKey].Tooltip,
     315                "cost": {},
     316            };
     317
     318            for (let res in template.Upgrade[upKey].Cost)
     319                upgrade.cost[res] = getEntityValue("Upgrade/" + upKey + "/Cost/" + res);
     320
     321            if (template.Upgrade[upKey].Time)
     322                upgrade.cost.time = getEntityValue("Upgrade/" + upKey + "/Time");
     323
     324            if (template.Upgrade[upKey].Icon)
     325                upgrade.icon = template.Upgrade[upKey].Icon;
     326
     327            if (template.RequiredTechnology)
     328                upgrade.requiredTechnology = template.RequiredTechnology;
     329
     330            ret.upgrades.push(upgrade);
     331        }
     332    }
     333
    306334    if (template.ProductionQueue)
    307335    {
    308336        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 92c60ce..388b665 100644
    a b function draw()  
    8282                        p++;
    8383                    }
    8484
     85                if (stru.upgrades[prod_pha])
     86                    for (let upgrade of stru.upgrades[prod_pha])
     87                    {
     88                        if (!drawProdIcon(i, s, r, p, upgrade.data))
     89                            break;
     90                        p++;
     91                    }
     92
    8593                if (stru.wallset && prod_pha == pha)
    86                     for (let prod of [stru.wallset.gate, stru.wallset.tower])
     94                    for (let prod of [stru.wallset.tower])
    8795                    {
    8896                        if (!drawProdIcon(i, s, r, p, prod))
    8997                            break;
    function draw()  
    156164        thisEle.hidden = false;
    157165       
    158166        let p = 0;
    159         for (let prodType in trainer.production)
    160         {
    161             for (let prod of trainer.production[prodType])
     167        if (trainer.production)
     168            for (let prodType in trainer.production)
    162169            {
    163                 switch (prodType)
     170                for (let prod of trainer.production[prodType])
    164171                {
    165                 case "units":
    166                     prod = g_ParsedData.units[prod];
    167                     break;
    168                 case "techs":
    169                     prod = clone(g_ParsedData.techs[prod]);
    170                     for (let res in trainer.techCostMultiplier)
    171                         if (prod.cost[res])
    172                             prod.cost[res] *= trainer.techCostMultiplier[res];
    173                     break;
    174                 default:
    175                     continue;
     172                    switch (prodType)
     173                    {
     174                    case "units":
     175                        prod = g_ParsedData.units[prod];
     176                        break;
     177                    case "techs":
     178                        prod = clone(g_ParsedData.techs[prod]);
     179                        for (let res in trainer.techCostMultiplier)
     180                            if (prod.cost[res])
     181                                prod.cost[res] *= trainer.techCostMultiplier[res];
     182                        break;
     183                    default:
     184                        continue;
     185                    }
     186                    if (!drawProdIcon(null, t, null, p, prod))
     187                        break;
     188                    ++p;
    176189                }
    177                 if (!drawProdIcon(null, t, null, p, prod))
     190            }
     191        if (trainer.upgrades)
     192            for (let upgrade of trainer.upgrades)
     193            {
     194                if (!drawProdIcon(null, t, null, p, upgrade.data))
    178195                    break;
    179196                ++p;
    180197            }
    181         }
    182198        hideRemaining("trainer["+t+"]_prod[", p, "]");
    183199
    184200        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 8c7fe49..6653c0d 100644
    a b function fetchTokens(templateName, keypath)  
    9393}
    9494
    9595/**
     96 * Function is used to move attribute values from an Upgrade component
     97 * entry to its designated entity data object, overriding current values.
     98 */
     99function transferUpgradeData(from, to)
     100{
     101    to.cost = from.cost;
     102    to.icon = from.icon || to.icon;
     103    to.tooltip = from.tooltip || to.tooltip;
     104    to.requiredTechnology = from.requiredTechnology || to.requiredTechnology;
     105    return to;
     106}
     107
     108/**
    96109 * This is needed because getEntityCostTooltip in tooltip.js needs to get
    97110 * the template data of the different wallSet pieces. In the session this
    98111 * 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 79205ba..63ee899 100644
    a b function loadUnit(templateName)  
    7878                g_Lists.structures.push(build);
    7979        }
    8080
     81    if (unit.upgrades)
     82        for (let idx in unit.upgrades)
     83        {
     84            unit.upgrades[idx].entity = unit.upgrades[idx].entity.replace("{civ}", g_SelectedCiv);
     85
     86            let data = loadUnit(unit.upgrades[idx].entity);
     87            data = transferUpgradeData(unit.upgrades[idx], data);
     88            unit.upgrades[idx].data = data;
     89        }
     90
    8191    return unit;
    8292}
    8393
    function loadStructure(templateName)  
    111121            }
    112122    }
    113123
     124    if (structure.upgrades)
     125        for (let idx in structure.upgrades)
     126        {
     127            structure.upgrades[idx].entity = structure.upgrades[idx].entity.replace("{civ}", g_SelectedCiv);
     128
     129            let data = loadStructure(structure.upgrades[idx].entity);
     130            data = transferUpgradeData(structure.upgrades[idx], data);
     131            structure.upgrades[idx].data = data;
     132        }
     133
    114134    if (structure.wallSet)
    115135    {
    116136        structure.wallset = {};
    117137
     138        if (!structure.upgrades)
     139            structure.upgrades = [];
     140
    118141        // Note: Assume wall segments of all lengths have the same armor and auras
    119142        let struct = loadStructure(structure.wallSet.templates.long);
    120143        structure.armour = struct.armour;
    function loadStructure(templateName)  
    134157            for (let research of wPart.production.technology)
    135158                structure.production.technology.push(research);
    136159
     160            if (wPart.upgrades)
     161                structure.upgrades = structure.upgrades.concat(wPart.upgrades);
     162
    137163            if (["gate", "tower"].indexOf(wSegm) != -1)
    138164                continue;
    139165
  • 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 a254e3b..57f22e0 100644
    a b function selectCiv(civCode)  
    161161        }
    162162    }
    163163
    164     // Group production lists of structures by phase
     164    // Group production and upgrade lists of structures by phase
    165165    for (let structCode of g_Lists.structures)
    166166    {
    167167        let structInfo = g_ParsedData.structures[structCode];
    function selectCiv(civCode)  
    222222            "technology": newProdTech,
    223223            "units": newProdUnits
    224224        };
     225
     226        // Sort upgrades by phase
     227        let newUpgrades = {};
     228        if (structInfo.upgrades)
     229        {
     230            for (let upgrade of structInfo.upgrades)
     231            {
     232                let phase = GetPhaseOfTemplate(upgrade.data);
     233
     234                if (g_ParsedData.phaseList.indexOf(phase) < structPhaseIdx)
     235                    phase = structInfo.phase;
     236
     237                if (!(phase in newUpgrades))
     238                    newUpgrades[phase] = [];
     239                newUpgrades[phase].push(upgrade);
     240            }
     241        }
     242        g_ParsedData.structures[structCode].upgrades = newUpgrades;
    225243    }
    226244
    227245    // Determine the buildList for the civ (grouped by phase)
    function selectCiv(civCode)  
    234252        let phase = g_ParsedData.structures[structCode].phase;
    235253        buildList[phase].push(structCode);
    236254    }
     255
    237256    for (let unitCode of g_Lists.units)
    238         if (g_ParsedData.units[unitCode] && g_ParsedData.units[unitCode].production)
     257        if (g_ParsedData.units[unitCode] && (g_ParsedData.units[unitCode].production || g_ParsedData.units[unitCode].upgrades))
    239258            trainerList.push(unitCode);
    240259
    241260    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 53f0d01..aef15c3 100644
    a b  
    11<?xml version="1.0" encoding="utf-8"?>
    22<Entity parent="template_structure_defense_wall_long">
    33  <Auras disable=""/>
     4  <Cost disable=""/>
    45  <GarrisonHolder disable=""/>
    56  <Gate>
    67    <PassRange>20</PassRange>