2 * $Logfile: /Freespace2/code/MissionUI/MissionScreenCommon.cpp $
8 * Revision 1.1 2002/05/03 03:28:10 root
12 * 13 10/14/99 2:51p Jefff
15 * 12 8/05/99 3:40p Jefff
16 * hi-res text adjustments
18 * 11 7/15/99 9:20a Andsager
19 * FS2_DEMO initial checkin
21 * 10 2/01/99 5:55p Dave
22 * Removed the idea of explicit bitmaps for buttons. Fixed text
23 * highlighting for disabled gadgets.
25 * 9 1/30/99 7:33p Neilk
26 * Fixed coords problems for mission briefing screens
28 * 8 1/30/99 5:08p Dave
29 * More new hi-res stuff.Support for nice D3D textures.
31 * 7 1/29/99 4:17p Dave
32 * New interface screens.
34 * 6 1/24/99 11:37p Dave
35 * First full rev of beam weapons. Very customizable. Removed some bogus
36 * Int3()'s in low level net code.
38 * 5 11/30/98 1:07p Dave
39 * 16 bit conversion, first run.
41 * 4 11/17/98 11:12a Dave
42 * Removed player identification by address. Now assign explicit id #'s.
44 * 3 10/16/98 9:40a Andsager
45 * Remove ".h" files from model.h
47 * 2 10/07/98 10:53a Dave
50 * 1 10/07/98 10:50a Dave
52 * 85 6/09/98 10:31a Hoffoss
53 * Created index numbers for all xstr() references. Any new xstr() stuff
54 * added from here on out should be added to the end if the list. The
55 * current list count can be found in FreeSpace.cpp (search for
58 * 84 5/08/98 7:52p Lawrance
59 * fix bug where wing slot icons were not getting loaded
61 * 83 5/08/98 10:17a Lawrance
62 * don't play briefing slide-in animation if detail level is below high
64 * 82 5/06/98 11:50p Lawrance
65 * Clean up help overlay code for loadout screens
67 * 81 5/03/98 1:55a Lawrance
68 * Fix some sound problems with loadout screens
70 * 80 4/30/98 6:03p Lawrance
71 * Make drag and drop work better.
73 * 79 4/22/98 5:52p Dave
74 * Large reworking of endgame sequencing. Updated host options screen for
75 * new artwork. Put in checks to end game if host leaves or if team
76 * captains leave mid-game.
78 * 78 4/07/98 7:51p Hoffoss
79 * Implemented changed to options screen due to artwork changes.
81 * 77 4/07/98 5:42p Dave
82 * Put in support for ui display of voice system status (recording,
83 * playing back, etc). Make sure main hall music is stopped before
84 * entering a multiplayer game via ingame join.
86 * 76 4/02/98 11:40a Lawrance
87 * check for #ifdef DEMO instead of #ifdef DEMO_RELEASE
89 * 75 4/01/98 11:19p Dave
90 * Put in auto-loading of xferred pilot pic files. Grey out background
91 * behind pinfo popup. Put a chatbox message in when players are kicked.
92 * Moved mission title down in briefing. Other ui fixes.
94 * 74 4/01/98 9:21p John
95 * Made NDEBUG, optimized build with no warnings or errors.
97 * 73 3/31/98 11:47p Lawrance
98 * Fix some bugs related to wingmen selection when doing a quick mission
101 * 72 3/31/98 5:31p Lawrance
102 * Fix sound bug that happenned when entering briefing
104 * 71 3/30/98 5:16p Lawrance
105 * centralize a check for disabled loadout screens
107 * 70 3/30/98 12:18a Lawrance
108 * change some DEMO_RELEASE code to not compile code rather than return
111 * 69 3/29/98 10:16p Allender
112 * scramble missions need to have ship/weapon selection disabled (this
113 * code was somehow lost)
115 * 68 3/29/98 1:24p Dave
116 * Make chatbox not clear between multiplayer screens. Select player ship
117 * as default in mp team select and weapons select screens. Made create
118 * game mission list use 2 fixed size columns.
120 * 67 3/29/98 12:55a Lawrance
121 * Get demo build working with limited set of data.
123 * 66 3/25/98 8:43p Hoffoss
124 * Changed anim_play() to not be so damn complex when you try and call it.
126 * 65 3/24/98 4:59p Dave
127 * Fixed several ui bugs. Put in pre and post voice stream playback sound
128 * fx. Put in error specific popups for clients getting dropped from games
129 * through actions other than their own.
131 * 64 3/19/98 5:32p Lawrance
132 * Added music to the background of command brief screen.
134 * 63 3/05/98 5:02p Dave
135 * More work on team vs. team support for multiplayer. Need to fix bugs in
138 * 62 3/03/98 8:55p Dave
139 * Finished pre-briefing team vs. team support.
141 * 61 3/03/98 8:12p Lawrance
142 * Double timeout before flashing buttons
144 * 60 3/02/98 3:27p Lawrance
145 * Don't call muti_ts_init() in single player
147 * 59 3/01/98 3:26p Dave
148 * Fixed a few team select bugs. Put in multiplayer intertface sounds.
149 * Corrected how ships are disabled/enabled in team select/weapon select
152 * 58 2/27/98 4:55p Sandeep
153 * Fixed a signed/unsigned bug in the wss packet type
155 * 57 2/26/98 4:59p Allender
156 * groundwork for team vs team briefings. Moved weaponry pool into the
157 * Team_data structure. Added team field into the p_info structure.
158 * Allow for mutliple structures in the briefing code.
160 * 56 2/25/98 10:24a Lawrance
161 * Don't ask for confirmation when ESC is pressed.
163 * 55 2/24/98 12:22a Lawrance
164 * New coords for revamped briefing graphics
166 * 54 2/22/98 4:17p John
167 * More string externalization classification... 190 left to go!
169 * 53 2/22/98 12:19p John
170 * Externalized some strings
172 * 52 2/21/98 2:50p Lawrance
173 * Tell players that their campaign position will get saved if they return
174 * to main hall from loadout screens.
176 * 51 2/19/98 6:26p Dave
177 * Fixed a few file xfer bugs. Tweaked mp team select screen. Put in
178 * initial support for player data uploading.
180 * 50 2/18/98 3:56p Dave
181 * Several bugs fixed for mp team select screen. Put in standalone packet
182 * routing for team select.
184 * 49 2/17/98 6:07p Dave
185 * Tore out old multiplayer team select screen, installed new one.
187 * 48 2/13/98 3:46p Dave
188 * Put in dynamic chatbox sizing. Made multiplayer file lookups use cfile
191 * 47 2/10/98 8:40p Dave
192 * Fixed some debriefing bugs.
194 * 46 2/04/98 11:06p Lawrance
195 * Fix a couple of bugs with save/restore of player weapon loadout.
197 * 45 2/04/98 4:32p Allender
198 * support for multiple briefings and debriefings. Changes to mission
199 * type (now a bitfield). Bitfield defs for multiplayer modes
201 * 44 1/30/98 10:40a Lawrance
202 * remove any binding references to hotkey screen
204 * 43 1/20/98 5:52p Lawrance
205 * prompt user before returning to main hall (in single player)
207 * 42 1/17/98 5:51p Dave
208 * Bug fixes for bugs generated by multiplayer testing.
210 * 41 1/14/98 11:39a Dave
211 * Polished up a bunch of popup support items.
213 * 40 1/13/98 5:35p Lawrance
214 * Show popup when trying to go to weapons loadout without any ships
217 * 39 1/10/98 5:48p Lawrance
218 * Don't allow Tab to go to ship/weapon loadout screen in training, play
219 * negative feedback sounds if user tries to.
221 * 38 1/10/98 12:45a Lawrance
222 * Don't restore loadout if mission was modified.
224 * 37 1/09/98 6:06p Dave
225 * Put in network sound support for multiplayer ship/weapon select
226 * screens. Made clients exit game correctly through warp effect. Fixed
227 * main hall menu help overlay bug.
229 * 36 1/09/98 11:04a Lawrance
230 * Fix bug that prevented buttons from flashing in the loadout screens.
232 * 35 1/07/98 6:45p Lawrance
233 * Play first briefing music if none specified.
235 * 34 1/05/98 4:57p Lawrance
236 * reset flash timers when a button is pressed or a key is pressed
238 * 33 12/30/97 5:46p Lawrance
239 * Rename rnd() to rand_alt().
241 * 32 12/30/97 4:27p Lawrance
242 * Add new rnd() function that doesn't affect rand() sequence.
244 * 31 12/29/97 4:21p Lawrance
245 * Flash buttons on briefing/ship select/weapons loadout when enough time
246 * has elapsed without activity.
248 * 30 12/28/97 5:52p Lawrance
249 * Add support for debriefing success/fail music.
251 * 29 12/24/97 8:54p Lawrance
252 * Integrating new popup code
254 * 28 12/24/97 1:19p Lawrance
255 * fix some bugs with the multiplayer ship/weapons loadout
257 * 27 12/23/97 11:58a Allender
258 * changes to ship/wespon selection for multplayer. added sounds to some
259 * interface screens. Update and modiied end-of-briefing packets -- yet
267 #include "freespace.h"
268 #include "eventmusic.h"
270 #include "missionscreencommon.h"
271 #include "missionshipchoice.h"
272 #include "missionweaponchoice.h"
273 #include "missionbrief.h"
275 #include "multimsgs.h"
278 #include "gamesequence.h"
280 // #include "movie.h"
284 #include "contexthelp.h"
289 #include "linklist.h"
290 #include "staticrand.h" // for rand_alt()
292 #include "multiutil.h"
293 #include "multiteamselect.h"
294 #include "hudwingmanstatus.h"
295 #include "multi_endgame.h"
297 #include "animplay.h"
299 //////////////////////////////////////////////////////////////////
301 //////////////////////////////////////////////////////////////////
303 int Common_select_inited = 0;
305 // Dependent on when mouse button goes up
306 int Drop_icon_mflag, Drop_on_wing_mflag, Brief_mouse_up_flag;
308 int Mouse_down_last_frame = 0;
310 // Timers used to flash buttons after timeouts
311 #define MSC_FLASH_AFTER_TIME 60000 // time before flashing a button
312 #define MSC_FLASH_INTERVAL 200 // time between flashes
313 int Flash_timer; // timestamp used to start flashing
314 int Flash_toggle; // timestamp used to toggle flashing
315 int Flash_bright; // state of button to flash
317 //////////////////////////////////////////////////////////////////
319 //////////////////////////////////////////////////////////////////
322 static int InterfacePaletteBitmap = -1; // PCX file that holds the interface palette
324 //////////////////////////////////////////////////////////////////
326 //////////////////////////////////////////////////////////////////
327 UI_WINDOW *Active_ui_window;
329 brief_common_buttons Common_buttons[3][GR_NUM_RESOLUTIONS][NUM_COMMON_BUTTONS] = {
332 brief_common_buttons("CB_00", 7, 3, 37, 7, 0),
333 brief_common_buttons("CB_01", 7, 19, 37, 23, 1),
334 brief_common_buttons("CB_02", 7, 35, 37, 39, 2),
335 brief_common_buttons("CB_05", 571, 425, 572, 413, 5),
336 brief_common_buttons("CB_06", 533, 425, 500, 440, 6),
337 brief_common_buttons("CB_07", 533, 455, 479, 464, 7),
340 brief_common_buttons("2_CB_00", 12, 5, 59, 12, 0),
341 brief_common_buttons("2_CB_01", 12, 31, 59, 37, 1),
342 brief_common_buttons("2_CB_02", 12, 56, 59, 62, 2),
343 brief_common_buttons("2_CB_05", 914, 681, 937, 671, 5),
344 brief_common_buttons("2_CB_06", 854, 681, 822, 704, 6),
345 brief_common_buttons("2_CB_07", 854, 724, 800, 743, 7),
350 brief_common_buttons("CB_00", 7, 3, 37, 7, 0),
351 brief_common_buttons("CB_01", 7, 19, 37, 23, 1),
352 brief_common_buttons("CB_02", 7, 35, 37, 39, 2),
353 brief_common_buttons("CB_05", 571, 425, 572, 413, 5),
354 brief_common_buttons("CB_06", 533, 425, 500, 440, 6),
355 brief_common_buttons("CB_07", 533, 455, 479, 464, 7),
358 brief_common_buttons("2_CB_00", 12, 5, 59, 12, 0),
359 brief_common_buttons("2_CB_01", 12, 31, 59, 37, 1),
360 brief_common_buttons("2_CB_02", 12, 56, 59, 62, 2),
361 brief_common_buttons("2_CB_05", 914, 681, 937, 671, 5),
362 brief_common_buttons("2_CB_06", 854, 681, 822, 704, 6),
363 brief_common_buttons("2_CB_07", 854, 724, 800, 743, 7),
368 brief_common_buttons("CB_00", 7, 3, 37, 7, 0),
369 brief_common_buttons("CB_01", 7, 19, 37, 23, 1),
370 brief_common_buttons("CB_02", 7, 35, 37, 39, 2),
371 brief_common_buttons("CB_05", 571, 425, 572, 413, 5),
372 brief_common_buttons("CB_06", 533, 425, 500, 440, 6),
373 brief_common_buttons("CB_07", 533, 455, 479, 464, 7),
376 brief_common_buttons("2_CB_00", 12, 5, 59, 12, 0),
377 brief_common_buttons("2_CB_01", 12, 31, 59, 37, 1),
378 brief_common_buttons("2_CB_02", 12, 56, 59, 62, 2),
379 brief_common_buttons("2_CB_05", 914, 681, 937, 671, 5),
380 brief_common_buttons("2_CB_06", 854, 681, 822, 704, 6),
381 brief_common_buttons("2_CB_07", 854, 724, 800, 743, 7),
386 #define COMMON_BRIEFING_BUTTON 0
387 #define COMMON_SS_BUTTON 1
388 #define COMMON_WEAPON_BUTTON 2
389 #define COMMON_COMMIT_BUTTON 3
390 #define COMMON_HELP_BUTTON 4
391 #define COMMON_OPTIONS_BUTTON 5
393 int Background_playing; // Flag to indicate background animation is playing
394 static anim *Background_anim; // Ids for the anim data that is loaded
396 // value for which Team_data entry to use
399 // Ids for the instance of the anim that is playing
400 static anim_instance *Background_anim_instance;
402 int Wing_slot_empty_bitmap;
403 int Wing_slot_disabled_bitmap;
406 int wss_slots_all_empty();
408 // Display the no ships selected error
409 void common_show_no_ship_error()
411 popup(PF_USE_AFFIRMATIVE_ICON, 1, POPUP_OK, XSTR( "At least one ship must be selected before proceeding to weapons loadout", 460));
414 // Check the status of the buttons common to the loadout screens
415 void common_check_buttons()
420 for ( i = 0; i < NUM_COMMON_BUTTONS; i++ ) {
421 b = &Common_buttons[Current_screen-1][gr_screen.res][i].button;
422 if ( b->pressed() ) {
429 // AL 11-23-97: let a joystick button press commit
430 if ( joy_down_count(0) || joy_down_count(1) ) {
437 // -------------------------------------------------------------------
438 // common_redraw_pressed_buttons()
440 // Redraw any common buttons that are pressed down. This function is needed
441 // since we sometimes need to draw pressed buttons last to ensure the entire
442 // button gets drawn (and not overlapped by other buttons)
444 void common_redraw_pressed_buttons()
449 for ( i = 0; i < NUM_COMMON_BUTTONS; i++ ) {
450 b = &Common_buttons[Current_screen-1][gr_screen.res][i].button;
451 if ( b->button_down() ) {
457 void common_buttons_maybe_reload(UI_WINDOW *ui_window)
462 for ( i = 0; i < NUM_COMMON_BUTTONS; i++ ) {
463 b = &Common_buttons[Current_screen-1][gr_screen.res][i].button;
464 b->set_bmaps(Common_buttons[Current_screen-1][gr_screen.res][i].filename);
468 void common_buttons_init(UI_WINDOW *ui_window)
473 for ( i = 0; i < NUM_COMMON_BUTTONS; i++ ) {
474 b = &Common_buttons[Current_screen-1][gr_screen.res][i].button;
475 b->create( ui_window, "", Common_buttons[Current_screen-1][gr_screen.res][i].x, Common_buttons[Current_screen-1][gr_screen.res][i].y, 60, 30, 0, 1);
476 // set up callback for when a mouse first goes over a button
477 b->set_highlight_action( common_play_highlight_sound );
478 b->set_bmaps(Common_buttons[Current_screen-1][gr_screen.res][i].filename);
479 b->link_hotspot(Common_buttons[Current_screen-1][gr_screen.res][i].hotspot);
483 ui_window->add_XSTR("Briefing", 1504, Common_buttons[Current_screen-1][gr_screen.res][COMMON_BRIEFING_BUTTON].xt, Common_buttons[Current_screen-1][gr_screen.res][COMMON_BRIEFING_BUTTON].yt, &Common_buttons[Current_screen-1][gr_screen.res][COMMON_BRIEFING_BUTTON].button, UI_XSTR_COLOR_GREEN);
484 ui_window->add_XSTR("Ship Selection", 1067, Common_buttons[Current_screen-1][gr_screen.res][COMMON_SS_BUTTON].xt, Common_buttons[Current_screen-1][gr_screen.res][COMMON_SS_BUTTON].yt, &Common_buttons[Current_screen-1][gr_screen.res][COMMON_SS_BUTTON].button, UI_XSTR_COLOR_GREEN);
485 ui_window->add_XSTR("Weapon Loadout", 1068, Common_buttons[Current_screen-1][gr_screen.res][COMMON_WEAPON_BUTTON].xt, Common_buttons[Current_screen-1][gr_screen.res][COMMON_WEAPON_BUTTON].yt, &Common_buttons[Current_screen-1][gr_screen.res][COMMON_WEAPON_BUTTON].button, UI_XSTR_COLOR_GREEN);
486 ui_window->add_XSTR("Commit", 1062, Common_buttons[Current_screen-1][gr_screen.res][COMMON_COMMIT_BUTTON].xt, Common_buttons[Current_screen-1][gr_screen.res][COMMON_COMMIT_BUTTON].yt, &Common_buttons[Current_screen-1][gr_screen.res][COMMON_COMMIT_BUTTON].button, UI_XSTR_COLOR_PINK);
487 ui_window->add_XSTR("Help", 928, Common_buttons[Current_screen-1][gr_screen.res][COMMON_HELP_BUTTON].xt, Common_buttons[Current_screen-1][gr_screen.res][COMMON_HELP_BUTTON].yt, &Common_buttons[Current_screen-1][gr_screen.res][COMMON_HELP_BUTTON].button, UI_XSTR_COLOR_GREEN);
488 ui_window->add_XSTR("Options", 1036, Common_buttons[Current_screen-1][gr_screen.res][COMMON_OPTIONS_BUTTON].xt, Common_buttons[Current_screen-1][gr_screen.res][COMMON_OPTIONS_BUTTON].yt, &Common_buttons[Current_screen-1][gr_screen.res][COMMON_OPTIONS_BUTTON].button, UI_XSTR_COLOR_GREEN);
490 common_reset_buttons();
492 Common_buttons[Current_screen-1][gr_screen.res][COMMON_COMMIT_BUTTON].button.set_hotkey(KEY_CTRLED+KEY_ENTER);
493 Common_buttons[Current_screen-1][gr_screen.res][COMMON_HELP_BUTTON].button.set_hotkey(KEY_F1);
494 Common_buttons[Current_screen-1][gr_screen.res][COMMON_OPTIONS_BUTTON].button.set_hotkey(KEY_F2);
496 // for scramble or training missions, disable the ship/weapon selection regions
497 if ( brief_only_allow_briefing() ) {
498 Common_buttons[Current_screen-1][gr_screen.res][COMMON_SS_REGION].button.disable();
499 Common_buttons[Current_screen-1][gr_screen.res][COMMON_WEAPON_REGION].button.disable();
502 #ifdef DEMO // allow for FS2_DEMO
503 Common_buttons[Current_screen-1][gr_screen.res][COMMON_SS_REGION].button.disable();
504 Common_buttons[Current_screen-1][gr_screen.res][COMMON_WEAPON_REGION].button.disable();
508 void set_active_ui(UI_WINDOW *ui_window)
510 Active_ui_window = ui_window;
513 void common_music_init(int score_index)
515 if ( Cmdline_freespace_no_music ) {
519 if ( score_index >= NUM_SCORES ) {
524 if ( Mission_music[score_index] < 0 ) {
525 if ( Num_music_files > 0 ) {
526 Mission_music[score_index] = 0;
527 nprintf(("Sound","No briefing music is selected, so play first briefing track: %s\n",Spooled_music[Mission_music[score_index]].name));
533 briefing_load_music( Spooled_music[Mission_music[score_index]].filename );
534 // Use this id to trigger the start of music playing on the briefing screen
535 Briefing_music_begin_timestamp = timestamp(BRIEFING_MUSIC_DELAY);
538 void common_music_do()
540 if ( Cmdline_freespace_no_music ) {
544 // Use this id to trigger the start of music playing on the briefing screen
545 if ( timestamp_elapsed( Briefing_music_begin_timestamp) ) {
546 Briefing_music_begin_timestamp = 0;
547 briefing_start_music();
551 void common_music_close()
553 if ( Cmdline_freespace_no_music ) {
557 if ( Num_music_files <= 0 )
560 briefing_stop_music();
563 // function that sets the current palette to the interface palette. This function
564 // needs to be followed by common_free_interface_palette() to restore the game palette.
565 void common_set_interface_palette(char *filename)
567 static char buf[MAX_FILENAME_LEN + 1] = {0};
570 filename = NOX("palette01");
572 Assert(strlen(filename) <= MAX_FILENAME_LEN);
573 if ( (InterfacePaletteBitmap != -1) && !stricmp(filename, buf) )
574 return; // already set to this palette
576 strcpy(buf, filename);
578 // unload the interface bitmap from memory
579 if (InterfacePaletteBitmap != -1) {
580 bm_unload(InterfacePaletteBitmap);
581 InterfacePaletteBitmap = -1;
584 // ugh - we don't need this anymore
586 InterfacePaletteBitmap = bm_load(filename);
587 if (InterfacePaletteBitmap < 0) {
588 Error(LOCATION, "Could not load in \"%s\"!", filename);
592 #ifndef HARDWARE_ONLY
593 palette_use_bm_palette(InterfacePaletteBitmap);
597 // release the interface palette .pcx file, and restore the game palette
598 void common_free_interface_palette()
600 // unload the interface bitmap from memory
601 if (InterfacePaletteBitmap != -1) {
602 bm_unload(InterfacePaletteBitmap);
603 InterfacePaletteBitmap = -1;
606 // restore the normal game palette
607 palette_restore_palette();
610 // Init timers used for flashing buttons
611 void common_flash_button_init()
613 Flash_timer = timestamp(MSC_FLASH_AFTER_TIME);
618 // determine if we should draw a button as bright
619 int common_flash_bright()
621 if ( timestamp_elapsed(Flash_timer) ) {
622 if ( timestamp_elapsed(Flash_toggle) ) {
623 Flash_toggle = timestamp(MSC_FLASH_INTERVAL);
631 // common_select_init() will load in animations and bitmaps that are common to the
632 // briefing/ship select/weapon select screens. The global Common_select_inited is set
633 // after this function is called once, and is only cleared when common_select_close()
634 // is called. This prevents multiple loadings of animations/bitmaps.
636 // This function also sets the palette based on the file palette01.pcx
637 void common_select_init()
639 if ( Common_select_inited ) {
640 nprintf(("Alan","common_select_init() returning without doing anything\n"));
644 nprintf(("Alan","entering common_select_init()\n"));
646 // No anims are playing
647 Background_playing = 0;
648 Background_anim = NULL;
650 #ifndef DEMO // not for FS2_DEMO
653 if ( current_detail_level() >= (NUM_DEFAULT_DETAIL_LEVELS-2) ) {
655 anim_play_struct aps;
657 // Load in the background transition anim
658 if ( Game_mode & GM_MULTIPLAYER )
659 Background_anim = anim_load("BriefTransMulti", 1); // 1 as last parm means file is mem-mapped
661 Background_anim = anim_load("BriefTrans", 1); // 1 as last parm means file is mem-mapped
664 Assert( Background_anim != NULL );
665 anim_play_init(&aps, Background_anim, 0, 0);
666 aps.framerate_independent = 1;
668 Background_anim_instance = anim_play(&aps);
669 Background_playing = 1; // start playing the Background anim
672 Current_screen = Next_screen = ON_BRIEFING_SELECT;
674 // load in the icons for the wing slots
675 load_wing_icons(NOX("iconwing01"));
680 Current_screen = Next_screen = ON_BRIEFING_SELECT;
684 Common_select_inited = 1;
686 // this handles the case where the player played a multiplayer game but now is in single player (in one instance
688 if(!(Game_mode & GM_MULTIPLAYER)){
692 // get the value of the team
693 Common_team = 0; // assume the first team -- we'll change this value if we need to
694 if ( (Game_mode & GM_MULTIPLAYER) && IS_MISSION_MULTI_TEAMS )
695 Common_team = Net_player->p_info.team;
697 ship_select_common_init();
698 weapon_select_common_init();
699 common_flash_button_init();
701 if ( Game_mode & GM_MULTIPLAYER ) {
702 multi_ts_common_init();
705 // restore loadout from Player_loadout if this is the same mission as the one previously played
706 if ( !(Game_mode & GM_MULTIPLAYER) ) {
707 if ( !stricmp(Player_loadout.filename, Game_current_mission_filename) ) {
708 wss_restore_loadout();
709 ss_synch_interface();
710 wl_synch_interface();
715 Drop_on_wing_mflag = 0;
718 void common_reset_buttons()
723 for ( i = 0; i < NUM_COMMON_BUTTONS; i++ ) {
724 b = &Common_buttons[Current_screen-1][gr_screen.res][i].button;
728 switch(Current_screen) {
729 case ON_BRIEFING_SELECT:
730 Common_buttons[Current_screen-1][gr_screen.res][COMMON_BRIEFING_REGION].button.skip_first_highlight_callback();
733 Common_buttons[Current_screen-1][gr_screen.res][COMMON_SS_REGION].button.skip_first_highlight_callback();
735 case ON_WEAPON_SELECT:
736 Common_buttons[Current_screen-1][gr_screen.res][COMMON_WEAPON_REGION].button.skip_first_highlight_callback();
741 // common_select_do() is called once per loop in the interface screens and is used
742 // for drawing and changing the common animations and blitting common bitmaps.
743 int common_select_do(float frametime)
747 // If the mouse went up, set flags. We can't use mouse_up_count() more than once a frame,
748 // since the count gets zeroed after the call.
751 Drop_on_wing_mflag = 0;
752 Brief_mouse_up_flag = 0;
754 if ( mouse_up_count(MOUSE_LEFT_BUTTON) ) {
756 Drop_on_wing_mflag = 1;
757 Brief_mouse_up_flag = 1;
760 Mouse_down_last_frame = 0;
761 if ( mouse_down_count(MOUSE_LEFT_BUTTON) ) {
762 Mouse_down_last_frame = 1;
765 if ( help_overlay_active(BR_OVERLAY) || help_overlay_active(SS_OVERLAY) || help_overlay_active(WL_OVERLAY) ) {
766 Common_buttons[0][gr_screen.res][COMMON_HELP_BUTTON].button.reset_status();
767 Common_buttons[1][gr_screen.res][COMMON_HELP_BUTTON].button.reset_status();
768 Common_buttons[2][gr_screen.res][COMMON_HELP_BUTTON].button.reset_status();
769 Active_ui_window->set_ignore_gadgets(1);
771 Active_ui_window->set_ignore_gadgets(0);
774 k = chatbox_process();
775 if ( Game_mode & GM_NORMAL ) {
776 new_k = Active_ui_window->process(k);
778 new_k = Active_ui_window->process(k, 0);
781 if ( (k > 0) || (new_k > 0) || B1_JUST_RELEASED ) {
782 if ( help_overlay_active(BR_OVERLAY) || help_overlay_active(SS_OVERLAY) || help_overlay_active(WL_OVERLAY) ) {
783 help_overlay_set_state(BR_OVERLAY, 0);
784 help_overlay_set_state(SS_OVERLAY, 0);
785 help_overlay_set_state(WL_OVERLAY, 0);
786 Active_ui_window->set_ignore_gadgets(0);
792 // reset timers for flashing buttons if key pressed
793 if ( (k>0) || (new_k>0) ) {
794 common_flash_button_init();
800 if ( Background_playing ) {
802 if ( Background_anim_instance->frame_num == BUTTON_SLIDE_IN_FRAME ) {
803 gamesnd_play_iface(SND_BTN_SLIDE);
806 if ( Background_anim_instance->frame_num == Background_anim_instance->stop_at ) {
807 // Free up the big honking background animation, since we won't be playing it again
808 anim_release_render_instance(Background_anim_instance);
809 anim_free(Background_anim);
811 Background_playing = 0;
812 Current_screen = Next_screen = ON_BRIEFING_SELECT;
817 if ( Current_screen != Next_screen ) {
818 switch( Next_screen ) {
819 case ON_BRIEFING_SELECT:
820 gameseq_post_event( GS_EVENT_START_BRIEFING );
824 // go to the specialized multiplayer team/ship select screen
825 if(Game_mode & GM_MULTIPLAYER){
826 gameseq_post_event(GS_EVENT_TEAM_SELECT);
828 // go to the normal ship select screen
830 gameseq_post_event(GS_EVENT_SHIP_SELECTION);
834 case ON_WEAPON_SELECT:
835 if ( !wss_slots_all_empty() ) {
836 gameseq_post_event(GS_EVENT_WEAPON_SELECTION);
838 common_show_no_ship_error();
847 // -------------------------------------------------------------------------------------
850 void common_render(float frametime)
852 if ( !Background_playing ) {
853 gr_set_bitmap(Brief_background_bitmap);
857 anim_render_all(0, frametime);
858 anim_render_all(ON_SHIP_SELECT, frametime);
861 // -------------------------------------------------------------------------------------
862 // common_render_selected_screen_button()
864 // A very ugly piece of special purpose code. This is used to draw the pressed button
865 // frame for whatever stage of the briefing/ship select/weapons loadout we are on.
867 void common_render_selected_screen_button()
869 Common_buttons[Next_screen-1][gr_screen.res][Next_screen-1].button.draw_forced(2);
872 // -------------------------------------------------------------------------------------
873 // common_button_do() do the button action for the specified pressed button
875 void common_button_do(int i)
877 if ( i == COMMON_COMMIT_BUTTON ) {
882 if ( Background_playing )
887 case COMMON_BRIEFING_BUTTON:
888 if ( Current_screen != ON_BRIEFING_SELECT ) {
889 gamesnd_play_iface(SND_SCREEN_MODE_PRESSED);
890 Next_screen = ON_BRIEFING_SELECT;
894 case COMMON_WEAPON_BUTTON:
895 if ( Current_screen != ON_WEAPON_SELECT ) {
896 if ( !wss_slots_all_empty() ) {
897 gamesnd_play_iface(SND_SCREEN_MODE_PRESSED);
898 Next_screen = ON_WEAPON_SELECT;
900 common_show_no_ship_error();
905 case COMMON_SS_BUTTON:
906 if ( Current_screen != ON_SHIP_SELECT ) {
907 gamesnd_play_iface(SND_SCREEN_MODE_PRESSED);
908 Next_screen = ON_SHIP_SELECT;
912 case COMMON_OPTIONS_BUTTON:
913 gamesnd_play_iface(SND_SWITCH_SCREENS);
914 gameseq_post_event( GS_EVENT_OPTIONS_MENU );
917 case COMMON_HELP_BUTTON:
918 gamesnd_play_iface(SND_HELP_PRESSED);
919 launch_context_help();
925 // common_check_keys() will check for keypresses common to all the interface screens.
926 void common_check_keys(int k)
932 if ( Current_screen == ON_BRIEFING_SELECT ) {
933 if ( brief_get_closeup_icon() != NULL ) {
934 brief_turn_off_closeup_icon();
939 // prompt the host of a multiplayer game
940 if(Game_mode & GM_MULTIPLAYER){
941 multi_quit_game(PROMPT_ALL);
943 // go through the single player quit process
945 // return to the main menu
947 int return_to_menu, pf_flags;
948 pf_flags = PF_USE_AFFIRMATIVE_ICON|PF_USE_NEGATIVE_ICON;
949 return_to_menu = popup(pf_flags, 2, POPUP_NO, POPUP_YES, XSTR( "Do you want to return to the Main Hall?\n(Your campaign position will be saved)", -1));
950 if ( return_to_menu == 1 ) {
951 gameseq_post_event(GS_EVENT_MAIN_MENU);
954 gameseq_post_event(GS_EVENT_MAIN_MENU);
959 case KEY_CTRLED + KEY_ENTER:
964 if ( Current_screen != ON_BRIEFING_SELECT && !Background_playing ) {
965 Next_screen = ON_BRIEFING_SELECT;
970 if ( brief_only_allow_briefing() ) {
971 gamesnd_play_iface(SND_GENERAL_FAIL);
975 #ifndef DEMO // not for FS2_DEMO
976 if ( Current_screen != ON_WEAPON_SELECT && !Background_playing ) {
977 if ( !wss_slots_all_empty() ) {
978 Next_screen = ON_WEAPON_SELECT;
980 common_show_no_ship_error();
984 gamesnd_play_iface(SND_GENERAL_FAIL);
991 if ( brief_only_allow_briefing() ) {
992 gamesnd_play_iface(SND_GENERAL_FAIL);
996 #ifndef DEMO // not for FS2_DEMO
997 if ( Current_screen != ON_SHIP_SELECT && !Background_playing ) {
998 Next_screen = ON_SHIP_SELECT;
1001 gamesnd_play_iface(SND_GENERAL_FAIL);
1006 case KEY_SHIFTED+KEY_TAB:
1008 if ( brief_only_allow_briefing() ) {
1009 gamesnd_play_iface(SND_GENERAL_FAIL);
1013 #ifndef DEMO // not for FS2_DEMO
1014 if ( !Background_playing ) {
1015 switch ( Current_screen ) {
1016 case ON_BRIEFING_SELECT:
1017 if ( !wss_slots_all_empty() ) {
1018 Next_screen = ON_WEAPON_SELECT;
1020 common_show_no_ship_error();
1024 case ON_SHIP_SELECT:
1025 Next_screen = ON_BRIEFING_SELECT;
1028 case ON_WEAPON_SELECT:
1029 Next_screen = ON_SHIP_SELECT;
1037 gamesnd_play_iface(SND_GENERAL_FAIL);
1044 if ( brief_only_allow_briefing() ) {
1045 gamesnd_play_iface(SND_GENERAL_FAIL);
1049 #ifndef DEMO // not for FS2_DEMO
1050 if ( !Background_playing ) {
1051 switch ( Current_screen ) {
1052 case ON_BRIEFING_SELECT:
1053 Next_screen = ON_SHIP_SELECT;
1056 case ON_SHIP_SELECT:
1057 if ( !wss_slots_all_empty() ) {
1058 Next_screen = ON_WEAPON_SELECT;
1060 common_show_no_ship_error();
1064 case ON_WEAPON_SELECT:
1065 Next_screen = ON_BRIEFING_SELECT;
1073 gamesnd_play_iface(SND_GENERAL_FAIL);
1087 // common_select_close() will release the memory for animations and bitmaps that
1088 // were loaded in common_select_init(). This function will abort if the Common_select_inited
1089 // flag is not set. The last thing common_select_close() does in clear the Common_select_inited
1092 // weapon_select_close() and ship_select_close() are both called, since common_select_close()
1093 // is the function that is called the interface screens are finally exited.
1094 void common_select_close()
1096 if ( !Common_select_inited ) {
1097 nprintf(("Alan","common_select_close() returning without doing anything\n"));
1101 nprintf(("Alan","entering common_select_close()\n"));
1103 weapon_select_close();
1104 if(Game_mode & GM_MULTIPLAYER){
1107 ship_select_close();
1110 common_free_interface_palette();
1112 // release the bitmpas that were previously extracted from anim files
1113 unload_wing_icons();
1115 // Release any instances that may still exist
1116 anim_release_all_instances();
1118 // free the anim's that were loaded into memory
1120 if ( Background_anim ) {
1121 anim_free(Background_anim);
1122 Background_anim = NULL;
1126 common_music_close();
1127 Common_select_inited = 0;
1130 // ------------------------------------------------------------------------
1131 // load_wing_icons() creates the bitmaps for wing icons
1133 void load_wing_icons(char *filename)
1135 int first_frame, num_frames;
1137 first_frame = bm_load_animation(filename, &num_frames);
1138 if ( first_frame == -1 ) {
1139 Error(LOCATION, "Could not load icons from %s\n", filename);
1143 Wing_slot_disabled_bitmap = first_frame;
1144 Wing_slot_empty_bitmap = first_frame + 1;
1145 // Wing_slot_player_empty_bitmap = first_frame + 2;
1148 // ------------------------------------------------------------------------
1149 // common_scroll_up_pressed()
1151 int common_scroll_up_pressed(int *start, int size, int max_show)
1153 // check if we even need to scroll at all
1154 if ( size <= max_show ) {
1158 if ( (size - *start) > max_show ) {
1165 // ------------------------------------------------------------------------
1166 // common_scroll_down_pressed()
1168 int common_scroll_down_pressed(int *start, int size, int max_show)
1170 // check if we even need to scroll at all
1171 if ( size <= max_show ) {
1184 loadout_data Player_loadout; // what the ship and weapon loadout is... used since we want to use the
1185 // same loadout if the mission is played again
1187 //wss_unit Wss_slots[MAX_WSS_SLOTS]; // slot data struct
1188 //int Wl_pool[MAX_WEAPON_TYPES]; // weapon pool
1189 //int Ss_pool[MAX_SHIP_TYPES]; // ship pool
1190 //int Wss_num_wings; // number of player wings
1192 wss_unit Wss_slots_teams[MAX_TEAMS][MAX_WSS_SLOTS];
1193 int Wl_pool_teams[MAX_TEAMS][MAX_WEAPON_TYPES];
1194 int Ss_pool_teams[MAX_TEAMS][MAX_SHIP_TYPES];
1195 int Wss_num_wings_teams[MAX_TEAMS];
1197 wss_unit *Wss_slots;
1202 // save ship selection loadout to the Player_loadout struct
1203 void wss_save_loadout()
1207 // save the ship pool
1208 for ( i = 0; i < MAX_SHIP_TYPES; i++ ) {
1209 Player_loadout.ship_pool[i] = Ss_pool[i];
1212 // save the weapons pool
1213 for ( i = 0; i < MAX_WEAPON_TYPES; i++ ) {
1214 Player_loadout.weapon_pool[i] = Wl_pool[i];
1217 // save the ship class / weapons for each slot
1218 for ( i = 0; i < MAX_WSS_SLOTS; i++ ) {
1219 Player_loadout.unit_data[i].ship_class = Wss_slots[i].ship_class;
1221 for ( j = 0; j < MAX_WL_WEAPONS; j++ ) {
1222 Player_loadout.unit_data[i].wep[j] = Wss_slots[i].wep[j];
1223 Player_loadout.unit_data[i].wep_count[j] = Wss_slots[i].wep_count[j];
1228 // restore ship/weapons loadout from the Player_loadout struct
1229 void wss_restore_loadout()
1234 // only restore if mission hasn't changed
1235 if ( stricmp(Player_loadout.last_modified, The_mission.modified) ) {
1239 // restore the ship pool
1240 for ( i = 0; i < MAX_SHIP_TYPES; i++ ) {
1241 Ss_pool[i] = Player_loadout.ship_pool[i];
1244 // restore the weapons pool
1245 for ( i = 0; i < MAX_WEAPON_TYPES; i++ ) {
1246 Wl_pool[i] = Player_loadout.weapon_pool[i];
1249 // restore the ship class / weapons for each slot
1250 for ( i = 0; i < MAX_WSS_SLOTS; i++ ) {
1251 slot = &Player_loadout.unit_data[i];
1252 Wss_slots[i].ship_class = slot->ship_class;
1254 for ( j = 0; j < MAX_WL_WEAPONS; j++ ) {
1255 Wss_slots[i].wep[j]= slot->wep[j];
1256 Wss_slots[i].wep_count[j] = slot->wep_count[j];
1261 // Do a direct restore of the Player_loadout ship/weapon data to the wings
1262 void wss_direct_restore_loadout()
1268 // only restore if mission hasn't changed
1269 if ( stricmp(Player_loadout.last_modified, The_mission.modified) ) {
1273 for ( i = 0; i < MAX_WING_BLOCKS; i++ ) {
1275 if ( Starting_wings[i] < 0 )
1278 wp = &Wings[Starting_wings[i]];
1280 // If this wing is still on the arrival list, then update the parse objects
1281 if ( wp->ship_index[0] == -1 ) {
1284 for ( p_objp = GET_FIRST(&ship_arrival_list); p_objp != END_OF_LIST(&ship_arrival_list); p_objp = GET_NEXT(p_objp) ) {
1285 slot = &Player_loadout.unit_data[i*4+j];
1286 if ( p_objp->wingnum == WING_INDEX(wp) ) {
1287 p_objp->ship_class = slot->ship_class;
1288 wl_update_parse_object_weapons(p_objp, slot);
1294 int cleanup_ship_index[MAX_WING_SLOTS];
1297 for ( k = 0; k < MAX_WING_SLOTS; k++ ) {
1298 cleanup_ship_index[k] = -1;
1301 // This wing is already created, so directly update the ships
1302 for ( j = 0; j < MAX_WING_SLOTS; j++ ) {
1303 slot = &Player_loadout.unit_data[i*4+j];
1304 shipp = &Ships[wp->ship_index[j]];
1305 if ( shipp->ship_info_index != slot->ship_class ) {
1307 if ( wp->ship_index[j] == -1 ) {
1311 if ( slot->ship_class == -1 ) {
1312 cleanup_ship_index[j] = wp->ship_index[j];
1313 ship_add_exited_ship( shipp, SEF_PLAYER_DELETED );
1314 obj_delete(shipp->objnum);
1315 hud_set_wingman_status_none( shipp->wing_status_wing_index, shipp->wing_status_wing_pos);
1318 change_ship_type(wp->ship_index[j], slot->ship_class);
1321 wl_bash_ship_weapons(&Ships[wp->ship_index[j]].weapons, slot);
1324 for ( k = 0; k < MAX_WING_SLOTS; k++ ) {
1325 if ( cleanup_ship_index[k] != -1 ) {
1326 ship_wing_cleanup( cleanup_ship_index[k], wp );
1333 int wss_slots_all_empty()
1337 for ( i = 0; i < MAX_WSS_SLOTS; i++ ) {
1338 if ( Wss_slots[i].ship_class >= 0 )
1342 if ( i == MAX_WSS_SLOTS )
1348 // determine the mode (WSS_...) based on slot/list index values
1349 int wss_get_mode(int from_slot, int from_list, int to_slot, int to_list, int wl_ship_slot)
1351 int mode, to_slot_empty=0;
1353 if ( wl_ship_slot >= 0 ) {
1355 if ( to_slot >= 0 ) {
1356 if ( Wss_slots[wl_ship_slot].wep_count[to_slot] == 0 ) {
1362 if ( to_slot >= 0 ) {
1363 if ( Wss_slots[to_slot].ship_class == -1 ){
1370 if ( from_slot >= 0 && to_slot >= 0 ) {
1371 mode = WSS_SWAP_SLOT_SLOT;
1372 } else if ( from_slot >= 0 && to_list >= 0 ) {
1373 mode = WSS_DUMP_TO_LIST;
1374 } else if ( (from_list >= 0) && (to_slot >= 0) && (to_slot_empty) ) {
1375 mode = WSS_GRAB_FROM_LIST;
1376 } else if ( (from_list >= 0) && (to_slot >= 0) && (!to_slot_empty) ) {
1377 mode = WSS_SWAP_LIST_SLOT;
1379 mode = -1; // no changes required
1385 // store all the unit data and pool data
1386 int store_wss_data(ubyte *block, int max_size, int sound,int player_index)
1392 // write the ship pool
1393 for ( i = 0; i < MAX_SHIP_TYPES; i++ ) {
1394 if ( Ss_pool[i] > 0 ) {
1395 block[offset++] = (ubyte)i;
1396 Assert( Ss_pool[i] < UCHAR_MAX );
1398 // take care of sign issues
1399 if(Ss_pool[i] == -1){
1400 block[offset++] = 0xff;
1402 block[offset++] = (ubyte)Ss_pool[i];
1407 block[offset++] = 0xff; // signals start of weapons pool
1409 // write the weapon pool
1410 for ( i = 0; i < MAX_WEAPON_TYPES; i++ ) {
1411 if ( Wl_pool[i] > 0 ) {
1412 block[offset++] = (ubyte)i;
1413 ishort = (short)Wl_pool[i];
1414 memcpy(block+offset, &ishort, sizeof(short));
1415 offset += sizeof(short);
1419 // write the unit data
1421 block[offset++] = 0xff; // signals start of unit data
1423 for ( i=0; i<MAX_WSS_SLOTS; i++ ) {
1424 Assert( Wss_slots[i].ship_class < UCHAR_MAX );
1425 if(Wss_slots[i].ship_class == -1){
1426 block[offset++] = 0xff;
1428 block[offset++] = (ubyte)(Wss_slots[i].ship_class);
1430 for ( j = 0; j < MAX_WL_WEAPONS; j++ ) {
1431 // take care of sign issues
1432 Assert( Wss_slots[i].wep[j] < UCHAR_MAX );
1433 if(Wss_slots[i].wep[j] == -1){
1434 block[offset++] = 0xff;
1436 block[offset++] = (ubyte)(Wss_slots[i].wep[j]);
1439 Assert( Wss_slots[i].wep_count[j] < SHRT_MAX );
1440 ishort = short(Wss_slots[i].wep_count[j]);
1442 memcpy(&(block[offset]), &(ishort), sizeof(short) );
1443 offset += sizeof(short);
1446 // mwa -- old way below -- too much space
1447 //memcpy(block+offset, &Wss_slots[i], sizeof(wss_unit));
1448 //offset += sizeof(wss_unit);
1453 block[offset++] = 0xff;
1455 block[offset++] = (ubyte)sound;
1458 // add a netplayer address to identify who should play the sound
1460 if(player_index != -1){
1461 player_id = Net_players[player_index].player_id;
1463 memcpy(block+offset,&player_id,sizeof(player_id));
1464 offset += sizeof(player_id);
1466 Assert( offset < max_size );
1470 int restore_wss_data(ubyte *block)
1472 int i, j, sanity, offset=0;
1477 // restore ship pool
1479 memset(Ss_pool, 0, MAX_SHIP_TYPES*sizeof(int));
1481 if ( sanity++ > MAX_SHIP_TYPES ) {
1486 b1 = block[offset++];
1491 // take care of sign issues
1492 b2 = block[offset++];
1500 // restore weapons pool
1502 memset(Wl_pool, 0, MAX_WEAPON_TYPES*sizeof(int));
1504 if ( sanity++ > MAX_WEAPON_TYPES ) {
1509 b1 = block[offset++];
1514 memcpy(&ishort, block+offset, sizeof(short));
1515 offset += sizeof(short);
1516 Wl_pool[b1] = ishort;
1519 for ( i=0; i<MAX_WSS_SLOTS; i++ ) {
1520 if(block[offset] == 0xff){
1521 Wss_slots[i].ship_class = -1;
1523 Wss_slots[i].ship_class = block[offset];
1526 for ( j = 0; j < MAX_WL_WEAPONS; j++ ) {
1527 // take care of sign issues
1528 if(block[offset] == 0xff){
1529 Wss_slots[i].wep[j] = -1;
1532 Wss_slots[i].wep[j] = (int)(block[offset++]);
1535 memcpy( &ishort, &(block[offset]), sizeof(short) );
1536 Wss_slots[i].wep_count[j] = (int)ishort;
1537 offset += sizeof(short);
1540 // mwa -- old way below
1541 //memcpy(&Wss_slots[i], block+offset, sizeof(wss_unit));
1542 //offset += sizeof(wss_unit);
1545 // read in the sound data
1546 sound = block[offset++]; // the sound index
1548 // read in the player address
1549 memcpy(&player_id,block+offset,sizeof(player_id));
1550 offset += sizeof(short);
1552 // determine if I'm the guy who should be playing the sound
1553 if((Net_player != NULL) && (Net_player->player_id == player_id)){
1556 gamesnd_play_iface((int)sound);
1560 if(!(Game_mode & GM_MULTIPLAYER)){
1561 ss_synch_interface();