diff --git a/ChangeLog b/ChangeLog index 82f0898..793ed4b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ +- Added: loadable maps. (ob1kenewb) + - Changed: now the send packet option will be set for every player directly, so if a slow player joinsit should not anymore slow down the whole network game. @@ -7,7 +9,7 @@ Player Selection screen. - Fixed/Add: first support for international keyboards, so the - shift key should work. (more or less) thx. to: ob1kenewb + shift key will work. thanks to (ob1kenewb) ! - Fixed: SuSe could not compile the game right. #include was needed. not only diff --git a/src/bomberclone.h b/src/bomberclone.h index 1ca0895..cbfcc06 100644 --- a/src/bomberclone.h +++ b/src/bomberclone.h @@ -1,4 +1,4 @@ -/* $Id: bomberclone.h,v 1.7 2003/05/04 19:23:00 ob1kenewb Exp $ */ +/* $Id: bomberclone.h,v 1.8 2003/05/05 04:14:55 stpohle Exp $ */ /* bomberclone.h */ #ifndef _BOMBERCLONE_H_ @@ -154,6 +154,7 @@ extern void game_set_playerposition(); extern void draw_field (); extern void draw_stone (int x, int y); extern void field_new (char *filename); +extern void field_set_playerposition (int usermap); // everything what is declared in players.c extern void dead_playerani (); diff --git a/src/chat.h b/src/chat.h index f3f3b14..6c0335e 100644 --- a/src/chat.h +++ b/src/chat.h @@ -24,5 +24,6 @@ extern _chat chat; extern void chat_show (int x1, int y1, int x2, int y2); extern void chat_addline (char *text); extern void chat_loop (SDL_Event *event); +extern void chat_drawbox (); #endif diff --git a/src/configuration.c b/src/configuration.c index 1227fef..173fad1 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -53,8 +53,8 @@ int ReadConfig () { FILE *config; - char buf[200], - key2[50]; + char buf[1024], + key2[1024]; char *findit, *keyword, *value; diff --git a/src/field.c b/src/field.c index 0436c3c..ae467c3 100644 --- a/src/field.c +++ b/src/field.c @@ -1,4 +1,4 @@ -/* $Id: field.c,v 1.7 2003/05/05 00:22:21 stpohle Exp $ */ +/* $Id: field.c,v 1.8 2003/05/05 04:14:55 stpohle Exp $ */ /* field.c - procedures which are needed to control the field */ #include @@ -84,7 +84,6 @@ draw_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) { @@ -130,8 +129,136 @@ field_load (FILE * map) bman.fieldsize.x = sizex - 1; bman.fieldsize.y = sizey; + + /* darw the border so we know everything is right */ + for (i = 0; i < bman.fieldsize.x; i++) + bman.field[i][0].type = bman.field[i][bman.fieldsize.y-1].type = FT_block; + for (i = 0; i < bman.fieldsize.y; i++) + bman.field[0][i].type = bman.field[bman.fieldsize.x-1][i].type = FT_block; } +/* will set the playerposition but in a way that we won't start on a block */ +/* i am just too lazy to write this all again and again */ +#define PLX bman.players[i].pos.x +#define PLY bman.players[i].pos.y +void field_set_playerposition (int usermap) { + int p, dist, i,j , mx, my, dx = 0, dy = 0; + char txt[255]; + + p = 50; + dist = 8; + while (p == 50) { + p = 0; + dist--; + for (i = 0; (p < 50 && i < MAX_PLAYERS);) { + if (usermap) { + int maxloop = 0; + while (maxloop < 200 && (PLX == -1 || PLY == -1)) { + maxloop++; + PLX = s_random (bman.fieldsize.x - 2) + 1; + PLY = s_random (bman.fieldsize.y - 2) + 1; + + for (dx = 10, dy = 10, j = 0; (j < i && j < MAX_PLAYERS && (dx > 1 || dy > 1)); j++) { /* is ther any other player */ + dx = PLX - bman.players[j].pos.x; + if (dx < 0) dx = - dx; + dy = PLY - bman.players[j].pos.y; + if (dy < 0) dy = - dy; + } + + /* check if there is no block */ + if ((dx > 1 || dy > 1) && ((bman.field[PLX][PLY].type != FT_block && maxloop > 100) || + bman.field[PLX][PLY].type == FT_nothing)) { + /* get (up or down) dx and (left or right) dy */ + dx = s_random (2); + if (dx == 0) + dx = -1; + dy = s_random (2); + if (dy == 0) + dy = -1; + + /* first check if there is and free place for us */ + if (!((bman.field[PLX+dx][PLY].type != FT_block && maxloop > 100) || + bman.field[PLX+dx][PLY].type == FT_nothing)) + dx = -dx; + if (!((bman.field[PLX+dx][PLY].type != FT_block && maxloop > 100) || + bman.field[PLX+dx][PLY].type == FT_nothing)) + PLX = -1; + + if (!((bman.field[PLX][PLY+dy].type != FT_block && maxloop > 100) || + bman.field[PLX][PLY+dy].type == FT_nothing)) + dy = -dy; + if (!((bman.field[PLX][PLY+dy].type != FT_block && maxloop > 100) || + bman.field[PLX][PLY+dy].type == FT_nothing)) + PLY = -1; + } + else { + PLX = -1; + PLY = -1; + } + + /* make some space */ + if (PLX != -1 && PLY != -1) { + bman.field[PLX][PLY].type = FT_nothing; + bman.field[PLX+dx][PLY].type = FT_nothing; + bman.field[PLX][PLY+dy].type = FT_nothing; + } + } + } + if (PLX == -1 || PLY == -1) { + /* we could not set all fields or we don't run on a usermap */ + if (usermap) { + sprintf (txt,"Not all players could be set (Pl:%d)", i); + menu_displaymessage ("MAP - ERROR",txt); + } + + /* now there will be some fields deleted */ + PLX = 2 * (s_random ((bman.fieldsize.x - 1) / 2)) + 1; + PLY = 2 * (s_random ((bman.fieldsize.y - 1) / 2)) + 1; + + bman.field[PLX][PLY].type = FT_nothing; + + dx = s_random (4); // bit 1 = up/down bit 2 = left/right + /* up and down */ + if (((dx & 1) == 0 && PLX > 1) || PLX >= bman.fieldsize.x - 2) + bman.field[PLX-1][PLY].type = FT_nothing; + else + bman.field[PLX+1][PLY].type = FT_nothing; + /* left and right */ + if (((dx & 2) == 0 && PLY > 1) || PLY >= bman.fieldsize.y - 2) + bman.field[PLX][PLY-1].type = FT_nothing; + else + bman.field[PLX][PLY+1].type = FT_nothing; + } + mx = my = 100; + for (j = 0; j <= i; j++) { /* search smalest distance */ + dy = PLY - bman.players[j].pos.y; + dx = PLX - bman.players[j].pos.x; + if (dy < 0) + dy = -dy; + if (dx < 0) + dx = -dx; + + if (mx > dx && i != j) + mx = dx; + if (my > dy && i != j) + my = dy; + } + + if (mx > dist || my > dist) + i++; + else + p++; + } + } + + for (i = 0; i < MAX_PLAYERS; i++) { + PLX = PLX << 8; + PLY = PLY << 8; + } +}; +#undef PLX +#undef PLY + void field_new (char *filename) @@ -146,14 +273,14 @@ field_new (char *filename) /* if we can't open the given filename for any reason, reverting to default value else, load the file */ - - if (fmap) field_load (fmap); - fkt = ((float) (bman.fieldsize.x * bman.fieldsize.y)) / (bman.fieldsize.x * bman.fieldsize.y); - - // Clean the field // + /* this is the item factor we multiply it with this so we know + how much items we want in the game */ + fkt = ((float)(bman.fieldsize.x * bman.fieldsize.y))/(25.0 * 17.0); + + // Clean and create the field // if (fmap == NULL) { for (x = 0; x < bman.fieldsize.x; x++) for (y = 0; y < bman.fieldsize.y; y++) { @@ -180,23 +307,6 @@ field_new (char *filename) } } - /* get some free space for the playerstart position */ - for (d = 0; d < MAX_PLAYERS; d++) - if ((PS_IS_alife (bman.players[d].state)) != 0) { - x = bman.players[d].pos.x >> 8; - y = bman.players[d].pos.y >> 8; - - bman.field[x][y].type = FT_nothing; - if (x > 1) - bman.field[x - 1][y].type = FT_nothing; - if (x < bman.fieldsize.x - 2) - bman.field[x + 1][y].type = FT_nothing; - if (y > 1) - bman.field[x][y - 1].type = FT_nothing; - if (y < bman.fieldsize.y - 2) - bman.field[x][y + 1].type = FT_nothing; - } - nb_try = 100; // to prevent infinite loops (maybe there are no stones) /* put the fire powerups in the field */ for (d = 0, x = 0, y = 0; d < GAME_SPECIAL_ITEMFIRE * fkt; d++) { @@ -252,4 +362,6 @@ field_new (char *filename) bman.field[x][y].special = FT_death; x = y = 0; } + + field_set_playerposition (fmap != NULL); } diff --git a/src/game.c b/src/game.c index 20fa418..788bd85 100644 --- a/src/game.c +++ b/src/game.c @@ -81,15 +81,16 @@ game_draw_info () redraw_logo (0, gfx.res.y - gfx.font.size.y, gfx.res.x, gfx.res.y); for (x = 0; x < bman.fieldsize.x; x++) draw_stone (x, bman.fieldsize.y-1); - - sprintf (text, "Net Option: ["); - for (i = 0 ; i < MAX_PLAYERS; i++) - sprintf (text, "%s%3d ", text, bman.players[i].net.pkgopt.send_set); - text[strlen(text)+1] = 0; - text[strlen(text)] = ']'; - - draw_text (0, gfx.res.y - gfx.font.size.y, text, 1); - gfx_AddUpdateRect (0, gfx.res.y - gfx.font.size.y, gfx.res.x, gfx.font.size.y); + + if (debug) { /* do some debug informations on the screen */ + sprintf (text, "Net Option: ["); + for (i = 0 ; i < MAX_PLAYERS; i++) + sprintf (text, "%s%3d ", text, bman.players[i].net.pkgopt.send_set); + text[strlen(text)+1] = 0; + text[strlen(text)] = ']'; + draw_text (0, gfx.res.y - gfx.font.size.y, text, 1); + gfx_AddUpdateRect (0, gfx.res.y - gfx.font.size.y, gfx.res.x, gfx.font.size.y); + } if (chat.visible == 0) { SDL_Flip (gfx.screen); @@ -226,41 +227,6 @@ game_loop () }; -void game_set_playerposition () { - int p, dist, i,j , mx, my, dx, dy; - - p = 50; - dist = 8; - while (p == 50) { - p = 0; - dist--; - for (i = 0; (p < 50 && i < MAX_PLAYERS);) { - bman.players[i].pos.x = 2 * (s_random ((bman.fieldsize.x - 1) / 2)) + 1; - bman.players[i].pos.y = 2 * (s_random ((bman.fieldsize.y - 1) / 2)) + 1; - mx = my = 100; - for (j = 0; j <= i; j++) { /* search smalest distance */ - dy = bman.players[i].pos.y - bman.players[j].pos.y; - dx = bman.players[i].pos.x - bman.players[j].pos.x; - if (dy < 0) - dy = -dy; - if (dx < 0) - dx = -dx; - - if (mx > dx && i != j) - mx = dx; - if (my > dy && i != j) - my = dy; - } - - if (mx > dist || my > dist) - i++; - else - p++; - } - } -}; - - /* check which player won */ void game_end () diff --git a/src/multiwait.c b/src/multiwait.c index 5f5da9f..55efeed 100644 --- a/src/multiwait.c +++ b/src/multiwait.c @@ -344,11 +344,11 @@ wait_for_players () done = 1; } - if ((GT_MP_PTPM) && keys[SDLK_F5] && (!keypressed)) { - /* Map modification */ - menu_get_text ("Enter the path of a field file", bman.fieldpath, 30); - draw_logo(); - chat_drawbox(); + if ((GT_MP_PTPM) && keys[SDLK_F5] && (!keypressed)) { + /* Map modification */ + menu_get_text ("Enter the path of a field file", bman.fieldpath, 30); + draw_logo (); + chat_drawbox (); } chat_loop (&event); diff --git a/src/netmenu.c b/src/netmenu.c index 54e929b..1fc777d 100644 --- a/src/netmenu.c +++ b/src/netmenu.c @@ -186,6 +186,8 @@ host_multiplayer_game () if (bman.p_nr != -1) { bman.state = GS_update; + net_new_game (); + field_new (bman.fieldpath); net_send_servermode (); gfx_game_init (); net_new_gamedata (); @@ -226,8 +228,8 @@ join_multiplayer_game () if (bman.p_nr != -1 && (GS_WAITRUNNING || bman.state == GS_update)) { gfx_game_init (); - - bman.state = GS_update; + bman.state = GS_update; + net_new_game (); net_new_gamedata (); if (bman.state == GS_ready || bman.state == GS_running) diff --git a/src/network.c b/src/network.c index 0e6123f..75934da 100644 --- a/src/network.c +++ b/src/network.c @@ -1,4 +1,4 @@ -/* $Id: network.c,v 1.10 2003/05/04 19:23:00 ob1kenewb Exp $ */ +/* $Id: network.c,v 1.11 2003/05/05 04:14:55 stpohle Exp $ */ /* network routines. */ @@ -400,7 +400,6 @@ net_new_gamedata () Uint8 *keys; Uint32 downtimestamp = 0; - net_host_new_game (); // we do it to for the clients 'cause we need to reset the clients draw_logo (); if (GT_MP_PTPM) @@ -727,7 +726,7 @@ net_game_send_ill (int p_nr) after this the data should be transfered to the other clients. */ void -net_host_new_game () +net_new_game () { int p, i; @@ -737,8 +736,6 @@ net_host_new_game () bman.players[i].pos.y = bman.players[i].pos.x = -1; bman.players_nr = 0; - game_set_playerposition (); - bman.players_nr_s = 0; for (p = 0; p < MAX_PLAYERS; p++) { bman.players[p].pos.x = bman.players[p].pos.x << 8; @@ -777,8 +774,6 @@ net_host_new_game () } } - 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/network.h b/src/network.h index 915274b..4ba7201 100644 --- a/src/network.h +++ b/src/network.h @@ -68,6 +68,7 @@ extern void network_shutdown (); extern int network_init (); extern int network_loop (); extern void net_change_playerid (int pl_nr, unsigned char senddata); +extern void net_new_game (); extern void net_new_gamedata (); extern void net_game_send_player (int p_nr); extern void net_game_send_playermove (int p_nr, int mustsend); @@ -82,8 +83,6 @@ extern void net_send_players (); extern int net_check_timeout (int pl_nr); extern void net_dyn_pkgoption (); extern void net_send_chat (char *text, signed char notigamesrv); -extern void net_host_new_game (); - // multiwait.c extern void wait_for_players (); diff --git a/src/single.c b/src/single.c index b5cab8a..1bfff32 100644 --- a/src/single.c +++ b/src/single.c @@ -1,4 +1,4 @@ -/* $Id: single.c,v 1.3 2003/05/04 19:23:00 ob1kenewb Exp $ */ +/* $Id: single.c,v 1.4 2003/05/05 04:14:56 stpohle Exp $ */ /* single player */ #include "basic.h" @@ -12,8 +12,8 @@ single_game_new (int ai_players) // set players on field 1,1 for (p = 0; p < MAX_PLAYERS; p++) { - bman.players[p].pos.x = 1 << 8; - bman.players[p].pos.y = 1 << 8; + bman.players[p].pos.x = -1; + bman.players[p].pos.y = -1; bman.players[p].state = 0; // reset bombs