Created
May 15, 2015 07:47
-
-
Save Putnam3145/8eecd5488f51f8464240 to your computer and use it in GitHub Desktop.
A script that notifies the user of the most common bad thoughts in the fort.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function getRaceName() | |
return df.creature_raw.find(df.global.ui.race_id).name[1] | |
end | |
local function emotionIsNegative(thought) | |
return thought.type~=-1 and df.emotion_type.attrs[thought.type].divider>0 | |
end | |
local function write_gamelog_and_announce(msg,color) | |
dfhack.gui.showAnnouncement(msg,color) | |
dfhack.gui.writeToGamelog(msg) | |
end | |
local function checkForBadThoughts(silent) | |
local thoughts={} | |
local mostPopularNegativeThought={cur_amount=0,thought_type=-1} | |
for _,unit in ipairs(df.global.world.units.active) do | |
if dfhack.units.isCitizen(unit) then | |
for __,emotion in ipairs(unit.status.current_soul.personality.emotions) do | |
if emotionIsNegative(emotion) then | |
thoughts[emotion.thought]=thoughts[emotion.thought] or 0 | |
thoughts[emotion.thought]=thoughts[emotion.thought]+1 | |
if thoughts[emotion.thought]>mostPopularNegativeThought.cur_amount then | |
mostPopularNegativeThought.cur_amount=thoughts[emotion.thought] | |
mostPopularNegativeThought.thought_type=emotion.thought | |
end | |
end | |
end | |
end | |
end | |
if df.unit_thought_type[mostPopularNegativeThought.thought_type] then | |
write_gamelog_and_announce('Your ' .. getRaceName() ..' are most feeling bad ' .. df.unit_thought_type.attrs[mostPopularNegativeThought.thought_type].caption..'.',COLOR_CYAN) | |
end | |
end | |
if ...=='-force' then | |
checkForBadThoughts() | |
else | |
require('repeat-util').scheduleEvery('badThoughtNotifier',7,'days',checkForBadThoughts) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment