X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ffiles.c;h=5ff8c06a873f0d0f14adc23d7e2258f92e36ed3d;hb=942ec4881e3b21c130df9ae105d06c2c633fa192;hp=011f715e0d8d94cf3bd48543f0d0175f908cb83f;hpb=2a357b702b5ceb9bf9173ac02f68cf42340b3158;p=rocksndiamonds.git diff --git a/src/files.c b/src/files.c index 011f715e..5ff8c06a 100644 --- a/src/files.c +++ b/src/files.c @@ -1032,7 +1032,7 @@ static void LoadLevel_InitElements(struct LevelInfo *level, char *filename) int element = EL_CUSTOM_START + i; /* order of checking and copying events to be mapped is important */ - for (j = CE_BY_OTHER_ACTION; j >= CE_BY_PLAYER; j--) + for (j = CE_BY_OTHER_ACTION; j >= CE_BY_PLAYER_OBSOLETE; j--) { if (HAS_CHANGE_EVENT(element, j - 2)) { @@ -1042,7 +1042,7 @@ static void LoadLevel_InitElements(struct LevelInfo *level, char *filename) } /* order of checking and copying events to be mapped is important */ - for (j = CE_OTHER_GETS_COLLECTED; j >= CE_COLLISION; j--) + for (j = CE_OTHER_GETS_COLLECTED; j >= CE_COLLISION_ACTIVE; j--) { if (HAS_CHANGE_EVENT(element, j - 1)) { @@ -1058,11 +1058,11 @@ static void LoadLevel_InitElements(struct LevelInfo *level, char *filename) { int element = EL_CUSTOM_START + i; - if (HAS_CHANGE_EVENT(element, CE_BY_PLAYER) || - HAS_CHANGE_EVENT(element, CE_BY_COLLISION)) + if (HAS_CHANGE_EVENT(element, CE_BY_PLAYER_OBSOLETE) || + HAS_CHANGE_EVENT(element, CE_BY_COLLISION_OBSOLETE)) { - SET_CHANGE_EVENT(element, CE_BY_PLAYER, FALSE); - SET_CHANGE_EVENT(element, CE_BY_COLLISION, FALSE); + SET_CHANGE_EVENT(element, CE_BY_PLAYER_OBSOLETE, FALSE); + SET_CHANGE_EVENT(element, CE_BY_COLLISION_OBSOLETE, FALSE); SET_CHANGE_EVENT(element, CE_BY_DIRECT_ACTION, TRUE); } @@ -2762,23 +2762,6 @@ void LoadSpecialMenuDesignSettings() freeSetupFileHash(setup_file_hash); } -static char *itoa(unsigned int i) -{ - static char *a = NULL; - - if (a != NULL) - free(a); - - if (i > 2147483647) /* yes, this is a kludge */ - i = 2147483647; - - a = checked_malloc(10 + 1); - - sprintf(a, "%d", i); - - return a; -} - void LoadUserDefinedEditorElementList(int **elements, int *num_elements) { char *filename = getEditorSetupFilename(); @@ -2793,7 +2776,7 @@ void LoadUserDefinedEditorElementList(int **elements, int *num_elements) element_hash = newSetupFileHash(); for (i = 0; i < NUM_FILE_ELEMENTS; i++) - setHashEntry(element_hash, element_info[i].token_name, itoa(i)); + setHashEntry(element_hash, element_info[i].token_name, i_to_a(i)); /* determined size may be larger than needed (due to unknown elements) */ *num_elements = 0; @@ -2962,10 +2945,19 @@ void LoadMusicInfo() new = &music_file_info; + printf("::: num_music == %d\n", num_music); + for (i = 0; i < num_music; i++) { music = getMusicListEntry(i); +#if 0 + printf("::: %d [%08x]\n", i, music->filename); +#endif + + if (music->filename == NULL) + continue; + if (strcmp(music->filename, UNDEFINED_FILENAME) == 0) continue; @@ -2998,6 +2990,9 @@ void LoadMusicInfo() { music = getMusicListEntry(i); + if (music->filename == NULL) + continue; + if (strcmp(basename, music->filename) == 0) { music_already_used = TRUE; @@ -3069,13 +3064,16 @@ void print_unknown_token_end(int token_nr) void LoadHelpAnimInfo() { char *filename = getHelpAnimFilename(); - SetupFileList *setup_file_list, *list; + SetupFileList *setup_file_list = NULL, *list; SetupFileHash *element_hash, *action_hash, *direction_hash; int num_list_entries = 0; int num_unknown_tokens = 0; int i; - if ((setup_file_list = loadSetupFileList(filename)) == NULL) + if (fileExists(filename)) + setup_file_list = loadSetupFileList(filename); + + if (setup_file_list == NULL) { /* use reliable default values from static configuration */ SetupFileList *insert_ptr; @@ -3095,16 +3093,16 @@ void LoadHelpAnimInfo() direction_hash = newSetupFileHash(); for (i = 0; i < MAX_NUM_ELEMENTS; i++) - setHashEntry(element_hash, element_info[i].token_name, itoa(i)); + setHashEntry(element_hash, element_info[i].token_name, i_to_a(i)); for (i = 0; i < NUM_ACTIONS; i++) setHashEntry(action_hash, element_action_info[i].suffix, - itoa(element_action_info[i].value)); + i_to_a(element_action_info[i].value)); /* do not store direction index (bit) here, but direction value! */ for (i = 0; i < NUM_DIRECTIONS; i++) setHashEntry(direction_hash, element_direction_info[i].suffix, - itoa(1 << element_direction_info[i].value)); + i_to_a(1 << element_direction_info[i].value)); for (list = setup_file_list; list != NULL; list = list->next) { @@ -3119,35 +3117,44 @@ void LoadHelpAnimInfo() continue; } - element_token = list->token; - element_value = getHashEntry(element_hash, element_token); + /* first try to break element into element/action/direction parts; + if this does not work, also accept combined "element[.act][.dir]" + elements (like "dynamite.active"), which are unique elements */ - if (element_value != NULL) + if (strchr(list->token, '.') == NULL) /* token contains no '.' */ { - /* element found */ - add_helpanim_entry(atoi(element_value), -1, -1, delay,&num_list_entries); + element_value = getHashEntry(element_hash, list->token); + if (element_value != NULL) /* element found */ + add_helpanim_entry(atoi(element_value), -1, -1, delay, + &num_list_entries); + else + { + /* no further suffixes found -- this is not an element */ + print_unknown_token(filename, list->token, num_unknown_tokens++); + } continue; } - if (strchr(element_token, '.') == NULL) - { - /* no further suffixes found -- this is not an element */ - print_unknown_token(filename, list->token, num_unknown_tokens++); + /* token has format "." */ - continue; - } + action_token = strchr(list->token, '.'); /* suffix may be action ... */ + direction_token = action_token; /* ... or direction */ - action_token = strchr(element_token, '.'); - element_token = getStringCopy(element_token); + element_token = getStringCopy(list->token); *strchr(element_token, '.') = '\0'; element_value = getHashEntry(element_hash, element_token); - if (element_value == NULL) + if (element_value == NULL) /* this is no element */ { - /* this is not an element */ - print_unknown_token(filename, list->token, num_unknown_tokens++); + element_value = getHashEntry(element_hash, list->token); + if (element_value != NULL) /* combined element found */ + add_helpanim_entry(atoi(element_value), -1, -1, delay, + &num_list_entries); + else + print_unknown_token(filename, list->token, num_unknown_tokens++); + free(element_token); continue; @@ -3155,24 +3162,23 @@ void LoadHelpAnimInfo() action_value = getHashEntry(action_hash, action_token); - if (action_value != NULL) + if (action_value != NULL) /* action found */ { - /* action found */ add_helpanim_entry(atoi(element_value), atoi(action_value), -1, delay, &num_list_entries); + free(element_token); continue; } - direction_token = action_token; direction_value = getHashEntry(direction_hash, direction_token); - if (direction_value != NULL) + if (direction_value != NULL) /* direction found */ { - /* direction found */ add_helpanim_entry(atoi(element_value), -1, atoi(direction_value), delay, &num_list_entries); + free(element_token); continue; @@ -3180,23 +3186,38 @@ void LoadHelpAnimInfo() if (strchr(action_token + 1, '.') == NULL) { - /* no further suffixes found -- this is not an action or direction */ - print_unknown_token(filename, list->token, num_unknown_tokens++); + /* no further suffixes found -- this is not an action nor direction */ + + element_value = getHashEntry(element_hash, list->token); + if (element_value != NULL) /* combined element found */ + add_helpanim_entry(atoi(element_value), -1, -1, delay, + &num_list_entries); + else + print_unknown_token(filename, list->token, num_unknown_tokens++); + free(element_token); continue; } + /* token has format ".." */ + direction_token = strchr(action_token + 1, '.'); + action_token = getStringCopy(action_token); *strchr(action_token + 1, '.') = '\0'; action_value = getHashEntry(action_hash, action_token); - if (action_value == NULL) + if (action_value == NULL) /* this is no action */ { - /* this is not an action */ - print_unknown_token(filename, list->token, num_unknown_tokens++); + element_value = getHashEntry(element_hash, list->token); + if (element_value != NULL) /* combined element found */ + add_helpanim_entry(atoi(element_value), -1, -1, delay, + &num_list_entries); + else + print_unknown_token(filename, list->token, num_unknown_tokens++); + free(element_token); free(action_token); @@ -3205,18 +3226,25 @@ void LoadHelpAnimInfo() direction_value = getHashEntry(direction_hash, direction_token); - if (direction_value != NULL) + if (direction_value != NULL) /* direction found */ { - /* direction found */ add_helpanim_entry(atoi(element_value), atoi(action_value), atoi(direction_value), delay, &num_list_entries); + free(element_token); free(action_token); continue; } - print_unknown_token(filename, list->token, num_unknown_tokens++); + /* this is no direction */ + + element_value = getHashEntry(element_hash, list->token); + if (element_value != NULL) /* combined element found */ + add_helpanim_entry(atoi(element_value), -1, -1, delay, + &num_list_entries); + else + print_unknown_token(filename, list->token, num_unknown_tokens++); free(element_token); free(action_token); @@ -3224,7 +3252,8 @@ void LoadHelpAnimInfo() print_unknown_token_end(num_unknown_tokens); - add_helpanim_entry(HELPANIM_LIST_END, -1, -1, -1, &num_list_entries); + add_helpanim_entry(HELPANIM_LIST_NEXT, -1, -1, -1, &num_list_entries); + add_helpanim_entry(HELPANIM_LIST_END, -1, -1, -1, &num_list_entries); freeSetupFileList(setup_file_list); freeSetupFileHash(element_hash); @@ -3248,9 +3277,15 @@ void LoadHelpTextInfo() int i; if (helptext_info != NULL) + { freeSetupFileHash(helptext_info); + helptext_info = NULL; + } + + if (fileExists(filename)) + helptext_info = loadSetupFileHash(filename); - if ((helptext_info = loadSetupFileHash(filename)) == NULL) + if (helptext_info == NULL) { /* use reliable default values from static configuration */ helptext_info = newSetupFileHash();