Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: new DFHack script - preferences.lua  (Read 3823 times)

Ygvir

  • Bay Watcher
    • View Profile
new DFHack script - preferences.lua
« on: December 22, 2016, 12:32:06 am »

So, I initially started to edit the prefchange.lua script to add a bit more flexibility to do what I was trying to accomplish but it turned into a complete rewrite/rework with a backwards compatibility mode to prefchange.lua and pref-adjust.lua style preference changes. Please take a look at the embedded script (it is quite long so I'll try to put it in a spoiler/code section).

I'd especially like feedback from Max™, vjek and Putnam because their work was my starting point. I'd also love to hear from lethosor, Warmist, ab9rf, PeridexistErrant and Quietust. I'm certain I've missed some of the other DFHack wizards so my apologies; I'd be happy to hear from you as well.

If you have the time to look please note that I make a fairly extensive look-up table. If this functionality is better done a different way or already existing in DFHack please let me know. If not, I'd like to humbly request that we have one. It could be modeled after what I've done here or improved.

Spoiler (click to show/hide)

I know it would be better to set this up as a pull request through github but I'm just not set up for that yet, sorry.
Logged

Fleeting Frames

  • Bay Watcher
  • Spooky cart at distance
    • View Profile
Re: new DFHack script - preferences.lua
« Reply #1 on: December 22, 2016, 04:03:19 am »

Awesome, literally yesterday I was looking for a better way to get preferences from petitioning visitors/residents than gui/gm-editor checking each unit's preferences in their soul.

(Previous pref-change show outputting ids and only all units at once was even less ideal.)

I also like the more verbose explanation on what the script does.



Checking the unit's preferences reveals that the unsupported preferences are the color brass, the words of The Good Decency and the sound of The Meadow of Glimmering.

Using it on non-resident visitor dwarves gives 0 preferences, which matches what I get when I make these people mine.

Using it on petitioning yet-not-resident visitor, I get 0 preferences before approving, matching the gm/editor - and, when I savescum just before approving, I get quite different preferences, both in-game and with script.

Max™

  • Bay Watcher
  • [CULL:SQUARE]
    • View Profile
Re: new DFHack script - preferences.lua
« Reply #2 on: December 22, 2016, 06:56:22 am »

Clever additions there, rock on man.
Logged

jaked122

  • Bay Watcher
  • [PREFSTRING:Lurker tendancies]
    • View Profile
Re: new DFHack script - preferences.lua
« Reply #3 on: January 10, 2017, 10:07:13 pm »

I know it would be better to set this up as a pull request through github but I'm just not set up for that yet, sorry.


You ought to make an account, just put it up as a gist, you won't need to go through the whole repo setup process (which is a pain for things like this).

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: new DFHack script - preferences.lua
« Reply #4 on: January 11, 2017, 02:09:00 am »

Only suggestion i have is to use multiline string at the end instead of lot of prints. E.g.
Code: [Select]
print([==[ stuff
more stuff
etc...
]==])

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: new DFHack script - preferences.lua
« Reply #5 on: January 12, 2017, 07:37:20 am »

All of the unit preference types are known, at least in the structures XML, but it'll probably be difficult to access within Lua due to the way the type enum is declared.

Code: [Select]
    <struct-type type-name='unit_preference'>
        <enum base-type='int16_t' name="type">
            <enum-item name='LikeMaterial'/>
            <enum-item name='LikeCreature'/>
            <enum-item name='LikeFood'/>
            <enum-item name='HateCreature'/>
            <enum-item name='LikeItem'/>
            <enum-item name='LikePlant'/>
            <enum-item name='LikeTree' comment='holdover from 40d and earlier'/>
            <enum-item name='LikeColor'/>
            <enum-item name='LikeShape'/>
            <enum-item name='LikePoeticForm'/>
            <enum-item name='LikeMusicalForm'/>
            <enum-item name='LikeDanceForm'/>
        </enum>
...
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: new DFHack script - preferences.lua
« Reply #6 on: January 12, 2017, 09:44:45 am »

Code: [Select]
df.unit_preference.T_type

Max™

  • Bay Watcher
  • [CULL:SQUARE]
    • View Profile
Re: new DFHack script - preferences.lua
« Reply #7 on: January 12, 2017, 04:24:15 pm »

Hmmm, wizard battle, or... TRIAL BY STONE?
Logged

Ygvir

  • Bay Watcher
    • View Profile
Re: new DFHack script - preferences.lua
« Reply #8 on: January 17, 2017, 02:55:27 pm »

@Quietust and @Warmist that is really useful. You are correct that it likely won't work for me as is but I think I could just iterate over that structure to build the LOOKUP and avoid doing all of the other nonsense I was using in order to build it. That is exactly what I was hoping for.

@jaked122 I'll try to get it into something that can be used easily for the dfhack maintainers... I'm a super git newby, I'd never even heard of a gist but I'll get something done.

Thanks for all of the help!

edit: typo
« Last Edit: January 17, 2017, 03:24:07 pm by Ygvir »
Logged