2 * $Logfile: /Freespace2/code/Network/multi_pause.cpp $
8 * Revision 1.3 2002/05/26 20:22:48 theoddone33
9 * Most of network/ works
11 * Revision 1.2 2002/05/07 03:16:47 theoddone33
12 * The Great Newline Fix
14 * Revision 1.1.1.1 2002/05/03 03:28:10 root
18 * 7 8/22/99 1:19p Dave
19 * Fixed up http proxy code. Cleaned up scoring code. Reverse the order in
20 * which d3d cards are detected.
22 * 6 8/04/99 3:33p Jefff
25 * 5 7/29/99 10:47p Dave
26 * Standardized D3D fogging using vertex fog. Shook out Savage 4 bugs.
28 * 4 11/05/98 5:55p Dave
29 * Big pass at reducing #includes
31 * 3 10/13/98 9:29a Dave
32 * Started neatening up freespace.h. Many variables renamed and
33 * reorganized. Added AlphaColors.[h,cpp]
35 * 2 10/07/98 10:53a Dave
38 * 1 10/07/98 10:50a Dave
40 * 15 9/17/98 3:08p Dave
41 * PXO to non-pxo game warning popup. Player icon stuff in create and join
42 * game screens. Upped server count refresh time in PXO to 35 secs (from
45 * 14 7/24/98 9:27a Dave
46 * Tidied up endgame sequencing by removing several old flags and
47 * standardizing _all_ endgame stuff with a single function call.
49 * 13 6/13/98 3:19p Hoffoss
50 * NOX()ed out a bunch of strings that shouldn't be translated.
52 * 12 5/20/98 2:24a Dave
53 * Fixed server side voice muting. Tweaked multi debrief/endgame
54 * sequencing a bit. Much friendlier for stats tossing/accepting now.
56 * 11 5/19/98 8:35p Dave
57 * Revamp PXO channel listing system. Send campaign goals/events to
58 * clients for evaluation. Made lock button pressable on all screens.
60 * 10 5/10/98 7:06p Dave
61 * Fix endgame sequencing ESC key. Changed how host options warning popups
62 * are done. Fixed pause/message scrollback/options screen problems in mp.
63 * Make sure observer HUD doesn't try to lock weapons.
65 * 9 5/08/98 5:05p Dave
66 * Go to the join game screen when quitting multiplayer. Fixed mission
67 * text chat bugs. Put mission type symbols on the create game list.
68 * Started updating standalone gui controls.
70 * 8 5/07/98 6:26p Dave
71 * Fix strange boundary conditions which arise when players die/respawn
72 * while the game is being ended. Spiff up the chatbox doskey thing a bit.
74 * 7 5/04/98 10:39p Dave
75 * Put in endgame sequencing. Need to check campaign situations.
76 * Realigned ship info on team select screen.
78 * 6 5/03/98 7:04p Dave
79 * Make team vs. team work mores smoothly with standalone. Change how host
80 * interacts with standalone for picking missions. Put in a time limit for
81 * ingame join ship select. Fix ingame join ship select screen for Vasudan
84 * 5 4/27/98 6:02p Dave
85 * Modify how missile scoring works. Fixed a team select ui bug. Speed up
86 * multi_lag system. Put in new main hall.
88 * 4 4/22/98 5:53p Dave
89 * Large reworking of endgame sequencing. Updated multi host options
90 * screen for new artwork. Put in checks for host or team captains leaving
93 * 3 4/16/98 1:55p Dave
94 * Removed unneeded Assert when processing chat packets. Fixed standalone
95 * sequencing bugs. Laid groundwork for join screen server status
98 * 2 4/14/98 5:06p Dave
99 * Don't load or send invalid pilot pics. Fixed chatbox graphic errors.
100 * Made chatbox display team icons in a team vs. team game. Fixed up pause
101 * and endgame sequencing issues.
103 * 1 4/14/98 12:18p Dave
114 #include "freespace.h"
117 #include "gamesequence.h"
118 #include "stand_gui.h"
120 #include "multiutil.h"
122 #include "multimsgs.h"
123 #include "multi_pause.h"
124 #include "multi_endgame.h"
125 #include "multi_pmsg.h"
127 #include "alphacolors.h"
130 // ----------------------------------------------------------------------------------
131 // PAUSE DEFINES/VARS
134 // state of the game (paused or not) on _my_ machine. Obviously this is important for the server
135 // call multi_pause_reset() to reinitialize
136 int Multi_pause_status = 0;
138 // who paused the game
139 net_player *Multi_pause_pauser = NULL;
141 // timestamp for eating keypresses for a while after
142 float Multi_pause_eat = -1.0f;
144 // pause ui screen stuff
145 #define MULTI_PAUSED_NUM_BUTTONS 3
148 #define MP_SCROLL_UP 0
149 #define MP_SCROLL_DOWN 1
150 #define MP_EXIT_MISSION 2
152 // where to place the pauser's callsign
153 int Mp_callsign_coords[GR_NUM_RESOLUTIONS][2] = {
162 ui_button_info Multi_paused_buttons[GR_NUM_RESOLUTIONS][MULTI_PAUSED_NUM_BUTTONS] = {
164 ui_button_info("PB00", 519, 212, -1, -1, 0),
165 ui_button_info("PB01", 519, 252, -1, -1, 1),
166 ui_button_info("PB02", 488, 321, -1, -1, 2),
169 ui_button_info("2_PB00", 831, 339, -1, -1, 0),
170 ui_button_info("2_PB01", 831, 403, -1, -1, 1),
171 ui_button_info("2_PB02", 781, 514, -1, -1, 2),
176 #define MULTI_PAUSED_NUM_TEXT 3
177 UI_XSTR Multi_paused_text[GR_NUM_RESOLUTIONS][MULTI_PAUSED_NUM_BUTTONS] = {
179 { "Exit", 1059, 493, 297, UI_XSTR_COLOR_PINK, -1, &Multi_paused_buttons[0][MP_EXIT_MISSION].button },
180 { "Mission", 1063, 482, 306, UI_XSTR_COLOR_PINK, -1, &Multi_paused_buttons[0][MP_EXIT_MISSION].button },
181 { "Mission Paused", 1440, 107, 356, UI_XSTR_COLOR_PINK, -1, NULL },
184 { "Exit", 1059, 787, 478, UI_XSTR_COLOR_PINK, -1, &Multi_paused_buttons[1][MP_EXIT_MISSION].button },
185 { "Mission", 1063, 778, 490, UI_XSTR_COLOR_PINK, -1, &Multi_paused_buttons[1][MP_EXIT_MISSION].button },
186 { "Mission Paused", 1440, 171, 567, UI_XSTR_COLOR_PINK, -1, NULL },
191 UI_WINDOW *Multi_paused_window;
192 int Multi_paused_screen_id; // backed up screen data
194 void multi_pause_check_buttons();
195 void multi_pause_button_pressed(int n);
197 // (server) evaluate a pause request from the given player (should call for himself as well)
198 void multi_pause_server_eval_request(net_player *pl, int pause);
200 // if this player can unpause
201 int multi_pause_can_unpause(net_player *p);
203 // render the callsign of the guy who paused
204 void multi_pause_render_callsign();
207 // ----------------------------------------------------------------------------------
211 // re-initializes the pause system. call before entering the mission to reset
212 void multi_pause_reset()
214 // set the pause status to 0
215 Multi_pause_status = 0;
217 // null out the pause pointer
218 Multi_pause_pauser = NULL;
220 // eat keys timestamp
221 Multi_pause_eat = -1.0f;
224 // (client) call when receiving a packet indicating we should pause
225 void multi_pause_pause()
229 // if we're already paused, don't do anything
230 if(Multi_pause_status){
235 Assert(!Multi_pause_status);
237 // mark the game as being paused
238 Multi_pause_status = 1;
240 // if we're not already in the pause state
241 if(gameseq_get_state() != GS_STATE_MULTI_PAUSED){
242 // jump into the paused state
243 gameseq_post_event(GS_EVENT_MULTI_PAUSE);
245 // mark the netgame state
246 Netgame.game_state = NETGAME_STATE_PAUSED;
249 // if we're the server of the game, send a packet which will pause the clients in the game now
250 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
251 for(idx=0;idx<MAX_PLAYERS;idx++){
252 if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx])){
253 send_client_update_packet(&Net_players[idx]);
259 // (client) call when receiving a packet indicating we should unpause
260 void multi_pause_unpause()
264 // if we're already unpaused, don't do anything
265 if(!Multi_pause_status){
270 Assert(Multi_pause_status);
272 // mark the game as being unpaused
273 Multi_pause_status = 0;
275 // pop us out of any necessary states (including the pause state !!)
276 multi_handle_state_special();
278 // mark the netgame state
279 Netgame.game_state = NETGAME_STATE_IN_MISSION;
281 // if we're the server of the game, send a packet which will unpause the clients in the game now
282 // if we're the server of the game, send a packet which will pause the clients in the game now
283 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
284 for(idx=0;idx<MAX_PLAYERS;idx++){
285 if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx])){
286 send_client_update_packet(&Net_players[idx]);
292 // send a request to pause or unpause a game (all players should use this function)
293 void multi_pause_request(int pause)
295 // if i'm the server, run it through the eval function right now
296 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
297 multi_pause_server_eval_request(Net_player,pause);
299 // otherwise, send a reliable request packet to the server
301 send_multi_pause_packet(pause);
305 // (server) evaluate a pause request from the given player (should call for himself as well)
306 void multi_pause_server_eval_request(net_player *pl, int pause)
310 // if this is a pause request and we're already in the pause state, do nothing
311 if(pause && Multi_pause_status){
315 // if this is an unpause request and we're already unpaused, do nothing
316 if(!pause && !Multi_pause_status){
320 // get the current state (don't allow pausing from certain states
321 cur_state = gameseq_get_state();
322 if((cur_state == GS_STATE_DEBRIEF) || (cur_state == GS_STATE_MULTI_MISSION_SYNC) || (cur_state == GS_STATE_BRIEFING) ||
323 (cur_state == GS_STATE_STANDALONE_POSTGAME) || (cur_state == GS_STATE_MULTI_STD_WAIT) || (cur_state == GS_STATE_WEAPON_SELECT) ||
324 (cur_state == GS_STATE_TEAM_SELECT) || (cur_state == GS_STATE_MULTI_DOGFIGHT_DEBRIEF)){
328 // if this is a pause request
330 // record who the pauser is
331 Multi_pause_pauser = pl;
336 // if this is an unpause request
338 // if this guy is allowed to unpause the game, do so
339 if(multi_pause_can_unpause(pl)){
340 // unmark the "pauser"
341 Multi_pause_pauser = NULL;
344 multi_pause_unpause();
349 // if this player can unpause
350 int multi_pause_can_unpause(net_player *p)
352 if(!(p->flags & NETINFO_FLAG_GAME_HOST) && (p != Multi_pause_pauser)){
359 // if we still want to eat keys
360 int multi_pause_eat_keys()
362 // if the eat timestamp is negative, don't eat keys
363 if(Multi_pause_eat < 0.0f){
367 // if less than 1 second has passed, continue eating keys
368 if((f2fl(timer_get_fixed_seconds()) - Multi_pause_eat) < 1.0f){
369 nprintf(("Network","PAUSE EATING KEYS\n"));
371 control_config_clear_used_status();
377 // otherwise, disable the timestamp
378 Multi_pause_eat = -1.0f;
384 // ----------------------------------------------------------------------------------
385 // PAUSE UI FUNCTIONS
388 void multi_pause_init(UI_WINDOW *Ui_window)
392 // standalone shouldn't be doing any freespace interface stuff
393 if (Game_mode & GM_STANDALONE_SERVER){
394 std_debug_set_standalone_state_string("Multi paused do");
396 // everyone else should be doing UI stuff
398 // switch off the text messaging system if it is active
399 multi_msg_text_flush();
401 // assign the local reference to the ui window
402 Multi_paused_window = Ui_window;
404 for (i=0; i<MULTI_PAUSED_NUM_BUTTONS; i++) {
406 Multi_paused_buttons[gr_screen.res][i].button.create(Multi_paused_window, "", Multi_paused_buttons[gr_screen.res][i].x, Multi_paused_buttons[gr_screen.res][i].y, 1, 1, 0, 1);
408 // set the highlight action
409 Multi_paused_buttons[gr_screen.res][i].button.set_highlight_action(common_play_highlight_sound);
412 Multi_paused_buttons[gr_screen.res][i].button.set_bmaps(Multi_paused_buttons[gr_screen.res][i].filename);
415 Multi_paused_buttons[gr_screen.res][i].button.link_hotspot(Multi_paused_buttons[gr_screen.res][i].hotspot);
419 for(i=0; i<MULTI_PAUSED_NUM_TEXT; i++){
420 Multi_paused_window->add_XSTR(&Multi_paused_text[gr_screen.res][i]);
423 // close any instances of a chatbox
426 // intiialize our custom chatbox
427 chatbox_create(CHATBOX_FLAG_MULTI_PAUSED);
431 multi_reset_timestamps();
434 void multi_pause_do()
438 // make sure we don't enter this state unless we're in the mission itself
439 Netgame.game_state = NETGAME_STATE_PAUSED;
441 // server of the game should periodically be sending pause packets for good measure
442 if (Net_player->flags & NETINFO_FLAG_AM_MASTER) {
445 if (!(Game_mode & GM_STANDALONE_SERVER)) {
446 // if we're inside of popup code right now, don't process the window
448 // process chatbox and window stuff
449 k = chatbox_process();
450 k = Multi_paused_window->process(k);
455 multi_pause_request(0);
460 // check for any button presses
461 multi_pause_check_buttons();
463 // render the callsign of the guy who paused
464 multi_pause_render_callsign();
466 // render the chatbox
470 // Multi_paused_window->draw_tooltip();
471 Multi_paused_window->draw();
473 // display the voice status indicator
474 multi_common_voice_display_status();
476 // standalone pretty much does nothing here
482 void multi_pause_close()
484 // set the standalonest
485 if (Game_mode & GM_STANDALONE_SERVER) {
486 std_debug_set_standalone_state_string("Game play");
488 // free the screen up
489 gr_free_screen(Multi_paused_screen_id);
492 // eat keys timestamp
493 Multi_pause_eat = f2fl(timer_get_fixed_seconds());
496 multi_reset_timestamps();
498 // clear out control config and keypress info
499 control_config_clear_used_status();
503 void multi_pause_check_buttons()
507 // process any pause buttons which may have been pressed
508 for (idx=0; idx<MULTI_PAUSED_NUM_BUTTONS; idx++){
509 if (Multi_paused_buttons[gr_screen.res][idx].button.pressed()){
510 multi_pause_button_pressed(idx);
515 void multi_pause_button_pressed(int n)
518 // the scroll up button
523 // the scroll down button
524 case MP_SCROLL_DOWN :
525 chatbox_scroll_down();
529 case MP_EXIT_MISSION :
530 multi_quit_game(PROMPT_ALL);
535 // render the callsign of the guy who paused
536 void multi_pause_render_callsign()
540 // write out the callsign of the player who paused the game
541 if((Multi_pause_pauser != NULL) && (Multi_pause_pauser->player != NULL)){
542 memset(pause_str,0,100);
543 strcpy(pause_str,Multi_pause_pauser->player->callsign);
546 gr_set_color_fast(&Color_bright);
547 gr_string(Mp_callsign_coords[gr_screen.res][0], Mp_callsign_coords[gr_screen.res][1], pause_str);