dfhack/scripts/make-legendary.lua

142 lines
4.3 KiB
Lua

-- Make a skill or skills of a unit Legendary +5
2015-09-04 01:13:21 -06:00
-- by vjek
2015-10-23 22:10:15 -06:00
--[[=begin
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.
=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)
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])
end
2015-09-21 16:18:48 -06:00
count=count-1
return count
end
function getName(unit)
return dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(unit)))
end
function make_legendary(skillname)
2015-09-21 16:18:48 -06:00
local skillnamenoun,skillnum
unit=dfhack.gui.getSelectedUnit()
2015-09-21 16:18:48 -06:00
if unit==nil then
print ("No unit under cursor! Aborting with extreme prejudice.")
return
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
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 (getName(unit) .. " is now a Legendary "..skillnamenoun)
2015-09-21 16:18:48 -06:00
else
print ("Empty skill name noun, bailing out!")
return
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])
end
2015-09-21 16:18:48 -06:00
print ("Provide the UPPER CASE argument, for example: PROCESSPLANTS rather than Threshing")
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
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')
end
print ("The breath of Armok has engulfed "..getName(unit))
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
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 "..getName(unit))
2015-09-21 16:18:48 -06:00
utils.insert_or_update(unit.status.current_soul.skills, { new = true, id = i, rating = 20 }, 'id')
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])
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")
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
if opt=="classes" then
PrintSkillClassList()
return
2015-09-21 16:18:48 -06:00
end
if opt=="all" then
BreathOfArmok()
return
2015-09-21 16:18:48 -06:00
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
2015-09-21 16:18:48 -06:00
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
2015-09-21 16:18:48 -06:00
end
2015-09-04 01:13:21 -06:00
make_legendary(skillname)