diff --git a/configure.in b/configure.in index dcb5620..cd9bf58 100644 --- a/configure.in +++ b/configure.in @@ -5,7 +5,7 @@ dnl Please disable it in the Anjuta project configuration AC_INIT(configure.in) AC_CANONICAL_TARGET -AM_INIT_AUTOMAKE(bomberclone, 0.11.6.1) +AM_INIT_AUTOMAKE(bomberclone, 0.11.6.2) AM_CONFIG_HEADER(config.h) diff --git a/include/basic.h b/include/basic.h index 66ccfed..62302ce 100644 --- a/include/basic.h +++ b/include/basic.h @@ -1,4 +1,4 @@ -/* $Id: basic.h,v 1.30 2005/03/27 01:31:49 stpohle Exp $ */ +/* $Id: basic.h,v 1.31 2005/04/09 18:22:40 stpohle Exp $ */ /* basic types which we need everywhere */ #ifndef _BC_BASIC_H_ @@ -80,6 +80,8 @@ #define UDP_TIMEOUT 15000 #define BUF_SIZE 1024 +#define AUTOSTART 20 /* dedicated server autostart */ + #define MW_IS_GFX_SELECT(__gfx_nr,__result) for (__result = (MAX_PLAYERS-1); (__result >= 0) && (players[__result].gfx_nr != __gfx_nr); __result--); #define CUTINT(__x) (__x-floorf(__x)) // cut the integer part off diff --git a/include/bomberclone.h b/include/bomberclone.h index 0d284a0..06e17ca 100644 --- a/include/bomberclone.h +++ b/include/bomberclone.h @@ -1,4 +1,4 @@ -/* $Id: bomberclone.h,v 1.32 2005/04/08 00:18:28 stpohle Exp $ */ +/* $Id: bomberclone.h,v 1.33 2005/04/09 18:22:40 stpohle Exp $ */ /* bomberclone.h */ #ifndef _BOMBERCLONE_H_ @@ -85,6 +85,10 @@ struct { int firewall; int notifygamemaster; int broadcast; + int dedicated; // if started as dedicated server + int autostart; // time for an autostart of the game + int minplayers; // minimal number of players + int askplayername; // ask player for name at startup int start_bombs; // start values diff --git a/include/gfx.h b/include/gfx.h index 6d7ab95..67ddb7c 100644 --- a/include/gfx.h +++ b/include/gfx.h @@ -1,4 +1,4 @@ -/* $Id: gfx.h,v 1.9 2005/04/06 21:17:48 stpohle Exp $ */ +/* $Id: gfx.h,v 1.10 2005/04/09 18:22:40 stpohle Exp $ */ #ifndef _GFX_H_ #define _GFX_H_ @@ -84,6 +84,7 @@ extern void gfx_unlocksurface (SDL_Surface *surface); extern void redraw_logo_shaded (int x, int y, int w, int h, int c); extern void gfx_load_players (int sx, int sy); extern void gfx_free_players (); +extern int gfx_get_nr_of_playergfx (); // gfxpixelimage.c extern void getRGBpixel (SDL_Surface *surface, int x, int y, int *R, int *G, int *B); diff --git a/src/bomb.c b/src/bomb.c index 77a570a..0f5dca2 100644 --- a/src/bomb.c +++ b/src/bomb.c @@ -1,4 +1,4 @@ -/* $Id: bomb.c,v 1.62 2005/02/20 19:11:20 stpohle Exp $ */ +/* $Id: bomb.c,v 1.63 2005/04/09 18:22:40 stpohle Exp $ */ /* everything what have to do with the bombs */ #include "bomberclone.h" @@ -19,6 +19,9 @@ draw_bomb (_bomb * bomb) y1, y2; + if (bman.dedicated) + return; + if (x < 0 || y < 0 || x >= map.size.x || y >= map.size.y) { d_printf ("FATAL: Draw Bomb out of range [%f,%f]\n", x, y); return; diff --git a/src/configuration.c b/src/configuration.c index f3d4ba7..cbaf098 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -1,4 +1,4 @@ -/* $Id: configuration.c,v 1.73 2005/04/08 00:18:29 stpohle Exp $ +/* $Id: configuration.c,v 1.74 2005/04/09 18:22:40 stpohle Exp $ * configuration */ #include @@ -93,6 +93,8 @@ config_init (int argc, char **argv) resend_cache.fill = -1; bman.notifygamemaster = 1; bman.broadcast = 1; + bman.dedicated = 0; + bman.autostart = AUTOSTART; bman.askplayername = 0; debug = 0; gfx.res.x = 640; @@ -111,6 +113,7 @@ config_init (int argc, char **argv) bman.firewall = 0; bman.init_timeout = GAME_TIMEOUT; bman.ai_players = 1; + bman.minplayers = 0; snd.inited = 0; snd.audio_rate = 22050; snd.audio_format = AUDIO_S16; @@ -133,36 +136,34 @@ config_init (int argc, char **argv) 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 (); - playernamemenu (); - } - else { - ReadPrgArgs (argc, argv); - gfx_init (); - draw_logo (); - if (bman.askplayername) - playermenu (); - } + config_read (); + + ReadPrgArgs (argc, argv); + + gfx_init (); + draw_logo (); + if (bman.askplayername) + playernamemenu (); snd_init (); - gfx_blitdraw (); - SDL_Flip (gfx.screen); + gfx_blitdraw (); + + if (!bman.dedicated) + SDL_Flip (gfx.screen); sprintf (text,"Bomberclone %s", VERSION); sprintf (icon,"%s/pixmaps/bomberclone.png", bman.datapath); SDL_WM_SetCaption(text , NULL); icon_img = IMG_Load(icon); if (icon_img == NULL) - d_printf ("could not load icon. (%s)\n", icon); + d_printf ("could not load icon. (%s)\n", icon); + #ifdef _WIN32 - { - SDL_Surface *tmp = icon_img; - icon_img = scale_image (tmp, 32, 32); - SDL_FreeSurface (tmp); - } + { + SDL_Surface *tmp = icon_img; + icon_img = scale_image (tmp, 32, 32); + SDL_FreeSurface (tmp); + } #endif SDL_WM_SetIcon (icon_img, NULL); @@ -173,8 +174,7 @@ config_init (int argc, char **argv) /* read the configuration file * return -1 if something went wrong and 0 if no problem */ int -config_read () -{ +config_read () { FILE *config; char buf[1024]; char *findit, @@ -675,6 +675,8 @@ ReadPrgArgs (int argc, char **argv) printf (" -join - go into the join menu\n"); printf (" -connect ADDRESS - connect to a server\n"); printf (" -debug 0/1 - enable/disable debug\n"); + printf (" -dedicated - run as dedicated server\n"); + printf (" -autostart SECONDS - time before a game starts\n"); exit (0); } if (!strcmp (argv[i], "-port")) @@ -693,6 +695,13 @@ ReadPrgArgs (int argc, char **argv) bman.broadcast = atoi (argv[++i]); if (!strcmp (argv[i], "-debug")) debug = atoi (argv[++i]); + if (!strcmp (argv[i], "-dedicated")) { + if (bman.minplayers <= 1) + bman.minplayers = 2; + bman.dedicated = 1; + } + if (!strcmp (argv[i], "-autostart")) + bman.autostart = atoi (argv[++i]); } }; @@ -717,6 +726,9 @@ ReadPrgArgs_Jump (int argc, char **argv) join_multiplayer_game (); } } + + if (bman.dedicated > 0) + host_multiplayer_game (); }; diff --git a/src/font.c b/src/font.c index 1ee6cee..c008f00 100644 --- a/src/font.c +++ b/src/font.c @@ -1,4 +1,4 @@ -/* $Id: font.c,v 1.14 2004/12/26 04:19:20 stpohle Exp $ */ +/* $Id: font.c,v 1.15 2005/04/09 18:22:40 stpohle Exp $ */ // Using Fonts in SDL #include @@ -126,17 +126,23 @@ void font_load () { b = 128; break; } - font[i].image[c] = SDL_DisplayFormat (tmp); - SDL_SetColorKey (font[i].image[c] , SDL_SRCCOLORKEY, SDL_MapRGB (font[i].image[c]->format, 0,0,0)); - SDL_FillRect (font[i].image[c], NULL, SDL_MapRGB (font[i].image[c]->format, r,g,b)); - SDL_BlitSurface (raw, NULL, font[i].image[c], NULL); + + if (!bman.dedicated) { + font[i].image[c] = SDL_DisplayFormat (tmp); + SDL_SetColorKey (font[i].image[c] , SDL_SRCCOLORKEY, SDL_MapRGB (font[i].image[c]->format, 0,0,0)); + SDL_FillRect (font[i].image[c], NULL, SDL_MapRGB (font[i].image[c]->format, r,g,b)); + SDL_BlitSurface (raw, NULL, font[i].image[c], NULL); + } + else + font[i].image[c] = tmp; } - font[i].size.x = raw->w / 16; - font[i].size.y = raw->h / 16; + font[i].size.x = tmp->w / 16; + font[i].size.y = tmp->h / 16; SDL_FreeSurface (raw); - SDL_FreeSurface (tmp); + if (!bman.dedicated) + SDL_FreeSurface (tmp); } }; diff --git a/src/game.c b/src/game.c index e9e9e97..2081aa8 100644 --- a/src/game.c +++ b/src/game.c @@ -1,4 +1,4 @@ -/* $Id: game.c,v 1.108 2005/04/06 21:17:48 stpohle Exp $ +/* $Id: game.c,v 1.109 2005/04/09 18:22:40 stpohle Exp $ game.c - procedures for the game. */ #include @@ -220,21 +220,21 @@ game_loop () SDL_Event event; int done = 0, eventstate; - gfx_blitupdaterectclear (); - - draw_logo (); - draw_field (); if (GT_MP) net_game_fillsockaddr (); - SDL_Flip (gfx.screen); menu = NULL; - bman.updatestatusbar = 1; // force an update timestamp = SDL_GetTicks (); // needed for time sync. d_gamedetail ("GAME START"); - draw_players (); + if (!bman.dedicated) { + gfx_blitupdaterectclear (); + draw_logo (); + draw_field (); + SDL_Flip (gfx.screen); + draw_players (); + } if (bman.p_nr >= 0 && bman.p_nr < MAX_PLAYERS) { players[bman.p_nr].ready = 1; @@ -248,33 +248,55 @@ game_loop () } while (!done && (bman.state == GS_running || bman.state == GS_ready)) { - if ((eventstate = SDL_PollEvent (&event)) != 0) - switch (event.type) { - case (SDL_QUIT): - done = 1; - bman.state = GS_quit; - } - /* - * input handling - */ - keyb_loop (&event); + if (!bman.dedicated) { + if ((eventstate = SDL_PollEvent (&event)) != 0) + switch (event.type) { + case (SDL_QUIT): + done = 1; + bman.state = GS_quit; + } - game_keys_loop (); + /* + * input handling + */ + keyb_loop (&event); - if (GT_MP) - chat_loop (&event); + game_keys_loop (); + + if (GT_MP) + chat_loop (&event); - if ((!IS_LPLAYER2) && (!chat.active)) - chat_setactive (1, 1); + if ((!IS_LPLAYER2) && (!chat.active)) + chat_setactive (1, 1); - restore_players_screen (); + restore_players_screen (); + } + + /* check if we have a dedicated server */ + if (bman.dedicated && bman.state == GS_ready) { + int i, ready = 1; + + for (i = 0; i < MAX_PLAYERS; i++) + if (NET_CANSEND (i) && !players[i].ready) + ready = 0; + + if (ready) + bman.state = GS_running; + else + d_printf ("game_keys_loop: not all players are ready\n"); + + net_send_servermode (); + } + player_check (bman.p_nr); if (IS_LPLAYER2) player_check (bman.p2_nr); - dead_playerani (); + if (!bman.dedicated) + dead_playerani (); + special_loop (); player_move (bman.p_nr); @@ -292,9 +314,12 @@ game_loop () bomb_loop (); field_loop (); flitems_loop (); - draw_players (); - game_draw_info (); // will set the var bman.player_nr - + + if (!bman.dedicated) { + draw_players (); + game_draw_info (); // will set the var bman.player_nr + } + /* check if there is only one player left and the game is in multiplayer mode and if there the last dieing animation is done */ if (game_check_endgame () && bman.timeout >= 0.0f) @@ -305,28 +330,34 @@ game_loop () done = 1; } - stonelist_draw (); + if (!bman.dedicated) { + stonelist_draw (); - /* if there is any menu displayed do so */ - if (menu != NULL) - game_menu_loop (&event, eventstate); + /* if there is any menu displayed do so */ + if (menu != NULL) + game_menu_loop (&event, eventstate); + + gfx_blitdraw (); + } - gfx_blitdraw (); s_calctimesync (); bman.timeout -= timediff; } if (menu != NULL) menu_delete (menu); - gfx_blitdraw (); - chat_show (-1, -1, -1, -1); + if (!bman.dedicated) { + gfx_blitdraw (); + + chat_show (-1, -1, -1, -1); + draw_logo (); + gfx_blitupdaterectclear (); + SDL_Flip (gfx.screen); + } d_gamedetail ("GAME END"); d_printf ("done = %d\n", done); - draw_logo (); - gfx_blitupdaterectclear (); - SDL_Flip (gfx.screen); }; @@ -471,7 +502,7 @@ game_start () { int p, i; - menu_displaytext ("Loading..", "Please Wait"); + if (!bman.dedicated) menu_displaytext ("Loading..", "Please Wait"); bman.players_nr_s = 0; @@ -527,10 +558,17 @@ game_start () flitems_reset (); init_map_tileset (); - tileset_load (map.tileset, -1, -1); + + if (!bman.dedicated) + tileset_load (map.tileset, -1, -1); + gfx_load_players (gfx.block.x, gfx.block.y); - snd_load (map.tileset); - snd_music_start (); + + if (!bman.dedicated) { + snd_load (map.tileset); + snd_music_start (); + } + map.state = MS_normal; bman.timeout = bman.init_timeout; s_calctimesync (); // to clean up the timesyc diff --git a/src/gfx.c b/src/gfx.c index 2869755..3b46585 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1,4 +1,4 @@ -/* $Id: gfx.c,v 1.39 2005/04/06 21:17:48 stpohle Exp $ */ +/* $Id: gfx.c,v 1.40 2005/04/09 18:22:40 stpohle Exp $ */ /* gfx.c */ #include "bomberclone.h" @@ -6,14 +6,14 @@ _gfx gfx; -static int gfx_get_nr_of_playergfx (); +int gfx_get_nr_of_playergfx (); static void gfx_load_menusmall_players (); static void gfx_load_fieldtype_menu (); /* * count all playergfx */ -static int gfx_get_nr_of_playergfx () { +int gfx_get_nr_of_playergfx () { int i = 0; FILE *f = NULL; char filename[255]; @@ -65,19 +65,24 @@ gfx_load_players (int sx, int sy) gfx.players[i].ani.h = sy * 2; gfx.players[i].ani.w = (tmpimage->w / 4) * sfkt; gfx.players[i].ani.frames = tmpimage->h / GFX_PLAYERIMGSIZE_Y; - tmpimage1 = - scale_image (tmpimage, gfx.players[i].ani.w * 4, - gfx.players[i].ani.frames * gfx.players[i].ani.h); - getRGBpixel (tmpimage1, 0, 0, &r, &g, &b); - SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b)); - gfx.players[i].ani.image = SDL_DisplayFormat (tmpimage1); - SDL_FreeSurface (tmpimage1); - - /* calculate the numbers of images for the animation */ - gfx.players[i].offset.x = (sx - gfx.players[i].ani.w) / 2; - gfx.players[i].offset.y = -sy; - - SDL_FreeSurface (tmpimage); + + if (!bman.dedicated) { + tmpimage1 = + scale_image (tmpimage, gfx.players[i].ani.w * 4, + gfx.players[i].ani.frames * gfx.players[i].ani.h); + getRGBpixel (tmpimage1, 0, 0, &r, &g, &b); + SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b)); + gfx.players[i].ani.image = SDL_DisplayFormat (tmpimage1); + SDL_FreeSurface (tmpimage1); + + /* calculate the numbers of images for the animation */ + gfx.players[i].offset.x = (sx - gfx.players[i].ani.w) / 2; + gfx.players[i].offset.y = -sy; + } + else + gfx.players[i].ani.image = NULL; + + SDL_FreeSurface (tmpimage); } } @@ -91,46 +96,48 @@ gfx_load_players (int sx, int sy) } gfx.dead.frames = tmpimage->h / (2* GFX_IMGSIZE); - tmpimage1 = - scale_image (tmpimage, ((2 * sx * tmpimage->w) / (2 * GFX_IMGSIZE)), - gfx.dead.frames * (2 * sy)); - getRGBpixel (tmpimage1, 0, 0, &r, &g, &b); - SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b)); - gfx.dead.image = SDL_DisplayFormat (tmpimage1); - SDL_FreeSurface (tmpimage1); - SDL_FreeSurface (tmpimage); - - - /* load the illnessthing */ - sprintf (filename, "%s/player/playersick.png", bman.datapath); - tmpimage = IMG_Load (filename); - if (tmpimage == NULL) { - printf ("Can't load image: %s\n", SDL_GetError ()); - exit (1); - } - gfx.ill.frames = tmpimage->h / (2 * GFX_IMGSIZE); - tmpimage1 = - scale_image (tmpimage, (2 * sx * tmpimage->w) / (2 * GFX_IMGSIZE), - gfx.ill.frames * (2 * sy)); - getRGBpixel (tmpimage1, 0, 0, &r, &g, &b); - SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b)); - gfx.ill.image = SDL_DisplayFormat (tmpimage1); - SDL_FreeSurface (tmpimage); - SDL_FreeSurface (tmpimage1); - + if (!bman.dedicated) { + tmpimage1 = + scale_image (tmpimage, ((2 * sx * tmpimage->w) / (2 * GFX_IMGSIZE)), + gfx.dead.frames * (2 * sy)); + getRGBpixel (tmpimage1, 0, 0, &r, &g, &b); + SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b)); + gfx.dead.image = SDL_DisplayFormat (tmpimage1); + SDL_FreeSurface (tmpimage1); + SDL_FreeSurface (tmpimage); + + /* load the illnessthing */ + sprintf (filename, "%s/player/playersick.png", bman.datapath); + tmpimage = IMG_Load (filename); + if (tmpimage == NULL) { + printf ("Can't load image: %s\n", SDL_GetError ()); + exit (1); + } + gfx.ill.frames = tmpimage->h / (2 * GFX_IMGSIZE); + tmpimage1 = + scale_image (tmpimage, (2 * sx * tmpimage->w) / (2 * GFX_IMGSIZE), + gfx.ill.frames * (2 * sy)); + getRGBpixel (tmpimage1, 0, 0, &r, &g, &b); + SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b)); + gfx.ill.image = SDL_DisplayFormat (tmpimage1); + SDL_FreeSurface (tmpimage); + SDL_FreeSurface (tmpimage1); - /* load the respawn gfx */ - sprintf (filename, "%s/player/respawn.png", bman.datapath); - tmpimage = IMG_Load (filename); - if (tmpimage == NULL) { - printf ("Can't load image: %s\n", SDL_GetError ()); - exit (1); - } - gfx.respawn.frames = tmpimage->h / (2 * GFX_IMGSIZE); - gfx.respawn.image = - scale_image (tmpimage, (2 * sx * tmpimage->w) / (2 * GFX_IMGSIZE), - gfx.respawn.frames * (2 * sy)); - SDL_FreeSurface (tmpimage); + /* load the respawn gfx */ + sprintf (filename, "%s/player/respawn.png", bman.datapath); + tmpimage = IMG_Load (filename); + if (tmpimage == NULL) { + printf ("Can't load image: %s\n", SDL_GetError ()); + exit (1); + } + gfx.respawn.frames = tmpimage->h / (2 * GFX_IMGSIZE); + gfx.respawn.image = + scale_image (tmpimage, (2 * sx * tmpimage->w) / (2 * GFX_IMGSIZE), + gfx.respawn.frames * (2 * sy)); + SDL_FreeSurface (tmpimage); + } + else + SDL_FreeSurface (tmpimage); }; @@ -162,20 +169,23 @@ void gfx_init () { int i; - - if (gfx.fullscreen) + + if (gfx.fullscreen && !bman.dedicated) gfx.screen = SDL_SetVideoMode (gfx.res.x, gfx.res.y, gfx.bpp, SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_HWACCEL | SDL_FULLSCREEN); - else + else if (!bman.dedicated) gfx.screen = SDL_SetVideoMode (gfx.res.x, gfx.res.y, gfx.bpp, SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_HWACCEL); - if (gfx.screen == NULL) { + if (!bman.dedicated && gfx.screen == NULL) { d_printf ("Unable to set video mode: %s\n", SDL_GetError ()); return; } + else if (bman.dedicated) { + gfx.screen = NULL; + } SDL_ShowCursor (SDL_DISABLE); /* delete small gfx und the menu player gfx */ @@ -521,6 +531,9 @@ void draw_logo () { SDL_Rect dest; + + if (bman.dedicated) return; + dest.x = dest.y = 0; dest.w = gfx.res.x; dest.h = gfx.res.y; diff --git a/src/gfxengine.c b/src/gfxengine.c index 75894ab..dc093af 100644 --- a/src/gfxengine.c +++ b/src/gfxengine.c @@ -1,4 +1,4 @@ -/* $Id: gfxengine.c,v 1.5 2004/09/25 10:57:51 stpohle Exp $ */ +/* $Id: gfxengine.c,v 1.6 2005/04/09 18:22:41 stpohle Exp $ */ /* GFX Game Engine */ #include "bomberclone.h" @@ -103,7 +103,7 @@ gfx_blitdraw () { int i; - if (blitdb_nr < 0) { + if (blitdb_nr < 0 || bman.dedicated) { blitdb_nr = 0; return; } diff --git a/src/gfxpixelimage.c b/src/gfxpixelimage.c index e99eb64..12aec69 100644 --- a/src/gfxpixelimage.c +++ b/src/gfxpixelimage.c @@ -1,4 +1,4 @@ -/* $Id: gfxpixelimage.c,v 1.12 2004/09/26 02:28:06 stpohle Exp $ */ +/* $Id: gfxpixelimage.c,v 1.13 2005/04/09 18:22:41 stpohle Exp $ */ /* gfx pixel manipulation and image manipulation */ #include "bomberclone.h" @@ -492,6 +492,8 @@ SDL_Surface *gfx_copyfrom (SDL_Surface *img, SDL_Rect *rect) { SDL_Surface *res; SDL_Rect src, dest; + if (img == NULL) return NULL; + if (rect == NULL) { src.x = 0; src.y = 0; diff --git a/src/main.c b/src/main.c index 77dfdb7..dfa90aa 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.30 2004/10/18 18:27:20 stpohle Exp $ */ +/* $Id: main.c,v 1.31 2005/04/09 18:22:41 stpohle Exp $ */ #include "basic.h" #include "bomberclone.h" @@ -41,7 +41,8 @@ main (int argc, char **argv) SDL_EnableUNICODE(1); config_init (argc, argv); - while (menuselect != -1 && bman.state != GS_quit) { + + while (menuselect != -1 && bman.state != GS_quit && bman.dedicated == 0) { menu = menu_new ("Bomberclone", 400, 250); // y=230 menu_create_button (menu, "Single Game", -1, 70, 200, 0); diff --git a/src/multiwait.c b/src/multiwait.c index 9a0954e..d2a7645 100644 --- a/src/multiwait.c +++ b/src/multiwait.c @@ -1,4 +1,4 @@ -/* $Id: multiwait.c,v 1.54 2004/12/26 04:19:20 stpohle Exp $ +/* $Id: multiwait.c,v 1.55 2005/04/09 18:22:41 stpohle Exp $ multiwait.c - this manages only the network screen where everyone have to select it's players and where even the basic chat is inside */ @@ -33,24 +33,30 @@ extern int blitdb_nr; static void mw_init () { team_update (); - gfx_blitdraw (); - draw_logo (); - gfx_blitdraw (); + if (!bman.dedicated) { + gfx_blitdraw (); + draw_logo (); + gfx_blitdraw (); + } bman.updatestatusbar = 1; d_playerdetail ("mw_init:\n"); - SDL_Flip (gfx.screen); - chat_show (10, gfx.res.y / 2, gfx.res.x - 20, gfx.res.y / 2 - 10); - chat_setactive (1, 1); + if (!bman.dedicated) { + SDL_Flip (gfx.screen); + chat_show (10, gfx.res.y / 2, gfx.res.x - 20, gfx.res.y / 2 - 10); + chat_setactive (1, 1); + } }; /* free all graphics */ static void mw_shutdown () { - chat_show (-1, -1, -1, -1); - gfx_blitdraw (); - draw_logo (); + if (!bman.dedicated) { + chat_show (-1, -1, -1, -1); + gfx_blitdraw (); + draw_logo (); - SDL_Flip (gfx.screen); + SDL_Flip (gfx.screen); + } }; @@ -214,6 +220,8 @@ static void mw_draw_all_teams () { /* the loop itself */ void wait_for_players () { SDL_Event event; + int i, cnt, aipl, humanpl_cnt; + int timeout_timestamp = timestamp + (bman.autostart * 1000); mw_init (); @@ -229,29 +237,54 @@ void wait_for_players () { * check some little things and do the network stuff */ network_loop (); - + /* * the drawing stuff */ - if (mw_check_screenredraw()) { - d_printf ("Draw Status\n"); + if (!bman.dedicated) { + if (mw_check_screenredraw()) { + d_printf ("Draw Status\n"); + gfx_blitdraw (); + draw_logo (); + if (bman.gametype==GT_team) mw_draw_all_teams(); + else mw_draw_all_player (); + } gfx_blitdraw (); - draw_logo (); - if (bman.gametype==GT_team) mw_draw_all_teams(); - else mw_draw_all_player (); - } - gfx_blitdraw (); - /* - * input handling - */ - keyb_loop (&event); - mw_keys_loop (); - - chat_loop (&event); - chat.active = 1; + /* + * input handling + */ + keyb_loop (&event); + mw_keys_loop (); + + chat_loop (&event); + chat.active = 1; + } + else { + /* check for the minimum of players */ + + for (humanpl_cnt = 0, i = 0, cnt = 0, aipl = -1; i < MAX_PLAYERS; i++) { + if (PS_IS_used (players[i].state)) { + cnt++; + if (PS_IS_aiplayer (players[i].state)) + aipl = i; + else if (players[i].gfx_nr >= 0) + humanpl_cnt++; + } + } + + if (cnt < (bman.minplayers+1)) + single_create_ai (1); + + if (cnt > (bman.minplayers+1) && aipl >= 0) + player_delete (aipl); + } s_calctimesync (); + + if ((bman.autostart > 0) && (timestamp > timeout_timestamp) && bman.dedicated && humanpl_cnt > 0) + bman.state = GS_ready; + } while (bman.state == GS_wait && bman.sock != -1); mw_shutdown (); diff --git a/src/network.c b/src/network.c index f30e94f..2d6aada 100644 --- a/src/network.c +++ b/src/network.c @@ -1,4 +1,4 @@ -/* $Id: network.c,v 1.72 2004/12/26 04:19:20 stpohle Exp $ */ +/* $Id: network.c,v 1.73 2005/04/09 18:22:41 stpohle Exp $ */ /* network routines. */ @@ -469,13 +469,15 @@ net_transmit_gamedata () Uint8 *keys; Uint32 downtimestamp = 0; - draw_logo (); - - if (GT_MP_PTPM) - font_draw (100, 0, "Waiting for the Clients", 1, 0); - else - font_draw (100, 0, "Downloading Data", 1, 0); + if (!bman.dedicated) { + draw_logo (); + if (GT_MP_PTPM) + font_draw (100, 0, "Waiting for the Clients", 1, 0); + else + font_draw (100, 0, "Downloading Data", 1, 0); + } + /* prepare everything for the loop */ @@ -494,8 +496,11 @@ net_transmit_gamedata () else net_istep = 3; - draw_netupdatestate (1); - SDL_Flip (gfx.screen); + if (!bman.dedicated) { + draw_netupdatestate (1); + SDL_Flip (gfx.screen); + } + downtimestamp = timestamp; while (!done && (bman.state == GS_update || (GT_MP_PTPS && net_istep != 0))) { /* the network thing */ @@ -600,30 +605,32 @@ net_transmit_gamedata () } /* do the grafik work */ - draw_netupdatestate (0); - - if (SDL_PollEvent (&event) != 0) - switch (event.type) { - case (SDL_QUIT): - bman.state = GS_quit; - bman.p_nr = -1; - done = 1; - } - - keys = SDL_GetKeyState (NULL); - - if (keys[SDLK_ESCAPE] && event.type == SDL_KEYDOWN) { - done = 1; - bman.p_nr = -1; - keypressed = 1; - bman.state = GS_startup; - } - - if (event.type == SDL_KEYUP) - keypressed = 0; + if (!bman.dedicated) { + draw_netupdatestate (0); + + if (SDL_PollEvent (&event) != 0) + switch (event.type) { + case (SDL_QUIT): + bman.state = GS_quit; + bman.p_nr = -1; + done = 1; + } + + keys = SDL_GetKeyState (NULL); + + if (keys[SDLK_ESCAPE] && event.type == SDL_KEYDOWN) { + done = 1; + bman.p_nr = -1; + keypressed = 1; + bman.state = GS_startup; + } + + if (event.type == SDL_KEYUP) + keypressed = 0; + } timestamp = SDL_GetTicks (); // needed for time sync. - SDL_Delay (1); // we don't need here anything better + SDL_Delay (1); // we don't need here anything better /* player is only watching so just go after we have got everything go to show the field */ diff --git a/src/player.c b/src/player.c index 3d2bbf8..dbaa215 100644 --- a/src/player.c +++ b/src/player.c @@ -1,4 +1,4 @@ -/* $Id: player.c,v 1.99 2005/02/20 21:58:05 stpohle Exp $ +/* $Id: player.c,v 1.100 2005/04/09 18:22:41 stpohle Exp $ * player.c - everything what have to do with the player */ #include @@ -18,6 +18,9 @@ draw_player (_player * player) dest; int i; + if (bman.dedicated) + return; + if ((int)player->pos.x < 0 || (int)player->pos.x >= map.size.x || (int)player->pos.y < 0 || (int)player->pos.y >= map.size.y) { d_printf ("FATAL: Draw Player out of range : [%f,%f]\n", player->pos.x, @@ -578,6 +581,9 @@ void draw_players () { int p; + + if (bman.dedicated) return; + for (p = 0; p < MAX_PLAYERS; p++) { if (PS_IS_playing (players[p].state) && players[p].tunnelto <= 0) draw_player (&players[p]); diff --git a/src/sound.c b/src/sound.c index 56f2423..8eb6cb3 100644 --- a/src/sound.c +++ b/src/sound.c @@ -1,4 +1,4 @@ -/* $Id: sound.c,v 1.6 2003/12/24 02:38:16 stpohle Exp $ */ +/* $Id: sound.c,v 1.7 2005/04/09 18:22:41 stpohle Exp $ */ /* sound */ #include "sound.h" @@ -80,6 +80,11 @@ void snd_init () { #if HAVE_SDL_MIXER + if (bman.dedicated) { + snd.inited = 0; + return; + } + if (Mix_OpenAudio (snd.audio_rate, snd.audio_format, snd.audio_channels, 1024) < 0) { d_printf ("Couldn't open audio mixer: %s\n", SDL_GetError ()); snd.inited = 0;