1 /* $Id: multi.c,v 1.9 2003-03-14 21:24:03 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Multiplayer code shared by serial and network play.
76 void multi_reset_player_object(object *objp);
77 void multi_reset_object_texture(object *objp);
78 void multi_add_lifetime_killed();
79 void multi_add_lifetime_kills();
80 void multi_send_play_by_play(int num,int spnum,int dpnum);
81 void multi_send_heartbeat();
82 void multi_send_modem_ping();
83 void multi_cap_objects();
84 void multi_adjust_remote_cap(int pnum);
85 void multi_save_game(ubyte slot, uint id, char *desc);
86 void multi_restore_game(ubyte slot, uint id);
87 void multi_set_robot_ai(void);
88 void multi_send_powerup_update();
89 void bash_to_shield(int i,char *s);
90 void init_hoard_data();
91 void multi_apply_goal_textures();
92 int find_goal_texture(ubyte t);
93 void multi_bad_restore();
94 void multi_do_capture_bonus(char *buf);
95 void multi_do_orb_bonus(char *buf);
96 void multi_send_drop_flag(int objnum,int seed);
97 void multi_send_ranking();
98 void multi_do_play_by_play(char *buf);
101 // Local macros and prototypes
106 #define vm_angvec_zero(v) (v)->p=(v)->b=(v)->h=0
108 void drop_player_eggs(object *player); // from collide.c
109 void GameLoop(int, int); // From game.c
115 extern vms_vector MarkerPoint[];
116 extern char MarkerMessage[16][40];
117 extern char MarkerOwner[16][40];
118 extern int MarkerObject[];
120 int control_invul_time = 0;
121 int who_killed_controlcen = -1; // -1 = noone
123 //do we draw the kill list on the HUD?
124 int Show_kill_list = 1;
125 int Show_reticle_name = 1;
126 fix Show_kill_list_timer = 0;
128 char Multi_is_guided=0;
129 char PKilledFlags[MAX_NUM_NET_PLAYERS];
131 int multi_sending_message = 0;
132 int multi_defining_message = 0;
133 int multi_message_index = 0;
135 char multibuf[MAX_MULTI_MESSAGE_LEN+4]; // This is where multiplayer message are built
137 short remote_to_local[MAX_NUM_NET_PLAYERS][MAX_OBJECTS]; // Remote object number for each local object
138 short local_to_remote[MAX_OBJECTS];
139 byte object_owner[MAX_OBJECTS]; // Who created each object in my universe, -1 = loaded at start
141 int Net_create_objnums[MAX_NET_CREATE_OBJECTS]; // For tracking object creation that will be sent to remote
142 int Net_create_loc = 0; // pointer into previous array
143 int Network_laser_fired = 0; // How many times we shot
144 int Network_laser_gun; // Which gun number we shot
145 int Network_laser_flags; // Special flags for the shot
146 int Network_laser_level; // What level
147 short Network_laser_track; // Who is it tracking?
148 char Network_message[MAX_MESSAGE_LEN];
149 char Network_message_macro[4][MAX_MESSAGE_LEN];
150 int Network_message_reciever=-1;
151 int sorted_kills[MAX_NUM_NET_PLAYERS];
152 short kill_matrix[MAX_NUM_NET_PLAYERS][MAX_NUM_NET_PLAYERS];
153 int multi_goto_secret = 0;
155 int multi_in_menu = 0;
156 int multi_leave_menu = 0;
157 int multi_quit_game = 0;
159 netgame_info Netgame;
160 AllNetPlayers_info NetPlayers;
162 bitmap_index multi_player_textures[MAX_NUM_NET_PLAYERS][N_PLAYER_SHIP_TEXTURES];
164 typedef struct netplayer_stats {
166 ubyte Player_num; // Who am i?
167 uint flags; // Powerup flags, see below...
168 fix energy; // Amount of energy remaining.
169 fix shields; // shields remaining (protection)
170 ubyte lives; // Lives remaining, 0 = game over.
171 ubyte laser_level; // Current level of the laser.
172 ubyte primary_weapon_flags; // bit set indicates the player has this weapon.
173 ubyte secondary_weapon_flags; // bit set indicates the player has this weapon.
174 ushort primary_ammo[MAX_PRIMARY_WEAPONS]; // How much ammo of each type.
175 ushort secondary_ammo[MAX_SECONDARY_WEAPONS]; // How much ammo of each type.
176 int last_score; // Score at beginning of current level.
177 int score; // Current score.
178 fix cloak_time; // Time cloaked
179 fix invulnerable_time; // Time invulnerable
180 fix homing_object_dist; // Distance of nearest homing object.
182 short net_killed_total; // Number of times killed total
183 short net_kills_total; // Number of net kills total
184 short num_kills_level; // Number of kills this level
185 short num_kills_total; // Number of kills total
186 short num_robots_level; // Number of initial robots this level
187 short num_robots_total; // Number of robots total
188 ushort hostages_rescued_total; // Total number of hostages rescued.
189 ushort hostages_total; // Total number of hostages.
190 ubyte hostages_on_board; // Number of hostages on ship.
194 int message_length[MULTI_MAX_TYPE+1] = {
200 97+9, // PLAYER_EXPLODE
201 37, // MESSAGE (MAX_MESSAGE_LENGTH = 40)
211 2, // CREATE_EXPLOSION
212 16, // CONTROLCEN_FIRE
214 19, // CREATE_POWERUP
218 28, // ROBOT_POSITION (shortpos_length (23) + 5 = 28)
226 27, // ROBOT_POWERUPS
228 2+24, // SAVE_GAME (ubyte slot, uint id, char name[20])
229 2+4, // RESTORE_GAME (ubyte slot, uint id)
230 1+1, // MULTI_REQ_PLAYER
231 sizeof(netplayer_stats), // MULTI_SEND_PLAYER
233 12, // MULTI_DROP_WEAPON
235 3+sizeof(shortpos), // MULTI_GUIDED, IF SHORTPOS CHANGES, CHANGE MAC VALUE BELOW
237 26, // MULTI_GUIDED IF SIZE OF SHORTPOS CHANGES, CHANGE THIS VALUE AS WELL!!!!!!
239 11, // MULTI_STOLEN_ITEMS
240 6, // MULTI_WALL_STATUS
241 5, // MULTI_HEARTBEAT
242 9, // MULTI_KILLGOALS
245 2, // MULTI_START_TRIGGER
247 2, // MULTI_DROP_BLOB
248 MAX_POWERUP_TYPES+1, // MULTI_POWERUP_UPDATE
249 sizeof(active_door)+3, // MULTI_ACTIVE_DOOR
250 4, // MULTI_SOUND_FUNCTION
251 2, // MULTI_CAPTURE_BONUS
253 12, // MULTI_DROP_FLAG
254 142, // MULTI_ROBOT_CONTROLS
255 2, // MULTI_FINISH_GAME
257 1, // MULTI_MODEM_PING
258 1, // MULTI_MODEM_PING_RETURN
259 3, // MULTI_ORB_BONUS
261 12, // MULTI_DROP_ORB
262 4, // MULTI_PLAY_BY_PLAY
265 void extract_netplayer_stats( netplayer_stats *ps, player * pd );
266 void use_netplayer_stats( player * ps, netplayer_stats *pd );
267 char PowerupsInMine[MAX_POWERUP_TYPES],MaxPowerupsAllowed[MAX_POWERUP_TYPES];
268 extern fix ThisLevelTime;
271 // Functions that replace what used to be macros
274 int objnum_remote_to_local(int remote_objnum, int owner)
276 // Map a remote object number from owner to a local object number
280 if ((owner >= N_players) || (owner < -1)) {
282 return(remote_objnum);
286 return(remote_objnum);
288 if ((remote_objnum < 0) || (remote_objnum >= MAX_OBJECTS))
291 result = remote_to_local[owner][remote_objnum];
295 mprintf((1, "Remote object owner %d number %d mapped to -1!\n", owner, remote_objnum));
300 if (object_owner[result] != owner)
302 mprintf((1, "Remote object owner %d number %d doesn't match owner %d.\n", owner, remote_objnum, object_owner[result]));
305 //Assert(object_owner[result] == owner);
310 int objnum_local_to_remote(int local_objnum, byte *owner)
312 // Map a local object number to a remote + owner
316 if ((local_objnum < 0) || (local_objnum > Highest_object_index)) {
321 *owner = object_owner[local_objnum];
324 return(local_objnum);
326 if ((*owner >= N_players) || (*owner < -1)) {
332 result = local_to_remote[local_objnum];
334 //mprintf((0, "Local object %d mapped to owner %d objnum %d.\n", local_objnum,
339 Int3(); // See Rob, object has no remote number!
346 map_objnum_local_to_remote(int local_objnum, int remote_objnum, int owner)
348 // Add a mapping from a network remote object number to a local one
350 Assert(local_objnum > -1);
351 Assert(remote_objnum > -1);
353 Assert(owner != Player_num);
354 Assert(local_objnum < MAX_OBJECTS);
355 Assert(remote_objnum < MAX_OBJECTS);
357 object_owner[local_objnum] = owner;
359 remote_to_local[owner][remote_objnum] = local_objnum;
360 local_to_remote[local_objnum] = remote_objnum;
366 map_objnum_local_to_local(int local_objnum)
368 // Add a mapping for our locally created objects
370 Assert(local_objnum > -1);
371 Assert(local_objnum < MAX_OBJECTS);
373 object_owner[local_objnum] = Player_num;
374 remote_to_local[Player_num][local_objnum] = local_objnum;
375 local_to_remote[local_objnum] = local_objnum;
381 // Part 1 : functions whose main purpose in life is to divert the flow
382 // of execution to either network or serial specific code based
383 // on the curretn Game_mode value.
387 multi_endlevel_score(void)
392 // Show a score list to end of net players
394 // Save connect state and change to new connect state
396 if (Game_mode & GM_NETWORK)
398 old_connect = Players[Player_num].connected;
399 if (Players[Player_num].connected!=3)
400 Players[Player_num].connected = CONNECT_END_MENU;
401 Network_status = NETSTAT_ENDLEVEL;
406 // Do the actual screen we wish to show
408 Function_mode = FMODE_MENU;
410 kmatrix_view(Game_mode & GM_NETWORK);
412 Function_mode = FMODE_GAME;
414 // Restore connect state
416 if (Game_mode & GM_NETWORK)
418 Players[Player_num].connected = old_connect;
422 if (Game_mode & GM_MULTI_COOP)
425 for (i = 0; i < MaxNumNetPlayers; i++)
427 Players[i].flags &= ~(PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY);
429 for (i = 0; i < MaxNumNetPlayers; i++)
430 Players[i].flags &= ~(PLAYER_FLAGS_FLAG); // Clear capture flag
434 for (i=0;i<MAX_PLAYERS;i++)
435 Players[i].KillGoalCount=0;
437 for (i=0;i<MAX_POWERUP_TYPES;i++)
439 MaxPowerupsAllowed[i]=0;
448 if ((Game_mode & GM_CAPTURE) && ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM)))
451 if (Netgame.team_vector & (1 << pnum))
458 multi_choose_mission(int *anarchy_only)
462 char *m[MAX_MISSIONS];
463 int new_mission_num = 0;
467 n_missions = build_mission_list(1);
469 if (n_missions > 1) {
472 for (i=0;i<n_missions;i++) {
473 m[i] = Mission_list[i].mission_name;
474 if ( !stricmp( m[i], config_last_mission ) )
478 ExtGameStatus=GAMESTAT_START_MULTIPLAYER_MISSION;
479 new_mission_num = newmenu_listbox1(TXT_MULTI_MISSION, n_missions, m, 1, default_mission, NULL );
481 if (new_mission_num == -1)
484 strcpy(config_last_mission, m[new_mission_num] );
486 if (!load_mission(new_mission_num)) {
487 nm_messagebox( NULL, 1, TXT_OK, TXT_MISSION_ERROR);
491 *anarchy_only = Mission_list[new_mission_num].anarchy_only_flag;
493 return(new_mission_num);
496 extern void game_disable_cheats();
503 // Reset variables for a new net game
505 memset(kill_matrix, 0, MAX_NUM_NET_PLAYERS*MAX_NUM_NET_PLAYERS*2); // Clear kill matrix
507 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
510 Players[i].net_killed_total = 0;
511 Players[i].net_kills_total = 0;
512 Players[i].flags = 0;
513 Players[i].KillGoalCount=0;
517 for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
519 robot_controlled[i] = -1;
520 robot_agitation[i] = 0;
525 team_kills[0] = team_kills[1] = 0;
526 Endlevel_sequence = 0;
528 multi_leave_menu = 0;
531 game_disable_cheats();
533 Dead_player_camera = 0;
537 multi_make_player_ghost(int playernum)
541 //Assert(playernum != Player_num);
542 //Assert(playernum < MAX_NUM_NET_PLAYERS);
544 if ((playernum == Player_num) || (playernum >= MAX_NUM_NET_PLAYERS) || (playernum < 0))
546 Int3(); // Non-terminal, see Rob
550 // if (Objects[Players[playernum].objnum].type != OBJ_PLAYER)
551 // mprintf((1, "Warning: Player %d is not currently a player.\n", playernum));
553 obj = &Objects[Players[playernum].objnum];
555 obj->type = OBJ_GHOST;
556 obj->render_type = RT_NONE;
557 obj->movement_type = MT_NONE;
558 multi_reset_player_object(obj);
560 if (Game_mode & GM_MULTI_ROBOTS)
561 multi_strip_robots(playernum);
565 multi_make_ghost_player(int playernum)
569 // Assert(playernum != Player_num);
570 // Assert(playernum < MAX_NUM_NET_PLAYERS);
572 if ((playernum == Player_num) || (playernum >= MAX_NUM_NET_PLAYERS))
574 Int3(); // Non-terminal, see rob
578 // if(Objects[Players[playernum].objnum].type != OBJ_GHOST)
579 // mprintf((1, "Warning: Player %d is not currently a ghost.\n", playernum));
581 obj = &Objects[Players[playernum].objnum];
583 obj->type = OBJ_PLAYER;
584 obj->movement_type = MT_PHYSICS;
585 multi_reset_player_object(obj);
588 int multi_get_kill_list(int *plist)
590 // Returns the number of active net players and their
591 // sorted order of kills
595 for (i = 0; i < N_players; i++)
596 //if (Players[sorted_kills[i]].connected)
597 plist[n++] = sorted_kills[i];
600 Int3(); // SEE ROB OR MATT
602 //memcpy(plist, sorted_kills, N_players*sizeof(int));
608 multi_sort_kill_list(void)
610 // Sort the kills list each time a new kill is added
612 int kills[MAX_NUM_NET_PLAYERS];
616 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
619 if (Game_mode & GM_MULTI_COOP)
620 kills[i] = Players[i].score;
623 if (Show_kill_list==2)
625 if (Players[i].net_killed_total+Players[i].net_kills_total==0)
626 kills[i]=-1; // always draw the ones without any ratio last
628 kills[i]=(int)((float)((float)Players[i].net_kills_total/((float)Players[i].net_killed_total+(float)Players[i].net_kills_total))*100.0);
631 kills[i] = Players[i].net_kills_total;
637 for (i = 0; i < N_players-1; i++)
639 if (kills[sorted_kills[i]] < kills[sorted_kills[i+1]])
641 changed = sorted_kills[i];
642 sorted_kills[i] = sorted_kills[i+1];
643 sorted_kills[i+1] = changed;
648 mprintf((0, "Sorted kills %d %d.\n", sorted_kills[0], sorted_kills[1]));
651 extern object *obj_find_first_of_type (int);
652 char Multi_killed_yourself=0;
654 void multi_compute_kill(int killer, int killed)
656 // Figure out the results of a network kills and add it to the
657 // appropriate player's tally.
659 int killed_pnum, killed_type;
660 int killer_pnum, killer_type,killer_id;
662 char killed_name[(CALLSIGN_LEN*2)+4];
663 char killer_name[(CALLSIGN_LEN*2)+4];
665 kmatrix_kills_changed = 1;
666 Multi_killed_yourself=0;
668 // Both object numbers are localized already!
670 mprintf((0, "compute_kill passed: object %d killed object %d.\n", killer, killed));
672 if ((killed < 0) || (killed > Highest_object_index) || (killer < 0) || (killer > Highest_object_index))
674 Int3(); // See Rob, illegal value passed to compute_kill;
678 killed_type = Objects[killed].type;
679 killer_type = Objects[killer].type;
680 killer_id = Objects[killer].id;
682 if ((killed_type != OBJ_PLAYER) && (killed_type != OBJ_GHOST))
684 Int3(); // compute_kill passed non-player object!
688 killed_pnum = Objects[killed].id;
690 PKilledFlags[killed_pnum]=1;
692 Assert ((killed_pnum >= 0) && (killed_pnum < N_players));
694 if (Game_mode & GM_TEAM)
695 sprintf(killed_name, "%s (%s)", Players[killed_pnum].callsign, Netgame.team_name[get_team(killed_pnum)]);
697 sprintf(killed_name, "%s", Players[killed_pnum].callsign);
699 if (Newdemo_state == ND_STATE_RECORDING)
700 newdemo_record_multi_death(killed_pnum);
702 digi_play_sample( SOUND_HUD_KILL, F3_0 );
704 if (Control_center_destroyed)
705 Players[killed_pnum].connected=3;
707 if (killer_type == OBJ_CNTRLCEN)
709 Players[killed_pnum].net_killed_total++;
710 Players[killed_pnum].net_kills_total--;
712 if (Newdemo_state == ND_STATE_RECORDING)
713 newdemo_record_multi_kill(killed_pnum, -1);
715 if (killed_pnum == Player_num)
717 HUD_init_message("%s %s.", TXT_YOU_WERE, TXT_KILLED_BY_NONPLAY);
718 multi_add_lifetime_killed ();
721 HUD_init_message("%s %s %s.", killed_name, TXT_WAS, TXT_KILLED_BY_NONPLAY );
726 else if ((killer_type != OBJ_PLAYER) && (killer_type != OBJ_GHOST))
728 if (killer_id==PMINE_ID && killer_type!=OBJ_ROBOT)
730 if (killed_pnum == Player_num)
731 HUD_init_message("You were killed by a mine!");
733 HUD_init_message("%s was killed by a mine!",killed_name);
737 if (killed_pnum == Player_num)
739 HUD_init_message("%s %s.", TXT_YOU_WERE, TXT_KILLED_BY_ROBOT);
740 multi_add_lifetime_killed();
743 HUD_init_message("%s %s %s.", killed_name, TXT_WAS, TXT_KILLED_BY_ROBOT );
745 Players[killed_pnum].net_killed_total++;
749 else if ((killer_type != OBJ_PLAYER) && (killer_type != OBJ_GHOST) && (killer_id!=PMINE_ID))
751 Int3(); // Illegal killer type?
754 if (killer_id==PMINE_ID)
756 if (killed_pnum==Player_num)
757 HUD_init_message("You were killed by a mine!");
759 HUD_init_message("%s was killed by a mine!",killed_name);
761 Players[killed_pnum].net_killed_total++;
767 killer_pnum = Objects[killer].id;
769 if (Game_mode & GM_TEAM)
770 sprintf(killer_name, "%s (%s)", Players[killer_pnum].callsign, Netgame.team_name[get_team(killer_pnum)]);
772 sprintf(killer_name, "%s", Players[killer_pnum].callsign);
774 // Beyond this point, it was definitely a player-player kill situation
776 if ((killer_pnum < 0) || (killer_pnum >= N_players))
777 Int3(); // See rob, tracking down bug with kill HUD messages
778 if ((killed_pnum < 0) || (killed_pnum >= N_players))
779 Int3(); // See rob, tracking down bug with kill HUD messages
781 if (killer_pnum == killed_pnum)
783 if (!(Game_mode & GM_HOARD))
785 if (Game_mode & GM_TEAM)
786 team_kills[get_team(killed_pnum)] -= 1;
788 Players[killed_pnum].net_killed_total += 1;
789 Players[killed_pnum].net_kills_total -= 1;
791 if (Newdemo_state == ND_STATE_RECORDING)
792 newdemo_record_multi_kill(killed_pnum, -1);
794 kill_matrix[killed_pnum][killed_pnum] += 1; // # of suicides
796 if (killer_pnum == Player_num)
798 HUD_init_message("%s %s %s!", TXT_YOU, TXT_KILLED, TXT_YOURSELF );
799 Multi_killed_yourself=1;
800 multi_add_lifetime_killed();
803 HUD_init_message("%s %s", killed_name, TXT_SUICIDE);
808 if (!(Game_mode & GM_HOARD))
810 if (Game_mode & GM_TEAM)
812 if (get_team(killed_pnum) == get_team(killer_pnum))
813 team_kills[get_team(killed_pnum)] -= 1;
815 team_kills[get_team(killer_pnum)] += 1;
818 Players[killer_pnum].net_kills_total += 1;
819 Players[killer_pnum].KillGoalCount+=1;
821 if (Newdemo_state == ND_STATE_RECORDING)
822 newdemo_record_multi_kill(killer_pnum, 1);
826 if (Game_mode & GM_TEAM)
828 if (killed_pnum==Player_num && get_team(killed_pnum) == get_team(killer_pnum))
829 Multi_killed_yourself=1;
833 kill_matrix[killer_pnum][killed_pnum] += 1;
834 Players[killed_pnum].net_killed_total += 1;
835 if (killer_pnum == Player_num) {
836 HUD_init_message("%s %s %s!", TXT_YOU, TXT_KILLED, killed_name);
837 multi_add_lifetime_kills();
838 if ((Game_mode & GM_MULTI_COOP) && (Players[Player_num].score >= 1000))
839 add_points_to_score(-1000);
841 else if (killed_pnum == Player_num)
843 HUD_init_message("%s %s %s!", killer_name, TXT_KILLED, TXT_YOU);
844 multi_add_lifetime_killed();
845 if (Game_mode & GM_HOARD)
847 if (Players[Player_num].secondary_ammo[PROXIMITY_INDEX]>3)
848 multi_send_play_by_play (1,killer_pnum,Player_num);
849 else if (Players[Player_num].secondary_ammo[PROXIMITY_INDEX]>0)
850 multi_send_play_by_play (0,killer_pnum,Player_num);
854 HUD_init_message("%s %s %s!", killer_name, TXT_KILLED, killed_name);
857 TheGoal=Netgame.KillGoal*5;
859 if (Netgame.KillGoal>0)
861 if (Players[killer_pnum].KillGoalCount>=TheGoal)
863 if (killer_pnum==Player_num)
865 HUD_init_message("You reached the kill goal!");
866 Players[Player_num].shields=i2f(200);
869 HUD_init_message ("%s has reached the kill goal!",Players[killer_pnum].callsign);
871 HUD_init_message ("The control center has been destroyed!");
872 net_destroy_controlcen (obj_find_first_of_type (OBJ_CNTRLCEN));
876 multi_sort_kill_list();
877 multi_show_player_list();
878 Players[killed_pnum].flags&=(~(PLAYER_FLAGS_HEADLIGHT_ON)); // clear the killed guys flags/headlights
884 static int lasttime=0;
887 if (!(Game_mode & GM_MULTI))
893 if ((Game_mode & GM_NETWORK) && Netgame.PlayTimeAllowed && lasttime!=f2i (ThisLevelTime))
895 for (i=0;i<N_players;i++)
896 if (Players[i].connected)
900 multi_send_heartbeat();
901 lasttime=f2i(ThisLevelTime);
907 multi_send_message(); // Send any waiting messages
910 multi_leave_menu = 0;
913 if (Game_mode & GM_MULTI_ROBOTS)
915 multi_check_robot_timeout();
919 if ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM))
925 network_do_frame(0, 1);
928 if (multi_quit_game && !multi_in_menu)
931 longjmp(LeaveGame, 0);
936 multi_send_data(char *buf, int len, int repeat)
938 Assert(len == message_length[(int)buf[0]]);
939 Assert(buf[0] <= MULTI_MAX_TYPE);
940 // Assert(buf[0] >= 0);
942 if (Game_mode & GM_NETWORK)
945 if ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM))
946 com_send_data(buf, len, repeat);
947 else if (Game_mode & GM_NETWORK)
948 network_send_data(buf, len, repeat);
952 multi_leave_game(void)
955 // if (Function_mode != FMODE_GAME)
958 if (!(Game_mode & GM_MULTI))
961 if (Game_mode & GM_NETWORK)
963 mprintf((0, "Sending explosion message.\n"));
968 drop_player_eggs(ConsoleObject);
969 multi_send_position(Players[Player_num].objnum);
970 multi_send_player_explode(MULTI_PLAYER_DROP);
973 mprintf((1, "Sending leave game.\n"));
974 multi_send_quit(MULTI_QUIT);
976 if ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM))
978 if (Game_mode & GM_NETWORK)
979 network_leave_game();
981 Game_mode |= GM_GAME_OVER;
983 if (Function_mode!=FMODE_EXIT)
984 Function_mode = FMODE_MENU;
988 // change_playernum_to(0);
989 // Viewer = ConsoleObject = &Objects[0];
994 multi_show_player_list()
996 if (!(Game_mode & GM_MULTI) || (Game_mode & GM_MULTI_COOP))
1002 Show_kill_list_timer = F1_0*5; // 5 second timer
1007 multi_endlevel(int *secret)
1011 if ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM))
1012 com_endlevel(secret); // an opportunity to re-sync or whatever
1013 else if (Game_mode & GM_NETWORK)
1014 result = network_endlevel(secret);
1020 // Part 2 : functions that act on network/serial messages and change the
1021 // the state of the game in some way.
1025 //extern PORT *com_port;
1029 multi_menu_poll(void)
1032 int was_fuelcen_alive;
1033 int player_was_dead;
1035 was_fuelcen_alive = Control_center_destroyed;
1037 // Special polling function for in-game menus for multiplayer and serial
1039 if (! ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)) )
1042 if (multi_leave_menu)
1045 old_shields = Players[Player_num].shields;
1046 player_was_dead = Player_is_dead;
1048 multi_in_menu++; // Track level of menu nesting
1054 timer_delay(f0_1); // delay 100 milliseconds
1056 if (Endlevel_sequence || (Control_center_destroyed && !was_fuelcen_alive) || (Player_is_dead != player_was_dead) || (Players[Player_num].shields < old_shields))
1058 multi_leave_menu = 1;
1061 if ((Control_center_destroyed) && (Countdown_seconds_left < 10))
1063 multi_leave_menu = 1;
1068 if ((Game_mode & GM_MODEM) && (!GetCd(com_port)))
1070 multi_leave_menu = 1;
1079 multi_define_macro(int key)
1081 if (!(Game_mode & GM_MULTI))
1084 key &= (~KEY_SHIFTED);
1089 multi_defining_message = 1; break;
1091 multi_defining_message = 2; break;
1093 multi_defining_message = 3; break;
1095 multi_defining_message = 4; break;
1100 if (multi_defining_message) {
1101 multi_message_index = 0;
1102 Network_message[multi_message_index] = 0;
1107 char feedback_result[200];
1110 multi_message_feedback(void)
1116 if (!( ((colon = strrchr(Network_message, ':')) == NULL) || (colon-Network_message < 1) || (colon-Network_message > CALLSIGN_LEN) ))
1118 sprintf(feedback_result, "%s ", TXT_MESSAGE_SENT_TO);
1119 if ((Game_mode & GM_TEAM) && (atoi(Network_message) > 0) && (atoi(Network_message) < 3))
1121 sprintf(feedback_result+strlen(feedback_result), "%s '%s'", TXT_TEAM, Netgame.team_name[atoi(Network_message)-1]);
1124 if (Game_mode & GM_TEAM)
1126 for (i = 0; i < N_players; i++)
1128 if (!strnicmp(Netgame.team_name[i], Network_message, colon-Network_message))
1131 strcat(feedback_result, ", ");
1134 strcat(feedback_result, "\n");
1135 sprintf(feedback_result+strlen(feedback_result), "%s '%s'", TXT_TEAM, Netgame.team_name[i]);
1139 for (i = 0; i < N_players; i++)
1141 if ((!strnicmp(Players[i].callsign, Network_message, colon-Network_message)) && (i != Player_num) && (Players[i].connected))
1144 strcat(feedback_result, ", ");
1147 strcat(feedback_result, "\n");
1148 sprintf(feedback_result+strlen(feedback_result), "%s", Players[i].callsign);
1152 strcat(feedback_result, TXT_NOBODY);
1154 strcat(feedback_result, ".");
1156 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1158 Assert(strlen(feedback_result) < 200);
1160 HUD_init_message(feedback_result);
1161 //sprintf (temp,"%s",colon);
1162 //sprintf (Network_message,"%s",temp);
1168 multi_send_macro(int key)
1170 if (! (Game_mode & GM_MULTI) )
1187 if (!Network_message_macro[key][0])
1189 HUD_init_message(TXT_NO_MACRO);
1193 strcpy(Network_message, Network_message_macro[key]);
1194 Network_message_reciever = 100;
1196 HUD_init_message("%s '%s'", TXT_SENDING, Network_message);
1197 multi_message_feedback();
1202 multi_send_message_start()
1204 if (Game_mode&GM_MULTI) {
1205 multi_sending_message = 1;
1206 multi_message_index = 0;
1207 Network_message[multi_message_index] = 0;
1211 extern fix StartingShields;
1212 fix PingLaunchTime,PingReturnTime;
1214 extern void network_send_ping (ubyte);
1215 extern int network_who_is_master();
1216 extern char NameReturning;
1217 extern int force_cockpit_redraw;
1219 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why);
1221 void multi_send_message_end()
1226 Network_message_reciever = 100;
1228 if (!strnicmp (Network_message,"!Names",6))
1230 NameReturning=1-NameReturning;
1231 HUD_init_message ("Name returning is now %s.",NameReturning?"active":"disabled");
1233 else if (!strnicmp (Network_message,"Handicap:",9))
1235 mytempbuf=&Network_message[9];
1236 mprintf ((0,"Networkhandi=%s\n",mytempbuf));
1237 StartingShields=atol (mytempbuf);
1238 if (StartingShields<10)
1240 if (StartingShields>100)
1242 sprintf (Network_message,"%s has tried to cheat!",Players[Player_num].callsign);
1243 StartingShields=100;
1246 sprintf (Network_message,"%s handicap is now %d",Players[Player_num].callsign,StartingShields);
1248 HUD_init_message ("Telling others of your handicap of %d!",StartingShields);
1249 StartingShields=i2f(StartingShields);
1251 else if (!strnicmp (Network_message,"NoBombs",7))
1252 Netgame.DoSmartMine=0;
1253 else if (!strnicmp (Network_message,"Ping:",5))
1255 if (Game_mode & GM_NETWORK)
1258 if (strlen(Network_message) > 5)
1259 while (Network_message[name_index] == ' ')
1262 if (strlen(Network_message)<=name_index)
1264 HUD_init_message ("You must specify a name to ping");
1268 for (i = 0; i < N_players; i++)
1269 if ((!strnicmp(Players[i].callsign, &Network_message[name_index], strlen(Network_message)-name_index)) && (i != Player_num) && (Players[i].connected))
1271 PingLaunchTime=timer_get_fixed_seconds();
1272 network_send_ping (i);
1273 HUD_init_message("Pinging %s...",Players[i].callsign);
1274 multi_message_index = 0;
1275 multi_sending_message = 0;
1279 else // Modem/Serial ping
1281 PingLaunchTime=timer_get_fixed_seconds();
1282 multi_send_modem_ping ();
1283 HUD_init_message("Pinging opponent...");
1284 multi_message_index = 0;
1285 multi_sending_message = 0;
1289 else if (!strnicmp (Network_message,"move:",5))
1291 mprintf ((0,"moving?\n"));
1293 if ((Game_mode & GM_NETWORK) && (Game_mode & GM_TEAM))
1296 if (strlen(Network_message) > 5)
1297 while (Network_message[name_index] == ' ')
1300 if (!network_i_am_master())
1302 HUD_init_message ("Only %s can move players!",Players[network_who_is_master()].callsign);
1306 if (strlen(Network_message)<=name_index)
1308 HUD_init_message ("You must specify a name to move");
1312 for (i = 0; i < N_players; i++)
1313 if ((!strnicmp(Players[i].callsign, &Network_message[name_index], strlen(Network_message)-name_index)) && (Players[i].connected))
1315 if ((Game_mode & GM_CAPTURE) && (Players[i].flags & PLAYER_FLAGS_FLAG))
1317 HUD_init_message ("Can't move player because s/he has a flag!");
1321 if (Netgame.team_vector & (1<<i))
1322 Netgame.team_vector&=(~(1<<i));
1324 Netgame.team_vector|=(1<<i);
1326 for (t=0;t<N_players;t++)
1327 if (Players[t].connected)
1328 multi_reset_object_texture (&Objects[Players[t].objnum]);
1330 network_send_netgame_update ();
1331 sprintf (Network_message,"%s has changed teams!",Players[i].callsign);
1334 HUD_init_message ("You have changed teams!");
1338 HUD_init_message ("Moving %s to other team.",Players[i].callsign);
1344 else if (!strnicmp (Network_message,"kick:",5) && (Game_mode & GM_NETWORK))
1347 if (strlen(Network_message) > 5)
1348 while (Network_message[name_index] == ' ')
1351 if (!network_i_am_master())
1353 HUD_init_message ("Only %s can kick others out!",Players[network_who_is_master()].callsign);
1354 multi_message_index = 0;
1355 multi_sending_message = 0;
1358 if (strlen(Network_message)<=name_index)
1360 HUD_init_message ("You must specify a name to kick");
1361 multi_message_index = 0;
1362 multi_sending_message = 0;
1366 if (Network_message[name_index] == '#' && isdigit(Network_message[name_index+1])) {
1367 int players[MAX_NUM_NET_PLAYERS];
1368 int listpos = Network_message[name_index+1] - '0';
1370 mprintf ((0,"Trying to kick %d , show_kill_list=%d\n",listpos,Show_kill_list));
1372 if (Show_kill_list==1 || Show_kill_list==2) {
1373 if (listpos == 0 || listpos >= N_players) {
1374 HUD_init_message ("Invalid player number for kick.");
1375 multi_message_index = 0;
1376 multi_sending_message = 0;
1379 multi_get_kill_list(players);
1380 i = players[listpos];
1381 if ((i != Player_num) && (Players[i].connected))
1384 else HUD_init_message ("You cannot use # kicking with in team display.");
1387 multi_message_index = 0;
1388 multi_sending_message = 0;
1393 for (i = 0; i < N_players; i++)
1394 if ((!strnicmp(Players[i].callsign, &Network_message[name_index], strlen(Network_message)-name_index)) && (i != Player_num) && (Players[i].connected)) {
1396 if (Network_game_type == IPX_GAME)
1397 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, 7);
1399 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, 7);
1401 HUD_init_message("Dumping %s...",Players[i].callsign);
1402 multi_message_index = 0;
1403 multi_sending_message = 0;
1409 HUD_init_message("%s '%s'", TXT_SENDING, Network_message);
1411 multi_send_message();
1412 multi_message_feedback();
1414 multi_message_index = 0;
1415 multi_sending_message = 0;
1418 void multi_define_macro_end()
1420 Assert( multi_defining_message > 0 );
1422 strcpy( Network_message_macro[multi_defining_message-1], Network_message );
1423 write_player_file();
1425 multi_message_index = 0;
1426 multi_defining_message = 0;
1429 void multi_message_input_sub( int key )
1434 multi_sending_message = 0;
1435 multi_defining_message = 0;
1436 game_flush_inputs();
1441 if (multi_message_index > 0)
1442 multi_message_index--;
1443 Network_message[multi_message_index] = 0;
1446 if ( multi_sending_message )
1447 multi_send_message_end();
1448 else if ( multi_defining_message )
1449 multi_define_macro_end();
1450 game_flush_inputs();
1454 int ascii = key_to_ascii(key);
1455 if ((ascii < 255 )) {
1456 if (multi_message_index < MAX_MESSAGE_LEN-2 ) {
1457 Network_message[multi_message_index++] = ascii;
1458 Network_message[multi_message_index] = 0;
1459 } else if ( multi_sending_message ) {
1461 char * ptext, * pcolon;
1463 Network_message[multi_message_index++] = ascii;
1464 Network_message[multi_message_index] = 0;
1465 for (i=multi_message_index-1; i>=0; i-- ) {
1466 if ( Network_message[i]==32 ) {
1467 ptext = &Network_message[i+1];
1468 Network_message[i] = 0;
1472 multi_send_message_end();
1474 multi_sending_message = 1;
1475 pcolon = strchr( Network_message, ':' );
1477 strcpy( pcolon+1, ptext );
1479 strcpy( Network_message, ptext );
1480 multi_message_index = strlen( Network_message );
1489 multi_send_message_dialog(void)
1494 if (!(Game_mode&GM_MULTI))
1497 Network_message[0] = 0; // Get rid of old contents
1499 m[0].type=NM_TYPE_INPUT; m[0].text = Network_message; m[0].text_len = MAX_MESSAGE_LEN-1;
1500 choice = newmenu_do( NULL, TXT_SEND_MESSAGE, 1, m, NULL );
1502 if ((choice > -1) && (strlen(Network_message) > 0)) {
1503 Network_message_reciever = 100;
1504 HUD_init_message("%s '%s'", TXT_SENDING, Network_message);
1505 multi_message_feedback();
1512 multi_do_death(int objnum)
1514 // Do any miscellaneous stuff for a new network player after death
1518 if (!(Game_mode & GM_MULTI_COOP))
1520 mprintf((0, "Setting all keys for player %d.\n", Player_num));
1521 Players[Player_num].flags |= (PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_GOLD_KEY);
1526 multi_do_fire(char *buf)
1533 // Act out the actual shooting
1537 weapon = (int)buf[2];
1542 Network_laser_track = INTEL_SHORT(*(short *)(buf+6));
1544 Assert (pnum < N_players);
1546 if (Objects[Players[(int)pnum].objnum].type == OBJ_GHOST)
1547 multi_make_ghost_player(pnum);
1549 // mprintf((0,"multi_do_fire, weapon = %d\n",weapon));
1551 if (weapon == FLARE_ADJUST)
1552 Laser_player_fire( Objects+Players[(int)pnum].objnum, FLARE_ID, 6, 1, 0);
1553 else if (weapon >= MISSILE_ADJUST) {
1554 int weapon_id,weapon_gun;
1556 weapon_id = Secondary_weapon_to_weapon_info[weapon-MISSILE_ADJUST];
1557 weapon_gun = Secondary_weapon_to_gun_num[weapon-MISSILE_ADJUST] + (flags & 1);
1558 mprintf((0,"missile id = %d, gun = %d\n",weapon_id,weapon_gun));
1560 if (weapon-MISSILE_ADJUST==GUIDED_INDEX)
1562 mprintf ((0,"Missile is guided!!!\n"));
1566 Laser_player_fire( Objects+Players[(int)pnum].objnum, weapon_id, weapon_gun, 1, 0 );
1569 fix save_charge = Fusion_charge;
1571 if (weapon == FUSION_INDEX) {
1572 Fusion_charge = flags << 12;
1573 mprintf((0, "Fusion charge X%f.\n", f2fl(Fusion_charge)));
1575 if (weapon == LASER_ID) {
1576 if (flags & LASER_QUAD)
1577 Players[(int)pnum].flags |= PLAYER_FLAGS_QUAD_LASERS;
1579 Players[(int)pnum].flags &= ~PLAYER_FLAGS_QUAD_LASERS;
1582 do_laser_firing(Players[(int)pnum].objnum, weapon, (int)buf[3], flags, (int)buf[5]);
1584 if (weapon == FUSION_INDEX)
1585 Fusion_charge = save_charge;
1590 multi_do_message(char *buf)
1593 char *tilde,mesbuf[100];
1598 if ((tilde=strchr (buf+loc,'$'))) // do that stupid name stuff
1599 { // why'd I put this in? Probably for the
1600 tloc=tilde-(buf+loc); // same reason you can name your guidebot
1601 mprintf ((0,"Tloc=%d\n",tloc));
1604 strncpy (mesbuf,buf+loc,tloc);
1605 strcpy (mesbuf+tloc,Players[Player_num].callsign);
1606 strcpy (mesbuf+strlen(Players[Player_num].callsign)+tloc,buf+loc+tloc+1);
1607 strcpy (buf+loc,mesbuf);
1610 if (((colon = strrchr(buf+loc, ':')) == NULL) || (colon-(buf+loc) < 1) || (colon-(buf+loc) > CALLSIGN_LEN))
1613 mesbuf[1] = BM_XRGB(28, 0, 0);
1614 strcpy(&mesbuf[2], Players[(int)buf[1]].callsign);
1618 mesbuf[t+2] = BM_XRGB(0, 31, 0);
1621 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1622 HUD_init_message("%s %s", mesbuf, buf+2);
1626 if ( (!strnicmp(Players[Player_num].callsign, buf+loc, colon-(buf+loc))) ||
1627 ((Game_mode & GM_TEAM) && ( (get_team(Player_num) == atoi(buf+loc)-1) || !strnicmp(Netgame.team_name[get_team(Player_num)], buf+loc, colon-(buf+loc)))) )
1630 mesbuf[1] = BM_XRGB(0, 32, 32);
1631 strcpy(&mesbuf[2], Players[(int)buf[1]].callsign);
1635 mesbuf[t+2] = BM_XRGB(0, 31, 0);
1638 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1639 HUD_init_message("%s %s", mesbuf, colon+1);
1645 multi_do_position(char *buf)
1651 // This routine does only player positions, mode game only
1652 // mprintf((0, "Got position packet.\n"));
1654 int pnum = (Player_num+1)%2;
1656 Assert(&Objects[Players[pnum].objnum] != ConsoleObject);
1658 if (Game_mode & GM_NETWORK)
1660 Int3(); // Get Jason, what the hell are we doing here?
1666 extract_shortpos(&Objects[Players[pnum].objnum], (shortpos *)(buf+1),0);
1668 memcpy((ubyte *)(sp.bytemat), (ubyte *)(buf + 1), 9);
1669 memcpy((ubyte *)&(sp.xo), (ubyte *)(buf + 10), 14);
1670 extract_shortpos(&Objects[Players[pnum].objnum], &sp, 1);
1673 if (Objects[Players[pnum].objnum].movement_type == MT_PHYSICS)
1674 set_thrust_from_velocity(&Objects[Players[pnum].objnum]);
1678 multi_do_reappear(char *buf)
1682 objnum = INTEL_SHORT(*(short *)(buf+1));
1684 Assert(objnum >= 0);
1685 // Assert(Players[Objects[objnum].id]].objnum == objnum);
1687 // mprintf((0, "Switching rendering back on for object %d.\n", objnum));
1689 multi_make_ghost_player(Objects[objnum].id);
1690 create_player_appearance_effect(&Objects[objnum]);
1691 PKilledFlags[Objects[objnum].id]=0;
1695 multi_do_player_explode(char *buf)
1697 // Only call this for players, not robots. pnum is player number, not
1704 char remote_created;
1709 if ((pnum < 0) || (pnum >= N_players))
1713 Assert(pnum < N_players);
1717 // If we are in the process of sending objects to a new player, reset that process
1718 if (Network_send_objects)
1720 mprintf((0, "Resetting object sync due to player explosion.\n"));
1721 Network_send_objnum = -1;
1725 // Stuff the Players structure to prepare for the explosion
1728 Players[pnum].primary_weapon_flags = INTEL_SHORT(*(ushort *)(buf+count)); count += 2;
1729 Players[pnum].secondary_weapon_flags = INTEL_SHORT(*(ushort *)(buf+count)); count += 2;
1730 Players[pnum].laser_level = buf[count]; count++;
1731 Players[pnum].secondary_ammo[HOMING_INDEX] = buf[count]; count++;
1732 Players[pnum].secondary_ammo[CONCUSSION_INDEX] = buf[count];count++;
1733 Players[pnum].secondary_ammo[SMART_INDEX] = buf[count]; count++;
1734 Players[pnum].secondary_ammo[MEGA_INDEX] = buf[count]; count++;
1735 Players[pnum].secondary_ammo[PROXIMITY_INDEX] = buf[count]; count++;
1737 Players[pnum].secondary_ammo[SMISSILE1_INDEX] = buf[count]; count++;
1738 Players[pnum].secondary_ammo[GUIDED_INDEX] = buf[count]; count++;
1739 Players[pnum].secondary_ammo[SMART_MINE_INDEX]= buf[count]; count++;
1740 Players[pnum].secondary_ammo[SMISSILE4_INDEX] = buf[count]; count++;
1741 Players[pnum].secondary_ammo[SMISSILE5_INDEX] = buf[count]; count++;
1743 Players[pnum].primary_ammo[VULCAN_INDEX] = INTEL_SHORT(*(ushort *)(buf+count)); count += 2;
1744 Players[pnum].primary_ammo[GAUSS_INDEX] = INTEL_SHORT(*(ushort *)(buf+count)); count += 2;
1745 Players[pnum].flags = INTEL_INT(*(uint *)(buf+count)); count += 4;
1747 multi_adjust_remote_cap (pnum);
1749 objp = Objects+Players[pnum].objnum;
1751 // objp->phys_info.velocity = *(vms_vector *)(buf+16); // 12 bytes
1752 // objp->pos = *(vms_vector *)(buf+28); // 12 bytes
1754 remote_created = buf[count++]; // How many did the other guy create?
1758 drop_player_eggs(objp);
1760 // Create mapping from remote to local numbering system
1762 mprintf((0, "I Created %d powerups, remote created %d.\n", Net_create_loc, remote_created));
1764 // We now handle this situation gracefully, Int3 not required
1765 // if (Net_create_loc != remote_created)
1766 // Int3(); // Probably out of object array space, see Rob
1768 for (i = 0; i < remote_created; i++)
1772 s = INTEL_SHORT(*(short *)(buf+count));
1774 if ((i < Net_create_loc) && (s > 0))
1775 map_objnum_local_to_remote((short)Net_create_objnums[i], s, pnum);
1776 else if (*(short *)(buf+count) <= 0)
1778 mprintf((0, "WARNING: Remote created object has non-valid number %d (player %d)", s, pnum));
1782 mprintf((0, "WARNING: Could not create all powerups created by player %d.\n", pnum));
1787 for (i = remote_created; i < Net_create_loc; i++) {
1788 mprintf((0, "WARNING: I Created more powerups than player %d, deleting.\n", pnum));
1789 Objects[Net_create_objnums[i]].flags |= OF_SHOULD_BE_DEAD;
1792 if (buf[0] == MULTI_PLAYER_EXPLODE)
1794 explode_badass_player(objp);
1796 objp->flags &= ~OF_SHOULD_BE_DEAD; //don't really kill player
1797 multi_make_player_ghost(pnum);
1801 create_player_appearance_effect(objp);
1804 Players[pnum].flags &= ~(PLAYER_FLAGS_CLOAKED | PLAYER_FLAGS_INVULNERABLE | PLAYER_FLAGS_FLAG);
1805 Players[pnum].cloak_time = 0;
1809 multi_do_kill(char *buf)
1815 pnum = (int)(buf[count]);
1816 if ((pnum < 0) || (pnum >= N_players))
1818 Int3(); // Invalid player number killed
1821 killed = Players[pnum].objnum;
1824 killer = INTEL_SHORT(*(short *)(buf+count));
1826 killer = objnum_remote_to_local(killer, (byte)buf[count+2]);
1829 if ((Objects[killed].type != OBJ_PLAYER) && (Objects[killed].type != OBJ_GHOST))
1832 mprintf( (1, "SOFT INT3: MULTI.C Non-player object %d of type %d killed! (JOHN)\n", killed, Objects[killed].type ));
1837 multi_compute_kill(killer, killed);
1842 // Changed by MK on 10/20/94 to send NULL as object to net_destroy_controlcen if it got -1
1843 // which means not a controlcen object, but contained in another object
1844 void multi_do_controlcen_destroy(char *buf)
1849 objnum = INTEL_SHORT(*(short *)(buf+1));
1852 if (Control_center_destroyed != 1)
1854 if ((who < N_players) && (who != Player_num)) {
1855 HUD_init_message("%s %s", Players[who].callsign, TXT_HAS_DEST_CONTROL);
1857 else if (who == Player_num)
1858 HUD_init_message(TXT_YOU_DEST_CONTROL);
1860 HUD_init_message(TXT_CONTROL_DESTROYED);
1863 net_destroy_controlcen(Objects+objnum);
1865 net_destroy_controlcen(NULL);
1870 multi_do_escape(char *buf)
1874 objnum = Players[(int)buf[1]].objnum;
1876 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1877 digi_kill_sound_linked_to_object (objnum);
1881 HUD_init_message("%s %s", Players[(int)buf[1]].callsign, TXT_HAS_ESCAPED);
1882 if (Game_mode & GM_NETWORK)
1883 Players[(int)buf[1]].connected = CONNECT_ESCAPE_TUNNEL;
1884 if (!multi_goto_secret)
1885 multi_goto_secret = 2;
1887 else if (buf[2] == 1)
1889 HUD_init_message("%s %s", Players[(int)buf[1]].callsign, TXT_HAS_FOUND_SECRET);
1890 if (Game_mode & GM_NETWORK)
1891 Players[(int)buf[1]].connected = CONNECT_FOUND_SECRET;
1892 if (!multi_goto_secret)
1893 multi_goto_secret = 1;
1895 create_player_appearance_effect(&Objects[objnum]);
1896 multi_make_player_ghost(buf[1]);
1900 multi_do_remobj(char *buf)
1902 short objnum; // which object to remove
1904 byte obj_owner; // which remote list is it entered in
1906 objnum = INTEL_SHORT(*(short *)(buf+1));
1909 Assert(objnum >= 0);
1914 local_objnum = objnum_remote_to_local(objnum, obj_owner); // translate to local objnum
1916 // mprintf((0, "multi_do_remobj: %d owner %d = %d.\n", objnum, obj_owner, local_objnum));
1918 if (local_objnum < 0)
1920 mprintf((1, "multi_do_remobj: Could not remove referenced object.\n"));
1924 if ((Objects[local_objnum].type != OBJ_POWERUP) && (Objects[local_objnum].type != OBJ_HOSTAGE))
1926 mprintf((1, "multi_get_remobj: tried to remove invalid type %d.\n", Objects[local_objnum].type));
1930 if (Network_send_objects && network_objnum_is_past(local_objnum))
1932 mprintf((0, "Resetting object sync due to object removal.\n"));
1933 Network_send_objnum = -1;
1935 if (Objects[local_objnum].type==OBJ_POWERUP)
1936 if (Game_mode & GM_NETWORK)
1938 if (PowerupsInMine[Objects[local_objnum].id]>0)
1939 PowerupsInMine[Objects[local_objnum].id]--;
1941 if (multi_powerup_is_4pack (Objects[local_objnum].id))
1943 mprintf ((0,"Hey babe! Doing that wacky 4 pack stuff."));
1945 if (PowerupsInMine[Objects[local_objnum].id-1]-4<0)
1946 PowerupsInMine[Objects[local_objnum].id-1]=0;
1948 PowerupsInMine[Objects[local_objnum].id-1]-=4;
1951 mprintf ((0,"Decrementing powerups! %d\n",PowerupsInMine[Objects[local_objnum].id]));
1954 Objects[local_objnum].flags |= OF_SHOULD_BE_DEAD; // quick and painless
1959 multi_do_quit(char *buf)
1962 if (Game_mode & GM_NETWORK)
1966 digi_play_sample( SOUND_HUD_MESSAGE, F1_0 );
1968 HUD_init_message( "%s %s", Players[(int)buf[1]].callsign, TXT_HAS_LEFT_THE_GAME);
1970 network_disconnect_player(buf[1]);
1975 for (i = 0; i < N_players; i++)
1976 if (Players[i].connected) n++;
1979 nm_messagebox(NULL, 1, TXT_OK, TXT_YOU_ARE_ONLY);
1983 if ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM))
1985 Function_mode = FMODE_MENU;
1986 multi_quit_game = 1;
1987 multi_leave_menu = 1;
1988 nm_messagebox(NULL, 1, TXT_OK, TXT_OPPONENT_LEFT);
1989 Function_mode = FMODE_GAME;
1990 multi_reset_stuff();
1996 multi_do_cloak(char *buf)
2000 pnum = (int)(buf[1]);
2002 Assert(pnum < N_players);
2004 mprintf((0, "Cloaking player %d\n", pnum));
2006 Players[pnum].flags |= PLAYER_FLAGS_CLOAKED;
2007 Players[pnum].cloak_time = GameTime;
2008 ai_do_cloak_stuff();
2011 if (Game_mode & GM_MULTI_ROBOTS)
2012 multi_strip_robots(pnum);
2015 if (Newdemo_state == ND_STATE_RECORDING)
2016 newdemo_record_multi_cloak(pnum);
2020 multi_do_decloak(char *buf)
2024 pnum = (int)(buf[1]);
2026 if (Newdemo_state == ND_STATE_RECORDING)
2027 newdemo_record_multi_decloak(pnum);
2032 multi_do_door_open(char *buf)
2040 segnum = INTEL_SHORT(*(short *)(buf+1));
2044 // mprintf((0, "Opening door on side %d of segment # %d.\n", side, segnum));
2046 if ((segnum < 0) || (segnum > Highest_segment_index) || (side < 0) || (side > 5))
2052 seg = &Segments[segnum];
2054 if (seg->sides[side].wall_num == -1) { //Opening door on illegal wall
2059 w = &Walls[seg->sides[side].wall_num];
2061 if (w->type == WALL_BLASTABLE)
2063 if (!(w->flags & WALL_BLASTED))
2065 mprintf((0, "Blasting wall by remote command.\n"));
2066 wall_destroy(seg, side);
2070 else if (w->state != WALL_DOOR_OPENING)
2072 wall_open_door(seg, side);
2079 // mprintf((0, "Door already opening!\n"));
2083 multi_do_create_explosion(char *buf)
2088 pnum = buf[count++];
2090 // mprintf((0, "Creating small fireball.\n"));
2091 create_small_fireball_on_object(&Objects[Players[pnum].objnum], F1_0, 1);
2095 multi_do_controlcen_fire(char *buf)
2097 vms_vector to_target;
2102 memcpy(&to_target, buf+count, 12); count += 12;
2103 #ifdef MACINTOSH // swap the vector to_target
2104 to_target.x = (fix)INTEL_INT((int)to_target.x);
2105 to_target.y = (fix)INTEL_INT((int)to_target.y);
2106 to_target.z = (fix)INTEL_INT((int)to_target.z);
2108 gun_num = buf[count]; count += 1;
2109 objnum = INTEL_SHORT(*(short *)(buf+count)); count += 2;
2111 Laser_create_new_easy(&to_target, &Gun_pos[(int)gun_num], objnum, CONTROLCEN_WEAPON_NUM, 1);
2115 multi_do_create_powerup(char *buf)
2125 if (Endlevel_sequence || Control_center_destroyed)
2128 pnum = buf[count++];
2129 powerup_type = buf[count++];
2130 segnum = INTEL_SHORT(*(short *)(buf+count)); count+=2;
2131 objnum = INTEL_SHORT(*(short *)(buf+count)); count+=2;
2133 if ((segnum < 0) || (segnum > Highest_segment_index)) {
2138 new_pos = *(vms_vector *)(buf+count); count+=sizeof(vms_vector);
2140 new_pos.x = (fix)SWAPINT((int)new_pos.x);
2141 new_pos.y = (fix)SWAPINT((int)new_pos.y);
2142 new_pos.z = (fix)SWAPINT((int)new_pos.z);
2146 my_objnum = call_object_create_egg(&Objects[Players[(int)pnum].objnum], 1, OBJ_POWERUP, powerup_type);
2148 if (my_objnum < 0) {
2149 mprintf((0, "Could not create new powerup!\n"));
2153 if (Network_send_objects && network_objnum_is_past(my_objnum))
2155 mprintf((0, "Resetting object sync due to powerup creation.\n"));
2156 Network_send_objnum = -1;
2159 Objects[my_objnum].pos = new_pos;
2161 vm_vec_zero(&Objects[my_objnum].mtype.phys_info.velocity);
2163 obj_relink(my_objnum, segnum);
2165 map_objnum_local_to_remote(my_objnum, objnum, pnum);
2167 object_create_explosion(segnum, &new_pos, i2f(5), VCLIP_POWERUP_DISAPPEARANCE);
2168 mprintf((0, "Creating powerup type %d in segment %i.\n", powerup_type, segnum));
2170 if (Game_mode & GM_NETWORK)
2171 PowerupsInMine[(int)powerup_type]++;
2175 multi_do_play_sound(char *buf)
2177 int pnum = (int)(buf[1]);
2178 int sound_num = (int)(buf[2]);
2179 fix volume = (int)(buf[3]) << 12;
2181 if (!Players[pnum].connected)
2184 Assert(Players[pnum].objnum >= 0);
2185 Assert(Players[pnum].objnum <= Highest_object_index);
2187 digi_link_sound_to_object( sound_num, Players[pnum].objnum, 0, volume);
2191 multi_do_score(char *buf)
2193 int pnum = (int)(buf[1]);
2195 if ((pnum < 0) || (pnum >= N_players))
2197 Int3(); // Non-terminal, see rob
2201 if (Newdemo_state == ND_STATE_RECORDING)
2202 newdemo_record_multi_score(pnum, INTEL_INT(*(int *)(buf+2)) );
2204 Players[pnum].score = INTEL_INT(*(int *)(buf+2));
2206 multi_sort_kill_list();
2210 multi_do_trigger(char *buf)
2212 int pnum = (int)(buf[1]);
2213 int trigger = (int)(buf[2]);
2215 mprintf ((0,"MULTI doing trigger!\n"));
2217 if ((pnum < 0) || (pnum >= N_players) || (pnum == Player_num))
2219 Int3(); // Got trigger from illegal playernum
2222 if ((trigger < 0) || (trigger >= Num_triggers))
2224 Int3(); // Illegal trigger number in multiplayer
2227 check_trigger_sub(trigger, pnum,0);
2230 void multi_do_drop_marker (char *buf)
2233 int pnum=(int)(buf[1]);
2234 int mesnum=(int)(buf[2]);
2235 vms_vector position;
2237 if (pnum==Player_num) // my marker? don't set it down cuz it might screw up the orientation
2240 position.x=(fix)INTEL_INT(*(int *)(buf+3));
2241 position.y=(fix)INTEL_INT(*(int *)(buf+7));
2242 position.z=(fix)INTEL_INT(*(int *)(buf+11));
2245 MarkerMessage[(pnum*2)+mesnum][i]=buf[15+i];
2247 MarkerPoint[(pnum*2)+mesnum]=position;
2249 if (MarkerObject[(pnum*2)+mesnum] !=-1 && Objects[MarkerObject[(pnum*2)+mesnum]].type!=OBJ_NONE && MarkerObject[(pnum*2)+mesnum] !=0)
2250 obj_delete(MarkerObject[(pnum*2)+mesnum]);
2252 MarkerObject[(pnum*2)+mesnum] = drop_marker_object(&position,Objects[Players[Player_num].objnum].segnum,&Objects[Players[Player_num].objnum].orient,(pnum*2)+mesnum);
2253 strcpy (MarkerOwner[(pnum*2)+mesnum],Players[pnum].callsign);
2254 mprintf ((0,"Dropped player %d message: %s\n",pnum,MarkerMessage[(pnum*2)+mesnum]));
2258 void multi_do_hostage_door_status(char *buf)
2260 // Update hit point status of a door
2266 wallnum = INTEL_SHORT(*(short *)(buf+count)); count += 2;
2267 hps = (fix)INTEL_INT(*(int *)(buf+count)); count += 4;
2269 if ((wallnum < 0) || (wallnum > Num_walls) || (hps < 0) || (Walls[wallnum].type != WALL_BLASTABLE))
2271 Int3(); // Non-terminal, see Rob
2275 // mprintf((0, "Damaging wall number %d to %f points.\n", wallnum, f2fl(hps)));
2277 if (hps < Walls[wallnum].hps)
2278 wall_damage(&Segments[Walls[wallnum].segnum], Walls[wallnum].sidenum, Walls[wallnum].hps - hps);
2281 void multi_do_save_game(char *buf)
2288 slot = *(ubyte *)(buf+count); count += 1;
2289 id = INTEL_INT(*(uint *)(buf+count)); count += 4;
2290 memcpy( desc, &buf[count], 20 ); count += 20;
2292 multi_save_game( slot, id, desc );
2295 void multi_do_restore_game(char *buf)
2301 slot = *(ubyte *)(buf+count); count += 1;
2302 id = INTEL_INT(*(uint *)(buf+count)); count += 4;
2304 multi_restore_game( slot, id );
2308 void multi_do_req_player(char *buf)
2312 // Send my netplayer_stats to everyone!
2313 player_n = *(ubyte *)(buf+1);
2314 if ( (player_n == Player_num) || (player_n == 255) ) {
2315 extract_netplayer_stats( &ps, &Players[Player_num] );
2316 ps.Player_num = Player_num;
2317 ps.message_type = MULTI_SEND_PLAYER; // SET
2318 multi_send_data((ubyte*)&ps, sizeof(netplayer_stats), 0);
2322 void multi_do_send_player(char *buf)
2324 // Got a player packet from someone!!!
2325 netplayer_stats * p;
2326 p = (netplayer_stats *)buf;
2328 Assert( p->Player_num <= N_players );
2330 mprintf(( 0, "Got netplayer_stats for player %d (I'm %d)\n", p->Player_num, Player_num ));
2331 mprintf(( 0, "Their shields are: %d\n", f2i(p->shields) ));
2333 use_netplayer_stats( &Players[p->Player_num], p );
2337 multi_reset_stuff(void)
2339 // A generic, emergency function to solve problems that crop up
2340 // when a player exits quick-out from the game because of a
2341 // serial connection loss. Fixes several weird bugs!
2345 Players[Player_num].homing_object_dist = -F1_0; // Turn off homing sound.
2347 Dead_player_camera = 0;
2348 Endlevel_sequence = 0;
2353 multi_reset_player_object(object *objp)
2357 //Init physics for a non-console player
2359 Assert(objp >= Objects);
2360 Assert(objp <= Objects+Highest_object_index);
2361 Assert((objp->type == OBJ_PLAYER) || (objp->type == OBJ_GHOST));
2363 vm_vec_zero(&objp->mtype.phys_info.velocity);
2364 vm_vec_zero(&objp->mtype.phys_info.thrust);
2365 vm_vec_zero(&objp->mtype.phys_info.rotvel);
2366 vm_vec_zero(&objp->mtype.phys_info.rotthrust);
2367 objp->mtype.phys_info.brakes = objp->mtype.phys_info.turnroll = 0;
2368 objp->mtype.phys_info.mass = Player_ship->mass;
2369 objp->mtype.phys_info.drag = Player_ship->drag;
2370 // objp->mtype.phys_info.flags &= ~(PF_TURNROLL | PF_LEVELLING | PF_WIGGLE | PF_USES_THRUST);
2371 objp->mtype.phys_info.flags &= ~(PF_TURNROLL | PF_LEVELLING | PF_WIGGLE);
2375 objp->render_type = RT_POLYOBJ;
2376 objp->rtype.pobj_info.model_num = Player_ship->model_num; //what model is this?
2377 objp->rtype.pobj_info.subobj_flags = 0; //zero the flags
2378 for (i=0;i<MAX_SUBMODELS;i++)
2379 vm_angvec_zero(&objp->rtype.pobj_info.anim_angles[i]);
2381 //reset textures for this, if not player 0
2383 multi_reset_object_texture (objp);
2389 if (objp->type == OBJ_GHOST)
2390 objp->render_type = RT_NONE;
2394 void multi_reset_object_texture (object *objp)
2398 if (Game_mode & GM_TEAM)
2399 id = get_team(objp->id);
2404 objp->rtype.pobj_info.alt_textures=0;
2406 Assert(N_PLAYER_SHIP_TEXTURES == Polygon_models[objp->rtype.pobj_info.model_num].n_textures);
2408 for (i=0;i<N_PLAYER_SHIP_TEXTURES;i++)
2409 multi_player_textures[id-1][i] = ObjBitmaps[ObjBitmapPtrs[Polygon_models[objp->rtype.pobj_info.model_num].first_texture+i]];
2411 multi_player_textures[id-1][4] = ObjBitmaps[ObjBitmapPtrs[First_multi_bitmap_num+(id-1)*2]];
2412 multi_player_textures[id-1][5] = ObjBitmaps[ObjBitmapPtrs[First_multi_bitmap_num+(id-1)*2+1]];
2414 objp->rtype.pobj_info.alt_textures = id;
2421 extern int TTRecv[];
2422 extern FILE *RecieveLogFile;
2425 multi_process_bigdata(char *buf, int len)
2427 // Takes a bunch of messages, check them for validity,
2428 // and pass them to multi_process_data.
2430 int type, sub_len, bytes_processed = 0;
2432 while( bytes_processed < len ) {
2433 type = buf[bytes_processed];
2435 if ( (type<0) || (type>MULTI_MAX_TYPE)) {
2436 mprintf( (1, "multi_process_bigdata: Invalid packet type %d!\n", type ));
2439 sub_len = message_length[type];
2441 Assert(sub_len > 0);
2443 if ( (bytes_processed+sub_len) > len ) {
2444 mprintf( (1, "multi_process_bigdata: packet type %d too short (%d>%d)!\n", type, (bytes_processed+sub_len), len ));
2449 multi_process_data(&buf[bytes_processed], sub_len);
2450 bytes_processed += sub_len;
2455 // Part 2 : Functions that send communication messages to inform the other
2456 // players of something we did.
2460 multi_send_fire(void)
2462 if (!Network_laser_fired)
2465 multibuf[0] = (char)MULTI_FIRE;
2466 multibuf[1] = (char)Player_num;
2467 multibuf[2] = (char)Network_laser_gun;
2468 multibuf[3] = (char)Network_laser_level;
2469 multibuf[4] = (char)Network_laser_flags;
2470 multibuf[5] = (char)Network_laser_fired;
2472 *(short *)(multibuf+6) = INTEL_SHORT(Network_laser_track);
2474 multi_send_data(multibuf, 8, 0);
2476 Network_laser_fired = 0;
2480 multi_send_destroy_controlcen(int objnum, int player)
2482 if (player == Player_num)
2483 HUD_init_message(TXT_YOU_DEST_CONTROL);
2484 else if ((player > 0) && (player < N_players))
2485 HUD_init_message("%s %s", Players[player].callsign, TXT_HAS_DEST_CONTROL);
2487 HUD_init_message(TXT_CONTROL_DESTROYED);
2489 multibuf[0] = (char)MULTI_CONTROLCEN;
2490 *(ushort *)(multibuf+1) = INTEL_SHORT(objnum);
2491 multibuf[3] = player;
2492 multi_send_data(multibuf, 4, 2);
2495 void multi_send_drop_marker (int player,vms_vector position,char messagenum,char text[])
2499 if (player<N_players)
2501 mprintf ((0,"Sending MARKER drop!\n"));
2502 multibuf[0]=(char)MULTI_MARKER;
2503 multibuf[1]=(char)player;
2504 multibuf[2]=messagenum;
2505 *(fix *)(multibuf+3)=INTEL_INT(position.x);
2506 *(fix *)(multibuf+7)=INTEL_INT(position.y);
2507 *(fix *)(multibuf+11)=INTEL_INT(position.z);
2509 multibuf[15+i]=text[i];
2511 multi_send_data(multibuf, 55, 1);
2515 multi_send_endlevel_start(int secret)
2517 multibuf[0] = (char)MULTI_ENDLEVEL_START;
2518 multibuf[1] = Player_num;
2519 multibuf[2] = (char)secret;
2521 if ((secret) && !multi_goto_secret)
2522 multi_goto_secret = 1;
2523 else if (!multi_goto_secret)
2524 multi_goto_secret = 2;
2526 multi_send_data(multibuf, 3, 1);
2527 if (Game_mode & GM_NETWORK)
2529 Players[Player_num].connected = 5;
2530 network_send_endlevel_packet();
2535 multi_send_player_explode(char type)
2540 Assert( (type == MULTI_PLAYER_DROP) || (type == MULTI_PLAYER_EXPLODE) );
2542 multi_send_position(Players[Player_num].objnum);
2544 if (Network_send_objects)
2546 mprintf((0, "Resetting object sync due to player explosion.\n"));
2547 Network_send_objnum = -1;
2550 multibuf[count++] = type;
2551 multibuf[count++] = Player_num;
2553 *(ushort *)(multibuf+count) = INTEL_SHORT((ushort)Players[Player_num].primary_weapon_flags);
2555 *(ushort *)(multibuf+count) = INTEL_SHORT((ushort)Players[Player_num].secondary_weapon_flags);
2557 multibuf[count++] = (char)Players[Player_num].laser_level;
2559 multibuf[count++] = (char)Players[Player_num].secondary_ammo[HOMING_INDEX];
2560 multibuf[count++] = (char)Players[Player_num].secondary_ammo[CONCUSSION_INDEX];
2561 multibuf[count++] = (char)Players[Player_num].secondary_ammo[SMART_INDEX];
2562 multibuf[count++] = (char)Players[Player_num].secondary_ammo[MEGA_INDEX];
2563 multibuf[count++] = (char)Players[Player_num].secondary_ammo[PROXIMITY_INDEX];
2565 multibuf[count++] = (char)Players[Player_num].secondary_ammo[SMISSILE1_INDEX];
2566 multibuf[count++] = (char)Players[Player_num].secondary_ammo[GUIDED_INDEX];
2567 multibuf[count++] = (char)Players[Player_num].secondary_ammo[SMART_MINE_INDEX];
2568 multibuf[count++] = (char)Players[Player_num].secondary_ammo[SMISSILE4_INDEX];
2569 multibuf[count++] = (char)Players[Player_num].secondary_ammo[SMISSILE5_INDEX];
2571 *(ushort *)(multibuf+count) = INTEL_SHORT( (ushort)Players[Player_num].primary_ammo[VULCAN_INDEX] );
2573 *(ushort *)(multibuf+count) = INTEL_SHORT( (ushort)Players[Player_num].primary_ammo[GAUSS_INDEX] );
2575 *(uint *)(multibuf+count) = INTEL_INT( (uint)Players[Player_num].flags );
2578 multibuf[count++] = Net_create_loc;
2580 Assert(Net_create_loc <= MAX_NET_CREATE_OBJECTS);
2582 memset(multibuf+count, -1, MAX_NET_CREATE_OBJECTS*sizeof(short));
2584 mprintf((0, "Created %d explosion objects.\n", Net_create_loc));
2586 for (i = 0; i < Net_create_loc; i++)
2588 if (Net_create_objnums[i] <= 0) {
2589 Int3(); // Illegal value in created egg object numbers
2594 *(short *)(multibuf+count) = INTEL_SHORT( (short)Net_create_objnums[i] ); count += 2;
2596 // We created these objs so our local number = the network number
2597 map_objnum_local_to_local((short)Net_create_objnums[i]);
2602 // mprintf((1, "explode message size = %d, max = %d.\n", count, message_length[MULTI_PLAYER_EXPLODE]));
2604 if (count > message_length[MULTI_PLAYER_EXPLODE])
2609 multi_send_data(multibuf, message_length[MULTI_PLAYER_EXPLODE], 2);
2610 if (Players[Player_num].flags & PLAYER_FLAGS_CLOAKED)
2611 multi_send_decloak();
2612 if (Game_mode & GM_MULTI_ROBOTS)
2613 multi_strip_robots(Player_num);
2616 extern ubyte Secondary_weapon_to_powerup[];
2617 extern ubyte Primary_weapon_to_powerup[];
2619 // put a lid on how many objects will be spewed by an exploding player
2620 // to prevent rampant powerups in netgames
2622 void multi_cap_objects ()
2627 if (!(Game_mode & GM_NETWORK))
2630 for (index=0;index<MAX_PRIMARY_WEAPONS;index++)
2632 type=Primary_weapon_to_powerup[index];
2633 if (PowerupsInMine[(int)type]>=MaxPowerupsAllowed[(int)type])
2634 if(Players[Player_num].primary_weapon_flags & (1 << index))
2636 mprintf ((0,"PIM=%d MPA=%d\n",PowerupsInMine[(int)type],MaxPowerupsAllowed[(int)type]));
2637 mprintf ((0,"Killing a primary cuz there's too many! (%d)\n",(int)type));
2638 Players[Player_num].primary_weapon_flags&=(~(1 << index));
2643 // Don't do the adjustment stuff for Hoard mode
2644 if (!(Game_mode & GM_HOARD))
2645 Players[Player_num].secondary_ammo[2]/=4;
2647 Players[Player_num].secondary_ammo[7]/=4;
2649 for (index=0;index<MAX_SECONDARY_WEAPONS;index++)
2651 if ((Game_mode & GM_HOARD) && index==PROXIMITY_INDEX)
2654 type=Secondary_weapon_to_powerup[index];
2656 if ((Players[Player_num].secondary_ammo[index]+PowerupsInMine[(int)type])>MaxPowerupsAllowed[(int)type])
2658 if (MaxPowerupsAllowed[(int)type]-PowerupsInMine[(int)type]<0)
2659 Players[Player_num].secondary_ammo[index]=0;
2661 Players[Player_num].secondary_ammo[index]=(MaxPowerupsAllowed[(int)type]-PowerupsInMine[(int)type]);
2663 mprintf ((0,"Hey! I killed secondary type %d because PIM=%d MPA=%d\n",(int)type,PowerupsInMine[(int)type],MaxPowerupsAllowed[(int)type]));
2667 if (!(Game_mode & GM_HOARD))
2668 Players[Player_num].secondary_ammo[2]*=4;
2669 Players[Player_num].secondary_ammo[7]*=4;
2671 if (Players[Player_num].laser_level > MAX_LASER_LEVEL)
2672 if (PowerupsInMine[POW_SUPER_LASER]+1 > MaxPowerupsAllowed[POW_SUPER_LASER])
2673 Players[Player_num].laser_level=0;
2675 if (Players[Player_num].flags & PLAYER_FLAGS_QUAD_LASERS)
2676 if (PowerupsInMine[POW_QUAD_FIRE]+1 > MaxPowerupsAllowed[POW_QUAD_FIRE])
2677 Players[Player_num].flags&=(~PLAYER_FLAGS_QUAD_LASERS);
2679 if (Players[Player_num].flags & PLAYER_FLAGS_CLOAKED)
2680 if (PowerupsInMine[POW_CLOAK]+1 > MaxPowerupsAllowed[POW_CLOAK])
2681 Players[Player_num].flags&=(~PLAYER_FLAGS_CLOAKED);
2683 if (Players[Player_num].flags & PLAYER_FLAGS_MAP_ALL)
2684 if (PowerupsInMine[POW_FULL_MAP]+1 > MaxPowerupsAllowed[POW_FULL_MAP])
2685 Players[Player_num].flags&=(~PLAYER_FLAGS_MAP_ALL);
2687 if (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)
2688 if (PowerupsInMine[POW_AFTERBURNER]+1 > MaxPowerupsAllowed[POW_AFTERBURNER])
2689 Players[Player_num].flags&=(~PLAYER_FLAGS_AFTERBURNER);
2691 if (Players[Player_num].flags & PLAYER_FLAGS_AMMO_RACK)
2692 if (PowerupsInMine[POW_AMMO_RACK]+1 > MaxPowerupsAllowed[POW_AMMO_RACK])
2693 Players[Player_num].flags&=(~PLAYER_FLAGS_AMMO_RACK);
2695 if (Players[Player_num].flags & PLAYER_FLAGS_CONVERTER)
2696 if (PowerupsInMine[POW_CONVERTER]+1 > MaxPowerupsAllowed[POW_CONVERTER])
2697 Players[Player_num].flags&=(~PLAYER_FLAGS_CONVERTER);
2699 if (Players[Player_num].flags & PLAYER_FLAGS_HEADLIGHT)
2700 if (PowerupsInMine[POW_HEADLIGHT]+1 > MaxPowerupsAllowed[POW_HEADLIGHT])
2701 Players[Player_num].flags&=(~PLAYER_FLAGS_HEADLIGHT);
2703 if (Game_mode & GM_CAPTURE)
2705 if (Players[Player_num].flags & PLAYER_FLAGS_FLAG)
2707 if (get_team(Player_num)==TEAM_RED)
2708 flagtype=POW_FLAG_BLUE;
2710 flagtype=POW_FLAG_RED;
2712 if (PowerupsInMine[(int)flagtype]+1 > MaxPowerupsAllowed[(int)flagtype])
2713 Players[Player_num].flags&=(~PLAYER_FLAGS_FLAG);
2719 // adds players inventory to multi cap
2721 void multi_adjust_cap_for_player (int pnum)
2727 if (!(Game_mode & GM_NETWORK))
2730 for (index=0;index<MAX_PRIMARY_WEAPONS;index++)
2732 type=Primary_weapon_to_powerup[index];
2733 if (Players[pnum].primary_weapon_flags & (1 << index))
2734 MaxPowerupsAllowed[(int)type]++;
2737 for (index=0;index<MAX_SECONDARY_WEAPONS;index++)
2739 type=Secondary_weapon_to_powerup[index];
2740 MaxPowerupsAllowed[(int)type]+=Players[pnum].secondary_ammo[index];
2743 if (Players[pnum].laser_level > MAX_LASER_LEVEL)
2744 MaxPowerupsAllowed[POW_SUPER_LASER]++;
2746 if (Players[pnum].flags & PLAYER_FLAGS_QUAD_LASERS)
2747 MaxPowerupsAllowed[POW_QUAD_FIRE]++;
2749 if (Players[pnum].flags & PLAYER_FLAGS_CLOAKED)
2750 MaxPowerupsAllowed[POW_CLOAK]++;
2752 if (Players[pnum].flags & PLAYER_FLAGS_MAP_ALL)
2753 MaxPowerupsAllowed[POW_FULL_MAP]++;
2755 if (Players[pnum].flags & PLAYER_FLAGS_AFTERBURNER)
2756 MaxPowerupsAllowed[POW_AFTERBURNER]++;
2758 if (Players[pnum].flags & PLAYER_FLAGS_AMMO_RACK)
2759 MaxPowerupsAllowed[POW_AMMO_RACK]++;
2761 if (Players[pnum].flags & PLAYER_FLAGS_CONVERTER)
2762 MaxPowerupsAllowed[POW_CONVERTER]++;
2764 if (Players[pnum].flags & PLAYER_FLAGS_HEADLIGHT)
2765 MaxPowerupsAllowed[POW_HEADLIGHT]++;
2768 void multi_adjust_remote_cap (int pnum)
2774 if (!(Game_mode & GM_NETWORK))
2777 for (index=0;index<MAX_PRIMARY_WEAPONS;index++)
2779 type=Primary_weapon_to_powerup[index];
2780 if (Players[pnum].primary_weapon_flags & (1 << index))
2781 PowerupsInMine[(int)type]++;
2784 for (index=0;index<MAX_SECONDARY_WEAPONS;index++)
2786 type=Secondary_weapon_to_powerup[index];
2788 if ((Game_mode & GM_HOARD) && index==2)
2791 if (index==2 || index==7) // PROX or SMARTMINES? Those bastards...
2792 PowerupsInMine[(int)type]+=(Players[pnum].secondary_ammo[index]/4);
2794 PowerupsInMine[(int)type]+=Players[pnum].secondary_ammo[index];
2798 if (Players[pnum].laser_level > MAX_LASER_LEVEL)
2799 PowerupsInMine[POW_SUPER_LASER]++;
2801 if (Players[pnum].flags & PLAYER_FLAGS_QUAD_LASERS)
2802 PowerupsInMine[POW_QUAD_FIRE]++;
2804 if (Players[pnum].flags & PLAYER_FLAGS_CLOAKED)
2805 PowerupsInMine[POW_CLOAK]++;
2807 if (Players[pnum].flags & PLAYER_FLAGS_MAP_ALL)
2808 PowerupsInMine[POW_FULL_MAP]++;
2810 if (Players[pnum].flags & PLAYER_FLAGS_AFTERBURNER)
2811 PowerupsInMine[POW_AFTERBURNER]++;
2813 if (Players[pnum].flags & PLAYER_FLAGS_AMMO_RACK)
2814 PowerupsInMine[POW_AMMO_RACK]++;
2816 if (Players[pnum].flags & PLAYER_FLAGS_CONVERTER)
2817 PowerupsInMine[POW_CONVERTER]++;
2819 if (Players[pnum].flags & PLAYER_FLAGS_HEADLIGHT)
2820 PowerupsInMine[POW_HEADLIGHT]++;
2825 multi_send_message(void)
2828 if (Network_message_reciever != -1)
2830 multibuf[loc] = (char)MULTI_MESSAGE; loc += 1;
2831 multibuf[loc] = (char)Player_num; loc += 1;
2832 strncpy(multibuf+loc, Network_message, MAX_MESSAGE_LEN); loc += MAX_MESSAGE_LEN;
2833 multibuf[loc-1] = '\0';
2834 multi_send_data(multibuf, loc, 0);
2835 Network_message_reciever = -1;
2840 multi_send_reappear()
2842 multibuf[0] = (char)MULTI_REAPPEAR;
2843 *(short *)(multibuf+1) = INTEL_SHORT(Players[Player_num].objnum);
2845 multi_send_data(multibuf, 3, 2);
2846 PKilledFlags[Player_num]=0;
2850 multi_send_position(int objnum)
2857 if (Game_mode & GM_NETWORK) {
2861 multibuf[count++] = (char)MULTI_POSITION;
2863 create_shortpos((shortpos *)(multibuf+count), Objects+objnum,0);
2864 count += sizeof(shortpos);
2866 create_shortpos(&sp, Objects+objnum, 1);
2867 memcpy(&(multibuf[count]), (ubyte *)(sp.bytemat), 9);
2869 memcpy(&(multibuf[count]), (ubyte *)&(sp.xo), 14);
2873 multi_send_data(multibuf, count, 0);
2877 multi_send_kill(int objnum)
2879 // I died, tell the world.
2884 Assert(Objects[objnum].id == Player_num);
2885 killer_objnum = Players[Player_num].killer_objnum;
2887 multi_compute_kill(killer_objnum, objnum);
2889 multibuf[0] = (char)MULTI_KILL; count += 1;
2890 multibuf[1] = Player_num; count += 1;
2891 if (killer_objnum > -1) {
2892 short s; // do it with variable since INTEL_SHORT won't work on return val from function.
2894 s = (short)objnum_local_to_remote(killer_objnum, (byte *)&multibuf[count+2]);
2895 *(short *)(multibuf+count) = INTEL_SHORT(s);
2899 *(short *)(multibuf+count) = INTEL_SHORT((short)-1);
2900 multibuf[count+2] = (char)-1;
2903 multi_send_data(multibuf, count, 1);
2906 if (Game_mode & GM_MULTI_ROBOTS)
2907 multi_strip_robots(Player_num);
2912 multi_send_remobj(int objnum)
2914 // Tell the other guy to remove an object from his list
2917 short remote_objnum;
2919 if (Objects[objnum].type==OBJ_POWERUP && (Game_mode & GM_NETWORK))
2921 if (PowerupsInMine[Objects[objnum].id] > 0)
2923 PowerupsInMine[Objects[objnum].id]--;
2924 if (multi_powerup_is_4pack (Objects[objnum].id))
2926 mprintf ((0,"Hey babe! Doing that wacky 4 pack stuff."));
2928 if (PowerupsInMine[Objects[objnum].id-1]-4<0)
2929 PowerupsInMine[Objects[objnum].id-1]=0;
2931 PowerupsInMine[Objects[objnum].id-1]-=4;
2937 multibuf[0] = (char)MULTI_REMOVE_OBJECT;
2939 remote_objnum = objnum_local_to_remote((short)objnum, &obj_owner);
2941 *(short *)(multibuf+1) = INTEL_SHORT(remote_objnum); // Map to network objnums
2943 multibuf[3] = obj_owner;
2945 // mprintf((0, "multi_send_remobj: %d = %d owner %d.\n", objnum, remote_objnum, obj_owner));
2947 multi_send_data(multibuf, 4, 0);
2949 if (Network_send_objects && network_objnum_is_past(objnum))
2951 mprintf((0, "Resetting object sync due to object removal.\n"));
2952 Network_send_objnum = -1;
2957 multi_send_quit(int why)
2959 // I am quitting the game, tell the other guy the bad news.
2961 Assert (why == MULTI_QUIT);
2963 multibuf[0] = (char)why;
2964 multibuf[1] = Player_num;
2965 multi_send_data(multibuf, 2, 1);
2970 multi_send_cloak(void)
2972 // Broadcast a change in our pflags (made to support cloaking)
2974 multibuf[0] = MULTI_CLOAK;
2975 multibuf[1] = (char)Player_num;
2977 multi_send_data(multibuf, 2, 1);
2980 if (Game_mode & GM_MULTI_ROBOTS)
2981 multi_strip_robots(Player_num);
2986 multi_send_decloak(void)
2988 // Broadcast a change in our pflags (made to support cloaking)
2990 multibuf[0] = MULTI_DECLOAK;
2991 multibuf[1] = (char)Player_num;
2993 multi_send_data(multibuf, 2, 1);
2997 multi_send_door_open(int segnum, int side,ubyte flag)
2999 // When we open a door make sure everyone else opens that door
3001 multibuf[0] = MULTI_DOOR_OPEN;
3002 *(short *)(multibuf+1) = INTEL_SHORT( (short)segnum );
3003 multibuf[3] = (byte)side;
3006 multi_send_data(multibuf, 5, 2);
3009 extern void network_send_naked_packet (char *,short,int);
3012 multi_send_door_open_specific(int pnum,int segnum, int side,ubyte flag)
3014 // For sending doors only to a specific person (usually when they're joining)
3016 Assert (Game_mode & GM_NETWORK);
3017 // Assert (pnum>-1 && pnum<N_players);
3019 multibuf[0] = MULTI_DOOR_OPEN;
3020 *(short *)(multibuf+1) = INTEL_SHORT( (short)segnum );
3021 multibuf[3] = (byte)side;
3024 network_send_naked_packet(multibuf, 5, pnum);
3028 // Part 3 : Functions that change or prepare the game for multiplayer use.
3029 // Not including functions needed to syncronize or start the
3030 // particular type of multiplayer game. Includes preparing the
3031 // mines, player structures, etc.
3034 multi_send_create_explosion(int pnum)
3036 // Send all data needed to create a remote explosion
3040 multibuf[count] = MULTI_CREATE_EXPLOSION; count += 1;
3041 multibuf[count] = (byte)pnum; count += 1;
3045 multi_send_data(multibuf, count, 0);
3049 multi_send_controlcen_fire(vms_vector *to_goal, int best_gun_num, int objnum)
3052 vms_vector swapped_vec;
3056 multibuf[count] = MULTI_CONTROLCEN_FIRE; count += 1;
3058 memcpy(multibuf+count, to_goal, 12); count += 12;
3060 swapped_vec.x = (fix)INTEL_INT( (int)to_goal->x );
3061 swapped_vec.y = (fix)INTEL_INT( (int)to_goal->y );
3062 swapped_vec.z = (fix)INTEL_INT( (int)to_goal->z );
3063 memcpy(multibuf+count, &swapped_vec, 12); count += 12;
3065 multibuf[count] = (char)best_gun_num; count += 1;
3066 *(short *)(multibuf+count) = INTEL_SHORT( (short)objnum ); count += 2;
3069 multi_send_data(multibuf, count, 0);
3073 multi_send_create_powerup(int powerup_type, int segnum, int objnum, vms_vector *pos)
3075 // Create a powerup on a remote machine, used for remote
3076 // placement of used powerups like missiles and cloaking
3080 vms_vector swapped_vec;
3084 if (Game_mode & GM_NETWORK)
3085 PowerupsInMine[powerup_type]++;
3087 multibuf[count] = MULTI_CREATE_POWERUP; count += 1;
3088 multibuf[count] = Player_num; count += 1;
3089 multibuf[count] = powerup_type; count += 1;
3090 *(short *)(multibuf+count) = INTEL_SHORT( (short)segnum ); count += 2;
3091 *(short *)(multibuf+count) = INTEL_SHORT( (short)objnum ); count += 2;
3093 *(vms_vector *)(multibuf+count) = *pos; count += sizeof(vms_vector);
3095 swapped_vec.x = (fix)INTEL_INT( (int)pos->x );
3096 swapped_vec.y = (fix)INTEL_INT( (int)pos->y );
3097 swapped_vec.z = (fix)INTEL_INT( (int)pos->z );
3098 memcpy(multibuf+count, &swapped_vec, 12); count += 12;
3102 multi_send_data(multibuf, count, 2);
3104 if (Network_send_objects && network_objnum_is_past(objnum))
3106 mprintf((0, "Resetting object sync due to powerup creation.\n"));
3107 Network_send_objnum = -1;
3110 mprintf((0, "Creating powerup type %d in segment %i.\n", powerup_type, segnum));
3111 map_objnum_local_to_local(objnum);
3115 multi_send_play_sound(int sound_num, fix volume)
3118 multibuf[count] = MULTI_PLAY_SOUND; count += 1;
3119 multibuf[count] = Player_num; count += 1;
3120 multibuf[count] = (char)sound_num; count += 1;
3121 multibuf[count] = (char)(volume >> 12); count += 1;
3124 multi_send_data(multibuf, count, 0);
3128 multi_send_audio_taunt(int taunt_num)
3130 return; // Taken out, awaiting sounds..
3133 int audio_taunts[4] = {
3134 SOUND_CONTROL_CENTER_WARNING_SIREN,
3135 SOUND_HOSTAGE_RESCUED,
3136 SOUND_REFUEL_STATION_GIVING_FUEL,
3141 Assert(taunt_num >= 0);
3142 Assert(taunt_num < 4);
3144 digi_play_sample( audio_taunts[taunt_num], F1_0 );
3145 multi_send_play_sound(audio_taunts[taunt_num], F1_0);
3150 multi_send_score(void)
3152 // Send my current score to all other players so it will remain
3156 if (Game_mode & GM_MULTI_COOP) {
3157 multi_sort_kill_list();
3158 multibuf[count] = MULTI_SCORE; count += 1;
3159 multibuf[count] = Player_num; count += 1;
3160 *(int *)(multibuf+count) = INTEL_INT( Players[Player_num].score ); count += 4;
3161 multi_send_data(multibuf, count, 0);
3167 multi_send_save_game(ubyte slot, uint id, char * desc)
3171 multibuf[count] = MULTI_SAVE_GAME; count += 1;
3172 multibuf[count] = slot; count += 1; // Save slot=0
3173 *(uint *)(multibuf+count) = INTEL_INT( id ); count += 4; // Save id
3174 memcpy( &multibuf[count], desc, 20 ); count += 20;
3176 multi_send_data(multibuf, count, 2);
3180 multi_send_restore_game(ubyte slot, uint id)
3184 multibuf[count] = MULTI_RESTORE_GAME; count += 1;
3185 multibuf[count] = slot; count += 1; // Save slot=0
3186 *(uint *)(multibuf+count) = INTEL_INT( id ); count += 4; // Save id
3188 multi_send_data(multibuf, count, 2);
3192 multi_send_netplayer_stats_request(ubyte player_num)
3196 multibuf[count] = MULTI_REQ_PLAYER; count += 1;
3197 multibuf[count] = player_num; count += 1;
3199 multi_send_data(multibuf, count, 0 );
3203 multi_send_trigger(int triggernum)
3205 // Send an even to trigger something in the mine
3209 multibuf[count] = MULTI_TRIGGER; count += 1;
3210 multibuf[count] = Player_num; count += 1;
3211 multibuf[count] = (ubyte)triggernum; count += 1;
3213 mprintf ((0,"Sending trigger %d\n",triggernum));
3215 multi_send_data(multibuf, count, 1);
3216 //multi_send_data(multibuf, count, 1); // twice?
3220 multi_send_hostage_door_status(int wallnum)
3222 // Tell the other player what the hit point status of a hostage door
3227 Assert(Walls[wallnum].type == WALL_BLASTABLE);
3229 multibuf[count] = MULTI_HOSTAGE_DOOR; count += 1;
3230 *(short *)(multibuf+count) = INTEL_SHORT( (short)wallnum ); count += 2;
3231 *(fix *)(multibuf+count) = (fix)INTEL_INT( (int)Walls[wallnum].hps ); count += 4;
3233 // mprintf((0, "Door %d damaged by %f points.\n", wallnum, f2fl(Walls[wallnum].hps)));
3235 multi_send_data(multibuf, count, 0);
3238 extern int ConsistencyCount;
3239 extern int Drop_afterburner_blob_flag;
3243 void multi_prep_level(void)
3245 // Do any special stuff to the level required for serial games
3246 // before we begin playing in it.
3248 // Player_num MUST be set before calling this procedure.
3250 // This function must be called before checksuming the Object array,
3251 // since the resulting checksum with depend on the value of Player_num
3252 // at the time this is called.
3255 int cloak_count, inv_count;
3257 Assert(Game_mode & GM_MULTI);
3259 Assert(NumNetPlayerPositions > 0);
3263 Drop_afterburner_blob_flag=0;
3266 for (i=0;i<MAX_NUM_NET_PLAYERS;i++)
3269 for (i = 0; i < NumNetPlayerPositions; i++)
3271 if (i != Player_num)
3272 Objects[Players[i].objnum].control_type = CT_REMOTE;
3273 Objects[Players[i].objnum].movement_type = MT_PHYSICS;
3274 multi_reset_player_object(&Objects[Players[i].objnum]);
3275 LastPacketTime[i] = 0;
3279 for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
3281 robot_controlled[i] = -1;
3282 robot_agitation[i] = 0;
3287 Viewer = ConsoleObject = &Objects[Players[Player_num].objnum];
3289 if (!(Game_mode & GM_MULTI_COOP))
3291 multi_delete_extra_objects(); // Removes monsters from level
3294 if (Game_mode & GM_MULTI_ROBOTS)
3296 multi_set_robot_ai(); // Set all Robot AI to types we can cope with
3299 if (Game_mode & GM_NETWORK)
3301 multi_adjust_cap_for_player(Player_num);
3302 multi_send_powerup_update();
3303 ng=1; // ng means network game
3309 for (i=0; i<=Highest_object_index; i++)
3313 if ((Objects[i].type == OBJ_HOSTAGE) && !(Game_mode & GM_MULTI_COOP))
3315 objnum = obj_create(OBJ_POWERUP, POW_SHIELD_BOOST, Objects[i].segnum, &Objects[i].pos, &vmd_identity_matrix, Powerup_info[POW_SHIELD_BOOST].size, CT_POWERUP, MT_PHYSICS, RT_POWERUP);
3319 Objects[objnum].rtype.vclip_info.vclip_num = Powerup_info[POW_SHIELD_BOOST].vclip_num;
3320 Objects[objnum].rtype.vclip_info.frametime = Vclip[Objects[objnum].rtype.vclip_info.vclip_num].frame_time;
3321 Objects[objnum].rtype.vclip_info.framenum = 0;
3322 Objects[objnum].mtype.phys_info.drag = 512; //1024;
3323 Objects[objnum].mtype.phys_info.mass = F1_0;
3324 vm_vec_zero(&Objects[objnum].mtype.phys_info.velocity);
3329 if (Objects[i].type == OBJ_POWERUP)
3331 if (Objects[i].id == POW_EXTRA_LIFE)
3333 if (ng && !Netgame.DoInvulnerability)
3335 Objects[i].id = POW_SHIELD_BOOST;
3336 Objects[i].rtype.vclip_info.vclip_num = Powerup_info[Objects[i].id].vclip_num;
3337 Objects[i].rtype.vclip_info.frametime = Vclip[Objects[i].rtype.vclip_info.vclip_num].frame_time;
3341 Objects[i].id = POW_INVULNERABILITY;
3342 Objects[i].rtype.vclip_info.vclip_num = Powerup_info[Objects[i].id].vclip_num;
3343 Objects[i].rtype.vclip_info.frametime = Vclip[Objects[i].rtype.vclip_info.vclip_num].frame_time;
3348 if (!(Game_mode & GM_MULTI_COOP))
3349 if ((Objects[i].id >= POW_KEY_BLUE) && (Objects[i].id <= POW_KEY_GOLD))
3351 Objects[i].id = POW_SHIELD_BOOST;
3352 Objects[i].rtype.vclip_info.vclip_num = Powerup_info[Objects[i].id].vclip_num;
3353 Objects[i].rtype.vclip_info.frametime = Vclip[Objects[i].rtype.vclip_info.vclip_num].frame_time;
3356 if (Objects[i].id == POW_INVULNERABILITY) {
3357 if (inv_count >= 3 || (ng && !Netgame.DoInvulnerability)) {
3358 mprintf((0, "Bashing Invulnerability object #%i to shield.\n", i));
3359 Objects[i].id = POW_SHIELD_BOOST;
3360 Objects[i].rtype.vclip_info.vclip_num = Powerup_info[Objects[i].id].vclip_num;
3361 Objects[i].rtype.vclip_info.frametime = Vclip[Objects[i].rtype.vclip_info.vclip_num].frame_time;
3366 if (Objects[i].id == POW_CLOAK) {
3367 if (cloak_count >= 3 || (ng && !Netgame.DoCloak)) {
3368 mprintf((0, "Bashing Cloak object #%i to shield.\n", i));
3369 Objects[i].id = POW_SHIELD_BOOST;
3370 Objects[i].rtype.vclip_info.vclip_num = Powerup_info[Objects[i].id].vclip_num;
3371 Objects[i].rtype.vclip_info.frametime = Vclip[Objects[i].rtype.vclip_info.vclip_num].frame_time;
3376 if (Objects[i].id == POW_AFTERBURNER && ng && !Netgame.DoAfterburner)
3377 bash_to_shield (i,"afterburner");
3378 if (Objects[i].id == POW_FUSION_WEAPON && ng && !Netgame.DoFusions)
3379 bash_to_shield (i,"fusion");
3380 if (Objects[i].id == POW_PHOENIX_WEAPON && ng && !Netgame.DoPhoenix)
3381 bash_to_shield (i,"phoenix");
3383 if (Objects[i].id == POW_HELIX_WEAPON && ng && !Netgame.DoHelix)
3384 bash_to_shield (i,"helix");
3386 if (Objects[i].id == POW_MEGA_WEAPON && ng && !Netgame.DoMegas)
3387 bash_to_shield (i,"mega");
3389 if (Objects[i].id == POW_SMARTBOMB_WEAPON && ng && !Netgame.DoSmarts)
3390 bash_to_shield (i,"smartmissile");
3392 if (Objects[i].id == POW_GAUSS_WEAPON && ng && !Netgame.DoGauss)
3393 bash_to_shield (i,"gauss");
3395 if (Objects[i].id == POW_VULCAN_WEAPON && ng && !Netgame.DoVulcan)
3396 bash_to_shield (i,"vulcan");
3398 if (Objects[i].id == POW_PLASMA_WEAPON && ng && !Netgame.DoPlasma)
3399 bash_to_shield (i,"plasma");
3401 if (Objects[i].id == POW_OMEGA_WEAPON && ng && !Netgame.DoOmega)
3402 bash_to_shield (i,"omega");
3404 if (Objects[i].id == POW_SUPER_LASER && ng && !Netgame.DoSuperLaser)
3405 bash_to_shield (i,"superlaser");
3407 if (Objects[i].id == POW_PROXIMITY_WEAPON && ng && !Netgame.DoProximity)
3408 bash_to_shield (i,"proximity");
3410 // Special: Make all proximity bombs into shields if in
3411 // hoard mode because we use the proximity slot in the
3412 // player struct to signify how many orbs the player has.
3414 if (Objects[i].id == POW_PROXIMITY_WEAPON && ng && (Game_mode & GM_HOARD))
3415 bash_to_shield (i,"proximity");
3417 if (Objects[i].id==POW_VULCAN_AMMO && ng && (!Netgame.DoVulcan && !Netgame.DoGauss))
3418 bash_to_shield(i,"vulcan ammo");
3420 if (Objects[i].id == POW_SPREADFIRE_WEAPON && ng && !Netgame.DoSpread)
3421 bash_to_shield (i,"spread");
3422 if (Objects[i].id == POW_SMART_MINE && ng && !Netgame.DoSmartMine)
3423 bash_to_shield (i,"smartmine");
3424 if (Objects[i].id == POW_SMISSILE1_1 && ng && !Netgame.DoFlash)
3425 bash_to_shield (i,"flash");
3426 if (Objects[i].id == POW_SMISSILE1_4 && ng && !Netgame.DoFlash)
3427 bash_to_shield (i,"flash");
3428 if (Objects[i].id == POW_GUIDED_MISSILE_1 && ng && !Netgame.DoGuided)
3429 bash_to_shield (i,"guided");
3430 if (Objects[i].id == POW_GUIDED_MISSILE_4 && ng && !Netgame.DoGuided)
3431 bash_to_shield (i,"guided");
3432 if (Objects[i].id == POW_EARTHSHAKER_MISSILE && ng && !Netgame.DoEarthShaker)
3433 bash_to_shield (i,"earth");
3434 if (Objects[i].id == POW_MERCURY_MISSILE_1 && ng && !Netgame.DoMercury)
3435 bash_to_shield (i,"Mercury");
3436 if (Objects[i].id == POW_MERCURY_MISSILE_4 && ng && !Netgame.DoMercury)
3437 bash_to_shield (i,"Mercury");
3438 if (Objects[i].id == POW_CONVERTER && ng && !Netgame.DoConverter)
3439 bash_to_shield (i,"Converter");
3440 if (Objects[i].id == POW_AMMO_RACK && ng && !Netgame.DoAmmoRack)
3441 bash_to_shield (i,"Ammo rack");
3442 if (Objects[i].id == POW_HEADLIGHT && ng && !Netgame.DoHeadlight)
3443 bash_to_shield (i,"Headlight");
3444 if (Objects[i].id == POW_LASER && ng && !Netgame.DoLaserUpgrade)
3445 bash_to_shield (i,"Laser powerup");
3446 if (Objects[i].id == POW_HOMING_AMMO_1 && ng && !Netgame.DoHoming)
3447 bash_to_shield (i,"Homing");
3448 if (Objects[i].id == POW_HOMING_AMMO_4 && ng && !Netgame.DoHoming)
3449 bash_to_shield (i,"Homing");
3450 if (Objects[i].id == POW_QUAD_FIRE && ng && !Netgame.DoQuadLasers)
3451 bash_to_shield (i,"Quad Lasers");
3452 if (Objects[i].id == POW_FLAG_BLUE && !(Game_mode & GM_CAPTURE))
3453 bash_to_shield (i,"Blue flag");
3454 if (Objects[i].id == POW_FLAG_RED && !(Game_mode & GM_CAPTURE))
3455 bash_to_shield (i,"Red flag");
3459 if (Game_mode & GM_HOARD)
3462 if ((Game_mode & GM_CAPTURE) || (Game_mode & GM_HOARD))
3463 multi_apply_goal_textures();
3465 multi_sort_kill_list();
3467 multi_show_player_list();
3469 ConsoleObject->control_type = CT_FLYING;
3471 reset_player_object();
3475 int Goal_blue_segnum,Goal_red_segnum;
3477 void multi_apply_goal_textures()
3483 for (i=0; i <= Highest_segment_index; i++)
3486 seg2 = &Segment2s[i];
3488 if (seg2->special==SEGMENT_IS_GOAL_BLUE)
3491 Goal_blue_segnum = i;
3493 if (Game_mode & GM_HOARD)
3494 tex=find_goal_texture (TMI_GOAL_HOARD);
3496 tex=find_goal_texture (TMI_GOAL_BLUE);
3499 for (j = 0; j < 6; j++) {
3501 seg->sides[j].tmap_num=tex;
3503 seg->sides[j].uvls[v].l = i2f(100); //max out
3506 seg2->static_light = i2f(100); //make static light bright
3510 if (seg2->special==SEGMENT_IS_GOAL_RED)
3512 Goal_red_segnum = i;
3514 // Make both textures the same if Hoard mode
3516 if (Game_mode & GM_HOARD)
3517 tex=find_goal_texture (TMI_GOAL_HOARD);
3519 tex=find_goal_texture (TMI_GOAL_RED);
3522 for (j = 0; j < 6; j++) {
3524 seg->sides[j].tmap_num=tex;
3526 seg->sides[j].uvls[v].l = i2f(1000); //max out
3529 seg2->static_light = i2f(100); //make static light bright
3533 int find_goal_texture (ubyte t)
3537 for (i=0;i<NumTextures;i++)
3538 if (TmapInfo[i].flags & t)
3541 Int3(); // Hey, there is no goal texture for this PIG!!!!
3542 // Edit bitmaps.tbl and designate two textures to be RED and BLUE
3548 /* DPH: Moved to gameseq.c
3549 void bash_to_shield (int i,char *s)
3551 int type=Objects[i].id;
3553 mprintf((0, "Bashing %s object #%i to shield.\n",s, i));
3555 PowerupsInMine[type]=MaxPowerupsAllowed[type]=0;
3557 Objects[i].id = POW_SHIELD_BOOST;
3558 Objects[i].rtype.vclip_info.vclip_num = Powerup_info[Objects[i].id].vclip_num;
3559 Objects[i].rtype.vclip_info.frametime = Vclip[Objects[i].rtype.vclip_info.vclip_num].frame_time;
3563 void multi_set_robot_ai(void)
3565 // Go through the objects array looking for robots and setting
3566 // them to certain supported types of NET AI behavior.
3570 // for (i = 0; i <= Highest_object_index; i++)
3572 // if (Objects[i].type == OBJ_ROBOT) {
3573 // Objects[i].ai_info.REMOTE_OWNER = -1;
3574 // if (Objects[i].ai_info.behavior == AIB_STATION)
3575 // Objects[i].ai_info.behavior = AIB_NORMAL;
3580 int multi_delete_extra_objects()
3586 // Go through the object list and remove any objects not used in
3587 // 'Anarchy!' games.
3589 // This function also prints the total number of available multiplayer
3590 // positions in this level, even though this should always be 8 or more!
3593 for (i=0;i<=Highest_object_index;i++) {
3594 if ((objp->type==OBJ_PLAYER) || (objp->type==OBJ_GHOST))
3596 else if ((objp->type==OBJ_ROBOT) && (Game_mode & GM_MULTI_ROBOTS))
3598 else if ( (objp->type!=OBJ_NONE) && (objp->type!=OBJ_PLAYER) && (objp->type!=OBJ_POWERUP) && (objp->type!=OBJ_CNTRLCEN) && (objp->type!=OBJ_HOSTAGE) && !(objp->type==OBJ_WEAPON && objp->id==PMINE_ID) ) {
3599 // Before deleting object, if it's a robot, drop it's special powerup, if any
3600 if (objp->type == OBJ_ROBOT)
3601 if (objp->contains_count && (objp->contains_type == OBJ_POWERUP))
3602 object_create_egg(objp);
3611 void change_playernum_to( int new_Player_num )
3613 if (Player_num > -1)
3614 memcpy( Players[new_Player_num].callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
3615 Player_num = new_Player_num;
3618 int multi_all_players_alive()
3621 for (i=0;i<N_players;i++)
3623 if (PKilledFlags[i] && Players[i].connected)
3629 void multi_initiate_save_game()
3636 if ((Endlevel_sequence) || (Control_center_destroyed))
3639 if (!multi_all_players_alive())
3641 HUD_init_message ("Can't save...all players must be alive!");
3645 //multi_send_netplayer_stats_request(255);
3650 slot = state_get_save_file(filename, desc, 1 );
3659 // Make a unique game id
3660 game_id = timer_get_fixed_seconds();
3661 game_id ^= N_players<<4;
3662 for (i=0; i<N_players; i++ )
3663 game_id ^= *(uint *)Players[i].callsign;
3664 if ( game_id == 0 ) game_id = 1; // 0 is invalid
3666 mprintf(( 1, "Game_id = %8x\n", game_id));
3667 multi_send_save_game(slot, game_id, desc );
3669 multi_save_game(slot,game_id, desc );
3672 extern int state_get_game_id(char *);
3674 void multi_initiate_restore_game()
3679 if ((Endlevel_sequence) || (Control_center_destroyed))
3682 if (!multi_all_players_alive())
3684 HUD_init_message ("Can't restore...all players must be alive!");
3689 slot = state_get_restore_file(filename,1);
3694 state_game_id=state_get_game_id (filename);
3700 multi_send_restore_game(slot,state_game_id);
3702 multi_restore_game(slot,state_game_id);
3705 void multi_save_game(ubyte slot, uint id, char *desc)
3709 if ((Endlevel_sequence) || (Control_center_destroyed))
3713 sprintf( filename, "%s.mg%d", Players[Player_num].callsign, slot );
3715 sprintf( filename, ":Players:%s.mg%d", Players[Player_num].callsign, slot );
3717 mprintf(( 0, "Save game %x on slot %d\n", id, slot ));
3718 HUD_init_message( "Saving game #%d, '%s'", slot, desc );
3721 state_save_all_sub(filename, desc, 0 );
3724 void multi_restore_game(ubyte slot, uint id)
3727 player saved_player;
3731 if ((Endlevel_sequence) || (Control_center_destroyed))
3734 mprintf(( 0, "Restore game %x from slot %d\n", id, slot ));
3735 saved_player = Players[Player_num];
3737 sprintf( filename, "%s.mg%d", Players[Player_num].callsign, slot );
3739 sprintf( filename, ":Players:%s.mg%d", Players[Player_num].callsign, slot );
3742 for (i=0;i<N_players;i++)
3743 multi_strip_robots(i);
3745 thisid=state_get_game_id (filename);
3748 multi_bad_restore ();
3752 pnum=state_restore_all_sub( filename, 1, 0 );
3754 mprintf ((0,"StateId=%d ThisID=%d\n",state_game_id,id));
3757 if (state_game_id != id ) {
3758 // Game doesn't match!!!
3759 nm_messagebox( "Error", 1, "Ok", "Cannot restore saved game" );
3760 Game_mode |= GM_GAME_OVER;
3761 Function_mode = FMODE_MENU;
3762 longjmp(LeaveGame, 0);
3765 change_playernum_to(pnum-1);
3766 memcpy( Players[Player_num].callsign, saved_player.callsign, CALLSIGN_LEN+1 );
3767 memcpy( Players[Player_num].net_address, saved_player.net_address, 6 );
3768 Players[Player_num].connected = saved_player.connected;
3769 Players[Player_num].n_packets_got = saved_player.n_packets_got;
3770 Players[Player_num].n_packets_sent = saved_player.n_packets_sent;
3771 Viewer = ConsoleObject = &Objects[pnum-1];
3777 void extract_netplayer_stats( netplayer_stats *ps, player * pd )
3781 ps->flags = INTEL_INT(pd->flags); // Powerup flags, see below...
3782 ps->energy = (fix)INTEL_INT(pd->energy); // Amount of energy remaining.
3783 ps->shields = (fix)INTEL_INT(pd->shields); // shields remaining (protection)
3784 ps->lives = pd->lives; // Lives remaining, 0 = game over.
3785 ps->laser_level = pd->laser_level; // Current level of the laser.
3786 ps->primary_weapon_flags=pd->primary_weapon_flags; // bit set indicates the player has this weapon.
3787 ps->secondary_weapon_flags=pd->secondary_weapon_flags; // bit set indicates the player has this weapon.
3788 for (i = 0; i < MAX_PRIMARY_WEAPONS; i++)
3789 ps->primary_ammo[i] = INTEL_SHORT(pd->primary_ammo[i]);
3790 for (i = 0; i < MAX_SECONDARY_WEAPONS; i++)
3791 ps->secondary_ammo[i] = INTEL_SHORT(pd->secondary_ammo[i]);
3793 //memcpy( ps->primary_ammo, pd->primary_ammo, MAX_PRIMARY_WEAPONS*sizeof(short) ); // How much ammo of each type.
3794 //memcpy( ps->secondary_ammo, pd->secondary_ammo, MAX_SECONDARY_WEAPONS*sizeof(short) ); // How much ammo of each type.
3796 ps->last_score=INTEL_INT(pd->last_score); // Score at beginning of current level.
3797 ps->score=INTEL_INT(pd->score); // Current score.
3798 ps->cloak_time=(fix)INTEL_INT(pd->cloak_time); // Time cloaked
3799 ps->homing_object_dist=(fix)INTEL_INT(pd->homing_object_dist); // Distance of nearest homing object.
3800 ps->invulnerable_time=(fix)INTEL_INT(pd->invulnerable_time); // Time invulnerable
3801 ps->KillGoalCount=INTEL_SHORT(pd->KillGoalCount);
3802 ps->net_killed_total=INTEL_SHORT(pd->net_killed_total); // Number of times killed total
3803 ps->net_kills_total=INTEL_SHORT(pd->net_kills_total); // Number of net kills total
3804 ps->num_kills_level=INTEL_SHORT(pd->num_kills_level); // Number of kills this level
3805 ps->num_kills_total=INTEL_SHORT(pd->num_kills_total); // Number of kills total
3806 ps->num_robots_level=INTEL_SHORT(pd->num_robots_level); // Number of initial robots this level
3807 ps->num_robots_total=INTEL_SHORT(pd->num_robots_total); // Number of robots total
3808 ps->hostages_rescued_total=INTEL_SHORT(pd->hostages_rescued_total); // Total number of hostages rescued.
3809 ps->hostages_total=INTEL_SHORT(pd->hostages_total); // Total number of hostages.
3810 ps->hostages_on_board=pd->hostages_on_board; // Number of hostages on ship.
3813 void use_netplayer_stats( player * ps, netplayer_stats *pd )
3817 ps->flags = INTEL_INT(pd->flags); // Powerup flags, see below...
3818 ps->energy = (fix)INTEL_INT((int)pd->energy); // Amount of energy remaining.
3819 ps->shields = (fix)INTEL_INT((int)pd->shields); // shields remaining (protection)
3820 ps->lives = pd->lives; // Lives remaining, 0 = game over.
3821 ps->laser_level = pd->laser_level; // Current level of the laser.
3822 ps->primary_weapon_flags=pd->primary_weapon_flags; // bit set indicates the player has this weapon.
3823 ps->secondary_weapon_flags=pd->secondary_weapon_flags; // bit set indicates the player has this weapon.
3824 for (i = 0; i < MAX_PRIMARY_WEAPONS; i++)
3825 ps->primary_ammo[i] = INTEL_SHORT(pd->primary_ammo[i]);
3826 for (i = 0; i < MAX_SECONDARY_WEAPONS; i++)
3827 ps->secondary_ammo[i] = INTEL_SHORT(pd->secondary_ammo[i]);
3828 //memcpy( ps->primary_ammo, pd->primary_ammo, MAX_PRIMARY_WEAPONS*sizeof(short) ); // How much ammo of each type.
3829 //memcpy( ps->secondary_ammo, pd->secondary_ammo, MAX_SECONDARY_WEAPONS*sizeof(short) ); // How much ammo of each type.
3830 ps->last_score = INTEL_INT(pd->last_score); // Score at beginning of current level.
3831 ps->score = INTEL_INT(pd->score); // Current score.
3832 ps->cloak_time = (fix)INTEL_INT((int)pd->cloak_time); // Time cloaked
3833 ps->homing_object_dist = (fix)INTEL_INT((int)pd->homing_object_dist); // Distance of nearest homing object.
3834 ps->invulnerable_time = (fix)INTEL_INT((int)pd->invulnerable_time); // Time invulnerable
3835 ps->KillGoalCount=INTEL_SHORT(pd->KillGoalCount);
3836 ps->net_killed_total = INTEL_SHORT(pd->net_killed_total); // Number of times killed total
3837 ps->net_kills_total = INTEL_SHORT(pd->net_kills_total); // Number of net kills total
3838 ps->num_kills_level = INTEL_SHORT(pd->num_kills_level); // Number of kills this level
3839 ps->num_kills_total = INTEL_SHORT(pd->num_kills_total); // Number of kills total
3840 ps->num_robots_level = INTEL_SHORT(pd->num_robots_level); // Number of initial robots this level
3841 ps->num_robots_total = INTEL_SHORT(pd->num_robots_total); // Number of robots total
3842 ps->hostages_rescued_total = INTEL_SHORT(pd->hostages_rescued_total); // Total number of hostages rescued.
3843 ps->hostages_total = INTEL_SHORT(pd->hostages_total); // Total number of hostages.
3844 ps->hostages_on_board=pd->hostages_on_board; // Number of hostages on ship.
3847 void multi_send_drop_weapon (int objnum,int seed)
3853 objp = &Objects[objnum];
3855 ammo_count = objp->ctype.powerup_info.count;
3857 if (objp->id == POW_OMEGA_WEAPON && ammo_count == F1_0)
3858 ammo_count = F1_0 - 1; //make fit in short
3860 Assert(ammo_count < F1_0); //make sure fits in short
3862 multibuf[count++]=(char)MULTI_DROP_WEAPON;
3863 multibuf[count++]=(char)objp->id;
3865 *(short *) (multibuf+count)=INTEL_SHORT(Player_num); count += 2;
3866 *(short *) (multibuf+count)=INTEL_SHORT(objnum); count += 2;
3867 *(short *) (multibuf+count)=INTEL_SHORT(ammo_count); count += 2;
3868 *(int *) (multibuf+count)=INTEL_INT(seed);
3870 map_objnum_local_to_local(objnum);
3872 if (Game_mode & GM_NETWORK)
3873 PowerupsInMine[objp->id]++;
3875 multi_send_data(multibuf, 12, 2);
3878 void multi_do_drop_weapon (char *buf)
3880 int pnum,ammo,objnum,remote_objnum,seed;
3884 powerup_id=(int)(buf[1]);
3885 pnum = INTEL_SHORT(*(short *)(buf+2));
3886 remote_objnum = INTEL_SHORT(*(short *)(buf+4));
3887 ammo = INTEL_SHORT(*(ushort *)(buf+6));
3888 seed = INTEL_INT(*(int *)(buf+8));
3890 objp = &Objects[Players[pnum].objnum];
3892 objnum = spit_powerup(objp, powerup_id, seed);
3894 map_objnum_local_to_remote(objnum, remote_objnum, pnum);
3897 Objects[objnum].ctype.powerup_info.count = ammo;
3899 if (Game_mode & GM_NETWORK)
3900 PowerupsInMine[powerup_id]++;
3902 mprintf ((0,"Dropped weapon %d!\n"));
3906 void multi_send_guided_info (object *miss,char done)
3913 mprintf ((0,"Sending guided info!\n"));
3915 multibuf[count++]=(char)MULTI_GUIDED;
3916 multibuf[count++]=(char)Player_num;
3917 multibuf[count++]=done;
3920 create_shortpos((shortpos *)(multibuf+count), miss,0);
3921 count+=sizeof(shortpos);
3923 create_shortpos(&sp, miss, 1);
3924 memcpy(&(multibuf[count]), (ubyte *)(sp.bytemat), 9);
3926 memcpy(&(multibuf[count]), (ubyte *)&(sp.xo), 14);
3930 multi_send_data(multibuf, count, 0);
3933 void multi_do_guided (char *buf)
3942 if (Guided_missile[(int)pnum]==NULL)
3946 mprintf ((0,"Guided missile for %s is NULL!\n",Players[(int)pnum].callsign));
3953 mprintf ((0,"Got guided info for %d (%s)\n",pnum,Players[(int)pnum].callsign));
3959 release_guided_missile(pnum);
3964 if (Guided_missile[(int)pnum]-Objects<0 || Guided_missile[(int)pnum]-Objects > Highest_object_index)
3966 Int3(); // Get Jason immediately!
3971 extract_shortpos(Guided_missile[(int)pnum], (shortpos *)(buf+count),0);
3973 memcpy((ubyte *)(sp.bytemat), (ubyte *)(buf + count), 9);
3974 memcpy((ubyte *)&(sp.xo), (ubyte *)(buf + count + 9), 14);
3975 extract_shortpos(Guided_missile[(int)pnum], &sp, 1);
3978 count+=sizeof (shortpos);
3980 update_object_seg(Guided_missile[(int)pnum]);
3983 void multi_send_stolen_items ()
3986 multibuf[0]=MULTI_STOLEN_ITEMS;
3988 for (i=0;i<MAX_STOLEN_ITEMS;i++)
3990 multibuf[i+1]=Stolen_items[i];
3991 mprintf ((0,"[%d]=%d ",i,Stolen_items[i]));
3992 count++; // So I like to break my stuff into smaller chunks, so what?
3995 multi_send_data(multibuf, count, 1);
3998 void multi_do_stolen_items (char *buf)
4002 mprintf ((0,"Recieved a stolen item packet...\n"));
4004 for (i=0;i<MAX_STOLEN_ITEMS;i++)
4006 Stolen_items[i]=buf[i+1];
4007 mprintf ((0,"[%d]=%d ",i,Stolen_items[i]));
4012 extern void network_send_important_packet (char *,int);
4014 void multi_send_wall_status (int wallnum,ubyte type,ubyte flags,ubyte state)
4017 multibuf[count]=MULTI_WALL_STATUS; count++;
4018 *(short *)(multibuf+count)=INTEL_SHORT(wallnum); count+=2;
4019 multibuf[count]=type; count++;
4020 multibuf[count]=flags; count++;
4021 multibuf[count]=state; count++;
4024 if (Game_mode & GM_NETWORK)
4026 network_send_important_packet (multibuf,count);
4027 network_send_important_packet (multibuf,count);
4032 multi_send_data(multibuf, count, 1); // twice, just to be sure
4033 multi_send_data(multibuf, count, 1);
4036 void multi_send_wall_status_specific (int pnum,int wallnum,ubyte type,ubyte flags,ubyte state)
4038 // Send wall states a specific rejoining player
4042 Assert (Game_mode & GM_NETWORK);
4043 //Assert (pnum>-1 && pnum<N_players);
4045 multibuf[count]=MULTI_WALL_STATUS; count++;
4046 *(short *)(multibuf+count)=INTEL_SHORT(wallnum); count+=2;
4047 multibuf[count]=type; count++;
4048 multibuf[count]=flags; count++;
4049 multibuf[count]=state; count++;
4051 network_send_naked_packet(multibuf, count,pnum); // twice, just to be sure
4052 network_send_naked_packet(multibuf, count,pnum);
4055 void multi_do_wall_status (char *buf)
4058 ubyte flag,type,state;
4060 wallnum=INTEL_SHORT( *(short *)(buf+1) );
4065 Assert (wallnum>=0);
4066 Walls[wallnum].type=type;
4067 Walls[wallnum].flags=flag;
4068 //Assert(state <= 4);
4069 Walls[wallnum].state=state;
4071 if (Walls[wallnum].type==WALL_OPEN)
4073 digi_kill_sound_linked_to_segment(Walls[wallnum].segnum,Walls[wallnum].sidenum,SOUND_FORCEFIELD_HUM);
4074 //digi_kill_sound_linked_to_segment(csegp-Segments,cside,SOUND_FORCEFIELD_HUM);
4078 //mprintf ((0,"Got a walls packet.\n"));
4081 void multi_send_jason_cheat (int num)
4087 void multi_send_kill_goal_counts()
4090 multibuf[0]=MULTI_KILLGOALS;
4092 for (i=0;i<MAX_PLAYERS;i++)
4094 *(char *)(multibuf+count)=(char)Players[i].KillGoalCount;
4098 mprintf ((0,"MULTI: Sending KillGoalCounts...\n"));
4099 multi_send_data(multibuf, count, 1);
4102 void multi_do_kill_goal_counts(char *buf)
4106 for (i=0;i<MAX_PLAYERS;i++)
4108 Players[i].KillGoalCount=*(char *)(buf+count);
4109 mprintf ((0,"KGC: %s has %d kills!\n",Players[i].callsign,Players[i].KillGoalCount));
4115 void multi_send_heartbeat ()
4117 if (!Netgame.PlayTimeAllowed)
4120 multibuf[0]=MULTI_HEARTBEAT;
4121 *(fix *)(multibuf+1)=(fix)INTEL_INT(ThisLevelTime);
4122 multi_send_data(multibuf, 5, 0);
4125 void multi_do_heartbeat (char *buf)
4129 num=(fix)INTEL_INT(*(int *)(buf+1));
4134 void multi_check_for_killgoal_winner ()
4136 int i,best=0,bestnum=0;
4139 if (Control_center_destroyed)
4142 for (i=0;i<N_players;i++)
4144 if (Players[i].KillGoalCount>best)
4146 best=Players[i].KillGoalCount;
4151 if (bestnum==Player_num)
4153 HUD_init_message("You have the best score at %d kills!",best);
4154 //Players[Player_num].shields=i2f(200);
4158 HUD_init_message ("%s has the best score with %d kills!",Players[bestnum].callsign,best);
4160 HUD_init_message ("The control center has been destroyed!");
4162 objp=obj_find_first_of_type (OBJ_CNTRLCEN);
4163 net_destroy_controlcen (objp);
4166 void multi_send_seismic (fix start,fix end)
4170 multibuf[0]=MULTI_SEISMIC;
4171 *(fix *)(multibuf+count)=(fix)INTEL_INT(start); count+=(sizeof(fix));
4172 *(fix *)(multibuf+count)=(fix)INTEL_INT(end); count+=(sizeof(fix));
4174 multi_send_data(multibuf, count, 1);
4177 extern fix Seismic_disturbance_start_time;
4178 extern fix Seismic_disturbance_end_time;
4180 void multi_do_seismic (char *buf)
4182 Seismic_disturbance_start_time=(fix)INTEL_INT( *(int *)(buf+1) );
4183 Seismic_disturbance_end_time=(fix)INTEL_INT( *(int *)(buf+5) );
4184 digi_play_sample (SOUND_SEISMIC_DISTURBANCE_START, F1_0);
4187 void multi_send_light (int segnum,ubyte val)
4190 multibuf[0]=MULTI_LIGHT;
4191 *(int *)(multibuf+count)=INTEL_INT(segnum); count+=(sizeof(int));
4192 *(char *)(multibuf+count)=val; count++;
4195 //mprintf ((0,"Sending %d!\n",Segments[segnum].sides[i].tmap_num2));
4196 *(short *)(multibuf+count)=INTEL_SHORT(Segments[segnum].sides[i].tmap_num2); count+=2;
4198 multi_send_data(multibuf, count, 1);
4200 void multi_send_light_specific (int pnum,int segnum,ubyte val)
4204 Assert (Game_mode & GM_NETWORK);
4205 // Assert (pnum>-1 && pnum<N_players);
4207 multibuf[0]=MULTI_LIGHT;
4208 *(int *)(multibuf+count)=INTEL_INT(segnum); count+=(sizeof(int));
4209 *(char *)(multibuf+count)=val; count++;
4213 //mprintf ((0,"Sending %d!\n",Segments[segnum].sides[i].tmap_num2));
4214 *(short *)(multibuf+count)=INTEL_SHORT(Segments[segnum].sides[i].tmap_num2); count+=2;
4216 network_send_naked_packet(multibuf, count, pnum);
4219 void multi_do_light (char *buf)
4222 int seg=INTEL_INT(*(int *)(buf+1));
4223 ubyte sides=*(char *)(buf+5);
4227 if ((sides & (1<<i)))
4229 subtract_light (seg,i);
4230 Segments[seg].sides[i].tmap_num2=INTEL_SHORT( *(short *)(buf+(6+(2*i))) );
4231 //mprintf ((0,"Got %d!\n",Segments[seg].sides[i].tmap_num2));
4236 //@@void multi_send_start_trigger(int triggernum)
4238 //@@ // Send an even to trigger something in the mine
4242 //@@ multibuf[count] = MULTI_START_TRIGGER; count += 1;
4243 //@@ multibuf[count] = Player_num; count += 1;
4244 //@@ multibuf[count] = (ubyte)triggernum; count += 1;
4246 //@@ //mprintf ((0,"Sending start trigger %d\n",triggernum));
4247 //@@ multi_send_data(multibuf, count, 2);
4249 //@@void multi_do_start_trigger(char *buf)
4251 //@@ int pnum = buf[1];
4252 //@@ int trigger = buf[2];
4254 //@@ //mprintf ((0,"MULTI doing start trigger!\n"));
4256 //@@ if ((pnum < 0) || (pnum >= N_players) || (pnum == Player_num))
4258 //@@ Int3(); // Got trigger from illegal playernum
4261 //@@ if ((trigger < 0) || (trigger >= Num_triggers))
4263 //@@ Int3(); // Illegal trigger number in multiplayer
4267 //@@ if (!(Triggers[trigger].flags & TF_SPRUNG))
4268 //@@ check_trigger_sub(trigger, pnum,0);
4272 void multi_do_flags (char *buf)
4275 uint flags=INTEL_INT( *(uint *)(buf+2) );
4277 if (pnum!=Player_num)
4278 Players[(int)pnum].flags=flags;
4281 void multi_send_flags (char pnum)
4283 multibuf[0]=MULTI_FLAGS;
4285 *(uint *)(multibuf+2)=INTEL_INT(Players[(int)pnum].flags);
4287 multi_send_data(multibuf, 6, 1);
4290 void multi_send_drop_blobs (char pnum)
4292 multibuf[0]=MULTI_DROP_BLOB;
4295 multi_send_data(multibuf, 2, 0);
4298 void multi_do_drop_blob (char *buf)
4301 drop_afterburner_blobs (&Objects[Players[(int)pnum].objnum], 2, i2f(5)/2, -1);
4304 void multi_send_powerup_update ()
4309 multibuf[0]=MULTI_POWERUP_UPDATE;
4310 for (i=0;i<MAX_POWERUP_TYPES;i++)
4311 multibuf[i+1]=MaxPowerupsAllowed[i];
4313 multi_send_data(multibuf, MAX_POWERUP_TYPES+1, 1);
4315 void multi_do_powerup_update (char *buf)
4319 for (i=0;i<MAX_POWERUP_TYPES;i++)
4320 if (buf[i+1]>MaxPowerupsAllowed[i])
4321 MaxPowerupsAllowed[i]=buf[i+1];
4324 extern active_door ActiveDoors[];
4325 extern int Num_open_doors; // Number of open doors
4327 void multi_send_active_door (char i)
4331 multibuf[0]=MULTI_ACTIVE_DOOR;
4333 multibuf[2]=Num_open_doors;
4336 memcpy ((char *)(&multibuf[3]),&ActiveDoors[(int)i],sizeof(struct active_door));
4337 count += sizeof(active_door);
4339 *(int *)(multibuf + count) = INTEL_INT(ActiveDoors[i].n_parts); count += 4;
4340 *(short *)(multibuf + count) = INTEL_SHORT(ActiveDoors[i].front_wallnum[0]); count += 2;
4341 *(short *)(multibuf + count) = INTEL_SHORT(ActiveDoors[i].front_wallnum[1]) count += 2;
4342 *(short *)(multibuf + count) = INTEL_SHORT(ActiveDoors[i].back_wallnum[0]); count += 2;
4343 *(short *)(multibuf + count) = INTEL_SHORT(ActiveDoors[i].back_wallnum[1]); count += 2;
4344 *(int *)(multibuf + count) = INTEL_INT(ActiveDoors[i].time); count += 4;
4346 //multi_send_data (multibuf,sizeof(struct active_door)+3,1);
4347 multi_send_data (multibuf,count,1);
4350 void multi_do_active_door (char *buf)
4354 Num_open_doors=buf[2];
4358 memcpy (&ActiveDoors[(int)i],buf+count,sizeof(struct active_door));
4360 ActiveDoors[i].n_parts = INTEL_INT( *(int *)(buf+count) ); count += 4;
4361 ActiveDoors[i].front_wallnum[0] = INTEL_SHORT( *(short *)(buf+count) ); count +=2;
4362 ActiveDoors[i].front_wallnum[1] = INTEL_SHORT( *(short *)(buf+count) ); count +=2;
4363 ActiveDoors[i].back_wallnum[0] = INTEL_SHORT( *(short *)(buf+count) ); count +=2;
4364 ActiveDoors[i].back_wallnum[1] = INTEL_SHORT( *(short *)(buf+count) ); count +=2;
4365 ActiveDoors[i].time = INTEL_INT( *(int *)(buf+count) ); count += 4;
4369 void multi_send_sound_function (char whichfunc,char sound)
4373 multibuf[0]=MULTI_SOUND_FUNCTION; count++;
4374 multibuf[1]=Player_num; count++;
4375 multibuf[2]=whichfunc; count++;
4377 *(uint *)(multibuf+count)=sound; count++;
4379 multibuf[3] = sound; count++; // this would probably work on the PC as well. Jason?
4381 multi_send_data (multibuf,4,0);
4384 #define AFTERBURNER_LOOP_START 20098
4385 #define AFTERBURNER_LOOP_END 25776
4387 void multi_do_sound_function (char *buf)
4391 char pnum,whichfunc;
4394 if (Players[Player_num].connected!=1)
4402 digi_kill_sound_linked_to_object (Players[(int)pnum].objnum);
4403 else if (whichfunc==3)
4404 digi_link_sound_to_object3( sound, Players[(int)pnum].objnum, 1,F1_0, i2f(256), AFTERBURNER_LOOP_START, AFTERBURNER_LOOP_END);
4407 void multi_send_capture_bonus (char pnum)
4409 Assert (Game_mode & GM_CAPTURE);
4411 multibuf[0]=MULTI_CAPTURE_BONUS;
4414 multi_send_data (multibuf,2,1);
4415 multi_do_capture_bonus (multibuf);
4417 void multi_send_orb_bonus (char pnum)
4419 Assert (Game_mode & GM_HOARD);
4421 multibuf[0]=MULTI_ORB_BONUS;
4423 multibuf[2]=Players[Player_num].secondary_ammo[PROXIMITY_INDEX];
4425 multi_send_data (multibuf,3,1);
4426 multi_do_orb_bonus (multibuf);
4428 void multi_do_capture_bonus(char *buf)
4430 // Figure out the results of a network kills and add it to the
4431 // appropriate player's tally.
4436 kmatrix_kills_changed = 1;
4438 if (pnum==Player_num)
4439 HUD_init_message("You have Scored!");
4441 HUD_init_message("%s has Scored!",Players[(int)pnum].callsign);
4443 if (pnum==Player_num)
4444 digi_play_sample (SOUND_HUD_YOU_GOT_GOAL,F1_0*2);
4445 else if (get_team(pnum)==TEAM_RED)
4446 digi_play_sample (SOUND_HUD_RED_GOT_GOAL,F1_0*2);
4448 digi_play_sample (SOUND_HUD_BLUE_GOT_GOAL,F1_0*2);
4450 Players[(int)pnum].flags &= ~(PLAYER_FLAGS_FLAG); // Clear capture flag
4452 team_kills[get_team(pnum)] += 5;
4453 Players[(int)pnum].net_kills_total += 5;
4454 Players[(int)pnum].KillGoalCount+=5;
4456 if (Netgame.KillGoal>0)
4458 TheGoal=Netgame.KillGoal*5;
4460 if (Players[(int)pnum].KillGoalCount>=TheGoal)
4462 if (pnum==Player_num)
4464 HUD_init_message("You reached the kill goal!");
4465 Players[Player_num].shields=i2f(200);
4468 HUD_init_message ("%s has reached the kill goal!",Players[(int)pnum].callsign);
4470 HUD_init_message ("The control center has been destroyed!");
4471 net_destroy_controlcen (obj_find_first_of_type (OBJ_CNTRLCEN));
4475 multi_sort_kill_list();
4476 multi_show_player_list();
4479 int GetOrbBonus (char num)
4483 bonus=num*(num+1)/2;
4487 void multi_do_orb_bonus(char *buf)
4489 // Figure out the results of a network kills and add it to the
4490 // appropriate player's tally.
4494 int bonus=GetOrbBonus (buf[2]);
4496 kmatrix_kills_changed = 1;
4498 if (pnum==Player_num)
4499 HUD_init_message("You have scored %d points!",bonus);
4501 HUD_init_message("%s has scored with %d orbs!",Players[(int)pnum].callsign,buf[2]);
4503 if (pnum==Player_num)
4504 digi_start_sound_queued (SOUND_HUD_YOU_GOT_GOAL,F1_0*2);
4505 else if (Game_mode & GM_TEAM)
4507 if (get_team(pnum)==TEAM_RED)
4508 digi_play_sample (SOUND_HUD_RED_GOT_GOAL,F1_0*2);
4510 digi_play_sample (SOUND_HUD_BLUE_GOT_GOAL,F1_0*2);
4513 digi_play_sample (SOUND_OPPONENT_HAS_SCORED,F1_0*2);
4515 if (bonus>PhallicLimit)
4517 if (pnum==Player_num)
4518 HUD_init_message ("You have the record with %d points!",bonus);
4520 HUD_init_message ("%s has the record with %d points!",Players[(int)pnum].callsign,bonus);
4521 digi_play_sample (SOUND_BUDDY_MET_GOAL,F1_0*2);
4526 Players[(int)pnum].flags &= ~(PLAYER_FLAGS_FLAG); // Clear orb flag
4528 team_kills[get_team(pnum)] += bonus;
4529 Players[(int)pnum].net_kills_total += bonus;
4530 Players[(int)pnum].KillGoalCount+=bonus;
4532 team_kills[get_team(pnum)]%=1000;
4533 Players[(int)pnum].net_kills_total%=1000;
4534 Players[(int)pnum].KillGoalCount%=1000;
4536 if (Netgame.KillGoal>0)
4538 TheGoal=Netgame.KillGoal*5;
4540 if (Players[(int)pnum].KillGoalCount>=TheGoal)
4542 if (pnum==Player_num)
4544 HUD_init_message("You reached the kill goal!");
4545 Players[Player_num].shields=i2f(200);
4548 HUD_init_message ("%s has reached the kill goal!",Players[(int)pnum].callsign);
4550 HUD_init_message ("The control center has been destroyed!");
4551 net_destroy_controlcen (obj_find_first_of_type (OBJ_CNTRLCEN));
4554 multi_sort_kill_list();
4555 multi_show_player_list();
4558 void multi_send_got_flag (char pnum)
4560 multibuf[0]=MULTI_GOT_FLAG;
4563 digi_start_sound_queued (SOUND_HUD_YOU_GOT_FLAG,F1_0*2);
4565 multi_send_data (multibuf,2,1);
4566 multi_send_flags (Player_num);
4570 digi_sound ReversedSound;
4572 void multi_send_got_orb (char pnum)
4574 multibuf[0]=MULTI_GOT_ORB;
4577 digi_play_sample (SOUND_YOU_GOT_ORB,F1_0*2);
4579 multi_send_data (multibuf,2,1);
4580 multi_send_flags (Player_num);
4583 void multi_do_got_flag (char *buf)
4587 if (pnum==Player_num)
4588 digi_start_sound_queued (SOUND_HUD_YOU_GOT_FLAG,F1_0*2);
4589 else if (get_team(pnum)==TEAM_RED)
4590 digi_start_sound_queued (SOUND_HUD_RED_GOT_FLAG,F1_0*2);
4592 digi_start_sound_queued (SOUND_HUD_BLUE_GOT_FLAG,F1_0*2);
4593 Players[(int)pnum].flags|=PLAYER_FLAGS_FLAG;
4594 HUD_init_message ("%s picked up a flag!",Players[(int)pnum].callsign);
4596 void multi_do_got_orb (char *buf)
4600 Assert (Game_mode & GM_HOARD);
4602 if (Game_mode & GM_TEAM)
4604 if (get_team(pnum)==get_team(Player_num))
4605 digi_play_sample (SOUND_FRIEND_GOT_ORB,F1_0*2);
4607 digi_play_sample (SOUND_OPPONENT_GOT_ORB,F1_0*2);
4610 digi_play_sample (SOUND_OPPONENT_GOT_ORB,F1_0*2);
4612 Players[(int)pnum].flags|=PLAYER_FLAGS_FLAG;
4613 HUD_init_message ("%s picked up an orb!",Players[(int)pnum].callsign);
4621 if (!(Game_mode & GM_HOARD))
4622 Int3(); // How did we get here? Get Leighton!
4624 if (!Players[Player_num].secondary_ammo[PROXIMITY_INDEX])
4626 HUD_init_message("No orbs to drop!");
4632 objnum = spit_powerup(ConsoleObject,POW_HOARD_ORB,seed);
4637 HUD_init_message("Orb dropped!");
4638 digi_play_sample (SOUND_DROP_WEAPON,F1_0);
4640 if ((Game_mode & GM_HOARD) && objnum>-1)
4641 multi_send_drop_flag(objnum,seed);
4643 Players[Player_num].secondary_ammo[PROXIMITY_INDEX]--;
4645 // If empty, tell everyone to stop drawing the box around me
4646 if (Players[Player_num].secondary_ammo[PROXIMITY_INDEX]==0)
4647 multi_send_flags (Player_num);
4654 if (!(Game_mode & GM_CAPTURE) && !(Game_mode & GM_HOARD))
4656 if (Game_mode & GM_HOARD)
4662 if (!(Players[Player_num].flags & PLAYER_FLAGS_FLAG))
4664 HUD_init_message("No flag to drop!");
4669 HUD_init_message("Flag dropped!");
4670 digi_play_sample (SOUND_DROP_WEAPON,F1_0);
4674 if (get_team (Player_num)==TEAM_RED)
4675 objnum = spit_powerup(ConsoleObject,POW_FLAG_BLUE,seed);
4677 objnum = spit_powerup(ConsoleObject,POW_FLAG_RED,seed);
4682 if ((Game_mode & GM_CAPTURE) && objnum>-1)
4683 multi_send_drop_flag(objnum,seed);
4685 Players[Player_num].flags &=~(PLAYER_FLAGS_FLAG);
4689 void multi_send_drop_flag (int objnum,int seed)
4694 objp = &Objects[objnum];
4696 multibuf[count++]=(char)MULTI_DROP_FLAG;
4697 multibuf[count++]=(char)objp->id;
4699 *(short *) (multibuf+count)=INTEL_SHORT(Player_num); count += 2;
4700 *(short *) (multibuf+count)=INTEL_SHORT(objnum); count += 2;
4701 *(short *) (multibuf+count)=INTEL_SHORT(objp->ctype.powerup_info.count); count += 2;
4702 *(int *) (multibuf+count)=INTEL_INT(seed);
4704 map_objnum_local_to_local(objnum);
4706 if (!(Game_mode & GM_HOARD))
4707 if (Game_mode & GM_NETWORK)
4708 PowerupsInMine[objp->id]++;
4710 multi_send_data(multibuf, 12, 2);
4713 void multi_do_drop_flag (char *buf)
4715 int pnum,ammo,objnum,remote_objnum,seed;
4720 pnum=INTEL_SHORT( *(short *)(buf+2) );
4721 remote_objnum=INTEL_SHORT( *(short *)(buf+4) );
4722 ammo=INTEL_SHORT( *(short *)(buf+6) );
4723 seed=INTEL_INT( *(int *)(buf+8) );
4725 objp = &Objects[Players[pnum].objnum];
4727 objnum = spit_powerup(objp, powerup_id, seed);
4729 map_objnum_local_to_remote(objnum, remote_objnum, pnum);
4732 Objects[objnum].ctype.powerup_info.count = ammo;
4734 if (!(Game_mode & GM_HOARD))
4736 if (Game_mode & GM_NETWORK)
4737 PowerupsInMine[powerup_id]++;
4738 Players[pnum].flags &= ~(PLAYER_FLAGS_FLAG);
4740 mprintf ((0,"Dropped flag %d!\n"));
4744 void multi_bad_restore ()
4746 Function_mode = FMODE_MENU;
4747 nm_messagebox(NULL, 1, TXT_OK,
4748 "A multi-save game was restored\nthat you are missing or does not\nmatch that of the others.\nYou must rejoin if you wish to\ncontinue.");
4749 Function_mode = FMODE_GAME;
4750 multi_quit_game = 1;
4751 multi_leave_menu = 1;
4752 multi_reset_stuff();
4755 extern int robot_controlled[MAX_ROBOTS_CONTROLLED];
4756 extern int robot_agitation[MAX_ROBOTS_CONTROLLED];
4757 extern fix robot_controlled_time[MAX_ROBOTS_CONTROLLED];
4758 extern fix robot_last_send_time[MAX_ROBOTS_CONTROLLED];
4759 extern fix robot_last_message_time[MAX_ROBOTS_CONTROLLED];
4760 extern int robot_send_pending[MAX_ROBOTS_CONTROLLED];
4761 extern int robot_fired[MAX_ROBOTS_CONTROLLED];
4762 extern byte robot_fire_buf[MAX_ROBOTS_CONTROLLED][18+3];
4765 void multi_send_robot_controls (char pnum)
4769 mprintf ((0,"Sending ROBOT_CONTROLS!!!\n"));
4771 multibuf[0]=MULTI_ROBOT_CONTROLS;
4773 memcpy (&(multibuf[count]),&robot_controlled,MAX_ROBOTS_CONTROLLED*4);
4774 count+=(MAX_ROBOTS_CONTROLLED*4);
4775 memcpy (&(multibuf[count]),&robot_agitation,MAX_ROBOTS_CONTROLLED*4);
4776 count+=(MAX_ROBOTS_CONTROLLED*4);
4777 memcpy (&(multibuf[count]),&robot_controlled_time,MAX_ROBOTS_CONTROLLED*4);
4778 count+=(MAX_ROBOTS_CONTROLLED*4);
4779 memcpy (&(multibuf[count]),&robot_last_send_time,MAX_ROBOTS_CONTROLLED*4);
4780 count+=(MAX_ROBOTS_CONTROLLED*4);
4781 memcpy (&(multibuf[count]),&robot_last_message_time,MAX_ROBOTS_CONTROLLED*4);
4782 count+=(MAX_ROBOTS_CONTROLLED*4);
4783 memcpy (&(multibuf[count]),&robot_send_pending,MAX_ROBOTS_CONTROLLED*4);
4784 count+=(MAX_ROBOTS_CONTROLLED*4);
4785 memcpy (&(multibuf[count]),&robot_fired,MAX_ROBOTS_CONTROLLED*4);
4786 count+=(MAX_ROBOTS_CONTROLLED*4);
4788 network_send_naked_packet (multibuf,142,pnum);
4790 void multi_do_robot_controls(char *buf)
4794 mprintf ((0,"Recieved ROBOT_CONTROLS!!!\n"));
4796 if (buf[1]!=Player_num)
4798 Int3(); // Get Jason! Recieved a coop_sync that wasn't ours!
4802 memcpy (&robot_controlled,&(buf[count]),MAX_ROBOTS_CONTROLLED*4);
4803 count+=(MAX_ROBOTS_CONTROLLED*4);
4804 memcpy (&robot_agitation,&(buf[count]),MAX_ROBOTS_CONTROLLED*4);
4805 count+=(MAX_ROBOTS_CONTROLLED*4);
4806 memcpy (&robot_controlled_time,&(buf[count]),MAX_ROBOTS_CONTROLLED*4);
4807 count+=(MAX_ROBOTS_CONTROLLED*4);
4808 memcpy (&robot_last_send_time,&(buf[count]),MAX_ROBOTS_CONTROLLED*4);
4809 count+=(MAX_ROBOTS_CONTROLLED*4);
4810 memcpy (&robot_last_message_time,&(buf[count]),MAX_ROBOTS_CONTROLLED*4);
4811 count+=(MAX_ROBOTS_CONTROLLED*4);
4812 memcpy (&robot_send_pending,&(buf[count]),MAX_ROBOTS_CONTROLLED*4);
4813 count+=(MAX_ROBOTS_CONTROLLED*4);
4814 memcpy (&robot_fired,&(buf[count]),MAX_ROBOTS_CONTROLLED*4);
4815 count+=(MAX_ROBOTS_CONTROLLED*4);
4818 #define POWERUPADJUSTS 5
4819 int PowerupAdjustMapping[]={11,19,39,41,44};
4821 int multi_powerup_is_4pack (int id)
4825 for (i=0;i<POWERUPADJUSTS;i++)
4826 if (id==PowerupAdjustMapping[i])
4831 int multi_powerup_is_allowed(int id)
4833 if (id == POW_INVULNERABILITY && !Netgame.DoInvulnerability)
4835 if (id == POW_CLOAK && !Netgame.DoCloak)
4837 if (id == POW_AFTERBURNER && !Netgame.DoAfterburner)
4839 if (id == POW_FUSION_WEAPON && !Netgame.DoFusions)
4841 if (id == POW_PHOENIX_WEAPON && !Netgame.DoPhoenix)
4843 if (id == POW_HELIX_WEAPON && !Netgame.DoHelix)
4845 if (id == POW_MEGA_WEAPON && !Netgame.DoMegas)
4847 if (id == POW_SMARTBOMB_WEAPON && !Netgame.DoSmarts)
4849 if (id == POW_GAUSS_WEAPON && !Netgame.DoGauss)
4851 if (id == POW_VULCAN_WEAPON && !Netgame.DoVulcan)
4853 if (id == POW_PLASMA_WEAPON && !Netgame.DoPlasma)
4855 if (id == POW_OMEGA_WEAPON && !Netgame.DoOmega)
4857 if (id == POW_SUPER_LASER && !Netgame.DoSuperLaser)
4859 if (id == POW_PROXIMITY_WEAPON && !Netgame.DoProximity)
4861 if (id==POW_VULCAN_AMMO && (!Netgame.DoVulcan && !Netgame.DoGauss))
4863 if (id == POW_SPREADFIRE_WEAPON && !Netgame.DoSpread)
4865 if (id == POW_SMART_MINE && !Netgame.DoSmartMine)
4867 if (id == POW_SMISSILE1_1 && !Netgame.DoFlash)
4869 if (id == POW_SMISSILE1_4 && !Netgame.DoFlash)
4871 if (id == POW_GUIDED_MISSILE_1 && !Netgame.DoGuided)
4873 if (id == POW_GUIDED_MISSILE_4 && !Netgame.DoGuided)
4875 if (id == POW_EARTHSHAKER_MISSILE && !Netgame.DoEarthShaker)
4877 if (id == POW_MERCURY_MISSILE_1 && !Netgame.DoMercury)
4879 if (id == POW_MERCURY_MISSILE_4 && !Netgame.DoMercury)
4881 if (id == POW_CONVERTER && !Netgame.DoConverter)
4883 if (id == POW_AMMO_RACK && !Netgame.DoAmmoRack)
4885 if (id == POW_HEADLIGHT && !Netgame.DoHeadlight)
4887 if (id == POW_LASER && !Netgame.DoLaserUpgrade)
4889 if (id == POW_HOMING_AMMO_1 && !Netgame.DoHoming)
4891 if (id == POW_HOMING_AMMO_4 && !Netgame.DoHoming)
4893 if (id == POW_QUAD_FIRE && !Netgame.DoQuadLasers)
4895 if (id == POW_FLAG_BLUE && !(Game_mode & GM_CAPTURE))
4897 if (id == POW_FLAG_RED && !(Game_mode & GM_CAPTURE))
4903 void multi_send_finish_game ()
4905 multibuf[0]=MULTI_FINISH_GAME;
4906 multibuf[1]=Player_num;
4908 multi_send_data (multibuf,2,1);
4912 extern void do_final_boss_hacks();
4913 void multi_do_finish_game (char *buf)
4915 if (buf[0]!=MULTI_FINISH_GAME)
4918 if (Current_level_num!=Last_level)
4921 do_final_boss_hacks();
4924 void multi_send_trigger_specific (char pnum,char trig)
4926 multibuf[0] = MULTI_START_TRIGGER;
4929 network_send_naked_packet(multibuf, 2, pnum);
4931 void multi_do_start_trigger (char *buf)
4933 Triggers[(int)buf[1]].flags |=TF_DISABLED;
4936 extern char *RankStrings[];
4938 void multi_add_lifetime_kills ()
4940 // This function adds a kill to lifetime stats of this player, and possibly
4941 // gives a promotion. If so, it will tell everyone else
4945 if (!Game_mode & GM_NETWORK)
4948 oldrank=GetMyNetRanking();
4952 if (oldrank!=GetMyNetRanking())
4954 multi_send_ranking();
4955 if (!FindArg("-norankings"))
4957 HUD_init_message ("You have been promoted to %s!",RankStrings[GetMyNetRanking()]);
4958 digi_play_sample (SOUND_BUDDY_MET_GOAL,F1_0*2);
4959 NetPlayers.players[Player_num].rank=GetMyNetRanking();
4962 write_player_file();
4965 void multi_add_lifetime_killed ()
4967 // This function adds a "killed" to lifetime stats of this player, and possibly
4968 // gives a demotion. If so, it will tell everyone else
4972 if (!Game_mode & GM_NETWORK)
4975 oldrank=GetMyNetRanking();
4979 if (oldrank!=GetMyNetRanking())
4981 multi_send_ranking();
4982 NetPlayers.players[Player_num].rank=GetMyNetRanking();
4984 if (!FindArg("-norankings"))
4985 HUD_init_message ("You have been demoted to %s!",RankStrings[GetMyNetRanking()]);
4988 write_player_file();
4992 void multi_send_ranking ()
4994 multibuf[0]=(char)MULTI_RANK;
4995 multibuf[1]=(char)Player_num;
4996 multibuf[2]=(char)GetMyNetRanking();
4998 multi_send_data (multibuf,3,1);
5001 void multi_do_ranking (char *buf)
5007 if (NetPlayers.players[(int)pnum].rank<rank)
5008 strcpy (rankstr,"promoted");
5009 else if (NetPlayers.players[(int)pnum].rank>rank)
5010 strcpy (rankstr,"demoted");
5014 NetPlayers.players[(int)pnum].rank=rank;
5016 if (!FindArg("-norankings"))
5017 HUD_init_message ("%s has been %s to %s!",Players[(int)pnum].callsign,rankstr,RankStrings[(int)rank]);
5019 void multi_send_modem_ping ()
5021 multibuf[0]=MULTI_MODEM_PING;
5022 multi_send_data (multibuf,1,1);
5024 void multi_send_modem_ping_return ()
5026 multibuf[0]=MULTI_MODEM_PING_RETURN;
5027 multi_send_data (multibuf,1,1);
5030 void multi_do_modem_ping_return ()
5032 if (PingLaunchTime==0)
5034 mprintf ((0,"Got invalid PING RETURN from opponent!\n"));
5038 PingReturnTime=timer_get_fixed_seconds();
5040 HUD_init_message ("Ping time for opponent is %d ms!",f2i(fixmul(PingReturnTime-PingLaunchTime,i2f(1000))));
5045 void multi_quick_sound_hack (int num)
5048 num = digi_xlat_sound(num);
5049 length=GameSounds[num].length;
5050 ReversedSound.data=(ubyte *)d_malloc (length);
5051 ReversedSound.length=length;
5053 for (i=0;i<length;i++)
5054 ReversedSound.data[i]=GameSounds[num].data[length-i-1];
5059 void multi_send_play_by_play (int num,int spnum,int dpnum)
5061 if (!(Game_mode & GM_HOARD))
5065 multibuf[0]=MULTI_PLAY_BY_PLAY;
5066 multibuf[1]=(char)num;
5067 multibuf[2]=(char)spnum;
5068 multibuf[3]=(char)dpnum;
5069 multi_send_data (multibuf,4,1);
5070 multi_do_play_by_play (multibuf);
5073 void multi_do_play_by_play (char *buf)
5075 int whichplay=buf[1];
5079 if (!(Game_mode & GM_HOARD))
5081 Int3(); // Get Leighton, something bad has happened.
5088 HUD_init_message ("Ouch! %s has been smacked by %s!",Players[dpnum].callsign,Players[spnum].callsign);
5091 HUD_init_message ("Haha! %s has been spanked by %s!",Players[dpnum].callsign,Players[spnum].callsign);
5099 /// CODE TO LOAD HOARD DATA
5103 void init_bitmap(grs_bitmap *bm,int w,int h,int flags,ubyte *data)
5105 bm->bm_x = bm->bm_y = 0;
5106 bm->bm_w = bm->bm_rowsize = w;
5108 bm->bm_type = BM_LINEAR;
5109 bm->bm_flags = flags;
5115 grs_bitmap Orb_icons[2];
5117 int Hoard_goal_eclip;
5119 void init_hoard_data()
5121 static int first_time=1;
5122 static int orb_vclip;
5123 int n_orb_frames,n_goal_frames;
5126 ubyte palette[256*3];
5129 extern int Num_bitmap_files,Num_effects,Num_sound_files;
5131 ifile = cfopen("hoard.ham","rb");
5133 Error("can't open <hoard.ham>");
5135 n_orb_frames = cfile_read_short(ifile);
5136 orb_w = cfile_read_short(ifile);
5137 orb_h = cfile_read_short(ifile);
5138 save_pos = cftell(ifile);
5139 cfseek(ifile,sizeof(palette)+n_orb_frames*orb_w*orb_h,SEEK_CUR);
5140 n_goal_frames = cfile_read_short(ifile);
5141 cfseek(ifile,save_pos,SEEK_SET);
5145 int bitmap_num=Num_bitmap_files;
5147 //Allocate memory for bitmaps
5148 MALLOC( bitmap_data, ubyte, n_orb_frames*orb_w*orb_h + n_goal_frames*64*64 );
5151 orb_vclip = Num_vclips++;
5152 Assert(Num_vclips <= VCLIP_MAXNUM);
5153 Vclip[orb_vclip].play_time = F1_0/2;
5154 Vclip[orb_vclip].num_frames = n_orb_frames;
5155 Vclip[orb_vclip].frame_time = Vclip[orb_vclip].play_time / Vclip[orb_vclip].num_frames;
5156 Vclip[orb_vclip].flags = 0;
5157 Vclip[orb_vclip].sound_num = -1;
5158 Vclip[orb_vclip].light_value = F1_0;
5159 for (i=0;i<n_orb_frames;i++) {
5160 Vclip[orb_vclip].frames[i].index = bitmap_num;
5161 init_bitmap(&GameBitmaps[bitmap_num],orb_w,orb_h,BM_FLAG_TRANSPARENT,bitmap_data);
5162 bitmap_data += orb_w*orb_h;
5164 Assert(bitmap_num < MAX_BITMAP_FILES);
5167 //Create obj powerup
5168 Powerup_info[POW_HOARD_ORB].vclip_num = orb_vclip;
5169 Powerup_info[POW_HOARD_ORB].hit_sound = -1; //Powerup_info[POW_SHIELD_BOOST].hit_sound;
5170 Powerup_info[POW_HOARD_ORB].size = Powerup_info[POW_SHIELD_BOOST].size;
5171 Powerup_info[POW_HOARD_ORB].light = Powerup_info[POW_SHIELD_BOOST].light;
5173 //Create orb goal wall effect
5174 Hoard_goal_eclip = Num_effects++;
5175 Assert(Num_effects < MAX_EFFECTS);
5176 Effects[Hoard_goal_eclip] = Effects[94]; //copy from blue goal
5177 Effects[Hoard_goal_eclip].changing_wall_texture = NumTextures;
5178 Effects[Hoard_goal_eclip].vc.num_frames=n_goal_frames;
5180 TmapInfo[NumTextures] = TmapInfo[find_goal_texture(TMI_GOAL_BLUE)];
5181 TmapInfo[NumTextures].eclip_num = Hoard_goal_eclip;
5182 TmapInfo[NumTextures].flags = TMI_GOAL_HOARD;
5184 Assert(NumTextures < MAX_TEXTURES);
5185 for (i=0;i<n_goal_frames;i++) {
5186 Effects[Hoard_goal_eclip].vc.frames[i].index = bitmap_num;
5187 init_bitmap(&GameBitmaps[bitmap_num],64,64,0,bitmap_data);
5188 bitmap_data += 64*64;
5190 Assert(bitmap_num < MAX_BITMAP_FILES);
5195 //Load and remap bitmap data for orb
5196 cfread(palette,3,256,ifile);
5197 for (i=0;i<n_orb_frames;i++) {
5198 grs_bitmap *bm = &GameBitmaps[Vclip[orb_vclip].frames[i].index];
5199 cfread(bm->bm_data,1,orb_w*orb_h,ifile);
5200 gr_remap_bitmap_good( bm, palette, 255, -1 );
5203 //Load and remap bitmap data for goal texture
5204 cfile_read_short(ifile); //skip frame count
5205 cfread(palette,3,256,ifile);
5206 for (i=0;i<n_goal_frames;i++) {
5207 grs_bitmap *bm = &GameBitmaps[Effects[Hoard_goal_eclip].vc.frames[i].index];
5208 cfread(bm->bm_data,1,64*64,ifile);
5209 gr_remap_bitmap_good( bm, palette, 255, -1 );
5212 //Load and remap bitmap data for HUD icons
5214 icon_w = cfile_read_short(ifile);
5215 icon_h = cfile_read_short(ifile);
5218 MALLOC( bitmap_data, ubyte, icon_w*icon_h );
5219 init_bitmap(&Orb_icons[i],icon_w,icon_h,BM_FLAG_TRANSPARENT,bitmap_data);
5221 cfread(palette,3,256,ifile);
5222 cfread(Orb_icons[i].bm_data,1,icon_w*icon_h,ifile);
5223 gr_remap_bitmap_good( &Orb_icons[i], palette, 255, -1 );
5228 //Load sounds for orb game
5233 len = cfile_read_int(ifile); //get 11k len
5235 if (digi_sample_rate == SAMPLE_RATE_22K) {
5236 cfseek(ifile,len,SEEK_CUR); //skip over 11k sample
5237 len = cfile_read_int(ifile); //get 22k len
5240 GameSounds[Num_sound_files+i].length = len;
5241 GameSounds[Num_sound_files+i].data = d_malloc(len);
5242 cfread(GameSounds[Num_sound_files+i].data,1,len,ifile);
5244 if (digi_sample_rate == SAMPLE_RATE_11K) {
5245 len = cfile_read_int(ifile); //get 22k len
5246 cfseek(ifile,len,SEEK_CUR); //skip over 22k sample
5249 Sounds[SOUND_YOU_GOT_ORB+i] = Num_sound_files+i;
5250 AltSounds[SOUND_YOU_GOT_ORB+i] = Sounds[SOUND_YOU_GOT_ORB+i];
5260 multi_process_data(char *buf, int len)
5262 // Take an entire message (that has already been checked for validity,
5263 // if necessary) and act on it.
5270 if (type > MULTI_MAX_TYPE)
5272 mprintf((1, "multi_process_data: invalid type %d.\n", type));
5280 fprintf (RecieveLogFile,"Packet type: %d Len:%d TT=%d\n",type,len,TTRecv[type]);
5281 fflush (RecieveLogFile);
5286 case MULTI_POSITION:
5287 if (!Endlevel_sequence) multi_do_position(buf); break;
5288 case MULTI_REAPPEAR:
5289 if (!Endlevel_sequence) multi_do_reappear(buf); break;
5291 if (!Endlevel_sequence) multi_do_fire(buf); break;
5293 multi_do_kill(buf); break;
5294 case MULTI_REMOVE_OBJECT:
5295 if (!Endlevel_sequence) multi_do_remobj(buf); break;
5296 case MULTI_PLAYER_DROP:
5297 case MULTI_PLAYER_EXPLODE:
5298 if (!Endlevel_sequence) multi_do_player_explode(buf); break;
5300 if (!Endlevel_sequence) multi_do_message(buf); break;
5302 if (!Endlevel_sequence) multi_do_quit(buf); break;
5303 case MULTI_BEGIN_SYNC:
5305 case MULTI_CONTROLCEN:
5306 if (!Endlevel_sequence) multi_do_controlcen_destroy(buf); break;
5307 case MULTI_POWERUP_UPDATE:
5308 if (!Endlevel_sequence) multi_do_powerup_update(buf); break;
5309 case MULTI_SOUND_FUNCTION:
5310 multi_do_sound_function(buf); break;
5312 if (!Endlevel_sequence) multi_do_drop_marker (buf); break;
5313 case MULTI_DROP_WEAPON:
5314 if (!Endlevel_sequence) multi_do_drop_weapon(buf); break;
5315 case MULTI_DROP_FLAG:
5316 if (!Endlevel_sequence) multi_do_drop_flag(buf); break;
5318 if (!Endlevel_sequence) multi_do_guided (buf); break;
5319 case MULTI_STOLEN_ITEMS:
5320 if (!Endlevel_sequence) multi_do_stolen_items(buf); break;
5321 case MULTI_WALL_STATUS:
5322 if (!Endlevel_sequence) multi_do_wall_status(buf); break;
5323 case MULTI_HEARTBEAT:
5324 if (!Endlevel_sequence) multi_do_heartbeat (buf); break;
5326 if (!Endlevel_sequence) multi_do_seismic (buf); break;
5328 if (!Endlevel_sequence) multi_do_light (buf); break;
5329 case MULTI_KILLGOALS:
5331 if (!Endlevel_sequence) multi_do_kill_goal_counts (buf); break;
5332 case MULTI_ENDLEVEL_START:
5333 if (!Endlevel_sequence) multi_do_escape(buf); break;
5334 case MULTI_END_SYNC:
5337 if (!Endlevel_sequence) multi_do_cloak(buf); break;
5339 if (!Endlevel_sequence) multi_do_decloak(buf); break;
5340 case MULTI_DOOR_OPEN:
5341 if (!Endlevel_sequence) multi_do_door_open(buf); break;
5342 case MULTI_CREATE_EXPLOSION:
5343 if (!Endlevel_sequence) multi_do_create_explosion(buf); break;
5344 case MULTI_CONTROLCEN_FIRE:
5345 if (!Endlevel_sequence) multi_do_controlcen_fire(buf); break;
5346 case MULTI_CREATE_POWERUP:
5347 if (!Endlevel_sequence) multi_do_create_powerup(buf); break;
5348 case MULTI_PLAY_SOUND:
5349 if (!Endlevel_sequence) multi_do_play_sound(buf); break;
5350 case MULTI_CAPTURE_BONUS:
5351 if (!Endlevel_sequence) multi_do_capture_bonus(buf); break;
5352 case MULTI_ORB_BONUS:
5353 if (!Endlevel_sequence) multi_do_orb_bonus(buf); break;
5354 case MULTI_GOT_FLAG:
5355 if (!Endlevel_sequence) multi_do_got_flag(buf); break;
5357 if (!Endlevel_sequence) multi_do_got_orb(buf); break;
5358 case MULTI_PLAY_BY_PLAY:
5359 if (!Endlevel_sequence) multi_do_play_by_play(buf); break;
5361 if (!Endlevel_sequence) multi_do_ranking (buf); break;
5362 case MULTI_MODEM_PING:
5363 if (!Endlevel_sequence) multi_send_modem_ping_return(); break;
5364 case MULTI_MODEM_PING_RETURN:
5365 if (!Endlevel_sequence) multi_do_modem_ping_return(); break;
5367 case MULTI_FINISH_GAME:
5368 multi_do_finish_game(buf); break; // do this one regardless of endsequence
5369 case MULTI_ROBOT_CONTROLS:
5370 if (!Endlevel_sequence) multi_do_robot_controls(buf); break;
5371 case MULTI_ROBOT_CLAIM:
5372 if (!Endlevel_sequence) multi_do_claim_robot(buf); break;
5373 case MULTI_ROBOT_POSITION:
5374 if (!Endlevel_sequence) multi_do_robot_position(buf); break;
5375 case MULTI_ROBOT_EXPLODE:
5376 if (!Endlevel_sequence) multi_do_robot_explode(buf); break;
5377 case MULTI_ROBOT_RELEASE:
5378 if (!Endlevel_sequence) multi_do_release_robot(buf); break;
5379 case MULTI_ROBOT_FIRE:
5380 if (!Endlevel_sequence) multi_do_robot_fire(buf); break;
5383 if (!Endlevel_sequence) multi_do_score(buf); break;
5384 case MULTI_CREATE_ROBOT:
5385 if (!Endlevel_sequence) multi_do_create_robot(buf); break;
5387 if (!Endlevel_sequence) multi_do_trigger(buf); break;
5388 case MULTI_START_TRIGGER:
5389 if (!Endlevel_sequence) multi_do_start_trigger(buf); break;
5391 if (!Endlevel_sequence) multi_do_flags(buf); break;
5392 case MULTI_DROP_BLOB:
5393 if (!Endlevel_sequence) multi_do_drop_blob(buf); break;
5394 case MULTI_ACTIVE_DOOR:
5395 if (!Endlevel_sequence) multi_do_active_door(buf); break;
5396 case MULTI_BOSS_ACTIONS:
5397 if (!Endlevel_sequence) multi_do_boss_actions(buf); break;
5398 case MULTI_CREATE_ROBOT_POWERUPS:
5399 if (!Endlevel_sequence) multi_do_create_robot_powerups(buf); break;
5400 case MULTI_HOSTAGE_DOOR:
5401 if (!Endlevel_sequence) multi_do_hostage_door_status(buf); break;
5402 case MULTI_SAVE_GAME:
5403 if (!Endlevel_sequence) multi_do_save_game(buf); break;
5404 case MULTI_RESTORE_GAME:
5405 if (!Endlevel_sequence) multi_do_restore_game(buf); break;
5406 case MULTI_REQ_PLAYER:
5407 if (!Endlevel_sequence) multi_do_req_player(buf); break;
5408 case MULTI_SEND_PLAYER:
5409 if (!Endlevel_sequence) multi_do_send_player(buf); break;
5412 mprintf((1, "Invalid type in multi_process_input().\n"));