forked from DFHack/scripts
-
Notifications
You must be signed in to change notification settings - Fork 4
/
hermit.lua
79 lines (63 loc) · 1.9 KB
/
hermit.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
-- Blocks most types of visitors (caravans, migrants, etc.)
--@ enable=true
--[====[
hermit
======
Blocks all caravans, migrants, diplomats, and forgotten beasts (not wildlife).
Useful for attempting the `hermit challenge`_.
Use ``enable`` or ``disable`` to enable/disable, or ``help`` for this help.
.. warning::
This does not block sieges, and may not block visitors or monarchs.
.. _hermit challenge: http://dwarffortresswiki.org/index.php/DF2014:Playstyle_challenge#Hermit
]====]
local repeat_util = require "repeat-util"
local timed_events = df.global.timed_events
local whitelist = {
[df.timed_event_type.WildlifeCurious] = true,
[df.timed_event_type.WildlifeMischievous] = true,
[df.timed_event_type.WildlifeFlier] = true,
}
enabled = enabled or false
function run()
local tmp_events = {} --as:df.timed_event[]
for _, event in pairs(timed_events) do
table.insert(tmp_events, event)
end
timed_events:resize(0)
for _, event in pairs(tmp_events) do
if whitelist[event.type] then
timed_events:insert('#', event)
else
event:delete()
end
end
end
function enable(state)
if not dfhack.isWorldLoaded() and state then
qerror('This script requires a world to be loaded')
end
enabled = state
if enabled then
repeat_util.scheduleEvery('hermit', 1, 'days', run)
print('hermit enabled')
else
repeat_util.cancel('hermit')
print('hermit disabled')
end
end
function dfhack.onStateChange.hermit(event)
if event == SC_WORLD_UNLOADED then
enable(false)
end
end
local args = {...}
if dfhack_flags.enable then
enable(dfhack_flags.enable_state)
elseif args[1] == 'enable' or args[1] == 'disable' then
enable(args[1] == 'enable')
else
if args[1] ~= 'help' then
dfhack.printerr('Unrecognized argument(s)')
end
print(dfhack.script_help())
end