-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathunit_drawfactoryrally.lua
More file actions
88 lines (79 loc) · 2.05 KB
/
Copy pathunit_drawfactoryrally.lua
File metadata and controls
88 lines (79 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function widget:GetInfo()
return {
name = "Mobile Factory Helper",
desc = "Displays queues of the fake units.",
author = "Shaman",
date = "12 January 2024",
license = "CC-0",
layer = 2500,
enabled = true,
alwaysStart = true,
}
end
local drawCount = 0
local wantDraw = false
local drawThese = {}
local wantedUnits = {}
local watchUnitsForUnselection = {}
local CMD_QUEUE_MODE = 34225
for i = 1, #UnitDefs do
local ud = UnitDefs[i]
if ud.customParams.ismobilefac then
wantedUnits[i] = true
end
end
local spDrawUnitCommands = Spring.DrawUnitCommands
local spGetUnitDefID = Spring.GetUnitDefID
local spGetUnitRulesParam = Spring.GetUnitRulesParam
local watchDefs = {
[UnitDefNames["athena"].id] = true
}
local function CheckForAthenaUnselection(oldselect, newselect)
local notInTab2 = {}
for k, _ in pairs(oldselect) do
if newselect[k] == nil then
Spring.GiveOrderToUnit(k, CMD_QUEUE_MODE, {0}, 0) -- turn off queue mode.
watchUnitsForUnselection[k] = nil
end
end
watchUnitsForUnselection = newselect
end
function widget:UnitDestroyed(unitID)
watchUnitsForUnselection[unitID] = nil
end
function widget:SelectionChanged(selectedUnits)
if not (selectedUnits and selectedUnits[1]) then
CheckForAthenaUnselection(watchUnitsForUnselection, {})
wantDraw = false
return
end
drawCount = 0
local watchUnits = {}
for i = 1, #selectedUnits do
local unitID = selectedUnits[i]
local unitDef = spGetUnitDefID(unitID)
if wantedUnits[unitDef] then
if watchDefs[unitDef] then
watchUnits[unitID] = true
watchUnitsForUnselection[unitID] = true
end
local queueUnit = spGetUnitRulesParam(unitID, "queueunit")
if queueUnit then
drawCount = drawCount + 1
drawThese[drawCount] = spGetUnitRulesParam(unitID, "queueunit")
end
end
end
CheckForAthenaUnselection(watchUnitsForUnselection, watchUnits)
wantDraw = drawCount > 0
end
local function DoDraw()
if wantDraw and drawCount > 0 then
for i = 1, drawCount do
spDrawUnitCommands(drawThese[i])
end
end
end
function widget:DrawWorld()
DoDraw()
end