1
0
forked from mirrors/0ad

Show entity upgrades in the Structure Tree

Reviewed By: bb
Trac Tickets: #4079
Differential Revision: https://code.wildfiregames.com/D92
This was SVN commit r19600.
This commit is contained in:
s0600204
2017-05-17 18:41:23 +00:00
parent 15e2b42525
commit df89091c48
6 changed files with 122 additions and 27 deletions
@@ -360,6 +360,29 @@ function GetTemplateDataHelper(template, player, auraTemplates, resources, modif
ret.speed.run = getEntityValue("UnitMotion/Run/Speed");
}
if (template.Upgrade)
{
ret.upgrades = [];
for (let upgradeName in template.Upgrade)
{
let upgrade = template.Upgrade[upgradeName];
let cost = {};
for (let res in upgrade.Cost)
cost[res] = getEntityValue("Upgrade/" + upgradeName + "/Cost/" + res, "Upgrade/Cost/" + res);
if (upgrade.Time)
cost.time = getEntityValue("Upgrade/" + upgradeName + "/Time", "Upgrade/Time");
ret.upgrades.push({
"entity": upgrade.Entity,
"tooltip": upgrade.Tooltip,
"cost": cost,
"icon": upgrade.Icon || undefined,
"requiredTechnology": upgrade.RequiredTechnology || undefined
});
}
}
if (template.ProductionQueue)
{
ret.techCostMultiplier = {};
+40 -25
View File
@@ -84,16 +84,23 @@ function draw()
prod = g_ParsedData.units[prod];
if (!drawProdIcon(i, s, r, p, prod))
break;
p++;
++p;
}
if (stru.upgrades[prod_pha])
for (let upgrade of stru.upgrades[prod_pha])
{
if (!drawProdIcon(i, s, r, p, upgrade))
break;
++p;
}
if (stru.wallset && prod_pha == pha)
for (let prod of [stru.wallset.gate, stru.wallset.tower])
{
if (!drawProdIcon(i, s, r, p, prod))
break;
p++;
}
{
if (!drawProdIcon(i, s, r, p, stru.wallset.tower))
break;
++p;
}
if (stru.production.technology[prod_pha])
for (let prod of stru.production.technology[prod_pha])
@@ -174,29 +181,37 @@ function draw()
thisEle.hidden = false;
let p = 0;
for (let prodType in trainer.production)
{
for (let prod of trainer.production[prodType])
{
switch (prodType)
if (trainer.production)
for (let prodType in trainer.production)
for (let prod of trainer.production[prodType])
{
case "units":
prod = g_ParsedData.units[prod];
break;
case "techs":
prod = clone(g_ParsedData.techs[g_SelectedCiv][prod]);
for (let res in trainer.techCostMultiplier)
if (prod.cost[res])
prod.cost[res] *= trainer.techCostMultiplier[res];
break;
default:
continue;
switch (prodType)
{
case "units":
prod = g_ParsedData.units[prod];
break;
case "techs":
prod = clone(g_ParsedData.techs[g_SelectedCiv][prod]);
for (let res in trainer.techCostMultiplier)
if (prod.cost[res])
prod.cost[res] *= trainer.techCostMultiplier[res];
break;
default:
continue;
}
if (!drawProdIcon(null, t, null, p, prod))
break;
++p;
}
if (!drawProdIcon(null, t, null, p, prod))
if (trainer.upgrades)
for (let upgrade of trainer.upgrades)
{
if (!drawProdIcon(null, t, null, p, upgrade.data))
break;
++p;
}
}
hideRemaining("trainer["+t+"]_row", p);
let size = thisEle.size;
@@ -78,6 +78,31 @@ function deriveModifications(techList)
return DeriveModificationsFromTechnologies(techData);
}
/**
* Provided with an array containing basic information about possible
* upgrades, such as that generated by globalscript's GetTemplateDataHelper,
* this function loads the actual template data of the upgrades, overwrites
* certain values within, then passes an array containing the template data
* back to caller.
*/
function getActualUpgradeData(upgradesInfo)
{
let newUpgrades = [];
for (let upgrade of upgradesInfo)
{
upgrade.entity = upgrade.entity.replace("{civ}", g_SelectedCiv);
let data = GetTemplateDataHelper(loadTemplate(upgrade.entity), null, g_AuraData, g_ResourceData);
data.cost = upgrade.cost
data.icon = upgrade.icon || data.icon;
data.tooltip = upgrade.tooltip || data.tooltip;
data.requiredTechnology = upgrade.requiredTechnology || data.requiredTechnology;
newUpgrades.push(data);
}
return newUpgrades;
}
/**
* This is needed because getEntityCostTooltip in tooltip.js needs to get
* the template data of the different wallSet pieces. In the session this
@@ -40,6 +40,9 @@ function loadUnit(templateName)
g_Lists.structures.push(build);
}
if (unit.upgrades)
unit.upgrades = getActualUpgradeData(unit.upgrades);
return unit;
}
@@ -73,10 +76,16 @@ function loadStructure(templateName)
}
}
if (structure.upgrades)
structure.upgrades = getActualUpgradeData(structure.upgrades);
if (structure.wallSet)
{
structure.wallset = {};
if (!structure.upgrades)
structure.upgrades = [];
// Note: Assume wall segments of all lengths have the same armor and auras
let struct = loadStructure(structure.wallSet.templates.long);
structure.armour = struct.armour;
@@ -96,6 +105,9 @@ function loadStructure(templateName)
for (let research of wPart.production.technology)
structure.production.technology.push(research);
if (wPart.upgrades)
structure.upgrades = structure.upgrades.concat(wPart.upgrades);
if (["gate", "tower"].indexOf(wSegm) != -1)
continue;
@@ -174,7 +174,7 @@ function selectCiv(civCode)
}
}
// Group production lists of structures by phase
// Group production and upgrade lists of structures by phase
for (let structCode of g_Lists.structures)
{
let structInfo = g_ParsedData.structures[structCode];
@@ -235,6 +235,22 @@ function selectCiv(civCode)
"technology": newProdTech,
"units": newProdUnits
};
// Sort upgrades by phase
let newUpgrades = {};
if (structInfo.upgrades)
for (let upgrade of structInfo.upgrades)
{
let phase = GetPhaseOfTemplate(upgrade);
if (g_ParsedData.phaseList.indexOf(phase) < structPhaseIdx)
phase = structInfo.phase;
if (!newUpgrades[phase])
newUpgrades[phase] = [];
newUpgrades[phase].push(upgrade);
}
g_ParsedData.structures[structCode].upgrades = newUpgrades;
}
// Determine the buildList for the civ (grouped by phase)
@@ -247,8 +263,11 @@ function selectCiv(civCode)
let phase = g_ParsedData.structures[structCode].phase;
buildList[phase].push(structCode);
}
for (let unitCode of g_Lists.units)
if (g_ParsedData.units[unitCode] && g_ParsedData.units[unitCode].production && Object.keys(g_ParsedData.units[unitCode].production).length)
if (g_ParsedData.units[unitCode] && (
g_ParsedData.units[unitCode].production && Object.keys(g_ParsedData.units[unitCode].production).length
|| g_ParsedData.units[unitCode].upgrades))
{
// Replace any pair techs with the actual techs of that pair
if (g_ParsedData.units[unitCode].production.techs)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Entity parent="template_structure_defense_wall_long">
<Auras disable=""/>
<!-- We don't disable the Cost component, although gates cannot be built directly, as Cost/BuildTime is required to prevent instantaneous repair -->
<GarrisonHolder disable=""/>
<Gate>
<PassRange>20</PassRange>