@ -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
@ -97,47 +98,19 @@ 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- ' } ,
@ -148,11 +121,10 @@ function qualityTable()
}
}
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
repeat amountok , amount = script.showInputPrompt ( ' Wish ' , ' How many do you want? (numbers only!) ' , COLOR_LIGHTGREEN ) until tonumber ( amount )
if mattype and itemtype then
for i = 1 , tonumber ( amount ) do
createItem ( { mattype , matindex } , { itemtype , itemsubtype } , quality , unit , description )
end
end
else
if mattype and itemtype then
if mattype and itemtype then
--for i=1,tonumber(amount) do
createItem ( { mattype , matindex } , { itemtype , itemsubtype } , quality , unit , description )
createItem ( { mattype , matindex } , { itemtype , itemsubtype } , quality , pos , description )
end
--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