From 3ff2e8a0b5c27b99a9920bdf5ed82bc41bf40181 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Tue, 16 Sep 2014 09:34:53 +0200 Subject: [PATCH] major cleanup of preprocessor hell --- ChangeLog | 3 + src/cartoons.c | 24 - src/conf_snd.c | 23 - src/config.c | 71 +- src/conftime.h | 2 +- src/editor.c | 599 +-- src/engines.h | 9 - src/events.c | 271 +- src/files.c | 6907 ++++++++-------------------------- src/game.c | 2338 +----------- src/game.h | 14 - src/game_em/cave.c | 61 - src/game_em/convert.c | 140 - src/game_em/global.h | 8 - src/game_em/graphics.c | 481 +-- src/game_em/init.c | 311 +- src/game_em/input.c | 41 - src/game_em/main_em.h | 52 +- src/game_em/sample.h | 10 - src/game_em/sound.c | 511 --- src/game_em/synchro_1.c | 198 - src/game_em/synchro_2.c | 105 +- src/game_em/synchro_3.c | 18 - src/game_em/tab_generate.c | 75 - src/game_em/ulaw_generate.c | 129 - src/game_sp/BugsTerminals.c | 4 - src/game_sp/BugsTerminals.h | 4 - src/game_sp/DDScrollBuffer.c | 120 - src/game_sp/DDScrollBuffer.h | 4 - src/game_sp/DDSpriteBuffer.c | 27 - src/game_sp/DoGameStuff.c | 14 - src/game_sp/DoGameStuff.h | 5 - src/game_sp/Explosions.c | 35 - src/game_sp/Globals.c | 40 - src/game_sp/Globals.h | 22 - src/game_sp/Infotrons.c | 11 - src/game_sp/MainForm.c | 57 - src/game_sp/MainGameLoop.c | 24 - src/game_sp/Murphy.c | 189 +- src/game_sp/SnikSnaks.c | 2 - src/game_sp/Zonk.c | 4 - src/game_sp/export.h | 13 - src/game_sp/file.c | 440 +-- src/game_sp/init.c | 3 - src/game_sp/main.c | 12 - src/game_sp/main_sp.h | 48 +- src/game_sp/vb_lib.c | 14 - src/game_sp/vb_lib.h | 4 - src/init.c | 773 +--- src/libgame/gadgets.c | 36 - src/libgame/image.c | 16 - src/libgame/misc.c | 361 +- src/libgame/misc.h | 29 - src/libgame/sdl.c | 454 +-- src/libgame/sdl.h | 4 - src/libgame/setup.c | 1357 +------ src/libgame/sound.c | 1290 ------- src/libgame/sound.h | 25 +- src/libgame/system.c | 435 +-- src/libgame/text.c | 332 -- src/libgame/toons.c | 19 - src/main.c | 20 - src/main.h | 118 - src/netserv.c | 177 +- src/netserv.h | 3 - src/network.c | 142 +- src/screens.c | 946 +---- src/tape.c | 321 +- src/tools.c | 5172 ++++--------------------- src/tools.h | 4 - 70 files changed, 2674 insertions(+), 22857 deletions(-) diff --git a/ChangeLog b/ChangeLog index d86e79d8..3011eeed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2014-09-15 + * removed large parts of the preprocessor hell of old and unused code + 2014-09-14 * updated source file headers (mainly author contact information) diff --git a/src/cartoons.c b/src/cartoons.c index f85d0263..a0115cf9 100644 --- a/src/cartoons.c +++ b/src/cartoons.c @@ -24,27 +24,7 @@ static void PrepareBackbuffer() if (game_status != GAME_MODE_PLAYING) return; -#if 1 BlitScreenToBitmap(backbuffer); -#else - if (level.game_engine_type == GAME_ENGINE_TYPE_EM) - { - BlitScreenToBitmap_EM(backbuffer); - } - else if (level.game_engine_type == GAME_ENGINE_TYPE_SP) - { - BlitScreenToBitmap_SP(backbuffer); - } - else if (setup.soft_scrolling) /* GAME_ENGINE_TYPE_RND */ - { - 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); - } -#endif } boolean ToonNeedsRedraw() @@ -85,11 +65,7 @@ void InitToons() toons[i].position = image->parameter[GFX_ARG_POSITION]; } -#if 1 InitToonScreen(bitmap_db_toons, -#else - InitToonScreen(bitmap_db_door, -#endif BackToFront, PrepareBackbuffer, ToonNeedsRedraw, toons, num_toons, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, diff --git a/src/conf_snd.c b/src/conf_snd.c index 37128ba1..fa6ae334 100644 --- a/src/conf_snd.c +++ b/src/conf_snd.c @@ -288,28 +288,5 @@ struct ConfigInfo sound_config[] = { "background.titlemessage_4", UNDEFINED_FILENAME }, { "background.titlemessage_5", UNDEFINED_FILENAME }, -#if 0 - { "[not used]", "antigrav.wav" }, - { "[not used]", "bong.wav" }, - { "[not used]", "fuel.wav" }, - { "[not used]", "holz.wav" }, - { "[not used]", "hui.wav" }, - { "[not used]", "kabumm.wav" }, - { "[not used]", "kink.wav" }, - { "[not used]", "kling.wav" }, - { "[not used]", "krach.wav" }, - { "[not used]", "laser.wav" }, - { "[not used]", "quiek.wav" }, - { "[not used]", "rumms.wav" }, - { "[not used]", "schlopp.wav" }, - { "[not used]", "schrff.wav" }, - { "[not used]", "schwirr.wav" }, - { "[not used]", "slurp.wav" }, - { "[not used]", "sproing.wav" }, - { "[not used]", "warnton.wav" }, - { "[not used]", "whoosh.wav" }, - { "[not used]", "boom.wav" }, -#endif - { NULL, NULL } }; diff --git a/src/config.c b/src/config.c index e44e8348..955c4979 100644 --- a/src/config.c +++ b/src/config.c @@ -15,62 +15,26 @@ #include "conftime.h" -#define USE_EXTENDED_VERSION 1 - - char *getCompileDateString() { return COMPILE_DATE_STRING; } -char *getProgramReleaseVersionString() -{ - static char program_version_string[32]; - -#if USE_EXTENDED_VERSION - sprintf(program_version_string, "%d.%d.%d.%d", - PROGRAM_VERSION_MAJOR, PROGRAM_VERSION_MINOR, PROGRAM_VERSION_PATCH, - PROGRAM_VERSION_BUILD); -#else - sprintf(program_version_string, "%d.%d.%d", - PROGRAM_VERSION_MAJOR, PROGRAM_VERSION_MINOR, PROGRAM_VERSION_PATCH); -#endif - - return program_version_string; -} - -char *getProgramFullVersionString() +char *getProgramVersionString() { static char program_version_string[32]; -#if USE_EXTENDED_VERSION sprintf(program_version_string, "%d.%d.%d.%d", PROGRAM_VERSION_MAJOR, PROGRAM_VERSION_MINOR, PROGRAM_VERSION_PATCH, PROGRAM_VERSION_BUILD); -#else - sprintf(program_version_string, "%d.%d.%d-%d", - PROGRAM_VERSION_MAJOR, PROGRAM_VERSION_MINOR, PROGRAM_VERSION_PATCH, - PROGRAM_VERSION_BUILD); -#endif return program_version_string; } -char *getProgramVersionString() -{ -#ifdef DEBUG - return getProgramFullVersionString(); -#else - return getProgramReleaseVersionString(); -#endif -} - char *getProgramInitString() { static char *program_init_string = NULL; -#if 1 - // do not display compile target anymore, as it is almost always "SDL" now if (program_init_string == NULL) { program_init_string = checked_malloc(strlen(PROGRAM_TITLE_STRING) + 1 + @@ -79,24 +43,12 @@ char *getProgramInitString() sprintf(program_init_string, "%s %s", PROGRAM_TITLE_STRING, getProgramVersionString()); } -#else - if (program_init_string == NULL) - { - program_init_string = checked_malloc(strlen(PROGRAM_TITLE_STRING) + 1 + - strlen(getProgramVersionString()) + 1 + - strlen(TARGET_STRING) + 1); - - sprintf(program_init_string, "%s %s %s", - PROGRAM_TITLE_STRING, getProgramVersionString(), TARGET_STRING); - } -#endif return program_init_string; } char *getWindowTitleString() { -#if 1 static char *window_title_string = NULL; checked_free(window_title_string); @@ -116,25 +68,4 @@ char *getWindowTitleString() #endif return window_title_string; - -#else - -#ifdef DEBUG - static char *window_title_string = NULL; - - if (window_title_string == NULL) - { - window_title_string = checked_malloc(strlen(getProgramInitString()) + 1 + - strlen(getCompileDateString()) + 2 +1); - - sprintf(window_title_string, "%s [%s]", - getProgramInitString(), getCompileDateString()); - } - - return window_title_string; -#else - return getProgramInitString(); -#endif - -#endif } diff --git a/src/conftime.h b/src/conftime.h index 923f4f88..9cde5495 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2014-09-14 21:23" +#define COMPILE_DATE_STRING "2014-09-16 09:25" diff --git a/src/editor.c b/src/editor.c index 9ce3bd5b..f39eb4e4 100644 --- a/src/editor.c +++ b/src/editor.c @@ -32,21 +32,12 @@ */ /* positions in the level editor */ -#if 1 #define ED_WIN_MB_LEFT_XPOS (editor.palette.element_left.x) #define ED_WIN_MB_LEFT_YPOS (editor.palette.element_left.y) #define ED_WIN_MB_MIDDLE_XPOS (editor.palette.element_middle.x) #define ED_WIN_MB_MIDDLE_YPOS (editor.palette.element_middle.y) #define ED_WIN_MB_RIGHT_XPOS (editor.palette.element_right.x) #define ED_WIN_MB_RIGHT_YPOS (editor.palette.element_right.y) -#else -#define ED_WIN_MB_LEFT_XPOS 6 -#define ED_WIN_MB_LEFT_YPOS 258 -#define ED_WIN_MB_MIDDLE_XPOS 42 -#define ED_WIN_MB_MIDDLE_YPOS ED_WIN_MB_LEFT_YPOS -#define ED_WIN_MB_RIGHT_XPOS 78 -#define ED_WIN_MB_RIGHT_YPOS ED_WIN_MB_LEFT_YPOS -#endif /* values for the control window */ #define ED_CTRL_NO_BUTTONS_GFX_XPOS 6 @@ -97,26 +88,12 @@ ED_NUM_CTRL4_BUTTONS) /* values for the element list */ -#if 1 #define ED_ELEMENTLIST_XPOS (editor.palette.x) #define ED_ELEMENTLIST_YPOS (editor.palette.y) #define ED_ELEMENTLIST_XSIZE 20 #define ED_ELEMENTLIST_YSIZE 20 -#else -#define ED_ELEMENTLIST_XPOS 5 -#define ED_ELEMENTLIST_YPOS 30 -#define ED_ELEMENTLIST_XSIZE 20 -#define ED_ELEMENTLIST_YSIZE 20 -#endif -#if 1 -// #define ED_ELEMENTLIST_BUTTONS_HORIZ 4 -// #define ED_ELEMENTLIST_BUTTONS_VERT 9 #define ED_ELEMENTLIST_BUTTONS_HORIZ (editor.palette.cols) #define ED_ELEMENTLIST_BUTTONS_VERT (editor.palette.rows) -#else -#define ED_ELEMENTLIST_BUTTONS_HORIZ 4 -#define ED_ELEMENTLIST_BUTTONS_VERT 11 -#endif #define ED_NUM_ELEMENTLIST_BUTTONS (ED_ELEMENTLIST_BUTTONS_HORIZ * \ ED_ELEMENTLIST_BUTTONS_VERT) @@ -234,7 +211,6 @@ #define ED_SCROLLBUTTON2_XSIZE 10 #define ED_SCROLLBUTTON2_YSIZE 10 -#if 1 #define ED_SCROLL2_UP_XPOS (ED_ELEMENTLIST_XPOS + \ ED_ELEMENTLIST_BUTTONS_HORIZ * \ ED_ELEMENTLIST_XSIZE) @@ -251,22 +227,6 @@ #define ED_SCROLL2_VERTICAL_YSIZE (ED_ELEMENTLIST_BUTTONS_VERT * \ ED_ELEMENTLIST_YSIZE - \ 2 * ED_SCROLLBUTTON2_YSIZE) -#else -#define ED_SCROLL2_UP_XPOS 85 -#define ED_SCROLL2_UP_YPOS 30 -#define ED_SCROLL2_DOWN_XPOS ED_SCROLL2_UP_XPOS -#define ED_SCROLL2_DOWN_YPOS (ED_SCROLL2_UP_YPOS + \ - ED_ELEMENTLIST_BUTTONS_VERT * \ - ED_ELEMENTLIST_YSIZE - \ - ED_SCROLLBUTTON2_YSIZE) -#define ED_SCROLL2_VERTICAL_XPOS ED_SCROLL2_UP_XPOS -#define ED_SCROLL2_VERTICAL_YPOS (ED_SCROLL2_UP_YPOS + \ - ED_SCROLLBUTTON2_YSIZE) -#define ED_SCROLL2_VERTICAL_XSIZE ED_SCROLLBUTTON2_XSIZE -#define ED_SCROLL2_VERTICAL_YSIZE (ED_ELEMENTLIST_BUTTONS_VERT * \ - ED_ELEMENTLIST_YSIZE - \ - 2 * ED_SCROLLBUTTON2_YSIZE) -#endif /* values for checkbutton gadgets */ #define ED_CHECKBUTTON_XSIZE ED_BUTTON_COUNT_XSIZE @@ -1011,13 +971,8 @@ #define RANDOM_USE_QUANTITY 1 /* maximal size of level editor drawing area */ -#if NEW_TILESIZE -#define MAX_ED_FIELDX (SCR_FIELDX) -#define MAX_ED_FIELDY (SCR_FIELDY - 1) -#else -#define MAX_ED_FIELDX (2 * SCR_FIELDX) -#define MAX_ED_FIELDY (2 * SCR_FIELDY - 1) -#endif +#define MAX_ED_FIELDX (SCR_FIELDX) +#define MAX_ED_FIELDY (SCR_FIELDY - 1) /* @@ -1092,11 +1047,7 @@ static struct /* ---------- current level number --------------------------------------- */ { -#if 1 -1, -1, /* these values are not constant, but can change at runtime */ -#else - DX + 5 - SX, DY + 3 - SY, -#endif 1, 100, GADGET_ID_SELECT_LEVEL_DOWN, GADGET_ID_SELECT_LEVEL_UP, GADGET_ID_SELECT_LEVEL_TEXT, GADGET_ID_NONE, @@ -2513,8 +2464,6 @@ static struct }, }; -#if 1 - static struct { int x, y; @@ -2595,136 +2544,6 @@ static struct } }; -#else - -static struct -{ - int gd_x, gd_y; - int x, y; - int gadget_id; - char *infotext; -} scrollbutton_info[ED_NUM_SCROLLBUTTONS] = -{ - { - ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 0 * ED_SCROLLBUTTON_YSIZE, -#if 1 - -1, -1, /* these values are not constant, but can change at runtime */ -#else - ED_SCROLL_UP_XPOS, ED_SCROLL_UP_YPOS, -#endif - GADGET_ID_SCROLL_UP, - "scroll level editing area up" - }, - { - ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 1 * ED_SCROLLBUTTON_YSIZE, -#if 1 - -1, -1, /* these values are not constant, but can change at runtime */ -#else - ED_SCROLL_DOWN_XPOS, ED_SCROLL_DOWN_YPOS, -#endif - GADGET_ID_SCROLL_DOWN, - "scroll level editing area down" - }, - { - ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 2 * ED_SCROLLBUTTON_YSIZE, -#if 1 - -1, -1, /* these values are not constant, but can change at runtime */ -#else - ED_SCROLL_LEFT_XPOS, ED_SCROLL_LEFT_YPOS, -#endif - GADGET_ID_SCROLL_LEFT, - "scroll level editing area left" - }, - { - ED_SCROLLBUTTON_XPOS, ED_SCROLLBUTTON_YPOS + 3 * ED_SCROLLBUTTON_YSIZE, -#if 1 - -1, -1, /* these values are not constant, but can change at runtime */ -#else - ED_SCROLL_RIGHT_XPOS, ED_SCROLL_RIGHT_YPOS, -#endif - GADGET_ID_SCROLL_RIGHT, - "scroll level editing area right" - }, - { - ED_SCROLLBUTTON2_XPOS, ED_SCROLLBUTTON2_YPOS + 0 * ED_SCROLLBUTTON2_YSIZE, - ED_SCROLL2_UP_XPOS, ED_SCROLL2_UP_YPOS, - GADGET_ID_SCROLL_LIST_UP, - "scroll element list up ('Page Up')" - }, - { - ED_SCROLLBUTTON2_XPOS, ED_SCROLLBUTTON2_YPOS + 1 * ED_SCROLLBUTTON2_YSIZE, - ED_SCROLL2_DOWN_XPOS, ED_SCROLL2_DOWN_YPOS, - GADGET_ID_SCROLL_LIST_DOWN, - "scroll element list down ('Page Down')" - }, -}; - -static struct -{ - int gd_x, gd_y; - int x, y; - int width, height; - int wheel_x, wheel_y; - int wheel_width, wheel_height; - int type; - int gadget_id; - char *infotext; -} scrollbar_info[ED_NUM_SCROLLBARS] = -{ - { - ED_SCROLLBAR_XPOS, ED_SCROLLBAR_YPOS, -#if 1 - -1, -1, /* these values are not constant, but can change at runtime */ - -1, -1, /* these values are not constant, but can change at runtime */ - -1, -1, /* these values are not constant, but can change at runtime */ - -1, -1, /* these values are not constant, but can change at runtime */ -#else - SX + ED_SCROLL_HORIZONTAL_XPOS, SY + ED_SCROLL_HORIZONTAL_YPOS, - ED_SCROLL_HORIZONTAL_XSIZE, ED_SCROLL_HORIZONTAL_YSIZE, - SX, SY, - SXSIZE, SYSIZE, -#endif - GD_TYPE_SCROLLBAR_HORIZONTAL, - GADGET_ID_SCROLL_HORIZONTAL, - "scroll level editing area horizontally" - }, - { - ED_SCROLLBAR_XPOS, ED_SCROLLBAR_YPOS, -#if 1 - -1, -1, /* these values are not constant, but can change at runtime */ - -1, -1, /* these values are not constant, but can change at runtime */ - -1, -1, /* these values are not constant, but can change at runtime */ - -1, -1, /* these values are not constant, but can change at runtime */ -#else - SX + ED_SCROLL_VERTICAL_XPOS, SY + ED_SCROLL_VERTICAL_YPOS, - ED_SCROLL_VERTICAL_XSIZE, ED_SCROLL_VERTICAL_YSIZE, - SX, SY, - SXSIZE, SYSIZE, -#endif - GD_TYPE_SCROLLBAR_VERTICAL, - GADGET_ID_SCROLL_VERTICAL, - "scroll level editing area vertically" - }, - { - ED_SCROLLBAR2_XPOS, ED_SCROLLBAR2_YPOS, -#if 1 - -1, -1, /* these values are not constant, but can change at runtime */ - ED_SCROLL2_VERTICAL_XSIZE, ED_SCROLL2_VERTICAL_YSIZE, - -1, -1, /* these values are not constant, but can change at runtime */ - -1, -1, /* these values are not constant, but can change at runtime */ -#else - DX + ED_SCROLL2_VERTICAL_XPOS, DY + ED_SCROLL2_VERTICAL_YPOS, - ED_SCROLL2_VERTICAL_XSIZE, ED_SCROLL2_VERTICAL_YSIZE, - DX, DY, - DXSIZE, DYSIZE, -#endif - GD_TYPE_SCROLLBAR_VERTICAL, - GADGET_ID_SCROLL_LIST_VERTICAL, - "scroll element list vertically" - } -}; - -#endif static struct { @@ -2963,15 +2782,8 @@ static struct ED_ELEMENT_SETTINGS_XPOS(0), ED_ELEMENT_SETTINGS_YPOS(1), GADGET_ID_CUSTOM_USE_GRAPHIC, GADGET_ID_NONE, &custom_element.use_gfx_element, - - /* !!! add separate "use existing element sound" !!! */ -#if 0 - NULL, - "use graphic/sound of element:", "use existing graphic and sound" -#else NULL, "use graphic of element:", "use existing element graphic" -#endif }, { ED_ELEMENT_SETTINGS_XPOS(0), ED_ELEMENT_SETTINGS_YPOS(2), @@ -3165,11 +2977,7 @@ static struct 0, 0, GADGET_ID_DRAWING_LEVEL, GADGET_ID_NONE, NULL, -#if 1 -1, -1, /* these values are not constant, but can change at runtime */ -#else - MAX_ED_FIELDX, MAX_ED_FIELDY, -#endif NULL, NULL, NULL, NULL }, @@ -3431,20 +3239,12 @@ static struct */ /* actual size of level editor drawing area */ -#if 1 static int ed_fieldx, ed_fieldy; -#else -static int ed_fieldx = MAX_ED_FIELDX - 1, ed_fieldy = MAX_ED_FIELDY - 1; -#endif /* actual position of level editor drawing area in level playfield */ static int level_xpos = -1, level_ypos = -1; -#if 1 #define IN_ED_FIELD(x,y) IN_FIELD(x, y, ed_fieldx, ed_fieldy) -#else -#define IN_ED_FIELD(x,y) ((x)>=0 && (x)=0 &&(y)width; height = gd->height; gd_x1 = gd->src_x; gd_y1 = gd->src_y; gd_x2 = gd->src_x + gd->pressed_xoffset; gd_y2 = gd->src_y + gd->pressed_yoffset; -#else - width = ED_SCROLLBUTTON2_XSIZE; - height = ED_SCROLLBUTTON2_YSIZE; - gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[i].gd_x; - gd_y1 = DOOR_GFX_PAGEY1 + scrollbutton_info[i].gd_y; - gd_x2 = gd_x1 - ED_SCROLLBUTTON2_XSIZE; - gd_y2 = gd_y1; -#endif } else { x += SX; y += SY; -#if 1 width = gd->width; height = gd->height; gd_x1 = gd->src_x; gd_y1 = gd->src_y; gd_x2 = gd->src_x + gd->pressed_xoffset; gd_y2 = gd->src_y + gd->pressed_yoffset; -#else - width = ED_SCROLLBUTTON_XSIZE; - height = ED_SCROLLBUTTON_YSIZE; - gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[i].gd_x; - gd_y1 = DOOR_GFX_PAGEY1 + scrollbutton_info[i].gd_y; - gd_x2 = gd_x1 - ED_SCROLLBUTTON_XSIZE; - gd_y2 = gd_y1; -#endif } gi = CreateGadget(GDI_CUSTOM_ID, id, @@ -5624,11 +5375,7 @@ static void CreateControlButtons() Bitmap *deco_bitmap; int deco_x, deco_y, deco_xpos, deco_ypos; int gd_xoffset, gd_yoffset; -#if 1 int gd_x1, gd_y1, gd_x2, gd_y2; -#else - int gd_x1, gd_x2, gd_y; -#endif int x = i % ED_ELEMENTLIST_BUTTONS_HORIZ; int y = i / ED_ELEMENTLIST_BUTTONS_HORIZ; int id = GADGET_ID_ELEMENTLIST_FIRST + i; @@ -5636,7 +5383,6 @@ static void CreateControlButtons() event_mask = GD_EVENT_RELEASED; -#if 1 gd_xoffset = ED_ELEMENTLIST_XPOS + x * gd->width; gd_yoffset = ED_ELEMENTLIST_YPOS + y * gd->height; @@ -5648,40 +5394,18 @@ static void CreateControlButtons() getMiniGraphicSource(el2edimg(element), &deco_bitmap, &deco_x, &deco_y); deco_xpos = (gd->width - MINI_TILEX) / 2; deco_ypos = (gd->height - MINI_TILEY) / 2; -#else - gd_xoffset = ED_ELEMENTLIST_XPOS + x * ED_ELEMENTLIST_XSIZE; - gd_yoffset = ED_ELEMENTLIST_YPOS + y * ED_ELEMENTLIST_YSIZE; - - gd_x1 = DOOR_GFX_PAGEX6 + ED_ELEMENTLIST_XPOS + ED_ELEMENTLIST_XSIZE; - gd_x2 = DOOR_GFX_PAGEX6 + ED_ELEMENTLIST_XPOS; - gd_y = DOOR_GFX_PAGEY1 + ED_ELEMENTLIST_YPOS; - - getMiniGraphicSource(el2edimg(element), &deco_bitmap, &deco_x, &deco_y); - deco_xpos = (ED_ELEMENTLIST_XSIZE - MINI_TILEX) / 2; - deco_ypos = (ED_ELEMENTLIST_YSIZE - MINI_TILEY) / 2; -#endif gi = CreateGadget(GDI_CUSTOM_ID, id, GDI_CUSTOM_TYPE_ID, i, GDI_INFO_TEXT, getElementInfoText(element), GDI_X, DX + gd_xoffset, GDI_Y, DY + gd_yoffset, -#if 1 GDI_WIDTH, gd->width, GDI_HEIGHT, gd->height, -#else - GDI_WIDTH, ED_ELEMENTLIST_XSIZE, - GDI_HEIGHT, ED_ELEMENTLIST_YSIZE, -#endif GDI_TYPE, GD_TYPE_NORMAL_BUTTON, GDI_STATE, GD_BUTTON_UNPRESSED, -#if 1 GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y1, GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y2, -#else - GDI_DESIGN_UNPRESSED, gd->bitmap, gd_x1, gd_y, - GDI_DESIGN_PRESSED, gd->bitmap, gd_x2, gd_y, -#endif GDI_DECORATION_DESIGN, deco_bitmap, deco_x, deco_y, GDI_DECORATION_POSITION, deco_xpos, deco_ypos, GDI_DECORATION_SIZE, MINI_TILEX, MINI_TILEY, @@ -5739,7 +5463,6 @@ static void CreateCounterButtons() if (i == ED_COUNTER_ID_SELECT_LEVEL) { -#if 1 int graphic = (j == 0 ? IMG_EDITOR_BUTTON_GFX_PREV_LEVEL : IMG_EDITOR_BUTTON_GFX_NEXT_LEVEL); @@ -5759,24 +5482,6 @@ static void CreateCounterButtons() gd_y2 = gd->src_y + gd->pressed_yoffset; x_size = gd->width; y_size = gd->height; -#else - int sid = (j == 0 ? - ED_SCROLLBUTTON_ID_AREA_LEFT : - ED_SCROLLBUTTON_ID_AREA_RIGHT); - - event_mask |= GD_EVENT_RELEASED; - - if (j == 1) - x += 2 * ED_GADGET_DISTANCE; - y += ED_GADGET_DISTANCE; - - gd_x1 = DOOR_GFX_PAGEX8 + scrollbutton_info[sid].gd_x; - gd_x2 = gd_x1 - ED_SCROLLBUTTON_XSIZE; - gd_y1 = DOOR_GFX_PAGEY1 + scrollbutton_info[sid].gd_y; - gd_y2 = gd_y1; - x_size = ED_SCROLLBUTTON_XSIZE; - y_size = ED_SCROLLBUTTON_YSIZE; -#endif } else { @@ -5829,11 +5534,7 @@ static void CreateCounterButtons() if (i == ED_COUNTER_ID_SELECT_LEVEL) { font_type = FONT_LEVEL_NUMBER; -#if 1 font_type_active = FONT_LEVEL_NUMBER_ACTIVE; -#else - font_type_active = FONT_LEVEL_NUMBER; -#endif x += 2 * ED_GADGET_DISTANCE; y -= ED_GADGET_DISTANCE; @@ -6257,7 +5958,6 @@ static void CreateScrollbarGadgets() int i; /* these values are not constant, but can change at runtime */ -#if 1 scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].x = SX + ED_SCROLL_HORIZONTAL_XPOS; scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].y = @@ -6296,57 +5996,13 @@ static void CreateScrollbarGadgets() scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_y = DY; scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_width = DXSIZE; scrollbar_pos[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_height = DYSIZE; -#else - scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].x = - SX + ED_SCROLL_HORIZONTAL_XPOS; - scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].y = - SY + ED_SCROLL_HORIZONTAL_YPOS; - scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].width = - ED_SCROLL_HORIZONTAL_XSIZE; - scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].height = - ED_SCROLL_HORIZONTAL_YSIZE; - scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].wheel_x = SX; - scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].wheel_y = SY; - scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].wheel_width = SXSIZE; - scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].wheel_height = SYSIZE; - - scrollbar_info[ED_SCROLLBAR_ID_AREA_VERTICAL].x = - SX + ED_SCROLL_VERTICAL_XPOS; - scrollbar_info[ED_SCROLLBAR_ID_AREA_VERTICAL].y = - SY + ED_SCROLL_VERTICAL_YPOS; - scrollbar_info[ED_SCROLLBAR_ID_AREA_VERTICAL].width = - ED_SCROLL_VERTICAL_XSIZE; - scrollbar_info[ED_SCROLLBAR_ID_AREA_VERTICAL].height = - ED_SCROLL_VERTICAL_YSIZE; - scrollbar_info[ED_SCROLLBAR_ID_AREA_VERTICAL].wheel_x = SX; - scrollbar_info[ED_SCROLLBAR_ID_AREA_VERTICAL].wheel_y = SY; - scrollbar_info[ED_SCROLLBAR_ID_AREA_VERTICAL].wheel_width = SXSIZE; - scrollbar_info[ED_SCROLLBAR_ID_AREA_VERTICAL].wheel_height = SYSIZE; - - scrollbar_info[ED_SCROLLBAR_ID_LIST_VERTICAL].x = - DX + ED_SCROLL2_VERTICAL_XPOS; - scrollbar_info[ED_SCROLLBAR_ID_LIST_VERTICAL].y = - DY + ED_SCROLL2_VERTICAL_YPOS; - scrollbar_info[ED_SCROLLBAR_ID_LIST_VERTICAL].width = - ED_SCROLL2_VERTICAL_XSIZE; - scrollbar_info[ED_SCROLLBAR_ID_LIST_VERTICAL].height = - ED_SCROLL2_VERTICAL_YSIZE; - scrollbar_info[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_x = DX; - scrollbar_info[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_y = DY; - scrollbar_info[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_width = DXSIZE; - scrollbar_info[ED_SCROLLBAR_ID_LIST_VERTICAL].wheel_height = DYSIZE; -#endif for (i = 0; i < ED_NUM_SCROLLBARS; i++) { int id = scrollbar_info[i].gadget_id; -#if 1 int graphic = scrollbar_info[i].graphic; struct GraphicInfo *gd = &graphic_info[graphic]; Bitmap *gd_bitmap = gd->bitmap; -#else - Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap; -#endif int gd_x1, gd_x2, gd_y1, gd_y2; struct GadgetInfo *gi; int items_max, items_visible, item_position; @@ -6376,48 +6032,26 @@ static void CreateScrollbarGadgets() event_mask = GD_EVENT_MOVING | GD_EVENT_OFF_BORDERS; -#if 1 gd_x1 = gd->src_x; gd_y1 = gd->src_y; gd_x2 = gd->src_x + gd->pressed_xoffset; gd_y2 = gd->src_y + gd->pressed_yoffset; -#else - gd_x1 = DOOR_GFX_PAGEX8 + scrollbar_info[i].gd_x; - gd_x2 = (gd_x1 - (scrollbar_info[i].type == GD_TYPE_SCROLLBAR_HORIZONTAL ? - scrollbar_info[i].height : scrollbar_info[i].width)); - gd_y1 = DOOR_GFX_PAGEY1 + scrollbar_info[i].gd_y; - gd_y2 = DOOR_GFX_PAGEY1 + scrollbar_info[i].gd_y; -#endif gi = CreateGadget(GDI_CUSTOM_ID, id, GDI_CUSTOM_TYPE_ID, i, GDI_INFO_TEXT, scrollbar_info[i].infotext, -#if 1 GDI_X, scrollbar_pos[i].x, GDI_Y, scrollbar_pos[i].y, GDI_WIDTH, scrollbar_pos[i].width, GDI_HEIGHT, scrollbar_pos[i].height, -#else - GDI_X, scrollbar_info[i].x, - GDI_Y, scrollbar_info[i].y, - GDI_WIDTH, scrollbar_info[i].width, - GDI_HEIGHT, scrollbar_info[i].height, -#endif GDI_TYPE, scrollbar_info[i].type, GDI_SCROLLBAR_ITEMS_MAX, items_max, GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible, GDI_SCROLLBAR_ITEM_POSITION, item_position, -#if 1 GDI_WHEEL_AREA_X, scrollbar_pos[i].wheel_x, GDI_WHEEL_AREA_Y, scrollbar_pos[i].wheel_y, GDI_WHEEL_AREA_WIDTH, scrollbar_pos[i].wheel_width, GDI_WHEEL_AREA_HEIGHT, scrollbar_pos[i].wheel_height, -#else - GDI_WHEEL_AREA_X, scrollbar_info[i].wheel_x, - GDI_WHEEL_AREA_Y, scrollbar_info[i].wheel_y, - GDI_WHEEL_AREA_WIDTH, scrollbar_info[i].wheel_width, - GDI_WHEEL_AREA_HEIGHT, scrollbar_info[i].wheel_height, -#endif GDI_STATE, GD_BUTTON_UNPRESSED, GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1, GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2, @@ -6986,16 +6620,10 @@ static void UnmapLevelEditorFieldGadgets() { int i; -#if 1 for (i = 0; i < num_editor_gadgets; i++) if (IN_GFX_FIELD_FULL(level_editor_gadget[i]->x, level_editor_gadget[i]->y)) UnmapGadget(level_editor_gadget[i]); -#else - for (i = 0; i < NUM_EDITOR_GADGETS; i++) - if (level_editor_gadget[i]->x < SX + SXSIZE) - UnmapGadget(level_editor_gadget[i]); -#endif } void UnmapLevelEditorGadgets() @@ -7033,13 +6661,6 @@ static boolean LevelChanged() boolean field_changed = FALSE; int x, y; -#if 1 - /* changed read-only levels can now be saved in personal level set */ -#else - if (leveldir_current->readonly) - return FALSE; -#endif - for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++) if (Feld[x][y] != level.field[x][y]) @@ -7754,42 +7375,23 @@ void DrawLevelEd() CloseDoor(DOOR_CLOSE_ALL); -#if 1 FadeOut(REDRAW_FIELD); - // FadeOut(REDRAW_ALL); -#endif -#if 1 /* needed after playing if editor playfield area has different size */ ClearRectangle(drawto, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); -#endif -#if 1 /* needed if different viewport properties defined for editor */ ChangeViewportPropertiesIfNeeded(); -#endif if (old_sx != SX || old_sy != SY || old_sxsize != SXSIZE || old_sysize != SYSIZE) - { playfield_area_changed = TRUE; - -#if 0 - printf("::: %d, %d, %d, %d != %d, %d, %d, %d\n", - old_sx, old_sy, old_sxsize, old_sysize, - SX, SY, SXSIZE, SYSIZE); -#endif - } else playfield_area_changed = FALSE; -#if 1 OpenDoor(DOOR_OPEN_1 | DOOR_OPEN_2 | DOOR_NO_DELAY); -#else - OpenDoor(DOOR_OPEN_2 | DOOR_NO_DELAY); -#endif #if DEBUG CheckElementDescriptions(); @@ -7815,19 +7417,10 @@ void DrawLevelEd() } /* copy default editor door content to main double buffer */ -#if 1 BlitBitmap(graphic_info[IMG_BACKGROUND_PALETTE].bitmap, drawto, graphic_info[IMG_BACKGROUND_PALETTE].src_x, graphic_info[IMG_BACKGROUND_PALETTE].src_y, DXSIZE, DYSIZE, DX, DY); -#else - BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, - DOOR_GFX_PAGEX6, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY); -#endif - -#if 0 - printf("::: %d, %d / %d, %d\n", VX, VY, EX, EY); -#endif /* draw bigger door */ DrawSpecialEditorDoor(); @@ -7838,53 +7431,23 @@ void DrawLevelEd() redraw_mask |= REDRAW_ALL; -#if 1 FreeLevelEditorGadgets(); CreateLevelEditorGadgets(); -#endif ReinitializeElementList(); /* update dynamic level element list */ ReinitializeElementListButtons(); /* custom element may look different */ InitElementPropertiesGfxElement(); -#if 1 UnmapAllGadgets(); -#else - UnmapTapeButtons(); -#endif MapControlButtons(); -#if 0 - FadeOut(REDRAW_FIELD); -#endif - DrawEditModeWindow(); -#if 1 FadeIn(playfield_area_changed ? REDRAW_ALL : REDRAW_FIELD); -#else - FadeIn(REDRAW_FIELD); - // FadeIn(REDRAW_ALL); -#endif /* copy actual editor door content to door double buffer for OpenDoor() */ -#if 1 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0); -#else - BlitBitmap(drawto, bitmap_db_door, - DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1); -#endif - -#if 0 - /* draw new control window (with border) to window */ - redraw_mask |= REDRAW_ALL; - BackToFront(); -#endif - -#if 0 - OpenDoor(DOOR_OPEN_1); -#endif } static void AdjustDrawingAreaGadgets() @@ -7930,24 +7493,14 @@ static void AdjustDrawingAreaGadgets() xoffset = (ed_fieldx == MAX_ED_FIELDX ? ED_SCROLLBUTTON_XSIZE : 0); yoffset = (ed_fieldy == MAX_ED_FIELDY ? ED_SCROLLBUTTON_YSIZE : 0); -#if 1 x = SX + scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_RIGHT].x + xoffset; y = SX + scrollbutton_pos[ED_SCROLLBUTTON_ID_AREA_DOWN].y + yoffset; -#else - x = SX + scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_RIGHT].x + xoffset; - y = SX + scrollbutton_info[ED_SCROLLBUTTON_ID_AREA_DOWN].y + yoffset; -#endif ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_RIGHT], GDI_X, x, GDI_END); ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_DOWN], GDI_Y, y, GDI_END); -#if 1 width = scrollbar_pos[ED_SCROLLBAR_ID_AREA_HORIZONTAL].width + xoffset; height = scrollbar_pos[ED_SCROLLBAR_ID_AREA_VERTICAL].height + yoffset; -#else - width = scrollbar_info[ED_SCROLLBAR_ID_AREA_HORIZONTAL].width + xoffset; - height = scrollbar_info[ED_SCROLLBAR_ID_AREA_VERTICAL].height + yoffset; -#endif ModifyGadget(level_editor_gadget[GADGET_ID_SCROLL_HORIZONTAL], GDI_WIDTH, width, @@ -8179,10 +7732,6 @@ static void DrawLevelInfoTabulatorGadgets() Pixel tab_color = GetPixel(gd->bitmap, gd_x, gd_y); int id_first = ED_TEXTBUTTON_ID_LEVELINFO_LEVEL; int id_last = ED_TEXTBUTTON_ID_LEVELINFO_EDITOR; -#if 1 -#else - int max_tabs = 2; -#endif int i; for (i = id_first; i <= id_last; i++) @@ -8202,19 +7751,11 @@ static void DrawLevelInfoTabulatorGadgets() MapTextbuttonGadget(i); } -#if 1 /* draw little border line below tabulator buttons */ if (tab_color != BLACK_PIXEL) /* black => transparent */ FillRectangle(drawto, gd_gi1->x, gd_gi1->y + gd_gi1->height + 1, getTabulatorBarWidth(), ED_GADGET_DISTANCE, tab_color); -#else - /* draw little border line below tabulator buttons */ - if (tab_color != BLACK_PIXEL) /* black => transparent */ - FillRectangle(drawto, gd_gi1->x, gd_gi1->y + gd_gi1->height + 1, - max_tabs * gd_gi1->width + (max_tabs -1) * ED_GADGET_DISTANCE, - ED_GADGET_DISTANCE, tab_color); -#endif } static void DrawPropertiesTabulatorGadgets() @@ -8226,10 +7767,6 @@ static void DrawPropertiesTabulatorGadgets() Pixel tab_color = GetPixel(gd->bitmap, gd_x, gd_y); int id_first = ED_TEXTBUTTON_ID_PROPERTIES_INFO; int id_last = ED_TEXTBUTTON_ID_PROPERTIES_CONFIG; -#if 1 -#else - int max_tabs = 4; -#endif int i; /* draw two config tabulators for player elements */ @@ -8263,19 +7800,11 @@ static void DrawPropertiesTabulatorGadgets() MapTextbuttonGadget(i); } -#if 1 /* draw little border line below tabulator buttons */ if (tab_color != BLACK_PIXEL) /* black => transparent */ FillRectangle(drawto, gd_gi1->x, gd_gi1->y + gd_gi1->height + 1, getTabulatorBarWidth(), ED_GADGET_DISTANCE, tab_color); -#else - /* draw little border line below tabulator buttons */ - if (tab_color != BLACK_PIXEL) /* black => transparent */ - FillRectangle(drawto, gd_gi1->x, gd_gi1->y + gd_gi1->height + 1, - max_tabs * gd_gi1->width + (max_tabs -1) * ED_GADGET_DISTANCE, - ED_GADGET_DISTANCE, tab_color); -#endif } static void DrawLevelInfoLevel() @@ -8324,19 +7853,7 @@ static void DrawLevelInfoWindow() SetMainBackgroundImage(IMG_BACKGROUND_EDITOR); ClearField(); -#if 1 -#if 1 DrawTextSCentered(ED_SETTINGS1_YPOS, FONT_TITLE_1, "Global Settings"); -#else - DrawTextSCentered(ED_SETTINGS1_YPOS, FONT_TITLE_1, "Level Settings"); - DrawTextSCentered(ED_SETTINGS2_YPOS, FONT_TITLE_1, "Editor Settings"); -#endif -#else - DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS1_YPOS, - "Level Settings", FONT_TITLE_1); - DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS2_YPOS, - "Editor Settings", FONT_TITLE_1); -#endif DrawLevelInfoTabulatorGadgets(); @@ -8574,21 +8091,11 @@ static int PrintElementDescriptionFromFile(char *filename, int start_line) int max_lines_per_screen = (SYSIZE - pad_y) / font_height - 1; int max_lines_drawable = max_lines_per_screen - start_line; -#if 0 - printf("::: SYSIZE == %d [%d / %d / %d]\n", SYSIZE, - max_chars_per_line, max_lines_per_screen, max_lines_drawable); -#endif - if (start_line >= max_lines_per_screen) return FALSE; -#if 1 return DrawTextFile(sx, sy, filename, font_nr, max_chars_per_line, -1, max_lines_drawable, 0, -1, TRUE, FALSE, FALSE); -#else - return DrawTextFile(sx, sy, filename, font_nr, max_chars_per_line, -1, - max_lines_per_screen, 0, -1, TRUE, FALSE, FALSE); -#endif } static void DrawPropertiesInfo() @@ -9310,12 +8817,7 @@ static void DrawPropertiesWindow() SetMainBackgroundImage(IMG_BACKGROUND_EDITOR); ClearField(); -#if 1 DrawTextSCentered(ED_SETTINGS1_YPOS, FONT_TITLE_1, "Element Settings"); -#else - DrawText(SX + ED_SETTINGS2_XPOS, SY + ED_SETTINGS1_YPOS, - "Element Settings", FONT_TITLE_1); -#endif FrameCounter = 0; /* restart animation frame counter */ @@ -10539,11 +10041,7 @@ static void SelectArea(int from_x, int from_y, int to_x, int to_y, static void CopyBrushExt(int from_x, int from_y, int to_x, int to_y, int button, int mode) { -#if 1 static short brush_buffer[MAX_LEV_FIELDX][MAX_LEV_FIELDY]; -#else - static short brush_buffer[MAX_ED_FIELDX][MAX_ED_FIELDY]; -#endif static int brush_width, brush_height; static int last_cursor_x = -1, last_cursor_y = -1; static boolean delete_old_brush; @@ -10725,9 +10223,6 @@ static int DrawLevelText(int sx, int sy, char letter, int mode) { static short delete_buffer[MAX_LEV_FIELDX]; static int start_sx; -#if 0 - static int start_sy; -#endif static int last_sx, last_sy; static boolean typing = FALSE; int letter_element = EL_CHAR_ASCII0 + letter; @@ -10770,9 +10265,6 @@ static int DrawLevelText(int sx, int sy, char letter, int mode) typing = TRUE; start_sx = sx; -#if 0 - start_sy = sy; -#endif last_sx = sx; last_sy = sy; DrawLevelText(sx, sy, 0, TEXT_SETCURSOR); @@ -10904,9 +10396,7 @@ static void RandomPlacement(int new_element) int num_percentage, num_elements; int x, y; -#if 1 ResetIntelliDraw(); -#endif /* determine number of free positions for randomly placing the new element */ for (x = 0; x < lev_fieldx; x++) for (y = 0; y < lev_fieldy; y++) @@ -10931,11 +10421,7 @@ static void RandomPlacement(int new_element) for (x = 0; x < lev_fieldx; x++) for (y = 0; y < lev_fieldy; y++) if (free_position[x][y]) -#if 1 SetElement(x, y, new_element); -#else - Feld[x][y] = new_element; -#endif } else { @@ -10948,11 +10434,7 @@ static void RandomPlacement(int new_element) if (free_position[x][y]) { free_position[x][y] = FALSE; -#if 1 SetElement(x, y, new_element); -#else - Feld[x][y] = new_element; -#endif num_elements--; } } @@ -11071,10 +10553,6 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) if (edit_mode == ED_MODE_DRAWING && draw_with_brush && !inside_drawing_area) DeleteBrushFromCursor(); - -#if 0 - ResetIntelliDraw(); -#endif } if (!button || button_release_event) @@ -11082,50 +10560,20 @@ static void HandleDrawingAreas(struct GadgetInfo *gi) if (draw_with_brush) { -#if 0 - if (!button_release_event) -#endif - CopyBrushToLevel(sx, sy, button); + CopyBrushToLevel(sx, sy, button); } -#if 1 else -#else - else if (new_element != Feld[lx][ly]) -#endif { if (new_element == EL_PLAYER_1) { /* remove player at old position */ for (y = 0; y < lev_fieldy; y++) - { for (x = 0; x < lev_fieldx; x++) - { if (Feld[x][y] == EL_PLAYER_1) - { -#if 1 SetElement(x, y, EL_EMPTY); -#else - Feld[x][y] = EL_EMPTY; -#if 1 - if (IN_ED_FIELD(x - level_xpos, y - level_ypos)) - DrawMiniElement(x - level_xpos, y - level_ypos, EL_EMPTY); -#else - if (x - level_xpos >= 0 && x - level_xpos < ed_fieldx && - y - level_ypos >= 0 && y - level_ypos < ed_fieldy) - DrawMiniElement(x - level_xpos, y - level_ypos, EL_EMPTY); -#endif -#endif - } - } - } } -#if 1 SetElementButton(lx, ly, new_element, button); -#else - Feld[lx][ly] = new_element; - DrawMiniElement(sx, sy, new_element); -#endif } } else @@ -11383,14 +10831,9 @@ static void HandleTextAreaGadgets(struct GadgetInfo *gi) { int type_id = gi->custom_type_id; -#if 1 strncpy(textarea_info[type_id].value, gi->textarea.value, MAX_ENVELOPE_TEXT_LEN); textarea_info[type_id].value[MAX_ENVELOPE_TEXT_LEN] = '\0'; -#else - /* !!! BUGGY !!! MAX_ENVELOPE_TEXT_LEN != MAX_GADGET_TEXTSIZE !!! */ - strcpy(textarea_info[type_id].value, gi->textarea.value); -#endif level.changed = TRUE; } @@ -11934,20 +11377,10 @@ static void HandleControlButtons(struct GadgetInfo *gi) CloseDoor(DOOR_CLOSE_ALL); -#if 0 - BackToFront(); /* force redraw of undrawn special door */ -#endif - -#if 1 /* needed before playing if editor playfield area has different size */ ClearRectangle(drawto, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); redraw_mask = REDRAW_ALL; -#endif - -#if 0 - DrawCompleteVideoDisplay(); -#endif level_editor_test_game = TRUE; @@ -12425,41 +11858,17 @@ void RequestExitLevelEditor(boolean ask_if_level_has_changed, Request("Level has changed! Exit without saving?", REQ_ASK | REQ_STAY_OPEN)) { -#if 1 - // CloseDoor(DOOR_CLOSE_1); SetDoorState(DOOR_CLOSE_2); -#else - CloseDoor(DOOR_CLOSE_1); - SetDoorState(DOOR_CLOSE_2); -#endif -#if 1 if (quick_quit) FadeSkipNextFadeIn(); -#else - if (quick_quit) - fading = fading_none; -#endif game_status = GAME_MODE_MAIN; -#if 1 + DrawAndFadeInMainMenu(playfield_area_changed ? REDRAW_ALL : REDRAW_FIELD); -#else -#if 1 - DrawAndFadeInMainMenu(REDRAW_FIELD); -#else - DrawMainMenu(); -#endif -#endif } else { -#if 1 - // CloseDoor(DOOR_CLOSE_1); - OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK); -#else - CloseDoor(DOOR_CLOSE_1); OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK); -#endif } } diff --git a/src/engines.h b/src/engines.h index 773005c4..d1181edb 100644 --- a/src/engines.h +++ b/src/engines.h @@ -26,13 +26,8 @@ extern void SetBitmaps_EM(Bitmap **); extern void UpdateEngineValues(int, int); -extern void DrawAllGameValues(int, int, int, int, int); -#if 1 extern boolean getTeamMode_EM(); -#else -extern int getNumActivePlayers_EM(); -#endif extern int getGameFrameDelay_EM(int); extern void PlayLevelSound_EM(int, int, int, int); @@ -48,10 +43,6 @@ void getGraphicSourcePlayerExt_EM(struct GraphicInfo_EM *, int, int, int); /* functions and definitions exported from main program to game_sp */ /* ========================================================================= */ -#if 0 -extern void SetBitmaps_SP(Bitmap **); -#endif - void CheckSingleStepMode_SP(boolean, boolean); void getGraphicSource_SP(struct GraphicInfo_SP *, int, int, int, int); diff --git a/src/events.c b/src/events.c index 709ad453..14e7df86 100644 --- a/src/events.c +++ b/src/events.c @@ -210,15 +210,10 @@ void EventLoop(void) SetMouseCursor(CURSOR_DEFAULT); playfield_cursor_set = FALSE; } - -#if 0 - HandleNoEvent(); -#endif } -#if 1 + /* also execute after pending events have been processed before */ HandleNoEvent(); -#endif /* don't use all CPU time when idle; the main loop while playing has its own synchronization and is CPU friendly, too */ @@ -230,6 +225,7 @@ void EventLoop(void) else { SyncDisplay(); + if (!PendingEvent()) /* delay only if no pending events */ Delay(10); } @@ -299,11 +295,7 @@ void ClearEventQueue() break; case EVENT_KEYRELEASE: -#if 1 ClearPlayerAction(); -#else - key_joystick_mapping = 0; -#endif break; default: @@ -408,6 +400,7 @@ void HandleMotionEvent(MotionEvent *event) } #if defined(TARGET_SDL2) + void HandleWindowEvent(WindowEvent *event) { #if DEBUG_EVENTS @@ -439,23 +432,8 @@ void HandleWindowEvent(WindowEvent *event) event->event == SDL_WINDOWEVENT_EXPOSED) SDLRedrawWindow(); -#if 0 - if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) - { - // if game started in fullscreen mode, window will also get fullscreen size - if (!video.fullscreen_enabled && video.fullscreen_initial) - { - SDLSetWindowScaling(setup.window_scaling_percent); - - // only do this correction once - video.fullscreen_initial = FALSE; - } - } -#endif - if (event->event == SDL_WINDOWEVENT_RESIZED && !video.fullscreen_enabled) { -#if 1 int new_window_width = event->data1; int new_window_height = event->data2; @@ -466,12 +444,6 @@ void HandleWindowEvent(WindowEvent *event) int new_xpercent = (100 * new_window_width / video.width); int new_ypercent = (100 * new_window_height / video.height); -#if 0 - printf("::: RESIZED from %d, %d to %d, %d\n", - video.window_width, video.window_height, - new_window_width, new_window_height); -#endif - setup.window_scaling_percent = video.window_scaling_percent = MIN(MAX(MIN_WINDOW_SCALING_PERCENT, MIN(new_xpercent, new_ypercent)), MAX_WINDOW_SCALING_PERCENT); @@ -479,50 +451,14 @@ void HandleWindowEvent(WindowEvent *event) video.window_width = new_window_width; video.window_height = new_window_height; -#if 0 - printf("::: setup.window_scaling_percent set to %d\n", - setup.window_scaling_percent); -#endif - if (game_status == GAME_MODE_SETUP) RedrawSetupScreenAfterFullscreenToggle(); SetWindowTitle(); } -#else - // prevent slightly wrong scaling factor due to rounding differences - float scaling_factor = (float)setup.window_scaling_percent / 100; - int old_xsize = (int)(scaling_factor * video.width); - int old_ysize = (int)(scaling_factor * video.height); - int new_xsize = event->data1; - int new_ysize = event->data2; - - // window size is unchanged when going from fullscreen to window mode, - // but reverse calculation of scaling factor might result in a scaling - // factor that is slightly different due to rounding differences; - // therefore compare old/new window size and not old/new scaling factor - if (old_xsize != new_xsize || - old_ysize != new_ysize) - { - int new_xpercent = (100 * new_xsize / video.width); - int new_ypercent = (100 * new_ysize / video.height); - - setup.window_scaling_percent = MIN(new_xpercent, new_ypercent); - - if (setup.window_scaling_percent < MIN_WINDOW_SCALING_PERCENT) - setup.window_scaling_percent = MIN_WINDOW_SCALING_PERCENT; - else if (setup.window_scaling_percent > MAX_WINDOW_SCALING_PERCENT) - setup.window_scaling_percent = MAX_WINDOW_SCALING_PERCENT; - - printf("::: setup.window_scaling_percent set to %d\n", - setup.window_scaling_percent); - } -#endif } } -#if 1 - #define NUM_TOUCH_FINGERS 3 static struct @@ -549,7 +485,6 @@ void HandleFingerEvent(FingerEvent *event) float event_x = event->x; float event_y = event->y; -#if 1 #if DEBUG_EVENTS Error(ERR_DEBUG, "FINGER EVENT: finger was %s, touch ID %lld, finger ID %lld, x/y %f/%f, dx/dy %f/%f, pressure %f", event->type == EVENT_FINGERPRESS ? "pressed" : @@ -559,23 +494,15 @@ void HandleFingerEvent(FingerEvent *event) event->x, event->y, event->dx, event->dy, event->pressure); -#endif #endif if (game_status != GAME_MODE_PLAYING) return; -#if 1 if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS)) -#else - boolean use_virtual_button_control = FALSE; - - if (use_virtual_button_control) -#endif { int key_status = (event->type == EVENT_FINGERRELEASE ? KEY_RELEASED : KEY_PRESSED); -#if 1 Key key = (event->x < 1.0 / 3.0 ? (event->y < 1.0 / 2.0 ? setup.input[0].key.snap : setup.input[0].key.drop) : @@ -585,23 +512,8 @@ void HandleFingerEvent(FingerEvent *event) event->x < 5.0 / 6.0 ? setup.input[0].key.left : setup.input[0].key.right) : KSYM_UNDEFINED); -#if 0 - char *key_name = (key == setup.input[0].key.snap ? "SNAP" : - key == setup.input[0].key.drop ? "DROP" : - key == setup.input[0].key.up ? "UP" : - key == setup.input[0].key.down ? "DOWN" : - key == setup.input[0].key.left ? "LEFT" : - key == setup.input[0].key.right ? "RIGHT" : "(unknown)"); -#endif char *key_status_name = (key_status == KEY_RELEASED ? "KEY_RELEASED" : "KEY_PRESSED"); -#else - Key key = (event->y < 1.0 / 3.0 ? setup.input[0].key.up : - event->y > 2.0 / 3.0 ? setup.input[0].key.down : - event->x < 1.0 / 3.0 ? setup.input[0].key.left : - event->x > 2.0 / 3.0 ? setup.input[0].key.right : - setup.input[0].key.snap); -#endif int i; Error(ERR_DEBUG, "::: key '%s' was '%s' [fingerId: %lld]", @@ -711,15 +623,6 @@ void HandleFingerEvent(FingerEvent *event) } } -#if 0 -#if 1 - Error(ERR_DEBUG, "=> key == '%s', key_status == '%s' [slot %d]", - key_name, key_status_name, i); -#else - Error(ERR_DEBUG, "=> key == %d, key_status == %d [%d]", key, key_status, i); -#endif -#endif - return; } @@ -858,94 +761,6 @@ void HandleFingerEvent(FingerEvent *event) } } -#else - -void HandleFingerEvent(FingerEvent *event) -{ -#if 0 - static int num_events = 0; - int max_events = 10; -#endif - -#if 0 -#if DEBUG_EVENTS - Error(ERR_DEBUG, "FINGER EVENT: finger was %s, touch ID %lld, finger ID %lld, x/y %f/%f, dx/dy %f/%f, pressure %f", - event->type == EVENT_FINGERPRESS ? "pressed" : - event->type == EVENT_FINGERRELEASE ? "released" : "moved", - event->touchId, - event->fingerId, - event->x, event->y, - event->dx, event->dy, - event->pressure); -#endif -#endif - -#if 0 - int x = (int)(event->x * video.width); - int y = (int)(event->y * video.height); - int button = MB_LEFTBUTTON; - - Error(ERR_DEBUG, "=> screen x/y %d/%d", x, y); -#endif - -#if 0 - if (++num_events >= max_events) - CloseAllAndExit(0); -#endif - -#if 1 -#if 0 - if (event->type == EVENT_FINGERPRESS || - event->type == EVENT_FINGERMOTION) - button_status = button; - else - button_status = MB_RELEASED; - - int max_x = SX + SXSIZE; - int max_y = SY + SYSIZE; -#endif - -#if 1 - if (game_status == GAME_MODE_PLAYING) -#else - if (game_status == GAME_MODE_PLAYING && - x < max_x) -#endif - { - int key_status = (event->type == EVENT_FINGERRELEASE ? KEY_RELEASED : - KEY_PRESSED); -#if 1 - Key key = (event->y < 1.0 / 3.0 ? setup.input[0].key.up : - event->y > 2.0 / 3.0 ? setup.input[0].key.down : - event->x < 1.0 / 3.0 ? setup.input[0].key.left : - event->x > 2.0 / 3.0 ? setup.input[0].key.right : - setup.input[0].key.drop); -#else - Key key = (y < max_y / 3 ? setup.input[0].key.up : - y > 2 * max_y / 3 ? setup.input[0].key.down : - x < max_x / 3 ? setup.input[0].key.left : - x > 2 * max_x / 3 ? setup.input[0].key.right : - setup.input[0].key.drop); -#endif - - Error(ERR_DEBUG, "=> key == %d, key_status == %d", key, key_status); - - HandleKey(key, key_status); - } - else - { -#if 0 - Error(ERR_DEBUG, "::: button_status == %d, button == %d\n", - button_status, button); - - HandleButton(x, y, button_status, button); -#endif - } -#endif -} - -#endif - static boolean checkTextInputKeyModState() { // when playing, only handle raw key events and ignore text input @@ -1014,13 +829,6 @@ void HandleKeyEvent(KeyEvent *event) getKeyNameFromKey(key)); #endif -#if 0 - if (key == KSYM_Menu) - Error(ERR_DEBUG, "menu key pressed"); - else if (key == KSYM_Back) - Error(ERR_DEBUG, "back key pressed"); -#endif - #if defined(PLATFORM_ANDROID) // always map the "back" button to the "escape" key on Android devices if (key == KSYM_Back) @@ -1030,12 +838,6 @@ void HandleKeyEvent(KeyEvent *event) HandleKeyModState(keymod, key_status); #if defined(TARGET_SDL2) - - // if (game_status == GAME_MODE_PLAYING || GetKeyModState() == KMOD_None) - /* - if (game_status == GAME_MODE_PLAYING || - (GetKeyModState() & KMOD_TextInput) == KMOD_None) - */ if (!checkTextInputKeyModState()) HandleKey(key, key_status); #else @@ -1132,10 +934,6 @@ void HandleButton(int mx, int my, int button, int button_nr) if (IS_WHEEL_BUTTON(button_nr)) return; -#if 0 - Error(ERR_DEBUG, "::: game_status == %d", game_status); -#endif - switch (game_status) { case GAME_MODE_TITLE: @@ -1400,15 +1198,11 @@ void HandleKey(Key key, int key_status) if (stored_player[pnr].action & KEY_BUTTON_DROP) element_dropped[pnr] = TRUE; } -#if 1 else if (key_status == KEY_PRESSED && key_action & KEY_BUTTON_DROP) { if (level.game_engine_type == GAME_ENGINE_TYPE_EM || level.game_engine_type == GAME_ENGINE_TYPE_SP) { -#if 0 - printf("::: drop key pressed\n"); -#endif if (level.game_engine_type == GAME_ENGINE_TYPE_SP && getRedDiskReleaseFlag_SP() == 0) @@ -1417,7 +1211,6 @@ void HandleKey(Key key, int key_status) TapeTogglePause(TAPE_TOGGLE_AUTOMATIC); } } -#endif else if (key_status == KEY_RELEASED && key_action & KEY_BUTTON) { if (key_action & KEY_BUTTON_SNAP) @@ -1436,7 +1229,6 @@ void HandleKey(Key key, int key_status) element_snapped[pnr] = FALSE; } -#if 1 if (key_action & KEY_BUTTON_DROP && level.game_engine_type == GAME_ENGINE_TYPE_RND) { @@ -1455,7 +1247,6 @@ void HandleKey(Key key, int key_status) element_dropped[pnr] = FALSE; } -#endif } } else if (tape.recording && tape.pausing) @@ -1496,10 +1287,6 @@ void HandleKey(Key key, int key_status) { setup.fullscreen = !setup.fullscreen; -#if 0 - printf("::: %d\n", setup.window_scaling_percent); -#endif - ToggleFullscreenOrChangeWindowScalingIfNeeded(); if (game_status == GAME_MODE_SETUP) @@ -1535,13 +1322,8 @@ void HandleKey(Key key, int key_status) return; } -#if 0 - if (game_status == GAME_MODE_PLAYING && local_player->LevelSolved_GameEnd && - (key == KSYM_Return || key == setup.shortcut.toggle_pause)) -#else if (game_status == GAME_MODE_PLAYING && AllPlayersGone && (key == KSYM_Return || key == setup.shortcut.toggle_pause)) -#endif { GameEnd(); @@ -1710,17 +1492,6 @@ void HandleKey(Key key, int key_status) #ifdef DEBUG case KSYM_0: -#if 0 - case KSYM_1: - case KSYM_2: - case KSYM_3: - case KSYM_4: - case KSYM_5: - case KSYM_6: - case KSYM_7: - case KSYM_8: - case KSYM_9: -#endif if (key == KSYM_0) { if (GameFrameDelay == 500) @@ -1769,28 +1540,6 @@ void HandleKey(Key key, int key_status) break; #endif -#if 0 - case KSYM_f: - ScrollStepSize = TILEX / 8; - printf("ScrollStepSize == %d (1/8)\n", ScrollStepSize); - break; - - case KSYM_g: - ScrollStepSize = TILEX / 4; - printf("ScrollStepSize == %d (1/4)\n", ScrollStepSize); - break; - - case KSYM_h: - ScrollStepSize = TILEX / 2; - printf("ScrollStepSize == %d (1/2)\n", ScrollStepSize); - break; - - case KSYM_l: - ScrollStepSize = TILEX; - printf("ScrollStepSize == %d (1/1)\n", ScrollStepSize); - break; -#endif - case KSYM_v: printf("::: currently using game engine version %d\n", game.engine_version); @@ -1819,10 +1568,6 @@ void HandleNoEvent() if (button_status && game_status != GAME_MODE_PLAYING) { HandleButton(0, 0, -button_status, button_status); - -#if 0 - return; -#endif } else { @@ -1932,21 +1677,11 @@ void HandleJoystick() HandleHallOfFame(0, 0, dx, dy, !newbutton); break; -#if 0 - case GAME_MODE_EDITOR: - HandleLevelEditorIdle(); - break; -#endif - case GAME_MODE_PLAYING: if (tape.playing || keyboard) newbutton = ((joy & JOY_BUTTON) != 0); -#if 0 - if (newbutton && local_player->LevelSolved_GameEnd) -#else if (newbutton && AllPlayersGone) -#endif { GameEnd(); diff --git a/src/files.c b/src/files.c index 16af2dd4..343c6d94 100644 --- a/src/files.c +++ b/src/files.c @@ -21,6 +21,9 @@ #include "tools.h" #include "tape.h" +#define ENABLE_UNUSED_CODE 0 /* currently unused functions */ +#define ENABLE_HISTORIC_CHUNKS 0 /* only for historic reference */ +#define ENABLE_RESERVED_CODE 0 /* reserved for later use */ #define CHUNK_ID_LEN 4 /* IFF style chunk id length */ #define CHUNK_SIZE_UNDEFINED 0 /* undefined chunk size == 0 */ @@ -867,8 +870,8 @@ static struct LevelFileConfigInfo chunk_config_CUSX_base[] = &xx_ei.properties[EP_BITFIELD_BASE_NR], EP_BITMASK_BASE_DEFAULT, &yy_ei.properties[EP_BITFIELD_BASE_NR] }, -#if 0 - /* (reserved) */ +#if ENABLE_RESERVED_CODE + /* (reserved for later use) */ { -1, -1, TYPE_BITFIELD, CONF_VALUE_32_BIT(2), @@ -1320,13 +1323,6 @@ filetype_id_list[] = static boolean check_special_flags(char *flag) { -#if 0 - printf("::: '%s', '%s', '%s'\n", - flag, - options.special_flags, - leveldir_current->special_flags); -#endif - if (strEqual(options.special_flags, flag) || strEqual(leveldir_current->special_flags, flag)) return TRUE; @@ -1575,11 +1571,6 @@ void setElementChangeInfoToDefaults(struct ElementChangeInfo *change) { xx_change = *change; /* copy change data into temporary buffer */ -#if 0 - /* (not needed; set by setConfigToDefaultsFromConfigList()) */ - xx_num_contents = 1; -#endif - setConfigToDefaultsFromConfigList(chunk_config_CUSX_change); *change = xx_change; @@ -1594,8 +1585,6 @@ void setElementChangeInfoToDefaults(struct ElementChangeInfo *change) change->post_change_function = NULL; } -#if 1 - static void setLevelInfoToDefaults_Level(struct LevelInfo *level) { int i, x, y; @@ -1780,183 +1769,6 @@ static void setLevelInfoToDefaults(struct LevelInfo *level, level->changed = FALSE; } -#else - -static void setLevelInfoToDefaults(struct LevelInfo *level, - boolean level_info_only) -{ - static boolean clipboard_elements_initialized = FALSE; - int i, x, y; - - if (level_info_only) - return; - - InitElementPropertiesStatic(); - - li = *level; /* copy level data into temporary buffer */ - - setConfigToDefaultsFromConfigList(chunk_config_INFO); - setConfigToDefaultsFromConfigList(chunk_config_ELEM); - - *level = li; /* copy temporary buffer back to level data */ - - setLevelInfoToDefaults_EM(); - setLevelInfoToDefaults_SP(); - - level->native_em_level = &native_em_level; - level->native_sp_level = &native_sp_level; - - level->file_version = FILE_VERSION_ACTUAL; - level->game_version = GAME_VERSION_ACTUAL; - - level->creation_date = getCurrentDate(); - - level->encoding_16bit_field = TRUE; - level->encoding_16bit_yamyam = TRUE; - level->encoding_16bit_amoeba = TRUE; - - for (x = 0; x < MAX_LEV_FIELDX; x++) - for (y = 0; y < MAX_LEV_FIELDY; y++) - level->field[x][y] = EL_SAND; - - for (i = 0; i < MAX_LEVEL_NAME_LEN; i++) - level->name[i] = '\0'; - for (i = 0; i < MAX_LEVEL_AUTHOR_LEN; i++) - level->author[i] = '\0'; - - strcpy(level->name, NAMELESS_LEVEL_NAME); - strcpy(level->author, ANONYMOUS_NAME); - - level->field[0][0] = EL_PLAYER_1; - level->field[STD_LEV_FIELDX - 1][STD_LEV_FIELDY - 1] = EL_EXIT_CLOSED; - - for (i = 0; i < MAX_NUM_ELEMENTS; i++) - { - int element = i; - struct ElementInfo *ei = &element_info[element]; - - /* never initialize clipboard elements after the very first time */ - /* (to be able to use clipboard elements between several levels) */ - if (IS_CLIPBOARD_ELEMENT(element) && clipboard_elements_initialized) - continue; - - if (IS_ENVELOPE(element)) - { - int envelope_nr = element - EL_ENVELOPE_1; - - setConfigToDefaultsFromConfigList(chunk_config_NOTE); - - level->envelope[envelope_nr] = xx_envelope; - } - - if (IS_CUSTOM_ELEMENT(element) || - IS_GROUP_ELEMENT(element) || - IS_INTERNAL_ELEMENT(element)) - { - xx_ei = *ei; /* copy element data into temporary buffer */ - - setConfigToDefaultsFromConfigList(chunk_config_CUSX_base); - - *ei = xx_ei; - } - - setElementChangePages(ei, 1); - setElementChangeInfoToDefaults(ei->change); - - if (IS_CUSTOM_ELEMENT(element) || - IS_GROUP_ELEMENT(element) || - IS_INTERNAL_ELEMENT(element)) - { - setElementDescriptionToDefault(ei); - - ei->modified_settings = FALSE; - } - - if (IS_CUSTOM_ELEMENT(element) || - IS_INTERNAL_ELEMENT(element)) - { - /* internal values used in level editor */ - - ei->access_type = 0; - ei->access_layer = 0; - ei->access_protected = 0; - ei->walk_to_action = 0; - ei->smash_targets = 0; - ei->deadliness = 0; - - ei->can_explode_by_fire = FALSE; - ei->can_explode_smashed = FALSE; - ei->can_explode_impact = FALSE; - - ei->current_change_page = 0; - } - - if (IS_GROUP_ELEMENT(element) || - IS_INTERNAL_ELEMENT(element)) - { - struct ElementGroupInfo *group; - - /* initialize memory for list of elements in group */ - if (ei->group == NULL) - ei->group = checked_malloc(sizeof(struct ElementGroupInfo)); - - group = ei->group; - - xx_group = *group; /* copy group data into temporary buffer */ - - setConfigToDefaultsFromConfigList(chunk_config_GRPX); - - *group = xx_group; - } - } - - clipboard_elements_initialized = TRUE; - - BorderElement = EL_STEELWALL; - - level->no_valid_file = FALSE; - - level->changed = FALSE; - - /* set all bug compatibility flags to "false" => do not emulate this bug */ - level->use_action_after_change_bug = FALSE; - - if (leveldir_current) - { - /* try to determine better author name than 'anonymous' */ - if (!strEqual(leveldir_current->author, ANONYMOUS_NAME)) - { - strncpy(level->author, leveldir_current->author, MAX_LEVEL_AUTHOR_LEN); - level->author[MAX_LEVEL_AUTHOR_LEN] = '\0'; - } - else - { - switch (LEVELCLASS(leveldir_current)) - { - case LEVELCLASS_TUTORIAL: - strcpy(level->author, PROGRAM_AUTHOR_STRING); - break; - - case LEVELCLASS_CONTRIB: - strncpy(level->author, leveldir_current->name, MAX_LEVEL_AUTHOR_LEN); - level->author[MAX_LEVEL_AUTHOR_LEN] = '\0'; - break; - - case LEVELCLASS_PRIVATE: - strncpy(level->author, getRealName(), MAX_LEVEL_AUTHOR_LEN); - level->author[MAX_LEVEL_AUTHOR_LEN] = '\0'; - break; - - default: - /* keep default value */ - break; - } - } - } -} - -#endif - static void setFileInfoToDefaults(struct LevelFileInfo *level_file_info) { level_file_info->nr = 0; @@ -2029,14 +1841,8 @@ static int getFileTypeFromBasename(char *basename) /* ---------- try to determine file type from filename ---------- */ /* check for typical filename of a Supaplex level package file */ -#if 1 if (strlen(basename) == 10 && strPrefixLower(basename, "levels.d")) return LEVEL_FILE_TYPE_SP; -#else - if (strlen(basename) == 10 && (strncmp(basename, "levels.d", 8) == 0 || - strncmp(basename, "LEVELS.D", 8) == 0)) - return LEVEL_FILE_TYPE_SP; -#endif /* check for typical filename of a Diamond Caves II level package file */ if (strSuffixLower(basename, ".dc") || @@ -2088,8 +1894,6 @@ static char *getSingleLevelBasename(int nr) return getSingleLevelBasenameExt(nr, LEVELFILE_EXTENSION); } -#if 1 - static char *getPackedLevelBasename(int type) { static char basename[MAX_FILENAME_LEN]; @@ -2128,54 +1932,12 @@ static char *getPackedLevelBasename(int type) return basename; } -#else - -static char *getPackedLevelBasename(int type) -{ - static char basename[MAX_FILENAME_LEN]; - char *directory = getCurrentLevelDir(); - DIR *dir; - struct dirent *dir_entry; - - strcpy(basename, UNDEFINED_FILENAME); /* default: undefined file */ - - if ((dir = opendir(directory)) == NULL) - { - Error(ERR_WARN, "cannot read current level directory '%s'", directory); - - return basename; - } - - while ((dir_entry = readdir(dir)) != NULL) /* loop until last dir entry */ - { - char *entry_basename = dir_entry->d_name; - int entry_type = getFileTypeFromBasename(entry_basename); - - if (entry_type != LEVEL_FILE_TYPE_UNKNOWN) /* found valid level package */ - { - if (type == LEVEL_FILE_TYPE_UNKNOWN || - type == entry_type) - { - strcpy(basename, entry_basename); - - break; - } - } - } - - closedir(dir); - - return basename; -} - -#endif - static char *getSingleLevelFilename(int nr) { return getLevelFilenameFromBasename(getSingleLevelBasename(nr)); } -#if 0 +#if ENABLE_UNUSED_CODE static char *getPackedLevelFilename(int type) { return getLevelFilenameFromBasename(getPackedLevelBasename(type)); @@ -2187,7 +1949,7 @@ char *getDefaultLevelFilename(int nr) return getSingleLevelFilename(nr); } -#if 0 +#if ENABLE_UNUSED_CODE static void setLevelFileInfo_SingleLevelFilename(struct LevelFileInfo *lfi, int type) { @@ -2259,7 +2021,6 @@ static void determineLevelFileInfo_Filename(struct LevelFileInfo *lfi) /* special case: level number is negative => check for level template file */ if (nr < 0) { -#if 1 /* global variable "leveldir_current" must be modified in the loop below */ LevelDirTree *leveldir_current_last = leveldir_current; @@ -2279,13 +2040,6 @@ static void determineLevelFileInfo_Filename(struct LevelFileInfo *lfi) /* restore global variable "leveldir_current" modified in above loop */ leveldir_current = leveldir_current_last; -#else - - setLevelFileInfo_FormatLevelFilename(lfi, LEVEL_FILE_TYPE_RND, - "template.%s", LEVELFILE_EXTENSION); - -#endif - /* no fallback if template file not existing */ return; } @@ -2449,8 +2203,6 @@ int getMappedElementByVersion(int element, int game_version) return element; } -#if 1 - static int LoadLevel_VERS(File *file, int chunk_size, struct LevelInfo *level) { level->file_version = getFileVersion(file); @@ -2629,20 +2381,13 @@ static int LoadLevel_CNT2(File *file, int chunk_size, struct LevelInfo *level) int i, x, y; int element; int num_contents; -#if 0 - int content_xsize, content_ysize; -#endif int content_array[MAX_ELEMENT_CONTENTS][3][3]; element = getMappedElement(getFile16BitBE(file)); num_contents = getFile8Bit(file); -#if 1 + getFile8Bit(file); /* content x size (unused) */ getFile8Bit(file); /* content y size (unused) */ -#else - content_xsize = getFile8Bit(file); - content_ysize = getFile8Bit(file); -#endif ReadUnusedBytesFromFile(file, LEVEL_CHUNK_CNT2_UNUSED); @@ -3365,4581 +3110,2132 @@ static int LoadLevel_GRPX(File *file, int chunk_size, struct LevelInfo *level) return real_chunk_size; } -#else - -static int LoadLevel_VERS(FILE *file, int chunk_size, struct LevelInfo *level) +static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, + struct LevelFileInfo *level_file_info, + boolean level_info_only) { - level->file_version = getFileVersion(file); - level->game_version = getFileVersion(file); + char *filename = level_file_info->filename; + char cookie[MAX_LINE_LEN]; + char chunk_name[CHUNK_ID_LEN + 1]; + int chunk_size; + File *file; - return chunk_size; -} + if (!(file = openFile(filename, MODE_READ))) + { + level->no_valid_file = TRUE; -static int LoadLevel_DATE(FILE *file, int chunk_size, struct LevelInfo *level) -{ - level->creation_date.year = getFile16BitBE(file); - level->creation_date.month = getFile8Bit(file); - level->creation_date.day = getFile8Bit(file); + if (!level_info_only) + Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); - level->creation_date.src = DATE_SRC_LEVELFILE; + return; + } - return chunk_size; -} + getFileChunkBE(file, chunk_name, NULL); + if (strEqual(chunk_name, "RND1")) + { + getFile32BitBE(file); /* not used */ -static int LoadLevel_HEAD(FILE *file, int chunk_size, struct LevelInfo *level) -{ - int initial_player_stepsize; - int initial_player_gravity; - int i, x, y; + getFileChunkBE(file, chunk_name, NULL); + if (!strEqual(chunk_name, "CAVE")) + { + level->no_valid_file = TRUE; - level->fieldx = getFile8Bit(file); - level->fieldy = getFile8Bit(file); + Error(ERR_WARN, "unknown format of level file '%s'", filename); - level->time = getFile16BitBE(file); - level->gems_needed = getFile16BitBE(file); + closeFile(file); - for (i = 0; i < MAX_LEVEL_NAME_LEN; i++) - level->name[i] = getFile8Bit(file); - level->name[MAX_LEVEL_NAME_LEN] = 0; + return; + } + } + else /* check for pre-2.0 file format with cookie string */ + { + strcpy(cookie, chunk_name); + if (getStringFromFile(file, &cookie[4], MAX_LINE_LEN - 4) == NULL) + cookie[4] = '\0'; + if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n') + cookie[strlen(cookie) - 1] = '\0'; - for (i = 0; i < LEVEL_SCORE_ELEMENTS; i++) - level->score[i] = getFile8Bit(file); + if (!checkCookieString(cookie, LEVEL_COOKIE_TMPL)) + { + level->no_valid_file = TRUE; - level->num_yamyam_contents = STD_ELEMENT_CONTENTS; - for (i = 0; i < STD_ELEMENT_CONTENTS; i++) - for (y = 0; y < 3; y++) - for (x = 0; x < 3; x++) - level->yamyam_content[i].e[x][y] = getMappedElement(getFile8Bit(file)); + Error(ERR_WARN, "unknown format of level file '%s'", filename); - level->amoeba_speed = getFile8Bit(file); - level->time_magic_wall = getFile8Bit(file); - level->time_wheel = getFile8Bit(file); - level->amoeba_content = getMappedElement(getFile8Bit(file)); + closeFile(file); - initial_player_stepsize = (getFile8Bit(file) == 1 ? STEPSIZE_FAST : - STEPSIZE_NORMAL); + return; + } - for (i = 0; i < MAX_PLAYERS; i++) - level->initial_player_stepsize[i] = initial_player_stepsize; + if ((level->file_version = getFileVersionFromCookieString(cookie)) == -1) + { + level->no_valid_file = TRUE; - initial_player_gravity = (getFile8Bit(file) == 1 ? TRUE : FALSE); + Error(ERR_WARN, "unsupported version of level file '%s'", filename); - for (i = 0; i < MAX_PLAYERS; i++) - level->initial_player_gravity[i] = initial_player_gravity; + closeFile(file); - level->encoding_16bit_field = (getFile8Bit(file) == 1 ? TRUE : FALSE); - level->em_slippery_gems = (getFile8Bit(file) == 1 ? TRUE : FALSE); + return; + } - level->use_custom_template = (getFile8Bit(file) == 1 ? TRUE : FALSE); + /* pre-2.0 level files have no game version, so use file version here */ + level->game_version = level->file_version; + } - level->block_last_field = (getFile8Bit(file) == 1 ? TRUE : FALSE); - level->sp_block_last_field = (getFile8Bit(file) == 1 ? TRUE : FALSE); - level->can_move_into_acid_bits = getFile32BitBE(file); - level->dont_collide_with_bits = getFile8Bit(file); + if (level->file_version < FILE_VERSION_1_2) + { + /* level files from versions before 1.2.0 without chunk structure */ + LoadLevel_HEAD(file, LEVEL_CHUNK_HEAD_SIZE, level); + LoadLevel_BODY(file, level->fieldx * level->fieldy, level); + } + else + { + static struct + { + char *name; + int size; + int (*loader)(File *, int, struct LevelInfo *); + } + chunk_info[] = + { + { "VERS", LEVEL_CHUNK_VERS_SIZE, LoadLevel_VERS }, + { "DATE", LEVEL_CHUNK_DATE_SIZE, LoadLevel_DATE }, + { "HEAD", LEVEL_CHUNK_HEAD_SIZE, LoadLevel_HEAD }, + { "NAME", LEVEL_CHUNK_NAME_SIZE, LoadLevel_NAME }, + { "AUTH", LEVEL_CHUNK_AUTH_SIZE, LoadLevel_AUTH }, + { "INFO", -1, LoadLevel_INFO }, + { "BODY", -1, LoadLevel_BODY }, + { "CONT", -1, LoadLevel_CONT }, + { "CNT2", LEVEL_CHUNK_CNT2_SIZE, LoadLevel_CNT2 }, + { "CNT3", -1, LoadLevel_CNT3 }, + { "CUS1", -1, LoadLevel_CUS1 }, + { "CUS2", -1, LoadLevel_CUS2 }, + { "CUS3", -1, LoadLevel_CUS3 }, + { "CUS4", -1, LoadLevel_CUS4 }, + { "GRP1", -1, LoadLevel_GRP1 }, + { "CONF", -1, LoadLevel_CONF }, + { "ELEM", -1, LoadLevel_ELEM }, + { "NOTE", -1, LoadLevel_NOTE }, + { "CUSX", -1, LoadLevel_CUSX }, + { "GRPX", -1, LoadLevel_GRPX }, - level->use_spring_bug = (getFile8Bit(file) == 1 ? TRUE : FALSE); - level->use_step_counter = (getFile8Bit(file) == 1 ? TRUE : FALSE); + { NULL, 0, NULL } + }; - level->instant_relocation = (getFile8Bit(file) == 1 ? TRUE : FALSE); - level->can_pass_to_walkable = (getFile8Bit(file) == 1 ? TRUE : FALSE); - level->grow_into_diggable = (getFile8Bit(file) == 1 ? TRUE : FALSE); + while (getFileChunkBE(file, chunk_name, &chunk_size)) + { + int i = 0; - level->game_engine_type = getFile8Bit(file); + while (chunk_info[i].name != NULL && + !strEqual(chunk_name, chunk_info[i].name)) + i++; - ReadUnusedBytesFromFile(file, LEVEL_CHUNK_HEAD_UNUSED); + if (chunk_info[i].name == NULL) + { + Error(ERR_WARN, "unknown chunk '%s' in level file '%s'", + chunk_name, filename); + ReadUnusedBytesFromFile(file, chunk_size); + } + else if (chunk_info[i].size != -1 && + chunk_info[i].size != chunk_size) + { + Error(ERR_WARN, "wrong size (%d) of chunk '%s' in level file '%s'", + chunk_size, chunk_name, filename); + ReadUnusedBytesFromFile(file, chunk_size); + } + else + { + /* call function to load this level chunk */ + int chunk_size_expected = + (chunk_info[i].loader)(file, chunk_size, level); - return chunk_size; -} + /* the size of some chunks cannot be checked before reading other + chunks first (like "HEAD" and "BODY") that contain some header + information, so check them here */ + if (chunk_size_expected != chunk_size) + { + Error(ERR_WARN, "wrong size (%d) of chunk '%s' in level file '%s'", + chunk_size, chunk_name, filename); + } + } + } + } -static int LoadLevel_NAME(FILE *file, int chunk_size, struct LevelInfo *level) -{ - int i; + closeFile(file); +} - for (i = 0; i < MAX_LEVEL_NAME_LEN; i++) - level->name[i] = getFile8Bit(file); - level->name[MAX_LEVEL_NAME_LEN] = 0; - return chunk_size; -} +/* ------------------------------------------------------------------------- */ +/* functions for loading EM level */ +/* ------------------------------------------------------------------------- */ -static int LoadLevel_AUTH(FILE *file, int chunk_size, struct LevelInfo *level) +void CopyNativeLevel_RND_to_EM(struct LevelInfo *level) { - int i; + static int ball_xy[8][2] = + { + { 0, 0 }, + { 1, 0 }, + { 2, 0 }, + { 0, 1 }, + { 2, 1 }, + { 0, 2 }, + { 1, 2 }, + { 2, 2 }, + }; + struct LevelInfo_EM *level_em = level->native_em_level; + struct LEVEL *lev = level_em->lev; + struct PLAYER **ply = level_em->ply; + int i, j, x, y; - for (i = 0; i < MAX_LEVEL_AUTHOR_LEN; i++) - level->author[i] = getFile8Bit(file); - level->author[MAX_LEVEL_AUTHOR_LEN] = 0; + lev->width = MIN(level->fieldx, EM_MAX_CAVE_WIDTH); + lev->height = MIN(level->fieldy, EM_MAX_CAVE_HEIGHT); - return chunk_size; -} + lev->time_seconds = level->time; + lev->required_initial = level->gems_needed; -static int LoadLevel_BODY(FILE *file, int chunk_size, struct LevelInfo *level) -{ - int x, y; - int chunk_size_expected = level->fieldx * level->fieldy; + lev->emerald_score = level->score[SC_EMERALD]; + lev->diamond_score = level->score[SC_DIAMOND]; + lev->alien_score = level->score[SC_ROBOT]; + lev->tank_score = level->score[SC_SPACESHIP]; + lev->bug_score = level->score[SC_BUG]; + lev->eater_score = level->score[SC_YAMYAM]; + lev->nut_score = level->score[SC_NUT]; + lev->dynamite_score = level->score[SC_DYNAMITE]; + lev->key_score = level->score[SC_KEY]; + lev->exit_score = level->score[SC_TIME_BONUS]; - /* Note: "chunk_size" was wrong before version 2.0 when elements are - stored with 16-bit encoding (and should be twice as big then). - Even worse, playfield data was stored 16-bit when only yamyam content - contained 16-bit elements and vice versa. */ + for (i = 0; i < MAX_ELEMENT_CONTENTS; i++) + for (y = 0; y < 3; y++) + for (x = 0; x < 3; x++) + lev->eater_array[i][y * 3 + x] = + map_element_RND_to_EM(level->yamyam_content[i].e[x][y]); - if (level->encoding_16bit_field && level->file_version >= FILE_VERSION_2_0) - chunk_size_expected *= 2; + lev->amoeba_time = level->amoeba_speed; + lev->wonderwall_time_initial = level->time_magic_wall; + lev->wheel_time = level->time_wheel; - if (chunk_size_expected != chunk_size) - { - ReadUnusedBytesFromFile(file, chunk_size); - return chunk_size_expected; - } + lev->android_move_time = level->android_move_time; + lev->android_clone_time = level->android_clone_time; + lev->ball_random = level->ball_random; + lev->ball_state_initial = level->ball_state_initial; + lev->ball_time = level->ball_time; + lev->num_ball_arrays = level->num_ball_contents; - for (y = 0; y < level->fieldy; y++) - for (x = 0; x < level->fieldx; x++) - level->field[x][y] = - getMappedElement(level->encoding_16bit_field ? getFile16BitBE(file) : - getFile8Bit(file)); - return chunk_size; -} + lev->lenses_score = level->lenses_score; + lev->magnify_score = level->magnify_score; + lev->slurp_score = level->slurp_score; -static int LoadLevel_CONT(FILE *file, int chunk_size, struct LevelInfo *level) -{ - int i, x, y; - int header_size = 4; - int content_size = MAX_ELEMENT_CONTENTS * 3 * 3; - int chunk_size_expected = header_size + content_size; - - /* Note: "chunk_size" was wrong before version 2.0 when elements are - stored with 16-bit encoding (and should be twice as big then). - Even worse, playfield data was stored 16-bit when only yamyam content - contained 16-bit elements and vice versa. */ - - if (level->encoding_16bit_field && level->file_version >= FILE_VERSION_2_0) - chunk_size_expected += content_size; - - if (chunk_size_expected != chunk_size) - { - ReadUnusedBytesFromFile(file, chunk_size); - return chunk_size_expected; - } - - getFile8Bit(file); - level->num_yamyam_contents = getFile8Bit(file); - getFile8Bit(file); - getFile8Bit(file); - - /* correct invalid number of content fields -- should never happen */ - if (level->num_yamyam_contents < 1 || - level->num_yamyam_contents > MAX_ELEMENT_CONTENTS) - level->num_yamyam_contents = STD_ELEMENT_CONTENTS; - - for (i = 0; i < MAX_ELEMENT_CONTENTS; i++) - for (y = 0; y < 3; y++) - for (x = 0; x < 3; x++) - level->yamyam_content[i].e[x][y] = - getMappedElement(level->encoding_16bit_field ? - getFile16BitBE(file) : getFile8Bit(file)); - return chunk_size; -} - -static int LoadLevel_CNT2(FILE *file, int chunk_size, struct LevelInfo *level) -{ - int i, x, y; - int element; - int num_contents; -#if 0 - int content_xsize, content_ysize; -#endif - int content_array[MAX_ELEMENT_CONTENTS][3][3]; - - element = getMappedElement(getFile16BitBE(file)); - num_contents = getFile8Bit(file); -#if 1 - getFile8Bit(file); /* content x size (unused) */ - getFile8Bit(file); /* content y size (unused) */ -#else - content_xsize = getFile8Bit(file); - content_ysize = getFile8Bit(file); -#endif + lev->lenses_time = level->lenses_time; + lev->magnify_time = level->magnify_time; - ReadUnusedBytesFromFile(file, LEVEL_CHUNK_CNT2_UNUSED); + lev->wind_direction_initial = + map_direction_RND_to_EM(level->wind_direction_initial); + lev->wind_cnt_initial = (level->wind_direction_initial != MV_NONE ? + lev->wind_time : 0); for (i = 0; i < MAX_ELEMENT_CONTENTS; i++) - for (y = 0; y < 3; y++) - for (x = 0; x < 3; x++) - content_array[i][x][y] = getMappedElement(getFile16BitBE(file)); + for (j = 0; j < 8; j++) + lev->ball_array[i][j] = + map_element_RND_to_EM(level-> + ball_content[i].e[ball_xy[j][0]][ball_xy[j][1]]); - /* correct invalid number of content fields -- should never happen */ - if (num_contents < 1 || num_contents > MAX_ELEMENT_CONTENTS) - num_contents = STD_ELEMENT_CONTENTS; + map_android_clone_elements_RND_to_EM(level); - if (element == EL_YAMYAM) - { - level->num_yamyam_contents = num_contents; + /* first fill the complete playfield with the default border element */ + for (y = 0; y < EM_MAX_CAVE_HEIGHT; y++) + for (x = 0; x < EM_MAX_CAVE_WIDTH; x++) + level_em->cave[x][y] = ZBORDER; - for (i = 0; i < num_contents; i++) - for (y = 0; y < 3; y++) - for (x = 0; x < 3; x++) - level->yamyam_content[i].e[x][y] = content_array[i][x][y]; - } - else if (element == EL_BD_AMOEBA) - { - level->amoeba_content = content_array[0][0][0]; - } - else + if (BorderElement == EL_STEELWALL) { - Error(ERR_WARN, "cannot load content for element '%d'", element); + for (y = 0; y < lev->height + 2; y++) + for (x = 0; x < lev->width + 2; x++) + level_em->cave[x + 1][y + 1] = map_element_RND_to_EM(EL_STEELWALL); } - return chunk_size; -} - -static int LoadLevel_CNT3(FILE *file, int chunk_size, struct LevelInfo *level) -{ - int i; - int element; - int envelope_nr; - int envelope_len; - int chunk_size_expected; - - element = getMappedElement(getFile16BitBE(file)); - if (!IS_ENVELOPE(element)) - element = EL_ENVELOPE_1; - - envelope_nr = element - EL_ENVELOPE_1; - - envelope_len = getFile16BitBE(file); - - level->envelope[envelope_nr].xsize = getFile8Bit(file); - level->envelope[envelope_nr].ysize = getFile8Bit(file); - - ReadUnusedBytesFromFile(file, LEVEL_CHUNK_CNT3_UNUSED); - - chunk_size_expected = LEVEL_CHUNK_CNT3_SIZE(envelope_len); - if (chunk_size_expected != chunk_size) + /* then copy the real level contents from level file into the playfield */ + for (y = 0; y < lev->height; y++) for (x = 0; x < lev->width; x++) { - ReadUnusedBytesFromFile(file, chunk_size - LEVEL_CHUNK_CNT3_HEADER); - return chunk_size_expected; - } - - for (i = 0; i < envelope_len; i++) - level->envelope[envelope_nr].text[i] = getFile8Bit(file); - - return chunk_size; -} + int new_element = map_element_RND_to_EM(level->field[x][y]); + int offset = (BorderElement == EL_STEELWALL ? 1 : 0); + int xx = x + 1 + offset; + int yy = y + 1 + offset; -static int LoadLevel_CUS1(FILE *file, int chunk_size, struct LevelInfo *level) -{ - int num_changed_custom_elements = getFile16BitBE(file); - int chunk_size_expected = 2 + num_changed_custom_elements * 6; - int i; + if (level->field[x][y] == EL_AMOEBA_DEAD) + new_element = map_element_RND_to_EM(EL_AMOEBA_WET); - if (chunk_size_expected != chunk_size) - { - ReadUnusedBytesFromFile(file, chunk_size - 2); - return chunk_size_expected; + level_em->cave[xx][yy] = new_element; } - for (i = 0; i < num_changed_custom_elements; i++) + for (i = 0; i < MAX_PLAYERS; i++) { - int element = getMappedElement(getFile16BitBE(file)); - int properties = getFile32BitBE(file); - - if (IS_CUSTOM_ELEMENT(element)) - element_info[element].properties[EP_BITFIELD_BASE_NR] = properties; - else - Error(ERR_WARN, "invalid custom element number %d", element); - - /* older game versions that wrote level files with CUS1 chunks used - different default push delay values (not yet stored in level file) */ - element_info[element].push_delay_fixed = 2; - element_info[element].push_delay_random = 8; + ply[i]->x_initial = 0; + ply[i]->y_initial = 0; } - return chunk_size; -} + /* initialize player positions and delete players from the playfield */ + for (y = 0; y < lev->height; y++) for (x = 0; x < lev->width; x++) + { + if (ELEM_IS_PLAYER(level->field[x][y])) + { + int player_nr = GET_PLAYER_NR(level->field[x][y]); + int offset = (BorderElement == EL_STEELWALL ? 1 : 0); + int xx = x + 1 + offset; + int yy = y + 1 + offset; -static int LoadLevel_CUS2(FILE *file, int chunk_size, struct LevelInfo *level) -{ - int num_changed_custom_elements = getFile16BitBE(file); - int chunk_size_expected = 2 + num_changed_custom_elements * 4; - int i; + ply[player_nr]->x_initial = xx; + ply[player_nr]->y_initial = yy; - if (chunk_size_expected != chunk_size) - { - ReadUnusedBytesFromFile(file, chunk_size - 2); - return chunk_size_expected; + level_em->cave[xx][yy] = map_element_RND_to_EM(EL_EMPTY); + } } - for (i = 0; i < num_changed_custom_elements; i++) + if (BorderElement == EL_STEELWALL) { - int element = getMappedElement(getFile16BitBE(file)); - int custom_target_element = getMappedElement(getFile16BitBE(file)); - - if (IS_CUSTOM_ELEMENT(element)) - element_info[element].change->target_element = custom_target_element; - else - Error(ERR_WARN, "invalid custom element number %d", element); + lev->width += 2; + lev->height += 2; } - - return chunk_size; } -static int LoadLevel_CUS3(FILE *file, int chunk_size, struct LevelInfo *level) +void CopyNativeLevel_EM_to_RND(struct LevelInfo *level) { - int num_changed_custom_elements = getFile16BitBE(file); - int chunk_size_expected = LEVEL_CHUNK_CUS3_SIZE(num_changed_custom_elements); + static int ball_xy[8][2] = + { + { 0, 0 }, + { 1, 0 }, + { 2, 0 }, + { 0, 1 }, + { 2, 1 }, + { 0, 2 }, + { 1, 2 }, + { 2, 2 }, + }; + struct LevelInfo_EM *level_em = level->native_em_level; + struct LEVEL *lev = level_em->lev; + struct PLAYER **ply = level_em->ply; int i, j, x, y; - if (chunk_size_expected != chunk_size) - { - ReadUnusedBytesFromFile(file, chunk_size - 2); - return chunk_size_expected; - } + level->fieldx = MIN(lev->width, MAX_LEV_FIELDX); + level->fieldy = MIN(lev->height, MAX_LEV_FIELDY); - for (i = 0; i < num_changed_custom_elements; i++) - { - int element = getMappedElement(getFile16BitBE(file)); - struct ElementInfo *ei = &element_info[element]; - unsigned int event_bits; + level->time = lev->time_seconds; + level->gems_needed = lev->required_initial; - if (!IS_CUSTOM_ELEMENT(element)) - { - Error(ERR_WARN, "invalid custom element number %d", element); + sprintf(level->name, "Level %d", level->file_info.nr); - element = EL_INTERNAL_DUMMY; - } + level->score[SC_EMERALD] = lev->emerald_score; + level->score[SC_DIAMOND] = lev->diamond_score; + level->score[SC_ROBOT] = lev->alien_score; + level->score[SC_SPACESHIP] = lev->tank_score; + level->score[SC_BUG] = lev->bug_score; + level->score[SC_YAMYAM] = lev->eater_score; + level->score[SC_NUT] = lev->nut_score; + level->score[SC_DYNAMITE] = lev->dynamite_score; + level->score[SC_KEY] = lev->key_score; + level->score[SC_TIME_BONUS] = lev->exit_score; - for (j = 0; j < MAX_ELEMENT_NAME_LEN; j++) - ei->description[j] = getFile8Bit(file); - ei->description[MAX_ELEMENT_NAME_LEN] = 0; + level->num_yamyam_contents = MAX_ELEMENT_CONTENTS; - ei->properties[EP_BITFIELD_BASE_NR] = getFile32BitBE(file); + for (i = 0; i < level->num_yamyam_contents; i++) + for (y = 0; y < 3; y++) + for (x = 0; x < 3; x++) + level->yamyam_content[i].e[x][y] = + map_element_EM_to_RND(lev->eater_array[i][y * 3 + x]); - /* some free bytes for future properties and padding */ - ReadUnusedBytesFromFile(file, 7); - - ei->use_gfx_element = getFile8Bit(file); - ei->gfx_element_initial = getMappedElement(getFile16BitBE(file)); - - ei->collect_score_initial = getFile8Bit(file); - ei->collect_count_initial = getFile8Bit(file); - - ei->push_delay_fixed = getFile16BitBE(file); - ei->push_delay_random = getFile16BitBE(file); - ei->move_delay_fixed = getFile16BitBE(file); - ei->move_delay_random = getFile16BitBE(file); - - ei->move_pattern = getFile16BitBE(file); - ei->move_direction_initial = getFile8Bit(file); - ei->move_stepsize = getFile8Bit(file); - - for (y = 0; y < 3; y++) - for (x = 0; x < 3; x++) - ei->content.e[x][y] = getMappedElement(getFile16BitBE(file)); - - event_bits = getFile32BitBE(file); - for (j = 0; j < NUM_CHANGE_EVENTS; j++) - if (event_bits & (1 << j)) - ei->change->has_event[j] = TRUE; - - ei->change->target_element = getMappedElement(getFile16BitBE(file)); - - ei->change->delay_fixed = getFile16BitBE(file); - ei->change->delay_random = getFile16BitBE(file); - ei->change->delay_frames = getFile16BitBE(file); - - ei->change->initial_trigger_element= getMappedElement(getFile16BitBE(file)); - - ei->change->explode = getFile8Bit(file); - ei->change->use_target_content = getFile8Bit(file); - ei->change->only_if_complete = getFile8Bit(file); - ei->change->use_random_replace = getFile8Bit(file); - - ei->change->random_percentage = getFile8Bit(file); - ei->change->replace_when = getFile8Bit(file); - - for (y = 0; y < 3; y++) - for (x = 0; x < 3; x++) - ei->change->target_content.e[x][y] = - getMappedElement(getFile16BitBE(file)); - - ei->slippery_type = getFile8Bit(file); - - /* some free bytes for future properties and padding */ - ReadUnusedBytesFromFile(file, LEVEL_CPART_CUS3_UNUSED); - - /* mark that this custom element has been modified */ - ei->modified_settings = TRUE; - } - - return chunk_size; -} - -static int LoadLevel_CUS4(FILE *file, int chunk_size, struct LevelInfo *level) -{ - struct ElementInfo *ei; - int chunk_size_expected; - int element; - int i, j, x, y; - - /* ---------- custom element base property values (96 bytes) ------------- */ - - element = getMappedElement(getFile16BitBE(file)); - - if (!IS_CUSTOM_ELEMENT(element)) - { - Error(ERR_WARN, "invalid custom element number %d", element); - - ReadUnusedBytesFromFile(file, chunk_size - 2); - return chunk_size; - } - - ei = &element_info[element]; - - for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++) - ei->description[i] = getFile8Bit(file); - ei->description[MAX_ELEMENT_NAME_LEN] = 0; - - ei->properties[EP_BITFIELD_BASE_NR] = getFile32BitBE(file); - - ReadUnusedBytesFromFile(file, 4); /* reserved for more base properties */ - - ei->num_change_pages = getFile8Bit(file); - - chunk_size_expected = LEVEL_CHUNK_CUS4_SIZE(ei->num_change_pages); - if (chunk_size_expected != chunk_size) - { - ReadUnusedBytesFromFile(file, chunk_size - 43); - return chunk_size_expected; - } - - ei->ce_value_fixed_initial = getFile16BitBE(file); - ei->ce_value_random_initial = getFile16BitBE(file); - ei->use_last_ce_value = getFile8Bit(file); - - ei->use_gfx_element = getFile8Bit(file); - ei->gfx_element_initial = getMappedElement(getFile16BitBE(file)); - - ei->collect_score_initial = getFile8Bit(file); - ei->collect_count_initial = getFile8Bit(file); - - ei->drop_delay_fixed = getFile8Bit(file); - ei->push_delay_fixed = getFile8Bit(file); - ei->drop_delay_random = getFile8Bit(file); - ei->push_delay_random = getFile8Bit(file); - ei->move_delay_fixed = getFile16BitBE(file); - ei->move_delay_random = getFile16BitBE(file); - - /* bits 0 - 15 of "move_pattern" ... */ - ei->move_pattern = getFile16BitBE(file); - ei->move_direction_initial = getFile8Bit(file); - ei->move_stepsize = getFile8Bit(file); - - ei->slippery_type = getFile8Bit(file); - - for (y = 0; y < 3; y++) - for (x = 0; x < 3; x++) - ei->content.e[x][y] = getMappedElement(getFile16BitBE(file)); - - ei->move_enter_element = getMappedElement(getFile16BitBE(file)); - ei->move_leave_element = getMappedElement(getFile16BitBE(file)); - ei->move_leave_type = getFile8Bit(file); - - /* ... bits 16 - 31 of "move_pattern" (not nice, but downward compatible) */ - ei->move_pattern |= (getFile16BitBE(file) << 16); - - ei->access_direction = getFile8Bit(file); - - ei->explosion_delay = getFile8Bit(file); - ei->ignition_delay = getFile8Bit(file); - ei->explosion_type = getFile8Bit(file); - - /* some free bytes for future custom property values and padding */ - ReadUnusedBytesFromFile(file, 1); - - /* ---------- change page property values (48 bytes) --------------------- */ - - setElementChangePages(ei, ei->num_change_pages); - - for (i = 0; i < ei->num_change_pages; i++) - { - struct ElementChangeInfo *change = &ei->change_page[i]; - unsigned int event_bits; - - /* always start with reliable default values */ - setElementChangeInfoToDefaults(change); - - /* bits 0 - 31 of "has_event[]" ... */ - event_bits = getFile32BitBE(file); - for (j = 0; j < MIN(NUM_CHANGE_EVENTS, 32); j++) - if (event_bits & (1 << j)) - change->has_event[j] = TRUE; - - change->target_element = getMappedElement(getFile16BitBE(file)); - - change->delay_fixed = getFile16BitBE(file); - change->delay_random = getFile16BitBE(file); - change->delay_frames = getFile16BitBE(file); - - change->initial_trigger_element = getMappedElement(getFile16BitBE(file)); - - change->explode = getFile8Bit(file); - change->use_target_content = getFile8Bit(file); - change->only_if_complete = getFile8Bit(file); - change->use_random_replace = getFile8Bit(file); - - change->random_percentage = getFile8Bit(file); - change->replace_when = getFile8Bit(file); - - for (y = 0; y < 3; y++) - for (x = 0; x < 3; x++) - change->target_content.e[x][y]= getMappedElement(getFile16BitBE(file)); - - change->can_change = getFile8Bit(file); - - change->trigger_side = getFile8Bit(file); - - change->trigger_player = getFile8Bit(file); - change->trigger_page = getFile8Bit(file); - - change->trigger_page = (change->trigger_page == CH_PAGE_ANY_FILE ? - CH_PAGE_ANY : (1 << change->trigger_page)); - - change->has_action = getFile8Bit(file); - change->action_type = getFile8Bit(file); - change->action_mode = getFile8Bit(file); - change->action_arg = getFile16BitBE(file); - - /* ... bits 32 - 39 of "has_event[]" (not nice, but downward compatible) */ - event_bits = getFile8Bit(file); - for (j = 32; j < NUM_CHANGE_EVENTS; j++) - if (event_bits & (1 << (j - 32))) - change->has_event[j] = TRUE; - } - - /* mark this custom element as modified */ - ei->modified_settings = TRUE; - - return chunk_size; -} - -static int LoadLevel_GRP1(FILE *file, int chunk_size, struct LevelInfo *level) -{ - struct ElementInfo *ei; - struct ElementGroupInfo *group; - int element; - int i; - - element = getMappedElement(getFile16BitBE(file)); - - if (!IS_GROUP_ELEMENT(element)) - { - Error(ERR_WARN, "invalid group element number %d", element); - - ReadUnusedBytesFromFile(file, chunk_size - 2); - return chunk_size; - } - - ei = &element_info[element]; - - for (i = 0; i < MAX_ELEMENT_NAME_LEN; i++) - ei->description[i] = getFile8Bit(file); - ei->description[MAX_ELEMENT_NAME_LEN] = 0; - - group = element_info[element].group; - - group->num_elements = getFile8Bit(file); - - ei->use_gfx_element = getFile8Bit(file); - ei->gfx_element_initial = getMappedElement(getFile16BitBE(file)); - - group->choice_mode = getFile8Bit(file); - - /* some free bytes for future values and padding */ - ReadUnusedBytesFromFile(file, 3); - - for (i = 0; i < MAX_ELEMENTS_IN_GROUP; i++) - group->element[i] = getMappedElement(getFile16BitBE(file)); - - /* mark this group element as modified */ - element_info[element].modified_settings = TRUE; - - return chunk_size; -} - -static int LoadLevel_MicroChunk(FILE *file, struct LevelFileConfigInfo *conf, - int element, int real_element) -{ - int micro_chunk_size = 0; - int conf_type = getFile8Bit(file); - int byte_mask = conf_type & CONF_MASK_BYTES; - boolean element_found = FALSE; - int i; - - micro_chunk_size += 1; - - if (byte_mask == CONF_MASK_MULTI_BYTES) - { - int num_bytes = getFile16BitBE(file); - byte *buffer = checked_malloc(num_bytes); - - ReadBytesFromFile(file, buffer, num_bytes); - - for (i = 0; conf[i].data_type != -1; i++) - { - if (conf[i].element == element && - conf[i].conf_type == conf_type) - { - int data_type = conf[i].data_type; - int num_entities = num_bytes / CONF_ENTITY_NUM_BYTES(data_type); - int max_num_entities = conf[i].max_num_entities; - - if (num_entities > max_num_entities) - { - Error(ERR_WARN, - "truncating number of entities for element %d from %d to %d", - element, num_entities, max_num_entities); - - num_entities = max_num_entities; - } - - if (num_entities == 0 && (data_type == TYPE_ELEMENT_LIST || - data_type == TYPE_CONTENT_LIST)) - { - /* for element and content lists, zero entities are not allowed */ - Error(ERR_WARN, "found empty list of entities for element %d", - element); - - /* do not set "num_entities" here to prevent reading behind buffer */ - - *(int *)(conf[i].num_entities) = 1; /* at least one is required */ - } - else - { - *(int *)(conf[i].num_entities) = num_entities; - } - - element_found = TRUE; - - if (data_type == TYPE_STRING) - { - char *string = (char *)(conf[i].value); - int j; - - for (j = 0; j < max_num_entities; j++) - string[j] = (j < num_entities ? buffer[j] : '\0'); - } - else if (data_type == TYPE_ELEMENT_LIST) - { - int *element_array = (int *)(conf[i].value); - int j; - - for (j = 0; j < num_entities; j++) - element_array[j] = - getMappedElement(CONF_ELEMENTS_ELEMENT(buffer, j)); - } - else if (data_type == TYPE_CONTENT_LIST) - { - struct Content *content= (struct Content *)(conf[i].value); - int c, x, y; - - for (c = 0; c < num_entities; c++) - for (y = 0; y < 3; y++) - for (x = 0; x < 3; x++) - content[c].e[x][y] = - getMappedElement(CONF_CONTENTS_ELEMENT(buffer, c, x, y)); - } - else - element_found = FALSE; - - break; - } - } - - checked_free(buffer); - - micro_chunk_size += 2 + num_bytes; - } - else /* constant size configuration data (1, 2 or 4 bytes) */ - { - int value = (byte_mask == CONF_MASK_1_BYTE ? getFile8Bit (file) : - byte_mask == CONF_MASK_2_BYTE ? getFile16BitBE(file) : - byte_mask == CONF_MASK_4_BYTE ? getFile32BitBE(file) : 0); - - for (i = 0; conf[i].data_type != -1; i++) - { - if (conf[i].element == element && - conf[i].conf_type == conf_type) - { - int data_type = conf[i].data_type; - - if (data_type == TYPE_ELEMENT) - value = getMappedElement(value); - - if (data_type == TYPE_BOOLEAN) - *(boolean *)(conf[i].value) = value; - else - *(int *) (conf[i].value) = value; - - element_found = TRUE; - - break; - } - } - - micro_chunk_size += CONF_VALUE_NUM_BYTES(byte_mask); - } - - if (!element_found) - { - char *error_conf_chunk_bytes = - (byte_mask == CONF_MASK_1_BYTE ? "CONF_VALUE_8_BIT" : - byte_mask == CONF_MASK_2_BYTE ? "CONF_VALUE_16_BIT" : - byte_mask == CONF_MASK_4_BYTE ? "CONF_VALUE_32_BIT" :"CONF_VALUE_BYTES"); - int error_conf_chunk_token = conf_type & CONF_MASK_TOKEN; - int error_element = real_element; - - Error(ERR_WARN, "cannot load micro chunk '%s(%d)' value for element %d ['%s']", - error_conf_chunk_bytes, error_conf_chunk_token, - error_element, EL_NAME(error_element)); - } - - return micro_chunk_size; -} - -static int LoadLevel_INFO(FILE *file, int chunk_size, struct LevelInfo *level) -{ - int real_chunk_size = 0; - - li = *level; /* copy level data into temporary buffer */ - - while (!feof(file)) - { - real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_INFO, -1, -1); - - if (real_chunk_size >= chunk_size) - break; - } - - *level = li; /* copy temporary buffer back to level data */ - - return real_chunk_size; -} - -static int LoadLevel_CONF(FILE *file, int chunk_size, struct LevelInfo *level) -{ - int real_chunk_size = 0; - - li = *level; /* copy level data into temporary buffer */ - - while (!feof(file)) - { - int element = getMappedElement(getFile16BitBE(file)); - - real_chunk_size += 2; - real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_CONF, - element, element); - if (real_chunk_size >= chunk_size) - break; - } - - *level = li; /* copy temporary buffer back to level data */ - - return real_chunk_size; -} - -static int LoadLevel_ELEM(FILE *file, int chunk_size, struct LevelInfo *level) -{ - int real_chunk_size = 0; - - li = *level; /* copy level data into temporary buffer */ - - while (!feof(file)) - { - int element = getMappedElement(getFile16BitBE(file)); - - real_chunk_size += 2; - real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_ELEM, - element, element); - if (real_chunk_size >= chunk_size) - break; - } - - *level = li; /* copy temporary buffer back to level data */ - - return real_chunk_size; -} - -static int LoadLevel_NOTE(FILE *file, int chunk_size, struct LevelInfo *level) -{ - int element = getMappedElement(getFile16BitBE(file)); - int envelope_nr = element - EL_ENVELOPE_1; - int real_chunk_size = 2; - - while (!feof(file)) - { - real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_NOTE, - -1, element); - - if (real_chunk_size >= chunk_size) - break; - } - - level->envelope[envelope_nr] = xx_envelope; - - return real_chunk_size; -} - -static int LoadLevel_CUSX(FILE *file, int chunk_size, struct LevelInfo *level) -{ - int element = getMappedElement(getFile16BitBE(file)); - int real_chunk_size = 2; - struct ElementInfo *ei = &element_info[element]; - int i; - - xx_ei = *ei; /* copy element data into temporary buffer */ - - xx_ei.num_change_pages = -1; - - while (!feof(file)) - { - real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_CUSX_base, - -1, element); - if (xx_ei.num_change_pages != -1) - break; - - if (real_chunk_size >= chunk_size) - break; - } - - *ei = xx_ei; - - if (ei->num_change_pages == -1) - { - Error(ERR_WARN, "LoadLevel_CUSX(): missing 'num_change_pages' for '%s'", - EL_NAME(element)); - - ei->num_change_pages = 1; - - setElementChangePages(ei, 1); - setElementChangeInfoToDefaults(ei->change); - - return real_chunk_size; - } - - /* initialize number of change pages stored for this custom element */ - setElementChangePages(ei, ei->num_change_pages); - for (i = 0; i < ei->num_change_pages; i++) - setElementChangeInfoToDefaults(&ei->change_page[i]); - - /* start with reading properties for the first change page */ - xx_current_change_page = 0; - - while (!feof(file)) - { - struct ElementChangeInfo *change = &ei->change_page[xx_current_change_page]; - - xx_change = *change; /* copy change data into temporary buffer */ - - resetEventBits(); /* reset bits; change page might have changed */ - - real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_CUSX_change, - -1, element); - - *change = xx_change; - - setEventFlagsFromEventBits(change); - - if (real_chunk_size >= chunk_size) - break; - } - - return real_chunk_size; -} - -static int LoadLevel_GRPX(FILE *file, int chunk_size, struct LevelInfo *level) -{ - int element = getMappedElement(getFile16BitBE(file)); - int real_chunk_size = 2; - struct ElementInfo *ei = &element_info[element]; - struct ElementGroupInfo *group = ei->group; - - xx_ei = *ei; /* copy element data into temporary buffer */ - xx_group = *group; /* copy group data into temporary buffer */ - - while (!feof(file)) - { - real_chunk_size += LoadLevel_MicroChunk(file, chunk_config_GRPX, - -1, element); - - if (real_chunk_size >= chunk_size) - break; - } - - *ei = xx_ei; - *group = xx_group; - - return real_chunk_size; -} - -#endif - -#if 1 - -static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, - struct LevelFileInfo *level_file_info, - boolean level_info_only) -{ - char *filename = level_file_info->filename; - char cookie[MAX_LINE_LEN]; - char chunk_name[CHUNK_ID_LEN + 1]; - int chunk_size; - File *file; - - if (!(file = openFile(filename, MODE_READ))) - { - level->no_valid_file = TRUE; - -#if 1 - if (!level_info_only) - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); -#else - if (level != &level_template) - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); -#endif - - return; - } - - getFileChunkBE(file, chunk_name, NULL); - if (strEqual(chunk_name, "RND1")) - { - getFile32BitBE(file); /* not used */ - - getFileChunkBE(file, chunk_name, NULL); - if (!strEqual(chunk_name, "CAVE")) - { - level->no_valid_file = TRUE; - - Error(ERR_WARN, "unknown format of level file '%s'", filename); - - closeFile(file); - - return; - } - } - else /* check for pre-2.0 file format with cookie string */ - { - strcpy(cookie, chunk_name); - if (getStringFromFile(file, &cookie[4], MAX_LINE_LEN - 4) == NULL) - cookie[4] = '\0'; - if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n') - cookie[strlen(cookie) - 1] = '\0'; - - if (!checkCookieString(cookie, LEVEL_COOKIE_TMPL)) - { - level->no_valid_file = TRUE; - - Error(ERR_WARN, "unknown format of level file '%s'", filename); - - closeFile(file); - - return; - } - - if ((level->file_version = getFileVersionFromCookieString(cookie)) == -1) - { - level->no_valid_file = TRUE; - - Error(ERR_WARN, "unsupported version of level file '%s'", filename); - - closeFile(file); - - return; - } - - /* pre-2.0 level files have no game version, so use file version here */ - level->game_version = level->file_version; - } - - if (level->file_version < FILE_VERSION_1_2) - { - /* level files from versions before 1.2.0 without chunk structure */ - LoadLevel_HEAD(file, LEVEL_CHUNK_HEAD_SIZE, level); - LoadLevel_BODY(file, level->fieldx * level->fieldy, level); - } - else - { - static struct - { - char *name; - int size; - int (*loader)(File *, int, struct LevelInfo *); - } - chunk_info[] = - { - { "VERS", LEVEL_CHUNK_VERS_SIZE, LoadLevel_VERS }, - { "DATE", LEVEL_CHUNK_DATE_SIZE, LoadLevel_DATE }, - { "HEAD", LEVEL_CHUNK_HEAD_SIZE, LoadLevel_HEAD }, - { "NAME", LEVEL_CHUNK_NAME_SIZE, LoadLevel_NAME }, - { "AUTH", LEVEL_CHUNK_AUTH_SIZE, LoadLevel_AUTH }, - { "INFO", -1, LoadLevel_INFO }, - { "BODY", -1, LoadLevel_BODY }, - { "CONT", -1, LoadLevel_CONT }, - { "CNT2", LEVEL_CHUNK_CNT2_SIZE, LoadLevel_CNT2 }, - { "CNT3", -1, LoadLevel_CNT3 }, - { "CUS1", -1, LoadLevel_CUS1 }, - { "CUS2", -1, LoadLevel_CUS2 }, - { "CUS3", -1, LoadLevel_CUS3 }, - { "CUS4", -1, LoadLevel_CUS4 }, - { "GRP1", -1, LoadLevel_GRP1 }, - { "CONF", -1, LoadLevel_CONF }, - { "ELEM", -1, LoadLevel_ELEM }, - { "NOTE", -1, LoadLevel_NOTE }, - { "CUSX", -1, LoadLevel_CUSX }, - { "GRPX", -1, LoadLevel_GRPX }, - - { NULL, 0, NULL } - }; - - while (getFileChunkBE(file, chunk_name, &chunk_size)) - { - int i = 0; - - while (chunk_info[i].name != NULL && - !strEqual(chunk_name, chunk_info[i].name)) - i++; - - if (chunk_info[i].name == NULL) - { - Error(ERR_WARN, "unknown chunk '%s' in level file '%s'", - chunk_name, filename); - ReadUnusedBytesFromFile(file, chunk_size); - } - else if (chunk_info[i].size != -1 && - chunk_info[i].size != chunk_size) - { - Error(ERR_WARN, "wrong size (%d) of chunk '%s' in level file '%s'", - chunk_size, chunk_name, filename); - ReadUnusedBytesFromFile(file, chunk_size); - } - else - { - /* call function to load this level chunk */ - int chunk_size_expected = - (chunk_info[i].loader)(file, chunk_size, level); - - /* the size of some chunks cannot be checked before reading other - chunks first (like "HEAD" and "BODY") that contain some header - information, so check them here */ - if (chunk_size_expected != chunk_size) - { - Error(ERR_WARN, "wrong size (%d) of chunk '%s' in level file '%s'", - chunk_size, chunk_name, filename); - } - } - } - } - - closeFile(file); -} - -#else - -static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, - struct LevelFileInfo *level_file_info, - boolean level_info_only) -{ - char *filename = level_file_info->filename; - char cookie[MAX_LINE_LEN]; - char chunk_name[CHUNK_ID_LEN + 1]; - int chunk_size; - FILE *file; - - if (!(file = fopen(filename, MODE_READ))) - { - level->no_valid_file = TRUE; - -#if 1 - if (!level_info_only) - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); -#else - if (level != &level_template) - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); -#endif - - return; - } - - getFileChunkBE(file, chunk_name, NULL); - if (strEqual(chunk_name, "RND1")) - { - getFile32BitBE(file); /* not used */ - - getFileChunkBE(file, chunk_name, NULL); - if (!strEqual(chunk_name, "CAVE")) - { - level->no_valid_file = TRUE; - - Error(ERR_WARN, "unknown format of level file '%s'", filename); - fclose(file); - return; - } - } - else /* check for pre-2.0 file format with cookie string */ - { - strcpy(cookie, chunk_name); - if (fgets(&cookie[4], MAX_LINE_LEN - 4, file) == NULL) - cookie[4] = '\0'; - if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n') - cookie[strlen(cookie) - 1] = '\0'; - - if (!checkCookieString(cookie, LEVEL_COOKIE_TMPL)) - { - level->no_valid_file = TRUE; - - Error(ERR_WARN, "unknown format of level file '%s'", filename); - fclose(file); - return; - } - - if ((level->file_version = getFileVersionFromCookieString(cookie)) == -1) - { - level->no_valid_file = TRUE; - - Error(ERR_WARN, "unsupported version of level file '%s'", filename); - fclose(file); - return; - } - - /* pre-2.0 level files have no game version, so use file version here */ - level->game_version = level->file_version; - } - - if (level->file_version < FILE_VERSION_1_2) - { - /* level files from versions before 1.2.0 without chunk structure */ - LoadLevel_HEAD(file, LEVEL_CHUNK_HEAD_SIZE, level); - LoadLevel_BODY(file, level->fieldx * level->fieldy, level); - } - else - { - static struct - { - char *name; - int size; - int (*loader)(FILE *, int, struct LevelInfo *); - } - chunk_info[] = - { - { "VERS", LEVEL_CHUNK_VERS_SIZE, LoadLevel_VERS }, - { "DATE", LEVEL_CHUNK_DATE_SIZE, LoadLevel_DATE }, - { "HEAD", LEVEL_CHUNK_HEAD_SIZE, LoadLevel_HEAD }, - { "NAME", LEVEL_CHUNK_NAME_SIZE, LoadLevel_NAME }, - { "AUTH", LEVEL_CHUNK_AUTH_SIZE, LoadLevel_AUTH }, - { "INFO", -1, LoadLevel_INFO }, - { "BODY", -1, LoadLevel_BODY }, - { "CONT", -1, LoadLevel_CONT }, - { "CNT2", LEVEL_CHUNK_CNT2_SIZE, LoadLevel_CNT2 }, - { "CNT3", -1, LoadLevel_CNT3 }, - { "CUS1", -1, LoadLevel_CUS1 }, - { "CUS2", -1, LoadLevel_CUS2 }, - { "CUS3", -1, LoadLevel_CUS3 }, - { "CUS4", -1, LoadLevel_CUS4 }, - { "GRP1", -1, LoadLevel_GRP1 }, - { "CONF", -1, LoadLevel_CONF }, - { "ELEM", -1, LoadLevel_ELEM }, - { "NOTE", -1, LoadLevel_NOTE }, - { "CUSX", -1, LoadLevel_CUSX }, - { "GRPX", -1, LoadLevel_GRPX }, - - { NULL, 0, NULL } - }; - - while (getFileChunkBE(file, chunk_name, &chunk_size)) - { - int i = 0; - - while (chunk_info[i].name != NULL && - !strEqual(chunk_name, chunk_info[i].name)) - i++; - - if (chunk_info[i].name == NULL) - { - Error(ERR_WARN, "unknown chunk '%s' in level file '%s'", - chunk_name, filename); - ReadUnusedBytesFromFile(file, chunk_size); - } - else if (chunk_info[i].size != -1 && - chunk_info[i].size != chunk_size) - { - Error(ERR_WARN, "wrong size (%d) of chunk '%s' in level file '%s'", - chunk_size, chunk_name, filename); - ReadUnusedBytesFromFile(file, chunk_size); - } - else - { - /* call function to load this level chunk */ - int chunk_size_expected = - (chunk_info[i].loader)(file, chunk_size, level); - - /* the size of some chunks cannot be checked before reading other - chunks first (like "HEAD" and "BODY") that contain some header - information, so check them here */ - if (chunk_size_expected != chunk_size) - { - Error(ERR_WARN, "wrong size (%d) of chunk '%s' in level file '%s'", - chunk_size, chunk_name, filename); - } - } - } - } - - fclose(file); -} - -#endif - - -/* ------------------------------------------------------------------------- */ -/* functions for loading EM level */ -/* ------------------------------------------------------------------------- */ - -#if 0 - -static int map_em_element_yam(int element) -{ - switch (element) - { - case 0x00: return EL_EMPTY; - case 0x01: return EL_EMERALD; - case 0x02: return EL_DIAMOND; - case 0x03: return EL_ROCK; - case 0x04: return EL_ROBOT; - case 0x05: return EL_SPACESHIP_UP; - case 0x06: return EL_BOMB; - case 0x07: return EL_BUG_UP; - case 0x08: return EL_AMOEBA_DROP; - case 0x09: return EL_NUT; - case 0x0a: return EL_YAMYAM; - case 0x0b: return EL_QUICKSAND_FULL; - case 0x0c: return EL_SAND; - case 0x0d: return EL_WALL_SLIPPERY; - case 0x0e: return EL_STEELWALL; - case 0x0f: return EL_WALL; - case 0x10: return EL_EM_KEY_1; - case 0x11: return EL_EM_KEY_2; - case 0x12: return EL_EM_KEY_4; - case 0x13: return EL_EM_KEY_3; - case 0x14: return EL_MAGIC_WALL; - case 0x15: return EL_ROBOT_WHEEL; - case 0x16: return EL_DYNAMITE; - - case 0x17: return EL_EM_KEY_1; /* EMC */ - case 0x18: return EL_BUG_UP; /* EMC */ - case 0x1a: return EL_DIAMOND; /* EMC */ - case 0x1b: return EL_EMERALD; /* EMC */ - case 0x25: return EL_NUT; /* EMC */ - case 0x80: return EL_EMPTY; /* EMC */ - case 0x85: return EL_EM_KEY_1; /* EMC */ - case 0x86: return EL_EM_KEY_2; /* EMC */ - case 0x87: return EL_EM_KEY_4; /* EMC */ - case 0x88: return EL_EM_KEY_3; /* EMC */ - case 0x94: return EL_QUICKSAND_EMPTY; /* EMC */ - case 0x9a: return EL_AMOEBA_WET; /* EMC */ - case 0xaf: return EL_DYNAMITE; /* EMC */ - case 0xbd: return EL_SAND; /* EMC */ - - default: - Error(ERR_WARN, "invalid level element %d", element); - return EL_UNKNOWN; - } -} - -static int map_em_element_field(int element) -{ - if (element >= 0xc8 && element <= 0xe1) - return EL_CHAR_A + (element - 0xc8); - else if (element >= 0xe2 && element <= 0xeb) - return EL_CHAR_0 + (element - 0xe2); - - switch (element) - { - case 0x00: return EL_ROCK; - case 0x01: return EL_ROCK; /* EMC */ - case 0x02: return EL_DIAMOND; - case 0x03: return EL_DIAMOND; - case 0x04: return EL_ROBOT; - case 0x05: return EL_ROBOT; /* EMC */ - case 0x06: return EL_EMPTY_SPACE; /* EMC */ - case 0x07: return EL_EMPTY_SPACE; /* EMC */ - case 0x08: return EL_SPACESHIP_UP; - case 0x09: return EL_SPACESHIP_RIGHT; - case 0x0a: return EL_SPACESHIP_DOWN; - case 0x0b: return EL_SPACESHIP_LEFT; - case 0x0c: return EL_SPACESHIP_UP; - case 0x0d: return EL_SPACESHIP_RIGHT; - case 0x0e: return EL_SPACESHIP_DOWN; - case 0x0f: return EL_SPACESHIP_LEFT; - - case 0x10: return EL_BOMB; - case 0x11: return EL_BOMB; /* EMC */ - case 0x12: return EL_EMERALD; - case 0x13: return EL_EMERALD; - case 0x14: return EL_BUG_UP; - case 0x15: return EL_BUG_RIGHT; - case 0x16: return EL_BUG_DOWN; - case 0x17: return EL_BUG_LEFT; - case 0x18: return EL_BUG_UP; - case 0x19: return EL_BUG_RIGHT; - case 0x1a: return EL_BUG_DOWN; - case 0x1b: return EL_BUG_LEFT; - case 0x1c: return EL_AMOEBA_DROP; - case 0x1d: return EL_AMOEBA_DROP; /* EMC */ - case 0x1e: return EL_AMOEBA_DROP; /* EMC */ - case 0x1f: return EL_AMOEBA_DROP; /* EMC */ - - case 0x20: return EL_ROCK; - case 0x21: return EL_BOMB; /* EMC */ - case 0x22: return EL_DIAMOND; /* EMC */ - case 0x23: return EL_EMERALD; /* EMC */ - case 0x24: return EL_MAGIC_WALL; - case 0x25: return EL_NUT; - case 0x26: return EL_NUT; /* EMC */ - case 0x27: return EL_NUT; /* EMC */ - - /* looks like magic wheel, but is _always_ activated */ - case 0x28: return EL_ROBOT_WHEEL; /* EMC */ - - case 0x29: return EL_YAMYAM; /* up */ - case 0x2a: return EL_YAMYAM; /* down */ - case 0x2b: return EL_YAMYAM; /* left */ /* EMC */ - case 0x2c: return EL_YAMYAM; /* right */ /* EMC */ - case 0x2d: return EL_QUICKSAND_FULL; - case 0x2e: return EL_EMPTY_SPACE; /* EMC */ - case 0x2f: return EL_EMPTY_SPACE; /* EMC */ - - case 0x30: return EL_EMPTY_SPACE; /* EMC */ - case 0x31: return EL_SAND; /* EMC */ - case 0x32: return EL_SAND; /* EMC */ - case 0x33: return EL_SAND; /* EMC */ - case 0x34: return EL_QUICKSAND_FULL; /* EMC */ - case 0x35: return EL_QUICKSAND_FULL; /* EMC */ - case 0x36: return EL_QUICKSAND_FULL; /* EMC */ - case 0x37: return EL_SAND; /* EMC */ - case 0x38: return EL_ROCK; /* EMC */ - case 0x39: return EL_EXPANDABLE_WALL_HORIZONTAL; /* EMC */ - case 0x3a: return EL_EXPANDABLE_WALL_VERTICAL; /* EMC */ - case 0x3b: return EL_DYNAMITE_ACTIVE; /* 1 */ - case 0x3c: return EL_DYNAMITE_ACTIVE; /* 2 */ - case 0x3d: return EL_DYNAMITE_ACTIVE; /* 3 */ - case 0x3e: return EL_DYNAMITE_ACTIVE; /* 4 */ - case 0x3f: return EL_ACID_POOL_BOTTOM; - - case 0x40: return EL_EXIT_OPEN; /* 1 */ - case 0x41: return EL_EXIT_OPEN; /* 2 */ - case 0x42: return EL_EXIT_OPEN; /* 3 */ - case 0x43: return EL_BALLOON; /* EMC */ - case 0x44: return EL_UNKNOWN; /* EMC ("plant") */ - case 0x45: return EL_SPRING; /* EMC */ - case 0x46: return EL_SPRING; /* falling */ /* EMC */ - case 0x47: return EL_SPRING; /* left */ /* EMC */ - case 0x48: return EL_SPRING; /* right */ /* EMC */ - case 0x49: return EL_UNKNOWN; /* EMC ("ball 1") */ - case 0x4a: return EL_UNKNOWN; /* EMC ("ball 2") */ - case 0x4b: return EL_UNKNOWN; /* EMC ("android") */ - case 0x4c: return EL_EMPTY_SPACE; /* EMC */ - case 0x4d: return EL_UNKNOWN; /* EMC ("android") */ - case 0x4e: return EL_INVISIBLE_WALL; /* EMC (? "android") */ - case 0x4f: return EL_UNKNOWN; /* EMC ("android") */ - - case 0x50: return EL_UNKNOWN; /* EMC ("android") */ - case 0x51: return EL_UNKNOWN; /* EMC ("android") */ - case 0x52: return EL_UNKNOWN; /* EMC ("android") */ - case 0x53: return EL_UNKNOWN; /* EMC ("android") */ - case 0x54: return EL_UNKNOWN; /* EMC ("android") */ - case 0x55: return EL_EMPTY_SPACE; /* EMC */ - case 0x56: return EL_EMPTY_SPACE; /* EMC */ - case 0x57: return EL_EMPTY_SPACE; /* EMC */ - case 0x58: return EL_EMPTY_SPACE; /* EMC */ - case 0x59: return EL_EMPTY_SPACE; /* EMC */ - case 0x5a: return EL_EMPTY_SPACE; /* EMC */ - case 0x5b: return EL_EMPTY_SPACE; /* EMC */ - case 0x5c: return EL_EMPTY_SPACE; /* EMC */ - case 0x5d: return EL_EMPTY_SPACE; /* EMC */ - case 0x5e: return EL_EMPTY_SPACE; /* EMC */ - case 0x5f: return EL_EMPTY_SPACE; /* EMC */ - - case 0x60: return EL_EMPTY_SPACE; /* EMC */ - case 0x61: return EL_EMPTY_SPACE; /* EMC */ - case 0x62: return EL_EMPTY_SPACE; /* EMC */ - case 0x63: return EL_SPRING; /* left */ /* EMC */ - case 0x64: return EL_SPRING; /* right */ /* EMC */ - case 0x65: return EL_ACID; /* 1 */ /* EMC */ - case 0x66: return EL_ACID; /* 2 */ /* EMC */ - case 0x67: return EL_ACID; /* 3 */ /* EMC */ - case 0x68: return EL_ACID; /* 4 */ /* EMC */ - case 0x69: return EL_ACID; /* 5 */ /* EMC */ - case 0x6a: return EL_ACID; /* 6 */ /* EMC */ - case 0x6b: return EL_ACID; /* 7 */ /* EMC */ - case 0x6c: return EL_ACID; /* 8 */ /* EMC */ - case 0x6d: return EL_EMPTY_SPACE; /* EMC */ - case 0x6e: return EL_EMPTY_SPACE; /* EMC */ - case 0x6f: return EL_EMPTY_SPACE; /* EMC */ - - case 0x70: return EL_EMPTY_SPACE; /* EMC */ - case 0x71: return EL_EMPTY_SPACE; /* EMC */ - case 0x72: return EL_NUT; /* left */ /* EMC */ - case 0x73: return EL_SAND; /* EMC (? "nut") */ - case 0x74: return EL_STEELWALL; - case 0x75: return EL_EMPTY_SPACE; /* EMC */ - case 0x76: return EL_EMPTY_SPACE; /* EMC */ - case 0x77: return EL_BOMB; /* left */ /* EMC */ - case 0x78: return EL_BOMB; /* right */ /* EMC */ - case 0x79: return EL_ROCK; /* left */ /* EMC */ - case 0x7a: return EL_ROCK; /* right */ /* EMC */ - case 0x7b: return EL_ACID; /* (? EMC "blank") */ - case 0x7c: return EL_EMPTY_SPACE; /* EMC */ - case 0x7d: return EL_EMPTY_SPACE; /* EMC */ - case 0x7e: return EL_EMPTY_SPACE; /* EMC */ - case 0x7f: return EL_EMPTY_SPACE; /* EMC */ - - case 0x80: return EL_EMPTY; - case 0x81: return EL_WALL_SLIPPERY; - case 0x82: return EL_SAND; - case 0x83: return EL_STEELWALL; - case 0x84: return EL_WALL; - case 0x85: return EL_EM_KEY_1; - case 0x86: return EL_EM_KEY_2; - case 0x87: return EL_EM_KEY_4; - case 0x88: return EL_EM_KEY_3; - case 0x89: return EL_EM_GATE_1; - case 0x8a: return EL_EM_GATE_2; - case 0x8b: return EL_EM_GATE_4; - case 0x8c: return EL_EM_GATE_3; - case 0x8d: return EL_INVISIBLE_WALL; /* EMC (? "dripper") */ - case 0x8e: return EL_EM_GATE_1_GRAY; - case 0x8f: return EL_EM_GATE_2_GRAY; - - case 0x90: return EL_EM_GATE_4_GRAY; - case 0x91: return EL_EM_GATE_3_GRAY; - case 0x92: return EL_MAGIC_WALL; - case 0x93: return EL_ROBOT_WHEEL; - case 0x94: return EL_QUICKSAND_EMPTY; /* (? EMC "sand") */ - case 0x95: return EL_ACID_POOL_TOPLEFT; - case 0x96: return EL_ACID_POOL_TOPRIGHT; - case 0x97: return EL_ACID_POOL_BOTTOMLEFT; - case 0x98: return EL_ACID_POOL_BOTTOMRIGHT; - case 0x99: return EL_ACID; /* (? EMC "fake blank") */ - case 0x9a: return EL_AMOEBA_DEAD; /* 1 */ - case 0x9b: return EL_AMOEBA_DEAD; /* 2 */ - case 0x9c: return EL_AMOEBA_DEAD; /* 3 */ - case 0x9d: return EL_AMOEBA_DEAD; /* 4 */ - case 0x9e: return EL_EXIT_CLOSED; - case 0x9f: return EL_CHAR_LESS; /* arrow left */ - - /* looks like normal sand, but behaves like wall */ - case 0xa0: return EL_UNKNOWN; /* EMC ("fake grass") */ - case 0xa1: return EL_UNKNOWN; /* EMC ("lenses") */ - case 0xa2: return EL_UNKNOWN; /* EMC ("magnify") */ - case 0xa3: return EL_UNKNOWN; /* EMC ("fake blank") */ - case 0xa4: return EL_UNKNOWN; /* EMC ("fake grass") */ - case 0xa5: return EL_UNKNOWN; /* EMC ("switch") */ - case 0xa6: return EL_UNKNOWN; /* EMC ("switch") */ - case 0xa7: return EL_EMPTY_SPACE; /* EMC */ - case 0xa8: return EL_EMC_WALL_1; /* EMC ("decor 8") */ - case 0xa9: return EL_EMC_WALL_2; /* EMC ("decor 9") */ - case 0xaa: return EL_EMC_WALL_3; /* EMC ("decor 10") */ - case 0xab: return EL_EMC_WALL_7; /* EMC ("decor 5") */ - case 0xac: return EL_CHAR_COMMA; /* EMC */ - case 0xad: return EL_CHAR_QUOTEDBL; /* EMC */ - case 0xae: return EL_CHAR_MINUS; /* EMC */ - case 0xaf: return EL_DYNAMITE; - - case 0xb0: return EL_EMC_STEELWALL_1; /* EMC ("steel 3") */ - case 0xb1: return EL_EMC_WALL_8; /* EMC ("decor 6") */ - case 0xb2: return EL_UNKNOWN; /* EMC ("decor 7") */ - case 0xb3: return EL_STEELWALL; /* 2 */ /* EMC */ - case 0xb4: return EL_WALL_SLIPPERY; /* 2 */ /* EMC */ - case 0xb5: return EL_EMC_WALL_6; /* EMC ("decor 2") */ - case 0xb6: return EL_EMC_WALL_5; /* EMC ("decor 4") */ - case 0xb7: return EL_EMC_WALL_4; /* EMC ("decor 3") */ - case 0xb8: return EL_BALLOON_SWITCH_ANY; /* EMC */ - case 0xb9: return EL_BALLOON_SWITCH_RIGHT; /* EMC */ - case 0xba: return EL_BALLOON_SWITCH_DOWN; /* EMC */ - case 0xbb: return EL_BALLOON_SWITCH_LEFT; /* EMC */ - case 0xbc: return EL_BALLOON_SWITCH_UP; /* EMC */ - case 0xbd: return EL_SAND; /* EMC ("dirt") */ - case 0xbe: return EL_UNKNOWN; /* EMC ("plant") */ - case 0xbf: return EL_UNKNOWN; /* EMC ("key 5") */ - - case 0xc0: return EL_UNKNOWN; /* EMC ("key 6") */ - case 0xc1: return EL_UNKNOWN; /* EMC ("key 7") */ - case 0xc2: return EL_UNKNOWN; /* EMC ("key 8") */ - case 0xc3: return EL_UNKNOWN; /* EMC ("door 5") */ - case 0xc4: return EL_UNKNOWN; /* EMC ("door 6") */ - case 0xc5: return EL_UNKNOWN; /* EMC ("door 7") */ - case 0xc6: return EL_UNKNOWN; /* EMC ("door 8") */ - case 0xc7: return EL_UNKNOWN; /* EMC ("bumper") */ - - /* characters: see above */ - - case 0xec: return EL_CHAR_PERIOD; - case 0xed: return EL_CHAR_EXCLAM; - case 0xee: return EL_CHAR_COLON; - case 0xef: return EL_CHAR_QUESTION; - - case 0xf0: return EL_CHAR_GREATER; /* arrow right */ - case 0xf1: return EL_CHAR_COPYRIGHT; /* EMC: "decor 1" */ - case 0xf2: return EL_UNKNOWN; /* EMC ("fake door 5") */ - case 0xf3: return EL_UNKNOWN; /* EMC ("fake door 6") */ - case 0xf4: return EL_UNKNOWN; /* EMC ("fake door 7") */ - case 0xf5: return EL_UNKNOWN; /* EMC ("fake door 8") */ - case 0xf6: return EL_EMPTY_SPACE; /* EMC */ - case 0xf7: return EL_EMPTY_SPACE; /* EMC */ - - case 0xf8: return EL_EMPTY_SPACE; /* EMC */ - case 0xf9: return EL_EMPTY_SPACE; /* EMC */ - case 0xfa: return EL_EMPTY_SPACE; /* EMC */ - case 0xfb: return EL_EMPTY_SPACE; /* EMC */ - case 0xfc: return EL_EMPTY_SPACE; /* EMC */ - case 0xfd: return EL_EMPTY_SPACE; /* EMC */ - - case 0xfe: return EL_PLAYER_1; /* EMC: "blank" */ - case 0xff: return EL_PLAYER_2; /* EMC: "blank" */ - - default: - /* should never happen (all 8-bit value cases should be handled) */ - Error(ERR_WARN, "invalid level element %d", element); - return EL_UNKNOWN; - } -} - -#define EM_LEVEL_SIZE 2106 -#define EM_LEVEL_XSIZE 64 -#define EM_LEVEL_YSIZE 32 - -static void OLD_LoadLevelFromFileInfo_EM(struct LevelInfo *level, - struct LevelFileInfo *level_file_info) -{ - char *filename = level_file_info->filename; - FILE *file; - unsigned char leveldata[EM_LEVEL_SIZE]; - unsigned char *header = &leveldata[EM_LEVEL_XSIZE * EM_LEVEL_YSIZE]; - int nr = level_file_info->nr; - int i, x, y; - - if (!(file = fopen(filename, MODE_READ))) - { - level->no_valid_file = TRUE; - - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); - - return; - } - - for (i = 0; i < EM_LEVEL_SIZE; i++) - leveldata[i] = fgetc(file); - - fclose(file); - - /* check if level data is crypted by testing against known starting bytes - of the few existing crypted level files (from Emerald Mine 1 + 2) */ - - if ((leveldata[0] == 0xf1 || - leveldata[0] == 0xf5) && leveldata[2] == 0xe7 && leveldata[3] == 0xee) - { - unsigned char code0 = 0x65; - unsigned char code1 = 0x11; - - if (leveldata[0] == 0xf5) /* error in crypted Emerald Mine 2 levels */ - leveldata[0] = 0xf1; - - /* decode crypted level data */ - - for (i = 0; i < EM_LEVEL_SIZE; i++) - { - leveldata[i] ^= code0; - leveldata[i] -= code1; - - code0 = (code0 + 7) & 0xff; - } - } - - level->fieldx = EM_LEVEL_XSIZE; - level->fieldy = EM_LEVEL_YSIZE; - - level->time = header[46] * 10; - level->gems_needed = header[47]; - - /* The original Emerald Mine levels have their level number stored - at the second byte of the level file... - Do not trust this information at other level files, e.g. EMC, - but correct it anyway (normally the first row is completely - steel wall, so the correction does not hurt anyway). */ - - if (leveldata[1] == nr) - leveldata[1] = leveldata[2]; /* correct level number field */ - - sprintf(level->name, "Level %d", nr); /* set level name */ - - level->score[SC_EMERALD] = header[36]; - level->score[SC_DIAMOND] = header[37]; - level->score[SC_ROBOT] = header[38]; - level->score[SC_SPACESHIP] = header[39]; - level->score[SC_BUG] = header[40]; - level->score[SC_YAMYAM] = header[41]; - level->score[SC_NUT] = header[42]; - level->score[SC_DYNAMITE] = header[43]; - level->score[SC_TIME_BONUS] = header[44]; - - level->num_yamyam_contents = 4; - - for (i = 0; i < level->num_yamyam_contents; i++) - for (y = 0; y < 3; y++) - for (x = 0; x < 3; x++) - level->yamyam_content[i].e[x][y] = - map_em_element_yam(header[i * 9 + y * 3 + x]); - - level->amoeba_speed = (header[52] * 256 + header[53]) % 256; - level->time_magic_wall = (header[54] * 256 + header[55]) * 16 / 100; - level->time_wheel = (header[56] * 256 + header[57]) * 16 / 100; - level->amoeba_content = EL_DIAMOND; - - for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++) - { - int new_element = map_em_element_field(leveldata[y * EM_LEVEL_XSIZE + x]); - - if (new_element == EL_AMOEBA_DEAD && level->amoeba_speed) - new_element = EL_AMOEBA_WET; - - level->field[x][y] = new_element; - } - - x = (header[48] * 256 + header[49]) % EM_LEVEL_XSIZE; - y = (header[48] * 256 + header[49]) / EM_LEVEL_XSIZE; - level->field[x][y] = EL_PLAYER_1; - - x = (header[50] * 256 + header[51]) % EM_LEVEL_XSIZE; - y = (header[50] * 256 + header[51]) / EM_LEVEL_XSIZE; - level->field[x][y] = EL_PLAYER_2; -} - -#endif - -void CopyNativeLevel_RND_to_EM(struct LevelInfo *level) -{ - static int ball_xy[8][2] = - { - { 0, 0 }, - { 1, 0 }, - { 2, 0 }, - { 0, 1 }, - { 2, 1 }, - { 0, 2 }, - { 1, 2 }, - { 2, 2 }, - }; - struct LevelInfo_EM *level_em = level->native_em_level; - struct LEVEL *lev = level_em->lev; - struct PLAYER **ply = level_em->ply; - int i, j, x, y; - - lev->width = MIN(level->fieldx, EM_MAX_CAVE_WIDTH); - lev->height = MIN(level->fieldy, EM_MAX_CAVE_HEIGHT); - - lev->time_seconds = level->time; - lev->required_initial = level->gems_needed; - - lev->emerald_score = level->score[SC_EMERALD]; - lev->diamond_score = level->score[SC_DIAMOND]; - lev->alien_score = level->score[SC_ROBOT]; - lev->tank_score = level->score[SC_SPACESHIP]; - lev->bug_score = level->score[SC_BUG]; - lev->eater_score = level->score[SC_YAMYAM]; - lev->nut_score = level->score[SC_NUT]; - lev->dynamite_score = level->score[SC_DYNAMITE]; - lev->key_score = level->score[SC_KEY]; - lev->exit_score = level->score[SC_TIME_BONUS]; - - for (i = 0; i < MAX_ELEMENT_CONTENTS; i++) - for (y = 0; y < 3; y++) - for (x = 0; x < 3; x++) - lev->eater_array[i][y * 3 + x] = - map_element_RND_to_EM(level->yamyam_content[i].e[x][y]); - - lev->amoeba_time = level->amoeba_speed; - lev->wonderwall_time_initial = level->time_magic_wall; - lev->wheel_time = level->time_wheel; - - lev->android_move_time = level->android_move_time; - lev->android_clone_time = level->android_clone_time; - lev->ball_random = level->ball_random; - lev->ball_state_initial = level->ball_state_initial; - lev->ball_time = level->ball_time; - lev->num_ball_arrays = level->num_ball_contents; - - lev->lenses_score = level->lenses_score; - lev->magnify_score = level->magnify_score; - lev->slurp_score = level->slurp_score; - - lev->lenses_time = level->lenses_time; - lev->magnify_time = level->magnify_time; - - lev->wind_direction_initial = - map_direction_RND_to_EM(level->wind_direction_initial); - lev->wind_cnt_initial = (level->wind_direction_initial != MV_NONE ? - lev->wind_time : 0); - - for (i = 0; i < MAX_ELEMENT_CONTENTS; i++) - for (j = 0; j < 8; j++) - lev->ball_array[i][j] = - map_element_RND_to_EM(level-> - ball_content[i].e[ball_xy[j][0]][ball_xy[j][1]]); - - map_android_clone_elements_RND_to_EM(level); - - /* first fill the complete playfield with the default border element */ - for (y = 0; y < EM_MAX_CAVE_HEIGHT; y++) - for (x = 0; x < EM_MAX_CAVE_WIDTH; x++) - level_em->cave[x][y] = ZBORDER; - - if (BorderElement == EL_STEELWALL) - { - for (y = 0; y < lev->height + 2; y++) - for (x = 0; x < lev->width + 2; x++) - level_em->cave[x + 1][y + 1] = map_element_RND_to_EM(EL_STEELWALL); - } - - /* then copy the real level contents from level file into the playfield */ - for (y = 0; y < lev->height; y++) for (x = 0; x < lev->width; x++) - { - int new_element = map_element_RND_to_EM(level->field[x][y]); - int offset = (BorderElement == EL_STEELWALL ? 1 : 0); - int xx = x + 1 + offset; - int yy = y + 1 + offset; - - if (level->field[x][y] == EL_AMOEBA_DEAD) - new_element = map_element_RND_to_EM(EL_AMOEBA_WET); - - level_em->cave[xx][yy] = new_element; - } - - for (i = 0; i < MAX_PLAYERS; i++) - { - ply[i]->x_initial = 0; - ply[i]->y_initial = 0; - } - - /* initialize player positions and delete players from the playfield */ - for (y = 0; y < lev->height; y++) for (x = 0; x < lev->width; x++) - { - if (ELEM_IS_PLAYER(level->field[x][y])) - { - int player_nr = GET_PLAYER_NR(level->field[x][y]); - int offset = (BorderElement == EL_STEELWALL ? 1 : 0); - int xx = x + 1 + offset; - int yy = y + 1 + offset; - - ply[player_nr]->x_initial = xx; - ply[player_nr]->y_initial = yy; - - level_em->cave[xx][yy] = map_element_RND_to_EM(EL_EMPTY); - } - } - - if (BorderElement == EL_STEELWALL) - { - lev->width += 2; - lev->height += 2; - } -} - -void CopyNativeLevel_EM_to_RND(struct LevelInfo *level) -{ - static int ball_xy[8][2] = - { - { 0, 0 }, - { 1, 0 }, - { 2, 0 }, - { 0, 1 }, - { 2, 1 }, - { 0, 2 }, - { 1, 2 }, - { 2, 2 }, - }; - struct LevelInfo_EM *level_em = level->native_em_level; - struct LEVEL *lev = level_em->lev; - struct PLAYER **ply = level_em->ply; - int i, j, x, y; - - level->fieldx = MIN(lev->width, MAX_LEV_FIELDX); - level->fieldy = MIN(lev->height, MAX_LEV_FIELDY); - - level->time = lev->time_seconds; - level->gems_needed = lev->required_initial; - - sprintf(level->name, "Level %d", level->file_info.nr); - - level->score[SC_EMERALD] = lev->emerald_score; - level->score[SC_DIAMOND] = lev->diamond_score; - level->score[SC_ROBOT] = lev->alien_score; - level->score[SC_SPACESHIP] = lev->tank_score; - level->score[SC_BUG] = lev->bug_score; - level->score[SC_YAMYAM] = lev->eater_score; - level->score[SC_NUT] = lev->nut_score; - level->score[SC_DYNAMITE] = lev->dynamite_score; - level->score[SC_KEY] = lev->key_score; - level->score[SC_TIME_BONUS] = lev->exit_score; - - level->num_yamyam_contents = MAX_ELEMENT_CONTENTS; - - for (i = 0; i < level->num_yamyam_contents; i++) - for (y = 0; y < 3; y++) - for (x = 0; x < 3; x++) - level->yamyam_content[i].e[x][y] = - map_element_EM_to_RND(lev->eater_array[i][y * 3 + x]); - - level->amoeba_speed = lev->amoeba_time; - level->time_magic_wall = lev->wonderwall_time_initial; - level->time_wheel = lev->wheel_time; - - level->android_move_time = lev->android_move_time; - level->android_clone_time = lev->android_clone_time; - level->ball_random = lev->ball_random; - level->ball_state_initial = lev->ball_state_initial; - level->ball_time = lev->ball_time; - level->num_ball_contents = lev->num_ball_arrays; - - level->lenses_score = lev->lenses_score; - level->magnify_score = lev->magnify_score; - level->slurp_score = lev->slurp_score; - - level->lenses_time = lev->lenses_time; - level->magnify_time = lev->magnify_time; - - level->wind_direction_initial = - map_direction_EM_to_RND(lev->wind_direction_initial); - - for (i = 0; i < MAX_ELEMENT_CONTENTS; i++) - for (j = 0; j < 8; j++) - level->ball_content[i].e[ball_xy[j][0]][ball_xy[j][1]] = - map_element_EM_to_RND(lev->ball_array[i][j]); - - map_android_clone_elements_EM_to_RND(level); - - /* convert the playfield (some elements need special treatment) */ - for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++) - { - int new_element = map_element_EM_to_RND(level_em->cave[x + 1][y + 1]); - - if (new_element == EL_AMOEBA_WET && level->amoeba_speed == 0) - new_element = EL_AMOEBA_DEAD; - - level->field[x][y] = new_element; - } - - for (i = 0; i < MAX_PLAYERS; i++) - { - /* in case of all players set to the same field, use the first player */ - int nr = MAX_PLAYERS - i - 1; - int jx = ply[nr]->x_initial - 1; - int jy = ply[nr]->y_initial - 1; - - if (jx != -1 && jy != -1) - level->field[jx][jy] = EL_PLAYER_1 + nr; - } -} - - -/* ------------------------------------------------------------------------- */ -/* functions for loading SP level */ -/* ------------------------------------------------------------------------- */ - -#if 0 - -#define NUM_SUPAPLEX_LEVELS_PER_PACKAGE 111 -#define SP_LEVEL_SIZE 1536 -#define SP_LEVEL_XSIZE 60 -#define SP_LEVEL_YSIZE 24 -#define SP_LEVEL_NAME_LEN 23 - -static void LoadLevelFromFileStream_SP(FILE *file, struct LevelInfo *level, - int nr) -{ - int initial_player_gravity; - int num_special_ports; - int i, x, y; - - /* for details of the Supaplex level format, see Herman Perk's Supaplex - documentation file "SPFIX63.DOC" from his Supaplex "SpeedFix" package */ - - /* read level body (width * height == 60 * 24 tiles == 1440 bytes) */ - for (y = 0; y < SP_LEVEL_YSIZE; y++) - { - for (x = 0; x < SP_LEVEL_XSIZE; x++) - { - int element_old = fgetc(file); - int element_new; - - if (element_old <= 0x27) - element_new = getMappedElement(EL_SP_START + element_old); - else if (element_old == 0x28) - element_new = EL_INVISIBLE_WALL; - else - { - Error(ERR_WARN, "in level %d, at position %d, %d:", nr, x, y); - Error(ERR_WARN, "invalid level element %d", element_old); - - element_new = EL_UNKNOWN; - } - - level->field[x][y] = element_new; - } - } - - ReadUnusedBytesFromFile(file, 4); /* (not used by Supaplex engine) */ - - /* initial gravity: 1 == "on", anything else (0) == "off" */ - initial_player_gravity = (fgetc(file) == 1 ? TRUE : FALSE); - - for (i = 0; i < MAX_PLAYERS; i++) - level->initial_player_gravity[i] = initial_player_gravity; - - ReadUnusedBytesFromFile(file, 1); /* (not used by Supaplex engine) */ - - /* level title in uppercase letters, padded with dashes ("-") (23 bytes) */ - for (i = 0; i < SP_LEVEL_NAME_LEN; i++) - level->name[i] = fgetc(file); - level->name[SP_LEVEL_NAME_LEN] = '\0'; - - /* initial "freeze zonks": 2 == "on", anything else (0, 1) == "off" */ - ReadUnusedBytesFromFile(file, 1); /* (not used by R'n'D engine) */ - - /* number of infotrons needed; 0 means that Supaplex will count the total - amount of infotrons in the level and use the low byte of that number - (a multiple of 256 infotrons will result in "0 infotrons needed"!) */ - level->gems_needed = fgetc(file); - - /* number of special ("gravity") port entries below (maximum 10 allowed) */ - num_special_ports = fgetc(file); - - /* database of properties of up to 10 special ports (6 bytes per port) */ - for (i = 0; i < 10; i++) - { - int port_location, port_x, port_y, port_element; - int gravity; - - /* high and low byte of the location of a special port; if (x, y) are the - coordinates of a port in the field and (0, 0) is the top-left corner, - the 16 bit value here calculates as 2 * (x + (y * 60)) (this is twice - of what may be expected: Supaplex works with a game field in memory - which is 2 bytes per tile) */ - port_location = getFile16BitBE(file); - - /* change gravity: 1 == "turn on", anything else (0) == "turn off" */ - gravity = fgetc(file); - - /* "freeze zonks": 2 == "turn on", anything else (0, 1) == "turn off" */ - ReadUnusedBytesFromFile(file, 1); /* (not used by R'n'D engine) */ - - /* "freeze enemies": 1 == "turn on", anything else (0) == "turn off" */ - ReadUnusedBytesFromFile(file, 1); /* (not used by R'n'D engine) */ - - ReadUnusedBytesFromFile(file, 1); /* (not used by Supaplex engine) */ - - if (i >= num_special_ports) - continue; - - port_x = (port_location / 2) % SP_LEVEL_XSIZE; - port_y = (port_location / 2) / SP_LEVEL_XSIZE; - - if (port_x < 0 || port_x >= SP_LEVEL_XSIZE || - port_y < 0 || port_y >= SP_LEVEL_YSIZE) - { - Error(ERR_WARN, "special port position (%d, %d) out of bounds", - port_x, port_y); - - continue; - } - - port_element = level->field[port_x][port_y]; - - if (port_element < EL_SP_GRAVITY_PORT_RIGHT || - port_element > EL_SP_GRAVITY_PORT_UP) - { - Error(ERR_WARN, "no special port at position (%d, %d)", port_x, port_y); - - continue; - } - - /* change previous (wrong) gravity inverting special port to either - gravity enabling special port or gravity disabling special port */ - level->field[port_x][port_y] += - (gravity == 1 ? EL_SP_GRAVITY_ON_PORT_RIGHT : - EL_SP_GRAVITY_OFF_PORT_RIGHT) - EL_SP_GRAVITY_PORT_RIGHT; - } - - ReadUnusedBytesFromFile(file, 4); /* (not used by Supaplex engine) */ - - /* change special gravity ports without database entries to normal ports */ - for (y = 0; y < SP_LEVEL_YSIZE; y++) - for (x = 0; x < SP_LEVEL_XSIZE; x++) - if (level->field[x][y] >= EL_SP_GRAVITY_PORT_RIGHT && - level->field[x][y] <= EL_SP_GRAVITY_PORT_UP) - level->field[x][y] += EL_SP_PORT_RIGHT - EL_SP_GRAVITY_PORT_RIGHT; - - /* auto-determine number of infotrons if it was stored as "0" -- see above */ - if (level->gems_needed == 0) - { - for (y = 0; y < SP_LEVEL_YSIZE; y++) - for (x = 0; x < SP_LEVEL_XSIZE; x++) - if (level->field[x][y] == EL_SP_INFOTRON) - level->gems_needed++; - - level->gems_needed &= 0xff; /* only use low byte -- see above */ - } - - level->fieldx = SP_LEVEL_XSIZE; - level->fieldy = SP_LEVEL_YSIZE; - - level->time = 0; /* no time limit */ - level->amoeba_speed = 0; - level->time_magic_wall = 0; - level->time_wheel = 0; - level->amoeba_content = EL_EMPTY; - -#if 1 - /* original Supaplex does not use score values -- use default values */ -#else - for (i = 0; i < LEVEL_SCORE_ELEMENTS; i++) - level->score[i] = 0; -#endif - - /* there are no yamyams in supaplex levels */ - for (i = 0; i < level->num_yamyam_contents; i++) - for (y = 0; y < 3; y++) - for (x = 0; x < 3; x++) - level->yamyam_content[i].e[x][y] = EL_EMPTY; -} - -static void LoadLevelFromFileInfo_SP(struct LevelInfo *level, - struct LevelFileInfo *level_file_info, - boolean level_info_only) -{ - char *filename = level_file_info->filename; - FILE *file; - int nr = level_file_info->nr - leveldir_current->first_level; - int i, l, x, y; - char name_first, name_last; - struct LevelInfo multipart_level; - int multipart_xpos, multipart_ypos; - boolean is_multipart_level; - boolean is_first_part; - boolean reading_multipart_level = FALSE; - boolean use_empty_level = FALSE; - - if (!(file = fopen(filename, MODE_READ))) - { - level->no_valid_file = TRUE; - - if (!level_info_only) - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); - - return; - } - - /* position file stream to the requested level inside the level package */ - if (level_file_info->packed && - fseek(file, nr * SP_LEVEL_SIZE, SEEK_SET) != 0) - { - level->no_valid_file = TRUE; - - Error(ERR_WARN, "cannot fseek in file '%s' -- using empty level", filename); - - return; - } - - /* there exist Supaplex level package files with multi-part levels which - can be detected as follows: instead of leading and trailing dashes ('-') - to pad the level name, they have leading and trailing numbers which are - the x and y coordinations of the current part of the multi-part level; - if there are '?' characters instead of numbers on the left or right side - of the level name, the multi-part level consists of only horizontal or - vertical parts */ - - for (l = nr; l < NUM_SUPAPLEX_LEVELS_PER_PACKAGE; l++) - { - LoadLevelFromFileStream_SP(file, level, l); - - /* check if this level is a part of a bigger multi-part level */ - - name_first = level->name[0]; - name_last = level->name[SP_LEVEL_NAME_LEN - 1]; - - is_multipart_level = - ((name_first == '?' || (name_first >= '0' && name_first <= '9')) && - (name_last == '?' || (name_last >= '0' && name_last <= '9'))); - - is_first_part = - ((name_first == '?' || name_first == '1') && - (name_last == '?' || name_last == '1')); - - /* correct leading multipart level meta information in level name */ - for (i = 0; i < SP_LEVEL_NAME_LEN && level->name[i] == name_first; i++) - level->name[i] = '-'; - - /* correct trailing multipart level meta information in level name */ - for (i = SP_LEVEL_NAME_LEN - 1; i >= 0 && level->name[i] == name_last; i--) - level->name[i] = '-'; - - /* ---------- check for normal single level ---------- */ - - if (!reading_multipart_level && !is_multipart_level) - { - /* the current level is simply a normal single-part level, and we are - not reading a multi-part level yet, so return the level as it is */ - - break; - } - - /* ---------- check for empty level (unused multi-part) ---------- */ - - if (!reading_multipart_level && is_multipart_level && !is_first_part) - { - /* this is a part of a multi-part level, but not the first part - (and we are not already reading parts of a multi-part level); - in this case, use an empty level instead of the single part */ - - use_empty_level = TRUE; - - break; - } - - /* ---------- check for finished multi-part level ---------- */ - - if (reading_multipart_level && - (!is_multipart_level || - !strEqual(level->name, multipart_level.name))) - { - /* we are already reading parts of a multi-part level, but this level is - either not a multi-part level, or a part of a different multi-part - level; in both cases, the multi-part level seems to be complete */ - - break; - } - - /* ---------- here we have one part of a multi-part level ---------- */ - - reading_multipart_level = TRUE; - - if (is_first_part) /* start with first part of new multi-part level */ - { - /* copy level info structure from first part */ - multipart_level = *level; - - /* clear playfield of new multi-part level */ - for (y = 0; y < MAX_LEV_FIELDY; y++) - for (x = 0; x < MAX_LEV_FIELDX; x++) - multipart_level.field[x][y] = EL_EMPTY; - } - - if (name_first == '?') - name_first = '1'; - if (name_last == '?') - name_last = '1'; - - multipart_xpos = (int)(name_first - '0'); - multipart_ypos = (int)(name_last - '0'); - -#if 0 - printf("----------> part (%d/%d) of multi-part level '%s'\n", - multipart_xpos, multipart_ypos, multipart_level.name); -#endif - - if (multipart_xpos * SP_LEVEL_XSIZE > MAX_LEV_FIELDX || - multipart_ypos * SP_LEVEL_YSIZE > MAX_LEV_FIELDY) - { - Error(ERR_WARN, "multi-part level is too big -- ignoring part of it"); - - break; - } - - multipart_level.fieldx = MAX(multipart_level.fieldx, - multipart_xpos * SP_LEVEL_XSIZE); - multipart_level.fieldy = MAX(multipart_level.fieldy, - multipart_ypos * SP_LEVEL_YSIZE); - - /* copy level part at the right position of multi-part level */ - for (y = 0; y < SP_LEVEL_YSIZE; y++) - { - for (x = 0; x < SP_LEVEL_XSIZE; x++) - { - int start_x = (multipart_xpos - 1) * SP_LEVEL_XSIZE; - int start_y = (multipart_ypos - 1) * SP_LEVEL_YSIZE; - - multipart_level.field[start_x + x][start_y + y] = level->field[x][y]; - } - } - } - - fclose(file); - - if (use_empty_level) - { - setLevelInfoToDefaults(level); - - level->fieldx = SP_LEVEL_XSIZE; - level->fieldy = SP_LEVEL_YSIZE; - - for (y = 0; y < SP_LEVEL_YSIZE; y++) - for (x = 0; x < SP_LEVEL_XSIZE; x++) - level->field[x][y] = EL_EMPTY; - - strcpy(level->name, "-------- EMPTY --------"); - - Error(ERR_WARN, "single part of multi-part level -- using empty level"); - } - - if (reading_multipart_level) - *level = multipart_level; -} - -#endif - -void CopyNativeLevel_RND_to_SP(struct LevelInfo *level) -{ - struct LevelInfo_SP *level_sp = level->native_sp_level; - LevelInfoType *header = &level_sp->header; - int i, x, y; - - level_sp->width = level->fieldx; - level_sp->height = level->fieldy; - - for (x = 0; x < level->fieldx; x++) - for (y = 0; y < level->fieldy; y++) - level_sp->playfield[x][y] = map_element_RND_to_SP(level->field[x][y]); - - header->InitialGravity = (level->initial_player_gravity[0] ? 1 : 0); - - for (i = 0; i < SP_LEVEL_NAME_LEN; i++) - header->LevelTitle[i] = level->name[i]; - /* !!! NO STRING TERMINATION IN SUPAPLEX VB CODE YET -- FIX THIS !!! */ - - header->InfotronsNeeded = level->gems_needed; - - header->SpecialPortCount = 0; - - for (x = 0; x < level->fieldx; x++) for (y = 0; y < level->fieldy; y++) - { - boolean gravity_port_found = FALSE; - boolean gravity_port_valid = FALSE; - int gravity_port_flag; - int gravity_port_base_element; - int element = level->field[x][y]; - - if (element >= EL_SP_GRAVITY_ON_PORT_RIGHT && - element <= EL_SP_GRAVITY_ON_PORT_UP) - { - gravity_port_found = TRUE; - gravity_port_valid = TRUE; - gravity_port_flag = 1; - gravity_port_base_element = EL_SP_GRAVITY_ON_PORT_RIGHT; - } - else if (element >= EL_SP_GRAVITY_OFF_PORT_RIGHT && - element <= EL_SP_GRAVITY_OFF_PORT_UP) - { - gravity_port_found = TRUE; - gravity_port_valid = TRUE; - gravity_port_flag = 0; - gravity_port_base_element = EL_SP_GRAVITY_OFF_PORT_RIGHT; - } - else if (element >= EL_SP_GRAVITY_PORT_RIGHT && - element <= EL_SP_GRAVITY_PORT_UP) - { - /* change R'n'D style gravity inverting special port to normal port - (there are no gravity inverting ports in native Supaplex engine) */ - - gravity_port_found = TRUE; - gravity_port_valid = FALSE; - gravity_port_base_element = EL_SP_GRAVITY_PORT_RIGHT; - } - - if (gravity_port_found) - { - if (gravity_port_valid && - header->SpecialPortCount < SP_MAX_SPECIAL_PORTS) - { - SpecialPortType *port = &header->SpecialPort[header->SpecialPortCount]; - - port->PortLocation = (y * level->fieldx + x) * 2; - port->Gravity = gravity_port_flag; - - element += EL_SP_GRAVITY_PORT_RIGHT - gravity_port_base_element; - - header->SpecialPortCount++; - } - else - { - /* change special gravity port to normal port */ - - element += EL_SP_PORT_RIGHT - gravity_port_base_element; - } - - level_sp->playfield[x][y] = element - EL_SP_START; - } - } -} - -void CopyNativeLevel_SP_to_RND(struct LevelInfo *level) -{ - struct LevelInfo_SP *level_sp = level->native_sp_level; - LevelInfoType *header = &level_sp->header; - int i, x, y; - - level->fieldx = level_sp->width; - level->fieldy = level_sp->height; - - for (x = 0; x < level->fieldx; x++) - { - for (y = 0; y < level->fieldy; y++) - { - int element_old = level_sp->playfield[x][y]; - int element_new = getMappedElement(map_element_SP_to_RND(element_old)); - - if (element_new == EL_UNKNOWN) - Error(ERR_WARN, "invalid element %d at position %d, %d", - element_old, x, y); - - level->field[x][y] = element_new; - } - } - - for (i = 0; i < MAX_PLAYERS; i++) - level->initial_player_gravity[i] = - (header->InitialGravity == 1 ? TRUE : FALSE); - - for (i = 0; i < SP_LEVEL_NAME_LEN; i++) - level->name[i] = header->LevelTitle[i]; - level->name[SP_LEVEL_NAME_LEN] = '\0'; - - level->gems_needed = header->InfotronsNeeded; - - for (i = 0; i < header->SpecialPortCount; i++) - { - SpecialPortType *port = &header->SpecialPort[i]; - int port_location = port->PortLocation; - int gravity = port->Gravity; - int port_x, port_y, port_element; - - port_x = (port_location / 2) % level->fieldx; - port_y = (port_location / 2) / level->fieldx; - - if (port_x < 0 || port_x >= level->fieldx || - port_y < 0 || port_y >= level->fieldy) - { - Error(ERR_WARN, "special port position (%d, %d) out of bounds", - port_x, port_y); - - continue; - } - - port_element = level->field[port_x][port_y]; - - if (port_element < EL_SP_GRAVITY_PORT_RIGHT || - port_element > EL_SP_GRAVITY_PORT_UP) - { - Error(ERR_WARN, "no special port at position (%d, %d)", port_x, port_y); - - continue; - } - - /* change previous (wrong) gravity inverting special port to either - gravity enabling special port or gravity disabling special port */ - level->field[port_x][port_y] += - (gravity == 1 ? EL_SP_GRAVITY_ON_PORT_RIGHT : - EL_SP_GRAVITY_OFF_PORT_RIGHT) - EL_SP_GRAVITY_PORT_RIGHT; - } - - /* change special gravity ports without database entries to normal ports */ - for (x = 0; x < level->fieldx; x++) - for (y = 0; y < level->fieldy; y++) - if (level->field[x][y] >= EL_SP_GRAVITY_PORT_RIGHT && - level->field[x][y] <= EL_SP_GRAVITY_PORT_UP) - level->field[x][y] += EL_SP_PORT_RIGHT - EL_SP_GRAVITY_PORT_RIGHT; - - level->time = 0; /* no time limit */ - level->amoeba_speed = 0; - level->time_magic_wall = 0; - level->time_wheel = 0; - level->amoeba_content = EL_EMPTY; - -#if 1 - /* original Supaplex does not use score values -- use default values */ -#else - for (i = 0; i < LEVEL_SCORE_ELEMENTS; i++) - level->score[i] = 0; -#endif - - /* there are no yamyams in supaplex levels */ - for (i = 0; i < level->num_yamyam_contents; i++) - for (x = 0; x < 3; x++) - for (y = 0; y < 3; y++) - level->yamyam_content[i].e[x][y] = EL_EMPTY; -} - -static void CopyNativeTape_RND_to_SP(struct LevelInfo *level) -{ - struct LevelInfo_SP *level_sp = level->native_sp_level; - struct DemoInfo_SP *demo = &level_sp->demo; - int i, j; - - /* always start with reliable default values */ - demo->is_available = FALSE; - demo->length = 0; - - if (TAPE_IS_EMPTY(tape)) - return; - - demo->level_nr = tape.level_nr; /* (currently not used) */ - - level_sp->header.DemoRandomSeed = tape.random_seed; - - demo->length = 0; - for (i = 0; i < tape.length; i++) - { - int demo_action = map_key_RND_to_SP(tape.pos[i].action[0]); - int demo_repeat = tape.pos[i].delay; - - for (j = 0; j < demo_repeat / 16; j++) - demo->data[demo->length++] = 0xf0 | demo_action; - - if (demo_repeat % 16) - demo->data[demo->length++] = ((demo_repeat % 16 - 1) << 4) | demo_action; - } - - demo->data[demo->length++] = 0xff; - - demo->is_available = TRUE; -} - -static void setTapeInfoToDefaults(); - -static void CopyNativeTape_SP_to_RND(struct LevelInfo *level) -{ - struct LevelInfo_SP *level_sp = level->native_sp_level; - struct DemoInfo_SP *demo = &level_sp->demo; - char *filename = level->file_info.filename; - int i; - - /* always start with reliable default values */ - setTapeInfoToDefaults(); - - if (!demo->is_available) - return; - - tape.level_nr = demo->level_nr; /* (currently not used) */ - tape.length = demo->length - 1; /* without "end of demo" byte */ - tape.random_seed = level_sp->header.DemoRandomSeed; - - TapeSetDateFromEpochSeconds(getFileTimestampEpochSeconds(filename)); - - for (i = 0; i < demo->length - 1; i++) - { - int demo_action = demo->data[i] & 0x0f; - int demo_repeat = (demo->data[i] & 0xf0) >> 4; - - tape.pos[i].action[0] = map_key_SP_to_RND(demo_action); - tape.pos[i].delay = demo_repeat + 1; - } - - tape.length_seconds = GetTapeLength(); -} - - -/* ------------------------------------------------------------------------- */ -/* functions for loading DC level */ -/* ------------------------------------------------------------------------- */ - -#define DC_LEVEL_HEADER_SIZE 344 - -unsigned short getDecodedWord_DC(unsigned short data_encoded, boolean init) -{ - static int last_data_encoded; - static int offset1; - static int offset2; - int diff; - int diff_hi, diff_lo; - int data_hi, data_lo; - unsigned short data_decoded; - - if (init) - { - last_data_encoded = 0; - offset1 = -1; - offset2 = 0; - - return 0; - } - - diff = data_encoded - last_data_encoded; - diff_hi = diff & ~0xff; - diff_lo = diff & 0xff; - - offset2 += diff_lo; - - data_hi = diff_hi - (offset1 << 8) + (offset2 & 0xff00); - data_lo = (diff_lo + (data_hi >> 16)) & 0x00ff; - data_hi = data_hi & 0xff00; - - data_decoded = data_hi | data_lo; - - last_data_encoded = data_encoded; - - offset1 = (offset1 + 1) % 31; - offset2 = offset2 & 0xff; - - return data_decoded; -} - -int getMappedElement_DC(int element) -{ - switch (element) - { - case 0x0000: - element = EL_ROCK; - break; - - /* 0x0117 - 0x036e: (?) */ - /* EL_DIAMOND */ - - /* 0x042d - 0x0684: (?) */ - /* EL_EMERALD */ - - case 0x06f1: - element = EL_NUT; - break; - - case 0x074c: - element = EL_BOMB; - break; - - case 0x07a4: - element = EL_PEARL; - break; - - case 0x0823: - element = EL_CRYSTAL; - break; - - case 0x0e77: /* quicksand (boulder) */ - element = EL_QUICKSAND_FAST_FULL; - break; - - case 0x0e99: /* slow quicksand (boulder) */ - element = EL_QUICKSAND_FULL; - break; - - case 0x0ed2: - element = EL_EM_EXIT_OPEN; - break; - - case 0x0ee3: - element = EL_EM_EXIT_CLOSED; - break; - - case 0x0eeb: - element = EL_EM_STEEL_EXIT_OPEN; - break; - - case 0x0efc: - element = EL_EM_STEEL_EXIT_CLOSED; - break; - - case 0x0f4f: /* dynamite (lit 1) */ - element = EL_EM_DYNAMITE_ACTIVE; - break; - - case 0x0f57: /* dynamite (lit 2) */ - element = EL_EM_DYNAMITE_ACTIVE; - break; - - case 0x0f5f: /* dynamite (lit 3) */ - element = EL_EM_DYNAMITE_ACTIVE; - break; - - case 0x0f67: /* dynamite (lit 4) */ - element = EL_EM_DYNAMITE_ACTIVE; - break; - - case 0x0f81: - case 0x0f82: - case 0x0f83: - case 0x0f84: - element = EL_AMOEBA_WET; - break; - - case 0x0f85: - element = EL_AMOEBA_DROP; - break; - - case 0x0fb9: - element = EL_DC_MAGIC_WALL; - break; - - case 0x0fd0: - element = EL_SPACESHIP_UP; - break; - - case 0x0fd9: - element = EL_SPACESHIP_DOWN; - break; - - case 0x0ff1: - element = EL_SPACESHIP_LEFT; - break; - - case 0x0ff9: - element = EL_SPACESHIP_RIGHT; - break; - - case 0x1057: - element = EL_BUG_UP; - break; - - case 0x1060: - element = EL_BUG_DOWN; - break; - - case 0x1078: - element = EL_BUG_LEFT; - break; - - case 0x1080: - element = EL_BUG_RIGHT; - break; - - case 0x10de: - element = EL_MOLE_UP; - break; - - case 0x10e7: - element = EL_MOLE_DOWN; - break; - - case 0x10ff: - element = EL_MOLE_LEFT; - break; - - case 0x1107: - element = EL_MOLE_RIGHT; - break; - - case 0x11c0: - element = EL_ROBOT; - break; - - case 0x13f5: - element = EL_YAMYAM; - break; - - case 0x1425: - element = EL_SWITCHGATE_OPEN; - break; - - case 0x1426: - element = EL_SWITCHGATE_CLOSED; - break; - - case 0x1437: - element = EL_DC_SWITCHGATE_SWITCH_UP; - break; - - case 0x143a: - element = EL_TIMEGATE_CLOSED; - break; + level->amoeba_speed = lev->amoeba_time; + level->time_magic_wall = lev->wonderwall_time_initial; + level->time_wheel = lev->wheel_time; - case 0x144c: /* conveyor belt switch (green) */ - element = EL_CONVEYOR_BELT_3_SWITCH_MIDDLE; - break; + level->android_move_time = lev->android_move_time; + level->android_clone_time = lev->android_clone_time; + level->ball_random = lev->ball_random; + level->ball_state_initial = lev->ball_state_initial; + level->ball_time = lev->ball_time; + level->num_ball_contents = lev->num_ball_arrays; - case 0x144f: /* conveyor belt switch (red) */ - element = EL_CONVEYOR_BELT_1_SWITCH_MIDDLE; - break; + level->lenses_score = lev->lenses_score; + level->magnify_score = lev->magnify_score; + level->slurp_score = lev->slurp_score; - case 0x1452: /* conveyor belt switch (blue) */ - element = EL_CONVEYOR_BELT_4_SWITCH_MIDDLE; - break; + level->lenses_time = lev->lenses_time; + level->magnify_time = lev->magnify_time; - case 0x145b: - element = EL_CONVEYOR_BELT_3_MIDDLE; - break; + level->wind_direction_initial = + map_direction_EM_to_RND(lev->wind_direction_initial); - case 0x1463: - element = EL_CONVEYOR_BELT_3_LEFT; - break; + for (i = 0; i < MAX_ELEMENT_CONTENTS; i++) + for (j = 0; j < 8; j++) + level->ball_content[i].e[ball_xy[j][0]][ball_xy[j][1]] = + map_element_EM_to_RND(lev->ball_array[i][j]); - case 0x146b: - element = EL_CONVEYOR_BELT_3_RIGHT; - break; + map_android_clone_elements_EM_to_RND(level); - case 0x1473: - element = EL_CONVEYOR_BELT_1_MIDDLE; - break; + /* convert the playfield (some elements need special treatment) */ + for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++) + { + int new_element = map_element_EM_to_RND(level_em->cave[x + 1][y + 1]); - case 0x147b: - element = EL_CONVEYOR_BELT_1_LEFT; - break; + if (new_element == EL_AMOEBA_WET && level->amoeba_speed == 0) + new_element = EL_AMOEBA_DEAD; - case 0x1483: - element = EL_CONVEYOR_BELT_1_RIGHT; - break; + level->field[x][y] = new_element; + } - case 0x148b: - element = EL_CONVEYOR_BELT_4_MIDDLE; - break; + for (i = 0; i < MAX_PLAYERS; i++) + { + /* in case of all players set to the same field, use the first player */ + int nr = MAX_PLAYERS - i - 1; + int jx = ply[nr]->x_initial - 1; + int jy = ply[nr]->y_initial - 1; - case 0x1493: - element = EL_CONVEYOR_BELT_4_LEFT; - break; + if (jx != -1 && jy != -1) + level->field[jx][jy] = EL_PLAYER_1 + nr; + } +} - case 0x149b: - element = EL_CONVEYOR_BELT_4_RIGHT; - break; - case 0x14ac: - element = EL_EXPANDABLE_WALL_HORIZONTAL; - break; +/* ------------------------------------------------------------------------- */ +/* functions for loading SP level */ +/* ------------------------------------------------------------------------- */ - case 0x14bd: - element = EL_EXPANDABLE_WALL_VERTICAL; - break; +void CopyNativeLevel_RND_to_SP(struct LevelInfo *level) +{ + struct LevelInfo_SP *level_sp = level->native_sp_level; + LevelInfoType *header = &level_sp->header; + int i, x, y; - case 0x14c6: - element = EL_EXPANDABLE_WALL_ANY; - break; + level_sp->width = level->fieldx; + level_sp->height = level->fieldy; - case 0x14ce: /* growing steel wall (left/right) */ - element = EL_EXPANDABLE_STEELWALL_HORIZONTAL; - break; + for (x = 0; x < level->fieldx; x++) + for (y = 0; y < level->fieldy; y++) + level_sp->playfield[x][y] = map_element_RND_to_SP(level->field[x][y]); - case 0x14df: /* growing steel wall (up/down) */ - element = EL_EXPANDABLE_STEELWALL_VERTICAL; - break; + header->InitialGravity = (level->initial_player_gravity[0] ? 1 : 0); - case 0x14e8: /* growing steel wall (up/down/left/right) */ - element = EL_EXPANDABLE_STEELWALL_ANY; - break; + for (i = 0; i < SP_LEVEL_NAME_LEN; i++) + header->LevelTitle[i] = level->name[i]; + /* !!! NO STRING TERMINATION IN SUPAPLEX VB CODE YET -- FIX THIS !!! */ - case 0x14e9: - element = EL_SHIELD_DEADLY; - break; + header->InfotronsNeeded = level->gems_needed; - case 0x1501: - element = EL_EXTRA_TIME; - break; + header->SpecialPortCount = 0; - case 0x154f: - element = EL_ACID; - break; + for (x = 0; x < level->fieldx; x++) for (y = 0; y < level->fieldy; y++) + { + boolean gravity_port_found = FALSE; + boolean gravity_port_valid = FALSE; + int gravity_port_flag; + int gravity_port_base_element; + int element = level->field[x][y]; - case 0x1577: - element = EL_EMPTY_SPACE; - break; + if (element >= EL_SP_GRAVITY_ON_PORT_RIGHT && + element <= EL_SP_GRAVITY_ON_PORT_UP) + { + gravity_port_found = TRUE; + gravity_port_valid = TRUE; + gravity_port_flag = 1; + gravity_port_base_element = EL_SP_GRAVITY_ON_PORT_RIGHT; + } + else if (element >= EL_SP_GRAVITY_OFF_PORT_RIGHT && + element <= EL_SP_GRAVITY_OFF_PORT_UP) + { + gravity_port_found = TRUE; + gravity_port_valid = TRUE; + gravity_port_flag = 0; + gravity_port_base_element = EL_SP_GRAVITY_OFF_PORT_RIGHT; + } + else if (element >= EL_SP_GRAVITY_PORT_RIGHT && + element <= EL_SP_GRAVITY_PORT_UP) + { + /* change R'n'D style gravity inverting special port to normal port + (there are no gravity inverting ports in native Supaplex engine) */ - case 0x1578: /* quicksand (empty) */ - element = EL_QUICKSAND_FAST_EMPTY; - break; + gravity_port_found = TRUE; + gravity_port_valid = FALSE; + gravity_port_base_element = EL_SP_GRAVITY_PORT_RIGHT; + } - case 0x1579: /* slow quicksand (empty) */ - element = EL_QUICKSAND_EMPTY; - break; + if (gravity_port_found) + { + if (gravity_port_valid && + header->SpecialPortCount < SP_MAX_SPECIAL_PORTS) + { + SpecialPortType *port = &header->SpecialPort[header->SpecialPortCount]; - /* 0x157c - 0x158b: */ - /* EL_SAND */ + port->PortLocation = (y * level->fieldx + x) * 2; + port->Gravity = gravity_port_flag; - /* 0x1590 - 0x159f: */ - /* EL_DC_LANDMINE */ + element += EL_SP_GRAVITY_PORT_RIGHT - gravity_port_base_element; - case 0x15a0: - element = EL_EM_DYNAMITE; - break; + header->SpecialPortCount++; + } + else + { + /* change special gravity port to normal port */ - case 0x15a1: /* key (red) */ - element = EL_EM_KEY_1; - break; + element += EL_SP_PORT_RIGHT - gravity_port_base_element; + } - case 0x15a2: /* key (yellow) */ - element = EL_EM_KEY_2; - break; + level_sp->playfield[x][y] = element - EL_SP_START; + } + } +} - case 0x15a3: /* key (blue) */ - element = EL_EM_KEY_4; - break; +void CopyNativeLevel_SP_to_RND(struct LevelInfo *level) +{ + struct LevelInfo_SP *level_sp = level->native_sp_level; + LevelInfoType *header = &level_sp->header; + int i, x, y; - case 0x15a4: /* key (green) */ - element = EL_EM_KEY_3; - break; + level->fieldx = level_sp->width; + level->fieldy = level_sp->height; - case 0x15a5: /* key (white) */ - element = EL_DC_KEY_WHITE; - break; + for (x = 0; x < level->fieldx; x++) + { + for (y = 0; y < level->fieldy; y++) + { + int element_old = level_sp->playfield[x][y]; + int element_new = getMappedElement(map_element_SP_to_RND(element_old)); - case 0x15a6: - element = EL_WALL_SLIPPERY; - break; + if (element_new == EL_UNKNOWN) + Error(ERR_WARN, "invalid element %d at position %d, %d", + element_old, x, y); - case 0x15a7: - element = EL_WALL; - break; + level->field[x][y] = element_new; + } + } - case 0x15a8: /* wall (not round) */ - element = EL_WALL; - break; + for (i = 0; i < MAX_PLAYERS; i++) + level->initial_player_gravity[i] = + (header->InitialGravity == 1 ? TRUE : FALSE); - case 0x15a9: /* (blue) */ - element = EL_CHAR_A; - break; + for (i = 0; i < SP_LEVEL_NAME_LEN; i++) + level->name[i] = header->LevelTitle[i]; + level->name[SP_LEVEL_NAME_LEN] = '\0'; - case 0x15aa: /* (blue) */ - element = EL_CHAR_B; - break; + level->gems_needed = header->InfotronsNeeded; - case 0x15ab: /* (blue) */ - element = EL_CHAR_C; - break; + for (i = 0; i < header->SpecialPortCount; i++) + { + SpecialPortType *port = &header->SpecialPort[i]; + int port_location = port->PortLocation; + int gravity = port->Gravity; + int port_x, port_y, port_element; - case 0x15ac: /* (blue) */ - element = EL_CHAR_D; - break; + port_x = (port_location / 2) % level->fieldx; + port_y = (port_location / 2) / level->fieldx; - case 0x15ad: /* (blue) */ - element = EL_CHAR_E; - break; + if (port_x < 0 || port_x >= level->fieldx || + port_y < 0 || port_y >= level->fieldy) + { + Error(ERR_WARN, "special port position (%d, %d) out of bounds", + port_x, port_y); - case 0x15ae: /* (blue) */ - element = EL_CHAR_F; - break; + continue; + } - case 0x15af: /* (blue) */ - element = EL_CHAR_G; - break; + port_element = level->field[port_x][port_y]; - case 0x15b0: /* (blue) */ - element = EL_CHAR_H; - break; + if (port_element < EL_SP_GRAVITY_PORT_RIGHT || + port_element > EL_SP_GRAVITY_PORT_UP) + { + Error(ERR_WARN, "no special port at position (%d, %d)", port_x, port_y); - case 0x15b1: /* (blue) */ - element = EL_CHAR_I; - break; + continue; + } - case 0x15b2: /* (blue) */ - element = EL_CHAR_J; - break; + /* change previous (wrong) gravity inverting special port to either + gravity enabling special port or gravity disabling special port */ + level->field[port_x][port_y] += + (gravity == 1 ? EL_SP_GRAVITY_ON_PORT_RIGHT : + EL_SP_GRAVITY_OFF_PORT_RIGHT) - EL_SP_GRAVITY_PORT_RIGHT; + } - case 0x15b3: /* (blue) */ - element = EL_CHAR_K; - break; + /* change special gravity ports without database entries to normal ports */ + for (x = 0; x < level->fieldx; x++) + for (y = 0; y < level->fieldy; y++) + if (level->field[x][y] >= EL_SP_GRAVITY_PORT_RIGHT && + level->field[x][y] <= EL_SP_GRAVITY_PORT_UP) + level->field[x][y] += EL_SP_PORT_RIGHT - EL_SP_GRAVITY_PORT_RIGHT; - case 0x15b4: /* (blue) */ - element = EL_CHAR_L; - break; + level->time = 0; /* no time limit */ + level->amoeba_speed = 0; + level->time_magic_wall = 0; + level->time_wheel = 0; + level->amoeba_content = EL_EMPTY; - case 0x15b5: /* (blue) */ - element = EL_CHAR_M; - break; +#if 1 + /* original Supaplex does not use score values -- use default values */ +#else + for (i = 0; i < LEVEL_SCORE_ELEMENTS; i++) + level->score[i] = 0; +#endif - case 0x15b6: /* (blue) */ - element = EL_CHAR_N; - break; + /* there are no yamyams in supaplex levels */ + for (i = 0; i < level->num_yamyam_contents; i++) + for (x = 0; x < 3; x++) + for (y = 0; y < 3; y++) + level->yamyam_content[i].e[x][y] = EL_EMPTY; +} - case 0x15b7: /* (blue) */ - element = EL_CHAR_O; - break; +static void CopyNativeTape_RND_to_SP(struct LevelInfo *level) +{ + struct LevelInfo_SP *level_sp = level->native_sp_level; + struct DemoInfo_SP *demo = &level_sp->demo; + int i, j; - case 0x15b8: /* (blue) */ - element = EL_CHAR_P; - break; + /* always start with reliable default values */ + demo->is_available = FALSE; + demo->length = 0; - case 0x15b9: /* (blue) */ - element = EL_CHAR_Q; - break; + if (TAPE_IS_EMPTY(tape)) + return; - case 0x15ba: /* (blue) */ - element = EL_CHAR_R; - break; + demo->level_nr = tape.level_nr; /* (currently not used) */ - case 0x15bb: /* (blue) */ - element = EL_CHAR_S; - break; + level_sp->header.DemoRandomSeed = tape.random_seed; - case 0x15bc: /* (blue) */ - element = EL_CHAR_T; - break; + demo->length = 0; + for (i = 0; i < tape.length; i++) + { + int demo_action = map_key_RND_to_SP(tape.pos[i].action[0]); + int demo_repeat = tape.pos[i].delay; - case 0x15bd: /* (blue) */ - element = EL_CHAR_U; - break; + for (j = 0; j < demo_repeat / 16; j++) + demo->data[demo->length++] = 0xf0 | demo_action; - case 0x15be: /* (blue) */ - element = EL_CHAR_V; - break; + if (demo_repeat % 16) + demo->data[demo->length++] = ((demo_repeat % 16 - 1) << 4) | demo_action; + } - case 0x15bf: /* (blue) */ - element = EL_CHAR_W; - break; + demo->data[demo->length++] = 0xff; - case 0x15c0: /* (blue) */ - element = EL_CHAR_X; - break; + demo->is_available = TRUE; +} - case 0x15c1: /* (blue) */ - element = EL_CHAR_Y; - break; +static void setTapeInfoToDefaults(); - case 0x15c2: /* (blue) */ - element = EL_CHAR_Z; - break; +static void CopyNativeTape_SP_to_RND(struct LevelInfo *level) +{ + struct LevelInfo_SP *level_sp = level->native_sp_level; + struct DemoInfo_SP *demo = &level_sp->demo; + char *filename = level->file_info.filename; + int i; - case 0x15c3: /* (blue) */ - element = EL_CHAR_AUMLAUT; - break; + /* always start with reliable default values */ + setTapeInfoToDefaults(); - case 0x15c4: /* (blue) */ - element = EL_CHAR_OUMLAUT; - break; + if (!demo->is_available) + return; - case 0x15c5: /* (blue) */ - element = EL_CHAR_UUMLAUT; - break; + tape.level_nr = demo->level_nr; /* (currently not used) */ + tape.length = demo->length - 1; /* without "end of demo" byte */ + tape.random_seed = level_sp->header.DemoRandomSeed; - case 0x15c6: /* (blue) */ - element = EL_CHAR_0; - break; + TapeSetDateFromEpochSeconds(getFileTimestampEpochSeconds(filename)); - case 0x15c7: /* (blue) */ - element = EL_CHAR_1; - break; + for (i = 0; i < demo->length - 1; i++) + { + int demo_action = demo->data[i] & 0x0f; + int demo_repeat = (demo->data[i] & 0xf0) >> 4; - case 0x15c8: /* (blue) */ - element = EL_CHAR_2; - break; + tape.pos[i].action[0] = map_key_SP_to_RND(demo_action); + tape.pos[i].delay = demo_repeat + 1; + } - case 0x15c9: /* (blue) */ - element = EL_CHAR_3; - break; + tape.length_seconds = GetTapeLength(); +} - case 0x15ca: /* (blue) */ - element = EL_CHAR_4; - break; - case 0x15cb: /* (blue) */ - element = EL_CHAR_5; - break; +/* ------------------------------------------------------------------------- */ +/* functions for loading DC level */ +/* ------------------------------------------------------------------------- */ - case 0x15cc: /* (blue) */ - element = EL_CHAR_6; - break; +#define DC_LEVEL_HEADER_SIZE 344 - case 0x15cd: /* (blue) */ - element = EL_CHAR_7; - break; +unsigned short getDecodedWord_DC(unsigned short data_encoded, boolean init) +{ + static int last_data_encoded; + static int offset1; + static int offset2; + int diff; + int diff_hi, diff_lo; + int data_hi, data_lo; + unsigned short data_decoded; - case 0x15ce: /* (blue) */ - element = EL_CHAR_8; - break; + if (init) + { + last_data_encoded = 0; + offset1 = -1; + offset2 = 0; - case 0x15cf: /* (blue) */ - element = EL_CHAR_9; - break; + return 0; + } - case 0x15d0: /* (blue) */ - element = EL_CHAR_PERIOD; - break; + diff = data_encoded - last_data_encoded; + diff_hi = diff & ~0xff; + diff_lo = diff & 0xff; - case 0x15d1: /* (blue) */ - element = EL_CHAR_EXCLAM; - break; + offset2 += diff_lo; - case 0x15d2: /* (blue) */ - element = EL_CHAR_COLON; - break; + data_hi = diff_hi - (offset1 << 8) + (offset2 & 0xff00); + data_lo = (diff_lo + (data_hi >> 16)) & 0x00ff; + data_hi = data_hi & 0xff00; - case 0x15d3: /* (blue) */ - element = EL_CHAR_LESS; - break; + data_decoded = data_hi | data_lo; - case 0x15d4: /* (blue) */ - element = EL_CHAR_GREATER; - break; + last_data_encoded = data_encoded; - case 0x15d5: /* (blue) */ - element = EL_CHAR_QUESTION; - break; + offset1 = (offset1 + 1) % 31; + offset2 = offset2 & 0xff; - case 0x15d6: /* (blue) */ - element = EL_CHAR_COPYRIGHT; - break; + return data_decoded; +} - case 0x15d7: /* (blue) */ - element = EL_CHAR_UP; +int getMappedElement_DC(int element) +{ + switch (element) + { + case 0x0000: + element = EL_ROCK; break; - case 0x15d8: /* (blue) */ - element = EL_CHAR_DOWN; - break; + /* 0x0117 - 0x036e: (?) */ + /* EL_DIAMOND */ - case 0x15d9: /* (blue) */ - element = EL_CHAR_BUTTON; - break; + /* 0x042d - 0x0684: (?) */ + /* EL_EMERALD */ - case 0x15da: /* (blue) */ - element = EL_CHAR_PLUS; + case 0x06f1: + element = EL_NUT; break; - case 0x15db: /* (blue) */ - element = EL_CHAR_MINUS; + case 0x074c: + element = EL_BOMB; break; - case 0x15dc: /* (blue) */ - element = EL_CHAR_APOSTROPHE; + case 0x07a4: + element = EL_PEARL; break; - case 0x15dd: /* (blue) */ - element = EL_CHAR_PARENLEFT; + case 0x0823: + element = EL_CRYSTAL; break; - case 0x15de: /* (blue) */ - element = EL_CHAR_PARENRIGHT; + case 0x0e77: /* quicksand (boulder) */ + element = EL_QUICKSAND_FAST_FULL; break; - case 0x15df: /* (green) */ - element = EL_CHAR_A; + case 0x0e99: /* slow quicksand (boulder) */ + element = EL_QUICKSAND_FULL; break; - case 0x15e0: /* (green) */ - element = EL_CHAR_B; + case 0x0ed2: + element = EL_EM_EXIT_OPEN; break; - case 0x15e1: /* (green) */ - element = EL_CHAR_C; + case 0x0ee3: + element = EL_EM_EXIT_CLOSED; break; - case 0x15e2: /* (green) */ - element = EL_CHAR_D; + case 0x0eeb: + element = EL_EM_STEEL_EXIT_OPEN; break; - case 0x15e3: /* (green) */ - element = EL_CHAR_E; + case 0x0efc: + element = EL_EM_STEEL_EXIT_CLOSED; break; - case 0x15e4: /* (green) */ - element = EL_CHAR_F; + case 0x0f4f: /* dynamite (lit 1) */ + element = EL_EM_DYNAMITE_ACTIVE; break; - case 0x15e5: /* (green) */ - element = EL_CHAR_G; + case 0x0f57: /* dynamite (lit 2) */ + element = EL_EM_DYNAMITE_ACTIVE; break; - case 0x15e6: /* (green) */ - element = EL_CHAR_H; + case 0x0f5f: /* dynamite (lit 3) */ + element = EL_EM_DYNAMITE_ACTIVE; break; - case 0x15e7: /* (green) */ - element = EL_CHAR_I; + case 0x0f67: /* dynamite (lit 4) */ + element = EL_EM_DYNAMITE_ACTIVE; break; - case 0x15e8: /* (green) */ - element = EL_CHAR_J; + case 0x0f81: + case 0x0f82: + case 0x0f83: + case 0x0f84: + element = EL_AMOEBA_WET; break; - case 0x15e9: /* (green) */ - element = EL_CHAR_K; + case 0x0f85: + element = EL_AMOEBA_DROP; break; - case 0x15ea: /* (green) */ - element = EL_CHAR_L; + case 0x0fb9: + element = EL_DC_MAGIC_WALL; break; - case 0x15eb: /* (green) */ - element = EL_CHAR_M; + case 0x0fd0: + element = EL_SPACESHIP_UP; break; - case 0x15ec: /* (green) */ - element = EL_CHAR_N; + case 0x0fd9: + element = EL_SPACESHIP_DOWN; break; - case 0x15ed: /* (green) */ - element = EL_CHAR_O; + case 0x0ff1: + element = EL_SPACESHIP_LEFT; break; - case 0x15ee: /* (green) */ - element = EL_CHAR_P; + case 0x0ff9: + element = EL_SPACESHIP_RIGHT; break; - case 0x15ef: /* (green) */ - element = EL_CHAR_Q; + case 0x1057: + element = EL_BUG_UP; break; - case 0x15f0: /* (green) */ - element = EL_CHAR_R; + case 0x1060: + element = EL_BUG_DOWN; break; - case 0x15f1: /* (green) */ - element = EL_CHAR_S; + case 0x1078: + element = EL_BUG_LEFT; break; - case 0x15f2: /* (green) */ - element = EL_CHAR_T; + case 0x1080: + element = EL_BUG_RIGHT; break; - case 0x15f3: /* (green) */ - element = EL_CHAR_U; + case 0x10de: + element = EL_MOLE_UP; break; - case 0x15f4: /* (green) */ - element = EL_CHAR_V; + case 0x10e7: + element = EL_MOLE_DOWN; break; - case 0x15f5: /* (green) */ - element = EL_CHAR_W; + case 0x10ff: + element = EL_MOLE_LEFT; break; - case 0x15f6: /* (green) */ - element = EL_CHAR_X; + case 0x1107: + element = EL_MOLE_RIGHT; break; - case 0x15f7: /* (green) */ - element = EL_CHAR_Y; + case 0x11c0: + element = EL_ROBOT; break; - case 0x15f8: /* (green) */ - element = EL_CHAR_Z; + case 0x13f5: + element = EL_YAMYAM; break; - case 0x15f9: /* (green) */ - element = EL_CHAR_AUMLAUT; + case 0x1425: + element = EL_SWITCHGATE_OPEN; break; - case 0x15fa: /* (green) */ - element = EL_CHAR_OUMLAUT; + case 0x1426: + element = EL_SWITCHGATE_CLOSED; break; - case 0x15fb: /* (green) */ - element = EL_CHAR_UUMLAUT; + case 0x1437: + element = EL_DC_SWITCHGATE_SWITCH_UP; break; - case 0x15fc: /* (green) */ - element = EL_CHAR_0; + case 0x143a: + element = EL_TIMEGATE_CLOSED; break; - case 0x15fd: /* (green) */ - element = EL_CHAR_1; + case 0x144c: /* conveyor belt switch (green) */ + element = EL_CONVEYOR_BELT_3_SWITCH_MIDDLE; break; - case 0x15fe: /* (green) */ - element = EL_CHAR_2; + case 0x144f: /* conveyor belt switch (red) */ + element = EL_CONVEYOR_BELT_1_SWITCH_MIDDLE; break; - case 0x15ff: /* (green) */ - element = EL_CHAR_3; + case 0x1452: /* conveyor belt switch (blue) */ + element = EL_CONVEYOR_BELT_4_SWITCH_MIDDLE; break; - case 0x1600: /* (green) */ - element = EL_CHAR_4; + case 0x145b: + element = EL_CONVEYOR_BELT_3_MIDDLE; break; - case 0x1601: /* (green) */ - element = EL_CHAR_5; + case 0x1463: + element = EL_CONVEYOR_BELT_3_LEFT; break; - case 0x1602: /* (green) */ - element = EL_CHAR_6; + case 0x146b: + element = EL_CONVEYOR_BELT_3_RIGHT; break; - case 0x1603: /* (green) */ - element = EL_CHAR_7; + case 0x1473: + element = EL_CONVEYOR_BELT_1_MIDDLE; break; - case 0x1604: /* (green) */ - element = EL_CHAR_8; + case 0x147b: + element = EL_CONVEYOR_BELT_1_LEFT; break; - case 0x1605: /* (green) */ - element = EL_CHAR_9; + case 0x1483: + element = EL_CONVEYOR_BELT_1_RIGHT; break; - case 0x1606: /* (green) */ - element = EL_CHAR_PERIOD; + case 0x148b: + element = EL_CONVEYOR_BELT_4_MIDDLE; break; - case 0x1607: /* (green) */ - element = EL_CHAR_EXCLAM; + case 0x1493: + element = EL_CONVEYOR_BELT_4_LEFT; break; - case 0x1608: /* (green) */ - element = EL_CHAR_COLON; + case 0x149b: + element = EL_CONVEYOR_BELT_4_RIGHT; break; - case 0x1609: /* (green) */ - element = EL_CHAR_LESS; + case 0x14ac: + element = EL_EXPANDABLE_WALL_HORIZONTAL; break; - case 0x160a: /* (green) */ - element = EL_CHAR_GREATER; + case 0x14bd: + element = EL_EXPANDABLE_WALL_VERTICAL; break; - case 0x160b: /* (green) */ - element = EL_CHAR_QUESTION; + case 0x14c6: + element = EL_EXPANDABLE_WALL_ANY; break; - case 0x160c: /* (green) */ - element = EL_CHAR_COPYRIGHT; + case 0x14ce: /* growing steel wall (left/right) */ + element = EL_EXPANDABLE_STEELWALL_HORIZONTAL; break; - case 0x160d: /* (green) */ - element = EL_CHAR_UP; + case 0x14df: /* growing steel wall (up/down) */ + element = EL_EXPANDABLE_STEELWALL_VERTICAL; break; - case 0x160e: /* (green) */ - element = EL_CHAR_DOWN; + case 0x14e8: /* growing steel wall (up/down/left/right) */ + element = EL_EXPANDABLE_STEELWALL_ANY; break; - case 0x160f: /* (green) */ - element = EL_CHAR_BUTTON; + case 0x14e9: + element = EL_SHIELD_DEADLY; break; - case 0x1610: /* (green) */ - element = EL_CHAR_PLUS; + case 0x1501: + element = EL_EXTRA_TIME; break; - case 0x1611: /* (green) */ - element = EL_CHAR_MINUS; + case 0x154f: + element = EL_ACID; break; - case 0x1612: /* (green) */ - element = EL_CHAR_APOSTROPHE; + case 0x1577: + element = EL_EMPTY_SPACE; break; - case 0x1613: /* (green) */ - element = EL_CHAR_PARENLEFT; + case 0x1578: /* quicksand (empty) */ + element = EL_QUICKSAND_FAST_EMPTY; break; - case 0x1614: /* (green) */ - element = EL_CHAR_PARENRIGHT; + case 0x1579: /* slow quicksand (empty) */ + element = EL_QUICKSAND_EMPTY; break; - case 0x1615: /* (blue steel) */ - element = EL_STEEL_CHAR_A; - break; + /* 0x157c - 0x158b: */ + /* EL_SAND */ + + /* 0x1590 - 0x159f: */ + /* EL_DC_LANDMINE */ - case 0x1616: /* (blue steel) */ - element = EL_STEEL_CHAR_B; + case 0x15a0: + element = EL_EM_DYNAMITE; break; - case 0x1617: /* (blue steel) */ - element = EL_STEEL_CHAR_C; + case 0x15a1: /* key (red) */ + element = EL_EM_KEY_1; break; - case 0x1618: /* (blue steel) */ - element = EL_STEEL_CHAR_D; + case 0x15a2: /* key (yellow) */ + element = EL_EM_KEY_2; break; - case 0x1619: /* (blue steel) */ - element = EL_STEEL_CHAR_E; + case 0x15a3: /* key (blue) */ + element = EL_EM_KEY_4; break; - case 0x161a: /* (blue steel) */ - element = EL_STEEL_CHAR_F; + case 0x15a4: /* key (green) */ + element = EL_EM_KEY_3; break; - case 0x161b: /* (blue steel) */ - element = EL_STEEL_CHAR_G; + case 0x15a5: /* key (white) */ + element = EL_DC_KEY_WHITE; break; - case 0x161c: /* (blue steel) */ - element = EL_STEEL_CHAR_H; + case 0x15a6: + element = EL_WALL_SLIPPERY; break; - case 0x161d: /* (blue steel) */ - element = EL_STEEL_CHAR_I; + case 0x15a7: + element = EL_WALL; break; - case 0x161e: /* (blue steel) */ - element = EL_STEEL_CHAR_J; + case 0x15a8: /* wall (not round) */ + element = EL_WALL; break; - case 0x161f: /* (blue steel) */ - element = EL_STEEL_CHAR_K; + case 0x15a9: /* (blue) */ + element = EL_CHAR_A; break; - case 0x1620: /* (blue steel) */ - element = EL_STEEL_CHAR_L; + case 0x15aa: /* (blue) */ + element = EL_CHAR_B; break; - case 0x1621: /* (blue steel) */ - element = EL_STEEL_CHAR_M; + case 0x15ab: /* (blue) */ + element = EL_CHAR_C; break; - case 0x1622: /* (blue steel) */ - element = EL_STEEL_CHAR_N; + case 0x15ac: /* (blue) */ + element = EL_CHAR_D; break; - case 0x1623: /* (blue steel) */ - element = EL_STEEL_CHAR_O; + case 0x15ad: /* (blue) */ + element = EL_CHAR_E; break; - case 0x1624: /* (blue steel) */ - element = EL_STEEL_CHAR_P; + case 0x15ae: /* (blue) */ + element = EL_CHAR_F; break; - case 0x1625: /* (blue steel) */ - element = EL_STEEL_CHAR_Q; + case 0x15af: /* (blue) */ + element = EL_CHAR_G; break; - case 0x1626: /* (blue steel) */ - element = EL_STEEL_CHAR_R; + case 0x15b0: /* (blue) */ + element = EL_CHAR_H; break; - case 0x1627: /* (blue steel) */ - element = EL_STEEL_CHAR_S; + case 0x15b1: /* (blue) */ + element = EL_CHAR_I; break; - case 0x1628: /* (blue steel) */ - element = EL_STEEL_CHAR_T; + case 0x15b2: /* (blue) */ + element = EL_CHAR_J; break; - case 0x1629: /* (blue steel) */ - element = EL_STEEL_CHAR_U; + case 0x15b3: /* (blue) */ + element = EL_CHAR_K; break; - case 0x162a: /* (blue steel) */ - element = EL_STEEL_CHAR_V; + case 0x15b4: /* (blue) */ + element = EL_CHAR_L; break; - case 0x162b: /* (blue steel) */ - element = EL_STEEL_CHAR_W; + case 0x15b5: /* (blue) */ + element = EL_CHAR_M; break; - case 0x162c: /* (blue steel) */ - element = EL_STEEL_CHAR_X; + case 0x15b6: /* (blue) */ + element = EL_CHAR_N; break; - case 0x162d: /* (blue steel) */ - element = EL_STEEL_CHAR_Y; + case 0x15b7: /* (blue) */ + element = EL_CHAR_O; break; - case 0x162e: /* (blue steel) */ - element = EL_STEEL_CHAR_Z; + case 0x15b8: /* (blue) */ + element = EL_CHAR_P; break; - case 0x162f: /* (blue steel) */ - element = EL_STEEL_CHAR_AUMLAUT; + case 0x15b9: /* (blue) */ + element = EL_CHAR_Q; break; - case 0x1630: /* (blue steel) */ - element = EL_STEEL_CHAR_OUMLAUT; + case 0x15ba: /* (blue) */ + element = EL_CHAR_R; break; - case 0x1631: /* (blue steel) */ - element = EL_STEEL_CHAR_UUMLAUT; + case 0x15bb: /* (blue) */ + element = EL_CHAR_S; break; - case 0x1632: /* (blue steel) */ - element = EL_STEEL_CHAR_0; + case 0x15bc: /* (blue) */ + element = EL_CHAR_T; break; - case 0x1633: /* (blue steel) */ - element = EL_STEEL_CHAR_1; + case 0x15bd: /* (blue) */ + element = EL_CHAR_U; break; - case 0x1634: /* (blue steel) */ - element = EL_STEEL_CHAR_2; + case 0x15be: /* (blue) */ + element = EL_CHAR_V; break; - case 0x1635: /* (blue steel) */ - element = EL_STEEL_CHAR_3; + case 0x15bf: /* (blue) */ + element = EL_CHAR_W; break; - case 0x1636: /* (blue steel) */ - element = EL_STEEL_CHAR_4; + case 0x15c0: /* (blue) */ + element = EL_CHAR_X; break; - case 0x1637: /* (blue steel) */ - element = EL_STEEL_CHAR_5; + case 0x15c1: /* (blue) */ + element = EL_CHAR_Y; break; - case 0x1638: /* (blue steel) */ - element = EL_STEEL_CHAR_6; + case 0x15c2: /* (blue) */ + element = EL_CHAR_Z; break; - case 0x1639: /* (blue steel) */ - element = EL_STEEL_CHAR_7; + case 0x15c3: /* (blue) */ + element = EL_CHAR_AUMLAUT; break; - case 0x163a: /* (blue steel) */ - element = EL_STEEL_CHAR_8; + case 0x15c4: /* (blue) */ + element = EL_CHAR_OUMLAUT; break; - case 0x163b: /* (blue steel) */ - element = EL_STEEL_CHAR_9; + case 0x15c5: /* (blue) */ + element = EL_CHAR_UUMLAUT; break; - case 0x163c: /* (blue steel) */ - element = EL_STEEL_CHAR_PERIOD; + case 0x15c6: /* (blue) */ + element = EL_CHAR_0; break; - case 0x163d: /* (blue steel) */ - element = EL_STEEL_CHAR_EXCLAM; + case 0x15c7: /* (blue) */ + element = EL_CHAR_1; break; - case 0x163e: /* (blue steel) */ - element = EL_STEEL_CHAR_COLON; + case 0x15c8: /* (blue) */ + element = EL_CHAR_2; break; - case 0x163f: /* (blue steel) */ - element = EL_STEEL_CHAR_LESS; + case 0x15c9: /* (blue) */ + element = EL_CHAR_3; break; - case 0x1640: /* (blue steel) */ - element = EL_STEEL_CHAR_GREATER; + case 0x15ca: /* (blue) */ + element = EL_CHAR_4; break; - case 0x1641: /* (blue steel) */ - element = EL_STEEL_CHAR_QUESTION; + case 0x15cb: /* (blue) */ + element = EL_CHAR_5; break; - case 0x1642: /* (blue steel) */ - element = EL_STEEL_CHAR_COPYRIGHT; + case 0x15cc: /* (blue) */ + element = EL_CHAR_6; break; - case 0x1643: /* (blue steel) */ - element = EL_STEEL_CHAR_UP; + case 0x15cd: /* (blue) */ + element = EL_CHAR_7; break; - case 0x1644: /* (blue steel) */ - element = EL_STEEL_CHAR_DOWN; + case 0x15ce: /* (blue) */ + element = EL_CHAR_8; break; - case 0x1645: /* (blue steel) */ - element = EL_STEEL_CHAR_BUTTON; + case 0x15cf: /* (blue) */ + element = EL_CHAR_9; break; - case 0x1646: /* (blue steel) */ - element = EL_STEEL_CHAR_PLUS; + case 0x15d0: /* (blue) */ + element = EL_CHAR_PERIOD; break; - case 0x1647: /* (blue steel) */ - element = EL_STEEL_CHAR_MINUS; + case 0x15d1: /* (blue) */ + element = EL_CHAR_EXCLAM; break; - case 0x1648: /* (blue steel) */ - element = EL_STEEL_CHAR_APOSTROPHE; + case 0x15d2: /* (blue) */ + element = EL_CHAR_COLON; break; - case 0x1649: /* (blue steel) */ - element = EL_STEEL_CHAR_PARENLEFT; + case 0x15d3: /* (blue) */ + element = EL_CHAR_LESS; break; - case 0x164a: /* (blue steel) */ - element = EL_STEEL_CHAR_PARENRIGHT; + case 0x15d4: /* (blue) */ + element = EL_CHAR_GREATER; break; - case 0x164b: /* (green steel) */ - element = EL_STEEL_CHAR_A; + case 0x15d5: /* (blue) */ + element = EL_CHAR_QUESTION; break; - case 0x164c: /* (green steel) */ - element = EL_STEEL_CHAR_B; + case 0x15d6: /* (blue) */ + element = EL_CHAR_COPYRIGHT; break; - case 0x164d: /* (green steel) */ - element = EL_STEEL_CHAR_C; + case 0x15d7: /* (blue) */ + element = EL_CHAR_UP; break; - case 0x164e: /* (green steel) */ - element = EL_STEEL_CHAR_D; + case 0x15d8: /* (blue) */ + element = EL_CHAR_DOWN; break; - case 0x164f: /* (green steel) */ - element = EL_STEEL_CHAR_E; + case 0x15d9: /* (blue) */ + element = EL_CHAR_BUTTON; break; - case 0x1650: /* (green steel) */ - element = EL_STEEL_CHAR_F; + case 0x15da: /* (blue) */ + element = EL_CHAR_PLUS; break; - case 0x1651: /* (green steel) */ - element = EL_STEEL_CHAR_G; + case 0x15db: /* (blue) */ + element = EL_CHAR_MINUS; break; - case 0x1652: /* (green steel) */ - element = EL_STEEL_CHAR_H; + case 0x15dc: /* (blue) */ + element = EL_CHAR_APOSTROPHE; break; - case 0x1653: /* (green steel) */ - element = EL_STEEL_CHAR_I; + case 0x15dd: /* (blue) */ + element = EL_CHAR_PARENLEFT; break; - case 0x1654: /* (green steel) */ - element = EL_STEEL_CHAR_J; + case 0x15de: /* (blue) */ + element = EL_CHAR_PARENRIGHT; break; - case 0x1655: /* (green steel) */ - element = EL_STEEL_CHAR_K; + case 0x15df: /* (green) */ + element = EL_CHAR_A; break; - case 0x1656: /* (green steel) */ - element = EL_STEEL_CHAR_L; + case 0x15e0: /* (green) */ + element = EL_CHAR_B; break; - case 0x1657: /* (green steel) */ - element = EL_STEEL_CHAR_M; + case 0x15e1: /* (green) */ + element = EL_CHAR_C; break; - case 0x1658: /* (green steel) */ - element = EL_STEEL_CHAR_N; + case 0x15e2: /* (green) */ + element = EL_CHAR_D; break; - case 0x1659: /* (green steel) */ - element = EL_STEEL_CHAR_O; + case 0x15e3: /* (green) */ + element = EL_CHAR_E; break; - case 0x165a: /* (green steel) */ - element = EL_STEEL_CHAR_P; + case 0x15e4: /* (green) */ + element = EL_CHAR_F; break; - case 0x165b: /* (green steel) */ - element = EL_STEEL_CHAR_Q; + case 0x15e5: /* (green) */ + element = EL_CHAR_G; break; - case 0x165c: /* (green steel) */ - element = EL_STEEL_CHAR_R; + case 0x15e6: /* (green) */ + element = EL_CHAR_H; break; - case 0x165d: /* (green steel) */ - element = EL_STEEL_CHAR_S; + case 0x15e7: /* (green) */ + element = EL_CHAR_I; break; - case 0x165e: /* (green steel) */ - element = EL_STEEL_CHAR_T; + case 0x15e8: /* (green) */ + element = EL_CHAR_J; break; - case 0x165f: /* (green steel) */ - element = EL_STEEL_CHAR_U; + case 0x15e9: /* (green) */ + element = EL_CHAR_K; break; - case 0x1660: /* (green steel) */ - element = EL_STEEL_CHAR_V; + case 0x15ea: /* (green) */ + element = EL_CHAR_L; break; - case 0x1661: /* (green steel) */ - element = EL_STEEL_CHAR_W; + case 0x15eb: /* (green) */ + element = EL_CHAR_M; break; - case 0x1662: /* (green steel) */ - element = EL_STEEL_CHAR_X; + case 0x15ec: /* (green) */ + element = EL_CHAR_N; break; - case 0x1663: /* (green steel) */ - element = EL_STEEL_CHAR_Y; + case 0x15ed: /* (green) */ + element = EL_CHAR_O; break; - case 0x1664: /* (green steel) */ - element = EL_STEEL_CHAR_Z; + case 0x15ee: /* (green) */ + element = EL_CHAR_P; break; - case 0x1665: /* (green steel) */ - element = EL_STEEL_CHAR_AUMLAUT; + case 0x15ef: /* (green) */ + element = EL_CHAR_Q; break; - case 0x1666: /* (green steel) */ - element = EL_STEEL_CHAR_OUMLAUT; + case 0x15f0: /* (green) */ + element = EL_CHAR_R; break; - case 0x1667: /* (green steel) */ - element = EL_STEEL_CHAR_UUMLAUT; + case 0x15f1: /* (green) */ + element = EL_CHAR_S; break; - case 0x1668: /* (green steel) */ - element = EL_STEEL_CHAR_0; + case 0x15f2: /* (green) */ + element = EL_CHAR_T; break; - case 0x1669: /* (green steel) */ - element = EL_STEEL_CHAR_1; + case 0x15f3: /* (green) */ + element = EL_CHAR_U; break; - case 0x166a: /* (green steel) */ - element = EL_STEEL_CHAR_2; + case 0x15f4: /* (green) */ + element = EL_CHAR_V; break; - case 0x166b: /* (green steel) */ - element = EL_STEEL_CHAR_3; + case 0x15f5: /* (green) */ + element = EL_CHAR_W; break; - case 0x166c: /* (green steel) */ - element = EL_STEEL_CHAR_4; + case 0x15f6: /* (green) */ + element = EL_CHAR_X; break; - case 0x166d: /* (green steel) */ - element = EL_STEEL_CHAR_5; + case 0x15f7: /* (green) */ + element = EL_CHAR_Y; break; - case 0x166e: /* (green steel) */ - element = EL_STEEL_CHAR_6; + case 0x15f8: /* (green) */ + element = EL_CHAR_Z; break; - case 0x166f: /* (green steel) */ - element = EL_STEEL_CHAR_7; + case 0x15f9: /* (green) */ + element = EL_CHAR_AUMLAUT; break; - case 0x1670: /* (green steel) */ - element = EL_STEEL_CHAR_8; + case 0x15fa: /* (green) */ + element = EL_CHAR_OUMLAUT; break; - case 0x1671: /* (green steel) */ - element = EL_STEEL_CHAR_9; + case 0x15fb: /* (green) */ + element = EL_CHAR_UUMLAUT; break; - case 0x1672: /* (green steel) */ - element = EL_STEEL_CHAR_PERIOD; + case 0x15fc: /* (green) */ + element = EL_CHAR_0; break; - case 0x1673: /* (green steel) */ - element = EL_STEEL_CHAR_EXCLAM; + case 0x15fd: /* (green) */ + element = EL_CHAR_1; break; - case 0x1674: /* (green steel) */ - element = EL_STEEL_CHAR_COLON; + case 0x15fe: /* (green) */ + element = EL_CHAR_2; break; - case 0x1675: /* (green steel) */ - element = EL_STEEL_CHAR_LESS; + case 0x15ff: /* (green) */ + element = EL_CHAR_3; break; - case 0x1676: /* (green steel) */ - element = EL_STEEL_CHAR_GREATER; + case 0x1600: /* (green) */ + element = EL_CHAR_4; break; - case 0x1677: /* (green steel) */ - element = EL_STEEL_CHAR_QUESTION; + case 0x1601: /* (green) */ + element = EL_CHAR_5; break; - case 0x1678: /* (green steel) */ - element = EL_STEEL_CHAR_COPYRIGHT; + case 0x1602: /* (green) */ + element = EL_CHAR_6; break; - case 0x1679: /* (green steel) */ - element = EL_STEEL_CHAR_UP; + case 0x1603: /* (green) */ + element = EL_CHAR_7; break; - case 0x167a: /* (green steel) */ - element = EL_STEEL_CHAR_DOWN; + case 0x1604: /* (green) */ + element = EL_CHAR_8; break; - case 0x167b: /* (green steel) */ - element = EL_STEEL_CHAR_BUTTON; + case 0x1605: /* (green) */ + element = EL_CHAR_9; break; - case 0x167c: /* (green steel) */ - element = EL_STEEL_CHAR_PLUS; + case 0x1606: /* (green) */ + element = EL_CHAR_PERIOD; break; - case 0x167d: /* (green steel) */ - element = EL_STEEL_CHAR_MINUS; + case 0x1607: /* (green) */ + element = EL_CHAR_EXCLAM; break; - case 0x167e: /* (green steel) */ - element = EL_STEEL_CHAR_APOSTROPHE; + case 0x1608: /* (green) */ + element = EL_CHAR_COLON; break; - case 0x167f: /* (green steel) */ - element = EL_STEEL_CHAR_PARENLEFT; + case 0x1609: /* (green) */ + element = EL_CHAR_LESS; break; - case 0x1680: /* (green steel) */ - element = EL_STEEL_CHAR_PARENRIGHT; + case 0x160a: /* (green) */ + element = EL_CHAR_GREATER; break; - case 0x1681: /* gate (red) */ - element = EL_EM_GATE_1; + case 0x160b: /* (green) */ + element = EL_CHAR_QUESTION; break; - case 0x1682: /* secret gate (red) */ - element = EL_GATE_1_GRAY; + case 0x160c: /* (green) */ + element = EL_CHAR_COPYRIGHT; break; - case 0x1683: /* gate (yellow) */ - element = EL_EM_GATE_2; + case 0x160d: /* (green) */ + element = EL_CHAR_UP; break; - case 0x1684: /* secret gate (yellow) */ - element = EL_GATE_2_GRAY; + case 0x160e: /* (green) */ + element = EL_CHAR_DOWN; break; - case 0x1685: /* gate (blue) */ - element = EL_EM_GATE_4; + case 0x160f: /* (green) */ + element = EL_CHAR_BUTTON; break; - case 0x1686: /* secret gate (blue) */ - element = EL_GATE_4_GRAY; + case 0x1610: /* (green) */ + element = EL_CHAR_PLUS; break; - case 0x1687: /* gate (green) */ - element = EL_EM_GATE_3; + case 0x1611: /* (green) */ + element = EL_CHAR_MINUS; break; - case 0x1688: /* secret gate (green) */ - element = EL_GATE_3_GRAY; + case 0x1612: /* (green) */ + element = EL_CHAR_APOSTROPHE; break; - case 0x1689: /* gate (white) */ - element = EL_DC_GATE_WHITE; + case 0x1613: /* (green) */ + element = EL_CHAR_PARENLEFT; break; - case 0x168a: /* secret gate (white) */ - element = EL_DC_GATE_WHITE_GRAY; + case 0x1614: /* (green) */ + element = EL_CHAR_PARENRIGHT; break; - case 0x168b: /* secret gate (no key) */ - element = EL_DC_GATE_FAKE_GRAY; + case 0x1615: /* (blue steel) */ + element = EL_STEEL_CHAR_A; break; - case 0x168c: - element = EL_ROBOT_WHEEL; + case 0x1616: /* (blue steel) */ + element = EL_STEEL_CHAR_B; break; - case 0x168d: - element = EL_DC_TIMEGATE_SWITCH; + case 0x1617: /* (blue steel) */ + element = EL_STEEL_CHAR_C; break; - case 0x168e: - element = EL_ACID_POOL_BOTTOM; + case 0x1618: /* (blue steel) */ + element = EL_STEEL_CHAR_D; break; - case 0x168f: - element = EL_ACID_POOL_TOPLEFT; + case 0x1619: /* (blue steel) */ + element = EL_STEEL_CHAR_E; break; - case 0x1690: - element = EL_ACID_POOL_TOPRIGHT; + case 0x161a: /* (blue steel) */ + element = EL_STEEL_CHAR_F; break; - case 0x1691: - element = EL_ACID_POOL_BOTTOMLEFT; + case 0x161b: /* (blue steel) */ + element = EL_STEEL_CHAR_G; break; - case 0x1692: - element = EL_ACID_POOL_BOTTOMRIGHT; + case 0x161c: /* (blue steel) */ + element = EL_STEEL_CHAR_H; break; - case 0x1693: - element = EL_STEELWALL; + case 0x161d: /* (blue steel) */ + element = EL_STEEL_CHAR_I; break; - case 0x1694: - element = EL_STEELWALL_SLIPPERY; + case 0x161e: /* (blue steel) */ + element = EL_STEEL_CHAR_J; break; - case 0x1695: /* steel wall (not round) */ - element = EL_STEELWALL; + case 0x161f: /* (blue steel) */ + element = EL_STEEL_CHAR_K; break; - case 0x1696: /* steel wall (left) */ - element = EL_DC_STEELWALL_1_LEFT; + case 0x1620: /* (blue steel) */ + element = EL_STEEL_CHAR_L; break; - case 0x1697: /* steel wall (bottom) */ - element = EL_DC_STEELWALL_1_BOTTOM; + case 0x1621: /* (blue steel) */ + element = EL_STEEL_CHAR_M; break; - case 0x1698: /* steel wall (right) */ - element = EL_DC_STEELWALL_1_RIGHT; + case 0x1622: /* (blue steel) */ + element = EL_STEEL_CHAR_N; break; - case 0x1699: /* steel wall (top) */ - element = EL_DC_STEELWALL_1_TOP; + case 0x1623: /* (blue steel) */ + element = EL_STEEL_CHAR_O; break; - case 0x169a: /* steel wall (left/bottom) */ - element = EL_DC_STEELWALL_1_BOTTOMLEFT; + case 0x1624: /* (blue steel) */ + element = EL_STEEL_CHAR_P; break; - case 0x169b: /* steel wall (right/bottom) */ - element = EL_DC_STEELWALL_1_BOTTOMRIGHT; + case 0x1625: /* (blue steel) */ + element = EL_STEEL_CHAR_Q; break; - case 0x169c: /* steel wall (right/top) */ - element = EL_DC_STEELWALL_1_TOPRIGHT; + case 0x1626: /* (blue steel) */ + element = EL_STEEL_CHAR_R; break; - case 0x169d: /* steel wall (left/top) */ - element = EL_DC_STEELWALL_1_TOPLEFT; + case 0x1627: /* (blue steel) */ + element = EL_STEEL_CHAR_S; break; - case 0x169e: /* steel wall (right/bottom small) */ - element = EL_DC_STEELWALL_1_BOTTOMRIGHT_2; + case 0x1628: /* (blue steel) */ + element = EL_STEEL_CHAR_T; break; - case 0x169f: /* steel wall (left/bottom small) */ - element = EL_DC_STEELWALL_1_BOTTOMLEFT_2; + case 0x1629: /* (blue steel) */ + element = EL_STEEL_CHAR_U; break; - case 0x16a0: /* steel wall (right/top small) */ - element = EL_DC_STEELWALL_1_TOPRIGHT_2; + case 0x162a: /* (blue steel) */ + element = EL_STEEL_CHAR_V; break; - case 0x16a1: /* steel wall (left/top small) */ - element = EL_DC_STEELWALL_1_TOPLEFT_2; + case 0x162b: /* (blue steel) */ + element = EL_STEEL_CHAR_W; break; - case 0x16a2: /* steel wall (left/right) */ - element = EL_DC_STEELWALL_1_VERTICAL; + case 0x162c: /* (blue steel) */ + element = EL_STEEL_CHAR_X; break; - case 0x16a3: /* steel wall (top/bottom) */ - element = EL_DC_STEELWALL_1_HORIZONTAL; + case 0x162d: /* (blue steel) */ + element = EL_STEEL_CHAR_Y; break; - case 0x16a4: /* steel wall 2 (left end) */ - element = EL_DC_STEELWALL_2_LEFT; + case 0x162e: /* (blue steel) */ + element = EL_STEEL_CHAR_Z; break; - case 0x16a5: /* steel wall 2 (right end) */ - element = EL_DC_STEELWALL_2_RIGHT; + case 0x162f: /* (blue steel) */ + element = EL_STEEL_CHAR_AUMLAUT; break; - case 0x16a6: /* steel wall 2 (top end) */ - element = EL_DC_STEELWALL_2_TOP; + case 0x1630: /* (blue steel) */ + element = EL_STEEL_CHAR_OUMLAUT; break; - case 0x16a7: /* steel wall 2 (bottom end) */ - element = EL_DC_STEELWALL_2_BOTTOM; + case 0x1631: /* (blue steel) */ + element = EL_STEEL_CHAR_UUMLAUT; break; - case 0x16a8: /* steel wall 2 (left/right) */ - element = EL_DC_STEELWALL_2_HORIZONTAL; + case 0x1632: /* (blue steel) */ + element = EL_STEEL_CHAR_0; break; - case 0x16a9: /* steel wall 2 (up/down) */ - element = EL_DC_STEELWALL_2_VERTICAL; + case 0x1633: /* (blue steel) */ + element = EL_STEEL_CHAR_1; break; - case 0x16aa: /* steel wall 2 (mid) */ - element = EL_DC_STEELWALL_2_MIDDLE; + case 0x1634: /* (blue steel) */ + element = EL_STEEL_CHAR_2; break; - case 0x16ab: - element = EL_SIGN_EXCLAMATION; + case 0x1635: /* (blue steel) */ + element = EL_STEEL_CHAR_3; break; - case 0x16ac: - element = EL_SIGN_RADIOACTIVITY; + case 0x1636: /* (blue steel) */ + element = EL_STEEL_CHAR_4; break; - case 0x16ad: - element = EL_SIGN_STOP; + case 0x1637: /* (blue steel) */ + element = EL_STEEL_CHAR_5; break; - case 0x16ae: - element = EL_SIGN_WHEELCHAIR; + case 0x1638: /* (blue steel) */ + element = EL_STEEL_CHAR_6; break; - case 0x16af: - element = EL_SIGN_PARKING; + case 0x1639: /* (blue steel) */ + element = EL_STEEL_CHAR_7; break; - case 0x16b0: - element = EL_SIGN_NO_ENTRY; + case 0x163a: /* (blue steel) */ + element = EL_STEEL_CHAR_8; break; - case 0x16b1: - element = EL_SIGN_HEART; + case 0x163b: /* (blue steel) */ + element = EL_STEEL_CHAR_9; break; - case 0x16b2: - element = EL_SIGN_GIVE_WAY; + case 0x163c: /* (blue steel) */ + element = EL_STEEL_CHAR_PERIOD; break; - case 0x16b3: - element = EL_SIGN_ENTRY_FORBIDDEN; + case 0x163d: /* (blue steel) */ + element = EL_STEEL_CHAR_EXCLAM; break; - case 0x16b4: - element = EL_SIGN_EMERGENCY_EXIT; + case 0x163e: /* (blue steel) */ + element = EL_STEEL_CHAR_COLON; break; - case 0x16b5: - element = EL_SIGN_YIN_YANG; + case 0x163f: /* (blue steel) */ + element = EL_STEEL_CHAR_LESS; break; - case 0x16b6: - element = EL_WALL_EMERALD; + case 0x1640: /* (blue steel) */ + element = EL_STEEL_CHAR_GREATER; break; - case 0x16b7: - element = EL_WALL_DIAMOND; + case 0x1641: /* (blue steel) */ + element = EL_STEEL_CHAR_QUESTION; break; - case 0x16b8: - element = EL_WALL_PEARL; + case 0x1642: /* (blue steel) */ + element = EL_STEEL_CHAR_COPYRIGHT; break; - case 0x16b9: - element = EL_WALL_CRYSTAL; + case 0x1643: /* (blue steel) */ + element = EL_STEEL_CHAR_UP; break; - case 0x16ba: - element = EL_INVISIBLE_WALL; + case 0x1644: /* (blue steel) */ + element = EL_STEEL_CHAR_DOWN; break; - case 0x16bb: - element = EL_INVISIBLE_STEELWALL; + case 0x1645: /* (blue steel) */ + element = EL_STEEL_CHAR_BUTTON; break; - /* 0x16bc - 0x16cb: */ - /* EL_INVISIBLE_SAND */ - - case 0x16cc: - element = EL_LIGHT_SWITCH; + case 0x1646: /* (blue steel) */ + element = EL_STEEL_CHAR_PLUS; break; - case 0x16cd: - element = EL_ENVELOPE_1; + case 0x1647: /* (blue steel) */ + element = EL_STEEL_CHAR_MINUS; break; - default: - if (element >= 0x0117 && element <= 0x036e) /* (?) */ - element = EL_DIAMOND; - else if (element >= 0x042d && element <= 0x0684) /* (?) */ - element = EL_EMERALD; - else if (element >= 0x157c && element <= 0x158b) - element = EL_SAND; - else if (element >= 0x1590 && element <= 0x159f) - element = EL_DC_LANDMINE; - else if (element >= 0x16bc && element <= 0x16cb) - element = EL_INVISIBLE_SAND; - else - { - Error(ERR_WARN, "unknown Diamond Caves element 0x%04x", element); - element = EL_UNKNOWN; - } + case 0x1648: /* (blue steel) */ + element = EL_STEEL_CHAR_APOSTROPHE; break; - } - return getMappedElement(element); -} + case 0x1649: /* (blue steel) */ + element = EL_STEEL_CHAR_PARENLEFT; + break; -#if 1 + case 0x164a: /* (blue steel) */ + element = EL_STEEL_CHAR_PARENRIGHT; + break; -#if 1 + case 0x164b: /* (green steel) */ + element = EL_STEEL_CHAR_A; + break; -static void LoadLevelFromFileStream_DC(File *file, struct LevelInfo *level, - int nr) -{ - byte header[DC_LEVEL_HEADER_SIZE]; - int envelope_size; - int envelope_header_pos = 62; - int envelope_content_pos = 94; - int level_name_pos = 251; - int level_author_pos = 292; - int envelope_header_len; - int envelope_content_len; - int level_name_len; - int level_author_len; - int fieldx, fieldy; - int num_yamyam_contents; - int i, x, y; + case 0x164c: /* (green steel) */ + element = EL_STEEL_CHAR_B; + break; - getDecodedWord_DC(0, TRUE); /* initialize DC2 decoding engine */ + case 0x164d: /* (green steel) */ + element = EL_STEEL_CHAR_C; + break; - for (i = 0; i < DC_LEVEL_HEADER_SIZE / 2; i++) - { - unsigned short header_word = getDecodedWord_DC(getFile16BitBE(file), FALSE); + case 0x164e: /* (green steel) */ + element = EL_STEEL_CHAR_D; + break; - header[i * 2 + 0] = header_word >> 8; - header[i * 2 + 1] = header_word & 0xff; - } + case 0x164f: /* (green steel) */ + element = EL_STEEL_CHAR_E; + break; - /* read some values from level header to check level decoding integrity */ - fieldx = header[6] | (header[7] << 8); - fieldy = header[8] | (header[9] << 8); - num_yamyam_contents = header[60] | (header[61] << 8); + case 0x1650: /* (green steel) */ + element = EL_STEEL_CHAR_F; + break; - /* do some simple sanity checks to ensure that level was correctly decoded */ - if (fieldx < 1 || fieldx > 256 || - fieldy < 1 || fieldy > 256 || - num_yamyam_contents < 1 || num_yamyam_contents > 8) - { - level->no_valid_file = TRUE; + case 0x1651: /* (green steel) */ + element = EL_STEEL_CHAR_G; + break; - Error(ERR_WARN, "cannot decode level from stream -- using empty level"); + case 0x1652: /* (green steel) */ + element = EL_STEEL_CHAR_H; + break; - return; - } + case 0x1653: /* (green steel) */ + element = EL_STEEL_CHAR_I; + break; - /* maximum envelope header size is 31 bytes */ - envelope_header_len = header[envelope_header_pos]; - /* maximum envelope content size is 110 (156?) bytes */ - envelope_content_len = header[envelope_content_pos]; + case 0x1654: /* (green steel) */ + element = EL_STEEL_CHAR_J; + break; - /* maximum level title size is 40 bytes */ - level_name_len = MIN(header[level_name_pos], MAX_LEVEL_NAME_LEN); - /* maximum level author size is 30 (51?) bytes */ - level_author_len = MIN(header[level_author_pos], MAX_LEVEL_AUTHOR_LEN); + case 0x1655: /* (green steel) */ + element = EL_STEEL_CHAR_K; + break; - envelope_size = 0; + case 0x1656: /* (green steel) */ + element = EL_STEEL_CHAR_L; + break; - for (i = 0; i < envelope_header_len; i++) - if (envelope_size < MAX_ENVELOPE_TEXT_LEN) - level->envelope[0].text[envelope_size++] = - header[envelope_header_pos + 1 + i]; + case 0x1657: /* (green steel) */ + element = EL_STEEL_CHAR_M; + break; - if (envelope_header_len > 0 && envelope_content_len > 0) - { - if (envelope_size < MAX_ENVELOPE_TEXT_LEN) - level->envelope[0].text[envelope_size++] = '\n'; - if (envelope_size < MAX_ENVELOPE_TEXT_LEN) - level->envelope[0].text[envelope_size++] = '\n'; - } + case 0x1658: /* (green steel) */ + element = EL_STEEL_CHAR_N; + break; - for (i = 0; i < envelope_content_len; i++) - if (envelope_size < MAX_ENVELOPE_TEXT_LEN) - level->envelope[0].text[envelope_size++] = - header[envelope_content_pos + 1 + i]; + case 0x1659: /* (green steel) */ + element = EL_STEEL_CHAR_O; + break; - level->envelope[0].text[envelope_size] = '\0'; + case 0x165a: /* (green steel) */ + element = EL_STEEL_CHAR_P; + break; - level->envelope[0].xsize = MAX_ENVELOPE_XSIZE; - level->envelope[0].ysize = 10; - level->envelope[0].autowrap = TRUE; - level->envelope[0].centered = TRUE; + case 0x165b: /* (green steel) */ + element = EL_STEEL_CHAR_Q; + break; - for (i = 0; i < level_name_len; i++) - level->name[i] = header[level_name_pos + 1 + i]; - level->name[level_name_len] = '\0'; + case 0x165c: /* (green steel) */ + element = EL_STEEL_CHAR_R; + break; - for (i = 0; i < level_author_len; i++) - level->author[i] = header[level_author_pos + 1 + i]; - level->author[level_author_len] = '\0'; + case 0x165d: /* (green steel) */ + element = EL_STEEL_CHAR_S; + break; - num_yamyam_contents = header[60] | (header[61] << 8); - level->num_yamyam_contents = - MIN(MAX(MIN_ELEMENT_CONTENTS, num_yamyam_contents), MAX_ELEMENT_CONTENTS); + case 0x165e: /* (green steel) */ + element = EL_STEEL_CHAR_T; + break; - for (i = 0; i < num_yamyam_contents; i++) - { - for (y = 0; y < 3; y++) for (x = 0; x < 3; x++) - { - unsigned short word = getDecodedWord_DC(getFile16BitBE(file), FALSE); -#if 1 - int element_dc = ((word & 0xff) << 8) | ((word >> 8) & 0xff); -#else - int element_dc = word; -#endif + case 0x165f: /* (green steel) */ + element = EL_STEEL_CHAR_U; + break; - if (i < MAX_ELEMENT_CONTENTS) - level->yamyam_content[i].e[x][y] = getMappedElement_DC(element_dc); - } - } + case 0x1660: /* (green steel) */ + element = EL_STEEL_CHAR_V; + break; - fieldx = header[6] | (header[7] << 8); - fieldy = header[8] | (header[9] << 8); - level->fieldx = MIN(MAX(MIN_LEV_FIELDX, fieldx), MAX_LEV_FIELDX); - level->fieldy = MIN(MAX(MIN_LEV_FIELDY, fieldy), MAX_LEV_FIELDY); + case 0x1661: /* (green steel) */ + element = EL_STEEL_CHAR_W; + break; - for (y = 0; y < fieldy; y++) for (x = 0; x < fieldx; x++) - { - unsigned short word = getDecodedWord_DC(getFile16BitBE(file), FALSE); -#if 1 - int element_dc = ((word & 0xff) << 8) | ((word >> 8) & 0xff); -#else - int element_dc = word; -#endif + case 0x1662: /* (green steel) */ + element = EL_STEEL_CHAR_X; + break; - if (x < MAX_LEV_FIELDX && y < MAX_LEV_FIELDY) - level->field[x][y] = getMappedElement_DC(element_dc); - } + case 0x1663: /* (green steel) */ + element = EL_STEEL_CHAR_Y; + break; - x = MIN(MAX(0, (header[10] | (header[11] << 8)) - 1), MAX_LEV_FIELDX - 1); - y = MIN(MAX(0, (header[12] | (header[13] << 8)) - 1), MAX_LEV_FIELDY - 1); - level->field[x][y] = EL_PLAYER_1; + case 0x1664: /* (green steel) */ + element = EL_STEEL_CHAR_Z; + break; - x = MIN(MAX(0, (header[14] | (header[15] << 8)) - 1), MAX_LEV_FIELDX - 1); - y = MIN(MAX(0, (header[16] | (header[17] << 8)) - 1), MAX_LEV_FIELDY - 1); - level->field[x][y] = EL_PLAYER_2; + case 0x1665: /* (green steel) */ + element = EL_STEEL_CHAR_AUMLAUT; + break; - level->gems_needed = header[18] | (header[19] << 8); + case 0x1666: /* (green steel) */ + element = EL_STEEL_CHAR_OUMLAUT; + break; - level->score[SC_EMERALD] = header[20] | (header[21] << 8); - level->score[SC_DIAMOND] = header[22] | (header[23] << 8); - level->score[SC_PEARL] = header[24] | (header[25] << 8); - level->score[SC_CRYSTAL] = header[26] | (header[27] << 8); - level->score[SC_NUT] = header[28] | (header[29] << 8); - level->score[SC_ROBOT] = header[30] | (header[31] << 8); - level->score[SC_SPACESHIP] = header[32] | (header[33] << 8); - level->score[SC_BUG] = header[34] | (header[35] << 8); - level->score[SC_YAMYAM] = header[36] | (header[37] << 8); - level->score[SC_DYNAMITE] = header[38] | (header[39] << 8); - level->score[SC_KEY] = header[40] | (header[41] << 8); - level->score[SC_TIME_BONUS] = header[42] | (header[43] << 8); + case 0x1667: /* (green steel) */ + element = EL_STEEL_CHAR_UUMLAUT; + break; - level->time = header[44] | (header[45] << 8); + case 0x1668: /* (green steel) */ + element = EL_STEEL_CHAR_0; + break; - level->amoeba_speed = header[46] | (header[47] << 8); - level->time_light = header[48] | (header[49] << 8); - level->time_timegate = header[50] | (header[51] << 8); - level->time_wheel = header[52] | (header[53] << 8); - level->time_magic_wall = header[54] | (header[55] << 8); - level->extra_time = header[56] | (header[57] << 8); - level->shield_normal_time = header[58] | (header[59] << 8); + case 0x1669: /* (green steel) */ + element = EL_STEEL_CHAR_1; + break; - /* Diamond Caves has the same (strange) behaviour as Emerald Mine that gems - can slip down from flat walls, like normal walls and steel walls */ - level->em_slippery_gems = TRUE; + case 0x166a: /* (green steel) */ + element = EL_STEEL_CHAR_2; + break; -#if 0 - /* Diamond Caves II levels are always surrounded by indestructible wall, but - not necessarily in a rectangular way -- fill with invisible steel wall */ + case 0x166b: /* (green steel) */ + element = EL_STEEL_CHAR_3; + break; - /* !!! not always true !!! keep level and set BorderElement instead !!! */ + case 0x166c: /* (green steel) */ + element = EL_STEEL_CHAR_4; + break; - for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++) - { -#if 1 - if ((x == 0 || x == level->fieldx - 1 || - y == 0 || y == level->fieldy - 1) && - level->field[x][y] == EL_EMPTY) - level->field[x][y] = EL_INVISIBLE_STEELWALL; -#else - if ((x == 0 || x == level->fieldx - 1 || - y == 0 || y == level->fieldy - 1) && - level->field[x][y] == EL_EMPTY) - FloodFillLevel(x, y, EL_INVISIBLE_STEELWALL, - level->field, level->fieldx, level->fieldy); -#endif - } -#endif -} + case 0x166d: /* (green steel) */ + element = EL_STEEL_CHAR_5; + break; -static void LoadLevelFromFileInfo_DC(struct LevelInfo *level, - struct LevelFileInfo *level_file_info, - boolean level_info_only) -{ - char *filename = level_file_info->filename; - File *file; - int num_magic_bytes = 8; - char magic_bytes[num_magic_bytes + 1]; - int num_levels_to_skip = level_file_info->nr - leveldir_current->first_level; + case 0x166e: /* (green steel) */ + element = EL_STEEL_CHAR_6; + break; - if (!(file = openFile(filename, MODE_READ))) - { - level->no_valid_file = TRUE; + case 0x166f: /* (green steel) */ + element = EL_STEEL_CHAR_7; + break; - if (!level_info_only) - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); + case 0x1670: /* (green steel) */ + element = EL_STEEL_CHAR_8; + break; - return; - } + case 0x1671: /* (green steel) */ + element = EL_STEEL_CHAR_9; + break; - // fseek(file, 0x0000, SEEK_SET); + case 0x1672: /* (green steel) */ + element = EL_STEEL_CHAR_PERIOD; + break; - if (level_file_info->packed) - { - /* read "magic bytes" from start of file */ - if (getStringFromFile(file, magic_bytes, num_magic_bytes + 1) == NULL) - magic_bytes[0] = '\0'; + case 0x1673: /* (green steel) */ + element = EL_STEEL_CHAR_EXCLAM; + break; - /* check "magic bytes" for correct file format */ - if (!strPrefix(magic_bytes, "DC2")) - { - level->no_valid_file = TRUE; + case 0x1674: /* (green steel) */ + element = EL_STEEL_CHAR_COLON; + break; - Error(ERR_WARN, "unknown DC level file '%s' -- using empty level", - filename); + case 0x1675: /* (green steel) */ + element = EL_STEEL_CHAR_LESS; + break; - return; - } + case 0x1676: /* (green steel) */ + element = EL_STEEL_CHAR_GREATER; + break; - if (strPrefix(magic_bytes, "DC2Win95") || - strPrefix(magic_bytes, "DC2Win98")) - { - int position_first_level = 0x00fa; - int extra_bytes = 4; - int skip_bytes; + case 0x1677: /* (green steel) */ + element = EL_STEEL_CHAR_QUESTION; + break; + + case 0x1678: /* (green steel) */ + element = EL_STEEL_CHAR_COPYRIGHT; + break; - /* advance file stream to first level inside the level package */ - skip_bytes = position_first_level - num_magic_bytes - extra_bytes; + case 0x1679: /* (green steel) */ + element = EL_STEEL_CHAR_UP; + break; - /* each block of level data is followed by block of non-level data */ - num_levels_to_skip *= 2; + case 0x167a: /* (green steel) */ + element = EL_STEEL_CHAR_DOWN; + break; - /* at least skip header bytes, therefore use ">= 0" instead of "> 0" */ - while (num_levels_to_skip >= 0) - { - /* advance file stream to next level inside the level package */ - if (seekFile(file, skip_bytes, SEEK_CUR) != 0) - { - level->no_valid_file = TRUE; + case 0x167b: /* (green steel) */ + element = EL_STEEL_CHAR_BUTTON; + break; - Error(ERR_WARN, "cannot fseek in file '%s' -- using empty level", - filename); + case 0x167c: /* (green steel) */ + element = EL_STEEL_CHAR_PLUS; + break; - return; - } + case 0x167d: /* (green steel) */ + element = EL_STEEL_CHAR_MINUS; + break; - /* skip apparently unused extra bytes following each level */ - ReadUnusedBytesFromFile(file, extra_bytes); + case 0x167e: /* (green steel) */ + element = EL_STEEL_CHAR_APOSTROPHE; + break; - /* read size of next level in level package */ - skip_bytes = getFile32BitLE(file); + case 0x167f: /* (green steel) */ + element = EL_STEEL_CHAR_PARENLEFT; + break; - num_levels_to_skip--; - } - } - else - { - level->no_valid_file = TRUE; + case 0x1680: /* (green steel) */ + element = EL_STEEL_CHAR_PARENRIGHT; + break; - Error(ERR_WARN, "unknown DC2 level file '%s' -- using empty level", - filename); + case 0x1681: /* gate (red) */ + element = EL_EM_GATE_1; + break; - return; - } - } + case 0x1682: /* secret gate (red) */ + element = EL_GATE_1_GRAY; + break; - LoadLevelFromFileStream_DC(file, level, level_file_info->nr); + case 0x1683: /* gate (yellow) */ + element = EL_EM_GATE_2; + break; - closeFile(file); -} + case 0x1684: /* secret gate (yellow) */ + element = EL_GATE_2_GRAY; + break; -#else + case 0x1685: /* gate (blue) */ + element = EL_EM_GATE_4; + break; -static void LoadLevelFromFileStream_DC(FILE *file, struct LevelInfo *level, - int nr) -{ - byte header[DC_LEVEL_HEADER_SIZE]; - int envelope_size; - int envelope_header_pos = 62; - int envelope_content_pos = 94; - int level_name_pos = 251; - int level_author_pos = 292; - int envelope_header_len; - int envelope_content_len; - int level_name_len; - int level_author_len; - int fieldx, fieldy; - int num_yamyam_contents; - int i, x, y; + case 0x1686: /* secret gate (blue) */ + element = EL_GATE_4_GRAY; + break; - getDecodedWord_DC(0, TRUE); /* initialize DC2 decoding engine */ + case 0x1687: /* gate (green) */ + element = EL_EM_GATE_3; + break; - for (i = 0; i < DC_LEVEL_HEADER_SIZE / 2; i++) - { - unsigned short header_word = getDecodedWord_DC(getFile16BitBE(file), FALSE); + case 0x1688: /* secret gate (green) */ + element = EL_GATE_3_GRAY; + break; - header[i * 2 + 0] = header_word >> 8; - header[i * 2 + 1] = header_word & 0xff; - } + case 0x1689: /* gate (white) */ + element = EL_DC_GATE_WHITE; + break; - /* read some values from level header to check level decoding integrity */ - fieldx = header[6] | (header[7] << 8); - fieldy = header[8] | (header[9] << 8); - num_yamyam_contents = header[60] | (header[61] << 8); + case 0x168a: /* secret gate (white) */ + element = EL_DC_GATE_WHITE_GRAY; + break; - /* do some simple sanity checks to ensure that level was correctly decoded */ - if (fieldx < 1 || fieldx > 256 || - fieldy < 1 || fieldy > 256 || - num_yamyam_contents < 1 || num_yamyam_contents > 8) - { - level->no_valid_file = TRUE; + case 0x168b: /* secret gate (no key) */ + element = EL_DC_GATE_FAKE_GRAY; + break; - Error(ERR_WARN, "cannot decode level from stream -- using empty level"); + case 0x168c: + element = EL_ROBOT_WHEEL; + break; - return; - } + case 0x168d: + element = EL_DC_TIMEGATE_SWITCH; + break; - /* maximum envelope header size is 31 bytes */ - envelope_header_len = header[envelope_header_pos]; - /* maximum envelope content size is 110 (156?) bytes */ - envelope_content_len = header[envelope_content_pos]; + case 0x168e: + element = EL_ACID_POOL_BOTTOM; + break; - /* maximum level title size is 40 bytes */ - level_name_len = MIN(header[level_name_pos], MAX_LEVEL_NAME_LEN); - /* maximum level author size is 30 (51?) bytes */ - level_author_len = MIN(header[level_author_pos], MAX_LEVEL_AUTHOR_LEN); + case 0x168f: + element = EL_ACID_POOL_TOPLEFT; + break; - envelope_size = 0; + case 0x1690: + element = EL_ACID_POOL_TOPRIGHT; + break; - for (i = 0; i < envelope_header_len; i++) - if (envelope_size < MAX_ENVELOPE_TEXT_LEN) - level->envelope[0].text[envelope_size++] = - header[envelope_header_pos + 1 + i]; + case 0x1691: + element = EL_ACID_POOL_BOTTOMLEFT; + break; - if (envelope_header_len > 0 && envelope_content_len > 0) - { - if (envelope_size < MAX_ENVELOPE_TEXT_LEN) - level->envelope[0].text[envelope_size++] = '\n'; - if (envelope_size < MAX_ENVELOPE_TEXT_LEN) - level->envelope[0].text[envelope_size++] = '\n'; - } + case 0x1692: + element = EL_ACID_POOL_BOTTOMRIGHT; + break; - for (i = 0; i < envelope_content_len; i++) - if (envelope_size < MAX_ENVELOPE_TEXT_LEN) - level->envelope[0].text[envelope_size++] = - header[envelope_content_pos + 1 + i]; + case 0x1693: + element = EL_STEELWALL; + break; - level->envelope[0].text[envelope_size] = '\0'; + case 0x1694: + element = EL_STEELWALL_SLIPPERY; + break; - level->envelope[0].xsize = MAX_ENVELOPE_XSIZE; - level->envelope[0].ysize = 10; - level->envelope[0].autowrap = TRUE; - level->envelope[0].centered = TRUE; + case 0x1695: /* steel wall (not round) */ + element = EL_STEELWALL; + break; - for (i = 0; i < level_name_len; i++) - level->name[i] = header[level_name_pos + 1 + i]; - level->name[level_name_len] = '\0'; + case 0x1696: /* steel wall (left) */ + element = EL_DC_STEELWALL_1_LEFT; + break; - for (i = 0; i < level_author_len; i++) - level->author[i] = header[level_author_pos + 1 + i]; - level->author[level_author_len] = '\0'; + case 0x1697: /* steel wall (bottom) */ + element = EL_DC_STEELWALL_1_BOTTOM; + break; - num_yamyam_contents = header[60] | (header[61] << 8); - level->num_yamyam_contents = - MIN(MAX(MIN_ELEMENT_CONTENTS, num_yamyam_contents), MAX_ELEMENT_CONTENTS); + case 0x1698: /* steel wall (right) */ + element = EL_DC_STEELWALL_1_RIGHT; + break; - for (i = 0; i < num_yamyam_contents; i++) - { - for (y = 0; y < 3; y++) for (x = 0; x < 3; x++) - { - unsigned short word = getDecodedWord_DC(getFile16BitBE(file), FALSE); -#if 1 - int element_dc = ((word & 0xff) << 8) | ((word >> 8) & 0xff); -#else - int element_dc = word; -#endif + case 0x1699: /* steel wall (top) */ + element = EL_DC_STEELWALL_1_TOP; + break; - if (i < MAX_ELEMENT_CONTENTS) - level->yamyam_content[i].e[x][y] = getMappedElement_DC(element_dc); - } - } + case 0x169a: /* steel wall (left/bottom) */ + element = EL_DC_STEELWALL_1_BOTTOMLEFT; + break; - fieldx = header[6] | (header[7] << 8); - fieldy = header[8] | (header[9] << 8); - level->fieldx = MIN(MAX(MIN_LEV_FIELDX, fieldx), MAX_LEV_FIELDX); - level->fieldy = MIN(MAX(MIN_LEV_FIELDY, fieldy), MAX_LEV_FIELDY); + case 0x169b: /* steel wall (right/bottom) */ + element = EL_DC_STEELWALL_1_BOTTOMRIGHT; + break; - for (y = 0; y < fieldy; y++) for (x = 0; x < fieldx; x++) - { - unsigned short word = getDecodedWord_DC(getFile16BitBE(file), FALSE); -#if 1 - int element_dc = ((word & 0xff) << 8) | ((word >> 8) & 0xff); -#else - int element_dc = word; -#endif + case 0x169c: /* steel wall (right/top) */ + element = EL_DC_STEELWALL_1_TOPRIGHT; + break; - if (x < MAX_LEV_FIELDX && y < MAX_LEV_FIELDY) - level->field[x][y] = getMappedElement_DC(element_dc); - } + case 0x169d: /* steel wall (left/top) */ + element = EL_DC_STEELWALL_1_TOPLEFT; + break; - x = MIN(MAX(0, (header[10] | (header[11] << 8)) - 1), MAX_LEV_FIELDX - 1); - y = MIN(MAX(0, (header[12] | (header[13] << 8)) - 1), MAX_LEV_FIELDY - 1); - level->field[x][y] = EL_PLAYER_1; + case 0x169e: /* steel wall (right/bottom small) */ + element = EL_DC_STEELWALL_1_BOTTOMRIGHT_2; + break; + + case 0x169f: /* steel wall (left/bottom small) */ + element = EL_DC_STEELWALL_1_BOTTOMLEFT_2; + break; - x = MIN(MAX(0, (header[14] | (header[15] << 8)) - 1), MAX_LEV_FIELDX - 1); - y = MIN(MAX(0, (header[16] | (header[17] << 8)) - 1), MAX_LEV_FIELDY - 1); - level->field[x][y] = EL_PLAYER_2; + case 0x16a0: /* steel wall (right/top small) */ + element = EL_DC_STEELWALL_1_TOPRIGHT_2; + break; - level->gems_needed = header[18] | (header[19] << 8); + case 0x16a1: /* steel wall (left/top small) */ + element = EL_DC_STEELWALL_1_TOPLEFT_2; + break; - level->score[SC_EMERALD] = header[20] | (header[21] << 8); - level->score[SC_DIAMOND] = header[22] | (header[23] << 8); - level->score[SC_PEARL] = header[24] | (header[25] << 8); - level->score[SC_CRYSTAL] = header[26] | (header[27] << 8); - level->score[SC_NUT] = header[28] | (header[29] << 8); - level->score[SC_ROBOT] = header[30] | (header[31] << 8); - level->score[SC_SPACESHIP] = header[32] | (header[33] << 8); - level->score[SC_BUG] = header[34] | (header[35] << 8); - level->score[SC_YAMYAM] = header[36] | (header[37] << 8); - level->score[SC_DYNAMITE] = header[38] | (header[39] << 8); - level->score[SC_KEY] = header[40] | (header[41] << 8); - level->score[SC_TIME_BONUS] = header[42] | (header[43] << 8); + case 0x16a2: /* steel wall (left/right) */ + element = EL_DC_STEELWALL_1_VERTICAL; + break; - level->time = header[44] | (header[45] << 8); + case 0x16a3: /* steel wall (top/bottom) */ + element = EL_DC_STEELWALL_1_HORIZONTAL; + break; - level->amoeba_speed = header[46] | (header[47] << 8); - level->time_light = header[48] | (header[49] << 8); - level->time_timegate = header[50] | (header[51] << 8); - level->time_wheel = header[52] | (header[53] << 8); - level->time_magic_wall = header[54] | (header[55] << 8); - level->extra_time = header[56] | (header[57] << 8); - level->shield_normal_time = header[58] | (header[59] << 8); + case 0x16a4: /* steel wall 2 (left end) */ + element = EL_DC_STEELWALL_2_LEFT; + break; - /* Diamond Caves has the same (strange) behaviour as Emerald Mine that gems - can slip down from flat walls, like normal walls and steel walls */ - level->em_slippery_gems = TRUE; + case 0x16a5: /* steel wall 2 (right end) */ + element = EL_DC_STEELWALL_2_RIGHT; + break; -#if 0 - /* Diamond Caves II levels are always surrounded by indestructible wall, but - not necessarily in a rectangular way -- fill with invisible steel wall */ + case 0x16a6: /* steel wall 2 (top end) */ + element = EL_DC_STEELWALL_2_TOP; + break; - /* !!! not always true !!! keep level and set BorderElement instead !!! */ + case 0x16a7: /* steel wall 2 (bottom end) */ + element = EL_DC_STEELWALL_2_BOTTOM; + break; - for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++) - { -#if 1 - if ((x == 0 || x == level->fieldx - 1 || - y == 0 || y == level->fieldy - 1) && - level->field[x][y] == EL_EMPTY) - level->field[x][y] = EL_INVISIBLE_STEELWALL; -#else - if ((x == 0 || x == level->fieldx - 1 || - y == 0 || y == level->fieldy - 1) && - level->field[x][y] == EL_EMPTY) - FloodFillLevel(x, y, EL_INVISIBLE_STEELWALL, - level->field, level->fieldx, level->fieldy); -#endif - } -#endif -} + case 0x16a8: /* steel wall 2 (left/right) */ + element = EL_DC_STEELWALL_2_HORIZONTAL; + break; -static void LoadLevelFromFileInfo_DC(struct LevelInfo *level, - struct LevelFileInfo *level_file_info, - boolean level_info_only) -{ - char *filename = level_file_info->filename; - FILE *file; - int num_magic_bytes = 8; - char magic_bytes[num_magic_bytes + 1]; - int num_levels_to_skip = level_file_info->nr - leveldir_current->first_level; + case 0x16a9: /* steel wall 2 (up/down) */ + element = EL_DC_STEELWALL_2_VERTICAL; + break; - if (!(file = fopen(filename, MODE_READ))) - { - level->no_valid_file = TRUE; + case 0x16aa: /* steel wall 2 (mid) */ + element = EL_DC_STEELWALL_2_MIDDLE; + break; - if (!level_info_only) - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); + case 0x16ab: + element = EL_SIGN_EXCLAMATION; + break; - return; - } + case 0x16ac: + element = EL_SIGN_RADIOACTIVITY; + break; - // fseek(file, 0x0000, SEEK_SET); + case 0x16ad: + element = EL_SIGN_STOP; + break; - if (level_file_info->packed) - { - /* read "magic bytes" from start of file */ - if (fgets(magic_bytes, num_magic_bytes + 1, file) == NULL) - magic_bytes[0] = '\0'; + case 0x16ae: + element = EL_SIGN_WHEELCHAIR; + break; - /* check "magic bytes" for correct file format */ - if (!strPrefix(magic_bytes, "DC2")) - { - level->no_valid_file = TRUE; + case 0x16af: + element = EL_SIGN_PARKING; + break; - Error(ERR_WARN, "unknown DC level file '%s' -- using empty level", - filename); + case 0x16b0: + element = EL_SIGN_NO_ENTRY; + break; - return; - } + case 0x16b1: + element = EL_SIGN_HEART; + break; - if (strPrefix(magic_bytes, "DC2Win95") || - strPrefix(magic_bytes, "DC2Win98")) - { - int position_first_level = 0x00fa; - int extra_bytes = 4; - int skip_bytes; + case 0x16b2: + element = EL_SIGN_GIVE_WAY; + break; - /* advance file stream to first level inside the level package */ - skip_bytes = position_first_level - num_magic_bytes - extra_bytes; + case 0x16b3: + element = EL_SIGN_ENTRY_FORBIDDEN; + break; - /* each block of level data is followed by block of non-level data */ - num_levels_to_skip *= 2; + case 0x16b4: + element = EL_SIGN_EMERGENCY_EXIT; + break; - /* at least skip header bytes, therefore use ">= 0" instead of "> 0" */ - while (num_levels_to_skip >= 0) - { - /* advance file stream to next level inside the level package */ - if (fseek(file, skip_bytes, SEEK_CUR) != 0) - { - level->no_valid_file = TRUE; + case 0x16b5: + element = EL_SIGN_YIN_YANG; + break; - Error(ERR_WARN, "cannot fseek in file '%s' -- using empty level", - filename); + case 0x16b6: + element = EL_WALL_EMERALD; + break; - return; - } + case 0x16b7: + element = EL_WALL_DIAMOND; + break; - /* skip apparently unused extra bytes following each level */ - ReadUnusedBytesFromFile(file, extra_bytes); + case 0x16b8: + element = EL_WALL_PEARL; + break; - /* read size of next level in level package */ - skip_bytes = getFile32BitLE(file); + case 0x16b9: + element = EL_WALL_CRYSTAL; + break; - num_levels_to_skip--; - } - } - else - { - level->no_valid_file = TRUE; + case 0x16ba: + element = EL_INVISIBLE_WALL; + break; - Error(ERR_WARN, "unknown DC2 level file '%s' -- using empty level", - filename); + case 0x16bb: + element = EL_INVISIBLE_STEELWALL; + break; - return; - } - } + /* 0x16bc - 0x16cb: */ + /* EL_INVISIBLE_SAND */ - LoadLevelFromFileStream_DC(file, level, level_file_info->nr); + case 0x16cc: + element = EL_LIGHT_SWITCH; + break; - fclose(file); -} + case 0x16cd: + element = EL_ENVELOPE_1; + break; -#endif + default: + if (element >= 0x0117 && element <= 0x036e) /* (?) */ + element = EL_DIAMOND; + else if (element >= 0x042d && element <= 0x0684) /* (?) */ + element = EL_EMERALD; + else if (element >= 0x157c && element <= 0x158b) + element = EL_SAND; + else if (element >= 0x1590 && element <= 0x159f) + element = EL_DC_LANDMINE; + else if (element >= 0x16bc && element <= 0x16cb) + element = EL_INVISIBLE_SAND; + else + { + Error(ERR_WARN, "unknown Diamond Caves element 0x%04x", element); + element = EL_UNKNOWN; + } + break; + } -#else + return getMappedElement(element); +} -static void LoadLevelFromFileInfo_DC(struct LevelInfo *level, - struct LevelFileInfo *level_file_info) +static void LoadLevelFromFileStream_DC(File *file, struct LevelInfo *level, + int nr) { - char *filename = level_file_info->filename; - FILE *file; -#if 0 - int nr = level_file_info->nr - leveldir_current->first_level; -#endif byte header[DC_LEVEL_HEADER_SIZE]; int envelope_size; int envelope_header_pos = 62; int envelope_content_pos = 94; int level_name_pos = 251; - int level_author_pos = 292; - int envelope_header_len; - int envelope_content_len; - int level_name_len; - int level_author_len; - int fieldx, fieldy; - int num_yamyam_contents; - int i, x, y; - - if (!(file = fopen(filename, MODE_READ))) - { - level->no_valid_file = TRUE; - - if (!level_info_only) - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); - - return; - } - -#if 0 - /* position file stream to the requested level inside the level package */ - if (fseek(file, nr * SP_LEVEL_SIZE, SEEK_SET) != 0) - { - level->no_valid_file = TRUE; - - Error(ERR_WARN, "cannot fseek in file '%s' -- using empty level", filename); - - return; - } -#endif + int level_author_pos = 292; + int envelope_header_len; + int envelope_content_len; + int level_name_len; + int level_author_len; + int fieldx, fieldy; + int num_yamyam_contents; + int i, x, y; getDecodedWord_DC(0, TRUE); /* initialize DC2 decoding engine */ @@ -7963,8 +5259,7 @@ static void LoadLevelFromFileInfo_DC(struct LevelInfo *level, { level->no_valid_file = TRUE; - Error(ERR_WARN, "cannot read level from file '%s' -- using empty level", - filename); + Error(ERR_WARN, "cannot decode level from stream -- using empty level"); return; } @@ -8023,447 +5318,191 @@ static void LoadLevelFromFileInfo_DC(struct LevelInfo *level, for (y = 0; y < 3; y++) for (x = 0; x < 3; x++) { unsigned short word = getDecodedWord_DC(getFile16BitBE(file), FALSE); -#if 1 int element_dc = ((word & 0xff) << 8) | ((word >> 8) & 0xff); -#else - int element_dc = word; -#endif - - if (i < MAX_ELEMENT_CONTENTS) - level->yamyam_content[i].e[x][y] = getMappedElement_DC(element_dc); - } - } - - fieldx = header[6] | (header[7] << 8); - fieldy = header[8] | (header[9] << 8); - level->fieldx = MIN(MAX(MIN_LEV_FIELDX, fieldx), MAX_LEV_FIELDX); - level->fieldy = MIN(MAX(MIN_LEV_FIELDY, fieldy), MAX_LEV_FIELDY); - - for (y = 0; y < fieldy; y++) for (x = 0; x < fieldx; x++) - { - unsigned short word = getDecodedWord_DC(getFile16BitBE(file), FALSE); -#if 1 - int element_dc = ((word & 0xff) << 8) | ((word >> 8) & 0xff); -#else - int element_dc = word; -#endif - - if (x < MAX_LEV_FIELDX && y < MAX_LEV_FIELDY) - level->field[x][y] = getMappedElement_DC(element_dc); - } - - x = MIN(MAX(0, (header[10] | (header[11] << 8)) - 1), MAX_LEV_FIELDX - 1); - y = MIN(MAX(0, (header[12] | (header[13] << 8)) - 1), MAX_LEV_FIELDY - 1); - level->field[x][y] = EL_PLAYER_1; - - x = MIN(MAX(0, (header[14] | (header[15] << 8)) - 1), MAX_LEV_FIELDX - 1); - y = MIN(MAX(0, (header[16] | (header[17] << 8)) - 1), MAX_LEV_FIELDY - 1); - level->field[x][y] = EL_PLAYER_2; - - level->gems_needed = header[18] | (header[19] << 8); - - level->score[SC_EMERALD] = header[20] | (header[21] << 8); - level->score[SC_DIAMOND] = header[22] | (header[23] << 8); - level->score[SC_PEARL] = header[24] | (header[25] << 8); - level->score[SC_CRYSTAL] = header[26] | (header[27] << 8); - level->score[SC_NUT] = header[28] | (header[29] << 8); - level->score[SC_ROBOT] = header[30] | (header[31] << 8); - level->score[SC_SPACESHIP] = header[32] | (header[33] << 8); - level->score[SC_BUG] = header[34] | (header[35] << 8); - level->score[SC_YAMYAM] = header[36] | (header[37] << 8); - level->score[SC_DYNAMITE] = header[38] | (header[39] << 8); - level->score[SC_KEY] = header[40] | (header[41] << 8); - level->score[SC_TIME_BONUS] = header[42] | (header[43] << 8); - - level->time = header[44] | (header[45] << 8); - - level->amoeba_speed = header[46] | (header[47] << 8); - level->time_light = header[48] | (header[49] << 8); - level->time_timegate = header[50] | (header[51] << 8); - level->time_wheel = header[52] | (header[53] << 8); - level->time_magic_wall = header[54] | (header[55] << 8); - level->extra_time = header[56] | (header[57] << 8); - level->shield_normal_time = header[58] | (header[59] << 8); - - fclose(file); - - /* Diamond Caves has the same (strange) behaviour as Emerald Mine that gems - can slip down from flat walls, like normal walls and steel walls */ - level->em_slippery_gems = TRUE; - -#if 0 - /* Diamond Caves II levels are always surrounded by indestructible wall, but - not necessarily in a rectangular way -- fill with invisible steel wall */ - - /* !!! not always true !!! keep level and set BorderElement instead !!! */ - - for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++) - { -#if 1 - if ((x == 0 || x == level->fieldx - 1 || - y == 0 || y == level->fieldy - 1) && - level->field[x][y] == EL_EMPTY) - level->field[x][y] = EL_INVISIBLE_STEELWALL; -#else - if ((x == 0 || x == level->fieldx - 1 || - y == 0 || y == level->fieldy - 1) && - level->field[x][y] == EL_EMPTY) - FloodFillLevel(x, y, EL_INVISIBLE_STEELWALL, - level->field, level->fieldx, level->fieldy); -#endif - } -#endif -} - -#endif - - -/* ------------------------------------------------------------------------- */ -/* functions for loading SB level */ -/* ------------------------------------------------------------------------- */ - -int getMappedElement_SB(int element_ascii, boolean use_ces) -{ - static struct - { - int ascii; - int sb; - int ce; - } - sb_element_mapping[] = - { - { ' ', EL_EMPTY, EL_CUSTOM_1 }, /* floor (space) */ - { '#', EL_STEELWALL, EL_CUSTOM_2 }, /* wall */ - { '@', EL_PLAYER_1, EL_CUSTOM_3 }, /* player */ - { '$', EL_SOKOBAN_OBJECT, EL_CUSTOM_4 }, /* box */ - { '.', EL_SOKOBAN_FIELD_EMPTY, EL_CUSTOM_5 }, /* goal square */ - { '*', EL_SOKOBAN_FIELD_FULL, EL_CUSTOM_6 }, /* box on goal square */ - { '+', EL_SOKOBAN_FIELD_PLAYER, EL_CUSTOM_7 }, /* player on goal square */ -#if 0 - { '_', EL_INVISIBLE_STEELWALL, EL_CUSTOM_8 }, /* floor beyond border */ -#else - { '_', EL_INVISIBLE_STEELWALL, EL_FROM_LEVEL_TEMPLATE }, /* floor beyond border */ -#endif - - { 0, -1, -1 }, - }; - - int i; - - for (i = 0; sb_element_mapping[i].ascii != 0; i++) - if (element_ascii == sb_element_mapping[i].ascii) - return (use_ces ? sb_element_mapping[i].ce : sb_element_mapping[i].sb); - - return EL_UNDEFINED; -} - -#if 1 - -static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, - struct LevelFileInfo *level_file_info, - boolean level_info_only) -{ - char *filename = level_file_info->filename; - char line[MAX_LINE_LEN], line_raw[MAX_LINE_LEN], previous_line[MAX_LINE_LEN]; - char last_comment[MAX_LINE_LEN]; - char level_name[MAX_LINE_LEN]; - char *line_ptr; - File *file; - int num_levels_to_skip = level_file_info->nr - leveldir_current->first_level; - boolean read_continued_line = FALSE; - boolean reading_playfield = FALSE; - boolean got_valid_playfield_line = FALSE; - boolean invalid_playfield_char = FALSE; - boolean load_xsb_to_ces = check_special_flags("load_xsb_to_ces"); - int file_level_nr = 0; - int line_nr = 0; - int x = 0, y = 0; /* initialized to make compilers happy */ - -#if 0 - printf("::: looking for level number %d [%d]\n", - level_file_info->nr, num_levels_to_skip); -#endif - - last_comment[0] = '\0'; - level_name[0] = '\0'; - - if (!(file = openFile(filename, MODE_READ))) - { - level->no_valid_file = TRUE; - - if (!level_info_only) - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); - - return; - } - - while (!checkEndOfFile(file)) - { - /* level successfully read, but next level may follow here */ - if (!got_valid_playfield_line && reading_playfield) - { -#if 0 - printf("::: read complete playfield\n"); -#endif - - /* read playfield from single level file -- skip remaining file */ - if (!level_file_info->packed) - break; - - if (file_level_nr >= num_levels_to_skip) - break; - - file_level_nr++; - - last_comment[0] = '\0'; - level_name[0] = '\0'; - - reading_playfield = FALSE; - } - - got_valid_playfield_line = FALSE; - - /* read next line of input file */ - if (!getStringFromFile(file, line, MAX_LINE_LEN)) - break; - - /* check if line was completely read and is terminated by line break */ - if (strlen(line) > 0 && line[strlen(line) - 1] == '\n') - line_nr++; - - /* cut trailing line break (this can be newline and/or carriage return) */ - for (line_ptr = &line[strlen(line)]; line_ptr >= line; line_ptr--) - if ((*line_ptr == '\n' || *line_ptr == '\r') && *(line_ptr + 1) == '\0') - *line_ptr = '\0'; - - /* copy raw input line for later use (mainly debugging output) */ - strcpy(line_raw, line); - - if (read_continued_line) - { - /* append new line to existing line, if there is enough space */ - if (strlen(previous_line) + strlen(line_ptr) < MAX_LINE_LEN) - strcat(previous_line, line_ptr); - - strcpy(line, previous_line); /* copy storage buffer to line */ - - read_continued_line = FALSE; - } - - /* if the last character is '\', continue at next line */ - if (strlen(line) > 0 && line[strlen(line) - 1] == '\\') - { - line[strlen(line) - 1] = '\0'; /* cut off trailing backslash */ - strcpy(previous_line, line); /* copy line to storage buffer */ - - read_continued_line = TRUE; - - continue; - } - - /* skip empty lines */ - if (line[0] == '\0') - continue; - - /* extract comment text from comment line */ - if (line[0] == ';') - { - for (line_ptr = line; *line_ptr; line_ptr++) - if (*line_ptr != ' ' && *line_ptr != '\t' && *line_ptr != ';') - break; - - strcpy(last_comment, line_ptr); - -#if 0 - printf("::: found comment '%s' in line %d\n", last_comment, line_nr); -#endif - - continue; - } - - /* extract level title text from line containing level title */ - if (line[0] == '\'') - { - strcpy(level_name, &line[1]); - if (strlen(level_name) > 0 && level_name[strlen(level_name) - 1] == '\'') - level_name[strlen(level_name) - 1] = '\0'; + if (i < MAX_ELEMENT_CONTENTS) + level->yamyam_content[i].e[x][y] = getMappedElement_DC(element_dc); + } + } -#if 0 - printf("::: found level name '%s' in line %d\n", level_name, line_nr); -#endif + fieldx = header[6] | (header[7] << 8); + fieldy = header[8] | (header[9] << 8); + level->fieldx = MIN(MAX(MIN_LEV_FIELDX, fieldx), MAX_LEV_FIELDX); + level->fieldy = MIN(MAX(MIN_LEV_FIELDY, fieldy), MAX_LEV_FIELDY); - continue; - } + for (y = 0; y < fieldy; y++) for (x = 0; x < fieldx; x++) + { + unsigned short word = getDecodedWord_DC(getFile16BitBE(file), FALSE); + int element_dc = ((word & 0xff) << 8) | ((word >> 8) & 0xff); - /* skip lines containing only spaces (or empty lines) */ - for (line_ptr = line; *line_ptr; line_ptr++) - if (*line_ptr != ' ') - break; - if (*line_ptr == '\0') - continue; + if (x < MAX_LEV_FIELDX && y < MAX_LEV_FIELDY) + level->field[x][y] = getMappedElement_DC(element_dc); + } - /* at this point, we have found a line containing part of a playfield */ + x = MIN(MAX(0, (header[10] | (header[11] << 8)) - 1), MAX_LEV_FIELDX - 1); + y = MIN(MAX(0, (header[12] | (header[13] << 8)) - 1), MAX_LEV_FIELDY - 1); + level->field[x][y] = EL_PLAYER_1; -#if 0 - printf("::: found playfield row in line %d\n", line_nr); -#endif + x = MIN(MAX(0, (header[14] | (header[15] << 8)) - 1), MAX_LEV_FIELDX - 1); + y = MIN(MAX(0, (header[16] | (header[17] << 8)) - 1), MAX_LEV_FIELDY - 1); + level->field[x][y] = EL_PLAYER_2; - got_valid_playfield_line = TRUE; + level->gems_needed = header[18] | (header[19] << 8); - if (!reading_playfield) - { - reading_playfield = TRUE; - invalid_playfield_char = FALSE; + level->score[SC_EMERALD] = header[20] | (header[21] << 8); + level->score[SC_DIAMOND] = header[22] | (header[23] << 8); + level->score[SC_PEARL] = header[24] | (header[25] << 8); + level->score[SC_CRYSTAL] = header[26] | (header[27] << 8); + level->score[SC_NUT] = header[28] | (header[29] << 8); + level->score[SC_ROBOT] = header[30] | (header[31] << 8); + level->score[SC_SPACESHIP] = header[32] | (header[33] << 8); + level->score[SC_BUG] = header[34] | (header[35] << 8); + level->score[SC_YAMYAM] = header[36] | (header[37] << 8); + level->score[SC_DYNAMITE] = header[38] | (header[39] << 8); + level->score[SC_KEY] = header[40] | (header[41] << 8); + level->score[SC_TIME_BONUS] = header[42] | (header[43] << 8); - for (x = 0; x < MAX_LEV_FIELDX; x++) - for (y = 0; y < MAX_LEV_FIELDY; y++) - level->field[x][y] = getMappedElement_SB(' ', load_xsb_to_ces); + level->time = header[44] | (header[45] << 8); - level->fieldx = 0; - level->fieldy = 0; + level->amoeba_speed = header[46] | (header[47] << 8); + level->time_light = header[48] | (header[49] << 8); + level->time_timegate = header[50] | (header[51] << 8); + level->time_wheel = header[52] | (header[53] << 8); + level->time_magic_wall = header[54] | (header[55] << 8); + level->extra_time = header[56] | (header[57] << 8); + level->shield_normal_time = header[58] | (header[59] << 8); - /* start with topmost tile row */ - y = 0; - } + /* Diamond Caves has the same (strange) behaviour as Emerald Mine that gems + can slip down from flat walls, like normal walls and steel walls */ + level->em_slippery_gems = TRUE; +} - /* skip playfield line if larger row than allowed */ - if (y >= MAX_LEV_FIELDY) - continue; +static void LoadLevelFromFileInfo_DC(struct LevelInfo *level, + struct LevelFileInfo *level_file_info, + boolean level_info_only) +{ + char *filename = level_file_info->filename; + File *file; + int num_magic_bytes = 8; + char magic_bytes[num_magic_bytes + 1]; + int num_levels_to_skip = level_file_info->nr - leveldir_current->first_level; - /* start with leftmost tile column */ - x = 0; + if (!(file = openFile(filename, MODE_READ))) + { + level->no_valid_file = TRUE; - /* read playfield elements from line */ - for (line_ptr = line; *line_ptr; line_ptr++) - { - int mapped_sb_element = getMappedElement_SB(*line_ptr, load_xsb_to_ces); + if (!level_info_only) + Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); - /* stop parsing playfield line if larger column than allowed */ - if (x >= MAX_LEV_FIELDX) - break; + return; + } - if (mapped_sb_element == EL_UNDEFINED) - { - invalid_playfield_char = TRUE; + // fseek(file, 0x0000, SEEK_SET); - break; - } + if (level_file_info->packed) + { + /* read "magic bytes" from start of file */ + if (getStringFromFile(file, magic_bytes, num_magic_bytes + 1) == NULL) + magic_bytes[0] = '\0'; - level->field[x][y] = mapped_sb_element; + /* check "magic bytes" for correct file format */ + if (!strPrefix(magic_bytes, "DC2")) + { + level->no_valid_file = TRUE; - /* continue with next tile column */ - x++; + Error(ERR_WARN, "unknown DC level file '%s' -- using empty level", + filename); - level->fieldx = MAX(x, level->fieldx); + return; } - if (invalid_playfield_char) + if (strPrefix(magic_bytes, "DC2Win95") || + strPrefix(magic_bytes, "DC2Win98")) { - /* if first playfield line, treat invalid lines as comment lines */ - if (y == 0) - reading_playfield = FALSE; + int position_first_level = 0x00fa; + int extra_bytes = 4; + int skip_bytes; - continue; - } + /* advance file stream to first level inside the level package */ + skip_bytes = position_first_level - num_magic_bytes - extra_bytes; - /* continue with next tile row */ - y++; - } + /* each block of level data is followed by block of non-level data */ + num_levels_to_skip *= 2; - closeFile(file); + /* at least skip header bytes, therefore use ">= 0" instead of "> 0" */ + while (num_levels_to_skip >= 0) + { + /* advance file stream to next level inside the level package */ + if (seekFile(file, skip_bytes, SEEK_CUR) != 0) + { + level->no_valid_file = TRUE; - level->fieldy = y; + Error(ERR_WARN, "cannot fseek in file '%s' -- using empty level", + filename); - level->fieldx = MIN(MAX(MIN_LEV_FIELDX, level->fieldx), MAX_LEV_FIELDX); - level->fieldy = MIN(MAX(MIN_LEV_FIELDY, level->fieldy), MAX_LEV_FIELDY); + return; + } - if (!reading_playfield) - { - level->no_valid_file = TRUE; + /* skip apparently unused extra bytes following each level */ + ReadUnusedBytesFromFile(file, extra_bytes); - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); + /* read size of next level in level package */ + skip_bytes = getFile32BitLE(file); - return; - } + num_levels_to_skip--; + } + } + else + { + level->no_valid_file = TRUE; - if (*level_name != '\0') - { - strncpy(level->name, level_name, MAX_LEVEL_NAME_LEN); - level->name[MAX_LEVEL_NAME_LEN] = '\0'; + Error(ERR_WARN, "unknown DC2 level file '%s' -- using empty level", + filename); -#if 0 - printf(":1: level name: '%s'\n", level->name); -#endif + return; + } } - else if (*last_comment != '\0') - { - strncpy(level->name, last_comment, MAX_LEVEL_NAME_LEN); - level->name[MAX_LEVEL_NAME_LEN] = '\0'; -#if 0 - printf(":2: level name: '%s'\n", level->name); -#endif - } - else - { - sprintf(level->name, "--> Level %d <--", level_file_info->nr); - } + LoadLevelFromFileStream_DC(file, level, level_file_info->nr); - /* set all empty fields beyond the border walls to invisible steel wall */ - for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++) - { - if ((x == 0 || x == level->fieldx - 1 || - y == 0 || y == level->fieldy - 1) && - level->field[x][y] == getMappedElement_SB(' ', load_xsb_to_ces)) - FloodFillLevel(x, y, getMappedElement_SB('_', load_xsb_to_ces), - level->field, level->fieldx, level->fieldy); - } + closeFile(file); +} - /* set special level settings for Sokoban levels */ - level->time = 0; - level->use_step_counter = TRUE; +/* ------------------------------------------------------------------------- */ +/* functions for loading SB level */ +/* ------------------------------------------------------------------------- */ - if (load_xsb_to_ces) +int getMappedElement_SB(int element_ascii, boolean use_ces) +{ + static struct { -#if 1 - /* !!! special global settings can now be set in level template !!! */ -#else - level->initial_player_stepsize[0] = STEPSIZE_SLOW; -#endif - - /* fill smaller playfields with padding "beyond border wall" elements */ - if (level->fieldx < SCR_FIELDX || - level->fieldy < SCR_FIELDY) - { - short field[level->fieldx][level->fieldy]; - int new_fieldx = MAX(level->fieldx, SCR_FIELDX); - int new_fieldy = MAX(level->fieldy, SCR_FIELDY); - int pos_fieldx = (new_fieldx - level->fieldx) / 2; - int pos_fieldy = (new_fieldy - level->fieldy) / 2; - - /* copy old playfield (which is smaller than the visible area) */ - for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++) - field[x][y] = level->field[x][y]; - - /* fill new, larger playfield with "beyond border wall" elements */ - for (y = 0; y < new_fieldy; y++) for (x = 0; x < new_fieldx; x++) - level->field[x][y] = getMappedElement_SB('_', load_xsb_to_ces); + int ascii; + int sb; + int ce; + } + sb_element_mapping[] = + { + { ' ', EL_EMPTY, EL_CUSTOM_1 }, /* floor (space) */ + { '#', EL_STEELWALL, EL_CUSTOM_2 }, /* wall */ + { '@', EL_PLAYER_1, EL_CUSTOM_3 }, /* player */ + { '$', EL_SOKOBAN_OBJECT, EL_CUSTOM_4 }, /* box */ + { '.', EL_SOKOBAN_FIELD_EMPTY, EL_CUSTOM_5 }, /* goal square */ + { '*', EL_SOKOBAN_FIELD_FULL, EL_CUSTOM_6 }, /* box on goal square */ + { '+', EL_SOKOBAN_FIELD_PLAYER, EL_CUSTOM_7 }, /* player on goal square */ + { '_', EL_INVISIBLE_STEELWALL, EL_FROM_LEVEL_TEMPLATE }, /* floor beyond border */ - /* copy the old playfield to the middle of the new playfield */ - for (y = 0; y < level->fieldy; y++) for (x = 0; x < level->fieldx; x++) - level->field[pos_fieldx + x][pos_fieldy + y] = field[x][y]; + { 0, -1, -1 }, + }; - level->fieldx = new_fieldx; - level->fieldy = new_fieldy; - } + int i; - level->use_custom_template = TRUE; - } -} + for (i = 0; sb_element_mapping[i].ascii != 0; i++) + if (element_ascii == sb_element_mapping[i].ascii) + return (use_ces ? sb_element_mapping[i].ce : sb_element_mapping[i].sb); -#else + return EL_UNDEFINED; +} static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, struct LevelFileInfo *level_file_info, @@ -8474,7 +5513,7 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, char last_comment[MAX_LINE_LEN]; char level_name[MAX_LINE_LEN]; char *line_ptr; - FILE *file; + File *file; int num_levels_to_skip = level_file_info->nr - leveldir_current->first_level; boolean read_continued_line = FALSE; boolean reading_playfield = FALSE; @@ -8485,15 +5524,10 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, int line_nr = 0; int x = 0, y = 0; /* initialized to make compilers happy */ -#if 0 - printf("::: looking for level number %d [%d]\n", - level_file_info->nr, num_levels_to_skip); -#endif - last_comment[0] = '\0'; level_name[0] = '\0'; - if (!(file = fopen(filename, MODE_READ))) + if (!(file = openFile(filename, MODE_READ))) { level->no_valid_file = TRUE; @@ -8503,15 +5537,11 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, return; } - while (!feof(file)) + while (!checkEndOfFile(file)) { /* level successfully read, but next level may follow here */ if (!got_valid_playfield_line && reading_playfield) { -#if 0 - printf("::: read complete playfield\n"); -#endif - /* read playfield from single level file -- skip remaining file */ if (!level_file_info->packed) break; @@ -8530,7 +5560,7 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, got_valid_playfield_line = FALSE; /* read next line of input file */ - if (!fgets(line, MAX_LINE_LEN, file)) + if (!getStringFromFile(file, line, MAX_LINE_LEN)) break; /* check if line was completely read and is terminated by line break */ @@ -8580,10 +5610,6 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, strcpy(last_comment, line_ptr); -#if 0 - printf("::: found comment '%s' in line %d\n", last_comment, line_nr); -#endif - continue; } @@ -8595,10 +5621,6 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, if (strlen(level_name) > 0 && level_name[strlen(level_name) - 1] == '\'') level_name[strlen(level_name) - 1] = '\0'; -#if 0 - printf("::: found level name '%s' in line %d\n", level_name, line_nr); -#endif - continue; } @@ -8611,10 +5633,6 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, /* at this point, we have found a line containing part of a playfield */ -#if 0 - printf("::: found playfield row in line %d\n", line_nr); -#endif - got_valid_playfield_line = TRUE; if (!reading_playfield) @@ -8677,7 +5695,7 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, y++; } - fclose(file); + closeFile(file); level->fieldy = y; @@ -8697,19 +5715,11 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, { strncpy(level->name, level_name, MAX_LEVEL_NAME_LEN); level->name[MAX_LEVEL_NAME_LEN] = '\0'; - -#if 0 - printf(":1: level name: '%s'\n", level->name); -#endif } else if (*last_comment != '\0') { strncpy(level->name, last_comment, MAX_LEVEL_NAME_LEN); level->name[MAX_LEVEL_NAME_LEN] = '\0'; - -#if 0 - printf(":2: level name: '%s'\n", level->name); -#endif } else { @@ -8733,11 +5743,7 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, if (load_xsb_to_ces) { -#if 1 - /* !!! special global settings can now be set in level template !!! */ -#else - level->initial_player_stepsize[0] = STEPSIZE_SLOW; -#endif + /* special global settings can now be set in level template */ /* fill smaller playfields with padding "beyond border wall" elements */ if (level->fieldx < SCR_FIELDX || @@ -8769,8 +5775,6 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, } } -#endif - /* ------------------------------------------------------------------------- */ /* functions for handling native levels */ @@ -8912,10 +5916,6 @@ static void LoadLevel_InitVersion(struct LevelInfo *level, char *filename) level->score[SC_TIME_BONUS] /= 10; } -#if 0 - leveldir_current->latest_engine = TRUE; /* !!! TEST ONLY !!! */ -#endif - if (leveldir_current->latest_engine) { /* ---------- use latest game engine ----------------------------------- */ @@ -8978,11 +5978,6 @@ static void LoadLevel_InitVersion(struct LevelInfo *level, char *filename) /* extra time score was same value as time left score before 3.2.0-5 */ level->extra_time_score = level->score[SC_TIME_BONUS]; - -#if 0 - /* time bonus score was given for 10 s instead of 1 s before 3.2.0-5 */ - level->score[SC_TIME_BONUS] /= 10; -#endif } if (level->game_version < VERSION_IDENT(3,2,0,7)) @@ -9047,7 +6042,6 @@ static void LoadLevel_InitVersion(struct LevelInfo *level, char *filename) change->target_element = EL_PLAYER_1; } -#if 1 /* try to detect and fix "Zelda" style levels, which are broken with 3.2.5 */ if (level->game_version < VERSION_IDENT(3,2,5,0)) { @@ -9071,35 +6065,6 @@ static void LoadLevel_InitVersion(struct LevelInfo *level, char *filename) level->use_action_after_change_bug = TRUE; } -#else - /* !!! THIS DOES NOT FIX "Zelda I" (GRAPHICALLY) AND "Alan's FMV" LEVELS */ - /* try to detect and fix "Zelda II" levels, which are broken with 3.2.5 */ - { - int element = EL_CUSTOM_16; - struct ElementInfo *ei = &element_info[element]; - - /* This is needed to fix a problem that was caused by a bugfix in function - game.c/CheckTriggeredElementChangeExt() introduced with 3.2.5 that - corrects the behaviour when a custom element changes to another custom - element with a higher element number that has change actions defined. - Normally, only one change per frame is allowed for custom elements. - Therefore, it is checked if a custom element already changed in the - current frame; if it did, subsequent changes are suppressed. - Unfortunately, this is only checked for element changes, but not for - change actions, which are still executed. As the function above loops - through all custom elements from lower to higher, an element change - resulting in a lower CE number won't be checked again, while a target - element with a higher number will also be checked, and potential change - actions will get executed for this CE, too (which is wrong), while - further changes are ignored (which is correct). As this bugfix breaks - Zelda II (but no other levels), allow the previous, incorrect behaviour - for this outstanding level set to not break the game or existing tapes */ - - if (strncmp(leveldir_current->identifier, "zelda2", 6) == 0 || - strncmp(ei->description, "scanline - row 1", 16) == 0) - level->use_action_after_change_bug = TRUE; - } -#endif /* not centering level after relocating player was default only in 3.2.3 */ if (level->game_version == VERSION_IDENT(3,2,3,0)) /* (no pre-releases) */ @@ -9312,14 +6277,7 @@ void LoadLevel(int nr) void LoadLevelInfoOnly(int nr) { -#if 0 - char *filename; -#endif - setLevelFileInfo(&level.file_info, nr); -#if 0 - filename = level.file_info.filename; -#endif LoadLevelFromFileInfo(&level, &level.file_info, TRUE); } @@ -9345,7 +6303,7 @@ static int SaveLevel_DATE(FILE *file, struct LevelInfo *level) return chunk_size; } -#if 0 +#if ENABLE_HISTORIC_CHUNKS static void SaveLevel_HEAD(FILE *file, struct LevelInfo *level) { int i, x, y; @@ -9419,7 +6377,7 @@ static int SaveLevel_AUTH(FILE *file, struct LevelInfo *level) return chunk_size; } -#if 0 +#if ENABLE_HISTORIC_CHUNKS static int SaveLevel_BODY(FILE *file, struct LevelInfo *level) { int chunk_size = 0; @@ -9448,7 +6406,7 @@ static int SaveLevel_BODY(FILE *file, struct LevelInfo *level) return chunk_size; } -#if 0 +#if ENABLE_HISTORIC_CHUNKS static void SaveLevel_CONT(FILE *file, struct LevelInfo *level) { int i, x, y; @@ -9468,7 +6426,7 @@ static void SaveLevel_CONT(FILE *file, struct LevelInfo *level) } #endif -#if 0 +#if ENABLE_HISTORIC_CHUNKS static void SaveLevel_CNT2(FILE *file, struct LevelInfo *level, int element) { int i, x, y; @@ -9521,7 +6479,7 @@ static void SaveLevel_CNT2(FILE *file, struct LevelInfo *level, int element) } #endif -#if 0 +#if ENABLE_HISTORIC_CHUNKS static int SaveLevel_CNT3(FILE *file, struct LevelInfo *level, int element) { int envelope_nr = element - EL_ENVELOPE_1; @@ -9544,7 +6502,7 @@ static int SaveLevel_CNT3(FILE *file, struct LevelInfo *level, int element) } #endif -#if 0 +#if ENABLE_HISTORIC_CHUNKS static void SaveLevel_CUS1(FILE *file, struct LevelInfo *level, int num_changed_custom_elements) { @@ -9575,7 +6533,7 @@ static void SaveLevel_CUS1(FILE *file, struct LevelInfo *level, } #endif -#if 0 +#if ENABLE_HISTORIC_CHUNKS static void SaveLevel_CUS2(FILE *file, struct LevelInfo *level, int num_changed_custom_elements) { @@ -9604,7 +6562,7 @@ static void SaveLevel_CUS2(FILE *file, struct LevelInfo *level, } #endif -#if 0 +#if ENABLE_HISTORIC_CHUNKS static void SaveLevel_CUS3(FILE *file, struct LevelInfo *level, int num_changed_custom_elements) { @@ -9687,7 +6645,7 @@ static void SaveLevel_CUS3(FILE *file, struct LevelInfo *level, } #endif -#if 0 +#if ENABLE_HISTORIC_CHUNKS static void SaveLevel_CUS4(FILE *file, struct LevelInfo *level, int element) { struct ElementInfo *ei = &element_info[element]; @@ -9807,7 +6765,7 @@ static void SaveLevel_CUS4(FILE *file, struct LevelInfo *level, int element) } #endif -#if 0 +#if ENABLE_HISTORIC_CHUNKS static void SaveLevel_GRP1(FILE *file, struct LevelInfo *level, int element) { struct ElementInfo *ei = &element_info[element]; @@ -10009,12 +6967,6 @@ static int SaveLevel_CUSX(FILE *file, struct LevelInfo *level, int element) /* set default description string for this specific element */ strcpy(xx_default_description, getDefaultElementDescription(ei)); -#if 0 - /* set (fixed) number of content areas (may be wrong by broken level file) */ - /* (this is now directly corrected for broken level files after loading) */ - xx_num_contents = 1; -#endif - for (i = 0; chunk_config_CUSX_base[i].data_type != -1; i++) chunk_size += SaveLevel_MicroChunk(file, &chunk_config_CUSX_base[i], FALSE); @@ -10235,184 +7187,29 @@ static void setTapeInfoToDefaults() { int i; - /* always start with reliable default values (empty tape) */ - TapeErase(); - - /* default values (also for pre-1.2 tapes) with only the first player */ - tape.player_participates[0] = TRUE; - for (i = 1; i < MAX_PLAYERS; i++) - tape.player_participates[i] = FALSE; - - /* at least one (default: the first) player participates in every tape */ - tape.num_participating_players = 1; - - tape.level_nr = level_nr; - tape.counter = 0; - tape.changed = FALSE; - - tape.recording = FALSE; - tape.playing = FALSE; - tape.pausing = FALSE; - - tape.no_valid_file = FALSE; -} - -#if 1 - -static int LoadTape_VERS(File *file, int chunk_size, struct TapeInfo *tape) -{ - tape->file_version = getFileVersion(file); - tape->game_version = getFileVersion(file); - - return chunk_size; -} - -static int LoadTape_HEAD(File *file, int chunk_size, struct TapeInfo *tape) -{ - int i; - - tape->random_seed = getFile32BitBE(file); - tape->date = getFile32BitBE(file); - tape->length = getFile32BitBE(file); - - /* read header fields that are new since version 1.2 */ - if (tape->file_version >= FILE_VERSION_1_2) - { - byte store_participating_players = getFile8Bit(file); - int engine_version; - - /* since version 1.2, tapes store which players participate in the tape */ - tape->num_participating_players = 0; - for (i = 0; i < MAX_PLAYERS; i++) - { - tape->player_participates[i] = FALSE; - - if (store_participating_players & (1 << i)) - { - tape->player_participates[i] = TRUE; - tape->num_participating_players++; - } - } - - ReadUnusedBytesFromFile(file, TAPE_CHUNK_HEAD_UNUSED); - - engine_version = getFileVersion(file); - if (engine_version > 0) - tape->engine_version = engine_version; - else - tape->engine_version = tape->game_version; - } - - return chunk_size; -} - -static int LoadTape_INFO(File *file, int chunk_size, struct TapeInfo *tape) -{ - int level_identifier_size; - int i; - - level_identifier_size = getFile16BitBE(file); - - tape->level_identifier = - checked_realloc(tape->level_identifier, level_identifier_size); - - for (i = 0; i < level_identifier_size; i++) - tape->level_identifier[i] = getFile8Bit(file); - - tape->level_nr = getFile16BitBE(file); - - chunk_size = 2 + level_identifier_size + 2; - - return chunk_size; -} - -static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape) -{ - int i, j; - int chunk_size_expected = - (tape->num_participating_players + 1) * tape->length; - - if (chunk_size_expected != chunk_size) - { - ReadUnusedBytesFromFile(file, chunk_size); - return chunk_size_expected; - } - - for (i = 0; i < tape->length; i++) - { - if (i >= MAX_TAPE_LEN) - break; - - for (j = 0; j < MAX_PLAYERS; j++) - { - tape->pos[i].action[j] = MV_NONE; - - if (tape->player_participates[j]) - tape->pos[i].action[j] = getFile8Bit(file); - } - - tape->pos[i].delay = getFile8Bit(file); - - if (tape->file_version == FILE_VERSION_1_0) - { - /* eliminate possible diagonal moves in old tapes */ - /* this is only for backward compatibility */ - - byte joy_dir[4] = { JOY_LEFT, JOY_RIGHT, JOY_UP, JOY_DOWN }; - byte action = tape->pos[i].action[0]; - int k, num_moves = 0; - - for (k = 0; k<4; k++) - { - if (action & joy_dir[k]) - { - tape->pos[i + num_moves].action[0] = joy_dir[k]; - if (num_moves > 0) - tape->pos[i + num_moves].delay = 0; - num_moves++; - } - } - - if (num_moves > 1) - { - num_moves--; - i += num_moves; - tape->length += num_moves; - } - } - else if (tape->file_version < FILE_VERSION_2_0) - { - /* convert pre-2.0 tapes to new tape format */ - - if (tape->pos[i].delay > 1) - { - /* action part */ - tape->pos[i + 1] = tape->pos[i]; - tape->pos[i + 1].delay = 1; - - /* delay part */ - for (j = 0; j < MAX_PLAYERS; j++) - tape->pos[i].action[j] = MV_NONE; - tape->pos[i].delay--; + /* always start with reliable default values (empty tape) */ + TapeErase(); - i++; - tape->length++; - } - } + /* default values (also for pre-1.2 tapes) with only the first player */ + tape.player_participates[0] = TRUE; + for (i = 1; i < MAX_PLAYERS; i++) + tape.player_participates[i] = FALSE; - if (checkEndOfFile(file)) - break; - } + /* at least one (default: the first) player participates in every tape */ + tape.num_participating_players = 1; - if (i != tape->length) - chunk_size = (tape->num_participating_players + 1) * i; + tape.level_nr = level_nr; + tape.counter = 0; + tape.changed = FALSE; - return chunk_size; -} + tape.recording = FALSE; + tape.playing = FALSE; + tape.pausing = FALSE; -#else + tape.no_valid_file = FALSE; +} -static int LoadTape_VERS(FILE *file, int chunk_size, struct TapeInfo *tape) +static int LoadTape_VERS(File *file, int chunk_size, struct TapeInfo *tape) { tape->file_version = getFileVersion(file); tape->game_version = getFileVersion(file); @@ -10420,7 +7217,7 @@ static int LoadTape_VERS(FILE *file, int chunk_size, struct TapeInfo *tape) return chunk_size; } -static int LoadTape_HEAD(FILE *file, int chunk_size, struct TapeInfo *tape) +static int LoadTape_HEAD(File *file, int chunk_size, struct TapeInfo *tape) { int i; @@ -10459,7 +7256,7 @@ static int LoadTape_HEAD(FILE *file, int chunk_size, struct TapeInfo *tape) return chunk_size; } -static int LoadTape_INFO(FILE *file, int chunk_size, struct TapeInfo *tape) +static int LoadTape_INFO(File *file, int chunk_size, struct TapeInfo *tape) { int level_identifier_size; int i; @@ -10479,7 +7276,7 @@ static int LoadTape_INFO(FILE *file, int chunk_size, struct TapeInfo *tape) return chunk_size; } -static int LoadTape_BODY(FILE *file, int chunk_size, struct TapeInfo *tape) +static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape) { int i, j; int chunk_size_expected = @@ -10553,7 +7350,7 @@ static int LoadTape_BODY(FILE *file, int chunk_size, struct TapeInfo *tape) } } - if (feof(file)) + if (checkEndOfFile(file)) break; } @@ -10563,10 +7360,6 @@ static int LoadTape_BODY(FILE *file, int chunk_size, struct TapeInfo *tape) return chunk_size; } -#endif - -#if 1 - void LoadTape_SokobanSolution(char *filename) { File *file; @@ -10635,245 +7428,16 @@ void LoadTape_SokobanSolution(char *filename) closeFile(file); if (tape.no_valid_file) - return; - - tape.length_seconds = GetTapeLength(); -} - -#else - -void LoadTape_SokobanSolution(char *filename) -{ - FILE *file; - int move_delay = TILESIZE / level.initial_player_stepsize[0]; - - if (!(file = fopen(filename, MODE_READ))) - { - tape.no_valid_file = TRUE; - - return; - } - - while (!feof(file)) - { - unsigned char c = fgetc(file); - - if (feof(file)) - break; - - switch (c) - { - case 'u': - case 'U': - tape.pos[tape.length].action[0] = MV_UP; - tape.pos[tape.length].delay = move_delay + (c < 'a' ? 2 : 0); - tape.length++; - break; - - case 'd': - case 'D': - tape.pos[tape.length].action[0] = MV_DOWN; - tape.pos[tape.length].delay = move_delay + (c < 'a' ? 2 : 0); - tape.length++; - break; - - case 'l': - case 'L': - tape.pos[tape.length].action[0] = MV_LEFT; - tape.pos[tape.length].delay = move_delay + (c < 'a' ? 2 : 0); - tape.length++; - break; - - case 'r': - case 'R': - tape.pos[tape.length].action[0] = MV_RIGHT; - tape.pos[tape.length].delay = move_delay + (c < 'a' ? 2 : 0); - tape.length++; - break; - - case '\n': - case '\r': - case '\t': - case ' ': - /* ignore white-space characters */ - break; - - default: - tape.no_valid_file = TRUE; - - Error(ERR_WARN, "unsupported Sokoban solution file '%s' ['%d']", filename, c); - - break; - } - } - - fclose(file); - - if (tape.no_valid_file) - return; - - tape.length_seconds = GetTapeLength(); -} - -#endif - -#if 1 - -void LoadTapeFromFilename(char *filename) -{ - char cookie[MAX_LINE_LEN]; - char chunk_name[CHUNK_ID_LEN + 1]; - File *file; - int chunk_size; - - /* always start with reliable default values */ - setTapeInfoToDefaults(); - - if (strSuffix(filename, ".sln")) - { - LoadTape_SokobanSolution(filename); - - return; - } - - if (!(file = openFile(filename, MODE_READ))) - { - tape.no_valid_file = TRUE; - - return; - } - - getFileChunkBE(file, chunk_name, NULL); - if (strEqual(chunk_name, "RND1")) - { - getFile32BitBE(file); /* not used */ - - getFileChunkBE(file, chunk_name, NULL); - if (!strEqual(chunk_name, "TAPE")) - { - tape.no_valid_file = TRUE; - - Error(ERR_WARN, "unknown format of tape file '%s'", filename); - - closeFile(file); - - return; - } - } - else /* check for pre-2.0 file format with cookie string */ - { - strcpy(cookie, chunk_name); - if (getStringFromFile(file, &cookie[4], MAX_LINE_LEN - 4) == NULL) - cookie[4] = '\0'; - if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n') - cookie[strlen(cookie) - 1] = '\0'; - - if (!checkCookieString(cookie, TAPE_COOKIE_TMPL)) - { - tape.no_valid_file = TRUE; - - Error(ERR_WARN, "unknown format of tape file '%s'", filename); - - closeFile(file); - - return; - } - - if ((tape.file_version = getFileVersionFromCookieString(cookie)) == -1) - { - tape.no_valid_file = TRUE; - - Error(ERR_WARN, "unsupported version of tape file '%s'", filename); - - closeFile(file); - - return; - } - - /* pre-2.0 tape files have no game version, so use file version here */ - tape.game_version = tape.file_version; - } - - if (tape.file_version < FILE_VERSION_1_2) - { - /* tape files from versions before 1.2.0 without chunk structure */ - LoadTape_HEAD(file, TAPE_CHUNK_HEAD_SIZE, &tape); - LoadTape_BODY(file, 2 * tape.length, &tape); - } - else - { - static struct - { - char *name; - int size; - int (*loader)(File *, int, struct TapeInfo *); - } - chunk_info[] = - { - { "VERS", TAPE_CHUNK_VERS_SIZE, LoadTape_VERS }, - { "HEAD", TAPE_CHUNK_HEAD_SIZE, LoadTape_HEAD }, - { "INFO", -1, LoadTape_INFO }, - { "BODY", -1, LoadTape_BODY }, - { NULL, 0, NULL } - }; - - while (getFileChunkBE(file, chunk_name, &chunk_size)) - { - int i = 0; - - while (chunk_info[i].name != NULL && - !strEqual(chunk_name, chunk_info[i].name)) - i++; - - if (chunk_info[i].name == NULL) - { - Error(ERR_WARN, "unknown chunk '%s' in tape file '%s'", - chunk_name, filename); - ReadUnusedBytesFromFile(file, chunk_size); - } - else if (chunk_info[i].size != -1 && - chunk_info[i].size != chunk_size) - { - Error(ERR_WARN, "wrong size (%d) of chunk '%s' in tape file '%s'", - chunk_size, chunk_name, filename); - ReadUnusedBytesFromFile(file, chunk_size); - } - else - { - /* call function to load this tape chunk */ - int chunk_size_expected = - (chunk_info[i].loader)(file, chunk_size, &tape); - - /* the size of some chunks cannot be checked before reading other - chunks first (like "HEAD" and "BODY") that contain some header - information, so check them here */ - if (chunk_size_expected != chunk_size) - { - Error(ERR_WARN, "wrong size (%d) of chunk '%s' in tape file '%s'", - chunk_size, chunk_name, filename); - } - } - } - } - - closeFile(file); + return; tape.length_seconds = GetTapeLength(); - -#if 0 - printf("::: tape file version: %d\n", tape.file_version); - printf("::: tape game version: %d\n", tape.game_version); - printf("::: tape engine version: %d\n", tape.engine_version); -#endif } -#else - void LoadTapeFromFilename(char *filename) { char cookie[MAX_LINE_LEN]; char chunk_name[CHUNK_ID_LEN + 1]; - FILE *file; + File *file; int chunk_size; /* always start with reliable default values */ @@ -10886,7 +7450,7 @@ void LoadTapeFromFilename(char *filename) return; } - if (!(file = fopen(filename, MODE_READ))) + if (!(file = openFile(filename, MODE_READ))) { tape.no_valid_file = TRUE; @@ -10904,14 +7468,16 @@ void LoadTapeFromFilename(char *filename) tape.no_valid_file = TRUE; Error(ERR_WARN, "unknown format of tape file '%s'", filename); - fclose(file); + + closeFile(file); + return; } } else /* check for pre-2.0 file format with cookie string */ { strcpy(cookie, chunk_name); - if (fgets(&cookie[4], MAX_LINE_LEN - 4, file) == NULL) + if (getStringFromFile(file, &cookie[4], MAX_LINE_LEN - 4) == NULL) cookie[4] = '\0'; if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n') cookie[strlen(cookie) - 1] = '\0'; @@ -10921,7 +7487,9 @@ void LoadTapeFromFilename(char *filename) tape.no_valid_file = TRUE; Error(ERR_WARN, "unknown format of tape file '%s'", filename); - fclose(file); + + closeFile(file); + return; } @@ -10930,7 +7498,8 @@ void LoadTapeFromFilename(char *filename) tape.no_valid_file = TRUE; Error(ERR_WARN, "unsupported version of tape file '%s'", filename); - fclose(file); + + closeFile(file); return; } @@ -11001,19 +7570,17 @@ void LoadTapeFromFilename(char *filename) } } - fclose(file); + closeFile(file); tape.length_seconds = GetTapeLength(); #if 0 - printf("::: tape file version: %d\n", tape.file_version); - printf("::: tape game version: %d\n", tape.game_version); + printf("::: tape file version: %d\n", tape.file_version); + printf("::: tape game version: %d\n", tape.game_version); printf("::: tape engine version: %d\n", tape.engine_version); #endif } -#endif - void LoadTape(int nr) { char *filename = getTapeFilename(nr); @@ -11027,12 +7594,10 @@ void LoadSolutionTape(int nr) LoadTapeFromFilename(filename); -#if 1 if (TAPE_IS_EMPTY(tape) && level.game_engine_type == GAME_ENGINE_TYPE_SP && level.native_sp_level->demo.is_available) CopyNativeTape_SP_to_RND(&level); -#endif } static void SaveTape_VERS(FILE *file, struct TapeInfo *tape) @@ -11094,9 +7659,6 @@ void SaveTape(int nr) { char *filename = getTapeFilename(nr); FILE *file; -#if 0 - boolean new_tape = TRUE; -#endif int num_participating_players = 0; int info_chunk_size; int body_chunk_size; @@ -11104,16 +7666,6 @@ void SaveTape(int nr) InitTapeDirectory(leveldir_current->subdir); -#if 0 - /* if a tape still exists, ask to overwrite it */ - if (fileExists(filename)) - { - new_tape = FALSE; - if (!Request("Replace old tape?", REQ_ASK)) - return; - } -#endif - if (!(file = fopen(filename, MODE_WRITE))) { Error(ERR_WARN, "cannot save level recording file '%s'", filename); @@ -11151,11 +7703,6 @@ void SaveTape(int nr) SetFilePermissions(filename, PERMS_PRIVATE); tape.changed = FALSE; - -#if 0 - if (new_tape) - Request("Tape saved!", REQ_CONFIRM); -#endif } boolean SaveTapeChecked(int nr) @@ -11523,7 +8070,6 @@ static struct TokenInfo global_setup_tokens[] = static boolean not_used = FALSE; static struct TokenInfo editor_setup_tokens[] = { -#if 1 { TYPE_SWITCH, ¬_used, "editor.el_boulderdash" }, { TYPE_SWITCH, ¬_used, "editor.el_emerald_mine" }, { TYPE_SWITCH, ¬_used, "editor.el_emerald_mine_club" }, @@ -11532,24 +8078,10 @@ static struct TokenInfo editor_setup_tokens[] = { TYPE_SWITCH, ¬_used, "editor.el_supaplex" }, { TYPE_SWITCH, ¬_used, "editor.el_diamond_caves" }, { TYPE_SWITCH, ¬_used, "editor.el_dx_boulderdash" }, -#else - { TYPE_SWITCH, &sei.el_boulderdash, "editor.el_boulderdash" }, - { TYPE_SWITCH, &sei.el_emerald_mine, "editor.el_emerald_mine" }, - { TYPE_SWITCH, &sei.el_emerald_mine_club,"editor.el_emerald_mine_club"}, - { TYPE_SWITCH, &sei.el_more, "editor.el_more" }, - { TYPE_SWITCH, &sei.el_sokoban, "editor.el_sokoban" }, - { TYPE_SWITCH, &sei.el_supaplex, "editor.el_supaplex" }, - { TYPE_SWITCH, &sei.el_diamond_caves, "editor.el_diamond_caves" }, - { TYPE_SWITCH, &sei.el_dx_boulderdash,"editor.el_dx_boulderdash" }, -#endif { TYPE_SWITCH, &sei.el_chars, "editor.el_chars" }, { TYPE_SWITCH, &sei.el_steel_chars, "editor.el_steel_chars" }, { TYPE_SWITCH, &sei.el_custom, "editor.el_custom" }, -#if 1 { TYPE_SWITCH, ¬_used, "editor.el_headlines" }, -#else - { TYPE_SWITCH, &sei.el_headlines, "editor.el_headlines" }, -#endif { TYPE_SWITCH, &sei.el_user_defined, "editor.el_user_defined" }, { TYPE_SWITCH, &sei.el_dynamic, "editor.el_dynamic" }, { TYPE_SWITCH, &sei.el_by_game, "editor.el_by_game" }, @@ -12079,19 +8611,10 @@ void LoadCustomElementDescriptions() static int getElementFromToken(char *token) { -#if 1 char *value = getHashEntry(element_token_hash, token); if (value != NULL) return atoi(value); -#else - int i; - - /* !!! OPTIMIZE THIS BY USING HASH !!! */ - for (i = 0; i < MAX_NUM_ELEMENTS; i++) - if (strEqual(token, element_info[i].token_name)) - return i; -#endif Error(ERR_WARN, "unknown element token '%s'", token); @@ -12109,25 +8632,8 @@ static int get_token_parameter_value(char *token, char *value_raw) if (suffix == NULL) suffix = token; -#if 1 if (strEqual(suffix, ".element")) return getElementFromToken(value_raw); -#endif - -#if 0 - if (strncmp(suffix, ".font", 5) == 0) - { - int i; - - /* !!! OPTIMIZE THIS BY USING HASH !!! */ - for (i = 0; i < NUM_FONTS; i++) - if (strEqual(value_raw, font_info[i].token_name)) - return i; - - /* if font not found, use reliable default value */ - return FONT_INITIAL_1; - } -#endif /* !!! USE CORRECT VALUE TYPE (currently works also for TYPE_BOOLEAN) !!! */ return get_parameter_value(value_raw, suffix, TYPE_INTEGER); @@ -12135,24 +8641,8 @@ static int get_token_parameter_value(char *token, char *value_raw) void InitMenuDesignSettings_Static() { -#if 0 - static SetupFileHash *image_config_hash = NULL; -#endif int i; -#if 0 - if (image_config_hash == NULL) - { - image_config_hash = newSetupFileHash(); - - for (i = 0; image_config[i].token != NULL; i++) - setHashEntry(image_config_hash, - image_config[i].token, - image_config[i].value); - } -#endif - -#if 1 /* always start with reliable default values from static default config */ for (i = 0; image_config_vars[i].token != NULL; i++) { @@ -12162,19 +8652,6 @@ void InitMenuDesignSettings_Static() *image_config_vars[i].value = get_token_parameter_value(image_config_vars[i].token, value); } - -#else - - int j; - - /* always start with reliable default values from static default config */ - for (i = 0; image_config_vars[i].token != NULL; i++) - for (j = 0; image_config[j].token != NULL; j++) - if (strEqual(image_config_vars[i].token, image_config[j].token)) - *image_config_vars[i].value = - get_token_parameter_value(image_config_vars[i].token, - image_config[j].value); -#endif } static void InitMenuDesignSettings_SpecialPreProcessing() @@ -12268,10 +8745,6 @@ static void LoadMenuDesignSettingsFromFilename(char *filename) SetupFileHash *setup_file_hash; int i, j, k; -#if 0 - printf("LoadMenuDesignSettings from file '%s' ...\n", filename); -#endif - if ((setup_file_hash = loadSetupFileHash(filename)) == NULL) return; @@ -12482,11 +8955,7 @@ void LoadMenuDesignSettings() InitMenuDesignSettings_Static(); InitMenuDesignSettings_SpecialPreProcessing(); -#if 1 if (!GFX_OVERRIDE_ARTWORK(ARTWORK_TYPE_GRAPHICS)) -#else - if (!SETUP_OVERRIDE_ARTWORK(setup, ARTWORK_TYPE_GRAPHICS)) -#endif { /* first look for special settings configured in level series config */ filename_base = getCustomArtworkLevelConfigFilename(ARTWORK_TYPE_GRAPHICS); @@ -12625,10 +9094,6 @@ static struct MusicFileInfo *get_music_file_info_ext(char *basename, int music, *strrchr(filename_prefix, '.') = '\0'; filename_info = getStringCat2(filename_prefix, ".txt"); -#if 0 - printf("trying to load file '%s'...\n", filename_info); -#endif - if (fileExists(filename_info)) setup_file_hash = loadSetupFileHash(filename_info); @@ -12642,10 +9107,6 @@ static struct MusicFileInfo *get_music_file_info_ext(char *basename, int music, filename_prefix = getStringCopy(filename_music); filename_info = getStringCat2(filename_prefix, ".txt"); -#if 0 - printf("trying to load file '%s'...\n", filename_info); -#endif - if (fileExists(filename_info)) setup_file_hash = loadSetupFileHash(filename_info); @@ -12708,8 +9169,6 @@ static boolean sound_info_listed(struct MusicFileInfo *list, char *basename) return music_info_listed_ext(list, basename, TRUE); } -#if 1 - void LoadMusicInfo() { char *music_directory = getCustomMusicDirectory(); @@ -12759,17 +9218,10 @@ void LoadMusicInfo() if (!FileIsMusic(music->filename)) continue; -#if 0 - printf("::: -> '%s' (configured)\n", music->filename); -#endif - if (!music_info_listed(music_file_info, music->filename)) { *new = get_music_file_info(music->filename, i); -#if 0 - if (*new != NULL) - printf(":1: adding '%s' ['%s'] ...\n", (*new)->title, music->filename); -#endif + if (*new != NULL) new = &(*new)->next; } @@ -12808,169 +9260,10 @@ void LoadMusicInfo() if (!FileIsMusic(basename)) continue; -#if 0 - printf("::: -> '%s' (found in directory)\n", basename); -#endif - if (!music_info_listed(music_file_info, basename)) { *new = get_music_file_info(basename, MAP_NOCONF_MUSIC(num_music_noconf)); -#if 0 - if (*new != NULL) - printf(":2: adding '%s' ['%s'] ...\n", (*new)->title, basename); -#endif - if (*new != NULL) - new = &(*new)->next; - } - - num_music_noconf++; - } - - closeDirectory(dir); - - for (i = 0; i < num_sounds; i++) - { - sound = getSoundListEntry(i); - - if (sound->filename == NULL) - continue; - - if (strEqual(sound->filename, UNDEFINED_FILENAME)) - continue; - - /* a configured file may be not recognized as sound */ - if (!FileIsSound(sound->filename)) - continue; - -#if 0 - printf("::: -> '%s' (configured)\n", sound->filename); -#endif - if (!sound_info_listed(music_file_info, sound->filename)) - { - *new = get_sound_file_info(sound->filename, i); - if (*new != NULL) - new = &(*new)->next; - } - } - -#if 0 - for (next = music_file_info; next != NULL; next = next->next) - printf("::: title == '%s'\n", next->title); -#endif -} - -#else - -void LoadMusicInfo() -{ - char *music_directory = getCustomMusicDirectory(); - int num_music = getMusicListSize(); - int num_music_noconf = 0; - int num_sounds = getSoundListSize(); - DIR *dir; - struct dirent *dir_entry; - struct FileInfo *music, *sound; - struct MusicFileInfo *next, **new; - int i; - - while (music_file_info != NULL) - { - next = music_file_info->next; - - checked_free(music_file_info->basename); - - checked_free(music_file_info->title_header); - checked_free(music_file_info->artist_header); - checked_free(music_file_info->album_header); - checked_free(music_file_info->year_header); - - checked_free(music_file_info->title); - checked_free(music_file_info->artist); - checked_free(music_file_info->album); - checked_free(music_file_info->year); - - free(music_file_info); - - music_file_info = next; - } - - new = &music_file_info; - - for (i = 0; i < num_music; i++) - { - music = getMusicListEntry(i); - - if (music->filename == NULL) - continue; - - if (strEqual(music->filename, UNDEFINED_FILENAME)) - continue; - - /* a configured file may be not recognized as music */ - if (!FileIsMusic(music->filename)) - continue; - -#if 0 - printf("::: -> '%s' (configured)\n", music->filename); -#endif - - if (!music_info_listed(music_file_info, music->filename)) - { - *new = get_music_file_info(music->filename, i); -#if 0 - if (*new != NULL) - printf(":1: adding '%s' ['%s'] ...\n", (*new)->title, music->filename); -#endif - if (*new != NULL) - new = &(*new)->next; - } - } - - if ((dir = opendir(music_directory)) == NULL) - { - Error(ERR_WARN, "cannot read music directory '%s'", music_directory); - return; - } - - while ((dir_entry = readdir(dir)) != NULL) /* loop until last dir entry */ - { - char *basename = dir_entry->d_name; - boolean music_already_used = FALSE; - int i; - - /* skip all music files that are configured in music config file */ - for (i = 0; i < num_music; i++) - { - music = getMusicListEntry(i); - - if (music->filename == NULL) - continue; - - if (strEqual(basename, music->filename)) - { - music_already_used = TRUE; - break; - } - } - - if (music_already_used) - continue; - - if (!FileIsMusic(basename)) - continue; - -#if 0 - printf("::: -> '%s' (found in directory)\n", basename); -#endif - - if (!music_info_listed(music_file_info, basename)) - { - *new = get_music_file_info(basename, MAP_NOCONF_MUSIC(num_music_noconf)); -#if 0 - if (*new != NULL) - printf(":2: adding '%s' ['%s'] ...\n", (*new)->title, basename); -#endif if (*new != NULL) new = &(*new)->next; } @@ -12978,7 +9271,7 @@ void LoadMusicInfo() num_music_noconf++; } - closedir(dir); + closeDirectory(dir); for (i = 0; i < num_sounds; i++) { @@ -12994,10 +9287,6 @@ void LoadMusicInfo() if (!FileIsSound(sound->filename)) continue; -#if 0 - printf("::: -> '%s' (configured)\n", sound->filename); -#endif - if (!sound_info_listed(music_file_info, sound->filename)) { *new = get_sound_file_info(sound->filename, i); @@ -13005,15 +9294,8 @@ void LoadMusicInfo() new = &(*new)->next; } } - -#if 0 - for (next = music_file_info; next != NULL; next = next->next) - printf("::: title == '%s'\n", next->title); -#endif } -#endif - void add_helpanim_entry(int element, int action, int direction, int delay, int *num_list_entries) { @@ -13570,10 +9852,3 @@ void CreateCustomElementImages() CloseAllAndExit(0); #endif } - -#if 0 -void CreateLevelSketchImages_TEST() -{ - void CreateCustomElementImages() -} -#endif diff --git a/src/game.c b/src/game.c index 28905e56..ba066ed9 100644 --- a/src/game.c +++ b/src/game.c @@ -28,49 +28,10 @@ #define USE_NEW_AMOEBA_CODE FALSE /* EXPERIMENTAL STUFF */ -#define USE_NEW_STUFF ( 1) - -#define USE_NEW_SP_SLIPPERY (USE_NEW_STUFF * 1) -#define USE_NEW_CUSTOM_VALUE (USE_NEW_STUFF * 1) -#define USE_NEW_PLAYER_ANIM (USE_NEW_STUFF * 1) -#define USE_NEW_ALL_SLIPPERY (USE_NEW_STUFF * 1) -#define USE_NEW_PLAYER_SPEED (USE_NEW_STUFF * 1) -#define USE_NEW_DELAYED_ACTION (USE_NEW_STUFF * 1) -#define USE_NEW_SNAP_DELAY (USE_NEW_STUFF * 1) -#define USE_ONLY_ONE_CHANGE_PER_FRAME (USE_NEW_STUFF * 1) -#define USE_ONE_MORE_CHANGE_PER_FRAME (USE_NEW_STUFF * 1) -#define USE_FIXED_DONT_RUN_INTO (USE_NEW_STUFF * 1) -#define USE_NEW_SPRING_BUMPER (USE_NEW_STUFF * 1) -#define USE_STOP_CHANGED_ELEMENTS (USE_NEW_STUFF * 1) -#define USE_ELEMENT_TOUCHING_BUGFIX (USE_NEW_STUFF * 1) -#define USE_NEW_CONTINUOUS_SNAPPING (USE_NEW_STUFF * 1) -#define USE_GFX_RESET_GFX_ANIMATION (USE_NEW_STUFF * 1) -#define USE_BOTH_SWITCHGATE_SWITCHES (USE_NEW_STUFF * 1) -#define USE_PLAYER_GRAVITY (USE_NEW_STUFF * 1) -#define USE_FIXED_BORDER_RUNNING_GFX (USE_NEW_STUFF * 1) -#define USE_QUICKSAND_BD_ROCK_BUGFIX (USE_NEW_STUFF * 0) - -#define USE_QUICKSAND_IMPACT_BUGFIX (USE_NEW_STUFF * 0) - -#define USE_CODE_THAT_BREAKS_SNAKE_BITE (USE_NEW_STUFF * 1) - -#define USE_UFAST_PLAYER_EXIT_BUGFIX (USE_NEW_STUFF * 1) - -#define USE_GFX_RESET_ONLY_WHEN_MOVING (USE_NEW_STUFF * 1) -#define USE_GFX_RESET_PLAYER_ARTWORK (USE_NEW_STUFF * 1) - -#define USE_FIX_KILLED_BY_NON_WALKABLE (USE_NEW_STUFF * 1) -#define USE_FIX_IMPACT_COLLISION (USE_NEW_STUFF * 1) -#define USE_FIX_CE_ACTION_WITH_PLAYER (USE_NEW_STUFF * 1) -#define USE_FIX_NO_ACTION_AFTER_CHANGE (USE_NEW_STUFF * 1) - -#define USE_PLAYER_REANIMATION (USE_NEW_STUFF * 1) - -#define USE_GFX_RESET_WHEN_NOT_MOVING (USE_NEW_STUFF * 1) - -#define USE_NEW_PLAYER_ASSIGNMENTS (USE_NEW_STUFF * 1) - -#define USE_DELAYED_GFX_REDRAW (USE_NEW_STUFF * 0) +#define USE_QUICKSAND_BD_ROCK_BUGFIX 0 +#define USE_QUICKSAND_IMPACT_BUGFIX 0 +#define USE_DELAYED_GFX_REDRAW 0 +#define USE_NEW_PLAYER_ASSIGNMENTS 1 #if USE_DELAYED_GFX_REDRAW #define TEST_DrawLevelField(x, y) \ @@ -1047,9 +1008,6 @@ static void KillPlayerUnlessExplosionProtected(int, int); static void TestIfPlayerTouchesCustomElement(int, int); static void TestIfElementTouchesCustomElement(int, int); static void TestIfElementHitsCustomElement(int, int, int); -#if 0 -static void TestIfElementSmashesCustomElement(int, int, int); -#endif static void HandleElementChange(int, int, int); static void ExecuteCustomElementAction(int, int, int, int); @@ -1235,11 +1193,7 @@ static struct ChangingElementInfo change_delay_list[] = }, { EL_EM_EXIT_CLOSING, -#if 1 EL_EMPTY, -#else - EL_EM_EXIT_CLOSED, -#endif 29, NULL, NULL, @@ -1255,11 +1209,7 @@ static struct ChangingElementInfo change_delay_list[] = }, { EL_EM_STEEL_EXIT_CLOSING, -#if 1 EL_STEELWALL, -#else - EL_EM_STEEL_EXIT_CLOSED, -#endif 29, NULL, NULL, @@ -1761,7 +1711,6 @@ static void InitPlayerField(int x, int y, int element, boolean init_game) player->jy = player->last_jy = y; } -#if USE_PLAYER_REANIMATION if (!init_game) { int player_nr = GET_PLAYER_NR(element); @@ -1770,7 +1719,6 @@ static void InitPlayerField(int x, int y, int element, boolean init_game) if (player->active && player->killed) player->reanimated = TRUE; /* if player was just killed, reanimate him */ } -#endif } static void InitField(int x, int y, boolean init_game) @@ -1923,18 +1871,6 @@ static void InitField(int x, int y, boolean init_game) } break; -#if !USE_BOTH_SWITCHGATE_SWITCHES - case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */ - if (init_game) - Feld[x][y] = EL_SWITCHGATE_SWITCH_UP; - break; - - case EL_DC_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */ - if (init_game) - Feld[x][y] = EL_DC_SWITCHGATE_SWITCH_UP; - break; -#endif - case EL_LIGHT_SWITCH_ACTIVE: if (init_game) game.light_time_left = level.time_light * FRAMES_PER_SECOND; @@ -1992,10 +1928,8 @@ static void InitField(int x, int y, boolean init_game) if (CAN_MOVE(element)) InitMovDir(x, y); -#if USE_NEW_CUSTOM_VALUE if (!element_info[element].use_last_ce_value || init_game) CustomValue[x][y] = GET_NEW_CE_VALUE(Feld[x][y]); -#endif } else if (IS_GROUP_ELEMENT(element)) { @@ -2401,12 +2335,8 @@ void UpdateGameControlValues() game_panel_controls[GAME_PANEL_MAGIC_WALL_TIME].value = game.magic_wall_time_left; -#if USE_PLAYER_GRAVITY game_panel_controls[GAME_PANEL_GRAVITY_STATE].value = local_player->gravity; -#else - game_panel_controls[GAME_PANEL_GRAVITY_STATE].value = game.gravity; -#endif for (i = 0; i < NUM_PANEL_GRAPHICS; i++) game_panel_controls[GAME_PANEL_GRAPHIC_1 + i].value = EL_GRAPHIC_1 + i; @@ -2503,47 +2433,25 @@ void DisplayGameControlValues() return; /* copy default game door content to main double buffer */ -#if 1 + /* !!! CHECK AGAIN !!! */ SetPanelBackground(); // SetDoorBackgroundImage(IMG_BACKGROUND_PANEL); DrawBackground(DX, DY, DXSIZE, DYSIZE); -#else - BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, - DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY); -#endif /* redraw game control buttons */ -#if 1 RedrawGameButtons(); -#else - UnmapGameButtons(); - MapGameButtons(); -#endif game_status = GAME_MODE_PSEUDO_PANEL; -#if 1 for (i = 0; i < NUM_GAME_PANEL_CONTROLS; i++) -#else - for (i = 0; game_panel_controls[i].nr != -1; i++) -#endif { -#if 1 int nr = game_panel_order[i].nr; struct GamePanelControlInfo *gpc = &game_panel_controls[nr]; -#else - struct GamePanelControlInfo *gpc = &game_panel_controls[i]; - int nr = gpc->nr; -#endif struct TextPosInfo *pos = gpc->pos; int type = gpc->type; int value = gpc->value; int frame = gpc->frame; -#if 0 - int last_value = gpc->last_value; - int last_frame = gpc->last_frame; -#endif int size = pos->size; int font = pos->font; boolean draw_masked = pos->draw_masked; @@ -2552,18 +2460,9 @@ void DisplayGameControlValues() if (PANEL_DEACTIVATED(pos)) continue; -#if 0 - if (value == last_value && frame == last_frame) - continue; -#endif - gpc->last_value = value; gpc->last_frame = frame; -#if 0 - printf("::: value %d changed from %d to %d\n", nr, last_value, value); -#endif - if (type == TYPE_INTEGER) { if (nr == GAME_PANEL_LEVEL_NUMBER || @@ -2581,33 +2480,15 @@ void DisplayGameControlValues() size = (value < value_change ? size1 : size2); font = (value < value_change ? font1 : font2); - -#if 0 - /* clear background if value just changed its size (dynamic digits) */ - if ((last_value < value_change) != (value < value_change)) - { - int width1 = size1 * getFontWidth(font1); - int width2 = size2 * getFontWidth(font2); - int max_width = MAX(width1, width2); - int max_height = MAX(getFontHeight(font1), getFontHeight(font2)); - - pos->width = max_width; - - ClearRectangleOnBackground(drawto, PANEL_XPOS(pos), PANEL_YPOS(pos), - max_width, max_height); - } -#endif } } -#if 1 /* correct text size if "digits" is zero or less */ if (size <= 0) size = strlen(int2str(value, size)); /* dynamically correct text alignment */ pos->width = size * getFontWidth(font); -#endif DrawTextExt(drawto, PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, size), font, mask_mode); @@ -2621,7 +2502,6 @@ void DisplayGameControlValues() int dst_x = PANEL_XPOS(pos); int dst_y = PANEL_YPOS(pos); -#if 1 if (value != EL_UNDEFINED && value != EL_EMPTY) { element = value; @@ -2629,10 +2509,8 @@ void DisplayGameControlValues() // printf("::: %d, '%s' [%d]\n", element, EL_NAME(element), size); -#if 1 if (element >= EL_GRAPHIC_1 && element <= EL_GRAPHIC_8 && size == 0) size = TILESIZE; -#endif getSizedGraphicSource(graphic, frame, size, &src_bitmap, &src_x, &src_y); @@ -2653,29 +2531,6 @@ void DisplayGameControlValues() dst_x, dst_y); } } -#else - if (value == EL_UNDEFINED || value == EL_EMPTY) - { - element = (last_value == EL_UNDEFINED ? EL_EMPTY : last_value); - graphic = el2panelimg(element); - - src_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap; - src_x = DOOR_GFX_PAGEX5 + ALIGNED_TEXT_XPOS(pos); - src_y = DOOR_GFX_PAGEY1 + ALIGNED_TEXT_YPOS(pos); - } - else - { - element = value; - graphic = el2panelimg(value); - - getSizedGraphicSource(graphic, frame, size, &src_bitmap, &src_x,&src_y); - } - - width = graphic_info[graphic].width * size / TILESIZE; - height = graphic_info[graphic].height * size / TILESIZE; - - BlitBitmap(src_bitmap, drawto, src_x, src_y, width, height, dst_x, dst_y); -#endif } else if (type == TYPE_STRING) { @@ -2692,20 +2547,6 @@ void DisplayGameControlValues() { int font1 = pos->font; /* (used for normal state) */ int font2 = pos->font_alt; /* (used for active state) */ -#if 0 - int size1 = strlen(state_normal); - int size2 = strlen(state_active); - int width1 = size1 * getFontWidth(font1); - int width2 = size2 * getFontWidth(font2); - int max_width = MAX(width1, width2); - int max_height = MAX(getFontHeight(font1), getFontHeight(font2)); - - pos->width = max_width; - - /* clear background for values that may have changed its size */ - ClearRectangleOnBackground(drawto, PANEL_XPOS(pos), PANEL_YPOS(pos), - max_width, max_height); -#endif font = (active ? font2 : font1); } @@ -2714,7 +2555,6 @@ void DisplayGameControlValues() { char *s_cut; -#if 1 if (size <= 0) { /* don't truncate output if "chars" is zero or less */ @@ -2723,7 +2563,6 @@ void DisplayGameControlValues() /* dynamically correct text alignment */ pos->width = size * getFontWidth(font); } -#endif s_cut = getStringCopyN(s, size); @@ -2749,216 +2588,6 @@ void UpdateAndDisplayGameControlValues() DisplayGameControlValues(); } -void DrawGameValue_Emeralds(int value) -{ - struct TextPosInfo *pos = &game.panel.gems; - int font_nr = pos->font; - int font_width = getFontWidth(font_nr); - int chars = pos->size; - -#if 1 - return; /* !!! USE NEW STUFF !!! */ -#endif - - if (PANEL_DEACTIVATED(pos)) - return; - - pos->width = chars * font_width; - - DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, chars), font_nr); -} - -void DrawGameValue_Dynamite(int value) -{ - struct TextPosInfo *pos = &game.panel.inventory_count; - int font_nr = pos->font; - int font_width = getFontWidth(font_nr); - int chars = pos->size; - -#if 1 - return; /* !!! USE NEW STUFF !!! */ -#endif - - if (PANEL_DEACTIVATED(pos)) - return; - - pos->width = chars * font_width; - - DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, chars), font_nr); -} - -void DrawGameValue_Score(int value) -{ - struct TextPosInfo *pos = &game.panel.score; - int font_nr = pos->font; - int font_width = getFontWidth(font_nr); - int chars = pos->size; - -#if 1 - return; /* !!! USE NEW STUFF !!! */ -#endif - - if (PANEL_DEACTIVATED(pos)) - return; - - pos->width = chars * font_width; - - DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, chars), font_nr); -} - -void DrawGameValue_Time(int value) -{ - struct TextPosInfo *pos = &game.panel.time; - static int last_value = -1; - int chars1 = 3; - int chars2 = 4; - int chars = pos->size; - int font1_nr = pos->font; - int font2_nr = pos->font_alt; - int font_nr = font1_nr; - boolean use_dynamic_chars = (chars == -1 ? TRUE : FALSE); - -#if 1 - return; /* !!! USE NEW STUFF !!! */ -#endif - - if (PANEL_DEACTIVATED(pos)) - return; - - if (use_dynamic_chars) /* use dynamic number of chars */ - { - chars = (value < 1000 ? chars1 : chars2); - font_nr = (value < 1000 ? font1_nr : font2_nr); - } - - /* clear background if value just changed its size (dynamic chars only) */ - if (use_dynamic_chars && (last_value < 1000) != (value < 1000)) - { - int width1 = chars1 * getFontWidth(font1_nr); - int width2 = chars2 * getFontWidth(font2_nr); - int max_width = MAX(width1, width2); - int max_height = MAX(getFontHeight(font1_nr), getFontHeight(font2_nr)); - - pos->width = max_width; - - ClearRectangleOnBackground(drawto, PANEL_XPOS(pos), PANEL_YPOS(pos), - max_width, max_height); - } - - pos->width = chars * getFontWidth(font_nr); - - DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, chars), font_nr); - - last_value = value; -} - -void DrawGameValue_Level(int value) -{ - struct TextPosInfo *pos = &game.panel.level_number; - int chars1 = 2; - int chars2 = 3; - int chars = pos->size; - int font1_nr = pos->font; - int font2_nr = pos->font_alt; - int font_nr = font1_nr; - boolean use_dynamic_chars = (chars == -1 ? TRUE : FALSE); - -#if 1 - return; /* !!! USE NEW STUFF !!! */ -#endif - - if (PANEL_DEACTIVATED(pos)) - return; - - if (use_dynamic_chars) /* use dynamic number of chars */ - { - chars = (level_nr < 100 ? chars1 : chars2); - font_nr = (level_nr < 100 ? font1_nr : font2_nr); - } - - pos->width = chars * getFontWidth(font_nr); - - DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, chars), font_nr); -} - -void DrawGameValue_Keys(int key[MAX_NUM_KEYS]) -{ - int i; - -#if 1 - return; /* !!! USE NEW STUFF !!! */ -#endif - - for (i = 0; i < MAX_NUM_KEYS; i++) - { - struct TextPosInfo *pos = &game.panel.key[i]; - int src_x = DOOR_GFX_PAGEX5 + 18 + (i % 4) * MINI_TILEX; - int src_y = DOOR_GFX_PAGEY1 + 123; - int dst_x = PANEL_XPOS(pos); - int dst_y = PANEL_YPOS(pos); - - int element = (i >= STD_NUM_KEYS ? EL_EMC_KEY_5 - 4 : - level.game_engine_type == GAME_ENGINE_TYPE_EM ? EL_EM_KEY_1 : - EL_KEY_1) + i; - int graphic = el2edimg(element); - - if (PANEL_DEACTIVATED(pos)) - continue; - -#if 0 - /* masked blit with tiles from half-size scaled bitmap does not work yet - (no mask bitmap created for these sizes after loading and scaling) -- - solution: load without creating mask, scale, then create final mask */ - - BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, src_x, src_y, - MINI_TILEX, MINI_TILEY, dst_x, dst_y); - - if (key[i]) - { - Bitmap *src_bitmap; - int src_x, src_y; - - getMiniGraphicSource(graphic, &src_bitmap, &src_x, &src_y); - - SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc, - dst_x - src_x, dst_y - src_y); - BlitBitmapMasked(src_bitmap, drawto, src_x, src_y, MINI_TILEX, MINI_TILEY, - dst_x, dst_y); - } -#else - if (key[i]) - DrawMiniGraphicExt(drawto, dst_x, dst_y, graphic); - else - BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, src_x, src_y, - MINI_TILEX, MINI_TILEY, dst_x, dst_y); -#endif - } -} - -void DrawAllGameValues(int emeralds, int dynamite, int score, int time, - int key_bits) -{ - int key[MAX_NUM_KEYS]; - int i; - - /* prevent EM engine from updating time/score values parallel to GameWon() */ - if (level.game_engine_type == GAME_ENGINE_TYPE_EM && - local_player->LevelSolved) - return; - - for (i = 0; i < MAX_NUM_KEYS; i++) - key[i] = key_bits & (1 << i); - - DrawGameValue_Level(level_nr); - - DrawGameValue_Emeralds(emeralds); - DrawGameValue_Dynamite(dynamite); - DrawGameValue_Score(score); - DrawGameValue_Time(time); - - DrawGameValue_Keys(key); -} - void UpdateGameDoorValues() { UpdateGameControlValues(); @@ -2969,49 +2598,6 @@ void DrawGameDoorValues() DisplayGameControlValues(); } -void DrawGameDoorValues_OLD() -{ - int time_value = (game.no_time_limit ? TimePlayed : TimeLeft); - int dynamite_value = 0; - int score_value = (local_player->LevelSolved ? local_player->score_final : - local_player->score); - int gems_value = local_player->gems_still_needed; - int key_bits = 0; - int i, j; - - if (level.game_engine_type == GAME_ENGINE_TYPE_EM) - { - DrawGameDoorValues_EM(); - - return; - } - - if (game.centered_player_nr == -1) - { - for (i = 0; i < MAX_PLAYERS; i++) - { - for (j = 0; j < MAX_NUM_KEYS; j++) - if (stored_player[i].key[j]) - key_bits |= (1 << j); - - dynamite_value += stored_player[i].inventory_size; - } - } - else - { - int player_nr = game.centered_player_nr; - - for (i = 0; i < MAX_NUM_KEYS; i++) - if (stored_player[player_nr].key[i]) - key_bits |= (1 << i); - - dynamite_value = stored_player[player_nr].inventory_size; - } - - DrawAllGameValues(gems_value, dynamite_value, score_value, time_value, - key_bits); -} - /* ============================================================================= @@ -3110,39 +2696,10 @@ static void InitGameEngine() game.use_block_last_field_bug = (game.engine_version < VERSION_IDENT(3,1,1,0)); - /* - Summary of bugfix/change: - Changed behaviour of CE changes with multiple changes per single frame. - - Fixed/changed in version: - 3.2.0-6 - - Description: - Before 3.2.0-6, only one single CE change was allowed in each engine frame. - This resulted in race conditions where CEs seem to behave strange in some - situations (where triggered CE changes were just skipped because there was - already a CE change on that tile in the playfield in that engine frame). - Since 3.2.0-6, this was changed to allow up to MAX_NUM_CHANGES_PER_FRAME. - (The number of changes per frame must be limited in any case, because else - it is easily possible to define CE changes that would result in an infinite - loop, causing the whole game to freeze. The MAX_NUM_CHANGES_PER_FRAME value - should be set large enough so that it would only be reached in cases where - the corresponding CE change conditions run into a loop. Therefore, it seems - to be reasonable to set MAX_NUM_CHANGES_PER_FRAME to the same value as the - maximal number of change pages for custom elements.) - - Affected levels/tapes: - Probably many. - */ + /* ---------------------------------------------------------------------- */ -#if USE_ONLY_ONE_CHANGE_PER_FRAME + /* set maximal allowed number of custom element changes per game frame */ game.max_num_changes_per_frame = 1; -#else - game.max_num_changes_per_frame = - (game.engine_version < VERSION_IDENT(3,2,0,6) ? 1 : 32); -#endif - - /* ---------------------------------------------------------------------- */ /* default scan direction: scan playfield from top/left to bottom/right */ InitPlayfieldScanMode(CA_ARG_SCAN_MODE_NORMAL); @@ -3264,7 +2821,6 @@ static void InitGameEngine() } } -#if 1 /* ---------- initialize reference elements in change conditions --------- */ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++) @@ -3283,7 +2839,6 @@ static void InitGameEngine() ei->change_page[j].trigger_element = trigger_element; } } -#endif /* ---------- initialize run-time trigger player and element ------------- */ @@ -3524,65 +3079,27 @@ void InitGame() boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */ boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */ boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */ -#if 0 - boolean do_fading = (game_status == GAME_MODE_MAIN); -#endif -#if 1 int initial_move_dir = MV_DOWN; -#else - int initial_move_dir = MV_NONE; -#endif int i, j, x, y; -#if 1 game_status = GAME_MODE_PLAYING; -#endif - -#if 1 StopAnimation(); if (!game.restart_level) CloseDoor(DOOR_CLOSE_1); -#if 1 if (level_editor_test_game) FadeSkipNextFadeIn(); else FadeSetEnterScreen(); -#else - if (level_editor_test_game) - fading = fading_none; - else - fading = menu.destination; -#endif -#if 1 FadeOut(REDRAW_FIELD); -#else - if (do_fading) - FadeOut(REDRAW_FIELD); -#endif - -#endif - -#if 0 - printf("::: FADING OUT: DONE\n"); - Delay(1000); -#endif - -#if 0 - game_status = GAME_MODE_PLAYING; -#endif -#if 1 /* needed if different viewport properties defined for playing */ ChangeViewportPropertiesIfNeeded(); -#endif -#if 1 DrawCompleteVideoDisplay(); -#endif InitGameEngine(); InitGameControlValues(); @@ -3782,11 +3299,6 @@ void InitGame() game.switchgate_pos = 0; game.wind_direction = level.wind_direction_initial; -#if !USE_PLAYER_GRAVITY - game.gravity = FALSE; - game.explosions_delayed = TRUE; -#endif - game.lenses_time_left = 0; game.magnify_time_left = 0; @@ -3829,9 +3341,7 @@ void InitGame() MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0; ChangeDelay[x][y] = 0; ChangePage[x][y] = -1; -#if USE_NEW_CUSTOM_VALUE CustomValue[x][y] = 0; /* initialized in InitField() */ -#endif Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0; AmoebaNr[x][y] = 0; WasJustMoving[x][y] = 0; @@ -3892,7 +3402,6 @@ void InitGame() emulate_sb ? EMU_SOKOBAN : emulate_sp ? EMU_SUPAPLEX : EMU_NONE); -#if USE_NEW_ALL_SLIPPERY /* initialize type of slippery elements */ for (i = 0; i < MAX_NUM_ELEMENTS; i++) { @@ -3910,7 +3419,6 @@ void InitGame() element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT; } } -#endif /* initialize explosion and ignition delay */ for (i = 0; i < MAX_NUM_ELEMENTS; i++) @@ -3930,14 +3438,6 @@ void InitGame() if (i == EL_BLACK_ORB) element_info[i].ignition_delay = 1; } - -#if 0 - if (element_info[i].explosion_delay < 1) /* !!! check again !!! */ - element_info[i].explosion_delay = 1; - - if (element_info[i].ignition_delay < 1) /* !!! check again !!! */ - element_info[i].ignition_delay = 1; -#endif } /* correct non-moving belts to start moving left */ @@ -3956,23 +3456,10 @@ void InitGame() local_player->connected = TRUE; /* !!! SAME AS init.c:InitPlayerInfo() -- FIX THIS !!! */ -#if 0 - printf("::: TEAM MODE: %d\n", game.team_mode); -#endif - if (tape.playing) { -#if 1 for (i = 0; i < MAX_PLAYERS; i++) stored_player[i].connected = tape.player_participates[i]; -#else - /* try to guess locally connected team mode players (needed for correct - assignment of player figures from level to locally playing players) */ - - for (i = 0; i < MAX_PLAYERS; i++) - if (tape.player_participates[i]) - stored_player[i].connected = TRUE; -#endif } else if (game.team_mode && !options.network) { @@ -4029,7 +3516,6 @@ void InitGame() /* assign first free player found that is present in the playfield */ -#if 1 /* first try: look for unmapped playfield player that is not connected */ for (j = 0; j < MAX_PLAYERS; j++) if (field_player == NULL && @@ -4044,22 +3530,6 @@ void InitGame() stored_player[j].present && !stored_player[j].mapped) field_player = &stored_player[j]; -#else - /* first try: look for unmapped playfield player that is not connected */ - if (field_player == NULL) - for (j = 0; j < MAX_PLAYERS; j++) - if (stored_player[j].present && - !stored_player[j].mapped && - !stored_player[j].connected) - field_player = &stored_player[j]; - - /* second try: look for *any* unmapped playfield player */ - if (field_player == NULL) - for (j = 0; j < MAX_PLAYERS; j++) - if (stored_player[j].present && - !stored_player[j].mapped) - field_player = &stored_player[j]; -#endif if (field_player != NULL) { @@ -4182,26 +3652,25 @@ void InitGame() #if USE_NEW_PLAYER_ASSIGNMENTS -#if 1 if (!game.team_mode) -#endif - - for (i = 0; i < MAX_PLAYERS; i++) { - if (stored_player[i].active && - !tape.player_participates[map_player_action[i]]) + for (i = 0; i < MAX_PLAYERS; i++) { - struct PlayerInfo *player = &stored_player[i]; - int jx = player->jx, jy = player->jy; + if (stored_player[i].active && + !tape.player_participates[map_player_action[i]]) + { + struct PlayerInfo *player = &stored_player[i]; + int jx = player->jx, jy = player->jy; #if DEBUG_INIT_PLAYER - if (options.debug) - printf("Removing player %d at (%d, %d)\n", i + 1, jx, jy); + if (options.debug) + printf("Removing player %d at (%d, %d)\n", i + 1, jx, jy); #endif - player->active = FALSE; - StorePlayer[jx][jy] = 0; - Feld[jx][jy] = EL_EMPTY; + player->active = FALSE; + StorePlayer[jx][jy] = 0; + Feld[jx][jy] = EL_EMPTY; + } } } @@ -4300,55 +3769,15 @@ void InitGame() SBY_Lower = lev_fieldy - SCR_FIELDY + 1; } -#if NEW_TILESIZE - - // printf("::: START-0: %d, %d\n", lev_fieldx, SCR_FIELDX); - // printf("::: START-1: %d, %d\n", SBX_Left, SBX_Right); - -#if 1 if (full_lev_fieldx <= SCR_FIELDX) SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2; - if (full_lev_fieldy <= SCR_FIELDY) SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2; -#else - if (lev_fieldx + (SBX_Left < 0 ? 2 : 0) <= SCR_FIELDX) - SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2; - - if (lev_fieldy + (SBY_Upper < 0 ? 2 : 0) <= SCR_FIELDY) - SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2; -#endif - - /* - printf("::: START-2: %d, %d (%d)\n", SBX_Left, SBX_Right, - SBX_Right - SBX_Left + 1); - */ -#if 1 if (EVEN(SCR_FIELDX) && full_lev_fieldx > SCR_FIELDX) SBX_Left--; if (EVEN(SCR_FIELDY) && full_lev_fieldy > SCR_FIELDY) SBY_Upper--; -#else - if (EVEN(SCR_FIELDX)) - SBX_Left--; - if (EVEN(SCR_FIELDY)) - SBY_Upper--; -#endif - -#if 0 - printf("::: START-3: %d, %d\n", SBX_Left, SBX_Right); - printf("\n"); -#endif - -#else - - if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX) - SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2; - - if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY) - SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2; -#endif /* if local player not found, look for custom element that might create the player (make some assumptions about the right custom element) */ @@ -4459,65 +3888,14 @@ void InitGame() local_player->jy - MIDPOSY); } -#if 0 - printf("::: %d, %d (initial)\n", scroll_x, scroll_y); -#endif - -#if 0 - /* do not use PLAYING mask for fading out from main screen */ - game_status = GAME_MODE_MAIN; -#endif - -#if 0 - - StopAnimation(); - - if (!game.restart_level) - CloseDoor(DOOR_CLOSE_1); - -#if 1 - if (level_editor_test_game) - FadeSkipNextFadeIn(); - else - FadeSetEnterScreen(); -#else - if (level_editor_test_game) - fading = fading_none; - else - fading = menu.destination; -#endif - -#if 1 - FadeOut(REDRAW_FIELD); -#else - if (do_fading) - FadeOut(REDRAW_FIELD); -#endif - -#endif - -#if 0 - game_status = GAME_MODE_PLAYING; -#endif - /* !!! FIX THIS (START) !!! */ if (level.game_engine_type == GAME_ENGINE_TYPE_EM) { InitGameEngine_EM(); - -#if 0 - /* blit playfield from scroll buffer to normal back buffer for fading in */ - BlitScreenToBitmap_EM(backbuffer); -#endif } else if (level.game_engine_type == GAME_ENGINE_TYPE_SP) { InitGameEngine_SP(); - -#if 0 - /* blit playfield from scroll buffer to normal back buffer for fading in */ - BlitScreenToBitmap_SP(backbuffer); -#endif } else { @@ -4527,70 +3905,30 @@ void InitGame() /* after drawing the level, correct some elements */ if (game.timegate_time_left == 0) CloseAllOpenTimegates(); - -#if 0 - /* blit playfield from scroll buffer to normal back buffer for fading in */ -#if NEW_TILESIZE - BlitScreenToBitmap(backbuffer); -#else - if (setup.soft_scrolling) - BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY); -#endif -#endif - -#if 0 - redraw_mask |= REDRAW_FROM_BACKBUFFER; -#endif } -#if 1 + /* blit playfield from scroll buffer to normal back buffer for fading in */ BlitScreenToBitmap(backbuffer); redraw_mask |= REDRAW_FROM_BACKBUFFER; -#endif /* !!! FIX THIS (END) !!! */ -#if 1 FadeIn(REDRAW_FIELD); -#else - if (do_fading) - FadeIn(REDRAW_FIELD); - - BackToFront(); -#endif if (!game.restart_level) { /* copy default game door content to main double buffer */ -#if 1 -#if 1 + /* !!! CHECK AGAIN !!! */ SetPanelBackground(); // SetDoorBackgroundImage(IMG_BACKGROUND_PANEL); DrawBackground(DX, DY, DXSIZE, DYSIZE); -#else - struct GraphicInfo *gfx = &graphic_info[IMG_BACKGROUND_PANEL]; - - /* (ClearRectangle() only needed if panel bitmap is smaller than panel) */ - ClearRectangle(drawto, DX, DY, DXSIZE, DYSIZE); - BlitBitmap(gfx->bitmap, drawto, gfx->src_x, gfx->src_y, - MIN(gfx->width, DXSIZE), MIN(gfx->height, DYSIZE), DX, DY); -#endif -#else - BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, - DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY); -#endif } SetPanelBackground(); SetDrawBackgroundMask(REDRAW_DOOR_1); -#if 1 UpdateAndDisplayGameControlValues(); -#else - UpdateGameDoorValues(); - DrawGameDoorValues(); -#endif if (!game.restart_level) { @@ -4603,12 +3941,7 @@ void InitGame() MapTapeButtons(); /* copy actual game door content to door double buffer for OpenDoor() */ -#if 1 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0); -#else - BlitBitmap(drawto, bitmap_db_door, - DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1); -#endif OpenDoor(DOOR_OPEN_ALL); @@ -4643,22 +3976,16 @@ void InitGame() #endif } -#if 1 UnmapAllGadgets(); MapGameButtons(); MapTapeButtons(); -#endif if (!game.restart_level && !tape.playing) { LevelStats_incPlayed(level_nr); SaveLevelSetup_SeriesInfo(); - -#if 0 - printf("::: PLAYING LEVEL (%d)\n", LevelStats_getPlayed(level_nr)); -#endif } game.restart_level = FALSE; @@ -4910,18 +4237,12 @@ void GameWon() LevelStats_incSolved(level_nr); SaveLevelSetup_SeriesInfo(); - -#if 0 - printf("::: LEVEL SOLVED (%d)\n", LevelStats_getSolved(level_nr)); -#endif } if (tape.auto_play) /* tape might already be stopped here */ tape.auto_play_level_solved = TRUE; -#if 1 TapeStop(); -#endif game_over_delay_1 = game_over_delay_value_1; game_over_delay_2 = game_over_delay_value_2; @@ -4947,7 +4268,6 @@ void GameWon() time = time_final; score = score_final; -#if 1 local_player->LevelSolved_CountingTime = time; local_player->LevelSolved_CountingScore = score; @@ -4955,10 +4275,6 @@ void GameWon() game_panel_controls[GAME_PANEL_SCORE].value = score; DisplayGameControlValues(); -#else - DrawGameValue_Time(time); - DrawGameValue_Score(score); -#endif } if (level.game_engine_type == GAME_ENGINE_TYPE_RND) @@ -4975,24 +4291,14 @@ void GameWon() { int element = Feld[ExitX][ExitY]; -#if 0 - if (element == EL_EM_EXIT_OPEN || - element == EL_EM_STEEL_EXIT_OPEN) - { - Bang(ExitX, ExitY); - } - else -#endif - { - Feld[ExitX][ExitY] = - (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING : - element == EL_EM_EXIT_OPEN ? EL_EM_EXIT_CLOSING : - element == EL_SP_EXIT_OPEN ? EL_SP_EXIT_CLOSING: - element == EL_STEEL_EXIT_OPEN ? EL_STEEL_EXIT_CLOSING: - EL_EM_STEEL_EXIT_CLOSING); - - PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING); - } + Feld[ExitX][ExitY] = + (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING : + element == EL_EM_EXIT_OPEN ? EL_EM_EXIT_CLOSING : + element == EL_SP_EXIT_OPEN ? EL_SP_EXIT_CLOSING: + element == EL_STEEL_EXIT_OPEN ? EL_STEEL_EXIT_CLOSING: + EL_EM_STEEL_EXIT_CLOSING); + + PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING); } /* player disappears */ @@ -5032,7 +4338,6 @@ void GameWon() time += time_count_steps * time_count_dir; score += time_count_steps * level.score[SC_TIME_BONUS]; -#if 1 local_player->LevelSolved_CountingTime = time; local_player->LevelSolved_CountingScore = score; @@ -5040,10 +4345,6 @@ void GameWon() game_panel_controls[GAME_PANEL_SCORE].value = score; DisplayGameControlValues(); -#else - DrawGameValue_Time(time); - DrawGameValue_Score(score); -#endif if (time == time_final) StopSound(SND_GAME_LEVELTIME_BONUS); @@ -5064,9 +4365,7 @@ void GameWon() return; } -#if 1 GameEnd(); -#endif } void GameEnd() @@ -5080,35 +4379,21 @@ void GameEnd() if (local_player->LevelSolved_SaveTape) { -#if 0 - TapeStop(); -#endif - -#if 1 SaveTapeChecked(tape.level_nr); /* ask to save tape */ -#else - SaveTape(tape.level_nr); /* ask to save tape */ -#endif } if (level_editor_test_game) { game_status = GAME_MODE_MAIN; -#if 1 DrawAndFadeInMainMenu(REDRAW_FIELD); -#else - DrawMainMenu(); -#endif return; } if (!local_player->LevelSolved_SaveScore) { -#if 1 FadeOut(REDRAW_FIELD); -#endif game_status = GAME_MODE_MAIN; @@ -5141,9 +4426,7 @@ void GameEnd() } else { -#if 1 FadeOut(REDRAW_FIELD); -#endif game_status = GAME_MODE_MAIN; @@ -5248,11 +4531,6 @@ void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir) { if (player->GfxAction != action || player->GfxDir != dir) { -#if 0 - printf("Player frame reset! (%d => %d, %d => %d)\n", - player->GfxAction, action, player->GfxDir, dir); -#endif - player->GfxAction = action; player->GfxDir = dir; player->Frame = 0; @@ -5260,7 +4538,6 @@ void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir) } } -#if USE_GFX_RESET_GFX_ANIMATION static void ResetGfxFrame(int x, int y, boolean redraw) { int element = Feld[x][y]; @@ -5279,7 +4556,6 @@ static void ResetGfxFrame(int x, int y, boolean redraw) if (redraw && GfxFrame[x][y] != last_gfx_frame) DrawLevelGraphicAnimation(x, y, graphic); } -#endif static void ResetGfxAnimation(int x, int y) { @@ -5287,9 +4563,7 @@ static void ResetGfxAnimation(int x, int y) GfxDir[x][y] = MovDir[x][y]; GfxFrame[x][y] = 0; -#if USE_GFX_RESET_GFX_ANIMATION ResetGfxFrame(x, y, FALSE); -#endif } static void ResetRandomAnimationValue(int x, int y) @@ -5305,51 +4579,24 @@ void InitMovingField(int x, int y, int direction) int newx = x + dx; int newy = y + dy; boolean is_moving_before, is_moving_after; -#if 0 - boolean continues_moving = (WasJustMoving[x][y] && direction == MovDir[x][y]); -#endif /* check if element was/is moving or being moved before/after mode change */ -#if 1 -#if 1 is_moving_before = (WasJustMoving[x][y] != 0); -#else - /* (!!! this does not work -- WasJustMoving is NOT a boolean value !!!) */ - is_moving_before = WasJustMoving[x][y]; -#endif -#else - is_moving_before = (getElementMoveStepsizeExt(x, y, MovDir[x][y]) != 0); -#endif is_moving_after = (getElementMoveStepsizeExt(x, y, direction) != 0); /* reset animation only for moving elements which change direction of moving or which just started or stopped moving (else CEs with property "can move" / "not moving" are reset each frame) */ -#if USE_GFX_RESET_ONLY_WHEN_MOVING -#if 1 if (is_moving_before != is_moving_after || direction != MovDir[x][y]) ResetGfxAnimation(x, y); -#else - if ((is_moving_before || is_moving_after) && !continues_moving) - ResetGfxAnimation(x, y); -#endif -#else - if (!continues_moving) - ResetGfxAnimation(x, y); -#endif MovDir[x][y] = direction; GfxDir[x][y] = direction; -#if USE_GFX_RESET_ONLY_WHEN_MOVING GfxAction[x][y] = (!is_moving_after ? ACTION_WAITING : direction == MV_DOWN && CAN_FALL(element) ? ACTION_FALLING : ACTION_MOVING); -#else - GfxAction[x][y] = (direction == MV_DOWN && CAN_FALL(element) ? - ACTION_FALLING : ACTION_MOVING); -#endif /* this is needed for CEs with property "can move" / "not moving" */ @@ -5360,9 +4607,7 @@ void InitMovingField(int x, int y, int direction) MovDir[newx][newy] = MovDir[x][y]; -#if USE_NEW_CUSTOM_VALUE CustomValue[newx][newy] = CustomValue[x][y]; -#endif GfxFrame[newx][newy] = GfxFrame[x][y]; GfxRandom[newx][newy] = GfxRandom[x][y]; @@ -5445,26 +4690,16 @@ static void RemoveField(int x, int y) MovDir[x][y] = 0; MovDelay[x][y] = 0; -#if USE_NEW_CUSTOM_VALUE CustomValue[x][y] = 0; -#endif AmoebaNr[x][y] = 0; ChangeDelay[x][y] = 0; ChangePage[x][y] = -1; Pushed[x][y] = FALSE; -#if 0 - ExplodeField[x][y] = EX_TYPE_NONE; -#endif - GfxElement[x][y] = EL_UNDEFINED; GfxAction[x][y] = ACTION_DEFAULT; GfxDir[x][y] = MV_NONE; -#if 0 - /* !!! this would prevent the removed tile from being redrawn !!! */ - GfxRedraw[x][y] = GFX_REDRAW_NONE; -#endif } void RemoveMovingField(int x, int y) @@ -5668,7 +4903,6 @@ void DrawRelocateScreen(int old_x, int old_y, int x, int y, int move_dir, } else { -#if 1 if (!level.shifted_relocation || center_screen) { /* quick relocation (without scrolling), with centering of screen */ @@ -5704,34 +4938,12 @@ void DrawRelocateScreen(int old_x, int old_y, int x, int y, int move_dir, offset_y > SBY_Lower + MIDPOSY ? SBY_Lower : offset_y - MIDPOSY); } -#else - /* quick relocation (without scrolling), inside visible screen area */ - - int offset = game.scroll_delay_value; - - if ((move_dir == MV_LEFT && scroll_x > x - MIDPOSX + offset) || - (move_dir == MV_RIGHT && scroll_x < x - MIDPOSX - offset)) - scroll_x = x - MIDPOSX + (scroll_x < x - MIDPOSX ? -offset : +offset); - - if ((move_dir == MV_UP && scroll_y > y - MIDPOSY + offset) || - (move_dir == MV_DOWN && scroll_y < y - MIDPOSY - offset)) - scroll_y = y - MIDPOSY + (scroll_y < y - MIDPOSY ? -offset : +offset); - - /* don't scroll over playfield boundaries */ - if (scroll_x < SBX_Left || scroll_x > SBX_Right) - scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right); - - /* don't scroll over playfield boundaries */ - if (scroll_y < SBY_Upper || scroll_y > SBY_Lower) - scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower); -#endif } RedrawPlayfield(TRUE, 0,0,0,0); } else { -#if 1 int scroll_xx, scroll_yy; if (!level.shifted_relocation || center_screen) @@ -5770,18 +4982,6 @@ void DrawRelocateScreen(int old_x, int old_y, int x, int y, int move_dir, offset_y - MIDPOSY); } -#else - - /* visible relocation (with scrolling), with centering of screen */ - - int scroll_xx = (x < SBX_Left + MIDPOSX ? SBX_Left : - x > SBX_Right + MIDPOSX ? SBX_Right : - x - MIDPOSX); - - int scroll_yy = (y < SBY_Upper + MIDPOSY ? SBY_Upper : - y > SBY_Lower + MIDPOSY ? SBY_Lower : - y - MIDPOSY); -#endif ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */ @@ -5897,12 +5097,6 @@ void RelocatePlayer(int jx, int jy, int el_player_raw) if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */ { Feld[jx][jy] = element; /* restore previously existing element */ -#if 0 - /* !!! do not initialize already initialized element a second time !!! */ - /* (this causes at least problems with "element creation" CE trigger for - already existing elements, and existing Sokoban fields counted twice) */ - InitField(jx, jy, FALSE); -#endif } /* only visually relocate centered player */ @@ -5919,7 +5113,6 @@ void RelocatePlayer(int jx, int jy, int el_player_raw) CheckTriggeredElementChangeByPlayer(jx, jy, element, CE_PLAYER_ENTERS_X, player->index_bit, enter_side); -#if 1 if (player->is_switching) { /* ensure that relocation while still switching an element does not cause @@ -5932,7 +5125,6 @@ void RelocatePlayer(int jx, int jy, int el_player_raw) player->switch_x += jx - old_jx; player->switch_y += jy - old_jy; } -#endif } void Explode(int ex, int ey, int phase, int mode) @@ -5955,23 +5147,6 @@ void Explode(int ex, int ey, int phase, int mode) int center_element = Feld[ex][ey]; int artwork_element, explosion_element; /* set these values later */ -#if 0 - /* --- This is only really needed (and now handled) in "Impact()". --- */ - /* do not explode moving elements that left the explode field in time */ - if (game.engine_version >= VERSION_IDENT(2,2,0,7) && - center_element == EL_EMPTY && - (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER)) - return; -#endif - -#if 0 - /* !!! at this place, the center element may be EL_BLOCKED !!! */ - if (mode == EX_TYPE_NORMAL || - mode == EX_TYPE_CENTER || - mode == EX_TYPE_CROSS) - PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING); -#endif - /* remove things displayed in background while burning dynamite */ if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey])) Back[ex][ey] = 0; @@ -6001,12 +5176,10 @@ void Explode(int ex, int ey, int phase, int mode) } } -#if 1 if (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER || mode == EX_TYPE_CROSS) PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING); -#endif last_phase = element_info[explosion_element].explosion_delay + 1; @@ -6143,31 +5316,9 @@ void Explode(int ex, int ey, int phase, int mode) ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0); -#ifdef DEBUG - - /* activate this even in non-DEBUG version until cause for crash in - getGraphicAnimationFrame() (see below) is found and eliminated */ - -#endif -#if 1 - -#if 1 /* this can happen if the player leaves an explosion just in time */ if (GfxElement[x][y] == EL_UNDEFINED) GfxElement[x][y] = EL_EMPTY; -#else - if (GfxElement[x][y] == EL_UNDEFINED) - { - printf("\n\n"); - printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y); - printf("Explode(): This should never happen!\n"); - printf("\n\n"); - - GfxElement[x][y] = EL_EMPTY; - } -#endif - -#endif border_element = Store2[x][y]; if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y)) @@ -6239,9 +5390,7 @@ void Explode(int ex, int ey, int phase, int mode) ChangeDelay[x][y] = 0; ChangePage[x][y] = -1; -#if USE_NEW_CUSTOM_VALUE CustomValue[x][y] = 0; -#endif InitField_WithBug2(x, y, FALSE); @@ -6341,12 +5490,7 @@ void Bang(int x, int y) { struct PlayerInfo *player = PLAYERINFO(x, y); -#if USE_FIX_CE_ACTION_WITH_PLAYER element = Feld[x][y] = player->initial_element; -#else - element = Feld[x][y] = (player->use_murphy ? EL_SP_MURPHY : - player->element_nr); -#endif if (level.use_explosion_element[player->index_nr]) { @@ -6384,10 +5528,6 @@ void Bang(int x, int y) break; case EL_DC_LANDMINE: -#if 0 - case EL_EM_EXIT_OPEN: - case EL_EM_STEEL_EXIT_OPEN: -#endif explosion_type = EX_TYPE_CENTER; break; @@ -6611,20 +5751,6 @@ static void ToggleSwitchgateSwitch(int x, int y) { int element = Feld[xx][yy]; -#if !USE_BOTH_SWITCHGATE_SWITCHES - if (element == EL_SWITCHGATE_SWITCH_UP || - element == EL_SWITCHGATE_SWITCH_DOWN) - { - Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos; - TEST_DrawLevelField(xx, yy); - } - else if (element == EL_DC_SWITCHGATE_SWITCH_UP || - element == EL_DC_SWITCHGATE_SWITCH_DOWN) - { - Feld[xx][yy] = EL_DC_SWITCHGATE_SWITCH_UP + game.switchgate_pos; - TEST_DrawLevelField(xx, yy); - } -#else if (element == EL_SWITCHGATE_SWITCH_UP) { Feld[xx][yy] = EL_SWITCHGATE_SWITCH_DOWN; @@ -6645,7 +5771,6 @@ static void ToggleSwitchgateSwitch(int x, int y) Feld[xx][yy] = EL_DC_SWITCHGATE_SWITCH_UP; TEST_DrawLevelField(xx, yy); } -#endif else if (element == EL_SWITCHGATE_OPEN || element == EL_SWITCHGATE_OPENING) { @@ -6878,12 +6003,8 @@ static void ActivateTimegateSwitch(int x, int y) } -#if 1 Feld[x][y] = (Feld[x][y] == EL_TIMEGATE_SWITCH ? EL_TIMEGATE_SWITCH_ACTIVE : EL_DC_TIMEGATE_SWITCH_ACTIVE); -#else - Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE; -#endif } void Impact(int x, int y) @@ -7109,10 +6230,6 @@ void Impact(int x, int y) } else { -#if 0 - TestIfElementSmashesCustomElement(x, y, MV_DOWN); -#endif - CheckElementChange(x, y + 1, smashed, element, CE_SMASHED); CheckElementChangeBySide(x, y + 1, smashed, element, @@ -7414,7 +6531,6 @@ inline static void TurnRoundExt(int x, int y) } else if (element == EL_SPRING) { -#if USE_NEW_SPRING_BUMPER if (MovDir[x][y] & MV_HORIZONTAL) { if (SPRING_CAN_BUMP_FROM_FIELD(move_x, move_y) && @@ -7430,12 +6546,6 @@ inline static void TurnRoundExt(int x, int y) SPRING_CAN_ENTER_FIELD(element, x, y + 1)) MovDir[x][y] = MV_NONE; } -#else - if (MovDir[x][y] & MV_HORIZONTAL && - (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) || - SPRING_CAN_ENTER_FIELD(element, x, y + 1))) - MovDir[x][y] = MV_NONE; -#endif MovDelay[x][y] = 0; } @@ -8295,13 +7405,8 @@ void StartMoving(int x, int y) Store[x][y] = EL_ACID; } else if ( -#if USE_FIX_IMPACT_COLLISION (game.engine_version >= VERSION_IDENT(3,1,0,0) && CheckImpact[x][y] && !IS_FREE(x, y + 1)) || -#else - (game.engine_version >= VERSION_IDENT(3,1,0,0) && - CheckCollision[x][y] && !IS_FREE(x, y + 1)) || -#endif (game.engine_version >= VERSION_IDENT(3,0,7,0) && CAN_FALL(element) && WasJustFalling[x][y] && (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) || @@ -8361,7 +7466,6 @@ void StartMoving(int x, int y) boolean can_fall_both = (can_fall_left && can_fall_right); int slippery_type = element_info[Feld[x][y + 1]].slippery_type; -#if USE_NEW_ALL_SLIPPERY if (can_fall_any && slippery_type != SLIPPERY_ANY_RANDOM) { if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both) @@ -8376,37 +7480,7 @@ void StartMoving(int x, int y) can_fall_any = (can_fall_left || can_fall_right); can_fall_both = FALSE; } -#else - if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1])) - { - if (slippery_type == SLIPPERY_ONLY_LEFT) - can_fall_right = FALSE; - else if (slippery_type == SLIPPERY_ONLY_RIGHT) - can_fall_left = FALSE; - else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both) - can_fall_right = FALSE; - else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both) - can_fall_left = FALSE; - - can_fall_any = (can_fall_left || can_fall_right); - can_fall_both = (can_fall_left && can_fall_right); - } -#endif - -#if USE_NEW_ALL_SLIPPERY -#else -#if USE_NEW_SP_SLIPPERY - /* !!! better use the same properties as for custom elements here !!! */ - else if (game.engine_version >= VERSION_IDENT(3,1,1,0) && - can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1])) - { - can_fall_right = FALSE; /* slip down on left side */ - can_fall_both = FALSE; - } -#endif -#endif -#if USE_NEW_ALL_SLIPPERY if (can_fall_both) { if (element == EL_BD_ROCK || element == EL_BD_DIAMOND) @@ -8416,18 +7490,6 @@ void StartMoving(int x, int y) can_fall_both = FALSE; } -#else - if (can_fall_both) - { - if (game.emulation == EMU_BOULDERDASH || - element == EL_BD_ROCK || element == EL_BD_DIAMOND) - can_fall_right = FALSE; /* slip down on left side */ - else - can_fall_left = !(can_fall_right = RND(2)); - - can_fall_both = FALSE; - } -#endif if (can_fall_any) { @@ -8436,11 +7498,7 @@ void StartMoving(int x, int y) started_moving = TRUE; } } -#if 0 - else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element)) -#else else if (IS_BELT_ACTIVE(Feld[x][y + 1])) -#endif { boolean left_is_free = (x > 0 && IS_FREE(x - 1, y)); boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y)); @@ -8468,26 +7526,11 @@ void StartMoving(int x, int y) } /* not "else if" because of elements that can fall and move (EL_SPRING) */ -#if 0 - if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NONE) -#else if (CAN_MOVE(element) && !started_moving) -#endif { int move_pattern = element_info[element].move_pattern; int newx, newy; -#if 0 -#if DEBUG - if (MovDir[x][y] == MV_NONE) - { - printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n", - x, y, element, element_info[element].token_name); - printf("StartMoving(): This should never happen!\n"); - } -#endif -#endif - Moving2Blocked(x, y, &newx, &newy); if (IS_PUSHABLE(element) && JustBeingPushed(x, y)) @@ -8580,20 +7623,10 @@ void StartMoving(int x, int y) { int flamed = MovingOrBlocked2Element(xx, yy); - /* !!! */ -#if 0 - if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed)) - Bang(xx, yy); - else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy)) - RemoveMovingField(xx, yy); - else - RemoveField(xx, yy); -#else if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed)) Bang(xx, yy); else RemoveMovingField(xx, yy); -#endif ChangeDelay[xx][yy] = 0; @@ -8789,78 +7822,14 @@ void StartMoving(int x, int y) } else if (!IS_FREE(newx, newy)) { -#if 0 - if (IS_PLAYER(x, y)) - DrawPlayerField(x, y); - else - TEST_DrawLevelField(x, y); -#endif - return; } } else if (IS_CUSTOM_ELEMENT(element) && CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy)) { -#if 1 if (!DigFieldByCE(newx, newy, element)) return; -#else - int new_element = Feld[newx][newy]; - - if (!IS_FREE(newx, newy)) - { - int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING : - IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING : - ACTION_BREAKING); - - /* no element can dig solid indestructible elements */ - if (IS_INDESTRUCTIBLE(new_element) && - !IS_DIGGABLE(new_element) && - !IS_COLLECTIBLE(new_element)) - return; - - if (AmoebaNr[newx][newy] && - (new_element == EL_AMOEBA_FULL || - new_element == EL_BD_AMOEBA || - new_element == EL_AMOEBA_GROWING)) - { - AmoebaCnt[AmoebaNr[newx][newy]]--; - AmoebaCnt2[AmoebaNr[newx][newy]]--; - } - - if (IS_MOVING(newx, newy)) - RemoveMovingField(newx, newy); - else - { - RemoveField(newx, newy); - TEST_DrawLevelField(newx, newy); - } - - /* if digged element was about to explode, prevent the explosion */ - ExplodeField[newx][newy] = EX_TYPE_NONE; - - PlayLevelSoundAction(x, y, action); - } - - Store[newx][newy] = EL_EMPTY; - -#if 1 - /* this makes it possible to leave the removed element again */ - if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element))) - Store[newx][newy] = new_element; -#else - if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element))) - { - int move_leave_element = element_info[element].move_leave_element; - - /* this makes it possible to leave the removed element again */ - Store[newx][newy] = (move_leave_element == EL_TRIGGER_ELEMENT ? - new_element : move_leave_element); - } -#endif - -#endif if (move_pattern & MV_MAZE_RUNNER_STYLE) { @@ -8908,25 +7877,11 @@ void StartMoving(int x, int y) MovDelay[x][y] = 50; - /* !!! */ -#if 0 - RemoveField(newx, newy); -#endif Feld[newx][newy] = EL_FLAMES; if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY) - { -#if 0 - RemoveField(newx1, newy1); -#endif Feld[newx1][newy1] = EL_FLAMES; - } if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY) - { -#if 0 - RemoveField(newx2, newy2); -#endif Feld[newx2][newy2] = EL_FLAMES; - } return; } @@ -8956,18 +7911,10 @@ void StartMoving(int x, int y) AmoebaCnt[AmoebaNr[newx][newy]]--; } -#if 0 - /* !!! test !!! */ - if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy)) - { - RemoveMovingField(newx, newy); - } -#else if (IS_MOVING(newx, newy)) { RemoveMovingField(newx, newy); } -#endif else { Feld[newx][newy] = EL_EMPTY; @@ -9020,21 +7967,6 @@ void StartMoving(int x, int y) TurnRound(x, y); -#if 0 - /* !!! NEW "CE_BLOCKED" STUFF !!! -- DOES NOT WORK YET... !!! */ - if (move_pattern & MV_ANY_DIRECTION && - move_pattern == MovDir[x][y]) - { - int blocking_element = - (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement); - - CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED, - MovDir[x][y]); - - element = Feld[x][y]; /* element might have changed */ - } -#endif - if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */ DrawLevelElementAnimation(x, y, element); @@ -9074,17 +8006,6 @@ void ContinueMoving(int x, int y) if (ABS(MovPos[x][y]) < TILEX) { -#if 0 - int ee = Feld[x][y]; - int gg = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]); - int ff = getGraphicAnimationFrame(gg, GfxFrame[x][y]); - - printf("::: %d.%d: moving %d ... [%d, %d, %d] [%d, %d, %d]\n", - x, y, ABS(MovPos[x][y]), - ee, gg, ff, - GfxAction[x][y], GfxDir[x][y], GfxFrame[x][y]); -#endif - TEST_DrawLevelField(x, y); return; /* element is still moving */ @@ -9140,9 +8061,7 @@ void ContinueMoving(int x, int y) Feld[x][y] = EL_MAGIC_WALL_DEAD; element = Feld[newx][newy] = Store[x][y]; -#if USE_NEW_CUSTOM_VALUE InitField(newx, newy, FALSE); -#endif } else if (element == EL_BD_MAGIC_WALL_FILLING) { @@ -9158,9 +8077,7 @@ void ContinueMoving(int x, int y) Feld[x][y] = EL_BD_MAGIC_WALL_DEAD; element = Feld[newx][newy] = Store[x][y]; -#if USE_NEW_CUSTOM_VALUE InitField(newx, newy, FALSE); -#endif } else if (element == EL_DC_MAGIC_WALL_FILLING) { @@ -9176,9 +8093,7 @@ void ContinueMoving(int x, int y) Feld[x][y] = EL_DC_MAGIC_WALL_DEAD; element = Feld[newx][newy] = Store[x][y]; -#if USE_NEW_CUSTOM_VALUE InitField(newx, newy, FALSE); -#endif } else if (element == EL_AMOEBA_DROPPING) { @@ -9212,18 +8127,14 @@ void ContinueMoving(int x, int y) ChangeEvent[newx][newy] = ChangeEvent[x][y]; } -#if USE_NEW_CUSTOM_VALUE CustomValue[newx][newy] = CustomValue[x][y]; -#endif ChangeDelay[x][y] = 0; ChangePage[x][y] = -1; ChangeCount[x][y] = 0; ChangeEvent[x][y] = -1; -#if USE_NEW_CUSTOM_VALUE CustomValue[x][y] = 0; -#endif /* copy animation control values to new field */ GfxFrame[newx][newy] = GfxFrame[x][y]; @@ -9234,34 +8145,15 @@ void ContinueMoving(int x, int y) Pushed[x][y] = Pushed[newx][newy] = FALSE; /* some elements can leave other elements behind after moving */ -#if 1 if (ei->move_leave_element != EL_EMPTY && (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) && (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element))) -#else - if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY && - (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) && - (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element))) -#endif { int move_leave_element = ei->move_leave_element; -#if 1 -#if 1 /* this makes it possible to leave the removed element again */ if (ei->move_leave_element == EL_TRIGGER_ELEMENT) move_leave_element = (stored == EL_ACID ? EL_EMPTY : stored); -#else - /* this makes it possible to leave the removed element again */ - if (ei->move_leave_element == EL_TRIGGER_ELEMENT) - move_leave_element = stored; -#endif -#else - /* this makes it possible to leave the removed element again */ - if (ei->move_leave_type == LEAVE_TYPE_LIMITED && - ei->move_leave_element == EL_TRIGGER_ELEMENT) - move_leave_element = stored; -#endif Feld[x][y] = move_leave_element; @@ -9316,10 +8208,8 @@ void ContinueMoving(int x, int y) if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again) CheckCollision[newx][newy] = CHECK_DELAY_COLLISION; -#if USE_FIX_IMPACT_COLLISION if (CAN_FALL(element) && direction == MV_DOWN && check_collision_again) CheckImpact[newx][newy] = CHECK_DELAY_IMPACT; -#endif } if (DONT_TOUCH(element)) /* object may be nasty to player or others */ @@ -9362,29 +8252,6 @@ void ContinueMoving(int x, int y) CheckTriggeredElementChangeBySide(x, y, element, CE_MOVE_OF_X, direction); TestIfElementTouchesCustomElement(x, y); /* empty or new element */ - -#if 0 - if (ChangePage[newx][newy] != -1) /* delayed change */ - { - int page = ChangePage[newx][newy]; - struct ElementChangeInfo *change = &ei->change_page[page]; - - ChangePage[newx][newy] = -1; - - if (change->can_change) - { - if (ChangeElement(newx, newy, element, page)) - { - if (change->post_change_function) - change->post_change_function(newx, newy); - } - } - - if (change->has_action) - ExecuteCustomElementAction(newx, newy, element, page); - } -#endif - TestIfElementHitsCustomElement(newx, newy, direction); TestIfPlayerTouchesCustomElement(newx, newy); TestIfElementTouchesCustomElement(newx, newy); @@ -9905,11 +8772,7 @@ static void RunTimegateWheel(int x, int y) static void InitMagicBallDelay(int x, int y) { -#if 1 ChangeDelay[x][y] = (level.ball_time + 1) * 8 + 1; -#else - ChangeDelay[x][y] = level.ball_time * FRAMES_PER_SECOND + 1; -#endif } static void ActivateMagicBall(int bx, int by) @@ -10522,11 +9385,6 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page) EL_EMPTY); int action_arg_element = GetElementFromGroupElement(action_arg_element_raw); -#if 0 - if (action_arg_element_raw == EL_GROUP_START) - printf("::: %d,%d: %d ('%s')\n", x, y, element, EL_NAME(element)); -#endif - int action_arg_direction = (action_arg >= CA_ARG_DIRECTION_LEFT && action_arg <= CA_ARG_DIRECTION_DOWN ? action_arg - CA_ARG_DIRECTION : @@ -10554,11 +9412,7 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page) action_type == CA_SET_LEVEL_GEMS ? level.gems_needed : action_type == CA_SET_LEVEL_TIME ? level.time : action_type == CA_SET_LEVEL_SCORE ? 0 : -#if USE_NEW_CUSTOM_VALUE action_type == CA_SET_CE_VALUE ? GET_NEW_CE_VALUE(element) : -#else - action_type == CA_SET_CE_VALUE ? ei->custom_value_initial : -#endif action_type == CA_SET_CE_SCORE ? 0 : 0); @@ -10570,11 +9424,7 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page) action_arg == CA_ARG_NUMBER_MIN ? action_arg_number_min : action_arg == CA_ARG_NUMBER_MAX ? action_arg_number_max : action_arg == CA_ARG_NUMBER_RESET ? action_arg_number_reset : -#if USE_NEW_CUSTOM_VALUE action_arg == CA_ARG_NUMBER_CE_VALUE ? CustomValue[x][y] : -#else - action_arg == CA_ARG_NUMBER_CE_VALUE ? ei->custom_value_initial : -#endif action_arg == CA_ARG_NUMBER_CE_SCORE ? ei->collect_score : action_arg == CA_ARG_NUMBER_CE_DELAY ? GET_CE_DELAY_VALUE(change) : action_arg == CA_ARG_NUMBER_LEVEL_TIME ? level_time_value : @@ -10604,17 +9454,9 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page) action_mode, action_arg_number, action_arg_number_min, action_arg_number_max); -#if 1 int trigger_player_bits = (change->actual_trigger_player_bits != CH_PLAYER_NONE ? change->actual_trigger_player_bits : change->trigger_player); -#else - int trigger_player_bits = - (change->actual_trigger_player >= EL_PLAYER_1 && - change->actual_trigger_player <= EL_PLAYER_4 ? - (1 << (change->actual_trigger_player - EL_PLAYER_1)) : - PLAYER_BITS_ANY); -#endif int action_arg_player_bits = (action_arg >= CA_ARG_PLAYER_1 && @@ -10658,13 +9500,9 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page) { TimeLeft = action_arg_number_new; -#if 1 game_panel_controls[GAME_PANEL_TIME].value = TimeLeft; DisplayGameControlValues(); -#else - DrawGameValue_Time(TimeLeft); -#endif if (!TimeLeft && setup.time_limit) for (i = 0; i < MAX_PLAYERS; i++) @@ -10678,13 +9516,9 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page) { local_player->score = action_arg_number_new; -#if 1 game_panel_controls[GAME_PANEL_SCORE].value = local_player->score; DisplayGameControlValues(); -#else - DrawGameValue_Score(local_player->score); -#endif break; } @@ -10693,27 +9527,13 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page) { local_player->gems_still_needed = action_arg_number_new; -#if 1 - game_panel_controls[GAME_PANEL_GEMS].value = local_player->gems_still_needed; + game_panel_controls[GAME_PANEL_GEMS].value = + local_player->gems_still_needed; DisplayGameControlValues(); -#else - DrawGameValue_Emeralds(local_player->gems_still_needed); -#endif - - break; - } -#if !USE_PLAYER_GRAVITY - case CA_SET_LEVEL_GRAVITY: - { - game.gravity = (action_arg == CA_ARG_GRAVITY_OFF ? FALSE : - action_arg == CA_ARG_GRAVITY_ON ? TRUE : - action_arg == CA_ARG_GRAVITY_TOGGLE ? !game.gravity : - game.gravity); break; } -#endif case CA_SET_LEVEL_WIND: { @@ -10724,27 +9544,8 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page) case CA_SET_LEVEL_RANDOM_SEED: { -#if 1 /* ensure that setting a new random seed while playing is predictable */ InitRND(action_arg_number_new ? action_arg_number_new : RND(1000000) + 1); -#else - InitRND(action_arg_number_new); -#endif - -#if 0 - printf("::: %d -> %d\n", action_arg_number_new, RND(10)); -#endif - -#if 0 - { - int i; - - printf("::: "); - for (i = 0; i < 9; i++) - printf("%d, ", RND(2)); - printf("\n"); - } -#endif break; } @@ -10803,10 +9604,6 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page) case CA_SET_PLAYER_SPEED: { -#if 0 - printf("::: trigger_player_bits == %d\n", trigger_player_bits); -#endif - for (i = 0; i < MAX_PLAYERS; i++) { if (trigger_player_bits & (1 << i)) @@ -10870,7 +9667,6 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page) break; } -#if USE_PLAYER_GRAVITY case CA_SET_PLAYER_GRAVITY: { for (i = 0; i < MAX_PLAYERS; i++) @@ -10887,7 +9683,6 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page) break; } -#endif case CA_SET_PLAYER_ARTWORK: { @@ -10902,10 +9697,8 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page) (level.use_artwork_element[i] ? level.artwork_element[i] : stored_player[i].element_nr); -#if USE_GFX_RESET_PLAYER_ARTWORK if (stored_player[i].artwork_element != artwork_element) stored_player[i].Frame = 0; -#endif stored_player[i].artwork_element = artwork_element; @@ -11026,7 +9819,6 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page) case CA_SET_CE_VALUE: { -#if USE_NEW_CUSTOM_VALUE int last_ce_value = CustomValue[x][y]; CustomValue[x][y] = action_arg_number_new; @@ -11042,14 +9834,12 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page) CheckTriggeredElementChange(x, y, element, CE_VALUE_GETS_ZERO_OF_X); } } -#endif break; } case CA_SET_CE_SCORE: { -#if USE_NEW_CUSTOM_VALUE int last_ce_score = ei->collect_score; ei->collect_score = action_arg_number_new; @@ -11085,7 +9875,6 @@ static void ExecuteCustomElementAction(int x, int y, int element, int page) } } } -#endif break; } @@ -11141,32 +9930,13 @@ static void CreateFieldExt(int x, int y, int element, boolean is_change) int old_element = Feld[x][y]; int new_element = GetElementFromGroupElement(element); int previous_move_direction = MovDir[x][y]; -#if USE_NEW_CUSTOM_VALUE int last_ce_value = CustomValue[x][y]; -#endif boolean player_explosion_protected = PLAYER_EXPLOSION_PROTECTED(x, y); boolean new_element_is_player = ELEM_IS_PLAYER(new_element); boolean add_player_onto_element = (new_element_is_player && -#if USE_CODE_THAT_BREAKS_SNAKE_BITE - /* this breaks SnakeBite when a snake is - halfway through a door that closes */ - /* NOW FIXED AT LEVEL INIT IN files.c */ new_element != EL_SOKOBAN_FIELD_PLAYER && -#endif IS_WALKABLE(old_element)); -#if 0 - /* check if element under the player changes from accessible to unaccessible - (needed for special case of dropping element which then changes) */ - if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) && - IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element)) - { - Bang(x, y); - - return; - } -#endif - if (!add_player_onto_element) { if (IS_MOVING(x, y) || IS_BLOCKED(x, y)) @@ -11176,27 +9946,18 @@ static void CreateFieldExt(int x, int y, int element, boolean is_change) Feld[x][y] = new_element; -#if !USE_GFX_RESET_GFX_ANIMATION - ResetGfxAnimation(x, y); - ResetRandomAnimationValue(x, y); -#endif - if (element_info[new_element].move_direction_initial == MV_START_PREVIOUS) MovDir[x][y] = previous_move_direction; -#if USE_NEW_CUSTOM_VALUE if (element_info[new_element].use_last_ce_value) CustomValue[x][y] = last_ce_value; -#endif InitField_WithBug1(x, y, FALSE); new_element = Feld[x][y]; /* element may have changed */ -#if USE_GFX_RESET_GFX_ANIMATION ResetGfxAnimation(x, y); ResetRandomAnimationValue(x, y); -#endif TEST_DrawLevelField(x, y); @@ -11204,11 +9965,9 @@ static void CreateFieldExt(int x, int y, int element, boolean is_change) TEST_DrawLevelFieldCrumbledNeighbours(x, y); } -#if 1 /* check if element under the player changes from accessible to unaccessible (needed for special case of dropping element which then changes) */ /* (must be checked after creating new element for walkable group elements) */ -#if USE_FIX_KILLED_BY_NON_WALKABLE if (IS_PLAYER(x, y) && !player_explosion_protected && IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element)) { @@ -11216,16 +9975,6 @@ static void CreateFieldExt(int x, int y, int element, boolean is_change) return; } -#else - if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) && - IS_ACCESSIBLE(old_element) && !IS_ACCESSIBLE(new_element)) - { - Bang(x, y); - - return; - } -#endif -#endif /* "ChangeCount" not set yet to allow "entered by player" change one time */ if (new_element_is_player) @@ -11248,7 +9997,6 @@ static void CreateElementFromChange(int x, int y, int element) { element = GET_VALID_RUNTIME_ELEMENT(element); -#if USE_STOP_CHANGED_ELEMENTS if (game.engine_version >= VERSION_IDENT(3,2,0,7)) { int old_element = Feld[x][y]; @@ -11259,7 +10007,6 @@ static void CreateElementFromChange(int x, int y, int element) (!CAN_MOVE(old_element) || !CAN_MOVE(element))) Stop[x][y] = TRUE; } -#endif CreateFieldExt(x, y, element, TRUE); } @@ -11435,8 +10182,6 @@ static boolean ChangeElement(int x, int y, int element, int page) return TRUE; } -#if USE_NEW_DELAYED_ACTION - static void HandleElementChange(int x, int y, int page) { int element = MovingOrBlocked2Element(x, y); @@ -11459,11 +10204,6 @@ static void HandleElementChange(int x, int y, int page) /* this can happen with classic bombs on walkable, changing elements */ if (!CAN_CHANGE_OR_HAS_ACTION(element)) { -#if 0 - if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */ - ChangeDelay[x][y] = 0; -#endif - return; } @@ -11473,19 +10213,15 @@ static void HandleElementChange(int x, int y, int page) if (change->can_change) { -#if 1 /* !!! not clear why graphic animation should be reset at all here !!! */ /* !!! UPDATE: but is needed for correct Snake Bite tail animation !!! */ -#if USE_GFX_RESET_WHEN_NOT_MOVING /* when a custom element is about to change (for example by change delay), do not reset graphic animation when the custom element is moving */ if (!IS_MOVING(x, y)) -#endif { ResetGfxAnimation(x, y); ResetRandomAnimationValue(x, y); } -#endif if (change->pre_change_function) change->pre_change_function(x, y); @@ -11525,14 +10261,12 @@ static void HandleElementChange(int x, int y, int page) return; } -#if 1 /* special case: set new level random seed before changing element */ if (change->has_action && change->action_type == CA_SET_LEVEL_RANDOM_SEED) handle_action_before_change = TRUE; if (change->has_action && handle_action_before_change) ExecuteCustomElementAction(x, y, element, page); -#endif if (change->can_change) { @@ -11548,87 +10282,6 @@ static void HandleElementChange(int x, int y, int page) } } -#else - -static void HandleElementChange(int x, int y, int page) -{ - int element = MovingOrBlocked2Element(x, y); - struct ElementInfo *ei = &element_info[element]; - struct ElementChangeInfo *change = &ei->change_page[page]; - -#ifdef DEBUG - if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y])) - { - printf("\n\n"); - printf("HandleElementChange(): %d,%d: element = %d ('%s')\n", - x, y, element, element_info[element].token_name); - printf("HandleElementChange(): This should never happen!\n"); - printf("\n\n"); - } -#endif - - /* this can happen with classic bombs on walkable, changing elements */ - if (!CAN_CHANGE(element)) - { -#if 0 - if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */ - ChangeDelay[x][y] = 0; -#endif - - return; - } - - if (ChangeDelay[x][y] == 0) /* initialize element change */ - { - ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1; - - ResetGfxAnimation(x, y); - ResetRandomAnimationValue(x, y); - - if (change->pre_change_function) - change->pre_change_function(x, y); - } - - ChangeDelay[x][y]--; - - if (ChangeDelay[x][y] != 0) /* continue element change */ - { - int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]); - - if (IS_ANIMATED(graphic)) - DrawLevelGraphicAnimationIfNeeded(x, y, graphic); - - if (change->change_function) - change->change_function(x, y); - } - else /* finish element change */ - { - if (ChangePage[x][y] != -1) /* remember page from delayed change */ - { - page = ChangePage[x][y]; - ChangePage[x][y] = -1; - - change = &ei->change_page[page]; - } - - if (IS_MOVING(x, y)) /* never change a running system ;-) */ - { - ChangeDelay[x][y] = 1; /* try change after next move step */ - ChangePage[x][y] = page; /* remember page to use for change */ - - return; - } - - if (ChangeElement(x, y, element, page)) - { - if (change->post_change_function) - change->post_change_function(x, y); - } - } -} - -#endif - static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y, int trigger_element, int trigger_event, @@ -11643,12 +10296,6 @@ static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y, if (!(trigger_events[trigger_element][trigger_event])) return FALSE; -#if 0 - printf("::: CheckTriggeredElementChangeExt %d ... [%d, %d, %d, '%s']\n", - trigger_event, recursion_loop_depth, recursion_loop_detected, - recursion_loop_element, EL_NAME(recursion_loop_element)); -#endif - RECURSION_LOOP_DETECTION_START(trigger_element, FALSE); for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++) @@ -11679,11 +10326,6 @@ static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y, change->actual_trigger_ce_value = CustomValue[trigger_x][trigger_y]; change->actual_trigger_ce_score = GET_CE_SCORE(trigger_element); -#if 0 - printf("::: TRIGGERED CHANGE FOUND: %d ['%s'], %d\n", - element, EL_NAME(element), p); -#endif - if ((change->can_change && !change_done) || change->has_action) { int x, y; @@ -11694,7 +10336,6 @@ static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y, { if (change->can_change && !change_done) { -#if USE_FIX_NO_ACTION_AFTER_CHANGE /* if element already changed in this frame, not only prevent another element change (checked in ChangeElement()), but also prevent additional element actions for this element */ @@ -11702,22 +10343,14 @@ static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y, if (ChangeCount[x][y] >= game.max_num_changes_per_frame && !level.use_action_after_change_bug) continue; -#endif - -#if 0 - printf("::: TRIGGERED CHANGE FOUND: %d ['%s'], %d -- CHANGE\n", - element, EL_NAME(element), p); -#endif ChangeDelay[x][y] = 1; ChangeEvent[x][y] = trigger_event; HandleElementChange(x, y, p); } -#if USE_NEW_DELAYED_ACTION else if (change->has_action) { -#if USE_FIX_NO_ACTION_AFTER_CHANGE /* if element already changed in this frame, not only prevent another element change (checked in ChangeElement()), but also prevent additional element actions for this element */ @@ -11725,24 +10358,10 @@ static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y, if (ChangeCount[x][y] >= game.max_num_changes_per_frame && !level.use_action_after_change_bug) continue; -#endif - - -#if 0 - printf("::: TRIGGERED CHANGE FOUND: %d ['%s'], %d -- ACTION\n", - element, EL_NAME(element), p); -#endif ExecuteCustomElementAction(x, y, element, p); PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p); } -#else - if (change->has_action) - { - ExecuteCustomElementAction(x, y, element, p); - PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p); - } -#endif } } @@ -11750,12 +10369,6 @@ static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y, { change_done = TRUE; change_done_any = TRUE; - -#if 0 - printf("::: TRIGGERED CHANGE FOUND: %d ['%s'], %d -- DONE\n", - element, EL_NAME(element), p); -#endif - } } } @@ -11787,11 +10400,6 @@ static boolean CheckElementChangeExt(int x, int y, element = Feld[x][y]; } -#if 0 - /* check if element has already changed */ - if (Feld[x][y] != element) - return FALSE; -#else /* check if element has already changed or is about to change after moving */ if ((game.engine_version < VERSION_IDENT(3,2,0,7) && Feld[x][y] != element) || @@ -11800,20 +10408,9 @@ static boolean CheckElementChangeExt(int x, int y, (ChangeCount[x][y] >= game.max_num_changes_per_frame || ChangePage[x][y] != -1))) return FALSE; -#endif - -#if 0 - printf("::: CheckElementChangeExt %d ... [%d, %d, %d, '%s']\n", - trigger_event, recursion_loop_depth, recursion_loop_detected, - recursion_loop_element, EL_NAME(recursion_loop_element)); -#endif RECURSION_LOOP_DETECTION_START(trigger_element, FALSE); -#if 0 - printf("::: X: trigger_player_bits == %d\n", trigger_player); -#endif - for (p = 0; p < element_info[element].num_change_pages; p++) { struct ElementChangeInfo *change = &element_info[element].change_page[p]; @@ -11826,10 +10423,7 @@ static boolean CheckElementChangeExt(int x, int y, (trigger_event == CE_TOUCHING_X || trigger_event == CE_HITTING_X || trigger_event == CE_HIT_BY_X || -#if 1 - /* this one was forgotten until 3.2.3 */ - trigger_event == CE_DIGGING_X); -#endif + trigger_event == CE_DIGGING_X); /* this one was forgotten until 3.2.3 */ if (change->can_change_or_has_action && change->has_event[trigger_event] && @@ -11878,19 +10472,11 @@ static boolean CheckElementChangeExt(int x, int y, change_done = TRUE; } -#if USE_NEW_DELAYED_ACTION else if (change->has_action) { ExecuteCustomElementAction(x, y, element, p); PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p); } -#else - if (change->has_action) - { - ExecuteCustomElementAction(x, y, element, p); - PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p); - } -#endif } } @@ -12218,18 +10804,11 @@ static void CheckLevelTime() if (TimeLeft <= 10 && setup.time_limit) PlaySound(SND_GAME_RUNNING_OUT_OF_TIME); -#if 1 /* this does not make sense: game_panel_controls[GAME_PANEL_TIME].value is reset from other values in UpdateGameDoorValues() -- FIX THIS */ game_panel_controls[GAME_PANEL_TIME].value = TimeLeft; - /* (already called by UpdateAndDisplayGameControlValues() below) */ - // DisplayGameControlValues(); -#else - DrawGameValue_Time(TimeLeft); -#endif - if (!TimeLeft && setup.time_limit) { if (level.game_engine_type == GAME_ENGINE_TYPE_EM) @@ -12239,18 +10818,10 @@ static void CheckLevelTime() KillPlayer(&stored_player[i]); } } -#if 1 else if (game.no_time_limit && !AllPlayersGone) /* level w/o time limit */ { game_panel_controls[GAME_PANEL_TIME].value = TimePlayed; - - /* (already called by UpdateAndDisplayGameControlValues() below) */ - // DisplayGameControlValues(); } -#else - else if (game.no_time_limit && !AllPlayersGone) /* level w/o time limit */ - DrawGameValue_Time(TimePlayed); -#endif level.native_em_level->lev->time = (game.no_time_limit ? TimePlayed : TimeLeft); @@ -12260,12 +10831,7 @@ static void CheckLevelTime() DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime); } -#if 1 UpdateAndDisplayGameControlValues(); -#else - UpdateGameDoorValues(); - DrawGameDoorValues(); -#endif } void AdvanceFrameAndPlayerCounters(int player_nr) @@ -12286,7 +10852,6 @@ void AdvanceFrameAndPlayerCounters(int player_nr) if (!advance_player_counters) /* not all players may be affected */ continue; -#if USE_NEW_PLAYER_ANIM if (move_frames == 0) /* less than one move per game frame */ { int stepsize = TILEX / move_delay_value; @@ -12297,7 +10862,6 @@ void AdvanceFrameAndPlayerCounters(int player_nr) if (count % delay == 0) move_frames = 1; } -#endif stored_player[i].Frame += move_frames; @@ -12452,11 +11016,9 @@ void GameActions() /* when playing tape, read previously recorded player input from tape data */ recorded_player_action = (tape.playing ? TapePlayAction() : NULL); -#if 1 /* TapePlayAction() may return NULL when toggling to "pause before death" */ if (tape.pausing) return; -#endif if (tape.set_centered_player) { @@ -12468,13 +11030,8 @@ void GameActions() { summarized_player_action |= stored_player[i].action; -#if 1 if (!network_playing && (game.team_mode || tape.playing)) stored_player[i].effective_action = stored_player[i].action; -#else - if (!network_playing) - stored_player[i].effective_action = stored_player[i].action; -#endif } #if defined(NETWORK_AVALIABLE) @@ -12503,19 +11060,13 @@ void GameActions() { tape_action[i] = stored_player[i].effective_action; -#if 1 /* (this may happen in the RND game engine if a player was not present on the playfield on level start, but appeared later from a custom element */ - if (tape.recording && - setup.team_mode && + if (setup.team_mode && + tape.recording && tape_action[i] && !tape.player_participates[i]) tape.player_participates[i] = TRUE; -#else - /* (this can only happen in the R'n'D game engine) */ - if (tape.recording && tape_action[i] && !tape.player_participates[i]) - tape.player_participates[i] = TRUE; /* player just appeared from CE */ -#endif } /* only record actions from input devices, but not programmed actions */ @@ -12523,9 +11074,7 @@ void GameActions() TapeRecordAction(tape_action); #if USE_NEW_PLAYER_ASSIGNMENTS -#if 1 if (game.team_mode) -#endif { byte mapped_action[MAX_PLAYERS]; @@ -12559,41 +11108,6 @@ void GameActions() #endif #endif -#if 0 - printf("::: summarized_player_action == %d\n", - local_player->effective_action); -#endif - - - - -#if 0 -#if DEBUG_INIT_PLAYER - if (options.debug) - { - printf("Player status (final):\n"); - - for (i = 0; i < MAX_PLAYERS; i++) - { - struct PlayerInfo *player = &stored_player[i]; - - printf("- player %d: present == %d, connected == %d, active == %d", - i + 1, - player->present, - player->connected, - player->active); - - if (local_player == player) - printf(" (local player)"); - - printf("\n"); - } - } -#endif -#endif - - - if (level.game_engine_type == GAME_ENGINE_TYPE_EM) { GameActions_EM_Main(); @@ -12647,7 +11161,6 @@ void GameActions_RND() InitPlayfieldScanModeVars(); -#if USE_ONE_MORE_CHANGE_PER_FRAME if (game.engine_version >= VERSION_IDENT(3,2,0,7)) { SCAN_PLAYFIELD(x, y) @@ -12656,7 +11169,6 @@ void GameActions_RND() ChangeEvent[x][y] = -1; } } -#endif if (game.set_centered_player) { @@ -12756,10 +11268,6 @@ void GameActions_RND() } } -#if 0 - debug_print_timestamp(0, "start main loop profiling"); -#endif - SCAN_PLAYFIELD(x, y) { ChangeCount[x][y] = 0; @@ -12773,7 +11281,6 @@ void GameActions_RND() RemoveField(x, y); } -#if USE_NEW_SNAP_DELAY if (Feld[x][y] == EL_ELEMENT_SNAPPING) { MovDelay[x][y]--; @@ -12785,7 +11292,6 @@ void GameActions_RND() TestIfElementTouchesCustomElement(x, y); /* for empty space */ } } -#endif #if DEBUG if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1) @@ -12834,63 +11340,6 @@ void GameActions_RND() #endif } -#if 0 - debug_print_timestamp(0, "- time for pre-main loop:"); -#endif - -#if 0 // -------------------- !!! TEST ONLY !!! -------------------- - SCAN_PLAYFIELD(x, y) - { - element = Feld[x][y]; - graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]); - -#if 1 - { -#if 1 - int element2 = element; - int graphic2 = graphic; -#else - int element2 = Feld[x][y]; - int graphic2 = el_act_dir2img(element2, GfxAction[x][y], GfxDir[x][y]); -#endif - int last_gfx_frame = GfxFrame[x][y]; - - if (graphic_info[graphic2].anim_global_sync) - GfxFrame[x][y] = FrameCounter; - else if (ANIM_MODE(graphic2) == ANIM_CE_VALUE) - GfxFrame[x][y] = CustomValue[x][y]; - else if (ANIM_MODE(graphic2) == ANIM_CE_SCORE) - GfxFrame[x][y] = element_info[element2].collect_score; - else if (ANIM_MODE(graphic2) == ANIM_CE_DELAY) - GfxFrame[x][y] = ChangeDelay[x][y]; - - if (redraw && GfxFrame[x][y] != last_gfx_frame) - DrawLevelGraphicAnimation(x, y, graphic2); - } -#else - ResetGfxFrame(x, y, TRUE); -#endif - -#if 1 - if (ANIM_MODE(graphic) == ANIM_RANDOM && - IS_NEXT_FRAME(GfxFrame[x][y], graphic)) - ResetRandomAnimationValue(x, y); -#endif - -#if 1 - SetRandomAnimationValue(x, y); -#endif - -#if 1 - PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]); -#endif - } -#endif // -------------------- !!! TEST ONLY !!! -------------------- - -#if 0 - debug_print_timestamp(0, "- time for TEST loop: -->"); -#endif - SCAN_PLAYFIELD(x, y) { element = Feld[x][y]; @@ -12920,157 +11369,12 @@ void GameActions_RND() { int page = element_info[element].event_page_nr[CE_DELAY]; -#if 1 HandleElementChange(x, y, page); -#else - if (CAN_CHANGE(element)) - HandleElementChange(x, y, page); - - if (HAS_ACTION(element)) - ExecuteCustomElementAction(x, y, element, page); -#endif - - element = Feld[x][y]; - graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]); - } - -#if 0 // --------------------------------------------------------------------- - - if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element))) - { - StartMoving(x, y); element = Feld[x][y]; graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]); - - if (IS_ANIMATED(graphic) && - !IS_MOVING(x, y) && - !Stop[x][y]) - DrawLevelGraphicAnimationIfNeeded(x, y, graphic); - - if (IS_GEM(element) || element == EL_SP_INFOTRON) - TEST_DrawTwinkleOnField(x, y); - } - else if (IS_MOVING(x, y)) - ContinueMoving(x, y); - else - { - switch (element) - { - case EL_ACID: - case EL_EXIT_OPEN: - case EL_EM_EXIT_OPEN: - case EL_SP_EXIT_OPEN: - case EL_STEEL_EXIT_OPEN: - case EL_EM_STEEL_EXIT_OPEN: - case EL_SP_TERMINAL: - case EL_SP_TERMINAL_ACTIVE: - case EL_EXTRA_TIME: - case EL_SHIELD_NORMAL: - case EL_SHIELD_DEADLY: - if (IS_ANIMATED(graphic)) - DrawLevelGraphicAnimationIfNeeded(x, y, graphic); - break; - - case EL_DYNAMITE_ACTIVE: - case EL_EM_DYNAMITE_ACTIVE: - case EL_DYNABOMB_PLAYER_1_ACTIVE: - case EL_DYNABOMB_PLAYER_2_ACTIVE: - case EL_DYNABOMB_PLAYER_3_ACTIVE: - case EL_DYNABOMB_PLAYER_4_ACTIVE: - case EL_SP_DISK_RED_ACTIVE: - CheckDynamite(x, y); - break; - - case EL_AMOEBA_GROWING: - AmoebeWaechst(x, y); - break; - - case EL_AMOEBA_SHRINKING: - AmoebaDisappearing(x, y); - break; - -#if !USE_NEW_AMOEBA_CODE - case EL_AMOEBA_WET: - case EL_AMOEBA_DRY: - case EL_AMOEBA_FULL: - case EL_BD_AMOEBA: - case EL_EMC_DRIPPER: - AmoebeAbleger(x, y); - break; -#endif - - case EL_GAME_OF_LIFE: - case EL_BIOMAZE: - Life(x, y); - break; - - case EL_EXIT_CLOSED: - CheckExit(x, y); - break; - - case EL_EM_EXIT_CLOSED: - CheckExitEM(x, y); - break; - - case EL_STEEL_EXIT_CLOSED: - CheckExitSteel(x, y); - break; - - case EL_EM_STEEL_EXIT_CLOSED: - CheckExitSteelEM(x, y); - break; - - case EL_SP_EXIT_CLOSED: - CheckExitSP(x, y); - break; - - case EL_EXPANDABLE_WALL_GROWING: - case EL_EXPANDABLE_STEELWALL_GROWING: - MauerWaechst(x, y); - break; - - case EL_EXPANDABLE_WALL: - case EL_EXPANDABLE_WALL_HORIZONTAL: - case EL_EXPANDABLE_WALL_VERTICAL: - case EL_EXPANDABLE_WALL_ANY: - case EL_BD_EXPANDABLE_WALL: - MauerAbleger(x, y); - break; - - case EL_EXPANDABLE_STEELWALL_HORIZONTAL: - case EL_EXPANDABLE_STEELWALL_VERTICAL: - case EL_EXPANDABLE_STEELWALL_ANY: - MauerAblegerStahl(x, y); - break; - - case EL_FLAMES: - CheckForDragon(x, y); - break; - - case EL_EXPLOSION: - break; - - case EL_ELEMENT_SNAPPING: - case EL_DIAGONAL_SHRINKING: - case EL_DIAGONAL_GROWING: - { - graphic = - el_act_dir2img(GfxElement[x][y], GfxAction[x][y],GfxDir[x][y]); - - DrawLevelGraphicAnimationIfNeeded(x, y, graphic); - break; - } - - default: - if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y)) - DrawLevelGraphicAnimationIfNeeded(x, y, graphic); - break; - } } -#else // --------------------------------------------------------------------- - if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element))) { StartMoving(x, y); @@ -13153,8 +11457,6 @@ void GameActions_RND() else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y)) DrawLevelGraphicAnimationIfNeeded(x, y, graphic); -#endif // --------------------------------------------------------------------- - if (IS_BELT_ACTIVE(element)) PlayLevelSoundAction(x, y, ACTION_ACTIVE); @@ -13180,10 +11482,6 @@ void GameActions_RND() } } -#if 0 - debug_print_timestamp(0, "- time for MAIN loop: -->"); -#endif - #if USE_NEW_AMOEBA_CODE /* new experimental amoeba growth stuff */ if (!(FrameCounter % 8)) @@ -13216,27 +11514,22 @@ void GameActions_RND() } #endif -#if 0 - if (game.explosions_delayed) -#endif - { - game.explosions_delayed = FALSE; - - SCAN_PLAYFIELD(x, y) - { - element = Feld[x][y]; + game.explosions_delayed = FALSE; - if (ExplodeField[x][y]) - Explode(x, y, EX_PHASE_START, ExplodeField[x][y]); - else if (element == EL_EXPLOSION) - Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL); + SCAN_PLAYFIELD(x, y) + { + element = Feld[x][y]; - ExplodeField[x][y] = EX_TYPE_NONE; - } + if (ExplodeField[x][y]) + Explode(x, y, EX_PHASE_START, ExplodeField[x][y]); + else if (element == EL_EXPLOSION) + Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL); - game.explosions_delayed = TRUE; + ExplodeField[x][y] = EX_TYPE_NONE; } + game.explosions_delayed = TRUE; + if (game.magic_wall_active) { if (!(game.magic_wall_time_left % 4)) @@ -13338,12 +11631,7 @@ void GameActions_RND() #if USE_DELAYED_GFX_REDRAW SCAN_PLAYFIELD(x, y) { -#if 1 if (GfxRedraw[x][y] != GFX_REDRAW_NONE) -#else - if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)) && - GfxRedraw[x][y] != GFX_REDRAW_NONE) -#endif { /* !!! PROBLEM: THIS REDRAWS THE PLAYFIELD _AFTER_ THE SCAN, BUT TILES !!! MAY HAVE CHANGED AFTER BEING DRAWN DURING PLAYFIELD SCAN !!! */ @@ -13398,11 +11686,6 @@ void GameActions_RND() local_player->show_envelope = 0; } -#if 0 - debug_print_timestamp(0, "stop main loop profiling "); - printf("----------------------------------------------------------\n"); -#endif - /* use random number generator in every frame to make it less predictable */ if (game.engine_version >= VERSION_IDENT(3,1,1,0)) RND(1); @@ -13449,82 +11732,9 @@ static boolean AllPlayersInVisibleScreen() void ScrollLevel(int dx, int dy) { -#if 0 - /* (directly solved in BlitBitmap() now) */ - static Bitmap *bitmap_db_field2 = NULL; - int softscroll_offset = (setup.soft_scrolling ? TILEX : 0); - int x, y; -#else - int x, y; -#endif - -#if 0 - /* !!! THIS IS APPARENTLY WRONG FOR PLAYER RELOCATION !!! */ - /* only horizontal XOR vertical scroll direction allowed */ - if ((dx == 0 && dy == 0) || (dx != 0 && dy != 0)) - return; -#endif - -#if 0 - /* (directly solved in BlitBitmap() now) */ - if (bitmap_db_field2 == NULL) - bitmap_db_field2 = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH); - - /* needed when blitting directly to same bitmap -- should not be needed with - recent SDL libraries, but apparently does not work in 1.2.11 directly */ - BlitBitmap(drawto_field, bitmap_db_field2, - FX + TILEX * (dx == -1) - softscroll_offset, - FY + TILEY * (dy == -1) - softscroll_offset, - SXSIZE - TILEX * (dx != 0) + 2 * softscroll_offset, - SYSIZE - TILEY * (dy != 0) + 2 * softscroll_offset, - FX + TILEX * (dx == 1) - softscroll_offset, - FY + TILEY * (dy == 1) - softscroll_offset); - BlitBitmap(bitmap_db_field2, drawto_field, - FX + TILEX * (dx == 1) - softscroll_offset, - FY + TILEY * (dy == 1) - softscroll_offset, - SXSIZE - TILEX * (dx != 0) + 2 * softscroll_offset, - SYSIZE - TILEY * (dy != 0) + 2 * softscroll_offset, - FX + TILEX * (dx == 1) - softscroll_offset, - FY + TILEY * (dy == 1) - softscroll_offset); - -#else - -#if 0 - /* !!! DOES NOT WORK FOR DIAGONAL PLAYER RELOCATION !!! */ - int xsize = (BX2 - BX1 + 1); - int ysize = (BY2 - BY1 + 1); - int start = (dx != 0 ? (dx == -1 ? BX1 : BX2) : (dy == -1 ? BY1 : BY2)); - int end = (dx != 0 ? (dx == -1 ? BX2 : BX1) : (dy == -1 ? BY2 : BY1)); - int step = (start < end ? +1 : -1); - - for (i = start; i != end; i += step) - { - BlitBitmap(drawto_field, drawto_field, - FX + TILEX * (dx != 0 ? i + step : 0), - FY + TILEY * (dy != 0 ? i + step : 0), - TILEX * (dx != 0 ? 1 : xsize), - TILEY * (dy != 0 ? 1 : ysize), - FX + TILEX * (dx != 0 ? i : 0), - FY + TILEY * (dy != 0 ? i : 0)); - } - -#else - -#if NEW_TILESIZE -#if NEW_SCROLL int softscroll_offset = (setup.soft_scrolling ? 2 * TILEX_VAR : 0); -#else - int softscroll_offset = (setup.soft_scrolling ? TILEX_VAR : 0); -#endif -#else -#if NEW_SCROLL - int softscroll_offset = (setup.soft_scrolling ? 2 * TILEX : 0); -#else - int softscroll_offset = (setup.soft_scrolling ? TILEX : 0); -#endif -#endif + int x, y; -#if NEW_TILESIZE BlitBitmap(drawto_field, drawto_field, FX + TILEX_VAR * (dx == -1) - softscroll_offset, FY + TILEY_VAR * (dy == -1) - softscroll_offset, @@ -13532,18 +11742,6 @@ void ScrollLevel(int dx, int dy) SYSIZE - TILEY_VAR * (dy != 0) + 2 * softscroll_offset, FX + TILEX_VAR * (dx == 1) - softscroll_offset, FY + TILEY_VAR * (dy == 1) - softscroll_offset); -#else - BlitBitmap(drawto_field, drawto_field, - FX + TILEX * (dx == -1) - softscroll_offset, - FY + TILEY * (dy == -1) - softscroll_offset, - SXSIZE - TILEX * (dx != 0) + 2 * softscroll_offset, - SYSIZE - TILEY * (dy != 0) + 2 * softscroll_offset, - FX + TILEX * (dx == 1) - softscroll_offset, - FY + TILEY * (dy == 1) - softscroll_offset); -#endif - -#endif -#endif if (dx != 0) { @@ -13606,11 +11804,7 @@ static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir) static void CheckGravityMovement(struct PlayerInfo *player) { -#if USE_PLAYER_GRAVITY if (player->gravity && !player->programmed_action) -#else - if (game.gravity && !player->programmed_action) -#endif { int move_dir_horizontal = player->effective_action & MV_HORIZONTAL; int move_dir_vertical = player->effective_action & MV_VERTICAL; @@ -13632,11 +11826,7 @@ static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player) { return CheckGravityMovement(player); -#if USE_PLAYER_GRAVITY if (player->gravity && !player->programmed_action) -#else - if (game.gravity && !player->programmed_action) -#endif { int jx = player->jx, jy = player->jy; boolean field_under_player_is_free = @@ -13663,9 +11853,6 @@ boolean MovePlayerOneStep(struct PlayerInfo *player, { int jx = player->jx, jy = player->jy; int new_jx = jx + dx, new_jy = jy + dy; -#if !USE_FIXED_DONT_RUN_INTO - int element; -#endif int can_move; boolean player_can_move = !player->cannot_move; @@ -13692,36 +11879,9 @@ boolean MovePlayerOneStep(struct PlayerInfo *player, } } -#if 1 if (!options.network && game.centered_player_nr == -1 && !AllPlayersInSight(player, new_jx, new_jy)) return MP_NO_ACTION; -#else - if (!options.network && !AllPlayersInSight(player, new_jx, new_jy)) - return MP_NO_ACTION; -#endif - -#if !USE_FIXED_DONT_RUN_INTO - element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy); - - /* (moved to DigField()) */ - if (player_can_move && DONT_RUN_INTO(element)) - { - if (element == EL_ACID && dx == 0 && dy == 1) - { - SplashAcid(new_jx, new_jy); - Feld[jx][jy] = EL_PLAYER_1; - InitMovingField(jx, jy, MV_DOWN); - Store[jx][jy] = EL_ACID; - ContinueMoving(jx, jy); - BuryPlayer(player); - } - else - TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir); - - return MP_MOVING; - } -#endif can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG); if (can_move != MP_MOVING) @@ -13751,9 +11911,7 @@ boolean MovePlayerOneStep(struct PlayerInfo *player, PlayerVisit[jx][jy] = FrameCounter; -#if USE_UFAST_PLAYER_EXIT_BUGFIX player->is_moving = TRUE; -#endif #if 1 /* should better be called in MovePlayer(), but this breaks some tapes */ @@ -13839,7 +11997,6 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy) moved |= MovePlayerOneStep(player, 0, dy, dx, dy); } -#if USE_FIXED_BORDER_RUNNING_GFX if (!moved && !player->is_active) { player->is_moving = FALSE; @@ -13848,19 +12005,13 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy) player->is_snapping = FALSE; player->is_pushing = FALSE; } -#endif jx = player->jx; jy = player->jy; -#if 1 if (moved & MP_MOVING && !ScreenMovPos && (player->index_nr == game.centered_player_nr || game.centered_player_nr == -1)) -#else - if (moved & MP_MOVING && !ScreenMovPos && - (player == local_player || !options.network)) -#endif { int old_scroll_x = scroll_x, old_scroll_y = scroll_y; int offset = game.scroll_delay_value; @@ -13915,7 +12066,6 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy) if (scroll_x != old_scroll_x || scroll_y != old_scroll_y) { -#if 1 if (!options.network && game.centered_player_nr == -1 && !AllPlayersInVisibleScreen()) { @@ -13923,14 +12073,6 @@ boolean MovePlayer(struct PlayerInfo *player, int dx, int dy) scroll_y = old_scroll_y; } else -#else - if (!options.network && !AllPlayersInVisibleScreen()) - { - scroll_x = old_scroll_x; - scroll_y = old_scroll_y; - } - else -#endif { ScrollScreen(player, SCROLL_INIT); ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y); @@ -13998,16 +12140,11 @@ void ScrollPlayer(struct PlayerInfo *player, int mode) int last_jx = player->last_jx, last_jy = player->last_jy; int move_stepsize = TILEX / player->move_delay_value; -#if USE_NEW_PLAYER_SPEED if (!player->active) return; if (player->MovPos == 0 && mode == SCROLL_GO_ON) /* player not moving */ return; -#else - if (!player->active || player->MovPos == 0) - return; -#endif if (mode == SCROLL_INIT) { @@ -14026,13 +12163,8 @@ void ScrollPlayer(struct PlayerInfo *player, int mode) last_field_block_delay += player->move_delay_value; /* when blocking enabled, prevent moving up despite gravity */ -#if USE_PLAYER_GRAVITY if (player->gravity && player->MovDir == MV_UP) block_delay_adjustment = -1; -#else - if (game.gravity && player->MovDir == MV_UP) - block_delay_adjustment = -1; -#endif } /* add block delay adjustment (also possible when not blocking) */ @@ -14042,17 +12174,12 @@ void ScrollPlayer(struct PlayerInfo *player, int mode) MovDelay[last_jx][last_jy] = last_field_block_delay + 1; } -#if USE_NEW_PLAYER_SPEED if (player->MovPos != 0) /* player has not yet reached destination */ return; -#else - return; -#endif } else if (!FrameReached(&player->actual_frame_counter, 1)) return; -#if USE_NEW_PLAYER_SPEED if (player->MovPos != 0) { player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize; @@ -14062,14 +12189,6 @@ void ScrollPlayer(struct PlayerInfo *player, int mode) if (player->MovPos == 0) CheckGravityMovement(player); } -#else - player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize; - player->GfxPos = move_stepsize * (player->MovPos / move_stepsize); - - /* before DrawPlayer() to draw correct player graphic for this case */ - if (player->MovPos == 0) - CheckGravityMovement(player); -#endif if (player->MovPos == 0) /* player reached destination field */ { @@ -14092,14 +12211,10 @@ void ScrollPlayer(struct PlayerInfo *player, int mode) if (Feld[jx][jy] == EL_EXIT_OPEN || Feld[jx][jy] == EL_EM_EXIT_OPEN || -#if 1 Feld[jx][jy] == EL_EM_EXIT_OPENING || -#endif Feld[jx][jy] == EL_STEEL_EXIT_OPEN || Feld[jx][jy] == EL_EM_STEEL_EXIT_OPEN || -#if 1 Feld[jx][jy] == EL_EM_STEEL_EXIT_OPENING || -#endif Feld[jx][jy] == EL_SP_EXIT_OPEN || Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */ { @@ -14138,13 +12253,8 @@ void ScrollPlayer(struct PlayerInfo *player, int mode) CE_PLAYER_ENTERS_X, player->index_bit, enter_side); -#if USE_FIX_CE_ACTION_WITH_PLAYER CheckTriggeredElementChangeBySide(jx, jy, player->initial_element, CE_MOVE_OF_X, move_direction); -#else - CheckTriggeredElementChangeBySide(jx, jy, player->element_nr, - CE_MOVE_OF_X, move_direction); -#endif } if (game.engine_version >= VERSION_IDENT(3,0,7,0)) @@ -14174,29 +12284,20 @@ void ScrollPlayer(struct PlayerInfo *player, int mode) if (TimeLeft <= 10 && setup.time_limit) PlaySound(SND_GAME_RUNNING_OUT_OF_TIME); -#if 1 game_panel_controls[GAME_PANEL_TIME].value = TimeLeft; DisplayGameControlValues(); -#else - DrawGameValue_Time(TimeLeft); -#endif if (!TimeLeft && setup.time_limit) for (i = 0; i < MAX_PLAYERS; i++) KillPlayer(&stored_player[i]); } -#if 1 else if (game.no_time_limit && !AllPlayersGone) /* level w/o time limit */ { game_panel_controls[GAME_PANEL_TIME].value = TimePlayed; DisplayGameControlValues(); } -#else - else if (game.no_time_limit && !AllPlayersGone) /* level w/o time limit */ - DrawGameValue_Time(TimePlayed); -#endif } if (tape.single_step && tape.recording && !tape.pausing && @@ -14290,7 +12391,6 @@ void TestIfPlayerTouchesCustomElement(int x, int y) CE_PLAYER_TOUCHES_X, player->index_bit, border_side); -#if USE_FIX_CE_ACTION_WITH_PLAYER { /* use player element that is initially defined in the level playfield, not the player element that corresponds to the runtime player number @@ -14301,7 +12401,6 @@ void TestIfPlayerTouchesCustomElement(int x, int y) CheckElementChangeBySide(xx, yy, border_element, player_element, CE_TOUCHING_X, border_side); } -#endif } else if (IS_PLAYER(xx, yy)) /* player found at border element */ { @@ -14319,7 +12418,6 @@ void TestIfPlayerTouchesCustomElement(int x, int y) CE_PLAYER_TOUCHES_X, player->index_bit, center_side); -#if USE_FIX_CE_ACTION_WITH_PLAYER { /* use player element that is initially defined in the level playfield, not the player element that corresponds to the runtime player number @@ -14330,15 +12428,12 @@ void TestIfPlayerTouchesCustomElement(int x, int y) CheckElementChangeBySide(x, y, center_element, player_element, CE_TOUCHING_X, center_side); } -#endif break; } } } -#if USE_ELEMENT_TOUCHING_BUGFIX - void TestIfElementTouchesCustomElement(int x, int y) { static int xy[4][2] = @@ -14424,7 +12519,6 @@ void TestIfElementTouchesCustomElement(int x, int y) CheckElementChangeBySide(x, y, center_element, border_element, CE_TOUCHING_X, border_side); -#if USE_FIX_CE_ACTION_WITH_PLAYER if (IS_PLAYER(xx, yy)) { /* use player element that is initially defined in the level playfield, @@ -14436,74 +12530,9 @@ void TestIfElementTouchesCustomElement(int x, int y) CheckElementChangeBySide(x, y, center_element, player_element, CE_TOUCHING_X, border_side); } -#endif - } -} - -#else - -void TestIfElementTouchesCustomElement_OLD(int x, int y) -{ - static int xy[4][2] = - { - { 0, -1 }, - { -1, 0 }, - { +1, 0 }, - { 0, +1 } - }; - static int trigger_sides[4][2] = - { - /* center side border side */ - { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */ - { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */ - { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */ - { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */ - }; - static int touch_dir[4] = - { - MV_LEFT | MV_RIGHT, - MV_UP | MV_DOWN, - MV_UP | MV_DOWN, - MV_LEFT | MV_RIGHT - }; - boolean change_center_element = FALSE; - int center_element = Feld[x][y]; /* should always be non-moving! */ - int i; - - for (i = 0; i < NUM_DIRECTIONS; i++) - { - int xx = x + xy[i][0]; - int yy = y + xy[i][1]; - int center_side = trigger_sides[i][0]; - int border_side = trigger_sides[i][1]; - int border_element; - - if (!IN_LEV_FIELD(xx, yy)) - continue; - - if (game.engine_version < VERSION_IDENT(3,0,7,0)) - border_element = Feld[xx][yy]; /* may be moving! */ - else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy)) - border_element = Feld[xx][yy]; - else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */ - border_element = MovingOrBlocked2Element(xx, yy); - else - continue; /* center and border element do not touch */ - - /* check for change of center element (but change it only once) */ - if (!change_center_element) - change_center_element = - CheckElementChangeBySide(x, y, center_element, border_element, - CE_TOUCHING_X, border_side); - - /* check for change of border element */ - CheckElementChangeBySide(xx, yy, border_element, center_element, - CE_TOUCHING_X, center_side); } } -#endif - void TestIfElementHitsCustomElement(int x, int y, int direction) { int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0); @@ -14540,7 +12569,6 @@ void TestIfElementHitsCustomElement(int x, int y, int direction) CheckElementChangeBySide(hitx, hity, touched_element, hitting_element, CE_HIT_BY_SOMETHING, opposite_direction); -#if USE_FIX_CE_ACTION_WITH_PLAYER if (IS_PLAYER(hitx, hity)) { /* use player element that is initially defined in the level playfield, @@ -14552,7 +12580,6 @@ void TestIfElementHitsCustomElement(int x, int y, int direction) CheckElementChangeBySide(x, y, hitting_element, player_element, CE_HITTING_X, touched_side); } -#endif } } @@ -14561,69 +12588,6 @@ void TestIfElementHitsCustomElement(int x, int y, int direction) CE_HITTING_SOMETHING, direction); } -#if 0 -void TestIfElementSmashesCustomElement(int x, int y, int direction) -{ - int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0); - int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0); - int hitx = x + dx, hity = y + dy; - int hitting_element = Feld[x][y]; - int touched_element; -#if 0 - boolean object_hit = (IN_LEV_FIELD(hitx, hity) && - !IS_FREE(hitx, hity) && - (!IS_MOVING(hitx, hity) || - MovDir[hitx][hity] != direction || - ABS(MovPos[hitx][hity]) <= TILEY / 2)); -#endif - - if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity)) - return; - -#if 0 - if (IN_LEV_FIELD(hitx, hity) && !object_hit) - return; -#endif - - touched_element = (IN_LEV_FIELD(hitx, hity) ? - MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL); - - CheckElementChangeBySide(x, y, hitting_element, touched_element, - EP_CAN_SMASH_EVERYTHING, direction); - - if (IN_LEV_FIELD(hitx, hity)) - { - int opposite_direction = MV_DIR_OPPOSITE(direction); - int hitting_side = direction; - int touched_side = opposite_direction; -#if 0 - int touched_element = MovingOrBlocked2Element(hitx, hity); -#endif -#if 1 - boolean object_hit = (!IS_MOVING(hitx, hity) || - MovDir[hitx][hity] != direction || - ABS(MovPos[hitx][hity]) <= TILEY / 2); - - object_hit = TRUE; -#endif - - if (object_hit) - { - int i; - - CheckElementChangeBySide(hitx, hity, touched_element, hitting_element, - CE_SMASHED_BY_SOMETHING, opposite_direction); - - CheckElementChangeBySide(x, y, hitting_element, touched_element, - CE_OTHER_IS_SMASHING, touched_side); - - CheckElementChangeBySide(hitx, hity, touched_element, hitting_element, - CE_OTHER_GETS_SMASHED, hitting_side); - } - } -} -#endif - void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir) { int i, kill_x = -1, kill_y = -1; @@ -14955,19 +12919,10 @@ void KillPlayer(struct PlayerInfo *player) player->killed, player->active, player->reanimated); #endif -#if USE_PLAYER_REANIMATION -#if 1 if (player->reanimated) /* killed player may have been reanimated */ player->killed = player->reanimated = FALSE; else BuryPlayer(player); -#else - if (player->killed) /* player may have been reanimated */ - BuryPlayer(player); -#endif -#else - BuryPlayer(player); -#endif } static void KillPlayerUnlessEnemyProtected(int x, int y) @@ -15021,7 +12976,6 @@ void RemovePlayer(struct PlayerInfo *player) ExitY = ZY = jy; } -#if USE_NEW_SNAP_DELAY static void setFieldForSnapping(int x, int y, int element, int direction) { struct ElementInfo *ei = &element_info[element]; @@ -15040,7 +12994,6 @@ static void setFieldForSnapping(int x, int y, int element, int direction) GfxDir[x][y] = direction; GfxFrame[x][y] = -1; } -#endif /* ============================================================================= @@ -15097,11 +13050,7 @@ static int DigField(struct PlayerInfo *player, int opposite_direction = MV_DIR_OPPOSITE(move_direction); int dig_side = MV_DIR_OPPOSITE(move_direction); int old_element = Feld[jx][jy]; -#if USE_FIXED_DONT_RUN_INTO int element = MovingOrBlocked2ElementIfNotLeaving(x, y); -#else - int element; -#endif int collect_count; if (is_player) /* function can also be called by EL_PENGUIN */ @@ -15124,11 +13073,6 @@ static int DigField(struct PlayerInfo *player, } } -#if !USE_FIXED_DONT_RUN_INTO - if (IS_MOVING(x, y) || IS_PLAYER(x, y)) - return MP_NO_ACTION; -#endif - if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0)) old_element = Back[jx][jy]; @@ -15143,7 +13087,6 @@ static int DigField(struct PlayerInfo *player, if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction)) return MP_NO_ACTION; /* field has no opening in this direction */ -#if USE_FIXED_DONT_RUN_INTO if (player_can_move && element == EL_ACID && move_direction == MV_DOWN) { SplashAcid(x, y); @@ -15156,25 +13099,16 @@ static int DigField(struct PlayerInfo *player, return MP_DONT_RUN_INTO; } -#endif -#if USE_FIXED_DONT_RUN_INTO if (player_can_move && DONT_RUN_INTO(element)) { TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir); return MP_DONT_RUN_INTO; } -#endif -#if USE_FIXED_DONT_RUN_INTO if (IS_MOVING(x, y) || IS_PLAYER(x, y)) return MP_NO_ACTION; -#endif - -#if !USE_FIXED_DONT_RUN_INTO - element = Feld[x][y]; -#endif collect_count = element_info[element].collect_count_initial; @@ -15201,17 +13135,10 @@ static int DigField(struct PlayerInfo *player, return MP_NO_ACTION; } -#if USE_PLAYER_GRAVITY if (player->gravity && is_player && !player->is_auto_moving && canFallDown(player) && move_direction != MV_DOWN && !canMoveToValidFieldWithGravity(jx, jy, move_direction)) return MP_NO_ACTION; /* player cannot walk here due to gravity */ -#else - if (game.gravity && is_player && !player->is_auto_moving && - canFallDown(player) && move_direction != MV_DOWN && - !canMoveToValidFieldWithGravity(jx, jy, move_direction)) - return MP_NO_ACTION; /* player cannot walk here due to gravity */ -#endif if (player_can_move && IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction)) @@ -15236,14 +13163,10 @@ static int DigField(struct PlayerInfo *player, } else if (element == EL_EXIT_OPEN || element == EL_EM_EXIT_OPEN || -#if 1 element == EL_EM_EXIT_OPENING || -#endif element == EL_STEEL_EXIT_OPEN || element == EL_EM_STEEL_EXIT_OPEN || -#if 1 element == EL_EM_STEEL_EXIT_OPENING || -#endif element == EL_SP_EXIT_OPEN || element == EL_SP_EXIT_OPENING) { @@ -15314,29 +13237,17 @@ static int DigField(struct PlayerInfo *player, element == EL_SP_GRAVITY_PORT_RIGHT || element == EL_SP_GRAVITY_PORT_UP || element == EL_SP_GRAVITY_PORT_DOWN) -#if USE_PLAYER_GRAVITY player->gravity = !player->gravity; -#else - game.gravity = !game.gravity; -#endif else if (element == EL_SP_GRAVITY_ON_PORT_LEFT || element == EL_SP_GRAVITY_ON_PORT_RIGHT || element == EL_SP_GRAVITY_ON_PORT_UP || element == EL_SP_GRAVITY_ON_PORT_DOWN) -#if USE_PLAYER_GRAVITY player->gravity = TRUE; -#else - game.gravity = TRUE; -#endif else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT || element == EL_SP_GRAVITY_OFF_PORT_RIGHT || element == EL_SP_GRAVITY_OFF_PORT_UP || element == EL_SP_GRAVITY_OFF_PORT_DOWN) -#if USE_PLAYER_GRAVITY player->gravity = FALSE; -#else - game.gravity = FALSE; -#endif } /* automatically move to the next field with double speed */ @@ -15368,14 +13279,10 @@ static int DigField(struct PlayerInfo *player, if (mode == DF_SNAP) { -#if USE_NEW_SNAP_DELAY if (level.block_snap_field) setFieldForSnapping(x, y, element, move_direction); else TestIfElementTouchesCustomElement(x, y); /* for empty space */ -#else - TestIfElementTouchesCustomElement(x, y); /* for empty space */ -#endif CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X, player->index_bit, dig_side); @@ -15399,13 +13306,9 @@ static int DigField(struct PlayerInfo *player, { TimeLeft += level.extra_time; -#if 1 game_panel_controls[GAME_PANEL_TIME].value = TimeLeft; DisplayGameControlValues(); -#else - DrawGameValue_Time(TimeLeft); -#endif } else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY) { @@ -15484,13 +13387,9 @@ static int DigField(struct PlayerInfo *player, if (local_player->gems_still_needed < 0) local_player->gems_still_needed = 0; -#if 1 game_panel_controls[GAME_PANEL_GEMS].value = local_player->gems_still_needed; DisplayGameControlValues(); -#else - DrawGameValue_Emeralds(local_player->gems_still_needed); -#endif } RaiseScoreElement(element); @@ -15502,14 +13401,10 @@ static int DigField(struct PlayerInfo *player, if (mode == DF_SNAP) { -#if USE_NEW_SNAP_DELAY if (level.block_snap_field) setFieldForSnapping(x, y, element, move_direction); else TestIfElementTouchesCustomElement(x, y); /* for empty space */ -#else - TestIfElementTouchesCustomElement(x, y); /* for empty space */ -#endif CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X, player->index_bit, dig_side); @@ -15621,13 +13516,8 @@ static int DigField(struct PlayerInfo *player, PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY, ACTION_FILLING); -#if 1 if (local_player->sokobanfields_still_needed == 0 && (game.emulation == EMU_SOKOBAN || level.auto_exit_sokoban)) -#else - if (local_player->sokobanfields_still_needed == 0 && - game.emulation == EMU_SOKOBAN) -#endif { PlayerWins(player); @@ -15752,13 +13642,9 @@ static int DigField(struct PlayerInfo *player, TimeLeft += level.time_orb_time; game.no_time_limit = FALSE; -#if 1 game_panel_controls[GAME_PANEL_TIME].value = TimeLeft; DisplayGameControlValues(); -#else - DrawGameValue_Time(TimeLeft); -#endif } ResetGfxAnimation(x, y); @@ -15885,20 +13771,9 @@ static boolean DigFieldByCE(int x, int y, int digging_element) Store[x][y] = EL_EMPTY; -#if 1 /* this makes it possible to leave the removed element again */ if (IS_EQUAL_OR_IN_GROUP(element, MOVE_ENTER_EL(digging_element))) Store[x][y] = element; -#else - if (IS_EQUAL_OR_IN_GROUP(element, MOVE_ENTER_EL(digging_element))) - { - int move_leave_element = element_info[digging_element].move_leave_element; - - /* this makes it possible to leave the removed element again */ - Store[x][y] = (move_leave_element == EL_TRIGGER_ELEMENT ? - element : move_leave_element); - } -#endif return TRUE; } @@ -15940,14 +13815,9 @@ static boolean SnapField(struct PlayerInfo *player, int dx, int dy) return FALSE; } -#if USE_NEW_CONTINUOUS_SNAPPING /* prevent snapping with already pressed snap key when not allowed */ if (player->is_snapping && !can_continue_snapping) return FALSE; -#else - if (player->is_snapping) - return FALSE; -#endif player->MovDir = snap_direction; @@ -15989,17 +13859,7 @@ static boolean DropElement(struct PlayerInfo *player) int dropx = player->jx, dropy = player->jy; int drop_direction = player->MovDir; int drop_side = drop_direction; -#if 1 int drop_element = get_next_dropped_element(player); -#else - int drop_element = (player->inventory_size > 0 ? - player->inventory_element[player->inventory_size - 1] : - player->inventory_infinite_element != EL_UNDEFINED ? - player->inventory_infinite_element : - player->dynabombs_left > 0 ? - EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr : - EL_UNDEFINED); -#endif player->is_dropping_pressed = TRUE; @@ -16105,28 +13965,13 @@ static boolean DropElement(struct PlayerInfo *player) if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) && element_info[new_element].move_pattern == MV_WHEN_DROPPED) { -#if 0 - int move_direction; - int nextx, nexty; -#endif - if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC) MovDir[dropx][dropy] = drop_direction; -#if 0 - move_direction = MovDir[dropx][dropy]; - nextx = dropx + GET_DX_FROM_DIR(move_direction); - nexty = dropy + GET_DY_FROM_DIR(move_direction); -#endif - ChangeCount[dropx][dropy] = 0; /* allow at least one more change */ -#if USE_FIX_IMPACT_COLLISION /* do not cause impact style collision by dropping elements that can fall */ CheckCollision[dropx][dropy] = CHECK_DELAY_COLLISION; -#else - CheckCollision[dropx][dropy] = CHECK_DELAY_COLLISION; -#endif } player->drop_delay = GET_NEW_DROP_DELAY(drop_element); @@ -16427,10 +14272,6 @@ void PlayLevelSound_SP(int xx, int yy, int element_sp, int action_sp) int x = xx - offset; int y = yy - offset; -#if 0 - printf("::: %d -> %d\n", element_sp, action_sp); -#endif - PlayLevelSoundElementAction(x, y, element, action); } @@ -16438,13 +14279,9 @@ void RaiseScore(int value) { local_player->score += value; -#if 1 game_panel_controls[GAME_PANEL_SCORE].value = local_player->score; DisplayGameControlValues(); -#else - DrawGameValue_Score(local_player->score); -#endif } void RaiseScoreElement(int element) @@ -16531,11 +14368,9 @@ void RequestQuitGameExt(boolean skip_request, boolean quick_quit, char *message) { if (skip_request || Request(message, REQ_ASK | REQ_STAY_CLOSED)) { -#if 1 /* closing door required in case of envelope style request dialogs */ if (!skip_request) CloseDoor(DOOR_CLOSE_1); -#endif #if defined(NETWORK_AVALIABLE) if (options.network) @@ -16545,32 +14380,14 @@ void RequestQuitGameExt(boolean skip_request, boolean quick_quit, char *message) { if (quick_quit) { -#if 1 - -#if 1 FadeSkipNextFadeIn(); -#else - fading = fading_none; -#endif - -#else - OpenDoor(DOOR_CLOSE_1); -#endif game_status = GAME_MODE_MAIN; -#if 1 DrawAndFadeInMainMenu(REDRAW_FIELD); -#else - DrawMainMenu(); -#endif } else { -#if 0 - FadeOut(REDRAW_FIELD); -#endif - game_status = GAME_MODE_MAIN; DrawAndFadeInMainMenu(REDRAW_FIELD); @@ -16607,18 +14424,7 @@ unsigned int InitEngineRandom_RND(int seed) { game.num_random_calls = 0; -#if 0 - unsigned int rnd_seed = InitEngineRandom(seed); - - printf("::: START RND: %d\n", rnd_seed); - - return rnd_seed; -#else - return InitEngineRandom(seed); - -#endif - } unsigned int RND(int max) @@ -16757,7 +14563,6 @@ void SaveEngineSnapshot() /* free previous snapshot buffers, if needed */ FreeEngineSnapshotBuffers(); -#if 1 /* copy some special values to a structure better suited for the snapshot */ if (level.game_engine_type == GAME_ENGINE_TYPE_RND) @@ -16775,19 +14580,6 @@ void SaveEngineSnapshot() SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_em)); if (level.game_engine_type == GAME_ENGINE_TYPE_SP) SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_sp)); -#else - /* copy some special values to a structure better suited for the snapshot */ - - SaveEngineSnapshotValues_RND(); - SaveEngineSnapshotValues_EM(); - SaveEngineSnapshotValues_SP(); - - /* save values stored in special snapshot structure */ - - SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_rnd)); - SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_em)); - SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_sp)); -#endif /* save further RND engine values */ @@ -16883,40 +14675,12 @@ void LoadEngineSnapshot() /* restore special values from snapshot structure */ -#if 1 if (level.game_engine_type == GAME_ENGINE_TYPE_RND) LoadEngineSnapshotValues_RND(); if (level.game_engine_type == GAME_ENGINE_TYPE_EM) LoadEngineSnapshotValues_EM(); if (level.game_engine_type == GAME_ENGINE_TYPE_SP) LoadEngineSnapshotValues_SP(); -#else - LoadEngineSnapshotValues_RND(); - LoadEngineSnapshotValues_EM(); - LoadEngineSnapshotValues_SP(); -#endif - -#if 0 - printf("::: %d, %d (LoadEngineSnapshot / 1)\n", scroll_x, scroll_y); -#endif - -#if 0 - // needed if tile size was different when saving and loading engine snapshot - if (local_player->present) - { - scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left : - local_player->jx > SBX_Right + MIDPOSX ? SBX_Right : - local_player->jx - MIDPOSX); - - scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper : - local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower : - local_player->jy - MIDPOSY); - } -#endif - -#if 0 - printf("::: %d, %d (LoadEngineSnapshot / 1)\n", scroll_x, scroll_y); -#endif } boolean CheckEngineSnapshot() @@ -17195,19 +14959,11 @@ static void HandleGameButtons(struct GadgetInfo *gi) void HandleSoundButtonKeys(Key key) { -#if 1 + if (key == setup.shortcut.sound_simple) ClickOnGadget(game_gadget[SOUND_CTRL_ID_SIMPLE], MB_LEFTBUTTON); else if (key == setup.shortcut.sound_loops) ClickOnGadget(game_gadget[SOUND_CTRL_ID_LOOPS], MB_LEFTBUTTON); else if (key == setup.shortcut.sound_music) ClickOnGadget(game_gadget[SOUND_CTRL_ID_MUSIC], MB_LEFTBUTTON); -#else - if (key == setup.shortcut.sound_simple) - HandleGameButtonsExt(SOUND_CTRL_ID_SIMPLE); - else if (key == setup.shortcut.sound_loops) - HandleGameButtonsExt(SOUND_CTRL_ID_LOOPS); - else if (key == setup.shortcut.sound_music) - HandleGameButtonsExt(SOUND_CTRL_ID_MUSIC); -#endif } diff --git a/src/game.h b/src/game.h index 49c866a5..22ea2e7e 100644 --- a/src/game.h +++ b/src/game.h @@ -28,7 +28,6 @@ #define NUM_PANEL_ELEMENTS 8 #define NUM_PANEL_CE_SCORE 8 -#if 1 struct GamePanelInfo { struct TextPosInfo level_number; @@ -99,19 +98,6 @@ struct GameButtonInfo struct Rect load; }; -#else - -struct GamePanelInfo -{ - struct XY level; - struct XY gems; - struct XY inventory; - struct XY keys; - struct XY score; - struct XY time; -}; -#endif - struct GameInfo { /* values for control panel */ diff --git a/src/game_em/cave.c b/src/game_em/cave.c index 09cc5955..b89c42f3 100644 --- a/src/game_em/cave.c +++ b/src/game_em/cave.c @@ -45,7 +45,6 @@ void setLevelInfoToDefaults_EM(void) for (i = 0; i < TILE_MAX; i++) lev.android_array[i] = Xblank; -#if 1 /* initial number of players in this level */ lev.home_initial = 0; @@ -54,16 +53,6 @@ void setLevelInfoToDefaults_EM(void) ply[i].exists = 0; ply[i].alive_initial = FALSE; } -#else - /* initial number of players in this level */ - lev.home_initial = (setup.team_mode ? 2 : 1); - - for (i = 0; i < MAX_PLAYERS; i++) - { - ply[i].exists = 0; - ply[i].alive_initial = (lev.home_initial > i ? TRUE : FALSE); - } -#endif } @@ -74,8 +63,6 @@ void setLevelInfoToDefaults_EM(void) #define MAX_EM_LEVEL_SIZE 16384 -#if 1 - boolean LoadNativeLevel_EM(char *filename, boolean level_info_only) { unsigned char raw_leveldata[MAX_EM_LEVEL_SIZE]; @@ -119,51 +106,3 @@ boolean LoadNativeLevel_EM(char *filename, boolean level_info_only) return TRUE; } - -#else - -boolean LoadNativeLevel_EM(char *filename, boolean level_info_only) -{ - unsigned char raw_leveldata[MAX_EM_LEVEL_SIZE]; - int raw_leveldata_length; - int file_version; - FILE *file; - - /* always start with reliable default values */ - setLevelInfoToDefaults_EM(); - - if (!(file = fopen(filename, MODE_READ))) - { - if (!level_info_only) - Error(ERR_WARN, "cannot open level '%s' -- using empty level", filename); - - return FALSE; - } - - raw_leveldata_length = fread(raw_leveldata, 1, MAX_EM_LEVEL_SIZE, file); - - fclose(file); - - if (raw_leveldata_length <= 0) - { - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); - - return FALSE; - } - - file_version = cleanup_em_level(raw_leveldata, raw_leveldata_length,filename); - - if (file_version == FILE_VERSION_EM_UNKNOWN) - { - Error(ERR_WARN, "unknown EM level '%s' -- using empty level", filename); - - return FALSE; - } - - convert_em_level(raw_leveldata, file_version); - prepare_em_level(); - - return TRUE; -} - -#endif diff --git a/src/game_em/convert.c b/src/game_em/convert.c index 6dc72ee0..3631114c 100644 --- a/src/game_em/convert.c +++ b/src/game_em/convert.c @@ -150,9 +150,6 @@ int cleanup_em_level(unsigned char *src, int length, char *filename) for (i = 2112; i < 2148; i++) src[i] = src[i - 64]; } - -#if 1 /* ================================================================== */ - else if (length >= 2106 && (src[1983] == 27 || /* encrypted (only EM I/II/III) */ src[1983] == 116 || /* unencrypted (usual case) */ @@ -237,93 +234,6 @@ int cleanup_em_level(unsigned char *src, int length, char *filename) return FILE_VERSION_EM_UNKNOWN; } -#else /* ================================================================== */ - -#if 0 - else if (length >= 2106) /* !!! TEST ONLY: SHOW BROKEN LEVELS !!! */ -#else - else if (length >= 2106 && - src[1983] == 116) -#endif - { - /* ---------- this cave has V4 file format ---------- */ - file_version = FILE_VERSION_EM_V4; - - /* remap elements to internal EMC level format */ - for (i = 0; i < 2048; i++) - src[i] = remap_v4[src[i]]; - for (i = 2048; i < 2084; i++) - src[i] = remap_v4eater[src[i] >= 28 ? 0 : src[i]]; - for (i = 2112; i < 2148; i++) - src[i] = src[i - 64]; - } - else if (length >= 2106 && - src[0] == 241 && /* <-- Emerald Mine I and III levels */ - src[1983] == 27) - { - unsigned char j = 94; - - /* ---------- this cave has V3 file format ---------- */ - file_version = FILE_VERSION_EM_V3; - - /* decrypt encrypted level file */ - for (i = 0; i < 2106; i++) - src[i] = (src[i] ^ (j += 7)) - 0x11; - - src[1] = 131; - - /* remap elements to internal EMC level format */ - for (i = 0; i < 2048; i++) - src[i] = remap_v4[src[i]]; - for (i = 2048; i < 2084; i++) - src[i] = remap_v4eater[src[i] >= 28 ? 0 : src[i]]; - for (i = 2112; i < 2148; i++) - src[i] = src[i - 64]; - } -#if 1 - else if (length >= 2106 && - src[0] == 245 && /* <-- Emerald Mine II levels */ - src[1983] == 27) - { - unsigned char j = 94; - - /* ---------- this cave has V3 file format ---------- */ - file_version = FILE_VERSION_EM_V3; - - /* decrypt encrypted level file */ - for (i = 0; i < 2106; i++) - src[i] = (src[i] ^ (j += 7)) - 0x11; - - src[0] = 131; /* needed for Emerald Mine II levels */ - src[1] = 131; - - /* remap elements to internal EMC level format */ - for (i = 0; i < 2048; i++) - src[i] = remap_v4[src[i]]; - for (i = 2048; i < 2084; i++) - src[i] = remap_v4eater[src[i] >= 28 ? 0 : src[i]]; - for (i = 2112; i < 2148; i++) - src[i] = src[i - 64]; - - /* fix copyright sign in Emerald Mine II levels */ - for (i = 0; i < 2048; i++) - if (src[i] == 241) - src[i] = 254; /* replace 'Xdecor_1' with 'Xalpha_copyr' */ - } -#endif - else - { - /* ---------- this cave has unknown file format ---------- */ - -#if 0 - printf("::: %d, %d\n", src[0], src[1983]); -#endif - - return 0; - } - -#endif /* ================================================================== */ - if (file_version < FILE_VERSION_EM_V6) { /* id */ @@ -347,17 +257,7 @@ int cleanup_em_level(unsigned char *src, int length, char *filename) /* ball data */ src[2159] = 128; - -#if 0 - printf("::: STORED TIME (< V6): %d s\n", src[2094] * 10); -#endif - } -#if 0 - else - { - printf("::: STORED TIME (>= V6): %d s\n", src[2110] * 256 + src[2111]); } -#endif /* ---------- at this stage, the cave data always has V6 format ---------- */ @@ -554,12 +454,8 @@ int cleanup_em_level(unsigned char *src, int length, char *filename) /* size of v6 cave */ length = 2172; -#if 1 -#if 1 if (options.debug) -#endif printf("::: EM level file version: %d\n", file_version); -#endif return file_version; } @@ -1093,14 +989,8 @@ void convert_em_level(unsigned char *src, int file_version) /* at last, set the two players at their positions in the playfield */ /* (native EM[C] levels always have exactly two players in a level) */ -#if 1 for (i = 0; i < 2; i++) native_em_level.cave[ply[i].x_initial][ply[i].y_initial] = Zplayer; -#else - for (i = 0; i < 2; i++) - if (ply[i].alive_initial) - native_em_level.cave[ply[i].x_initial][ply[i].y_initial] = Zplayer; -#endif native_em_level.file_version = file_version; } @@ -1109,11 +999,7 @@ void prepare_em_level(void) { int i, x, y; int players_left; -#if 1 boolean team_mode; -#else - int num_tape_players; -#endif /* reset all runtime variables to their initial values */ @@ -1129,11 +1015,7 @@ void prepare_em_level(void) for (x = 0; x < WIDTH; x++) Draw[y][x] = Cave[y][x]; -#if 1 lev.time_initial = lev.time_seconds; -#else - lev.time_initial = (lev.time_seconds * 50 + 7) / 8; -#endif lev.time = lev.time_initial; lev.required = lev.required_initial; @@ -1180,27 +1062,10 @@ void prepare_em_level(void) } } -#if 1 team_mode = getTeamMode_EM(); if (!team_mode) lev.home_initial = 1; -#else - num_tape_players = getNumActivePlayers_EM(); - -#if 0 - printf("::: getNumActivePlayers_EM: %d\n", num_tape_players); -#endif - -#if 1 - lev.home_initial = MIN(lev.home_initial, num_tape_players); -#else - if (num_tape_players != -1) - lev.home_initial = MIN(lev.home_initial, num_tape_players); - else if (!setup.team_mode) - lev.home_initial = MIN(lev.home_initial, 1); -#endif -#endif lev.home = lev.home_initial; players_left = lev.home_initial; @@ -1240,11 +1105,6 @@ void prepare_em_level(void) ply[i].joy_n = ply[i].joy_e = ply[i].joy_s = ply[i].joy_w = 0; ply[i].joy_snap = ply[i].joy_drop = 0; ply[i].joy_stick = ply[i].joy_spin = 0; - -#if 0 - printf("player %d: x/y == %d/%d, alive == %d\n", - i, ply[i].x_initial, ply[i].y_initial, ply[i].alive); -#endif } game_em.any_player_moving = FALSE; diff --git a/src/game_em/global.h b/src/game_em/global.h index 2da0ec8e..0bad3d3d 100644 --- a/src/game_em/global.h +++ b/src/game_em/global.h @@ -14,10 +14,6 @@ extern int debug; extern char *progname; extern char *arg_basedir; -#if 0 -extern int TILEX, TILEY; -#endif - extern int frame; extern short ulaw_to_linear[256]; @@ -28,11 +24,7 @@ extern unsigned char linear_to_ulaw[65536]; int open_all(void); void close_all(void); -#if 1 void readjoy(byte, struct PLAYER *); -#else -void readjoy(byte); -#endif void input_eventloop(void); void blitscreen(void); diff --git a/src/game_em/graphics.c b/src/game_em/graphics.c index 5e53a433..12c62180 100644 --- a/src/game_em/graphics.c +++ b/src/game_em/graphics.c @@ -30,34 +30,13 @@ #define USE_EXTENDED_GRAPHICS_ENGINE 1 -#if 0 -int TILEX = ORIG_TILEX * ZOOM_FACTOR; -int TILEY = ORIG_TILEY * ZOOM_FACTOR; -#endif - int frame; /* current screen frame */ int screen_x, screen_y; /* current scroll position */ /* tiles currently on screen */ -#if 1 static int screentiles[MAX_PLAYFIELD_HEIGHT + 2][MAX_PLAYFIELD_WIDTH + 2]; static int crumbled_state[MAX_PLAYFIELD_HEIGHT + 2][MAX_PLAYFIELD_WIDTH + 2]; - static boolean redraw[MAX_PLAYFIELD_WIDTH + 2][MAX_PLAYFIELD_HEIGHT + 2]; -#else -static int screentiles[MAX_BUF_YSIZE][MAX_BUF_XSIZE]; -static int crumbled_state[MAX_BUF_YSIZE][MAX_BUF_XSIZE]; - -static boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; -#endif - -#if 0 -#if 1 -int centered_player_nr; -#else -static int centered_player_nr; -#endif -#endif /* copy the entire screen to the window at the scroll position */ @@ -71,24 +50,11 @@ void BlitScreenToBitmap_EM(Bitmap *target_bitmap) int full_xsize = lev.width * TILEX; int full_ysize = lev.height * TILEY; -#if 0 - printf("::: %d, %d\n", screenBitmap->width, screenBitmap->height); - printf("::: %d / %d, %d / %d\n", - MAX_BUF_XSIZE, MAX_BUF_YSIZE, SXSIZE, SYSIZE); -#endif - sxsize = (full_xsize < xsize ? full_xsize : xsize); sysize = (full_ysize < ysize ? full_ysize : ysize); sx = SX + (full_xsize < xsize ? (xsize - full_xsize) / 2 : 0); sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0); -#if 0 - printf("::: %d, %d\n", screenBitmap->width, screenBitmap->height); - BlitBitmap(screenBitmap, target_bitmap, 0, 0, 544, 544, SX, SY); - return; -#endif - -#if 1 if (x < 2 * TILEX && y < 2 * TILEY) { BlitBitmap(screenBitmap, target_bitmap, x, y, @@ -127,46 +93,6 @@ void BlitScreenToBitmap_EM(Bitmap *target_bitmap) x - 2 * TILEX, y - 2 * TILEY, sx + MAX_BUF_XSIZE * TILEX - x, sy + MAX_BUF_YSIZE * TILEY - y); } -#else - if (x < 2 * TILEX && y < 2 * TILEY) - { - BlitBitmap(screenBitmap, target_bitmap, x, y, - SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY); - } - else if (x < 2 * TILEX && y >= 2 * TILEY) - { - BlitBitmap(screenBitmap, target_bitmap, x, y, - SCR_FIELDX * TILEX, MAX_BUF_YSIZE * TILEY - y, - SX, SY); - BlitBitmap(screenBitmap, target_bitmap, x, 0, - SCR_FIELDX * TILEX, y - 2 * TILEY, - SX, SY + MAX_BUF_YSIZE * TILEY - y); - } - else if (x >= 2 * TILEX && y < 2 * TILEY) - { - BlitBitmap(screenBitmap, target_bitmap, x, y, - MAX_BUF_XSIZE * TILEX - x, SCR_FIELDY * TILEY, - SX, SY); - BlitBitmap(screenBitmap, target_bitmap, 0, y, - x - 2 * TILEX, SCR_FIELDY * TILEY, - SX + MAX_BUF_XSIZE * TILEX - x, SY); - } - else - { - BlitBitmap(screenBitmap, target_bitmap, x, y, - MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y, - SX, SY); - BlitBitmap(screenBitmap, target_bitmap, 0, y, - x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y, - SX + MAX_BUF_XSIZE * TILEX - x, SY); - BlitBitmap(screenBitmap, target_bitmap, x, 0, - MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY, - SX, SY + MAX_BUF_YSIZE * TILEY - y); - BlitBitmap(screenBitmap, target_bitmap, 0, 0, - x - 2 * TILEX, y - 2 * TILEY, - SX + MAX_BUF_XSIZE * TILEX - x, SY + MAX_BUF_YSIZE * TILEY - y); - } -#endif } void BackToFront_EM(void) @@ -175,17 +101,9 @@ void BackToFront_EM(void) static boolean scrolling_last = FALSE; int left = screen_x / TILEX; int top = screen_y / TILEY; -#if 1 boolean scrolling = (screen_x != screen_x_last || screen_y != screen_y_last); -#else - boolean scrolling = (screen_x % TILEX != 0 || screen_y % TILEY != 0); -#endif int x, y; -#if 0 - printf("::: %d, %d\n", screen_x, screen_y); -#endif - SyncDisplay(); if (redraw_tiles > REDRAWTILES_THRESHOLD || scrolling || scrolling_last) @@ -198,40 +116,18 @@ void BackToFront_EM(void) } else { -#if 1 -#if 1 boolean half_shifted_x = (screen_x % TILEX != 0); boolean half_shifted_y = (screen_y % TILEY != 0); -#else - boolean half_shifted_x = (EVEN(SCR_FIELDX) && screen_x % TILEX != 0); - boolean half_shifted_y = (EVEN(SCR_FIELDY) && screen_y % TILEY != 0); -#endif int sx, sy; -#if 0 - int sxsize, sysize; -#endif int xsize = SXSIZE; int ysize = SYSIZE; int full_xsize = lev.width * TILEX; int full_ysize = lev.height * TILEY; -#if 0 - sxsize = (full_xsize < xsize ? full_xsize : xsize); - sysize = (full_ysize < ysize ? full_ysize : ysize); -#endif sx = SX + (full_xsize < xsize ? (xsize - full_xsize) / 2 : 0); sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0); -#if 0 -#if 1 - printf("::: %d, %d\n", EVEN(SCR_FIELDX), screen_x); -#else - half_shifted_x = TRUE; - half_shifted_y = FALSE; -#endif -#endif - int x1 = 0, x2 = SCR_FIELDX - (half_shifted_x ? 0 : 1); int y1 = 0, y2 = SCR_FIELDY - (half_shifted_y ? 0 : 1); int scroll_xoffset = (half_shifted_x ? TILEX / 2 : 0); @@ -255,23 +151,6 @@ void BackToFront_EM(void) } InitGfxClipRegion(FALSE, -1, -1, -1, -1); - -#else - - for (x = 0; x < SCR_FIELDX; x++) - { - for (y = 0; y < SCR_FIELDY; y++) - { - int xx = (left + x) % MAX_BUF_XSIZE; - int yy = (top + y) % MAX_BUF_YSIZE; - - if (redraw[xx][yy]) - BlitBitmap(screenBitmap, window, - xx * TILEX, yy * TILEY, TILEX, TILEY, - SX + x * TILEX, SY + y * TILEY); - } - } -#endif } FlushDisplay(); @@ -316,21 +195,12 @@ static void DrawLevelField_EM(int x, int y, int sx, int sy, boolean draw_masked) { struct GraphicInfo_EM *g = getObjectGraphic(x, y); -#if NEW_TILESIZE int src_x = g->src_x + g->src_offset_x * TILESIZE_VAR / TILESIZE; int src_y = g->src_y + g->src_offset_y * TILESIZE_VAR / TILESIZE; int dst_x = sx * TILEX + g->dst_offset_x * TILESIZE_VAR / TILESIZE; int dst_y = sy * TILEY + g->dst_offset_y * TILESIZE_VAR / TILESIZE; int width = g->width * TILESIZE_VAR / TILESIZE; int height = g->height * TILESIZE_VAR / TILESIZE; -#else - int src_x = g->src_x + g->src_offset_x; - int src_y = g->src_y + g->src_offset_y; - int dst_x = sx * TILEX + g->dst_offset_x; - int dst_y = sy * TILEY + g->dst_offset_y; - int width = g->width; - int height = g->height; -#endif int left = screen_x / TILEX; int top = screen_y / TILEY; @@ -363,11 +233,7 @@ static void DrawLevelField_EM(int x, int y, int sx, int sy, static void DrawLevelFieldCrumbled_EM(int x, int y, int sx, int sy, int crm, boolean draw_masked) { -#if 1 struct GraphicInfo_EM *g; -#else - struct GraphicInfo_EM *g = getObjectGraphic(x, y); -#endif int crumbled_border_size; int left = screen_x / TILEX; int top = screen_y / TILEY; @@ -381,22 +247,9 @@ static void DrawLevelFieldCrumbled_EM(int x, int y, int sx, int sy, if (crm == 0) /* no crumbled edges for this tile */ return; -#if 1 g = getObjectGraphic(x, y); -#endif - - crumbled_border_size = g->crumbled_border_size; - -#if NEW_TILESIZE - crumbled_border_size = crumbled_border_size * TILESIZE_VAR / TILESIZE; -#endif -#if 0 - if (x == 3 && y == 3 && frame == 0) - printf("::: %d, %d\n", - graphic_info_em_object[207][0].crumbled_src_x, - graphic_info_em_object[207][0].crumbled_src_y); -#endif + crumbled_border_size = g->crumbled_border_size * TILESIZE_VAR / TILESIZE; for (i = 0; i < 4; i++) { @@ -563,12 +416,6 @@ static void animscreen(void) redraw_screen_tile = (screentiles[sy][sx] != obj || crumbled_state[sy][sx] != crm); -#if 0 - /* !!! TEST ONLY -- CHANGE THIS !!! */ - if (!game.use_native_emc_graphics_engine) - redraw_screen_tile = TRUE; -#endif - /* only redraw screen tiles if they (or their crumbled state) changed */ if (redraw_screen_tile) { @@ -604,10 +451,6 @@ static void blitplayer(struct PLAYER *ply) x2 = x1 + TILEX - 1; y2 = y1 + TILEY - 1; -#if 0 - printf("::: %d, %d\n", x1, y1); -#endif - if ((int)(x2 - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) && (int)(y2 - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1)) { @@ -622,29 +465,13 @@ static void blitplayer(struct PLAYER *ply) int old_sy = old_y % MAX_BUF_YSIZE; int new_sx = new_x % MAX_BUF_XSIZE; int new_sy = new_y % MAX_BUF_YSIZE; -#if 0 - int old_crm = crumbled_state[old_sy][old_sx]; -#endif int new_crm = crumbled_state[new_sy][new_sx]; /* only diggable elements can be crumbled in the classic EM engine */ boolean player_is_digging = (new_crm != 0); -#if 0 - x1 %= MAX_BUF_XSIZE * TILEX; - y1 %= MAX_BUF_YSIZE * TILEY; - x2 %= MAX_BUF_XSIZE * TILEX; - y2 %= MAX_BUF_YSIZE * TILEY; -#endif - if (player_is_digging) { -#if 0 - /* draw the field the player is moving from (under the player) */ - DrawLevelField_EM(old_x, old_y, old_sx, old_sy, FALSE); - DrawLevelFieldCrumbled_EM(old_x, old_y, old_sx, old_sy, old_crm, FALSE); -#endif - /* draw the field the player is moving to (under the player) */ DrawLevelField_EM(new_x, new_y, new_sx, new_sy, FALSE); DrawLevelFieldCrumbled_EM(new_x, new_y, new_sx, new_sy, new_crm, FALSE); @@ -652,10 +479,8 @@ static void blitplayer(struct PLAYER *ply) /* draw the player (masked) over the element he is just digging away */ DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, TRUE); -#if 1 /* draw the field the player is moving from (masked over the player) */ DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE); -#endif } else { @@ -682,17 +507,11 @@ static void blitplayer(struct PLAYER *ply) void game_initscreen(void) { - int x,y; - int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */ - int all_keys_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys; int player_nr; + int x,y; frame = 6; -#if 0 - game.centered_player_nr = getCenteredPlayerNr_EM(); -#endif - player_nr = (game.centered_player_nr != -1 ? game.centered_player_nr : 0); screen_x = VALID_SCREEN_X(PLAYER_SCREEN_X(player_nr)); @@ -706,106 +525,7 @@ void game_initscreen(void) crumbled_state[y][x] = 0; } } - - DrawAllGameValues(lev.required, dynamite_state, lev.score, - lev.time, all_keys_state); -} - -#if 0 -void DrawRelocatePlayer(struct PlayerInfo *player, boolean quick_relocation) -{ - boolean ffwd_delay = (tape.playing && tape.fast_forward); - boolean no_delay = (tape.warp_forward); - int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay); - int wait_delay_value = (no_delay ? 0 : frame_delay_value); - int jx = player->jx; - int jy = player->jy; - - if (quick_relocation) - { - int offset = game.scroll_delay_value; - - if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy))) - { - scroll_x = (player->jx < SBX_Left + MIDPOSX ? SBX_Left : - player->jx > SBX_Right + MIDPOSX ? SBX_Right : - player->jx - MIDPOSX); - - scroll_y = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper : - player->jy > SBY_Lower + MIDPOSY ? SBY_Lower : - player->jy - MIDPOSY); - } - else - { - if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) || - (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset)) - scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset); - - if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) || - (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset)) - scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset); - - /* don't scroll over playfield boundaries */ - if (scroll_x < SBX_Left || scroll_x > SBX_Right) - scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right); - - /* don't scroll over playfield boundaries */ - if (scroll_y < SBY_Upper || scroll_y > SBY_Lower) - scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower); - } - - RedrawPlayfield(TRUE, 0,0,0,0); - } - else - { - int scroll_xx = -999, scroll_yy = -999; - - ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */ - - while (scroll_xx != scroll_x || scroll_yy != scroll_y) - { - int dx = 0, dy = 0; - int fx = FX, fy = FY; - - scroll_xx = (player->jx < SBX_Left + MIDPOSX ? SBX_Left : - player->jx > SBX_Right + MIDPOSX ? SBX_Right : - player->jx - MIDPOSX); - - scroll_yy = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper : - player->jy > SBY_Lower + MIDPOSY ? SBY_Lower : - player->jy - MIDPOSY); - - dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0); - dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0); - - if (dx == 0 && dy == 0) /* no scrolling needed at all */ - break; - - scroll_x -= dx; - scroll_y -= dy; - - fx += dx * TILEX / 2; - fy += dy * TILEY / 2; - - ScrollLevel(dx, dy); - DrawAllPlayers(); - - /* scroll in two steps of half tile size to make things smoother */ - BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY); - FlushDisplay(); - Delay(wait_delay_value); - - /* scroll second step to align at full tile size */ - BackToFront(); - Delay(wait_delay_value); - } - - DrawPlayer(player); - BackToFront(); - Delay(wait_delay_value); - } } -#endif static int getMaxCenterDistancePlayerNr(int center_x, int center_y) { @@ -908,24 +628,10 @@ static boolean checkIfAllPlayersAreVisible(int center_x, int center_y) void RedrawPlayfield_EM(boolean force_redraw) { -#if 0 - boolean all_players_visible = checkIfAllPlayersAreVisible(); -#endif boolean draw_new_player_location = FALSE; boolean quick_relocation = setup.quick_switch; -#if 0 - boolean scrolling = (screen_x % TILEX != 0 || screen_y % TILEY != 0); -#endif -#if 0 - boolean game.set_centered_player = getSetCenteredPlayer_EM(); - int game.centered_player_nr_next = getCenteredPlayerNr_EM(); -#endif -#if 1 int max_center_distance_player_nr = getMaxCenterDistancePlayerNr(screen_x, screen_y); -#else - int player_nr = game_em.last_moving_player; -#endif int stepsize = TILEX / 8; int offset = game.scroll_delay_value * TILEX; int offset_x = offset; @@ -955,46 +661,27 @@ void RedrawPlayfield_EM(boolean force_redraw) } } -#if 1 /* also allow focus switching when screen is scrolled to half tile */ -#else - if (!scrolling) /* screen currently aligned at tile position */ -#endif + if (game.set_centered_player) { -#if 1 - if (game.set_centered_player) -#else - if (game.centered_player_nr != game.centered_player_nr_next) -#endif - { - game.centered_player_nr = game.centered_player_nr_next; + game.centered_player_nr = game.centered_player_nr_next; - draw_new_player_location = TRUE; - force_redraw = TRUE; + draw_new_player_location = TRUE; + force_redraw = TRUE; - game.set_centered_player = FALSE; - } + game.set_centered_player = FALSE; } if (game.centered_player_nr == -1) { -#if 1 if (draw_new_player_location || offset == 0) -#else - if (draw_new_player_location) -#endif { setScreenCenteredToAllPlayers(&sx, &sy); } else { -#if 1 sx = PLAYER_SCREEN_X(max_center_distance_player_nr); sy = PLAYER_SCREEN_Y(max_center_distance_player_nr); -#else - sx = PLAYER_SCREEN_X(game_em.last_moving_player); - sy = PLAYER_SCREEN_Y(game_em.last_moving_player); -#endif } } else @@ -1009,20 +696,11 @@ void RedrawPlayfield_EM(boolean force_redraw) screen_y = VALID_SCREEN_Y(sy); screen_x_old = screen_x; screen_y_old = screen_y; - -#if 0 - offset_x = 0; - offset_y = 0; -#endif } if (draw_new_player_location && !quick_relocation) { -#if 1 unsigned int game_frame_delay_value = getGameFrameDelay_EM(20); -#else - unsigned int game_frame_delay_value = getGameFrameDelay_EM(25); -#endif int wait_delay_value = game_frame_delay_value; int screen_xx = VALID_SCREEN_X(sx); int screen_yy = VALID_SCREEN_Y(sy); @@ -1036,8 +714,6 @@ void RedrawPlayfield_EM(boolean force_redraw) if (dx == 0 && dy == 0) /* no scrolling needed at all */ break; -#if 1 - if (ABS(screen_xx - screen_x) >= TILEX) { screen_x -= dx * TILEX; @@ -1060,36 +736,6 @@ void RedrawPlayfield_EM(boolean force_redraw) dyy = 0; } -#else - -#if 1 - if (ABS(screen_xx - screen_x) >= TILEX || - ABS(screen_yy - screen_y) >= TILEY) - { - screen_x -= dx * TILEX; - screen_y -= dy * TILEY; - - dxx = dx * TILEX / 2; - dyy = dy * TILEY / 2; - } - else - { - screen_x = screen_xx; - screen_y = screen_yy; - - dxx = 0; - dyy = 0; - } -#else - screen_x -= dx * TILEX; - screen_y -= dy * TILEY; - - dxx += dx * TILEX / 2; - dyy += dy * TILEY / 2; -#endif - -#endif - /* scroll in two steps of half tile size to make things smoother */ screen_x += dxx; screen_y += dyy; @@ -1107,10 +753,6 @@ void RedrawPlayfield_EM(boolean force_redraw) screen_x -= dxx; screen_y -= dyy; -#if 0 - SyncDisplay(); -#endif - animscreen(); for (i = 0; i < MAX_PLAYERS; i++) @@ -1145,22 +787,6 @@ void RedrawPlayfield_EM(boolean force_redraw) sy - offset_y > screen_y ? sy - offset_y : screen_y); -#if 0 - printf("::: (%d, %d) => (%d, %d) [(%d, %d), (%d, %d)] [%d, %d] [%d / %d]\n", - screen_x_old, screen_y_old, - screen_x, screen_y, - ply[max_center_distance_player_nr].oldx, - ply[max_center_distance_player_nr].x, - ply[max_center_distance_player_nr].oldy, - ply[max_center_distance_player_nr].y, - sx, sy, - ABS(screen_x - screen_x_old), - ABS(screen_y - screen_y_old)); -#endif - -#if 1 - -#if 1 /* prevent scrolling further than double player step size when scrolling */ if (ABS(screen_x - screen_x_old) > 2 * stepsize) { @@ -1174,36 +800,10 @@ void RedrawPlayfield_EM(boolean force_redraw) screen_y = screen_y_old + dy * 2 * stepsize; } -#else - /* prevent scrolling further than double player step size when scrolling */ - if (ABS(screen_x - screen_x_old) > 2 * stepsize || - ABS(screen_y - screen_y_old) > 2 * stepsize) - { - int dx = SIGN(screen_x - screen_x_old); - int dy = SIGN(screen_y - screen_y_old); - - screen_x = screen_x_old + dx * 2 * stepsize; - screen_y = screen_y_old + dy * 2 * stepsize; - } -#endif - -#else - /* prevent scrolling further than player step size when scrolling */ - if (ABS(screen_x - screen_x_old) > stepsize || - ABS(screen_y - screen_y_old) > stepsize) - { - int dx = SIGN(screen_x - screen_x_old); - int dy = SIGN(screen_y - screen_y_old); - - screen_x = screen_x_old + dx * stepsize; - screen_y = screen_y_old + dy * stepsize; - } -#endif /* prevent scrolling away from the other players when focus on all players */ if (game.centered_player_nr == -1) { -#if 1 /* check if all players are still visible with new scrolling position */ if (checkIfAllPlayersAreVisible(screen_x_old, screen_y_old) && !checkIfAllPlayersAreVisible(screen_x, screen_y)) @@ -1216,17 +816,6 @@ void RedrawPlayfield_EM(boolean force_redraw) if (!checkIfAllPlayersAreVisible(screen_x_old, screen_y)) screen_y = screen_y_old; } -#else - boolean all_players_visible = checkIfAllPlayersAreVisible(); - - if (!all_players_visible) - { - printf("::: not all players visible\n"); - - screen_x = screen_x_old; - screen_y = screen_y_old; - } -#endif } /* prevent scrolling (for screen correcting) if no player is moving */ @@ -1238,9 +827,6 @@ void RedrawPlayfield_EM(boolean force_redraw) else { /* prevent scrolling against the players move direction */ -#if 0 - int player_nr = game_em.last_moving_player; -#endif int player_nr = (game.centered_player_nr == -1 ? max_center_distance_player_nr : game.centered_player_nr); int player_move_dir = game_em.last_player_direction[player_nr]; @@ -1260,14 +846,6 @@ void RedrawPlayfield_EM(boolean force_redraw) for (i = 0; i < MAX_PLAYERS; i++) blitplayer(&ply[i]); - -#if 0 -#if 0 - SyncDisplay(); -#endif - - blitscreen(); -#endif } void game_animscreen(void) @@ -1277,49 +855,4 @@ void game_animscreen(void) void DrawGameDoorValues_EM() { -#if 1 - int dynamite_state; - int key_state; -#else - int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */ - int key_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys; -#endif - -#if 1 - if (game.centered_player_nr == -1) - { -#if 1 - int i; - - dynamite_state = 0; - key_state = 0; - - for (i = 0; i < MAX_PLAYERS; i++) - { - dynamite_state += ply[i].dynamite; - key_state |= ply[i].keys; - } - -#else - - dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */ - key_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys; -#endif - } - else - { - int player_nr = game.centered_player_nr; - - dynamite_state = ply[player_nr].dynamite; - key_state = ply[player_nr].keys; - } -#endif - -#if 1 - DrawAllGameValues(lev.required, dynamite_state, lev.score, - lev.time, key_state); -#else - DrawAllGameValues(lev.required, ply1.dynamite, lev.score, - DISPLAY_TIME(lev.time), ply1.keys | ply2.keys); -#endif } diff --git a/src/game_em/init.c b/src/game_em/init.c index 3aa8361d..d0ccc094 100644 --- a/src/game_em/init.c +++ b/src/game_em/init.c @@ -13,272 +13,47 @@ Bitmap *sprBitmap; Bitmap *screenBitmap; -#if 0 -Pixmap spriteBitmap; -#endif - Pixmap objPixmap; Pixmap sprPixmap; -#if 0 -Pixmap objmaskBitmap; -Pixmap sprmaskBitmap; - -GC spriteGC; -#endif - char play[SAMPLE_MAX]; int play_x[SAMPLE_MAX]; int play_y[SAMPLE_MAX]; int play_element[SAMPLE_MAX]; -static boolean use_native_em_sound = 0; - struct GlobalInfo_EM global_em_info; struct GameInfo_EM game_em; -#if defined(AUDIO_UNIX_NATIVE) -static int sound_pid = -1; -int sound_pipe[2] = { -1, -1 }; /* for communication */ -short *sound_data[SAMPLE_MAX]; /* pointer to sound data */ -int sound_length[SAMPLE_MAX]; /* length of sound data */ - -static const char *sound_names[SAMPLE_MAX] = -{ - "00.blank.au", - "01.roll.au", - "02.stone.au", - "03.nut.au", - "04.crack.au", - "05.bug.au", - "06.tank.au", - "07.android.au", - "06.tank.au", /* android moving */ - "08.spring.au", - "09.slurp.au", - "10.eater.au", - "10.eater.au", /* eater eating */ - "11.alien.au", - "12.collect.au", - "13.diamond.au", - "14.squash.au", - "14.squash.au", - "15.drip.au", - "16.push.au", - "17.dirt.au", - "18.acid.au", - "19.ball.au", - "20.grow.au", - "21.wonder.au", - "22.door.au", - "23.exit.au", - "23.exit.au", - "24.dynamite.au", - "25.tick.au", - "26.press.au", - "27.wheel.au", - "28.boom.au", - "29.time.au", - "30.die.au" -}; -static const int sound_volume[SAMPLE_MAX] = -{ - 20, - 100, - 100, - 100, - 100, - 20, - 20, - 100, - 20, - 100, - 100, - 50, - 50, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 20, - 100, - 100, - 100, - 100, - 100, - 100, - 20, - 100, - 100, - 100 -}; -#endif - char *progname; char *arg_basedir; extern void tab_generate(); extern void tab_generate_graphics_info_em(); -extern void ulaw_generate(); int open_all(void) { Bitmap *emc_bitmaps[2]; -#if 0 - XGCValues gcValues; -#endif -#if 1 SetBitmaps_EM(emc_bitmaps); objBitmap = emc_bitmaps[0]; sprBitmap = emc_bitmaps[1]; -#if 0 - objPixmap = emc_bitmaps[0]->drawable; - sprPixmap = emc_bitmaps[1]->drawable; - - objmaskBitmap = emc_bitmaps[0]->clip_mask; - sprmaskBitmap = emc_bitmaps[1]->clip_mask; -#endif - -#if 0 - printf("::: CreateBitmap: %d, %d => %d\n", - MAX_BUF_XSIZE, TILEX, MAX_BUF_XSIZE * TILEX); - - screenBitmap = CreateBitmap(MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY, - DEFAULT_DEPTH); - - global_em_info.screenbuffer = screenBitmap; -#endif - -#endif - -#if 0 - spriteBitmap = XCreatePixmap(display, window->drawable, TILEX, TILEY, 1); - if (spriteBitmap == 0) - Error(ERR_EXIT, "failed to create sprite pixmap for EM engine"); - - gcValues.function = - objmaskBitmap ? GXcopyInverted : sprmaskBitmap ? GXcopy : GXset; - gcValues.graphics_exposures = False; - spriteGC = XCreateGC(display, spriteBitmap, GCFunction | GCGraphicsExposures, - &gcValues); - if (spriteGC == 0) - Error(ERR_EXIT, "failed to create sprite GC for EM engine"); -#endif - - /* ----------------------------------------------------------------- */ - -#if defined(AUDIO_UNIX_NATIVE) - -#if defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) - - if (use_native_em_sound) - { - char name[MAXNAME+2]; - int i; - - for (i = 0; i < SAMPLE_MAX; i++) - { - name[MAXNAME] = 0; - - if (arg_basedir) - { - snprintf(name, MAXNAME+2, "%s/%s/%s", arg_basedir, EM_SND_DIR, - sound_names[i]); - } - else - { - snprintf(name, MAXNAME+2, "%s/%s", EM_SND_DIR, sound_names[i]); - } - - if (name[MAXNAME]) - Error(ERR_EXIT, "buffer overflow when reading sounds directory"); - - if (read_sample(name, &sound_data[i], &sound_length[i])) - return(1); - - { - short *ptr, *stop; - int mult = sound_volume[i] * 65536 / (100 * MIXER_MAX); - stop = sound_data[i] + sound_length[i]; - for (ptr = sound_data[i]; ptr < stop; ptr++) - *ptr = (*ptr * mult) / 65536; - } - } - - if (pipe(sound_pipe) == -1) - { - Error(ERR_WARN, "unable to create sound pipe for EM engine -- no sound"); - - return(1); - } - - sound_pid = fork(); - if (sound_pid == -1) - { - Error(ERR_WARN, "unable to fork sound thread for EM engine -- no sound"); - - return(1); - } - - close(sound_pipe[sound_pid == 0]); - sound_pipe[sound_pid == 0] = -1; - if (sound_pid == 0) - _exit(sound_thread()); - - signal(SIGPIPE, SIG_IGN); /* dont crash if sound process dies */ - } - -#endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) */ - -#endif /* AUDIO_UNIX_NATIVE */ - - return(0); + return 0; } void InitGfxBuffers_EM() { - -#if 1 - -#if 0 - printf("::: InitGfxBuffers_EM: %d, %d => %d\n", - MAX_BUF_XSIZE, TILEX, MAX_BUF_XSIZE * TILEX); -#endif - ReCreateBitmap(&screenBitmap, MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY, DEFAULT_DEPTH); global_em_info.screenbuffer = screenBitmap; - -#else - - printf("::: CreateBitmap: %d, %d => %d\n", - MAX_BUF_XSIZE, TILEX, MAX_BUF_XSIZE * TILEX); - - screenBitmap = CreateBitmap(MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY, - DEFAULT_DEPTH); - - global_em_info.screenbuffer = screenBitmap; -#endif } void em_open_all() { /* pre-calculate some data */ tab_generate(); -#if defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) - ulaw_generate(); -#endif progname = "emerald mine"; @@ -293,32 +68,6 @@ void em_open_all() void em_close_all(void) { -#if defined(AUDIO_UNIX_NATIVE) - int i; - - if (sound_pid != -1) - { - kill(sound_pid, SIGTERM); - waitpid(sound_pid, 0, 0); - } - - if (sound_pipe[0] != -1) - close(sound_pipe[0]); - if (sound_pipe[1] != -1) - close(sound_pipe[1]); - - for (i = 0; i < SAMPLE_MAX; i++) - if (sound_data[i]) - free(sound_data[i]); -#endif - -#if 0 - if (spriteGC) - XFreeGC(display, spriteGC); - - if (spriteBitmap) - XFreePixmap(display, spriteBitmap); -#endif } /* ---------------------------------------------------------------------- */ @@ -328,24 +77,7 @@ extern int screen_y; void play_element_sound(int x, int y, int sample, int element) { -#if 0 - int left = screen_x / TILEX; - int top = screen_y / TILEY; - - if ((x == -1 && y == -1) || /* play sound in the middle of the screen */ - ((int)(y - top) <= SCR_FIELDY && - (int)(x - left) <= SCR_FIELDX)) -#endif - { -#if 1 - PlayLevelSound_EM(x, y, element, sample); -#else - play[sample] = 1; - play_x[sample] = x; - play_y[sample] = y; - play_element[sample] = element; -#endif - } + PlayLevelSound_EM(x, y, element, sample); } void play_sound(int x, int y, int sample) @@ -355,45 +87,6 @@ void play_sound(int x, int y, int sample) void sound_play(void) { - if (!use_native_em_sound) - { - int i; - -#if 0 - UpdateEngineValues(screen_x / TILEX, screen_y / TILEY); -#endif - - return; - - for (i = 0; i < SAMPLE_MAX; i++) - if (play[i]) - PlayLevelSound_EM(play_x[i], play_y[i], play_element[i], i); - } - -#if defined(AUDIO_UNIX_NATIVE) - if (use_native_em_sound && sound_pipe[1] != -1) - { - if (write(sound_pipe[1], &play, sizeof(play)) == -1) - { - Error(ERR_WARN, "cannot write into pipe to child process -- no sounds"); - - if (sound_pipe[0] != -1) - { - close(sound_pipe[0]); - sound_pipe[0] = -1; - } - - if (sound_pipe[1] != -1) - { - close(sound_pipe[1]); - sound_pipe[1] = -1; - } - } - } - -#endif - - clear_mem(play, sizeof(play)); } unsigned int InitEngineRandom_EM(int seed) diff --git a/src/game_em/input.c b/src/game_em/input.c index 76932c54..30870643 100644 --- a/src/game_em/input.c +++ b/src/game_em/input.c @@ -64,11 +64,6 @@ void InitGameEngine_EM() game_initscreen(); game_animscreen(); - -#if 0 - /* blit playfield from scroll buffer to normal back buffer for fading in */ - BlitScreenToBitmap_EM(backbuffer); -#endif } void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode) @@ -76,34 +71,6 @@ void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode) int i; boolean player_is_dropping = FALSE; -#if 0 - static int foo = -1; - - if (action[0] == 0 && foo != 0) - printf("KEY RELEASED @ %05d\n", FrameCounter); - - foo = action[0]; -#endif - -#if 0 -#if 1 - if (FrameCounter % 10 == 0) -#endif - printf("::: %05d: %lu, %d\n", FrameCounter, RandomEM, frame); -#endif - -#if 0 - game_animscreen(); - -#if 1 -#if 0 - SyncDisplay(); -#endif - - blitscreen(); -#endif -#endif - RandomEM = RandomEM * 129 + 1; frame = (frame - 1) & 7; @@ -138,17 +105,9 @@ void GameActions_EM(byte action[MAX_PLAYERS], boolean warp_mode) CheckSingleStepMode_EM(action, frame, game_em.any_player_moving, player_is_dropping); -#if 1 game_animscreen(); -#if 1 -#if 0 - SyncDisplay(); -#endif - blitscreen(); -#endif -#endif } /* read input device for players */ diff --git a/src/game_em/main_em.h b/src/game_em/main_em.h index 91b01844..46ade655 100644 --- a/src/game_em/main_em.h +++ b/src/game_em/main_em.h @@ -45,64 +45,22 @@ /* screen sizes and positions for EM engine */ -#define NEW_TILESIZE 1 - -#define ORIG_TILESIZE 16 - -#define ORIG_TILEX 16 -#define ORIG_TILEY 16 -#define ORIG_SCOREX 8 -#define ORIG_SCOREY 9 -#define ORIG_GFXMENUFONTX 14 -#define ORIG_GFXMENUFONTY 16 -#define ORIG_MENUFONTX 12 -#define ORIG_MENUFONTY 16 - -#if NEW_TILESIZE -#define ZOOM_FACTOR (2 * TILESIZE_VAR / TILESIZE) -#else -#define ZOOM_FACTOR 2 -#endif - #define TILESIZE 32 -#if NEW_TILESIZE extern int TILESIZE_VAR; + #define TILEX TILESIZE_VAR #define TILEY TILESIZE_VAR -#else -#define TILEX (ORIG_TILEX * ZOOM_FACTOR) -#define TILEY (ORIG_TILEY * ZOOM_FACTOR) -#endif -#define SCOREX (ORIG_SCOREX * ZOOM_FACTOR) -#define SCOREY (ORIG_SCOREY * ZOOM_FACTOR) -#define GFXMENUFONTX (ORIG_GFXMENUFONTX * ZOOM_FACTOR) -#define GFXMENUFONTY (ORIG_GFXMENUFONTY * ZOOM_FACTOR) -#define MENUFONTX (ORIG_MENUFONTX * ZOOM_FACTOR) -#define MENUFONTY (ORIG_MENUFONTY * ZOOM_FACTOR) - -#define ORIG_SCR_MENUX 20 -#define ORIG_SCR_MENUY 12 -#define SCR_MENUX 17 -#define SCR_MENUY 12 -#if 1 + extern int SCR_FIELDX, SCR_FIELDY; -#else -#define SCR_FIELDX 17 -#define SCR_FIELDY 17 -#endif + #define MAX_BUF_XSIZE (SCR_FIELDX + 2) #define MAX_BUF_YSIZE (SCR_FIELDY + 2) /* often used screen positions */ -#define ORIG_MENU_SX ((ORIG_SCR_MENUX - SCR_MENUX) * TILEX / 2) -#define ORIG_MENU_SY 0 -#if 1 + extern int SX, SY; -#else -#define SX 8 -#define SY 8 -#endif + #define SXSIZE (SCR_FIELDX * TILEX) #define SYSIZE (SCR_FIELDY * TILEY) diff --git a/src/game_em/sample.h b/src/game_em/sample.h index efbd7745..41bc8722 100644 --- a/src/game_em/sample.h +++ b/src/game_em/sample.h @@ -14,14 +14,4 @@ extern int sound_length[SAMPLE_MAX]; #define MIXER_MAX 4 /* maximum number of samples we can play at once */ -#if defined(AUDIO_UNIX_NATIVE) - -enum -{ - AUDIO_ULAW = 0, - AUDIO_U8 -}; - -#endif /* AUDIO_UNIX_NATIVE */ - #endif /* SAMPLE_H */ diff --git a/src/game_em/sound.c b/src/game_em/sound.c index f03abf1e..174d6238 100644 --- a/src/game_em/sound.c +++ b/src/game_em/sound.c @@ -4,514 +4,3 @@ */ #include "main_em.h" - - -#if defined(AUDIO_UNIX_NATIVE) - -#if defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) - -#ifdef PLATFORM_LINUX -#include -#include -#endif - -#ifdef PLATFORM_BSD -#include -#include -#endif - -static char audioname[] = "/dev/audio"; - -static const int sound_priority[SAMPLE_MAX] = -{ - SAMPLE_exit_open, - SAMPLE_exit_leave, - SAMPLE_die, - SAMPLE_time, - SAMPLE_boom, - SAMPLE_tick, - SAMPLE_collect, - SAMPLE_roll, - SAMPLE_push, - SAMPLE_dynamite, - SAMPLE_press, - SAMPLE_door, - SAMPLE_dirt, - SAMPLE_blank, - SAMPLE_android_clone, - SAMPLE_android_move, - SAMPLE_ball, - SAMPLE_grow, - SAMPLE_squash, - SAMPLE_wonderfall, - SAMPLE_crack, - SAMPLE_slurp, - SAMPLE_drip, - SAMPLE_wonder, - SAMPLE_wheel, - SAMPLE_stone, - SAMPLE_spring, - SAMPLE_diamond, - SAMPLE_nut, - SAMPLE_bug, - SAMPLE_tank, - SAMPLE_eater, - SAMPLE_eater_eat, - SAMPLE_alien, - SAMPLE_acid -}; - -int sound_thread(void) -{ - int audio_fd; /* file descriptor of /dev/audio or -1 if not open */ - int audio_format; - // int sample_rate; - int fragment_size; - unsigned char *audio_buffer; /* actual buffer pumped to /dev/audio */ - short *mix_buffer; - - char sound_play[SAMPLE_MAX]; /* if set, we should be playing these sounds */ - int sound_pos[SAMPLE_MAX]; /* position in the sound */ - int mix_play[MIXER_MAX]; /* which sounds we have chosen to mix (calculated each time) */ - int mix_count; - int i; - - loop: - - audio_fd = -1; - audio_format = AUDIO_ULAW; /* defaults for non-OSS /dev/audio */ - // sample_rate = 8000; - fragment_size = 256; - audio_buffer = 0; - mix_buffer = 0; - mix_count = 0; - - clear_mem(sound_play, sizeof(sound_play)); /* not playing any sounds */ - - for (;;) - { - for (;;) - { - - /* pick sounds to play, if any */ - if (sound_play[SAMPLE_exit_open] || - sound_play[SAMPLE_exit_leave] || - sound_play[SAMPLE_die]) - sound_play[SAMPLE_boom] = 0; /* no explosions if player goes home */ - - mix_count = 0; - for (i = 0; i < SAMPLE_MAX; i++) - { - if (sound_play[sound_priority[i]]) - { - mix_play[mix_count++] = sound_priority[i]; - - if (mix_count == MIXER_MAX) - break; /* cant mix too many sounds at once */ - } - } - - /* check for incoming messages */ - if (mix_count || audio_fd != -1) - { - /* dont block if we are playing sounds */ - fd_set rfds; - struct timeval tv; - FD_ZERO(&rfds); - FD_SET(sound_pipe[0], &rfds); - tv.tv_sec = 0; - tv.tv_usec = 0; /* (900000 * fragment_size / sample_rate) */ - i = select(sound_pipe[0] + 1, &rfds, 0, 0, &tv); /* dont block */ - - if (i == -1) - { - Error(ERR_WARN, "select() failed in sound thread"); - - goto fail; - } - - if (i == 0) - break; /* no messages */ - } - - /* get a message and start a sound */ - i = read(sound_pipe[0], &play, sizeof(play)); - - if (i == -1) - { - Error(ERR_WARN, "read() failed in sound thread"); - - goto fail; - } - - if (i == 0) - { - Error(ERR_WARN, "reading sound failed in sound thread"); - - goto fail; - } - - if (i != sizeof(play)) - { - Error(ERR_WARN, "bad message length in sound thread"); - - goto fail; - } - - for (i = 0; i < SAMPLE_MAX; i++) - { - if (play[i]) - { - sound_play[i] = 1; /* play this sound */ - sound_pos[i] = 0; /* start it from the start */ - } - } - } - - /* open the audio device if there are sounds to play */ - if (mix_count && audio_fd == -1) - { - audio_fd = open(audioname, O_WRONLY); - - if (audio_fd == -1) - goto reset; - -#ifdef OPEN_SOUND_SYSTEM - i = 0x00020008; - - if (ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &i) == -1) - { - Error(ERR_WARN, "unable to set fragment size in sound thread"); - - goto reset; - } - - if (ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &i) == -1) - { - Error(ERR_WARN, "unable to query audio format in sound thread"); - - goto reset; - } - - /* prefer 8 bit unsigned and fall back on mu-law */ - audio_format = (i & AFMT_U8) ? AFMT_U8 : AFMT_MU_LAW; - - i = audio_format; - if (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &i) == -1) - { - Error(ERR_WARN, "unable to set audio format in sound thread"); - - goto reset; - } - - if (i == AFMT_MU_LAW) - { - audio_format = AUDIO_ULAW; - } - else if (i == AFMT_U8) - { - audio_format = AUDIO_U8; - } - else - { - Error(ERR_WARN, "audio format required by device not supported"); - - goto reset; - } - - i = 1; - if (ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &i) == -1) - { - Error(ERR_WARN, "unable to set channels to mono in sound thread"); - - goto reset; - } - - if (i != 1) - { - Error(ERR_WARN, "channels required by device not supported"); - - goto reset; - } - - i = 8000; - if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &i) == -1) - { - Error(ERR_WARN, "unable to set sampling rate in sound thread"); - - goto reset; - } - - // sample_rate = i; - if (ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &i) == -1) - { - Error(ERR_WARN, "unable to get block size in sound thread"); - - goto reset; - } - - fragment_size = i; - -#else - if (fcntl(audio_fd, F_SETFL, O_NONBLOCK) == -1) - { - Error(ERR_WARN, "unable to make audio non blocking in sound thread"); - - goto reset; - } - -#endif /* OPEN_SOUND_SYSTEM */ - - audio_buffer = malloc(fragment_size * sizeof(*audio_buffer)); - if (audio_buffer == 0) - { - Error(ERR_WARN, "unable to malloc audio buffer in sound thread"); - - goto fail; - } - - mix_buffer = malloc(fragment_size * sizeof(*mix_buffer)); - if (mix_buffer == 0) - { - Error(ERR_WARN, "unable to malloc mixing buffer in sound thread"); - - goto fail; - } - } - - /* close the audio device if no sounds are playing */ - if (mix_count == 0 && audio_fd != -1) - { - close(audio_fd); - free(audio_buffer); - free(mix_buffer); - audio_fd = -1; - audio_buffer = 0; - mix_buffer = 0; - } - - /* if we are playing sounds and the audio device is open, mix them */ - if (mix_count && audio_fd != -1) - { - /* prepare mix buffer */ - clear_mem(mix_buffer, fragment_size * sizeof(*mix_buffer)); - - for (i = 0; i < mix_count; i++) - { - register short *mix_ptr = mix_buffer; - register short *sound_ptr = - sound_data[mix_play[i]] + sound_pos[mix_play[i]]; - register int count = - sound_length[mix_play[i]] - sound_pos[mix_play[i]]; - - if (count > fragment_size) - count = fragment_size; - - while (count--) - *mix_ptr++ += *sound_ptr++; /* mix the sounds in */ - } - - switch(audio_format) - { - case AUDIO_ULAW: - for (i = 0; i < fragment_size; i++) - audio_buffer[i] = linear_to_ulaw[mix_buffer[i] + 32768]; - break; - - case AUDIO_U8: - for (i = 0; i < fragment_size; i++) - audio_buffer[i] = (mix_buffer[i] + 32768) >> 8; - break; - } - - /* advance sound pointers */ - for (i = 0; i < SAMPLE_MAX; i++) - { - if (sound_play[i]) - { - if (sound_pos[i] + fragment_size < sound_length[i]) - { - sound_pos[i] += fragment_size; - } - else - { - sound_play[i] = 0; - } - } - } - - /* send the data to the audio device */ - i = write(audio_fd, audio_buffer, fragment_size); - if (i == -1) - { - Error(ERR_WARN, "cannot write to audio device in sound thread"); - - goto reset; - } - - if (i != fragment_size) - { - Error(ERR_WARN, "bad write length to audio device in sound thread"); - - goto reset; - } - } - } /* for */ - - reset: - - if (audio_fd != -1) - close(audio_fd); - if (audio_buffer) - free(audio_buffer); - if (mix_buffer) - free(mix_buffer); - - goto loop; /* back to top */ - - fail: - if (audio_fd != -1) - close(audio_fd); - if (audio_buffer) - free(audio_buffer); - if (mix_buffer) - free(mix_buffer); - - return(0); -} - -int read_sample(char *name, short **data, int *length) -{ - int result; - FILE *file = 0; - short *dataptr = 0; - int datalength; - - int i, actual, ch; - unsigned char buffer[24]; - unsigned int temp; - - file = fopen(name, "rb"); - if (file == 0) - { - Error(ERR_WARN, "cannot open file '%s' in sound thread", name); - - result = 1; - goto fail; - } - - actual = fread(buffer, 1, 24, file); - if (actual == -1) - { - Error(ERR_WARN, "cannot read file '%s' in sound thread", name); - - result = 1; - goto fail; - } - - if (actual < 24) - { - Error(ERR_WARN, "premature eof of file '%s' in sound thread", name); - - result = 1; - goto fail; - } - - /* magic */ - temp = buffer[0] << 24 | buffer[1] << 16 | buffer[2] << 8 | buffer[3]; - if (temp != 0x2e736e64) - { - Error(ERR_WARN, "unrecognized format of file '%s' in sound thread", name); - - result = 1; - goto fail; - } - - /* header length */ - temp = buffer[4] << 24 | buffer[5] << 16 | buffer[6] << 8 | buffer[7]; - if (temp < 24) - { - Error(ERR_WARN, "bad header length of file '%s' in sound thread", name); - - result = 1; - goto fail; - } - - actual = temp; - for (i = 24; i < actual; i++) - { - /* skip the rest of the header */ - ch = fgetc(file); - if (ch == EOF) - break; - } - - /* data length */ - temp = buffer[8] << 24 | buffer[9] << 16 | buffer[10] << 8 | buffer[11]; - datalength = temp; - - /* encoding */ - temp = buffer[12] << 24 | buffer[13] << 16 | buffer[14] << 8 | buffer[15]; - if (temp != 1) - { - fprintf(stderr, "%s: \"%s\": %s (%d != 1)\n", progname, name, - "bad encoding type", temp); - result = 1; - goto fail; - } - - /* sample rate */ - temp = buffer[16] << 24 | buffer[17] << 16 | buffer[18] << 8 | buffer[19]; - if (temp != 8000) - { - fprintf(stderr, "%s: \"%s\": %s (%d != 8000)\n", progname, name, - "bad sample rate", temp); - result = 1; - goto fail; - } - - /* channels */ - temp = buffer[20] << 24 | buffer[21] << 16 | buffer[22] << 8 | buffer[23]; - if (temp != 1) - { - fprintf(stderr, "%s: \"%s\": %s (%d != 1)\n", progname, name, - "unsupported channels", temp); - result = 1; - goto fail; - } - - dataptr = malloc(datalength * sizeof(*dataptr)); - if (dataptr == 0) - { - Error(ERR_WARN, "unable to malloc buffer for file '%s' in sound thread", - name); - - result = 1; - goto fail; - } - - for (i = 0; i < datalength; i++) - { - ch = fgetc(file); - if (ch == EOF) break; - dataptr[i] = ulaw_to_linear[ch]; - } - - fclose(file); - file = 0; - - *data = dataptr; - *length = datalength; - result = 0; - - fail: - - if (file) - fclose(file); - - return(result); -} - -#endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) */ - -#endif /* AUDIO_UNIX_NATIVE */ diff --git a/src/game_em/synchro_1.c b/src/game_em/synchro_1.c index ef4d0f2c..f09fc848 100644 --- a/src/game_em/synchro_1.c +++ b/src/game_em/synchro_1.c @@ -8,10 +8,6 @@ #include "main_em.h" -#if 0 -extern int centered_player_nr; -#endif - #define USE_CHANGED_ACID_STUFF 1 extern boolean checkIfAllPlayersFitToScreen(); @@ -23,15 +19,12 @@ static boolean player_killed(struct PLAYER *); void synchro_1(void) { -#if 1 - int start_check_nr; int i; game_em.any_player_moving = FALSE; /* must test for death and actually kill separately */ - for (i = 0; i < MAX_PLAYERS; i++) { boolean ply_kill = player_killed(&ply[i]); @@ -40,25 +33,6 @@ void synchro_1(void) kill_player(&ply[i]); } -#else - - /* must test for death and actually kill separately */ - boolean ply1_kill = player_killed(&ply1); - boolean ply2_kill = player_killed(&ply2); - - if (ply1.alive && ply1_kill) - kill_player(&ply1); - if (ply2.alive && ply2_kill) - kill_player(&ply2); - -#endif - -#if 0 - ply1.alive = 1; /* debugging */ -#endif - -#if 1 - for (i = 0; i < MAX_PLAYERS; i++) { ply[i].oldx = ply[i].x; @@ -93,58 +67,6 @@ void synchro_1(void) Next[ply[i].y][ply[i].x] = Zplayer; } } - -#else - - ply1.oldx = ply1.x; - ply1.oldy = ply1.y; - ply1.anim = SPR_still; - ply2.oldx = ply2.x; - ply2.oldy = ply2.y; - ply2.anim = SPR_still; - - if (RandomEM & 256) - { - if (ply1.alive) check_player(&ply1); - if (ply2.alive) check_player(&ply2); - } - else - { - if (ply2.alive) check_player(&ply2); - if (ply1.alive) check_player(&ply1); - } - - if (ply1.alive) - { - if (Cave[ply1.oldy][ply1.oldx] == Zplayer) - { - Cave[ply1.oldy][ply1.oldx] = Xblank; - Next[ply1.oldy][ply1.oldx] = Xblank; - } - - if (Cave[ply1.y][ply1.x] == Xblank) - { - Cave[ply1.y][ply1.x] = Zplayer; - Next[ply1.y][ply1.x] = Zplayer; - } - } - - if (ply2.alive) - { - if (Cave[ply2.oldy][ply2.oldx] == Zplayer) - { - Cave[ply2.oldy][ply2.oldx] = Xblank; - Next[ply2.oldy][ply2.oldx] = Xblank; - } - - if (Cave[ply2.y][ply2.x] == Xblank) - { - Cave[ply2.y][ply2.x] = Zplayer; - Next[ply2.y][ply2.x] = Zplayer; - } - } - -#endif } static boolean player_killed(struct PLAYER *ply) @@ -152,20 +74,11 @@ static boolean player_killed(struct PLAYER *ply) int x = ply->x; int y = ply->y; -#if 0 - printf("::: %d: %d, %d\n", ply->num, x, y); -#endif - if (!ply->alive) return FALSE; -#if 1 if (lev.killed_out_of_time && setup.time_limit) return TRUE; -#else - if (lev.time_initial > 0 && lev.time == 0 && setup.time_limit) - return TRUE; -#endif switch(Cave[y-1][x]) { @@ -295,11 +208,6 @@ static void kill_player(struct PLAYER *ply) case Xbug_gos: case Xbug_gow: Cave[y-1][x] = Xboom_bug; -#if 0 -#if PLAY_ELEMENT_SOUND - play_element_sound(x, y, SAMPLE_boom, Zplayer); -#endif -#endif break; case Xtank_n: @@ -311,11 +219,6 @@ static void kill_player(struct PLAYER *ply) case Xtank_gos: case Xtank_gow: Cave[y-1][x] = Xboom_bomb; -#if 0 -#if PLAY_ELEMENT_SOUND - play_element_sound(x, y, SAMPLE_boom, Zplayer); -#endif -#endif break; } @@ -330,11 +233,6 @@ static void kill_player(struct PLAYER *ply) case Xbug_gos: case Xbug_gow: Cave[y][x+1] = Xboom_bug; -#if 0 -#if PLAY_ELEMENT_SOUND - play_element_sound(x, y, SAMPLE_boom, Zplayer); -#endif -#endif break; case Xtank_n: @@ -346,11 +244,6 @@ static void kill_player(struct PLAYER *ply) case Xtank_gos: case Xtank_gow: Cave[y][x+1] = Xboom_bomb; -#if 0 -#if PLAY_ELEMENT_SOUND - play_element_sound(x, y, SAMPLE_boom, Zplayer); -#endif -#endif break; } @@ -365,11 +258,6 @@ static void kill_player(struct PLAYER *ply) case Xbug_gos: case Xbug_gow: Cave[y+1][x] = Xboom_bug; -#if 0 -#if PLAY_ELEMENT_SOUND - play_element_sound(x, y, SAMPLE_boom, Zplayer); -#endif -#endif break; case Xtank_n: @@ -381,11 +269,6 @@ static void kill_player(struct PLAYER *ply) case Xtank_gos: case Xtank_gow: Cave[y+1][x] = Xboom_bomb; -#if 0 -#if PLAY_ELEMENT_SOUND - play_element_sound(x, y, SAMPLE_boom, Zplayer); -#endif -#endif break; } @@ -400,11 +283,6 @@ static void kill_player(struct PLAYER *ply) case Xbug_gos: case Xbug_gow: Cave[y][x-1] = Xboom_bug; -#if 0 -#if PLAY_ELEMENT_SOUND - play_element_sound(x, y, SAMPLE_boom, Zplayer); -#endif -#endif break; case Xtank_n: @@ -416,11 +294,6 @@ static void kill_player(struct PLAYER *ply) case Xtank_gos: case Xtank_gow: Cave[y][x-1] = Xboom_bomb; -#if 0 -#if PLAY_ELEMENT_SOUND - play_element_sound(x, y, SAMPLE_boom, Zplayer); -#endif -#endif break; } @@ -435,9 +308,6 @@ static void kill_player(struct PLAYER *ply) break; default: -#if PLAY_ELEMENT_SOUND - play_element_sound(x, y, SAMPLE_boom, Zplayer); -#endif play_element_sound(x, y, SAMPLE_die, Zplayer); break; } @@ -473,13 +343,6 @@ static void check_player(struct PLAYER *ply) game_em.last_player_direction[ply->num] = MV_NONE; -#if 0 - printf("::: up == %d, down == %d, left == %d, right == %d, fire == %d [spin == %d, stick == %d]\n", - ply->joy_n, ply->joy_s, ply->joy_w, ply->joy_e, ply->joy_fire, - ply->joy_spin, ply->joy_stick); -#endif - -#if 1 if (ply->joy_w) /* west */ { x--; @@ -502,56 +365,6 @@ static void check_player(struct PLAYER *ply) dy = 1; } -#else - - if ((ply->joy_spin = !ply->joy_spin)) - { - if (ply->joy_n) /* north */ - { - y--; - dy = -1; - } - else if (ply->joy_e) /* east */ - { - x++; - dx = 1; - } - else if (ply->joy_s) /* south */ - { - y++; - dy = 1; - } - else if (ply->joy_w) /* west */ - { - x--; - dx = -1; - } - } - else - { - if (ply->joy_w) /* west */ - { - x--; - dx = -1; - } - else if (ply->joy_s) /* south */ - { - y++; - dy = 1; - } - else if (ply->joy_e) /* east */ - { - x++; - dx = 1; - } - else if (ply->joy_n) /* north */ - { - y--; - dy = -1; - } - } -#endif - if (dx || dy) { int oldx = ply->x; @@ -1253,19 +1066,8 @@ static boolean player_digfield(struct PLAYER *ply, int dx, int dy) case Xexit_1: case Xexit_2: case Xexit_3: -#if 0 - /* !!! already played in kill_player !!! */ - play_element_sound(x, y, SAMPLE_exit_leave, Xexit_1); -#endif - lev.home--; -#if 0 - /* !!! CHECK SCORE CALCULATION !!! */ - if (lev.home == 0 && lev.time_initial > 0) /* game won */ - lev.score += lev.time * lev.exit_score / 100; -#endif - ply->anim = SPR_walk + anim; ply->x = x; ply->y = y; diff --git a/src/game_em/synchro_2.c b/src/game_em/synchro_2.c index c4b9a678..8fc7ada1 100644 --- a/src/game_em/synchro_2.c +++ b/src/game_em/synchro_2.c @@ -1902,46 +1902,8 @@ void synchro_2(void) Cave[y+1][x+1] == Zplayer) goto android_still; -#if 1 - set_nearest_player_xy(x, y, &dx, &dy); -#else - - if (ply1.alive && ply2.alive) - { - if ((ply1.x > x ? ply1.x - x : x - ply1.x) + - (ply1.y > y ? ply1.y - y : y - ply1.y) < - (ply2.x > x ? ply2.x - x : x - ply2.x) + - (ply2.y > y ? ply2.y - y : y - ply2.y)) - { - dx = ply1.x; - dy = ply1.y; - } - else - { - dx = ply2.x; - dy = ply2.y; - } - } - else if (ply1.alive) - { - dx = ply1.x; - dy = ply1.y; - } - else if (ply2.alive) - { - dx = ply2.x; - dy = ply2.y; - } - else - { - dx = 0; - dy = 0; - } - -#endif - Next[y][x] = Xblank; /* assume we will move */ temp = ((x < dx) + 1 - (x > dx)) + ((y < dy) + 1 - (y > dy)) * 3; @@ -3237,8 +3199,6 @@ void synchro_2(void) case Xalien: -#if 1 - if (lev.wheel_cnt) { dx = lev.wheel_x; @@ -3249,47 +3209,6 @@ void synchro_2(void) set_nearest_player_xy(x, y, &dx, &dy); } -#else - - if (lev.wheel_cnt) - { - dx = lev.wheel_x; - dy = lev.wheel_y; - } - else if (ply1.alive && ply2.alive) - { - if ((ply1.x > x ? ply1.x - x : x - ply1.x) + - (ply1.y > y ? ply1.y - y : y - ply1.y) < - (ply2.x > x ? ply2.x - x : x - ply2.x) + - (ply2.y > y ? ply2.y - y : y - ply2.y)) - { - dx = ply1.x; - dy = ply1.y; - } - else - { - dx = ply2.x; - dy = ply2.y; - } - } - else if (ply1.alive) - { - dx = ply1.x; - dy = ply1.y; - } - else if (ply2.alive) - { - dx = ply2.x; - dy = ply2.y; - } - else - { - dx = 0; - dy = 0; - } - -#endif - if (RANDOM & 1) { if (y > dy) @@ -4565,11 +4484,8 @@ void synchro_2(void) } } -#if 1 lev.ball_pos = (lev.ball_pos + 1) % lev.num_ball_arrays; -#else - lev.ball_pos = (lev.ball_pos + 1) & 7; -#endif + goto loop; /* --------------------------------------------------------------------- */ @@ -4716,7 +4632,6 @@ void synchro_2(void) case Xacid_6: case Xacid_7: case Xacid_8: -#if 1 Cave[y][x] = Xsand_stonesand_quickout_1; if (Cave[y][x+1] == Xblank) Cave[y][x+1] = Yacid_splash_eB; @@ -4725,33 +4640,15 @@ void synchro_2(void) Next[y][x] = Xsand_stonesand_quickout_2; play_element_sound(x, y, SAMPLE_acid, Xacid_1); goto loop; -#else - Cave[y][x] = Xsand_stonesand_3; - if (Cave[y][x+1] == Xblank) - Cave[y][x+1] = Yacid_splash_eB; - if (Cave[y][x-1] == Xblank) - Cave[y][x-1] = Yacid_splash_wB; - Next[y][x] = Xsand_stonesand_4; - play_element_sound(x, y, SAMPLE_acid, Xacid_1); - goto loop; -#endif case Xblank: case Yacid_splash_eB: case Yacid_splash_wB: -#if 1 Cave[y][x] = Xsand_stonesand_quickout_1; Cave[y+1][x] = Xsand_stoneout_1; Next[y][x] = Xsand_stonesand_quickout_2; Next[y+1][x] = Xsand_stoneout_2; goto loop; -#else - Cave[y][x] = Xsand_stonesand_3; - Cave[y+1][x] = Xsand_stoneout_1; - Next[y][x] = Xsand_stonesand_4; - Next[y+1][x] = Xsand_stoneout_2; - goto loop; -#endif case Xsand: Cave[y][x] = Xsand_stonesand_1; diff --git a/src/game_em/synchro_3.c b/src/game_em/synchro_3.c index bafc581f..307d285e 100644 --- a/src/game_em/synchro_3.c +++ b/src/game_em/synchro_3.c @@ -20,18 +20,6 @@ void synchro_3(void) if (lev.score > 9999) lev.score = 9999; -#if 0 -#if 1 - if (lev.time_initial == 0) - lev.time++; - else if (lev.time > 0) - lev.time--; -#else - if (lev.time) - lev.time--; -#endif -#endif - if (lev.android_move_cnt-- == 0) lev.android_move_cnt = lev.android_move_time; if (lev.android_clone_cnt-- == 0) @@ -50,12 +38,6 @@ void synchro_3(void) if (lev.wonderwall_time && lev.wonderwall_state) lev.wonderwall_time--; -#if 0 - if (lev.time_initial > 0 && - lev.time > 0 && lev.time <= 50 && lev.time % 5 == 0 && setup.time_limit) - play_sound(-1, -1, SAMPLE_time); -#endif - if (lev.wheel_cnt) play_element_sound(lev.wheel_x, lev.wheel_y, SAMPLE_wheel, Xwheel); diff --git a/src/game_em/tab_generate.c b/src/game_em/tab_generate.c index 8a3f731a..936f63b3 100644 --- a/src/game_em/tab_generate.c +++ b/src/game_em/tab_generate.c @@ -4482,79 +4482,6 @@ void create_obj() int *map = obj_map; int buffer[8][TILE_MAX]; -#if 0 - - int debug = 0; - - for (i = 0; i < 8; i++) - for (j = 0; j < TILE_MAX; j++) - buffer[i][j] = 0; - - for (i = 0; i < 64; i++) - { - for (;*map != -1; map += 2) - { - if (map[0] < 0 || map[0] >= TILE_MAX || map[1] < 0 || map[1] >= 8) - { - fprintf(stderr, "obj_map: bad tile (%d, %d) @ %d+%d\n", - map[0], map[1], i / 16, i % 16); - debug = 1; - continue; - } - buffer[map[1]][map[0]]++; - } - map++; - } - - for (i = 0; i < 896; i++) - { - for (;*map != -1; map += 2) - { - if (map[0] < 0 || map[0] >= TILE_MAX || map[1] < 0 || map[1] >= 8) - { - fprintf(stderr, "obj_map: bad tile (%d, %d) @ %d\n", map[0], map[1], i); - debug = 1; - continue; - } - buffer[map[1]][map[0]]++; - } - map++; - } - - for (i = 0; i < TILE_MAX; i++) - { - for (j = 0; j < 8; j++) - { - switch(buffer[j][i]) - { - case 0: - fprintf(stderr, "obj_map: uninitialized (%d, %d)\n", i, j); - debug = 1; - break; - case 1: - break; /* good */ - default: - fprintf(stderr, "obj_map: duplicate (%d, %d)\n", i, j); - debug = 1; - break; - } - } - } - - if (sizeof(obj_map) / sizeof(*obj_map) != map - obj_map) - { - fprintf(stderr, "obj_map: bad end (%d != %d)\n", - sizeof(obj_map) / sizeof(*obj_map), map - obj_map); - debug = 1; - } - - if (debug == 0) - fprintf(stderr, "obj_map: looks good, now disable debug code\n"); - - abort(); - -#else - for (i = 0; i < 8; i++) for (j = 0; j < TILE_MAX; j++) buffer[i][j] = Xblank; @@ -4578,8 +4505,6 @@ void create_obj() for (i = 0; i < 8; i++) for (j = 0; j < TILE_MAX; j++) map_obj[i][j] = buffer[7 - i][j]; - -#endif } void create_obj_graphics_info_em() diff --git a/src/game_em/ulaw_generate.c b/src/game_em/ulaw_generate.c index 7c06c300..64488f6a 100644 --- a/src/game_em/ulaw_generate.c +++ b/src/game_em/ulaw_generate.c @@ -5,132 +5,3 @@ */ #include "main_em.h" - - -#if defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) - -int calc_ulaw_to_linear(unsigned char); -unsigned char calc_linear_to_ulaw(int); - -int buffer[65536]; - -/* convert from 8 bit ulaw to signed 16 bit linear */ -short ulaw_to_linear[256]; - -/* convert from signed 16 bit linear to 8 bit ulaw */ -unsigned char linear_to_ulaw[65536]; - -void ulaw_generate() -{ - int i; - - for(i = 0; i < 256; i++) - ulaw_to_linear[i] = calc_ulaw_to_linear(i); - - for(i = -32768; i < 32768; i++) - linear_to_ulaw[i + 32768] = calc_linear_to_ulaw(i); -} - -/* -** This routine converts from ulaw to 16 bit linear. -** -** Craig Reese: IDA/Supercomputing Research Center -** 29 September 1989 -** -** References: -** 1) CCITT Recommendation G.711 (very difficult to follow) -** 2) MIL-STD-188-113,"Interoperability and Performance Standards -** for Analog-to_Digital Conversion Techniques," -** 17 February 1987 -** -** Input: 8 bit ulaw sample -** Output: signed 16 bit linear sample -*/ - -int calc_ulaw_to_linear(unsigned char ulawbyte) -{ - static int exp_lut[8] = { 0, 132, 396, 924, 1980, 4092, 8316, 16764 }; - int sign, exponent, mantissa, sample; - - ulawbyte = ~ ulawbyte; - sign = ( ulawbyte & 0x80 ); - exponent = ( ulawbyte >> 4 ) & 0x07; - mantissa = ulawbyte & 0x0F; - sample = exp_lut[exponent] + ( mantissa << ( exponent + 3 ) ); - if (sign != 0) - sample = -sample; - - return(sample); -} - -/* -** This routine converts from linear to ulaw. -** -** Craig Reese: IDA/Supercomputing Research Center -** Joe Campbell: Department of Defense -** 29 September 1989 -** -** References: -** 1) CCITT Recommendation G.711 (very difficult to follow) -** 2) "A New Digital Technique for Implementation of Any -** Continuous PCM Companding Law," Villeret, Michel, -** et al. 1973 IEEE Int. Conf. on Communications, Vol 1, -** 1973, pg. 11.12-11.17 -** 3) MIL-STD-188-113,"Interoperability and Performance Standards -** for Analog-to_Digital Conversion Techniques," -** 17 February 1987 -** -** Input: Signed 16 bit linear sample -** Output: 8 bit ulaw sample -*/ - -#define ZEROTRAP /* turn on the trap as per the MIL-STD */ -#define BIAS 0x84 /* define the add-in bias for 16 bit samples */ -#define CLIP 32635 - -unsigned char calc_linear_to_ulaw(int sample) -{ - static int exp_lut[256] = - { - 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3, - 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, - 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, - 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, - 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, - 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, - 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, - 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 - }; - - int sign, exponent, mantissa; - unsigned char ulawbyte; - -/* Get the sample into sign-magnitude. */ - sign = (sample >> 8) & 0x80; /* set aside the sign */ - if (sign != 0) - sample = -sample; /* get magnitude */ - if (sample > CLIP) - sample = CLIP; /* clip the magnitude */ - -/* Convert from 16 bit linear to ulaw. */ - sample = sample + BIAS; - exponent = exp_lut[( sample >> 7 ) & 0xFF]; - mantissa = ( sample >> ( exponent + 3 ) ) & 0x0F; - ulawbyte = ~ ( sign | ( exponent << 4 ) | mantissa ); -#ifdef ZEROTRAP - if (ulawbyte == 0) - ulawbyte = 0x02; /* optional CCITT trap */ -#endif - - return(ulawbyte); -} - -#endif /* defined(PLATFORM_LINUX) || defined(PLATFORM_BSD) */ diff --git a/src/game_sp/BugsTerminals.c b/src/game_sp/BugsTerminals.c index d0a82ad4..afa7345e 100644 --- a/src/game_sp/BugsTerminals.c +++ b/src/game_sp/BugsTerminals.c @@ -5,11 +5,7 @@ #include "BugsTerminals.h" -#if 1 byte TerminalState[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE]; -#else -byte *TerminalState; -#endif int TerminalMaxCycles; diff --git a/src/game_sp/BugsTerminals.h b/src/game_sp/BugsTerminals.h index 61458526..572395c1 100644 --- a/src/game_sp/BugsTerminals.h +++ b/src/game_sp/BugsTerminals.h @@ -7,11 +7,7 @@ #include "global.h" -#if 1 extern byte TerminalState[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE]; -#else -extern byte *TerminalState; -#endif extern int TerminalMaxCycles; diff --git a/src/game_sp/DDScrollBuffer.c b/src/game_sp/DDScrollBuffer.c index de24a921..698d33b8 100644 --- a/src/game_sp/DDScrollBuffer.c +++ b/src/game_sp/DDScrollBuffer.c @@ -10,13 +10,8 @@ int mScrollX, mScrollY; int mScrollX_last, mScrollY_last; -#if 1 int ScreenBuffer[2 + MAX_PLAYFIELD_WIDTH + 2][2 + MAX_PLAYFIELD_HEIGHT + 2]; boolean redraw[2 + MAX_PLAYFIELD_WIDTH + 2][2 + MAX_PLAYFIELD_HEIGHT + 2]; -#else -int ScreenBuffer[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; -boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; -#endif void RestorePlayfield() @@ -50,7 +45,6 @@ static void ScrollPlayfield(int dx, int dy) int y2 = mScrollY_last / TILEY + (SCR_FIELDY - 1) + 2; int x, y; -#if NEW_TILESIZE BlitBitmap(bitmap_db_field_sp, bitmap_db_field_sp, TILEX_VAR * (dx == -1), TILEY_VAR * (dy == -1), @@ -58,26 +52,11 @@ static void ScrollPlayfield(int dx, int dy) (MAX_BUF_YSIZE * TILEY_VAR) - TILEY_VAR * (dy != 0), TILEX_VAR * (dx == 1), TILEY_VAR * (dy == 1)); -#else - BlitBitmap(bitmap_db_field_sp, bitmap_db_field_sp, - TILEX * (dx == -1), - TILEY * (dy == -1), - (MAX_BUF_XSIZE * TILEX) - TILEX * (dx != 0), - (MAX_BUF_YSIZE * TILEY) - TILEY * (dy != 0), - TILEX * (dx == 1), - TILEY * (dy == 1)); -#endif /* when scrolling the whole playfield, do not redraw single tiles */ -#if 1 for (x = 0; x < 2 + MAX_PLAYFIELD_WIDTH + 2; x++) for (y = 0; y < 2 + MAX_PLAYFIELD_HEIGHT + 2; y++) redraw[x][y] = FALSE; -#else - for (x = 0; x < MAX_BUF_XSIZE; x++) - for (y = 0; y < MAX_BUF_YSIZE; y++) - redraw[x][y] = FALSE; -#endif redraw_tiles = 0; DrawFrameIfNeeded(); @@ -122,13 +101,8 @@ static void ScrollPlayfieldIfNeededExt(boolean reset) if (mScrollX_last == -1 || mScrollY_last == -1) { -#if 1 mScrollX_last = (mScrollX / TILESIZE) * TILESIZE; mScrollY_last = (mScrollY / TILESIZE) * TILESIZE; -#else - mScrollX_last = mScrollX; - mScrollY_last = mScrollY; -#endif return; } @@ -180,12 +154,6 @@ void UpdatePlayfield(boolean force_redraw) int sync_frame = GfxFrame[x][y]; boolean redraw = force_redraw; -#if DEBUG_REDRAW -#if 0 - redraw = TRUE; // !!! TEST ONLY -- ALWAYS REDRAW !!! -#endif -#endif - if (graphic < 0) { GfxGraphicLast[x][y] = GfxGraphic[x][y]; @@ -222,12 +190,6 @@ void UpdatePlayfield(boolean force_redraw) int sx = x * StretchWidth; int sy = y * StretchWidth; -#if DEBUG_REDRAW -#if 0 - printf("::: REDRAW (%d, %d): %d, %d\n", x, y, graphic, sync_frame); -#endif -#endif - DDSpriteBuffer_BltImg(sx, sy, graphic, sync_frame); #if DEBUG_REDRAW @@ -249,29 +211,10 @@ void BlitScreenToBitmap_SP(Bitmap *target_bitmap) int px = 2 * TILEX + (mScrollX - mScrollX_last) % TILEX; int py = 2 * TILEY + (mScrollY - mScrollY_last) % TILEY; int sx, sy, sxsize, sysize; - -#if 0 - printf("::: %d, %d / %d, %d / %ld, %ld (%ld, %ld) / %d, %d\n", - MurphyScreenXPos, MurphyScreenYPos, - ScreenScrollXPos, ScreenScrollYPos, - mScrollX, mScrollY, - mScrollX_last, mScrollY_last, - px, py); -#endif - int xsize = SXSIZE; int ysize = SYSIZE; -#if NEW_TILESIZE int full_xsize = (FieldWidth - (menBorder ? 0 : 1)) * TILEX_VAR; int full_ysize = (FieldHeight - (menBorder ? 0 : 1)) * TILEY_VAR; -#else - int full_xsize = (FieldWidth - (menBorder ? 0 : 1)) * TILEX; - int full_ysize = (FieldHeight - (menBorder ? 0 : 1)) * TILEY; -#endif - -#if NEW_TILESIZE - -#endif sxsize = (full_xsize < xsize ? full_xsize : xsize); sysize = (full_ysize < ysize ? full_ysize : ysize); @@ -282,29 +225,14 @@ void BlitScreenToBitmap_SP(Bitmap *target_bitmap) px += game_sp.scroll_xoffset; py += game_sp.scroll_yoffset; -#if 1 if (ExplosionShakeMurphy != 0) { px += TILEX / 2 - GetSimpleRandom(TILEX + 1); py += TILEY / 2 - GetSimpleRandom(TILEX + 1); } -#endif -#if NEW_TILESIZE px = px * TILESIZE_VAR / TILESIZE; py = py * TILESIZE_VAR / TILESIZE; -#endif - -#if 0 - printf("::: (%d, %d) (%d, %d) (%d, %d) [%d / %d]\n", - px, py, sxsize, sysize, sx, sy, - FieldHeight, menBorder); -#endif - -#if 0 - printf("::: (%d, %d)\n", - bitmap_db_field_sp->width, bitmap_db_field_sp->height); -#endif BlitBitmap(bitmap_db_field_sp, target_bitmap, px, py, sxsize, sysize, sx, sy); } @@ -314,21 +242,9 @@ void BackToFront_SP(void) static int scroll_x_last = -1, scroll_y_last = -1; static boolean scrolling_last = FALSE; static boolean ExplosionShakeMurphy_last = -1; -#if 1 boolean scrolling = (mScrollX != scroll_x_last || mScrollY != scroll_y_last); - // boolean scrolling = (mScrollX != mScrollX_last || mScrollY != mScrollY_last); -#else - boolean scrolling = (mScrollX % TILEX != 0 || mScrollY % TILEY != 0); -#endif int x, y; -#if 0 - printf("::: %d, %d / %d, %d [%d, %d]\n", - mScrollX, mScrollY, - mScrollX_last, mScrollY_last, - game_sp.scroll_xoffset, game_sp.scroll_yoffset); -#endif - SyncDisplay(); if (0 || @@ -343,35 +259,19 @@ void BackToFront_SP(void) int scroll_yoffset = mScrollY - mScrollY_last + game_sp.scroll_yoffset; int x1 = 0, x2 = SCR_FIELDX - (scroll_xoffset != 0 ? 0 : 1); int y1 = 0, y2 = SCR_FIELDY - (scroll_yoffset != 0 ? 0 : 1); -#if NEW_TILESIZE int full_xsize = (FieldWidth - (menBorder ? 0 : 1)) * TILEX_VAR; int full_ysize = (FieldHeight - (menBorder ? 0 : 1)) * TILEY_VAR; -#else - int full_xsize = (FieldWidth - (menBorder ? 0 : 1)) * TILEX; - int full_ysize = (FieldHeight - (menBorder ? 0 : 1)) * TILEY; -#endif -#if 1 int xsize = SXSIZE; int ysize = SYSIZE; int sxsize = (full_xsize < xsize ? full_xsize : xsize); int sysize = (full_ysize < ysize ? full_ysize : ysize); int sx = SX + (full_xsize < xsize ? (xsize - full_xsize) / 2 : 0); int sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0); -#else - int sx = SX + (full_xsize < SXSIZE ? (SXSIZE - full_xsize) / 2 : 0); - int sy = SY + (full_ysize < SYSIZE ? (SYSIZE - full_ysize) / 2 : 0); -#endif -#if 1 InitGfxClipRegion(TRUE, sx, sy, sxsize, sysize); -#else - InitGfxClipRegion(TRUE, SX, SY, SXSIZE, SYSIZE); -#endif -#if NEW_TILESIZE scroll_xoffset = scroll_xoffset * TILESIZE_VAR / TILESIZE; scroll_yoffset = scroll_yoffset * TILESIZE_VAR / TILESIZE; -#endif for (x = x1; x <= x2; x++) { @@ -380,19 +280,11 @@ void BackToFront_SP(void) int xx = 2 + x; int yy = 2 + y; -#if NEW_TILESIZE if (redraw[xx][yy]) BlitBitmap(bitmap_db_field_sp, window, xx * TILEX_VAR, yy * TILEY_VAR, TILEX_VAR, TILEY_VAR, sx + x * TILEX_VAR - scroll_xoffset, sy + y * TILEY_VAR - scroll_yoffset); -#else - if (redraw[xx][yy]) - BlitBitmap(bitmap_db_field_sp, window, - xx * TILEX, yy * TILEY, TILEX, TILEY, - sx + x * TILEX - scroll_xoffset, - sy + y * TILEY - scroll_yoffset); -#endif } } @@ -401,15 +293,9 @@ void BackToFront_SP(void) FlushDisplay(); -#if 1 for (x = 0; x < 2 + MAX_PLAYFIELD_WIDTH + 2; x++) for (y = 0; y < 2 + MAX_PLAYFIELD_HEIGHT + 2; y++) redraw[x][y] = FALSE; -#else - for (x = 0; x < MAX_BUF_XSIZE; x++) - for (y = 0; y < MAX_BUF_YSIZE; y++) - redraw[x][y] = FALSE; -#endif redraw_tiles = 0; scroll_x_last = mScrollX; @@ -457,9 +343,6 @@ void DDScrollBuffer_ScrollTowards(int X, int Y, double Step) void DDScrollBuffer_SoftScrollTo(int X, int Y, int TimeMS, int FPS) { double dx, dY; -#if 0 - int dT; -#endif int StepCount; double T, tStep; int oldX, oldY, maxD; @@ -484,9 +367,6 @@ void DDScrollBuffer_SoftScrollTo(int X, int Y, int TimeMS, int FPS) if (StepCount == 0) StepCount = 1; -#if 0 - dT = 1000 / FPS; -#endif tStep = (double)1 / StepCount; oldX = mScrollX; oldY = mScrollY; diff --git a/src/game_sp/DDScrollBuffer.h b/src/game_sp/DDScrollBuffer.h index 83bb5c85..e22db88e 100644 --- a/src/game_sp/DDScrollBuffer.h +++ b/src/game_sp/DDScrollBuffer.h @@ -11,11 +11,7 @@ extern int mScrollX, mScrollY; extern int mScrollX_last, mScrollY_last; -#if 1 extern boolean redraw[2 + MAX_PLAYFIELD_WIDTH + 2][2 + MAX_PLAYFIELD_HEIGHT + 2]; -#else -extern boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; -#endif extern int TEST_flag; diff --git a/src/game_sp/DDSpriteBuffer.c b/src/game_sp/DDSpriteBuffer.c index 47ec6aa3..e2f47eee 100644 --- a/src/game_sp/DDSpriteBuffer.c +++ b/src/game_sp/DDSpriteBuffer.c @@ -7,28 +7,12 @@ static void Blt(int pX, int pY, Bitmap *bitmap, int SpriteX, int SpriteY) { -#if NEW_TILESIZE -#if 0 - int pseudo_sxsize = SXSIZE * TILESIZE / TILESIZE_VAR; - int pseudo_sysize = SYSIZE * TILESIZE / TILESIZE_VAR; -#endif -#endif int scx = (mScrollX_last < 0 ? 0 : mScrollX_last); int scy = (mScrollY_last < 0 ? 0 : mScrollY_last); int sx1 = scx - 2 * TILEX; int sy1 = scy - 2 * TILEY; -#if NEW_TILESIZE -#if 1 int sx2 = scx + (SCR_FIELDX + 1) * TILEX; int sy2 = scy + (SCR_FIELDY + 1) * TILEY; -#else - int sx2 = scx + pseudo_sxsize + 1 * TILEX; - int sy2 = scy + pseudo_sysize + 1 * TILEY; -#endif -#else - int sx2 = scx + SXSIZE + 1 * TILEX; - int sy2 = scy + SYSIZE + 1 * TILEY; -#endif int sx = pX - sx1; int sy = pY - sy1; int tile_x = sx / TILESIZE; @@ -43,22 +27,11 @@ static void Blt(int pX, int pY, Bitmap *bitmap, int SpriteX, int SpriteY) if (pX < sx1 || pX > sx2 || pY < sy1 || pY > sy2) return; -#if NEW_TILESIZE - -#if 0 - SpriteX = SpriteX * TILESIZE_VAR / TILESIZE; - SpriteY = SpriteY * TILESIZE_VAR / TILESIZE; -#endif - sx = sx * TILESIZE_VAR / TILESIZE; sy = sy * TILESIZE_VAR / TILESIZE; BlitBitmap(bitmap, bitmap_db_field_sp, SpriteX, SpriteY, TILEX_VAR, TILEY_VAR, sx, sy); -#else - BlitBitmap(bitmap, bitmap_db_field_sp, SpriteX, SpriteY, - TILEX, TILEY, sx, sy); -#endif redraw[tile_x][tile_y] = TRUE; redraw_tiles++; diff --git a/src/game_sp/DoGameStuff.c b/src/game_sp/DoGameStuff.c index 5575d11a..88434a90 100644 --- a/src/game_sp/DoGameStuff.c +++ b/src/game_sp/DoGameStuff.c @@ -8,13 +8,8 @@ static void CallAnimation(int si, byte bl); static boolean IsToBeAnimated(int bl); -#if 1 int AnimationPosTable[SP_MAX_PLAYFIELD_SIZE]; byte AnimationSubTable[SP_MAX_PLAYFIELD_SIZE]; -#else -int *AnimationPosTable; -byte *AnimationSubTable; -#endif // ========================================================================== @@ -75,19 +70,10 @@ void subDoGameStuff() !game_sp.LevelSolved && !game_sp.GameOver) { -#if 0 - printf("::: DoGameStuff.c: killing murphy [%d] ...\n", KillMurphyFlag); -#endif - KillMurphyFlag = 0; // no more "kill Murphy" ExplodeFieldSP(MurphyExplodePos); // Explode LeadOutCounter = 0x40; // quit: start lead-out -#if 0 - printf("::: DoGameStuff.c: !!!!!!!!!! GAME OVER !!!!!!!!!!\n"); - printf("::: [KillMurphyFlag == %d]\n", KillMurphyFlag); -#endif - /* give Murphy some more time (LeadOutCounter) to reach the exit */ } } // loc_g_22FB: diff --git a/src/game_sp/DoGameStuff.h b/src/game_sp/DoGameStuff.h index 4cf98184..4fff48c0 100644 --- a/src/game_sp/DoGameStuff.h +++ b/src/game_sp/DoGameStuff.h @@ -7,13 +7,8 @@ #include "global.h" -#if 1 extern int AnimationPosTable[SP_MAX_PLAYFIELD_SIZE]; extern byte AnimationSubTable[SP_MAX_PLAYFIELD_SIZE]; -#else -extern byte *AnimationSubTable; -extern int *AnimationPosTable; -#endif extern void subDoGameStuff(); diff --git a/src/game_sp/Explosions.c b/src/game_sp/Explosions.c index 0a73d754..7729d844 100644 --- a/src/game_sp/Explosions.c +++ b/src/game_sp/Explosions.c @@ -18,9 +18,6 @@ static void subExplodeZonk(int tsi, int cx); void subAnimateExplosion(int si) { int ax, bl; -#if 0 - int X, Y; -#endif if (LowByte(PlayField16[si]) != fiExplosion) return; @@ -38,10 +35,6 @@ void subAnimateExplosion(int si) MovHighByte(&PlayField16[si], bl); // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -#if 0 - X = GetStretchX(si); - Y = GetStretchY(si); -#endif GfxGraphic[GetX(si)][GetY(si)] = aniDefaultExplosion; // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -76,10 +69,6 @@ loc_g_28D0: // explosion produces infotron MovHighByte(&PlayField16[si], bl); // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -#if 0 - X = GetStretchX(si); - Y = GetStretchY(si); -#endif GfxGraphic[GetX(si)][GetY(si)] = aniElectronExplosion; // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ } @@ -101,15 +90,9 @@ void ExplodeFieldSP(int si) if (ax == fiMurphy) { -#if 0 - printf("::: Explosions.c: ExplodeFieldSP(): killing murphy\n"); -#endif - KillMurphyFlag = 1; -#if 1 ExplosionShakeMurphy = 30; // Murphy explodes -#endif } if (ax == fiElectron) @@ -175,11 +158,6 @@ static void LetExplodeFieldSP(int tsi, int cx, int dh) break; case fiMurphy: -#if 0 - printf("::: Explosions.c: LetExplodeFieldSP(): killing murphy [%d]\n", - tsi); -#endif - KillMurphyFlag = 1; PlayField8[tsi] = dh; PlayField16[tsi] = cx; @@ -283,19 +261,11 @@ static void subExplodeInfotron(int tsi, int cx) void subClearFieldDueToExplosion(int si) { -#if 0 - int X, Y; -#endif - if (LowByte(PlayField16[si]) == fiExplosion) return; PlayField16[si] = 0; // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -#if 0 - X = GetStretchX(si); - Y = GetStretchY(si); -#endif GfxGraphic[GetX(si)][GetY(si)] = aniSpace; // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ } @@ -315,12 +285,7 @@ void subRedDiskReleaseExplosion() // +++++++++++++++++++++++++++++++++++++++++ X = GetStretchX(si); Y = GetStretchY(si); -#if 0 - // !!! causes flicker -- fix in Murphy.c !!! - GfxGraphic[GetX(si)][GetY(si)] = aniRedDisk; -#else DDSpriteBuffer_BltImg(X, Y, aniRedDisk, 0); -#endif // +++++++++++++++++++++++++++++++++++++++++ RedDiskReleasePhase = RedDiskReleasePhase + 1; diff --git a/src/game_sp/Globals.c b/src/game_sp/Globals.c index 9ddbf2b0..44affc03 100644 --- a/src/game_sp/Globals.c +++ b/src/game_sp/Globals.c @@ -14,28 +14,13 @@ int FieldWidth; // standard size = 60 int FieldHeight; // standard size = 24 int HeaderSize; // standard size = 96 int FieldMax, LevelMax; -#if 0 -int FileMax; -#endif -#if 1 int *PlayField16; byte *PlayField8; -// int PlayField16[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE]; -// byte PlayField8[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE]; byte DisPlayField[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE]; -#else -int *PlayField16; -byte *PlayField8; -byte *DisPlayField; -#endif int TimerVar; -#if 1 short RandomSeed; -#else -int RandomSeed; -#endif int FreezeZonks; @@ -192,17 +177,6 @@ void InitGlobals() SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE) * sizeof(byte)); PlayField8 = &PlayField8[SP_MAX_PLAYFIELD_WIDTH]; - -#if 0 - /* these defaults will be changed after reading a Supaplex level file */ - PlayField8 = REDIM_1D(sizeof(byte), 0, FieldMax); - DisPlayField = REDIM_1D(sizeof(byte), 0, FieldMax); - PlayField16 = REDIM_1D(sizeof(int), 0, FieldMax); - - AnimationPosTable = REDIM_1D(sizeof(int), 0, LevelMax); - AnimationSubTable = REDIM_1D(sizeof(byte), 0, LevelMax); - TerminalState = REDIM_1D(sizeof(byte), 0, FieldMax); -#endif } int GetSI(int X, int Y) @@ -234,26 +208,12 @@ void PrepareLevel() { copyInternalEngineVars_SP(); -#if 1 SetDisplayRegion(); SetScrollEdges(); -#endif LevelLoaded = True; } -#if 0 -void Trace(char *Source, char *Message) -{ - printf("::: Trace: Source == '%s', Message == '%s'\n", Source, Message); -} - -void ReportError(char *Source, char *Message) -{ - printf("::: ReportError: Source == '%s', Message == '%s'\n", Source, Message); -} -#endif - int Min(int A, int B) { return (A < B ? A : B); diff --git a/src/game_sp/Globals.h b/src/game_sp/Globals.h index 6b965de9..5923bad5 100644 --- a/src/game_sp/Globals.h +++ b/src/game_sp/Globals.h @@ -15,12 +15,7 @@ #define ScrollDelta ((int)1) -#if NEW_TILESIZE -// #define ZoomFactor (ZOOM_FACTOR) #define ZoomFactor (2) -#else -#define ZoomFactor (2) -#endif #define StretchWidth (ZoomFactor * 16) #define TwoPixels (ZoomFactor * 2) @@ -282,11 +277,6 @@ extern void PrepareLevel(); extern int getSequenceLength(int sequence); extern boolean isSnappingSequence(int sequence); -#if 0 -extern void Trace(char *Source, char *Message); -extern void ReportError(char *Source, char *Message); -#endif - extern int Min(int A, int B); extern int Max(int A, int B); @@ -299,17 +289,9 @@ extern boolean LevelLoaded; extern boolean DemoAvailable; extern boolean menBorder; -#if 1 extern int *PlayField16; extern byte *PlayField8; -// extern int PlayField16[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE]; -// extern byte PlayField8[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE]; extern byte DisPlayField[SP_MAX_PLAYFIELD_SIZE + SP_HEADER_SIZE]; -#else -extern int *PlayField16; -extern byte *PlayField8; -extern byte *DisPlayField; -#endif extern int FieldHeight; extern int FieldMax, LevelMax; @@ -319,10 +301,6 @@ extern int HeaderSize; extern int TimerVar; extern short RandomSeed; -#if 0 -extern int FileMax; -#endif - extern LevelInfoType LInfo; extern int ScrollMinX, ScrollMaxX, ScrollMinY, ScrollMaxY; extern int ScrollX, ScrollY; diff --git a/src/game_sp/Infotrons.c b/src/game_sp/Infotrons.c index c671c606..ecf29af4 100644 --- a/src/game_sp/Infotrons.c +++ b/src/game_sp/Infotrons.c @@ -164,19 +164,8 @@ loc_g_1242: // infotron comes falling from above if (ax == fiOrangeDisk) // orange disk hit goto loc_g_1386; -#if 1 - -#if 1 // play the infotron sound, 'cause infotron hits something "hard" subSoundFX(si, fiInfotron, actImpact); -#else - // play the zonk sound, 'cause zonk hits something "hard" - subSoundFX(si, fiZonk, actImpact); -#endif - -#else - subSoundFXZonk(); // play the zonk sound,'cause zonk hits something "hard" -#endif if (! (ax == fiZonk || ax == fiInfotron || ax == fiRAM)) return; diff --git a/src/game_sp/MainForm.c b/src/game_sp/MainForm.c index d33191d6..b6d7952c 100644 --- a/src/game_sp/MainForm.c +++ b/src/game_sp/MainForm.c @@ -17,10 +17,8 @@ void DrawFrameIfNeeded() DrawFrame(0); /* !!! CHECK THIS !!! */ -#if 1 if (! menBorder) DrawFrame(1); -#endif } void DisplayLevel() @@ -31,16 +29,9 @@ void DisplayLevel() return; ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); -#if 1 ClearRectangle(bitmap_db_field_sp, 0, 0, FXSIZE, FYSIZE); -#else - ClearRectangle(bitmap_db_field_sp, 0, 0, - MAX_BUF_XSIZE * TILEX, MAX_BUF_YSIZE * TILEY); -#endif -#if 1 SetDisplayRegion(); -#endif DrawFrameIfNeeded(); @@ -157,14 +148,6 @@ void menPlay_Click() ReStretch(); subMainGameLoop_Init(); - -#if 1 - return; -#endif - - bPlaying = False; - - subFetchAndInitLevel(); } static void ReStretch() @@ -187,30 +170,14 @@ static void ReStretch() void SetScrollEdges() { -#if NEW_TILESIZE -#if 0 - int pseudo_sxsize = SXSIZE * TILESIZE / TILESIZE_VAR; - int pseudo_sysize = SYSIZE * TILESIZE / TILESIZE_VAR; -#endif -#endif int border1_offset = (menBorder ? 1 : 2); int border2_offset = (menBorder ? 0 : TILESIZE / 2); /* scroll correction for border frame (1 tile) or border element (2 tiles) */ ScrollMinX = 0; ScrollMinY = 0; -#if NEW_TILESIZE -#if 1 ScrollMaxX = (DisplayMaxX + border1_offset - SCR_FIELDX) * TILEX; ScrollMaxY = (DisplayMaxY + border1_offset - SCR_FIELDY) * TILEY; -#else - ScrollMaxX = (DisplayMaxX + border1_offset) * TILEX - pseudo_sxsize; - ScrollMaxY = (DisplayMaxY + border1_offset) * TILEY - pseudo_sysize; -#endif -#else - ScrollMaxX = (DisplayMaxX + border1_offset) * TILEX - SXSIZE; - ScrollMaxY = (DisplayMaxY + border1_offset) * TILEY - SYSIZE; -#endif /* scroll correction for border element (half tile on left and right side) */ ScrollMinX += border2_offset; @@ -223,12 +190,6 @@ void SetScrollEdges() ScrollMaxX -= game_sp.scroll_xoffset; ScrollMinY -= game_sp.scroll_yoffset; ScrollMaxY -= game_sp.scroll_yoffset; - -#if 0 - printf("::: (%ld, %ld), (%ld, %ld) -> (%d, %d), (%d, %d)\n", - DisplayMinX, DisplayMinY, DisplayMaxX, DisplayMaxY, - ScrollMinX, ScrollMinY, ScrollMaxX, ScrollMaxY); -#endif } void DrawField(int X, int Y) @@ -289,25 +250,7 @@ void DrawFieldNoAnimated(int X, int Y) break; default: -#if 1 DrawField(X, Y); -#else - if (Tmp < fiFirst || Tmp > fiLast) - Tmp = fiSpace; - - if (Tmp == fiRAM || - Tmp == fiHardWare || - Tmp == fiBug || - Tmp == fiWallSpace) - Tmp = DisPlayField[tsi]; - - subCopyImageToScreen(tsi, fiGraphic[Tmp]); - - if (Tmp != fiSpace && - Tmp != fiSnikSnak && - Tmp != fiElectron) - GfxGraphic[X][Y] = fiGraphic[Tmp]; -#endif break; } } diff --git a/src/game_sp/MainGameLoop.c b/src/game_sp/MainGameLoop.c index 48a1ac48..61d5ed1c 100644 --- a/src/game_sp/MainGameLoop.c +++ b/src/game_sp/MainGameLoop.c @@ -51,24 +51,13 @@ void subMainGameLoop_Main(byte action, boolean warp_mode) TimerVar = TimerVar + 1; -#if 1 if (ExplosionShakeMurphy > 0) ExplosionShakeMurphy--; -#endif -#if 1 if (ExitToMenuFlag == 1) { // happens when demo ends or when Murphy enters exit (to be checked) - -#if 0 - goto locExitMainGameLoop; -#endif } -#else - if (ExitToMenuFlag == 1) - goto locExitMainGameLoop; -#endif if (LeadOutCounter == 0) // no lead-out: game busy return; @@ -85,25 +74,13 @@ void subMainGameLoop_Main(byte action, boolean warp_mode) // lead-out done: exit now // ---------------------- END OF GAME-BUSY LOOP (including lead-out) --------- -#if 0 -locExitMainGameLoop: -#endif - -#if 0 - printf("::: locExitMainGameLoop reached [%d]\n", LeadOutCounter); - printf("::: [KillMurphyFlag == %d]\n", KillMurphyFlag); -#endif - -#if 1 /* if the game is not won when reaching this point, then it is lost */ if (!game_sp.LevelSolved) game_sp.GameOver = TRUE; -#endif } void subCalculateScreenScrollPos() { -#if 1 int jump_pos = TILEX / 2; /* handle wrap-around */ @@ -117,7 +94,6 @@ void subCalculateScreenScrollPos() MurphyScreenXPos = MurphyScreenXPos - FieldWidth * TILEX; MurphyScreenYPos += TILEY; } -#endif if (ExplosionShake != 0) { diff --git a/src/game_sp/Murphy.c b/src/game_sp/Murphy.c index 115227ff..bf590db0 100644 --- a/src/game_sp/Murphy.c +++ b/src/game_sp/Murphy.c @@ -8,18 +8,9 @@ static void subEatRedDisk(int si); static boolean subMoveKillsMurphy(int si, int ax, int bl); -#if 1 - #define LocalStretch (2) #define MurphyZoomFactor (ZoomFactor) -#else - -#define LocalStretch (1) -#define MurphyZoomFactor (1) - -#endif - // ========================================================================== // SUBROUTINE // Move Murphy in any direction @@ -81,10 +72,6 @@ void subAnimateMurphy(int *si) } } // loc_g_5E8B: -#if 0 - printf("::: RedDiskReleaseFlag == %d\n", RedDiskReleaseFlag); -#endif - bl = DemoKeyCode; if (bl != 0) // a key was pressed! goto locKeyPressed5FCF; @@ -96,14 +83,6 @@ void subAnimateMurphy(int *si) goto loc_g_6364; } -#if 1 - -#if 0 - ax = (TimerVar & 3); - if (ax != 0) - return; -#endif - // ------------------------------------------------------------------ // Murphy's YAWN & SLEEP sequence, counted down by YawnSleepCounter: @@ -184,79 +163,6 @@ void subAnimateMurphy(int *si) // end of YAWN-SLEEP-Sequence -#else - - ax = (TimerVar & 3); - if (ax != 0) - return; - - // ------------------------------------------------------------------ - // Murphy's YAWN & SLEEP sequence, counted down by YawnSleepCounter: - YawnSleepCounter = YawnSleepCounter + 1; - if (YawnSleepCounter == 4) - { - subCopyFieldToScreen(*si, fiMurphy); // normal grin - return; - } // loc_g_5ECE: - - if (YawnSleepCounter <= 500) // loc_g_5ED7: - return; - - if (YawnSleepCounter <= 522) - { - bx = (YawnSleepCounter - 500) / 2; - subCopyFieldToScreen(*si, aniMurphyYawn + bx); // yawn! and look depressed afterwards... - return; - } // loc_g_5F00: - - if (YawnSleepCounter <= 1000) - return; - - if (YawnSleepCounter <= 1022) - { - bx = (YawnSleepCounter - 1000) / 2; - subCopyFieldToScreen(*si, aniMurphyYawn + bx); // yawn again! - return; - } // loc_g_5F32: - - if (YawnSleepCounter <= 1600) // loc_g_5F3B: - return; - - if (YawnSleepCounter <= 1622) - { - bx = (YawnSleepCounter - 1600) / 2; - subCopyFieldToScreen(*si, aniMurphyYawn + bx); // yawn again! - third time - return; - } // loc_g_5F64: - - if (YawnSleepCounter > 1654) - return; - - if (PlayField16[*si - 1] == 0) - { - if (PlayField16[*si + 1] == 0) - { - YawnSleepCounter = 36; - return; - - } - else - { - bx = (YawnSleepCounter - 1622) / 16; - subCopyFieldToScreen(*si, aniMurphySleepRight + bx); // go to sleep - return; - } - } // loc_g_5F81: - - bx = (YawnSleepCounter - 1622) / 16; - subCopyFieldToScreen(*si, aniMurphySleepLeft + bx); // go to sleep - - return; - - // end of YAWN-SLEEP-Sequence - -#endif - // ------------------------------------------------------------------ // ========================================================================== // (Direct Jump) a key was pressed @@ -944,11 +850,6 @@ loc_g_65FE: subSoundFX(*si, fiInfotron, actCollecting); dx1 = aniEatInfotronLeft; -#if 0 - dx2 = fiInfotron; - dx2Step = -1; - ClearPos = -1; -#endif PlayField16[*si - 1] = 0xA03; PlayField16[*si] = 0x300; *si = *si - 1; @@ -975,11 +876,6 @@ loc_g_6662: subSoundFX(*si, fiInfotron, actCollecting); dx1 = aniEatInfotronRight; -#if 0 - dx2 = fiInfotron; - dx2Step = 1; - ClearPos = -1; -#endif PlayField16[*si + 1] = 0xC03; PlayField16[*si] = 0x300; *si = *si + 1; @@ -1050,14 +946,7 @@ loc_g_6756: if (LowByte(InfotronsNeeded) != 0) return; -#if 0 - if (!game_sp.LevelSolved) - printf("::: Murphy.c: !!!!!!!!!! LEVEL %d SOLVED !!!!!!!!!!\n", level_nr); -#endif - -#if 1 game_sp.LevelSolved = TRUE; -#endif subSoundFX(*si, fiExit, actPassing); @@ -1119,16 +1008,8 @@ loc_g_6817: return; } // loc_g_6838: -#if 1 // draw new terminal type -#if 1 GfxGraphic[GetX(*si - FieldWidth)][GetY(*si - FieldWidth)] = aniTerminalActive; -#else - subCopyImageToScreen(*si - FieldWidth, aniTerminalActive); -#endif -#else - subCopyFieldToScreen(*si - FieldWidth, 0x88); // draw new terminal type -#endif TerminalState[*si - FieldWidth] = 8; goto loc_g_68F0; @@ -1145,16 +1026,8 @@ loc_g_684E: return; } // loc_g_6838: -#if 1 // draw new terminal type -#if 1 GfxGraphic[GetX(*si - 1)][GetY(*si - 1)] = aniTerminalActive; -#else - subCopyImageToScreen(*si - 1, aniTerminalActive); -#endif -#else - subCopyFieldToScreen(*si - 1, 0x88); // draw new terminal type -#endif TerminalState[*si - 1] = 8; goto loc_g_68F0; @@ -1171,16 +1044,8 @@ loc_g_6884: return; } // loc_g_6838: -#if 1 // draw new terminal type -#if 1 GfxGraphic[GetX(*si + FieldWidth)][GetY(*si + FieldWidth)] = aniTerminalActive; -#else - subCopyImageToScreen(*si + FieldWidth, aniTerminalActive); -#endif -#else - subCopyFieldToScreen(*si + FieldWidth, 0x88); // draw new terminal type -#endif TerminalState[*si + FieldWidth] = 8; goto loc_g_68F0; @@ -1197,16 +1062,8 @@ loc_g_68BA: return; } // loc_g_6838: -#if 1 // draw new terminal type -#if 1 GfxGraphic[GetX(*si + 1)][GetY(*si + 1)] = aniTerminalActive; -#else - subCopyImageToScreen(*si + 1, aniTerminalActive); -#endif -#else - subCopyFieldToScreen(*si + 1, 0x88); // draw new terminal type -#endif TerminalState[*si + 1] = 8; // ========================================================================== // common TERMINAL stuff moving/touching from all directions @@ -1579,10 +1436,8 @@ locProceedMovingMurphy: // proceed moving murphy loc_g_6C8F: -#if 1 if (SeqPos <= 0) dx1SequenceLength = getSequenceLength(dx1); -#endif if (SplitMoveFlag == 0) { @@ -1594,55 +1449,28 @@ loc_g_6C8F: if (!(ClearPos < 0)) // clear field that murphy is leaving subCopyImageToScreen(ClearPos, aniSpace); -#if 0 - // !!! special two-tile animation currently not used !!! - if (dx2 == fiInfotron) // special case of infotron moving left or right - { - tDeltaX = 0; - tDeltaY = 0; - } - else -#endif - { - tDeltaX = MurphyDX * LocalStretch * (SeqPos + 1); - tDeltaY = MurphyDY * LocalStretch * (SeqPos + 1); - } + tDeltaX = MurphyDX * LocalStretch * (SeqPos + 1); + tDeltaY = MurphyDY * LocalStretch * (SeqPos + 1); X = GetStretchX(dxPos) + tDeltaX; Y = GetStretchY(dxPos) + tDeltaY; Tmp = (SeqPos < 0 ? 0 : SeqPos); // 9StepBugFix!(red disk move right) -#if 1 if (isSnappingSequence(dx1) && SeqPos == dx1SequenceLength - 1) dx1 = aniSpace; -#endif -#if 1 DDSpriteBuffer_BltImg(X, Y, dx1, Tmp); GfxGraphic[GetX(*si)][GetY(*si)] = -1; // (Murphy's position) GfxGraphic[GetX(dxPos)][GetY(dxPos)] = -1; // (snapping position) - // printf("::: Tmp: %d\n", Tmp); -#else - StretchedSprites.BltEx(X, Y, dx[Tmp]); -#endif if (!(dx2 < 0)) { tPos = dxPos + dx2Step; X = GetStretchX(tPos); Y = GetStretchY(tPos); -#if 0 - // !!! special two-tile animation currently not used !!! - if (dx2 == fiInfotron) // special case of infotron moving left or right - { - StretchedSprites.BltEx(X, Y, dx[SeqPos] + dx2Step); - } - else // pushing something -#endif - { - // (SeqPos iterates from 0 to 7 while pushing) - DDSpriteBuffer_BltImg(X + tDeltaX, Y + tDeltaY, dx2, SeqPos); - } + + // (SeqPos iterates from 0 to 7 while pushing) + DDSpriteBuffer_BltImg(X + tDeltaX, Y + tDeltaY, dx2, SeqPos); } // End of normal movement @@ -1671,13 +1499,8 @@ loc_g_6C8F: } // loc_g_6D1E:'loc_g_6D28: SeqPos = SeqPos + 1; -#if 1 if (SeqPos < dx1SequenceLength) return; -#else - if (dx[SeqPos] > -1) - return; -#endif // Follow-up after movement completed 'loc_g_6D35: MurphyXPos = MurphyXPos + MurphyDX; @@ -1966,9 +1789,7 @@ loc_g_6F3B: loc_g_6F77: ExitToMenuFlag = 1; -#if 1 PlayField16[*si] = fiSpace; // remove Murphy from playfield after exiting -#endif return; diff --git a/src/game_sp/SnikSnaks.c b/src/game_sp/SnikSnaks.c index e23dc902..a03e332e 100644 --- a/src/game_sp/SnikSnaks.c +++ b/src/game_sp/SnikSnaks.c @@ -33,11 +33,9 @@ void subAnimateSnikSnaks(int si) if (SnikSnaksElectronsFrozen == 1) return; -#if 1 /* (not sure why this was removed -- this broke several level solutions) */ if (LowByte(PlayField16[si]) != fiSnikSnak) return; -#endif // If LowByte(PlayField16(si)) <> fiSnikSnak Then Exit Function // Debug.Assert (LowByte(PlayField16[si]) == fiSnikSnak); diff --git a/src/game_sp/Zonk.c b/src/game_sp/Zonk.c index d8285345..785b9c49 100644 --- a/src/game_sp/Zonk.c +++ b/src/game_sp/Zonk.c @@ -181,12 +181,8 @@ loc_g_0DE8: // zonk comes falling from above if (ax == fiOrangeDisk) // OrangeDisk explodes 'loc_g_0E95: goto loc_g_0F75; -#if 1 // play the zonk sound, 'cause zonk hits something "hard" subSoundFX(si, fiZonk, actImpact); -#else - subSoundFXZonk(); // play the zonk sound,'cause zonk hits something "hard" -#endif if (! (ax == fiZonk || ax == fiInfotron || ax == fiRAM)) return; diff --git a/src/game_sp/export.h b/src/game_sp/export.h index 364ede02..42d01420 100644 --- a/src/game_sp/export.h +++ b/src/game_sp/export.h @@ -26,11 +26,6 @@ SP_MAX_PLAYFIELD_HEIGHT) #define SP_STD_LEVEL_SIZE (SP_HEADER_SIZE + SP_STD_PLAYFIELD_SIZE) -#if 0 -#define SP_SCREEN_BUFFER_XSIZE (SCR_FIELDX + 2) -#define SP_SCREEN_BUFFER_YSIZE (SCR_FIELDY + 2) -#endif - #define SP_FRAMES_PER_SECOND 35 #define SP_MAX_TAPE_LEN 64010 /* (see "spfix63.doc") */ @@ -55,11 +50,7 @@ #ifndef HAS_SpecialPortType typedef struct { -#if 1 short PortLocation; // = 2*(x+(y*60)) /* big endian format */ -#else - int PortLocation; // = 2*(x+(y*60)) -#endif byte Gravity; // 1 = turn on, anything else (0) = turn off byte FreezeZonks; // 2 = turn on, anything else (0) = turn off (1=off!) byte FreezeEnemies; // 1 = turn on, anything else (0) = turn off @@ -85,11 +76,7 @@ typedef struct SpecialPortType SpecialPort[10]; byte SpeedByte; // = Speed XOR Highbyte(RandomSeed) byte CheckSumByte; // = CheckSum XOR SpeedByte -#if 1 short DemoRandomSeed; /* little endian format */ -#else - int DemoRandomSeed; -#endif } LevelInfoType; #define HAS_LevelInfoType #endif diff --git a/src/game_sp/file.c b/src/game_sp/file.c index 438e7664..a38c8066 100644 --- a/src/game_sp/file.c +++ b/src/game_sp/file.c @@ -72,17 +72,6 @@ void copyInternalEngineVars_SP() FieldMax = (FieldWidth * FieldHeight) + HeaderSize - 1; LevelMax = (FieldWidth * FieldHeight) - 1; -#if 0 - /* (add one byte for the level number stored as first byte of demo data) */ - FileMax = FieldMax + native_sp_level.demo.length + 1; -#endif - -#if 0 - PlayField8 = REDIM_1D(sizeof(byte), 0, FileMax); - DisPlayField = REDIM_1D(sizeof(byte), 0, FieldMax); - PlayField16 = REDIM_1D(sizeof(int), -game_sp.preceding_buffer_size, FieldMax); -#endif - /* initialize preceding playfield buffer */ for (i = -game_sp.preceding_buffer_size; i < 0; i++) PlayField16[i] = 0; @@ -137,38 +126,15 @@ void copyInternalEngineVars_SP() } if (native_sp_level.demo.is_available) - { DemoAvailable = True; -#if 0 - /* !!! NEVER USED !!! */ - PlayField8[FieldMax + 1] = native_sp_level.demo.level_nr; - - /* !!! NEVER USED !!! */ - for (i = 0; i < native_sp_level.demo.length; i++) - PlayField8[FieldMax + 2 + i] = native_sp_level.demo.data[i]; -#endif - } - -#if 0 - AnimationPosTable = REDIM_1D(sizeof(int), 0, LevelMax - 2 * FieldWidth); - AnimationSubTable = REDIM_1D(sizeof(byte), 0, LevelMax - 2 * FieldWidth); - TerminalState = REDIM_1D(sizeof(byte), 0, FieldMax); -#endif - GravityFlag = LInfo.InitialGravity; FreezeZonks = LInfo.InitialFreezeZonks; -#if 1 - /* this is set by main game tape code to native random generator directly */ -#else - RandomSeed = LInfo.DemoRandomSeed; -#endif - LevelLoaded = True; -} -#if 1 + /* random seed set by main game tape code to native random generator seed */ +} static void LoadNativeLevelFromFileStream_SP(File *file, int width, int height, boolean demo_available) @@ -300,142 +266,6 @@ static void LoadNativeLevelFromFileStream_SP(File *file, int width, int height, } } -#else - -static void LoadNativeLevelFromFileStream_SP(FILE *file, int width, int height, - boolean demo_available) -{ - LevelInfoType *header = &native_sp_level.header; - int i, x, y; - - /* for details of the Supaplex level format, see Herman Perk's Supaplex - documentation file "SPFIX63.DOC" from his Supaplex "SpeedFix" package */ - - native_sp_level.width = MIN(width, SP_MAX_PLAYFIELD_WIDTH); - native_sp_level.height = MIN(height, SP_MAX_PLAYFIELD_HEIGHT); - - /* read level playfield (width * height == 60 * 24 tiles == 1440 bytes) */ - /* (MPX levels may have non-standard playfield size -- check max. size) */ - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - { - byte element = getFile8Bit(file); - - if (x < SP_MAX_PLAYFIELD_WIDTH && - y < SP_MAX_PLAYFIELD_HEIGHT) - native_sp_level.playfield[x][y] = element; - } - } - - /* read level header (96 bytes) */ - - ReadUnusedBytesFromFile(file, 4); /* (not used by Supaplex engine) */ - - /* initial gravity: 1 == "on", anything else (0) == "off" */ - header->InitialGravity = getFile8Bit(file); - - /* SpeedFixVersion XOR 0x20 */ - header->Version = getFile8Bit(file); - - /* level title in uppercase letters, padded with dashes ("-") (23 bytes) */ - for (i = 0; i < SP_LEVEL_NAME_LEN; i++) - header->LevelTitle[i] = getFile8Bit(file); - - /* initial "freeze zonks": 2 == "on", anything else (0, 1) == "off" */ - header->InitialFreezeZonks = getFile8Bit(file); - - /* number of infotrons needed; 0 means that Supaplex will count the total - amount of infotrons in the level and use the low byte of that number - (a multiple of 256 infotrons will result in "0 infotrons needed"!) */ - header->InfotronsNeeded = getFile8Bit(file); - - /* number of special ("gravity") port entries below (maximum 10 allowed) */ - header->SpecialPortCount = getFile8Bit(file); - - /* database of properties of up to 10 special ports (6 bytes per port) */ - for (i = 0; i < SP_MAX_SPECIAL_PORTS; i++) - { - SpecialPortType *port = &header->SpecialPort[i]; - - /* high and low byte of the location of a special port; if (x, y) are the - coordinates of a port in the field and (0, 0) is the top-left corner, - the 16 bit value here calculates as 2 * (x + (y * 60)) (this is twice - of what may be expected: Supaplex works with a game field in memory - which is 2 bytes per tile) */ - port->PortLocation = getFile16BitBE(file); /* yes, big endian */ - - /* change gravity: 1 == "turn on", anything else (0) == "turn off" */ - port->Gravity = getFile8Bit(file); - - /* "freeze zonks": 2 == "turn on", anything else (0, 1) == "turn off" */ - port->FreezeZonks = getFile8Bit(file); - - /* "freeze enemies": 1 == "turn on", anything else (0) == "turn off" */ - port->FreezeEnemies = getFile8Bit(file); - - ReadUnusedBytesFromFile(file, 1); /* (not used by Supaplex engine) */ - } - - /* SpeedByte XOR Highbyte(RandomSeed) */ - header->SpeedByte = getFile8Bit(file); - - /* CheckSum XOR SpeedByte */ - header->CheckSumByte = getFile8Bit(file); - - /* random seed used for recorded demos */ - header->DemoRandomSeed = getFile16BitLE(file); /* yes, little endian */ - - /* auto-determine number of infotrons if it was stored as "0" -- see above */ - if (header->InfotronsNeeded == 0) - { - for (x = 0; x < native_sp_level.width; x++) - for (y = 0; y < native_sp_level.height; y++) - if (native_sp_level.playfield[x][y] == fiInfotron) - header->InfotronsNeeded++; - - header->InfotronsNeeded &= 0xff; /* only use low byte -- see above */ - } - - /* read raw level header bytes (96 bytes) */ - - fseek(file, -(SP_HEADER_SIZE), SEEK_CUR); /* rewind file */ - for (i = 0; i < SP_HEADER_SIZE; i++) - native_sp_level.header_raw_bytes[i] = fgetc(file); - - /* also load demo tape, if available (only in single level files) */ - - if (demo_available) - { - int level_nr = getFile8Bit(file); - - level_nr &= 0x7f; /* clear highest bit */ - level_nr = (level_nr < 1 ? 1 : - level_nr > 111 ? 111 : level_nr); - - native_sp_level.demo.level_nr = level_nr; - - for (i = 0; i < SP_MAX_TAPE_LEN && !feof(file); i++) - { - native_sp_level.demo.data[i] = getFile8Bit(file); - - if (native_sp_level.demo.data[i] == 0xff) /* "end of demo" byte */ - { - i++; - - break; - } - } - - native_sp_level.demo.length = i; - native_sp_level.demo.is_available = (native_sp_level.demo.length > 0); - } -} - -#endif - -#if 1 - boolean LoadNativeLevel_SP(char *filename, int level_pos, boolean level_info_only) { @@ -644,11 +474,6 @@ boolean LoadNativeLevel_SP(char *filename, int level_pos, multipart_xpos = (int)(name_first - '0'); multipart_ypos = (int)(name_last - '0'); -#if 0 - printf("----------> part (%d/%d) of multi-part level '%s'\n", - multipart_xpos, multipart_ypos, multipart_level.header.LevelTitle); -#endif - if (multipart_xpos * SP_STD_PLAYFIELD_WIDTH > SP_MAX_PLAYFIELD_WIDTH || multipart_ypos * SP_STD_PLAYFIELD_HEIGHT > SP_MAX_PLAYFIELD_HEIGHT) { @@ -693,267 +518,6 @@ boolean LoadNativeLevel_SP(char *filename, int level_pos, return TRUE; } -#else - -boolean LoadNativeLevel_SP(char *filename, int level_pos, - boolean level_info_only) -{ - FILE *file; - int i, l, x, y; - char name_first, name_last; - struct LevelInfo_SP multipart_level; - int multipart_xpos, multipart_ypos; - boolean is_multipart_level; - boolean is_first_part; - boolean reading_multipart_level = FALSE; - boolean use_empty_level = FALSE; - LevelInfoType *header = &native_sp_level.header; - boolean is_single_level_file = (strSuffixLower(filename, ".sp") || - strSuffixLower(filename, ".mpx")); - boolean demo_available = is_single_level_file; - boolean is_mpx_file = strSuffixLower(filename, ".mpx"); - int file_seek_pos = level_pos * SP_STD_LEVEL_SIZE; - int level_width = SP_STD_PLAYFIELD_WIDTH; - int level_height = SP_STD_PLAYFIELD_HEIGHT; - - /* always start with reliable default values */ - setLevelInfoToDefaults_SP(); - copyInternalEngineVars_SP(); - - if (!(file = fopen(filename, MODE_READ))) - { - if (!level_info_only) - Error(ERR_WARN, "cannot open file '%s' -- using empty level", filename); - - return FALSE; - } - - if (is_mpx_file) - { - char mpx_chunk_name[4 + 1]; - int mpx_version; - int mpx_level_count; - LevelDescriptor *mpx_level_desc; - - getFileChunkBE(file, mpx_chunk_name, NULL); - - if (!strEqual(mpx_chunk_name, "MPX ")) - { - Error(ERR_WARN, "cannot find MPX ID in file '%s' -- using empty level", - filename); - - return FALSE; - } - - mpx_version = getFile16BitLE(file); - - if (mpx_version != 1) - { - Error(ERR_WARN, "unknown MPX version in file '%s' -- using empty level", - filename); - - return FALSE; - } - - mpx_level_count = getFile16BitLE(file); - - if (mpx_level_count < 1) - { - Error(ERR_WARN, "no MPX levels found in file '%s' -- using empty level", - filename); - - return FALSE; - } - - if (level_pos >= mpx_level_count) - { - Error(ERR_WARN, "MPX level not found in file '%s' -- using empty level", - filename); - - return FALSE; - } - - mpx_level_desc = checked_calloc(mpx_level_count * sizeof(LevelDescriptor)); - - for (i = 0; i < mpx_level_count; i++) - { - LevelDescriptor *ldesc = &mpx_level_desc[i]; - - ldesc->Width = getFile16BitLE(file); - ldesc->Height = getFile16BitLE(file); - ldesc->OffSet = getFile32BitLE(file); /* starts with 1, not with 0 */ - ldesc->Size = getFile32BitLE(file); - } - - level_width = mpx_level_desc[level_pos].Width; - level_height = mpx_level_desc[level_pos].Height; - - file_seek_pos = mpx_level_desc[level_pos].OffSet - 1; - } - - /* position file stream to the requested level (in case of level package) */ - if (fseek(file, file_seek_pos, SEEK_SET) != 0) - { - Error(ERR_WARN, "cannot fseek in file '%s' -- using empty level", filename); - - return FALSE; - } - - /* there exist Supaplex level package files with multi-part levels which - can be detected as follows: instead of leading and trailing dashes ('-') - to pad the level name, they have leading and trailing numbers which are - the x and y coordinations of the current part of the multi-part level; - if there are '?' characters instead of numbers on the left or right side - of the level name, the multi-part level consists of only horizontal or - vertical parts */ - - for (l = level_pos; l < SP_NUM_LEVELS_PER_PACKAGE; l++) - { - LoadNativeLevelFromFileStream_SP(file, level_width, level_height, - demo_available); - - /* check if this level is a part of a bigger multi-part level */ - - if (is_single_level_file) - break; - - name_first = header->LevelTitle[0]; - name_last = header->LevelTitle[SP_LEVEL_NAME_LEN - 1]; - - is_multipart_level = - ((name_first == '?' || (name_first >= '0' && name_first <= '9')) && - (name_last == '?' || (name_last >= '0' && name_last <= '9'))); - - is_first_part = - ((name_first == '?' || name_first == '1') && - (name_last == '?' || name_last == '1')); - - if (is_multipart_level) - { - /* correct leading multipart level meta information in level name */ - for (i = 0; - i < SP_LEVEL_NAME_LEN && header->LevelTitle[i] == name_first; - i++) - header->LevelTitle[i] = '-'; - - /* correct trailing multipart level meta information in level name */ - for (i = SP_LEVEL_NAME_LEN - 1; - i >= 0 && header->LevelTitle[i] == name_last; - i--) - header->LevelTitle[i] = '-'; - } - - /* ---------- check for normal single level ---------- */ - - if (!reading_multipart_level && !is_multipart_level) - { - /* the current level is simply a normal single-part level, and we are - not reading a multi-part level yet, so return the level as it is */ - - break; - } - - /* ---------- check for empty level (unused multi-part) ---------- */ - - if (!reading_multipart_level && is_multipart_level && !is_first_part) - { - /* this is a part of a multi-part level, but not the first part - (and we are not already reading parts of a multi-part level); - in this case, use an empty level instead of the single part */ - - use_empty_level = TRUE; - - break; - } - - /* ---------- check for finished multi-part level ---------- */ - - if (reading_multipart_level && - (!is_multipart_level || - !strEqualN(header->LevelTitle, multipart_level.header.LevelTitle, - SP_LEVEL_NAME_LEN))) - { - /* we are already reading parts of a multi-part level, but this level is - either not a multi-part level, or a part of a different multi-part - level; in both cases, the multi-part level seems to be complete */ - - break; - } - - /* ---------- here we have one part of a multi-part level ---------- */ - - reading_multipart_level = TRUE; - - if (is_first_part) /* start with first part of new multi-part level */ - { - /* copy level info structure from first part */ - multipart_level = native_sp_level; - - /* clear playfield of new multi-part level */ - for (x = 0; x < SP_MAX_PLAYFIELD_WIDTH; x++) - for (y = 0; y < SP_MAX_PLAYFIELD_HEIGHT; y++) - multipart_level.playfield[x][y] = fiSpace; - } - - if (name_first == '?') - name_first = '1'; - if (name_last == '?') - name_last = '1'; - - multipart_xpos = (int)(name_first - '0'); - multipart_ypos = (int)(name_last - '0'); - -#if 0 - printf("----------> part (%d/%d) of multi-part level '%s'\n", - multipart_xpos, multipart_ypos, multipart_level.header.LevelTitle); -#endif - - if (multipart_xpos * SP_STD_PLAYFIELD_WIDTH > SP_MAX_PLAYFIELD_WIDTH || - multipart_ypos * SP_STD_PLAYFIELD_HEIGHT > SP_MAX_PLAYFIELD_HEIGHT) - { - Error(ERR_WARN, "multi-part level is too big -- ignoring part of it"); - - break; - } - - multipart_level.width = MAX(multipart_level.width, - multipart_xpos * SP_STD_PLAYFIELD_WIDTH); - multipart_level.height = MAX(multipart_level.height, - multipart_ypos * SP_STD_PLAYFIELD_HEIGHT); - - /* copy level part at the right position of multi-part level */ - for (x = 0; x < SP_STD_PLAYFIELD_WIDTH; x++) - { - for (y = 0; y < SP_STD_PLAYFIELD_HEIGHT; y++) - { - int start_x = (multipart_xpos - 1) * SP_STD_PLAYFIELD_WIDTH; - int start_y = (multipart_ypos - 1) * SP_STD_PLAYFIELD_HEIGHT; - - multipart_level.playfield[start_x + x][start_y + y] = - native_sp_level.playfield[x][y]; - } - } - } - - fclose(file); - - if (use_empty_level) - { - setLevelInfoToDefaults_SP(); - - Error(ERR_WARN, "single part of multi-part level -- using empty level"); - } - - if (reading_multipart_level) - native_sp_level = multipart_level; - - copyInternalEngineVars_SP(); - - return TRUE; -} - -#endif - void SaveNativeLevel_SP(char *filename) { LevelInfoType *header = &native_sp_level.header; diff --git a/src/game_sp/init.c b/src/game_sp/init.c index acd426ff..ebd6d296 100644 --- a/src/game_sp/init.c +++ b/src/game_sp/init.c @@ -130,9 +130,6 @@ void SaveEngineSnapshotValues_SP() SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FieldHeight)); SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FieldMax)); SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(LevelMax)); -#if 0 - SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(FileMax)); -#endif SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(TimerVar)); SaveEngineSnapshotBuffer(ARGS_ADDRESS_AND_SIZEOF(RandomSeed)); diff --git a/src/game_sp/main.c b/src/game_sp/main.c index 4fe06feb..4486656f 100644 --- a/src/game_sp/main.c +++ b/src/game_sp/main.c @@ -31,12 +31,10 @@ void InitGameEngine_SP() game_sp.scroll_xoffset = (EVEN(SCR_FIELDX) ? TILEX / 2 : 0); game_sp.scroll_yoffset = (EVEN(SCR_FIELDY) ? TILEY / 2 : 0); -#if 1 if (native_sp_level.width <= SCR_FIELDX) game_sp.scroll_xoffset = TILEX / 2; if (native_sp_level.height <= SCR_FIELDY) game_sp.scroll_yoffset = TILEY / 2; -#endif for (x = 0; x < SP_MAX_PLAYFIELD_WIDTH; x++) { @@ -66,20 +64,10 @@ void RedrawPlayfield_SP(boolean force_redraw) void DrawGameDoorValues_SP() { -#if 1 - // game_sp.time_played = TimerVar / FRAMES_PER_SECOND_SP; game_sp.time_played = TimerVar / FRAMES_PER_SECOND; -#else - game_sp.time_played = TimerVar * setup.game_frame_delay / 1000; -#endif game_sp.infotrons_still_needed = InfotronsNeeded; game_sp.red_disk_count = RedDiskCount; game_sp.score = 0; // (currently no score in Supaplex engine) - -#if 0 - printf("::: %d, %d => %d\n", - TimerVar, setup.game_frame_delay, game_sp.time_played); -#endif } void GameActions_SP(byte action[MAX_PLAYERS], boolean warp_mode) diff --git a/src/game_sp/main_sp.h b/src/game_sp/main_sp.h index ac239390..f34baa69 100644 --- a/src/game_sp/main_sp.h +++ b/src/game_sp/main_sp.h @@ -27,68 +27,30 @@ /* screen sizes and positions for SP engine */ -#define NEW_TILESIZE 1 - -#define ORIG_TILESIZE 16 - -#if NEW_TILESIZE -#define ZOOM_FACTOR (2 * TILESIZE_VAR / TILESIZE) -#else -#define ZOOM_FACTOR 2 -#endif - -#if NEW_TILESIZE extern int TILESIZE_VAR; + #define TILESIZE 32 #define TILEX TILESIZE #define TILEY TILESIZE #define TILEX_VAR TILESIZE_VAR #define TILEY_VAR TILESIZE_VAR -#else -#define TILESIZE (ORIG_TILESIZE * ZOOM_FACTOR) -#define TILEX TILESIZE -#define TILEY TILESIZE -#endif -#define ORIG_SCR_MENUX 20 -#define ORIG_SCR_MENUY 12 -#define SCR_MENUX 17 -#define SCR_MENUY 12 -#if 1 extern int SCR_FIELDX, SCR_FIELDY; -#else -#define SCR_FIELDX 17 -#define SCR_FIELDY 17 -#endif + #define MAX_BUF_XSIZE (2 + SCR_FIELDX + 2) #define MAX_BUF_YSIZE (2 + SCR_FIELDY + 2) /* often used screen positions */ -#if 1 + extern int SX, SY; -#else -#define SX 8 -#define SY 8 -#endif -#if NEW_TILESIZE #define SXSIZE (SCR_FIELDX * TILEX_VAR) #define SYSIZE (SCR_FIELDY * TILEY_VAR) #define FXSIZE (MAX_BUF_XSIZE * TILEX_VAR) #define FYSIZE (MAX_BUF_YSIZE * TILEY_VAR) -#else -#define SXSIZE (SCR_FIELDX * TILEX) -#define SYSIZE (SCR_FIELDY * TILEY) -#define FXSIZE (MAX_BUF_XSIZE * TILEX) -#define FYSIZE (MAX_BUF_YSIZE * TILEY) -#endif - -#if 1 + extern int REAL_SX, REAL_SY; -#else -#define REAL_SX (SX - 2) -#define REAL_SY (SY - 2) -#endif + #define FULL_SXSIZE (2 + SXSIZE + 2) #define FULL_SYSIZE (2 + SYSIZE + 2) diff --git a/src/game_sp/vb_lib.c b/src/game_sp/vb_lib.c index bdbe7691..f7b402ae 100644 --- a/src/game_sp/vb_lib.c +++ b/src/game_sp/vb_lib.c @@ -9,20 +9,6 @@ /* helper functions for constructs not supported by C */ -#if 0 -void *REDIM_1D(int data_size, int first_data_pos, int last_data_pos) -{ - /* for a buffer of n elements, first_data_pos is 0 and last_data_pos is n-1 */ - /* a negative value for "first_data_pos" indicates a preceding buffer zone */ - - int data_count = last_data_pos - first_data_pos + 1; - int buffer_size = data_size * data_count; - int buffer_start = data_size * first_data_pos; - - return (checked_calloc(buffer_size) - buffer_start); -} -#endif - int MyGetTickCount() { return random_linux_libc(RANDOM_SIMPLE); diff --git a/src/game_sp/vb_lib.h b/src/game_sp/vb_lib.h index 4f19f3a2..5c4852ce 100644 --- a/src/game_sp/vb_lib.h +++ b/src/game_sp/vb_lib.h @@ -11,10 +11,6 @@ /* helper functions for constructs not supported by C */ -#if 0 -extern void *REDIM_1D(int, int, int); -#endif - extern int MyGetTickCount(); #endif /* VB_LIB_H */ diff --git a/src/init.c b/src/init.c index bbf59514..e57e4aaf 100644 --- a/src/init.c +++ b/src/init.c @@ -102,44 +102,13 @@ void DrawInitAnim() if (!DelayReached(&action_delay, action_delay_value)) return; -#if 0 - { - static unsigned int last_counter = -1; - unsigned int current_counter = Counter(); - unsigned int delay = current_counter - last_counter; - - if (last_counter != -1 && delay > action_delay_value + 5) - printf("::: DrawInitAnim: DELAY TOO LONG: %ld\n", delay); - - last_counter = current_counter; - } -#endif - x = ALIGNED_TEXT_XPOS(&init_last.busy); y = ALIGNED_TEXT_YPOS(&init_last.busy); graphic_info = &anim_initial; /* graphic == 0 => anim_initial */ -#if 0 - { - static boolean done = FALSE; - - // if (!done) - printf("::: %d, %d, %d, %d => %d, %d [%d, %d] [%d, %d]\n", - init.busy.x, init.busy.y, - init.busy.align, init.busy.valign, - x, y, - graphic_info[graphic].width, - graphic_info[graphic].height, - sync_frame, anim_initial.anim_delay); - - done = TRUE; - } -#endif - if (sync_frame % anim_initial.anim_delay == 0) { -#if 1 Bitmap *src_bitmap; int src_x, src_y; int width = graphic_info[graphic].width; @@ -148,10 +117,6 @@ void DrawInitAnim() getFixedGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y); BlitBitmap(src_bitmap, window, src_x, src_y, width, height, x, y); -#else - /* !!! this can only draw TILEX/TILEY size animations !!! */ - DrawGraphicAnimationExt(window, x, y, graphic, sync_frame, NO_MASKING); -#endif } graphic_info = graphic_info_last; @@ -188,12 +153,6 @@ void InitGadgets() inline void InitElementSmallImagesScaledUp(int graphic) { -#if 0 - struct FileInfo *fi = getImageListEntryFromImageID(graphic); - - printf("::: '%s' -> '%s'\n", fi->token, fi->filename); -#endif - CreateImageWithSmallImages(graphic, graphic_info[graphic].scale_up_factor, graphic_info[graphic].tile_size); } @@ -276,19 +235,6 @@ static int getFontBitmapID(int font_nr) special = game_status; else if (game_status == GAME_MODE_PSEUDO_TYPENAME) special = GFX_SPECIAL_ARG_MAIN; -#if 0 - else if (game_status == GAME_MODE_PLAYING) - special = GFX_SPECIAL_ARG_DOOR; -#endif - -#if 0 - if (special != -1) - { - printf("%s%s\n", - font_info[font_nr].token_name, - special_suffix_info[special].suffix); - } -#endif if (special != -1) return font_info[font_nr].special_bitmap_id[special]; @@ -298,19 +244,10 @@ static int getFontBitmapID(int font_nr) static int getFontFromToken(char *token) { -#if 1 char *value = getHashEntry(font_token_hash, token); if (value != NULL) return atoi(value); -#else - int i; - - /* !!! OPTIMIZE THIS BY USING HASH !!! */ - for (i = 0; i < NUM_FONTS; i++) - if (strEqual(token, font_info[i].token_name)) - return i; -#endif /* if font not found, use reliable default value */ return FONT_INITIAL_1; @@ -635,16 +572,6 @@ void InitElementGraphicInfo() int graphic = property_mapping[i].artwork_index; boolean crumbled = FALSE; -#if 0 - if ((element == EL_EM_DYNAMITE || - element == EL_EM_DYNAMITE_ACTIVE) && - action == ACTION_ACTIVE && - (special == GFX_SPECIAL_ARG_EDITOR || - special == GFX_SPECIAL_ARG_PANEL)) - printf("::: DYNAMIC: %d, %d, %d -> %d\n", - element, action, special, graphic); -#endif - if (special == GFX_SPECIAL_ARG_CRUMBLED) { special = -1; @@ -717,12 +644,9 @@ void InitElementGraphicInfo() } } -#if 1 /* set hardcoded definitions for some runtime elements without graphic */ element_info[EL_AMOEBA_TO_DIAMOND].graphic[ACTION_DEFAULT] = IMG_AMOEBA_DEAD; -#endif -#if 1 /* set hardcoded definitions for some internal elements without graphic */ for (i = 0; i < MAX_NUM_ELEMENTS; i++) { @@ -731,7 +655,6 @@ void InitElementGraphicInfo() else if (IS_EDITOR_CASCADE_ACTIVE(i)) element_info[i].graphic[ACTION_DEFAULT] = IMG_EDITOR_CASCADE_LIST_ACTIVE; } -#endif /* now set all undefined/invalid graphics to -1 to set to default after it */ for (i = 0; i < MAX_NUM_ELEMENTS; i++) @@ -834,14 +757,9 @@ void InitElementGraphicInfo() if (default_graphic == -1) default_graphic = IMG_UNKNOWN; -#if 1 + if (default_crumbled == -1) default_crumbled = default_graphic; -#else - /* !!! THIS LOOKS CRAPPY FOR SAND ETC. WITHOUT CRUMBLED GRAPHICS !!! */ - if (default_crumbled == -1) - default_crumbled = IMG_EMPTY; -#endif for (dir = 0; dir < NUM_DIRECTIONS_FULL; dir++) { @@ -852,14 +770,9 @@ void InitElementGraphicInfo() if (default_direction_graphic[dir] == -1) default_direction_graphic[dir] = default_graphic; -#if 1 + if (default_direction_crumbled[dir] == -1) default_direction_crumbled[dir] = default_direction_graphic[dir]; -#else - /* !!! THIS LOOKS CRAPPY FOR SAND ETC. WITHOUT CRUMBLED GRAPHICS !!! */ - if (default_direction_crumbled[dir] == -1) - default_direction_crumbled[dir] = default_crumbled; -#endif } for (act = 0; act < NUM_ACTIONS; act++) @@ -895,7 +808,6 @@ void InitElementGraphicInfo() if (IS_SB_ELEMENT(i) && element_info[EL_SB_DEFAULT].crumbled[act] != -1) default_action_crumbled = element_info[EL_SB_DEFAULT].crumbled[act]; -#if 1 /* !!! needed because EL_EMPTY_SPACE treated as IS_SP_ELEMENT !!! */ /* !!! make this better !!! */ if (i == EL_EMPTY_SPACE) @@ -903,18 +815,12 @@ void InitElementGraphicInfo() default_action_graphic = element_info[EL_DEFAULT].graphic[act]; default_action_crumbled = element_info[EL_DEFAULT].crumbled[act]; } -#endif if (default_action_graphic == -1) default_action_graphic = default_graphic; -#if 1 + if (default_action_crumbled == -1) default_action_crumbled = default_action_graphic; -#else - /* !!! THIS LOOKS CRAPPY FOR SAND ETC. WITHOUT CRUMBLED GRAPHICS !!! */ - if (default_action_crumbled == -1) - default_action_crumbled = default_crumbled; -#endif for (dir = 0; dir < NUM_DIRECTIONS_FULL; dir++) { @@ -936,20 +842,9 @@ void InitElementGraphicInfo() element_info[i].direction_graphic[act][dir] = default_action_direction_graphic; -#if 1 if (default_action_direction_crumbled == -1) default_action_direction_crumbled = element_info[i].direction_graphic[act][dir]; -#else - if (default_action_direction_crumbled == -1) - default_action_direction_crumbled = - (act_remove ? default_remove_graphic : - act_turning ? - element_info[i].direction_crumbled[ACTION_TURNING][dir] : - default_action_crumbled != default_crumbled ? - default_action_crumbled : - default_direction_crumbled[dir]); -#endif if (element_info[i].direction_crumbled[act][dir] == -1) element_info[i].direction_crumbled[act][dir] = @@ -962,62 +857,13 @@ void InitElementGraphicInfo() (act_remove ? default_remove_graphic : act_turning ? element_info[i].graphic[ACTION_TURNING] : default_action_graphic); -#if 1 + if (element_info[i].crumbled[act] == -1) element_info[i].crumbled[act] = element_info[i].graphic[act]; -#else - if (element_info[i].crumbled[act] == -1) - element_info[i].crumbled[act] = - (act_remove ? default_remove_graphic : - act_turning ? element_info[i].crumbled[ACTION_TURNING] : - default_action_crumbled); -#endif } } UPDATE_BUSY_STATE(); - -#if 0 - /* !!! THIS ALSO CLEARS SPECIAL FLAGS (AND IS NOT NEEDED ANYWAY) !!! */ - /* set animation mode to "none" for each graphic with only 1 frame */ - for (i = 0; i < MAX_NUM_ELEMENTS; i++) - { - for (act = 0; act < NUM_ACTIONS; act++) - { - int graphic = element_info[i].graphic[act]; - int crumbled = element_info[i].crumbled[act]; - - if (graphic_info[graphic].anim_frames == 1) - graphic_info[graphic].anim_mode = ANIM_NONE; - if (graphic_info[crumbled].anim_frames == 1) - graphic_info[crumbled].anim_mode = ANIM_NONE; - - for (dir = 0; dir < NUM_DIRECTIONS_FULL; dir++) - { - graphic = element_info[i].direction_graphic[act][dir]; - crumbled = element_info[i].direction_crumbled[act][dir]; - - if (graphic_info[graphic].anim_frames == 1) - graphic_info[graphic].anim_mode = ANIM_NONE; - if (graphic_info[crumbled].anim_frames == 1) - graphic_info[crumbled].anim_mode = ANIM_NONE; - } - } - } -#endif - -#if 0 -#if DEBUG - if (options.verbose) - { - for (i = 0; i < MAX_NUM_ELEMENTS; i++) - if (element_info[i].graphic[ACTION_DEFAULT] == IMG_UNKNOWN && - i != EL_UNKNOWN) - Error(ERR_INFO, "warning: no graphic for element '%s' (%d)", - element_info[i].token_name, i); - } -#endif -#endif } void InitElementSpecialGraphicInfo() @@ -1044,15 +890,6 @@ void InitElementSpecialGraphicInfo() boolean special_redefined = getImageListEntryFromImageID(graphic)->redefined; -#if 0 - if ((element == EL_EM_DYNAMITE || - element == EL_EM_DYNAMITE_ACTIVE) && - (special == GFX_SPECIAL_ARG_EDITOR || - special == GFX_SPECIAL_ARG_PANEL)) - printf("::: SPECIAL STATIC: %d, %d -> %d\n", - element, special, graphic); -#endif - /* if the base graphic ("emerald", for example) has been redefined, but not the special graphic ("emerald.EDITOR", for example), do not use an existing (in this case considered obsolete) special graphic @@ -1072,43 +909,12 @@ void InitElementSpecialGraphicInfo() int special = property_mapping[i].ext3_index; int graphic = property_mapping[i].artwork_index; -#if 0 - if ((element == EL_EM_DYNAMITE || - element == EL_EM_DYNAMITE_ACTIVE || - element == EL_CONVEYOR_BELT_1_MIDDLE || - element == EL_CONVEYOR_BELT_1_MIDDLE_ACTIVE) && - (special == GFX_SPECIAL_ARG_EDITOR || - special == GFX_SPECIAL_ARG_PANEL)) - printf("::: SPECIAL DYNAMIC: %d, %d -> %d [%d]\n", - element, special, graphic, property_mapping[i].ext1_index); -#endif - -#if 0 - if (element == EL_CONVEYOR_BELT_1_MIDDLE && - action == ACTION_ACTIVE) - { - element = EL_CONVEYOR_BELT_1_MIDDLE_ACTIVE; - action = -1; - } -#endif - -#if 0 - if (element == EL_MAGIC_WALL && - action == ACTION_ACTIVE) - { - element = EL_MAGIC_WALL_ACTIVE; - action = -1; - } -#endif - -#if 1 /* for action ".active", replace element with active element, if exists */ if (action == ACTION_ACTIVE && element != ELEMENT_ACTIVE(element)) { element = ELEMENT_ACTIVE(element); action = -1; } -#endif if (element >= MAX_NUM_ELEMENTS) continue; @@ -1210,30 +1016,24 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, g->bitmap = src_bitmap; -#if 1 /* optional zoom factor for scaling up the image to a larger size */ if (parameter[GFX_ARG_SCALE_UP_FACTOR] != ARG_UNDEFINED_VALUE) g->scale_up_factor = parameter[GFX_ARG_SCALE_UP_FACTOR]; if (g->scale_up_factor < 1) g->scale_up_factor = 1; /* no scaling */ -#endif -#if 1 /* optional tile size for using non-standard image size */ if (parameter[GFX_ARG_TILE_SIZE] != ARG_UNDEFINED_VALUE) g->tile_size = parameter[GFX_ARG_TILE_SIZE]; if (g->tile_size < TILESIZE) g->tile_size = TILESIZE; /* standard tile size */ -#endif -#if 1 if (g->use_image_size) { /* set new default bitmap size (with scaling, but without small images) */ g->width = get_scaled_graphic_width(graphic); g->height = get_scaled_graphic_height(graphic); } -#endif /* optional x and y tile position of animation frame sequence */ if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE) @@ -1276,14 +1076,6 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, } } -#if 0 - /* optional zoom factor for scaling up the image to a larger size */ - if (parameter[GFX_ARG_SCALE_UP_FACTOR] != ARG_UNDEFINED_VALUE) - g->scale_up_factor = parameter[GFX_ARG_SCALE_UP_FACTOR]; - if (g->scale_up_factor < 1) - g->scale_up_factor = 1; /* no scaling */ -#endif - if (src_bitmap) { /* get final bitmap size (with scaling, but without small images) */ @@ -1370,10 +1162,6 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, g->anim_delay = 1; g->anim_mode = parameter[GFX_ARG_ANIM_MODE]; -#if 0 - if (g->anim_frames == 1) - g->anim_mode = ANIM_NONE; -#endif /* automatically determine correct start frame, if not defined */ if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE) @@ -1453,7 +1241,6 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, static void set_graphic_parameters(int graphic) { -#if 1 struct FileInfo *image = getImageListEntryFromImageID(graphic); char **parameter_raw = image->parameter; Bitmap *src_bitmap = getBitmapFromImageID(graphic); @@ -1472,258 +1259,6 @@ static void set_graphic_parameters(int graphic) set_graphic_parameters_ext(graphic, parameter, src_bitmap); -#else - - struct FileInfo *image = getImageListEntryFromImageID(graphic); - char **parameter_raw = image->parameter; - Bitmap *src_bitmap = getBitmapFromImageID(graphic); - int parameter[NUM_GFX_ARGS]; - int anim_frames_per_row = 1, anim_frames_per_col = 1; - int anim_frames_per_line = 1; - int i; - - /* if fallback to default artwork is done, also use the default parameters */ - if (image->fallback_to_default) - parameter_raw = image->default_parameter; - - /* get integer values from string parameters */ - for (i = 0; i < NUM_GFX_ARGS; i++) - parameter[i] = get_graphic_parameter_value(parameter_raw[i], - image_config_suffix[i].token, - image_config_suffix[i].type); - - graphic_info[graphic].bitmap = src_bitmap; - - /* always start with reliable default values */ - graphic_info[graphic].src_image_width = 0; - graphic_info[graphic].src_image_height = 0; - graphic_info[graphic].src_x = 0; - graphic_info[graphic].src_y = 0; - graphic_info[graphic].width = TILEX; /* default for element graphics */ - graphic_info[graphic].height = TILEY; /* default for element graphics */ - graphic_info[graphic].offset_x = 0; /* one or both of these values ... */ - graphic_info[graphic].offset_y = 0; /* ... will be corrected later */ - graphic_info[graphic].offset2_x = 0; /* one or both of these values ... */ - graphic_info[graphic].offset2_y = 0; /* ... will be corrected later */ - graphic_info[graphic].swap_double_tiles = -1; /* auto-detect tile swapping */ - graphic_info[graphic].crumbled_like = -1; /* do not use clone element */ - graphic_info[graphic].diggable_like = -1; /* do not use clone element */ - graphic_info[graphic].border_size = TILEX / 8; /* "CRUMBLED" border size */ - graphic_info[graphic].scale_up_factor = 1; /* default: no scaling up */ - graphic_info[graphic].clone_from = -1; /* do not use clone graphic */ - graphic_info[graphic].anim_delay_fixed = 0; - graphic_info[graphic].anim_delay_random = 0; - graphic_info[graphic].post_delay_fixed = 0; - graphic_info[graphic].post_delay_random = 0; - graphic_info[graphic].fade_mode = FADE_MODE_DEFAULT; - graphic_info[graphic].fade_delay = -1; - graphic_info[graphic].post_delay = -1; - graphic_info[graphic].auto_delay = -1; - graphic_info[graphic].align = ALIGN_CENTER; /* default for title screens */ - graphic_info[graphic].valign = VALIGN_MIDDLE; /* default for title screens */ - graphic_info[graphic].sort_priority = 0; /* default for title screens */ - -#if 1 - /* optional zoom factor for scaling up the image to a larger size */ - if (parameter[GFX_ARG_SCALE_UP_FACTOR] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].scale_up_factor = parameter[GFX_ARG_SCALE_UP_FACTOR]; - if (graphic_info[graphic].scale_up_factor < 1) - graphic_info[graphic].scale_up_factor = 1; /* no scaling */ -#endif - -#if 1 - if (graphic_info[graphic].use_image_size) - { - /* set new default bitmap size (with scaling, but without small images) */ - graphic_info[graphic].width = get_scaled_graphic_width(graphic); - graphic_info[graphic].height = get_scaled_graphic_height(graphic); - } -#endif - - /* optional x and y tile position of animation frame sequence */ - if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].src_x = parameter[GFX_ARG_XPOS] * TILEX; - if (parameter[GFX_ARG_YPOS] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].src_y = parameter[GFX_ARG_YPOS] * TILEY; - - /* optional x and y pixel position of animation frame sequence */ - if (parameter[GFX_ARG_X] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].src_x = parameter[GFX_ARG_X]; - if (parameter[GFX_ARG_Y] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].src_y = parameter[GFX_ARG_Y]; - - /* optional width and height of each animation frame */ - if (parameter[GFX_ARG_WIDTH] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].width = parameter[GFX_ARG_WIDTH]; - if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT]; - -#if 0 - /* optional zoom factor for scaling up the image to a larger size */ - if (parameter[GFX_ARG_SCALE_UP_FACTOR] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].scale_up_factor = parameter[GFX_ARG_SCALE_UP_FACTOR]; - if (graphic_info[graphic].scale_up_factor < 1) - graphic_info[graphic].scale_up_factor = 1; /* no scaling */ -#endif - - if (src_bitmap) - { - /* get final bitmap size (with scaling, but without small images) */ - int src_image_width = get_scaled_graphic_width(graphic); - int src_image_height = get_scaled_graphic_height(graphic); - - anim_frames_per_row = src_image_width / graphic_info[graphic].width; - anim_frames_per_col = src_image_height / graphic_info[graphic].height; - - graphic_info[graphic].src_image_width = src_image_width; - graphic_info[graphic].src_image_height = src_image_height; - } - - /* correct x or y offset dependent of vertical or horizontal frame order */ - if (parameter[GFX_ARG_VERTICAL]) /* frames are ordered vertically */ - { - graphic_info[graphic].offset_y = - (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ? - parameter[GFX_ARG_OFFSET] : graphic_info[graphic].height); - anim_frames_per_line = anim_frames_per_col; - } - else /* frames are ordered horizontally */ - { - graphic_info[graphic].offset_x = - (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ? - parameter[GFX_ARG_OFFSET] : graphic_info[graphic].width); - anim_frames_per_line = anim_frames_per_row; - } - - /* optionally, the x and y offset of frames can be specified directly */ - if (parameter[GFX_ARG_XOFFSET] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].offset_x = parameter[GFX_ARG_XOFFSET]; - if (parameter[GFX_ARG_YOFFSET] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].offset_y = parameter[GFX_ARG_YOFFSET]; - - /* optionally, moving animations may have separate start and end graphics */ - graphic_info[graphic].double_movement = parameter[GFX_ARG_2ND_MOVEMENT_TILE]; - - if (parameter[GFX_ARG_2ND_VERTICAL] == ARG_UNDEFINED_VALUE) - parameter[GFX_ARG_2ND_VERTICAL] = !parameter[GFX_ARG_VERTICAL]; - - /* correct x or y offset2 dependent of vertical or horizontal frame order */ - if (parameter[GFX_ARG_2ND_VERTICAL]) /* frames are ordered vertically */ - graphic_info[graphic].offset2_y = - (parameter[GFX_ARG_2ND_OFFSET] != ARG_UNDEFINED_VALUE ? - parameter[GFX_ARG_2ND_OFFSET] : graphic_info[graphic].height); - else /* frames are ordered horizontally */ - graphic_info[graphic].offset2_x = - (parameter[GFX_ARG_2ND_OFFSET] != ARG_UNDEFINED_VALUE ? - parameter[GFX_ARG_2ND_OFFSET] : graphic_info[graphic].width); - - /* optionally, the x and y offset of 2nd graphic can be specified directly */ - if (parameter[GFX_ARG_2ND_XOFFSET] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].offset2_x = parameter[GFX_ARG_2ND_XOFFSET]; - if (parameter[GFX_ARG_2ND_YOFFSET] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].offset2_y = parameter[GFX_ARG_2ND_YOFFSET]; - - /* optionally, the second movement tile can be specified as start tile */ - if (parameter[GFX_ARG_2ND_SWAP_TILES] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].swap_double_tiles= parameter[GFX_ARG_2ND_SWAP_TILES]; - - /* automatically determine correct number of frames, if not defined */ - if (parameter[GFX_ARG_FRAMES] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].anim_frames = parameter[GFX_ARG_FRAMES]; - else if (parameter[GFX_ARG_XPOS] == 0 && !parameter[GFX_ARG_VERTICAL]) - graphic_info[graphic].anim_frames = anim_frames_per_row; - else if (parameter[GFX_ARG_YPOS] == 0 && parameter[GFX_ARG_VERTICAL]) - graphic_info[graphic].anim_frames = anim_frames_per_col; - else - graphic_info[graphic].anim_frames = 1; - - if (graphic_info[graphic].anim_frames == 0) /* frames must be at least 1 */ - graphic_info[graphic].anim_frames = 1; - - graphic_info[graphic].anim_frames_per_line = - (parameter[GFX_ARG_FRAMES_PER_LINE] != ARG_UNDEFINED_VALUE ? - parameter[GFX_ARG_FRAMES_PER_LINE] : anim_frames_per_line); - - graphic_info[graphic].anim_delay = parameter[GFX_ARG_DELAY]; - if (graphic_info[graphic].anim_delay == 0) /* delay must be at least 1 */ - graphic_info[graphic].anim_delay = 1; - - graphic_info[graphic].anim_mode = parameter[GFX_ARG_ANIM_MODE]; -#if 0 - if (graphic_info[graphic].anim_frames == 1) - graphic_info[graphic].anim_mode = ANIM_NONE; -#endif - - /* automatically determine correct start frame, if not defined */ - if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE) - graphic_info[graphic].anim_start_frame = 0; - else if (graphic_info[graphic].anim_mode & ANIM_REVERSE) - graphic_info[graphic].anim_start_frame = - graphic_info[graphic].anim_frames - parameter[GFX_ARG_START_FRAME] - 1; - else - graphic_info[graphic].anim_start_frame = parameter[GFX_ARG_START_FRAME]; - - /* animation synchronized with global frame counter, not move position */ - graphic_info[graphic].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC]; - - /* optional element for cloning crumble graphics */ - if (parameter[GFX_ARG_CRUMBLED_LIKE] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].crumbled_like = parameter[GFX_ARG_CRUMBLED_LIKE]; - - /* optional element for cloning digging graphics */ - if (parameter[GFX_ARG_DIGGABLE_LIKE] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].diggable_like = parameter[GFX_ARG_DIGGABLE_LIKE]; - - /* optional border size for "crumbling" diggable graphics */ - if (parameter[GFX_ARG_BORDER_SIZE] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].border_size = parameter[GFX_ARG_BORDER_SIZE]; - - /* this is only used for player "boring" and "sleeping" actions */ - if (parameter[GFX_ARG_ANIM_DELAY_FIXED] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].anim_delay_fixed = - parameter[GFX_ARG_ANIM_DELAY_FIXED]; - if (parameter[GFX_ARG_ANIM_DELAY_RANDOM] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].anim_delay_random = - parameter[GFX_ARG_ANIM_DELAY_RANDOM]; - if (parameter[GFX_ARG_POST_DELAY_FIXED] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].post_delay_fixed = - parameter[GFX_ARG_POST_DELAY_FIXED]; - if (parameter[GFX_ARG_POST_DELAY_RANDOM] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].post_delay_random = - parameter[GFX_ARG_POST_DELAY_RANDOM]; - - /* this is only used for toon animations */ - graphic_info[graphic].step_offset = parameter[GFX_ARG_STEP_OFFSET]; - graphic_info[graphic].step_delay = parameter[GFX_ARG_STEP_DELAY]; - - /* this is only used for drawing font characters */ - graphic_info[graphic].draw_xoffset = parameter[GFX_ARG_DRAW_XOFFSET]; - graphic_info[graphic].draw_yoffset = parameter[GFX_ARG_DRAW_YOFFSET]; - - /* this is only used for drawing envelope graphics */ - graphic_info[graphic].draw_masked = parameter[GFX_ARG_DRAW_MASKED]; - - /* optional graphic for cloning all graphics settings */ - if (parameter[GFX_ARG_CLONE_FROM] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].clone_from = parameter[GFX_ARG_CLONE_FROM]; - - /* optional settings for drawing title screens and title messages */ - if (parameter[GFX_ARG_FADE_MODE] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].fade_mode = parameter[GFX_ARG_FADE_MODE]; - if (parameter[GFX_ARG_FADE_DELAY] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].fade_delay = parameter[GFX_ARG_FADE_DELAY]; - if (parameter[GFX_ARG_POST_DELAY] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].post_delay = parameter[GFX_ARG_POST_DELAY]; - if (parameter[GFX_ARG_AUTO_DELAY] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].auto_delay = parameter[GFX_ARG_AUTO_DELAY]; - if (parameter[GFX_ARG_ALIGN] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].align = parameter[GFX_ARG_ALIGN]; - if (parameter[GFX_ARG_VALIGN] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].valign = parameter[GFX_ARG_VALIGN]; - if (parameter[GFX_ARG_SORT_PRIORITY] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].sort_priority = parameter[GFX_ARG_SORT_PRIORITY]; -#endif - UPDATE_BUSY_STATE(); } @@ -1836,7 +1371,6 @@ static void InitGraphicInfo() graphic_info = checked_calloc(num_images * sizeof(struct GraphicInfo)); -#if 1 /* initialize "use_image_size" flag with default value */ for (i = 0; i < num_images; i++) graphic_info[i].use_image_size = FALSE; @@ -1844,7 +1378,6 @@ static void InitGraphicInfo() /* initialize "use_image_size" flag from static configuration above */ for (i = 0; full_size_graphics[i] != -1; i++) graphic_info[full_size_graphics[i]].use_image_size = TRUE; -#endif /* first set all graphic paramaters ... */ for (i = 0; i < num_images; i++) @@ -1881,11 +1414,9 @@ static void InitGraphicInfo() first_frame = 0; getFixedGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y); -#if 1 /* this avoids calculating wrong start position for out-of-bounds frame */ src_x = graphic_info[i].src_x; src_y = graphic_info[i].src_y; -#endif if (src_x < 0 || src_y < 0 || src_x + width > src_bitmap_width || @@ -1979,68 +1510,7 @@ static void InitGraphicCompatibilityInfo() } } -#if 1 InitGraphicCompatibilityInfo_Doors(); -#endif - -#if 0 - struct - { - int graphic; - int *width, *height; - boolean right_wing; - } - doors[] = - { - { IMG_DOOR_1_WING_LEFT, &door_1.width, &door_1.height, FALSE }, - { IMG_DOOR_1_WING_RIGHT, &door_1.width, &door_1.height, TRUE }, - { IMG_DOOR_2_WING_LEFT, &door_2.width, &door_2.height, FALSE }, - { IMG_DOOR_2_WING_RIGHT, &door_2.width, &door_2.height, TRUE }, - - { 0, NULL, NULL, FALSE } - }; - - for (i = 0; doors[i].graphic != 0; i++) - { - int graphic = doors[i].graphic; - int *width = doors[i].width; - int *height = doors[i].height; - boolean right_wing = doors[i].right_wing; - - struct FileInfo *fi = getImageListEntryFromImageID(graphic); - struct GraphicInfo *g = &graphic_info[graphic]; - - if (!fi->redefined) - { - if (*width != -1) - { - // correct start position for right wing of "standard" door graphic - if (right_wing) - g->src_x += g->width - *width; - - g->width = *width; - } - - if (*height != -1) - g->height = *height; - } - } -#endif - -#if 0 - for (i = 0; i < num_images; i++) - { - struct FileInfo *fi = getImageListEntryFromImageID(i); - - if (i == IMG_GLOBAL_DOOR) - { - printf("::: %s, %s, %d\n", - fi->default_filename, - fi->filename, - fi->redefined); - } - } -#endif } static void InitElementSoundInfo() @@ -2125,19 +1595,10 @@ static void InitElementSoundInfo() if (IS_SB_ELEMENT(i) && element_info[EL_SB_DEFAULT].sound[act] != -1) default_action_sound = element_info[EL_SB_DEFAULT].sound[act]; - /* !!! there's no such thing as a "default action sound" !!! */ -#if 0 - /* look for element specific default sound (independent from action) */ - if (element_info[i].sound[ACTION_DEFAULT] != -1) - default_action_sound = element_info[i].sound[ACTION_DEFAULT]; -#endif - -#if 1 /* !!! needed because EL_EMPTY_SPACE treated as IS_SP_ELEMENT !!! */ /* !!! make this better !!! */ if (i == EL_EMPTY_SPACE) default_action_sound = element_info[EL_DEFAULT].sound[act]; -#endif /* no sound for this specific action -- use default action sound */ if (element_info[i].sound[act] == -1) @@ -2178,12 +1639,6 @@ static void InitGameModeSoundInfo() for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++) if (menu.sound[i] == -1) menu.sound[i] = menu.sound[GAME_MODE_DEFAULT]; - -#if 0 - for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++) - if (menu.sound[i] != -1) - printf("::: menu.sound[%d] == %d\n", i, menu.sound[i]); -#endif } static void set_sound_parameters(int sound, char **parameter_raw) @@ -2233,10 +1688,6 @@ static void InitSoundInfo() sound_effect_properties[i] = ACTION_OTHER; sound_info[i].loop = FALSE; /* default: play sound only once */ -#if 0 - printf("::: sound %d: '%s'\n", i, sound->token); -#endif - /* determine all loop sounds and identify certain sound classes */ for (j = 0; element_action_info[j].suffix; j++) @@ -2299,10 +1750,6 @@ static void InitGameModeMusicInfo() int gamemode = gamemode_to_music[i].gamemode; int music = gamemode_to_music[i].music; -#if 0 - printf("::: gamemode == %d, music == %d\n", gamemode, music); -#endif - if (gamemode < 0) gamemode = GAME_MODE_DEFAULT; @@ -2317,11 +1764,6 @@ static void InitGameModeMusicInfo() int level = property_mapping[i].ext2_index; int music = property_mapping[i].artwork_index; -#if 0 - printf("::: prefix == %d, gamemode == %d, level == %d, music == %d\n", - prefix, gamemode, level, music); -#endif - if (prefix < 0 || prefix >= NUM_MUSIC_PREFIXES) continue; @@ -2353,15 +1795,6 @@ static void InitGameModeMusicInfo() for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++) if (menu.music[i] == -1) menu.music[i] = menu.music[GAME_MODE_DEFAULT]; - -#if 0 - for (i = 0; i < MAX_LEVELS; i++) - if (levelset.music[i] != -1) - printf("::: levelset.music[%d] == %d\n", i, levelset.music[i]); - for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++) - if (menu.music[i] != -1) - printf("::: menu.music[%d] == %d\n", i, menu.music[i]); -#endif } static void set_music_parameters(int music, char **parameter_raw) @@ -2421,9 +1854,7 @@ static void ReinitializeGraphics() { print_timestamp_init("ReinitializeGraphics"); -#if NEW_GAME_TILESIZE InitGfxTileSizeInfo(game.tile_size, TILESIZE); -#endif InitGraphicInfo(); /* graphic properties mapping */ print_timestamp_time("InitGraphicInfo"); @@ -2931,18 +2362,14 @@ void InitElementPropertiesStatic() EL_SWITCHGATE_OPENING, EL_SWITCHGATE_CLOSED, EL_SWITCHGATE_CLOSING, -#if 1 EL_DC_SWITCHGATE_SWITCH_UP, EL_DC_SWITCHGATE_SWITCH_DOWN, -#endif EL_TIMEGATE_OPEN, EL_TIMEGATE_OPENING, EL_TIMEGATE_CLOSED, EL_TIMEGATE_CLOSING, -#if 1 EL_DC_TIMEGATE_SWITCH, EL_DC_TIMEGATE_SWITCH_ACTIVE, -#endif EL_TUBE_ANY, EL_TUBE_VERTICAL, EL_TUBE_HORIZONTAL, @@ -3181,16 +2608,12 @@ void InitElementPropertiesStatic() EL_SOKOBAN_FIELD_EMPTY, EL_EXIT_OPEN, EL_EM_EXIT_OPEN, -#if 1 EL_EM_EXIT_OPENING, -#endif EL_SP_EXIT_OPEN, EL_SP_EXIT_OPENING, EL_STEEL_EXIT_OPEN, EL_EM_STEEL_EXIT_OPEN, -#if 1 EL_EM_STEEL_EXIT_OPENING, -#endif EL_GATE_1, EL_GATE_2, EL_GATE_3, @@ -4861,15 +4284,9 @@ void InitElementPropertiesEngine(int engine_version) HAS_ACTION(i))); /* ---------- GFX_CRUMBLED --------------------------------------------- */ -#if 1 SET_PROPERTY(i, EP_GFX_CRUMBLED, element_info[i].crumbled[ACTION_DEFAULT] != element_info[i].graphic[ACTION_DEFAULT]); -#else - /* !!! THIS LOOKS CRAPPY FOR SAND ETC. WITHOUT CRUMBLED GRAPHICS !!! */ - SET_PROPERTY(i, EP_GFX_CRUMBLED, - element_info[i].crumbled[ACTION_DEFAULT] != IMG_EMPTY); -#endif /* ---------- EDITOR_CASCADE ------------------------------------------- */ SET_PROPERTY(i, EP_EDITOR_CASCADE, (IS_EDITOR_CASCADE_ACTIVE(i) || @@ -4967,10 +4384,6 @@ static void InitGlobal() element_info[i].token_name = element_name_info[i].token_name; element_info[i].class_name = element_name_info[i].class_name; element_info[i].editor_description= element_name_info[i].editor_description; - -#if 0 - printf("%04d: %s\n", i, element_name_info[i].token_name); -#endif } /* create hash from image config list */ @@ -5053,10 +4466,6 @@ static void InitGlobal() global.fps_slowdown_factor = 1; global.border_status = GAME_MODE_MAIN; -#if 0 - global.fading_status = GAME_MODE_MAIN; - global.fading_type = TYPE_ENTER_MENU; -#endif global.use_envelope_request = FALSE; } @@ -5386,28 +4795,6 @@ static char *get_level_id_suffix(int id_nr) return id_suffix; } -#if 0 -static char *get_element_class_token(int element) -{ - char *element_class_name = element_info[element].class_name; - char *element_class_token = checked_malloc(strlen(element_class_name) + 3); - - sprintf(element_class_token, "[%s]", element_class_name); - - return element_class_token; -} - -static char *get_action_class_token(int action) -{ - char *action_class_name = &element_action_info[action].suffix[1]; - char *action_class_token = checked_malloc(strlen(action_class_name) + 3); - - sprintf(action_class_token, "[%s]", action_class_name); - - return action_class_token; -} -#endif - static void InitArtworkConfig() { static char *image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS + 1]; @@ -5525,9 +4912,6 @@ void InitGfxBuffers() ReCreateBitmap(&bitmap_db_cross, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH); ReCreateBitmap(&bitmap_db_field, FXSIZE, FYSIZE, DEFAULT_DEPTH); ReCreateBitmap(&bitmap_db_panel, DXSIZE, DYSIZE, DEFAULT_DEPTH); -#if 0 - ReCreateBitmap(&bitmap_db_door, 3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH); -#endif ReCreateBitmap(&bitmap_db_door_1, 3 * DXSIZE, DYSIZE, DEFAULT_DEPTH); ReCreateBitmap(&bitmap_db_door_2, 3 * VXSIZE, VYSIZE, DEFAULT_DEPTH); ReCreateBitmap(&bitmap_db_toons, FULL_SXSIZE, FULL_SYSIZE, DEFAULT_DEPTH); @@ -5605,30 +4989,19 @@ void InitGfx() font_height = getFontHeight(FC_RED); -#if 0 - DrawInitTextAlways(getWindowTitleString(), 20, FC_YELLOW); -#else DrawInitTextAlways(getProgramInitString(), 20, FC_YELLOW); -#endif DrawInitTextAlways(PROGRAM_COPYRIGHT_STRING, 50, FC_RED); DrawInitTextAlways(PROGRAM_WEBSITE_STRING, WIN_YSIZE - 20 - font_height, FC_RED); DrawInitTextAlways("Loading graphics", 120, FC_GREEN); -#if 1 -#if 1 /* initialize busy animation with default values */ int parameter[NUM_GFX_ARGS]; for (i = 0; i < NUM_GFX_ARGS; i++) parameter[i] = get_graphic_parameter_value(image_config_suffix[i].value, image_config_suffix[i].token, image_config_suffix[i].type); -#if 0 - for (i = 0; i < NUM_GFX_ARGS; i++) - printf("::: '%s' => %d\n", image_config_suffix[i].token, parameter[i]); -#endif -#endif /* determine settings for busy animation (when displaying startup messages) */ for (i = 0; image_config[i].token != NULL; i++) @@ -5641,7 +5014,6 @@ void InitGfx() else if (strlen(image_config[i].token) > len_anim_token && strncmp(image_config[i].token, anim_token, len_anim_token) == 0) { -#if 1 for (j = 0; image_config_suffix[j].token != NULL; j++) { if (strEqual(&image_config[i].token[len_anim_token], @@ -5651,23 +5023,6 @@ void InitGfx() image_config_suffix[j].token, image_config_suffix[j].type); } -#else - if (strEqual(&image_config[i].token[len_anim_token], ".x")) - anim_initial.src_x = atoi(image_config[i].value); - else if (strEqual(&image_config[i].token[len_anim_token], ".y")) - anim_initial.src_y = atoi(image_config[i].value); - else if (strEqual(&image_config[i].token[len_anim_token], ".width")) - anim_initial.width = atoi(image_config[i].value); - else if (strEqual(&image_config[i].token[len_anim_token], ".height")) - anim_initial.height = atoi(image_config[i].value); - else if (strEqual(&image_config[i].token[len_anim_token], ".frames")) - anim_initial.anim_frames = atoi(image_config[i].value); - else if (strEqual(&image_config[i].token[len_anim_token], - ".frames_per_line")) - anim_initial.anim_frames_per_line = atoi(image_config[i].value); - else if (strEqual(&image_config[i].token[len_anim_token], ".delay")) - anim_initial.anim_delay = atoi(image_config[i].value); -#endif } } @@ -5692,15 +5047,6 @@ void InitGfx() set_graphic_parameters_ext(0, parameter, anim_initial.bitmap); -#if 0 - printf("::: INIT_GFX: anim_frames_per_line == %d [%d / %d] [%d, %d]\n", - graphic_info[0].anim_frames_per_line, - get_scaled_graphic_width(0), - graphic_info[0].width, - getOriginalImageWidthFromImageID(0), - graphic_info[0].scale_up_factor); -#endif - graphic_info = graphic_info_last; init.busy.width = anim_initial.width; @@ -5711,7 +5057,6 @@ void InitGfx() /* use copy of busy animation to prevent change while reloading artwork */ init_last = init; -#endif } void RedrawBackground() @@ -5729,14 +5074,7 @@ void InitGfxBackground() fieldbuffer = bitmap_db_field; SetDrawtoField(DRAW_BACKBUFFER); -#if 1 ClearRectangle(backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE); -#else - RedrawBackground(); - - ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); - ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE); -#endif for (x = 0; x < MAX_BUF_XSIZE; x++) for (y = 0; y < MAX_BUF_YSIZE; y++) @@ -6005,19 +5343,11 @@ static char *getNewArtworkIdentifier(int type) static boolean last_has_level_artwork_set[3] = { FALSE, FALSE, FALSE }; static boolean initialized[3] = { FALSE, FALSE, FALSE }; TreeInfo *artwork_first_node = ARTWORK_FIRST_NODE(artwork, type); -#if 1 boolean setup_override_artwork = GFX_OVERRIDE_ARTWORK(type); -#else - boolean setup_override_artwork = SETUP_OVERRIDE_ARTWORK(setup, type); -#endif char *setup_artwork_set = SETUP_ARTWORK_SET(setup, type); char *leveldir_identifier = leveldir_current->identifier; -#if 1 /* !!! setLevelArtworkDir() should be moved to an earlier stage !!! */ char *leveldir_artwork_set = setLevelArtworkDir(artwork_first_node); -#else - char *leveldir_artwork_set = LEVELDIR_ARTWORK_SET(leveldir_current, type); -#endif boolean has_level_artwork_set = (leveldir_artwork_set != NULL); char *artwork_current_identifier; char *artwork_new_identifier = NULL; /* default: nothing has changed */ @@ -6047,16 +5377,6 @@ static char *getNewArtworkIdentifier(int type) /* 2nd step: check if it is really needed to reload artwork set ------------------------------------------------------------ */ -#if 0 - if (type == ARTWORK_TYPE_GRAPHICS) - printf("::: 0: '%s' ['%s', '%s'] ['%s' ('%s')]\n", - artwork_new_identifier, - ARTWORK_CURRENT_IDENTIFIER(artwork, type), - artwork_current_identifier, - leveldir_current->graphics_set, - leveldir_current->identifier); -#endif - /* ---------- reload if level set and also artwork set has changed ------- */ if (leveldir_current_identifier[type] != leveldir_identifier && (last_has_level_artwork_set[type] || has_level_artwork_set)) @@ -6065,22 +5385,12 @@ static char *getNewArtworkIdentifier(int type) leveldir_current_identifier[type] = leveldir_identifier; last_has_level_artwork_set[type] = has_level_artwork_set; -#if 0 - if (type == ARTWORK_TYPE_GRAPHICS) - printf("::: 1: '%s'\n", artwork_new_identifier); -#endif - /* ---------- reload if "override artwork" setting has changed ----------- */ if (last_override_level_artwork[type] != setup_override_artwork) artwork_new_identifier = artwork_current_identifier; last_override_level_artwork[type] = setup_override_artwork; -#if 0 - if (type == ARTWORK_TYPE_GRAPHICS) - printf("::: 2: '%s'\n", artwork_new_identifier); -#endif - /* ---------- reload if current artwork identifier has changed ----------- */ if (!strEqual(ARTWORK_CURRENT_IDENTIFIER(artwork, type), artwork_current_identifier)) @@ -6088,30 +5398,12 @@ static char *getNewArtworkIdentifier(int type) *(ARTWORK_CURRENT_IDENTIFIER_PTR(artwork, type))= artwork_current_identifier; -#if 0 - if (type == ARTWORK_TYPE_GRAPHICS) - printf("::: 3: '%s'\n", artwork_new_identifier); -#endif - /* ---------- do not reload directly after starting ---------------------- */ if (!initialized[type]) artwork_new_identifier = NULL; initialized[type] = TRUE; -#if 0 - if (type == ARTWORK_TYPE_GRAPHICS) - printf("::: 4: '%s'\n", artwork_new_identifier); -#endif - -#if 0 - if (type == ARTWORK_TYPE_GRAPHICS) - printf("CHECKING OLD/NEW GFX:\n- OLD: %s\n- NEW: %s ['%s', '%s'] ['%s']\n", - artwork.gfx_current_identifier, artwork_current_identifier, - artwork.gfx_current->identifier, leveldir_current->graphics_set, - artwork_new_identifier); -#endif - return artwork_new_identifier; } @@ -6147,20 +5439,10 @@ void ReloadCustomArtwork(int force_reload) FadeOut(REDRAW_ALL); -#if 1 ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE); -#else - ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE); -#endif print_timestamp_time("ClearRectangle"); -#if 0 - printf("::: fading in ... %d\n", fading.fade_mode); -#endif FadeIn(REDRAW_ALL); -#if 0 - printf("::: done\n"); -#endif if (gfx_new_identifier != NULL || force_reload_gfx) { @@ -6192,18 +5474,7 @@ void ReloadCustomArtwork(int force_reload) init_last = init; /* switch to new busy animation */ -#if 0 - printf("::: ----------------DELAY 1 ...\n"); - Delay(3000); -#endif - -#if 0 - printf("::: FadeOut @ ReloadCustomArtwork ...\n"); -#endif FadeOut(REDRAW_ALL); -#if 0 - printf("::: FadeOut @ ReloadCustomArtwork done\n"); -#endif RedrawBackground(); @@ -6211,23 +5482,8 @@ void ReloadCustomArtwork(int force_reload) SetDoorState(DOOR_OPEN_ALL); CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY); -#if 1 -#if 1 -#if 1 FadeSetEnterScreen(); FadeSkipNextFadeOut(); - // FadeSetDisabled(); -#else - FadeSkipNext(); -#endif -#else - fading = fading_none; -#endif -#endif - -#if 0 - redraw_mask = REDRAW_ALL; -#endif print_timestamp_done("ReloadCustomArtwork"); @@ -6308,9 +5564,7 @@ void OpenAll() game_status = GAME_MODE_LOADING; -#if 1 InitCounter(); -#endif InitGlobal(); /* initialize some global variables */ @@ -6345,10 +5599,6 @@ void OpenAll() InitMixer(); print_timestamp_time("[init setup/config stuff (6)]"); -#if 0 - InitCounter(); -#endif - InitRND(NEW_RANDOMIZE); InitSimpleRandom(NEW_RANDOMIZE); @@ -6393,13 +5643,8 @@ void OpenAll() InitGfxBackground(); -#if 1 em_open_all(); -#endif - -#if 1 sp_open_all(); -#endif if (global.autoplay_leveldir) { @@ -6419,14 +5664,9 @@ void OpenAll() game_status = GAME_MODE_MAIN; -#if 1 FadeSetEnterScreen(); if (!(fading.fade_mode & FADE_TYPE_TRANSFORM)) FadeSkipNextFadeOut(); - // FadeSetDisabled(); -#else - fading = fading_none; -#endif print_timestamp_time("[post-artwork]"); @@ -6462,13 +5702,8 @@ void CloseAllAndExit(int exit_value) FreeAllMusic(); CloseAudio(); /* called after freeing sounds (needed for SDL) */ -#if 1 em_close_all(); -#endif - -#if 1 sp_close_all(); -#endif FreeAllImages(); diff --git a/src/libgame/gadgets.c b/src/libgame/gadgets.c index 9c07371b..9c974b87 100644 --- a/src/libgame/gadgets.c +++ b/src/libgame/gadgets.c @@ -382,16 +382,9 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) gi->height - 2 * border_y); /* gadget text value */ -#if 1 DrawTextBuffer(gi->x + border_x, gi->y + border_y, gi->textarea.value, font_nr, gi->textarea.xsize, -1, gi->textarea.ysize, 0, BLIT_ON_BACKGROUND, FALSE, FALSE, FALSE); -#else - DrawTextToTextArea(gi->x + border_x, gi->y + border_y, - gi->textarea.value, font_nr, gi->textarea.xsize, - gi->textarea.xsize, gi->textarea.ysize, - BLIT_ON_BACKGROUND); -#endif cursor_letter = gi->textarea.value[gi->textarea.cursor_position]; cursor_string[0] = (cursor_letter != '\0' ? cursor_letter : ' '); @@ -708,7 +701,6 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) } else { -#if 1 int x = gi->x; int y = gi->y; @@ -716,11 +708,6 @@ static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct) IN_GFX_DOOR_1(x, y) ? REDRAW_DOOR_1 : IN_GFX_DOOR_2(x, y) ? REDRAW_DOOR_2 : IN_GFX_DOOR_3(x, y) ? REDRAW_DOOR_3 : REDRAW_ALL); -#else - redraw_mask |= (gi->x < gfx.sx + gfx.sxsize ? REDRAW_FIELD : - gi->y < gfx.dy + gfx.dysize ? REDRAW_DOOR_1 : - gi->y > gfx.vy ? REDRAW_DOOR_2 : REDRAW_DOOR_3); -#endif } } @@ -1354,7 +1341,6 @@ static void MultiMapGadgets(int mode) while (gi != NULL) { -#if 1 int x = gi->x; int y = gi->y; @@ -1363,15 +1349,6 @@ static void MultiMapGadgets(int mode) (mode & MULTIMAP_DOOR_2 && IN_GFX_DOOR_2(x, y)) || (mode & MULTIMAP_DOOR_3 && IN_GFX_DOOR_3(x, y)) || (mode & MULTIMAP_ALL) == MULTIMAP_ALL) -#else - if ((mode & MULTIMAP_PLAYFIELD && - gi->x < gfx.sx + gfx.sxsize) || - (mode & MULTIMAP_DOOR_1 && - gi->x >= gfx.dx && gi->y < gfx.dy + gfx.dysize) || - (mode & MULTIMAP_DOOR_2 && - gi->x >= gfx.dx && gi->y > gfx.dy + gfx.dysize) || - (mode & MULTIMAP_ALL) == MULTIMAP_ALL) -#endif { if (mode & MULTIMAP_UNMAP) { @@ -1487,9 +1464,6 @@ boolean HandleGadgets(int mx, int my, int button) boolean gadget_dragging; boolean gadget_released; boolean gadget_released_inside; -#if 0 - boolean gadget_released_inside_select_line; -#endif boolean gadget_released_inside_select_area; boolean gadget_released_off_borders; boolean changed_position = FALSE; @@ -1591,19 +1565,9 @@ boolean HandleGadgets(int mx, int my, int button) /* when handling selectbox, set additional state values */ if (gadget_released_inside && (last_gi->type & GD_TYPE_SELECTBOX)) - { -#if 0 - gadget_released_inside_select_line = insideSelectboxLine(last_gi, mx, my); -#endif gadget_released_inside_select_area = insideSelectboxArea(last_gi, mx, my); - } else - { -#if 0 - gadget_released_inside_select_line = FALSE; -#endif gadget_released_inside_select_area = FALSE; - } /* setting state for handling over-large selectbox */ if (keep_selectbox_open && (press_event || !mouse_inside_select_line)) diff --git a/src/libgame/image.c b/src/libgame/image.c index 885905d2..4546d436 100644 --- a/src/libgame/image.c +++ b/src/libgame/image.c @@ -31,18 +31,10 @@ typedef struct ImageInfo ImageInfo; static struct ArtworkListInfo *image_info = NULL; -#if 1 static void *Load_Image(char *filename) -#else -static void *Load_PCX(char *filename) -#endif { ImageInfo *img_info; -#if 0 - printf("::: loading PCX file '%s'\n", filename); -#endif - img_info = checked_calloc(sizeof(ImageInfo)); if ((img_info->bitmap = LoadImage(filename)) == NULL) @@ -233,20 +225,12 @@ void InitImageList(struct ConfigInfo *config_list, int num_file_list_entries, /* ---------- initialize artwork loading/freeing functions ---------- */ -#if 1 image_info->load_artwork = Load_Image; -#else - image_info->load_artwork = Load_PCX; -#endif image_info->free_artwork = FreeImage; } void ReloadCustomImages() { -#if 0 - printf("::: reloading images '%s' ...\n", artwork.gfx_current_identifier); -#endif - print_timestamp_init("ReloadCustomImages"); LoadArtworkConfig(image_info); diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 8a7c94d6..78dddf8a 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -224,14 +224,10 @@ boolean getTokenValueFromString(char *string, char **token, char **value) /* maximal allowed length of a command line option */ #define MAX_OPTION_LEN 256 -#if 1 - -#if defined(TARGET_SDL) static unsigned int getCurrentMS() { return SDL_GetTicks(); } -#endif static unsigned int mainCounter(int mode) { @@ -249,29 +245,6 @@ static unsigned int mainCounter(int mode) return current_ms - base_ms; } -#else - -#if defined(TARGET_SDL) -static unsigned int mainCounter(int mode) -{ - static unsigned int base_ms = 0; - unsigned int current_ms; - unsigned int counter_ms; - - current_ms = SDL_GetTicks(); - - /* reset base time in case of counter initializing or wrap-around */ - if (mode == INIT_COUNTER || current_ms < base_ms) - base_ms = current_ms; - - counter_ms = current_ms - base_ms; - - return counter_ms; /* return milliseconds since last init */ -} -#endif - -#endif - void InitCounter() /* set counter back to zero */ { mainCounter(INIT_COUNTER); @@ -301,17 +274,7 @@ static void sleep_milliseconds(unsigned int milliseconds_delay) } else { -#if defined(TARGET_SDL) SDL_Delay(milliseconds_delay); -#else - struct timeval delay; - - delay.tv_sec = milliseconds_delay / 1000; - delay.tv_usec = 1000 * (milliseconds_delay % 1000); - - if (select(0, NULL, NULL, NULL, &delay) != 0) - Error(ERR_WARN, "sleep_milliseconds(): select() failed"); -#endif } } @@ -387,15 +350,11 @@ unsigned int init_random_number(int nr, int seed) seed += (int)current_time.tv_usec; // microseconds since the epoch #endif -#if defined(TARGET_SDL) /* add some more randomness */ seed += (int)SDL_GetTicks(); // milliseconds since SDL init -#endif -#if 1 /* add some more randomness */ seed += GetSimpleRandom(1000000); -#endif } srandom_linux_libc(nr, (unsigned int) seed); @@ -771,7 +730,6 @@ void GetOptions(char *argv[], char *rw_base_path = RW_BASE_PATH; char **options_left = &argv[1]; -#if 1 /* if the program is configured to start from current directory (default), determine program package directory from program binary (some versions of KDE/Konqueror and Mac OS X (especially "Mavericks") apparently do not @@ -781,22 +739,6 @@ void GetOptions(char *argv[], ro_base_path = getProgramMainDataPath(); if (strEqual(rw_base_path, ".")) rw_base_path = getProgramMainDataPath(); -#else - -#if !defined(PLATFORM_MACOSX) - /* if the program is configured to start from current directory (default), - determine program package directory (KDE/Konqueror does not do this by - itself and fails otherwise); on Mac OS X, the program binary is stored - in an application package directory -- do not try to use this directory - as the program data directory (Mac OS X handles this correctly anyway) */ - - if (strEqual(ro_base_path, ".")) - ro_base_path = program.command_basepath; - if (strEqual(rw_base_path, ".")) - rw_base_path = program.command_basepath; -#endif - -#endif /* initialize global program options */ options.display_name = NULL; @@ -963,22 +905,7 @@ void GetOptions(char *argv[], } else if (strPrefix(option, "-D")) { -#if 1 options.special_flags = getStringCopy(&option[2]); -#else - char *flags_string = &option[2]; - unsigned int flags_value; - - if (*flags_string == '\0') - Error(ERR_EXIT_HELP, "empty flag ignored"); - - flags_value = get_special_flags_function(flags_string); - - if (flags_value == 0) - Error(ERR_EXIT_HELP, "unknown flag '%s'", flags_string); - - options.special_flags |= flags_value; -#endif } else if (strncmp(option, "-execute", option_len) == 0) { @@ -1050,11 +977,9 @@ void Error(int mode, char *format, ...) ANDROID_LOG_UNKNOWN); #endif -#if 1 /* display warnings only when running in verbose mode */ if (mode & ERR_WARN && !options.verbose) return; -#endif if (mode == ERR_INFO_LINE) { @@ -1204,22 +1129,11 @@ inline void swap_number_pairs(int *x1, int *y1, int *x2, int *y2) of the (not yet written) chunk, write the correct chunk size and finally write the chunk itself */ -#if 1 - int getFile8BitInteger(File *file) { return getByteFromFile(file); } -#else - -int getFile8BitInteger(FILE *file) -{ - return fgetc(file); -} - -#endif - int putFile8BitInteger(FILE *file, int value) { if (file != NULL) @@ -1228,8 +1142,6 @@ int putFile8BitInteger(FILE *file, int value) return 1; } -#if 1 - int getFile16BitInteger(File *file, int byte_order) { if (byte_order == BYTE_ORDER_BIG_ENDIAN) @@ -1240,20 +1152,6 @@ int getFile16BitInteger(File *file, int byte_order) (getByteFromFile(file) << 8)); } -#else - -int getFile16BitInteger(FILE *file, int byte_order) -{ - if (byte_order == BYTE_ORDER_BIG_ENDIAN) - return ((fgetc(file) << 8) | - (fgetc(file) << 0)); - else /* BYTE_ORDER_LITTLE_ENDIAN */ - return ((fgetc(file) << 0) | - (fgetc(file) << 8)); -} - -#endif - int putFile16BitInteger(FILE *file, int value, int byte_order) { if (file != NULL) @@ -1273,8 +1171,6 @@ int putFile16BitInteger(FILE *file, int value, int byte_order) return 2; } -#if 1 - int getFile32BitInteger(File *file, int byte_order) { if (byte_order == BYTE_ORDER_BIG_ENDIAN) @@ -1289,24 +1185,6 @@ int getFile32BitInteger(File *file, int byte_order) (getByteFromFile(file) << 24)); } -#else - -int getFile32BitInteger(FILE *file, int byte_order) -{ - if (byte_order == BYTE_ORDER_BIG_ENDIAN) - return ((fgetc(file) << 24) | - (fgetc(file) << 16) | - (fgetc(file) << 8) | - (fgetc(file) << 0)); - else /* BYTE_ORDER_LITTLE_ENDIAN */ - return ((fgetc(file) << 0) | - (fgetc(file) << 8) | - (fgetc(file) << 16) | - (fgetc(file) << 24)); -} - -#endif - int putFile32BitInteger(FILE *file, int value, int byte_order) { if (file != NULL) @@ -1330,8 +1208,6 @@ int putFile32BitInteger(FILE *file, int value, int byte_order) return 4; } -#if 1 - boolean getFileChunk(File *file, char *chunk_name, int *chunk_size, int byte_order) { @@ -1350,28 +1226,6 @@ boolean getFileChunk(File *file, char *chunk_name, int *chunk_size, return (checkEndOfFile(file) ? FALSE : TRUE); } -#else - -boolean getFileChunk(FILE *file, char *chunk_name, int *chunk_size, - int byte_order) -{ - const int chunk_name_length = 4; - - /* read chunk name */ - if (fgets(chunk_name, chunk_name_length + 1, file) == NULL) - return FALSE; - - if (chunk_size != NULL) - { - /* read chunk size */ - *chunk_size = getFile32BitInteger(file, byte_order); - } - - return (feof(file) || ferror(file) ? FALSE : TRUE); -} - -#endif - int putFileChunk(FILE *file, char *chunk_name, int chunk_size, int byte_order) { @@ -1395,8 +1249,6 @@ int putFileChunk(FILE *file, char *chunk_name, int chunk_size, return num_bytes; } -#if 1 - int getFileVersion(File *file) { int version_major = getByteFromFile(file); @@ -1408,21 +1260,6 @@ int getFileVersion(File *file) version_build); } -#else - -int getFileVersion(FILE *file) -{ - int version_major = fgetc(file); - int version_minor = fgetc(file); - int version_patch = fgetc(file); - int version_build = fgetc(file); - - return VERSION_IDENT(version_major, version_minor, version_patch, - version_build); -} - -#endif - int putFileVersion(FILE *file, int version) { if (file != NULL) @@ -1441,8 +1278,6 @@ int putFileVersion(FILE *file, int version) return 4; } -#if 1 - void ReadBytesFromFile(File *file, byte *buffer, unsigned int bytes) { int i; @@ -1451,18 +1286,6 @@ void ReadBytesFromFile(File *file, byte *buffer, unsigned int bytes) buffer[i] = getByteFromFile(file); } -#else - -void ReadBytesFromFile(FILE *file, byte *buffer, unsigned int bytes) -{ - int i; - - for(i = 0; i < bytes && !feof(file); i++) - buffer[i] = fgetc(file); -} - -#endif - void WriteBytesToFile(FILE *file, byte *buffer, unsigned int bytes) { int i; @@ -1471,24 +1294,12 @@ void WriteBytesToFile(FILE *file, byte *buffer, unsigned int bytes) fputc(buffer[i], file); } -#if 1 - void ReadUnusedBytesFromFile(File *file, unsigned int bytes) { while (bytes-- && !checkEndOfFile(file)) getByteFromFile(file); } -#else - -void ReadUnusedBytesFromFile(FILE *file, unsigned int bytes) -{ - while (bytes-- && !feof(file)) - fgetc(file); -} - -#endif - void WriteUnusedBytesToFile(FILE *file, unsigned int bytes) { while (bytes--) @@ -2342,12 +2153,6 @@ DirectoryEntry *readDirectory(Directory *dir) (stat(dir->dir_entry->filename, &file_status) == 0 && (file_status.st_mode & S_IFMT) == S_IFDIR); -#if 0 - Error(ERR_INFO, "::: '%s' is directory: %d", - dir->dir_entry->basename, - dir->dir_entry->is_directory); -#endif - return dir->dir_entry; } @@ -2459,7 +2264,6 @@ boolean fileHasSuffix(char *basename, char *suffix) return FALSE; } -#if defined(TARGET_SDL) static boolean FileCouldBeArtwork(char *basename) { return (!strEqual(basename, ".") && @@ -2467,57 +2271,26 @@ static boolean FileCouldBeArtwork(char *basename) !fileHasSuffix(basename, "txt") && !fileHasSuffix(basename, "conf")); } -#endif boolean FileIsGraphic(char *filename) { char *basename = getBaseNamePtr(filename); -#if defined(TARGET_SDL) return FileCouldBeArtwork(basename); -#else - return fileHasSuffix(basename, "pcx"); -#endif } boolean FileIsSound(char *filename) { char *basename = getBaseNamePtr(filename); -#if defined(TARGET_SDL) return FileCouldBeArtwork(basename); -#else - return fileHasSuffix(basename, "wav"); -#endif } boolean FileIsMusic(char *filename) { char *basename = getBaseNamePtr(filename); -#if defined(TARGET_SDL) return FileCouldBeArtwork(basename); -#else - if (FileIsSound(basename)) - return TRUE; - -#if 0 -#if defined(TARGET_SDL) - if ((fileHasPrefix(basename, "mod") && !fileHasSuffix(basename, "txt")) || - fileHasSuffix(basename, "mod") || - fileHasSuffix(basename, "s3m") || - fileHasSuffix(basename, "it") || - fileHasSuffix(basename, "xm") || - fileHasSuffix(basename, "midi") || - fileHasSuffix(basename, "mid") || - fileHasSuffix(basename, "mp3") || - fileHasSuffix(basename, "ogg")) - return TRUE; -#endif -#endif - - return FALSE; -#endif } boolean FileIsArtworkType(char *basename, int type) @@ -2665,11 +2438,7 @@ int get_parameter_value(char *value_raw, char *suffix, int type) string_has_parameter(value, "melt") ? FADE_MODE_MELT : FADE_MODE_DEFAULT); } -#if 1 else if (strPrefix(suffix, ".font")) /* (may also be ".font_xyz") */ -#else - else if (strEqualN(suffix, ".font", 5)) /* (may also be ".font_xyz") */ -#endif { result = gfx.get_font_from_token_function(value); } @@ -2779,9 +2548,6 @@ struct FileInfo *getFileListFromConfigList(struct ConfigInfo *config_list, for (i = 0; config_list[i].token != NULL; i++) { int len_config_token = strlen(config_list[i].token); -#if 0 - int len_config_value = strlen(config_list[i].value); -#endif boolean is_file_entry = TRUE; for (j = 0; suffix_list[j].token != NULL; j++) @@ -2814,24 +2580,8 @@ struct FileInfo *getFileListFromConfigList(struct ConfigInfo *config_list, if (list_pos >= num_file_list_entries) break; -#if 0 - /* simple sanity check if this is really a file definition */ - if (!strEqual(&config_list[i].value[len_config_value - 4], ".pcx") && - !strEqual(&config_list[i].value[len_config_value - 4], ".wav") && - !strEqual(config_list[i].value, UNDEFINED_FILENAME)) - { - Error(ERR_INFO, "Configuration directive '%s' -> '%s':", - config_list[i].token, config_list[i].value); - Error(ERR_EXIT, "This seems to be no valid definition -- please fix"); - } -#endif - file_list[list_pos].token = config_list[i].token; file_list[list_pos].default_filename = config_list[i].value; - -#if 0 - printf("::: '%s' => '%s'\n", config_list[i].token, config_list[i].value); -#endif } if (strSuffix(config_list[i].token, ".clone_from")) @@ -2850,10 +2600,6 @@ struct FileInfo *getFileListFromConfigList(struct ConfigInfo *config_list, Error(ERR_EXIT, "please fix"); } -#if 0 - printf("::: ---------- DONE ----------\n"); -#endif - return file_list; } @@ -2995,10 +2741,6 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, if (filename == NULL) return; -#if 0 - printf("LoadArtworkConfigFromFilename '%s' ...\n", filename); -#endif - if ((setup_file_hash = loadSetupFileHash(filename)) == NULL) return; @@ -3081,10 +2823,6 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, boolean base_prefix_found = FALSE; boolean parameter_suffix_found = FALSE; -#if 0 - printf("::: examining '%s' -> '%s'\n", token, HASH_ITERATION_VALUE(itr)); -#endif - /* skip all parameter definitions (handled by read_token_parameters()) */ for (i = 0; i < num_suffix_list_entries && !parameter_suffix_found; i++) { @@ -3120,20 +2858,10 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, base_index = i; -#if 0 - if (IS_PARENT_PROCESS()) - printf("===> MATCH: '%s', '%s'\n", token, base_prefix); -#endif - if (start_pos + len_base_prefix == len_token) /* exact match */ { exact_match = TRUE; -#if 0 - if (IS_PARENT_PROCESS()) - printf("===> EXACT MATCH: '%s', '%s'\n", token, base_prefix); -#endif - add_dynamic_file_list_entry(dynamic_file_list, num_dynamic_file_list_entries, extra_file_hash, @@ -3147,11 +2875,6 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, continue; } -#if 0 - if (IS_PARENT_PROCESS()) - printf("---> examining token '%s': search 1st suffix ...\n", token); -#endif - /* ---------- step 1: search for matching first suffix ---------- */ start_pos += len_base_prefix; @@ -3167,20 +2890,10 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, ext1_index = j; -#if 0 - if (IS_PARENT_PROCESS()) - printf("===> MATCH: '%s', '%s'\n", token, ext1_suffix); -#endif - if (start_pos + len_ext1_suffix == len_token) /* exact match */ { exact_match = TRUE; -#if 0 - if (IS_PARENT_PROCESS()) - printf("===> EXACT MATCH: '%s', '%s'\n", token, ext1_suffix); -#endif - add_dynamic_file_list_entry(dynamic_file_list, num_dynamic_file_list_entries, extra_file_hash, @@ -3200,11 +2913,6 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, if (exact_match) break; -#if 0 - if (IS_PARENT_PROCESS()) - printf("---> examining token '%s': search 2nd suffix ...\n", token); -#endif - /* ---------- step 2: search for matching second suffix ---------- */ for (k = 0; k < num_ext2_suffixes && !ext2_suffix_found; k++) @@ -3219,20 +2927,10 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, ext2_index = k; -#if 0 - if (IS_PARENT_PROCESS()) - printf("===> MATCH: '%s', '%s'\n", token, ext2_suffix); -#endif - if (start_pos + len_ext2_suffix == len_token) /* exact match */ { exact_match = TRUE; -#if 0 - if (IS_PARENT_PROCESS()) - printf("===> EXACT MATCH: '%s', '%s'\n", token, ext2_suffix); -#endif - add_dynamic_file_list_entry(dynamic_file_list, num_dynamic_file_list_entries, extra_file_hash, @@ -3252,11 +2950,6 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, if (exact_match) break; -#if 0 - if (IS_PARENT_PROCESS()) - printf("---> examining token '%s': search 3rd suffix ...\n",token); -#endif - /* ---------- step 3: search for matching third suffix ---------- */ for (l = 0; l < num_ext3_suffixes && !ext3_suffix_found; l++) @@ -3271,20 +2964,10 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, ext3_index = l; -#if 0 - if (IS_PARENT_PROCESS()) - printf("===> MATCH: '%s', '%s'\n", token, ext3_suffix); -#endif - if (start_pos + len_ext3_suffix == len_token) /* exact match */ { exact_match = TRUE; -#if 0 - if (IS_PARENT_PROCESS()) - printf("===> EXACT MATCH: '%s', '%s'\n", token, ext3_suffix); -#endif - add_dynamic_file_list_entry(dynamic_file_list, num_dynamic_file_list_entries, extra_file_hash, @@ -3384,17 +3067,6 @@ static void LoadArtworkConfigFromFilename(struct ArtworkListInfo *artwork_info, freeSetupFileHash(extra_file_hash); freeSetupFileHash(empty_file_hash); - -#if 0 - for (i = 0; i < num_file_list_entries; i++) - { - printf("'%s' ", file_list[i].token); - if (file_list[i].filename) - printf("-> '%s'\n", file_list[i].filename); - else - printf("-> UNDEFINED [-> '%s']\n", file_list[i].default_filename); - } -#endif } void LoadArtworkConfig(struct ArtworkListInfo *artwork_info) @@ -3446,21 +3118,11 @@ void LoadArtworkConfig(struct ArtworkListInfo *artwork_info) artwork_info->num_property_mapping_entries = 0; } -#if 1 if (!GFX_OVERRIDE_ARTWORK(artwork_info->type)) -#else - if (!SETUP_OVERRIDE_ARTWORK(setup, artwork_info->type)) -#endif { /* first look for special artwork configured in level series config */ filename_base = getCustomArtworkLevelConfigFilename(artwork_info->type); -#if 0 - printf("::: filename_base == '%s' [%s, %s]\n", filename_base, - leveldir_current->graphics_set, - leveldir_current->graphics_path); -#endif - if (fileExists(filename_base)) LoadArtworkConfigFromFilename(artwork_info, filename_base); } @@ -3554,23 +3216,15 @@ static void replaceArtworkListEntry(struct ArtworkListInfo *artwork_info, This usually means that this artwork does not exist in this artwork set and a fallback to the existing artwork is done. */ -#if 0 - printf("[artwork '%s' already exists (same list entry)]\n", filename); -#endif - return; } /* delete existing artwork file entry */ deleteArtworkListEntry(artwork_info, listnode); - /* check if the new artwork file already exists in the list of artworks */ + /* check if the new artwork file already exists in the list of artwork */ if ((node = getNodeFromKey(artwork_info->content_list, filename)) != NULL) { -#if 0 - printf("[artwork '%s' already exists (other list entry)]\n", filename); -#endif - *listnode = (struct ListNodeInfo *)node->content; (*listnode)->num_references++; @@ -3582,10 +3236,7 @@ static void replaceArtworkListEntry(struct ArtworkListInfo *artwork_info, if ((*listnode = artwork_info->load_artwork(filename)) != NULL) { -#if 0 - printf("[adding new artwork '%s']\n", filename); -#endif - + /* add new artwork file entry to the list of artwork files */ (*listnode)->num_references = 1; addNodeToList(&artwork_info->content_list, (*listnode)->source_filename, *listnode); @@ -3608,10 +3259,6 @@ static void LoadCustomArtwork(struct ArtworkListInfo *artwork_info, struct ListNodeInfo **listnode, struct FileInfo *file_list_entry) { -#if 0 - printf("GOT CUSTOM ARTWORK FILE '%s'\n", file_list_entry->filename); -#endif - if (strEqual(file_list_entry->filename, UNDEFINED_FILENAME)) { deleteArtworkListEntry(artwork_info, listnode); @@ -3811,11 +3458,7 @@ void debug_print_timestamp(int counter_nr, char *message) counter[counter_nr][1] = counter[counter_nr][0]; if (message) -#if 1 Error(ERR_DEBUG, "%s%s%s %.3f %s", -#else - printf("%s%s%s %.3f %s\n", -#endif debug_print_timestamp_get_padding(counter_nr * indent_size), message, debug_print_timestamp_get_padding(padding_size - strlen(message)), diff --git a/src/libgame/misc.h b/src/libgame/misc.h index d83a6563..9f75cc20 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -50,11 +50,6 @@ #define ERR_EXIT_SOUND_SERVER (ERR_EXIT | ERR_SOUND_SERVER) #define ERR_EXIT_NETWORK_SERVER (ERR_EXIT | ERR_NETWORK_SERVER) #define ERR_EXIT_NETWORK_CLIENT (ERR_EXIT | ERR_NETWORK_CLIENT) -#if 0 -#define ERR_ERROR (ERR_UNKNOWN) -#define ERR_FATAL (ERR_EXIT) -#define ERR_VERBOSE (ERR_INFO) -#endif /* values for getFile...() and putFile...() */ #define BYTE_ORDER_BIG_ENDIAN 0 @@ -181,8 +176,6 @@ void clear_mem(void *, unsigned int); void swap_numbers(int *, int *); void swap_number_pairs(int *, int *, int *, int *); -#if 1 - int getFile8BitInteger(File *); int putFile8BitInteger(FILE *, int); int getFile16BitInteger(File *, int); @@ -201,28 +194,6 @@ void WriteBytesToFile(FILE *, byte *, unsigned int); void ReadUnusedBytesFromFile(File *, unsigned int); void WriteUnusedBytesToFile(FILE *, unsigned int); -#else - -int getFile8BitInteger(FILE *); -int putFile8BitInteger(FILE *, int); -int getFile16BitInteger(FILE *, int); -int putFile16BitInteger(FILE *, int, int); -int getFile32BitInteger(FILE *, int); -int putFile32BitInteger(FILE *, int, int); - -boolean getFileChunk(FILE *, char *, int *, int); -int putFileChunk(FILE *, char *, int, int); -int getFileVersion(FILE *); -int putFileVersion(FILE *, int); - -void ReadBytesFromFile(FILE *, byte *, unsigned int); -void WriteBytesToFile(FILE *, byte *, unsigned int); - -void ReadUnusedBytesFromFile(FILE *, unsigned int); -void WriteUnusedBytesToFile(FILE *, unsigned int); - -#endif - #define getFile8Bit(f) getFile8BitInteger(f) #define putFile8Bit(f,x) putFile8BitInteger(f,x) #define getFile16BitBE(f) getFile16BitInteger(f,BYTE_ORDER_BIG_ENDIAN) diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index da72bd49..12b39d86 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -15,8 +15,8 @@ #include "misc.h" #include "setup.h" +#define ENABLE_UNUSED_CODE 0 /* currently unused functions */ -#if defined(TARGET_SDL) /* ========================================================================= */ /* video functions */ @@ -54,19 +54,16 @@ static void UpdateScreen(SDL_Rect *rect) static unsigned int update_screen_delay = 0; unsigned int update_screen_delay_value = 20; /* (milliseconds) */ -#if 1 if (limit_screen_updates && !DelayReached(&update_screen_delay, update_screen_delay_value)) return; LimitScreenUpdates(FALSE); -#endif #if defined(TARGET_SDL2) #if USE_RENDERER SDL_Surface *screen = backbuffer->surface; -#if 1 if (rect) { int bytes_x = screen->pitch / video.width; @@ -83,9 +80,6 @@ static void UpdateScreen(SDL_Rect *rect) { SDL_UpdateTexture(sdl_texture, NULL, screen->pixels, screen->pitch); } -#else - SDL_UpdateTexture(sdl_texture, NULL, screen->pixels, screen->pitch); -#endif SDL_RenderClear(sdl_renderer); SDL_RenderCopy(sdl_renderer, sdl_texture, NULL, NULL); SDL_RenderPresent(sdl_renderer); @@ -228,26 +222,6 @@ SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface) backbuffer->surface == NULL) return NULL; -#if 0 - boolean same_pixel_format = - equalSDLPixelFormat(surface->format, backbuffer->surface->format); - - printf("::: SDL_DisplayFormat: %08x -> %08x [%08x, %08x, %08x -> %08x, %08x, %08x] [%d, %d -> %d, %d] => %s\n", - surface->format->format, - backbuffer->surface->format->format, - surface->format->Rmask, - surface->format->Gmask, - surface->format->Bmask, - backbuffer->surface->format->Rmask, - backbuffer->surface->format->Gmask, - backbuffer->surface->format->Bmask, - surface->format->BitsPerPixel, - surface->format->BytesPerPixel, - backbuffer->surface->format->BitsPerPixel, - backbuffer->surface->format->BytesPerPixel, - (same_pixel_format ? "SAME" : "DIFF")); -#endif - return SDL_ConvertSurface(surface, backbuffer->surface->format, 0); } @@ -344,12 +318,10 @@ void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window, fullscreen_yoffset = (fullscreen_height - video.height) / 2; #endif -#if 1 checked_free(video.fullscreen_modes); video.fullscreen_modes = NULL; video.fullscreen_mode_current = NULL; -#endif video.window_scaling_percent = setup.window_scaling_percent; video.window_scaling_quality = setup.window_scaling_quality; @@ -466,20 +438,13 @@ void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window, } #endif -#if 0 - /* set window icon */ - SDLSetWindowIcon(program.sdl_icon_filename); -#endif - /* open SDL video output device (window or fullscreen mode) */ if (!SDLSetVideoMode(backbuffer, fullscreen)) Error(ERR_EXIT, "setting video mode failed"); -#if 1 /* !!! SDL2 can only set the window icon if the window already exists !!! */ /* set window icon */ SDLSetWindowIcon(program.sdl_icon_filename); -#endif /* set window and icon title */ #if defined(TARGET_SDL2) @@ -502,11 +467,7 @@ void SDLInitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window, should never be drawn to directly, it would do no harm nevertheless. */ /* create additional (symbolic) buffer for double-buffering */ -#if 1 ReCreateBitmap(window, video.width, video.height, video.depth); -#else - *window = CreateBitmap(video.width, video.height, video.depth); -#endif } static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer, @@ -541,13 +502,7 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer, // store if initial screen mode on game start is fullscreen mode if (sdl_window == NULL) - { -#if 0 - printf("::: GAME STARTS WITH FULLSCREEN %d\n", fullscreen); -#endif - video.fullscreen_initial = fullscreen; - } #if USE_RENDERER float window_scaling_factor = (float)setup.window_scaling_percent / 100; @@ -558,10 +513,6 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer, video.window_width = window_scaling_factor * width; video.window_height = window_scaling_factor * height; -#if 0 - printf("::: use window scaling factor %f\n", screen_scaling_factor); -#endif - if ((*backbuffer)->surface) { SDL_FreeSurface((*backbuffer)->surface); @@ -589,14 +540,6 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer, } } -#if 0 - Error(ERR_INFO, "::: checking 'sdl_window' ..."); - - if (sdl_window == NULL) - Error(ERR_INFO, "::: calling SDL_CreateWindow() [%d, %d, %d] ...", - setup.fullscreen, fullscreen, fullscreen_enabled); -#endif - if (sdl_window == NULL) sdl_window = SDL_CreateWindow(program.window_title, SDL_WINDOWPOS_CENTERED, @@ -637,28 +580,8 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer, if (sdl_texture != NULL) { -#if 1 // use SDL default values for RGB masks and no alpha channel new_surface = SDL_CreateRGBSurface(0, width, height, 32, 0,0,0, 0); -#else - -#if 1 - // (do not use alpha channel) - new_surface = SDL_CreateRGBSurface(0, width, height, 32, - 0x00FF0000, - 0x0000FF00, - 0x000000FF, - 0x00000000); -#else - // (this uses an alpha channel, which we don't want here) - new_surface = SDL_CreateRGBSurface(0, width, height, 32, - 0x00FF0000, - 0x0000FF00, - 0x000000FF, - 0xFF000000); -#endif - -#endif if (new_surface == NULL) Error(ERR_WARN, "SDL_CreateRGBSurface() failed: %s", @@ -710,17 +633,6 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer, boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen) { boolean success = TRUE; -#if 1 -#else -#if defined(TARGET_SDL2) - // int surface_flags_fullscreen = SURFACE_FLAGS | SDL_WINDOW_FULLSCREEN; - int surface_flags_fullscreen = SURFACE_FLAGS | SDL_WINDOW_FULLSCREEN_DESKTOP; - int surface_flags_window = SURFACE_FLAGS; -#else - int surface_flags_fullscreen = SURFACE_FLAGS | SDL_FULLSCREEN; - int surface_flags_window = SURFACE_FLAGS; -#endif -#endif SDL_Surface *new_surface = NULL; SetWindowTitle(); @@ -740,28 +652,7 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen) video_yoffset = fullscreen_yoffset; /* switch display to fullscreen mode, if available */ -#if 1 new_surface = SDLCreateScreen(backbuffer, TRUE); -#else - -#if defined(TARGET_SDL2) - sdl_window = SDL_CreateWindow(program.window_title, - SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, - fullscreen_width, fullscreen_height, - surface_flags_fullscreen); - if (sdl_window != NULL) - { - new_surface = SDL_GetWindowSurface(sdl_window); - - // SDL_UpdateWindowSurface(sdl_window); // immediately map window - // UpdateScreen(NULL); // immediately map window - } -#else - new_surface = SDL_SetVideoMode(fullscreen_width, fullscreen_height, - video.depth, surface_flags_fullscreen); -#endif -#endif if (new_surface == NULL) { @@ -790,113 +681,7 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen) video_yoffset = 0; /* switch display to window mode */ -#if 1 new_surface = SDLCreateScreen(backbuffer, FALSE); -#else - -#if defined(TARGET_SDL2) - -#if USE_RENDERER - float screen_scaling_factor = 1.2; - int test_fullscreen = 0; - int surface_flags = (test_fullscreen ? surface_flags_fullscreen : - surface_flags_window); - - if ((*backbuffer)->surface) - SDL_FreeSurface((*backbuffer)->surface); - - if (sdl_texture) - SDL_DestroyTexture(sdl_texture); - - if (sdl_renderer) - SDL_DestroyRenderer(sdl_renderer); - - if (sdl_window) - SDL_DestroyWindow(sdl_window); - - sdl_window = SDL_CreateWindow(program.window_title, - SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, - (int)(screen_scaling_factor * video.width), - (int)(screen_scaling_factor * video.height), - surface_flags); - - if (sdl_window != NULL) - { - sdl_renderer = SDL_CreateRenderer(sdl_window, -1, 0); - - if (sdl_renderer != NULL) - { - SDL_RenderSetLogicalSize(sdl_renderer, video.width, video.height); - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); - - sdl_texture = SDL_CreateTexture(sdl_renderer, - SDL_PIXELFORMAT_ARGB8888, - SDL_TEXTUREACCESS_STREAMING, - video.width, video.height); - - if (sdl_texture != NULL) - { -#if 1 - // (do not use alpha channel) - new_surface = SDL_CreateRGBSurface(0, video.width, video.height, 32, - 0x00FF0000, - 0x0000FF00, - 0x000000FF, - 0x00000000); -#else - // (this uses an alpha channel, which we don't want here) - new_surface = SDL_CreateRGBSurface(0, video.width, video.height, 32, - 0x00FF0000, - 0x0000FF00, - 0x000000FF, - 0xFF000000); -#endif - - if (new_surface == NULL) - Error(ERR_WARN, "SDL_CreateRGBSurface() failed: %s", - SDL_GetError()); - } - else - { - Error(ERR_WARN, "SDL_CreateTexture() failed: %s", SDL_GetError()); - } - } - else - { - Error(ERR_WARN, "SDL_CreateRenderer() failed: %s", SDL_GetError()); - } - } - else - { - Error(ERR_WARN, "SDL_CreateWindow() failed: %s", SDL_GetError()); - } - -#else - - if (sdl_window) - SDL_DestroyWindow(sdl_window); - - sdl_window = SDL_CreateWindow(program.window_title, - SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, - video.width, video.height, - surface_flags_window); - - if (sdl_window != NULL) - { - new_surface = SDL_GetWindowSurface(sdl_window); - - // SDL_UpdateWindowSurface(sdl_window); // immediately map window - // UpdateScreen(NULL); // immediately map window - } -#endif - -#else - new_surface = SDL_SetVideoMode(video.width, video.height, - video.depth, surface_flags_window); -#endif -#endif if (new_surface == NULL) { @@ -919,10 +704,8 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen) #if defined(TARGET_SDL2) SDLRedrawWindow(); // map window - // UpdateScreen(NULL); // map window #endif -#if 1 SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); #if defined(PLATFORM_WIN32) @@ -950,7 +733,6 @@ boolean SDLSetVideoMode(DrawBuffer **backbuffer, boolean fullscreen) DragAcceptFiles(hwnd, TRUE); } } -#endif #endif return success; @@ -975,10 +757,6 @@ void SDLSetWindowScaling(int window_scaling_percent) int new_window_width = (int)(window_scaling_factor * video.width); int new_window_height = (int)(window_scaling_factor * video.height); -#if 0 - Error(ERR_DEBUG, "::: SDLSetWindowScaling(%d) ...", window_scaling_percent); -#endif - SDL_SetWindowSize(sdl_window, new_window_width, new_window_height); video.window_scaling_percent = window_scaling_percent; @@ -1023,19 +801,9 @@ void SDLSetWindowFullscreen(boolean fullscreen) int flags = (fullscreen ? SDL_WINDOW_FULLSCREEN : 0); #endif -#if 0 - Error(ERR_DEBUG, "::: SDL_SetWindowFullscreen(%d) ...", fullscreen); -#endif - if (SDL_SetWindowFullscreen(sdl_window, flags) == 0) video.fullscreen_enabled = fullscreen; -#if 0 - printf("::: SDLSetWindowFullscreen: %d, %d\n", - fullscreen, video.fullscreen_initial); -#endif - -#if 1 // if game started in fullscreen mode, window will also get fullscreen size if (!fullscreen && video.fullscreen_initial) { @@ -1045,7 +813,6 @@ void SDLSetWindowFullscreen(boolean fullscreen) video.fullscreen_initial = FALSE; } -#endif } void SDLRedrawWindow() @@ -1057,7 +824,6 @@ void SDLRedrawWindow() void SDLCreateBitmapContent(Bitmap *bitmap, int width, int height, int depth) { -#if 1 SDL_Surface *surface = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height, depth, 0,0,0, 0); @@ -1067,23 +833,6 @@ void SDLCreateBitmapContent(Bitmap *bitmap, int width, int height, SDLSetNativeSurface(&surface); bitmap->surface = surface; - -#else - - SDL_Surface *surface_tmp, *surface_native; - - if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height, depth, - 0, 0, 0, 0)) - == NULL) - Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError()); - - if ((surface_native = SDL_DisplayFormat(surface_tmp)) == NULL) - Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError()); - - SDL_FreeSurface(surface_tmp); - - new_bitmap->surface = surface_native; -#endif } void SDLFreeBitmapPointers(Bitmap *bitmap) @@ -1456,19 +1205,8 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height, if (draw_border_function != NULL) draw_border_function(); -#if 1 /* only update the region of the screen that is affected from fading */ -#if defined(TARGET_SDL2) - // SDL_UpdateWindowSurface(sdl_window); - // SDL_UpdateWindowSurfaceRects(sdl_window, &dst_rect, 1); - UpdateScreen(&dst_rect); -#else - // SDL_UpdateRect(surface_screen, dst_x, dst_y, width, height); UpdateScreen(&dst_rect); -#endif -#else - SDL_Flip(surface_screen); -#endif } } @@ -1515,7 +1253,7 @@ void SDLDrawLine(Bitmap *dst_bitmap, int from_x, int from_y, sge_Line(dst_bitmap->surface, from_x, from_y, to_x, to_y, color); } -#if 0 +#if ENABLE_UNUSED_CODE void SDLDrawLines(SDL_Surface *surface, struct XY *points, int num_points, Uint32 color) { @@ -2123,17 +1861,11 @@ int zoomSurfaceRGBA_scaleDownBy2(SDL_Surface *src, SDL_Surface *dst) { int x, y; tColorRGBA *sp, *csp, *dp; -#if 0 - int sgap; -#endif int dgap; /* pointer setup */ sp = csp = (tColorRGBA *) src->pixels; dp = (tColorRGBA *) dst->pixels; -#if 0 - sgap = src->pitch - src->w * 4; -#endif dgap = dst->pitch - dst->w * 4; for (y = 0; y < dst->h; y++) @@ -2176,8 +1908,6 @@ int zoomSurfaceRGBA_scaleDownBy2(SDL_Surface *src, SDL_Surface *dst) return 0; } -#if 1 - int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst) { int x, y, *sax, *say, *csax, *csay; @@ -2190,11 +1920,6 @@ int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst) src->h == 2 * dst->h) return zoomSurfaceRGBA_scaleDownBy2(src, dst); -#if 0 - printf("::: zoomSurfaceRGBA: %d, %d -> %d, %d\n", - src->w, src->h, dst->w, dst->h); -#endif - /* variable setup */ sx = (float) src->w / (float) dst->w; sy = (float) src->h / (float) dst->h; @@ -2248,94 +1973,6 @@ int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst) return 0; } -#else - -int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst) -{ - int x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy; - tColorRGBA *sp, *csp, *dp; -#if 0 - int sgap; -#endif - int dgap; - - /* use specialized zoom function when scaling down to exactly half size */ - if (src->w == 2 * dst->w && - src->h == 2 * dst->h) - return zoomSurfaceRGBA_scaleDownBy2(src, dst); - - /* variable setup */ - sx = (int) (65536.0 * (float) src->w / (float) dst->w); - sy = (int) (65536.0 * (float) src->h / (float) dst->h); - - /* allocate memory for row increments */ - sax = (int *)checked_malloc((dst->w + 1) * sizeof(Uint32)); - say = (int *)checked_malloc((dst->h + 1) * sizeof(Uint32)); - - /* precalculate row increments */ - csx = 0; - csax = sax; - for (x = 0; x <= dst->w; x++) - { - *csax = csx; - csax++; - csx &= 0xffff; - csx += sx; - } - - csy = 0; - csay = say; - for (y = 0; y <= dst->h; y++) - { - *csay = csy; - csay++; - csy &= 0xffff; - csy += sy; - } - - /* pointer setup */ - sp = csp = (tColorRGBA *) src->pixels; - dp = (tColorRGBA *) dst->pixels; -#if 0 - sgap = src->pitch - src->w * 4; -#endif - dgap = dst->pitch - dst->w * 4; - - csay = say; - for (y = 0; y < dst->h; y++) - { - sp = csp; - csax = sax; - - for (x = 0; x < dst->w; x++) - { - /* draw */ - *dp = *sp; - - /* advance source pointers */ - csax++; - sp += (*csax >> 16); - - /* advance destination pointer */ - dp++; - } - - /* advance source pointer */ - csay++; - csp = (tColorRGBA *) ((Uint8 *) csp + (*csay >> 16) * src->pitch); - - /* advance destination pointers */ - dp = (tColorRGBA *) ((Uint8 *) dp + dgap); - } - - free(sax); - free(say); - - return 0; -} - -#endif - /* ----------------------------------------------------------------------------- 8 bit zoomer @@ -2521,12 +2158,8 @@ SDL_Surface *zoomSurface(SDL_Surface *src, int dst_width, int dst_height) return zoom_dst; } -#if 1 - Bitmap *SDLZoomBitmap(Bitmap *src_bitmap, int dst_width, int dst_height) { -#if 1 - Bitmap *dst_bitmap = CreateBitmapStruct(); SDL_Surface **dst_surface = &dst_bitmap->surface; @@ -2543,70 +2176,8 @@ Bitmap *SDLZoomBitmap(Bitmap *src_bitmap, int dst_width, int dst_height) SDLSetNativeSurface(dst_surface); return dst_bitmap; - -#else - - Bitmap *dst_bitmap = CreateBitmapStruct(); - SDL_Surface *sdl_surface_tmp; - - dst_width = MAX(1, dst_width); /* prevent zero bitmap width */ - dst_height = MAX(1, dst_height); /* prevent zero bitmap height */ - - dst_bitmap->width = dst_width; - dst_bitmap->height = dst_height; - - print_timestamp_init("SDLZoomBitmap"); - - /* create zoomed temporary surface from source surface */ - sdl_surface_tmp = zoomSurface(src_bitmap->surface, dst_width, dst_height); - print_timestamp_time("zoomSurface"); - - /* create native format destination surface from zoomed temporary surface */ - dst_bitmap->surface = SDL_DisplayFormat(sdl_surface_tmp); - print_timestamp_time("SDL_DisplayFormat"); - - /* free temporary surface */ - SDL_FreeSurface(sdl_surface_tmp); - print_timestamp_time("SDL_FreeSurface"); - - print_timestamp_done("SDLZoomBitmap"); - - return dst_bitmap; - -#endif -} - -#else - -void SDLZoomBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap) -{ - SDL_Surface *sdl_surface_tmp; - int dst_width = dst_bitmap->width; - int dst_height = dst_bitmap->height; - - print_timestamp_init("SDLZoomBitmap"); - - /* throw away old destination surface */ - SDL_FreeSurface(dst_bitmap->surface); - print_timestamp_time("SDL_FreeSurface"); - - /* create zoomed temporary surface from source surface */ - sdl_surface_tmp = zoomSurface(src_bitmap->surface, dst_width, dst_height); - print_timestamp_time("zoomSurface"); - - /* create native format destination surface from zoomed temporary surface */ - dst_bitmap->surface = SDL_DisplayFormat(sdl_surface_tmp); - print_timestamp_time("SDL_DisplayFormat"); - - /* free temporary surface */ - SDL_FreeSurface(sdl_surface_tmp); - print_timestamp_time("SDL_FreeSurface"); - - print_timestamp_done("SDLZoomBitmap"); } -#endif - /* ========================================================================= */ /* load image to bitmap */ @@ -2634,21 +2205,12 @@ Bitmap *SDLLoadImage(char *filename) UPDATE_BUSY_STATE(); /* create native non-transparent surface for current image */ -#if 1 if ((new_bitmap->surface = SDLGetNativeSurface(sdl_image_tmp)) == NULL) { SetError("SDL_DisplayFormat(): %s", SDL_GetError()); return NULL; } -#else - if ((new_bitmap->surface = SDL_DisplayFormat(sdl_image_tmp)) == NULL) - { - SetError("SDL_DisplayFormat(): %s", SDL_GetError()); - - return NULL; - } -#endif print_timestamp_time("SDL_DisplayFormat (opaque)"); @@ -2657,21 +2219,13 @@ Bitmap *SDLLoadImage(char *filename) /* create native transparent surface for current image */ SDL_SetColorKey(sdl_image_tmp, SET_TRANSPARENT_PIXEL, SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00)); -#if 1 - if ((new_bitmap->surface_masked = SDLGetNativeSurface(sdl_image_tmp)) == NULL) - { - SetError("SDL_DisplayFormat(): %s", SDL_GetError()); - return NULL; - } -#else - if ((new_bitmap->surface_masked = SDL_DisplayFormat(sdl_image_tmp)) == NULL) + if ((new_bitmap->surface_masked = SDLGetNativeSurface(sdl_image_tmp)) == NULL) { SetError("SDL_DisplayFormat(): %s", SDL_GetError()); return NULL; } -#endif print_timestamp_time("SDL_DisplayFormat (masked)"); @@ -2985,5 +2539,3 @@ boolean SDLReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2) return TRUE; } - -#endif /* TARGET_SDL */ diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index ae649fcb..35251220 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -465,11 +465,7 @@ void SDLPutPixel(Bitmap *, int, int, Pixel); void SDLInvertArea(Bitmap *, int, int, int, int, Uint32); void SDLCopyInverseMasked(Bitmap *, Bitmap *, int, int, int, int, int, int); -#if 1 Bitmap *SDLZoomBitmap(Bitmap *, int, int); -#else -void SDLZoomBitmap(Bitmap *, Bitmap *); -#endif Bitmap *SDLLoadImage(char *); diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 16c11dfd..b9f9a3ae 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -30,6 +30,8 @@ #include "hash.h" +#define ENABLE_UNUSED_CODE 0 /* currently unused functions */ + #define NUM_LEVELCLASS_DESC 8 static char *levelclass_desc[NUM_LEVELCLASS_DESC] = @@ -1089,13 +1091,7 @@ TreeInfo *cloneTreeNode(TreeInfo **node_top, TreeInfo *node_parent, return cloneTreeNode(node_top, node_parent, node->next, skip_sets_without_levels); -#if 1 node_new = getTreeInfoCopy(node); /* copy complete node */ -#else - node_new = newTreeInfo(); - - *node_new = *node; /* copy complete node */ -#endif node_new->node_top = node_top; /* correct top node link */ node_new->node_parent = node_parent; /* correct parent node link */ @@ -1613,7 +1609,7 @@ SetupFileList *addListEntry(SetupFileList *list, char *token, char *value) return addListEntry(list->next, token, value); } -#if 0 +#if ENABLE_UNUSED_CODE #ifdef DEBUG static void printSetupFileList(SetupFileList *list) { @@ -1725,7 +1721,8 @@ char *removeHashEntry(SetupFileHash *hash, char *token) return remove_hash_entry(hash, token); } -#if 0 +#if ENABLE_UNUSED_CODE +#if DEBUG static void printSetupFileHash(SetupFileHash *hash) { BEGIN_HASH_ITERATION(hash, itr) @@ -1736,6 +1733,7 @@ static void printSetupFileHash(SetupFileHash *hash) END_HASH_ITERATION(hash, itr) } #endif +#endif #define ALLOW_TOKEN_VALUE_SEPARATOR_BEING_WHITESPACE 1 #define CHECK_TOKEN_VALUE_SEPARATOR__WARN_IF_MISSING 0 @@ -1801,12 +1799,8 @@ static boolean getTokenValueFromSetupLineExt(char *line, /* find end of token to determine start of value */ for (line_ptr = token; *line_ptr; line_ptr++) { -#if 1 /* first look for an explicit token/value separator, like ':' or '=' */ if (*line_ptr == ':' || *line_ptr == '=') -#else - if (*line_ptr == ' ' || *line_ptr == '\t' || *line_ptr == ':') -#endif { *line_ptr = '\0'; /* terminate token string */ value = line_ptr + 1; /* set beginning of value */ @@ -1873,11 +1867,6 @@ static boolean getTokenValueFromSetupLineExt(char *line, if (*value != ' ' && *value != '\t') break; -#if 0 - if (*value == '\0') - value = "true"; /* treat tokens without value as "true" */ -#endif - *token_ptr = token; *value_ptr = value; @@ -1893,9 +1882,6 @@ boolean getTokenValueFromSetupLine(char *line, char **token, char **value) return getTokenValueFromSetupLineExt(line, token, value, NULL, NULL, 0, TRUE); } -#if 1 - -#if 1 static boolean loadSetupFileData(void *setup_file_data, char *filename, boolean top_recursion_level, boolean is_hash) { @@ -1915,10 +1901,6 @@ static boolean loadSetupFileData(void *setup_file_data, char *filename, token_already_exists_warning = FALSE; #endif -#if 0 - Error(ERR_INFO, "===== opening file: '%s'", filename); -#endif - if (!(file = openFile(filename, MODE_READ))) { Error(ERR_WARN, "cannot open configuration file '%s'", filename); @@ -1926,10 +1908,6 @@ static boolean loadSetupFileData(void *setup_file_data, char *filename, return FALSE; } -#if 0 - Error(ERR_INFO, "===== reading file: '%s'", filename); -#endif - /* use "insert pointer" to store list end for constant insertion complexity */ if (!is_hash) insert_ptr = setup_file_data; @@ -1947,10 +1925,6 @@ static boolean loadSetupFileData(void *setup_file_data, char *filename, if (!getStringFromFile(file, line, MAX_LINE_LEN)) break; -#if 0 - Error(ERR_INFO, "got line: '%s'", line); -#endif - /* check if line was completely read and is terminated by line break */ if (strlen(line) > 0 && line[strlen(line) - 1] == '\n') line_nr++; @@ -1965,14 +1939,6 @@ static boolean loadSetupFileData(void *setup_file_data, char *filename, if (read_continued_line) { -#if 0 - /* !!! ??? WHY ??? !!! */ - /* cut leading whitespaces from input line */ - for (line_ptr = line; *line_ptr; line_ptr++) - if (*line_ptr != ' ' && *line_ptr != '\t') - break; -#endif - /* append new line to existing line, if there is enough space */ if (strlen(previous_line) + strlen(line_ptr) < MAX_LINE_LEN) strcat(previous_line, line_ptr); @@ -2007,10 +1973,6 @@ static boolean loadSetupFileData(void *setup_file_data, char *filename, char *basename = getBaseName(value); char *filename_include = getPath2(basepath, basename); -#if 0 - Error(ERR_INFO, "[including file '%s']", filename_include); -#endif - loadSetupFileData(setup_file_data, filename_include, FALSE, is_hash); free(basepath); @@ -2082,573 +2044,162 @@ static boolean loadSetupFileData(void *setup_file_data, char *filename, return TRUE; } -#else - -static boolean loadSetupFileData(void *setup_file_data, char *filename, - boolean top_recursion_level, boolean is_hash) +void saveSetupFileHash(SetupFileHash *hash, char *filename) { - static SetupFileHash *include_filename_hash = NULL; - char line[MAX_LINE_LEN], line_raw[MAX_LINE_LEN], previous_line[MAX_LINE_LEN]; - char *token, *value, *line_ptr; - void *insert_ptr = NULL; - boolean read_continued_line = FALSE; FILE *file; - int line_nr = 0, token_count = 0, include_count = 0; - -#if CHECK_TOKEN_VALUE_SEPARATOR__WARN_IF_MISSING - token_value_separator_warning = FALSE; -#endif - -#if CHECK_TOKEN__WARN_IF_ALREADY_EXISTS_IN_HASH - token_already_exists_warning = FALSE; -#endif - if (!(file = fopen(filename, MODE_READ))) + if (!(file = fopen(filename, MODE_WRITE))) { - Error(ERR_WARN, "cannot open configuration file '%s'", filename); + Error(ERR_WARN, "cannot write configuration file '%s'", filename); - return FALSE; + return; } - /* use "insert pointer" to store list end for constant insertion complexity */ - if (!is_hash) - insert_ptr = setup_file_data; + BEGIN_HASH_ITERATION(hash, itr) + { + fprintf(file, "%s\n", getFormattedSetupEntry(HASH_ITERATION_TOKEN(itr), + HASH_ITERATION_VALUE(itr))); + } + END_HASH_ITERATION(hash, itr) - /* on top invocation, create hash to mark included files (to prevent loops) */ - if (top_recursion_level) - include_filename_hash = newSetupFileHash(); + fclose(file); +} - /* mark this file as already included (to prevent including it again) */ - setHashEntry(include_filename_hash, getBaseNamePtr(filename), "true"); +SetupFileList *loadSetupFileList(char *filename) +{ + SetupFileList *setup_file_list = newSetupFileList("", ""); + SetupFileList *first_valid_list_entry; - while (!feof(file)) + if (!loadSetupFileData(setup_file_list, filename, TRUE, FALSE)) { - /* read next line of input file */ - if (!fgets(line, MAX_LINE_LEN, file)) - break; + freeSetupFileList(setup_file_list); - /* check if line was completely read and is terminated by line break */ - if (strlen(line) > 0 && line[strlen(line) - 1] == '\n') - line_nr++; + return NULL; + } - /* cut trailing line break (this can be newline and/or carriage return) */ - for (line_ptr = &line[strlen(line)]; line_ptr >= line; line_ptr--) - if ((*line_ptr == '\n' || *line_ptr == '\r') && *(line_ptr + 1) == '\0') - *line_ptr = '\0'; + first_valid_list_entry = setup_file_list->next; - /* copy raw input line for later use (mainly debugging output) */ - strcpy(line_raw, line); + /* free empty list header */ + setup_file_list->next = NULL; + freeSetupFileList(setup_file_list); - if (read_continued_line) - { -#if 0 - /* !!! ??? WHY ??? !!! */ - /* cut leading whitespaces from input line */ - for (line_ptr = line; *line_ptr; line_ptr++) - if (*line_ptr != ' ' && *line_ptr != '\t') - break; -#endif + return first_valid_list_entry; +} - /* append new line to existing line, if there is enough space */ - if (strlen(previous_line) + strlen(line_ptr) < MAX_LINE_LEN) - strcat(previous_line, line_ptr); +SetupFileHash *loadSetupFileHash(char *filename) +{ + SetupFileHash *setup_file_hash = newSetupFileHash(); - strcpy(line, previous_line); /* copy storage buffer to line */ + if (!loadSetupFileData(setup_file_hash, filename, TRUE, TRUE)) + { + freeSetupFileHash(setup_file_hash); - read_continued_line = FALSE; - } + return NULL; + } - /* if the last character is '\', continue at next line */ - if (strlen(line) > 0 && line[strlen(line) - 1] == '\\') - { - line[strlen(line) - 1] = '\0'; /* cut off trailing backslash */ - strcpy(previous_line, line); /* copy line to storage buffer */ + return setup_file_hash; +} - read_continued_line = TRUE; +void checkSetupFileHashIdentifier(SetupFileHash *setup_file_hash, + char *filename, char *identifier) +{ + char *value = getHashEntry(setup_file_hash, TOKEN_STR_FILE_IDENTIFIER); - continue; - } + if (value == NULL) + Error(ERR_WARN, "config file '%s' has no file identifier", filename); + else if (!checkCookieString(value, identifier)) + Error(ERR_WARN, "config file '%s' has wrong file identifier", filename); +} - if (!getTokenValueFromSetupLineExt(line, &token, &value, filename, - line_raw, line_nr, FALSE)) - continue; - if (*token) - { - if (strEqual(token, "include")) - { - if (getHashEntry(include_filename_hash, value) == NULL) - { - char *basepath = getBasePath(filename); - char *basename = getBaseName(value); - char *filename_include = getPath2(basepath, basename); +/* ========================================================================= */ +/* setup file stuff */ +/* ========================================================================= */ -#if 0 - Error(ERR_INFO, "[including file '%s']", filename_include); -#endif +#define TOKEN_STR_LAST_LEVEL_SERIES "last_level_series" +#define TOKEN_STR_LAST_PLAYED_LEVEL "last_played_level" +#define TOKEN_STR_HANDICAP_LEVEL "handicap_level" - loadSetupFileData(setup_file_data, filename_include, FALSE, is_hash); +/* level directory info */ +#define LEVELINFO_TOKEN_IDENTIFIER 0 +#define LEVELINFO_TOKEN_NAME 1 +#define LEVELINFO_TOKEN_NAME_SORTING 2 +#define LEVELINFO_TOKEN_AUTHOR 3 +#define LEVELINFO_TOKEN_YEAR 4 +#define LEVELINFO_TOKEN_IMPORTED_FROM 5 +#define LEVELINFO_TOKEN_IMPORTED_BY 6 +#define LEVELINFO_TOKEN_TESTED_BY 7 +#define LEVELINFO_TOKEN_LEVELS 8 +#define LEVELINFO_TOKEN_FIRST_LEVEL 9 +#define LEVELINFO_TOKEN_SORT_PRIORITY 10 +#define LEVELINFO_TOKEN_LATEST_ENGINE 11 +#define LEVELINFO_TOKEN_LEVEL_GROUP 12 +#define LEVELINFO_TOKEN_READONLY 13 +#define LEVELINFO_TOKEN_GRAPHICS_SET_ECS 14 +#define LEVELINFO_TOKEN_GRAPHICS_SET_AGA 15 +#define LEVELINFO_TOKEN_GRAPHICS_SET 16 +#define LEVELINFO_TOKEN_SOUNDS_SET 17 +#define LEVELINFO_TOKEN_MUSIC_SET 18 +#define LEVELINFO_TOKEN_FILENAME 19 +#define LEVELINFO_TOKEN_FILETYPE 20 +#define LEVELINFO_TOKEN_SPECIAL_FLAGS 21 +#define LEVELINFO_TOKEN_HANDICAP 22 +#define LEVELINFO_TOKEN_SKIP_LEVELS 23 - free(basepath); - free(basename); - free(filename_include); +#define NUM_LEVELINFO_TOKENS 24 - include_count++; - } - else - { - Error(ERR_WARN, "ignoring already processed file '%s'", value); - } - } - else - { - if (is_hash) - { -#if CHECK_TOKEN__WARN_IF_ALREADY_EXISTS_IN_HASH - char *old_value = - getHashEntry((SetupFileHash *)setup_file_data, token); +static LevelDirTree ldi; - if (old_value != NULL) - { - if (!token_already_exists_warning) - { - Error(ERR_INFO_LINE, "-"); - Error(ERR_WARN, "duplicate token(s) found in config file:"); - Error(ERR_INFO, "- config file: '%s'", filename); +static struct TokenInfo levelinfo_tokens[] = +{ + /* level directory info */ + { TYPE_STRING, &ldi.identifier, "identifier" }, + { TYPE_STRING, &ldi.name, "name" }, + { TYPE_STRING, &ldi.name_sorting, "name_sorting" }, + { TYPE_STRING, &ldi.author, "author" }, + { TYPE_STRING, &ldi.year, "year" }, + { TYPE_STRING, &ldi.imported_from, "imported_from" }, + { TYPE_STRING, &ldi.imported_by, "imported_by" }, + { TYPE_STRING, &ldi.tested_by, "tested_by" }, + { TYPE_INTEGER, &ldi.levels, "levels" }, + { TYPE_INTEGER, &ldi.first_level, "first_level" }, + { TYPE_INTEGER, &ldi.sort_priority, "sort_priority" }, + { TYPE_BOOLEAN, &ldi.latest_engine, "latest_engine" }, + { TYPE_BOOLEAN, &ldi.level_group, "level_group" }, + { TYPE_BOOLEAN, &ldi.readonly, "readonly" }, + { TYPE_STRING, &ldi.graphics_set_ecs, "graphics_set.ecs" }, + { TYPE_STRING, &ldi.graphics_set_aga, "graphics_set.aga" }, + { TYPE_STRING, &ldi.graphics_set, "graphics_set" }, + { TYPE_STRING, &ldi.sounds_set, "sounds_set" }, + { TYPE_STRING, &ldi.music_set, "music_set" }, + { TYPE_STRING, &ldi.level_filename, "filename" }, + { TYPE_STRING, &ldi.level_filetype, "filetype" }, + { TYPE_STRING, &ldi.special_flags, "special_flags" }, + { TYPE_BOOLEAN, &ldi.handicap, "handicap" }, + { TYPE_BOOLEAN, &ldi.skip_levels, "skip_levels" } +}; - token_already_exists_warning = TRUE; - } +static struct TokenInfo artworkinfo_tokens[] = +{ + /* artwork directory info */ + { TYPE_STRING, &ldi.identifier, "identifier" }, + { TYPE_STRING, &ldi.subdir, "subdir" }, + { TYPE_STRING, &ldi.name, "name" }, + { TYPE_STRING, &ldi.name_sorting, "name_sorting" }, + { TYPE_STRING, &ldi.author, "author" }, + { TYPE_INTEGER, &ldi.sort_priority, "sort_priority" }, + { TYPE_STRING, &ldi.basepath, "basepath" }, + { TYPE_STRING, &ldi.fullpath, "fullpath" }, + { TYPE_BOOLEAN, &ldi.in_user_dir, "in_user_dir" }, + { TYPE_INTEGER, &ldi.color, "color" }, + { TYPE_STRING, &ldi.class_desc, "class_desc" }, - Error(ERR_INFO, "- token: '%s' (in line %d)", token, line_nr); - Error(ERR_INFO, " old value: '%s'", old_value); - Error(ERR_INFO, " new value: '%s'", value); - } -#endif + { -1, NULL, NULL }, +}; - setHashEntry((SetupFileHash *)setup_file_data, token, value); - } - else - { - insert_ptr = addListEntry((SetupFileList *)insert_ptr, token, value); - } - - token_count++; - } - } - } - - fclose(file); - -#if CHECK_TOKEN_VALUE_SEPARATOR__WARN_IF_MISSING - if (token_value_separator_warning) - Error(ERR_INFO_LINE, "-"); -#endif - -#if CHECK_TOKEN__WARN_IF_ALREADY_EXISTS_IN_HASH - if (token_already_exists_warning) - Error(ERR_INFO_LINE, "-"); -#endif - - if (token_count == 0 && include_count == 0) - Error(ERR_WARN, "configuration file '%s' is empty", filename); - - if (top_recursion_level) - freeSetupFileHash(include_filename_hash); - - return TRUE; -} - -#endif - -#else - -static boolean loadSetupFileData(void *setup_file_data, char *filename, - boolean top_recursion_level, boolean is_hash) -{ - static SetupFileHash *include_filename_hash = NULL; - char line[MAX_LINE_LEN], line_raw[MAX_LINE_LEN], previous_line[MAX_LINE_LEN]; - char *token, *value, *line_ptr; - void *insert_ptr = NULL; - boolean read_continued_line = FALSE; - FILE *file; - int line_nr = 0; - int token_count = 0; - -#if CHECK_TOKEN_VALUE_SEPARATOR__WARN_IF_MISSING - token_value_separator_warning = FALSE; -#endif - - if (!(file = fopen(filename, MODE_READ))) - { - Error(ERR_WARN, "cannot open configuration file '%s'", filename); - - return FALSE; - } - - /* use "insert pointer" to store list end for constant insertion complexity */ - if (!is_hash) - insert_ptr = setup_file_data; - - /* on top invocation, create hash to mark included files (to prevent loops) */ - if (top_recursion_level) - include_filename_hash = newSetupFileHash(); - - /* mark this file as already included (to prevent including it again) */ - setHashEntry(include_filename_hash, getBaseNamePtr(filename), "true"); - - while (!feof(file)) - { - /* read next line of input file */ - if (!fgets(line, MAX_LINE_LEN, file)) - break; - - /* check if line was completely read and is terminated by line break */ - if (strlen(line) > 0 && line[strlen(line) - 1] == '\n') - line_nr++; - - /* cut trailing line break (this can be newline and/or carriage return) */ - for (line_ptr = &line[strlen(line)]; line_ptr >= line; line_ptr--) - if ((*line_ptr == '\n' || *line_ptr == '\r') && *(line_ptr + 1) == '\0') - *line_ptr = '\0'; - - /* copy raw input line for later use (mainly debugging output) */ - strcpy(line_raw, line); - - if (read_continued_line) - { - /* cut leading whitespaces from input line */ - for (line_ptr = line; *line_ptr; line_ptr++) - if (*line_ptr != ' ' && *line_ptr != '\t') - break; - - /* append new line to existing line, if there is enough space */ - if (strlen(previous_line) + strlen(line_ptr) < MAX_LINE_LEN) - strcat(previous_line, line_ptr); - - strcpy(line, previous_line); /* copy storage buffer to line */ - - read_continued_line = FALSE; - } - - /* if the last character is '\', continue at next line */ - if (strlen(line) > 0 && line[strlen(line) - 1] == '\\') - { - line[strlen(line) - 1] = '\0'; /* cut off trailing backslash */ - strcpy(previous_line, line); /* copy line to storage buffer */ - - read_continued_line = TRUE; - - continue; - } - - /* cut trailing comment from input line */ - for (line_ptr = line; *line_ptr; line_ptr++) - { - if (*line_ptr == '#') - { - *line_ptr = '\0'; - break; - } - } - - /* cut trailing whitespaces from input line */ - for (line_ptr = &line[strlen(line)]; line_ptr >= line; line_ptr--) - if ((*line_ptr == ' ' || *line_ptr == '\t') && *(line_ptr + 1) == '\0') - *line_ptr = '\0'; - - /* ignore empty lines */ - if (*line == '\0') - continue; - - /* cut leading whitespaces from token */ - for (token = line; *token; token++) - if (*token != ' ' && *token != '\t') - break; - - /* start with empty value as reliable default */ - value = ""; - - token_value_separator_found = FALSE; - - /* find end of token to determine start of value */ - for (line_ptr = token; *line_ptr; line_ptr++) - { -#if 1 - /* first look for an explicit token/value separator, like ':' or '=' */ - if (*line_ptr == ':' || *line_ptr == '=') -#else - if (*line_ptr == ' ' || *line_ptr == '\t' || *line_ptr == ':') -#endif - { - *line_ptr = '\0'; /* terminate token string */ - value = line_ptr + 1; /* set beginning of value */ - - token_value_separator_found = TRUE; - - break; - } - } - -#if ALLOW_TOKEN_VALUE_SEPARATOR_BEING_WHITESPACE - /* fallback: if no token/value separator found, also allow whitespaces */ - if (!token_value_separator_found) - { - for (line_ptr = token; *line_ptr; line_ptr++) - { - if (*line_ptr == ' ' || *line_ptr == '\t') - { - *line_ptr = '\0'; /* terminate token string */ - value = line_ptr + 1; /* set beginning of value */ - - token_value_separator_found = TRUE; - - break; - } - } - -#if CHECK_TOKEN_VALUE_SEPARATOR__WARN_IF_MISSING - if (token_value_separator_found) - { - if (!token_value_separator_warning) - { - Error(ERR_INFO_LINE, "-"); - Error(ERR_WARN, "missing token/value separator(s) in config file:"); - Error(ERR_INFO, "- config file: '%s'", filename); - - token_value_separator_warning = TRUE; - } - - Error(ERR_INFO, "- line %d: '%s'", line_nr, line_raw); - } -#endif - } -#endif - - /* cut trailing whitespaces from token */ - for (line_ptr = &token[strlen(token)]; line_ptr >= token; line_ptr--) - if ((*line_ptr == ' ' || *line_ptr == '\t') && *(line_ptr + 1) == '\0') - *line_ptr = '\0'; - - /* cut leading whitespaces from value */ - for (; *value; value++) - if (*value != ' ' && *value != '\t') - break; - -#if 0 - if (*value == '\0') - value = "true"; /* treat tokens without value as "true" */ -#endif - - if (*token) - { - if (strEqual(token, "include")) - { - if (getHashEntry(include_filename_hash, value) == NULL) - { - char *basepath = getBasePath(filename); - char *basename = getBaseName(value); - char *filename_include = getPath2(basepath, basename); - -#if 0 - Error(ERR_INFO, "[including file '%s']", filename_include); -#endif - - loadSetupFileData(setup_file_data, filename_include, FALSE, is_hash); - - free(basepath); - free(basename); - free(filename_include); - } - else - { - Error(ERR_WARN, "ignoring already processed file '%s'", value); - } - } - else - { - if (is_hash) - setHashEntry((SetupFileHash *)setup_file_data, token, value); - else - insert_ptr = addListEntry((SetupFileList *)insert_ptr, token, value); - - token_count++; - } - } - } - - fclose(file); - -#if CHECK_TOKEN_VALUE_SEPARATOR__WARN_IF_MISSING - if (token_value_separator_warning) - Error(ERR_INFO_LINE, "-"); -#endif - - if (token_count == 0) - Error(ERR_WARN, "configuration file '%s' is empty", filename); - - if (top_recursion_level) - freeSetupFileHash(include_filename_hash); - - return TRUE; -} -#endif - -void saveSetupFileHash(SetupFileHash *hash, char *filename) -{ - FILE *file; - - if (!(file = fopen(filename, MODE_WRITE))) - { - Error(ERR_WARN, "cannot write configuration file '%s'", filename); - - return; - } - - BEGIN_HASH_ITERATION(hash, itr) - { - fprintf(file, "%s\n", getFormattedSetupEntry(HASH_ITERATION_TOKEN(itr), - HASH_ITERATION_VALUE(itr))); - } - END_HASH_ITERATION(hash, itr) - - fclose(file); -} - -SetupFileList *loadSetupFileList(char *filename) -{ - SetupFileList *setup_file_list = newSetupFileList("", ""); - SetupFileList *first_valid_list_entry; - - if (!loadSetupFileData(setup_file_list, filename, TRUE, FALSE)) - { - freeSetupFileList(setup_file_list); - - return NULL; - } - - first_valid_list_entry = setup_file_list->next; - - /* free empty list header */ - setup_file_list->next = NULL; - freeSetupFileList(setup_file_list); - - return first_valid_list_entry; -} - -SetupFileHash *loadSetupFileHash(char *filename) -{ - SetupFileHash *setup_file_hash = newSetupFileHash(); - - if (!loadSetupFileData(setup_file_hash, filename, TRUE, TRUE)) - { - freeSetupFileHash(setup_file_hash); - - return NULL; - } - - return setup_file_hash; -} - -void checkSetupFileHashIdentifier(SetupFileHash *setup_file_hash, - char *filename, char *identifier) -{ - char *value = getHashEntry(setup_file_hash, TOKEN_STR_FILE_IDENTIFIER); - - if (value == NULL) - Error(ERR_WARN, "config file '%s' has no file identifier", filename); - else if (!checkCookieString(value, identifier)) - Error(ERR_WARN, "config file '%s' has wrong file identifier", filename); -} - - -/* ========================================================================= */ -/* setup file stuff */ -/* ========================================================================= */ - -#define TOKEN_STR_LAST_LEVEL_SERIES "last_level_series" -#define TOKEN_STR_LAST_PLAYED_LEVEL "last_played_level" -#define TOKEN_STR_HANDICAP_LEVEL "handicap_level" - -/* level directory info */ -#define LEVELINFO_TOKEN_IDENTIFIER 0 -#define LEVELINFO_TOKEN_NAME 1 -#define LEVELINFO_TOKEN_NAME_SORTING 2 -#define LEVELINFO_TOKEN_AUTHOR 3 -#define LEVELINFO_TOKEN_YEAR 4 -#define LEVELINFO_TOKEN_IMPORTED_FROM 5 -#define LEVELINFO_TOKEN_IMPORTED_BY 6 -#define LEVELINFO_TOKEN_TESTED_BY 7 -#define LEVELINFO_TOKEN_LEVELS 8 -#define LEVELINFO_TOKEN_FIRST_LEVEL 9 -#define LEVELINFO_TOKEN_SORT_PRIORITY 10 -#define LEVELINFO_TOKEN_LATEST_ENGINE 11 -#define LEVELINFO_TOKEN_LEVEL_GROUP 12 -#define LEVELINFO_TOKEN_READONLY 13 -#define LEVELINFO_TOKEN_GRAPHICS_SET_ECS 14 -#define LEVELINFO_TOKEN_GRAPHICS_SET_AGA 15 -#define LEVELINFO_TOKEN_GRAPHICS_SET 16 -#define LEVELINFO_TOKEN_SOUNDS_SET 17 -#define LEVELINFO_TOKEN_MUSIC_SET 18 -#define LEVELINFO_TOKEN_FILENAME 19 -#define LEVELINFO_TOKEN_FILETYPE 20 -#define LEVELINFO_TOKEN_SPECIAL_FLAGS 21 -#define LEVELINFO_TOKEN_HANDICAP 22 -#define LEVELINFO_TOKEN_SKIP_LEVELS 23 - -#define NUM_LEVELINFO_TOKENS 24 - -static LevelDirTree ldi; - -static struct TokenInfo levelinfo_tokens[] = -{ - /* level directory info */ - { TYPE_STRING, &ldi.identifier, "identifier" }, - { TYPE_STRING, &ldi.name, "name" }, - { TYPE_STRING, &ldi.name_sorting, "name_sorting" }, - { TYPE_STRING, &ldi.author, "author" }, - { TYPE_STRING, &ldi.year, "year" }, - { TYPE_STRING, &ldi.imported_from, "imported_from" }, - { TYPE_STRING, &ldi.imported_by, "imported_by" }, - { TYPE_STRING, &ldi.tested_by, "tested_by" }, - { TYPE_INTEGER, &ldi.levels, "levels" }, - { TYPE_INTEGER, &ldi.first_level, "first_level" }, - { TYPE_INTEGER, &ldi.sort_priority, "sort_priority" }, - { TYPE_BOOLEAN, &ldi.latest_engine, "latest_engine" }, - { TYPE_BOOLEAN, &ldi.level_group, "level_group" }, - { TYPE_BOOLEAN, &ldi.readonly, "readonly" }, - { TYPE_STRING, &ldi.graphics_set_ecs, "graphics_set.ecs" }, - { TYPE_STRING, &ldi.graphics_set_aga, "graphics_set.aga" }, - { TYPE_STRING, &ldi.graphics_set, "graphics_set" }, - { TYPE_STRING, &ldi.sounds_set, "sounds_set" }, - { TYPE_STRING, &ldi.music_set, "music_set" }, - { TYPE_STRING, &ldi.level_filename, "filename" }, - { TYPE_STRING, &ldi.level_filetype, "filetype" }, - { TYPE_STRING, &ldi.special_flags, "special_flags" }, - { TYPE_BOOLEAN, &ldi.handicap, "handicap" }, - { TYPE_BOOLEAN, &ldi.skip_levels, "skip_levels" } -}; - -static struct TokenInfo artworkinfo_tokens[] = -{ - /* artwork directory info */ - { TYPE_STRING, &ldi.identifier, "identifier" }, - { TYPE_STRING, &ldi.subdir, "subdir" }, - { TYPE_STRING, &ldi.name, "name" }, - { TYPE_STRING, &ldi.name_sorting, "name_sorting" }, - { TYPE_STRING, &ldi.author, "author" }, - { TYPE_INTEGER, &ldi.sort_priority, "sort_priority" }, - { TYPE_STRING, &ldi.basepath, "basepath" }, - { TYPE_STRING, &ldi.fullpath, "fullpath" }, - { TYPE_BOOLEAN, &ldi.in_user_dir, "in_user_dir" }, - { TYPE_INTEGER, &ldi.color, "color" }, - { TYPE_STRING, &ldi.class_desc, "class_desc" }, - - { -1, NULL, NULL }, -}; - -static void setTreeInfoToDefaults(TreeInfo *ti, int type) -{ - ti->type = type; +static void setTreeInfoToDefaults(TreeInfo *ti, int type) +{ + ti->type = type; ti->node_top = (ti->type == TREE_TYPE_LEVEL_DIR ? &leveldir_first : ti->type == TREE_TYPE_GRAPHICS_DIR ? &artwork.gfx_first : @@ -2780,11 +2331,7 @@ static void setTreeInfoToDefaultsFromParent(TreeInfo *ti, TreeInfo *parent) ti->last_level = 0; ti->level_group = FALSE; ti->handicap_level = 0; -#if 1 ti->readonly = parent->readonly; -#else - ti->readonly = TRUE; -#endif ti->handicap = TRUE; ti->skip_levels = FALSE; } @@ -3082,16 +2629,7 @@ static char *getCacheToken(char *prefix, char *suffix) static char *getFileTimestampString(char *filename) { -#if 1 return getStringCopy(i_to_a(getFileTimestampEpochSeconds(filename))); -#else - struct stat file_status; - - if (stat(filename, &file_status) != 0) /* cannot stat file */ - return getStringCopy(i_to_a(0)); - - return getStringCopy(i_to_a(file_status.st_mtime)); -#endif } static boolean modifiedFileTimestamp(char *filename, char *timestamp_string) @@ -3139,9 +2677,7 @@ static TreeInfo *getArtworkInfoCacheEntry(LevelDirTree *level_node, int type) /* check if cache entry for this item is invalid or incomplete */ if (value == NULL) { -#if 1 Error(ERR_WARN, "cache entry '%s' invalid", token); -#endif cached = FALSE; } @@ -3171,11 +2707,6 @@ static TreeInfo *getArtworkInfoCacheEntry(LevelDirTree *level_node, int type) if (modifiedFileTimestamp(filename_artworkinfo, cache_entry)) cached = FALSE; -#if 0 - if (!cached) - printf("::: '%s': INVALIDATED FROM CACHE BY TIMESTAMP\n", identifier); -#endif - checked_free(filename_levelinfo); checked_free(filename_artworkinfo); } @@ -3247,10 +2778,6 @@ static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first, char *level_directory, char *directory_name) { -#if 0 - static unsigned int progress_delay = 0; - unsigned int progress_delay_value = 100; /* (in milliseconds) */ -#endif char *directory_path = getPath2(level_directory, directory_name); char *filename = getPath2(directory_path, LEVELINFO_FILENAME); SetupFileHash *setup_file_hash; @@ -3317,23 +2844,12 @@ static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first, leveldir_new->fullpath = getPath2(node_parent->fullpath, directory_name); } -#if 0 - if (leveldir_new->levels < 1) - leveldir_new->levels = 1; -#endif - leveldir_new->last_level = leveldir_new->first_level + leveldir_new->levels - 1; leveldir_new->in_user_dir = (!strEqual(leveldir_new->basepath, options.level_directory)); -#if 0 - printf("::: '%s' -> %d\n", - leveldir_new->identifier, - leveldir_new->in_user_dir); -#endif - /* adjust some settings if user's private level directory was detected */ if (leveldir_new->sort_priority == LEVELCLASS_UNDEFINED && leveldir_new->in_user_dir && @@ -3356,34 +2872,8 @@ static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first, (leveldir_new->user_defined || !leveldir_new->handicap ? leveldir_new->last_level : leveldir_new->first_level); -#if 1 -#if 1 DrawInitTextExt(leveldir_new->name, 150, FC_YELLOW, leveldir_new->level_group); -#else - if (leveldir_new->level_group || - DelayReached(&progress_delay, progress_delay_value)) - DrawInitText(leveldir_new->name, 150, FC_YELLOW); -#endif -#else - DrawInitText(leveldir_new->name, 150, FC_YELLOW); -#endif - -#if 0 - /* !!! don't skip sets without levels (else artwork base sets are missing) */ -#if 1 - if (leveldir_new->levels < 1 && !leveldir_new->level_group) - { - /* skip level sets without levels (which are probably artwork base sets) */ - - freeSetupFileHash(setup_file_hash); - free(directory_path); - free(filename); - - return FALSE; - } -#endif -#endif pushTreeInfo(node_first, leveldir_new); @@ -3405,7 +2895,6 @@ static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first, return TRUE; } -#if 1 static void LoadLevelInfoFromLevelDir(TreeInfo **node_first, TreeInfo *node_parent, char *level_directory) @@ -3414,10 +2903,6 @@ static void LoadLevelInfoFromLevelDir(TreeInfo **node_first, DirectoryEntry *dir_entry; boolean valid_entry_found = FALSE; -#if 0 - Error(ERR_INFO, "looking for levels in '%s' ...", level_directory); -#endif - if ((dir = openDirectory(level_directory)) == NULL) { Error(ERR_WARN, "cannot read level directory '%s'", level_directory); @@ -3425,346 +2910,95 @@ static void LoadLevelInfoFromLevelDir(TreeInfo **node_first, return; } -#if 0 - Error(ERR_INFO, "opening '%s' succeeded ...", level_directory); -#endif - while ((dir_entry = readDirectory(dir)) != NULL) /* loop all entries */ { char *directory_name = dir_entry->basename; char *directory_path = getPath2(level_directory, directory_name); -#if 0 - Error(ERR_INFO, "checking entry '%s' ...", directory_name); -#endif - - /* skip entries for current and parent directory */ - if (strEqual(directory_name, ".") || - strEqual(directory_name, "..")) - { - free(directory_path); - - continue; - } - -#if 1 - /* find out if directory entry is itself a directory */ - if (!dir_entry->is_directory) /* not a directory */ - { - free(directory_path); - -#if 0 - Error(ERR_INFO, "* entry '%s' is not a directory ...", directory_name); -#endif - - continue; - } -#else - /* find out if directory entry is itself a directory */ - struct stat file_status; - if (stat(directory_path, &file_status) != 0 || /* cannot stat file */ - (file_status.st_mode & S_IFMT) != S_IFDIR) /* not a directory */ - { - free(directory_path); - - continue; - } -#endif - - free(directory_path); - - if (strEqual(directory_name, GRAPHICS_DIRECTORY) || - strEqual(directory_name, SOUNDS_DIRECTORY) || - strEqual(directory_name, MUSIC_DIRECTORY)) - continue; - - valid_entry_found |= LoadLevelInfoFromLevelConf(node_first, node_parent, - level_directory, - directory_name); - } - - closeDirectory(dir); - - /* special case: top level directory may directly contain "levelinfo.conf" */ - if (node_parent == NULL && !valid_entry_found) - { - /* check if this directory directly contains a file "levelinfo.conf" */ - valid_entry_found |= LoadLevelInfoFromLevelConf(node_first, node_parent, - level_directory, "."); - } - - if (!valid_entry_found) - Error(ERR_WARN, "cannot find any valid level series in directory '%s'", - level_directory); -} - -#else - -static void LoadLevelInfoFromLevelDir(TreeInfo **node_first, - TreeInfo *node_parent, - char *level_directory) -{ - DIR *dir; - struct dirent *dir_entry; - boolean valid_entry_found = FALSE; - -#if 1 - Error(ERR_INFO, "looking for levels in '%s' ...", level_directory); -#endif - - if ((dir = opendir(level_directory)) == NULL) - { - Error(ERR_WARN, "cannot read level directory '%s'", level_directory); - - return; - } - -#if 1 - Error(ERR_INFO, "opening '%s' succeeded ...", level_directory); -#endif - - while ((dir_entry = readdir(dir)) != NULL) /* loop until last dir entry */ - { - struct stat file_status; - char *directory_name = dir_entry->d_name; - char *directory_path = getPath2(level_directory, directory_name); - -#if 1 - Error(ERR_INFO, "checking entry '%s' ...", directory_name); -#endif - - /* skip entries for current and parent directory */ - if (strEqual(directory_name, ".") || - strEqual(directory_name, "..")) - { - free(directory_path); - continue; - } - - /* find out if directory entry is itself a directory */ - if (stat(directory_path, &file_status) != 0 || /* cannot stat file */ - (file_status.st_mode & S_IFMT) != S_IFDIR) /* not a directory */ - { - free(directory_path); - continue; - } - - free(directory_path); - - if (strEqual(directory_name, GRAPHICS_DIRECTORY) || - strEqual(directory_name, SOUNDS_DIRECTORY) || - strEqual(directory_name, MUSIC_DIRECTORY)) - continue; - - valid_entry_found |= LoadLevelInfoFromLevelConf(node_first, node_parent, - level_directory, - directory_name); - } - - closedir(dir); - - /* special case: top level directory may directly contain "levelinfo.conf" */ - if (node_parent == NULL && !valid_entry_found) - { - /* check if this directory directly contains a file "levelinfo.conf" */ - valid_entry_found |= LoadLevelInfoFromLevelConf(node_first, node_parent, - level_directory, "."); - } - - if (!valid_entry_found) - Error(ERR_WARN, "cannot find any valid level series in directory '%s'", - level_directory); -} -#endif - -boolean AdjustGraphicsForEMC() -{ - boolean settings_changed = FALSE; - - settings_changed |= adjustTreeGraphicsForEMC(leveldir_first_all); - settings_changed |= adjustTreeGraphicsForEMC(leveldir_first); - - return settings_changed; -} - -void LoadLevelInfo() -{ - InitUserLevelDirectory(getLoginName()); - - DrawInitText("Loading level series", 120, FC_GREEN); - - LoadLevelInfoFromLevelDir(&leveldir_first, NULL, options.level_directory); - LoadLevelInfoFromLevelDir(&leveldir_first, NULL, getUserLevelDir(NULL)); - - /* after loading all level set information, clone the level directory tree - and remove all level sets without levels (these may still contain artwork - to be offered in the setup menu as "custom artwork", and are therefore - checked for existing artwork in the function "LoadLevelArtworkInfo()") */ - leveldir_first_all = leveldir_first; - cloneTree(&leveldir_first, leveldir_first_all, TRUE); - - AdjustGraphicsForEMC(); - - /* before sorting, the first entries will be from the user directory */ - leveldir_current = getFirstValidTreeInfoEntry(leveldir_first); - - if (leveldir_first == NULL) - Error(ERR_EXIT, "cannot find any valid level series in any directory"); - - sortTreeInfo(&leveldir_first); - -#if 0 - dumpTreeInfo(leveldir_first, 0); -#endif -} - -#if 1 - -static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, - TreeInfo *node_parent, - char *base_directory, - char *directory_name, int type) -{ - char *directory_path = getPath2(base_directory, directory_name); - char *filename = getPath2(directory_path, ARTWORKINFO_FILENAME(type)); - SetupFileHash *setup_file_hash = NULL; - TreeInfo *artwork_new = NULL; - int i; - - if (fileExists(filename)) - setup_file_hash = loadSetupFileHash(filename); - - if (setup_file_hash == NULL) /* no config file -- look for artwork files */ - { - Directory *dir; - DirectoryEntry *dir_entry; - boolean valid_file_found = FALSE; - - if ((dir = openDirectory(directory_path)) != NULL) - { - while ((dir_entry = readDirectory(dir)) != NULL) - { - char *entry_name = dir_entry->basename; - - if (FileIsArtworkType(entry_name, type)) - { - valid_file_found = TRUE; - - break; - } - } - - closeDirectory(dir); - } - - if (!valid_file_found) - { - if (!strEqual(directory_name, ".")) - Error(ERR_WARN, "ignoring artwork directory '%s'", directory_path); - - free(directory_path); - free(filename); - - return FALSE; - } - } - - artwork_new = newTreeInfo(); - - if (node_parent) - setTreeInfoToDefaultsFromParent(artwork_new, node_parent); - else - setTreeInfoToDefaults(artwork_new, type); + /* skip entries for current and parent directory */ + if (strEqual(directory_name, ".") || + strEqual(directory_name, "..")) + { + free(directory_path); - artwork_new->subdir = getStringCopy(directory_name); + continue; + } - if (setup_file_hash) /* (before defining ".color" and ".class_desc") */ - { -#if 0 - checkSetupFileHashIdentifier(setup_file_hash, filename, getCookie("...")); -#endif + /* find out if directory entry is itself a directory */ + if (!dir_entry->is_directory) /* not a directory */ + { + free(directory_path); - /* set all structure fields according to the token/value pairs */ - ldi = *artwork_new; - for (i = 0; i < NUM_LEVELINFO_TOKENS; i++) - setSetupInfo(levelinfo_tokens, i, - getHashEntry(setup_file_hash, levelinfo_tokens[i].text)); - *artwork_new = ldi; + continue; + } - if (strEqual(artwork_new->name, ANONYMOUS_NAME)) - setString(&artwork_new->name, artwork_new->subdir); + free(directory_path); - if (artwork_new->identifier == NULL) - artwork_new->identifier = getStringCopy(artwork_new->subdir); + if (strEqual(directory_name, GRAPHICS_DIRECTORY) || + strEqual(directory_name, SOUNDS_DIRECTORY) || + strEqual(directory_name, MUSIC_DIRECTORY)) + continue; - if (artwork_new->name_sorting == NULL) - artwork_new->name_sorting = getStringCopy(artwork_new->name); + valid_entry_found |= LoadLevelInfoFromLevelConf(node_first, node_parent, + level_directory, + directory_name); } - if (node_parent == NULL) /* top level group */ - { - artwork_new->basepath = getStringCopy(base_directory); - artwork_new->fullpath = getStringCopy(artwork_new->subdir); - } - else /* sub level group */ + closeDirectory(dir); + + /* special case: top level directory may directly contain "levelinfo.conf" */ + if (node_parent == NULL && !valid_entry_found) { - artwork_new->basepath = getStringCopy(node_parent->basepath); - artwork_new->fullpath = getPath2(node_parent->fullpath, directory_name); + /* check if this directory directly contains a file "levelinfo.conf" */ + valid_entry_found |= LoadLevelInfoFromLevelConf(node_first, node_parent, + level_directory, "."); } - artwork_new->in_user_dir = - (!strEqual(artwork_new->basepath, OPTIONS_ARTWORK_DIRECTORY(type))); + if (!valid_entry_found) + Error(ERR_WARN, "cannot find any valid level series in directory '%s'", + level_directory); +} - /* (may use ".sort_priority" from "setup_file_hash" above) */ - artwork_new->color = ARTWORKCOLOR(artwork_new); +boolean AdjustGraphicsForEMC() +{ + boolean settings_changed = FALSE; - setString(&artwork_new->class_desc, getLevelClassDescription(artwork_new)); + settings_changed |= adjustTreeGraphicsForEMC(leveldir_first_all); + settings_changed |= adjustTreeGraphicsForEMC(leveldir_first); - if (setup_file_hash == NULL) /* (after determining ".user_defined") */ - { - if (strEqual(artwork_new->subdir, ".")) - { - if (artwork_new->user_defined) - { - setString(&artwork_new->identifier, "private"); - artwork_new->sort_priority = ARTWORKCLASS_PRIVATE; - } - else - { - setString(&artwork_new->identifier, "classic"); - artwork_new->sort_priority = ARTWORKCLASS_CLASSICS; - } + return settings_changed; +} - /* set to new values after changing ".sort_priority" */ - artwork_new->color = ARTWORKCOLOR(artwork_new); +void LoadLevelInfo() +{ + InitUserLevelDirectory(getLoginName()); - setString(&artwork_new->class_desc, - getLevelClassDescription(artwork_new)); - } - else - { - setString(&artwork_new->identifier, artwork_new->subdir); - } + DrawInitText("Loading level series", 120, FC_GREEN); - setString(&artwork_new->name, artwork_new->identifier); - setString(&artwork_new->name_sorting, artwork_new->name); - } + LoadLevelInfoFromLevelDir(&leveldir_first, NULL, options.level_directory); + LoadLevelInfoFromLevelDir(&leveldir_first, NULL, getUserLevelDir(NULL)); -#if 0 - DrawInitText(artwork_new->name, 150, FC_YELLOW); -#endif + /* after loading all level set information, clone the level directory tree + and remove all level sets without levels (these may still contain artwork + to be offered in the setup menu as "custom artwork", and are therefore + checked for existing artwork in the function "LoadLevelArtworkInfo()") */ + leveldir_first_all = leveldir_first; + cloneTree(&leveldir_first, leveldir_first_all, TRUE); - pushTreeInfo(node_first, artwork_new); + AdjustGraphicsForEMC(); - freeSetupFileHash(setup_file_hash); + /* before sorting, the first entries will be from the user directory */ + leveldir_current = getFirstValidTreeInfoEntry(leveldir_first); - free(directory_path); - free(filename); + if (leveldir_first == NULL) + Error(ERR_EXIT, "cannot find any valid level series in any directory"); - return TRUE; -} + sortTreeInfo(&leveldir_first); -#else +#if ENABLE_UNUSED_CODE + dumpTreeInfo(leveldir_first, 0); +#endif +} static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, TreeInfo *node_parent, @@ -3782,24 +3016,25 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, if (setup_file_hash == NULL) /* no config file -- look for artwork files */ { - DIR *dir; - struct dirent *dir_entry; + Directory *dir; + DirectoryEntry *dir_entry; boolean valid_file_found = FALSE; - if ((dir = opendir(directory_path)) != NULL) + if ((dir = openDirectory(directory_path)) != NULL) { - while ((dir_entry = readdir(dir)) != NULL) + while ((dir_entry = readDirectory(dir)) != NULL) { - char *entry_name = dir_entry->d_name; + char *entry_name = dir_entry->basename; if (FileIsArtworkType(entry_name, type)) { valid_file_found = TRUE; + break; } } - closedir(dir); + closeDirectory(dir); } if (!valid_file_found) @@ -3825,10 +3060,6 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, if (setup_file_hash) /* (before defining ".color" and ".class_desc") */ { -#if 0 - checkSetupFileHashIdentifier(setup_file_hash, filename, getCookie("...")); -#endif - /* set all structure fields according to the token/value pairs */ ldi = *artwork_new; for (i = 0; i < NUM_LEVELINFO_TOKENS; i++) @@ -3895,10 +3126,6 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, setString(&artwork_new->name_sorting, artwork_new->name); } -#if 0 - DrawInitText(artwork_new->name, 150, FC_YELLOW); -#endif - pushTreeInfo(node_first, artwork_new); freeSetupFileHash(setup_file_hash); @@ -3909,10 +3136,6 @@ static boolean LoadArtworkInfoFromArtworkConf(TreeInfo **node_first, return TRUE; } -#endif - -#if 1 - static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first, TreeInfo *node_parent, char *base_directory, int type) @@ -3944,7 +3167,6 @@ static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first, continue; } -#if 1 /* skip directory entries which are not a directory */ if (!dir_entry->is_directory) /* not a directory */ { @@ -3952,17 +3174,6 @@ static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first, continue; } -#else - /* skip directory entries which are not a directory or are not accessible */ - struct stat file_status; - if (stat(directory_path, &file_status) != 0 || /* cannot stat file */ - (file_status.st_mode & S_IFMT) != S_IFDIR) /* not a directory */ - { - free(directory_path); - - continue; - } -#endif free(directory_path); @@ -3983,68 +3194,6 @@ static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first, base_directory); } -#else - -static void LoadArtworkInfoFromArtworkDir(TreeInfo **node_first, - TreeInfo *node_parent, - char *base_directory, int type) -{ - DIR *dir; - struct dirent *dir_entry; - boolean valid_entry_found = FALSE; - - if ((dir = opendir(base_directory)) == NULL) - { - /* display error if directory is main "options.graphics_directory" etc. */ - if (base_directory == OPTIONS_ARTWORK_DIRECTORY(type)) - Error(ERR_WARN, "cannot read directory '%s'", base_directory); - - return; - } - - while ((dir_entry = readdir(dir)) != NULL) /* loop until last dir entry */ - { - struct stat file_status; - char *directory_name = dir_entry->d_name; - char *directory_path = getPath2(base_directory, directory_name); - - /* skip directory entries for current and parent directory */ - if (strEqual(directory_name, ".") || - strEqual(directory_name, "..")) - { - free(directory_path); - continue; - } - - /* skip directory entries which are not a directory or are not accessible */ - if (stat(directory_path, &file_status) != 0 || /* cannot stat file */ - (file_status.st_mode & S_IFMT) != S_IFDIR) /* not a directory */ - { - free(directory_path); - continue; - } - - free(directory_path); - - /* check if this directory contains artwork with or without config file */ - valid_entry_found |= LoadArtworkInfoFromArtworkConf(node_first, node_parent, - base_directory, - directory_name, type); - } - - closedir(dir); - - /* check if this directory directly contains artwork itself */ - valid_entry_found |= LoadArtworkInfoFromArtworkConf(node_first, node_parent, - base_directory, ".", - type); - if (!valid_entry_found) - Error(ERR_WARN, "cannot find any valid artwork in directory '%s'", - base_directory); -} - -#endif - static TreeInfo *getDummyArtworkInfo(int type) { /* this is only needed when there is completely no artwork available */ @@ -4126,7 +3275,7 @@ void LoadArtworkInfo() artwork.snd_current_identifier = artwork.snd_current->identifier; artwork.mus_current_identifier = artwork.mus_current->identifier; -#if 0 +#if ENABLE_UNUSED_CODE printf("graphics set == %s\n\n", artwork.gfx_current_identifier); printf("sounds set == %s\n\n", artwork.snd_current_identifier); printf("music set == %s\n\n", artwork.mus_current_identifier); @@ -4136,7 +3285,7 @@ void LoadArtworkInfo() sortTreeInfo(&artwork.snd_first); sortTreeInfo(&artwork.mus_first); -#if 0 +#if ENABLE_UNUSED_CODE dumpTreeInfo(artwork.gfx_first, 0); dumpTreeInfo(artwork.snd_first, 0); dumpTreeInfo(artwork.mus_first, 0); @@ -4146,10 +3295,6 @@ void LoadArtworkInfo() void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node, LevelDirTree *level_node) { -#if 0 - static unsigned int progress_delay = 0; - unsigned int progress_delay_value = 100; /* (in milliseconds) */ -#endif int type = (*artwork_node)->type; /* recursively check all level directories for artwork sub-directories */ @@ -4194,14 +3339,8 @@ void LoadArtworkInfoFromLevelInfo(ArtworkDirTree **artwork_node, setArtworkInfoCacheEntry(artwork_new, level_node, type); } -#if 1 DrawInitTextExt(level_node->name, 150, FC_YELLOW, level_node->level_group); -#else - if (level_node->level_group || - DelayReached(&progress_delay, progress_delay_value)) - DrawInitText(level_node->name, 150, FC_YELLOW); -#endif if (level_node->node_group != NULL) LoadArtworkInfoFromLevelInfo(artwork_node, level_node->node_group); @@ -4272,7 +3411,7 @@ void LoadLevelArtworkInfo() print_timestamp_time("sortTreeInfo"); -#if 0 +#if ENABLE_UNUSED_CODE dumpTreeInfo(artwork.gfx_first, 0); dumpTreeInfo(artwork.snd_first, 0); dumpTreeInfo(artwork.mus_first, 0); @@ -4530,15 +3669,10 @@ void SaveLevelSetup_LastSeries_Deactivate() SaveLevelSetup_LastSeries_Ext(TRUE); } -#if 1 - static void checkSeriesInfo() { static char *level_directory = NULL; Directory *dir; -#if 0 - DirectoryEntry *dir_entry; -#endif /* check for more levels besides the 'levels' field of 'levelinfo.conf' */ @@ -4554,96 +3688,9 @@ static void checkSeriesInfo() return; } -#if 0 - while ((dir_entry = readDirectory(dir)) != NULL) /* last directory entry */ - { - if (strlen(dir_entry->basename) > 4 && - dir_entry->basename[3] == '.' && - strEqual(&dir_entry->basename[4], LEVELFILE_EXTENSION)) - { - char levelnum_str[4]; - int levelnum_value; - - strncpy(levelnum_str, dir_entry->basename, 3); - levelnum_str[3] = '\0'; - - levelnum_value = atoi(levelnum_str); - - if (levelnum_value < leveldir_current->first_level) - { - Error(ERR_WARN, "additional level %d found", levelnum_value); - leveldir_current->first_level = levelnum_value; - } - else if (levelnum_value > leveldir_current->last_level) - { - Error(ERR_WARN, "additional level %d found", levelnum_value); - leveldir_current->last_level = levelnum_value; - } - } - } -#endif - closeDirectory(dir); } -#else - -static void checkSeriesInfo() -{ - static char *level_directory = NULL; - DIR *dir; -#if 0 - struct dirent *dir_entry; -#endif - - /* check for more levels besides the 'levels' field of 'levelinfo.conf' */ - - level_directory = getPath2((leveldir_current->in_user_dir ? - getUserLevelDir(NULL) : - options.level_directory), - leveldir_current->fullpath); - - if ((dir = opendir(level_directory)) == NULL) - { - Error(ERR_WARN, "cannot read level directory '%s'", level_directory); - - return; - } - -#if 0 - while ((dir_entry = readdir(dir)) != NULL) /* last directory entry */ - { - if (strlen(dir_entry->d_name) > 4 && - dir_entry->d_name[3] == '.' && - strEqual(&dir_entry->d_name[4], LEVELFILE_EXTENSION)) - { - char levelnum_str[4]; - int levelnum_value; - - strncpy(levelnum_str, dir_entry->d_name, 3); - levelnum_str[3] = '\0'; - - levelnum_value = atoi(levelnum_str); - - if (levelnum_value < leveldir_current->first_level) - { - Error(ERR_WARN, "additional level %d found", levelnum_value); - leveldir_current->first_level = levelnum_value; - } - else if (levelnum_value > leveldir_current->last_level) - { - Error(ERR_WARN, "additional level %d found", levelnum_value); - leveldir_current->last_level = levelnum_value; - } - } - } -#endif - - closedir(dir); -} - -#endif - void LoadLevelSetup_SeriesInfo() { char *filename; diff --git a/src/libgame/sound.c b/src/libgame/sound.c index f1c4aaf7..591ea7d4 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -20,19 +20,6 @@ #include #include "platform.h" - -#if defined(PLATFORM_LINUX) -#include -#include -#elif defined(PLATFORM_FREEBSD) -#include -#elif defined(PLATFORM_NETBSD) -#include -#include -#elif defined(PLATFORM_HPUX) -#include -#endif - #include "system.h" #include "sound.h" #include "misc.h" @@ -46,11 +33,6 @@ /* one second fading interval == 1000 ticks (milliseconds) */ #define SOUND_FADING_INTERVAL 1000 -#if defined(AUDIO_STREAMING_DSP) -#define SOUND_FADING_VOLUME_STEP (SOUND_MAX_VOLUME / 40) -#define SOUND_FADING_VOLUME_THRESHOLD (SOUND_FADING_VOLUME_STEP * 2) -#endif - #define SND_TYPE_NONE 0 #define SND_TYPE_WAV 1 @@ -83,19 +65,6 @@ SOUND_VOLUME_LOOPS(v) : \ SOUND_VOLUME_SIMPLE(v)) - -#if defined(AUDIO_UNIX_NATIVE) -struct SoundHeader_WAV -{ - unsigned short compression_code; - unsigned short num_channels; - unsigned int sample_rate; - unsigned int bytes_per_second; - unsigned short block_align; - unsigned short bits_per_sample; -}; -#endif - struct AudioFormatInfo { boolean stereo; /* availability of stereo sound */ @@ -154,16 +123,6 @@ static int stereo_volume[SOUND_MAX_LEFT2RIGHT + 1]; static struct SoundControl mixer[NUM_MIXER_CHANNELS]; static int mixer_active_channels = 0; -#if defined(AUDIO_UNIX_NATIVE) -static struct AudioFormatInfo afmt; - -static void Mixer_Main(void); -#if !defined(AUDIO_STREAMING_DSP) -static unsigned char linear_to_ulaw(int); -static int ulaw_to_linear(unsigned char); -#endif -#endif - static void ReloadCustomSounds(); static void ReloadCustomMusic(); static void FreeSound(void *); @@ -174,442 +133,6 @@ static SoundInfo *getSoundInfoEntryFromSoundID(int); static MusicInfo *getMusicInfoEntryFromMusicID(int); -/* ------------------------------------------------------------------------- */ -/* functions for native (non-SDL) Unix audio/mixer support */ -/* ------------------------------------------------------------------------- */ - -#if defined(AUDIO_UNIX_NATIVE) - -static int OpenAudioDevice(char *audio_device_name) -{ - int audio_device_fd; - - /* check if desired audio device is accessible */ - if (access(audio_device_name, W_OK) != 0) - return -1; - - /* try to open audio device in non-blocking mode */ - if ((audio_device_fd = open(audio_device_name, O_WRONLY | O_NONBLOCK)) < 0) - return audio_device_fd; - - /* re-open audio device in blocking mode */ - close(audio_device_fd); - audio_device_fd = open(audio_device_name, O_WRONLY); - - return audio_device_fd; -} - -static void CloseAudioDevice(int *audio_device_fd) -{ - if (*audio_device_fd == 0) - return; - - close(*audio_device_fd); - *audio_device_fd = -1; -} - -static boolean TestAudioDevices(void) -{ - static char *audio_device_name[] = - { - DEVICENAME_DSP, - DEVICENAME_SOUND_DSP, - DEVICENAME_AUDIO - }; - int audio_device_fd = -1; - int i; - - /* look for available audio devices, starting with preferred ones */ - for (i = 0; i < sizeof(audio_device_name)/sizeof(char *); i++) - if ((audio_device_fd = OpenAudioDevice(audio_device_name[i])) >= 0) - break; - - if (audio_device_fd < 0) - { - Error(ERR_WARN, "cannot open audio device -- no sound"); - return FALSE; - } - - close(audio_device_fd); - - audio.device_name = audio_device_name[i]; - - return TRUE; -} - -static boolean ForkAudioProcess(void) -{ - if (pipe(audio.mixer_pipe) < 0) - { - Error(ERR_WARN, "cannot create pipe -- no sounds"); - return FALSE; - } - - if ((audio.mixer_pid = fork()) < 0) - { - Error(ERR_WARN, "cannot create sound server process -- no sounds"); - return FALSE; - } - - if (audio.mixer_pid == 0) /* we are the child process */ - audio.mixer_pid = getpid(); - - if (IS_CHILD_PROCESS()) - Mixer_Main(); /* this function never returns */ - else - close(audio.mixer_pipe[0]); /* no reading from pipe needed */ - - return TRUE; -} - -void UnixOpenAudio(void) -{ - if (!TestAudioDevices()) - return; - - audio.sound_available = TRUE; - audio.sound_enabled = TRUE; - -#if defined(AUDIO_STREAMING_DSP) - audio.music_available = TRUE; - audio.loops_available = TRUE; -#endif - - audio.num_channels = NUM_MIXER_CHANNELS; - audio.music_channel = MUSIC_CHANNEL; - audio.first_sound_channel = FIRST_SOUND_CHANNEL; -} - -void UnixCloseAudio(void) -{ - if (audio.device_fd) - close(audio.device_fd); - - if (IS_PARENT_PROCESS() && HAS_CHILD_PROCESS()) - kill(audio.mixer_pid, SIGTERM); -} - - -/* ------------------------------------------------------------------------- */ -/* functions for platform specific audio device initialization */ -/* ------------------------------------------------------------------------- */ - -#if defined(AUDIO_LINUX_IOCTL) -static void InitAudioDevice_Linux(struct AudioFormatInfo *afmt) -{ - /* "ioctl()" expects pointer to 'int' value for stereo flag - (boolean is defined as 'char', which will not work here) */ - unsigned int fragment_spec = 0; - int fragment_size_query = -1; - int stereo = TRUE; - struct - { - int format_ioctl; - int format_result; - } - formats[] = - { - /* supported audio format in preferred order */ - { AFMT_S16_LE, AUDIO_FORMAT_S16 | AUDIO_FORMAT_LE }, - { AFMT_S16_BE, AUDIO_FORMAT_S16 | AUDIO_FORMAT_BE }, - { AFMT_U8, AUDIO_FORMAT_U8 }, - { -1, -1 } - }; - int i; - - /* determine logarithm (log2) of the fragment size */ - while ((1 << fragment_spec) < afmt->fragment_size) - fragment_spec++; - - /* use two fragments (play one fragment, prepare the other); - one fragment would result in interrupted audio output, more - than two fragments would raise audio output latency to much */ - fragment_spec |= 0x00020000; - - /* Example for fragment specification: - - 2 buffers / 512 bytes (giving 1/16 second resolution for 8 kHz) - - (with stereo the effective buffer size will shrink to 256) - => fragment_size = 0x00020009 */ - - if (ioctl(audio.device_fd, SNDCTL_DSP_SETFRAGMENT, &fragment_spec) < 0) - Error(ERR_EXIT_SOUND_SERVER, - "cannot set fragment size of audio device -- no sounds"); - - i = 0; - afmt->format = 0; - while (formats[i].format_result != -1) - { - unsigned int audio_format = formats[i].format_ioctl; - if (ioctl(audio.device_fd, SNDCTL_DSP_SETFMT, &audio_format) == 0) - { - afmt->format = formats[i].format_result; - break; - } - } - - if (afmt->format == 0) /* no supported audio format found */ - Error(ERR_EXIT_SOUND_SERVER, - "cannot set audio format of audio device -- no sounds"); - - /* try if we can use stereo sound */ - afmt->stereo = TRUE; - if (ioctl(audio.device_fd, SNDCTL_DSP_STEREO, &stereo) < 0) - afmt->stereo = FALSE; - - if (ioctl(audio.device_fd, SNDCTL_DSP_SPEED, &afmt->sample_rate) < 0) - Error(ERR_EXIT_SOUND_SERVER, - "cannot set sample rate of audio device -- no sounds"); - - /* get the real fragmentation size; this should return 512 */ - if (ioctl(audio.device_fd, SNDCTL_DSP_GETBLKSIZE, &fragment_size_query) < 0) - Error(ERR_EXIT_SOUND_SERVER, - "cannot get fragment size of audio device -- no sounds"); - if (fragment_size_query != afmt->fragment_size) - Error(ERR_EXIT_SOUND_SERVER, - "cannot set fragment size of audio device -- no sounds"); -} -#endif /* AUDIO_LINUX_IOCTL */ - -#if defined(PLATFORM_NETBSD) -static void InitAudioDevice_NetBSD(struct AudioFormatInfo *afmt) -{ - audio_info_t a_info; - boolean stereo = TRUE; - - AUDIO_INITINFO(&a_info); - a_info.play.encoding = AUDIO_ENCODING_LINEAR8; - a_info.play.precision = 8; - a_info.play.channels = 2; - a_info.play.sample_rate = afmt->sample_rate; - a_info.blocksize = afmt->fragment_size; - - afmt->format = AUDIO_FORMAT_U8; - afmt->stereo = TRUE; - - if (ioctl(audio.device_fd, AUDIO_SETINFO, &a_info) < 0) - { - /* try to disable stereo */ - a_info.play.channels = 1; - - afmt->stereo = FALSE; - - if (ioctl(audio.device_fd, AUDIO_SETINFO, &a_info) < 0) - Error(ERR_EXIT_SOUND_SERVER, - "cannot set sample rate of audio device -- no sounds"); - } -} -#endif /* PLATFORM_NETBSD */ - -#if defined(PLATFORM_HPUX) -static void InitAudioDevice_HPUX(struct AudioFormatInfo *afmt) -{ - struct audio_describe ainfo; - int audio_ctl; - - audio_ctl = open("/dev/audioCtl", O_WRONLY | O_NDELAY); - if (audio_ctl == -1) - Error(ERR_EXIT_SOUND_SERVER, "cannot open audio device -- no sounds"); - - if (ioctl(audio_ctl, AUDIO_DESCRIBE, &ainfo) == -1) - Error(ERR_EXIT_SOUND_SERVER, "no audio info -- no sounds"); - - if (ioctl(audio_ctl, AUDIO_SET_DATA_FORMAT, AUDIO_FORMAT_ULAW) == -1) - Error(ERR_EXIT_SOUND_SERVER, "ulaw audio not available -- no sounds"); - - ioctl(audio_ctl, AUDIO_SET_CHANNELS, 1); - ioctl(audio_ctl, AUDIO_SET_SAMPLE_RATE, 8000); - - afmt->format = AUDIO_FORMAT_U8; - afmt->stereo = FALSE; - afmt->sample_rate = 8000; - - close(audio_ctl); -} -#endif /* PLATFORM_HPUX */ - -static void InitAudioDevice(struct AudioFormatInfo *afmt) -{ - afmt->stereo = TRUE; - afmt->format = AUDIO_FORMAT_UNKNOWN; - afmt->sample_rate = DEFAULT_AUDIO_SAMPLE_RATE; - afmt->fragment_size = DEFAULT_AUDIO_FRAGMENT_SIZE; - -#if defined(AUDIO_LINUX_IOCTL) - InitAudioDevice_Linux(afmt); -#elif defined(PLATFORM_NETBSD) - InitAudioDevice_NetBSD(afmt); -#elif defined(PLATFORM_HPUX) - InitAudioDevice_HPUX(afmt); -#else - /* generic /dev/audio stuff might be placed here */ -#endif -} - - -/* ------------------------------------------------------------------------- */ -/* functions for communication between main process and sound mixer process */ -/* ------------------------------------------------------------------------- */ - -static void SendSoundControlToMixerProcess(SoundControl *snd_ctrl) -{ - if (IS_CHILD_PROCESS()) - return; - - if (write(audio.mixer_pipe[1], snd_ctrl, sizeof(SoundControl)) < 0) - { - Error(ERR_WARN, "cannot pipe to child process -- no sounds"); - audio.sound_available = audio.sound_enabled = FALSE; - return; - } -} - -static void ReadSoundControlFromMainProcess(SoundControl *snd_ctrl) -{ - if (IS_PARENT_PROCESS()) - return; - - if (read(audio.mixer_pipe[0], snd_ctrl, sizeof(SoundControl)) - != sizeof(SoundControl)) - Error(ERR_EXIT_SOUND_SERVER, "broken pipe -- no sounds"); -} - -static void WriteReloadInfoToPipe(char *set_identifier, int type) -{ - SoundControl snd_ctrl; - TreeInfo *ti = (type == SND_CTRL_RELOAD_SOUNDS ? artwork.snd_current : - artwork.mus_current); - unsigned int str_size1 = strlen(leveldir_current->fullpath) + 1; - unsigned int str_size2 = strlen(leveldir_current->sounds_path) + 1; - unsigned int str_size3 = strlen(leveldir_current->music_path) + 1; - unsigned int str_size4 = strlen(ti->basepath) + 1; - unsigned int str_size5 = strlen(ti->fullpath) + 1; - boolean override_level_artwork = (type == SND_CTRL_RELOAD_SOUNDS ? - gfx.override_level_sounds : - gfx.override_level_music); - - if (IS_CHILD_PROCESS()) - return; - - if (leveldir_current == NULL) /* should never happen */ - Error(ERR_EXIT, "leveldir_current == NULL"); - - clear_mem(&snd_ctrl, sizeof(SoundControl)); /* to make valgrind happy */ - - snd_ctrl.active = FALSE; - snd_ctrl.state = type; - snd_ctrl.data_len = strlen(set_identifier) + 1; - - if (write(audio.mixer_pipe[1], &snd_ctrl, - sizeof(snd_ctrl)) < 0 || - write(audio.mixer_pipe[1], set_identifier, - snd_ctrl.data_len) < 0 || - write(audio.mixer_pipe[1], &override_level_artwork, - sizeof(boolean)) < 0 || - write(audio.mixer_pipe[1], leveldir_current, - sizeof(TreeInfo)) < 0 || - write(audio.mixer_pipe[1], ti, - sizeof(TreeInfo)) < 0 || - write(audio.mixer_pipe[1], &str_size1, - sizeof(unsigned int)) < 0 || - write(audio.mixer_pipe[1], &str_size2, - sizeof(unsigned int)) < 0 || - write(audio.mixer_pipe[1], &str_size3, - sizeof(unsigned int)) < 0 || - write(audio.mixer_pipe[1], &str_size4, - sizeof(unsigned int)) < 0 || - write(audio.mixer_pipe[1], &str_size5, - sizeof(unsigned int)) < 0 || - write(audio.mixer_pipe[1], leveldir_current->fullpath, - str_size1) < 0 || - write(audio.mixer_pipe[1], leveldir_current->sounds_path, - str_size2) < 0 || - write(audio.mixer_pipe[1], leveldir_current->music_path, - str_size3) < 0 || - write(audio.mixer_pipe[1], ti->basepath, - str_size4) < 0 || - write(audio.mixer_pipe[1], ti->fullpath, - str_size5) < 0) - { - Error(ERR_WARN, "cannot pipe to child process -- no sounds"); - audio.sound_available = audio.sound_enabled = FALSE; - return; - } -} - -static void ReadReloadInfoFromPipe(SoundControl *snd_ctrl) -{ - TreeInfo **ti_ptr = ((snd_ctrl->state & SND_CTRL_RELOAD_SOUNDS) ? - &artwork.snd_current : &artwork.mus_current); - TreeInfo *ti = *ti_ptr; - unsigned int str_size1, str_size2, str_size3, str_size4, str_size5; - static char *set_identifier = NULL; - boolean *override_level_artwork = (snd_ctrl->state & SND_CTRL_RELOAD_SOUNDS ? - &gfx.override_level_sounds : - &gfx.override_level_music); - - checked_free(set_identifier); - - set_identifier = checked_malloc(snd_ctrl->data_len); - - if (leveldir_current == NULL) - leveldir_current = checked_calloc(sizeof(TreeInfo)); - - if (ti == NULL) - ti = *ti_ptr = checked_calloc(sizeof(TreeInfo)); - - checked_free(leveldir_current->fullpath); - checked_free(leveldir_current->sounds_path); - checked_free(leveldir_current->music_path); - checked_free(ti->basepath); - checked_free(ti->fullpath); - - if (read(audio.mixer_pipe[0], set_identifier, - snd_ctrl->data_len) != snd_ctrl->data_len || - read(audio.mixer_pipe[0], override_level_artwork, - sizeof(boolean)) != sizeof(boolean) || - read(audio.mixer_pipe[0], leveldir_current, - sizeof(TreeInfo)) != sizeof(TreeInfo) || - read(audio.mixer_pipe[0], ti, - sizeof(TreeInfo)) != sizeof(TreeInfo) || - read(audio.mixer_pipe[0], &str_size1, - sizeof(unsigned int)) != sizeof(unsigned int) || - read(audio.mixer_pipe[0], &str_size2, - sizeof(unsigned int)) != sizeof(unsigned int) || - read(audio.mixer_pipe[0], &str_size3, - sizeof(unsigned int)) != sizeof(unsigned int) || - read(audio.mixer_pipe[0], &str_size4, - sizeof(unsigned int)) != sizeof(unsigned int) || - read(audio.mixer_pipe[0], &str_size5, - sizeof(unsigned int)) != sizeof(unsigned int)) - Error(ERR_EXIT_SOUND_SERVER, "broken pipe -- no sounds"); - - leveldir_current->fullpath = checked_calloc(str_size1); - leveldir_current->sounds_path = checked_calloc(str_size2); - leveldir_current->music_path = checked_calloc(str_size3); - ti->basepath = checked_calloc(str_size4); - ti->fullpath = checked_calloc(str_size5); - - if (read(audio.mixer_pipe[0], leveldir_current->fullpath, - str_size1) != str_size1 || - read(audio.mixer_pipe[0], leveldir_current->sounds_path, - str_size2) != str_size2 || - read(audio.mixer_pipe[0], leveldir_current->music_path, - str_size3) != str_size3 || - read(audio.mixer_pipe[0], ti->basepath, - str_size4) != str_size4 || - read(audio.mixer_pipe[0], ti->fullpath, - str_size5) != str_size5) - Error(ERR_EXIT_SOUND_SERVER, "broken pipe -- no sounds"); - - if (snd_ctrl->state & SND_CTRL_RELOAD_SOUNDS) - artwork.snd_current_identifier = set_identifier; - else - artwork.mus_current_identifier = set_identifier; -} - -#endif /* AUDIO_UNIX_NATIVE */ - - /* ------------------------------------------------------------------------- */ /* mixer functions */ /* ------------------------------------------------------------------------- */ @@ -627,10 +150,8 @@ static void Mixer_ResetChannelExpiration(int channel) { mixer[channel].playing_starttime = Counter(); -#if defined(TARGET_SDL) if (IS_LOOP(mixer[channel]) && !IS_MUSIC(mixer[channel])) Mix_ExpireChannel(channel, SOUND_LOOP_EXPIRATION_TIME); -#endif } static boolean Mixer_ChannelExpired(int channel) @@ -643,10 +164,8 @@ static boolean Mixer_ChannelExpired(int channel) SOUND_LOOP_EXPIRATION_TIME)) return TRUE; -#if defined(TARGET_SDL) if (!Mix_Playing(channel)) return TRUE; -#endif return FALSE; } @@ -658,20 +177,16 @@ static boolean Mixer_AllocateChannel(int channel) static void Mixer_SetChannelProperties(int channel) { -#if defined(TARGET_SDL) Mix_Volume(channel, mixer[channel].volume); Mix_SetPanning(channel, SOUND_VOLUME_LEFT(mixer[channel].stereo_position), SOUND_VOLUME_RIGHT(mixer[channel].stereo_position)); -#endif } static void Mixer_StartChannel(int channel) { -#if defined(TARGET_SDL) Mix_PlayChannel(channel, mixer[channel].data_ptr, IS_LOOP(mixer[channel]) ? -1 : 0); -#endif } static void Mixer_PlayChannel(int channel) @@ -699,7 +214,6 @@ static void Mixer_PlayMusicChannel() { Mixer_PlayChannel(audio.music_channel); -#if defined(TARGET_SDL) if (mixer[audio.music_channel].type != MUS_TYPE_WAV) { /* Mix_VolumeMusic() must be called _after_ Mix_PlayMusic() -- @@ -707,7 +221,6 @@ static void Mixer_PlayMusicChannel() Mix_PlayMusic(mixer[audio.music_channel].data_ptr, -1); Mix_VolumeMusic(mixer[audio.music_channel].volume); } -#endif } static void Mixer_StopChannel(int channel) @@ -715,9 +228,7 @@ static void Mixer_StopChannel(int channel) if (!mixer[channel].active) return; -#if defined(TARGET_SDL) Mix_HaltChannel(channel); -#endif mixer[channel].active = FALSE; mixer_active_channels--; @@ -727,9 +238,7 @@ static void Mixer_StopMusicChannel() { Mixer_StopChannel(audio.music_channel); -#if defined(TARGET_SDL) Mix_HaltMusic(); -#endif } static void Mixer_FadeChannel(int channel) @@ -739,18 +248,14 @@ static void Mixer_FadeChannel(int channel) mixer[channel].state |= SND_CTRL_FADE; -#if defined(TARGET_SDL) Mix_FadeOutChannel(channel, SOUND_FADING_INTERVAL); -#endif } static void Mixer_FadeMusicChannel() { Mixer_FadeChannel(audio.music_channel); -#if defined(TARGET_SDL) Mix_FadeOutMusic(SOUND_FADING_INTERVAL); -#endif } static void Mixer_UnFadeChannel(int channel) @@ -761,10 +266,8 @@ static void Mixer_UnFadeChannel(int channel) mixer[channel].state &= ~SND_CTRL_FADE; mixer[channel].volume = SOUND_MAX_VOLUME; -#if defined(TARGET_SDL) Mix_ExpireChannel(channel, -1); Mix_Volume(channel, mixer[channel].volume); -#endif } static void Mixer_InsertSound(SoundControl snd_ctrl) @@ -903,17 +406,6 @@ static void Mixer_InsertSound(SoundControl snd_ctrl) unsigned int playing_current = Counter(); int longest = 0, longest_nr = audio.first_sound_channel; -#if 0 -#if DEBUG - /* print some debugging information about audio channel usage */ - for (i = audio.first_sound_channel; i < audio.num_channels; i++) - { - Error(ERR_INFO, "Mixer_InsertSound: %d [%d]: %d (%d)", - i, mixer[i].active, mixer[i].data_len, (int)mixer[i].data_ptr); - } -#endif -#endif - for (i = audio.first_sound_channel; i < audio.num_channels; i++) { int playing_time = playing_current - mixer[i].playing_starttime; @@ -934,13 +426,6 @@ static void Mixer_InsertSound(SoundControl snd_ctrl) { if (!mixer[i].active) { -#if defined(AUDIO_UNIX_NATIVE) - if (snd_info->data_len == 0) - { - printf("THIS SHOULD NEVER HAPPEN! [snd_info->data_len == 0]\n"); - } -#endif - mixer[i] = snd_ctrl; Mixer_PlayChannel(i); @@ -953,14 +438,6 @@ static void HandleSoundRequest(SoundControl snd_ctrl) { int i; -#if defined(AUDIO_UNIX_NATIVE) - if (IS_PARENT_PROCESS()) - { - SendSoundControlToMixerProcess(&snd_ctrl); - return; - } -#endif - /* deactivate channels that have expired since the last request */ for (i = 0; i < audio.num_channels; i++) if (mixer[i].active && Mixer_ChannelExpired(i)) @@ -972,11 +449,6 @@ static void HandleSoundRequest(SoundControl snd_ctrl) for (i = audio.first_sound_channel; i < audio.num_channels; i++) Mixer_StopChannel(i); -#if defined(AUDIO_UNIX_NATIVE) - CloseAudioDevice(&audio.device_fd); - ReadReloadInfoFromPipe(&snd_ctrl); -#endif - if (snd_ctrl.state & SND_CTRL_RELOAD_SOUNDS) ReloadCustomSounds(); else @@ -1005,11 +477,6 @@ static void HandleSoundRequest(SoundControl snd_ctrl) for (i = audio.first_sound_channel; i < audio.num_channels; i++) if (SAME_SOUND_NR(mixer[i], snd_ctrl) || ALL_SOUNDS(snd_ctrl)) Mixer_StopChannel(i); - -#if defined(AUDIO_UNIX_NATIVE) - if (!mixer_active_channels) - CloseAudioDevice(&audio.device_fd); -#endif } else if (snd_ctrl.active) /* add new sound to mixer */ { @@ -1021,21 +488,6 @@ void StartMixer(void) { int i; -#if 0 - SDL_version compile_version; - const SDL_version *link_version; - MIX_VERSION(&compile_version); - printf("compiled with SDL_mixer version: %d.%d.%d\n", - compile_version.major, - compile_version.minor, - compile_version.patch); - link_version = Mix_Linked_Version(); - printf("running with SDL_mixer version: %d.%d.%d\n", - link_version->major, - link_version->minor, - link_version->patch); -#endif - if (!audio.sound_available) return; @@ -1043,445 +495,7 @@ void StartMixer(void) for (i = 0; i <= SOUND_MAX_LEFT2RIGHT; i++) stereo_volume[i] = (int)sqrt((float)(SOUND_MAX_LEFT2RIGHT * SOUND_MAX_LEFT2RIGHT - i * i)); - -#if defined(AUDIO_UNIX_NATIVE) - if (!ForkAudioProcess()) - audio.sound_available = FALSE; -#endif -} - -#if defined(AUDIO_UNIX_NATIVE) - -static void CopySampleToMixingBuffer(SoundControl *snd_ctrl, - int sample_pos, int sample_size, - short *buffer_base_ptr, int buffer_pos, - int num_output_channels) -{ - short *buffer_ptr = buffer_base_ptr + num_output_channels * buffer_pos; - int num_channels = snd_ctrl->num_channels; - int stepsize = num_channels; - int output_stepsize = num_output_channels; - int i, j; - - if (snd_ctrl->format == AUDIO_FORMAT_U8) - { - byte *sample_ptr = (byte *)snd_ctrl->data_ptr + num_channels * sample_pos; - - for (i = 0; i < num_output_channels; i++) - { - int offset = (snd_ctrl->num_channels == 1 ? 0 : i); - - for (j = 0; j < sample_size; j++) - buffer_ptr[output_stepsize * j + i] = - ((short)(sample_ptr[stepsize * j + offset] ^ 0x80)) << 8; - } - } - else /* AUDIO_FORMAT_S16 */ - { - short *sample_ptr= (short *)snd_ctrl->data_ptr + num_channels * sample_pos; - - for (i = 0; i < num_output_channels; i++) - { - int offset = (snd_ctrl->num_channels == 1 ? 0 : i); - - for (j = 0; j < sample_size; j++) - buffer_ptr[output_stepsize * j + i] = - sample_ptr[stepsize * j + offset]; - } - } -} - -#if defined(AUDIO_STREAMING_DSP) -static void Mixer_Main_DSP() -{ - static short premix_first_buffer[DEFAULT_AUDIO_FRAGMENT_SIZE]; - static int premix_last_buffer[DEFAULT_AUDIO_FRAGMENT_SIZE]; - static byte playing_buffer[DEFAULT_AUDIO_FRAGMENT_SIZE]; - boolean stereo; - int fragment_size; - int sample_bytes; - int max_sample_size; - int num_output_channels; - int i, j; - - if (!mixer_active_channels) - return; - - if (audio.device_fd < 0) - { - if ((audio.device_fd = OpenAudioDevice(audio.device_name)) < 0) - return; - - InitAudioDevice(&afmt); - } - - stereo = afmt.stereo; - fragment_size = afmt.fragment_size; - sample_bytes = (afmt.format & AUDIO_FORMAT_U8 ? 1 : 2); - num_output_channels = (stereo ? 2 : 1); - max_sample_size = fragment_size / (num_output_channels * sample_bytes); - - /* first clear the last premixing buffer */ - clear_mem(premix_last_buffer, - max_sample_size * num_output_channels * sizeof(int)); - - for (i = 0; i < audio.num_channels; i++) - { - // void *sample_ptr; - int sample_len; - int sample_pos; - int sample_size; - - if (!mixer[i].active) - continue; - - if (Mixer_ChannelExpired(i)) - { - Mixer_StopChannel(i); - continue; - } - - /* pointer, lenght and actual playing position of sound sample */ - // sample_ptr = mixer[i].data_ptr; - sample_len = mixer[i].data_len; - sample_pos = mixer[i].playing_pos; - sample_size = MIN(max_sample_size, sample_len - sample_pos); - mixer[i].playing_pos += sample_size; - - /* copy original sample to first mixing buffer */ - CopySampleToMixingBuffer(&mixer[i], sample_pos, sample_size, - premix_first_buffer, 0, num_output_channels); - - /* are we about to restart a looping sound? */ - if (IS_LOOP(mixer[i]) && sample_size < max_sample_size) - { - while (sample_size < max_sample_size) - { - int restarted_sample_size = - MIN(max_sample_size - sample_size, sample_len); - - CopySampleToMixingBuffer(&mixer[i], 0, restarted_sample_size, - premix_first_buffer, sample_size, - num_output_channels); - - mixer[i].playing_pos = restarted_sample_size; - sample_size += restarted_sample_size; - } - } - - /* decrease volume if sound is fading out */ - if (IS_FADING(mixer[i]) && - mixer[i].volume >= SOUND_FADING_VOLUME_THRESHOLD) - mixer[i].volume -= SOUND_FADING_VOLUME_STEP; - - /* adjust volume of actual sound sample */ - if (mixer[i].volume != SOUND_MAX_VOLUME) - for (j = 0; j < sample_size * num_output_channels; j++) - premix_first_buffer[j] = - mixer[i].volume * (int)premix_first_buffer[j] / SOUND_MAX_VOLUME; - - /* adjust left and right channel volume due to stereo sound position */ - if (stereo) - { - int left_volume = SOUND_VOLUME_LEFT(mixer[i].stereo_position); - int right_volume = SOUND_VOLUME_RIGHT(mixer[i].stereo_position); - - for (j = 0; j < sample_size; j++) - { - premix_first_buffer[2 * j + 0] = - left_volume * premix_first_buffer[2 * j + 0] / SOUND_MAX_LEFT2RIGHT; - premix_first_buffer[2 * j + 1] = - right_volume * premix_first_buffer[2 * j + 1] / SOUND_MAX_LEFT2RIGHT; - } - } - - /* fill the last mixing buffer with stereo or mono sound */ - for (j = 0; j < sample_size * num_output_channels; j++) - premix_last_buffer[j] += premix_first_buffer[j]; - - /* delete completed sound entries from the mixer */ - if (mixer[i].playing_pos >= mixer[i].data_len) - { - if (IS_LOOP(mixer[i])) - mixer[i].playing_pos = 0; - else - Mixer_StopChannel(i); - } - else if (mixer[i].volume <= SOUND_FADING_VOLUME_THRESHOLD) - Mixer_StopChannel(i); - } - - /* prepare final playing buffer according to system audio format */ - for (i = 0; i < max_sample_size * num_output_channels; i++) - { - /* cut off at 17 bit value */ - if (premix_last_buffer[i] < -65535) - premix_last_buffer[i] = -65535; - else if (premix_last_buffer[i] > 65535) - premix_last_buffer[i] = 65535; - - /* shift to 16 bit value */ - premix_last_buffer[i] >>= 1; - - if (afmt.format & AUDIO_FORMAT_U8) - { - playing_buffer[i] = (premix_last_buffer[i] >> 8) ^ 0x80; - } - else if (afmt.format & AUDIO_FORMAT_LE) /* 16 bit */ - { - playing_buffer[2 * i + 0] = premix_last_buffer[i] & 0xff; - playing_buffer[2 * i + 1] = premix_last_buffer[i] >> 8; - } - else /* big endian */ - { - playing_buffer[2 * i + 0] = premix_last_buffer[i] >> 8; - playing_buffer[2 * i + 1] = premix_last_buffer[i] & 0xff; - } - } - - /* finally play the sound fragment */ - if (write(audio.device_fd, playing_buffer, fragment_size) == -1) - Error(ERR_WARN, "write() failed; %s", strerror(errno)); - - if (!mixer_active_channels) - CloseAudioDevice(&audio.device_fd); -} - -#else /* !AUDIO_STREAMING_DSP */ - -static int Mixer_Main_SimpleAudio(SoundControl snd_ctrl) -{ - static short premix_first_buffer[DEFAULT_AUDIO_FRAGMENT_SIZE]; - static byte playing_buffer[DEFAULT_AUDIO_FRAGMENT_SIZE]; - int max_sample_size = DEFAULT_AUDIO_FRAGMENT_SIZE; - int num_output_channels = 1; - void *sample_ptr; - int sample_len; - int sample_pos; - int sample_size; - int i, j; - - i = 1; - - /* pointer, lenght and actual playing position of sound sample */ - sample_ptr = mixer[i].data_ptr; - sample_len = mixer[i].data_len; - sample_pos = mixer[i].playing_pos; - sample_size = MIN(max_sample_size, sample_len - sample_pos); - mixer[i].playing_pos += sample_size; - - /* copy original sample to first mixing buffer */ - CopySampleToMixingBuffer(&mixer[i], sample_pos, sample_size, - premix_first_buffer, 0, num_output_channels); - - /* adjust volume of actual sound sample */ - if (mixer[i].volume != SOUND_MAX_VOLUME) - for (j = 0; j < sample_size; j++) - premix_first_buffer[j] = - mixer[i].volume * (int)premix_first_buffer[j] / SOUND_MAX_VOLUME; - - /* might be needed for u-law /dev/audio */ - for (j = 0; j < sample_size; j++) - playing_buffer[j] = - linear_to_ulaw(premix_first_buffer[j]); - - /* delete completed sound entries from the mixer */ - if (mixer[i].playing_pos >= mixer[i].data_len) - Mixer_StopChannel(i); - - for (i = 0; i < sample_size; i++) - playing_buffer[i] = (premix_first_buffer[i] >> 8) ^ 0x80; - - /* finally play the sound fragment */ - write(audio.device_fd, playing_buffer, sample_size); - - return sample_size; -} -#endif /* !AUDIO_STREAMING_DSP */ - -void Mixer_Main() -{ - SoundControl snd_ctrl; - fd_set mixer_fdset; - - close(audio.mixer_pipe[1]); /* no writing into pipe needed */ - - Mixer_InitChannels(); - -#if defined(PLATFORM_HPUX) - InitAudioDevice(&afmt); -#endif - - FD_ZERO(&mixer_fdset); - FD_SET(audio.mixer_pipe[0], &mixer_fdset); - - while (1) /* wait for sound playing commands from client */ - { - struct timeval delay = { 0, 0 }; - - FD_SET(audio.mixer_pipe[0], &mixer_fdset); - select(audio.mixer_pipe[0] + 1, &mixer_fdset, NULL, NULL, NULL); - if (!FD_ISSET(audio.mixer_pipe[0], &mixer_fdset)) - continue; - - ReadSoundControlFromMainProcess(&snd_ctrl); - - HandleSoundRequest(snd_ctrl); - -#if defined(AUDIO_STREAMING_DSP) - - while (mixer_active_channels && - select(audio.mixer_pipe[0] + 1, - &mixer_fdset, NULL, NULL, &delay) < 1) - { - FD_SET(audio.mixer_pipe[0], &mixer_fdset); - - Mixer_Main_DSP(); - } - -#else /* !AUDIO_STREAMING_DSP */ - - if (!snd_ctrl.active || IS_LOOP(snd_ctrl) || - (audio.device_fd = OpenAudioDevice(audio.device_name)) < 0) - continue; - - InitAudioDevice(&afmt); - - delay.tv_sec = 0; - delay.tv_usec = 0; - - while (mixer_active_channels && - select(audio.mixer_pipe[0] + 1, - &mixer_fdset, NULL, NULL, &delay) < 1) - { - int wait_percent = 90; /* wait 90% of the real playing time */ - int sample_size; - - FD_SET(audio.mixer_pipe[0], &mixer_fdset); - - sample_size = Mixer_Main_SimpleAudio(snd_ctrl); - - delay.tv_sec = 0; - delay.tv_usec = - ((sample_size * 10 * wait_percent) / afmt.sample_rate) * 1000; - } - - CloseAudioDevice(&audio.device_fd); - - Mixer_InitChannels(); /* remove all sounds from mixer */ - -#endif /* !AUDIO_STREAMING_DSP */ - } } -#endif /* AUDIO_UNIX_NATIVE */ - - -#if defined(AUDIO_UNIX_NATIVE) && !defined(AUDIO_STREAMING_DSP) - -/* these two are stolen from "sox"... :) */ - -/* -** This routine converts from linear to ulaw. -** -** Craig Reese: IDA/Supercomputing Research Center -** Joe Campbell: Department of Defense -** 29 September 1989 -** -** References: -** 1) CCITT Recommendation G.711 (very difficult to follow) -** 2) "A New Digital Technique for Implementation of Any -** Continuous PCM Companding Law," Villeret, Michel, -** et al. 1973 IEEE Int. Conf. on Communications, Vol 1, -** 1973, pg. 11.12-11.17 -** 3) MIL-STD-188-113,"Interoperability and Performance Standards -** for Analog-to_Digital Conversion Techniques," -** 17 February 1987 -** -** Input: Signed 16 bit linear sample -** Output: 8 bit ulaw sample -*/ - -#define ZEROTRAP /* turn on the trap as per the MIL-STD */ -#define BIAS 0x84 /* define the add-in bias for 16 bit samples */ -#define CLIP 32635 - -static unsigned char linear_to_ulaw(int sample) -{ - static int exp_lut[256] = - { - 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3, - 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, - 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, - 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, - 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, - 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, - 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, - 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 - }; - - int sign, exponent, mantissa; - unsigned char ulawbyte; - - /* Get the sample into sign-magnitude. */ - sign = (sample >> 8) & 0x80; /* set aside the sign */ - if (sign != 0) - sample = -sample; /* get magnitude */ - if (sample > CLIP) - sample = CLIP; /* clip the magnitude */ - - /* Convert from 16 bit linear to ulaw. */ - sample = sample + BIAS; - exponent = exp_lut[( sample >> 7 ) & 0xFF]; - mantissa = ( sample >> ( exponent + 3 ) ) & 0x0F; - ulawbyte = ~ ( sign | ( exponent << 4 ) | mantissa ); -#ifdef ZEROTRAP - if (ulawbyte == 0) - ulawbyte = 0x02; /* optional CCITT trap */ -#endif - - return(ulawbyte); -} - -/* -** This routine converts from ulaw to 16 bit linear. -** -** Craig Reese: IDA/Supercomputing Research Center -** 29 September 1989 -** -** References: -** 1) CCITT Recommendation G.711 (very difficult to follow) -** 2) MIL-STD-188-113,"Interoperability and Performance Standards -** for Analog-to_Digital Conversion Techniques," -** 17 February 1987 -** -** Input: 8 bit ulaw sample -** Output: signed 16 bit linear sample -*/ - -static int ulaw_to_linear(unsigned char ulawbyte) -{ - static int exp_lut[8] = { 0, 132, 396, 924, 1980, 4092, 8316, 16764 }; - int sign, exponent, mantissa, sample; - - ulawbyte = ~ ulawbyte; - sign = ( ulawbyte & 0x80 ); - exponent = ( ulawbyte >> 4 ) & 0x07; - mantissa = ulawbyte & 0x0F; - sample = exp_lut[exponent] + ( mantissa << ( exponent + 3 ) ); - if (sign != 0) - sample = -sample; - - return(sample); -} -#endif /* AUDIO_UNIX_NATIVE && !AUDIO_STREAMING_DSP */ /* THE STUFF ABOVE IS ONLY USED BY THE SOUND SERVER CHILD PROCESS */ @@ -1494,25 +508,12 @@ static int ulaw_to_linear(unsigned char ulawbyte) static void *Load_WAV(char *filename) { SoundInfo *snd_info; -#if defined(AUDIO_UNIX_NATIVE) - struct SoundHeader_WAV header; -#if 0 - byte sound_header_buffer[WAV_HEADER_SIZE]; - int i; -#endif - char chunk_name[CHUNK_ID_LEN + 1]; - int chunk_size; - int data_byte_len; - FILE *file; -#endif if (!audio.sound_available) return NULL; snd_info = checked_calloc(sizeof(SoundInfo)); -#if defined(TARGET_SDL) - if ((snd_info->data_ptr = Mix_LoadWAV(filename)) == NULL) { Error(ERR_WARN, "cannot read sound file '%s'", filename); @@ -1522,171 +523,6 @@ static void *Load_WAV(char *filename) snd_info->data_len = ((Mix_Chunk *)snd_info->data_ptr)->alen; -#else /* AUDIO_UNIX_NATIVE */ - - clear_mem(&header, sizeof(struct SoundHeader_WAV)); /* to make gcc happy */ - - if ((file = fopen(filename, MODE_READ)) == NULL) - { - Error(ERR_WARN, "cannot open sound file '%s'", filename); - free(snd_info); - return NULL; - } - - /* read chunk id "RIFF" */ - getFileChunkLE(file, chunk_name, &chunk_size); - if (!strEqual(chunk_name, "RIFF")) - { - Error(ERR_WARN, "missing 'RIFF' chunk of sound file '%s'", filename); - fclose(file); - free(snd_info); - return NULL; - } - - /* read "RIFF" type id "WAVE" */ - getFileChunkLE(file, chunk_name, NULL); - if (!strEqual(chunk_name, "WAVE")) - { - Error(ERR_WARN, "missing 'WAVE' type ID of sound file '%s'", filename); - fclose(file); - free(snd_info); - return NULL; - } - - while (getFileChunkLE(file, chunk_name, &chunk_size)) - { - if (strEqual(chunk_name, "fmt ")) - { - if (chunk_size < WAV_HEADER_SIZE) - { - Error(ERR_WARN, "sound file '%s': chunk 'fmt ' too short", filename); - fclose(file); - free(snd_info); - return NULL; - } - - header.compression_code = getFile16BitLE(file); - header.num_channels = getFile16BitLE(file); - header.sample_rate = getFile32BitLE(file); - header.bytes_per_second = getFile32BitLE(file); - header.block_align = getFile16BitLE(file); - header.bits_per_sample = getFile16BitLE(file); - - if (chunk_size > WAV_HEADER_SIZE) - ReadUnusedBytesFromFile(file, chunk_size - WAV_HEADER_SIZE); - - if (header.compression_code != 1) - { - Error(ERR_WARN, "sound file '%s': compression code %d not supported", - filename, header.compression_code); - fclose(file); - free(snd_info); - return NULL; - } - - if (header.num_channels != 1 && - header.num_channels != 2) - { - Error(ERR_WARN, "sound file '%s': number of %d channels not supported", - filename, header.num_channels); - fclose(file); - free(snd_info); - return NULL; - } - - if (header.bits_per_sample != 8 && - header.bits_per_sample != 16) - { - Error(ERR_WARN, "sound file '%s': %d bits per sample not supported", - filename, header.bits_per_sample); - fclose(file); - free(snd_info); - return NULL; - } - - /* warn, but accept wrong sample rate (may be only slightly different) */ - if (header.sample_rate != DEFAULT_AUDIO_SAMPLE_RATE) - Error(ERR_WARN, "sound file '%s': wrong sample rate %d instead of %d", - filename, header.sample_rate, DEFAULT_AUDIO_SAMPLE_RATE); - -#if 0 - printf("WAV file: '%s'\n", filename); - printf(" Compression code: %d'\n", header.compression_code); - printf(" Number of channels: %d'\n", header.num_channels); - printf(" Sample rate: %d'\n", header.sample_rate); - printf(" Average bytes per second: %d'\n", header.bytes_per_second); - printf(" Block align: %d'\n", header.block_align); - printf(" Significant bits per sample: %d'\n", header.bits_per_sample); -#endif - } - else if (strEqual(chunk_name, "data")) - { - data_byte_len = chunk_size; - - snd_info->data_len = data_byte_len; - snd_info->data_ptr = checked_malloc(snd_info->data_len); - - /* read sound data */ - if (fread(snd_info->data_ptr, 1, snd_info->data_len, file) != - snd_info->data_len) - { - Error(ERR_WARN,"cannot read 'data' chunk of sound file '%s'",filename); - fclose(file); - free(snd_info->data_ptr); - free(snd_info); - return NULL; - } - - /* check for odd number of data bytes (data chunk is word aligned) */ - if ((data_byte_len % 2) == 1) - ReadUnusedBytesFromFile(file, 1); - } - else /* unknown chunk -- ignore */ - ReadUnusedBytesFromFile(file, chunk_size); - } - - fclose(file); - - if (snd_info->data_ptr == NULL) - { - Error(ERR_WARN, "missing 'data' chunk of sound file '%s'", filename); - free(snd_info); - return NULL; - } - - if (header.bits_per_sample == 8) - snd_info->format = AUDIO_FORMAT_U8; - else /* header.bits_per_sample == 16 */ - { - snd_info->format = AUDIO_FORMAT_S16; - snd_info->data_len /= 2; /* correct number of samples */ - } - - snd_info->num_channels = header.num_channels; - if (header.num_channels == 2) - snd_info->data_len /= 2; /* correct number of samples */ - -#if 0 - if (header.num_channels == 1) /* convert mono sound to stereo */ - { - void *buffer_ptr = checked_malloc(data_byte_len * 2); - void *sample_ptr = snd_info->data_ptr; - int sample_size = snd_info->data_len; - int i; - - if (snd_ctrl->format == AUDIO_FORMAT_U8) - for (i = 0; i < sample_size; i++) - *buffer_ptr++ = - ((short)(((byte *)sample_ptr)[i] ^ 0x80)) << 8; - else /* AUDIO_FORMAT_S16 */ - for (i = 0; i < sample_size; i++) - *buffer_ptr++ = - ((short *)sample_ptr)[i]; - } -#endif - -#endif /* AUDIO_UNIX_NATIVE */ - snd_info->type = SND_TYPE_WAV; snd_info->source_filename = getStringCopy(filename); @@ -1695,7 +531,6 @@ static void *Load_WAV(char *filename) static void *Load_MOD(char *filename) { -#if defined(TARGET_SDL) MusicInfo *mod_info; if (!audio.sound_available) @@ -1714,32 +549,18 @@ static void *Load_MOD(char *filename) mod_info->source_filename = getStringCopy(filename); return mod_info; -#else - return NULL; -#endif } static void *Load_WAV_or_MOD(char *filename) { -#if 1 if (FileIsMusic(filename)) return Load_MOD(filename); else if (FileIsSound(filename)) return Load_WAV(filename); else return NULL; -#else - if (FileIsSound(filename)) - return Load_WAV(filename); - else if (FileIsMusic(filename)) - return Load_MOD(filename); - else - return NULL; -#endif } -#if 1 - void LoadCustomMusic_NoConf(void) { static boolean draw_init_text = TRUE; /* only draw at startup */ @@ -1821,91 +642,6 @@ void LoadCustomMusic_NoConf(void) draw_init_text = FALSE; } -#else - -void LoadCustomMusic_NoConf(void) -{ - static boolean draw_init_text = TRUE; /* only draw at startup */ - static char *last_music_directory = NULL; - char *music_directory = getCustomMusicDirectory(); - DIR *dir; - struct dirent *dir_entry; - int num_music = getMusicListSize(); - - if (!audio.sound_available) - return; - - if (last_music_directory != NULL && - strEqual(last_music_directory, music_directory)) - return; /* old and new music directory are the same */ - - if (last_music_directory != NULL) - free(last_music_directory); - last_music_directory = getStringCopy(music_directory); - - FreeAllMusic_NoConf(); - - if ((dir = opendir(music_directory)) == NULL) - { - Error(ERR_WARN, "cannot read music directory '%s'", music_directory); - - audio.music_available = FALSE; - - return; - } - - if (draw_init_text) - DrawInitText("Loading music", 120, FC_GREEN); - - while ((dir_entry = readdir(dir)) != NULL) /* loop until last dir entry */ - { - char *basename = dir_entry->d_name; - char *filename = NULL; - MusicInfo *mus_info = NULL; - boolean music_already_used = FALSE; - int i; - - /* skip all music files that are configured in music config file */ - for (i = 0; i < num_music; i++) - { - struct FileInfo *music = getMusicListEntry(i); - - if (strEqual(basename, music->filename)) - { - music_already_used = TRUE; - break; - } - } - - if (music_already_used) - continue; - - if (draw_init_text) - DrawInitText(basename, 150, FC_YELLOW); - - filename = getPath2(music_directory, basename); - - if (FileIsMusic(basename)) - mus_info = Load_WAV_or_MOD(filename); - - free(filename); - - if (mus_info) - { - num_music_noconf++; - Music_NoConf = checked_realloc(Music_NoConf, - num_music_noconf * sizeof(MusicInfo *)); - Music_NoConf[num_music_noconf - 1] = mus_info; - } - } - - closedir(dir); - - draw_init_text = FALSE; -} - -#endif - int getSoundListSize() { return (sound_info->num_file_list_entries + @@ -2261,20 +997,12 @@ void StopSoundExt(int nr, int state) static void ReloadCustomSounds() { -#if 0 - printf("::: reloading sounds '%s' ...\n", artwork.snd_current_identifier); -#endif - LoadArtworkConfig(sound_info); ReloadCustomArtworkList(sound_info); } static void ReloadCustomMusic() { -#if 0 - printf("::: reloading music '%s' ...\n", artwork.mus_current_identifier); -#endif - LoadArtworkConfig(music_info); ReloadCustomArtworkList(music_info); @@ -2287,12 +1015,7 @@ void InitReloadCustomSounds(char *set_identifier) if (!audio.sound_available) return; -#if defined(AUDIO_UNIX_NATIVE) - LoadArtworkConfig(sound_info); /* also load config on sound client */ - WriteReloadInfoToPipe(set_identifier, SND_CTRL_RELOAD_SOUNDS); -#else ReloadCustomSounds(); -#endif } void InitReloadCustomMusic(char *set_identifier) @@ -2300,12 +1023,7 @@ void InitReloadCustomMusic(char *set_identifier) if (!audio.music_available) return; -#if defined(AUDIO_UNIX_NATIVE) - LoadArtworkConfig(music_info); /* also load config on sound client */ - WriteReloadInfoToPipe(set_identifier, SND_CTRL_RELOAD_MUSIC); -#else ReloadCustomMusic(); -#endif } void FreeSound(void *ptr) @@ -2317,11 +1035,7 @@ void FreeSound(void *ptr) if (sound->data_ptr) { -#if defined(TARGET_SDL) Mix_FreeChunk(sound->data_ptr); -#else /* AUDIO_UNIX_NATIVE */ - free(sound->data_ptr); -#endif } checked_free(sound->source_filename); @@ -2338,14 +1052,10 @@ void FreeMusic(void *ptr) if (music->data_ptr) { -#if defined(TARGET_SDL) if (music->type == MUS_TYPE_MOD) Mix_FreeMusic(music->data_ptr); else Mix_FreeChunk(music->data_ptr); -#else /* AUDIO_UNIX_NATIVE */ - free(music->data_ptr); -#endif } free(music); diff --git a/src/libgame/sound.h b/src/libgame/sound.h index 586f0fe5..9e2d2420 100644 --- a/src/libgame/sound.h +++ b/src/libgame/sound.h @@ -15,16 +15,7 @@ #include "system.h" -#if defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD) || defined(VOXWARE) -#define AUDIO_LINUX_IOCTL -#endif - -#if defined(AUDIO_LINUX_IOCTL) || defined(PLATFORM_NETBSD) -#define AUDIO_STREAMING_DSP -#endif - /* values for platform specific sound initialization */ -#define AUDIO_SAMPLE_RATE_8000 8000 #define AUDIO_SAMPLE_RATE_22050 22050 #define AUDIO_FRAGMENT_SIZE_512 512 @@ -42,25 +33,15 @@ #define AUDIO_FORMAT_LE (1 << 2) #define AUDIO_FORMAT_BE (1 << 3) -#if defined(AUDIO_UNIX_NATIVE) && !defined(AUDIO_STREAMING_DSP) -#define DEFAULT_AUDIO_SAMPLE_RATE AUDIO_SAMPLE_RATE_8000 -#else #define DEFAULT_AUDIO_SAMPLE_RATE AUDIO_SAMPLE_RATE_22050 -#endif -#if defined(PLATFORM_HPUX) -#define DEFAULT_AUDIO_FRAGMENT_SIZE AUDIO_FRAGMENT_SIZE_32768 -#elif defined(PLATFORM_WIN32) +#if defined(PLATFORM_WIN32) #define DEFAULT_AUDIO_FRAGMENT_SIZE AUDIO_FRAGMENT_SIZE_1024 #else #define DEFAULT_AUDIO_FRAGMENT_SIZE AUDIO_FRAGMENT_SIZE_512 #endif -#if defined(TARGET_SDL) #define NUM_MIXER_CHANNELS MIX_CHANNELS -#else -#define NUM_MIXER_CHANNELS 8 -#endif #define MUSIC_CHANNEL 0 #define FIRST_SOUND_CHANNEL 1 @@ -101,11 +82,7 @@ #define SOUND_MIN_VOLUME 0 -#if defined(TARGET_SDL) #define SOUND_MAX_VOLUME SDL_MIX_MAXVOLUME -#else -#define SOUND_MAX_VOLUME 128 -#endif #define SOUND_MAX_LEFT 0 #define SOUND_MAX_RIGHT 255 diff --git a/src/libgame/system.c b/src/libgame/system.c index e5105b44..aa344da5 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -21,6 +21,8 @@ #include "joystick.h" #include "misc.h" +#define ENABLE_UNUSED_CODE 0 /* currently unused functions */ + /* ========================================================================= */ /* exported variables */ @@ -102,9 +104,7 @@ void SetWindowTitle() { program.window_title = program.window_title_function(); -#if defined(TARGET_SDL) SDLSetWindowTitle(); -#endif } void InitWindowTitleFunction(char *(*window_title_function)(void)) @@ -125,10 +125,8 @@ void InitExitFunction(void (*exit_function)(int)) signal(SIGINT, exit_function); signal(SIGTERM, exit_function); -#if defined(TARGET_SDL) /* set exit function to automatically cleanup SDL stuff after exit() */ atexit(SDL_Quit); -#endif } void InitPlatformDependentStuff(void) @@ -140,15 +138,8 @@ void InitPlatformDependentStuff(void) updateUserGameDataDir(); #endif -#if 1 - openErrorFile(); -#else -#if !defined(PLATFORM_UNIX) || defined(PLATFORM_MACOSX) openErrorFile(); -#endif -#endif -#if defined(TARGET_SDL) #if defined(TARGET_SDL2) int sdl_init_flags = SDL_INIT_EVENTS | SDL_INIT_NOPARACHUTE; #else @@ -159,7 +150,6 @@ void InitPlatformDependentStuff(void) Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError()); SDLNet_Init(); -#endif } void ClosePlatformDependentStuff(void) @@ -185,11 +175,6 @@ void InitGfxFieldInfo(int sx, int sy, int sxsize, int sysize, gfx.field_save_buffer = field_save_buffer; -#if 0 - gfx.background_bitmap = NULL; - gfx.background_bitmap_mask = REDRAW_NONE; -#endif - SetDrawDeactivationMask(REDRAW_NONE); /* do not deactivate drawing */ SetDrawBackgroundMask(REDRAW_NONE); /* deactivate masked drawing */ } @@ -229,11 +214,9 @@ void InitGfxWindowInfo(int win_xsize, int win_ysize) gfx.win_xsize = win_xsize; gfx.win_ysize = win_ysize; -#if 1 gfx.background_bitmap_mask = REDRAW_NONE; ReCreateBitmap(&gfx.background_bitmap, win_xsize, win_ysize, DEFAULT_DEPTH); -#endif } void InitGfxScrollbufferInfo(int scrollbuffer_width, int scrollbuffer_height) @@ -277,33 +260,6 @@ void SetDrawBackgroundMask(int draw_background_mask) gfx.draw_background_mask = draw_background_mask; } -#if 0 - -static void DrawBitmapFromTile(Bitmap *bitmap, Bitmap *tile, - int dest_x, int dest_y, int width, int height) -{ - int bitmap_xsize = width; - int bitmap_ysize = height; - int tile_xsize = tile->width; - int tile_ysize = tile->height; - int tile_xsteps = (bitmap_xsize + tile_xsize - 1) / tile_xsize; - int tile_ysteps = (bitmap_ysize + tile_ysize - 1) / tile_ysize; - int x, y; - - for (y = 0; y < tile_ysteps; y++) - { - for (x = 0; x < tile_xsteps; x++) - { - int draw_x = dest_x + x * tile_xsize; - int draw_y = dest_y + y * tile_ysize; - int draw_xsize = MIN(tile_xsize, bitmap_xsize - x * tile_xsize); - int draw_ysize = MIN(tile_ysize, bitmap_ysize - y * tile_ysize); - - BlitBitmap(tile, bitmap, 0, 0, draw_xsize, draw_ysize, draw_x, draw_y); - } - } -} - void SetBackgroundBitmap(Bitmap *background_bitmap_tile, int mask) { if (background_bitmap_tile != NULL) @@ -311,43 +267,6 @@ void SetBackgroundBitmap(Bitmap *background_bitmap_tile, int mask) else gfx.background_bitmap_mask &= ~mask; -#if 0 - if (gfx.background_bitmap == NULL) - gfx.background_bitmap = CreateBitmap(video.width, video.height, - DEFAULT_DEPTH); -#endif - - if (background_bitmap_tile == NULL) /* empty background requested */ - return; - - if (mask == REDRAW_ALL) - DrawBitmapFromTile(gfx.background_bitmap, background_bitmap_tile, - 0, 0, video.width, video.height); - else if (mask == REDRAW_FIELD) - DrawBitmapFromTile(gfx.background_bitmap, background_bitmap_tile, - gfx.real_sx, gfx.real_sy, - gfx.full_sxsize, gfx.full_sysize); - else if (mask == REDRAW_DOOR_1) - DrawBitmapFromTile(gfx.background_bitmap, background_bitmap_tile, - gfx.dx, gfx.dy, - gfx.dxsize, gfx.dysize); -} - -#else - -void SetBackgroundBitmap(Bitmap *background_bitmap_tile, int mask) -{ - if (background_bitmap_tile != NULL) - gfx.background_bitmap_mask |= mask; - else - gfx.background_bitmap_mask &= ~mask; - -#if 0 - if (gfx.background_bitmap == NULL) - gfx.background_bitmap = CreateBitmap(video.width, video.height, - DEFAULT_DEPTH); -#endif - if (background_bitmap_tile == NULL) /* empty background requested */ return; @@ -362,8 +281,6 @@ void SetBackgroundBitmap(Bitmap *background_bitmap_tile, int mask) gfx.dx, gfx.dy, gfx.dxsize, gfx.dysize); } -#endif - void SetWindowBackgroundBitmap(Bitmap *background_bitmap_tile) { /* remove every mask before setting mask for window */ @@ -414,9 +331,7 @@ inline static void sysCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, void LimitScreenUpdates(boolean enable) { -#if defined(TARGET_SDL) SDLLimitScreenUpdates(enable); -#endif } void InitVideoDisplay(void) @@ -428,31 +343,17 @@ void CloseVideoDisplay(void) { KeyboardAutoRepeatOn(); -#if defined(TARGET_SDL) SDL_QuitSubSystem(SDL_INIT_VIDEO); -#else - if (display) - XCloseDisplay(display); -#endif } void InitVideoBuffer(int width, int height, int depth, boolean fullscreen) { -#if 0 - printf("::: InitVideoBuffer\n"); -#endif - video.width = width; video.height = height; video.depth = GetRealDepth(depth); video.fullscreen_available = FULLSCREEN_STATUS; video.fullscreen_enabled = FALSE; - // video.fullscreen_initial = FALSE; -#if 0 - video.fullscreen_mode_current = NULL; - video.fullscreen_modes = NULL; -#endif video.window_scaling_available = WINDOW_SCALING_STATUS; @@ -541,7 +442,6 @@ inline static boolean CheckDrawingArea(int x, int y, int width, int height, if (draw_mask & REDRAW_ALL) return TRUE; -#if 1 if ((draw_mask & REDRAW_FIELD) && IN_GFX_FIELD_FULL(x, y)) return TRUE; @@ -553,19 +453,6 @@ inline static boolean CheckDrawingArea(int x, int y, int width, int height, if ((draw_mask & REDRAW_DOOR_3) && IN_GFX_DOOR_3(x, y)) return TRUE; -#else - if ((draw_mask & REDRAW_FIELD) && - x >= gfx.real_sx && x < gfx.real_sx + gfx.full_sxsize) - return TRUE; - - if ((draw_mask & REDRAW_DOOR_1) && - x >= gfx.dx && y < gfx.dy + gfx.dysize) - return TRUE; - - if ((draw_mask & REDRAW_DOOR_2) && - x >= gfx.dx && y >= gfx.vy) - return TRUE; -#endif return FALSE; } @@ -584,7 +471,6 @@ boolean DrawingOnBackground(int x, int y) static boolean InClippedRectangle(Bitmap *bitmap, int *x, int *y, int *width, int *height, boolean is_dest) { -#if 1 int clip_x, clip_y, clip_width, clip_height; if (gfx.clipping_enabled && is_dest) /* only clip destination bitmap */ @@ -633,41 +519,6 @@ static boolean InClippedRectangle(Bitmap *bitmap, int *x, int *y, } return TRUE; - -#else - - /* skip if rectangle completely outside bitmap */ - - if (*x + *width <= 0 || - *y + *height <= 0 || - *x >= bitmap->width || - *y >= bitmap->height) - return FALSE; - - /* clip if rectangle overlaps bitmap */ - - if (*x < 0) - { - *width += *x; - *x = 0; - } - else if (*x + *width > bitmap->width) - { - *width = bitmap->width - *x; - } - - if (*y < 0) - { - *height += *y; - *y = 0; - } - else if (*y + *height > bitmap->height) - { - *height = bitmap->height - *y; - } - - return TRUE; -#endif } void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap, @@ -683,7 +534,6 @@ void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap, if (DrawingDeactivated(dst_x, dst_y, width, height)) return; -#if 1 if (!InClippedRectangle(src_bitmap, &src_x, &src_y, &width, &height, FALSE) || !InClippedRectangle(dst_bitmap, &dst_x, &dst_y, &width, &height, TRUE)) return; @@ -692,40 +542,16 @@ void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap, src_x += dst_x - dst_x_unclipped; src_y += dst_y - dst_y_unclipped; -#else - /* skip if rectangle starts outside bitmap */ - if (src_x >= src_bitmap->width || - src_y >= src_bitmap->height || - dst_x >= dst_bitmap->width || - dst_y >= dst_bitmap->height) - return; - - /* clip if rectangle overlaps bitmap */ - if (src_x + width > src_bitmap->width) - width = src_bitmap->width - src_x; - if (src_y + height > src_bitmap->height) - height = src_bitmap->height - src_y; - if (dst_x + width > dst_bitmap->width) - width = dst_bitmap->width - dst_x; - if (dst_y + height > dst_bitmap->height) - height = dst_bitmap->height - dst_y; -#endif - -#if 1 +#if defined(TARGET_SDL2) /* !!! 2013-12-11: An "old friend" is back. Same bug in SDL2 2.0.1 !!! */ -#if 1 /* !!! 2009-03-30: Fixed by using self-compiled, patched SDL.dll !!! */ /* (This bug still exists in the actual (as of 2009-06-15) version 1.2.13, but is already fixed in SVN and should therefore finally be fixed with the next official SDL release, which is probably version 1.2.14.) */ -#if 1 /* !!! 2009-03-24: It seems that this problem still exists in 1.2.12 !!! */ - //#if defined(TARGET_SDL) && defined(PLATFORM_WIN32) -#if defined(TARGET_SDL2) + if (src_bitmap == dst_bitmap) { - /* !!! THIS IS A BUG (IN THE SDL LIBRARY?) AND SHOULD BE FIXED !!! */ - /* needed when blitting directly to same bitmap -- should not be needed with recent SDL libraries, but apparently does not work in 1.2.11 directly */ @@ -764,15 +590,6 @@ void BlitBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap, return; } #endif -#endif -#endif -#endif - -#if 0 - if (dst_x < gfx.sx + gfx.sxsize) - printf("::: %d: BlitBitmap(%d, %d, %d, %d)\n", - FrameCounter, dst_x, dst_y, width, height); -#endif sysCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height, dst_x, dst_y, BLIT_OPAQUE); @@ -809,11 +626,9 @@ void FadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height, int fade_mode, int fade_delay, int post_delay, void (*draw_border_function)(void)) { -#if 1 /* (use destination bitmap "backbuffer" -- "bitmap_cross" may be undefined) */ if (!InClippedRectangle(backbuffer, &x, &y, &width, &height, TRUE)) return; -#endif SDLFadeRectangle(bitmap_cross, x, y, width, height, fade_mode, fade_delay, post_delay, draw_border_function); @@ -825,21 +640,8 @@ void FillRectangle(Bitmap *bitmap, int x, int y, int width, int height, if (DrawingDeactivated(x, y, width, height)) return; -#if 1 if (!InClippedRectangle(bitmap, &x, &y, &width, &height, TRUE)) return; -#else - /* skip if rectangle starts outside bitmap */ - if (x >= bitmap->width || - y >= bitmap->height) - return; - - /* clip if rectangle overlaps bitmap */ - if (x + width > bitmap->width) - width = bitmap->width - x; - if (y + height > bitmap->height) - height = bitmap->height - y; -#endif sysFillRectangle(bitmap, x, y, width, height, color); } @@ -984,7 +786,6 @@ void SyncDisplay(void) void KeyboardAutoRepeatOn(void) { -#if defined(TARGET_SDL) #if defined(TARGET_SDL2) keyrepeat_status = TRUE; #else @@ -992,42 +793,21 @@ void KeyboardAutoRepeatOn(void) SDL_DEFAULT_REPEAT_INTERVAL / 2); SDL_EnableUNICODE(1); #endif -#else - if (display) - XAutoRepeatOn(display); -#endif } void KeyboardAutoRepeatOff(void) { -#if defined(TARGET_SDL) #if defined(TARGET_SDL2) keyrepeat_status = FALSE; #else SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); SDL_EnableUNICODE(0); #endif -#else - if (display) - XAutoRepeatOff(display); -#endif } boolean PointerInWindow(DrawWindow *window) { -#if defined(TARGET_SDL) return TRUE; -#else - Window root, child; - int root_x, root_y; - unsigned int mask; - int win_x, win_y; - - /* if XQueryPointer() returns False, the pointer - is not on the same screen as the specified window */ - return XQueryPointer(display, window->drawable, &root, &child, - &root_x, &root_y, &win_x, &win_y, &mask); -#endif } boolean SetVideoMode(boolean fullscreen) @@ -1037,11 +817,9 @@ boolean SetVideoMode(boolean fullscreen) boolean ChangeVideoModeIfNeeded(boolean fullscreen) { -#if defined(TARGET_SDL) if ((fullscreen && !video.fullscreen_enabled && video.fullscreen_available)|| (!fullscreen && video.fullscreen_enabled)) fullscreen = SetVideoMode(fullscreen); -#endif return fullscreen; } @@ -1113,32 +891,7 @@ void ReloadCustomImage(Bitmap *bitmap, char *basename) Bitmap *ZoomBitmap(Bitmap *src_bitmap, int zoom_width, int zoom_height) { -#if 0 - // !!! TEST ONLY !!! - - Bitmap *dst_bitmap = CreateBitmap(zoom_width, zoom_height, DEFAULT_DEPTH); - print_timestamp_time("CreateBitmap"); - - SDL_Rect src_rect, dst_rect; - - src_rect.x = 0; - src_rect.y = 0; - src_rect.w = src_bitmap->width - 0; - src_rect.h = src_bitmap->height; - - dst_rect.x = 0; - dst_rect.y = 0; - dst_rect.w = dst_bitmap->width; - dst_rect.h = dst_bitmap->height; - - SDL_BlitScaled(src_bitmap->surface, &src_rect, - dst_bitmap->surface, &dst_rect); - print_timestamp_time("SDL_BlitScaled"); - -#else - Bitmap *dst_bitmap = SDLZoomBitmap(src_bitmap, zoom_width, zoom_height); -#endif return dst_bitmap; } @@ -1163,9 +916,7 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, int width_4, height_4; int width_8, height_8; int width_16, height_16; -#if 1 int width_32, height_32; -#endif int old_width, old_height; int new_width, new_height; @@ -1174,7 +925,6 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, old_width = old_bitmap->width; old_height = old_bitmap->height; -#if 1 /* calculate new image dimensions for final image size */ width_final = old_width * zoom_factor; height_final = old_height * zoom_factor; @@ -1186,20 +936,6 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, else tmp_bitmap_final = old_bitmap; -#else - - /* calculate new image dimensions for final image size */ - width_1 = old_width * zoom_factor; - height_1 = old_height * zoom_factor; - - /* get image with final size (this might require scaling up) */ - /* ("final" size may result in non-standard tile size image) */ - if (zoom_factor != 1) - tmp_bitmap_1 = ZoomBitmap(old_bitmap, width_1, height_1); - else - tmp_bitmap_1 = old_bitmap; -#endif - UPDATE_BUSY_STATE(); width_0 = width_1 = width_final; @@ -1207,7 +943,6 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, tmp_bitmap_0 = tmp_bitmap_1 = tmp_bitmap_final; -#if 1 if (create_small_bitmaps) { /* check if we have a non-gameplay tile size image */ @@ -1222,15 +957,7 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, else if (width_0 == width_final) tmp_bitmap_0 = tmp_bitmap_final; else - { -#if 0 - if (old_width != width_0) - printf("::: %d, %d -> %d, %d\n", - old_width, old_height, width_0, height_0); -#endif - tmp_bitmap_0 = ZoomBitmap(old_bitmap, width_0, height_0); - } UPDATE_BUSY_STATE(); } @@ -1254,7 +981,6 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, UPDATE_BUSY_STATE(); } } -#endif if (create_small_bitmaps) { @@ -1267,12 +993,9 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, height_8 = height_1 / 8; width_16 = width_1 / 16; height_16 = height_1 / 16; -#if 1 width_32 = width_1 / 32; height_32 = height_1 / 32; -#endif -#if 1 /* get image with 1/2 of normal size (for use in the level editor) */ if (width_2 == old_width) tmp_bitmap_2 = old_bitmap; @@ -1312,87 +1035,23 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, tmp_bitmap_32 = ZoomBitmap(tmp_bitmap_16, width_32, height_32); UPDATE_BUSY_STATE(); - -#else - - /* get image with 1/2 of normal size (for use in the level editor) */ - if (zoom_factor != 2) - tmp_bitmap_2 = ZoomBitmap(tmp_bitmap_1, width_1 / 2, height_1 / 2); - else - tmp_bitmap_2 = old_bitmap; - - UPDATE_BUSY_STATE(); - - /* get image with 1/4 of normal size (for use in the level editor) */ - if (zoom_factor != 4) - tmp_bitmap_4 = ZoomBitmap(tmp_bitmap_2, width_2 / 2, height_2 / 2); - else - tmp_bitmap_4 = old_bitmap; - - UPDATE_BUSY_STATE(); - - /* get image with 1/8 of normal size (for use on the preview screen) */ - if (zoom_factor != 8) - tmp_bitmap_8 = ZoomBitmap(tmp_bitmap_4, width_4 / 2, height_4 / 2); - else - tmp_bitmap_8 = old_bitmap; - - UPDATE_BUSY_STATE(); - - /* get image with 1/16 of normal size (for use on the preview screen) */ - if (zoom_factor != 16) - tmp_bitmap_16 = ZoomBitmap(tmp_bitmap_8, width_8 / 2, height_8 / 2); - else - tmp_bitmap_16 = old_bitmap; - - UPDATE_BUSY_STATE(); - - /* get image with 1/32 of normal size (for use on the preview screen) */ - if (zoom_factor != 32) - tmp_bitmap_32 = ZoomBitmap(tmp_bitmap_16, width_16 / 2, height_16 / 2); - else - tmp_bitmap_32 = old_bitmap; - - UPDATE_BUSY_STATE(); -#endif } -#if 0 - /* if image was scaled up, create new clipmask for normal size image */ - if (zoom_factor != 1) - { - SDL_Surface *tmp_surface_1 = tmp_bitmap_1->surface; - - if (old_bitmap->surface_masked) - SDL_FreeSurface(old_bitmap->surface_masked); - - SDL_SetColorKey(tmp_surface_1, SET_TRANSPARENT_PIXEL, - SDL_MapRGB(tmp_surface_1->format, 0x00, 0x00, 0x00)); - if ((old_bitmap->surface_masked = SDL_DisplayFormat(tmp_surface_1)) ==NULL) - Error(ERR_EXIT, "SDL_DisplayFormat() failed"); - SDL_SetColorKey(tmp_surface_1, UNSET_TRANSPARENT_PIXEL, 0); - } -#endif - if (create_small_bitmaps) { new_width = width_1; new_height = height_1 + (height_1 + 1) / 2; /* prevent odd height */ -#if 1 if (width_0 != width_1) { new_width += width_0; new_height = MAX(new_height, height_0); } -#endif new_bitmap = CreateBitmap(new_width, new_height, DEFAULT_DEPTH); -#if 1 if (width_0 != width_1) BlitBitmap(tmp_bitmap_0, new_bitmap, 0, 0, width_0, height_0, width_1, 0); -#endif BlitBitmap(tmp_bitmap_1, new_bitmap, 0, 0, width_1, height_1, 0, 0); BlitBitmap(tmp_bitmap_2, new_bitmap, 0, 0, width_1 / 2, height_1 / 2, @@ -1420,7 +1079,6 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, { /* if no small bitmaps created, tmp_bitmap_1 is used as new bitmap now */ -#if 1 if (tmp_bitmap_final != old_bitmap) FreeBitmap(tmp_bitmap_final); @@ -1447,44 +1105,16 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, if (tmp_bitmap_32 != old_bitmap) FreeBitmap(tmp_bitmap_32); - -#else - - if (zoom_factor != 1) - FreeBitmap(tmp_bitmap_1); - - if (zoom_factor != 2) - FreeBitmap(tmp_bitmap_2); - - if (zoom_factor != 4) - FreeBitmap(tmp_bitmap_4); - - if (zoom_factor != 8) - FreeBitmap(tmp_bitmap_8); - - if (zoom_factor != 16) - FreeBitmap(tmp_bitmap_16); - - if (zoom_factor != 32) - FreeBitmap(tmp_bitmap_32); -#endif } /* replace image with extended image (containing 1/1, 1/2, 1/4, 1/8 size) */ -#if defined(TARGET_SDL) swap_bitmap.surface = old_bitmap->surface; old_bitmap->surface = new_bitmap->surface; new_bitmap->surface = swap_bitmap.surface; -#else - swap_bitmap.drawable = old_bitmap->drawable; - old_bitmap->drawable = new_bitmap->drawable; - new_bitmap->drawable = swap_bitmap.drawable; -#endif old_bitmap->width = new_bitmap->width; old_bitmap->height = new_bitmap->height; -#if 1 /* this replaces all blit masks created when loading -- maybe optimize this */ { SDL_Surface *old_surface = old_bitmap->surface; @@ -1495,17 +1125,11 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, SDL_SetColorKey(old_surface, SET_TRANSPARENT_PIXEL, SDL_MapRGB(old_surface->format, 0x00, 0x00, 0x00)); -#if 1 if ((old_bitmap->surface_masked = SDLGetNativeSurface(old_surface)) == NULL) Error(ERR_EXIT, "SDL_DisplayFormat() failed"); -#else - if ((old_bitmap->surface_masked = SDL_DisplayFormat(old_surface)) == NULL) - Error(ERR_EXIT, "SDL_DisplayFormat() failed"); -#endif SDL_SetColorKey(old_surface, UNSET_TRANSPARENT_PIXEL, 0); } -#endif UPDATE_BUSY_STATE(); @@ -1696,16 +1320,12 @@ void OpenAudio(void) audio.music_channel = 0; audio.first_sound_channel = 0; -#if defined(TARGET_SDL) SDLOpenAudio(); -#endif } void CloseAudio(void) { -#if defined(TARGET_SDL) SDLCloseAudio(); -#endif audio.sound_enabled = FALSE; } @@ -1726,55 +1346,40 @@ void SetAudioMode(boolean enabled) void InitEventFilter(EventFilter filter_function) { /* set event filter to filter out certain events */ -#if defined(TARGET_SDL) #if defined(TARGET_SDL2) SDL_SetEventFilter(filter_function, NULL); #else SDL_SetEventFilter(filter_function); #endif -#endif } boolean PendingEvent(void) { -#if defined(TARGET_SDL) return (SDL_PollEvent(NULL) ? TRUE : FALSE); -#else - return (XPending(display) ? TRUE : FALSE); -#endif } void NextEvent(Event *event) { -#if defined(TARGET_SDL) SDLNextEvent(event); -#else - XNextEvent(display, event); -#endif } void PeekEvent(Event *event) { -#if defined(TARGET_SDL) #if defined(TARGET_SDL2) SDL_PeepEvents(event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT); #else SDL_PeepEvents(event, 1, SDL_PEEKEVENT, SDL_ALLEVENTS); #endif -#else - XPeekEvent(display, event); -#endif } Key GetEventKey(KeyEvent *event, boolean with_modifiers) { -#if defined(TARGET_SDL) #if defined(TARGET_SDL2) /* key up/down events in SDL2 do not return text characters anymore */ return event->keysym.sym; #else -#if 0 +#if ENABLE_UNUSED_CODE printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n", (int)event->keysym.unicode, (int)event->keysym.sym, @@ -1789,19 +1394,6 @@ Key GetEventKey(KeyEvent *event, boolean with_modifiers) return event->keysym.sym; #endif -#else - -#if 0 - printf("with modifiers == '0x%04x', without modifiers == '0x%04x'\n", - (int)XLookupKeysym(event, event->state), - (int)XLookupKeysym(event, 0)); -#endif - - if (with_modifiers) - return XLookupKeysym(event, event->state); - else - return XLookupKeysym(event, 0); -#endif } KeyMod HandleKeyModState(Key key, int key_status) @@ -1853,11 +1445,7 @@ KeyMod HandleKeyModState(Key key, int key_status) KeyMod GetKeyModState() { -#if defined(TARGET_SDL) return (KeyMod)SDL_GetModState(); -#else - return HandleKeyModState(KSYM_UNDEFINED, 0); -#endif } KeyMod GetKeyModStateFromEvents() @@ -1876,11 +1464,7 @@ boolean CheckCloseWindowEvent(ClientMessageEvent *event) if (event->type != EVENT_CLIENTMESSAGE) return FALSE; -#if defined(TARGET_SDL) return TRUE; /* the only possible message here is SDL_QUIT */ -#endif - - return FALSE; } @@ -1901,19 +1485,10 @@ void InitJoysticks() for (i = 0; i < MAX_PLAYERS; i++) joystick.fd[i] = -1; /* joystick device closed */ -#if defined(TARGET_SDL) SDLInitJoysticks(); -#endif - -#if 0 - for (i = 0; i < MAX_PLAYERS; i++) - printf("::: Joystick for player %d: %d\n", i, joystick.fd[i]); -#endif } boolean ReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2) { -#if defined(TARGET_SDL) return SDLReadJoystick(nr, x, y, b1, b2); -#endif } diff --git a/src/libgame/text.c b/src/libgame/text.c index 77edb425..36cb6dd5 100644 --- a/src/libgame/text.c +++ b/src/libgame/text.c @@ -120,23 +120,10 @@ int maxWordLengthInString(char *text) void DrawInitTextExt(char *text, int ypos, int font_nr, boolean force) { -#if 1 -#if 0 - static unsigned int progress_delay = 0; - unsigned int progress_delay_value = 100; /* (in milliseconds) */ -#endif - - // LimitScreenUpdates(TRUE); // (ignore "force" for now) - // LimitScreenUpdates(!force); LimitScreenUpdates(TRUE); UPDATE_BUSY_STATE(); -#if 0 - if (!force && !DelayReached(&progress_delay, progress_delay_value)) - return; -#endif - if (window != NULL && gfx.draw_init_text && gfx.num_fonts > 0 && @@ -152,35 +139,6 @@ void DrawInitTextExt(char *text, int ypos, int font_nr, boolean force) BlitBitmap(drawto, window, 0, 0, video.width, video.height, 0, 0); } -#else - static unsigned int progress_delay = 0; - unsigned int progress_delay_value = 100; /* (in milliseconds) */ - - // LimitScreenUpdates(TRUE); // (ignore "force" for now) - LimitScreenUpdates(!force); - - UPDATE_BUSY_STATE(); - - if (!force && !DelayReached(&progress_delay, progress_delay_value)) - return; - - if (window != NULL && - gfx.draw_init_text && - gfx.num_fonts > 0 && - gfx.font_bitmap_info[font_nr].bitmap != NULL) - { - int x = (video.width - getTextWidth(text, font_nr)) / 2; - int y = ypos; - int width = video.width; - int height = getFontHeight(font_nr); - - ClearRectangle(drawto, 0, y, width, height); - DrawTextExt(drawto, x, y, text, font_nr, BLIT_OPAQUE); - - /* this makes things significantly faster than directly drawing to window */ - BlitBitmap(drawto, window, 0, y, width, height, 0, y); - } -#endif } void DrawInitText(char *text, int ypos, int font_nr) @@ -267,7 +225,6 @@ void DrawText(int x, int y, char *text, int font_nr) DrawTextExt(drawto, x, y, text, font_nr, mask_mode); -#if 1 if (IN_GFX_FIELD_FULL(x, y)) redraw_mask |= REDRAW_FIELD; else if (IN_GFX_DOOR_1(x, y)) @@ -278,30 +235,14 @@ void DrawText(int x, int y, char *text, int font_nr) redraw_mask |= REDRAW_DOOR_3; else redraw_mask |= REDRAW_ALL; -#else - if (x < gfx.dx) - redraw_mask |= REDRAW_FIELD; - else if (y < gfx.vy || gfx.vy == 0) - redraw_mask |= REDRAW_DOOR_1; -#endif } void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text, int font_nr, int mask_mode) { -#if 1 struct FontBitmapInfo *font = getFontBitmapInfo(font_nr); -#else - int font_bitmap_id = gfx.select_font_function(font_nr); - struct FontBitmapInfo *font = &gfx.font_bitmap_info[font_bitmap_id]; -#endif int font_width = getFontWidth(font_nr); int font_height = getFontHeight(font_nr); -#if 0 - int border_1 = gfx.sx + gfx.sxsize; - int border_2 = gfx.dx + gfx.dxsize; - int dst_x_start = dst_x; -#endif Bitmap *src_bitmap; int src_x, src_y; char *text_ptr = text; @@ -335,15 +276,8 @@ void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text, } /* clip text at the right side of the window */ -#if 1 if (dst_x + font_width > video.width) break; -#else - /* (this does not work well when trying to print text to whole screen) */ - if ((dst_x_start < border_1 && dst_x + font_width > border_1) || - (dst_x_start < border_2 && dst_x + font_width > border_2)) - break; -#endif if (mask_mode == BLIT_INVERSE) /* special mode for text gadgets */ { @@ -360,17 +294,9 @@ void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text, font_width, font_height, dst_x, dst_y); } -#if defined(TARGET_SDL) /* second step: draw masked inverted character */ SDLCopyInverseMasked(src_bitmap, dst_bitmap, src_x, src_y, font_width, font_height, dst_x, dst_y); -#else - /* second step: draw masked black rectangle (use "space" character) */ - SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc, - dst_x - src_x, dst_y - src_y); - BlitBitmapMasked(src_bitmap, dst_bitmap, 0, 0, - font_width, font_height, dst_x, dst_y); -#endif } else if (mask_mode == BLIT_MASKED || mask_mode == BLIT_ON_BACKGROUND) { @@ -404,8 +330,6 @@ void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text, #define MAX_LINES_FROM_FILE 1024 -#if 1 - char *GetTextBufferFromFile(char *filename, int max_lines) { File *file; @@ -440,72 +364,6 @@ char *GetTextBufferFromFile(char *filename, int max_lines) return buffer; } -#else - -char *GetTextBufferFromFile(char *filename, int max_lines) -{ - FILE *file; - char *buffer; - int num_lines = 0; - - if (filename == NULL) - return NULL; - - if (!(file = fopen(filename, MODE_READ))) - return NULL; - - buffer = checked_calloc(1); /* start with valid, but empty text buffer */ - - while (!feof(file) && num_lines < max_lines) - { - char line[MAX_LINE_LEN]; - - /* read next line of input file */ - if (!fgets(line, MAX_LINE_LEN, file)) - break; - - buffer = checked_realloc(buffer, strlen(buffer) + strlen(line) + 1); - - strcat(buffer, line); - - num_lines++; - } - - fclose(file); - - return buffer; -} - -#endif - -void DrawTextToTextArea_OLD(int x, int y, char *text, int font_nr, int line_length, - int area_xsize, int area_ysize, int mask_mode) -{ - int area_line = 0; - int font_height = getFontHeight(font_nr); - - if (text == NULL) - return; - - while (*text && area_line < area_ysize) - { - char buffer[MAX_OUTPUT_LINESIZE + 1]; - int i; - - for (i = 0; i < line_length && *text; i++) - if ((buffer[i] = *text++) == '\n') - break; - buffer[MIN(i, area_xsize)] = '\0'; - - DrawTextExt(drawto, x, y + area_line * font_height, buffer, font_nr, - mask_mode); - - area_line++; - } - - redraw_mask |= REDRAW_FIELD; -} - static boolean RenderLineToBuffer(char **src_buffer_ptr, char *dst_buffer, int *dst_buffer_len, int line_length, boolean last_line_was_empty) @@ -585,138 +443,6 @@ static boolean RenderLineToBuffer(char **src_buffer_ptr, char *dst_buffer, return buffer_filled; } -#if 0 -void DrawTextWrapped_OLD(int x, int y, char *text, int font_nr, int line_length, - int max_lines) -{ - char *text_ptr = text; - int current_line = 0; - int font_height = getFontHeight(font_nr); - - while (*text_ptr && current_line < max_lines) - { - char buffer[line_length + 1]; - int buffer_len = 0; - - buffer[0] = '\0'; - - RenderLineToBuffer(&text_ptr, buffer, &buffer_len, line_length, TRUE); - - DrawText(x, y + current_line * font_height, buffer, font_nr); - current_line++; - } -} -#endif - -#if 0 -int DrawTextFromFile_OLD(int x, int y, char *filename, int font_nr, - int line_length, int max_lines, boolean wrap_text) -{ - int font_height = getFontHeight(font_nr); - char line[MAX_LINE_LEN]; - char buffer[line_length + 1]; - int buffer_len; - int current_line = 0; - FILE *file; - - if (current_line >= max_lines) - return 0; - - if (filename == NULL) - return 0; - - if (!(file = fopen(filename, MODE_READ))) - return 0; - - buffer[0] = '\0'; - buffer_len = 0; - - while (!feof(file) && current_line < max_lines) - { - char *line_ptr; - boolean last_line_was_empty = TRUE; - - /* read next line of input file */ - if (!fgets(line, MAX_LINE_LEN, file)) - break; - - /* skip comments (lines directly beginning with '#') */ - if (line[0] == '#') - continue; - - /* cut trailing newline from input line */ - for (line_ptr = line; *line_ptr; line_ptr++) - { - if (*line_ptr == '\n' || *line_ptr == '\r') - { - *line_ptr = '\0'; - break; - } - } - - if (strlen(line) == 0) /* special case: force empty line */ - strcpy(line, "\n"); - - line_ptr = line; - - while (*line_ptr && current_line < max_lines) - { -#if 1 - boolean buffer_filled; - - if (wrap_text) - { - buffer_filled = RenderLineToBuffer(&line_ptr, buffer, &buffer_len, - line_length, last_line_was_empty); - } - else - { - if (strlen(line_ptr) <= line_length) - { - buffer_len = strlen(line_ptr); - strcpy(buffer, line_ptr); - } - else - { - buffer_len = line_length; - strncpy(buffer, line_ptr, line_length); - } - - buffer[buffer_len] = '\0'; - line_ptr += buffer_len; - - buffer_filled = TRUE; - } -#else - boolean buffer_filled = RenderLineToBuffer(&line_ptr, buffer, &buffer_len, - line_length, last_line_was_empty); -#endif - - if (buffer_filled) - { - DrawText(x, y + current_line * font_height, buffer, font_nr); - current_line++; - - last_line_was_empty = (buffer_len == 0); - - buffer[0] = '\0'; - buffer_len = 0; - } - } - } - - fclose(file); - - if (buffer_len > 0 && current_line < max_lines) - { - DrawText(x, y + current_line * font_height, buffer, font_nr); - current_line++; - } - - return current_line; -} -#endif - static boolean getCheckedTokenValueFromString(char *string, char **token, char **value) { @@ -767,10 +493,6 @@ int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr, int line_spacing, int mask_mode, boolean autowrap, boolean centered, boolean parse_comments) { -#if 0 - int font_width = getFontWidth(font_nr); - int font_height = getFontHeight(font_nr); -#endif char buffer[line_length + 1]; int buffer_len; int current_line = 0; @@ -792,11 +514,7 @@ int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr, char line[MAX_LINE_LEN + 1]; char *line_ptr; boolean last_line_was_empty = TRUE; -#if 1 int num_line_chars = MAX_LINE_LEN; -#else - int num_line_chars = (autowrap ? MAX_LINE_LEN : line_length); -#endif int i; /* copy next line from text buffer to line buffer (nearly fgets() style) */ @@ -887,25 +605,8 @@ int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr, if (buffer_filled) { -#if 1 DrawTextBuffer_Flush(x, y, buffer, font_nr, line_length, cut_length, line_spacing, mask_mode, centered, current_line); -#else - int offset_chars = (centered ? (line_length - buffer_len) / 2 : 0); - int offset_xsize = - (centered ? font_width * (line_length - buffer_len) / 2 : 0); - int final_cut_length = MAX(0, cut_length - offset_chars); - int xx = x + offset_xsize; - - buffer[final_cut_length] = '\0'; - - if (mask_mode != -1) - DrawTextExt(drawto, xx, y + current_line * font_height, buffer, - font_nr, mask_mode); - else - DrawText(xx, y + current_line * font_height, buffer, font_nr); -#endif - current_line++; last_line_was_empty = (buffer_len == 0); @@ -918,25 +619,8 @@ int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr, if (buffer_len > 0 && current_line < max_lines) { -#if 1 DrawTextBuffer_Flush(x, y, buffer, font_nr, line_length, cut_length, line_spacing, mask_mode, centered, current_line); -#else - int offset_chars = (centered ? (line_length - buffer_len) / 2 : 0); - int offset_xsize = - (centered ? font_width * (line_length - buffer_len) / 2 : 0); - int final_cut_length = MAX(0, cut_length - offset_chars); - int xx = x + offset_xsize; - - buffer[final_cut_length] = '\0'; - - if (mask_mode != -1) - DrawTextExt(drawto, xx, y + current_line * font_height, buffer, - font_nr, mask_mode); - else - DrawText(xx, y + current_line * font_height, buffer, font_nr); -#endif - current_line++; } @@ -975,19 +659,3 @@ int DrawTextFile(int x, int y, char *filename, int font_nr, return num_lines_printed; } - -#if 0 -void DrawTextWrapped(int x, int y, char *text, int font_nr, int line_length, - int max_lines) -{ - DrawTextBuffer(x, y, text, font_nr, line_length, -1, max_lines, -1, TRUE, - FALSE, FALSE); -} - -void DrawTextToTextArea(int x, int y, char *text, int font_nr, int line_length, - int cut_length, int max_lines, int mask_mode) -{ - DrawTextBuffer(x, y, text, font_nr, line_length, cut_length, max_lines, - mask_mode, FALSE, FALSE, FALSE); -} -#endif diff --git a/src/libgame/toons.c b/src/libgame/toons.c index b60ebe38..8d0a8ba5 100644 --- a/src/libgame/toons.c +++ b/src/libgame/toons.c @@ -127,25 +127,8 @@ void DrawAnim(Bitmap *toon_bitmap, GC toon_clip_gc, int pad_dest_y = dest_y - pad_y; int pad_width = width + 2 * pad_x; int pad_height = height + 2 * pad_y; -#if 1 int buffer_x = 0; int buffer_y = 0; -#else - int buffer_x = DOOR_GFX_PAGEX3; - int buffer_y = DOOR_GFX_PAGEY1; -#endif - -#if 0 - printf("::: (%d, %d), (%d, %d), (%d, %d), (%d, %d) -> (%d, %d), (%d, %d), (%d, %d)\n", - src_x, src_y, - width, height, - dest_x, dest_y, - pad_x, pad_y, - - pad_dest_x, pad_dest_y, - pad_width, pad_height, - buffer_x, buffer_y); -#endif /* correct values to avoid off-screen blitting (start position) */ if (pad_dest_x < screen_info.startx) @@ -374,11 +357,9 @@ void HandleAnimation(int mode) case ANIM_STOP: if (anim_running) { -#if 1 redraw_mask |= (REDRAW_FIELD | REDRAW_FROM_BACKBUFFER); screen_info.update_function(); -#endif anim_running = FALSE; } diff --git a/src/main.c b/src/main.c index 65cd4ed2..8a727907 100644 --- a/src/main.c +++ b/src/main.c @@ -23,9 +23,6 @@ Bitmap *bitmap_db_store; Bitmap *bitmap_db_cross; Bitmap *bitmap_db_field; Bitmap *bitmap_db_panel; -#if 0 -Bitmap *bitmap_db_door; -#endif Bitmap *bitmap_db_door_1; Bitmap *bitmap_db_door_2; Bitmap *bitmap_db_toons; @@ -43,15 +40,7 @@ SDL_Thread *server_thread; int key_joystick_mapping = 0; -#if 1 -#if NEW_SCROLL boolean redraw[2 + MAX_LEV_FIELDX + 2][2 + MAX_LEV_FIELDY + 2]; -#else -boolean redraw[MAX_LEV_FIELDX + 2][MAX_LEV_FIELDY + 2]; -#endif -#else -boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; -#endif int redraw_x1 = 0, redraw_y1 = 0; short Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY]; @@ -116,24 +105,15 @@ int EXSIZE = 100; int EYSIZE = 144; int TILESIZE_VAR = TILESIZE; -#if 1 int FX, FY; -#else -int FX = SX, FY = SY; -#endif int ScrollStepSize; int ScreenMovDir = MV_NONE, ScreenMovPos = 0; int ScreenGfxPos = 0; int BorderElement = EL_STEELWALL; int GameFrameDelay = GAME_FRAME_DELAY; int FfwdFrameDelay = FFWD_FRAME_DELAY; -#if 1 int BX1, BY1; int BX2, BY2; -#else -int BX1 = 0, BY1 = 0; -int BX2 = SCR_FIELDX - 1, BY2 = SCR_FIELDY - 1; -#endif int SBX_Left, SBX_Right; int SBY_Upper, SBY_Lower; int ZX, ZY; diff --git a/src/main.h b/src/main.h index a8d7cf07..4f907998 100644 --- a/src/main.h +++ b/src/main.h @@ -29,10 +29,6 @@ #include "conf_mus.h" /* include auto-generated data structure definitions */ -#define NEW_GAME_TILESIZE 1 -#define NEW_TILESIZE 1 -#define NEW_SCROLL 1 - #define IMG_UNDEFINED (-1) #define IMG_EMPTY IMG_EMPTY_SPACE #define IMG_SP_EMPTY IMG_EMPTY_SPACE @@ -45,17 +41,8 @@ #define SND_UNDEFINED (-1) #define MUS_UNDEFINED (-1) -#if 0 -#define WIN_XSIZE 672 -#define WIN_YSIZE 560 -#endif - #define DEFAULT_FULLSCREEN_MODE "800x600" -#if 0 -#define SCR_FIELDX 17 -#define SCR_FIELDY 17 -#endif #define MAX_BUF_XSIZE (SCR_FIELDX + 2) #define MAX_BUF_YSIZE (SCR_FIELDY + 2) #define MIN_LEV_FIELDX 3 @@ -768,27 +755,7 @@ #define IS_DC_STEELWALL_2(e) ((e) >= EL_DC_STEELWALL_2_LEFT && \ (e) <= EL_DC_STEELWALL_2_SINGLE) -#if 1 - -#if 1 #define GFX_ELEMENT(e) (element_info[e].gfx_element) -#else -#define GFX_ELEMENT(e) (element_info[e].gfx_element == \ - (element_info[e].use_gfx_element ? \ - element_info[e].gfx_element : e) ? \ - element_info[e].gfx_element : \ - element_info[e].gfx_element + \ - 0 * printf("::: %d: %d <-> %d\n", \ - e, \ - element_info[e].gfx_element, \ - element_info[e].use_gfx_element ? \ - element_info[e].gfx_element : e)) -#endif - -#else -#define GFX_ELEMENT(e) (element_info[e].use_gfx_element ? \ - element_info[e].gfx_element : e) -#endif /* !!! CHECK THIS !!! */ #if 1 @@ -949,18 +916,6 @@ #define MAX_INITIAL_INVENTORY_SIZE 8 /* often used screen positions */ -#if 0 -#define SX 8 -#define SY 8 -#define REAL_SX (SX - 2) -#define REAL_SY (SY - 2) -#define DX 566 -#define DY 60 -#define VX DX -#define VY 400 -#define EX DX -#define EY (VY - 44) -#endif #define TILESIZE 32 #define TILEX TILESIZE #define TILEY TILESIZE @@ -974,53 +929,9 @@ #define MICRO_TILEY MICRO_TILESIZE #define MIDPOSX (SCR_FIELDX / 2) #define MIDPOSY (SCR_FIELDY / 2) -#if NEW_TILESIZE -#if NEW_SCROLL -#if 0 -#define SXSIZE (SCR_FIELDX * TILEX_VAR) -#define SYSIZE (SCR_FIELDY * TILEY_VAR) -#endif #define FXSIZE ((2 + SCR_FIELDX + 2) * TILEX_VAR) #define FYSIZE ((2 + SCR_FIELDY + 2) * TILEY_VAR) -#else -#if 0 -#define SXSIZE (SCR_FIELDX * TILEX_VAR) -#define SYSIZE (SCR_FIELDY * TILEY_VAR) -#endif -#define FXSIZE ((SCR_FIELDX + 2) * TILEX_VAR) -#define FYSIZE ((SCR_FIELDY + 2) * TILEY_VAR) -#endif -#else -#if NEW_SCROLL -#if 0 -#define SXSIZE (SCR_FIELDX * TILEX) -#define SYSIZE (SCR_FIELDY * TILEY) -#endif -#define FXSIZE ((2 + SCR_FIELDX + 2) * TILEX) -#define FYSIZE ((2 + SCR_FIELDY + 2) * TILEY) -#else -#if 0 -#define SXSIZE (SCR_FIELDX * TILEX) -#define SYSIZE (SCR_FIELDY * TILEY) -#endif -#define FXSIZE ((SCR_FIELDX + 2) * TILEX) -#define FYSIZE ((SCR_FIELDY + 2) * TILEY) -#endif -#endif -#if 0 -#define DXSIZE 100 -#define DYSIZE 280 -#define VXSIZE DXSIZE -#define VYSIZE 100 -#define EXSIZE DXSIZE -#define EYSIZE (VYSIZE + 44) -#endif - -#if 0 -#define FULL_SXSIZE (2 + SXSIZE + 2) -#define FULL_SYSIZE (2 + SYSIZE + 2) -#endif #define MICROLEVEL_XSIZE ((STD_LEV_FIELDX + 2) * MICRO_TILEX) #define MICROLEVEL_YSIZE ((STD_LEV_FIELDY + 2) * MICRO_TILEY) #define MICROLEVEL_XPOS (SX + (SXSIZE - MICROLEVEL_XSIZE) / 2) @@ -2025,20 +1936,6 @@ #define NUM_FONTS 38 #define NUM_INITIAL_FONTS 4 -#if 0 -#define FONT_ACTIVE(f) \ - ((f) == FONT_MENU_1 ? FONT_MENU_1_ACTIVE : \ - (f) == FONT_MENU_2 ? FONT_MENU_2_ACTIVE : \ - (f) == FONT_TEXT_1 ? FONT_TEXT_1_ACTIVE : \ - (f) == FONT_TEXT_2 ? FONT_TEXT_2_ACTIVE : \ - (f) == FONT_TEXT_3 ? FONT_TEXT_3_ACTIVE : \ - (f) == FONT_TEXT_4 ? FONT_TEXT_4_ACTIVE : \ - (f) == FONT_INPUT_1 ? FONT_INPUT_1_ACTIVE : \ - (f) == FONT_INPUT_2 ? FONT_INPUT_2_ACTIVE : \ - (f) == FONT_LEVEL_NUMBER ? FONT_LEVEL_NUMBER_ACTIVE : \ - (f)) -#endif - /* values for game_status (must match special image configuration suffixes) */ #define GAME_MODE_DEFAULT 0 #define GAME_MODE_LOADING 1 @@ -2556,10 +2453,6 @@ struct GlobalInfo /* global values for fading screens and masking borders */ int border_status; -#if 0 - int fading_status; - int fading_type; -#endif boolean use_envelope_request; }; @@ -2899,9 +2792,6 @@ extern Bitmap *bitmap_db_store; extern Bitmap *bitmap_db_cross; extern Bitmap *bitmap_db_field; extern Bitmap *bitmap_db_panel; -#if 0 -extern Bitmap *bitmap_db_door; -#endif extern Bitmap *bitmap_db_door_1; extern Bitmap *bitmap_db_door_2; extern Bitmap *bitmap_db_toons; @@ -2920,15 +2810,7 @@ extern SDL_Thread *server_thread; extern int key_joystick_mapping; -#if 1 -#if NEW_SCROLL extern boolean redraw[2 + MAX_LEV_FIELDX + 2][2 + MAX_LEV_FIELDY + 2]; -#else -extern boolean redraw[MAX_LEV_FIELDX + 2][MAX_LEV_FIELDY + 2]; -#endif -#else -extern boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE]; -#endif extern int redraw_x1, redraw_y1; extern short Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY]; diff --git a/src/netserv.c b/src/netserv.c index 5ecbf1b7..6555e049 100644 --- a/src/netserv.c +++ b/src/netserv.c @@ -18,16 +18,7 @@ #include #include -#if defined(TARGET_SDL) #include "main.h" -#else -#include -#include -#include -#include -#include -#include /* apparently needed for OS/2 port */ -#endif #include "libgame/libgame.h" @@ -38,12 +29,7 @@ static int onceonly = 0; struct NetworkServerPlayerInfo { -#if defined(TARGET_SDL) TCPsocket fd; -#else - int fd; -#endif - char player_name[16]; unsigned char number; struct NetworkServerPlayerInfo *next; @@ -60,16 +46,9 @@ static struct NetworkServerPlayerInfo *first_player = NULL; #define NEXT(player) ((player)->next ? (player)->next : first_player) -#if defined(TARGET_SDL) /* TODO: peer address */ static TCPsocket lfd; /* listening socket */ static SDLNet_SocketSet fds; /* socket set */ -#else -static struct sockaddr_in saddr; -static int lfd; /* listening socket */ -static fd_set fds; /* socket set */ -static int tcp = -1; -#endif static unsigned char realbuffer[512], *buffer = realbuffer + 4; @@ -92,12 +71,8 @@ static void flushuser(struct NetworkServerPlayerInfo *player) { if (player->nwrite) { -#if defined(TARGET_SDL) SDLNet_TCP_Send(player->fd, player->writbuffer, player->nwrite); -#else - if (write(player->fd, player->writbuffer, player->nwrite) == -1) - Error(ERR_WARN, "write() failed; %s", strerror(errno)); -#endif + player->nwrite = 0; } } @@ -144,12 +119,8 @@ static void RemovePlayer(struct NetworkServerPlayerInfo *player) } } -#if defined(TARGET_SDL) SDLNet_TCP_DelSocket(fds, player->fd); SDLNet_TCP_Close(player->fd); -#else - close(player->fd); -#endif if (player->introduced) { @@ -172,11 +143,7 @@ static void RemovePlayer(struct NetworkServerPlayerInfo *player) } } -#if defined(TARGET_SDL) static void AddPlayer(TCPsocket fd) -#else -static void AddPlayer(int fd) -#endif { struct NetworkServerPlayerInfo *player, *v; unsigned char nxn; @@ -194,9 +161,7 @@ static void AddPlayer(int fd) player->action = 0; player->action_received = FALSE; -#if defined(TARGET_SDL) SDLNet_TCP_AddSocket(fds, fd); -#endif first_player = player; @@ -221,11 +186,6 @@ static void AddPlayer(int fd) } player->number = nxn; -#if !defined(TARGET_SDL) - if (options.verbose) - Error(ERR_NETWORK_SERVER, "client %d connecting from %s", - nxn, inet_ntoa(saddr.sin_addr)); -#endif clients++; buffer[0] = 0; @@ -470,15 +430,9 @@ static void Handle_OP_MOVE_PLAYER(struct NetworkServerPlayerInfo *player) broadcast(NULL, 6 + last_client_nr, 0); -#if 0 - Error(ERR_NETWORK_SERVER, "sending ServerFrameCounter value %d", - ServerFrameCounter); -#endif - ServerFrameCounter++; } -#if defined(TARGET_SDL) /* the following is not used for a standalone server; the pointer points to an integer containing the port-number */ int NetworkServerThread(void *ptr) @@ -488,7 +442,6 @@ int NetworkServerThread(void *ptr) /* should never be reached */ return 0; } -#endif void NetworkServer(int port, int serveronly) { @@ -496,15 +449,7 @@ void NetworkServer(int port, int serveronly) struct NetworkServerPlayerInfo *player; int r; unsigned int len; -#if defined(TARGET_SDL) IPaddress ip; -#else - int i, on; - int is_daemon = 0; - struct protoent *tcpproto; - struct timeval tv; - int mfd; -#endif #if defined(PLATFORM_UNIX) && !defined(PLATFORM_NEXT) struct sigaction sact; @@ -516,11 +461,6 @@ void NetworkServer(int port, int serveronly) if (!serveronly) onceonly = 1; -#if !defined(TARGET_SDL) - if ((tcpproto = getprotobyname("tcp")) != NULL) - tcp = tcpproto->p_proto; -#endif - #if defined(PLATFORM_UNIX) #if defined(PLATFORM_NEXT) signal(SIGPIPE, SIG_IGN); @@ -532,15 +472,6 @@ void NetworkServer(int port, int serveronly) #endif #endif -#if defined(TARGET_SDL) - - /* assume that SDL is already initialized */ -#if 0 - if (SDLNet_Init() == -1) - Error(ERR_EXIT_NETWORK_SERVER, "SDLNet_Init() failed"); - atexit(SDLNet_Quit); -#endif - if (SDLNet_ResolveHost(&ip, NULL, port) == -1) Error(ERR_EXIT_NETWORK_SERVER, "SDLNet_ResolveHost() failed"); @@ -551,50 +482,6 @@ void NetworkServer(int port, int serveronly) fds = SDLNet_AllocSocketSet(MAX_PLAYERS+1); SDLNet_TCP_AddSocket(fds, lfd); -#else - - if ((lfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) - Error(ERR_EXIT_NETWORK_SERVER, "socket() failed"); - - saddr.sin_family = AF_INET; - saddr.sin_addr.s_addr = htonl(INADDR_ANY); - saddr.sin_port = htons(port); - - on = 1; - - setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(int)); - if (bind(lfd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) - Error(ERR_EXIT_NETWORK_SERVER, "bind() failed"); - - listen(lfd, 5); -#endif - -#if !defined(TARGET_SDL) - if (is_daemon) - { - /* become a daemon, breaking all ties with the controlling terminal */ - options.verbose = FALSE; - for (i = 0; i < 255; i++) - { - if (i != lfd) - close(i); - } - - if (fork()) - exit(0); - setsid(); - if (fork()) - exit(0); - if (chdir("/") == -1) - Error(ERR_WARN, "chdir() failed; %s", strerror(errno)); - - /* open a fake stdin, stdout, stderr, just in case */ - open("/dev/null", O_RDONLY); - open("/dev/null", O_WRONLY); - open("/dev/null", O_WRONLY); - } -#endif - if (options.verbose) { Error(ERR_NETWORK_SERVER, "started up, listening on port %d", port); @@ -609,7 +496,6 @@ void NetworkServer(int port, int serveronly) for (player = first_player; player; player = player->next) flushuser(player); -#if defined(TARGET_SDL) if ((sl = SDLNet_CheckSockets(fds, 500000)) < 1) { Error(ERR_NETWORK_SERVER, "SDLNet_CheckSockets failed: %s", @@ -617,30 +503,6 @@ void NetworkServer(int port, int serveronly) perror("SDLNet_CheckSockets"); } -#else - - FD_ZERO(&fds); - mfd = lfd; - player = first_player; - while (player) - { - FD_SET(player->fd, &fds); - if (player->fd > mfd) - mfd = player->fd; - player = player->next; - } - FD_SET(lfd, &fds); - tv.tv_sec = 0; - tv.tv_usec = 500000; - if ((sl = select(mfd + 1, &fds, NULL, NULL, &tv)) < 0) - { - if (errno != EINTR) - Error(ERR_EXIT_NETWORK_SERVER, "select() failed"); - else - continue; - } -#endif - if (sl < 0) continue; @@ -648,7 +510,6 @@ void NetworkServer(int port, int serveronly) continue; /* accept incoming connections */ -#if defined(TARGET_SDL) if (SDLNet_SocketReady(lfd)) { TCPsocket newsock; @@ -659,51 +520,15 @@ void NetworkServer(int port, int serveronly) AddPlayer(newsock); } -#else - - if (FD_ISSET(lfd, &fds)) - { - int newfd; - socklen_t slen; - - slen = sizeof(saddr); - newfd = accept(lfd, (struct sockaddr *)&saddr, &slen); - if (newfd < 0) - { - if (errno != EINTR) - Error(ERR_EXIT_NETWORK_SERVER, "accept() failed"); - } - else - { - if (tcp != -1) - { - on = 1; - setsockopt(newfd, tcp, TCP_NODELAY, (char *)&on, sizeof(int)); - } - AddPlayer(newfd); - } - continue; - } -#endif - player = first_player; do { -#if defined(TARGET_SDL) if (SDLNet_SocketReady(player->fd)) -#else - if (FD_ISSET(player->fd, &fds)) -#endif { -#if defined(TARGET_SDL) /* read only 1 byte, because SDLNet blocks when we want more than is in the buffer */ r = SDLNet_TCP_Recv(player->fd, player->readbuffer + player->nread, 1); -#else - r = read(player->fd, player->readbuffer + player->nread, - MAX_BUFFER_SIZE - player->nread); -#endif if (r <= 0) { diff --git a/src/netserv.h b/src/netserv.h index e0815bd0..53d96276 100644 --- a/src/netserv.h +++ b/src/netserv.h @@ -36,10 +36,7 @@ #define MAX_BUFFER_SIZE 4096 -#if defined(TARGET_SDL) int NetworkServerThread(void *); -#endif - void NetworkServer(int, int); #endif diff --git a/src/network.c b/src/network.c index 8d853201..e62df4ce 100644 --- a/src/network.c +++ b/src/network.c @@ -16,16 +16,7 @@ #include #include -#if defined(TARGET_SDL) #include "main.h" -#else -#include -#include -#include -#include -#include -#include -#endif #include "libgame/libgame.h" @@ -53,12 +44,8 @@ static struct NetworkClientPlayerInfo first_player = /* server stuff */ -#if defined(TARGET_SDL) static TCPsocket sfd; /* server socket */ static SDLNet_SocketSet rfds; /* socket set */ -#else -static int sfd; /* server socket */ -#endif static byte realbuffer[512]; static byte readbuffer[MAX_BUFFER_SIZE], writbuffer[MAX_BUFFER_SIZE]; @@ -82,12 +69,7 @@ static void SendBufferToServer(int size) nwrite += 4 + size; /* directly send the buffer to the network server */ -#if defined(TARGET_SDL) SDLNet_TCP_Send(sfd, writbuffer, nwrite); -#else - if (write(sfd, writbuffer, nwrite) == -1) - Error(ERR_WARN, "write() failed; %s", strerror(errno)); -#endif nwrite = 0; } @@ -124,7 +106,6 @@ char *getNetworkPlayerName(int player_nr) static void StartNetworkServer(int port) { -#if defined(TARGET_SDL) static int p; p = port; @@ -135,31 +116,8 @@ static void StartNetworkServer(int port) server_thread = SDL_CreateThread(NetworkServerThread, &p); #endif network_server = TRUE; - -#else - - switch (fork()) - { - case 0: - NetworkServer(port, options.serveronly); - - /* never reached */ - exit(0); - - case -1: - Error(ERR_WARN, - "cannot create network server process - no network playing"); - options.network = FALSE; - return; - - default: - /* we are parent process -- resume normal operation */ - return; - } -#endif } -#if defined(TARGET_SDL) boolean ConnectToServer(char *hostname, int port) { IPaddress ip; @@ -216,72 +174,6 @@ boolean ConnectToServer(char *hostname, int port) return FALSE; } -#else - -boolean ConnectToServer(char *hostname, int port) -{ - struct sockaddr_in s; - struct protoent *tcpproto; - int on = 1, i; - - if (hostname) - { - if ((s.sin_addr.s_addr = inet_addr(hostname)) == -1) - { - struct hostent *host; - - if ((host = gethostbyname(hostname)) == NULL) - Error(ERR_EXIT, "cannot locate host '%s'", hostname); - - s.sin_addr = *(struct in_addr *)(host->h_addr_list[0]); - } - } - else - s.sin_addr.s_addr = inet_addr("127.0.0.1"); /* localhost */ - - if (port == 0) - port = DEFAULT_SERVER_PORT; - - s.sin_port = htons(port); - s.sin_family = AF_INET; - - sfd = socket(PF_INET, SOCK_STREAM, 0); - if (sfd < 0) - Error(ERR_EXIT, "out of file descriptors"); - - if ((tcpproto = getprotobyname("tcp")) != NULL) - setsockopt(sfd, tcpproto->p_proto, TCP_NODELAY, (char *)&on, sizeof(int)); - - if (connect(sfd, (struct sockaddr *)&s, sizeof(s)) == 0) /* connected */ - return TRUE; - - if (hostname) /* connect to specified server failed */ - return FALSE; - - printf("No rocksndiamonds server on localhost -- starting up one ...\n"); - StartNetworkServer(port); - - /* wait for server to start up and try connecting several times */ - for (i = 0; i < 6; i++) - { - Delay(500); /* wait 500 ms == 0.5 seconds */ - close(sfd); - - sfd = socket(PF_INET, SOCK_STREAM, 0); - if (sfd < 0) - Error(ERR_EXIT, "out of file descriptors"); - - setsockopt(sfd, tcpproto->p_proto, TCP_NODELAY, (char *)&on, sizeof(int)); - - if (connect(sfd, (struct sockaddr *)&s, sizeof(s)) >= 0) /* connected */ - return TRUE; - } - - /* when reaching this point, connect to newly started server has failed */ - return FALSE; -} -#endif /* defined(TARGET_SDL) */ - void SendToServer_PlayerName(char *player_name) { int len_player_name = strlen(player_name); @@ -587,11 +479,6 @@ static void Handle_OP_MOVE_PLAYER(unsigned int len) server_frame_counter = (buffer[2] << 24) | (buffer[3] << 16) | (buffer[4] << 8) | (buffer[5]); -#if 0 - Error(ERR_NETWORK_CLIENT, "receiving server frame counter value %d [%d]", - server_frame_counter, FrameCounter); -#endif - if (server_frame_counter != FrameCounter) { Error(ERR_INFO, "client and servers frame counters out of sync"); @@ -692,43 +579,16 @@ static void HandleNetworkingMessages() void HandleNetworking() { -#if !defined(TARGET_SDL) - static struct timeval tv = { 0, 0 }; - fd_set rfds; -#endif int r = 0; do { -#if defined(TARGET_SDL) if ((r = SDLNet_CheckSockets(rfds, 1)) < 0) Error(ERR_EXIT, "HandleNetworking(): SDLNet_CheckSockets() failed"); -#else - - FD_ZERO(&rfds); - FD_SET(sfd, &rfds); - - r = select(sfd + 1, &rfds, NULL, NULL, &tv); - - if (r < 0 && errno != EINTR) - Error(ERR_EXIT, "HandleNetworking(): select() failed"); - - if (r < 0) - FD_ZERO(&rfds); -#endif - -#if defined(TARGET_SDL) if (r > 0) -#else - if (FD_ISSET(sfd, &rfds)) -#endif { -#if defined(TARGET_SDL) r = SDLNet_TCP_Recv(sfd, readbuffer + nread, 1); -#else - r = read(sfd, readbuffer + nread, MAX_BUFFER_SIZE - nread); -#endif if (r < 0) Error(ERR_EXIT, "error reading from network server"); @@ -744,4 +604,4 @@ void HandleNetworking() while (r > 0); } -#endif /* PLATFORM_UNIX */ +#endif /* NETWORK_AVALIABLE */ diff --git a/src/screens.c b/src/screens.c index d28e4d22..61cb7106 100644 --- a/src/screens.c +++ b/src/screens.c @@ -84,13 +84,8 @@ /* for various menu stuff */ #define MENU_SCREEN_START_XPOS 1 #define MENU_SCREEN_START_YPOS 2 -#if 1 #define MENU_SCREEN_VALUE_XPOS (SCR_FIELDX - 3) #define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1) -#else -#define MENU_SCREEN_VALUE_XPOS 14 -#define MENU_SCREEN_MAX_XPOS (SCR_FIELDX - 1) -#endif #define MENU_TITLE1_YPOS 8 #define MENU_TITLE2_YPOS 46 #define MENU_SCREEN_INFO_XSTART 16 @@ -102,22 +97,12 @@ MENU_SCREEN_INFO_YSTART2 - \ TILEY / 2) #define MAX_INFO_ELEMENTS_ON_SCREEN 128 -#if 1 #define NUM_INFO_ELEMENTS_ON_SCREEN MIN(MENU_SCREEN_INFO_YSIZE / \ MENU_SCREEN_INFO_YSTEP, \ MAX_INFO_ELEMENTS_ON_SCREEN) -#else -#define NUM_INFO_ELEMENTS_ON_SCREEN 10 -#endif #define MAX_MENU_ENTRIES_ON_SCREEN (SCR_FIELDY - MENU_SCREEN_START_YPOS) -#if 1 #define MAX_MENU_TEXT_LENGTH_BIG 13 #define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2) -#else -#define MAX_MENU_TEXT_LENGTH_BIG (MENU_SCREEN_VALUE_XPOS - \ - MENU_SCREEN_START_XPOS) -#define MAX_MENU_TEXT_LENGTH_MEDIUM (MAX_MENU_TEXT_LENGTH_BIG * 2) -#endif /* buttons and scrollbars identifiers */ #define SCREEN_CTRL_ID_PREV_LEVEL 0 @@ -828,11 +813,6 @@ static struct TitleFadingInfo getTitleFading(struct TitleControlInfo *tci) } } -#if 0 - if (ti.anim_mode == ANIM_NONE) - ti.fade_delay = ti.post_delay = 0; -#endif - return ti; } @@ -876,12 +856,6 @@ static void InitializeTitleControls_CheckTitleInfo(boolean initial) Bitmap *bitmap = graphic_info[graphic].bitmap; int sort_priority = graphic_info[graphic].sort_priority; -#if 0 - /* skip images and messages (fonts!) when using forced custom graphics */ - if (setup.override_level_graphics && !initial) - continue; -#endif - if (bitmap != NULL) InitializeTitleControlsExt_AddTitleInfo(TRUE, initial, i, sort_priority); } @@ -892,12 +866,6 @@ static void InitializeTitleControls_CheckTitleInfo(boolean initial) char *filename = getLevelSetTitleMessageFilename(i, initial); int sort_priority = tmi->sort_priority; -#if 0 - /* skip images and messages (fonts!) when using forced custom graphics */ - if (setup.override_level_graphics) - continue; -#endif - if (filename != NULL) InitializeTitleControlsExt_AddTitleInfo(FALSE, initial, i, sort_priority); } @@ -907,11 +875,9 @@ static void InitializeTitleControls(boolean show_title_initial) { num_title_screens = 0; -#if 1 /* 1st step: initialize title screens for game start (only when starting) */ if (show_title_initial) InitializeTitleControls_CheckTitleInfo(TRUE); -#endif /* 2nd step: initialize title screens for current level set */ InitializeTitleControls_CheckTitleInfo(FALSE); @@ -962,13 +928,8 @@ static void InitializeMainControls() char *text = (mci->text ? *mci->text : NULL); char *input = (mci->input ? *mci->input : NULL); int button_graphic = mci->button_graphic; -#if 1 int font_text = (pos_text ? pos_text->font : -1); int font_input = (pos_input ? pos_input->font : -1); -#else - int font_text = mci->font_text; - int font_input = mci->font_input; -#endif int font_text_width = (font_text != -1 ? getFontWidth(font_text) : 0); int font_text_height = (font_text != -1 ? getFontHeight(font_text) : 0); @@ -988,20 +949,8 @@ static void InitializeMainControls() if (nr == MAIN_CONTROL_NAME) { -#if 0 - if (menu.main.input.name.x == -1) - menu.main.input.name.x = menu.main.text.name.x + text_width; - if (menu.main.input.name.y == -1) - menu.main.input.name.y = menu.main.text.name.y; -#endif - -#if 1 menu.main.input.name.width = input_width; menu.main.input.name.height = input_height; -#else - menu.main.input.name.width = font_input_width * MAX_PLAYER_NAME_LEN; - menu.main.input.name.height = font_input_height; -#endif } if (pos_button != NULL) /* (x/y may be -1/-1 here) */ @@ -1014,13 +963,8 @@ static void InitializeMainControls() if (pos_text != NULL) /* (x/y may be -1/-1 here) */ { -#if 1 /* calculate size for non-clickable text -- needed for text alignment */ boolean calculate_text_size = (pos_button == NULL && text != NULL); -#else - /* calculate width for non-clickable text -- needed for text alignment */ - boolean calculate_text_width = (pos_button == NULL && text != NULL); -#endif if (visibleMenuPos(pos_button)) { @@ -1030,17 +974,10 @@ static void InitializeMainControls() pos_text->y = pos_button->y; } -#if 1 if (pos_text->width == -1 || calculate_text_size) pos_text->width = text_width; if (pos_text->height == -1 || calculate_text_size) pos_text->height = text_height; -#else - if (pos_text->width == -1 || calculate_text_width) - pos_text->width = text_width; - if (pos_text->height == -1) - pos_text->height = text_height; -#endif } if (pos_input != NULL) /* (x/y may be -1/-1 here) */ @@ -1078,13 +1015,8 @@ static void DrawCursorAndText_Main_Ext(int nr, boolean active_text, char *text = (mci->text ? *mci->text : NULL); char *input = (mci->input ? *mci->input : NULL); int button_graphic = mci->button_graphic; -#if 1 int font_text = (pos_text ? pos_text->font : -1); int font_input = (pos_input ? pos_input->font : -1); -#else - int font_text = mci->font_text; - int font_input = mci->font_input; -#endif if (active_text) { @@ -1192,11 +1124,7 @@ static boolean insideTextPosRect(struct TextPosInfo *rect, int x, int y) static void drawCursorExt(int xpos, int ypos, boolean active, int graphic) { -#if 1 static int cursor_array[MAX_LEV_FIELDY]; -#else - static int cursor_array[SCR_FIELDY]; -#endif int x = mSX + TILEX * xpos; int y = mSY + TILEY * (MENU_SCREEN_START_YPOS + ypos); @@ -1234,11 +1162,6 @@ static void drawChooseTreeCursor(int ypos, boolean active) { int last_game_status = game_status; /* save current game status */ -#if 0 - /* force LEVELS draw offset on artwork setup screen */ - game_status = GAME_MODE_LEVELS; -#endif - drawCursorExt(0, ypos, active, -1); game_status = last_game_status; /* restore current game status */ @@ -1250,28 +1173,6 @@ void DrawHeadline() DrawTextSCentered(MENU_TITLE2_YPOS, FONT_TITLE_2, PROGRAM_COPYRIGHT_STRING); } -#if 0 -static int getPrevlevelButtonPos() -{ - return 10; -} - -static int getCurrentLevelTextPos() -{ - return (getPrevlevelButtonPos() + 1); -} - -static int getNextLevelButtonPos() -{ - return getPrevlevelButtonPos() + 3 + 1; -} - -static int getLevelRangeTextPos() -{ - return getNextLevelButtonPos() + 1; -} -#endif - int effectiveGameStatus() { if (game_status == GAME_MODE_INFO && info_mode == INFO_MODE_TITLE) @@ -1367,10 +1268,6 @@ void DrawTitleScreen() { KeyboardAutoRepeatOff(); -#if 0 - SetMainBackgroundImage(IMG_BACKGROUND_TITLE); -#endif - HandleTitleScreen(0, 0, 0, 0, MB_MENU_INITIALIZE); StopAnimation(); @@ -1448,33 +1345,15 @@ void DrawMainMenuExt(int fade_mask, boolean do_fading) if (redraw_mask & REDRAW_ALL) fade_mask = REDRAW_ALL; -#if 1 FadeOut(fade_mask); -#if 0 - /* needed if last screen was the editor screen */ - UndrawSpecialEditorDoor(); -#endif - -#if 0 - if (fade_mask == REDRAW_FIELD) - BackToFront(); -#endif -#endif - -#if 1 /* needed if different viewport properties defined for menues */ ChangeViewportPropertiesIfNeeded(); -#endif -#if 1 /* needed if last screen was the editor screen */ UndrawSpecialEditorDoor(); -#endif -#if defined(TARGET_SDL) SetDrawtoField(DRAW_BACKBUFFER); -#endif if (CheckTitleScreen(levelset_has_changed)) { @@ -1494,17 +1373,9 @@ void DrawMainMenuExt(int fade_mask, boolean do_fading) SetMainBackgroundImage(IMG_BACKGROUND_MAIN); -#if 1 if (fade_mask == REDRAW_ALL) - { - // int door_state = GetDoorState(); - RedrawBackground(); - // OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW); - } -#endif - ClearField(); InitializeMainControls(); @@ -1530,39 +1401,19 @@ void DrawMainMenuExt(int fade_mask, boolean do_fading) MapTapeButtons(); MapScreenMenuGadgets(SCREEN_MASK_MAIN); -#if 1 /* copy actual game door content to door double buffer for OpenDoor() */ BlitBitmap(drawto, bitmap_db_door_2, VX, VY, VXSIZE, VYSIZE, 0, 0); -#endif - -#if 1 - // if (fade_mask == REDRAW_ALL) - // (always redraw current door state) - { - int door_state = GetDoorState(); - - // RedrawBackground(); - - OpenDoor(door_state | DOOR_NO_DELAY | DOOR_FORCE_REDRAW); - } -#endif -#if 0 - redraw_mask |= REDRAW_ALL; - BackToFront(); - Delay(3000); -#endif + OpenDoor(GetDoorState() | DOOR_NO_DELAY | DOOR_FORCE_REDRAW); DrawMaskedBorder(REDRAW_ALL); FadeIn(fade_mask); FadeSetEnterMenu(); -#if 1 /* update screen area with special editor door */ redraw_mask |= REDRAW_ALL; BackToFront(); -#endif SetMouseCursor(CURSOR_DEFAULT); @@ -1646,9 +1497,7 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button) FadeSoundsAndMusic(); -#if 1 FadeOut(REDRAW_ALL); -#endif } if (tci->is_image) @@ -1660,22 +1509,13 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button) fading = fading_next = getTitleFading(tci); -#if 1 -#if 1 if (!(fading_last.fade_mode & FADE_TYPE_TRANSFORM) && fading_next.fade_mode & FADE_TYPE_TRANSFORM) { fading.fade_mode = FADE_MODE_FADE; fading.fade_delay = fading_default.fade_delay; } -#else - if (fading_last.fade_mode != FADE_MODE_CROSSFADE && - fading_next.fade_mode == FADE_MODE_CROSSFADE) - fading.fade_mode = FADE_MODE_FADE; -#endif -#endif -#if 1 sound = getTitleSound(tci); music = getTitleMusic(tci); @@ -1686,13 +1526,10 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button) last_sound = sound; last_music = music; -#endif SetMouseCursor(CURSOR_NONE); -#if 1 FadeIn(REDRAW_ALL); -#endif fading = fading_next; @@ -1701,13 +1538,8 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button) return; } -#if 1 if (fading.auto_delay > 0 && DelayReached(&title_delay, fading.auto_delay)) button = MB_MENU_CHOICE; -#else - if (fading.auto_delay > -1 && DelayReached(&title_delay, fading.auto_delay)) - button = MB_MENU_CHOICE; -#endif if (button == MB_MENU_LEAVE) { @@ -1718,10 +1550,6 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button) { if (game_status == GAME_MODE_INFO && num_title_screens == 0) { -#if 0 - FadeOut(REDRAW_FIELD); -#endif - FadeSetEnterScreen(); info_mode = INFO_MODE_MAIN; @@ -1743,9 +1571,7 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button) if (music == MUS_UNDEFINED || music != last_music) FadeMusic(); -#if 1 FadeOut(REDRAW_ALL); -#endif if (tci->is_image) DrawTitleScreenImage(tci->local_nr, tci->initial); @@ -1754,7 +1580,6 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button) fading_next = getTitleFading(tci); -#if 1 sound = getTitleSound(tci); music = getTitleMusic(tci); @@ -1765,23 +1590,13 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button) last_sound = sound; last_music = music; -#endif -#if 1 /* last screen already faded out, next screen has no animation */ if (!(fading.fade_mode & FADE_TYPE_TRANSFORM) && fading_next.fade_mode == FADE_MODE_NONE) fading = fading_next; -#else - /* last screen already faded out, next screen has no animation */ - if (fading.fade_mode != FADE_MODE_CROSSFADE && - fading_next.fade_mode == FADE_MODE_NONE) - fading = fading_next; -#endif -#if 1 FadeIn(REDRAW_ALL); -#endif fading = fading_next; @@ -1797,28 +1612,18 @@ void HandleTitleScreen(int mx, int my, int dx, int dy, int button) if (return_to_main_menu) { -#if 0 - RedrawBackground(); -#endif - SetMouseCursor(CURSOR_DEFAULT); if (game_status == GAME_MODE_INFO) { -#if 0 - OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW); -#endif - info_mode = INFO_MODE_MAIN; + DrawInfoScreenExt(REDRAW_ALL, use_fading_main_menu); } else /* default: return to main menu */ { -#if 0 - OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW); -#endif - game_status = GAME_MODE_MAIN; + DrawMainMenuExt(REDRAW_ALL, use_fading_main_menu); } } @@ -1892,19 +1697,10 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) for (i = 0; main_controls[i].nr != -1; i++) { -#if 0 - printf("::: check click (%d, %d) for %d [%d] ...\n", - mx - mSX, my - mSY, i, main_controls[i].nr); -#endif - if (insideMenuPosRect(main_controls[i].pos_button, mx - mSX, my - mSY) || insideTextPosRect(main_controls[i].pos_text, mx - mSX, my - mSY) || insideTextPosRect(main_controls[i].pos_input, mx - mSX, my - mSY)) { -#if 0 - printf("::: inside %d\n", i); -#endif - pos = main_controls[i].nr; break; @@ -1936,9 +1732,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) { game_status = GAME_MODE_LEVELNR; -#if 1 ChangeViewportPropertiesIfNeeded(); -#endif DrawChooseLevelNr(); } @@ -1979,9 +1773,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) gotoTopLevelDir(); #endif -#if 1 ChangeViewportPropertiesIfNeeded(); -#endif DrawChooseLevelSet(); } @@ -1990,9 +1782,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) { game_status = GAME_MODE_SCORES; -#if 1 ChangeViewportPropertiesIfNeeded(); -#endif DrawHallOfFame(-1); } @@ -2008,11 +1798,6 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) FadeSetEnterScreen(); -#if 0 - /* needed if different viewport properties defined for editor */ - ChangeViewportPropertiesIfNeeded(); -#endif - DrawLevelEd(); } else if (pos == MAIN_CONTROL_INFO) @@ -2020,9 +1805,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) game_status = GAME_MODE_INFO; info_mode = INFO_MODE_MAIN; -#if 1 ChangeViewportPropertiesIfNeeded(); -#endif DrawInfoScreen(); } @@ -2035,9 +1818,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) game_status = GAME_MODE_SETUP; setup_mode = SETUP_MODE_MAIN; -#if 1 ChangeViewportPropertiesIfNeeded(); -#endif DrawSetupScreen(); } @@ -2051,14 +1832,6 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) } } } - -#if 0 - if (game_status == GAME_MODE_MAIN) - { - DrawPreviewLevelAnimation(); - DoAnimation(); - } -#endif } @@ -2167,18 +1940,14 @@ static void DrawInfoScreen_Main(int fade_mask, boolean do_fading) FadeSetLeaveScreen(); -#if 1 FadeOut(fade_mask); -#endif -#if 1 if (fade_mask == REDRAW_ALL) { RedrawBackground(); OpenDoor(DOOR_CLOSE_1 | DOOR_CLOSE_2 | DOOR_NO_DELAY | DOOR_FORCE_REDRAW); } -#endif ClearField(); @@ -2187,11 +1956,7 @@ static void DrawInfoScreen_Main(int fade_mask, boolean do_fading) info_info = info_info_main; num_info_info = 0; -#if 1 for (i = 0; info_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++) -#else - for (i = 0; info_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++) -#endif { if (info_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST)) initCursor(i, IMG_MENU_BUTTON_ENTER_MENU); @@ -2581,10 +2346,8 @@ void HandleInfoScreen_Elements(int button) return; } -#if 1 if (page > 0) FadeSetNextScreen(); -#endif if (button != MB_MENU_INITIALIZE) FadeOut(REDRAW_FIELD); @@ -2608,9 +2371,7 @@ void DrawInfoScreen_Music() { SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_MUSIC); -#if 1 FadeOut(REDRAW_FIELD); -#endif ClearField(); DrawHeadline(); @@ -2619,9 +2380,7 @@ void DrawInfoScreen_Music() HandleInfoScreen_Music(MB_MENU_INITIALIZE); -#if 1 FadeIn(REDRAW_FIELD); -#endif } void HandleInfoScreen_Music(int button) @@ -2688,10 +2447,8 @@ void HandleInfoScreen_Music(int button) FadeSoundsAndMusic(); -#if 1 if (list != music_file_info) FadeSetNextScreen(); -#endif if (button != MB_MENU_INITIALIZE) FadeOut(REDRAW_FIELD); @@ -2945,15 +2702,11 @@ void DrawInfoScreen_Credits() FadeSoundsAndMusic(); -#if 1 FadeOut(REDRAW_FIELD); -#endif HandleInfoScreen_Credits(MB_MENU_INITIALIZE); -#if 1 FadeIn(REDRAW_FIELD); -#endif } void HandleInfoScreen_Credits(int button) @@ -2996,10 +2749,8 @@ void HandleInfoScreen_Credits(int button) return; } -#if 1 if (screen_nr > 0) FadeSetNextScreen(); -#endif if (button != MB_MENU_INITIALIZE) FadeOut(REDRAW_FIELD); @@ -3024,9 +2775,7 @@ void DrawInfoScreen_Program() SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_PROGRAM); -#if 1 FadeOut(REDRAW_FIELD); -#endif ClearField(); DrawHeadline(); @@ -3039,7 +2788,6 @@ void DrawInfoScreen_Program() "If you like it, send e-mail to:"); DrawTextSCentered(ystart2 + 2 * ystep, FONT_TEXT_3, PROGRAM_EMAIL_STRING); -#if 1 DrawTextSCentered(ystart2 + 4 * ystep, FONT_TEXT_2, "More information and levels:"); DrawTextSCentered(ystart2 + 5 * ystep, FONT_TEXT_3, @@ -3050,35 +2798,11 @@ void DrawInfoScreen_Program() "send them to me to include them!"); DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2, ":-)"); -#else - DrawTextSCentered(ystart2 + 3 * ystep, FONT_TEXT_2, - "or SnailMail to:"); - DrawTextSCentered(ystart2 + 4 * ystep + 0, FONT_TEXT_3, - "Holger Schemel"); - DrawTextSCentered(ystart2 + 4 * ystep + 20, FONT_TEXT_3, - "Detmolder Strasse 189"); - DrawTextSCentered(ystart2 + 4 * ystep + 40, FONT_TEXT_3, - "33604 Bielefeld"); - DrawTextSCentered(ystart2 + 4 * ystep + 60, FONT_TEXT_3, - "Germany"); - DrawTextSCentered(ystart2 + 7 * ystep, FONT_TEXT_2, - "More information and levels:"); - DrawTextSCentered(ystart2 + 8 * ystep, FONT_TEXT_3, - PROGRAM_WEBSITE_STRING); - DrawTextSCentered(ystart2 + 9 * ystep, FONT_TEXT_2, - "If you have created new levels,"); - DrawTextSCentered(ystart2 + 10 * ystep, FONT_TEXT_2, - "send them to me to include them!"); - DrawTextSCentered(ystart2 + 11 * ystep, FONT_TEXT_2, - ":-)"); -#endif DrawTextSCentered(ybottom, FONT_TEXT_4, "Press any key or button for info menu"); -#if 1 FadeIn(REDRAW_FIELD); -#endif } void HandleInfoScreen_Program(int button) @@ -3098,10 +2822,6 @@ void HandleInfoScreen_Program(int button) FadeSoundsAndMusic(); -#if 0 - FadeOut(REDRAW_FIELD); -#endif - info_mode = INFO_MODE_MAIN; DrawAndFadeInInfoScreen(REDRAW_FIELD); } @@ -3122,7 +2842,6 @@ void DrawInfoScreen_Version() int ybottom = mSY - SY + SYSIZE - 20; int xstart1 = mSX - SX + 2 * xstep; int xstart2 = mSX - SX + 18 * xstep; -#if defined(TARGET_SDL) int xstart3 = mSX - SX + 28 * xstep; SDL_version sdl_version_compiled; const SDL_version *sdl_version_linked; @@ -3132,14 +2851,11 @@ void DrawInfoScreen_Version() const char *driver_name = NULL; #else char driver_name[driver_name_len]; -#endif #endif SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_VERSION); -#if 1 FadeOut(REDRAW_FIELD); -#endif ClearField(); DrawHeadline(); @@ -3151,7 +2867,7 @@ void DrawInfoScreen_Version() ystart2 += ystep; DrawTextF(xstart1, ystart2, font_header, "Version"); - DrawTextF(xstart2, ystart2, font_text, getProgramFullVersionString()); + DrawTextF(xstart2, ystart2, font_text, getProgramVersionString()); ystart2 += ystep; DrawTextF(xstart1, ystart2, font_header, "Platform"); @@ -3165,7 +2881,6 @@ void DrawInfoScreen_Version() DrawTextF(xstart1, ystart2, font_header, "Compile time"); DrawTextF(xstart2, ystart2, font_text, getCompileDateString()); -#if defined(TARGET_SDL) ystart2 += 3 * ystep; DrawTextF(xstart1, ystart2, font_header, "Library"); DrawTextF(xstart2, ystart2, font_header, "compiled"); @@ -3258,14 +2973,11 @@ void DrawInfoScreen_Version() DrawTextF(xstart1, ystart2, font_text, "SDL_AudioDriver"); DrawTextF(xstart2, ystart2, font_text, "%s", setup.system.sdl_audiodriver); DrawTextF(xstart3, ystart2, font_text, "%s", driver_name); -#endif DrawTextSCentered(ybottom, FONT_TEXT_4, "Press any key or button for info menu"); -#if 1 FadeIn(REDRAW_FIELD); -#endif } void HandleInfoScreen_Version(int button) @@ -3285,10 +2997,6 @@ void HandleInfoScreen_Version(int button) FadeSoundsAndMusic(); -#if 0 - FadeOut(REDRAW_FIELD); -#endif - info_mode = INFO_MODE_MAIN; DrawAndFadeInInfoScreen(REDRAW_FIELD); } @@ -3317,9 +3025,7 @@ void DrawInfoScreen_LevelSet() SetMainBackgroundImageIfDefined(IMG_BACKGROUND_INFO_LEVELSET); -#if 1 FadeOut(REDRAW_FIELD); -#endif ClearField(); DrawHeadline(); @@ -3337,9 +3043,7 @@ void DrawInfoScreen_LevelSet() DrawTextCentered(mSY + SYSIZE - 20, FONT_TEXT_4, "Press any key or button for info menu"); -#if 1 FadeIn(REDRAW_FIELD); -#endif } void HandleInfoScreen_LevelSet(int button) @@ -3359,10 +3063,6 @@ void HandleInfoScreen_LevelSet(int button) FadeSoundsAndMusic(); -#if 0 - FadeOut(REDRAW_FIELD); -#endif - info_mode = INFO_MODE_MAIN; DrawAndFadeInInfoScreen(REDRAW_FIELD); } @@ -3430,10 +3130,6 @@ void HandleInfoScreen(int mx, int my, int dx, int dy, int button) HandleInfoScreen_LevelSet(button); else HandleInfoScreen_Main(mx, my, dx, dy, button); - -#if 0 - DoAnimation(); -#endif } @@ -3525,18 +3221,14 @@ static void DrawChooseTree(TreeInfo **ti_ptr) CloseDoor(DOOR_CLOSE_2); -#if 1 FadeOut(REDRAW_FIELD); -#endif ClearField(); HandleChooseTree(0, 0, 0, 0, MB_MENU_INITIALIZE, ti_ptr); MapScreenTreeGadgets(*ti_ptr); -#if 1 FadeIn(REDRAW_FIELD); -#endif InitAnimation(); } @@ -3556,24 +3248,8 @@ static void AdjustScrollbar(int id, int items_max, int items_visible, static void AdjustChooseTreeScrollbar(int id, int first_entry, TreeInfo *ti) { -#if 1 AdjustScrollbar(id, numTreeInfoInGroup(ti), NUM_MENU_ENTRIES_ON_SCREEN, first_entry); -#else - struct GadgetInfo *gi = screen_gadget[id]; - int items_max, items_visible, item_position; - - items_max = numTreeInfoInGroup(ti); - items_visible = NUM_MENU_ENTRIES_ON_SCREEN; - item_position = first_entry; - - if (item_position > items_max - items_visible) - item_position = items_max - items_visible; - - ModifyGadget(gi, GDI_SCROLLBAR_ITEMS_MAX, items_max, - GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible, - GDI_SCROLLBAR_ITEM_POSITION, item_position, GDI_END); -#endif } static void drawChooseTreeList(int first_entry, int num_page_entries, @@ -3591,22 +3267,10 @@ static void drawChooseTreeList(int first_entry, int num_page_entries, DrawTextSCentered(mSY - SY + yoffset, FONT_TITLE_1, title_string); -#if 0 - /* force LEVELS font on artwork setup screen */ - game_status = GAME_MODE_LEVELS; -#endif - -#if 1 /* clear tree list area, but not title or scrollbar */ DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32, SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset, NUM_MENU_ENTRIES_ON_SCREEN * 32); -#else - /* clear tree list area, but not title or scrollbar */ - DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32, - SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset, - MAX_MENU_ENTRIES_ON_SCREEN * 32); -#endif for (i = 0; i < num_page_entries; i++) { @@ -3663,7 +3327,6 @@ static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti) DrawBackgroundForFont(SX, SY + ypos, SXSIZE, getFontHeight(font_nr), font_nr); -#if 1 if (node->parent_link) DrawTextFCentered(ypos, font_nr, "leave \"%s\"", node->node_parent->name); @@ -3674,17 +3337,6 @@ static void drawChooseTreeInfo(int entry_pos, TreeInfo *ti) DrawTextFCentered(ypos, font_nr, "%3d %s (%s)", node->levels, (node->levels > 1 ? "levels" : "level"), node->class_desc); -#else - if (node->parent_link) - DrawTextFCentered(ypos, font_nr, "leave group \"%s\"", - node->class_desc); - else if (node->level_group) - DrawTextFCentered(ypos, font_nr, "enter group \"%s\"", - node->class_desc); - else if (ti->type == TREE_TYPE_LEVEL_DIR) - DrawTextFCentered(ypos, font_nr, "%3d levels (%s)", - node->levels, node->class_desc); -#endif /* let BackToFront() redraw only what is needed */ redraw_mask = last_redraw_mask | REDRAW_TILES; @@ -3704,11 +3356,6 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, int last_game_status = game_status; /* save current game status */ boolean position_set_by_scrollbar = (dx == 999); -#if 0 - /* force LEVELS draw offset on choose level and artwork setup screen */ - game_status = GAME_MODE_LEVELS; -#endif - if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN) num_page_entries = num_entries; else @@ -3796,11 +3443,6 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, { int last_game_status = game_status; /* save current game status */ -#if 0 - /* force LEVELS draw offset on artwork setup screen */ - game_status = GAME_MODE_LEVELS; -#endif - x = (mx - mSX) / 32; y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS; @@ -3819,7 +3461,6 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, if (ti->cl_cursor + dy < 0 || ti->cl_cursor + dy > num_page_entries - 1) { -#if 1 boolean redraw = FALSE; if (ABS(dy) == SCROLL_PAGE) @@ -3856,42 +3497,6 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, ti->cl_first, ti); } -#else - - if (ABS(dy) == SCROLL_PAGE) - step = num_page_entries - 1; - - if (dy < 0 && ti->cl_first > 0) - { - /* scroll page/line up */ - - ti->cl_first -= step; - if (ti->cl_first < 0) - ti->cl_first = 0; - - drawChooseTreeList(ti->cl_first, num_page_entries, ti); - drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti); - drawChooseTreeCursor(ti->cl_cursor, TRUE); - - AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, - ti->cl_first, ti); - } - else if (dy > 0 && ti->cl_first + num_page_entries < num_entries) - { - /* scroll page/line down */ - - ti->cl_first += step; - if (ti->cl_first + num_page_entries > num_entries) - ti->cl_first = MAX(0, num_entries - num_page_entries); - - drawChooseTreeList(ti->cl_first, num_page_entries, ti); - drawChooseTreeInfo(ti->cl_first + ti->cl_cursor, ti); - drawChooseTreeCursor(ti->cl_cursor, TRUE); - - AdjustChooseTreeScrollbar(SCREEN_CTRL_ID_SCROLL_VERTICAL, - ti->cl_first, ti); - } -#endif return; } @@ -3939,11 +3544,6 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x && y >= 0 && y < num_page_entries) { -#if 0 - printf("::: TEST/HandleChooseTree [%d, %d, %d, %d]\n", Counter(), - button, mx, screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x); -#endif - if (button) { if (y != ti->cl_cursor) @@ -3985,11 +3585,7 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button, } else { -#if 1 FadeSetEnterMenu(); -#else - FadeSetEnterScreen(); -#endif node_cursor->cl_first = ti->cl_first; node_cursor->cl_cursor = ti->cl_cursor; @@ -4051,10 +3647,6 @@ void DrawChooseLevelSet() void HandleChooseLevelSet(int mx, int my, int dx, int dy, int button) { HandleChooseTree(mx, my, dx, dy, button, &leveldir_current); - -#if 0 - DoAnimation(); -#endif } void DrawChooseLevelNr() @@ -4107,11 +3699,7 @@ void DrawChooseLevelNr() SetMainBackgroundImage(IMG_BACKGROUND_LEVELNR); -#if 1 DrawChooseTree(&level_number_current); -#else - DrawChooseTree(&leveldir_current); -#endif PlayMenuSound(); PlayMenuMusic(); @@ -4119,15 +3707,7 @@ void DrawChooseLevelNr() void HandleChooseLevelNr(int mx, int my, int dx, int dy, int button) { -#if 1 HandleChooseTree(mx, my, dx, dy, button, &level_number_current); -#else - HandleChooseTree(mx, my, dx, dy, button, &leveldir_current); -#endif - -#if 0 - DoAnimation(); -#endif } void DrawHallOfFame(int highlight_position) @@ -4150,11 +3730,7 @@ void DrawHallOfFame(int highlight_position) FadeSetEnterScreen(); - // printf("::: %d: %d\n", game_status, menu.enter_screen[game_status]); - -#if 1 FadeOut(REDRAW_FIELD); -#endif InitAnimation(); @@ -4163,9 +3739,7 @@ void DrawHallOfFame(int highlight_position) HandleHallOfFame(highlight_position, 0, 0, 0, MB_MENU_INITIALIZE); -#if 1 FadeIn(REDRAW_FIELD); -#endif } static void drawHallOfFameList(int first_entry, int highlight_position) @@ -4189,22 +3763,15 @@ static void drawHallOfFameList(int first_entry, int highlight_position) int font_nr4 = (active ? FONT_TEXT_4_ACTIVE : FONT_TEXT_4); int dx1 = 3 * getFontWidth(font_nr1); int dx2 = dx1 + getFontWidth(font_nr1); -#if 1 int dx3 = SXSIZE - 5 * getFontWidth(font_nr4); int num_dots = (dx3 - dx2) / getFontWidth(font_nr3); -#else - int dx3 = dx2 + 25 * getFontWidth(font_nr3); -#endif int sy = mSY + 64 + i * 32; DrawText(mSX, sy, int2str(entry + 1, 3), font_nr1); DrawText(mSX + dx1, sy, ".", font_nr1); -#if 1 + for (j = 0; j < num_dots; j++) DrawText(mSX + dx2 + j * getFontWidth(font_nr3), sy, ".", font_nr3); -#else - DrawText(mSX + dx2, sy, ".........................", font_nr3); -#endif if (!strEqual(highscore[entry].Name, EMPTY_PLAYER_NAME)) DrawText(mSX + dx2, sy, highscore[entry].Name, font_nr2); @@ -4271,10 +3838,6 @@ void HandleHallOfFame(int mx, int my, int dx, int dy, int button) FadeSound(SND_BACKGROUND_SCORES); -#if 0 - FadeOut(REDRAW_FIELD); -#endif - game_status = GAME_MODE_MAIN; DrawAndFadeInMainMenu(REDRAW_FIELD); @@ -4282,10 +3845,6 @@ void HandleHallOfFame(int mx, int my, int dx, int dy, int button) if (game_status == GAME_MODE_SCORES) PlayMenuSoundIfLoop(); - -#if 0 - DoAnimation(); -#endif } @@ -4680,11 +4239,6 @@ static void execSetupGraphics() #if defined(TARGET_SDL2) static void execSetupChooseWindowSize() { -#if 0 - if (!video.window_scaling_available) - return; -#endif - setup_mode = SETUP_MODE_CHOOSE_WINDOW_SIZE; DrawSetupScreen(); @@ -4732,7 +4286,6 @@ static void execSetupChooseVolumeMusic() static void execSetupSound() { -#if 1 if (volumes_simple == NULL) { int i; @@ -4867,7 +4420,6 @@ static void execSetupSound() volume_simple_text = volume_simple_current->name; volume_loops_text = volume_loops_current->name; volume_music_text = volume_music_current->name; -#endif setup_mode = SETUP_MODE_SOUND; @@ -4897,7 +4449,6 @@ static void execSetupChooseDropDistance() static void execSetupTouch() { -#if 1 if (touch_controls == NULL) { int i; @@ -5034,7 +4585,6 @@ static void execSetupTouch() touch_controls_text = touch_control_current->name; move_distance_text = move_distance_current->name; drop_distance_text = drop_distance_current->name; -#endif setup_mode = SETUP_MODE_TOUCH; @@ -5231,24 +4781,16 @@ static struct TokenInfo setup_info_graphics[] = #if defined(TARGET_SDL2) { TYPE_ENTER_LIST, execSetupChooseWindowSize, "Window Scaling:" }, { TYPE_STRING, &window_size_text, "" }, -#if 1 { TYPE_ENTER_LIST, execSetupChooseScalingType, "Anti-Aliasing:" }, { TYPE_STRING, &scaling_type_text, "" }, -#endif #else { TYPE_ENTER_LIST, execSetupChooseScreenMode, "Fullscreen Mode:" }, { TYPE_STRING, &screen_mode_text, "" }, #endif #endif -#if 0 - { TYPE_SWITCH, &setup.scroll_delay, "Scroll Delay:" }, -#endif #if 0 { TYPE_ENTER_LIST, execSetupChooseScrollDelay, "Scroll Delay:" }, { TYPE_STRING, &scroll_delay_text, "" }, -#endif -#if 0 - { TYPE_SWITCH, &setup.soft_scrolling, "Soft Scrolling:" }, #endif { TYPE_SWITCH, &setup.fade_screens, "Fade Screens:" }, { TYPE_SWITCH, &setup.quick_switch, "Quick Player Focus Switch:" }, @@ -5291,23 +4833,9 @@ static struct TokenInfo setup_info_artwork[] = { TYPE_ENTER_LIST, execSetupChooseMusic, "Custom Music:" }, { TYPE_STRING, &music_set_name, "" }, { TYPE_EMPTY, NULL, "" }, -#if 1 -#if 1 { TYPE_YES_NO_AUTO,&setup.override_level_graphics,"Override Level Graphics:"}, { TYPE_YES_NO_AUTO,&setup.override_level_sounds, "Override Level Sounds:" }, { TYPE_YES_NO_AUTO,&setup.override_level_music, "Override Level Music:" }, -#else - { TYPE_YES_NO, &setup.override_level_graphics,"Override Level Graphics:" }, - { TYPE_YES_NO, &setup.override_level_sounds, "Override Level Sounds:" }, - { TYPE_YES_NO, &setup.override_level_music, "Override Level Music:" }, - { TYPE_YES_NO, &setup.auto_override_artwork, "Auto-Override Non-CE Sets:" }, -#endif -#else - { TYPE_STRING, NULL, "Override Level Artwork:"}, - { TYPE_YES_NO, &setup.override_level_graphics, "Graphics:" }, - { TYPE_YES_NO, &setup.override_level_sounds, "Sounds:" }, - { TYPE_YES_NO, &setup.override_level_music, "Music:" }, -#endif { TYPE_EMPTY, NULL, "" }, { TYPE_LEAVE_MENU, execSetupMain, "Back" }, @@ -5525,7 +5053,6 @@ static int getSetupValueFont(int type, void *value) return FONT_VALUE_1; } -#if 1 static void drawSetupValue(int screen_pos, int setup_info_pos_raw) { int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw); @@ -5540,15 +5067,10 @@ static void drawSetupValue(int screen_pos, int setup_info_pos_raw) int startx = mSX + xpos * 32; int starty = mSY + ypos * 32; int font_nr, font_width; -#if 0 - int font_height; -#endif int type = si->type; void *value = si->value; char *value_string = getSetupValue(type, value); -#if 1 int i; -#endif if (value_string == NULL) return; @@ -5578,14 +5100,6 @@ static void drawSetupValue(int screen_pos, int setup_info_pos_raw) starty = mSY + ypos * 32; font_nr = getSetupValueFont(type, value); font_width = getFontWidth(font_nr); -#if 0 - font_height = getFontHeight(font_nr); -#endif - -#if 0 - if (menu_screen_value_xpos < 1 + MAX_MENU_TEXT_LENGTH_BIG) - font_nr = ...; -#endif /* downward compatibility correction for Juergen Bonhagen's menu settings */ if (setup_mode != SETUP_MODE_INPUT) @@ -5625,14 +5139,8 @@ static void drawSetupValue(int screen_pos, int setup_info_pos_raw) } } -#if 0 - DrawBackground(startx, starty, SX + SXSIZE - startx, font_height); -#else for (i = 0; i <= menu_screen_max_xpos - xpos; i++) DrawText(startx + i * font_width, starty, " ", font_nr); -#endif - - // printf("::: startx == %d\n", startx); DrawText(startx, starty, value_string, font_nr); @@ -5640,109 +5148,6 @@ static void drawSetupValue(int screen_pos, int setup_info_pos_raw) getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old; } -#else - -static void drawSetupValue(int pos) -{ - boolean font_draw_xoffset_modified = FALSE; - int font_draw_xoffset_old = -1; - int xpos = MENU_SCREEN_VALUE_XPOS; - int ypos = MENU_SCREEN_START_YPOS + pos; - int startx = mSX + xpos * 32; - int starty = mSY + ypos * 32; - int font_nr, font_width; -#if 0 - int font_height; -#endif - int type = setup_info[pos].type; - void *value = setup_info[pos].value; - char *value_string = getSetupValue(type, value); -#if 1 - int i; -#endif - - if (value_string == NULL) - return; - - if (type & TYPE_KEY) - { - xpos = MENU_SCREEN_START_XPOS; - - if (type & TYPE_QUERY) - value_string = ""; - } - else if (type & TYPE_STRING) - { - int max_value_len = (SCR_FIELDX - 2) * 2; - - xpos = MENU_SCREEN_START_XPOS; - - if (strlen(value_string) > max_value_len) - value_string[max_value_len] = '\0'; - } - else if (type & TYPE_YES_NO_AUTO) - { - xpos = MENU_SCREEN_VALUE_XPOS - 1; - } - - startx = mSX + xpos * 32; - starty = mSY + ypos * 32; - font_nr = getSetupValueFont(type, value); - font_width = getFontWidth(font_nr); -#if 0 - font_height = getFontHeight(font_nr); -#endif - - /* downward compatibility correction for Juergen Bonhagen's menu settings */ - if (setup_mode != SETUP_MODE_INPUT) - { - int check_font_nr = FONT_OPTION_ON; /* known font that needs correction */ - int font1_xoffset = getFontBitmapInfo(font_nr)->draw_xoffset; - int font2_xoffset = getFontBitmapInfo(check_font_nr)->draw_xoffset; - int text_startx = mSX + MENU_SCREEN_START_XPOS * 32; - int text_font_nr = getSetupTextFont(FONT_MENU_2); - int text_font_xoffset = getFontBitmapInfo(text_font_nr)->draw_xoffset; - int text_width = MAX_MENU_TEXT_LENGTH_MEDIUM * getFontWidth(text_font_nr); - boolean correct_font_draw_xoffset = FALSE; - - if (xpos == MENU_SCREEN_START_XPOS && - startx + font1_xoffset < text_startx + text_font_xoffset) - correct_font_draw_xoffset = TRUE; - - if (xpos == MENU_SCREEN_VALUE_XPOS && - startx + font2_xoffset < text_startx + text_width + text_font_xoffset) - correct_font_draw_xoffset = TRUE; - - /* check if setup value would overlap with setup text when printed */ - /* (this can happen for extreme/wrong values for font draw offset) */ - if (correct_font_draw_xoffset) - { - font_draw_xoffset_old = getFontBitmapInfo(font_nr)->draw_xoffset; - font_draw_xoffset_modified = TRUE; - - if (type & TYPE_KEY) - getFontBitmapInfo(font_nr)->draw_xoffset += 2 * getFontWidth(font_nr); - else if (!(type & TYPE_STRING)) - getFontBitmapInfo(font_nr)->draw_xoffset = text_font_xoffset + 20 - - MAX_MENU_TEXT_LENGTH_MEDIUM * (16 - getFontWidth(text_font_nr)); - } - } - -#if 0 - DrawBackground(startx, starty, SX + SXSIZE - startx, font_height); -#else - for (i = 0; i <= MENU_SCREEN_MAX_XPOS - xpos; i++) - DrawText(startx + i * font_width, starty, " ", font_nr); -#endif - - DrawText(startx, starty, value_string, font_nr); - - if (font_draw_xoffset_modified) - getFontBitmapInfo(font_nr)->draw_xoffset = font_draw_xoffset_old; -} -#endif - -#if 1 static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx) { int si_pos = (setup_info_pos_raw < 0 ? screen_pos : setup_info_pos_raw); @@ -5781,45 +5186,6 @@ static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx) ToggleFullscreenOrChangeWindowScalingIfNeeded(); } -#else - -static void changeSetupValue(int pos, int dx) -{ - if (setup_info[pos].type & TYPE_BOOLEAN_STYLE) - { - *(boolean *)setup_info[pos].value ^= TRUE; - } - else if (setup_info[pos].type & TYPE_YES_NO_AUTO) - { - *(int *)setup_info[pos].value = - (dx == -1 ? - (*(int *)setup_info[pos].value == AUTO ? TRUE : - *(int *)setup_info[pos].value == TRUE ? FALSE : AUTO) : - (*(int *)setup_info[pos].value == TRUE ? AUTO : - *(int *)setup_info[pos].value == AUTO ? FALSE : TRUE)); - } - else if (setup_info[pos].type & TYPE_KEY) - { - Key key; - - setup_info[pos].type |= TYPE_QUERY; - drawSetupValue(pos, -1); - setup_info[pos].type &= ~TYPE_QUERY; - - key = getSetupKey(); - if (key != KSYM_UNDEFINED) - *(Key *)setup_info[pos].value = key; - } - - drawSetupValue(pos, -1); - - // fullscreen state may have changed at this point - if (setup_info[pos].value == &setup.fullscreen) - ToggleFullscreenOrChangeWindowScalingIfNeeded(); -} -#endif - -#if 1 static void DrawCursorAndText_Setup(int screen_pos, int setup_info_pos_raw, boolean active) { @@ -5840,25 +5206,6 @@ static void DrawCursorAndText_Setup(int screen_pos, int setup_info_pos_raw, if (si->type & ~TYPE_SKIP_ENTRY) drawCursor(screen_pos, active); } -#else -static void DrawCursorAndText_Setup(int pos, boolean active) -{ - int xpos = MENU_SCREEN_START_XPOS; - int ypos = MENU_SCREEN_START_YPOS + pos; - int font_nr = getSetupTextFont(setup_info[pos].type); - - if (setup_info == setup_info_input) - font_nr = FONT_MENU_1; - - if (active) - font_nr = FONT_ACTIVE(font_nr); - - DrawText(mSX + xpos * 32, mSY + ypos * 32, setup_info[pos].text, font_nr); - - if (setup_info[pos].type & ~TYPE_SKIP_ENTRY) - drawCursor(pos, active); -} -#endif static void drawSetupInfoList(struct TokenInfo *setup_info, int first_entry, int num_page_entries) @@ -5874,12 +5221,10 @@ static void drawSetupInfoList(struct TokenInfo *setup_info, if (first_entry + num_page_entries > max_setup_info) first_entry = 0; -#if 1 /* clear tree list area, but not title or scrollbar */ DrawBackground(mSX, mSY + MENU_SCREEN_START_YPOS * 32, SC_SCROLLBAR_XPOS + menu.scrollbar_xoffset, NUM_MENU_ENTRIES_ON_SCREEN * 32); -#endif for (i = 0; i < num_page_entries; i++) { @@ -5919,28 +5264,15 @@ static void DrawSetupScreen_Generic() UnmapAllGadgets(); -#if 1 FreeScreenGadgets(); CreateScreenGadgets(); -#endif CloseDoor(DOOR_CLOSE_2); if (redraw_mask & REDRAW_ALL) redraw_all = TRUE; -#if 0 - printf("::: %s\n", (redraw_mask & REDRAW_FIELD ? "REDRAW_FIELD" : - redraw_mask & REDRAW_ALL ? "REDRAW_ALL" : - int2str(0, redraw_mask))); -#endif - -#if 0 - /* !!! usually REDRAW_NONE => DOES NOT WORK (with fade) => CHECK THIS !!! */ - FadeOut(redraw_mask); -#else FadeOut(REDRAW_FIELD); -#endif ClearField(); @@ -6012,8 +5344,6 @@ static void DrawSetupScreen_Generic() DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, title_string); -#if 1 - num_setup_info = 0; for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++) num_setup_info++; @@ -6022,73 +5352,16 @@ static void DrawSetupScreen_Generic() for (i = 0; setup_info[i].type != 0; i++) max_setup_info++; -#if 0 - drawSetupInfoList(setup_info, 0, NUM_MENU_ENTRIES_ON_SCREEN); -#endif - -#else - - num_setup_info = 0; -#if 1 - for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++) -#else - for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++) -#endif - { - void *value_ptr = setup_info[i].value; - - /* set some entries to "unchangeable" according to other variables */ - if ((value_ptr == &setup.sound_simple && !audio.sound_available) || - (value_ptr == &setup.sound_loops && !audio.loops_available) || - (value_ptr == &setup.sound_music && !audio.music_available) || - (value_ptr == &setup.fullscreen && !video.fullscreen_available) || - (value_ptr == &screen_mode_text && !video.fullscreen_available) || - (value_ptr == &window_size_text && !video.window_scaling_available) || - (value_ptr == &scaling_type_text && !video.window_scaling_available)) - setup_info[i].type |= TYPE_GHOSTED; - - if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST)) - initCursor(i, IMG_MENU_BUTTON_ENTER_MENU); - else if (setup_info[i].type & (TYPE_LEAVE_MENU|TYPE_LEAVE_LIST)) - initCursor(i, IMG_MENU_BUTTON_LEAVE_MENU); - else if (setup_info[i].type & ~TYPE_SKIP_ENTRY) - initCursor(i, IMG_MENU_BUTTON); - - DrawCursorAndText_Setup(i, FALSE); - - if (setup_info[i].type & TYPE_VALUE) - drawSetupValue(i); - - num_setup_info++; - } -#endif - -#if 0 - DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4, - "Joysticks deactivated in setup menu"); -#endif - -#if 1 HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE); -#endif -#if 1 MapScreenGadgets(max_setup_info); -#endif if (redraw_all) redraw_mask = REDRAW_ALL; -#if 1 FadeIn(redraw_mask); -#else - FadeIn(REDRAW_FIELD); -#endif InitAnimation(); -#if 0 - HandleSetupScreen_Generic(0, 0, 0, 0, MB_MENU_INITIALIZE); -#endif } void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button) @@ -6098,19 +5371,13 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button) int choice = choice_store[setup_mode]; /* starts with 0 */ int first_entry = first_entry_store[setup_mode]; /* starts with 0 */ int x = 0; -#if 1 int y = choice - first_entry; int y_old = y; -#else - int y = choice; -#endif boolean position_set_by_scrollbar = (dx == 999); -#if 1 int step = (button == 1 ? 1 : button == 2 ? 5 : 10); int num_page_entries; num_page_entries = MIN(max_setup_info, NUM_MENU_ENTRIES_ON_SCREEN); -#endif if (button == MB_MENU_INITIALIZE) { @@ -6118,11 +5385,7 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button) while (choice < num_setup_info && setup_info[choice].type & TYPE_SKIP_ENTRY) choice++; -#if 0 - choice_store[setup_mode] = choice; -#endif -#if 1 if (position_set_by_scrollbar) first_entry = first_entry_store[setup_mode] = dy; else @@ -6130,9 +5393,7 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button) NUM_MENU_ENTRIES_ON_SCREEN, first_entry); drawSetupInfoList(setup_info, first_entry, NUM_MENU_ENTRIES_ON_SCREEN); -#endif -#if 1 if (choice < first_entry) { choice = first_entry; @@ -6151,9 +5412,6 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button) choice_store[setup_mode] = choice; DrawCursorAndText_Setup(choice - first_entry, choice, TRUE); -#else - DrawCursorAndText_Setup(choice, -1, TRUE); -#endif return; } @@ -6185,11 +5443,7 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button) x = (mx - mSX) / 32; y = (my - mSY) / 32 - MENU_SCREEN_START_YPOS; } -#if 1 else if (dx || dy) /* keyboard or scrollbar/scrollbutton input */ -#else - else if (dx || dy) /* keyboard input */ -#endif { /* move cursor instead of scrolling when already at start/end of list */ if (dy == -1 * SCROLL_LINE && first_entry == 0) @@ -6246,7 +5500,6 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button) if (setup_info[choice].type & TYPE_SKIP_ENTRY) choice--; } -#if 1 else if (setup_info[choice].type & TYPE_SKIP_ENTRY) { choice += SIGN(dy); @@ -6255,9 +5508,6 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button) choice > first_entry + num_page_entries - 1) first_entry += SIGN(dy); } -#endif - - // printf("::: MARK 1: %d\n", first_entry); first_entry_store[setup_mode] = first_entry; choice_store[setup_mode] = choice; @@ -6282,37 +5532,23 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button) setup_info[choice].type & TYPE_YES_NO_AUTO) button = MB_MENU_CHOICE; } -#if 1 else if (dy) y += dy; -#else - else if (dy) - y = choice + dy; -#endif /* jump to next non-empty menu entry (up or down) */ -#if 1 while (first_entry + y > 0 && first_entry + y < max_setup_info - 1 && setup_info[first_entry + y].type & TYPE_SKIP_ENTRY) y += dy; -#else - while (y > 0 && y < num_setup_info - 1 && - setup_info[first_entry + y].type & TYPE_SKIP_ENTRY) - y += dy; -#endif if (!IN_VIS_FIELD(x, y)) { choice += y - y_old; -#if 1 + if (choice < first_entry) first_entry = choice; else if (choice > first_entry + num_page_entries - 1) first_entry = choice - num_page_entries + 1; -#else - first_entry += y - y_old; -#endif if (first_entry >= 0 && first_entry + num_page_entries <= max_setup_info) @@ -6338,23 +5574,13 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button) } } -#if 1 if (!anyScrollbarGadgetActive() && IN_VIS_FIELD(x, y) && mx < screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x && y >= 0 && y < num_page_entries) -#else - if (IN_VIS_FIELD(x, y) && y >= 0 && y < num_setup_info) -#endif { -#if 0 - printf("::: TEST/HandleSetupScreen_Generic [%d, %d, %d, %d]\n", Counter(), - button, mx, screen_gadget[SCREEN_CTRL_ID_SCROLL_VERTICAL]->x); -#endif - if (button) { -#if 1 if (first_entry + y != choice && setup_info[first_entry + y].type & ~TYPE_SKIP_ENTRY) { @@ -6365,19 +5591,7 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button) choice = choice_store[setup_mode] = first_entry + y; } -#else - if (y != choice && setup_info[y].type & ~TYPE_SKIP_ENTRY) - { - PlaySound(SND_MENU_ITEM_ACTIVATING); - - DrawCursorAndText_Setup(choice, -1, FALSE); - DrawCursorAndText_Setup(y, -1, TRUE); - - choice = choice_store[setup_mode] = y; - } -#endif } -#if 1 else if (!(setup_info[first_entry + y].type & TYPE_GHOSTED)) { PlaySound(SND_MENU_ITEM_SELECTING); @@ -6407,36 +5621,6 @@ void HandleSetupScreen_Generic(int mx, int my, int dx, int dy, int button) changeSetupValue(y, first_entry + y, dx); } } -#else - else if (!(setup_info[y].type & TYPE_GHOSTED)) - { - PlaySound(SND_MENU_ITEM_SELECTING); - - /* when selecting key headline, execute function for key value change */ - if (setup_info[y].type & TYPE_KEYTEXT && - setup_info[y + 1].type & TYPE_KEY) - y++; - - /* when selecting string value, execute function for list selection */ - if (setup_info[y].type & TYPE_STRING && y > 0 && - setup_info[y - 1].type & TYPE_ENTER_LIST) - y--; - - if (setup_info[y].type & TYPE_ENTER_OR_LEAVE) - { - void (*menu_callback_function)(void) = setup_info[y].value; - - FadeSetFromType(setup_info[y].type); - - menu_callback_function(); - } - else - { - if (setup_info[y].type & TYPE_VALUE) - changeSetupValue(y, dx); - } - } -#endif } } @@ -6444,33 +5628,18 @@ void DrawSetupScreen_Input() { int i; -#if 1 FadeOut(REDRAW_FIELD); -#endif ClearField(); -#if 1 setup_info = setup_info_input; -#endif DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Setup Input"); -#if 1 -#if 1 DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2, "Joysticks deactivated on this screen"); -#else - DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4, - "Joysticks deactivated on this screen"); -#endif -#endif -#if 1 for (i = 0; setup_info[i].type != 0 && i < MAX_MENU_ENTRIES_ON_SCREEN; i++) -#else - for (i = 0; setup_info[i].type != 0 && i < NUM_MENU_ENTRIES_ON_SCREEN; i++) -#endif { if (setup_info[i].type & (TYPE_ENTER_MENU|TYPE_ENTER_LIST)) initCursor(i, IMG_MENU_BUTTON_ENTER_MENU); @@ -6482,20 +5651,6 @@ void DrawSetupScreen_Input() DrawCursorAndText_Setup(i, -1, FALSE); } -#if 0 - DeactivateJoystickForCalibration(); -#endif - -#if 0 -#if 1 - DrawTextSCentered(SYSIZE - 20, FONT_TITLE_2, - "Joysticks deactivated on this screen"); -#else - DrawTextSCentered(SYSIZE - 20, FONT_TEXT_4, - "Joysticks deactivated on this screen"); -#endif -#endif - /* create gadgets for setup input menu screen */ FreeScreenGadgets(); CreateScreenGadgets(); @@ -6505,9 +5660,7 @@ void DrawSetupScreen_Input() HandleSetupScreen_Input(0, 0, 0, 0, MB_MENU_INITIALIZE); -#if 1 FadeIn(REDRAW_FIELD); -#endif InitAnimation(); } @@ -6780,11 +5933,6 @@ void CustomizeKeyboard(int player_nr) DrawTextSCentered(mSY - SY + 16, FONT_TITLE_1, "Keyboard Input"); -#if 0 - BackToFront(); - InitAnimation(); -#endif - step_nr = 0; DrawText(mSX, mSY + (2 + 2 * step_nr) * 32, customize_step[step_nr].text, FONT_INPUT_1_ACTIVE); @@ -6793,11 +5941,9 @@ void CustomizeKeyboard(int player_nr) DrawText(mSX + 4 * 32, mSY + (2 + 2 * step_nr + 1) * 32, getKeyNameFromKey(*customize_step[step_nr].key), FONT_VALUE_OLD); -#if 1 FadeIn(REDRAW_FIELD); InitAnimation(); -#endif while (!finished) { @@ -7034,20 +6180,6 @@ static boolean CalibrateJoystickMain(int player_nr) check[x+1][y+1] = TRUE; check_remaining--; } - -#if 0 -#ifdef DEBUG - printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n", - setup.input[player_nr].joy.xleft, - setup.input[player_nr].joy.xmiddle, - setup.input[player_nr].joy.xright); - printf("UP / MIDDLE / DOWN == %d / %d / %d\n", - setup.input[player_nr].joy.yupper, - setup.input[player_nr].joy.ymiddle, - setup.input[player_nr].joy.ylower); -#endif -#endif - } DoAnimation(); @@ -7066,10 +6198,6 @@ static boolean CalibrateJoystickMain(int player_nr) StopAnimation(); -#if 0 - DrawSetupScreen_Input(); -#endif - /* wait until the last pressed button was released */ while (Joystick(player_nr) & JOY_BUTTON) { @@ -7107,9 +6235,7 @@ void CalibrateJoystick(int player_nr) ClearEventQueue(); } -#if 1 DrawSetupScreen_Input(); -#endif } void DrawSetupScreen() @@ -7157,7 +6283,6 @@ void DrawSetupScreen() void RedrawSetupScreenAfterFullscreenToggle() { -#if 1 if (setup_mode == SETUP_MODE_GRAPHICS || setup_mode == SETUP_MODE_CHOOSE_WINDOW_SIZE) { @@ -7166,10 +6291,6 @@ void RedrawSetupScreenAfterFullscreenToggle() DrawSetupScreen(); } -#else - if (setup_mode == SETUP_MODE_GRAPHICS) - DrawSetupScreen(); -#endif } void HandleSetupScreen(int mx, int my, int dx, int dy, int button) @@ -7206,10 +6327,6 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current); else HandleSetupScreen_Generic(mx, my, dx, dy, button); - -#if 0 - DoAnimation(); -#endif } void HandleGameActions() @@ -7230,7 +6347,6 @@ static void getScreenMenuButtonPos(int *x, int *y, int gadget_id) { switch (gadget_id) { -#if 1 case SCREEN_CTRL_ID_PREV_LEVEL: *x = mSX + GDI_ACTIVE_POS(menu.main.button.prev_level.x); *y = mSY + GDI_ACTIVE_POS(menu.main.button.prev_level.y); @@ -7240,17 +6356,6 @@ static void getScreenMenuButtonPos(int *x, int *y, int gadget_id) *x = mSX + GDI_ACTIVE_POS(menu.main.button.next_level.x); *y = mSY + GDI_ACTIVE_POS(menu.main.button.next_level.y); break; -#else - case SCREEN_CTRL_ID_PREV_LEVEL: - *x = mSX + TILEX * getPrevlevelButtonPos(); - *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1); - break; - - case SCREEN_CTRL_ID_NEXT_LEVEL: - *x = mSX + TILEX * getNextLevelButtonPos(); - *y = mSY + TILEY * (MENU_SCREEN_START_YPOS + 1); - break; -#endif case SCREEN_CTRL_ID_PREV_PLAYER: *x = mSX + TILEX * 10; @@ -7316,21 +6421,13 @@ static struct { { IMG_MENU_BUTTON_UP, IMG_MENU_BUTTON_UP_ACTIVE, -#if 1 -1, -1, /* these values are not constant, but can change at runtime */ -#else - SC_SCROLL_UP_XPOS, SC_SCROLL_UP_YPOS, -#endif SCREEN_CTRL_ID_SCROLL_UP, "scroll up" }, { IMG_MENU_BUTTON_DOWN, IMG_MENU_BUTTON_DOWN_ACTIVE, -#if 1 -1, -1, /* these values are not constant, but can change at runtime */ -#else - SC_SCROLL_DOWN_XPOS, SC_SCROLL_DOWN_YPOS, -#endif SCREEN_CTRL_ID_SCROLL_DOWN, "scroll down" } @@ -7348,13 +6445,8 @@ static struct { { IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE, -#if 1 -1, -1, /* these values are not constant, but can change at runtime */ -1, -1, /* these values are not constant, but can change at runtime */ -#else - SC_SCROLL_VERTICAL_XPOS, SC_SCROLL_VERTICAL_YPOS, - SC_SCROLL_VERTICAL_XSIZE, SC_SCROLL_VERTICAL_YSIZE, -#endif GD_TYPE_SCROLLBAR_VERTICAL, SCREEN_CTRL_ID_SCROLL_VERTICAL, "scroll level series vertically" @@ -7533,17 +6625,10 @@ static void CreateScreenScrollbars() GDI_SCROLLBAR_ITEMS_MAX, items_max, GDI_SCROLLBAR_ITEMS_VISIBLE, items_visible, GDI_SCROLLBAR_ITEM_POSITION, item_position, -#if 1 GDI_WHEEL_AREA_X, SX, GDI_WHEEL_AREA_Y, SY, GDI_WHEEL_AREA_WIDTH, SXSIZE, GDI_WHEEL_AREA_HEIGHT, SYSIZE, -#else - GDI_WHEEL_AREA_X, 0, - GDI_WHEEL_AREA_Y, 0, - GDI_WHEEL_AREA_WIDTH, WIN_XSIZE, - GDI_WHEEL_AREA_HEIGHT, WIN_YSIZE, -#endif GDI_STATE, GD_BUTTON_UNPRESSED, GDI_DESIGN_UNPRESSED, gd_bitmap_unpressed, gd_x1, gd_y1, GDI_DESIGN_PRESSED, gd_bitmap_pressed, gd_x2, gd_y2, @@ -7566,11 +6651,6 @@ void CreateScreenGadgets() CreateScreenMenubuttons(); -#if 0 - /* force LEVELS draw offset for scrollbar / scrollbutton gadgets */ - game_status = GAME_MODE_LEVELS; -#endif - CreateScreenScrollbuttons(); CreateScreenScrollbars(); @@ -7610,21 +6690,7 @@ void MapScreenGadgets(int num_entries) void MapScreenTreeGadgets(TreeInfo *ti) { -#if 1 MapScreenGadgets(numTreeInfoInGroup(ti)); -#else - int num_entries = numTreeInfoInGroup(ti); - int i; - - if (num_entries <= NUM_MENU_ENTRIES_ON_SCREEN) - return; - - for (i = 0; i < NUM_SCREEN_SCROLLBUTTONS; i++) - MapGadget(screen_gadget[scrollbutton_info[i].gadget_id]); - - for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++) - MapGadget(screen_gadget[scrollbar_info[i].gadget_id]); -#endif } static void HandleScreenGadgets(struct GadgetInfo *gi) diff --git a/src/tape.c b/src/tape.c index 4f123917..526c6d1d 100644 --- a/src/tape.c +++ b/src/tape.c @@ -193,160 +193,6 @@ void DrawVideoDisplay(unsigned int state, unsigned int value) "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" }; -#if 0 - static struct - { - int gd_x1, gd_y1; - int gd_x2, gd_y2; - int x, y; - int width, height; - } - video_pos[NUM_TAPE_FUNCTIONS][NUM_TAPE_FUNCTION_PARTS] = - { - { - { - PG_X4(VIDEO_PLAY_LABEL_XPOS), PG_Y2(VIDEO_PLAY_LABEL_YPOS), - PG_X3(VIDEO_PLAY_LABEL_XPOS), PG_Y2(VIDEO_PLAY_LABEL_YPOS), - VIDEO_PLAY_LABEL_XPOS, VIDEO_PLAY_LABEL_YPOS, - VIDEO_PLAY_LABEL_XSIZE, VIDEO_PLAY_LABEL_YSIZE - }, - { - PG_X4(VIDEO_PLAY_SYMBOL_XPOS), PG_Y2(VIDEO_PLAY_SYMBOL_YPOS), - PG_X3(VIDEO_PLAY_SYMBOL_XPOS), PG_Y2(VIDEO_PLAY_SYMBOL_YPOS), - VIDEO_PLAY_SYMBOL_XPOS, VIDEO_PLAY_SYMBOL_YPOS, - VIDEO_PLAY_SYMBOL_XSIZE, VIDEO_PLAY_SYMBOL_YSIZE - } - }, - { - { - PG_X4(VIDEO_REC_LABEL_XPOS), PG_Y2(VIDEO_REC_LABEL_YPOS), - PG_X3(VIDEO_REC_LABEL_XPOS), PG_Y2(VIDEO_REC_LABEL_YPOS), - VIDEO_REC_LABEL_XPOS, VIDEO_REC_LABEL_YPOS, - VIDEO_REC_LABEL_XSIZE, VIDEO_REC_LABEL_YSIZE - }, - { - PG_X4(VIDEO_REC_SYMBOL_XPOS), PG_Y2(VIDEO_REC_SYMBOL_YPOS), - PG_X3(VIDEO_REC_SYMBOL_XPOS), PG_Y2(VIDEO_REC_SYMBOL_YPOS), - VIDEO_REC_SYMBOL_XPOS, VIDEO_REC_SYMBOL_YPOS, - VIDEO_REC_SYMBOL_XSIZE, VIDEO_REC_SYMBOL_YSIZE - } - }, - { - { - PG_X4(VIDEO_PAUSE_LABEL_XPOS), PG_Y2(VIDEO_PAUSE_LABEL_YPOS), - PG_X3(VIDEO_PAUSE_LABEL_XPOS), PG_Y2(VIDEO_PAUSE_LABEL_YPOS), - VIDEO_PAUSE_LABEL_XPOS, VIDEO_PAUSE_LABEL_YPOS, - VIDEO_PAUSE_LABEL_XSIZE, VIDEO_PAUSE_LABEL_YSIZE - }, - { - PG_X4(VIDEO_PAUSE_SYMBOL_XPOS), PG_Y2(VIDEO_PAUSE_SYMBOL_YPOS), - PG_X3(VIDEO_PAUSE_SYMBOL_XPOS), PG_Y2(VIDEO_PAUSE_SYMBOL_YPOS), - VIDEO_PAUSE_SYMBOL_XPOS, VIDEO_PAUSE_SYMBOL_YPOS, - VIDEO_PAUSE_SYMBOL_XSIZE, VIDEO_PAUSE_SYMBOL_YSIZE - } - }, - { - { - PG_X4(VIDEO_DATE_LABEL_XPOS), PG_Y2(VIDEO_DATE_LABEL_YPOS), - PG_X3(VIDEO_DATE_LABEL_XPOS), PG_Y2(VIDEO_DATE_LABEL_YPOS), - VIDEO_DATE_LABEL_XPOS, VIDEO_DATE_LABEL_YPOS, - VIDEO_DATE_LABEL_XSIZE, VIDEO_DATE_LABEL_YSIZE - }, - { - PG_X4(VIDEO_DATE_XPOS), PG_Y2(VIDEO_DATE_YPOS), - PG_X3(VIDEO_DATE_XPOS), PG_Y2(VIDEO_DATE_YPOS), - VIDEO_DATE_XPOS, VIDEO_DATE_YPOS, - VIDEO_DATE_XSIZE, VIDEO_DATE_YSIZE - } - }, - { - { - -1, -1, - -1, -1, - -1, -1, - -1, -1 - }, - { - PG_X4(VIDEO_TIME_XPOS), PG_Y2(VIDEO_TIME_YPOS), - PG_X3(VIDEO_TIME_XPOS), PG_Y2(VIDEO_TIME_YPOS), - VIDEO_TIME_XPOS, VIDEO_TIME_YPOS, - VIDEO_TIME_XSIZE, VIDEO_TIME_YSIZE - } - }, - { - { - PG_X6(VIDEO_FFWD_LABEL_XPOS), PG_Y1(VIDEO_FFWD_LABEL_YPOS), - PG_X3(VIDEO_LABEL_XPOS), PG_Y2(VIDEO_LABEL_YPOS), - VIDEO_LABEL_XPOS, VIDEO_LABEL_YPOS, - VIDEO_LABEL_XSIZE, VIDEO_LABEL_YSIZE - }, - { - PG_X6(VIDEO_FFWD_SYMBOL_XPOS), PG_Y1(VIDEO_FFWD_SYMBOL_YPOS), - PG_X3(VIDEO_FFWD_SYMBOL_XPOS), PG_Y2(VIDEO_SYMBOL_YPOS), - VIDEO_SYMBOL_XPOS, VIDEO_SYMBOL_YPOS, - VIDEO_FFWD_SYMBOL_XSIZE, VIDEO_FFWD_SYMBOL_YSIZE - } - }, - { - { - PG_X6(VIDEO_PBEND_LABEL_XPOS), PG_Y1(VIDEO_PBEND_LABEL_YPOS), - PG_X3(VIDEO_LABEL_XPOS), PG_Y2(VIDEO_LABEL_YPOS), - VIDEO_LABEL_XPOS, VIDEO_LABEL_YPOS, - VIDEO_LABEL_XSIZE, VIDEO_LABEL_YSIZE - }, - { - PG_X6(VIDEO_PBEND_SYMBOL_XPOS), PG_Y1(VIDEO_PBEND_SYMBOL_YPOS), - PG_X3(VIDEO_PBEND_SYMBOL_XPOS), PG_Y2(VIDEO_SYMBOL_YPOS), - VIDEO_SYMBOL_XPOS, VIDEO_SYMBOL_YPOS, - VIDEO_PBEND_SYMBOL_XSIZE, VIDEO_PBEND_SYMBOL_YSIZE - } - }, - { - { - PG_X6(VIDEO_WARP_LABEL_XPOS), PG_Y1(VIDEO_WARP_LABEL_YPOS), - PG_X3(VIDEO_LABEL_XPOS), PG_Y2(VIDEO_LABEL_YPOS), - VIDEO_LABEL_XPOS, VIDEO_LABEL_YPOS, - VIDEO_LABEL_XSIZE, VIDEO_LABEL_YSIZE - }, - { - PG_X6(VIDEO_WARP_SYMBOL_XPOS), PG_Y1(VIDEO_WARP_SYMBOL_YPOS), - PG_X3(VIDEO_WARP_SYMBOL_XPOS), PG_Y2(VIDEO_SYMBOL_YPOS), - VIDEO_SYMBOL_XPOS, VIDEO_SYMBOL_YPOS, - VIDEO_WARP_SYMBOL_XSIZE, VIDEO_WARP_SYMBOL_YSIZE - } - }, - { - { - -1, -1, - -1, -1, - -1, -1, - -1, -1 - }, - { - PG_X6(VIDEO_WARP2_SYMBOL_XPOS), PG_Y1(VIDEO_WARP2_SYMBOL_YPOS), - PG_X3(VIDEO_WARP2_SYMBOL_XPOS), PG_Y2(VIDEO_SYMBOL_YPOS), - VIDEO_SYMBOL_XPOS, VIDEO_SYMBOL_YPOS, - VIDEO_WARP2_SYMBOL_XSIZE, VIDEO_WARP2_SYMBOL_YSIZE - } - }, - { - { - -1, -1, - -1, -1, - -1, -1, - -1, -1 - }, - { - PG_X6(VIDEO_1STEP_SYMBOL_XPOS), PG_Y1(VIDEO_1STEP_SYMBOL_YPOS), - PG_X3(VIDEO_1STEP_SYMBOL_XPOS), PG_Y2(VIDEO_SYMBOL_YPOS), - VIDEO_1STEP_SYMBOL_XPOS, VIDEO_SYMBOL_YPOS, - VIDEO_1STEP_SYMBOL_XSIZE, VIDEO_1STEP_SYMBOL_YSIZE - } - }, - }; -#endif - -#if 1 static struct { int graphic; @@ -442,45 +288,6 @@ void DrawVideoDisplay(unsigned int state, unsigned int value) } } -#else - - for (k = 0; k < NUM_TAPE_FUNCTION_STATES; k++) /* on or off states */ - { - for (i = 0; i < NUM_TAPE_FUNCTIONS; i++) /* record, play, ... */ - { - for (j = 0; j < NUM_TAPE_FUNCTION_PARTS; j++) /* label or symbol */ - { - if (state & (1 << (i * 2 + k))) - { - int gd_x, gd_y; - int skip_value = - (j == 0 ? VIDEO_DISPLAY_SYMBOL_ONLY : VIDEO_DISPLAY_LABEL_ONLY); - - if (k == 1) /* on */ - { - gd_x = video_pos[i][j].gd_x1; - gd_y = video_pos[i][j].gd_y1; - } - else /* off */ - { - gd_x = video_pos[i][j].gd_x2; - gd_y = video_pos[i][j].gd_y2; - } - - if (video_pos[i][j].x != -1 && value != skip_value) - BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, - gd_x, gd_y, - video_pos[i][j].width, - video_pos[i][j].height, - VX + video_pos[i][j].x, - VY + video_pos[i][j].y); - } - } - } - } -#endif - -#if 1 if (state & VIDEO_STATE_DATE_ON) { struct TextPosInfo *pos = &tape.text.date; @@ -503,47 +310,11 @@ void DrawVideoDisplay(unsigned int state, unsigned int value) DrawText(VX + pos->x + 27, VY + pos->y, int2str(sec, 2), pos->font); } -#else - - if (state & VIDEO_STATE_DATE_ON) - { - int tag = value % 100; - int monat = (value/100) % 100; - int jahr = (value/10000); - - DrawText(VX + VIDEO_DATE_XPOS, VY + VIDEO_DATE_YPOS, - int2str(tag, 2), FONT_TAPE_RECORDER); - DrawText(VX + VIDEO_DATE_XPOS + 27, VY + VIDEO_DATE_YPOS, - monatsname[monat], FONT_TAPE_RECORDER); - DrawText(VX + VIDEO_DATE_XPOS + 64, VY + VIDEO_DATE_YPOS, - int2str(jahr, 2), FONT_TAPE_RECORDER); - } - - if (state & VIDEO_STATE_TIME_ON) - { - int min = value / 60; - int sec = value % 60; - - DrawText(VX + VIDEO_TIME_XPOS, VY + VIDEO_TIME_YPOS, - int2str(min, 2), FONT_TAPE_RECORDER); - DrawText(VX + VIDEO_TIME_XPOS + 27, VY + VIDEO_TIME_YPOS, - int2str(sec, 2), FONT_TAPE_RECORDER); - } -#endif - redraw_mask |= REDRAW_DOOR_2; } void DrawCompleteVideoDisplay() { -#if 0 - printf("::: %d, %d / %d, %d [%d] [%d, %d] [%d/%d]\n", - VX, VY, EX, EY, game_status, gfx.vx, gfx.vy, - tape.date, tape.length); -#endif - -#if 1 - struct GraphicInfo *g_tape = &graphic_info[IMG_BACKGROUND_TAPE]; /* draw tape background */ @@ -554,55 +325,8 @@ void DrawCompleteVideoDisplay() UnmapTapeButtons(); MapTapeButtons(); -#else - -#if 1 - struct GraphicInfo *g_tape = &graphic_info[IMG_BACKGROUND_TAPE]; - int tape_button_graphics[] = - { - IMG_TAPE_BUTTON_GFX_EJECT, - IMG_TAPE_BUTTON_GFX_STOP, - IMG_TAPE_BUTTON_GFX_PAUSE, - IMG_TAPE_BUTTON_GFX_RECORD, - IMG_TAPE_BUTTON_GFX_PLAY - }; - struct Rect *tape_button_positions[] = - { - &tape.button.eject, - &tape.button.stop, - &tape.button.pause, - &tape.button.record, - &tape.button.play - }; - int i; - - BlitBitmap(g_tape->bitmap, drawto, g_tape->src_x, g_tape->src_y, - gfx.vxsize, gfx.vysize, gfx.vx, gfx.vy); - - for (i = 0; i < SIZEOF_ARRAY_INT(tape_button_graphics); i++) - { - struct GraphicInfo *g = &graphic_info[tape_button_graphics[i]]; - struct Rect *pos = tape_button_positions[i]; - - BlitBitmap(g->bitmap, drawto, g->src_x, g->src_y, - g->width, g->height, gfx.vx + pos->x, gfx.vy + pos->y); - } -#else - BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, - DOOR_GFX_PAGEX3, DOOR_GFX_PAGEY2, - gfx.vxsize, gfx.vysize, gfx.vx, gfx.vy); - BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, - DOOR_GFX_PAGEX4 + VIDEO_CONTROL_XPOS, - DOOR_GFX_PAGEY2 + VIDEO_CONTROL_YPOS, - VIDEO_CONTROL_XSIZE, VIDEO_CONTROL_YSIZE, - gfx.vx + VIDEO_CONTROL_XPOS, gfx.vy + VIDEO_CONTROL_YPOS); -#endif - -#endif - DrawVideoDisplay(VIDEO_ALL_OFF, 0); -#if 1 if (tape.recording) { DrawVideoDisplay(VIDEO_STATE_REC_ON, 0); @@ -626,21 +350,9 @@ void DrawCompleteVideoDisplay() DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date); DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds); } -#else - if (tape.date && tape.length) - { - DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date); - DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds); - } -#endif -#if 1 BlitBitmap(drawto, bitmap_db_door_2, gfx.vx, gfx.vy, gfx.vxsize, gfx.vysize, 0, 0); -#else - BlitBitmap(drawto, bitmap_db_door, gfx.vx, gfx.vy, gfx.vxsize, gfx.vysize, - DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY2); -#endif } void TapeDeactivateDisplayOn() @@ -786,9 +498,7 @@ static void TapeAppendRecording() DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date); DrawVideoDisplay(VIDEO_STATE_PLAY_OFF | VIDEO_STATE_REC_ON, 0); -#if 1 UpdateAndDisplayGameControlValues(); -#endif } void TapeHaltRecording() @@ -1177,10 +887,6 @@ void TapeQuickLoad() if (CheckEngineSnapshot()) { -#if 0 - printf("::: MARK 1\n"); -#endif - TapeStartGamePlaying(); LoadEngineSnapshot(); @@ -1197,10 +903,6 @@ void TapeQuickLoad() return; } -#if 0 - printf("::: MARK 2\n"); -#endif - TapeStop(); TapeErase(); @@ -1248,9 +950,6 @@ void AutoPlayTape() static int num_levels_solved = 0; static int num_tape_missing = 0; static boolean level_failed[MAX_TAPES_PER_SET]; -#if 0 - static boolean tape_missing[MAX_TAPES_PER_SET]; -#endif int i; if (autoplay_initialized) @@ -1297,12 +996,7 @@ void AutoPlayTape() printf("\n"); for (i = 0; i < MAX_TAPES_PER_SET; i++) - { level_failed[i] = FALSE; -#if 0 - tape_missing[i] = FALSE; -#endif - } autoplay_initialized = TRUE; } @@ -1336,12 +1030,9 @@ void AutoPlayTape() if (tape.no_valid_file) { num_tape_missing++; -#if 0 - if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET) - tape_missing[level_nr] = TRUE; -#endif printf("(no tape)\n"); + continue; } @@ -1372,16 +1063,6 @@ void AutoPlayTape() printf(" %03d", i); } -#if 0 - if (num_tape_missing > 0) - { - printf(", NO TAPE:"); - for (i = 0; i < MAX_TAPES_PER_SET; i++) - if (tape_missing[i]) - printf(" %03d", i); - } -#endif - printf("\n"); printf_line("=", 79); diff --git a/src/tools.c b/src/tools.c index 0a90d675..7de35d14 100644 --- a/src/tools.c +++ b/src/tools.c @@ -235,8 +235,6 @@ void SetDrawtoField(int mode) { if (mode == DRAW_BUFFERED && setup.soft_scrolling) { -#if NEW_TILESIZE -#if NEW_SCROLL FX = 2 * TILEX_VAR; FY = 2 * TILEY_VAR; BX1 = -2; @@ -245,37 +243,6 @@ void SetDrawtoField(int mode) BY2 = SCR_FIELDY + 1; redraw_x1 = 2; redraw_y1 = 2; -#else - FX = TILEX_VAR; - FY = TILEY_VAR; - BX1 = -1; - BY1 = -1; - BX2 = SCR_FIELDX; - BY2 = SCR_FIELDY; - redraw_x1 = 1; - redraw_y1 = 1; -#endif -#else -#if NEW_SCROLL - FX = 2 * TILEX; - FY = 2 * TILEY; - BX1 = -2; - BY1 = -2; - BX2 = SCR_FIELDX + 1; - BY2 = SCR_FIELDY + 1; - redraw_x1 = 2; - redraw_y1 = 2; -#else - FX = TILEX; - FY = TILEY; - BX1 = -1; - BY1 = -1; - BX2 = SCR_FIELDX; - BY2 = SCR_FIELDY; - redraw_x1 = 1; - redraw_y1 = 1; -#endif -#endif drawto_field = fieldbuffer; } @@ -294,46 +261,13 @@ void SetDrawtoField(int mode) } } -#if 1 - static void RedrawPlayfield_RND() { if (game.envelope_active) return; -#if 1 DrawLevel(REDRAW_ALL); -#else - int x, y; - - SetMainBackgroundImage(IMG_BACKGROUND_PLAYING); - // SetDrawBackgroundMask(REDRAW_FIELD); // !!! CHECK THIS !!! - SetDrawBackgroundMask(REDRAW_ALL); // !!! CHECK THIS !!! - - for (x = BX1; x <= BX2; x++) - for (y = BY1; y <= BY2; y++) - DrawScreenField(x, y); - - redraw_mask |= REDRAW_FIELD; -#endif DrawAllPlayers(); - -#if 0 -#if NEW_TILESIZE - BlitScreenToBitmap(backbuffer); -#else - /* blit playfield from scroll buffer to normal back buffer */ - 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); - } -#endif -#endif } void RedrawPlayfield() @@ -354,76 +288,6 @@ void RedrawPlayfield() gfx.sx, gfx.sy); } -#else - -void RedrawPlayfield(boolean force_redraw, int x, int y, int width, int height) -{ - if (game_status == GAME_MODE_PLAYING && - level.game_engine_type == GAME_ENGINE_TYPE_EM) - { - /* currently there is no partial redraw -- always redraw whole playfield */ - RedrawPlayfield_EM(TRUE); - - /* blit playfield from scroll buffer to normal back buffer for fading in */ - BlitScreenToBitmap_EM(backbuffer); - } - else if (game_status == GAME_MODE_PLAYING && - level.game_engine_type == GAME_ENGINE_TYPE_SP) - { - /* currently there is no partial redraw -- always redraw whole playfield */ - RedrawPlayfield_SP(TRUE); - - /* blit playfield from scroll buffer to normal back buffer for fading in */ - BlitScreenToBitmap_SP(backbuffer); - } - else if (game_status == GAME_MODE_PLAYING && - !game.envelope_active) - { - if (force_redraw) - { - x = gfx.sx - TILEX; - y = gfx.sy - TILEY; - width = gfx.sxsize + 2 * TILEX; - height = gfx.sysize + 2 * TILEY; - } - - if (force_redraw) - { - int xx, yy; - int x1 = (x - SX) / TILEX, y1 = (y - SY) / TILEY; - int x2 = (x - SX + width) / TILEX, y2 = (y - SY + height) / TILEY; - - 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.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); - } - } - - if (force_redraw) - { - x = gfx.sx; - y = gfx.sy; - width = gfx.sxsize; - height = gfx.sysize; - } - - BlitBitmap(drawto, window, x, y, width, height, x, y); -} - -#endif - void DrawMaskedBorder_Rect(int x, int y, int width, int height) { Bitmap *bitmap = graphic_info[IMG_GLOBAL_BORDER].bitmap; @@ -502,20 +366,12 @@ static void BlitScreenToBitmap_RND(Bitmap *target_bitmap) int full_lev_fieldx = lev_fieldx + (BorderElement != EL_EMPTY ? 2 : 0); int full_lev_fieldy = lev_fieldy + (BorderElement != EL_EMPTY ? 2 : 0); -#if NEW_TILESIZE int dx = (ScreenMovDir & (MV_LEFT | MV_RIGHT) ? ScreenGfxPos : 0); int dy = (ScreenMovDir & (MV_UP | MV_DOWN) ? ScreenGfxPos : 0); int dx_var = dx * TILESIZE_VAR / TILESIZE; int dy_var = dy * TILESIZE_VAR / TILESIZE; int ffx, ffy; - // fx += dx * TILESIZE_VAR / TILESIZE; - // fy += dy * TILESIZE_VAR / TILESIZE; -#else - fx += (ScreenMovDir & (MV_LEFT | MV_RIGHT) ? ScreenGfxPos : 0); - fy += (ScreenMovDir & (MV_UP | MV_DOWN) ? ScreenGfxPos : 0); -#endif - ffx = (scroll_x - SBX_Left) * TILEX_VAR + dx_var; ffy = (scroll_y - SBY_Upper) * TILEY_VAR + dy_var; @@ -543,25 +399,12 @@ static void BlitScreenToBitmap_RND(Bitmap *target_bitmap) fy += dy_var; } -#if 0 - printf("::: (%d, %d) [(%d / %d, %d / %d)] => %d, %d\n", - scroll_x, scroll_y, - SBX_Left, SBX_Right, - SBY_Upper, SBY_Lower, - fx, fy); -#endif - -#if 1 if (full_lev_fieldx <= SCR_FIELDX) { - // printf(":1: PLAYFIELD FITS TO SCREEN [%d, %d, %d]\n", fx, ffx, dx_var); - if (EVEN(SCR_FIELDX)) fx = 2 * TILEX_VAR - (ODD(lev_fieldx) ? TILEX_VAR / 2 : 0); else fx = 2 * TILEX_VAR - (EVEN(lev_fieldx) ? TILEX_VAR / 2 : 0); - - // printf(":2: PLAYFIELD FITS TO SCREEN [%d, %d, %d]\n", fx, ffx, dx_var); } if (full_lev_fieldy <= SCR_FIELDY) @@ -571,7 +414,6 @@ static void BlitScreenToBitmap_RND(Bitmap *target_bitmap) else fy = 2 * TILEY_VAR - (EVEN(lev_fieldy) ? TILEY_VAR / 2 : 0); } -#endif if (border.draw_masked[GAME_MODE_PLAYING]) { @@ -607,16 +449,6 @@ void BackToFront() int x, y; DrawBuffer *buffer = (drawto_field == window ? backbuffer : drawto_field); -#if 0 - printf("::: TILES TO REFRESH: %d\n", redraw_tiles); - for (x = 0; x < SCR_FIELDX; x++) - for (y = 0 ; y < SCR_FIELDY; y++) - if (redraw[redraw_x1 + x][redraw_y1 + y]) - printf("::: - %d, %d [%s]\n", - LEVELX(x), LEVELY(y), - EL_NAME(Feld[LEVELX(x)][LEVELY(y)])); -#endif - if (redraw_mask & REDRAW_TILES && redraw_tiles > REDRAWTILES_THRESHOLD) redraw_mask |= REDRAW_FIELD; @@ -711,39 +543,13 @@ void BackToFront() if (redraw_mask & REDRAW_ALL) { -#if 0 - if (game_status != GAME_MODE_PLAYING || - redraw_mask & REDRAW_FROM_BACKBUFFER) - { -#if 0 - printf("::: REDRAW_ALL [%d]\n", FrameCounter); -#endif - - BlitBitmap(backbuffer, window, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); - - redraw_mask = REDRAW_NONE; - } - else - { - redraw_mask &= ~REDRAW_ALL; - } -#else -#if 0 - printf("::: REDRAW_ALL [%d]\n", FrameCounter); -#endif - BlitBitmap(backbuffer, window, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); redraw_mask = REDRAW_NONE; -#endif } if (redraw_mask & REDRAW_FIELD) { -#if 0 - printf("::: REDRAW_FIELD [%d]\n", FrameCounter); -#endif - if (game_status != GAME_MODE_PLAYING || redraw_mask & REDRAW_FROM_BACKBUFFER) { @@ -752,88 +558,7 @@ void BackToFront() } else { -#if 1 BlitScreenToBitmap_RND(window); -#else - int fx = FX, fy = FY; - -#if NEW_TILESIZE - int dx = (ScreenMovDir & (MV_LEFT | MV_RIGHT) ? ScreenGfxPos : 0); - int dy = (ScreenMovDir & (MV_UP | MV_DOWN) ? ScreenGfxPos : 0); - int dx_var = dx * TILESIZE_VAR / TILESIZE; - int dy_var = dy * TILESIZE_VAR / TILESIZE; - int ffx, ffy; - - // fx += dx * TILESIZE_VAR / TILESIZE; - // fy += dy * TILESIZE_VAR / TILESIZE; -#else - fx += (ScreenMovDir & (MV_LEFT | MV_RIGHT) ? ScreenGfxPos : 0); - fy += (ScreenMovDir & (MV_UP | MV_DOWN) ? ScreenGfxPos : 0); -#endif - - /* !!! THIS WORKS !!! */ - - printf("::: %d, %d\n", scroll_x, scroll_y); - - ffx = (scroll_x - SBX_Left) * TILEX_VAR + dx_var; - ffy = (scroll_y - SBY_Upper) * TILEY_VAR + dy_var; - - if (EVEN(SCR_FIELDX)) - { - if (ffx < SBX_Right * TILEX_VAR + TILEX_VAR / 2 + TILEX_VAR) - fx += dx_var - MIN(ffx, TILEX_VAR / 2) + TILEX_VAR; - else - fx += (dx > 0 ? TILEX_VAR : 0); - } - else - { - fx += dx; - } - - if (EVEN(SCR_FIELDY)) - { - if (ffy < SBY_Lower * TILEY_VAR + TILEY_VAR / 2 + TILEY_VAR) - fy += dy_var - MIN(ffy, TILEY_VAR / 2) + TILEY_VAR; - else - fy += (dy > 0 ? TILEY_VAR : 0); - } - else - { - fy += dy; - } - - if (border.draw_masked[GAME_MODE_PLAYING]) - { - if (buffer != backbuffer) - { - /* copy playfield buffer to backbuffer to add masked border */ - BlitBitmap(buffer, backbuffer, fx, fy, SXSIZE, SYSIZE, SX, SY); - DrawMaskedBorder(REDRAW_FIELD); - } - - BlitBitmap(backbuffer, window, - REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, - REAL_SX, REAL_SY); - } - else - { - BlitBitmap(buffer, window, fx, fy, SXSIZE, SYSIZE, SX, SY); - } -#endif - -#if 0 -#ifdef DEBUG - printf("redrawing all (ScreenGfxPos == %d) because %s\n", - ScreenGfxPos, - (setup.soft_scrolling ? - "setup.soft_scrolling" : - ABS(ScreenGfxPos) + ScrollStepSize == TILEX ? - "ABS(ScreenGfxPos) + ScrollStepSize == TILEX" : - ABS(ScreenGfxPos) == ScrollStepSize ? - "ABS(ScreenGfxPos) == ScrollStepSize" : - "redraw_tiles > REDRAWTILES_THRESHOLD")); -#endif -#endif } redraw_mask &= ~REDRAW_MAIN; @@ -863,97 +588,66 @@ void BackToFront() if (redraw_mask & REDRAW_TILES) { -#if 0 - printf("::: REDRAW_TILES\n"); -#endif - -#if NEW_TILESIZE - -#if 1 - InitGfxClipRegion(TRUE, SX, SY, SXSIZE, SYSIZE); + int sx = SX; + int sy = SY; - { - int sx = SX; // - (EVEN(SCR_FIELDX) ? TILEX_VAR / 2 : 0); - int sy = SY; // + (EVEN(SCR_FIELDY) ? TILEY_VAR / 2 : 0); + int dx = 0, dy = 0; + int dx_var = dx * TILESIZE_VAR / TILESIZE; + int dy_var = dy * TILESIZE_VAR / TILESIZE; + int ffx, ffy; + int fx = FX, fy = FY; - int dx = 0, dy = 0; - int dx_var = dx * TILESIZE_VAR / TILESIZE; - int dy_var = dy * TILESIZE_VAR / TILESIZE; - int ffx, ffy; - int fx = FX, fy = FY; + int scr_fieldx = SCR_FIELDX + (EVEN(SCR_FIELDX) ? 2 : 0); + int scr_fieldy = SCR_FIELDY + (EVEN(SCR_FIELDY) ? 2 : 0); - int scr_fieldx = SCR_FIELDX + (EVEN(SCR_FIELDX) ? 2 : 0); - int scr_fieldy = SCR_FIELDY + (EVEN(SCR_FIELDY) ? 2 : 0); + InitGfxClipRegion(TRUE, SX, SY, SXSIZE, SYSIZE); - ffx = (scroll_x - SBX_Left) * TILEX_VAR + dx_var; - ffy = (scroll_y - SBY_Upper) * TILEY_VAR + dy_var; + ffx = (scroll_x - SBX_Left) * TILEX_VAR + dx_var; + ffy = (scroll_y - SBY_Upper) * TILEY_VAR + dy_var; - if (EVEN(SCR_FIELDX)) + if (EVEN(SCR_FIELDX)) + { + if (ffx < SBX_Right * TILEX_VAR + TILEX_VAR / 2 + TILEX_VAR) { - if (ffx < SBX_Right * TILEX_VAR + TILEX_VAR / 2 + TILEX_VAR) - { - fx += dx_var - MIN(ffx, TILEX_VAR / 2) + TILEX_VAR; + fx += dx_var - MIN(ffx, TILEX_VAR / 2) + TILEX_VAR; - if (fx % TILEX_VAR) - sx -= TILEX_VAR / 2; - else - sx -= TILEX_VAR; - } + if (fx % TILEX_VAR) + sx -= TILEX_VAR / 2; else - { - fx += (dx_var > 0 ? TILEX_VAR : 0); - } + sx -= TILEX_VAR; + } + else + { + fx += (dx_var > 0 ? TILEX_VAR : 0); } + } - if (EVEN(SCR_FIELDY)) + if (EVEN(SCR_FIELDY)) + { + if (ffy < SBY_Lower * TILEY_VAR + TILEY_VAR / 2 + TILEY_VAR) { - if (ffy < SBY_Lower * TILEY_VAR + TILEY_VAR / 2 + TILEY_VAR) - { - fy += dy_var - MIN(ffy, TILEY_VAR / 2) + TILEY_VAR; + fy += dy_var - MIN(ffy, TILEY_VAR / 2) + TILEY_VAR; - if (fy % TILEY_VAR) - sy -= TILEY_VAR / 2; - else - sy -= TILEY_VAR; - } + if (fy % TILEY_VAR) + sy -= TILEY_VAR / 2; else - { - fy += (dy_var > 0 ? TILEY_VAR : 0); - } + sy -= TILEY_VAR; + } + else + { + fy += (dy_var > 0 ? TILEY_VAR : 0); } - -#if 0 - printf("::: %d, %d, %d, %d\n", sx, sy, SCR_FIELDX, SCR_FIELDY); -#endif - - for (x = 0; x < scr_fieldx; x++) - for (y = 0 ; y < scr_fieldy; y++) - if (redraw[redraw_x1 + x][redraw_y1 + y]) - BlitBitmap(buffer, window, - FX + x * TILEX_VAR, FY + y * TILEY_VAR, - TILEX_VAR, TILEY_VAR, - sx + x * TILEX_VAR, sy + y * TILEY_VAR); } - InitGfxClipRegion(FALSE, -1, -1, -1, -1); -#else - for (x = 0; x < SCR_FIELDX; x++) - for (y = 0 ; y < SCR_FIELDY; y++) + for (x = 0; x < scr_fieldx; x++) + for (y = 0 ; y < scr_fieldy; y++) if (redraw[redraw_x1 + x][redraw_y1 + y]) BlitBitmap(buffer, window, FX + x * TILEX_VAR, FY + y * TILEY_VAR, TILEX_VAR, TILEY_VAR, - SX + x * TILEX_VAR, SY + y * TILEY_VAR); -#endif + sx + x * TILEX_VAR, sy + y * TILEY_VAR); -#else - for (x = 0; x < SCR_FIELDX; x++) - for (y = 0 ; y < SCR_FIELDY; y++) - if (redraw[redraw_x1 + x][redraw_y1 + y]) - BlitBitmap(buffer, window, - FX + x * TILEX, FY + y * TILEY, TILEX, TILEY, - SX + x * TILEX, SY + y * TILEY); -#endif + InitGfxClipRegion(FALSE, -1, -1, -1, -1); } if (redraw_mask & REDRAW_FPS) /* display frames per second */ @@ -966,11 +660,8 @@ void BackToFront() info1[0] = '\0'; sprintf(text, "%04.1f fps%s", global.frames_per_second, info1); -#if 1 + DrawTextExt(window, SX + SXSIZE + SX, 0, text, FONT_TEXT_2, BLIT_OPAQUE); -#else - DrawTextExt(window, SX, SY, text, FONT_TEXT_2, BLIT_OPAQUE); -#endif } FlushDisplay(); @@ -999,10 +690,6 @@ static void FadeExt(int fade_mask, int fade_mode, int fade_type) { if (fade_type_skip != FADE_TYPE_NONE) { -#if 0 - printf("::: skipping %d ... [%d] (X)\n", fade_mode, fade_type_skip); -#endif - /* skip all fade operations until specified fade operation */ if (fade_type & fade_type_skip) fade_type_skip = FADE_TYPE_NONE; @@ -1022,72 +709,28 @@ static void FadeExt(int fade_mask, int fade_mode, int fade_type) if (fade_type == FADE_TYPE_SKIP) { -#if 0 - printf("::: will skip %d ... [%d]\n", fade_mode, fade_type_skip); -#endif - fade_type_skip = fade_mode; return; } -#if 0 - printf("::: !!! FADING %d ... [%d] [%d]\n", fade_mode, fade_type, - fade_type_skip); -#endif - -#if 1 fade_delay = fading.fade_delay; post_delay = (fade_mode == FADE_MODE_FADE_OUT ? fading.post_delay : 0); -#endif if (fade_type_skip != FADE_TYPE_NONE) { -#if 0 - printf("::: skipping %d ... [%d]\n", fade_mode, fade_type_skip); -#endif - /* skip all fade operations until specified fade operation */ if (fade_type & fade_type_skip) fade_type_skip = FADE_TYPE_NONE; -#if 1 fade_delay = 0; -#else - return; -#endif } -#if 1 if (global.autoplay_leveldir) { - // fading.fade_mode = FADE_MODE_NONE; - - return; - } -#endif - -#if 0 - if (fading.fade_mode == FADE_MODE_NONE) - { - BackToFront(); - return; } -#endif - - /* !!! what about fade_mask == REDRAW_FIELD | REDRAW_ALL ??? !!! */ - -#if 0 - printf("::: NOW FADING %d ... [%d]\n", fade_mode, fade_type); -#endif - -#if 0 - if (fade_mask == REDRAW_NONE) - fade_mask = REDRAW_FIELD; -#endif - // if (fade_mask & REDRAW_FIELD) if (fade_mask == REDRAW_FIELD) { x = REAL_SX; @@ -1095,11 +738,6 @@ static void FadeExt(int fade_mask, int fade_mode, int fade_type) width = FULL_SXSIZE; height = FULL_SYSIZE; -#if 0 - fade_delay = fading.fade_delay; - post_delay = (fade_mode == FADE_MODE_FADE_OUT ? fading.post_delay : 0); -#endif - if (border.draw_masked_when_fading) draw_border_function = DrawMaskedBorder_FIELD; /* update when fading */ else @@ -1111,53 +749,18 @@ static void FadeExt(int fade_mask, int fade_mode, int fade_type) y = 0; width = WIN_XSIZE; height = WIN_YSIZE; - -#if 0 - fade_delay = fading.fade_delay; - post_delay = (fade_mode == FADE_MODE_FADE_OUT ? fading.post_delay : 0); -#endif } -#if 1 if (!setup.fade_screens || fade_delay == 0 || fading.fade_mode == FADE_MODE_NONE) -#else - if (!setup.fade_screens || fade_delay == 0) -#endif { if (fade_mode == FADE_MODE_FADE_OUT) return; -#if 0 - if (fade_mode == FADE_MODE_FADE_OUT && - fading.fade_mode != FADE_MODE_NONE) - ClearRectangle(backbuffer, x, y, width, height); -#endif - -#if 1 - -#if 1 BlitBitmap(backbuffer, window, x, y, width, height, x, y); redraw_mask &= ~fade_mask; -#else - /* always redraw area that was explicitly marked to fade */ - redraw_mask |= fade_mask; - - BackToFront(); -#endif - -#else - -#if 1 - BlitBitmap(backbuffer, window, x, y, width, height, x, y); - redraw_mask = REDRAW_NONE; - // (^^^ WRONG; should be "redraw_mask &= ~fade_mask" if done this way) -#else - BackToFront(); -#endif -#endif return; } @@ -1200,10 +803,6 @@ void FadeSetEnterMenu() { fading = menu.enter_menu; -#if 0 - printf("::: storing enter_menu\n"); -#endif - FadeSetLeaveNext(fading, TRUE); /* (keep same fade mode) */ } @@ -1211,10 +810,6 @@ void FadeSetLeaveMenu() { fading = menu.leave_menu; -#if 0 - printf("::: storing leave_menu\n"); -#endif - FadeSetLeaveNext(fading, TRUE); /* (keep same fade mode) */ } @@ -1222,10 +817,6 @@ void FadeSetEnterScreen() { fading = menu.enter_screen[game_status]; -#if 0 - printf("::: storing leave_screen[%d]\n", game_status); -#endif - FadeSetLeaveNext(menu.leave_screen[game_status], TRUE); /* store */ } @@ -1233,20 +824,12 @@ void FadeSetNextScreen() { fading = menu.next_screen; -#if 0 - printf("::: storing next_screen\n"); -#endif - // (do not overwrite fade mode set by FadeSetEnterScreen) // FadeSetLeaveNext(fading, TRUE); /* (keep same fade mode) */ } void FadeSetLeaveScreen() { -#if 0 - printf("::: recalling last stored value\n"); -#endif - FadeSetLeaveNext(menu.leave_screen[game_status], FALSE); /* recall */ } @@ -1321,39 +904,19 @@ void SetDoorBackgroundImage(int graphic) void SetPanelBackground() { -#if 1 struct GraphicInfo *gfx = &graphic_info[IMG_BACKGROUND_PANEL]; -#if 1 BlitBitmapTiled(gfx->bitmap, bitmap_db_panel, gfx->src_x, gfx->src_y, gfx->width, gfx->height, 0, 0, DXSIZE, DYSIZE); -#else - /* (ClearRectangle() only needed if panel bitmap is smaller than panel) */ - ClearRectangle(bitmap_db_panel, DX, DY, DXSIZE, DYSIZE); - BlitBitmap(gfx->bitmap, bitmap_db_panel, gfx->src_x, gfx->src_y, - MIN(gfx->width, DXSIZE), MIN(gfx->height, DYSIZE), 0, 0); -#endif -#else - BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, bitmap_db_panel, - DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, 0, 0); -#endif SetDoorBackgroundBitmap(bitmap_db_panel); } void DrawBackground(int x, int y, int width, int height) { - /* !!! "drawto" might still point to playfield buffer here (see below) !!! */ - /* (when entering hall of fame after playing) */ -#if 0 - ClearRectangleOnBackground(drawto, x, y, width, height); -#else + /* "drawto" might still point to playfield buffer here (hall of fame) */ ClearRectangleOnBackground(backbuffer, x, y, width, height); -#endif - -#if 1 -#if 1 if (IN_GFX_FIELD_FULL(x, y)) redraw_mask |= REDRAW_FIELD; else if (IN_GFX_DOOR_1(x, y)) @@ -1362,20 +925,6 @@ void DrawBackground(int x, int y, int width, int height) redraw_mask |= REDRAW_DOOR_2; else if (IN_GFX_DOOR_3(x, y)) redraw_mask |= REDRAW_DOOR_3; -#else - /* (this only works for the current arrangement of playfield and panels) */ - if (x < gfx.dx) - redraw_mask |= REDRAW_FIELD; - else if (y < gfx.vy) - redraw_mask |= REDRAW_DOOR_1; - else - redraw_mask |= REDRAW_DOOR_2; -#endif - -#else - /* (this is just wrong (when drawing to one of the two door panel areas)) */ - redraw_mask |= REDRAW_FIELD; -#endif } void DrawBackgroundForFont(int x, int y, int width, int height, int font_nr) @@ -1526,9 +1075,6 @@ void getSizedGraphicSourceExt(int graphic, int frame, int tilesize_raw, int height_div = offset_calc[offset_calc_pos].height_div; int startx = bitmap_width * width_mult / width_div; int starty = bitmap_height * height_mult / height_div; - -#if NEW_GAME_TILESIZE - int src_x = (g->src_x + (get_backside ? g->offset2_x : 0)) * tilesize_raw / TILESIZE; int src_y = (g->src_y + (get_backside ? g->offset2_y : 0)) * @@ -1538,25 +1084,6 @@ void getSizedGraphicSourceExt(int graphic, int frame, int tilesize_raw, int offset_x = g->offset_x * tilesize_raw / TILESIZE; int offset_y = g->offset_y * tilesize_raw / TILESIZE; -#else - -#if NEW_TILESIZE - int src_x = (g->src_x + (get_backside ? g->offset2_x : 0)) * - tilesize / TILESIZE; - int src_y = (g->src_y + (get_backside ? g->offset2_y : 0)) * - tilesize / TILESIZE; -#else - int src_x = g->src_x * tilesize / TILESIZE; - int src_y = g->src_y * tilesize / TILESIZE; -#endif - int width = g->width * tilesize / TILESIZE; - int height = g->height * tilesize / TILESIZE; - int offset_x = g->offset_x * tilesize / TILESIZE; - int offset_y = g->offset_y * tilesize / TILESIZE; - -#endif - -#if NEW_GAME_TILESIZE if (game.tile_size != TILESIZE) { int bitmap_width_std = @@ -1580,7 +1107,6 @@ void getSizedGraphicSourceExt(int graphic, int frame, int tilesize_raw, starty = bitmap_height * height_mult / height_div; } } -#endif if (g->offset_y == 0) /* frames are ordered horizontally */ { @@ -1630,17 +1156,7 @@ void getFixedGraphicSource(int graphic, int frame, void getMiniGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y) { -#if 1 getSizedGraphicSource(graphic, 0, MINI_TILESIZE, bitmap, x, y); -#else - struct GraphicInfo *g = &graphic_info[graphic]; - int mini_startx = 0; - int mini_starty = g->bitmap->height * 2 / 3; - - *bitmap = g->bitmap; - *x = mini_startx + g->src_x / 2; - *y = mini_starty + g->src_y / 2; -#endif } inline void getGraphicSourceExt(int graphic, int frame, Bitmap **bitmap, @@ -1650,11 +1166,9 @@ inline void getGraphicSourceExt(int graphic, int frame, Bitmap **bitmap, int src_x = g->src_x + (get_backside ? g->offset2_x : 0); int src_y = g->src_y + (get_backside ? g->offset2_y : 0); -#if NEW_TILESIZE if (TILESIZE_VAR != TILESIZE) return getSizedGraphicSourceExt(graphic, frame, TILESIZE_VAR, bitmap, x, y, get_backside); -#endif *bitmap = g->bitmap; @@ -1697,12 +1211,9 @@ void DrawGraphic(int x, int y, int graphic, int frame) } #endif -#if NEW_TILESIZE DrawGraphicExt(drawto_field, FX + x * TILEX_VAR, FY + y * TILEY_VAR, graphic, frame); -#else - DrawGraphicExt(drawto_field, FX + x * TILEX, FY + y * TILEY, graphic, frame); -#endif + MarkTileDirty(x, y); } @@ -1729,11 +1240,8 @@ void DrawGraphicExt(DrawBuffer *dst_bitmap, int x, int y, int graphic, int src_x, src_y; getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y); -#if NEW_TILESIZE + BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, TILEX_VAR, TILEY_VAR, x, y); -#else - BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, TILEX, TILEY, x, y); -#endif } void DrawFixedGraphicExt(DrawBuffer *dst_bitmap, int x, int y, int graphic, @@ -1757,13 +1265,9 @@ void DrawGraphicThruMask(int x, int y, int graphic, int frame) } #endif -#if NEW_TILESIZE DrawGraphicThruMaskExt(drawto_field, FX + x * TILEX_VAR, FY + y * TILEY_VAR, graphic, frame); -#else - DrawGraphicThruMaskExt(drawto_field, FX + x * TILEX, FY + y * TILEY, graphic, - frame); -#endif + MarkTileDirty(x, y); } @@ -1793,12 +1297,9 @@ void DrawGraphicThruMaskExt(DrawBuffer *d, int dst_x, int dst_y, int graphic, SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc, dst_x - src_x, dst_y - src_y); -#if NEW_TILESIZE + BlitBitmapMasked(src_bitmap, d, src_x, src_y, TILEX_VAR, TILEY_VAR, dst_x, dst_y); -#else - BlitBitmapMasked(src_bitmap, d, src_x, src_y, TILEX, TILEY, dst_x, dst_y); -#endif } void DrawFixedGraphicThruMaskExt(DrawBuffer *d, int dst_x, int dst_y, @@ -1929,14 +1430,12 @@ inline static void DrawGraphicShiftedNormal(int x, int y, int dx, int dy, } #endif -#if NEW_TILESIZE width = width * TILESIZE_VAR / TILESIZE; height = height * TILESIZE_VAR / TILESIZE; cx = cx * TILESIZE_VAR / TILESIZE; cy = cy * TILESIZE_VAR / TILESIZE; dx = dx * TILESIZE_VAR / TILESIZE; dy = dy * TILESIZE_VAR / TILESIZE; -#endif if (width > 0 && height > 0) { @@ -1945,13 +1444,8 @@ inline static void DrawGraphicShiftedNormal(int x, int y, int dx, int dy, src_x += cx; src_y += cy; -#if NEW_TILESIZE dst_x = FX + x * TILEX_VAR + dx; dst_y = FY + y * TILEY_VAR + dy; -#else - dst_x = FX + x * TILEX + dx; - dst_y = FY + y * TILEY + dy; -#endif if (mask_mode == USE_MASKING) { @@ -1975,64 +1469,34 @@ inline static void DrawGraphicShiftedDouble(int x, int y, int dx, int dy, Bitmap *src_bitmap; int src_x, src_y; int dst_x, dst_y; -#if NEW_TILESIZE int width = TILEX_VAR, height = TILEY_VAR; -#else - int width = TILEX, height = TILEY; -#endif int x1 = x; int y1 = y; int x2 = x + SIGN(dx); int y2 = y + SIGN(dy); -#if 0 - /* !!! DOES NOT WORK FOR SLOW MOVEMENT !!! */ - int sync_frame = GfxFrame[LEVELX(x)][LEVELY(y)]; -#else + /* movement with two-tile animations must be sync'ed with movement position, not with current GfxFrame (which can be higher when using slow movement) */ int anim_pos = (dx ? ABS(dx) : ABS(dy)); int anim_frames = graphic_info[graphic].anim_frames; -#if 1 + /* (we also need anim_delay here for movement animations with less frames) */ int anim_delay = graphic_info[graphic].anim_delay; int sync_frame = anim_pos * anim_frames * anim_delay / TILESIZE; -#else - int sync_frame = anim_pos * anim_frames / TILESIZE; -#endif -#endif + boolean draw_start_tile = (cut_mode != CUT_ABOVE); /* only for falling! */ boolean draw_end_tile = (cut_mode != CUT_BELOW); /* only for falling! */ /* re-calculate animation frame for two-tile movement animation */ frame = getGraphicAnimationFrame(graphic, sync_frame); -#if 0 -#if 0 - printf("::: %d, %d, %d => %d [%d]\n", - anim_pos, anim_frames, anim_delay, sync_frame, graphic); -#else - printf("::: %d, %d => %d\n", - anim_pos, anim_frames, sync_frame); -#endif -#endif - -#if 0 - printf("::: %d [%d, %d] [%d] [%d]\n", frame, sync_frame, dy, - GfxFrame[LEVELX(x)][LEVELY(y)], mask_mode); -#endif - /* check if movement start graphic inside screen area and should be drawn */ if (draw_start_tile && IN_SCR_FIELD(x1, y1)) { getGraphicSourceExt(graphic, frame, &src_bitmap, &src_x, &src_y, TRUE); -#if NEW_TILESIZE dst_x = FX + x1 * TILEX_VAR; dst_y = FY + y1 * TILEY_VAR; -#else - dst_x = FX + x1 * TILEX; - dst_y = FY + y1 * TILEY; -#endif if (mask_mode == USE_MASKING) { @@ -2053,13 +1517,8 @@ inline static void DrawGraphicShiftedDouble(int x, int y, int dx, int dy, { getGraphicSourceExt(graphic, frame, &src_bitmap, &src_x, &src_y, FALSE); -#if NEW_TILESIZE dst_x = FX + x2 * TILEX_VAR; dst_y = FY + y2 * TILEY_VAR; -#else - dst_x = FX + x2 * TILEX; - dst_y = FY + y2 * TILEY; -#endif if (mask_mode == USE_MASKING) { @@ -2229,7 +1688,6 @@ static void DrawLevelFieldCrumbledInnerCorners(int x, int y, int dx, int dy, getGraphicSource(graphic, 1, &src_bitmap, &src_x, &src_y); -#if NEW_TILESIZE width = crumbled_border_size * TILESIZE_VAR / TILESIZE; height = crumbled_border_size * TILESIZE_VAR / TILESIZE; cx = (dx > 0 ? TILESIZE_VAR - width : 0); @@ -2237,15 +1695,6 @@ static void DrawLevelFieldCrumbledInnerCorners(int x, int y, int dx, int dy, BlitBitmap(src_bitmap, drawto_field, src_x + cx, src_y + cy, width, height, FX + sx * TILEX_VAR + cx, FY + sy * TILEY_VAR + cy); -#else - width = crumbled_border_size; - height = crumbled_border_size; - cx = (dx > 0 ? TILEX - crumbled_border_size : 0); - cy = (dy > 0 ? TILEY - crumbled_border_size : 0); - - BlitBitmap(src_bitmap, drawto_field, src_x + cx, src_y + cy, - width, height, FX + sx * TILEX + cx, FY + sy * TILEY + cy); -#endif } static void DrawLevelFieldCrumbledBorders(int x, int y, int graphic, int frame, @@ -2264,40 +1713,14 @@ static void DrawLevelFieldCrumbledBorders(int x, int y, int graphic, int frame, /* draw simple, sloppy, non-corner-accurate crumbled border */ -#if 1 width = (dir == 1 || dir == 2 ? crumbled_border_size_var : TILESIZE_VAR); height = (dir == 0 || dir == 3 ? crumbled_border_size_var : TILESIZE_VAR); cx = (dir == 2 ? crumbled_border_pos_var : 0); cy = (dir == 3 ? crumbled_border_pos_var : 0); -#else - if (dir == 1 || dir == 2) /* left or right crumbled border */ - { - width = crumbled_border_size; - height = TILEY; - cx = (dir == 2 ? TILEX - crumbled_border_size : 0); - cy = 0; - } - else /* top or bottom crumbled border */ - { - width = TILEX; - height = crumbled_border_size; - cx = 0; - cy = (dir == 3 ? TILEY - crumbled_border_size : 0); - } -#endif -#if NEW_TILESIZE - BlitBitmap(src_bitmap, drawto_field, - src_x + cx, - src_y + cy, - width, - height, + BlitBitmap(src_bitmap, drawto_field, src_x + cx, src_y + cy, width, height, FX + sx * TILEX_VAR + cx, FY + sy * TILEY_VAR + cy); -#else - BlitBitmap(src_bitmap, drawto_field, src_x + cx, src_y + cy, - width, height, FX + sx * TILEX + cx, FY + sy * TILEY + cy); -#endif /* (remaining middle border part must be at least as big as corner part) */ if (!(graphic_info[graphic].style & STYLE_ACCURATE_BORDERS) || @@ -2306,7 +1729,6 @@ static void DrawLevelFieldCrumbledBorders(int x, int y, int graphic, int frame, /* correct corners of crumbled border, if needed */ -#if 1 for (i = -1; i <= 1; i += 2) { int xx = x + (dir == 0 || dir == 3 ? i : 0); @@ -2344,80 +1766,12 @@ static void DrawLevelFieldCrumbledBorders(int x, int y, int graphic, int frame, by = cy; } -#if NEW_TILESIZE - BlitBitmap(src_bitmap, drawto_field, - src_x + bx, - src_y + by, - width, - height, + BlitBitmap(src_bitmap, drawto_field, src_x + bx, src_y + by, + width, height, FX + sx * TILEX_VAR + cx, FY + sy * TILEY_VAR + cy); -#else - BlitBitmap(src_bitmap, drawto_field, src_x + bx, src_y + by, - width, height, FX + sx * TILEX + cx, FY + sy * TILEY + cy); -#endif - } - } -#else - if (dir == 1 || dir == 2) /* left or right crumbled border */ - { - for (i = -1; i <= 1; i+=2) - { - int xx = x; - int yy = y + i; - int element = (IN_LEV_FIELD(xx, yy) ? TILE_GFX_ELEMENT(xx, yy) : - BorderElement); - - /* check if neighbour field is of same crumble type */ - if (IS_CRUMBLED_TILE(xx, yy, element) && - graphic_info[graphic].class == - graphic_info[el_act2crm(element, ACTION_DEFAULT)].class) - { - /* no crumbled corner, but continued crumbled border */ - - width = crumbled_border_size; - height = crumbled_border_size; - cx = (dir == 2 ? TILEX - crumbled_border_size : 0); - cy = (i == 1 ? TILEY - crumbled_border_size : 0); - bx = cx; - by = (i == 1 ? crumbled_border_size : - TILEY - 2 * crumbled_border_size); - - BlitBitmap(src_bitmap, drawto_field, src_x + bx, src_y + by, - width, height, FX + sx * TILEX + cx, FY + sy * TILEY + cy); - } - } - } - else /* top or bottom crumbled border */ - { - for (i = -1; i <= 1; i+=2) - { - int xx = x + i; - int yy = y; - int element = (IN_LEV_FIELD(xx, yy) ? TILE_GFX_ELEMENT(xx, yy) : - BorderElement); - - /* check if neighbour field is of same crumble type */ - if (IS_CRUMBLED_TILE(xx, yy, element) && - graphic_info[graphic].class == - graphic_info[el_act2crm(element, ACTION_DEFAULT)].class) - { - /* no crumbled corner, but continued crumbled border */ - - width = crumbled_border_size; - height = crumbled_border_size; - cx = (i == 1 ? TILEX - crumbled_border_size : 0); - cy = (dir == 3 ? TILEY - crumbled_border_size : 0); - bx = (i == 1 ? crumbled_border_size : - TILEX - 2 * crumbled_border_size); - by = cy; - - BlitBitmap(src_bitmap, drawto_field, src_x + bx, src_y + by, - width, height, FX + sx * TILEX + cx, FY + sy * TILEY + cy); - } } } -#endif } static void DrawLevelFieldCrumbledExt(int x, int y, int graphic, int frame) @@ -2453,15 +1807,10 @@ static void DrawLevelFieldCrumbledExt(int x, int y, int graphic, int frame) BorderElement); /* check if neighbour field is of same crumble type */ -#if 1 if (IS_CRUMBLED_TILE(xx, yy, element) && graphic_info[graphic].class == graphic_info[el_act2crm(element, ACTION_DEFAULT)].class) continue; -#else - if (IS_CRUMBLED_TILE(xx, yy, element)) - continue; -#endif DrawLevelFieldCrumbledBorders(x, y, graphic, frame, i); } @@ -2517,14 +1866,6 @@ void DrawLevelFieldCrumbled(int x, int y) if (!IN_LEV_FIELD(x, y)) return; -#if 1 - /* !!! CHECK THIS !!! */ - - /* - if (Feld[x][y] == EL_ELEMENT_SNAPPING && - GFX_CRUMBLED(GfxElement[x][y])) - */ - if (Feld[x][y] == EL_ELEMENT_SNAPPING && GfxElement[x][y] != EL_UNDEFINED && GFX_CRUMBLED(GfxElement[x][y])) @@ -2533,13 +1874,8 @@ void DrawLevelFieldCrumbled(int x, int y) return; } -#endif -#if 1 graphic = el_act2crm(TILE_GFX_ELEMENT(x, y), ACTION_DEFAULT); -#else - graphic = el_act2crm(Feld[x][y], ACTION_DEFAULT); -#endif DrawLevelFieldCrumbledExt(x, y, graphic, 0); } @@ -2660,22 +1996,8 @@ void DrawScreenField(int x, int y) element == EL_DC_MAGIC_WALL_FILLING) cut_mode = CUT_BELOW; -#if 0 - if (lx == 9 && ly == 1) - printf("::: %s [%d] [%d, %d] [%d]\n", - EL_NAME(TILE_GFX_ELEMENT(lx, ly)), - el_act2crm(TILE_GFX_ELEMENT(lx, ly), ACTION_DEFAULT), - element_info[EL_QUICKSAND_EMPTYING].graphic[ACTION_DEFAULT], - element_info[EL_QUICKSAND_EMPTYING].crumbled[ACTION_DEFAULT], - GFX_CRUMBLED(TILE_GFX_ELEMENT(lx, ly))); -#endif - if (cut_mode == CUT_ABOVE) -#if 1 DrawScreenElement(x, y, element); -#else - DrawScreenElementShifted(x, y, 0, 0, element, NO_CUTTING); -#endif else DrawScreenElement(x, y, EL_EMPTY); @@ -2687,11 +2009,9 @@ void DrawScreenField(int x, int y) { DrawScreenElementShifted(x, y, 0, MovPos[lx][ly], content, cut_mode); -#if 1 if (cut_mode == CUT_BELOW && IN_LEV_FIELD(lx, ly + 1) && IN_SCR_FIELD(x, y + 1)) DrawLevelElement(lx, ly + 1, element); -#endif } if (content == EL_ACID) @@ -2874,11 +2194,7 @@ void AnimateEnvelope(int envelope_nr, int anim_mode, int action) SetDrawtoField(DRAW_BUFFERED); -#if 1 BlitScreenToBitmap(backbuffer); -#else - BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY); -#endif SetDrawtoField(DRAW_BACKBUFFER); @@ -2886,17 +2202,11 @@ void AnimateEnvelope(int envelope_nr, int anim_mode, int action) for (xx = 0; xx < xsize; xx++) DrawEnvelopeBackground(graphic, sx, sy, xx, yy, xsize, ysize, font_nr); -#if 1 DrawTextBuffer(sx + font_width, sy + font_height, level.envelope[envelope_nr].text, font_nr, max_xsize, xsize - 2, ysize - 2, 0, mask_mode, level.envelope[envelope_nr].autowrap, level.envelope[envelope_nr].centered, FALSE); -#else - DrawTextToTextArea(sx + font_width, sy + font_height, - level.envelope[envelope_nr].text, font_nr, max_xsize, - xsize - 2, ysize - 2, mask_mode); -#endif redraw_mask |= REDRAW_FIELD | REDRAW_FROM_BACKBUFFER; BackToFront(); @@ -3039,41 +2349,16 @@ void DrawEnvelopeRequest(char *text) // store readily prepared envelope request for later use when animating BlitBitmap(backbuffer, bitmap_db_cross, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); -#if 0 - // !!! TEST !!! - BlitBitmap(bitmap_db_store, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); - BlitBitmap(bitmap_db_cross, backbuffer, sx, sy, width, height, sx, sy); - - redraw_mask = REDRAW_FIELD | REDRAW_FROM_BACKBUFFER; - BackToFront(); - - Delay(3000); - - BlitBitmap(bitmap_db_store, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); - - redraw_mask = REDRAW_FIELD | REDRAW_FROM_BACKBUFFER; - BackToFront(); - - Delay(1000); -#endif - if (text_door_style) free(text_door_style); } -#if 1 - void AnimateEnvelopeRequest(int anim_mode, int action) { int graphic = IMG_BACKGROUND_REQUEST; boolean draw_masked = graphic_info[graphic].draw_masked; -#if 1 int delay_value_normal = request.step_delay; int delay_value_fast = delay_value_normal / 2; -#else - int delay_value_normal = GameFrameDelay; - int delay_value_fast = FfwdFrameDelay; -#endif boolean ffwd_delay = (tape.playing && tape.fast_forward); boolean no_delay = (tape.warp_forward); int delay_value = (ffwd_delay ? delay_value_fast : delay_value_normal); @@ -3114,7 +2399,6 @@ void AnimateEnvelopeRequest(int anim_mode, int action) BlitBitmap(bitmap_db_store, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); -#if 1 for (yy = 0; yy < 2; yy++) { for (xx = 0; xx < 2; xx++) @@ -3134,341 +2418,56 @@ void AnimateEnvelopeRequest(int anim_mode, int action) src_xx, src_yy, xx_size, yy_size, dst_xx, dst_yy); } } -#else - BlitBitmap(bitmap_db_cross, backbuffer, - src_x, src_y, - xsize_size_left, ysize_size_top, - dst_x, dst_y); - BlitBitmap(bitmap_db_cross, backbuffer, - src_x + max_xsize_pos, src_y, - tile_size, ysize_size_top, - dst_x + xsize_size_left, dst_y); - BlitBitmap(bitmap_db_cross, backbuffer, - src_x, src_y + max_ysize_pos, - xsize_size_left, tile_size, - dst_x, dst_y + ysize_size_top); - BlitBitmap(bitmap_db_cross, backbuffer, - src_x + max_xsize_pos, src_y + max_ysize_pos, - tile_size, tile_size, - dst_x + xsize_size_left, dst_y + ysize_size_top); -#endif -#if 0 - redraw_mask = REDRAW_FIELD | REDRAW_FROM_BACKBUFFER; - // redraw_mask |= REDRAW_ALL | REDRAW_FROM_BACKBUFFER; -#else - /* CHECK AGAIN (previous code reactivated) */ redraw_mask |= REDRAW_FIELD | REDRAW_FROM_BACKBUFFER; -#endif -#if 1 DoAnimation(); BackToFront(); -#else - BackToFront(); -#endif WaitUntilDelayReached(&anim_delay, anim_delay_value / 2); } } -#else -void AnimateEnvelopeRequest(char *text, int anim_mode, int action) +void ShowEnvelopeRequest(char *text, unsigned int req_state, int action) { -#if 0 - int envelope_nr = 0; -#endif -#if 1 + int last_game_status = game_status; /* save current game status */ int graphic = IMG_BACKGROUND_REQUEST; -#else - int graphic = IMG_BACKGROUND_ENVELOPE_1 + envelope_nr; -#endif - Bitmap *src_bitmap = graphic_info[graphic].bitmap; - int mask_mode = (src_bitmap != NULL ? BLIT_MASKED : BLIT_ON_BACKGROUND); - boolean ffwd_delay = (tape.playing && tape.fast_forward); - boolean no_delay = (tape.warp_forward); - unsigned int anim_delay = 0; - int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay); - int anim_delay_value = (no_delay ? 0 : frame_delay_value + 500 * 0); -#if 1 - int max_word_len = maxWordLengthInString(text); - int font_nr = (max_word_len > 7 ? FONT_TEXT_1 : FONT_TEXT_2); -#else - int font_nr = FONT_ENVELOPE_1 + envelope_nr; -#endif - int font_width = getFontWidth(font_nr); - int font_height = getFontHeight(font_nr); - int line_spacing = 2 * 1; -#if 1 - -#if 1 - int max_xsize = DXSIZE / font_width; - // int max_ysize = DYSIZE / font_height; - int max_ysize = DYSIZE / (font_height + line_spacing); -#else - int max_xsize = 7; /* tools.c: MAX_REQUEST_LINE_FONT1_LEN == 7 */ - int max_ysize = 13; /* tools.c: MAX_REQUEST_LINES == 13 */ -#endif - -#else - int max_xsize = level.envelope[envelope_nr].xsize; - int max_ysize = level.envelope[envelope_nr].ysize; -#endif - int xstart = (anim_mode & ANIM_VERTICAL ? max_xsize : 0); - int ystart = (anim_mode & ANIM_HORIZONTAL ? max_ysize : 0); - int xend = max_xsize; - int yend = (anim_mode != ANIM_DEFAULT ? max_ysize : 0); - int xstep = (xstart < xend ? 1 : 0); - int ystep = (ystart < yend || xstep == 0 ? 1 : 0); - int x, y; + int sound_opening = SND_REQUEST_OPENING; + int sound_closing = SND_REQUEST_CLOSING; + int anim_mode = graphic_info[graphic].anim_mode; + int main_anim_mode = (anim_mode == ANIM_NONE ? ANIM_VERTICAL|ANIM_HORIZONTAL: + anim_mode == ANIM_DEFAULT ? ANIM_VERTICAL : anim_mode); -#if 1 - char *text_ptr; - char *text_copy = getStringCopy(text); -#else -#if 1 - font_nr = FONT_TEXT_2; + if (game_status == GAME_MODE_PLAYING) + BlitScreenToBitmap(backbuffer); - if (maxWordLengthInString(text) > 7) /* MAX_REQUEST_LINE_FONT1_LEN == 7 */ - { - max_xsize = 10; /* tools.c: MAX_REQUEST_LINE_FONT2_LEN == 10 */ - font_nr = FONT_TEXT_1; - } -#else - int max_word_len = 0; - char *text_ptr; - char *text_copy = getStringCopy(text); + SetDrawtoField(DRAW_BACKBUFFER); - font_nr = FONT_TEXT_2; + // SetDrawBackgroundMask(REDRAW_NONE); - for (text_ptr = text; *text_ptr; text_ptr++) + if (action == ACTION_OPENING) { - max_word_len = (*text_ptr != ' ' ? max_word_len + 1 : 0); + BlitBitmap(backbuffer, bitmap_db_store, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); - if (max_word_len > 7) /* tools.c: MAX_REQUEST_LINE_FONT1_LEN == 7 */ + if (req_state & REQ_ASK) { - max_xsize = 10; /* tools.c: MAX_REQUEST_LINE_FONT2_LEN == 10 */ - font_nr = FONT_TEXT_1; - - break; + MapGadget(tool_gadget[TOOL_CTRL_ID_YES]); + MapGadget(tool_gadget[TOOL_CTRL_ID_NO]); } - } -#endif -#endif - -#if 1 - for (text_ptr = text_copy; *text_ptr; text_ptr++) - if (*text_ptr == ' ') - *text_ptr = '\n'; -#endif - -#if 1 - dDX = SX + (SXSIZE - DXSIZE) / 2 - DX; - dDY = SY + (SYSIZE - DYSIZE) / 2 - DY; -#else - dDX = SX + SXSIZE / 2 - max_xsize * font_width / 2 - DX; - dDY = SY + SYSIZE / 2 - max_ysize * font_height / 2 - DY; -#endif - - for (x = xstart, y = ystart; x <= xend && y <= yend; x += xstep, y += ystep) - { - int xsize = (action == ACTION_CLOSING ? xend - (x - xstart) : x) + 2; - int ysize = (action == ACTION_CLOSING ? yend - (y - ystart) : y) + 2; - int sx = SX + (SXSIZE - xsize * font_width) / 2; - // int sy = SX + (SYSIZE - ysize * font_height) / 2; - int sy = SY + (SYSIZE - ysize * (font_height + line_spacing)) / 2; - int xx, yy; - -#if 1 - BlitBitmap(bitmap_db_store, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); -#else - SetDrawtoField(DRAW_BUFFERED); - -#if 1 - BlitScreenToBitmap(backbuffer); -#else - BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY); -#endif - - SetDrawtoField(DRAW_BACKBUFFER); -#endif - - for (yy = 0; yy < ysize; yy++) - for (xx = 0; xx < xsize; xx++) - DrawEnvelopeBackgroundTiles(graphic, sx, sy, xx, yy, xsize, ysize, - getFontWidth(font_nr), - getFontHeight(font_nr) + line_spacing); - -#if 1 - -#if 1 - DrawTextBuffer(sx + font_width, sy + font_height + 8, - text_copy, font_nr, max_xsize, - xsize - 2, ysize - 2, line_spacing, mask_mode, - FALSE, TRUE, FALSE); -#else - DrawTextBuffer(sx + font_width, sy + font_height, - level.envelope[envelope_nr].text, font_nr, max_xsize, - xsize - 2, ysize - 2, 0, mask_mode, - level.envelope[envelope_nr].autowrap, - level.envelope[envelope_nr].centered, FALSE); -#endif - -#else - DrawTextToTextArea(sx + font_width, sy + font_height, - level.envelope[envelope_nr].text, font_nr, max_xsize, - xsize - 2, ysize - 2, mask_mode); -#endif - - /* copy request gadgets to door backbuffer */ -#if 1 - /* - if ((ysize - 2) > 13) - BlitBitmap(bitmap_db_door, drawto, - DOOR_GFX_PAGEX1 + (DXSIZE - (xsize - 2) * font_width) / 2, - DOOR_GFX_PAGEY1 + 13 * font_height, - (xsize - 2) * font_width, - (ysize - 2 - 13) * font_height, - sx + font_width, - sy + font_height * (1 + 13)); - */ - if ((ysize - 2) > 13) - BlitBitmap(bitmap_db_door, drawto, - DOOR_GFX_PAGEX1 + (DXSIZE - (xsize - 2) * font_width) / 2, - DOOR_GFX_PAGEY1 + 11 * (font_height + line_spacing * 0), - (xsize - 2) * font_width, - (ysize - 2 - 13) * (font_height + line_spacing), - sx + font_width, - sy + (font_height + line_spacing) * (1 + 13)); -#else - if ((ysize - 2) > 13) - BlitBitmap(bitmap_db_door, drawto, - DOOR_GFX_PAGEX1 + (DXSIZE - (xsize - 2) * font_width) / 2, - DOOR_GFX_PAGEY1 + 13 * font_height, - (xsize - 2) * font_width, - (ysize - 2 - 13) * font_height, - sx + font_width, - sy + font_height * (1 + 13)); -#endif - -#if 1 - redraw_mask = REDRAW_FIELD | REDRAW_FROM_BACKBUFFER; - // redraw_mask |= REDRAW_ALL | REDRAW_FROM_BACKBUFFER; -#else - redraw_mask |= REDRAW_FIELD | REDRAW_FROM_BACKBUFFER; -#endif - -#if 1 - DoAnimation(); - BackToFront(); -#else - BackToFront(); -#endif - - WaitUntilDelayReached(&anim_delay, anim_delay_value / 2); - } - -#if 1 - free(text_copy); -#endif -} - -#endif - -void ShowEnvelopeRequest(char *text, unsigned int req_state, int action) -{ -#if 1 - int last_game_status = game_status; /* save current game status */ - // int last_draw_background_mask = gfx.draw_background_mask; -#endif -#if 1 - int graphic = IMG_BACKGROUND_REQUEST; - int sound_opening = SND_REQUEST_OPENING; - int sound_closing = SND_REQUEST_CLOSING; -#else - int envelope_nr = 0; - int element = EL_ENVELOPE_1 + envelope_nr; - int graphic = IMG_BACKGROUND_ENVELOPE_1 + envelope_nr; - int sound_opening = element_info[element].sound[ACTION_OPENING]; - int sound_closing = element_info[element].sound[ACTION_CLOSING]; -#endif -#if 0 - boolean ffwd_delay = (tape.playing && tape.fast_forward); - boolean no_delay = (tape.warp_forward); - int normal_delay_value = ONE_SECOND_DELAY / (ffwd_delay ? 2 : 1); - int wait_delay_value = (no_delay ? 0 : normal_delay_value); -#endif - int anim_mode = graphic_info[graphic].anim_mode; - int main_anim_mode = (anim_mode == ANIM_NONE ? ANIM_VERTICAL|ANIM_HORIZONTAL: - anim_mode == ANIM_DEFAULT ? ANIM_VERTICAL : anim_mode); -#if 0 - char *text_copy = getStringCopy(text); - char *text_ptr; - - for (text_ptr = text_copy; *text_ptr; text_ptr++) - if (*text_ptr == ' ') - *text_ptr = '\n'; -#endif - -#if 1 - if (game_status == GAME_MODE_PLAYING) - { -#if 1 -#if 1 - BlitScreenToBitmap(backbuffer); -#else - if (level.game_engine_type == GAME_ENGINE_TYPE_EM) - BlitScreenToBitmap_EM(backbuffer); - else if (level.game_engine_type == GAME_ENGINE_TYPE_SP) - BlitScreenToBitmap_SP(backbuffer); - else - BlitScreenToBitmap_RND(backbuffer); -#endif -#else - if (level.game_engine_type == GAME_ENGINE_TYPE_EM) - BlitScreenToBitmap_EM(backbuffer); - else if (level.game_engine_type == GAME_ENGINE_TYPE_SP) - BlitScreenToBitmap_SP(backbuffer); - else + else if (req_state & REQ_CONFIRM) { - BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY); + MapGadget(tool_gadget[TOOL_CTRL_ID_CONFIRM]); + } + else if (req_state & REQ_PLAYER) + { + MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_1]); + MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_2]); + MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_3]); + MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_4]); } -#endif - } - - SetDrawtoField(DRAW_BACKBUFFER); - - // SetDrawBackgroundMask(REDRAW_NONE); - - if (action == ACTION_OPENING) - { - BlitBitmap(backbuffer, bitmap_db_store, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); - -#if 1 - if (req_state & REQ_ASK) - { - MapGadget(tool_gadget[TOOL_CTRL_ID_YES]); - MapGadget(tool_gadget[TOOL_CTRL_ID_NO]); - } - else if (req_state & REQ_CONFIRM) - { - MapGadget(tool_gadget[TOOL_CTRL_ID_CONFIRM]); - } - else if (req_state & REQ_PLAYER) - { - MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_1]); - MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_2]); - MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_3]); - MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_4]); - } -#endif -#if 1 DrawEnvelopeRequest(text); -#else - DrawEnvelopeRequest(text_copy); -#endif if (game_status != GAME_MODE_MAIN) InitAnimation(); @@ -3476,7 +2475,6 @@ void ShowEnvelopeRequest(char *text, unsigned int req_state, int action) /* force DOOR font inside door area */ game_status = GAME_MODE_PSEUDO_DOOR; -#endif game.envelope_active = TRUE; /* needed for RedrawPlayfield() events */ @@ -3489,12 +2487,6 @@ void ShowEnvelopeRequest(char *text, unsigned int req_state, int action) AnimateEnvelopeRequest(main_anim_mode, ACTION_OPENING); -#if 0 - if (tape.playing) - Delay(wait_delay_value); - else - WaitForEventToContinue(); -#endif } else { @@ -3509,13 +2501,7 @@ void ShowEnvelopeRequest(char *text, unsigned int req_state, int action) game.envelope_active = FALSE; -#if 1 - // game_status = last_game_status; /* restore current game status */ - -#if 1 - /* !!! CHECK AGAIN (SEE BELOW) !!! */ game_status = last_game_status; /* restore current game status */ -#endif if (action == ACTION_CLOSING) { @@ -3524,49 +2510,20 @@ void ShowEnvelopeRequest(char *text, unsigned int req_state, int action) BlitBitmap(bitmap_db_store, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); } -#else - SetDrawtoField(DRAW_BUFFERED); -#endif // SetDrawBackgroundMask(last_draw_background_mask); -#if 0 - redraw_mask = REDRAW_FIELD; - // redraw_mask |= REDRAW_ALL; -#else - /* CHECK AGAIN (previous code reactivated) */ redraw_mask |= REDRAW_FIELD; -#endif -#if 1 if (game_status == GAME_MODE_MAIN) DoAnimation(); BackToFront(); -#if 0 - /* (important: after "BackToFront()", but before "SetDrawtoField()") */ - game_status = last_game_status; /* restore current game status */ -#endif - -#if 1 if (action == ACTION_CLOSING && game_status == GAME_MODE_PLAYING && level.game_engine_type == GAME_ENGINE_TYPE_RND) SetDrawtoField(DRAW_BUFFERED); -#else - if (game_status == GAME_MODE_PLAYING && - level.game_engine_type == GAME_ENGINE_TYPE_RND) - SetDrawtoField(DRAW_BUFFERED); -#endif - -#else - BackToFront(); -#endif - -#if 0 - free(text_copy); -#endif } void DrawPreviewElement(int dst_x, int dst_y, int element, int tilesize) @@ -3583,17 +2540,8 @@ void DrawLevel(int draw_background_mask) { int x,y; -#if 1 SetMainBackgroundImage(IMG_BACKGROUND_PLAYING); SetDrawBackgroundMask(draw_background_mask); -#else -#if 1 - SetMainBackgroundImage(IMG_BACKGROUND_PLAYING); - SetDrawBackgroundMask(REDRAW_FIELD); -#else - SetDrawBackgroundMask(REDRAW_NONE); -#endif -#endif ClearField(); @@ -3631,22 +2579,13 @@ static void DrawPreviewLevelPlayfieldExt(int from_x, int from_y) int dst_y = SY + ALIGNED_YPOS(preview.y, preview_height, preview.valign); int x, y; -#if 1 if (!IN_GFX_FIELD_FULL(dst_x, dst_y + preview_height - 1)) return; -#endif -#if 0 - dst_x += (preview_width - real_preview_width) / 2; - dst_y += (preview_height - real_preview_height) / 2; - - DrawBackground(dst_x, dst_y, real_preview_width, real_preview_height); -#else DrawBackground(dst_x, dst_y, preview_width, preview_height); dst_x += (preview_width - real_preview_width) / 2; dst_y += (preview_height - real_preview_height) / 2; -#endif for (x = 0; x < real_preview_xsize; x++) { @@ -3694,7 +2633,6 @@ static void DrawPreviewLevelLabelExt(int mode) struct TextPosInfo *pos = &menu.main.text.level_info_2; char label_text[MAX_OUTPUT_LINESIZE + 1]; int max_len_label_text; -#if 1 int font_nr = pos->font; int i; @@ -3705,42 +2643,18 @@ static void DrawPreviewLevelLabelExt(int mode) mode == MICROLABEL_IMPORTED_FROM_HEAD || mode == MICROLABEL_IMPORTED_BY_HEAD) font_nr = pos->font_alt; -#else - int font_nr = FONT_TEXT_2; - int i; - - if (mode == MICROLABEL_LEVEL_AUTHOR_HEAD || - mode == MICROLABEL_IMPORTED_FROM_HEAD || - mode == MICROLABEL_IMPORTED_BY_HEAD) - font_nr = FONT_TEXT_3; -#endif -#if 1 max_len_label_text = getMaxTextLength(pos, font_nr); -#else - max_len_label_text = SXSIZE / getFontWidth(font_nr); -#endif -#if 1 if (pos->size != -1) max_len_label_text = pos->size; -#endif for (i = 0; i < max_len_label_text; i++) label_text[i] = ' '; label_text[max_len_label_text] = '\0'; if (strlen(label_text) > 0) - { -#if 1 DrawTextSAligned(pos->x, pos->y, label_text, font_nr, pos->align); -#else - int lxpos = SX + (SXSIZE - getTextWidth(label_text, font_nr)) / 2; - int lypos = MICROLABEL2_YPOS; - - DrawText(lxpos, lypos, label_text, font_nr); -#endif - } strncpy(label_text, (mode == MICROLABEL_LEVEL_NAME ? level.name : @@ -3754,16 +2668,7 @@ static void DrawPreviewLevelLabelExt(int mode) label_text[max_len_label_text] = '\0'; if (strlen(label_text) > 0) - { -#if 1 DrawTextSAligned(pos->x, pos->y, label_text, font_nr, pos->align); -#else - int lxpos = SX + (SXSIZE - getTextWidth(label_text, font_nr)) / 2; - int lypos = MICROLABEL2_YPOS; - - DrawText(lxpos, lypos, label_text, font_nr); -#endif - } redraw_mask |= REDRAW_MICROLEVEL; } @@ -3780,11 +2685,6 @@ static void DrawPreviewLevelExt(boolean restart) int level_ysize = lev_fieldy + (show_level_border ? 2 : 0); int last_game_status = game_status; /* save current game status */ -#if 0 - /* force PREVIEW font on preview level */ - game_status = GAME_MODE_PSEUDO_PREVIEW; -#endif - if (restart) { from_x = 0; @@ -3816,38 +2716,17 @@ static void DrawPreviewLevelExt(boolean restart) { struct TextPosInfo *pos = &menu.main.text.level_info_1; char label_text[MAX_OUTPUT_LINESIZE + 1]; -#if 1 int font_nr = pos->font; -#else - int font_nr = FONT_TEXT_1; -#endif -#if 1 int max_len_label_text = getMaxTextLength(pos, font_nr); -#else - int max_len_label_text = SXSIZE / getFontWidth(font_nr); -#endif -#if 0 - int text_width; - int lxpos, lypos; -#endif -#if 1 if (pos->size != -1) max_len_label_text = pos->size; -#endif strncpy(label_text, leveldir_current->name, max_len_label_text); label_text[max_len_label_text] = '\0'; -#if 1 if (IN_GFX_FIELD_FULL(pos->x, pos->y + getFontHeight(pos->font))) DrawTextSAligned(pos->x, pos->y, label_text, font_nr, pos->align); -#else - lxpos = SX + (SXSIZE - getTextWidth(label_text, font_nr)) / 2; - lypos = SY + MICROLABEL1_YPOS; - - DrawText(lxpos, lypos, label_text, font_nr); -#endif } game_status = last_game_status; /* restore current game status */ @@ -3995,13 +2874,9 @@ inline void DrawGraphicAnimation(int x, int y, int graphic) if (!IN_SCR_FIELD(x, y)) return; -#if NEW_TILESIZE DrawGraphicAnimationExt(drawto_field, FX + x * TILEX_VAR, FY + y * TILEY_VAR, graphic, GfxFrame[lx][ly], NO_MASKING); -#else - DrawGraphicAnimationExt(drawto_field, FX + x * TILEX, FY + y * TILEY, - graphic, GfxFrame[lx][ly], NO_MASKING); -#endif + MarkTileDirty(x, y); } @@ -4250,15 +3125,10 @@ void DrawPlayer(struct PlayerInfo *player) GfxElement[jx][jy] = EL_UNDEFINED; /* make sure that pushed elements are drawn with correct frame rate */ -#if 1 graphic = el_act_dir2img(element, ACTION_PUSHING, move_dir); if (player->is_pushing && player->is_moving && !IS_ANIM_MODE_CE(graphic)) GfxFrame[jx][jy] = player->StepFrame; -#else - if (player->is_pushing && player->is_moving) - GfxFrame[jx][jy] = player->StepFrame; -#endif DrawLevelField(jx, jy); } @@ -4318,13 +3188,6 @@ void DrawPlayer(struct PlayerInfo *player) /* draw things the player is pushing, if needed */ /* ----------------------------------------------------------------------- */ -#if 0 - printf("::: %d, %d [%d, %d] [%d]\n", - player->is_pushing, player_is_moving, player->GfxAction, - player->is_moving, player_is_moving); -#endif - -#if 1 if (player->is_pushing && player->is_moving) { int px = SCREENX(jx), py = SCREENY(jy); @@ -4344,15 +3207,10 @@ void DrawPlayer(struct PlayerInfo *player) graphic = el_act_dir2img(element, ACTION_PUSHING, move_dir); -#if 1 sync_frame = (IS_ANIM_MODE_CE(graphic) ? gfx_frame : player->StepFrame); frame = getGraphicAnimationFrame(graphic, sync_frame); -#else - frame = getGraphicAnimationFrame(graphic, player->StepFrame); -#endif /* draw background element under pushed element (like the Sokoban field) */ -#if 1 if (game.use_masked_pushing && IS_MOVING(jx, jy)) { /* this allows transparent pushing animation over non-black background */ @@ -4369,20 +3227,6 @@ void DrawPlayer(struct PlayerInfo *player) } else if (Back[next_jx][next_jy]) DrawLevelElement(next_jx, next_jy, Back[next_jx][next_jy]); -#else - if (Back[next_jx][next_jy]) - DrawLevelElement(next_jx, next_jy, Back[next_jx][next_jy]); -#endif - -#if 0 - printf("::: %d, %d, %d, %d [%d] [%d, %d, %d] [%d] [%d, %d] [%d, %d]\n", - jx, px, player->GfxPos, player->StepFrame, - player->is_pushing, - dx, sxx, pxx, - IS_MOVING(jx, jy), - graphic, frame, - GfxFrame[jx][jy], GfxFrame[next_jx][next_jy]); -#endif #if 1 /* do not draw (EM style) pushing animation when pushing is finished */ @@ -4397,7 +3241,6 @@ void DrawPlayer(struct PlayerInfo *player) DrawGraphicShiftedThruMask(px, py, pxx, pyy, graphic, frame, NO_CUTTING); #endif } -#endif #if DRAW_PLAYER_OVER_PUSHED_ELEMENT /* ----------------------------------------------------------------------- */ @@ -4505,9 +3348,7 @@ void WaitForEventToContinue() button_status = MB_RELEASED; -#if 1 ClearEventQueue(); -#endif while (still_wait) { @@ -4549,8 +3390,6 @@ void WaitForEventToContinue() #define MAX_REQUEST_LINE_FONT1_LEN 7 #define MAX_REQUEST_LINE_FONT2_LEN 10 -#if 1 - static int RequestHandleEvents(unsigned int req_state) { int last_game_status = game_status; /* save current game status */ @@ -4683,8 +3522,6 @@ static int RequestHandleEvents(unsigned int req_state) result = 0; } -#if 1 - if (game_status == GAME_MODE_PLAYING && local_player->LevelSolved_GameEnd) { HandleGameActions(); @@ -4697,29 +3534,11 @@ static int RequestHandleEvents(unsigned int req_state) Delay(10); } -#if 1 game_status = GAME_MODE_PSEUDO_DOOR; -#endif BackToFront(); -#if 1 game_status = last_game_status; /* restore current game status */ -#endif - -#else - - DoAnimation(); - -#if 1 - if (!PendingEvent()) /* delay only if no pending events */ - Delay(10); -#else - /* don't eat all CPU time */ - Delay(10); -#endif - -#endif } return result; @@ -4742,16 +3561,7 @@ static boolean RequestDoor(char *text, unsigned int req_state) } if (game_status == GAME_MODE_PLAYING) - { -#if 1 BlitScreenToBitmap(backbuffer); -#else - if (level.game_engine_type == GAME_ENGINE_TYPE_EM) - BlitScreenToBitmap_EM(backbuffer); - else if (level.game_engine_type == GAME_ENGINE_TYPE_SP) - BlitScreenToBitmap_SP(backbuffer); -#endif - } /* disable deactivated drawing when quick-loading level tape recording */ if (tape.playing && tape.deactivate_display) @@ -4783,14 +3593,8 @@ static boolean RequestDoor(char *text, unsigned int req_state) CloseDoor(DOOR_CLOSE_1); /* save old door content */ -#if 1 BlitBitmap(bitmap_db_door_1, bitmap_db_door_1, 0 * DXSIZE, 0, DXSIZE, DYSIZE, 1 * DXSIZE, 0); -#else - BlitBitmap(bitmap_db_door, bitmap_db_door, - DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, - DOOR_GFX_PAGEX2, DOOR_GFX_PAGEY1); -#endif } SetDoorBackgroundImage(IMG_BACKGROUND_DOOR); @@ -4860,13 +3664,7 @@ static boolean RequestDoor(char *text, unsigned int req_state) } /* copy request gadgets to door backbuffer */ -#if 1 BlitBitmap(drawto, bitmap_db_door_1, DX, DY, DXSIZE, DYSIZE, 0, 0); -#else - BlitBitmap(drawto, bitmap_db_door, - DX, DY, DXSIZE, DYSIZE, - DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1); -#endif OpenDoor(DOOR_OPEN_1); @@ -4937,30 +3735,9 @@ static boolean RequestDoor(char *text, unsigned int req_state) static boolean RequestEnvelope(char *text, unsigned int req_state) { int result; -#if 0 - int i; -#endif if (game_status == GAME_MODE_PLAYING) - { -#if 1 -#if 1 BlitScreenToBitmap(backbuffer); -#else - if (level.game_engine_type == GAME_ENGINE_TYPE_EM) - BlitScreenToBitmap_EM(backbuffer); - else if (level.game_engine_type == GAME_ENGINE_TYPE_SP) - BlitScreenToBitmap_SP(backbuffer); - else - BlitScreenToBitmap_RND(backbuffer); -#endif -#else - if (level.game_engine_type == GAME_ENGINE_TYPE_EM) - BlitScreenToBitmap_EM(backbuffer); - else if (level.game_engine_type == GAME_ENGINE_TYPE_SP) - BlitScreenToBitmap_SP(backbuffer); -#endif - } /* disable deactivated drawing when quick-loading level tape recording */ if (tape.playing && tape.deactivate_display) @@ -4989,74 +3766,8 @@ static boolean RequestEnvelope(char *text, unsigned int req_state) /* clear door drawing field */ // DrawBackground(DX, DY, DXSIZE, DYSIZE); -#if 0 - if (global.use_envelope_request) - { - /* !!! TMP !!! */ - FreeToolButtons(); - CreateToolButtons(); - } -#endif - -#if 0 -#if 0 - if (req_state & REQ_ASK) - { - MapGadgetExt(tool_gadget[TOOL_CTRL_ID_YES], FALSE); - MapGadgetExt(tool_gadget[TOOL_CTRL_ID_NO], FALSE); - } - else if (req_state & REQ_CONFIRM) - { - MapGadgetExt(tool_gadget[TOOL_CTRL_ID_CONFIRM], FALSE); - } - else if (req_state & REQ_PLAYER) - { - MapGadgetExt(tool_gadget[TOOL_CTRL_ID_PLAYER_1], FALSE); - MapGadgetExt(tool_gadget[TOOL_CTRL_ID_PLAYER_2], FALSE); - MapGadgetExt(tool_gadget[TOOL_CTRL_ID_PLAYER_3], FALSE); - MapGadgetExt(tool_gadget[TOOL_CTRL_ID_PLAYER_4], FALSE); - } -#else - if (req_state & REQ_ASK) - { - MapGadget(tool_gadget[TOOL_CTRL_ID_YES]); - MapGadget(tool_gadget[TOOL_CTRL_ID_NO]); - } - else if (req_state & REQ_CONFIRM) - { - MapGadget(tool_gadget[TOOL_CTRL_ID_CONFIRM]); - } - else if (req_state & REQ_PLAYER) - { - MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_1]); - MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_2]); - MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_3]); - MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_4]); - } -#endif -#endif - ShowEnvelopeRequest(text, req_state, ACTION_OPENING); -#if 0 - for (i = 0; i < NUM_TOOL_BUTTONS; i++) - { - if ((req_state & REQ_ASK && (i == TOOL_CTRL_ID_YES || - i == TOOL_CTRL_ID_NO)) || - (req_state & REQ_CONFIRM && i == TOOL_CTRL_ID_CONFIRM) || - (req_state & REQ_PLAYER && (i == TOOL_CTRL_ID_PLAYER_1 && - i == TOOL_CTRL_ID_PLAYER_2 && - i == TOOL_CTRL_ID_PLAYER_3 && - i == TOOL_CTRL_ID_PLAYER_4))) - { - int x = tool_gadget[i]->x + dDX; - int y = tool_gadget[i]->y + dDY; - - ModifyGadget(tool_gadget[i], GDI_X, x, GDI_Y, y, GDI_END); - } - } -#endif - if (!(req_state & REQUEST_WAIT_FOR_INPUT)) { if (game_status == GAME_MODE_PLAYING) @@ -5072,11 +3783,6 @@ static boolean RequestEnvelope(char *text, unsigned int req_state) return FALSE; } -#if 0 - if (game_status != GAME_MODE_MAIN) - InitAnimation(); -#endif - SetDrawBackgroundMask(REDRAW_FIELD | REDRAW_DOOR_1); // ---------- handle request buttons ---------- @@ -5124,2177 +3830,753 @@ boolean Request(char *text, unsigned int req_state) return RequestDoor(text, req_state); } -#else // ===================================================================== - -boolean Request(char *text, unsigned int req_state) +static int compareDoorPartOrderInfo(const void *object1, const void *object2) { - int mx, my, ty, result = -1; - unsigned int old_door_state; - int last_game_status = game_status; /* save current game status */ - int max_request_line_len = MAX_REQUEST_LINE_FONT1_LEN; - int font_nr = FONT_TEXT_2; -#if 0 - int max_word_len = 0; -#endif - char *text_ptr; - int i; + const struct DoorPartOrderInfo *dpo1 = (struct DoorPartOrderInfo *)object1; + const struct DoorPartOrderInfo *dpo2 = (struct DoorPartOrderInfo *)object2; + int compare_result; -#if 0 - global.use_envelope_request = 1; -#endif + if (dpo1->sort_priority != dpo2->sort_priority) + compare_result = dpo1->sort_priority - dpo2->sort_priority; + else + compare_result = dpo1->nr - dpo2->nr; -#if 1 - if (maxWordLengthInString(text) > MAX_REQUEST_LINE_FONT1_LEN) + return compare_result; +} + +void InitGraphicCompatibilityInfo_Doors() +{ + struct { - max_request_line_len = MAX_REQUEST_LINE_FONT2_LEN; - font_nr = FONT_TEXT_1; + int door_token; + int part_1, part_8; + struct DoorInfo *door; } -#else - for (text_ptr = text; *text_ptr; text_ptr++) + doors[] = { - max_word_len = (*text_ptr != ' ' ? max_word_len + 1 : 0); - - if (max_word_len > MAX_REQUEST_LINE_FONT1_LEN) - { - max_request_line_len = MAX_REQUEST_LINE_FONT2_LEN; -#if 1 - font_nr = FONT_TEXT_1; -#else - font_nr = FONT_LEVEL_NUMBER; -#endif + { DOOR_1, IMG_DOOR_1_GFX_PART_1, IMG_DOOR_1_GFX_PART_8, &door_1 }, + { DOOR_2, IMG_DOOR_2_GFX_PART_1, IMG_DOOR_2_GFX_PART_8, &door_2 }, - break; - } - } -#endif + { -1, -1, -1, NULL } + }; + struct Rect door_rect_list[] = + { + { DX, DY, DXSIZE, DYSIZE }, + { VX, VY, VXSIZE, VYSIZE } + }; + int i, j; - if (game_status == GAME_MODE_PLAYING) + for (i = 0; doors[i].door_token != -1; i++) { -#if 1 - BlitScreenToBitmap(backbuffer); -#else - if (level.game_engine_type == GAME_ENGINE_TYPE_EM) - BlitScreenToBitmap_EM(backbuffer); - else if (level.game_engine_type == GAME_ENGINE_TYPE_SP) - BlitScreenToBitmap_SP(backbuffer); -#endif - } + int door_token = doors[i].door_token; + int door_index = DOOR_INDEX_FROM_TOKEN(door_token); + int part_1 = doors[i].part_1; + int part_8 = doors[i].part_8; + int part_2 = part_1 + 1; + int part_3 = part_1 + 2; + struct DoorInfo *door = doors[i].door; + struct Rect *door_rect = &door_rect_list[door_index]; + boolean door_gfx_redefined = FALSE; - /* disable deactivated drawing when quick-loading level tape recording */ - if (tape.playing && tape.deactivate_display) - TapeDeactivateDisplayOff(TRUE); + /* check if any door part graphic definitions have been redefined */ - SetMouseCursor(CURSOR_DEFAULT); + for (j = 0; door_part_controls[j].door_token != -1; j++) + { + struct DoorPartControlInfo *dpc = &door_part_controls[j]; + struct FileInfo *fi = getImageListEntryFromImageID(dpc->graphic); -#if defined(NETWORK_AVALIABLE) - /* pause network game while waiting for request to answer */ - if (options.network && - game_status == GAME_MODE_PLAYING && - req_state & REQUEST_WAIT_FOR_INPUT) - SendToServer_PausePlaying(); -#endif + if (dpc->door_token == door_token && fi->redefined) + door_gfx_redefined = TRUE; + } - old_door_state = GetDoorState(); + /* check for old-style door graphic/animation modifications */ - /* simulate releasing mouse button over last gadget, if still pressed */ - if (button_status) - HandleGadgets(-1, -1, 0); + if (!door_gfx_redefined) + { + if (door->anim_mode & ANIM_STATIC_PANEL) + { + door->panel.step_xoffset = 0; + door->panel.step_yoffset = 0; + } - UnmapAllGadgets(); + if (door->anim_mode & (ANIM_HORIZONTAL | ANIM_VERTICAL)) + { + struct GraphicInfo *g_part_1 = &graphic_info[part_1]; + struct GraphicInfo *g_part_2 = &graphic_info[part_2]; + int num_door_steps, num_panel_steps; - /* draw released gadget before proceeding */ - // BackToFront(); + /* remove door part graphics other than the two default wings */ -#if 0 - if (old_door_state & DOOR_OPEN_1 && !global.use_envelope_request) -#else - if (old_door_state & DOOR_OPEN_1) -#endif - { -#if 1 - if (!global.use_envelope_request) - CloseDoor(DOOR_CLOSE_1); -#else - CloseDoor(DOOR_CLOSE_1); -#endif + for (j = 0; door_part_controls[j].door_token != -1; j++) + { + struct DoorPartControlInfo *dpc = &door_part_controls[j]; + struct GraphicInfo *g = &graphic_info[dpc->graphic]; - /* save old door content */ - BlitBitmap(bitmap_db_door, bitmap_db_door, - DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, - DOOR_GFX_PAGEX2, DOOR_GFX_PAGEY1); - } + if (dpc->graphic >= part_3 && + dpc->graphic <= part_8) + g->bitmap = NULL; + } -#if 1 - SetDoorBackgroundImage(IMG_BACKGROUND_DOOR); -#endif + /* set graphics and screen positions of the default wings */ - SetDrawBackgroundMask(REDRAW_FIELD | REDRAW_DOOR_1); + g_part_1->width = door_rect->width; + g_part_1->height = door_rect->height; + g_part_2->width = door_rect->width; + g_part_2->height = door_rect->height; + g_part_2->src_x = door_rect->width; + g_part_2->src_y = g_part_1->src_y; - /* clear door drawing field */ - DrawBackground(DX, DY, DXSIZE, DYSIZE); + door->part_2.x = door->part_1.x; + door->part_2.y = door->part_1.y; - /* force DOOR font inside door area */ - game_status = GAME_MODE_PSEUDO_DOOR; + if (door->width != -1) + { + g_part_1->width = door->width; + g_part_2->width = door->width; - /* write text for request */ - for (text_ptr = text, ty = 0; ty < MAX_REQUEST_LINES; ty++) - { - char text_line[max_request_line_len + 1]; - int tx, tl, tc = 0; + // special treatment for graphics and screen position of right wing + g_part_2->src_x += door_rect->width - door->width; + door->part_2.x += door_rect->width - door->width; + } - if (!*text_ptr) - break; - - for (tl = 0, tx = 0; tx < max_request_line_len; tl++, tx++) - { - tc = *(text_ptr + tx); - if (!tc || tc == ' ') - break; - } + if (door->height != -1) + { + g_part_1->height = door->height; + g_part_2->height = door->height; - if (!tl) - { - text_ptr++; - ty--; - continue; - } + // special treatment for graphics and screen position of bottom wing + g_part_2->src_y += door_rect->height - door->height; + door->part_2.y += door_rect->height - door->height; + } - strncpy(text_line, text_ptr, tl); - text_line[tl] = 0; + /* set animation delays for the default wings and panels */ - DrawText(DX + (DXSIZE - tl * getFontWidth(font_nr)) / 2, - DY + 8 + ty * (getFontHeight(font_nr) + 2), - text_line, font_nr); + door->part_1.step_delay = door->step_delay; + door->part_2.step_delay = door->step_delay; + door->panel.step_delay = door->step_delay; - text_ptr += tl + (tc == ' ' ? 1 : 0); - } + /* set animation draw order for the default wings */ - game_status = last_game_status; /* restore current game status */ + door->part_1.sort_priority = 2; /* draw left wing over ... */ + door->part_2.sort_priority = 1; /* ... right wing */ -#if 1 - if (global.use_envelope_request) - { - /* !!! TMP !!! */ - FreeToolButtons(); - CreateToolButtons(); - } -#endif + /* set animation draw offset for the default wings */ - if (req_state & REQ_ASK) - { - MapGadget(tool_gadget[TOOL_CTRL_ID_YES]); - MapGadget(tool_gadget[TOOL_CTRL_ID_NO]); - } - else if (req_state & REQ_CONFIRM) - { - MapGadget(tool_gadget[TOOL_CTRL_ID_CONFIRM]); - } - else if (req_state & REQ_PLAYER) - { - MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_1]); - MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_2]); - MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_3]); - MapGadget(tool_gadget[TOOL_CTRL_ID_PLAYER_4]); - } + if (door->anim_mode & ANIM_HORIZONTAL) + { + door->part_1.step_xoffset = door->step_offset; + door->part_1.step_yoffset = 0; + door->part_2.step_xoffset = door->step_offset * -1; + door->part_2.step_yoffset = 0; - /* copy request gadgets to door backbuffer */ - BlitBitmap(drawto, bitmap_db_door, - DX, DY, DXSIZE, DYSIZE, - DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1); + num_door_steps = g_part_1->width / door->step_offset; + } + else // ANIM_VERTICAL + { + door->part_1.step_xoffset = 0; + door->part_1.step_yoffset = door->step_offset; + door->part_2.step_xoffset = 0; + door->part_2.step_yoffset = door->step_offset * -1; -#if 1 - if (global.use_envelope_request) - { - ShowEnvelopeRequest(text, ACTION_OPENING); + num_door_steps = g_part_1->height / door->step_offset; + } - for (i = 0; i < NUM_TOOL_BUTTONS; i++) - { - if ((req_state & REQ_ASK && (i == TOOL_CTRL_ID_YES || - i == TOOL_CTRL_ID_NO)) || - (req_state & REQ_CONFIRM && i == TOOL_CTRL_ID_CONFIRM) || - (req_state & REQ_PLAYER && (i == TOOL_CTRL_ID_PLAYER_1 && - i == TOOL_CTRL_ID_PLAYER_2 && - i == TOOL_CTRL_ID_PLAYER_3 && - i == TOOL_CTRL_ID_PLAYER_4))) - { - int x = tool_gadget[i]->x + dDX; - int y = tool_gadget[i]->y + dDY; + /* set animation draw offset for the default panels */ - ModifyGadget(tool_gadget[i], GDI_X, x, GDI_Y, y, GDI_END); + if (door->step_offset > 1) + { + num_panel_steps = 2 * door_rect->height / door->step_offset; + door->panel.start_step = num_panel_steps - num_door_steps; + } + else + { + num_panel_steps = door_rect->height / door->step_offset; + door->panel.start_step = num_panel_steps - num_door_steps / 2; + door->panel.step_delay *= 2; + } } } } -#endif +} -#if 1 - if (!global.use_envelope_request) - OpenDoor(DOOR_OPEN_1); -#else - OpenDoor(DOOR_OPEN_1); -#endif +void InitDoors() +{ + int i; - if (!(req_state & REQUEST_WAIT_FOR_INPUT)) + for (i = 0; door_part_controls[i].door_token != -1; i++) { - if (game_status == GAME_MODE_PLAYING) - { - SetPanelBackground(); - SetDrawBackgroundMask(REDRAW_DOOR_1); - } - else + struct DoorPartControlInfo *dpc = &door_part_controls[i]; + struct DoorPartOrderInfo *dpo = &door_part_order[i]; + + /* initialize "start_step_opening" and "start_step_closing", if needed */ + if (dpc->pos->start_step_opening == 0 && + dpc->pos->start_step_closing == 0) { - SetDrawBackgroundMask(REDRAW_FIELD); + // dpc->pos->start_step_opening = dpc->pos->start_step; + dpc->pos->start_step_closing = dpc->pos->start_step; } - return FALSE; + /* fill structure for door part draw order (sorted below) */ + dpo->nr = i; + dpo->sort_priority = dpc->pos->sort_priority; } -#if 1 - if (game_status != GAME_MODE_MAIN && !global.use_envelope_request) - InitAnimation(); -#else - if (game_status != GAME_MODE_MAIN) - InitAnimation(); -#endif - - button_status = MB_RELEASED; - - request_gadget_id = -1; - - SetDrawBackgroundMask(REDRAW_FIELD | REDRAW_DOOR_1); + /* sort door part controls according to sort_priority and graphic number */ + qsort(door_part_order, MAX_DOOR_PARTS, + sizeof(struct DoorPartOrderInfo), compareDoorPartOrderInfo); +} - while (result < 0) +unsigned int OpenDoor(unsigned int door_state) +{ + if (door_state & DOOR_COPY_BACK) { - if (PendingEvent()) - { - Event event; + if (door_state & DOOR_OPEN_1) + BlitBitmap(bitmap_db_door_1, bitmap_db_door_1, + 1 * DXSIZE, 0, DXSIZE, DYSIZE, 0 * DXSIZE, 0); - NextEvent(&event); + if (door_state & DOOR_OPEN_2) + BlitBitmap(bitmap_db_door_2, bitmap_db_door_2, + 1 * VXSIZE, 0, VXSIZE, VYSIZE, 0 * VXSIZE, 0); - switch (event.type) - { - case EVENT_BUTTONPRESS: - case EVENT_BUTTONRELEASE: - case EVENT_MOTIONNOTIFY: - { - if (event.type == EVENT_MOTIONNOTIFY) - { - if (!PointerInWindow(window)) - continue; /* window and pointer are on different screens */ + door_state &= ~DOOR_COPY_BACK; + } - if (!button_status) - continue; + return MoveDoor(door_state); +} - motion_status = TRUE; - mx = ((MotionEvent *) &event)->x; - my = ((MotionEvent *) &event)->y; - } - else - { - motion_status = FALSE; - mx = ((ButtonEvent *) &event)->x; - my = ((ButtonEvent *) &event)->y; - if (event.type == EVENT_BUTTONPRESS) - button_status = ((ButtonEvent *) &event)->button; - else - button_status = MB_RELEASED; - } +unsigned int CloseDoor(unsigned int door_state) +{ + unsigned int old_door_state = GetDoorState(); - /* this sets 'request_gadget_id' */ - HandleGadgets(mx, my, button_status); + if (!(door_state & DOOR_NO_COPY_BACK)) + { + if (old_door_state & DOOR_OPEN_1) + BlitBitmap(backbuffer, bitmap_db_door_1, + DX, DY, DXSIZE, DYSIZE, 0, 0); - switch (request_gadget_id) - { - case TOOL_CTRL_ID_YES: - result = TRUE; - break; - case TOOL_CTRL_ID_NO: - result = FALSE; - break; - case TOOL_CTRL_ID_CONFIRM: - result = TRUE | FALSE; - break; + if (old_door_state & DOOR_OPEN_2) + BlitBitmap(backbuffer, bitmap_db_door_2, + VX, VY, VXSIZE, VYSIZE, 0, 0); - case TOOL_CTRL_ID_PLAYER_1: - result = 1; - break; - case TOOL_CTRL_ID_PLAYER_2: - result = 2; - break; - case TOOL_CTRL_ID_PLAYER_3: - result = 3; - break; - case TOOL_CTRL_ID_PLAYER_4: - result = 4; - break; + door_state &= ~DOOR_NO_COPY_BACK; + } - default: - break; - } + return MoveDoor(door_state); +} - break; - } +unsigned int GetDoorState() +{ + return MoveDoor(DOOR_GET_STATE); +} - case EVENT_KEYPRESS: - switch (GetEventKey((KeyEvent *)&event, TRUE)) - { - case KSYM_space: - if (req_state & REQ_CONFIRM) - result = 1; - break; +unsigned int SetDoorState(unsigned int door_state) +{ + return MoveDoor(door_state | DOOR_SET_STATE); +} - case KSYM_Return: - result = 1; - break; +int euclid(int a, int b) +{ + return (b ? euclid(b, a % b) : a); +} - case KSYM_Escape: -#if defined(TARGET_SDL2) - case KSYM_Back: -#endif - result = 0; - break; +unsigned int MoveDoor(unsigned int door_state) +{ + struct Rect door_rect_list[] = + { + { DX, DY, DXSIZE, DYSIZE }, + { VX, VY, VXSIZE, VYSIZE } + }; + static int door1 = DOOR_OPEN_1; + static int door2 = DOOR_CLOSE_2; + unsigned int door_delay = 0; + unsigned int door_delay_value; + int i; - default: - break; - } + if (door_1.width < 0 || door_1.width > DXSIZE) + door_1.width = DXSIZE; + if (door_1.height < 0 || door_1.height > DYSIZE) + door_1.height = DYSIZE; + if (door_2.width < 0 || door_2.width > VXSIZE) + door_2.width = VXSIZE; + if (door_2.height < 0 || door_2.height > VYSIZE) + door_2.height = VYSIZE; - if (req_state & REQ_PLAYER) - result = 0; - break; + if (door_state == DOOR_GET_STATE) + return (door1 | door2); - case EVENT_KEYRELEASE: - ClearPlayerAction(); - break; + 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; - default: - HandleOtherEvents(&event); - break; - } - } - else if (AnyJoystickButton() == JOY_BUTTON_NEW_PRESSED) - { - int joy = AnyJoystick(); + return (door1 | door2); + } - if (joy & JOY_BUTTON_1) - result = 1; - else if (joy & JOY_BUTTON_2) - result = 0; - } + if (!(door_state & DOOR_FORCE_REDRAW)) + { + 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) + door_state &= ~DOOR_CLOSE_1; + if (door2 == DOOR_OPEN_2 && door_state & DOOR_OPEN_2) + door_state &= ~DOOR_OPEN_2; + else if (door2 == DOOR_CLOSE_2 && door_state & DOOR_CLOSE_2) + door_state &= ~DOOR_CLOSE_2; + } -#if 1 + if (global.autoplay_leveldir) + { + door_state |= DOOR_NO_DELAY; + door_state &= ~DOOR_CLOSE_ALL; + } - if (game_status == GAME_MODE_PLAYING && local_player->LevelSolved_GameEnd) - { - HandleGameActions(); - } - else + if (game_status == GAME_MODE_EDITOR) + door_state |= DOOR_NO_DELAY; + + if (door_state & DOOR_ACTION) + { + boolean door_panel_drawn[NUM_DOORS]; + boolean panel_has_doors[NUM_DOORS]; + boolean door_part_skip[MAX_DOOR_PARTS]; + boolean door_part_done[MAX_DOOR_PARTS]; + boolean door_part_done_all; + int num_steps[MAX_DOOR_PARTS]; + int max_move_delay = 0; // delay for complete animations of all doors + int max_step_delay = 0; // delay (ms) between two animation frames + int num_move_steps = 0; // number of animation steps for all doors + int current_move_delay = 0; + int k; + + for (i = 0; i < NUM_DOORS; i++) + panel_has_doors[i] = FALSE; + + for (i = 0; i < MAX_DOOR_PARTS; i++) { - DoAnimation(); + struct DoorPartControlInfo *dpc = &door_part_controls[i]; + struct GraphicInfo *g = &graphic_info[dpc->graphic]; + int door_token = dpc->door_token; - if (!PendingEvent()) /* delay only if no pending events */ - Delay(10); + door_part_done[i] = FALSE; + door_part_skip[i] = (!(door_state & door_token) || + !g->bitmap); } -#if 1 - game_status = GAME_MODE_PSEUDO_DOOR; -#endif + for (i = 0; i < MAX_DOOR_PARTS; i++) + { + int nr = door_part_order[i].nr; + struct DoorPartControlInfo *dpc = &door_part_controls[nr]; + struct DoorPartPosInfo *pos = dpc->pos; + struct GraphicInfo *g = &graphic_info[dpc->graphic]; + int door_token = dpc->door_token; + int door_index = DOOR_INDEX_FROM_TOKEN(door_token); + boolean is_panel = DOOR_PART_IS_PANEL(nr); + int step_xoffset = ABS(pos->step_xoffset); + int step_yoffset = ABS(pos->step_yoffset); + int step_delay = pos->step_delay; + int current_door_state = door_state & door_token; + boolean door_opening = ((current_door_state & DOOR_OPEN) != 0); + boolean door_closing = ((current_door_state & DOOR_CLOSE) != 0); + boolean part_opening = (is_panel ? door_closing : door_opening); + int start_step = (part_opening ? pos->start_step_opening : + pos->start_step_closing); + float move_xsize = (step_xoffset ? g->width : 0); + float move_ysize = (step_yoffset ? g->height : 0); + int move_xsteps = (step_xoffset ? ceil(move_xsize / step_xoffset) : 0); + int move_ysteps = (step_yoffset ? ceil(move_ysize / step_yoffset) : 0); + int move_steps = (move_xsteps && move_ysteps ? + MIN(move_xsteps, move_ysteps) : + move_xsteps ? move_xsteps : move_ysteps) - start_step; + int move_delay = move_steps * step_delay; - BackToFront(); + if (door_part_skip[nr]) + continue; -#if 1 - game_status = last_game_status; /* restore current game status */ -#endif + if (!is_panel) + panel_has_doors[door_index] = TRUE; -#else + max_move_delay = MAX(max_move_delay, move_delay); + max_step_delay = (max_step_delay == 0 ? step_delay : + euclid(max_step_delay, step_delay)); + num_steps[nr] = move_steps; + } - DoAnimation(); + num_move_steps = max_move_delay / max_step_delay; -#if 1 - if (!PendingEvent()) /* delay only if no pending events */ - Delay(10); -#else - /* don't eat all CPU time */ - Delay(10); -#endif + door_delay_value = max_step_delay; -#endif - } + for (k = 0; k < num_move_steps; k++) + { + door_part_done_all = TRUE; - if (game_status != GAME_MODE_MAIN) - StopAnimation(); + for (i = 0; i < NUM_DOORS; i++) + door_panel_drawn[i] = FALSE; - UnmapToolButtons(); + for (i = 0; i < MAX_DOOR_PARTS; i++) + { + int nr = door_part_order[i].nr; + struct DoorPartControlInfo *dpc = &door_part_controls[nr]; + struct DoorPartPosInfo *pos = dpc->pos; + struct GraphicInfo *g = &graphic_info[dpc->graphic]; + int door_token = dpc->door_token; + int door_index = DOOR_INDEX_FROM_TOKEN(door_token); + boolean is_panel = DOOR_PART_IS_PANEL(nr); + struct Rect *door_rect = &door_rect_list[door_index]; + Bitmap *bitmap_db_door = (door_token == DOOR_1 ? bitmap_db_door_1 : + bitmap_db_door_2); + Bitmap *bitmap = (is_panel ? bitmap_db_door : g->bitmap); + int current_door_state = door_state & door_token; + boolean door_opening = ((current_door_state & DOOR_OPEN) != 0); + boolean door_closing = !door_opening; + boolean part_opening = (is_panel ? door_closing : door_opening); + boolean part_closing = !part_opening; + int start_step = (part_opening ? pos->start_step_opening : + pos->start_step_closing); + int step_delay = pos->step_delay; + int step_factor = step_delay / max_step_delay; + int k1 = (step_factor ? k / step_factor + 1 : k); + int k2 = (part_opening ? k1 + start_step : num_steps[nr] - k1); + int kk = (k2 < 0 ? 0 : k2); + int src_x, src_y, src_xx, src_yy; + int dst_x, dst_y, dst_xx, dst_yy; + int width, height; -#if 1 - if (global.use_envelope_request) - ShowEnvelopeRequest(text, ACTION_CLOSING); -#endif + if (door_part_skip[nr]) + continue; -#if 1 - if (!(req_state & REQ_STAY_OPEN) && !global.use_envelope_request) -#else - if (!(req_state & REQ_STAY_OPEN)) -#endif - { - CloseDoor(DOOR_CLOSE_1); + if (!(door_state & door_token)) + continue; - if (((old_door_state & DOOR_OPEN_1) && !(req_state & REQ_STAY_CLOSED)) || - (req_state & REQ_REOPEN)) - OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK); - } + if (!g->bitmap) + continue; - RemapAllGadgets(); + // draw door panel - if (game_status == GAME_MODE_PLAYING) - { - SetPanelBackground(); - SetDrawBackgroundMask(REDRAW_DOOR_1); - } - else - { - SetDrawBackgroundMask(REDRAW_FIELD); - } + if (!door_panel_drawn[door_index]) + { + ClearRectangle(drawto, door_rect->x, door_rect->y, + door_rect->width, door_rect->height); -#if defined(NETWORK_AVALIABLE) - /* continue network game after request */ - if (options.network && - game_status == GAME_MODE_PLAYING && - req_state & REQUEST_WAIT_FOR_INPUT) - SendToServer_ContinuePlaying(); -#endif + door_panel_drawn[door_index] = TRUE; + } - /* restore deactivated drawing when quick-loading level tape recording */ - if (tape.playing && tape.deactivate_display) - TapeDeactivateDisplayOn(); + // draw opening or closing door parts - return result; -} + if (pos->step_xoffset < 0) // door part on right side + { + src_xx = 0; + dst_xx = pos->x + ABS(kk * pos->step_xoffset); + width = g->width; -#endif + if (dst_xx + width > door_rect->width) + width = door_rect->width - dst_xx; + } + else // door part on left side + { + src_xx = 0; + dst_xx = pos->x - kk * pos->step_xoffset; -static int compareDoorPartOrderInfo(const void *object1, const void *object2) -{ - const struct DoorPartOrderInfo *dpo1 = (struct DoorPartOrderInfo *)object1; - const struct DoorPartOrderInfo *dpo2 = (struct DoorPartOrderInfo *)object2; - int compare_result; - - if (dpo1->sort_priority != dpo2->sort_priority) - compare_result = dpo1->sort_priority - dpo2->sort_priority; - else - compare_result = dpo1->nr - dpo2->nr; - - return compare_result; -} - -void InitGraphicCompatibilityInfo_Doors() -{ - struct - { - int door_token; - int part_1, part_8; - struct DoorInfo *door; - } - doors[] = - { - { DOOR_1, IMG_DOOR_1_GFX_PART_1, IMG_DOOR_1_GFX_PART_8, &door_1 }, - { DOOR_2, IMG_DOOR_2_GFX_PART_1, IMG_DOOR_2_GFX_PART_8, &door_2 }, - - { -1, -1, -1, NULL } - }; - struct Rect door_rect_list[] = - { - { DX, DY, DXSIZE, DYSIZE }, - { VX, VY, VXSIZE, VYSIZE } - }; - int i, j; - - for (i = 0; doors[i].door_token != -1; i++) - { - int door_token = doors[i].door_token; - int door_index = DOOR_INDEX_FROM_TOKEN(door_token); - int part_1 = doors[i].part_1; - int part_8 = doors[i].part_8; - int part_2 = part_1 + 1; - int part_3 = part_1 + 2; - struct DoorInfo *door = doors[i].door; - struct Rect *door_rect = &door_rect_list[door_index]; - boolean door_gfx_redefined = FALSE; - - /* check if any door part graphic definitions have been redefined */ - - for (j = 0; door_part_controls[j].door_token != -1; j++) - { - struct DoorPartControlInfo *dpc = &door_part_controls[j]; - struct FileInfo *fi = getImageListEntryFromImageID(dpc->graphic); - - if (dpc->door_token == door_token && fi->redefined) - door_gfx_redefined = TRUE; - } - - /* check for old-style door graphic/animation modifications */ - - if (!door_gfx_redefined) - { - if (door->anim_mode & ANIM_STATIC_PANEL) - { - door->panel.step_xoffset = 0; - door->panel.step_yoffset = 0; - } + if (dst_xx < 0) + { + src_xx = ABS(dst_xx); + dst_xx = 0; + } - if (door->anim_mode & (ANIM_HORIZONTAL | ANIM_VERTICAL)) - { - struct GraphicInfo *g_part_1 = &graphic_info[part_1]; - struct GraphicInfo *g_part_2 = &graphic_info[part_2]; - int num_door_steps, num_panel_steps; + width = g->width - src_xx; - /* remove door part graphics other than the two default wings */ + // printf("::: k == %d [%d] \n", k, start_step); + } - for (j = 0; door_part_controls[j].door_token != -1; j++) + if (pos->step_yoffset < 0) // door part on bottom side { - struct DoorPartControlInfo *dpc = &door_part_controls[j]; - struct GraphicInfo *g = &graphic_info[dpc->graphic]; + src_yy = 0; + dst_yy = pos->y + ABS(kk * pos->step_yoffset); + height = g->height; - if (dpc->graphic >= part_3 && - dpc->graphic <= part_8) - g->bitmap = NULL; + if (dst_yy + height > door_rect->height) + height = door_rect->height - dst_yy; } + else // door part on top side + { + src_yy = 0; + dst_yy = pos->y - kk * pos->step_yoffset; - /* set graphics and screen positions of the default wings */ - - g_part_1->width = door_rect->width; - g_part_1->height = door_rect->height; - g_part_2->width = door_rect->width; - g_part_2->height = door_rect->height; - g_part_2->src_x = door_rect->width; - g_part_2->src_y = g_part_1->src_y; + if (dst_yy < 0) + { + src_yy = ABS(dst_yy); + dst_yy = 0; + } - door->part_2.x = door->part_1.x; - door->part_2.y = door->part_1.y; + height = g->height - src_yy; + } - if (door->width != -1) + if (is_panel) { - g_part_1->width = door->width; - g_part_2->width = door->width; - - // special treatment for graphics and screen position of right wing - g_part_2->src_x += door_rect->width - door->width; - door->part_2.x += door_rect->width - door->width; + src_x = src_xx; + src_y = src_yy; } - - if (door->height != -1) + else { - g_part_1->height = door->height; - g_part_2->height = door->height; - - // special treatment for graphics and screen position of bottom wing - g_part_2->src_y += door_rect->height - door->height; - door->part_2.y += door_rect->height - door->height; + src_x = g->src_x + src_xx; + src_y = g->src_y + src_yy; } - /* set animation delays for the default wings and panels */ - - door->part_1.step_delay = door->step_delay; - door->part_2.step_delay = door->step_delay; - door->panel.step_delay = door->step_delay; + dst_x = door_rect->x + dst_xx; + dst_y = door_rect->y + dst_yy; - /* set animation draw order for the default wings */ + if (width >= 0 && width <= g->width && + height >= 0 && height <= g->height) + { + if (is_panel || !pos->draw_masked) + BlitBitmap(bitmap, drawto, src_x, src_y, width, height, + dst_x, dst_y); + else + BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, + dst_x, dst_y); + } - door->part_1.sort_priority = 2; /* draw left wing over ... */ - door->part_2.sort_priority = 1; /* ... right wing */ + redraw_mask |= REDRAW_DOOR_FROM_TOKEN(door_token); - /* set animation draw offset for the default wings */ + if ((part_opening && (width < 0 || height < 0)) || + (part_closing && (width >= g->width && height >= g->height))) + door_part_done[nr] = TRUE; - if (door->anim_mode & ANIM_HORIZONTAL) - { - door->part_1.step_xoffset = door->step_offset; - door->part_1.step_yoffset = 0; - door->part_2.step_xoffset = door->step_offset * -1; - door->part_2.step_yoffset = 0; + // continue door part animations, but not panel after door has closed + if (!door_part_done[nr] && + !(is_panel && door_closing && panel_has_doors[door_index])) + door_part_done_all = FALSE; + } - num_door_steps = g_part_1->width / door->step_offset; - } - else // ANIM_VERTICAL - { - door->part_1.step_xoffset = 0; - door->part_1.step_yoffset = door->step_offset; - door->part_2.step_xoffset = 0; - door->part_2.step_yoffset = door->step_offset * -1; + if (!(door_state & DOOR_NO_DELAY)) + { + BackToFront(); - num_door_steps = g_part_1->height / door->step_offset; - } + if (game_status == GAME_MODE_MAIN) + DoAnimation(); - /* set animation draw offset for the default panels */ + WaitUntilDelayReached(&door_delay, door_delay_value); - if (door->step_offset > 1) - { - num_panel_steps = 2 * door_rect->height / door->step_offset; - door->panel.start_step = num_panel_steps - num_door_steps; - } - else - { - num_panel_steps = door_rect->height / door->step_offset; - door->panel.start_step = num_panel_steps - num_door_steps / 2; - door->panel.step_delay *= 2; - } + current_move_delay += max_step_delay; } + + if (door_part_done_all) + break; } } -} - -void InitDoors() -{ - int i; - for (i = 0; door_part_controls[i].door_token != -1; i++) - { - struct DoorPartControlInfo *dpc = &door_part_controls[i]; - struct DoorPartOrderInfo *dpo = &door_part_order[i]; + if (door_state & DOOR_ACTION_1) + door1 = door_state & DOOR_ACTION_1; + if (door_state & DOOR_ACTION_2) + door2 = door_state & DOOR_ACTION_2; - /* initialize "start_step_opening" and "start_step_closing", if needed */ - if (dpc->pos->start_step_opening == 0 && - dpc->pos->start_step_closing == 0) - { - // dpc->pos->start_step_opening = dpc->pos->start_step; - dpc->pos->start_step_closing = dpc->pos->start_step; - } + return (door1 | door2); +} - /* fill structure for door part draw order (sorted below) */ - dpo->nr = i; - dpo->sort_priority = dpc->pos->sort_priority; +void DrawSpecialEditorDoor() +{ + struct GraphicInfo *gfx1 = &graphic_info[IMG_DOOR_2_TOP_BORDER_CORRECTION]; + int top_border_width = gfx1->width; + int top_border_height = gfx1->height; + int outer_border = viewport.door_2[GAME_MODE_EDITOR].border_size; + int ex = EX - outer_border; + int ey = EY - outer_border; + int vy = VY - outer_border; + int exsize = EXSIZE + 2 * outer_border; -#if 0 - struct DoorPartPosInfo *pos = dpc->pos; + CloseDoor(DOOR_CLOSE_2); - printf(":0: step_xoffset == %d, step_yoffset == %d\n", - pos->step_xoffset, pos->step_yoffset); -#endif - } + /* draw bigger level editor toolbox window */ + BlitBitmap(gfx1->bitmap, drawto, gfx1->src_x, gfx1->src_y, + top_border_width, top_border_height, ex, ey - top_border_height); + BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto, ex, vy, + exsize, EYSIZE - VYSIZE + outer_border, ex, ey); - /* sort door part controls according to sort_priority and graphic number */ - qsort(door_part_order, MAX_DOOR_PARTS, - sizeof(struct DoorPartOrderInfo), compareDoorPartOrderInfo); + redraw_mask |= REDRAW_ALL; } -unsigned int OpenDoor(unsigned int door_state) +void UndrawSpecialEditorDoor() { - if (door_state & DOOR_COPY_BACK) - { -#if 1 - if (door_state & DOOR_OPEN_1) - BlitBitmap(bitmap_db_door_1, bitmap_db_door_1, - 1 * DXSIZE, 0, DXSIZE, DYSIZE, 0 * DXSIZE, 0); - - if (door_state & DOOR_OPEN_2) - BlitBitmap(bitmap_db_door_2, bitmap_db_door_2, - 1 * VXSIZE, 0, VXSIZE, VYSIZE, 0 * VXSIZE, 0); -#else - if (door_state & DOOR_OPEN_1) - BlitBitmap(bitmap_db_door, bitmap_db_door, - DOOR_GFX_PAGEX2, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, - DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1); - - if (door_state & DOOR_OPEN_2) - BlitBitmap(bitmap_db_door, bitmap_db_door, - DOOR_GFX_PAGEX2, DOOR_GFX_PAGEY2, VXSIZE, VYSIZE, - DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY2); -#endif + struct GraphicInfo *gfx1 = &graphic_info[IMG_DOOR_2_TOP_BORDER_CORRECTION]; + int top_border_width = gfx1->width; + int top_border_height = gfx1->height; + int outer_border = viewport.door_2[GAME_MODE_EDITOR].border_size; + int ex = EX - outer_border; + int ey = EY - outer_border; + int ey_top = ey - top_border_height; + int exsize = EXSIZE + 2 * outer_border; + int eysize = EYSIZE + 2 * outer_border; - door_state &= ~DOOR_COPY_BACK; + /* draw normal tape recorder window */ + if (graphic_info[IMG_GLOBAL_BORDER].bitmap) + { + BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto, + ex, ey_top, top_border_width, top_border_height, + ex, ey_top); + BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto, + ex, ey, exsize, eysize, ex, ey); + } + else + { + // if screen background is set to "[NONE]", clear editor toolbox window + ClearRectangle(drawto, ex, ey_top, top_border_width, top_border_height); + ClearRectangle(drawto, ex, ey, exsize, eysize); } - return MoveDoor(door_state); + redraw_mask |= REDRAW_ALL; } -unsigned int CloseDoor(unsigned int door_state) + +/* ---------- new tool button stuff ---------------------------------------- */ + +static struct { - unsigned int old_door_state = GetDoorState(); + int graphic; + struct TextPosInfo *pos; + int gadget_id; + char *infotext; +} toolbutton_info[NUM_TOOL_BUTTONS] = +{ + { + IMG_REQUEST_BUTTON_GFX_YES, &request.button.yes, + TOOL_CTRL_ID_YES, "yes" + }, + { + IMG_REQUEST_BUTTON_GFX_NO, &request.button.no, + TOOL_CTRL_ID_NO, "no" + }, + { + IMG_REQUEST_BUTTON_GFX_CONFIRM, &request.button.confirm, + TOOL_CTRL_ID_CONFIRM, "confirm" + }, + { + IMG_REQUEST_BUTTON_GFX_PLAYER_1, &request.button.player_1, + TOOL_CTRL_ID_PLAYER_1, "player 1" + }, + { + IMG_REQUEST_BUTTON_GFX_PLAYER_2, &request.button.player_2, + TOOL_CTRL_ID_PLAYER_2, "player 2" + }, + { + IMG_REQUEST_BUTTON_GFX_PLAYER_3, &request.button.player_3, + TOOL_CTRL_ID_PLAYER_3, "player 3" + }, + { + IMG_REQUEST_BUTTON_GFX_PLAYER_4, &request.button.player_4, + TOOL_CTRL_ID_PLAYER_4, "player 4" + } +}; - if (!(door_state & DOOR_NO_COPY_BACK)) +void CreateToolButtons() +{ + int i; + + for (i = 0; i < NUM_TOOL_BUTTONS; i++) { -#if 1 - if (old_door_state & DOOR_OPEN_1) - BlitBitmap(backbuffer, bitmap_db_door_1, - DX, DY, DXSIZE, DYSIZE, 0, 0); + struct GraphicInfo *gfx = &graphic_info[toolbutton_info[i].graphic]; + struct TextPosInfo *pos = toolbutton_info[i].pos; + struct GadgetInfo *gi; + Bitmap *deco_bitmap = None; + int deco_x = 0, deco_y = 0, deco_xpos = 0, deco_ypos = 0; + unsigned int event_mask = GD_EVENT_RELEASED; + int dx = DX; + int dy = DY; + int gd_x = gfx->src_x; + int gd_y = gfx->src_y; + int gd_xp = gfx->src_x + gfx->pressed_xoffset; + int gd_yp = gfx->src_y + gfx->pressed_yoffset; + int id = i; - if (old_door_state & DOOR_OPEN_2) - BlitBitmap(backbuffer, bitmap_db_door_2, - VX, VY, VXSIZE, VYSIZE, 0, 0); -#else - if (old_door_state & DOOR_OPEN_1) - BlitBitmap(backbuffer, bitmap_db_door, - DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1); + if (global.use_envelope_request) + setRequestPosition(&dx, &dy, TRUE); - if (old_door_state & DOOR_OPEN_2) - BlitBitmap(backbuffer, bitmap_db_door, - VX, VY, VXSIZE, VYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY2); -#endif + if (id >= TOOL_CTRL_ID_PLAYER_1 && id <= TOOL_CTRL_ID_PLAYER_4) + { + int player_nr = id - TOOL_CTRL_ID_PLAYER_1; - door_state &= ~DOOR_NO_COPY_BACK; - } + getSizedGraphicSource(PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0, + pos->size, &deco_bitmap, &deco_x, &deco_y); + deco_xpos = (gfx->width - pos->size) / 2; + deco_ypos = (gfx->height - pos->size) / 2; + } - return MoveDoor(door_state); -} + gi = CreateGadget(GDI_CUSTOM_ID, id, + GDI_INFO_TEXT, toolbutton_info[i].infotext, + GDI_X, dx + GDI_ACTIVE_POS(pos->x), + GDI_Y, dy + GDI_ACTIVE_POS(pos->y), + GDI_WIDTH, gfx->width, + GDI_HEIGHT, gfx->height, + GDI_TYPE, GD_TYPE_NORMAL_BUTTON, + GDI_STATE, GD_BUTTON_UNPRESSED, + GDI_DESIGN_UNPRESSED, gfx->bitmap, gd_x, gd_y, + GDI_DESIGN_PRESSED, gfx->bitmap, gd_xp, gd_yp, + GDI_DECORATION_DESIGN, deco_bitmap, deco_x, deco_y, + GDI_DECORATION_POSITION, deco_xpos, deco_ypos, + GDI_DECORATION_SIZE, pos->size, pos->size, + GDI_DECORATION_SHIFTING, 1, 1, + GDI_DIRECT_DRAW, FALSE, + GDI_EVENT_MASK, event_mask, + GDI_CALLBACK_ACTION, HandleToolButtons, + GDI_END); -unsigned int GetDoorState() -{ - return MoveDoor(DOOR_GET_STATE); + if (gi == NULL) + Error(ERR_EXIT, "cannot create gadget"); + + tool_gadget[id] = gi; + } } -unsigned int SetDoorState(unsigned int door_state) +void FreeToolButtons() { - return MoveDoor(door_state | DOOR_SET_STATE); + int i; + + for (i = 0; i < NUM_TOOL_BUTTONS; i++) + FreeGadget(tool_gadget[i]); } -#if 1 +static void UnmapToolButtons() +{ + int i; -// ========== TEST 1 =========================================================== + for (i = 0; i < NUM_TOOL_BUTTONS; i++) + UnmapGadget(tool_gadget[i]); +} -int euclid(int a, int b) +static void HandleToolButtons(struct GadgetInfo *gi) { - return (b ? euclid(b, a % b) : a); + request_gadget_id = gi->custom_id; } -unsigned int MoveDoor(unsigned int door_state) +static struct Mapping_EM_to_RND_object { -#if 0 - struct XY panel_pos_list[] = - { - { DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1 }, - { DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY2 }, - }; -#endif - struct Rect door_rect_list[] = - { - { DX, DY, DXSIZE, DYSIZE }, - { VX, VY, VXSIZE, VYSIZE } - }; - static int door1 = DOOR_OPEN_1; - static int door2 = DOOR_CLOSE_2; - unsigned int door_delay = 0; - unsigned int door_delay_value; - int i; - -#if 1 - if (door_1.width < 0 || door_1.width > DXSIZE) - door_1.width = DXSIZE; - if (door_1.height < 0 || door_1.height > DYSIZE) - door_1.height = DYSIZE; - if (door_2.width < 0 || door_2.width > VXSIZE) - door_2.width = VXSIZE; - if (door_2.height < 0 || door_2.height > VYSIZE) - door_2.height = VYSIZE; -#endif - - if (door_state == DOOR_GET_STATE) - return (door1 | door2); + int element_em; + boolean is_rnd_to_em_mapping; /* unique mapping EM <-> RND */ + boolean is_backside; /* backside of moving element */ - if (door_state & DOOR_SET_STATE) + int element_rnd; + int action; + int direction; +} +em_object_mapping_list[] = +{ { - 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 (!(door_state & DOOR_FORCE_REDRAW)) + Xblank, TRUE, FALSE, + EL_EMPTY, -1, -1 + }, { - 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) - door_state &= ~DOOR_CLOSE_1; - if (door2 == DOOR_OPEN_2 && door_state & DOOR_OPEN_2) - door_state &= ~DOOR_OPEN_2; - else if (door2 == DOOR_CLOSE_2 && door_state & DOOR_CLOSE_2) - door_state &= ~DOOR_CLOSE_2; - } - -#if 0 - door_delay_value = (door_state & DOOR_ACTION_1 ? door_1.step_delay : - door_2.step_delay); - - if (setup.quick_doors) + Yacid_splash_eB, FALSE, FALSE, + EL_ACID_SPLASH_RIGHT, -1, -1 + }, { - stepsize = 20; /* must be chosen to always draw last frame */ - door_delay_value = 0; - } -#endif + Yacid_splash_wB, FALSE, FALSE, + EL_ACID_SPLASH_LEFT, -1, -1 + }, - if (global.autoplay_leveldir) +#ifdef EM_ENGINE_BAD_ROLL { - door_state |= DOOR_NO_DELAY; - door_state &= ~DOOR_CLOSE_ALL; - } - -#if 1 - if (game_status == GAME_MODE_EDITOR) - door_state |= DOOR_NO_DELAY; -#endif - - if (door_state & DOOR_ACTION) - { - boolean door_panel_drawn[NUM_DOORS]; - boolean panel_has_doors[NUM_DOORS]; - boolean door_part_skip[MAX_DOOR_PARTS]; - boolean door_part_done[MAX_DOOR_PARTS]; - boolean door_part_done_all; - int num_steps[MAX_DOOR_PARTS]; - int max_move_delay = 0; // delay for complete animations of all doors - int max_step_delay = 0; // delay (ms) between two animation frames - int num_move_steps = 0; // number of animation steps for all doors - int current_move_delay = 0; - int k; - - for (i = 0; i < NUM_DOORS; i++) - panel_has_doors[i] = FALSE; - - for (i = 0; i < MAX_DOOR_PARTS; i++) - { - struct DoorPartControlInfo *dpc = &door_part_controls[i]; - struct GraphicInfo *g = &graphic_info[dpc->graphic]; - int door_token = dpc->door_token; - - door_part_done[i] = FALSE; - door_part_skip[i] = (!(door_state & door_token) || - !g->bitmap); - } - -#if 0 - for (i = 0; i < MAX_DOOR_PARTS; i++) - { - struct DoorPartControlInfo *dpc = &door_part_controls[i]; - struct DoorPartPosInfo *pos = dpc->pos; - int start_step = pos->start_step; - - printf("::: ---> %d: start_step == %d [%d]\n", - i, start_step, door_part_done[i]); - } -#endif - - for (i = 0; i < MAX_DOOR_PARTS; i++) - { - int nr = door_part_order[i].nr; - struct DoorPartControlInfo *dpc = &door_part_controls[nr]; - struct DoorPartPosInfo *pos = dpc->pos; - struct GraphicInfo *g = &graphic_info[dpc->graphic]; - int door_token = dpc->door_token; - int door_index = DOOR_INDEX_FROM_TOKEN(door_token); - boolean is_panel = DOOR_PART_IS_PANEL(nr); - int step_xoffset = ABS(pos->step_xoffset); - int step_yoffset = ABS(pos->step_yoffset); - int step_delay = pos->step_delay; - int current_door_state = door_state & door_token; - boolean door_opening = ((current_door_state & DOOR_OPEN) != 0); - boolean door_closing = ((current_door_state & DOOR_CLOSE) != 0); - boolean part_opening = (is_panel ? door_closing : door_opening); - int start_step = (part_opening ? pos->start_step_opening : - pos->start_step_closing); - float move_xsize = (step_xoffset ? g->width : 0); - float move_ysize = (step_yoffset ? g->height : 0); - int move_xsteps = (step_xoffset ? ceil(move_xsize / step_xoffset) : 0); - int move_ysteps = (step_yoffset ? ceil(move_ysize / step_yoffset) : 0); - int move_steps = (move_xsteps && move_ysteps ? - MIN(move_xsteps, move_ysteps) : - move_xsteps ? move_xsteps : move_ysteps) - start_step; - int move_delay = move_steps * step_delay; - - if (door_part_skip[nr]) - continue; - - if (!is_panel) - panel_has_doors[door_index] = TRUE; - - max_move_delay = MAX(max_move_delay, move_delay); - max_step_delay = (max_step_delay == 0 ? step_delay : - euclid(max_step_delay, step_delay)); - num_steps[nr] = move_steps; - -#if 0 -#if 0 - printf("::: %d: move_delay == %d, start_step == %d [%d]\n", - i, move_delay, start_step, door_part_order[i].nr); -#else - if (DOOR_PART_IS_PANEL(i)) - printf("::: %d: move_delay == %d, start_step == %d\n", - i, move_delay, start_step); -#endif -#endif - } - - num_move_steps = max_move_delay / max_step_delay; - - door_delay_value = max_step_delay; - -#if 0 - door_delay_value *= 10; -#endif - -#if 0 - printf("::: num_move_steps == %d, max_move_delay == %d, max_step_delay == %d\n", num_move_steps, max_move_delay, max_step_delay); -#endif - - for (k = 0; k < num_move_steps; k++) - { - door_part_done_all = TRUE; - - for (i = 0; i < NUM_DOORS; i++) - door_panel_drawn[i] = FALSE; - - for (i = 0; i < MAX_DOOR_PARTS; i++) - { - int nr = door_part_order[i].nr; - struct DoorPartControlInfo *dpc = &door_part_controls[nr]; - struct DoorPartPosInfo *pos = dpc->pos; - struct GraphicInfo *g = &graphic_info[dpc->graphic]; - int door_token = dpc->door_token; - int door_index = DOOR_INDEX_FROM_TOKEN(door_token); - boolean is_panel = DOOR_PART_IS_PANEL(nr); -#if 0 - struct XY *panel_pos = &panel_pos_list[door_index]; -#endif - struct Rect *door_rect = &door_rect_list[door_index]; - Bitmap *bitmap_db_door = (door_token == DOOR_1 ? bitmap_db_door_1 : - bitmap_db_door_2); - Bitmap *bitmap = (is_panel ? bitmap_db_door : g->bitmap); - int current_door_state = door_state & door_token; - boolean door_opening = ((current_door_state & DOOR_OPEN) != 0); - boolean door_closing = !door_opening; - boolean part_opening = (is_panel ? door_closing : door_opening); - boolean part_closing = !part_opening; - int start_step = (part_opening ? pos->start_step_opening : - pos->start_step_closing); - int step_delay = pos->step_delay; - int step_factor = step_delay / max_step_delay; - int k1 = (step_factor ? k / step_factor + 1 : k); - int k2 = (part_opening ? k1 + start_step : num_steps[nr] - k1); - int kk = (k2 < 0 ? 0 : k2); - int src_x, src_y, src_xx, src_yy; - int dst_x, dst_y, dst_xx, dst_yy; - int width, height; - -#if 0 - if (k == 0 && is_panel && door_token == DOOR_2) - printf("::: %d, %d\n", g->width, g->height); -#endif - -#if 0 - if (DOOR_PART_IS_PANEL(nr)) - { - int start_step = pos->start_step; - - k2 = (door_closing ? k1 : num_steps[nr] - k1);// - start_step; - kk = (k2 < 0 ? 0 : k2); - } -#endif - -#if 0 - // !!! TEST !!! - if (nr != 16 && nr != 0) - continue; -#endif - -#if 0 - // !!! TEST !!! - if (!is_panel) - continue; -#endif - -#if 1 - if (door_part_skip[nr]) - continue; -#endif - - if (!(door_state & door_token)) - continue; - - if (!g->bitmap) - continue; - -#if 0 - if (current_move_delay % step_delay) - continue; -#endif - - // draw door panel - - if (!door_panel_drawn[door_index]) - { -#if 1 - ClearRectangle(drawto, door_rect->x, door_rect->y, - door_rect->width, door_rect->height); -#else - BlitBitmap(bitmap_db_door, drawto, panel_pos->x, panel_pos->y, - door_rect->width, door_rect->height, - door_rect->x, door_rect->y); -#endif - - door_panel_drawn[door_index] = TRUE; - } - - // draw opening or closing door parts - - if (pos->step_xoffset < 0) // door part on right side - { - src_xx = 0; - dst_xx = pos->x + ABS(kk * pos->step_xoffset); - width = g->width; - - if (dst_xx + width > door_rect->width) - width = door_rect->width - dst_xx; - } - else // door part on left side - { - src_xx = 0; - dst_xx = pos->x - kk * pos->step_xoffset; - - if (dst_xx < 0) - { - src_xx = ABS(dst_xx); - dst_xx = 0; - } - - width = g->width - src_xx; - - // printf("::: k == %d [%d] \n", k, start_step); - } - - if (pos->step_yoffset < 0) // door part on bottom side - { - src_yy = 0; - dst_yy = pos->y + ABS(kk * pos->step_yoffset); - height = g->height; - - if (dst_yy + height > door_rect->height) - height = door_rect->height - dst_yy; - } - else // door part on top side - { - src_yy = 0; - dst_yy = pos->y - kk * pos->step_yoffset; - - if (dst_yy < 0) - { - src_yy = ABS(dst_yy); - dst_yy = 0; - } - - height = g->height - src_yy; - } - - if (is_panel) - { -#if 1 - src_x = src_xx; - src_y = src_yy; -#else - src_x = panel_pos->x + src_xx; - src_y = panel_pos->y + src_yy; -#endif - } - else - { - src_x = g->src_x + src_xx; - src_y = g->src_y + src_yy; - } - - dst_x = door_rect->x + dst_xx; - dst_y = door_rect->y + dst_yy; - -#if 0 - if (DOOR_PART_IS_PANEL(nr)) - { - printf("::: width == %d, height == %d [%d, %d] [%d, %d]\n", - width, height, g->width, g->height, src_x, src_y); - } -#endif - - if (width >= 0 && width <= g->width && - height >= 0 && height <= g->height) - { - if (is_panel || !pos->draw_masked) - BlitBitmap(bitmap, drawto, src_x, src_y, width, height, - dst_x, dst_y); - else - BlitBitmapMasked(bitmap, drawto, src_x, src_y, width, height, - dst_x, dst_y); - } - -#if 0 - if (DOOR_PART_IS_PANEL(nr)) - { - bitmap = bitmap_db_door; - src_x = panel_pos->x + src_xx; - src_y = panel_pos->y + src_yy; - - printf("::: width == %d, height == %d [%d, %d] [%d, %d]\n", - width, height, g->width, g->height, src_x, src_y); - - if (width >= 0 && width <= g->width && - height >= 0 && height <= g->height) - BlitBitmap(bitmap, drawto, src_x, src_y, - width, height, - dst_x, dst_y); - } -#endif - - redraw_mask |= REDRAW_DOOR_FROM_TOKEN(door_token); - -#if 1 - if ((part_opening && (width < 0 || height < 0)) || - (part_closing && (width >= g->width && height >= g->height))) - door_part_done[nr] = TRUE; -#else - if ((door_opening && (width < 0 || height < 0)) || - (door_closing && (width >= g->width && height >= g->height))) - door_part_done[nr] = TRUE; -#endif - -#if 1 - // continue door part animations, but not panel after door has closed - if (!door_part_done[nr] && - !(is_panel && door_closing && panel_has_doors[door_index])) - door_part_done_all = FALSE; -#else - // continue door part animations, but not panel after door has closed - if (!door_part_done[nr] && !(is_panel && door_closing)) - door_part_done_all = FALSE; -#endif - -#if 0 - if (!door_part_done[nr]) - printf("::: k == %d, nr == %d\n", k, nr); -#endif - } - - if (!(door_state & DOOR_NO_DELAY)) - { - BackToFront(); - - if (game_status == GAME_MODE_MAIN) - DoAnimation(); - - WaitUntilDelayReached(&door_delay, door_delay_value); - - current_move_delay += max_step_delay; - } - -#if 0 - door_part_done_all = TRUE; - - for (i = 0; i < MAX_DOOR_PARTS; i++) - if (!door_part_done[i] && - !(DOOR_PART_IS_PANEL(i) && door_closing)) - door_part_done_all = FALSE; -#endif -#if 1 - if (door_part_done_all) - break; -#endif - } - } - - if (door_state & DOOR_ACTION_1) - door1 = door_state & DOOR_ACTION_1; - if (door_state & DOOR_ACTION_2) - door2 = door_state & DOOR_ACTION_2; - -#if 0 - printf("::: DOORS DONE %08x\n", door_state); - Delay(3000); - printf("::: GO!\n"); -#endif - - return (door1 | door2); -} - -#else - -// ========== OLD ============================================================== - -unsigned int MoveDoor(unsigned int door_state) -{ - static int door1 = DOOR_OPEN_1; - static int door2 = DOOR_CLOSE_2; - unsigned int door_delay = 0; - unsigned int door_delay_value; - int stepsize = 1; - -#if 1 - if (door_1.width < 0 || door_1.width > DXSIZE) - door_1.width = DXSIZE; - if (door_1.height < 0 || door_1.height > DYSIZE) - door_1.height = DYSIZE; - if (door_2.width < 0 || door_2.width > VXSIZE) - door_2.width = VXSIZE; - if (door_2.height < 0 || door_2.height > VYSIZE) - door_2.height = VYSIZE; -#endif - - 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 (!(door_state & DOOR_FORCE_REDRAW)) - { - 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) - door_state &= ~DOOR_CLOSE_1; - if (door2 == DOOR_OPEN_2 && door_state & DOOR_OPEN_2) - door_state &= ~DOOR_OPEN_2; - else if (door2 == DOOR_CLOSE_2 && door_state & DOOR_CLOSE_2) - door_state &= ~DOOR_CLOSE_2; - } - - door_delay_value = (door_state & DOOR_ACTION_1 ? door_1.step_delay : - door_2.step_delay); - - // door_delay_value *= 4; // !!! TEST ONLY !!! - - if (setup.quick_doors) - { - stepsize = 20; /* must be chosen to always draw last frame */ - door_delay_value = 0; - } - - if (global.autoplay_leveldir) - { - door_state |= DOOR_NO_DELAY; - door_state &= ~DOOR_CLOSE_ALL; - } - -#if 1 - if (game_status == GAME_MODE_EDITOR) - door_state |= DOOR_NO_DELAY; -#endif - - if (door_state & DOOR_ACTION) - { -#if 1 - struct GraphicInfo *g1_left = &graphic_info[IMG_DOOR_1_WING_LEFT]; - struct GraphicInfo *g1_right = &graphic_info[IMG_DOOR_1_WING_RIGHT]; - struct GraphicInfo *g2_left = &graphic_info[IMG_DOOR_2_WING_LEFT]; - struct GraphicInfo *g2_right = &graphic_info[IMG_DOOR_2_WING_RIGHT]; - int door_1_left_width = g1_left->width; - int door_1_left_height = g1_left->height; - int door_1_right_width = g1_right->width; - int door_1_right_height = g1_right->height; - int door_2_left_width = g2_left->width; - int door_2_left_height = g2_left->height; - int door_2_right_width = g2_right->width; - int door_2_right_height = g2_right->height; - int door_1_width = MAX(door_1_left_width, door_1_right_width); - int door_1_height = MAX(door_1_left_height, door_1_right_height); - int door_2_width = MAX(door_2_left_width, door_2_right_width); - int door_2_height = MAX(door_2_left_height, door_2_right_height); -#endif - boolean handle_door_1 = (door_state & DOOR_ACTION_1); - boolean handle_door_2 = (door_state & DOOR_ACTION_2); - boolean door_1_done = (!handle_door_1); - boolean door_2_done = (!handle_door_2); - boolean door_1_vertical = (door_1.anim_mode & ANIM_VERTICAL); - boolean door_2_vertical = (door_2.anim_mode & ANIM_VERTICAL); -#if 1 -#if 1 - int door_size_1 = (door_1_vertical ? door_1_height : door_1_width); - int door_size_2 = (door_2_vertical ? door_2_height : door_2_width); -#else - int door_size_1 = (door_1_vertical ? DYSIZE : DXSIZE); - int door_size_2 = (door_2_vertical ? VYSIZE : VXSIZE); -#endif -#else - int door_size_1 = (door_1_vertical ? door_1.height : door_1.width); - int door_size_2 = (door_2_vertical ? door_2.height : door_2.width); -#endif - int max_door_size_1 = (door_1_vertical ? DYSIZE : DXSIZE); - int max_door_size_2 = (door_2_vertical ? VYSIZE : VXSIZE); - // int door_size = (handle_door_1 ? door_size_1 : door_size_2); - int door_size = (handle_door_2 ? door_size_2 : door_size_1); - int max_door_size = (handle_door_1 ? max_door_size_1 : max_door_size_2); - int door_skip = max_door_size - door_size; - int end = door_size; - int start = ((door_state & DOOR_NO_DELAY) ? end : 0); - int k; - - if (!(door_state & DOOR_NO_DELAY) && !setup.quick_doors) - { - /* opening door sound has priority over simultaneously closing door */ - if (door_state & (DOOR_OPEN_1 | DOOR_OPEN_2)) - PlayMenuSoundStereo(SND_DOOR_OPENING, SOUND_MIDDLE); - else if (door_state & (DOOR_CLOSE_1 | DOOR_CLOSE_2)) - PlayMenuSoundStereo(SND_DOOR_CLOSING, SOUND_MIDDLE); - } - - for (k = start; k <= end && !(door_1_done && door_2_done); k += stepsize) - { - int x = k; -#if 0 - Bitmap *bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap; - GC gc = bitmap->stored_clip_gc; -#endif - - if (door_state & DOOR_ACTION_1 && - x * door_1.step_offset <= door_size_1) - { - int a = MIN(x * door_1.step_offset, end); - int p = (door_state & DOOR_OPEN_1 ? end - a : a); -#if 1 - int i = p; -#else - int i = p + door_skip; -#endif - -#if 1 - struct GraphicInfo *g_left = &graphic_info[IMG_DOOR_1_WING_LEFT]; - struct GraphicInfo *g_right = &graphic_info[IMG_DOOR_1_WING_RIGHT]; - Bitmap *bm_left = g_left->bitmap; - Bitmap *bm_right = g_right->bitmap; - GC gc_left = bm_left->stored_clip_gc; - GC gc_right = bm_right->stored_clip_gc; -#endif - - int classic_dxsize = 100; - int classic_dysize = 280; - boolean classic_door_1_size = (DXSIZE == classic_dxsize && - DYSIZE == classic_dysize); - - if (door_1.anim_mode & ANIM_STATIC_PANEL) - { - BlitBitmap(bitmap_db_door, drawto, - DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1, - DXSIZE, DYSIZE, DX, DY); - } - else if (x <= a) - { - BlitBitmap(bitmap_db_door, drawto, - DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1 + p / 2, - DXSIZE, DYSIZE - p / 2, DX, DY); - -#if 1 - // printf("::: p == %d\n", p); - ClearRectangle(drawto, DX, DY + DYSIZE - p / 2, DXSIZE, p / 2); -#endif - } - - if (door_1.anim_mode & ANIM_HORIZONTAL && x <= DXSIZE) - { -#if 1 - int src1_x = g_right->src_x; - int src1_y = g_right->src_y; - int src2_x = g_left->src_x + g_left->width - i; - int src2_y = g_left->src_y; - int dst1_x = DX + DXSIZE - i; - int dst1_y = DY; - int dst2_x = DX; - int dst2_y = DY; - int width = i; - int height = DYSIZE; - - SetClipOrigin(bm_right, gc_right, dst1_x - src1_x, dst1_y - src1_y); - BlitBitmapMasked(bm_right, drawto, src1_x, src1_y, width, height, - dst1_x, dst1_y); - - SetClipOrigin(bm_left, gc_left, dst2_x - src2_x, dst2_y - src2_y); - BlitBitmapMasked(bm_left, drawto, src2_x, src2_y, width, height, - dst2_x, dst2_y); -#else - int src1_x = DXSIZE, src1_y = DOOR_GFX_PAGEY1; - int src2_x = DXSIZE - i, src2_y = DOOR_GFX_PAGEY1; - int dst1_x = DX + DXSIZE - i, dst1_y = DY; - int dst2_x = DX, dst2_y = DY; - int width = i, height = DYSIZE; - - SetClipOrigin(bitmap, gc, dst1_x - src1_x, dst1_y - src1_y); - BlitBitmapMasked(bitmap, drawto, src1_x, src1_y, width, height, - dst1_x, dst1_y); - - SetClipOrigin(bitmap, gc, dst2_x - src2_x, dst2_y - src2_y); - BlitBitmapMasked(bitmap, drawto, src2_x, src2_y, width, height, - dst2_x, dst2_y); -#endif - } - else if (door_1.anim_mode & ANIM_VERTICAL && x <= DYSIZE) - { -#if 1 - int src1_x = g_right->src_x; - int src1_y = g_right->src_y; - int src2_x = g_left->src_x; - int src2_y = g_left->src_y + g_left->height - i; - int dst1_x = DX; - int dst1_y = DY + DYSIZE - i; - int dst2_x = DX; - int dst2_y = DY; - int width = DXSIZE; - int height = i; - - SetClipOrigin(bm_right, gc_right, dst1_x - src1_x, dst1_y - src1_y); - BlitBitmapMasked(bm_right, drawto, src1_x, src1_y, width, height, - dst1_x, dst1_y); - - SetClipOrigin(bm_left, gc_left, dst2_x - src2_x, dst2_y - src2_y); - BlitBitmapMasked(bm_left, drawto, src2_x, src2_y, width, height, - dst2_x, dst2_y); -#else - int src1_x = DXSIZE, src1_y = DOOR_GFX_PAGEY1; - int src2_x = 0, src2_y = DOOR_GFX_PAGEY1 + DYSIZE - i; - int dst1_x = DX, dst1_y = DY + DYSIZE - i; - int dst2_x = DX, dst2_y = DY; - int width = DXSIZE, height = i; - - SetClipOrigin(bitmap, gc, dst1_x - src1_x, dst1_y - src1_y); - BlitBitmapMasked(bitmap, drawto, src1_x, src1_y, width, height, - dst1_x, dst1_y); - - SetClipOrigin(bitmap, gc, dst2_x - src2_x, dst2_y - src2_y); - BlitBitmapMasked(bitmap, drawto, src2_x, src2_y, width, height, - dst2_x, dst2_y); -#endif - } - else if (classic_door_1_size && x <= DXSIZE) /* ANIM_DEFAULT */ - { - int j = (door_1.anim_mode == ANIM_DEFAULT ? (DXSIZE - i) / 3 : 0); - -#if 1 - int src1_x = g_right->src_x; - int src1_y = g_right->src_y; - int src2_x = g_left->src_x + g_left->width - i; - int src2_y = g_left->src_y; - int dst1_x = DX + DXSIZE - i; - int dst1_y = DY; - int dst2_x = DX; - int dst2_y = DY; - int width = i; - int height1 = 63, height2 = DYSIZE / 2 - height1; - int ypos1 = 0, ypos2 = height2; - int ypos3 = DYSIZE / 2, ypos4 = DYSIZE - height2; - - SetClipOrigin(bm_right, gc_right, - dst1_x - src1_x, dst1_y - src1_y + j); - BlitBitmapMasked(bm_right, drawto, - src1_x, src1_y + ypos1, width, height2, - dst1_x, dst1_y + ypos1 + j); - BlitBitmapMasked(bm_right, drawto, - src1_x, src1_y + ypos3, width, height1, - dst1_x, dst1_y + ypos3 + j); - SetClipOrigin(bm_left, gc_left, - dst2_x - src2_x, dst2_y - src2_y - j); - BlitBitmapMasked(bm_left, drawto, - src2_x, src2_y + ypos1 + j, width, height2 - j, - dst2_x, dst2_y + ypos1); - BlitBitmapMasked(bm_left, drawto, - src2_x, src2_y + ypos3, width, height1, - dst2_x, dst2_y + ypos3 - j); - - SetClipOrigin(bm_left, gc_left, - dst2_x - src2_x, dst2_y - src2_y - j); - BlitBitmapMasked(bm_left, drawto, - src2_x, src2_y + ypos2, width, height1, - dst2_x, dst2_y + ypos2 - j); - BlitBitmapMasked(bm_left, drawto, - src2_x, src2_y + ypos4, width, height2, - dst2_x, dst2_y + ypos4 - j); - SetClipOrigin(bm_right, gc_right, - dst1_x - src1_x, dst1_y - src1_y + j); - BlitBitmapMasked(bm_right, drawto, - src1_x, src1_y + ypos2, width, height1, - dst1_x, dst1_y + ypos2 + j); - BlitBitmapMasked(bm_right, drawto, - src1_x, src1_y + ypos4, width, height2 - j, - dst1_x, dst1_y + ypos4 + j); - -#else - int src1_x = DXSIZE, src1_y = DOOR_GFX_PAGEY1; - int src2_x = DXSIZE - i, src2_y = DOOR_GFX_PAGEY1; - int dst1_x = DX + DXSIZE - i, dst1_y = DY; - int dst2_x = DX, dst2_y = DY; - int width = i, height = DYSIZE; - int ypos1 = 63, ypos2 = 77, ypos3 = 140, ypos4 = 203; - - SetClipOrigin(bitmap, gc, dst1_x - src1_x, dst1_y - src1_y + j); - BlitBitmapMasked(bitmap, drawto, - src1_x, src1_y, width, ypos2, - dst1_x, dst1_y + j); - BlitBitmapMasked(bitmap, drawto, - src1_x, src1_y + ypos3, width, ypos1, - dst1_x, dst1_y + ypos3 + j); - SetClipOrigin(bitmap, gc, dst2_x - src2_x, dst2_y - src2_y - j); - BlitBitmapMasked(bitmap, drawto, - src2_x, src2_y + j, width, ypos2 - j, - dst2_x, dst2_y); - BlitBitmapMasked(bitmap, drawto, - src2_x, src2_y + ypos3, width, ypos1, - dst2_x, dst2_y + ypos3 - j); - - SetClipOrigin(bitmap, gc, dst2_x - src2_x, dst2_y - src2_y - j); - BlitBitmapMasked(bitmap, drawto, - src2_x, src2_y + ypos2, width, ypos1, - dst2_x, dst2_y + ypos2 - j); - BlitBitmapMasked(bitmap, drawto, - src2_x, src2_y + ypos4, width, ypos2, - dst2_x, dst2_y + ypos4 - j); - SetClipOrigin(bitmap, gc, dst1_x - src1_x, dst1_y - src1_y + j); - BlitBitmapMasked(bitmap, drawto, - src1_x, src1_y + ypos2, width, ypos1, - dst1_x, dst1_y + ypos2 + j); - BlitBitmapMasked(bitmap, drawto, - src1_x, src1_y + ypos4, width, ypos2 - j, - dst1_x, dst1_y + ypos4 + j); - - /* - SetClipOrigin(bitmap, gc, DX - i, (DY + j) - DOOR_GFX_PAGEY1); - BlitBitmapMasked(bitmap, drawto, - DXSIZE, DOOR_GFX_PAGEY1, i, 77, - DX + DXSIZE - i, DY + j); - BlitBitmapMasked(bitmap, drawto, - DXSIZE, DOOR_GFX_PAGEY1 + 140, i, 63, - DX + DXSIZE - i, DY + 140 + j); - SetClipOrigin(bitmap, gc, DX - DXSIZE + i, - DY - (DOOR_GFX_PAGEY1 + j)); - BlitBitmapMasked(bitmap, drawto, - DXSIZE - i, DOOR_GFX_PAGEY1 + j, i, 77 - j, - DX, DY); - BlitBitmapMasked(bitmap, drawto, - DXSIZE-i, DOOR_GFX_PAGEY1 + 140, i, 63, - DX, DY + 140 - j); - - BlitBitmapMasked(bitmap, drawto, - DXSIZE - i, DOOR_GFX_PAGEY1 + 77, i, 63, - DX, DY + 77 - j); - BlitBitmapMasked(bitmap, drawto, - DXSIZE - i, DOOR_GFX_PAGEY1 + 203, i, 77, - DX, DY + 203 - j); - SetClipOrigin(bitmap, gc, DX - i, (DY + j) - DOOR_GFX_PAGEY1); - BlitBitmapMasked(bitmap, drawto, - DXSIZE, DOOR_GFX_PAGEY1 + 77, i, 63, - DX + DXSIZE - i, DY + 77 + j); - BlitBitmapMasked(bitmap, drawto, - DXSIZE, DOOR_GFX_PAGEY1 + 203, i, 77 - j, - DX + DXSIZE - i, DY + 203 + j); - */ -#endif - } - - redraw_mask |= REDRAW_DOOR_1; - door_1_done = (a == end); - } - - if (door_state & DOOR_ACTION_2 && - x * door_2.step_offset <= door_size_2) - { - int a = MIN(x * door_2.step_offset, door_size); - int p = (door_state & DOOR_OPEN_2 ? door_size - a : a); - int i = p + door_skip; - -#if 1 - struct GraphicInfo *g_left = &graphic_info[IMG_DOOR_2_WING_LEFT]; - struct GraphicInfo *g_right = &graphic_info[IMG_DOOR_2_WING_RIGHT]; - Bitmap *bm_left = g_left->bitmap; - Bitmap *bm_right = g_right->bitmap; - GC gc_left = bm_left->stored_clip_gc; - GC gc_right = bm_right->stored_clip_gc; -#endif - - int classic_vxsize = 100; - int classic_vysize = 100; - boolean classic_door_2_size = (VXSIZE == classic_vxsize && - VYSIZE == classic_vysize); - - if (door_2.anim_mode & ANIM_STATIC_PANEL) - { - BlitBitmap(bitmap_db_door, drawto, - DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY2, - VXSIZE, VYSIZE, VX, VY); - } - else if (x <= VYSIZE) - { - BlitBitmap(bitmap_db_door, drawto, - DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY2 + p / 2, - VXSIZE, VYSIZE - p / 2, VX, VY); - - ClearRectangle(drawto, VX, VY + VYSIZE - p / 2, VXSIZE, p / 2); - } - - if (door_2.anim_mode & ANIM_HORIZONTAL && x <= VXSIZE) - { -#if 1 - int src1_x = g_right->src_x; - int src1_y = g_right->src_y; - int src2_x = g_left->src_x + g_left->width - i; - int src2_y = g_left->src_y; - int dst1_x = VX + VXSIZE - i; - int dst1_y = VY; - int dst2_x = VX; - int dst2_y = VY; - int width = i; - int height = VYSIZE; - - SetClipOrigin(bm_right, gc_right, dst1_x - src1_x, dst1_y - src1_y); - BlitBitmapMasked(bm_right, drawto, src1_x, src1_y, width, height, - dst1_x, dst1_y); - - SetClipOrigin(bm_left, gc_left, dst2_x - src2_x, dst2_y - src2_y); - BlitBitmapMasked(bm_left, drawto, src2_x, src2_y, width, height, - dst2_x, dst2_y); -#else - int src1_x = VXSIZE, src1_y = DOOR_GFX_PAGEY2; - int src2_x = VXSIZE - i, src2_y = DOOR_GFX_PAGEY2; - int dst1_x = VX + VXSIZE - i, dst1_y = VY; - int dst2_x = VX, dst2_y = VY; - int width = i, height = VYSIZE; - - SetClipOrigin(bitmap, gc, dst1_x - src1_x, dst1_y - src1_y); - BlitBitmapMasked(bitmap, drawto, src1_x, src1_y, width, height, - dst1_x, dst1_y); - - SetClipOrigin(bitmap, gc, dst2_x - src2_x, dst2_y - src2_y); - BlitBitmapMasked(bitmap, drawto, src2_x, src2_y, width, height, - dst2_x, dst2_y); -#endif - } - else if (door_2.anim_mode & ANIM_VERTICAL && x <= VYSIZE) - { -#if 1 - int src1_x = g_right->src_x; - int src1_y = g_right->src_y; - int src2_x = g_left->src_x; - int src2_y = g_left->src_y + g_left->height - i; - int dst1_x = VX; - int dst1_y = VY + VYSIZE - i; - int dst2_x = VX; - int dst2_y = VY; - int width = VXSIZE; - int height = i; - - SetClipOrigin(bm_right, gc_right, dst1_x - src1_x, dst1_y - src1_y); - BlitBitmapMasked(bm_right, drawto, src1_x, src1_y, width, height, - dst1_x, dst1_y); - - SetClipOrigin(bm_left, gc_left, dst2_x - src2_x, dst2_y - src2_y); - BlitBitmapMasked(bm_left, drawto, src2_x, src2_y, width, height, - dst2_x, dst2_y); -#else - int src1_x = VXSIZE, src1_y = DOOR_GFX_PAGEY2; - int src2_x = 0, src2_y = DOOR_GFX_PAGEY2 + VYSIZE - i; - int dst1_x = VX, dst1_y = VY + VYSIZE - i; - int dst2_x = VX, dst2_y = VY; - int width = VXSIZE, height = i; - - SetClipOrigin(bitmap, gc, dst1_x - src1_x, dst1_y - src1_y); - BlitBitmapMasked(bitmap, drawto, src1_x, src1_y, width, height, - dst1_x, dst1_y); - - SetClipOrigin(bitmap, gc, dst2_x - src2_x, dst2_y - src2_y); - BlitBitmapMasked(bitmap, drawto, src2_x, src2_y, width, height, - dst2_x, dst2_y); -#endif - } - else if (classic_door_2_size && x <= VXSIZE) /* ANIM_DEFAULT */ - { - int j = (door_2.anim_mode == ANIM_DEFAULT ? (VXSIZE - i) / 3 : 0); - -#if 1 - int src1_x = g_right->src_x; - int src1_y = g_right->src_y; - int src2_x = g_left->src_x + g_left->width - i; - int src2_y = g_left->src_y; - int dst1_x = VX + VXSIZE - i; - int dst1_y = VY; - int dst2_x = VX; - int dst2_y = VY; - int width = i; - int height = VYSIZE / 2; - int ypos1 = 0, ypos2 = VYSIZE / 2; - - SetClipOrigin(bm_right, gc_right, - dst1_x - src1_x, dst1_y - src1_y + j); - BlitBitmapMasked(bm_right, drawto, - src1_x, src1_y + ypos1, width, height, - dst1_x, dst1_y + ypos1 + j); - SetClipOrigin(bm_left, gc_left, - dst2_x - src2_x, dst2_y - src2_y - j); - BlitBitmapMasked(bm_left, drawto, - src2_x, src2_y + ypos1 + j, width, height - j, - dst2_x, dst2_y + ypos1); - - SetClipOrigin(bm_left, gc_left, - dst2_x - src2_x, dst2_y - src2_y - j); - BlitBitmapMasked(bm_left, drawto, - src2_x, src2_y + ypos2, width, height, - dst2_x, dst2_y + ypos2 - j); - SetClipOrigin(bm_right, gc_right, - dst1_x - src1_x, dst1_y - src1_y + j); - BlitBitmapMasked(bm_right, drawto, - src1_x, src1_y + ypos2, width, height - j, - dst1_x, dst1_y + ypos2 + j); -#else - int src1_x = VXSIZE, src1_y = DOOR_GFX_PAGEY2; - int src2_x = VXSIZE - i, src2_y = DOOR_GFX_PAGEY2; - int dst1_x = VX + VXSIZE - i, dst1_y = VY; - int dst2_x = VX, dst2_y = VY; - int width = i, height = VYSIZE; - int ypos = VYSIZE / 2; - - SetClipOrigin(bitmap, gc, dst1_x - src1_x, dst1_y - src1_y + j); - BlitBitmapMasked(bitmap, drawto, - src1_x, src1_y, width, ypos, - dst1_x, dst1_y + j); - SetClipOrigin(bitmap, gc, dst2_x - src2_x, dst2_y - src1_y - j); - BlitBitmapMasked(bitmap, drawto, - src2_x, src2_y + j, width, ypos - j, - dst2_x, dst2_y); - - SetClipOrigin(bitmap, gc, dst2_x - src2_x, dst2_y - src1_y - j); - BlitBitmapMasked(bitmap, drawto, - src2_x, src2_y + ypos, width, ypos, - dst2_x, dst2_y + ypos - j); - SetClipOrigin(bitmap, gc, dst1_x - src1_x, dst1_y - src1_y + j); - BlitBitmapMasked(bitmap, drawto, - src1_x, src1_y + ypos, width, ypos - j, - dst1_x, dst1_y + ypos + j); - - /* - SetClipOrigin(bitmap, gc, VX - i, (VY + j) - DOOR_GFX_PAGEY2); - BlitBitmapMasked(bitmap, drawto, - VXSIZE, DOOR_GFX_PAGEY2, i, VYSIZE / 2, - VX + VXSIZE - i, VY + j); - SetClipOrigin(bitmap, gc, - VX - VXSIZE + i, VY - (DOOR_GFX_PAGEY2 + j)); - BlitBitmapMasked(bitmap, drawto, - VXSIZE - i, DOOR_GFX_PAGEY2 + j, i, VYSIZE / 2 - j, - VX, VY); - - BlitBitmapMasked(bitmap, drawto, - VXSIZE - i, DOOR_GFX_PAGEY2 + VYSIZE / 2, - i, VYSIZE / 2, VX, VY + VYSIZE / 2 - j); - SetClipOrigin(bitmap, gc, VX - i, (VY + j) - DOOR_GFX_PAGEY2); - BlitBitmapMasked(bitmap, drawto, - VXSIZE, DOOR_GFX_PAGEY2 + VYSIZE / 2, - i, VYSIZE / 2 - j, - VX + VXSIZE - i, VY + VYSIZE / 2 + j); - */ -#endif - } - - redraw_mask |= REDRAW_DOOR_2; - door_2_done = (a == VXSIZE); - } - - if (!(door_state & DOOR_NO_DELAY)) - { - BackToFront(); - - if (game_status == GAME_MODE_MAIN) - DoAnimation(); - - WaitUntilDelayReached(&door_delay, door_delay_value); - } - } - } - - 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); -} - -#endif - -void DrawSpecialEditorDoor() -{ -#if 1 - struct GraphicInfo *gfx1 = &graphic_info[IMG_DOOR_2_TOP_BORDER_CORRECTION]; - int top_border_width = gfx1->width; - int top_border_height = gfx1->height; - int outer_border = viewport.door_2[GAME_MODE_EDITOR].border_size; - int ex = EX - outer_border; - int ey = EY - outer_border; - int vy = VY - outer_border; - int exsize = EXSIZE + 2 * outer_border; - - CloseDoor(DOOR_CLOSE_2); - - /* draw bigger level editor toolbox window */ - BlitBitmap(gfx1->bitmap, drawto, gfx1->src_x, gfx1->src_y, - top_border_width, top_border_height, ex, ey - top_border_height); - BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto, ex, vy, - exsize, EYSIZE - VYSIZE + outer_border, ex, ey); -#else - /* draw bigger level editor toolbox window */ - BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, - DOOR_GFX_PAGEX7, 0, EXSIZE + 8, 8, - EX - 4, EY - 12); - BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto, - EX - 6, VY - 4, EXSIZE + 12, EYSIZE - VYSIZE + 4, - EX - 6, EY - 4); -#endif - - redraw_mask |= REDRAW_ALL; -} - -void UndrawSpecialEditorDoor() -{ -#if 1 - struct GraphicInfo *gfx1 = &graphic_info[IMG_DOOR_2_TOP_BORDER_CORRECTION]; - int top_border_width = gfx1->width; - int top_border_height = gfx1->height; - int outer_border = viewport.door_2[GAME_MODE_EDITOR].border_size; - int ex = EX - outer_border; - int ey = EY - outer_border; - int ey_top = ey - top_border_height; - int exsize = EXSIZE + 2 * outer_border; - int eysize = EYSIZE + 2 * outer_border; - - /* draw normal tape recorder window */ - if (graphic_info[IMG_GLOBAL_BORDER].bitmap) - { - BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto, - ex, ey_top, top_border_width, top_border_height, - ex, ey_top); - BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto, - ex, ey, exsize, eysize, ex, ey); - } - else - { - // if screen background is set to "[NONE]", clear editor toolbox window - ClearRectangle(drawto, ex, ey_top, top_border_width, top_border_height); - ClearRectangle(drawto, ex, ey, exsize, eysize); - } -#else - /* draw normal tape recorder window */ - BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, drawto, - EX - 6, EY - 12, EXSIZE + 12, EYSIZE - VYSIZE + 12, - EX - 6, EY - 12); -#endif - - redraw_mask |= REDRAW_ALL; -} - - -/* ---------- new tool button stuff ---------------------------------------- */ - -#if 1 - -static struct -{ - int graphic; - struct TextPosInfo *pos; - int gadget_id; - char *infotext; -} toolbutton_info[NUM_TOOL_BUTTONS] = -{ - { - IMG_REQUEST_BUTTON_GFX_YES, &request.button.yes, - TOOL_CTRL_ID_YES, "yes" - }, - { - IMG_REQUEST_BUTTON_GFX_NO, &request.button.no, - TOOL_CTRL_ID_NO, "no" - }, - { - IMG_REQUEST_BUTTON_GFX_CONFIRM, &request.button.confirm, - TOOL_CTRL_ID_CONFIRM, "confirm" - }, - { - IMG_REQUEST_BUTTON_GFX_PLAYER_1, &request.button.player_1, - TOOL_CTRL_ID_PLAYER_1, "player 1" - }, - { - IMG_REQUEST_BUTTON_GFX_PLAYER_2, &request.button.player_2, - TOOL_CTRL_ID_PLAYER_2, "player 2" - }, - { - IMG_REQUEST_BUTTON_GFX_PLAYER_3, &request.button.player_3, - TOOL_CTRL_ID_PLAYER_3, "player 3" - }, - { - IMG_REQUEST_BUTTON_GFX_PLAYER_4, &request.button.player_4, - TOOL_CTRL_ID_PLAYER_4, "player 4" - } -}; - -void CreateToolButtons() -{ - int i; - - for (i = 0; i < NUM_TOOL_BUTTONS; i++) - { - struct GraphicInfo *gfx = &graphic_info[toolbutton_info[i].graphic]; - struct TextPosInfo *pos = toolbutton_info[i].pos; - struct GadgetInfo *gi; - Bitmap *deco_bitmap = None; - int deco_x = 0, deco_y = 0, deco_xpos = 0, deco_ypos = 0; - unsigned int event_mask = GD_EVENT_RELEASED; - int dx = DX; - int dy = DY; - int gd_x = gfx->src_x; - int gd_y = gfx->src_y; - int gd_xp = gfx->src_x + gfx->pressed_xoffset; - int gd_yp = gfx->src_y + gfx->pressed_yoffset; - int id = i; - - if (global.use_envelope_request) - setRequestPosition(&dx, &dy, TRUE); - - if (id >= TOOL_CTRL_ID_PLAYER_1 && id <= TOOL_CTRL_ID_PLAYER_4) - { - int player_nr = id - TOOL_CTRL_ID_PLAYER_1; - - getSizedGraphicSource(PLAYER_NR_GFX(IMG_PLAYER_1, player_nr), 0, - pos->size, &deco_bitmap, &deco_x, &deco_y); - deco_xpos = (gfx->width - pos->size) / 2; - deco_ypos = (gfx->height - pos->size) / 2; - } - - gi = CreateGadget(GDI_CUSTOM_ID, id, - GDI_INFO_TEXT, toolbutton_info[i].infotext, - GDI_X, dx + GDI_ACTIVE_POS(pos->x), - GDI_Y, dy + GDI_ACTIVE_POS(pos->y), - GDI_WIDTH, gfx->width, - GDI_HEIGHT, gfx->height, - GDI_TYPE, GD_TYPE_NORMAL_BUTTON, - GDI_STATE, GD_BUTTON_UNPRESSED, - GDI_DESIGN_UNPRESSED, gfx->bitmap, gd_x, gd_y, - GDI_DESIGN_PRESSED, gfx->bitmap, gd_xp, gd_yp, - GDI_DECORATION_DESIGN, deco_bitmap, deco_x, deco_y, - GDI_DECORATION_POSITION, deco_xpos, deco_ypos, - GDI_DECORATION_SIZE, pos->size, pos->size, - GDI_DECORATION_SHIFTING, 1, 1, - GDI_DIRECT_DRAW, FALSE, - GDI_EVENT_MASK, event_mask, - GDI_CALLBACK_ACTION, HandleToolButtons, - GDI_END); - - if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); - - tool_gadget[id] = gi; - } -} - -#else - -/* graphic position values for tool buttons */ -#define TOOL_BUTTON_YES_XPOS 2 -#define TOOL_BUTTON_YES_YPOS 250 -#define TOOL_BUTTON_YES_GFX_YPOS 0 -#define TOOL_BUTTON_YES_XSIZE 46 -#define TOOL_BUTTON_YES_YSIZE 28 -#define TOOL_BUTTON_NO_XPOS 52 -#define TOOL_BUTTON_NO_YPOS TOOL_BUTTON_YES_YPOS -#define TOOL_BUTTON_NO_GFX_YPOS TOOL_BUTTON_YES_GFX_YPOS -#define TOOL_BUTTON_NO_XSIZE TOOL_BUTTON_YES_XSIZE -#define TOOL_BUTTON_NO_YSIZE TOOL_BUTTON_YES_YSIZE -#define TOOL_BUTTON_CONFIRM_XPOS TOOL_BUTTON_YES_XPOS -#define TOOL_BUTTON_CONFIRM_YPOS TOOL_BUTTON_YES_YPOS -#define TOOL_BUTTON_CONFIRM_GFX_YPOS 30 -#define TOOL_BUTTON_CONFIRM_XSIZE 96 -#define TOOL_BUTTON_CONFIRM_YSIZE TOOL_BUTTON_YES_YSIZE -#define TOOL_BUTTON_PLAYER_XSIZE 30 -#define TOOL_BUTTON_PLAYER_YSIZE 30 -#define TOOL_BUTTON_PLAYER_GFX_XPOS 5 -#define TOOL_BUTTON_PLAYER_GFX_YPOS 185 -#define TOOL_BUTTON_PLAYER_XPOS (5 + TOOL_BUTTON_PLAYER_XSIZE / 2) -#define TOOL_BUTTON_PLAYER_YPOS (215 - TOOL_BUTTON_PLAYER_YSIZE / 2) -#define TOOL_BUTTON_PLAYER1_XPOS (TOOL_BUTTON_PLAYER_XPOS \ - + 0 * TOOL_BUTTON_PLAYER_XSIZE) -#define TOOL_BUTTON_PLAYER2_XPOS (TOOL_BUTTON_PLAYER_XPOS \ - + 1 * TOOL_BUTTON_PLAYER_XSIZE) -#define TOOL_BUTTON_PLAYER3_XPOS (TOOL_BUTTON_PLAYER_XPOS \ - + 0 * TOOL_BUTTON_PLAYER_XSIZE) -#define TOOL_BUTTON_PLAYER4_XPOS (TOOL_BUTTON_PLAYER_XPOS \ - + 1 * TOOL_BUTTON_PLAYER_XSIZE) -#define TOOL_BUTTON_PLAYER1_YPOS (TOOL_BUTTON_PLAYER_YPOS \ - + 0 * TOOL_BUTTON_PLAYER_YSIZE) -#define TOOL_BUTTON_PLAYER2_YPOS (TOOL_BUTTON_PLAYER_YPOS \ - + 0 * TOOL_BUTTON_PLAYER_YSIZE) -#define TOOL_BUTTON_PLAYER3_YPOS (TOOL_BUTTON_PLAYER_YPOS \ - + 1 * TOOL_BUTTON_PLAYER_YSIZE) -#define TOOL_BUTTON_PLAYER4_YPOS (TOOL_BUTTON_PLAYER_YPOS \ - + 1 * TOOL_BUTTON_PLAYER_YSIZE) - -static struct -{ - int xpos, ypos; - int x, y; - int width, height; - int gadget_id; - char *infotext; -} toolbutton_info[NUM_TOOL_BUTTONS] = -{ - { - TOOL_BUTTON_YES_XPOS, TOOL_BUTTON_YES_GFX_YPOS, - TOOL_BUTTON_YES_XPOS, TOOL_BUTTON_YES_YPOS, - TOOL_BUTTON_YES_XSIZE, TOOL_BUTTON_YES_YSIZE, - TOOL_CTRL_ID_YES, - "yes" - }, - { - TOOL_BUTTON_NO_XPOS, TOOL_BUTTON_NO_GFX_YPOS, - TOOL_BUTTON_NO_XPOS, TOOL_BUTTON_NO_YPOS, - TOOL_BUTTON_NO_XSIZE, TOOL_BUTTON_NO_YSIZE, - TOOL_CTRL_ID_NO, - "no" - }, - { - TOOL_BUTTON_CONFIRM_XPOS, TOOL_BUTTON_CONFIRM_GFX_YPOS, - TOOL_BUTTON_CONFIRM_XPOS, TOOL_BUTTON_CONFIRM_YPOS, - TOOL_BUTTON_CONFIRM_XSIZE, TOOL_BUTTON_CONFIRM_YSIZE, - TOOL_CTRL_ID_CONFIRM, - "confirm" - }, - { - TOOL_BUTTON_PLAYER_GFX_XPOS,TOOL_BUTTON_PLAYER_GFX_YPOS, - TOOL_BUTTON_PLAYER1_XPOS, TOOL_BUTTON_PLAYER1_YPOS, - TOOL_BUTTON_PLAYER_XSIZE, TOOL_BUTTON_PLAYER_YSIZE, - TOOL_CTRL_ID_PLAYER_1, - "player 1" - }, - { - TOOL_BUTTON_PLAYER_GFX_XPOS,TOOL_BUTTON_PLAYER_GFX_YPOS, - TOOL_BUTTON_PLAYER2_XPOS, TOOL_BUTTON_PLAYER2_YPOS, - TOOL_BUTTON_PLAYER_XSIZE, TOOL_BUTTON_PLAYER_YSIZE, - TOOL_CTRL_ID_PLAYER_2, - "player 2" - }, - { - TOOL_BUTTON_PLAYER_GFX_XPOS,TOOL_BUTTON_PLAYER_GFX_YPOS, - TOOL_BUTTON_PLAYER3_XPOS, TOOL_BUTTON_PLAYER3_YPOS, - TOOL_BUTTON_PLAYER_XSIZE, TOOL_BUTTON_PLAYER_YSIZE, - TOOL_CTRL_ID_PLAYER_3, - "player 3" - }, - { - TOOL_BUTTON_PLAYER_GFX_XPOS,TOOL_BUTTON_PLAYER_GFX_YPOS, - TOOL_BUTTON_PLAYER4_XPOS, TOOL_BUTTON_PLAYER4_YPOS, - TOOL_BUTTON_PLAYER_XSIZE, TOOL_BUTTON_PLAYER_YSIZE, - TOOL_CTRL_ID_PLAYER_4, - "player 4" - } -}; - -void CreateToolButtons() -{ - int i; - - for (i = 0; i < NUM_TOOL_BUTTONS; i++) - { - Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap; - Bitmap *deco_bitmap = None; - int deco_x = 0, deco_y = 0, deco_xpos = 0, deco_ypos = 0; - struct GadgetInfo *gi; - unsigned int event_mask; - int gd_xoffset, gd_yoffset; - int gd_x1, gd_x2, gd_y; - int id = i; - - event_mask = GD_EVENT_RELEASED; - - gd_xoffset = toolbutton_info[i].xpos; - gd_yoffset = toolbutton_info[i].ypos; - gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset; - gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset; - gd_y = DOOR_GFX_PAGEY1 + gd_yoffset; - - if (id >= TOOL_CTRL_ID_PLAYER_1 && id <= TOOL_CTRL_ID_PLAYER_4) - { - int player_nr = id - TOOL_CTRL_ID_PLAYER_1; - - getMiniGraphicSource(PLAYER_NR_GFX(IMG_PLAYER_1, 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; - } - - gi = CreateGadget(GDI_CUSTOM_ID, id, - GDI_INFO_TEXT, toolbutton_info[i].infotext, - GDI_X, DX + GDI_ACTIVE_POS(toolbutton_info[i].x), - GDI_Y, DY + GDI_ACTIVE_POS(toolbutton_info[i].y), - GDI_WIDTH, toolbutton_info[i].width, - GDI_HEIGHT, toolbutton_info[i].height, - GDI_TYPE, GD_TYPE_NORMAL_BUTTON, - GDI_STATE, GD_BUTTON_UNPRESSED, - GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y, - GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y, - GDI_DECORATION_DESIGN, deco_bitmap, deco_x, deco_y, - GDI_DECORATION_POSITION, deco_xpos, deco_ypos, - GDI_DECORATION_SIZE, MINI_TILEX, MINI_TILEY, - GDI_DECORATION_SHIFTING, 1, 1, - GDI_DIRECT_DRAW, FALSE, - GDI_EVENT_MASK, event_mask, - GDI_CALLBACK_ACTION, HandleToolButtons, - GDI_END); - - if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); - - tool_gadget[id] = gi; - } -} - -#endif - -void FreeToolButtons() -{ - int i; - - for (i = 0; i < NUM_TOOL_BUTTONS; i++) - FreeGadget(tool_gadget[i]); -} - -static void UnmapToolButtons() -{ - int i; - - for (i = 0; i < NUM_TOOL_BUTTONS; i++) - UnmapGadget(tool_gadget[i]); -} - -static void HandleToolButtons(struct GadgetInfo *gi) -{ - request_gadget_id = gi->custom_id; -} - -static struct Mapping_EM_to_RND_object -{ - int element_em; - boolean is_rnd_to_em_mapping; /* unique mapping EM <-> RND */ - boolean is_backside; /* backside of moving element */ - - int element_rnd; - int action; - int direction; -} -em_object_mapping_list[] = -{ - { - Xblank, TRUE, FALSE, - EL_EMPTY, -1, -1 - }, - { - Yacid_splash_eB, FALSE, FALSE, - EL_ACID_SPLASH_RIGHT, -1, -1 - }, - { - Yacid_splash_wB, FALSE, FALSE, - EL_ACID_SPLASH_LEFT, -1, -1 - }, - -#ifdef EM_ENGINE_BAD_ROLL - { - Xstone_force_e, FALSE, FALSE, - EL_ROCK, -1, MV_BIT_RIGHT - }, + Xstone_force_e, FALSE, FALSE, + EL_ROCK, -1, MV_BIT_RIGHT + }, { Xstone_force_w, FALSE, FALSE, EL_ROCK, -1, MV_BIT_LEFT @@ -8481,7 +5763,6 @@ em_object_mapping_list[] = Xsand_stonein_4, FALSE, TRUE, EL_ROCK, ACTION_FILLING, -1 }, -#if 1 { Xsand_stonesand_1, FALSE, FALSE, EL_QUICKSAND_EMPTYING, -1, -1 @@ -8506,24 +5787,6 @@ em_object_mapping_list[] = Xsand_stonesand_quickout_2, FALSE, FALSE, EL_QUICKSAND_EMPTYING, -1, -1 }, -#else - { - Xsand_stonesand_1, FALSE, FALSE, - EL_QUICKSAND_FULL, -1, -1 - }, - { - Xsand_stonesand_2, FALSE, FALSE, - EL_QUICKSAND_FULL, -1, -1 - }, - { - Xsand_stonesand_3, FALSE, FALSE, - EL_QUICKSAND_FULL, -1, -1 - }, - { - Xsand_stonesand_4, FALSE, FALSE, - EL_QUICKSAND_FULL, -1, -1 - }, -#endif { Xsand_stoneout_1, FALSE, FALSE, EL_ROCK, ACTION_EMPTYING, -1 @@ -8532,7 +5795,6 @@ em_object_mapping_list[] = Xsand_stoneout_2, FALSE, FALSE, EL_ROCK, ACTION_EMPTYING, -1 }, -#if 1 { Xsand_sandstone_1, FALSE, FALSE, EL_QUICKSAND_FILLING, -1, -1 @@ -8549,24 +5811,6 @@ em_object_mapping_list[] = Xsand_sandstone_4, FALSE, FALSE, EL_QUICKSAND_FILLING, -1, -1 }, -#else - { - Xsand_sandstone_1, FALSE, FALSE, - EL_QUICKSAND_FULL, -1, -1 - }, - { - Xsand_sandstone_2, FALSE, FALSE, - EL_QUICKSAND_FULL, -1, -1 - }, - { - Xsand_sandstone_3, FALSE, FALSE, - EL_QUICKSAND_FULL, -1, -1 - }, - { - Xsand_sandstone_4, FALSE, FALSE, - EL_QUICKSAND_FULL, -1, -1 - }, -#endif { Xplant, TRUE, FALSE, EL_EMC_PLANT, -1, -1 @@ -9422,19 +6666,6 @@ int get_next_element(int element) } } -#if 0 -int el_act_dir2img(int element, int action, int direction) -{ - element = GFX_ELEMENT(element); - - if (direction == MV_NONE) - return element_info[element].graphic[action]; - - direction = MV_DIR_TO_BIT(direction); - - return element_info[element].direction_graphic[action][direction]; -} -#else int el_act_dir2img(int element, int action, int direction) { element = GFX_ELEMENT(element); @@ -9443,21 +6674,7 @@ int el_act_dir2img(int element, int action, int direction) /* direction_graphic[][] == graphic[] for undefined direction graphics */ return element_info[element].direction_graphic[action][direction]; } -#endif - -#if 0 -static int el_act_dir2crm(int element, int action, int direction) -{ - element = GFX_ELEMENT(element); - - if (direction == MV_NONE) - return element_info[element].crumbled[action]; - direction = MV_DIR_TO_BIT(direction); - - return element_info[element].direction_crumbled[action][direction]; -} -#else static int el_act_dir2crm(int element, int action, int direction) { element = GFX_ELEMENT(element); @@ -9466,7 +6683,6 @@ static int el_act_dir2crm(int element, int action, int direction) /* direction_graphic[][] == graphic[] for undefined direction graphics */ return element_info[element].direction_crumbled[action][direction]; } -#endif int el_act2img(int element, int action) { @@ -9643,49 +6859,15 @@ int getBeltSwitchElementFromBeltNrAndBeltDirNr(int belt_nr, int belt_dir_nr) int getBeltSwitchElementFromBeltNrAndBeltDir(int belt_nr, int belt_dir) { - int belt_dir_nr = (belt_dir == MV_LEFT ? 0 : belt_dir == MV_RIGHT ? 2 : 1); - - return getBeltSwitchElementFromBeltNrAndBeltDirNr(belt_nr, belt_dir_nr); -} - -#if 1 -boolean getTeamMode_EM() -{ - return game.team_mode; -} -#else -int getNumActivePlayers_EM() -{ -#if 1 - int num_players = 0; - int i; - - if (!tape.playing) - return (setup.team_mode ? MAX_PLAYERS : 1); - - for (i = 0; i < MAX_PLAYERS; i++) - if (tape.player_participates[i]) - num_players++; - - return (num_players > 1 ? MAX_PLAYERS : 1); - -#else - - int num_players = 0; - int i; - - /* when recording game, activate all connected players */ - if (!tape.playing) - return -1; + int belt_dir_nr = (belt_dir == MV_LEFT ? 0 : belt_dir == MV_RIGHT ? 2 : 1); - for (i = 0; i < MAX_PLAYERS; i++) - if (tape.player_participates[i]) - num_players++; + return getBeltSwitchElementFromBeltNrAndBeltDirNr(belt_nr, belt_dir_nr); +} - return num_players; -#endif +boolean getTeamMode_EM() +{ + return game.team_mode; } -#endif int getGameFrameDelay_EM(int native_em_game_frame_delay) { @@ -9712,10 +6894,8 @@ unsigned int InitRND(int seed) return InitEngineRandom_RND(seed); } -#if 1 static struct Mapping_EM_to_RND_object object_mapping[TILE_MAX]; static struct Mapping_EM_to_RND_player player_mapping[MAX_PLAYERS][SPR_MAX]; -#endif inline static int get_effective_element_EM(int tile, int frame_em) { @@ -9734,13 +6914,6 @@ inline static int get_effective_element_EM(int tile, int frame_em) case Yacid_splash_wB: return (frame_em > 5 ? EL_EMPTY : element); -#if 0 - /* !!! FIX !!! */ - case Ydiamond_stone: - // if (!game.use_native_emc_graphics_engine) - return EL_ROCK; -#endif - default: return element; } @@ -9818,11 +6991,9 @@ inline static boolean check_linear_animation_EM(int tile) case Ytank_s_e: case Ytank_w_s: case Ytank_n_w: -#if 1 case Yacid_splash_eB: case Yacid_splash_wB: case Yemerald_stone: -#endif return TRUE; } @@ -9875,7 +7046,6 @@ void SetGfxAnimation_EM(struct GraphicInfo_EM *g_em, int tile, int frame_em, int x, int y) { int action = object_mapping[tile].action; -#if 1 int direction = object_mapping[tile].direction; int effective_element = get_effective_element_EM(tile, frame_em); int graphic = (direction == MV_NONE ? @@ -9883,7 +7053,6 @@ void SetGfxAnimation_EM(struct GraphicInfo_EM *g_em, el_act_dir2img(effective_element, action, direction)); struct GraphicInfo *g = &graphic_info[graphic]; int sync_frame; -#endif boolean action_removing = (action == ACTION_DIGGING || action == ACTION_SNAPPING || action == ACTION_COLLECTING); @@ -9910,496 +7079,114 @@ void SetGfxAnimation_EM(struct GraphicInfo_EM *g_em, g = &graphic_info[graphic]; } -#if 0 - if (tile == Xsand_stonesand_1 || - tile == Xsand_stonesand_2 || - tile == Xsand_stonesand_3 || - tile == Xsand_stonesand_4) - printf("::: 1: quicksand frame %d [%d]\n", GfxFrame[x][y], tile); -#endif - -#if 1 if ((action_removing || check_linear_animation_EM(tile)) && frame_em == 0) { GfxFrame[x][y] = 0; - - // printf("::: resetting... [%d]\n", tile); - } -#else - if (action_removing || check_linear_animation_EM(tile)) - { - GfxFrame[x][y] = frame_em; - - // printf("::: resetting... [%d]\n", tile); } -#endif else if (action_moving) { boolean is_backside = object_mapping[tile].is_backside; if (is_backside) { - int direction = object_mapping[tile].direction; - int move_dir = (action_falling ? MV_DOWN : direction); - - GfxFrame[x][y]++; - -#if 1 - /* !!! TEST !!! NEW !!! DOES NOT WORK RIGHT YET !!! */ - if (g->double_movement && frame_em == 0) - { - GfxFrame[x][y] = 0; - - // printf("::: resetting... [%d]\n", tile); - } -#endif - - if (move_dir == MV_LEFT) - GfxFrame[x - 1][y] = GfxFrame[x][y]; - else if (move_dir == MV_RIGHT) - GfxFrame[x + 1][y] = GfxFrame[x][y]; - else if (move_dir == MV_UP) - GfxFrame[x][y - 1] = GfxFrame[x][y]; - else if (move_dir == MV_DOWN) - GfxFrame[x][y + 1] = GfxFrame[x][y]; - } - } - else - { - GfxFrame[x][y]++; - - /* special case: animation for Xsand_stonesand_quickout_1/2 twice as fast */ - if (tile == Xsand_stonesand_quickout_1 || - tile == Xsand_stonesand_quickout_2) - GfxFrame[x][y]++; - } - -#if 0 - if (tile == Xsand_stonesand_1 || - tile == Xsand_stonesand_2 || - tile == Xsand_stonesand_3 || - tile == Xsand_stonesand_4) - printf("::: 2: quicksand frame %d [%d]\n", GfxFrame[x][y], tile); -#endif - -#if 1 - if (graphic_info[graphic].anim_global_sync) - sync_frame = FrameCounter; - else if (IN_FIELD(x, y, MAX_LEV_FIELDX, MAX_LEV_FIELDY)) - sync_frame = GfxFrame[x][y]; - else - sync_frame = 0; /* playfield border (pseudo steel) */ - - SetRandomAnimationValue(x, y); - - int frame = getAnimationFrame(g->anim_frames, - g->anim_delay, - g->anim_mode, - g->anim_start_frame, - sync_frame); - - g_em->unique_identifier = - (graphic << 16) | ((frame % 8) << 12) | (g_em->width << 6) | g_em->height; -#endif -} - -void getGraphicSourceObjectExt_EM(struct GraphicInfo_EM *g_em, - int tile, int frame_em, int x, int y) -{ - int action = object_mapping[tile].action; - int direction = object_mapping[tile].direction; - boolean is_backside = object_mapping[tile].is_backside; - int effective_element = get_effective_element_EM(tile, frame_em); -#if 1 - int effective_action = action; -#else - int effective_action = (frame_em < 7 ? action : ACTION_DEFAULT); -#endif - int graphic = (direction == MV_NONE ? - el_act2img(effective_element, effective_action) : - el_act_dir2img(effective_element, effective_action, - direction)); - int crumbled = (direction == MV_NONE ? - el_act2crm(effective_element, effective_action) : - el_act_dir2crm(effective_element, effective_action, - direction)); - int base_graphic = el_act2img(effective_element, ACTION_DEFAULT); - int base_crumbled = el_act2crm(effective_element, ACTION_DEFAULT); - boolean has_crumbled_graphics = (base_crumbled != base_graphic); - struct GraphicInfo *g = &graphic_info[graphic]; -#if 0 - struct GraphicInfo *g_crumbled = &graphic_info[crumbled]; -#endif - int sync_frame; - - /* special case: graphic uses "2nd movement tile" and has defined - 7 frames for movement animation (or less) => use default graphic - for last (8th) frame which ends the movement animation */ - if (g->double_movement && g->anim_frames < 8 && frame_em == 7) - { - effective_action = ACTION_DEFAULT; - graphic = (direction == MV_NONE ? - el_act2img(effective_element, effective_action) : - el_act_dir2img(effective_element, effective_action, - direction)); - crumbled = (direction == MV_NONE ? - el_act2crm(effective_element, effective_action) : - el_act_dir2crm(effective_element, effective_action, - direction)); - - g = &graphic_info[graphic]; - } - -#if 0 - if (frame_em == 7) - return; -#endif - - -#if 0 - if (frame_em == 0) /* reset animation frame for certain elements */ - { - if (check_linear_animation_EM(tile)) - GfxFrame[x][y] = 0; - } -#endif - - if (graphic_info[graphic].anim_global_sync) - sync_frame = FrameCounter; - else if (IN_FIELD(x, y, MAX_LEV_FIELDX, MAX_LEV_FIELDY)) - sync_frame = GfxFrame[x][y]; - else - sync_frame = 0; /* playfield border (pseudo steel) */ - - SetRandomAnimationValue(x, y); - -#if 0 - int i = tile; - int j = frame_em; - int xxx_sync_frame = (i == Xdrip_stretch ? 7 : - i == Xdrip_stretchB ? 7 : - i == Ydrip_s2 ? j + 8 : - i == Ydrip_s2B ? j + 8 : - i == Xacid_1 ? 0 : - i == Xacid_2 ? 10 : - i == Xacid_3 ? 20 : - i == Xacid_4 ? 30 : - i == Xacid_5 ? 40 : - i == Xacid_6 ? 50 : - i == Xacid_7 ? 60 : - i == Xacid_8 ? 70 : - i == Xfake_acid_1 ? 0 : - i == Xfake_acid_2 ? 10 : - i == Xfake_acid_3 ? 20 : - i == Xfake_acid_4 ? 30 : - i == Xfake_acid_5 ? 40 : - i == Xfake_acid_6 ? 50 : - i == Xfake_acid_7 ? 60 : - i == Xfake_acid_8 ? 70 : - i == Xball_2 ? 7 : - i == Xball_2B ? j + 8 : - i == Yball_eat ? j + 1 : - i == Ykey_1_eat ? j + 1 : - i == Ykey_2_eat ? j + 1 : - i == Ykey_3_eat ? j + 1 : - i == Ykey_4_eat ? j + 1 : - i == Ykey_5_eat ? j + 1 : - i == Ykey_6_eat ? j + 1 : - i == Ykey_7_eat ? j + 1 : - i == Ykey_8_eat ? j + 1 : - i == Ylenses_eat ? j + 1 : - i == Ymagnify_eat ? j + 1 : - i == Ygrass_eat ? j + 1 : - i == Ydirt_eat ? j + 1 : - i == Xamoeba_1 ? 0 : - i == Xamoeba_2 ? 1 : - i == Xamoeba_3 ? 2 : - i == Xamoeba_4 ? 3 : - i == Xamoeba_5 ? 0 : - i == Xamoeba_6 ? 1 : - i == Xamoeba_7 ? 2 : - i == Xamoeba_8 ? 3 : - i == Xexit_2 ? j + 8 : - i == Xexit_3 ? j + 16 : - i == Xdynamite_1 ? 0 : - i == Xdynamite_2 ? 8 : - i == Xdynamite_3 ? 16 : - i == Xdynamite_4 ? 24 : - i == Xsand_stonein_1 ? j + 1 : - i == Xsand_stonein_2 ? j + 9 : - i == Xsand_stonein_3 ? j + 17 : - i == Xsand_stonein_4 ? j + 25 : - i == Xsand_stoneout_1 && j == 0 ? 0 : - i == Xsand_stoneout_1 && j == 1 ? 0 : - i == Xsand_stoneout_1 && j == 2 ? 1 : - i == Xsand_stoneout_1 && j == 3 ? 2 : - i == Xsand_stoneout_1 && j == 4 ? 2 : - i == Xsand_stoneout_1 && j == 5 ? 3 : - i == Xsand_stoneout_1 && j == 6 ? 4 : - i == Xsand_stoneout_1 && j == 7 ? 4 : - i == Xsand_stoneout_2 && j == 0 ? 5 : - i == Xsand_stoneout_2 && j == 1 ? 6 : - i == Xsand_stoneout_2 && j == 2 ? 7 : - i == Xsand_stoneout_2 && j == 3 ? 8 : - i == Xsand_stoneout_2 && j == 4 ? 9 : - i == Xsand_stoneout_2 && j == 5 ? 11 : - i == Xsand_stoneout_2 && j == 6 ? 13 : - i == Xsand_stoneout_2 && j == 7 ? 15 : - i == Xboom_bug && j == 1 ? 2 : - i == Xboom_bug && j == 2 ? 2 : - i == Xboom_bug && j == 3 ? 4 : - i == Xboom_bug && j == 4 ? 4 : - i == Xboom_bug && j == 5 ? 2 : - i == Xboom_bug && j == 6 ? 2 : - i == Xboom_bug && j == 7 ? 0 : - i == Xboom_bomb && j == 1 ? 2 : - i == Xboom_bomb && j == 2 ? 2 : - i == Xboom_bomb && j == 3 ? 4 : - i == Xboom_bomb && j == 4 ? 4 : - i == Xboom_bomb && j == 5 ? 2 : - i == Xboom_bomb && j == 6 ? 2 : - i == Xboom_bomb && j == 7 ? 0 : - i == Xboom_android && j == 7 ? 6 : - i == Xboom_1 && j == 1 ? 2 : - i == Xboom_1 && j == 2 ? 2 : - i == Xboom_1 && j == 3 ? 4 : - i == Xboom_1 && j == 4 ? 4 : - i == Xboom_1 && j == 5 ? 6 : - i == Xboom_1 && j == 6 ? 6 : - i == Xboom_1 && j == 7 ? 8 : - i == Xboom_2 && j == 0 ? 8 : - i == Xboom_2 && j == 1 ? 8 : - i == Xboom_2 && j == 2 ? 10 : - i == Xboom_2 && j == 3 ? 10 : - i == Xboom_2 && j == 4 ? 10 : - i == Xboom_2 && j == 5 ? 12 : - i == Xboom_2 && j == 6 ? 12 : - i == Xboom_2 && j == 7 ? 12 : -#if 0 - special_animation && j == 4 ? 3 : - effective_action != action ? 0 : -#endif - j); + int direction = object_mapping[tile].direction; + int move_dir = (action_falling ? MV_DOWN : direction); + + GfxFrame[x][y]++; + +#if 1 + /* !!! TEST !!! NEW !!! DOES NOT WORK RIGHT YET !!! */ + if (g->double_movement && frame_em == 0) + GfxFrame[x][y] = 0; #endif -#if 0 - int xxx_effective_action; - int xxx_has_action_graphics; + if (move_dir == MV_LEFT) + GfxFrame[x - 1][y] = GfxFrame[x][y]; + else if (move_dir == MV_RIGHT) + GfxFrame[x + 1][y] = GfxFrame[x][y]; + else if (move_dir == MV_UP) + GfxFrame[x][y - 1] = GfxFrame[x][y]; + else if (move_dir == MV_DOWN) + GfxFrame[x][y + 1] = GfxFrame[x][y]; + } + } + else + { + GfxFrame[x][y]++; + + /* special case: animation for Xsand_stonesand_quickout_1/2 twice as fast */ + if (tile == Xsand_stonesand_quickout_1 || + tile == Xsand_stonesand_quickout_2) + GfxFrame[x][y]++; + } + + if (graphic_info[graphic].anim_global_sync) + sync_frame = FrameCounter; + else if (IN_FIELD(x, y, MAX_LEV_FIELDX, MAX_LEV_FIELDY)) + sync_frame = GfxFrame[x][y]; + else + sync_frame = 0; /* playfield border (pseudo steel) */ + + SetRandomAnimationValue(x, y); + + int frame = getAnimationFrame(g->anim_frames, + g->anim_delay, + g->anim_mode, + g->anim_start_frame, + sync_frame); + + g_em->unique_identifier = + (graphic << 16) | ((frame % 8) << 12) | (g_em->width << 6) | g_em->height; +} + +void getGraphicSourceObjectExt_EM(struct GraphicInfo_EM *g_em, + int tile, int frame_em, int x, int y) +{ + int action = object_mapping[tile].action; + int direction = object_mapping[tile].direction; + boolean is_backside = object_mapping[tile].is_backside; + int effective_element = get_effective_element_EM(tile, frame_em); + int effective_action = action; + int graphic = (direction == MV_NONE ? + el_act2img(effective_element, effective_action) : + el_act_dir2img(effective_element, effective_action, + direction)); + int crumbled = (direction == MV_NONE ? + el_act2crm(effective_element, effective_action) : + el_act_dir2crm(effective_element, effective_action, + direction)); + int base_graphic = el_act2img(effective_element, ACTION_DEFAULT); + int base_crumbled = el_act2crm(effective_element, ACTION_DEFAULT); + boolean has_crumbled_graphics = (base_crumbled != base_graphic); + struct GraphicInfo *g = &graphic_info[graphic]; + int sync_frame; + /* special case: graphic uses "2nd movement tile" and has defined + 7 frames for movement animation (or less) => use default graphic + for last (8th) frame which ends the movement animation */ + if (g->double_movement && g->anim_frames < 8 && frame_em == 7) { - int element = object_mapping[i].element_rnd; - int action = object_mapping[i].action; - int direction = object_mapping[i].direction; - boolean is_backside = object_mapping[i].is_backside; -#if 0 - boolean action_removing = (action == ACTION_DIGGING || - action == ACTION_SNAPPING || - action == ACTION_COLLECTING); -#endif - boolean action_exploding = ((action == ACTION_EXPLODING || - action == ACTION_SMASHED_BY_ROCK || - action == ACTION_SMASHED_BY_SPRING) && - element != EL_DIAMOND); - boolean action_active = (action == ACTION_ACTIVE); - boolean action_other = (action == ACTION_OTHER); + effective_action = ACTION_DEFAULT; + graphic = (direction == MV_NONE ? + el_act2img(effective_element, effective_action) : + el_act_dir2img(effective_element, effective_action, + direction)); + crumbled = (direction == MV_NONE ? + el_act2crm(effective_element, effective_action) : + el_act_dir2crm(effective_element, effective_action, + direction)); - { -#if 1 - int effective_element = get_effective_element_EM(i, j); -#else - int effective_element = (j > 5 && i == Yacid_splash_eB ? EL_EMPTY : - j > 5 && i == Yacid_splash_wB ? EL_EMPTY : - j < 7 ? element : - i == Xdrip_stretch ? element : - i == Xdrip_stretchB ? element : - i == Ydrip_s1 ? element : - i == Ydrip_s1B ? element : - i == Xball_1B ? element : - i == Xball_2 ? element : - i == Xball_2B ? element : - i == Yball_eat ? element : - i == Ykey_1_eat ? element : - i == Ykey_2_eat ? element : - i == Ykey_3_eat ? element : - i == Ykey_4_eat ? element : - i == Ykey_5_eat ? element : - i == Ykey_6_eat ? element : - i == Ykey_7_eat ? element : - i == Ykey_8_eat ? element : - i == Ylenses_eat ? element : - i == Ymagnify_eat ? element : - i == Ygrass_eat ? element : - i == Ydirt_eat ? element : - i == Yemerald_stone ? EL_EMERALD : - i == Ydiamond_stone ? EL_ROCK : - i == Xsand_stonein_1 ? element : - i == Xsand_stonein_2 ? element : - i == Xsand_stonein_3 ? element : - i == Xsand_stonein_4 ? element : - is_backside ? EL_EMPTY : - action_removing ? EL_EMPTY : - element); -#endif - int effective_action = (j < 7 ? action : - i == Xdrip_stretch ? action : - i == Xdrip_stretchB ? action : - i == Ydrip_s1 ? action : - i == Ydrip_s1B ? action : - i == Xball_1B ? action : - i == Xball_2 ? action : - i == Xball_2B ? action : - i == Yball_eat ? action : - i == Ykey_1_eat ? action : - i == Ykey_2_eat ? action : - i == Ykey_3_eat ? action : - i == Ykey_4_eat ? action : - i == Ykey_5_eat ? action : - i == Ykey_6_eat ? action : - i == Ykey_7_eat ? action : - i == Ykey_8_eat ? action : - i == Ylenses_eat ? action : - i == Ymagnify_eat ? action : - i == Ygrass_eat ? action : - i == Ydirt_eat ? action : - i == Xsand_stonein_1 ? action : - i == Xsand_stonein_2 ? action : - i == Xsand_stonein_3 ? action : - i == Xsand_stonein_4 ? action : - i == Xsand_stoneout_1 ? action : - i == Xsand_stoneout_2 ? action : - i == Xboom_android ? ACTION_EXPLODING : - action_exploding ? ACTION_EXPLODING : - action_active ? action : - action_other ? action : - ACTION_DEFAULT); - int graphic = (el_act_dir2img(effective_element, effective_action, - direction)); - int crumbled = (el_act_dir2crm(effective_element, effective_action, - direction)); - int base_graphic = el_act2img(effective_element, ACTION_DEFAULT); - int base_crumbled = el_act2crm(effective_element, ACTION_DEFAULT); - boolean has_action_graphics = (graphic != base_graphic); - boolean has_crumbled_graphics = (base_crumbled != base_graphic); - struct GraphicInfo *g = &graphic_info[graphic]; -#if 0 - struct GraphicInfo *g_crumbled = &graphic_info[crumbled]; -#endif - struct GraphicInfo_EM *g_em = &graphic_info_em_object[i][7 - j]; - Bitmap *src_bitmap; - int src_x, src_y; - /* ensure to get symmetric 3-frame, 2-delay animations as used in EM */ - boolean special_animation = (action != ACTION_DEFAULT && - g->anim_frames == 3 && - g->anim_delay == 2 && - g->anim_mode & ANIM_LINEAR); - xxx_sync_frame = (i == Xdrip_stretch ? 7 : - i == Xdrip_stretchB ? 7 : - i == Ydrip_s2 ? j + 8 : - i == Ydrip_s2B ? j + 8 : - i == Xacid_1 ? 0 : - i == Xacid_2 ? 10 : - i == Xacid_3 ? 20 : - i == Xacid_4 ? 30 : - i == Xacid_5 ? 40 : - i == Xacid_6 ? 50 : - i == Xacid_7 ? 60 : - i == Xacid_8 ? 70 : - i == Xfake_acid_1 ? 0 : - i == Xfake_acid_2 ? 10 : - i == Xfake_acid_3 ? 20 : - i == Xfake_acid_4 ? 30 : - i == Xfake_acid_5 ? 40 : - i == Xfake_acid_6 ? 50 : - i == Xfake_acid_7 ? 60 : - i == Xfake_acid_8 ? 70 : - i == Xball_2 ? 7 : - i == Xball_2B ? j + 8 : - i == Yball_eat ? j + 1 : - i == Ykey_1_eat ? j + 1 : - i == Ykey_2_eat ? j + 1 : - i == Ykey_3_eat ? j + 1 : - i == Ykey_4_eat ? j + 1 : - i == Ykey_5_eat ? j + 1 : - i == Ykey_6_eat ? j + 1 : - i == Ykey_7_eat ? j + 1 : - i == Ykey_8_eat ? j + 1 : - i == Ylenses_eat ? j + 1 : - i == Ymagnify_eat ? j + 1 : - i == Ygrass_eat ? j + 1 : - i == Ydirt_eat ? j + 1 : - i == Xamoeba_1 ? 0 : - i == Xamoeba_2 ? 1 : - i == Xamoeba_3 ? 2 : - i == Xamoeba_4 ? 3 : - i == Xamoeba_5 ? 0 : - i == Xamoeba_6 ? 1 : - i == Xamoeba_7 ? 2 : - i == Xamoeba_8 ? 3 : - i == Xexit_2 ? j + 8 : - i == Xexit_3 ? j + 16 : - i == Xdynamite_1 ? 0 : - i == Xdynamite_2 ? 8 : - i == Xdynamite_3 ? 16 : - i == Xdynamite_4 ? 24 : - i == Xsand_stonein_1 ? j + 1 : - i == Xsand_stonein_2 ? j + 9 : - i == Xsand_stonein_3 ? j + 17 : - i == Xsand_stonein_4 ? j + 25 : - i == Xsand_stoneout_1 && j == 0 ? 0 : - i == Xsand_stoneout_1 && j == 1 ? 0 : - i == Xsand_stoneout_1 && j == 2 ? 1 : - i == Xsand_stoneout_1 && j == 3 ? 2 : - i == Xsand_stoneout_1 && j == 4 ? 2 : - i == Xsand_stoneout_1 && j == 5 ? 3 : - i == Xsand_stoneout_1 && j == 6 ? 4 : - i == Xsand_stoneout_1 && j == 7 ? 4 : - i == Xsand_stoneout_2 && j == 0 ? 5 : - i == Xsand_stoneout_2 && j == 1 ? 6 : - i == Xsand_stoneout_2 && j == 2 ? 7 : - i == Xsand_stoneout_2 && j == 3 ? 8 : - i == Xsand_stoneout_2 && j == 4 ? 9 : - i == Xsand_stoneout_2 && j == 5 ? 11 : - i == Xsand_stoneout_2 && j == 6 ? 13 : - i == Xsand_stoneout_2 && j == 7 ? 15 : - i == Xboom_bug && j == 1 ? 2 : - i == Xboom_bug && j == 2 ? 2 : - i == Xboom_bug && j == 3 ? 4 : - i == Xboom_bug && j == 4 ? 4 : - i == Xboom_bug && j == 5 ? 2 : - i == Xboom_bug && j == 6 ? 2 : - i == Xboom_bug && j == 7 ? 0 : - i == Xboom_bomb && j == 1 ? 2 : - i == Xboom_bomb && j == 2 ? 2 : - i == Xboom_bomb && j == 3 ? 4 : - i == Xboom_bomb && j == 4 ? 4 : - i == Xboom_bomb && j == 5 ? 2 : - i == Xboom_bomb && j == 6 ? 2 : - i == Xboom_bomb && j == 7 ? 0 : - i == Xboom_android && j == 7 ? 6 : - i == Xboom_1 && j == 1 ? 2 : - i == Xboom_1 && j == 2 ? 2 : - i == Xboom_1 && j == 3 ? 4 : - i == Xboom_1 && j == 4 ? 4 : - i == Xboom_1 && j == 5 ? 6 : - i == Xboom_1 && j == 6 ? 6 : - i == Xboom_1 && j == 7 ? 8 : - i == Xboom_2 && j == 0 ? 8 : - i == Xboom_2 && j == 1 ? 8 : - i == Xboom_2 && j == 2 ? 10 : - i == Xboom_2 && j == 3 ? 10 : - i == Xboom_2 && j == 4 ? 10 : - i == Xboom_2 && j == 5 ? 12 : - i == Xboom_2 && j == 6 ? 12 : - i == Xboom_2 && j == 7 ? 12 : - special_animation && j == 4 ? 3 : - effective_action != action ? 0 : - j); + g = &graphic_info[graphic]; + } + + if (graphic_info[graphic].anim_global_sync) + sync_frame = FrameCounter; + else if (IN_FIELD(x, y, MAX_LEV_FIELDX, MAX_LEV_FIELDY)) + sync_frame = GfxFrame[x][y]; + else + sync_frame = 0; /* playfield border (pseudo steel) */ - xxx_effective_action = effective_action; - xxx_has_action_graphics = has_action_graphics; - } - } -#endif + SetRandomAnimationValue(x, y); int frame = getAnimationFrame(g->anim_frames, g->anim_delay, @@ -10407,183 +7194,13 @@ void getGraphicSourceObjectExt_EM(struct GraphicInfo_EM *g_em, g->anim_start_frame, sync_frame); - -#if 0 - return; -#endif - -#if 0 - if (frame_em == 7) - return; -#endif - -#if 0 - int old_src_x = g_em->src_x; - int old_src_y = g_em->src_y; -#endif - -#if 1 getGraphicSourceExt(graphic, frame, &g_em->bitmap, &g_em->src_x, &g_em->src_y, g->double_movement && is_backside); -#else - getGraphicSourceExt(graphic, frame, &g_em->bitmap, - &g_em->src_x, &g_em->src_y, FALSE); -#endif - - -#if 0 - if (tile == Ydiamond_stone) - printf("::: stone smashing diamond... %d: %d, %d, %d, %d, %d -> %d [%d, %d, %d, %d, %d, %d] [%d]\n", - frame_em, - g->anim_frames, - g->anim_delay, - g->anim_mode, - g->anim_start_frame, - sync_frame, - frame, - g_em->src_x, g_em->src_y, - g_em->src_offset_x, g_em->src_offset_y, - g_em->dst_offset_x, g_em->dst_offset_y, - graphic); -#endif - - -#if 0 - return; -#endif - -#if 0 - if (frame_em == 7) - { - if (graphic == IMG_BUG_MOVING_RIGHT) - printf("::: %d, %d, %d: %d, %d [%d, %d -> %d, %d]\n", graphic, x, y, - g->double_movement, is_backside, - old_src_x, old_src_y, g_em->src_x, g_em->src_y); - - return; - } -#endif - - -#if 0 - g_em->src_offset_x = 0; - g_em->src_offset_y = 0; - g_em->dst_offset_x = 0; - g_em->dst_offset_y = 0; - g_em->width = TILEX; - g_em->height = TILEY; - - g_em->preserve_background = FALSE; -#endif /* (updating the "crumbled" graphic definitions is probably not really needed, as animations for crumbled graphics can't be longer than one EMC cycle) */ -#if 1 set_crumbled_graphics_EM(g_em, has_crumbled_graphics, crumbled, sync_frame); - -#else - - g_em->crumbled_bitmap = NULL; - g_em->crumbled_src_x = 0; - g_em->crumbled_src_y = 0; - - g_em->has_crumbled_graphics = FALSE; - - if (has_crumbled_graphics && crumbled != IMG_EMPTY_SPACE) - { - int frame_crumbled = getAnimationFrame(g_crumbled->anim_frames, - g_crumbled->anim_delay, - g_crumbled->anim_mode, - g_crumbled->anim_start_frame, - sync_frame); - - getGraphicSource(crumbled, frame_crumbled, &g_em->crumbled_bitmap, - &g_em->crumbled_src_x, &g_em->crumbled_src_y); - - g_em->has_crumbled_graphics = TRUE; - } -#endif - -#if 0 - { - int effective_action = xxx_effective_action; - int has_action_graphics = xxx_has_action_graphics; - - if ((!g->double_movement && (effective_action == ACTION_FALLING || - effective_action == ACTION_MOVING || - effective_action == ACTION_PUSHING || - effective_action == ACTION_EATING)) || - (!has_action_graphics && (effective_action == ACTION_FILLING || - effective_action == ACTION_EMPTYING))) - { - int move_dir = - (effective_action == ACTION_FALLING || - effective_action == ACTION_FILLING || - effective_action == ACTION_EMPTYING ? MV_DOWN : direction); - int dx = (move_dir == MV_LEFT ? -1 : move_dir == MV_RIGHT ? 1 : 0); - int dy = (move_dir == MV_UP ? -1 : move_dir == MV_DOWN ? 1 : 0); - int num_steps = (i == Ydrip_s1 ? 16 : - i == Ydrip_s1B ? 16 : - i == Ydrip_s2 ? 16 : - i == Ydrip_s2B ? 16 : - i == Xsand_stonein_1 ? 32 : - i == Xsand_stonein_2 ? 32 : - i == Xsand_stonein_3 ? 32 : - i == Xsand_stonein_4 ? 32 : - i == Xsand_stoneout_1 ? 16 : - i == Xsand_stoneout_2 ? 16 : 8); - int cx = ABS(dx) * (TILEX / num_steps); - int cy = ABS(dy) * (TILEY / num_steps); - int step_frame = (i == Ydrip_s2 ? j + 8 : - i == Ydrip_s2B ? j + 8 : - i == Xsand_stonein_2 ? j + 8 : - i == Xsand_stonein_3 ? j + 16 : - i == Xsand_stonein_4 ? j + 24 : - i == Xsand_stoneout_2 ? j + 8 : j) + 1; - int step = (is_backside ? step_frame : num_steps - step_frame); - - if (is_backside) /* tile where movement starts */ - { - if (dx < 0 || dy < 0) - { - g_em->src_offset_x = cx * step; - g_em->src_offset_y = cy * step; - } - else - { - g_em->dst_offset_x = cx * step; - g_em->dst_offset_y = cy * step; - } - } - else /* tile where movement ends */ - { - if (dx < 0 || dy < 0) - { - g_em->dst_offset_x = cx * step; - g_em->dst_offset_y = cy * step; - } - else - { - g_em->src_offset_x = cx * step; - g_em->src_offset_y = cy * step; - } - } - - g_em->width = TILEX - cx * step; - g_em->height = TILEY - cy * step; - } - - /* create unique graphic identifier to decide if tile must be redrawn */ - /* bit 31 - 16 (16 bit): EM style graphic - bit 15 - 12 ( 4 bit): EM style frame - bit 11 - 6 ( 6 bit): graphic width - bit 5 - 0 ( 6 bit): graphic height */ - g_em->unique_identifier = - (graphic << 16) | (frame << 12) | (g_em->width << 6) | g_em->height; - } -#endif - } void getGraphicSourcePlayerExt_EM(struct GraphicInfo_EM *g_em, @@ -10612,22 +7229,10 @@ void getGraphicSourcePlayerExt_EM(struct GraphicInfo_EM *g_em, getGraphicSourceExt(graphic, frame, &g_em->bitmap, &g_em->src_x, &g_em->src_y, FALSE); - -#if 0 - printf("::: %d: %d, %d [%d]\n", - player_nr, - stored_player[player_nr].Frame, - stored_player[player_nr].StepFrame, - FrameCounter); -#endif } void InitGraphicInfo_EM(void) { -#if 0 - struct Mapping_EM_to_RND_object object_mapping[TILE_MAX]; - struct Mapping_EM_to_RND_player player_mapping[MAX_PLAYERS][SPR_MAX]; -#endif int i, j, p; #if DEBUG_EM_GFX @@ -10699,11 +7304,6 @@ void InitGraphicInfo_EM(void) int action = object_mapping[i].action; int direction = object_mapping[i].direction; boolean is_backside = object_mapping[i].is_backside; -#if 0 - boolean action_removing = (action == ACTION_DIGGING || - action == ACTION_SNAPPING || - action == ACTION_COLLECTING); -#endif boolean action_exploding = ((action == ACTION_EXPLODING || action == ACTION_SMASHED_BY_ROCK || action == ACTION_SMASHED_BY_SPRING) && @@ -10713,42 +7313,7 @@ void InitGraphicInfo_EM(void) for (j = 0; j < 8; j++) { -#if 1 int effective_element = get_effective_element_EM(i, j); -#else - int effective_element = (j > 5 && i == Yacid_splash_eB ? EL_EMPTY : - j > 5 && i == Yacid_splash_wB ? EL_EMPTY : - j < 7 ? element : - i == Xdrip_stretch ? element : - i == Xdrip_stretchB ? element : - i == Ydrip_s1 ? element : - i == Ydrip_s1B ? element : - i == Xball_1B ? element : - i == Xball_2 ? element : - i == Xball_2B ? element : - i == Yball_eat ? element : - i == Ykey_1_eat ? element : - i == Ykey_2_eat ? element : - i == Ykey_3_eat ? element : - i == Ykey_4_eat ? element : - i == Ykey_5_eat ? element : - i == Ykey_6_eat ? element : - i == Ykey_7_eat ? element : - i == Ykey_8_eat ? element : - i == Ylenses_eat ? element : - i == Ymagnify_eat ? element : - i == Ygrass_eat ? element : - i == Ydirt_eat ? element : - i == Yemerald_stone ? EL_EMERALD : - i == Ydiamond_stone ? EL_ROCK : - i == Xsand_stonein_1 ? element : - i == Xsand_stonein_2 ? element : - i == Xsand_stonein_3 ? element : - i == Xsand_stonein_4 ? element : - is_backside ? EL_EMPTY : - action_removing ? EL_EMPTY : - element); -#endif int effective_action = (j < 7 ? action : i == Xdrip_stretch ? action : i == Xdrip_stretchB ? action : @@ -10790,9 +7355,6 @@ void InitGraphicInfo_EM(void) boolean has_action_graphics = (graphic != base_graphic); boolean has_crumbled_graphics = (base_crumbled != base_graphic); struct GraphicInfo *g = &graphic_info[graphic]; -#if 0 - struct GraphicInfo *g_crumbled = &graphic_info[crumbled]; -#endif struct GraphicInfo_EM *g_em = &graphic_info_em_object[i][7 - j]; Bitmap *src_bitmap; int src_x, src_y; @@ -10931,75 +7493,9 @@ void InitGraphicInfo_EM(void) g_em->preserve_background = FALSE; -#if 1 set_crumbled_graphics_EM(g_em, has_crumbled_graphics, crumbled, sync_frame); -#else - - g_em->crumbled_bitmap = NULL; - g_em->crumbled_src_x = 0; - g_em->crumbled_src_y = 0; - g_em->crumbled_border_size = 0; - - g_em->has_crumbled_graphics = FALSE; - -#if 0 - if (has_crumbled_graphics && crumbled == IMG_EMPTY_SPACE) - printf("::: empty crumbled: %d [%s], %d, %d\n", - effective_element, element_info[effective_element].token_name, - effective_action, direction); -#endif - - /* if element can be crumbled, but certain action graphics are just empty - space (like instantly snapping sand to empty space in 1 frame), do not - treat these empty space graphics as crumbled graphics in EMC engine */ - if (has_crumbled_graphics && crumbled != IMG_EMPTY_SPACE) - { - int frame_crumbled = getAnimationFrame(g_crumbled->anim_frames, - g_crumbled->anim_delay, - g_crumbled->anim_mode, - g_crumbled->anim_start_frame, - sync_frame); - - getGraphicSource(crumbled, frame_crumbled, &src_bitmap, &src_x, &src_y); - - g_em->has_crumbled_graphics = TRUE; - g_em->crumbled_bitmap = src_bitmap; - g_em->crumbled_src_x = src_x; - g_em->crumbled_src_y = src_y; - g_em->crumbled_border_size = graphic_info[crumbled].border_size; - - -#if 0 - if (g_em == &graphic_info_em_object[207][0]) - printf("... %d, %d [%d, %d, %d, %d] [%d, %d, %d, %d, %d, %d => %d]\n", - graphic_info_em_object[207][0].crumbled_src_x, - graphic_info_em_object[207][0].crumbled_src_y, - - crumbled, frame, src_x, src_y, - - g->anim_frames, - g->anim_delay, - g->anim_mode, - g->anim_start_frame, - sync_frame, - gfx.anim_random_frame, - frame); -#endif - -#if 0 - printf("::: EMC tile %d is crumbled\n", i); -#endif - } -#endif - -#if 0 - if (element == EL_ROCK && - effective_action == ACTION_FILLING) - printf("::: has_action_graphics == %d\n", has_action_graphics); -#endif - if ((!g->double_movement && (effective_action == ACTION_FALLING || effective_action == ACTION_MOVING || effective_action == ACTION_PUSHING || @@ -11295,42 +7791,16 @@ void CheckSingleStepMode_EM(byte action[MAX_PLAYERS], int frame, boolean player_is_dropping) { if (tape.single_step && tape.recording && !tape.pausing) - { -#if 0 - boolean active_players = FALSE; - int i; - - for (i = 0; i < MAX_PLAYERS; i++) - if (action[i] != JOY_NO_ACTION) - active_players = TRUE; -#endif - - // if (frame == 0) if (frame == 0 && !player_is_dropping) TapeTogglePause(TAPE_TOGGLE_AUTOMATIC); - } } void CheckSingleStepMode_SP(boolean murphy_is_waiting, boolean murphy_is_dropping) { -#if 0 - printf("::: waiting: %d, dropping: %d\n", - murphy_is_waiting, murphy_is_dropping); -#endif - if (tape.single_step && tape.recording && !tape.pausing) - { - // if (murphy_is_waiting || murphy_is_dropping) if (murphy_is_waiting) - { -#if 0 - printf("::: murphy is waiting -> pause mode\n"); -#endif - TapeTogglePause(TAPE_TOGGLE_AUTOMATIC); - } - } } void getGraphicSource_SP(struct GraphicInfo_SP *g_sp, @@ -11501,30 +7971,14 @@ void ToggleFullscreenOrChangeWindowScalingIfNeeded() FreeBitmap(tmp_backbuffer); -#if 1 /* update visible window/screen */ BlitBitmap(backbuffer, window, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); -#else - redraw_mask = REDRAW_ALL; -#endif } } void ChangeViewportPropertiesIfNeeded() { -#if 0 - int *door_1_x = &DX; - int *door_1_y = &DY; - int *door_2_x = (game_status == GAME_MODE_EDITOR ? &EX : &VX); - int *door_2_y = (game_status == GAME_MODE_EDITOR ? &EY : &VY); -#endif -#if 1 int gfx_game_mode = game_status; -#else - int gfx_game_mode = (game_status == GAME_MODE_PLAYING || - game_status == GAME_MODE_EDITOR ? game_status : - GAME_MODE_MAIN); -#endif int gfx_game_mode2 = (game_status == GAME_MODE_EDITOR ? GAME_MODE_DEFAULT : game_status); struct RectWithBorder *vp_playfield = &viewport.playfield[gfx_game_mode]; @@ -11552,14 +8006,8 @@ void ChangeViewportPropertiesIfNeeded() int new_ey = vp_door_3->y; int new_exsize = vp_door_3->width; int new_eysize = vp_door_3->height; -#if NEW_TILESIZE - -#if NEW_GAME_TILESIZE int new_tilesize_var = (setup.small_game_graphics ? MINI_TILESIZE : game.tile_size); -#else - int new_tilesize_var = TILESIZE / (setup.small_game_graphics ? 2 : 1); -#endif int tilesize = (gfx_game_mode == GAME_MODE_PLAYING ? new_tilesize_var : gfx_game_mode == GAME_MODE_EDITOR ? MINI_TILESIZE : TILESIZE); @@ -11567,41 +8015,19 @@ void ChangeViewportPropertiesIfNeeded() int new_scr_fieldy = new_sysize / tilesize; int new_scr_fieldx_buffers = new_sxsize / new_tilesize_var; int new_scr_fieldy_buffers = new_sysize / new_tilesize_var; -#else - int new_scr_fieldx = (vp_playfield->width - 2 * border_size) / TILESIZE; - int new_scr_fieldy = (vp_playfield->height - 2 * border_size) / TILESIZE; -#endif boolean init_gfx_buffers = FALSE; boolean init_video_buffer = FALSE; boolean init_gadgets_and_toons = FALSE; boolean init_em_graphics = FALSE; -#if 0 - /* !!! TEST ONLY !!! */ - // InitGfxBuffers(); - return; -#endif - if (viewport.window.width != WIN_XSIZE || viewport.window.height != WIN_YSIZE) { WIN_XSIZE = viewport.window.width; WIN_YSIZE = viewport.window.height; -#if 1 init_video_buffer = TRUE; init_gfx_buffers = TRUE; -#else - InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen); - InitGfxBuffers(); - -#if 1 - SetDrawDeactivationMask(REDRAW_NONE); - SetDrawBackgroundMask(REDRAW_FIELD); - - // RedrawBackground(); -#endif -#endif // printf("::: video: init_video_buffer, init_gfx_buffers\n"); } @@ -11617,20 +8043,6 @@ void ChangeViewportPropertiesIfNeeded() // printf("::: new_scr_fieldx != SCR_FIELDX ...\n"); } -#if 0 - if (new_tilesize_var != TILESIZE_VAR && - gfx_game_mode == GAME_MODE_PLAYING) - { - /* doing this outside GAME_MODE_PLAYING would give wrong playfield size */ - - TILESIZE_VAR = new_tilesize_var; - - init_gfx_buffers = TRUE; - - // printf("::: tilesize: init_gfx_buffers\n"); - } -#endif - if (new_sx != SX || new_sy != SY || new_dx != DX || @@ -11652,16 +8064,8 @@ void ChangeViewportPropertiesIfNeeded() new_full_sxsize != FULL_SXSIZE || new_full_sysize != FULL_SYSIZE || new_tilesize_var != TILESIZE_VAR -#if 0 - || - vp_door_1->x != *door_1_x || - vp_door_1->y != *door_1_y || - vp_door_2->x != *door_2_x || - vp_door_2->y != *door_2_y -#endif ) { -#if 1 if (new_tilesize_var != TILESIZE_VAR) { // printf("::: new_tilesize_var != TILESIZE_VAR\n"); @@ -11672,7 +8076,6 @@ void ChangeViewportPropertiesIfNeeded() // changing tile size requires update of graphic mapping for EM engine init_em_graphics = TRUE; } -#endif SX = new_sx; SY = new_sy; @@ -11696,40 +8099,11 @@ void ChangeViewportPropertiesIfNeeded() FULL_SYSIZE = new_full_sysize; TILESIZE_VAR = new_tilesize_var; -#if 0 - printf("::: %d, %d, %d [%d]\n", - SCR_FIELDX, SCR_FIELDY, TILESIZE_VAR, - setup.small_game_graphics); -#endif - -#if 0 - *door_1_x = vp_door_1->x; - *door_1_y = vp_door_1->y; - *door_2_x = vp_door_2->x; - *door_2_y = vp_door_2->y; -#endif - -#if 1 init_gfx_buffers = TRUE; + init_gadgets_and_toons = TRUE; // printf("::: viewports: init_gfx_buffers\n"); -#else - InitGfxBuffers(); -#endif - -#if 0 - if (gfx_game_mode == GAME_MODE_MAIN) -#endif - { -#if 1 - init_gadgets_and_toons = TRUE; - - // printf("::: viewports: init_gadgets_and_toons\n"); -#else - InitGadgets(); - InitToons(); -#endif - } + // printf("::: viewports: init_gadgets_and_toons\n"); } if (init_gfx_buffers) @@ -11767,8 +8141,4 @@ void ChangeViewportPropertiesIfNeeded() { InitGraphicInfo_EM(); } - -#if 0 - printf("::: %d, %d / %d, %d [%d]\n", VX, VY, EX, EY, game_status); -#endif } diff --git a/src/tools.h b/src/tools.h index 37f7d06b..638a22fe 100644 --- a/src/tools.h +++ b/src/tools.h @@ -78,11 +78,7 @@ void DrawMaskedBorder_ALL(); void DrawMaskedBorder(int); void SetDrawtoField(int); -#if 1 void RedrawPlayfield(); -#else -void RedrawPlayfield(boolean, int, int, int, int); -#endif void BlitScreenToBitmap(Bitmap *); void BackToFront(); -- 2.34.1