Skip to content

Instantly share code, notes, and snippets.

@warmist
Created November 26, 2012 20:50
Show Gist options
  • Save warmist/4150528 to your computer and use it in GitHub Desktop.
Save warmist/4150528 to your computer and use it in GitHub Desktop.
job creation
function getLastJobLink()
local st=df.global.world.job_list
while st.next~=nil do
st=st.next
end
return st
end
function AddNewJob(job)
local nn=getLastJobLink()
local nl=df.job_list_link:new()
nl.prev=nn
nn.next=nl
nl.item=job
job.list_link=nl
end
function MakeDig(unit,pos,job_type)
local nj=df.job:new()
nj.id=df.global.job_next_id
df.global.job_next_id=df.global.job_next_id+1
--nj.flags.special=true
nj.job_type=job_type
nj.completion_timer=-1
--nj.unk4a=12
--nj.unk4b=0
nj.pos:assign(pos)
AssignUnitToJob(nj,unit)
AddNewJob(nj)
end
function AssignUnitToJob(job,unit)
job.general_refs:insert("#",{new=df.general_ref_unit_workerst,unit_id=unit.id})
unit.job.current_job=job
unit.path.dest:assign({x=job.pos.x-1,y=job.pos.y,z=job.pos.z})
end
C=df.global.cursor
adv=df.global.world.units.active[0]
if C.z==-30000 then
C={x=adv.pos.x,y=adv.pos.y,z=adv.pos.z}
end
MakeDig(adv,{x=C.x,y=C.y,z=C.z},df.job_type.FellTree)
function AssignJobToBuild(pos,unit)
for k,v in pairs(df.global.world.buildings.all) do
if v.centerx==pos.x and v.centery==pos.y and v.z==pos.z then
AssignUnitToJob(v.jobs[0],unit)
end
end
end
--print(dfhack.constructions.designateNew({x=C.x,y=C.y,z=C.z},df.construction_type.Wall,df.item_type.WOOD,86))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment