Skip to content

Commit

Permalink
factory stop production: removed broken/unused code (#4206)
Browse files Browse the repository at this point in the history
small performance improvement
  • Loading branch information
Ruwetuin authored Jan 24, 2025
1 parent a7f49f5 commit 1e180e8
Showing 1 changed file with 8 additions and 45 deletions.
53 changes: 8 additions & 45 deletions luarules/gadgets/cmd_factory_stop_production.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function gadget:GetInfo()
return {
name = "Factory Stop Production",
Expand All @@ -12,22 +9,18 @@ function gadget:GetInfo()
enabled = true,
}
end
if gadgetHandler:IsSyncedCode() then

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local identifier = "StopProduction"

include("luarules/configs/customcmds.h.lua")
include("luarules/configs/customcmds.h.lua")

local isFactory = {}
for udid = 1, #UnitDefs do
local ud = UnitDefs[udid]
if ud.isFactory then
isFactory[udid] = true
local isFactory = {}
for udid = 1, #UnitDefs do
local ud = UnitDefs[udid]
if ud.isFactory then
isFactory[udid] = true
end
end
end

if gadgetHandler:IsSyncedCode() then
local spGetRealBuildQueue = Spring.GetRealBuildQueue
local spGiveOrderToUnit = Spring.GiveOrderToUnit
local spInsertUnitCmdDesc = Spring.InsertUnitCmdDesc
Expand All @@ -36,9 +29,6 @@ if gadgetHandler:IsSyncedCode() then
local EMPTY = {}
local DEQUEUE_OPTS = { "right", "ctrl", "shift" } -- right: dequeue, ctrl+shift: 100

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

local stopProductionCmdDesc = {
id = CMD_STOP_PRODUCTION,
type = CMDTYPE.ICON,
Expand All @@ -48,10 +38,6 @@ if gadgetHandler:IsSyncedCode() then
tooltip = "Stop Production: Clear factory production queue.",
}

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Handle the command

function gadget:AllowCommand_GetWantedCommand()
return { [CMD_STOP_PRODUCTION] = true }
end
Expand Down Expand Up @@ -88,25 +74,19 @@ if gadgetHandler:IsSyncedCode() then
-- Dequeue build order by sending build command to factory to minimize number of commands sent
-- As opposed to removing each build command individually
local queue = spGetRealBuildQueue(unitID)

if queue ~= nil then
for _, buildPair in ipairs(queue) do
local buildUnitDefID, count = next(buildPair, nil)

orderDequeue(unitID, buildUnitDefID, count)
end
end

spGiveOrderToUnit(unitID, CMD_WAIT, EMPTY, 0) -- Removes wait if there is a wait but doesn't readd it.
spGiveOrderToUnit(unitID, CMD_WAIT, EMPTY, 0) -- If a factory is waiting, it will not clear the current build command, even if the cmd is removed.
-- See: http://zero-k.info/Forum/Post/237176#237176 for details.
SendToUnsynced(identifier, unitID, unitDefID, unitTeam, cmdID)
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Add the command to factories

function gadget:UnitCreated(unitID, unitDefID)
if isFactory[unitDefID] then
spInsertUnitCmdDesc(unitID, stopProductionCmdDesc)
Expand All @@ -120,21 +100,4 @@ if gadgetHandler:IsSyncedCode() then
gadget:UnitCreated(unitID, Spring.GetUnitDefID(unitID))
end
end
else
local myTeamID, isSpec

function gadget:PlayerChanged()
myTeamID = Spring.GetMyTeamID()
isSpec = Spring.GetSpectatingState()
end

function gadget:Initialize()
gadget:PlayerChanged()
end

function gadget:RecvFromSynced(messageID, unitID, unitDefID, unitTeam, cmdID)
if messageID == identifier and (Spring.AreTeamsAllied(unitTeam, myTeamID) or isSpec) then
Script.LuaUI.UnitCommand(unitID, unitDefID, unitTeam, cmdID, {}, {coded = 0})
end
end
end

0 comments on commit 1e180e8

Please sign in to comment.