Differential D1130 Diff 4656 ps/trunk/binaries/data/mods/public/simulation/ai/common-api/gamestate.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/common-api/gamestate.js
Show First 20 Lines • Show All 213 Lines • ▼ Show 20 Lines | for (let entity of requirement.entities) | ||||
}); | }); | ||||
} | } | ||||
return entityReqs; | return entityReqs; | ||||
}; | }; | ||||
m.GameState.prototype.isResearched = function(template) | m.GameState.prototype.isResearched = function(template) | ||||
{ | { | ||||
return this.playerData.researchedTechs[template] !== undefined; | return this.playerData.researchedTechs.has(template); | ||||
}; | }; | ||||
/** true if started or queued */ | /** true if started or queued */ | ||||
m.GameState.prototype.isResearching = function(template) | m.GameState.prototype.isResearching = function(template) | ||||
{ | { | ||||
return this.playerData.researchStarted[template] !== undefined || | return this.playerData.researchStarted[template] !== undefined || | ||||
this.playerData.researchQueued[template] !== undefined; | this.playerData.researchQueued[template] !== undefined; | ||||
}; | }; | ||||
/** this is an "in-absolute" check that doesn't check if we have a building to research from. */ | /** this is an "in-absolute" check that doesn't check if we have a building to research from. */ | ||||
m.GameState.prototype.canResearch = function(techTemplateName, noRequirementCheck) | m.GameState.prototype.canResearch = function(techTemplateName, noRequirementCheck) | ||||
{ | { | ||||
if (this.playerData.disabledTechnologies[techTemplateName]) | if (this.playerData.disabledTechnologies[techTemplateName]) | ||||
return false; | return false; | ||||
let template = this.getTemplate(techTemplateName); | let template = this.getTemplate(techTemplateName); | ||||
if (!template) | if (!template) | ||||
return false; | return false; | ||||
// researching or already researched: NOO. | // researching or already researched: NOO. | ||||
if (this.playerData.researchQueued[techTemplateName] || | if (this.playerData.researchQueued[techTemplateName] || | ||||
this.playerData.researchStarted[techTemplateName] || | this.playerData.researchStarted[techTemplateName] || | ||||
this.playerData.researchedTechs[techTemplateName]) | this.playerData.researchedTechs.has(techTemplateName)) | ||||
return false; | return false; | ||||
if (noRequirementCheck) | if (noRequirementCheck) | ||||
return true; | return true; | ||||
// if this is a pair, we must check that the pair tech is not being researched | // if this is a pair, we must check that the pair tech is not being researched | ||||
if (template.pair()) | if (template.pair()) | ||||
{ | { | ||||
let other = template.pairedWith(); | let other = template.pairedWith(); | ||||
if (this.playerData.researchQueued[other] || | if (this.playerData.researchQueued[other] || | ||||
this.playerData.researchStarted[other] || | this.playerData.researchStarted[other] || | ||||
this.playerData.researchedTechs[other]) | this.playerData.researchedTechs.has(other)) | ||||
return false; | return false; | ||||
} | } | ||||
return this.checkTechRequirements(template.requirements(this.playerData.civ)); | return this.checkTechRequirements(template.requirements(this.playerData.civ)); | ||||
}; | }; | ||||
/** | /** | ||||
* Private function for checking a set of requirements is met. | * Private function for checking a set of requirements is met. | ||||
Show All 25 Lines | function doesEntitySpecPass(entity) | ||||
return true; | return true; | ||||
} | } | ||||
return reqs.some(req => { | return reqs.some(req => { | ||||
return Object.keys(req).every(type => { | return Object.keys(req).every(type => { | ||||
switch (type) | switch (type) | ||||
{ | { | ||||
case "techs": | case "techs": | ||||
return req[type].every(tech => !!this.playerData.researchedTechs[tech]); | return req[type].every(tech => this.playerData.researchedTechs.has(tech)); | ||||
case "entities": | case "entities": | ||||
return req[type].every(doesEntitySpecPass, this); | return req[type].every(doesEntitySpecPass, this); | ||||
} | } | ||||
return false; | return false; | ||||
}); | }); | ||||
}); | }); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 625 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator