Question about map.json files and their relationship to tileset.json

Background:

I'm working with a group of colleagues (programmers/academics) on a procedural generation tool for RPGmaker. Our goal is not to create an in-game random generator, but rather a stand alone tool that can be used to generate maps (based on certain criteria) which could then be edited in RPGmaker. Much of the pleasure is in the fine tuning, but I believe a degree of procedural generation can be a wonderful assist.

To do this, we're going to take some preexisting procedural map generating tools, based on semi-realistic environmental modeling, and build a program that outputs their value into a map.json file (compatible with RPGmaker); we will also need to amend the mapinfos.json file so that new maps can then be seen in RPGmaker.

In so far as I can tell -- each map.json file refers to a "tilesetId", which can be found in the tileset.json file (in the "data" folder). Following this, there are six "levels" of value, presented in a single array (total length = map height * map width * 6). I have every reason to believe that "6" is not a set number, rather it is determined by the user (database -> tilesets).

Problem:

Assuming that I am working with a default map tileset "Overworld", if I place grassland in the upper left corner, it predictably changes the first item in the array from "0" to "2816". Changing other values to "2816" will predictably add new grasslands (this gets more complicated for other objects). However, I have no idea how/where this number "2816" is set from. In tileset.json, there is no number "2816". I know the file that it references "World_A2.png"... but I can't figure out how a location on that file gets coded to a specific number -- in fact I can't figure out where than number comes from at all.

While it's reasonably easy, though tedious, for me to hard code the values, I worry that this would make the generator we're building much less useful for the community, as it would necessitate a great deal of a hard coding whenever a person wanted to make use of a non-standard tileset. Alternatively, if the generator can load a tileset (with tags, rules, etc), I could see the program being much more useful.

To repeat my question: how does an area on a .png file come to receive an index number (that also contains movement information) in RPG maker? -- more to the point, is there a file in RPG maker that keeps track of this "conversion table"?

I would appreciate any direction in this matter. If I got anything wrong, please correct.
Rest assured, I will upload a version of the terrain generator as soon as we can get it working.

If I posted this in the wrong area, I apologize.
Moderator note: I think the best place for this is the Learning Javascript forum, which seems to be pretty flexible about what can be posted there. I am, therefore moving this.
It has to do with x y z in like bit size or something.

@Another Fen explained it to me in this thread.
https://forums.rpgmakerweb.com/index.php?threads/marshal-dump-integer-maxed-out-at-127.75394/

I was able to determine the layer array length, but I still don't know what they draw.

This thread is Ruby forum, but those dudes helped me write a thing to Unmarshal and convert RVDATA2 into MV JSON.
6 is a set number. That is exactly how many levels there are, and you cannot increase or decrease that number.

I am not certain how these are allocated, but there will be 3 or 4 for the mapping layers, a shadow layer, a regions layer and a another layer that I don't know what it's used for - it looked like there were two layers that had region data when I pulled them apart for my Ace > MV script, but I didn't need to look into it any further than just copying the data. Within each layer, there will be x by y tiles, according to the width and height of the map.

For the mapping layers, each element will refer to a tile ID on the tileset. 0 is the top left B tile, and each subsequent number works its way through the B, C, D and E tiles, followed by the A5 tile, and then the A1, A2, A3 and A4 autotiles. The B-E and A5 tiles have one number for each tile, but the A1-A4 autotiles have more, as each autotile has up to 48 different patterns and the water autotiles have that multiplied by 3. If you want an explanation of those, look for the autotile tutorial for VX Ace (I think it's by PK8) - the format for Ace and MV is the same.

The tileset contains all the flags (passage settings, counter, damage, ladder, etc), and the engine uses the tile id from the x/y location on the map to retrieve those settings for whatever tile is being looked at. For passage settings, it starts with the highest mapping layer and works its way down, until it encounters a tile with a passability setting (ie - not a star).
Shaz, thank you very much for your response. I came to the conclusion about six being non-arbitrary, but I did not realize the shadow layer was present. As far as I can see, region data (for encounters) is controlled by the 6th layer only.

I've figured out that variants of the tile (e.g. border, different center, etc) have standard offset values. The lowest value correlates to the "center" tile, i.e. what it looks like what it is surrounded. Every other tile can be expressed as an offset of that. For reference, here is a legend from the map.json (see image).

sq up left = min + 34
sq mid left = min + 16
sq dwn left = min + 40
sq up center = min + 20
sq mid center = min + 0
sq sq center = min + 28
sq up right = min + 36
sq mid right = min + 24
sq dwn right = min + 38
horz left = min + 43
horz mid = min + 33
horz right = min + 45
vert line top = min + 42
vert line mid + min +32
vert line bottom = min + 44
solo = min + 46
cross center = min + 15

Now I will admit being a little confused. I can only see these 17 configurations as they end up being represented in the map.json. Using animated tiles doesn't appear to change this, though I believe you that the extra space might be reserved for them.

What leads you to believe there are 48 different patterns for non-animated tiles?

I am more than willing to believe I missed something.

Thanks again for your assistance.
@chris.k please check the following tutorial about shift-click-mapping.
One of the pictures there shows the possible different combinations of autotiles, you missed quite a lot of them because you only looked at basic sequences
https://forums.rpgmakerweb.com/index.php?threads/shift-click-mapping.14387/
Andar, thank you kindly. That certainly gives me something to chew on.
If you have RMXP, or want to download the trial, it lets you see all the autotile patterns available. Just go into the editor and double-click on one of the autotiles (these are in the top row only). This will show you all 48 different combinations.

VX, Ace and MV all follow the same autotile format, though they use tiles that are made up of 2x3 units rather than 3x4, but the resulting patterns are the same. The "smaller" autotiles - the waterfalls, cliff/building faces, rooftops - don't give you as many patterns, but internally they still have 48 numbers/ids allocated to them - the extras are just blank. I confirmed this when I made my Upper Autotiles plugin, that broke when MV 1.4 was released and changed the way tile animation happens.
Shaz,

Thank you for the information, and I am sorry for not responding sooner.

Using RPG MakerXP, I pulled the auto tile patterns as you suggested. I imposed a grid on top of them and calculated the offset value, which I then checked against the map file.

If you know the mapfile value associated with a 0 tile, you can calculate all other tiles.

This may not be useful to anyone other than me, but I wanted to share the table and a descriptive summary of it.

AutoTile Table.PNG


The table below describes where the border pieces appear in a given tile.

AutoTile table description.PNG
Hey, I'm also messing around with an external program that can edit the map.json and I was completly lost on what the data hash meant. After doing some research I found this topic and it helped me understand what was going on here. Thanks to everyone who shared their discovies.

Original thread: https://forums.rpgmakerweb.com/threads/question-about-map-json-files-and-their-relationship-to-tileset-json.76860/