summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--README.rst8
-rw-r--r--scripts/siren.lua109
3 files changed, 118 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 22f64d7d..d46c47e6 100644
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,7 @@ DFHack v0.34.11-r2 (UNRELEASED)
New scripts:
- fixnaked: removes thoughts about nakedness.
- setfps: set FPS cap at runtime, in case you want slow motion or speed-up.
+ - siren: wakes up units, stops breaks and parties - but causes bad thoughts.
- fix/population-cap: run after every migrant wave to prevent exceeding the cap.
- fix/stable-temp: counts items with temperature updates; does instant one-shot stable-temp.
New GUI scripts:
diff --git a/README.rst b/README.rst
index b0258bb3..97eb61a8 100644
--- a/README.rst
+++ b/README.rst
@@ -1539,6 +1539,14 @@ setfps
Run ``setfps <number>`` to set the FPS cap at runtime, in case you want to watch
combat in slow motion or something :)
+siren
+=====
+
+Wakes up sleeping units, cancels breaks and stops parties either everywhere,
+or in the burrows given as arguments. In return, adds bad thoughts about
+noise and tiredness. Also, the units with interrupted breaks will go on
+break again a lot sooner.
+
growcrops
=========
Instantly grow seeds inside farming plots.
diff --git a/scripts/siren.lua b/scripts/siren.lua
new file mode 100644
index 00000000..5371e3d7
--- /dev/null
+++ b/scripts/siren.lua
@@ -0,0 +1,109 @@
+-- Wakes up the sleeping, breaks up parties and stops breaks.
+
+local utils = require 'utils'
+
+local args = {...}
+local burrows = {}
+local bnames = {}
+
+if not dfhack.isMapLoaded() then
+ qerror('Map is not loaded.')
+end
+
+for _,v in ipairs(args) do
+ local b = dfhack.burrows.findByName(v)
+ if not b then
+ qerror('Unknown burrow: '..v)
+ end
+ table.insert(bnames, v)
+ table.insert(burrows, b)
+end
+
+function is_in_burrows(pos)
+ if #burrows == 0 then
+ return true
+ end
+ for _,v in ipairs(burrows) do
+ if dfhack.burrows.isAssignedTile(v, pos) then
+ return true
+ end
+ end
+end
+
+function add_thought(unit, code)
+ for _,v in ipairs(unit.status.recent_events) do
+ if v.type == code then
+ v.age = 0
+ return
+ end
+ end
+
+ unit.status.recent_events:insert('#', { new = true, type = code })
+end
+
+function wake_unit(unit)
+ local job = unit.job.current_job
+ if not job or job.job_type ~= df.job_type.Sleep then
+ return
+ end
+
+ if job.completion_timer > 0 then
+ unit.counters.unconscious = 0
+ add_thought(unit, df.unit_thought_type.SleepNoiseWake)
+ elseif job.completion_timer < 0 then
+ add_thought(unit, df.unit_thought_type.Tired)
+ end
+
+ job.pos:assign(unit.pos)
+
+ job.completion_timer = 0
+
+ unit.path.dest:assign(unit.pos)
+ unit.path.path.x:resize(0)
+ unit.path.path.y:resize(0)
+ unit.path.path.z:resize(0)
+
+ unit.counters.job_counter = 0
+end
+
+function stop_break(unit)
+ local counter = dfhack.units.getMiscTrait(unit, df.misc_trait_type.OnBreak)
+ if counter then
+ counter.id = df.misc_trait_type.TimeSinceBreak
+ counter.value = 100800 - 30*1200
+ add_thought(unit, df.unit_thought_type.Tired)
+ end
+end
+
+-- Stop rest
+for _,v in ipairs(df.global.world.units.active) do
+ local x,y,z = dfhack.units.getPosition(v)
+ if x and not dfhack.units.isDead(v) and is_in_burrows(xyz2pos(x,y,z)) then
+ wake_unit(v)
+ stop_break(v)
+ end
+end
+
+-- Stop parties
+for _,v in ipairs(df.global.ui.parties) do
+ local pos = utils.getBuildingCenter(v.location)
+ if is_in_burrows(pos) then
+ v.timer = 0
+ for _, u in ipairs(v.units) do
+ add_thought(unit, df.unit_thought_type.Tired)
+ end
+ end
+end
+
+local place = 'the halls and tunnels'
+if #bnames > 0 then
+ if #bnames == 1 then
+ place = bnames[1]
+ else
+ place = table.concat(bnames,', ',1,#bnames-1)..' and '..bnames[#bnames]
+ end
+end
+dfhack.gui.showAnnouncement(
+ 'A loud siren sounds throughout '..place..', waking the sleeping and startling the awake.',
+ COLOR_BROWN, true
+)