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/Mission/MissionBriefCommon.cpp $
15 * C module for briefing code common to FreeSpace and FRED
18 * Revision 1.7 2003/05/25 02:30:42 taylor
21 * Revision 1.6 2002/06/17 06:33:09 relnev
22 * ryan's struct patch for gcc 2.95
24 * Revision 1.5 2002/06/09 04:41:22 relnev
25 * added copyright header
27 * Revision 1.4 2002/06/02 04:26:34 relnev
30 * Revision 1.3 2002/06/01 07:12:33 relnev
31 * a few NDEBUG updates.
33 * removed a few warnings.
35 * Revision 1.2 2002/05/07 03:16:46 theoddone33
36 * The Great Newline Fix
38 * Revision 1.1.1.1 2002/05/03 03:28:10 root
42 * 19 11/02/99 3:23p Jefff
43 * translate briefing icon names
45 * 18 9/09/99 9:44a Jefff
46 * doh, fixed reversed brief text color thingy. i am stoopid.
48 * 17 9/08/99 11:14a Jefff
49 * toned down hostile/friendly colors in briefing text
51 * 16 9/07/99 12:20p Mikeb
52 * return pos of briefing icon even it does not fit on screen.
54 * 15 9/03/99 1:32a Dave
55 * CD checking by act. Added support to play 2 cutscenes in a row
56 * seamlessly. Fixed super low level cfile bug related to files in the
57 * root directory of a CD. Added cheat code to set campaign mission # in
60 * 14 8/10/99 7:28p Jefff
61 * shuffled some text around
63 * 13 7/30/99 3:05p Jefff
64 * Fixed briefing icon fades -- in and out were reversed.
66 * 12 7/26/99 1:52p Mikeb
67 * Fixed strange briefing bug where a NULL wasn't being checked for when
68 * copying briefing stage text. Odd.
70 * 11 7/24/99 6:15p Jefff
71 * moved "stage x of y" text in multiplayer mode so its not covered by the
74 * 10 7/20/99 7:09p Jefff
75 * briefing text occupies full window in 1024x768
77 * 9 7/09/99 5:54p Dave
78 * Seperated cruiser types into individual types. Added tons of new
79 * briefing icons. Campaign screen.
81 * 8 6/29/99 7:39p Dave
82 * Lots of small bug fixes.
84 * 7 2/05/99 7:19p Neilk
85 * Removed black part from mission screen, fixed info text coords
87 * 6 1/29/99 4:17p Dave
88 * New interface screens.
90 * 5 12/18/98 1:13a Dave
91 * Rough 1024x768 support for Direct3D. Proper detection and usage through
94 * 4 10/23/98 3:51p Dave
95 * Full support for tstrings.tbl and foreign languages. All that remains
96 * is to make it active in Fred.
98 * 3 10/13/98 9:28a Dave
99 * Started neatening up freespace.h. Many variables renamed and
100 * reorganized. Added AlphaColors.[h,cpp]
102 * 2 10/07/98 10:53a Dave
105 * 1 10/07/98 10:49a Dave
107 * 122 6/09/98 10:31a Hoffoss
108 * Created index numbers for all xstr() references. Any new xstr() stuff
109 * added from here on out should be added to the end if the list. The
110 * current list count can be found in FreeSpace.cpp (search for
113 * 121 6/05/98 9:54a Lawrance
116 * 120 6/01/98 11:43a John
117 * JAS & MK: Classified all strings for localization.
119 * 119 5/23/98 10:38p Lawrance
120 * Avoid doing a cfile refresh when running debug
122 * 118 5/23/98 6:49p Lawrance
123 * Fix problems with refreshing the file list when a CD is inserted
125 * 117 5/21/98 6:57p Lawrance
126 * Don't prompt for the CD if voice not found
128 * 116 5/21/98 12:35a Lawrance
129 * Tweak how CD is checked for
131 * 115 5/12/98 11:46a John
132 * Changed the way the "glowing movement" type text draw. Use Hoffoss's
133 * gr_get_string_size optional length parameter to determine length of
134 * string which accounts for kerning on the last character and then I only
135 * draw each character only once.
137 * 114 5/08/98 5:32p Lawrance
138 * prompt for CD if can't load animations or voice
140 * 113 5/06/98 5:30p John
141 * Removed unused cfilearchiver. Removed/replaced some unused/little used
142 * graphics functions, namely gradient_h and _v and pixel_sp. Put in new
143 * DirectX header files and libs that fixed the Direct3D alpha blending
146 * 112 4/27/98 9:08p Allender
147 * fix the debriefing stage problems when clients get to screen long after
150 * 111 4/25/98 3:49p Lawrance
151 * Save briefing auto-advance pref
153 * 110 4/20/98 3:53p Lawrance
154 * Fix various bugs with auto-advancing through briefings.
159 #include "freespace.h"
167 #include "linklist.h"
174 #include "missionbrief.h"
175 #include "missiongrid.h"
176 #include "missionbriefcommon.h"
177 #include "animplay.h"
183 #include "audiostr.h"
184 #include "missioncmdbrief.h"
185 #include "missiondebrief.h"
186 #include "alphacolors.h"
187 #include "localize.h"
189 // --------------------------------------------------------------------------------------
191 // --------------------------------------------------------------------------------------
192 hud_frames Icon_bitmaps[MAX_BRIEF_ICONS][MAX_SPECIES_NAMES];
193 hud_anim Icon_highlight_anims[MAX_BRIEF_ICONS][MAX_SPECIES_NAMES];
194 hud_anim Icon_fade_anims[MAX_BRIEF_ICONS][MAX_SPECIES_NAMES];
197 // --------------------------------------------------------------------------------------
199 // --------------------------------------------------------------------------------------
201 brief_screen bscreen;
203 // briefing screen sections
204 #define BRIEF_CUP_X1 400
205 #define BRIEF_CUP_Y1 70
206 #define BRIEF_CUP_X2 639
207 #define BRIEF_CUP_Y2 245
208 #define BRIEF_CUPINFO_X1 445
209 #define BRIEF_CUPINFO_Y1 247
210 #define BRIEF_CUPINFO_X2 639
211 #define BRIEF_CUPINFO_Y2 438
213 char *Brief_static_name[GR_NUM_RESOLUTIONS] = {
218 int Brief_static_coords[GR_NUM_RESOLUTIONS][2] = {
231 int Brief_bmap_coords[GR_NUM_RESOLUTIONS][2] = {
244 int Brief_grid_coords[GR_NUM_RESOLUTIONS][4] = {
257 int Brief_text_coords[GR_NUM_RESOLUTIONS][4] = {
270 int Brief_stage_text_coords[GR_NUM_RESOLUTIONS][2] = {
283 int Brief_stage_text_coords_multi[GR_NUM_RESOLUTIONS][2] = {
296 int Brief_text_max_lines[GR_NUM_RESOLUTIONS] = {
300 #define LOOKAT_DIST 500.0f
302 // --------------------------------------------------------------------------------------
303 // Game-wide global data
304 // --------------------------------------------------------------------------------------
305 briefing Briefings[MAX_TEAMS]; // there is exactly one briefing per mission
306 debriefing Debriefings[MAX_TEAMS]; // there can be multiple debriefings per mission
307 briefing *Briefing; // pointer used in code -- points to correct briefing
308 debriefing *Debriefing; // pointer to correct debriefing
310 int Briefing_voice_enabled=1; // flag which turn on/off voice playback of briefings/debriefings
312 // --------------------------------------------------------------------------------------
313 // Module global data
314 // --------------------------------------------------------------------------------------
316 static int Last_new_stage;
319 const char BRIEF_META_CHAR = '$';
321 // static int Brief_voice_ask_for_cd;
324 static vector Current_cam_pos; // current camera position
325 static vector Target_cam_pos; // desired camera position
326 static matrix Current_cam_orient; // current camera orientation
327 static matrix Target_cam_orient; // desired camera orientation
328 static matrix Start_cam_orient; // start camera orientation
329 static vector Start_cam_pos; // position of camera at the start of a translation
330 static vector Cam_vel; // camera velocity
331 static vector Current_lookat_pos; // lookat point
332 static vector Target_lookat_pos; // lookat point
333 static vector Start_lookat_pos;
334 static vector Lookat_vel; // lookat point velocity
336 static float Start_cam_move; // time at which camera started moving (seconds)
337 static float Total_move_time; // time in which camera should move from current pos to target pos (seconds)
338 static float Elapsed_time;
340 static float Start_dist;
341 static float End_dist;
342 static float Dist_change_rate;
344 static vector Acc_limit;
345 static vector Vel_limit;
347 static float Total_dist;
348 static float Peak_speed;
349 static float Cam_accel;
350 static float Last_dist;
351 static vector W_init;
353 // flag to indicate that the sound for a spinning highlight animation has played
354 static int Brief_stage_highlight_sound_handle = -1;
356 // used for scrolling briefing text ( if necessary )
357 int Num_brief_text_lines[MAX_TEXT_STREAMS];
358 int Top_brief_text_line;
359 static char Brief_text[MAX_BRIEF_LINES][MAX_BRIEF_LINE_LEN];
361 // Used to support drawing colored text for the briefing. Gets complicates since we
362 // need to be able to draw one character at a time as well when the briefing text
364 typedef struct colored_char
367 ubyte color; // index into Brief_text_colors[]
370 static colored_char Colored_text[MAX_TEXT_STREAMS][MAX_BRIEF_LINES][MAX_BRIEF_LINE_LEN];
371 static int Colored_text_len[MAX_TEXT_STREAMS][MAX_BRIEF_LINES];
373 #define MAX_BRIEF_TEXT_COLORS 9
374 #define BRIEF_TEXT_WHITE 0
375 #define BRIEF_TEXT_BRIGHT_WHITE 1
376 #define BRIEF_TEXT_RED 2
377 #define BRIEF_TEXT_GREEN 3
378 #define BRIEF_TEXT_YELLOW 4
379 #define BRIEF_TEXT_BLUE 5
380 #define BRIEF_IFF_FRIENDLY 6
381 #define BRIEF_IFF_HOSTILE 7
382 #define BRIEF_IFF_NEUTRAL 8
384 color Brief_color_red, Brief_color_green;
386 color *Brief_text_colors[MAX_BRIEF_TEXT_COLORS] =
396 &IFF_colors[IFF_COLOR_NEUTRAL][0],
399 #define BRIGHTEN_LEAD 2
401 float Brief_text_wipe_time_elapsed;
402 static int Max_briefing_line_len;
404 static int Brief_voice_ended;
405 static int Brief_textdraw_finished;
406 static int Brief_voice_started;
407 static int Brief_stage_time;
409 const float BRIEF_TEXT_WIPE_TIME = 1.5f; // time in seconds for wipe to occur
410 static int Brief_text_wipe_snd; // sound handle of sound effect for text wipe
411 static int Play_brief_voice;
414 static int Play_highlight_flag;
415 static int Cam_target_reached;
416 static int Cam_movement_done;
419 typedef struct icon_move_info
421 icon_move_info *next, *prev;
428 // used to move icons smoothly
432 float total_move_time;
438 #define MAX_MOVE_ICONS 10
439 icon_move_info Icon_movers[MAX_MOVE_ICONS];
440 icon_move_info Icon_move_list; // head of linked list
443 typedef struct fade_icon
445 hud_anim fade_anim; // anim info
450 #define MAX_FADE_ICONS 30
451 fade_icon Fading_icons[MAX_FADE_ICONS];
454 // voice id's for briefing text
455 int Brief_voices[MAX_BRIEF_STAGES];
457 cmd_brief *Cur_cmd_brief;
458 cmd_brief Cmd_briefs[MAX_TEAMS];
460 // --------------------------------------------------------------------------------------
461 // forward declarations
462 // --------------------------------------------------------------------------------------
463 void brief_render_elements(vector *pos, grid *gridp);
464 void brief_render_icons(int stage_num, float frametime);
465 void brief_parse_icon_tbl();
466 void brief_grid_read_camera_controls( control_info * ci, float frametime );
467 void brief_maybe_create_new_grid(grid *gridp, vector *pos, matrix *orient, int force = 0);
468 grid *brief_create_grid(grid *gridp, vector *forward, vector *right, vector *center, int nrows, int ncols, float square_size);
469 grid *brief_create_default_grid(void);
470 void brief_render_grid(grid *gridp);
471 void brief_modify_grid(grid *gridp);
472 void brief_rpd_line(vector *v0, vector *v1);
473 void brief_set_text_color(int color_index);
474 extern void get_camera_limits(matrix *start_camera, matrix *end_camera, float time, vector *acc_max, vector *w_max);
475 int brief_text_wipe_finished();
477 void brief_set_icon_color(int team)
480 case TEAM_FRIENDLY: SET_COLOR_FRIENDLY; break;
481 case TEAM_HOSTILE: SET_COLOR_HOSTILE; break;
482 case TEAM_NEUTRAL: SET_COLOR_NEUTRAL; break;
483 case TEAM_TRAITOR: SET_COLOR_HOSTILE; break;
485 SET_COLOR_HOSTILE; break;
489 // --------------------------------------------------------------------------------------
490 // brief_move_icon_reset()
493 void brief_move_icon_reset()
497 list_init(&Icon_move_list);
498 for ( i = 0; i < MAX_MOVE_ICONS; i++ )
499 Icon_movers[i].used = 0;
503 // --------------------------------------------------------------------------------------
504 // Does one time initialization of the briefing and debriefing structures.
505 // Namely setting all malloc'ble pointers to NULL. Called once at game startup.
506 void mission_brief_common_init()
510 // setup brief text colors
511 gr_init_alphacolor( &Brief_color_green, 50, 100, 50, 255 );
512 gr_init_alphacolor( &Brief_color_red, 140, 20, 20, 255 );
514 if ( Fred_running ) {
515 // If Fred is running malloc out max space
516 for (i=0; i<MAX_TEAMS; i++ ) {
517 for (j=0; j<MAX_BRIEF_STAGES; j++ ) {
518 Briefings[i].stages[j].new_text = (char *)malloc(MAX_BRIEF_LEN);
519 Assert(Briefings[i].stages[j].new_text!=NULL);
520 Briefings[i].stages[j].icons = (brief_icon *)malloc(sizeof(brief_icon)*MAX_STAGE_ICONS);
521 Assert(Briefings[i].stages[j].icons!=NULL);
522 Briefings[i].stages[j].lines = (brief_line *)malloc(sizeof(brief_line)*MAX_BRIEF_STAGE_LINES);
523 Assert(Briefings[i].stages[j].lines!=NULL);
524 Briefings[i].stages[j].num_icons = 0;
525 Briefings[i].stages[j].num_lines = 0;
529 for (i=0; i<MAX_TEAMS; i++ ) {
530 for (j=0; j<MAX_DEBRIEF_STAGES; j++ ) {
531 Debriefings[i].stages[j].new_text = (char *)malloc(MAX_DEBRIEF_LEN);
532 Assert(Debriefings[i].stages[j].new_text!=NULL);
533 Debriefings[i].stages[j].new_recommendation_text = (char *)malloc(MAX_RECOMMENDATION_LEN);
534 Assert(Debriefings[i].stages[j].new_recommendation_text!=NULL);
539 // If game is running don't malloc anything
540 for (i=0; i<MAX_TEAMS; i++ ) {
541 for (j=0; j<MAX_BRIEF_STAGES; j++ ) {
542 Briefings[i].stages[j].new_text = NULL;
543 Briefings[i].stages[j].num_icons = 0;
544 Briefings[i].stages[j].icons = NULL;
545 Briefings[i].stages[j].num_lines = 0;
546 Briefings[i].stages[j].lines = NULL;
550 for (i=0; i<MAX_TEAMS; i++ ) {
551 for (j=0; j<MAX_DEBRIEF_STAGES; j++ ) {
552 Debriefings[i].stages[j].new_text = NULL;
553 Debriefings[i].stages[j].new_recommendation_text = NULL;
562 //--------------------------------------------------------------------------------------
563 // Frees all the memory allocated in the briefing and debriefing structures
564 // and sets all pointers to NULL.
565 void mission_brief_common_reset()
569 if ( Fred_running ) {
570 return; // Don't free these under Fred.
573 for (i=0; i<MAX_TEAMS; i++ ) {
574 for (j=0; j<MAX_BRIEF_STAGES; j++ ) {
575 if ( Briefings[i].stages[j].new_text ) {
576 free(Briefings[i].stages[j].new_text);
577 Briefings[i].stages[j].new_text = NULL;
580 if ( Briefings[i].stages[j].icons ) {
581 free(Briefings[i].stages[j].icons);
582 Briefings[i].stages[j].icons = NULL;
585 if ( Briefings[i].stages[j].lines ) {
586 free(Briefings[i].stages[j].lines);
587 Briefings[i].stages[j].lines = NULL;
592 for (i=0; i<MAX_TEAMS; i++ ) {
593 for (j=0; j<MAX_DEBRIEF_STAGES; j++ ) {
594 if ( Debriefings[i].stages[j].new_text ) {
595 free(Debriefings[i].stages[j].new_text);
596 Debriefings[i].stages[j].new_text = NULL;
598 if ( Debriefings[i].stages[j].new_recommendation_text ) {
599 free(Debriefings[i].stages[j].new_recommendation_text);
600 Debriefings[i].stages[j].new_recommendation_text = NULL;
610 // --------------------------------------------------------------------------------------
619 for ( i = 0; i < MAX_TEAMS; i++ )
620 Briefings[i].num_stages = 0;
624 // --------------------------------------------------------------------------------------
633 for ( i = 0; i < MAX_TEAMS; i++ ) {
634 Debriefings[i].num_stages = 0;
635 for (j=0; j<MAX_DEBRIEF_STAGES; j++ ) {
636 if ( Debriefings[i].stages[j].new_recommendation_text ) {
637 Debriefings[i].stages[j].new_recommendation_text[0] = 0;
642 // MWA 4/27/98 -- must initialize this variable here since we cannot do it as debrief
643 // init time because race conditions between all players in the game make that type of
644 // initialization unsafe.
645 Debrief_multi_stages_loaded = 0;
648 // --------------------------------------------------------------------------------------
649 // brief_init_screen()
651 // Set up the screen regions. A mulitplayer briefing will look different than a single player
654 void brief_init_screen(int multiplayer_flag)
656 bscreen.map_x1 = Brief_grid_coords[gr_screen.res][0];
657 bscreen.map_x2 = Brief_grid_coords[gr_screen.res][0] + Brief_grid_coords[gr_screen.res][2];
658 bscreen.map_y1 = Brief_grid_coords[gr_screen.res][1];
659 bscreen.map_y2 = Brief_grid_coords[gr_screen.res][1] + Brief_grid_coords[gr_screen.res][3];
661 bscreen.map_x1 = BRIEF_GRID3_X1;
662 bscreen.map_x2 = BRIEF_GRID0_X2;
663 bscreen.map_y1 = BRIEF_GRID3_Y1;
664 bscreen.map_y2 = BRIEF_GRID0_Y2+4;
665 bscreen.btext_x1 = BRIEF_TEXT_X1;
666 bscreen.btext_x2 = BRIEF_TEXT_X2;
667 bscreen.btext_y1 = BRIEF_TEXT_Y1;
668 bscreen.btext_y2 = BRIEF_TEXT_Y2;
669 bscreen.cup_x1 = BRIEF_CUP_X1;
670 bscreen.cup_y1 = BRIEF_CUP_Y1;
671 bscreen.cup_x2 = BRIEF_CUP_X2;
672 bscreen.cup_y2 = BRIEF_CUP_Y2;
673 bscreen.cupinfo_x1 = BRIEF_CUPINFO_X1;
674 bscreen.cupinfo_y1 = BRIEF_CUPINFO_Y1;
675 bscreen.cupinfo_x2 = BRIEF_CUPINFO_X2;
676 bscreen.cupinfo_y2 = BRIEF_CUPINFO_Y2;
680 // --------------------------------------------------------------------------------------
681 // brief_init_icons()
684 void brief_init_icons()
686 if ( Fred_running ) {
687 gr_init_alphacolor( &IFF_colors[IFF_COLOR_HOSTILE][0], 0xff, 0x00, 0x00, 15*16 );
688 gr_init_alphacolor( &IFF_colors[IFF_COLOR_FRIENDLY][0], 0x00, 0xff, 0x00, 15*16 );
691 // Load in the bitmaps for the icons from icons.tbl
692 brief_parse_icon_tbl();
695 // Reset the highlight and fade anims... call before brief_parse_icon_tbl();
696 void brief_init_anims()
703 for (i=0; i<MAX_BRIEF_ICONS; i++) {
705 for(idx=0; idx<MAX_SPECIES_NAMES; idx++){
706 Icon_highlight_anims[i][idx].num_frames=0;
707 Icon_fade_anims[i][idx].num_frames=0;
710 // one set of icons for all species in FS1
711 Icon_highlight_anims[i][1].num_frames=0;
712 Icon_fade_anims[i][1].num_frames=0;
717 // ------------------------------------------------------------------------
718 // brief_unload_icons()
721 void brief_unload_icons()
726 for ( i = 0; i < MAX_BRIEF_ICONS; i++ ) {
727 for(idx=0; idx<MAX_SPECIES_NAMES; idx++){
728 ib = &Icon_bitmaps[i][idx];
730 for ( j=0; j<ib->num_frames; j++ ) {
731 bm_unload(ib->first_frame+j);
737 // determine if icon type is used in the current briefing
738 int brief_icon_used_in_briefing(int icon_type)
740 int num_icons, num_stages, i, j;
742 num_stages = Briefing->num_stages;
744 for ( i = 0; i < num_stages; i++ ) {
745 num_icons = Briefing->stages[i].num_icons;
746 for ( j = 0; j < num_icons; j++ ) {
747 if ( Briefing->stages[i].icons[j].type == icon_type ) {
756 // --------------------------------------------------------------------------------------
757 // brief_parse_icon_tbl()
760 void brief_parse_icon_tbl()
763 char name[NAME_LENGTH];
771 if ((rval = setjmp(parse_abort)) != 0) {
772 Error(LOCATION, "Unable to parse icons.tbl! Code = %i.\n", rval);
775 read_file_text("icons.tbl");
780 required_string("#Start");
783 int load_this_icon = 0;
785 while (required_string_either("#End","$Name:")) {
786 for(idx=0; idx<MAX_SPECIES_NAMES; idx++){
787 Assert( num_icons < MAX_BRIEF_ICONS);
788 hf = &Icon_bitmaps[num_icons][idx];
790 // load in regular frames
791 required_string("$Name:");
792 stuff_string(name, F_NAME, NULL);
794 if ( Fred_running ) {
797 load_this_icon = brief_icon_used_in_briefing(num_icons);
800 if ( load_this_icon ) {
801 hf->first_frame = bm_load_animation(name, &hf->num_frames);
802 if ( hf->first_frame == -1 ) {
803 Int3(); // missing briefing icon
807 // load in fade frames
808 required_string("$Name:");
809 stuff_string(name, F_NAME, NULL);
810 ha = &Icon_fade_anims[num_icons][idx];
811 hud_anim_init(ha, 0, 0, name);
813 // load in highlighting frames
814 required_string("$Name:");
815 stuff_string(name, F_NAME, NULL);
816 ha = &Icon_highlight_anims[num_icons][idx];
817 hud_anim_init(ha, 0, 0, name);
823 required_string("#End");
825 // close localization
829 // --------------------------------------------------------------------------------------
833 void brief_close_map()
835 brief_unload_icons();
838 void brief_preload_highlight_anim(brief_icon *bi)
841 int species = ship_get_species_by_type(bi->ship_class);
847 ha = &Icon_highlight_anims[bi->type][species];
848 if ( !stricmp(NOX("none"), ha->name) ) {
852 // force read of data from disk, so we don't glitch on initial playback
853 if ( ha->first_frame == -1 ) {
855 Assert(ha->first_frame >= 0);
858 bi->highlight_anim = *ha;
860 gr_set_bitmap(ha->first_frame);
864 void brief_preload_fade_anim(brief_icon *bi)
867 int species = ship_get_species_by_type(bi->ship_class);
873 ha = &Icon_fade_anims[bi->type][species];
874 if ( !stricmp(NOX("none"), ha->name) ) {
878 // force read of data from disk, so we don't glitch on initial playback
879 if ( ha->first_frame == -1 ) {
881 Assert(ha->first_frame >= 0);
884 gr_set_bitmap(ha->first_frame);
888 // preload highlight, fadein and fadeout animations that are used in this stage
889 void brief_preload_anims()
891 int num_icons, num_stages, i, j;
894 num_stages = Briefing->num_stages;
896 for ( i = 0; i < num_stages; i++ ) {
897 num_icons = Briefing->stages[i].num_icons;
898 for ( j = 0; j < num_icons; j++ ) {
899 bi = &Briefing->stages[i].icons[j];
900 if ( bi->flags & BI_HIGHLIGHT ) {
901 brief_preload_highlight_anim(bi);
903 brief_preload_fade_anim(bi);
908 // --------------------------------------------------------------------------------------
912 void brief_init_map()
917 Assert( Briefing != NULL );
919 pos = &Briefing->stages[0].camera_pos;
920 orient = &Briefing->stages[0].camera_orient;
921 vm_vec_zero(&Current_lookat_pos);
922 vm_vec_zero(&Target_lookat_pos);
924 Total_move_time = 0.0f;
926 The_grid = brief_create_default_grid();
927 brief_maybe_create_new_grid(The_grid, pos, orient, 1);
931 brief_move_icon_reset();
932 brief_preload_anims();
934 Brief_text_wipe_snd = -1;
940 #pragma optimize("", off)
943 // render fade-out anim frame
945 void brief_render_fade_outs(float frametime)
949 vertex tv; // temp vertex used to find screen position for text
953 for (i=0; i<Num_fade_icons; i++) {
954 fi = &Fading_icons[i];
956 g3_rotate_vertex(&tv, &fi->pos);
958 if (!(tv.flags & PF_PROJECTED))
959 g3_project_vertex(&tv);
961 if (!(tv.flags & PF_OVERFLOW) ) { // make sure point projected before drawing text
963 brief_set_icon_color(fi->team);
965 if ( fi->fade_anim.first_frame < 0 ) {
969 bm_get_info( fi->fade_anim.first_frame, &w, &h, NULL);
971 bxf = tv.sx - w / 2.0f + 0.5f;
972 byf = tv.sy - h / 2.0f + 0.5f;
976 if ( fi->fade_anim.first_frame >= 0 ) {
977 fi->fade_anim.sx = bx;
978 fi->fade_anim.sy = by;
980 // FS1 has the anis reversed from FS2 so play them backwards
981 hud_anim_render(&fi->fade_anim, frametime, 1, 0, 0, 1);
983 hud_anim_render(&fi->fade_anim, frametime, 1, 0, 0, 0);
990 // figure out how far an icon should move based on the elapsed time
991 float brief_icon_get_dist_moved(icon_move_info *mi, float elapsed_time)
993 float time, dist_moved=0.0f;
995 // first half of movement
996 if ( elapsed_time < mi->total_move_time/2.0f ) {
997 dist_moved=0.5f*mi->accel*elapsed_time*elapsed_time; // d = 1/2at^2
1001 // second half of movement
1002 time=elapsed_time - mi->total_move_time/2.0f;
1003 dist_moved=(mi->total_dist/2.0f)+(mi->peak_speed*time) - 0.5f*mi->accel*time*time;
1007 // Draw a line between two icons on the briefing screen
1008 void brief_render_icon_line(int stage_num, int line_num)
1011 brief_icon *icon[2];
1012 vertex icon_vertex[2];
1013 int icon_status[2] = {0,0};
1014 int icon_w, icon_h, i;
1015 float icon_x[2], icon_y[2];
1017 bl = &Briefing->stages[stage_num].lines[line_num];
1018 icon[0] = &Briefing->stages[stage_num].icons[bl->start_icon];
1019 icon[1] = &Briefing->stages[stage_num].icons[bl->end_icon];
1022 for (i=0; i<2; i++) {
1023 g3_rotate_vertex(&icon_vertex[i],&icon[i]->pos);
1024 if (!(icon_vertex[i].flags&PF_PROJECTED))
1025 g3_project_vertex(&icon_vertex[i]);
1027 if (!(icon_vertex[i].flags & PF_OVERFLOW) ) { // make sure point projected before drawing text
1032 if ( !icon_status[0] || !icon_status[1] ) {
1036 // get screen (x,y) for icons
1037 for (i=0; i<2; i++) {
1038 brief_common_get_icon_dimensions(&icon_w, &icon_h, icon[i]->type, icon[i]->ship_class);
1039 icon_x[i] = icon_vertex[i].sx;
1040 icon_y[i] = icon_vertex[i].sy;
1043 brief_set_icon_color(icon[0]->team);
1045 gr_line(fl2i(icon_x[0]), fl2i(icon_y[0]), fl2i(icon_x[1]), fl2i(icon_y[1]));
1048 // -------------------------------------------------------------------------------------
1049 // Draw a briefing icon
1051 // parameters: stage_num => briefing stage number (start at 0)
1052 // icon_num => icon number in stage
1053 // frametime => time elapsed in seconds
1054 // selected => FRED only (will be 0 or non-zero)
1055 // w_scale_factor => scale icon in width by this amount (default 1.0f)
1056 // h_scale_factor => scale icon in height by this amount (default 1.0f)
1057 void brief_render_icon(int stage_num, int icon_num, float frametime, int selected, float w_scale_factor, float h_scale_factor)
1059 brief_icon *bi, *closeup_icon;
1061 vertex tv; // temp vertex used to find screen position for text
1063 int bx,by,bc,w,h,icon_w,icon_h,icon_bitmap=-1;
1064 float bxf, byf, dist=0.0f;
1066 Assert( Briefing != NULL );
1068 bi = &Briefing->stages[stage_num].icons[icon_num];
1070 icon_move_info *mi, *next;
1071 int interp_pos_found = 0;
1073 mi = GET_FIRST(&Icon_move_list);
1075 while ( mi != &Icon_move_list ) {
1077 if ( ( mi->id != 0 ) && ( mi->id == bi->id ) ) {
1079 if ( !mi->reached_dest ) {
1080 dist = brief_icon_get_dist_moved(mi, Elapsed_time);
1081 if ( dist < mi->last_dist ) {
1088 if ( !mi->reached_dest ) {
1090 vm_vec_copy_scale(&dist_moved, &mi->direction, dist);
1091 vm_vec_add(&mi->current, &mi->start, &dist_moved);
1093 mi->current = mi->finish;
1097 interp_pos_found = 1;
1103 if ( !interp_pos_found )
1106 brief_render_elements(pos, The_grid);
1107 g3_rotate_vertex(&tv,pos);
1109 if (!(tv.flags&PF_PROJECTED))
1110 g3_project_vertex(&tv);
1112 if (!(tv.flags & PF_OVERFLOW) ) { // make sure point projected before drawing text
1114 brief_set_icon_color(bi->team);
1116 int species = ship_get_species_by_type(bi->ship_class);
1122 ib = &Icon_bitmaps[bi->type][species];
1123 if ( ib->first_frame < 0 ) {
1128 brief_common_get_icon_dimensions(&icon_w, &icon_h, bi->type, bi->ship_class);
1130 closeup_icon = (brief_icon*)brief_get_closeup_icon();
1131 if ( bi == closeup_icon || selected ) {
1132 icon_bitmap=ib->first_frame+1;
1133 // gr_set_bitmap(ib->first_frame+1);
1136 icon_bitmap=ib->first_frame;
1137 // gr_set_bitmap(ib->first_frame);
1140 // draw icon centered at draw position
1141 // bx = fl2i(tv.sx - ib->icon_w/2.0f);
1142 // by = fl2i(tv.sy - ib->icon_h/2.0f);
1143 // bc = bx + fl2i(ib->icon_w/2.0f);
1144 //gr_aabitmap(bx, by);
1146 float scaled_w, scaled_h;
1148 scaled_w = icon_w * w_scale_factor;
1149 scaled_h = icon_h * h_scale_factor;
1150 bxf = tv.sx - scaled_w / 2.0f + 0.5f;
1151 byf = tv.sy - scaled_h / 2.0f + 0.5f;
1156 if ( (bx < 0) || (bx > gr_screen.max_w) || (by < 0) || (by > gr_screen.max_h) && !Fred_running ) {
1168 vb.sx = bxf+scaled_w-1;
1169 vb.sy = byf+scaled_h-1;
1173 // render highlight anim frame
1174 if ( (bi->flags&BI_SHOWHIGHLIGHT) && (bi->flags&BI_HIGHLIGHT) ) {
1175 hud_anim *ha = &bi->highlight_anim;
1176 if ( ha->first_frame >= 0 ) {
1177 ha->sx = bi->hold_x;
1178 if ( strlen(bi->label) > 0 ) {
1179 ha->sy = bi->hold_y - fl2i(gr_get_font_height()/2.0f +0.5) - 2;
1181 ha->sy = bi->hold_y;
1184 //hud_set_iff_color(bi->team);
1185 brief_set_icon_color(bi->team);
1187 hud_anim_render(ha, frametime, 1, 0, 1);
1189 if ( Brief_stage_highlight_sound_handle < 0 ) {
1190 if ( !Fred_running) {
1191 Brief_stage_highlight_sound_handle = snd_play(&Snds_iface[SND_ICON_HIGHLIGHT]);
1197 // render fade-in anim frame
1198 if ( bi->flags & BI_FADEIN ) {
1199 hud_anim *ha = &bi->fadein_anim;
1200 if ( ha->first_frame >= 0 ) {
1203 // hud_set_iff_color(bi->team);
1204 brief_set_icon_color(bi->team);
1207 // FS1 has the anims backwards from FS2 so play in reverse
1208 if ( hud_anim_render(ha, frametime, 1, 0, 0, 0) == 0 ) {
1210 if ( hud_anim_render(ha, frametime, 1, 0, 0, 1) == 0 ) {
1212 bi->flags &= ~BI_FADEIN;
1215 bi->flags &= ~BI_FADEIN;
1219 if ( !(bi->flags & BI_FADEIN) ) {
1220 gr_set_bitmap(icon_bitmap);
1222 if ( Fred_running ) {
1223 gr_aascaler(&va, &vb);
1225 // Don't bother scaling for the game
1226 gr_aabitmap(bx, by);
1229 // draw text centered over the icon (make text darker)
1230 if ( bi->type == ICON_FIGHTER_PLAYER || bi->type == ICON_BOMBER_PLAYER ) {
1231 gr_get_string_size(&w,&h,Players[Player_num].callsign);
1232 gr_printf(bc - fl2i(w/2.0f), by - h, Players[Player_num].callsign);
1237 strcpy(buf, bi->label);
1238 lcl_translate_brief_icon_name(buf);
1239 gr_get_string_size(&w, &h, buf);
1240 gr_printf(bc - fl2i(w/2.0f), by - h, buf);
1242 gr_get_string_size(&w,&h,bi->label);
1243 gr_printf(bc - fl2i(w/2.0f), by - h, bi->label);
1247 // show icon as selected (FRED only)
1249 gr_get_string_size(&w,&h,NOX("(S)"));
1250 gr_printf(bc - fl2i(w/2.0f), by - h*2, NOX("(S)"));
1254 // store screen x,y,w,h
1257 bi->w = fl2i(scaled_w);
1258 bi->h = fl2i(scaled_h);
1260 } // end if vertex is projected
1264 #pragma optimize("", on)
1267 // -------------------------------------------------------------------------------------
1268 // brief_render_icons()
1270 void brief_render_icons(int stage_num, float frametime)
1272 int i, num_icons, num_lines;
1274 Assert( Briefing != NULL );
1276 num_icons = Briefing->stages[stage_num].num_icons;
1277 num_lines = Briefing->stages[stage_num].num_lines;
1279 if ( Cam_target_reached ) {
1280 for ( i = 0; i < num_lines; i++ ) {
1281 brief_render_icon_line(stage_num, i);
1285 for ( i = 0; i < num_icons; i++ ) {
1286 brief_render_icon(stage_num, i, frametime, 0);
1290 // ------------------------------------------------------------------------------------
1291 // brief_start_highlight_anims()
1293 // see if there are any highlight animations to play
1295 void brief_start_highlight_anims(int stage_num)
1299 int x,y,i,anim_w,anim_h;
1301 Assert( Briefing != NULL );
1302 bs = &Briefing->stages[stage_num];
1304 for ( i = 0; i < bs->num_icons; i++ ) {
1306 if ( bi->flags & BI_HIGHLIGHT ) {
1307 bi->flags &= ~BI_SHOWHIGHLIGHT;
1308 if ( bi->highlight_anim.first_frame < 0 ) {
1312 bi->highlight_anim.time_elapsed=0.0f;
1314 bm_get_info( bi->highlight_anim.first_frame, &anim_w, &anim_h, NULL);
1315 x = fl2i( i2fl(bi->x) + bi->w/2.0f - anim_w/2.0f );
1316 y = fl2i( i2fl(bi->y) + bi->h/2.0f - anim_h/2.0f );
1319 bi->flags |= BI_SHOWHIGHLIGHT;
1320 bi->highlight_anim.time_elapsed=0.0f;
1325 // -------------------------------------------------------------------------------------
1326 // brief_render_map()
1329 void brief_render_map(int stage_num, float frametime)
1333 gr_set_clip(bscreen.map_x1 + 1, bscreen.map_y1 + 1, bscreen.map_x2 - bscreen.map_x1 - 1, bscreen.map_y2 - bscreen.map_y1 - 2);
1335 // REMOVED by neilk: removed gr_clear for FS2 because interface no longer calls for black background on grid
1340 if (stage_num >= Briefing->num_stages) {
1346 bs = &Briefing->stages[stage_num];
1349 g3_set_view_matrix(&Current_cam_pos, &Current_cam_orient, 0.5f);
1351 brief_maybe_create_new_grid(The_grid, &Current_cam_pos, &Current_cam_orient);
1352 brief_render_grid(The_grid);
1354 brief_render_fade_outs(frametime);
1356 // go ahead and render everything that is in the active objects list
1357 brief_render_icons(stage_num, frametime);
1359 if ( Cam_target_reached && brief_text_wipe_finished() ) {
1361 if ( Brief_textdraw_finished == 0 ) {
1362 Brief_textdraw_finished = 1;
1363 Brief_stage_time = 0;
1366 if ( Play_highlight_flag ) {
1367 brief_start_highlight_anims(stage_num);
1368 Play_highlight_flag = 0;
1372 anim_render_all(ON_BRIEFING_SELECT, frametime);
1379 // -------------------------------------------------------------------------------------
1380 // brief_text_set_color()
1382 void brief_text_set_color(char c) {
1394 gr_set_color_fast(&Color_red);
1397 gr_set_color_fast(&Color_green);
1400 gr_set_color_fast(&Color_blue);
1403 Int3(); // unsupported meta-code
1408 // Display what stage of the briefing is active
1409 void brief_blit_stage_num(int stage_num, int stage_max)
1414 Assert( Briefing != NULL );
1416 gr_set_color_fast(&Color_bright_blue);
1418 gr_set_color_fast(&Color_text_heading);
1420 sprintf(buf, XSTR( "Stage %d of %d", 394), stage_num + 1, stage_max);
1421 if (Game_mode & GM_MULTIPLAYER) {
1422 gr_printf(Brief_stage_text_coords_multi[gr_screen.res][0], Brief_stage_text_coords_multi[gr_screen.res][1], buf);
1424 gr_printf(Brief_stage_text_coords[gr_screen.res][0], Brief_stage_text_coords[gr_screen.res][1], buf);
1427 // draw the title of the mission
1428 // if this goes above briefing text, it will need to be raised 10 pixels in multiplayer to make
1429 // room for stage num, which makes toom for chat box
1431 if (Game_mode & GM_MULTIPLAYER) {
1432 gr_get_string_size(&w,NULL,The_mission.name);
1433 gr_string(bscreen.map_x2 - w, bscreen.map_y2 + 5, The_mission.name);
1435 gr_get_string_size(&w,NULL,The_mission.name);
1436 gr_string(bscreen.map_x2 - w, bscreen.map_y2 + 5, The_mission.name);
1441 // Render a line of text for the briefings. Lines are drawn in as a wipe, with leading bright
1442 // white characters. Have to jump through some hoops since we support colored words. This means
1443 // that we need to process the line one character at a time.
1444 void brief_render_line(int line_num, int x, int y, int instance)
1446 int len, count, next, truncate_len, last_color, offset, w, h, bright_len, i;
1448 char line[MAX_BRIEF_LINE_LEN];
1450 src = &Colored_text[instance][line_num][0];
1451 len = Colored_text_len[instance][line_num];
1457 truncate_len = fl2i(Brief_text_wipe_time_elapsed / BRIEF_TEXT_WIPE_TIME * Max_briefing_line_len);
1458 if (truncate_len > len){
1463 if (truncate_len < len) {
1464 if (truncate_len <= BRIGHTEN_LEAD) {
1465 bright_len = truncate_len;
1469 bright_len = BRIGHTEN_LEAD;
1470 truncate_len -= BRIGHTEN_LEAD;
1478 gr_set_color_fast(&Color_white);
1479 last_color = BRIEF_TEXT_WHITE;
1480 for (i=0; i<truncate_len; i++) {
1481 if (count >= truncate_len){
1485 line[next] = src[count].letter;
1487 if (is_white_space(line[next])) {
1488 // end of word reached, blit it
1490 gr_string(x + offset, y, line);
1491 gr_get_string_size(&w, &h, line);
1496 if (last_color != BRIEF_TEXT_WHITE) {
1497 brief_set_text_color(BRIEF_TEXT_WHITE);
1498 last_color = BRIEF_TEXT_WHITE;
1505 if (src[count].color != last_color) {
1506 brief_set_text_color(src[count].color);
1507 last_color = src[count].color;
1515 gr_string(x + offset, y, line);
1518 // draw leading portion of the line bright white
1521 gr_set_color_fast(&Color_bright_white);
1522 for (i=0; i<truncate_len+bright_len; i++) {
1523 line[i] = src[i].letter;
1529 if ( truncate_len > 0 ) {
1530 int width_dim, height_dim;
1531 gr_get_string_size(&width_dim, &height_dim, line, truncate_len );
1532 gr_string(x+width_dim, y, &line[truncate_len]);
1534 gr_string(x, y, line);
1538 // // now erase the part we don't want to be bright white
1539 // gr_set_color_fast(&Color_black);
1540 // if (i > BRIGHTEN_LEAD) {
1541 // line[i - BRIGHTEN_LEAD] = 0;
1542 // gr_get_string_size(&w, &h, line);
1543 // gr_set_clip(x, y, w, gr_get_font_height());
1550 int brief_text_wipe_finished()
1552 if ( Brief_text_wipe_time_elapsed > (BRIEF_TEXT_WIPE_TIME+0.5f) ) {
1559 // -------------------------------------------------------------------------------------
1560 // brief_render_text()
1562 // input: frametime => Time in seconds of previous frame
1563 // instance => Optional parameter. Used to indicate which text stream is used.
1564 // This value is 0 unless multiple text streams are required
1565 int brief_render_text(int line_offset, int x, int y, int h, float frametime, int instance, int line_spacing)
1569 fh = gr_get_font_height();
1570 if (Brief_text_wipe_time_elapsed == 0) {
1571 if (snd_is_playing(Brief_text_wipe_snd)) {
1572 snd_stop(Brief_text_wipe_snd);
1574 gamesnd_play_iface(SND_BRIEF_TEXT_WIPE);
1575 Play_brief_voice = 1;
1578 Brief_text_wipe_time_elapsed += frametime;
1582 while (yy + fh <= h) {
1583 if (line >= Num_brief_text_lines[instance])
1586 brief_render_line(line, x, y + yy, instance);
1589 yy += fh + line_spacing;
1592 if ( brief_text_wipe_finished() && (Play_brief_voice) ) {
1593 Play_brief_voice = 0;
1600 // ------------------------------------------------------------------------------------
1601 // brief_render_elements()
1603 // Draw the lines that show objects positions on the grid
1605 void brief_render_elements(vector *pos, grid* gridp)
1607 vector gpos; // Location of point on grid.
1613 if ( pos->xyz.y < 1 && pos->xyz.y > -1 )
1616 tplane.A = gridp->gmatrix.v.uvec.xyz.x;
1617 tplane.B = gridp->gmatrix.v.uvec.xyz.y;
1618 tplane.C = gridp->gmatrix.v.uvec.xyz.z;
1619 tplane.D = gridp->planeD;
1621 compute_point_on_plane(&gpos, &tplane, pos);
1623 dxz = vm_vec_dist(pos, &gpos)/8.0f;
1625 gv = &gridp->gmatrix.v.uvec;
1626 if (gv->xyz.x * pos->xyz.x + gv->xyz.y * pos->xyz.y + gv->xyz.z * pos->xyz.z < -gridp->planeD)
1627 gr_set_color(127, 127, 127);
1629 gr_set_color(255, 255, 255); // white
1631 // AL 11-20-97: don't draw elevation lines.. they are confusing
1633 brief_rpd_line(&gpos, pos); // Line from grid to object center.
1637 vm_vec_scale_add2(&gpos, &gridp->gmatrix.v.rvec, -dxz/2);
1638 vm_vec_scale_add2(&gpos, &gridp->gmatrix.v.fvec, -dxz/2);
1640 vm_vec_scale_add2(&tpos, &gridp->gmatrix.v.rvec, dxz/2);
1641 vm_vec_scale_add2(&tpos, &gridp->gmatrix.v.fvec, dxz/2);
1643 brief_rpd_line(&gpos, &tpos);
1645 vm_vec_scale_add2(&gpos, &gridp->gmatrix.v.rvec, dxz);
1646 vm_vec_scale_add2(&tpos, &gridp->gmatrix.v.rvec, -dxz);
1648 brief_rpd_line(&gpos, &tpos);
1653 // ------------------------------------------------------------------------------------
1654 // brief_reset_icons()
1656 void brief_reset_icons(int stage_num)
1662 Assert( Briefing != NULL );
1663 bs = &Briefing->stages[stage_num];
1665 for ( i = 0; i < bs->num_icons; i++ ) {
1667 bi->flags &= ~BI_SHOWHIGHLIGHT;
1671 // ------------------------------------------------------------------------------------
1672 // brief_set_camera_target()
1674 // input: pos => target position for the camera
1675 // orient => target orientation for the camera
1676 // time => time in ms to reach target
1678 void brief_set_camera_target(vector *pos, matrix *orient, int time)
1680 float time_in_seconds;
1682 time_in_seconds = time / 1000.0f;
1685 Current_cam_pos = *pos;
1686 Current_cam_orient = *orient;
1689 Target_cam_pos = *pos;
1690 Target_cam_orient = *orient;
1691 Start_cam_orient = Current_cam_orient;
1692 Start_cam_pos = Current_cam_pos; // we need this when checking if camera movement complete
1693 Start_cam_move = timer_get_milliseconds()*1000.0f; // start time, convert to seconds
1694 Total_move_time = time_in_seconds;
1695 Elapsed_time = 0.0f;
1697 vm_vec_scale_add(&Start_lookat_pos, &Start_cam_pos, &Start_cam_orient.v.fvec, LOOKAT_DIST);
1698 vm_vec_scale_add(&Target_lookat_pos, &Target_cam_pos, &Target_cam_orient.v.fvec, LOOKAT_DIST);
1700 Play_highlight_flag = 1; // once target reached, play highlight anims
1701 Cam_target_reached = 0;
1702 Cam_movement_done=0;
1703 anim_release_all_instances(ON_BRIEFING_SELECT); // stop any briefing-specific anims
1705 // calculate camera velocity
1706 vm_vec_sub(&Cam_vel, pos, &Current_cam_pos);
1707 // vm_vec_scale(&Cam_vel, 1.0f/time_in_seconds);
1708 if ( !IS_VEC_NULL(&Cam_vel) ) {
1709 vm_vec_normalize(&Cam_vel);
1712 // calculate lookat point velocity
1713 vm_vec_sub(&Lookat_vel, &Target_lookat_pos, &Current_lookat_pos);
1714 vm_vec_scale(&Lookat_vel, 1.0f/time_in_seconds);
1716 Start_dist = vm_vec_dist(&Start_cam_pos, &Start_lookat_pos);
1717 End_dist = vm_vec_dist(&Target_cam_pos, &Target_lookat_pos);
1718 Dist_change_rate = (End_dist - Start_dist) / time_in_seconds;
1720 Total_dist=vm_vec_dist(&Start_cam_pos, &Target_cam_pos);
1722 // Peak_speed=Total_dist/Total_move_time*1.5f;
1723 // Cam_accel = Peak_speed/Total_move_time*3.0f;
1725 Peak_speed=Total_dist/Total_move_time*2.0f;
1726 Cam_accel = 4*Total_dist/(Total_move_time*Total_move_time);
1729 vm_vec_zero(&W_init);
1731 get_camera_limits(&Start_cam_orient, &Target_cam_orient, Total_move_time, &Acc_limit, &Vel_limit);
1735 ubyte brief_return_color_index(char c)
1739 return BRIEF_IFF_FRIENDLY;
1742 return BRIEF_IFF_HOSTILE;
1745 return BRIEF_IFF_NEUTRAL;
1748 return BRIEF_TEXT_RED;
1751 return BRIEF_TEXT_GREEN;
1754 return BRIEF_TEXT_BLUE;
1757 Int3(); // unsupported meta-code
1761 return BRIEF_TEXT_WHITE;
1764 void brief_set_text_color(int color_index)
1766 Assert(color_index < MAX_BRIEF_TEXT_COLORS);
1767 gr_set_color_fast(Brief_text_colors[color_index]);
1770 // Set up the Colored_text array.
1771 // input: index => Index into Brief_text[] for source text.
1772 // instance => Which instance of Colored_text[] to use.
1773 // Value is 0 unless multiple text streams are required.
1774 int brief_text_colorize(int index, int instance)
1777 int len, i, skip_to_next_word, dest_len;
1779 ubyte active_color_index;
1781 src = Brief_text[index];
1782 dest = &Colored_text[instance][index][0];
1785 skip_to_next_word = 0;
1787 active_color_index = BRIEF_TEXT_WHITE;
1788 for (i=0; i<len; i++) {
1789 if (skip_to_next_word) {
1790 if (is_white_space(src[i])) {
1791 skip_to_next_word = 0;
1797 if ( src[i] == BRIEF_META_CHAR && is_white_space(src[i + 2]) ) {
1798 active_color_index = brief_return_color_index(src[i + 1]);
1799 skip_to_next_word = 1;
1803 if (is_white_space(src[i])) {
1804 active_color_index = BRIEF_TEXT_WHITE;
1807 dest[dest_len].letter = src[i];
1808 dest[dest_len].color = active_color_index;
1812 dest[dest_len].letter = 0;
1813 Colored_text_len[instance][index] = dest_len;
1817 // ------------------------------------------------------------------------------------
1818 // brief_color_text_init()
1820 // input: src => paragraph of text to process
1821 // w => max width of line in pixels
1822 // instance => optional parameter, used when multiple text streams are required
1823 // (default value is 0)
1824 int brief_color_text_init(char *src, int w, int instance)
1826 int i, n_lines, len;
1827 int n_chars[MAX_BRIEF_LINES];
1828 char *p_str[MAX_BRIEF_LINES];
1831 n_lines = split_str(src, w, n_chars, p_str, MAX_BRIEF_LINES, BRIEF_META_CHAR);
1832 Assert(n_lines >= 0);
1834 Max_briefing_line_len = 1;
1835 for (i=0; i<n_lines; i++) {
1836 Assert(n_chars[i] < MAX_BRIEF_LINE_LEN);
1837 strncpy(Brief_text[i], p_str[i], n_chars[i]);
1838 Brief_text[i][n_chars[i]] = 0;
1839 drop_leading_white_space(Brief_text[i]);
1840 len = brief_text_colorize(i, instance);
1841 if (len > Max_briefing_line_len)
1842 Max_briefing_line_len = len;
1845 Brief_text_wipe_time_elapsed = 0.0f;
1846 Play_brief_voice = 0;
1848 Num_brief_text_lines[instance] = n_lines;
1852 // ------------------------------------------------------------------------------------
1853 // brief_get_free_move_icon()
1855 // returns: failure => -1
1856 // success => handle to a free move icon struct
1858 int brief_get_free_move_icon()
1862 for ( i = 0; i < MAX_MOVE_ICONS; i++ ) {
1863 if ( Icon_movers[i].used == 0 )
1867 if ( i == MAX_MOVE_ICONS )
1870 Icon_movers[i].used = 1;
1875 // ------------------------------------------------------------------------------------
1876 // brief_set_move_list()
1878 // input: new_stage => new stage number that briefing is now moving to
1879 // current_stage => current stage that the briefing is on
1880 // time => time in seconds
1882 int brief_set_move_list(int new_stage, int current_stage, float time)
1884 brief_stage *newb, *cb;
1885 icon_move_info *imi;
1886 int i,j,k,num_movers,is_gone=0;
1888 Assert(new_stage != current_stage);
1890 Assert( Briefing != NULL );
1891 newb = &Briefing->stages[new_stage];
1892 cb = &Briefing->stages[current_stage];
1895 for ( i = 0; i < cb->num_icons; i++ ) {
1897 for ( j = 0; j < newb->num_icons; j++ ) {
1898 if ( ( cb->icons[i].id != 0 ) && ( cb->icons[i].id == newb->icons[j].id ) ) {
1900 if ( vm_vec_cmp(&cb->icons[i].pos, &newb->icons[j].pos) ) {
1901 //nprintf(("Alan","We found a match in icon %s\n", cb->icons[i].label));
1902 k = brief_get_free_move_icon();
1904 Int3(); // should never happen, get Alan
1907 imi = &Icon_movers[k];
1908 imi->id = cb->icons[i].id;
1909 imi->start = cb->icons[i].pos;
1910 imi->finish = newb->icons[j].pos;
1911 imi->current = imi->start;
1912 list_append(&Icon_move_list, imi);
1914 imi->total_dist = vm_vec_dist(&imi->start, &imi->finish);
1915 imi->total_move_time = time;
1916 imi->peak_speed = imi->total_dist/imi->total_move_time*2.0f;
1917 imi->accel = 4*imi->total_dist/(time*time);
1918 imi->last_dist=0.0f;
1919 imi->reached_dest=0;
1922 vm_vec_sub(&imi->direction, &imi->finish, &imi->start);
1923 if ( !IS_VEC_NULL(&imi->direction) ) {
1924 vm_vec_normalize(&imi->direction);
1932 // Set up fading icon (to fade out)
1934 if ( Num_fade_icons >= MAX_FADE_ICONS ) {
1939 int species = ship_get_species_by_type(cb->icons[i].ship_class);
1944 Fading_icons[Num_fade_icons].fade_anim = Icon_fade_anims[cb->icons[i].type][species];
1945 Fading_icons[Num_fade_icons].pos = cb->icons[i].pos;
1946 Fading_icons[Num_fade_icons].team = cb->icons[i].team;
1951 // flag new icons for fading in
1952 for ( i=0; i<newb->num_icons; i++ ) {
1954 newb->icons[i].flags &= ~BI_FADEIN;
1955 for ( j=0; j<cb->num_icons; j++ ) {
1956 if ( ( cb->icons[j].id != 0 ) && ( cb->icons[j].id == newb->icons[i].id ) ) {
1961 int species = ship_get_species_by_type(newb->icons[i].ship_class);
1966 newb->icons[i].flags |= BI_FADEIN;
1967 newb->icons[i].fadein_anim = Icon_fade_anims[newb->icons[i].type][species];
1968 newb->icons[i].fadein_anim.time_elapsed = 0.0f;
1975 void brief_clear_fade_out_icons()
1981 // ------------------------------------------------------------------------------------
1982 // brief_set_new_stage()
1984 // input: pos => target position for the camera
1985 // orient => target orientation for the camera
1986 // time => time in ms to reach target
1987 // stage_num => stage number of briefing (start numbering at 0)
1990 void brief_set_new_stage(vector *pos, matrix *orient, int time, int stage_num)
1992 char msg[MAX_BRIEF_LEN];
1993 int num_movers, new_time, not_objv = 1;
1995 Assert( Briefing != NULL );
1998 if (stage_num >= Briefing->num_stages) {
1999 not_objv = 0; // turns out this is an objectives stage
2003 if ( stage_num == Last_new_stage ) {
2008 brief_move_icon_reset();
2009 brief_clear_fade_out_icons();
2010 if ( (Last_new_stage != -1) && not_objv ) {
2011 num_movers = brief_set_move_list(stage_num, Last_new_stage, new_time / 1000.0f);
2014 if ( (Last_new_stage != -1) && (num_movers == 0) && not_objv ) {
2015 if ( !vm_vec_cmp( &Briefing->stages[stage_num].camera_pos, &Briefing->stages[Last_new_stage].camera_pos) ) {
2016 if ( !vm_vec_cmp( &Briefing->stages[stage_num].camera_orient.v.fvec, &Briefing->stages[Last_new_stage].camera_orient.v.fvec) ){
2023 if(Briefing->stages[stage_num].new_text == NULL){
2026 strcpy(msg, Briefing->stages[stage_num].new_text);
2029 strcpy(msg, XSTR( "Please review your objectives for this mission.", 395));
2032 if (gr_screen.res == GR_640) {
2034 Num_brief_text_lines[0] = brief_color_text_init(msg, MAX_BRIEF_LINE_W_640);
2037 Num_brief_text_lines[0] = brief_color_text_init(msg, MAX_BRIEF_LINE_W_1024);
2039 Top_brief_text_line = 0;
2042 brief_set_camera_target(pos, orient, new_time);
2045 if ( snd_is_playing(Brief_stage_highlight_sound_handle) ) {
2046 snd_stop(Brief_stage_highlight_sound_handle);
2049 Brief_voice_ended = 0;
2050 Brief_textdraw_finished = 0;
2051 Brief_voice_started = 0;
2052 Brief_stage_time = 0;
2055 Brief_stage_highlight_sound_handle = -1;
2056 Last_new_stage = stage_num;
2059 // ------------------------------------------------------------------------------------
2060 // camera_pos_past_target()
2063 int camera_pos_past_target(vector *start, vector *current, vector *dest)
2068 vm_vec_sub(&num, current, start);
2069 vm_vec_sub(&den, start, dest);
2071 ratio = vm_vec_mag_quick(&num) / vm_vec_mag_quick(&den);
2078 // ------------------------------------------------------------------------------------
2079 // Interpolate between matrices.
2080 // elapsed_time/total_time gives percentage of interpolation between cur
2082 void interpolate_matrix(matrix *result, matrix *goal, matrix *start, float elapsed_time, float total_time)
2087 if ( !vm_matrix_cmp( goal, start ) ) {
2091 time0 = elapsed_time / total_time;
2092 time1 = (total_time - elapsed_time) / total_time;
2094 vm_vec_copy_scale(&fvec, &start->v.fvec, time1);
2095 vm_vec_scale_add2(&fvec, &goal->v.fvec, time0);
2097 vm_vec_copy_scale(&rvec, &start->v.rvec, time1);
2098 vm_vec_scale_add2(&rvec, &goal->v.rvec, time0);
2100 vm_vector_2_matrix(result, &fvec, NULL, &rvec);
2103 // calculate how far the camera should have moved
2104 float brief_camera_get_dist_moved(float elapsed_time)
2106 float time, dist_moved=0.0f;
2108 // first half of movement
2109 if ( elapsed_time < Total_move_time/2.0f ) {
2110 dist_moved=0.5f*Cam_accel*elapsed_time*elapsed_time; // d = 1/2at^2
2114 // second half of movement
2115 time=elapsed_time - Total_move_time/2.0f;
2116 dist_moved=(Total_dist/2.0f)+(Peak_speed*time) - 0.5f*Cam_accel*time*time;
2121 // ------------------------------------------------------------------------------------
2122 // Update the camera position
2123 void brief_camera_move(float frametime, int stage_num)
2130 Elapsed_time += frametime;
2132 if ( Cam_target_reached ) {
2133 // Current_cam_pos = Target_cam_pos;
2134 // Current_lookat_pos = Target_lookat_pos;
2135 // Current_cam_orient = Target_cam_orient;
2139 // Update orientation
2140 if ( (Elapsed_time < Total_move_time) ) {
2141 // interpolate_matrix(&Current_cam_orient, &Target_cam_orient, &Start_cam_orient, Elapsed_time, Total_move_time );
2142 vm_matrix_interpolate(&Target_cam_orient, &Current_cam_orient, &W_init, frametime, &result, &w_out, &Vel_limit, &Acc_limit);
2143 Current_cam_orient = result;
2148 // interpolate lookat position
2149 if ( vm_vec_cmp( &Current_lookat_pos, &Target_lookat_pos ) ) {
2150 vm_vec_copy_scale(&dist_moved, &Lookat_vel, Elapsed_time);
2151 vm_vec_add(&Current_lookat_pos, &Start_lookat_pos, &dist_moved);
2153 if ( camera_pos_past_target(&Start_lookat_pos, &Current_lookat_pos, &Target_lookat_pos) ) {
2154 Current_lookat_pos = Target_lookat_pos;
2158 cur_dist = Start_dist + Dist_change_rate * Elapsed_time;
2159 vm_vec_copy_scale(&dist_moved, &Current_cam_orient.v.fvec, -cur_dist);
2160 vm_vec_add(&Current_cam_pos, &Current_lookat_pos, &dist_moved);
2163 // use absolute pos to update position
2164 if ( vm_vec_cmp( &Current_cam_pos, &Target_cam_pos ) ) {
2165 dist = brief_camera_get_dist_moved(Elapsed_time);
2166 if ( dist < Last_dist ) {
2167 Cam_movement_done=1;
2172 if ( Cam_movement_done == 0 ) {
2173 vm_vec_copy_scale(&dist_moved, &Cam_vel, dist);
2174 vm_vec_add(&Current_cam_pos, &Start_cam_pos, &dist_moved);
2176 Current_cam_pos=Target_cam_pos;
2180 Cam_movement_done=1;
2181 Current_cam_pos=Target_cam_pos;
2184 if ( Cam_movement_done && (Elapsed_time >= Total_move_time) ) {
2185 Cam_target_reached=1;
2189 // Project the viewer's position onto the grid plane. If more than threshold distance
2190 // from grid center, move grid center.
2191 void brief_maybe_create_new_grid(grid* gridp, vector *pos, matrix *orient, int force)
2195 vector gpos, tmp, c;
2196 float dist_to_plane;
2197 float square_size, ux, uy, uz;
2199 ux = tplane.A = gridp->gmatrix.v.uvec.xyz.x;
2200 uy = tplane.B = gridp->gmatrix.v.uvec.xyz.y;
2201 uz = tplane.C = gridp->gmatrix.v.uvec.xyz.z;
2202 tplane.D = gridp->planeD;
2204 compute_point_on_plane(&c, &tplane, pos);
2205 dist_to_plane = fl_abs(vm_dist_to_plane(pos, &gridp->gmatrix.v.uvec, &c));
2208 while (dist_to_plane >= 25.0f)
2210 square_size *= 10.0f;
2211 dist_to_plane /= 10.0f;
2214 if (fvi_ray_plane(&gpos, &gridp->center, &gridp->gmatrix.v.uvec, pos, &orient->v.fvec, 0.0f)<0.0f) {
2216 vm_vec_scale_add(&p,pos,&orient->v.fvec, 100.0f );
2217 compute_point_on_plane(&gpos, &tplane, &p );
2220 if (vm_vec_dist(&gpos, &c) > 50.0f * square_size)
2222 vm_vec_sub(&tmp, &gpos, &c);
2223 vm_vec_normalize(&tmp);
2224 vm_vec_scale_add(&gpos, &c, &tmp, 50.0f * square_size);
2227 roundoff = (int) square_size * 10;
2229 gpos.xyz.x = fl_roundoff(gpos.xyz.x, roundoff);
2231 gpos.xyz.y = fl_roundoff(gpos.xyz.y, roundoff);
2233 gpos.xyz.z = fl_roundoff(gpos.xyz.z, roundoff);
2235 if ((square_size != gridp->square_size) ||
2236 (gpos.xyz.x != gridp->center.xyz.x) ||
2237 (gpos.xyz.y != gridp->center.xyz.y) ||
2238 (gpos.xyz.z != gridp->center.xyz.z) || force)
2240 gridp->square_size = square_size;
2241 gridp->center = gpos;
2242 brief_modify_grid(gridp);
2247 // *forward is vector pointing forward
2248 // *right is vector pointing right
2249 // *center is center point of grid
2250 // length is length of grid
2251 // width is width of grid
2252 // square_size is size of a grid square
2254 // *forward = (0.0, 0.0, 1.0)
2255 // *right = (1.0, 0.0, 0.0)
2256 // *center = (0.0, 0.0, 0.0)
2259 // square_size = 10.0
2260 // will generate a grid of squares 10 long by 5 wide.
2261 // Each grid square will be 10.0 x 10.0 units.
2262 // The center of the grid will be at the global origin.
2263 // The grid will be parallel to the xz plane (because the normal is 0,1,0).
2264 // (In fact, it will be the xz plane because it is centered on the origin.)
2266 // Stuffs grid in *gridp. If gridp == NULL, mallocs and returns a grid.
2267 grid *brief_create_grid(grid *gridp, vector *forward, vector *right, vector *center, int nrows, int ncols, float square_size)
2269 int i, ncols2, nrows2, d = 1;
2270 vector dfvec, drvec, cur, cur2, tvec, uvec, save, save2;
2272 Assert(square_size > 0.0);
2273 if (double_fine_gridlines)
2277 gridp = (grid *) malloc(sizeof(grid));
2281 gridp->center = *center;
2282 gridp->square_size = square_size;
2284 // Create the plane equation.
2285 Assert(!IS_VEC_NULL(forward));
2286 Assert(!IS_VEC_NULL(right));
2288 vm_vec_copy_normalize(&dfvec, forward);
2289 vm_vec_copy_normalize(&drvec, right);
2291 vm_vec_cross(&uvec, &dfvec, &drvec);
2293 Assert(!IS_VEC_NULL(&uvec));
2295 gridp->gmatrix.v.uvec = uvec;
2297 gridp->planeD = -(center->xyz.x * uvec.xyz.x + center->xyz.y * uvec.xyz.y + center->xyz.z * uvec.xyz.z);
2298 Assert(!_isnan(gridp->planeD));
2300 gridp->gmatrix.v.fvec = dfvec;
2301 gridp->gmatrix.v.rvec = drvec;
2303 vm_vec_scale(&dfvec, square_size);
2304 vm_vec_scale(&drvec, square_size);
2306 vm_vec_scale_add(&cur, center, &dfvec, (float) -nrows * d / 2);
2307 vm_vec_scale_add2(&cur, &drvec, (float) -ncols * d / 2);
2308 vm_vec_scale_add(&cur2, center, &dfvec, (float) -nrows * 5 / 2);
2309 vm_vec_scale_add2(&cur2, &drvec, (float) -ncols * 5 / 2);
2313 gridp->ncols = ncols;
2314 gridp->nrows = nrows;
2317 Assert(ncols < MAX_GRIDLINE_POINTS && nrows < MAX_GRIDLINE_POINTS);
2319 // Create the points along the edges of the grid, so we can just draw lines
2320 // between them to form the grid.
2321 for (i=0; i<=ncols*d; i++) {
2322 gridp->gpoints1[i] = cur; // small, dark gridline points
2323 vm_vec_scale_add(&tvec, &cur, &dfvec, (float) nrows * d);
2324 gridp->gpoints2[i] = tvec;
2325 vm_vec_add2(&cur, &drvec);
2328 for (i=0; i<=ncols2; i++) {
2329 gridp->gpoints5[i] = cur2; // large, brighter gridline points
2330 vm_vec_scale_add(&tvec, &cur2, &dfvec, (float) nrows2 * 10);
2331 gridp->gpoints6[i] = tvec;
2332 vm_vec_scale_add2(&cur2, &drvec, 10.0f);
2337 for (i=0; i<=nrows*d; i++) {
2338 gridp->gpoints3[i] = cur; // small, dark gridline points
2339 vm_vec_scale_add(&tvec, &cur, &drvec, (float) ncols * d);
2340 gridp->gpoints4[i] = tvec;
2341 vm_vec_add2(&cur, &dfvec);
2344 for (i=0; i<=nrows2; i++) {
2345 gridp->gpoints7[i] = cur2; // large, brighter gridline points
2346 vm_vec_scale_add(&tvec, &cur2, &drvec, (float) ncols2 * 10);
2347 gridp->gpoints8[i] = tvec;
2348 vm_vec_scale_add2(&cur2, &dfvec, 10.0f);
2354 // Create a nice grid -- centered at origin, 10x10, 10.0 size squares, in xz plane.
2355 grid *brief_create_default_grid(void)
2358 vector fvec, rvec, cvec;
2360 rgrid = brief_create_grid(&Global_grid, vm_vec_make(&fvec, 0.0f, 0.0f, 1.0f),
2361 vm_vec_make(&rvec, 1.0f, 0.0f, 0.0f),
2362 vm_vec_make(&cvec, 0.0f, -10.0f, 0.0f), 100, 100, 5.0f);
2364 physics_init(&rgrid->physics);
2365 rgrid->physics.flags |= (PF_ACCELERATES | PF_SLIDE_ENABLED);
2369 // Rotate and project points and draw a line.
2370 void brief_rpd_line(vector *v0, vector *v1)
2373 g3_rotate_vertex(&tv0, v0);
2374 g3_rotate_vertex(&tv1, v1);
2377 g3_project_vertex(&tv0);
2378 g3_project_vertex(&tv1);
2380 if ( (tv0.flags & PF_OVERFLOW) || (tv1.flags & PF_OVERFLOW) )
2384 gr_set_color_fast(&Color_grey);
2385 g3_draw_line(&tv0, &tv1);
2388 // Renders a grid defined in a grid struct
2389 void brief_render_grid(grid *gridp)
2391 int i, ncols, nrows;
2393 ncols = gridp->ncols;
2394 nrows = gridp->nrows;
2395 if (double_fine_gridlines)
2401 gr_set_color(30,30,30);
2404 // Draw the column lines.
2405 for (i=0; i<=ncols; i++)
2406 brief_rpd_line(&gridp->gpoints1[i], &gridp->gpoints2[i]);
2408 // Draw the row lines.
2409 for (i=0; i<=nrows; i++)
2410 brief_rpd_line(&gridp->gpoints3[i], &gridp->gpoints4[i]);
2412 ncols = gridp->ncols / 2;
2413 nrows = gridp->nrows / 2;
2415 // now draw the larger, brighter gridlines that is x10 the scale of smaller one.
2418 for (i=0; i<=ncols; i++)
2419 brief_rpd_line(&gridp->gpoints5[i], &gridp->gpoints6[i]);
2421 for (i=0; i<=nrows; i++)
2422 brief_rpd_line(&gridp->gpoints7[i], &gridp->gpoints8[i]);
2426 void brief_modify_grid(grid *gridp)
2428 brief_create_grid(gridp, &gridp->gmatrix.v.fvec, &gridp->gmatrix.v.rvec, &gridp->center,
2429 gridp->nrows, gridp->ncols, gridp->square_size);
2432 void brief_unload_anims()
2439 for (i=0; i<MAX_BRIEF_ICONS; i++) {
2441 for(idx=0; idx<MAX_SPECIES_NAMES; idx++){
2442 hud_anim_release(&Icon_highlight_anims[i][idx]);
2443 hud_anim_release(&Icon_fade_anims[i][idx]);
2446 // one set of icons in FS1
2447 hud_anim_release(&Icon_highlight_anims[i][1]);
2448 hud_anim_release(&Icon_fade_anims[i][1]);
2453 void brief_common_close()
2456 brief_unload_anims();
2460 void brief_restart_text_wipe()
2462 Brief_stage_time = 0;
2463 Brief_voice_ended = 0;
2464 Brief_voice_started = 0;
2465 Brief_text_wipe_time_elapsed = 0.0f;
2468 // initialize the array of handles to the different voice streams
2469 void brief_voice_init()
2472 for ( i = 0; i < MAX_BRIEF_STAGES; i++ ) {
2473 Brief_voices[i] = -1;
2477 void brief_load_voice_file(int voice_num, char *name)
2479 int load_attempts = 0;
2482 if ( load_attempts++ > 5 ) {
2486 Brief_voices[voice_num] = audiostream_open( name, ASF_VOICE );
2487 if ( Brief_voices[voice_num] >= 0 ) {
2491 // Don't bother to ask for the CD in multiplayer
2492 if ( Game_mode & GM_MULTIPLAYER ) {
2496 // couldn't load animation, ask user to insert CD (if necessary)
2497 // if ( Brief_voice_ask_for_cd ) {
2498 // if ( game_do_cd_check() == 0 ) {
2499 // Brief_voice_ask_for_cd = 0;
2506 // open and pre-load the stream buffers for the different voice streams
2507 void brief_voice_load_all()
2512 // Brief_voice_ask_for_cd = 1;
2514 Assert( Briefing != NULL );
2515 for ( i = 0; i < Briefing->num_stages; i++ ) {
2516 bs = &Briefing->stages[i];
2517 if ( strnicmp(bs->voice, NOX("none"), 4) ) {
2518 brief_load_voice_file(i, bs->voice);
2519 // Brief_voices[i] = audiostream_open( bs->voice, ASF_VOICE );
2524 // close all the briefing voice streams
2525 void brief_voice_unload_all()
2529 for ( i = 0; i < MAX_BRIEF_STAGES; i++ ) {
2530 if ( Brief_voices[i] != -1 ) {
2531 audiostream_close_file(Brief_voices[i], 0);
2532 Brief_voices[i] = -1;
2537 // start playback of the voice for a particular briefing stage
2538 void brief_voice_play(int stage_num)
2540 if ( Brief_voices[stage_num] == -1 )
2541 return; // voice file doesn't exist
2543 if ( !Briefing_voice_enabled ) {
2547 if ( audiostream_is_playing( Brief_voices[stage_num]) )
2550 audiostream_play(Brief_voices[stage_num], Master_voice_volume, 0);
2551 Brief_voice_started = 1;
2554 // stop playback of the voice for a particular briefing stage
2555 void brief_voice_stop(int stage_num)
2557 if ( Brief_voices[stage_num] == -1 )
2560 audiostream_stop(Brief_voices[stage_num]); // stream is automatically rewound
2563 // pause playback of the voice for a particular briefing stage, to resume just
2564 // call brief_voice_unpause() again
2565 void brief_voice_pause(int stage_num)
2567 if ( Brief_voices[stage_num] == -1 )
2570 audiostream_pause(Brief_voices[stage_num]);
2573 void brief_voice_unpause(int stage_num)
2575 if ( Brief_voices[stage_num] == -1 )
2578 audiostream_unpause(Brief_voices[stage_num]);
2581 void brief_reset_last_new_stage()
2583 Last_new_stage = -1;
2586 // get the dimensions for a briefing icon
2587 void brief_common_get_icon_dimensions(int *w, int *h, int type, int ship_class)
2589 Assert(type >= 0 && type < MAX_BRIEF_ICONS);
2591 // in case anything goes wrong
2595 int species = ship_get_species_by_type(ship_class);
2600 if ( Icon_bitmaps[type][species].first_frame >= 0 ) {
2601 bm_get_info( Icon_bitmaps[type][species].first_frame, w, h, NULL);
2608 void cmd_brief_reset()
2611 static int inited = 0;
2614 for (i=0; i<MAX_TEAMS; i++) {
2615 for (j=0; j<Cmd_briefs[i].num_stages; j++) {
2616 if (Cmd_briefs[i].stage[j].text)
2617 free(Cmd_briefs[i].stage[j].text);
2623 for (i=0; i<MAX_TEAMS; i++)
2624 Cmd_briefs[i].num_stages = 0;
2627 #define STAGE_ADVANCE_DELAY 1000 // time in ms to wait after voice stops before advancing stage
2629 // should briefing advance to the next stage?
2630 int brief_time_to_advance(int stage_num, float frametime)
2632 int voice_active, advance = 0;
2633 brief_icon *closeup_icon;
2635 closeup_icon = (brief_icon*)brief_get_closeup_icon();
2636 if ( closeup_icon ) {
2640 if ( !Player->auto_advance ) {
2644 Brief_stage_time += fl2i(frametime*1000 + 0.5f);
2646 if ( (Brief_voices[stage_num] >= 0) && Briefing_voice_enabled ) {
2652 if ( voice_active && (Brief_voice_ended == 0) && Brief_voice_started) {
2653 if ( !audiostream_is_playing( Brief_voices[stage_num]) ) {
2654 Brief_voice_ended = 1;
2655 Brief_stage_time = 0;
2659 if ( Brief_voice_ended ) {
2660 if ( Brief_stage_time > STAGE_ADVANCE_DELAY ) {
2665 if ( !voice_active && (Brief_textdraw_finished > 0) ) {
2666 if ( Brief_stage_time > max(5000, Num_brief_text_lines[0] * 3500) ) {