Index: binaries/data/mods/public/simulation/ai/petra/researchManager.js =================================================================== --- binaries/data/mods/public/simulation/ai/petra/researchManager.js +++ binaries/data/mods/public/simulation/ai/petra/researchManager.js @@ -35,43 +35,43 @@ } }; -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) { if (queues.minorTech.hasQueuedUnits()) - return; + return false; let techs = gameState.findAvailableTech(); for (let tech of techs) { - if (!tech[1]._template.modifications) - continue; - // TODO may-be loop on all modifs and check if the effect if positive ? - if (tech[1]._template.modifications[0].value !== "Population/Bonus") + let template = tech[1]._template; + if (!template.modifications || affects && (!template.affects || template.affects.indexOf(affects) === -1)) continue; - queues.minorTech.addPlan(new PETRA.ResearchPlan(gameState, tech[0])); - break; + for (let i in template.modifications) + { + if (template.modifications[i].value === modif) + { + // ToDo: May-be check if the total effect is positive? + queues.minorTech.addPlan(new PETRA.ResearchPlan(gameState, tech[0])); + return true; + } + } } + return false; }; -PETRA.ResearchManager.prototype.researchTradeBonus = function(gameState, queues) +PETRA.ResearchManager.prototype.researchPopulationBonus = function(gameState, queues) { - if (queues.minorTech.hasQueuedUnits()) - return; + this.tryImprove(gameState, queues, "Population/Bonus"); +}; - let techs = gameState.findAvailableTech(); - for (let tech of techs) - { - if (!tech[1]._template.modifications || !tech[1]._template.affects) - continue; - 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; - } +PETRA.ResearchManager.prototype.researchTradeBonus = function(gameState, queues) +{ + this.tryImprove(gameState, queues, "UnitMotion/WalkSpeed", "Trader") || + this.tryImprove(gameState, queues, "Trader/GainMultiplier", "Trader"); }; /** Techs to be searched for as soon as they are available */