Getting world data

This post will sorta explain wtf: http://smf.cataclysmdda.com/index.php?topic=14581.0

Given that, I’m working on getting world data out of DDA and things were going along rather well when I came to this: http://imgur.com/a/jX33V

I started scratching my head, I was certain my chunk loading was centered around the player… that cant be world 0,0… Then I realized this was SCREEN space coordinates I was getting and not world space derp

I’m still working my way around the DDA code trying to puzzle it all out, but given the following function what would be the best way to query the data out of the world? (or can I o.0):

    Map* getTilesBetween(IVector2 from, IVector2 to) {
        Map* map = (Map*)::CoTaskMemAlloc(sizeof(Map));
        IVector2 bottomLeft;
        IVector2 topRight;
        if (from.x < to.x && from.y < to.y) {
            bottomLeft = from;
            topRight = to;
        }
        else {
            bottomLeft = to;
            topRight = from;
        }
        int width = topRight.x - bottomLeft.x + 1;
        int height = topRight.y - bottomLeft.y + 1;
        map->width = width;
        map->height = height;
        map->tiles = (Tile*)::CoTaskMemAlloc(sizeof(Tile) * width * height);

        int i = 0;
        for (int dx = bottomLeft.x; dx <= topRight.x; dx++) {
            for (int dy = bottomLeft.y; dy <= topRight.y; dy++) {
                const tripoint p = tripoint(dx, dy, 0);
                ter_str_id ter = g->m.ter(p)->id;
                map->tiles[i].ter = (char*)::CoTaskMemAlloc(ter.str().length() + 1);
                strcpy(map->tiles[i].ter, ter.c_str());
                furn_str_id furn = g->m.furn(p)->id;
                map->tiles[i].furn = (char*)::CoTaskMemAlloc(furn.str().length() + 1);
                strcpy(map->tiles[i].furn, furn.c_str());
                map->tiles[i].loc.x = p.x;
                map->tiles[i].loc.y = p.z;
                map->tiles[i].loc.z = p.y; // swap z and y for unity coordinate system
                i++;
            }
        }

        return map;
    }

What is the question exactly?

What do you want to get and what you’re getting instead of that?

what I’m trying to get is the world between 2 points
What I’m getting is only the screen tiles

When the game loads I get the player’s position g->u.pos then load the chunk the player is in as well as x chunks away from the player (configurable, in the screen shot I had it set to 50x50 tiles per chunk with 7x7 chunks loading)
Chunks are configured to pull data from DDA using the method I pasted.
the screenshot I attached illustrates the issue. There’s no way that the player is at/near world 0,0 but the bottom left of that picture is, in fact, 0,0 per the data from DDA

What it seems that I’m getting is the players place on the console screen, and the tiles I’m getting are the tiles at the console screen position 0,0 - 131,131

The idea is that I don’t need to pass a “look” command back to DDA to pan around, I should be able to get all the tiles the player can see and simply switch to free cam in unity to allow for smooth panning. I also need to be able to load tiles outside of the visible range in the background so there’s no extra lag when a player crosses a chunk boundary.

The code you listed should be getting tiles in local map coords, not screen coords, meaning look command should not be affecting anything.

You can’t easily get tiles outside 0-131 range because they may not exist.
You can use mapbuffer::lookup_submap to try to get a submap, but expect nulls for submaps that aren’t loaded into memory yet. Also expect submaps in memory that aren’t part of the currently loaded map to be unassigned without warning.
Submaps that aren’t generated will always be nulls here. You could try triggering a load with map::loadn, but it may have side effects.
A side-effect-free (as long as you run it serially, not in parallel with the game) way would be to create a map object and map::load a submap with it, but expect that to be relatively slow.

Hmm, I see… Is there a way to translate local to world point? I’d imagine submap = chunk in my case so a world point would be something like submap.x131+local.x, submap.y131+local.y?

I had started looking at submap, I’ll have to poke it a bit more and see what falls out.

Look up coordinate_conversions.h
Not the most intuitive thing, but it’s usable.

Why map-files contained in maps\x.y.z subfolders have coordinate values multiplied by two (2x,2y,2*z)?

For example, there are following files:

[pre]\cdda\save\Magee\maps\0.0.0\10.0.0.map
\cdda\save\Magee\maps\0.0.0\10.1.0.map
\cdda\save\Magee\maps\0.0.0\10.2.0.map
\cdda\save\Magee\maps\0.0.0\10.3.0.map[/pre]

These files have following coordinates:

[pre]“coordinates”:[20,0,0]
“coordinates”:[20,2,0]
“coordinates”:[20,4,0]
“coordinates”:[20,6,0][/pre]

Is it 2 *2 submaps which are described in coordinate_conversions.h?

 * submap (sm): each overmap terrain contains (2*2) submaps.
 * Translating from sm to omt coordinates:
 * sm.x /= 2
 * sm.y /= 2

There are 4 coordinate systems:

[ul][li]Local map tile (1x1)[/li]
[li]Submap (12x12 local map tiles)[/li]
[li]Overmap tile (2x2 submaps, 24x24 local map tiles)[/li]
[li]Overmap (180x180 overmap tiles)[/li][/ul]

Each file contains an overmap tile.

Thanks!

I presume youve meant submap instead of overmap? Otherwise there is no sense in having four map files.

No, not submap. A tile on overmap, so overmap tile - 2x2 submaps.