From 5fe60f460c869b600fe5c223aa7374b55450a949 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sun, 30 Nov 2003 15:31:18 +0100 Subject: [PATCH] rnd-20031130-2-src --- src/conf_dem.c | 24 +++--- src/conftime.h | 2 +- src/files.c | 229 ++++++++++++++++++++++++++++++++++++++++++++++++- src/screens.c | 52 +++++++++++ 4 files changed, 291 insertions(+), 16 deletions(-) diff --git a/src/conf_dem.c b/src/conf_dem.c index 20f76dc4..d9050854 100644 --- a/src/conf_dem.c +++ b/src/conf_dem.c @@ -362,7 +362,7 @@ struct ConfigInfo helpanim_config[] = struct ConfigInfo helptext_config[] = { { - "player_1.moving.down", + "player_1", "THE HERO: (Is _this_ guy good old Rockford?)" }, { @@ -386,7 +386,7 @@ struct ConfigInfo helptext_config[] = "Normal Wall: You can't go through it, but you can bomb it away" }, { - "expandable_wall.growing.left", + "expandable_wall", "Growing Wall: Grows in several directions if there is an empty field" }, { @@ -470,7 +470,7 @@ struct ConfigInfo helptext_config[] = "Dynamite: This one explodes after a few seconds" }, { - "dynabomb.active", + "dynabomb", "Dyna Bomb: Explodes in 4 directions with variable explosion size" }, { @@ -486,11 +486,11 @@ struct ConfigInfo helptext_config[] = "Dyna Bomb: Increases the power of explosion of dyna bombs" }, { - "spaceship.right", + "spaceship", "Spaceship: Moves at the left side of walls; don't touch it!" }, { - "bug.right", + "bug", "Bug: Moves at the right side of walls; don't touch it!" }, { @@ -502,7 +502,7 @@ struct ConfigInfo helptext_config[] = "Firefly: Moves at the left side of walls; don't touch it!" }, { - "pacman.right", + "pacman", "Pacman: Eats the amoeba and you, if you're not careful" }, { @@ -518,19 +518,19 @@ struct ConfigInfo helptext_config[] = "Robot: Tries to kill the player" }, { - "mole.moving.right", + "mole", "The mole: Eats the amoeba and turns empty space into normal sand" }, { - "penguin.moving.right", + "penguin", "The penguin: Guide him to the exit, but keep him away from monsters!" }, { - "pig.moving.right", + "pig", "The Pig: Harmless, but eats all gems it can get" }, { - "dragon.moving.right", + "dragon", "The Dragon: Breathes fire, especially to some monsters" }, { @@ -578,11 +578,11 @@ struct ConfigInfo helptext_config[] = "Biomaze: A bit like the 'Game Of Life', but builds crazy mazes" }, { - "magic_wall.active", + "magic_wall", "Magic Wall: Changes rocks, emeralds and diamonds when they pass it" }, { - "bd_magic_wall.active", + "bd_magic_wall", "Magic Wall (BD style): Changes rocks and BD style diamonds" }, { diff --git a/src/conftime.h b/src/conftime.h index 7643c40f..6d445a38 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2003-11-30 02:58]" +#define COMPILE_DATE_STRING "[2003-11-30 15:29]" diff --git a/src/files.c b/src/files.c index 011f715e..08653161 100644 --- a/src/files.c +++ b/src/files.c @@ -3066,16 +3066,232 @@ void print_unknown_token_end(int token_nr) Error(ERR_RETURN_LINE, "-"); } +#if 1 + 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; + + insert_ptr = setup_file_list = + newSetupFileList(helpanim_config[0].token, + helpanim_config[0].value); + + for (i = 1; helpanim_config[i].token; i++) + insert_ptr = addListEntry(insert_ptr, + helpanim_config[i].token, + helpanim_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_helpanim_entry(HELPANIM_LIST_NEXT, -1, -1, -1, &num_list_entries); + + continue; + } + + /* 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 (strchr(list->token, '.') == NULL) /* token contains no '.' */ + { + 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; + } + + /* token has format "." */ + + action_token = strchr(list->token, '.'); /* suffix may be action ... */ + direction_token = action_token; /* ... or direction */ + + element_token = getStringCopy(list->token); + *strchr(element_token, '.') = '\0'; + + element_value = getHashEntry(element_hash, element_token); + + if (element_value == NULL) /* this is no element */ + { + 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) /* action found */ + { + add_helpanim_entry(atoi(element_value), atoi(action_value), -1, delay, + &num_list_entries); + + free(element_token); + + continue; + } + + direction_value = getHashEntry(direction_hash, direction_token); + + if (direction_value != NULL) /* 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 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) /* this is no action */ + { + 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); + + continue; + } + + direction_value = getHashEntry(direction_hash, direction_token); + + if (direction_value != NULL) /* 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; + } + + /* 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); + + 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", + helpanim_info[i].element, + helpanim_info[i].action, + helpanim_info[i].direction, + helpanim_info[i].delay); +#endif +} + +#else + +void LoadHelpAnimInfo() +{ + char *filename = getHelpAnimFilename(); + 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 (fileExists(filename)) + setup_file_list = loadSetupFileList(filename); + + if (setup_file_list == NULL) { /* use reliable default values from static configuration */ SetupFileList *insert_ptr; @@ -3241,6 +3457,7 @@ void LoadHelpAnimInfo() helpanim_info[i].delay); #endif } +#endif void LoadHelpTextInfo() { @@ -3248,9 +3465,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(); diff --git a/src/screens.c b/src/screens.c index efa7e2e2..23bfc0c4 100644 --- a/src/screens.c +++ b/src/screens.c @@ -811,6 +811,57 @@ void DrawInfoScreen_HelpAnim(int start, int max_anims, boolean init) FrameCounter++; } +#if 1 + +static char *getHelpText(int element, int action, int direction) +{ + char token[MAX_LINE_LEN]; + + strcpy(token, element_info[element].token_name); + + if (action != -1) + strcat(token, element_action_info[action].suffix); + + if (direction != -1) + strcat(token, element_direction_info[MV_DIR_BIT(direction)].suffix); + + return getHashEntry(helptext_info, token); +} + +void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos) +{ + int font_nr = FONT_TEXT_2; + int max_chars_per_line = 34; + int max_lines_per_text = 2; + int sx = mSX + 56; + int sy = mSY + 65 + 2 * 32 + 1; + int ystep = TILEY + 4; + char *text = NULL; + + if (action != -1 && direction != -1) /* element.action.direction */ + text = getHelpText(element, action, direction); + + if (text == NULL && action != -1) /* element.action */ + text = getHelpText(element, action, -1); + + if (text == NULL && direction != -1) /* element.direction */ + text = getHelpText(element, -1, direction); + + if (text == NULL) /* base element */ + text = getHelpText(element, -1, -1); + + if (text == NULL) /* not found */ + text = "No description available"; + + if (strlen(text) <= max_chars_per_line) /* only one line of text */ + sy += getFontHeight(font_nr) / 2; + + DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr, + max_chars_per_line, max_lines_per_text); +} + +#else + void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos) { int font_nr = FONT_TEXT_2; @@ -849,6 +900,7 @@ void DrawInfoScreen_HelpText(int element, int action, int direction, int ypos) DrawTextWrapped(sx, sy + ypos * ystep, text, font_nr, max_chars_per_line, max_lines_per_text); } +#endif void DrawInfoScreen_Elements() { -- 2.34.1