From f980ecf38d655b1160f88e9673bb6607610afff3 Mon Sep 17 00:00:00 2001 From: Putnam3145 Date: Mon, 10 Nov 2014 01:44:30 -0800 Subject: [PATCH 1/4] Added add-thought to scripts. I figure that it's useful enough and good enough by this point to be included. --- scripts/add-thought.lua | 79 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 scripts/add-thought.lua diff --git a/scripts/add-thought.lua b/scripts/add-thought.lua new file mode 100644 index 000000000..4cfd7c0ce --- /dev/null +++ b/scripts/add-thought.lua @@ -0,0 +1,79 @@ +-- Adds thoughts to creatures. Use add-thought -help for more information. +-- author Putnam + +local function addEmotionToUnit(emotions,thought,emotion,severity) + 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, + unk3=1, + thought=thought, + subthought=0, + severity=severity, + flags=0, + unk7=0, + year=df.global.cur_year, + year_tick=df.global.cur_year_tick + }) +end + +function tablify(iterableObject) + t={} + for k,v in ipairs(iterableObject) do + t[k] = v~=nil and v or 'nil' + end + return t +end + + +local utils=require('utils') + +validArgs = validArgs or utils.invert({ + 'unit', + 'thought', + 'emotion', + 'severity', + 'gui', + 'help' +}) + +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) + +if not unit then qerror('A unit must be specified or selected.') end +if args.gui then + 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 + addEmotionToUnit(unit.status.current_soul.personality.emotions,thought,emotion,severity) + end + end + end + end) +else + local thought = args.thought or 180 + + local emotion = args.emotion or -1 + + local severity = args.severity or 0 + + addEmotionToUnit(unit.status.current_soul.personality.emotions,thought,emotion,severity) +end \ No newline at end of file From ce09e1a70f4d8becb6a4e74224471c4f4c27a20b Mon Sep 17 00:00:00 2001 From: Putnam3145 Date: Mon, 10 Nov 2014 01:46:23 -0800 Subject: [PATCH 2/4] Update NEWS. --- NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS b/NEWS index dada05bda..e91a79cdd 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,8 @@ DFHack Future + New scripts: + scripts/ + add-thought.lua + allows the user to add thoughts to creatures. DFHack 0.40.15-r1 Fixes: From 4ccd4a96be964bd44553d97faa5a0b89d45458c4 Mon Sep 17 00:00:00 2001 From: Putnam3145 Date: Wed, 12 Nov 2014 13:54:44 -0800 Subject: [PATCH 3/4] 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. --- scripts/add-thought.lua | 66 +++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 39 deletions(-) diff --git a/scripts/add-thought.lua b/scripts/add-thought.lua index 4cfd7c0ce..6d918debf 100644 --- a/scripts/add-thought.lua +++ b/scripts/add-thought.lua @@ -1,7 +1,8 @@ --- Adds thoughts to creatures. Use add-thought -help for more information. --- author Putnam +-- Adds emotions to creatures. -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(thought)=='number') then thought=df.unit_thought_type[thought] end emotions:insert('#',{new=df.unit_personality.T_emotions, @@ -9,7 +10,7 @@ local function addEmotionToUnit(emotions,thought,emotion,severity) unk2=1, unk3=1, thought=thought, - subthought=0, + subthought=subthought, severity=severity, flags=0, unk7=0, @@ -18,6 +19,14 @@ local function addEmotionToUnit(emotions,thought,emotion,severity) }) end +validArgs = validArgs or utils.invert({ + 'unit', + 'thought', + 'emotion', + 'severity', + 'gui' +}) + function tablify(iterableObject) t={} for k,v in ipairs(iterableObject) do @@ -26,47 +35,24 @@ function tablify(iterableObject) return t end - -local utils=require('utils') - -validArgs = validArgs or utils.invert({ - 'unit', - 'thought', - 'emotion', - 'severity', - 'gui', - 'help' -}) - 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) if not unit then qerror('A unit must be specified or selected.') end if args.gui then 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 - addEmotionToUnit(unit.status.current_soul.personality.emotions,thought,emotion,severity) - end - end - end + 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 + addEmotionToUnit(unit.status.current_soul.personality.emotions,thought,emotion,severity,0) + end + end + end end) else local thought = args.thought or 180 @@ -75,5 +61,7 @@ else local severity = args.severity or 0 - addEmotionToUnit(unit.status.current_soul.personality.emotions,thought,emotion,severity) -end \ No newline at end of file + local subthought = args.subthought or 0 + + addEmotionToUnit(unit.status.current_soul.personality.emotions,thought,emotion,severity,subthought) +end From 9f6a04db7fb5a88ecc5a458da0adf46a08bb6107 Mon Sep 17 00:00:00 2001 From: Putnam3145 Date: Wed, 12 Nov 2014 13:55:38 -0800 Subject: [PATCH 4/4] Switched subthought and severity in function arg --- scripts/add-thought.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/add-thought.lua b/scripts/add-thought.lua index 6d918debf..b0b154a00 100644 --- a/scripts/add-thought.lua +++ b/scripts/add-thought.lua @@ -2,7 +2,7 @@ local utils=require('utils') -local function addEmotionToUnit(emotions,thought,emotion,subthought,severity) +local function addEmotionToUnit(emotions,thought,emotion,severity,subthought) 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,