Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 144 145 [146] 147 148 ... 244

Author Topic: DFHack 50.14-r1.1  (Read 894541 times)

Erendir

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r3 | 0.47.03-beta1
« Reply #2175 on: March 06, 2020, 01:24:03 pm »

I recently (with 0.47 release) got interest in writing dfhack scripts (in Lua), an was facing same problems you do now.

The built-in `lua` REPL is actually a great help. F.e.

Code: [Select]
[DFHack]# lua
Type quit to exit interactive lua interpreter.
Shortcuts:
 '= foo' => '_1,_2,... = foo'
 '! foo' => 'print(foo)'
 '~ foo' => 'printall(foo)'
 '^ foo' => 'printall_recurse(foo)'
 '@ foo' => 'printall_ipairs(foo)'
All of these save the first result as '_'.
[lua]# ^ df.global.world.items.all[0]
gives me lots of info, especially interesting
Code: [Select]
flags                   = <item_flags: 00000206A2E739C0>
    artifact                = true
    artifact_mood           = true
flags2                  = <item_flags2: 00000206A2E739C4>

The types exist in Lua scope under `df`; flag types can be enumerated like this.

Code: [Select]
[lua]# @ df.item_flags

this prints a list with 32 flags with their names.

This was enough for me for the beginning, and then I switched to a full-text search for keywords in dfhack sources.
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r3 | 0.47.03-beta1
« Reply #2176 on: March 06, 2020, 01:43:42 pm »

Thanks for your response.

So it seems there is no item flag that has the information whether the item is owned by the fort (as being indicated by the stockpile color red) and I must check other states that might block access.

Look at the item flags to try to figure out which ones you need.
That's part of the general question above. Where should I look up such an information?
That's the part of the "try to figure out" above. You've got the names that somebody assigned at some time, which typically was done without writing a description of how that was done, although in some cases you may have comments in the XML files. From there you'll guess at the detailed meaning, and perform experiments to see if you've got it correctly.

For instance, if all webs are red, then you can assume the spider_web flag is one criterion of several that can cause the items to be colored red. If only some are red, then look at one uncollected web (e.g. in the cavern) and one collected web (in an inventory or workshop) and try to see which flags differ.

I use gui/gm-editor to look at things in DF.
Logged

Roses

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r3 | 0.47.03-beta1
« Reply #2177 on: March 06, 2020, 02:12:26 pm »

Thanks for your response.

So it seems there is no item flag that has the information whether the item is owned by the fort (as being indicated by the stockpile color red) and I must check other states that might block access.

Look at the item flags to try to figure out which ones you need.
That's part of the general question above. Where should I look up such an information?
That's the part of the "try to figure out" above. You've got the names that somebody assigned at some time, which typically was done without writing a description of how that was done, although in some cases you may have comments in the XML files. From there you'll guess at the detailed meaning, and perform experiments to see if you've got it correctly.

For instance, if all webs are red, then you can assume the spider_web flag is one criterion of several that can cause the items to be colored red. If only some are red, then look at one uncollected web (e.g. in the cavern) and one collected web (in an inventory or workshop) and try to see which flags differ.

I use gui/gm-editor to look at things in DF.

Or to be more explicit, there isn't anywhere you can go to look up that information (very rarely there will be comments in the df-structures xml files, but that is the exception not the rule). It's basically just experimenting through look ups to figure the stuff out.
Logged

Alatun

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r3 | 0.47.03-beta1
« Reply #2178 on: March 06, 2020, 03:28:22 pm »

Thanks for your replies, Erendir, PatrikLundell, Roses. I've already done some small scripts by experimenting, reading scripts of others. Sometimes I had the feeling I was running against a wall, because after a whole evening of trial and error, I hardly got 20-30 lines of working code. So the question was: did I overlook something? This should be easier. But it seems, I need to develop more skill in researching the available code base.

I recently (with 0.47 release) got interest in writing dfhack scripts (in Lua), an was facing same problems you do now.

The built-in `lua` REPL is actually a great help. F.e.
...
This was enough for me for the beginning, and then I switched to a full-text search for keywords in dfhack sources.

The LUA REPL looks promising, I will surely give it a try. I already tried to use the dfhack sources, but I was not able to make much use of that information in LUA so far. One of my approaches was to find the namespace the LUA interpreter is using to resolve the symbols being used in the LUA code. Any pointers here? Is this idea a dead end?

I use gui/gm-editor to look at things in DF.

Already did that for stuff related to creatures. But it seems, it is not really usefull for general world items. Am I overlooking something here, too?
Logged

Roses

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r3 | 0.47.03-beta1
« Reply #2179 on: March 06, 2020, 03:42:20 pm »

Thanks for your replies, Erendir, PatrikLundell, Roses. I've already done some small scripts by experimenting, reading scripts of others. Sometimes I had the feeling I was running against a wall, because after a whole evening of trial and error, I hardly got 20-30 lines of working code. So the question was: did I overlook something? This should be easier. But it seems, I need to develop more skill in researching the available code base.

I recently (with 0.47 release) got interest in writing dfhack scripts (in Lua), an was facing same problems you do now.

The built-in `lua` REPL is actually a great help. F.e.
...
This was enough for me for the beginning, and then I switched to a full-text search for keywords in dfhack sources.

The LUA REPL looks promising, I will surely give it a try. I already tried to use the dfhack sources, but I was not able to make much use of that information in LUA so far. One of my approaches was to find the namespace the LUA interpreter is using to resolve the symbols being used in the LUA code. Any pointers here? Is this idea a dead end?

I use gui/gm-editor to look at things in DF.

Already did that for stuff related to creatures. But it seems, it is not really usefull for general world items. Am I overlooking something here, too?

The df structures xml files are the actual variable name spaces being used by the dfhack lua, for instance, df.items.xml has
Code: [Select]
...
    <bitfield-type type-name='item_flags'>
        <flag-bit name='on_ground' comment='Item on ground'/>
        <flag-bit name='in_job' comment='Item currently being used in a job'/>
        <flag-bit name='hostile' comment='Item owned by hostile'/>
        <flag-bit name='in_inventory' comment='Item in a creature, workshop or container inventory'/>

        <flag-bit name='removed' comment='completely invisible and with no position'/>
        <flag-bit name='in_building' comment='Part of a building (including mechanisms, bodies in coffins)'/>
        <flag-bit name='container' comment='Set on anything that contains or contained items?'/>
        <flag-bit name='dead_dwarf' comment='Dwarfs dead body or body part'/>

        <flag-bit name='rotten' comment='Rotten food'/>
        <flag-bit name='spider_web' comment='Thread in spider web'/>
        <flag-bit name='construction' comment='Material used in construction'/>
        <flag-bit name='encased' comment='Item encased in ice or obsidian'/>

        <flag-bit name='unk12' comment='unknown, unseen'/>
        <flag-bit name='murder' comment='Implies murder - used in fell moods'/>
        <flag-bit name='foreign' comment='Item is imported'/>
        <flag-bit name='trader' comment='Item ownwed by trader'/>

        <flag-bit name='owned' comment='Item is owned by a dwarf'/>
        <flag-bit name='garbage_collect' comment='Marked for deallocation by DF it seems'/>
        <flag-bit name='artifact' comment='Artifact'/>
        <flag-bit name='forbid' comment='Forbidden item'/>

        <flag-bit name='already_uncategorized' comment='unknown, unseen'/>
        <flag-bit name='dump' comment='Designated for dumping'/>
        <flag-bit name='on_fire' comment='Indicates if item is on fire, Will Set Item On Fire if Set!'/>
        <flag-bit name='melt' comment='Designated for melting, if applicable'/>

        <flag-bit name='hidden' comment='Hidden item'/>
        <flag-bit name='in_chest' comment='Stored in chest/part of well?'/>
        <flag-bit name='use_recorded' comment='transient in unit.used_items update'/>
        <flag-bit name='artifact_mood' comment='created by mood/named existing item'/>

        <flag-bit name='temps_computed' comment='melting/boiling/ignite/etc. points'/>
        <flag-bit name='weight_computed'/>
        <flag-bit name='unk30' comment='unknown, unseen'/>
        <flag-bit name='from_worldgen' comment='created by underground critters?'/>
    </bitfield-type>
...

while df.item-raws.xml has
Code: [Select]
...
    <enum-type type-name='item_type' base-type='int16_t'>
        <enum-attr name='caption'/>
        <enum-attr name='is_rawable' type-name='bool'/>
        <enum-attr name='is_stackable' type-name='bool'/>
        <enum-attr name='is_caste_mat' type-name='bool'
                   comment='instead of material, uses a creature/caste pair'/>
        <enum-attr name='classname'/>

        <enum-item name='NONE' value='-1'/>
        <enum-item name='BAR' comment='Bars, such as metal, fuel, or soap.'>
            <item-attr name='caption' value='bars'/>
            <item-attr name='classname' value='item_barst'/>
        </enum-item>
        <enum-item name='SMALLGEM' comment='Cut gemstones usable in jewelers workshop'>
            <item-attr name='caption' value='cut gem'/>
            <item-attr name='classname' value='item_smallgemst'/>
        </enum-item>
        <enum-item name='BLOCKS' comment='Blocks of any kind.'>
            <item-attr name='caption' value='blocks'/>
            <item-attr name='classname' value='item_blocksst'/>
        </enum-item>
        <enum-item name='ROUGH' comment='Rough gemstones.'>
            <item-attr name='caption' value='rough gem'/>
            <item-attr name='classname' value='item_roughst'/>
        </enum-item>
        <enum-item name='BOULDER' comment='Raw mined stone.'>
            <item-attr name='caption' value='boulder'/>
            <item-attr name='classname' value='item_boulderst'/>
        </enum-item>
        <enum-item name='WOOD' comment='Wooden logs.'>
            <item-attr name='caption' value='logs'/>
            <item-attr name='classname' value='item_woodst'/>
        </enum-item>
...

It can be difficult to parse through the files since there is a lot of information, and only some of them have comments, but I pretty much am always looking through those files
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r3 | 0.47.03-beta1
« Reply #2180 on: March 06, 2020, 04:53:58 pm »

gui/gm-editor can show the info about items just the same way it can show info about creatures. The difference is that you'd have to have the right viewing mode in DF, so for a creature it would be 'v', while for an item it would be 'k', and I think workshops show different info with 'k' and 't'.
Logged

Alatun

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r3 | 0.47.03-beta1
« Reply #2181 on: March 06, 2020, 05:30:21 pm »


The df structures xml files are the actual variable name spaces being used by the dfhack lua, for instance, df.items.xml ...

I did a git clone of dfhack and found nothing. Until I discovered a few minutes ago that there is another repo, which contains the xml files you mentioned:
https://github.com/DFHack/df-structures

It looks, like this is the key!


gui/gm-editor can show the info about items just the same way it can show info about creatures. The difference is that you'd have to have the right viewing mode in DF, so for a creature it would be 'v', while for an item it would be 'k', and I think workshops show different info with 'k' and 't'.

Another helpful hint. I was using it mostly from the units list, so I never had the idea to try it with other viewing modes.

Hopefully, with this information my progress will be better. Thanks guys.

Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: DFHack 0.44.12-r3 | 0.47.03-beta1
« Reply #2182 on: March 06, 2020, 10:35:03 pm »

Uhh, someone said it outright but surrounded by other stuff so the flag you are looking for is "foreign". If that is false, then it is a fort item.

Atomic Chicken

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r3 | 0.47.03-beta1
« Reply #2183 on: March 07, 2020, 02:19:04 am »

artifact_mood: I assume this means in_job, but specifically for an artifact.

No, this is set for any item that is a 'genuine' artifact, in the sense that it was produced via a strange mood, item creation interaction, etc as opposed to artifacts created by simply bestowing a name on items (which have the 'artifact' item flag set but lack 'artifact_mood'). If I remember correctly, artifact_mood is also what makes artifact items indestructible.


Another helpful hint. I was using it mostly from the units list, so I never had the idea to try it with other viewing modes.

Even more useful than that is the fact that you can use commands like "gui/gm-editor df.global", "gui/gm-editor df.global.world", "gui/gm-editor df.global.ui_advmode", "gui/gm-editor dfhack.gui.getCurViewscreen()", etc. I've got a whole bunch of these in hotkey form to facilitate research.
Logged
As mentioned in the previous turn, the most exciting field of battle this year will be in the Arstotzkan capitol, with plenty of close-quarter fighting and siege warfare.  Arstotzka, accordingly, spent their design phase developing a high-altitude tactical bomber. 

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r3 | 0.47.03-beta1
« Reply #2184 on: March 07, 2020, 04:16:06 am »

Thanks Atomic Chicken. I guess that illustrates the "try to figure out" part, including how it can lead you astray...
Logged

Erendir

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r3 | 0.47.03-beta1
« Reply #2185 on: March 07, 2020, 05:31:21 am »


The df structures xml files are the actual variable name spaces being used by the dfhack lua, for instance, df.items.xml ...

I did a git clone of dfhack and found nothing. Until I discovered a few minutes ago that there is another repo, which contains the xml files you mentioned:
https://github.com/DFHack/df-structures

It looks, like this is the key!

dfhack is using git submodules, they are a bit tricky, see dfhack docs for how to:
Code: [Select]
git clone --recursive https://github.com/DFHack/dfhack
`recursive` is the important part.

On another note, Lua the programming language's name isn't an acronym.
Logged

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: DFHack 0.44.12-r3 | 0.47.03-beta1
« Reply #2186 on: March 07, 2020, 09:49:05 am »

So it seems there is no item flag that has the information whether the item is owned by the fort (as being indicated by the stockpile color red) and I must check other states that might block access.

In this case, you are correct - the criteria for "foreign" items in the stocks screen showing up Red is that they are stored in the inventory of a unit who is not a member of your fortress. Determining this involves looking at item.general_refs and following them until you get to the owner, then using a DFHack builtin function to tell you if that unit is a citizen.
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.

Alatun

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r3 | 0.47.03-beta1
« Reply #2187 on: March 07, 2020, 02:19:36 pm »

So it seems there is no item flag that has the information whether the item is owned by the fort (as being indicated by the stockpile color red) and I must check other states that might block access.

In this case, you are correct - the criteria for "foreign" items in the stocks screen showing up Red is that they are stored in the inventory of a unit who is not a member of your fortress. Determining this involves looking at item.general_refs and following them until you get to the owner, then using a DFHack builtin function to tell you if that unit is a citizen.

It seems I found a solution that works for me now:
Code: [Select]
not item.flags.rotten and not item.flags.dump and not item.flags.forbid and not item.flags.construction and not item.flags.trader and not item.flags.spider_web
If it turns out, that this is not enough I will try to add your proposal. Thx.
« Last Edit: March 08, 2020, 03:28:58 am by Alatun »
Logged

ragundo

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r3 | 0.47.03-beta1
« Reply #2188 on: March 07, 2020, 03:40:11 pm »

If you are on Windows, you can take also a look at my plugin Dwarfexplorer (I need to promote it  ;D)



You get:
  • A graphical viewer for all df structures
  • All comments defined in the xml definition
  • Flags decoded
  • Subclasses automatically casted to the correct derived class
  • Visualization of parent classes
  • Open as many windows as you want
  • Zoom Dwarf Fortress window automatically to the coordinate selected in a structure
  • Hexadecimal memory viewer
  • The xml file name where the structure is defined

https://github.com/ragundo/DwarfExplorer

Also I'm working actively right now in the version 2 of the plugin which features:
  • A interactive input where you can choose what structure to show as a lua expression
  • Intellisense for data input
  • Bookmarks to most used structures and recently used expressions
  • Fully dockable views
  • Support for hyperlinking between structures using index-refer-to, etc







Logged

Erendir

  • Bay Watcher
    • View Profile
Re: DFHack 0.44.12-r3 | 0.47.03-beta1
« Reply #2189 on: March 08, 2020, 04:09:49 am »

this Dwarfexplorer looks very promising. Unfortunately, the v1.2 release's `DwarfExplorer_0.44.07_Win64.zip` doesn't include the `qapplication.plug.dll`, and v1.1's is compiled against dfhack 0.44.12-r3 and wouldn't work with 0.47.03-beta1.
Logged
Pages: 1 ... 144 145 [146] 147 148 ... 244