Updated add-thought to allow subthoughts.

Only works in non-gui mode for now, since there's no easy way to tell people what subthought is which with the GUI.
develop
Putnam3145 2014-11-12 13:54:44 -08:00
parent ce09e1a70f
commit 4ccd4a96be
1 changed files with 27 additions and 39 deletions

@ -1,7 +1,8 @@
-- Adds thoughts to creatures. Use add-thought -help for more information. -- Adds emotions to creatures.
-- author Putnam
local function addEmotionToUnit(emotions,thought,emotion,severity) local utils=require('utils')
local function addEmotionToUnit(emotions,thought,emotion,subthought,severity)
if not (type(emotion)=='number') then emotion=df.emotion_type[emotion] end 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 if not (type(thought)=='number') then thought=df.unit_thought_type[thought] end
emotions:insert('#',{new=df.unit_personality.T_emotions, emotions:insert('#',{new=df.unit_personality.T_emotions,
@ -9,7 +10,7 @@ local function addEmotionToUnit(emotions,thought,emotion,severity)
unk2=1, unk2=1,
unk3=1, unk3=1,
thought=thought, thought=thought,
subthought=0, subthought=subthought,
severity=severity, severity=severity,
flags=0, flags=0,
unk7=0, unk7=0,
@ -18,6 +19,14 @@ local function addEmotionToUnit(emotions,thought,emotion,severity)
}) })
end end
validArgs = validArgs or utils.invert({
'unit',
'thought',
'emotion',
'severity',
'gui'
})
function tablify(iterableObject) function tablify(iterableObject)
t={} t={}
for k,v in ipairs(iterableObject) do for k,v in ipairs(iterableObject) do
@ -26,47 +35,24 @@ function tablify(iterableObject)
return t return t
end end
local utils=require('utils')
validArgs = validArgs or utils.invert({
'unit',
'thought',
'emotion',
'severity',
'gui',
'help'
})
local args = utils.processArgs({...}, validArgs) local args = utils.processArgs({...}, validArgs)
if args.help then
print(' add-thought: add a thought to a unit with an associated emotion.')
print(' add-thought -gui: opens a gui to add a thought to the selected unit.')
print(' add-thought -emotion numOrName -thought numOrName -severity num')
print(' adds thought with given thought, emotion and severity to selected unit.')
print(' names can be found here:')
print(' https://github.com/DFHack/df-structures/blob/master/df.unit-thoughts.xml')
print(' add-thought -unit etc.: as two above, but instead of selected unit uses unit')
print(' with given ID. (for use with modtools)')
end
local unit = args.unit and df.unit.find(args.unit) or dfhack.gui.getSelectedUnit(true) 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 not unit then qerror('A unit must be specified or selected.') end
if args.gui then if args.gui then
local script=require('gui.script') local script=require('gui.script')
script.start(function() script.start(function()
local tok,thought=script.showListPrompt('emotions','Which thought?',COLOR_WHITE,tablify(df.unit_thought_type),10,true) local tok,thought=script.showListPrompt('emotions','Which thought?',COLOR_WHITE,tablify(df.unit_thought_type),10,true)
if tok then if tok then
local eok,emotion=script.showListPrompt('emotions','Which emotion?',COLOR_WHITE,tablify(df.emotion_type),10,true) local eok,emotion=script.showListPrompt('emotions','Which emotion?',COLOR_WHITE,tablify(df.emotion_type),10,true)
if eok then if eok then
local sok,severity=script.showInputPrompt('emotions','At what severity?',COLOR_WHITE,'0') local sok,severity=script.showInputPrompt('emotions','At what severity?',COLOR_WHITE,'0')
if sok then if sok then
addEmotionToUnit(unit.status.current_soul.personality.emotions,thought,emotion,severity) addEmotionToUnit(unit.status.current_soul.personality.emotions,thought,emotion,severity,0)
end end
end end
end end
end) end)
else else
local thought = args.thought or 180 local thought = args.thought or 180
@ -75,5 +61,7 @@ else
local severity = args.severity or 0 local severity = args.severity or 0
addEmotionToUnit(unit.status.current_soul.personality.emotions,thought,emotion,severity) local subthought = args.subthought or 0
addEmotionToUnit(unit.status.current_soul.personality.emotions,thought,emotion,severity,subthought)
end end