Bay 12 Games Forum

Please login or register.

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

Author Topic: Is there a DFHack script to merge stacks or the contents of barrels?  (Read 6579 times)

ldog

  • Bay Watcher
    • View Profile
Re: Is there a DFHack script to merge stacks or the contents of barrels?
« Reply #15 on: June 26, 2015, 05:29:59 pm »

PTW
I'm very interested in this, even if only for booze. I have been toying with the idea of making custom reactions for it, but it seems like too many places for it to go wrong.

Then you're in luck, sorta, because I made some scripts that merge both plants and drinks manually.  The links to them and a description of their use is here, in the DFHack thread.  They aren't the most convenient ever, I'm afraid, but I don't have a ton of time right now to improve them.

I did, just now, upload the current version I've been using, which adds support for flour to combine_plants, and lets you specify a container or stockpile ID with -stockpile (for _plants and _drinks) and -container (for _plants).  That way, you can use the repeat script to run my combine scripts at a regular interval, if you want.  Anything more complex than that will have to wait until I have some free time.

If you notice any bugs, give me a shout and I'll fix them as I'm able.

Awesome! Thanks very much. Both scripts seem to work like a champ so far.
I've been trying to micromanage my drink & plant stocks by forbidding and unforbidding around jobs, and trading all small stacks away but it's been really getting old. Plants I use a QSP for, but the tons of barrels of like 5 drink in them were killing me.
Logged
Quote from: Dirst
For example, if you wanted to check if a unit was eligible to be a politician or a car salesman, you'd first want to verify that there is no soul present...

Quote from: gchristopher
The more appropriate question becomes, are they awesome and dwarven enough.

kane_t

  • Bay Watcher
    • View Profile
Re: Is there a DFHack script to merge stacks or the contents of barrels?
« Reply #16 on: June 26, 2015, 05:53:04 pm »

No problem.  I'll post here if and when I update the script in the future.  The main thing I'll be doing is improving the performance and maybe adding support for other types of item (like cheese and ammunition, maybe). 
Logged

ldog

  • Bay Watcher
    • View Profile
Re: Is there a DFHack script to merge stacks or the contents of barrels?
« Reply #17 on: July 03, 2015, 09:39:44 pm »

Scripts still working well. I use them constantly.
One thought, might be better to reduce plant stacks to 6.

What happens is when you bag 12 quarry bushes you get a stack of 60 leaves, this turns into a lavish roast so large it can't fit in a barrel.
I'm on the fence if this is a good thing or not since it makes it easy to select and trade, but then it's a huge value item, like hippies and humans don't usually even have enough stuff I want to trade them 1 even.
I was about to go do this, but then I wasn't sure what happens when you get a larger stack to begin with (like say from L20 planter + potash) if it is going to break something or not.

Booze of course only will brew half a 12 stack, although if you queue the job 2x  they will use the second 6 instead of hauling. Thread, sugar, flour and dye of course the large stacks are nice, saves bags.
Logged
Quote from: Dirst
For example, if you wanted to check if a unit was eligible to be a politician or a car salesman, you'd first want to verify that there is no soul present...

Quote from: gchristopher
The more appropriate question becomes, are they awesome and dwarven enough.

kane_t

  • Bay Watcher
    • View Profile
Re: Is there a DFHack script to merge stacks or the contents of barrels?
« Reply #18 on: July 04, 2015, 09:06:39 am »


What happens is when you bag 12 quarry bushes you get a stack of 60 leaves, this turns into a lavish roast so large it can't fit in a barrel.

Oh yeah, I hadn't thought about that specific problem.  There are probably other plant types that process into stacks based on their input stack size which might cause problems.

The reason I picked 12 is as you suspected: brewing is done in multiples of six, so picking a multiple of six for the combined stack size allows two maximum-size brewing jobs to happen in a single hauling action (for the plant, at least).  With fertiliser and a high farming skill it's possible to get stacks of 9 or 10, so 12 isn't a significant difference.  (And, no, the script doesn't break if you have unusually large stack sizes in the container.  Though, it may choose to take items from those large stacks to merge into smaller ones.) 

Maybe this should be reported as a bug, actually—brewers obviously split stacks to ensure that drink doesn't exceed barrel capacity (although, they don't take into account the larger capacity of a pot), so maybe cooks should do the same thing.

When you say the lavish roast can't fit in a barrel, are you sure it isn't getting stored?  I know I've cooked roasts larger than a barrel's maximum capacity (usually because my cook selected a full barrel of 30 drinks for one of the inputs) and they've gone into a single barrel just fine.  I'm pretty sure the maximum capacity is just a limit for adding more items.  So you'll end up with a barrel just containing your one giant roast.

I might have to change the script to better handle barrel capacity regardless, because I realised yesterday that it's not doing that properly.  Because of the way it processes items, it has a high chance of filling barrels past their capacity.  As near as I can tell, this doesn't cause any problems, but it does violate the simulation's mechanics in a way I don't like.  I've got a couple ideas of how to handle that, but not much time to implement them.  If anyone can confirm that over-capacity containers are causing problems, I'll try to squeeze in the time to fix it as soon as I can, otherwise I might have to put it off for a week or two.

In the meantime, you can use the -max parameter to manually set the desired stack size.  That's the main reason I separated the drinks and plants versions of the script, so you could individually change the stack size for them.  Later, I might add the option to specify maximums for specific plant types, so you can ensure that quarry bushes only get combined into stacks of 6, but leave strawberry plants in stacks of 12.
« Last Edit: July 04, 2015, 09:09:00 am by kane_t »
Logged

ldog

  • Bay Watcher
    • View Profile
Re: Is there a DFHack script to merge stacks or the contents of barrels?
« Reply #19 on: July 04, 2015, 09:46:11 am »

Yeah, I'm looking at a roast that started as 72 I think, they've eaten it down to 66.
Another of 85. Both in meals storage pile, that has other barrels of roasts, and I've got plenty of empty barrels.
I'm thinking it is when a single item is too large for the barrel that it doesn't go in. The other barrels in there seem to fill up to around 40-50 urists, which is about what these weigh. I'll try to keep an eye on the shrinking one to see what the threshold is for it getting barreled.

Logged
Quote from: Dirst
For example, if you wanted to check if a unit was eligible to be a politician or a car salesman, you'd first want to verify that there is no soul present...

Quote from: gchristopher
The more appropriate question becomes, are they awesome and dwarven enough.

kane_t

  • Bay Watcher
    • View Profile
Re: Is there a DFHack script to merge stacks or the contents of barrels?
« Reply #20 on: July 05, 2015, 01:36:44 pm »

Alright, that's good to know.  Immediately, there's a quick fix you can do to your copy of the script.  After line 67, which reads:
Code: [Select]
local itemsNeeded = max - currentPlant.stack_sizeAdd the following line:
Code: [Select]
if currentPlant:getType() == 53 and currentPlant.mat_type == 419 and currentPlant.mat_index == 176 then itemsNeeded = 6 - currentPlant.stack_size endWhich will use 6 as the desired stack size for quarry bushes.  Exempting quarry bushes from merging altogether would be easy in a minimally-adequate programming language with a continue statement, but in Lua it would require adding two lines of code in different parts of the file, so if you want that I'll just upload a modified version of the script to github.

Like I said, I don't have time to do much work on it right now, but I figure I'm going to have to rewrite it to allow customising the items included in merging and setting separate stack sizes for them.  It'll be substantially easier to write code that complex in C++, so I'll rewrite it as a plugin, and I actually thought of a more-or-less adequate way of automating it, so I might make an automerge plugin as well.  I figure some people would want it done automatically, and some would only want to do merging in very specific cases.  It's just a question of whether I find the time to do it this month or the next.

This situation does seem like a bug, though, even without my script mucking things up.  Just doing the math in my head, it's possible to get a stack of 9 bushes from a fertilised plot, which process into a stack of 45 leaves.  If your farmer selected four such stacks as the inputs for a lavish roast, you'd end up with a stack of 180 quarry bush leaf roasts.  Slightly more than fits in a barrel.  Cooks should either split input stacks like brewers do, to ensure they never have inputs totalling more than 60, or they should split their output into smaller stacks if necessary.  (Cooks should also intelligently choose different ingredients for each input, rather than selecting four stacks of quarry bush leafs, but that's another gripe altogether.)
Logged

ldog

  • Bay Watcher
    • View Profile
Re: Is there a DFHack script to merge stacks or the contents of barrels?
« Reply #21 on: July 05, 2015, 01:42:59 pm »

Cool. I'll give it a shot.
60 roasts seems to be the magic number, at which point they put it in a barrel.
I haven't bothered with pots in this fortress. Mountain embark, no vermin, so it really hasn't bothered me with the roast sitting on the floor.
Like you said, even without mods or scripts it's still quite possible to go oversize.

Didn't seem to work. I've done some other modding to my game though, although I think the itemcodes are hardcoded anyway.
Haven't noticed anything else amiss with barrels, but then I'm a recent QSP convert.
« Last Edit: July 05, 2015, 06:58:22 pm by ldog »
Logged
Quote from: Dirst
For example, if you wanted to check if a unit was eligible to be a politician or a car salesman, you'd first want to verify that there is no soul present...

Quote from: gchristopher
The more appropriate question becomes, are they awesome and dwarven enough.

DG123

  • Bay Watcher
    • View Profile
Re: Is there a DFHack script to merge stacks or the contents of barrels?
« Reply #22 on: March 18, 2016, 04:44:02 pm »

PTW
I'm very interested in this, even if only for booze. I have been toying with the idea of making custom reactions for it, but it seems like too many places for it to go wrong.

Then you're in luck, sorta, because I made some scripts that merge both plants and drinks manually.  The links to them and a description of their use is here, in the DFHack thread.  They aren't the most convenient ever, I'm afraid, but I don't have a ton of time right now to improve them.

I did, just now, upload the current version I've been using, which adds support for flour to combine_plants, and lets you specify a container or stockpile ID with -stockpile (for _plants and _drinks) and -container (for _plants).  That way, you can use the repeat script to run my combine scripts at a regular interval, if you want.  Anything more complex than that will have to wait until I have some free time.

If you notice any bugs, give me a shout and I'll fix them as I'm able.

Can anyone explain to me how to actually use the combine drinks script?

I just get error messages when I type in the command.
Logged

kane_t

  • Bay Watcher
    • View Profile
Re: Is there a DFHack script to merge stacks or the contents of barrels?
« Reply #23 on: March 18, 2016, 04:57:12 pm »

You need to have a stockpile selected when you call the command.  Select it with the buildings selection command (q) then call combine_drinks, and it'll combine the drinks in the selected stockpile.  Does it still not work when you have a stockpile selected?  If so, let me know what the error is.

(You can also, optionally, specify a stockpile by ID with an argument, for use with the repeat command.  The parameter for that is "stockpile", as in "combine_drinks -stockpile <stockpile building ID>".  This way, you don't need to have a stockpile selected.)
Logged

DG123

  • Bay Watcher
    • View Profile
Re: Is there a DFHack script to merge stacks or the contents of barrels?
« Reply #24 on: March 19, 2016, 08:44:32 am »

It's still giving an error. This:

D:\DFMasterwork\Dwarf Fortress\hack\lua\dfhack.lua:354:...asterwork\Dwarf Fortress\hack\scripts/combine_drinks.lua:5: unexpected symbol near '<'
stack traceback: [C}: in function 'error'
D:\DFMasterwork\Dwarf Fortress\hack\lua\dfhack.lua:354: in function <D:\DFMasterwork\Dwarf Fortress\hack\lua\dfhack.lua:344>
Logged

kane_t

  • Bay Watcher
    • View Profile
Re: Is there a DFHack script to merge stacks or the contents of barrels?
« Reply #25 on: March 19, 2016, 08:51:01 am »

Okay, that's weird.  There isn't even a < symbol in the script.  The only thing I can imagine is that the script somehow got modified and a bug was introduced?  As far as I know, all Perdexis did for the LNP was add the documentation comment at the top (and it's more than five lines, so the error would be inside the comment, which doesn't make sense).

If you attach the file, I'll take a look and see if I can figure out where the bug is.  If it hasn't been modified, the only other possibility I can imagine is that it doesn't play well with mods (since it hard-codes item types), but even that seems unlikely, since those item types should be hardcoded in the game itself.
Logged

DG123

  • Bay Watcher
    • View Profile
Re: Is there a DFHack script to merge stacks or the contents of barrels?
« Reply #26 on: March 19, 2016, 11:31:03 am »

Maybe I messed something up when trying to download it? What's the correct way to get the script downloaded and installed?
Logged

kane_t

  • Bay Watcher
    • View Profile
Re: Is there a DFHack script to merge stacks or the contents of barrels?
« Reply #27 on: March 22, 2016, 09:49:03 pm »

Apologies for the delay.  You should just need to save the file as combine-drinks.lua in your hack/scripts directory.  (You can copy/paste the entire text into a new file if you don't want to download it using Github.)  It also comes bundled with the newest version of the LNP, but it looks like you're using some mod that has its own special launcher and stuff.
Logged

DG123

  • Bay Watcher
    • View Profile
Re: Is there a DFHack script to merge stacks or the contents of barrels?
« Reply #28 on: March 27, 2016, 08:23:17 am »

Hmm. I think I might have screwed up the actual download. It's not that obvious on github how you actually download the script. I've done it by right clicking on Raw this time. I don't recall what I did before.

Hopefully this will work.

Is there a way to do this with meat and fish etc by any chance? It seems like all my barrels are being taken up with food leaving none for drinks.
Logged

kane_t

  • Bay Watcher
    • View Profile
Re: Is there a DFHack script to merge stacks or the contents of barrels?
« Reply #29 on: March 27, 2016, 09:17:06 am »

If the problem is barrel capacity, I'm afraid not, you'll just have to build more barrels.  For everything but liquids, barrel capacity isn't based on number of stacks, it's the total amount of items.  One stack of ten takes up as much space as ten stacks of one, so it doesn't matter how your fish and meat are stacked, they're already using your barrels as efficiently as is possible.  You'll just have to keep pumping out barrels at a regular pace to make sure you've always got empty spares for brewing.

The reason why I made the combine-drinks script is because, for drinks, barrels can only contain a single stack, and dwarves won't combine partially-empty barrels with the same kind of liquid in them, so you can end up with two barrels containing strawberry wine [2], wasting 28 units of space apiece, when really dwarves should just be merging them into an empty barrel and one containing strawberry wine [4].  And combine-plants has a similar motivation: each plant brews into 5 units of drink, but brewers won't intelligently go through the stockpile and grab 6 plants of the same type to fill a full barrel, they'll just grab that single strawberry next to the strawberries [4] and make a pointless barrel of strawberry wine [5], so merging plants improves brewing efficiency by ensuring that brewers (usually) make the maximum amount they can in a single action.  (And there are similar problems with cooking that make it preferable to combine cookables into similar stack sizes.)

All of this would be solved if Toady made workers form ideally-sized stacks in their hands when grabbing items for a job and added a minor "maintain stockpile" job to sort and store loose items and merge barrel contents, which is something that I'd like to see happen, but probably won't for quite a while.

When I come back to Dwarf Fortress, I'll probably make a better version of these scripts, and I might add support for meat and fish in just to help with cooking, but I don't know when that'll be.  Sorry!
Logged
Pages: 1 [2]