Merge pull request #605 from Putnam3145/patch-15

Made hack-wish assign quality properly.
develop
Lethosor 2015-04-26 21:05:25 -04:00
commit 3d56ec3362
2 changed files with 65 additions and 57 deletions

@ -16,6 +16,7 @@ DFHack Future
Plugins with vmethod hooks can now be reloaded on OS X Plugins with vmethod hooks can now be reloaded on OS X
Lua's os.system() now works on OS X Lua's os.system() now works on OS X
Fixed default arguments in Lua gametype detection functions Fixed default arguments in Lua gametype detection functions
gui/hack-wish now properly assigns quality to items.
Misc Improvements Misc Improvements
"keybinding list" accepts a context "keybinding list" accepts a context
nyan: Can now be stopped with dfhack-run nyan: Can now be stopped with dfhack-run

@ -4,7 +4,7 @@
-- edited by expwnent -- edited by expwnent
function getGenderString(gender) local function getGenderString(gender)
local genderStr local genderStr
if gender==0 then if gender==0 then
genderStr=string.char(12) genderStr=string.char(12)
@ -16,7 +16,7 @@ function getGenderString(gender)
return string.char(40)..genderStr..string.char(41) return string.char(40)..genderStr..string.char(41)
end end
function getCreatureList() local function getCreatureList()
local crList={} local crList={}
for k,cr in ipairs(df.global.world.raws.creatures.alphabetic) do for k,cr in ipairs(df.global.world.raws.creatures.alphabetic) do
for kk,ca in ipairs(cr.caste) do for kk,ca in ipairs(cr.caste) do
@ -28,7 +28,47 @@ function getCreatureList()
return crList return crList
end end
function getMatFilter(itemtype) local function getRestrictiveMatFilter(itemType)
if not args.restrictive then return nil end
local itemTypes={
WEAPON=function(mat,parent,typ,idx)
return (mat.flags.ITEMS_WEAPON or mat.flags.ITEMS_WEAPON_RANGED)
end,
AMMO=function(mat,parent,typ,idx)
return (mat.flags.ITEMS_AMMO)
end,
ARMOR=function(mat,parent,typ,idx)
return (mat.flags.ITEMS_ARMOR)
end,
INSTRUMENT=function(mat,parent,typ,idx)
return (mat.flags.ITEMS_HARD)
end,
AMULET=function(mat,parent,typ,idx)
return (mat.flags.ITEMS_SOFT or mat.flags.ITEMS_HARD)
end,
ROCK=function(mat,parent,typ,idx)
return (mat.flags.IS_STONE)
end,
BOULDER=ROCK,
BAR=function(mat,parent,typ,idx)
return (mat.flags.IS_METAL or mat.flags.SOAP or mat.id==COAL)
end
}
for k,v in ipairs({'GOBLET','FLASK','TOY','RING','CROWN','SCEPTER','FIGURINE','TOOL'}) do
itemTypes[v]=itemTypes.INSTRUMENT
end
for k,v in ipairs({'SHOES','SHIELD','HELM','GLOVES'}) do
itemTypes[v]=itemTypes.ARMOR
end
for k,v in ipairs({'EARRING','BRACELET'}) do
itemTypes[v]=itemTypes.AMULET
end
itemTypes.BOULDER=itemTypes.ROCK
return itemTypes[df.item_type[itemType]]
end
local 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
@ -70,54 +110,17 @@ function getMatFilter(itemtype)
return itemTypes[df.item_type[itemtype]] or getRestrictiveMatFilter(itemtype) return itemTypes[df.item_type[itemtype]] or getRestrictiveMatFilter(itemtype)
end end
function getRestrictiveMatFilter(itemType) local function createItem(mat,itemType,quality,creator,description)
if not args.restrictive then return nil end local item=df.item.find(dfhack.items.createItem(itemType[1], itemType[2], mat[1], mat[2], creator))
local itemTypes={ if pcall(function() print(item.quality) end) then
WEAPON=function(mat,parent,typ,idx) item.quality=quality-1
return (mat.flags.ITEMS_WEAPON or mat.flags.ITEMS_WEAPON_RANGED)
end,
AMMO=function(mat,parent,typ,idx)
return (mat.flags.ITEMS_AMMO)
end,
ARMOR=function(mat,parent,typ,idx)
return (mat.flags.ITEMS_ARMOR)
end,
INSTRUMENT=function(mat,parent,typ,idx)
return (mat.flags.ITEMS_HARD)
end,
AMULET=function(mat,parent,typ,idx)
return (mat.flags.ITEMS_SOFT or mat.flags.ITEMS_HARD)
end,
ROCK=function(mat,parent,typ,idx)
return (mat.flags.IS_STONE)
end,
BOULDER=ROCK,
BAR=function(mat,parent,typ,idx)
return (mat.flags.IS_METAL or mat.flags.SOAP or mat.id==COAL)
end
}
for k,v in ipairs({'GOBLET','FLASK','TOY','RING','CROWN','SCEPTER','FIGURINE','TOOL'}) do
itemTypes[v]=itemTypes.INSTRUMENT
end end
for k,v in ipairs({'SHOES','SHIELD','HELM','GLOVES'}) do
itemTypes[v]=itemTypes.ARMOR
end
for k,v in ipairs({'EARRING','BRACELET'}) do
itemTypes[v]=itemTypes.AMULET
end
itemTypes.BOULDER=itemTypes.ROCK
return itemTypes[df.item_type[itemType]]
end
function createItem(mat,itemType,quality,creator,description)
dfhack.items.createItem(itemType[1], itemType[2], mat[1], mat[2], creator)
if df.item_type[itemType[1]]=='SLAB' then if df.item_type[itemType[1]]=='SLAB' then
item.description=description item.description=description
end end
end end
function qualityTable() local function qualityTable()
return {{'None'}, return {{'None'},
{'-Well-crafted-'}, {'-Well-crafted-'},
{'+Finely-crafted+'}, {'+Finely-crafted+'},
@ -129,7 +132,7 @@ end
local script=require('gui.script') local script=require('gui.script')
function showItemPrompt(text,item_filter,hide_none) local function showItemPrompt(text,item_filter,hide_none)
require('gui.materials').ItemTypeDialog{ require('gui.materials').ItemTypeDialog{
prompt=text, prompt=text,
item_filter=item_filter, item_filter=item_filter,
@ -142,7 +145,7 @@ function showItemPrompt(text,item_filter,hide_none)
return script.wait() return script.wait()
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 local 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
require('gui.materials').MaterialDialog{ require('gui.materials').MaterialDialog{
frame_title = title, frame_title = title,
prompt = prompt, prompt = prompt,
@ -158,12 +161,12 @@ function showMaterialPrompt(title, prompt, filter, inorganic, creature, plant) -
return script.wait() return script.wait()
end end
function usesCreature(itemtype) local function usesCreature(itemtype)
typesThatUseCreatures={REMAINS=true,FISH=true,FISH_RAW=true,VERMIN=true,PET=true,EGG=true,CORPSE=true,CORPSEPIECE=true} typesThatUseCreatures={REMAINS=true,FISH=true,FISH_RAW=true,VERMIN=true,PET=true,EGG=true,CORPSE=true,CORPSEPIECE=true}
return typesThatUseCreatures[df.item_type[itemtype]] return typesThatUseCreatures[df.item_type[itemtype]]
end end
function getCreatureRaceAndCaste(caste) local 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
@ -198,11 +201,15 @@ function hackWish(unit)
dfhack.items.createItem(itemtype, itemsubtype, mattype, matindex, unit) dfhack.items.createItem(itemtype, itemsubtype, mattype, matindex, unit)
end end
end end
return true
end end
return false
else else
if mattype and itemtype then if mattype and itemtype then
createItem({mattype,matindex},{itemtype,itemsubtype},quality,unit,description) createItem({mattype,matindex},{itemtype,itemsubtype},quality,unit,description)
return true
end end
return false
end end
end) end)
end end