Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/helpers/Commands.js
Show First 20 Lines • Show All 347 Lines • ▼ Show 20 Lines | for (let ent of data.entities) | ||||
var cmpTechnologyManager = QueryOwnerInterface(ent, IID_TechnologyManager); | var cmpTechnologyManager = QueryOwnerInterface(ent, IID_TechnologyManager); | ||||
if (cmpTechnologyManager && !cmpTechnologyManager.CanProduce(cmd.template)) | if (cmpTechnologyManager && !cmpTechnologyManager.CanProduce(cmd.template)) | ||||
{ | { | ||||
if (g_DebugCommands) | if (g_DebugCommands) | ||||
warn("Invalid command: training requires unresearched technology: " + uneval(cmd)); | warn("Invalid command: training requires unresearched technology: " + uneval(cmd)); | ||||
continue; | continue; | ||||
} | } | ||||
var queue = Engine.QueryInterface(ent, IID_ProductionQueue); | const cmpTrainer = Engine.QueryInterface(ent, IID_Trainer); | ||||
if (!cmpTrainer) | |||||
continue; | |||||
let templateName = cmd.template; | |||||
// Check if the building can train the unit | // Check if the building can train the unit | ||||
// TODO: the AI API does not take promotion technologies into account for the list | // TODO: the AI API does not take promotion technologies into account for the list | ||||
// of trainable units (taken directly from the unit template). Here is a temporary fix. | // of trainable units (taken directly from the unit template). Here is a temporary fix. | ||||
if (queue && data.cmpPlayer.IsAI()) | if (data.cmpPlayer.IsAI()) | ||||
{ | templateName = cmpTrainer.GetUpgradedTemplate(cmd.template); | ||||
var list = queue.GetEntitiesList(); | |||||
if (list.indexOf(cmd.template) === -1 && cmd.promoted) | if (cmpTrainer.CanTrain(templateName)) | ||||
{ | Engine.QueryInterface(ent, IID_ProductionQueue)?.AddItem(templateName, "unit", +cmd.count, cmd.metadata, cmd.pushFront); | ||||
for (var promoted of cmd.promoted) | |||||
{ | |||||
if (list.indexOf(promoted) === -1) | |||||
continue; | |||||
cmd.template = promoted; | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
if (queue && queue.GetEntitiesList().indexOf(cmd.template) != -1) | |||||
queue.AddItem(cmd.template, "unit", +cmd.count, cmd.metadata, cmd.pushFront); | |||||
} | } | ||||
}, | }, | ||||
"research": function(player, cmd, data) | "research": function(player, cmd, data) | ||||
{ | { | ||||
var cmpTechnologyManager = QueryOwnerInterface(cmd.entity, IID_TechnologyManager); | var cmpTechnologyManager = QueryOwnerInterface(cmd.entity, IID_TechnologyManager); | ||||
if (cmpTechnologyManager && !cmpTechnologyManager.CanResearch(cmd.template)) | if (cmpTechnologyManager && !cmpTechnologyManager.CanResearch(cmd.template)) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 1,481 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator