2014-11-12 14:54:44 -07:00
|
|
|
-- Adds emotions to creatures.
|
2015-03-22 14:54:38 -06:00
|
|
|
--@ module = true
|
2014-11-10 02:44:30 -07:00
|
|
|
|
2015-10-23 07:33:35 -06:00
|
|
|
--[[=begin
|
2015-09-27 00:45:11 -06:00
|
|
|
|
|
|
|
add-thought
|
|
|
|
===========
|
|
|
|
Adds a thought or emotion to the selected unit. Can be used by other scripts,
|
|
|
|
or the gui invoked by running ``add-thought gui`` with a unit selected.
|
|
|
|
|
2015-10-23 07:33:35 -06:00
|
|
|
=end]]
|
2015-09-27 00:45:11 -06:00
|
|
|
|
2014-11-12 14:54:44 -07:00
|
|
|
local utils=require('utils')
|
|
|
|
|
2015-01-31 20:43:54 -07:00
|
|
|
function addEmotionToUnit(unit,thought,emotion,severity,strength,subthought)
|
2015-01-26 20:11:53 -07:00
|
|
|
local emotions=unit.status.current_soul.personality.emotions
|
2014-11-10 02:44:30 -07:00
|
|
|
if not (type(emotion)=='number') then emotion=df.emotion_type[emotion] end
|
|
|
|
if not (type(thought)=='number') then thought=df.unit_thought_type[thought] end
|
|
|
|
emotions:insert('#',{new=df.unit_personality.T_emotions,
|
|
|
|
type=emotion,
|
|
|
|
unk2=1,
|
2015-01-26 20:11:53 -07:00
|
|
|
strength=strength,
|
2014-11-10 02:44:30 -07:00
|
|
|
thought=thought,
|
2014-11-12 14:54:44 -07:00
|
|
|
subthought=subthought,
|
2014-11-10 02:44:30 -07:00
|
|
|
severity=severity,
|
|
|
|
flags=0,
|
|
|
|
unk7=0,
|
|
|
|
year=df.global.cur_year,
|
|
|
|
year_tick=df.global.cur_year_tick
|
|
|
|
})
|
2015-01-26 20:11:53 -07:00
|
|
|
local divider=df.emotion_type.attrs[emotion].divider
|
|
|
|
if divider~=0 then
|
|
|
|
unit.status.current_soul.personality.stress_level=unit.status.current_soul.personality.stress_level+math.ceil(severity/df.emotion_type.attrs[emotion].divider)
|
|
|
|
end
|
2014-11-10 02:44:30 -07:00
|
|
|
end
|
|
|
|
|
2014-11-12 14:54:44 -07:00
|
|
|
validArgs = validArgs or utils.invert({
|
|
|
|
'unit',
|
|
|
|
'thought',
|
|
|
|
'emotion',
|
|
|
|
'severity',
|
2015-01-26 20:11:53 -07:00
|
|
|
'strength',
|
2015-02-06 14:52:56 -07:00
|
|
|
'subthought',
|
2014-11-12 14:54:44 -07:00
|
|
|
'gui'
|
|
|
|
})
|
|
|
|
|
2014-11-10 02:44:30 -07:00
|
|
|
function tablify(iterableObject)
|
|
|
|
t={}
|
|
|
|
for k,v in ipairs(iterableObject) do
|
|
|
|
t[k] = v~=nil and v or 'nil'
|
|
|
|
end
|
|
|
|
return t
|
|
|
|
end
|
|
|
|
|
2015-01-31 20:43:54 -07:00
|
|
|
if moduleMode then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-11-10 02:44:30 -07:00
|
|
|
local args = utils.processArgs({...}, validArgs)
|
|
|
|
|
|
|
|
local unit = args.unit and df.unit.find(args.unit) or dfhack.gui.getSelectedUnit(true)
|
|
|
|
|
|
|
|
if not unit then qerror('A unit must be specified or selected.') end
|
|
|
|
if args.gui then
|
2015-01-26 20:11:53 -07:00
|
|
|
local script=require('gui.script')
|
|
|
|
script.start(function()
|
|
|
|
local tok,thought=script.showListPrompt('emotions','Which thought?',COLOR_WHITE,tablify(df.unit_thought_type),10,true)
|
|
|
|
if tok then
|
|
|
|
local eok,emotion=script.showListPrompt('emotions','Which emotion?',COLOR_WHITE,tablify(df.emotion_type),10,true)
|
|
|
|
if eok then
|
|
|
|
local sok,severity=script.showInputPrompt('emotions','At what severity?',COLOR_WHITE,'0')
|
|
|
|
if sok then
|
|
|
|
local stok,strength=script.showInputPrompt('emotions','At what strength?',COLOR_WHITE,'0')
|
|
|
|
if stok then
|
|
|
|
addEmotionToUnit(unit,thought,emotion,severity,strength,0)
|
|
|
|
end
|
2014-11-12 14:54:44 -07:00
|
|
|
end
|
2015-01-26 20:11:53 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
2014-11-10 02:44:30 -07:00
|
|
|
else
|
|
|
|
local thought = args.thought or 180
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2014-11-10 02:44:30 -07:00
|
|
|
local emotion = args.emotion or -1
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2014-11-10 02:44:30 -07:00
|
|
|
local severity = args.severity or 0
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2014-11-12 14:54:44 -07:00
|
|
|
local subthought = args.subthought or 0
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2015-01-26 20:11:53 -07:00
|
|
|
local strength = args.strength or 0
|
2015-02-14 20:53:06 -07:00
|
|
|
|
2015-01-26 20:11:53 -07:00
|
|
|
addEmotionToUnit(unit,thought,emotion,severity,strength,subthought)
|
2014-11-12 14:54:44 -07:00
|
|
|
end
|