2015-09-04 00:51:28 -06:00
-- 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
-- the skill will be increased to 20 (Legendary +5)
-- arguments 'list', 'classes' and 'all' added
2015-09-04 01:13:21 -06:00
-- by vjek
2015-09-04 00:51:28 -06:00
-- 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 )
2015-09-21 16:18:48 -06:00
local count = - 1
local var1 = " "
while var1 ~= nil do
count = count + 1
var1 = ( to_be_counted [ count ] )
2015-09-04 00:51:28 -06:00
end
2015-09-21 16:18:48 -06:00
count = count - 1
return count
2015-09-04 00:51:28 -06:00
end
function make_legendary ( skillname )
2015-09-21 16:18:48 -06:00
local skillnamenoun , skillnum
unit = dfhack.gui . getSelectedUnit ( )
2015-09-04 00:51:28 -06:00
2015-09-21 16:18:48 -06:00
if unit == nil then
print ( " No unit under cursor! Aborting with extreme prejudice. " )
return
2015-09-04 00:51:28 -06:00
end
2015-09-21 16:18:48 -06:00
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
2015-09-04 00:51:28 -06:00
end
2015-09-21 16:18:48 -06:00
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
2015-09-04 00:51:28 -06:00
end
end
function PrintSkillList ( )
2015-09-21 16:18:48 -06:00
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 ] )
2015-09-04 00:51:28 -06:00
end
2015-09-21 16:18:48 -06:00
print ( " Provide the UPPER CASE argument, for example: PROCESSPLANTS rather than Threshing " )
2015-09-04 00:51:28 -06:00
end
function BreathOfArmok ( )
2015-09-21 16:18:48 -06:00
unit = dfhack.gui . getSelectedUnit ( )
if unit == nil then
print ( " No unit under cursor! Aborting with extreme prejudice. " )
return
2015-09-04 00:51:28 -06:00
end
2015-09-21 16:18:48 -06:00
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 ' )
2015-09-04 00:51:28 -06:00
end
2015-09-21 16:18:48 -06:00
print ( " The breath of Armok has engulfed " .. dfhack.TranslateName ( dfhack.units . getVisibleName ( unit ) ) )
2015-09-04 00:51:28 -06:00
end
function LegendaryByClass ( skilltype )
2015-09-21 16:18:48 -06:00
unit = dfhack.gui . getSelectedUnit ( )
if unit == nil then
print ( " No unit under cursor! Aborting with extreme prejudice. " )
return
2015-09-04 00:51:28 -06:00
end
2015-09-21 16:18:48 -06:00
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 ' )
2015-09-04 00:51:28 -06:00
end
end
end
function PrintSkillClassList ( )
2015-09-21 16:18:48 -06:00
local i
local count_max = count_this ( df.job_skill_class )
for i = 0 , count_max do
print ( df.job_skill_class [ i ] )
2015-09-04 00:51:28 -06:00
end
2015-09-21 16:18:48 -06:00
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 " )
2015-09-04 00:51:28 -06:00
end
--main script operation starts here
----
local opt = ...
local skillname
if opt then
if opt == " list " then
PrintSkillList ( )
return
2015-09-21 16:18:48 -06:00
end
2015-09-04 00:51:28 -06:00
if opt == " classes " then
PrintSkillClassList ( )
return
2015-09-21 16:18:48 -06:00
end
2015-09-04 00:51:28 -06:00
if opt == " all " then
BreathOfArmok ( )
return
2015-09-21 16:18:48 -06:00
end
2015-09-04 00:51:28 -06:00
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
2015-09-21 16:18:48 -06:00
end
2015-09-04 00:51:28 -06:00
skillname = opt
else
print ( " No skillname supplied. \n Use 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
2015-09-21 16:18:48 -06:00
end
2015-09-04 00:51:28 -06:00
2015-09-04 01:13:21 -06:00
make_legendary ( skillname )