From 0a63afa97742e0f008875554f2ad4234da72c3d2 Mon Sep 17 00:00:00 2001 From: PeridexisErrant Date: Fri, 4 Sep 2015 16:51:28 +1000 Subject: [PATCH 1/3] Import Vjek's script collection from the wiki http://dwarffortresswiki.org/index.php/User:Vjek --- scripts/armoks-blessing.lua | 196 +++++++++++++++++++++++++++++++++++ scripts/brainwash.lua | 64 ++++++++++++ scripts/elevate-mental.lua | 46 ++++++++ scripts/elevate-physical.lua | 46 ++++++++ scripts/make-legendary.lua | 132 +++++++++++++++++++++++ scripts/pref-adjust.lua | 93 +++++++++++++++++ scripts/rejuvenate.lua | 29 ++++++ 7 files changed, 606 insertions(+) create mode 100644 scripts/armoks-blessing.lua create mode 100644 scripts/brainwash.lua create mode 100644 scripts/elevate-mental.lua create mode 100644 scripts/elevate-physical.lua create mode 100644 scripts/make-legendary.lua create mode 100644 scripts/pref-adjust.lua create mode 100644 scripts/rejuvenate.lua diff --git a/scripts/armoks-blessing.lua b/scripts/armoks-blessing.lua new file mode 100644 index 000000000..0228908f5 --- /dev/null +++ b/scripts/armoks-blessing.lua @@ -0,0 +1,196 @@ +-- Adjust all attributes, personality, age and skills of all dwarves in play +-- place in /hack/scripts/ for ease of use +-- without arguments, all attributes, age & personalities are adjusted +-- arguments allow for skills to be adjusted as well +-- WARNING: USING THIS SCRIPT WILL ADJUST ALL DWARVES IN PLAY! +-- by vjek, version 5, 20140816, for DF(hack) 40.08 +-- Praise Armok! +-- --------------------------------------------------------------------------- +function rejuvenate(unit) + + if unit==nil then + print ("No unit available! Aborting with extreme prejudice.") + return + end + +local current_year=df.global.cur_year +local newbirthyear=current_year - 20 + if unit.relations.birth_year < newbirthyear then + unit.relations.birth_year=newbirthyear + end + if unit.relations.old_year < current_year+100 then + unit.relations.old_year=current_year+100 + end + +end +-- --------------------------------------------------------------------------- +function brainwash_unit(unit) + if unit==nil then + print ("No unit available! Aborting with extreme prejudice.") + return + end + +local profile ={75,25,25,75,25,25,25,99,25,25,25,50,75,50,25,75,75,50,75,75,25,75,75,50,75,25,50,25,75,75,75,25,75,75,25,75,25,25,75,75,25,75,75,75,25,75,75,25,25,50} +local i + +for i=1, #profile do + unit.status.current_soul.personality.traits[i-1]=profile[i] +end + +end +-- --------------------------------------------------------------------------- +function elevate_attributes(unit) + if unit==nil then + print ("No unit available! Aborting with extreme prejudice.") + return + end + +local ok,f,t,k = pcall(pairs,unit.status.current_soul.mental_attrs) + if ok then + for k,v in f,t,k do + v.value=v.max_value + end + end + +local ok,f,t,k = pcall(pairs,unit.body.physical_attrs) + if ok then + for k,v in f,t,k do + v.value=v.max_value + end + end +end +-- --------------------------------------------------------------------------- +-- this function will return the number of elements, starting at zero. +-- useful for counting things where #foo doesn't work +function count_this(to_be_counted) +local count = -1 +local var1 = "" +while var1 ~= nil do + count = count + 1 + var1 = (to_be_counted[count]) + end +count=count-1 +return count +end +-- --------------------------------------------------------------------------- +function make_legendary(skillname,unit) +local skillnamenoun,skillnum + + if unit==nil then + print ("No unit available! Aborting with extreme prejudice.") + return + end + + if (df.job_skill[skillname]) then + skillnamenoun = df.job_skill.attrs[df.job_skill[skillname]].caption_noun + else + print ("The skill name provided is not in the list.") + return + end + + if skillnamenoun ~= nil then + utils = require 'utils' + skillnum = df.job_skill[skillname] + utils.insert_or_update(unit.status.current_soul.skills, { new = true, id = skillnum, rating = 20 }, 'id') + print (unit.name.first_name.." is now a Legendary "..skillnamenoun) + else + print ("Empty skill name noun, bailing out!") + return + end +end +-- --------------------------------------------------------------------------- +function BreathOfArmok(unit) + + if unit==nil then + print ("No unit available! Aborting with extreme prejudice.") + return + end +local i + +local count_max = count_this(df.job_skill) +utils = require 'utils' +for i=0, count_max do + utils.insert_or_update(unit.status.current_soul.skills, { new = true, id = i, rating = 20 }, 'id') + end +print ("The breath of Armok has engulfed "..unit.name.first_name) +end +-- --------------------------------------------------------------------------- +function LegendaryByClass(skilltype,v) +unit=v + if unit==nil then + print ("No unit available! Aborting with extreme prejudice.") + return + end + +utils = require 'utils' +local i +local skillclass +local count_max = count_this(df.job_skill) +for i=0, count_max do + skillclass = df.job_skill_class[df.job_skill.attrs[i].type] + if skilltype == skillclass then + print ("Skill "..df.job_skill.attrs[i].caption.." is type: "..skillclass.." and is now Legendary for "..unit.name.first_name) + utils.insert_or_update(unit.status.current_soul.skills, { new = true, id = i, rating = 20 }, 'id') + end + end +end +-- --------------------------------------------------------------------------- +function PrintSkillList() +local count_max = count_this(df.job_skill) +local i +for i=0, count_max do + print("'"..df.job_skill.attrs[i].caption.."' "..df.job_skill[i].." Type: "..df.job_skill_class[df.job_skill.attrs[i].type]) + end +print ("Provide the UPPER CASE argument, for example: PROCESSPLANTS rather than Threshing") +end +-- --------------------------------------------------------------------------- +function PrintSkillClassList() +local i +local count_max = count_this(df.job_skill_class) +for i=0, count_max do + print(df.job_skill_class[i]) + end +print ("Provide one of these arguments, and all skills of that type will be made Legendary") +print ("For example: Medical will make all medical skills legendary") +end +-- --------------------------------------------------------------------------- +function adjust_all_dwarves(skillname) + for _,v in ipairs(df.global.world.units.all) do + if v.race == df.global.ui.race_id then + print("Adjusting "..dfhack.TranslateName(dfhack.units.getVisibleName(v))) + brainwash_unit(v) + elevate_attributes(v) + rejuvenate(v) + if skillname then + if skillname=="Normal" or skillname=="Medical" or skillname=="Personal" or skillname=="Social" or skillname=="Cultural" or skillname=="MilitaryWeapon" or skillname=="MilitaryAttack" or skillname=="MilitaryDefense" or skillname=="MilitaryMisc" then + LegendaryByClass(skillname,v) + elseif skillname=="all" then + BreathOfArmok(v) + else + make_legendary(skillname,v) + end + end + end + end +end +-- --------------------------------------------------------------------------- +-- main script operation starts here +-- --------------------------------------------------------------------------- +local opt = ... +local skillname + +if opt then + if opt=="list" then + PrintSkillList() + return + end + if opt=="classes" then + PrintSkillClassList() + return + end + skillname = opt +else + print ("No skillname supplied, no skills will be adjusted. Pass argument 'list' to see a skill list, 'classes' to show skill classes, or use 'all' if you want all skills legendary.") + end + +adjust_all_dwarves(skillname) \ No newline at end of file diff --git a/scripts/brainwash.lua b/scripts/brainwash.lua new file mode 100644 index 000000000..0b83580d9 --- /dev/null +++ b/scripts/brainwash.lua @@ -0,0 +1,64 @@ +-- This script will brainwash a dwarf, modifying their personality +-- usage is: target a unit in DF, and execute this script in dfhack +-- via ' lua /path/to/script ' +-- by vjek, version 5, 20140816, for DF(hack) 40.08 +-- Praise Armok! +-- for a in `awk -F= '{ print $2 }' input.txt`; do echo -n $a,; done + +function brainwash_unit(profile) +local i,unit_name + +unit=dfhack.gui.getSelectedUnit() + if unit==nil then + print ("No unit under cursor! Aborting with extreme prejudice.") + return + end + +unit_name=dfhack.TranslateName(dfhack.units.getVisibleName(unit)) + +print("Previous personality values for "..unit_name) +printall(unit.status.current_soul.personality.traits) + +--now set new personality +for i=1, #profile do + unit.status.current_soul.personality.traits[i-1]=profile[i] +end + +print("New personality values for "..unit_name) +printall(unit.status.current_soul.personality.traits) +print(unit_name.." has been brainwashed, praise Armok!") +end + +-- main script starts here +-- profiles are listed here and passed to the brainwash function +-- +local baseline={50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50} +local ideal={75,25,25,75,25,25,25,99,25,25,25,50,75,50,25,75,75,50,75,75,25,75,75,50,75,25,50,25,75,75,75,25,75,75,25,75,25,25,75,75,25,75,75,75,25,75,75,25,25,50} +local stepford={99,1,1,99,1,1,1,99,1,1,1,1,50,50,1,99,99,50,50,50,1,1,99,50,50,50,50,50,50,99,50,1,1,99,1,99,1,1,99,99,1,99,99,99,1,50,50,1,1,1} +local wrecked={1,99,99,1,99,99,99,1,99,99,99,1,1,99,99,1,1,1,1,1,99,1,1,99,1,99,99,99,1,1,1,99,1,1,99,1,99,99,1,1,99,1,1,1,99,1,1,99,99,99} +local opt = ... + +if opt then + if opt=="ideal" then + brainwash_unit(ideal) + return + end + if opt=="baseline" then + brainwash_unit(baseline) + return + end + if opt=="stepford" then + brainwash_unit(stepford) + return + end + if opt=="wrecked" then + brainwash_unit(wrecked) + return + end +else + print ("Invalid or missing personality argument.\nValid choices are ideal , baseline , stepford, and wrecked.") + print ("ideal will create a reliable dwarf with generally positive personality traits.") + print ("baseline will reset all personality traits to a default / the average.") + print ("stepford amplifies all good qualities to an excessive degree.") + print ("wrecked amplifies all bad qualities to an excessive degree.") + end \ No newline at end of file diff --git a/scripts/elevate-mental.lua b/scripts/elevate-mental.lua new file mode 100644 index 000000000..1adf2a8f1 --- /dev/null +++ b/scripts/elevate-mental.lua @@ -0,0 +1,46 @@ +-- This script will elevate all the mental attributes of a unit +-- usage is: target a unit in DF, and execute this script in dfhack +-- all physical attributes will be set to whatever the max value is +-- by vjek, version 5, 20140816, for DF(hack) 40.08 +-- Praise Armok! + +function ElevateMentalAttributes(value) +unit=dfhack.gui.getSelectedUnit() +if unit==nil then + print ("No unit under cursor! Aborting with extreme prejudice.") + return + end +--print name of dwarf +print("Adjusting "..dfhack.TranslateName(dfhack.units.getVisibleName(unit))) +--walk through available attributes, adjust current to max +local ok,f,t,k = pcall(pairs,unit.status.current_soul.mental_attrs) + if ok then + for k,v in f,t,k do + if value ~= nil then + print("Adjusting current value for "..tostring(k).." of "..v.value.." to the value of "..value) + v.value=value + else + print("Adjusting current value for "..tostring(k).." of "..v.value.." to max value of "..v.max_value) + v.value=v.max_value + --below will reset values back to "normal" + --v.value=v.max_value/2 + end + end + end +end +--script execution starts here +local opt = ... +opt = tonumber(opt) + +if opt ~= nil then + if opt >=0 and opt <=5000 then + ElevateMentalAttributes(opt) + end + if opt <0 or opt >5000 then + print("Invalid Range or argument. This script accepts either no argument, in which case it will increase the attribute to the max_value for the unit, or an argument between 0 and 5000, which will set all attributes to that value.") + end +end + +if opt == nil then + ElevateMentalAttributes() +end diff --git a/scripts/elevate-physical.lua b/scripts/elevate-physical.lua new file mode 100644 index 000000000..12c50cc0f --- /dev/null +++ b/scripts/elevate-physical.lua @@ -0,0 +1,46 @@ +-- This script will elevate all the physical attributes of a unit +-- usage is: target a unit in DF, and execute this script in dfhack +-- all physical attributes will be set to whatever the max value is +-- by vjek, version 5, 20140816, for DF(hack) 40.08 +-- Praise Armok! + +function ElevatePhysicalAttributes(value) +unit=dfhack.gui.getSelectedUnit() +if unit==nil then + print ("No unit under cursor! Aborting with extreme prejudice.") + return + end +--print name of dwarf +print("Adjusting "..dfhack.TranslateName(dfhack.units.getVisibleName(unit))) +--walk through available attributes, adjust current to max +local ok,f,t,k = pcall(pairs,unit.body.physical_attrs) + if ok then + for k,v in f,t,k do + if value ~= nil then + print("Adjusting current value for "..tostring(k).." of "..v.value.." to the value of "..value) + v.value=value + else + print("Adjusting current value for "..tostring(k).." of "..v.value.." to max value of "..v.max_value) + v.value=v.max_value + --below will reset values back to "normal" + --v.value=v.max_value/2 + end + end + end +end +--script execution starts here +local opt = ... +opt = tonumber(opt) + +if opt ~= nil then + if opt >=0 and opt <=5000 then + ElevatePhysicalAttributes(opt) + end + if opt <0 or opt >5000 then + print("Invalid Range or argument. This script accepts either no argument, in which case it will increase the attribute to the max_value for the unit, or an argument between 0 and 5000, which will set all attributes to that value.") + end +end + +if opt == nil then + ElevatePhysicalAttributes() +end diff --git a/scripts/make-legendary.lua b/scripts/make-legendary.lua new file mode 100644 index 000000000..5247e3ebd --- /dev/null +++ b/scripts/make-legendary.lua @@ -0,0 +1,132 @@ +-- This script will modify a skill or the skills of a single unit +-- usage is: target a unit in DF, and execute this script in dfhack +-- via ' lua /path/to/script skillname ' +-- the skill will be increased to 20 (Legendary +5) +-- arguments 'list', 'classes' and 'all' added +-- by vjek, version 4, 20141016, for DF(hack) 40.08 +-- Praise Armok! + +-- this function will return the number of elements, starting at zero. +-- useful for counting things where #foo doesn't work +function count_this(to_be_counted) +local count = -1 +local var1 = "" +while var1 ~= nil do + count = count + 1 + var1 = (to_be_counted[count]) + end +count=count-1 +return count +end + +function make_legendary(skillname) +local skillnamenoun,skillnum +unit=dfhack.gui.getSelectedUnit() + +if unit==nil then + print ("No unit under cursor! Aborting with extreme prejudice.") + return + end + +if (df.job_skill[skillname]) then + skillnamenoun = df.job_skill.attrs[df.job_skill[skillname]].caption_noun +else + print ("The skill name provided is not in the list.") + return + end + +if skillnamenoun ~= nil then + utils = require 'utils' + skillnum = df.job_skill[skillname] + utils.insert_or_update(unit.status.current_soul.skills, { new = true, id = skillnum, rating = 20 }, 'id') + print (dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." is now a Legendary "..skillnamenoun) +else + print ("Empty skill name noun, bailing out!") + return + end +end + +function PrintSkillList() +local count_max = count_this(df.job_skill) +local i +for i=0, count_max do + print("'"..df.job_skill.attrs[i].caption.."' "..df.job_skill[i].." Type: "..df.job_skill_class[df.job_skill.attrs[i].type]) + end +print ("Provide the UPPER CASE argument, for example: PROCESSPLANTS rather than Threshing") +end + +function BreathOfArmok() +unit=dfhack.gui.getSelectedUnit() +if unit==nil then + print ("No unit under cursor! Aborting with extreme prejudice.") + return + end +local i +local count_max = count_this(df.job_skill) +utils = require 'utils' +for i=0, count_max do + utils.insert_or_update(unit.status.current_soul.skills, { new = true, id = i, rating = 20 }, 'id') + end +print ("The breath of Armok has engulfed "..dfhack.TranslateName(dfhack.units.getVisibleName(unit))) +end + +function LegendaryByClass(skilltype) +unit=dfhack.gui.getSelectedUnit() +if unit==nil then + print ("No unit under cursor! Aborting with extreme prejudice.") + return + end + +utils = require 'utils' +local i +local skillclass +local count_max = count_this(df.job_skill) +for i=0, count_max do + skillclass = df.job_skill_class[df.job_skill.attrs[i].type] + if skilltype == skillclass then + print ("Skill "..df.job_skill.attrs[i].caption.." is type: "..skillclass.." and is now Legendary for "..dfhack.TranslateName(dfhack.units.getVisibleName(unit))) + utils.insert_or_update(unit.status.current_soul.skills, { new = true, id = i, rating = 20 }, 'id') + end + end +end + +function PrintSkillClassList() +local i +local count_max = count_this(df.job_skill_class) +for i=0, count_max do + print(df.job_skill_class[i]) + end +print ("Provide one of these arguments, and all skills of that type will be made Legendary") +print ("For example: Medical will make all medical skills legendary") +end + +--main script operation starts here +---- +local opt = ... +local skillname + +if opt then + if opt=="list" then + PrintSkillList() + return + end + if opt=="classes" then + PrintSkillClassList() + return + end + if opt=="all" then + BreathOfArmok() + return + end + if opt=="Normal" or opt=="Medical" or opt=="Personal" or opt=="Social" or opt=="Cultural" or opt=="MilitaryWeapon" or opt=="MilitaryAttack" or opt=="MilitaryDefense" or opt=="MilitaryMisc" then + LegendaryByClass(opt) + return + end + skillname = opt +else + print ("No skillname supplied.\nUse argument 'list' to see a list, 'classes' to show skill classes, or use 'all' if you want it all!") + print ("Example: To make a legendary miner, use make_legendary MINING") + return + end + +make_legendary(skillname) \ No newline at end of file diff --git a/scripts/pref-adjust.lua b/scripts/pref-adjust.lua new file mode 100644 index 000000000..fea32525c --- /dev/null +++ b/scripts/pref-adjust.lua @@ -0,0 +1,93 @@ +-- Adjust all preferences of all dwarves in play +-- place in /hack/scripts/ for ease of use +-- all preferences are cleared, then set +-- WARNING: USING THIS SCRIPT WILL ADJUST ALL DWARVES IN PLAY! +-- by vjek, version 4, 20141016, for DF(hack) 40.08 +-- Praise Armok! +-- --------------------------------------------------------------------------- +function brainwash_unit(unit) + + if unit==nil then + print ("No unit available! Aborting with extreme prejudice.") + return + end + +local pss_counter=31415926 + +local prefcount = #(unit.status.current_soul.preferences) +print ("Before, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + +utils = require 'utils' +-- below populates an array with all creature names and id's, used for 'detests...' +rtbl={} +vec=df.global.world.raws.creatures.all +for k=0,#vec-1 do + local name=vec[k].creature_id + rtbl[name]=k +end + +-- Now iterate through for the type 3 detests... +utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 3 , item_type = rtbl.TROLL , creature_id = rtbl.TROLL , color_id = rtbl.TROLL , shape_id = rtbl.TROLL , plant_id = rtbl.TROLL , item_subtype = -1 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') +pss_counter = pss_counter + 1 +utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 3 , item_type = rtbl.BIRD_BUZZARD , creature_id = rtbl.BIRD_BUZZARD , color_id = rtbl.BIRD_BUZZARD , shape_id = rtbl.BIRD_BUZZARD , plant_id = rtbl.BIRD_BUZZARD , item_subtype = -1 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') +pss_counter = pss_counter + 1 +utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 3 , item_type = rtbl.BIRD_VULTURE , creature_id = rtbl.BIRD_VULTURE , color_id = rtbl.BIRD_VULTURE , shape_id = rtbl.BIRD_VULTURE , plant_id = rtbl.BIRD_VULTURE , item_subtype = -1 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') +pss_counter = pss_counter + 1 +utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 3 , item_type = rtbl.CRUNDLE , creature_id = rtbl.CRUNDLE , color_id = rtbl.CRUNDLE , shape_id = rtbl.CRUNDLE , plant_id = rtbl.CRUNDLE , item_subtype = -1 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') +pss_counter = pss_counter + 1 +-- and the type 4 likes +utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.WEAPON , creature_id = df.item_type.WEAPON , color_id = df.item_type.WEAPON , shape_id = df.item_type.WEAPON , plant_id = df.item_type.WEAPON , item_subtype = -1 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') +pss_counter = pss_counter + 1 +utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.ARMOR , creature_id = df.item_type.ARMOR , color_id = df.item_type.ARMOR , shape_id = df.item_type.ARMOR , plant_id = df.item_type.ARMOR , item_subtype = -1 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') +pss_counter = pss_counter + 1 +utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 4 , item_type = df.item_type.SHIELD , creature_id = df.item_type.SHIELD , color_id = df.item_type.SHIELD , shape_id = df.item_type.SHIELD , plant_id = df.item_type.SHIELD , item_subtype = -1 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') +pss_counter = pss_counter + 1 +-- prefers plump helmets for their ... +local ph_mat_type=dfhack.matinfo.find("MUSHROOM_HELMET_PLUMP:STRUCTURAL").index +utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 5 , item_type = ph_mat_type , creature_id = ph_mat_type , color_id = ph_mat_type , shape_id = ph_mat_type , plant_id = ph_mat_type , item_subtype = -1 , mattype = -1 , matindex = -1 , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') +pss_counter = pss_counter + 1 +-- prefers to consume dwarven wine: +utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 2 , item_type = 68 , creature_id = 68 , color_id = 68 , shape_id = 68 , plant_id = 68 , item_subtype = -1 , mattype = dfhack.matinfo.find("MUSHROOM_HELMET_PLUMP:DRINK").type , matindex = dfhack.matinfo.find("MUSHROOM_HELMET_PLUMP:DRINK").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') +pss_counter = pss_counter + 1 +-- likes iron, steel (0,8) adam is 25 +utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("IRON").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') +pss_counter = pss_counter + 1 +utils.insert_or_update(unit.status.current_soul.preferences, { new = true, type = 0 , item_type = -1 , creature_id = -1 , color_id = -1 , shape_id = -1 , plant_id = -1 , item_subtype = -1 , mattype = 0 , matindex = dfhack.matinfo.find("STEEL").index , active = true, prefstring_seed = pss_counter }, 'prefstring_seed') + +prefcount = #(unit.status.current_soul.preferences) +print ("After, unit "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." has "..prefcount.." preferences") + +end +-- --------------------------------------------------------------------------- +function clear_preferences(v) +unit=v + +local prefs=unit.status.current_soul.preferences + for index,pref in ipairs(prefs) do + pref:delete() + end +prefs:resize(0) +end +-- --------------------------------------------------------------------------- +function clearpref_all_dwarves() + for _,v in ipairs(df.global.world.units.active) do + if v.race == df.global.ui.race_id then + print("Clearing Preferences for "..dfhack.TranslateName(dfhack.units.getVisibleName(v))) + clear_preferences(v) + end + end +end +-- --------------------------------------------------------------------------- +function adjust_all_dwarves() + for _,v in ipairs(df.global.world.units.active) do + if v.race == df.global.ui.race_id then + print("Adjusting "..dfhack.TranslateName(dfhack.units.getVisibleName(v))) + brainwash_unit(v) + end + end +end +-- --------------------------------------------------------------------------- +-- main script operation starts here +-- --------------------------------------------------------------------------- +clearpref_all_dwarves() +adjust_all_dwarves() \ No newline at end of file diff --git a/scripts/rejuvenate.lua b/scripts/rejuvenate.lua new file mode 100644 index 000000000..9b0ec7403 --- /dev/null +++ b/scripts/rejuvenate.lua @@ -0,0 +1,29 @@ +-- This script will make any "old" dwarf 20 years old +-- usage is: target a unit in DF, and execute this script in dfhack +-- via ' lua /path/to/script ' +-- the target will be changed to 20 years old +-- by vjek, version 5, 20141016, for DF(hack) 40.08 +-- Paise Armok! + +function rejuvenate() +local current_year,newbirthyear +unit=dfhack.gui.getSelectedUnit() + +if unit==nil then + print ("No unit under cursor! Aborting with extreme prejudice.") + return + end + +current_year=df.global.cur_year +newbirthyear=current_year - 20 +if unit.relations.birth_year < newbirthyear then + unit.relations.birth_year=newbirthyear +end +if unit.relations.old_year < current_year+100 then + unit.relations.old_year=current_year+100 +end +print (dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." is now 20 years old and will live at least 100 years") + +end + +rejuvenate() \ No newline at end of file From f242872963569874fbef1a768230ce39570c471b Mon Sep 17 00:00:00 2001 From: PeridexisErrant Date: Fri, 4 Sep 2015 17:13:21 +1000 Subject: [PATCH 2/3] Documentation for Vjek's scripts --- Contributors.rst | 1 + NEWS | 2 ++ Readme.rst | 55 ++++++++++++++++++++++++++++++++++++ scripts/armoks-blessing.lua | 8 ++---- scripts/brainwash.lua | 7 ++--- scripts/elevate-mental.lua | 3 +- scripts/elevate-physical.lua | 3 +- scripts/make-legendary.lua | 6 ++-- scripts/pref-adjust.lua | 45 +++++++++++++++-------------- scripts/rejuvenate.lua | 33 +++++++++------------- 10 files changed, 103 insertions(+), 60 deletions(-) diff --git a/Contributors.rst b/Contributors.rst index 7fb774085..08cbce113 100644 --- a/Contributors.rst +++ b/Contributors.rst @@ -81,6 +81,7 @@ acwatkins acwatkins Wes Malone wesQ3 Michon van Dooren MaienM Seth Woodworth sethwoodworth +Vjek ======================= ==================== =========================== And these are the cool people who made **Stonesense**. diff --git a/NEWS b/NEWS index dd2acc430..34d90269f 100644 --- a/NEWS +++ b/NEWS @@ -28,6 +28,8 @@ DFHack Future view-item-info: adds information and customisable descriptions to item viewscreens warn-starving: check for starving, thirsty, or very drowsy units and pause with warning if any are found points: set number of points available at embark screen + Vjek's script collection: armoks-blessing, brainwash, elevate-mental, + elevate-physical, make-legendary, pref0adjust, rejuvenate New tweaks embark-profile-name: Allows the use of lowercase letters when saving embark profiles kitchen-keys: Fixes DF kitchen meal keybindings diff --git a/Readme.rst b/Readme.rst index dea56d40e..379b7f970 100644 --- a/Readme.rst +++ b/Readme.rst @@ -2380,6 +2380,13 @@ directory. Don't forget to `enable stockpiles` and create the `stocksettings` directory in the DF folder before trying to use this plugin. + +modtools/* +========== +Scripts which provide tools for modders, often with changes to the raw files. +Not intended to be called manually by end-users. + + adaptation ========== View or set level of cavern adaptation for the selected unit or the whole fort. @@ -2391,6 +2398,13 @@ 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. +armoks-blessing +=============== +Runs the equivalent of rejuvenate, elevate_physical, elevate_mental, and brainwash +on all dwarves currently on the map. This is an extreme change, which sets every +stat to an ideal - legendary skills, great traits, and easy-to-satisfy preferences. +Use in moderation; it's as 'cheaty' as DFHack gets. + autofarm ======== Automatically handle crop selection in farm plots based on current plant stocks. @@ -2424,6 +2438,12 @@ If the name of the patch has no extension or directory separators, the script uses ``hack/patches//.dif``, thus auto-selecting the version appropriate for the currently loaded executable. +brainwash +========= +Modify the personality traits of the selected dwarf to match an 'ideal' +personality - as stable and reliable as possible. This makes dwarves very +stable, preventing tantrums even after months of misery. + burial ====== Sets all unowned coffins to allow burial. ``burial -pets`` also allows burial @@ -2492,6 +2512,17 @@ drain-aquifer ============= Remove all 'aquifer' tag from the map blocks. Irreversible. +elevate-mental +============== +Set all mental attributes of a dwarf to 2600, which is very high. +Other numbers can be passed as an argument: ``elevate-mental 100`` +for example would make the dwarf very stupid indeed. + +elevate-physical +================ +As for elevate-mental, but for physical traits. High is good for soldiers, +while having an ineffective hammerer can be useful too... + exterminate =========== Kills any unit of a given race. @@ -2644,6 +2675,13 @@ There are the following ways to invoke this command: Parses and executes the lua statement like the interactive interpreter would. +make-legendary +============== +Makes the selected dwarf legendary in one skill, a group of skills, or all +skills. View groups with ``make-legendary classes``, or all skills with +``make-legendary list``. Use ``make-legendary MINING`` when you need something +dug up, or ``make-legendary all`` when only perfection will do. + make-monarch ============ Make the selected unit King or Queen of your civilisation. @@ -2682,6 +2720,18 @@ position Reports the current time: date, clock time, month, and season. Also reports location: z-level, cursor position, window size, and mouse location. +pref-adjust +=========== +A two-stage script: ``pref-adjust clear`` removes preferences from all dwarves, +and ``pref-adjust`` inserts an 'ideal' set which is easy to satisfy:: + + Feb Idashzefon likes wild strawberries for their vivid red color, fisher berries + for their round shape, prickle berries for their precise thorns, plump helmets + for their rounded tops, prepared meals, plants, drinks, doors, thrones, tables and + beds. When possible, she prefers to consume wild strawberries, fisher berries, + prickle berries, plump helmets, strawberry wine, fisher berry wine, prickle berry + wine, and dwarven wine. + putontable ========== Makes item appear on the table, like in adventure mode shops. Arguments: '-a' @@ -2696,6 +2746,11 @@ region-pops =========== Show or modify the populations of animals in the region. Use ``region-pops`` for details. +rejuvenate +========== +Set the age of the selected dwarf to 20 years. Useful if valuable citizens are +getting old, or there are too many babies around... + remove-stress ============= Sets stress to -1,000,000; the normal range is 0 to 500,000 with very stable or diff --git a/scripts/armoks-blessing.lua b/scripts/armoks-blessing.lua index 0228908f5..cb9478846 100644 --- a/scripts/armoks-blessing.lua +++ b/scripts/armoks-blessing.lua @@ -1,11 +1,9 @@ -- Adjust all attributes, personality, age and skills of all dwarves in play --- place in /hack/scripts/ for ease of use -- without arguments, all attributes, age & personalities are adjusted -- arguments allow for skills to be adjusted as well -- WARNING: USING THIS SCRIPT WILL ADJUST ALL DWARVES IN PLAY! --- by vjek, version 5, 20140816, for DF(hack) 40.08 --- Praise Armok! --- --------------------------------------------------------------------------- +-- by vjek + function rejuvenate(unit) if unit==nil then @@ -193,4 +191,4 @@ else print ("No skillname supplied, no skills will be adjusted. Pass argument 'list' to see a skill list, 'classes' to show skill classes, or use 'all' if you want all skills legendary.") end -adjust_all_dwarves(skillname) \ No newline at end of file +adjust_all_dwarves(skillname) diff --git a/scripts/brainwash.lua b/scripts/brainwash.lua index 0b83580d9..5492017c8 100644 --- a/scripts/brainwash.lua +++ b/scripts/brainwash.lua @@ -1,9 +1,6 @@ -- This script will brainwash a dwarf, modifying their personality -- usage is: target a unit in DF, and execute this script in dfhack --- via ' lua /path/to/script ' --- by vjek, version 5, 20140816, for DF(hack) 40.08 --- Praise Armok! --- for a in `awk -F= '{ print $2 }' input.txt`; do echo -n $a,; done +-- by vjek function brainwash_unit(profile) local i,unit_name @@ -61,4 +58,4 @@ else print ("baseline will reset all personality traits to a default / the average.") print ("stepford amplifies all good qualities to an excessive degree.") print ("wrecked amplifies all bad qualities to an excessive degree.") - end \ No newline at end of file +end diff --git a/scripts/elevate-mental.lua b/scripts/elevate-mental.lua index 1adf2a8f1..487ad40ef 100644 --- a/scripts/elevate-mental.lua +++ b/scripts/elevate-mental.lua @@ -1,8 +1,7 @@ -- This script will elevate all the mental attributes of a unit -- usage is: target a unit in DF, and execute this script in dfhack -- all physical attributes will be set to whatever the max value is --- by vjek, version 5, 20140816, for DF(hack) 40.08 --- Praise Armok! +-- by vjek function ElevateMentalAttributes(value) unit=dfhack.gui.getSelectedUnit() diff --git a/scripts/elevate-physical.lua b/scripts/elevate-physical.lua index 12c50cc0f..41d7ef1a0 100644 --- a/scripts/elevate-physical.lua +++ b/scripts/elevate-physical.lua @@ -1,8 +1,7 @@ -- This script will elevate all the physical attributes of a unit -- usage is: target a unit in DF, and execute this script in dfhack -- all physical attributes will be set to whatever the max value is --- by vjek, version 5, 20140816, for DF(hack) 40.08 --- Praise Armok! +-- by vjek function ElevatePhysicalAttributes(value) unit=dfhack.gui.getSelectedUnit() diff --git a/scripts/make-legendary.lua b/scripts/make-legendary.lua index 5247e3ebd..4e487484b 100644 --- a/scripts/make-legendary.lua +++ b/scripts/make-legendary.lua @@ -1,10 +1,8 @@ -- This script will modify a skill or the skills of a single unit -- usage is: target a unit in DF, and execute this script in dfhack --- via ' lua /path/to/script skillname ' -- the skill will be increased to 20 (Legendary +5) -- arguments 'list', 'classes' and 'all' added --- by vjek, version 4, 20141016, for DF(hack) 40.08 --- Praise Armok! +-- by vjek -- this function will return the number of elements, starting at zero. -- useful for counting things where #foo doesn't work @@ -129,4 +127,4 @@ else return end -make_legendary(skillname) \ No newline at end of file +make_legendary(skillname) diff --git a/scripts/pref-adjust.lua b/scripts/pref-adjust.lua index fea32525c..1f6607b04 100644 --- a/scripts/pref-adjust.lua +++ b/scripts/pref-adjust.lua @@ -1,16 +1,15 @@ -- Adjust all preferences of all dwarves in play --- place in /hack/scripts/ for ease of use -- all preferences are cleared, then set -- WARNING: USING THIS SCRIPT WILL ADJUST ALL DWARVES IN PLAY! --- by vjek, version 4, 20141016, for DF(hack) 40.08 --- Praise Armok! +-- by vjek + -- --------------------------------------------------------------------------- function brainwash_unit(unit) - if unit==nil then - print ("No unit available! Aborting with extreme prejudice.") - return - end + if unit==nil then + print ("No unit available! Aborting with extreme prejudice.") + return + end local pss_counter=31415926 @@ -63,31 +62,31 @@ function clear_preferences(v) unit=v local prefs=unit.status.current_soul.preferences - for index,pref in ipairs(prefs) do - pref:delete() - end + for index,pref in ipairs(prefs) do + pref:delete() + end prefs:resize(0) end -- --------------------------------------------------------------------------- function clearpref_all_dwarves() - for _,v in ipairs(df.global.world.units.active) do - if v.race == df.global.ui.race_id then - print("Clearing Preferences for "..dfhack.TranslateName(dfhack.units.getVisibleName(v))) - clear_preferences(v) - end - end + for _,v in ipairs(df.global.world.units.active) do + if v.race == df.global.ui.race_id then + print("Clearing Preferences for "..dfhack.TranslateName(dfhack.units.getVisibleName(v))) + clear_preferences(v) + end + end end -- --------------------------------------------------------------------------- function adjust_all_dwarves() - for _,v in ipairs(df.global.world.units.active) do - if v.race == df.global.ui.race_id then - print("Adjusting "..dfhack.TranslateName(dfhack.units.getVisibleName(v))) - brainwash_unit(v) - end - end + for _,v in ipairs(df.global.world.units.active) do + if v.race == df.global.ui.race_id then + print("Adjusting "..dfhack.TranslateName(dfhack.units.getVisibleName(v))) + brainwash_unit(v) + end + end end -- --------------------------------------------------------------------------- -- main script operation starts here -- --------------------------------------------------------------------------- clearpref_all_dwarves() -adjust_all_dwarves() \ No newline at end of file +adjust_all_dwarves() diff --git a/scripts/rejuvenate.lua b/scripts/rejuvenate.lua index 9b0ec7403..597bfd528 100644 --- a/scripts/rejuvenate.lua +++ b/scripts/rejuvenate.lua @@ -1,29 +1,24 @@ -- This script will make any "old" dwarf 20 years old -- usage is: target a unit in DF, and execute this script in dfhack --- via ' lua /path/to/script ' -- the target will be changed to 20 years old --- by vjek, version 5, 20141016, for DF(hack) 40.08 --- Paise Armok! +-- by vjek function rejuvenate() -local current_year,newbirthyear -unit=dfhack.gui.getSelectedUnit() + local current_year,newbirthyear + unit=dfhack.gui.getSelectedUnit() -if unit==nil then - print ("No unit under cursor! Aborting with extreme prejudice.") - return - end + if unit==nil then print ("No unit under cursor! Aborting.") return end -current_year=df.global.cur_year -newbirthyear=current_year - 20 -if unit.relations.birth_year < newbirthyear then - unit.relations.birth_year=newbirthyear -end -if unit.relations.old_year < current_year+100 then - unit.relations.old_year=current_year+100 -end -print (dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." is now 20 years old and will live at least 100 years") + current_year=df.global.cur_year + newbirthyear=current_year - 20 + if unit.relations.birth_year < newbirthyear then + unit.relations.birth_year=newbirthyear + end + if unit.relations.old_year < current_year+100 then + unit.relations.old_year=current_year+100 + end + print (dfhack.TranslateName(dfhack.units.getVisibleName(unit)).." is now 20 years old and will live at least 100 years") end -rejuvenate() \ No newline at end of file +rejuvenate() From 02dd77aef6966a04cc4cca2023c398e1a2e5b094 Mon Sep 17 00:00:00 2001 From: PeridexisErrant Date: Sat, 5 Sep 2015 09:54:44 +1000 Subject: [PATCH 3/3] Fix new script names in readme --- Readme.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.rst b/Readme.rst index 379b7f970..fb75774f0 100644 --- a/Readme.rst +++ b/Readme.rst @@ -2400,7 +2400,7 @@ or the gui invoked by running ``add-thought gui`` with a unit selected. armoks-blessing =============== -Runs the equivalent of rejuvenate, elevate_physical, elevate_mental, and brainwash +Runs the equivalent of rejuvenate, elevate-physical, elevate-mental, and brainwash on all dwarves currently on the map. This is an extreme change, which sets every stat to an ideal - legendary skills, great traits, and easy-to-satisfy preferences. Use in moderation; it's as 'cheaty' as DFHack gets.