Skip to content

Commit

Permalink
Added a command to build a plate to the factory tab in spot BZ aka ro…
Browse files Browse the repository at this point in the history
…w 3, column 1. When command is issued, cursor shows a plate icon, and if cursor moves in range of a factory, the active command gets switched to building a plate of that factory.

It's implemented as a generic do-nothing command in LuaRules, and I edited cmd_factory_plate_placer.lua in LuaUI to add the behavior there in a way that does not disrupt the current plating behavior.  This allows it to also use the LuaUI glsl stuff in the current widget, which is familiar and looks nicer.
  • Loading branch information
Dave-tB committed Sep 24, 2021
1 parent a792c41 commit 8747d1d
Show file tree
Hide file tree
Showing 13 changed files with 276 additions and 45 deletions.
2 changes: 2 additions & 0 deletions Anims/cursorplate.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hotspot topleft
frame anims/cursorplate_0.png 0.1
Binary file added Anims/cursorplate_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Anims/zk_large/cursorplate.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hotspot topleft
frame anims/cursorplate_0.png 0.1
Binary file added Anims/zk_large/cursorplate_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions LuaRules/Configs/customcmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,7 @@ return {
RESTORE = 39739,
BUMPY = 39740,
TERRAFORM_INTERNAL = 39801,

-- build plate
PLATE = 39802,
}
124 changes: 124 additions & 0 deletions LuaRules/Gadgets/cmd_generic_plate.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function gadget:GetInfo()
return {
name = "Generic Plate Command",
desc = "Implements CMD_PLATE as a do-nothing command, behaviour is defined in LuaUI",
author = "DavetheBrave",
date = "23 September 2021",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = true,
}
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Speedup
include("LuaRules/Configs/customcmds.h.lua")

if gadgetHandler:IsSyncedCode() then

local spInsertUnitCmdDesc = Spring.InsertUnitCmdDesc
local spGetUnitAllyTeam = Spring.GetUnitAllyTeam
local spGetUnitIsDead = Spring.GetUnitIsDead

local constructors = 0
local constructor = {}
local constructorTable = {}
local constructors = 0


local exceptionArray = {
[UnitDefNames["athena"].id] = true,
}
local plateCmdDesc = {
id = CMD_PLATE,
type = CMDTYPE.ICON_MAP,
name = 'plate',
cursor = 'Plate',
action = 'plate',
tooltip = 'Build a Plate of a nearby factory',
}

local wantedCommands = {
[CMD_PLATE] = true,
}

function gadget:AllowCommand_GetWantedCommand()
return wantedCommands
end

function gadget:AllowCommand_GetWantedUnitDefID()
return true
end

-- local function dump(o)
-- if type(o) == 'table' then
-- local s = '{ '
-- for k,v in pairs(o) do
-- if type(k) ~= 'number' then k = '"'..k..'"' end
-- s = s .. '['..k..'] = ' .. dump(v) .. ','
-- end
-- return s .. '} '
-- else
-- return tostring(o)
-- end
-- end

local plateUnitDefIDs = {}
for i = 1, #UnitDefs do
local ud = UnitDefs[i]
if ud and ud.isMobileBuilder and not ud.isFactory and not exceptionArray[i] then
plateUnitDefIDs[i] = true
end
end

function gadget:AllowCommand(unitID, unitDefID, teamID, cmdID, cmdParams, cmdOptions)
-- Don't allow non-constructors to queue terraform fallback.
if not plateUnitDefIDs[unitDefID] then
return false
end
return true
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
end

function gadget:UnitCreated(unitID, unitDefID, teamID)
if spGetUnitIsDead(unitID) then
return
end

local ud = UnitDefs[unitDefID]
-- add plate command to builders
if plateUnitDefIDs[unitDefID] then
spInsertUnitCmdDesc(unitID, plateCmdDesc)
local aTeam = spGetUnitAllyTeam(unitID)
constructors = constructors + 1
constructorTable[constructors] = unitID
constructor[unitID] = {allyTeam = aTeam, index = constructors}
end
end

function gadget:UnitDestroyed(unitID, unitDefID, teamID)
if constructor[unitID] then
local index = constructor[unitID].index
if index ~= constructors then
constructorTable[index] = constructorTable[constructors]
end
constructorTable[constructors] = nil
constructors = constructors - 1
constructor[unitID] = nil
end
end

function gadget:Initialize()
gadgetHandler:RegisterCMDID(CMD_PLATE)
end

else
function gadget:Initialize()
Spring.AssignMouseCursor("Plate", "cursorplate", true, true)
end
end
3 changes: 3 additions & 0 deletions LuaUI/Configs/border_menu_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ local buildoptions = {
{ "platetank", notSea=true },

{ "striderhub" },
{CMD_PLATE, tech=3 },
},

{-- economy
Expand Down Expand Up @@ -215,6 +216,7 @@ local overrides = {
[CMD_SMOOTH] = {texture = imageDir .. 'smooth.png'},
[CMD_RESTORE] = {texture = imageDir .. 'restore.png'},
[CMD_BUMPY] = {texture = imageDir .. 'bumpy.png'},
[CMD_PLATE] = {texture = imageDir .. 'plate.png'},

[CMD_AREA_MEX] = {caption = '', texture = imageDir .. 'Bold/mex.png'},
[CMD_AREA_TERRA_MEX] = {caption = '', texture = imageDir .. 'Bold/mex.png'},
Expand Down Expand Up @@ -333,6 +335,7 @@ local custom_cmd_actions = { -- states are 2, not states are 1
smoothground=1,
restoreground=1,
--terraform_internal=1,
plate=1,

resetfire=1,
resetmove=1,
Expand Down
4 changes: 4 additions & 0 deletions LuaUI/Configs/customCmdTypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ local custom_cmd_actions = {
restoreground = {cmdType = 1, name = "Terraform Restore"},
--terraform_internal = {cmdType = 1, name = "--terraform_internal"},

--build a "generic" plate from build factory menu
plate = {cmdType = 1, name = "plate"},

resetfire = {cmdType = 3, name = "Reset Fire"},
resetmove = {cmdType = 3, name = "Reset Move"},

Expand Down Expand Up @@ -163,6 +166,7 @@ local usedActions = {
["raiseground"] = true,
["smoothground"] = true,
["restoreground"] = true,
["buildplate"] = true,
["jump"] = true,
["idlemode"] = true,
["areaattack"] = true,
Expand Down
3 changes: 3 additions & 0 deletions LuaUI/Configs/integral_menu_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ local cmdPosDef = {
[CMD_AREA_GUARD] = {pos = 1, priority = 10},
[CMD.AREA_ATTACK] = {pos = 1, priority = 11},

--[CMD_PLATE] = {pos = 7, priority = 12},

[CMD_UPGRADE_UNIT] = {pos = 7, priority = -8},
[CMD_UPGRADE_STOP] = {pos = 7, priority = -7},
[CMD_MORPH] = {pos = 7, priority = -6},
Expand Down Expand Up @@ -290,6 +292,7 @@ local factory_commands = {
factoryamph = {order = 10, row = 2, col = 4},
factoryship = {order = 11, row = 2, col = 5},
striderhub = {order = 12, row = 2, col = 6},
[CMD_PLATE] = {order = 13, row = 3, col = 1},
}

local econ_commands = {
Expand Down
13 changes: 12 additions & 1 deletion LuaUI/Configs/integral_menu_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ local commandDisplayConfig = {
[CMD_SMOOTH] = {texture = imageDir .. 'smooth.png'},
[CMD_RESTORE] = {texture = imageDir .. 'restore.png'},
[CMD_BUMPY] = {texture = imageDir .. 'bumpy.png'},
[CMD_PLATE] = {texture = imageDir .. 'plate.png'},

[CMD_AREA_GUARD] = { texture = imageDir .. 'Bold/guard.png', tooltip = "Guard: Protect the target and assist its production."},

Expand Down Expand Up @@ -421,12 +422,20 @@ for i = 1, 5 do
}
end

local factoryButtonLayoutOverride = {}
factoryButtonLayoutOverride[1] = {
[3] = {
buttonLayoutConfig = buttonLayoutConfig.command,
isStructure = false,
}
}

local commandPanels = {
{
humanName = "Orders",
name = "orders",
inclusionFunction = function(cmdID)
return cmdID >= 0 and not buildCmdSpecial[cmdID] -- Terraform
return cmdID >= 0 and not buildCmdFactory[cmdID] and not buildCmdSpecial[cmdID]-- Terraform and Plate
end,
loiterable = true,
buttonLayoutConfig = buttonLayoutConfig.command,
Expand Down Expand Up @@ -484,10 +493,12 @@ local commandPanels = {
end,
isBuild = true,
isStructure = true,
notBuildRow = 3,
gridHotkeys = true,
returnOnClick = "orders",
optionName = "tab_factory",
buttonLayoutConfig = buttonLayoutConfig.build,
buttonLayoutOverride = factoryButtonLayoutOverride,
},
{
humanName = "Units",
Expand Down
Binary file added LuaUI/Images/commands/plate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8747d1d

Please sign in to comment.