Axle fix, lever linking, clutter display.

develop
Warmist 2015-02-04 00:04:12 +02:00
parent cd027afe90
commit 510fdd529c
2 changed files with 207 additions and 79 deletions

@ -1,8 +1,13 @@
-- allows to do jobs in adv. mode. -- allows to do jobs in adv. mode.
--[==[ --[==[
version: 0.013 version: 0.02
changelog: 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 *0.013
- fixed siege weapons and traps (somewhat). Now you can load them with new menu :) - fixed siege weapons and traps (somewhat). Now you can load them with new menu :)
*0.012 *0.012
@ -30,6 +35,7 @@
- items blocking construction stuck the game - items blocking construction stuck the game
- burning charcoal crashed game - burning charcoal crashed game
- gem thingies probably broken - 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 all=makeset{"w","h","d"}
local needs={[btype.FarmPlot]=area,[btype.Bridge]=all, local needs={[btype.FarmPlot]=area,[btype.Bridge]=all,
[btype.RoadDirt]=area,[btype.RoadPaved]=area,[btype.ScrewPump]=makeset{"d"}, [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] local myneeds=needs[args.type]
if myneeds==nil then return end if myneeds==nil then return end
if args.width==nil and myneeds.w then if args.width==nil and myneeds.w then
@ -568,7 +574,7 @@ function isSuitableItem(job_item,item)
--print(matinfo:getCraftClass()) --print(matinfo:getCraftClass())
--print("Matching ",item," vs ",job_item) --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={} local true_flags={}
for k,v in pairs(job_item.flags1) do for k,v in pairs(job_item.flags1) do
@ -605,8 +611,8 @@ function isSuitableItem(job_item,item)
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
if job_item.has_tool_use~=-1 then if job_item.has_tool_use~=-1 then
if not item:hasToolUse(job_item.has_tool_use) then if not item:hasToolUse(job_item.has_tool_use) then
return false,"tool use" return false,"tool use"
@ -729,37 +735,29 @@ function finish_item_assign(args)
uncollected[1].is_fetching=1 uncollected[1].is_fetching=1
end end
end end
function AssignJobItems(args) function EnumItems_with_settings( 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
if settings.check_inv then 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, 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} [df.unit_inventory_item.T_mode.Weapon]=settings.use_worn,},deep=true}
else else
its=EnumItems{pos=args.from_pos} return EnumItems{pos=args.from_pos}
end end
end
--[[while(#job.items>0) do --clear old job items function find_suitable_items(job,items,job_items)
job.items[#job.items-1]:delete() job_items=job_items or job.job_items
job.items:erase(#job.items-1)
end]]
local item_counts={} 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 item_counts[job_id]=trg_job_item.quantity
end end
local item_suitability={} local item_suitability={}
local used_item_id={} 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]={} 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 if not used_item_id[cur_item.id] then
local item_suitable,msg=isSuitableItem(trg_job_item,cur_item) local item_suitable,msg=isSuitableItem(trg_job_item,cur_item)
@ -783,14 +781,28 @@ function AssignJobItems(args)
end end
end 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 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')
--local rr=require('gui.script').start(function()
--print("before dialog")
local ret=item_dialog.showItemEditor(job,item_suitability) local ret=item_dialog.showItemEditor(job,item_suitability)
--print("post dialog",ret)
--showItemEditor(job,item_suitability)
if ret then if ret then
finish_item_assign(args) finish_item_assign(args)
return true 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!! --unit.path.dest:assign(c_job.pos) -- FIXME: job pos is not always the target pos!!
addJobAction(c_job,unit) addJobAction(c_job,unit)
end 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={ actions={
{"CarveFortification" ,df.job_type.CarveFortification,{IsWall,IsHardMaterial}}, {"CarveFortification" ,df.job_type.CarveFortification,{IsWall,IsHardMaterial}},
{"DetailWall" ,df.job_type.DetailWall,{IsWall,IsHardMaterial}}, {"DetailWall" ,df.job_type.DetailWall,{IsWall,IsHardMaterial}},
@ -914,6 +1025,7 @@ actions={
{"BuildLast" ,BuildLast,{NoConstructedBuilding}}, {"BuildLast" ,BuildLast,{NoConstructedBuilding}},
{"Clean" ,df.job_type.Clean,{}}, {"Clean" ,df.job_type.Clean,{}},
{"GatherWebs" ,df.job_type.CollectWebs,{--[[HasWeb]]},{SetWebRef}}, {"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}, frame = {l=35,xalign=0,yalign=0},
visible=false, visible=false,
text={ 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{ wid.Label{
@ -1306,6 +1418,11 @@ function usetool:shopMode(enable,mode,building)
self.subviews.shopLabel.visible=enable self.subviews.shopLabel.visible=enable
if mode then if mode then
self.subviews.shopLabel:itemById("text1").text=mode.name 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 self.building=building
end end
self.mode=mode self.mode=mode

@ -12,6 +12,7 @@ jobitemEditor.ATTRS{
allow_remove=false, allow_remove=false,
allow_any_item=false, allow_any_item=false,
job=DEFAULT_NIL, job=DEFAULT_NIL,
job_items=DEFAULT_NIL,
items=DEFAULT_NIL, items=DEFAULT_NIL,
on_okay=DEFAULT_NIL, on_okay=DEFAULT_NIL,
} }
@ -29,7 +30,7 @@ end
--items-> table => key-> id of job.job_items, value-> table => key (num), value => item(ref) --items-> table => key-> id of job.job_items, value-> table => key (num), value => item(ref)
function jobitemEditor:init(args) function jobitemEditor:init(args)
--self.job=args.job --self.job=args.job
if self.job==nil then qerror("This screen must have job target") end if self.job==nil and self.job_items==nil then qerror("This screen must have job target or job_items list") end
if self.items==nil then qerror("This screen must have item list") end if self.items==nil then qerror("This screen must have item list") end
self:addviews{ self:addviews{
@ -124,7 +125,15 @@ end
function jobitemEditor:fill() function jobitemEditor:fill()
self.slots={} self.slots={}
for k,v in pairs(self.items) do for k,v in pairs(self.items) do
table.insert(self.slots,{job_item=self.job.job_items[k], id=k, items={},choices=v,filled_amount=0,slot_id=#self.slots}) local job_item
if self.job then
job_item=self.job.job_items[k]
else
job_item=self.job_items[k]
end
table.insert(self.slots,{job_item=job_item, id=k, items={},choices=v,filled_amount=0,slot_id=#self.slots})
update_slot_text(self.slots[#self.slots]) update_slot_text(self.slots[#self.slots])
end end
self.subviews.itemList:setChoices(self.slots) self.subviews.itemList:setChoices(self.slots)
@ -139,13 +148,15 @@ function jobitemEditor:jobValid()
return true return true
end end
function jobitemEditor:commit() function jobitemEditor:commit()
if self.job then
for _,slot in pairs(self.slots) do for _,slot in pairs(self.slots) do
for _1,cur_item in pairs(slot.items) do for _1,cur_item in pairs(slot.items) do
self.job.items:insert("#",{new=true,item=cur_item,role=df.job_item_ref.T_role.Reagent,job_item_idx=slot.id}) self.job.items:insert("#",{new=true,item=cur_item,role=df.job_item_ref.T_role.Reagent,job_item_idx=slot.id})
end end
end end
end
self:dismiss() self:dismiss()
if self.on_okay then self:on_okay() end if self.on_okay then self.on_okay(self.slots) end
end end
function showItemEditor(job,item_selections) function showItemEditor(job,item_selections)