X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=4c1f5683c67175dc0641771d72ddee2bdeed337e;hp=559fd3859a69b443e9a95267d269c92118780c5c;hb=5bdc30d016416d04eec826a28321325d4ddc66c2;hpb=14a9d030139b185b174f538e1ac8f027182c521c diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 559fd385..4c1f5683 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -222,6 +222,18 @@ void Print(char *format, ...) va_end(ap); } +void PrintNoLog(char *format, ...) +{ + FILE *file = program.log_file_default[LOG_OUT_ID]; + va_list ap; + + va_start(ap, format); + vfprintf(file, format, ap); + va_end(ap); + + fflush(file); +} + void PrintLine(char *line_chars, int line_length) { int i; @@ -682,6 +694,7 @@ static char *getProgramMainDataPath() #if defined(PLATFORM_MACOSX) static char *main_data_binary_subdir = NULL; + static char *main_data_files_subdir = NULL; if (main_data_binary_subdir == NULL) { @@ -693,14 +706,37 @@ static char *getProgramMainDataPath() program.program_title, MAC_APP_BINARY_SUBDIR); } - // cut relative path to Mac OS X application binary directory from path + if (main_data_files_subdir == NULL) + { + main_data_files_subdir = checked_malloc(strlen(program.program_title) + 1 + + strlen("app") + 1 + + strlen(MAC_APP_FILES_SUBDIR) + 1); + + sprintf(main_data_files_subdir, "%s.app/%s", + program.program_title, MAC_APP_FILES_SUBDIR); + } + if (strSuffix(main_data_path, main_data_binary_subdir)) + { + char *main_data_path_old = main_data_path; + + // cut relative path to Mac OS X application binary directory from path main_data_path[strlen(main_data_path) - strlen(main_data_binary_subdir)] = '\0'; - // cut trailing path separator from path (but not if path is root directory) - if (strSuffix(main_data_path, "/") && !strEqual(main_data_path, "/")) - main_data_path[strlen(main_data_path) - 1] = '\0'; + // cut trailing path separator from path (but not if path is root directory) + if (strSuffix(main_data_path, "/") && !strEqual(main_data_path, "/")) + main_data_path[strlen(main_data_path) - 1] = '\0'; + + // replace empty path with current directory + if (strEqual(main_data_path, "")) + main_data_path = "."; + + // add relative path to Mac OS X application resources directory to path + main_data_path = getPath2(main_data_path, main_data_files_subdir); + + free(main_data_path_old); + } #endif return main_data_path; @@ -2680,6 +2716,78 @@ static boolean string_has_parameter(char *s, char *s_contained) return string_has_parameter(substring, s_contained); } +static boolean string_has_anim_parameter(char *s, char *s_contained) +{ + char *s_copy = getStringCopy(s); + boolean has_parameter = FALSE; + int len_s_copy = strlen(s_copy); + int i; + + // replace all "anim" and "part" numbers with 'X' + for (i = 0; i < len_s_copy; i++) + if (s_copy[i] >= '1' && s_copy[i] <= '8') + s_copy[i] = 'X'; + + has_parameter = string_has_parameter(s_copy, s_contained); + + checked_free(s_copy); + + return has_parameter; +} + +int get_anim_parameter_value(char *s) +{ + char *pattern_1 = "click:anim_"; + char *pattern_2 = ".part_"; + char *matching_char = NULL; + char *s_ptr = s; + int result = ANIM_EVENT_NONE; + + matching_char = strstr(s_ptr, pattern_1); + if (matching_char == NULL) + return result; + + s_ptr = matching_char + strlen(pattern_1); + if (*s_ptr == '\0') + return result; + + // check for "click:anim_X" + if (*s_ptr >= '1' && *s_ptr <= '8') + { + result |= ANIM_EVENT_CLICK_ANIM_1 << (*s_ptr - '1'); + s_ptr++; + + // check for "click:anim_X.part_X" + if (strPrefix(s_ptr, pattern_2)) + { + s_ptr += strlen(pattern_2); + + if (*s_ptr >= '1' && *s_ptr <= '8') + { + result |= ANIM_EVENT_CLICK_PART_1 << (*s_ptr - '1'); + s_ptr++; + } + } + else + { + // no "part_X" specified -- trigger by click on any part + result |= ANIM_EVENT_CLICK_PART_ALL; + } + } + + /* discard result if next character is neither delimiter nor whitespace */ + if (!(*s_ptr == ',' || *s_ptr == '\0' || + *s_ptr == ' ' || *s_ptr == '\t')) + return get_anim_parameter_value(s_ptr); + + /* check if string contains another parameter string after a comma */ + s_ptr = strchr(s_ptr, ','); + if (s_ptr == NULL) /* string does not contain a comma */ + return result; + + return result | get_anim_parameter_value(s_ptr); +} + int get_parameter_value(char *value_raw, char *suffix, int type) { char *value = getStringToLower(value_raw); @@ -2746,6 +2854,18 @@ int get_parameter_value(char *value_raw, char *suffix, int type) if (string_has_parameter(value, "static_panel")) result |= ANIM_STATIC_PANEL; } + else if (strEqual(suffix, ".init_event") || + strEqual(suffix, ".anim_event")) + { + result = ANIM_EVENT_DEFAULT; + + if (string_has_parameter(value, "click")) + result |= ANIM_EVENT_CLICK_SELF; + + if (string_has_anim_parameter(value, "click:anim_X") || + string_has_anim_parameter(value, "click:anim_X.part_X")) + result |= get_anim_parameter_value(value); + } else if (strEqual(suffix, ".class")) { result = (strEqual(value, ARG_UNDEFINED) ? ARG_UNDEFINED_VALUE :