Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ local commonFunctions = {
LuaUI = true,
},

cmd = {
LuaRules = true,
LuaUI = true,
},

map = {
LuaRules = true,
LuaUI = true,
Expand All @@ -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")
Expand Down
42 changes: 2 additions & 40 deletions luarules/configs/customcmds.h.lua
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions luarules/gadgets/cmd_alliance_break.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions luarules/gadgets/cmd_factory_stop_production.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions luarules/gadgets/unit_factory_guard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 4 additions & 13 deletions luarules/gadgets/unit_target_on_the_move.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions luarules/gadgets/unit_timeslow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions luarules/gadgets/unit_weapon_smart_select_helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 3 additions & 5 deletions luaui/Tests/cmd_blueprint/test_cmd_blueprint_line.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ end

local delay = 5
function test()
VFS.Include("luarules/configs/customcmds.h.lua")

widget = widgetHandler:FindWidget(widgetName)
assert(widget)

Expand Down Expand Up @@ -66,7 +64,7 @@ function test()

Test.waitFrames(delay)

widget:CommandNotify(CMD_BLUEPRINT_CREATE, {}, {})
widget:CommandNotify(CMD.BLUEPRINT_CREATE, {}, {})

assert(#(widget.blueprints) == 1)

Expand All @@ -88,7 +86,7 @@ function test()
Test.waitFrames(delay)

Spring.SetActiveCommand(
Spring.GetCmdDescIndex(CMD_BLUEPRINT_PLACE),
Spring.GetCmdDescIndex(CMD.BLUEPRINT_PLACE),
1,
true,
false,
Expand Down Expand Up @@ -121,7 +119,7 @@ function test()

Test.waitFrames(delay)

widget:CommandNotify(CMD_BLUEPRINT_PLACE, {}, {})
widget:CommandNotify(CMD.BLUEPRINT_PLACE, {}, {})
mockSpringGetMouseState.remove()

Test.waitFrames(delay)
Expand Down
8 changes: 3 additions & 5 deletions luaui/Tests/cmd_blueprint/test_cmd_blueprint_single.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ end

local delay = 5
function test()
VFS.Include("luarules/configs/customcmds.h.lua")

widget = widgetHandler:FindWidget(widgetName)
assert(widget)

Expand Down Expand Up @@ -62,7 +60,7 @@ function test()

Test.waitFrames(delay)

widget:CommandNotify(CMD_BLUEPRINT_CREATE, {}, {})
widget:CommandNotify(CMD.BLUEPRINT_CREATE, {}, {})

assert(#(widget.blueprints) == 1)

Expand All @@ -84,7 +82,7 @@ function test()
Test.waitFrames(delay)

Spring.SetActiveCommand(
Spring.GetCmdDescIndex(CMD_BLUEPRINT_PLACE),
Spring.GetCmdDescIndex(CMD.BLUEPRINT_PLACE),
1,
true,
false,
Expand All @@ -103,7 +101,7 @@ function test()

Test.waitFrames(delay)

widget:CommandNotify(CMD_BLUEPRINT_PLACE, {}, {})
widget:CommandNotify(CMD.BLUEPRINT_PLACE, {}, {})

Test.waitFrames(delay)

Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/cmd_area_mex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions luaui/Widgets/cmd_blueprint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ function widget:GetInfo()
}
end

VFS.Include("luarules/configs/customcmds.h.lua")

-- types
-- =====

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions luaui/Widgets/cmd_customformations2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/cmd_default_set_target.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/cmd_factory_guard_pref.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions luaui/Widgets/gui_attack_aoe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ function widget:GetInfo()
}
end

VFS.Include('luarules/configs/customcmds.h.lua')

--------------------------------------------------------------------------------
--config
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion luaui/Widgets/gui_buildmenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions luaui/Widgets/gui_commands_fx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/gui_gridmenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion luaui/Widgets/gui_unit_market.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/unit_builder_priority.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions luaui/Widgets/unit_cloak_firestate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Expand Down
Loading