From 120e75d275988c5d723ac827e141d4ea5195e461 Mon Sep 17 00:00:00 2001 From: sphericalice Date: Mon, 25 Oct 2021 18:03:14 +0100 Subject: [PATCH 1/4] Document the CloseBattlePikeCurtain special --- include/constants/metatile_labels.h | 1 + include/global.fieldmap.h | 5 +++++ src/field_specials.c | 34 +++++++++++++++++++---------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/include/constants/metatile_labels.h b/include/constants/metatile_labels.h index b4ee3eacf..519120082 100644 --- a/include/constants/metatile_labels.h +++ b/include/constants/metatile_labels.h @@ -352,6 +352,7 @@ #define METATILE_InsideShip_IntactDoor_Bottom_Interior 0x297 // gTileset_BattlePike +#define METATILE_BattlePike_CurtainFrames_Start 0x201 #define METATILE_BattlePike_Curtain_Stage0_Tile0 0x24A #define METATILE_BattlePike_Curtain_Stage0_Tile1 0x251 #define METATILE_BattlePike_Curtain_Stage0_Tile2 0x252 diff --git a/include/global.fieldmap.h b/include/global.fieldmap.h index 41b8539ff..a1e752415 100644 --- a/include/global.fieldmap.h +++ b/include/global.fieldmap.h @@ -36,6 +36,11 @@ struct Tileset /*0x14*/ TilesetCB callback; }; +// Tilesets do not actually have s strict width. +// This constant is simply used for the offset between rows of metatiles for +// large tiles, such as the Battle Pike's curtain tile. +#define TILESET_WIDTH 8 + struct MapLayout { /*0x00*/ s32 width; diff --git a/src/field_specials.c b/src/field_specials.c index ab02f9938..17790532b 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -3931,13 +3931,18 @@ static void Task_LoopWingFlapSE(u8 taskId) #undef playCount #undef delay +#define CURTAIN_HEIGHT 4 +#define CURTAIN_WIDTH 3 +#define tFrameTimer data +#define tCurrentFrame data[3] + void CloseBattlePikeCurtain(void) { u8 taskId = CreateTask(Task_CloseBattlePikeCurtain, 8); - gTasks[taskId].data[0] = 4; - gTasks[taskId].data[1] = 4; - gTasks[taskId].data[2] = 4; - gTasks[taskId].data[3] = 0; + gTasks[taskId].tFrameTimer[0] = 4; + gTasks[taskId].tFrameTimer[1] = 4; + gTasks[taskId].tFrameTimer[2] = 4; + gTasks[taskId].tCurrentFrame = 0; } static void Task_CloseBattlePikeCurtain(u8 taskId) @@ -3945,19 +3950,21 @@ static void Task_CloseBattlePikeCurtain(u8 taskId) u8 x, y; s16 *data = gTasks[taskId].data; - data[data[3]]--; - if (data[data[3]] == 0) + tFrameTimer[tCurrentFrame]--; + if (tFrameTimer[tCurrentFrame] == 0) { - for (y = 0; y < 4; y++) + for (y = 0; y < CURTAIN_HEIGHT; y++) { - for (x = 0; x < 3; x++) + for (x = 0; x < CURTAIN_WIDTH; x++) { - MapGridSetMetatileIdAt(gSaveBlock1Ptr->pos.x + x + 6, gSaveBlock1Ptr->pos.y + y + 4, x + 513 + y * 8 + data[3] * 32); + MapGridSetMetatileIdAt(gSaveBlock1Ptr->pos.x + x + MAP_OFFSET - 1, + gSaveBlock1Ptr->pos.y + y + MAP_OFFSET - 3, + (x + METATILE_BattlePike_CurtainFrames_Start) + (y * TILESET_WIDTH) + (tCurrentFrame * CURTAIN_HEIGHT * TILESET_WIDTH)); } } DrawWholeMapView(); - data[3]++; - if (data[3] == 3) + tCurrentFrame++; + if (tCurrentFrame == 3) { DestroyTask(taskId); EnableBothScriptContexts(); @@ -3965,6 +3972,11 @@ static void Task_CloseBattlePikeCurtain(u8 taskId) } } +#undef CURTAIN_HEIGHT +#undef CURTAIN_WIDTH +#undef tFrameTimer +#undef tCurrentFrame + void GetBattlePyramidHint(void) { gSpecialVar_Result = gSpecialVar_0x8004 / 7; From 0637910f5856ea0ee0e877f81c57150f7101d419 Mon Sep 17 00:00:00 2001 From: sphericalice Date: Mon, 25 Oct 2021 18:07:46 +0100 Subject: [PATCH 2/4] Use the TILESET_WIDTH constant in rotating_tile_puzzle.c --- src/rotating_tile_puzzle.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rotating_tile_puzzle.c b/src/rotating_tile_puzzle.c index 56be9736f..b8dd03f9e 100644 --- a/src/rotating_tile_puzzle.c +++ b/src/rotating_tile_puzzle.c @@ -134,14 +134,14 @@ u16 MoveRotatingTileObjects(u8 puzzleNumber) continue; // Object is on a metatile after the puzzle tile section (never occurs, in both cases the puzzle tiles are last) - if ((u8)((metatile - puzzleTileStart) / 8) >= 5) + if ((u8)((metatile - puzzleTileStart) / TILESET_WIDTH) >= 5) continue; // Object is on a metatile in puzzle tile section, but not one of the currently rotating color - if ((u8)((metatile - puzzleTileStart) / 8) != puzzleNumber) + if ((u8)((metatile - puzzleTileStart) / TILESET_WIDTH) != puzzleNumber) continue; - puzzleTileNum = (u8)((metatile - puzzleTileStart) % 8); + puzzleTileNum = (u8)((metatile - puzzleTileStart) % TILESET_WIDTH); // First 4 puzzle tiles are the colored arrows if (puzzleTileNum < 4) @@ -221,7 +221,7 @@ void TurnRotatingTileObjects(void) // prevPuzzleTileNum will similarly be a number [0-3] representing the arrow tile the object just moved from // All the puzzles are oriented counter-clockwise and can only move 1 step at a time, so the difference between the current tile and the previous tile will always either be -1 or 3 (0-1, 1-2, 2-3, 3-0) // Which means tileDifference will always either be -1 or 3 after the below subtraction, and rotation will always be ROTATE_COUNTERCLOCKWISE after the following conditionals - tileDifference = (u8)((metatile - puzzleTileStart) % 8); + tileDifference = (u8)((metatile - puzzleTileStart) % TILESET_WIDTH); tileDifference -= (sRotatingTilePuzzle->objects[i].prevPuzzleTileNum); // Always true, see above @@ -331,7 +331,7 @@ static void TurnUnsavedRotatingTileObject(u8 eventTemplateId, u8 puzzleTileNum) else puzzleTileStart = METATILE_TrickHousePuzzle_Arrow_YellowOnWhite_Right; - tileDifference = (u8)((metatile - puzzleTileStart) % 8); + tileDifference = (u8)((metatile - puzzleTileStart) % TILESET_WIDTH); tileDifference -= puzzleTileNum; if (tileDifference < 0 || tileDifference == 3) From 5bce17cbcee66842b33e1c46c2a71684ee8093fb Mon Sep 17 00:00:00 2001 From: sphericalice Date: Mon, 25 Oct 2021 18:11:06 +0100 Subject: [PATCH 3/4] Fix typo in the TILESET_WIDTH comment --- include/global.fieldmap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/global.fieldmap.h b/include/global.fieldmap.h index a1e752415..5c673fc45 100644 --- a/include/global.fieldmap.h +++ b/include/global.fieldmap.h @@ -36,7 +36,7 @@ struct Tileset /*0x14*/ TilesetCB callback; }; -// Tilesets do not actually have s strict width. +// Tilesets do not actually have a strict width. // This constant is simply used for the offset between rows of metatiles for // large tiles, such as the Battle Pike's curtain tile. #define TILESET_WIDTH 8 From 7b5267c799579047ac012928024ce92918c541fe Mon Sep 17 00:00:00 2001 From: sphericalice Date: Mon, 25 Oct 2021 20:51:04 +0100 Subject: [PATCH 4/4] Rename TILESET_WIDTH to METATILE_ROW_WIDTH --- include/global.fieldmap.h | 10 +++++----- src/field_specials.c | 2 +- src/rotating_tile_puzzle.c | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/global.fieldmap.h b/include/global.fieldmap.h index 5c673fc45..5d788ddf7 100644 --- a/include/global.fieldmap.h +++ b/include/global.fieldmap.h @@ -11,6 +11,11 @@ #define METATILE_ID(tileset, name) (METATILE_##tileset##_##name) +// Rows of metatiles do not actually have a strict width. +// This constant is used for calculations for finding the next row of metatiles +// for constructing large tiles, such as the Battle Pike's curtain tile. +#define METATILE_ROW_WIDTH 8 + enum { CONNECTION_INVALID = -1, @@ -36,11 +41,6 @@ struct Tileset /*0x14*/ TilesetCB callback; }; -// Tilesets do not actually have a strict width. -// This constant is simply used for the offset between rows of metatiles for -// large tiles, such as the Battle Pike's curtain tile. -#define TILESET_WIDTH 8 - struct MapLayout { /*0x00*/ s32 width; diff --git a/src/field_specials.c b/src/field_specials.c index 17790532b..53e1e7fb7 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -3959,7 +3959,7 @@ static void Task_CloseBattlePikeCurtain(u8 taskId) { MapGridSetMetatileIdAt(gSaveBlock1Ptr->pos.x + x + MAP_OFFSET - 1, gSaveBlock1Ptr->pos.y + y + MAP_OFFSET - 3, - (x + METATILE_BattlePike_CurtainFrames_Start) + (y * TILESET_WIDTH) + (tCurrentFrame * CURTAIN_HEIGHT * TILESET_WIDTH)); + (x + METATILE_BattlePike_CurtainFrames_Start) + (y * METATILE_ROW_WIDTH) + (tCurrentFrame * CURTAIN_HEIGHT * METATILE_ROW_WIDTH)); } } DrawWholeMapView(); diff --git a/src/rotating_tile_puzzle.c b/src/rotating_tile_puzzle.c index b8dd03f9e..2e919f550 100644 --- a/src/rotating_tile_puzzle.c +++ b/src/rotating_tile_puzzle.c @@ -134,14 +134,14 @@ u16 MoveRotatingTileObjects(u8 puzzleNumber) continue; // Object is on a metatile after the puzzle tile section (never occurs, in both cases the puzzle tiles are last) - if ((u8)((metatile - puzzleTileStart) / TILESET_WIDTH) >= 5) + if ((u8)((metatile - puzzleTileStart) / METATILE_ROW_WIDTH) >= 5) continue; // Object is on a metatile in puzzle tile section, but not one of the currently rotating color - if ((u8)((metatile - puzzleTileStart) / TILESET_WIDTH) != puzzleNumber) + if ((u8)((metatile - puzzleTileStart) / METATILE_ROW_WIDTH) != puzzleNumber) continue; - puzzleTileNum = (u8)((metatile - puzzleTileStart) % TILESET_WIDTH); + puzzleTileNum = (u8)((metatile - puzzleTileStart) % METATILE_ROW_WIDTH); // First 4 puzzle tiles are the colored arrows if (puzzleTileNum < 4) @@ -221,7 +221,7 @@ void TurnRotatingTileObjects(void) // prevPuzzleTileNum will similarly be a number [0-3] representing the arrow tile the object just moved from // All the puzzles are oriented counter-clockwise and can only move 1 step at a time, so the difference between the current tile and the previous tile will always either be -1 or 3 (0-1, 1-2, 2-3, 3-0) // Which means tileDifference will always either be -1 or 3 after the below subtraction, and rotation will always be ROTATE_COUNTERCLOCKWISE after the following conditionals - tileDifference = (u8)((metatile - puzzleTileStart) % TILESET_WIDTH); + tileDifference = (u8)((metatile - puzzleTileStart) % METATILE_ROW_WIDTH); tileDifference -= (sRotatingTilePuzzle->objects[i].prevPuzzleTileNum); // Always true, see above @@ -331,7 +331,7 @@ static void TurnUnsavedRotatingTileObject(u8 eventTemplateId, u8 puzzleTileNum) else puzzleTileStart = METATILE_TrickHousePuzzle_Arrow_YellowOnWhite_Right; - tileDifference = (u8)((metatile - puzzleTileStart) % TILESET_WIDTH); + tileDifference = (u8)((metatile - puzzleTileStart) % METATILE_ROW_WIDTH); tileDifference -= puzzleTileNum; if (tileDifference < 0 || tileDifference == 3)