return(TRUE);
}
+
+
+#if 0
+
boolean CreateNewNamesFile(int mode)
{
char filename[MAX_FILENAME_LEN];
return(TRUE);
}
+#endif
+
+
boolean LoadLevelInfo()
{
int i;
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);
}
if (!num_leveldirs)
{
- Error(ERR_RETURN, "empty level info '%s'", filename);
+ Error(ERR_WARN, "empty level info '%s'", filename);
return(FALSE);
}
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);
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;
}
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;
}
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();
}
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)
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;
}
}
}
+
+
+#if 0
+
void LoadPlayerInfo(int mode)
{
int i;
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);
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)
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;
}
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
{
fclose(file);
}
+#endif
+
+
+
void SaveLevel(int level_nr)
{
int i,x,y;
if (!(file=fopen(filename,"w")))
{
- Error(ERR_RETURN, "cannot save level file '%s'", filename);
+ Error(ERR_WARN, "cannot save level file '%s'", filename);
return;
}
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;
}
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;
}
fclose(file);
}
+
+
+#if 0
+
void SavePlayerInfo(int mode)
{
int i;
if (mode == PLAYER_SETUP)
SaveSetup();
+ else if (mode == PLAYER_LEVEL)
+ SaveLevelSetup();
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;
}
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;
}
fclose(file);
}
+#endif
+
+
+
void LoadJoystickData()
{
int i;
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;
}
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;
}
/* 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
#define NUM_SETUP_TOKENS 21
-#define SETUP_TOKEN_PLAYER_PREFIX "player_"
-
static struct
{
char *token, *value_true, *value_false;
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); i<TOKEN_VALUE_POSITION; i++)
+ entry[i] = ' ';
+ entry[i] = '\0';
+
+ strcat(entry, value);
+
+ return entry;
+}
+
static char *getSetupEntry(char *prefix, int token_nr, int token_value)
{
int i;
- static char entry[80];
+ static char entry[MAX_LINE_LEN];
sprintf(entry, "%s%s:", prefix, getSetupToken(token_nr));
- for (i=strlen(entry); i<30; i++)
+ for (i=strlen(entry); i<TOKEN_VALUE_POSITION; i++)
entry[i] = ' ';
entry[i] = '\0';
static char *getSetupEntryWithComment(char *prefix,int token_nr, KeySym keysym)
{
int i;
- static char entry[80];
+ static char entry[MAX_LINE_LEN];
char *keyname = getKeyNameFromKeySym(keysym);
sprintf(entry, "%s%s:", prefix, getSetupToken(token_nr));
- for (i=strlen(entry); i<30; i++)
+ for (i=strlen(entry); i<TOKEN_VALUE_POSITION; i++)
entry[i] = ' ';
entry[i] = '\0';
return entry;
}
-static void freeSetupFileInfo(struct SetupFileInfo *setup_file_info)
+static void freeSetupFileList(struct SetupFileList *setup_file_list)
{
- if (!setup_file_info)
+ if (!setup_file_list)
return;
- if (setup_file_info->token)
- 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);
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;
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;
}
}
-
-
- /*
- 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)
{
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;
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<MAX_PLAYERS; i++)
{
- int i;
-
- Error(ERR_RETURN, "cannot open setup file '%s'", filename);
-
- /* use default values for setup */
-
- 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;
-
- for (i=0; i<MAX_PLAYERS; i++)
- {
- setup.input[i].use_joystick = FALSE;
- setup.input[i].joystick_nr = 0;
- setup.input[i].joy.snap = (i == 0 ? JOY_BUTTON_1 : 0);
- setup.input[i].joy.bomb = (i == 0 ? JOY_BUTTON_2 : 0);
- setup.input[i].key.left = (i == 0 ? DEFAULT_KEY_LEFT : KEY_UNDEFINDED);
- setup.input[i].key.right = (i == 0 ? DEFAULT_KEY_RIGHT : KEY_UNDEFINDED);
- setup.input[i].key.up = (i == 0 ? DEFAULT_KEY_UP : KEY_UNDEFINDED);
- setup.input[i].key.down = (i == 0 ? DEFAULT_KEY_DOWN : KEY_UNDEFINDED);
- setup.input[i].key.snap = (i == 0 ? DEFAULT_KEY_SNAP : KEY_UNDEFINDED);
- setup.input[i].key.bomb = (i == 0 ? DEFAULT_KEY_BOMB : KEY_UNDEFINDED);
- }
-
- return;
+ setup.input[i].use_joystick = FALSE;
+ setup.input[i].joystick_nr = 0;
+ setup.input[i].joy.snap = (i == 0 ? JOY_BUTTON_1 : 0);
+ setup.input[i].joy.bomb = (i == 0 ? JOY_BUTTON_2 : 0);
+ setup.input[i].key.left = (i == 0 ? DEFAULT_KEY_LEFT : KEY_UNDEFINDED);
+ setup.input[i].key.right = (i == 0 ? DEFAULT_KEY_RIGHT : KEY_UNDEFINDED);
+ setup.input[i].key.up = (i == 0 ? DEFAULT_KEY_UP : KEY_UNDEFINDED);
+ setup.input[i].key.down = (i == 0 ? DEFAULT_KEY_DOWN : KEY_UNDEFINDED);
+ setup.input[i].key.snap = (i == 0 ? DEFAULT_KEY_SNAP : KEY_UNDEFINDED);
+ setup.input[i].key.bomb = (i == 0 ? DEFAULT_KEY_BOMB : KEY_UNDEFINDED);
}
+ sprintf(filename, "%s/%s", SETUP_PATH, SETUP_FILENAME);
+ setup_file_list = loadSetupFileList(filename);
- /*
- next_entry = &setup_file;
- */
+ if (setup_file_list)
+ {
+#if 0
+ printSetupFileList(setup_file_list);
+#endif
+ checkSetupFileListIdentifier(setup_file_list, SETUP_COOKIE);
+ decodeSetupFileList(setup_file_list);
- while(!feof(file))
- {
- /* read next line */
- if (!fgets(line, MAX_LINE_LEN, file))
- break;
+ freeSetupFileList(setup_file_list);
+ }
+ else
+ Error(ERR_RETURN, "using default setup values");
+}
- /* 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;
- }
- }
+void LoadLevelSetup()
+{
+ char filename[MAX_FILENAME_LEN];
- /* 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';
+ /* 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<num_leveldirs; i++)
{
- *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 (strcmp(last_level_series, leveldir[i].filename) == 0)
+ {
+ char *token_value =
+ getSetupFileListEntry(level_setup_list, last_level_series);
- /*
- printf("token / value: '%s' / '%s'\n", token, value);
- */
+ leveldir_nr = i;
+ if (token_value)
+ {
+ level_nr = atoi(token_value);
- if (*token && *value)
- {
- /* allocate new token/value pair */
+ if (level_nr < 0)
+ level_nr = 0;
+ if (level_nr > 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()
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");
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; i<MAX_PLAYERS; i++)
{
char prefix[30];
- sprintf(prefix, "%s%d", SETUP_TOKEN_PLAYER_PREFIX, i + 1);
+ sprintf(prefix, "%s%d", TOKEN_STR_PLAYER_PREFIX, i + 1);
fprintf(file, "\n");
setup.input[i].key.bomb));
}
+ fclose(file);
+
+ chmod(filename, SETUP_PERMS);
+}
+
+void SaveLevelSetup()
+{
+ char filename[MAX_FILENAME_LEN];
+ struct SetupFileList *list_entry = level_setup_list;
+ FILE *file;
+
+ updateSetupFileListEntry(level_setup_list,
+ TOKEN_STR_LAST_LEVEL_SERIES,
+ leveldir[leveldir_nr].filename);
+
+ updateSetupFileListEntry(level_setup_list,
+ leveldir[leveldir_nr].filename,
+ int2str(level_nr, 0));
+
+ sprintf(filename, "%s/%s", SETUP_PATH, LEVELSETUP_FILENAME);
+
+ if (!(file = fopen(filename, "w")))
+ {
+ Error(ERR_WARN, "cannot write setup file '%s'", filename);
+ return;
+ }
+
+ fprintf(file, "%s: %s\n\n",
+ TOKEN_STR_FILE_IDENTIFIER, LEVELSETUP_COOKIE);
+
+ while (list_entry)
+ {
+ if (strcmp(list_entry->token, 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);
}
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);
if (num_leveldirs)
{
game_status = CHOOSELEVEL;
+
+
+ SaveLevelSetup();
+
+#if 0
SavePlayerInfo(PLAYER_LEVEL);
+#endif
+
+
DrawChooseLevel();
}
}
}
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;
}
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)
level_nr = local_player->handicap;
}
}
+#endif
+
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;
/*
else
{
local_player->leveldir_nr = leveldir_nr = y-3;
+
+ SaveLevelSetup();
+
+ /*
LoadPlayerInfo(PLAYER_LEVEL);
SavePlayerInfo(PLAYER_SETUP);
+ */
+
+
+#if 0
CheckCheat();
+#endif
+
TapeErase();
LoadLevelTape(level_nr);
void DrawSetupScreen()
{
int i;
+
+
+#if 0
static struct setup
{
unsigned int bit;
{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;
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]);
}
}
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)
{
{
if (y==pos_end)
{
+
+
+ SaveSetup();
+
+
+#if 0
SavePlayerInfo(PLAYER_SETUP);
+#endif
+
SaveJoystickData();
}
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);
}
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
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