Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 [3]

Author Topic: Ways to drag enemies?  (Read 8359 times)

Max™

  • Bay Watcher
  • [CULL:SQUARE]
    • View Profile
Re: Ways to drag enemies?
« Reply #30 on: August 31, 2017, 10:14:40 am »

Add this to advfort in some of the functions around line #400 or so:
oh yeah I remember having a carry, drag, mount and Stuff folks into a item function for dfhack for several years now due to help by warmist.
kinda made looking at this thread in puzzle confusion though.
loads of fun for making a chain of dragging units each being pulled by another person.
the drag code that I had for years back, probably need an update since relationships section in dfhack got rewritten.
Spoiler (click to show/hide)
though nice to see max making addons to advfort.
I was looking at the ride launch/ollie stuff and it clicked why the old cage creature/etc bits weren't working.

These are the bits I was tinkering with:
Code: (advfort function chunks) [Select]
function SetCagedRef(args)
   local caged
   local pos=args.pos
   for k,v in pairs(df.global.world.units.active) do
if v.pos.x==pos.x and v.pos.y==pos.y and v.pos.z==pos.z then
     caged = v
end
   end
   local adv=df.global.world.units.active[0]
   local items=EnumItems{pos=adv.pos,unit=adv,
        inv={[df.unit_inventory_item.T_mode.Hauled]=true,--[df.unit_inventory_item.T_mode.Worn]=true,
             [df.unit_inventory_item.T_mode.Weapon]=true,},deep=true}
   local choices={}
   for k,v in pairs(items) do
        table.insert(choices,{text=dfhack.items.getDescription(v,0),item=v})
    end
    dialog.showListPrompt("Item choice", "Choose item to put into:", COLOR_WHITE,choices,
function (idx,choice)
  caged.flags1.on_ground = true
  caged.flags1.move_state = false
  choice.item.general_refs:insert('#',{new=df.general_ref_contains_unitst,unit_id=caged.id})
          caged.general_refs:insert("#",{new=df.general_ref_contained_in_itemst,item_id=choice.item.id})
  choice.item.flags.container = true
  choice.item.flags.weight_computed = false
  caged.flags1.caged = true
          return
        end)
          dfhack.maps.ensureTileBlock(caged.pos).occupancy[caged.pos.x%16][caged.pos.y%16].unit = false
  caged.flags1.on_ground = false
end

function SetCarryRef(args)
    local mnt
    local rid
    local pos=args.pos
    for k,v in pairs(df.global.world.units.active) do
        if v.pos.x==pos.x and v.pos.y==pos.y and v.pos.z==pos.z then
mnt = df.global.world.units.active[0]
rid = v
  mnt.general_refs:insert("#",{new=df.general_ref_unit_riderst,unit_id=rid.id})
                  dfhack.maps.ensureTileBlock(rid.pos).occupancy[rid.pos.x%16][rid.pos.y%16].unit = false
  rid.relationship_ids.RiderMount=mnt.id
  rid.pos.x=mnt.pos.x
  rid.pos.y=mnt.pos.y
  rid.pos.z=mnt.pos.z
  rid.flags1.rider=true
  mnt.flags1.ridden=true
  require("utils").insert_sorted(df.global.world.units.other.ANY_RIDER,rid,"id")
            return
        end
    end
end
function SetPatientRef(args)
    local job=args.job
    local pos=args.pos
    local doc=df.global.world.units.active[0]
--    doc.general_refs:insert("#",{new=df.general_ref_unit_workerst,unit_id=doc.id})
    for k,v in pairs(df.global.world.units.active) do
        if v.pos.x==pos.x and v.pos.y==pos.y and v.pos.z==pos.z then
            doc.general_refs:insert("#",{new=df.general_ref_unit_patientst,unit_id=v.id})
            return
        end
    end
end
function SetGeldingRef(args)
    local job=args.job
    local pos=args.pos
    local doc=df.global.world.units.active[0]
--    doc.general_refs:insert("#",{new=df.general_ref_unit_workerst,unit_id=doc.id})
    for k,v in pairs(df.global.world.units.active) do
        if v.pos.x==pos.x and v.pos.y==pos.y and v.pos.z==pos.z then
            doc.general_refs:insert("#",{new=df.general_ref_unit_geldeest,unit_id=v.id})
    v.flags3.gelded=true
            return
        end
    end
end
function SetFightRef(args)
    local jerk
    local mark
    local job=args.job
    if jerk==nil then
        local pos1=args.pos
        for k,v in pairs(df.global.world.units.active) do
            if v.pos.x==pos1.x and v.pos.y==pos1.y and v.pos.z==pos1.z then
                jerk=v
                jerk.job.current_job=job
--                jerk.general_refs:insert("#",{new=df.general_ref_unit_workerst,unit_id=jerk.id})
                dfhack.gui.showAnnouncement("Selected Jerk",COLOR_YELLOW,true)
                return jerk
            end
        end
    elseif mark==nil then
        local pos2=args.pos
        for k,v in pairs(df.global.world.units.active) do
            if v.pos.x==pos2.x and v.pos.y==pos2.y and v.pos.z==pos2.z then
                mark=v
                jerk.job.hunt_target=mark
                dfhack.gui.showAnnouncement("Selected Mark",COLOR_YELLOW,true)
                return mark
            end
        end
    end
end
I almost had the patient stuff working I thought but I got lost because I started wondering if I could do the fight starting stuff similarly, I made the SetCageRef function into a "cram targeted unit into [choose an item]" option.

These are what I was trying to do for the actual interface option bits:
Code: [Select]
    {"Recover"              ,df.job_type.RecoverWounded,{SetCarryRef,SetPatientRef}},
    {"Diagnose"            ,df.job_type.DiagnosePatient,{SetPatientRef}},
    {"Clean Patient"            ,df.job_type.CleanPatient,{SetPatientRef}},
    {"Dress Wound"            ,df.job_type.DressWound,{SetPatientRef}},
    {"Set Bone"            ,df.job_type.SetBone,{SetPatientRef}},
    {"Surgery"            ,df.job_type.Surgery,{SetPatientRef}},
    {"Suture"            ,df.job_type.Suture,{SetPatientRef}},
    {"Geld"     ,df.job_type.GeldAnimal,{SetPatientRef}},
    {"Carry"           ,SetCarryRef,{}},
    {"Instigate"        ,df.job_type.StartingFistFight,{SetFightRef}},
    {"Confine"   ,SetCagedRef,{}},
Logged
Pages: 1 2 [3]