dfhack icon indicating copy to clipboard operation
dfhack copied to clipboard

Getting all tiles in local map through RemoteFortressReader Python client

Open hyperioo opened this issue 2 years ago • 3 comments

Hello,

First I would like to thank you for putting up this work! I am struggling a bit using the RemoteFortressReader plugin.

Basically I want to grab information about all ingame tiles of the currently opened Fortress with DFHack running in the background. Ideally, this would be a 3D matrix with each cell containing information about the type of the associated tile (air, rock, water, wood...), potentially with buildings, items and creatures in that tile.

I dug a bit in DFHack documentation and from what I understand tiles are gathered in blocks. So I was trying to use the GetBlockList function to see what I could get (and from what I see in https://github.com/DFHack/dfhack/blob/b954cd7a0d574fa92d7c9a26a9e2298ab9126959/plugins/remotefortressreader/remotefortressreader.cpp#L1395 it seems to access tile info).

I am using the Python client (https://github.com/McArcady/dfhack-client-python). I successfully managed to get some info like map info with GetMapInfo or the list of units with GetUnitList. Sadly when I use GetBlockList, the ouput has an empty field for the map_blocks and I don't really know if the interface is broken somehow or if I am doing something wrong.

I edited blendwarf.py with theses lines:

from RemoteFortressReader_pb2 import BlockRequest

from RemoteFortressReader_pb2 import BlockList
@remote(plugin='RemoteFortressReader')
async def GetBlockList(input: BlockRequest, output: BlockList): pass

and

    # Input argument
    blockRequest = BlockRequest()
    # Values based on what I saw in GetMapInfo
    blockRequest.min_x = 88
    blockRequest.max_x = 90
    blockRequest.min_y = 66
    blockRequest.max_y = 68
    blockRequest.min_z = -16
    blockRequest.max_z = -14

    # Reproducing the formulas of plugins/remotefortressreader/remotefortressreader.cpp
    center_x = (blockRequest.min_x + blockRequest.max_x) / 2
    center_y = (blockRequest.min_y + blockRequest.max_y) / 2
    nb_points = ((blockRequest.max_x - center_x + 1) * 2) * ((blockRequest.max_y - center_y + 1) * 2)
    blockRequest.blocks_needed = int(nb_points * (blockRequest.max_z - blockRequest.min_z))

    # Output argument
    blockList = BlockList()

    # Call to function
    print("Blocks: ", (await GetBlockList(blockRequest, blockList)))
    print(blockList)

I just see Blocks: map_x: 89 map_y: 67 so the funtion is well-called and returns values, but nothing for the blocks.

Do you have any idea about what is wrong? Do you know per chance if the interface is broken so this is expected?

Thank you for your help,

hyperioo avatar Dec 18 '22 14:12 hyperioo

Armok Vision uses RemoteFortressReader and renders the game map just fine, so I think that means it should be working. What could be happening here is that GetBlockList might be expecting block coordinates, and you're giving map coordinates, which are effectively greater than the allowable block bounds. In other words, try dividing your x and y values by 16.

myk002 avatar Dec 18 '22 15:12 myk002

Thank you for your reply.

I tried Armok Vision and it does render properly the local map so connection seems to be working. I dug into Armok Vision code to be sure I'm sending the right coordinates but I still don't have much success.

I got a In RPC server: I/O error in receive header. in DFHack window each time I make a request, even a simple one like GetMapInfo, so I guess something is going wrong with the input/output requests (made in https://github.com/McArcady/dfhack-client-python/blob/master/dfhack_remote.py) which could explain why I don't get block data (yet it works for GetUnitLists so...).

hyperioo avatar Dec 18 '22 16:12 hyperioo

Sorry to digging this up, but I looked into the same issues @hyperioo mentioned earlier. It seems the problem is with the wrapper in dfhack_remote.py

Since this doesn’t seem to be a DFHack issue, I’ll comment directly on the issue raised by hyperioo here

Ummoon avatar Oct 15 '24 12:10 Ummoon