X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ftools.c;h=9b972e7df955a0557e9876d2c413142ab35859eb;hb=3fd727f8ab7628eaab0be7de31658d7d468d6c8d;hp=b0ffdcf7b7bc148ca9000f7c87cdc2243780ca6e;hpb=dfe0a71a9939e0c55bb54dcc92db1749e8e21747;p=rocksndiamonds.git diff --git a/src/tools.c b/src/tools.c index b0ffdcf7..9b972e7d 100644 --- a/src/tools.c +++ b/src/tools.c @@ -1,7 +1,7 @@ /*********************************************************** * Rocks'n'Diamonds -- McDuffin Strikes Back! * *----------------------------------------------------------* -* (c) 1995-2001 Artsoft Entertainment * +* (c) 1995-2002 Artsoft Entertainment * * Holger Schemel * * Detmolder Strasse 189 * * 33604 Bielefeld * @@ -20,10 +20,6 @@ #include "network.h" #include "tape.h" -#if defined(PLATFORM_MSDOS) -extern boolean wait_for_vsync; -#endif - /* tool button identifiers */ #define TOOL_CTRL_ID_YES 0 #define TOOL_CTRL_ID_NO 1 @@ -36,9 +32,6 @@ extern boolean wait_for_vsync; #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 *); @@ -390,6 +383,39 @@ void ClearWindow() 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) { int xx = redraw_x1 + x; @@ -406,14 +432,14 @@ void SetBorderElement() { int x, y; - BorderElement = EL_LEERRAUM; + BorderElement = EL_EMPTY; - for(y=0; yactive || !IN_SCR_FIELD(SCREENX(last_jx), SCREENY(last_jy))) @@ -462,7 +489,7 @@ void DrawPlayer(struct PlayerInfo *player) } #endif - if (element == EL_EXPLODING) + if (element == EL_EXPLOSION) return; /* draw things in the field the player is leaving, if needed */ @@ -472,6 +499,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 @@ -486,10 +514,10 @@ void DrawPlayer(struct PlayerInfo *player) { if (player->GfxPos) { - if (Feld[next_jx][next_jy] == EL_SOKOBAN_FELD_VOLL) - DrawLevelElement(next_jx, next_jy, EL_SOKOBAN_FELD_LEER); + if (Feld[next_jx][next_jy] == EL_SOKOBAN_FIELD_FULL) + DrawLevelElement(next_jx, next_jy, EL_SOKOBAN_FIELD_EMPTY); else - DrawLevelElement(next_jx, next_jy, EL_LEERRAUM); + DrawLevelElement(next_jx, next_jy, EL_EMPTY); } else DrawLevelField(next_jx, next_jy); @@ -509,7 +537,7 @@ void DrawPlayer(struct PlayerInfo *player) else if (!IS_ACTIVE_BOMB(element)) DrawLevelField(jx, jy); else - DrawLevelElement(jx, jy, EL_LEERRAUM); + DrawLevelElement(jx, jy, EL_EMPTY); /* draw player himself */ @@ -523,44 +551,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_OSCILLATE); + frame = getGraphicAnimationFrame(graphic, -1); } if (player->MovDir == MV_LEFT || player->MovDir == MV_RIGHT) @@ -569,18 +597,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->index_nr * 3 * HEROES_PER_LINE; - graphic += player->Frame; + graphic = PLAYER_NR_GFX(graphic, player->index_nr); + +#if 0 + frame = player->Frame; +#else + frame = getGraphicAnimationFrame(graphic, player->Frame); +#endif } if (player->GfxPos) @@ -594,43 +633,73 @@ 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_OSCILLATE); + 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_FELD_LEER || - Feld[next_jx][next_jy] == EL_SOKOBAN_FELD_VOLL) - DrawGraphicShiftedThruMask(px, py, sxx, syy, GFX_SOKOBAN_OBJEKT, + if (element == EL_SOKOBAN_FIELD_EMPTY || + Feld[next_jx][next_jy] == EL_SOKOBAN_FIELD_FULL) + DrawGraphicShiftedThruMask(px, py, sxx, syy, GFX_SOKOBAN_OBJEKT, 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_FELSBROCKEN || - element == EL_SP_ZONK || - element == EL_BD_ROCK) && sxx) + if ((element == EL_ROCK || + element == EL_BD_ROCK || + element == EL_SP_ZONK) && sxx) { - 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); } } @@ -638,39 +707,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, GFX_SP_DISK_RED, 0); else - DrawGraphicThruMask(sx, sy, graphic + phase); + DrawGraphicThruMask(sx, sy, graphic, frame); } - if (player_is_moving && last_element == EL_EXPLODING) + 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); @@ -690,143 +768,154 @@ 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_OSCILLATE) - { - 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); -} - -void DrawGraphicAnimationExt(int x, int y, int graphic, - int frames, int delay, int mode, int mask_mode) -{ - int phase = getGraphicAnimationPhase(frames, delay, mode); - - 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); - } -} - -void DrawGraphicAnimation(int x, int y, int graphic, - int frames, int delay, int mode) -{ - DrawGraphicAnimationExt(x, y, graphic, frames, delay, mode, 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); + DrawGraphicExt(dst_bitmap, x, y, graphic, frame); } -static void DrawGraphicAnimationShiftedThruMask(int sx, int sy, - int sxx, int syy, - int graphic, - int frames, int delay, - int 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; - DrawGraphicShiftedThruMask(sx, sy, sxx, syy, graphic + phase, NO_CUTTING); + DrawGraphicAnimationExt(drawto_field, FX + x * TILEX, FY + y * TILEY, + graphic, NO_MASKING); + MarkTileDirty(x, y); } -void getGraphicSource(int graphic, int *bitmap_nr, int *x, int *y) +#if 0 +void getOldGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y) { - if (graphic >= GFX_START_ROCKSSCREEN && graphic <= GFX_END_ROCKSSCREEN) + if (graphic >= 0 && graphic_info[graphic].bitmap != NULL) { - graphic -= GFX_START_ROCKSSCREEN; - *bitmap_nr = PIX_BACK; - *x = SX + (graphic % GFX_PER_LINE) * TILEX; - *y = SY + (graphic / GFX_PER_LINE) * TILEY; + *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_nr = 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_nr = 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_nr = 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_nr = 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_nr = PIX_BIGFONT; + *bitmap = new_graphic_info[IMG_OLD_PIX_FONT_EM].bitmap; *x = (graphic % FONT_CHARS_PER_LINE) * TILEX; - *y = ((graphic / FONT_CHARS_PER_LINE) * TILEY + - FC_SPECIAL1 * FONT_LINES_PER_FONT * TILEY); + *y = (graphic / FONT_CHARS_PER_LINE) * TILEY; } else { - *bitmap_nr = PIX_SP; + *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) +void DrawGraphic(int x, int y, int graphic, int frame) { #if DEBUG - if (!IN_SCR_FIELD(x,y)) + if (!IN_SCR_FIELD(x, y)) { - printf("DrawGraphic(): x = %d, y = %d, graphic = %d\n",x,y,graphic); + printf("DrawGraphic(): x = %d, y = %d, graphic = %d\n", x, y, graphic); printf("DrawGraphic(): This should never happen!\n"); return; } #endif - DrawGraphicExt(drawto_field, FX + x*TILEX, FY + y*TILEY, graphic); - MarkTileDirty(x,y); + DrawGraphicExt(drawto_field, FX + x * TILEX, FY + y * TILEY, graphic, frame); + MarkTileDirty(x, y); } -void DrawGraphicExt(DrawBuffer *bitmap, int x, int y, int graphic) +#if 0 +void DrawOldGraphicExt(DrawBuffer *dst_bitmap, int x, int y, int graphic) { - int bitmap_nr; + Bitmap *src_bitmap; int src_x, src_y; - getGraphicSource(graphic, &bitmap_nr, &src_x, &src_y); - BlitBitmap(pix[bitmap_nr], bitmap, src_x, src_y, TILEX, TILEY, x, y); + getOldGraphicSource(graphic, &src_bitmap, &src_x, &src_y); + BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, TILEX, TILEY, x, y); } +#endif -void DrawGraphicThruMask(int x, int y, int graphic) +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; + int offset_x = new_graphic_info[graphic].offset_x; + int offset_y = new_graphic_info[graphic].offset_y; + + src_x += frame * offset_x; + src_y += frame * offset_y; +#endif + + BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, TILEX, TILEY, x, y); +} + +void DrawGraphicThruMask(int x, int y, int graphic, int frame) { #if DEBUG - if (!IN_SCR_FIELD(x,y)) + 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"); @@ -834,154 +923,126 @@ void DrawGraphicThruMask(int x, int y, int graphic) } #endif - DrawGraphicThruMaskExt(drawto_field, FX + x*TILEX, FY + y*TILEY, graphic); - MarkTileDirty(x,y); + 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 bitmap_nr; - 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, frame, &src_bitmap, &src_x, &src_y); + 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; - getGraphicSource(graphic, &bitmap_nr, &src_x, &src_y); - src_bitmap = pix[bitmap_nr]; - drawing_gc = pix[bitmap_nr]->stored_clip_gc; + src_x += frame * offset_x; + src_y += frame * offset_y; - 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); - } + 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_ROCKSSCREEN && graphic <= GFX_END_ROCKSSCREEN) - { - graphic -= GFX_START_ROCKSSCREEN; - *bitmap = pix[PIX_BACK]; - *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; - graphic -= ((graphic / SP_PER_LINE) * SP_PER_LINE) / 2; - *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_SMALLFONT]; - *x = (graphic % FONT_CHARS_PER_LINE) * FONT4_XSIZE; - *y = ((graphic / FONT_CHARS_PER_LINE) * FONT4_YSIZE + - FC_SPECIAL2 * FONT2_YSIZE * FONT_LINES_PER_FONT); - } - else + 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 (src_x + MINI_TILEX > src_bitmap->width || + src_y + MINI_TILEY > src_bitmap->height) { - *bitmap = pix[PIX_SP]; - *x = MINI_SP_STARTX; - *y = MINI_SP_STARTY; + /* 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); } + + *bitmap = src_bitmap; + *x = src_x; + *y = src_y; } void DrawMiniGraphicExt(DrawBuffer *d, int x, int y, int graphic) { - Bitmap *bitmap; + Bitmap *src_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); + getMiniGraphicSource(graphic, &src_bitmap, &src_x, &src_y); + BlitBitmap(src_bitmap, d, src_x, src_y, MINI_TILEX, MINI_TILEY, x, y); } -void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, +void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, int frame, 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; - int bitmap_nr; Bitmap *src_bitmap; GC drawing_gc; + int src_x; + int src_y; + int offset_x; + int offset_y; + + int width = TILEX, height = TILEY; + int cx = 0, cy = 0; + int dest_x, dest_y; if (graphic < 0) { - DrawGraphic(x, y, graphic); + 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; @@ -989,13 +1050,13 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, 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; @@ -1003,23 +1064,30 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, } 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)); } - getGraphicSource(graphic, &bitmap_nr, &src_x, &src_y); - src_bitmap = pix[bitmap_nr]; - drawing_gc = pix[bitmap_nr]->stored_clip_gc; + 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; + + src_x += frame * offset_x; + src_y += frame * offset_y; src_x += cx; src_y += cy; @@ -1038,39 +1106,24 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, 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); - } + 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(pix[bitmap_nr], drawto_field, - src_x, src_y, width, height, dest_x, dest_y); + 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) + int frame, int cut_mode) { - DrawGraphicShifted(x,y, dx,dy, graphic, 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) { @@ -1081,16 +1134,16 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, int phase2 = phase8 / 4; int dir = MovDir[ux][uy]; - if (element == EL_PACMAN || element == EL_KAEFER || element == EL_FLIEGER) + if (element == EL_PACMAN || element == EL_BUG || element == EL_SPACESHIP) { - graphic += 4 * !phase2; + graphic += 1 * !phase2; if (dir == MV_UP) - graphic += 1; + graphic += 1 * 2; else if (dir == MV_LEFT) - graphic += 2; + graphic += 2 * 2; else if (dir == MV_DOWN) - graphic += 3; + graphic += 3 * 2; } else if (element == EL_SP_SNIKSNAK) { @@ -1107,39 +1160,39 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, } else if (element == EL_SP_ELECTRON) { - graphic = GFX2_SP_ELECTRON + getGraphicAnimationPhase(8, 2, ANIM_NORMAL); + graphic = GFX2_SP_ELECTRON + getGraphicAnimationPhase(8, 2, ANIM_LOOP); } - else if (element == EL_MOLE || element == EL_PINGUIN || - element == EL_SCHWEIN || element == EL_DRACHE) + else if (element == EL_MOLE || element == EL_PENGUIN || + element == EL_PIG || element == EL_DRAGON) { if (dir == MV_LEFT) graphic = (element == EL_MOLE ? GFX_MOLE_LEFT : - element == EL_PINGUIN ? GFX_PINGUIN_LEFT : - element == EL_SCHWEIN ? GFX_SCHWEIN_LEFT : GFX_DRACHE_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_PINGUIN ? GFX_PINGUIN_RIGHT : - element == EL_SCHWEIN ? GFX_SCHWEIN_RIGHT : GFX_DRACHE_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_PINGUIN ? GFX_PINGUIN_UP : - element == EL_SCHWEIN ? GFX_SCHWEIN_UP : GFX_DRACHE_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_PINGUIN ? GFX_PINGUIN_DOWN : - element == EL_SCHWEIN ? GFX_SCHWEIN_DOWN : GFX_DRACHE_DOWN); + element == EL_PENGUIN ? GFX_PINGUIN_DOWN : + element == EL_PIG ? GFX_SCHWEIN_DOWN : GFX_DRACHE_DOWN); graphic += phase4; } - else if (element == EL_SONDE) + else if (element == EL_SATELLITE) { - graphic = GFX_SONDE_START + getGraphicAnimationPhase(8, 2, ANIM_NORMAL); + graphic = GFX_SONDE_START + getGraphicAnimationPhase(8, 2, ANIM_LOOP); } - else if (element == EL_SALZSAEURE) + else if (element == EL_ACID) { - graphic = GFX_GEBLUBBER + getGraphicAnimationPhase(4, 10, ANIM_NORMAL); + graphic = GFX_GEBLUBBER + getGraphicAnimationPhase(4, 10, ANIM_LOOP); } - else if (element == EL_BUTTERFLY || element == EL_FIREFLY) + else if (element == EL_BD_BUTTERFLY || element == EL_BD_FIREFLY) { graphic += !phase2; } @@ -1147,7 +1200,7 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, { graphic += phase4; } - else if ((element == EL_FELSBROCKEN || + else if ((element == EL_ROCK || element == EL_SP_ZONK || element == EL_BD_ROCK || element == EL_SP_INFOTRON || @@ -1156,7 +1209,7 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, { if (uy >= lev_fieldy-1 || !IS_BELT(Feld[ux][uy+1])) { - if (element == EL_FELSBROCKEN || + if (element == EL_ROCK || element == EL_SP_ZONK || element == EL_BD_ROCK) { @@ -1171,21 +1224,21 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, graphic += phase2; } } - else if (element == EL_MAGIC_WALL_EMPTY || + else if (element == EL_MAGIC_WALL_ACTIVE || element == EL_MAGIC_WALL_EMPTYING || - element == EL_MAGIC_WALL_BD_EMPTY || - element == EL_MAGIC_WALL_BD_EMPTYING || + element == EL_BD_MAGIC_WALL_ACTIVE || + element == EL_BD_MAGIC_WALL_EMPTYING || element == EL_MAGIC_WALL_FULL || - element == EL_MAGIC_WALL_BD_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_AMOEBE_TOT ? GFX_AMOEBE_TOT : GFX_AMOEBE_LEBT); + graphic = (element == EL_AMOEBA_DEAD ? GFX_AMOEBE_TOT : GFX_AMOEBE_LEBT); graphic += (x + 2 * y + 4) % 4; } - else if (element == EL_MAUER_LEBT) + else if (element == EL_WALL_GROWING) { boolean links_massiv = FALSE, rechts_massiv = FALSE; @@ -1201,14 +1254,16 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, else if (rechts_massiv) graphic = GFX_MAUER_L; } - else if ((element == EL_INVISIBLE_STEEL || - element == EL_UNSICHTBAR || - element == EL_SAND_INVISIBLE) && game.light_time_left) +#if 0 + else if ((element == EL_INVISIBLE_STEELWALL || + element == EL_INVISIBLE_WALL || + element == EL_INVISIBLE_SAND) && game.light_time_left) { - graphic = (element == EL_INVISIBLE_STEEL ? GFX_INVISIBLE_STEEL_ON : - element == EL_UNSICHTBAR ? GFX_UNSICHTBAR_ON : + 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); @@ -1217,6 +1272,111 @@ 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]; + + 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 + +#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 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; + 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) + { + boolean left_stopped = FALSE, right_stopped = FALSE; + + if (!IN_LEV_FIELD(ux - 1, uy) || IS_MAUER(Feld[ux - 1][uy])) + left_stopped = TRUE; + if (!IN_LEV_FIELD(ux + 1, uy) || IS_MAUER(Feld[ux + 1][uy])) + 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; + } + else if (right_stopped) + { + graphic = IMG_WALL_GROWING_ACTIVE_LEFT; + frame = new_graphic_info[graphic].anim_frames - 1; + } + } + else if (IS_AMOEBOID(element) || element == EL_AMOEBA_DRIPPING) + { + graphic = (element == EL_BD_AMOEBA ? IMG_BD_AMOEBA_PART1 : + element == EL_AMOEBA_WET ? IMG_AMOEBA_WET_PART1 : + element == EL_AMOEBA_DRY ? IMG_AMOEBA_DRY_PART1 : + element == EL_AMOEBA_FULL ? IMG_AMOEBA_FULL_PART1 : + IMG_AMOEBA_DEAD_PART1); + + graphic += (x + 2 * y + 4) % 4; + } + + if (dx || dy) + DrawGraphicShifted(x, y, dx, dy, graphic, frame, cut_mode, mask_mode); + else if (mask_mode == USE_MASKING) + DrawGraphicThruMask(x, y, graphic, frame); + else + DrawGraphic(x, y, graphic, frame); +} void DrawLevelElementExt(int x, int y, int dx, int dy, int element, int cut_mode, int mask_mode) @@ -1238,10 +1398,17 @@ void DrawLevelElementShifted(int x, int y, int dx, int dy, int element, DrawLevelElementExt(x, y, dx, dy, element, cut_mode, NO_MASKING); } +#if 0 +void DrawOldScreenElementThruMask(int x, int y, int element) +{ + 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); } +#endif void DrawLevelElementThruMask(int x, int y, int element) { @@ -1253,8 +1420,10 @@ void DrawLevelFieldThruMask(int x, int y) DrawLevelElementExt(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; int i, width, height, cx,cy; int ux = LEVELX(x), uy = LEVELY(y); int element, graphic; @@ -1272,15 +1441,19 @@ void ErdreichAnbroeckeln(int x, int y) element = Feld[ux][uy]; - if (element == EL_ERDREICH || + if (element == EL_SAND || element == EL_LANDMINE || - element == EL_TRAP_INACTIVE || + element == EL_TRAP || element == EL_TRAP_ACTIVE) { if (!IN_SCR_FIELD(x, y)) return; - graphic = GFX_ERDENRAND; + 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; for(i=0; i<4; i++) { @@ -1289,13 +1462,13 @@ void ErdreichAnbroeckeln(int x, int y) uxx = ux + xy[i][0]; uyy = uy + xy[i][1]; if (!IN_LEV_FIELD(uxx, uyy)) - element = EL_BETON; + element = EL_STEELWALL; else element = Feld[uxx][uyy]; - if (element == EL_ERDREICH || + if (element == EL_SAND || element == EL_LANDMINE || - element == EL_TRAP_INACTIVE || + element == EL_TRAP || element == EL_TRAP_ACTIVE) continue; @@ -1314,9 +1487,7 @@ void ErdreichAnbroeckeln(int x, int y) cy = (i == 3 ? TILEY - snip : 0); } - BlitBitmap(pix[PIX_BACK], drawto_field, - SX + (graphic % GFX_PER_LINE) * TILEX + cx, - SY + (graphic / GFX_PER_LINE) * TILEY + cy, + BlitBitmap(src_bitmap, drawto_field, src_x + cx, src_y + cy, width, height, FX + x * TILEX + cx, FY + y * TILEY + cy); } @@ -1324,7 +1495,11 @@ void ErdreichAnbroeckeln(int x, int y) } else { - graphic = GFX_ERDENRAND; + 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; for(i=0; i<4; i++) { @@ -1336,9 +1511,9 @@ void ErdreichAnbroeckeln(int x, int y) uyy = uy + xy[i][1]; if (!IN_LEV_FIELD(uxx, uyy) || - (Feld[uxx][uyy] != EL_ERDREICH && + (Feld[uxx][uyy] != EL_SAND && Feld[uxx][uyy] != EL_LANDMINE && - Feld[uxx][uyy] != EL_TRAP_INACTIVE && + Feld[uxx][uyy] != EL_TRAP && Feld[uxx][uyy] != EL_TRAP_ACTIVE) || !IN_SCR_FIELD(xx, yy)) continue; @@ -1358,9 +1533,7 @@ void ErdreichAnbroeckeln(int x, int y) cy = (i==0 ? TILEY-snip : 0); } - BlitBitmap(pix[PIX_BACK], drawto_field, - SX + (graphic % GFX_PER_LINE) * TILEX + cx, - SY + (graphic / GFX_PER_LINE) * TILEY + cy, + BlitBitmap(src_bitmap, drawto_field, src_x + cx, src_y + cy, width, height, FX + xx * TILEX + cx, FY + yy * TILEY + cy); MarkTileDirty(xx, yy); @@ -1371,7 +1544,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); + DrawCrumbledSand(x, y); } void DrawLevelElement(int x, int y, int element) @@ -1388,7 +1561,7 @@ void DrawScreenField(int x, int y) if (!IN_LEV_FIELD(ux, uy)) { if (ux < -1 || ux > lev_fieldx || uy < -1 || uy > lev_fieldy) - element = EL_LEERRAUM; + element = EL_EMPTY; else element = BorderElement; @@ -1406,18 +1579,18 @@ void DrawScreenField(int x, int y) if (element == EL_QUICKSAND_EMPTYING || element == EL_MAGIC_WALL_EMPTYING || - element == EL_MAGIC_WALL_BD_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_MAGIC_WALL_BD_FILLING) + element == EL_BD_MAGIC_WALL_FILLING) cut_mode = CUT_BELOW; if (cut_mode == CUT_ABOVE) DrawScreenElementShifted(x, y, 0, 0, element, NO_CUTTING); else - DrawScreenElement(x, y, EL_LEERRAUM); + DrawScreenElement(x, y, EL_EMPTY); if (horiz_move) DrawScreenElementShifted(x, y, MovPos[ux][uy], 0, element, NO_CUTTING); @@ -1426,8 +1599,8 @@ void DrawScreenField(int x, int y) else DrawScreenElementShifted(x, y, 0, MovPos[ux][uy], content, cut_mode); - if (content == EL_SALZSAEURE) - DrawLevelElementThruMask(ux, uy + 1, EL_SALZSAEURE); + if (content == EL_ACID) + DrawLevelElementThruMask(ux, uy + 1, EL_ACID); } else if (IS_BLOCKED(ux, uy)) { @@ -1448,11 +1621,11 @@ void DrawScreenField(int x, int y) if (element_old == EL_QUICKSAND_EMPTYING || element_old == EL_MAGIC_WALL_EMPTYING || - element_old == EL_MAGIC_WALL_BD_EMPTYING || + element_old == EL_BD_MAGIC_WALL_EMPTYING || element_old == EL_AMOEBA_DRIPPING) cut_mode = CUT_ABOVE; - DrawScreenElement(x, y, EL_LEERRAUM); + DrawScreenElement(x, y, EL_EMPTY); if (horiz_move) DrawScreenElementShifted(sx, sy, MovPos[oldx][oldy], 0, element_old, @@ -1467,7 +1640,7 @@ void DrawScreenField(int x, int y) else if (IS_DRAWABLE(element)) DrawScreenElement(x, y, element); else - DrawScreenElement(x, y, EL_LEERRAUM); + DrawScreenElement(x, y, EL_EMPTY); } void DrawLevelField(int x, int y) @@ -1496,13 +1669,7 @@ 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); } @@ -1511,7 +1678,7 @@ void DrawMiniElementOrWall(int sx, int sy, int scroll_x, int scroll_y) int x = sx + scroll_x, y = sy + scroll_y; if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy) - DrawMiniElement(sx, sy, EL_LEERRAUM); + DrawMiniElement(sx, sy, EL_EMPTY); else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy) DrawMiniElement(sx, sy, Feld[x][y]); else @@ -1519,15 +1686,15 @@ 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_BETON ? 0 : 1); + 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 : @@ -1540,45 +1707,44 @@ void DrawMiniElementOrWall(int sx, int sy, int scroll_x, int scroll_y) } } +void getMicroGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y) +{ + 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 (src_x + MICRO_TILEX > src_bitmap->width || + src_y + MICRO_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 - MICRO_TILEX / 2); + src_y += (TILEY / 2 - MICRO_TILEY / 2); + } + + *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; - if (element == EL_LEERRAUM) + if (element == EL_EMPTY) return; - graphic = el2gfx(element); + graphic = el2img(element); - if (graphic >= GFX_START_ROCKSSP && graphic <= GFX_END_ROCKSSP) - { - graphic -= GFX_START_ROCKSSP; - graphic -= ((graphic / SP_PER_LINE) * SP_PER_LINE) / 2; - 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 - BlitBitmap(pix[PIX_BACK], 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); + getMicroGraphicSource(graphic, &src_bitmap, &src_x, &src_y); + BlitBitmap(src_bitmap, drawto, src_x, src_y, MICRO_TILEX, MICRO_TILEY, + xpos, ypos); } void DrawLevel() @@ -1798,7 +1964,7 @@ 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); @@ -1855,7 +2021,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); @@ -1966,7 +2132,7 @@ boolean Request(char *text, unsigned int req_state) break; case EVENT_KEYRELEASE: - key_joystick_mapping = 0; + ClearPlayerAction(); break; default: @@ -2001,7 +2167,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); @@ -2027,7 +2193,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; @@ -2042,9 +2208,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); @@ -2096,29 +2262,44 @@ unsigned int MoveDoor(unsigned int door_state) { stepsize = 20; door_delay_value = 0; - StopSound(SND_OEFFNEN); + + 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)) - PlaySoundStereo(SND_OEFFNEN, PSND_MAX_RIGHT); + { + /* 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); + else if (door_state & (DOOR_CLOSE_1 | DOOR_CLOSE_2)) + PlaySoundStereo(SND_MENU_DOOR_CLOSING, SOUND_MAX_RIGHT); + } start = ((door_state & DOOR_NO_DELAY) ? DXSIZE : 0); for(x=start; x<=DXSIZE; x+=stepsize) { - Bitmap *bitmap = pix[PIX_DOOR]; + Bitmap *bitmap = new_graphic_info[IMG_MENU_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); @@ -2161,7 +2342,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); @@ -2197,7 +2378,10 @@ unsigned int MoveDoor(unsigned int door_state) } if (setup.quick_doors) - StopSound(SND_OEFFNEN); + { + StopSound(SND_MENU_DOOR_OPENING); + StopSound(SND_MENU_DOOR_CLOSING); + } if (door_state & DOOR_ACTION_1) door1 = door_state & DOOR_ACTION_1; @@ -2210,7 +2394,7 @@ unsigned int MoveDoor(unsigned int door_state) void DrawSpecialEditorDoor() { /* draw bigger toolbox window */ - BlitBitmap(pix[PIX_DOOR], drawto, + BlitBitmap(new_graphic_info[IMG_MENU_DOOR].bitmap, drawto, DOOR_GFX_PAGEX7, 0, 108, 56, EX - 4, EY - 12); redraw_mask |= REDRAW_ALL; @@ -2219,7 +2403,7 @@ void DrawSpecialEditorDoor() void UndrawSpecialEditorDoor() { /* draw normal tape recorder window */ - BlitBitmap(pix[PIX_BACK], drawto, + BlitBitmap(new_graphic_info[IMG_MENU_BACK].bitmap, drawto, 562, 344, 108, 56, EX - 4, EY - 12); redraw_mask |= REDRAW_ALL; @@ -2348,7 +2532,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; @@ -2398,6 +2584,14 @@ void CreateToolButtons() } } +void FreeToolButtons() +{ + int i; + + for (i=0; i= MAX_ELEMENTS) + { + Error(ERR_WARN, "el2gfx: element == %d >= MAX_ELEMENTS", element); + } + + if (graphic_NEW != graphic_OLD) + { + Error(ERR_WARN, "el2gfx: graphic_NEW (%d) != graphic_OLD (%d)", + graphic_NEW, graphic_OLD); + } +#endif + + return graphic_NEW; +#endif +} + +int el2img(int element) +{ + int graphic = element_info[element].graphic[GFX_ACTION_DEFAULT]; + +#if DEBUG + if (graphic < 0) + Error(ERR_WARN, "element %d -> graphic %d -- probably crashing now...", + element, graphic); +#endif + + return graphic; +} + +int el_dir2img(int element, int direction) +{ + return el_dir_act2img(element, direction, GFX_ACTION_DEFAULT); +} + +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); + + return element_info[element].direction_graphic[action][direction]; +}