Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/common-api/entity.js
Show All 10 Lines | "_init": function(sharedAI, templateName, template) | ||||
// save a reference to the template tech modifications | // save a reference to the template tech modifications | ||||
if (!sharedAI._templatesModifications[this._templateName]) | if (!sharedAI._templatesModifications[this._templateName]) | ||||
sharedAI._templatesModifications[this._templateName] = {}; | sharedAI._templatesModifications[this._templateName] = {}; | ||||
this._templateModif = sharedAI._templatesModifications[this._templateName]; | this._templateModif = sharedAI._templatesModifications[this._templateName]; | ||||
this._tpCache = new Map(); | this._tpCache = new Map(); | ||||
}, | }, | ||||
// helper function to return a template value, optionally adjusting for tech. | // helper function to return a template value, optionally adjusting for tech. | ||||
// TODO: there's no support for "_string" values here. | // TODO: there's no support for "_string" values here. | ||||
lyv: The `TODO` I mentioned. Although, I have not checked whether what it's saying is true. | |||||
"get": function(string) | "get": function(string) | ||||
{ | { | ||||
let value = this._template; | let value = this._template; | ||||
if (this._entityModif && this._entityModif.has(string)) | if (this._entityModif && this._entityModif.has(string)) | ||||
return this._entityModif.get(string); | return this._entityModif.get(string); | ||||
else if (this._templateModif) | else if (this._templateModif) | ||||
{ | { | ||||
let owner = this._entity ? this._entity.owner : PlayerID; | let owner = this._entity ? this._entity.owner : PlayerID; | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | if (!classes) | ||||
return false; | return false; | ||||
for (let cls of array) | for (let cls of array) | ||||
if (classes.indexOf(cls) == -1) | if (classes.indexOf(cls) == -1) | ||||
return false; | return false; | ||||
return true; | return true; | ||||
}, | }, | ||||
"requiredTech": function() { return this.get("Identity/RequiredTechnology"); }, | "requiredTechs": function() { | ||||
let requiredTechnologies = this.get("Identity/RequiredTechnologies"); | |||||
Not Done Inline ActionsThis might break, I recall having seen a todo saying ._string values are missing. And IIRC, classes are also derived from a function in globalscript/Templates.js lyv: This might break, I recall having seen a todo saying `._string` values are missing. And IIRC… | |||||
Done Inline ActionsWorking for formation list in Identity component. Silier: Working for formation list in Identity component. | |||||
Not Done Inline ActionsI meant for the AI. lyv: I meant for the AI. | |||||
if (requiredTechnologies && requiredTechnologies._string) | |||||
return requiredTechnologies._string.split(/\s+/); | |||||
return []; | |||||
}, | |||||
"available": function(gameState) { | "available": function(gameState) { | ||||
let techRequired = this.requiredTech(); | let techsRequired = this.requiredTechs(); | ||||
if (!techRequired) | if (!techsRequired) | ||||
return true; | return true; | ||||
return gameState.isResearched(techRequired); | return gameState.areResearched(techsRequired); | ||||
}, | }, | ||||
// specifically | // specifically | ||||
"phase": function() { | "phase": function() { | ||||
let techRequired = this.requiredTech(); | let techsRequired = this.requiredTechs(); | ||||
if (!techRequired) | let id = 0; | ||||
return 0; | for (let techRequired of techsRequired) { | ||||
if (techRequired == "phase_village") | if (techRequired == "phase_village") | ||||
Not Done Inline Actionsswitch case ? Stan: switch case ? | |||||
Done Inline ActionsI dont think I can write switch case for .startsWith Silier: I dont think I can write switch case for .startsWith | |||||
return 1; | id = Math.max(id, 1); | ||||
if (techRequired == "phase_town") | if (techRequired == "phase_town") | ||||
return 2; | id = Math.max(id, 2); | ||||
if (techRequired == "phase_city") | if (techRequired == "phase_city") | ||||
return 3; | id = Math.max(id, 3); | ||||
if (techRequired.startsWith("phase_")) | if (techRequired.startsWith("phase_")) | ||||
Not Done Inline ActionsThe only relevant code here is id = Math.max(id, 4) lyv: The only relevant code here is `id = Math.max(id, 4)`
This statement would always be true. In… | |||||
Done Inline Actionsif it has more phase requirments it takes the highest needed. Silier: if it has more phase requirments it takes the highest needed. | |||||
Done Inline Actionsoh, I get your comment now Silier: oh, I get your comment now | |||||
return 4; | id = Math.max(id, 4); | ||||
return 0; | } | ||||
Not Done Inline ActionsI'd change this to Math.max(this.requiredTechs().map([the if here])) wraitii: I'd change this to Math.max(this.requiredTechs().map([the if here])) | |||||
return id; | |||||
}, | }, | ||||
"cost": function(productionQueue) { | "cost": function(productionQueue) { | ||||
if (!this.get("Cost")) | if (!this.get("Cost")) | ||||
return undefined; | return undefined; | ||||
let ret = {}; | let ret = {}; | ||||
for (let type in this.get("Cost/Resources")) | for (let type in this.get("Cost/Resources")) | ||||
▲ Show 20 Lines • Show All 832 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
The TODO I mentioned. Although, I have not checked whether what it's saying is true.