You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
500 lines
16 KiB
500 lines
16 KiB
/* configuration */
|
|
|
|
#include <SDL.h>
|
|
|
|
#include "basic.h"
|
|
#include "bomberclone.h"
|
|
#include "network.h"
|
|
#include "packets.h"
|
|
#include "gfx.h"
|
|
#include "chat.h"
|
|
#include "sound.h"
|
|
#include "menu.h"
|
|
|
|
void
|
|
config_init (int argc, char **argv)
|
|
{
|
|
int i;
|
|
|
|
srand (((int) time (NULL))); // initialize randomgenerator
|
|
|
|
for (i = 0; i < MAX_PLAYERS; i++) {
|
|
players[i].gfx = NULL; /* we will select them in the wait_for_players loop */
|
|
players[i].gfx_nr = -1; /* and even now in the singleplayer menu */
|
|
}
|
|
|
|
menu.oldscreen = NULL;
|
|
|
|
stonelist_del ();
|
|
chat.visible = 0;
|
|
chat.startline = 0;
|
|
keybinput_new (&chat.input, KEYBI_text, 255);
|
|
|
|
for (i = 0; i < CHAT_MAX_LINES; i++)
|
|
chat.lines[i].text[0] = 0;
|
|
|
|
bman.maxplayer = MAX_PLAYERS;
|
|
bman.net_ai_family = PF_INET;
|
|
bman.sock = -1;
|
|
bman.gamename[0] = 0;
|
|
sprintf (bman.port, "%d", DEFAULT_UDPPORT);
|
|
sprintf (bman.ogcserver, DEFAULT_GAMECACHE);
|
|
sprintf (bman.ogc_port, DEFAULT_GAMECACHEPORT);
|
|
resend_cache.data = NULL;
|
|
resend_cache.fill = -1;
|
|
bman.notifygamemaster = 1;
|
|
bman.askplayername = 1;
|
|
debug = 0;
|
|
gfx.res.x = 640;
|
|
gfx.res.y = 480;
|
|
gfx.bpp = 16;
|
|
map.tileset[0] = 0;
|
|
map.random_tileset = 1;
|
|
map.size.x = 25;
|
|
map.size.y = 17;
|
|
sprintf (bman.datapath, PACKAGE_DATA_DIR);
|
|
map.map[0] = 0;
|
|
map.map_selection = 2;
|
|
map.type = -1;
|
|
bman.firewall = 0;
|
|
bman.init_timeout = GAME_TIMEOUT;
|
|
bman.ai_players = 1;
|
|
snd.inited = 0;
|
|
snd.audio_rate = 22050;
|
|
snd.audio_format = AUDIO_S16;
|
|
snd.audio_channels = 2;
|
|
snd.playmusic = 1;
|
|
snd.playsound = 1;
|
|
map.bombs = GAME_SPECIAL_ITEMBOMB;
|
|
map.fire = GAME_SPECIAL_ITEMFIRE;
|
|
map.shoes = GAME_SPECIAL_ITEMSHOE;
|
|
map.mixed = GAME_SPECIAL_ITEMMIXED;
|
|
map.death = GAME_SPECIAL_ITEMDEATH;
|
|
map.sp_trigger = GAME_SPECIAL_ITEMSTRIGGER;
|
|
map.sp_row = GAME_SPECIAL_ITEMSROW;
|
|
map.sp_push = GAME_SPECIAL_ITEMSPUSH;
|
|
map.sp_kick = GAME_SPECIAL_ITEMSKICK;
|
|
|
|
bman.start_bombs = START_BOMBS;
|
|
bman.start_speed = START_SPEED;
|
|
bman.start_range = START_RANGE;
|
|
bman.bomb_tickingtime = BOMB_TIMEOUT;
|
|
bman.dropitemsondeath = 0;
|
|
|
|
d_printf ("\n\n ***** Bomberclone Version %s \n\n", VERSION);
|
|
if (config_read ()) { /* error on reading the config file */
|
|
ReadPrgArgs (argc, argv);
|
|
gfx_init ();
|
|
draw_logo ();
|
|
bman.playername[LEN_PLAYERNAME - 1] = 0;
|
|
bman.playername[0] = 0;
|
|
config_menu ();
|
|
}
|
|
else {
|
|
ReadPrgArgs (argc, argv);
|
|
gfx_init ();
|
|
draw_logo ();
|
|
if (bman.askplayername)
|
|
config_menu ();
|
|
}
|
|
|
|
snd_init ();
|
|
gfx_blitdraw ();
|
|
SDL_Flip (gfx.screen);
|
|
};
|
|
|
|
|
|
/* read the configuration file
|
|
* return -1 if something went wrong and 0 if no problem */
|
|
int
|
|
config_read ()
|
|
{
|
|
FILE *config;
|
|
char buf[1024];
|
|
char *findit,
|
|
*keyword,
|
|
*value;
|
|
int i;
|
|
char filename[512];
|
|
|
|
#ifdef _WIN32
|
|
sprintf (filename, "%sbomberclone.cfg", s_gethomedir ());
|
|
#else
|
|
sprintf (filename, "%s.bomberclone.cfg", s_gethomedir ());
|
|
#endif
|
|
|
|
config = fopen (filename, "r");
|
|
if (config == NULL) {
|
|
d_printf ("Error: Config file not found!\n");
|
|
return -1;
|
|
}
|
|
d_printf ("Reading Config-file: %s", filename);
|
|
|
|
while (fgets (buf, sizeof (buf), config) != NULL) {
|
|
findit = strchr (buf, '\n');
|
|
if (findit)
|
|
findit[0] = '\0';
|
|
if (buf[0] == '\0')
|
|
continue;
|
|
|
|
keyword = buf;
|
|
while (isspace (*keyword))
|
|
keyword++;
|
|
|
|
value = strchr (buf, '=');
|
|
if (value == NULL)
|
|
continue;
|
|
*value = 0;
|
|
value++;
|
|
while (*value == ' ')
|
|
value++;
|
|
while (keyword[strlen (keyword) - 1] == ' ')
|
|
keyword[strlen (keyword) - 1] = 0;
|
|
while (value[strlen (value) - 1] == ' ')
|
|
value[strlen (value) - 1] = 0;
|
|
if (strlen (value) == 0)
|
|
continue;
|
|
for (i = 0; i < (int) strlen (keyword); i++)
|
|
keyword[i] = tolower (keyword[i]);
|
|
|
|
if (!strcmp (keyword, "playername")) {
|
|
if (strlen (value) > LEN_PLAYERNAME) {
|
|
d_printf
|
|
("*** Error - playername too long (maximum size permitted is %d characters)!\n\n",
|
|
LEN_PLAYERNAME);
|
|
}
|
|
value[LEN_PLAYERNAME - 1] = 0;
|
|
strcpy (bman.playername, value);
|
|
}
|
|
|
|
if (!strcmp (keyword, "gamename")) {
|
|
if (strlen (value) > LEN_GAMENAME) {
|
|
d_printf
|
|
("*** Error - servername too long (maximum size permitted is %d characters)!\n\n",
|
|
LEN_GAMENAME);
|
|
}
|
|
value[LEN_GAMENAME - 1] = 0;
|
|
strcpy (bman.gamename, value);
|
|
}
|
|
if (!strcmp (keyword, "askplayername")) {
|
|
bman.askplayername = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "resolutionx")) {
|
|
gfx.res.x = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "resolutiony")) {
|
|
gfx.res.y = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "tileset")) {
|
|
strcpy (map.tileset, value);
|
|
}
|
|
if (!strcmp (keyword, "mapname")) {
|
|
if (strlen (value) > LEN_PATHFILENAME) {
|
|
d_printf
|
|
("*** Error - fieldpath too long (maximum size permitted is %d characters)!\n\n",
|
|
LEN_PATHFILENAME);
|
|
}
|
|
value[511] = 0;
|
|
strcpy (map.map, value);
|
|
}
|
|
if (!strcmp (keyword, "firewall")) {
|
|
bman.firewall = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "udpport")) {
|
|
if (strlen (value) > LEN_PORT) {
|
|
d_printf
|
|
("*** Error - servername too long (maximum size permitted is %d characters)!\n\n",
|
|
LEN_PORT);
|
|
}
|
|
value[LEN_PORT - 1] = 0;
|
|
strcpy (bman.port, value);
|
|
}
|
|
if (!strcmp (keyword, "ai_players")) {
|
|
bman.ai_players = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "fieldsizex")) {
|
|
map.size.x = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "fieldsizey")) {
|
|
map.size.y = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "fullscreen")) {
|
|
gfx.fullscreen = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "bitsperpixel")) {
|
|
gfx.bpp = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "ai_family")) {
|
|
bman.net_ai_family = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "debug")) {
|
|
debug = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "notify")) {
|
|
bman.notifygamemaster = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "ogcserver")) {
|
|
strcpy (bman.ogcserver, value);
|
|
}
|
|
if (!strcmp (keyword, "ogc_port")) {
|
|
strcpy (bman.ogc_port, value);
|
|
}
|
|
if (!strcmp (keyword, "maxplayer")) {
|
|
bman.maxplayer = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "mapselection")) {
|
|
map.map_selection = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "randomtileset")) {
|
|
map.random_tileset = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "gametimeout")) {
|
|
bman.init_timeout = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "gametype")) {
|
|
bman.gametype = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "sndrate")) {
|
|
snd.audio_rate = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "sndchannels")) {
|
|
snd.audio_channels = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "sndformat")) {
|
|
snd.audio_format = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "sndplaymusic")) {
|
|
snd.playmusic = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "sndplaysound")) {
|
|
snd.playsound = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "start_bombs")) {
|
|
bman.start_bombs = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "start_range")) {
|
|
bman.start_range = atoi (value);
|
|
}
|
|
if (!strcmp (keyword, "start_speed")) {
|
|
sscanf (value, "%f", &bman.start_speed);
|
|
}
|
|
if (!strcmp (keyword, "bomb_ticking")) {
|
|
sscanf (value, "%f", &bman.bomb_tickingtime);
|
|
}
|
|
if (!strcmp (keyword, "dropitemsondeath")) {
|
|
bman.dropitemsondeath = atoi (value);
|
|
}
|
|
}
|
|
fclose (config);
|
|
return 0;
|
|
};
|
|
|
|
|
|
int
|
|
config_write ()
|
|
{
|
|
FILE *config;
|
|
char filename[512];
|
|
#ifdef _WIN32
|
|
sprintf (filename, "%sbomberclone.cfg", s_gethomedir ());
|
|
#else
|
|
sprintf (filename, "%s.bomberclone.cfg", s_gethomedir ());
|
|
#endif
|
|
if ((config = fopen (filename, "w")) == NULL)
|
|
return -1;
|
|
fprintf (config, "resolutionx=%d\n", gfx.res.x);
|
|
fprintf (config, "resolutiony=%d\n", gfx.res.y);
|
|
fprintf (config, "fullscreen=%d\n", gfx.fullscreen);
|
|
fprintf (config, "tileset=%s\n", map.tileset);
|
|
fprintf (config, "mapname=%s\n", map.map);
|
|
fprintf (config, "firewall=%d\n", bman.firewall);
|
|
fprintf (config, "udpport=%s\n", bman.port);
|
|
fprintf (config, "ai_players=%d\n", bman.ai_players);
|
|
fprintf (config, "fieldsizex=%d\n", map.size.x);
|
|
fprintf (config, "fieldsizey=%d\n", map.size.y);
|
|
fprintf (config, "notify=%d\n", bman.notifygamemaster);
|
|
fprintf (config, "ai_family=%d\n", bman.net_ai_family);
|
|
fprintf (config, "ogcserver=%s\n", bman.ogcserver);
|
|
fprintf (config, "ogc_port=%s\n", bman.ogc_port);
|
|
fprintf (config, "gamename=%s\n", bman.gamename);
|
|
fprintf (config, "gametimeout=%d\n", bman.init_timeout);
|
|
fprintf (config, "gametype=%d\n", bman.gametype);
|
|
fprintf (config, "maxplayer=%d\n", bman.maxplayer);
|
|
fprintf (config, "debug=%d\n", debug);
|
|
fprintf (config, "askplayername=%d\n", bman.askplayername);
|
|
fprintf (config, "playername=%s\n", bman.playername);
|
|
fprintf (config, "bitsperpixel=%d\n", gfx.bpp);
|
|
fprintf (config, "randomtileset=%d\n", map.random_tileset);
|
|
fprintf (config, "mapselection=%d\n", map.map_selection);
|
|
fprintf (config, "sndrate=%d\n", snd.audio_rate);
|
|
fprintf (config, "sndchannels=%d\n", snd.audio_channels);
|
|
fprintf (config, "sndformat=%d\n", snd.audio_format);
|
|
fprintf (config, "sndplaymusic=%d\n", snd.playmusic);
|
|
fprintf (config, "sndplaysound=%d\n", snd.playsound);
|
|
fprintf (config, "start_bombs=%d\n", bman.start_bombs);
|
|
fprintf (config, "start_range=%d\n", bman.start_range);
|
|
fprintf (config, "start_speed=%f\n", bman.start_speed);
|
|
fprintf (config, "bomb_ticking=%f\n", bman.bomb_tickingtime);
|
|
fprintf (config, "dropitemsondeath=%d\n", bman.dropitemsondeath);
|
|
fclose (config);
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
void
|
|
config_video ()
|
|
{
|
|
int done = 0,
|
|
menuselect,
|
|
x,
|
|
y;
|
|
_charlist screenres[] = {
|
|
{"640x480", NULL},
|
|
{"800x600", NULL},
|
|
{"1024x768", NULL},
|
|
{"1280x1024", NULL}
|
|
};
|
|
_charlist screenbpp[] = {
|
|
{"16", NULL},
|
|
{"24", NULL},
|
|
{"32", NULL}
|
|
};
|
|
_charlist *selres = NULL;
|
|
_charlist *selbpp = NULL;
|
|
char text[100];
|
|
|
|
/* set all pointers in this array */
|
|
charlist_fillarraypointer (screenres, 4);
|
|
charlist_fillarraypointer (screenbpp, 3);
|
|
|
|
/* select the current settings */
|
|
sprintf (text, "%dx%d", gfx.res.x, gfx.res.y);
|
|
selres = charlist_findtext (screenres, text);
|
|
sprintf (text, "%d", gfx.bpp);
|
|
selbpp = charlist_findtext (screenbpp, text);
|
|
|
|
while (!done && bman.state != GS_quit) {
|
|
menu_new ("Video Setup", 325, 300);
|
|
menu_create_label ("Resolution", 25, 70, 0, COLOR_brown);
|
|
menu_create_list ("res", 155, 55, 150, 70, screenres, &selres, 1);
|
|
menu_create_label ("Colors", 65, 160, 0, COLOR_brown);
|
|
menu_create_list ("bpp", 195, 145, 50, 55, screenbpp, &selbpp, 2);
|
|
menu_create_bool ("Fullscreen", -1, 210, 150, &gfx.fullscreen, 3);
|
|
menu_create_button ("OK", -1, 250, 100, 0);
|
|
menuselect = menu_loop ();
|
|
menu_delete ();
|
|
|
|
switch (menuselect) {
|
|
case (0):
|
|
done = 1;
|
|
gfx_shutdown ();
|
|
gfx_init ();
|
|
break;
|
|
case (1): // new resolution
|
|
gfx_shutdown ();
|
|
sscanf (selres->text, "%dx%d", &x, &y);
|
|
gfx.res.x = x;
|
|
gfx.res.y = y;
|
|
gfx_init ();
|
|
draw_logo ();
|
|
break;
|
|
case (2): // new color depth
|
|
gfx_shutdown ();
|
|
sscanf (selbpp->text, "%d", &x);
|
|
gfx.bpp = x;
|
|
gfx_init ();
|
|
draw_logo ();
|
|
break;
|
|
default:
|
|
done = 1;
|
|
break;
|
|
}
|
|
};
|
|
draw_logo ();
|
|
SDL_Flip (gfx.screen);
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Configuration Menu */
|
|
void
|
|
config_menu ()
|
|
{
|
|
int menuselect = 0;
|
|
|
|
while (menuselect != -1 && bman.state != GS_quit) {
|
|
menu_new ("Configuration", 400, 300);
|
|
menu_create_label ("General Option", -1, 50, 1, COLOR_brown);
|
|
menu_create_entry ("Name", -1, 85, 200, bman.playername, LEN_PLAYERNAME, MENU_entrytext, 1);
|
|
menu_create_button ("Video Setup", -1, 120, 200, 2);
|
|
menu_create_label ("Sound", 25, 154, 0, COLOR_brown);
|
|
menu_create_bool ("ON", 100, 150, 50, &snd.playsound, 3);
|
|
menu_create_label ("Music", 250, 154, 0, COLOR_brown);
|
|
menu_create_bool ("ON", 325, 150, 50, &snd.playmusic, 4);
|
|
menu_create_label ("Extended Option", -1, 200, 1, COLOR_brown);
|
|
menu_create_bool ("Debug", 25, 230, 150, &debug, 5);
|
|
menu_create_bool ("Ask Playername", 250, 230, 150, &bman.askplayername, 6);
|
|
menu_create_button ("Ok", -1, 270, 150, 0);
|
|
if (bman.playername[0] == '\0')
|
|
menu_focus_id (1);
|
|
else
|
|
menu_focus_id (0);
|
|
|
|
menu_reload ();
|
|
menuselect = menu_loop ();
|
|
|
|
menu_delete ();
|
|
switch (menuselect) {
|
|
case (0): // Back to the Main Menu
|
|
if (bman.playername[0] == '\0')
|
|
menuselect = 0;
|
|
else
|
|
menuselect = -1;
|
|
break;
|
|
case (2): // Screen Options
|
|
config_video ();
|
|
break;
|
|
}
|
|
}
|
|
config_write ();
|
|
};
|
|
|
|
|
|
/* Read Programm parameter */
|
|
void
|
|
ReadPrgArgs (int argc, char **argv)
|
|
{
|
|
int i = 0;
|
|
|
|
while (argv[++i] != NULL) {
|
|
if (!strcmp (argv[i], "-port"))
|
|
strncpy (bman.port, argv[++i], LEN_PORT);
|
|
if (!strcmp (argv[i], "-ogcport"))
|
|
strncpy (bman.ogc_port, argv[++i], LEN_PORT);
|
|
if (!strcmp (argv[i], "-firewall"))
|
|
bman.firewall = 1;
|
|
if (!strcmp (argv[i], "-name"))
|
|
strncpy (bman.playername, argv[++i], LEN_PLAYERNAME);
|
|
if (!strcmp (argv[i], "-help")) {
|
|
printf ("BomberClone Version " VERSION "\n");
|
|
printf (" WebPage : http://www.bomberclone.de\n");
|
|
printf (" Bug Report to :\n");
|
|
printf (" http://sourceforge.net/tracker/?group_id=79449&atid=556629\n");
|
|
printf (" Other Comments: steffen@bomberclone.de\n");
|
|
printf ("\nProgramm options:\n");
|
|
printf (" -name PLAYERNAME - set the Playername\n");
|
|
printf (" -port PORT - set the local BomberClone port (Def.: 11000)\n");
|
|
printf (" -ogcport PORT - set the local OGC Port (Def.: 11100)\n");
|
|
printf (" -ogc 0/1 - Enable/Disable OGC\n");
|
|
printf (" -firewall - Client is behind a firewall\n");
|
|
printf (" Only set this if you get some problems\n");
|
|
printf (" with network games.\n");
|
|
exit (0);
|
|
}
|
|
if (!strcmp (argv[i], "-ogc"))
|
|
bman.notifygamemaster = atoi (argv[++i]);
|
|
}
|
|
};
|