Skip to content

Commit

Permalink
add sync-windmills
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Oct 30, 2023
1 parent 996c040 commit 89e0c9c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Template for new versions:
# Future

## New Tools
- `sync-windmills`: synchronize or randomize movement of active windmills

## New Features

Expand Down
32 changes: 32 additions & 0 deletions docs/sync-windmills.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
sync-windmills
==============

.. dfhack-tool::
:summary: Synchronize or randomize windmill movement.
:tags: fort buildings

This tool can adjust the appearance of running windmills so that they are
either all in synchronization or are all completely randomized.

Usage
-----

::

sync-windmills [<options>]

Examples
--------

``sync-windmills``
Make all active windmills synchronize their turning.
``sync-windmills -r``
Randomize the movement of all active windmills.

Options
-------

``-q``, ``--quiet``
Suppress non-error console output.
``-r``, ``--randomize``
Randomize windmill state.
32 changes: 32 additions & 0 deletions sync-windmills.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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.visual_rotated = 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 },
})

if opts.help then
print(dfhack.script_help())
return
end

process_windmills(
opts.randomize and function() return math.random(1, 2) == 1 end or function() return false end,
opts.randomize 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

0 comments on commit 89e0c9c

Please sign in to comment.