2 * $Logfile: /Freespace2/code/Network/multi_respawn.cpp $
8 * Revision 1.1 2002/05/03 03:28:10 root
12 * 24 9/13/99 4:52p Dave
15 * 23 8/24/99 8:55p Dave
16 * Make sure nondimming pixels work properly in tech menu.
18 * 22 8/22/99 5:53p Dave
19 * Scoring fixes. Added self destruct key. Put callsigns in the logfile
20 * instead of ship designations for multiplayer players.
22 * 21 8/06/99 9:46p Dave
23 * Hopefully final changes for the demo.
25 * 20 8/06/99 2:44a Dave
26 * Make sure dead players who leave respawn AI.
28 * 19 8/03/99 11:02p Dave
29 * Maybe fixed sync problems in multiplayer.
31 * 18 6/16/99 6:33p Dave
32 * Fixed HUD text problem in multiplayer respawns.
34 * 17 4/02/99 4:11p Anoop
35 * Temporary fix for RFC code.
37 * 16 3/19/99 9:51a Dave
38 * Checkin to repair massive source safe crash. Also added support for
39 * pof-style nebulae, and some new weapons code.
41 * 16 3/12/99 3:13p Anoop
42 * Temporary fix to get by dumb TvT respawning problem.
44 * 15 3/10/99 6:50p Dave
45 * Changed the way we buffer packets for all clients. Optimized turret
46 * fired packets. Did some weapon firing optimizations.
48 * 14 3/09/99 6:24p Dave
49 * More work on object update revamping. Identified several sources of
50 * unnecessary bandwidth.
52 * 13 3/02/99 9:25p Dave
53 * Added a bunch of model rendering debug code. Started work on fixing
54 * beam weapon wacky firing.
56 * 12 3/01/99 7:39p Dave
57 * Added prioritizing ship respawns. Also fixed respawns in TvT so teams
58 * don't mix respawn points.
60 * 11 2/24/99 4:12p Anoop
61 * Switched TEAM_TRAITOR on respawn from TvT to dogfight mode.
63 * 10 2/24/99 3:57p Dave
64 * Fixed yet another TEAM_TRAITOR problem in non-dogfight multiplayer.
66 * 9 2/24/99 2:25p Dave
67 * Fixed up chatbox bugs. Made squad war reporting better. Fixed a respawn
68 * bug for dogfight more.
70 * 8 2/23/99 8:11p Dave
71 * Tidied up dogfight mode. Fixed TvT ship type problems for alpha wing.
72 * Small pass over todolist items.
74 * 7 2/23/99 2:29p Dave
75 * First run of oldschool dogfight mode.
77 * 6 2/11/99 3:08p Dave
78 * PXO refresh button. Very preliminary squad war support.
80 * 5 11/19/98 8:03a Dave
81 * Full support for D3-style reliable sockets. Revamped packet lag/loss
82 * system, made it receiver side and at the lowest possible level.
84 * 4 11/17/98 11:12a Dave
85 * Removed player identification by address. Now assign explicit id #'s.
87 * 3 11/05/98 5:55p Dave
88 * Big pass at reducing #includes
90 * 2 10/07/98 10:53a Dave
93 * 1 10/07/98 10:50a Dave
98 #include "systemvars.h"
101 #include "linklist.h"
102 #include "multimsgs.h"
103 #include "multiutil.h"
104 #include "missionweaponchoice.h"
105 #include "observer.h"
106 #include "gamesequence.h"
107 #include "hudconfig.h"
108 #include "hudobserver.h"
109 #include "hudmessage.h"
110 #include "multi_respawn.h"
111 #include "multi_observer.h"
112 #include "multi_team.h"
113 #include "hudwingmanstatus.h"
114 #include "missionparse.h"
115 #include "multiteamselect.h"
118 // ---------------------------------------------------------------------------------------
119 // MULTI RESPAWN DEFINES/VARS
122 // respawn notice codes
123 #define RESPAWN_BROADCAST 0x1 // server to clients - create this ship, and if you're the respawner, set it to be your object
124 #define RESPAWN_REQUEST 0x2 // client to server requesting a respawn (observer or normal)
125 #define AI_RESPAWN_NOTICE 0x3 // respawn an AI ship
127 // struct used to store AI objects which should get respawned
128 #define MAX_AI_RESPAWNS MAX_PLAYERS
129 #define AI_RESPAWN_TIME (7000) // should respawn 2.0 seconds after they die
131 typedef struct ai_respawn
133 p_object *pobjp; // parse object
134 int timestamp; // timestamp when this object should get respawned
137 ai_respawn Ai_respawns[MAX_AI_RESPAWNS]; // this is way too many, but I don't care
140 typedef struct respawn_point {
141 char ship_name[NAME_LENGTH+1]; // for priority respawns
142 vector pos; // respawn location (non-priority respawns)
143 int team; // team it belongs to
147 #define MAX_MULTI_RESPAWN_POINTS MAX_PLAYERS
148 respawn_point Multi_respawn_points[MAX_MULTI_RESPAWN_POINTS];
149 int Multi_respawn_point_count = 0;
150 int Multi_next_respawn_point = 0;
152 // priority ships for respawning
153 #define MAX_PRIORITY_POINTS 10
154 respawn_point Multi_respawn_priority_ships[MAX_PRIORITY_POINTS];
155 int Multi_respawn_priority_count = 0;
157 // ---------------------------------------------------------------------------------------
158 // MULTI RESPAWN FORWARD DECLARATIONS
161 // respawn the passed player with the passed ship object and weapon link settings
162 void multi_respawn_player(net_player *pl, char cur_primary_bank, char cur_secondary_bank, ubyte cur_link_status, ushort ship_ets, ushort net_sign, char *parse_name, vector *pos = NULL);
164 // respawn an AI ship
165 void multi_respawn_ai(p_object *pobjp);
167 // respawn myself as an observer
168 void multi_respawn_as_observer();
170 // send a request to the server saying I want to respawn (as an observer or not)
171 void multi_respawn_send_request(int as_observer);
173 // send a request to respawn an AI ship
174 void multi_respawn_send_ai_respawn(ushort net_signature);
176 // send a broadcast pack indicating a player has respawned
177 void multi_respawn_broadcast(net_player *player);
179 // <server> make the given player an observer
180 void multi_respawn_make_observer(net_player *pl);
182 // place a newly respawned object intelligently
183 void multi_respawn_place(object *new_obj, int team);
185 // respawn the server immediately
186 void multi_respawn_server();
189 // ---------------------------------------------------------------------------------------
190 // MULTI RESPAWN FUNCTIONS
193 // check to see if a net player needs to be respawned
194 void multi_respawn_check(object *objp)
197 net_player *pl = NULL;
200 // get the parse object since we are storing all data for the respawns in the parse object
201 pobjp = mission_parse_get_arrival_ship( objp->net_signature );
203 // the server should check against all players
204 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
205 player_index = multi_find_player_by_object(objp);
206 if(player_index != -1){
207 pl = &Net_players[player_index];
210 // clients should just check against themselves
211 else if(objp == Player_obj){
215 // if this ship isn't a player ship, then maybe it is an AI ship which should get respawed. Only respawn
216 // on the server, then send message to respawn on client.
219 // try and find the parse object with this net signature. If we found it, and it's a player start
220 // position, respawn it.
221 if ( Net_player->flags & NETINFO_FLAG_AM_MASTER ) {
226 // if we need to respawn this ai ship, add him to a list of ships to get respawned
227 if ( (pobjp->flags & P_OF_PLAYER_START) && (pobjp->respawn_count < Netgame.respawn) && !(Netgame.type_flags & NG_TYPE_DOGFIGHT) ){
230 for (i = 0; i < MAX_AI_RESPAWNS; i++ ) {
231 if ( Ai_respawns[i].pobjp == NULL ) {
232 Ai_respawns[i].pobjp = pobjp;
233 Ai_respawns[i].timestamp = timestamp(AI_RESPAWN_TIME);
237 Assert( i < MAX_AI_RESPAWNS );
243 // reset his datarate timestamp
245 pl->s_info.rate_stamp = timestamp( (int)(1000.0f / (float)OO_gran) );
248 Assert( pl != NULL );
249 Assert( pobjp ); // we have a player, and we should have a record of it.
251 // mark the player as in the state of respawning
252 if( (pobjp->respawn_count < Netgame.respawn) || (Netgame.type_flags & NG_TYPE_DOGFIGHT) ){
253 pl->flags |= NETINFO_FLAG_RESPAWNING;
255 // otherwise mark the player as being in limbo
257 pl->flags |= NETINFO_FLAG_LIMBO;
261 // notify of a player leaving
262 void multi_respawn_player_leave(net_player *pl)
268 if( MULTI_OBSERVER((*pl)) ){
271 if((Net_player == NULL) || !(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
274 if(pl->p_info.p_objp == NULL){
279 if((Game_mode & GM_MULTIPLAYER) && (Netgame.type_flags & NG_TYPE_DOGFIGHT)){
283 // if we need to respawn this ai ship, add him to a list of ships to get respawned
284 p_object *pobjp = pl->p_info.p_objp;
285 if ( (pobjp->flags & P_OF_PLAYER_START) && (pobjp->respawn_count < Netgame.respawn) ){
288 for (i = 0; i < MAX_AI_RESPAWNS; i++ ) {
289 if ( Ai_respawns[i].pobjp == NULL ) {
290 Ai_respawns[i].pobjp = pobjp;
291 Ai_respawns[i].timestamp = timestamp(AI_RESPAWN_TIME);
299 void multi_respawn_normal()
301 // make sure we should be respawning and _not_ as an observer
302 Assert((Net_player->flags & NETINFO_FLAG_RESPAWNING) && !(Net_player->flags & NETINFO_FLAG_LIMBO));
304 // server respawns immediately
305 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
306 multi_respawn_server();
308 // client sends a respawn request (multiple ones are ok if he clicks over and over)
309 multi_respawn_send_request(0);
313 // respawn as an observer
314 void multi_respawn_observer()
316 // make sure we should be respawning as an observer
317 Assert(!(Net_player->flags & NETINFO_FLAG_RESPAWNING) && (Net_player->flags & NETINFO_FLAG_LIMBO));
319 // respawn as an observer
320 multi_respawn_as_observer();
322 // clients should notify the server that they are doing so
323 if(!(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
324 multi_respawn_send_request(1);
327 // jump back into the game right away
328 gameseq_post_event(GS_EVENT_ENTER_GAME);
331 // server should check to see if any respawned players have run out of their invulnerability
332 void multi_respawn_handle_invul_players()
336 for(idx=0;idx<MAX_PLAYERS;idx++){
337 if(MULTI_CONNECTED(Net_players[idx]) && (Objects[Net_players[idx].player->objnum].flags & OF_INVULNERABLE)){
338 // make him normal (_non_ invulnerable) on either of 2 conditions :
339 // 1.) More than 5 seconds have passed
340 // 2.) He's fired either a primary or a secondary weapon
341 if( ((Net_players[idx].s_info.invul_timestamp != -1) && (timestamp_elapsed(Net_players[idx].s_info.invul_timestamp))) ||
342 ((Net_players[idx].player->ci.fire_primary_count > 0) || (Net_players[idx].player->ci.fire_secondary_count > 0)) ) {
343 objp = &Objects[Net_players[idx].player->objnum];
344 obj_set_flags(objp,objp->flags & ~(OF_INVULNERABLE));
350 // build a list of respawn points for the mission
351 void multi_respawn_build_points()
357 Multi_respawn_point_count = 0;
358 Multi_next_respawn_point = 0;
359 moveup = GET_FIRST(&Ship_obj_list);
360 while(moveup != END_OF_LIST(&Ship_obj_list)){
362 if(Objects[moveup->objnum].flags & (OF_PLAYER_SHIP | OF_COULD_BE_PLAYER)){
363 r = &Multi_respawn_points[Multi_respawn_point_count++];
365 r->pos = Objects[moveup->objnum].pos;
366 r->team = Ships[Objects[moveup->objnum].instance].team;
368 moveup = GET_NEXT(moveup);
371 // priority respawn points
372 Multi_respawn_priority_count = 0;
373 moveup = GET_FIRST(&Ship_obj_list);
374 while(moveup != END_OF_LIST(&Ship_obj_list)){
376 if((Ships[Objects[moveup->objnum].instance].respawn_priority > 0) && (Multi_respawn_priority_count < MAX_PRIORITY_POINTS)){
377 r = &Multi_respawn_priority_ships[Multi_respawn_priority_count++];
379 strcpy(r->ship_name, Ships[Objects[moveup->objnum].instance].ship_name);
380 r->team = Ships[Objects[moveup->objnum].instance].team;
382 moveup = GET_NEXT(moveup);
387 // ---------------------------------------------------------------------------------------
388 // MULTI RESPAWN FORWARD DECLARATIONS
391 void multi_respawn_wing_stuff(ship *shipp)
395 // deal with re-adding this ship to it's wing
396 Assert( shipp->wingnum != -1 );
397 wingp = &Wings[shipp->wingnum];
398 wingp->ship_index[wingp->current_count] = SHIP_INDEX(shipp);
399 wingp->current_count++;
401 hud_set_wingman_status_alive(shipp->wing_status_wing_index, shipp->wing_status_wing_pos);
404 int multi_respawn_common_stuff(p_object *pobjp)
406 int objnum, team, slot_index;
412 objnum = parse_create_object(pobjp);
413 Assert(objnum != -1);
414 objp = &Objects[objnum];
416 // get the team and slot
417 shipp = &Ships[objp->instance];
418 multi_ts_get_team_and_slot(shipp->ship_name, &team, &slot_index);
419 Assert( team != -1 );
420 Assert( slot_index != -1 );
422 // reset object update stuff
423 for(idx=0; idx<MAX_PLAYERS; idx++){
424 shipp->np_updates[idx].orient_chksum = 0;
425 shipp->np_updates[idx].pos_chksum = 0;
426 shipp->np_updates[idx].seq = 0;
427 shipp->np_updates[idx].status_update_stamp = -1;
428 shipp->np_updates[idx].subsys_update_stamp = -1;
429 shipp->np_updates[idx].update_stamp = -1;
432 // change the ship type and the weapons
433 change_ship_type(objp->instance, Wss_slots_teams[team][slot_index].ship_class);
434 wl_bash_ship_weapons(&shipp->weapons,&Wss_slots_teams[team][slot_index]);
435 multi_respawn_wing_stuff( shipp );
437 if(Netgame.type_flags & NG_TYPE_TEAM){
438 multi_team_mark_ship(&Ships[Objects[objnum].instance]);
441 pobjp->respawn_count++;
446 // respawn the passed player with the passed ship object and weapon link settings
447 void multi_respawn_player(net_player *pl, char cur_primary_bank, char cur_secondary_bank, ubyte cur_link_status, ushort ship_ets, ushort net_sig, char *parse_name, vector *pos)
454 // try and find the parse object
455 pobjp = mission_parse_get_arrival_ship(parse_name);
456 Assert(pobjp != NULL);
460 objnum = multi_respawn_common_stuff(pobjp);
462 Assert( objnum != -1 );
463 objp = &Objects[objnum];
464 shipp = &Ships[objp->instance];
466 // this is a player, so mark him as a player,
467 objp->flags |= OF_PLAYER_SHIP;
468 objp->flags &= ~OF_COULD_BE_PLAYER;
470 // server should mark this player as invulerable for a short time
471 if ( MULTIPLAYER_MASTER ) {
472 objp->flags |= OF_INVULNERABLE;
473 pl->s_info.invul_timestamp = timestamp(RESPAWN_INVUL_TIMESTAMP);
474 multi_respawn_place( objp, shipp->team );
477 // reset his datarate timestamp
479 pl->s_info.rate_stamp = timestamp( (int)(1000.0f / (float)OO_gran) );
481 // set some player information
482 pl->player->objnum = objnum;
483 if ( pl == Net_player ) {
484 // this is a hack to ensure that old (dead) player ships are destroyed, since at this point he's actually an OBJ_GHOST
485 Player_obj->flags |= OF_SHOULD_BE_DEAD;
486 obj_delete(OBJ_INDEX(Player_obj));
490 Player_ai = &Ai_info[Player_ship->ai_index];
492 // get rid of the annoying HUD dead message text.
493 HUD_init_fixed_text();
496 // clients bash net signature
497 if(!(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
498 objp->net_signature = net_sig;
501 // restore the correct weapon bank selections
502 shipp->weapons.current_primary_bank = (int)cur_primary_bank;
503 shipp->weapons.current_secondary_bank = (int)cur_secondary_bank;
504 if(cur_link_status & (1<<0)){
505 shipp->flags |= SF_PRIMARY_LINKED;
507 shipp->flags &= ~(SF_PRIMARY_LINKED);
509 if(cur_link_status & (1<<1)){
510 shipp->flags |= SF_SECONDARY_DUAL_FIRE;
512 shipp->flags &= ~(SF_SECONDARY_DUAL_FIRE);
515 Assert( ship_ets != 0 ); // find dave or allender
517 // restore the correct ets settings
518 shipp->shield_recharge_index = ((ship_ets & 0x0f00) >> 8);
520 shipp->weapon_recharge_index = ((ship_ets & 0x00f0) >> 4);
522 shipp->engine_recharge_index = (ship_ets & 0x000f);
524 // if this is a dogfight mission, make him TEAM_TRAITOR
525 if(Netgame.type_flags & NG_TYPE_DOGFIGHT){
526 shipp->team = TEAM_TRAITOR;
529 // maybe bash ship position
534 // unset his respawning flag
535 pl->flags &= ~(NETINFO_FLAG_RESPAWNING | NETINFO_FLAG_LIMBO);
537 // blast his control and button info clear
538 memset(&pl->player->bi, 0, sizeof(pl->player->bi));
539 memset(&pl->player->ci, 0, sizeof(pl->player->ci));
541 // if this is me, clear accum button info
542 if(pl == Net_player){
543 // clear multiplayer button info
544 extern button_info Multi_ship_status_bi;
545 memset(&Multi_ship_status_bi, 0, sizeof(button_info));
548 // notify other players of the respawn
549 if ( MULTIPLAYER_MASTER ){
550 multi_respawn_broadcast(pl);
554 // respawns an AI ship.
555 void multi_respawn_ai( p_object *pobjp )
560 // create the object and change the ship type
561 objnum = multi_respawn_common_stuff( pobjp );
562 objp = &Objects[objnum];
564 // be sure the the OF_PLAYER_SHIP flag is unset, and the could be player flag is set
565 obj_set_flags( objp, objp->flags | OF_COULD_BE_PLAYER );
566 objp->flags &= ~OF_PLAYER_SHIP;
569 // <server> make the given player an observer
570 void multi_respawn_make_observer(net_player *pl)
572 pl->flags |= (NETINFO_FLAG_OBSERVER | NETINFO_FLAG_OBS_PLAYER);
573 pl->flags &= ~(NETINFO_FLAG_RESPAWNING | NETINFO_FLAG_LIMBO);
575 // MWA 6/3/98 -- don't set to high -- let it default to whatever player chose
576 //pl->p_info.options.obj_update_level = OBJ_UPDATE_HIGH;
577 pl->last_heard_time = timer_get_fixed_seconds();
579 // reset the ping time for this player
580 multi_ping_reset(&pl->s_info.ping);
582 // timestamp his last_full_update_time
583 pl->s_info.last_full_update_time = timestamp(0);
585 // create an observer object for him
586 multi_obs_create_observer(pl);
589 // respawn myself as an observer
590 void multi_respawn_as_observer()
592 // configure the hud to be in "observer" mode
593 hud_config_as_observer(Player_ship,Player_ai);
595 // blow away my old player object
596 Player_obj->flags |= OF_SHOULD_BE_DEAD;
597 obj_delete(OBJ_INDEX(Player_obj));
599 // create a new shiny observer object for me
600 multi_obs_create_observer(Net_player);
602 // set my object to be the observer object
603 Player_obj = &Objects[Net_player->player->objnum];
604 Player_ship = &Hud_obs_ship;
605 Player_ai = &Hud_obs_ai;
607 // set some flags for myself
608 Net_player->flags |= NETINFO_FLAG_OBSERVER;
609 Net_player->flags |= NETINFO_FLAG_OBS_PLAYER;
610 Net_player->flags &= ~(NETINFO_FLAG_LIMBO);
612 // clear my auto-match speed flag
613 Net_player->player->flags &= ~(PLAYER_FLAGS_AUTO_MATCH_SPEED | PLAYER_FLAGS_MATCH_TARGET);
615 // reset the control info structure
616 memset(&Player->ci,0,sizeof(control_info));
619 // send a request to respawn an AI object
620 void multi_respawn_send_ai_respawn( ushort net_signature )
625 // build the header and add the opcode
626 BUILD_HEADER(RESPAWN_NOTICE);
627 val = AI_RESPAWN_NOTICE;
629 ADD_DATA( net_signature );
631 // broadcast the packet to all players
632 Assert(Net_player->flags & NETINFO_FLAG_AM_MASTER);
633 multi_io_send_to_all_reliable(data, packet_size);
636 // send a request to the server saying I want to respawn (as an observer or not)
637 void multi_respawn_send_request(int as_observer)
642 // build the header and add the opcode
643 BUILD_HEADER(RESPAWN_NOTICE);
644 val = RESPAWN_REQUEST;
647 // add a byte indicating whether or not we want to respawn as an observer
648 val = (ubyte)as_observer;
651 // send the request to the server
652 multi_io_send_reliable(Net_player, data, packet_size);
655 // send a broadcast pack indicating a player has respawned
656 void multi_respawn_broadcast(net_player *np)
663 // broadcast the packet to all players
664 Assert(Net_player->flags & NETINFO_FLAG_AM_MASTER);
666 signature = Objects[np->player->objnum].net_signature;
667 pos = Objects[np->player->objnum].pos;
669 // build the header and add the opcode
670 BUILD_HEADER(RESPAWN_NOTICE);
671 val = RESPAWN_BROADCAST;
674 // add the data for the respawn
677 ADD_DATA(np->player_id);
678 ADD_DATA(np->s_info.cur_primary_bank);
679 ADD_DATA(np->s_info.cur_secondary_bank);
680 ADD_DATA(np->s_info.cur_link_status);
681 ADD_DATA(np->s_info.ship_ets);
682 ADD_STRING(np->p_info.p_objp->name);
684 Assert( np->s_info.ship_ets != 0 ); // find dave or allender
686 multi_io_send_to_all_reliable(data, packet_size);
689 // process an incoming respawn info packet
690 void multi_respawn_process_packet(ubyte *data, header *hinfo)
692 ubyte code,cur_link_status;
693 char cur_primary_bank,cur_secondary_bank;
694 ushort net_sig,ship_ets;
698 char parse_name[1024] = "";
699 int offset = HEADER_LENGTH;
701 // determine who send the packet
702 player_index = find_player_id(hinfo->id);
703 if(player_index == -1){
704 nprintf(("Network","Couldn't find player for processing respawn packet!\n"));
710 // do something based upon the opcode
713 case AI_RESPAWN_NOTICE:
717 pobjp = mission_parse_get_arrival_ship( net_sig );
718 Assert( pobjp != NULL );
719 multi_respawn_ai( pobjp );
722 case RESPAWN_BROADCAST:
723 // get the respawn data
727 GET_DATA(cur_primary_bank);
728 GET_DATA(cur_secondary_bank);
729 GET_DATA(cur_link_status);
731 GET_STRING(parse_name);
732 player_index = find_player_id(player_id);
733 if(player_index == -1){
734 nprintf(("Network","Couldn't find player to respawn!\n"));
738 // create the ship and assign its position, net_signature, and class
739 // respawn the player
740 multi_respawn_player(&Net_players[player_index], cur_primary_bank, cur_secondary_bank, cur_link_status, ship_ets, net_sig, parse_name, &v);
742 // if this is for me, I should jump back into gameplay
743 if(&Net_players[player_index] == Net_player){
744 extern int Player_multi_died_check;
745 Player_multi_died_check = -1;
747 gameseq_post_event(GS_EVENT_ENTER_GAME);
751 case RESPAWN_REQUEST:
752 // determine whether he wants to respawn as an observer or not
755 nprintf(("Network","Received respawn request\n"));
756 if(player_index == -1){
757 nprintf(("Network","Received respawn request from unknown player!\n"));
761 // make sure he's not making an invalid request
762 if((code == 0) && !(Net_players[player_index].flags & NETINFO_FLAG_RESPAWNING)){
763 nprintf(("Network","Received respawn request from player who shouldn't be respawning!\n"));
766 } else if((code == 1) && !(Net_players[player_index].flags & NETINFO_FLAG_LIMBO)){
767 nprintf(("Network","Received respawn observer request from a player who shouldn't be respawning as an observer!\n"));
772 // otherwise perform the operation
773 // respawn the guy as an observer
775 multi_respawn_make_observer(&Net_players[player_index]);
777 // respawn him as normal
779 // create his new ship, and change him from respawning to respawned
780 Assert(Net_players[player_index].p_info.p_objp != NULL);
781 if(Net_players[player_index].p_info.p_objp != NULL){
782 multi_respawn_player(&Net_players[player_index], Net_players[player_index].s_info.cur_primary_bank, Net_players[player_index].s_info.cur_secondary_bank,Net_players[player_index].s_info.cur_link_status, Net_players[player_index].s_info.ship_ets, 0, Net_players[player_index].p_info.p_objp->name);
791 // respawn the server immediately
792 void multi_respawn_server()
794 Assert(Net_player->flags & NETINFO_FLAG_AM_MASTER);
797 multi_respawn_player(Net_player, Net_player->s_info.cur_primary_bank, Net_player->s_info.cur_secondary_bank, Net_player->s_info.cur_link_status, Net_player->s_info.ship_ets, 0, Net_player->p_info.p_objp->name);
799 // jump back into the game
800 gameseq_post_event(GS_EVENT_ENTER_GAME);
803 // level init for respawn stuff
804 void multi_respawn_init()
808 for (i = 0; i < MAX_AI_RESPAWNS; i++ ) {
809 Ai_respawns[i].pobjp = NULL;
810 Ai_respawns[i].timestamp = timestamp(-1);
814 // function to detect whether or not we have AI ships to respawn this frame
815 void multi_respawn_check_ai()
819 for (i = 0; i < MAX_AI_RESPAWNS; i++ ) {
820 if ( Ai_respawns[i].pobjp != NULL ) {
821 if ( timestamp_elapsed(Ai_respawns[i].timestamp) ) {
823 // be sure that ship is actually gone before respawning it.
824 if ( ship_name_lookup(Ai_respawns[i].pobjp->name) != -1 ) {
825 Ai_respawns[i].timestamp = timestamp(1000);
827 multi_respawn_ai( Ai_respawns[i].pobjp );
828 multi_respawn_send_ai_respawn( Ai_respawns[i].pobjp->net_signature );
829 Ai_respawns[i].pobjp = NULL;
830 Ai_respawns[i].timestamp = timestamp(-1);
839 // this is a completely off the cuff way of doing things. Feel free to find a better way.
841 // 1. Take the average vector position of all the ships in the game
842 // 2. Check to make sure we aren't within the radius of any of the ships in the game
843 // a.) If we are, move away along the vector between the two ships (by the radius of the ship it collided with)
846 #define MOVE_AWAY() { vector away; vm_vec_sub(&away,&new_obj->pos,&hit_check->pos); \
847 vm_vec_normalize_quick(&away); vm_vec_scale(&away,hit_check->radius+hit_check->radius); \
848 vm_vec_add2(&new_obj->pos,&away); }
850 #define WITHIN_RADIUS() { float dist; dist=vm_vec_dist(&new_obj->pos,&hit_check->pos); \
851 if(dist <= hit_check->radius) collided = 1; }
854 #define WITHIN_BBOX() do { \
855 float scale = 2.0f; \
856 polymodel *pm = model_get(s_check->modelnum); \
859 vector temp = new_obj->pos; \
861 vm_vec_sub2(&temp, &hit_check->pos); \
862 vm_vec_rotate(&gpos, &temp, &hit_check->orient); \
863 if((gpos.x >= pm->mins.x * scale) && (gpos.y >= pm->mins.y * scale) && (gpos.z >= pm->mins.z * scale) && (gpos.x <= pm->maxs.x * scale) && (gpos.y <= pm->maxs.y * scale) && (gpos.z <= pm->maxs.z * scale)) { \
869 #define MOVE_AWAY_BBOX() do { \
870 polymodel *pm = model_get(s_check->modelnum); \
872 switch((int)frand_range(0.0f, 3.9f)){ \
874 new_obj->pos.x += 200.0f; \
877 new_obj->pos.x -= 200.0f; \
880 new_obj->pos.y += 200.0f; \
883 new_obj->pos.y -= 200.0f; \
886 new_obj->pos.z -= 200.0f; \
892 void multi_respawn_place(object *new_obj, int team)
897 object *pri_obj = NULL;
899 int collided, idx, lookup;
901 // first determine if there are any appropriate priority ships to use
904 for(idx=0; idx<Multi_respawn_priority_count; idx++){
905 // all relevant ships
906 if((Multi_respawn_priority_ships[idx].team == team) || !(Netgame.type_flags & NG_TYPE_TEAM)){
908 lookup = ship_name_lookup(Multi_respawn_priority_ships[idx].ship_name);
909 if( (lookup >= 0) && ((pri == NULL) || (Ships[lookup].respawn_priority > pri->respawn_priority)) && (Ships[lookup].objnum >= 0) && (Ships[lookup].objnum < MAX_OBJECTS)){
910 pri = &Ships[lookup];
911 pri_obj = &Objects[Ships[lookup].objnum];
916 // if we have a relevant respawn ship
917 if((pri != NULL) && (pri_obj != NULL)){
918 // pick a point just outside his bounding box
919 polymodel *pm = model_get(pri->modelnum);
921 // hmm, ugly. Pick a point 2000 meters to the y direction
923 vm_vec_scale_add(&new_obj->pos, &pri_obj->pos, &pri_obj->orient.rvec, 2000.0f);
925 // pick a random direction
926 int d = (int)frand_range(0.0f, 5.9f);
929 vm_vec_scale_add(&new_obj->pos, &pri_obj->pos, &pri_obj->orient.rvec, (pm->maxs.x - pm->mins.x));
933 vm_vec_scale_add(&new_obj->pos, &pri_obj->pos, &pri_obj->orient.rvec, -(pm->maxs.x - pm->mins.x));
937 vm_vec_scale_add(&new_obj->pos, &pri_obj->pos, &pri_obj->orient.uvec, (pm->maxs.y - pm->mins.y));
941 vm_vec_scale_add(&new_obj->pos, &pri_obj->pos, &pri_obj->orient.uvec, -(pm->maxs.y - pm->mins.y));
945 vm_vec_scale_add(&new_obj->pos, &pri_obj->pos, &pri_obj->orient.fvec, (pm->maxs.z - pm->mins.z));
949 vm_vec_scale_add(&new_obj->pos, &pri_obj->pos, &pri_obj->orient.fvec, -(pm->maxs.z - pm->mins.z));
953 vm_vec_scale_add(&new_obj->pos, &pri_obj->pos, &pri_obj->orient.uvec, -(pm->maxs.y - pm->mins.y));
958 // otherwise, resort to plain respawn points
960 Assert(Multi_respawn_point_count > 0);
962 // get the next appropriate respawn point by team
965 while(!lookup && (count < 13)){
966 if((team == TEAM_TRAITOR) || (team == Multi_respawn_points[Multi_next_respawn_point].team)){
972 if(Multi_next_respawn_point >= (Multi_respawn_point_count-1)){
973 Multi_next_respawn_point = 0;
975 Multi_next_respawn_point++;
983 new_obj->pos = Multi_respawn_points[Multi_next_respawn_point].pos;
986 // now make sure we're not colliding with anyone
989 moveup = GET_FIRST(&Ship_obj_list);
990 while(moveup!=END_OF_LIST(&Ship_obj_list)){
991 // don't check the new_obj itself!!
992 if(Objects[moveup->objnum].net_signature != new_obj->net_signature){
993 hit_check = &Objects[moveup->objnum];
994 Assert(hit_check->type == OBJ_SHIP);
995 Assert(hit_check->instance >= 0);
996 if((hit_check->type != OBJ_SHIP) || (hit_check->instance < 0)){
999 s_check = &Ships[hit_check->instance];
1001 // just to make sure we don't get any strange magnitude errors
1002 if(vm_vec_same(&hit_check->pos, &new_obj->pos)){
1003 new_obj->pos.x += 1.0f;
1013 moveup = GET_NEXT(moveup);