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))
{
}
/* 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))
{
{
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);
}
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();
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;
#endif
}
-static struct MusicFileInfo *get_music_file_info(char *basename)
+static struct MusicFileInfo *get_music_file_info(char *basename, int music)
{
SetupFileHash *setup_file_hash = NULL;
struct MusicFileInfo tmp_music_file_info, *new_music_file_info;
/* ---------- music file info found ---------- */
+ memset(&tmp_music_file_info, 0, sizeof(struct MusicFileInfo));
+
for (i = 0; token_to_value_ptr[i].token != NULL; i++)
{
char *value = getHashEntry(setup_file_hash, token_to_value_ptr[i].token);
- *token_to_value_ptr[i].value_ptr = getStringCopy(value); /* may be NULL */
+ *token_to_value_ptr[i].value_ptr =
+ getStringCopy(value != NULL ? value : UNKNOWN_NAME);
}
- new_music_file_info = checked_calloc(sizeof(struct MusicFileInfo));
+ tmp_music_file_info.music = music;
+
+ new_music_file_info = checked_malloc(sizeof(struct MusicFileInfo));
*new_music_file_info = tmp_music_file_info;
return new_music_file_info;
{
char *music_directory = getCustomMusicDirectory();
int num_music = getMusicListSize();
+ int num_music_noconf = 0;
DIR *dir;
struct dirent *dir_entry;
struct FileInfo *music;
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;
+ /* a configured file may be not recognized as music */
+ if (!FileIsMusic(music->filename))
+ continue;
+
#if 0
- printf("::: -> '%s'\n", music->filename);
+ printf("::: -> '%s' (configured)\n", music->filename);
#endif
- *new = get_music_file_info(music->filename);
+ *new = get_music_file_info(music->filename, i);
if (*new != NULL)
new = &(*new)->next;
}
{
music = getMusicListEntry(i);
+ if (music->filename == NULL)
+ continue;
+
if (strcmp(basename, music->filename) == 0)
{
music_already_used = TRUE;
if (music_already_used)
continue;
- if (!FileIsSound(basename) && !FileIsMusic(basename))
+ if (!FileIsMusic(basename))
continue;
#if 0
- printf("::: -> '%s'\n", basename);
+ printf("::: -> '%s' (found in directory)\n", basename);
#endif
- *new = get_music_file_info(basename);
+ *new = get_music_file_info(basename, MAP_NOCONF_MUSIC(num_music_noconf));
if (*new != NULL)
new = &(*new)->next;
+
+ num_music_noconf++;
}
closedir(dir);
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;
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)
{
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 "<prefix>.<something>" */
- 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;
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;
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 "<prefix>.<suffix>.<something>" */
+
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);
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);
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);
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();