X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Ffiles.c;h=8cb6ec6e3bb879214a56dccee9813f17db73645b;hp=a78b46acd7f1b2e034884c5b407514d1d2d7edc5;hb=e086ff916e148637704376bff8314a8f23c5f552;hpb=58546d540453ea1ddf4142a3911f9873acce1132 diff --git a/src/files.c b/src/files.c index a78b46ac..8cb6ec6e 100644 --- a/src/files.c +++ b/src/files.c @@ -2070,7 +2070,7 @@ static char *getPackedLevelBasename(int type) if ((dir = openDirectory(directory)) == NULL) { - Error(ERR_WARN, "cannot read current level directory '%s'", directory); + Warn("cannot read current level directory '%s'", directory); return basename; } @@ -2334,7 +2334,7 @@ static void copyLevelFileInfo(struct LevelFileInfo *lfi_from, // functions for loading R'n'D level // ---------------------------------------------------------------------------- -static int getMappedElement(int element) +int getMappedElement(int element) { // remap some (historic, now obsolete) elements @@ -2375,7 +2375,7 @@ static int getMappedElement(int element) default: if (element >= NUM_FILE_ELEMENTS) { - Error(ERR_WARN, "invalid level element %d", element); + Warn("invalid level element %d", element); element = EL_UNKNOWN; } @@ -2623,7 +2623,7 @@ static int LoadLevel_CNT2(File *file, int chunk_size, struct LevelInfo *level) } else { - Error(ERR_WARN, "cannot load content for element '%d'", element); + Warn("cannot load content for element '%d'", element); } return chunk_size; @@ -2683,7 +2683,7 @@ static int LoadLevel_CUS1(File *file, int chunk_size, struct LevelInfo *level) if (IS_CUSTOM_ELEMENT(element)) element_info[element].properties[EP_BITFIELD_BASE_NR] = properties; else - Error(ERR_WARN, "invalid custom element number %d", element); + 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) @@ -2716,7 +2716,7 @@ static int LoadLevel_CUS2(File *file, int chunk_size, struct LevelInfo *level) if (IS_CUSTOM_ELEMENT(element)) element_info[element].change->target_element = custom_target_element; else - Error(ERR_WARN, "invalid custom element number %d", element); + Warn("invalid custom element number %d", element); } level->file_has_custom_elements = TRUE; @@ -2744,7 +2744,7 @@ static int LoadLevel_CUS3(File *file, int chunk_size, struct LevelInfo *level) if (!IS_CUSTOM_ELEMENT(element)) { - Error(ERR_WARN, "invalid custom element number %d", element); + Warn("invalid custom element number %d", element); element = EL_INTERNAL_DUMMY; } @@ -2830,9 +2830,10 @@ static int LoadLevel_CUS4(File *file, int chunk_size, struct LevelInfo *level) if (!IS_CUSTOM_ELEMENT(element)) { - Error(ERR_WARN, "invalid custom element number %d", element); + Warn("invalid custom element number %d", element); ReadUnusedBytesFromFile(file, chunk_size - 2); + return chunk_size; } @@ -2978,9 +2979,10 @@ static int LoadLevel_GRP1(File *file, int chunk_size, struct LevelInfo *level) if (!IS_GROUP_ELEMENT(element)) { - Error(ERR_WARN, "invalid group element number %d", element); + Warn("invalid group element number %d", element); ReadUnusedBytesFromFile(file, chunk_size - 2); + return chunk_size; } @@ -3042,9 +3044,8 @@ static int LoadLevel_MicroChunk(File *file, struct LevelFileConfigInfo *conf, 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); + Warn("truncating number of entities for element %d from %d to %d", + element, num_entities, max_num_entities); num_entities = max_num_entities; } @@ -3053,8 +3054,7 @@ static int LoadLevel_MicroChunk(File *file, struct LevelFileConfigInfo *conf, 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); + Warn("found empty list of entities for element %d", element); // do not set "num_entities" here to prevent reading behind buffer @@ -3145,9 +3145,9 @@ static int LoadLevel_MicroChunk(File *file, struct LevelFileConfigInfo *conf, 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)); + 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; @@ -3264,8 +3264,8 @@ static int LoadLevel_CUSX(File *file, int chunk_size, struct LevelInfo *level) if (ei->num_change_pages == -1) { - Error(ERR_WARN, "LoadLevel_CUSX(): missing 'num_change_pages' for '%s'", - EL_NAME(element)); + Warn("LoadLevel_CUSX(): missing 'num_change_pages' for '%s'", + EL_NAME(element)); ei->num_change_pages = 1; @@ -3352,7 +3352,7 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, if (level_info_only) return; - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); + Warn("cannot read level '%s' -- using empty level", filename); if (!setup.editor.use_template_for_new_levels) return; @@ -3379,7 +3379,7 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, { level->no_valid_file = TRUE; - Error(ERR_WARN, "unknown format of level file '%s'", filename); + Warn("unknown format of level file '%s'", filename); closeFile(file); @@ -3398,7 +3398,7 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, { level->no_valid_file = TRUE; - Error(ERR_WARN, "unknown format of level file '%s'", filename); + Warn("unknown format of level file '%s'", filename); closeFile(file); @@ -3409,7 +3409,7 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, { level->no_valid_file = TRUE; - Error(ERR_WARN, "unsupported version of level file '%s'", filename); + Warn("unsupported version of level file '%s'", filename); closeFile(file); @@ -3470,15 +3470,17 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, if (chunk_info[i].name == NULL) { - Error(ERR_WARN, "unknown chunk '%s' in level file '%s'", - chunk_name, filename); + 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); + Warn("wrong size (%d) of chunk '%s' in level file '%s'", + chunk_size, chunk_name, filename); + ReadUnusedBytesFromFile(file, chunk_size); } else @@ -3492,8 +3494,8 @@ static void LoadLevelFromFileInfo_RND(struct LevelInfo *level, // 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); + Warn("wrong size (%d) of chunk '%s' in level file '%s'", + chunk_size, chunk_name, filename); } } } @@ -3820,7 +3822,7 @@ static void CopyNativeLevel_SP_to_RND(struct LevelInfo *level) { num_invalid_elements++; - Error(ERR_DEBUG, "invalid element %d at position %d, %d", + Debug("level:native:SP", "invalid element %d at position %d, %d", element_old, x, y); } @@ -3829,8 +3831,8 @@ static void CopyNativeLevel_SP_to_RND(struct LevelInfo *level) } if (num_invalid_elements > 0) - Error(ERR_WARN, "found %d invalid elements%s", num_invalid_elements, - (!options.debug ? " (use '--debug' for more details)" : "")); + Warn("found %d invalid elements%s", num_invalid_elements, + (!options.debug ? " (use '--debug' for more details)" : "")); for (i = 0; i < MAX_PLAYERS; i++) level->initial_player_gravity[i] = @@ -3866,8 +3868,7 @@ static void CopyNativeLevel_SP_to_RND(struct LevelInfo *level) 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); + Warn("special port position (%d, %d) out of bounds", port_x, port_y); continue; } @@ -3877,7 +3878,7 @@ static void CopyNativeLevel_SP_to_RND(struct LevelInfo *level) 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); + Warn("no special port at position (%d, %d)", port_x, port_y); continue; } @@ -3943,8 +3944,8 @@ static void CopyNativeTape_RND_to_SP(struct LevelInfo *level) if (demo->length + demo_entries >= SP_MAX_TAPE_LEN) { - Error(ERR_WARN, "tape truncated: size exceeds maximum SP demo size %d", - SP_MAX_TAPE_LEN); + Warn("tape truncated: size exceeds maximum SP demo size %d", + SP_MAX_TAPE_LEN); break; } @@ -3997,8 +3998,8 @@ static void CopyNativeTape_SP_to_RND(struct LevelInfo *level) if (!success) { - Error(ERR_WARN, "SP demo truncated: size exceeds maximum tape size %d", - MAX_TAPE_LEN); + Warn("SP demo truncated: size exceeds maximum tape size %d", + MAX_TAPE_LEN); break; } @@ -4273,7 +4274,7 @@ static int getMappedElement_DC(int element) break; case 0x13f5: - element = EL_YAMYAM; + element = EL_YAMYAM_UP; break; case 0x1425: @@ -5299,7 +5300,7 @@ static int getMappedElement_DC(int element) break; case 0x1682: // secret gate (red) - element = EL_GATE_1_GRAY; + element = EL_EM_GATE_1_GRAY; break; case 0x1683: // gate (yellow) @@ -5307,7 +5308,7 @@ static int getMappedElement_DC(int element) break; case 0x1684: // secret gate (yellow) - element = EL_GATE_2_GRAY; + element = EL_EM_GATE_2_GRAY; break; case 0x1685: // gate (blue) @@ -5315,7 +5316,7 @@ static int getMappedElement_DC(int element) break; case 0x1686: // secret gate (blue) - element = EL_GATE_4_GRAY; + element = EL_EM_GATE_4_GRAY; break; case 0x1687: // gate (green) @@ -5323,7 +5324,7 @@ static int getMappedElement_DC(int element) break; case 0x1688: // secret gate (green) - element = EL_GATE_3_GRAY; + element = EL_EM_GATE_3_GRAY; break; case 0x1689: // gate (white) @@ -5554,7 +5555,8 @@ static int getMappedElement_DC(int element) element = EL_INVISIBLE_SAND; else { - Error(ERR_WARN, "unknown Diamond Caves element 0x%04x", element); + Warn("unknown Diamond Caves element 0x%04x", element); + element = EL_UNKNOWN; } break; @@ -5602,7 +5604,7 @@ static void LoadLevelFromFileStream_DC(File *file, struct LevelInfo *level, { level->no_valid_file = TRUE; - Error(ERR_WARN, "cannot decode level from stream -- using empty level"); + Warn("cannot decode level from stream -- using empty level"); return; } @@ -5715,6 +5717,13 @@ static void LoadLevelFromFileStream_DC(File *file, struct LevelInfo *level, level->extra_time = header[56] | (header[57] << 8); level->shield_normal_time = header[58] | (header[59] << 8); + // shield and extra time elements do not have a score + level->score[SC_SHIELD] = 0; + level->extra_time_score = 0; + + // set time for normal and deadly shields to the same value + level->shield_deadly_time = level->shield_normal_time; + // 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; @@ -5735,7 +5744,7 @@ static void LoadLevelFromFileInfo_DC(struct LevelInfo *level, level->no_valid_file = TRUE; if (!level_info_only) - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); + Warn("cannot read level '%s' -- using empty level", filename); return; } @@ -5753,8 +5762,7 @@ static void LoadLevelFromFileInfo_DC(struct LevelInfo *level, { level->no_valid_file = TRUE; - Error(ERR_WARN, "unknown DC level file '%s' -- using empty level", - filename); + Warn("unknown DC level file '%s' -- using empty level", filename); return; } @@ -5780,8 +5788,7 @@ static void LoadLevelFromFileInfo_DC(struct LevelInfo *level, { level->no_valid_file = TRUE; - Error(ERR_WARN, "cannot fseek in file '%s' -- using empty level", - filename); + Warn("cannot fseek in file '%s' -- using empty level", filename); return; } @@ -5799,8 +5806,7 @@ static void LoadLevelFromFileInfo_DC(struct LevelInfo *level, { level->no_valid_file = TRUE; - Error(ERR_WARN, "unknown DC2 level file '%s' -- using empty level", - filename); + Warn("unknown DC2 level file '%s' -- using empty level", filename); return; } @@ -5875,7 +5881,7 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, level->no_valid_file = TRUE; if (!level_info_only) - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); + Warn("cannot read level '%s' -- using empty level", filename); return; } @@ -6049,7 +6055,7 @@ static void LoadLevelFromFileInfo_SB(struct LevelInfo *level, { level->no_valid_file = TRUE; - Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename); + Warn("cannot read level '%s' -- using empty level", filename); return; } @@ -6631,7 +6637,7 @@ void LoadLevelTemplate(int nr) { if (!fileExists(getGlobalLevelTemplateFilename())) { - Error(ERR_WARN, "no level template found for this level"); + Warn("no level template found for this level"); return; } @@ -6872,7 +6878,8 @@ static void SaveLevel_CNT2(FILE *file, struct LevelInfo *level, int element) // chunk header already written -- write empty chunk data WriteUnusedBytesToFile(file, LEVEL_CHUNK_CNT2_SIZE); - Error(ERR_WARN, "cannot save content for element '%d'", element); + Warn("cannot save content for element '%d'", element); + return; } @@ -6940,7 +6947,7 @@ static void SaveLevel_CUS1(FILE *file, struct LevelInfo *level, } if (check != num_changed_custom_elements) // should not happen - Error(ERR_WARN, "inconsistent number of custom element properties"); + Warn("inconsistent number of custom element properties"); } #endif @@ -6969,7 +6976,7 @@ static void SaveLevel_CUS2(FILE *file, struct LevelInfo *level, } if (check != num_changed_custom_elements) // should not happen - Error(ERR_WARN, "inconsistent number of custom target elements"); + Warn("inconsistent number of custom target elements"); } #endif @@ -7052,7 +7059,7 @@ static void SaveLevel_CUS3(FILE *file, struct LevelInfo *level, } if (check != num_changed_custom_elements) // should not happen - Error(ERR_WARN, "inconsistent number of custom element properties"); + Warn("inconsistent number of custom element properties"); } #endif @@ -7430,7 +7437,8 @@ static void SaveLevelFromFilename(struct LevelInfo *level, char *filename, if (!(file = fopen(filename, MODE_WRITE))) { - Error(ERR_WARN, "cannot save level file '%s'", filename); + Warn("cannot save level file '%s'", filename); + return; } @@ -7555,7 +7563,7 @@ void DumpLevel(struct LevelInfo *level) { if (level->no_level_file || level->no_valid_file) { - Error(ERR_WARN, "cannot dump -- no valid level file found"); + Warn("cannot dump -- no valid level file found"); return; } @@ -7746,7 +7754,7 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape) { if (i >= MAX_TAPE_LEN) { - Error(ERR_WARN, "tape truncated -- size exceeds maximum tape size %d", + Warn("tape truncated -- size exceeds maximum tape size %d", MAX_TAPE_LEN); // tape too large; read and ignore remaining tape data from this chunk @@ -7892,7 +7900,7 @@ static void LoadTape_SokobanSolution(char *filename) default: tape.no_valid_file = TRUE; - Error(ERR_WARN, "unsupported Sokoban solution file '%s' ['%d']", filename, c); + Warn("unsupported Sokoban solution file '%s' ['%d']", filename, c); break; } @@ -7941,7 +7949,7 @@ void LoadTapeFromFilename(char *filename) { tape.no_valid_file = TRUE; - Error(ERR_WARN, "unknown format of tape file '%s'", filename); + Warn("unknown format of tape file '%s'", filename); closeFile(file); @@ -7960,7 +7968,7 @@ void LoadTapeFromFilename(char *filename) { tape.no_valid_file = TRUE; - Error(ERR_WARN, "unknown format of tape file '%s'", filename); + Warn("unknown format of tape file '%s'", filename); closeFile(file); @@ -7971,7 +7979,7 @@ void LoadTapeFromFilename(char *filename) { tape.no_valid_file = TRUE; - Error(ERR_WARN, "unsupported version of tape file '%s'", filename); + Warn("unsupported version of tape file '%s'", filename); closeFile(file); @@ -8015,15 +8023,17 @@ void LoadTapeFromFilename(char *filename) if (chunk_info[i].name == NULL) { - Error(ERR_WARN, "unknown chunk '%s' in tape file '%s'", + 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'", + Warn("wrong size (%d) of chunk '%s' in tape file '%s'", chunk_size, chunk_name, filename); + ReadUnusedBytesFromFile(file, chunk_size); } else @@ -8037,7 +8047,7 @@ void LoadTapeFromFilename(char *filename) // information, so check them here if (chunk_size_expected != chunk_size) { - Error(ERR_WARN, "wrong size (%d) of chunk '%s' in tape file '%s'", + Warn("wrong size (%d) of chunk '%s' in tape file '%s'", chunk_size, chunk_name, filename); } } @@ -8050,9 +8060,12 @@ void LoadTapeFromFilename(char *filename) tape.length_seconds = GetTapeLengthSeconds(); #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); + Debug("files:LoadTapeFromFilename", "tape file version: %d", + tape.file_version); + Debug("files:LoadTapeFromFilename", "tape game version: %d", + tape.game_version); + Debug("files:LoadTapeFromFilename", "tape engine version: %d", + tape.engine_version); #endif } @@ -8153,7 +8166,8 @@ void SaveTapeToFilename(char *filename) if (!(file = fopen(filename, MODE_WRITE))) { - Error(ERR_WARN, "cannot save level recording file '%s'", filename); + Warn("cannot save level recording file '%s'", filename); + return; } @@ -8242,7 +8256,7 @@ void DumpTape(struct TapeInfo *tape) if (tape->no_valid_file) { - Error(ERR_WARN, "cannot dump -- no valid tape file found"); + Warn("cannot dump -- no valid tape file found"); return; } @@ -8322,15 +8336,18 @@ void LoadScore(int nr) if (!checkCookieString(cookie, SCORE_COOKIE)) { - Error(ERR_WARN, "unknown format of score file '%s'", filename); + Warn("unknown format of score file '%s'", filename); + fclose(file); + return; } for (i = 0; i < MAX_SCORE_ENTRIES; i++) { if (fscanf(file, "%d", &highscore[i].Score) == EOF) - Error(ERR_WARN, "fscanf() failed; %s", strerror(errno)); + Warn("fscanf() failed; %s", strerror(errno)); + if (fgets(line, MAX_LINE_LEN, file) == NULL) line[0] = '\0'; @@ -8363,7 +8380,8 @@ void SaveScore(int nr) if (!(file = fopen(filename, MODE_WRITE))) { - Error(ERR_WARN, "cannot save score for level %d", nr); + Warn("cannot save score for level %d", nr); + return; } @@ -8391,6 +8409,10 @@ static struct TokenInfo global_setup_tokens[] = TYPE_STRING, &setup.player_name, "player_name" }, + { + TYPE_SWITCH, + &setup.multiple_users, "multiple_users" + }, { TYPE_SWITCH, &setup.sound, "sound" @@ -9135,6 +9157,14 @@ static struct TokenInfo debug_setup_tokens[] = TYPE_BOOLEAN, &setup.debug.show_frames_per_second, "debug.show_frames_per_second" }, + { + TYPE_SWITCH3, + &setup.debug.xsn_mode, "debug.xsn_mode" + }, + { + TYPE_INTEGER, + &setup.debug.xsn_percent, "debug.xsn_percent" + }, }; static struct TokenInfo options_setup_tokens[] = @@ -9145,26 +9175,14 @@ static struct TokenInfo options_setup_tokens[] = }, }; -static char *get_corrected_login_name(char *login_name) -{ - // needed because player name must be a fixed length string - char *login_name_new = checked_malloc(MAX_PLAYER_NAME_LEN + 1); - - strncpy(login_name_new, login_name, MAX_PLAYER_NAME_LEN); - login_name_new[MAX_PLAYER_NAME_LEN] = '\0'; - - if (strlen(login_name) > MAX_PLAYER_NAME_LEN) // name has been cut - if (strchr(login_name_new, ' ')) - *strchr(login_name_new, ' ') = '\0'; - - return login_name_new; -} - static void setSetupInfoToDefaults(struct SetupInfo *si) { + char *player_name = (user.nr == 0 ? getLoginName() : EMPTY_PLAYER_NAME); int i; - si->player_name = get_corrected_login_name(getLoginName()); + si->player_name = getFixedUserName(player_name); + + si->multiple_users = TRUE; si->sound = TRUE; si->sound_loops = TRUE; @@ -9408,11 +9426,16 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) si->debug.show_frames_per_second = FALSE; + si->debug.xsn_mode = AUTO; + si->debug.xsn_percent = 0; + si->options.verbose = FALSE; #if defined(PLATFORM_ANDROID) si->fullscreen = TRUE; #endif + + setHideSetupEntry(&setup.debug.xsn_mode); } static void setSetupInfoToDefaults_AutoSetup(struct SetupInfo *si) @@ -9459,10 +9482,21 @@ void setHideSetupEntry(void *setup_value) { char *hide_setup_token = getHideSetupToken(setup_value); + if (hide_setup_hash == NULL) + hide_setup_hash = newSetupFileHash(); + if (setup_value != NULL) setHashEntry(hide_setup_hash, hide_setup_token, ""); } +void removeHideSetupEntry(void *setup_value) +{ + char *hide_setup_token = getHideSetupToken(setup_value); + + if (setup_value != NULL) + removeHashEntry(hide_setup_hash, hide_setup_token); +} + boolean hideSetupEntry(void *setup_value) { char *hide_setup_token = getHideSetupToken(setup_value); @@ -9484,6 +9518,8 @@ static void setSetupInfoFromTokenText(SetupFileHash *setup_file_hash, // check if this setup option should be hidden in the setup menu if (token_hide_value != NULL && get_boolean_from_string(token_hide_value)) setHideSetupEntry(token_info[token_nr].value); + + free(token_hide_text); } static void setSetupInfoFromTokenInfo(SetupFileHash *setup_file_hash, @@ -9501,9 +9537,6 @@ static void decodeSetupFileHash(SetupFileHash *setup_file_hash) if (!setup_file_hash) return; - if (hide_setup_hash == NULL) - hide_setup_hash = newSetupFileHash(); - for (i = 0; i < ARRAY_SIZE(global_setup_tokens); i++) setSetupInfoFromTokenInfo(setup_file_hash, global_setup_tokens, i); @@ -9610,6 +9643,43 @@ static void decodeSetupFileHash_EditorCascade(SetupFileHash *setup_file_hash) editor_cascade_setup_tokens[i].text)); } +void LoadUserNames(void) +{ + int last_user_nr = user.nr; + int i; + + if (global.user_names != NULL) + { + for (i = 0; i < MAX_PLAYER_NAMES; i++) + checked_free(global.user_names[i]); + + checked_free(global.user_names); + } + + global.user_names = checked_calloc(MAX_PLAYER_NAMES * sizeof(char *)); + + for (i = 0; i < MAX_PLAYER_NAMES; i++) + { + user.nr = i; + + SetupFileHash *setup_file_hash = loadSetupFileHash(getSetupFilename()); + + if (setup_file_hash) + { + char *player_name = getHashEntry(setup_file_hash, "player_name"); + + global.user_names[i] = getFixedUserName(player_name); + + freeSetupFileHash(setup_file_hash); + } + + if (global.user_names[i] == NULL) + global.user_names[i] = getStringCopy(EMPTY_PLAYER_NAME); + } + + user.nr = last_user_nr; +} + void LoadSetupFromFilename(char *filename) { SetupFileHash *setup_file_hash = loadSetupFileHash(filename); @@ -9622,7 +9692,7 @@ void LoadSetupFromFilename(char *filename) } else { - Error(ERR_DEBUG, "using default setup values"); + Debug("setup", "using default setup values"); } } @@ -9631,7 +9701,7 @@ static void LoadSetup_SpecialPostProcessing(void) char *player_name_new; // needed to work around problems with fixed length strings - player_name_new = get_corrected_login_name(setup.player_name); + player_name_new = getFixedUserName(setup.player_name); free(setup.player_name); setup.player_name = player_name_new; @@ -9739,7 +9809,7 @@ static void LoadSetup_ReadGameControllerMappings(SetupFileHash *mappings_hash, if (!(file = fopen(filename, MODE_READ))) { - Error(ERR_WARN, "cannot read game controller mappings file '%s'", filename); + Warn("cannot read game controller mappings file '%s'", filename); return; } @@ -9767,7 +9837,8 @@ void SaveSetup(void) if (!(file = fopen(filename, MODE_WRITE))) { - Error(ERR_WARN, "cannot write setup file '%s'", filename); + Warn("cannot write setup file '%s'", filename); + return; } @@ -9776,7 +9847,8 @@ void SaveSetup(void) for (i = 0; i < ARRAY_SIZE(global_setup_tokens); i++) { // just to make things nicer :) - if (global_setup_tokens[i].value == &setup.sound || + if (global_setup_tokens[i].value == &setup.multiple_users || + global_setup_tokens[i].value == &setup.sound || global_setup_tokens[i].value == &setup.graphics_set || global_setup_tokens[i].value == &setup.volume_simple || global_setup_tokens[i].value == &setup.network_mode || @@ -9844,7 +9916,9 @@ void SaveSetup(void) fprintf(file, "\n"); for (i = 0; i < ARRAY_SIZE(debug_setup_tokens); i++) - fprintf(file, "%s\n", getSetupLine(debug_setup_tokens, "", i)); + if (!strPrefix(debug_setup_tokens[i].text, "debug.xsn_") || + setup.debug.xsn_mode != AUTO) + fprintf(file, "%s\n", getSetupLine(debug_setup_tokens, "", i)); fprintf(file, "\n"); for (i = 0; i < ARRAY_SIZE(options_setup_tokens); i++) @@ -9865,8 +9939,10 @@ void SaveSetup_AutoSetup(void) if (!(file = fopen(filename, MODE_WRITE))) { - Error(ERR_WARN, "cannot write auto setup file '%s'", filename); + Warn("cannot write auto setup file '%s'", filename); + free(filename); + return; } @@ -9892,8 +9968,10 @@ void SaveSetup_EditorCascade(void) if (!(file = fopen(filename, MODE_WRITE))) { - Error(ERR_WARN, "cannot write editor cascade state file '%s'", filename); + Warn("cannot write editor cascade state file '%s'", filename); + free(filename); + return; } @@ -9916,7 +9994,7 @@ static void SaveSetup_WriteGameControllerMappings(SetupFileHash *mappings_hash, if (!(file = fopen(filename, MODE_WRITE))) { - Error(ERR_WARN, "cannot write game controller mappings file '%s'",filename); + Warn("cannot write game controller mappings file '%s'", filename); return; } @@ -9989,7 +10067,7 @@ static int getElementFromToken(char *token) if (value != NULL) return atoi(value); - Error(ERR_WARN, "unknown element token '%s'", token); + Warn("unknown element token '%s'", token); return EL_UNDEFINED; } @@ -10246,6 +10324,10 @@ static int get_anim_parameter_values(char *s) static int get_anim_action_parameter_value(char *token) { + // check most common default case first to massively speed things up + if (strEqual(token, ARG_UNDEFINED)) + return ANIM_EVENT_ACTION_NONE; + int result = getImageIDFromToken(token); if (result == -1) @@ -11338,19 +11420,19 @@ void LoadUserDefinedEditorElementList(int **elements, int *num_elements) { if (num_unknown_tokens == 0) { - Error(ERR_INFO_LINE, "-"); - Error(ERR_INFO, "warning: unknown token(s) found in config file:"); - Error(ERR_INFO, "- config file: '%s'", filename); + Warn("---"); + Warn("unknown token(s) found in config file:"); + Warn("- config file: '%s'", filename); num_unknown_tokens++; } - Error(ERR_INFO, "- token: '%s'", list->token); + Warn("- token: '%s'", list->token); } } if (num_unknown_tokens > 0) - Error(ERR_INFO_LINE, "-"); + Warn("---"); while (*num_elements % 4) // pad with empty elements, if needed (*elements)[(*num_elements)++] = EL_EMPTY; @@ -11360,8 +11442,8 @@ void LoadUserDefinedEditorElementList(int **elements, int *num_elements) #if 0 for (i = 0; i < *num_elements; i++) - printf("editor: element '%s' [%d]\n", - element_info[(*elements)[i]].token_name, (*elements)[i]); + Debug("editor", "element '%s' [%d]\n", + element_info[(*elements)[i]].token_name, (*elements)[i]); #endif } @@ -11540,7 +11622,8 @@ void LoadMusicInfo(void) if ((dir = openDirectory(music_directory)) == NULL) { - Error(ERR_WARN, "cannot read music directory '%s'", music_directory); + Warn("cannot read music directory '%s'", music_directory); + return; } @@ -11628,18 +11711,18 @@ static void print_unknown_token(char *filename, char *token, int token_nr) { if (token_nr == 0) { - Error(ERR_INFO_LINE, "-"); - Error(ERR_INFO, "warning: unknown token(s) found in config file:"); - Error(ERR_INFO, "- config file: '%s'", filename); + Warn("---"); + Warn("unknown token(s) found in config file:"); + Warn("- config file: '%s'", filename); } - Error(ERR_INFO, "- token: '%s'", token); + Warn("- token: '%s'", token); } static void print_unknown_token_end(int token_nr) { if (token_nr > 0) - Error(ERR_INFO_LINE, "-"); + Warn("---"); } void LoadHelpAnimInfo(void) @@ -11843,12 +11926,12 @@ void LoadHelpAnimInfo(void) #if 0 for (i = 0; i < num_list_entries; i++) - printf("::: '%s': %d, %d, %d => %d\n", - EL_NAME(helpanim_info[i].element), - helpanim_info[i].element, - helpanim_info[i].action, - helpanim_info[i].direction, - helpanim_info[i].delay); + Debug("files:LoadHelpAnimInfo", "'%s': %d, %d, %d => %d", + EL_NAME(helpanim_info[i].element), + helpanim_info[i].element, + helpanim_info[i].action, + helpanim_info[i].direction, + helpanim_info[i].delay); #endif } @@ -11880,8 +11963,8 @@ void LoadHelpTextInfo(void) #if 0 BEGIN_HASH_ITERATION(helptext_info, itr) { - printf("::: '%s' => '%s'\n", - HASH_ITERATION_TOKEN(itr), HASH_ITERATION_VALUE(itr)); + Debug("files:LoadHelpTextInfo", "'%s' => '%s'", + HASH_ITERATION_TOKEN(itr), HASH_ITERATION_VALUE(itr)); } END_HASH_ITERATION(hash, itr) #endif @@ -11907,8 +11990,7 @@ void ConvertLevels(void) global.convert_leveldir); if (convert_leveldir == NULL) - Error(ERR_EXIT, "no such level identifier: '%s'", - global.convert_leveldir); + Fail("no such level identifier: '%s'", global.convert_leveldir); leveldir_current = convert_leveldir; @@ -12035,13 +12117,13 @@ void CreateLevelSketchImages(void) BlitBitmap(drawto, bitmap1, SX, SY, TILEX, TILEY, 0, 0); if (SDL_SaveBMP(bitmap1->surface, filename1) != 0) - Error(ERR_EXIT, "cannot save level sketch image file '%s'", filename1); + Fail("cannot save level sketch image file '%s'", filename1); DrawSizedElement(0, 0, element, MINI_TILESIZE); BlitBitmap(drawto, bitmap2, SX, SY, MINI_TILEX, MINI_TILEY, 0, 0); if (SDL_SaveBMP(bitmap2->surface, filename2) != 0) - Error(ERR_EXIT, "cannot save level sketch image file '%s'", filename2); + Fail("cannot save level sketch image file '%s'", filename2); free(filename1); free(filename2); @@ -12067,7 +12149,7 @@ void CreateLevelSketchImages(void) if (options.debug) fprintf(stderr, "\n"); - Error(ERR_INFO, "%d normal and small images created", NUM_FILE_ELEMENTS); + Info("%d normal and small images created", NUM_FILE_ELEMENTS); CloseAllAndExit(0); } @@ -12165,7 +12247,7 @@ void CreateCustomElementImages(char *directory) } if (SDL_SaveBMP(bitmap->surface, dst_filename) != 0) - Error(ERR_EXIT, "cannot save CE graphics file '%s'", dst_filename); + Fail("cannot save CE graphics file '%s'", dst_filename); FreeBitmap(bitmap);