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_pause.cpp $
16 * Revision 1.4 2002/06/09 04:41:23 relnev
17 * added copyright header
19 * Revision 1.3 2002/05/26 20:22:48 theoddone33
20 * Most of network/ works
22 * Revision 1.2 2002/05/07 03:16:47 theoddone33
23 * The Great Newline Fix
25 * Revision 1.1.1.1 2002/05/03 03:28:10 root
29 * 7 8/22/99 1:19p Dave
30 * Fixed up http proxy code. Cleaned up scoring code. Reverse the order in
31 * which d3d cards are detected.
33 * 6 8/04/99 3:33p Jefff
36 * 5 7/29/99 10:47p Dave
37 * Standardized D3D fogging using vertex fog. Shook out Savage 4 bugs.
39 * 4 11/05/98 5:55p Dave
40 * Big pass at reducing #includes
42 * 3 10/13/98 9:29a Dave
43 * Started neatening up freespace.h. Many variables renamed and
44 * reorganized. Added AlphaColors.[h,cpp]
46 * 2 10/07/98 10:53a Dave
49 * 1 10/07/98 10:50a Dave
51 * 15 9/17/98 3:08p Dave
52 * PXO to non-pxo game warning popup. Player icon stuff in create and join
53 * game screens. Upped server count refresh time in PXO to 35 secs (from
56 * 14 7/24/98 9:27a Dave
57 * Tidied up endgame sequencing by removing several old flags and
58 * standardizing _all_ endgame stuff with a single function call.
60 * 13 6/13/98 3:19p Hoffoss
61 * NOX()ed out a bunch of strings that shouldn't be translated.
63 * 12 5/20/98 2:24a Dave
64 * Fixed server side voice muting. Tweaked multi debrief/endgame
65 * sequencing a bit. Much friendlier for stats tossing/accepting now.
67 * 11 5/19/98 8:35p Dave
68 * Revamp PXO channel listing system. Send campaign goals/events to
69 * clients for evaluation. Made lock button pressable on all screens.
71 * 10 5/10/98 7:06p Dave
72 * Fix endgame sequencing ESC key. Changed how host options warning popups
73 * are done. Fixed pause/message scrollback/options screen problems in mp.
74 * Make sure observer HUD doesn't try to lock weapons.
76 * 9 5/08/98 5:05p Dave
77 * Go to the join game screen when quitting multiplayer. Fixed mission
78 * text chat bugs. Put mission type symbols on the create game list.
79 * Started updating standalone gui controls.
81 * 8 5/07/98 6:26p Dave
82 * Fix strange boundary conditions which arise when players die/respawn
83 * while the game is being ended. Spiff up the chatbox doskey thing a bit.
85 * 7 5/04/98 10:39p Dave
86 * Put in endgame sequencing. Need to check campaign situations.
87 * Realigned ship info on team select screen.
89 * 6 5/03/98 7:04p Dave
90 * Make team vs. team work mores smoothly with standalone. Change how host
91 * interacts with standalone for picking missions. Put in a time limit for
92 * ingame join ship select. Fix ingame join ship select screen for Vasudan
95 * 5 4/27/98 6:02p Dave
96 * Modify how missile scoring works. Fixed a team select ui bug. Speed up
97 * multi_lag system. Put in new main hall.
99 * 4 4/22/98 5:53p Dave
100 * Large reworking of endgame sequencing. Updated multi host options
101 * screen for new artwork. Put in checks for host or team captains leaving
104 * 3 4/16/98 1:55p Dave
105 * Removed unneeded SDL_assert when processing chat packets. Fixed standalone
106 * sequencing bugs. Laid groundwork for join screen server status
109 * 2 4/14/98 5:06p Dave
110 * Don't load or send invalid pilot pics. Fixed chatbox graphic errors.
111 * Made chatbox display team icons in a team vs. team game. Fixed up pause
112 * and endgame sequencing issues.
114 * 1 4/14/98 12:18p Dave
125 #include "freespace.h"
128 #include "gamesequence.h"
129 #include "stand_server.h"
131 #include "multiutil.h"
133 #include "multimsgs.h"
134 #include "multi_pause.h"
135 #include "multi_endgame.h"
136 #include "multi_pmsg.h"
138 #include "alphacolors.h"
141 // ----------------------------------------------------------------------------------
142 // PAUSE DEFINES/VARS
145 // state of the game (paused or not) on _my_ machine. Obviously this is important for the server
146 // call multi_pause_reset() to reinitialize
147 int Multi_pause_status = 0;
149 // who paused the game
150 net_player *Multi_pause_pauser = NULL;
152 // timestamp for eating keypresses for a while after
153 float Multi_pause_eat = -1.0f;
155 // pause ui screen stuff
156 #define MULTI_PAUSED_NUM_BUTTONS 3
159 #define MP_SCROLL_UP 0
160 #define MP_SCROLL_DOWN 1
161 #define MP_EXIT_MISSION 2
163 // where to place the pauser's callsign
164 int Mp_callsign_coords[GR_NUM_RESOLUTIONS][2] = {
173 ui_button_info Multi_paused_buttons[GR_NUM_RESOLUTIONS][MULTI_PAUSED_NUM_BUTTONS] = {
175 ui_button_info("PB00", 519, 212, -1, -1, 0),
176 ui_button_info("PB01", 519, 252, -1, -1, 1),
177 ui_button_info("PB02", 488, 321, -1, -1, 2),
180 ui_button_info("2_PB00", 831, 339, -1, -1, 0),
181 ui_button_info("2_PB01", 831, 403, -1, -1, 1),
182 ui_button_info("2_PB02", 781, 514, -1, -1, 2),
187 #define MULTI_PAUSED_NUM_TEXT 3
188 UI_XSTR Multi_paused_text[GR_NUM_RESOLUTIONS][MULTI_PAUSED_NUM_BUTTONS] = {
190 { "Exit", 1059, 493, 297, UI_XSTR_COLOR_PINK, -1, &Multi_paused_buttons[0][MP_EXIT_MISSION].button },
191 { "Mission", 1063, 482, 306, UI_XSTR_COLOR_PINK, -1, &Multi_paused_buttons[0][MP_EXIT_MISSION].button },
192 { "Mission Paused", 1440, 107, 356, UI_XSTR_COLOR_PINK, -1, NULL },
195 { "Exit", 1059, 787, 478, UI_XSTR_COLOR_PINK, -1, &Multi_paused_buttons[1][MP_EXIT_MISSION].button },
196 { "Mission", 1063, 778, 490, UI_XSTR_COLOR_PINK, -1, &Multi_paused_buttons[1][MP_EXIT_MISSION].button },
197 { "Mission Paused", 1440, 171, 567, UI_XSTR_COLOR_PINK, -1, NULL },
202 UI_WINDOW *Multi_paused_window;
203 int Multi_paused_screen_id; // backed up screen data
205 void multi_pause_check_buttons();
206 void multi_pause_button_pressed(int n);
208 // (server) evaluate a pause request from the given player (should call for himself as well)
209 void multi_pause_server_eval_request(net_player *pl, int pause);
211 // if this player can unpause
212 int multi_pause_can_unpause(net_player *p);
214 // render the callsign of the guy who paused
215 void multi_pause_render_callsign();
218 // ----------------------------------------------------------------------------------
222 // re-initializes the pause system. call before entering the mission to reset
223 void multi_pause_reset()
225 // set the pause status to 0
226 Multi_pause_status = 0;
228 // null out the pause pointer
229 Multi_pause_pauser = NULL;
231 // eat keys timestamp
232 Multi_pause_eat = -1.0f;
235 // (client) call when receiving a packet indicating we should pause
236 void multi_pause_pause()
240 // if we're already paused, don't do anything
241 if(Multi_pause_status){
246 SDL_assert(!Multi_pause_status);
248 // mark the game as being paused
249 Multi_pause_status = 1;
251 // if we're not already in the pause state
252 if(gameseq_get_state() != GS_STATE_MULTI_PAUSED){
253 // jump into the paused state
254 gameseq_post_event(GS_EVENT_MULTI_PAUSE);
256 // mark the netgame state
257 Netgame.game_state = NETGAME_STATE_PAUSED;
260 // if we're the server of the game, send a packet which will pause the clients in the game now
261 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
262 for(idx=0;idx<MAX_PLAYERS;idx++){
263 if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx])){
264 send_client_update_packet(&Net_players[idx]);
270 // (client) call when receiving a packet indicating we should unpause
271 void multi_pause_unpause()
275 // if we're already unpaused, don't do anything
276 if(!Multi_pause_status){
281 SDL_assert(Multi_pause_status);
283 // mark the game as being unpaused
284 Multi_pause_status = 0;
286 // pop us out of any necessary states (including the pause state !!)
287 multi_handle_state_special();
289 // mark the netgame state
290 Netgame.game_state = NETGAME_STATE_IN_MISSION;
292 // if we're the server of the game, send a packet which will unpause the clients in the game now
293 // if we're the server of the game, send a packet which will pause the clients in the game now
294 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
295 for(idx=0;idx<MAX_PLAYERS;idx++){
296 if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx])){
297 send_client_update_packet(&Net_players[idx]);
303 // send a request to pause or unpause a game (all players should use this function)
304 void multi_pause_request(int pause)
306 // if i'm the server, run it through the eval function right now
307 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
308 multi_pause_server_eval_request(Net_player,pause);
310 // otherwise, send a reliable request packet to the server
312 send_multi_pause_packet(pause);
316 // (server) evaluate a pause request from the given player (should call for himself as well)
317 void multi_pause_server_eval_request(net_player *pl, int pause)
321 // if this is a pause request and we're already in the pause state, do nothing
322 if(pause && Multi_pause_status){
326 // if this is an unpause request and we're already unpaused, do nothing
327 if(!pause && !Multi_pause_status){
331 // get the current state (don't allow pausing from certain states
332 cur_state = gameseq_get_state();
333 if((cur_state == GS_STATE_DEBRIEF) || (cur_state == GS_STATE_MULTI_MISSION_SYNC) || (cur_state == GS_STATE_BRIEFING) ||
334 (cur_state == GS_STATE_STANDALONE_POSTGAME) || (cur_state == GS_STATE_MULTI_STD_WAIT) || (cur_state == GS_STATE_WEAPON_SELECT) ||
335 (cur_state == GS_STATE_TEAM_SELECT) || (cur_state == GS_STATE_MULTI_DOGFIGHT_DEBRIEF)){
339 // if this is a pause request
341 // record who the pauser is
342 Multi_pause_pauser = pl;
347 // if this is an unpause request
349 // if this guy is allowed to unpause the game, do so
350 if(multi_pause_can_unpause(pl)){
351 // unmark the "pauser"
352 Multi_pause_pauser = NULL;
355 multi_pause_unpause();
360 // if this player can unpause
361 int multi_pause_can_unpause(net_player *p)
363 if(!(p->flags & NETINFO_FLAG_GAME_HOST) && (p != Multi_pause_pauser)){
370 // if we still want to eat keys
371 int multi_pause_eat_keys()
373 // if the eat timestamp is negative, don't eat keys
374 if(Multi_pause_eat < 0.0f){
378 // if less than 1 second has passed, continue eating keys
379 if((f2fl(timer_get_fixed_seconds()) - Multi_pause_eat) < 1.0f){
380 nprintf(("Network","PAUSE EATING KEYS\n"));
382 control_config_clear_used_status();
388 // otherwise, disable the timestamp
389 Multi_pause_eat = -1.0f;
395 // ----------------------------------------------------------------------------------
396 // PAUSE UI FUNCTIONS
399 void multi_pause_init(UI_WINDOW *Ui_window)
403 // standalone shouldn't be doing any freespace interface stuff
404 if (Game_mode & GM_STANDALONE_SERVER){
405 std_debug_set_standalone_state_string("Multi paused do");
407 // everyone else should be doing UI stuff
409 // switch off the text messaging system if it is active
410 multi_msg_text_flush();
412 // assign the local reference to the ui window
413 Multi_paused_window = Ui_window;
415 for (i=0; i<MULTI_PAUSED_NUM_BUTTONS; i++) {
417 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);
419 // set the highlight action
420 Multi_paused_buttons[gr_screen.res][i].button.set_highlight_action(common_play_highlight_sound);
423 Multi_paused_buttons[gr_screen.res][i].button.set_bmaps(Multi_paused_buttons[gr_screen.res][i].filename);
426 Multi_paused_buttons[gr_screen.res][i].button.link_hotspot(Multi_paused_buttons[gr_screen.res][i].hotspot);
430 for(i=0; i<MULTI_PAUSED_NUM_TEXT; i++){
431 Multi_paused_window->add_XSTR(&Multi_paused_text[gr_screen.res][i]);
434 // close any instances of a chatbox
437 // intiialize our custom chatbox
438 chatbox_create(CHATBOX_FLAG_MULTI_PAUSED);
442 multi_reset_timestamps();
445 void multi_pause_do()
449 // make sure we don't enter this state unless we're in the mission itself
450 Netgame.game_state = NETGAME_STATE_PAUSED;
452 // server of the game should periodically be sending pause packets for good measure
453 if (Net_player->flags & NETINFO_FLAG_AM_MASTER) {
456 if (!(Game_mode & GM_STANDALONE_SERVER)) {
457 // if we're inside of popup code right now, don't process the window
459 // process chatbox and window stuff
460 k = chatbox_process();
461 k = Multi_paused_window->process(k);
466 multi_pause_request(0);
471 // check for any button presses
472 multi_pause_check_buttons();
474 // render the callsign of the guy who paused
475 multi_pause_render_callsign();
477 // render the chatbox
481 // Multi_paused_window->draw_tooltip();
482 Multi_paused_window->draw();
484 // display the voice status indicator
485 multi_common_voice_display_status();
487 // standalone pretty much does nothing here
493 void multi_pause_close()
495 // set the standalonest
496 if (Game_mode & GM_STANDALONE_SERVER) {
497 std_debug_set_standalone_state_string("Game play");
499 // free the screen up
500 gr_free_screen(Multi_paused_screen_id);
503 // eat keys timestamp
504 Multi_pause_eat = f2fl(timer_get_fixed_seconds());
507 multi_reset_timestamps();
509 // clear out control config and keypress info
510 control_config_clear_used_status();
514 void multi_pause_check_buttons()
518 // process any pause buttons which may have been pressed
519 for (idx=0; idx<MULTI_PAUSED_NUM_BUTTONS; idx++){
520 if (Multi_paused_buttons[gr_screen.res][idx].button.pressed()){
521 multi_pause_button_pressed(idx);
526 void multi_pause_button_pressed(int n)
529 // the scroll up button
534 // the scroll down button
535 case MP_SCROLL_DOWN :
536 chatbox_scroll_down();
540 case MP_EXIT_MISSION :
541 multi_quit_game(PROMPT_ALL);
546 // render the callsign of the guy who paused
547 void multi_pause_render_callsign()
551 // write out the callsign of the player who paused the game
552 if((Multi_pause_pauser != NULL) && (Multi_pause_pauser->player != NULL)){
553 memset(pause_str,0,100);
554 SDL_strlcpy(pause_str, Multi_pause_pauser->player->callsign, SDL_arraysize(pause_str));
557 gr_set_color_fast(&Color_bright);
558 gr_string(Mp_callsign_coords[gr_screen.res][0], Mp_callsign_coords[gr_screen.res][1], pause_str);