This commit was manufactured by cvs2svn to create branch
[btb/d2x.git] / main / multi.c
1 /* $Id: multi.c,v 1.9 2003-03-14 21:24:03 btb Exp $ */
2 /*
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.
13 */
14
15 /*
16  *
17  * Multiplayer code shared by serial and network play.
18  *
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include <conf.h>
23 #endif
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <time.h>
29 #include <ctype.h>
30
31 #include "u_mem.h"
32 #include "strutil.h"
33 #include "game.h"
34 #include "modem.h"
35 #include "network.h"
36 #include "multi.h"
37 #include "object.h"
38 #include "laser.h"
39 #include "fuelcen.h"
40 #include "scores.h"
41 #include "gauges.h"
42 #include "collide.h"
43 #include "error.h"
44 #include "fireball.h"
45 #include "newmenu.h"
46 #include "mono.h"
47 #include "wall.h"
48 #include "cntrlcen.h"
49 #include "powerup.h"
50 #include "polyobj.h"
51 #include "bm.h"
52 #include "endlevel.h"
53 #include "key.h"
54 #include "playsave.h"
55 #include "timer.h"
56 #include "digi.h"
57 #include "sounds.h"
58 #include "kconfig.h"
59 #include "newdemo.h"
60 #include "text.h"
61 #include "kmatrix.h"
62 #include "multibot.h"
63 #include "gameseq.h"
64 #include "physics.h"
65 #include "config.h"
66 #include "state.h"
67 #include "ai.h"
68 #include "switch.h"
69 #include "textures.h"
70 #include "byteswap.h"
71 #include "sounds.h"
72 #include "args.h"
73 #include "cfile.h"
74 #include "effects.h"
75
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);
99
100 //
101 // Local macros and prototypes
102 //
103
104 // LOCALIZE ME!!
105
106 #define vm_angvec_zero(v) (v)->p=(v)->b=(v)->h=0
107
108 void drop_player_eggs(object *player); // from collide.c
109 void GameLoop(int, int); // From game.c
110
111 //
112 // Global variables
113 //
114
115 extern vms_vector MarkerPoint[];
116 extern char MarkerMessage[16][40];
117 extern char MarkerOwner[16][40];
118 extern int MarkerObject[];
119
120 int control_invul_time = 0;
121 int who_killed_controlcen = -1;  // -1 = noone
122
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;
127
128 char Multi_is_guided=0;
129 char PKilledFlags[MAX_NUM_NET_PLAYERS];
130
131 int multi_sending_message = 0;
132 int multi_defining_message = 0;
133 int multi_message_index = 0;
134
135 char multibuf[MAX_MULTI_MESSAGE_LEN+4];            // This is where multiplayer message are built
136
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
140
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;
154 short team_kills[2];
155 int   multi_in_menu = 0;
156 int   multi_leave_menu = 0;
157 int   multi_quit_game = 0;
158
159 netgame_info Netgame;
160 AllNetPlayers_info NetPlayers;
161
162 bitmap_index multi_player_textures[MAX_NUM_NET_PLAYERS][N_PLAYER_SHIP_TEXTURES];
163
164 typedef struct netplayer_stats {
165         ubyte  message_type;
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.
181         short  KillGoalCount;
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.
191         ubyte  unused[16];
192 } netplayer_stats;
193
194 int message_length[MULTI_MAX_TYPE+1] = {
195         24, // POSITION
196         3,  // REAPPEAR
197         8,  // FIRE
198         5,  // KILL
199         4,  // REMOVE_OBJECT
200         97+9, // PLAYER_EXPLODE
201         37, // MESSAGE (MAX_MESSAGE_LENGTH = 40)
202         2,  // QUIT
203         4,  // PLAY_SOUND
204         41, // BEGIN_SYNC
205         4,  // CONTROLCEN
206         5,  // CLAIM ROBOT
207         4,  // END_SYNC
208         2,  // CLOAK
209         3,  // ENDLEVEL_START
210         5,  // DOOR_OPEN
211         2,  // CREATE_EXPLOSION
212         16, // CONTROLCEN_FIRE
213         97+9, // PLAYER_DROP
214         19, // CREATE_POWERUP
215         9,  // MISSILE_TRACK
216         2,  // DE-CLOAK
217         2,  // MENU_CHOICE
218         28, // ROBOT_POSITION  (shortpos_length (23) + 5 = 28)
219         9,  // ROBOT_EXPLODE
220         5,  // ROBOT_RELEASE
221         18, // ROBOT_FIRE
222         6,  // SCORE
223         6,  // CREATE_ROBOT
224         3,  // TRIGGER
225         10, // BOSS_ACTIONS
226         27, // ROBOT_POWERUPS
227         7,  // HOSTAGE_DOOR
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
232         55, // MULTI_MARKER
233         12, // MULTI_DROP_WEAPON
234 #ifndef MACINTOSH
235         3+sizeof(shortpos), // MULTI_GUIDED, IF SHORTPOS CHANGES, CHANGE MAC VALUE BELOW
236 #else
237         26, // MULTI_GUIDED IF SIZE OF SHORTPOS CHANGES, CHANGE THIS VALUE AS WELL!!!!!!
238 #endif
239         11, // MULTI_STOLEN_ITEMS
240         6,  // MULTI_WALL_STATUS
241         5,  // MULTI_HEARTBEAT
242         9,  // MULTI_KILLGOALS
243         9,  // MULTI_SEISMIC
244         18, // MULTI_LIGHT
245         2,  // MULTI_START_TRIGGER
246         6,  // MULTI_FLAGS
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
252         2,  // MULTI_GOT_FLAG
253         12, // MULTI_DROP_FLAG
254         142, // MULTI_ROBOT_CONTROLS
255         2,  // MULTI_FINISH_GAME
256         3,  // MULTI_RANK
257         1,  // MULTI_MODEM_PING
258         1,  // MULTI_MODEM_PING_RETURN
259         3,  // MULTI_ORB_BONUS
260         2,  // MULTI_GOT_ORB
261         12, // MULTI_DROP_ORB
262         4,  // MULTI_PLAY_BY_PLAY
263 };
264
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;
269
270 //
271 //  Functions that replace what used to be macros
272 //
273
274 int objnum_remote_to_local(int remote_objnum, int owner)
275 {
276         // Map a remote object number from owner to a local object number
277
278         int result;
279
280         if ((owner >= N_players) || (owner < -1)) {
281                 Int3(); // Illegal!
282                 return(remote_objnum);
283         }
284
285         if (owner == -1)
286                 return(remote_objnum);
287
288         if ((remote_objnum < 0) || (remote_objnum >= MAX_OBJECTS))
289                 return(-1);
290
291         result = remote_to_local[owner][remote_objnum];
292
293         if (result < 0)
294         {
295                 mprintf((1, "Remote object owner %d number %d mapped to -1!\n", owner, remote_objnum));
296                 return(-1);
297         }
298
299 #ifndef NDEBUG
300         if (object_owner[result] != owner)
301         {
302                 mprintf((1, "Remote object owner %d number %d doesn't match owner %d.\n", owner, remote_objnum, object_owner[result]));
303         }
304 #endif
305         //Assert(object_owner[result] == owner);
306
307         return(result);
308 }
309
310 int objnum_local_to_remote(int local_objnum, byte *owner)
311 {
312         // Map a local object number to a remote + owner
313
314         int result;
315
316         if ((local_objnum < 0) || (local_objnum > Highest_object_index)) {
317                 *owner = -1;
318                 return(-1);
319         }
320
321         *owner = object_owner[local_objnum];
322
323         if (*owner == -1)
324                 return(local_objnum);
325
326         if ((*owner >= N_players) || (*owner < -1)) {
327                 Int3(); // Illegal!
328                 *owner = -1;
329                 return local_objnum;
330         }
331
332         result = local_to_remote[local_objnum];
333
334         //mprintf((0, "Local object %d mapped to owner %d objnum %d.\n", local_objnum,
335         //      *owner, result));
336
337         if (result < 0)
338         {
339                 Int3(); // See Rob, object has no remote number!
340         }
341
342         return(result);
343 }
344
345 void
346 map_objnum_local_to_remote(int local_objnum, int remote_objnum, int owner)
347 {
348         // Add a mapping from a network remote object number to a local one
349
350         Assert(local_objnum > -1);
351         Assert(remote_objnum > -1);
352         Assert(owner > -1);
353         Assert(owner != Player_num);
354         Assert(local_objnum < MAX_OBJECTS);
355         Assert(remote_objnum < MAX_OBJECTS);
356
357         object_owner[local_objnum] = owner;
358
359         remote_to_local[owner][remote_objnum] = local_objnum;
360         local_to_remote[local_objnum] = remote_objnum;
361
362         return;
363 }
364
365 void
366 map_objnum_local_to_local(int local_objnum)
367 {
368         // Add a mapping for our locally created objects
369
370         Assert(local_objnum > -1);
371         Assert(local_objnum < MAX_OBJECTS);
372
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;
376
377         return;
378 }
379
380 //
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.
384 //
385
386 void
387 multi_endlevel_score(void)
388 {
389         int old_connect=0;
390         int i;
391
392         // Show a score list to end of net players
393
394         // Save connect state and change to new connect state
395 #ifdef NETWORK
396         if (Game_mode & GM_NETWORK)
397         {
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;
402
403         }
404 #endif
405
406         // Do the actual screen we wish to show
407
408         Function_mode = FMODE_MENU;
409
410         kmatrix_view(Game_mode & GM_NETWORK);
411
412         Function_mode = FMODE_GAME;
413
414         // Restore connect state
415
416         if (Game_mode & GM_NETWORK)
417         {
418                 Players[Player_num].connected = old_connect;
419         }
420
421 #ifndef SHAREWARE
422         if (Game_mode & GM_MULTI_COOP)
423         {
424                 int i;
425                 for (i = 0; i < MaxNumNetPlayers; i++)
426                         // Reset keys
427                         Players[i].flags &= ~(PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY);
428         }
429         for (i = 0; i < MaxNumNetPlayers; i++)
430                 Players[i].flags &= ~(PLAYER_FLAGS_FLAG);  // Clear capture flag
431
432 #endif
433
434         for (i=0;i<MAX_PLAYERS;i++)
435                 Players[i].KillGoalCount=0;
436
437         for (i=0;i<MAX_POWERUP_TYPES;i++)
438         {
439                 MaxPowerupsAllowed[i]=0;
440                 PowerupsInMine[i]=0;
441         }
442
443 }
444
445 int
446 get_team(int pnum)
447 {
448         if ((Game_mode & GM_CAPTURE) && ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM)))
449                 return pnum;
450
451         if (Netgame.team_vector & (1 << pnum))
452                 return 1;
453         else
454                 return 0;
455 }
456
457 int
458 multi_choose_mission(int *anarchy_only)
459 {
460         int i, n_missions;
461         int default_mission;
462         char *m[MAX_MISSIONS];
463         int new_mission_num = 0;
464
465         *anarchy_only = 0;
466
467         n_missions = build_mission_list(1);
468
469         if (n_missions > 1) {
470
471                 default_mission = 0;
472                 for (i=0;i<n_missions;i++) {
473                         m[i] = Mission_list[i].mission_name;
474                         if ( !stricmp( m[i], config_last_mission ) )
475                                 default_mission = i;
476                 }
477
478       ExtGameStatus=GAMESTAT_START_MULTIPLAYER_MISSION;
479                 new_mission_num = newmenu_listbox1(TXT_MULTI_MISSION, n_missions, m, 1, default_mission, NULL );
480
481                 if (new_mission_num == -1)
482                         return -1;      //abort!
483
484                 strcpy(config_last_mission, m[new_mission_num]  );
485
486                 if (!load_mission(new_mission_num)) {
487                         nm_messagebox( NULL, 1, TXT_OK, TXT_MISSION_ERROR);
488                         return -1;
489                 }
490
491                 *anarchy_only = Mission_list[new_mission_num].anarchy_only_flag;
492         }
493         return(new_mission_num);
494 }
495
496 extern void game_disable_cheats();
497
498 void
499 multi_new_game(void)
500 {
501         int i;
502
503         // Reset variables for a new net game
504
505         memset(kill_matrix, 0, MAX_NUM_NET_PLAYERS*MAX_NUM_NET_PLAYERS*2); // Clear kill matrix
506
507         for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
508         {
509                 sorted_kills[i] = 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;
514         }
515
516 #ifndef SHAREWARE
517         for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
518         {
519                 robot_controlled[i] = -1;
520                 robot_agitation[i] = 0;
521                 robot_fired[i] = 0;
522         }
523 #endif
524
525         team_kills[0] = team_kills[1] = 0;
526         Endlevel_sequence = 0;
527         Player_is_dead = 0;
528         multi_leave_menu = 0;
529         multi_quit_game = 0;
530         Show_kill_list = 1;
531         game_disable_cheats();
532         Player_exploded = 0;
533         Dead_player_camera = 0;
534 }
535
536 void
537 multi_make_player_ghost(int playernum)
538 {
539         object *obj;
540
541         //Assert(playernum != Player_num);
542         //Assert(playernum < MAX_NUM_NET_PLAYERS);
543
544         if ((playernum == Player_num) || (playernum >= MAX_NUM_NET_PLAYERS) || (playernum < 0))
545         {
546                 Int3(); // Non-terminal, see Rob
547                 return;
548         }
549
550 //      if (Objects[Players[playernum].objnum].type != OBJ_PLAYER)
551 //              mprintf((1, "Warning: Player %d is not currently a player.\n", playernum));
552
553         obj = &Objects[Players[playernum].objnum];
554
555         obj->type = OBJ_GHOST;
556         obj->render_type = RT_NONE;
557         obj->movement_type = MT_NONE;
558         multi_reset_player_object(obj);
559
560         if (Game_mode & GM_MULTI_ROBOTS)
561                 multi_strip_robots(playernum);
562 }
563
564 void
565 multi_make_ghost_player(int playernum)
566 {
567         object *obj;
568
569 // Assert(playernum != Player_num);
570 // Assert(playernum < MAX_NUM_NET_PLAYERS);
571
572         if ((playernum == Player_num) || (playernum >= MAX_NUM_NET_PLAYERS))
573         {
574                 Int3(); // Non-terminal, see rob
575                 return;
576         }
577
578 //      if(Objects[Players[playernum].objnum].type != OBJ_GHOST)
579 //              mprintf((1, "Warning: Player %d is not currently a ghost.\n", playernum));
580
581         obj = &Objects[Players[playernum].objnum];
582
583         obj->type = OBJ_PLAYER;
584         obj->movement_type = MT_PHYSICS;
585         multi_reset_player_object(obj);
586 }
587
588 int multi_get_kill_list(int *plist)
589 {
590         // Returns the number of active net players and their
591         // sorted order of kills
592         int i;
593         int n = 0;
594
595         for (i = 0; i < N_players; i++)
596                 //if (Players[sorted_kills[i]].connected)
597                 plist[n++] = sorted_kills[i];
598
599         if (n == 0)
600                 Int3(); // SEE ROB OR MATT
601
602         //memcpy(plist, sorted_kills, N_players*sizeof(int));
603
604         return(n);
605 }
606
607 void
608 multi_sort_kill_list(void)
609 {
610         // Sort the kills list each time a new kill is added
611
612         int kills[MAX_NUM_NET_PLAYERS];
613         int i;
614         int changed = 1;
615
616         for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
617         {
618 #ifndef SHAREWARE
619                 if (Game_mode & GM_MULTI_COOP)
620                         kills[i] = Players[i].score;
621                 else
622 #endif
623                 if (Show_kill_list==2)
624                 {
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
627                         else
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);
629                 }
630                 else
631                         kills[i] = Players[i].net_kills_total;
632         }
633
634         while (changed)
635         {
636                 changed = 0;
637                 for (i = 0; i < N_players-1; i++)
638                 {
639                         if (kills[sorted_kills[i]] < kills[sorted_kills[i+1]])
640                         {
641                                 changed = sorted_kills[i];
642                                 sorted_kills[i] = sorted_kills[i+1];
643                                 sorted_kills[i+1] = changed;
644                                 changed = 1;
645                         }
646                 }
647         }
648         mprintf((0, "Sorted kills %d %d.\n", sorted_kills[0], sorted_kills[1]));
649 }
650
651 extern object *obj_find_first_of_type (int);
652 char Multi_killed_yourself=0;
653
654 void multi_compute_kill(int killer, int killed)
655 {
656         // Figure out the results of a network kills and add it to the
657         // appropriate player's tally.
658
659         int killed_pnum, killed_type;
660         int killer_pnum, killer_type,killer_id;
661         int TheGoal;
662         char killed_name[(CALLSIGN_LEN*2)+4];
663         char killer_name[(CALLSIGN_LEN*2)+4];
664
665         kmatrix_kills_changed = 1;
666         Multi_killed_yourself=0;
667
668         // Both object numbers are localized already!
669
670         mprintf((0, "compute_kill passed: object %d killed object %d.\n", killer, killed));
671
672         if ((killed < 0) || (killed > Highest_object_index) || (killer < 0) || (killer > Highest_object_index))
673         {
674                 Int3(); // See Rob, illegal value passed to compute_kill;
675                 return;
676         }
677
678         killed_type = Objects[killed].type;
679         killer_type = Objects[killer].type;
680         killer_id = Objects[killer].id;
681
682         if ((killed_type != OBJ_PLAYER) && (killed_type != OBJ_GHOST))
683         {
684                 Int3(); // compute_kill passed non-player object!
685                 return;
686         }
687
688         killed_pnum = Objects[killed].id;
689
690         PKilledFlags[killed_pnum]=1;
691
692         Assert ((killed_pnum >= 0) && (killed_pnum < N_players));
693
694         if (Game_mode & GM_TEAM)
695                 sprintf(killed_name, "%s (%s)", Players[killed_pnum].callsign, Netgame.team_name[get_team(killed_pnum)]);
696         else
697                 sprintf(killed_name, "%s", Players[killed_pnum].callsign);
698
699         if (Newdemo_state == ND_STATE_RECORDING)
700                 newdemo_record_multi_death(killed_pnum);
701
702         digi_play_sample( SOUND_HUD_KILL, F3_0 );
703
704         if (Control_center_destroyed)
705                 Players[killed_pnum].connected=3;
706
707         if (killer_type == OBJ_CNTRLCEN)
708         {
709                 Players[killed_pnum].net_killed_total++;
710                 Players[killed_pnum].net_kills_total--;
711
712                 if (Newdemo_state == ND_STATE_RECORDING)
713                         newdemo_record_multi_kill(killed_pnum, -1);
714
715                 if (killed_pnum == Player_num)
716                 {
717                         HUD_init_message("%s %s.", TXT_YOU_WERE, TXT_KILLED_BY_NONPLAY);
718                         multi_add_lifetime_killed ();
719                 }
720                 else
721                         HUD_init_message("%s %s %s.", killed_name, TXT_WAS, TXT_KILLED_BY_NONPLAY );
722                 return;
723         }
724
725 #ifndef SHAREWARE
726         else if ((killer_type != OBJ_PLAYER) && (killer_type != OBJ_GHOST))
727         {
728                 if (killer_id==PMINE_ID && killer_type!=OBJ_ROBOT)
729                 {
730                         if (killed_pnum == Player_num)
731                                 HUD_init_message("You were killed by a mine!");
732                         else
733                                 HUD_init_message("%s was killed by a mine!",killed_name);
734                 }
735                 else
736                 {
737                         if (killed_pnum == Player_num)
738                         {
739                                 HUD_init_message("%s %s.", TXT_YOU_WERE, TXT_KILLED_BY_ROBOT);
740                                 multi_add_lifetime_killed();
741                         }
742                         else
743                                 HUD_init_message("%s %s %s.", killed_name, TXT_WAS, TXT_KILLED_BY_ROBOT );
744                 }
745                 Players[killed_pnum].net_killed_total++;
746                 return;
747         }
748 #else
749         else if ((killer_type != OBJ_PLAYER) && (killer_type != OBJ_GHOST) && (killer_id!=PMINE_ID))
750         {
751                 Int3(); // Illegal killer type?
752                 return;
753         }
754         if (killer_id==PMINE_ID)
755         {
756                 if (killed_pnum==Player_num)
757                         HUD_init_message("You were killed by a mine!");
758                 else
759                         HUD_init_message("%s was killed by a mine!",killed_name);
760
761                 Players[killed_pnum].net_killed_total++;
762
763                 return;
764         }
765 #endif
766
767         killer_pnum = Objects[killer].id;
768
769         if (Game_mode & GM_TEAM)
770                 sprintf(killer_name, "%s (%s)", Players[killer_pnum].callsign, Netgame.team_name[get_team(killer_pnum)]);
771         else
772                 sprintf(killer_name, "%s", Players[killer_pnum].callsign);
773
774         // Beyond this point, it was definitely a player-player kill situation
775
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
780
781         if (killer_pnum == killed_pnum)
782         {
783                 if (!(Game_mode & GM_HOARD))
784                 {
785                         if (Game_mode & GM_TEAM)
786                                 team_kills[get_team(killed_pnum)] -= 1;
787
788                         Players[killed_pnum].net_killed_total += 1;
789                         Players[killed_pnum].net_kills_total -= 1;
790
791                         if (Newdemo_state == ND_STATE_RECORDING)
792                                 newdemo_record_multi_kill(killed_pnum, -1);
793                 }
794                 kill_matrix[killed_pnum][killed_pnum] += 1; // # of suicides
795
796                 if (killer_pnum == Player_num)
797                 {
798                         HUD_init_message("%s %s %s!", TXT_YOU, TXT_KILLED, TXT_YOURSELF );
799                         Multi_killed_yourself=1;
800                         multi_add_lifetime_killed();
801                 }
802                 else
803                         HUD_init_message("%s %s", killed_name, TXT_SUICIDE);
804         }
805
806         else
807         {
808                 if (!(Game_mode & GM_HOARD))
809                 {
810                         if (Game_mode & GM_TEAM)
811                         {
812                                 if (get_team(killed_pnum) == get_team(killer_pnum))
813                                         team_kills[get_team(killed_pnum)] -= 1;
814                                 else
815                                         team_kills[get_team(killer_pnum)] += 1;
816                         }
817
818                         Players[killer_pnum].net_kills_total += 1;
819                         Players[killer_pnum].KillGoalCount+=1;
820
821                         if (Newdemo_state == ND_STATE_RECORDING)
822                                 newdemo_record_multi_kill(killer_pnum, 1);
823                 }
824                 else
825                 {
826                         if (Game_mode & GM_TEAM)
827                         {
828                                 if (killed_pnum==Player_num && get_team(killed_pnum) == get_team(killer_pnum))
829                                         Multi_killed_yourself=1;
830                         }
831                 }
832
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);
840                 }
841                 else if (killed_pnum == Player_num)
842                 {
843                         HUD_init_message("%s %s %s!", killer_name, TXT_KILLED, TXT_YOU);
844                         multi_add_lifetime_killed();
845                         if (Game_mode & GM_HOARD)
846                         {
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);
851                         }
852                 }
853                 else
854                         HUD_init_message("%s %s %s!", killer_name, TXT_KILLED, killed_name);
855         }
856
857         TheGoal=Netgame.KillGoal*5;
858
859         if (Netgame.KillGoal>0)
860         {
861                 if (Players[killer_pnum].KillGoalCount>=TheGoal)
862                 {
863                         if (killer_pnum==Player_num)
864                         {
865                                 HUD_init_message("You reached the kill goal!");
866                                 Players[Player_num].shields=i2f(200);
867                         }
868                         else
869                                 HUD_init_message ("%s has reached the kill goal!",Players[killer_pnum].callsign);
870
871                         HUD_init_message ("The control center has been destroyed!");
872                         net_destroy_controlcen (obj_find_first_of_type (OBJ_CNTRLCEN));
873                 }
874         }
875
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
879 }
880
881 void
882 multi_do_frame(void)
883 {
884         static int lasttime=0;
885         int i;
886
887         if (!(Game_mode & GM_MULTI))
888         {
889                 Int3();
890                 return;
891         }
892
893         if ((Game_mode & GM_NETWORK) && Netgame.PlayTimeAllowed && lasttime!=f2i (ThisLevelTime))
894         {
895                 for (i=0;i<N_players;i++)
896                         if (Players[i].connected)
897                         {
898                                 if (i==Player_num)
899                                 {
900                                         multi_send_heartbeat();
901                                         lasttime=f2i(ThisLevelTime);
902                                 }
903                                 break;
904                         }
905         }
906
907         multi_send_message(); // Send any waiting messages
908
909         if (!multi_in_menu)
910                 multi_leave_menu = 0;
911
912 #ifndef SHAREWARE
913         if (Game_mode & GM_MULTI_ROBOTS)
914         {
915                 multi_check_robot_timeout();
916         }
917 #endif
918
919         if ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM))
920         {
921                 com_do_frame();
922         }
923         else
924         {
925                 network_do_frame(0, 1);
926         }
927
928         if (multi_quit_game && !multi_in_menu)
929         {
930                 multi_quit_game = 0;
931                 longjmp(LeaveGame, 0);
932         }
933 }
934
935 void
936 multi_send_data(char *buf, int len, int repeat)
937 {
938         Assert(len == message_length[(int)buf[0]]);
939         Assert(buf[0] <= MULTI_MAX_TYPE);
940         //      Assert(buf[0] >= 0);
941
942         if (Game_mode & GM_NETWORK)
943                 Assert(buf[0] > 0);
944
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);
949 }
950
951 void
952 multi_leave_game(void)
953 {
954
955         //      if (Function_mode != FMODE_GAME)
956         //              return;
957
958         if (!(Game_mode & GM_MULTI))
959                 return;
960
961         if (Game_mode & GM_NETWORK)
962         {
963                 mprintf((0, "Sending explosion message.\n"));
964
965                 Net_create_loc = 0;
966                 AdjustMineSpawn();
967                 multi_cap_objects();
968                 drop_player_eggs(ConsoleObject);
969                 multi_send_position(Players[Player_num].objnum);
970                 multi_send_player_explode(MULTI_PLAYER_DROP);
971         }
972
973         mprintf((1, "Sending leave game.\n"));
974         multi_send_quit(MULTI_QUIT);
975
976         if ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM))
977                 serial_leave_game();
978         if (Game_mode & GM_NETWORK)
979                 network_leave_game();
980
981         Game_mode |= GM_GAME_OVER;
982
983         if (Function_mode!=FMODE_EXIT)
984                 Function_mode = FMODE_MENU;
985
986         //      N_players = 0;
987
988         //      change_playernum_to(0);
989         //      Viewer = ConsoleObject = &Objects[0];
990
991 }
992
993 void
994 multi_show_player_list()
995 {
996         if (!(Game_mode & GM_MULTI) || (Game_mode & GM_MULTI_COOP))
997                 return;
998
999         if (Show_kill_list)
1000                 return;
1001
1002         Show_kill_list_timer = F1_0*5; // 5 second timer
1003         Show_kill_list = 1;
1004 }
1005
1006 int
1007 multi_endlevel(int *secret)
1008 {
1009         int result = 0;
1010
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);
1015
1016         return(result);
1017 }
1018
1019 //
1020 // Part 2 : functions that act on network/serial messages and change the
1021 //          the state of the game in some way.
1022 //
1023
1024 #ifndef MACINTOSH
1025 //extern PORT *com_port;
1026 #endif
1027
1028 int
1029 multi_menu_poll(void)
1030 {
1031         fix old_shields;
1032         int was_fuelcen_alive;
1033         int player_was_dead;
1034
1035         was_fuelcen_alive = Control_center_destroyed;
1036
1037         // Special polling function for in-game menus for multiplayer and serial
1038
1039         if (! ((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)) )
1040                 return(0);
1041
1042         if (multi_leave_menu)
1043                 return(-1);
1044
1045         old_shields = Players[Player_num].shields;
1046         player_was_dead = Player_is_dead;
1047
1048         multi_in_menu++; // Track level of menu nesting
1049
1050         GameLoop( 0, 0 );
1051
1052         multi_in_menu--;
1053
1054         timer_delay(f0_1);   // delay 100 milliseconds
1055
1056         if (Endlevel_sequence || (Control_center_destroyed && !was_fuelcen_alive) || (Player_is_dead != player_was_dead) || (Players[Player_num].shields < old_shields))
1057         {
1058                 multi_leave_menu = 1;
1059                 return(-1);
1060         }
1061         if ((Control_center_destroyed) && (Countdown_seconds_left < 10))
1062         {
1063                 multi_leave_menu = 1;
1064                 return(-1);
1065         }
1066
1067 #if 0
1068         if ((Game_mode & GM_MODEM) && (!GetCd(com_port)))
1069         {
1070                 multi_leave_menu = 1;
1071                 return(-1);
1072         }
1073 #endif
1074
1075         return(0);
1076 }
1077
1078 void
1079 multi_define_macro(int key)
1080 {
1081         if (!(Game_mode & GM_MULTI))
1082                 return;
1083
1084         key &= (~KEY_SHIFTED);
1085
1086         switch(key)
1087         {
1088         case KEY_F9:
1089                 multi_defining_message = 1; break;
1090         case KEY_F10:
1091                 multi_defining_message = 2; break;
1092         case KEY_F11:
1093                 multi_defining_message = 3; break;
1094         case KEY_F12:
1095                 multi_defining_message = 4; break;
1096         default:
1097                 Int3();
1098         }
1099
1100         if (multi_defining_message)     {
1101                 multi_message_index = 0;
1102                 Network_message[multi_message_index] = 0;
1103         }
1104
1105 }
1106
1107 char feedback_result[200];
1108
1109 void
1110 multi_message_feedback(void)
1111 {
1112         char *colon;
1113         int found = 0;
1114         int i;
1115
1116         if (!( ((colon = strrchr(Network_message, ':')) == NULL) || (colon-Network_message < 1) || (colon-Network_message > CALLSIGN_LEN) ))
1117         {
1118                 sprintf(feedback_result, "%s ", TXT_MESSAGE_SENT_TO);
1119                 if ((Game_mode & GM_TEAM) && (atoi(Network_message) > 0) && (atoi(Network_message) < 3))
1120                 {
1121                         sprintf(feedback_result+strlen(feedback_result), "%s '%s'", TXT_TEAM, Netgame.team_name[atoi(Network_message)-1]);
1122                         found = 1;
1123                 }
1124                 if (Game_mode & GM_TEAM)
1125                 {
1126                         for (i = 0; i < N_players; i++)
1127                         {
1128                                 if (!strnicmp(Netgame.team_name[i], Network_message, colon-Network_message))
1129                                 {
1130                                         if (found)
1131                                                 strcat(feedback_result, ", ");
1132                                         found++;
1133                                         if (!(found % 4))
1134                                                 strcat(feedback_result, "\n");
1135                                         sprintf(feedback_result+strlen(feedback_result), "%s '%s'", TXT_TEAM, Netgame.team_name[i]);
1136                                 }
1137                         }
1138                 }
1139                 for (i = 0; i < N_players; i++)
1140                 {
1141                         if ((!strnicmp(Players[i].callsign, Network_message, colon-Network_message)) && (i != Player_num) && (Players[i].connected))
1142                         {
1143                                 if (found)
1144                                         strcat(feedback_result, ", ");
1145                                 found++;
1146                                 if (!(found % 4))
1147                                         strcat(feedback_result, "\n");
1148                                 sprintf(feedback_result+strlen(feedback_result), "%s", Players[i].callsign);
1149                         }
1150                 }
1151                 if (!found)
1152                         strcat(feedback_result, TXT_NOBODY);
1153                 else
1154                         strcat(feedback_result, ".");
1155
1156                 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1157
1158                 Assert(strlen(feedback_result) < 200);
1159
1160                 HUD_init_message(feedback_result);
1161                 //sprintf (temp,"%s",colon);
1162                 //sprintf (Network_message,"%s",temp);
1163
1164         }
1165 }
1166
1167 void
1168 multi_send_macro(int key)
1169 {
1170         if (! (Game_mode & GM_MULTI) )
1171                 return;
1172
1173         switch(key)
1174         {
1175         case KEY_F9:
1176                 key = 0; break;
1177         case KEY_F10:
1178                 key = 1; break;
1179         case KEY_F11:
1180                 key = 2; break;
1181         case KEY_F12:
1182                 key = 3; break;
1183         default:
1184                 Int3();
1185         }
1186
1187         if (!Network_message_macro[key][0])
1188         {
1189                 HUD_init_message(TXT_NO_MACRO);
1190                 return;
1191         }
1192
1193         strcpy(Network_message, Network_message_macro[key]);
1194         Network_message_reciever = 100;
1195
1196         HUD_init_message("%s '%s'", TXT_SENDING, Network_message);
1197         multi_message_feedback();
1198 }
1199
1200
1201 void
1202 multi_send_message_start()
1203 {
1204         if (Game_mode&GM_MULTI) {
1205                 multi_sending_message = 1;
1206                 multi_message_index = 0;
1207                 Network_message[multi_message_index] = 0;
1208         }
1209 }
1210
1211 extern fix StartingShields;
1212 fix PingLaunchTime,PingReturnTime;
1213
1214 extern void network_send_ping (ubyte);
1215 extern int network_who_is_master();
1216 extern char NameReturning;
1217 extern int force_cockpit_redraw;
1218
1219 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why);
1220
1221 void multi_send_message_end()
1222 {
1223         char *mytempbuf;
1224         int i,t;
1225
1226         Network_message_reciever = 100;
1227
1228         if (!strnicmp (Network_message,"!Names",6))
1229         {
1230                 NameReturning=1-NameReturning;
1231                 HUD_init_message ("Name returning is now %s.",NameReturning?"active":"disabled");
1232         }
1233         else if (!strnicmp (Network_message,"Handicap:",9))
1234         {
1235                 mytempbuf=&Network_message[9];
1236                 mprintf ((0,"Networkhandi=%s\n",mytempbuf));
1237                 StartingShields=atol (mytempbuf);
1238                 if (StartingShields<10)
1239                         StartingShields=10;
1240                 if (StartingShields>100)
1241                 {
1242                         sprintf (Network_message,"%s has tried to cheat!",Players[Player_num].callsign);
1243                         StartingShields=100;
1244                 }
1245                 else
1246                         sprintf (Network_message,"%s handicap is now %d",Players[Player_num].callsign,StartingShields);
1247
1248                 HUD_init_message ("Telling others of your handicap of %d!",StartingShields);
1249                 StartingShields=i2f(StartingShields);
1250         }
1251         else if (!strnicmp (Network_message,"NoBombs",7))
1252                 Netgame.DoSmartMine=0;
1253         else if (!strnicmp (Network_message,"Ping:",5))
1254         {
1255                 if (Game_mode & GM_NETWORK)
1256                 {
1257                         int name_index=5;
1258                         if (strlen(Network_message) > 5)
1259                                 while (Network_message[name_index] == ' ')
1260                                         name_index++;
1261
1262                         if (strlen(Network_message)<=name_index)
1263                         {
1264                                 HUD_init_message ("You must specify a name to ping");
1265                                 return;
1266                         }
1267
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))
1270                                 {
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;
1276                                         return;
1277                                 }
1278                 }
1279                 else // Modem/Serial ping
1280                 {
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;
1286                         return;
1287                 }
1288         }
1289         else if (!strnicmp (Network_message,"move:",5))
1290         {
1291                 mprintf ((0,"moving?\n"));
1292
1293                 if ((Game_mode & GM_NETWORK) && (Game_mode & GM_TEAM))
1294                 {
1295                         int name_index=5;
1296                         if (strlen(Network_message) > 5)
1297                                 while (Network_message[name_index] == ' ')
1298                                         name_index++;
1299
1300                         if (!network_i_am_master())
1301                         {
1302                                 HUD_init_message ("Only %s can move players!",Players[network_who_is_master()].callsign);
1303                                 return;
1304                         }
1305
1306                         if (strlen(Network_message)<=name_index)
1307                         {
1308                                 HUD_init_message ("You must specify a name to move");
1309                                 return;
1310                         }
1311
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))
1314                                 {
1315                                         if ((Game_mode & GM_CAPTURE) && (Players[i].flags & PLAYER_FLAGS_FLAG))
1316                                         {
1317                                                 HUD_init_message ("Can't move player because s/he has a flag!");
1318                                                 return;
1319                                         }
1320
1321                                         if (Netgame.team_vector & (1<<i))
1322                                                 Netgame.team_vector&=(~(1<<i));
1323                                         else
1324                                                 Netgame.team_vector|=(1<<i);
1325
1326                                         for (t=0;t<N_players;t++)
1327                                                 if (Players[t].connected)
1328                                                         multi_reset_object_texture (&Objects[Players[t].objnum]);
1329
1330                                         network_send_netgame_update ();
1331                                         sprintf (Network_message,"%s has changed teams!",Players[i].callsign);
1332                                         if (i==Player_num)
1333                                         {
1334                                                 HUD_init_message ("You have changed teams!");
1335                                                 reset_cockpit();
1336                                         }
1337                                         else
1338                                                 HUD_init_message ("Moving %s to other team.",Players[i].callsign);
1339                                         break;
1340                                 }
1341                 }
1342         }
1343
1344         else if (!strnicmp (Network_message,"kick:",5) && (Game_mode & GM_NETWORK))
1345         {
1346                 int name_index=5;
1347                 if (strlen(Network_message) > 5)
1348                         while (Network_message[name_index] == ' ')
1349                                 name_index++;
1350
1351                 if (!network_i_am_master())
1352                 {
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;
1356                         return;
1357                 }
1358                 if (strlen(Network_message)<=name_index)
1359                 {
1360                         HUD_init_message ("You must specify a name to kick");
1361                         multi_message_index = 0;
1362                         multi_sending_message = 0;
1363                         return;
1364                 }
1365
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';
1369
1370                         mprintf ((0,"Trying to kick %d , show_kill_list=%d\n",listpos,Show_kill_list));
1371
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;
1377                                         return;
1378                                 }
1379                                 multi_get_kill_list(players);
1380                                 i = players[listpos];
1381                                 if ((i != Player_num) && (Players[i].connected))
1382                                         goto kick_player;
1383                         }
1384                         else HUD_init_message ("You cannot use # kicking with in team display.");
1385
1386
1387                     multi_message_index = 0;
1388                     multi_sending_message = 0;
1389                         return;
1390                 }
1391
1392
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)) {
1395                         kick_player:;
1396                                 if (Network_game_type == IPX_GAME)
1397                                         network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, 7);
1398                                 else
1399                                         network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, 7);
1400
1401                                 HUD_init_message("Dumping %s...",Players[i].callsign);
1402                                 multi_message_index = 0;
1403                                 multi_sending_message = 0;
1404                                 return;
1405                         }
1406         }
1407
1408         else
1409                 HUD_init_message("%s '%s'", TXT_SENDING, Network_message);
1410
1411         multi_send_message();
1412         multi_message_feedback();
1413
1414         multi_message_index = 0;
1415         multi_sending_message = 0;
1416 }
1417
1418 void multi_define_macro_end()
1419 {
1420         Assert( multi_defining_message > 0 );
1421
1422         strcpy( Network_message_macro[multi_defining_message-1], Network_message );
1423         write_player_file();
1424
1425         multi_message_index = 0;
1426         multi_defining_message = 0;
1427 }
1428
1429 void multi_message_input_sub( int key )
1430 {
1431         switch( key )   {
1432         case KEY_F8:
1433         case KEY_ESC:
1434                 multi_sending_message = 0;
1435                 multi_defining_message = 0;
1436                 game_flush_inputs();
1437                 break;
1438         case KEY_LEFT:
1439         case KEY_BACKSP:
1440         case KEY_PAD4:
1441                 if (multi_message_index > 0)
1442                         multi_message_index--;
1443                 Network_message[multi_message_index] = 0;
1444                 break;
1445         case KEY_ENTER:
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();
1451                 break;
1452         default:
1453                 if ( key > 0 )  {
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 )     {
1460                                         int i;
1461                                         char * ptext, * pcolon;
1462                                         ptext = NULL;
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;
1469                                                         break;
1470                                                 }
1471                                         }
1472                                         multi_send_message_end();
1473                                         if ( ptext )    {
1474                                                 multi_sending_message = 1;
1475                                                 pcolon = strchr( Network_message, ':' );
1476                                                 if ( pcolon )
1477                                                         strcpy( pcolon+1, ptext );
1478                                                 else
1479                                                         strcpy( Network_message, ptext );
1480                                                 multi_message_index = strlen( Network_message );
1481                                         }
1482                                 }
1483                         }
1484                 }
1485         }
1486 }
1487
1488 void
1489 multi_send_message_dialog(void)
1490 {
1491         newmenu_item m[1];
1492         int choice;
1493
1494         if (!(Game_mode&GM_MULTI))
1495                 return;
1496
1497         Network_message[0] = 0;             // Get rid of old contents
1498
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 );
1501
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();
1506         }
1507 }
1508
1509
1510
1511 void
1512 multi_do_death(int objnum)
1513 {
1514         // Do any miscellaneous stuff for a new network player after death
1515
1516         objnum = objnum;
1517
1518         if (!(Game_mode & GM_MULTI_COOP))
1519         {
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);
1522         }
1523 }
1524
1525 void
1526 multi_do_fire(char *buf)
1527 {
1528         ubyte weapon;
1529         char pnum;
1530         byte flags;
1531         //static dum=0;
1532
1533         // Act out the actual shooting
1534         pnum = buf[1];
1535
1536 #ifndef MACINTOSH
1537         weapon = (int)buf[2];
1538 #else
1539         weapon = buf[2];
1540 #endif
1541         flags = buf[4];
1542         Network_laser_track = INTEL_SHORT(*(short *)(buf+6));
1543
1544         Assert (pnum < N_players);
1545
1546         if (Objects[Players[(int)pnum].objnum].type == OBJ_GHOST)
1547                 multi_make_ghost_player(pnum);
1548
1549         //  mprintf((0,"multi_do_fire, weapon = %d\n",weapon));
1550
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;
1555
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));
1559
1560                 if (weapon-MISSILE_ADJUST==GUIDED_INDEX)
1561                 {
1562                         mprintf ((0,"Missile is guided!!!\n"));
1563                         Multi_is_guided=1;
1564                 }
1565
1566                 Laser_player_fire( Objects+Players[(int)pnum].objnum, weapon_id, weapon_gun, 1, 0 );
1567         }
1568         else {
1569                 fix save_charge = Fusion_charge;
1570
1571                 if (weapon == FUSION_INDEX) {
1572                         Fusion_charge = flags << 12;
1573                         mprintf((0, "Fusion charge X%f.\n", f2fl(Fusion_charge)));
1574                 }
1575                 if (weapon == LASER_ID) {
1576                         if (flags & LASER_QUAD)
1577                                 Players[(int)pnum].flags |= PLAYER_FLAGS_QUAD_LASERS;
1578                         else
1579                                 Players[(int)pnum].flags &= ~PLAYER_FLAGS_QUAD_LASERS;
1580                 }
1581
1582                 do_laser_firing(Players[(int)pnum].objnum, weapon, (int)buf[3], flags, (int)buf[5]);
1583
1584                 if (weapon == FUSION_INDEX)
1585                         Fusion_charge = save_charge;
1586         }
1587 }
1588
1589 void
1590 multi_do_message(char *buf)
1591 {
1592         char *colon;
1593         char *tilde,mesbuf[100];
1594         int tloc,t;
1595
1596         int loc = 2;
1597
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));
1602
1603                 if (tloc>0)
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);
1608         }
1609
1610         if (((colon = strrchr(buf+loc, ':')) == NULL) || (colon-(buf+loc) < 1) || (colon-(buf+loc) > CALLSIGN_LEN))
1611         {
1612                 mesbuf[0] = 1;
1613                 mesbuf[1] = BM_XRGB(28, 0, 0);
1614                 strcpy(&mesbuf[2], Players[(int)buf[1]].callsign);
1615                 t = strlen(mesbuf);
1616                 mesbuf[t] = ':';
1617                 mesbuf[t+1] = 1;
1618                 mesbuf[t+2] = BM_XRGB(0, 31, 0);
1619                 mesbuf[t+3] = 0;
1620
1621                 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1622                 HUD_init_message("%s %s", mesbuf, buf+2);
1623         }
1624         else
1625         {
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)))) )
1628                 {
1629                         mesbuf[0] = 1;
1630                         mesbuf[1] = BM_XRGB(0, 32, 32);
1631                         strcpy(&mesbuf[2], Players[(int)buf[1]].callsign);
1632                         t = strlen(mesbuf);
1633                         mesbuf[t] = ':';
1634                         mesbuf[t+1] = 1;
1635                         mesbuf[t+2] = BM_XRGB(0, 31, 0);
1636                         mesbuf[t+3] = 0;
1637
1638                         digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1639                         HUD_init_message("%s %s", mesbuf, colon+1);
1640                 }
1641         }
1642 }
1643
1644 void
1645 multi_do_position(char *buf)
1646 {
1647 #ifdef MACINTOSH
1648         shortpos sp;
1649 #endif
1650
1651         // This routine does only player positions, mode game only
1652         //      mprintf((0, "Got position packet.\n"));
1653
1654         int pnum = (Player_num+1)%2;
1655
1656         Assert(&Objects[Players[pnum].objnum] != ConsoleObject);
1657
1658         if (Game_mode & GM_NETWORK)
1659         {
1660                 Int3(); // Get Jason, what the hell are we doing here?
1661                 return;
1662     }
1663
1664
1665 #ifndef MACINTOSH
1666         extract_shortpos(&Objects[Players[pnum].objnum], (shortpos *)(buf+1),0);
1667 #else
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);
1671 #endif
1672
1673         if (Objects[Players[pnum].objnum].movement_type == MT_PHYSICS)
1674                 set_thrust_from_velocity(&Objects[Players[pnum].objnum]);
1675 }
1676
1677 void
1678 multi_do_reappear(char *buf)
1679 {
1680         short objnum;
1681
1682         objnum = INTEL_SHORT(*(short *)(buf+1));
1683
1684         Assert(objnum >= 0);
1685         //      Assert(Players[Objects[objnum].id]].objnum == objnum);
1686
1687         // mprintf((0, "Switching rendering back on for object %d.\n", objnum));
1688
1689         multi_make_ghost_player(Objects[objnum].id);
1690         create_player_appearance_effect(&Objects[objnum]);
1691         PKilledFlags[Objects[objnum].id]=0;
1692 }
1693
1694 void
1695 multi_do_player_explode(char *buf)
1696 {
1697         // Only call this for players, not robots.  pnum is player number, not
1698         // Object number.
1699
1700         object *objp;
1701         int count;
1702         int pnum;
1703         int i;
1704         char remote_created;
1705
1706         pnum = buf[1];
1707
1708 #ifdef NDEBUG
1709         if ((pnum < 0) || (pnum >= N_players))
1710                 return;
1711 #else
1712         Assert(pnum >= 0);
1713         Assert(pnum < N_players);
1714 #endif
1715
1716 #ifdef NETWORK
1717         // If we are in the process of sending objects to a new player, reset that process
1718         if (Network_send_objects)
1719         {
1720                 mprintf((0, "Resetting object sync due to player explosion.\n"));
1721                 Network_send_objnum = -1;
1722         }
1723 #endif
1724
1725         // Stuff the Players structure to prepare for the explosion
1726
1727         count = 2;
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++;
1736
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++;
1742
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;
1746
1747         multi_adjust_remote_cap (pnum);
1748
1749         objp = Objects+Players[pnum].objnum;
1750
1751         //      objp->phys_info.velocity = *(vms_vector *)(buf+16); // 12 bytes
1752         //      objp->pos = *(vms_vector *)(buf+28);                // 12 bytes
1753
1754         remote_created = buf[count++]; // How many did the other guy create?
1755
1756         Net_create_loc = 0;
1757
1758         drop_player_eggs(objp);
1759
1760         // Create mapping from remote to local numbering system
1761
1762         mprintf((0, "I Created %d powerups, remote created %d.\n", Net_create_loc, remote_created));
1763
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
1767
1768         for (i = 0; i < remote_created; i++)
1769         {
1770                 short s;
1771
1772                 s = INTEL_SHORT(*(short *)(buf+count));
1773
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)
1777                 {
1778                         mprintf((0, "WARNING: Remote created object has non-valid number %d (player %d)", s, pnum));
1779                 }
1780                 else
1781                 {
1782                         mprintf((0, "WARNING: Could not create all powerups created by player %d.\n", pnum));
1783                 }
1784                 //              Assert(s > 0);
1785                 count += 2;
1786         }
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;
1790         }
1791
1792         if (buf[0] == MULTI_PLAYER_EXPLODE)
1793         {
1794                 explode_badass_player(objp);
1795
1796                 objp->flags &= ~OF_SHOULD_BE_DEAD;              //don't really kill player
1797                 multi_make_player_ghost(pnum);
1798         }
1799         else
1800         {
1801                 create_player_appearance_effect(objp);
1802         }
1803
1804         Players[pnum].flags &= ~(PLAYER_FLAGS_CLOAKED | PLAYER_FLAGS_INVULNERABLE | PLAYER_FLAGS_FLAG);
1805         Players[pnum].cloak_time = 0;
1806 }
1807
1808 void
1809 multi_do_kill(char *buf)
1810 {
1811         int killer, killed;
1812         int count = 1;
1813         int pnum;
1814
1815         pnum = (int)(buf[count]);
1816         if ((pnum < 0) || (pnum >= N_players))
1817         {
1818                 Int3(); // Invalid player number killed
1819                 return;
1820         }
1821         killed = Players[pnum].objnum;
1822         count += 1;
1823
1824         killer = INTEL_SHORT(*(short *)(buf+count));
1825         if (killer > 0)
1826                 killer = objnum_remote_to_local(killer, (byte)buf[count+2]);
1827
1828 #ifdef SHAREWARE
1829         if ((Objects[killed].type != OBJ_PLAYER) && (Objects[killed].type != OBJ_GHOST))
1830         {
1831                 Int3();
1832                 mprintf( (1, "SOFT INT3: MULTI.C Non-player object %d of type %d killed! (JOHN)\n", killed, Objects[killed].type ));
1833                 return;
1834         }
1835 #endif
1836
1837         multi_compute_kill(killer, killed);
1838
1839 }
1840
1841
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)
1845 {
1846         byte who;
1847         short objnum;
1848
1849         objnum = INTEL_SHORT(*(short *)(buf+1));
1850         who = buf[3];
1851
1852         if (Control_center_destroyed != 1)
1853         {
1854                 if ((who < N_players) && (who != Player_num)) {
1855                         HUD_init_message("%s %s", Players[who].callsign, TXT_HAS_DEST_CONTROL);
1856                 }
1857                 else if (who == Player_num)
1858                         HUD_init_message(TXT_YOU_DEST_CONTROL);
1859                 else
1860                         HUD_init_message(TXT_CONTROL_DESTROYED);
1861
1862                 if (objnum != -1)
1863                         net_destroy_controlcen(Objects+objnum);
1864                 else
1865                         net_destroy_controlcen(NULL);
1866         }
1867 }
1868
1869 void
1870 multi_do_escape(char *buf)
1871 {
1872         int objnum;
1873
1874         objnum = Players[(int)buf[1]].objnum;
1875
1876         digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1877         digi_kill_sound_linked_to_object (objnum);
1878
1879         if (buf[2] == 0)
1880         {
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;
1886         }
1887         else if (buf[2] == 1)
1888         {
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;
1894         }
1895         create_player_appearance_effect(&Objects[objnum]);
1896         multi_make_player_ghost(buf[1]);
1897 }
1898
1899 void
1900 multi_do_remobj(char *buf)
1901 {
1902         short objnum; // which object to remove
1903         short local_objnum;
1904         byte obj_owner; // which remote list is it entered in
1905
1906         objnum = INTEL_SHORT(*(short *)(buf+1));
1907         obj_owner = buf[3];
1908
1909         Assert(objnum >= 0);
1910
1911         if (objnum < 1)
1912                 return;
1913
1914         local_objnum = objnum_remote_to_local(objnum, obj_owner); // translate to local objnum
1915
1916         //      mprintf((0, "multi_do_remobj: %d owner %d = %d.\n", objnum, obj_owner, local_objnum));
1917
1918         if (local_objnum < 0)
1919         {
1920                 mprintf((1, "multi_do_remobj: Could not remove referenced object.\n"));
1921                 return;
1922         }
1923
1924         if ((Objects[local_objnum].type != OBJ_POWERUP) && (Objects[local_objnum].type != OBJ_HOSTAGE))
1925         {
1926                 mprintf((1, "multi_get_remobj: tried to remove invalid type %d.\n", Objects[local_objnum].type));
1927                 return;
1928         }
1929
1930         if (Network_send_objects && network_objnum_is_past(local_objnum))
1931         {
1932                 mprintf((0, "Resetting object sync due to object removal.\n"));
1933                 Network_send_objnum = -1;
1934         }
1935         if (Objects[local_objnum].type==OBJ_POWERUP)
1936                 if (Game_mode & GM_NETWORK)
1937                 {
1938                         if (PowerupsInMine[Objects[local_objnum].id]>0)
1939                                 PowerupsInMine[Objects[local_objnum].id]--;
1940
1941                         if (multi_powerup_is_4pack (Objects[local_objnum].id))
1942                         {
1943                                 mprintf ((0,"Hey babe! Doing that wacky 4 pack stuff."));
1944
1945                                 if (PowerupsInMine[Objects[local_objnum].id-1]-4<0)
1946                                         PowerupsInMine[Objects[local_objnum].id-1]=0;
1947                                 else
1948                                         PowerupsInMine[Objects[local_objnum].id-1]-=4;
1949                         }
1950
1951                         mprintf ((0,"Decrementing powerups! %d\n",PowerupsInMine[Objects[local_objnum].id]));
1952                 }
1953
1954         Objects[local_objnum].flags |= OF_SHOULD_BE_DEAD; // quick and painless
1955
1956 }
1957
1958 void
1959 multi_do_quit(char *buf)
1960 {
1961
1962         if (Game_mode & GM_NETWORK)
1963         {
1964                 int i, n = 0;
1965
1966                 digi_play_sample( SOUND_HUD_MESSAGE, F1_0 );
1967
1968                 HUD_init_message( "%s %s", Players[(int)buf[1]].callsign, TXT_HAS_LEFT_THE_GAME);
1969
1970                 network_disconnect_player(buf[1]);
1971
1972                 if (multi_in_menu)
1973                         return;
1974
1975                 for (i = 0; i < N_players; i++)
1976                         if (Players[i].connected) n++;
1977                 if (n == 1)
1978                 {
1979                         nm_messagebox(NULL, 1, TXT_OK, TXT_YOU_ARE_ONLY);
1980                 }
1981         }
1982
1983         if ((Game_mode & GM_SERIAL) || (Game_mode & GM_MODEM))
1984         {
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();
1991         }
1992         return;
1993 }
1994
1995 void
1996 multi_do_cloak(char *buf)
1997 {
1998         int pnum;
1999
2000         pnum = (int)(buf[1]);
2001
2002         Assert(pnum < N_players);
2003
2004         mprintf((0, "Cloaking player %d\n", pnum));
2005
2006         Players[pnum].flags |= PLAYER_FLAGS_CLOAKED;
2007         Players[pnum].cloak_time = GameTime;
2008         ai_do_cloak_stuff();
2009
2010 #ifndef SHAREWARE
2011         if (Game_mode & GM_MULTI_ROBOTS)
2012                 multi_strip_robots(pnum);
2013 #endif
2014
2015         if (Newdemo_state == ND_STATE_RECORDING)
2016                 newdemo_record_multi_cloak(pnum);
2017 }
2018
2019 void
2020 multi_do_decloak(char *buf)
2021 {
2022         int pnum;
2023
2024         pnum = (int)(buf[1]);
2025
2026         if (Newdemo_state == ND_STATE_RECORDING)
2027                 newdemo_record_multi_decloak(pnum);
2028
2029 }
2030
2031 void
2032 multi_do_door_open(char *buf)
2033 {
2034         int segnum;
2035         byte side;
2036         segment *seg;
2037         wall *w;
2038         ubyte flag;
2039
2040         segnum = INTEL_SHORT(*(short *)(buf+1));
2041         side = buf[3];
2042         flag= buf[4];
2043
2044         //      mprintf((0, "Opening door on side %d of segment # %d.\n", side, segnum));
2045
2046         if ((segnum < 0) || (segnum > Highest_segment_index) || (side < 0) || (side > 5))
2047         {
2048                 Int3();
2049                 return;
2050         }
2051
2052         seg = &Segments[segnum];
2053
2054         if (seg->sides[side].wall_num == -1) {  //Opening door on illegal wall
2055                 Int3();
2056                 return;
2057         }
2058
2059         w = &Walls[seg->sides[side].wall_num];
2060
2061         if (w->type == WALL_BLASTABLE)
2062         {
2063                 if (!(w->flags & WALL_BLASTED))
2064                 {
2065                         mprintf((0, "Blasting wall by remote command.\n"));
2066                         wall_destroy(seg, side);
2067                 }
2068                 return;
2069         }
2070         else if (w->state != WALL_DOOR_OPENING)
2071         {
2072                 wall_open_door(seg, side);
2073                 w->flags=flag;
2074         }
2075         else
2076                 w->flags=flag;
2077
2078         //      else
2079         //              mprintf((0, "Door already opening!\n"));
2080 }
2081
2082 void
2083 multi_do_create_explosion(char *buf)
2084 {
2085         int pnum;
2086         int count = 1;
2087
2088         pnum = buf[count++];
2089
2090         //      mprintf((0, "Creating small fireball.\n"));
2091         create_small_fireball_on_object(&Objects[Players[pnum].objnum], F1_0, 1);
2092 }
2093
2094 void
2095 multi_do_controlcen_fire(char *buf)
2096 {
2097         vms_vector to_target;
2098         char gun_num;
2099         short objnum;
2100         int count = 1;
2101
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);
2107 #endif
2108         gun_num = buf[count];                                   count += 1;
2109         objnum = INTEL_SHORT(*(short *)(buf+count));         count += 2;
2110
2111         Laser_create_new_easy(&to_target, &Gun_pos[(int)gun_num], objnum, CONTROLCEN_WEAPON_NUM, 1);
2112 }
2113
2114 void
2115 multi_do_create_powerup(char *buf)
2116 {
2117         short segnum;
2118         short objnum;
2119         int my_objnum;
2120         char pnum;
2121         int count = 1;
2122         vms_vector new_pos;
2123         char powerup_type;
2124
2125         if (Endlevel_sequence || Control_center_destroyed)
2126                 return;
2127
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;
2132
2133         if ((segnum < 0) || (segnum > Highest_segment_index)) {
2134                 Int3();
2135                 return;
2136         }
2137
2138         new_pos = *(vms_vector *)(buf+count); count+=sizeof(vms_vector);
2139 #ifdef MACINTOSH
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);
2143 #endif
2144
2145         Net_create_loc = 0;
2146         my_objnum = call_object_create_egg(&Objects[Players[(int)pnum].objnum], 1, OBJ_POWERUP, powerup_type);
2147
2148         if (my_objnum < 0) {
2149                 mprintf((0, "Could not create new powerup!\n"));
2150                 return;
2151         }
2152
2153         if (Network_send_objects && network_objnum_is_past(my_objnum))
2154         {
2155                 mprintf((0, "Resetting object sync due to powerup creation.\n"));
2156                 Network_send_objnum = -1;
2157         }
2158
2159         Objects[my_objnum].pos = new_pos;
2160
2161         vm_vec_zero(&Objects[my_objnum].mtype.phys_info.velocity);
2162
2163         obj_relink(my_objnum, segnum);
2164
2165         map_objnum_local_to_remote(my_objnum, objnum, pnum);
2166
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));
2169
2170         if (Game_mode & GM_NETWORK)
2171                 PowerupsInMine[(int)powerup_type]++;
2172 }
2173
2174 void
2175 multi_do_play_sound(char *buf)
2176 {
2177         int pnum = (int)(buf[1]);
2178         int sound_num = (int)(buf[2]);
2179         fix volume = (int)(buf[3]) << 12;
2180
2181         if (!Players[pnum].connected)
2182                 return;
2183
2184         Assert(Players[pnum].objnum >= 0);
2185         Assert(Players[pnum].objnum <= Highest_object_index);
2186
2187         digi_link_sound_to_object( sound_num, Players[pnum].objnum, 0, volume);
2188 }
2189
2190 void
2191 multi_do_score(char *buf)
2192 {
2193         int pnum = (int)(buf[1]);
2194
2195         if ((pnum < 0) || (pnum >= N_players))
2196         {
2197                 Int3(); // Non-terminal, see rob
2198                 return;
2199         }
2200
2201         if (Newdemo_state == ND_STATE_RECORDING)
2202                 newdemo_record_multi_score(pnum, INTEL_INT(*(int *)(buf+2)) );
2203
2204         Players[pnum].score = INTEL_INT(*(int *)(buf+2));
2205
2206         multi_sort_kill_list();
2207 }
2208
2209 void
2210 multi_do_trigger(char *buf)
2211 {
2212         int pnum = (int)(buf[1]);
2213         int trigger = (int)(buf[2]);
2214
2215         mprintf ((0,"MULTI doing trigger!\n"));
2216
2217         if ((pnum < 0) || (pnum >= N_players) || (pnum == Player_num))
2218         {
2219                 Int3(); // Got trigger from illegal playernum
2220                 return;
2221         }
2222         if ((trigger < 0) || (trigger >= Num_triggers))
2223         {
2224                 Int3(); // Illegal trigger number in multiplayer
2225                 return;
2226         }
2227         check_trigger_sub(trigger, pnum,0);
2228 }
2229
2230 void multi_do_drop_marker (char *buf)
2231 {
2232         int i;
2233         int pnum=(int)(buf[1]);
2234         int mesnum=(int)(buf[2]);
2235         vms_vector position;
2236
2237         if (pnum==Player_num)  // my marker? don't set it down cuz it might screw up the orientation
2238                 return;
2239
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));
2243
2244         for (i=0;i<40;i++)
2245                 MarkerMessage[(pnum*2)+mesnum][i]=buf[15+i];
2246
2247         MarkerPoint[(pnum*2)+mesnum]=position;
2248
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]);
2251
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]));
2255 }
2256
2257
2258 void multi_do_hostage_door_status(char *buf)
2259 {
2260         // Update hit point status of a door
2261
2262         int count = 1;
2263         int wallnum;
2264         fix hps;
2265
2266         wallnum = INTEL_SHORT(*(short *)(buf+count));                count += 2;
2267         hps = (fix)INTEL_INT(*(int *)(buf+count));              count += 4;
2268
2269         if ((wallnum < 0) || (wallnum > Num_walls) || (hps < 0) || (Walls[wallnum].type != WALL_BLASTABLE))
2270         {
2271                 Int3(); // Non-terminal, see Rob
2272                 return;
2273         }
2274
2275         //      mprintf((0, "Damaging wall number %d to %f points.\n", wallnum, f2fl(hps)));
2276
2277         if (hps < Walls[wallnum].hps)
2278                 wall_damage(&Segments[Walls[wallnum].segnum], Walls[wallnum].sidenum, Walls[wallnum].hps - hps);
2279 }
2280
2281 void multi_do_save_game(char *buf)
2282 {
2283         int count = 1;
2284         ubyte slot;
2285         uint id;
2286         char desc[25];
2287
2288         slot = *(ubyte *)(buf+count);           count += 1;
2289         id = INTEL_INT(*(uint *)(buf+count));              count += 4;
2290         memcpy( desc, &buf[count], 20 );        count += 20;
2291
2292         multi_save_game( slot, id, desc );
2293 }
2294
2295 void multi_do_restore_game(char *buf)
2296 {
2297         int count = 1;
2298         ubyte slot;
2299         uint id;
2300
2301         slot = *(ubyte *)(buf+count);           count += 1;
2302         id = INTEL_INT(*(uint *)(buf+count));              count += 4;
2303
2304         multi_restore_game( slot, id );
2305 }
2306
2307
2308 void multi_do_req_player(char *buf)
2309 {
2310         netplayer_stats ps;
2311         ubyte player_n;
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);
2319         }
2320 }
2321
2322 void multi_do_send_player(char *buf)
2323 {
2324         // Got a player packet from someone!!!
2325         netplayer_stats * p;
2326         p = (netplayer_stats *)buf;
2327
2328         Assert( p->Player_num <= N_players );
2329
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) ));
2332
2333         use_netplayer_stats( &Players[p->Player_num], p );
2334 }
2335
2336 void
2337 multi_reset_stuff(void)
2338 {
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!
2342
2343         dead_player_end();
2344
2345         Players[Player_num].homing_object_dist = -F1_0; // Turn off homing sound.
2346
2347         Dead_player_camera = 0;
2348         Endlevel_sequence = 0;
2349         reset_rear_view();
2350 }
2351
2352 void
2353 multi_reset_player_object(object *objp)
2354 {
2355         int i;
2356
2357         //Init physics for a non-console player
2358
2359         Assert(objp >= Objects);
2360         Assert(objp <= Objects+Highest_object_index);
2361         Assert((objp->type == OBJ_PLAYER) || (objp->type == OBJ_GHOST));
2362
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);
2372
2373         //Init render info
2374
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]);
2380
2381         //reset textures for this, if not player 0
2382
2383         multi_reset_object_texture (objp);
2384
2385         // Clear misc
2386
2387         objp->flags = 0;
2388
2389         if (objp->type == OBJ_GHOST)
2390                 objp->render_type = RT_NONE;
2391
2392 }
2393
2394 void multi_reset_object_texture (object *objp)
2395 {
2396         int id,i;
2397
2398         if (Game_mode & GM_TEAM)
2399                 id = get_team(objp->id);
2400         else
2401                 id = objp->id;
2402
2403         if (id == 0)
2404                 objp->rtype.pobj_info.alt_textures=0;
2405         else {
2406                 Assert(N_PLAYER_SHIP_TEXTURES == Polygon_models[objp->rtype.pobj_info.model_num].n_textures);
2407
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]];
2410
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]];
2413
2414                 objp->rtype.pobj_info.alt_textures = id;
2415         }
2416 }
2417
2418
2419
2420
2421 extern int TTRecv[];
2422 extern FILE *RecieveLogFile;
2423
2424 void
2425 multi_process_bigdata(char *buf, int len)
2426 {
2427         // Takes a bunch of messages, check them for validity,
2428         // and pass them to multi_process_data.
2429
2430         int type, sub_len, bytes_processed = 0;
2431
2432         while( bytes_processed < len )  {
2433                 type = buf[bytes_processed];
2434
2435                 if ( (type<0) || (type>MULTI_MAX_TYPE)) {
2436                         mprintf( (1, "multi_process_bigdata: Invalid packet type %d!\n", type ));
2437                         return;
2438                 }
2439                 sub_len = message_length[type];
2440
2441                 Assert(sub_len > 0);
2442
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 ));
2445                         Int3();
2446                         return;
2447                 }
2448
2449                 multi_process_data(&buf[bytes_processed], sub_len);
2450                 bytes_processed += sub_len;
2451         }
2452 }
2453
2454 //
2455 // Part 2 : Functions that send communication messages to inform the other
2456 //          players of something we did.
2457 //
2458
2459 void
2460 multi_send_fire(void)
2461 {
2462         if (!Network_laser_fired)
2463                 return;
2464
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;
2471
2472         *(short *)(multibuf+6) = INTEL_SHORT(Network_laser_track);
2473
2474         multi_send_data(multibuf, 8, 0);
2475
2476         Network_laser_fired = 0;
2477 }
2478
2479 void
2480 multi_send_destroy_controlcen(int objnum, int player)
2481 {
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);
2486         else
2487                 HUD_init_message(TXT_CONTROL_DESTROYED);
2488
2489         multibuf[0] = (char)MULTI_CONTROLCEN;
2490         *(ushort *)(multibuf+1) = INTEL_SHORT(objnum);
2491         multibuf[3] = player;
2492         multi_send_data(multibuf, 4, 2);
2493 }
2494
2495 void multi_send_drop_marker (int player,vms_vector position,char messagenum,char text[])
2496 {
2497         int i;
2498
2499         if (player<N_players)
2500         {
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);
2508                 for (i=0;i<40;i++)
2509                         multibuf[15+i]=text[i];
2510         }
2511         multi_send_data(multibuf, 55, 1);
2512 }
2513
2514 void
2515 multi_send_endlevel_start(int secret)
2516 {
2517         multibuf[0] = (char)MULTI_ENDLEVEL_START;
2518         multibuf[1] = Player_num;
2519         multibuf[2] = (char)secret;
2520
2521         if ((secret) && !multi_goto_secret)
2522                 multi_goto_secret = 1;
2523         else if (!multi_goto_secret)
2524                 multi_goto_secret = 2;
2525
2526         multi_send_data(multibuf, 3, 1);
2527         if (Game_mode & GM_NETWORK)
2528         {
2529                 Players[Player_num].connected = 5;
2530                 network_send_endlevel_packet();
2531         }
2532 }
2533
2534 void
2535 multi_send_player_explode(char type)
2536 {
2537         int count = 0;
2538         int i;
2539
2540         Assert( (type == MULTI_PLAYER_DROP) || (type == MULTI_PLAYER_EXPLODE) );
2541
2542         multi_send_position(Players[Player_num].objnum);
2543
2544         if (Network_send_objects)
2545         {
2546                 mprintf((0, "Resetting object sync due to player explosion.\n"));
2547                 Network_send_objnum = -1;
2548         }
2549
2550         multibuf[count++] = type;
2551         multibuf[count++] = Player_num;
2552
2553         *(ushort *)(multibuf+count) = INTEL_SHORT((ushort)Players[Player_num].primary_weapon_flags);
2554         count += 2;
2555         *(ushort *)(multibuf+count) = INTEL_SHORT((ushort)Players[Player_num].secondary_weapon_flags);
2556         count += 2;
2557         multibuf[count++] = (char)Players[Player_num].laser_level;
2558
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];
2564
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];
2570
2571         *(ushort *)(multibuf+count) = INTEL_SHORT( (ushort)Players[Player_num].primary_ammo[VULCAN_INDEX] );
2572         count += 2;
2573         *(ushort *)(multibuf+count) = INTEL_SHORT( (ushort)Players[Player_num].primary_ammo[GAUSS_INDEX] );
2574         count += 2;
2575         *(uint *)(multibuf+count) = INTEL_INT( (uint)Players[Player_num].flags );
2576         count += 4;
2577
2578         multibuf[count++] = Net_create_loc;
2579
2580         Assert(Net_create_loc <= MAX_NET_CREATE_OBJECTS);
2581
2582         memset(multibuf+count, -1, MAX_NET_CREATE_OBJECTS*sizeof(short));
2583
2584         mprintf((0, "Created %d explosion objects.\n", Net_create_loc));
2585
2586         for (i = 0; i < Net_create_loc; i++)
2587         {
2588                 if (Net_create_objnums[i] <= 0) {
2589                         Int3(); // Illegal value in created egg object numbers
2590                         count +=2;
2591                         continue;
2592                 }
2593
2594                 *(short *)(multibuf+count) = INTEL_SHORT( (short)Net_create_objnums[i] ); count += 2;
2595
2596                 // We created these objs so our local number = the network number
2597                 map_objnum_local_to_local((short)Net_create_objnums[i]);
2598         }
2599
2600         Net_create_loc = 0;
2601
2602         //      mprintf((1, "explode message size = %d, max = %d.\n", count, message_length[MULTI_PLAYER_EXPLODE]));
2603
2604         if (count > message_length[MULTI_PLAYER_EXPLODE])
2605         {
2606                 Int3(); // See Rob
2607         }
2608
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);
2614 }
2615
2616 extern ubyte Secondary_weapon_to_powerup[];
2617 extern ubyte Primary_weapon_to_powerup[];
2618
2619 // put a lid on how many objects will be spewed by an exploding player
2620 // to prevent rampant powerups in netgames
2621
2622 void multi_cap_objects ()
2623 {
2624         char type,flagtype;
2625         int index;
2626
2627         if (!(Game_mode & GM_NETWORK))
2628                 return;
2629
2630         for (index=0;index<MAX_PRIMARY_WEAPONS;index++)
2631         {
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))
2635                         {
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));
2639                         }
2640         }
2641
2642
2643         // Don't do the adjustment stuff for Hoard mode
2644         if (!(Game_mode & GM_HOARD))
2645                 Players[Player_num].secondary_ammo[2]/=4;
2646
2647         Players[Player_num].secondary_ammo[7]/=4;
2648
2649         for (index=0;index<MAX_SECONDARY_WEAPONS;index++)
2650         {
2651                 if ((Game_mode & GM_HOARD) && index==PROXIMITY_INDEX)
2652                         continue;
2653
2654                 type=Secondary_weapon_to_powerup[index];
2655
2656                 if ((Players[Player_num].secondary_ammo[index]+PowerupsInMine[(int)type])>MaxPowerupsAllowed[(int)type])
2657                 {
2658                         if (MaxPowerupsAllowed[(int)type]-PowerupsInMine[(int)type]<0)
2659                                 Players[Player_num].secondary_ammo[index]=0;
2660                         else
2661                                 Players[Player_num].secondary_ammo[index]=(MaxPowerupsAllowed[(int)type]-PowerupsInMine[(int)type]);
2662
2663                         mprintf ((0,"Hey! I killed secondary type %d because PIM=%d MPA=%d\n",(int)type,PowerupsInMine[(int)type],MaxPowerupsAllowed[(int)type]));
2664                 }
2665         }
2666
2667         if (!(Game_mode & GM_HOARD))
2668                 Players[Player_num].secondary_ammo[2]*=4;
2669         Players[Player_num].secondary_ammo[7]*=4;
2670
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;
2674
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);
2678
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);
2682
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);
2686
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);
2690
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);
2694
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);
2698
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);
2702
2703         if (Game_mode & GM_CAPTURE)
2704         {
2705                 if (Players[Player_num].flags & PLAYER_FLAGS_FLAG)
2706                 {
2707                         if (get_team(Player_num)==TEAM_RED)
2708                                 flagtype=POW_FLAG_BLUE;
2709                         else
2710                                 flagtype=POW_FLAG_RED;
2711
2712                         if (PowerupsInMine[(int)flagtype]+1 > MaxPowerupsAllowed[(int)flagtype])
2713                                 Players[Player_num].flags&=(~PLAYER_FLAGS_FLAG);
2714                 }
2715         }
2716
2717 }
2718
2719 // adds players inventory to multi cap
2720
2721 void multi_adjust_cap_for_player (int pnum)
2722 {
2723         char type;
2724
2725         int index;
2726
2727         if (!(Game_mode & GM_NETWORK))
2728                 return;
2729
2730         for (index=0;index<MAX_PRIMARY_WEAPONS;index++)
2731         {
2732                 type=Primary_weapon_to_powerup[index];
2733                 if (Players[pnum].primary_weapon_flags & (1 << index))
2734                     MaxPowerupsAllowed[(int)type]++;
2735         }
2736
2737         for (index=0;index<MAX_SECONDARY_WEAPONS;index++)
2738         {
2739                 type=Secondary_weapon_to_powerup[index];
2740                 MaxPowerupsAllowed[(int)type]+=Players[pnum].secondary_ammo[index];
2741         }
2742
2743         if (Players[pnum].laser_level > MAX_LASER_LEVEL)
2744                 MaxPowerupsAllowed[POW_SUPER_LASER]++;
2745
2746         if (Players[pnum].flags & PLAYER_FLAGS_QUAD_LASERS)
2747                 MaxPowerupsAllowed[POW_QUAD_FIRE]++;
2748
2749         if (Players[pnum].flags & PLAYER_FLAGS_CLOAKED)
2750                 MaxPowerupsAllowed[POW_CLOAK]++;
2751
2752         if (Players[pnum].flags & PLAYER_FLAGS_MAP_ALL)
2753                 MaxPowerupsAllowed[POW_FULL_MAP]++;
2754
2755         if (Players[pnum].flags & PLAYER_FLAGS_AFTERBURNER)
2756                 MaxPowerupsAllowed[POW_AFTERBURNER]++;
2757
2758         if (Players[pnum].flags & PLAYER_FLAGS_AMMO_RACK)
2759                 MaxPowerupsAllowed[POW_AMMO_RACK]++;
2760
2761         if (Players[pnum].flags & PLAYER_FLAGS_CONVERTER)
2762                 MaxPowerupsAllowed[POW_CONVERTER]++;
2763
2764         if (Players[pnum].flags & PLAYER_FLAGS_HEADLIGHT)
2765                 MaxPowerupsAllowed[POW_HEADLIGHT]++;
2766 }
2767
2768 void multi_adjust_remote_cap (int pnum)
2769 {
2770         char type;
2771
2772         int index;
2773
2774         if (!(Game_mode & GM_NETWORK))
2775                 return;
2776
2777         for (index=0;index<MAX_PRIMARY_WEAPONS;index++)
2778         {
2779                 type=Primary_weapon_to_powerup[index];
2780                 if (Players[pnum].primary_weapon_flags & (1 << index))
2781                     PowerupsInMine[(int)type]++;
2782         }
2783
2784         for (index=0;index<MAX_SECONDARY_WEAPONS;index++)
2785         {
2786                 type=Secondary_weapon_to_powerup[index];
2787
2788                 if ((Game_mode & GM_HOARD) && index==2)
2789                         continue;
2790
2791                 if (index==2 || index==7) // PROX or SMARTMINES? Those bastards...
2792                         PowerupsInMine[(int)type]+=(Players[pnum].secondary_ammo[index]/4);
2793                 else
2794                         PowerupsInMine[(int)type]+=Players[pnum].secondary_ammo[index];
2795
2796         }
2797
2798         if (Players[pnum].laser_level > MAX_LASER_LEVEL)
2799                 PowerupsInMine[POW_SUPER_LASER]++;
2800
2801         if (Players[pnum].flags & PLAYER_FLAGS_QUAD_LASERS)
2802                 PowerupsInMine[POW_QUAD_FIRE]++;
2803
2804         if (Players[pnum].flags & PLAYER_FLAGS_CLOAKED)
2805                 PowerupsInMine[POW_CLOAK]++;
2806
2807         if (Players[pnum].flags & PLAYER_FLAGS_MAP_ALL)
2808                 PowerupsInMine[POW_FULL_MAP]++;
2809
2810         if (Players[pnum].flags & PLAYER_FLAGS_AFTERBURNER)
2811                 PowerupsInMine[POW_AFTERBURNER]++;
2812
2813         if (Players[pnum].flags & PLAYER_FLAGS_AMMO_RACK)
2814                 PowerupsInMine[POW_AMMO_RACK]++;
2815
2816         if (Players[pnum].flags & PLAYER_FLAGS_CONVERTER)
2817                 PowerupsInMine[POW_CONVERTER]++;
2818
2819         if (Players[pnum].flags & PLAYER_FLAGS_HEADLIGHT)
2820                 PowerupsInMine[POW_HEADLIGHT]++;
2821
2822 }
2823
2824 void
2825 multi_send_message(void)
2826 {
2827         int loc = 0;
2828         if (Network_message_reciever != -1)
2829         {
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;
2836         }
2837 }
2838
2839 void
2840 multi_send_reappear()
2841 {
2842         multibuf[0] = (char)MULTI_REAPPEAR;
2843         *(short *)(multibuf+1) = INTEL_SHORT(Players[Player_num].objnum);
2844
2845         multi_send_data(multibuf, 3, 2);
2846         PKilledFlags[Player_num]=0;
2847 }
2848
2849 void
2850 multi_send_position(int objnum)
2851 {
2852 #ifdef MACINTOSH
2853         shortpos sp;
2854 #endif
2855         int count=0;
2856
2857         if (Game_mode & GM_NETWORK) {
2858                 return;
2859         }
2860
2861         multibuf[count++] = (char)MULTI_POSITION;
2862 #ifndef MACINTOSH
2863         create_shortpos((shortpos *)(multibuf+count), Objects+objnum,0);
2864         count += sizeof(shortpos);
2865 #else
2866         create_shortpos(&sp, Objects+objnum, 1);
2867         memcpy(&(multibuf[count]), (ubyte *)(sp.bytemat), 9);
2868         count += 9;
2869         memcpy(&(multibuf[count]), (ubyte *)&(sp.xo), 14);
2870         count += 14;
2871 #endif
2872
2873         multi_send_data(multibuf, count, 0);
2874 }
2875
2876 void
2877 multi_send_kill(int objnum)
2878 {
2879         // I died, tell the world.
2880
2881         int killer_objnum;
2882         int count = 0;
2883
2884         Assert(Objects[objnum].id == Player_num);
2885         killer_objnum = Players[Player_num].killer_objnum;
2886
2887         multi_compute_kill(killer_objnum, objnum);
2888
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.
2893
2894                 s = (short)objnum_local_to_remote(killer_objnum, (byte *)&multibuf[count+2]);
2895                 *(short *)(multibuf+count) = INTEL_SHORT(s);
2896         }
2897         else
2898         {
2899                 *(short *)(multibuf+count) = INTEL_SHORT((short)-1);
2900                 multibuf[count+2] = (char)-1;
2901         }
2902         count += 3;
2903         multi_send_data(multibuf, count, 1);
2904
2905 #ifndef SHAREWARE
2906         if (Game_mode & GM_MULTI_ROBOTS)
2907                 multi_strip_robots(Player_num);
2908 #endif
2909 }
2910
2911 void
2912 multi_send_remobj(int objnum)
2913 {
2914         // Tell the other guy to remove an object from his list
2915
2916         byte obj_owner;
2917         short remote_objnum;
2918
2919         if (Objects[objnum].type==OBJ_POWERUP && (Game_mode & GM_NETWORK))
2920     {
2921                 if (PowerupsInMine[Objects[objnum].id] > 0)
2922                 {
2923                         PowerupsInMine[Objects[objnum].id]--;
2924                         if (multi_powerup_is_4pack (Objects[objnum].id))
2925                         {
2926                                 mprintf ((0,"Hey babe! Doing that wacky 4 pack stuff."));
2927
2928                                 if (PowerupsInMine[Objects[objnum].id-1]-4<0)
2929                                         PowerupsInMine[Objects[objnum].id-1]=0;
2930                                 else
2931                                         PowerupsInMine[Objects[objnum].id-1]-=4;
2932                         }
2933                 }
2934
2935         }
2936
2937         multibuf[0] = (char)MULTI_REMOVE_OBJECT;
2938
2939         remote_objnum = objnum_local_to_remote((short)objnum, &obj_owner);
2940
2941         *(short *)(multibuf+1) = INTEL_SHORT(remote_objnum); // Map to network objnums
2942
2943         multibuf[3] = obj_owner;
2944
2945         //      mprintf((0, "multi_send_remobj: %d = %d owner %d.\n", objnum, remote_objnum, obj_owner));
2946
2947         multi_send_data(multibuf, 4, 0);
2948
2949         if (Network_send_objects && network_objnum_is_past(objnum))
2950         {
2951                 mprintf((0, "Resetting object sync due to object removal.\n"));
2952                 Network_send_objnum = -1;
2953         }
2954 }
2955
2956 void
2957 multi_send_quit(int why)
2958 {
2959         // I am quitting the game, tell the other guy the bad news.
2960
2961         Assert (why == MULTI_QUIT);
2962
2963         multibuf[0] = (char)why;
2964         multibuf[1] = Player_num;
2965         multi_send_data(multibuf, 2, 1);
2966
2967 }
2968
2969 void
2970 multi_send_cloak(void)
2971 {
2972         // Broadcast a change in our pflags (made to support cloaking)
2973
2974         multibuf[0] = MULTI_CLOAK;
2975         multibuf[1] = (char)Player_num;
2976
2977         multi_send_data(multibuf, 2, 1);
2978
2979 #ifndef SHAREWARE
2980         if (Game_mode & GM_MULTI_ROBOTS)
2981                 multi_strip_robots(Player_num);
2982 #endif
2983 }
2984
2985 void
2986 multi_send_decloak(void)
2987 {
2988         // Broadcast a change in our pflags (made to support cloaking)
2989
2990         multibuf[0] = MULTI_DECLOAK;
2991         multibuf[1] = (char)Player_num;
2992
2993         multi_send_data(multibuf, 2, 1);
2994 }
2995
2996 void
2997 multi_send_door_open(int segnum, int side,ubyte flag)
2998 {
2999         // When we open a door make sure everyone else opens that door
3000
3001         multibuf[0] = MULTI_DOOR_OPEN;
3002         *(short *)(multibuf+1) = INTEL_SHORT( (short)segnum );
3003         multibuf[3] = (byte)side;
3004         multibuf[4] = flag;
3005
3006         multi_send_data(multibuf, 5, 2);
3007 }
3008
3009 extern void network_send_naked_packet (char *,short,int);
3010
3011 void
3012 multi_send_door_open_specific(int pnum,int segnum, int side,ubyte flag)
3013 {
3014         // For sending doors only to a specific person (usually when they're joining)
3015
3016         Assert (Game_mode & GM_NETWORK);
3017         //   Assert (pnum>-1 && pnum<N_players);
3018
3019         multibuf[0] = MULTI_DOOR_OPEN;
3020         *(short *)(multibuf+1) = INTEL_SHORT( (short)segnum );
3021         multibuf[3] = (byte)side;
3022         multibuf[4] = flag;
3023
3024         network_send_naked_packet(multibuf, 5, pnum);
3025 }
3026
3027 //
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.
3032
3033 void
3034 multi_send_create_explosion(int pnum)
3035 {
3036         // Send all data needed to create a remote explosion
3037
3038         int count = 0;
3039
3040         multibuf[count] = MULTI_CREATE_EXPLOSION;       count += 1;
3041         multibuf[count] = (byte)pnum;                                   count += 1;
3042         //                                                                                                      -----------
3043         //                                                                                                      Total size = 2
3044
3045         multi_send_data(multibuf, count, 0);
3046 }
3047
3048 void
3049 multi_send_controlcen_fire(vms_vector *to_goal, int best_gun_num, int objnum)
3050 {
3051 #ifdef MACINTOSH
3052         vms_vector swapped_vec;
3053 #endif
3054         int count = 0;
3055
3056         multibuf[count] = MULTI_CONTROLCEN_FIRE;                count +=  1;
3057 #ifndef MACINTOSH
3058         memcpy(multibuf+count, to_goal, 12);                    count += 12;
3059 #else
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;
3064 #endif
3065         multibuf[count] = (char)best_gun_num;                   count +=  1;
3066         *(short *)(multibuf+count) = INTEL_SHORT( (short)objnum );     count +=  2;
3067         //                                                                                                                      ------------
3068         //                                                                                                                      Total  = 16
3069         multi_send_data(multibuf, count, 0);
3070 }
3071
3072 void
3073 multi_send_create_powerup(int powerup_type, int segnum, int objnum, vms_vector *pos)
3074 {
3075         // Create a powerup on a remote machine, used for remote
3076         // placement of used powerups like missiles and cloaking
3077         // powerups.
3078
3079 #ifdef MACINTOSH
3080         vms_vector swapped_vec;
3081 #endif
3082         int count = 0;
3083
3084         if (Game_mode & GM_NETWORK)
3085                 PowerupsInMine[powerup_type]++;
3086
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;
3092 #ifndef MACINTOSH
3093         *(vms_vector *)(multibuf+count) = *pos;         count += sizeof(vms_vector);
3094 #else
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;
3099 #endif
3100         //                                                                                                            -----------
3101         //                                                                                                            Total =  19
3102         multi_send_data(multibuf, count, 2);
3103
3104         if (Network_send_objects && network_objnum_is_past(objnum))
3105         {
3106                 mprintf((0, "Resetting object sync due to powerup creation.\n"));
3107                 Network_send_objnum = -1;
3108         }
3109
3110         mprintf((0, "Creating powerup type %d in segment %i.\n", powerup_type, segnum));
3111         map_objnum_local_to_local(objnum);
3112 }
3113
3114 void
3115 multi_send_play_sound(int sound_num, fix volume)
3116 {
3117         int count = 0;
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;
3122         //                                                                                                         -----------
3123         //                                                                                                         Total = 4
3124         multi_send_data(multibuf, count, 0);
3125 }
3126
3127 void
3128 multi_send_audio_taunt(int taunt_num)
3129 {
3130         return; // Taken out, awaiting sounds..
3131
3132 #if 0
3133         int audio_taunts[4] = {
3134                 SOUND_CONTROL_CENTER_WARNING_SIREN,
3135                 SOUND_HOSTAGE_RESCUED,
3136                 SOUND_REFUEL_STATION_GIVING_FUEL,
3137                 SOUND_BAD_SELECTION
3138         };
3139
3140
3141         Assert(taunt_num >= 0);
3142         Assert(taunt_num < 4);
3143
3144         digi_play_sample( audio_taunts[taunt_num], F1_0 );
3145         multi_send_play_sound(audio_taunts[taunt_num], F1_0);
3146 #endif
3147 }
3148
3149 void
3150 multi_send_score(void)
3151 {
3152         // Send my current score to all other players so it will remain
3153         // synced.
3154         int count = 0;
3155
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);
3162         }
3163 }
3164
3165
3166 void
3167 multi_send_save_game(ubyte slot, uint id, char * desc)
3168 {
3169         int count = 0;
3170
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;
3175
3176         multi_send_data(multibuf, count, 2);
3177 }
3178
3179 void
3180 multi_send_restore_game(ubyte slot, uint id)
3181 {
3182         int count = 0;
3183
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
3187
3188         multi_send_data(multibuf, count, 2);
3189 }
3190
3191 void
3192 multi_send_netplayer_stats_request(ubyte player_num)
3193 {
3194         int count = 0;
3195
3196         multibuf[count] = MULTI_REQ_PLAYER;     count += 1;
3197         multibuf[count] = player_num;                   count += 1;
3198
3199         multi_send_data(multibuf, count, 0 );
3200 }
3201
3202 void
3203 multi_send_trigger(int triggernum)
3204 {
3205         // Send an even to trigger something in the mine
3206
3207         int count = 0;
3208
3209         multibuf[count] = MULTI_TRIGGER;                                count += 1;
3210         multibuf[count] = Player_num;                                   count += 1;
3211         multibuf[count] = (ubyte)triggernum;            count += 1;
3212
3213         mprintf ((0,"Sending trigger %d\n",triggernum));
3214
3215         multi_send_data(multibuf, count, 1);
3216         //multi_send_data(multibuf, count, 1); // twice?
3217 }
3218
3219 void
3220 multi_send_hostage_door_status(int wallnum)
3221 {
3222         // Tell the other player what the hit point status of a hostage door
3223         // should be
3224
3225         int count = 0;
3226
3227         Assert(Walls[wallnum].type == WALL_BLASTABLE);
3228
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;
3232
3233         //      mprintf((0, "Door %d damaged by %f points.\n", wallnum, f2fl(Walls[wallnum].hps)));
3234
3235         multi_send_data(multibuf, count, 0);
3236 }
3237
3238 extern int ConsistencyCount;
3239 extern int Drop_afterburner_blob_flag;
3240 int PhallicLimit=0;
3241 int PhallicMan=-1;
3242
3243 void multi_prep_level(void)
3244 {
3245         // Do any special stuff to the level required for serial games
3246         // before we begin playing in it.
3247
3248         // Player_num MUST be set before calling this procedure.
3249
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.
3253
3254         int i,ng=0;
3255         int     cloak_count, inv_count;
3256
3257         Assert(Game_mode & GM_MULTI);
3258
3259         Assert(NumNetPlayerPositions > 0);
3260
3261         PhallicLimit=0;
3262         PhallicMan=-1;
3263         Drop_afterburner_blob_flag=0;
3264         ConsistencyCount=0;
3265
3266         for (i=0;i<MAX_NUM_NET_PLAYERS;i++)
3267                 PKilledFlags[i]=0;
3268
3269         for (i = 0; i < NumNetPlayerPositions; i++)
3270         {
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;
3276         }
3277
3278 #ifndef SHAREWARE
3279         for (i = 0; i < MAX_ROBOTS_CONTROLLED; i++)
3280         {
3281                 robot_controlled[i] = -1;
3282                 robot_agitation[i] = 0;
3283                 robot_fired[i] = 0;
3284         }
3285 #endif
3286
3287         Viewer = ConsoleObject = &Objects[Players[Player_num].objnum];
3288
3289         if (!(Game_mode & GM_MULTI_COOP))
3290         {
3291                 multi_delete_extra_objects(); // Removes monsters from level
3292         }
3293
3294         if (Game_mode & GM_MULTI_ROBOTS)
3295         {
3296                 multi_set_robot_ai(); // Set all Robot AI to types we can cope with
3297         }
3298
3299         if (Game_mode & GM_NETWORK)
3300         {
3301                 multi_adjust_cap_for_player(Player_num);
3302                 multi_send_powerup_update();
3303                 ng=1;  // ng means network game
3304         }
3305         ng=1;
3306
3307         inv_count = 0;
3308         cloak_count = 0;
3309         for (i=0; i<=Highest_object_index; i++)
3310         {
3311                 int objnum;
3312
3313                 if ((Objects[i].type == OBJ_HOSTAGE) && !(Game_mode & GM_MULTI_COOP))
3314                 {
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);
3316                         obj_delete(i);
3317                         if (objnum != -1)
3318                         {
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);
3325                         }
3326                         continue;
3327                 }
3328
3329                 if (Objects[i].type == OBJ_POWERUP)
3330                 {
3331                         if (Objects[i].id == POW_EXTRA_LIFE)
3332                         {
3333                                 if (ng && !Netgame.DoInvulnerability)
3334                                 {
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;
3338                                 }
3339                                 else
3340                                 {
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;
3344                                 }
3345
3346                         }
3347
3348                         if (!(Game_mode & GM_MULTI_COOP))
3349                                 if ((Objects[i].id >= POW_KEY_BLUE) && (Objects[i].id <= POW_KEY_GOLD))
3350                                 {
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;
3354                                 }
3355
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;
3362                                 } else
3363                                         inv_count++;
3364                         }
3365
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;
3372                                 } else
3373                                         cloak_count++;
3374                         }
3375
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");
3382
3383                         if (Objects[i].id == POW_HELIX_WEAPON && ng && !Netgame.DoHelix)
3384                                 bash_to_shield (i,"helix");
3385
3386                         if (Objects[i].id == POW_MEGA_WEAPON && ng && !Netgame.DoMegas)
3387                                 bash_to_shield (i,"mega");
3388
3389                         if (Objects[i].id == POW_SMARTBOMB_WEAPON && ng && !Netgame.DoSmarts)
3390                                 bash_to_shield (i,"smartmissile");
3391
3392                         if (Objects[i].id == POW_GAUSS_WEAPON && ng && !Netgame.DoGauss)
3393                                 bash_to_shield (i,"gauss");
3394
3395                         if (Objects[i].id == POW_VULCAN_WEAPON && ng && !Netgame.DoVulcan)
3396                                 bash_to_shield (i,"vulcan");
3397
3398                         if (Objects[i].id == POW_PLASMA_WEAPON && ng && !Netgame.DoPlasma)
3399                                 bash_to_shield (i,"plasma");
3400
3401                         if (Objects[i].id == POW_OMEGA_WEAPON && ng && !Netgame.DoOmega)
3402                                 bash_to_shield (i,"omega");
3403
3404                         if (Objects[i].id == POW_SUPER_LASER && ng && !Netgame.DoSuperLaser)
3405                                 bash_to_shield (i,"superlaser");
3406
3407                         if (Objects[i].id == POW_PROXIMITY_WEAPON && ng && !Netgame.DoProximity)
3408                                 bash_to_shield (i,"proximity");
3409
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.
3413
3414                         if (Objects[i].id == POW_PROXIMITY_WEAPON && ng && (Game_mode & GM_HOARD))
3415                                 bash_to_shield (i,"proximity");
3416
3417                         if (Objects[i].id==POW_VULCAN_AMMO && ng && (!Netgame.DoVulcan && !Netgame.DoGauss))
3418                                 bash_to_shield(i,"vulcan ammo");
3419
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");
3456                 }
3457         }
3458
3459         if (Game_mode & GM_HOARD)
3460                 init_hoard_data();
3461
3462         if ((Game_mode & GM_CAPTURE) || (Game_mode & GM_HOARD))
3463                 multi_apply_goal_textures();
3464
3465         multi_sort_kill_list();
3466
3467         multi_show_player_list();
3468
3469         ConsoleObject->control_type = CT_FLYING;
3470
3471         reset_player_object();
3472
3473 }
3474
3475 int Goal_blue_segnum,Goal_red_segnum;
3476
3477 void multi_apply_goal_textures()
3478 {
3479         int             i,j,tex;
3480         segment *seg;
3481         segment2        *seg2;
3482
3483         for (i=0; i <= Highest_segment_index; i++)
3484         {
3485                 seg = &Segments[i];
3486                 seg2 = &Segment2s[i];
3487
3488                 if (seg2->special==SEGMENT_IS_GOAL_BLUE)
3489                 {
3490
3491                         Goal_blue_segnum = i;
3492
3493                         if (Game_mode & GM_HOARD)
3494                                 tex=find_goal_texture (TMI_GOAL_HOARD);
3495                         else
3496                                 tex=find_goal_texture (TMI_GOAL_BLUE);
3497
3498                         if (tex>-1)
3499                                 for (j = 0; j < 6; j++) {
3500                                         int v;
3501                                         seg->sides[j].tmap_num=tex;
3502                                         for (v=0;v<4;v++)
3503                                                 seg->sides[j].uvls[v].l = i2f(100);             //max out
3504                                 }
3505
3506                         seg2->static_light = i2f(100);  //make static light bright
3507
3508                 }
3509
3510                 if (seg2->special==SEGMENT_IS_GOAL_RED)
3511                 {
3512                         Goal_red_segnum = i;
3513
3514                         // Make both textures the same if Hoard mode
3515
3516                         if (Game_mode & GM_HOARD)
3517                                 tex=find_goal_texture (TMI_GOAL_HOARD);
3518                         else
3519                                 tex=find_goal_texture (TMI_GOAL_RED);
3520
3521                         if (tex>-1)
3522                                 for (j = 0; j < 6; j++) {
3523                                         int v;
3524                                         seg->sides[j].tmap_num=tex;
3525                                         for (v=0;v<4;v++)
3526                                                 seg->sides[j].uvls[v].l = i2f(1000);            //max out
3527                                 }
3528
3529                         seg2->static_light = i2f(100);  //make static light bright
3530                 }
3531         }
3532 }
3533 int find_goal_texture (ubyte t)
3534 {
3535         int i;
3536
3537         for (i=0;i<NumTextures;i++)
3538                 if (TmapInfo[i].flags & t)
3539                         return i;
3540
3541         Int3(); // Hey, there is no goal texture for this PIG!!!!
3542         // Edit bitmaps.tbl and designate two textures to be RED and BLUE
3543         // goal textures
3544         return (-1);
3545 }
3546
3547