Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advfort2 #931

Merged
merged 3 commits into from
Jun 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions library/lua/dfhack/workshops.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,6 @@ jobs_workshop={
job_fields={job_type=df.job_type.CatchLiveFish}
}, -- 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]={
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does workshop_type need to be updated?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope this file (workshops.lua) is out of date. Though not much depends on it but there are some jobs that are no longer hardcoded.

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},
{
Expand Down Expand Up @@ -336,20 +323,20 @@ jobs_workshop={
},
[df.workshop_type.Kitchen]={
--mat_type=2,3,4
defaults={flags1={unrotten=true,cookable=true}},
defaults={flags1={unrotten=true}},
{
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}
},
{
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}
},
{
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}
},
},
Expand Down
182 changes: 115 additions & 67 deletions scripts/gui/advfort.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ keybinding. (e.g. ``keybinding set Ctrl-T gui/advfort``). Possible arguments:
:-a, --nodfassign: uses different method to assign items.
:-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
:-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)

An example of player digging in adventure mode:
Expand All @@ -22,8 +25,13 @@ An example of player digging in adventure mode:
=end]]

--[==[
version: 0.044
version: 0.05
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
- added output to clear_jobs of number of cleared jobs
- another failed attempt at gather plants fix
Expand Down Expand Up @@ -663,7 +671,7 @@ function RemoveBuilding(args)
end

function isSuitableItem(job_item,item)
--todo butcher test

if job_item.item_type~=-1 then
if item:getType()~= job_item.item_type then
return false, "type"
Expand Down Expand Up @@ -696,29 +704,31 @@ function isSuitableItem(job_item,item)
return false,"already cooked"
end

if type(job_item) ~= "table" and not matinfo:matches(job_item) then
--[[
local true_flags={}
for k,v in pairs(job_item.flags1) do
if v then
table.insert(true_flags,k)
if job_item.has_material_reaction_product~="" then
local ok=false
for k,v in pairs(matinfo.material.reaction_product.id) do
if v.value==job_item.has_material_reaction_product then
ok=true
break
end
end
for k,v in pairs(job_item.flags2) do
if v then
table.insert(true_flags,k)
end
if not ok then
return false, "no material reaction product"
end
for k,v in pairs(job_item.flags3) do
if v then
table.insert(true_flags,k)
end
if job_item.reaction_class~="" then
local ok=false
for k,v in pairs(matinfo.material.reaction_class) do
if v.value==job_item.reaction_class then
ok=true
break
end
end
for k,v in pairs(true_flags) do
print(v)
if not ok then
return false, "no material reaction class"
end
--]]
end
if type(job_item) ~= "table" and not matinfo:matches(job_item) then
return false,"matinfo"
end
-- some bonus checks:
Expand All @@ -732,6 +742,7 @@ function isSuitableItem(job_item,item)
return false,"metal ore"
end
if job_item.min_dimension~=-1 then

end
-- if #job_item.contains~=0 then
-- end
Expand All @@ -740,30 +751,35 @@ function isSuitableItem(job_item,item)
return false,"tool use"
end
end
if job_item.has_material_reaction_product~="" then
local ok=false
for k,v in pairs(matinfo.material.reaction_product.id) do
if v.value==job_item.has_material_reaction_product then
ok=true
break
end
end
if not ok then
return false, "no material reaction product"

if job_item.flags3.food_storage and not item:isFoodStorage() then
return false,"not food storage"
end

if job_item.flags1.empty and dfhack.items.getGeneralRef(item,df.general_ref_type.CONTAINS_ITEM) then
return false,"not empty"
end
--[[
local true_flags={}
for k,v in pairs(job_item.flags1) do
if v then
table.insert(true_flags,k.." f1")
end
end
if job_item.reaction_class~="" then
local ok=false
for k,v in pairs(matinfo.material.reaction_class) do
if v.value==job_item.reaction_class then
ok=true
break
end
for k,v in pairs(job_item.flags2) do
if v then
table.insert(true_flags,k.." f2")
end
if not ok then
return false, "no material reaction class"
end
for k,v in pairs(job_item.flags3) do
if v then
table.insert(true_flags,k.." f3")
end
end
for k,v in pairs(true_flags) do
print(v)
end
--]]
return true
end
function getItemsUncollected(job)
Expand Down Expand Up @@ -1386,7 +1402,37 @@ function usetool:onWorkShopButtonClicked(building,index,choice)
self:openShopWindowButtoned(building,true)
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)
self:setupFields()
local wui=df.global.ui_sidebar_menus.workshop_job
Expand All @@ -1396,45 +1442,47 @@ function usetool:openShopWindowButtoned(building,no_reset)
for k,v in pairs(wui.material_category) do
wui.material_category[k]=false
end
--]]
--[[building:fillSidebarMenu()
if #wui.choices_all>0 then
wui.choices_all[#wui.choices_all-1]:click()
end
--]]
end
building:fillSidebarMenu()

local list={}
local names_already_in={}
for id,choice in pairs(wui.choices_visible) do
table.insert(list,{text=utils.call_with_string(choice,"getLabel"),button=choice})
end
if #list ==0 and not no_reset then
print("Fallback")
self:openShopWindow(building)
return
--qerror("No jobs for this workshop")
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
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 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
,screen=self,bld=building,common=filter_pile.common}
choices={}
for k,v in pairs(filter_pile) do
table.insert(choices,{job_id=0,text=v.name:lower(),filter=v})
end
dialog.showListPrompt("Workshop job choice", "Choose what to make",COLOR_WHITE,choices,dfhack.curry(onWorkShopJobChosen,state)
,nil, nil,true)
,screen=self,bld=building}
if #list==0 then
--we couldn't use the df hack so let's fill the list from fallback
self:openShopWindowFallback(building,list)
else
qerror("No jobs for this workshop")
--the hack worked. Though we are not sure how well so let's add a button for fallback
table.insert(list,{text='[fallback]'})
end

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
onWorkShopJobChosen(state,index,choice)
end
end
,nil, nil,true)
end

function track_stop_configure(bld) --TODO: dedicated widget with nice interface and current setting display
local dump_choices={
{text="no dumping"},
Expand Down
21 changes: 20 additions & 1 deletion scripts/gui/advfort_items.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ function jobitemEditor:can_remove()
local slot=self:get_slot()
return #slot.items>0
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()
local cur_slot=self:get_slot()
local choices={}
Expand All @@ -110,7 +129,7 @@ function jobitemEditor:add_item()
end
end
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
self:add_item_to_slot(cur_slot,choice.item)
end
Expand Down