diff --git a/src/bomberclone.h b/src/bomberclone.h index 7979869..1ca0895 100644 --- a/src/bomberclone.h +++ b/src/bomberclone.h @@ -1,3 +1,4 @@ +/* $Id: bomberclone.h,v 1.7 2003/05/04 19:23:00 ob1kenewb Exp $ */ /* bomberclone.h */ #ifndef _BOMBERCLONE_H_ @@ -107,6 +108,7 @@ struct __bomberclone { int p_nr; // Playernumber 0 if you host a game or the number of the one you are. _field field[MAX_FIELDSIZE_X][MAX_FIELDSIZE_Y]; + char fieldpath[512]; // path of the field file int last_ex_nr; // number of the last explosion @@ -151,7 +153,7 @@ extern void game_set_playerposition(); // everything is declared in field.c extern void draw_field (); extern void draw_stone (int x, int y); -extern void field_new (); +extern void field_new (char *filename); // everything what is declared in players.c extern void dead_playerani (); diff --git a/src/configuration.c b/src/configuration.c index f4ff575..1227fef 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -46,6 +46,7 @@ game_init () bman.fieldsize.x = 25; bman.fieldsize.y = 17; sprintf (bman.datapath, "data/bomberclone.gfx"); + bman.fieldpath[0] = 0; }; int @@ -130,6 +131,15 @@ ReadConfig () if (!strcmp (keyword, "resolutiony")) { gfx.res.y = atoi (value); } + if (!strcmp (keyword, "fieldpath")) { + if (strlen (value) > 510) { + d_printf + ("*** Error - fieldpath too long (maximum size permitted is %d characters)!\n\n", + 510); + } + value[511] = 0; + strcpy(bman.fieldpath,value); + } if (!strcmp (keyword, "fieldsizex")) { bman.fieldsize.x = atoi (value); } @@ -184,6 +194,7 @@ WriteConfig () 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, "fieldpath=%s\n", bman.fieldpath); fprintf (config, "fieldsizex=%d\n", bman.fieldsize.x); fprintf (config, "fieldsizey=%d\n", bman.fieldsize.y); fprintf (config, "notify=%d\n", bman.notifygamemaster); @@ -197,7 +208,7 @@ WriteConfig () fprintf (config, "askplayername=%d\n", bman.askplayername); fprintf (config, "playername=%s\n", bman.playername); fprintf (config, "bitsperpixel=%d\n", gfx.bpp); - + fclose (config); return 0; } @@ -291,31 +302,35 @@ configuration () {1, "Video Options"}, {2, "Sound Options"}, {3, "Customize Keyboard"}, - {4, "Field Size X:"}, - {5, "Field Size Y:"}, - {6, "Prompt For Player Name"}, - {7, "Debug"}, - {8, "Save Config"}, - {9, "Return To Main Manu"}, + {4, "Field File:"}, + {5, "Field Size X:"}, + {6, "Field Size Y:"}, + {7, "Prompt For Player Name"}, + {8, "Debug"}, + {9, "Save Config"}, + {10, "Return To Main Manu"}, {-1, ""} }; while (menuselect != -1) { sprintf (menu[0].text, "Player Name: %s", bman.playername); - - sprintf (menu[4].text, "Field Size X: %d", bman.fieldsize.x); - sprintf (menu[5].text, "Field Size Y: %d", bman.fieldsize.y); + if(bman.fieldpath[0]) + sprintf (menu[4].text, "Field File: %s", bman.fieldpath); + else + sprintf (menu[4].text, "Field File: "); + sprintf (menu[5].text, "Field Size X: %d", bman.fieldsize.x); + sprintf (menu[6].text, "Field Size Y: %d", bman.fieldsize.y); if (debug == 1) - sprintf (menu[6].text, "Debug Messages ON"); + sprintf (menu[8].text, "Debug Messages ON"); else - sprintf (menu[6].text, "Debug Messages OFF"); + sprintf (menu[8].text, "Debug Messages OFF"); if (bman.askplayername == 1) - sprintf (menu[6].text, "Prompt For Name: Yes"); + sprintf (menu[7].text, "Prompt For Name: Yes"); else - sprintf (menu[6].text, "Prompt For Name: No"); + sprintf (menu[7].text, "Prompt For Name: No"); menuselect = menu_loop ("Configuration", menu, menuselect); @@ -331,35 +346,39 @@ configuration () case (2): // Sound Options case (3): // Customize Keyboard break; - case (4): // Change X Fieldsize - sprintf (menu[4].text, "%d", bman.fieldsize.x); + case (4): // Field File + menu_get_text ("Enter the path of a field file", bman.fieldpath, 30); + bman.fieldpath[511] = 0; + break; + case (5): // Change X Fieldsize + sprintf (menu[5].text, "%d", bman.fieldsize.x); sprintf (text, "Field Size X (%d - %d)", MIN_FIELDSIZE_X, MAX_FIELDSIZE_X); - menu_get_text (text, menu[4].text, 3); - bman.fieldsize.x = atoi (menu[4].text) | 1; + menu_get_text (text, menu[5].text, 3); + bman.fieldsize.x = atoi (menu[5].text) | 1; if (bman.fieldsize.x < MIN_FIELDSIZE_X) bman.fieldsize.x = MIN_FIELDSIZE_X; if (bman.fieldsize.x > MAX_FIELDSIZE_X) bman.fieldsize.x = MAX_FIELDSIZE_X; break; - case (5): // Change Y Fieldsize - sprintf (menu[5].text, "%d", bman.fieldsize.y); + case (6): // Change Y Fieldsize + sprintf (menu[6].text, "%d", bman.fieldsize.y); sprintf (text, "Field Size Y (%d - %d)", MIN_FIELDSIZE_Y, MAX_FIELDSIZE_Y); - menu_get_text (text, menu[5].text, 3); - bman.fieldsize.y = atoi (menu[5].text) | 1; + menu_get_text (text, menu[6].text, 3); + bman.fieldsize.y = atoi (menu[6].text) | 1; if (bman.fieldsize.y < MIN_FIELDSIZE_Y) bman.fieldsize.y = MIN_FIELDSIZE_Y; if (bman.fieldsize.y > MAX_FIELDSIZE_Y) bman.fieldsize.y = MAX_FIELDSIZE_Y; break; - case (6): // Debugging On / Off + case (7): // Debugging On / Off if (bman.askplayername == 1) bman.askplayername = 0; else bman.askplayername = 1; break; - case (7): // Debugging On / Off + case (8): // Debugging On / Off if (debug == 1) debug = 0; else { @@ -367,10 +386,10 @@ configuration () d_printf ("BomberClone ver.%s\n", VERSION); } break; - case (8): // Save Configuration + case (9): // Save Configuration WriteConfig (); break; - case (9): // Return to main menu + case (10): // Return to main menu menuselect = -1; break; } diff --git a/src/field.c b/src/field.c index 87c3cff..8fe5746 100644 --- a/src/field.c +++ b/src/field.c @@ -1,3 +1,4 @@ +/* $Id: field.c,v 1.4 2003/05/04 19:23:00 ob1kenewb Exp $ */ /* field.c - procedures which are needed to control the field */ #include @@ -78,17 +79,89 @@ draw_field () draw_stone (x, y); }; +/* read from an open file map, determine field.x and field.y + and fill the field. + (# correspond to a bloc and @ correspond to a stone, + an espace is nothing ' ' + % are commentary at the beginning of the map */ + +void field_load(FILE *map) +{ + size_t length; + char *currentline; + char tmp[MAX_FIELDSIZE_X]; + int sizex=0; + int sizey=0; + int i; + int d; + + while((currentline=fgets(&tmp,MAX_FIELDSIZE_X,map))) +/* fgetln is only implemented on *BSD */ +/* while((currentline=fgetln(map,&length))) */ + { + length=strlen(currentline); + if(currentline[0]=='%') + continue; + /* now each line correspond to the field */ + else + { + for(i=0;i @@ -179,7 +180,9 @@ menu_get_text (char *title, char *text, int len) SDL_Event event; Uint8 *keys; + text[len]=0; curpos = strlen (text); + if(curpos>=len) curpos=len-1; strcpy (t, text); if (len > strlen (title)) { len_ = len; diff --git a/src/network.c b/src/network.c index 7d34025..0e6123f 100644 --- a/src/network.c +++ b/src/network.c @@ -1,3 +1,4 @@ +/* $Id: network.c,v 1.10 2003/05/04 19:23:00 ob1kenewb Exp $ */ /* network routines. */ @@ -776,7 +777,7 @@ net_host_new_game () } } - field_new (); + field_new (bman.fieldpath); bman.players[bman.p_nr].state &= (0xFF - PSF_net); // we are the local player bman.last_ex_nr = 1; diff --git a/src/single.c b/src/single.c index 87dbb2b..b5cab8a 100644 --- a/src/single.c +++ b/src/single.c @@ -1,3 +1,4 @@ +/* $Id: single.c,v 1.3 2003/05/04 19:23:00 ob1kenewb Exp $ */ /* single player */ #include "basic.h" @@ -36,8 +37,7 @@ single_game_new (int ai_players) player_set_gfx (&bman.players[bman.p_nr], 0); bman.last_ex_nr = 1; - field_new (); - + field_new (bman.fieldpath); bman.players_nr_s = 1; bman.players_nr = 1; bman.gametype = GT_single;