X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ftools.c;h=16cb3984075fd88b48bec40c43a3f39ead5e8d48;hb=b461a474a18f36ff4bd5f1805ea01de11dd5a5fc;hp=ebc8cb6dd6a0a0f95b4cc4fe98d4da8953ac4f25;hpb=a84bd00a438ff458c2d74d1d1784deefe12bf84a;p=rocksndiamonds.git diff --git a/src/tools.c b/src/tools.c index ebc8cb6d..16cb3984 100644 --- a/src/tools.c +++ b/src/tools.c @@ -32,9 +32,6 @@ #define NUM_TOOL_BUTTONS 7 /* forward declaration for internal use */ -static int getGraphicAnimationPhase(int, int, int); -static void DrawGraphicAnimationShiftedThruMask(int, int, int, int, int, - int, int, int); static void UnmapToolButtons(); static void HandleToolButtons(struct GadgetInfo *); @@ -282,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, FS_SMALL, FC_YELLOW, FONT_OPAQUE); } FlushDisplay(); @@ -365,9 +362,32 @@ void FadeToFront() BackToFront(); } +void SetMainBackgroundImage(int graphic) +{ + SetMainBackgroundBitmap(graphic == IMG_NONE ? NULL : + new_graphic_info[graphic].bitmap ? + new_graphic_info[graphic].bitmap : + new_graphic_info[IMG_BACKGROUND_DEFAULT].bitmap); +} + +void SetDoorBackgroundImage(int graphic) +{ + SetDoorBackgroundBitmap(graphic == IMG_NONE ? NULL : + new_graphic_info[graphic].bitmap ? + new_graphic_info[graphic].bitmap : + new_graphic_info[IMG_BACKGROUND_DEFAULT].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) { @@ -382,8 +402,39 @@ void ClearWindow() 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) @@ -442,7 +493,8 @@ void DrawPlayer(struct PlayerInfo *player) int sx = SCREENX(jx), sy = SCREENY(jy); int sxx = 0, syy = 0; int element = Feld[jx][jy], last_element = Feld[last_jx][last_jy]; - int graphic, phase; + int graphic; + int frame = 0; boolean player_is_moving = (last_jx != jx || last_jy != jy ? TRUE : FALSE); if (!player->active || !IN_SCR_FIELD(SCREENX(last_jx), SCREENY(last_jy))) @@ -468,6 +520,7 @@ void DrawPlayer(struct PlayerInfo *player) if (Store[last_jx][last_jy] && IS_DRAWABLE(last_element)) { DrawLevelElement(last_jx, last_jy, Store[last_jx][last_jy]); + if (last_element == EL_DYNAMITE_ACTIVE) DrawDynamite(last_jx, last_jy); else @@ -519,44 +572,44 @@ void DrawPlayer(struct PlayerInfo *player) ((action & (MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)) && !(action & ~(MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN)))); - graphic = GFX_SP_MURPHY; + graphic = IMG_SP_MURPHY; if (player->Pushing) { if (player->MovDir == MV_LEFT) - graphic = GFX_MURPHY_PUSH_LEFT; + graphic = IMG_SP_MURPHY_LEFT_PUSHING; else if (player->MovDir == MV_RIGHT) - graphic = GFX_MURPHY_PUSH_RIGHT; + graphic = IMG_SP_MURPHY_RIGHT_PUSHING; else if (player->MovDir & (MV_UP | MV_DOWN) && last_dir == MV_LEFT) - graphic = GFX_MURPHY_PUSH_LEFT; + graphic = IMG_SP_MURPHY_LEFT_PUSHING; else if (player->MovDir & (MV_UP | MV_DOWN) && last_dir == MV_RIGHT) - graphic = GFX_MURPHY_PUSH_RIGHT; + graphic = IMG_SP_MURPHY_RIGHT_PUSHING; } else if (player->snapped) { if (player->MovDir == MV_LEFT) - graphic = GFX_MURPHY_SNAP_LEFT; + graphic = IMG_SP_MURPHY_LEFT_SNAPPING; else if (player->MovDir == MV_RIGHT) - graphic = GFX_MURPHY_SNAP_RIGHT; + graphic = IMG_SP_MURPHY_RIGHT_SNAPPING; else if (player->MovDir == MV_UP) - graphic = GFX_MURPHY_SNAP_UP; + graphic = IMG_SP_MURPHY_UP_SNAPPING; else if (player->MovDir == MV_DOWN) - graphic = GFX_MURPHY_SNAP_DOWN; + graphic = IMG_SP_MURPHY_DOWN_SNAPPING; } else if (action_moving) { if (player->MovDir == MV_LEFT) - graphic = GFX_MURPHY_GO_LEFT; + graphic = IMG_SP_MURPHY_LEFT_MOVING; else if (player->MovDir == MV_RIGHT) - graphic = GFX_MURPHY_GO_RIGHT; + graphic = IMG_SP_MURPHY_RIGHT_MOVING; else if (player->MovDir & (MV_UP | MV_DOWN) && last_dir == MV_LEFT) - graphic = GFX_MURPHY_GO_LEFT; + graphic = IMG_SP_MURPHY_LEFT_MOVING; else if (player->MovDir & (MV_UP | MV_DOWN) && last_dir == MV_RIGHT) - graphic = GFX_MURPHY_GO_RIGHT; + graphic = IMG_SP_MURPHY_RIGHT_MOVING; else - graphic = GFX_MURPHY_GO_LEFT; + graphic = IMG_SP_MURPHY_LEFT_MOVING; - graphic += getGraphicAnimationPhase(3, 2, ANIM_PINGPONG); + frame = getGraphicAnimationFrame(graphic, -1); } if (player->MovDir == MV_LEFT || player->MovDir == MV_RIGHT) @@ -565,18 +618,29 @@ void DrawPlayer(struct PlayerInfo *player) else { if (player->MovDir == MV_LEFT) - graphic = - (player->Pushing ? GFX_SPIELER1_PUSH_LEFT : GFX_SPIELER1_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 ? GFX_SPIELER1_PUSH_RIGHT : GFX_SPIELER1_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 = GFX_SPIELER1_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 = GFX_SPIELER1_DOWN; + 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); - graphic += player->index_nr * 3 * HEROES_PER_LINE; - graphic += player->Frame; +#if 0 + frame = player->Frame; +#else + frame = getGraphicAnimationFrame(graphic, player->Frame); +#endif } if (player->GfxPos) @@ -590,43 +654,72 @@ void DrawPlayer(struct PlayerInfo *player) if (!setup.soft_scrolling && ScreenMovPos) sxx = syy = 0; - DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, NO_CUTTING); +#if 0 + if (player->Frame) + printf("-> %d\n", player->Frame); +#endif + + DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, frame, NO_CUTTING); if (SHIELD_ON(player)) { - int graphic = (player->shield_active_time_left ? GFX2_SHIELD_ACTIVE : - GFX2_SHIELD_PASSIVE); + int graphic = (player->shield_deadly_time_left ? IMG_SHIELD_DEADLY_ACTIVE : + IMG_SHIELD_NORMAL_ACTIVE); + int frame = getGraphicAnimationFrame(graphic, -1); - DrawGraphicAnimationShiftedThruMask(sx, sy, sxx, syy, graphic, - 3, 8, ANIM_PINGPONG); + DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic, frame, NO_CUTTING); } +#if 0 if (player->Pushing && player->GfxPos) +#else + 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, + 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 { int element = Feld[next_jx][next_jy]; - int graphic = el2gfx(element); + int graphic = el2img(element); +#if 1 + int frame = 0; +#endif - if ((element == EL_ROCK || - element == EL_SP_ZONK || - element == EL_BD_ROCK) && sxx) + if ((sxx || syy) && IS_PUSHABLE(element)) { - int phase = (player->GfxPos / (TILEX / 4)); + graphic = el_dir_act2img(element, player->MovDir, GFX_ACTION_MOVING); +#if 1 + frame = getGraphicAnimationFrame(graphic, player->GfxPos); + + 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) - graphic += phase; - else - graphic += (phase + 4) % 4; + 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, NO_CUTTING, NO_MASKING); + DrawGraphicShifted(px, py, sxx, syy, graphic, frame, + NO_CUTTING, NO_MASKING); } } @@ -634,39 +727,48 @@ void DrawPlayer(struct PlayerInfo *player) if (IS_ACTIVE_BOMB(element)) { - graphic = el2gfx(element); + graphic = el2img(element); +#if 0 if (element == EL_DYNAMITE_ACTIVE) { - if ((phase = (96 - MovDelay[jx][jy]) / 12) > 6) - phase = 6; + if ((frame = (96 - MovDelay[jx][jy]) / 12) > 6) + frame = 6; } else { - if ((phase = ((96 - MovDelay[jx][jy]) / 6) % 8) > 3) - phase = 7 - phase; + if ((frame = ((96 - MovDelay[jx][jy]) / 6) % 8) > 3) + frame = 7 - frame; } +#else + frame = getGraphicAnimationFrame(graphic, 96 - MovDelay[jx][jy]); +#endif if (game.emulation == EMU_SUPAPLEX) - DrawGraphic(sx, sy, GFX_SP_DISK_RED); + DrawGraphic(sx, sy, IMG_SP_DISK_RED, 0); else - DrawGraphicThruMask(sx, sy, graphic + phase); + DrawGraphicThruMask(sx, sy, graphic, frame); } if (player_is_moving && last_element == EL_EXPLOSION) { - int phase = Frame[last_jx][last_jy]; - int delay = 2; + 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); + int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2); + int phase = Frame[last_jx][last_jy] - 1; + int frame = getGraphicAnimationFrame(graphic, phase - delay); - if (phase > 2) - DrawGraphicThruMask(SCREENX(last_jx), SCREENY(last_jy), - GFX_EXPLOSION + ((phase - 1) / delay - 1)); + if (phase >= delay) + DrawGraphicThruMask(SCREENX(last_jx), SCREENY(last_jy), graphic, frame); } /* draw elements that stay over the player */ /* handle the field the player is leaving ... */ if (player_is_moving && IS_OVER_PLAYER(last_element)) DrawLevelField(last_jx, last_jy); + /* ... and the field the player is entering */ if (IS_OVER_PLAYER(element)) DrawLevelField(jx, jy); @@ -686,131 +788,30 @@ void DrawPlayer(struct PlayerInfo *player) MarkTileDirty(sx,sy); } -static int getGraphicAnimationPhase(int frames, int delay, int mode) +void DrawGraphicAnimationExt(DrawBuffer *dst_bitmap, int x, int y, + int graphic, int mask_mode) { - int phase; + int frame = getGraphicAnimationFrame(graphic, -1); - 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); - } + if (mask_mode == USE_MASKING) + DrawGraphicThruMaskExt(dst_bitmap, x, y, graphic, frame); else - phase = (FrameCounter % (delay * frames)) / delay; - - if (mode == ANIM_REVERSE) - phase = -phase; - - return phase; -} - -int getNewGraphicAnimationFrame(int graphic, int sync_frame) -{ - int num_frames = new_graphic_info[graphic].anim_frames; - int delay = new_graphic_info[graphic].anim_delay; - int mode = new_graphic_info[graphic].anim_mode; - int frame = 0; - - /* animation synchronized with global frame counter, not move position */ - if (new_graphic_info[graphic].anim_global_sync || sync_frame < 0) - sync_frame = FrameCounter; - - if (mode & ANIM_LOOP) /* normal, looping animation */ - { - frame = (sync_frame % (delay * num_frames)) / delay; - } - else if (mode & ANIM_LINEAR) /* normal, non-looping animation */ - { - frame = sync_frame / delay; - - if (frame > num_frames - 1) - frame = num_frames - 1; - } - else if (mode & ANIM_PINGPONG) /* use border frames once */ - { - int max_anim_frames = 2 * num_frames - 2; - - frame = (sync_frame % (delay * max_anim_frames)) / delay; - frame = (frame < num_frames ? frame : max_anim_frames - frame); - } - else if (mode & ANIM_PINGPONG2) /* use border frames twice */ - { - int max_anim_frames = 2 * num_frames; - - frame = (sync_frame % (delay * max_anim_frames)) / delay; - frame = (frame < num_frames ? frame : max_anim_frames - frame - 1); - } - - if (mode & ANIM_REVERSE) /* use reverse animation direction */ - frame = num_frames - frame - 1; - - return frame; + DrawGraphicExt(dst_bitmap, x, y, graphic, frame); } -void DrawGraphicAnimationExt(int x, int y, int graphic, - int frames, int delay, int mode, int mask_mode) +void DrawGraphicAnimation(int x, int y, int graphic) { - int phase = getGraphicAnimationPhase(frames, delay, mode); + if (!IN_SCR_FIELD(x, y) || + (FrameCounter % new_graphic_info[graphic].anim_delay) != 0) + return; - if (!(FrameCounter % delay) && IN_SCR_FIELD(SCREENX(x), SCREENY(y))) - { - if (mask_mode == USE_MASKING) - DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic + phase); - else - DrawGraphic(SCREENX(x), SCREENY(y), graphic + phase); - } + DrawGraphicAnimationExt(drawto_field, FX + x * TILEX, FY + y * TILEY, + graphic, NO_MASKING); + MarkTileDirty(x, y); } -void DrawNewGraphicAnimationExt(int x, int y, int graphic, int mask_mode) -{ - int delay = new_graphic_info[graphic].anim_delay; - #if 0 - if (!(FrameCounter % delay) && IN_SCR_FIELD(SCREENX(x), SCREENY(y))) -#else - if (IN_SCR_FIELD(SCREENX(x), SCREENY(y))) -#endif - { - int frame = getNewGraphicAnimationFrame(graphic, -1); - - if (mask_mode == USE_MASKING) - DrawNewGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame); - else - DrawNewGraphic(SCREENX(x), SCREENY(y), graphic, frame); - } -} - -void DrawGraphicAnimation(int x, int y, int graphic, - int frames, int delay, int mode) -{ - DrawGraphicAnimationExt(x, y, graphic, frames, delay, mode, NO_MASKING); -} - -void DrawNewGraphicAnimation(int x, int y, int graphic) -{ - DrawNewGraphicAnimationExt(x, y, graphic, NO_MASKING); -} - -void DrawGraphicAnimationThruMask(int x, int y, int graphic, - int frames, int delay, int mode) -{ - DrawGraphicAnimationExt(x, y, graphic, frames, delay, mode, USE_MASKING); -} - -static void DrawGraphicAnimationShiftedThruMask(int sx, int sy, - int sxx, int syy, - int graphic, - int frames, int delay, - int mode) -{ - int phase = getGraphicAnimationPhase(frames, delay, mode); - - DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic + phase, NO_CUTTING); -} - -void getGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y) +void getOldGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y) { if (graphic >= 0 && graphic_info[graphic].bitmap != NULL) { @@ -822,96 +823,102 @@ void getGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y) graphic <= GFX_END_ROCKSELEMENTS) { graphic -= GFX_START_ROCKSELEMENTS; - *bitmap = pix[PIX_ELEMENTS]; + *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 = pix[PIX_HEROES]; + *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) { graphic -= GFX_START_ROCKSSP; - *bitmap = pix[PIX_SP]; + *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 = pix[PIX_DC]; + *bitmap = new_graphic_info[IMG_OLD_PIX_DC].bitmap; *x = (graphic % DC_PER_LINE) * TILEX; *y = (graphic / DC_PER_LINE) * TILEY; } else if (graphic >= GFX_START_ROCKSMORE && graphic <= GFX_END_ROCKSMORE) { graphic -= GFX_START_ROCKSMORE; - *bitmap = pix[PIX_MORE]; + *bitmap = new_graphic_info[IMG_OLD_PIX_MORE].bitmap; *x = (graphic % MORE_PER_LINE) * TILEX; *y = (graphic / MORE_PER_LINE) * TILEY; } else if (graphic >= GFX_START_ROCKSFONT && graphic <= GFX_END_ROCKSFONT) { graphic -= GFX_START_ROCKSFONT; - *bitmap = pix[PIX_FONT_EM]; + *bitmap = new_graphic_info[IMG_OLD_PIX_FONT_EM].bitmap; *x = (graphic % FONT_CHARS_PER_LINE) * TILEX; *y = (graphic / FONT_CHARS_PER_LINE) * TILEY; } else { - *bitmap = pix[PIX_SP]; + *bitmap = new_graphic_info[IMG_OLD_PIX_SP].bitmap; *x = 0; *y = 0; } } +#endif -void DrawGraphic(int x, int y, int graphic) +void getGraphicSource(int graphic, int frame, Bitmap **bitmap, int *x, int *y) { -#if DEBUG - if (!IN_SCR_FIELD(x, y)) - { - printf("DrawGraphic(): x = %d, y = %d, graphic = %d\n", x, y, graphic); - printf("DrawGraphic(): This should never happen!\n"); - return; - } -#endif + 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; - DrawGraphicExt(drawto_field, FX + x * TILEX, FY + y * TILEY, graphic); - MarkTileDirty(x, y); + *bitmap = src_bitmap; + *x = src_x; + *y = src_y; } -void DrawNewGraphic(int x, int y, int graphic, int frame) +void DrawGraphic(int x, int y, int graphic, int frame) { #if DEBUG if (!IN_SCR_FIELD(x, y)) { - printf("DrawNewGraphic(): x = %d, y = %d, graphic = %d\n", x, y, graphic); - printf("DrawNewGraphic(): This should never happen!\n"); + printf("DrawGraphic(): x = %d, y = %d, graphic = %d\n", x, y, graphic); + printf("DrawGraphic(): This should never happen!\n"); return; } #endif - DrawNewGraphicExt(drawto_field, FX + x * TILEX, FY + y * TILEY, - graphic, frame); + DrawGraphicExt(drawto_field, FX + x * TILEX, FY + y * TILEY, graphic, frame); MarkTileDirty(x, y); } -void DrawGraphicExt(DrawBuffer *dst_bitmap, int x, int y, int graphic) +#if 0 +void DrawOldGraphicExt(DrawBuffer *dst_bitmap, int x, int y, int graphic) { Bitmap *src_bitmap; int src_x, src_y; - getGraphicSource(graphic, &src_bitmap, &src_x, &src_y); + getOldGraphicSource(graphic, &src_bitmap, &src_x, &src_y); BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, TILEX, TILEY, x, y); } +#endif -void DrawNewGraphicExt(DrawBuffer *dst_bitmap, int x, int y, int graphic, - int frame) +void DrawGraphicExt(DrawBuffer *dst_bitmap, int x, int y, int graphic, + int frame) { +#if 1 + Bitmap *src_bitmap; + int src_x, src_y; + + 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; @@ -920,26 +927,12 @@ void DrawNewGraphicExt(DrawBuffer *dst_bitmap, int x, int y, int graphic, src_x += frame * offset_x; src_y += frame * offset_y; - - BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, TILEX, TILEY, x, y); -} - -void DrawGraphicThruMask(int x, int y, int graphic) -{ -#if DEBUG - if (!IN_SCR_FIELD(x, y)) - { - printf("DrawGraphicThruMask(): x = %d,y = %d, graphic = %d\n",x,y,graphic); - printf("DrawGraphicThruMask(): This should never happen!\n"); - return; - } #endif - DrawGraphicThruMaskExt(drawto_field, FX + x * TILEX, FY + y *TILEY, graphic); - MarkTileDirty(x, y); + BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, TILEX, TILEY, x, y); } -void DrawNewGraphicThruMask(int x, int y, int graphic, int frame) +void DrawGraphicThruMask(int x, int y, int graphic, int frame) { #if DEBUG if (!IN_SCR_FIELD(x, y)) @@ -950,50 +943,24 @@ void DrawNewGraphicThruMask(int x, int y, int graphic, int frame) } #endif - DrawNewGraphicThruMaskExt(drawto_field, FX + x * TILEX, FY + y *TILEY, - graphic, frame); + DrawGraphicThruMaskExt(drawto_field, FX + x * TILEX, FY + y *TILEY, graphic, + frame); MarkTileDirty(x, y); } -void DrawGraphicThruMaskExt(DrawBuffer *d, int dest_x, int dest_y, int graphic) +void DrawGraphicThruMaskExt(DrawBuffer *d, int dest_x, int dest_y, int graphic, + int frame) { - int tile = graphic; - int src_x, src_y; +#if 1 Bitmap *src_bitmap; + int src_x, src_y; GC drawing_gc; - if (graphic == GFX_LEERRAUM) - return; - - getGraphicSource(graphic, &src_bitmap, &src_x, &src_y); + getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y); drawing_gc = src_bitmap->stored_clip_gc; - - if (tile_clipmask[tile] != None) - { - SetClipMask(src_bitmap, tile_clip_gc, tile_clipmask[tile]); - SetClipOrigin(src_bitmap, tile_clip_gc, dest_x, dest_y); - BlitBitmapMasked(src_bitmap, d, - src_x, src_y, TILEX, TILEY, dest_x, dest_y); - } - else - { -#if DEBUG -#ifndef TARGET_SDL - printf("DrawGraphicThruMask(): tile '%d' needs clipping!\n", tile); -#endif -#endif - - SetClipOrigin(src_bitmap, drawing_gc, dest_x - src_x, dest_y - src_y); - BlitBitmapMasked(src_bitmap, d, - src_x, src_y, TILEX, TILEY, dest_x, dest_y); - } -} - -void DrawNewGraphicThruMaskExt(DrawBuffer *d, int dest_x, int dest_y, - int graphic, int frame) -{ - Bitmap *src_bitmap = new_graphic_info[graphic].bitmap; +#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; @@ -1002,198 +969,52 @@ void DrawNewGraphicThruMaskExt(DrawBuffer *d, int dest_x, int dest_y, src_x += frame * offset_x; src_y += frame * offset_y; +#endif + SetClipOrigin(src_bitmap, drawing_gc, dest_x - src_x, dest_y - src_y); BlitBitmapMasked(src_bitmap, d, src_x, src_y, TILEX, TILEY, dest_x, dest_y); } void DrawMiniGraphic(int x, int y, int graphic) { - DrawMiniGraphicExt(drawto, SX + x*MINI_TILEX, SY + y*MINI_TILEY, graphic); - MarkTileDirty(x/2, y/2); + DrawMiniGraphicExt(drawto, SX + x * MINI_TILEX,SY + y * MINI_TILEY, graphic); + MarkTileDirty(x / 2, y / 2); } void getMiniGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y) { - if (graphic >= GFX_START_ROCKSELEMENTS && graphic <= GFX_END_ROCKSELEMENTS) - { - graphic -= GFX_START_ROCKSELEMENTS; - *bitmap = pix[PIX_ELEMENTS]; - *x = MINI_GFX_STARTX + (graphic % MINI_GFX_PER_LINE) * MINI_TILEX; - *y = MINI_GFX_STARTY + (graphic / MINI_GFX_PER_LINE) * MINI_TILEY; - } - else if (graphic >= GFX_START_ROCKSSP && graphic <= GFX_END_ROCKSSP) - { - graphic -= GFX_START_ROCKSSP; - *bitmap = pix[PIX_SP]; - *x = MINI_SP_STARTX + (graphic % MINI_SP_PER_LINE) * MINI_TILEX; - *y = MINI_SP_STARTY + (graphic / MINI_SP_PER_LINE) * MINI_TILEY; - } - else if (graphic >= GFX_START_ROCKSDC && graphic <= GFX_END_ROCKSDC) - { - graphic -= GFX_START_ROCKSDC; - *bitmap = pix[PIX_DC]; - *x = MINI_DC_STARTX + (graphic % MINI_DC_PER_LINE) * MINI_TILEX; - *y = MINI_DC_STARTY + (graphic / MINI_DC_PER_LINE) * MINI_TILEY; - } - else if (graphic >= GFX_START_ROCKSMORE && graphic <= GFX_END_ROCKSMORE) - { - graphic -= GFX_START_ROCKSMORE; - *bitmap = pix[PIX_MORE]; - *x = MINI_MORE_STARTX + (graphic % MINI_MORE_PER_LINE) * MINI_TILEX; - *y = MINI_MORE_STARTY + (graphic / MINI_MORE_PER_LINE) * MINI_TILEY; - } - else if (graphic >= GFX_START_ROCKSFONT && graphic <= GFX_END_ROCKSFONT) - { - graphic -= GFX_START_ROCKSFONT; - *bitmap = pix[PIX_FONT_EM]; - *x = MINI_FONT_STARTX + (graphic % FONT_CHARS_PER_LINE) * FONT4_XSIZE; - *y = MINI_FONT_STARTY + (graphic / FONT_CHARS_PER_LINE) * FONT4_YSIZE; - } - else - { - *bitmap = pix[PIX_SP]; - *x = MINI_SP_STARTX; - *y = MINI_SP_STARTY; - } -} - -void DrawMiniGraphicExt(DrawBuffer *d, int x, int y, int graphic) -{ - Bitmap *bitmap; - int src_x, src_y; - - getMiniGraphicSource(graphic, &bitmap, &src_x, &src_y); - BlitBitmap(bitmap, d, src_x, src_y, MINI_TILEX, MINI_TILEY, x, y); -} - -void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, - int cut_mode, int mask_mode) -{ - int width = TILEX, height = TILEY; - int cx = 0, cy = 0; - int src_x, src_y, dest_x, dest_y; - int tile = graphic; - Bitmap *src_bitmap; - GC drawing_gc; + Bitmap *src_bitmap = new_graphic_info[graphic].bitmap; + 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 (graphic < 0) + if (src_x + MINI_TILEX > src_bitmap->width || + src_y + MINI_TILEY > src_bitmap->height) { - DrawGraphic(x, y, graphic); - return; - } + /* graphic of desired size seems not to be contained in this image; + dirty workaround: get it from the middle of the normal sized image */ - if (dx || dy) /* Verschiebung der Grafik? */ - { - if (x < BX1) /* Element kommt von links ins Bild */ - { - x = BX1; - width = dx; - cx = TILEX - dx; - dx = 0; - } - else if (x > BX2) /* Element kommt von rechts ins Bild */ - { - x = BX2; - width = -dx; - dx = TILEX + dx; - } - else if (x==BX1 && dx < 0) /* Element verläßt links das Bild */ - { - width += dx; - cx = -dx; - dx = 0; - } - else if (x==BX2 && dx > 0) /* Element verläßt rechts das Bild */ - width -= dx; - else if (dx) /* allg. Bewegung in x-Richtung */ - MarkTileDirty(x + SIGN(dx), y); - - if (y < BY1) /* Element kommt von oben ins Bild */ - { - if (cut_mode==CUT_BELOW) /* Element oberhalb des Bildes */ - return; - - y = BY1; - height = dy; - cy = TILEY - dy; - dy = 0; - } - else if (y > BY2) /* Element kommt von unten ins Bild */ - { - y = BY2; - height = -dy; - dy = TILEY + dy; - } - else if (y==BY1 && dy < 0) /* Element verläßt oben das Bild */ - { - height += dy; - cy = -dy; - dy = 0; - } - else if (dy > 0 && cut_mode == CUT_ABOVE) - { - if (y == BY2) /* Element unterhalb des Bildes */ - return; - - height = dy; - cy = TILEY - dy; - dy = TILEY; - MarkTileDirty(x, y + 1); - } /* Element verläßt unten das Bild */ - else if (dy > 0 && (y == BY2 || cut_mode == CUT_BELOW)) - height -= dy; - else if (dy) /* allg. Bewegung in y-Richtung */ - MarkTileDirty(x, y + SIGN(dy)); + getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y); + src_x += (TILEX / 2 - MINI_TILEX / 2); + src_y += (TILEY / 2 - MINI_TILEY / 2); } - getGraphicSource(graphic, &src_bitmap, &src_x, &src_y); - drawing_gc = src_bitmap->stored_clip_gc; - - src_x += cx; - src_y += cy; - - dest_x = FX + x * TILEX + dx; - dest_y = FY + y * TILEY + dy; - -#if DEBUG - if (!IN_SCR_FIELD(x,y)) - { - printf("DrawGraphicShifted(): x = %d, y = %d, graphic = %d\n",x,y,graphic); - printf("DrawGraphicShifted(): This should never happen!\n"); - return; - } -#endif - - if (mask_mode == USE_MASKING) - { - if (tile_clipmask[tile] != None) - { - SetClipMask(src_bitmap, tile_clip_gc, tile_clipmask[tile]); - SetClipOrigin(src_bitmap, tile_clip_gc, dest_x, dest_y); - BlitBitmapMasked(src_bitmap, drawto_field, - src_x, src_y, TILEX, TILEY, dest_x, dest_y); - } - else - { -#if DEBUG -#ifndef TARGET_SDL - printf("DrawGraphicShifted(): tile '%d' needs clipping!\n", tile); -#endif -#endif - - SetClipOrigin(src_bitmap, drawing_gc, dest_x - src_x, dest_y - src_y); - BlitBitmapMasked(src_bitmap, drawto_field, - src_x, src_y, width, height, dest_x, dest_y); - } - } - else - BlitBitmap(src_bitmap, drawto_field, - src_x, src_y, width, height, dest_x, dest_y); + *bitmap = src_bitmap; + *x = src_x; + *y = src_y; +} - MarkTileDirty(x,y); +void DrawMiniGraphicExt(DrawBuffer *d, int x, int y, int graphic) +{ + Bitmap *src_bitmap; + int src_x, src_y; + + getMiniGraphicSource(graphic, &src_bitmap, &src_x, &src_y); + BlitBitmap(src_bitmap, d, src_x, src_y, MINI_TILEX, MINI_TILEY, x, y); } -void DrawNewGraphicShifted(int x,int y, int dx,int dy, int graphic, int frame, +void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, int frame, int cut_mode, int mask_mode) { Bitmap *src_bitmap; @@ -1209,39 +1030,39 @@ void DrawNewGraphicShifted(int x,int y, int dx,int dy, int graphic, int frame, if (graphic < 0) { - DrawNewGraphic(x, y, graphic, frame); + DrawGraphic(x, y, graphic, frame); return; } - if (dx || dy) /* Verschiebung der Grafik? */ + if (dx || dy) /* shifted graphic */ { - if (x < BX1) /* Element kommt von links ins Bild */ + if (x < BX1) /* object enters playfield from the left */ { x = BX1; width = dx; cx = TILEX - dx; dx = 0; } - else if (x > BX2) /* Element kommt von rechts ins Bild */ + else if (x > BX2) /* object enters playfield from the right */ { x = BX2; width = -dx; dx = TILEX + dx; } - else if (x==BX1 && dx < 0) /* Element verläßt links das Bild */ + else if (x==BX1 && dx < 0) /* object leaves playfield to the left */ { width += dx; cx = -dx; dx = 0; } - else if (x==BX2 && dx > 0) /* Element verläßt rechts das Bild */ + else if (x==BX2 && dx > 0) /* object leaves playfield to the right */ width -= dx; - else if (dx) /* allg. Bewegung in x-Richtung */ + else if (dx) /* general horizontal movement */ MarkTileDirty(x + SIGN(dx), y); - if (y < BY1) /* Element kommt von oben ins Bild */ + if (y < BY1) /* object enters playfield from the top */ { - if (cut_mode==CUT_BELOW) /* Element oberhalb des Bildes */ + if (cut_mode==CUT_BELOW) /* object completely above top border */ return; y = BY1; @@ -1249,13 +1070,13 @@ void DrawNewGraphicShifted(int x,int y, int dx,int dy, int graphic, int frame, cy = TILEY - dy; dy = 0; } - else if (y > BY2) /* Element kommt von unten ins Bild */ + else if (y > BY2) /* object enters playfield from the bottom */ { y = BY2; height = -dy; dy = TILEY + dy; } - else if (y==BY1 && dy < 0) /* Element verläßt oben das Bild */ + else if (y==BY1 && dy < 0) /* object leaves playfield to the top */ { height += dy; cy = -dy; @@ -1263,27 +1084,28 @@ void DrawNewGraphicShifted(int x,int y, int dx,int dy, int graphic, int frame, } else if (dy > 0 && cut_mode == CUT_ABOVE) { - if (y == BY2) /* Element unterhalb des Bildes */ + if (y == BY2) /* object completely above bottom border */ return; height = dy; cy = TILEY - dy; dy = TILEY; MarkTileDirty(x, y + 1); - } /* Element verläßt unten das Bild */ + } /* object leaves playfield to the bottom */ else if (dy > 0 && (y == BY2 || cut_mode == CUT_BELOW)) height -= dy; - else if (dy) /* allg. Bewegung in y-Richtung */ + else if (dy) /* general vertical movement */ MarkTileDirty(x, y + SIGN(dy)); } src_bitmap = new_graphic_info[graphic].bitmap; - drawing_gc = src_bitmap->stored_clip_gc; 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; + src_x += frame * offset_x; src_y += frame * offset_y; @@ -1303,26 +1125,25 @@ void DrawNewGraphicShifted(int x,int y, int dx,int dy, int graphic, int frame, #endif if (mask_mode == USE_MASKING) + { SetClipOrigin(src_bitmap, drawing_gc, dest_x - src_x, dest_y - src_y); - - BlitBitmap(src_bitmap, drawto_field, src_x, src_y, width, height, - dest_x, dest_y); + BlitBitmapMasked(src_bitmap, drawto_field, src_x, src_y, width, height, + dest_x, dest_y); + } + else + BlitBitmap(src_bitmap, drawto_field, src_x, src_y, width, height, + dest_x, dest_y); MarkTileDirty(x,y); } void DrawGraphicShiftedThruMask(int x,int y, int dx,int dy, int graphic, - int cut_mode) -{ - DrawGraphicShifted(x,y, dx,dy, graphic, cut_mode, USE_MASKING); -} - -void DrawNewGraphicShiftedThruMask(int x,int y, int dx,int dy, int graphic, - int frame, int cut_mode) + int frame, int cut_mode) { - DrawNewGraphicShifted(x,y, dx,dy, graphic, frame, cut_mode, USE_MASKING); + 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) { @@ -1471,11 +1292,13 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, 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]; - int frame_pos = -1; if (element == EL_QUICKSAND_FULL || element == EL_MAGIC_WALL_FULL || @@ -1483,6 +1306,9 @@ inline static int getFramePosition(int x, int y) 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; } @@ -1491,23 +1317,45 @@ 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 + +#if DEBUG + if (gfx_action < 0) + printf("getGfxAction: THIS SHOULD NEVER HAPPEN: GfxAction[%d][%d] == %d\n", + x, y, gfx_action); +#endif return gfx_action; } -void DrawNewScreenElementExt(int x, int y, int dx, int dy, int element, +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 = getNewGraphicAnimationFrame(graphic, move_pos); + int graphic; + int frame; + + if (IN_LEV_FIELD(ux, uy)) + { + int move_dir = MovDir[ux][uy]; + int move_pos = getFramePosition(ux, uy); + int gfx_action = getGfxAction(ux, uy); + + graphic = el_dir_act2img(element, move_dir, gfx_action); + frame = getGraphicAnimationFrame(graphic, move_pos); + } + else + { + graphic = el2img(element); + frame = getGraphicAnimationFrame(graphic, 0); + } if (element == EL_WALL_GROWING) { @@ -1521,36 +1369,16 @@ void DrawNewScreenElementExt(int x, int y, int dx, int dy, int element, 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; + } else if (right_stopped) - graphic = IMG_WALL_GROWING_ACTIVE_LEFT; - } -#if 0 - 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 (move_dir == MV_LEFT) - graphic += (4 - phase4) % 4; - else if (move_dir == MV_RIGHT) - graphic += phase4; - else - graphic += phase2 * 2; - } - else if (element != EL_SP_INFOTRON) - graphic += phase2; + graphic = IMG_WALL_GROWING_ACTIVE_LEFT; + frame = new_graphic_info[graphic].anim_frames - 1; } } -#endif else if (IS_AMOEBOID(element) || element == EL_AMOEBA_DRIPPING) { graphic = (element == EL_BD_AMOEBA ? IMG_BD_AMOEBA_PART1 : @@ -1563,11 +1391,11 @@ void DrawNewScreenElementExt(int x, int y, int dx, int dy, int element, } if (dx || dy) - DrawNewGraphicShifted(x, y, dx, dy, graphic, frame, cut_mode, mask_mode); + DrawGraphicShifted(x, y, dx, dy, graphic, frame, cut_mode, mask_mode); else if (mask_mode == USE_MASKING) - DrawNewGraphicThruMask(x, y, graphic, frame); + DrawGraphicThruMask(x, y, graphic, frame); else - DrawNewGraphic(x, y, graphic, frame); + DrawGraphic(x, y, graphic, frame); } void DrawLevelElementExt(int x, int y, int dx, int dy, int element, @@ -1578,69 +1406,41 @@ void DrawLevelElementExt(int x, int y, int dx, int dy, int element, cut_mode, mask_mode); } -void DrawNewLevelElementExt(int x, int y, int dx, int dy, int element, - int cut_mode, int mask_mode) -{ - if (IN_LEV_FIELD(x, y) && IN_SCR_FIELD(SCREENX(x), SCREENY(y))) - DrawNewScreenElementExt(SCREENX(x), SCREENY(y), dx, dy, element, - cut_mode, mask_mode); -} - void DrawScreenElementShifted(int x, int y, int dx, int dy, int element, int cut_mode) { DrawScreenElementExt(x, y, dx, dy, element, cut_mode, NO_MASKING); } -void DrawNewScreenElementShifted(int x, int y, int dx, int dy, int element, - int cut_mode) -{ - DrawNewScreenElementExt(x, y, dx, dy, element, cut_mode, NO_MASKING); -} - void DrawLevelElementShifted(int x, int y, int dx, int dy, int element, int cut_mode) { DrawLevelElementExt(x, y, dx, dy, element, cut_mode, NO_MASKING); } -void DrawNewLevelElementShifted(int x, int y, int dx, int dy, int element, - int cut_mode) +#if 0 +void DrawOldScreenElementThruMask(int x, int y, int element) { - DrawNewLevelElementExt(x, y, dx, dy, element, cut_mode, NO_MASKING); + DrawOldScreenElementExt(x, y, 0, 0, element, NO_CUTTING, USE_MASKING); } void DrawScreenElementThruMask(int x, int y, int element) { DrawScreenElementExt(x, y, 0, 0, element, NO_CUTTING, USE_MASKING); } - -void DrawNewScreenElementThruMask(int x, int y, int element) -{ - DrawNewScreenElementExt(x, y, 0, 0, element, NO_CUTTING, USE_MASKING); -} +#endif void DrawLevelElementThruMask(int x, int y, int element) { DrawLevelElementExt(x, y, 0, 0, element, NO_CUTTING, USE_MASKING); } -void DrawNewLevelElementThruMask(int x, int y, int element) -{ - DrawNewLevelElementExt(x, y, 0, 0, element, NO_CUTTING, USE_MASKING); -} - void DrawLevelFieldThruMask(int x, int y) { DrawLevelElementExt(x, y, 0, 0, Feld[x][y], NO_CUTTING, USE_MASKING); } -void DrawNewLevelFieldThruMask(int x, int y) -{ - DrawNewLevelElementExt(x, y, 0, 0, Feld[x][y], NO_CUTTING, USE_MASKING); -} - -void ErdreichAnbroeckeln(int x, int y) +void DrawCrumbledSand(int x, int y) { Bitmap *src_bitmap; int src_x, src_y; @@ -1669,9 +1469,11 @@ void ErdreichAnbroeckeln(int x, int y) if (!IN_SCR_FIELD(x, y)) return; - graphic = GFX_ERDENRAND; + graphic = IMG_SAND_CRUMBLED; - getGraphicSource(graphic, &src_bitmap, &src_x, &src_y); + src_bitmap = new_graphic_info[graphic].bitmap; + src_x = new_graphic_info[graphic].src_x; + src_y = new_graphic_info[graphic].src_y; for(i=0; i<4; i++) { @@ -1713,9 +1515,11 @@ void ErdreichAnbroeckeln(int x, int y) } else { - graphic = GFX_ERDENRAND; + graphic = IMG_SAND_CRUMBLED; - getGraphicSource(graphic, &src_bitmap, &src_x, &src_y); + src_bitmap = new_graphic_info[graphic].bitmap; + src_x = new_graphic_info[graphic].src_x; + src_y = new_graphic_info[graphic].src_y; for(i=0; i<4; i++) { @@ -1760,13 +1564,7 @@ void ErdreichAnbroeckeln(int x, int y) void DrawScreenElement(int x, int y, int element) { DrawScreenElementExt(x, y, 0, 0, element, NO_CUTTING, NO_MASKING); - ErdreichAnbroeckeln(x, y); -} - -void DrawNewScreenElement(int x, int y, int element) -{ - DrawNewScreenElementExt(x, y, 0, 0, element, NO_CUTTING, NO_MASKING); - ErdreichAnbroeckeln(x, y); + DrawCrumbledSand(x, y); } void DrawLevelElement(int x, int y, int element) @@ -1775,12 +1573,6 @@ void DrawLevelElement(int x, int y, int element) DrawScreenElement(SCREENX(x), SCREENY(y), element); } -void DrawNewLevelElement(int x, int y, int element) -{ - if (IN_LEV_FIELD(x, y) && IN_SCR_FIELD(SCREENX(x), SCREENY(y))) - DrawNewScreenElement(SCREENX(x), SCREENY(y), element); -} - void DrawScreenField(int x, int y) { int ux = LEVELX(x), uy = LEVELY(y); @@ -1871,96 +1663,6 @@ void DrawScreenField(int x, int y) DrawScreenElement(x, y, EL_EMPTY); } -void DrawNewScreenField(int x, int y) -{ - int ux = LEVELX(x), uy = LEVELY(y); - int element, content; - - if (!IN_LEV_FIELD(ux, uy)) - { - if (ux < -1 || ux > lev_fieldx || uy < -1 || uy > lev_fieldy) - element = EL_EMPTY; - else - element = BorderElement; - - DrawNewScreenElement(x, y, element); - return; - } - - element = Feld[ux][uy]; - content = Store[ux][uy]; - - if (IS_MOVING(ux, uy)) - { - int horiz_move = (MovDir[ux][uy] == MV_LEFT || MovDir[ux][uy] == 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) - cut_mode = CUT_ABOVE; - else if (element == EL_QUICKSAND_FILLING || - element == EL_MAGIC_WALL_FILLING || - element == EL_BD_MAGIC_WALL_FILLING) - cut_mode = CUT_BELOW; - - if (cut_mode == CUT_ABOVE) - DrawNewScreenElementShifted(x, y, 0, 0, element, NO_CUTTING); - else - DrawNewScreenElement(x, y, EL_EMPTY); - - if (horiz_move) - DrawNewScreenElementShifted(x, y, MovPos[ux][uy], 0, element, NO_CUTTING); - else if (cut_mode == NO_CUTTING) - DrawNewScreenElementShifted(x, y, 0, MovPos[ux][uy], element, cut_mode); - else - DrawNewScreenElementShifted(x, y, 0, MovPos[ux][uy], content, cut_mode); - - if (content == EL_ACID) - DrawNewLevelElementThruMask(ux, uy + 1, EL_ACID); - } - else if (IS_BLOCKED(ux, uy)) - { - int oldx, oldy; - int sx, sy; - int horiz_move; - boolean cut_mode = NO_CUTTING; - int element_old, content_old; - - Blocked2Moving(ux, uy, &oldx, &oldy); - sx = SCREENX(oldx); - sy = SCREENY(oldy); - horiz_move = (MovDir[oldx][oldy] == MV_LEFT || - MovDir[oldx][oldy] == MV_RIGHT); - - element_old = Feld[oldx][oldy]; - content_old = Store[oldx][oldy]; - - if (element_old == EL_QUICKSAND_EMPTYING || - element_old == EL_MAGIC_WALL_EMPTYING || - element_old == EL_BD_MAGIC_WALL_EMPTYING || - element_old == EL_AMOEBA_DRIPPING) - cut_mode = CUT_ABOVE; - - DrawNewScreenElement(x, y, EL_EMPTY); - - if (horiz_move) - DrawNewScreenElementShifted(sx, sy, MovPos[oldx][oldy], 0, element_old, - NO_CUTTING); - else if (cut_mode == NO_CUTTING) - DrawNewScreenElementShifted(sx, sy, 0, MovPos[oldx][oldy], element_old, - cut_mode); - else - DrawNewScreenElementShifted(sx, sy, 0, MovPos[oldx][oldy], content_old, - cut_mode); - } - else if (IS_DRAWABLE(element)) - DrawNewScreenElement(x, y, element); - else - DrawNewScreenElement(x, y, EL_EMPTY); -} - void DrawLevelField(int x, int y) { if (IN_SCR_FIELD(SCREENX(x), SCREENY(y))) @@ -1983,39 +1685,11 @@ void DrawLevelField(int x, int y) } } -void DrawNewLevelField(int x, int y) -{ - if (IN_SCR_FIELD(SCREENX(x), SCREENY(y))) - DrawNewScreenField(SCREENX(x), SCREENY(y)); - else if (IS_MOVING(x, y)) - { - int newx,newy; - - Moving2Blocked(x, y, &newx, &newy); - if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy))) - DrawNewScreenField(SCREENX(newx), SCREENY(newy)); - } - else if (IS_BLOCKED(x, y)) - { - int oldx, oldy; - - Blocked2Moving(x, y, &oldx, &oldy); - if (IN_SCR_FIELD(SCREENX(oldx), SCREENY(oldy))) - DrawNewScreenField(SCREENX(oldx), SCREENY(oldy)); - } -} - void DrawMiniElement(int x, int y, int element) { int graphic; - if (!element) - { - DrawMiniGraphic(x, y, -1); - return; - } - - graphic = el2gfx(element); + graphic = el2img(element); DrawMiniGraphic(x, y, graphic); } @@ -2032,12 +1706,12 @@ void DrawMiniElementOrWall(int sx, int sy, int scroll_x, int scroll_y) int steel_type, steel_position; int border[6][2] = { - { GFX_VSTEEL_UPPER_LEFT, GFX_ISTEEL_UPPER_LEFT }, - { GFX_VSTEEL_UPPER_RIGHT, GFX_ISTEEL_UPPER_RIGHT }, - { GFX_VSTEEL_LOWER_LEFT, GFX_ISTEEL_LOWER_LEFT }, - { GFX_VSTEEL_LOWER_RIGHT, GFX_ISTEEL_LOWER_RIGHT }, - { GFX_VSTEEL_VERTICAL, GFX_ISTEEL_VERTICAL }, - { GFX_VSTEEL_HORIZONTAL, GFX_ISTEEL_HORIZONTAL } + { 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); @@ -2053,58 +1727,46 @@ void DrawMiniElementOrWall(int sx, int sy, int scroll_x, int scroll_y) } } -void DrawMicroElement(int xpos, int ypos, int element) +void getMicroGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y) { - int graphic; - - if (element == EL_EMPTY) - return; - - graphic = el2gfx(element); + Bitmap *src_bitmap = new_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; - if (graphic >= GFX_START_ROCKSSP && graphic <= GFX_END_ROCKSSP) - { - graphic -= GFX_START_ROCKSSP; - BlitBitmap(pix[PIX_SP], drawto, - MICRO_SP_STARTX + (graphic % MICRO_SP_PER_LINE) * MICRO_TILEX, - MICRO_SP_STARTY + (graphic / MICRO_SP_PER_LINE) * MICRO_TILEY, - MICRO_TILEX, MICRO_TILEY, xpos, ypos); - } - else if (graphic >= GFX_START_ROCKSDC && graphic <= GFX_END_ROCKSDC) - { - graphic -= GFX_START_ROCKSDC; - BlitBitmap(pix[PIX_DC], drawto, - MICRO_DC_STARTX + (graphic % MICRO_DC_PER_LINE) * MICRO_TILEX, - MICRO_DC_STARTY + (graphic / MICRO_DC_PER_LINE) * MICRO_TILEY, - MICRO_TILEX, MICRO_TILEY, xpos, ypos); - } - else if (graphic >= GFX_START_ROCKSMORE && graphic <= GFX_END_ROCKSMORE) - { - graphic -= GFX_START_ROCKSMORE; - BlitBitmap(pix[PIX_MORE], drawto, - MICRO_MORE_STARTX + (graphic % MICRO_MORE_PER_LINE)*MICRO_TILEX, - MICRO_MORE_STARTY + (graphic / MICRO_MORE_PER_LINE)*MICRO_TILEY, - MICRO_TILEX, MICRO_TILEY, xpos, ypos); - } - else if (graphic >= GFX_CHAR_START && graphic <= GFX_CHAR_END) + if (src_x + MICRO_TILEX > src_bitmap->width || + src_y + MICRO_TILEY > src_bitmap->height) { - graphic -= GFX_CHAR_START; - BlitBitmap(pix[PIX_FONT_EM], drawto, - MICRO_FONT_STARTX + (graphic % MICRO_GFX_PER_LINE)* MICRO_TILEX, - MICRO_FONT_STARTY + (graphic / MICRO_GFX_PER_LINE)* MICRO_TILEY, - MICRO_TILEX, MICRO_TILEY, xpos, ypos); + /* 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 - MICRO_TILEX / 2); + src_y += (TILEY / 2 - MICRO_TILEY / 2); } - else - BlitBitmap(pix[PIX_ELEMENTS], drawto, - MICRO_GFX_STARTX + (graphic % MICRO_GFX_PER_LINE) * MICRO_TILEX, - MICRO_GFX_STARTY + (graphic / MICRO_GFX_PER_LINE) * MICRO_TILEY, - MICRO_TILEX, MICRO_TILEY, xpos, ypos); + + *bitmap = src_bitmap; + *x = src_x; + *y = src_y; +} + +void DrawMicroElement(int xpos, int ypos, int element) +{ + Bitmap *src_bitmap; + int src_x, src_y; + int graphic = el2img(element); + + getMicroGraphicSource(graphic, &src_bitmap, &src_x, &src_y); + BlitBitmap(src_bitmap, drawto, src_x, src_y, MICRO_TILEX, MICRO_TILEY, + xpos, ypos); } void DrawLevel() { int x,y; + SetDrawBackgroundMask(REDRAW_NONE); ClearWindow(); for(x=BX1; x<=BX2; x++) @@ -2129,7 +1791,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; @@ -2148,7 +1810,8 @@ 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); } @@ -2170,7 +1833,7 @@ static void DrawMicroLevelLabelExt(int mode) { char label_text[MAX_MICROLABEL_SIZE + 1]; - ClearRectangle(drawto, SX, MICROLABEL_YPOS, SXSIZE, FONT4_YSIZE); + DrawBackground(SX, MICROLABEL_YPOS, SXSIZE, FONT4_YSIZE); strncpy(label_text, (mode == MICROLABEL_LEVEL_NAME ? level.name : mode == MICROLABEL_CREATED_BY ? "created by" : @@ -2318,12 +1981,14 @@ boolean Request(char *text, unsigned int req_state) CloseDoor(DOOR_CLOSE_1); /* save old door content */ - BlitBitmap(pix[PIX_DB_DOOR], pix[PIX_DB_DOOR], + BlitBitmap(bitmap_db_door, bitmap_db_door, 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); /* write text for request */ for(ty=0; ty < MAX_REQUEST_LINES; ty++) @@ -2351,8 +2016,8 @@ 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 + 50 - (tl * 14)/2, DY + 8 + ty * 16, + text_line, FS_SMALL, FC_YELLOW); text += tl + (tc == ' ' ? 1 : 0); } @@ -2375,7 +2040,7 @@ boolean Request(char *text, unsigned int req_state) } /* copy request gadgets to door backbuffer */ - BlitBitmap(drawto, pix[PIX_DB_DOOR], + BlitBitmap(drawto, bitmap_db_door, DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1); @@ -2386,7 +2051,11 @@ 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) InitAnimation(); @@ -2395,6 +2064,8 @@ boolean Request(char *text, unsigned int req_state) request_gadget_id = -1; + SetDrawBackgroundMask(REDRAW_FIELD | REDRAW_DOOR_1); + while(result < 0) { if (PendingEvent()) @@ -2521,7 +2192,7 @@ boolean Request(char *text, unsigned int req_state) if (!(req_state & REQ_STAY_CLOSED) && (old_door_state & DOOR_OPEN_1)) { - BlitBitmap(pix[PIX_DB_DOOR], pix[PIX_DB_DOOR], + BlitBitmap(bitmap_db_door, bitmap_db_door, DOOR_GFX_PAGEX2,DOOR_GFX_PAGEY1, DXSIZE,DYSIZE, DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY1); OpenDoor(DOOR_OPEN_1); @@ -2530,6 +2201,8 @@ boolean Request(char *text, unsigned int req_state) RemapAllGadgets(); + SetDrawBackgroundMask(REDRAW_FIELD); + #if defined(PLATFORM_UNIX) /* continue network game after request */ if (options.network && @@ -2538,7 +2211,7 @@ boolean Request(char *text, unsigned int req_state) SendToServer_ContinuePlaying(); #endif - return(result); + return result; } unsigned int OpenDoor(unsigned int door_state) @@ -2547,7 +2220,7 @@ unsigned int OpenDoor(unsigned int door_state) if (door_state & DOOR_COPY_BACK) { - BlitBitmap(pix[PIX_DB_DOOR], pix[PIX_DB_DOOR], + BlitBitmap(bitmap_db_door, bitmap_db_door, DOOR_GFX_PAGEX2, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE + VYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1); door_state &= ~DOOR_COPY_BACK; @@ -2562,9 +2235,9 @@ unsigned int CloseDoor(unsigned int door_state) { unsigned int new_door_state; - BlitBitmap(backbuffer, pix[PIX_DB_DOOR], + BlitBitmap(backbuffer, bitmap_db_door, DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1); - BlitBitmap(backbuffer, pix[PIX_DB_DOOR], + BlitBitmap(backbuffer, bitmap_db_door, VX, VY, VXSIZE, VYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY2); new_door_state = MoveDoor(door_state); @@ -2616,10 +2289,17 @@ unsigned int MoveDoor(unsigned int door_state) { stepsize = 20; door_delay_value = 0; + StopSound(SND_MENU_DOOR_OPENING); StopSound(SND_MENU_DOOR_CLOSING); } + if (global.autoplay_leveldir) + { + door_state |= DOOR_NO_DELAY; + door_state &= ~DOOR_CLOSE_ALL; + } + if (door_state & DOOR_ACTION) { if (!(door_state & DOOR_NO_DELAY)) @@ -2635,17 +2315,18 @@ unsigned int MoveDoor(unsigned int door_state) for(x=start; x<=DXSIZE; x+=stepsize) { - Bitmap *bitmap = pix[PIX_DOOR]; + Bitmap *bitmap = new_graphic_info[IMG_GLOBAL_DOOR].bitmap; GC gc = bitmap->stored_clip_gc; - WaitUntilDelayReached(&door_delay, door_delay_value); + if (!(door_state & DOOR_NO_DELAY)) + WaitUntilDelayReached(&door_delay, door_delay_value); if (door_state & DOOR_ACTION_1) { int i = (door_state & DOOR_OPEN_1 ? DXSIZE-x : x); int j = (DXSIZE - i) / 3; - BlitBitmap(pix[PIX_DB_DOOR], drawto, + BlitBitmap(bitmap_db_door, drawto, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1 + i/2, DXSIZE,DYSIZE - i/2, DX, DY); @@ -2688,7 +2369,7 @@ unsigned int MoveDoor(unsigned int door_state) int i = (door_state & DOOR_OPEN_2 ? VXSIZE - x : x); int j = (VXSIZE - i) / 3; - BlitBitmap(pix[PIX_DB_DOOR], drawto, + BlitBitmap(bitmap_db_door, drawto, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY2 + i/2, VXSIZE, VYSIZE - i/2, VX, VY); @@ -2740,8 +2421,12 @@ unsigned int MoveDoor(unsigned int door_state) void DrawSpecialEditorDoor() { /* draw bigger toolbox window */ - BlitBitmap(pix[PIX_DOOR], drawto, - DOOR_GFX_PAGEX7, 0, 108, 56, EX - 4, EY - 12); + BlitBitmap(new_graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, + DOOR_GFX_PAGEX7, 0, EXSIZE + 8, 8, + EX - 4, EY - 12); + BlitBitmap(new_graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto, + EX - 4, VY - 4, EXSIZE + 8, EYSIZE - VYSIZE + 4, + EX - 4, EY - 4); redraw_mask |= REDRAW_ALL; } @@ -2749,8 +2434,9 @@ void DrawSpecialEditorDoor() void UndrawSpecialEditorDoor() { /* draw normal tape recorder window */ - BlitBitmap(pix[PIX_BACK], drawto, - 562, 344, 108, 56, EX - 4, EY - 12); + BlitBitmap(new_graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto, + EX - 4, EY - 12, EXSIZE + 8, EYSIZE - VYSIZE + 12, + EX - 4, EY - 12); redraw_mask |= REDRAW_ALL; } @@ -2878,7 +2564,7 @@ void CreateToolButtons() for (i=0; i= TOOL_CTRL_ID_PLAYER_1 && id <= TOOL_CTRL_ID_PLAYER_4) { - getMiniGraphicSource(GFX_SPIELER1 + id - TOOL_CTRL_ID_PLAYER_1, + int player_nr = id - TOOL_CTRL_ID_PLAYER_1; + + getMiniGraphicSource(PLAYER_NR_GFX(IMG_PLAYER1, player_nr), &deco_bitmap, &deco_x, &deco_y); deco_xpos = (toolbutton_info[i].width - MINI_TILEX) / 2; deco_ypos = (toolbutton_info[i].height - MINI_TILEY) / 2; @@ -2928,6 +2616,14 @@ void CreateToolButtons() } } +void FreeToolButtons() +{ + int i; + + for (i=0; i graphic %d -- probably crashing now...", + element, graphic); #endif + + return graphic; } int el_dir2img(int element, int direction) @@ -3311,6 +2997,24 @@ int el_dir2img(int element, int direction) int el_dir_act2img(int element, int direction, int action) { +#if DEBUG + if (element < 0) + { + printf("el_dir_act2img: THIS SHOULD NEVER HAPPEN: element == %d\n", + element); + + return IMG_EMPTY; + } + + if (action < 0) + { + printf("el_dir_act2img: THIS SHOULD NEVER HAPPEN: action == %d\n", + action); + + return IMG_EMPTY; + } +#endif + action = graphics_action_mapping[action]; direction = MV_DIR_BIT(direction);