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 716 Lines • ▼ Show 20 Lines | for (let ent of data.entities) | ||||
var cmpEntityLimits = QueryPlayerIDInterface(player, IID_EntityLimits); | var cmpEntityLimits = QueryPlayerIDInterface(player, IID_EntityLimits); | ||||
if (cmpEntityLimits && !cmpEntityLimits.AllowedToReplace(ent, cmd.template)) | if (cmpEntityLimits && !cmpEntityLimits.AllowedToReplace(ent, cmd.template)) | ||||
{ | { | ||||
if (g_DebugCommands) | if (g_DebugCommands) | ||||
warn("Invalid command: build limits check failed for player " + player + ": " + uneval(cmd)); | warn("Invalid command: build limits check failed for player " + player + ": " + uneval(cmd)); | ||||
continue; | continue; | ||||
} | } | ||||
let cmpTechnologyManager = QueryOwnerInterface(ent, IID_TechnologyManager); | if (!RequirementsHelper.AreRequirementsMet(cmpUpgrade.GetRequirements(cmd.template), player)) | ||||
let requiredTechnology = cmpUpgrade.GetRequiredTechnology(cmd.template); | |||||
if (requiredTechnology && (!cmpTechnologyManager || !cmpTechnologyManager.IsTechnologyResearched(requiredTechnology))) | |||||
{ | { | ||||
if (g_DebugCommands) | if (g_DebugCommands) | ||||
warn("Invalid command: upgrading is not possible for this player or requires unresearched technology: " + uneval(cmd)); | warn("Invalid command: upgrading is not possible for this player or requires unresearched technology: " + uneval(cmd)); | ||||
continue; | continue; | ||||
} | } | ||||
cmpUpgrade.Upgrade(cmd.template, data.cmpPlayer); | cmpUpgrade.Upgrade(cmd.template, data.cmpPlayer); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,054 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
'g_Commands' was used before it was defined.