void CK6_MapMiscFlagsCheck(CK_object *obj) { if (obj->user3 == 0) { int tileX = obj->clipRects.tileXmid; int tileY = RF_UnitToTile(obj->clipRects.unitY1 + (obj->clipRects.unitY2 - obj->clipRects.unitY1)/2); uint16_t tile = CA_TileAtPos(tileX, tileY, 1); uint8_t miscValue = TI_ForeMisc(tile); if (miscValue == MISCFLAG_TELEPORT) CK_AnimateMapTeleporter(tileX, tileY); } }
void CK6_ToggleBigSwitch(CK_object *obj, bool dir) { // Replace switch tiles int ty = dir ? obj->clipRects.tileY2 : obj->clipRects.tileY1 - 2; int tx = obj->clipRects.tileX1 - 1; uint16_t *infoTile = CA_TilePtrAtPos(tx + 1, ty + 1, 2); while (!*infoTile) { tx++; infoTile++; } uint16_t *fgTile = CA_TilePtrAtPos(tx, ty, 1); uint16_t tile_array[6]; for (int y = 0; y < 3; y++) { for (int x = 0; x < 2; x++) { tile_array[2 * y + x] = *fgTile + TI_ForeAnimTile(*fgTile); fgTile++; } fgTile += CA_GetMapWidth() - 2; } RF_ReplaceTiles(tile_array, 1, tx, ty, 2, 3); // Apply the switch effect infoTile = CA_TilePtrAtPos(tx + 1, ty + 1, 2); int destX = *infoTile >> 8; int destY = *infoTile & 0xFF; SD_PlaySound(SOUND_KEENOUTOFAMMO); infoTile = CA_TilePtrAtPos(destX, destY, 2); if (*infoTile >= 0x5B && *infoTile < 0x5B + 8) { // Toggle a goplat arrow static uint16_t infoPlaneInverses[8] = {2, 3, 0, 1, 6, 7, 4, 5}; *infoTile = infoPlaneInverses[(*infoTile - 0x5B)] + 0x5B; } else { fgTile = CA_TilePtrAtPos(destX, destY, 1); int miscValue = TI_ForeMisc(*fgTile) & 0x7F; if (miscValue == MISCFLAG_ACTIVEZAPPER) { uint16_t start = CA_TileAtPos(0, 0, 1); uint16_t mid = CA_TileAtPos(1, 0, 1); uint16_t end = CA_TileAtPos(2, 0, 1); RF_ReplaceTiles(&start, 1, destX, destY, 1, 1); destY++; while (TI_ForeMisc(CA_TileAtPos(destX, destY, 1)) == MISCFLAG_DEADLY) { RF_ReplaceTiles(&mid, 1, destX, destY, 1, 1); destY++; } RF_ReplaceTiles(&end, 1, destX, destY, 1, 1); } else if (miscValue == MISCFLAG_INACTIVEZAPPER) { uint16_t start = CA_TileAtPos(3, 0, 1); uint16_t mid = CA_TileAtPos(4, 0, 1); uint16_t end = CA_TileAtPos(5, 0, 1); RF_ReplaceTiles(&start, 1, destX, destY, 1, 1); destY++; while (TI_ForeMisc(CA_TileAtPos(destX, destY, 1)) != MISCFLAG_INACTIVEZAPPER) { RF_ReplaceTiles(&mid, 1, destX, destY, 1, 1); destY++; } RF_ReplaceTiles(&end, 1, destX, destY, 1, 1); } else if (miscValue == MISCFLAG_BRIDGE) { for (int y = destY; y < destY + 2; ++y) { for (int x = destX - ((y == destY) ? 0 : 1); x < CA_GetMapWidth(); ++x) { uint16_t currentTile = CA_TileAtPos(x, y, 1); if (!TI_ForeAnimTile(currentTile)) break; uint16_t newTile = currentTile + TI_ForeAnimTile(currentTile); RF_ReplaceTiles(&newTile, 1, x, y, 1, 1); } } } else { // Toggle a B block *infoTile ^= 0x1F; } } }