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.4 2004/06/11 01:45:13 tigital
17 * byte-swapping changes for bigendian systems
19 * Revision 1.3 2002/06/09 04:41:24 relnev
20 * added copyright header
22 * Revision 1.2 2002/05/07 03:16:47 theoddone33
23 * The Great Newline Fix
25 * Revision 1.1.1.1 2002/05/03 03:28:10 root
29 * 13 9/08/99 1:59p Dave
30 * Nailed the problem with assigning teams improperly in TvT. Basic
31 * problem was that clients were sending team update packets with bogus
32 * info that the server was willingly accepting, thereby blowing away his
35 * 12 8/22/99 1:55p Dave
36 * Cleaned up host/team-captain leaving code.
38 * 11 8/22/99 1:19p Dave
39 * Fixed up http proxy code. Cleaned up scoring code. Reverse the order in
40 * which d3d cards are detected.
42 * 10 4/09/99 2:21p Dave
43 * Multiplayer beta stuff. CD checking.
45 * 9 3/10/99 6:50p Dave
46 * Changed the way we buffer packets for all clients. Optimized turret
47 * fired packets. Did some weapon firing optimizations.
49 * 8 3/09/99 6:24p Dave
50 * More work on object update revamping. Identified several sources of
51 * unnecessary bandwidth.
53 * 7 2/17/99 2:11p Dave
54 * First full run of squad war. All freespace and tracker side stuff
57 * 6 2/11/99 3:08p Dave
58 * PXO refresh button. Very preliminary squad war support.
60 * 5 11/19/98 8:03a Dave
61 * Full support for D3-style reliable sockets. Revamped packet lag/loss
62 * system, made it receiver side and at the lowest possible level.
64 * 4 11/17/98 11:12a Dave
65 * Removed player identification by address. Now assign explicit id #'s.
67 * 3 11/05/98 5:55p Dave
68 * Big pass at reducing #includes
70 * 2 10/07/98 10:53a Dave
73 * 1 10/07/98 10:50a Dave
75 * 18 6/13/98 3:19p Hoffoss
76 * NOX()ed out a bunch of strings that shouldn't be translated.
78 * 17 5/26/98 7:33p Dave
79 * Once extra check for TvT oktocommit. Tested against all cases.
81 * 16 5/22/98 9:35p Dave
82 * Put in channel based support for PXO. Put in "shutdown" button for
83 * standalone. UI tweaks for TvT
85 * 15 5/15/98 5:16p Dave
86 * Fix a standalone resetting bug.Tweaked PXO interface. Display captaincy
87 * status for team vs. team. Put in asserts to check for invalid team vs.
90 * 14 5/03/98 7:04p Dave
91 * Make team vs. team work mores smoothly with standalone. Change how host
92 * interacts with standalone for picking missions. Put in a time limit for
93 * ingame join ship select. Fix ingame join ship select screen for Vasudan
96 * 13 4/22/98 5:53p Dave
97 * Large reworking of endgame sequencing. Updated multi host options
98 * screen for new artwork. Put in checks for host or team captains leaving
101 * 12 4/15/98 5:03p Dave
102 * Put in a rough countdown to mission start on final sync screen. Fixed
103 * several team vs. team bugs on the ship/team select screen.
105 * 11 4/14/98 12:57a Dave
106 * Made weapon select screen show netplayer names above ships. Fixed pilot
107 * info popup to show the status of pilot images more correctly.
109 * 10 4/08/98 2:51p Dave
110 * Fixed pilot image xfer once again. Solidify team selection process in
111 * pre-briefing multiplayer.
113 * 9 4/04/98 4:22p Dave
114 * First rev of UDP reliable sockets is done. Seems to work well if not
117 * 8 4/03/98 1:03a Dave
118 * First pass at unreliable guaranteed delivery packets.
120 * 7 3/31/98 4:51p Dave
121 * Removed medals screen and multiplayer buttons from demo version. Put in
122 * new pilot popup screen. Make ships in mp team vs. team have proper team
123 * ids. Make mp respawns a permanent option saved in the player file.
125 * 6 3/15/98 4:17p Dave
126 * Fixed oberver hud problems. Put in handy netplayer macros. Reduced size
127 * of network orientation matrices.
129 * 5 3/12/98 5:45p Dave
130 * Put in new observer HUD. Made it possible for observers to join at the
131 * beginning of a game and follow it around as an observer full-time.
133 * 4 3/10/98 4:26p Dave
134 * Second pass at furball mode. Fixed several team vs. team bugs.
136 * 3 3/09/98 5:54p Dave
137 * Fixed stats to take asteroid hits into account. Polished up UI stuff in
138 * team select. Finished up pilot info popup. Tracked down and fixed
141 * 2 3/03/98 8:55p Dave
142 * Finished pre-briefing team vs. team support.
144 * 1 3/03/98 5:09p Dave
149 #include "freespace.h"
150 #include "linklist.h"
151 #include "multimsgs.h"
152 #include "multiutil.h"
153 #include "multi_team.h"
154 #include "multi_endgame.h"
155 #include "multi_pmsg.h"
158 // ------------------------------------------------------------------------------------
159 // MULTIPLAYER TEAMPLAY DEFINES/VARS
163 #define MT_CODE_TEAM_UPDATE 0 // send a full team update on a player-per-player basis
164 #define MT_CODE_TEAM_REQUEST 1 // a request sent to the host to be be on a given team
168 char *Multi_team0_names[4] = { // ships on team 0 (TEAM_FRIENDLY)
169 "alpha 1", "alpha 2", "alpha 3", "alpha 4"
171 char *Multi_team1_names[4] = { // ships on team 1 (TEAM_HOSTILE)
172 "zeta 1", "zeta 2", "zeta 3", "zeta 4"
175 // score for teams 0 and 1 for this mission
176 int Multi_team0_score = 0;
177 int Multi_team1_score = 0;
180 // ------------------------------------------------------------------------------------
181 // MULTIPLAYER TEAMPLAY FORWARD DECLARATIONS
184 // process a request to change a team
185 void multi_team_process_team_change_request(net_player *pl,net_player *who_from,int team);
187 // send a packet to the host requesting to change my team
188 void multi_team_send_team_request(net_player *pl,int team);
190 // have the netgame host assign default teams
191 void multi_team_host_assign_default_teams();
193 // check to make sure all teams have a proper captain.
194 void multi_team_sync_captains();
196 // process a team update packet, return bytes processed
197 int multi_team_process_team_update(ubyte *data);
200 // ------------------------------------------------------------------------------------
201 // MULTIPLAYER TEAMPLAY FUNCTIONS
204 // call before level load (pre-sync)
205 void multi_team_level_init()
207 // score for teams 0 and 1 for this mission
208 Multi_team0_score = 0;
209 Multi_team1_score = 0;
212 // call to determine who won the sw match, -1 == tie, 0 == team 0, 1 == team 1
213 int multi_team_winner()
218 if(Multi_team0_score == Multi_team1_score){
223 if(Multi_team0_score > Multi_team1_score){
227 // team 1 must have won
231 // call to add score to a team
232 void multi_team_maybe_add_score(int points, int team)
234 // if we're not in multiplayer mode
235 if(!(Game_mode & GM_MULTIPLAYER)){
240 if(!(Netgame.type_flags & NG_TYPE_TEAM)){
244 // if i'm not the server of the game, bail here
245 if(!MULTIPLAYER_MASTER){
252 nprintf(("Network", "TVT : adding %d points to team 0 (total == %d)\n", points, points + Multi_team0_score));
253 Multi_team0_score += points;
257 nprintf(("Network", "TVT : adding %d points to team 1 (total == %d)\n", points, points + Multi_team1_score));
258 Multi_team1_score += points;
263 // reset all players and assign them to default teams
264 void multi_team_reset()
268 nprintf(("Network","MULTI TEAM : resetting\n"));
270 // unset everyone's captaincy and locked flags
271 for(idx=0;idx<MAX_PLAYERS;idx++){
272 if(MULTI_CONNECTED(Net_players[idx])){
273 Net_players[idx].p_info.team = 0;
274 Net_players[idx].flags &= ~(NETINFO_FLAG_TEAM_LOCKED | NETINFO_FLAG_TEAM_CAPTAIN);
278 // host should divvy up the teams, send a reset notice to all players and assign captains
279 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
280 // divvy up the teams here
281 multi_team_host_assign_default_teams();
285 // set the captaincy status of this player
286 void multi_team_set_captain(net_player *pl,int set)
288 // only the host should ever get here!
289 Assert(Net_player->flags & NETINFO_FLAG_AM_MASTER);
291 // set the player flags as being a captain and notify everyone else of this
293 nprintf(("Network","MULTI TEAM : Server setting player %s team %d captain\n",pl->player->callsign,pl->p_info.team));
294 pl->flags |= NETINFO_FLAG_TEAM_CAPTAIN;
296 nprintf(("Network","MULTI TEAM : Server unsetting player %s as team %d captain\n",pl->player->callsign,pl->p_info.team));
297 pl->flags &= ~(NETINFO_FLAG_TEAM_CAPTAIN);
301 // 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)
302 void multi_team_set_team(net_player *pl,int team)
304 // if i'm the server of the game, do it now
305 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
306 nprintf(("Network","MULTI TEAM : Server/Host setting player %s to team %d and locking\n",pl->player->callsign,team));
308 pl->p_info.team = team;
310 if(Net_player->flags & NETINFO_FLAG_GAME_HOST){
311 pl->flags |= NETINFO_FLAG_TEAM_LOCKED;
313 pl->flags &= ~(NETINFO_FLAG_TEAM_CAPTAIN);
315 // check to see if the resulting team rosters need a captain
316 multi_team_sync_captains();
318 nprintf(("Network","MULTI TEAM : Sending team change request to server\n"));
319 multi_team_send_team_request(pl,team);
322 // verify that we have valid team stuff
326 // process a request to change a team
327 void multi_team_process_team_change_request(net_player *pl,net_player *who_from,int team)
329 // if this player has already been locked, don't do anything
330 if((pl->flags & NETINFO_FLAG_TEAM_LOCKED) && !(who_from->flags & NETINFO_FLAG_GAME_HOST)){
331 nprintf(("Network","MULTI TEAM : Server ignoring team change request because player is locked\n"));
335 // otherwise set the team for the player and send an update
336 nprintf(("Network","MULTI TEAM : Server changing player %s to team %d from client request\n",pl->player->callsign,team));
337 pl->p_info.team = team;
338 pl->flags &= ~(NETINFO_FLAG_TEAM_CAPTAIN);
340 // if this came from the host, lock the player down
341 if(who_from->flags & NETINFO_FLAG_GAME_HOST){
342 pl->flags |= NETINFO_FLAG_TEAM_LOCKED;
345 // check to see if the resulting team rosters need a captain
346 multi_team_sync_captains();
348 // send a team update
349 multi_team_send_update();
351 // verify that we have valid team stuff
355 // have the netgame host assign default teams
356 void multi_team_host_assign_default_teams()
358 int player_count,idx;
361 // first determine how many players there are in the game
363 for(idx=0;idx<MAX_PLAYERS;idx++){
364 // count anyone except the standalone server (if applicable)
365 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
370 // determine how many players should be stuck on team 0
371 if(player_count < 2){
374 team0_count = player_count / 2;
377 // assign the players to team 0
379 while(team0_count > 0){
380 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
381 Net_players[idx].p_info.team = 0;
382 Net_players[idx].flags &= ~(NETINFO_FLAG_TEAM_LOCKED);
383 Net_players[idx].flags &= ~(NETINFO_FLAG_TEAM_CAPTAIN);
390 // assign the remaining players to team 1
391 while(idx < MAX_PLAYERS){
392 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
393 Net_players[idx].p_info.team = 1;
394 Net_players[idx].flags &= ~(NETINFO_FLAG_TEAM_LOCKED);
395 Net_players[idx].flags &= ~(NETINFO_FLAG_TEAM_CAPTAIN);
401 multi_team_sync_captains();
403 // send a full update to all players
404 multi_team_send_update();
406 // verify that we have valid team stuff
410 // check to see if the team this player on needs a captain and assign him if so
411 void multi_team_sync_captains()
414 int team0_cap,team1_cap;
416 // if I'm not the server, bail
417 if(!MULTIPLAYER_MASTER){
421 // determine if any team now needs a captain
424 for(idx=0;idx<MAX_PLAYERS;idx++){
425 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)){
426 switch(Net_players[idx].p_info.team){
437 // if team 0 needs a captain, get one
439 for(idx=0;idx<MAX_PLAYERS;idx++){
440 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)){
441 multi_team_set_captain(&Net_players[idx],1);
447 // if team 1 needs a captain, get one
449 for(idx=0;idx<MAX_PLAYERS;idx++){
450 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)){
451 multi_team_set_captain(&Net_players[idx],1);
458 // is it ok for the host to hit commit
459 int multi_team_ok_to_commit()
461 int team0_captains,team1_captains;
462 int team0_count,team1_count;
465 // verify that we have valid team stuff
468 // check to see if both teams have a captain
472 for(idx=0;idx<MAX_PLAYERS;idx++){
473 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
474 // if this is team 0's captain
475 if((Net_players[idx].p_info.team == 0) && (Net_players[idx].flags & NETINFO_FLAG_TEAM_CAPTAIN)){
477 } else if((Net_players[idx].p_info.team == 1) && (Net_players[idx].flags & NETINFO_FLAG_TEAM_CAPTAIN)){
483 // check to see if both teams has <= 4 players
484 multi_team_get_player_counts(&team0_count,&team1_count);
485 team0_count = ((team0_count <= 4) && (team0_count > 0)) ? 1 : 0;
486 team1_count = ((team1_count <= 4) && (team1_count > 0)) ? 1 : 0;
488 return ((team0_captains == 1) && (team1_captains == 1) && team0_count && team1_count) ? 1 : 0;
491 // handle a player drop
492 void multi_team_handle_drop()
495 int team0_cap, team1_cap;
497 // if I'm not the server, bail
498 if(!MULTIPLAYER_MASTER){
502 // if we're not in a team vs team situation, we don't care
503 if(!(Netgame.type_flags & NG_TYPE_TEAM)){
507 // is either team at 0 players, ingame?
508 if(Game_mode & GM_IN_MISSION){
509 int team0_count, team1_count;
510 multi_team_get_player_counts(&team0_count, &team1_count);
511 if(team0_count <= 0){
512 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_TEAM0_EMPTY);
515 if(team1_count <= 0){
516 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_TEAM1_EMPTY);
521 // check to see if a team captain has left the game
524 for(idx=0;idx<MAX_PLAYERS;idx++){
525 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)){
526 switch(Net_players[idx].p_info.team){
537 // if we have lost a team captain and we're not in the forming state, abort the game
538 if((!team0_cap || !team1_cap) && (Netgame.game_state != NETGAME_STATE_FORMING)){
539 // if we're in-mission, just sync up captains
540 if(Game_mode & GM_IN_MISSION){
542 multi_team_sync_captains();
544 // send a team update
545 multi_team_send_update();
547 // find the player who is the new captain
548 int team_check = team0_cap ? 1 : 0;
549 for(idx=0; idx<MAX_PLAYERS; idx++){
550 if(MULTI_CONNECTED(Net_players[idx]) && (Net_players[idx].flags & NETINFO_FLAG_TEAM_CAPTAIN) && (Net_players[idx].p_info.team == team_check)){
551 send_host_captain_change_packet(Net_players[idx].player_id, 1);
558 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_CAPTAIN_LEFT);
560 // otherwise sync things up and be done with it.
562 // sync up team captains
563 multi_team_sync_captains();
565 // send a team update
566 multi_team_send_update();
568 // verify that we have valid team stuff
573 // handle a player join
574 void multi_team_handle_join(net_player *pl)
576 int team0_count,team1_count,idx,team_select;
578 // if we're not in a team vs team situation, we don't care
579 if(!(Netgame.type_flags & NG_TYPE_TEAM)){
583 // if the joining player is joining as an observer, don't put him on a team
584 if(pl->flags & NETINFO_FLAG_OBSERVER){
588 // only the host should ever do this
589 Assert(Net_player->flags & NETINFO_FLAG_AM_MASTER);
590 if(!(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
594 // count the # of players on each time
597 for(idx=0;idx<MAX_PLAYERS;idx++){
598 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
599 // player is on team 0
600 if(Net_players[idx].p_info.team == 0){
603 // player is on team 1
604 else if(Net_players[idx].p_info.team == 1){
607 // some other case - should never happen
614 // determine what team he should be on
615 if((team0_count == team1_count) || (team0_count < team1_count)){
621 // place him on the team, but don't lock him yet
622 multi_team_set_team(pl,team_select);
623 pl->flags &= ~(NETINFO_FLAG_TEAM_LOCKED);
625 // send a team update
626 multi_team_send_update();
628 // verify that we have valid team stuff
632 // set all ships in the mission to be marked as the proper team (TEAM_HOSTILE, TEAM_FRIENLY)
633 void multi_team_mark_all_ships()
637 // look through all ships in the mission
638 moveup = GET_FIRST(&Ship_obj_list);
639 while(moveup!=END_OF_LIST(&Ship_obj_list)){
640 multi_team_mark_ship(&Ships[Objects[moveup->objnum].instance]);
642 moveup = GET_NEXT(moveup);
645 // verify that we have valid team stuff
649 // set the proper team for the passed in ship
650 void multi_team_mark_ship(ship *sp)
658 // look through team 0
659 for(idx=0;idx<4;idx++){
660 if(!stricmp(sp->ship_name,Multi_team0_names[idx])){
666 // look through team 1 if necessary
668 for(idx=0;idx<4;idx++){
669 if(!stricmp(sp->ship_name,Multi_team1_names[idx])){
676 // if we found a team
679 sp->team = TEAM_FRIENDLY;
682 sp->team = TEAM_HOSTILE;
686 // verify that we have valid team stuff
690 // host locks all players into their teams
691 void multi_team_host_lock_all()
695 // lock all players down
696 for(idx=0;idx<MAX_PLAYERS;idx++){
697 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
698 Net_players[idx].flags |= NETINFO_FLAG_TEAM_LOCKED;
702 // verify that we have valid team stuff
706 // get the player counts for team 0 and team 1 (NULL values are valid)
707 void multi_team_get_player_counts(int *team0, int *team1)
711 // initialize the values
720 for(idx=0;idx<MAX_PLAYERS;idx++){
721 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx])){
722 if((Net_players[idx].p_info.team == 0) && (team0 != NULL)){
724 } else if((Net_players[idx].p_info.team == 1) && (team1 != NULL)){
731 // report on the winner/loser of the game via chat text
732 #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);
733 void multi_team_report()
735 char report[400] = "";
738 SEND_AND_DISPLAY("----****");
741 sprintf(report, XSTR("<Team 1 had %d points>", 1275), Multi_team0_score);
742 SEND_AND_DISPLAY(report);
743 sprintf(report, XSTR("<Team 2 had %d points>", 1276), Multi_team1_score);
744 SEND_AND_DISPLAY(report);
747 switch(multi_team_winner()){
749 SEND_AND_DISPLAY(XSTR("<Match was a tie>", 1277));
753 SEND_AND_DISPLAY(XSTR("<Team 1 (green) is the winner>", 1278));
757 SEND_AND_DISPLAY(XSTR("<Team 2 (red) is the winner>", 1279));
761 SEND_AND_DISPLAY("----****");
765 // ------------------------------------------------------------------------------------
766 // MULTIPLAYER TEAMPLAY PACKET HANDLERS
769 // process an incoming team update packet
770 void multi_team_process_packet(unsigned char *data, header *hinfo)
774 int offset = HEADER_LENGTH;
776 // find out who is sending this data
777 player_index = find_player_id(hinfo->id);
779 // get the packet opcode
782 // take action absed upon the opcode
784 // a request to set the team for a player
785 case MT_CODE_TEAM_REQUEST:
787 int req_index,req_team;
789 Assert(Net_player->flags & NETINFO_FLAG_AM_MASTER);
791 // get the packet data
792 GET_DATA_U16(player_id);
793 GET_DATA_S32(req_team);
795 // if i'm the host of the game, process here
796 req_index = find_player_id(player_id);
798 nprintf(("Network","Could not find player to process team change request !\n"));
800 multi_team_process_team_change_request(&Net_players[req_index],&Net_players[player_index],req_team);
804 // a full team update
805 case MT_CODE_TEAM_UPDATE:
806 offset += multi_team_process_team_update(data+offset);
812 // verify that we have valid team stuff
816 // send a packet to the host requesting to change my team
817 void multi_team_send_team_request(net_player *pl, int team)
819 ubyte data[MAX_PACKET_SIZE],code;
822 // build the header and add the opcode
823 BUILD_HEADER(TEAM_UPDATE);
824 code = MT_CODE_TEAM_REQUEST;
827 // add the address of the guy we want to change
828 ADD_DATA_S16(pl->player_id);
830 // add the team I want to be on
833 // send to the server of the game (will be routed to host if in a standalone situation)
834 multi_io_send_reliable(Net_player, data, packet_size);
837 // send a full update on a player-per-player basis (should call this to update all players after other relevant function calls)
838 void multi_team_send_update()
840 ubyte data[MAX_PACKET_SIZE],val,stop;
844 // if I'm not the server, bail
845 if(!MULTIPLAYER_MASTER){
849 // first, verify that we have valid settings
852 // build the header and add the opcode
853 BUILD_HEADER(TEAM_UPDATE);
854 val = MT_CODE_TEAM_UPDATE;
857 // add the info for all players;
858 for(idx=0;idx<MAX_PLAYERS;idx++){
859 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx])){
865 ADD_DATA_S16(Net_players[idx].player_id);
867 // pack all his data into a byte
870 // set bit 0 if he's on team 1
871 if(Net_players[idx].p_info.team == 1){
875 // set bit 1 if he's a team captain
876 if(Net_players[idx].flags & NETINFO_FLAG_TEAM_CAPTAIN){
883 // add the final stop byte
887 // if i'm the server, I should broadcast to this to all players, otherwise I should send it to the standalone
888 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
889 multi_io_send_to_all_reliable(data, packet_size);
891 multi_io_send_reliable(Net_player, data, packet_size);
895 // process a team update packet, return bytes processed
896 int multi_team_process_team_update(ubyte *data)
903 // if I'm the server, bail
904 Assert(!MULTIPLAYER_MASTER);
906 // process all players
909 // get the net address and flags for the guy
910 GET_DATA_S16(player_id);
913 // do a player lookup
914 if(!MULTIPLAYER_MASTER){
915 player_index = find_player_id(player_id);
916 if(player_index != -1){
917 // set his team correctly
919 Net_players[player_index].p_info.team = 1;
921 Net_players[player_index].p_info.team = 0;
924 // set his captaincy flag correctly
925 Net_players[player_index].flags &= ~(NETINFO_FLAG_TEAM_CAPTAIN);
927 Net_players[player_index].flags |= NETINFO_FLAG_TEAM_CAPTAIN;
932 // get the next stop byte
936 // verify that we have valid team stuff
939 // return bytes processed
943 // verify that we have valid team stuff
944 void multi_team_verify()
947 int team0_count,team0_cap;
948 int team1_count,team1_cap;
951 // determine how many players we have on team 0 and if they have a captain
954 for(idx=0;idx<MAX_PLAYERS;idx++){
955 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx])){
957 if(Net_players[idx].p_info.team == 0){
961 if(Net_players[idx].flags & NETINFO_FLAG_TEAM_CAPTAIN){
967 // if the team has members
969 // make sure it also has a captain
970 Assert(team0_cap > 0);
972 // make sure it only has 1 captain
973 Assert(team0_cap == 1);
976 // determine how many players we have on team 1 and if they have a captain
979 for(idx=0;idx<MAX_PLAYERS;idx++){
980 if(MULTI_CONNECTED(Net_players[idx]) && !MULTI_PERM_OBSERVER(Net_players[idx]) && !MULTI_STANDALONE(Net_players[idx])){
982 if(Net_players[idx].p_info.team == 1){
986 if(Net_players[idx].flags & NETINFO_FLAG_TEAM_CAPTAIN){
992 // if the team has members
994 // make sure it also has a captain
995 Assert(team1_cap > 0);
997 // make sure it only has 1 captain
998 Assert(team1_cap == 1);