From c4b26cf489dcc65a00bfcc05f7898700d2f0c9e4 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Mon, 26 Oct 1998 00:28:11 +0100 Subject: [PATCH] rnd-19981026-1 --- src/files.c | 632 ++++++++++++++++++++++++++++++++++--------------- src/files.h | 23 ++ src/game.c | 28 ++- src/init.c | 30 ++- src/joystick.c | 2 +- src/main.c | 2 + src/main.h | 16 +- src/misc.c | 30 ++- src/misc.h | 9 +- src/network.c | 14 +- src/screens.c | 160 ++++++++++--- src/sound.c | 16 +- 12 files changed, 693 insertions(+), 269 deletions(-) diff --git a/src/files.c b/src/files.c index a77b4463..17bc45e5 100644 --- a/src/files.c +++ b/src/files.c @@ -53,6 +53,10 @@ boolean CreateNewScoreFile() return(TRUE); } + + +#if 0 + boolean CreateNewNamesFile(int mode) { char filename[MAX_FILENAME_LEN]; @@ -74,6 +78,9 @@ boolean CreateNewNamesFile(int mode) return(TRUE); } +#endif + + boolean LoadLevelInfo() { int i; @@ -85,14 +92,14 @@ boolean LoadLevelInfo() if (!(file=fopen(filename,"r"))) { - Error(ERR_RETURN, "cannot read level info '%s'", filename); + Error(ERR_WARN, "cannot read level info '%s'", filename); return(FALSE); } fscanf(file,"%s\n",cookie); if (strcmp(cookie,LEVELDIR_COOKIE)) /* ungültiges Format? */ { - Error(ERR_RETURN, "wrong format of level info file"); + Error(ERR_WARN, "wrong format of level info file"); fclose(file); return(FALSE); } @@ -113,7 +120,7 @@ boolean LoadLevelInfo() if (!num_leveldirs) { - Error(ERR_RETURN, "empty level info '%s'", filename); + Error(ERR_WARN, "empty level info '%s'", filename); return(FALSE); } @@ -131,7 +138,7 @@ void LoadLevel(int level_nr) level_directory,leveldir[leveldir_nr].filename,level_nr); if (!(file = fopen(filename,"r"))) - Error(ERR_RETURN, "cannot read level '%s' - creating new level", filename); + Error(ERR_WARN, "cannot read level '%s' - creating new level", filename); else { fgets(cookie,LEVEL_COOKIE_LEN,file); @@ -139,7 +146,7 @@ void LoadLevel(int level_nr) if (strcmp(cookie,LEVEL_COOKIE)) /* ungültiges Format? */ { - Error(ERR_RETURN, "wrong format of level file '%s'", filename); + Error(ERR_WARN, "wrong format of level file '%s'", filename); fclose(file); file = NULL; } @@ -234,7 +241,7 @@ void LoadLevelTape(int level_nr) levelrec_10 = TRUE; else if (strcmp(cookie,LEVELREC_COOKIE)) /* unknown tape format */ { - Error(ERR_RETURN, "wrong format of level recording file '%s'", filename); + Error(ERR_WARN, "wrong format of level recording file '%s'", filename); fclose(file); file = NULL; } @@ -284,7 +291,7 @@ void LoadLevelTape(int level_nr) fclose(file); if (i != tape.length) - Error(ERR_RETURN, "level recording file '%s' corrupted", filename); + Error(ERR_WARN, "level recording file '%s' corrupted", filename); tape.length_seconds = GetTapeLength(); } @@ -302,9 +309,9 @@ void LoadScore(int level_nr) if (!(file = fopen(filename,"r"))) { if (!CreateNewScoreFile()) - Error(ERR_RETURN, "cannot create score file '%s'", filename); + Error(ERR_WARN, "cannot create score file '%s'", filename); else if (!(file = fopen(filename,"r"))) - Error(ERR_RETURN, "cannot read score for level %d", level_nr); + Error(ERR_WARN, "cannot read score for level %d", level_nr); } if (file) @@ -312,7 +319,7 @@ void LoadScore(int level_nr) fgets(cookie,SCORE_COOKIE_LEN,file); if (strcmp(cookie,SCORE_COOKIE)) /* ungültiges Format? */ { - Error(ERR_RETURN, "wrong format of score file '%s'", filename); + Error(ERR_WARN, "wrong format of score file '%s'", filename); fclose(file); file = NULL; } @@ -341,6 +348,10 @@ void LoadScore(int level_nr) } } + + +#if 0 + void LoadPlayerInfo(int mode) { int i; @@ -351,6 +362,15 @@ void LoadPlayerInfo(int mode) struct PlayerInfo default_player, new_player; int version_10_file = FALSE; + + + if (mode == PLAYER_SETUP) + LoadSetup(); + else if (mode == PLAYER_LEVEL) + LoadLevelSetup(); + + + if (mode==PLAYER_LEVEL) sprintf(filename,"%s/%s/%s", level_directory,leveldir[leveldir_nr].filename,NAMES_FILENAME); @@ -371,9 +391,9 @@ void LoadPlayerInfo(int mode) if (!(file = fopen(filename,"r"))) { if (!CreateNewNamesFile(mode)) - Error(ERR_RETURN, "cannot create names file '%s'", filename); + Error(ERR_WARN, "cannot create names file '%s'", filename); else if (!(file = fopen(filename,"r"))) - Error(ERR_RETURN, "cannot read player information file '%s'", filename); + Error(ERR_WARN, "cannot read player information file '%s'", filename); } if (file) @@ -383,7 +403,7 @@ void LoadPlayerInfo(int mode) version_10_file = TRUE; else if (strcmp(cookie,NAMES_COOKIE)) /* ungültiges Format? */ { - Error(ERR_RETURN, "wrong format of names file '%s'", filename); + Error(ERR_WARN, "wrong format of names file '%s'", filename); fclose(file); file = NULL; } @@ -420,7 +440,7 @@ void LoadPlayerInfo(int mode) fclose(file); if (!(file = fopen(filename,"a"))) - Error(ERR_RETURN, "cannot append new player to names file '%s'", + Error(ERR_WARN, "cannot append new player to names file '%s'", filename); else { @@ -466,6 +486,10 @@ void LoadPlayerInfo(int mode) fclose(file); } +#endif + + + void SaveLevel(int level_nr) { int i,x,y; @@ -477,7 +501,7 @@ void SaveLevel(int level_nr) if (!(file=fopen(filename,"w"))) { - Error(ERR_RETURN, "cannot save level file '%s'", filename); + Error(ERR_WARN, "cannot save level file '%s'", filename); return; } @@ -543,7 +567,7 @@ void SaveLevelTape(int level_nr) if (!(file=fopen(filename,"w"))) { - Error(ERR_RETURN, "cannot save level recording file '%s'", filename); + Error(ERR_WARN, "cannot save level recording file '%s'", filename); return; } @@ -596,7 +620,7 @@ void SaveScore(int level_nr) if (!(file=fopen(filename,"r+"))) { - Error(ERR_RETURN, "cannot save score for level %d", level_nr); + Error(ERR_WARN, "cannot save score for level %d", level_nr); return; } @@ -613,6 +637,10 @@ void SaveScore(int level_nr) fclose(file); } + + +#if 0 + void SavePlayerInfo(int mode) { int i; @@ -626,6 +654,8 @@ void SavePlayerInfo(int mode) if (mode == PLAYER_SETUP) SaveSetup(); + else if (mode == PLAYER_LEVEL) + SaveLevelSetup(); @@ -637,7 +667,7 @@ void SavePlayerInfo(int mode) if (!(file = fopen(filename,"r+"))) { - Error(ERR_RETURN, "cannot save player information to file '%s'", filename); + Error(ERR_WARN, "cannot save player information to file '%s'", filename); return; } @@ -646,7 +676,7 @@ void SavePlayerInfo(int mode) version_10_file = TRUE; else if (strcmp(cookie,NAMES_COOKIE)) /* ungültiges Format? */ { - Error(ERR_RETURN, "wrong format of names file '%s'", filename); + Error(ERR_WARN, "wrong format of names file '%s'", filename); fclose(file); return; } @@ -700,6 +730,10 @@ void SavePlayerInfo(int mode) fclose(file); } +#endif + + + void LoadJoystickData() { int i; @@ -716,7 +750,7 @@ void LoadJoystickData() fscanf(file,"%s",cookie); if (strcmp(cookie,JOYSTICK_COOKIE)) /* ungültiges Format? */ { - Error(ERR_RETURN, "wrong format of joystick file '%s'", JOYDAT_FILE); + Error(ERR_WARN, "wrong format of joystick file '%s'", JOYDAT_FILE); fclose(file); return; } @@ -750,7 +784,7 @@ void SaveJoystickData() if (!(file=fopen(JOYDAT_FILE,"w"))) { - Error(ERR_RETURN, "cannot save joystick calibration data to file '%s'", + Error(ERR_WARN, "cannot save joystick calibration data to file '%s'", JOYDAT_FILE); return; } @@ -777,6 +811,17 @@ void SaveJoystickData() /* new setup functions */ /* ------------------------------------------------------------------------- */ +#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 SETUP_TOKEN_SOUND 0 #define SETUP_TOKEN_SOUND_LOOPS 1 #define SETUP_TOKEN_SOUND_MUSIC 2 @@ -801,8 +846,6 @@ void SaveJoystickData() #define NUM_SETUP_TOKENS 21 -#define SETUP_TOKEN_PLAYER_PREFIX "player_" - static struct { char *token, *value_true, *value_false; @@ -902,13 +945,28 @@ static char *getSetupValue(int token_nr, boolean token_value) return setup_info[token_nr].value_false; } +static char *getFormattedSetupEntry(char *token, char *value) +{ + int i; + static char entry[MAX_LINE_LEN]; + + sprintf(entry, "%s:", token); + for (i=strlen(entry); itoken) - free(setup_file_info->token); - if (setup_file_info->value) - free(setup_file_info->value); - if (setup_file_info->next) - freeSetupFileInfo(setup_file_info->next); - free(setup_file_info); + if (setup_file_list->token) + free(setup_file_list->token); + if (setup_file_list->value) + free(setup_file_list->value); + if (setup_file_list->next) + freeSetupFileList(setup_file_list->next); + free(setup_file_list); } -static struct SetupFileInfo *newSetupFileInfo(char *token, char *value) +static struct SetupFileList *newSetupFileList(char *token, char *value) { - struct SetupFileInfo *new = checked_malloc(sizeof(struct SetupFileInfo)); + struct SetupFileList *new = checked_malloc(sizeof(struct SetupFileList)); new->token = checked_malloc(strlen(token) + 1); strcpy(new->token, token); @@ -973,35 +1031,204 @@ static struct SetupFileInfo *newSetupFileInfo(char *token, char *value) return new; } -static char *lookupSetupFileValue(struct SetupFileInfo *setup_file_info, - char *token) +static char *getSetupFileListEntry(struct SetupFileList *setup_file_list, + char *token) { - if (!setup_file_info) + if (!setup_file_list) return NULL; - if (strcmp(setup_file_info->token, token) == 0) - return setup_file_info->value; + if (strcmp(setup_file_list->token, token) == 0) + return setup_file_list->value; + else + return getSetupFileListEntry(setup_file_list->next, token); +} + +boolean setSetupFileListEntry(struct SetupFileList *setup_file_list, + char *token, char *value) +{ + if (!setup_file_list) + return FALSE; + + 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 - return lookupSetupFileValue(setup_file_info->next, token); + 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); + } } #ifdef DEBUG -static void printSetupFileInfo(struct SetupFileInfo *setup_file_info) +static void printSetupFileList(struct SetupFileList *setup_file_list) { - if (!setup_file_info) + if (!setup_file_list) return; - printf("token: '%s'\n", setup_file_info->token); - printf("value: '%s'\n", setup_file_info->value); + printf("token: '%s'\n", setup_file_list->token); + printf("value: '%s'\n", setup_file_list->value); - printSetupFileInfo(setup_file_info->next); + printSetupFileList(setup_file_list->next); } #endif -static void decodeSetupFileInfo(struct SetupFileInfo *setup_file_info) +static struct SetupFileList *loadSetupFileList(char *filename) +{ + int line_len; + char line[MAX_LINE_LEN]; + char *token, *value, *line_ptr; + struct SetupFileList *setup_file_list = newSetupFileList("", ""); + struct SetupFileList *first_valid_list_entry; + + + + /* + struct SetupFileList **next_entry = &setup_file_list; + */ + + + FILE *file; + + if (!(file = fopen(filename, "r"))) + { + Error(ERR_WARN, "cannot open setup file '%s'", filename); + return NULL; + } + + while(!feof(file)) + { + /* read next line of input file */ + if (!fgets(line, MAX_LINE_LEN, file)) + break; + + /* cut trailing comment or whitespace from input line */ + for (line_ptr = line; *line_ptr; line_ptr++) + { + if (*line_ptr == '#' || *line_ptr == '\n') + { + *line_ptr = '\0'; + break; + } + } + + /* cut trailing whitespaces from input line */ + for (line_ptr = &line[strlen(line)]; line_ptr > line; line_ptr--) + if ((*line_ptr == ' ' || *line_ptr == '\t') && line_ptr[1] == '\0') + *line_ptr = '\0'; + + /* ignore empty lines */ + if (*line == '\0') + continue; + + line_len = strlen(line); + + /* cut leading whitespaces from token */ + for (token = line; *token; token++) + if (*token != ' ' && *token != '\t') + break; + + /* find end of token */ + for (line_ptr = token; *line_ptr; line_ptr++) + { + if (*line_ptr == ' ' || *line_ptr == '\t' || *line_ptr == ':') + { + *line_ptr = '\0'; + break; + } + } + + if (line_ptr < line + line_len) + value = line_ptr + 1; + else + value = "\0"; + + /* cut leading whitespaces from value */ + for (; *value; value++) + if (*value != ' ' && *value != '\t') + break; + + if (*token && *value) + updateSetupFileListEntry(setup_file_list, token, value); + + +#if 0 + { + /* allocate new token/value pair */ + + *next_entry = newSetupFileList(token, value); + next_entry = &((*next_entry)->next); + } +#endif + + + + } + + fclose(file); + + first_valid_list_entry = setup_file_list->next; + + /* free empty list header */ + setup_file_list->next = NULL; + freeSetupFileList(setup_file_list); + + if (!first_valid_list_entry) + Error(ERR_WARN, "setup file is empty"); + + return first_valid_list_entry; +} + +static void checkSetupFileListIdentifier(struct SetupFileList *setup_file_list, + char *identifier) +{ + if (!setup_file_list) + return; + + if (strcmp(setup_file_list->token, TOKEN_STR_FILE_IDENTIFIER) == 0) + { + if (strcmp(setup_file_list->value, identifier) != 0) + { + Error(ERR_WARN, "setup file has wrong version"); + return; + } + else + return; + } + + if (setup_file_list->next) + checkSetupFileListIdentifier(setup_file_list->next, identifier); + else + { + Error(ERR_WARN, "setup file has no version information"); + return; + } +} + +static void decodeSetupFileList(struct SetupFileList *setup_file_list) { int i; - int token_nr = -1; + int token_nr = TOKEN_INVALID; int player_nr = 0; char *token; char *token_value; @@ -1009,17 +1236,18 @@ static void decodeSetupFileInfo(struct SetupFileInfo *setup_file_info) boolean token_boolean_value; int token_player_prefix_len; - if (!setup_file_info) + if (!setup_file_list) return; - token = setup_file_info->token; - token_value = setup_file_info->value; + token = setup_file_list->token; + token_value = setup_file_list->value; token_integer_value = get_string_integer_value(token_value); token_boolean_value = get_string_boolean_value(token_value); - token_player_prefix_len = strlen(SETUP_TOKEN_PLAYER_PREFIX); + token_player_prefix_len = strlen(TOKEN_STR_PLAYER_PREFIX); - if (strncmp(token, SETUP_TOKEN_PLAYER_PREFIX, token_player_prefix_len) == 0) + if (strncmp(token, TOKEN_STR_PLAYER_PREFIX, + token_player_prefix_len) == 0) { token += token_player_prefix_len; @@ -1039,19 +1267,10 @@ static void decodeSetupFileInfo(struct SetupFileInfo *setup_file_info) } } - - - /* - printf("token == '%s', token_integer_value == %d\n", - token, token_integer_value); - - - printf("[player %d] token == '%s', token_value == '%s' (%ld)\n", - player_nr, token, token_value, - (unsigned long)getKeySymFromX11KeyName(token_value)); - */ - - + if (strcmp(token, TOKEN_STR_FILE_IDENTIFIER) == 0) + token_nr = TOKEN_IGNORE; + else if (strcmp(token, TOKEN_STR_ALIAS_NAME) == 0) + token_nr = SETUP_TOKEN_ALIAS_NAME; switch (token_nr) { @@ -1071,7 +1290,7 @@ static void decodeSetupFileInfo(struct SetupFileInfo *setup_file_info) setup.toons_on = token_boolean_value; break; case SETUP_TOKEN_DIRECT_DRAW: - setup.direct_draw_on = token_boolean_value; + setup.direct_draw_on = !token_boolean_value; break; case SETUP_TOKEN_SCROLL_DELAY: setup.scroll_delay_on = token_boolean_value; @@ -1121,164 +1340,142 @@ static void decodeSetupFileInfo(struct SetupFileInfo *setup_file_info) case SETUP_TOKEN_KEY_BOMB: setup.input[player_nr].key.bomb = getKeySymFromX11KeyName(token_value); break; + + case SETUP_TOKEN_ALIAS_NAME: + strncpy(local_player->alias_name, token_value, MAX_NAMELEN-1); + local_player->alias_name[MAX_NAMELEN-1] = '\0'; + break; + + case TOKEN_INVALID: + Error(ERR_WARN, "unknown token '%s' not recognized", token); + break; + + case TOKEN_IGNORE: default: break; } - decodeSetupFileInfo(setup_file_info->next); + decodeSetupFileList(setup_file_list->next); } void LoadSetup() { - int line_len; + int i; char filename[MAX_FILENAME_LEN]; - char line[MAX_LINE_LEN]; - char *token, *value, *line_ptr; - struct SetupFileInfo *setup_file_info, **next_entry = &setup_file_info; - FILE *file; + struct SetupFileList *setup_file_list = NULL; + /* always start with reliable default setup values */ + strncpy(local_player->login_name, GetLoginName(), MAX_NAMELEN-1); + local_player->login_name[MAX_NAMELEN-1] = '\0'; - printf("LoadSetup\n"); + strncpy(local_player->alias_name, GetLoginName(), MAX_NAMELEN-1); + local_player->alias_name[MAX_NAMELEN-1] = '\0'; + setup.sound_on = TRUE; + setup.sound_loops_on = FALSE; + setup.sound_music_on = FALSE; + setup.sound_simple_on = FALSE; + setup.toons_on = TRUE; + setup.direct_draw_on = FALSE; + setup.scroll_delay_on = FALSE; + setup.soft_scrolling_on = TRUE; + setup.fading_on = FALSE; + setup.autorecord_on = FALSE; + setup.quick_doors = FALSE; - - sprintf(filename, "%s/%s", SETUP_PATH, SETUP_FILENAME); - - if (!(file = fopen(filename, "r"))) + for (i=0; i line; line_ptr--) - if ((*line_ptr == ' ' || *line_ptr == '\t') && line_ptr[1] == '\0') - *line_ptr = '\0'; + /* always start with reliable default setup values */ - /* ignore empty lines */ - if (*line == '\0') - continue; + leveldir_nr = 0; + level_nr = 0; - line_len = strlen(line); + sprintf(filename, "%s/%s", SETUP_PATH, LEVELSETUP_FILENAME); + if (level_setup_list) + freeSetupFileList(level_setup_list); - /* - printf("line: '%s'\n", line); - */ + level_setup_list = loadSetupFileList(filename); + if (level_setup_list) + { + int i; - /* cut leading whitespaces from token */ - for (token = line; *token; token++) - if (*token != ' ' && *token != '\t') - break; + char *last_level_series = + getSetupFileListEntry(level_setup_list, TOKEN_STR_LAST_LEVEL_SERIES); - /* find end of token */ - for (line_ptr = token; *line_ptr; line_ptr++) + if (last_level_series) { - if (*line_ptr == ' ' || *line_ptr == '\t' || *line_ptr == ':') + for (i=0; i leveldir[leveldir_nr].levels - 1) + level_nr = leveldir[leveldir_nr].levels - 1; + } - *next_entry = newSetupFileInfo(token, value); - next_entry = &((*next_entry)->next); + break; + } + } } - } - fclose(file); #if 0 - printf("Content of setup file info:\n"); - - printSetupFileInfo(setup_file_info); + printSetupFileList(level_setup_list); #endif - - - printf("decodeSetupFileInfo\n"); - - - - decodeSetupFileInfo(setup_file_info); - freeSetupFileInfo(setup_file_info); + checkSetupFileListIdentifier(level_setup_list, LEVELSETUP_COOKIE); + } + else + Error(ERR_RETURN, "using default setup values"); } void SaveSetup() @@ -1287,22 +1484,16 @@ void SaveSetup() char filename[MAX_FILENAME_LEN]; FILE *file; - - - printf("SaveSetup\n"); - - - sprintf(filename, "%s/%s", SETUP_PATH, SETUP_FILENAME); if (!(file = fopen(filename, "w"))) { - Error(ERR_RETURN, "cannot write setup file '%s'", filename); + Error(ERR_WARN, "cannot write setup file '%s'", filename); return; } - fprintf(file, "file_identifier: %s\n", - SETUP_COOKIE); + fprintf(file, "%s: %s\n", + TOKEN_STR_FILE_IDENTIFIER, SETUP_COOKIE); fprintf(file, "\n"); @@ -1340,11 +1531,17 @@ void SaveSetup() getSetupEntry("", SETUP_TOKEN_QUICK_DOORS, setup.quick_doors)); + fprintf(file, "\n"); + + fprintf(file, "%s\n", + getFormattedSetupEntry(TOKEN_STR_ALIAS_NAME, + local_player->alias_name)); + for (i=0; itoken, TOKEN_STR_FILE_IDENTIFIER) != 0) + fprintf(file, "%s\n", + getFormattedSetupEntry(list_entry->token, list_entry->value)); + + /* just to make things nicer :) */ + if (strcmp(list_entry->token, TOKEN_STR_LAST_LEVEL_SERIES) == 0) + fprintf(file, "\n"); + + list_entry = list_entry->next; + } + + fclose(file); + chmod(filename, SETUP_PERMS); } diff --git a/src/files.h b/src/files.h index 9aa751f8..fae0b6b4 100644 --- a/src/files.h +++ b/src/files.h @@ -16,6 +16,10 @@ #include "main.h" + + +#if 0 + /* names file mode: local level setup or global game setup */ #define PLAYER_LEVEL 0 #define PLAYER_SETUP 1 @@ -51,25 +55,44 @@ #define SETUP_SCROLL_DELAY_ON(x) (((x) & SETUP_SCROLL_DELAY) != 0) #define SETUP_SOFT_SCROLL_ON(x) (((x) & SETUP_SOFT_SCROLL) != 0) +#endif + + + /* for LoadSetup() */ #define MAX_LINE_LEN 1000 #define MAX_SETUP_TOKEN_LEN 100 #define MAX_SETUP_VALUE_LEN 100 boolean CreateNewScoreFile(void); + +/* boolean CreateNewNamesFile(int); +*/ + boolean LoadLevelInfo(void); void LoadLevel(int); void LoadLevelTape(int); void LoadScore(int); + +/* void LoadPlayerInfo(int); +*/ + void SaveLevel(int); void SaveLevelTape(int); void SaveScore(int); + +/* void SavePlayerInfo(int); +*/ + void LoadJoystickData(void); void SaveJoystickData(void); + void LoadSetup(void); +void LoadLevelSetup(void); void SaveSetup(void); +void SaveLevelSetup(void); #endif diff --git a/src/game.c b/src/game.c index d198a32e..5de902ee 100644 --- a/src/game.c +++ b/src/game.c @@ -25,16 +25,24 @@ void GetPlayerConfig() { +#if 0 int old_joystick_nr = setup.input[0].joystick_nr; +#endif + + + if (sound_status == SOUND_OFF) + setup.sound_on = FALSE; - if (sound_status==SOUND_OFF) - local_player->setup &= ~SETUP_SOUND; if (!sound_loops_allowed) { - local_player->setup &= ~SETUP_SOUND_LOOPS; - local_player->setup &= ~SETUP_SOUND_MUSIC; + setup.sound_loops_on = FALSE; + setup.sound_music_on = FALSE; } + setup.sound_simple_on = setup.sound_on; + + +#if 0 setup.sound_on = setup.sound_simple_on = SETUP_SOUND_ON(local_player->setup); setup.sound_loops_on = SETUP_SOUND_LOOPS_ON(local_player->setup); setup.sound_music_on = SETUP_SOUND_MUSIC_ON(local_player->setup); @@ -61,6 +69,9 @@ void GetPlayerConfig() InitJoystick(); } #endif + +#endif + } void InitGame() @@ -572,13 +583,22 @@ void GameWon() SaveLevelTape(tape.level_nr); /* Ask to save tape */ } + + /* if (level_nr == local_player->handicap && level_nr < leveldir[leveldir_nr].levels-1) { local_player->handicap++; bumplevel = TRUE; + + +#if 0 SavePlayerInfo(PLAYER_LEVEL); +#endif + } + */ + if ((hi_pos=NewHiScore()) >= 0) { diff --git a/src/init.c b/src/init.c index 211e66e3..b0480831 100644 --- a/src/init.c +++ b/src/init.c @@ -134,15 +134,19 @@ void InitLevelAndPlayerInfo() Error(ERR_EXIT, NULL); - - LoadSetup(); - + LoadSetup(); /* global setup info */ + LoadLevelSetup(); /* info about last played level */ +#if 0 LoadPlayerInfo(PLAYER_SETUP); /* global setup info */ LoadPlayerInfo(PLAYER_LEVEL); /* level specific info */ +#endif + +#if 0 /* after LoadPlayerInfo(), because it overwrites 'local_player' */ +#endif for (i=0; i 20) + size = 20; + + if (size) + { + sprintf(s, " %09d", number); + return &s[strlen(s) - size]; + } + else + { + sprintf(s, "%d", number); + return s; + } } unsigned int SimpleRND(unsigned int max) @@ -318,7 +329,7 @@ void Error(int mode, char *format_str, ...) FILE *output_stream = stderr; char *process_name = ""; - if (mode == ERR_EXIT_SOUNDSERVER) + if (mode & ERR_SOUNDSERVER) process_name = " sound server"; if (format_str) @@ -331,6 +342,9 @@ void Error(int mode, char *format_str, ...) fprintf(output_stream, "%s%s: ", program_name, process_name); + if (mode & ERR_WARN) + fprintf(output_stream, "warning: "); + va_start(ap, format_str); /* ap points to first unnamed argument */ for(format_ptr=format_str; *format_ptr; format_ptr++) @@ -370,11 +384,11 @@ void Error(int mode, char *format_str, ...) fprintf(output_stream, "\n"); } - if (mode == ERR_EXIT_HELP) + if (mode & ERR_HELP) fprintf(output_stream, "%s: Try option '--help' for more information.\n", program_name); - if (mode != ERR_RETURN) + if (mode & ERR_EXIT) { fprintf(output_stream, "%s%s: aborting\n", program_name, process_name); CloseAllAndExit(1); diff --git a/src/misc.h b/src/misc.h index 2e979a09..10aae9ce 100644 --- a/src/misc.h +++ b/src/misc.h @@ -22,9 +22,12 @@ #define NEW_RANDOMIZE -1 #define ERR_RETURN 0 -#define ERR_EXIT 1 -#define ERR_EXIT_HELP 2 -#define ERR_EXIT_SOUNDSERVER 3 +#define ERR_WARN (1 << 0) +#define ERR_EXIT (1 << 1) +#define ERR_HELP (1 << 2) +#define ERR_SOUNDSERVER (1 << 3) +#define ERR_EXIT_HELP (ERR_EXIT | ERR_HELP) +#define ERR_EXIT_SOUNDSERVER (ERR_EXIT | ERR_SOUNDSERVER) void InitCounter(void); unsigned long Counter(void); diff --git a/src/network.c b/src/network.c index a58c6621..3f51426c 100644 --- a/src/network.c +++ b/src/network.c @@ -145,7 +145,7 @@ static void StartNetworkServer(int port) exit(0); case -1: - Error(ERR_RETURN, + Error(ERR_WARN, "cannot create network server process - no network games"); options.network = FALSE; return; @@ -303,7 +303,7 @@ void SendToServer_MovePlayer(byte player_action) static void Handle_OP_BAD_PROTOCOL_VERSION() { - Error(ERR_RETURN, "protocol version mismatch"); + Error(ERR_WARN, "protocol version mismatch"); Error(ERR_EXIT, "server expects %d.%d.x instead of %d.%d.%d", buf[2], buf[3], PROT_VERS_1, PROT_VERS_2, PROT_VERS_3); } @@ -480,13 +480,21 @@ static void Handle_OP_START_PLAYING() if (strcmp(leveldir[new_leveldir_nr].name, new_leveldir_name) != 0) - Error(ERR_RETURN, "no such level directory: '%s'",new_leveldir_name); + Error(ERR_WARN, "no such level directory: '%s'",new_leveldir_name); leveldir_nr = new_leveldir_nr; local_player->leveldir_nr = leveldir_nr; + + /* + SaveLevelSetup(); + */ + + /* LoadPlayerInfo(PLAYER_LEVEL); SavePlayerInfo(PLAYER_SETUP); + */ + level_nr = new_level_nr; diff --git a/src/screens.c b/src/screens.c index ab56a797..acc371dc 100644 --- a/src/screens.c +++ b/src/screens.c @@ -151,8 +151,12 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) level_nr = new_level_nr; + + /* if (level_nr > local_player->handicap) level_nr = local_player->handicap; + */ + DrawTextExt(drawto,gc,SX+11*32,SY+3*32, int2str(level_nr,3), FS_BIG,FC_RED); @@ -194,7 +198,15 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) if (num_leveldirs) { game_status = CHOOSELEVEL; + + + SaveLevelSetup(); + +#if 0 SavePlayerInfo(PLAYER_LEVEL); +#endif + + DrawChooseLevel(); } } @@ -235,7 +247,13 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) } else if (y==10) { + + SaveLevelSetup(); + +#if 0 SavePlayerInfo(PLAYER_LEVEL); +#endif + if (Request("Do you really want to quit ?", REQ_ASK | REQ_STAY_CLOSED)) game_status = EXITGAME; } @@ -683,13 +701,13 @@ void HandleHelpScreen(int button) BackToFront(); } + +#if 0 void CheckCheat() { int old_handicap = local_player->handicap; -#if 0 if (!strcmp(local_player->alias_name,"Artsoft")) -#endif local_player->handicap = leveldir[leveldir_nr].levels-1; if (local_player->handicap != old_handicap) @@ -698,6 +716,8 @@ void CheckCheat() level_nr = local_player->handicap; } } +#endif + void HandleTypeName(int newxpos, KeySym key) { @@ -744,8 +764,21 @@ void HandleTypeName(int newxpos, KeySym key) { DrawText(SX+6*32,SY+ypos*32,local_player->alias_name,FS_BIG,FC_RED); DrawGraphic(xpos+6,ypos,GFX_LEERRAUM); + + + SaveSetup(); + + +#if 0 SavePlayerInfo(PLAYER_SETUP); +#endif + + + +#if 0 CheckCheat(); +#endif + game_status = MAINMENU; /* @@ -832,9 +865,19 @@ void HandleChooseLevel(int mx, int my, int dx, int dy, int button) else { local_player->leveldir_nr = leveldir_nr = y-3; + + SaveLevelSetup(); + + /* LoadPlayerInfo(PLAYER_LEVEL); SavePlayerInfo(PLAYER_SETUP); + */ + + +#if 0 CheckCheat(); +#endif + TapeErase(); LoadLevelTape(level_nr); @@ -897,6 +940,9 @@ void HandleHallOfFame(int button) void DrawSetupScreen() { int i; + + +#if 0 static struct setup { unsigned int bit; @@ -920,11 +966,42 @@ void DrawSetupScreen() {0, "Exit", {"", ""}, {0,0}}, {0, "Save and exit",{"", ""}, {0,0}} }; +#endif + + static struct setup + { + boolean *value; + char *text, *mode[2]; + int color[2]; + } setup_info[] = + { + { &setup.sound_on, "Sound:", {"on", "off"},{FC_YELLOW,FC_BLUE}}, + { &setup.sound_loops_on," Sound Loops:",{"on", "off"},{FC_YELLOW,FC_BLUE}}, + { &setup.sound_music_on," Game Music:", {"on", "off"},{FC_YELLOW,FC_BLUE}}, + { &setup.toons_on, "Toons:", {"on", "off"},{FC_YELLOW,FC_BLUE}}, + { &setup.direct_draw_on,"Buffered gfx:",{"off","on" },{FC_BLUE,FC_YELLOW}}, + { &setup.scroll_delay_on,"Scroll Delay:",{"on", "off"},{FC_YELLOW,FC_BLUE}}, + { &setup.soft_scrolling_on, "Soft Scroll.:",{"on", "off"},{FC_YELLOW,FC_BLUE}}, + { &setup.fading_on, "Fading:", {"on", "off"},{FC_YELLOW,FC_BLUE}}, + { &setup.quick_doors,"Quick Doors:", {"on", "off"},{FC_YELLOW,FC_BLUE}}, + { &setup.autorecord_on,"Auto-Record:", {"on", "off"},{FC_YELLOW,FC_BLUE}}, + { NULL, "Input Devices",{"", ""}, {0,0}}, + { NULL, "", {"", ""}, {0,0}}, + { NULL, "", {"", ""}, {0,0}}, + { NULL, "Exit", {"", ""}, {0,0}}, + { NULL, "Save and exit",{"", ""}, {0,0}} + }; CloseDoor(DOOR_CLOSE_2); ClearWindow(); DrawText(SX+16, SY+16, "SETUP",FS_BIG,FC_YELLOW); + + /* + printf("setup.sound_loops_on == %d\n", setup.sound_loops_on); + */ + + for(i=SETUP_SCREEN_POS_START;i<=SETUP_SCREEN_POS_END;i++) { int base = i - SETUP_SCREEN_POS_START; @@ -932,15 +1009,24 @@ void DrawSetupScreen() if (!(i >= SETUP_SCREEN_POS_EMPTY1 && i <= SETUP_SCREEN_POS_EMPTY2)) { DrawGraphic(0,i,GFX_KUGEL_BLAU); - DrawText(SX+32,SY+i*32, setup[base].text, FS_BIG,FC_GREEN); + DrawText(SX+32,SY+i*32, setup_info[base].text, FS_BIG,FC_GREEN); } +#if 0 if (i < SETUP_SCREEN_POS_EMPTY1) { - int setting_bit = setup[base].bit; + int setting_bit = setup_info[base].bit; int setting_pos = ((local_player->setup & setting_bit) != 0 ? 0 : 1); - DrawText(SX+14*32, SY+i*32,setup[base].mode[setting_pos], - FS_BIG,setup[base].color[setting_pos]); + } +#endif + + if (setup_info[base].value) + { + int setting_value = *setup_info[base].value; + int setting_pos = (setting_value != 0 ? 0 : 1); + + DrawText(SX+14*32, SY+i*32,setup_info[base].mode[setting_pos], + FS_BIG,setup_info[base].color[setting_pos]); } } @@ -1014,97 +1100,97 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) if (y==3 && sound_status==SOUND_AVAILABLE) { - if (SETUP_SOUND_ON(local_player->setup)) + if (setup.sound_on) { DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); DrawText(SX+14*32, SY+(yy+1)*32,"off",FS_BIG,FC_BLUE); DrawText(SX+14*32, SY+(yy+2)*32,"off",FS_BIG,FC_BLUE); - local_player->setup &= ~SETUP_SOUND_LOOPS; - local_player->setup &= ~SETUP_SOUND_MUSIC; + setup.sound_loops_on = FALSE; + setup.sound_music_on = FALSE; } else DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); - local_player->setup ^= SETUP_SOUND; + setup.sound_on = !setup.sound_on; } else if (y==4 && sound_loops_allowed) { - if (SETUP_SOUND_LOOPS_ON(local_player->setup)) + if (setup.sound_loops_on) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else { DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); DrawText(SX+14*32, SY+(yy-1)*32,"on ",FS_BIG,FC_YELLOW); - local_player->setup |= SETUP_SOUND; + setup.sound_on = TRUE; } - local_player->setup ^= SETUP_SOUND_LOOPS; + setup.sound_loops_on = !setup.sound_loops_on; } else if (y==5 && sound_loops_allowed) { - if (SETUP_SOUND_MUSIC_ON(local_player->setup)) + if (setup.sound_music_on) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else { DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); DrawText(SX+14*32, SY+(yy-2)*32,"on ",FS_BIG,FC_YELLOW); - local_player->setup |= SETUP_SOUND; + setup.sound_on = TRUE; } - local_player->setup ^= SETUP_SOUND_MUSIC; + setup.sound_music_on = !setup.sound_music_on; } else if (y==6) { - if (SETUP_TOONS_ON(local_player->setup)) + if (setup.toons_on) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); - local_player->setup ^= SETUP_TOONS; + setup.toons_on = !setup.toons_on; } else if (y==7) { - if (!SETUP_DIRECT_DRAW_ON(local_player->setup)) + if (!setup.direct_draw_on) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); - local_player->setup ^= SETUP_DIRECT_DRAW; + setup.direct_draw_on = !setup.direct_draw_on; } else if (y==8) { - if (SETUP_SCROLL_DELAY_ON(local_player->setup)) + if (setup.scroll_delay_on) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); - local_player->setup ^= SETUP_SCROLL_DELAY; + setup.scroll_delay_on = !setup.scroll_delay_on; } else if (y==9) { - if (SETUP_SOFT_SCROLL_ON(local_player->setup)) + if (setup.soft_scrolling_on) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); - local_player->setup ^= SETUP_SOFT_SCROLL; + setup.soft_scrolling_on = !setup.soft_scrolling_on; } else if (y==10) { - if (SETUP_FADING_ON(local_player->setup)) + if (setup.fading_on) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); - local_player->setup ^= SETUP_FADING; + setup.fading_on = !setup.fading_on; } else if (y==11) { - if (SETUP_QUICK_DOORS_ON(local_player->setup)) + if (setup.quick_doors) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); - local_player->setup ^= SETUP_QUICK_DOORS; + setup.quick_doors = !setup.quick_doors; } else if (y==12) { - if (SETUP_AUTO_RECORD_ON(local_player->setup)) + if (setup.autorecord_on) DrawText(SX+14*32, SY+yy*32,"off",FS_BIG,FC_BLUE); else DrawText(SX+14*32, SY+yy*32,"on ",FS_BIG,FC_YELLOW); - local_player->setup ^= SETUP_AUTO_RECORD; + setup.autorecord_on = !setup.autorecord_on; } else if (y==13) { @@ -1116,7 +1202,15 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button) { if (y==pos_end) { + + + SaveSetup(); + + +#if 0 SavePlayerInfo(PLAYER_SETUP); +#endif + SaveJoystickData(); } @@ -1958,14 +2052,12 @@ void HandleSoundButtons(int mx, int my, int button) if (setup.sound_music_on) { setup.sound_music_on = FALSE; - local_player->setup &= ~SETUP_SOUND_MUSIC; FadeSound(background_loop[level_nr % num_bg_loops]); DrawSoundDisplay(BUTTON_SOUND_MUSIC_OFF); } else if (sound_loops_allowed) { setup.sound_on = setup.sound_music_on = TRUE; - local_player->setup |= (SETUP_SOUND | SETUP_SOUND_MUSIC); PlaySoundLoop(background_loop[level_nr % num_bg_loops]); DrawSoundDisplay(BUTTON_SOUND_MUSIC_ON); } @@ -1977,13 +2069,11 @@ void HandleSoundButtons(int mx, int my, int button) if (setup.sound_loops_on) { setup.sound_loops_on = FALSE; - local_player->setup &= ~SETUP_SOUND_LOOPS; DrawSoundDisplay(BUTTON_SOUND_LOOPS_OFF); } else if (sound_loops_allowed) { setup.sound_on = setup.sound_loops_on = TRUE; - local_player->setup |= (SETUP_SOUND | SETUP_SOUND_LOOPS); DrawSoundDisplay(BUTTON_SOUND_LOOPS_ON); } else @@ -1994,13 +2084,11 @@ void HandleSoundButtons(int mx, int my, int button) if (setup.sound_simple_on) { setup.sound_simple_on = FALSE; - local_player->setup &= ~SETUP_SOUND; DrawSoundDisplay(BUTTON_SOUND_SIMPLE_OFF); } else if (sound_status==SOUND_AVAILABLE) { setup.sound_on = setup.sound_simple_on = TRUE; - local_player->setup |= SETUP_SOUND; DrawSoundDisplay(BUTTON_SOUND_SIMPLE_ON); } else diff --git a/src/sound.c b/src/sound.c index be825edc..9ceeffcd 100644 --- a/src/sound.c +++ b/src/sound.c @@ -632,13 +632,13 @@ boolean LoadSound(struct SoundInfo *snd_info) #ifndef MSDOS if (!(file=fopen(filename,"r"))) { - Error(ERR_RETURN, "cannot open sound file '%s' - no sounds", filename); + Error(ERR_WARN, "cannot open sound file '%s' - no sounds", filename); return(FALSE); } if (fseek(file,0,SEEK_END)<0) { - Error(ERR_RETURN, "cannot read sound file '%s' - no sounds", filename); + Error(ERR_WARN, "cannot read sound file '%s' - no sounds", filename); fclose(file); return(FALSE); } @@ -648,14 +648,14 @@ boolean LoadSound(struct SoundInfo *snd_info) if (!(snd_info->file_ptr=malloc(snd_info->file_len))) { - Error(ERR_RETURN, "out of memory (this shouldn't happen :) - no sounds"); + Error(ERR_WARN, "out of memory (this shouldn't happen :) - no sounds"); fclose(file); return(FALSE); } if (fread(snd_info->file_ptr,1,snd_info->file_len,file)!=snd_info->file_len) { - Error(ERR_RETURN, "cannot read sound file '%s' - no sounds", filename); + Error(ERR_WARN, "cannot read sound file '%s' - no sounds", filename); fclose(file); return(FALSE); } @@ -668,7 +668,7 @@ boolean LoadSound(struct SoundInfo *snd_info) snd_info->file_len != be2long(&sound_header->chunk_size)+8 || strncmp(sound_header->magic_8SVX,"8SVX",4)) { - Error(ERR_RETURN, "'%s' is not an IFF/8SVX file or broken - no sounds", + Error(ERR_WARN, "'%s' is not an IFF/8SVX file or broken - no sounds", filename); return(FALSE); } @@ -711,7 +711,7 @@ boolean LoadSound(struct SoundInfo *snd_info) snd_info->sample_ptr = load_sample(filename); if(!snd_info->sample_ptr) { - Error(ERR_RETURN, "cannot read sound file '%s' - no sounds", filename); + Error(ERR_WARN, "cannot read sound file '%s' - no sounds", filename); fclose(file); return(FALSE); } @@ -762,7 +762,7 @@ void PlaySoundExt(int nr, int volume, int stereo, boolean loop) #ifndef MSDOS if (write(sound_pipe[1], &snd_ctrl, sizeof(snd_ctrl))<0) { - Error(ERR_RETURN, "cannot pipe to child process - no sounds"); + Error(ERR_WARN, "cannot pipe to child process - no sounds"); sound_status = SOUND_OFF; return; } @@ -812,7 +812,7 @@ void StopSoundExt(int nr, int method) #ifndef MSDOS if (write(sound_pipe[1], &snd_ctrl, sizeof(snd_ctrl))<0) { - Error(ERR_RETURN, "cannot pipe to child process - no sounds"); + Error(ERR_WARN, "cannot pipe to child process - no sounds"); sound_status = SOUND_OFF; return; } -- 2.34.1