2 * $Logfile: /Freespace2/code/Network/multi_ingame.cpp $
8 * Revision 1.1 2002/05/03 03:28:10 root
12 * 20 8/03/99 11:02p Dave
13 * Maybe fixed sync problems in multiplayer.
15 * 19 7/30/99 7:01p Dave
16 * Dogfight escort gauge. Fixed up laser rendering in Glide.
18 * 18 7/28/99 5:33p Dave
19 * Nailed the missing stats bug to the wall. Problem was optimized build
20 * and using GET_DATA() with array elements. BLECH.
22 * 17 7/26/99 6:07p Dave
23 * Removed some warnings.
25 * 16 7/26/99 5:50p Dave
26 * Revised ingame join. Better? We'll see....
28 * 15 7/24/99 5:48p Jefff
29 * converted to new UI stuff -- added 1024 support
31 * 14 7/08/99 10:53a Dave
32 * New multiplayer interpolation scheme. Not 100% done yet, but still
33 * better than the old way.
35 * 13 4/21/99 6:15p Dave
36 * Did some serious housecleaning in the beam code. Made it ready to go
37 * for anti-fighter "pulse" weapons. Fixed collision pair creation. Added
38 * a handy macro for recalculating collision pairs for a given object.
40 * 12 3/10/99 6:50p Dave
41 * Changed the way we buffer packets for all clients. Optimized turret
42 * fired packets. Did some weapon firing optimizations.
44 * 11 3/09/99 6:24p Dave
45 * More work on object update revamping. Identified several sources of
46 * unnecessary bandwidth.
48 * 10 3/08/99 7:03p Dave
49 * First run of new object update system. Looks very promising.
51 * 9 3/01/99 7:39p Dave
52 * Added prioritizing ship respawns. Also fixed respawns in TvT so teams
53 * don't mix respawn points.
55 * 8 1/30/99 5:08p Dave
56 * More new hi-res stuff.Support for nice D3D textures.
58 * 7 1/27/99 9:56a Dave
59 * Temporary checkin of beam weapons for Dan to make cool sounds.
61 * 6 11/19/98 8:03a Dave
62 * Full support for D3-style reliable sockets. Revamped packet lag/loss
63 * system, made it receiver side and at the lowest possible level.
65 * 5 11/17/98 11:12a Dave
66 * Removed player identification by address. Now assign explicit id #'s.
68 * 4 11/05/98 5:55p Dave
69 * Big pass at reducing #includes
71 * 3 10/13/98 9:29a Dave
72 * Started neatening up freespace.h. Many variables renamed and
73 * reorganized. Added AlphaColors.[h,cpp]
75 * 2 10/07/98 10:53a Dave
78 * 1 10/07/98 10:50a Dave
80 * 83 9/18/98 4:54p Dave
81 * Fixed ingame ship select icon problem.
83 * 82 9/18/98 4:23p Dave
84 * Reversed the logic on a bogus assert.
86 * 81 9/18/98 3:13p Allender
87 * actually delete ships from wings when ingame joining. Shoudl get over
88 * problem were too many ships are presend in the mission since we don't
89 * delete unused ships until after ingame join is completed
91 * 80 9/15/98 1:59p Dave
92 * Fixed bonehead mistake calling multi_endgame_ending()
94 * 79 9/11/98 4:14p Dave
95 * Fixed file checksumming of < file_size. Put in more verbose kicking and
96 * PXO stats store reporting.
98 * 78 9/11/98 2:10p Allender
99 * base temporary parse_object's ai_goals to -1 so that we don't try and
100 * free sepxressions that shouldn't be freed
102 * 77 8/07/98 10:16a Allender
103 * use obj_set_flags for the COULD_BE_PLAYER flag
105 * 76 7/24/98 9:27a Dave
106 * Tidied up endgame sequencing by removing several old flags and
107 * standardizing _all_ endgame stuff with a single function call.
109 * 75 6/30/98 2:17p Dave
110 * Revised object update system. Removed updates for all weapons. Put
111 * button info back into control info packet.
113 * 74 6/13/98 6:01p Hoffoss
114 * Externalized all new (or forgot to be added) strings to all the code.
116 * 73 6/13/98 3:18p Hoffoss
117 * NOX()ed out a bunch of strings that shouldn't be translated.
119 * 72 6/10/98 2:56p Dave
120 * Substantial changes to reduce bandwidth and latency problems.
122 * 71 6/04/98 11:46a Dave
123 * Drastically reduce size/rate of client control info update packets. Put
124 * in rate limiting for object updating from server.
126 * 70 5/26/98 11:54a Allender
127 * fix multiplayer problems and sexpression crash
129 * 69 5/25/98 1:33a Allender
130 * fixed timestamp problem for client update packets, small fix for ingame
133 * 68 5/24/98 9:17p Allender
134 * commented out test code to help rectify bogus player objects when
137 * 67 5/23/98 3:16p Allender
138 * work on object update packet optimizations (a new updating system).
139 * Don't allow medals/promotions/badges when playing singple player
140 * missions through the simulator
142 * 66 5/22/98 9:35p Dave
143 * Put in channel based support for PXO. Put in "shutdown" button for
144 * standalone. UI tweaks for TvT
146 * 65 5/21/98 10:03p Allender
147 * add secondary ammo counts to ingame join packets
149 * 64 5/21/98 1:52a Dave
150 * Remove obsolete command line functions. Reduce shield explosion packets
151 * drastically. Tweak PXO screen even more. Fix file xfer system so that
152 * we can guarantee file uniqueness.
154 * 63 5/21/98 12:14a Allender
155 * fix ingame join problems
157 * 62 5/20/98 3:25p Allender
158 * ingame join changes (which probably won't make the final version).
159 * Added RAS code into psnet
161 * 61 5/19/98 11:36p Allender
162 * fixed very nasty mask problem with ingame joiner marking player objects
163 * incorrectly. Named ingame joiner ship and observer ship unique names
165 * 60 5/19/98 8:35p Dave
166 * Revamp PXO channel listing system. Send campaign goals/events to
167 * clients for evaluation. Made lock button pressable on all screens.
169 * 59 5/18/98 12:41a Allender
170 * fixed subsystem problems on clients (i.e. not reporting properly on
171 * damage indicator). Fixed ingame join problem with respawns. minor
174 * 58 5/15/98 4:12p Allender
175 * removed redbook code. Put back in ingame join timer. Major fixups for
176 * stats in multiplayer. Pass correct score, medals, etc when leaving
177 * game. Be sure clients display medals, badges, etc.
179 * 57 5/15/98 1:44p Allender
180 * initialize hotkeys when entering the mission ingame joining
182 * 56 5/11/98 4:33p Allender
183 * fixed ingame join problems -- started to work on new object updating
184 * code (currently ifdef'ed out)
186 * 55 5/09/98 4:31p Chad
187 * Fixed weapon recharge rate problem and fixed weapon link status problem
188 * for ingame joiners.
190 * 54 5/08/98 11:21a Allender
191 * fix ingame join trouble. Small messaging fix. Enable collisions for
194 * 53 5/03/98 7:04p Dave
195 * Make team vs. team work mores smoothly with standalone. Change how host
196 * interacts with standalone for picking missions. Put in a time limit for
197 * ingame join ship select. Fix ingame join ship select screen for Vasudan
200 * 52 5/03/98 2:52p Dave
201 * Removed multiplayer furball mode.
203 * 51 5/02/98 1:47a Dave
204 * Make sure ingame joiners know how many respawns they have left. Tidy up
205 * some multiui stuff.
207 * 50 5/01/98 4:11p Comet
208 * Fixed ship_ets bug. I think.
210 * 49 4/30/98 12:49a Allender
211 * change ship type and weapons of any player wing ship, not just ones
212 * that players currently occupy
214 * 48 4/29/98 9:36p Allender
215 * ingame join tweaks. added network message for countermeasures
217 * 47 4/29/98 12:28p Chad
218 * set packet size when selecting a player's ingame choice
220 * 46 4/25/98 2:02p Dave
221 * Put in multiplayer context help screens. Reworked ingame join ship
222 * select screen. Fixed places where network timestamps get hosed.
224 * 45 4/23/98 11:52p Allender
225 * make homing weapons send their homing object. Fixed ingame joiners so
226 * they bash ship types and weapons correctly when joining
228 * 44 4/23/98 1:49a Allender
229 * major rearm/repair fixes for multiplayer. Fixed respawning of AI ships
230 * to not respawn until 5 seconds after they die. Send escort information
233 * 43 4/22/98 5:53p Dave
234 * Large reworking of endgame sequencing. Updated multi host options
235 * screen for new artwork. Put in checks for host or team captains leaving
238 * 42 4/22/98 4:59p Allender
239 * new multiplayer dead popup. big changes to the comm menu system for
240 * team vs. team. Start of debriefing stuff for team vs. team Make form
241 * on my wing work with individual ships who have high priority orders
243 * 41 4/21/98 11:56p Dave
244 * Put in player deaths statskeeping. Use arrow keys in the ingame join
245 * ship select screen. Don't quit the game if in the debriefing and server
248 * 40 4/20/98 12:40a Allender
249 * fixed nasty problem where network read code was not reentrant. minor
250 * UI tweaks. ingame joiners now get netgame info correctly.
252 * 39 4/07/98 5:42p Dave
253 * Put in support for ui display of voice system status (recording,
254 * playing back, etc). Make sure main hall music is stopped before
255 * entering a multiplayer game via ingame join.
257 * 38 4/06/98 6:47p Allender
258 * be sure that ingame joiner has reasonable current primary and secondary
261 * 37 4/06/98 12:33a Allender
262 * ingame joiners need to unmark all player ships as could be players
263 * before getting ship information from host. Don't send count with
264 * countermeasure fired packet
266 * 36 4/04/98 4:22p Dave
267 * First rev of UDP reliable sockets is done. Seems to work well if not
270 * 35 4/04/98 3:55p Allender
271 * made ingame join send packet to all other clients in the game when in
272 * game joiner selects his ship
274 * 34 4/03/98 1:03a Dave
275 * First pass at unreliable guaranteed delivery packets.
277 * 33 4/02/98 5:36p John
278 * Made the level paging occur at the same time as the level is read in.
280 * 32 3/31/98 4:03p Allender
281 * some ingame join fixed -- make sure ingame joiners have parse objects
282 * for all other players
284 * 31 3/24/98 5:12p Allender
285 * ingame join packet sequencing
296 #include "multiutil.h"
297 #include "multimsgs.h"
299 #include "missionparse.h"
300 #include "freespace.h"
301 #include "gamesequence.h"
306 #include "linklist.h"
307 #include "multi_ingame.h"
308 #include "missionscreencommon.h"
312 #include "multi_observer.h"
313 #include "multi_xfer.h"
314 #include "multi_kick.h"
315 #include "missiongoals.h"
316 #include "mainhallmenu.h"
318 #include "multiteamselect.h"
319 #include "missionweaponchoice.h"
320 #include "multi_endgame.h"
321 #include "hudescort.h"
322 #include "hudshield.h"
323 #include "objcollide.h"
324 #include "missionhotkey.h"
325 #include "multi_campaign.h"
326 #include "multi_obj.h"
327 #include "alphacolors.h"
330 // --------------------------------------------------------------------------------------------------
331 // DAVE's BIGASS INGAME JOIN WARNING/DISCLAIMER
333 // Ingame joining is another delicate system. Although not as delicate as server transfer, it will
334 // help to take as many precautions as possible when handling ingame joins. Please be sure to follow
335 // all the same rules as explained in multi_strans.h
337 // --------------------------------------------------------------------------------------------------
339 // --------------------------------------------------------------------------------------------------
340 // INGAME JOIN DESCRIPTION
342 // 1.) Joiner sends a JOIN packet to the server
343 // 2.) If the server accepts him, he receives an ACCEPT packet in return
344 // 3.) The client then moves into the INGAME_SYNC state to begin receiving data from the server
345 // 4.) The first thing he does on this screen is send his filesig packet to the server. At which
346 // point the server will either let him in or deny him. There are no file transfers ingame.
347 // 5.) The server calls multi_handle_ingame_joiners() once per frame, through multi_do_frame()
348 // 6.) After verifiying or kicking the player because of his file signature, the server tells the
349 // player to load the mission
350 // 7.) When the mission is loaded, the server, sends a netgame update to the client
351 // 8.) Without waiting, the server then begins sending data ship packets to the player
352 // 9.) Upon confirmation of receiving these packets, the server sends wing data packets
353 // 10.) Upon completion of this, the server sends respawn point packets
354 // 11.) Upon completion of this, the server sends a post briefing data block packet containing ship class and
355 // weapon information
356 // 12.) After this, the server sends a player settings packet (to all players for good measure)
357 // 13.) At this point, the server sends a jump into mission packet
358 // 14.) Upon receipt of this packet, the client moves into the ingame ship select state
359 // 15.) The first thing the client does in this state is load the mission data (textures, etc)
360 // 16.) The player is presented with a list of ships he can choose from. He selects one and sends
361 // an INGAME_SHIP_REQUEST to the server.
362 // 17.) The server checks to see if this request is acceptable and sends an INGAME_SHIP_REQUEST back
363 // with the appropriate data.
364 // 18.) If the client received an affirmative, he selects the ship and jumps into the mission, otherwise
365 // he removes it from the list and tries for another ship
366 // --------------------------------------------------------------------------------------------------
369 LOCAL int Ingame_ships_deleted = 0;
370 LOCAL int Ingame_ships_to_delete[MAX_SHIPS];
373 // --------------------------------------------------------------------------------------------------
374 // INGAME JOIN FORWARD DECLARATIONS
377 void multi_ingame_send_ship_update(net_player *p);
379 void multi_ingame_join_check_buttons();
380 void multi_ingame_join_button_pressed(int n);
384 // --------------------------------------------------------------------------------------------------
385 // INGAME JOIN COMMON DEFINITIONS
389 // --------------------------------------------------------------------------------------------------
390 // INGAME JOIN SERVER FUNCTIONS
393 // called on the server to process ingame joiners and move them through the motions of ingame joining
394 void multi_handle_ingame_joiners()
398 Assert( MULTIPLAYER_MASTER );
400 // if my ingame joining flag isn't set, then don't do anything.
401 if ( !(Netgame.flags & NG_FLAG_INGAME_JOINING) ){
405 // traverse through all the players
406 for(idx = 0; idx<MAX_PLAYERS; idx++){
407 // only process ingame joiners
408 if( !(Net_players[idx].flags & NETINFO_FLAG_RELIABLE_CONNECTED) || !(Net_players[idx].flags & NETINFO_FLAG_INGAME_JOIN)){
412 // if we're waiting for players to receive files, then check on their status
413 if(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_FILE_XFER){
414 switch(multi_xfer_get_status(Net_players[idx].s_info.xfer_handle)){
415 // if it has successfully completed, set his ok flag
416 case MULTI_XFER_SUCCESS :
418 Net_players[idx].flags |= NETINFO_FLAG_MISSION_OK;
420 // release the xfer instance handle
421 multi_xfer_release_handle(Net_players[idx].s_info.xfer_handle);
422 Net_players[idx].s_info.xfer_handle = -1;
424 // if it has failed or timed-out, kick the player
425 case MULTI_XFER_TIMEDOUT:
426 case MULTI_XFER_FAIL:
427 // release the xfer handle
428 multi_xfer_release_handle(Net_players[idx].s_info.xfer_handle);
429 Net_players[idx].s_info.xfer_handle = -1;
432 multi_kick_player(idx, 0, KICK_REASON_BAD_XFER);
437 // if the player has verified his file signature then send him the packet to load the mission and mark this down
438 if((Net_players[idx].flags & NETINFO_FLAG_MISSION_OK) && !(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_LOADING_MISSION)){
439 // send the netgame update here as well
440 send_netgame_update_packet(&Net_players[idx]);
441 send_netplayer_update_packet(&Net_players[idx]);
443 // send the packet and mark it down
444 send_netplayer_load_packet(&Net_players[idx]);
445 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_LOADING_MISSION;
448 // once he has finished loading the mission, start sending him ship data packets and mark this down
449 if((Net_players[idx].state == NETPLAYER_STATE_MISSION_LOADED) && !(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_SENDING_SHIPS)){
452 // send the packet and mark it down
453 for (i = 0; i < Num_teams; i++ ) {
454 if(Game_mode & GM_STANDALONE_SERVER){
455 send_wss_slots_data_packet(i, 1, &Net_players[idx], 0);
457 send_wss_slots_data_packet(i, 1, &Net_players[idx]);
461 // mark the netgame as a critical stage in ingame joining so that I don't evaluate mission event/
462 // goals, ship arrivals, etc.
463 Netgame.flags |= NG_FLAG_INGAME_JOINING_CRITICAL;
465 // send the packet and mark it down
466 send_ingame_ships_packet(&Net_players[idx]);
467 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_SENDING_SHIPS;
470 // once he has finished receiving the ship data, start sending him wing data and mark this down
472 if((Net_players[idx].state == NETPLAYER_STATE_INGAME_SHIPS) && !(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_SENDING_WINGS)){
473 // setup the list of wings to send
474 Net_players[idx].s_info.wing_index = 0;
475 Net_players[idx].s_info.wing_index_backup = 0;
477 // send the packet and mark it down
478 send_ingame_wings_packet(&Net_players[idx]);
479 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_SENDING_WINGS;
483 // once he has received the respawn packet, send him the player settings for all the players in the game and mark this down
484 if((Net_players[idx].state == NETPLAYER_STATE_INGAME_SHIPS) && !(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_SENDING_POST)){
485 // reset the critical ingame joining flag so that I as server, will start evaluating mission
487 Netgame.flags &= ~NG_FLAG_INGAME_JOINING_CRITICAL;
489 // send the packet and mark it down
490 if(Game_mode & GM_STANDALONE_SERVER){
491 send_post_sync_data_packet(&Net_players[idx],0);
493 send_post_sync_data_packet(&Net_players[idx]);
495 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_SENDING_POST;
498 // once the settings have been received, send him the jump into mission packet and mark this down. now the joiner
499 // moves into the ship select state (ingame)
500 if((Net_players[idx].state == NETPLAYER_STATE_POST_DATA_ACK) && !(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_PICK_SHIP)){
501 // if this guy is an obsever, create his observer object and be done!
502 if(Net_players[idx].flags & NETINFO_FLAG_OBSERVER){
503 multi_obs_create_observer(&Net_players[idx]);
504 Net_players[idx].flags &= ~(NETINFO_FLAG_INGAME_JOIN);
505 Netgame.flags &= ~(NG_FLAG_INGAME_JOINING_CRITICAL | NG_FLAG_INGAME_JOINING);
508 // send the packet and mark it down
509 send_jump_into_mission_packet(&Net_players[idx]);
510 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_PICK_SHIP;
513 // check to see if his timestamp for ship update (hull, shields, etc) has popped. If so, send some info and reset
514 if(timestamp_elapsed(Net_players[idx].s_info.last_full_update_time)){
516 multi_ingame_send_ship_update(&Net_players[idx]);
518 // reset the timestamp
519 Net_players[idx].s_info.last_full_update_time = timestamp(INGAME_SHIP_UPDATE_TIME);
522 // once he has received the weapon state packet, send him the player settings for all the players in the game and mark this down
523 if(!(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_SENDING_SETS)){
524 // send the packet and mark it down
525 // this will update _ALL_ players in the game which is important
526 send_player_settings_packet();
527 send_player_settings_packet( &Net_players[idx] ); // send directly so he gets the packet
529 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_SENDING_SETS;
534 // the final step for an ingame joining observer - create my observer object, unflag myself as joining and jump into mission
535 void multi_ingame_observer_finish()
537 // create my local observer object
538 multi_obs_create_observer_client();
540 // unflag myself as being an ingame joiner
541 Net_player->flags &= ~(NETINFO_FLAG_INGAME_JOIN);
543 // set my state to be in-mission
544 Net_player->state = NETPLAYER_STATE_IN_MISSION;
545 send_netplayer_update_packet();
547 // jump into the game
548 gameseq_post_event(GS_EVENT_ENTER_GAME);
551 // --------------------------------------------------------------------------------------------------
552 // INGAME DATA SYNC SCREEN
555 // mission sync screen init function for ingame joining
556 void multi_ingame_sync_init()
558 // if we couldn't get the file signature correctly. send some bogus values
559 multi_get_mission_checksum(Game_current_mission_filename);
561 // everyone should re-initialize these
562 init_multiplayer_stats();
564 // reset all sequencing info
565 multi_oo_reset_sequencing();
567 // send the file signature to the host for possible mission file transfer
568 strcpy(Netgame.mission_name,Game_current_mission_filename);
569 send_file_sig_packet(Multi_current_file_checksum,Multi_current_file_length);
571 Ingame_ships_deleted = 0;
574 // mission sync screen do function for ingame joining
575 void multi_ingame_sync_do()
579 // mission sync screen do function for ingame joining
580 void multi_ingame_sync_close()
585 // --------------------------------------------------------------------------------------------------
586 // INGAME SHIP SELECT SCREEN
588 static char *Multi_ingame_join_bitmap_fname[GR_NUM_RESOLUTIONS] = {
589 "MultiIngame", // GR_640
590 "2_MultiIngame" // GR_1024
593 static char *Multi_ingame_join_bitmap_mask_fname[GR_NUM_RESOLUTIONS] = {
594 "MultiIngame-M", // GR_640
595 "2_MultiIngame-M" // GR_1024
600 #define MULTI_INGAME_JOIN_NUM_BUTTONS 2
604 ui_button_info Multi_ingame_join_buttons[GR_NUM_RESOLUTIONS][MULTI_INGAME_JOIN_NUM_BUTTONS] = {
606 ui_button_info( "MIB_00", 532, 434, 510, 413, 0 ), // cancel
607 ui_button_info( "MIB_01", 572, 428, 585, 413, 1 ), // join
610 ui_button_info( "2_MIB_00", 851, 695, 916, 685, 0 ), // cancel
611 ui_button_info( "2_MIB_01", 916, 685, 950, 665, 1 ), // join
615 #define MULTI_INGAME_JOIN_NUM_TEXT 8
617 UI_XSTR Multi_ingame_join_text[GR_NUM_RESOLUTIONS][MULTI_INGAME_JOIN_NUM_TEXT] = {
619 {"Cancel", 387, 510, 413, UI_XSTR_COLOR_PINK, -1, &Multi_ingame_join_buttons[GR_640][MIJ_CANCEL].button},
620 {"Join", 1303, 585, 413, UI_XSTR_COLOR_PINK, -1, &Multi_ingame_join_buttons[GR_640][MIJ_JOIN].button},
621 {"Select Ship", 317, 39, 6, UI_XSTR_COLOR_PINK, -1, NULL},
622 {"name", 1423, 39, 28, UI_XSTR_COLOR_GREEN, -1, NULL},
623 {"class", 1424, 145, 28, UI_XSTR_COLOR_GREEN, -1, NULL},
624 {"status", 1425, 214, 28, UI_XSTR_COLOR_GREEN, -1, NULL},
625 {"primary", 1426, 295, 28, UI_XSTR_COLOR_GREEN, -1, NULL},
626 {"secondary", 1427, 440, 28, UI_XSTR_COLOR_GREEN, -1, NULL}
629 {"Cancel", 387, 843, 665, UI_XSTR_COLOR_PINK, -1, &Multi_ingame_join_buttons[GR_1024][MIJ_CANCEL].button},
630 {"Join", 1303, 950, 665, UI_XSTR_COLOR_PINK, -1, &Multi_ingame_join_buttons[GR_1024][MIJ_JOIN].button},
631 {"Select Ship", 317, 63, 14, UI_XSTR_COLOR_PINK, -1, NULL},
632 {"name", 1423, 63, 45, UI_XSTR_COLOR_GREEN, -1, NULL},
633 {"class", 1424, 233, 45, UI_XSTR_COLOR_GREEN, -1, NULL},
634 {"status", 1425, 343, 45, UI_XSTR_COLOR_GREEN, -1, NULL},
635 {"primary", 1426, 473, 45, UI_XSTR_COLOR_GREEN, -1, NULL},
636 {"secondary", 1427, 704, 45, UI_XSTR_COLOR_GREEN, -1, NULL}
645 static int Mi_width[GR_NUM_RESOLUTIONS] = {
650 static int Mi_height[GR_NUM_RESOLUTIONS] = {
655 static int Mi_spacing[GR_NUM_RESOLUTIONS] = {
660 static int Mi_name_field[GR_NUM_RESOLUTIONS][4] = {
677 static int Mi_class_field[GR_NUM_RESOLUTIONS][4] = {
694 static int Mi_status_field[GR_NUM_RESOLUTIONS][4] = {
711 static int Mi_primary_field[GR_NUM_RESOLUTIONS][4] = {
728 static int Mi_secondary_field[GR_NUM_RESOLUTIONS][4] = {
745 // for timing a player out
746 static int Multi_ingame_timer_coords[GR_NUM_RESOLUTIONS][2] = {
759 //#define MULTI_INGAME_TIME_LEFT_X 26
760 //#define MULTI_INGAME_TIME_LEFT_Y 411
762 #define MULTI_INGAME_TIME_SECONDS (1000 * 15)
763 LOCAL int Ingame_time_left;
765 // uses MULTI_JOIN_REFRESH_TIME as its timestamp
766 UI_WINDOW Multi_ingame_window; // the window object for the join screen
767 UI_BUTTON Multi_ingame_select_button; // for selecting list items
768 int Multi_ingame_bitmap; // the background bitmap
771 #define MULTI_INGAME_MAX_SHIP_ICONS 40
772 typedef struct is_icon {
773 int bmaps[NUM_ICON_FRAMES];
776 is_icon Multi_ingame_ship_icon[MULTI_INGAME_MAX_SHIP_ICONS];
777 int Multi_ingame_num_ship_icons;
779 // # of available ships (also == the # currently being displayed)
780 int Multi_ingame_num_avail;
782 // signatures for each of the available ships
783 ushort Multi_ingame_ship_sigs[MAX_PLAYERS];
785 // net signature of the ship we've requested to grab as an ingame joiner (waiting for server response if >= 0)
786 ushort Multi_ingame_join_sig;
788 // the index into the list of the ship currently selected
789 int Multi_ingame_ship_selected;
791 // temporary stuff - used only until we come up with a more permanent interface for this screen
792 #define MAX_INGAME_SHIPS 50
793 #define INGAME_FINAL_TIMEOUT 4000
795 ushort Ingame_ship_signatures[MAX_INGAME_SHIPS];
796 LOCAL int Ingame_final_timeout;
800 // local variables to hold ship/obj/ai information for the joiner. We need to
801 // create a bogus ship so that packets that the joiner receives during his join
802 // have valid Player_ship, Player_obj, and Player_ai to work with
805 // display the available ships (OF_COULD_BE_PLAYER flagged)
806 void multi_ingame_join_display_avail();
808 // try and scroll the selected ship up
809 void multi_ingame_scroll_select_up();
811 // try and scroll the selected ship down
812 void multi_ingame_scroll_select_down();
814 // handle all timeout details
815 void multi_ingame_handle_timeout();
817 int multi_ingame_get_ship_class_icon(int ship_class)
821 // lookup through all available ship icons
822 for(idx=0;idx<Multi_ingame_num_ship_icons;idx++){
823 if(Multi_ingame_ship_icon[idx].ship_class == ship_class){
832 void multi_ingame_load_icons()
834 int first_frame, num_frames, idx, s_idx;
836 // zero out the icon handles
837 for(idx=0;idx<MULTI_INGAME_MAX_SHIP_ICONS;idx++){
838 Multi_ingame_ship_icon[idx].ship_class = -1;
839 for(s_idx=0;s_idx<NUM_ICON_FRAMES;s_idx++){
840 Multi_ingame_ship_icon[idx].bmaps[s_idx] = -1;
843 Multi_ingame_num_ship_icons = 0;
845 // traverse through all ship types
846 for(idx=0;idx<MAX_SHIP_TYPES;idx++){
847 // if there is a valid icon for this ship
848 if((strlen(Ship_info[idx].icon_filename) > 0) && (Multi_ingame_num_ship_icons < MULTI_INGAME_MAX_SHIP_ICONS)){
849 // set the ship class
850 Multi_ingame_ship_icon[Multi_ingame_num_ship_icons].ship_class = idx;
852 // load in the animation frames for the icon
853 first_frame = bm_load_animation(Ship_info[idx].icon_filename, &num_frames);
854 if ( first_frame == -1 ) {
855 Int3(); // Could not load in icon frames.. get Dave
857 for ( s_idx = 0; s_idx < num_frames; s_idx++ ) {
858 Multi_ingame_ship_icon[Multi_ingame_num_ship_icons].bmaps[s_idx] = first_frame+s_idx;
861 Multi_ingame_num_ship_icons++;
866 void multi_ingame_unload_icons()
870 // unload all the bitmaps
871 for(idx=0;idx<Multi_ingame_num_ship_icons;idx++){
872 for(s_idx=0;s_idx<NUM_ICON_FRAMES;s_idx++){
873 if(Multi_ingame_ship_icon[idx].bmaps[s_idx] != -1){
874 bm_release(Multi_ingame_ship_icon[idx].bmaps[s_idx]);
875 Multi_ingame_ship_icon[idx].bmaps[s_idx] = -1;
881 // ingame join ship selection screen init
882 void multi_ingame_select_init()
884 /// int objnum, wingnum_save,idx, goals_save;
885 // ushort net_signature;
888 Multi_ingame_join_sig = 0;
889 Net_player->player->objnum = -1;
891 // create a ship, then find a ship to copy crucial information from. Save and restore the wing
892 // number to be safe.
894 wingnum_save = Player_start_pobject.wingnum;
895 net_signature = Player_start_pobject.net_signature;
896 goals_save = Player_start_pobject.ai_goals;
897 Player_start_pobject.wingnum = -1;
898 Player_start_pobject.net_signature = 0;
899 Player_start_pobject.ai_goals = -1;
900 objnum = parse_create_object( &Player_start_pobject );
901 Player_start_pobject.wingnum = wingnum_save;
902 Player_start_pobject.net_signature = net_signature;
903 Player_start_pobject.ai_goals = goals_save;
905 if ( objnum == -1 ) {
906 nprintf(("Network", "Bailing ingame join because unable to create parse object player ship\n"));
907 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_INGAME_SHIP);
912 Player_obj = &Objects[objnum];
913 Player_obj->net_signature = 0;
914 Player_ship = &Ships[Player_obj->instance];
915 strcpy(Player_ship->ship_name, NOX("JIP Ship"));
916 Player_ai = &Ai_info[Player_ship->ai_index];
919 // load the temp ship icons
920 multi_ingame_load_icons();
922 // blast all the ingame ship signatures
923 memset(Multi_ingame_ship_sigs,0,sizeof(ushort) * MAX_PLAYERS);
925 // the index into the list of the ship currently selected
926 Multi_ingame_ship_selected = -1;
928 // initialize the time he has left to select a ship
929 Ingame_time_left = timestamp(MULTI_INGAME_TIME_SECONDS);
931 // initialize GUI data
933 // create the interface window
934 Multi_ingame_window.create(0,0,gr_screen.max_w,gr_screen.max_h,0);
935 Multi_ingame_window.set_mask_bmap(Multi_ingame_join_bitmap_mask_fname[gr_screen.res]);
937 // load the background bitmap
938 Multi_ingame_bitmap = bm_load(Multi_ingame_join_bitmap_fname[gr_screen.res]);
939 if(Multi_ingame_bitmap < 0)
940 Error(LOCATION, "Couldn't load background bitmap for ingame join");
942 // create the interface buttons
943 for(idx=0; idx<MULTI_INGAME_JOIN_NUM_BUTTONS; idx++) {
945 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);
947 // set the sound to play when highlighted
948 Multi_ingame_join_buttons[gr_screen.res][idx].button.set_highlight_action(common_play_highlight_sound);
950 // set the ani for the button
951 Multi_ingame_join_buttons[gr_screen.res][idx].button.set_bmaps(Multi_ingame_join_buttons[gr_screen.res][idx].filename);
954 Multi_ingame_join_buttons[gr_screen.res][idx].button.link_hotspot(Multi_ingame_join_buttons[gr_screen.res][idx].hotspot);
958 for(idx=0; idx<MULTI_INGAME_JOIN_NUM_TEXT; idx++) {
959 Multi_ingame_window.add_XSTR(&Multi_ingame_join_text[gr_screen.res][idx]);
962 // create the list item select button
963 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);
964 Multi_ingame_select_button.hide();
966 // load freespace stuff
967 // JAS: Code to do paging used to be here.
970 // process all ship list related details
971 void multi_ingame_ship_list_process()
975 // if we currently don't have any ships selected, but we've got items on the list, select the first one
976 if((Multi_ingame_ship_selected == -1) && (Multi_ingame_num_avail > 0)){
977 gamesnd_play_iface(SND_USER_SELECT);
978 Multi_ingame_ship_selected = 0;
981 // if we currently have a ship selected, but it disappears, select the next ship (is possible0
982 if((Multi_ingame_ship_selected >= 0) && (Multi_ingame_ship_selected >= Multi_ingame_num_avail)){
983 gamesnd_play_iface(SND_USER_SELECT);
984 Multi_ingame_ship_selected = Multi_ingame_num_avail-1;
987 // if the player clicked on the select button, see if the selection has changed
988 if(Multi_ingame_select_button.pressed()){
989 Multi_ingame_select_button.get_mouse_pos(NULL,&y);
990 select_index = y / Mi_spacing[gr_screen.res];
992 // if we've selected a valid item
993 if((select_index >= 0) && (select_index < Multi_ingame_num_avail)){
994 // if we're not selected the same item, play a sound
995 if(Multi_ingame_ship_selected != select_index){
996 gamesnd_play_iface(SND_USER_SELECT);
1000 Multi_ingame_ship_selected = select_index;
1006 // determines if a button was pressed, and acts accordingly
1007 void multi_ingame_join_check_buttons()
1010 for(idx=0; idx<MULTI_INGAME_JOIN_NUM_BUTTONS; idx++) {
1011 // we only really need to check for one button pressed at a time,
1012 // so we can break after finding one.
1013 if(Multi_ingame_join_buttons[gr_screen.res][idx].button.pressed()) {
1014 multi_ingame_join_button_pressed(idx);
1020 // a button was pressed, so make it do its thing
1021 // this is the "acting accordingly" part
1022 void multi_ingame_join_button_pressed(int n)
1026 multi_quit_game(PROMPT_CLIENT);
1029 // don't do further processing if the game is paused
1030 if ( Netgame.game_state == NETGAME_STATE_PAUSED )
1033 if(Multi_ingame_join_sig == 0) {
1034 // if he has a valid ship selected
1035 if(Multi_ingame_ship_selected >= 0) {
1036 gamesnd_play_iface(SND_USER_SELECT);
1038 // select the sig of this ship and send a request for it
1039 Multi_ingame_join_sig = Multi_ingame_ship_sigs[Multi_ingame_ship_selected];
1041 // send a request to the
1042 send_ingame_ship_request_packet(INGAME_SR_REQUEST,Multi_ingame_join_sig);
1044 gamesnd_play_iface(SND_GENERAL_FAIL);
1047 gamesnd_play_iface(SND_GENERAL_FAIL);
1052 // how the hell did this happen?
1058 // ingame join ship selection screen do
1059 void multi_ingame_select_do()
1061 int k = Multi_ingame_window.process();
1063 // process any keypresses
1066 multi_quit_game(PROMPT_CLIENT);
1070 multi_ingame_scroll_select_up();
1074 multi_ingame_scroll_select_down();
1078 // process button presses
1079 // multi_ingame_process_buttons();
1080 multi_ingame_join_check_buttons();
1082 // process any ship list related events
1083 multi_ingame_ship_list_process();
1085 // draw the background, etc
1087 GR_MAYBE_CLEAR_RES(Multi_ingame_bitmap);
1088 if(Multi_ingame_bitmap != -1){
1089 gr_set_bitmap(Multi_ingame_bitmap);
1092 Multi_ingame_window.draw();
1094 // handle all timeout details. blitting, etc
1095 multi_ingame_handle_timeout();
1097 // display the available ships
1098 multi_ingame_join_display_avail();
1104 // ingame join ship select close
1105 void multi_ingame_select_close()
1107 // unload any bitmaps
1108 if(!bm_unload(Multi_ingame_bitmap)){
1109 nprintf(("General","WARNING : could not unload background bitmap %s\n",Multi_ingame_join_bitmap_fname[gr_screen.res]));
1112 // unload all the ship class icons
1113 multi_ingame_unload_icons();
1115 // destroy the UI_WINDOW
1116 Multi_ingame_window.destroy();
1118 // stop main hall music
1119 main_hall_stop_music();
1122 // display an individual ships information, starting at the indicated y pixel value
1123 void multi_ingame_join_display_ship(object *objp,int y_start)
1130 sip = &Ship_info[Ships[objp->instance].ship_info_index];
1132 // blit the ship name itself
1133 gr_set_color_fast(&Color_normal);
1134 gr_string(Mi_name_field[gr_screen.res][MI_FIELD_X],y_start+10, Ships[objp->instance].ship_name);
1136 // blit the ship class icon
1137 icon_num = multi_ingame_get_ship_class_icon(Ships[objp->instance].ship_info_index);
1139 gr_set_bitmap(Multi_ingame_ship_icon[icon_num].bmaps[0]);
1140 gr_bitmap(Mi_class_field[gr_screen.res][MI_FIELD_X] + 15, y_start);
1143 gr_set_color_fast(&Color_bright);
1144 wp = &Ships[objp->instance].weapons;
1146 // blit the ship's primary weapons
1147 y_spacing = (Mi_spacing[gr_screen.res] - (wp->num_primary_banks * 10)) / 2;
1148 for(idx=0;idx<wp->num_primary_banks;idx++){
1149 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);
1152 // blit the ship's secondary weapons
1153 y_spacing = (Mi_spacing[gr_screen.res] - (wp->num_secondary_banks * 10)) / 2;
1154 for(idx=0;idx<wp->num_secondary_banks;idx++){
1155 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);
1158 // blit the shield/hull integrity
1159 hud_shield_show_mini(objp, Mi_status_field[gr_screen.res][MI_FIELD_X] + 15, y_start + 3,5,7);
1162 // display the available ships (OF_COULD_BE_PLAYER flagged)
1163 void multi_ingame_join_display_avail()
1167 // recalculate this # every frame
1168 Multi_ingame_num_avail = 0;
1170 // display a background highlight rectangle for any selected lines
1171 if(Multi_ingame_ship_selected != -1){
1172 int y_start = (Mi_name_field[gr_screen.res][MI_FIELD_Y] + (Multi_ingame_ship_selected * Mi_spacing[gr_screen.res]));
1175 gr_set_color_fast(&Color_bright_blue);
1176 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);
1177 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);
1178 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);
1179 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);
1182 moveup = GET_FIRST(&Ship_obj_list);
1183 while(moveup != END_OF_LIST(&Ship_obj_list)){
1184 if( !(Ships[Objects[moveup->objnum].instance].flags & (SF_DYING|SF_DEPARTING)) && (Objects[moveup->objnum].flags & OF_COULD_BE_PLAYER) ) {
1186 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]));
1188 // set the ship signature
1189 Multi_ingame_ship_sigs[Multi_ingame_num_avail] = Objects[moveup->objnum].net_signature;
1191 // inc the # available
1192 Multi_ingame_num_avail++;
1194 moveup = GET_NEXT(moveup);
1198 // try and scroll the selected ship up
1199 void multi_ingame_scroll_select_up()
1201 if(Multi_ingame_ship_selected > 0){
1202 gamesnd_play_iface(SND_USER_SELECT);
1203 Multi_ingame_ship_selected--;
1205 gamesnd_play_iface(SND_GENERAL_FAIL);
1209 // try and scroll the selected ship down
1210 void multi_ingame_scroll_select_down()
1212 if(Multi_ingame_ship_selected < (Multi_ingame_num_avail - 1)){
1213 gamesnd_play_iface(SND_USER_SELECT);
1214 Multi_ingame_ship_selected++;
1216 gamesnd_play_iface(SND_GENERAL_FAIL);
1220 // handle all timeout details
1221 void multi_ingame_handle_timeout()
1224 // uncomment this block to disable the timer
1225 gr_set_color_fast(&Color_bright_red);
1226 gr_string(Multi_ingame_timer_coords[gr_screen.res][0], Multi_ingame_timer_coords[gr_screen.res][1], "Timer disabled!!");
1230 // if we've timed out, leave the game
1231 if( timestamp_elapsed(Ingame_time_left) ) {
1232 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_INGAME_TIMEOUT, MULTI_END_ERROR_NONE);
1236 // otherwise, blit how much time we have left
1237 int time_left = timestamp_until(Ingame_time_left) / 1000;
1238 char tl_string[100];
1239 gr_set_color_fast(&Color_bright);
1240 memset(tl_string,0,100);
1241 sprintf(tl_string,XSTR("Time remaining : %d s\n",682),time_left);
1242 gr_string(Multi_ingame_timer_coords[gr_screen.res][0], Multi_ingame_timer_coords[gr_screen.res][1], tl_string);
1246 // --------------------------------------------------------------------------------------------------
1247 // PACKET HANDLER functions
1248 // these are also defined in multimsgs.h, but the implementations are in the module for the sake of convenience
1251 #define INGAME_PACKET_SLOP 75 // slop value used for packets to ingame joiner
1253 void process_ingame_ships_packet( ubyte *data, header *hinfo )
1255 int offset, sflags, oflags, team, j;
1257 ushort net_signature;
1259 int team_val, slot_index, idx;
1260 char ship_name[255] = "";
1264 // go through the ship obj list and delete everything. YEAH
1265 if(!Ingame_ships_deleted){
1274 for(idx=0; idx<MAX_SHIPS; idx++){
1275 if((Ships[idx].objnum >= 0) && (Ships[idx].objnum < MAX_OBJECTS)){
1276 obj_delete(Ships[idx].objnum);
1280 Ingame_ships_deleted = 1;
1283 offset = HEADER_LENGTH;
1287 while ( p_type == INGAME_SHIP_NEXT ) {
1289 int ship_num, objnum;
1291 GET_STRING( ship_name );
1292 GET_DATA( net_signature );
1296 GET_DATA( wing_data );
1299 GET_DATA(Wings[wing_data].current_wave);
1300 net_sig_modify = Wings[wing_data].current_wave - 1;
1303 // lookup ship in the original ships array
1304 p_objp = mission_parse_get_original_ship(net_signature);
1306 // if this ship is part of wing not on its current wave, look for its "original" by subtracting out wave #
1307 p_objp = mission_parse_get_arrival_ship((ushort)(net_signature - (ushort)net_sig_modify));
1311 nprintf(("Network", "Couldn't find ship %s in either arrival list or in mission"));
1312 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_INGAME_BOGUS);
1316 // go ahead and create the parse object. Set the network signature of this guy before
1318 // multi_set_network_signature( net_signature, MULTI_SIG_SHIP );
1319 objnum = parse_create_object( p_objp );
1320 ship_num = Objects[objnum].instance;
1321 Objects[objnum].flags = oflags;
1322 Objects[objnum].net_signature = net_signature;
1324 // assign any common data
1325 strcpy(Ships[ship_num].ship_name, ship_name);
1326 Ships[ship_num].flags = sflags;
1327 Ships[ship_num].team = team;
1328 Ships[ship_num].wingnum = (int)wing_data;
1335 // if we have reached the end of the list and change our network state
1336 if ( p_type == INGAME_SHIP_LIST_EOL ) {
1337 // merge all created list
1338 obj_merge_created_list();
1340 // fixup player ship stuff
1341 for(idx=0; idx<MAX_SHIPS; idx++){
1342 if(Ships[idx].objnum < 0){
1346 // get the team and slot. Team will be -1 when it isn't a part of player wing. So, if
1347 // not -1, then be sure we have a valid slot, then change the ship type, etc.
1348 objp = &Objects[Ships[idx].objnum];
1349 multi_ts_get_team_and_slot(Ships[idx].ship_name, &team_val, &slot_index);
1350 if ( team_val != -1 ) {
1351 Assert( slot_index != -1 );
1353 // change the ship type and the weapons
1354 change_ship_type(objp->instance, Wss_slots_teams[team_val][slot_index].ship_class);
1355 wl_bash_ship_weapons(&Ships[idx].weapons, &Wss_slots_teams[team_val][slot_index]);
1357 // Be sure to mark this ship as as a could_be_player
1358 obj_set_flags( objp, objp->flags | OF_COULD_BE_PLAYER );
1359 objp->flags &= ~OF_PLAYER_SHIP;
1362 // if this is a player ship, make sure we find out who's it is and set their objnum accordingly
1364 for( j = 0; j < MAX_PLAYERS; j++){
1365 if(MULTI_CONNECTED(Net_players[j]) && (Net_players[j].player->objnum == Objects[Ships[idx].objnum].net_signature)) {
1366 // nprintf(("Network", "Making %s ship for %s\n", Ships[shipnum].ship_name, Net_players[j].player->callsign));
1367 multi_assign_player_ship( j, objp, Ships[idx].ship_info_index );
1368 objp->flags |= OF_PLAYER_SHIP;
1369 objp->flags &= ~OF_COULD_BE_PLAYER;
1376 // notify the server that we're all good.
1377 Net_player->state = NETPLAYER_STATE_INGAME_SHIPS;
1378 send_netplayer_update_packet();
1380 // add some mission sync text
1381 multi_common_add_text(XSTR("Ships packet ack (ingame)\n",683));
1385 void send_ingame_ships_packet(net_player *player)
1387 ubyte data[MAX_PACKET_SIZE];
1393 BUILD_HEADER( SHIPS_INGAME_PACKET );
1395 // essentially, we are going to send a list of ship names to the joiner for ships that are not
1396 // in wings. The joiner will take the list, create any ships which should be created, and delete all
1397 // other ships after the list is sent.
1398 for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
1401 shipp = &Ships[Objects[so->objnum].instance];
1404 // if ( shipp->wingnum != -1 ){
1408 if ( Objects[so->objnum].net_signature == STANDALONE_SHIP_SIG ){
1412 // add the ship name and other information such as net signature, ship and object(?) flags.
1413 p_type = INGAME_SHIP_NEXT;
1415 ADD_STRING( shipp->ship_name );
1416 ADD_DATA( Objects[so->objnum].net_signature );
1417 ADD_DATA( shipp->flags );
1418 ADD_DATA( Objects[so->objnum].flags );
1419 ADD_DATA( shipp->team );
1420 wing_data = (short)shipp->wingnum;
1421 ADD_DATA(wing_data);
1423 ADD_DATA(Wings[wing_data].current_wave);
1426 // don't send anymore data if we are getting close to the maximum size of this packet. Send it off and
1428 if ( packet_size > (MAX_PACKET_SIZE - INGAME_PACKET_SLOP) ) {
1429 p_type = INGAME_SHIP_LIST_EOP;
1431 multi_io_send_reliable(player, data, packet_size);
1432 BUILD_HEADER( SHIPS_INGAME_PACKET );
1436 // end of the ship list!!!
1437 p_type = INGAME_SHIP_LIST_EOL;
1439 multi_io_send_reliable(player, data, packet_size);
1442 void process_ingame_wings_packet( ubyte *data, header *hinfo )
1447 // code to process the wing data from a server.
1448 void process_ingame_wings_packet( ubyte *data, header *hinfo )
1450 int offset, wingnum;
1453 offset = HEADER_LENGTH;
1457 // p_type tells us whether to stop or not
1458 while ( p_type == INGAME_WING_NEXT ) {
1461 // get the wingnum and a pointer to it. The game stores data for all wings always, so this
1462 // is perfectly valid
1463 GET_DATA( wingnum );
1464 wingp = &Wings[wingnum];
1467 if ( what == INGAME_WING_NOT_ARRIVED ) {
1468 Assert( wingp->total_arrived_count == 0 ); // this had better be true!!!
1469 } else if ( what == INGAME_WING_DEPARTED ) {
1470 // mark the wing as gone. if it isn't, it soon will be. Maybe we should send more information
1471 // about these wings later (like total_arrived_count, etc), but we will see.
1472 wingp->flags |= WF_WING_GONE;
1474 int total_arrived_count, current_count, current_wave, i, j;
1478 // the wing is present in the mission on the server. Get the crucial information about the
1479 // wing. Then get the ships for this wing in order on the client machine
1480 GET_DATA( total_arrived_count );
1481 GET_DATA( current_count );
1482 GET_DATA( current_wave );
1484 Assert( current_wave > 0 );
1485 Assert( total_arrived_count > 0 );
1487 // for this wing, strip it down to nothing. Let the parse object ocde recreate the
1488 // wing from the parse objects, then bash any weapons, etc for player wings. We need
1489 // to do this because we might actually wind up with > MAX_SHIPS_PER_WING if we
1490 // don't delete them all first, and have a > 0 threshold, and are on something other
1491 // than the first wave. Only do this for non-player wings.
1493 nprintf(("Network", "Clearing %s -- %d ships\n", wingp->name, wingp->current_count));
1494 for ( i = 0; i < wingp->current_count; i++ ) {
1497 index = wingp->ship_index[i];
1498 Assert( index != -1 );
1499 objnum = Ships[index].objnum;
1500 Assert( objnum != -1 );
1502 // delete the object since we are filling the wing again anyway.
1503 obj_delete( objnum );
1504 Objects[objnum].net_signature = 0; // makes this object "invalid" until dead.
1505 if ( Objects[objnum].type == OBJ_GHOST ) {
1506 nprintf(("Network", "Marking ghost objnum %d as dead\n", objnum));
1507 Objects[objnum].flags |= OF_SHOULD_BE_DEAD;
1509 Ingame_ships_to_delete[index] = 0; // be sure that this guy doesn't get deleted, since we already deleted it
1510 wingp->ship_index[i] = -1;
1512 wingp->current_count = 0;
1513 wingp->total_arrived_count = 0;
1515 // now, recreate all the ships needed
1516 for (i = 0; i < current_count; i++ ) {
1517 int which_one, team, slot_index, specific_instance;;
1521 GET_DATA( signature );
1523 // assign which_one to be the given signature - wing's base signature. This let's us
1524 // know which ship to create (i.e. the total_arrivel_count);
1525 which_one = signature - wingp->net_signature;
1526 Assert( (which_one >= 0) && (which_one < (wingp->net_signature + (wingp->wave_count*wingp->num_waves))) );
1527 wingp->total_arrived_count = (ushort)which_one;
1529 // determine which ship in the ahip arrival list this guy is. It is a 0 based index
1530 specific_instance = which_one % wingp->wave_count;
1532 // call parse_wing_create_ships making sure that we only ever create 1 ship at a time. We don't
1533 // want parse_wing_create_ships() to assign network signature either. We will directly
1536 wingp->current_wave = 0; // make it the first wave. Ensures that ships don't get removed off the list
1537 parse_wing_create_ships( wingp, 1, 1, specific_instance );
1538 shipnum = wingp->ship_index[wingp->current_count-1];
1539 Ingame_ships_to_delete[shipnum] = 0; // "unmark" this ship so it doesn't get deleted.
1541 // kind of stupid, but bash the name since it won't get recreated properly from
1542 // the parse_wing_create_ships call.
1543 shipp = &Ships[shipnum];
1544 sprintf(shipp->ship_name, NOX("%s %d"), wingp->name, which_one + 1);
1545 nprintf(("Network", "Created %s\n", shipp->ship_name));
1547 objp = &Objects[shipp->objnum];
1548 objp->net_signature = (ushort)(wingp->net_signature + which_one);
1550 // get the team and slot. Team will be -1 when it isn't a part of player wing. So, if
1551 // not -1, then be sure we have a valid slot, then change the ship type, etc.
1552 multi_ts_get_team_and_slot(shipp->ship_name, &team, &slot_index);
1554 Assert( slot_index != -1 );
1556 // change the ship type and the weapons
1557 change_ship_type(objp->instance, Wss_slots_teams[team][slot_index].ship_class);
1558 wl_bash_ship_weapons(&shipp->weapons,&Wss_slots_teams[team][slot_index]);
1560 // Be sure to mark this ship as as a could_be_player
1561 obj_set_flags( objp, objp->flags | OF_COULD_BE_PLAYER );
1562 objp->flags &= ~OF_PLAYER_SHIP;
1565 // if this is a player ship, make sure we find out who's it is and set their objnum accordingly
1566 for( j = 0; j < MAX_PLAYERS; j++){
1567 if(MULTI_CONNECTED(Net_players[j]) && (Net_players[j].player->objnum == signature)) {
1568 Assert( team != -1 ); // to help trap errors!!!
1569 nprintf(("Network", "Making %s ship for %s\n", Ships[shipnum].ship_name, Net_players[j].player->callsign));
1570 multi_assign_player_ship( j, objp, Ships[shipnum].ship_info_index );
1571 objp->flags |= OF_PLAYER_SHIP;
1572 objp->flags &= ~OF_COULD_BE_PLAYER;
1579 // we will have no ships in any wings at this point (we didn't create any when we loaded the
1580 // mission). Set the current wave of this wing to be 1 less than was passed in since this value
1581 // will get incremented in parse_wing_create_ships;
1582 wingp->current_wave = current_wave;
1583 wingp->total_arrived_count = total_arrived_count;
1591 // if we have reached the end of the list change our network state
1592 if ( p_type == INGAME_WING_LIST_EOL ) {
1593 Net_player->state = NETPLAYER_STATE_INGAME_WINGS;
1594 send_netplayer_update_packet();
1596 // add some mission sync text
1597 multi_common_add_text(XSTR("Wings packet (ingame)\n",684));
1602 // function to send information about wings. We need to send enough information to let the client
1603 // construct or reconstruct any wings in the mission. We will rely on the fact that the host wing array
1604 // will exactly match the client wing array (in terms of number, and wing names)
1605 void send_ingame_wings_packet( net_player *player )
1607 ubyte data[MAX_PACKET_SIZE];
1612 BUILD_HEADER( WINGS_INGAME_PACKET );
1614 // iterate through the wings list
1615 for ( i = 0; i < num_wings; i++ ) {
1620 p_type = INGAME_WING_NEXT;
1625 // add wing data that the client needs. There are several conditions to send to clients:
1627 // 1. wing hasn't arrived -- total_arrived_count will be 0
1628 // 2. wing is done (or currently departing)
1629 // 3. wing is present (any wave, any number of ships).
1631 // 1 and 2 are easy to handle. (3) is the hardest.
1632 if ( wingp->total_arrived_count == 0 ) {
1633 what = INGAME_WING_NOT_ARRIVED;
1635 } else if ( wingp->flags & (WF_WING_GONE | WF_WING_DEPARTING) ) {
1636 what = INGAME_WING_DEPARTED;
1641 // include to code to possibly send more wing data here in this part of the if/else
1642 // chain. We can do this because MAX_WINGS * 8 (8 being the number of byte for a minimum
1643 // description of a wing) is always less than MAX_PACKET_SIZE. Checking here ensures that
1644 // we have enough space for *this* wing in the packet, and not the largest wing. The
1645 // formula below looks at number of ships in the wing, the name length, length of the signature,
1646 // and the size of the bytes added before the ship names. 32 accounts for a little slop
1647 if ( packet_size > (MAX_PACKET_SIZE - (wingp->current_count * (NAME_LENGTH+2) + 32)) ) {
1648 p_type = INGAME_WING_LIST_EOP;
1650 multi_io_send_reliable(player, data, packet_size);
1651 BUILD_HEADER( WINGS_INGAME_PACKET );
1653 what = INGAME_WING_PRESENT;
1655 ADD_DATA( wingp->total_arrived_count );
1656 ADD_DATA( wingp->current_count );
1657 ADD_DATA( wingp->current_wave );
1659 // add the ship name and net signature of all ships currently in the wing.
1660 for ( j = 0; j < wingp->current_count; j++ ) {
1663 shipp = &Ships[wingp->ship_index[j]];
1664 //ADD_STRING( shipp->ship_name );
1665 ADD_DATA( Objects[shipp->objnum].net_signature );
1671 p_type = INGAME_WING_LIST_EOL;
1674 multi_io_send_reliable(player, data, packet_size);
1678 // send a request or a reply regarding ingame join ship choice
1679 void send_ingame_ship_request_packet(int code,int rdata,net_player *pl)
1681 ubyte data[MAX_PACKET_SIZE],val;
1683 int i, packet_size = 0;
1688 BUILD_HEADER(INGAME_SHIP_REQUEST);
1693 // add any code specific data
1695 case INGAME_SR_REQUEST:
1696 // add the net signature of the ship we're requesting
1697 signature = (ushort)rdata;
1698 ADD_DATA( signature );
1700 case INGAME_SR_CONFIRM:
1701 // get a pointer to the ship
1702 shipp = &Ships[Objects[rdata].instance];
1704 // add the most recent position and orientation for the requested ship
1705 ADD_DATA(Objects[rdata].pos);
1706 ADD_ORIENT(Objects[rdata].orient);
1707 ADD_DATA( Missiontime );
1709 // add the # of respawns this ship has left
1710 pobj = mission_parse_get_arrival_ship( Objects[rdata].net_signature );
1711 Assert(pobj != NULL);
1712 ADD_DATA(pobj->respawn_count);
1714 // add the ships ets settings
1715 val = (ubyte)shipp->weapon_recharge_index;
1717 val = (ubyte)shipp->shield_recharge_index;
1719 val = (ubyte)shipp->engine_recharge_index;
1722 // add current primary and secondary banks, and add link status
1723 val = (ubyte)shipp->weapons.current_primary_bank;
1725 val = (ubyte)shipp->weapons.current_secondary_bank;
1728 // add the current ammo count for secondary banks;
1729 val = (ubyte)shipp->weapons.num_secondary_banks; // for sanity checking
1731 for ( i = 0; i < shipp->weapons.num_secondary_banks; i++ ) {
1732 Assert( shipp->weapons.secondary_bank_ammo[i] < UCHAR_MAX );
1733 val = (ubyte)shipp->weapons.secondary_bank_ammo[i];
1737 // add the link status of weapons
1738 // primary link status
1740 if(shipp->flags & SF_PRIMARY_LINKED){
1743 if(shipp->flags & SF_SECONDARY_DUAL_FIRE){
1751 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
1753 multi_io_send_reliable(pl, data, packet_size);
1755 multi_io_send_reliable(Net_player, data, packet_size);
1758 // if this is a confirm to a player -- send data to the other players in the game telling them
1759 if ( (code == INGAME_SR_CONFIRM) && (Net_player->flags & NETINFO_FLAG_AM_MASTER) ) {
1762 player_num = NET_PLAYER_NUM(pl);
1763 code = INGAME_PLAYER_CHOICE;
1764 BUILD_HEADER(INGAME_SHIP_REQUEST);
1766 ADD_DATA(player_num);
1767 ADD_DATA(Objects[rdata].net_signature);
1768 for (i = 0; i < MAX_PLAYERS; i++ ) {
1769 if(MULTI_CONNECTED(Net_players[i]) && (&Net_players[i] != Net_player) && (i != player_num) ) {
1770 multi_io_send_reliable(&Net_players[i], data, packet_size);
1776 // function to validate all players in the game according to their team select index. If discrepancies
1777 // are found, this function should be able to fix them up.
1778 void multi_ingame_validate_players()
1782 for ( i = 0; i < MAX_PLAYERS; i++ ) {
1783 if( MULTI_CONNECTED(Net_players[i]) && (Net_player != &Net_players[i]) && !MULTI_STANDALONE(Net_players[i]) ) {
1785 int shipnum, objnum, player_objnum;
1787 player_objnum = Net_players[i].player->objnum;
1788 if ( (Objects[player_objnum].type != OBJ_SHIP) || (Objects[player_objnum].type != OBJ_GHOST) ) {
1792 ship_name = multi_ts_get_shipname( Net_players[i].p_info.team, Net_players[i].p_info.ship_index );
1793 Assert( ship_name != NULL );
1794 shipnum = ship_name_lookup( ship_name );
1795 if ( shipnum == -1 ) {
1796 // ship could be respawning
1799 objnum = Ships[shipnum].objnum;
1800 Assert( objnum != -1 );
1802 // if this guy's objnum isn't a ship, then it should proably be a ghost!!
1803 if ( Objects[objnum].type == OBJ_SHIP ) {
1804 if ( objnum != Net_players[i].player->objnum ) {
1806 Net_players[i].player->objnum = objnum;
1809 Assert( Objects[objnum].type == OBJ_GHOST );
1815 // process an ingame ship request packet
1816 void process_ingame_ship_request_packet(ubyte *data, header *hinfo)
1820 int offset = HEADER_LENGTH;
1821 int team, slot_index, i;
1823 ubyte val, num_secondary_banks;
1830 // a request for a ship from an ingame joiner
1831 case INGAME_SR_REQUEST:
1835 // lookup the player and make sure he doesn't already have an objnum (along with possible error conditions)
1836 GET_DATA(sig_request);
1839 player_num = find_player_id(hinfo->id);
1840 if(player_num == -1){
1841 nprintf(("Network","Received ingame ship request packet from unknown player!!\n"));
1845 // make sure this player doesn't already have an object
1846 Assert(MULTI_CONNECTED(Net_players[player_num]));
1847 if(Net_players[player_num].player->objnum != -1){
1848 send_ingame_ship_request_packet(INGAME_SR_DENY,0,&Net_players[player_num]);
1852 // try and find the object
1854 objp = multi_get_network_object(sig_request);
1855 if(objp == NULL || !(objp->flags & OF_COULD_BE_PLAYER)){
1856 send_ingame_ship_request_packet(INGAME_SR_DENY,0,&Net_players[player_num]);
1860 // Assign the player this objnum and ack him
1861 Net_players[player_num].player->objnum = OBJ_INDEX(objp);
1862 Net_players[player_num].state = NETPLAYER_STATE_IN_MISSION; // since he'll do this anyway...
1863 Net_players[player_num].flags &= ~(NETINFO_FLAG_INGAME_JOIN);
1864 multi_assign_player_ship( player_num, objp, Ships[objp->instance].ship_info_index );
1866 // update his ets and link status stuff
1867 multi_server_update_player_weapons(&Net_players[player_num],&Ships[objp->instance]);
1869 objp->flags &= ~(OF_COULD_BE_PLAYER);
1870 objp->flags |= OF_PLAYER_SHIP;
1872 // send a player settings packet to update all other players of this guy's final choices
1873 send_player_settings_packet();
1875 // initialize datarate limiting for this guy
1876 multi_oo_rate_init(&Net_players[player_num]);
1879 send_ingame_ship_request_packet(INGAME_SR_CONFIRM,OBJ_INDEX(objp),&Net_players[player_num]);
1881 // clear my ingame join flag so that others may join
1882 Netgame.flags &= ~NG_FLAG_INGAME_JOINING;
1884 // clear his net stats
1885 scoring_level_init( &(Net_players[player_num].player->stats) );
1888 // a denial for the ship we requested from the server
1889 case INGAME_SR_DENY :
1892 // set this to -1 so we can pick again
1893 Multi_ingame_join_sig = 0;
1896 popup(PF_BODY_BIG | PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You have been denied the requested ship",686));
1899 // a confirmation that we can use the selected ship
1900 case INGAME_SR_CONFIRM:
1901 // object *temp_objp;
1903 // delete the ship this ingame joiner was using. Unassign Player_obj so that this object
1904 // doesn't become a ghost.
1905 // temp_objp = Player_obj;
1906 // Player_obj = NULL;
1907 // obj_delete( OBJ_INDEX(temp_objp) );
1909 // get the object itself
1910 objp = multi_get_network_object(Multi_ingame_join_sig);
1911 Assert(objp != NULL);
1913 // get its most recent position and orientation
1914 GET_DATA(objp->pos);
1915 GET_ORIENT(objp->orient);
1916 GET_DATA( Missiontime );
1917 GET_DATA( respawn_count );
1919 // tell the server I'm in the mission
1920 Net_player->state = NETPLAYER_STATE_IN_MISSION;
1921 send_netplayer_update_packet();
1924 Net_player->player->objnum = OBJ_INDEX(objp);
1926 Player_obj->flags &= ~(OF_COULD_BE_PLAYER);
1927 Player_obj->flags |= OF_PLAYER_SHIP;
1928 multi_assign_player_ship( MY_NET_PLAYER_NUM, objp, Ships[objp->instance].ship_info_index );
1930 // must change the ship type and weapons. An ingame joiner know about the default class
1931 // and weapons for a ship, but these could have changed.
1932 multi_ts_get_team_and_slot(Player_ship->ship_name, &team, &slot_index);
1933 Assert( team != -1 );
1934 Assert( slot_index != -1 );
1935 change_ship_type(objp->instance, Wss_slots_teams[team][slot_index].ship_class);
1936 wl_bash_ship_weapons(&Player_ship->weapons,&Wss_slots_teams[team][slot_index]);
1938 // get the parse object for it and assign the respawn count
1939 pobj = mission_parse_get_arrival_ship( objp->net_signature );
1940 Assert(pobj != NULL);
1941 pobj->respawn_count = respawn_count;
1943 // get the ships ets settings
1945 Player_ship->weapon_recharge_index = val;
1947 Player_ship->shield_recharge_index = val;
1949 Player_ship->engine_recharge_index = val;
1951 // get current primary and secondary banks, and add link status
1953 Player_ship->weapons.current_primary_bank = val;
1955 Player_ship->weapons.current_secondary_bank = val;
1957 // secondary bank ammo data
1958 GET_DATA( num_secondary_banks );
1959 Assert( num_secondary_banks == Player_ship->weapons.num_secondary_banks );
1960 for ( i = 0; i < Player_ship->weapons.num_secondary_banks; i++ ) {
1962 Player_ship->weapons.secondary_bank_ammo[i] = val;
1966 // get the link status of weapons
1969 Player_ship->flags |= SF_PRIMARY_LINKED;
1972 Player_ship->flags |= SF_SECONDARY_DUAL_FIRE;
1976 // be sure that this ships current primary/secondary weapons are valid. Easiest is to just
1977 // bash the values to 0!
1979 if ( Player_ship->weapons.current_primary_bank == -1 )
1980 Player_ship->weapons.current_primary_bank = 0;
1981 if ( Player_ship->weapons.current_secondary_bank == -1 )
1982 Player_ship->weapons.current_secondary_bank = 0;
1985 Net_player->flags &= ~(NETINFO_FLAG_INGAME_JOIN);
1987 // clear all object collision pairs, then add myself to the list
1988 extern void obj_reset_all_collisions();
1989 obj_reset_all_collisions();
1990 // obj_reset_pairs();
1991 // obj_add_pairs( OBJ_INDEX(Player_obj) );
1993 mission_hotkey_set_defaults();
1995 //multi_ingame_validate_players();
1997 // jump into the mission
1998 // NOTE : we check this flag because its possible that the player could have received an endgame packet in the same
1999 // frame as getting this confirmation. In that case, he should be quitting to the main menu. We must not make
2000 // him continue on into the mission
2001 if(!multi_endgame_ending()){
2002 gameseq_post_event(GS_EVENT_ENTER_GAME);
2006 case INGAME_PLAYER_CHOICE: {
2008 ushort net_signature;
2011 // get the player number of this guy, and the net signature of the ship he has chosen
2012 GET_DATA(player_num);
2013 GET_DATA(net_signature);
2016 objp = multi_get_network_object(net_signature);
2017 if ( objp == NULL ) {
2018 // bogus!!! couldn't find the object -- we cannot connect his -- this is really bad!!!
2019 nprintf(("Network", "Couldn't find ship for ingame joiner %s\n", Net_players[player_num].player->callsign));
2022 objp->flags |= OF_PLAYER_SHIP;
2023 objp->flags &= ~OF_COULD_BE_PLAYER;
2025 multi_assign_player_ship( player_num, objp, Ships[objp->instance].ship_info_index );
2033 // --------------------------------------------------------------------------------------------------
2034 // INGAME JOIN FORWARD DEFINITIONS
2037 void multi_ingame_send_ship_update(net_player *p)
2041 // get the first object on the list
2042 moveup = GET_FIRST(&Ship_obj_list);
2044 // go through the list and send all ships which are mark as OF_COULD_BE_PLAYER
2045 while(moveup!=END_OF_LIST(&Ship_obj_list)){
2046 if(Objects[moveup->objnum].flags & OF_COULD_BE_PLAYER){
2048 send_ingame_ship_update_packet(p,&Ships[Objects[moveup->objnum].instance]);
2051 // move to the next item
2052 moveup = GET_NEXT(moveup);
2056 // for now, I guess we'll just send hull and shield % values
2057 void send_ingame_ship_update_packet(net_player *p,ship *sp)
2059 ubyte data[MAX_PACKET_SIZE];
2062 int packet_size = 0;
2065 BUILD_HEADER(INGAME_SHIP_UPDATE);
2067 // just send net signature, shield and hull percentages
2068 objp = &Objects[sp->objnum];
2069 ADD_DATA(objp->net_signature);
2070 ADD_DATA(objp->flags);
2071 ADD_DATA(objp->hull_strength);
2073 // shield percentages
2074 for(idx=0; idx<MAX_SHIELD_SECTIONS; idx++){
2075 f_tmp = objp->shields[idx];
2079 multi_io_send_reliable(p, data, packet_size);
2082 void process_ingame_ship_update_packet(ubyte *data, header *hinfo)
2092 offset = HEADER_LENGTH;
2093 // get the net sig for the ship and do a lookup
2098 lookup = multi_get_network_object(net_sig);
2100 // read in garbage values if we can't find the ship
2101 nprintf(("Network","Got ingame ship update for unknown object\n"));
2103 for(idx=0;idx<MAX_SHIELD_SECTIONS;idx++){
2110 // otherwise read in the ship values
2111 lookup->flags = flags;
2112 GET_DATA(lookup->hull_strength);
2113 for(idx=0;idx<MAX_SHIELD_SECTIONS;idx++){
2115 lookup->shields[idx] = f_tmp;