X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ftools.c;h=7888e606efb015b7d738e2ddf4b60c7984a400db;hb=dce27fe1c087a26e6dac4ef6367012c51810f327;hp=e1ec84bd480dd9a172ed29da0b54275b99d73613;hpb=091030459bbdc406295bcb6d9ecc431081ff03db;p=rocksndiamonds.git diff --git a/src/tools.c b/src/tools.c index e1ec84bd..7888e606 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 * @@ -11,26 +11,15 @@ * tools.c * ***********************************************************/ -#include - -#if defined(PLATFORM_FREEBSD) -#include -#endif - #include "libgame/libgame.h" #include "tools.h" #include "game.h" #include "events.h" -#include "joystick.h" #include "cartoons.h" #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 @@ -82,6 +71,51 @@ void SetDrawtoField(int mode) } } +void RedrawPlayfield(boolean force_redraw, int x, int y, int width, int height) +{ + if (game_status == PLAYING) + { + if (force_redraw) + { + x = gfx.sx - TILEX; + y = gfx.sy - TILEY; + width = gfx.sxsize + 2 * TILEX; + height = gfx.sysize + 2 * TILEY; + } + + if (force_redraw || setup.direct_draw) + { + int xx, yy; + int x1 = (x - SX) / TILEX, y1 = (y - SY) / TILEY; + int x2 = (x - SX + width) / TILEX, y2 = (y - SY + height) / TILEY; + + if (setup.direct_draw) + SetDrawtoField(DRAW_BACKBUFFER); + + for(xx=BX1; xx<=BX2; xx++) + for(yy=BY1; yy<=BY2; yy++) + if (xx >= x1 && xx <= x2 && yy >= y1 && yy <= y2) + DrawScreenField(xx, yy); + DrawAllPlayers(); + + if (setup.direct_draw) + SetDrawtoField(DRAW_DIRECT); + } + + if (setup.soft_scrolling) + { + int fx = FX, fy = FY; + + fx += (ScreenMovDir & (MV_LEFT|MV_RIGHT) ? ScreenGfxPos : 0); + fy += (ScreenMovDir & (MV_UP|MV_DOWN) ? ScreenGfxPos : 0); + + BlitBitmap(fieldbuffer, backbuffer, fx,fy, SXSIZE,SYSIZE, SX,SY); + } + } + + BlitBitmap(drawto, window, x, y, width, height, x, y); +} + void BackToFront() { int x,y; @@ -96,7 +130,7 @@ void BackToFront() if (redraw_mask & REDRAW_FIELD) redraw_mask &= ~REDRAW_TILES; - if (!redraw_mask) + if (redraw_mask == REDRAW_NONE) return; if (global.fps_slowdown && game_status == PLAYING) @@ -257,7 +291,7 @@ void BackToFront() for(y=0; y= GFX_START_ROCKSSCREEN && graphic <= GFX_END_ROCKSSCREEN) + if (graphic >= 0 && graphic_info[graphic].bitmap != NULL) + { + *bitmap = graphic_info[graphic].bitmap; + *x = graphic_info[graphic].src_x; + *y = graphic_info[graphic].src_y; + } + else if (graphic >= GFX_START_ROCKSSCREEN && graphic <= GFX_END_ROCKSSCREEN) { graphic -= GFX_START_ROCKSSCREEN; - *bitmap_nr = PIX_BACK; + *bitmap = pix[PIX_BACK]; *x = SX + (graphic % GFX_PER_LINE) * TILEX; *y = SY + (graphic / GFX_PER_LINE) * TILEY; } else if (graphic >= GFX_START_ROCKSHEROES && graphic <= GFX_END_ROCKSHEROES) { graphic -= GFX_START_ROCKSHEROES; - *bitmap_nr = PIX_HEROES; + *bitmap = pix[PIX_HEROES]; *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 = pix[PIX_SP]; *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 = pix[PIX_DC]; *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 = pix[PIX_MORE]; *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 = pix[PIX_BIGFONT]; *x = (graphic % FONT_CHARS_PER_LINE) * TILEX; *y = ((graphic / FONT_CHARS_PER_LINE) * TILEY + FC_SPECIAL1 * FONT_LINES_PER_FONT * TILEY); } else { - *bitmap_nr = PIX_SP; + *bitmap = pix[PIX_SP]; *x = 0; *y = 0; } @@ -771,13 +816,13 @@ void DrawGraphic(int x, int y, int graphic) MarkTileDirty(x,y); } -void DrawGraphicExt(DrawBuffer *bitmap, int x, int y, int graphic) +void DrawGraphicExt(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); + getGraphicSource(graphic, &src_bitmap, &src_x, &src_y); + BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, TILEX, TILEY, x, y); } void DrawGraphicThruMask(int x, int y, int graphic) @@ -798,7 +843,6 @@ void DrawGraphicThruMask(int x, int y, int graphic) void DrawGraphicThruMaskExt(DrawBuffer *d, int dest_x, int dest_y, int graphic) { int tile = graphic; - int bitmap_nr; int src_x, src_y; Bitmap *src_bitmap; GC drawing_gc; @@ -806,9 +850,8 @@ void DrawGraphicThruMaskExt(DrawBuffer *d, int dest_x, int dest_y, int graphic) if (graphic == GFX_LEERRAUM) return; - getGraphicSource(graphic, &bitmap_nr, &src_x, &src_y); - src_bitmap = pix[bitmap_nr]; - drawing_gc = pix[bitmap_nr]->stored_clip_gc; + getGraphicSource(graphic, &src_bitmap, &src_x, &src_y); + drawing_gc = src_bitmap->stored_clip_gc; if (tile_clipmask[tile] != None) { @@ -900,7 +943,6 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, 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; @@ -974,9 +1016,8 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, 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; + getGraphicSource(graphic, &src_bitmap, &src_x, &src_y); + drawing_gc = src_bitmap->stored_clip_gc; src_x += cx; src_y += cy; @@ -1016,7 +1057,7 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, } } else - BlitBitmap(pix[bitmap_nr], drawto_field, + BlitBitmap(src_bitmap, drawto_field, src_x, src_y, width, height, dest_x, dest_y); MarkTileDirty(x,y); @@ -1107,7 +1148,9 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, else if ((element == EL_FELSBROCKEN || element == EL_SP_ZONK || element == EL_BD_ROCK || - IS_GEM(element)) && !cut_mode) + element == EL_SP_INFOTRON || + IS_GEM(element)) + && !cut_mode) { if (uy >= lev_fieldy-1 || !IS_BELT(Feld[ux][uy+1])) { @@ -1730,6 +1773,9 @@ int REQ_in_range(int x, int y) return 0; } +#define MAX_REQUEST_LINES 13 +#define MAX_REQUEST_LINE_LEN 7 + boolean Request(char *text, unsigned int req_state) { int mx, my, ty, result = -1; @@ -1758,31 +1804,35 @@ boolean Request(char *text, unsigned int req_state) ClearRectangle(drawto, DX, DY, DXSIZE, DYSIZE); /* write text for request */ - for(ty=0; ty<13; ty++) + for(ty=0; ty < MAX_REQUEST_LINES; ty++) { + char text_line[MAX_REQUEST_LINE_LEN + 1]; int tx, tl, tc; - char txt[256]; if (!*text) break; - for(tl=0,tx=0; tx<7; tl++,tx++) + for(tl=0,tx=0; tx < MAX_REQUEST_LINE_LEN; tl++,tx++) { tc = *(text + tx); - if (!tc || tc == 32) + if (!tc || tc == ' ') break; } + if (!tl) { text++; ty--; continue; } - sprintf(txt, text); - txt[tl] = 0; - DrawTextExt(drawto, DX + 51 - (tl * 14)/2, DY + 8 + ty * 16, - txt, FS_SMALL, FC_YELLOW); - text += tl + (tc == 32 ? 1 : 0); + + 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); + + text += tl + (tc == ' ' ? 1 : 0); } if (req_state & REQ_ASK) @@ -1914,7 +1964,7 @@ boolean Request(char *text, unsigned int req_state) break; case EVENT_KEYRELEASE: - key_joystick_mapping = 0; + ClearPlayerAction(); break; default: @@ -2002,7 +2052,12 @@ unsigned int CloseDoor(unsigned int door_state) unsigned int GetDoorState() { - return(MoveDoor(DOOR_GET_STATE)); + return MoveDoor(DOOR_GET_STATE); +} + +unsigned int SetDoorState(unsigned int door_state) +{ + return MoveDoor(door_state | DOOR_SET_STATE); } unsigned int MoveDoor(unsigned int door_state) @@ -2016,6 +2071,16 @@ unsigned int MoveDoor(unsigned int door_state) if (door_state == DOOR_GET_STATE) return(door1 | door2); + if (door_state & DOOR_SET_STATE) + { + if (door_state & DOOR_ACTION_1) + door1 = door_state & DOOR_ACTION_1; + if (door_state & DOOR_ACTION_2) + door2 = door_state & DOOR_ACTION_2; + + return(door1 | door2); + } + if (door1 == DOOR_OPEN_1 && door_state & DOOR_OPEN_1) door_state &= ~DOOR_OPEN_1; else if (door1 == DOOR_CLOSE_1 && door_state & DOOR_CLOSE_1) @@ -2029,13 +2094,20 @@ 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 (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); @@ -2130,7 +2202,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; @@ -2275,13 +2350,6 @@ static struct } }; -#if 0 -static void DoNotDisplayInfoText(void *ptr) -{ - return; -} -#endif - void CreateToolButtons() { int i; @@ -2328,11 +2396,6 @@ void CreateToolButtons() GDI_DECORATION_SIZE, MINI_TILEX, MINI_TILEY, GDI_DECORATION_SHIFTING, 1, 1, GDI_EVENT_MASK, event_mask, - -#if 0 - GDI_CALLBACK_INFO, DoNotDisplayInfoText, -#endif - GDI_CALLBACK_ACTION, HandleToolButtons, GDI_END); @@ -2356,7 +2419,23 @@ static void HandleToolButtons(struct GadgetInfo *gi) request_gadget_id = gi->custom_id; } -int el2gfx(int element) +int get_next_element(int element) +{ + switch(element) + { + case EL_QUICKSAND_FILLING: return EL_MORAST_VOLL; + case EL_QUICKSAND_EMPTYING: return EL_MORAST_LEER; + case EL_MAGIC_WALL_FILLING: return EL_MAGIC_WALL_FULL; + case EL_MAGIC_WALL_EMPTYING: return EL_MAGIC_WALL_EMPTY; + case EL_MAGIC_WALL_BD_FILLING: return EL_MAGIC_WALL_BD_FULL; + case EL_MAGIC_WALL_BD_EMPTYING: return EL_MAGIC_WALL_BD_EMPTY; + case EL_AMOEBA_DRIPPING: return EL_AMOEBE_NASS; + + default: return element; + } +} + +int el2gfx_OLD(int element) { switch(element) { @@ -2637,3 +2716,25 @@ int el2gfx(int element) } } } + +int el2gfx(int element) +{ + int graphic_NEW = element_info[element].graphic; + +#if DEBUG + int graphic_OLD = el2gfx_OLD(element); + + if (element >= 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; +}