2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/Network/multi_ingame.cpp $
16 * Revision 1.4 2003/08/03 16:10:29 taylor
17 * cleanup; compile warning fixes
19 * Revision 1.3 2002/06/09 04:41:23 relnev
20 * added copyright header
22 * Revision 1.2 2002/06/02 04:26:34 relnev
25 * Revision 1.1.1.1 2002/05/03 03:28:10 root
29 * 20 8/03/99 11:02p Dave
30 * Maybe fixed sync problems in multiplayer.
32 * 19 7/30/99 7:01p Dave
33 * Dogfight escort gauge. Fixed up laser rendering in Glide.
35 * 18 7/28/99 5:33p Dave
36 * Nailed the missing stats bug to the wall. Problem was optimized build
37 * and using GET_DATA() with array elements. BLECH.
39 * 17 7/26/99 6:07p Dave
40 * Removed some warnings.
42 * 16 7/26/99 5:50p Dave
43 * Revised ingame join. Better? We'll see....
45 * 15 7/24/99 5:48p Jefff
46 * converted to new UI stuff -- added 1024 support
48 * 14 7/08/99 10:53a Dave
49 * New multiplayer interpolation scheme. Not 100% done yet, but still
50 * better than the old way.
52 * 13 4/21/99 6:15p Dave
53 * Did some serious housecleaning in the beam code. Made it ready to go
54 * for anti-fighter "pulse" weapons. Fixed collision pair creation. Added
55 * a handy macro for recalculating collision pairs for a given object.
57 * 12 3/10/99 6:50p Dave
58 * Changed the way we buffer packets for all clients. Optimized turret
59 * fired packets. Did some weapon firing optimizations.
61 * 11 3/09/99 6:24p Dave
62 * More work on object update revamping. Identified several sources of
63 * unnecessary bandwidth.
65 * 10 3/08/99 7:03p Dave
66 * First run of new object update system. Looks very promising.
68 * 9 3/01/99 7:39p Dave
69 * Added prioritizing ship respawns. Also fixed respawns in TvT so teams
70 * don't mix respawn points.
72 * 8 1/30/99 5:08p Dave
73 * More new hi-res stuff.Support for nice D3D textures.
75 * 7 1/27/99 9:56a Dave
76 * Temporary checkin of beam weapons for Dan to make cool sounds.
78 * 6 11/19/98 8:03a Dave
79 * Full support for D3-style reliable sockets. Revamped packet lag/loss
80 * system, made it receiver side and at the lowest possible level.
82 * 5 11/17/98 11:12a Dave
83 * Removed player identification by address. Now assign explicit id #'s.
85 * 4 11/05/98 5:55p Dave
86 * Big pass at reducing #includes
88 * 3 10/13/98 9:29a Dave
89 * Started neatening up freespace.h. Many variables renamed and
90 * reorganized. Added AlphaColors.[h,cpp]
92 * 2 10/07/98 10:53a Dave
95 * 1 10/07/98 10:50a Dave
97 * 83 9/18/98 4:54p Dave
98 * Fixed ingame ship select icon problem.
100 * 82 9/18/98 4:23p Dave
101 * Reversed the logic on a bogus assert.
103 * 81 9/18/98 3:13p Allender
104 * actually delete ships from wings when ingame joining. Shoudl get over
105 * problem were too many ships are presend in the mission since we don't
106 * delete unused ships until after ingame join is completed
108 * 80 9/15/98 1:59p Dave
109 * Fixed bonehead mistake calling multi_endgame_ending()
111 * 79 9/11/98 4:14p Dave
112 * Fixed file checksumming of < file_size. Put in more verbose kicking and
113 * PXO stats store reporting.
115 * 78 9/11/98 2:10p Allender
116 * base temporary parse_object's ai_goals to -1 so that we don't try and
117 * free sepxressions that shouldn't be freed
119 * 77 8/07/98 10:16a Allender
120 * use obj_set_flags for the COULD_BE_PLAYER flag
122 * 76 7/24/98 9:27a Dave
123 * Tidied up endgame sequencing by removing several old flags and
124 * standardizing _all_ endgame stuff with a single function call.
126 * 75 6/30/98 2:17p Dave
127 * Revised object update system. Removed updates for all weapons. Put
128 * button info back into control info packet.
130 * 74 6/13/98 6:01p Hoffoss
131 * Externalized all new (or forgot to be added) strings to all the code.
133 * 73 6/13/98 3:18p Hoffoss
134 * NOX()ed out a bunch of strings that shouldn't be translated.
136 * 72 6/10/98 2:56p Dave
137 * Substantial changes to reduce bandwidth and latency problems.
139 * 71 6/04/98 11:46a Dave
140 * Drastically reduce size/rate of client control info update packets. Put
141 * in rate limiting for object updating from server.
143 * 70 5/26/98 11:54a Allender
144 * fix multiplayer problems and sexpression crash
146 * 69 5/25/98 1:33a Allender
147 * fixed timestamp problem for client update packets, small fix for ingame
150 * 68 5/24/98 9:17p Allender
151 * commented out test code to help rectify bogus player objects when
154 * 67 5/23/98 3:16p Allender
155 * work on object update packet optimizations (a new updating system).
156 * Don't allow medals/promotions/badges when playing singple player
157 * missions through the simulator
159 * 66 5/22/98 9:35p Dave
160 * Put in channel based support for PXO. Put in "shutdown" button for
161 * standalone. UI tweaks for TvT
163 * 65 5/21/98 10:03p Allender
164 * add secondary ammo counts to ingame join packets
166 * 64 5/21/98 1:52a Dave
167 * Remove obsolete command line functions. Reduce shield explosion packets
168 * drastically. Tweak PXO screen even more. Fix file xfer system so that
169 * we can guarantee file uniqueness.
171 * 63 5/21/98 12:14a Allender
172 * fix ingame join problems
174 * 62 5/20/98 3:25p Allender
175 * ingame join changes (which probably won't make the final version).
176 * Added RAS code into psnet
178 * 61 5/19/98 11:36p Allender
179 * fixed very nasty mask problem with ingame joiner marking player objects
180 * incorrectly. Named ingame joiner ship and observer ship unique names
182 * 60 5/19/98 8:35p Dave
183 * Revamp PXO channel listing system. Send campaign goals/events to
184 * clients for evaluation. Made lock button pressable on all screens.
186 * 59 5/18/98 12:41a Allender
187 * fixed subsystem problems on clients (i.e. not reporting properly on
188 * damage indicator). Fixed ingame join problem with respawns. minor
191 * 58 5/15/98 4:12p Allender
192 * removed redbook code. Put back in ingame join timer. Major fixups for
193 * stats in multiplayer. Pass correct score, medals, etc when leaving
194 * game. Be sure clients display medals, badges, etc.
196 * 57 5/15/98 1:44p Allender
197 * initialize hotkeys when entering the mission ingame joining
199 * 56 5/11/98 4:33p Allender
200 * fixed ingame join problems -- started to work on new object updating
201 * code (currently ifdef'ed out)
203 * 55 5/09/98 4:31p Chad
204 * Fixed weapon recharge rate problem and fixed weapon link status problem
205 * for ingame joiners.
207 * 54 5/08/98 11:21a Allender
208 * fix ingame join trouble. Small messaging fix. Enable collisions for
211 * 53 5/03/98 7:04p Dave
212 * Make team vs. team work mores smoothly with standalone. Change how host
213 * interacts with standalone for picking missions. Put in a time limit for
214 * ingame join ship select. Fix ingame join ship select screen for Vasudan
217 * 52 5/03/98 2:52p Dave
218 * Removed multiplayer furball mode.
220 * 51 5/02/98 1:47a Dave
221 * Make sure ingame joiners know how many respawns they have left. Tidy up
222 * some multiui stuff.
224 * 50 5/01/98 4:11p Comet
225 * Fixed ship_ets bug. I think.
227 * 49 4/30/98 12:49a Allender
228 * change ship type and weapons of any player wing ship, not just ones
229 * that players currently occupy
231 * 48 4/29/98 9:36p Allender
232 * ingame join tweaks. added network message for countermeasures
234 * 47 4/29/98 12:28p Chad
235 * set packet size when selecting a player's ingame choice
237 * 46 4/25/98 2:02p Dave
238 * Put in multiplayer context help screens. Reworked ingame join ship
239 * select screen. Fixed places where network timestamps get hosed.
241 * 45 4/23/98 11:52p Allender
242 * make homing weapons send their homing object. Fixed ingame joiners so
243 * they bash ship types and weapons correctly when joining
245 * 44 4/23/98 1:49a Allender
246 * major rearm/repair fixes for multiplayer. Fixed respawning of AI ships
247 * to not respawn until 5 seconds after they die. Send escort information
250 * 43 4/22/98 5:53p Dave
251 * Large reworking of endgame sequencing. Updated multi host options
252 * screen for new artwork. Put in checks for host or team captains leaving
255 * 42 4/22/98 4:59p Allender
256 * new multiplayer dead popup. big changes to the comm menu system for
257 * team vs. team. Start of debriefing stuff for team vs. team Make form
258 * on my wing work with individual ships who have high priority orders
260 * 41 4/21/98 11:56p Dave
261 * Put in player deaths statskeeping. Use arrow keys in the ingame join
262 * ship select screen. Don't quit the game if in the debriefing and server
265 * 40 4/20/98 12:40a Allender
266 * fixed nasty problem where network read code was not reentrant. minor
267 * UI tweaks. ingame joiners now get netgame info correctly.
269 * 39 4/07/98 5:42p Dave
270 * Put in support for ui display of voice system status (recording,
271 * playing back, etc). Make sure main hall music is stopped before
272 * entering a multiplayer game via ingame join.
274 * 38 4/06/98 6:47p Allender
275 * be sure that ingame joiner has reasonable current primary and secondary
278 * 37 4/06/98 12:33a Allender
279 * ingame joiners need to unmark all player ships as could be players
280 * before getting ship information from host. Don't send count with
281 * countermeasure fired packet
283 * 36 4/04/98 4:22p Dave
284 * First rev of UDP reliable sockets is done. Seems to work well if not
287 * 35 4/04/98 3:55p Allender
288 * made ingame join send packet to all other clients in the game when in
289 * game joiner selects his ship
291 * 34 4/03/98 1:03a Dave
292 * First pass at unreliable guaranteed delivery packets.
294 * 33 4/02/98 5:36p John
295 * Made the level paging occur at the same time as the level is read in.
297 * 32 3/31/98 4:03p Allender
298 * some ingame join fixed -- make sure ingame joiners have parse objects
299 * for all other players
301 * 31 3/24/98 5:12p Allender
302 * ingame join packet sequencing
313 #include "multiutil.h"
314 #include "multimsgs.h"
316 #include "missionparse.h"
317 #include "freespace.h"
318 #include "gamesequence.h"
323 #include "linklist.h"
324 #include "multi_ingame.h"
325 #include "missionscreencommon.h"
329 #include "multi_observer.h"
330 #include "multi_xfer.h"
331 #include "multi_kick.h"
332 #include "missiongoals.h"
333 #include "mainhallmenu.h"
335 #include "multiteamselect.h"
336 #include "missionweaponchoice.h"
337 #include "multi_endgame.h"
338 #include "hudescort.h"
339 #include "hudshield.h"
340 #include "objcollide.h"
341 #include "missionhotkey.h"
342 #include "multi_campaign.h"
343 #include "multi_obj.h"
344 #include "alphacolors.h"
347 // --------------------------------------------------------------------------------------------------
348 // DAVE's BIGASS INGAME JOIN WARNING/DISCLAIMER
350 // Ingame joining is another delicate system. Although not as delicate as server transfer, it will
351 // help to take as many precautions as possible when handling ingame joins. Please be sure to follow
352 // all the same rules as explained in multi_strans.h
354 // --------------------------------------------------------------------------------------------------
356 // --------------------------------------------------------------------------------------------------
357 // INGAME JOIN DESCRIPTION
359 // 1.) Joiner sends a JOIN packet to the server
360 // 2.) If the server accepts him, he receives an ACCEPT packet in return
361 // 3.) The client then moves into the INGAME_SYNC state to begin receiving data from the server
362 // 4.) The first thing he does on this screen is send his filesig packet to the server. At which
363 // point the server will either let him in or deny him. There are no file transfers ingame.
364 // 5.) The server calls multi_handle_ingame_joiners() once per frame, through multi_do_frame()
365 // 6.) After verifiying or kicking the player because of his file signature, the server tells the
366 // player to load the mission
367 // 7.) When the mission is loaded, the server, sends a netgame update to the client
368 // 8.) Without waiting, the server then begins sending data ship packets to the player
369 // 9.) Upon confirmation of receiving these packets, the server sends wing data packets
370 // 10.) Upon completion of this, the server sends respawn point packets
371 // 11.) Upon completion of this, the server sends a post briefing data block packet containing ship class and
372 // weapon information
373 // 12.) After this, the server sends a player settings packet (to all players for good measure)
374 // 13.) At this point, the server sends a jump into mission packet
375 // 14.) Upon receipt of this packet, the client moves into the ingame ship select state
376 // 15.) The first thing the client does in this state is load the mission data (textures, etc)
377 // 16.) The player is presented with a list of ships he can choose from. He selects one and sends
378 // an INGAME_SHIP_REQUEST to the server.
379 // 17.) The server checks to see if this request is acceptable and sends an INGAME_SHIP_REQUEST back
380 // with the appropriate data.
381 // 18.) If the client received an affirmative, he selects the ship and jumps into the mission, otherwise
382 // he removes it from the list and tries for another ship
383 // --------------------------------------------------------------------------------------------------
386 LOCAL int Ingame_ships_deleted = 0;
387 //LOCAL int Ingame_ships_to_delete[MAX_SHIPS]; // no longer used
390 // --------------------------------------------------------------------------------------------------
391 // INGAME JOIN FORWARD DECLARATIONS
394 void multi_ingame_send_ship_update(net_player *p);
396 void multi_ingame_join_check_buttons();
397 void multi_ingame_join_button_pressed(int n);
401 // --------------------------------------------------------------------------------------------------
402 // INGAME JOIN COMMON DEFINITIONS
406 // --------------------------------------------------------------------------------------------------
407 // INGAME JOIN SERVER FUNCTIONS
410 // called on the server to process ingame joiners and move them through the motions of ingame joining
411 void multi_handle_ingame_joiners()
415 Assert( MULTIPLAYER_MASTER );
417 // if my ingame joining flag isn't set, then don't do anything.
418 if ( !(Netgame.flags & NG_FLAG_INGAME_JOINING) ){
422 // traverse through all the players
423 for(idx = 0; idx<MAX_PLAYERS; idx++){
424 // only process ingame joiners
425 if( !(Net_players[idx].flags & NETINFO_FLAG_RELIABLE_CONNECTED) || !(Net_players[idx].flags & NETINFO_FLAG_INGAME_JOIN)){
429 // if we're waiting for players to receive files, then check on their status
430 if(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_FILE_XFER){
431 switch(multi_xfer_get_status(Net_players[idx].s_info.xfer_handle)){
432 // if it has successfully completed, set his ok flag
433 case MULTI_XFER_SUCCESS :
435 Net_players[idx].flags |= NETINFO_FLAG_MISSION_OK;
437 // release the xfer instance handle
438 multi_xfer_release_handle(Net_players[idx].s_info.xfer_handle);
439 Net_players[idx].s_info.xfer_handle = -1;
441 // if it has failed or timed-out, kick the player
442 case MULTI_XFER_TIMEDOUT:
443 case MULTI_XFER_FAIL:
444 // release the xfer handle
445 multi_xfer_release_handle(Net_players[idx].s_info.xfer_handle);
446 Net_players[idx].s_info.xfer_handle = -1;
449 multi_kick_player(idx, 0, KICK_REASON_BAD_XFER);
454 // if the player has verified his file signature then send him the packet to load the mission and mark this down
455 if((Net_players[idx].flags & NETINFO_FLAG_MISSION_OK) && !(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_LOADING_MISSION)){
456 // send the netgame update here as well
457 send_netgame_update_packet(&Net_players[idx]);
458 send_netplayer_update_packet(&Net_players[idx]);
460 // send the packet and mark it down
461 send_netplayer_load_packet(&Net_players[idx]);
462 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_LOADING_MISSION;
465 // once he has finished loading the mission, start sending him ship data packets and mark this down
466 if((Net_players[idx].state == NETPLAYER_STATE_MISSION_LOADED) && !(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_SENDING_SHIPS)){
469 // send the packet and mark it down
470 for (i = 0; i < Num_teams; i++ ) {
471 if(Game_mode & GM_STANDALONE_SERVER){
472 send_wss_slots_data_packet(i, 1, &Net_players[idx], 0);
474 send_wss_slots_data_packet(i, 1, &Net_players[idx]);
478 // mark the netgame as a critical stage in ingame joining so that I don't evaluate mission event/
479 // goals, ship arrivals, etc.
480 Netgame.flags |= NG_FLAG_INGAME_JOINING_CRITICAL;
482 // send the packet and mark it down
483 send_ingame_ships_packet(&Net_players[idx]);
484 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_SENDING_SHIPS;
487 // once he has finished receiving the ship data, start sending him wing data and mark this down
489 if((Net_players[idx].state == NETPLAYER_STATE_INGAME_SHIPS) && !(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_SENDING_WINGS)){
490 // setup the list of wings to send
491 Net_players[idx].s_info.wing_index = 0;
492 Net_players[idx].s_info.wing_index_backup = 0;
494 // send the packet and mark it down
495 send_ingame_wings_packet(&Net_players[idx]);
496 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_SENDING_WINGS;
500 // once he has received the respawn packet, send him the player settings for all the players in the game and mark this down
501 if((Net_players[idx].state == NETPLAYER_STATE_INGAME_SHIPS) && !(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_SENDING_POST)){
502 // reset the critical ingame joining flag so that I as server, will start evaluating mission
504 Netgame.flags &= ~NG_FLAG_INGAME_JOINING_CRITICAL;
506 // send the packet and mark it down
507 if(Game_mode & GM_STANDALONE_SERVER){
508 send_post_sync_data_packet(&Net_players[idx],0);
510 send_post_sync_data_packet(&Net_players[idx]);
512 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_SENDING_POST;
515 // once the settings have been received, send him the jump into mission packet and mark this down. now the joiner
516 // moves into the ship select state (ingame)
517 if((Net_players[idx].state == NETPLAYER_STATE_POST_DATA_ACK) && !(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_PICK_SHIP)){
518 // if this guy is an obsever, create his observer object and be done!
519 if(Net_players[idx].flags & NETINFO_FLAG_OBSERVER){
520 multi_obs_create_observer(&Net_players[idx]);
521 Net_players[idx].flags &= ~(NETINFO_FLAG_INGAME_JOIN);
522 Netgame.flags &= ~(NG_FLAG_INGAME_JOINING_CRITICAL | NG_FLAG_INGAME_JOINING);
525 // send the packet and mark it down
526 send_jump_into_mission_packet(&Net_players[idx]);
527 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_PICK_SHIP;
530 // check to see if his timestamp for ship update (hull, shields, etc) has popped. If so, send some info and reset
531 if(timestamp_elapsed(Net_players[idx].s_info.last_full_update_time)){
533 multi_ingame_send_ship_update(&Net_players[idx]);
535 // reset the timestamp
536 Net_players[idx].s_info.last_full_update_time = timestamp(INGAME_SHIP_UPDATE_TIME);
539 // once he has received the weapon state packet, send him the player settings for all the players in the game and mark this down
540 if(!(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_SENDING_SETS)){
541 // send the packet and mark it down
542 // this will update _ALL_ players in the game which is important
543 send_player_settings_packet();
544 send_player_settings_packet( &Net_players[idx] ); // send directly so he gets the packet
546 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_SENDING_SETS;
551 // the final step for an ingame joining observer - create my observer object, unflag myself as joining and jump into mission
552 void multi_ingame_observer_finish()
554 // create my local observer object
555 multi_obs_create_observer_client();
557 // unflag myself as being an ingame joiner
558 Net_player->flags &= ~(NETINFO_FLAG_INGAME_JOIN);
560 // set my state to be in-mission
561 Net_player->state = NETPLAYER_STATE_IN_MISSION;
562 send_netplayer_update_packet();
564 // jump into the game
565 gameseq_post_event(GS_EVENT_ENTER_GAME);
568 // --------------------------------------------------------------------------------------------------
569 // INGAME DATA SYNC SCREEN
572 // mission sync screen init function for ingame joining
573 void multi_ingame_sync_init()
575 // if we couldn't get the file signature correctly. send some bogus values
576 multi_get_mission_checksum(Game_current_mission_filename);
578 // everyone should re-initialize these
579 init_multiplayer_stats();
581 // reset all sequencing info
582 multi_oo_reset_sequencing();
584 // send the file signature to the host for possible mission file transfer
585 strcpy(Netgame.mission_name,Game_current_mission_filename);
586 send_file_sig_packet(Multi_current_file_checksum,Multi_current_file_length);
588 Ingame_ships_deleted = 0;
591 // mission sync screen do function for ingame joining
592 void multi_ingame_sync_do()
596 // mission sync screen do function for ingame joining
597 void multi_ingame_sync_close()
602 // --------------------------------------------------------------------------------------------------
603 // INGAME SHIP SELECT SCREEN
605 static char *Multi_ingame_join_bitmap_fname[GR_NUM_RESOLUTIONS] = {
606 "MultiIngame", // GR_640
607 "2_MultiIngame" // GR_1024
610 static char *Multi_ingame_join_bitmap_mask_fname[GR_NUM_RESOLUTIONS] = {
611 "MultiIngame-M", // GR_640
612 "2_MultiIngame-M" // GR_1024
617 #define MULTI_INGAME_JOIN_NUM_BUTTONS 2
621 ui_button_info Multi_ingame_join_buttons[GR_NUM_RESOLUTIONS][MULTI_INGAME_JOIN_NUM_BUTTONS] = {
623 ui_button_info( "MIB_00", 532, 434, 510, 413, 0 ), // cancel
624 ui_button_info( "MIB_01", 572, 428, 585, 413, 1 ), // join
627 ui_button_info( "2_MIB_00", 851, 695, 916, 685, 0 ), // cancel
628 ui_button_info( "2_MIB_01", 916, 685, 950, 665, 1 ), // join
632 #define MULTI_INGAME_JOIN_NUM_TEXT 8
634 UI_XSTR Multi_ingame_join_text[GR_NUM_RESOLUTIONS][MULTI_INGAME_JOIN_NUM_TEXT] = {
636 {"Cancel", 387, 510, 413, UI_XSTR_COLOR_PINK, -1, &Multi_ingame_join_buttons[GR_640][MIJ_CANCEL].button},
637 {"Join", 1303, 585, 413, UI_XSTR_COLOR_PINK, -1, &Multi_ingame_join_buttons[GR_640][MIJ_JOIN].button},
638 {"Select Ship", 317, 39, 6, UI_XSTR_COLOR_PINK, -1, NULL},
639 {"name", 1423, 39, 28, UI_XSTR_COLOR_GREEN, -1, NULL},
640 {"class", 1424, 145, 28, UI_XSTR_COLOR_GREEN, -1, NULL},
641 {"status", 1425, 214, 28, UI_XSTR_COLOR_GREEN, -1, NULL},
642 {"primary", 1426, 295, 28, UI_XSTR_COLOR_GREEN, -1, NULL},
643 {"secondary", 1427, 440, 28, UI_XSTR_COLOR_GREEN, -1, NULL}
646 {"Cancel", 387, 843, 665, UI_XSTR_COLOR_PINK, -1, &Multi_ingame_join_buttons[GR_1024][MIJ_CANCEL].button},
647 {"Join", 1303, 950, 665, UI_XSTR_COLOR_PINK, -1, &Multi_ingame_join_buttons[GR_1024][MIJ_JOIN].button},
648 {"Select Ship", 317, 63, 14, UI_XSTR_COLOR_PINK, -1, NULL},
649 {"name", 1423, 63, 45, UI_XSTR_COLOR_GREEN, -1, NULL},
650 {"class", 1424, 233, 45, UI_XSTR_COLOR_GREEN, -1, NULL},
651 {"status", 1425, 343, 45, UI_XSTR_COLOR_GREEN, -1, NULL},
652 {"primary", 1426, 473, 45, UI_XSTR_COLOR_GREEN, -1, NULL},
653 {"secondary", 1427, 704, 45, UI_XSTR_COLOR_GREEN, -1, NULL}
662 static int Mi_width[GR_NUM_RESOLUTIONS] = {
667 static int Mi_height[GR_NUM_RESOLUTIONS] = {
672 static int Mi_spacing[GR_NUM_RESOLUTIONS] = {
677 static int Mi_name_field[GR_NUM_RESOLUTIONS][4] = {
694 static int Mi_class_field[GR_NUM_RESOLUTIONS][4] = {
711 static int Mi_status_field[GR_NUM_RESOLUTIONS][4] = {
728 static int Mi_primary_field[GR_NUM_RESOLUTIONS][4] = {
745 static int Mi_secondary_field[GR_NUM_RESOLUTIONS][4] = {
762 // for timing a player out
763 static int Multi_ingame_timer_coords[GR_NUM_RESOLUTIONS][2] = {
776 //#define MULTI_INGAME_TIME_LEFT_X 26
777 //#define MULTI_INGAME_TIME_LEFT_Y 411
779 #define MULTI_INGAME_TIME_SECONDS (1000 * 15)
780 LOCAL int Ingame_time_left;
782 // uses MULTI_JOIN_REFRESH_TIME as its timestamp
783 UI_WINDOW Multi_ingame_window; // the window object for the join screen
784 UI_BUTTON Multi_ingame_select_button; // for selecting list items
785 int Multi_ingame_bitmap; // the background bitmap
788 #define MULTI_INGAME_MAX_SHIP_ICONS 40
789 typedef struct is_icon {
790 int bmaps[NUM_ICON_FRAMES];
793 is_icon Multi_ingame_ship_icon[MULTI_INGAME_MAX_SHIP_ICONS];
794 int Multi_ingame_num_ship_icons;
796 // # of available ships (also == the # currently being displayed)
797 int Multi_ingame_num_avail;
799 // signatures for each of the available ships
800 ushort Multi_ingame_ship_sigs[MAX_PLAYERS];
802 // net signature of the ship we've requested to grab as an ingame joiner (waiting for server response if >= 0)
803 ushort Multi_ingame_join_sig;
805 // the index into the list of the ship currently selected
806 int Multi_ingame_ship_selected;
808 // temporary stuff - used only until we come up with a more permanent interface for this screen
809 #define MAX_INGAME_SHIPS 50
810 #define INGAME_FINAL_TIMEOUT 4000
812 ushort Ingame_ship_signatures[MAX_INGAME_SHIPS];
816 // local variables to hold ship/obj/ai information for the joiner. We need to
817 // create a bogus ship so that packets that the joiner receives during his join
818 // have valid Player_ship, Player_obj, and Player_ai to work with
821 // display the available ships (OF_COULD_BE_PLAYER flagged)
822 void multi_ingame_join_display_avail();
824 // try and scroll the selected ship up
825 void multi_ingame_scroll_select_up();
827 // try and scroll the selected ship down
828 void multi_ingame_scroll_select_down();
830 // handle all timeout details
831 void multi_ingame_handle_timeout();
833 int multi_ingame_get_ship_class_icon(int ship_class)
837 // lookup through all available ship icons
838 for(idx=0;idx<Multi_ingame_num_ship_icons;idx++){
839 if(Multi_ingame_ship_icon[idx].ship_class == ship_class){
848 void multi_ingame_load_icons()
850 int first_frame, num_frames, idx, s_idx;
852 // zero out the icon handles
853 for(idx=0;idx<MULTI_INGAME_MAX_SHIP_ICONS;idx++){
854 Multi_ingame_ship_icon[idx].ship_class = -1;
855 for(s_idx=0;s_idx<NUM_ICON_FRAMES;s_idx++){
856 Multi_ingame_ship_icon[idx].bmaps[s_idx] = -1;
859 Multi_ingame_num_ship_icons = 0;
861 // traverse through all ship types
862 for(idx=0;idx<MAX_SHIP_TYPES;idx++){
863 // if there is a valid icon for this ship
864 if((strlen(Ship_info[idx].icon_filename) > 0) && (Multi_ingame_num_ship_icons < MULTI_INGAME_MAX_SHIP_ICONS)){
865 // set the ship class
866 Multi_ingame_ship_icon[Multi_ingame_num_ship_icons].ship_class = idx;
868 // load in the animation frames for the icon
869 first_frame = bm_load_animation(Ship_info[idx].icon_filename, &num_frames);
870 if ( first_frame == -1 ) {
871 Int3(); // Could not load in icon frames.. get Dave
873 for ( s_idx = 0; s_idx < num_frames; s_idx++ ) {
874 Multi_ingame_ship_icon[Multi_ingame_num_ship_icons].bmaps[s_idx] = first_frame+s_idx;
877 Multi_ingame_num_ship_icons++;
882 void multi_ingame_unload_icons()
886 // unload all the bitmaps
887 for(idx=0;idx<Multi_ingame_num_ship_icons;idx++){
888 for(s_idx=0;s_idx<NUM_ICON_FRAMES;s_idx++){
889 if(Multi_ingame_ship_icon[idx].bmaps[s_idx] != -1){
890 bm_release(Multi_ingame_ship_icon[idx].bmaps[s_idx]);
891 Multi_ingame_ship_icon[idx].bmaps[s_idx] = -1;
897 // ingame join ship selection screen init
898 void multi_ingame_select_init()
900 /// int objnum, wingnum_save,idx, goals_save;
901 // ushort net_signature;
904 Multi_ingame_join_sig = 0;
905 Net_player->player->objnum = -1;
907 // create a ship, then find a ship to copy crucial information from. Save and restore the wing
908 // number to be safe.
910 wingnum_save = Player_start_pobject.wingnum;
911 net_signature = Player_start_pobject.net_signature;
912 goals_save = Player_start_pobject.ai_goals;
913 Player_start_pobject.wingnum = -1;
914 Player_start_pobject.net_signature = 0;
915 Player_start_pobject.ai_goals = -1;
916 objnum = parse_create_object( &Player_start_pobject );
917 Player_start_pobject.wingnum = wingnum_save;
918 Player_start_pobject.net_signature = net_signature;
919 Player_start_pobject.ai_goals = goals_save;
921 if ( objnum == -1 ) {
922 nprintf(("Network", "Bailing ingame join because unable to create parse object player ship\n"));
923 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_INGAME_SHIP);
928 Player_obj = &Objects[objnum];
929 Player_obj->net_signature = 0;
930 Player_ship = &Ships[Player_obj->instance];
931 strcpy(Player_ship->ship_name, NOX("JIP Ship"));
932 Player_ai = &Ai_info[Player_ship->ai_index];
935 // load the temp ship icons
936 multi_ingame_load_icons();
938 // blast all the ingame ship signatures
939 memset(Multi_ingame_ship_sigs,0,sizeof(ushort) * MAX_PLAYERS);
941 // the index into the list of the ship currently selected
942 Multi_ingame_ship_selected = -1;
944 // initialize the time he has left to select a ship
945 Ingame_time_left = timestamp(MULTI_INGAME_TIME_SECONDS);
947 // initialize GUI data
949 // create the interface window
950 Multi_ingame_window.create(0,0,gr_screen.max_w,gr_screen.max_h,0);
951 Multi_ingame_window.set_mask_bmap(Multi_ingame_join_bitmap_mask_fname[gr_screen.res]);
953 // load the background bitmap
954 Multi_ingame_bitmap = bm_load(Multi_ingame_join_bitmap_fname[gr_screen.res]);
955 if(Multi_ingame_bitmap < 0)
956 Error(LOCATION, "Couldn't load background bitmap for ingame join");
958 // create the interface buttons
959 for(idx=0; idx<MULTI_INGAME_JOIN_NUM_BUTTONS; idx++) {
961 Multi_ingame_join_buttons[gr_screen.res][idx].button.create(&Multi_ingame_window, "", Multi_ingame_join_buttons[gr_screen.res][idx].x, Multi_ingame_join_buttons[gr_screen.res][idx].y, 1, 1, 0, 1);
963 // set the sound to play when highlighted
964 Multi_ingame_join_buttons[gr_screen.res][idx].button.set_highlight_action(common_play_highlight_sound);
966 // set the ani for the button
967 Multi_ingame_join_buttons[gr_screen.res][idx].button.set_bmaps(Multi_ingame_join_buttons[gr_screen.res][idx].filename);
970 Multi_ingame_join_buttons[gr_screen.res][idx].button.link_hotspot(Multi_ingame_join_buttons[gr_screen.res][idx].hotspot);
974 for(idx=0; idx<MULTI_INGAME_JOIN_NUM_TEXT; idx++) {
975 Multi_ingame_window.add_XSTR(&Multi_ingame_join_text[gr_screen.res][idx]);
978 // create the list item select button
979 Multi_ingame_select_button.create(&Multi_ingame_window, "", Mi_name_field[gr_screen.res][MI_FIELD_X], Mi_name_field[gr_screen.res][MI_FIELD_Y], Mi_width[gr_screen.res], Mi_height[gr_screen.res], 0, 1);
980 Multi_ingame_select_button.hide();
982 // load freespace stuff
983 // JAS: Code to do paging used to be here.
986 // process all ship list related details
987 void multi_ingame_ship_list_process()
991 // if we currently don't have any ships selected, but we've got items on the list, select the first one
992 if((Multi_ingame_ship_selected == -1) && (Multi_ingame_num_avail > 0)){
993 gamesnd_play_iface(SND_USER_SELECT);
994 Multi_ingame_ship_selected = 0;
997 // if we currently have a ship selected, but it disappears, select the next ship (is possible0
998 if((Multi_ingame_ship_selected >= 0) && (Multi_ingame_ship_selected >= Multi_ingame_num_avail)){
999 gamesnd_play_iface(SND_USER_SELECT);
1000 Multi_ingame_ship_selected = Multi_ingame_num_avail-1;
1003 // if the player clicked on the select button, see if the selection has changed
1004 if(Multi_ingame_select_button.pressed()){
1005 Multi_ingame_select_button.get_mouse_pos(NULL,&y);
1006 select_index = y / Mi_spacing[gr_screen.res];
1008 // if we've selected a valid item
1009 if((select_index >= 0) && (select_index < Multi_ingame_num_avail)){
1010 // if we're not selected the same item, play a sound
1011 if(Multi_ingame_ship_selected != select_index){
1012 gamesnd_play_iface(SND_USER_SELECT);
1016 Multi_ingame_ship_selected = select_index;
1022 // determines if a button was pressed, and acts accordingly
1023 void multi_ingame_join_check_buttons()
1026 for(idx=0; idx<MULTI_INGAME_JOIN_NUM_BUTTONS; idx++) {
1027 // we only really need to check for one button pressed at a time,
1028 // so we can break after finding one.
1029 if(Multi_ingame_join_buttons[gr_screen.res][idx].button.pressed()) {
1030 multi_ingame_join_button_pressed(idx);
1036 // a button was pressed, so make it do its thing
1037 // this is the "acting accordingly" part
1038 void multi_ingame_join_button_pressed(int n)
1042 multi_quit_game(PROMPT_CLIENT);
1045 // don't do further processing if the game is paused
1046 if ( Netgame.game_state == NETGAME_STATE_PAUSED )
1049 if(Multi_ingame_join_sig == 0) {
1050 // if he has a valid ship selected
1051 if(Multi_ingame_ship_selected >= 0) {
1052 gamesnd_play_iface(SND_USER_SELECT);
1054 // select the sig of this ship and send a request for it
1055 Multi_ingame_join_sig = Multi_ingame_ship_sigs[Multi_ingame_ship_selected];
1057 // send a request to the
1058 send_ingame_ship_request_packet(INGAME_SR_REQUEST,Multi_ingame_join_sig);
1060 gamesnd_play_iface(SND_GENERAL_FAIL);
1063 gamesnd_play_iface(SND_GENERAL_FAIL);
1068 // how the hell did this happen?
1074 // ingame join ship selection screen do
1075 void multi_ingame_select_do()
1077 int k = Multi_ingame_window.process();
1079 // process any keypresses
1082 multi_quit_game(PROMPT_CLIENT);
1086 multi_ingame_scroll_select_up();
1090 multi_ingame_scroll_select_down();
1094 // process button presses
1095 // multi_ingame_process_buttons();
1096 multi_ingame_join_check_buttons();
1098 // process any ship list related events
1099 multi_ingame_ship_list_process();
1101 // draw the background, etc
1103 GR_MAYBE_CLEAR_RES(Multi_ingame_bitmap);
1104 if(Multi_ingame_bitmap != -1){
1105 gr_set_bitmap(Multi_ingame_bitmap);
1108 Multi_ingame_window.draw();
1110 // handle all timeout details. blitting, etc
1111 multi_ingame_handle_timeout();
1113 // display the available ships
1114 multi_ingame_join_display_avail();
1120 // ingame join ship select close
1121 void multi_ingame_select_close()
1123 // unload any bitmaps
1124 if(!bm_unload(Multi_ingame_bitmap)){
1125 nprintf(("General","WARNING : could not unload background bitmap %s\n",Multi_ingame_join_bitmap_fname[gr_screen.res]));
1128 // unload all the ship class icons
1129 multi_ingame_unload_icons();
1131 // destroy the UI_WINDOW
1132 Multi_ingame_window.destroy();
1134 // stop main hall music
1135 main_hall_stop_music();
1138 // display an individual ships information, starting at the indicated y pixel value
1139 void multi_ingame_join_display_ship(object *objp,int y_start)
1146 sip = &Ship_info[Ships[objp->instance].ship_info_index];
1148 // blit the ship name itself
1149 gr_set_color_fast(&Color_normal);
1150 gr_string(Mi_name_field[gr_screen.res][MI_FIELD_X],y_start+10, Ships[objp->instance].ship_name);
1152 // blit the ship class icon
1153 icon_num = multi_ingame_get_ship_class_icon(Ships[objp->instance].ship_info_index);
1155 gr_set_bitmap(Multi_ingame_ship_icon[icon_num].bmaps[0]);
1156 gr_bitmap(Mi_class_field[gr_screen.res][MI_FIELD_X] + 15, y_start);
1159 gr_set_color_fast(&Color_bright);
1160 wp = &Ships[objp->instance].weapons;
1162 // blit the ship's primary weapons
1163 y_spacing = (Mi_spacing[gr_screen.res] - (wp->num_primary_banks * 10)) / 2;
1164 for(idx=0;idx<wp->num_primary_banks;idx++){
1165 gr_string(Mi_primary_field[gr_screen.res][MI_FIELD_X], y_start + y_spacing + (idx * 10), Weapon_info[wp->primary_bank_weapons[idx]].name);
1168 // blit the ship's secondary weapons
1169 y_spacing = (Mi_spacing[gr_screen.res] - (wp->num_secondary_banks * 10)) / 2;
1170 for(idx=0;idx<wp->num_secondary_banks;idx++){
1171 gr_string(Mi_secondary_field[gr_screen.res][MI_FIELD_X], y_start + y_spacing + (idx * 10), Weapon_info[wp->secondary_bank_weapons[idx]].name);
1174 // blit the shield/hull integrity
1175 hud_shield_show_mini(objp, Mi_status_field[gr_screen.res][MI_FIELD_X] + 15, y_start + 3,5,7);
1178 // display the available ships (OF_COULD_BE_PLAYER flagged)
1179 void multi_ingame_join_display_avail()
1183 // recalculate this # every frame
1184 Multi_ingame_num_avail = 0;
1186 // display a background highlight rectangle for any selected lines
1187 if(Multi_ingame_ship_selected != -1){
1188 int y_start = (Mi_name_field[gr_screen.res][MI_FIELD_Y] + (Multi_ingame_ship_selected * Mi_spacing[gr_screen.res]));
1191 gr_set_color_fast(&Color_bright_blue);
1192 gr_line(Mi_name_field[gr_screen.res][MI_FIELD_X]-1,y_start-1, (Mi_name_field[gr_screen.res][MI_FIELD_X]-1) + (Mi_width[gr_screen.res]+2),y_start-1);
1193 gr_line(Mi_name_field[gr_screen.res][MI_FIELD_X]-1,y_start + Mi_spacing[gr_screen.res] - 2, (Mi_name_field[gr_screen.res][MI_FIELD_X]-1) + (Mi_width[gr_screen.res]+2),y_start + Mi_spacing[gr_screen.res] - 2);
1194 gr_line(Mi_name_field[gr_screen.res][MI_FIELD_X]-1,y_start, Mi_name_field[gr_screen.res][MI_FIELD_X]-1, y_start + Mi_spacing[gr_screen.res] - 2);
1195 gr_line((Mi_name_field[gr_screen.res][MI_FIELD_X]-1) + (Mi_width[gr_screen.res]+2), y_start,(Mi_name_field[gr_screen.res][MI_FIELD_X]-1) + (Mi_width[gr_screen.res]+2),y_start + Mi_spacing[gr_screen.res] - 2);
1198 moveup = GET_FIRST(&Ship_obj_list);
1199 while(moveup != END_OF_LIST(&Ship_obj_list)){
1200 if( !(Ships[Objects[moveup->objnum].instance].flags & (SF_DYING|SF_DEPARTING)) && (Objects[moveup->objnum].flags & OF_COULD_BE_PLAYER) ) {
1202 multi_ingame_join_display_ship(&Objects[moveup->objnum],Mi_name_field[gr_screen.res][MI_FIELD_Y] + (Multi_ingame_num_avail * Mi_spacing[gr_screen.res]));
1204 // set the ship signature
1205 Multi_ingame_ship_sigs[Multi_ingame_num_avail] = Objects[moveup->objnum].net_signature;
1207 // inc the # available
1208 Multi_ingame_num_avail++;
1210 moveup = GET_NEXT(moveup);
1214 // try and scroll the selected ship up
1215 void multi_ingame_scroll_select_up()
1217 if(Multi_ingame_ship_selected > 0){
1218 gamesnd_play_iface(SND_USER_SELECT);
1219 Multi_ingame_ship_selected--;
1221 gamesnd_play_iface(SND_GENERAL_FAIL);
1225 // try and scroll the selected ship down
1226 void multi_ingame_scroll_select_down()
1228 if(Multi_ingame_ship_selected < (Multi_ingame_num_avail - 1)){
1229 gamesnd_play_iface(SND_USER_SELECT);
1230 Multi_ingame_ship_selected++;
1232 gamesnd_play_iface(SND_GENERAL_FAIL);
1236 // handle all timeout details
1237 void multi_ingame_handle_timeout()
1240 // uncomment this block to disable the timer
1241 gr_set_color_fast(&Color_bright_red);
1242 gr_string(Multi_ingame_timer_coords[gr_screen.res][0], Multi_ingame_timer_coords[gr_screen.res][1], "Timer disabled!!");
1246 // if we've timed out, leave the game
1247 if( timestamp_elapsed(Ingame_time_left) ) {
1248 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_INGAME_TIMEOUT, MULTI_END_ERROR_NONE);
1252 // otherwise, blit how much time we have left
1253 int time_left = timestamp_until(Ingame_time_left) / 1000;
1254 char tl_string[100];
1255 gr_set_color_fast(&Color_bright);
1256 memset(tl_string,0,100);
1257 sprintf(tl_string,XSTR("Time remaining : %d s\n",682),time_left);
1258 gr_string(Multi_ingame_timer_coords[gr_screen.res][0], Multi_ingame_timer_coords[gr_screen.res][1], tl_string);
1262 // --------------------------------------------------------------------------------------------------
1263 // PACKET HANDLER functions
1264 // these are also defined in multimsgs.h, but the implementations are in the module for the sake of convenience
1267 #define INGAME_PACKET_SLOP 75 // slop value used for packets to ingame joiner
1269 void process_ingame_ships_packet( ubyte *data, header *hinfo )
1271 int offset, sflags, oflags, team, j;
1273 ushort net_signature;
1275 int team_val, slot_index, idx;
1276 char ship_name[255] = "";
1280 // go through the ship obj list and delete everything. YEAH
1281 if(!Ingame_ships_deleted){
1290 for(idx=0; idx<MAX_SHIPS; idx++){
1291 if((Ships[idx].objnum >= 0) && (Ships[idx].objnum < MAX_OBJECTS)){
1292 obj_delete(Ships[idx].objnum);
1296 Ingame_ships_deleted = 1;
1299 offset = HEADER_LENGTH;
1303 while ( p_type == INGAME_SHIP_NEXT ) {
1305 int ship_num, objnum;
1307 GET_STRING( ship_name );
1308 GET_DATA( net_signature );
1312 GET_DATA( wing_data );
1315 GET_DATA(Wings[wing_data].current_wave);
1316 net_sig_modify = Wings[wing_data].current_wave - 1;
1319 // lookup ship in the original ships array
1320 p_objp = mission_parse_get_original_ship(net_signature);
1322 // if this ship is part of wing not on its current wave, look for its "original" by subtracting out wave #
1323 p_objp = mission_parse_get_arrival_ship((ushort)(net_signature - (ushort)net_sig_modify));
1327 nprintf(("Network", "Couldn't find ship %s in either arrival list or in mission"));
1328 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_INGAME_BOGUS);
1332 // go ahead and create the parse object. Set the network signature of this guy before
1334 // multi_set_network_signature( net_signature, MULTI_SIG_SHIP );
1335 objnum = parse_create_object( p_objp );
1336 ship_num = Objects[objnum].instance;
1337 Objects[objnum].flags = oflags;
1338 Objects[objnum].net_signature = net_signature;
1340 // assign any common data
1341 strcpy(Ships[ship_num].ship_name, ship_name);
1342 Ships[ship_num].flags = sflags;
1343 Ships[ship_num].team = team;
1344 Ships[ship_num].wingnum = (int)wing_data;
1351 // if we have reached the end of the list and change our network state
1352 if ( p_type == INGAME_SHIP_LIST_EOL ) {
1353 // merge all created list
1354 obj_merge_created_list();
1356 // fixup player ship stuff
1357 for(idx=0; idx<MAX_SHIPS; idx++){
1358 if(Ships[idx].objnum < 0){
1362 // get the team and slot. Team will be -1 when it isn't a part of player wing. So, if
1363 // not -1, then be sure we have a valid slot, then change the ship type, etc.
1364 objp = &Objects[Ships[idx].objnum];
1365 multi_ts_get_team_and_slot(Ships[idx].ship_name, &team_val, &slot_index);
1366 if ( team_val != -1 ) {
1367 Assert( slot_index != -1 );
1369 // change the ship type and the weapons
1370 change_ship_type(objp->instance, Wss_slots_teams[team_val][slot_index].ship_class);
1371 wl_bash_ship_weapons(&Ships[idx].weapons, &Wss_slots_teams[team_val][slot_index]);
1373 // Be sure to mark this ship as as a could_be_player
1374 obj_set_flags( objp, objp->flags | OF_COULD_BE_PLAYER );
1375 objp->flags &= ~OF_PLAYER_SHIP;
1378 // if this is a player ship, make sure we find out who's it is and set their objnum accordingly
1380 for( j = 0; j < MAX_PLAYERS; j++){
1381 if(MULTI_CONNECTED(Net_players[j]) && (Net_players[j].player->objnum == Objects[Ships[idx].objnum].net_signature)) {
1382 // nprintf(("Network", "Making %s ship for %s\n", Ships[shipnum].ship_name, Net_players[j].player->callsign));
1383 multi_assign_player_ship( j, objp, Ships[idx].ship_info_index );
1384 objp->flags |= OF_PLAYER_SHIP;
1385 objp->flags &= ~OF_COULD_BE_PLAYER;
1392 // notify the server that we're all good.
1393 Net_player->state = NETPLAYER_STATE_INGAME_SHIPS;
1394 send_netplayer_update_packet();
1396 // add some mission sync text
1397 multi_common_add_text(XSTR("Ships packet ack (ingame)\n",683));
1401 void send_ingame_ships_packet(net_player *player)
1403 ubyte data[MAX_PACKET_SIZE];
1409 BUILD_HEADER( SHIPS_INGAME_PACKET );
1411 // essentially, we are going to send a list of ship names to the joiner for ships that are not
1412 // in wings. The joiner will take the list, create any ships which should be created, and delete all
1413 // other ships after the list is sent.
1414 for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
1417 shipp = &Ships[Objects[so->objnum].instance];
1420 // if ( shipp->wingnum != -1 ){
1424 if ( Objects[so->objnum].net_signature == STANDALONE_SHIP_SIG ){
1428 // add the ship name and other information such as net signature, ship and object(?) flags.
1429 p_type = INGAME_SHIP_NEXT;
1431 ADD_STRING( shipp->ship_name );
1432 ADD_DATA( Objects[so->objnum].net_signature );
1433 ADD_DATA( shipp->flags );
1434 ADD_DATA( Objects[so->objnum].flags );
1435 ADD_DATA( shipp->team );
1436 wing_data = (short)shipp->wingnum;
1437 ADD_DATA(wing_data);
1439 ADD_DATA(Wings[wing_data].current_wave);
1442 // don't send anymore data if we are getting close to the maximum size of this packet. Send it off and
1444 if ( packet_size > (MAX_PACKET_SIZE - INGAME_PACKET_SLOP) ) {
1445 p_type = INGAME_SHIP_LIST_EOP;
1447 multi_io_send_reliable(player, data, packet_size);
1448 BUILD_HEADER( SHIPS_INGAME_PACKET );
1452 // end of the ship list!!!
1453 p_type = INGAME_SHIP_LIST_EOL;
1455 multi_io_send_reliable(player, data, packet_size);
1458 void process_ingame_wings_packet( ubyte *data, header *hinfo )
1463 // code to process the wing data from a server.
1464 void process_ingame_wings_packet( ubyte *data, header *hinfo )
1466 int offset, wingnum;
1469 offset = HEADER_LENGTH;
1473 // p_type tells us whether to stop or not
1474 while ( p_type == INGAME_WING_NEXT ) {
1477 // get the wingnum and a pointer to it. The game stores data for all wings always, so this
1478 // is perfectly valid
1479 GET_DATA( wingnum );
1480 wingp = &Wings[wingnum];
1483 if ( what == INGAME_WING_NOT_ARRIVED ) {
1484 Assert( wingp->total_arrived_count == 0 ); // this had better be true!!!
1485 } else if ( what == INGAME_WING_DEPARTED ) {
1486 // mark the wing as gone. if it isn't, it soon will be. Maybe we should send more information
1487 // about these wings later (like total_arrived_count, etc), but we will see.
1488 wingp->flags |= WF_WING_GONE;
1490 int total_arrived_count, current_count, current_wave, i, j;
1494 // the wing is present in the mission on the server. Get the crucial information about the
1495 // wing. Then get the ships for this wing in order on the client machine
1496 GET_DATA( total_arrived_count );
1497 GET_DATA( current_count );
1498 GET_DATA( current_wave );
1500 Assert( current_wave > 0 );
1501 Assert( total_arrived_count > 0 );
1503 // for this wing, strip it down to nothing. Let the parse object ocde recreate the
1504 // wing from the parse objects, then bash any weapons, etc for player wings. We need
1505 // to do this because we might actually wind up with > MAX_SHIPS_PER_WING if we
1506 // don't delete them all first, and have a > 0 threshold, and are on something other
1507 // than the first wave. Only do this for non-player wings.
1509 nprintf(("Network", "Clearing %s -- %d ships\n", wingp->name, wingp->current_count));
1510 for ( i = 0; i < wingp->current_count; i++ ) {
1513 index = wingp->ship_index[i];
1514 Assert( index != -1 );
1515 objnum = Ships[index].objnum;
1516 Assert( objnum != -1 );
1518 // delete the object since we are filling the wing again anyway.
1519 obj_delete( objnum );
1520 Objects[objnum].net_signature = 0; // makes this object "invalid" until dead.
1521 if ( Objects[objnum].type == OBJ_GHOST ) {
1522 nprintf(("Network", "Marking ghost objnum %d as dead\n", objnum));
1523 Objects[objnum].flags |= OF_SHOULD_BE_DEAD;
1525 Ingame_ships_to_delete[index] = 0; // be sure that this guy doesn't get deleted, since we already deleted it
1526 wingp->ship_index[i] = -1;
1528 wingp->current_count = 0;
1529 wingp->total_arrived_count = 0;
1531 // now, recreate all the ships needed
1532 for (i = 0; i < current_count; i++ ) {
1533 int which_one, team, slot_index, specific_instance;;
1537 GET_DATA( signature );
1539 // assign which_one to be the given signature - wing's base signature. This let's us
1540 // know which ship to create (i.e. the total_arrivel_count);
1541 which_one = signature - wingp->net_signature;
1542 Assert( (which_one >= 0) && (which_one < (wingp->net_signature + (wingp->wave_count*wingp->num_waves))) );
1543 wingp->total_arrived_count = (ushort)which_one;
1545 // determine which ship in the ahip arrival list this guy is. It is a 0 based index
1546 specific_instance = which_one % wingp->wave_count;
1548 // call parse_wing_create_ships making sure that we only ever create 1 ship at a time. We don't
1549 // want parse_wing_create_ships() to assign network signature either. We will directly
1552 wingp->current_wave = 0; // make it the first wave. Ensures that ships don't get removed off the list
1553 parse_wing_create_ships( wingp, 1, 1, specific_instance );
1554 shipnum = wingp->ship_index[wingp->current_count-1];
1555 Ingame_ships_to_delete[shipnum] = 0; // "unmark" this ship so it doesn't get deleted.
1557 // kind of stupid, but bash the name since it won't get recreated properly from
1558 // the parse_wing_create_ships call.
1559 shipp = &Ships[shipnum];
1560 sprintf(shipp->ship_name, NOX("%s %d"), wingp->name, which_one + 1);
1561 nprintf(("Network", "Created %s\n", shipp->ship_name));
1563 objp = &Objects[shipp->objnum];
1564 objp->net_signature = (ushort)(wingp->net_signature + which_one);
1566 // get the team and slot. Team will be -1 when it isn't a part of player wing. So, if
1567 // not -1, then be sure we have a valid slot, then change the ship type, etc.
1568 multi_ts_get_team_and_slot(shipp->ship_name, &team, &slot_index);
1570 Assert( slot_index != -1 );
1572 // change the ship type and the weapons
1573 change_ship_type(objp->instance, Wss_slots_teams[team][slot_index].ship_class);
1574 wl_bash_ship_weapons(&shipp->weapons,&Wss_slots_teams[team][slot_index]);
1576 // Be sure to mark this ship as as a could_be_player
1577 obj_set_flags( objp, objp->flags | OF_COULD_BE_PLAYER );
1578 objp->flags &= ~OF_PLAYER_SHIP;
1581 // if this is a player ship, make sure we find out who's it is and set their objnum accordingly
1582 for( j = 0; j < MAX_PLAYERS; j++){
1583 if(MULTI_CONNECTED(Net_players[j]) && (Net_players[j].player->objnum == signature)) {
1584 Assert( team != -1 ); // to help trap errors!!!
1585 nprintf(("Network", "Making %s ship for %s\n", Ships[shipnum].ship_name, Net_players[j].player->callsign));
1586 multi_assign_player_ship( j, objp, Ships[shipnum].ship_info_index );
1587 objp->flags |= OF_PLAYER_SHIP;
1588 objp->flags &= ~OF_COULD_BE_PLAYER;
1595 // we will have no ships in any wings at this point (we didn't create any when we loaded the
1596 // mission). Set the current wave of this wing to be 1 less than was passed in since this value
1597 // will get incremented in parse_wing_create_ships;
1598 wingp->current_wave = current_wave;
1599 wingp->total_arrived_count = total_arrived_count;
1607 // if we have reached the end of the list change our network state
1608 if ( p_type == INGAME_WING_LIST_EOL ) {
1609 Net_player->state = NETPLAYER_STATE_INGAME_WINGS;
1610 send_netplayer_update_packet();
1612 // add some mission sync text
1613 multi_common_add_text(XSTR("Wings packet (ingame)\n",684));
1618 // function to send information about wings. We need to send enough information to let the client
1619 // construct or reconstruct any wings in the mission. We will rely on the fact that the host wing array
1620 // will exactly match the client wing array (in terms of number, and wing names)
1621 void send_ingame_wings_packet( net_player *player )
1623 ubyte data[MAX_PACKET_SIZE];
1628 BUILD_HEADER( WINGS_INGAME_PACKET );
1630 // iterate through the wings list
1631 for ( i = 0; i < num_wings; i++ ) {
1636 p_type = INGAME_WING_NEXT;
1641 // add wing data that the client needs. There are several conditions to send to clients:
1643 // 1. wing hasn't arrived -- total_arrived_count will be 0
1644 // 2. wing is done (or currently departing)
1645 // 3. wing is present (any wave, any number of ships).
1647 // 1 and 2 are easy to handle. (3) is the hardest.
1648 if ( wingp->total_arrived_count == 0 ) {
1649 what = INGAME_WING_NOT_ARRIVED;
1651 } else if ( wingp->flags & (WF_WING_GONE | WF_WING_DEPARTING) ) {
1652 what = INGAME_WING_DEPARTED;
1657 // include to code to possibly send more wing data here in this part of the if/else
1658 // chain. We can do this because MAX_WINGS * 8 (8 being the number of byte for a minimum
1659 // description of a wing) is always less than MAX_PACKET_SIZE. Checking here ensures that
1660 // we have enough space for *this* wing in the packet, and not the largest wing. The
1661 // formula below looks at number of ships in the wing, the name length, length of the signature,
1662 // and the size of the bytes added before the ship names. 32 accounts for a little slop
1663 if ( packet_size > (MAX_PACKET_SIZE - (wingp->current_count * (NAME_LENGTH+2) + 32)) ) {
1664 p_type = INGAME_WING_LIST_EOP;
1666 multi_io_send_reliable(player, data, packet_size);
1667 BUILD_HEADER( WINGS_INGAME_PACKET );
1669 what = INGAME_WING_PRESENT;
1671 ADD_DATA( wingp->total_arrived_count );
1672 ADD_DATA( wingp->current_count );
1673 ADD_DATA( wingp->current_wave );
1675 // add the ship name and net signature of all ships currently in the wing.
1676 for ( j = 0; j < wingp->current_count; j++ ) {
1679 shipp = &Ships[wingp->ship_index[j]];
1680 //ADD_STRING( shipp->ship_name );
1681 ADD_DATA( Objects[shipp->objnum].net_signature );
1687 p_type = INGAME_WING_LIST_EOL;
1690 multi_io_send_reliable(player, data, packet_size);
1694 // send a request or a reply regarding ingame join ship choice
1695 void send_ingame_ship_request_packet(int code,int rdata,net_player *pl)
1697 ubyte data[MAX_PACKET_SIZE],val;
1699 int i, packet_size = 0;
1704 BUILD_HEADER(INGAME_SHIP_REQUEST);
1709 // add any code specific data
1711 case INGAME_SR_REQUEST:
1712 // add the net signature of the ship we're requesting
1713 signature = (ushort)rdata;
1714 ADD_DATA( signature );
1716 case INGAME_SR_CONFIRM:
1717 // get a pointer to the ship
1718 shipp = &Ships[Objects[rdata].instance];
1720 // add the most recent position and orientation for the requested ship
1721 ADD_DATA(Objects[rdata].pos);
1722 ADD_ORIENT(Objects[rdata].orient);
1723 ADD_DATA( Missiontime );
1725 // add the # of respawns this ship has left
1726 pobj = mission_parse_get_arrival_ship( Objects[rdata].net_signature );
1727 Assert(pobj != NULL);
1728 ADD_DATA(pobj->respawn_count);
1730 // add the ships ets settings
1731 val = (ubyte)shipp->weapon_recharge_index;
1733 val = (ubyte)shipp->shield_recharge_index;
1735 val = (ubyte)shipp->engine_recharge_index;
1738 // add current primary and secondary banks, and add link status
1739 val = (ubyte)shipp->weapons.current_primary_bank;
1741 val = (ubyte)shipp->weapons.current_secondary_bank;
1744 // add the current ammo count for secondary banks;
1745 val = (ubyte)shipp->weapons.num_secondary_banks; // for sanity checking
1747 for ( i = 0; i < shipp->weapons.num_secondary_banks; i++ ) {
1748 Assert( shipp->weapons.secondary_bank_ammo[i] < UCHAR_MAX );
1749 val = (ubyte)shipp->weapons.secondary_bank_ammo[i];
1753 // add the link status of weapons
1754 // primary link status
1756 if(shipp->flags & SF_PRIMARY_LINKED){
1759 if(shipp->flags & SF_SECONDARY_DUAL_FIRE){
1767 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
1769 multi_io_send_reliable(pl, data, packet_size);
1771 multi_io_send_reliable(Net_player, data, packet_size);
1774 // if this is a confirm to a player -- send data to the other players in the game telling them
1775 if ( (code == INGAME_SR_CONFIRM) && (Net_player->flags & NETINFO_FLAG_AM_MASTER) ) {
1778 player_num = NET_PLAYER_NUM(pl);
1779 code = INGAME_PLAYER_CHOICE;
1780 BUILD_HEADER(INGAME_SHIP_REQUEST);
1782 ADD_DATA(player_num);
1783 ADD_DATA(Objects[rdata].net_signature);
1784 for (i = 0; i < MAX_PLAYERS; i++ ) {
1785 if(MULTI_CONNECTED(Net_players[i]) && (&Net_players[i] != Net_player) && (i != player_num) ) {
1786 multi_io_send_reliable(&Net_players[i], data, packet_size);
1792 // function to validate all players in the game according to their team select index. If discrepancies
1793 // are found, this function should be able to fix them up.
1794 void multi_ingame_validate_players()
1798 for ( i = 0; i < MAX_PLAYERS; i++ ) {
1799 if( MULTI_CONNECTED(Net_players[i]) && (Net_player != &Net_players[i]) && !MULTI_STANDALONE(Net_players[i]) ) {
1801 int shipnum, objnum, player_objnum;
1803 player_objnum = Net_players[i].player->objnum;
1804 if ( (Objects[player_objnum].type != OBJ_SHIP) || (Objects[player_objnum].type != OBJ_GHOST) ) {
1808 ship_name = multi_ts_get_shipname( Net_players[i].p_info.team, Net_players[i].p_info.ship_index );
1809 Assert( ship_name != NULL );
1810 shipnum = ship_name_lookup( ship_name );
1811 if ( shipnum == -1 ) {
1812 // ship could be respawning
1815 objnum = Ships[shipnum].objnum;
1816 Assert( objnum != -1 );
1818 // if this guy's objnum isn't a ship, then it should proably be a ghost!!
1819 if ( Objects[objnum].type == OBJ_SHIP ) {
1820 if ( objnum != Net_players[i].player->objnum ) {
1822 Net_players[i].player->objnum = objnum;
1825 Assert( Objects[objnum].type == OBJ_GHOST );
1831 // process an ingame ship request packet
1832 void process_ingame_ship_request_packet(ubyte *data, header *hinfo)
1836 int offset = HEADER_LENGTH;
1837 int team, slot_index, i;
1839 ubyte val, num_secondary_banks;
1846 // a request for a ship from an ingame joiner
1847 case INGAME_SR_REQUEST:
1851 // lookup the player and make sure he doesn't already have an objnum (along with possible error conditions)
1852 GET_DATA(sig_request);
1855 player_num = find_player_id(hinfo->id);
1856 if(player_num == -1){
1857 nprintf(("Network","Received ingame ship request packet from unknown player!!\n"));
1861 // make sure this player doesn't already have an object
1862 Assert(MULTI_CONNECTED(Net_players[player_num]));
1863 if(Net_players[player_num].player->objnum != -1){
1864 send_ingame_ship_request_packet(INGAME_SR_DENY,0,&Net_players[player_num]);
1868 // try and find the object
1870 objp = multi_get_network_object(sig_request);
1871 if(objp == NULL || !(objp->flags & OF_COULD_BE_PLAYER)){
1872 send_ingame_ship_request_packet(INGAME_SR_DENY,0,&Net_players[player_num]);
1876 // Assign the player this objnum and ack him
1877 Net_players[player_num].player->objnum = OBJ_INDEX(objp);
1878 Net_players[player_num].state = NETPLAYER_STATE_IN_MISSION; // since he'll do this anyway...
1879 Net_players[player_num].flags &= ~(NETINFO_FLAG_INGAME_JOIN);
1880 multi_assign_player_ship( player_num, objp, Ships[objp->instance].ship_info_index );
1882 // update his ets and link status stuff
1883 multi_server_update_player_weapons(&Net_players[player_num],&Ships[objp->instance]);
1885 objp->flags &= ~(OF_COULD_BE_PLAYER);
1886 objp->flags |= OF_PLAYER_SHIP;
1888 // send a player settings packet to update all other players of this guy's final choices
1889 send_player_settings_packet();
1891 // initialize datarate limiting for this guy
1892 multi_oo_rate_init(&Net_players[player_num]);
1895 send_ingame_ship_request_packet(INGAME_SR_CONFIRM,OBJ_INDEX(objp),&Net_players[player_num]);
1897 // clear my ingame join flag so that others may join
1898 Netgame.flags &= ~NG_FLAG_INGAME_JOINING;
1900 // clear his net stats
1901 scoring_level_init( &(Net_players[player_num].player->stats) );
1904 // a denial for the ship we requested from the server
1905 case INGAME_SR_DENY :
1908 // set this to -1 so we can pick again
1909 Multi_ingame_join_sig = 0;
1912 popup(PF_BODY_BIG | PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You have been denied the requested ship",686));
1915 // a confirmation that we can use the selected ship
1916 case INGAME_SR_CONFIRM:
1917 // object *temp_objp;
1919 // delete the ship this ingame joiner was using. Unassign Player_obj so that this object
1920 // doesn't become a ghost.
1921 // temp_objp = Player_obj;
1922 // Player_obj = NULL;
1923 // obj_delete( OBJ_INDEX(temp_objp) );
1925 // get the object itself
1926 objp = multi_get_network_object(Multi_ingame_join_sig);
1927 Assert(objp != NULL);
1929 // get its most recent position and orientation
1930 GET_DATA(objp->pos);
1931 GET_ORIENT(objp->orient);
1932 GET_DATA( Missiontime );
1933 GET_DATA( respawn_count );
1935 // tell the server I'm in the mission
1936 Net_player->state = NETPLAYER_STATE_IN_MISSION;
1937 send_netplayer_update_packet();
1940 Net_player->player->objnum = OBJ_INDEX(objp);
1942 Player_obj->flags &= ~(OF_COULD_BE_PLAYER);
1943 Player_obj->flags |= OF_PLAYER_SHIP;
1944 multi_assign_player_ship( MY_NET_PLAYER_NUM, objp, Ships[objp->instance].ship_info_index );
1946 // must change the ship type and weapons. An ingame joiner know about the default class
1947 // and weapons for a ship, but these could have changed.
1948 multi_ts_get_team_and_slot(Player_ship->ship_name, &team, &slot_index);
1949 Assert( team != -1 );
1950 Assert( slot_index != -1 );
1951 change_ship_type(objp->instance, Wss_slots_teams[team][slot_index].ship_class);
1952 wl_bash_ship_weapons(&Player_ship->weapons,&Wss_slots_teams[team][slot_index]);
1954 // get the parse object for it and assign the respawn count
1955 pobj = mission_parse_get_arrival_ship( objp->net_signature );
1956 Assert(pobj != NULL);
1957 pobj->respawn_count = respawn_count;
1959 // get the ships ets settings
1961 Player_ship->weapon_recharge_index = val;
1963 Player_ship->shield_recharge_index = val;
1965 Player_ship->engine_recharge_index = val;
1967 // get current primary and secondary banks, and add link status
1969 Player_ship->weapons.current_primary_bank = val;
1971 Player_ship->weapons.current_secondary_bank = val;
1973 // secondary bank ammo data
1974 GET_DATA( num_secondary_banks );
1975 Assert( num_secondary_banks == Player_ship->weapons.num_secondary_banks );
1976 for ( i = 0; i < Player_ship->weapons.num_secondary_banks; i++ ) {
1978 Player_ship->weapons.secondary_bank_ammo[i] = val;
1982 // get the link status of weapons
1985 Player_ship->flags |= SF_PRIMARY_LINKED;
1988 Player_ship->flags |= SF_SECONDARY_DUAL_FIRE;
1992 // be sure that this ships current primary/secondary weapons are valid. Easiest is to just
1993 // bash the values to 0!
1995 if ( Player_ship->weapons.current_primary_bank == -1 )
1996 Player_ship->weapons.current_primary_bank = 0;
1997 if ( Player_ship->weapons.current_secondary_bank == -1 )
1998 Player_ship->weapons.current_secondary_bank = 0;
2001 Net_player->flags &= ~(NETINFO_FLAG_INGAME_JOIN);
2003 // clear all object collision pairs, then add myself to the list
2004 extern void obj_reset_all_collisions();
2005 obj_reset_all_collisions();
2006 // obj_reset_pairs();
2007 // obj_add_pairs( OBJ_INDEX(Player_obj) );
2009 mission_hotkey_set_defaults();
2011 //multi_ingame_validate_players();
2013 // jump into the mission
2014 // NOTE : we check this flag because its possible that the player could have received an endgame packet in the same
2015 // frame as getting this confirmation. In that case, he should be quitting to the main menu. We must not make
2016 // him continue on into the mission
2017 if(!multi_endgame_ending()){
2018 gameseq_post_event(GS_EVENT_ENTER_GAME);
2022 case INGAME_PLAYER_CHOICE: {
2024 ushort net_signature;
2027 // get the player number of this guy, and the net signature of the ship he has chosen
2028 GET_DATA(player_num);
2029 GET_DATA(net_signature);
2032 objp = multi_get_network_object(net_signature);
2033 if ( objp == NULL ) {
2034 // bogus!!! couldn't find the object -- we cannot connect his -- this is really bad!!!
2035 nprintf(("Network", "Couldn't find ship for ingame joiner %s\n", Net_players[player_num].player->callsign));
2038 objp->flags |= OF_PLAYER_SHIP;
2039 objp->flags &= ~OF_COULD_BE_PLAYER;
2041 multi_assign_player_ship( player_num, objp, Ships[objp->instance].ship_info_index );
2049 // --------------------------------------------------------------------------------------------------
2050 // INGAME JOIN FORWARD DEFINITIONS
2053 void multi_ingame_send_ship_update(net_player *p)
2057 // get the first object on the list
2058 moveup = GET_FIRST(&Ship_obj_list);
2060 // go through the list and send all ships which are mark as OF_COULD_BE_PLAYER
2061 while(moveup!=END_OF_LIST(&Ship_obj_list)){
2062 if(Objects[moveup->objnum].flags & OF_COULD_BE_PLAYER){
2064 send_ingame_ship_update_packet(p,&Ships[Objects[moveup->objnum].instance]);
2067 // move to the next item
2068 moveup = GET_NEXT(moveup);
2072 // for now, I guess we'll just send hull and shield % values
2073 void send_ingame_ship_update_packet(net_player *p,ship *sp)
2075 ubyte data[MAX_PACKET_SIZE];
2078 int packet_size = 0;
2081 BUILD_HEADER(INGAME_SHIP_UPDATE);
2083 // just send net signature, shield and hull percentages
2084 objp = &Objects[sp->objnum];
2085 ADD_DATA(objp->net_signature);
2086 ADD_DATA(objp->flags);
2087 ADD_DATA(objp->hull_strength);
2089 // shield percentages
2090 for(idx=0; idx<MAX_SHIELD_SECTIONS; idx++){
2091 f_tmp = objp->shields[idx];
2095 multi_io_send_reliable(p, data, packet_size);
2098 void process_ingame_ship_update_packet(ubyte *data, header *hinfo)
2108 offset = HEADER_LENGTH;
2109 // get the net sig for the ship and do a lookup
2114 lookup = multi_get_network_object(net_sig);
2116 // read in garbage values if we can't find the ship
2117 nprintf(("Network","Got ingame ship update for unknown object\n"));
2119 for(idx=0;idx<MAX_SHIELD_SECTIONS;idx++){
2126 // otherwise read in the ship values
2127 lookup->flags = flags;
2128 GET_DATA(lookup->hull_strength);
2129 for(idx=0;idx<MAX_SHIELD_SECTIONS;idx++){
2131 lookup->shields[idx] = f_tmp;