X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=43065f6053070fcc6286a3545ba40f0849c61880;hb=ba0f8b82068a5c0d6f245efea2b2c04cb3411c8d;hp=be7447666d29dc90c4e29ca326d51a365bb2c84d;hpb=e534f3cf4f5640bf422bb1484e1cc45c0a4b5339;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index be744766..43065f60 100644 --- a/src/init.c +++ b/src/init.c @@ -333,6 +333,8 @@ static int getFontBitmapID(int font_nr) special = game_status; else if (game_status == GAME_MODE_PSEUDO_TYPENAME) special = GFX_SPECIAL_ARG_MAIN; + else if (game_status == GAME_MODE_PSEUDO_TYPENAMES) + special = GFX_SPECIAL_ARG_NAMES; if (special != -1) return font_info[font_nr].special_bitmap_id[special]; @@ -650,15 +652,14 @@ static void InitGlobalAnimGraphicInfo(void) } #if 0 - printf("::: InitGlobalAnimGraphicInfo\n"); - for (i = 0; i < NUM_GLOBAL_ANIMS; i++) for (j = 0; j < NUM_GLOBAL_ANIM_PARTS_ALL; j++) for (k = 0; k < NUM_SPECIAL_GFX_ARGS; k++) if (global_anim_info[i].graphic[j][k] != IMG_UNDEFINED && graphic_info[global_anim_info[i].graphic[j][k]].bitmap != NULL) - printf("::: - anim %d, part %d, mode %d => %d\n", - i, j, k, global_anim_info[i].graphic[j][k]); + Debug("init:InitGlobalAnimGraphicInfo", + "anim %d, part %d, mode %d => %d", + i, j, k, global_anim_info[i].graphic[j][k]); #endif } @@ -700,14 +701,13 @@ static void InitGlobalAnimSoundInfo(void) } #if 0 - printf("::: InitGlobalAnimSoundInfo\n"); - for (i = 0; i < NUM_GLOBAL_ANIMS; i++) for (j = 0; j < NUM_GLOBAL_ANIM_PARTS_ALL; j++) for (k = 0; k < NUM_SPECIAL_GFX_ARGS; k++) if (global_anim_info[i].sound[j][k] != SND_UNDEFINED) - printf("::: - anim %d, part %d, mode %d => %d\n", - i, j, k, global_anim_info[i].sound[j][k]); + Debug("init:InitGlobalAnimSoundInfo", + "anim %d, part %d, mode %d => %d", + i, j, k, global_anim_info[i].sound[j][k]); #endif } @@ -749,14 +749,13 @@ static void InitGlobalAnimMusicInfo(void) } #if 0 - printf("::: InitGlobalAnimMusicInfo\n"); - for (i = 0; i < NUM_GLOBAL_ANIMS; i++) for (j = 0; j < NUM_GLOBAL_ANIM_PARTS_ALL; j++) for (k = 0; k < NUM_SPECIAL_GFX_ARGS; k++) if (global_anim_info[i].music[j][k] != MUS_UNDEFINED) - printf("::: - anim %d, part %d, mode %d => %d\n", - i, j, k, global_anim_info[i].music[j][k]); + Debug("init:InitGlobalAnimMusicInfo", + "anim %d, part %d, mode %d => %d", + i, j, k, global_anim_info[i].music[j][k]); #endif } @@ -1224,13 +1223,13 @@ static int get_graphic_parameter_value(char *value_raw, char *suffix, int type) if (value == NULL) { - Error(ERR_INFO_LINE, "-"); - Error(ERR_INFO, "warning: error found in config file:"); - Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename()); - Error(ERR_INFO, "error: invalid element token '%s'", value_raw); - Error(ERR_INFO, "custom graphic rejected for this element/action"); - Error(ERR_INFO, "fallback done to undefined element for this graphic"); - Error(ERR_INFO_LINE, "-"); + Warn("---"); + Warn("error found in config file:"); + Warn("- config file: '%s'", getImageConfigFilename()); + Warn("error: invalid element token '%s'", value_raw); + Warn("custom graphic rejected for this element/action"); + Warn("fallback done to undefined element for this graphic"); + Warn("---"); } return (value != NULL ? atoi(value) : EL_UNDEFINED); @@ -1242,13 +1241,13 @@ static int get_graphic_parameter_value(char *value_raw, char *suffix, int type) if (value == NULL) { - Error(ERR_INFO_LINE, "-"); - Error(ERR_INFO, "warning: error found in config file:"); - Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename()); - Error(ERR_INFO, "error: invalid graphic token '%s'", value_raw); - Error(ERR_INFO, "custom graphic rejected for this element/action"); - Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic"); - Error(ERR_INFO_LINE, "-"); + Warn("---"); + Warn("error found in config file:"); + Warn("- config file: '%s'", getImageConfigFilename()); + Warn("error: invalid graphic token '%s'", value_raw); + Warn("custom graphic rejected for this element/action"); + Warn("fallback done to 'char_exclam' for this graphic"); + Warn("---"); } return (value != NULL ? atoi(value) : fallback_graphic); @@ -1379,20 +1378,20 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, { if (g->width <= 0) { - Error(ERR_INFO_LINE, "-"); - Error(ERR_WARN, "invalid value %d for '%s.width' (fallback done to %d)", - g->width, getTokenFromImageID(graphic), TILEX); - Error(ERR_INFO_LINE, "-"); + Warn("---"); + Warn("invalid value %d for '%s.width' (fallback done to %d)", + g->width, getTokenFromImageID(graphic), TILEX); + Warn("---"); g->width = TILEX; // will be checked to be inside bitmap later } if (g->height <= 0) { - Error(ERR_INFO_LINE, "-"); - Error(ERR_WARN, "invalid value %d for '%s.height' (fallback done to %d)", - g->height, getTokenFromImageID(graphic), TILEY); - Error(ERR_INFO_LINE, "-"); + Warn("---"); + Warn("invalid value %d for '%s.height' (fallback done to %d)", + g->height, getTokenFromImageID(graphic), TILEY); + Warn("---"); g->height = TILEY; // will be checked to be inside bitmap later } @@ -1650,18 +1649,18 @@ static void set_cloned_graphic_parameters(int graphic) if (num_references_followed >= max_num_images) { - Error(ERR_INFO_LINE, "-"); - Error(ERR_INFO, "warning: error found in config file:"); - Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename()); - Error(ERR_INFO, "- config token: '%s'", getTokenFromImageID(graphic)); - Error(ERR_INFO, "error: loop discovered when resolving cloned graphics"); - Error(ERR_INFO, "custom graphic rejected for this element/action"); + Warn("---"); + Warn("error found in config file:"); + Warn("- config file: '%s'", getImageConfigFilename()); + Warn("- config token: '%s'", getTokenFromImageID(graphic)); + Warn("error: loop discovered when resolving cloned graphics"); + Warn("custom graphic rejected for this element/action"); if (graphic == fallback_graphic) - Error(ERR_EXIT, "no fallback graphic available"); + Fail("no fallback graphic available"); - Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic"); - Error(ERR_INFO_LINE, "-"); + Warn("fallback done to 'char_exclam' for this graphic"); + Warn("---"); graphic_info[graphic] = graphic_info[fallback_graphic]; } @@ -1698,6 +1697,7 @@ static void InitGraphicInfo(void) IMG_BACKGROUND_TITLE_INITIAL, IMG_BACKGROUND_TITLE, IMG_BACKGROUND_MAIN, + IMG_BACKGROUND_NAMES, IMG_BACKGROUND_LEVELS, IMG_BACKGROUND_LEVELNR, IMG_BACKGROUND_SCORES, @@ -1800,22 +1800,21 @@ static void InitGraphicInfo(void) src_x + width > src_bitmap_width || src_y + height > src_bitmap_height) { - Error(ERR_INFO_LINE, "-"); - Error(ERR_INFO, "warning: error found in config file:"); - Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename()); - Error(ERR_INFO, "- config token: '%s'", getTokenFromImageID(i)); - Error(ERR_INFO, "- image file: '%s'", src_bitmap->source_filename); - Error(ERR_INFO, "- frame size: %d, %d", width, height); - Error(ERR_INFO, - "error: first animation frame out of bounds (%d, %d) [%d, %d]", - src_x, src_y, src_bitmap_width, src_bitmap_height); - Error(ERR_INFO, "custom graphic rejected for this element/action"); + Warn("---"); + Warn("error found in config file:"); + Warn("- config file: '%s'", getImageConfigFilename()); + Warn("- config token: '%s'", getTokenFromImageID(i)); + Warn("- image file: '%s'", src_bitmap->source_filename); + Warn("- frame size: %d, %d", width, height); + Warn("error: first animation frame out of bounds (%d, %d) [%d, %d]", + src_x, src_y, src_bitmap_width, src_bitmap_height); + Warn("custom graphic rejected for this element/action"); if (i == fallback_graphic) - Error(ERR_EXIT, "no fallback graphic available"); + Fail("no fallback graphic available"); - Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic"); - Error(ERR_INFO_LINE, "-"); + Warn("fallback done to 'char_exclam' for this graphic"); + Warn("---"); graphic_info[i] = graphic_info[fallback_graphic]; @@ -1832,22 +1831,21 @@ static void InitGraphicInfo(void) src_x + width > src_bitmap_width || src_y + height > src_bitmap_height) { - Error(ERR_INFO_LINE, "-"); - Error(ERR_INFO, "warning: error found in config file:"); - Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename()); - Error(ERR_INFO, "- config token: '%s'", getTokenFromImageID(i)); - Error(ERR_INFO, "- image file: '%s'", src_bitmap->source_filename); - Error(ERR_INFO, "- frame size: %d, %d", width, height); - Error(ERR_INFO, - "error: last animation frame (%d) out of bounds (%d, %d) [%d, %d]", - last_frame, src_x, src_y, src_bitmap_width, src_bitmap_height); - Error(ERR_INFO, "custom graphic rejected for this element/action"); + Warn("---"); + Warn("error found in config file:"); + Warn("- config file: '%s'", getImageConfigFilename()); + Warn("- config token: '%s'", getTokenFromImageID(i)); + Warn("- image file: '%s'", src_bitmap->source_filename); + Warn("- frame size: %d, %d", width, height); + Warn("error: last animation frame (%d) out of bounds (%d, %d) [%d, %d]", + last_frame, src_x, src_y, src_bitmap_width, src_bitmap_height); + Warn("custom graphic rejected for this element/action"); if (i == fallback_graphic) - Error(ERR_EXIT, "no fallback graphic available"); + Fail("no fallback graphic available"); - Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic"); - Error(ERR_INFO_LINE, "-"); + Warn("fallback done to 'char_exclam' for this graphic"); + Warn("---"); graphic_info[i] = graphic_info[fallback_graphic]; } @@ -1884,7 +1882,10 @@ static void InitGraphicCompatibilityInfo(void) // process all images which default to same image as "global.door" if (strEqual(fi->default_filename, fi_global_door->default_filename)) { - // printf("::: special treatment needed for token '%s'\n", fi->token); +#if 0 + Debug("init:InitGraphicCompatibilityInfo", + "special treatment needed for token '%s'", fi->token); +#endif graphic_info[i].bitmaps = graphic_info[IMG_GLOBAL_DOOR].bitmaps; graphic_info[i].bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap; @@ -2442,7 +2443,7 @@ static void ResolveGroupElementExt(int group_element, int recursion_depth) if (recursion_depth > NUM_GROUP_ELEMENTS) // recursion too deep { - Error(ERR_WARN, "recursion too deep when resolving group element %d", + Warn("recursion too deep when resolving group element %d", group_element - EL_GROUP_START + 1); // replace element which caused too deep recursion by question mark @@ -2999,6 +3000,22 @@ void InitElementPropertiesStatic(void) static int ep_walkable_over[] = { EL_EMPTY_SPACE, + EL_EMPTY_SPACE_1, + EL_EMPTY_SPACE_2, + EL_EMPTY_SPACE_3, + EL_EMPTY_SPACE_4, + EL_EMPTY_SPACE_5, + EL_EMPTY_SPACE_6, + EL_EMPTY_SPACE_7, + EL_EMPTY_SPACE_8, + EL_EMPTY_SPACE_9, + EL_EMPTY_SPACE_10, + EL_EMPTY_SPACE_11, + EL_EMPTY_SPACE_12, + EL_EMPTY_SPACE_13, + EL_EMPTY_SPACE_14, + EL_EMPTY_SPACE_15, + EL_EMPTY_SPACE_16, EL_SP_EMPTY_SPACE, EL_SOKOBAN_FIELD_EMPTY, EL_EXIT_OPEN, @@ -3296,6 +3313,29 @@ void InitElementPropertiesStatic(void) -1 }; + static int ep_empty_space[] = + { + EL_EMPTY_SPACE, + EL_EMPTY_SPACE_1, + EL_EMPTY_SPACE_2, + EL_EMPTY_SPACE_3, + EL_EMPTY_SPACE_4, + EL_EMPTY_SPACE_5, + EL_EMPTY_SPACE_6, + EL_EMPTY_SPACE_7, + EL_EMPTY_SPACE_8, + EL_EMPTY_SPACE_9, + EL_EMPTY_SPACE_10, + EL_EMPTY_SPACE_11, + EL_EMPTY_SPACE_12, + EL_EMPTY_SPACE_13, + EL_EMPTY_SPACE_14, + EL_EMPTY_SPACE_15, + EL_EMPTY_SPACE_16, + + -1 + }; + static int ep_player[] = { EL_PLAYER_1, @@ -4098,6 +4138,22 @@ void InitElementPropertiesStatic(void) static int ep_inactive[] = { EL_EMPTY, + EL_EMPTY_SPACE_1, + EL_EMPTY_SPACE_2, + EL_EMPTY_SPACE_3, + EL_EMPTY_SPACE_4, + EL_EMPTY_SPACE_5, + EL_EMPTY_SPACE_6, + EL_EMPTY_SPACE_7, + EL_EMPTY_SPACE_8, + EL_EMPTY_SPACE_9, + EL_EMPTY_SPACE_10, + EL_EMPTY_SPACE_11, + EL_EMPTY_SPACE_12, + EL_EMPTY_SPACE_13, + EL_EMPTY_SPACE_14, + EL_EMPTY_SPACE_15, + EL_EMPTY_SPACE_16, EL_SAND, EL_WALL, EL_BD_WALL, @@ -4347,6 +4403,7 @@ void InitElementPropertiesStatic(void) EL_INTERNAL_CASCADE_STEEL_CHARS_ACTIVE, EL_INTERNAL_CASCADE_CE_ACTIVE, EL_INTERNAL_CASCADE_GE_ACTIVE, + EL_INTERNAL_CASCADE_ES_ACTIVE, EL_INTERNAL_CASCADE_REF_ACTIVE, EL_INTERNAL_CASCADE_USER_ACTIVE, EL_INTERNAL_CASCADE_DYNAMIC_ACTIVE, @@ -4370,6 +4427,7 @@ void InitElementPropertiesStatic(void) EL_INTERNAL_CASCADE_STEEL_CHARS, EL_INTERNAL_CASCADE_CE, EL_INTERNAL_CASCADE_GE, + EL_INTERNAL_CASCADE_ES, EL_INTERNAL_CASCADE_REF, EL_INTERNAL_CASCADE_USER, EL_INTERNAL_CASCADE_DYNAMIC, @@ -4427,6 +4485,7 @@ void InitElementPropertiesStatic(void) { ep_can_explode, EP_CAN_EXPLODE }, { ep_gravity_reachable, EP_GRAVITY_REACHABLE }, + { ep_empty_space, EP_EMPTY_SPACE }, { ep_player, EP_PLAYER }, { ep_can_pass_magic_wall, EP_CAN_PASS_MAGIC_WALL }, { ep_can_pass_dc_magic_wall, EP_CAN_PASS_DC_MAGIC_WALL }, @@ -4663,7 +4722,7 @@ void InitElementPropertiesEngine(int engine_version) i == EL_BLACK_ORB)); // ---------- COULD_MOVE_INTO_ACID ---------------------------------------- - SET_PROPERTY(i, EP_COULD_MOVE_INTO_ACID, (ELEM_IS_PLAYER(i) || + SET_PROPERTY(i, EP_COULD_MOVE_INTO_ACID, (IS_PLAYER_ELEMENT(i) || CAN_MOVE(i) || IS_CUSTOM_ELEMENT(i))); @@ -4784,7 +4843,7 @@ static void InitGlobal(void) { // check if element_name_info entry defined for each element in "main.h" if (i < MAX_NUM_ELEMENTS && element_name_info[i].token_name == NULL) - Error(ERR_EXIT, "undefined 'element_name_info' entry for element %d", i); + Fail("undefined 'element_name_info' entry for element %d", i); element_info[i].token_name = element_name_info[i].token_name; element_info[i].class_name = element_name_info[i].class_name; @@ -4796,7 +4855,7 @@ static void InitGlobal(void) // check if global_anim_name_info defined for each entry in "main.h" if (i < NUM_GLOBAL_ANIM_TOKENS && global_anim_name_info[i].token_name == NULL) - Error(ERR_EXIT, "undefined 'global_anim_name_info' entry for anim %d", i); + Fail("undefined 'global_anim_name_info' entry for anim %d", i); global_anim_info[i].token_name = global_anim_name_info[i].token_name; } @@ -4902,7 +4961,10 @@ static void InitGlobal(void) global.autoplay_leveldir = NULL; global.patchtapes_leveldir = NULL; global.convert_leveldir = NULL; - global.create_images_dir = NULL; + global.dumplevel_leveldir = NULL; + global.dumptape_leveldir = NULL; + global.create_sketch_images_dir = NULL; + global.create_collect_images_dir = NULL; global.frames_per_second = 0; global.show_frames_per_second = FALSE; @@ -4911,6 +4973,8 @@ static void InitGlobal(void) global.anim_status = global.anim_status_next = GAME_MODE_LOADING; global.use_envelope_request = FALSE; + + global.user_names = NULL; } static void Execute_Command(char *command) @@ -5012,39 +5076,70 @@ static void Execute_Command(char *command) { char *filename = &command[11]; - if (!fileExists(filename)) - Error(ERR_EXIT, "cannot open file '%s'", filename); + if (fileExists(filename)) + { + LoadLevelFromFilename(&level, filename); + DumpLevel(&level); - LoadLevelFromFilename(&level, filename); - DumpLevel(&level); + exit(0); + } - exit(0); + char *leveldir = getStringCopy(filename); // read command parameters + char *level_nr = strchr(leveldir, ' '); + + if (level_nr == NULL) + Fail("cannot open file '%s'", filename); + + *level_nr++ = '\0'; + + global.dumplevel_leveldir = leveldir; + global.dumplevel_level_nr = atoi(level_nr); + + program.headless = TRUE; } else if (strPrefix(command, "dump tape ")) { char *filename = &command[10]; - if (!fileExists(filename)) - Error(ERR_EXIT, "cannot open file '%s'", filename); + if (fileExists(filename)) + { + LoadTapeFromFilename(filename); + DumpTape(&tape); - LoadTapeFromFilename(filename); - DumpTape(&tape); + exit(0); + } - exit(0); + char *leveldir = getStringCopy(filename); // read command parameters + char *level_nr = strchr(leveldir, ' '); + + if (level_nr == NULL) + Fail("cannot open file '%s'", filename); + + *level_nr++ = '\0'; + + global.dumptape_leveldir = leveldir; + global.dumptape_level_nr = atoi(level_nr); + + program.headless = TRUE; } else if (strPrefix(command, "autoplay ") || strPrefix(command, "autoffwd ") || strPrefix(command, "autowarp ") || strPrefix(command, "autotest ") || + strPrefix(command, "autosave ") || + strPrefix(command, "autoupload ") || strPrefix(command, "autofix ")) { - char *str_ptr = getStringCopy(&command[8]); // read command parameters + char *arg_ptr = strchr(command, ' '); + char *str_ptr = getStringCopy(arg_ptr); // read command parameters global.autoplay_mode = (strPrefix(command, "autoplay") ? AUTOPLAY_MODE_PLAY : strPrefix(command, "autoffwd") ? AUTOPLAY_MODE_FFWD : strPrefix(command, "autowarp") ? AUTOPLAY_MODE_WARP : strPrefix(command, "autotest") ? AUTOPLAY_MODE_TEST : + strPrefix(command, "autosave") ? AUTOPLAY_MODE_SAVE : + strPrefix(command, "autoupload") ? AUTOPLAY_MODE_UPLOAD : strPrefix(command, "autofix") ? AUTOPLAY_MODE_FIX : AUTOPLAY_MODE_NONE); @@ -5080,7 +5175,7 @@ static void Execute_Command(char *command) str_ptr++; } - if (global.autoplay_mode & AUTOPLAY_MODE_WARP_NO_DISPLAY) + if (global.autoplay_mode & AUTOPLAY_WARP_NO_DISPLAY) program.headless = TRUE; } else if (strPrefix(command, "patch tapes ")) @@ -5092,7 +5187,7 @@ static void Execute_Command(char *command) str_ptr++; if (*str_ptr == '\0') - Error(ERR_EXIT, "cannot find MODE in command '%s'", command); + Fail("cannot find MODE in command '%s'", command); global.patchtapes_mode = str_ptr; // store patch mode @@ -5137,7 +5232,7 @@ static void Execute_Command(char *command) if (strEqual(global.patchtapes_mode, "help")) global.patchtapes_leveldir = UNDEFINED_LEVELSET; else - Error(ERR_EXIT, "cannot find LEVELDIR in command '%s'", command); + Fail("cannot find LEVELDIR in command '%s'", command); } program.headless = TRUE; @@ -5158,13 +5253,21 @@ static void Execute_Command(char *command) program.headless = TRUE; } - else if (strPrefix(command, "create images ")) + else if (strPrefix(command, "create sketch images ")) { - global.create_images_dir = getStringCopy(&command[14]); + global.create_sketch_images_dir = getStringCopy(&command[21]); - if (access(global.create_images_dir, W_OK) != 0) - Error(ERR_EXIT, "image target directory '%s' not found or not writable", - global.create_images_dir); + if (access(global.create_sketch_images_dir, W_OK) != 0) + Fail("image target directory '%s' not found or not writable", + global.create_sketch_images_dir); + } + else if (strPrefix(command, "create collect image ")) + { + global.create_collect_images_dir = getStringCopy(&command[21]); + + if (access(global.create_collect_images_dir, W_OK) != 0) + Fail("image target directory '%s' not found or not writable", + global.create_collect_images_dir); } else if (strPrefix(command, "create CE image ")) { @@ -5174,7 +5277,7 @@ static void Execute_Command(char *command) } else { - Error(ERR_EXIT_HELP, "unrecognized command '%s'", command); + FailWithHelp("unrecognized command '%s'", command); } // disable networking if any valid command was recognized @@ -5183,8 +5286,10 @@ static void Execute_Command(char *command) static void InitSetup(void) { + LoadUserNames(); // global user names + LoadUserSetup(); // global user number + LoadSetup(); // global setup info - LoadSetup_AutoSetup(); // global auto setup info // set some options from setup file @@ -5199,7 +5304,9 @@ static void InitGameInfo(void) { game.restart_level = FALSE; game.restart_game_message = NULL; + game.request_active = FALSE; + game.request_active_or_moving = FALSE; } static void InitPlayerInfo(void) @@ -5465,7 +5572,7 @@ static void InitGfx(void) } if (filename_font_initial == NULL) // should not happen - Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL); + Fail("cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL); InitGfxBuffers(); InitGfxCustomArtworkInfo(); @@ -5480,7 +5587,7 @@ static void InitGfx(void) DrawProgramInfo(); - DrawInitText("Loading graphics", 120, FC_GREEN); + DrawInitTextHead("Loading graphics"); // initialize settings for busy animation with default values int parameter[NUM_GFX_ARGS]; @@ -5551,7 +5658,7 @@ static void InitGfx(void) } if (filename_anim_initial == NULL) // should not happen - Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_GLOBAL_BUSY); + Fail("cannot get filename for '%s'", CONFIG_TOKEN_GLOBAL_BUSY); anim_initial.bitmaps = checked_calloc(sizeof(Bitmap *) * NUM_IMG_BITMAP_POINTERS); @@ -5623,36 +5730,36 @@ static void InitImages(void) print_timestamp_init("InitImages"); #if 0 - printf("::: leveldir_current->identifier == '%s'\n", - leveldir_current == NULL ? "[NULL]" : leveldir_current->identifier); - printf("::: leveldir_current->graphics_path == '%s'\n", - leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_path); - printf("::: leveldir_current->graphics_set == '%s'\n", - leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_set); - printf("::: getLevelArtworkSet(ARTWORK_TYPE_GRAPHICS) == '%s'\n", - leveldir_current == NULL ? "[NULL]" : LEVELDIR_ARTWORK_SET(leveldir_current, ARTWORK_TYPE_GRAPHICS)); + Debug("init:InitImages", "leveldir_current->identifier == '%s'", + leveldir_current == NULL ? "[NULL]" : leveldir_current->identifier); + Debug("init:InitImages", "leveldir_current->graphics_path == '%s'", + leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_path); + Debug("init:InitImages", "leveldir_current->graphics_set == '%s'", + leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_set); + Debug("init:InitImages", "getLevelArtworkSet(ARTWORK_TYPE_GRAPHICS) == '%s'", + leveldir_current == NULL ? "[NULL]" : LEVELDIR_ARTWORK_SET(leveldir_current, ARTWORK_TYPE_GRAPHICS)); #endif setLevelArtworkDir(artwork.gfx_first); #if 0 - printf("::: leveldir_current->identifier == '%s'\n", - leveldir_current == NULL ? "[NULL]" : leveldir_current->identifier); - printf("::: leveldir_current->graphics_path == '%s'\n", - leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_path); - printf("::: leveldir_current->graphics_set == '%s'\n", + Debug("init:InitImages", "leveldir_current->identifier == '%s'", + leveldir_current == NULL ? "[NULL]" : leveldir_current->identifier); + Debug("init:InitImages", "leveldir_current->graphics_path == '%s'", + leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_path); + Debug("init:InitImages", "leveldir_current->graphics_set == '%s'", leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_set); - printf("::: getLevelArtworkSet(ARTWORK_TYPE_GRAPHICS) == '%s'\n", - leveldir_current == NULL ? "[NULL]" : LEVELDIR_ARTWORK_SET(leveldir_current, ARTWORK_TYPE_GRAPHICS)); + Debug("init:InitImages", "getLevelArtworkSet(ARTWORK_TYPE_GRAPHICS) == '%s'", + leveldir_current == NULL ? "[NULL]" : LEVELDIR_ARTWORK_SET(leveldir_current, ARTWORK_TYPE_GRAPHICS)); #endif #if 0 - printf("::: InitImages for '%s' ['%s', '%s'] ['%s', '%s']\n", - leveldir_current->identifier, - artwork.gfx_current_identifier, - artwork.gfx_current->identifier, - leveldir_current->graphics_set, - leveldir_current->graphics_path); + Debug("init:InitImages", "InitImages for '%s' ['%s', '%s'] ['%s', '%s']", + leveldir_current->identifier, + artwork.gfx_current_identifier, + artwork.gfx_current->identifier, + leveldir_current->graphics_set, + leveldir_current->graphics_path); #endif UPDATE_BUSY_STATE(); @@ -5811,22 +5918,27 @@ static boolean CheckArtworkTypeForRedefinedCustomElements(int type) setLevelArtworkDir(ARTWORK_FIRST_NODE(artwork, type)); #if 0 - printf("::: leveldir_current->identifier == '%s'\n", - leveldir_current == NULL ? "[NULL]" : leveldir_current->identifier); - printf("::: leveldir_current->graphics_path == '%s'\n", - leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_path); - printf("::: leveldir_current->graphics_set == '%s'\n", - leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_set); - printf("::: getLevelArtworkSet(ARTWORK_TYPE_GRAPHICS) == '%s'\n", - leveldir_current == NULL ? "[NULL]" : - LEVELDIR_ARTWORK_SET(leveldir_current, type)); + Debug("init:CheckArtworkTypeForRedefinedCustomElements", + "leveldir_current->identifier == '%s'", + leveldir_current == NULL ? "[NULL]" : leveldir_current->identifier); + Debug("init:CheckArtworkTypeForRedefinedCustomElements", + "leveldir_current->graphics_path == '%s'", + leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_path); + Debug("init:CheckArtworkTypeForRedefinedCustomElements", + "leveldir_current->graphics_set == '%s'", + leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_set); + Debug("init:CheckArtworkTypeForRedefinedCustomElements", + "getLevelArtworkSet(ARTWORK_TYPE_GRAPHICS) == '%s'", + leveldir_current == NULL ? "[NULL]" : + LEVELDIR_ARTWORK_SET(leveldir_current, type)); #endif // first look for special artwork configured in level series config filename_base = getCustomArtworkLevelConfigFilename(type); #if 0 - printf("::: filename_base == '%s'\n", filename_base); + Debug("init:CheckArtworkTypeForRedefinedCustomElements", + "filename_base == '%s'", filename_base); #endif if (fileExists(filename_base)) @@ -5835,14 +5947,16 @@ static boolean CheckArtworkTypeForRedefinedCustomElements(int type) filename_local = getCustomArtworkConfigFilename(type); #if 0 - printf("::: filename_local == '%s'\n", filename_local); + Debug("init:CheckArtworkTypeForRedefinedCustomElements", + "filename_local == '%s'", filename_local); #endif if (filename_local != NULL && !strEqual(filename_base, filename_local)) redefined_ce_found |= CheckArtworkConfigForCustomElements(filename_local); #if 0 - printf("::: redefined_ce_found == %d\n", redefined_ce_found); + Debug("init:CheckArtworkTypeForRedefinedCustomElements", + "redefined_ce_found == %d", redefined_ce_found); #endif return redefined_ce_found; @@ -5867,7 +5981,8 @@ static void InitOverrideArtwork(void) CheckArtworkTypeForRedefinedCustomElements(ARTWORK_TYPE_MUSIC)); #if 0 - printf("::: redefined_ce_found == %d\n", redefined_ce_found); + Debug("init:InitOverrideArtwork", "redefined_ce_found == %d", + redefined_ce_found); #endif if (redefined_ce_found) @@ -5886,16 +6001,17 @@ static void InitOverrideArtwork(void) } #if 0 - printf("::: => %d, %d, %d\n", - gfx.override_level_graphics, - gfx.override_level_sounds, - gfx.override_level_music); + Debug("init:InitOverrideArtwork", "%d, %d, %d", + gfx.override_level_graphics, + gfx.override_level_sounds, + gfx.override_level_music); #endif } static char *getNewArtworkIdentifier(int type) { - static char *leveldir_current_identifier[3] = { NULL, NULL, NULL }; + static char *last_leveldir_identifier[3] = { NULL, NULL, NULL }; + static char *last_artwork_identifier[3] = { NULL, NULL, NULL }; static boolean last_override_level_artwork[3] = { FALSE, FALSE, FALSE }; static boolean last_has_level_artwork_set[3] = { FALSE, FALSE, FALSE }; static boolean initialized[3] = { FALSE, FALSE, FALSE }; @@ -5930,16 +6046,15 @@ static char *getNewArtworkIdentifier(int type) else artwork_current_identifier = setup_artwork_set; - /* 2nd step: check if it is really needed to reload artwork set ------------------------------------------------------------ */ // ---------- reload if level set and also artwork set has changed ---------- - if (leveldir_current_identifier[type] != leveldir_identifier && + if (last_leveldir_identifier[type] != leveldir_identifier && (last_has_level_artwork_set[type] || has_level_artwork_set)) artwork_new_identifier = artwork_current_identifier; - leveldir_current_identifier[type] = leveldir_identifier; + last_leveldir_identifier[type] = leveldir_identifier; last_has_level_artwork_set[type] = has_level_artwork_set; // ---------- reload if "override artwork" setting has changed -------------- @@ -5949,11 +6064,13 @@ static char *getNewArtworkIdentifier(int type) last_override_level_artwork[type] = setup_override_artwork; // ---------- reload if current artwork identifier has changed -------------- - if (!strEqual(ARTWORK_CURRENT_IDENTIFIER(artwork, type), - artwork_current_identifier)) + if (!strEqual(last_artwork_identifier[type], artwork_current_identifier)) artwork_new_identifier = artwork_current_identifier; - *(ARTWORK_CURRENT_IDENTIFIER_PTR(artwork, type))= artwork_current_identifier; + // (we cannot compare string pointers here, so copy string content itself) + setString(&last_artwork_identifier[type], artwork_current_identifier); + + *(ARTWORK_CURRENT_IDENTIFIER_PTR(artwork, type)) = artwork_current_identifier; // ---------- do not reload directly after starting ------------------------- if (!initialized[type]) @@ -5977,8 +6094,8 @@ void ReloadCustomArtwork(int force_reload) InitOverrideArtwork(); - force_reload_gfx |= AdjustGraphicsForEMC(); - force_reload_snd |= AdjustSoundsForEMC(); + AdjustGraphicsForEMC(); + AdjustSoundsForEMC(); gfx_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_GRAPHICS); snd_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_SOUNDS); @@ -6005,11 +6122,12 @@ void ReloadCustomArtwork(int force_reload) if (gfx_new_identifier != NULL || force_reload_gfx) { #if 0 - printf("RELOADING GRAPHICS '%s' -> '%s' ['%s', '%s']\n", - artwork.gfx_current_identifier, - gfx_new_identifier, - artwork.gfx_current->identifier, - leveldir_current->graphics_set); + Debug("init:ReloadCustomArtwork", + "RELOADING GRAPHICS '%s' -> '%s' ['%s', '%s']", + artwork.gfx_current_identifier, + gfx_new_identifier, + artwork.gfx_current->identifier, + leveldir_current->graphics_set); #endif InitImages(); @@ -6135,14 +6253,16 @@ void OpenAll(void) InitGlobal(); // initialize some global variables + InitRND(NEW_RANDOMIZE); + InitSimpleRandom(NEW_RANDOMIZE); + InitBetterRandom(NEW_RANDOMIZE); + print_timestamp_time("[init global stuff]"); InitSetup(); print_timestamp_time("[init setup/config stuff (1)]"); - InitScoresInfo(); - if (options.execute_command) Execute_Command(options.execute_command); @@ -6155,7 +6275,7 @@ void OpenAll(void) #if defined(PLATFORM_UNIX) NetworkServer(network.server_port, TRUE); #else - Error(ERR_WARN, "networking only supported in Unix version"); + Warn("networking only supported in Unix version"); #endif exit(0); // never reached, server loops forever @@ -6172,9 +6292,6 @@ void OpenAll(void) InitMixer(); print_timestamp_time("[init setup/config stuff (6)]"); - InitRND(NEW_RANDOMIZE); - InitSimpleRandom(NEW_RANDOMIZE); - InitJoysticks(); print_timestamp_time("[init setup/config stuff]"); @@ -6239,11 +6356,26 @@ void OpenAll(void) ConvertLevels(); return; } - else if (global.create_images_dir) + else if (global.dumplevel_leveldir) + { + DumpLevels(); + return; + } + else if (global.dumptape_leveldir) + { + DumpTapes(); + return; + } + else if (global.create_sketch_images_dir) { CreateLevelSketchImages(); return; } + else if (global.create_collect_images_dir) + { + CreateCollectElementImages(); + return; + } InitNetworkServer(); @@ -6257,19 +6389,22 @@ void OpenAll(void) print_timestamp_done("OpenAll"); + if (setup.ask_for_remaining_tapes) + setup.ask_for_uploading_tapes = TRUE; + DrawMainMenu(); #if 0 - Error(ERR_DEBUG, "::: SDL_GetBasePath() == '%s'", + Debug("internal:path", "SDL_GetBasePath() == '%s'", SDL_GetBasePath()); - Error(ERR_DEBUG, "::: SDL_GetPrefPath() == '%s'", + Debug("internal:path", "SDL_GetPrefPath() == '%s'", SDL_GetPrefPath("artsoft", "rocksndiamonds")); #if defined(PLATFORM_ANDROID) - Error(ERR_DEBUG, "::: SDL_AndroidGetInternalStoragePath() == '%s'", + Debug("internal:path", "SDL_AndroidGetInternalStoragePath() == '%s'", SDL_AndroidGetInternalStoragePath()); - Error(ERR_DEBUG, "::: SDL_AndroidGetExternalStoragePath() == '%s'", + Debug("internal:path", "SDL_AndroidGetExternalStoragePath() == '%s'", SDL_AndroidGetExternalStoragePath()); - Error(ERR_DEBUG, "::: SDL_AndroidGetExternalStorageState() == '%s'", + Debug("internal:path", "SDL_AndroidGetExternalStorageState() == '%s'", (SDL_AndroidGetExternalStorageState() & SDL_ANDROID_EXTERNAL_STORAGE_WRITE ? "writable" : SDL_AndroidGetExternalStorageState() & @@ -6278,8 +6413,44 @@ void OpenAll(void) #endif } +static boolean WaitForApiThreads(void) +{ + unsigned int thread_delay = 0; + unsigned int thread_delay_value = 10000; + + if (program.api_thread_count == 0) + return TRUE; + + // deactivate global animations (not accessible in game state "loading") + setup.toons = FALSE; + + // set game state to "loading" to be able to show busy animation + SetGameStatus(GAME_MODE_LOADING); + + ResetDelayCounter(&thread_delay); + + // wait for threads to finish (and fail on timeout) + while (program.api_thread_count > 0) + { + if (DelayReached(&thread_delay, thread_delay_value)) + { + Error("failed waiting for threads - TIMEOUT"); + + return FALSE; + } + + UPDATE_BUSY_STATE(); + + Delay(20); + } + + return TRUE; +} + void CloseAllAndExit(int exit_value) { + WaitForApiThreads(); + StopSounds(); FreeAllSounds(); FreeAllMusic(); @@ -6295,8 +6466,8 @@ void CloseAllAndExit(int exit_value) // using SDL_WaitThread() // // Code used with SDL 1.2: - // if (network_server) // terminate network server - // SDL_KillThread(server_thread); + // if (network.server_thread) // terminate network server + // SDL_KillThread(network.server_thread); CloseVideoDisplay(); ClosePlatformDependentStuff();