@@ -76,15 +76,17 @@ Arguments::
76
76
local utils = require ' utils'
77
77
local eventful = require ' plugins.eventful'
78
78
79
- outcomeLists = outcomeLists or {}
79
+ -- luacheck: global
80
+ outcomeLists = outcomeLists or {} -- as:{total:number,outcomes:'{weight:number,command:__arg}[]'}[]
81
+ -- luacheck: global
80
82
randomGen = randomGen or dfhack .random .new ()
81
83
82
84
eventful .enableEvent (eventful .eventType .UNLOAD , 1 )
83
85
eventful .onUnload .randomTrigger = function ()
84
86
outcomeLists = {}
85
87
end
86
88
87
- validArgs = utils .invert ({
89
+ local validArgs = utils .invert ({
88
90
' help' ,
89
91
' command' ,
90
92
' outcomeListName' ,
@@ -132,11 +134,11 @@ end
132
134
if args .weight and not tonumber (args .weight ) then
133
135
error (' Invalid weight: ' .. args .weight )
134
136
end
135
- args . weight = (args .weight and tonumber (args .weight )) or 1
136
- if args . weight ~= math.floor (args . weight ) then
137
+ local weight = (args .weight and tonumber (args .weight )) or 1
138
+ if weight ~= math.floor (weight ) then
137
139
error ' Noninteger weight.'
138
140
end
139
- if args . weight < 0 then
141
+ if weight < 0 then
140
142
error ' invalid weight: must be non-negative'
141
143
end
142
144
@@ -148,11 +150,11 @@ args.outcomeListName = args.outcomeListName or ''
148
150
args .outcomeListName = ' outcomeList ' .. args .outcomeListName
149
151
150
152
if args .withProbability then
151
- args . withProbability = tonumber (args .withProbability )
152
- if not args . withProbability or args . withProbability < 0 or args . withProbability > 1 then
153
- error (' Invalid withProbability: ' .. (args . withProbability or ' nil' ))
153
+ local withProbability = tonumber (args .withProbability )
154
+ if not withProbability or withProbability < 0 or withProbability > 1 then
155
+ error (' Invalid withProbability: ' .. (withProbability or ' nil' ))
154
156
end
155
- if randomGen :drandom () < args . withProbability then
157
+ if randomGen :drandom () < withProbability then
156
158
dfhack .run_command (table.unpack (args .command ))
157
159
end
158
160
end
@@ -190,9 +192,9 @@ if not outcomeList then
190
192
outcomeList = outcomeLists [args .outcomeListName ]
191
193
end
192
194
193
- outcomeList .total = args . weight + (outcomeList .total or 0 )
194
- local outcome = {}
195
- outcome .weight = args . weight
195
+ outcomeList .total = weight + (outcomeList .total or 0 )
196
+ local outcome = {} -- as:{weight:number,command:__arg}
197
+ outcome .weight = weight
196
198
outcome .command = args .command
197
199
outcomeList .outcomes = outcomeList .outcomes or {}
198
200
table.insert (outcomeList .outcomes , outcome )
0 commit comments