DFHack / dfhack

Memory hacking library for Dwarf Fortress and a set of tools that use it
Other
1.86k stars 468 forks source link

Request/Question: Access to automining designation through DFHack #1754

Closed MicroTransactionsMatterToo closed 3 years ago

MicroTransactionsMatterToo commented 3 years ago

Been trying to write a script to mark visible vein walls of a given material to be automined, but have hit a barrier trying to find a way to designate automining as opposed to normal digging. The only place I can find mention of it is in the exported ruby-autogen file, where it's present under UiSideBarMenus as the field mine_mode. As best I can tell, automining designations can't be told apart from normal dig designations within dfhack, but clearly the game itself handles them differently, so presumably there's a flag or a mine_mode field set on tiles somewhere. Anybody able to offer advice on this?

Ruby auto-gen code for reference

class UiSidebarMenus < MemHack::Compound
    sizeof 7304

    field(:designation, 0) {
        compound(:UiSidebarMenus_TDesignation) {
            field(:marker_only, 0) {
                number 8, true, nil, BooleanEnum
            }
            field(:priority_set, 1) {
                number 8, true, nil, BooleanEnum
            }
            field(:priority, 4) {
                number 32, true, 4000
            }
            field(:mine_mode, 8) {
                class ::DFHack::UiSidebarMenus_TDesignation_TMineMode < MemHack::Enum
                    ENUM = Hash.new
                    NUME = Hash.new
                    ENUM[0] = :All ; NUME[:All] = 0
                    ENUM[1] = :AutoMine ; NUME[:AutoMine] = 1
                    ENUM[2] = :Economic ; NUME[:Economic] = 2
                    ENUM[3] = :Gems ; NUME[:Gems] = 3
                end

                number 32, true, nil, UiSidebarMenus_TDesignation_TMineMode
            }
        }
    }
lethosor commented 3 years ago

The thing you found is part of the sidebar UI. The flags themselves are stored in the tile_occupancy struct (that's the C name, anyway) as dig_auto and dig_marked, probably because tile_designation ran out of space. In Ruby:

class TileOccupancy < MemHack::Compound
    field(:_whole, 0) {
        number 32, true
    }
    field(:building, 0) { bits 0, 3, TileBuildingOcc }
    field(:unit, 0) { bit 3 }
    field(:unit_grounded, 0) { bit 4 }
    field(:item, 0) { bit 5 }
    field(:edge_flow_in, 0) { bit 6 }
    field(:moss, 0) { bit 7 }
    field(:arrow_color, 0) { bits 8, 4 }
    field(:arrow_variant, 0) { bit 12 }
    field(:unk13_noncitizen_unit, 0) { bit 13 }
    field(:monster_lair, 0) { bit 14 }
    field(:no_grow, 0) { bit 15 }
    field(:unk16, 0) { bit 16 }
    field(:unk17, 0) { bit 17 }
    field(:carve_track_north, 0) { bit 18 }
    field(:carve_track_south, 0) { bit 19 }
    field(:carve_track_east, 0) { bit 20 }
    field(:carve_track_west, 0) { bit 21 }
    field(:unk22, 0) { bit 22 }
    field(:unk23, 0) { bit 23 }
    field(:dig_marked, 0) { bit 24 }
    field(:dig_auto, 0) { bit 25 }
    field(:heavy_aquifer, 0) { bit 26 }
end
MicroTransactionsMatterToo commented 3 years ago

Right, sweet. Thanks for the help. Would be nice if there was clearer documentation for the df object, the docs don't really cover what's in it. Obviously you can figure it out by reading other scripts and reading the source, but some proper docs would be nice.