Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 226 227 [228] 229 230 ... 243

Author Topic: DFHack 50.13-r3  (Read 839794 times)

xzaxza

  • Bay Watcher
    • View Profile
Re: DFHack 50.07-r1
« Reply #3405 on: April 23, 2023, 05:31:39 am »

I was trying to get a manager workorder to use only rock nuts for paste-making to avoid running low on hemp seeds, so I tried to copy "job_item" of a workshop job I'd adjusted with `job item-material`, and add it to the the workorder's "items" element (which happens to be nil for that specific order). Dunno if it'd even work, but I saw that for many work orders, items is a vector with "job_item" elements in it, so I thought it'd be worth a shot.

That was also before I learned of gui/workorder-details, since I've been using DFHack version 0.47.05-r5.

Code: [Select]
local help = [====[
======================

]====]

utils = require('utils')
--debug.setmetatable(nil, {__index = function()end})
function findworkorder(workorder_id)
-- does something like this exist? df.global.world.manager_orders.find(workorder_id)
for _, mgr_order in ipairs(df.global.world.manager_orders) do
if mgr_order.id == workorder_id then
return mgr_order
end
end
qerror('not found')
end
function processworkorder(workorder_id)
--df.global.world.manager_orders
local workorder
local job
local mode = 1 -- for quickly switching between different approaches to the problem
local workorder_jobitems = {}

if pcall(findworkorder, workorder_id) then
workorder = findworkorder(workorder_id)
else
qerror('Work order not found')
end
job = dfhack.gui.getSelectedJob(true) or qerror('No job selected')

print("test")
if mode == 1 then
table.remove(workorder,'items')
workorder['items'] = workorder_jobitems
workorder.items = utils.clone(job.job_items, true)
else
--workorder.items = {}
workorder['items'] = workorder_jobitems
for _, copy_job_item in ipairs(job.job_items) do
--workorder.items:insert('#', copy_job_item)
table.insert(workorder.items, copy_job_item)
end
end
end


-- main script
local opt = ...
if opt and opt ~= "" then
if tonumber(opt) then
if tonumber(opt) >= 0 then
processworkorder(math.floor(tonumber(opt)))
else
print("The number should be non-negative.")
end
return
else
print(help)
end
else
print("No work order provided, here's a list of existing work orders:")
for _, mgr_order in ipairs(df.global.world.manager_orders) do
if mgr_order.reaction_name ~= nil and mgr_order.reaction_name ~= "" then
print(mgr_order.id .. ": " .. df.job_type[mgr_order.job_type] .. " (" .. mgr_order.reaction_name .. ")")
else
print(mgr_order.id .. ": " .. df.job_type[mgr_order.job_type])
end
end
end
Logged
Known issues
You may get a dwarf that likes bugged stockpiles.

myk

  • Bay Watcher
    • View Profile
Re: DFHack 50.07-r1
« Reply #3406 on: April 23, 2023, 05:58:58 pm »

Are you essentially trying to get gui/workorder-details working for the Steam version? Or is this still for 0.47.05 and the existing gui/workorder-details meets your needs?
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: DFHack 50.07-r1
« Reply #3407 on: April 23, 2023, 09:19:01 pm »

Oh, so you're trying to create a vector<df::job_item*> in Lua. Unfortunately we don't have a way to create vectors containing arbitrary types from Lua. You might be able to come up with one by duplicating an existing work order that already has a non-null items vector. From a quick test, df.new(workorder) should make a shallow copy of the given work order (note that you will need to delete it to avoid leaking memory, e.g. with df.delete()).

Once you have a vector, you can call :insert() on it, with a table similar to what I was describing, e.g.
Code: [Select]
new_workorder.items:insert({
  new = true,
  field1 = value,
  -- ...
})

I also want to note that table.remove(workorder,'items') won't work. workorder (by my reading, anyway) is an instance of df.manager_order, and all instances of DF objects are actually userdata, not tables. Essentially, they are wrappers around native C++ classes. Their fields are fixed, and you can't add or remove fields. You can set them, and since items is a pointer to a vector, you can set it to nil (Lua's equivalent of null) with workorder.items = nil (although this will leak memory).
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

xzaxza

  • Bay Watcher
    • View Profile
Re: DFHack 50.07-r1
« Reply #3408 on: April 24, 2023, 12:43:44 am »

Are you essentially trying to get gui/workorder-details working for the Steam version? Or is this still for 0.47.05 and the existing gui/workorder-details meets your needs?
Nah, I'm in no hurry to try 0.50. I didn't get workorder-details to work with 0.47.05-r5, but it appears to work, and function as needed with r8. So, the problem I had with my Dwarf Fortress experience has been resolved (thanks!), it was more about me trying to learn why the approach I took with DFHack didn't work, and lethosor cleared that up. Thanks!
Logged
Known issues
You may get a dwarf that likes bugged stockpiles.

Salmeuk

  • Bay Watcher
    • View Profile
Re: DFHack 50.07-r1
« Reply #3409 on: April 24, 2023, 08:46:07 pm »

https://github.com/DFHack/dfhack/issues/3256

Quote
our in-game Dwarf Therapist-like interface needs an entirely new UI. Existing functionality (and maybe design elements) might be salvageable from the old plugin.

Integrate with or replace work details?

I, for one, used the old Manipulator religiously and thought it was a perfect medium between Therapist and Vanilla (or Autolabor). The new work details are not very convenient to work with, and I miss most dearly these two features from Manipulator:

1. ability to sort a list of units showing each enabled skill for that unit
2. ability to copy-paste skill loadouts from unit to unit

despite what people claim, a spreadsheet is the ultimate tool for bureaucratic labor management. the compact and efficient style of the previous manipulator will be hard to beat, but even something merely copying that layout would be a wondrous improvement.
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: DFHack 50.07-r1
« Reply #3410 on: April 24, 2023, 09:51:10 pm »

Left a reply on Github: https://github.com/DFHack/dfhack/issues/3256#issuecomment-1521087200
(Not to discourage you from discussing this here, but it does help people looking at Github to have all the discussion in one place. Github accounts are free to create.)

I think the word "need" may have been too strong. Our new-style UI tools have diverged significantly, but as far as I know, there's no technical requirement that manipulator's UI be replaced in order to work in v50. The plugin does need to compile to be usable, though. It's currently commented out in our build files, which likely means that it didn't compile at one point during early work on v50 DFHack. I don't expect any of the UI code to cause compilation issues now, but some of the other code might.
« Last Edit: April 24, 2023, 09:52:41 pm by lethosor »
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

0x517A5D

  • Bay Watcher
  • Hex Editor‬‬
    • View Profile
Re: DFHack 50.07-r1
« Reply #3411 on: April 26, 2023, 02:09:06 pm »

Is there a way to probe a userdata object to see it it contains a particular field?

I was trying to iterate all buildings to study their .contained_items, but had the problem that some buildings (e.g. zones) don't have that field.

I get why accessing somezone.contained_items throws an error, but I expected somezone:_field('contained_items') to return nil.  Instead it also throws an error.

I resorted to enumerating pairs(somebuilding) to see if there is a key == 'contained_items' in the object.  This feels clumsy.

Thoughts?

Here's my actual code, a oneliner at the [lua#] prompt.
Code: [Select]
for _,b in ipairs(df.global.world.buildings.all) do for key,_ in pairs(b) do if key == 'contained_items' then for j,v in ipairs(b.contained_items) do i=v.item; f=i.flags; if v.use_mode == 0 and f.in_building and not f.trader then print(b._type,j,dfhack.items.getDescription(i,0)); end; end; end; end; end;
Logged

myk

  • Bay Watcher
    • View Profile
Re: DFHack 50.07-r1
« Reply #3412 on: April 26, 2023, 02:15:49 pm »

If you're exploring a type, you're better off browsing using gui/gm-editor. FWIW, that script also uses pairs to iterate through a userdata object's fields: https://github.com/DFHack/scripts/blob/ad1998a0032ce50e90d05429a4178b668c0840ba/gui/gm-editor.lua#L567
Logged

0x517A5D

  • Bay Watcher
  • Hex Editor‬‬
    • View Profile
Re: DFHack 50.07-r1
« Reply #3413 on: April 26, 2023, 03:09:08 pm »

I do make heavy use of gui/gm-editor, very nice tool.

But one of my test forts has 4000 buildings with 32000 total contained_items.  Manually probing that is... not practical.

Anyway.



Documenting this because it took me far too long to figure it out:

Items in a Trade Depot are ready to be traded (i.e. they have been selected by Move goods to/from depot) if they have item.flags.in_building == true.

Here's a one-liner that sets as tradeable all fort-produced items that are sitting in the Trade Depot.  It assumes you only have one Trade Depot.  Run it at the [lua]# prompt.

Code: [Select]
b=df.global.world.buildings.other.TRADE_DEPOT[0]; for j,v in ipairs(b.contained_items) do i=v.item; if v.use_mode == 0 and not i.flags.foreign and not i.flags.trader then i.flags.in_building = true; end; end;

Note that this code probably also should test other flags like .in_job, .owned, .dump, .melt, etc.  Use at your own risk.
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: DFHack 50.07-r1
« Reply #3414 on: April 27, 2023, 11:12:46 pm »

_field() is similar to the C++ & operator - the field you're referencing must exist.

Another option is to use pcall() to catch and ignore errors. A couple scripts do that for "safe" indexing of DF objects.
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

myk

  • Bay Watcher
    • View Profile
Re: DFHack 50.07-r1
« Reply #3415 on: May 02, 2023, 05:04:53 pm »

Logged

Criperum

  • Bay Watcher
    • View Profile
Re: DFHack 50.08-r1
« Reply #3416 on: May 08, 2023, 05:57:28 am »

How can I make a DF shotcut that starts the game without DFHack?
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: DFHack 50.08-r1
« Reply #3417 on: May 08, 2023, 10:03:59 am »

How can I make a DF shotcut that starts the game without DFHack?
We don't support this currently for the Windows build of DF (i.e. the only one for v50). You could probably write a custom script that renames the necessary DLLs, although then you would need to write another script that renames them back if you want to run with DFHack. For 50.08-r1 and newer (again, on Windows) you would want to rename "dfhooks.dll" to something else to disable DFHack.
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

Criperum

  • Bay Watcher
    • View Profile
Re: DFHack 50.08-r1
« Reply #3418 on: May 08, 2023, 06:52:25 pm »

Thank you
Logged

A_Curious_Cat

  • Bay Watcher
    • View Profile
Re: DFHack 50.08-r1
« Reply #3419 on: May 13, 2023, 03:23:40 pm »

I’ve been thinking…

I’ve alway’s though that it’s be nice if the dwarves could move the embark wagon after they embark.  I know that this would require several new systems that are not in the game right now.

In the meantime, however, is there a DFHack command that will teleport the embark wagon (and it’s contents) to a chosen position on the map?  It’d make things a lot faster if my dwarves didn’t have to walk so long when transferring items from the wagon to the initial stockpile.
Logged
Really hoping somebody puts this in their signature.
Pages: 1 ... 226 227 [228] 229 230 ... 243