Advfort bug fixes and quickmode addition.

develop
Warmist 2015-09-14 18:54:02 +03:00
parent b58ccc9e55
commit a1e0a30335
2 changed files with 66 additions and 9 deletions

@ -1,8 +1,12 @@
-- allows to do jobs in adv. mode. -- allows to do jobs in adv. mode.
--[==[ --[==[
version: 0.03 version: 0.04
changelog: changelog:
*0.04
- add (-q)uick mode. Autoselects materials.
- fixed few(?) crash bugs
- fixed job errors not being shown in df
*0.031 *0.031
- make forbiding optional (-s)afe mode - make forbiding optional (-s)afe mode
*0.03 *0.03
@ -60,6 +64,7 @@ up_alt1={key="CUSTOM_CTRL_E",desc="Use job up"},
up_alt2={key="CURSOR_UP_Z_AUX",desc="Use job up"}, up_alt2={key="CURSOR_UP_Z_AUX",desc="Use job up"},
use_same={key="A_MOVE_SAME_SQUARE",desc="Use job at the tile you are standing"}, use_same={key="A_MOVE_SAME_SQUARE",desc="Use job at the tile you are standing"},
workshop={key="CHANGETAB",desc="Show building menu"}, workshop={key="CHANGETAB",desc="Show building menu"},
quick={key="CUSTOM_Q",desc="Toggle quick item select"},
} }
-- building filters -- building filters
build_filter={ build_filter={
@ -124,6 +129,8 @@ for k,v in ipairs({...}) do --setting parsing
if v=="-c" or v=="--cheat" then if v=="-c" or v=="--cheat" then
settings.build_by_items=true settings.build_by_items=true
settings.df_assign=false settings.df_assign=false
elseif v=="-q" or v=="--quick" then
settings.quick=true
elseif v=="-s" or v=="--safe" then elseif v=="-s" or v=="--safe" then
settings.safe=true settings.safe=true
elseif v=="-i" or v=="--inventory" then elseif v=="-i" or v=="--inventory" then
@ -257,6 +264,26 @@ function make_native_job(args)
args.unlinked=true args.unlinked=true
end end
end end
function smart_job_delete( job )
local gref_types=df.general_ref_type
for i,v in ipairs(job.general_refs) do
if v:getType()==gref_types.BUILDING_HOLDER then
local b=v:getBuilding()
if b then
for i,v in ipairs(b.jobs) do
if v==job then
b.jobs:erase(i)
break
end
end
end
else
print("Warning: failed to remove link from job with type:",gref_types[v:getType()])
end
end
job:delete() --FIXME: smarter job delete here!!
end
function makeJob(args) function makeJob(args)
gscript.start(function () gscript.start(function ()
make_native_job(args) make_native_job(args)
@ -289,8 +316,10 @@ function makeJob(args)
addJobAction(args.job,args.unit) addJobAction(args.job,args.unit)
args.screen:wait_tick() args.screen:wait_tick()
else else
args.job:delete() if not args.no_job_delete then
dfhack.gui.showAnnouncement(msg,5,1) smart_job_delete(args.job)
end
dfhack.gui.showAnnouncement("Job failed:"..failed,5,1)
end end
end) end)
end end
@ -817,7 +846,22 @@ function AssignJobItems(args)
if settings.gui_item_select and #job.job_items>0 then if settings.gui_item_select and #job.job_items>0 then
local item_dialog=require('hack.scripts.gui.advfort_items') local item_dialog=require('hack.scripts.gui.advfort_items')
if settings.quick then --TODO not so nice hack. instead of rewriting logic for job item filling i'm using one in gui dialog...
local item_editor=item_dialog.jobitemEditor{
job = job,
items = item_suitability,
}
if item_editor:jobValid() then
item_editor:commit()
finish_item_assign(args)
return true
else
return false, "Quick select items"
end
else
local ret=item_dialog.showItemEditor(job,item_suitability) local ret=item_dialog.showItemEditor(job,item_suitability)
print("===",ret)
if ret then if ret then
finish_item_assign(args) finish_item_assign(args)
return true return true
@ -826,6 +870,7 @@ function AssignJobItems(args)
end end
--end) --end)
return false,"Selecting items" return false,"Selecting items"
end
else else
if not settings.build_by_items then if not settings.build_by_items then
for job_id, trg_job_item in ipairs(job.job_items) do for job_id, trg_job_item in ipairs(job.job_items) do
@ -846,6 +891,7 @@ CheckAndFinishBuilding=function (args,bld)
for idx,job in pairs(bld.jobs) do for idx,job in pairs(bld.jobs) do
if job.job_type==df.job_type.ConstructBuilding then if job.job_type==df.job_type.ConstructBuilding then
args.job=job args.job=job
args.no_job_delete=true
break break
end end
end end
@ -856,6 +902,7 @@ CheckAndFinishBuilding=function (args,bld)
local t={items=buildings.getFiltersByType({},bld:getType(),bld:getSubtype(),bld:getCustomType())} local t={items=buildings.getFiltersByType({},bld:getType(),bld:getSubtype(),bld:getCustomType())}
args.pre_actions={dfhack.curry(setFiltersUp,t),AssignBuildingRef}--,AssignJobItems args.pre_actions={dfhack.curry(setFiltersUp,t),AssignBuildingRef}--,AssignJobItems
end end
args.no_job_delete=true
makeJob(args) makeJob(args)
end end
function AssignJobToBuild(args) function AssignJobToBuild(args)
@ -1069,12 +1116,16 @@ usetool=defclass(usetool,gui.Screen)
usetool.focus_path = 'advfort' usetool.focus_path = 'advfort'
function usetool:getModeName() function usetool:getModeName()
local adv=df.global.world.units.active[0] local adv=df.global.world.units.active[0]
local ret
if adv.job.current_job then if adv.job.current_job then
return string.format("%s working(%d) ",(actions[(mode or 0)+1][1] or ""),adv.job.current_job.completion_timer) ret= string.format("%s working(%d) ",(actions[(mode or 0)+1][1] or ""),adv.job.current_job.completion_timer)
else else
return actions[(mode or 0)+1][1] or " " ret= actions[(mode or 0)+1][1] or " "
end end
if settings.quick then
ret=ret.."*"
end
return ret
end end
function usetool:update_site() function usetool:update_site()
@ -1595,6 +1646,8 @@ function usetool:onInput(keys)
elseif keys["A_SHORT_WAIT"] then elseif keys["A_SHORT_WAIT"] then
--ContinueJob(adv) --ContinueJob(adv)
self:sendInputToParent("A_SHORT_WAIT") self:sendInputToParent("A_SHORT_WAIT")
elseif keys[keybinds.quick.key] then
settings.quick=not settings.quick
elseif keys[keybinds.continue.key] then elseif keys[keybinds.continue.key] then
--ContinueJob(adv) --ContinueJob(adv)
--self:sendInputToParent("A_SHORT_WAIT") --self:sendInputToParent("A_SHORT_WAIT")

@ -179,7 +179,11 @@ function jobitemEditor:commit()
self:dismiss() self:dismiss()
if self.on_okay then self.on_okay(self.slots) end if self.on_okay then self.on_okay(self.slots) end
end end
function jobitemEditor:onDestroy()
if self.on_close then
self.on_close()
end
end
function showItemEditor(job,item_selections) function showItemEditor(job,item_selections)
jobitemEditor{ jobitemEditor{
job = job, job = job,