-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a command to build a plate to the factory tab in spot BZ aka ro…
…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
Showing
13 changed files
with
276 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
hotspot topleft | ||
frame anims/cursorplate_0.png 0.1 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
hotspot topleft | ||
frame anims/cursorplate_0.png 0.1 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,4 +104,7 @@ return { | |
RESTORE = 39739, | ||
BUMPY = 39740, | ||
TERRAFORM_INTERNAL = 39801, | ||
|
||
-- build plate | ||
PLATE = 39802, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.