-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathsync-windmills.lua
37 lines (32 loc) · 1.12 KB
/
sync-windmills.lua
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
local argparse = require('argparse')
local function process_windmills(rotate_fn, timer_fn)
for _, bld in ipairs(df.global.world.buildings.other.WINDMILL) do
if bld.is_working ~= 0 then
bld.rotation = rotate_fn()
bld.rotate_timer = timer_fn()
end
end
end
local opts = {}
argparse.processArgsGetopt({...}, {
{ 'h', 'help', handler = function() opts.help = true end },
{ 'q', 'quiet', handler = function() opts.quiet = true end },
{ 'r', 'randomize', handler = function() opts.randomize = true end },
{ 't', 'timing-only', handler = function() opts.timing = true end },
})
if opts.help then
print(dfhack.script_help())
return
end
process_windmills(
(opts.randomize or opts.timing) and
function() return math.random(0, 1) end or
function() return 0 end,
opts.randomize and not opts.timing and
function() return math.random(0, 74) end or
function() return 0 end)
if not opts.quiet then
print(('%d windmills %s'):format(
#df.global.world.buildings.other.WINDMILL,
opts.randomize and 'randomized' or 'synchronized'))
end