X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=6d32cd3b46158d149470e58a04e890ffd37a147e;hb=aacdd16335c68a011fab047272b828792a2a884e;hp=b689911c61d11ebc893b3d29a5a180cb3edb33e1;hpb=b8ccb648b89e24b27f8a60e2d8e9a4680322bd86;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index b689911c..6d32cd3b 100644 --- a/src/init.c +++ b/src/init.c @@ -24,306 +24,18 @@ #include "network.h" #include "netserv.h" #include "cartoons.h" -#include "config.h" #include "conf_e2g.c" /* include auto-generated data structure definitions */ #include "conf_esg.c" /* include auto-generated data structure definitions */ #include "conf_e2s.c" /* include auto-generated data structure definitions */ #include "conf_fnt.c" /* include auto-generated data structure definitions */ -#define CONFIG_TOKEN_FONT_INITIAL "font.initial" - -struct FontBitmapInfo font_initial[NUM_INITIAL_FONTS]; - -static void InitGlobal(); -static void InitSetup(); -static void InitPlayerInfo(); -static void InitLevelInfo(); -static void InitArtworkInfo(); -static void InitLevelArtworkInfo(); -static void InitNetworkServer(); -static void InitArtworkConfig(); -static void InitImages(); -static void InitMixer(); -static void InitSound(); -static void InitMusic(); -static void InitGfx(); -static void InitGfxBackground(); -static void InitGadgets(); -static void InitFontGraphicInfo(); -static void InitElementSmallImages(); -static void InitElementGraphicInfo(); -static void InitElementSpecialGraphicInfo(); -static void InitElementSoundInfo(); -static void InitElementProperties(); -static void InitGraphicInfo(); -static void InitSoundInfo(); -static void Execute_Command(char *); - -void OpenAll() -{ - InitGlobal(); /* initialize some global variables */ - - if (options.execute_command) - Execute_Command(options.execute_command); - - if (options.serveronly) - { -#if defined(PLATFORM_UNIX) - NetworkServer(options.server_port, options.serveronly); -#else - Error(ERR_WARN, "networking only supported in Unix version"); -#endif - exit(0); /* never reached */ - } - - InitProgramInfo(UNIX_USERDATA_DIRECTORY, - PROGRAM_TITLE_STRING, getWindowTitleString(), - ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME, - MSDOS_POINTER_FILENAME, - COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL); - - InitSetup(); - InitPlayerInfo(); - InitArtworkInfo(); /* needed before loading gfx, sound & music */ - InitArtworkConfig(); /* needed before forking sound child process */ - InitMixer(); - - InitCounter(); - - InitJoysticks(); - InitRND(NEW_RANDOMIZE); - - InitVideoDisplay(); - InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, - setup.fullscreen); - - InitEventFilter(FilterMouseMotionEvents); - - InitElementProperties(); - - InitGfx(); - - InitLevelInfo(); - InitLevelArtworkInfo(); - - InitImages(); /* needs to know current level directory */ - InitSound(); /* needs to know current level directory */ - InitMusic(); /* needs to know current level directory */ - - InitGfxBackground(); - - if (global.autoplay_leveldir) - { - AutoPlayTape(); - return; - } - - game_status = MAINMENU; - - DrawMainMenu(); - - InitNetworkServer(); -} - -static void InitGlobal() -{ - global.autoplay_leveldir = NULL; - - global.frames_per_second = 0; - global.fps_slowdown = FALSE; - global.fps_slowdown_factor = 1; -} - -static void InitSetup() -{ - LoadSetup(); /* global setup info */ -} - -static void InitPlayerInfo() -{ - int i; - - /* choose default local player */ - local_player = &stored_player[0]; - - for (i=0; iconnected = TRUE; -} - -static void InitLevelInfo() -{ - LoadLevelInfo(); /* global level info */ - LoadLevelSetup_LastSeries(); /* last played series info */ - LoadLevelSetup_SeriesInfo(); /* last played level info */ -} - -static void InitArtworkInfo() -{ - LoadArtworkInfo(); -} - -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 void InitArtworkConfig() -{ - static char *image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS + 1]; - static char *sound_id_prefix[MAX_NUM_ELEMENTS + MAX_NUM_ELEMENTS + 1]; - static char *action_id_suffix[NUM_ACTIONS + 1]; - static char *direction_id_suffix[NUM_DIRECTIONS + 1]; - static char *special_id_suffix[NUM_SPECIAL_GFX_ARGS + 1]; - static char *dummy[1] = { NULL }; - static char *ignore_image_tokens[] = - { - "name", - "sort_priority", - "global.num_toons", - "menu.draw_xoffset", - "menu.draw_yoffset", - "menu.draw_xoffset.MAIN", - "menu.draw_yoffset.MAIN", - "door.step_offset", - "door.step_delay", - NULL - }; - static char *ignore_sound_tokens[] = - { - "name", - "sort_priority", - NULL - }; - int i; - - for (i=0; iidentifier); - ReinitializeSounds(); -} +struct FontBitmapInfo font_initial[NUM_INITIAL_FONTS]; -static void InitMusic() -{ - InitReloadCustomMusic(artwork.mus_current->identifier); - ReinitializeMusic(); -} static void InitTileClipmasks() { @@ -499,227 +211,7 @@ void FreeTileClipmasks() #endif } -void InitGfx() -{ - char *filename_font_initial = NULL; - Bitmap *bitmap_font_initial = NULL; - int i, j; - - /* determine settings for initial font (for displaying startup messages) */ - for (i=0; image_config[i].token != NULL; i++) - { - for (j=0; j < NUM_INITIAL_FONTS; j++) - { - char font_token[128]; - int len_font_token; - - sprintf(font_token, "%s_%d", CONFIG_TOKEN_FONT_INITIAL, j + 1); - len_font_token = strlen(font_token); - - if (strcmp(image_config[i].token, font_token) == 0) - filename_font_initial = image_config[i].value; - else if (strlen(image_config[i].token) > len_font_token && - strncmp(image_config[i].token, font_token, len_font_token) == 0) - { - if (strcmp(&image_config[i].token[len_font_token], ".x") == 0) - font_initial[j].src_x = atoi(image_config[i].value); - else if (strcmp(&image_config[i].token[len_font_token], ".y") == 0) - font_initial[j].src_y = atoi(image_config[i].value); - else if (strcmp(&image_config[i].token[len_font_token], ".width") == 0) - font_initial[j].width = atoi(image_config[i].value); - else if (strcmp(&image_config[i].token[len_font_token],".height") == 0) - font_initial[j].height = atoi(image_config[i].value); - } - } - } - - if (filename_font_initial == NULL) /* should not happen */ - Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL); - - /* initialize screen properties */ - InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE, - REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); - InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE); - InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE); - InitGfxScrollbufferInfo(FXSIZE, FYSIZE); - - /* create additional image buffers for double-buffering */ - bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH); - bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH); - - bitmap_font_initial = LoadCustomImage(filename_font_initial); - - for (j=0; j < NUM_INITIAL_FONTS; j++) - font_initial[j].bitmap = bitmap_font_initial; - - InitFontGraphicInfo(); - - DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW); - DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED); - - DrawInitText("Loading graphics:", 120, FC_GREEN); - - InitTileClipmasks(); -} - -void InitGfxBackground() -{ - int x, y; - - drawto = backbuffer; - fieldbuffer = bitmap_db_field; - SetDrawtoField(DRAW_BACKBUFFER); - - BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer, - 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); - ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); - ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE); - - for (x=0; xidentifier; - char *snd_new_identifier = artwork.snd_current->identifier; - char *mus_new_identifier = artwork.mus_current->identifier; - boolean redraw_screen = FALSE; - - if (leveldir_current_identifier == NULL) - leveldir_current_identifier = leveldir_current->identifier; - -#if 0 - printf("CURRENT GFX: '%s' ['%s']\n", artwork.gfx_current->identifier, - leveldir_current->graphics_set); - printf("CURRENT LEV: '%s' / '%s'\n", leveldir_current_identifier, - leveldir_current->identifier); -#endif - -#if 0 - printf("graphics --> '%s' ('%s')\n", - artwork.gfx_current_identifier, artwork.gfx_current->filename); - printf("sounds --> '%s' ('%s')\n", - artwork.snd_current_identifier, artwork.snd_current->filename); - printf("music --> '%s' ('%s')\n", - artwork.mus_current_identifier, artwork.mus_current->filename); -#endif - - /* leveldir_current may be invalid (level group, parent link) */ - if (!validLevelSeries(leveldir_current)) - return; - - /* when a new level series was selected, check if there was a change - in custom artwork stored in level series directory */ - if (leveldir_current_identifier != leveldir_current->identifier) - { - char *identifier_old = leveldir_current_identifier; - char *identifier_new = leveldir_current->identifier; - - if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) != - getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new)) - gfx_new_identifier = identifier_new; - if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) != - getTreeInfoFromIdentifier(artwork.snd_first, identifier_new)) - snd_new_identifier = identifier_new; - if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) != - getTreeInfoFromIdentifier(artwork.mus_first, identifier_new)) - mus_new_identifier = identifier_new; - - leveldir_current_identifier = leveldir_current->identifier; - } - - /* custom level artwork configured in level series configuration file - always overrides custom level artwork stored in level series directory - and (level independant) custom artwork configured in setup menue */ - if (leveldir_current->graphics_set != NULL) - gfx_new_identifier = leveldir_current->graphics_set; - if (leveldir_current->sounds_set != NULL) - snd_new_identifier = leveldir_current->sounds_set; - if (leveldir_current->music_set != NULL) - mus_new_identifier = leveldir_current->music_set; - - if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 || - last_override_level_graphics != setup.override_level_graphics) - { -#if 0 - printf("RELOADING GRAPHICS '%s' -> '%s' ('%s')\n", - artwork.gfx_current_identifier, - artwork.gfx_current->identifier, - gfx_new_identifier); -#endif - - setLevelArtworkDir(artwork.gfx_first); - - ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE); - - InitImages(); - - FreeTileClipmasks(); - InitTileClipmasks(); - - artwork.gfx_current_identifier = artwork.gfx_current->identifier; - last_override_level_graphics = setup.override_level_graphics; - - redraw_screen = TRUE; - } - - if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 || - last_override_level_sounds != setup.override_level_sounds) - { -#if 0 - printf("RELOADING SOUNDS '%s' -> '%s' ('%s')\n", - artwork.snd_current_identifier, - artwork.snd_current->identifier, - snd_new_identifier); -#endif - - /* set artwork path to send it to the sound server process */ - setLevelArtworkDir(artwork.snd_first); - - InitReloadCustomSounds(snd_new_identifier); - ReinitializeSounds(); - - artwork.snd_current_identifier = artwork.snd_current->identifier; - last_override_level_sounds = setup.override_level_sounds; - - redraw_screen = TRUE; - } - - if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 || - last_override_level_music != setup.override_level_music) - { - /* set artwork path to send it to the sound server process */ - setLevelArtworkDir(artwork.mus_first); - - InitReloadCustomMusic(mus_new_identifier); - ReinitializeMusic(); - - artwork.mus_current_identifier = artwork.mus_current->identifier; - last_override_level_music = setup.override_level_music; - - redraw_screen = TRUE; - } - - if (redraw_screen) - { - InitGfxBackground(); - - /* force redraw of (open or closed) door graphics */ - SetDoorState(DOOR_OPEN_ALL); - CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY); - } -} - -void FreeGadgets() +void FreeGadgets() { FreeLevelEditorGadgets(); FreeGameButtons(); @@ -768,21 +260,11 @@ static int getFontBitmapID(int font_nr) { int special = -1; - if (game_status == MAINMENU || game_status == TYPENAME) + if (game_status >= GAME_MODE_MAIN && game_status <= GAME_MODE_PSEUDO_PREVIEW) + special = game_status; + else if (game_status == GAME_MODE_PSEUDO_TYPENAME) special = GFX_SPECIAL_ARG_MAIN; - else if (game_status == CHOOSELEVEL) - special = GFX_SPECIAL_ARG_LEVELS; - else if (game_status == HALLOFFAME) - special = GFX_SPECIAL_ARG_SCORES; - else if (game_status == LEVELED) - special = GFX_SPECIAL_ARG_EDITOR; - else if (game_status == HELPSCREEN) - special = GFX_SPECIAL_ARG_INFO; - else if (game_status == SETUP) - special = GFX_SPECIAL_ARG_SETUP; - else if (game_status == PSEUDO_PREVIEW) - special = GFX_SPECIAL_ARG_PREVIEW; - else if (game_status == PLAYING || game_status == PSEUDO_DOOR) + else if (game_status == GAME_MODE_PLAYING) special = GFX_SPECIAL_ARG_DOOR; if (special != -1) @@ -871,7 +353,7 @@ void InitFontGraphicInfo() /* ---------- initialize font bitmap array ---------- */ if (font_bitmap_info != NULL) - free(font_bitmap_info); + FreeFontInfo(font_bitmap_info); font_bitmap_info = checked_calloc(num_font_bitmaps * sizeof(struct FontBitmapInfo)); @@ -891,6 +373,13 @@ void InitFontGraphicInfo() int font_bitmap_id = font_info[i].special_bitmap_id[j]; int graphic = font_info[i].special_graphic[j]; + /* set 'graphic_info' for font entries, if uninitialized (guessed) */ + if (graphic_info[graphic].anim_frames < MIN_NUM_CHARS_PER_FONT) + { + graphic_info[graphic].anim_frames = DEFAULT_NUM_CHARS_PER_FONT; + graphic_info[graphic].anim_frames_per_line= DEFAULT_NUM_CHARS_PER_LINE; + } + /* copy font relevant information from graphics information */ font_bitmap_info[font_bitmap_id].bitmap = graphic_info[graphic].bitmap; font_bitmap_info[font_bitmap_id].src_x = graphic_info[graphic].src_x; @@ -899,6 +388,11 @@ void InitFontGraphicInfo() font_bitmap_info[font_bitmap_id].height = graphic_info[graphic].height; font_bitmap_info[font_bitmap_id].draw_x = graphic_info[graphic].draw_x; font_bitmap_info[font_bitmap_id].draw_y = graphic_info[graphic].draw_y; + + font_bitmap_info[font_bitmap_id].num_chars = + graphic_info[graphic].anim_frames; + font_bitmap_info[font_bitmap_id].num_chars_per_line = + graphic_info[graphic].anim_frames_per_line; } } @@ -931,6 +425,22 @@ void InitElementGraphicInfo() int direction = element_to_graphic[i].direction; int graphic = element_to_graphic[i].graphic; + if (graphic_info[graphic].bitmap == NULL) + continue; + + if ((action > -1 || direction > -1) && el2img(element) != -1) + { + boolean base_redefined = getImageListEntry(el2img(element))->redefined; + boolean act_dir_redefined = getImageListEntry(graphic)->redefined; + + /* if the base graphic ("emerald", for example) has been redefined, + but not the action graphic ("emerald.falling", for example), do not + use an existing (in this case considered obsolete) action graphic + anymore, but use the automatically determined default graphic */ + if (base_redefined && !act_dir_redefined) + continue; + } + if (action < 0) action = ACTION_DEFAULT; @@ -949,12 +459,19 @@ void InitElementGraphicInfo() int special = property_mapping[i].ext3_index; int graphic = property_mapping[i].artwork_index; + if (graphic_info[graphic].bitmap == NULL) + continue; + if (element >= MAX_NUM_ELEMENTS || special != -1) continue; if (action < 0) action = ACTION_DEFAULT; + if (direction < 0) + for (dir=0; dir -1) element_info[element].direction_graphic[action][direction] = graphic; else @@ -964,39 +481,59 @@ void InitElementGraphicInfo() /* now set all '-1' values to element specific default values */ for (i=0; iredefined; boolean special_redefined = getImageListEntry(graphic)->redefined; + /* 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 + anymore, but use the automatically created (down-scaled) graphic */ if (base_redefined && !special_redefined) continue; @@ -1059,9 +600,9 @@ void InitElementSpecialGraphicInfo() static void set_graphic_parameters(int graphic, char **parameter_raw) { Bitmap *src_bitmap = getBitmapFromImageID(graphic); - int num_xtiles = (src_bitmap ? src_bitmap->width : TILEX) / TILEX; - int num_ytiles = (src_bitmap ? src_bitmap->height * 2 / 3 : TILEY) / TILEY; int parameter[NUM_GFX_ARGS]; + int anim_frames_per_row = 1, anim_frames_per_col = 1; + int anim_frames_per_line = 1; int i; /* get integer values from string parameters */ @@ -1098,20 +639,26 @@ static void set_graphic_parameters(int graphic, char **parameter_raw) if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE) graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT]; + if (src_bitmap) + { + anim_frames_per_row = src_bitmap->width / graphic_info[graphic].width; + anim_frames_per_col = src_bitmap->height / graphic_info[graphic].height; + } + /* correct x or y offset dependant of vertical or horizontal frame order */ if (parameter[GFX_ARG_VERTICAL]) /* frames are ordered vertically */ { - if (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].offset_y = parameter[GFX_ARG_OFFSET]; - else - graphic_info[graphic].offset_y = graphic_info[graphic].height; + 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 */ { - if (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE) - graphic_info[graphic].offset_x = parameter[GFX_ARG_OFFSET]; - else - graphic_info[graphic].offset_x = graphic_info[graphic].width; + 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 */ @@ -1124,20 +671,23 @@ static void set_graphic_parameters(int graphic, char **parameter_raw) 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 = num_xtiles; + 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 = num_ytiles; + graphic_info[graphic].anim_frames = anim_frames_per_col; else 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; - if (parameter[GFX_ARG_ANIM_MODE] != ANIM_NONE) - graphic_info[graphic].anim_mode = parameter[GFX_ARG_ANIM_MODE]; - else if (graphic_info[graphic].anim_frames > 1) - graphic_info[graphic].anim_mode = ANIM_LOOP; + graphic_info[graphic].anim_mode = parameter[GFX_ARG_ANIM_MODE]; + if (graphic_info[graphic].anim_frames == 1) + graphic_info[graphic].anim_mode = ANIM_NONE; /* automatically determine correct start frame, if not defined */ if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE) @@ -1336,22 +886,6 @@ static void InitElementSoundInfo() element_info[j].sound[action] = sound; } - /* initialize element/sound mapping from dynamic configuration */ - for (i=0; i < num_property_mappings; i++) - { - int element = property_mapping[i].base_index; - int action = property_mapping[i].ext1_index; - int sound = property_mapping[i].artwork_index; - - if (element >= MAX_NUM_ELEMENTS) - continue; - - if (action < 0) - action = ACTION_DEFAULT; - - element_info[element].sound[action] = sound; - } - /* initialize element class/sound mapping from dynamic configuration */ for (i=0; i < num_property_mappings; i++) { @@ -1371,13 +905,42 @@ static void InitElementSoundInfo() element_info[j].sound[action] = sound; } - /* now set all '-1' values to element specific default values */ - for (i=0; i= MAX_NUM_ELEMENTS) + continue; + + if (action < 0) + action = ACTION_DEFAULT; + + element_info[element].sound[action] = sound; + } + + /* now set all '-1' values to element specific default values */ + for (i=0; i= EL_CHAR_START && i <= EL_CHAR_END) + SET_PROPERTY(i, EP_INACTIVE, TRUE); + + /* ---------- WALKABLE, PASSABLE, ACCESSIBLE --------------------------- */ + SET_PROPERTY(i, EP_WALKABLE, (IS_WALKABLE_OVER(i) || + IS_WALKABLE_INSIDE(i) || + IS_WALKABLE_UNDER(i))); + + SET_PROPERTY(i, EP_PASSABLE, (IS_PASSABLE_OVER(i) || + IS_PASSABLE_INSIDE(i) || + IS_PASSABLE_UNDER(i))); + + SET_PROPERTY(i, EP_ACCESSIBLE_OVER, (IS_WALKABLE_OVER(i) || + IS_PASSABLE_OVER(i))); + + SET_PROPERTY(i, EP_ACCESSIBLE_INSIDE, (IS_WALKABLE_INSIDE(i) || + IS_PASSABLE_INSIDE(i))); + + SET_PROPERTY(i, EP_ACCESSIBLE_UNDER, (IS_WALKABLE_UNDER(i) || + IS_PASSABLE_UNDER(i))); + + SET_PROPERTY(i, EP_ACCESSIBLE, (IS_WALKABLE(i) || + IS_PASSABLE(i))); + + /* ---------- SNAPPABLE ------------------------------------------------ */ + SET_PROPERTY(i, EP_SNAPPABLE, (IS_DIGGABLE(i) || + IS_COLLECTIBLE(i) || + IS_SWITCHABLE(i) || + i == EL_BD_ROCK)); + + /* ---------- WALL ----------------------------------------------------- */ + SET_PROPERTY(i, EP_WALL, TRUE); /* default: element is wall */ + + for (j=0; no_wall_properties[j] != -1; j++) + if (HAS_PROPERTY(i, no_wall_properties[j]) || + i >= EL_FIRST_RUNTIME_UNREAL) + SET_PROPERTY(i, EP_WALL, FALSE); + + if (IS_HISTORIC_WALL(i)) + SET_PROPERTY(i, EP_WALL, TRUE); + + /* ---------- SOLID_FOR_PUSHING ---------------------------------------- */ + if (engine_version < VERSION_IDENT(2,2,0)) + SET_PROPERTY(i, EP_SOLID_FOR_PUSHING, IS_HISTORIC_SOLID(i)); + else + SET_PROPERTY(i, EP_SOLID_FOR_PUSHING, (!IS_WALKABLE(i) && + !IS_DIGGABLE(i) && + !IS_COLLECTIBLE(i))); + + /* ---------- DRAGONFIRE_PROOF ----------------------------------------- */ + + if (IS_HISTORIC_SOLID(i) || i == EL_EXPLOSION) + SET_PROPERTY(i, EP_DRAGONFIRE_PROOF, TRUE); + else + SET_PROPERTY(i, EP_DRAGONFIRE_PROOF, (IS_CUSTOM_ELEMENT(i) && + IS_INDESTRUCTIBLE(i))); + + /* ---------- EXPLOSION_PROOF ------------------------------------------ */ + if (i == EL_FLAMES) + SET_PROPERTY(i, EP_EXPLOSION_PROOF, TRUE); + else if (engine_version < VERSION_IDENT(2,2,0)) + SET_PROPERTY(i, EP_EXPLOSION_PROOF, IS_INDESTRUCTIBLE(i)); + else + SET_PROPERTY(i, EP_EXPLOSION_PROOF, (IS_INDESTRUCTIBLE(i) && + !IS_WALKABLE_OVER(i) && + !IS_WALKABLE_UNDER(i))); + + if (IS_CUSTOM_ELEMENT(i)) + { + /* ---------- DONT_COLLIDE_WITH / DONT_RUN_INTO ---------------------- */ + if (DONT_TOUCH(i)) + SET_PROPERTY(i, EP_DONT_COLLIDE_WITH, TRUE); + if (DONT_COLLIDE_WITH(i)) + SET_PROPERTY(i, EP_DONT_RUN_INTO, TRUE); + + /* ---------- CAN_SMASH_ENEMIES / CAN_SMASH_PLAYER ------------------- */ + if (CAN_SMASH_EVERYTHING(i)) + SET_PROPERTY(i, EP_CAN_SMASH_ENEMIES, TRUE); + if (CAN_SMASH_ENEMIES(i)) + SET_PROPERTY(i, EP_CAN_SMASH_PLAYER, TRUE); + } + + /* ---------- CAN_SMASH ------------------------------------------------ */ + SET_PROPERTY(i, EP_CAN_SMASH, (CAN_SMASH_PLAYER(i) || + CAN_SMASH_ENEMIES(i) || + CAN_SMASH_EVERYTHING(i))); + + /* ---------- CAN_EXPLODE ---------------------------------------------- */ + SET_PROPERTY(i, EP_CAN_EXPLODE, (CAN_EXPLODE_BY_FIRE(i) || + CAN_EXPLODE_SMASHED(i) || + CAN_EXPLODE_BY_FIRE(i))); + } + +#if 0 + /* determine inactive elements (used for engine main loop optimization) */ + for (i=0; i < MAX_NUM_ELEMENTS; i++) + { + boolean active = FALSE; + + for (j=0; i < NUM_ELEMENT_PROPERTIES; j++) + { + if (HAS_PROPERTY(i, j)) + active = TRUE; + } + +#if 0 + if (!active) + SET_PROPERTY(i, EP_INACTIVE, TRUE); +#endif + } +#endif + + /* dynamically adjust element properties according to game engine version */ + { + static int ep_em_slippery_wall[] = + { + EL_STEELWALL, + EL_WALL, + EL_EXPANDABLE_WALL, + EL_EXPANDABLE_WALL_HORIZONTAL, + EL_EXPANDABLE_WALL_VERTICAL, + EL_EXPANDABLE_WALL_ANY, + -1 + }; + + /* special EM style gems behaviour */ + for (i=0; ep_em_slippery_wall[i] != -1; i++) + SET_PROPERTY(ep_em_slippery_wall[i], EP_EM_SLIPPERY_WALL, + level.em_slippery_gems); + + /* "EL_EXPANDABLE_WALL_GROWING" wasn't slippery for EM gems in 2.0.1 */ + SET_PROPERTY(EL_EXPANDABLE_WALL_GROWING, EP_EM_SLIPPERY_WALL, + (level.em_slippery_gems && + engine_version > VERSION_IDENT(2,0,1))); + } + +#if 0 + /* dynamically adjust element properties according to game engine version */ +#if 0 + if (engine_version < RELEASE_IDENT(2,2,0,7)) +#endif + { + for (i=0; i < NUM_CUSTOM_ELEMENTS; i++) + { + int element = EL_CUSTOM_START + i; + + element_info[element].push_delay_fixed = 2; + element_info[element].push_delay_random = 8; + } + } +#endif +} + +static void InitGlobal() +{ + global.autoplay_leveldir = NULL; + + global.frames_per_second = 0; + global.fps_slowdown = FALSE; + global.fps_slowdown_factor = 1; +} + +void Execute_Command(char *command) +{ + if (strcmp(command, "print graphicsinfo.conf") == 0) + { + int i; + + printf("# You can configure additional/alternative image files here.\n"); + printf("# (The images below are default and therefore commented out.)\n"); + printf("\n"); + printf("%s\n", getFormattedSetupEntry("name", "Classic Graphics")); + printf("\n"); + printf("%s\n", getFormattedSetupEntry("sort_priority", "100")); + printf("\n"); + + for (i=0; image_config[i].token != NULL; i++) + printf("# %s\n", + getFormattedSetupEntry(image_config[i].token, + image_config[i].value)); + + exit(0); + } + else if (strcmp(command, "print soundsinfo.conf") == 0) + { + int i; + + printf("# You can configure additional/alternative sound files here.\n"); + printf("# (The sounds below are default and therefore commented out.)\n"); + printf("\n"); + printf("%s\n", getFormattedSetupEntry("name", "Classic Sounds")); + printf("\n"); + printf("%s\n", getFormattedSetupEntry("sort_priority", "100")); + printf("\n"); + + for (i=0; sound_config[i].token != NULL; i++) + printf("# %s\n", + getFormattedSetupEntry(sound_config[i].token, + sound_config[i].value)); + + exit(0); + } + else if (strcmp(command, "print musicinfo.conf") == 0) + { + printf("# (Currently only \"name\" and \"sort_priority\" recognized.)\n"); + printf("\n"); + printf("%s\n", getFormattedSetupEntry("name", "Classic Music")); + printf("\n"); + printf("%s\n", getFormattedSetupEntry("sort_priority", "100")); + + exit(0); + } + else if (strncmp(command, "dump level ", 11) == 0) + { + char *filename = &command[11]; + + if (access(filename, F_OK) != 0) + Error(ERR_EXIT, "cannot open file '%s'", filename); + + LoadLevelFromFilename(filename); + DumpLevel(&level); + + exit(0); + } + else if (strncmp(command, "dump tape ", 10) == 0) + { + char *filename = &command[10]; + + if (access(filename, F_OK) != 0) + Error(ERR_EXIT, "cannot open file '%s'", filename); + + LoadTapeFromFilename(filename); + DumpTape(&tape); + exit(0); } - else if (strncmp(command, "dump level ", 11) == 0) + else if (strncmp(command, "autoplay ", 9) == 0) + { + char *str_copy = getStringCopy(&command[9]); + char *str_ptr = strchr(str_copy, ' '); + + global.autoplay_leveldir = str_copy; + global.autoplay_level_nr = -1; + + if (str_ptr != NULL) + { + *str_ptr++ = '\0'; /* terminate leveldir string */ + global.autoplay_level_nr = atoi(str_ptr); /* get level_nr value */ + } + } + else + { + Error(ERR_EXIT_HELP, "unrecognized command '%s'", command); + } +} + +static void InitSetup() +{ + LoadSetup(); /* global setup info */ + + /* set some options from setup file */ + + if (setup.options.verbose) + options.verbose = TRUE; +} + +static void InitPlayerInfo() +{ + int i; + + /* choose default local player */ + local_player = &stored_player[0]; + + for (i=0; iconnected = TRUE; +} + +static void InitArtworkInfo() +{ + LoadArtworkInfo(); +} + +static char *get_string_in_brackets(char *string) +{ + char *string_in_brackets = checked_malloc(strlen(string) + 3); + + sprintf(string_in_brackets, "[%s]", string); + + return string_in_brackets; +} + +#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]; + static char *sound_id_prefix[2 * MAX_NUM_ELEMENTS + 1]; + static char *action_id_suffix[NUM_ACTIONS + 1]; + static char *direction_id_suffix[NUM_DIRECTIONS + 1]; + static char *special_id_suffix[NUM_SPECIAL_GFX_ARGS + 1]; + static char *dummy[1] = { NULL }; + static char *ignore_generic_tokens[] = + { + "name", + "sort_priority", + NULL + }; + static char **ignore_image_tokens, **ignore_sound_tokens; + int num_ignore_generic_tokens; + int num_ignore_image_tokens, num_ignore_sound_tokens; + int i; + + /* dynamically determine list of generic tokens to be ignored */ + num_ignore_generic_tokens = 0; + for (i=0; ignore_generic_tokens[i] != NULL; i++) + num_ignore_generic_tokens++; + + /* dynamically determine list of image tokens to be ignored */ + num_ignore_image_tokens = num_ignore_generic_tokens; + for (i=0; image_config_vars[i].token != NULL; i++) + num_ignore_image_tokens++; + ignore_image_tokens = + checked_malloc((num_ignore_image_tokens + 1) * sizeof(char *)); + for (i=0; i < num_ignore_generic_tokens; i++) + ignore_image_tokens[i] = ignore_generic_tokens[i]; + for (i=0; i < num_ignore_image_tokens - num_ignore_generic_tokens; i++) + ignore_image_tokens[num_ignore_generic_tokens + i] = + image_config_vars[i].token; + ignore_image_tokens[num_ignore_image_tokens] = NULL; + + /* dynamically determine list of sound tokens to be ignored */ + num_ignore_sound_tokens = num_ignore_generic_tokens; + ignore_sound_tokens = + checked_malloc((num_ignore_sound_tokens + 1) * sizeof(char *)); + for (i=0; i < num_ignore_generic_tokens; i++) + ignore_sound_tokens[i] = ignore_generic_tokens[i]; + ignore_sound_tokens[num_ignore_sound_tokens] = NULL; + + for (i=0; i len_font_token && + strncmp(image_config[i].token, font_token, len_font_token) == 0) + { + if (strcmp(&image_config[i].token[len_font_token], ".x") == 0) + font_initial[j].src_x = atoi(image_config[i].value); + else if (strcmp(&image_config[i].token[len_font_token], ".y") == 0) + font_initial[j].src_y = atoi(image_config[i].value); + else if (strcmp(&image_config[i].token[len_font_token], ".width") == 0) + font_initial[j].width = atoi(image_config[i].value); + else if (strcmp(&image_config[i].token[len_font_token],".height") == 0) + font_initial[j].height = atoi(image_config[i].value); + } + } + } + + for (j=0; j < NUM_INITIAL_FONTS; j++) + { + font_initial[j].num_chars = DEFAULT_NUM_CHARS_PER_FONT; + font_initial[j].num_chars_per_line = DEFAULT_NUM_CHARS_PER_LINE; + } + + if (filename_font_initial == NULL) /* should not happen */ + Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL); + + /* create additional image buffers for double-buffering */ + bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH); + bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH); + + /* initialize screen properties */ + InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE, + REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, + bitmap_db_field); + InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE); + InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE); + InitGfxScrollbufferInfo(FXSIZE, FYSIZE); + + bitmap_font_initial = LoadCustomImage(filename_font_initial); + + for (j=0; j < NUM_INITIAL_FONTS; j++) + font_initial[j].bitmap = bitmap_font_initial; + + InitFontGraphicInfo(); + + DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW); + DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED); + + DrawInitText("Loading graphics:", 120, FC_GREEN); + + InitTileClipmasks(); +} + +void InitGfxBackground() +{ + int x, y; + + drawto = backbuffer; + fieldbuffer = bitmap_db_field; + SetDrawtoField(DRAW_BACKBUFFER); + + BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer, + 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); + ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); + ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE); + + for (x=0; xidentifier); + ReinitializeSounds(); +} + +static void InitMusic() +{ + InitReloadCustomMusic(artwork.mus_current->identifier); + ReinitializeMusic(); +} + +void InitNetworkServer() +{ +#if defined(PLATFORM_UNIX) + int nr_wanted; +#endif + + if (!options.network) + return; + +#if defined(PLATFORM_UNIX) + nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED); + + if (!ConnectToServer(options.server_host, options.server_port)) + Error(ERR_EXIT, "cannot connect to network game server"); + + SendToServer_PlayerName(setup.player_name); + SendToServer_ProtocolVersion(); + + if (nr_wanted) + SendToServer_NrWanted(nr_wanted); +#endif +} + +void ReloadCustomArtwork() +{ + static char *leveldir_current_identifier = NULL; + static boolean last_override_level_graphics = FALSE; + static boolean last_override_level_sounds = FALSE; + static boolean last_override_level_music = FALSE; + /* identifier for new artwork; default: artwork configured in setup */ + char *gfx_new_identifier = artwork.gfx_current->identifier; + char *snd_new_identifier = artwork.snd_current->identifier; + char *mus_new_identifier = artwork.mus_current->identifier; + boolean redraw_screen = FALSE; + + if (leveldir_current_identifier == NULL) + leveldir_current_identifier = leveldir_current->identifier; + +#if 0 + printf("CURRENT GFX: '%s' ['%s']\n", artwork.gfx_current->identifier, + leveldir_current->graphics_set); + printf("CURRENT LEV: '%s' / '%s'\n", leveldir_current_identifier, + leveldir_current->identifier); +#endif + +#if 0 + printf("graphics --> '%s' ('%s')\n", + artwork.gfx_current_identifier, artwork.gfx_current->filename); + printf("sounds --> '%s' ('%s')\n", + artwork.snd_current_identifier, artwork.snd_current->filename); + printf("music --> '%s' ('%s')\n", + artwork.mus_current_identifier, artwork.mus_current->filename); +#endif + + /* leveldir_current may be invalid (level group, parent link) */ + if (!validLevelSeries(leveldir_current)) + return; + + /* when a new level series was selected, check if there was a change + in custom artwork stored in level series directory */ + if (leveldir_current_identifier != leveldir_current->identifier) + { + char *identifier_old = leveldir_current_identifier; + char *identifier_new = leveldir_current->identifier; + + if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) != + getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new)) + gfx_new_identifier = identifier_new; + if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) != + getTreeInfoFromIdentifier(artwork.snd_first, identifier_new)) + snd_new_identifier = identifier_new; + if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) != + getTreeInfoFromIdentifier(artwork.mus_first, identifier_new)) + mus_new_identifier = identifier_new; + + leveldir_current_identifier = leveldir_current->identifier; + } + + /* custom level artwork configured in level series configuration file + always overrides custom level artwork stored in level series directory + and (level independant) custom artwork configured in setup menue */ + if (leveldir_current->graphics_set != NULL) + gfx_new_identifier = leveldir_current->graphics_set; + if (leveldir_current->sounds_set != NULL) + snd_new_identifier = leveldir_current->sounds_set; + if (leveldir_current->music_set != NULL) + mus_new_identifier = leveldir_current->music_set; + + if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 || + last_override_level_graphics != setup.override_level_graphics) { - char *filename = &command[11]; +#if 0 + printf("RELOADING GRAPHICS '%s' -> '%s' ('%s')\n", + artwork.gfx_current_identifier, + artwork.gfx_current->identifier, + gfx_new_identifier); +#endif - if (access(filename, F_OK) != 0) - Error(ERR_EXIT, "cannot open file '%s'", filename); + setLevelArtworkDir(artwork.gfx_first); - LoadLevelFromFilename(filename); - DumpLevel(&level); + ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE); - exit(0); + InitImages(); + + FreeTileClipmasks(); + InitTileClipmasks(); + + artwork.gfx_current_identifier = artwork.gfx_current->identifier; + last_override_level_graphics = setup.override_level_graphics; + + redraw_screen = TRUE; } - else if (strncmp(command, "dump tape ", 10) == 0) + + if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 || + last_override_level_sounds != setup.override_level_sounds) { - char *filename = &command[10]; +#if 0 + printf("RELOADING SOUNDS '%s' -> '%s' ('%s')\n", + artwork.snd_current_identifier, + artwork.snd_current->identifier, + snd_new_identifier); +#endif - if (access(filename, F_OK) != 0) - Error(ERR_EXIT, "cannot open file '%s'", filename); + /* set artwork path to send it to the sound server process */ + setLevelArtworkDir(artwork.snd_first); - LoadTapeFromFilename(filename); - DumpTape(&tape); + InitReloadCustomSounds(snd_new_identifier); + ReinitializeSounds(); - exit(0); + artwork.snd_current_identifier = artwork.snd_current->identifier; + last_override_level_sounds = setup.override_level_sounds; + + redraw_screen = TRUE; } - else if (strncmp(command, "autoplay ", 9) == 0) + + if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 || + last_override_level_music != setup.override_level_music) { - char *str_copy = getStringCopy(&command[9]); - char *str_ptr = strchr(str_copy, ' '); + /* set artwork path to send it to the sound server process */ + setLevelArtworkDir(artwork.mus_first); - global.autoplay_leveldir = str_copy; - global.autoplay_level_nr = -1; + InitReloadCustomMusic(mus_new_identifier); + ReinitializeMusic(); - if (str_ptr != NULL) - { - *str_ptr++ = '\0'; /* terminate leveldir string */ - global.autoplay_level_nr = atoi(str_ptr); /* get level_nr value */ - } + artwork.mus_current_identifier = artwork.mus_current->identifier; + last_override_level_music = setup.override_level_music; + + redraw_screen = TRUE; } - else + + if (redraw_screen) { - Error(ERR_EXIT_HELP, "unrecognized command '%s'", command); + InitGfxBackground(); + + /* force redraw of (open or closed) door graphics */ + SetDoorState(DOOR_OPEN_ALL); + CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY); + } +} + +void KeyboardAutoRepeatOffUnlessAutoplay() +{ + if (global.autoplay_leveldir == NULL) + KeyboardAutoRepeatOff(); +} + + +/* ========================================================================= */ +/* OpenAll() */ +/* ========================================================================= */ + +void OpenAll() +{ + InitGlobal(); /* initialize some global variables */ + + if (options.execute_command) + Execute_Command(options.execute_command); + + if (options.serveronly) + { +#if defined(PLATFORM_UNIX) + NetworkServer(options.server_port, options.serveronly); +#else + Error(ERR_WARN, "networking only supported in Unix version"); +#endif + exit(0); /* never reached */ + } + + InitSetup(); + + InitPlayerInfo(); + InitArtworkInfo(); /* needed before loading gfx, sound & music */ + InitArtworkConfig(); /* needed before forking sound child process */ + InitMixer(); + + InitCounter(); + + InitRND(NEW_RANDOMIZE); + InitSimpleRND(NEW_RANDOMIZE); + + InitJoysticks(); + + InitVideoDisplay(); + InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, + setup.fullscreen); + + InitEventFilter(FilterMouseMotionEvents); + + InitElementPropertiesStatic(); + + InitGfx(); + + InitLevelInfo(); + InitLevelArtworkInfo(); + + InitImages(); /* needs to know current level directory */ + InitSound(); /* needs to know current level directory */ + InitMusic(); /* needs to know current level directory */ + + InitGfxBackground(); + + if (global.autoplay_leveldir) + { + AutoPlayTape(); + return; } + + game_status = GAME_MODE_MAIN; + + DrawMainMenu(); + + InitNetworkServer(); } void CloseAllAndExit(int exit_value)