43 Expanding The Metatile Count
Team Aqua's Hideout edited this page 2024-11-10 17:45:33 -05:00

Here in this tutorial we will increase the cap for metatiles from 1024 to 4096 by removing the redundant collision bit and decreasing the possible elevations from 16 to 8. You can also get 2048 metatiles with just the unused collision bit, without affecting elevation, the process would be largely the same as described here with some small changes:

Why Would I Want This:

Increasing the metatile cap is pretty self explanatory for some but many people have asked exactly what that means for them so I will be clear here for anyone confused, skip if you understand already. Normally when you're creating a map you have access to 512 metatiles from each tileset (in pokeemerald at least) adding up to 1024 total metatiles you can use. Metatiles are the 16x16 tiles that you actually place down in porymap, made up of 3 layers of 4 8x8 tiles from the actual tileset image. This does not increase the size of the tileset, but it does quadruple the number of metatiles that you can create using your tileset which is probably more than you will ever need. Before you could use 512 metatiles per tileset, after these changes you can use 2048.

Code Changes:

Link to Code Changes (branch of TAH pokeemerald fork)

Code Change Screenshots
Screenshot 3 Screenshot 3 Screenshot 3

There are a handful of constants that need to be changed in the fieldmap header files. The bit masks have to be changed so that the metatile id goes from 10 to 12 bits. This is what allows the game to register ids up to 4096. The collision section is reduced to 1 bit because thats all that is ever used. The elevation mask is reduced by 1 bit as well to gain more space. This one isn't required if you're okay with 2048 metatiles, but other parts of this tutorial will differ if you don't. The other changes found in the link are to change the metatile count constants to 2048 for primary and 4096 for total count, and then to change a couple of values in event_object_movement.c from 15 to 7 which is the new elevation max. This needs to be done so that the crossed arrows elevation used for bridges is now updated to the new max, which is now 7.

Porymap Changes:

After changing this stuff some updates will need to be made in Porymap, to only use 8 elevations you will want to change the elevation image to collisions.png this new one, and change the max elevation number to 7 which you can do in Porymaps settings here:

image collisions

Python Script to Update Existing Maps

With the constants updated and the settings changed in porymap, after reloading you will be able to use 4096 metatiles in your maps. However, you may notice that every single map you have made is broken. This is normal, the binary map data needs to be converted into the new format so porymap can properly recognize it. For that there is a python script in the repo Found Here. This script when in the main pokeemerald folder of your project is ran using:

python3 expand_metatiles.py

If you do not have python installed you will need to install it. After running this script all your maps should be converted into the new format. If you used any elevations greater than 6 in your maps those areas will be the wrong elevation and will need to be fixed but 99% of maps don't use any above 5 so that shouldn't be a common issue, Mossdeep is affected in vanilla but idk about anywhere else. Anyway, reload porymap and your maps should be back to normal again. If you did not get rid of the elevation bit, you will have to make changes to the Python program so that the new elevation bitmask is four bits instead of three like it is currently.

Metatile Labels

All the metatile labels for secondary tileset metatiles that you have created will have to be updated. There is a very easy way to do this though. Just open include/constants/metatile_labels.h and do a Find and Replace for 0x2 with 0x8 and then another for 0x3 with 0x9. This should convert all the vanilla metatile labels into the new ranges.

Porytiles Compatibility:

As is tradition for Porytiles, documentation will be left as an exercise for the reader... Here is what Lucas had to say about it:

image

Credits

  • Tutorial by Archie (with help from GriffinR and inspired by Dragonfly)
  • Python Script by Archie and ChatGPT for lazy boilerplate
  • Porymap Compatibility Already Existed From The Awesome Dev Team

Contact

If you have questions or problems with the branch join the TAH Discord and ping me in the #romhacking-help channel for help: https://discord.gg/hX3a63RYzZ