@ -3,6 +3,7 @@
-- author Putnam
-- author Putnam
-- edited by expwnent
-- edited by expwnent
function getGenderString ( gender )
function getGenderString ( gender )
local genderStr
local genderStr
if gender == 0 then
if gender == 0 then
@ -28,50 +29,50 @@ function getCreatureList()
end
end
function getMatFilter ( itemtype )
function getMatFilter ( itemtype )
local itemTypes = {
local itemTypes = {
SEEDS = function ( mat , parent , typ , idx )
SEEDS = function ( mat , parent , typ , idx )
return mat.flags . SEED_MAT
return mat.flags . SEED_MAT
end ,
end ,
PLANT = function ( mat , parent , typ , idx )
PLANT = function ( mat , parent , typ , idx )
return mat.flags . STRUCTURAL_PLANT_MAT
return mat.flags . STRUCTURAL_PLANT_MAT
end ,
end ,
LEAVES = function ( mat , parent , typ , idx )
LEAVES = function ( mat , parent , typ , idx )
return mat.flags . LEAF_MAT
return mat.flags . LEAF_MAT
end ,
end ,
MEAT = function ( mat , parent , typ , idx )
MEAT = function ( mat , parent , typ , idx )
return mat.flags . MEAT
return mat.flags . MEAT
end ,
end ,
CHEESE = function ( mat , parent , typ , idx )
CHEESE = function ( mat , parent , typ , idx )
return ( mat.flags . CHEESE_PLANT or mat.flags . CHEESE_CREATURE )
return ( mat.flags . CHEESE_PLANT or mat.flags . CHEESE_CREATURE )
end ,
end ,
LIQUID_MISC = function ( mat , parent , typ , idx )
LIQUID_MISC = function ( mat , parent , typ , idx )
return ( mat.flags . LIQUID_MISC_PLANT or mat.flags . LIQUID_MISC_CREATURE or mat.flags . LIQUID_MISC_OTHER )
return ( mat.flags . LIQUID_MISC_PLANT or mat.flags . LIQUID_MISC_CREATURE or mat.flags . LIQUID_MISC_OTHER )
end ,
end ,
POWDER_MISC = function ( mat , parent , typ , idx )
POWDER_MISC = function ( mat , parent , typ , idx )
return ( mat.flags . POWDER_MISC_PLANT or mat.flags . POWDER_MISC_CREATURE )
return ( mat.flags . POWDER_MISC_PLANT or mat.flags . POWDER_MISC_CREATURE )
end ,
end ,
DRINK = function ( mat , parent , typ , idx )
DRINK = function ( mat , parent , typ , idx )
return ( mat.flags . ALCOHOL_PLANT or mat.flags . ALCOHOL_CREATURE )
return ( mat.flags . ALCOHOL_PLANT or mat.flags . ALCOHOL_CREATURE )
end ,
end ,
GLOB = function ( mat , parent , typ , idx )
GLOB = function ( mat , parent , typ , idx )
return ( mat.flags . STOCKPILE_GLOB )
return ( mat.flags . STOCKPILE_GLOB )
end ,
end ,
WOOD = function ( mat , parent , typ , idx )
WOOD = function ( mat , parent , typ , idx )
return ( mat.flags . WOOD )
return ( mat.flags . WOOD )
end ,
end ,
THREAD = function ( mat , parent , typ , idx )
THREAD = function ( mat , parent , typ , idx )
return ( mat.flags . THREAD_PLANT )
return ( mat.flags . THREAD_PLANT )
end ,
end ,
LEATHER = function ( mat , parent , typ , idx )
LEATHER = function ( mat , parent , typ , idx )
return ( mat.flags . LEATHER )
return ( mat.flags . LEATHER )
end
end
}
}
return itemTypes [ df.item_type [ itemtype ] ] or getRestrictiveMatFilter ( itemtype )
return itemTypes [ df.item_type [ itemtype ] ] or getRestrictiveMatFilter ( itemtype )
end
end
function getRestrictiveMatFilter ( itemType )
function getRestrictiveMatFilter ( itemType )
if not args.veryRestrictive then return nil else
if not args.veryRestrictive then return nil else
local itemTypes = {
local itemTypes = {
WEAPON = function ( mat , parent , typ , idx )
WEAPON = function ( mat , parent , typ , idx )
return ( mat.flags . ITEMS_WEAPON or mat.flags . ITEMS_WEAPON_RANGED )
return ( mat.flags . ITEMS_WEAPON or mat.flags . ITEMS_WEAPON_RANGED )
end ,
end ,
@ -97,62 +98,33 @@ function getRestrictiveMatFilter(itemType)
BAR = function ( mat , parent , typ , idx )
BAR = function ( mat , parent , typ , idx )
return ( mat.flags . IS_METAL or mat.flags . SOAP or mat.id == COAL )
return ( mat.flags . IS_METAL or mat.flags . SOAP or mat.id == COAL )
end
end
}
}
return itemTypes [ df.item_type [ itemType ] ]
return itemTypes [ df.item_type [ itemType ] ]
end
end
end
end
function createItem ( mat , itemType , quality , pos , description )
function createItem ( mat , itemType , quality , creator , description )
local item = df [ df.item_type . attrs [ itemType [ 1 ] ] . classname ] : new ( )
dfhack.items . createItem ( itemType [ 1 ] , itemType [ 2 ] , mat [ 1 ] , mat [ 2 ] , creator )
item.id = df.global . item_next_id
df.global . world.items . all : insert ( ' # ' , item )
df.global . item_next_id = df.global . item_next_id + 1
item : setSubtype ( itemType [ 2 ] )
item : setMaterial ( mat [ 1 ] )
item : setMaterialIndex ( mat [ 2 ] )
if df.item_type [ itemType [ 1 ] ] == ' EGG ' then
local creature = df.creature_raw . find ( mat [ 1 ] )
local eggMat = { }
eggMat [ 1 ] = dfhack.matinfo . find ( creature.creature_id .. ' :EGGSHELL ' )
if eggMat [ 1 ] then
eggMat [ 2 ] = dfhack.matinfo . find ( creature.creature_id .. ' :EGG_WHITE ' )
eggMat [ 3 ] = dfhack.matinfo . find ( creature.creature_id .. ' EGG_YOLK ' )
for k , v in ipairs ( eggMat ) do
item.egg_materials . mat_type : insert ( ' # ' , v.type )
item.egg_materials . mat_index : insert ( ' # ' , v.index )
end
else
eggMat = dfhack.matinfo . find ( creature.creature_id .. ' :MUSCLE ' )
item.egg_materials . mat_type : insert ( ' # ' , eggMat.type )
item.egg_materials . mat_index : insert ( ' # ' , eggMat.index )
end
end
item : categorize ( true )
item.flags . removed = true
item : setSharpness ( 1 , 0 )
item : setQuality ( quality - 1 )
if df.item_type [ itemType [ 1 ] ] == ' SLAB ' then
if df.item_type [ itemType [ 1 ] ] == ' SLAB ' then
item.description = description
item.description = description
end
end
dfhack.items . moveToGround ( item , { x = pos.x , y = pos.y , z = pos.z } )
end
end
--TODO: should this be a function?
function qualityTable ( )
function qualityTable ( )
return { { ' None ' } ,
return { { ' None ' } ,
{ ' -Well-crafted- ' } ,
{ ' -Well-crafted- ' } ,
{ ' +Finely-crafted+ ' } ,
{ ' +Finely-crafted+ ' } ,
{ ' *Superior* ' } ,
{ ' *Superior* ' } ,
{ string.char ( 240 ) .. ' Exceptional ' .. string.char ( 240 ) } ,
{ string.char ( 240 ) .. ' Exceptional ' .. string.char ( 240 ) } ,
{ string.char ( 15 ) .. ' Masterwork ' .. string.char ( 15 ) }
{ string.char ( 15 ) .. ' Masterwork ' .. string.char ( 15 ) }
}
}
end
end
local script = require ( ' gui/script ' )
local script = require ( ' gui.script ' )
local guimaterials = require ( ' gui.materials ' )
function showItemPrompt ( text , item_filter , hide_none )
function showItemPrompt ( text , item_filter , hide_none )
guimaterials.ItemTypeDialog{
require ( ' gui.materials ' ) . ItemTypeDialog {
prompt = text ,
prompt = text ,
item_filter = item_filter ,
item_filter = item_filter ,
hide_none = hide_none ,
hide_none = hide_none ,
@ -165,7 +137,7 @@ function showItemPrompt(text,item_filter,hide_none)
end
end
function showMaterialPrompt ( title , prompt , filter , inorganic , creature , plant ) --the one included with DFHack doesn't have a filter or the inorganic, creature, plant things available
function showMaterialPrompt ( title , prompt , filter , inorganic , creature , plant ) --the one included with DFHack doesn't have a filter or the inorganic, creature, plant things available
guimaterials.MaterialDialog{
require( ' gui. materials' ) . MaterialDialog{
frame_title = title ,
frame_title = title ,
prompt = prompt ,
prompt = prompt ,
mat_filter = filter ,
mat_filter = filter ,
@ -189,10 +161,9 @@ function getCreatureRaceAndCaste(caste)
return df.global . world.raws . creatures.list_creature [ caste.index ] , df.global . world.raws . creatures.list_caste [ caste.index ]
return df.global . world.raws . creatures.list_creature [ caste.index ] , df.global . world.raws . creatures.list_caste [ caste.index ]
end
end
function hackWish ( posOrUnit )
function hackWish ( unit )
local pos = df.unit : is_instance ( posOrUnit ) and posOrUnit.pos or posOrUnit
script.start ( function ( )
script.start ( function ( )
--local amountok, amount
local amountok , amount
local matok , mattype , matindex , matFilter
local matok , mattype , matindex , matFilter
local itemok , itemtype , itemsubtype = showItemPrompt ( ' What item do you want? ' , function ( itype ) return df.item_type [ itype ] ~= ' CORPSE ' and df.item_type [ itype ] ~= ' FOOD ' end , true )
local itemok , itemtype , itemsubtype = showItemPrompt ( ' What item do you want? ' , function ( itype ) return df.item_type [ itype ] ~= ' CORPSE ' and df.item_type [ itype ] ~= ' FOOD ' end , true )
if not args.notRestrictive then
if not args.notRestrictive then
@ -210,43 +181,43 @@ function hackWish(posOrUnit)
local descriptionok
local descriptionok
descriptionok , description = script.showInputPrompt ( ' Slab ' , ' What should the slab say? ' , COLOR_WHITE )
descriptionok , description = script.showInputPrompt ( ' Slab ' , ' What should the slab say? ' , COLOR_WHITE )
end
end
--repeat amountok,amount=script.showInputPrompt('Wish','How many do you want? (numbers only!)',COLOR_LIGHTGREEN) until tonumber(amount)
if args.multi then
if mattype and itemtype then
repeat amountok , amount = script.showInputPrompt ( ' Wish ' , ' How many do you want? (numbers only!) ' , COLOR_LIGHTGREEN ) until tonumber ( amount )
--for i=1,tonumber(amount) do
if mattype and itemtype then
createItem ( { mattype , matindex } , { itemtype , itemsubtype } , quality , pos , description )
for i = 1 , tonumber ( amount ) do
--end
createItem ( { mattype , matindex } , { itemtype , itemsubtype } , quality , unit , description )
end
end
else
if mattype and itemtype then
createItem ( { mattype , matindex } , { itemtype , itemsubtype } , quality , unit , description )
end
end
end
end )
end )
end
end
scriptArgs = { ... }
scriptArgs = { ... }
args = { }
validArgs = validArgs or utils.invert ( {
' startup ' ,
for k , v in ipairs ( scriptArgs ) do
' all ' ,
v = v : lower ( )
' restrictive ' ,
if v == ' startup ' then args.startup = true end
' unit ' ,
if v == ' all ' then args.notRestrictive = true end
' multi '
if v == ' restrictive ' then args.veryRestrictive = true end
} )
if v == ' unit ' then args.unitNum = args [ k + 1 ] end
if v == ' x ' then args.x = args [ k + 1 ] end
if v == ' y ' then args.y = args [ k + 1 ] end
if v == ' z ' then args.z = args [ k + 1 ] end
end
eventful= require ( ' plugins.eventful ' )
utils = require ( ' utils ' )
function posIsValid ( po s)
args = utils.processArgs ( { ... } , validArgs )
return pos.x ~=- 30000 and pos or false
end
eventful = require ( ' plugins.eventful ' )
if not args.startup then
if not args.startup then
local posOrUnit= args.x and { x = args.x , y = args.y , z = args.z } or args.unitNum and df.unit . find ( args.unit Num) or posIsValid ( df.global . cursor ) or dfhack.gui . getSelectedUnit ( true )
local unit= args.unit and df.unit . find ( args.unit ) or dfhack.gui . getSelectedUnit ( true )
hackWish ( posOrU nit)
hackWish ( u nit)
else
else
eventful.onReactionComplete . hackWishP = function ( reaction , unit , input_items , input_reagents , output_items , call_native )
eventful.onReactionComplete . hackWishP = function ( reaction , unit , input_items , input_reagents , output_items , call_native )
if not reaction.code : find ( ' DFHACK_WISH ' ) then return nil end
if not reaction.code : find ( ' DFHACK_WISH ' ) then return nil end
hackWish ( unit )
hackWish ( unit )
end
end
end
end