2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/Network/multi_team.cpp $
16 * Revision 1.3 2002/06/09 04:41:24 relnev
17 * added copyright header
19 * Revision 1.2 2002/05/07 03:16:47 theoddone33
20 * The Great Newline Fix
22 * Revision 1.1.1.1 2002/05/03 03:28:10 root
26 * 13 9/08/99 1:59p Dave
27 * Nailed the problem with assigning teams improperly in TvT. Basic
28 * problem was that clients were sending team update packets with bogus
29 * info that the server was willingly accepting, thereby blowing away his
32 * 12 8/22/99 1:55p Dave
33 * Cleaned up host/team-captain leaving code.
35 * 11 8/22/99 1:19p Dave
36 * Fixed up http proxy code. Cleaned up scoring code. Reverse the order in
37 * which d3d cards are detected.
39 * 10 4/09/99 2:21p Dave
40 * Multiplayer beta stuff. CD checking.
42 * 9 3/10/99 6:50p Dave
43 * Changed the way we buffer packets for all clients. Optimized turret
44 * fired packets. Did some weapon firing optimizations.
46 * 8 3/09/99 6:24p Dave
47 * More work on object update revamping. Identified several sources of
48 * unnecessary bandwidth.
50 * 7 2/17/99 2:11p Dave
51 * First full run of squad war. All freespace and tracker side stuff
54 * 6 2/11/99 3:08p Dave
55 * PXO refresh button. Very preliminary squad war support.
57 * 5 11/19/98 8:03a Dave
58 * Full support for D3-style reliable sockets. Revamped packet lag/loss
59 * system, made it receiver side and at the lowest possible level.
61 * 4 11/17/98 11:12a Dave
62 * Removed player identification by address. Now assign explicit id #'s.
64 * 3 11/05/98 5:55p Dave
65 * Big pass at reducing #includes
67 * 2 10/07/98 10:53a Dave
70 * 1 10/07/98 10:50a Dave
72 * 18 6/13/98 3:19p Hoffoss
73 * NOX()ed out a bunch of strings that shouldn't be translated.
75 * 17 5/26/98 7:33p Dave
76 * Once extra check for TvT oktocommit. Tested against all cases.
78 * 16 5/22/98 9:35p Dave
79 * Put in channel based support for PXO. Put in "shutdown" button for
80 * standalone. UI tweaks for TvT
82 * 15 5/15/98 5:16p Dave
83 * Fix a standalone resetting bug.Tweaked PXO interface. Display captaincy
84 * status for team vs. team. Put in asserts to check for invalid team vs.
87 * 14 5/03/98 7:04p Dave
88 * Make team vs. team work mores smoothly with standalone. Change how host
89 * interacts with standalone for picking missions. Put in a time limit for
90 * ingame join ship select. Fix ingame join ship select screen for Vasudan
93 * 13 4/22/98 5:53p Dave
94 * Large reworking of endgame sequencing. Updated multi host options
95 * screen for new artwork. Put in checks for host or team captains leaving
98 * 12 4/15/98 5:03p Dave
99 * Put in a rough countdown to mission start on final sync screen. Fixed
100 * several team vs. team bugs on the ship/team select screen.
102 * 11 4/14/98 12:57a Dave
103 * Made weapon select screen show netplayer names above ships. Fixed pilot
104 * info popup to show the status of pilot images more correctly.
106 * 10 4/08/98 2:51p Dave
107 * Fixed pilot image xfer once again. Solidify team selection process in
108 * pre-briefing multiplayer.
110 * 9 4/04/98 4:22p Dave
111 * First rev of UDP reliable sockets is done. Seems to work well if not
114 * 8 4/03/98 1:03a Dave
115 * First pass at unreliable guaranteed delivery packets.
117 * 7 3/31/98 4:51p Dave
118 * Removed medals screen and multiplayer buttons from demo version. Put in
119 * new pilot popup screen. Make ships in mp team vs. team have proper team
120 * ids. Make mp respawns a permanent option saved in the player file.
122 * 6 3/15/98 4:17p Dave
123 * Fixed oberver hud problems. Put in handy netplayer macros. Reduced size
124 * of network orientation matrices.
126 * 5 3/12/98 5:45p Dave
127 * Put in new observer HUD. Made it possible for observers to join at the
128 * beginning of a game and follow it around as an observer full-time.
130 * 4 3/10/98 4:26p Dave
131 * Second pass at furball mode. Fixed several team vs. team bugs.
133 * 3 3/09/98 5:54p Dave
134 * Fixed stats to take asteroid hits into account. Polished up UI stuff in
135 * team select. Finished up pilot info popup. Tracked down and fixed
138 * 2 3/03/98 8:55p Dave
139 * Finished pre-briefing team vs. team support.
141 * 1 3/03/98 5:09p Dave
146 #include "freespace.h"
147 #include "linklist.h"
148 #include "multimsgs.h"
149 #include "multiutil.h"
150 #include "multi_team.h"
151 #include "multi_endgame.h"
152 #include "multi_pmsg.h"
155 // ------------------------------------------------------------------------------------
156 // MULTIPLAYER TEAMPLAY DEFINES/VARS
160 #define MT_CODE_TEAM_UPDATE 0 // send a full team update on a player-per-player basis
161 #define MT_CODE_TEAM_REQUEST 1 // a request sent to the host to be be on a given team
165 char *Multi_team0_names[4] = { // ships on team 0 (TEAM_FRIENDLY)
166 "alpha 1", "alpha 2", "alpha 3", "alpha 4"
168 char *Multi_team1_names[4] = { // ships on team 1 (TEAM_HOSTILE)
169 "zeta 1", "zeta 2", "zeta 3", "zeta 4"
172 // score for teams 0 and 1 for this mission
173 int Multi_team0_score = 0;
174 int Multi_team1_score = 0;
177 // ------------------------------------------------------------------------------------
178 // MULTIPLAYER TEAMPLAY FORWARD DECLARATIONS
181 // process a request to change a team
182 void multi_team_process_team_change_request(net_player *pl,net_player *who_from,int team);
184 // send a packet to the host requesting to change my team
185 void multi_team_send_team_request(net_player *pl,int team);
187 // have the netgame host assign default teams
188 void multi_team_host_assign_default_teams();
190 // check to make sure all teams have a proper captain.
191 void multi_team_sync_captains();
193 // process a team update packet, return bytes processed
194 int multi_team_process_team_update(ubyte *data);
197 // ------------------------------------------------------------------------------------
198 // MULTIPLAYER TEAMPLAY FUNCTIONS
201 // call before level load (pre-sync)
202 void multi_team_level_init()
204 // score for teams 0 and 1 for this mission
205 Multi_team0_score = 0;
206 Multi_team1_score = 0;
209 // call to determine who won the sw match, -1 == tie, 0 == team 0, 1 == team 1
210 int multi_team_winner()
215 if(Multi_team0_score == Multi_team1_score){
220 if(Multi_team0_score > Multi_team1_score){
224 // team 1 must have won
228 // call to add score to a team
229 void multi_team_maybe_add_score(int points, int team)
231 // if we're not in multiplayer mode
232 if(!(Game_mode & GM_MULTIPLAYER)){
237 if(!(Netgame.type_flags & NG_TYPE_TEAM)){
241 // if i'm not the server of the game, bail here
242 if(!MULTIPLAYER_MASTER){
249 nprintf(("Network", "TVT : adding %d points to team 0 (total == %d)\n", points, points + Multi_team0_score));
250 Multi_team0_score += points;
254 nprintf(("Network", "TVT : adding %d points to team 1 (total == %d)\n", points, points + Multi_team1_score));
255 Multi_team1_score += points;
260 // reset all players and assign them to default teams
261 void multi_team_reset()
265 nprintf(("Network","MULTI TEAM : resetting\n"));
267 // unset everyone's captaincy and locked flags
268 for(idx=0;idx<MAX_PLAYERS;idx++){
269 if(MULTI_CONNECTED(Net_players[idx])){
270 Net_players[idx].p_info.team = 0;
271 Net_players[idx].flags &= ~(NETINFO_FLAG_TEAM_LOCKED | NETINFO_FLAG_TEAM_CAPTAIN);
275 // host should divvy up the teams, send a reset notice to all players and assign captains
276 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
277 // divvy up the teams here
278 multi_team_host_assign_default_teams();
282 // set the captaincy status of this player
283 void multi_team_set_captain(net_player *pl,int set)
285 // only the host should ever get here!
286 Assert(Net_player->flags & NETINFO_FLAG_AM_MASTER);
288 // set the player flags as being a captain and notify everyone else of this
290 nprintf(("Network","MULTI TEAM : Server setting player %s team %d captain\n",pl->player->callsign,pl->p_info.team));
291 pl->flags |= NETINFO_FLAG_TEAM_CAPTAIN;
293 nprintf(("Network","MULTI TEAM : Server unsetting player %s as team %d captain\n",pl->player->callsign,pl->p_info.team));
294 pl->flags &= ~(NETINFO_FLAG_TEAM_CAPTAIN);
298 // set the team of this given player (if called by the host, the player becomes locked, cnad only the host can modify him from thereon)
299 void multi_team_set_team(net_player *pl,int team)
301 // if i'm the server of the game, do it now
302 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
303 nprintf(("Network","MULTI TEAM : Server/Host setting player %s to team %d and locking\n",pl->player->callsign,team));
305 pl->p_info.team = team;
307 if(Net_player->flags & NETINFO_FLAG_GAME_HOST){
308 pl->flags |= NETINFO_FLAG_TEAM_LOCKED;
310 pl->flags &= ~(NETINFO_FLAG_TEAM_CAPTAIN);
312 // check to see if the resulting team rosters need a captain
313 multi_team_sync_captains();
315 nprintf(("Network","MULTI TEAM : Sending team change request to server\n"));
316 multi_team_send_team_request(pl,team);
319 // verify that we have valid team stuff
323 // process a request to change a team
324 void multi_team_process_team_change_request(net_player *pl,net_player *who_from,int team)
326 // if this player has already been locked, don't do anything
327 if((pl->flags & NETINFO_FLAG_TEAM_LOCKED) && !(who_from->flags & NETINFO_FLAG_GAME_HOST)){
328 nprintf(("Network","MULTI TEAM : Server ignoring team change request because player is locked\n"));
332 // otherwise set the team for the player and send an update
333 nprintf(("Network","MULTI TEAM : Server changing player %s to team %d from client request\n",pl->player->callsign,team));
334 pl->p_info.team = team;
335 pl->flags &= ~(NETINFO_FLAG_TEAM_CAPTAIN);
337 // if this came from the host, lock the player down
338 if(who_from->flags & NETINFO_FLAG_GAME_HOST){
339 pl->flags |= NETINFO_FLAG_TEAM_LOCKED;
342 // check to see if the resulting team rosters need a captain
343 multi_team_sync_captains();
345 // send a team update
346 multi_team_send_update();
348 // verify that we have valid team stuff
352 // have the netgame host assign default teams
353 void multi_team_host_assign_default_teams()
355 int player_count,idx;
358 // first determine how many players there are in the game
360 for(idx=0;idx<MAX_PLAYERS;idx++){
361 // count anyone except the standalone server (if applicable)
362 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
367 // determine how many players should be stuck on team 0
368 if(player_count < 2){
371 team0_count = player_count / 2;
374 // assign the players to team 0
376 while(team0_count > 0){
377 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
378 Net_players[idx].p_info.team = 0;
379 Net_players[idx].flags &= ~(NETINFO_FLAG_TEAM_LOCKED);
380 Net_players[idx].flags &= ~(NETINFO_FLAG_TEAM_CAPTAIN);
387 // assign the remaining players to team 1
388 while(idx < MAX_PLAYERS){
389 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
390 Net_players[idx].p_info.team = 1;
391 Net_players[idx].flags &= ~(NETINFO_FLAG_TEAM_LOCKED);
392 Net_players[idx].flags &= ~(NETINFO_FLAG_TEAM_CAPTAIN);
398 multi_team_sync_captains();
400 // send a full update to all players
401 multi_team_send_update();
403 // verify that we have valid team stuff
407 // check to see if the team this player on needs a captain and assign him if so
408 void multi_team_sync_captains()
411 int team0_cap,team1_cap;
413 // if I'm not the server, bail
414 if(!MULTIPLAYER_MASTER){
418 // determine if any team now needs a captain
421 for(idx=0;idx<MAX_PLAYERS;idx++){
422 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx]) && (Net_players[idx].flags & NETINFO_FLAG_TEAM_CAPTAIN)){
423 switch(Net_players[idx].p_info.team){
434 // if team 0 needs a captain, get one
436 for(idx=0;idx<MAX_PLAYERS;idx++){
437 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx]) && (Net_players[idx].p_info.team == 0) && !(Net_players[idx].flags & NETINFO_FLAG_TEAM_CAPTAIN)){
438 multi_team_set_captain(&Net_players[idx],1);
444 // if team 1 needs a captain, get one
446 for(idx=0;idx<MAX_PLAYERS;idx++){
447 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx]) && (Net_players[idx].p_info.team == 1) && !(Net_players[idx].flags & NETINFO_FLAG_TEAM_CAPTAIN)){
448 multi_team_set_captain(&Net_players[idx],1);
455 // is it ok for the host to hit commit
456 int multi_team_ok_to_commit()
458 int team0_captains,team1_captains;
459 int team0_count,team1_count;
462 // verify that we have valid team stuff
465 // check to see if both teams have a captain
469 for(idx=0;idx<MAX_PLAYERS;idx++){
470 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
471 // if this is team 0's captain
472 if((Net_players[idx].p_info.team == 0) && (Net_players[idx].flags & NETINFO_FLAG_TEAM_CAPTAIN)){
474 } else if((Net_players[idx].p_info.team == 1) && (Net_players[idx].flags & NETINFO_FLAG_TEAM_CAPTAIN)){
480 // check to see if both teams has <= 4 players
481 multi_team_get_player_counts(&team0_count,&team1_count);
482 team0_count = ((team0_count <= 4) && (team0_count > 0)) ? 1 : 0;
483 team1_count = ((team1_count <= 4) && (team1_count > 0)) ? 1 : 0;
485 return ((team0_captains == 1) && (team1_captains == 1) && team0_count && team1_count) ? 1 : 0;
488 // handle a player drop
489 void multi_team_handle_drop()
492 int team0_cap, team1_cap;
494 // if I'm not the server, bail
495 if(!MULTIPLAYER_MASTER){
499 // if we're not in a team vs team situation, we don't care
500 if(!(Netgame.type_flags & NG_TYPE_TEAM)){
504 // is either team at 0 players, ingame?
505 if(Game_mode & GM_IN_MISSION){
506 int team0_count, team1_count;
507 multi_team_get_player_counts(&team0_count, &team1_count);
508 if(team0_count <= 0){
509 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_TEAM0_EMPTY);
512 if(team1_count <= 0){
513 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_TEAM1_EMPTY);
518 // check to see if a team captain has left the game
521 for(idx=0;idx<MAX_PLAYERS;idx++){
522 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx]) && (Net_players[idx].flags & NETINFO_FLAG_TEAM_CAPTAIN)){
523 switch(Net_players[idx].p_info.team){
534 // if we have lost a team captain and we're not in the forming state, abort the game
535 if((!team0_cap || !team1_cap) && (Netgame.game_state != NETGAME_STATE_FORMING)){
536 // if we're in-mission, just sync up captains
537 if(Game_mode & GM_IN_MISSION){
539 multi_team_sync_captains();
541 // send a team update
542 multi_team_send_update();
544 // find the player who is the new captain
545 int team_check = team0_cap ? 1 : 0;
546 for(idx=0; idx<MAX_PLAYERS; idx++){
547 if(MULTI_CONNECTED(Net_players[idx]) && (Net_players[idx].flags & NETINFO_FLAG_TEAM_CAPTAIN) && (Net_players[idx].p_info.team == team_check)){
548 send_host_captain_change_packet(Net_players[idx].player_id, 1);
555 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_CAPTAIN_LEFT);
557 // otherwise sync things up and be done with it.
559 // sync up team captains
560 multi_team_sync_captains();
562 // send a team update
563 multi_team_send_update();
565 // verify that we have valid team stuff
570 // handle a player join
571 void multi_team_handle_join(net_player *pl)
573 int team0_count,team1_count,idx,team_select;
575 // if we're not in a team vs team situation, we don't care
576 if(!(Netgame.type_flags & NG_TYPE_TEAM)){
580 // if the joining player is joining as an observer, don't put him on a team
581 if(pl->flags & NETINFO_FLAG_OBSERVER){
585 // only the host should ever do this
586 Assert(Net_player->flags & NETINFO_FLAG_AM_MASTER);
587 if(!(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
591 // count the # of players on each time
594 for(idx=0;idx<MAX_PLAYERS;idx++){
595 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
596 // player is on team 0
597 if(Net_players[idx].p_info.team == 0){
600 // player is on team 1
601 else if(Net_players[idx].p_info.team == 1){
604 // some other case - should never happen
611 // determine what team he should be on
612 if((team0_count == team1_count) || (team0_count < team1_count)){
618 // place him on the team, but don't lock him yet
619 multi_team_set_team(pl,team_select);
620 pl->flags &= ~(NETINFO_FLAG_TEAM_LOCKED);
622 // send a team update
623 multi_team_send_update();
625 // verify that we have valid team stuff
629 // set all ships in the mission to be marked as the proper team (TEAM_HOSTILE, TEAM_FRIENLY)
630 void multi_team_mark_all_ships()
634 // look through all ships in the mission
635 moveup = GET_FIRST(&Ship_obj_list);
636 while(moveup!=END_OF_LIST(&Ship_obj_list)){
637 multi_team_mark_ship(&Ships[Objects[moveup->objnum].instance]);
639 moveup = GET_NEXT(moveup);
642 // verify that we have valid team stuff
646 // set the proper team for the passed in ship
647 void multi_team_mark_ship(ship *sp)
655 // look through team 0
656 for(idx=0;idx<4;idx++){
657 if(!stricmp(sp->ship_name,Multi_team0_names[idx])){
663 // look through team 1 if necessary
665 for(idx=0;idx<4;idx++){
666 if(!stricmp(sp->ship_name,Multi_team1_names[idx])){
673 // if we found a team
676 sp->team = TEAM_FRIENDLY;
679 sp->team = TEAM_HOSTILE;
683 // verify that we have valid team stuff
687 // host locks all players into their teams
688 void multi_team_host_lock_all()
692 // lock all players down
693 for(idx=0;idx<MAX_PLAYERS;idx++){
694 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
695 Net_players[idx].flags |= NETINFO_FLAG_TEAM_LOCKED;
699 // verify that we have valid team stuff
703 // get the player counts for team 0 and team 1 (NULL values are valid)
704 void multi_team_get_player_counts(int *team0, int *team1)
708 // initialize the values
717 for(idx=0;idx<MAX_PLAYERS;idx++){
718 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
719 if((Net_players[idx].p_info.team == 0) && (team0 != NULL)){
721 } else if((Net_players[idx].p_info.team == 1) && (team1 != NULL)){
728 // report on the winner/loser of the game via chat text
729 #define SEND_AND_DISPLAY(mesg) do { send_game_chat_packet(Net_player, mesg, MULTI_MSG_ALL, NULL, NULL, 1); multi_display_chat_msg(mesg, 0, 0); } while(0);
730 void multi_team_report()
732 char report[400] = "";
735 SEND_AND_DISPLAY("----****");
738 sprintf(report, XSTR("<Team 1 had %d points>", 1275), Multi_team0_score);
739 SEND_AND_DISPLAY(report);
740 sprintf(report, XSTR("<Team 2 had %d points>", 1276), Multi_team1_score);
741 SEND_AND_DISPLAY(report);
744 switch(multi_team_winner()){
746 SEND_AND_DISPLAY(XSTR("<Match was a tie>", 1277));
750 SEND_AND_DISPLAY(XSTR("<Team 1 (green) is the winner>", 1278));
754 SEND_AND_DISPLAY(XSTR("<Team 2 (red) is the winner>", 1279));
758 SEND_AND_DISPLAY("----****");
762 // ------------------------------------------------------------------------------------
763 // MULTIPLAYER TEAMPLAY PACKET HANDLERS
766 // process an incoming team update packet
767 void multi_team_process_packet(unsigned char *data, header *hinfo)
771 int offset = HEADER_LENGTH;
773 // find out who is sending this data
774 player_index = find_player_id(hinfo->id);
776 // get the packet opcode
779 // take action absed upon the opcode
781 // a request to set the team for a player
782 case MT_CODE_TEAM_REQUEST:
784 int req_index,req_team;
786 Assert(Net_player->flags & NETINFO_FLAG_AM_MASTER);
788 // get the packet data
792 // if i'm the host of the game, process here
793 req_index = find_player_id(player_id);
795 nprintf(("Network","Could not find player to process team change request !\n"));
797 multi_team_process_team_change_request(&Net_players[req_index],&Net_players[player_index],req_team);
801 // a full team update
802 case MT_CODE_TEAM_UPDATE:
803 offset += multi_team_process_team_update(data+offset);
809 // verify that we have valid team stuff
813 // send a packet to the host requesting to change my team
814 void multi_team_send_team_request(net_player *pl, int team)
816 ubyte data[MAX_PACKET_SIZE],code;
819 // build the header and add the opcode
820 BUILD_HEADER(TEAM_UPDATE);
821 code = MT_CODE_TEAM_REQUEST;
824 // add the address of the guy we want to change
825 ADD_DATA(pl->player_id);
827 // add the team I want to be on
830 // send to the server of the game (will be routed to host if in a standalone situation)
831 multi_io_send_reliable(Net_player, data, packet_size);
834 // send a full update on a player-per-player basis (should call this to update all players after other relevant function calls)
835 void multi_team_send_update()
837 ubyte data[MAX_PACKET_SIZE],val,stop;
841 // if I'm not the server, bail
842 if(!MULTIPLAYER_MASTER){
846 // first, verify that we have valid settings
849 // build the header and add the opcode
850 BUILD_HEADER(TEAM_UPDATE);
851 val = MT_CODE_TEAM_UPDATE;
854 // add the info for all players;
855 for(idx=0;idx<MAX_PLAYERS;idx++){
856 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx])){
862 ADD_DATA(Net_players[idx].player_id);
864 // pack all his data into a byte
867 // set bit 0 if he's on team 1
868 if(Net_players[idx].p_info.team == 1){
872 // set bit 1 if he's a team captain
873 if(Net_players[idx].flags & NETINFO_FLAG_TEAM_CAPTAIN){
880 // add the final stop byte
884 // if i'm the server, I should broadcast to this to all players, otherwise I should send it to the standalone
885 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
886 multi_io_send_to_all_reliable(data, packet_size);
888 multi_io_send_reliable(Net_player, data, packet_size);
892 // process a team update packet, return bytes processed
893 int multi_team_process_team_update(ubyte *data)
900 // if I'm the server, bail
901 Assert(!MULTIPLAYER_MASTER);
903 // process all players
906 // get the net address and flags for the guy
910 // do a player lookup
911 if(!MULTIPLAYER_MASTER){
912 player_index = find_player_id(player_id);
913 if(player_index != -1){
914 // set his team correctly
916 Net_players[player_index].p_info.team = 1;
918 Net_players[player_index].p_info.team = 0;
921 // set his captaincy flag correctly
922 Net_players[player_index].flags &= ~(NETINFO_FLAG_TEAM_CAPTAIN);
924 Net_players[player_index].flags |= NETINFO_FLAG_TEAM_CAPTAIN;
929 // get the next stop byte
933 // verify that we have valid team stuff
936 // return bytes processed
940 // verify that we have valid team stuff
941 void multi_team_verify()
944 int team0_count,team0_cap;
945 int team1_count,team1_cap;
948 // determine how many players we have on team 0 and if they have a captain
951 for(idx=0;idx<MAX_PLAYERS;idx++){
952 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx])){
954 if(Net_players[idx].p_info.team == 0){
958 if(Net_players[idx].flags & NETINFO_FLAG_TEAM_CAPTAIN){
964 // if the team has members
966 // make sure it also has a captain
967 Assert(team0_cap > 0);
969 // make sure it only has 1 captain
970 Assert(team0_cap == 1);
973 // determine how many players we have on team 1 and if they have a captain
976 for(idx=0;idx<MAX_PLAYERS;idx++){
977 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx])){
979 if(Net_players[idx].p_info.team == 1){
983 if(Net_players[idx].flags & NETINFO_FLAG_TEAM_CAPTAIN){
989 // if the team has members
991 // make sure it also has a captain
992 Assert(team1_cap > 0);
994 // make sure it only has 1 captain
995 Assert(team1_cap == 1);