Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/helpers/Commands.js
Show All 40 Lines | function ProcessCommand(player, cmd) | ||||
// Note: checks of UnitAI targets are not robust enough here, as ownership | // Note: checks of UnitAI targets are not robust enough here, as ownership | ||||
// can change after the order is issued, they should be checked by UnitAI | // can change after the order is issued, they should be checked by UnitAI | ||||
// when the specific behavior (e.g. attack, garrison) is performed. | // when the specific behavior (e.g. attack, garrison) is performed. | ||||
// (Also it's not ideal if a command silently fails, it's nicer if UnitAI | // (Also it's not ideal if a command silently fails, it's nicer if UnitAI | ||||
// moves the entities closer to the target before giving up.) | // moves the entities closer to the target before giving up.) | ||||
// Now handle various commands | // Now handle various commands | ||||
if (g_Commands[cmd.type]) | if (g_Commands[cmd.type]) | ||||
Lint: no-use-before-define: 'g_Commands' was used before it was defined. | |||||
{ | { | ||||
var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); | var cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); | ||||
cmpTrigger.CallEvent("OnPlayerCommand", { "player": player, "cmd": cmd }); | cmpTrigger.CallEvent("OnPlayerCommand", { "player": player, "cmd": cmd }); | ||||
g_Commands[cmd.type](player, cmd, data); | g_Commands[cmd.type](player, cmd, data); | ||||
Lint: no-use-before-define 'g_Commands' was used before it was defined. Lint: no-use-before-define: 'g_Commands' was used before it was defined. | |||||
} | } | ||||
else | else | ||||
error("Invalid command: unknown command type: "+uneval(cmd)); | error("Invalid command: unknown command type: "+uneval(cmd)); | ||||
} | } | ||||
var g_Commands = { | var g_Commands = { | ||||
"aichat": function(player, cmd, data) | "aichat": function(player, cmd, data) | ||||
▲ Show 20 Lines • Show All 305 Lines • ▼ Show 20 Lines | for (let ent of data.entities) | ||||
if (list.indexOf(promoted) === -1) | if (list.indexOf(promoted) === -1) | ||||
continue; | continue; | ||||
cmd.template = promoted; | cmd.template = promoted; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (queue && queue.GetEntitiesList().indexOf(cmd.template) != -1) | if (queue && queue.GetEntitiesList().indexOf(cmd.template) != -1) | ||||
if ("metadata" in cmd) | queue.AddItem(cmd.template, "unit", +cmd.count, cmd.metadata, cmd.pushFront); | ||||
queue.AddItem(cmd.template, "unit", +cmd.count, cmd.metadata); | |||||
else | |||||
queue.AddItem(cmd.template, "unit", +cmd.count); | |||||
} | } | ||||
}, | }, | ||||
"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)) | ||||
{ | { | ||||
if (g_DebugCommands) | if (g_DebugCommands) | ||||
warn("Invalid command: Requirements to research technology are not met: " + uneval(cmd)); | warn("Invalid command: Requirements to research technology are not met: " + uneval(cmd)); | ||||
return; | return; | ||||
} | } | ||||
var queue = Engine.QueryInterface(cmd.entity, IID_ProductionQueue); | var queue = Engine.QueryInterface(cmd.entity, IID_ProductionQueue); | ||||
if (queue) | if (queue) | ||||
queue.AddItem(cmd.template, "technology"); | queue.AddItem(cmd.template, "technology", undefined, cmd.metadata, cmd.pushFront); | ||||
}, | }, | ||||
"stop-production": function(player, cmd, data) | "stop-production": function(player, cmd, data) | ||||
{ | { | ||||
let cmpProductionQueue = Engine.QueryInterface(cmd.entity, IID_ProductionQueue); | let cmpProductionQueue = Engine.QueryInterface(cmd.entity, IID_ProductionQueue); | ||||
if (cmpProductionQueue) | if (cmpProductionQueue) | ||||
cmpProductionQueue.RemoveItem(cmd.id); | cmpProductionQueue.RemoveItem(cmd.id); | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 1,465 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
'g_Commands' was used before it was defined.