@@ -31,21 +31,21 @@ INTERESTING_FLAGS = {
31
31
seized = ' Goods seized' ,
32
32
offended = ' Offended'
33
33
}
34
- caravans = df .global .ui .caravans
34
+ local caravans = df .global .ui .caravans
35
35
36
- function caravans_from_ids (ids )
36
+ local function caravans_from_ids (ids )
37
37
if not ids or # ids == 0 then
38
- return pairs ( caravans )
38
+ return caravans
39
39
end
40
- local i = 0
41
- return function ()
42
- i = i + 1
43
- local id = tonumber (ids [ i ] )
40
+
41
+ local c = {} -- as:df.caravan_state[]
42
+ for _ , id in ipairs ( ids ) do
43
+ local id = tonumber (id )
44
44
if id then
45
- return id , caravans [id ]
45
+ c [ id ] = caravans [id ]
46
46
end
47
- return nil
48
47
end
48
+ return c
49
49
end
50
50
51
51
function bring_back (car )
@@ -54,9 +54,7 @@ function bring_back(car)
54
54
end
55
55
end
56
56
57
- commands = {}
58
-
59
- function commands .list ()
57
+ local function list ()
60
58
for id , car in pairs (caravans ) do
61
59
print (dfhack .df2console ((' %d: %s caravan from %s' ):format (
62
60
id ,
@@ -73,32 +71,42 @@ function commands.list()
73
71
end
74
72
end
75
73
76
- function commands . extend (days , ...)
74
+ local function extend (days , ...)
77
75
days = tonumber (days or 7 ) or qerror (' invalid number of days: ' .. days )
78
- for id , car in caravans_from_ids {... } do
76
+ for id , car in pairs ( caravans_from_ids {... }) do
79
77
car .time_remaining = car .time_remaining + (days * 120 )
80
78
bring_back (car )
81
79
end
82
80
end
83
81
84
- function commands . happy (...)
85
- for id , car in caravans_from_ids {... } do
82
+ local function happy (...)
83
+ for id , car in pairs ( caravans_from_ids {... }) do
86
84
-- all flags default to false
87
85
car .flags .whole = 0
88
86
bring_back (car )
89
87
end
90
88
end
91
89
92
- function commands . leave (...)
93
- for id , car in caravans_from_ids {... } do
90
+ local function leave (...)
91
+ for id , car in pairs ( caravans_from_ids {... }) do
94
92
car .trade_state = df .caravan_state .T_trade_state .Leaving
95
93
end
96
94
end
97
95
98
96
function main (...)
99
- args = {... }
100
- command = table.remove (args , 1 )
101
- commands [command ](table.unpack (args ))
97
+ local args = {... }
98
+ local command = table.remove (args , 1 )
99
+ if command == " list" then
100
+ list (table.unpack (args ))
101
+ elseif command == " extend" then
102
+ extend (table.unpack (args ))
103
+ elseif command == " happy" then
104
+ happy (table.unpack (args ))
105
+ elseif command == " leave" then
106
+ leave (table.unpack (args ))
107
+ else
108
+ qerror (" No such command: " .. command )
109
+ end
102
110
end
103
111
104
112
if not dfhack_flags .module then
0 commit comments