diff --git a/init.lua b/init.lua index 3c9cd863056..4f3ddcce5df 100644 --- a/init.lua +++ b/init.lua @@ -27,6 +27,11 @@ local commonFunctions = { LuaUI = true, }, + cmd = { + LuaRules = true, + LuaUI = true, + }, + map = { LuaRules = true, LuaUI = true, @@ -45,6 +50,10 @@ if commonFunctions.i18n[environment] then Spring.I18N = Spring.I18N or VFS.Include("modules/i18n/i18n.lua") end +if commonFunctions.cmd[environment] then + Game.CustomCommands = VFS.Include("modules/customcommands.lua") + Game.CustomCommands.injectIntoCMD() +end if commonFunctions.map[environment] then Spring.Lava = VFS.Include("modules/lava.lua") diff --git a/luarules/configs/customcmds.h.lua b/luarules/configs/customcmds.h.lua index f15efc4c889..3a03e1d4ec8 100644 --- a/luarules/configs/customcmds.h.lua +++ b/luarules/configs/customcmds.h.lua @@ -1,41 +1,3 @@ --------------------------------------------------------------------------------- --- --- Proposed Command ID Ranges: --- --- all negative: Engine (build commands) --- 0 - 999: Engine --- 1000 - 9999: Group AI --- 10000 - 19999: LuaUI --- 20000 - 29999: LuaCob --- 30000 - 39999: LuaRules --- +-- Please stop using this file, commands should go inside modules/customcommands.lua --- if you add a command, please order it by ID! - -CMD_FACTORY_GUARD = 13921 -CMD_AREA_GUARD = 13922 -CMD_STOP_PRODUCTION = 13923 - --- blueprint -CMD_BLUEPRINT_PLACE = 18200 -CMD_BLUEPRINT_CREATE = 18201 - --- quota -CMD_QUOTA_BUILD_TOGGLE = 23000 - -CMD_AREA_MEX = 30100 -CMD_SELL_UNIT = 30101 -CMD_MORPH = 31210 -CMD_MANUAL_LAUNCH = 32102 -CMD_PRIORITY = 34220 -CMD_UNIT_SET_TARGET = 34923 -- unit_target_on_the_move -CMD_UNIT_CANCEL_TARGET = 34924 -CMD_PRIORITY = 34571 -CMD_WANT_CLOAK = 37382 -CMD_HOUND_WEAPON_TOGGLE = 37383 -CMD_SMART_TOGGLE = 37384 - --- terraform -CMD_RESTORE = 39739 - -CMD_RAW_MOVE = 39812 +Game.CustomCommands.importCommandsToObject(gadget or widget) diff --git a/luarules/gadgets/cmd_alliance_break.lua b/luarules/gadgets/cmd_alliance_break.lua index 26856701964..164653ccf03 100644 --- a/luarules/gadgets/cmd_alliance_break.lua +++ b/luarules/gadgets/cmd_alliance_break.lua @@ -30,8 +30,8 @@ if gadgetHandler:IsSyncedCode() then local ValidUnitID = Spring.ValidUnitID local min = math.min - local CMD_UNIT_SET_TARGET = 34923 - local CMD_UNIT_SET_TARGET_RECTANGLE = 34925 + local CMD_UNIT_SET_TARGET = CMD.UNIT_SET_TARGET + local CMD_UNIT_SET_TARGET_RECTANGLE = CMD.UNIT_SET_TARGET_RECTANGLE local CMD_ATTACK = CMD.ATTACK local CMD_LOOPBACKATTACK = CMD.LOOPBACKATTACK local CMD_MANUALFIRE = CMD.MANUALFIRE diff --git a/luarules/gadgets/cmd_factory_stop_production.lua b/luarules/gadgets/cmd_factory_stop_production.lua index 1dfc242a710..9ee406227be 100644 --- a/luarules/gadgets/cmd_factory_stop_production.lua +++ b/luarules/gadgets/cmd_factory_stop_production.lua @@ -11,9 +11,9 @@ function gadget:GetInfo() enabled = true, } end -if gadgetHandler:IsSyncedCode() then - include("luarules/configs/customcmds.h.lua") + +if gadgetHandler:IsSyncedCode() then local isFactory = {} for udid = 1, #UnitDefs do @@ -27,6 +27,7 @@ if gadgetHandler:IsSyncedCode() then local spGiveOrderToUnit = Spring.GiveOrderToUnit local spInsertUnitCmdDesc = Spring.InsertUnitCmdDesc + local CMD_STOP_PRODUCTION = CMD.STOP_PRODUCTION local CMD_WAIT = CMD.WAIT local EMPTY = {} local DEQUEUE_OPTS = { "right", "ctrl", "shift" } -- right: dequeue, ctrl+shift: 100 diff --git a/luarules/gadgets/unit_factory_guard.lua b/luarules/gadgets/unit_factory_guard.lua index 60352480eb2..846d9ff2572 100644 --- a/luarules/gadgets/unit_factory_guard.lua +++ b/luarules/gadgets/unit_factory_guard.lua @@ -27,11 +27,10 @@ local spInsertUnitCmdDesc = Spring.InsertUnitCmdDesc local spEditUnitCmdDesc = Spring.EditUnitCmdDesc local spFindUnitCmdDesc = Spring.FindUnitCmdDesc +local CMD_FACTORY_GUARD = CMD.FACTORY_GUARD local CMD_GUARD = CMD.GUARD local CMD_MOVE = CMD.MOVE -include("luarules/configs/customcmds.h.lua") - local factoryGuardCmdDesc = { id = CMD_FACTORY_GUARD, type = CMDTYPE.ICON_MODE, diff --git a/luarules/gadgets/unit_target_on_the_move.lua b/luarules/gadgets/unit_target_on_the_move.lua index 3dcc106fd3c..e444389b6f4 100644 --- a/luarules/gadgets/unit_target_on_the_move.lua +++ b/luarules/gadgets/unit_target_on_the_move.lua @@ -13,19 +13,10 @@ function gadget:GetInfo() end -local CMD_UNIT_SET_TARGET_NO_GROUND = 34922 -local CMD_UNIT_SET_TARGET = 34923 -local CMD_UNIT_CANCEL_TARGET = 34924 -local CMD_UNIT_SET_TARGET_RECTANGLE = 34925 ---export to CMD table -CMD.CMD_UNIT_SET_TARGET_NO_GROUND = CMD_UNIT_SET_TARGET_NO_GROUND -CMD[CMD_UNIT_SET_TARGET_NO_GROUND] = 'UNIT_SET_TARGET_NO_GROUND' -CMD.UNIT_SET_TARGET = CMD_UNIT_SET_TARGET -CMD[CMD_UNIT_SET_TARGET] = 'UNIT_SET_TARGET' -CMD.UNIT_CANCEL_TARGET = CMD_UNIT_SET_TARGET -CMD[CMD_UNIT_CANCEL_TARGET] = 'UNIT_CANCEL_TARGET' -CMD.UNIT_SET_TARGET_RECTANGLE = CMD_UNIT_SET_TARGET_RECTANGLE -CMD[CMD_UNIT_SET_TARGET_RECTANGLE] = 'UNIT_SET_TARGET_RECTANGLE' +local CMD_UNIT_SET_TARGET_NO_GROUND = CMD.UNIT_SET_TARGET_NO_GROUND +local CMD_UNIT_SET_TARGET = CMD.UNIT_SET_TARGET +local CMD_UNIT_CANCEL_TARGET = CMD.UNIT_CANCEL_TARGET +local CMD_UNIT_SET_TARGET_RECTANGLE = CMD.UNIT_SET_TARGET_RECTANGLE local deleteMaxDistance = 30 diff --git a/luarules/gadgets/unit_timeslow.lua b/luarules/gadgets/unit_timeslow.lua index 84e423fca3e..a68c3162481 100644 --- a/luarules/gadgets/unit_timeslow.lua +++ b/luarules/gadgets/unit_timeslow.lua @@ -33,13 +33,12 @@ local spGetUnitNearestEnemy = Spring.GetUnitNearestEnemy local CMD_ATTACK = CMD.ATTACK local CMD_REMOVE = CMD.REMOVE +local CMD_RESTORE = CMD.RESTORE local CMD_MOVE = CMD.MOVE local CMD_FIGHT = CMD.FIGHT local CMD_SET_WANTED_MAX_SPEED = CMD.SET_WANTED_MAX_SPEED local LOS_ACCESS = {inlos = true} -include("LuaRules/Configs/customcmds.h.lua") - local gaiaTeamID = Spring.GetGaiaTeamID() local attritionWeaponDefs, MAX_SLOW_FACTOR, DEGRADE_TIMER, DEGRADE_FACTOR, UPDATE_PERIOD = include("LuaRules/Configs/timeslow_defs.lua") diff --git a/luarules/gadgets/unit_weapon_smart_select_helper.lua b/luarules/gadgets/unit_weapon_smart_select_helper.lua index 41a638da559..a8cedb34dd7 100644 --- a/luarules/gadgets/unit_weapon_smart_select_helper.lua +++ b/luarules/gadgets/unit_weapon_smart_select_helper.lua @@ -54,6 +54,8 @@ local backupSwitchThreshold = backupAutoAggro * 1.2 * -1 --the aggro at which ba local priorityCooldownFrames = Game.gameSpeed * 1.5 -- so that no matter how the aggro weights are set, the mode switches will happen no sooner than this. local backupCooldownFrames = Game.gameSpeed * 4 +local CMD_SMART_TOGGLE = CMD.SMART_TOGGLE + local PRIORITY_AIMINGSTATE = 0 local BACKUP_AIMINGSTATE = 1 local AUTO_TOGGLESTATE = 2 @@ -82,8 +84,6 @@ local spInsertUnitCmdDesc = Spring.InsertUnitCmdDesc local spEditUnitCmdDesc = Spring.EditUnitCmdDesc local spFindUnitCmdDesc = Spring.FindUnitCmdDesc -include("luarules/configs/customcmds.h.lua") - local trajectoryCmdDesc = { id = CMD_SMART_TOGGLE, type = CMDTYPE.ICON_MODE, diff --git a/luaui/Tests/cmd_blueprint/test_cmd_blueprint_line.lua b/luaui/Tests/cmd_blueprint/test_cmd_blueprint_line.lua index 06ae6adabef..104a8154c34 100644 --- a/luaui/Tests/cmd_blueprint/test_cmd_blueprint_line.lua +++ b/luaui/Tests/cmd_blueprint/test_cmd_blueprint_line.lua @@ -29,8 +29,6 @@ end local delay = 5 function test() - VFS.Include("luarules/configs/customcmds.h.lua") - widget = widgetHandler:FindWidget(widgetName) assert(widget) @@ -66,7 +64,7 @@ function test() Test.waitFrames(delay) - widget:CommandNotify(CMD_BLUEPRINT_CREATE, {}, {}) + widget:CommandNotify(CMD.BLUEPRINT_CREATE, {}, {}) assert(#(widget.blueprints) == 1) @@ -88,7 +86,7 @@ function test() Test.waitFrames(delay) Spring.SetActiveCommand( - Spring.GetCmdDescIndex(CMD_BLUEPRINT_PLACE), + Spring.GetCmdDescIndex(CMD.BLUEPRINT_PLACE), 1, true, false, @@ -121,7 +119,7 @@ function test() Test.waitFrames(delay) - widget:CommandNotify(CMD_BLUEPRINT_PLACE, {}, {}) + widget:CommandNotify(CMD.BLUEPRINT_PLACE, {}, {}) mockSpringGetMouseState.remove() Test.waitFrames(delay) diff --git a/luaui/Tests/cmd_blueprint/test_cmd_blueprint_single.lua b/luaui/Tests/cmd_blueprint/test_cmd_blueprint_single.lua index 13cc8e4cbda..f4ced968aad 100644 --- a/luaui/Tests/cmd_blueprint/test_cmd_blueprint_single.lua +++ b/luaui/Tests/cmd_blueprint/test_cmd_blueprint_single.lua @@ -28,8 +28,6 @@ end local delay = 5 function test() - VFS.Include("luarules/configs/customcmds.h.lua") - widget = widgetHandler:FindWidget(widgetName) assert(widget) @@ -62,7 +60,7 @@ function test() Test.waitFrames(delay) - widget:CommandNotify(CMD_BLUEPRINT_CREATE, {}, {}) + widget:CommandNotify(CMD.BLUEPRINT_CREATE, {}, {}) assert(#(widget.blueprints) == 1) @@ -84,7 +82,7 @@ function test() Test.waitFrames(delay) Spring.SetActiveCommand( - Spring.GetCmdDescIndex(CMD_BLUEPRINT_PLACE), + Spring.GetCmdDescIndex(CMD.BLUEPRINT_PLACE), 1, true, false, @@ -103,7 +101,7 @@ function test() Test.waitFrames(delay) - widget:CommandNotify(CMD_BLUEPRINT_PLACE, {}, {}) + widget:CommandNotify(CMD.BLUEPRINT_PLACE, {}, {}) Test.waitFrames(delay) diff --git a/luaui/Widgets/cmd_area_mex.lua b/luaui/Widgets/cmd_area_mex.lua index e6ebb990aae..5422270b384 100644 --- a/luaui/Widgets/cmd_area_mex.lua +++ b/luaui/Widgets/cmd_area_mex.lua @@ -13,7 +13,7 @@ function widget:GetInfo() } end -VFS.Include("luarules/configs/customcmds.h.lua") +local CMD_AREA_MEX = CMD.AREA_MEX local spGetActiveCommand = Spring.GetActiveCommand local spGetMapDrawMode = Spring.GetMapDrawMode diff --git a/luaui/Widgets/cmd_blueprint.lua b/luaui/Widgets/cmd_blueprint.lua index 677457c3bbf..0a47bd027c5 100644 --- a/luaui/Widgets/cmd_blueprint.lua +++ b/luaui/Widgets/cmd_blueprint.lua @@ -11,8 +11,6 @@ function widget:GetInfo() } end -VFS.Include("luarules/configs/customcmds.h.lua") - -- types -- ===== @@ -183,6 +181,9 @@ local BLUEPRINT_UNIT_LIMIT = 100 ---maximum total number of orders in a given blueprint placement command local BLUEPRINT_ORDER_LIMIT = 400 +local CMD_BLUEPRINT_PLACE = CMD.BLUEPRINT_PLACE +local CMD_BLUEPRINT_CREATE = CMD.BLUEPRINT_CREATE + local CMD_BLUEPRINT_PLACE_DESCRIPTION = { id = CMD_BLUEPRINT_PLACE, type = CMDTYPE.ICON_MAP, diff --git a/luaui/Widgets/cmd_customformations2.lua b/luaui/Widgets/cmd_customformations2.lua index 351a677f8f1..fdb015f3562 100644 --- a/luaui/Widgets/cmd_customformations2.lua +++ b/luaui/Widgets/cmd_customformations2.lua @@ -52,8 +52,8 @@ local unitIncreaseThresh = 0.85 -- We only increase maxUnits if the units are gr local lineFadeRate = 2.0 -- What commands are eligible for custom formations -local CMD_SETTARGET = 34923 -local CMD_MANUAL_LAUNCH = 32102 +local CMD_SETTARGET = CMD.UNIT_SET_TARGET +local CMD_MANUAL_LAUNCH = CMD.MANUAL_LAUNCH local formationCmds = { [CMD.MOVE] = true, diff --git a/luaui/Widgets/cmd_default_set_target.lua b/luaui/Widgets/cmd_default_set_target.lua index 1f4a297dcc5..f2cb82b50af 100644 --- a/luaui/Widgets/cmd_default_set_target.lua +++ b/luaui/Widgets/cmd_default_set_target.lua @@ -14,7 +14,7 @@ end local rebindKeys = false -local CMD_UNIT_SET_TARGET = 34923 +local CMD_UNIT_SET_TARGET = CMD.UNIT_SET_TARGET local IsUnitAllied = Spring.IsUnitAllied local GetSelectedUnitsCounts = Spring.GetSelectedUnitsCounts diff --git a/luaui/Widgets/cmd_factory_guard_pref.lua b/luaui/Widgets/cmd_factory_guard_pref.lua index 7fa99c3132d..cd5ec7047e6 100644 --- a/luaui/Widgets/cmd_factory_guard_pref.lua +++ b/luaui/Widgets/cmd_factory_guard_pref.lua @@ -13,7 +13,7 @@ function widget:GetInfo() } end -VFS.Include("luarules/configs/customcmds.h.lua") +local CMD_FACTORY_GUARD = CMD.FACTORY_GUARD local isFactory = {} for unitDefID, unitDef in pairs(UnitDefs) do diff --git a/luaui/Widgets/gui_attack_aoe.lua b/luaui/Widgets/gui_attack_aoe.lua index 149acb6f1f5..6050987f7e5 100644 --- a/luaui/Widgets/gui_attack_aoe.lua +++ b/luaui/Widgets/gui_attack_aoe.lua @@ -12,8 +12,6 @@ function widget:GetInfo() } end -VFS.Include('luarules/configs/customcmds.h.lua') - -------------------------------------------------------------------------------- --config -------------------------------------------------------------------------------- @@ -57,6 +55,7 @@ local GetUnitStates = Spring.GetUnitStates local TraceScreenRay = Spring.TraceScreenRay local CMD_ATTACK = CMD.ATTACK local CMD_MANUALFIRE = CMD.MANUALFIRE +local CMD_MANUAL_LAUNCH = CMD.MANUAL_LAUNCH local g = Game.gravity local GAME_SPEED = 30 local g_f = g / GAME_SPEED / GAME_SPEED diff --git a/luaui/Widgets/gui_buildmenu.lua b/luaui/Widgets/gui_buildmenu.lua index c95ee42f773..516eafa4feb 100644 --- a/luaui/Widgets/gui_buildmenu.lua +++ b/luaui/Widgets/gui_buildmenu.lua @@ -14,10 +14,11 @@ function widget:GetInfo() end include("keysym.h.lua") -VFS.Include('luarules/configs/customcmds.h.lua') SYMKEYS = table.invert(KEYSYMS) +local CMD_STOP_PRODUCTION = CMD.STOP_PRODUCTION + local useRenderToTexture = Spring.GetConfigFloat("ui_rendertotexture", 0) == 1 -- much faster than drawing via DisplayLists only local comBuildOptions diff --git a/luaui/Widgets/gui_commands_fx.lua b/luaui/Widgets/gui_commands_fx.lua index 8abc2fdaa88..882e6ccf86b 100644 --- a/luaui/Widgets/gui_commands_fx.lua +++ b/luaui/Widgets/gui_commands_fx.lua @@ -16,7 +16,7 @@ end -- handle set target -- quickfade on cmd cancel -local CMD_RAW_MOVE = 39812 +local CMD_RAW_MOVE = CMD.RAW_MOVE local CMD_ATTACK = CMD.ATTACK --icon unit or map local CMD_CAPTURE = CMD.CAPTURE --icon unit or area local CMD_FIGHT = CMD.FIGHT -- icon map @@ -31,7 +31,7 @@ local CMD_RECLAIM = CMD.RECLAIM --icon unit feature or area local CMD_REPAIR = CMD.REPAIR -- icon unit or area local CMD_RESTORE = CMD.RESTORE -- icon area local CMD_RESURRECT = CMD.RESURRECT -- icon unit feature or area --- local CMD_SET_TARGET = 34923 -- custom command, doesn't go through UnitCommand +-- local CMD_SET_TARGET = CMD.UNIT_SET_TARGET -- custom command, doesn't go through UnitCommand local CMD_UNLOAD_UNIT = CMD.UNLOAD_UNIT -- icon map local CMD_UNLOAD_UNITS = CMD.UNLOAD_UNITS -- icon unit or area local BUILD = -1 diff --git a/luaui/Widgets/gui_gridmenu.lua b/luaui/Widgets/gui_gridmenu.lua index 98ee5ddc1af..e1e12b1c60e 100644 --- a/luaui/Widgets/gui_gridmenu.lua +++ b/luaui/Widgets/gui_gridmenu.lua @@ -48,13 +48,13 @@ local GL_ONE_MINUS_SRC_ALPHA = GL.ONE_MINUS_SRC_ALPHA local GL_ONE = GL.ONE local GL_ONE_MINUS_SRC_COLOR = GL.ONE_MINUS_SRC_COLOR +local CMD_STOP_PRODUCTION = CMD.STOP_PRODUCTION local CMD_INSERT = CMD.INSERT local CMD_OPT_ALT = CMD.OPT_ALT local CMD_OPT_CTRL = CMD.OPT_CTRL local CMD_OPT_SHIFT = CMD.OPT_SHIFT local CMD_OPT_RIGHT = CMD.OPT_RIGHT -VFS.Include('luarules/configs/customcmds.h.lua') ------------------------------------------------------------------------------- --- STATIC VALUES ------------------------------------------------------------------------------- diff --git a/luaui/Widgets/gui_unit_market.lua b/luaui/Widgets/gui_unit_market.lua index 8f21e5489a7..0e8b25e0323 100644 --- a/luaui/Widgets/gui_unit_market.lua +++ b/luaui/Widgets/gui_unit_market.lua @@ -49,7 +49,6 @@ function widget:GetInfo() return { -- develop UI so that you can browse units that are for sale with a buy button maybe? -------------------------------- -VFS.Include("luarules/configs/customcmds.h.lua") local spGetPlayerInfo = Spring.GetPlayerInfo local spGetSpectatingState = Spring.GetSpectatingState diff --git a/luaui/Widgets/unit_builder_priority.lua b/luaui/Widgets/unit_builder_priority.lua index 55fbbcc9219..81bbee78177 100644 --- a/luaui/Widgets/unit_builder_priority.lua +++ b/luaui/Widgets/unit_builder_priority.lua @@ -14,7 +14,7 @@ function widget:GetInfo() } end -local CMD_PRIORITY = 34571 +local CMD_PRIORITY = CMD.PRIORITY -- symbol localization optimization for engine calls local spGetUnitDefID = Spring.GetUnitDefID diff --git a/luaui/Widgets/unit_cloak_firestate.lua b/luaui/Widgets/unit_cloak_firestate.lua index 75868a63588..7fb2add6a06 100644 --- a/luaui/Widgets/unit_cloak_firestate.lua +++ b/luaui/Widgets/unit_cloak_firestate.lua @@ -17,12 +17,11 @@ end -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -VFS.Include('luarules/configs/customcmds.h.lua') -- Speedups local GiveOrderToUnit = Spring.GiveOrderToUnit local GetUnitStates = Spring.GetUnitStates -local CMD_CLOAK = CMD_WANT_CLOAK +local CMD_WANT_CLOAK = CMD.WANT_CLOAK -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- diff --git a/luaui/Widgets/unit_factory_quota.lua b/luaui/Widgets/unit_factory_quota.lua index d2e814e314d..ec09dd8bf88 100644 --- a/luaui/Widgets/unit_factory_quota.lua +++ b/luaui/Widgets/unit_factory_quota.lua @@ -14,8 +14,6 @@ function widget:GetInfo() } end -VFS.Include('luarules/configs/customcmds.h.lua') - local maxBuildProg = 0.075 -- maximum build progress that gets replaced in a repeat queue local maxMetal = 500 -- maximum metal cost that gets replaced in a repeat queue(7.5% of a juggernaut is still over 2k metal) @@ -52,6 +50,7 @@ local CMD_INSERT = CMD.INSERT local CMD_OPT_ALT = CMD.OPT_ALT local CMD_OPT_CTRL = CMD.OPT_CTRL local CMD_OPT_INTERNAL = CMD.OPT_INTERNAL +local CMD_QUOTA_BUILD_TOGGLE = CMD.QUOTA_BUILD_TOGGLE ----- --------- quota logic ------------- diff --git a/modules/customcommands.lua b/modules/customcommands.lua new file mode 100644 index 00000000000..5c9b9db3793 --- /dev/null +++ b/modules/customcommands.lua @@ -0,0 +1,74 @@ +-------------------------------------------------------------------------------- +-- +-- Proposed Command ID Ranges: +-- +-- all negative: Engine (build commands) +-- 0 - 999: Engine +-- 1000 - 9999: Group AI +-- 10000 - 19999: LuaUI +-- 20000 - 29999: LuaCob +-- 30000 - 39999: LuaRules +-- + +-- if you add a command, please order it by ID! + +local gameCommands = { + FACTORY_GUARD = 13921, + AREA_GUARD = 13922, + STOP_PRODUCTION = 13923, + + -- blueprint + BLUEPRINT_PLACE = 18200, + BLUEPRINT_CREATE = 18201, + + -- quota + QUOTA_BUILD_TOGGLE = 23000, + + AREA_MEX = 30100, + SELL_UNIT = 30101, + MORPH = 31210, + MANUAL_LAUNCH = 32102, + UNIT_SET_TARGET_NO_GROUND = 34922, -- unit_target_on_the_move + UNIT_SET_TARGET = 34923, + UNIT_CANCEL_TARGET = 34924, + UNIT_SET_TARGET_RECTANGLE = 34925, + PRIORITY = 34571, + WANT_CLOAK = 37382, + HOUND_WEAPON_TOGGLE = 37383, + SMART_TOGGLE = 37384, + + -- terraform + RESTORE = 39739, + + RAW_MOVE = 39812, +} + +local globalCmdDeprecatedShown = false + +local importCommandsToObject = function(object) + if not globalCmdDeprecatedShown and not object.gadgetHandler then + local msg = 'Should not use customcmds.h.lua or importCommandsToObject. Use the CMD table directly, or read modules/customcommands.lua for more information.' + Spring.Log('CMD', LOG.DEPRECATED, msg) + globalCmdDeprecatedShown = true + end + for code, cmdID in pairs(gameCommands) do + object['CMD_' .. code] = cmdID + end + +end + +local injectIntoCMD = function() + for code, cmdID in pairs(gameCommands) do + if CMD[cmdID] then + Spring.Log('CMD', LOG.ERROR, 'Duplicate command id: ' .. code .. ' ' .. tostring(cmdID) .. '!') + end + CMD[code] = cmdID + CMD[cmdID] = code + end +end + +return { + gameCMD = gameCommands, + importCommandsToObject = importCommandsToObject, + injectIntoCMD = injectIntoCMD, + }