|
|
|
@ -1,8 +1,13 @@
|
|
|
|
|
-- allows to do jobs in adv. mode.
|
|
|
|
|
|
|
|
|
|
--[==[
|
|
|
|
|
version: 0.013
|
|
|
|
|
version: 0.02
|
|
|
|
|
changelog:
|
|
|
|
|
*0.02
|
|
|
|
|
- fixed axles not being able to be placed in other direction (thanks SyrusLD)
|
|
|
|
|
- added lever linking
|
|
|
|
|
- restructured advfort_items, don't forget to update that too!
|
|
|
|
|
- Added clutter view if shop is cluttered.
|
|
|
|
|
*0.013
|
|
|
|
|
- fixed siege weapons and traps (somewhat). Now you can load them with new menu :)
|
|
|
|
|
*0.012
|
|
|
|
@ -30,6 +35,7 @@
|
|
|
|
|
- items blocking construction stuck the game
|
|
|
|
|
- burning charcoal crashed game
|
|
|
|
|
- gem thingies probably broken
|
|
|
|
|
- custom reactions semibroken
|
|
|
|
|
|
|
|
|
|
--]==]
|
|
|
|
|
|
|
|
|
@ -470,7 +476,7 @@ function chooseBuildingWidthHeightDir(args) --TODO nicer selection dialog
|
|
|
|
|
local all=makeset{"w","h","d"}
|
|
|
|
|
local needs={[btype.FarmPlot]=area,[btype.Bridge]=all,
|
|
|
|
|
[btype.RoadDirt]=area,[btype.RoadPaved]=area,[btype.ScrewPump]=makeset{"d"},
|
|
|
|
|
[btype.AxleHorizontal]=makeset{"w","h"},[btype.WaterWheel]=makeset{"d"},[btype.Rollers]=makeset{"d"}}
|
|
|
|
|
[btype.AxleHorizontal]=all,[btype.WaterWheel]=makeset{"d"},[btype.Rollers]=makeset{"d"}}
|
|
|
|
|
local myneeds=needs[args.type]
|
|
|
|
|
if myneeds==nil then return end
|
|
|
|
|
if args.width==nil and myneeds.w then
|
|
|
|
@ -568,7 +574,7 @@ function isSuitableItem(job_item,item)
|
|
|
|
|
--print(matinfo:getCraftClass())
|
|
|
|
|
--print("Matching ",item," vs ",job_item)
|
|
|
|
|
|
|
|
|
|
if not matinfo:matches(job_item) then
|
|
|
|
|
if type(job_item) ~= "table" and not matinfo:matches(job_item) then
|
|
|
|
|
--[[
|
|
|
|
|
local true_flags={}
|
|
|
|
|
for k,v in pairs(job_item.flags1) do
|
|
|
|
@ -605,8 +611,8 @@ function isSuitableItem(job_item,item)
|
|
|
|
|
end
|
|
|
|
|
if job_item.min_dimension~=-1 then
|
|
|
|
|
end
|
|
|
|
|
if #job_item.contains~=0 then
|
|
|
|
|
end
|
|
|
|
|
-- if #job_item.contains~=0 then
|
|
|
|
|
-- end
|
|
|
|
|
if job_item.has_tool_use~=-1 then
|
|
|
|
|
if not item:hasToolUse(job_item.has_tool_use) then
|
|
|
|
|
return false,"tool use"
|
|
|
|
@ -729,37 +735,29 @@ function finish_item_assign(args)
|
|
|
|
|
uncollected[1].is_fetching=1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
function AssignJobItems(args)
|
|
|
|
|
--print("----")
|
|
|
|
|
if settings.df_assign then --use df default logic and hope that it would work
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
-- first find items that you want to use for the job
|
|
|
|
|
local job=args.job
|
|
|
|
|
local its
|
|
|
|
|
function EnumItems_with_settings( args )
|
|
|
|
|
if settings.check_inv then
|
|
|
|
|
its=EnumItems{pos=args.from_pos,unit=args.unit,
|
|
|
|
|
return EnumItems{pos=args.from_pos,unit=args.unit,
|
|
|
|
|
inv={[df.unit_inventory_item.T_mode.Hauled]=settings.use_worn,[df.unit_inventory_item.T_mode.Worn]=settings.use_worn,
|
|
|
|
|
[df.unit_inventory_item.T_mode.Weapon]=settings.use_worn,},deep=true}
|
|
|
|
|
else
|
|
|
|
|
its=EnumItems{pos=args.from_pos}
|
|
|
|
|
return EnumItems{pos=args.from_pos}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--[[while(#job.items>0) do --clear old job items
|
|
|
|
|
job.items[#job.items-1]:delete()
|
|
|
|
|
job.items:erase(#job.items-1)
|
|
|
|
|
end]]
|
|
|
|
|
end
|
|
|
|
|
function find_suitable_items(job,items,job_items)
|
|
|
|
|
job_items=job_items or job.job_items
|
|
|
|
|
|
|
|
|
|
local item_counts={}
|
|
|
|
|
for job_id, trg_job_item in ipairs(job.job_items) do
|
|
|
|
|
for job_id, trg_job_item in ipairs(job_items) do
|
|
|
|
|
item_counts[job_id]=trg_job_item.quantity
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local item_suitability={}
|
|
|
|
|
local used_item_id={}
|
|
|
|
|
for job_id, trg_job_item in ipairs(job.job_items) do
|
|
|
|
|
for job_id, trg_job_item in ipairs(job_items) do
|
|
|
|
|
item_suitability[job_id]={}
|
|
|
|
|
|
|
|
|
|
for _,cur_item in pairs(its) do
|
|
|
|
|
for _,cur_item in pairs(items) do
|
|
|
|
|
if not used_item_id[cur_item.id] then
|
|
|
|
|
|
|
|
|
|
local item_suitable,msg=isSuitableItem(trg_job_item,cur_item)
|
|
|
|
@ -783,14 +781,28 @@ function AssignJobItems(args)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
--print("before block")
|
|
|
|
|
return item_suitability,item_counts
|
|
|
|
|
end
|
|
|
|
|
function AssignJobItems(args)
|
|
|
|
|
--print("----")
|
|
|
|
|
if settings.df_assign then --use df default logic and hope that it would work
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
-- first find items that you want to use for the job
|
|
|
|
|
local job=args.job
|
|
|
|
|
local its=EnumItems_with_settings(args)
|
|
|
|
|
|
|
|
|
|
local item_suitability,item_counts=find_suitable_items(job,its)
|
|
|
|
|
--[[while(#job.items>0) do --clear old job items
|
|
|
|
|
job.items[#job.items-1]:delete()
|
|
|
|
|
job.items:erase(#job.items-1)
|
|
|
|
|
end]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if settings.gui_item_select and #job.job_items>0 then
|
|
|
|
|
local item_dialog=require('hack.scripts.gui.advfort_items')
|
|
|
|
|
--local rr=require('gui.script').start(function()
|
|
|
|
|
--print("before dialog")
|
|
|
|
|
local ret=item_dialog.showItemEditor(job,item_suitability)
|
|
|
|
|
--print("post dialog",ret)
|
|
|
|
|
--showItemEditor(job,item_suitability)
|
|
|
|
|
if ret then
|
|
|
|
|
finish_item_assign(args)
|
|
|
|
|
return true
|
|
|
|
@ -887,7 +899,106 @@ function ContinueJob(unit)
|
|
|
|
|
--unit.path.dest:assign(c_job.pos) -- FIXME: job pos is not always the target pos!!
|
|
|
|
|
addJobAction(c_job,unit)
|
|
|
|
|
end
|
|
|
|
|
-- function assign_link_refs(args )
|
|
|
|
|
-- local job=args.job
|
|
|
|
|
-- --job.general_refs:insert("#",{new=df.general_ref_building_holderst,building_id=args.building.id})
|
|
|
|
|
-- job.general_refs:insert("#",{new=df.general_ref_building_triggertargetst,building_id=args.triggertarget.id})
|
|
|
|
|
-- printall(job)
|
|
|
|
|
-- end
|
|
|
|
|
-- function assign_link_roles( args )
|
|
|
|
|
-- if #args.job.items~=2 then
|
|
|
|
|
-- print("AAA FAILED!")
|
|
|
|
|
-- return false
|
|
|
|
|
-- end
|
|
|
|
|
-- args.job.items[0].role=df.job_item_ref.T_role.LinkToTarget
|
|
|
|
|
-- args.job.items[1].role=df.job_item_ref.T_role.LinkToTrigger
|
|
|
|
|
-- end
|
|
|
|
|
function fake_linking(lever,building,slots)
|
|
|
|
|
local item1=slots[1].items[1]
|
|
|
|
|
local item2=slots[2].items[1]
|
|
|
|
|
if not dfhack.items.moveToBuilding(item1,lever,2) then
|
|
|
|
|
qerror("failed to move item to building")
|
|
|
|
|
end
|
|
|
|
|
if not dfhack.items.moveToBuilding(item2,building,2) then
|
|
|
|
|
qerror("failed to move item2 to building")
|
|
|
|
|
end
|
|
|
|
|
item2.general_refs:insert("#",{new=df.general_ref_building_triggerst,building_id=lever.id})
|
|
|
|
|
item1.general_refs:insert("#",{new=df.general_ref_building_triggertargetst,building_id=building.id})
|
|
|
|
|
|
|
|
|
|
lever.linked_mechanisms:insert("#",item2)
|
|
|
|
|
--fixes...
|
|
|
|
|
if building:getType()==df.building_type.Door then
|
|
|
|
|
building.door_flags.operated_by_mechanisms=true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
dfhack.gui.showAnnouncement("Linked!",COLOR_YELLOW,true)
|
|
|
|
|
end
|
|
|
|
|
function LinkBuilding(args)
|
|
|
|
|
local bld=args.building or dfhack.buildings.findAtTile(args.pos)
|
|
|
|
|
args.building=bld
|
|
|
|
|
|
|
|
|
|
local lever_bld
|
|
|
|
|
if lever_id then --intentionally global!
|
|
|
|
|
lever_bld=df.building.find(lever_id)
|
|
|
|
|
if lever_bld==nil then
|
|
|
|
|
lever_id=nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if lever_bld==nil then
|
|
|
|
|
if bld:getType()==df.building_type.Trap and bld:getSubtype()==df.trap_type.Lever then
|
|
|
|
|
lever_id=bld.id
|
|
|
|
|
dfhack.gui.showAnnouncement("Selected lever for linking",COLOR_YELLOW,true)
|
|
|
|
|
return
|
|
|
|
|
else
|
|
|
|
|
dfhack.gui.showAnnouncement("You first need a lever",COLOR_RED,true)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if lever_bld==bld then
|
|
|
|
|
dfhack.gui.showAnnouncement("Invalid target",COLOR_RED,true) --todo more invalid targets
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
-- args.job_type=df.job_type.LinkBuildingToTrigger
|
|
|
|
|
-- args.building=lever_bld
|
|
|
|
|
-- args.triggertarget=bld
|
|
|
|
|
-- args.pre_actions={
|
|
|
|
|
-- dfhack.curry(setFiltersUp,{items={{quantity=1,item_type=df.item_type.TRAPPARTS},{quantity=1,item_type=df.item_type.TRAPPARTS}}}),
|
|
|
|
|
-- AssignJobItems,
|
|
|
|
|
-- assign_link_refs,}
|
|
|
|
|
-- args.post_actions={AssignBuildingRef,assign_link_roles}
|
|
|
|
|
-- makeJob(args)
|
|
|
|
|
local input_filter_defaults = { --stolen from buildings lua to better customize...
|
|
|
|
|
item_type = df.item_type.TRAPPARTS,
|
|
|
|
|
item_subtype = -1,
|
|
|
|
|
mat_type = -1,
|
|
|
|
|
mat_index = -1,
|
|
|
|
|
flags1 = {},
|
|
|
|
|
-- Instead of noting those that allow artifacts, mark those that forbid them.
|
|
|
|
|
-- Leaves actually enabling artifacts to the discretion of the API user,
|
|
|
|
|
-- which is the right thing because unlike the game UI these filters are
|
|
|
|
|
-- used in a way that does not give the user a chance to choose manually.
|
|
|
|
|
flags2 = { allow_artifact = true },
|
|
|
|
|
flags3 = {},
|
|
|
|
|
flags4 = 0,
|
|
|
|
|
flags5 = 0,
|
|
|
|
|
reaction_class = '',
|
|
|
|
|
has_material_reaction_product = '',
|
|
|
|
|
metal_ore = -1,
|
|
|
|
|
min_dimension = -1,
|
|
|
|
|
has_tool_use = -1,
|
|
|
|
|
quantity = 1
|
|
|
|
|
}
|
|
|
|
|
local job_items={copyall(input_filter_defaults),copyall(input_filter_defaults)}
|
|
|
|
|
local its=EnumItems_with_settings(args)
|
|
|
|
|
local suitability=find_suitable_items(nil,its,job_items)
|
|
|
|
|
require('hack.scripts.gui.advfort_items').jobitemEditor{items=suitability,job_items=job_items,on_okay=dfhack.curry(fake_linking,lever_bld,bld)}:show()
|
|
|
|
|
lever_id=nil
|
|
|
|
|
end
|
|
|
|
|
--one item as LinkToTrigger role
|
|
|
|
|
--one item as LinkToTarget
|
|
|
|
|
--genref for holder(lever)
|
|
|
|
|
--genref for triggertarget
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
actions={
|
|
|
|
|
{"CarveFortification" ,df.job_type.CarveFortification,{IsWall,IsHardMaterial}},
|
|
|
|
|
{"DetailWall" ,df.job_type.DetailWall,{IsWall,IsHardMaterial}},
|
|
|
|
@ -914,6 +1025,7 @@ actions={
|
|
|
|
|
{"BuildLast" ,BuildLast,{NoConstructedBuilding}},
|
|
|
|
|
{"Clean" ,df.job_type.Clean,{}},
|
|
|
|
|
{"GatherWebs" ,df.job_type.CollectWebs,{--[[HasWeb]]},{SetWebRef}},
|
|
|
|
|
{"Link Buildings" ,LinkBuilding,{IsBuilding}},
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -950,7 +1062,7 @@ function usetool:init(args)
|
|
|
|
|
frame = {l=35,xalign=0,yalign=0},
|
|
|
|
|
visible=false,
|
|
|
|
|
text={
|
|
|
|
|
{id="text1",gap=1,key=keybinds.workshop.key,key_sep="()", text="Workshop menu",pen=dfhack.pen.parse{fg=COLOR_YELLOW,bg=0}}}
|
|
|
|
|
{id="text1",gap=1,key=keybinds.workshop.key,key_sep="()", text="Workshop menu",pen=dfhack.pen.parse{fg=COLOR_YELLOW,bg=0}},{id="clutter"}}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
wid.Label{
|
|
|
|
@ -1306,6 +1418,11 @@ function usetool:shopMode(enable,mode,building)
|
|
|
|
|
self.subviews.shopLabel.visible=enable
|
|
|
|
|
if mode then
|
|
|
|
|
self.subviews.shopLabel:itemById("text1").text=mode.name
|
|
|
|
|
if building:getClutterLevel()<=1 then
|
|
|
|
|
self.subviews.shopLabel:itemById("clutter").text=""
|
|
|
|
|
else
|
|
|
|
|
self.subviews.shopLabel:itemById("clutter").text=" Clutter:"..tostring(building:getClutterLevel())
|
|
|
|
|
end
|
|
|
|
|
self.building=building
|
|
|
|
|
end
|
|
|
|
|
self.mode=mode
|
|
|
|
|