X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ffiles.c;h=cb4c6a605a173139931c8203c7f39353b77275a6;hb=c2a639c0b2c1a9a2bd14de86932a47429ae918a4;hp=f8b4983994e6549448e8ad9a577da8dddb5170ca;hpb=d292f0ad61b32968ca4a6750b93ac7e5b99ff00d;p=rocksndiamonds.git diff --git a/src/files.c b/src/files.c index f8b49839..cb4c6a60 100644 --- a/src/files.c +++ b/src/files.c @@ -13,6 +13,7 @@ #include #include +#include #include #include "libgame/libgame.h" @@ -613,7 +614,7 @@ static int LoadLevel_CUS3(FILE *file, int chunk_size, struct LevelInfo *level) { Error(ERR_WARN, "invalid custom element number %d", element); - element = EL_DEFAULT; /* dummy element used for artwork config */ + element = EL_DUMMY; } for(j=0; jnext; + + if (music_file_info->context) + free(music_file_info->context); + if (music_file_info->title) + free(music_file_info->title); + if (music_file_info->artist) + free(music_file_info->artist); + if (music_file_info->album) + free(music_file_info->album); + if (music_file_info->year) + free(music_file_info->year); + + free(music_file_info); + + music_file_info = next; + } + + new = &music_file_info; + + for (i=0; i < num_music; i++) + { + music = getMusicListEntry(i); + + if (strcmp(music->filename, UNDEFINED_FILENAME) == 0) + continue; + +#if 0 + printf("::: -> '%s'\n", music->filename); +#endif + + *new = get_music_file_info(music->filename); + if (*new != NULL) + new = &(*new)->next; + } + + if ((dir = opendir(music_directory)) == NULL) + { + Error(ERR_WARN, "cannot read music directory '%s'", music_directory); + return; + } + + while ((dir_entry = readdir(dir)) != NULL) /* loop until last dir entry */ + { + char *basename = dir_entry->d_name; + boolean music_already_used = FALSE; + int i; + + for (i=0; i < num_music; i++) + { + music = getMusicListEntry(i); + + if (strcmp(basename, music->filename) == 0) + { + music_already_used = TRUE; + break; + } + } + + if (music_already_used) + continue; + + if (!FileIsSound(basename) && !FileIsMusic(basename)) + continue; + +#if 0 + printf("::: -> '%s'\n", basename); +#endif + + *new = get_music_file_info(basename); + if (*new != NULL) + new = &(*new)->next; + } + + closedir(dir); + +#if 0 + /* TEST-ONLY */ + for (next = music_file_info; next != NULL; next = next->next) + printf("::: title == '%s'\n", next->title); +#endif +} + +void add_demo_anim(int element, int action, int direction, int delay, + int *num_list_entries) +{ + struct DemoAnimInfo *new_list_entry; + (*num_list_entries)++; + + demo_anim_info = + checked_realloc(demo_anim_info, + *num_list_entries * sizeof(struct DemoAnimInfo)); + new_list_entry = &demo_anim_info[*num_list_entries - 1]; + + new_list_entry->element = element; + new_list_entry->action = action; + new_list_entry->direction = direction; + new_list_entry->delay = delay; +} + +void print_unknown_token(char *filename, char *token, int token_nr) +{ + if (token_nr == 0) + { + Error(ERR_RETURN_LINE, "-"); + Error(ERR_RETURN, "warning: unknown token(s) found in config file:"); + Error(ERR_RETURN, "- config file: '%s'", filename); + } + + Error(ERR_RETURN, "- token: '%s'", token); +} + +void print_unknown_token_end(int token_nr) +{ + if (token_nr > 0) + Error(ERR_RETURN_LINE, "-"); +} + +void LoadDemoAnimInfo() +{ + char *filename = getDemoAnimInfoFilename(); + SetupFileList *setup_file_list, *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) + { + /* use reliable default values from static configuration */ + SetupFileList *insert_ptr; + + insert_ptr = setup_file_list = + newSetupFileList(demo_anim_info_config[0].token, + demo_anim_info_config[0].value); + + for (i=1; demo_anim_info_config[i].token; i++) + insert_ptr = addListEntry(insert_ptr, + demo_anim_info_config[i].token, + demo_anim_info_config[i].value); + } + + element_hash = newSetupFileHash(); + action_hash = newSetupFileHash(); + direction_hash = newSetupFileHash(); + + for (i=0; i < MAX_NUM_ELEMENTS; i++) + setHashEntry(element_hash, element_info[i].token_name, itoa(i)); + + for (i=0; i < NUM_ACTIONS; i++) + setHashEntry(action_hash, element_action_info[i].suffix, + itoa(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)); + + for (list = setup_file_list; list != NULL; list = list->next) + { + char *element_token, *action_token, *direction_token; + char *element_value, *action_value, *direction_value; + int delay = atoi(list->value); + + if (strcmp(list->token, "end") == 0) + { + add_demo_anim(-1, -1, -1, -1, &num_list_entries); + + continue; + } + + element_token = list->token; + element_value = getHashEntry(element_hash, element_token); + + if (element_value != NULL) + { + /* element found */ + add_demo_anim(atoi(element_value), -1, -1, delay, &num_list_entries); + + continue; + } + + if (strchr(element_token, '.') == NULL) + { + /* no further suffixes found -- this is not an element */ + print_unknown_token(filename, list->token, num_unknown_tokens++); + + continue; + } + + action_token = strchr(element_token, '.'); + element_token = getStringCopy(element_token); + *strchr(element_token, '.') = '\0'; + + element_value = getHashEntry(element_hash, element_token); + + if (element_value == NULL) + { + /* this is not an element */ + print_unknown_token(filename, list->token, num_unknown_tokens++); + free(element_token); + + continue; + } + + action_value = getHashEntry(action_hash, action_token); + + if (action_value != NULL) + { + /* action found */ + add_demo_anim(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) + { + /* direction found */ + add_demo_anim(atoi(element_value), -1, atoi(direction_value), delay, + &num_list_entries); + free(element_token); + + continue; + } + + 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++); + free(element_token); + + continue; + } + + 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) + { + /* this is not an action */ + print_unknown_token(filename, list->token, num_unknown_tokens++); + free(element_token); + free(action_token); + + continue; + } + + direction_value = getHashEntry(direction_hash, direction_token); + + if (direction_value != NULL) + { + /* direction found */ + add_demo_anim(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++); + + free(element_token); + free(action_token); + } + + print_unknown_token_end(num_unknown_tokens); + + add_demo_anim(-999, -999, -999, -999, &num_list_entries); + + freeSetupFileList(setup_file_list); + freeSetupFileHash(element_hash); + freeSetupFileHash(action_hash); + freeSetupFileHash(direction_hash); + +#if 0 + /* TEST ONLY */ + for (i=0; i < num_list_entries; i++) + printf("::: %d, %d, %d => %d\n", + demo_anim_info[i].element, + demo_anim_info[i].action, + demo_anim_info[i].direction, + demo_anim_info[i].delay); +#endif +} + +void LoadDemoAnimText() +{ + char *filename = getDemoAnimTextFilename(); + int i; + + if (demo_anim_text != NULL) + freeSetupFileHash(demo_anim_text); + + if ((demo_anim_text = loadSetupFileHash(filename)) == NULL) + { + /* use reliable default values from static configuration */ + demo_anim_text = newSetupFileHash(); + + for (i=0; demo_anim_text_config[i].token; i++) + setHashEntry(demo_anim_text, demo_anim_text_config[i].token, + demo_anim_text_config[i].value); + } + +#if 0 + /* TEST ONLY */ + BEGIN_HASH_ITERATION(demo_anim_text, itr) + { + printf("::: '%s' => '%s'\n", + HASH_ITERATION_TOKEN(itr), HASH_ITERATION_VALUE(itr)); + } + END_HASH_ITERATION(hash, itr) +#endif +}