/* $Id: multiwait.c,v 1.49 2004/09/27 19:20:20 patty21 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 */ #include "bomberclone.h" #include "network.h" #include "packets.h" #include "gfx.h" #include "chat.h" #include "menu.h" #include "single.h" #include "keyb.h" extern int UpdateRects_nr; extern int blitdb_nr; static int mw_num_readyplayers; // number of players who are ready static int mw_num_players_x; // number of players in the x static int mw_num_players_y; // number of players in the y static int mw_num_players; _point mw_pos[MAX_PLAYERS+1]; // uncomment to sort by points // #define SORT_BY_POINTS 1 #define MW_PLAYERSCR_X 310 #define MW_PLAYERSCR_Y 50 #define MW_TITLE_Y 50 /* returns number of active players in a team */ int mw_team_is_used (int t_nr) { int i,j=0; for(i=0;istate))) { j++;} d_printf("Team: %s : %d players\n",teams[t_nr].name,j); return j; } /* Calcs the position of all items on the screen */ int mw_calc_screen() { int i,j,k=0,n=0,cy; if (bman.updatestatusbar) { if (bman.gametype==GT_team) { /* team mode */ for(i=0;ik) k=j; if (j>0) n++; } mw_num_players_x=2; mw_num_players_y=floorf(n/2)+n%2; mw_num_players=n; for(i=0;iMAX_PLAYERS) { mw_num_players_x=2; mw_num_players_y=floorf(mw_num_players/2)+mw_num_players%2; } else { mw_num_players_x=1; mw_num_players_y=mw_num_players; } for(i=0;i= 0 && players[i].gfx_nr < MAX_PLAYERS) mw_num_readyplayers++; } } /* * draw only the given player */ void mw_draw_player (int p_nr, int pos) { _player *player; _point p; char text[255]; SDL_Rect src; SDL_Rect dest; player=&players[p_nr]; p.x = mw_pos[pos].x; p.y = mw_pos[pos].y; if (PS_IS_used (player->state)) { /* * player is used */ if (player->gfx_nr >= 0 && player->gfx_nr < gfx.player_gfx_count) { /* player is used and selected a gfx */ dest.x = p.x; src.x = 0; src.y = 0; if (p_nr==bman.p_nr) { /* player 1 */ dest.y = p.y; src.w = dest.w = gfx.players[player->gfx_nr].menu_image->w; src.h = dest.h = gfx.players[player->gfx_nr].menu_image->h; gfx_blit (gfx.players[player->gfx_nr].menu_image, &src, gfx.screen, &dest, 10001); } else if (p_nr==bman.p2_nr) { /* player 2 */ dest.x=p.x+MW_PLAYERSCR_X-64; dest.y = p.y; src.w = dest.w = gfx.players[player->gfx_nr].menu_image->w; src.h = dest.h = gfx.players[player->gfx_nr].menu_image->h; gfx_blit (gfx.players[player->gfx_nr].menu_image, &src, gfx.screen, &dest, 10001); } else { /* net-player */ dest.x=p.x+35; dest.y = p.y + 15; src.w = dest.w = gfx.players[player->gfx_nr].small_image->w; src.h = dest.h = gfx.players[player->gfx_nr].small_image->h; gfx_blit (gfx.players[player->gfx_nr].small_image, &src, gfx.screen, &dest, 10001); } } font_gfxdraw (p.x + GFX_IMGSIZE, p.y, player->name, 1, COLOR_yellow, 10002); sprintf (text,"Victorys:%2d(%d)", player->wins, player->points); font_gfxdraw (p.x + GFX_IMGSIZE, p.y + font[2].size.y - 4, text, 0, COLOR_white, 10002); if (debug && PS_IS_used (player->state)) { sprintf (text, "%s:%s [%d]", player->net.addr.host, player->net.addr.port, player->state); if (player->net.flags & NETF_firewall) sprintf (text,"%s FW", text); font_gfxdraw (p.x + GFX_IMGSIZE, p.y + font[0].size.y + font[2].size.y - 4, text, 0, COLOR_white, 10002); } } else { /* * player is free */ font_gfxdraw (p.x + GFX_IMGSIZE, p.y, "No Player" , 0, COLOR_gray, 10002); } }; /* * draw all player informations */ void mw_draw_all_player () { int i,j,h; int n[MAX_PLAYERS]; for(i=0;iplayers[j].points) { #else if (players[i].wins>players[j].wins) { #endif h=n[i];n[i]=n[j];n[j]=h; } j=0; for (i = 0; i < MAX_PLAYERS; i++) { if (PS_IS_used (players[n[i]].state)) { mw_draw_player (n[i], j); j++; } } gfx_blitdraw(); }; /* * draw only the given team */ void mw_draw_team (int t_nr, int pos) { _player *player; _team *team; _point p; int i,j=0; char text[255]; SDL_Rect src; SDL_Rect dest; team=&teams[t_nr]; p.x = mw_pos[pos].x; p.y = mw_pos[pos].y; /* Find if there is any active player in that team */ if (mw_team_is_used(t_nr)>0) { /* * team is used */ font_gfxdraw (p.x + GFX_IMGSIZE, p.y, team->name, 1, COLOR_yellow, 10002); sprintf (text,"Victorys:%2d(%d)", team->wins, team->points); font_gfxdraw (p.x + GFX_IMGSIZE, p.y + font[2].size.y - 4, text, 0, COLOR_white, 10002); j=1; for(i=0;iplayers[i]!=NULL) && (PS_IS_used(team->players[i]->state))) { player=team->players[i]; if (player->gfx_nr >= 0 && player->gfx_nr < gfx.player_gfx_count) { /* player is used and selected a gfx */ dest.x = p.x; src.x = 0; src.y = 0; dest.x=p.x+35+20; dest.y = p.y + 30+j*15; src.w = dest.w = gfx.players[player->gfx_nr].small_image->w; src.h = dest.h = gfx.players[player->gfx_nr].small_image->h; gfx_blit (gfx.players[player->gfx_nr].small_image, &src, gfx.screen, &dest, 10001); } font_gfxdraw (p.x + GFX_IMGSIZE+20, p.y + 30+j*15, team->players[i]->name, 0, COLOR_white, 10002); j++; } } } else { /* * team is emty */ font_gfxdraw (p.x + GFX_IMGSIZE, p.y, "No TEAM" , 0, COLOR_gray, 10002); } }; /* Draw players which are not assigned to any team */ void mw_draw_unassigned_players () { int i, n=0; char text[255]; sprintf(text,"Unassigned Players: "); for (i=0;iteams[j].points) { #else if (teams[i].wins>teams[j].wins) { #endif h=n[i];n[i]=n[j];n[j]=h; } j=0; for (i = 0; i < MAX_TEAMS; i++) { if (mw_team_is_used(n[i])) { mw_draw_team (n[i], j); j++; } } mw_draw_unassigned_players(); gfx_blitdraw(); }; /* * check if one key is pressed */ void mw_keys_loop () { if (GT_MP_PTPM && mw_num_readyplayers >= 2 && keyb_gamekeys.state[BCK_pause] && !keyb_gamekeys.old[BCK_pause]) { /* min 2 players are ready for the game and * the start key has pressed */ bman.state = GS_ready; bman.updatestatusbar = 1; // force an update } if (keyb_gamekeys.state[BCK_fullscreen] && !keyb_gamekeys.old[BCK_fullscreen]) { /* Switch Fullscreen */ SDL_WM_ToggleFullScreen(gfx.screen); gfx.fullscreen = !gfx.fullscreen; bman.updatestatusbar = 1; // force an update bman.updatestatusbar = 1; } if (keyb_gamekeys.state[BCK_esc] && !keyb_gamekeys.old[BCK_esc]) { /* ESCAPE key was pressed */ bman.state = GS_startup; } if ((keyb_gamekeys.state[BCPK_drop] && !keyb_gamekeys.old[BCPK_drop]) || ((!IS_LPLAYER2) && keyb_gamekeys.state[BCPK_max + BCPK_drop] && !keyb_gamekeys.old[BCPK_max + BCPK_drop])) { /* player 1 want to select a new gfx */ playermenu_selgfx (bman.p_nr); net_change_playerid (bman.p_nr, 1); bman.updatestatusbar = 1; keyb_loop (NULL); // to reload the current keys } if (IS_LPLAYER2 && keyb_gamekeys.state[BCPK_max + BCPK_drop] && !keyb_gamekeys.old[BCPK_max + BCPK_drop]) { /* player 2 want to select a new gfx */ playermenu_selgfx (bman.p2_nr); net_change_playerid (bman.p2_nr, 1); bman.updatestatusbar = 1; keyb_loop (NULL); // to reload the current keys } if (keyb_gamekeys.state[BCK_mapmenu] && !keyb_gamekeys.old[BCK_mapmenu] && GT_MP_PTPM) { /* mapmenu */ mapmenu (); bman.updatestatusbar = 1; keyb_loop (NULL); // to reload the current keys } if (keyb_gamekeys.state[BCK_playermenu] && !keyb_gamekeys.old[BCK_playermenu]) { /* playermenu */ playermenu (); bman.updatestatusbar = 1; keyb_loop (NULL); // to reload the current keys } }; /* the loop itself */ void wait_for_players () { SDL_Event event; mw_init (); mw_calc_screen(); if (bman.gametype==GT_team) mw_draw_all_teams(); else mw_draw_all_player (); do { if (SDL_PollEvent (&event) != 0) switch (event.type) { case (SDL_QUIT): bman.state = GS_quit; break; } /* * check some little things and do the network stuff */ mw_check_players (); network_loop (); /* * the drawing stuff */ if (mw_calc_screen()) { 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; s_calctimesync (); } while (bman.state == GS_wait && bman.sock != -1); mw_shutdown (); };