X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=a19bcace92430800df871f8918dafb0a9974fdb0;hb=39af00f43cf5c4cea174d0e90633877df08a2f7c;hp=70b2a5d6b802ccbcbe16894a44e5778ced15cfaf;hpb=30d4bba6b5c11c262a79d442b67defe7eba9bfde;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 70b2a5d6..a19bcace 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -984,28 +984,26 @@ void putFileChunk(FILE *file, char *chunk_name, int chunk_size, int getFileVersion(FILE *file) { - int version_major, version_minor, version_patch, version_release; + int version_major = fgetc(file); + int version_minor = fgetc(file); + int version_patch = fgetc(file); + int version_build = fgetc(file); - version_major = fgetc(file); - version_minor = fgetc(file); - version_patch = fgetc(file); - version_release = fgetc(file); - - return RELEASE_IDENT(version_major, version_minor, version_patch, - version_release); + return VERSION_IDENT(version_major, version_minor, version_patch, + version_build); } void putFileVersion(FILE *file, int version) { - int version_major = VERSION_MAJOR(version); - int version_minor = VERSION_MINOR(version); - int version_patch = VERSION_PATCH(version); - int version_release = VERSION_RELEASE(version); + int version_major = VERSION_MAJOR(version); + int version_minor = VERSION_MINOR(version); + int version_patch = VERSION_PATCH(version); + int version_build = VERSION_BUILD(version); - fputc(version_major, file); - fputc(version_minor, file); - fputc(version_patch, file); - fputc(version_release, file); + fputc(version_major, file); + fputc(version_minor, file); + fputc(version_patch, file); + fputc(version_build, file); } void ReadUnusedBytesFromFile(FILE *file, unsigned long bytes) @@ -1376,32 +1374,41 @@ int get_integer_from_string(char *s) { static char *number_text[][3] = { - { "0", "zero", "null", }, - { "1", "one", "first" }, - { "2", "two", "second" }, - { "3", "three", "third" }, - { "4", "four", "fourth" }, - { "5", "five", "fifth" }, - { "6", "six", "sixth" }, - { "7", "seven", "seventh" }, - { "8", "eight", "eighth" }, - { "9", "nine", "ninth" }, - { "10", "ten", "tenth" }, - { "11", "eleven", "eleventh" }, - { "12", "twelve", "twelfth" }, + { "0", "zero", "null", }, + { "1", "one", "first" }, + { "2", "two", "second" }, + { "3", "three", "third" }, + { "4", "four", "fourth" }, + { "5", "five", "fifth" }, + { "6", "six", "sixth" }, + { "7", "seven", "seventh" }, + { "8", "eight", "eighth" }, + { "9", "nine", "ninth" }, + { "10", "ten", "tenth" }, + { "11", "eleven", "eleventh" }, + { "12", "twelve", "twelfth" }, + + { NULL, NULL, NULL }, }; int i, j; char *s_lower = getStringToLower(s); int result = -1; - for (i=0; i<13; i++) - for (j=0; j<3; j++) + for (i=0; number_text[i][0] != NULL; i++) + for (j=0; j < 3; j++) if (strcmp(s_lower, number_text[i][j]) == 0) result = i; if (result == -1) - result = atoi(s); + { + if (strcmp(s_lower, "false") == 0) + result = 0; + else if (strcmp(s_lower, "true") == 0) + result = 1; + else + result = atoi(s); + } free(s_lower); @@ -1518,37 +1525,77 @@ boolean fileExists(char *filename) return (access(filename, F_OK) == 0); } -boolean FileIsGraphic(char *filename) +boolean fileHasPrefix(char *basename, char *prefix) { - if (strlen(filename) > 4 && - strcmp(&filename[strlen(filename) - 4], ".pcx") == 0) + static char *basename_lower = NULL; + int basename_length, prefix_length; + + if (basename_lower != NULL) + free(basename_lower); + + if (basename == NULL || prefix == NULL) + return FALSE; + + basename_lower = getStringToLower(basename); + basename_length = strlen(basename_lower); + prefix_length = strlen(prefix); + + if (basename_length > prefix_length + 1 && + basename_lower[prefix_length] == '.' && + strncmp(basename_lower, prefix, prefix_length) == 0) return TRUE; return FALSE; } -boolean FileIsSound(char *basename) +boolean fileHasSuffix(char *basename, char *suffix) { - if (strlen(basename) > 4 && - strcmp(&basename[strlen(basename) - 4], ".wav") == 0) + static char *basename_lower = NULL; + int basename_length, suffix_length; + + if (basename_lower != NULL) + free(basename_lower); + + if (basename == NULL || suffix == NULL) + return FALSE; + + basename_lower = getStringToLower(basename); + basename_length = strlen(basename_lower); + suffix_length = strlen(suffix); + + if (basename_length > suffix_length + 1 && + basename_lower[basename_length - suffix_length - 1] == '.' && + strcmp(&basename_lower[basename_length - suffix_length], suffix) == 0) return TRUE; return FALSE; } -boolean FileIsMusic(char *basename) +boolean FileIsGraphic(char *basename) { - /* "music" can be a WAV (loop) file or (if compiled with SDL) a MOD file */ + return fileHasSuffix(basename, "pcx"); +} + +boolean FileIsSound(char *basename) +{ + return fileHasSuffix(basename, "wav"); +} +boolean FileIsMusic(char *basename) +{ if (FileIsSound(basename)) return TRUE; #if defined(TARGET_SDL) - if (strlen(basename) > 4 && - (strcmp(&basename[strlen(basename) - 4], ".mod") == 0 || - strcmp(&basename[strlen(basename) - 4], ".MOD") == 0 || - strncmp(basename, "mod.", 4) == 0 || - strncmp(basename, "MOD.", 4) == 0)) + if (fileHasPrefix(basename, "mod") || + fileHasSuffix(basename, "mod") || + fileHasSuffix(basename, "s3m") || + fileHasSuffix(basename, "it") || + fileHasSuffix(basename, "xm") || + fileHasSuffix(basename, "midi") || + fileHasSuffix(basename, "mid") || + fileHasSuffix(basename, "mp3") || + fileHasSuffix(basename, "ogg")) return TRUE; #endif @@ -1606,27 +1653,29 @@ static boolean string_has_parameter(char *s, char *s_contained) return string_has_parameter(substring, s_contained); } -int get_parameter_value(char *token, char *value_raw, int type) +int get_parameter_value(char *suffix, char *value_raw, int type) { char *value = getStringToLower(value_raw); int result = 0; /* probably a save default value */ - if (strcmp(token, ".direction") == 0) + if (strcmp(suffix, ".direction") == 0) { result = (strcmp(value, "left") == 0 ? MV_LEFT : strcmp(value, "right") == 0 ? MV_RIGHT : strcmp(value, "up") == 0 ? MV_UP : strcmp(value, "down") == 0 ? MV_DOWN : MV_NO_MOVING); } - else if (strcmp(token, ".anim_mode") == 0) - { - result = (string_has_parameter(value, "loop") ? ANIM_LOOP : - string_has_parameter(value, "linear") ? ANIM_LINEAR : - string_has_parameter(value, "pingpong") ? ANIM_PINGPONG : - string_has_parameter(value, "pingpong2") ? ANIM_PINGPONG2 : - string_has_parameter(value, "random") ? ANIM_RANDOM : - string_has_parameter(value, "none") ? ANIM_NONE : - ANIM_LOOP); + else if (strcmp(suffix, ".anim_mode") == 0) + { + result = (string_has_parameter(value, "none") ? ANIM_NONE : + string_has_parameter(value, "loop") ? ANIM_LOOP : + string_has_parameter(value, "linear") ? ANIM_LINEAR : + string_has_parameter(value, "pingpong") ? ANIM_PINGPONG : + string_has_parameter(value, "pingpong2") ? ANIM_PINGPONG2 : + string_has_parameter(value, "random") ? ANIM_RANDOM : + string_has_parameter(value, "horizontal") ? ANIM_HORIZONTAL : + string_has_parameter(value, "vertical") ? ANIM_VERTICAL : + ANIM_DEFAULT); if (string_has_parameter(value, "reverse")) result |= ANIM_REVERSE; @@ -1644,6 +1693,20 @@ int get_parameter_value(char *token, char *value_raw, int type) return result; } +int get_auto_parameter_value(char *token, char *value_raw) +{ + char *suffix; + + if (token == NULL || value_raw == NULL) + return ARG_UNDEFINED_VALUE; + + suffix = strrchr(token, '.'); + if (suffix == NULL) + suffix = token; + + return get_parameter_value(suffix, value_raw, TYPE_INTEGER); +} + static void FreeCustomArtworkList(struct ArtworkListInfo *, struct ListNodeInfo ***, int *); @@ -2228,6 +2291,9 @@ void LoadArtworkConfig(struct ArtworkListInfo *artwork_info) printf("GOT CUSTOM ARTWORK CONFIG FILE '%s'\n", filename); #endif + DrawInitText("Loading artwork config:", 120, FC_GREEN); + DrawInitText(ARTWORKINFO_FILENAME(artwork_info->type), 150, FC_YELLOW); + /* always start with reliable default values */ for (i=0; i