-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #879 from myk002/myk_sync_windmills
new tool: sync-windmills
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
sync-windmills | ||
============== | ||
|
||
.. dfhack-tool:: | ||
:summary: Synchronize or randomize windmill movement. | ||
:tags: fort buildings | ||
|
||
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 | ||
----- | ||
|
||
:: | ||
|
||
sync-windmills [<options>] | ||
|
||
Examples | ||
-------- | ||
|
||
``sync-windmills`` | ||
Synchronize movement of all active windmills. | ||
``sync-windmills -r`` | ||
Randomize the movement of all active windmills. | ||
|
||
Options | ||
------- | ||
|
||
``-q``, ``--quiet`` | ||
Suppress non-error console output. | ||
``-r``, ``--randomize`` | ||
Randomize the polarity and timer value for all windmills. | ||
``-t``, ``--timing-only`` | ||
Randomize windmill polarity, but synchronize windmill timers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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.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 }, | ||
{ '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(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( | ||
#df.global.world.buildings.other.WINDMILL, | ||
opts.randomize and 'randomized' or 'synchronized')) | ||
end |