Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/researchManager.js
Show All 29 Lines | PETRA.ResearchManager.prototype.checkPhase = function(gameState, queues) | ||||
{ | { | ||||
gameState.ai.HQ.phasing = currentPhaseIndex + 1; | gameState.ai.HQ.phasing = currentPhaseIndex + 1; | ||||
// Reset the queue priority in case it was changed during a previous phase update | // Reset the queue priority in case it was changed during a previous phase update | ||||
gameState.ai.queueManager.changePriority("majorTech", gameState.ai.Config.priorities.majorTech); | gameState.ai.queueManager.changePriority("majorTech", gameState.ai.Config.priorities.majorTech); | ||||
queues.majorTech.addPlan(new PETRA.ResearchPlan(gameState, nextPhaseName, true)); | queues.majorTech.addPlan(new PETRA.ResearchPlan(gameState, nextPhaseName, true)); | ||||
} | } | ||||
}; | }; | ||||
PETRA.ResearchManager.prototype.researchPopulationBonus = function(gameState, queues) | /** | ||||
* @param {string} modif - The path we try to improve. | |||||
* @param {string} affects - Optionally the class of entities we want to affect. | |||||
*/ | |||||
PETRA.ResearchManager.prototype.tryImprove = function(gameState, queues, modif, affects) | |||||
Silier: should be tryToImprove | |||||
{ | { | ||||
if (queues.minorTech.hasQueuedUnits()) | if (queues.minorTech.hasQueuedUnits()) | ||||
return; | return false; | ||||
let techs = gameState.findAvailableTech(); | const techs = gameState.findAvailableTech(); | ||||
SilierUnsubmitted Not Done Inline Actionsalso, this one is expensive, now called twice in researchTradeBonus, you should consider passing arrays here for modif and affects Silier: also, this one is expensive, now called twice in researchTradeBonus, you should consider… | |||||
for (let tech of techs) | for (const tech of techs) | ||||
{ | { | ||||
if (!tech[1]._template.modifications) | const template = tech[1]._template; | ||||
continue; | if (!template.modifications || affects && (!template.affects || template.affects.indexOf(affects) === -1)) | ||||
// TODO may-be loop on all modifs and check if the effect if positive ? | |||||
if (tech[1]._template.modifications[0].value !== "Population/Bonus") | |||||
continue; | continue; | ||||
for (const i in template.modifications) | |||||
if (template.modifications[i].value === modif) | |||||
SilierUnsubmitted Not Done Inline Actionsdont think you need === here Silier: dont think you need === here | |||||
StanUnsubmitted Not Done Inline ActionsIt's good practise :) Stan: It's good practise :) | |||||
{ | |||||
// ToDo: May-be check if the total effect is positive? | |||||
queues.minorTech.addPlan(new PETRA.ResearchPlan(gameState, tech[0])); | queues.minorTech.addPlan(new PETRA.ResearchPlan(gameState, tech[0])); | ||||
break; | return true; | ||||
} | } | ||||
} | |||||
return false; | |||||
}; | }; | ||||
PETRA.ResearchManager.prototype.researchTradeBonus = function(gameState, queues) | PETRA.ResearchManager.prototype.researchPopulationBonus = function(gameState, queues) | ||||
{ | { | ||||
if (queues.minorTech.hasQueuedUnits()) | this.tryImprove(gameState, queues, "Population/Bonus"); | ||||
return; | }; | ||||
let techs = gameState.findAvailableTech(); | PETRA.ResearchManager.prototype.researchTradeBonus = function(gameState, queues) | ||||
for (let tech of techs) | |||||
{ | { | ||||
if (!tech[1]._template.modifications || !tech[1]._template.affects) | if (!this.tryImprove(gameState, queues, "UnitMotion/WalkSpeed", "Trader")) | ||||
Done Inline ActionsThis tech is not present in vanilla anymore, but _is_ in DE. Freagarach: This tech is not present in vanilla anymore, but _is_ in DE. | |||||
continue; | this.tryImprove(gameState, queues, "Trader/GainMultiplier", "Trader"); | ||||
SilierUnsubmitted Not Done Inline Actionsnow you loop twice Silier: now you loop twice | |||||
if (tech[1]._template.affects.indexOf("Trader") === -1) | |||||
continue; | |||||
// TODO may-be loop on all modifs and check if the effect if positive ? | |||||
if (tech[1]._template.modifications[0].value !== "UnitMotion/WalkSpeed" && | |||||
tech[1]._template.modifications[0].value !== "Trader/GainMultiplier") | |||||
continue; | |||||
queues.minorTech.addPlan(new PETRA.ResearchPlan(gameState, tech[0])); | |||||
break; | |||||
} | |||||
}; | }; | ||||
/** Techs to be searched for as soon as they are available */ | /** Techs to be searched for as soon as they are available */ | ||||
PETRA.ResearchManager.prototype.researchWantedTechs = function(gameState, techs) | PETRA.ResearchManager.prototype.researchWantedTechs = function(gameState, techs) | ||||
{ | { | ||||
let phase1 = gameState.currentPhase() === 1; | let phase1 = gameState.currentPhase() === 1; | ||||
let available = phase1 ? gameState.ai.queueManager.getAvailableResources(gameState) : null; | let available = phase1 ? gameState.ai.queueManager.getAvailableResources(gameState) : null; | ||||
let numWorkers = phase1 ? gameState.getOwnEntitiesByRole("worker", true).length : 0; | let numWorkers = phase1 ? gameState.getOwnEntitiesByRole("worker", true).length : 0; | ||||
▲ Show 20 Lines • Show All 160 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
should be tryToImprove