From 120e75d275988c5d723ac827e141d4ea5195e461 Mon Sep 17 00:00:00 2001 From: sphericalice Date: Mon, 25 Oct 2021 18:03:14 +0100 Subject: [PATCH] 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;