summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp AUER <SBird1337@users.noreply.github.com>2020-07-17 12:16:23 +0200
committerPhilipp AUER <SBird1337@users.noreply.github.com>2020-07-17 12:16:23 +0200
commita962c037f21fe241b9af2d23210a7aa0cc1e7325 (patch)
treed25de33452f6357a44a7a6adaa4a82b2471c7319
parent564cc13089ede58c50fc34a05449f1fd23096b54 (diff)
Updated Triple layer metatiles (markdown)
-rw-r--r--Triple-layer-metatiles.md93
1 files changed, 93 insertions, 0 deletions
diff --git a/Triple-layer-metatiles.md b/Triple-layer-metatiles.md
index 32c6594..5f6b478 100644
--- a/Triple-layer-metatiles.md
+++ b/Triple-layer-metatiles.md
@@ -106,6 +106,99 @@ With the state as is doors will break. Drawing doors also causes a call to `Draw
This causes the game to use the normal rendering behavior when using handling door animations.
+## Fixing the pokemart
+
+Marts are weird in vanilla. They try to move tiles from BG1 to the other 2 BGs in order to make some space for the `pokemart` UI. They also redraw a big portion of the map which needs to be updated. All those changes go to `src/mart.c`
+
+In `BuyMenuDrawMapBg`:
+
+```diff
+ static void BuyMenuDrawMapBg(void)
+ {
+ metatile = MapGridGetMetatileIdAt(x + i, y + j);
+ if (BuyMenuCheckForOverlapWithMenuBg(i, j) == TRUE)
+- metatileLayerType = MapGridGetMetatileLayerTypeAt(x + i, y + j);
++ metatileLayerType = 0;
+ else
+ metatileLayerType = 1;
+
+ if (metatile < NUM_METATILES_IN_PRIMARY)
+ {
+- BuyMenuDrawMapMetatile(i, j, (u16*)mapLayout->primaryTileset->metatiles + metatile * 8, metatileLayerType);
++ BuyMenuDrawMapMetatile(i, j, (u16*)mapLayout->primaryTileset->metatiles + metatile * 12, metatileLayerType);
+ }
+ else
+ {
+- BuyMenuDrawMapMetatile(i, j, (u16*)mapLayout->secondaryTileset->metatiles + ((metatile - NUM_METATILES_IN_PRIMARY) * 8), metatileLayerType);
++ BuyMenuDrawMapMetatile(i, j, (u16*)mapLayout->secondaryTileset->metatiles + ((metatile - NUM_METATILES_IN_PRIMARY) * 12), metatileLayerType);
+ }
+ }
+```
+
+This will get the size of the metatiles correct and will also update the `metatileLayerType` which we will use to do some tile reordering later. Next have a look at `BuyMenuDrawMapMetatile`:
+
+```diff
+ static void BuyMenuDrawMapMetatile(s16 x, s16 y, const u16 *src, u8 metatileLayerType)
+ {
+ u16 offset1 = x * 2;
+ u16 offset2 = y * 64;
+-
+- switch (metatileLayerType)
++ if(metatileLayerType == 0)
+ {
+- case 0:
+- BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[3], offset1, offset2, src);
+- BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[1], offset1, offset2, src + 4);
+- break;
+- case 1:
+- BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[2], offset1, offset2, src);
++ BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[2], offset1, offset2, src + 0);
+ BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[3], offset1, offset2, src + 4);
+- break;
+- case 2:
+- BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[2], offset1, offset2, src);
+- BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[1], offset1, offset2, src + 4);
+- break;
++ BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[1], offset1, offset2, src + 8);
++ }
++ else
++ {
++ if(IsMetatileLayerEmpty(src))
++ {
++ BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[2], offset1, offset2, src + 4);
++ BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[3], offset1, offset2, src + 8);
++ }
++ else if(IsMetatileLayerEmpty(src + 4))
++ {
++ BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[2], offset1, offset2, src);
++ BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[3], offset1, offset2, src + 8);
++ }
++ else if(IsMetatileLayerEmpty(src + 8))
++ {
++ BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[2], offset1, offset2, src);
++ BuyMenuDrawMapMetatileLayer(gShopDataPtr->tilemapBuffers[3], offset1, offset2, src + 4);
++ }
+ }
+ }
+```
+
+This will handle drawing triple layers, except when the element on the mapgrid would overlap with an UI element. It will then try to find and empty layer and move the other tiles accordingly. You also have to add this function somewhere above `BuyMenuDrawMapMetatile`:
+
+```C
+static bool8 IsMetatileLayerEmpty(const u16 *src)
+{
+ u32 i = 0;
+ for(i = 0; i < 4; ++i)
+ {
+ if((src[i] & 0x3FF) != 0)
+ return FALSE;
+ }
+ return TRUE;
+}
+```
+
+Note that when using the `pokemart` you have to absolutely make sure that no triple layer tiles are around the UI elements when the mart is open. The mart uses one BG layer for itself, which we need to take into account here.
+
## Updating existing tilesets
As mentioned previously this method requires us 4 additional tilemap entries for each metatile. The normal tileset data does not contain that data and at this stage your game will just look corrupted. Luckily we can just run a simple python script to migrate old tilesets. It can be found here: https://gist.github.com/SBird1337/ccfa47b5ef41c454b637735d4574592a