(Reference Suite) Fetch teambonus auras from player_{civ}.xml files
(The `civ` key (in the team bonus aura templates) was added in190d6e7cf5
for the purpose of identifying which aura belongs to which civ. It's no longer used.) Proposed by: @Nescio Comments by: @Freagarach Refs:190d6e7cf5
Differential Revision: https://code.wildfiregames.com/D3864 This was SVN commit r25689.
This commit is contained in:
parent
ad8c7cb2e0
commit
6b7a80b260
@ -11,8 +11,6 @@ class Subsection
|
||||
for (let auraCode of auraList)
|
||||
{
|
||||
let aura = this.page.TemplateParser.getAura(auraCode);
|
||||
if (!aura.civ || aura.civ != civCode)
|
||||
continue;
|
||||
|
||||
captions.push(this.page.formatEntry(
|
||||
getEntityNames(aura),
|
||||
|
@ -29,7 +29,7 @@ class BonusesSubsection extends Subsection
|
||||
);
|
||||
|
||||
let teamBonuses = this.getAuraCaptions(
|
||||
this.page.TemplateLoader.teamBonusAuraList,
|
||||
this.page.TemplateParser.getPlayer(civCode).teambonuses,
|
||||
civCode
|
||||
);
|
||||
teamBonuses.unshift(
|
||||
|
@ -9,6 +9,7 @@ class TemplateLoader
|
||||
* Raw Data Caches.
|
||||
*/
|
||||
this.auraData = {};
|
||||
this.playerData = {};
|
||||
this.technologyData = {};
|
||||
this.templateData = {};
|
||||
|
||||
@ -16,7 +17,6 @@ class TemplateLoader
|
||||
* Partly-composed data.
|
||||
*/
|
||||
this.autoResearchTechList = this.findAllAutoResearchedTechs();
|
||||
this.teamBonusAuraList = this.findAllTeamBonusAuras();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,6 +71,30 @@ class TemplateLoader
|
||||
return this.templateData[templateName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads raw player template.
|
||||
*
|
||||
* Loads from local cache if data present, else from file system.
|
||||
*
|
||||
* If a civ doesn't have their own civ-specific template,
|
||||
* then we return the generic template.
|
||||
*
|
||||
* @param {string} civCode
|
||||
* @return {Object} Object containing raw template data.
|
||||
*/
|
||||
loadPlayerTemplate(civCode)
|
||||
{
|
||||
if (!(civCode in this.playerData))
|
||||
{
|
||||
let templateName = this.buildPlayerTemplateName(civCode);
|
||||
this.playerData[civCode] = Engine.GetTemplate(templateName);
|
||||
|
||||
// No object keys need to be translated
|
||||
}
|
||||
|
||||
return this.playerData[civCode];
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads raw technology template.
|
||||
*
|
||||
@ -186,6 +210,22 @@ class TemplateLoader
|
||||
return DeriveModificationsFromTechnologies(techData);
|
||||
}
|
||||
|
||||
/**
|
||||
* If a civ doesn't have its own civ-specific player template,
|
||||
* this returns the name of the generic player template.
|
||||
*
|
||||
* @see simulation/helpers/Player.js GetPlayerTemplateName()
|
||||
* (Which can't be combined with this due to different Engine contexts)
|
||||
*/
|
||||
buildPlayerTemplateName(civCode)
|
||||
{
|
||||
let templateName = this.PlayerPath + this.PlayerTemplatePrefix + civCode;
|
||||
if (Engine.TemplateExists(templateName))
|
||||
return templateName;
|
||||
|
||||
return this.PlayerPath + this.PlayerTemplateFallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crudely iterates through every tech JSON file and identifies those
|
||||
* that are auto-researched.
|
||||
@ -204,33 +244,6 @@ class TemplateLoader
|
||||
return techList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates through and loads all team bonus auras.
|
||||
*
|
||||
* We make an assumption in this method: that all team bonus auras are
|
||||
* in a single folder.
|
||||
*
|
||||
* Team bonuses must have a "civ" attribute to indicate what civ they
|
||||
* belong to.
|
||||
*
|
||||
* @return {array} List of teambonus auras
|
||||
*/
|
||||
findAllTeamBonusAuras()
|
||||
{
|
||||
let auraList = [];
|
||||
let path = this.AuraPath + TemplateLoader.prototype.AuraTeamBonusSubpath;
|
||||
for (let templateName of listFiles(path, ".json", true))
|
||||
{
|
||||
let filename = TemplateLoader.prototype.AuraTeamBonusSubpath + templateName;
|
||||
let data = this.loadAuraTemplate(filename);
|
||||
if (!data || !data.civ)
|
||||
continue;
|
||||
|
||||
auraList.push(filename);
|
||||
}
|
||||
return auraList;
|
||||
}
|
||||
|
||||
/**
|
||||
* A template may be a variant of another template,
|
||||
* eg. `*_house`, `*_trireme`, or a promotion.
|
||||
@ -305,11 +318,17 @@ class TemplateLoader
|
||||
* It might be nice if we could get these from somewhere, instead of having them hardcoded here.
|
||||
*/
|
||||
TemplateLoader.prototype.AuraPath = "simulation/data/auras/";
|
||||
TemplateLoader.prototype.AuraTeamBonusSubpath = "teambonuses/";
|
||||
TemplateLoader.prototype.PlayerPath = "special/player/";
|
||||
TemplateLoader.prototype.TechnologyPath = "simulation/data/technologies/";
|
||||
|
||||
TemplateLoader.prototype.DefaultCiv = "gaia";
|
||||
|
||||
/**
|
||||
* Expected prefix for player templates, and the file to use if a civ doesn't have its own.
|
||||
*/
|
||||
TemplateLoader.prototype.PlayerTemplatePrefix = "player_";
|
||||
TemplateLoader.prototype.PlayerTemplateFallback = "player";
|
||||
|
||||
/**
|
||||
* Keys of template values that are to be translated on load.
|
||||
*/
|
||||
|
@ -15,6 +15,7 @@ class TemplateParser
|
||||
this.techs = {};
|
||||
this.phases = {};
|
||||
this.modifiers = {};
|
||||
this.players = {};
|
||||
|
||||
this.phaseList = [];
|
||||
}
|
||||
@ -33,6 +34,9 @@ class TemplateParser
|
||||
if (template.civ)
|
||||
parsed.civ = template.civ;
|
||||
|
||||
let affectedPlayers = template.affectedPlayers || this.AuraAffectedPlayerDefault;
|
||||
parsed.affectsTeam = this.AuraTeamIndicators.some(indicator => affectedPlayers.includes(indicator));
|
||||
|
||||
this.auras[auraName] = parsed;
|
||||
return this.auras[auraName];
|
||||
}
|
||||
@ -206,6 +210,28 @@ class TemplateParser
|
||||
return this.getTechnology(phaseCode, civCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and parse the relevant player_{civ}.xml template.
|
||||
*/
|
||||
getPlayer(civCode)
|
||||
{
|
||||
if (civCode in this.players)
|
||||
return this.players[civCode];
|
||||
|
||||
let template = this.TemplateLoader.loadPlayerTemplate(civCode);
|
||||
let parsed = {
|
||||
"teambonuses": [],
|
||||
};
|
||||
|
||||
if (template.Auras)
|
||||
for (let auraTemplateName of template.Auras._string.split(/\s+/))
|
||||
if (AuraTemplateExists(auraTemplateName) && this.getAura(auraTemplateName).affectsTeam)
|
||||
parsed.teambonuses.push(auraTemplateName);
|
||||
|
||||
this.players[civCode] = parsed;
|
||||
return parsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provided with an array containing basic information about possible
|
||||
* upgrades, such as that generated by globalscript's GetTemplateDataHelper,
|
||||
@ -340,3 +366,13 @@ class TemplateParser
|
||||
return finalReqs;
|
||||
}
|
||||
}
|
||||
|
||||
// Default affected player token list to use if an aura doesn't explicitly give one.
|
||||
// Keep in sync with simulation/components/Auras.js
|
||||
TemplateParser.prototype.AuraAffectedPlayerDefault =
|
||||
["Player"];
|
||||
|
||||
// List of tokens that, if found in an aura's "affectedPlayers" attribute, indicate
|
||||
// that the aura applies to team members.
|
||||
TemplateParser.prototype.AuraTeamIndicators =
|
||||
["MutualAlly", "ExclusiveMutualAlly"];
|
||||
|
@ -2,7 +2,6 @@
|
||||
"type": "global",
|
||||
"affects": ["Warship"],
|
||||
"affectedPlayers": ["MutualAlly"],
|
||||
"civ": "athen",
|
||||
"modifications": [
|
||||
{ "value": "Cost/BuildTime", "multiply": 0.75 }
|
||||
],
|
||||
|
@ -2,7 +2,6 @@
|
||||
"type": "global",
|
||||
"affects": ["Healer"],
|
||||
"affectedPlayers": ["MutualAlly"],
|
||||
"civ": "brit",
|
||||
"modifications": [
|
||||
{ "value": "Cost/Resources/food", "multiply": 0.8 },
|
||||
{ "value": "Cost/Resources/wood", "multiply": 0.8 },
|
||||
|
@ -2,7 +2,6 @@
|
||||
"type": "global",
|
||||
"affects": ["Trade"],
|
||||
"affectedPlayers": ["MutualAlly"],
|
||||
"civ": "cart",
|
||||
"modifications": [
|
||||
{ "value": "Market/InternationalBonus", "add": 0.1 }
|
||||
],
|
||||
|
@ -2,7 +2,6 @@
|
||||
"type": "global",
|
||||
"affects": ["Forge"],
|
||||
"affectedPlayers": ["MutualAlly"],
|
||||
"civ": "gaul",
|
||||
"modifications": [
|
||||
{ "value": "ProductionQueue/TechCostMultiplier/food", "multiply": 0.85 },
|
||||
{ "value": "ProductionQueue/TechCostMultiplier/wood", "multiply": 0.85 },
|
||||
|
@ -2,7 +2,6 @@
|
||||
"type": "global",
|
||||
"affects": ["Citizen Javelineer"],
|
||||
"affectedPlayers": ["MutualAlly"],
|
||||
"civ": "iber",
|
||||
"modifications": [
|
||||
{ "value": "Cost/Resources/food", "multiply": 0.9 },
|
||||
{ "value": "Cost/Resources/wood", "multiply": 0.9 },
|
||||
|
@ -2,7 +2,6 @@
|
||||
"type": "global",
|
||||
"affects": ["Elephant"],
|
||||
"affectedPlayers": ["MutualAlly"],
|
||||
"civ": "kush",
|
||||
"modifications": [
|
||||
{ "value": "Cost/BuildTime", "multiply": 0.8 },
|
||||
{ "value": "Cost/Resources/food", "multiply": 0.8 },
|
||||
|
@ -2,7 +2,6 @@
|
||||
"type": "player",
|
||||
"affects": ["Player"],
|
||||
"affectedPlayers": ["MutualAlly"],
|
||||
"civ": "mace",
|
||||
"modifications": [
|
||||
{ "value": "Player/BarterMultiplier/Sell/food", "multiply": 1.2 },
|
||||
{ "value": "Player/BarterMultiplier/Sell/wood", "multiply": 1.2 },
|
||||
|
@ -2,7 +2,6 @@
|
||||
"type": "global",
|
||||
"affects": ["Temple"],
|
||||
"affectedPlayers": ["MutualAlly"],
|
||||
"civ": "maur",
|
||||
"modifications": [
|
||||
{ "value": "Cost/BuildTime", "multiply": 0.5 },
|
||||
{ "value": "Cost/Resources/wood", "multiply": 0.5 },
|
||||
|
@ -2,7 +2,6 @@
|
||||
"type": "global",
|
||||
"affects": ["Trader !Ship"],
|
||||
"affectedPlayers": ["MutualAlly"],
|
||||
"civ": "pers",
|
||||
"modifications": [
|
||||
{ "value": "Trader/GainMultiplier", "multiply": 1.15 }
|
||||
],
|
||||
|
@ -2,7 +2,6 @@
|
||||
"type": "player",
|
||||
"affects": ["Player"],
|
||||
"affectedPlayers": ["MutualAlly"],
|
||||
"civ": "ptol",
|
||||
"modifications": [
|
||||
{ "value": "ResourceTrickle/Rates/food", "add": 1 }
|
||||
],
|
||||
|
@ -2,7 +2,6 @@
|
||||
"type": "global",
|
||||
"affects": ["Citizen Infantry"],
|
||||
"affectedPlayers": ["MutualAlly"],
|
||||
"civ": "rome",
|
||||
"modifications": [
|
||||
{ "value": "Cost/BuildTime", "multiply": 0.9 }
|
||||
],
|
||||
|
@ -2,7 +2,6 @@
|
||||
"type": "global",
|
||||
"affects": ["CivilCentre"],
|
||||
"affectedPlayers": ["MutualAlly"],
|
||||
"civ": "sele",
|
||||
"modifications": [
|
||||
{ "value": "Cost/Resources/food", "multiply": 0.8 },
|
||||
{ "value": "Cost/Resources/wood", "multiply": 0.8 },
|
||||
|
@ -2,7 +2,6 @@
|
||||
"type": "global",
|
||||
"affects": ["Citizen Infantry Spearman"],
|
||||
"affectedPlayers": ["MutualAlly"],
|
||||
"civ": "spart",
|
||||
"modifications": [
|
||||
{ "value": "Health/Max", "multiply": 1.1 }
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user