| 1 | diff -purN bomberclone-0.11.8.orig/src/configuration.c bomberclone-0.11.8/src/configuration.c |
| 2 | --- bomberclone-0.11.8.orig/src/configuration.c 2010-01-21 19:34:52.000000000 +0100 |
| 3 | +++ bomberclone-0.11.8/src/configuration.c 2010-01-21 19:40:17.000000000 +0100 |
| 4 | @@ -545,6 +545,7 @@ config_video () |
| 5 | x, |
| 6 | y; |
| 7 | _charlist screenres[] = { |
| 8 | + {"320x240", NULL}, |
| 9 | {"640x480", NULL}, |
| 10 | {"800x600", NULL}, |
| 11 | {"1024x768", NULL}, |
| 12 | diff -purN bomberclone-0.11.8.orig/src/configuration.c~ bomberclone-0.11.8/src/configuration.c~ |
| 13 | --- bomberclone-0.11.8.orig/src/configuration.c~ 1970-01-01 01:00:00.000000000 +0100 |
| 14 | +++ bomberclone-0.11.8/src/configuration.c~ 2010-01-21 19:38:07.000000000 +0100 |
| 15 | @@ -0,0 +1,833 @@ |
| 16 | +/* $Id: configuration.c,v 1.82 2007/12/07 22:06:57 stpohle Exp $ |
| 17 | + * configuration */ |
| 18 | + |
| 19 | +#include <SDL.h> |
| 20 | + |
| 21 | +#include "basic.h" |
| 22 | +#include "bomberclone.h" |
| 23 | +#include "network.h" |
| 24 | +#include "packets.h" |
| 25 | +#include "gfx.h" |
| 26 | +#include "chat.h" |
| 27 | +#include "sound.h" |
| 28 | +#include "menu.h" |
| 29 | +#include "keyb.h" |
| 30 | +#include "player.h" |
| 31 | + |
| 32 | + |
| 33 | +/* |
| 34 | + * try to find the datapath and set the variable bman.datapath |
| 35 | + * test: 1) PACKAGE_DATA_DIR |
| 36 | + * 2) ./data |
| 37 | + * 3) ../data |
| 38 | + */ |
| 39 | +void |
| 40 | +config_get_datapath () |
| 41 | +{ |
| 42 | + FILE *f; |
| 43 | + char filename[255]; |
| 44 | + |
| 45 | + sprintf (bman.datapath, PACKAGE_DATA_DIR); |
| 46 | + sprintf (filename, "%s/gfx/logo.png", bman.datapath); |
| 47 | + f = fopen (filename, "r"); |
| 48 | + |
| 49 | + if (!f) { |
| 50 | + sprintf (bman.datapath, "data"); |
| 51 | + sprintf (filename, "%s/gfx/logo.png", bman.datapath); |
| 52 | + f = fopen (filename, "r"); |
| 53 | + if (!f) { |
| 54 | + sprintf (bman.datapath, "../data"); |
| 55 | + sprintf (filename, "%s/gfx/logo.png", bman.datapath); |
| 56 | + f = fopen (filename, "r"); |
| 57 | + if (!f) { |
| 58 | + printf ("Can't find Datafiles.\n"); |
| 59 | + exit (1); |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + fclose (f); |
| 64 | +} |
| 65 | + |
| 66 | + |
| 67 | +/* |
| 68 | + * reset all variables and load all configs. |
| 69 | + */ |
| 70 | +void |
| 71 | +config_init (int argc, char **argv) |
| 72 | +{ |
| 73 | + SDL_Surface *icon_img; |
| 74 | + char text[255], |
| 75 | + icon[255]; |
| 76 | + int i, |
| 77 | + j; |
| 78 | + |
| 79 | + config_get_datapath (); |
| 80 | + |
| 81 | + srand (((int) time (NULL))); // initialize randomgenerator |
| 82 | + |
| 83 | + for (i = 0; i < MAX_TEAMS; i++) { |
| 84 | + teams[i].col = i; |
| 85 | + sprintf (teams[i].name, "Team %d", i + 1); |
| 86 | + for (j = 0; j < MAX_PLAYERS; j++) |
| 87 | + teams[i].players[j] = NULL; |
| 88 | + } |
| 89 | + |
| 90 | + stonelist_del (); |
| 91 | + chat.oldscreen = NULL; |
| 92 | + chat.active = 0; |
| 93 | + chat.curline = 0; |
| 94 | + keyb_config_reset (); |
| 95 | + keybinput_new (&chat.input, KEYBI_text, 255); |
| 96 | + |
| 97 | + for (i = 0; i < CHAT_MAX_LINES; i++) |
| 98 | + chat.lines[i].text[0] = 0; |
| 99 | + |
| 100 | + bman.maxplayer = MAX_PLAYERS; |
| 101 | + bman.net_ai_family = PF_INET; |
| 102 | + bman.sock = -1; |
| 103 | + bman.p_nr = -1; |
| 104 | + bman.p2_nr = -1; |
| 105 | + bman.gamename[0] = 0; |
| 106 | + sprintf (bman.playername, "Player1"); |
| 107 | + sprintf (bman.player2name, "Player2"); |
| 108 | + sprintf (bman.port, "%d", DEFAULT_UDPPORT); |
| 109 | + sprintf (bman.ogcserver, DEFAULT_GAMECACHE); |
| 110 | + sprintf (bman.ogc_port, DEFAULT_GAMECACHEPORT); |
| 111 | + rscache.count = 0; |
| 112 | + bman.notifygamemaster = 1; |
| 113 | + bman.broadcast = 1; |
| 114 | + bman.autostart = AUTOSTART; |
| 115 | + bman.askplayername = 0; |
| 116 | + debug = 0; |
| 117 | + gfx.res.x = 640; |
| 118 | + gfx.res.y = 480; |
| 119 | + gfx.bpp = 16; |
| 120 | + gfx.players = NULL; |
| 121 | + bman.password[0] = 0; |
| 122 | + bman.passwordenabled = 0; |
| 123 | + map.tileset[0] = 0; |
| 124 | + map.random_tileset = 1; |
| 125 | + map.size.x = 25; |
| 126 | + map.size.y = 17; |
| 127 | + map.map[0] = 0; |
| 128 | + map.map_selection = 2; |
| 129 | + map.type = -1; |
| 130 | + bman.firewall = 0; |
| 131 | + bman.init_timeout = GAME_TIMEOUT; |
| 132 | + bman.ai_players = 1; |
| 133 | + bman.minplayers = 0; |
| 134 | + snd.inited = 0; |
| 135 | + snd.audio_rate = 22050; |
| 136 | + snd.audio_format = AUDIO_S16; |
| 137 | + snd.audio_channels = 2; |
| 138 | + snd.playmusic = 1; |
| 139 | + snd.playsound = 1; |
| 140 | + map.bombs = GAME_SPECIAL_ITEMBOMB; |
| 141 | + map.fire = GAME_SPECIAL_ITEMFIRE; |
| 142 | + map.shoes = GAME_SPECIAL_ITEMSHOE; |
| 143 | + map.mixed = GAME_SPECIAL_ITEMMIXED; |
| 144 | + map.death = GAME_SPECIAL_ITEMDEATH; |
| 145 | + map.sp_trigger = GAME_SPECIAL_ITEMSTRIGGER; |
| 146 | + map.sp_row = GAME_SPECIAL_ITEMSROW; |
| 147 | + map.sp_push = GAME_SPECIAL_ITEMSPUSH; |
| 148 | + map.sp_kick = GAME_SPECIAL_ITEMSKICK; |
| 149 | + |
| 150 | + bman.start_bombs = START_BOMBS; |
| 151 | + bman.start_speed = START_SPEED; |
| 152 | + bman.start_range = START_RANGE; |
| 153 | + bman.bomb_tickingtime = BOMB_TIMEOUT; |
| 154 | + bman.dropitemsondeath = 0; |
| 155 | + d_printf ("\n\n ***** Bomberclone Version %s \n\n", VERSION); |
| 156 | + config_read (); |
| 157 | + |
| 158 | + ReadPrgArgs (argc, argv); |
| 159 | + |
| 160 | + gfx_init (); |
| 161 | + draw_logo (); |
| 162 | + if (bman.askplayername) |
| 163 | + playernamemenu (); |
| 164 | + |
| 165 | + snd_init (); |
| 166 | + gfx_blitdraw (); |
| 167 | + |
| 168 | + SDL_Flip (gfx.screen); |
| 169 | + |
| 170 | + sprintf (text, "Bomberclone %s", VERSION); |
| 171 | + sprintf (icon, "%s/pixmaps/bomberclone.png", bman.datapath); |
| 172 | + SDL_WM_SetCaption (text, NULL); |
| 173 | + icon_img = IMG_Load (icon); |
| 174 | + if (icon_img == NULL) |
| 175 | + d_printf ("could not load icon. (%s)\n", icon); |
| 176 | + |
| 177 | +#ifdef _WIN32 |
| 178 | + { |
| 179 | + SDL_Surface *tmp = icon_img; |
| 180 | + icon_img = scale_image (tmp, 32, 32); |
| 181 | + SDL_FreeSurface (tmp); |
| 182 | + } |
| 183 | +#endif |
| 184 | + SDL_WM_SetIcon (icon_img, NULL); |
| 185 | + |
| 186 | + ReadPrgArgs_Jump (argc, argv); |
| 187 | +}; |
| 188 | + |
| 189 | + |
| 190 | +/* read the configuration file |
| 191 | + * return -1 if something went wrong and 0 if no problem */ |
| 192 | +int |
| 193 | +config_read () |
| 194 | +{ |
| 195 | + FILE *config; |
| 196 | + char buf[1024]; |
| 197 | + char *findit, |
| 198 | + *keyword, |
| 199 | + *value; |
| 200 | + int i; |
| 201 | + char filename[512]; |
| 202 | + |
| 203 | +#ifdef _WIN32 |
| 204 | + sprintf (filename, "%sbomberclone.cfg", s_gethomedir ()); |
| 205 | +#else |
| 206 | + sprintf (filename, "%s.bomberclone.cfg", s_gethomedir ()); |
| 207 | +#endif |
| 208 | + |
| 209 | + config = fopen (filename, "r"); |
| 210 | + if (config == NULL) { |
| 211 | + d_printf ("Error: Config file not found!\n"); |
| 212 | + return -1; |
| 213 | + } |
| 214 | + d_printf ("Reading Config-file: %s", filename); |
| 215 | + |
| 216 | + while (fgets (buf, sizeof (buf), config) != NULL) { |
| 217 | + findit = strchr (buf, '\n'); |
| 218 | + if (findit) |
| 219 | + findit[0] = '\0'; |
| 220 | + if (buf[0] == '\0') |
| 221 | + continue; |
| 222 | + |
| 223 | + keyword = buf; |
| 224 | + while (isspace (*keyword)) |
| 225 | + keyword++; |
| 226 | + |
| 227 | + value = strchr (buf, '='); |
| 228 | + if (value == NULL) |
| 229 | + continue; |
| 230 | + *value = 0; |
| 231 | + value++; |
| 232 | + while (*value == ' ') |
| 233 | + value++; |
| 234 | + while (keyword[strlen (keyword) - 1] == ' ') |
| 235 | + keyword[strlen (keyword) - 1] = 0; |
| 236 | + while (value[strlen (value) - 1] == ' ') |
| 237 | + value[strlen (value) - 1] = 0; |
| 238 | + if (strlen (value) == 0) |
| 239 | + continue; |
| 240 | + for (i = 0; i < (int) strlen (keyword); i++) |
| 241 | + keyword[i] = tolower (keyword[i]); |
| 242 | + |
| 243 | + if (!strcmp (keyword, "playername")) { |
| 244 | + if (strlen (value) > LEN_PLAYERNAME) { |
| 245 | + d_printf |
| 246 | + ("*** Error - playername too long (maximum size permitted is %d characters)!\n\n", |
| 247 | + LEN_PLAYERNAME); |
| 248 | + } |
| 249 | + value[LEN_PLAYERNAME - 1] = 0; |
| 250 | + strcpy (bman.playername, value); |
| 251 | + } |
| 252 | + |
| 253 | + if (!strcmp (keyword, "player2name")) { |
| 254 | + if (strlen (value) > LEN_PLAYERNAME) { |
| 255 | + d_printf |
| 256 | + ("*** Error - playername too long (maximum size permitted is %d characters)!\n\n", |
| 257 | + LEN_PLAYERNAME); |
| 258 | + } |
| 259 | + value[LEN_PLAYERNAME - 1] = 0; |
| 260 | + strcpy (bman.player2name, value); |
| 261 | + } |
| 262 | + |
| 263 | + if (!strcmp (keyword, "gamename")) { |
| 264 | + if (strlen (value) > LEN_GAMENAME) { |
| 265 | + d_printf |
| 266 | + ("*** Error - servername too long (maximum size permitted is %d characters)!\n\n", |
| 267 | + LEN_GAMENAME); |
| 268 | + } |
| 269 | + value[LEN_GAMENAME - 1] = 0; |
| 270 | + strcpy (bman.gamename, value); |
| 271 | + } |
| 272 | + if (!strcmp (keyword, "askplayername")) { |
| 273 | + bman.askplayername = atoi (value); |
| 274 | + } |
| 275 | + if (!strcmp (keyword, "password")) { |
| 276 | + if (strlen (value) > LEN_PASSWORD) { |
| 277 | + d_printf |
| 278 | + ("*** Error - Password is too long (maximum size permitted is %d characters)!\n\n", |
| 279 | + LEN_PASSWORD); |
| 280 | + } |
| 281 | + value[LEN_PASSWORD - 1] = 0; |
| 282 | + strcpy (bman.password, value); |
| 283 | + } |
| 284 | + if (!strcmp (keyword, "passwordenabled")) { |
| 285 | + bman.passwordenabled = atoi (value); |
| 286 | + } |
| 287 | + if (!strcmp (keyword, "resolutionx")) { |
| 288 | + gfx.res.x = atoi (value); |
| 289 | + } |
| 290 | + if (!strcmp (keyword, "resolutiony")) { |
| 291 | + gfx.res.y = atoi (value); |
| 292 | + } |
| 293 | + if (!strcmp (keyword, "tileset")) { |
| 294 | + strcpy (map.tileset, value); |
| 295 | + } |
| 296 | + if (!strcmp (keyword, "mapname")) { |
| 297 | + if (strlen (value) > LEN_PATHFILENAME) { |
| 298 | + d_printf |
| 299 | + ("*** Error - fieldpath too long (maximum size permitted is %d characters)!\n\n", |
| 300 | + LEN_PATHFILENAME); |
| 301 | + } |
| 302 | + value[511] = 0; |
| 303 | + strcpy (map.map, value); |
| 304 | + } |
| 305 | + if (!strcmp (keyword, "udpport")) { |
| 306 | + if (strlen (value) > LEN_PORT) { |
| 307 | + d_printf |
| 308 | + ("*** Error - servername too long (maximum size permitted is %d characters)!\n\n", |
| 309 | + LEN_PORT); |
| 310 | + } |
| 311 | + value[LEN_PORT - 1] = 0; |
| 312 | + strcpy (bman.port, value); |
| 313 | + } |
| 314 | + if (!strcmp (keyword, "ai_players")) { |
| 315 | + bman.ai_players = atoi (value); |
| 316 | + } |
| 317 | + if (!strcmp (keyword, "fieldsizex")) { |
| 318 | + map.size.x = atoi (value); |
| 319 | + } |
| 320 | + if (!strcmp (keyword, "fieldsizey")) { |
| 321 | + map.size.y = atoi (value); |
| 322 | + } |
| 323 | + if (!strcmp (keyword, "fullscreen")) { |
| 324 | + gfx.fullscreen = atoi (value); |
| 325 | + } |
| 326 | + if (!strcmp (keyword, "bitsperpixel")) { |
| 327 | + gfx.bpp = atoi (value); |
| 328 | + } |
| 329 | + if (!strcmp (keyword, "ai_family")) { |
| 330 | + bman.net_ai_family = atoi (value); |
| 331 | + } |
| 332 | + if (!strcmp (keyword, "debug")) { |
| 333 | + debug = atoi (value); |
| 334 | + } |
| 335 | + if (!strcmp (keyword, "notify")) { |
| 336 | + bman.notifygamemaster = atoi (value); |
| 337 | + } |
| 338 | + if (!strcmp (keyword, "broadcast")) { |
| 339 | + bman.broadcast = atoi (value); |
| 340 | + } |
| 341 | + if (!strcmp (keyword, "ogcserver")) { |
| 342 | + strcpy (bman.ogcserver, value); |
| 343 | + } |
| 344 | + if (!strcmp (keyword, "ogc_port")) { |
| 345 | + strcpy (bman.ogc_port, value); |
| 346 | + } |
| 347 | + if (!strcmp (keyword, "maxplayer")) { |
| 348 | + bman.maxplayer = atoi (value); |
| 349 | + } |
| 350 | + if (!strcmp (keyword, "mapselection")) { |
| 351 | + map.map_selection = atoi (value); |
| 352 | + } |
| 353 | + if (!strcmp (keyword, "randomtileset")) { |
| 354 | + map.random_tileset = atoi (value); |
| 355 | + } |
| 356 | + if (!strcmp (keyword, "gametimeout")) { |
| 357 | + bman.init_timeout = atoi (value); |
| 358 | + } |
| 359 | + if (!strcmp (keyword, "gametype")) { |
| 360 | + bman.gametype = atoi (value); |
| 361 | + } |
| 362 | + if (!strcmp (keyword, "sndrate")) { |
| 363 | + snd.audio_rate = atoi (value); |
| 364 | + } |
| 365 | + if (!strcmp (keyword, "sndchannels")) { |
| 366 | + snd.audio_channels = atoi (value); |
| 367 | + } |
| 368 | + if (!strcmp (keyword, "sndformat")) { |
| 369 | + snd.audio_format = atoi (value); |
| 370 | + } |
| 371 | + if (!strcmp (keyword, "sndplaymusic")) { |
| 372 | + snd.playmusic = atoi (value); |
| 373 | + } |
| 374 | + if (!strcmp (keyword, "sndplaysound")) { |
| 375 | + snd.playsound = atoi (value); |
| 376 | + } |
| 377 | + if (!strcmp (keyword, "start_bombs")) { |
| 378 | + bman.start_bombs = atoi (value); |
| 379 | + } |
| 380 | + if (!strcmp (keyword, "start_range")) { |
| 381 | + bman.start_range = atoi (value); |
| 382 | + } |
| 383 | + if (!strcmp (keyword, "start_speed")) { |
| 384 | + sscanf (value, "%f", &bman.start_speed); |
| 385 | + } |
| 386 | + if (!strcmp (keyword, "special_trigger")) { |
| 387 | + sscanf (value, "%d", &map.sp_trigger); |
| 388 | + } |
| 389 | + if (!strcmp (keyword, "special_row")) { |
| 390 | + sscanf (value, "%d", &map.sp_row); |
| 391 | + } |
| 392 | + if (!strcmp (keyword, "special_push")) { |
| 393 | + sscanf (value, "%d", &map.sp_push); |
| 394 | + } |
| 395 | + if (!strcmp (keyword, "special_kick")) { |
| 396 | + sscanf (value, "%d", &map.sp_kick); |
| 397 | + } |
| 398 | + if (!strcmp (keyword, "bomb_ticking")) { |
| 399 | + sscanf (value, "%f", &bman.bomb_tickingtime); |
| 400 | + } |
| 401 | + if (!strcmp (keyword, "dropitemsondeath")) { |
| 402 | + bman.dropitemsondeath = atoi (value); |
| 403 | + } |
| 404 | + |
| 405 | + for (i = 0; i < MAX_TEAMS; i++) { |
| 406 | + char txt[255]; |
| 407 | + sprintf (txt, "teamcol%d", i); |
| 408 | + if (!strcmp (keyword, txt)) { |
| 409 | + teams[i].col = atoi (value); |
| 410 | + } |
| 411 | + sprintf (txt, "teamname%d", i); |
| 412 | + if (!strcmp (keyword, txt)) { |
| 413 | + strncpy (teams[i].name, value, LEN_PLAYERNAME); |
| 414 | + } |
| 415 | + } |
| 416 | + |
| 417 | + /* |
| 418 | + * keyboard config, i will give names to the keys insteed of the numbers, |
| 419 | + * this is done to add more keys to the game without destroying the config. |
| 420 | + */ |
| 421 | + if (!strcmp (keyword, "key_p1_up")) |
| 422 | + keyb_gamekeys.keycode[BCPK_up] = atoi (value); |
| 423 | + if (!strcmp (keyword, "key_p1_down")) |
| 424 | + keyb_gamekeys.keycode[BCPK_down] = atoi (value); |
| 425 | + if (!strcmp (keyword, "key_p1_left")) |
| 426 | + keyb_gamekeys.keycode[BCPK_left] = atoi (value); |
| 427 | + if (!strcmp (keyword, "key_p1_right")) |
| 428 | + keyb_gamekeys.keycode[BCPK_right] = atoi (value); |
| 429 | + if (!strcmp (keyword, "key_p1_bomb")) |
| 430 | + keyb_gamekeys.keycode[BCPK_drop] = atoi (value); |
| 431 | + if (!strcmp (keyword, "key_p1_special")) |
| 432 | + keyb_gamekeys.keycode[BCPK_special] = atoi (value); |
| 433 | + |
| 434 | + if (!strcmp (keyword, "key_p2_up")) |
| 435 | + keyb_gamekeys.keycode[BCPK_max + BCPK_up] = atoi (value); |
| 436 | + if (!strcmp (keyword, "key_p2_down")) |
| 437 | + keyb_gamekeys.keycode[BCPK_max + BCPK_down] = atoi (value); |
| 438 | + if (!strcmp (keyword, "key_p2_left")) |
| 439 | + keyb_gamekeys.keycode[BCPK_max + BCPK_left] = atoi (value); |
| 440 | + if (!strcmp (keyword, "key_p2_right")) |
| 441 | + keyb_gamekeys.keycode[BCPK_max + BCPK_right] = atoi (value); |
| 442 | + if (!strcmp (keyword, "key_p2_bomb")) |
| 443 | + keyb_gamekeys.keycode[BCPK_max + BCPK_drop] = atoi (value); |
| 444 | + if (!strcmp (keyword, "key_p2_special")) |
| 445 | + keyb_gamekeys.keycode[BCPK_max + BCPK_special] = atoi (value); |
| 446 | + |
| 447 | + if (!strcmp (keyword, "key_help")) |
| 448 | + keyb_gamekeys.keycode[BCK_help] = atoi (value); |
| 449 | + if (!strcmp (keyword, "key_playermenu")) |
| 450 | + keyb_gamekeys.keycode[BCK_playermenu] = atoi (value); |
| 451 | + if (!strcmp (keyword, "key_mapmenu")) |
| 452 | + keyb_gamekeys.keycode[BCK_mapmenu] = atoi (value); |
| 453 | + if (!strcmp (keyword, "key_chat")) |
| 454 | + keyb_gamekeys.keycode[BCK_chat] = atoi (value); |
| 455 | + if (!strcmp (keyword, "key_pause")) |
| 456 | + keyb_gamekeys.keycode[BCK_pause] = atoi (value); |
| 457 | + if (!strcmp (keyword, "key_fullscreen")) |
| 458 | + keyb_gamekeys.keycode[BCK_fullscreen] = atoi (value); |
| 459 | + } |
| 460 | + fclose (config); |
| 461 | + return 0; |
| 462 | +}; |
| 463 | + |
| 464 | + |
| 465 | +int |
| 466 | +config_write () |
| 467 | +{ |
| 468 | + FILE *config; |
| 469 | + int i; |
| 470 | + char filename[512]; |
| 471 | + |
| 472 | +#ifdef _WIN32 |
| 473 | + sprintf (filename, "%sbomberclone.cfg", s_gethomedir ()); |
| 474 | +#else |
| 475 | + sprintf (filename, "%s.bomberclone.cfg", s_gethomedir ()); |
| 476 | +#endif |
| 477 | + if ((config = fopen (filename, "w")) == NULL) |
| 478 | + return -1; |
| 479 | + fprintf (config, "resolutionx=%d\n", gfx.res.x); |
| 480 | + fprintf (config, "resolutiony=%d\n", gfx.res.y); |
| 481 | + fprintf (config, "fullscreen=%d\n", gfx.fullscreen); |
| 482 | + fprintf (config, "tileset=%s\n", map.tileset); |
| 483 | + fprintf (config, "mapname=%s\n", map.map); |
| 484 | + fprintf (config, "udpport=%s\n", bman.port); |
| 485 | + fprintf (config, "ai_players=%d\n", bman.ai_players); |
| 486 | + fprintf (config, "fieldsizex=%d\n", map.size.x); |
| 487 | + fprintf (config, "fieldsizey=%d\n", map.size.y); |
| 488 | + fprintf (config, "notify=%d\n", bman.notifygamemaster); |
| 489 | + fprintf (config, "broadcast=%d\n", bman.broadcast); |
| 490 | + fprintf (config, "ai_family=%d\n", bman.net_ai_family); |
| 491 | + fprintf (config, "ogcserver=%s\n", bman.ogcserver); |
| 492 | + fprintf (config, "ogc_port=%s\n", bman.ogc_port); |
| 493 | + fprintf (config, "gamename=%s\n", bman.gamename); |
| 494 | + fprintf (config, "gametimeout=%d\n", bman.init_timeout); |
| 495 | + fprintf (config, "gametype=%d\n", bman.gametype); |
| 496 | + fprintf (config, "maxplayer=%d\n", bman.maxplayer); |
| 497 | + fprintf (config, "debug=%d\n", debug); |
| 498 | + fprintf (config, "password=%s\n", bman.password); |
| 499 | + fprintf (config, "passwordenabled=%d\n", bman.passwordenabled); |
| 500 | + fprintf (config, "askplayername=%d\n", bman.askplayername); |
| 501 | + fprintf (config, "playername=%s\n", bman.playername); |
| 502 | + fprintf (config, "player2name=%s\n", bman.player2name); |
| 503 | + fprintf (config, "bitsperpixel=%d\n", gfx.bpp); |
| 504 | + fprintf (config, "randomtileset=%d\n", map.random_tileset); |
| 505 | + fprintf (config, "mapselection=%d\n", map.map_selection); |
| 506 | + fprintf (config, "sndrate=%d\n", snd.audio_rate); |
| 507 | + fprintf (config, "sndchannels=%d\n", snd.audio_channels); |
| 508 | + fprintf (config, "sndformat=%d\n", snd.audio_format); |
| 509 | + fprintf (config, "sndplaymusic=%d\n", snd.playmusic); |
| 510 | + fprintf (config, "sndplaysound=%d\n", snd.playsound); |
| 511 | + fprintf (config, "start_bombs=%d\n", bman.start_bombs); |
| 512 | + fprintf (config, "start_range=%d\n", bman.start_range); |
| 513 | + fprintf (config, "start_speed=%f\n", bman.start_speed); |
| 514 | + fprintf (config, "special_trigger=%d\n", map.sp_trigger); |
| 515 | + fprintf (config, "special_row=%d\n", map.sp_row); |
| 516 | + fprintf (config, "special_push=%d\n", map.sp_push); |
| 517 | + fprintf (config, "special_kick=%d\n", map.sp_kick); |
| 518 | + |
| 519 | + fprintf (config, "bomb_ticking=%f\n", bman.bomb_tickingtime); |
| 520 | + fprintf (config, "dropitemsondeath=%d\n",bman.dropitemsondeath); |
| 521 | + |
| 522 | + for (i = 0; i < MAX_TEAMS; i++) { |
| 523 | + fprintf (config, "teamcol%d=%d\n", i, teams[i].col); |
| 524 | + fprintf (config, "teamname%d=%s\n", i, teams[i].name); |
| 525 | + } |
| 526 | + |
| 527 | + /* |
| 528 | + * keyboard config |
| 529 | + */ |
| 530 | + fprintf (config, "key_p1_up=%d\n", keyb_gamekeys.keycode[BCPK_up]); |
| 531 | + fprintf (config, "key_p1_down=%d\n", keyb_gamekeys.keycode[BCPK_down]); |
| 532 | + fprintf (config, "key_p1_left=%d\n", keyb_gamekeys.keycode[BCPK_left]); |
| 533 | + fprintf (config, "key_p1_right=%d\n", keyb_gamekeys.keycode[BCPK_right]); |
| 534 | + fprintf (config, "key_p1_bomb=%d\n", keyb_gamekeys.keycode[BCPK_drop]); |
| 535 | + fprintf (config, "key_p1_special=%d\n", keyb_gamekeys.keycode[BCPK_special]); |
| 536 | + fprintf (config, "key_p2_up=%d\n", keyb_gamekeys.keycode[BCPK_max + BCPK_up]); |
| 537 | + fprintf (config, "key_p2_down=%d\n", keyb_gamekeys.keycode[BCPK_max + BCPK_down]); |
| 538 | + fprintf (config, "key_p2_left=%d\n", keyb_gamekeys.keycode[BCPK_max + BCPK_left]); |
| 539 | + fprintf (config, "key_p2_right=%d\n", keyb_gamekeys.keycode[BCPK_max + BCPK_right]); |
| 540 | + fprintf (config, "key_p2_bomb=%d\n", keyb_gamekeys.keycode[BCPK_max + BCPK_drop]); |
| 541 | + fprintf (config, "key_p2_special=%d\n", keyb_gamekeys.keycode[BCPK_max + BCPK_special]); |
| 542 | + fprintf (config, "key_help=%d\n", keyb_gamekeys.keycode[BCK_help]); |
| 543 | + fprintf (config, "key_fullscreen=%d\n", keyb_gamekeys.keycode[BCK_fullscreen]); |
| 544 | + fprintf (config, "key_chat=%d\n", keyb_gamekeys.keycode[BCK_chat]); |
| 545 | + fprintf (config, "key_mapmenu=%d\n", keyb_gamekeys.keycode[BCK_mapmenu]); |
| 546 | + fprintf (config, "key_pause=%d\n", keyb_gamekeys.keycode[BCK_pause]); |
| 547 | + fprintf (config, "key_playermenu=%d\n", keyb_gamekeys.keycode[BCK_playermenu]); |
| 548 | + |
| 549 | + fclose (config); |
| 550 | + return 0; |
| 551 | +} |
| 552 | + |
| 553 | + |
| 554 | + |
| 555 | +void |
| 556 | +config_video () |
| 557 | +{ |
| 558 | + int done = 0, |
| 559 | + menuselect, |
| 560 | + x, |
| 561 | + y; |
| 562 | + _charlist screenres[] = { |
| 563 | + {"320x240", NULL |
| 564 | + {"640x480", NULL}, |
| 565 | + {"800x600", NULL}, |
| 566 | + {"1024x768", NULL}, |
| 567 | + {"1280x1024", NULL}, |
| 568 | + {"1600x1200", NULL}, |
| 569 | + {"1920x1080", NULL}, |
| 570 | + {"1920x1200", NULL}, |
| 571 | + {"1280x800", NULL} |
| 572 | + }; |
| 573 | + _charlist screenbpp[] = { |
| 574 | + {"16", NULL}, |
| 575 | + {"24", NULL}, |
| 576 | + {"32", NULL} |
| 577 | + }; |
| 578 | + _charlist *selres = NULL; |
| 579 | + _charlist *selbpp = NULL; |
| 580 | + char text[100]; |
| 581 | + |
| 582 | + _menu *menu; |
| 583 | + |
| 584 | + /* set all pointers in this array */ |
| 585 | + charlist_fillarraypointer (screenres, 6); |
| 586 | + charlist_fillarraypointer (screenbpp, 3); |
| 587 | + |
| 588 | + /* select the current settings */ |
| 589 | + sprintf (text, "%dx%d", gfx.res.x, gfx.res.y); |
| 590 | + selres = charlist_findtext (screenres, text); |
| 591 | + sprintf (text, "%d", gfx.bpp); |
| 592 | + selbpp = charlist_findtext (screenbpp, text); |
| 593 | + |
| 594 | + while (!done && bman.state != GS_quit) { |
| 595 | + menu = menu_new ("Video Setup", 325, 300); |
| 596 | + menu_create_label (menu, "Resolution", 25, 70, 0, COLOR_brown); |
| 597 | + menu_create_list (menu, "res", 155, 55, 150, 85, screenres, &selres, 1); |
| 598 | + menu_create_label (menu, "Colors", 65, 170, 0, COLOR_brown); |
| 599 | + menu_create_list (menu, "bpp", 195, 155, 50, 55, screenbpp, &selbpp, 2); |
| 600 | + menu_create_bool (menu, "Fullscreen", -1, 220, 150, &gfx.fullscreen, 3); |
| 601 | + menu_create_button (menu, "OK", -1, 260, 100, 0); |
| 602 | + menuselect = menu_loop (menu); |
| 603 | + menu_delete (menu); |
| 604 | + |
| 605 | + switch (menuselect) { |
| 606 | + case (0): |
| 607 | + done = 1; |
| 608 | + gfx_shutdown (); |
| 609 | + gfx_init (); |
| 610 | + break; |
| 611 | + case (1): // new resolution |
| 612 | + gfx_shutdown (); |
| 613 | + sscanf (selres->text, "%dx%d", &x, &y); |
| 614 | + gfx.res.x = x; |
| 615 | + gfx.res.y = y; |
| 616 | + gfx_init (); |
| 617 | + draw_logo (); |
| 618 | + break; |
| 619 | + case (2): // new color depth |
| 620 | + gfx_shutdown (); |
| 621 | + sscanf (selbpp->text, "%d", &x); |
| 622 | + gfx.bpp = x; |
| 623 | + gfx_init (); |
| 624 | + draw_logo (); |
| 625 | + break; |
| 626 | + default: |
| 627 | + done = 1; |
| 628 | + break; |
| 629 | + } |
| 630 | + }; |
| 631 | + draw_logo (); |
| 632 | + SDL_Flip (gfx.screen); |
| 633 | +}; |
| 634 | + |
| 635 | + |
| 636 | + |
| 637 | + |
| 638 | + |
| 639 | +/* Configuration Menu */ |
| 640 | +void |
| 641 | +config_menu () |
| 642 | +{ |
| 643 | + int menuselect = 0; |
| 644 | + _menu *menu; |
| 645 | + |
| 646 | + while (menuselect != -1 && bman.state != GS_quit) { |
| 647 | + menu = menu_new ("Configuration", 400, 300); |
| 648 | + menu_create_label (menu, "General Option", -1, 50, 1, COLOR_brown); |
| 649 | + menu_create_button (menu, "Playernames", 25, 85, 150, 1); |
| 650 | + menu_create_button (menu, "Keyboard", 225, 85, 150, 2); |
| 651 | + menu_create_button (menu, "Video Setup", -1, 120, 200, 3); |
| 652 | + menu_create_label (menu, "Sound", 25, 154, 0, COLOR_brown); |
| 653 | + menu_create_bool (menu, "ON", 100, 150, 50, &snd.playsound, 4); |
| 654 | + menu_create_label (menu, "Music", 250, 154, 0, COLOR_brown); |
| 655 | + menu_create_bool (menu, "ON", 325, 150, 50, &snd.playmusic, 5); |
| 656 | + menu_create_label (menu, "Extended Option", -1, 200, 1, COLOR_brown); |
| 657 | + menu_create_bool (menu, "Debug", 25, 230, 150, &debug, 6); |
| 658 | + menu_create_bool (menu, "Ask Playername", 250, 230, 150, &bman.askplayername, 7); |
| 659 | + menu_create_button (menu, "Ok", -1, 270, 150, 0); |
| 660 | + if (bman.playername[0] == '\0') |
| 661 | + menu_focus_id (menu, 1); |
| 662 | + else |
| 663 | + menu_focus_id (menu, 0); |
| 664 | + |
| 665 | + menu_reload (menu); |
| 666 | + menuselect = menu_loop (menu); |
| 667 | + |
| 668 | + menu_delete (menu); |
| 669 | + switch (menuselect) { |
| 670 | + case (0): // Back to the Main Menu |
| 671 | + if (bman.playername[0] == '\0') |
| 672 | + menuselect = 0; |
| 673 | + else |
| 674 | + menuselect = -1; |
| 675 | + break; |
| 676 | + case (1): // player screen |
| 677 | + playernamemenu (); |
| 678 | + break; |
| 679 | + case (2): // keyboard settings |
| 680 | + keyb_config (); |
| 681 | + break; |
| 682 | + case (3): // Screen Options |
| 683 | + config_video (); |
| 684 | + break; |
| 685 | + } |
| 686 | + } |
| 687 | + config_write (); |
| 688 | +}; |
| 689 | + |
| 690 | + |
| 691 | +/* Read Programm parameter */ |
| 692 | +void |
| 693 | +ReadPrgArgs (int argc, char **argv) |
| 694 | +{ |
| 695 | + int i = 0; |
| 696 | + char s; |
| 697 | + while (argv[++i] != NULL) { |
| 698 | + if (!strcmp (argv[i], "-h")||!strcmp (argv[i], "-help")||!strcmp (argv[i], "--help")) { |
| 699 | + printf ("BomberClone Version " VERSION "\n"); |
| 700 | + printf (" WebPage : http://www.bomberclone.de\n"); |
| 701 | + printf (" Bug Report to :\n"); |
| 702 | + printf (" http://sourceforge.net/tracker/?group_id=79449&atid=556629\n"); |
| 703 | + printf (" Other Comments: steffen@bomberclone.de\n"); |
| 704 | + printf ("\nProgramm options:\n"); |
| 705 | + printf (" -name PLAYERNAME - set the Playername\n"); |
| 706 | + printf (" -name2 PLAYERNAME - set the Playername for the second player\n"); |
| 707 | + printf (" -gamename GAMENAME - set the name of the game\n"); |
| 708 | + printf (" -port PORT - set the local BomberClone port\n"); |
| 709 | + printf (" (Def.: 11000)\n"); |
| 710 | + printf (" -ogcport PORT - set the local OGC Port (Def.: 11100)\n"); |
| 711 | + printf (" -ogc 0/1 - Enable/Disable OGC\n"); |
| 712 | + printf (" -broadcast 0/1 - Enable/Disable broadcast requests.\n"); |
| 713 | + printf (" -host - start a network game\n"); |
| 714 | + printf (" -join - go into the join menu\n"); |
| 715 | + printf (" -connect ADDRESS - connect to a server\n"); |
| 716 | + printf (" -debug 0/1 - enable/disable debug\n"); |
| 717 | + printf (" -autostart SECONDS - time before a game starts\n"); |
| 718 | + exit (0); |
| 719 | + } |
| 720 | + } |
| 721 | + i=0; |
| 722 | + while (argv[++i] != NULL) { |
| 723 | + if (argv[i][0]=='-') { |
| 724 | + if (argv[i+1] != NULL) |
| 725 | + s=argv[i+1][0]; |
| 726 | + else |
| 727 | + s='-'; |
| 728 | + if (!strcmp (argv[i], "-port")) { |
| 729 | + if (s!='-') |
| 730 | + strncpy (bman.port, argv[++i], LEN_PORT); |
| 731 | + else { |
| 732 | + printf("Error: Parameter required for -port\n"); |
| 733 | + exit(1); |
| 734 | + } |
| 735 | + } |
| 736 | + if (!strcmp (argv[i], "-ogcport")) { |
| 737 | + if (s!='-') |
| 738 | + strncpy (bman.ogc_port, argv[++i], LEN_PORT); |
| 739 | + else { |
| 740 | + printf("Error: Parameter required for -ogcport\n"); |
| 741 | + exit(1); |
| 742 | + } |
| 743 | + } |
| 744 | + if (!strcmp (argv[i], "-name")) { |
| 745 | + if (s!='-') |
| 746 | + strncpy (bman.playername, argv[++i], LEN_PLAYERNAME); |
| 747 | + else { |
| 748 | + printf("Error: Parameter required for -name\n"); |
| 749 | + exit(1); |
| 750 | + } |
| 751 | + } |
| 752 | + if (!strcmp (argv[i], "-name2")) { |
| 753 | + if (s!='-') |
| 754 | + strncpy (bman.player2name, argv[++i], LEN_PLAYERNAME); |
| 755 | + else { |
| 756 | + printf("Error: Parameter required for -name2\n"); |
| 757 | + exit(1); |
| 758 | + } |
| 759 | + } |
| 760 | + if (!strcmp (argv[i], "-gamename")) { |
| 761 | + if (s!='-') |
| 762 | + strncpy (bman.gamename, argv[++i], LEN_GAMENAME); |
| 763 | + else { |
| 764 | + printf("Error: Parameter required for -gamename\n"); |
| 765 | + exit(1); |
| 766 | + } |
| 767 | + } |
| 768 | + if (!strcmp (argv[i], "-autostart")) { |
| 769 | + if (s!='-') |
| 770 | + bman.autostart = atoi (argv[++i]); |
| 771 | + else { |
| 772 | + printf("Error: Parameter required for -autostart\n"); |
| 773 | + exit(1); |
| 774 | + } |
| 775 | + } |
| 776 | + if (!strcmp (argv[i], "-ogc")) { |
| 777 | + if (s!='-') |
| 778 | + bman.notifygamemaster = atoi (argv[++i]); |
| 779 | + else |
| 780 | + bman.notifygamemaster = 1; |
| 781 | + } |
| 782 | + if (!strcmp (argv[i], "-broadcast")) { |
| 783 | + if (s!='-') |
| 784 | + bman.broadcast = atoi (argv[++i]); |
| 785 | + else |
| 786 | + bman.broadcast = 1; |
| 787 | + } |
| 788 | + if (!strcmp (argv[i], "-debug")) { |
| 789 | + if (s!='-') |
| 790 | + debug = atoi (argv[++i]); |
| 791 | + else |
| 792 | + debug = 1; |
| 793 | + } |
| 794 | + } |
| 795 | + } |
| 796 | +}; |
| 797 | + |
| 798 | + |
| 799 | + |
| 800 | +/* Read Programm Parameter which will drop us in a special menu */ |
| 801 | +void |
| 802 | +ReadPrgArgs_Jump (int argc, char **argv) |
| 803 | +{ |
| 804 | + int i = 0; |
| 805 | + |
| 806 | + while (argv[++i] != NULL) { |
| 807 | + /* check for commands which will put us into a certain menu */ |
| 808 | + if (!strcmp (argv[i], "-host")) { |
| 809 | + host_multiplayer_game (); |
| 810 | + } |
| 811 | + else if (!strcmp (argv[i], "-join")) { |
| 812 | + join_multiplayer_game (); |
| 813 | + } |
| 814 | + else if (!strcmp (argv[i], "-connect")) { |
| 815 | + strncpy (bman.servername, argv[++i], LEN_SERVERNAME + LEN_PORT + 2); |
| 816 | + join_multiplayer_game (); |
| 817 | + } |
| 818 | + } |
| 819 | +}; |
| 820 | + |
| 821 | + |
| 822 | +/* check the version number, return [ 0 =] [-1 <] [ 1 >] */ |
| 823 | +int |
| 824 | +check_version (int ma, int mi, int su, char *ver) |
| 825 | +{ |
| 826 | + int v1, |
| 827 | + v2, |
| 828 | + v3, |
| 829 | + res = 0; |
| 830 | + |
| 831 | + sscanf (ver, "%d.%d.%d", &v1, &v2, &v3); |
| 832 | + if (v1 < ma) |
| 833 | + res = -1; |
| 834 | + else if (v1 > ma) |
| 835 | + res = 1; |
| 836 | + else if (v2 < mi) |
| 837 | + res = -1; |
| 838 | + else if (v2 > mi) |
| 839 | + res = 1; |
| 840 | + else if (v3 < su) |
| 841 | + res = -1; |
| 842 | + else if (v3 > su) |
| 843 | + res = 1; |
| 844 | + |
| 845 | + // d_printf ("version_check (%d.%d.%d, %s = %d\n" , ma, mi, su, ver, res); |
| 846 | + |
| 847 | + return res; |
| 848 | +}; |