v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

User:Andux/Scripts

From Dwarf Fortress Wiki
< User:Andux
Revision as of 16:05, 19 July 2018 by Andux (talk | contribs) (+Kinsey, remove HealUnit (made obsolete by DFHack's included full-heal script))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

A collection of scripts for DFHack.

Fortress mode[edit]

Name generator[edit]

Based on Aerval's; changes:

  • Expanded selection of name parts.
  • Uses the world's name seed instead of the dwarf race index.
  • Better handling of historical figures.
--Nameparts by http://jtevans.kilnar.com/rpg/dnd/tools/dwarf.php, Aerval, and Andux
local firstnamepart = {
	"ad", "ak", "an", "ar", "ash", "at",
	"ba", "bal", "bar", "bel", "ber", "bil", "bof", "bol", "bro", "bul",
	"cal", "chal",
	"da", "das", "dal", "dim", "dor", "dru", "dur", "dwe", "dwin",
	"el",
	"fal", "far", "fash", "fel", "fim", "ful", "fun",
	"gal", "gar", "ger", "gil", "gim", "gom", "gol", "gri", "gro", "gru", "grun",
	"ha", "hal", "ham", "har", "hel", "her", "ho", "hol", "hor", "hul",
	"ing", "in", "ir",

	"kal", "kas", "ket", "kha", "khor", "kil", "kin", "ko", "kor", "kul",
	"lam", "lar", "lon", "lun",
	"mag", "mal", "mar", "mor", "mun",
	"nal", "nar", "nil", "nor",
	"ol", "or", "ov",

	"rag", "ral", "ram", "rim", "ron", "run", 
	"sal", "sar", "shal", "shar", "shor", "sim", "sor", "stal", "stav", "sven",
	"tan", "tha", "thal", "thin", "thor", "thra", "thu", 
	"um", "ur",
	"val", "van",
	"wil",

	"yar",
	"za", "zir", "zul"
};
local female_secondpart = {
	"a", "ada", "ala", "ana", "ani", "atha",
	"bari", "bina", "bine", "bura", 
	"cha", "chi",
	"da", "dana", "dani", "dili", "dina", "dola", "dora", "dri", "dria", 
	"edi", "ena", "eta", "eva", "eza",
	"fani", "fi",
	"ga", "gana", "gari", "gela", "gina", "gini", "goli", "grima", 

	"i", "ia", "ida", "ila", "ilda", "ili", "ika", "ina", "iri",

	"ka", "ki", "kia", "kona", "kuni",
	"la", "lani", "leda", "lena", "lia", "lina", "lona",
	"ma", "mani", "mela", "mina", "moda", "modi",
	"na", "neva", "ni", "nia", "nomi",
	"ola", "olga", "ona", "ondi", "oti", "ova",

	"ra", "raka", "rana", "ravi", "ri", "ria", "rimi", "rinda", "rundi", 
	"sha", "shi", "si", "ska",
	"ta", "tha", "ti", "tila", "tri", "tria", 
	"umma", "undi", "unga", "unni", 
	"vala", "vali", "vara", "vari", "vina",

	"ya",
	"zadi", "zani", "zara", "zi"
};
local male_secondpart = {
	"aim", "ain", "ak", "ald", "am", "ar", "ard", "ash", 
	"bain", "bald", "ban", "bar", "bash", "brun", "bur", 

	"dain", "dall", "dar", "din", "dok", "dol", "dor", "dum", "dun", "dur",
	"eff", "esh", "ev",
	"far", "fath", "feb",
	"gan", "gar", "gath", "gin", "gor", "grim", 

	"ik", "il", "im", "in", "ip", "isch", 

	"kad", "kar", "kash", "keld", "kesh", "kon", 
	"lek", "lem", "lesh", "let", "leth", "lin", "lor", 
	"mar", "mek", "min", "mok", "mon", "moth", "mund", 
	"nar", "nek", "nir", "nod", "nor", 
	"od", "oin", "ok", "old", "on", "ond", "or", 

	"rak", "ram", "rik", "rim", "rin", "ros", "roth", "rund", 
	"skal", "skar",
	"tar", "tek", "til", "tok", "tul",
	"um", "und", "unn", "ur", "urd",
	"val", "van", "var", "vath", "vek", "ven", "vesh", "veth", "vin", "von",

	"zad", "zar", "zek", "zim", "zin"
};

local dwarfRace = df.global.ui.race_id;

math.randomseed(tonumber(df.global.world.worldgen.worldgen_parms.name_seed,36));
for index,unit in pairs(df.global.world.history.figures) do --Renaming all the historical dwarves
	if ( unit.race == dwarfRace ) then
		if (unit.sex ~= 0) then
			unit.name.first_name = firstnamepart[math.random(#firstnamepart)]..male_secondpart[math.random(#male_secondpart)];
		else
			unit.name.first_name = firstnamepart[math.random(#firstnamepart)]..female_secondpart[math.random(#female_secondpart)];
		end
	end
end
for index,unit in pairs(df.global.world.units.all) do --Renaming pretty much everyone else
	if ( unit.race == dwarfRace ) then
		if unit.flags1.important_historical_figure or unit.flags2.important_historical_figure then
			--Use the same name as the histfig data
			unit.name.first_name = df.historical_figure.find(unit.hist_figure_id).name.first_name;
		else
			if (unit.sex ~= 0) then
				unit.name.first_name = firstnamepart[math.random(#firstnamepart)]..male_secondpart[math.random(#male_secondpart)];
			else
				unit.name.first_name = firstnamepart[math.random(#firstnamepart)]..female_secondpart[math.random(#female_secondpart)];
			end
		end
	end
end
print("firstnamepart: "..#firstnamepart.."\nfemale: "..#female_secondpart.."\nmale: "..#male_secondpart);

Adventure mode[edit]

Item material changer[edit]

Roughly equivalent to changeitem m, but works better in adventure mode.

local r=nil
local top=dfhack.gui.getCurViewscreen()
print(top.parent,top)
local cvstype=dfhack.gui.getFocusString(top)
print(dfhack.gui.getFocusString(top.parent).."/"..cvstype)
if cvstype=="dungeon_monsterstatus" then
	print("  inventory size: "..#top.inventory)
	print("  inventory_cursor: "..top.inventory_cursor)
	r=top.inventory[top.inventory_cursor].item
elseif cvstype=="item" then
	-- override getSelectedItem()'s default behaviour for containers
	r=top.item
else
	r=dfhack.gui.getSelectedItem()
end

if r then
	local m=...
	if not m then
		print("no material")
		return
	end

	r.mat_type=dfhack.matinfo.find(m).type
	r.mat_index=dfhack.matinfo.find(m).index
	r.flags.weight_computed=0

	printall(r)
end

Urbanizer[edit]

For older versions of Dwarf Fortress--converts all forest retreats to visitable towns.

for k,v in pairs(df.global.world.world_data.sites) do
	if v.type==4 then
		v.type=5
		print('Site #'..k..': '..dfhack.TranslateName(v.name)..', "'..dfhack.TranslateName(v.name,1)..'", converted to town.')
	end
end

General[edit]

GoodAsNew[edit]

Removes all wear from the selected item.

local r=nil
local top=dfhack.gui.getCurViewscreen()
print(top.parent,top)
local cvstype=dfhack.gui.getFocusString(top)
print(dfhack.gui.getFocusString(top.parent).."/"..cvstype)
if cvstype=="dungeon_monsterstatus" then
	print("  inventory size: "..#top.inventory)
	print("  inventory_cursor: "..top.inventory_cursor)
	r=top.inventory[top.inventory_cursor].item
else
	r=dfhack.gui.getSelectedItem()
end

if r then
	r.wear=0
	r.wear_timer=0
	printall(r)
end

Kinsey[edit]

-- View or change the sexual orientation of the selected unit.

--[====[

kinsey
======
View or change the sexual orientation of the selected unit. Usage:

:kinsey:
    Print the unit's orientation flags.
:kinsey -asexual:
    Change flags so that the unit will not romance or marry anyone.
:kinsey -rf:
    Allow the unit to romance females.
:kinsey -rm:
    Allow the unit to romance males.
:kinsey -mf:
    Allow the unit to marry females.
:kinsey -mm:
    Allow the unit to marry males.
:kinsey -indeterminate:
    Mark the unit's orientation as indeterminate (default for adventurers).

Apart from the -asexual flag, any of the options above can be used together;
for example, ``kinsey -rm -mf`` will allow a unit to romance either sex, but
only marry females.

]====]

local utils = require('utils')

local validArgs = utils.invert({
    'asexual',
    'rf',
    'rm',
    'mf',
    'mm',
    'indeterminate',
    'help',
})

local args = utils.processArgs({...}, validArgs)

if args.help then
	print(dfhack.script_help())
	return
end

local unit = dfhack.gui.getSelectedUnit()
if not unit then
	qerror('Error: please select a unit.')
end

local hf = df.historical_figure.find(unit.hist_figure_id)
if not hf then
	print("Warning: Couldn't find histfig data for this unit.")
end

if unit then
	if args.asexual then
		unit.status.current_soul.orientation_flags.indeterminate = false
		unit.status.current_soul.orientation_flags.romance_male = false
		unit.status.current_soul.orientation_flags.marry_male = false
		unit.status.current_soul.orientation_flags.romance_female = false
		unit.status.current_soul.orientation_flags.marry_female = false
		print("Unit orientation flags cleared.")
		if hf then
			hf.orientation_flags.indeterminate = false
			hf.orientation_flags.romance_male = false
			hf.orientation_flags.marry_male = false
			hf.orientation_flags.romance_female = false
			hf.orientation_flags.marry_female = false
			print("Changes propagated to histfig data.")
		end

	elseif args.indeterminate or args.rm or args.mm or args.rf or args.mf then
		unit.status.current_soul.orientation_flags.indeterminate = (args.indeterminate~=nil)
		unit.status.current_soul.orientation_flags.romance_male = (args.rm~=nil)
		unit.status.current_soul.orientation_flags.marry_male = (args.mm~=nil)
		unit.status.current_soul.orientation_flags.romance_female = (args.rf~=nil)
		unit.status.current_soul.orientation_flags.marry_female = (args.mf~=nil)
		print("Unit orientation flags updated.")
		if hf then
			hf.orientation_flags.indeterminate = unit.status.current_soul.orientation_flags.indeterminate
			hf.orientation_flags.romance_male = unit.status.current_soul.orientation_flags.romance_male
			hf.orientation_flags.marry_male = unit.status.current_soul.orientation_flags.marry_male
			hf.orientation_flags.romance_female = unit.status.current_soul.orientation_flags.romance_female
			hf.orientation_flags.marry_female = unit.status.current_soul.orientation_flags.marry_female
			print("Histfig data updated to match.")
		end
	end

	print("Current orientation flags:")
	print("  indeterminate: ", unit.status.current_soul.orientation_flags.indeterminate)
	print("  romance_male:  ", unit.status.current_soul.orientation_flags.romance_male)
	print("  marry_male:    ", unit.status.current_soul.orientation_flags.marry_male)
	print("  romance_female:", unit.status.current_soul.orientation_flags.romance_female)
	print("  marry_female:  ", unit.status.current_soul.orientation_flags.marry_female)
end