# Getting world data

**URL:** <https://discourse.cataclysmdda.org/t/getting-world-data/14007>\
**Category:** The Toolbox\
**Created:** [July 18, 2017, 1:48am UTC](https://discourse.cataclysmdda.org/t/getting-world-data/14007 "2017-07-18T01:48:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ioncloud](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/ioncloud/32/1300_2.png) [@Ioncloud](https://discourse.cataclysmdda.org/u/Ioncloud)\
**Post date:** [July 18, 2017, 1:48am UTC](https://discourse.cataclysmdda.org/t/getting-world-data/14007/1 "2017-07-18T01:48:19Z")

</div>

This post will sorta explain wtf: [http://smf.cataclysmdda.com/index.php?topic=14581.0](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](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):

```auto
    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;
    }
```

---

<div class="post-metadata">

**Author:** ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)\
**Post date:** [July 18, 2017, 4:52am UTC](https://discourse.cataclysmdda.org/t/getting-world-data/14007/2 "2017-07-18T04:52:55Z")

</div>

What is the question exactly?

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

---

<div class="post-metadata">

**Author:** ![Ioncloud](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/ioncloud/32/1300_2.png) [@Ioncloud](https://discourse.cataclysmdda.org/u/Ioncloud)\
**Post date:** [July 18, 2017, 12:46pm UTC](https://discourse.cataclysmdda.org/t/getting-world-data/14007/3 "2017-07-18T12:46:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)\
**Post date:** [July 18, 2017, 2:29pm UTC](https://discourse.cataclysmdda.org/t/getting-world-data/14007/4 "2017-07-18T14:29:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ioncloud](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/ioncloud/32/1300_2.png) [@Ioncloud](https://discourse.cataclysmdda.org/u/Ioncloud)\
**Post date:** [July 18, 2017, 4:16pm UTC](https://discourse.cataclysmdda.org/t/getting-world-data/14007/5 "2017-07-18T16:16:36Z")

</div>

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.x_131+local.x, submap.y_131+local.y?

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

---

<div class="post-metadata">

**Author:** ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)\
**Post date:** [July 18, 2017, 5:49pm UTC](https://discourse.cataclysmdda.org/t/getting-world-data/14007/6 "2017-07-18T17:49:48Z")

</div>

Look up coordinate\_conversions.h  
Not the most intuitive thing, but it’s usable.

---

<div class="post-metadata">

**Author:** ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)\
**Post date:** [July 27, 2017, 8:14am UTC](https://discourse.cataclysmdda.org/t/getting-world-data/14007/7 "2017-07-27T08:14:08Z")

</div>

Why map-files contained in maps\x.y.z subfolders have coordinate values multiplied by two (2_x,2_y,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`?

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

---

<div class="post-metadata">

**Author:** ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)\
**Post date:** [July 27, 2017, 11:39am UTC](https://discourse.cataclysmdda.org/t/getting-world-data/14007/8 "2017-07-27T11:39:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)\
**Post date:** [July 27, 2017, 5:36pm UTC](https://discourse.cataclysmdda.org/t/getting-world-data/14007/9 "2017-07-27T17:36:49Z")

</div>

Thanks!

> [@Coolthulhu](#):
>
> Each file contains an overmap tile.

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

---

<div class="post-metadata">

**Author:** ![Coolthulhu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/coolthulhu/32/2446_2.png) [@Coolthulhu](https://discourse.cataclysmdda.org/u/Coolthulhu)\
**Post date:** [July 27, 2017, 5:47pm UTC](https://discourse.cataclysmdda.org/t/getting-world-data/14007/10 "2017-07-27T17:47:29Z")

</div>

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