Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: trade-prefs script  (Read 1456 times)

disacorns

  • Bay Watcher
    • View Profile
trade-prefs script
« on: January 12, 2020, 05:26:43 am »

https://bitbucket.org/disacorns/df-trade-prefs/src/master/

trade-prefs

so, i created my first script for dfhack! lets call it the alpha version.

what it does:
shows you a list of items that your dwarves prefer, sorted as the trade agreements sort. it also shows where the trade negotiator will list the items, and how many you currently have in stocks.
e.g.

Spoiler (click to show/hide)

the output columns go like:
<name> <page number>, <row number> <stocks>
page number is how many pages down in 'Meat' or whatever the item will be shown, <row number> is how many items down on that page. Stocks is how many of that item you currently have.
'Not Found' means the script believes the civilazition doesn't offer that item.
'Not Matched' means the civilization offers another form of that item, but seems not to offer that particular item. e.g. dwarves don't offer strawberry wine in drinks, but they could offer strawberries. This also happens with gypsum plaster, your citizen may want it a stone, but the dwarves offer it as a powder.
----
To further explain what this script is for I thought I should describe why I made it:
I like to buy my citizens stuff they want. Gold, quartzite, whatever, but stuff my fortress doesn't produce. Just using DwarfTherapist's preferences dock was tedious, so  i started using a spreadsheet to keep track of what they want, and if the traders actually offer it. Updating that was also tedious and full of human error, (going through the list of meat to find a specific animal, and then missing it, or not realizing 'Larch' is a kind of tree.) So I made this script.
---
While this script works (for my purposes at least), anyone looking at the code will realize quickly I have no idea what Im doing. If anyone who does have some idea what they're doing could look at it and give me some advice, or even clean it up, i would be supremely grateful.
My biggest problem at the moment, is looking up :LikeItem preferences.
e.g. picks. I know picks have a sub_type 7, but so do other things in the itemdefs, and I cant figure out what dance_form: 24 is telling me about a pick?!?
Having written one script, im working on another, and really need to know this.
Thanks in advance for any help.

I hope someone else finds this useful.
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: trade-prefs script
« Reply #1 on: January 12, 2020, 06:24:59 am »

I think you'd want two scripts: one for the trade liaison to order things for the next caravan, and another to select things that the caravan currently at the trade depot actually offers.
I've got a version of the latter, although it selects for food preferences only, and it doesn't check current stock (so I have to manually deselect some things that are brought in abundance).
I've had very little experience looking at Ruby scripts (using Lua for DF myself), so I won't comment on your script (Though DF is indeed lying when it displays a food preference for e.g. Mole, when the actual preference is Mole Liver, as testing has showed only the specific item has any effect on food satisfaction).

Obviously, the conclusion that there's a connection to a dance form from a pick isn't correct, although I can't tell you what the correct conclusion is. It may be that the subtype field references something the DFHack community hasn't figured out yet, but it's probably not important for preferences anyway: the bugger likes picks, and so any pick would do, although a steel one would be better liked if the dorf likes steel as well.
Note that item and material preferences tend to be used mainly for noble mandates and craftdorf production quality purposes, although it does affect trinket and clothing acquisition to some extent, and there are rare cases where dorfs nick other items of liked types or materials. Furniture in their rooms presumably help, but quality and value probably trump preferences.

My script:
Spoiler (click to show/hide)
Logged

disacorns

  • Bay Watcher
    • View Profile
Re: trade-prefs script
« Reply #2 on: January 12, 2020, 06:57:29 am »

thaks for the help!
my script doesn't actually deal with trading with the caravans at the depot. yours looks helpful.
thanks for the tip about the specific meat. "mole liver" that question was bothering me.
would you know what the deal is with "kangaroo milk"? my dorf likes kangaroo milk, the traders allow me to request kangaroo milk, but dfhack shows the kangaroo milk i'm asking for is actually "kangarooman kangaroo milk" (super gross). would it still satisfy food satisfaction requirements?
my "pick" problem is how do I know the guy likes picks? (I know because dwarftherapist tells me so) i can figure out which pref of his must be the pick by process of elimination, but i cant do it programmatically. i think your telling me it doesn't matter, and it really doesn't for this script, but as i mentioned i'm working on something else that needs to know what items they prefer, (and not just picks).
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: trade-prefs script
« Reply #3 on: January 12, 2020, 07:52:08 am »

There's another bug in the food preferences in that Giant and anthropogenic versions of animals are falsely displayed as the regular animal version, although I think the "only" preferences you can have for animal sapients is milk and cheese (but I don't think it's been investigated in depth). A further bug allows for preferences for things that cannot be acquired, like vermin parts (e.g. moghopper eyes), or parts that are too small to be gained from the animal (cavy eyes, for instance). Only exactly the thing matching preferences will do.

I don't remember off the top of my head exactly how to decode preferences, but this script does it https://github.com/PatrikLundell/scripts/blob/own_scripts/thoughts.lua, and it ought to be possible to find the relevant part there. Note that it's a web page with the script on it, not the script itself. It's basically a research tool where I've added things bit by bit, and some of it required investigation (which resulted in updates to the corresponding DF structures). It started out trying to replicate the thought screen for dorfs, but expanded to show the info that's actually there (such as the specific food part preferences, or which piece of music a thought involved), plus a bit about relations (from the relations screen), although that part has bugs I haven't bothered to deal with. The "research" is on hold since a fair while, though.
Logged

disacorns

  • Bay Watcher
    • View Profile
Re: trade-prefs script
« Reply #4 on: January 12, 2020, 02:23:45 pm »

thanks Patrik, it looks like that may be helpful with converting to readable names.
im starting to think I should have used lua, but I really like ruby.

also considering doing something like you did with the caravan, if the trade agreement page is open, the script should automatically change the priorities. i had considered changing the agreement even after the meeting, but decided against it.
Logged

Fleeting Frames

  • Bay Watcher
  • Spooky cart at distance
    • View Profile
Re: trade-prefs script
« Reply #5 on: January 13, 2020, 09:28:35 pm »

Huh, seems similar to script I did five days ago, based on what Patrik mentioned: https://dwarffortresswiki.org/index.php/User:Fleeting_Frames/order_takeout

Though, that one doesn't check things already in fortress and only works for items, both worthy improvements - but it does provide example of changing the priorities while trade screen is open.

A possible future improvement might be a gui to set what categories to import (ex are you really going to cook that flour or get them to haul Mountain Goat Horn amulet?)

Feather tree eggs are growths on feather trees - elves bring their yolks into your depot sometimes, but you can't use those for cooking.

Kenaf seed oil should probably be "Not Matched" i.e. able to import  seeds but not the oil itself.

Like Patrik, I don't know much of ruby, including anything stopping you from using it for this purpose.

disacorns

  • Bay Watcher
    • View Profile
Re: trade-prefs script
« Reply #6 on: January 14, 2020, 12:22:07 am »

wow, thanks fleeting frames.
i would have been surprised if no one else had thought of this.
a quick glance shows me a lot that will be helpful. e.g. the difference between plants and garden vegetables. that was bothering me.

your way seems a lot shorter. just using the trade screen saves a lot of trouble, e.g. trying output a readable name, as well as user effort.
but yeah, automatically ordering everything could have drawbacks.

checking stocks is probably the shortest part of my script, but the slowest.

p.s. kenaf seed oil would show as not matched if the traders offered kenaf seeds. its alone at the bottom there because i dont know what category to put it in. another problem that just doesnt exist with your script.
Logged

disacorns

  • Bay Watcher
    • View Profile
Re: trade-prefs script
« Reply #7 on: January 14, 2020, 12:29:19 am »

just noticed something is broken with fish, i know i had it working earlier. will get to it.
Logged