Skip to content

Commit

Permalink
immobile_builder: Get just the last command. (#4018)
Browse files Browse the repository at this point in the history
Get just the last command.
  • Loading branch information
saurtron authored Dec 13, 2024
1 parent 105babf commit 586a2ee
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions luaui/Widgets/unit_immobile_builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ local spGetUnitPosition = Spring.GetUnitPosition
local spGiveOrderToUnit = Spring.GiveOrderToUnit
local spGetCommandQueue = Spring.GetCommandQueue
local spGetSpectatingState = Spring.GetSpectatingState
local spGetUnitCurrentCommand = Spring.GetUnitCurrentCommand

local hmsx = Game.mapSizeX/2
local hmsz = Game.mapSizeZ/2
Expand Down Expand Up @@ -132,10 +133,13 @@ end

function widget:UnitCommand(unitID, unitDefID, _, cmdID, _, cmdOpts)
if isImmobileBuilder[unitDefID] and cmdOpts.shift and cmdID ~= CMD_FIGHT then
local commandQueue = spGetCommandQueue(unitID, -1)
local lastCommand = commandQueue[#commandQueue]
if lastCommand and lastCommand.id == CMD_FIGHT then
spGiveOrderToUnit(unitID, CMD.REMOVE, { lastCommand.tag }, 0)
local count = spGetCommandQueue(unitID, 0)
if count == 0 then
return
end
local cmdID, opts, tag = spGetUnitCurrentCommand(unitID, count)
if cmdID and cmdID == CMD_FIGHT then
spGiveOrderToUnit(unitID, CMD.REMOVE, { tag }, 0)
end
end
end
Expand Down

0 comments on commit 586a2ee

Please sign in to comment.