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.3 2002/06/09 04:41:23 relnev
17 * added copyright header
19 * Revision 1.2 2002/06/02 04:26:34 relnev
22 * Revision 1.1.1.1 2002/05/03 03:28:10 root
26 * 20 8/03/99 11:02p Dave
27 * Maybe fixed sync problems in multiplayer.
29 * 19 7/30/99 7:01p Dave
30 * Dogfight escort gauge. Fixed up laser rendering in Glide.
32 * 18 7/28/99 5:33p Dave
33 * Nailed the missing stats bug to the wall. Problem was optimized build
34 * and using GET_DATA() with array elements. BLECH.
36 * 17 7/26/99 6:07p Dave
37 * Removed some warnings.
39 * 16 7/26/99 5:50p Dave
40 * Revised ingame join. Better? We'll see....
42 * 15 7/24/99 5:48p Jefff
43 * converted to new UI stuff -- added 1024 support
45 * 14 7/08/99 10:53a Dave
46 * New multiplayer interpolation scheme. Not 100% done yet, but still
47 * better than the old way.
49 * 13 4/21/99 6:15p Dave
50 * Did some serious housecleaning in the beam code. Made it ready to go
51 * for anti-fighter "pulse" weapons. Fixed collision pair creation. Added
52 * a handy macro for recalculating collision pairs for a given object.
54 * 12 3/10/99 6:50p Dave
55 * Changed the way we buffer packets for all clients. Optimized turret
56 * fired packets. Did some weapon firing optimizations.
58 * 11 3/09/99 6:24p Dave
59 * More work on object update revamping. Identified several sources of
60 * unnecessary bandwidth.
62 * 10 3/08/99 7:03p Dave
63 * First run of new object update system. Looks very promising.
65 * 9 3/01/99 7:39p Dave
66 * Added prioritizing ship respawns. Also fixed respawns in TvT so teams
67 * don't mix respawn points.
69 * 8 1/30/99 5:08p Dave
70 * More new hi-res stuff.Support for nice D3D textures.
72 * 7 1/27/99 9:56a Dave
73 * Temporary checkin of beam weapons for Dan to make cool sounds.
75 * 6 11/19/98 8:03a Dave
76 * Full support for D3-style reliable sockets. Revamped packet lag/loss
77 * system, made it receiver side and at the lowest possible level.
79 * 5 11/17/98 11:12a Dave
80 * Removed player identification by address. Now assign explicit id #'s.
82 * 4 11/05/98 5:55p Dave
83 * Big pass at reducing #includes
85 * 3 10/13/98 9:29a Dave
86 * Started neatening up freespace.h. Many variables renamed and
87 * reorganized. Added AlphaColors.[h,cpp]
89 * 2 10/07/98 10:53a Dave
92 * 1 10/07/98 10:50a Dave
94 * 83 9/18/98 4:54p Dave
95 * Fixed ingame ship select icon problem.
97 * 82 9/18/98 4:23p Dave
98 * Reversed the logic on a bogus assert.
100 * 81 9/18/98 3:13p Allender
101 * actually delete ships from wings when ingame joining. Shoudl get over
102 * problem were too many ships are presend in the mission since we don't
103 * delete unused ships until after ingame join is completed
105 * 80 9/15/98 1:59p Dave
106 * Fixed bonehead mistake calling multi_endgame_ending()
108 * 79 9/11/98 4:14p Dave
109 * Fixed file checksumming of < file_size. Put in more verbose kicking and
110 * PXO stats store reporting.
112 * 78 9/11/98 2:10p Allender
113 * base temporary parse_object's ai_goals to -1 so that we don't try and
114 * free sepxressions that shouldn't be freed
116 * 77 8/07/98 10:16a Allender
117 * use obj_set_flags for the COULD_BE_PLAYER flag
119 * 76 7/24/98 9:27a Dave
120 * Tidied up endgame sequencing by removing several old flags and
121 * standardizing _all_ endgame stuff with a single function call.
123 * 75 6/30/98 2:17p Dave
124 * Revised object update system. Removed updates for all weapons. Put
125 * button info back into control info packet.
127 * 74 6/13/98 6:01p Hoffoss
128 * Externalized all new (or forgot to be added) strings to all the code.
130 * 73 6/13/98 3:18p Hoffoss
131 * NOX()ed out a bunch of strings that shouldn't be translated.
133 * 72 6/10/98 2:56p Dave
134 * Substantial changes to reduce bandwidth and latency problems.
136 * 71 6/04/98 11:46a Dave
137 * Drastically reduce size/rate of client control info update packets. Put
138 * in rate limiting for object updating from server.
140 * 70 5/26/98 11:54a Allender
141 * fix multiplayer problems and sexpression crash
143 * 69 5/25/98 1:33a Allender
144 * fixed timestamp problem for client update packets, small fix for ingame
147 * 68 5/24/98 9:17p Allender
148 * commented out test code to help rectify bogus player objects when
151 * 67 5/23/98 3:16p Allender
152 * work on object update packet optimizations (a new updating system).
153 * Don't allow medals/promotions/badges when playing singple player
154 * missions through the simulator
156 * 66 5/22/98 9:35p Dave
157 * Put in channel based support for PXO. Put in "shutdown" button for
158 * standalone. UI tweaks for TvT
160 * 65 5/21/98 10:03p Allender
161 * add secondary ammo counts to ingame join packets
163 * 64 5/21/98 1:52a Dave
164 * Remove obsolete command line functions. Reduce shield explosion packets
165 * drastically. Tweak PXO screen even more. Fix file xfer system so that
166 * we can guarantee file uniqueness.
168 * 63 5/21/98 12:14a Allender
169 * fix ingame join problems
171 * 62 5/20/98 3:25p Allender
172 * ingame join changes (which probably won't make the final version).
173 * Added RAS code into psnet
175 * 61 5/19/98 11:36p Allender
176 * fixed very nasty mask problem with ingame joiner marking player objects
177 * incorrectly. Named ingame joiner ship and observer ship unique names
179 * 60 5/19/98 8:35p Dave
180 * Revamp PXO channel listing system. Send campaign goals/events to
181 * clients for evaluation. Made lock button pressable on all screens.
183 * 59 5/18/98 12:41a Allender
184 * fixed subsystem problems on clients (i.e. not reporting properly on
185 * damage indicator). Fixed ingame join problem with respawns. minor
188 * 58 5/15/98 4:12p Allender
189 * removed redbook code. Put back in ingame join timer. Major fixups for
190 * stats in multiplayer. Pass correct score, medals, etc when leaving
191 * game. Be sure clients display medals, badges, etc.
193 * 57 5/15/98 1:44p Allender
194 * initialize hotkeys when entering the mission ingame joining
196 * 56 5/11/98 4:33p Allender
197 * fixed ingame join problems -- started to work on new object updating
198 * code (currently ifdef'ed out)
200 * 55 5/09/98 4:31p Chad
201 * Fixed weapon recharge rate problem and fixed weapon link status problem
202 * for ingame joiners.
204 * 54 5/08/98 11:21a Allender
205 * fix ingame join trouble. Small messaging fix. Enable collisions for
208 * 53 5/03/98 7:04p Dave
209 * Make team vs. team work mores smoothly with standalone. Change how host
210 * interacts with standalone for picking missions. Put in a time limit for
211 * ingame join ship select. Fix ingame join ship select screen for Vasudan
214 * 52 5/03/98 2:52p Dave
215 * Removed multiplayer furball mode.
217 * 51 5/02/98 1:47a Dave
218 * Make sure ingame joiners know how many respawns they have left. Tidy up
219 * some multiui stuff.
221 * 50 5/01/98 4:11p Comet
222 * Fixed ship_ets bug. I think.
224 * 49 4/30/98 12:49a Allender
225 * change ship type and weapons of any player wing ship, not just ones
226 * that players currently occupy
228 * 48 4/29/98 9:36p Allender
229 * ingame join tweaks. added network message for countermeasures
231 * 47 4/29/98 12:28p Chad
232 * set packet size when selecting a player's ingame choice
234 * 46 4/25/98 2:02p Dave
235 * Put in multiplayer context help screens. Reworked ingame join ship
236 * select screen. Fixed places where network timestamps get hosed.
238 * 45 4/23/98 11:52p Allender
239 * make homing weapons send their homing object. Fixed ingame joiners so
240 * they bash ship types and weapons correctly when joining
242 * 44 4/23/98 1:49a Allender
243 * major rearm/repair fixes for multiplayer. Fixed respawning of AI ships
244 * to not respawn until 5 seconds after they die. Send escort information
247 * 43 4/22/98 5:53p Dave
248 * Large reworking of endgame sequencing. Updated multi host options
249 * screen for new artwork. Put in checks for host or team captains leaving
252 * 42 4/22/98 4:59p Allender
253 * new multiplayer dead popup. big changes to the comm menu system for
254 * team vs. team. Start of debriefing stuff for team vs. team Make form
255 * on my wing work with individual ships who have high priority orders
257 * 41 4/21/98 11:56p Dave
258 * Put in player deaths statskeeping. Use arrow keys in the ingame join
259 * ship select screen. Don't quit the game if in the debriefing and server
262 * 40 4/20/98 12:40a Allender
263 * fixed nasty problem where network read code was not reentrant. minor
264 * UI tweaks. ingame joiners now get netgame info correctly.
266 * 39 4/07/98 5:42p Dave
267 * Put in support for ui display of voice system status (recording,
268 * playing back, etc). Make sure main hall music is stopped before
269 * entering a multiplayer game via ingame join.
271 * 38 4/06/98 6:47p Allender
272 * be sure that ingame joiner has reasonable current primary and secondary
275 * 37 4/06/98 12:33a Allender
276 * ingame joiners need to unmark all player ships as could be players
277 * before getting ship information from host. Don't send count with
278 * countermeasure fired packet
280 * 36 4/04/98 4:22p Dave
281 * First rev of UDP reliable sockets is done. Seems to work well if not
284 * 35 4/04/98 3:55p Allender
285 * made ingame join send packet to all other clients in the game when in
286 * game joiner selects his ship
288 * 34 4/03/98 1:03a Dave
289 * First pass at unreliable guaranteed delivery packets.
291 * 33 4/02/98 5:36p John
292 * Made the level paging occur at the same time as the level is read in.
294 * 32 3/31/98 4:03p Allender
295 * some ingame join fixed -- make sure ingame joiners have parse objects
296 * for all other players
298 * 31 3/24/98 5:12p Allender
299 * ingame join packet sequencing
310 #include "multiutil.h"
311 #include "multimsgs.h"
313 #include "missionparse.h"
314 #include "freespace.h"
315 #include "gamesequence.h"
320 #include "linklist.h"
321 #include "multi_ingame.h"
322 #include "missionscreencommon.h"
326 #include "multi_observer.h"
327 #include "multi_xfer.h"
328 #include "multi_kick.h"
329 #include "missiongoals.h"
330 #include "mainhallmenu.h"
332 #include "multiteamselect.h"
333 #include "missionweaponchoice.h"
334 #include "multi_endgame.h"
335 #include "hudescort.h"
336 #include "hudshield.h"
337 #include "objcollide.h"
338 #include "missionhotkey.h"
339 #include "multi_campaign.h"
340 #include "multi_obj.h"
341 #include "alphacolors.h"
344 // --------------------------------------------------------------------------------------------------
345 // DAVE's BIGASS INGAME JOIN WARNING/DISCLAIMER
347 // Ingame joining is another delicate system. Although not as delicate as server transfer, it will
348 // help to take as many precautions as possible when handling ingame joins. Please be sure to follow
349 // all the same rules as explained in multi_strans.h
351 // --------------------------------------------------------------------------------------------------
353 // --------------------------------------------------------------------------------------------------
354 // INGAME JOIN DESCRIPTION
356 // 1.) Joiner sends a JOIN packet to the server
357 // 2.) If the server accepts him, he receives an ACCEPT packet in return
358 // 3.) The client then moves into the INGAME_SYNC state to begin receiving data from the server
359 // 4.) The first thing he does on this screen is send his filesig packet to the server. At which
360 // point the server will either let him in or deny him. There are no file transfers ingame.
361 // 5.) The server calls multi_handle_ingame_joiners() once per frame, through multi_do_frame()
362 // 6.) After verifiying or kicking the player because of his file signature, the server tells the
363 // player to load the mission
364 // 7.) When the mission is loaded, the server, sends a netgame update to the client
365 // 8.) Without waiting, the server then begins sending data ship packets to the player
366 // 9.) Upon confirmation of receiving these packets, the server sends wing data packets
367 // 10.) Upon completion of this, the server sends respawn point packets
368 // 11.) Upon completion of this, the server sends a post briefing data block packet containing ship class and
369 // weapon information
370 // 12.) After this, the server sends a player settings packet (to all players for good measure)
371 // 13.) At this point, the server sends a jump into mission packet
372 // 14.) Upon receipt of this packet, the client moves into the ingame ship select state
373 // 15.) The first thing the client does in this state is load the mission data (textures, etc)
374 // 16.) The player is presented with a list of ships he can choose from. He selects one and sends
375 // an INGAME_SHIP_REQUEST to the server.
376 // 17.) The server checks to see if this request is acceptable and sends an INGAME_SHIP_REQUEST back
377 // with the appropriate data.
378 // 18.) If the client received an affirmative, he selects the ship and jumps into the mission, otherwise
379 // he removes it from the list and tries for another ship
380 // --------------------------------------------------------------------------------------------------
383 LOCAL int Ingame_ships_deleted = 0;
384 LOCAL int Ingame_ships_to_delete[MAX_SHIPS];
387 // --------------------------------------------------------------------------------------------------
388 // INGAME JOIN FORWARD DECLARATIONS
391 void multi_ingame_send_ship_update(net_player *p);
393 void multi_ingame_join_check_buttons();
394 void multi_ingame_join_button_pressed(int n);
398 // --------------------------------------------------------------------------------------------------
399 // INGAME JOIN COMMON DEFINITIONS
403 // --------------------------------------------------------------------------------------------------
404 // INGAME JOIN SERVER FUNCTIONS
407 // called on the server to process ingame joiners and move them through the motions of ingame joining
408 void multi_handle_ingame_joiners()
412 Assert( MULTIPLAYER_MASTER );
414 // if my ingame joining flag isn't set, then don't do anything.
415 if ( !(Netgame.flags & NG_FLAG_INGAME_JOINING) ){
419 // traverse through all the players
420 for(idx = 0; idx<MAX_PLAYERS; idx++){
421 // only process ingame joiners
422 if( !(Net_players[idx].flags & NETINFO_FLAG_RELIABLE_CONNECTED) || !(Net_players[idx].flags & NETINFO_FLAG_INGAME_JOIN)){
426 // if we're waiting for players to receive files, then check on their status
427 if(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_FILE_XFER){
428 switch(multi_xfer_get_status(Net_players[idx].s_info.xfer_handle)){
429 // if it has successfully completed, set his ok flag
430 case MULTI_XFER_SUCCESS :
432 Net_players[idx].flags |= NETINFO_FLAG_MISSION_OK;
434 // release the xfer instance handle
435 multi_xfer_release_handle(Net_players[idx].s_info.xfer_handle);
436 Net_players[idx].s_info.xfer_handle = -1;
438 // if it has failed or timed-out, kick the player
439 case MULTI_XFER_TIMEDOUT:
440 case MULTI_XFER_FAIL:
441 // release the xfer handle
442 multi_xfer_release_handle(Net_players[idx].s_info.xfer_handle);
443 Net_players[idx].s_info.xfer_handle = -1;
446 multi_kick_player(idx, 0, KICK_REASON_BAD_XFER);
451 // if the player has verified his file signature then send him the packet to load the mission and mark this down
452 if((Net_players[idx].flags & NETINFO_FLAG_MISSION_OK) && !(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_LOADING_MISSION)){
453 // send the netgame update here as well
454 send_netgame_update_packet(&Net_players[idx]);
455 send_netplayer_update_packet(&Net_players[idx]);
457 // send the packet and mark it down
458 send_netplayer_load_packet(&Net_players[idx]);
459 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_LOADING_MISSION;
462 // once he has finished loading the mission, start sending him ship data packets and mark this down
463 if((Net_players[idx].state == NETPLAYER_STATE_MISSION_LOADED) && !(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_SENDING_SHIPS)){
466 // send the packet and mark it down
467 for (i = 0; i < Num_teams; i++ ) {
468 if(Game_mode & GM_STANDALONE_SERVER){
469 send_wss_slots_data_packet(i, 1, &Net_players[idx], 0);
471 send_wss_slots_data_packet(i, 1, &Net_players[idx]);
475 // mark the netgame as a critical stage in ingame joining so that I don't evaluate mission event/
476 // goals, ship arrivals, etc.
477 Netgame.flags |= NG_FLAG_INGAME_JOINING_CRITICAL;
479 // send the packet and mark it down
480 send_ingame_ships_packet(&Net_players[idx]);
481 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_SENDING_SHIPS;
484 // once he has finished receiving the ship data, start sending him wing data and mark this down
486 if((Net_players[idx].state == NETPLAYER_STATE_INGAME_SHIPS) && !(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_SENDING_WINGS)){
487 // setup the list of wings to send
488 Net_players[idx].s_info.wing_index = 0;
489 Net_players[idx].s_info.wing_index_backup = 0;
491 // send the packet and mark it down
492 send_ingame_wings_packet(&Net_players[idx]);
493 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_SENDING_WINGS;
497 // once he has received the respawn packet, send him the player settings for all the players in the game and mark this down
498 if((Net_players[idx].state == NETPLAYER_STATE_INGAME_SHIPS) && !(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_SENDING_POST)){
499 // reset the critical ingame joining flag so that I as server, will start evaluating mission
501 Netgame.flags &= ~NG_FLAG_INGAME_JOINING_CRITICAL;
503 // send the packet and mark it down
504 if(Game_mode & GM_STANDALONE_SERVER){
505 send_post_sync_data_packet(&Net_players[idx],0);
507 send_post_sync_data_packet(&Net_players[idx]);
509 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_SENDING_POST;
512 // once the settings have been received, send him the jump into mission packet and mark this down. now the joiner
513 // moves into the ship select state (ingame)
514 if((Net_players[idx].state == NETPLAYER_STATE_POST_DATA_ACK) && !(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_PICK_SHIP)){
515 // if this guy is an obsever, create his observer object and be done!
516 if(Net_players[idx].flags & NETINFO_FLAG_OBSERVER){
517 multi_obs_create_observer(&Net_players[idx]);
518 Net_players[idx].flags &= ~(NETINFO_FLAG_INGAME_JOIN);
519 Netgame.flags &= ~(NG_FLAG_INGAME_JOINING_CRITICAL | NG_FLAG_INGAME_JOINING);
522 // send the packet and mark it down
523 send_jump_into_mission_packet(&Net_players[idx]);
524 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_PICK_SHIP;
527 // check to see if his timestamp for ship update (hull, shields, etc) has popped. If so, send some info and reset
528 if(timestamp_elapsed(Net_players[idx].s_info.last_full_update_time)){
530 multi_ingame_send_ship_update(&Net_players[idx]);
532 // reset the timestamp
533 Net_players[idx].s_info.last_full_update_time = timestamp(INGAME_SHIP_UPDATE_TIME);
536 // once he has received the weapon state packet, send him the player settings for all the players in the game and mark this down
537 if(!(Net_players[idx].s_info.ingame_join_flags & INGAME_JOIN_FLAG_SENDING_SETS)){
538 // send the packet and mark it down
539 // this will update _ALL_ players in the game which is important
540 send_player_settings_packet();
541 send_player_settings_packet( &Net_players[idx] ); // send directly so he gets the packet
543 Net_players[idx].s_info.ingame_join_flags |= INGAME_JOIN_FLAG_SENDING_SETS;
548 // the final step for an ingame joining observer - create my observer object, unflag myself as joining and jump into mission
549 void multi_ingame_observer_finish()
551 // create my local observer object
552 multi_obs_create_observer_client();
554 // unflag myself as being an ingame joiner
555 Net_player->flags &= ~(NETINFO_FLAG_INGAME_JOIN);
557 // set my state to be in-mission
558 Net_player->state = NETPLAYER_STATE_IN_MISSION;
559 send_netplayer_update_packet();
561 // jump into the game
562 gameseq_post_event(GS_EVENT_ENTER_GAME);
565 // --------------------------------------------------------------------------------------------------
566 // INGAME DATA SYNC SCREEN
569 // mission sync screen init function for ingame joining
570 void multi_ingame_sync_init()
572 // if we couldn't get the file signature correctly. send some bogus values
573 multi_get_mission_checksum(Game_current_mission_filename);
575 // everyone should re-initialize these
576 init_multiplayer_stats();
578 // reset all sequencing info
579 multi_oo_reset_sequencing();
581 // send the file signature to the host for possible mission file transfer
582 strcpy(Netgame.mission_name,Game_current_mission_filename);
583 send_file_sig_packet(Multi_current_file_checksum,Multi_current_file_length);
585 Ingame_ships_deleted = 0;
588 // mission sync screen do function for ingame joining
589 void multi_ingame_sync_do()
593 // mission sync screen do function for ingame joining
594 void multi_ingame_sync_close()
599 // --------------------------------------------------------------------------------------------------
600 // INGAME SHIP SELECT SCREEN
602 static char *Multi_ingame_join_bitmap_fname[GR_NUM_RESOLUTIONS] = {
603 "MultiIngame", // GR_640
604 "2_MultiIngame" // GR_1024
607 static char *Multi_ingame_join_bitmap_mask_fname[GR_NUM_RESOLUTIONS] = {
608 "MultiIngame-M", // GR_640
609 "2_MultiIngame-M" // GR_1024
614 #define MULTI_INGAME_JOIN_NUM_BUTTONS 2
618 ui_button_info Multi_ingame_join_buttons[GR_NUM_RESOLUTIONS][MULTI_INGAME_JOIN_NUM_BUTTONS] = {
620 ui_button_info( "MIB_00", 532, 434, 510, 413, 0 ), // cancel
621 ui_button_info( "MIB_01", 572, 428, 585, 413, 1 ), // join
624 ui_button_info( "2_MIB_00", 851, 695, 916, 685, 0 ), // cancel
625 ui_button_info( "2_MIB_01", 916, 685, 950, 665, 1 ), // join
629 #define MULTI_INGAME_JOIN_NUM_TEXT 8
631 UI_XSTR Multi_ingame_join_text[GR_NUM_RESOLUTIONS][MULTI_INGAME_JOIN_NUM_TEXT] = {
633 {"Cancel", 387, 510, 413, UI_XSTR_COLOR_PINK, -1, &Multi_ingame_join_buttons[GR_640][MIJ_CANCEL].button},
634 {"Join", 1303, 585, 413, UI_XSTR_COLOR_PINK, -1, &Multi_ingame_join_buttons[GR_640][MIJ_JOIN].button},
635 {"Select Ship", 317, 39, 6, UI_XSTR_COLOR_PINK, -1, NULL},
636 {"name", 1423, 39, 28, UI_XSTR_COLOR_GREEN, -1, NULL},
637 {"class", 1424, 145, 28, UI_XSTR_COLOR_GREEN, -1, NULL},
638 {"status", 1425, 214, 28, UI_XSTR_COLOR_GREEN, -1, NULL},
639 {"primary", 1426, 295, 28, UI_XSTR_COLOR_GREEN, -1, NULL},
640 {"secondary", 1427, 440, 28, UI_XSTR_COLOR_GREEN, -1, NULL}
643 {"Cancel", 387, 843, 665, UI_XSTR_COLOR_PINK, -1, &Multi_ingame_join_buttons[GR_1024][MIJ_CANCEL].button},
644 {"Join", 1303, 950, 665, UI_XSTR_COLOR_PINK, -1, &Multi_ingame_join_buttons[GR_1024][MIJ_JOIN].button},
645 {"Select Ship", 317, 63, 14, UI_XSTR_COLOR_PINK, -1, NULL},
646 {"name", 1423, 63, 45, UI_XSTR_COLOR_GREEN, -1, NULL},
647 {"class", 1424, 233, 45, UI_XSTR_COLOR_GREEN, -1, NULL},
648 {"status", 1425, 343, 45, UI_XSTR_COLOR_GREEN, -1, NULL},
649 {"primary", 1426, 473, 45, UI_XSTR_COLOR_GREEN, -1, NULL},
650 {"secondary", 1427, 704, 45, UI_XSTR_COLOR_GREEN, -1, NULL}
659 static int Mi_width[GR_NUM_RESOLUTIONS] = {
664 static int Mi_height[GR_NUM_RESOLUTIONS] = {
669 static int Mi_spacing[GR_NUM_RESOLUTIONS] = {
674 static int Mi_name_field[GR_NUM_RESOLUTIONS][4] = {
691 static int Mi_class_field[GR_NUM_RESOLUTIONS][4] = {
708 static int Mi_status_field[GR_NUM_RESOLUTIONS][4] = {
725 static int Mi_primary_field[GR_NUM_RESOLUTIONS][4] = {
742 static int Mi_secondary_field[GR_NUM_RESOLUTIONS][4] = {
759 // for timing a player out
760 static int Multi_ingame_timer_coords[GR_NUM_RESOLUTIONS][2] = {
773 //#define MULTI_INGAME_TIME_LEFT_X 26
774 //#define MULTI_INGAME_TIME_LEFT_Y 411
776 #define MULTI_INGAME_TIME_SECONDS (1000 * 15)
777 LOCAL int Ingame_time_left;
779 // uses MULTI_JOIN_REFRESH_TIME as its timestamp
780 UI_WINDOW Multi_ingame_window; // the window object for the join screen
781 UI_BUTTON Multi_ingame_select_button; // for selecting list items
782 int Multi_ingame_bitmap; // the background bitmap
785 #define MULTI_INGAME_MAX_SHIP_ICONS 40
786 typedef struct is_icon {
787 int bmaps[NUM_ICON_FRAMES];
790 is_icon Multi_ingame_ship_icon[MULTI_INGAME_MAX_SHIP_ICONS];
791 int Multi_ingame_num_ship_icons;
793 // # of available ships (also == the # currently being displayed)
794 int Multi_ingame_num_avail;
796 // signatures for each of the available ships
797 ushort Multi_ingame_ship_sigs[MAX_PLAYERS];
799 // net signature of the ship we've requested to grab as an ingame joiner (waiting for server response if >= 0)
800 ushort Multi_ingame_join_sig;
802 // the index into the list of the ship currently selected
803 int Multi_ingame_ship_selected;
805 // temporary stuff - used only until we come up with a more permanent interface for this screen
806 #define MAX_INGAME_SHIPS 50
807 #define INGAME_FINAL_TIMEOUT 4000
809 ushort Ingame_ship_signatures[MAX_INGAME_SHIPS];
813 // local variables to hold ship/obj/ai information for the joiner. We need to
814 // create a bogus ship so that packets that the joiner receives during his join
815 // have valid Player_ship, Player_obj, and Player_ai to work with
818 // display the available ships (OF_COULD_BE_PLAYER flagged)
819 void multi_ingame_join_display_avail();
821 // try and scroll the selected ship up
822 void multi_ingame_scroll_select_up();
824 // try and scroll the selected ship down
825 void multi_ingame_scroll_select_down();
827 // handle all timeout details
828 void multi_ingame_handle_timeout();
830 int multi_ingame_get_ship_class_icon(int ship_class)
834 // lookup through all available ship icons
835 for(idx=0;idx<Multi_ingame_num_ship_icons;idx++){
836 if(Multi_ingame_ship_icon[idx].ship_class == ship_class){
845 void multi_ingame_load_icons()
847 int first_frame, num_frames, idx, s_idx;
849 // zero out the icon handles
850 for(idx=0;idx<MULTI_INGAME_MAX_SHIP_ICONS;idx++){
851 Multi_ingame_ship_icon[idx].ship_class = -1;
852 for(s_idx=0;s_idx<NUM_ICON_FRAMES;s_idx++){
853 Multi_ingame_ship_icon[idx].bmaps[s_idx] = -1;
856 Multi_ingame_num_ship_icons = 0;
858 // traverse through all ship types
859 for(idx=0;idx<MAX_SHIP_TYPES;idx++){
860 // if there is a valid icon for this ship
861 if((strlen(Ship_info[idx].icon_filename) > 0) && (Multi_ingame_num_ship_icons < MULTI_INGAME_MAX_SHIP_ICONS)){
862 // set the ship class
863 Multi_ingame_ship_icon[Multi_ingame_num_ship_icons].ship_class = idx;
865 // load in the animation frames for the icon
866 first_frame = bm_load_animation(Ship_info[idx].icon_filename, &num_frames);
867 if ( first_frame == -1 ) {
868 Int3(); // Could not load in icon frames.. get Dave
870 for ( s_idx = 0; s_idx < num_frames; s_idx++ ) {
871 Multi_ingame_ship_icon[Multi_ingame_num_ship_icons].bmaps[s_idx] = first_frame+s_idx;
874 Multi_ingame_num_ship_icons++;
879 void multi_ingame_unload_icons()
883 // unload all the bitmaps
884 for(idx=0;idx<Multi_ingame_num_ship_icons;idx++){
885 for(s_idx=0;s_idx<NUM_ICON_FRAMES;s_idx++){
886 if(Multi_ingame_ship_icon[idx].bmaps[s_idx] != -1){
887 bm_release(Multi_ingame_ship_icon[idx].bmaps[s_idx]);
888 Multi_ingame_ship_icon[idx].bmaps[s_idx] = -1;
894 // ingame join ship selection screen init
895 void multi_ingame_select_init()
897 /// int objnum, wingnum_save,idx, goals_save;
898 // ushort net_signature;
901 Multi_ingame_join_sig = 0;
902 Net_player->player->objnum = -1;
904 // create a ship, then find a ship to copy crucial information from. Save and restore the wing
905 // number to be safe.
907 wingnum_save = Player_start_pobject.wingnum;
908 net_signature = Player_start_pobject.net_signature;
909 goals_save = Player_start_pobject.ai_goals;
910 Player_start_pobject.wingnum = -1;
911 Player_start_pobject.net_signature = 0;
912 Player_start_pobject.ai_goals = -1;
913 objnum = parse_create_object( &Player_start_pobject );
914 Player_start_pobject.wingnum = wingnum_save;
915 Player_start_pobject.net_signature = net_signature;
916 Player_start_pobject.ai_goals = goals_save;
918 if ( objnum == -1 ) {
919 nprintf(("Network", "Bailing ingame join because unable to create parse object player ship\n"));
920 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_INGAME_SHIP);
925 Player_obj = &Objects[objnum];
926 Player_obj->net_signature = 0;
927 Player_ship = &Ships[Player_obj->instance];
928 strcpy(Player_ship->ship_name, NOX("JIP Ship"));
929 Player_ai = &Ai_info[Player_ship->ai_index];
932 // load the temp ship icons
933 multi_ingame_load_icons();
935 // blast all the ingame ship signatures
936 memset(Multi_ingame_ship_sigs,0,sizeof(ushort) * MAX_PLAYERS);
938 // the index into the list of the ship currently selected
939 Multi_ingame_ship_selected = -1;
941 // initialize the time he has left to select a ship
942 Ingame_time_left = timestamp(MULTI_INGAME_TIME_SECONDS);
944 // initialize GUI data
946 // create the interface window
947 Multi_ingame_window.create(0,0,gr_screen.max_w,gr_screen.max_h,0);
948 Multi_ingame_window.set_mask_bmap(Multi_ingame_join_bitmap_mask_fname[gr_screen.res]);
950 // load the background bitmap
951 Multi_ingame_bitmap = bm_load(Multi_ingame_join_bitmap_fname[gr_screen.res]);
952 if(Multi_ingame_bitmap < 0)
953 Error(LOCATION, "Couldn't load background bitmap for ingame join");
955 // create the interface buttons
956 for(idx=0; idx<MULTI_INGAME_JOIN_NUM_BUTTONS; idx++) {
958 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);
960 // set the sound to play when highlighted
961 Multi_ingame_join_buttons[gr_screen.res][idx].button.set_highlight_action(common_play_highlight_sound);
963 // set the ani for the button
964 Multi_ingame_join_buttons[gr_screen.res][idx].button.set_bmaps(Multi_ingame_join_buttons[gr_screen.res][idx].filename);
967 Multi_ingame_join_buttons[gr_screen.res][idx].button.link_hotspot(Multi_ingame_join_buttons[gr_screen.res][idx].hotspot);
971 for(idx=0; idx<MULTI_INGAME_JOIN_NUM_TEXT; idx++) {
972 Multi_ingame_window.add_XSTR(&Multi_ingame_join_text[gr_screen.res][idx]);
975 // create the list item select button
976 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);
977 Multi_ingame_select_button.hide();
979 // load freespace stuff
980 // JAS: Code to do paging used to be here.
983 // process all ship list related details
984 void multi_ingame_ship_list_process()
988 // if we currently don't have any ships selected, but we've got items on the list, select the first one
989 if((Multi_ingame_ship_selected == -1) && (Multi_ingame_num_avail > 0)){
990 gamesnd_play_iface(SND_USER_SELECT);
991 Multi_ingame_ship_selected = 0;
994 // if we currently have a ship selected, but it disappears, select the next ship (is possible0
995 if((Multi_ingame_ship_selected >= 0) && (Multi_ingame_ship_selected >= Multi_ingame_num_avail)){
996 gamesnd_play_iface(SND_USER_SELECT);
997 Multi_ingame_ship_selected = Multi_ingame_num_avail-1;
1000 // if the player clicked on the select button, see if the selection has changed
1001 if(Multi_ingame_select_button.pressed()){
1002 Multi_ingame_select_button.get_mouse_pos(NULL,&y);
1003 select_index = y / Mi_spacing[gr_screen.res];
1005 // if we've selected a valid item
1006 if((select_index >= 0) && (select_index < Multi_ingame_num_avail)){
1007 // if we're not selected the same item, play a sound
1008 if(Multi_ingame_ship_selected != select_index){
1009 gamesnd_play_iface(SND_USER_SELECT);
1013 Multi_ingame_ship_selected = select_index;
1019 // determines if a button was pressed, and acts accordingly
1020 void multi_ingame_join_check_buttons()
1023 for(idx=0; idx<MULTI_INGAME_JOIN_NUM_BUTTONS; idx++) {
1024 // we only really need to check for one button pressed at a time,
1025 // so we can break after finding one.
1026 if(Multi_ingame_join_buttons[gr_screen.res][idx].button.pressed()) {
1027 multi_ingame_join_button_pressed(idx);
1033 // a button was pressed, so make it do its thing
1034 // this is the "acting accordingly" part
1035 void multi_ingame_join_button_pressed(int n)
1039 multi_quit_game(PROMPT_CLIENT);
1042 // don't do further processing if the game is paused
1043 if ( Netgame.game_state == NETGAME_STATE_PAUSED )
1046 if(Multi_ingame_join_sig == 0) {
1047 // if he has a valid ship selected
1048 if(Multi_ingame_ship_selected >= 0) {
1049 gamesnd_play_iface(SND_USER_SELECT);
1051 // select the sig of this ship and send a request for it
1052 Multi_ingame_join_sig = Multi_ingame_ship_sigs[Multi_ingame_ship_selected];
1054 // send a request to the
1055 send_ingame_ship_request_packet(INGAME_SR_REQUEST,Multi_ingame_join_sig);
1057 gamesnd_play_iface(SND_GENERAL_FAIL);
1060 gamesnd_play_iface(SND_GENERAL_FAIL);
1065 // how the hell did this happen?
1071 // ingame join ship selection screen do
1072 void multi_ingame_select_do()
1074 int k = Multi_ingame_window.process();
1076 // process any keypresses
1079 multi_quit_game(PROMPT_CLIENT);
1083 multi_ingame_scroll_select_up();
1087 multi_ingame_scroll_select_down();
1091 // process button presses
1092 // multi_ingame_process_buttons();
1093 multi_ingame_join_check_buttons();
1095 // process any ship list related events
1096 multi_ingame_ship_list_process();
1098 // draw the background, etc
1100 GR_MAYBE_CLEAR_RES(Multi_ingame_bitmap);
1101 if(Multi_ingame_bitmap != -1){
1102 gr_set_bitmap(Multi_ingame_bitmap);
1105 Multi_ingame_window.draw();
1107 // handle all timeout details. blitting, etc
1108 multi_ingame_handle_timeout();
1110 // display the available ships
1111 multi_ingame_join_display_avail();
1117 // ingame join ship select close
1118 void multi_ingame_select_close()
1120 // unload any bitmaps
1121 if(!bm_unload(Multi_ingame_bitmap)){
1122 nprintf(("General","WARNING : could not unload background bitmap %s\n",Multi_ingame_join_bitmap_fname[gr_screen.res]));
1125 // unload all the ship class icons
1126 multi_ingame_unload_icons();
1128 // destroy the UI_WINDOW
1129 Multi_ingame_window.destroy();
1131 // stop main hall music
1132 main_hall_stop_music();
1135 // display an individual ships information, starting at the indicated y pixel value
1136 void multi_ingame_join_display_ship(object *objp,int y_start)
1143 sip = &Ship_info[Ships[objp->instance].ship_info_index];
1145 // blit the ship name itself
1146 gr_set_color_fast(&Color_normal);
1147 gr_string(Mi_name_field[gr_screen.res][MI_FIELD_X],y_start+10, Ships[objp->instance].ship_name);
1149 // blit the ship class icon
1150 icon_num = multi_ingame_get_ship_class_icon(Ships[objp->instance].ship_info_index);
1152 gr_set_bitmap(Multi_ingame_ship_icon[icon_num].bmaps[0]);
1153 gr_bitmap(Mi_class_field[gr_screen.res][MI_FIELD_X] + 15, y_start);
1156 gr_set_color_fast(&Color_bright);
1157 wp = &Ships[objp->instance].weapons;
1159 // blit the ship's primary weapons
1160 y_spacing = (Mi_spacing[gr_screen.res] - (wp->num_primary_banks * 10)) / 2;
1161 for(idx=0;idx<wp->num_primary_banks;idx++){
1162 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);
1165 // blit the ship's secondary weapons
1166 y_spacing = (Mi_spacing[gr_screen.res] - (wp->num_secondary_banks * 10)) / 2;
1167 for(idx=0;idx<wp->num_secondary_banks;idx++){
1168 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);
1171 // blit the shield/hull integrity
1172 hud_shield_show_mini(objp, Mi_status_field[gr_screen.res][MI_FIELD_X] + 15, y_start + 3,5,7);
1175 // display the available ships (OF_COULD_BE_PLAYER flagged)
1176 void multi_ingame_join_display_avail()
1180 // recalculate this # every frame
1181 Multi_ingame_num_avail = 0;
1183 // display a background highlight rectangle for any selected lines
1184 if(Multi_ingame_ship_selected != -1){
1185 int y_start = (Mi_name_field[gr_screen.res][MI_FIELD_Y] + (Multi_ingame_ship_selected * Mi_spacing[gr_screen.res]));
1188 gr_set_color_fast(&Color_bright_blue);
1189 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);
1190 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);
1191 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);
1192 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);
1195 moveup = GET_FIRST(&Ship_obj_list);
1196 while(moveup != END_OF_LIST(&Ship_obj_list)){
1197 if( !(Ships[Objects[moveup->objnum].instance].flags & (SF_DYING|SF_DEPARTING)) && (Objects[moveup->objnum].flags & OF_COULD_BE_PLAYER) ) {
1199 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]));
1201 // set the ship signature
1202 Multi_ingame_ship_sigs[Multi_ingame_num_avail] = Objects[moveup->objnum].net_signature;
1204 // inc the # available
1205 Multi_ingame_num_avail++;
1207 moveup = GET_NEXT(moveup);
1211 // try and scroll the selected ship up
1212 void multi_ingame_scroll_select_up()
1214 if(Multi_ingame_ship_selected > 0){
1215 gamesnd_play_iface(SND_USER_SELECT);
1216 Multi_ingame_ship_selected--;
1218 gamesnd_play_iface(SND_GENERAL_FAIL);
1222 // try and scroll the selected ship down
1223 void multi_ingame_scroll_select_down()
1225 if(Multi_ingame_ship_selected < (Multi_ingame_num_avail - 1)){
1226 gamesnd_play_iface(SND_USER_SELECT);
1227 Multi_ingame_ship_selected++;
1229 gamesnd_play_iface(SND_GENERAL_FAIL);
1233 // handle all timeout details
1234 void multi_ingame_handle_timeout()
1237 // uncomment this block to disable the timer
1238 gr_set_color_fast(&Color_bright_red);
1239 gr_string(Multi_ingame_timer_coords[gr_screen.res][0], Multi_ingame_timer_coords[gr_screen.res][1], "Timer disabled!!");
1243 // if we've timed out, leave the game
1244 if( timestamp_elapsed(Ingame_time_left) ) {
1245 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_INGAME_TIMEOUT, MULTI_END_ERROR_NONE);
1249 // otherwise, blit how much time we have left
1250 int time_left = timestamp_until(Ingame_time_left) / 1000;
1251 char tl_string[100];
1252 gr_set_color_fast(&Color_bright);
1253 memset(tl_string,0,100);
1254 sprintf(tl_string,XSTR("Time remaining : %d s\n",682),time_left);
1255 gr_string(Multi_ingame_timer_coords[gr_screen.res][0], Multi_ingame_timer_coords[gr_screen.res][1], tl_string);
1259 // --------------------------------------------------------------------------------------------------
1260 // PACKET HANDLER functions
1261 // these are also defined in multimsgs.h, but the implementations are in the module for the sake of convenience
1264 #define INGAME_PACKET_SLOP 75 // slop value used for packets to ingame joiner
1266 void process_ingame_ships_packet( ubyte *data, header *hinfo )
1268 int offset, sflags, oflags, team, j;
1270 ushort net_signature;
1272 int team_val, slot_index, idx;
1273 char ship_name[255] = "";
1277 // go through the ship obj list and delete everything. YEAH
1278 if(!Ingame_ships_deleted){
1287 for(idx=0; idx<MAX_SHIPS; idx++){
1288 if((Ships[idx].objnum >= 0) && (Ships[idx].objnum < MAX_OBJECTS)){
1289 obj_delete(Ships[idx].objnum);
1293 Ingame_ships_deleted = 1;
1296 offset = HEADER_LENGTH;
1300 while ( p_type == INGAME_SHIP_NEXT ) {
1302 int ship_num, objnum;
1304 GET_STRING( ship_name );
1305 GET_DATA( net_signature );
1309 GET_DATA( wing_data );
1312 GET_DATA(Wings[wing_data].current_wave);
1313 net_sig_modify = Wings[wing_data].current_wave - 1;
1316 // lookup ship in the original ships array
1317 p_objp = mission_parse_get_original_ship(net_signature);
1319 // if this ship is part of wing not on its current wave, look for its "original" by subtracting out wave #
1320 p_objp = mission_parse_get_arrival_ship((ushort)(net_signature - (ushort)net_sig_modify));
1324 nprintf(("Network", "Couldn't find ship %s in either arrival list or in mission"));
1325 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_INGAME_BOGUS);
1329 // go ahead and create the parse object. Set the network signature of this guy before
1331 // multi_set_network_signature( net_signature, MULTI_SIG_SHIP );
1332 objnum = parse_create_object( p_objp );
1333 ship_num = Objects[objnum].instance;
1334 Objects[objnum].flags = oflags;
1335 Objects[objnum].net_signature = net_signature;
1337 // assign any common data
1338 strcpy(Ships[ship_num].ship_name, ship_name);
1339 Ships[ship_num].flags = sflags;
1340 Ships[ship_num].team = team;
1341 Ships[ship_num].wingnum = (int)wing_data;
1348 // if we have reached the end of the list and change our network state
1349 if ( p_type == INGAME_SHIP_LIST_EOL ) {
1350 // merge all created list
1351 obj_merge_created_list();
1353 // fixup player ship stuff
1354 for(idx=0; idx<MAX_SHIPS; idx++){
1355 if(Ships[idx].objnum < 0){
1359 // get the team and slot. Team will be -1 when it isn't a part of player wing. So, if
1360 // not -1, then be sure we have a valid slot, then change the ship type, etc.
1361 objp = &Objects[Ships[idx].objnum];
1362 multi_ts_get_team_and_slot(Ships[idx].ship_name, &team_val, &slot_index);
1363 if ( team_val != -1 ) {
1364 Assert( slot_index != -1 );
1366 // change the ship type and the weapons
1367 change_ship_type(objp->instance, Wss_slots_teams[team_val][slot_index].ship_class);
1368 wl_bash_ship_weapons(&Ships[idx].weapons, &Wss_slots_teams[team_val][slot_index]);
1370 // Be sure to mark this ship as as a could_be_player
1371 obj_set_flags( objp, objp->flags | OF_COULD_BE_PLAYER );
1372 objp->flags &= ~OF_PLAYER_SHIP;
1375 // if this is a player ship, make sure we find out who's it is and set their objnum accordingly
1377 for( j = 0; j < MAX_PLAYERS; j++){
1378 if(MULTI_CONNECTED(Net_players[j]) && (Net_players[j].player->objnum == Objects[Ships[idx].objnum].net_signature)) {
1379 // nprintf(("Network", "Making %s ship for %s\n", Ships[shipnum].ship_name, Net_players[j].player->callsign));
1380 multi_assign_player_ship( j, objp, Ships[idx].ship_info_index );
1381 objp->flags |= OF_PLAYER_SHIP;
1382 objp->flags &= ~OF_COULD_BE_PLAYER;
1389 // notify the server that we're all good.
1390 Net_player->state = NETPLAYER_STATE_INGAME_SHIPS;
1391 send_netplayer_update_packet();
1393 // add some mission sync text
1394 multi_common_add_text(XSTR("Ships packet ack (ingame)\n",683));
1398 void send_ingame_ships_packet(net_player *player)
1400 ubyte data[MAX_PACKET_SIZE];
1406 BUILD_HEADER( SHIPS_INGAME_PACKET );
1408 // essentially, we are going to send a list of ship names to the joiner for ships that are not
1409 // in wings. The joiner will take the list, create any ships which should be created, and delete all
1410 // other ships after the list is sent.
1411 for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
1414 shipp = &Ships[Objects[so->objnum].instance];
1417 // if ( shipp->wingnum != -1 ){
1421 if ( Objects[so->objnum].net_signature == STANDALONE_SHIP_SIG ){
1425 // add the ship name and other information such as net signature, ship and object(?) flags.
1426 p_type = INGAME_SHIP_NEXT;
1428 ADD_STRING( shipp->ship_name );
1429 ADD_DATA( Objects[so->objnum].net_signature );
1430 ADD_DATA( shipp->flags );
1431 ADD_DATA( Objects[so->objnum].flags );
1432 ADD_DATA( shipp->team );
1433 wing_data = (short)shipp->wingnum;
1434 ADD_DATA(wing_data);
1436 ADD_DATA(Wings[wing_data].current_wave);
1439 // don't send anymore data if we are getting close to the maximum size of this packet. Send it off and
1441 if ( packet_size > (MAX_PACKET_SIZE - INGAME_PACKET_SLOP) ) {
1442 p_type = INGAME_SHIP_LIST_EOP;
1444 multi_io_send_reliable(player, data, packet_size);
1445 BUILD_HEADER( SHIPS_INGAME_PACKET );
1449 // end of the ship list!!!
1450 p_type = INGAME_SHIP_LIST_EOL;
1452 multi_io_send_reliable(player, data, packet_size);
1455 void process_ingame_wings_packet( ubyte *data, header *hinfo )
1460 // code to process the wing data from a server.
1461 void process_ingame_wings_packet( ubyte *data, header *hinfo )
1463 int offset, wingnum;
1466 offset = HEADER_LENGTH;
1470 // p_type tells us whether to stop or not
1471 while ( p_type == INGAME_WING_NEXT ) {
1474 // get the wingnum and a pointer to it. The game stores data for all wings always, so this
1475 // is perfectly valid
1476 GET_DATA( wingnum );
1477 wingp = &Wings[wingnum];
1480 if ( what == INGAME_WING_NOT_ARRIVED ) {
1481 Assert( wingp->total_arrived_count == 0 ); // this had better be true!!!
1482 } else if ( what == INGAME_WING_DEPARTED ) {
1483 // mark the wing as gone. if it isn't, it soon will be. Maybe we should send more information
1484 // about these wings later (like total_arrived_count, etc), but we will see.
1485 wingp->flags |= WF_WING_GONE;
1487 int total_arrived_count, current_count, current_wave, i, j;
1491 // the wing is present in the mission on the server. Get the crucial information about the
1492 // wing. Then get the ships for this wing in order on the client machine
1493 GET_DATA( total_arrived_count );
1494 GET_DATA( current_count );
1495 GET_DATA( current_wave );
1497 Assert( current_wave > 0 );
1498 Assert( total_arrived_count > 0 );
1500 // for this wing, strip it down to nothing. Let the parse object ocde recreate the
1501 // wing from the parse objects, then bash any weapons, etc for player wings. We need
1502 // to do this because we might actually wind up with > MAX_SHIPS_PER_WING if we
1503 // don't delete them all first, and have a > 0 threshold, and are on something other
1504 // than the first wave. Only do this for non-player wings.
1506 nprintf(("Network", "Clearing %s -- %d ships\n", wingp->name, wingp->current_count));
1507 for ( i = 0; i < wingp->current_count; i++ ) {
1510 index = wingp->ship_index[i];
1511 Assert( index != -1 );
1512 objnum = Ships[index].objnum;
1513 Assert( objnum != -1 );
1515 // delete the object since we are filling the wing again anyway.
1516 obj_delete( objnum );
1517 Objects[objnum].net_signature = 0; // makes this object "invalid" until dead.
1518 if ( Objects[objnum].type == OBJ_GHOST ) {
1519 nprintf(("Network", "Marking ghost objnum %d as dead\n", objnum));
1520 Objects[objnum].flags |= OF_SHOULD_BE_DEAD;
1522 Ingame_ships_to_delete[index] = 0; // be sure that this guy doesn't get deleted, since we already deleted it
1523 wingp->ship_index[i] = -1;
1525 wingp->current_count = 0;
1526 wingp->total_arrived_count = 0;
1528 // now, recreate all the ships needed
1529 for (i = 0; i < current_count; i++ ) {
1530 int which_one, team, slot_index, specific_instance;;
1534 GET_DATA( signature );
1536 // assign which_one to be the given signature - wing's base signature. This let's us
1537 // know which ship to create (i.e. the total_arrivel_count);
1538 which_one = signature - wingp->net_signature;
1539 Assert( (which_one >= 0) && (which_one < (wingp->net_signature + (wingp->wave_count*wingp->num_waves))) );
1540 wingp->total_arrived_count = (ushort)which_one;
1542 // determine which ship in the ahip arrival list this guy is. It is a 0 based index
1543 specific_instance = which_one % wingp->wave_count;
1545 // call parse_wing_create_ships making sure that we only ever create 1 ship at a time. We don't
1546 // want parse_wing_create_ships() to assign network signature either. We will directly
1549 wingp->current_wave = 0; // make it the first wave. Ensures that ships don't get removed off the list
1550 parse_wing_create_ships( wingp, 1, 1, specific_instance );
1551 shipnum = wingp->ship_index[wingp->current_count-1];
1552 Ingame_ships_to_delete[shipnum] = 0; // "unmark" this ship so it doesn't get deleted.
1554 // kind of stupid, but bash the name since it won't get recreated properly from
1555 // the parse_wing_create_ships call.
1556 shipp = &Ships[shipnum];
1557 sprintf(shipp->ship_name, NOX("%s %d"), wingp->name, which_one + 1);
1558 nprintf(("Network", "Created %s\n", shipp->ship_name));
1560 objp = &Objects[shipp->objnum];
1561 objp->net_signature = (ushort)(wingp->net_signature + which_one);
1563 // get the team and slot. Team will be -1 when it isn't a part of player wing. So, if
1564 // not -1, then be sure we have a valid slot, then change the ship type, etc.
1565 multi_ts_get_team_and_slot(shipp->ship_name, &team, &slot_index);
1567 Assert( slot_index != -1 );
1569 // change the ship type and the weapons
1570 change_ship_type(objp->instance, Wss_slots_teams[team][slot_index].ship_class);
1571 wl_bash_ship_weapons(&shipp->weapons,&Wss_slots_teams[team][slot_index]);
1573 // Be sure to mark this ship as as a could_be_player
1574 obj_set_flags( objp, objp->flags | OF_COULD_BE_PLAYER );
1575 objp->flags &= ~OF_PLAYER_SHIP;
1578 // if this is a player ship, make sure we find out who's it is and set their objnum accordingly
1579 for( j = 0; j < MAX_PLAYERS; j++){
1580 if(MULTI_CONNECTED(Net_players[j]) && (Net_players[j].player->objnum == signature)) {
1581 Assert( team != -1 ); // to help trap errors!!!
1582 nprintf(("Network", "Making %s ship for %s\n", Ships[shipnum].ship_name, Net_players[j].player->callsign));
1583 multi_assign_player_ship( j, objp, Ships[shipnum].ship_info_index );
1584 objp->flags |= OF_PLAYER_SHIP;
1585 objp->flags &= ~OF_COULD_BE_PLAYER;
1592 // we will have no ships in any wings at this point (we didn't create any when we loaded the
1593 // mission). Set the current wave of this wing to be 1 less than was passed in since this value
1594 // will get incremented in parse_wing_create_ships;
1595 wingp->current_wave = current_wave;
1596 wingp->total_arrived_count = total_arrived_count;
1604 // if we have reached the end of the list change our network state
1605 if ( p_type == INGAME_WING_LIST_EOL ) {
1606 Net_player->state = NETPLAYER_STATE_INGAME_WINGS;
1607 send_netplayer_update_packet();
1609 // add some mission sync text
1610 multi_common_add_text(XSTR("Wings packet (ingame)\n",684));
1615 // function to send information about wings. We need to send enough information to let the client
1616 // construct or reconstruct any wings in the mission. We will rely on the fact that the host wing array
1617 // will exactly match the client wing array (in terms of number, and wing names)
1618 void send_ingame_wings_packet( net_player *player )
1620 ubyte data[MAX_PACKET_SIZE];
1625 BUILD_HEADER( WINGS_INGAME_PACKET );
1627 // iterate through the wings list
1628 for ( i = 0; i < num_wings; i++ ) {
1633 p_type = INGAME_WING_NEXT;
1638 // add wing data that the client needs. There are several conditions to send to clients:
1640 // 1. wing hasn't arrived -- total_arrived_count will be 0
1641 // 2. wing is done (or currently departing)
1642 // 3. wing is present (any wave, any number of ships).
1644 // 1 and 2 are easy to handle. (3) is the hardest.
1645 if ( wingp->total_arrived_count == 0 ) {
1646 what = INGAME_WING_NOT_ARRIVED;
1648 } else if ( wingp->flags & (WF_WING_GONE | WF_WING_DEPARTING) ) {
1649 what = INGAME_WING_DEPARTED;
1654 // include to code to possibly send more wing data here in this part of the if/else
1655 // chain. We can do this because MAX_WINGS * 8 (8 being the number of byte for a minimum
1656 // description of a wing) is always less than MAX_PACKET_SIZE. Checking here ensures that
1657 // we have enough space for *this* wing in the packet, and not the largest wing. The
1658 // formula below looks at number of ships in the wing, the name length, length of the signature,
1659 // and the size of the bytes added before the ship names. 32 accounts for a little slop
1660 if ( packet_size > (MAX_PACKET_SIZE - (wingp->current_count * (NAME_LENGTH+2) + 32)) ) {
1661 p_type = INGAME_WING_LIST_EOP;
1663 multi_io_send_reliable(player, data, packet_size);
1664 BUILD_HEADER( WINGS_INGAME_PACKET );
1666 what = INGAME_WING_PRESENT;
1668 ADD_DATA( wingp->total_arrived_count );
1669 ADD_DATA( wingp->current_count );
1670 ADD_DATA( wingp->current_wave );
1672 // add the ship name and net signature of all ships currently in the wing.
1673 for ( j = 0; j < wingp->current_count; j++ ) {
1676 shipp = &Ships[wingp->ship_index[j]];
1677 //ADD_STRING( shipp->ship_name );
1678 ADD_DATA( Objects[shipp->objnum].net_signature );
1684 p_type = INGAME_WING_LIST_EOL;
1687 multi_io_send_reliable(player, data, packet_size);
1691 // send a request or a reply regarding ingame join ship choice
1692 void send_ingame_ship_request_packet(int code,int rdata,net_player *pl)
1694 ubyte data[MAX_PACKET_SIZE],val;
1696 int i, packet_size = 0;
1701 BUILD_HEADER(INGAME_SHIP_REQUEST);
1706 // add any code specific data
1708 case INGAME_SR_REQUEST:
1709 // add the net signature of the ship we're requesting
1710 signature = (ushort)rdata;
1711 ADD_DATA( signature );
1713 case INGAME_SR_CONFIRM:
1714 // get a pointer to the ship
1715 shipp = &Ships[Objects[rdata].instance];
1717 // add the most recent position and orientation for the requested ship
1718 ADD_DATA(Objects[rdata].pos);
1719 ADD_ORIENT(Objects[rdata].orient);
1720 ADD_DATA( Missiontime );
1722 // add the # of respawns this ship has left
1723 pobj = mission_parse_get_arrival_ship( Objects[rdata].net_signature );
1724 Assert(pobj != NULL);
1725 ADD_DATA(pobj->respawn_count);
1727 // add the ships ets settings
1728 val = (ubyte)shipp->weapon_recharge_index;
1730 val = (ubyte)shipp->shield_recharge_index;
1732 val = (ubyte)shipp->engine_recharge_index;
1735 // add current primary and secondary banks, and add link status
1736 val = (ubyte)shipp->weapons.current_primary_bank;
1738 val = (ubyte)shipp->weapons.current_secondary_bank;
1741 // add the current ammo count for secondary banks;
1742 val = (ubyte)shipp->weapons.num_secondary_banks; // for sanity checking
1744 for ( i = 0; i < shipp->weapons.num_secondary_banks; i++ ) {
1745 Assert( shipp->weapons.secondary_bank_ammo[i] < UCHAR_MAX );
1746 val = (ubyte)shipp->weapons.secondary_bank_ammo[i];
1750 // add the link status of weapons
1751 // primary link status
1753 if(shipp->flags & SF_PRIMARY_LINKED){
1756 if(shipp->flags & SF_SECONDARY_DUAL_FIRE){
1764 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
1766 multi_io_send_reliable(pl, data, packet_size);
1768 multi_io_send_reliable(Net_player, data, packet_size);
1771 // if this is a confirm to a player -- send data to the other players in the game telling them
1772 if ( (code == INGAME_SR_CONFIRM) && (Net_player->flags & NETINFO_FLAG_AM_MASTER) ) {
1775 player_num = NET_PLAYER_NUM(pl);
1776 code = INGAME_PLAYER_CHOICE;
1777 BUILD_HEADER(INGAME_SHIP_REQUEST);
1779 ADD_DATA(player_num);
1780 ADD_DATA(Objects[rdata].net_signature);
1781 for (i = 0; i < MAX_PLAYERS; i++ ) {
1782 if(MULTI_CONNECTED(Net_players[i]) && (&Net_players[i] != Net_player) && (i != player_num) ) {
1783 multi_io_send_reliable(&Net_players[i], data, packet_size);
1789 // function to validate all players in the game according to their team select index. If discrepancies
1790 // are found, this function should be able to fix them up.
1791 void multi_ingame_validate_players()
1795 for ( i = 0; i < MAX_PLAYERS; i++ ) {
1796 if( MULTI_CONNECTED(Net_players[i]) && (Net_player != &Net_players[i]) && !MULTI_STANDALONE(Net_players[i]) ) {
1798 int shipnum, objnum, player_objnum;
1800 player_objnum = Net_players[i].player->objnum;
1801 if ( (Objects[player_objnum].type != OBJ_SHIP) || (Objects[player_objnum].type != OBJ_GHOST) ) {
1805 ship_name = multi_ts_get_shipname( Net_players[i].p_info.team, Net_players[i].p_info.ship_index );
1806 Assert( ship_name != NULL );
1807 shipnum = ship_name_lookup( ship_name );
1808 if ( shipnum == -1 ) {
1809 // ship could be respawning
1812 objnum = Ships[shipnum].objnum;
1813 Assert( objnum != -1 );
1815 // if this guy's objnum isn't a ship, then it should proably be a ghost!!
1816 if ( Objects[objnum].type == OBJ_SHIP ) {
1817 if ( objnum != Net_players[i].player->objnum ) {
1819 Net_players[i].player->objnum = objnum;
1822 Assert( Objects[objnum].type == OBJ_GHOST );
1828 // process an ingame ship request packet
1829 void process_ingame_ship_request_packet(ubyte *data, header *hinfo)
1833 int offset = HEADER_LENGTH;
1834 int team, slot_index, i;
1836 ubyte val, num_secondary_banks;
1843 // a request for a ship from an ingame joiner
1844 case INGAME_SR_REQUEST:
1848 // lookup the player and make sure he doesn't already have an objnum (along with possible error conditions)
1849 GET_DATA(sig_request);
1852 player_num = find_player_id(hinfo->id);
1853 if(player_num == -1){
1854 nprintf(("Network","Received ingame ship request packet from unknown player!!\n"));
1858 // make sure this player doesn't already have an object
1859 Assert(MULTI_CONNECTED(Net_players[player_num]));
1860 if(Net_players[player_num].player->objnum != -1){
1861 send_ingame_ship_request_packet(INGAME_SR_DENY,0,&Net_players[player_num]);
1865 // try and find the object
1867 objp = multi_get_network_object(sig_request);
1868 if(objp == NULL || !(objp->flags & OF_COULD_BE_PLAYER)){
1869 send_ingame_ship_request_packet(INGAME_SR_DENY,0,&Net_players[player_num]);
1873 // Assign the player this objnum and ack him
1874 Net_players[player_num].player->objnum = OBJ_INDEX(objp);
1875 Net_players[player_num].state = NETPLAYER_STATE_IN_MISSION; // since he'll do this anyway...
1876 Net_players[player_num].flags &= ~(NETINFO_FLAG_INGAME_JOIN);
1877 multi_assign_player_ship( player_num, objp, Ships[objp->instance].ship_info_index );
1879 // update his ets and link status stuff
1880 multi_server_update_player_weapons(&Net_players[player_num],&Ships[objp->instance]);
1882 objp->flags &= ~(OF_COULD_BE_PLAYER);
1883 objp->flags |= OF_PLAYER_SHIP;
1885 // send a player settings packet to update all other players of this guy's final choices
1886 send_player_settings_packet();
1888 // initialize datarate limiting for this guy
1889 multi_oo_rate_init(&Net_players[player_num]);
1892 send_ingame_ship_request_packet(INGAME_SR_CONFIRM,OBJ_INDEX(objp),&Net_players[player_num]);
1894 // clear my ingame join flag so that others may join
1895 Netgame.flags &= ~NG_FLAG_INGAME_JOINING;
1897 // clear his net stats
1898 scoring_level_init( &(Net_players[player_num].player->stats) );
1901 // a denial for the ship we requested from the server
1902 case INGAME_SR_DENY :
1905 // set this to -1 so we can pick again
1906 Multi_ingame_join_sig = 0;
1909 popup(PF_BODY_BIG | PF_USE_AFFIRMATIVE_ICON,1,POPUP_OK,XSTR("You have been denied the requested ship",686));
1912 // a confirmation that we can use the selected ship
1913 case INGAME_SR_CONFIRM:
1914 // object *temp_objp;
1916 // delete the ship this ingame joiner was using. Unassign Player_obj so that this object
1917 // doesn't become a ghost.
1918 // temp_objp = Player_obj;
1919 // Player_obj = NULL;
1920 // obj_delete( OBJ_INDEX(temp_objp) );
1922 // get the object itself
1923 objp = multi_get_network_object(Multi_ingame_join_sig);
1924 Assert(objp != NULL);
1926 // get its most recent position and orientation
1927 GET_DATA(objp->pos);
1928 GET_ORIENT(objp->orient);
1929 GET_DATA( Missiontime );
1930 GET_DATA( respawn_count );
1932 // tell the server I'm in the mission
1933 Net_player->state = NETPLAYER_STATE_IN_MISSION;
1934 send_netplayer_update_packet();
1937 Net_player->player->objnum = OBJ_INDEX(objp);
1939 Player_obj->flags &= ~(OF_COULD_BE_PLAYER);
1940 Player_obj->flags |= OF_PLAYER_SHIP;
1941 multi_assign_player_ship( MY_NET_PLAYER_NUM, objp, Ships[objp->instance].ship_info_index );
1943 // must change the ship type and weapons. An ingame joiner know about the default class
1944 // and weapons for a ship, but these could have changed.
1945 multi_ts_get_team_and_slot(Player_ship->ship_name, &team, &slot_index);
1946 Assert( team != -1 );
1947 Assert( slot_index != -1 );
1948 change_ship_type(objp->instance, Wss_slots_teams[team][slot_index].ship_class);
1949 wl_bash_ship_weapons(&Player_ship->weapons,&Wss_slots_teams[team][slot_index]);
1951 // get the parse object for it and assign the respawn count
1952 pobj = mission_parse_get_arrival_ship( objp->net_signature );
1953 Assert(pobj != NULL);
1954 pobj->respawn_count = respawn_count;
1956 // get the ships ets settings
1958 Player_ship->weapon_recharge_index = val;
1960 Player_ship->shield_recharge_index = val;
1962 Player_ship->engine_recharge_index = val;
1964 // get current primary and secondary banks, and add link status
1966 Player_ship->weapons.current_primary_bank = val;
1968 Player_ship->weapons.current_secondary_bank = val;
1970 // secondary bank ammo data
1971 GET_DATA( num_secondary_banks );
1972 Assert( num_secondary_banks == Player_ship->weapons.num_secondary_banks );
1973 for ( i = 0; i < Player_ship->weapons.num_secondary_banks; i++ ) {
1975 Player_ship->weapons.secondary_bank_ammo[i] = val;
1979 // get the link status of weapons
1982 Player_ship->flags |= SF_PRIMARY_LINKED;
1985 Player_ship->flags |= SF_SECONDARY_DUAL_FIRE;
1989 // be sure that this ships current primary/secondary weapons are valid. Easiest is to just
1990 // bash the values to 0!
1992 if ( Player_ship->weapons.current_primary_bank == -1 )
1993 Player_ship->weapons.current_primary_bank = 0;
1994 if ( Player_ship->weapons.current_secondary_bank == -1 )
1995 Player_ship->weapons.current_secondary_bank = 0;
1998 Net_player->flags &= ~(NETINFO_FLAG_INGAME_JOIN);
2000 // clear all object collision pairs, then add myself to the list
2001 extern void obj_reset_all_collisions();
2002 obj_reset_all_collisions();
2003 // obj_reset_pairs();
2004 // obj_add_pairs( OBJ_INDEX(Player_obj) );
2006 mission_hotkey_set_defaults();
2008 //multi_ingame_validate_players();
2010 // jump into the mission
2011 // NOTE : we check this flag because its possible that the player could have received an endgame packet in the same
2012 // frame as getting this confirmation. In that case, he should be quitting to the main menu. We must not make
2013 // him continue on into the mission
2014 if(!multi_endgame_ending()){
2015 gameseq_post_event(GS_EVENT_ENTER_GAME);
2019 case INGAME_PLAYER_CHOICE: {
2021 ushort net_signature;
2024 // get the player number of this guy, and the net signature of the ship he has chosen
2025 GET_DATA(player_num);
2026 GET_DATA(net_signature);
2029 objp = multi_get_network_object(net_signature);
2030 if ( objp == NULL ) {
2031 // bogus!!! couldn't find the object -- we cannot connect his -- this is really bad!!!
2032 nprintf(("Network", "Couldn't find ship for ingame joiner %s\n", Net_players[player_num].player->callsign));
2035 objp->flags |= OF_PLAYER_SHIP;
2036 objp->flags &= ~OF_COULD_BE_PLAYER;
2038 multi_assign_player_ship( player_num, objp, Ships[objp->instance].ship_info_index );
2046 // --------------------------------------------------------------------------------------------------
2047 // INGAME JOIN FORWARD DEFINITIONS
2050 void multi_ingame_send_ship_update(net_player *p)
2054 // get the first object on the list
2055 moveup = GET_FIRST(&Ship_obj_list);
2057 // go through the list and send all ships which are mark as OF_COULD_BE_PLAYER
2058 while(moveup!=END_OF_LIST(&Ship_obj_list)){
2059 if(Objects[moveup->objnum].flags & OF_COULD_BE_PLAYER){
2061 send_ingame_ship_update_packet(p,&Ships[Objects[moveup->objnum].instance]);
2064 // move to the next item
2065 moveup = GET_NEXT(moveup);
2069 // for now, I guess we'll just send hull and shield % values
2070 void send_ingame_ship_update_packet(net_player *p,ship *sp)
2072 ubyte data[MAX_PACKET_SIZE];
2075 int packet_size = 0;
2078 BUILD_HEADER(INGAME_SHIP_UPDATE);
2080 // just send net signature, shield and hull percentages
2081 objp = &Objects[sp->objnum];
2082 ADD_DATA(objp->net_signature);
2083 ADD_DATA(objp->flags);
2084 ADD_DATA(objp->hull_strength);
2086 // shield percentages
2087 for(idx=0; idx<MAX_SHIELD_SECTIONS; idx++){
2088 f_tmp = objp->shields[idx];
2092 multi_io_send_reliable(p, data, packet_size);
2095 void process_ingame_ship_update_packet(ubyte *data, header *hinfo)
2105 offset = HEADER_LENGTH;
2106 // get the net sig for the ship and do a lookup
2111 lookup = multi_get_network_object(net_sig);
2113 // read in garbage values if we can't find the ship
2114 nprintf(("Network","Got ingame ship update for unknown object\n"));
2116 for(idx=0;idx<MAX_SHIELD_SECTIONS;idx++){
2123 // otherwise read in the ship values
2124 lookup->flags = flags;
2125 GET_DATA(lookup->hull_strength);
2126 for(idx=0;idx<MAX_SHIELD_SECTIONS;idx++){
2128 lookup->shields[idx] = f_tmp;