2015-11-09 19:21:00 -07:00
|
|
|
-- Wakes up the sleeping, ends breaks and parties
|
2015-10-23 22:10:15 -06:00
|
|
|
--[[=begin
|
|
|
|
|
|
|
|
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, tiredness and lack of protection. Also, the units with interrupted
|
|
|
|
breaks will go on break again a lot sooner. The script is intended for
|
|
|
|
emergencies, e.g. when a siege appears, and all your military is partying.
|
|
|
|
|
|
|
|
=end]]
|
2012-09-22 11:00:13 -06:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2012-09-24 10:01:53 -06:00
|
|
|
local in_siege = false
|
|
|
|
|
2012-09-22 11:00:13 -06:00
|
|
|
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
|
|
|
|
|
2015-01-05 06:33:10 -07:00
|
|
|
function add_thought(unit, emotion, thought)
|
|
|
|
unit.status.current_soul.personality.emotions:insert('#', { new = true,
|
|
|
|
type = emotion,
|
|
|
|
unk2=1,
|
|
|
|
strength=1,
|
|
|
|
thought=thought,
|
|
|
|
subthought=0,
|
|
|
|
severity=0,
|
|
|
|
flags=0,
|
|
|
|
unk7=0,
|
|
|
|
year=df.global.cur_year,
|
|
|
|
year_tick=df.global.cur_year_tick})
|
2012-09-22 11:00:13 -06:00
|
|
|
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
|
2015-01-05 06:33:10 -07:00
|
|
|
add_thought(unit, df.emotion_type.Grouchiness, df.unit_thought_type.Drowsy)
|
2012-09-22 11:00:13 -06:00
|
|
|
elseif job.completion_timer < 0 then
|
2015-01-05 06:33:10 -07:00
|
|
|
add_thought(unit, df.emotion_type.Grumpiness, df.unit_thought_type.Drowsy)
|
2012-09-22 11:00:13 -06:00
|
|
|
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
|
2015-01-05 06:33:10 -07:00
|
|
|
add_thought(unit, df.emotion_type.Grumpiness, df.unit_thought_type.Drowsy)
|
2012-09-22 11:00:13 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-24 10:01:53 -06:00
|
|
|
-- Check siege for thought purpose
|
|
|
|
for _,v in ipairs(df.global.ui.invasions.list) do
|
|
|
|
if v.flags.siege and v.flags.active then
|
|
|
|
in_siege = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-22 11:00:13 -06:00
|
|
|
-- Stop rest
|
|
|
|
for _,v in ipairs(df.global.world.units.active) do
|
|
|
|
local x,y,z = dfhack.units.getPosition(v)
|
2012-09-24 10:01:53 -06:00
|
|
|
if x and dfhack.units.isCitizen(v) and is_in_burrows(xyz2pos(x,y,z)) then
|
2012-10-20 14:35:39 -06:00
|
|
|
if not in_siege and v.military.squad_id < 0 then
|
2015-01-05 06:33:10 -07:00
|
|
|
add_thought(v, df.emotion_type.Nervousness, df.unit_thought_type.LackProtection)
|
2012-09-24 10:01:53 -06:00
|
|
|
end
|
2012-09-22 11:00:13 -06:00
|
|
|
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
|
2015-01-05 06:33:10 -07:00
|
|
|
add_thought(unit, df.emotion_type.Grumpiness, df.unit_thought_type.Drowsy)
|
2012-09-22 11:00:13 -06:00
|
|
|
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
|
|
|
|
)
|