forked from mirrors/0ad
Unify structree production queue loading duplication.
Differential Revision: https://code.wildfiregames.com/D1192 Reviewed By: s0600204 This was SVN commit r21022.
This commit is contained in:
@@ -93,14 +93,12 @@ function getTemplateListsFromUnit(templateName)
|
||||
{
|
||||
if (!templateName || !Engine.TemplateExists(templateName))
|
||||
return {};
|
||||
|
||||
let template = loadTemplate(templateName);
|
||||
|
||||
let templateLists = {
|
||||
"structures": [],
|
||||
"units": [],
|
||||
"techs": []
|
||||
};
|
||||
let templateLists = loadProductionQueue(template);
|
||||
|
||||
templateLists.structures = [];
|
||||
if (template.Builder && template.Builder.Entities._string)
|
||||
for (let build of template.Builder.Entities._string.split(" "))
|
||||
{
|
||||
@@ -109,30 +107,6 @@ function getTemplateListsFromUnit(templateName)
|
||||
templateLists.structures.push(build);
|
||||
}
|
||||
|
||||
if (template.ProductionQueue)
|
||||
{
|
||||
if (template.ProductionQueue.Entities)
|
||||
for (let build of template.ProductionQueue.Entities._string.split(" "))
|
||||
{
|
||||
build = build.replace(/\{(civ|native)\}/g, g_SelectedCiv);
|
||||
if (Engine.TemplateExists(build) && templateLists.units.indexOf(build) === -1)
|
||||
templateLists.units.push(build);
|
||||
}
|
||||
|
||||
if (template.ProductionQueue.Technologies)
|
||||
for (let research of template.ProductionQueue.Technologies._string.split(" "))
|
||||
{
|
||||
if (research.indexOf("{civ}") != -1)
|
||||
{
|
||||
let civResearch = research.replace("{civ}", g_SelectedCiv);
|
||||
research = techDataExists(civResearch) ?
|
||||
civResearch : research.replace("{civ}", "generic");
|
||||
}
|
||||
if (templateLists.techs.indexOf(research) === -1)
|
||||
templateLists.techs.push(research);
|
||||
}
|
||||
}
|
||||
|
||||
return templateLists;
|
||||
}
|
||||
|
||||
@@ -146,36 +120,10 @@ function getTemplateListsFromStructure(templateName)
|
||||
{
|
||||
if (!templateName || !Engine.TemplateExists(templateName))
|
||||
return {};
|
||||
|
||||
let template = loadTemplate(templateName);
|
||||
|
||||
let templateLists = {
|
||||
"techs": [],
|
||||
"units": []
|
||||
};
|
||||
|
||||
if (template.ProductionQueue)
|
||||
{
|
||||
if (template.ProductionQueue.Entities && template.ProductionQueue.Entities._string)
|
||||
for (let build of template.ProductionQueue.Entities._string.split(" "))
|
||||
{
|
||||
build = build.replace(/\{(civ|native)\}/g, g_SelectedCiv);
|
||||
if (Engine.TemplateExists(build) && templateLists.units.indexOf(build) === -1)
|
||||
templateLists.units.push(build);
|
||||
}
|
||||
|
||||
if (template.ProductionQueue.Technologies && template.ProductionQueue.Technologies._string)
|
||||
for (let research of template.ProductionQueue.Technologies._string.split(" "))
|
||||
{
|
||||
if (research.indexOf("{civ}") != -1)
|
||||
{
|
||||
let civResearch = research.replace("{civ}", g_SelectedCiv);
|
||||
research = techDataExists(civResearch) ?
|
||||
civResearch : research.replace("{civ}", "generic");
|
||||
}
|
||||
if (templateLists.techs.indexOf(research) === -1)
|
||||
templateLists.techs.push(research);
|
||||
}
|
||||
}
|
||||
let templateLists = loadProductionQueue(template);
|
||||
|
||||
if (template.WallSet)
|
||||
for (let wSegm in template.WallSet.Templates)
|
||||
@@ -188,3 +136,40 @@ function getTemplateListsFromStructure(templateName)
|
||||
|
||||
return templateLists;
|
||||
}
|
||||
|
||||
function loadProductionQueue(template)
|
||||
{
|
||||
let production = {
|
||||
"techs": [],
|
||||
"units": []
|
||||
};
|
||||
|
||||
if (!template.ProductionQueue)
|
||||
return production;
|
||||
|
||||
if (template.ProductionQueue.Entities && template.ProductionQueue.Entities._string)
|
||||
for (let templateName of template.ProductionQueue.Entities._string.split(" "))
|
||||
{
|
||||
templateName = templateName.replace(/\{(civ|native)\}/g, g_SelectedCiv);
|
||||
if (Engine.TemplateExists(templateName))
|
||||
production.units.push(templateName);
|
||||
}
|
||||
|
||||
if (template.ProductionQueue.Technologies && template.ProductionQueue.Technologies._string)
|
||||
for (let technologyName of template.ProductionQueue.Technologies._string.split(" "))
|
||||
{
|
||||
if (technologyName.indexOf("{civ}") != -1)
|
||||
{
|
||||
let civTechName = technologyName.replace("{civ}", g_SelectedCiv);
|
||||
technologyName = techDataExists(civTechName) ? civTechName : technologyName.replace("{civ}", "generic");
|
||||
}
|
||||
|
||||
if (isPairTech(technologyName))
|
||||
for (let pairTechnologyName of loadTechnologyPair(technologyName).techs)
|
||||
production.techs.push(pairTechnologyName);
|
||||
else
|
||||
production.techs.push(technologyName);
|
||||
}
|
||||
|
||||
return production;
|
||||
}
|
||||
|
||||
@@ -108,39 +108,7 @@ function loadUnit(templateName)
|
||||
|
||||
let template = loadTemplate(templateName);
|
||||
let unit = GetTemplateDataHelper(template, null, g_AuraData, g_ResourceData, g_DamageTypes, g_CurrentModifiers);
|
||||
|
||||
if (template.ProductionQueue)
|
||||
{
|
||||
unit.production = {};
|
||||
if (template.ProductionQueue.Entities)
|
||||
{
|
||||
unit.production.units = [];
|
||||
for (let build of template.ProductionQueue.Entities._string.split(" "))
|
||||
{
|
||||
build = build.replace(/\{(civ|native)\}/g, g_SelectedCiv);
|
||||
if (Engine.TemplateExists(build))
|
||||
unit.production.units.push(build);
|
||||
}
|
||||
}
|
||||
if (template.ProductionQueue.Technologies)
|
||||
{
|
||||
unit.production.techs = [];
|
||||
for (let research of template.ProductionQueue.Technologies._string.split(" "))
|
||||
{
|
||||
if (research.indexOf("{civ}") != -1)
|
||||
{
|
||||
let civResearch = research.replace("{civ}", g_SelectedCiv);
|
||||
research = techDataExists(civResearch) ?
|
||||
civResearch : research.replace("{civ}", "generic");
|
||||
}
|
||||
if (isPairTech(research))
|
||||
for (let tech of loadTechnologyPair(research).techs)
|
||||
unit.production.techs.push(tech);
|
||||
else
|
||||
unit.production.techs.push(research);
|
||||
}
|
||||
}
|
||||
}
|
||||
unit.production = loadProductionQueue(template);
|
||||
|
||||
if (template.Builder && template.Builder.Entities._string)
|
||||
{
|
||||
@@ -173,37 +141,7 @@ function loadStructure(templateName)
|
||||
let template = loadTemplate(templateName);
|
||||
let structure = GetTemplateDataHelper(template, null, g_AuraData, g_ResourceData, g_DamageTypes, g_CurrentModifiers);
|
||||
|
||||
structure.production = {
|
||||
"technology": [],
|
||||
"units": []
|
||||
};
|
||||
|
||||
if (template.ProductionQueue)
|
||||
{
|
||||
if (template.ProductionQueue.Entities && template.ProductionQueue.Entities._string)
|
||||
for (let build of template.ProductionQueue.Entities._string.split(" "))
|
||||
{
|
||||
build = build.replace(/\{(civ|native)\}/g, g_SelectedCiv);
|
||||
if (Engine.TemplateExists(build))
|
||||
structure.production.units.push(build);
|
||||
}
|
||||
|
||||
if (template.ProductionQueue.Technologies && template.ProductionQueue.Technologies._string)
|
||||
for (let research of template.ProductionQueue.Technologies._string.split(" "))
|
||||
{
|
||||
if (research.indexOf("{civ}") != -1)
|
||||
{
|
||||
let civResearch = research.replace("{civ}", g_SelectedCiv);
|
||||
research = techDataExists(civResearch) ?
|
||||
civResearch : research.replace("{civ}", "generic");
|
||||
}
|
||||
if (isPairTech(research))
|
||||
for (let tech of loadTechnologyPair(research).techs)
|
||||
structure.production.technology.push(tech);
|
||||
else
|
||||
structure.production.technology.push(research);
|
||||
}
|
||||
}
|
||||
structure.production = loadProductionQueue(template);
|
||||
|
||||
if (structure.upgrades)
|
||||
structure.upgrades = getActualUpgradeData(structure.upgrades);
|
||||
@@ -234,8 +172,8 @@ function loadStructure(templateName)
|
||||
let wPart = loadStructure(structure.wallSet.templates[wSegm]);
|
||||
structure.wallset[wSegm] = wPart;
|
||||
|
||||
for (let research of wPart.production.technology)
|
||||
structure.production.technology.push(research);
|
||||
for (let research of wPart.production.techs)
|
||||
structure.production.techs.push(research);
|
||||
|
||||
if (wPart.upgrades)
|
||||
structure.upgrades = structure.upgrades.concat(wPart.upgrades);
|
||||
|
||||
@@ -81,8 +81,8 @@ function draw()
|
||||
++p;
|
||||
}
|
||||
|
||||
if (stru.production.technology[prod_pha])
|
||||
for (let prod of stru.production.technology[prod_pha])
|
||||
if (stru.production.techs[prod_pha])
|
||||
for (let prod of stru.production.techs[prod_pha])
|
||||
{
|
||||
prod = clone(basename(prod).startsWith("phase") ?
|
||||
g_ParsedData.phases[prod] :
|
||||
|
||||
@@ -97,12 +97,12 @@ function selectCiv(civCode)
|
||||
|
||||
// If this building is shared with another civ,
|
||||
// it may have already gone through the grouping process already
|
||||
if (!Array.isArray(structInfo.production.technology))
|
||||
if (!Array.isArray(structInfo.production.techs))
|
||||
continue;
|
||||
|
||||
// Sort techs by phase
|
||||
let newProdTech = {};
|
||||
for (let prod of structInfo.production.technology)
|
||||
for (let prod of structInfo.production.techs)
|
||||
{
|
||||
let phase = getPhaseOfTechnology(prod);
|
||||
if (phase === false)
|
||||
@@ -135,7 +135,7 @@ function selectCiv(civCode)
|
||||
}
|
||||
|
||||
g_ParsedData.structures[structCode].production = {
|
||||
"technology": newProdTech,
|
||||
"techs": newProdTech,
|
||||
"units": newProdUnits
|
||||
};
|
||||
|
||||
@@ -170,7 +170,7 @@ function selectCiv(civCode)
|
||||
for (let unitCode of templateLists.units.keys())
|
||||
{
|
||||
let unitTemplate = g_ParsedData.units[unitCode];
|
||||
if ((!unitTemplate.production || !Object.keys(unitTemplate.production).length) && !unitTemplate.upgrades)
|
||||
if (!unitTemplate.production.units.length && !unitTemplate.production.techs.length && !unitTemplate.upgrades)
|
||||
continue;
|
||||
|
||||
trainerList.push(unitCode);
|
||||
|
||||
Reference in New Issue
Block a user