-
Notifications
You must be signed in to change notification settings - Fork 330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Standardize factory alt behavior #4177
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||||
function widget:GetInfo() | ||||||||
return { | ||||||||
name = "Factory Alt Behavior", | ||||||||
desc = "Queueing with alt in a factory won't cancel the current command.", | ||||||||
author = "hihoman23", | ||||||||
date = "Jan 2025", | ||||||||
license = "GNU GPL, v2 or later", | ||||||||
layer = 0, | ||||||||
enabled = true | ||||||||
} | ||||||||
end | ||||||||
|
||||||||
local spGiveOrderToUnit = Spring.GiveOrderToUnit | ||||||||
local spGetSelectedUnits = Spring.GetSelectedUnits | ||||||||
local spGetUnitDefID = Spring.GetUnitDefID | ||||||||
local spGetUnitWorkerTask = Spring.GetUnitWorkerTask | ||||||||
|
||||||||
local CMD_INSERT = CMD.INSERT | ||||||||
local factoryBuildOpts = {} | ||||||||
for unitDefID, unitDef in pairs(UnitDefs) do | ||||||||
if unitDef.isFactory and unitDef.buildOptions then | ||||||||
local opts = {} | ||||||||
for _, opt in pairs(unitDef.buildOptions) do | ||||||||
opts[opt] = true | ||||||||
end | ||||||||
factoryBuildOpts[unitDefID] = opts | ||||||||
end | ||||||||
end | ||||||||
|
||||||||
function widget:CommandNotify(cmdID, cmdParams, cmdOpts) | ||||||||
if cmdID < 0 and cmdOpts.alt and not cmdOpts.right then | ||||||||
local factoryExists = false | ||||||||
for _, unitID in ipairs(spGetSelectedUnits()) do | ||||||||
local unitDefID = spGetUnitDefID(unitID) | ||||||||
if factoryBuildOpts[unitDefID] and factoryBuildOpts[unitDefID][-cmdID] then | ||||||||
factoryExists = true | ||||||||
if not cmdOpts.internal then | ||||||||
cmdOpts.coded = cmdOpts.coded + CMD.OPT_INTERNAL -- prevent repeating command | ||||||||
end | ||||||||
local currentCmdID, targetID = spGetUnitWorkerTask(unitID) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what happens if there is a unit in queue but the factory isn't actually building it (opening animation, area blocked, etc). There may be a minor behaviour difference compared to native engine insert. Sounds fine though. |
||||||||
|
||||||||
-- insert command into wanted position | ||||||||
spGiveOrderToUnit(unitID, CMD_INSERT, {currentCmdID and 1 or 0, cmdID, cmdOpts.coded}, CMD.OPT_CTRL + CMD.OPT_ALT) | ||||||||
end | ||||||||
end | ||||||||
return factoryExists | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In theory this makes any fac in selection eat the entire order for all the other units. Sounds fine though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It only does this if the unit is in the build options, so when it's relevant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but if you have a factory and a mobile unit who both have the same buildoption. Consider: Beyond-All-Reason/units/Legion/Bots/T2 Bots/leginfestor.lua Lines 43 to 44 in 9bb196c
What happens if you have both selected and give a mobile build order while holding alt? Right now it looks like it's going to drop the mobile order but insert it in the factory instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a weird one: in this case the factory already eats the command (in current master), even without alt (in both buildmenus). I would fix this in a future PR. |
||||||||
end | ||||||||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I slightly dislike using INTERNAL over ALT but I suppose that ship had already sailed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What could be done to prevent this? I assume the factory will repeat commands, unless it has INTERNAL in the params.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can skip factories who are on repeat (since they already handle Alt correctly) and then for the remaining non-repeat ones you don't need to add internal since they won't repeat anyway.