Update siren.lua for emotions

Runs now without exception/error and adds emotions correctly. Seems to work as intended.
develop
Chris Dombroski 2015-01-05 08:33:10 -05:00
parent 10fa55570e
commit 294fe0b30c
1 changed files with 17 additions and 14 deletions

@ -32,15 +32,18 @@ function is_in_burrows(pos)
end end
end end
function add_thought(unit, code) function add_thought(unit, emotion, thought)
for _,v in ipairs(unit.status.recent_events) do unit.status.current_soul.personality.emotions:insert('#', { new = true,
if v.type == code then type = emotion,
v.age = 0 unk2=1,
return strength=1,
end thought=thought,
end subthought=0,
severity=0,
unit.status.recent_events:insert('#', { new = true, type = code }) flags=0,
unk7=0,
year=df.global.cur_year,
year_tick=df.global.cur_year_tick})
end end
function wake_unit(unit) function wake_unit(unit)
@ -51,9 +54,9 @@ function wake_unit(unit)
if job.completion_timer > 0 then if job.completion_timer > 0 then
unit.counters.unconscious = 0 unit.counters.unconscious = 0
add_thought(unit, df.unit_thought_type.SleepNoiseWake) add_thought(unit, df.emotion_type.Grouchiness, df.unit_thought_type.Drowsy)
elseif job.completion_timer < 0 then elseif job.completion_timer < 0 then
add_thought(unit, df.unit_thought_type.Tired) add_thought(unit, df.emotion_type.Grumpiness, df.unit_thought_type.Drowsy)
end end
job.pos:assign(unit.pos) job.pos:assign(unit.pos)
@ -73,7 +76,7 @@ function stop_break(unit)
if counter then if counter then
counter.id = df.misc_trait_type.TimeSinceBreak counter.id = df.misc_trait_type.TimeSinceBreak
counter.value = 100800 - 30*1200 counter.value = 100800 - 30*1200
add_thought(unit, df.unit_thought_type.Tired) add_thought(unit, df.emotion_type.Grumpiness, df.unit_thought_type.Drowsy)
end end
end end
@ -90,7 +93,7 @@ for _,v in ipairs(df.global.world.units.active) do
local x,y,z = dfhack.units.getPosition(v) local x,y,z = dfhack.units.getPosition(v)
if x and dfhack.units.isCitizen(v) and is_in_burrows(xyz2pos(x,y,z)) then if x and dfhack.units.isCitizen(v) and is_in_burrows(xyz2pos(x,y,z)) then
if not in_siege and v.military.squad_id < 0 then if not in_siege and v.military.squad_id < 0 then
add_thought(v, df.unit_thought_type.LackProtection) add_thought(v, df.emotion_type.Nervousness, df.unit_thought_type.LackProtection)
end end
wake_unit(v) wake_unit(v)
stop_break(v) stop_break(v)
@ -103,7 +106,7 @@ for _,v in ipairs(df.global.ui.parties) do
if is_in_burrows(pos) then if is_in_burrows(pos) then
v.timer = 0 v.timer = 0
for _, u in ipairs(v.units) do for _, u in ipairs(v.units) do
add_thought(unit, df.unit_thought_type.Tired) add_thought(unit, df.emotion_type.Grumpiness, df.unit_thought_type.Drowsy)
end end
end end
end end