Merge pull request #931 from warmist/advfort2

Advfort2
develop
Lethosor 2016-06-14 09:45:33 -04:00 committed by GitHub
commit a2b2c66798
3 changed files with 139 additions and 85 deletions

@ -126,19 +126,6 @@ jobs_workshop={
job_fields={job_type=df.job_type.CatchLiveFish} job_fields={job_type=df.job_type.CatchLiveFish}
}, -- no items? }, -- no items?
}, },
[df.workshop_type.Still]={
{
name="brew drink",
items={{flags1={distillable=true},vector_id=22},{flags1={empty=true},flags3={food_storage=true}}},
job_fields={job_type=df.job_type.BrewDrink}
},
{
name="extract from plants",
items={{item_type=df.item_type.PLANT,flags1={unrotten=true,extract_bearing_plant=true}},{item_type=df.item_type.FLASK,flags1={empty=true}}},
job_fields={job_type=df.job_type.ExtractFromPlants}
},
--mead from raws?
},
[df.workshop_type.Masons]={ [df.workshop_type.Masons]={
defaults={item_type=df.item_type.BOULDER,item_subtype=-1,vector_id=df.job_item_vector_id.BOULDER, mat_type=0,mat_index=-1,flags3={hard=true}},--flags2={non_economic=true}, defaults={item_type=df.item_type.BOULDER,item_subtype=-1,vector_id=df.job_item_vector_id.BOULDER, mat_type=0,mat_index=-1,flags3={hard=true}},--flags2={non_economic=true},
{ {
@ -336,20 +323,20 @@ jobs_workshop={
}, },
[df.workshop_type.Kitchen]={ [df.workshop_type.Kitchen]={
--mat_type=2,3,4 --mat_type=2,3,4
defaults={flags1={unrotten=true,cookable=true}}, defaults={flags1={unrotten=true}},
{ {
name="prepare easy meal", name="prepare easy meal",
items={{flags1={solid=true}},{}}, items={{flags1={solid=true,cookable=true}},{flags1={cookable=true}}},
job_fields={job_type=df.job_type.PrepareMeal,mat_type=2} job_fields={job_type=df.job_type.PrepareMeal,mat_type=2}
}, },
{ {
name="prepare fine meal", name="prepare fine meal",
items={{flags1={solid=true}},{},{}}, items={{flags1={solid=true,cookable=true}},{flags1={cookable=true}},{flags1={cookable=true}}},
job_fields={job_type=df.job_type.PrepareMeal,mat_type=3} job_fields={job_type=df.job_type.PrepareMeal,mat_type=3}
}, },
{ {
name="prepare lavish meal", name="prepare lavish meal",
items={{flags1={solid=true}},{},{},{}}, items={{flags1={solid=true,cookable=true}},{flags1={cookable=true}},{flags1={cookable=true}},{flags1={cookable=true}}},
job_fields={job_type=df.job_type.PrepareMeal,mat_type=4} job_fields={job_type=df.job_type.PrepareMeal,mat_type=4}
}, },
}, },

@ -11,6 +11,9 @@ keybinding. (e.g. ``keybinding set Ctrl-T gui/advfort``). Possible arguments:
:-a, --nodfassign: uses different method to assign items. :-a, --nodfassign: uses different method to assign items.
:-i, --inventory: checks inventory for possible items to use in the job. :-i, --inventory: checks inventory for possible items to use in the job.
:-c, --cheat: relaxes item requirements for buildings (e.g. walls from bones). Implies -a :-c, --cheat: relaxes item requirements for buildings (e.g. walls from bones). Implies -a
:-u, --unsafe: ignores dangerous conditions.
:-s, --safe: only allow building and etc. only if in site
:-q, --quick: quick item select mode
:job: selects that job (e.g. Dig or FellTree) :job: selects that job (e.g. Dig or FellTree)
An example of player digging in adventure mode: An example of player digging in adventure mode:
@ -22,8 +25,13 @@ An example of player digging in adventure mode:
=end]] =end]]
--[==[ --[==[
version: 0.044 version: 0.05
changelog: changelog:
*0.05
- fixed some reactions not showing. Now there is a '[fallback]' choice to choose from other way of getting reactions.
- fixed brewing accepting too many items instead of barrel
- fixed tallow making to accept fat
- display filters
*0.044 *0.044
- added output to clear_jobs of number of cleared jobs - added output to clear_jobs of number of cleared jobs
- another failed attempt at gather plants fix - another failed attempt at gather plants fix
@ -663,7 +671,7 @@ function RemoveBuilding(args)
end end
function isSuitableItem(job_item,item) function isSuitableItem(job_item,item)
--todo butcher test
if job_item.item_type~=-1 then if job_item.item_type~=-1 then
if item:getType()~= job_item.item_type then if item:getType()~= job_item.item_type then
return false, "type" return false, "type"
@ -696,29 +704,31 @@ function isSuitableItem(job_item,item)
return false,"already cooked" return false,"already cooked"
end end
if type(job_item) ~= "table" and not matinfo:matches(job_item) then if job_item.has_material_reaction_product~="" then
--[[ local ok=false
local true_flags={} for k,v in pairs(matinfo.material.reaction_product.id) do
for k,v in pairs(job_item.flags1) do if v.value==job_item.has_material_reaction_product then
if v then ok=true
table.insert(true_flags,k) break
end end
end end
for k,v in pairs(job_item.flags2) do if not ok then
if v then return false, "no material reaction product"
table.insert(true_flags,k)
end end
end end
for k,v in pairs(job_item.flags3) do if job_item.reaction_class~="" then
if v then local ok=false
table.insert(true_flags,k) for k,v in pairs(matinfo.material.reaction_class) do
if v.value==job_item.reaction_class then
ok=true
break
end end
end end
for k,v in pairs(true_flags) do if not ok then
print(v) return false, "no material reaction class"
end end
--]] end
if type(job_item) ~= "table" and not matinfo:matches(job_item) then
return false,"matinfo" return false,"matinfo"
end end
-- some bonus checks: -- some bonus checks:
@ -732,6 +742,7 @@ function isSuitableItem(job_item,item)
return false,"metal ore" return false,"metal ore"
end end
if job_item.min_dimension~=-1 then if job_item.min_dimension~=-1 then
end end
-- if #job_item.contains~=0 then -- if #job_item.contains~=0 then
-- end -- end
@ -740,30 +751,35 @@ function isSuitableItem(job_item,item)
return false,"tool use" return false,"tool use"
end end
end end
if job_item.has_material_reaction_product~="" then
local ok=false if job_item.flags3.food_storage and not item:isFoodStorage() then
for k,v in pairs(matinfo.material.reaction_product.id) do return false,"not food storage"
if v.value==job_item.has_material_reaction_product then
ok=true
break
end end
if job_item.flags1.empty and dfhack.items.getGeneralRef(item,df.general_ref_type.CONTAINS_ITEM) then
return false,"not empty"
end end
if not ok then --[[
return false, "no material reaction product" local true_flags={}
for k,v in pairs(job_item.flags1) do
if v then
table.insert(true_flags,k.." f1")
end end
end end
if job_item.reaction_class~="" then for k,v in pairs(job_item.flags2) do
local ok=false if v then
for k,v in pairs(matinfo.material.reaction_class) do table.insert(true_flags,k.." f2")
if v.value==job_item.reaction_class then
ok=true
break
end end
end end
if not ok then for k,v in pairs(job_item.flags3) do
return false, "no material reaction class" if v then
table.insert(true_flags,k.." f3")
end
end end
for k,v in pairs(true_flags) do
print(v)
end end
--]]
return true return true
end end
function getItemsUncollected(job) function getItemsUncollected(job)
@ -1386,7 +1402,37 @@ function usetool:onWorkShopButtonClicked(building,index,choice)
self:openShopWindowButtoned(building,true) self:openShopWindowButtoned(building,true)
end end
end end
function usetool:openShopWindowFallback( building,list)
local open_window=false
if not list then --if list is not passed we are responsible for showing the menu
list={}
open_window=true
end
local filter_pile=workshopJobs.getJobs(building:getType(),building:getSubtype(),building:getCustomType())
local adv=df.global.world.units.active[0]
local state={unit=adv,from_pos={x=adv.pos.x,y=adv.pos.y, z=adv.pos.z},building=building
,screen=self,bld=building}
if filter_pile then
local count=0
state.common=filter_pile.common
for i,v in ipairs(filter_pile) do
local label=v.name:lower()
table.insert(list,{job_id=0,text=label,filter=v})
count=count+1
end
end
if open_window then
dialog.showListPrompt("Workshop job choice", "Choose what to make",
COLOR_WHITE,list,
function (index,choice)
onWorkShopJobChosen(state,index,choice)
end
,nil, nil,true)
end
end
--no reset here means that the button opens submenu
function usetool:openShopWindowButtoned(building,no_reset) function usetool:openShopWindowButtoned(building,no_reset)
self:setupFields() self:setupFields()
local wui=df.global.ui_sidebar_menus.workshop_job local wui=df.global.ui_sidebar_menus.workshop_job
@ -1396,45 +1442,47 @@ function usetool:openShopWindowButtoned(building,no_reset)
for k,v in pairs(wui.material_category) do for k,v in pairs(wui.material_category) do
wui.material_category[k]=false wui.material_category[k]=false
end end
--]]
--[[building:fillSidebarMenu()
if #wui.choices_all>0 then
wui.choices_all[#wui.choices_all-1]:click()
end
--]]
end end
building:fillSidebarMenu() building:fillSidebarMenu()
local list={} local list={}
local names_already_in={}
for id,choice in pairs(wui.choices_visible) do for id,choice in pairs(wui.choices_visible) do
table.insert(list,{text=utils.call_with_string(choice,"getLabel"),button=choice}) local label=string.lower(utils.call_with_string(choice,"getLabel"))
table.insert(list,{text=label,button=choice,is_button=true})
names_already_in[label]=true
end end
if #list ==0 and not no_reset then
print("Fallback")
self:openShopWindow(building)
return
--qerror("No jobs for this workshop")
end
dialog.showListPrompt("Workshop job choice", "Choose what to make",COLOR_WHITE,list,self:callback("onWorkShopButtonClicked",building)
,nil, nil,true)
end
function usetool:openShopWindow(building)
local adv=df.global.world.units.active[0] local adv=df.global.world.units.active[0]
local filter_pile=workshopJobs.getJobs(building:getType(),building:getSubtype(),building:getCustomType())
if filter_pile then
local state={unit=adv,from_pos={x=adv.pos.x,y=adv.pos.y, z=adv.pos.z},building=building local state={unit=adv,from_pos={x=adv.pos.x,y=adv.pos.y, z=adv.pos.z},building=building
,screen=self,bld=building,common=filter_pile.common} ,screen=self,bld=building}
choices={} if #list==0 then
for k,v in pairs(filter_pile) do --we couldn't use the df hack so let's fill the list from fallback
table.insert(choices,{job_id=0,text=v.name:lower(),filter=v}) self:openShopWindowFallback(building,list)
else
--the hack worked. Though we are not sure how well so let's add a button for fallback
table.insert(list,{text='[fallback]'})
end end
dialog.showListPrompt("Workshop job choice", "Choose what to make",COLOR_WHITE,choices,dfhack.curry(onWorkShopJobChosen,state)
,nil, nil,true) if #list==0 then
qerror("no jobs for this shop")
end
dialog.showListPrompt("Workshop job choice", "Choose what to make",
COLOR_WHITE,list,
function (index,choice)
if choice.text=="[fallback]" then
self:openShopWindowFallback(building)
return
end
if choice.is_button then
self:onWorkShopButtonClicked(building,index,choice)
else else
qerror("No jobs for this workshop") onWorkShopJobChosen(state,index,choice)
end
end end
,nil, nil,true)
end end
function track_stop_configure(bld) --TODO: dedicated widget with nice interface and current setting display function track_stop_configure(bld) --TODO: dedicated widget with nice interface and current setting display
local dump_choices={ local dump_choices={
{text="no dumping"}, {text="no dumping"},

@ -100,6 +100,25 @@ function jobitemEditor:can_remove()
local slot=self:get_slot() local slot=self:get_slot()
return #slot.items>0 return #slot.items>0
end end
function jobitemEditor:get_item_filters( job_item )
local true_flags={}
for k,v in pairs(job_item.flags1) do
if v then
table.insert(true_flags,k)
end
end
for k,v in pairs(job_item.flags2) do
if v then
table.insert(true_flags,k)
end
end
for k,v in pairs(job_item.flags3) do
if v then
table.insert(true_flags,k)
end
end
return table.concat(true_flags,"\n")
end
function jobitemEditor:add_item() function jobitemEditor:add_item()
local cur_slot=self:get_slot() local cur_slot=self:get_slot()
local choices={} local choices={}
@ -110,7 +129,7 @@ function jobitemEditor:add_item()
end end
end end
gscript.start(function () gscript.start(function ()
local _,_2,choice=gscript.showListPrompt("which item?", "Select item", COLOR_WHITE, choices) local _,_2,choice=gscript.showListPrompt("which item?", "Select item\nItem filters:\n"..self:get_item_filters(cur_slot.job_item), COLOR_WHITE, choices)
if choice ~= nil and choice.item~=nil then if choice ~= nil and choice.item~=nil then
self:add_item_to_slot(cur_slot,choice.item) self:add_item_to_slot(cur_slot,choice.item)
end end