X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fgame_mm%2Fmm_game.c;h=8e45cfb8da103fe66817e20deaba290ff3a2d47a;hp=0e9496e6c1fb8696ee6b92a23c40eaf176fa8486;hb=645b5ff6bb70e1caf8cd6b8be4747d24cf93f527;hpb=7921b0b5a961cf321de9e4da14626d268be55d5c diff --git a/src/game_mm/mm_game.c b/src/game_mm/mm_game.c index 0e9496e6..8e45cfb8 100644 --- a/src/game_mm/mm_game.c +++ b/src/game_mm/mm_game.c @@ -9,6 +9,8 @@ // mm_game.c // ============================================================================ +#include + #include "main_mm.h" #include "mm_main.h" @@ -355,7 +357,7 @@ static boolean CheckLaserPixel(int x, int y) return (pixel == WHITE_PIXEL); } -static void CheckExitMM() +static void CheckExitMM(void) { int exit_element = EL_EMPTY; int exit_x = 0; @@ -515,7 +517,7 @@ static void InitField(int x, int y, boolean init_game) } } -static void InitCycleElements_RotateSingleStep() +static void InitCycleElements_RotateSingleStep(void) { int i; @@ -540,7 +542,7 @@ static void InitCycleElements_RotateSingleStep() } } -static void InitLaser() +static void InitLaser(void) { int start_element = Feld[laser.start_edge.x][laser.start_edge.y]; int step = (IS_LASER(start_element) ? 4 : 0); @@ -578,7 +580,7 @@ static void InitLaser() native_mm_level.laser_blue * 0xFF); } -void InitGameEngine_MM() +void InitGameEngine_MM(void) { int i, x, y; @@ -665,7 +667,7 @@ void InitGameEngine_MM() DrawLevel_MM(); } -void InitGameActions_MM() +void InitGameActions_MM(void) { int num_init_game_frames = INIT_GAME_ACTIONS_DELAY; int cycle_steps_done = 0; @@ -742,19 +744,25 @@ void InitGameActions_MM() if (game_mm.kettles_still_needed == 0) CheckExitMM(); + + SetTileCursorXY(laser.start_edge.x, laser.start_edge.y); + SetTileCursorActive(TRUE); } void AddLaserEdge(int lx, int ly) { - if (lx < -2 || ly < -2 || lx >= SXSIZE + 2 || ly >= SYSIZE + 2) + int clx = dSX + lx; + int cly = dSY + ly; + + if (clx < -2 || cly < -2 || clx >= SXSIZE + 2 || cly >= SYSIZE + 2) { Error(ERR_WARN, "AddLaserEdge: out of bounds: %d, %d", lx, ly); return; } - laser.edge[laser.num_edges].x = SX + 2 + lx; - laser.edge[laser.num_edges].y = SY + 2 + ly; + laser.edge[laser.num_edges].x = cSX2 + lx; + laser.edge[laser.num_edges].y = cSY2 + ly; laser.num_edges++; laser.redraw = TRUE; @@ -770,14 +778,14 @@ void AddDamagedField(int ex, int ey) laser.num_damages++; } -boolean StepBehind() +static boolean StepBehind(void) { if (laser.num_edges) { int x = LX - XS; int y = LY - YS; - int last_x = laser.edge[laser.num_edges - 1].x - SX - 2; - int last_y = laser.edge[laser.num_edges - 1].y - SY - 2; + int last_x = laser.edge[laser.num_edges - 1].x - cSX2; + int last_y = laser.edge[laser.num_edges - 1].y - cSY2; return ((x - last_x) * XS < 0 || (y - last_y) * YS < 0); } @@ -797,7 +805,7 @@ static int getMaskFromElement(int element) return IMG_MM_MASK_CIRCLE; } -int ScanPixel() +static int ScanPixel(void) { int hit_mask = 0; @@ -855,8 +863,8 @@ int ScanPixel() } else { - pixel = (SX + px < REAL_SX || SX + px >= REAL_SX + FULL_SXSIZE || - SY + py < REAL_SY || SY + py >= REAL_SY + FULL_SYSIZE); + pixel = (cSX + px < REAL_SX || cSX + px >= REAL_SX + FULL_SXSIZE || + cSY + py < REAL_SY || cSY + py >= REAL_SY + FULL_SYSIZE); } if ((Sign[laser.current_angle] & (1 << i)) && pixel) @@ -874,7 +882,7 @@ int ScanPixel() return hit_mask; } -void ScanLaser() +void ScanLaser(void) { int element; int end = 0, rf = laser.num_edges; @@ -1061,7 +1069,7 @@ void ScanLaser() #endif } -void DrawLaserExt(int start_edge, int num_edges, int mode) +static void DrawLaserExt(int start_edge, int num_edges, int mode) { int element; int elx, ely; @@ -1186,8 +1194,8 @@ void DrawLaserExt(int start_edge, int num_edges, int mode) if (start_edge == 0) laser.current_angle = laser.start_angle; - LX = laser.edge[start_edge].x - (SX + 2); - LY = laser.edge[start_edge].y - (SY + 2); + LX = laser.edge[start_edge].x - cSX2; + LY = laser.edge[start_edge].y - cSY2; XS = 2 * Step[laser.current_angle].x; YS = 2 * Step[laser.current_angle].y; @@ -1334,7 +1342,7 @@ void DrawLaser(int start_edge, int mode) game_mm.laser_enabled = mode; } -void DrawLaser_MM() +void DrawLaser_MM(void) { DrawLaser(0, game_mm.laser_enabled); } @@ -1536,6 +1544,8 @@ boolean HitElement(int element, int hit_mask) if (game_mm.kettles_still_needed > 0) game_mm.kettles_still_needed--; + game.snapshot.collected_item = TRUE; + if (game_mm.kettles_still_needed == 0) { CheckExitMM(); @@ -1963,8 +1973,12 @@ boolean HitLaserDestination(int element, int hit_mask) AddDamagedField(ELX, ELY); if (game_mm.lights_still_needed == 0) + { game_mm.level_solved = TRUE; + SetTileCursorActive(FALSE); + } + return TRUE; } @@ -2272,7 +2286,7 @@ boolean HitAbsorbingWalls(int element, int hit_mask) return TRUE; } -void OpenExit(int x, int y) +static void OpenExit(int x, int y) { int delay = 6; @@ -2297,7 +2311,7 @@ void OpenExit(int x, int y) } } -void OpenSurpriseBall(int x, int y) +static void OpenSurpriseBall(int x, int y) { int delay = 2; @@ -2318,7 +2332,7 @@ void OpenSurpriseBall(int x, int y) getGraphicSource(graphic, 0, &bitmap, &gx, &gy); BlitBitmap(bitmap, drawto, gx + dx, gy + dy, 6, 6, - SX + x * TILEX + dx, SY + y * TILEY + dy); + cSX + x * TILEX + dx, cSY + y * TILEY + dy); MarkTileDirty(x, y); } @@ -2334,7 +2348,7 @@ void OpenSurpriseBall(int x, int y) } } -void MeltIce(int x, int y) +static void MeltIce(int x, int y) { int frames = 5; int delay = 5; @@ -2383,7 +2397,7 @@ void MeltIce(int x, int y) } } -void GrowAmoeba(int x, int y) +static void GrowAmoeba(int x, int y) { int frames = 5; int delay = 1; @@ -2472,11 +2486,15 @@ static void Explode_MM(int x, int y, int phase, int mode) game_mm.game_over = TRUE; game_mm.game_over_cause = GAME_OVER_BOMB; + SetTileCursorActive(FALSE); + laser.overloaded = FALSE; } else if (IS_MCDUFFIN(Store[x][y])) { Store[x][y] = EL_EMPTY; + + game.restart_game_message = "Bomb killed Mc Duffin! Play it again?"; } Feld[x][y] = Store[x][y]; @@ -2525,7 +2543,7 @@ static void Explode_MM(int x, int y, int phase, int mode) getGraphicSource(graphic, graphic_phase, &bitmap, &src_x, &src_y); BlitBitmap(bitmap, drawto_field, src_x, src_y, TILEX, TILEY, - FX + x * TILEX, FY + y * TILEY); + cFX + x * TILEX, cFY + y * TILEY); MarkTileDirty(x, y); } @@ -2720,11 +2738,12 @@ static void ContinueMoving_MM(int x, int y) laser.redraw = TRUE; } -void ClickElement(int x, int y, int button) +boolean ClickElement(int x, int y, int button) { static unsigned int click_delay = 0; static int click_delay_value = CLICK_DELAY; static boolean new_button = TRUE; + boolean element_clicked = FALSE; int element; if (button == -1) @@ -2734,12 +2753,12 @@ void ClickElement(int x, int y, int button) click_delay_value = CLICK_DELAY; new_button = TRUE; - return; + return FALSE; } /* do not rotate objects hit by the laser after the game was solved */ if (game_mm.level_solved && Hit[x][y]) - return; + return FALSE; if (button == MB_RELEASED) { @@ -2749,20 +2768,20 @@ void ClickElement(int x, int y, int button) /* release eventually hold auto-rotating mirror */ RotateMirror(x, y, MB_RELEASED); - return; + return FALSE; } if (!FrameReached(&click_delay, click_delay_value) && !new_button) - return; + return FALSE; if (button == MB_MIDDLEBUTTON) /* middle button has no function */ - return; + return FALSE; if (!IN_LEV_FIELD(x, y)) - return; + return FALSE; if (Feld[x][y] == EL_EMPTY) - return; + return FALSE; element = Feld[x][y]; @@ -2774,6 +2793,8 @@ void ClickElement(int x, int y, int button) IS_DF_MIRROR_AUTO(element)) { RotateMirror(x, y, button); + + element_clicked = TRUE; } else if (IS_MCDUFFIN(element)) { @@ -2800,17 +2821,21 @@ void ClickElement(int x, int y, int button) if (!laser.fuse_off) ScanLaser(); + + element_clicked = TRUE; } else if (element == EL_FUSE_ON && laser.fuse_off) { if (x != laser.fuse_x || y != laser.fuse_y) - return; + return FALSE; laser.fuse_off = FALSE; laser.fuse_x = laser.fuse_y = -1; DrawGraphic_MM(x, y, IMG_MM_FUSE_ACTIVE); ScanLaser(); + + element_clicked = TRUE; } else if (element == EL_FUSE_ON && !laser.fuse_off && new_button) { @@ -2821,16 +2846,22 @@ void ClickElement(int x, int y, int button) DrawLaser(0, DL_LASER_DISABLED); DrawGraphic_MM(x, y, IMG_MM_FUSE); + + element_clicked = TRUE; } else if (element == EL_LIGHTBALL) { Bang_MM(x, y); RaiseScoreElement_MM(element); DrawLaser(0, DL_LASER_ENABLED); + + element_clicked = TRUE; } click_delay_value = (new_button ? CLICK_DELAY_FIRST : CLICK_DELAY); new_button = FALSE; + + return element_clicked; } void RotateMirror(int x, int y, int button) @@ -2928,7 +2959,7 @@ void RotateMirror(int x, int y, int button) } } -void AutoRotateMirrors() +static void AutoRotateMirrors(void) { int x, y; @@ -2963,24 +2994,24 @@ boolean ObjHit(int obx, int oby, int bits) if (bits & HIT_POS_CENTER) { - if (CheckLaserPixel(SX + obx + 15, - SY + oby + 15)) + if (CheckLaserPixel(cSX + obx + 15, + cSY + oby + 15)) return TRUE; } if (bits & HIT_POS_EDGE) { for (i = 0; i < 4; i++) - if (CheckLaserPixel(SX + obx + 31 * (i % 2), - SY + oby + 31 * (i / 2))) + if (CheckLaserPixel(cSX + obx + 31 * (i % 2), + cSY + oby + 31 * (i / 2))) return TRUE; } if (bits & HIT_POS_BETWEEN) { for (i = 0; i < 4; i++) - if (CheckLaserPixel(SX + 4 + obx + 22 * (i % 2), - SY + 4 + oby + 22 * (i / 2))) + if (CheckLaserPixel(cSX + 4 + obx + 22 * (i % 2), + cSY + 4 + oby + 22 * (i / 2))) return TRUE; } @@ -3153,8 +3184,12 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode) game_mm.game_over = TRUE; game_mm.game_over_cause = GAME_OVER_NO_ENERGY; + SetTileCursorActive(FALSE); + + game.restart_game_message = "Out of magic energy! Play it again?"; + #if 0 - if (Request("Out of magic energy ! Play it again ?", + if (Request("Out of magic energy! Play it again?", REQ_ASK | REQ_STAY_CLOSED)) { InitGame(); @@ -3283,8 +3318,12 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode) game_mm.game_over = TRUE; game_mm.game_over_cause = GAME_OVER_OVERLOADED; + SetTileCursorActive(FALSE); + + game.restart_game_message = "Magic spell hit Mc Duffin! Play it again?"; + #if 0 - if (Request("Magic spell hit Mc Duffin ! Play it again ?", + if (Request("Magic spell hit Mc Duffin! Play it again?", REQ_ASK | REQ_STAY_CLOSED)) { InitGame(); @@ -3328,7 +3367,7 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode) laser.num_edges = 0; Bang_MM(laser.start_edge.x, laser.start_edge.y); - if (Request("Bomb killed Mc Duffin ! Play it again ?", + if (Request("Bomb killed Mc Duffin! Play it again?", REQ_ASK | REQ_STAY_CLOSED)) { InitGame(); @@ -3506,8 +3545,8 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode) /* laser.num_edges--; - LX = laser.edge[laser.num_edges].x - (SX + 2); - LY = laser.edge[laser.num_edges].y - (SY + 2); + LX = laser.edge[laser.num_edges].x - cSX2; + LY = laser.edge[laser.num_edges].y - cSY2; */ for (i = (laser.num_damages > 0 ? laser.num_damages - 1 : 0); i >= 0; i--) @@ -3560,12 +3599,12 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode) { if (laser.wall_mask & (1 << i)) { - if (CheckLaserPixel(SX + ELX * TILEX + 14 + (i % 2) * 2, - SY + ELY * TILEY + 31 * (i / 2))) + if (CheckLaserPixel(cSX + ELX * TILEX + 14 + (i % 2) * 2, + cSY + ELY * TILEY + 31 * (i / 2))) break; - if (CheckLaserPixel(SX + ELX * TILEX + 31 * (i % 2), - SY + ELY * TILEY + 14 + (i / 2) * 2)) + if (CheckLaserPixel(cSX + ELX * TILEX + 31 * (i % 2), + cSY + ELY * TILEY + 14 + (i / 2) * 2)) break; } } @@ -3576,8 +3615,8 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode) { if (laser.wall_mask & (1 << i)) { - if (CheckLaserPixel(SX + ELX * TILEX + 31 * (i % 2), - SY + ELY * TILEY + 31 * (i / 2))) + if (CheckLaserPixel(cSX + ELX * TILEX + 31 * (i % 2), + cSY + ELY * TILEY + 31 * (i / 2))) break; } } @@ -3586,8 +3625,8 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode) if (laser.num_beamers > 0 || k1 < 1 || k2 < 4 || k3 < 4 || - CheckLaserPixel(SX + ELX * TILEX + 14, - SY + ELY * TILEY + 14)) + CheckLaserPixel(cSX + ELX * TILEX + 14, + cSY + ELY * TILEY + 14)) { laser.num_edges = r; laser.num_damages = d; @@ -3729,12 +3768,15 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode) void GameActions_MM(struct MouseActionInfo action, boolean warp_mode) { - ClickElement(action.lx, action.ly, action.button); + boolean element_clicked = ClickElement(action.lx, action.ly, action.button); + boolean button_released = (action.button == MB_RELEASED); GameActions_MM_Ext(action, warp_mode); + + CheckSingleStepMode_MM(element_clicked, button_released); } -void MovePacMen() +void MovePacMen(void) { int mx, my, ox, oy, nx, ny; int element; @@ -3799,8 +3841,8 @@ void MovePacMen() getGraphicSource(graphic, 0, &bitmap, &src_x, &src_y); CT = FrameCounter; - ox = SX + ox * TILEX; - oy = SY + oy * TILEY; + ox = cSX + ox * TILEX; + oy = cSY + oy * TILEY; for (i = 1; i < 33; i += 2) BlitBitmap(bitmap, window, @@ -3839,7 +3881,7 @@ void MovePacMen() } } -void GameWon_MM() +void GameWon_MM(void) { int hi_pos; boolean raise_level = FALSE; @@ -3923,7 +3965,7 @@ void GameWon_MM() CloseDoor(DOOR_CLOSE_1); - Request("Level solved !", REQ_CONFIRM); + Request("Level solved!", REQ_CONFIRM); if (level_nr == leveldir_current->handicap_level) { @@ -3958,7 +4000,7 @@ void GameWon_MM() BackToFront(); } -int NewHiScore_MM() +int NewHiScore_MM(void) { int k, l; int position = -1; @@ -4192,3 +4234,179 @@ void RaiseScoreElement_MM(int element) break; } } + + +/* ------------------------------------------------------------------------- */ +/* Mirror Magic game engine snapshot handling functions */ +/* ------------------------------------------------------------------------- */ + +void SaveEngineSnapshotValues_MM(ListNode **buffers) +{ + int x, y; + + engine_snapshot_mm.game_mm = game_mm; + engine_snapshot_mm.laser = laser; + + for (x = 0; x < MAX_PLAYFIELD_WIDTH; x++) + { + for (y = 0; y < MAX_PLAYFIELD_HEIGHT; y++) + { + engine_snapshot_mm.Ur[x][y] = Ur[x][y]; + engine_snapshot_mm.Hit[x][y] = Hit[x][y]; + engine_snapshot_mm.Box[x][y] = Box[x][y]; + engine_snapshot_mm.Angle[x][y] = Angle[x][y]; + engine_snapshot_mm.Frame[x][y] = Frame[x][y]; + } + } + + engine_snapshot_mm.LX = LX; + engine_snapshot_mm.LY = LY; + engine_snapshot_mm.XS = XS; + engine_snapshot_mm.YS = YS; + engine_snapshot_mm.ELX = ELX; + engine_snapshot_mm.ELY = ELY; + engine_snapshot_mm.CT = CT; + engine_snapshot_mm.Ct = Ct; + + engine_snapshot_mm.last_LX = last_LX; + engine_snapshot_mm.last_LY = last_LY; + engine_snapshot_mm.last_hit_mask = last_hit_mask; + engine_snapshot_mm.hold_x = hold_x; + engine_snapshot_mm.hold_y = hold_y; + engine_snapshot_mm.pacman_nr = pacman_nr; + + engine_snapshot_mm.rotate_delay = rotate_delay; + engine_snapshot_mm.pacman_delay = pacman_delay; + engine_snapshot_mm.energy_delay = energy_delay; + engine_snapshot_mm.overload_delay = overload_delay; +} + +void LoadEngineSnapshotValues_MM(void) +{ + int x, y; + + /* stored engine snapshot buffers already restored at this point */ + + game_mm = engine_snapshot_mm.game_mm; + laser = engine_snapshot_mm.laser; + + for (x = 0; x < MAX_PLAYFIELD_WIDTH; x++) + { + for (y = 0; y < MAX_PLAYFIELD_HEIGHT; y++) + { + Ur[x][y] = engine_snapshot_mm.Ur[x][y]; + Hit[x][y] = engine_snapshot_mm.Hit[x][y]; + Box[x][y] = engine_snapshot_mm.Box[x][y]; + Angle[x][y] = engine_snapshot_mm.Angle[x][y]; + Frame[x][y] = engine_snapshot_mm.Frame[x][y]; + } + } + + LX = engine_snapshot_mm.LX; + LY = engine_snapshot_mm.LY; + XS = engine_snapshot_mm.XS; + YS = engine_snapshot_mm.YS; + ELX = engine_snapshot_mm.ELX; + ELY = engine_snapshot_mm.ELY; + CT = engine_snapshot_mm.CT; + Ct = engine_snapshot_mm.Ct; + + last_LX = engine_snapshot_mm.last_LX; + last_LY = engine_snapshot_mm.last_LY; + last_hit_mask = engine_snapshot_mm.last_hit_mask; + hold_x = engine_snapshot_mm.hold_x; + hold_y = engine_snapshot_mm.hold_y; + pacman_nr = engine_snapshot_mm.pacman_nr; + + rotate_delay = engine_snapshot_mm.rotate_delay; + pacman_delay = engine_snapshot_mm.pacman_delay; + energy_delay = engine_snapshot_mm.energy_delay; + overload_delay = engine_snapshot_mm.overload_delay; + + RedrawPlayfield_MM(); +} + +static int getAngleFromTouchDelta(int dx, int dy, int base) +{ + double pi = 3.141592653; + double rad = atan2((double)-dy, (double)dx); + double rad2 = (rad < 0 ? rad + 2 * pi : rad); + double deg = rad2 * 180.0 / pi; + + return (int)(deg * base / 360.0 + 0.5) % base; +} + +int getButtonFromTouchPosition(int x, int y, int dst_mx, int dst_my) +{ + // calculate start (source) position to be at the middle of the tile + int src_mx = cSX + x * TILESIZE_VAR + TILESIZE_VAR / 2; + int src_my = cSY + y * TILESIZE_VAR + TILESIZE_VAR / 2; + int dx = dst_mx - src_mx; + int dy = dst_my - src_my; + int element; + int base = 16; + int phases = 16; + int angle_old = -1; + int angle_new = -1; + int button = 0; + int i; + + if (!IN_LEV_FIELD(x, y)) + return 0; + + element = Feld[x][y]; + + if (!IS_MCDUFFIN(element) && + !IS_MIRROR(element) && + !IS_BEAMER(element) && + !IS_POLAR(element) && + !IS_POLAR_CROSS(element) && + !IS_DF_MIRROR(element)) + return 0; + + angle_old = get_element_angle(element); + + if (IS_MCDUFFIN(element)) + { + angle_new = (dx > 0 && ABS(dy) < ABS(dx) ? ANG_RAY_RIGHT : + dy < 0 && ABS(dx) < ABS(dy) ? ANG_RAY_UP : + dx < 0 && ABS(dy) < ABS(dx) ? ANG_RAY_LEFT : + dy > 0 && ABS(dx) < ABS(dy) ? ANG_RAY_DOWN : + -1); + } + else if (IS_MIRROR(element) || + IS_DF_MIRROR(element)) + { + for (i = 0; i < laser.num_damages; i++) + { + if (laser.damage[i].x == x && + laser.damage[i].y == y && + ObjHit(x, y, HIT_POS_CENTER)) + { + angle_old = get_mirrored_angle(laser.damage[i].angle, angle_old); + angle_new = getAngleFromTouchDelta(dx, dy, base) % phases; + + break; + } + } + } + + if (angle_new == -1) + { + if (IS_MIRROR(element) || + IS_DF_MIRROR(element) || + IS_POLAR(element)) + base = 32; + + if (IS_POLAR_CROSS(element)) + phases = 4; + + angle_new = getAngleFromTouchDelta(dx, dy, base) % phases; + } + + button = (angle_new == angle_old ? 0 : + (angle_new - angle_old + phases) % phases < (phases / 2) ? + MB_LEFTBUTTON : MB_RIGHTBUTTON); + + return button; +}