Bay 12 Games Forum

Please login or register.

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

Author Topic: Getting the material of a tile [DFHack]  (Read 4301 times)

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Getting the material of a tile [DFHack]
« on: November 21, 2014, 02:08:17 pm »

Simply put, how do you get the material of a tile from it's coords? I really need to be able to tell if a building is built on sand or clay, and all I can seem to get is if it is built on soil.
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS

Protonicus

  • Bay Watcher
    • View Profile
Re: Getting the material of a tile [DFHack]
« Reply #1 on: December 04, 2014, 02:34:18 am »

I cannot help you directly.
But you may look at your df folder "dwarf fortress/hack/ruby/map.rb"
I found there smth similiar to your question.

Code: [Select]
def tilemat
     Tiletype::Material[tiletype]
end

def map_block_at(x, y=nil, z=nil)
      x = x.pos if x.respond_to?(:pos)
      x, y, z = x.x, x.y, x.z if x.respond_to?(:x)
      if x >= 0 and x < world.map.x_count and y >= 0 and y < world.map.y_count and z >= 0 and z < world.map.z_count
           world.map.block_index[x/16][y/16][z]
      end
end
« Last Edit: December 04, 2014, 02:36:05 am by Protonicus »
Logged

UristMcNoble

  • Escaped Lunatic
    • View Profile
Re: Getting the material of a tile [DFHack]
« Reply #2 on: January 26, 2015, 09:21:57 pm »

Might be a bit late, but this will tell you what the material under the current cursor position is
Code: [Select]
df.map_tile_at(*df.cursor).mat_info.token
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Getting the material of a tile [DFHack]
« Reply #3 on: January 26, 2015, 09:48:32 pm »

uh what language is that

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: Getting the material of a tile [DFHack]
« Reply #4 on: January 27, 2015, 02:15:07 am »

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Getting the material of a tile [DFHack]
« Reply #5 on: January 27, 2015, 02:19:09 am »

I figured it was probably, but the snippet was too small for me to tell precisely. I mean, I was fairly confident, but ya gotta ask.

Raidau

  • Bay Watcher
    • View Profile
Re: Getting the material of a tile [DFHack]
« Reply #6 on: January 27, 2015, 08:35:42 am »

probe plugin may be the answer, since it gets the tile material somehow. I wish to implement tile material related things in my mod :)
Logged
Marital status manipulator
Custom item descriprions
Natural Balance Mod (2013-2015) development suspended...

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: Getting the material of a tile [DFHack]
« Reply #7 on: January 27, 2015, 05:23:10 pm »

Is there a Lua way to do that?
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Getting the material of a tile [DFHack]
« Reply #8 on: January 27, 2015, 06:09:25 pm »

Well, probe does it like so:

Code: [Select]
df::tiletype_material material = tileMaterial(tiletype);

tileMaterial is a function:

Code: [Select]
    inline
    df::tiletype_material tileMaterial(df::tiletype tiletype)
    {
        return ENUM_ATTR(tiletype, material, tiletype);
    }

And ENUM_ATTR is a function-like preprocessor macro:

Code: [Select]
#define ENUM_ATTR(enum,attr,val) (df::enum_traits<df::enum>::attrs(val).attr)
There's a lot more in probe, gimme a little bit. df.tiletype.attrs[num].material is most certainly a thing, at least.

EDIT: Wow this is complicated, heh. Hmm:

Code: [Select]
    /// Base layer material (i.e. layer stone, veins, feature stone)
    t_matpair baseMaterialAt(df::coord2d p)
    {
        if (!basemats) init_tiles(true);
        return t_matpair(
            index_tile<int16_t>(basemats->mat_type,p),
            index_tile<int16_t>(basemats->mat_index,p)
        );
    }

Okay. That's in MapCache, so apparently that may be needed.
« Last Edit: January 27, 2015, 06:16:29 pm by Putnam »
Logged

milo christiansen

  • Bay Watcher
  • Something generic here
    • View Profile
Re: Getting the material of a tile [DFHack]
« Reply #9 on: January 27, 2015, 06:20:07 pm »

That's s far as I got too, MapCache is apparently not exported to Lua.
Logged
Rubble 8 - The most powerful modding suite in existence!
After all, coke is for furnaces, not for snorting.
You're not true dwarven royalty unless you own the complete 'Signature Collection' baby-bone bedroom set from NOKEAS

lethosor

  • Bay Watcher
    • View Profile
Re: Getting the material of a tile [DFHack]
« Reply #10 on: January 27, 2015, 09:26:04 pm »

I believe MapCache is only a wrapper, so you should be able to get the same data from map blocks directly (although I'm not exactly sure how).
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

Raidau

  • Bay Watcher
    • View Profile
Re: Getting the material of a tile [DFHack]
« Reply #11 on: January 27, 2015, 10:03:29 pm »

I believe MapCache is only a wrapper, so you should be able to get the same data from map blocks directly (although I'm not exactly sure how).

Yeah, blocks contain information about inorganics the tiles consist of. But the data structure there is complicated
Logged
Marital status manipulator
Custom item descriprions
Natural Balance Mod (2013-2015) development suspended...

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: Getting the material of a tile [DFHack]
« Reply #12 on: January 28, 2015, 01:47:41 am »

this part
Code: [Select]
#define ENUM_ATTR(enum,attr,val) (df::enum_traits<df::enum>::attrs(val).attr)
is actually exported to lua. I think it's "df.tiletype.attrs[tiletype]" or "df.tiletype._attrs[tiletype]".
So it would look like:
Code: [Select]
local ttype=dfhack.maps.getTileType(x,y,z)
local material=df.tiletype.attrs[ttype].material
or something like that...

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Getting the material of a tile [DFHack]
« Reply #13 on: January 28, 2015, 01:54:55 am »

Yeah, I mentioned that.

There's a lot more in probe, gimme a little bit. df.tiletype.attrs[num].material is most certainly a thing, at least.

It doesn't really actually help though...

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
Re: Getting the material of a tile [DFHack]
« Reply #14 on: January 28, 2015, 02:09:04 am »

Oh missed that. I guess we need to make an util for that.

The complexity arises because map does not have "materials". It has indication that this tile is of some type. And then if it's construction you need to look one place, if it's vein other place, trees are yet in another place, layer materials are from yet another place and so on...
Pages: [1] 2