local_player->dynamite = 1000;
break;
+
+
+#if 0
+
case XK_x:
{
break;
-
-#if 0
case XK_y:
/*
{
printf("direct_draw_on == %d\n", setup.direct_draw_on);
break;
-#endif
-
case XK_z:
{
}
break;
+#endif
#endif
default:
* files.h *
***********************************************************/
+#include <ctype.h>
+
#include "files.h"
#include "tools.h"
#include "misc.h"
if (!(file=fopen(filename,"r")))
{
- Error(ERR_RETURN, "cannot load level info '%s'", filename);
+ Error(ERR_RETURN, "cannot read level info '%s'", filename);
return(FALSE);
}
level_directory,leveldir[leveldir_nr].filename,level_nr);
if (!(file = fopen(filename,"r")))
- Error(ERR_RETURN, "cannot load level '%s' - creating new level", filename);
+ Error(ERR_RETURN, "cannot read level '%s' - creating new level", filename);
else
{
fgets(cookie,LEVEL_COOKIE_LEN,file);
if (!CreateNewScoreFile())
Error(ERR_RETURN, "cannot create score file '%s'", filename);
else if (!(file = fopen(filename,"r")))
- Error(ERR_RETURN, "cannot load score for level %d", level_nr);
+ Error(ERR_RETURN, "cannot read score for level %d", level_nr);
}
if (file)
if (!CreateNewNamesFile(mode))
Error(ERR_RETURN, "cannot create names file '%s'", filename);
else if (!(file = fopen(filename,"r")))
- Error(ERR_RETURN, "cannot load player information file '%s'", filename);
+ Error(ERR_RETURN, "cannot read player information file '%s'", filename);
}
if (file)
struct PlayerInfo default_player;
int version_10_file = FALSE;
- if (mode==PLAYER_LEVEL)
+
+
+ if (mode == PLAYER_SETUP)
+ SaveSetup();
+
+
+
+ if (mode == PLAYER_LEVEL)
sprintf(filename,"%s/%s/%s",
level_directory,leveldir[leveldir_nr].filename,NAMES_FILENAME);
else
#endif
}
+
+/* ------------------------------------------------------------------------- */
+/* new setup functions */
+/* ------------------------------------------------------------------------- */
+
+#define SETUP_TOKEN_SOUND 0
+#define SETUP_TOKEN_SOUND_LOOPS 1
+#define SETUP_TOKEN_SOUND_MUSIC 2
+#define SETUP_TOKEN_SOUND_SIMPLE 3
+#define SETUP_TOKEN_TOONS 4
+#define SETUP_TOKEN_DIRECT_DRAW 5
+#define SETUP_TOKEN_SCROLL_DELAY 6
+#define SETUP_TOKEN_SOFT_SCROLLING 7
+#define SETUP_TOKEN_FADING 8
+#define SETUP_TOKEN_AUTORECORD 9
+#define SETUP_TOKEN_QUICK_DOORS 10
+#define SETUP_TOKEN_USE_JOYSTICK 11
+#define SETUP_TOKEN_JOYSTICK_NR 12
+#define SETUP_TOKEN_JOY_SNAP 13
+#define SETUP_TOKEN_JOY_BOMB 14
+#define SETUP_TOKEN_KEY_LEFT 15
+#define SETUP_TOKEN_KEY_RIGHT 16
+#define SETUP_TOKEN_KEY_UP 17
+#define SETUP_TOKEN_KEY_DOWN 18
+#define SETUP_TOKEN_KEY_SNAP 19
+#define SETUP_TOKEN_KEY_BOMB 20
+
+#define NUM_SETUP_TOKENS 21
+
+#define SETUP_TOKEN_PLAYER_PREFIX "player_"
+
+static struct
+{
+ char *token, *value_true, *value_false;
+} setup_info[] =
+{
+ { "sound", "on", "off" },
+ { "repeating_sound_loops", "on", "off" },
+ { "background_music", "on", "off" },
+ { "simple_sound_effects", "on", "off" },
+ { "toons", "on", "off" },
+ { "double_buffering", "off", "on" },
+ { "scroll_delay", "on", "off" },
+ { "soft_scrolling", "on", "off" },
+ { "screen_fading", "on", "off" },
+ { "automatic_tape_recording", "on", "off" },
+ { "quick_doors", "on", "off" },
+
+ /* for each player: */
+ { ".use_joystick", "true", "false" },
+ { ".joystick_device", "second", "first" },
+ { ".joy.snap_field", "", "" },
+ { ".joy.place_bomb", "", "" },
+ { ".key.move_left", "", "" },
+ { ".key.move_right", "", "" },
+ { ".key.move_up", "", "" },
+ { ".key.move_down", "", "" },
+ { ".key.snap_field", "", "" },
+ { ".key.place_bomb", "", "" }
+};
+
+static char *string_tolower(char *s)
+{
+ static char s_lower[100];
+ int i;
+
+ if (strlen(s) >= 100)
+ return s;
+
+ strcpy(s_lower, s);
+
+ for (i=0; i<strlen(s_lower); i++)
+ s_lower[i] = tolower(s_lower[i]);
+
+ return s_lower;
+}
+
+static int get_string_integer_value(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" },
+ };
+
+ int i, j;
+
+ for (i=0; i<13; i++)
+ for (j=0; j<3; j++)
+ if (strcmp(string_tolower(s), number_text[i][j]) == 0)
+ return i;
+
+ return -1;
+}
+
+static boolean get_string_boolean_value(char *s)
+{
+ if (strcmp(string_tolower(s), "true") == 0 ||
+ strcmp(string_tolower(s), "yes") == 0 ||
+ strcmp(string_tolower(s), "on") == 0 ||
+ get_string_integer_value(s) == 1)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+static char *getSetupToken(int token_nr)
+{
+ return setup_info[token_nr].token;
+}
+
+static char *getSetupValue(int token_nr, boolean token_value)
+{
+ if (token_value == TRUE)
+ return setup_info[token_nr].value_true;
+ else
+ return setup_info[token_nr].value_false;
+}
+
+static char *getSetupEntry(char *prefix, int token_nr, int token_value)
+{
+ int i;
+ static char entry[80];
+
+ sprintf(entry, "%s%s:", prefix, getSetupToken(token_nr));
+ for (i=strlen(entry); i<30; i++)
+ entry[i] = ' ';
+ entry[i] = '\0';
+
+ strcat(entry, getSetupValue(token_nr, token_value));
+
+ return entry;
+}
+
+static char *getSetupEntryWithComment(char *prefix,int token_nr, KeySym keysym)
+{
+ int i;
+ static char entry[80];
+ char *keyname = getKeyNameFromKeySym(keysym);
+
+ sprintf(entry, "%s%s:", prefix, getSetupToken(token_nr));
+ for (i=strlen(entry); i<30; i++)
+ entry[i] = ' ';
+ entry[i] = '\0';
+
+ strcat(entry, getX11KeyNameFromKeySym(keysym));
+ for (i=strlen(entry); i<50; i++)
+ entry[i] = ' ';
+ entry[i] = '\0';
+
+ /* add comment, if useful */
+ if (strcmp(keyname, "(undefined)") != 0 &&
+ strcmp(keyname, "(unknown)") != 0)
+ {
+ strcat(entry, "# ");
+ strcat(entry, keyname);
+ }
+
+ return entry;
+}
+
+static void freeSetupFileInfo(struct SetupFileInfo *setup_file_info)
+{
+ if (!setup_file_info)
+ 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);
+}
+
+static struct SetupFileInfo *newSetupFileInfo(char *token, char *value)
+{
+ struct SetupFileInfo *new = checked_malloc(sizeof(struct SetupFileInfo));
+
+ new->token = checked_malloc(strlen(token) + 1);
+ strcpy(new->token, token);
+
+ new->value = checked_malloc(strlen(value) + 1);
+ strcpy(new->value, value);
+
+ new->next = NULL;
+
+ return new;
+}
+
+static char *lookupSetupFileValue(struct SetupFileInfo *setup_file_info,
+ char *token)
+{
+ if (!setup_file_info)
+ return NULL;
+
+ if (strcmp(setup_file_info->token, token) == 0)
+ return setup_file_info->value;
+ else
+ return lookupSetupFileValue(setup_file_info->next, token);
+}
+
+#ifdef DEBUG
+static void printSetupFileInfo(struct SetupFileInfo *setup_file_info)
+{
+ if (!setup_file_info)
+ return;
+
+ printf("token: '%s'\n", setup_file_info->token);
+ printf("value: '%s'\n", setup_file_info->value);
+
+ printSetupFileInfo(setup_file_info->next);
+}
+#endif
+
+static void decodeSetupFileInfo(struct SetupFileInfo *setup_file_info)
+{
+ int i;
+ int token_nr = -1;
+ int player_nr = 0;
+ char *token;
+ char *token_value;
+ int token_integer_value;
+ boolean token_boolean_value;
+ int token_player_prefix_len;
+
+ if (!setup_file_info)
+ return;
+
+ token = setup_file_info->token;
+ token_value = setup_file_info->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);
+
+ if (strncmp(token, SETUP_TOKEN_PLAYER_PREFIX, token_player_prefix_len) == 0)
+ {
+ token += token_player_prefix_len;
+
+ if (*token >= '0' && *token <= '9')
+ {
+ player_nr = ((int)(*token - '0') - 1 + MAX_PLAYERS) % MAX_PLAYERS;
+ token++;
+ }
+ }
+
+ for (i=0; i<NUM_SETUP_TOKENS; i++)
+ {
+ if (strcmp(token, setup_info[i].token) == 0)
+ {
+ token_nr = i;
+ break;
+ }
+ }
+
+
+
+ /*
+ 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));
+ */
+
+
+
+ switch (token_nr)
+ {
+ case SETUP_TOKEN_SOUND:
+ setup.sound_on = token_boolean_value;
+ break;
+ case SETUP_TOKEN_SOUND_LOOPS:
+ setup.sound_loops_on = token_boolean_value;
+ break;
+ case SETUP_TOKEN_SOUND_MUSIC:
+ setup.sound_music_on = token_boolean_value;
+ break;
+ case SETUP_TOKEN_SOUND_SIMPLE:
+ setup.sound_simple_on = token_boolean_value;
+ break;
+ case SETUP_TOKEN_TOONS:
+ setup.toons_on = token_boolean_value;
+ break;
+ case SETUP_TOKEN_DIRECT_DRAW:
+ setup.direct_draw_on = token_boolean_value;
+ break;
+ case SETUP_TOKEN_SCROLL_DELAY:
+ setup.scroll_delay_on = token_boolean_value;
+ break;
+ case SETUP_TOKEN_SOFT_SCROLLING:
+ setup.soft_scrolling_on = token_boolean_value;
+ break;
+ case SETUP_TOKEN_FADING:
+ setup.fading_on = token_boolean_value;
+ break;
+ case SETUP_TOKEN_AUTORECORD:
+ setup.autorecord_on = token_boolean_value;
+ break;
+ case SETUP_TOKEN_QUICK_DOORS:
+ setup.quick_doors = token_boolean_value;
+ break;
+
+ case SETUP_TOKEN_USE_JOYSTICK:
+ setup.input[player_nr].use_joystick = token_boolean_value;
+ break;
+ case SETUP_TOKEN_JOYSTICK_NR:
+ if (token_integer_value < 0 || token_integer_value > 1)
+ token_integer_value = 1;
+ setup.input[player_nr].joystick_nr = token_integer_value - 1;
+ break;
+ case SETUP_TOKEN_JOY_SNAP:
+ setup.input[player_nr].joy.snap = getJoySymbolFromJoyName(token_value);
+ break;
+ case SETUP_TOKEN_JOY_BOMB :
+ setup.input[player_nr].joy.bomb = getJoySymbolFromJoyName(token_value);
+ break;
+ case SETUP_TOKEN_KEY_LEFT:
+ setup.input[player_nr].key.left = getKeySymFromX11KeyName(token_value);
+ break;
+ case SETUP_TOKEN_KEY_RIGHT:
+ setup.input[player_nr].key.right = getKeySymFromX11KeyName(token_value);
+ break;
+ case SETUP_TOKEN_KEY_UP:
+ setup.input[player_nr].key.up = getKeySymFromX11KeyName(token_value);
+ break;
+ case SETUP_TOKEN_KEY_DOWN:
+ setup.input[player_nr].key.down = getKeySymFromX11KeyName(token_value);
+ break;
+ case SETUP_TOKEN_KEY_SNAP:
+ setup.input[player_nr].key.snap = getKeySymFromX11KeyName(token_value);
+ break;
+ case SETUP_TOKEN_KEY_BOMB:
+ setup.input[player_nr].key.bomb = getKeySymFromX11KeyName(token_value);
+ break;
+ default:
+ break;
+ }
+
+ decodeSetupFileInfo(setup_file_info->next);
+}
+
+void LoadSetup()
+{
+ int line_len;
+ 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;
+
+
+
+ printf("LoadSetup\n");
+
+
+
+ sprintf(filename, "%s/%s", SETUP_PATH, SETUP_FILENAME);
+
+ if (!(file = fopen(filename, "r")))
+ {
+ 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;
+ }
+
+
+
+ /*
+ next_entry = &setup_file;
+ */
+
+
+
+ while(!feof(file))
+ {
+ /* read next line */
+ 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);
+
+
+ /*
+ printf("line: '%s'\n", 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;
+
+
+ /*
+ printf("token / value: '%s' / '%s'\n", token, value);
+ */
+
+
+ if (*token && *value)
+ {
+ /* allocate new token/value pair */
+
+ *next_entry = newSetupFileInfo(token, value);
+ next_entry = &((*next_entry)->next);
+ }
+ }
+
+ fclose(file);
+
+#if 0
+ printf("Content of setup file info:\n");
+
+ printSetupFileInfo(setup_file_info);
+#endif
+
+
+
+ printf("decodeSetupFileInfo\n");
+
+
+
+ decodeSetupFileInfo(setup_file_info);
+ freeSetupFileInfo(setup_file_info);
+}
+
+void SaveSetup()
+{
+ int i;
+ 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);
+ return;
+ }
+
+ fprintf(file, "file_identifier: %s\n",
+ SETUP_COOKIE);
+
+ fprintf(file, "\n");
+
+ fprintf(file, "%s\n",
+ getSetupEntry("", SETUP_TOKEN_SOUND,
+ setup.sound_on));
+ fprintf(file, "%s\n",
+ getSetupEntry("", SETUP_TOKEN_SOUND_LOOPS,
+ setup.sound_loops_on));
+ fprintf(file, "%s\n",
+ getSetupEntry("", SETUP_TOKEN_SOUND_MUSIC,
+ setup.sound_music_on));
+ fprintf(file, "%s\n",
+ getSetupEntry("", SETUP_TOKEN_SOUND_SIMPLE,
+ setup.sound_simple_on));
+ fprintf(file, "%s\n",
+ getSetupEntry("", SETUP_TOKEN_TOONS,
+ setup.toons_on));
+ fprintf(file, "%s\n",
+ getSetupEntry("", SETUP_TOKEN_DIRECT_DRAW,
+ setup.direct_draw_on));
+ fprintf(file, "%s\n",
+ getSetupEntry("", SETUP_TOKEN_SCROLL_DELAY,
+ setup.scroll_delay_on));
+ fprintf(file, "%s\n",
+ getSetupEntry("", SETUP_TOKEN_SOFT_SCROLLING,
+ setup.soft_scrolling_on));
+ fprintf(file, "%s\n",
+ getSetupEntry("", SETUP_TOKEN_FADING,
+ setup.fading_on));
+ fprintf(file, "%s\n",
+ getSetupEntry("", SETUP_TOKEN_AUTORECORD,
+ setup.autorecord_on));
+ fprintf(file, "%s\n",
+ getSetupEntry("", SETUP_TOKEN_QUICK_DOORS,
+ setup.quick_doors));
+
+ for (i=0; i<MAX_PLAYERS; i++)
+ {
+ char prefix[30];
+
+ sprintf(prefix, "%s%d", SETUP_TOKEN_PLAYER_PREFIX, i + 1);
+
+ fprintf(file, "\n");
+
+ fprintf(file, "%s\n",
+ getSetupEntry(prefix, SETUP_TOKEN_USE_JOYSTICK,
+ setup.input[i].use_joystick));
+ fprintf(file, "%s\n",
+ getSetupEntry(prefix, SETUP_TOKEN_JOYSTICK_NR,
+ setup.input[i].joystick_nr));
+
+ fprintf(file, "%s%s: %s\n", prefix,
+ getSetupToken(SETUP_TOKEN_JOY_SNAP),
+ getJoyNameFromJoySymbol(setup.input[i].joy.snap));
+ fprintf(file, "%s%s: %s\n", prefix,
+ getSetupToken(SETUP_TOKEN_JOY_BOMB),
+ getJoyNameFromJoySymbol(setup.input[i].joy.bomb));
+
+ fprintf(file, "%s\n",
+ getSetupEntryWithComment(prefix, SETUP_TOKEN_KEY_LEFT,
+ setup.input[i].key.left));
+ fprintf(file, "%s\n",
+ getSetupEntryWithComment(prefix, SETUP_TOKEN_KEY_RIGHT,
+ setup.input[i].key.right));
+ fprintf(file, "%s\n",
+ getSetupEntryWithComment(prefix, SETUP_TOKEN_KEY_UP,
+ setup.input[i].key.up));
+ fprintf(file, "%s\n",
+ getSetupEntryWithComment(prefix, SETUP_TOKEN_KEY_DOWN,
+ setup.input[i].key.down));
+ fprintf(file, "%s\n",
+ getSetupEntryWithComment(prefix, SETUP_TOKEN_KEY_SNAP,
+ setup.input[i].key.snap));
+ fprintf(file, "%s\n",
+ getSetupEntryWithComment(prefix, SETUP_TOKEN_KEY_BOMB,
+ setup.input[i].key.bomb));
+ }
+
+ chmod(filename, SETUP_PERMS);
+}
#define SETUP_SCROLL_DELAY_ON(x) (((x) & SETUP_SCROLL_DELAY) != 0)
#define SETUP_SOFT_SCROLL_ON(x) (((x) & SETUP_SOFT_SCROLL) != 0)
+/* 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 SavePlayerInfo(int);
void LoadJoystickData(void);
void SaveJoystickData(void);
+void LoadSetup(void);
+void SaveSetup(void);
#endif
if (!IN_VIS_FIELD(SCREENX(jx),SCREENY(jy)))
{
-
-
- printf("prevent player %d from leaving visible screen\n",
- player->index_nr);
-
-
-
/* actual player has left the screen -- scroll in that direction */
if (jx != old_jx) /* player has moved horizontally */
scroll_x += (jx - old_jx);
{
if (!options.network && !AllPlayersInVisibleScreen())
{
-
-
- printf("oops! not all players visible if we scroll now\n");
-
-
-
scroll_x = old_scroll_x;
scroll_y = old_scroll_y;
}
else
{
-
-
- printf("ok, scrolling screen...\n");
-
-
-
ScrollScreen(player, SCROLL_INIT);
ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
}
{
int i;
+
+#if 0
+
/* initialize local setup */
setup.sound_on = TRUE;
setup.sound_loops_on = FALSE;
setup.input[i].key.bomb = (i == 0 ? DEFAULT_KEY_BOMB : KEY_UNDEFINDED);
}
+#endif
+
+
+
/* choose default local player */
local_player = &stored_player[0];
if (!LoadLevelInfo()) /* global level info */
Error(ERR_EXIT, NULL);
+
+
+ LoadSetup();
+
+
+
LoadPlayerInfo(PLAYER_SETUP); /* global setup info */
LoadPlayerInfo(PLAYER_LEVEL); /* level specific info */
struct LevelDirInfo leveldir[MAX_LEVDIR_ENTRIES];
struct LevelInfo level;
-struct PlayerInfo stored_player[MAX_PLAYERS], *local_player;
+struct PlayerInfo stored_player[MAX_PLAYERS], *local_player = NULL;
struct HiScore highscore[MAX_SCORE_ENTRIES];
struct SoundInfo Sound[NUM_SOUNDS];
struct RecordingInfo tape;
boolean verbose;
};
+struct SetupJoystickInfo
+{
+ int snap;
+ int bomb;
+};
+
struct SetupKeyboardInfo
{
KeySym left;
KeySym bomb;
};
-struct SetupJoystickInfo
-{
- int snap;
- int bomb;
-};
-
struct SetupInfo
{
boolean sound_on;
} input[MAX_PLAYERS];
};
+struct SetupFileInfo
+{
+ char *token;
+ char *value;
+ struct SetupFileInfo *next;
+};
+
struct PlayerInfo
{
boolean present; /* player present in level playfield */
(s)==SND_TWILIGHT)
/* default input keys */
-#define KEY_UNDEFINDED 0
+#define KEY_UNDEFINDED XK_VoidSymbol
#define DEFAULT_KEY_LEFT XK_Left
#define DEFAULT_KEY_RIGHT XK_Right
#define DEFAULT_KEY_UP XK_Up
#ifndef JOYDAT_PATH
#define JOYDAT_PATH GAME_DIR
#endif
+#ifndef SETUP_PATH
+#define SETUP_PATH GAME_DIR
+#endif
#ifndef MSDOS
#define SCORE_FILENAME "ROCKS.score"
#define NAMES_FILENAME "ROCKS.names"
#define LEVDIR_FILENAME "ROCKS.levelinfo"
#define JOYDAT_FILENAME "ROCKS.joystick"
+#define SETUP_FILENAME "ROCKS.setup"
#else
#define SCORE_FILENAME "ROCKS.sco"
#define NAMES_FILENAME "ROCKS.nam"
#define LEVDIR_FILENAME "ROCKS.lev"
#define JOYDAT_FILENAME "ROCKS.joy"
+#define SETUP_FILENAME "ROCKS.set"
#endif
#define JOYDAT_FILE JOYDAT_PATH "/" JOYDAT_FILENAME
#define LEVDIR_PERMS LEVEL_PERMS
#define LEVREC_PERMS LEVEL_PERMS
#define JOYDAT_PERMS LEVEL_PERMS
+#define SETUP_PERMS LEVEL_PERMS
/* old cookies */
#define NAMES_COOKIE_10 "ROCKSNDIAMONDS_NAMES_FILE_VERSION_1.0"
#define LEVELDIR_COOKIE "ROCKSNDIAMONDS_LEVELDIR_FILE_VERSION_1.0"
#define LEVELREC_COOKIE "ROCKSNDIAMONDS_LEVELREC_FILE_VERSION_1.2"
#define JOYSTICK_COOKIE "ROCKSNDIAMONDS_JOYSTICK_FILE_VERSION_1.0"
+#define SETUP_COOKIE "ROCKSNDIAMONDS_SETUP_FILE_VERSION_1.2"
#define LEVEL_COOKIE_LEN (strlen(LEVEL_COOKIE)+1)
#define SCORE_COOKIE_LEN (strlen(SCORE_COOKIE)+1)
#define NAMES_COOKIE_LEN (strlen(NAMES_COOKIE)+1)
#define LEVELDIR_COOKIE_LEN (strlen(LEVELDIR_COOKIE)+1)
#define LEVELREC_COOKIE_LEN (strlen(LEVELREC_COOKIE)+1)
#define JOYSTICK_COOKIE_LEN (strlen(JOYSTICK_COOKIE)+1)
+#define SETUP_COOKIE_LEN (strlen(SETUP_COOKIE)+1)
#define VERSION_STRING "1.2"
#define GAMETITLE_STRING "Rocks'n'Diamonds"
#include "tools.h"
#include "sound.h"
#include "random.h"
+#include "joystick.h"
static unsigned long mainCounter(int mode)
{
return ptr;
}
-char *getKeySymName(KeySym key)
+#define TRANSLATE_KEYSYM_TO_KEYNAME 0
+#define TRANSLATE_KEYSYM_TO_X11KEYNAME 1
+#define TRANSLATE_X11KEYNAME_TO_KEYSYM 2
+
+void translate_keyname(KeySym *keysym, char **x11name, char **name, int mode)
{
- static char key_name[20];
static struct
{
KeySym keysym;
+ char *x11name;
char *name;
- } translate[] =
+ } translate_key[] =
{
/* normal cursor keys */
- { XK_Left, "cursor left" },
- { XK_Right, "cursor right" },
- { XK_Up, "cursor up" },
- { XK_Down, "cursor down" },
+ { XK_Left, "XK_Left", "cursor left" },
+ { XK_Right, "XK_Right", "cursor right" },
+ { XK_Up, "XK_Up", "cursor up" },
+ { XK_Down, "XK_Down", "cursor down" },
/* keypad cursor keys */
#ifdef XK_KP_Left
- { XK_KP_Left, "keypad left" },
- { XK_KP_Right, "keypad right" },
- { XK_KP_Up, "keypad up" },
- { XK_KP_Down, "keypad down" },
+ { XK_KP_Left, "XK_KP_Left", "keypad left" },
+ { XK_KP_Right, "XK_KP_Right", "keypad right" },
+ { XK_KP_Up, "XK_KP_Up", "keypad up" },
+ { XK_KP_Down, "XK_KP_Down", "keypad down" },
#endif
/* other keypad keys */
#ifdef XK_KP_Enter
- { XK_KP_Enter, "keypad enter" },
- { XK_KP_Add, "keypad +" },
- { XK_KP_Subtract, "keypad -" },
- { XK_KP_Multiply, "keypad mltply" },
- { XK_KP_Divide, "keypad /" },
- { XK_KP_Separator, "keypad ," },
+ { XK_KP_Enter, "XK_KP_Enter", "keypad enter" },
+ { XK_KP_Add, "XK_KP_Add", "keypad +" },
+ { XK_KP_Subtract, "XK_KP_Subtract", "keypad -" },
+ { XK_KP_Multiply, "XK_KP_Multiply", "keypad mltply" },
+ { XK_KP_Divide, "XK_KP_Divide", "keypad /" },
+ { XK_KP_Separator, "XK_KP_Separator", "keypad ," },
#endif
/* modifier keys */
- { XK_Shift_L, "left shift" },
- { XK_Shift_R, "right shift" },
- { XK_Control_L, "left control" },
- { XK_Control_R, "right control" },
- { XK_Meta_L, "left meta" },
- { XK_Meta_R, "right meta" },
- { XK_Alt_L, "left alt" },
- { XK_Alt_R, "right alt" },
- { XK_Mode_switch, "mode switch" },
- { XK_Multi_key, "multi key" },
+ { XK_Shift_L, "XK_Shift_L", "left shift" },
+ { XK_Shift_R, "XK_Shift_R", "right shift" },
+ { XK_Control_L, "XK_Control_L", "left control" },
+ { XK_Control_R, "XK_Control_R", "right control" },
+ { XK_Meta_L, "XK_Meta_L", "left meta" },
+ { XK_Meta_R, "XK_Meta_R", "right meta" },
+ { XK_Alt_L, "XK_Alt_L", "left alt" },
+ { XK_Alt_R, "XK_Alt_R", "right alt" },
+ { XK_Mode_switch, "XK_Mode_switch", "mode switch" },
+ { XK_Multi_key, "XK_Multi_key", "multi key" },
/* some special keys */
- { XK_BackSpace, "backspace" },
- { XK_Delete, "delete" },
- { XK_Insert, "insert" },
- { XK_Tab, "tab" },
- { XK_Home, "home" },
- { XK_End, "end" },
- { XK_Page_Up, "page up" },
- { XK_Page_Down, "page down" },
- { XK_space, "space" },
+ { XK_BackSpace, "XK_BackSpace", "backspace" },
+ { XK_Delete, "XK_Delete", "delete" },
+ { XK_Insert, "XK_Insert", "insert" },
+ { XK_Tab, "XK_Tab", "tab" },
+ { XK_Home, "XK_Home", "home" },
+ { XK_End, "XK_End", "end" },
+ { XK_Page_Up, "XK_Page_Up", "page up" },
+ { XK_Page_Down, "XK_Page_Down", "page down" },
+ { XK_space, "XK_space", "space" },
/* even more special keys */
- { XK_adiaeresis, "ä" },
- { XK_odiaeresis, "ö" },
- { XK_udiaeresis, "ü" },
- { XK_apostrophe, "'" },
- { XK_plus, "+" },
- { XK_minus, "-" },
- { XK_comma, "," },
- { XK_period, "." },
- { XK_numbersign, "#" },
- { XK_less, "less" },
- { XK_greater, "greater" },
- { XK_asciicircum, "circumflex" },
- { XK_ssharp, "sharp s" },
+ { XK_adiaeresis, "XK_adiaeresis", "ä" },
+ { XK_odiaeresis, "XK_odiaeresis", "ö" },
+ { XK_udiaeresis, "XK_udiaeresis", "ü" },
+ { XK_apostrophe, "XK_apostrophe", "'" },
+ { XK_plus, "XK_plus", "+" },
+ { XK_minus, "XK_minus", "-" },
+ { XK_comma, "XK_comma", "," },
+ { XK_period, "XK_period", "." },
+ { XK_numbersign, "XK_numbersign", "#" },
+ { XK_less, "XK_less", "less" },
+ { XK_greater, "XK_greater", "greater" },
+ { XK_asciicircum, "XK_asciicircum", "circumflex" },
+ { XK_ssharp, "XK_ssharp", "sharp s" },
/* end-of-array identifier */
- { 0, NULL }
+ { 0, NULL, NULL }
};
- if (key >= XK_A && key <= XK_Z)
+ int i;
+
+ if (mode == TRANSLATE_KEYSYM_TO_KEYNAME)
{
- sprintf(key_name, "%c", 'A' + (char)(key - XK_A));
- return key_name;
+ static char name_buffer[30];
+ KeySym key = *keysym;
+
+ if (key >= XK_A && key <= XK_Z)
+ sprintf(name_buffer, "%c", 'A' + (char)(key - XK_A));
+ else if (key >= XK_a && key <= XK_z)
+ sprintf(name_buffer, "%c", 'a' + (char)(key - XK_a));
+ else if (key >= XK_0 && key <= XK_9)
+ sprintf(name_buffer, "%c", '0' + (char)(key - XK_0));
+ else if (key >= XK_KP_0 && key <= XK_KP_9)
+ sprintf(name_buffer, "keypad %c", '0' + (char)(key - XK_KP_0));
+ else if (key >= XK_F1 && key <= XK_F24)
+ sprintf(name_buffer, "function F%d", (int)(key - XK_F1 + 1));
+ else if (key == KEY_UNDEFINDED)
+ strcpy(name_buffer, "(undefined)");
+ else
+ {
+ i = 0;
+
+ do
+ {
+ if (key == translate_key[i].keysym)
+ {
+ strcpy(name_buffer, translate_key[i].name);
+ break;
+ }
+ }
+ while (translate_key[++i].name);
+
+ if (!translate_key[i].name)
+ strcpy(name_buffer, "(unknown)");
+ }
+
+ *name = name_buffer;
}
- else if (key >= XK_a && key <= XK_z)
+ else if (mode == TRANSLATE_KEYSYM_TO_X11KEYNAME)
{
- sprintf(key_name, "%c", 'a' + (char)(key - XK_a));
- return key_name;
+ static char name_buffer[30];
+ KeySym key = *keysym;
+
+ if (key >= XK_A && key <= XK_Z)
+ sprintf(name_buffer, "XK_%c", 'A' + (char)(key - XK_A));
+ else if (key >= XK_a && key <= XK_z)
+ sprintf(name_buffer, "XK_%c", 'a' + (char)(key - XK_a));
+ else if (key >= XK_0 && key <= XK_9)
+ sprintf(name_buffer, "XK_%c", '0' + (char)(key - XK_0));
+ else if (key >= XK_KP_0 && key <= XK_KP_9)
+ sprintf(name_buffer, "XK_KP_%c", '0' + (char)(key - XK_KP_0));
+ else if (key >= XK_F1 && key <= XK_F24)
+ sprintf(name_buffer, "XK_F%d", (int)(key - XK_F1 + 1));
+ else if (key == KEY_UNDEFINDED)
+ strcpy(name_buffer, "[undefined]");
+ else
+ {
+ i = 0;
+
+ do
+ {
+ if (key == translate_key[i].keysym)
+ {
+ strcpy(name_buffer, translate_key[i].x11name);
+ break;
+ }
+ }
+ while (translate_key[++i].x11name);
+
+ if (!translate_key[i].x11name)
+ sprintf(name_buffer, "0x%04lx", (unsigned long)key);
+ }
+
+ *x11name = name_buffer;
}
- else if (key >= XK_0 && key <= XK_9)
+ else if (mode == TRANSLATE_X11KEYNAME_TO_KEYSYM)
{
- sprintf(key_name, "%c", '0' + (char)(key - XK_0));
- return key_name;
+ KeySym key = XK_VoidSymbol;
+ char *name_ptr = *x11name;
+
+ if (strncmp(name_ptr, "XK_", 3) == 0 && strlen(name_ptr) == 4)
+ {
+ char c = name_ptr[3];
+
+ if (c >= 'A' && c <= 'Z')
+ key = XK_A + (KeySym)(c - 'A');
+ else if (c >= 'a' && c <= 'z')
+ key = XK_a + (KeySym)(c - 'a');
+ else if (c >= '0' && c <= '9')
+ key = XK_0 + (KeySym)(c - '0');
+ }
+ else if (strncmp(name_ptr, "XK_KP_", 6) == 0 && strlen(name_ptr) == 7)
+ {
+ char c = name_ptr[6];
+
+ if (c >= '0' && c <= '9')
+ key = XK_0 + (KeySym)(c - '0');
+ }
+ else if (strncmp(name_ptr, "XK_F", 4) == 0 && strlen(name_ptr) <= 6)
+ {
+ char c1 = name_ptr[4];
+ char c2 = name_ptr[5];
+ int d = 0;
+
+ if ((c1 >= '0' && c1 <= '9') &&
+ ((c2 >= '0' && c1 <= '9') || c2 == '\0'))
+ d = atoi(&name_ptr[4]);
+
+ if (d >=1 && d <= 24)
+ key = XK_F1 + (KeySym)(d - 1);
+ }
+ else if (strncmp(name_ptr, "XK_", 3) == 0)
+ {
+ i = 0;
+
+ do
+ {
+ if (strcmp(name_ptr, translate_key[i].x11name) == 0)
+ {
+ key = translate_key[i].keysym;
+ break;
+ }
+ }
+ while (translate_key[++i].x11name);
+ }
+ else if (strncmp(name_ptr, "0x", 2) == 0)
+ {
+ unsigned long value = 0;
+
+ name_ptr += 2;
+
+ while (name_ptr)
+ {
+ char c = *name_ptr++;
+ int d = -1;
+
+ if (c >= '0' && c <= '9')
+ d = (int)(c - '0');
+ else if (c >= 'a' && c <= 'f')
+ d = (int)(c - 'a' + 10);
+ else if (c >= 'A' && c <= 'F')
+ d = (int)(c - 'A' + 10);
+
+ if (d == -1)
+ {
+ value = -1;
+ break;
+ }
+
+ value = value * 16 + d;
+ }
+
+ if (value != -1)
+ key = (KeySym)value;
+ }
+
+ *keysym = key;
}
- else if (key >= XK_KP_0 && key <= XK_KP_9)
+}
+
+char *getKeyNameFromKeySym(KeySym keysym)
+{
+ char *name;
+
+ translate_keyname(&keysym, NULL, &name, TRANSLATE_KEYSYM_TO_KEYNAME);
+ return name;
+}
+
+char *getX11KeyNameFromKeySym(KeySym keysym)
+{
+ char *x11name;
+
+ translate_keyname(&keysym, &x11name, NULL, TRANSLATE_KEYSYM_TO_X11KEYNAME);
+ return x11name;
+}
+
+KeySym getKeySymFromX11KeyName(char *x11name)
+{
+ KeySym keysym;
+
+ translate_keyname(&keysym, &x11name, NULL, TRANSLATE_X11KEYNAME_TO_KEYSYM);
+ return keysym;
+}
+
+#define TRANSLATE_JOYSYMBOL_TO_JOYNAME 0
+#define TRANSLATE_JOYNAME_TO_JOYSYMBOL 1
+
+void translate_joyname(int *joysymbol, char **name, int mode)
+{
+ static struct
{
- sprintf(key_name, "keypad %c", '0' + (char)(key - XK_KP_0));
- return key_name;
- }
- else if (key >= XK_F1 && key <= XK_F24)
+ int joysymbol;
+ char *name;
+ } translate_joy[] =
{
- sprintf(key_name, "function F%d", (int)(key - XK_F1 + 1));
- return key_name;
- }
- else
+ { JOY_LEFT, "joystick_left" },
+ { JOY_RIGHT, "joystick_right" },
+ { JOY_UP, "joystick_up" },
+ { JOY_DOWN, "joystick_down" },
+ { JOY_BUTTON_1, "joystick_button_1" },
+ { JOY_BUTTON_2, "joystick_button_2" },
+ };
+
+ int i;
+
+ if (mode == TRANSLATE_JOYSYMBOL_TO_JOYNAME)
{
- int i = 0;
+ *name = "[undefined]";
- do
+ for (i=0; i<6; i++)
{
- if (key == translate[i].keysym)
- return translate[i].name;
+ if (*joysymbol == translate_joy[i].joysymbol)
+ {
+ *name = translate_joy[i].name;
+ break;
+ }
}
- while (translate[++i].name);
+ }
+ else if (mode == TRANSLATE_JOYNAME_TO_JOYSYMBOL)
+ {
+ *joysymbol = 0;
- sprintf(key_name, "(unknown)");
- return key_name;
+ for (i=0; i<6; i++)
+ {
+ if (strcmp(*name, translate_joy[i].name) == 0)
+ {
+ *joysymbol = translate_joy[i].joysymbol;
+ break;
+ }
+ }
}
}
+
+char *getJoyNameFromJoySymbol(int joysymbol)
+{
+ char *name;
+
+ translate_joyname(&joysymbol, &name, TRANSLATE_JOYSYMBOL_TO_JOYNAME);
+ return name;
+}
+
+int getJoySymbolFromJoyName(char *name)
+{
+ int joysymbol;
+
+ translate_joyname(&joysymbol, &name, TRANSLATE_JOYNAME_TO_JOYSYMBOL);
+ return joysymbol;
+}
void GetOptions(char **);
void Error(int, char *, ...);
void *checked_malloc(unsigned long);
-char *getKeySymName(KeySym);
+char *getKeyNameFromKeySym(KeySym);
+char *getX11KeyNameFromKeySym(KeySym);
+KeySym getKeySymFromX11KeyName(char *);
+char *getJoyNameFromJoySymbol(int);
+int getJoySymbolFromJoyName(char *);
#endif
DrawText(SX + 3*32, SY + ypos*32,
(setup.input[player_nr].use_joystick ?
custom[i].text :
- getKeySymName(*custom[i].keysym)),
+ getKeyNameFromKeySym(*custom[i].keysym)),
FS_BIG, FC_YELLOW);
}
}
DrawText(SX, SY + (2+2*step_nr+1)*32,
"Key:", FS_BIG, FC_RED);
DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
- getKeySymName(*customize_step[step_nr].keysym), FS_BIG, FC_BLUE);
+ getKeyNameFromKeySym(*customize_step[step_nr].keysym),
+ FS_BIG, FC_BLUE);
while(!finished)
{
DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
" ", FS_BIG, FC_YELLOW);
DrawText(SX + 4*32, SY + (2+2*step_nr+1)*32,
- getKeySymName(key), FS_BIG, FC_YELLOW);
+ getKeyNameFromKeySym(key), FS_BIG, FC_YELLOW);
step_nr++;
/* un-highlight last query */
DrawText(SX, SY+(2+2*step_nr+1)*32,
"Key:", FS_BIG, FC_RED);
DrawText(SX + 4*32, SY+(2+2*step_nr+1)*32,
- getKeySymName(*customize_step[step_nr].keysym),
+ getKeyNameFromKeySym(*customize_step[step_nr].keysym),
FS_BIG, FC_BLUE);
}
break;