From: Holger Schemel Date: Thu, 29 Oct 1998 22:13:34 +0000 (+0100) Subject: rnd-19981029-2 X-Git-Tag: 1.2.0^2~40 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=4b22e01f196292da25d7201cb08ca52af6a38901;p=rocksndiamonds.git rnd-19981029-2 --- diff --git a/src/files.c b/src/files.c index 21ed3ca1..0de480e0 100644 --- a/src/files.c +++ b/src/files.c @@ -467,105 +467,13 @@ void SaveScore(int level_nr) fclose(file); } - - -#if 0 - -void LoadJoystickData() -{ - int i; - char cookie[256]; - FILE *file; - - if (joystick_status==JOYSTICK_OFF) - return; - -#ifndef MSDOS - if (!(file=fopen(JOYDAT_FILE,"r"))) - return; - - fscanf(file,"%s",cookie); - if (strcmp(cookie,JOYSTICK_COOKIE)) /* ungültiges Format? */ - { - Error(ERR_WARN, "wrong format of joystick file '%s'", JOYDAT_FILE); - fclose(file); - return; - } - - for(i=0;i<2;i++) - { - fscanf(file,"%s",cookie); - fscanf(file, "%d %d %d \n", - &joystick[i].xleft, &joystick[i].xmiddle, &joystick[i].xright); - fscanf(file, "%d %d %d \n", - &joystick[i].yupper, &joystick[i].ymiddle, &joystick[i].ylower); - } - fclose(file); - - CheckJoystickData(); -#else - load_joystick_data(JOYDAT_FILE); -#endif -} - -void SaveJoystickData() -{ - int i; - FILE *file; - - if (joystick_status==JOYSTICK_OFF) - return; - -#ifndef MSDOS - CheckJoystickData(); - - if (!(file=fopen(JOYDAT_FILE,"w"))) - { - Error(ERR_WARN, "cannot save joystick calibration data to file '%s'", - JOYDAT_FILE); - return; - } - - fprintf(file,"%s\n",JOYSTICK_COOKIE); /* Formatkennung */ - for(i=0;i<2;i++) - { - fprintf(file,"JOYSTICK_%d_DATA\n",i); - fprintf(file, "%d %d %d \n", - joystick[i].xleft, joystick[i].xmiddle, joystick[i].xright); - fprintf(file, "%d %d %d \n", - joystick[i].yupper, joystick[i].ymiddle, joystick[i].ylower); - } - fclose(file); - - chmod(JOYDAT_FILE, JOYDAT_PERMS); -#else - save_joystick_data(JOYDAT_FILE); -#endif - -} - -#endif - - - -/* ------------------------------------------------------------------------- */ -/* new setup functions */ -/* ------------------------------------------------------------------------- */ - #define MAX_LINE_LEN 1000 -#define MAX_SETUP_TOKEN_LEN 100 -#define MAX_SETUP_VALUE_LEN 100 #define TOKEN_STR_FILE_IDENTIFIER "file_identifier" #define TOKEN_STR_LAST_LEVEL_SERIES "last_level_series" -#define TOKEN_STR_ALIAS_NAME "alias_name" - #define TOKEN_STR_PLAYER_PREFIX "player_" -#define TOKEN_VALUE_POSITION 30 -#define TOKEN_INVALID -1 -#define TOKEN_IGNORE -99 -#define SETUP_TOKEN_ALIAS_NAME 100 +#define TOKEN_VALUE_POSITION 30 #define SETUP_TOKEN_SOUND 0 #define SETUP_TOKEN_SOUND_LOOPS 1 @@ -578,7 +486,7 @@ void SaveJoystickData() #define SETUP_TOKEN_FADING 8 #define SETUP_TOKEN_AUTORECORD 9 #define SETUP_TOKEN_QUICK_DOORS 10 -#define SETUP_TOKEN_ALIAS_NAMES 11 +#define SETUP_TOKEN_ALIAS_NAME 11 #define SETUP_TOKEN_USE_JOYSTICK 12 #define SETUP_TOKEN_JOY_DEVICE_NAME 13 @@ -600,7 +508,7 @@ void SaveJoystickData() #define NUM_SETUP_TOKENS 28 #define FIRST_GLOBAL_SETUP_TOKEN SETUP_TOKEN_SOUND -#define LAST_GLOBAL_SETUP_TOKEN SETUP_TOKEN_ALIAS_NAMES +#define LAST_GLOBAL_SETUP_TOKEN SETUP_TOKEN_ALIAS_NAME #define FIRST_PLAYER_SETUP_TOKEN SETUP_TOKEN_USE_JOYSTICK #define LAST_PLAYER_SETUP_TOKEN SETUP_TOKEN_KEY_BOMB @@ -708,32 +616,6 @@ static boolean get_string_boolean_value(char *s) return FALSE; } - - -#if 0 - -static char *getSetupToken(int token_nr) -{ - return token_info[token_nr].text; -} - -static char *getSetupValue(int token_nr, boolean token_value) -{ - return (token_value == TRUE ? "true" : "false"); - - /* - if (token_value == TRUE) - return token_info[token_nr].value_true; - else - return token_info[token_nr].value_false; - */ - -} - -#endif - - - static char *getFormattedSetupEntry(char *token, char *value) { int i; @@ -749,55 +631,6 @@ static char *getFormattedSetupEntry(char *token, char *value) return entry; } - - -#if 0 - -static char *getSetupEntry(char *prefix, int token_nr, int token_value) -{ - int i; - static char entry[MAX_LINE_LEN]; - - sprintf(entry, "%s%s:", prefix, getSetupToken(token_nr)); - for (i=strlen(entry); itoken, token) == 0) return setup_file_list->value; else - return getSetupFileListEntry(setup_file_list->next, token); + return getTokenValue(setup_file_list->next, token); } -boolean setSetupFileListEntry(struct SetupFileList *setup_file_list, - char *token, char *value) +static void setTokenValue(struct SetupFileList *setup_file_list, + char *token, char *value) { if (!setup_file_list) - return FALSE; + return; if (strcmp(setup_file_list->token, token) == 0) { free(setup_file_list->value); setup_file_list->value = checked_malloc(strlen(value) + 1); strcpy(setup_file_list->value, value); - - return TRUE; } + else if (setup_file_list->next == NULL) + setup_file_list->next = newSetupFileList(token, value); else - return setSetupFileListEntry(setup_file_list->next, token, value); -} - -void updateSetupFileListEntry(struct SetupFileList *setup_file_list, - char *token, char *value) -{ - if (!setup_file_list) - return; - - if (getSetupFileListEntry(setup_file_list, token) != NULL) - setSetupFileListEntry(setup_file_list, token, value); - else - { - struct SetupFileList *list_entry = setup_file_list; - - while (list_entry->next) - list_entry = list_entry->next; - - list_entry->next = newSetupFileList(token, value); - } + setTokenValue(setup_file_list->next, token, value); } #ifdef DEBUG @@ -958,7 +772,7 @@ static struct SetupFileList *loadSetupFileList(char *filename) break; if (*token && *value) - updateSetupFileListEntry(setup_file_list, token, value); + setTokenValue(setup_file_list, token, value); } fclose(file); @@ -1001,155 +815,112 @@ static void checkSetupFileListIdentifier(struct SetupFileList *setup_file_list, } } -static void decodeSetupFileList(struct SetupFileList *setup_file_list) +static void setSetupInfoToDefaults(struct SetupInfo *si) { int i; - int token_nr = TOKEN_INVALID; - int player_nr = 0; - char *token; - char *token_value; - boolean token_boolean_value; - int token_integer_value; - int token_player_prefix_len; - - if (!setup_file_list) - return; - - token = setup_file_list->token; - token_value = setup_file_list->value; - token_boolean_value = get_string_boolean_value(token_value); - token_integer_value = get_string_integer_value(token_value); - token_player_prefix_len = strlen(TOKEN_STR_PLAYER_PREFIX); + si->sound = TRUE; + si->sound_loops = FALSE; + si->sound_music = FALSE; + si->sound_simple = FALSE; + si->toons = TRUE; + si->double_buffering = TRUE; + si->direct_draw = !si->double_buffering; + si->scroll_delay = FALSE; + si->soft_scrolling = TRUE; + si->fading = FALSE; + si->autorecord = FALSE; + si->quick_doors = FALSE; + + strncpy(si->login_name, GetLoginName(), MAX_NAMELEN-1); + si->login_name[MAX_NAMELEN-1] = '\0'; + strncpy(si->alias_name, GetLoginName(), MAX_NAMELEN-1); + si->alias_name[MAX_NAMELEN-1] = '\0'; - if (strncmp(token, TOKEN_STR_PLAYER_PREFIX, - token_player_prefix_len) == 0) + for (i=0; i= '0' && *token <= '9') - { - player_nr = ((int)(*token - '0') - 1 + MAX_PLAYERS) % MAX_PLAYERS; - token++; - } + si->input[i].use_joystick = FALSE; + strcpy(si->input[i].joy.device_name, joystick_device_name[i]); + si->input[i].joy.xleft = JOYSTICK_XLEFT; + si->input[i].joy.xmiddle = JOYSTICK_XMIDDLE; + si->input[i].joy.xright = JOYSTICK_XRIGHT; + si->input[i].joy.yupper = JOYSTICK_YUPPER; + si->input[i].joy.ymiddle = JOYSTICK_YMIDDLE; + si->input[i].joy.ylower = JOYSTICK_YLOWER; + si->input[i].joy.snap = (i == 0 ? JOY_BUTTON_1 : 0); + si->input[i].joy.bomb = (i == 0 ? JOY_BUTTON_2 : 0); + si->input[i].key.left = (i == 0 ? DEFAULT_KEY_LEFT : KEY_UNDEFINDED); + si->input[i].key.right = (i == 0 ? DEFAULT_KEY_RIGHT : KEY_UNDEFINDED); + si->input[i].key.up = (i == 0 ? DEFAULT_KEY_UP : KEY_UNDEFINDED); + si->input[i].key.down = (i == 0 ? DEFAULT_KEY_DOWN : KEY_UNDEFINDED); + si->input[i].key.snap = (i == 0 ? DEFAULT_KEY_SNAP : KEY_UNDEFINDED); + si->input[i].key.bomb = (i == 0 ? DEFAULT_KEY_BOMB : KEY_UNDEFINDED); } +} - for (i=0; inext); +static void decodeSetupFileList(struct SetupFileList *setup_file_list) +{ + int i, pnr; + + if (!setup_file_list) + return; + + /* handle global setup values */ + si = setup; + for (i=FIRST_GLOBAL_SETUP_TOKEN; i<=LAST_GLOBAL_SETUP_TOKEN; i++) + setSetupInfo(i, getTokenValue(setup_file_list, token_info[i].text)); + setup = si; + + /* handle player specific setup values */ + for (pnr=0; pnr