X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fgame_mm%2Fmm_game.c;h=b258e374b7f0bbeb868be9b873e831e331394af0;hp=d4a69181a3f608d0c19245d0ed5f13b053468bd7;hb=HEAD;hpb=a476bb35e8b7a41f8bef49d6ffd7ec9478ece646 diff --git a/src/game_mm/mm_game.c b/src/game_mm/mm_game.c index d4a69181..b258e374 100644 --- a/src/game_mm/mm_game.c +++ b/src/game_mm/mm_game.c @@ -97,7 +97,6 @@ static void RaiseScoreElement_MM(int); static void RemoveMovingField_MM(int, int); static void InitMovingField_MM(int, int, int); static void ContinueMoving_MM(int, int); -static void Moving2Blocked_MM(int, int, int *, int *); static void AddLaserEdge(int, int); static void ScanLaser(void); @@ -140,10 +139,14 @@ static DelayCounter overload_delay = { 0 }; #define MM_MASK_GRID_2 5 #define MM_MASK_GRID_3 6 #define MM_MASK_GRID_4 7 -#define MM_MASK_RECTANGLE 8 -#define MM_MASK_CIRCLE 9 +#define MM_MASK_SLOPE_1 8 +#define MM_MASK_SLOPE_2 9 +#define MM_MASK_SLOPE_3 10 +#define MM_MASK_SLOPE_4 11 +#define MM_MASK_RECTANGLE 12 +#define MM_MASK_CIRCLE 13 -#define NUM_MM_MASKS 10 +#define NUM_MM_MASKS 14 // element masks for scanning pixels of MM elements static const char mm_masks[NUM_MM_MASKS][16][16 + 1] = @@ -292,6 +295,78 @@ static const char mm_masks[NUM_MM_MASKS][16][16 + 1] = " XXX XXXX ", " XX XXXXX ", }, + { + " X", + " XX", + " XXX", + " XXXX", + " XXXXX", + " XXXXXX", + " XXXXXXX", + " XXXXXXXX", + " XXXXXXXXX", + " XXXXXXXXXX", + " XXXXXXXXXXX", + " XXXXXXXXXXXX", + " XXXXXXXXXXXXX", + " XXXXXXXXXXXXXX", + " XXXXXXXXXXXXXXX", + "XXXXXXXXXXXXXXXX", + }, + { + "X ", + "XX ", + "XXX ", + "XXXX ", + "XXXXX ", + "XXXXXX ", + "XXXXXXX ", + "XXXXXXXX ", + "XXXXXXXXX ", + "XXXXXXXXXX ", + "XXXXXXXXXXX ", + "XXXXXXXXXXXX ", + "XXXXXXXXXXXXX ", + "XXXXXXXXXXXXXX ", + "XXXXXXXXXXXXXXX ", + "XXXXXXXXXXXXXXXX", + }, + { + "XXXXXXXXXXXXXXXX", + "XXXXXXXXXXXXXXX ", + "XXXXXXXXXXXXXX ", + "XXXXXXXXXXXXX ", + "XXXXXXXXXXXX ", + "XXXXXXXXXXX ", + "XXXXXXXXXX ", + "XXXXXXXXX ", + "XXXXXXXX ", + "XXXXXXX ", + "XXXXXX ", + "XXXXX ", + "XXXX ", + "XXX ", + "XX ", + "X ", + }, + { + "XXXXXXXXXXXXXXXX", + " XXXXXXXXXXXXXXX", + " XXXXXXXXXXXXXX", + " XXXXXXXXXXXXX", + " XXXXXXXXXXXX", + " XXXXXXXXXXX", + " XXXXXXXXXX", + " XXXXXXXXX", + " XXXXXXXX", + " XXXXXXX", + " XXXXXX", + " XXXXX", + " XXXX", + " XXX", + " XX", + " X", + }, { "XXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXX", @@ -339,6 +414,8 @@ static int get_element_angle(int element) IS_LASER(element) || IS_RECEIVER(element)) return 4 * element_phase; + else if (IS_DF_SLOPE(element)) + return 4 + (element_phase % 2) * 8; else return element_phase; } @@ -364,7 +441,7 @@ static void DrawLaserLines(struct XY *points, int num_points, int mode) Pixel pixel_drawto = (mode == DL_LASER_ENABLED ? pen_ray : pen_bg); Pixel pixel_buffer = (mode == DL_LASER_ENABLED ? WHITE_PIXEL : BLACK_PIXEL); - DrawLines(drawto, points, num_points, pixel_drawto); + DrawLines(drawto_mm, points, num_points, pixel_drawto); BEGIN_NO_HEADLESS { @@ -570,6 +647,8 @@ static void InitField(int x, int y, boolean init_game) game_mm.laser_green = native_mm_level.df_laser_green; game_mm.laser_blue = native_mm_level.df_laser_blue; } + + game_mm.has_mcduffin = (IS_MCDUFFIN(element)); } break; @@ -642,8 +721,8 @@ void InitGameEngine_MM(void) BEGIN_NO_HEADLESS { // initialize laser bitmap to current playfield (screen) size - ReCreateBitmap(&laser_bitmap, drawto->width, drawto->height); - ClearRectangle(laser_bitmap, 0, 0, drawto->width, drawto->height); + ReCreateBitmap(&laser_bitmap, drawto_mm->width, drawto_mm->height); + ClearRectangle(laser_bitmap, 0, 0, drawto_mm->width, drawto_mm->height); } END_NO_HEADLESS @@ -662,10 +741,12 @@ void InitGameEngine_MM(void) game_mm.laser_red = FALSE; game_mm.laser_green = FALSE; game_mm.laser_blue = TRUE; + game_mm.has_mcduffin = TRUE; game_mm.level_solved = FALSE; game_mm.game_over = FALSE; game_mm.game_over_cause = 0; + game_mm.game_over_message = NULL; game_mm.laser_overload_value = 0; game_mm.laser_enabled = FALSE; @@ -756,16 +837,24 @@ void InitGameActions_MM(void) AdvanceFrameCounter(); AdvanceGfxFrame(); - DrawLevel_MM(); - - BackToFront(); + if (PendingEscapeKeyEvent()) + continue; #ifdef DEBUG if (setup.quick_doors) continue; #endif + + DrawLevel_MM(); + + BackToFront_MM(); } +#ifdef DEBUG + if (setup.quick_doors) + DrawLevel_MM(); +#endif + ScanLaser(); if (game_mm.kettles_still_needed == 0) @@ -791,7 +880,7 @@ static void FadeOutLaser(void) DrawLaser(0, DL_LASER_ENABLED); - BackToFront(); + BackToFront_MM(); Delay_WithScreenUpdates(50); } @@ -802,31 +891,35 @@ static void FadeOutLaser(void) static void GameOver_MM(int game_over_cause) { - // do not handle game over if request dialog is already active - if (game.request_active) - return; - game_mm.game_over = TRUE; game_mm.game_over_cause = game_over_cause; - - if (setup.ask_on_game_over) - game.restart_game_message = (game_over_cause == GAME_OVER_BOMB ? - "Bomb killed Mc Duffin! Play it again?" : - game_over_cause == GAME_OVER_NO_ENERGY ? - "Out of magic energy! Play it again?" : - game_over_cause == GAME_OVER_OVERLOADED ? - "Magic spell hit Mc Duffin! Play it again?" : - NULL); + game_mm.game_over_message = (game_mm.has_mcduffin ? + (game_over_cause == GAME_OVER_BOMB ? + "Bomb killed Mc Duffin!" : + game_over_cause == GAME_OVER_NO_ENERGY ? + "Out of magic energy!" : + game_over_cause == GAME_OVER_OVERLOADED ? + "Magic spell hit Mc Duffin!" : + NULL) : + (game_over_cause == GAME_OVER_BOMB ? + "Bomb destroyed laser cannon!" : + game_over_cause == GAME_OVER_NO_ENERGY ? + "Out of laser energy!" : + game_over_cause == GAME_OVER_OVERLOADED ? + "Laser beam hit laser cannon!" : + NULL)); SetTileCursorActive(FALSE); } static void AddLaserEdge(int lx, int ly) { - int clx = dSX + lx; - int cly = dSY + ly; + int full_sxsize = MAX(FULL_SXSIZE, lev_fieldx * TILEX); + int full_sysize = MAX(FULL_SYSIZE, lev_fieldy * TILEY); - if (clx < -2 || cly < -2 || clx >= SXSIZE + 2 || cly >= SYSIZE + 2) + // check if laser is still inside visible playfield area (or inside level) + if (cSX + lx < REAL_SX || cSX + lx >= REAL_SX + full_sxsize || + cSY + ly < REAL_SY || cSY + ly >= REAL_SY + full_sysize) { Warn("AddLaserEdge: out of bounds: %d, %d", lx, ly); @@ -874,16 +967,35 @@ static boolean StepBehind(void) static int getMaskFromElement(int element) { - if (IS_GRID(element)) - return MM_MASK_GRID_1 + get_element_phase(element); - else if (IS_MCDUFFIN(element)) + if (IS_MCDUFFIN(element)) return MM_MASK_MCDUFFIN_RIGHT + get_element_phase(element); - else if (IS_RECTANGLE(element) || IS_DF_GRID(element)) + else if (IS_GRID(element)) + return MM_MASK_GRID_1 + get_element_phase(element); + else if (IS_DF_GRID(element)) + return MM_MASK_RECTANGLE; + else if (IS_DF_SLOPE(element)) + return MM_MASK_SLOPE_1 + get_element_phase(element); + else if (IS_RECTANGLE(element)) return MM_MASK_RECTANGLE; else return MM_MASK_CIRCLE; } +static int getPixelFromMask(int pos, int dx, int dy) +{ + return (mm_masks[pos][dy / 2][dx / 2] == 'X' ? 1 : 0); +} + +static int getLevelFromLaserX(int x) +{ + return x / TILEX - (x < 0 ? 1 : 0); // correct negative values +} + +static int getLevelFromLaserY(int y) +{ + return y / TILEY - (y < 0 ? 1 : 0); // correct negative values +} + static int ScanPixel(void) { int hit_mask = 0; @@ -909,14 +1021,34 @@ static int ScanPixel(void) } #endif + // check if laser scan has crossed element boundaries (not just mini tiles) + boolean cross_x = (LX / TILEX != (LX + 2) / TILEX); + boolean cross_y = (LY / TILEY != (LY + 2) / TILEY); + + if (cross_x && cross_y) + { + int elx1 = (LX - XS) / TILEX; + int ely1 = (LY + YS) / TILEY; + int elx2 = (LX + XS) / TILEX; + int ely2 = (LY - YS) / TILEY; + + // add element corners left and right from the laser beam to damage list + + if (IN_LEV_FIELD(elx1, ely1) && Tile[elx1][ely1] != EL_EMPTY) + AddDamagedField(elx1, ely1); + + if (IN_LEV_FIELD(elx2, ely2) && Tile[elx2][ely2] != EL_EMPTY) + AddDamagedField(elx2, ely2); + } + for (i = 0; i < 4; i++) { int px = LX + (i % 2) * 2; int py = LY + (i / 2) * 2; int dx = px % TILEX; int dy = py % TILEY; - int lx = (px + TILEX) / TILEX - 1; // ...+TILEX...-1 to get correct - int ly = (py + TILEY) / TILEY - 1; // negative values! + int lx = getLevelFromLaserX(px); + int ly = getLevelFromLaserY(py); Pixel pixel; if (IN_LEV_FIELD(lx, ly)) @@ -937,11 +1069,12 @@ static int ScanPixel(void) { int pos = getMaskFromElement(element); - pixel = (mm_masks[pos][dy / 2][dx / 2] == 'X' ? 1 : 0); + pixel = getPixelFromMask(pos, dx, dy); } } else { + // check if laser is still inside visible playfield area pixel = (cSX + px < REAL_SX || cSX + px >= REAL_SX + FULL_SXSIZE || cSY + py < REAL_SY || cSY + py >= REAL_SY + FULL_SYSIZE); } @@ -1032,29 +1165,62 @@ static void ScanLaser(void) LX, LY, XS, YS); #endif - // hit something -- check out what it was - ELX = (LX + XS) / TILEX; - ELY = (LY + YS) / TILEY; + // check if laser scan has hit two diagonally adjacent element corners + boolean diag_1 = ((hit_mask & HIT_MASK_DIAGONAL_1) == HIT_MASK_DIAGONAL_1); + boolean diag_2 = ((hit_mask & HIT_MASK_DIAGONAL_2) == HIT_MASK_DIAGONAL_2); + + // check if laser scan has crossed element boundaries (not just mini tiles) + boolean cross_x = (getLevelFromLaserX(LX) != getLevelFromLaserX(LX + 2)); + boolean cross_y = (getLevelFromLaserY(LY) != getLevelFromLaserY(LY + 2)); + + if (cross_x || cross_y) + { + // hit something at next tile -- check out what it was + ELX = getLevelFromLaserX(LX + XS); + ELY = getLevelFromLaserY(LY + YS); + } + else + { + // hit something at same tile -- check out what it was + ELX = getLevelFromLaserX(LX); + ELY = getLevelFromLaserY(LY); + } #if 0 Debug("game:mm:ScanLaser", "hit_mask (1) == '%x' (%d, %d) (%d, %d)", hit_mask, LX, LY, ELX, ELY); #endif - if (!IN_LEV_FIELD(ELX, ELY) || !IN_PIX_FIELD(LX, LY)) + if (!IN_LEV_FIELD(ELX, ELY)) { + // laser next step position + int x = cSX + LX + XS; + int y = cSY + LY + YS; + + // check if next step of laser is still inside visible playfield area + if (x >= REAL_SX && x < REAL_SX + FULL_SXSIZE && + y >= REAL_SY && y < REAL_SY + FULL_SYSIZE) + { + // go on with another step + LX += XS; + LY += YS; + + continue; + } + element = EL_EMPTY; laser.dest_element = element; break; } - if (hit_mask == HIT_MASK_DIAGONAL_1 || hit_mask == HIT_MASK_DIAGONAL_2) + // handle special case of laser hitting two diagonally adjacent elements + // (with or without a third corner element behind these two elements) + if ((diag_1 || diag_2) && cross_x && cross_y) { - // we have hit two diagonally adjacent elements -- compare them - boolean dia_1 = (hit_mask == HIT_MASK_DIAGONAL_1); + // compare the two diagonally adjacent elements int xoffset = 2; - int yoffset = 2 * (dia_1 ? -1 : +1); + int yoffset = 2 * (diag_1 ? -1 : +1); int elx1 = (LX - xoffset) / TILEX; int ely1 = (LY + yoffset) / TILEY; int elx2 = (LX + xoffset) / TILEX; @@ -1072,16 +1238,14 @@ static void ScanLaser(void) } else if (IS_WALL_AMOEBA(e1) || IS_WALL_AMOEBA(e2)) { - if (IS_WALL_AMOEBA(e1) && IS_WALL_AMOEBA(e2)) - use_element_1 = (RND(2) ? TRUE : FALSE); - else if (IS_WALL_AMOEBA(e1)) + // if both tiles match, we can just select the first one + if (IS_WALL_AMOEBA(e1)) use_element_1 = TRUE; } else if (IS_ABSORBING_BLOCK(e1) || IS_ABSORBING_BLOCK(e2)) { - if (IS_ABSORBING_BLOCK(e1) && IS_ABSORBING_BLOCK(e2)) - use_element_1 = (RND(2) ? TRUE : FALSE); - else if (IS_ABSORBING_BLOCK(e1)) + // if both tiles match, we can just select the first one + if (IS_ABSORBING_BLOCK(e1)) use_element_1 = TRUE; } @@ -1523,8 +1687,78 @@ void DrawLaser_MM(void) static boolean HitElement(int element, int hit_mask) { - if (HitOnlyAnEdge(hit_mask)) - return FALSE; + if (IS_DF_SLOPE(element)) + { + // check if laser scan has crossed element boundaries (not just mini tiles) + boolean cross_x = (getLevelFromLaserX(LX) != getLevelFromLaserX(LX + 2)); + boolean cross_y = (getLevelFromLaserY(LY) != getLevelFromLaserY(LY + 2)); + int element_angle = get_element_angle(element); + int mirrored_angle = get_mirrored_angle(laser.current_angle, element_angle); + int opposite_angle = get_opposite_angle(laser.current_angle); + + // check if wall (horizontal or vertical) side of slope was hit + if (hit_mask == HIT_MASK_LEFT || + hit_mask == HIT_MASK_RIGHT || + hit_mask == HIT_MASK_TOP || + hit_mask == HIT_MASK_BOTTOM) + { + boolean hit_slope_corner_in_laser_direction = + ((hit_mask == HIT_MASK_LEFT && (element == EL_DF_SLOPE_01 || + element == EL_DF_SLOPE_02)) || + (hit_mask == HIT_MASK_RIGHT && (element == EL_DF_SLOPE_00 || + element == EL_DF_SLOPE_03)) || + (hit_mask == HIT_MASK_TOP && (element == EL_DF_SLOPE_02 || + element == EL_DF_SLOPE_03)) || + (hit_mask == HIT_MASK_BOTTOM && (element == EL_DF_SLOPE_00 || + element == EL_DF_SLOPE_01))); + + boolean hit_slope_corner_in_laser_direction_double_checked = + (cross_x && cross_y && + laser.current_angle == mirrored_angle && + hit_slope_corner_in_laser_direction); + + // check special case of laser hitting the corner of a slope and another + // element (either wall or another slope), following the diagonal side + // of the slope which has the same angle as the direction of the laser + if (!hit_slope_corner_in_laser_direction_double_checked) + return HitReflectingWalls(element, hit_mask); + } + + // check if an edge was hit while crossing element borders + if (cross_x && cross_y && get_number_of_bits(hit_mask) == 1) + { + // check both sides of potentially diagonal side of slope + int dx1 = (LX + XS) % TILEX; + int dy1 = (LY + YS) % TILEY; + int dx2 = (LX + XS + 2) % TILEX; + int dy2 = (LY + YS + 2) % TILEY; + int pos = getMaskFromElement(element); + + // check if we are entering empty space area after hitting edge + if (!getPixelFromMask(pos, dx1, dy1) && + !getPixelFromMask(pos, dx2, dy2)) + { + // we already know that we hit an edge, but use this function to go on + if (HitOnlyAnEdge(hit_mask)) + return FALSE; + } + } + + // check if laser is reflected by slope by 180° + if (mirrored_angle == opposite_angle) + { + AddDamagedField(LX / TILEX, LY / TILEY); + + laser.overloaded = TRUE; + + return TRUE; + } + } + else + { + if (HitOnlyAnEdge(hit_mask)) + return FALSE; + } if (IS_MOVING(ELX, ELY) || IS_BLOCKED(ELX, ELY)) element = MovingOrBlocked2Element_MM(ELX, ELY); @@ -1544,8 +1778,11 @@ static boolean HitElement(int element, int hit_mask) AddDamagedField(ELX, ELY); + boolean through_center = ((ELX * TILEX + 14 - LX) * YS == + (ELY * TILEY + 14 - LY) * XS); + // this is more precise: check if laser would go through the center - if ((ELX * TILEX + 14 - LX) * YS != (ELY * TILEY + 14 - LY) * XS) + if (!IS_DF_SLOPE(element) && !through_center) { int skip_count = 0; @@ -1616,10 +1853,28 @@ static boolean HitElement(int element, int hit_mask) return TRUE; } - if (!IS_BEAMER(element) && - !IS_FIBRE_OPTIC(element) && - !IS_GRID_WOOD(element) && - element != EL_FUEL_EMPTY) + if (IS_DF_SLOPE(element) && !through_center) + { + int correction = 2; + + if (hit_mask == HIT_MASK_ALL) + { + // laser already inside slope -- go back half step + LX -= XS / 2; + LY -= YS / 2; + + correction = 1; + } + + AddLaserEdge(LX, LY); + + LX -= (ABS(XS) < ABS(YS) ? correction * SIGN(XS) : 0); + LY -= (ABS(YS) < ABS(XS) ? correction * SIGN(YS) : 0); + } + else if (!IS_BEAMER(element) && + !IS_FIBRE_OPTIC(element) && + !IS_GRID_WOOD(element) && + element != EL_FUEL_EMPTY) { #if 0 if ((ELX * TILEX + 14 - LX) * YS == (ELY * TILEY + 14 - LY) * XS) @@ -1640,6 +1895,8 @@ static boolean HitElement(int element, int hit_mask) IS_POLAR_CROSS(element) || IS_DF_MIRROR(element) || IS_DF_MIRROR_AUTO(element) || + IS_DF_MIRROR_FIXED(element) || + IS_DF_SLOPE(element) || element == EL_PRISM || element == EL_REFRACTOR) { @@ -1658,7 +1915,9 @@ static boolean HitElement(int element, int hit_mask) if (IS_MIRROR(element) || IS_MIRROR_FIXED(element) || IS_DF_MIRROR(element) || - IS_DF_MIRROR_AUTO(element)) + IS_DF_MIRROR_AUTO(element) || + IS_DF_MIRROR_FIXED(element) || + IS_DF_SLOPE(element)) laser.current_angle = get_mirrored_angle(laser.current_angle, get_element_angle(element)); @@ -1668,13 +1927,27 @@ static boolean HitElement(int element, int hit_mask) XS = 2 * Step[laser.current_angle].x; YS = 2 * Step[laser.current_angle].y; - if (!IS_22_5_ANGLE(laser.current_angle)) // 90° or 45° angle - step_size = 8; - else - step_size = 4; + if (through_center) + { + // start from center position for all game elements but slope + if (!IS_22_5_ANGLE(laser.current_angle)) // 90° or 45° angle + step_size = 8; + else + step_size = 4; - LX += step_size * XS; - LY += step_size * YS; + LX += step_size * XS; + LY += step_size * YS; + } + else + { + // advance laser position until reaching the next tile (slopes) + while (LX / TILEX == ELX && (LX + 2) / TILEX == ELX && + LY / TILEY == ELY && (LY + 2) / TILEY == ELY) + { + LX += XS; + LY += YS; + } + } // draw sparkles on mirror if ((IS_MIRROR(element) || @@ -1693,6 +1966,68 @@ static boolean HitElement(int element, int hit_mask) (get_opposite_angle(laser.current_angle) == laser.damage[laser.num_damages - 1].angle ? TRUE : FALSE); + if (IS_DF_SLOPE(element)) + { + // handle special cases for slope element + + if (IS_45_ANGLE(laser.current_angle)) + { + int elx, ely; + + elx = getLevelFromLaserX(LX + XS); + ely = getLevelFromLaserY(LY + YS); + + if (IN_LEV_FIELD(elx, ely)) + { + int element_next = Tile[elx][ely]; + + // check if slope is followed by slope with opposite orientation + if (IS_DF_SLOPE(element_next) && ABS(element - element_next) == 2) + laser.overloaded = TRUE; + } + + int nr = element - EL_DF_SLOPE_START; + int dx = (nr == 0 ? (XS > 0 ? TILEX - 1 : -1) : + nr == 1 ? (XS > 0 ? TILEX : 0) : + nr == 2 ? (XS > 0 ? TILEX : 0) : + nr == 3 ? (XS > 0 ? TILEX - 1 : -1) : 0); + int dy = (nr == 0 ? (YS > 0 ? TILEY - 1 : -1) : + nr == 1 ? (YS > 0 ? TILEY - 1 : -1) : + nr == 2 ? (YS > 0 ? TILEY : 0) : + nr == 3 ? (YS > 0 ? TILEY : 0) : 0); + + int px = ELX * TILEX + dx; + int py = ELY * TILEY + dy; + + dx = px % TILEX; + dy = py % TILEY; + + elx = getLevelFromLaserX(px); + ely = getLevelFromLaserY(py); + + if (IN_LEV_FIELD(elx, ely)) + { + int element_side = Tile[elx][ely]; + + // check if end of slope is blocked by other element + if (IS_WALL(element_side) || IS_WALL_CHANGING(element_side)) + { + int pos = dy / MINI_TILEY * 2 + dx / MINI_TILEX; + + if (element & (1 << pos)) + laser.overloaded = TRUE; + } + else + { + int pos = getMaskFromElement(element_side); + + if (getPixelFromMask(pos, dx, dy)) + laser.overloaded = TRUE; + } + } + } + } + return (laser.overloaded ? TRUE : FALSE); } @@ -1995,10 +2330,16 @@ static boolean HitPolarizer(int element, int hit_mask) } else if (IS_GRID_STEEL(element)) { + // may be required if graphics for steel grid redefined + AddDamagedField(ELX, ELY); + return HitReflectingWalls(element, hit_mask); } else // IS_GRID_WOOD { + // may be required if graphics for wooden grid redefined + AddDamagedField(ELX, ELY); + return HitAbsorbingWalls(element, hit_mask); } @@ -2048,11 +2389,9 @@ static boolean HitBlock(int element, int hit_mask) if (element == EL_GATE_STONE || element == EL_GATE_WOOD) { int xs = XS / 2, ys = YS / 2; - int hit_mask_diagonal1 = HIT_MASK_TOPRIGHT | HIT_MASK_BOTTOMLEFT; - int hit_mask_diagonal2 = HIT_MASK_TOPLEFT | HIT_MASK_BOTTOMRIGHT; - if ((hit_mask & hit_mask_diagonal1) == hit_mask_diagonal1 || - (hit_mask & hit_mask_diagonal2) == hit_mask_diagonal2) + if ((hit_mask & HIT_MASK_DIAGONAL_1) == HIT_MASK_DIAGONAL_1 || + (hit_mask & HIT_MASK_DIAGONAL_2) == HIT_MASK_DIAGONAL_2) { laser.overloaded = (element == EL_GATE_STONE); @@ -2091,11 +2430,9 @@ static boolean HitBlock(int element, int hit_mask) if (element == EL_BLOCK_STONE || element == EL_BLOCK_WOOD) { int xs = XS / 2, ys = YS / 2; - int hit_mask_diagonal1 = HIT_MASK_TOPRIGHT | HIT_MASK_BOTTOMLEFT; - int hit_mask_diagonal2 = HIT_MASK_TOPLEFT | HIT_MASK_BOTTOMRIGHT; - if ((hit_mask & hit_mask_diagonal1) == hit_mask_diagonal1 || - (hit_mask & hit_mask_diagonal2) == hit_mask_diagonal2) + if ((hit_mask & HIT_MASK_DIAGONAL_1) == HIT_MASK_DIAGONAL_1 || + (hit_mask & HIT_MASK_DIAGONAL_2) == HIT_MASK_DIAGONAL_2) { laser.overloaded = (element == EL_BLOCK_STONE); @@ -2532,7 +2869,7 @@ static void OpenGrayBall(int x, int y) DrawWalls_MM(x, y, Store[x][y]); // copy wall tile to spare bitmap for "melting" animation - BlitBitmap(drawto, bitmap_db_field, cSX + x * TILEX, cSY + y * TILEY, + BlitBitmap(drawto_mm, bitmap_db_field, cSX + x * TILEX, cSY + y * TILEY, TILEX, TILEY, x * TILEX, y * TILEY); DrawElement_MM(x, y, EL_GRAY_BALL); @@ -2565,7 +2902,7 @@ static void OpenGrayBall(int x, int y) getGraphicSource(graphic, 0, &bitmap, &gx, &gy); } - BlitBitmap(bitmap, drawto, gx + dx, gy + dy, 6, 6, + BlitBitmap(bitmap, drawto_mm, gx + dx, gy + dy, 6, 6, cSX + x * TILEX + dx, cSY + y * TILEY + dy); laser.redraw = TRUE; @@ -2618,7 +2955,7 @@ static void OpenEnvelope(int x, int y) ScanLaser(); - ShowEnvelope_MM(nr); + ShowEnvelope(nr); } } } @@ -2797,11 +3134,9 @@ static void Explode_MM(int x, int y, int phase, int mode) Bang_MM(laser.start_edge.x, laser.start_edge.y); - GameOver_MM(GAME_OVER_DELAYED); - laser.overloaded = FALSE; } - else if (IS_MCDUFFIN(center_element)) + else if (IS_MCDUFFIN(center_element) || IS_LASER(center_element)) { GameOver_MM(GAME_OVER_BOMB); } @@ -2851,26 +3186,28 @@ static void TurnRound(int x, int y) int x, y; } move_xy[] = { - { 0, 0 }, - {-1, 0 }, - {+1, 0 }, - { 0, 0 }, - { 0, -1 }, - { 0, 0 }, { 0, 0 }, { 0, 0 }, - { 0, +1 } + { 0, 0 }, + { -1, 0 }, + { +1, 0 }, + { 0, 0 }, + { 0, -1 }, + { 0, 0 }, { 0, 0 }, { 0, 0 }, + { 0, +1 } }; static struct { int left, right, back; } turn[] = { - { 0, 0, 0 }, + { 0, 0, 0 }, { MV_DOWN, MV_UP, MV_RIGHT }, - { MV_UP, MV_DOWN, MV_LEFT }, - { 0, 0, 0 }, - { MV_LEFT, MV_RIGHT, MV_DOWN }, - { 0,0,0 }, { 0,0,0 }, { 0,0,0 }, - { MV_RIGHT, MV_LEFT, MV_UP } + { MV_UP, MV_DOWN, MV_LEFT }, + { 0, 0, 0 }, + { MV_LEFT, MV_RIGHT, MV_DOWN }, + { 0, 0, 0 }, + { 0, 0, 0 }, + { 0, 0, 0 }, + { MV_RIGHT, MV_LEFT, MV_UP } }; int element = Tile[x][y]; @@ -2918,7 +3255,7 @@ static void StartMoving_MM(int x, int y) // now make next step - Moving2Blocked_MM(x, y, &newx, &newy); // get next screen position + Moving2Blocked(x, y, &newx, &newy); // get next screen position if (element == EL_PACMAN && IN_LEV_FIELD(newx, newy) && IS_EATABLE4PACMAN(Tile[newx][newy]) && @@ -3055,29 +3392,25 @@ boolean ClickElement(int x, int y, int button) } else if (IS_MCDUFFIN(element)) { - if (!laser.fuse_off) - { - DrawLaser(0, DL_LASER_DISABLED); + boolean has_laser = (x == laser.start_edge.x && y == laser.start_edge.y); - /* - BackToFront(); - */ - } + if (has_laser && !laser.fuse_off) + DrawLaser(0, DL_LASER_DISABLED); element = get_rotated_element(element, BUTTON_ROTATION(button)); - laser.start_angle = get_element_angle(element); - - InitLaser(); Tile[x][y] = element; DrawField_MM(x, y); - /* - BackToFront(); - */ + if (has_laser) + { + laser.start_angle = get_element_angle(element); - if (!laser.fuse_off) - ScanLaser(); + InitLaser(); + + if (!laser.fuse_off) + ScanLaser(); + } element_clicked = TRUE; } @@ -3244,7 +3577,11 @@ static void AutoRotateMirrors(void) IS_GRID_WOOD_AUTO(element) || IS_GRID_STEEL_AUTO(element) || element == EL_REFRACTOR) + { RotateMirror(x, y, MB_RIGHTBUTTON); + + laser.redraw = TRUE; + } } } } @@ -3717,7 +4054,7 @@ static void GameActions_MM_Ext(void) UpdateAndDisplayGameControlValues(); - BackToFront(); + BackToFront_MM(); } Tile[ELX][ELY] = laser.dest_element = EL_FUEL_EMPTY; @@ -3816,7 +4153,7 @@ static void MovePacMen(void) } DrawField_MM(nx, ny); - BackToFront(); + BackToFront_MM(); if (!laser.fuse_off) { @@ -3857,35 +4194,6 @@ static void InitMovingField_MM(int x, int y, int direction) Tile[newx][newy] = EL_BLOCKED; } -static void Moving2Blocked_MM(int x, int y, int *goes_to_x, int *goes_to_y) -{ - int direction = MovDir[x][y]; - int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0); - int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0); - - *goes_to_x = newx; - *goes_to_y = newy; -} - -static void Blocked2Moving_MM(int x, int y, - int *comes_from_x, int *comes_from_y) -{ - int oldx = x, oldy = y; - int direction = MovDir[x][y]; - - if (direction == MV_LEFT) - oldx++; - else if (direction == MV_RIGHT) - oldx--; - else if (direction == MV_UP) - oldy++; - else if (direction == MV_DOWN) - oldy--; - - *comes_from_x = oldx; - *comes_from_y = oldy; -} - static int MovingOrBlocked2Element_MM(int x, int y) { int element = Tile[x][y]; @@ -3894,7 +4202,7 @@ static int MovingOrBlocked2Element_MM(int x, int y) { int oldx, oldy; - Blocked2Moving_MM(x, y, &oldx, &oldy); + Blocked2Moving(x, y, &oldx, &oldy); return Tile[oldx][oldy]; } @@ -3911,13 +4219,13 @@ static void RemoveMovingField_MM(int x, int y) if (IS_MOVING(x, y)) { - Moving2Blocked_MM(x, y, &newx, &newy); + Moving2Blocked(x, y, &newx, &newy); if (Tile[newx][newy] != EL_BLOCKED) return; } else if (Tile[x][y] == EL_BLOCKED) { - Blocked2Moving_MM(x, y, &oldx, &oldy); + Blocked2Moving(x, y, &oldx, &oldy); if (!IS_MOVING(oldx, oldy)) return; }