X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ftools.c;h=867ee3c0f394bb2162a9368f474773d615ac1c5a;hb=aacdd16335c68a011fab047272b828792a2a884e;hp=2e627abfb59add5567f933cf395520f9ae63532f;hpb=fa2a77aa4b53bb786e67f35d6c46f759ebe7823d;p=rocksndiamonds.git diff --git a/src/tools.c b/src/tools.c index 2e627abf..867ee3c0 100644 --- a/src/tools.c +++ b/src/tools.c @@ -70,7 +70,7 @@ void SetDrawtoField(int mode) void RedrawPlayfield(boolean force_redraw, int x, int y, int width, int height) { - if (game_status == PLAYING) + if (game_status == GAME_MODE_PLAYING) { if (force_redraw) { @@ -118,7 +118,7 @@ void BackToFront() int x,y; DrawBuffer *buffer = (drawto_field == window ? backbuffer : drawto_field); - if (setup.direct_draw && game_status == PLAYING) + if (setup.direct_draw && game_status == GAME_MODE_PLAYING) redraw_mask &= ~REDRAW_MAIN; if (redraw_mask & REDRAW_TILES && redraw_tiles > REDRAWTILES_THRESHOLD) @@ -130,7 +130,7 @@ void BackToFront() if (redraw_mask == REDRAW_NONE) return; - if (global.fps_slowdown && game_status == PLAYING) + if (global.fps_slowdown && game_status == GAME_MODE_PLAYING) { static boolean last_frame_skipped = FALSE; boolean skip_even_when_not_scrolling = TRUE; @@ -175,7 +175,8 @@ void BackToFront() if (redraw_mask & REDRAW_FIELD) { - if (game_status != PLAYING || redraw_mask & REDRAW_FROM_BACKBUFFER) + if (game_status != GAME_MODE_PLAYING || + redraw_mask & REDRAW_FROM_BACKBUFFER) { BlitBitmap(backbuffer, window, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, REAL_SX, REAL_SY); @@ -243,19 +244,18 @@ void BackToFront() VX+VIDEO_CONTROL_XPOS,VY+VIDEO_CONTROL_YPOS); } } + if (redraw_mask & REDRAW_DOOR_3) BlitBitmap(backbuffer, window, EX, EY, EXSIZE, EYSIZE, EX, EY); + redraw_mask &= ~REDRAW_DOORS; } if (redraw_mask & REDRAW_MICROLEVEL) { - BlitBitmap(backbuffer, window, - MICROLEV_XPOS, MICROLEV_YPOS, MICROLEV_XSIZE, MICROLEV_YSIZE, - MICROLEV_XPOS, MICROLEV_YPOS); - BlitBitmap(backbuffer, window, - SX, MICROLABEL_YPOS, SXSIZE, FONT4_YSIZE, - SX, MICROLABEL_YPOS); + BlitBitmap(backbuffer, window, SX, SY + 10 * TILEY, SXSIZE, 7 * TILEY, + SX, SY + 10 * TILEY); + redraw_mask &= ~REDRAW_MICROLEVEL; } @@ -279,7 +279,7 @@ void BackToFront() info1[0] = '\0'; sprintf(text, "%.1f fps%s", global.frames_per_second, info1); - DrawTextExt(window, SX, SY, text, FS_SMALL, FC_YELLOW); + DrawTextExt(window, SX, SY, text, FONT_TEXT_2, BLIT_OPAQUE); } FlushDisplay(); @@ -362,11 +362,34 @@ void FadeToFront() BackToFront(); } +void SetMainBackgroundImage(int graphic) +{ + SetMainBackgroundBitmap(graphic == IMG_UNDEFINED ? NULL : + graphic_info[graphic].bitmap ? + graphic_info[graphic].bitmap : + graphic_info[IMG_BACKGROUND].bitmap); +} + +void SetDoorBackgroundImage(int graphic) +{ + SetDoorBackgroundBitmap(graphic == IMG_UNDEFINED ? NULL : + graphic_info[graphic].bitmap ? + graphic_info[graphic].bitmap : + graphic_info[IMG_BACKGROUND].bitmap); +} + +void DrawBackground(int dest_x, int dest_y, int width, int height) +{ + ClearRectangleOnBackground(backbuffer, dest_x, dest_y, width, height); + + redraw_mask |= REDRAW_FIELD; +} + void ClearWindow() { - ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); + DrawBackground(REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); - if (setup.soft_scrolling && game_status == PLAYING) + if (setup.soft_scrolling && game_status == GAME_MODE_PLAYING) { ClearRectangle(fieldbuffer, 0, 0, FXSIZE, FYSIZE); SetDrawtoField(DRAW_BUFFERED); @@ -374,46 +397,11 @@ void ClearWindow() else SetDrawtoField(DRAW_BACKBUFFER); - if (setup.direct_draw && game_status == PLAYING) + if (setup.direct_draw && game_status == GAME_MODE_PLAYING) { ClearRectangle(window, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); SetDrawtoField(DRAW_DIRECT); } - - redraw_mask |= REDRAW_FIELD; -} - -static int getGraphicAnimationPhase(int frames, int delay, int mode) -{ - int phase; - - if (mode & ANIM_PINGPONG) - { - int max_anim_frames = 2 * frames - 2; - - phase = (FrameCounter % (delay * max_anim_frames)) / delay; - phase = (phase < frames ? phase : max_anim_frames - phase); - } - else - phase = (FrameCounter % (delay * frames)) / delay; - - if (mode & ANIM_REVERSE) - phase = -phase; - - return phase; -} - -inline int getGraphicAnimationFrame(int graphic, int sync_frame) -{ - /* animation synchronized with global frame counter, not move position */ - if (new_graphic_info[graphic].anim_global_sync || sync_frame < 0) - sync_frame = FrameCounter; - - return getAnimationFrame(new_graphic_info[graphic].anim_frames, - new_graphic_info[graphic].anim_delay, - new_graphic_info[graphic].anim_mode, - new_graphic_info[graphic].anim_start_frame, - sync_frame); } void MarkTileDirty(int x, int y) @@ -438,7 +426,7 @@ void SetBorderElement() { for(x=0; xMovDir; + int action = ACTION_DEFAULT; if (!player->active || !IN_SCR_FIELD(SCREENX(last_jx), SCREENY(last_jy))) return; @@ -492,20 +568,32 @@ void DrawPlayer(struct PlayerInfo *player) if (element == EL_EXPLOSION) return; - /* draw things in the field the player is leaving, if needed */ + action = (player->Pushing ? ACTION_PUSHING : + player->is_digging ? ACTION_DIGGING : + player->is_collecting ? ACTION_COLLECTING : + player->is_moving ? ACTION_MOVING : + player->snapped ? ACTION_SNAPPING : ACTION_DEFAULT); + + InitPlayerGfxAnimation(player, action, move_dir); + + /* ----------------------------------------------------------------------- */ + /* draw things in the field the player is leaving, if needed */ + /* ----------------------------------------------------------------------- */ if (player_is_moving) { - if (Store[last_jx][last_jy] && IS_DRAWABLE(last_element)) + if (Back[last_jx][last_jy] && IS_DRAWABLE(last_element)) { - DrawLevelElement(last_jx, last_jy, Store[last_jx][last_jy]); + DrawLevelElement(last_jx, last_jy, Back[last_jx][last_jy]); - if (last_element == EL_DYNAMITE_ACTIVE) + if (last_element == EL_DYNAMITE_ACTIVE || + last_element == EL_SP_DISK_RED_ACTIVE) DrawDynamite(last_jx, last_jy); else DrawLevelFieldThruMask(last_jx, last_jy); } - else if (last_element == EL_DYNAMITE_ACTIVE) + else if (last_element == EL_DYNAMITE_ACTIVE || + last_element == EL_SP_DISK_RED_ACTIVE) DrawDynamite(last_jx, last_jy); else DrawLevelField(last_jx, last_jy); @@ -530,101 +618,61 @@ void DrawPlayer(struct PlayerInfo *player) if (setup.direct_draw) SetDrawtoField(DRAW_BUFFERED); - /* draw things behind the player, if needed */ + /* ----------------------------------------------------------------------- */ + /* draw things behind the player, if needed */ + /* ----------------------------------------------------------------------- */ - if (Store[jx][jy]) - DrawLevelElement(jx, jy, Store[jx][jy]); - else if (!IS_ACTIVE_BOMB(element)) - DrawLevelField(jx, jy); - else + if (Back[jx][jy]) + DrawLevelElement(jx, jy, Back[jx][jy]); + else if (IS_ACTIVE_BOMB(element)) DrawLevelElement(jx, jy, EL_EMPTY); - - /* draw player himself */ - - if (game.emulation == EMU_SUPAPLEX) + else { - static int last_dir = MV_LEFT; - int action = (player->programmed_action ? player->programmed_action : - player->action); - boolean action_moving = - (player_is_moving || - ((action & (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)) && - !(action & ~(MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)))); - - graphic = IMG_SP_MURPHY; - - if (player->Pushing) - { - if (player->MovDir == MV_LEFT) - graphic = IMG_SP_MURPHY_LEFT_PUSHING; - else if (player->MovDir == MV_RIGHT) - graphic = IMG_SP_MURPHY_RIGHT_PUSHING; - else if (player->MovDir & (MV_UP | MV_DOWN) && last_dir == MV_LEFT) - graphic = IMG_SP_MURPHY_LEFT_PUSHING; - else if (player->MovDir & (MV_UP | MV_DOWN) && last_dir == MV_RIGHT) - graphic = IMG_SP_MURPHY_RIGHT_PUSHING; - } - else if (player->snapped) + if (player_is_moving && GfxElement[jx][jy] != EL_UNDEFINED) { - if (player->MovDir == MV_LEFT) - graphic = IMG_SP_MURPHY_LEFT_SNAPPING; - else if (player->MovDir == MV_RIGHT) - graphic = IMG_SP_MURPHY_RIGHT_SNAPPING; - else if (player->MovDir == MV_UP) - graphic = IMG_SP_MURPHY_UP_SNAPPING; - else if (player->MovDir == MV_DOWN) - graphic = IMG_SP_MURPHY_DOWN_SNAPPING; - } - else if (action_moving) - { - if (player->MovDir == MV_LEFT) - graphic = IMG_SP_MURPHY_LEFT_MOVING; - else if (player->MovDir == MV_RIGHT) - graphic = IMG_SP_MURPHY_RIGHT_MOVING; - else if (player->MovDir & (MV_UP | MV_DOWN) && last_dir == MV_LEFT) - graphic = IMG_SP_MURPHY_LEFT_MOVING; - else if (player->MovDir & (MV_UP | MV_DOWN) && last_dir == MV_RIGHT) - graphic = IMG_SP_MURPHY_RIGHT_MOVING; + if (GfxElement[jx][jy] == EL_SAND) + DrawLevelFieldCrumbledSandDigging(jx, jy, move_dir, player->StepFrame); else - graphic = IMG_SP_MURPHY_LEFT_MOVING; + { + int old_element = GfxElement[jx][jy]; + int old_graphic = el_act_dir2img(old_element, action, move_dir); + int frame = getGraphicAnimationFrame(old_graphic, player->StepFrame); - frame = getGraphicAnimationFrame(graphic, -1); + DrawGraphic(sx, sy, old_graphic, frame); + } } + else + { + GfxElement[jx][jy] = EL_UNDEFINED; - if (player->MovDir == MV_LEFT || player->MovDir == MV_RIGHT) - last_dir = player->MovDir; + DrawLevelField(jx, jy); + } } - else + + /* ----------------------------------------------------------------------- */ + /* draw player himself */ + /* ----------------------------------------------------------------------- */ + + if (player->use_murphy_graphic) { - if (player->MovDir == MV_LEFT) - graphic = (player->Pushing ? IMG_PLAYER1_LEFT_PUSHING : - player->is_moving ? IMG_PLAYER1_LEFT_MOVING : - IMG_PLAYER1_LEFT); - else if (player->MovDir == MV_RIGHT) - graphic = (player->Pushing ? IMG_PLAYER1_RIGHT_PUSHING : - player->is_moving ? IMG_PLAYER1_RIGHT_MOVING : - IMG_PLAYER1_RIGHT); - else if (player->MovDir == MV_UP) - graphic = (player->Pushing ? IMG_PLAYER1_UP_PUSHING : - player->is_moving ? IMG_PLAYER1_UP_MOVING : - IMG_PLAYER1_UP); - else /* MV_DOWN || MV_NO_MOVING */ - graphic = (player->Pushing ? IMG_PLAYER1_DOWN_PUSHING : - player->is_moving ? IMG_PLAYER1_DOWN_MOVING : - IMG_PLAYER1_DOWN); - - graphic = PLAYER_NR_GFX(graphic, player->index_nr); + static int last_horizontal_dir = MV_LEFT; + int direction; -#if 0 - frame = player->Frame; -#else - frame = getGraphicAnimationFrame(graphic, player->Frame); -#endif + if (move_dir == MV_LEFT || move_dir == MV_RIGHT) + last_horizontal_dir = move_dir; + + direction = (player->snapped ? move_dir : last_horizontal_dir); + + graphic = el_act_dir2img(EL_SP_MURPHY, player->GfxAction, direction); } + else + graphic = el_act_dir2img(player->element_nr, player->GfxAction, move_dir); + + frame = getGraphicAnimationFrame(graphic, player->Frame); if (player->GfxPos) { - if (player->MovDir == MV_LEFT || player->MovDir == MV_RIGHT) + if (move_dir == MV_LEFT || move_dir == MV_RIGHT) sxx = player->GfxPos; else syy = player->GfxPos; @@ -633,11 +681,6 @@ void DrawPlayer(struct PlayerInfo *player) if (!setup.soft_scrolling && ScreenMovPos) sxx = syy = 0; -#if 0 - if (player->Frame) - printf("-> %d\n", player->Frame); -#endif - DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, frame, NO_CUTTING); if (SHIELD_ON(player)) @@ -649,53 +692,34 @@ void DrawPlayer(struct PlayerInfo *player) DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, frame, NO_CUTTING); } -#if 0 - if (player->Pushing && player->GfxPos) -#else + /* ----------------------------------------------------------------------- */ + /* draw things the player is pushing, if needed */ + /* ----------------------------------------------------------------------- */ + if (player->Pushing && player_is_moving) -#endif { int px = SCREENX(next_jx), py = SCREENY(next_jy); - if (element == EL_SOKOBAN_FIELD_EMPTY || - Feld[next_jx][next_jy] == EL_SOKOBAN_FIELD_FULL) - DrawGraphicShiftedThruMask(px, py, sxx, syy, GFX_SOKOBAN_OBJEKT, 0, + if ((sxx || syy) && + (element == EL_SOKOBAN_FIELD_EMPTY || + Feld[next_jx][next_jy] == EL_SOKOBAN_FIELD_FULL)) + DrawGraphicShiftedThruMask(px, py, sxx, syy, IMG_SOKOBAN_OBJECT, 0, NO_CUTTING); else { +#if 0 + int element = Feld[jx][jy]; +#else int element = Feld[next_jx][next_jy]; +#endif + int graphic = el2img(element); -#if 1 int frame = 0; -#endif - if ((element == EL_ROCK || - element == EL_BD_ROCK || - element == EL_SP_ZONK) && sxx) + if ((sxx || syy) && IS_PUSHABLE(element)) { - graphic = el_dir_act2img(element, player->MovDir, GFX_ACTION_MOVING); -#if 1 - frame = getGraphicAnimationFrame(graphic, player->GfxPos); - + graphic = el_act_dir2img(element, ACTION_MOVING, move_dir); frame = getGraphicAnimationFrame(graphic, player->Frame); -#endif - -#if 0 - printf("-> %d [%d]\n", player->Frame, player->GfxPos); -#endif - -#if 0 - /* !!! FIX !!! */ - if (player->MovDir == MV_LEFT) - frame = 3 - frame; -#endif - -#if 0 - frame = (player->GfxPos / (TILEX / 4)); - - if (player->MovDir == MV_RIGHT) - frame = (frame + 4) % 4; -#endif } DrawGraphicShifted(px, py, sxx, syy, graphic, frame, @@ -703,55 +727,54 @@ void DrawPlayer(struct PlayerInfo *player) } } - /* draw things in front of player (active dynamite or dynabombs) */ + /* ----------------------------------------------------------------------- */ + /* draw things in front of player (active dynamite or dynabombs) */ + /* ----------------------------------------------------------------------- */ if (IS_ACTIVE_BOMB(element)) { graphic = el2img(element); - -#if 0 - if (element == EL_DYNAMITE_ACTIVE) - { - if ((frame = (96 - MovDelay[jx][jy]) / 12) > 6) - frame = 6; - } - else - { - if ((frame = ((96 - MovDelay[jx][jy]) / 6) % 8) > 3) - frame = 7 - frame; - } -#else - frame = getGraphicAnimationFrame(graphic, 96 - MovDelay[jx][jy]); -#endif + frame = getGraphicAnimationFrame(graphic, GfxFrame[jx][jy]); if (game.emulation == EMU_SUPAPLEX) - DrawGraphic(sx, sy, GFX_SP_DISK_RED, 0); + DrawGraphic(sx, sy, IMG_SP_DISK_RED, frame); else DrawGraphicThruMask(sx, sy, graphic, frame); } if (player_is_moving && last_element == EL_EXPLOSION) { +#if 1 + int graphic = el_act2img(GfxElement[last_jx][last_jy], ACTION_EXPLODING); +#else int stored = Store[last_jx][last_jy]; int graphic = (game.emulation != EMU_SUPAPLEX ? IMG_EXPLOSION : stored == EL_SP_INFOTRON ? IMG_SP_EXPLOSION_INFOTRON : IMG_SP_EXPLOSION); +#endif int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2); - int phase = Frame[last_jx][last_jy] - 1; + int phase = ExplodePhase[last_jx][last_jy] - 1; int frame = getGraphicAnimationFrame(graphic, phase - delay); if (phase >= delay) DrawGraphicThruMask(SCREENX(last_jx), SCREENY(last_jy), graphic, frame); } - /* draw elements that stay over the player */ + /* ----------------------------------------------------------------------- */ + /* draw elements the player is just walking/passing through/under */ + /* ----------------------------------------------------------------------- */ + /* handle the field the player is leaving ... */ - if (player_is_moving && IS_OVER_PLAYER(last_element)) + if (player_is_moving && IS_ACCESSIBLE_INSIDE(last_element)) DrawLevelField(last_jx, last_jy); + else if (player_is_moving && IS_ACCESSIBLE_UNDER(last_element)) + DrawLevelFieldThruMask(last_jx, last_jy); /* ... and the field the player is entering */ - if (IS_OVER_PLAYER(element)) + if (IS_ACCESSIBLE_INSIDE(element)) DrawLevelField(jx, jy); + else if (IS_ACCESSIBLE_UNDER(element)) + DrawLevelFieldThruMask(jx, jy); if (setup.direct_draw) { @@ -768,100 +791,31 @@ void DrawPlayer(struct PlayerInfo *player) MarkTileDirty(sx,sy); } -void DrawGraphicAnimationExt(DrawBuffer *dst_bitmap, int x, int y, - int graphic, int mask_mode) +void getGraphicSource(int graphic, int frame, Bitmap **bitmap, int *x, int *y) { - int frame = getGraphicAnimationFrame(graphic, -1); - - if (mask_mode == USE_MASKING) - DrawGraphicThruMaskExt(dst_bitmap, x, y, graphic, frame); - else - DrawGraphicExt(dst_bitmap, x, y, graphic, frame); -} + struct GraphicInfo *g = &graphic_info[graphic]; -void DrawGraphicAnimation(int x, int y, int graphic) -{ - if (!IN_SCR_FIELD(x, y) || - (FrameCounter % new_graphic_info[graphic].anim_delay) != 0) - return; + *bitmap = g->bitmap; - DrawGraphicAnimationExt(drawto_field, FX + x * TILEX, FY + y * TILEY, - graphic, NO_MASKING); - MarkTileDirty(x, y); -} - -#if 0 -void getOldGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y) -{ - if (graphic >= 0 && graphic_info[graphic].bitmap != NULL) - { - *bitmap = graphic_info[graphic].bitmap; - *x = graphic_info[graphic].src_x; - *y = graphic_info[graphic].src_y; - } - else if (graphic >= GFX_START_ROCKSELEMENTS && - graphic <= GFX_END_ROCKSELEMENTS) - { - graphic -= GFX_START_ROCKSELEMENTS; - *bitmap = new_graphic_info[IMG_OLD_PIX_ELEMENTS].bitmap; - *x = (graphic % GFX_PER_LINE) * TILEX; - *y = (graphic / GFX_PER_LINE) * TILEY; - } - else if (graphic >= GFX_START_ROCKSHEROES && graphic <= GFX_END_ROCKSHEROES) - { - graphic -= GFX_START_ROCKSHEROES; - *bitmap = new_graphic_info[IMG_OLD_PIX_HEROES].bitmap; - *x = (graphic % HEROES_PER_LINE) * TILEX; - *y = (graphic / HEROES_PER_LINE) * TILEY; - } - else if (graphic >= GFX_START_ROCKSSP && graphic <= GFX_END_ROCKSSP) + if (g->offset_y == 0) /* frames are ordered horizontally */ { - graphic -= GFX_START_ROCKSSP; - *bitmap = new_graphic_info[IMG_OLD_PIX_SP].bitmap; - *x = (graphic % SP_PER_LINE) * TILEX; - *y = (graphic / SP_PER_LINE) * TILEY; - } - else if (graphic >= GFX_START_ROCKSDC && graphic <= GFX_END_ROCKSDC) - { - graphic -= GFX_START_ROCKSDC; - *bitmap = new_graphic_info[IMG_OLD_PIX_DC].bitmap; - *x = (graphic % DC_PER_LINE) * TILEX; - *y = (graphic / DC_PER_LINE) * TILEY; + int max_width = g->anim_frames_per_line * g->width; + + *x = (g->src_x + frame * g->offset_x) % max_width; + *y = g->src_y + (g->src_x + frame * g->offset_x) / max_width * g->height; } - else if (graphic >= GFX_START_ROCKSMORE && graphic <= GFX_END_ROCKSMORE) + else if (g->offset_x == 0) /* frames are ordered vertically */ { - graphic -= GFX_START_ROCKSMORE; - *bitmap = new_graphic_info[IMG_OLD_PIX_MORE].bitmap; - *x = (graphic % MORE_PER_LINE) * TILEX; - *y = (graphic / MORE_PER_LINE) * TILEY; + int max_height = g->anim_frames_per_line * g->height; + + *x = g->src_x + (g->src_y + frame * g->offset_y) / max_height * g->width; + *y = (g->src_y + frame * g->offset_y) % max_height; } - else if (graphic >= GFX_START_ROCKSFONT && graphic <= GFX_END_ROCKSFONT) + else /* frames are ordered diagonally */ { - graphic -= GFX_START_ROCKSFONT; - *bitmap = new_graphic_info[IMG_OLD_PIX_FONT_EM].bitmap; - *x = (graphic % FONT_CHARS_PER_LINE) * TILEX; - *y = (graphic / FONT_CHARS_PER_LINE) * TILEY; + *x = g->src_x + frame * g->offset_x; + *y = g->src_y + frame * g->offset_y; } - else - { - *bitmap = new_graphic_info[IMG_OLD_PIX_SP].bitmap; - *x = 0; - *y = 0; - } -} -#endif - -void getGraphicSource(int graphic, int frame, Bitmap **bitmap, int *x, int *y) -{ - Bitmap *src_bitmap = new_graphic_info[graphic].bitmap; - int offset_x = new_graphic_info[graphic].offset_x; - int offset_y = new_graphic_info[graphic].offset_y; - int src_x = new_graphic_info[graphic].src_x + frame * offset_x; - int src_y = new_graphic_info[graphic].src_y + frame * offset_y; - - *bitmap = src_bitmap; - *x = src_x; - *y = src_y; } void DrawGraphic(int x, int y, int graphic, int frame) @@ -899,11 +853,11 @@ void DrawGraphicExt(DrawBuffer *dst_bitmap, int x, int y, int graphic, getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y); #else - Bitmap *src_bitmap = new_graphic_info[graphic].bitmap; - int src_x = new_graphic_info[graphic].src_x; - int src_y = new_graphic_info[graphic].src_y; - int offset_x = new_graphic_info[graphic].offset_x; - int offset_y = new_graphic_info[graphic].offset_y; + Bitmap *src_bitmap = graphic_info[graphic].bitmap; + int src_x = graphic_info[graphic].src_x; + int src_y = graphic_info[graphic].src_y; + int offset_x = graphic_info[graphic].offset_x; + int offset_y = graphic_info[graphic].offset_y; src_x += frame * offset_x; src_y += frame * offset_y; @@ -940,11 +894,11 @@ void DrawGraphicThruMaskExt(DrawBuffer *d, int dest_x, int dest_y, int graphic, drawing_gc = src_bitmap->stored_clip_gc; #else GC drawing_gc = src_bitmap->stored_clip_gc; - Bitmap *src_bitmap = new_graphic_info[graphic].bitmap; - int src_x = new_graphic_info[graphic].src_x; - int src_y = new_graphic_info[graphic].src_y; - int offset_x = new_graphic_info[graphic].offset_x; - int offset_y = new_graphic_info[graphic].offset_y; + Bitmap *src_bitmap = graphic_info[graphic].bitmap; + int src_x = graphic_info[graphic].src_x; + int src_y = graphic_info[graphic].src_y; + int offset_x = graphic_info[graphic].offset_x; + int offset_y = graphic_info[graphic].offset_y; src_x += frame * offset_x; src_y += frame * offset_y; @@ -963,26 +917,13 @@ void DrawMiniGraphic(int x, int y, int graphic) void getMiniGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y) { - Bitmap *src_bitmap = new_graphic_info[graphic].bitmap; + struct GraphicInfo *g = &graphic_info[graphic]; int mini_startx = 0; - int mini_starty = src_bitmap->height * 2 / 3; - int src_x = mini_startx + new_graphic_info[graphic].src_x / 2; - int src_y = mini_starty + new_graphic_info[graphic].src_y / 2; - - if (src_x + MINI_TILEX > src_bitmap->width || - src_y + MINI_TILEY > src_bitmap->height) - { - /* graphic of desired size seems not to be contained in this image; - dirty workaround: get it from the middle of the normal sized image */ - - getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y); - src_x += (TILEX / 2 - MINI_TILEX / 2); - src_y += (TILEY / 2 - MINI_TILEY / 2); - } + int mini_starty = g->bitmap->height * 2 / 3; - *bitmap = src_bitmap; - *x = src_x; - *y = src_y; + *bitmap = g->bitmap; + *x = mini_startx + g->src_x / 2; + *y = mini_starty + g->src_y / 2; } void DrawMiniGraphicExt(DrawBuffer *d, int x, int y, int graphic) @@ -999,11 +940,7 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, int frame, { Bitmap *src_bitmap; GC drawing_gc; - int src_x; - int src_y; - int offset_x; - int offset_y; - + int src_x, src_y; int width = TILEX, height = TILEY; int cx = 0, cy = 0; int dest_x, dest_y; @@ -1078,16 +1015,20 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, int frame, MarkTileDirty(x, y + SIGN(dy)); } - src_bitmap = new_graphic_info[graphic].bitmap; - src_x = new_graphic_info[graphic].src_x; - src_y = new_graphic_info[graphic].src_y; - offset_x = new_graphic_info[graphic].offset_x; - offset_y = new_graphic_info[graphic].offset_y; - - drawing_gc = src_bitmap->stored_clip_gc; +#if 1 + getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y); +#else + src_bitmap = graphic_info[graphic].bitmap; + src_x = graphic_info[graphic].src_x; + src_y = graphic_info[graphic].src_y; + offset_x = graphic_info[graphic].offset_x; + offset_y = graphic_info[graphic].offset_y; src_x += frame * offset_x; src_y += frame * offset_y; +#endif + + drawing_gc = src_bitmap->stored_clip_gc; src_x += cx; src_y += cy; @@ -1117,231 +1058,56 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, int frame, MarkTileDirty(x,y); } -void DrawGraphicShiftedThruMask(int x,int y, int dx,int dy, int graphic, +void DrawGraphicShiftedThruMask(int x, int y, int dx, int dy, int graphic, int frame, int cut_mode) { DrawGraphicShifted(x,y, dx,dy, graphic, frame, cut_mode, USE_MASKING); } -#if 0 void DrawScreenElementExt(int x, int y, int dx, int dy, int element, int cut_mode, int mask_mode) { - int ux = LEVELX(x), uy = LEVELY(y); - int graphic = el2gfx(element); - int phase8 = ABS(MovPos[ux][uy]) / (TILEX / 8); - int phase4 = phase8 / 2; - int phase2 = phase8 / 4; - int dir = MovDir[ux][uy]; - - if (element == EL_PACMAN || element == EL_BUG || element == EL_SPACESHIP) - { - graphic += 1 * !phase2; - - if (dir == MV_UP) - graphic += 1 * 2; - else if (dir == MV_LEFT) - graphic += 2 * 2; - else if (dir == MV_DOWN) - graphic += 3 * 2; - } - else if (element == EL_SP_SNIKSNAK) - { - if (dir == MV_LEFT) - graphic = GFX_SP_SNIKSNAK_LEFT; - else if (dir == MV_RIGHT) - graphic = GFX_SP_SNIKSNAK_RIGHT; - else if (dir == MV_UP) - graphic = GFX_SP_SNIKSNAK_UP; - else - graphic = GFX_SP_SNIKSNAK_DOWN; + int lx = LEVELX(x), ly = LEVELY(y); + int graphic; + int frame; - graphic += (phase8 < 4 ? phase8 : 7 - phase8); - } - else if (element == EL_SP_ELECTRON) - { - graphic = GFX2_SP_ELECTRON + getGraphicAnimationPhase(8, 2, ANIM_LOOP); - } - else if (element == EL_MOLE || element == EL_PENGUIN || - element == EL_PIG || element == EL_DRAGON) + if (IN_LEV_FIELD(lx, ly)) { - if (dir == MV_LEFT) - graphic = (element == EL_MOLE ? GFX_MOLE_LEFT : - element == EL_PENGUIN ? GFX_PINGUIN_LEFT : - element == EL_PIG ? GFX_SCHWEIN_LEFT : GFX_DRACHE_LEFT); - else if (dir == MV_RIGHT) - graphic = (element == EL_MOLE ? GFX_MOLE_RIGHT : - element == EL_PENGUIN ? GFX_PINGUIN_RIGHT : - element == EL_PIG ? GFX_SCHWEIN_RIGHT : GFX_DRACHE_RIGHT); - else if (dir == MV_UP) - graphic = (element == EL_MOLE ? GFX_MOLE_UP : - element == EL_PENGUIN ? GFX_PINGUIN_UP : - element == EL_PIG ? GFX_SCHWEIN_UP : GFX_DRACHE_UP); - else - graphic = (element == EL_MOLE ? GFX_MOLE_DOWN : - element == EL_PENGUIN ? GFX_PINGUIN_DOWN : - element == EL_PIG ? GFX_SCHWEIN_DOWN : GFX_DRACHE_DOWN); + SetRandomAnimationValue(lx, ly); - graphic += phase4; - } - else if (element == EL_SATELLITE) - { - graphic = GFX_SONDE_START + getGraphicAnimationPhase(8, 2, ANIM_LOOP); - } - else if (element == EL_ACID) - { - graphic = GFX_GEBLUBBER + getGraphicAnimationPhase(4, 10, ANIM_LOOP); + graphic = el_act_dir2img(element, GfxAction[lx][ly], MovDir[lx][ly]); + frame = getGraphicAnimationFrame(graphic, GfxFrame[lx][ly]); } - else if (element == EL_BD_BUTTERFLY || element == EL_BD_FIREFLY) + else /* border element */ { - graphic += !phase2; - } - else if (element == EL_BALLOON) - { - graphic += phase4; - } - else if ((element == EL_ROCK || - element == EL_SP_ZONK || - element == EL_BD_ROCK || - element == EL_SP_INFOTRON || - IS_GEM(element)) - && !cut_mode) - { - if (uy >= lev_fieldy-1 || !IS_BELT(Feld[ux][uy+1])) - { - if (element == EL_ROCK || - element == EL_SP_ZONK || - element == EL_BD_ROCK) - { - if (dir == MV_LEFT) - graphic += (4 - phase4) % 4; - else if (dir == MV_RIGHT) - graphic += phase4; - else - graphic += phase2 * 2; - } - else if (element != EL_SP_INFOTRON) - graphic += phase2; - } - } - else if (element == EL_MAGIC_WALL_ACTIVE || - element == EL_MAGIC_WALL_EMPTYING || - element == EL_BD_MAGIC_WALL_ACTIVE || - element == EL_BD_MAGIC_WALL_EMPTYING || - element == EL_MAGIC_WALL_FULL || - element == EL_BD_MAGIC_WALL_FULL) - { - graphic += 3 + getGraphicAnimationPhase(4, 4, ANIM_REVERSE); - } - else if (IS_AMOEBOID(element) || element == EL_AMOEBA_DRIPPING) - { - graphic = (element == EL_AMOEBA_DEAD ? GFX_AMOEBE_TOT : GFX_AMOEBE_LEBT); - graphic += (x + 2 * y + 4) % 4; + graphic = el2img(element); + frame = getGraphicAnimationFrame(graphic, -1); } - else if (element == EL_WALL_GROWING) - { - boolean links_massiv = FALSE, rechts_massiv = FALSE; - - if (!IN_LEV_FIELD(ux-1, uy) || IS_MAUER(Feld[ux-1][uy])) - links_massiv = TRUE; - if (!IN_LEV_FIELD(ux+1, uy) || IS_MAUER(Feld[ux+1][uy])) - rechts_massiv = TRUE; - if (links_massiv && rechts_massiv) - graphic = GFX_MAUERWERK; - else if (links_massiv) - graphic = GFX_MAUER_R; - else if (rechts_massiv) - graphic = GFX_MAUER_L; - } -#if 0 - else if ((element == EL_INVISIBLE_STEELWALL || - element == EL_INVISIBLE_WALL || - element == EL_INVISIBLE_SAND) && game.light_time_left) - { - graphic = (element == EL_INVISIBLE_STEELWALL ? GFX_INVISIBLE_STEEL_ON : - element == EL_INVISIBLE_WALL ? GFX_UNSICHTBAR_ON : - GFX_SAND_INVISIBLE_ON); - } -#endif - - if (dx || dy) - DrawGraphicShifted(x, y, dx, dy, graphic, cut_mode, mask_mode); - else if (mask_mode == USE_MASKING) - DrawGraphicThruMask(x, y, graphic); - else - DrawGraphic(x, y, graphic); -} -#endif - -inline static int getFramePosition(int x, int y) -{ - int frame_pos = -1; /* default: global synchronization */ -#if 0 - int element = Feld[x][y]; - - if (element == EL_QUICKSAND_FULL || - element == EL_MAGIC_WALL_FULL || - element == EL_BD_MAGIC_WALL_FULL) - frame_pos = -1; - else if (IS_MOVING(x, y) || CAN_MOVE(element) || CAN_FALL(element)) - frame_pos = ABS(MovPos[x][y]) / (TILEX / 8); -#else - frame_pos = ABS(MovPos[x][y]) / (TILEX / 8); -#endif - - return frame_pos; -} - -inline static int getGfxAction(int x, int y) -{ - int gfx_action = GFX_ACTION_DEFAULT; - -#if 0 - if (GfxAction[x][y] != GFX_ACTION_DEFAULT) - gfx_action = GfxAction[x][y]; - else if (IS_MOVING(x, y)) - gfx_action = GFX_ACTION_MOVING; -#else - gfx_action = GfxAction[x][y]; -#endif - - return gfx_action; -} - -void DrawScreenElementExt(int x, int y, int dx, int dy, int element, - int cut_mode, int mask_mode) -{ - int ux = LEVELX(x), uy = LEVELY(y); - int move_dir = MovDir[ux][uy]; - int move_pos = getFramePosition(ux, uy); - int gfx_action = getGfxAction(ux, uy); - int graphic = el_dir_act2img(element, move_dir, gfx_action); - int frame = getGraphicAnimationFrame(graphic, move_pos); - - if (element == EL_WALL_GROWING) + if (element == EL_EXPANDABLE_WALL) { boolean left_stopped = FALSE, right_stopped = FALSE; - if (!IN_LEV_FIELD(ux - 1, uy) || IS_MAUER(Feld[ux - 1][uy])) + if (!IN_LEV_FIELD(lx - 1, ly) || IS_WALL(Feld[lx - 1][ly])) left_stopped = TRUE; - if (!IN_LEV_FIELD(ux + 1, uy) || IS_MAUER(Feld[ux + 1][uy])) + if (!IN_LEV_FIELD(lx + 1, ly) || IS_WALL(Feld[lx + 1][ly])) right_stopped = TRUE; if (left_stopped && right_stopped) graphic = IMG_WALL; else if (left_stopped) { - graphic = IMG_WALL_GROWING_ACTIVE_RIGHT; - frame = new_graphic_info[graphic].anim_frames - 1; + graphic = IMG_EXPANDABLE_WALL_GROWING_RIGHT; + frame = graphic_info[graphic].anim_frames - 1; } else if (right_stopped) { - graphic = IMG_WALL_GROWING_ACTIVE_LEFT; - frame = new_graphic_info[graphic].anim_frames - 1; + graphic = IMG_EXPANDABLE_WALL_GROWING_LEFT; + frame = graphic_info[graphic].anim_frames - 1; } } - else if (IS_AMOEBOID(element) || element == EL_AMOEBA_DRIPPING) +#if 0 + else if (IS_AMOEBOID(element) || element == EL_AMOEBA_DROPPING) { graphic = (element == EL_BD_AMOEBA ? IMG_BD_AMOEBA_PART1 : element == EL_AMOEBA_WET ? IMG_AMOEBA_WET_PART1 : @@ -1351,6 +1117,16 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, graphic += (x + 2 * y + 4) % 4; } +#endif + +#if 0 + if (IS_AMOEBOID(element) || element == EL_AMOEBA_DROPPING) + { + if (Feld[lx][ly] == EL_AMOEBA_DROPPING) + printf("---> %d -> %d / %d [%d]\n", + element, graphic, frame, GfxRandom[lx][ly]); + } +#endif if (dx || dy) DrawGraphicShifted(x, y, dx, dy, graphic, frame, cut_mode, mask_mode); @@ -1402,14 +1178,14 @@ void DrawLevelFieldThruMask(int x, int y) DrawLevelElementExt(x, y, 0, 0, Feld[x][y], NO_CUTTING, USE_MASKING); } -void DrawCrumbledSand(int x, int y) +static void DrawLevelFieldCrumbledSandExt(int x, int y, int graphic, int frame) { Bitmap *src_bitmap; int src_x, src_y; - int i, width, height, cx,cy; - int ux = LEVELX(x), uy = LEVELY(y); - int element, graphic; - int snip = 4; + int sx = SCREENX(x), sy = SCREENY(y); + int element; + int width, height, cx, cy, i; + int snip = TILEX / 8; /* number of border pixels from "crumbled graphic" */ static int xy[4][2] = { { 0, -1 }, @@ -1418,40 +1194,28 @@ void DrawCrumbledSand(int x, int y) { 0, +1 } }; - if (!IN_LEV_FIELD(ux, uy)) + if (!IN_LEV_FIELD(x, y)) return; - element = Feld[ux][uy]; + element = (GfxElement[x][y] != EL_UNDEFINED ? GfxElement[x][y] : Feld[x][y]); - if (element == EL_SAND || - element == EL_LANDMINE || - element == EL_TRAP || - element == EL_TRAP_ACTIVE) + /* crumble field itself */ + if (CAN_BE_CRUMBLED(element) && !IS_MOVING(x, y)) { - if (!IN_SCR_FIELD(x, y)) + if (!IN_SCR_FIELD(sx, sy)) return; - graphic = IMG_SAND_CRUMBLED; - - src_bitmap = new_graphic_info[graphic].bitmap; - src_x = new_graphic_info[graphic].src_x; - src_y = new_graphic_info[graphic].src_y; + getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y); for(i=0; i<4; i++) { - int uxx, uyy; + int xx = x + xy[i][0]; + int yy = y + xy[i][1]; - uxx = ux + xy[i][0]; - uyy = uy + xy[i][1]; - if (!IN_LEV_FIELD(uxx, uyy)) - element = EL_STEELWALL; - else - element = Feld[uxx][uyy]; + element = (IN_LEV_FIELD(xx, yy) ? Feld[xx][yy] : EL_STEELWALL); - if (element == EL_SAND || - element == EL_LANDMINE || - element == EL_TRAP || - element == EL_TRAP_ACTIVE) + /* check if neighbour field is of same type */ + if (CAN_BE_CRUMBLED(element) && !IS_MOVING(xx, yy)) continue; if (i == 1 || i == 2) @@ -1470,34 +1234,26 @@ void DrawCrumbledSand(int x, int y) } BlitBitmap(src_bitmap, drawto_field, src_x + cx, src_y + cy, - width, height, FX + x * TILEX + cx, FY + y * TILEY + cy); + width, height, FX + sx * TILEX + cx, FY + sy * TILEY + cy); } - MarkTileDirty(x, y); + MarkTileDirty(sx, sy); } - else + else /* crumble neighbour fields */ { - graphic = IMG_SAND_CRUMBLED; - - src_bitmap = new_graphic_info[graphic].bitmap; - src_x = new_graphic_info[graphic].src_x; - src_y = new_graphic_info[graphic].src_y; + getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y); for(i=0; i<4; i++) { - int xx, yy, uxx, uyy; - - xx = x + xy[i][0]; - yy = y + xy[i][1]; - uxx = ux + xy[i][0]; - uyy = uy + xy[i][1]; - - if (!IN_LEV_FIELD(uxx, uyy) || - (Feld[uxx][uyy] != EL_SAND && - Feld[uxx][uyy] != EL_LANDMINE && - Feld[uxx][uyy] != EL_TRAP && - Feld[uxx][uyy] != EL_TRAP_ACTIVE) || - !IN_SCR_FIELD(xx, yy)) + int xx = x + xy[i][0]; + int yy = y + xy[i][1]; + int sxx = sx + xy[i][0]; + int syy = sy + xy[i][1]; + + if (!IN_LEV_FIELD(xx, yy) || + !IN_SCR_FIELD(sxx, syy) || + !CAN_BE_CRUMBLED(Feld[xx][yy]) || + IS_MOVING(xx, yy)) continue; if (i == 1 || i == 2) @@ -1516,17 +1272,58 @@ void DrawCrumbledSand(int x, int y) } BlitBitmap(src_bitmap, drawto_field, src_x + cx, src_y + cy, - width, height, FX + xx * TILEX + cx, FY + yy * TILEY + cy); + width, height, FX + sxx * TILEX + cx, FY + syy * TILEY + cy); - MarkTileDirty(xx, yy); + MarkTileDirty(sxx, syy); } } } +void DrawLevelFieldCrumbledSand(int x, int y) +{ + DrawLevelFieldCrumbledSandExt(x, y, IMG_SAND_CRUMBLED, 0); +} + +void DrawLevelFieldCrumbledSandDigging(int x, int y, int direction, + int step_frame) +{ + int graphic1 = el_act_dir2img(EL_SAND, ACTION_DIGGING, direction); + int graphic2 = el_act_dir2img(EL_SAND_CRUMBLED, ACTION_DIGGING, direction); + int frame1 = getGraphicAnimationFrame(graphic1, step_frame); + int frame2 = getGraphicAnimationFrame(graphic2, step_frame); + int sx = SCREENX(x), sy = SCREENY(y); + + DrawGraphic(sx, sy, graphic1, frame1); + DrawLevelFieldCrumbledSandExt(x, y, graphic2, frame2); +} + +static int getBorderElement(int x, int y) +{ + int border[7][2] = + { + { EL_STEELWALL_TOPLEFT, EL_INVISIBLE_STEELWALL_TOPLEFT }, + { EL_STEELWALL_TOPRIGHT, EL_INVISIBLE_STEELWALL_TOPRIGHT }, + { EL_STEELWALL_BOTTOMLEFT, EL_INVISIBLE_STEELWALL_BOTTOMLEFT }, + { EL_STEELWALL_BOTTOMRIGHT, EL_INVISIBLE_STEELWALL_BOTTOMRIGHT }, + { EL_STEELWALL_VERTICAL, EL_INVISIBLE_STEELWALL_VERTICAL }, + { EL_STEELWALL_HORIZONTAL, EL_INVISIBLE_STEELWALL_HORIZONTAL }, + { EL_STEELWALL, EL_INVISIBLE_STEELWALL } + }; + int steel_type = (BorderElement == EL_STEELWALL ? 0 : 1); + int steel_position = (x == -1 && y == -1 ? 0 : + x == lev_fieldx && y == -1 ? 1 : + x == -1 && y == lev_fieldy ? 2 : + x == lev_fieldx && y == lev_fieldy ? 3 : + x == -1 || x == lev_fieldx ? 4 : + y == -1 || y == lev_fieldy ? 5 : 6); + + return border[steel_position][steel_type]; +} + void DrawScreenElement(int x, int y, int element) { DrawScreenElementExt(x, y, 0, 0, element, NO_CUTTING, NO_MASKING); - DrawCrumbledSand(x, y); + DrawLevelFieldCrumbledSand(LEVELX(x), LEVELY(y)); } void DrawLevelElement(int x, int y, int element) @@ -1537,32 +1334,32 @@ void DrawLevelElement(int x, int y, int element) void DrawScreenField(int x, int y) { - int ux = LEVELX(x), uy = LEVELY(y); + int lx = LEVELX(x), ly = LEVELY(y); int element, content; - if (!IN_LEV_FIELD(ux, uy)) + if (!IN_LEV_FIELD(lx, ly)) { - if (ux < -1 || ux > lev_fieldx || uy < -1 || uy > lev_fieldy) + if (lx < -1 || lx > lev_fieldx || ly < -1 || ly > lev_fieldy) element = EL_EMPTY; else - element = BorderElement; + element = getBorderElement(lx, ly); DrawScreenElement(x, y, element); return; } - element = Feld[ux][uy]; - content = Store[ux][uy]; + element = Feld[lx][ly]; + content = Store[lx][ly]; - if (IS_MOVING(ux, uy)) + if (IS_MOVING(lx, ly)) { - int horiz_move = (MovDir[ux][uy] == MV_LEFT || MovDir[ux][uy] == MV_RIGHT); + int horiz_move = (MovDir[lx][ly] == MV_LEFT || MovDir[lx][ly] == MV_RIGHT); boolean cut_mode = NO_CUTTING; if (element == EL_QUICKSAND_EMPTYING || element == EL_MAGIC_WALL_EMPTYING || element == EL_BD_MAGIC_WALL_EMPTYING || - element == EL_AMOEBA_DRIPPING) + element == EL_AMOEBA_DROPPING) cut_mode = CUT_ABOVE; else if (element == EL_QUICKSAND_FILLING || element == EL_MAGIC_WALL_FILLING || @@ -1575,16 +1372,16 @@ void DrawScreenField(int x, int y) DrawScreenElement(x, y, EL_EMPTY); if (horiz_move) - DrawScreenElementShifted(x, y, MovPos[ux][uy], 0, element, NO_CUTTING); + DrawScreenElementShifted(x, y, MovPos[lx][ly], 0, element, NO_CUTTING); else if (cut_mode == NO_CUTTING) - DrawScreenElementShifted(x, y, 0, MovPos[ux][uy], element, cut_mode); + DrawScreenElementShifted(x, y, 0, MovPos[lx][ly], element, cut_mode); else - DrawScreenElementShifted(x, y, 0, MovPos[ux][uy], content, cut_mode); + DrawScreenElementShifted(x, y, 0, MovPos[lx][ly], content, cut_mode); if (content == EL_ACID) - DrawLevelElementThruMask(ux, uy + 1, EL_ACID); + DrawLevelElementThruMask(lx, ly + 1, EL_ACID); } - else if (IS_BLOCKED(ux, uy)) + else if (IS_BLOCKED(lx, ly)) { int oldx, oldy; int sx, sy; @@ -1592,7 +1389,7 @@ void DrawScreenField(int x, int y) boolean cut_mode = NO_CUTTING; int element_old, content_old; - Blocked2Moving(ux, uy, &oldx, &oldy); + Blocked2Moving(lx, ly, &oldx, &oldy); sx = SCREENX(oldx); sy = SCREENY(oldy); horiz_move = (MovDir[oldx][oldy] == MV_LEFT || @@ -1604,7 +1401,7 @@ void DrawScreenField(int x, int y) if (element_old == EL_QUICKSAND_EMPTYING || element_old == EL_MAGIC_WALL_EMPTYING || element_old == EL_BD_MAGIC_WALL_EMPTYING || - element_old == EL_AMOEBA_DRIPPING) + element_old == EL_AMOEBA_DROPPING) cut_mode = CUT_ABOVE; DrawScreenElement(x, y, EL_EMPTY); @@ -1651,7 +1448,7 @@ void DrawMiniElement(int x, int y, int element) { int graphic; - graphic = el2img(element); + graphic = el2edimg(element); DrawMiniGraphic(x, y, graphic); } @@ -1664,39 +1461,18 @@ void DrawMiniElementOrWall(int sx, int sy, int scroll_x, int scroll_y) else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy) DrawMiniElement(sx, sy, Feld[x][y]); else - { - int steel_type, steel_position; - int border[6][2] = - { - { IMG_STEELWALL_TOPLEFT, IMG_INVISIBLE_STEELWALL_TOPLEFT }, - { IMG_STEELWALL_TOPRIGHT, IMG_INVISIBLE_STEELWALL_TOPRIGHT }, - { IMG_STEELWALL_BOTTOMLEFT, IMG_INVISIBLE_STEELWALL_BOTTOMLEFT }, - { IMG_STEELWALL_BOTTOMRIGHT, IMG_INVISIBLE_STEELWALL_BOTTOMRIGHT }, - { IMG_STEELWALL_VERTICAL, IMG_INVISIBLE_STEELWALL_VERTICAL }, - { IMG_STEELWALL_HORIZONTAL, IMG_INVISIBLE_STEELWALL_HORIZONTAL } - }; - - steel_type = (BorderElement == EL_STEELWALL ? 0 : 1); - steel_position = (x == -1 && y == -1 ? 0 : - x == lev_fieldx && y == -1 ? 1 : - x == -1 && y == lev_fieldy ? 2 : - x == lev_fieldx && y == lev_fieldy ? 3 : - x == -1 || x == lev_fieldx ? 4 : - y == -1 || y == lev_fieldy ? 5 : -1); - - if (steel_position != -1) - DrawMiniGraphic(sx, sy, border[steel_position][steel_type]); - } + DrawMiniGraphic(sx, sy, el2edimg(getBorderElement(x, y))); } void getMicroGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y) { - Bitmap *src_bitmap = new_graphic_info[graphic].bitmap; + Bitmap *src_bitmap = graphic_info[graphic].bitmap; int mini_startx = src_bitmap->width * 3 / 4; int mini_starty = src_bitmap->height * 2 / 3; - int src_x = mini_startx + new_graphic_info[graphic].src_x / 8; - int src_y = mini_starty + new_graphic_info[graphic].src_y / 8; + int src_x = mini_startx + graphic_info[graphic].src_x / 8; + int src_y = mini_starty + graphic_info[graphic].src_y / 8; +#if 0 if (src_x + MICRO_TILEX > src_bitmap->width || src_y + MICRO_TILEY > src_bitmap->height) { @@ -1707,6 +1483,7 @@ void getMicroGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y) src_x += (TILEX / 2 - MICRO_TILEX / 2); src_y += (TILEY / 2 - MICRO_TILEY / 2); } +#endif *bitmap = src_bitmap; *x = src_x; @@ -1717,12 +1494,7 @@ void DrawMicroElement(int xpos, int ypos, int element) { Bitmap *src_bitmap; int src_x, src_y; - int graphic; - - if (element == EL_EMPTY) - return; - - graphic = el2img(element); + int graphic = el2preimg(element); getMicroGraphicSource(graphic, &src_bitmap, &src_x, &src_y); BlitBitmap(src_bitmap, drawto, src_x, src_y, MICRO_TILEX, MICRO_TILEY, @@ -1733,6 +1505,7 @@ void DrawLevel() { int x,y; + SetDrawBackgroundMask(REDRAW_NONE); ClearWindow(); for(x=BX1; x<=BX2; x++) @@ -1757,7 +1530,7 @@ static void DrawMicroLevelExt(int xpos, int ypos, int from_x, int from_y) { int x, y; - ClearRectangle(drawto, xpos, ypos, MICROLEV_XSIZE, MICROLEV_YSIZE); + DrawBackground(xpos, ypos, MICROLEV_XSIZE, MICROLEV_YSIZE); if (lev_fieldx < STD_LEV_FIELDX) xpos += (STD_LEV_FIELDX - lev_fieldx) / 2 * MICRO_TILEX; @@ -1776,9 +1549,10 @@ static void DrawMicroLevelExt(int xpos, int ypos, int from_x, int from_y) if (lx >= 0 && lx < lev_fieldx && ly >= 0 && ly < lev_fieldy) DrawMicroElement(xpos + x * MICRO_TILEX, ypos + y * MICRO_TILEY, Ur[lx][ly]); - else if (lx >= -1 && lx < lev_fieldx+1 && ly >= -1 && ly < lev_fieldy+1) + else if (lx >= -1 && lx < lev_fieldx+1 && ly >= -1 && ly < lev_fieldy+1 + && BorderElement != EL_EMPTY) DrawMicroElement(xpos + x * MICRO_TILEX, ypos + y * MICRO_TILEY, - BorderElement); + getBorderElement(lx, ly)); } } @@ -1792,13 +1566,18 @@ static void DrawMicroLevelExt(int xpos, int ypos, int from_x, int from_y) #define MICROLABEL_IMPORTED_FROM 4 #define MICROLABEL_LEVEL_IMPORT_INFO 5 -#define MAX_MICROLABEL_SIZE (SXSIZE / FONT4_XSIZE) - static void DrawMicroLevelLabelExt(int mode) { - char label_text[MAX_MICROLABEL_SIZE + 1]; + char label_text[MAX_OUTPUT_LINESIZE + 1]; + int max_len_label_text; + int font_nr = FONT_TEXT_2; + + if (mode == MICROLABEL_CREATED_BY || mode == MICROLABEL_IMPORTED_FROM) + font_nr = FONT_TEXT_3; - ClearRectangle(drawto, SX, MICROLABEL_YPOS, SXSIZE, FONT4_YSIZE); + max_len_label_text = SXSIZE / getFontWidth(font_nr); + + DrawBackground(SX, MICROLABEL_YPOS, SXSIZE, getFontHeight(font_nr)); strncpy(label_text, (mode == MICROLABEL_LEVEL_NAME ? level.name : mode == MICROLABEL_CREATED_BY ? "created by" : @@ -1806,15 +1585,16 @@ static void DrawMicroLevelLabelExt(int mode) mode == MICROLABEL_IMPORTED_FROM ? "imported from" : mode == MICROLABEL_LEVEL_IMPORT_INFO ? leveldir_current->imported_from : ""), - MAX_MICROLABEL_SIZE); - label_text[MAX_MICROLABEL_SIZE] = '\0'; + max_len_label_text); + label_text[max_len_label_text] = '\0'; if (strlen(label_text) > 0) { - int lxpos = SX + (SXSIZE - strlen(label_text) * FONT4_XSIZE) / 2; + int text_width = strlen(label_text) * getFontWidth(font_nr); + int lxpos = SX + (SXSIZE - text_width) / 2; int lypos = MICROLABEL_YPOS; - DrawText(lxpos, lypos, label_text, FS_SMALL, FC_SPECIAL2); + DrawText(lxpos, lypos, label_text, font_nr); } redraw_mask |= REDRAW_MICROLEVEL; @@ -1826,6 +1606,10 @@ void DrawMicroLevel(int xpos, int ypos, boolean restart) static unsigned long label_delay = 0; static int from_x, from_y, scroll_direction; static int label_state, label_counter; + int last_game_status = game_status; /* save current game status */ + + /* force PREVIEW font on preview level */ + game_status = GAME_MODE_PSEUDO_PREVIEW; if (restart) { @@ -1841,6 +1625,17 @@ void DrawMicroLevel(int xpos, int ypos, boolean restart) DelayReached(&scroll_delay, 0); DelayReached(&label_delay, 0); + if (leveldir_current->name) + { + int len = strlen(leveldir_current->name); + int lxpos = SX + (SXSIZE - len * getFontWidth(FONT_TEXT_1)) / 2; + int lypos = SY + 352; + + DrawText(lxpos, lypos, leveldir_current->name, FONT_TEXT_1); + } + + game_status = last_game_status; /* restore current game status */ + return; } @@ -1909,6 +1704,8 @@ void DrawMicroLevel(int xpos, int ypos, boolean restart) MICROLABEL_LEVEL_IMPORT_INFO : MICROLABEL_EMPTY); DrawMicroLevelLabelExt(label_state); } + + game_status = last_game_status; /* restore current game status */ } int REQ_in_range(int x, int y) @@ -1930,11 +1727,12 @@ boolean Request(char *text, unsigned int req_state) { int mx, my, ty, result = -1; unsigned int old_door_state; + int last_game_status = game_status; /* save current game status */ #if defined(PLATFORM_UNIX) /* pause network game while waiting for request to answer */ if (options.network && - game_status == PLAYING && + game_status == GAME_MODE_PLAYING && req_state & REQUEST_WAIT_FOR) SendToServer_PausePlaying(); #endif @@ -1950,8 +1748,13 @@ boolean Request(char *text, unsigned int req_state) DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DOOR_GFX_PAGEX2, DOOR_GFX_PAGEY1); + SetDrawBackgroundMask(REDRAW_FIELD | REDRAW_DOOR_1); + /* clear door drawing field */ - ClearRectangle(drawto, DX, DY, DXSIZE, DYSIZE); + DrawBackground(DX, DY, DXSIZE, DYSIZE); + + /* force DOOR font on preview level */ + game_status = GAME_MODE_PSEUDO_DOOR; /* write text for request */ for(ty=0; ty < MAX_REQUEST_LINES; ty++) @@ -1979,12 +1782,15 @@ boolean Request(char *text, unsigned int req_state) strncpy(text_line, text, tl); text_line[tl] = 0; - DrawTextExt(drawto, DX + 50 - (tl * 14)/2, DY + 8 + ty * 16, - text_line, FS_SMALL, FC_YELLOW); + DrawText(DX + (DXSIZE - tl * getFontWidth(FONT_TEXT_2)) / 2, + DY + 8 + ty * (getFontHeight(FONT_TEXT_2) + 2), + text_line, FONT_TEXT_2); text += tl + (tc == ' ' ? 1 : 0); } + game_status = last_game_status; /* restore current game status */ + if (req_state & REQ_ASK) { MapGadget(tool_gadget[TOOL_CTRL_ID_YES]); @@ -2014,15 +1820,21 @@ boolean Request(char *text, unsigned int req_state) #endif if (!(req_state & REQUEST_WAIT_FOR)) - return(FALSE); + { + SetDrawBackgroundMask(REDRAW_FIELD); + + return FALSE; + } - if (game_status != MAINMENU) + if (game_status != GAME_MODE_MAIN) InitAnimation(); button_status = MB_RELEASED; request_gadget_id = -1; + SetDrawBackgroundMask(REDRAW_FIELD | REDRAW_DOOR_1); + while(result < 0) { if (PendingEvent()) @@ -2138,7 +1950,7 @@ boolean Request(char *text, unsigned int req_state) Delay(10); } - if (game_status != MAINMENU) + if (game_status != GAME_MODE_MAIN) StopAnimation(); UnmapToolButtons(); @@ -2158,15 +1970,17 @@ boolean Request(char *text, unsigned int req_state) RemapAllGadgets(); + SetDrawBackgroundMask(REDRAW_FIELD); + #if defined(PLATFORM_UNIX) /* continue network game after request */ if (options.network && - game_status == PLAYING && + game_status == GAME_MODE_PLAYING && req_state & REQUEST_WAIT_FOR) SendToServer_ContinuePlaying(); #endif - return(result); + return result; } unsigned int OpenDoor(unsigned int door_state) @@ -2215,8 +2029,8 @@ unsigned int MoveDoor(unsigned int door_state) static int door1 = DOOR_OPEN_1; static int door2 = DOOR_CLOSE_2; static unsigned long door_delay = 0; - int x, start, stepsize = 2; - unsigned long door_delay_value = stepsize * 5; + int x, start, stepsize = door.step_offset; + unsigned long door_delay_value = door.step_delay; if (door_state == DOOR_GET_STATE) return(door1 | door2); @@ -2245,8 +2059,8 @@ unsigned int MoveDoor(unsigned int door_state) stepsize = 20; door_delay_value = 0; - StopSound(SND_MENU_DOOR_OPENING); - StopSound(SND_MENU_DOOR_CLOSING); + StopSound(SND_DOOR_OPENING); + StopSound(SND_DOOR_CLOSING); } if (global.autoplay_leveldir) @@ -2261,16 +2075,16 @@ unsigned int MoveDoor(unsigned int door_state) { /* opening door sound has priority over simultaneously closing door */ if (door_state & (DOOR_OPEN_1 | DOOR_OPEN_2)) - PlaySoundStereo(SND_MENU_DOOR_OPENING, SOUND_MAX_RIGHT); + PlaySoundStereo(SND_DOOR_OPENING, SOUND_MIDDLE); else if (door_state & (DOOR_CLOSE_1 | DOOR_CLOSE_2)) - PlaySoundStereo(SND_MENU_DOOR_CLOSING, SOUND_MAX_RIGHT); + PlaySoundStereo(SND_DOOR_CLOSING, SOUND_MIDDLE); } start = ((door_state & DOOR_NO_DELAY) ? DXSIZE : 0); for(x=start; x<=DXSIZE; x+=stepsize) { - Bitmap *bitmap = new_graphic_info[IMG_MENU_DOOR].bitmap; + Bitmap *bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap; GC gc = bitmap->stored_clip_gc; if (!(door_state & DOOR_NO_DELAY)) @@ -2354,15 +2168,15 @@ unsigned int MoveDoor(unsigned int door_state) BackToFront(); - if (game_status == MAINMENU) + if (game_status == GAME_MODE_MAIN) DoAnimation(); } } if (setup.quick_doors) { - StopSound(SND_MENU_DOOR_OPENING); - StopSound(SND_MENU_DOOR_CLOSING); + StopSound(SND_DOOR_OPENING); + StopSound(SND_DOOR_CLOSING); } if (door_state & DOOR_ACTION_1) @@ -2376,8 +2190,12 @@ unsigned int MoveDoor(unsigned int door_state) void DrawSpecialEditorDoor() { /* draw bigger toolbox window */ - BlitBitmap(new_graphic_info[IMG_MENU_DOOR].bitmap, drawto, - DOOR_GFX_PAGEX7, 0, 108, 56, EX - 4, EY - 12); + BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, + DOOR_GFX_PAGEX7, 0, EXSIZE + 8, 8, + EX - 4, EY - 12); + BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto, + EX - 4, VY - 4, EXSIZE + 8, EYSIZE - VYSIZE + 4, + EX - 4, EY - 4); redraw_mask |= REDRAW_ALL; } @@ -2385,27 +2203,13 @@ void DrawSpecialEditorDoor() void UndrawSpecialEditorDoor() { /* draw normal tape recorder window */ - BlitBitmap(new_graphic_info[IMG_MENU_BACK].bitmap, drawto, - 562, 344, 108, 56, EX - 4, EY - 12); + BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto, + EX - 4, EY - 12, EXSIZE + 8, EYSIZE - VYSIZE + 12, + EX - 4, EY - 12); redraw_mask |= REDRAW_ALL; } -#ifndef TARGET_SDL -int ReadPixel(DrawBuffer *bitmap, int x, int y) -{ - XImage *pixel_image; - unsigned long pixel_value; - - pixel_image = XGetImage(display, bitmap->drawable, - x, y, 1, 1, AllPlanes, ZPixmap); - pixel_value = XGetPixel(pixel_image, 0, 0); - - XDestroyImage(pixel_image); - - return pixel_value; -} -#endif /* ---------- new tool button stuff ---------------------------------------- */ @@ -2514,7 +2318,7 @@ void CreateToolButtons() for (i=0; i= EL_SP_START && element <= EL_SP_END) - { - int nr_element = element - EL_SP_START; - int gfx_per_line = 8; - int nr_graphic = - (nr_element / gfx_per_line) * SP_PER_LINE + - (nr_element % gfx_per_line); + element = GFX_ELEMENT(element); + direction = MV_DIR_BIT(direction); - return GFX_START_ROCKSSP + nr_graphic; - } - else - return -1; - } - } + return element_info[element].direction_graphic[action][direction]; } -int el2gfx(int element) +int el_act2img(int element, int action) { -#if 1 - int graphic_OLD = el2gfx_OLD(element); - - return graphic_OLD; -#else - - int graphic_NEW = element_info[element].graphic[GFX_ACTION_DEFAULT]; - -#if DEBUG - int graphic_OLD = el2gfx_OLD(element); + element = GFX_ELEMENT(element); - if (element >= MAX_ELEMENTS) - { - Error(ERR_WARN, "el2gfx: element == %d >= MAX_ELEMENTS", element); - } + return element_info[element].graphic[action]; +} - if (graphic_NEW != graphic_OLD) - { - Error(ERR_WARN, "el2gfx: graphic_NEW (%d) != graphic_OLD (%d)", - graphic_NEW, graphic_OLD); - } -#endif +int el_dir2img(int element, int direction) +{ + element = GFX_ELEMENT(element); - return graphic_NEW; -#endif + return el_act_dir2img(element, ACTION_DEFAULT, direction); } int el2img(int element) { - int graphic = element_info[element].graphic[GFX_ACTION_DEFAULT]; + element = GFX_ELEMENT(element); -#if DEBUG - if (graphic < 0) - Error(ERR_WARN, "element %d -> graphic %d -- probably crashing now...", - element, graphic); -#endif - - return graphic; + return element_info[element].graphic[ACTION_DEFAULT]; } -int el_dir2img(int element, int direction) +int el2edimg(int element) { - return el_dir_act2img(element, direction, GFX_ACTION_DEFAULT); + element = GFX_ELEMENT(element); + + return element_info[element].special_graphic[GFX_SPECIAL_ARG_EDITOR]; } -int el_dir_act2img(int element, int direction, int action) +int el2preimg(int element) { - action = graphics_action_mapping[action]; - direction = MV_DIR_BIT(direction); + element = GFX_ELEMENT(element); - return element_info[element].direction_graphic[action][direction]; + return element_info[element].special_graphic[GFX_SPECIAL_ARG_PREVIEW]; }