Skip to content

Commit

Permalink
add --timing-only option for synchronizing timing but not polarity
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Oct 30, 2023
1 parent 89e0c9c commit 6159990
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
17 changes: 13 additions & 4 deletions docs/sync-windmills.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ sync-windmills
: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.
Windmills cycle between two graphical states to simulate movement. This is the
polarity of the appearance. Each windmill also has a timer that controls when
the windmill switches polarity. Each windmill's timer starts from zero at the
instant that it is built, so two different windmills will rarely have exactly
the same state. This tool can adjust the alignment of polarity and timers
across your active windmills to your preference.

Note that this tool will not affect windmills that have just been activated and
are still rotating to adjust to the regional wind direction.

Usage
-----
Expand All @@ -19,7 +26,7 @@ Examples
--------

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

Expand All @@ -29,4 +36,6 @@ Options
``-q``, ``--quiet``
Suppress non-error console output.
``-r``, ``--randomize``
Randomize windmill state.
Randomize the polarity and timer value for all windmills.
``-t``, ``--timing-only``
Randomize windmill polarity, but synchronize windmill timers.
9 changes: 7 additions & 2 deletions sync-windmills.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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
Expand All @@ -22,8 +23,12 @@ if opts.help then
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)
(opts.randomize or opts.timing) and
function() return math.random(1, 2) == 1 end or
function() return false 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(
Expand Down

0 comments on commit 6159990

Please sign in to comment.