2 * $Logfile: /Freespace2/code/Mission/MissionTraining.cpp $
7 * Special code for training missions. Stuff like displaying training messages in
8 * the special training window, listing the training objectives, etc.
11 * Revision 1.2 2002/05/07 03:16:46 theoddone33
12 * The Great Newline Fix
14 * Revision 1.1.1.1 2002/05/03 03:28:10 root
18 * 10 8/27/99 2:20p Andsager
19 * Sort directives by born on date
21 * 9 8/22/99 7:57p Alanl
22 * fix bug that was scaling down mission training voice twice
24 * 8 8/02/99 7:29p Jefff
25 * moved instructor text in hi res
27 * 7 8/02/99 3:49p Jefff
28 * moved directives window down in 1024
30 * 6 7/10/99 1:44p Andsager
31 * Modified directives listing so that current and recently
32 * satisfied/failed directives stay on screen.
34 * 5 6/10/99 3:43p Dave
35 * Do a better job of syncing text colors to HUD gauges.
37 * 4 2/17/99 2:10p Dave
38 * First full run of squad war. All freespace and tracker side stuff
41 * 3 10/13/98 9:28a Dave
42 * Started neatening up freespace.h. Many variables renamed and
43 * reorganized. Added AlphaColors.[h,cpp]
45 * 2 10/07/98 10:53a Dave
48 * 1 10/07/98 10:49a Dave
50 * 58 8/25/98 1:48p Dave
51 * First rev of EMP effect. Player side stuff basically done. Next comes
54 * 57 6/13/98 5:19p Hoffoss
55 * externalized control config texts.
57 * 56 6/09/98 10:31a Hoffoss
58 * Created index numbers for all xstr() references. Any new xstr() stuff
59 * added from here on out should be added to the end if the list. The
60 * current list count can be found in FreeSpace.cpp (search for
63 * 55 6/01/98 11:43a John
64 * JAS & MK: Classified all strings for localization.
66 * 54 5/23/98 4:14p John
67 * Added code to preload textures to video card for AGP. Added in code
68 * to page in some bitmaps that weren't getting paged in at level start.
70 * 53 5/16/98 9:13p Allender
71 * don't display the directive display in multiplayer
73 * 52 5/07/98 11:59p Mike
74 * Don't show training popup for unbound key unless in training mission.
77 * 51 4/30/98 12:01a Lawrance
78 * using nprintf((Warning,...)) when audiostream can't be opened
80 * 50 4/27/98 11:20a Hoffoss
81 * Doubled TRAINING_MSG_QUE_MAX.
83 * 49 4/22/98 3:21p Hoffoss
84 * Fixed slight training message problems with training_failure state.
86 * 48 4/16/98 4:33p Hoffoss
87 * Added support for detecting instructor terminating training due to
88 * player shooting at him.
90 * 47 4/15/98 10:16p Mike
91 * Training mission #5.
92 * Fix application of subsystem damage.
94 * 46 4/15/98 5:25p Lawrance
95 * only show damage gauge when training msg not visible
97 * 45 4/03/98 2:52p Allender
98 * use Missiontime insteadof timestamp() for objective display
100 * 44 3/31/98 5:23p Hoffoss
101 * Fixed bug with training message token handling.
103 * 43 3/18/98 6:22p John
104 * Made directives display wiggle when afterburner is on
106 * 42 3/11/98 2:46p Hoffoss
107 * Shortened the width of the training message window so it doesn't
108 * overlap other hud objects.
110 * 41 2/23/98 8:31a John
111 * More string externalization
113 * 40 2/22/98 4:30p John
114 * More string externalization classification
116 * 39 2/04/98 4:32p Allender
117 * support for multiple briefings and debriefings. Changes to mission
118 * type (now a bitfield). Bitfield defs for multiplayer modes
120 * 38 1/30/98 4:24p Hoffoss
121 * Added a 3 second delay for directives before they get displayed.
123 * 37 1/26/98 6:27p Lawrance
124 * Change popups to use '&' meta-char for underlined hotkey.
126 * 36 1/22/98 11:46p Hoffoss
127 * Fixed linking problem with Fred.
129 * 35 1/22/98 11:00p Mike
130 * Fix Fred link error by commenting out line, email Hoffoss with info.
132 * 34 1/22/98 4:15p Hoffoss
133 * Added code to allow popup to tell player he needs to bind a key for the
136 * 33 1/20/98 2:26p Hoffoss
137 * Removed references to timestamp_ticker, used timestamp() instead.
139 * 32 1/19/98 9:37p Allender
140 * Great Compiler Warning Purge of Jan, 1998. Used pragma's in a couple
141 * of places since I was unsure of what to do with code.
143 * 31 1/15/98 6:00p Hoffoss
144 * Added option to quit menu (in game) to restart the mission. Doesn't
145 * seem to quite work, though. Checking code in so someone else can look
148 * 30 1/09/98 10:47a Lawrance
149 * Only clear auto-target, linking etc. when actually starting a training
152 * 29 1/08/98 4:07p Hoffoss
153 * Made objective key text appear in Green.
155 * 28 1/06/98 2:07p Lawrance
156 * strip leading whitespace on training msg lines
158 * 27 1/05/98 11:05p Lawrance
159 * Clear primary/secondary linking if playing a training mission.
161 * 26 1/05/98 10:03p Lawrance
162 * Fix HUD gauge flag that didn't get changed.
164 * 25 1/05/98 4:04p Hoffoss
165 * Changed training-msg sexp operator to allow it to control the length of
166 * time a message is displayed for.
168 * 24 1/05/98 11:16a Mike
169 * Clear auto-targeting and auto-speed-matching in a training mission.
171 * 23 1/02/98 9:10p Lawrance
172 * Big changes to how colors get set on the HUD.
174 * 22 12/22/97 6:07p Hoffoss
175 * Made directives flash when completed, fixed but with is-destroyed
178 * 21 12/19/97 12:43p Hoffoss
179 * Changed code to allow counts in directives.
181 * 20 12/18/97 11:53a Lawrance
182 * fix bug with displaying hud directives
184 * 19 12/16/97 9:13p Lawrance
185 * Integrate new gauges into HUD config.
187 * 18 12/15/97 5:26p Allender
188 * temporary code to display for 5 second completion status of objectives
190 * 17 11/20/97 1:10a Lawrance
191 * add support for voice volumes
193 * 16 11/17/97 6:38p Lawrance
194 * move directives window down
196 * 15 11/14/97 1:24p Lawrance
197 * draw 'directives' as the title
199 * 14 11/14/97 1:21p Lawrance
200 * split directives lines if they get too long
202 * 13 11/12/97 6:00p Hoffoss
203 * Added training messages to hud scrollback log.
205 * 12 11/11/97 10:27p Lawrance
206 * implement new HUD directives gauge
208 * 11 11/11/97 12:59a Lawrance
209 * move objective window up slightly
211 * 10 10/21/97 7:18p Hoffoss
212 * Overhauled the key/joystick control structure and usage throughout the
213 * entire FreeSpace code. The whole system is very different now.
215 * 9 10/21/97 3:35p Dan
216 * ALAN: if wave file doesn't exist, don't play it
218 * 8 10/17/97 6:39p Hoffoss
219 * Added delayability to key-pressed operator and training-msg operator.
221 * 7 10/17/97 10:23a Hoffoss
222 * Added more comments.
224 * 6 10/14/97 11:35p Lawrance
225 * change snd_load parameters
227 * 5 10/13/97 4:33p Hoffoss
228 * Made training messages go away after time.
230 * 4 10/13/97 3:24p Hoffoss
231 * Made it so training message text can be arbitrarily bolded.
233 * 3 10/10/97 6:15p Hoffoss
234 * Implemented a training objective list display.
236 * 2 10/09/97 4:44p Hoffoss
237 * Dimmed training window glass and made it less transparent, added flags
238 * to events, set he stage for detecting current events.
240 * 1 10/09/97 2:41p Hoffoss
249 #include "audiostr.h"
250 #include "missionmessage.h"
251 #include "missiongoals.h"
252 #include "missionparse.h"
254 #include "controlsconfig.h"
257 #include "hudtarget.h"
258 #include "freespace.h"
261 #include "hudconfig.h"
264 #include "gamesequence.h"
266 #include "alphacolors.h"
269 #define MAX_TRAINING_MSG_LINES 10
270 //#define TRAINING_MSG_WINDOW_X 174
271 //#define TRAINING_MSG_WINDOW_Y 40
272 #define TRAINING_MSG_WINDOW_WIDTH 266
273 #define TRAINING_LINE_WIDTH 250 // width in pixels of actual text
274 #define TRAINING_TIMING 150 // milliseconds per character to display messages
275 #define TRAINING_TIMING_BASE 1000 // Minimum milliseconds to display any message
276 //#define TRAINING_OBJ_WND_X 0 // offset of left edge of window
277 //#define TRAINING_OBJ_WND_Y 180 // offset of top edge of window
278 //#define TRAINING_OBJ_WND_Y 187 // offset of top edge of window
279 #define TRAINING_OBJ_WND_WIDTH 170 // number of pixels wide window is.
280 #define TRAINING_OBJ_LINE_WIDTH 150 // number of pixels wide text can be
281 #define TRAINING_OBJ_LINES 50 // number of lines to track in objective list
282 #define TRAINING_OBJ_DISPLAY_LINES 5 // only display this many lines on screen max
283 #define MAX_TRAINING_MSG_MODS 20
284 #define TRAINING_MSG_QUE_MAX 40
286 #define TRAINING_OBJ_STATUS_UNKNOWN (1 << 28) // directive status is unknown
287 #define TRAINING_OBJ_STATUS_KNOWN (1 << 29) // directive status is known (satisfied or failed)
288 #define TRAINING_OBJ_LINES_KEY (1 << 30) // flag indicating line describes the key associated with objective
289 #define TRAINING_OBJ_LINES_EVENT_STATUS_MASK (TRAINING_OBJ_STATUS_KNOWN | TRAINING_OBJ_STATUS_UNKNOWN)
291 #define TRAINING_OBJ_LINES_MASK(n) (Training_obj_lines[n] & 0xffff)
293 #define TMMOD_NORMAL 0
298 int mode; // what function to perform at given position (TMMOD_*)
299 } training_msg_mods; // training message modifiers
307 char Training_buf[8192], Training_text[8192];
308 char *Training_lines[MAX_TRAINING_MSG_LINES]; // Training message split into lines
309 char Training_voice_filename[NAME_LENGTH];
310 int Training_msg_timestamp;
311 int Training_line_sizes[MAX_TRAINING_MSG_LINES];
312 int Training_msg_method = 1;
313 int Training_num_lines = 0;
314 int Training_voice = -1;
315 int Training_voice_type;
316 int Training_voice_handle;
317 int Training_flag = 0;
318 int Training_failure = 0;
319 int Training_msg_que_count = 0;
320 int Training_bind_warning = -1; // Missiontime at which we last gave warning
321 int Training_msg_visible;
322 training_msg_que Training_msg_que[TRAINING_MSG_QUE_MAX];
324 // coordinates for training messages
325 int Training_msg_window_coords[GR_NUM_RESOLUTIONS][2] = {
330 // coordinates for "directives" window on hud
331 int Training_obj_window_coords[GR_NUM_RESOLUTIONS][2] = {
337 // training objectives global vars.
338 int Training_obj_num_lines;
339 int Training_obj_lines[TRAINING_OBJ_LINES];
340 training_msg_mods Training_msg_mods[MAX_TRAINING_MSG_MODS];
342 // local module prototypes
343 void training_process_msg(char *msg);
344 void message_translate_tokens(char *buf, char *text);
347 #define NUM_DIRECTIVE_GAUGES 3
348 static hud_frames Directive_gauge[NUM_DIRECTIVE_GAUGES];
349 static int Directive_frames_loaded = 0;
351 static char *Directive_fnames[3] =
360 #define DIRECTIVE_H 9
361 #define DIRECTIVE_X 5
362 #define NUM_DIRECTIVE_COORDS 3
363 #define DIRECTIVE_COORDS_TOP 0
364 #define DIRECTIVE_COORDS_MIDDLE 1
365 #define DIRECTIVE_COORDS_TITLE 2
366 static int Directive_coords[GR_NUM_RESOLUTIONS][NUM_DIRECTIVE_COORDS][2] =
382 // displays (renders) the training objectives list
383 void training_obj_display()
385 char buf[256], *second_line;
386 int i, t, x, y, z, height, end, offset, bx, by, y_count;
389 if (!Training_obj_num_lines){
393 if ( !hud_gauge_active(HUD_DIRECTIVES_VIEW) ) {
394 // Always draw the directives display if this is a training mission
395 if ( !(The_mission.game_type & MISSION_TYPE_TRAINING) ) {
400 // don't ever display directives display in multiplayer missions
401 // if ( Game_mode & GM_MULTIPLAYER ){
405 height = gr_get_font_height();
408 end = Training_obj_num_lines;
409 if (end > TRAINING_OBJ_DISPLAY_LINES) {
410 end = TRAINING_OBJ_DISPLAY_LINES;
411 offset = Training_obj_num_lines - end;
414 // draw top of objective display
415 // hud_set_default_color();
416 hud_set_gauge_color(HUD_DIRECTIVES_VIEW);
418 GR_AABITMAP(Directive_gauge[0].first_frame, Directive_coords[gr_screen.res][DIRECTIVE_COORDS_TOP][0]+fl2i(HUD_offset_x), Directive_coords[gr_screen.res][DIRECTIVE_COORDS_TOP][1]+fl2i(HUD_offset_y));
419 // gr_set_bitmap(Directive_gauge[0].first_frame);
420 // gr_aabitmap(Directive_coords[DIRECTIVE_COORDS_TOP][0]+fl2i(HUD_offset_x), Directive_coords[DIRECTIVE_COORDS_TOP][1]+fl2i(HUD_offset_y));
423 emp_hud_printf(Directive_coords[gr_screen.res][DIRECTIVE_COORDS_TITLE][0]+fl2i(HUD_offset_x), Directive_coords[gr_screen.res][DIRECTIVE_COORDS_TITLE][1]+fl2i(HUD_offset_y), EG_OBJ_TITLE, XSTR( "directives", 422));
424 // gr_printf(Directive_coords[DIRECTIVE_COORDS_TITLE][0]+fl2i(HUD_offset_x), Directive_coords[DIRECTIVE_COORDS_TITLE][1]+fl2i(HUD_offset_y), XSTR( "directives", 422));
426 bx = DIRECTIVE_X+fl2i(HUD_offset_x);
427 by = Directive_coords[gr_screen.res][DIRECTIVE_COORDS_MIDDLE][1]+fl2i(HUD_offset_y);
430 for (i=0; i<end; i++) {
431 x = DIRECTIVE_X + 3 + fl2i(HUD_offset_x);
432 y = Training_obj_window_coords[gr_screen.res][1] + fl2i(HUD_offset_y) + y_count * height + height / 2 + 1;
433 z = TRAINING_OBJ_LINES_MASK(i + offset);
436 if (Training_obj_lines[i + offset] & TRAINING_OBJ_LINES_KEY) {
437 message_translate_tokens(buf, Mission_events[z].objective_key_text); // remap keys
438 // gr_set_color_fast(&Color_normal);
439 c = &Color_bright_green;
441 strcpy(buf, Mission_events[z].objective_text);
442 if (Mission_events[z].count){
443 sprintf(buf + strlen(buf), NOX(" [%d]"), Mission_events[z].count);
446 // if this is a multiplayer tvt game, and this is event is not for my team, don't display it
447 if((Game_mode & GM_MULTIPLAYER) && (Netgame.type_flags & NG_TYPE_TEAM) && (Net_player != NULL)){
448 if((Mission_events[z].team != -1) && (Net_player->p_info.team != Mission_events[z].team)){
453 switch (mission_get_event_status(z)) {
455 // gr_set_color_fast(&Color_bright_white);
456 c = &Color_bright_white;
460 // gr_set_color_fast(&Color_bright_red);
461 c = &Color_bright_red;
464 case EVENT_SATISFIED:
465 // gr_set_color_fast(&Color_bright_blue);
466 t = Mission_events[z].satisfied_time;
467 if (t + i2f(2) > Missiontime) {
468 if (Missiontime % fl2f(.4f) < fl2f(.2f)){
469 c = &Color_bright_blue;
471 c = &Color_bright_white;
474 c = &Color_bright_blue;
480 // maybe split the directives line
481 second_line = split_str_once(buf, 167);
483 // blit the background frames
484 // hud_set_default_color();
485 hud_set_gauge_color(HUD_DIRECTIVES_VIEW);
487 GR_AABITMAP(Directive_gauge[1].first_frame, bx, by);
488 // gr_set_bitmap(Directive_gauge[1].first_frame);
489 // gr_aabitmap(bx, by);
494 GR_AABITMAP(Directive_gauge[1].first_frame, bx, by);
495 // gr_set_bitmap(Directive_gauge[1].first_frame);
496 // gr_aabitmap(bx, by);
502 gr_set_color_fast(c);
504 emp_hud_string(x, y, EG_OBJ1 + i, buf);
505 // gr_printf(x, y, buf);
510 y = Training_obj_window_coords[gr_screen.res][1] + fl2i(HUD_offset_y) + y_count * height + height / 2 + 1;
512 emp_hud_string(x+12, y, EG_OBJ1 + i + 1, second_line);
513 // gr_printf(x+12, y, second_line);
519 // draw the bottom of objective display
520 // hud_set_default_color();
521 hud_set_gauge_color(HUD_DIRECTIVES_VIEW);
523 GR_AABITMAP(Directive_gauge[2].first_frame, bx, by);
524 // gr_set_bitmap(Directive_gauge[2].first_frame);
525 // gr_aabitmap(bx, by);
528 // mission initializations (called once before a new mission is started)
529 void training_mission_init()
533 Assert(!Training_num_lines);
534 Training_obj_num_lines = 0;
535 Training_msg_que_count = 0;
536 Training_failure = 0;
537 for (i=0; i<TRAINING_OBJ_LINES; i++)
538 Training_obj_lines[i] = -1;
540 if ( !Directive_frames_loaded ) {
541 for ( i = 0; i < NUM_DIRECTIVE_GAUGES; i++ ) {
542 Directive_gauge[i].first_frame = bm_load_animation(Directive_fnames[i], &Directive_gauge[i].num_frames);
543 if ( Directive_gauge[i].first_frame < 0 ) {
544 Warning(LOCATION,"Cannot load hud ani: %s\n", Directive_fnames[i]);
548 Directive_frames_loaded = 1;
551 // only clear player flags if this is actually a training mission
552 if ( The_mission.game_type & MISSION_TYPE_TRAINING ) {
553 Player->flags &= ~(PLAYER_FLAGS_MATCH_TARGET | PLAYER_FLAGS_MSG_MODE | PLAYER_FLAGS_AUTO_TARGETING | PLAYER_FLAGS_AUTO_MATCH_SPEED | PLAYER_FLAGS_LINK_PRIMARY | PLAYER_FLAGS_LINK_SECONDARY );
557 void training_mission_page_in()
560 for ( i = 0; i < NUM_DIRECTIVE_GAUGES; i++ ) {
561 bm_page_in_aabitmap( Directive_gauge[i].first_frame, Directive_gauge[i].num_frames );
566 int comp_training_lines_by_born_on_date(const void *m1, const void *m2)
572 Assert(Mission_events[*e1 & 0xffff].born_on_date != 0);
573 Assert(Mission_events[*e2 & 0xffff].born_on_date != 0);
575 return (Mission_events[*e1 & 0xffff].born_on_date - Mission_events[*e2 & 0xffff].born_on_date);
579 // now sort list of events
580 // sort on EVENT_CURRENT and born on date, for other events (EVENT_SATISFIED, EVENT_FAILED) sort on born on date
581 #define MIN_SATISFIED_TIME 5
582 #define MIN_FAILED_TIME 7
583 void sort_training_objectives()
585 int i, event_status, offset;
587 // start by sorting on born on date
588 qsort(Training_obj_lines, Training_obj_num_lines, sizeof(int), comp_training_lines_by_born_on_date);
590 // get the index of the first directive that will be displayed
591 // if less than 0, display all lines
592 offset = Training_obj_num_lines - TRAINING_OBJ_DISPLAY_LINES;
598 // go through lines 0 to offset-1 and check if there are any CURRENT or RECENTLY_KNOWN events that should be shown
599 int num_offset_events = 0;
600 for (i=0; i<offset; i++) {
601 event_status = mission_get_event_status(TRAINING_OBJ_LINES_MASK(i));
603 if (event_status == EVENT_CURRENT) {
604 Training_obj_lines[i] |= TRAINING_OBJ_STATUS_UNKNOWN;
606 } else if (event_status == EVENT_SATISFIED) {
607 if (f2i(Missiontime - Mission_events[TRAINING_OBJ_LINES_MASK(i)].satisfied_time) < MIN_SATISFIED_TIME) {
608 Training_obj_lines[i] |= TRAINING_OBJ_STATUS_UNKNOWN;
611 Training_obj_lines[i] |= TRAINING_OBJ_STATUS_KNOWN;
613 } else if (event_status == EVENT_FAILED) {
614 if (f2i(Missiontime - Mission_events[TRAINING_OBJ_LINES_MASK(i)].satisfied_time) < MIN_FAILED_TIME) {
615 Training_obj_lines[i] |= TRAINING_OBJ_STATUS_UNKNOWN;
618 Training_obj_lines[i] |= TRAINING_OBJ_STATUS_KNOWN;
623 // if there are no directives which should be moved, we're done
624 if (num_offset_events == 0) {
628 // go through lines offset to Training_obj_num_lines to check which should be shown, since some will need to be bumped
629 for (i=offset; i<Training_obj_num_lines; i++) {
630 event_status = mission_get_event_status(TRAINING_OBJ_LINES_MASK(i));
632 if (event_status == EVENT_CURRENT) {
633 Training_obj_lines[i] |= TRAINING_OBJ_STATUS_UNKNOWN;
634 } else if (event_status == EVENT_SATISFIED) {
635 if (f2i(Missiontime - Mission_events[TRAINING_OBJ_LINES_MASK(i)].satisfied_time) < MIN_SATISFIED_TIME) {
636 Training_obj_lines[i] |= TRAINING_OBJ_STATUS_UNKNOWN;
638 Training_obj_lines[i] |= TRAINING_OBJ_STATUS_KNOWN;
640 } else if (event_status == EVENT_FAILED) {
641 if (f2i(Missiontime - Mission_events[TRAINING_OBJ_LINES_MASK(i)].satisfied_time) < MIN_FAILED_TIME) {
642 Training_obj_lines[i] |= TRAINING_OBJ_STATUS_UNKNOWN;
644 Training_obj_lines[i] |= TRAINING_OBJ_STATUS_UNKNOWN;
650 int slot_idx, unkn_vis;
651 // go through list and bump as needed
652 for (i=0; i<num_offset_events; i++) {
654 // find most recent directive that would not be shown
655 for (unkn_vis=offset-1; unkn_vis>=0; unkn_vis--) {
656 if (Training_obj_lines[unkn_vis] & TRAINING_OBJ_STATUS_UNKNOWN) {
661 // find first slot that can be bumped
662 // look at the last (N-4 to N) positions
663 for (slot_idx=0; slot_idx<TRAINING_OBJ_DISPLAY_LINES; slot_idx++) {
664 if ( Training_obj_lines[i+offset] & TRAINING_OBJ_STATUS_KNOWN ) {
669 // shift and replace (mark old one as STATUS_KNOWN)
670 for (int j=slot_idx; j>0; j--) {
671 Training_obj_lines[j+offset-1] = Training_obj_lines[j+offset-2];
673 Training_obj_lines[offset] = Training_obj_lines[unkn_vis];
674 Training_obj_lines[unkn_vis] &= ~TRAINING_OBJ_LINES_EVENT_STATUS_MASK;
675 Training_obj_lines[unkn_vis] |= TRAINING_OBJ_STATUS_KNOWN;
678 // remove event status
679 for (i=0; i<Training_obj_num_lines; i++) {
680 Training_obj_lines[i] &= ~TRAINING_OBJ_LINES_EVENT_STATUS_MASK;
684 // called at same rate as goals/events are evaluated. Maintains the objectives listing, adding,
685 // removing and updating items
686 void training_check_objectives()
688 int i, event_idx, event_status;
690 Training_obj_num_lines = 0;
691 for (event_idx=0; event_idx<Num_mission_events; event_idx++) {
692 event_status = mission_get_event_status(event_idx);
693 if ( (event_status != EVENT_UNBORN) && Mission_events[event_idx].objective_text && (timestamp() > Mission_events[event_idx].born_on_date + 3000) ) {
694 if (!Training_failure || !strnicmp(Mission_events[event_idx].name, XSTR( "Training failed", 423), 15)) {
696 // check for the actual objective
697 for (i=0; i<Training_obj_num_lines; i++) {
698 if (Training_obj_lines[i] == event_idx) {
703 // not in objective list, need to add it
704 if (i == Training_obj_num_lines) {
705 if (Training_obj_num_lines == TRAINING_OBJ_LINES) {
707 // objective list full, remove topmost objective
708 for (i=1; i<TRAINING_OBJ_LINES; i++) {
709 Training_obj_lines[i - 1] = Training_obj_lines[i];
711 Training_obj_num_lines--;
713 // add the new directive
714 Training_obj_lines[Training_obj_num_lines++] = event_idx;
717 // now check for the associated keypress text
718 for (i=0; i<Training_obj_num_lines; i++) {
719 if (Training_obj_lines[i] == (event_idx | TRAINING_OBJ_LINES_KEY)) {
724 // if there is a keypress message with directive, process that too.
725 if (Mission_events[event_idx].objective_key_text) {
726 if (event_status == EVENT_CURRENT) {
728 // not in objective list, need to add it
729 if (i == Training_obj_num_lines) {
730 if (Training_obj_num_lines == TRAINING_OBJ_LINES) {
732 // objective list full, remove topmost objective
733 for (i=1; i<Training_obj_num_lines; i++) {
734 Training_obj_lines[i - 1] = Training_obj_lines[i];
736 Training_obj_num_lines--;
738 // mark objective as having key text
739 Training_obj_lines[Training_obj_num_lines++] = event_idx | TRAINING_OBJ_LINES_KEY;
743 // message with key press text is no longer valid, so remove it
744 if (i < Training_obj_num_lines) {
745 for (; i<Training_obj_num_lines - 1; i++) {
746 Training_obj_lines[i] = Training_obj_lines[i + 1];
748 Training_obj_num_lines--;
756 // now sort list of events
757 // sort on EVENT_CURRENT and born on date, for other events (EVENT_SATISFIED, EVENT_FAILED) sort on born on date
758 sort_training_objectives();
761 // called to do cleanup when leaving a mission
762 void training_mission_shutdown()
764 if (Training_voice >= 0) {
765 if (Training_voice_type) {
766 audiostream_close_file(Training_voice_handle, 0);
769 snd_stop(Training_voice_handle);
774 Training_num_lines = Training_obj_num_lines = 0;
778 // translates special tokens. Handles one token only.
779 char *translate_msg_token(char *str)
781 if (!stricmp(str, NOX("wp"))) {
782 sprintf(str, "%d", Training_context_goal_waypoint + 1);
789 // translates all special tokens in a message, producing the new finalized message to be displayed
790 void message_translate_tokens(char *buf, char *text)
792 char temp[40], *toke1, *toke2, *ptr, *orig_buf;
797 toke1 = strchr(text, '$');
798 toke2 = strchr(text, '#');
799 while (toke1 || toke2) { // is either token types present?
800 if (!toke2 || (toke1 && (toke1 < toke2))) { // found $ before #
801 strncpy(buf, text, toke1 - text + 1); // copy text up to token
802 buf += toke1 - text + 1;
803 text = toke1 + 1; // advance pointers past processed data
805 toke2 = strchr(text, '$');
806 if (!toke2) // No second one?
809 strncpy(temp, text, toke2 - text); // isolate token into seperate buffer
810 temp[toke2 - text] = 0; // null terminate string
811 ptr = translate_key(temp); // try and translate key
812 if (ptr) { // was key translated properly?
813 if (!stricmp(ptr, NOX("none")) && (Training_bind_warning != Missiontime)) {
814 if ( The_mission.game_type & MISSION_TYPE_TRAINING ) {
815 r = popup(PF_TITLE_BIG | PF_TITLE_RED, 2, XSTR( "&Bind Control", 424), XSTR( "&Abort mission", 425),
816 XSTR( "Warning\nYou have no control bound to the action \"%s\". You must do so before you can continue with your training.", 426),
817 XSTR(Control_config[Failed_key_index].text, CONTROL_CONFIG_XSTR + Failed_key_index));
819 if (r) { // do they want to abort the mission?
820 gameseq_post_event(GS_EVENT_END_GAME);
824 gameseq_post_event(GS_EVENT_CONTROL_CONFIG); // goto control config screen to bind the control
828 buf--; // erase the $
829 strcpy(buf, ptr); // put translated key in place of token
835 strncpy(buf, text, toke2 - text + 1); // copy text up to token
836 buf += toke2 - text + 1;
837 text = toke2 + 1; // advance pointers past processed data
839 toke1 = strchr(text, '#');
840 if (toke1) // No second one?
843 strncpy(temp, text, toke1 - text); // isolate token into seperate buffer
844 temp[toke1 - text] = 0; // null terminate string
845 ptr = translate_msg_token(temp); // try and translate key
846 if (ptr) { // was key translated properly?
847 buf--; // erase the #
848 strcpy(buf, ptr); // put translated key in place of token
854 toke1 = strchr(text, '$');
855 toke2 = strchr(text, '#');
862 // plays the voice file associated with a training message. Automatically streams the file
863 // from disk if it's over 100k, otherwise plays it as a normal file in memory. Returns -1
864 // if it didn't play, otherwise index of voice
865 int message_play_training_voice(int index)
871 if (Training_voice >= 0) {
872 if (Training_voice_type) {
873 audiostream_close_file(Training_voice_handle, 0);
876 snd_stop(Training_voice_handle);
884 if (Message_waves[index].num < 0) {
885 fp = cfopen(Message_waves[index].name, "rb");
889 len = cfilelength(fp);
892 if ((Training_voice < 0) || !Training_voice_type || (Training_voice != index)) {
893 if (Training_voice >= 0) {
894 if (Training_voice_type) {
895 if (Training_voice == index)
896 audiostream_stop(Training_voice_handle);
898 audiostream_close_file(Training_voice_handle, 0);
901 snd_stop(Training_voice_handle);
905 if (stricmp(Message_waves[index].name, NOX("none.wav"))) {
906 Training_voice_handle = audiostream_open(Message_waves[index].name, ASF_VOICE);
907 if (Training_voice_handle < 0) {
908 nprintf(("Warning", "Unable to load voice file %s\n", Message_waves[index].name));
909 // Warning(LOCATION, "Unable to load voice file %s\n", Message_waves[index].name);
912 } // Training_voice should be valid and loaded now
914 Training_voice_type = 1;
915 if (Training_voice_handle >= 0)
916 audiostream_play(Training_voice_handle, Master_voice_volume, 0);
918 Training_voice = index;
919 return Training_voice;
923 memset(&tmp_gs, 0, sizeof(game_snd));
924 strcpy(tmp_gs.filename, Message_waves[index].name);
925 Message_waves[index].num = snd_load(&tmp_gs);
926 if (Message_waves[index].num < 0) {
927 nprintf(("Warning", "Cannot load message wave: %s. Will not play\n", Message_waves[index].name));
933 if (Training_voice >= 0) {
934 if (Training_voice_type) {
935 audiostream_close_file(Training_voice_handle, 0);
938 snd_stop(Training_voice_handle);
942 Training_voice = index;
943 if (Message_waves[index].num >= 0)
944 Training_voice_handle = snd_play_raw(Message_waves[index].num, 0.0f);
946 Training_voice_handle = -1;
948 Training_voice_type = 0;
949 return Training_voice;
952 // one time initializations done when we want to display a new training mission. This does
953 // all the processing and setup required to actually display it, including starting the
954 // voice file playing
955 void message_training_setup(int m, int length)
957 if ((m < 0) || !Messages[m].message[0]) { // remove current message from the screen
958 Training_num_lines = 0;
962 message_translate_tokens(Training_buf, Messages[m].message);
963 HUD_add_to_scrollback(Training_buf, HUD_SOURCE_TRAINING);
964 strcpy(Training_text, Messages[m].message);
966 if (message_play_training_voice(Messages[m].wave_info.index) < 0) {
968 Training_msg_timestamp = timestamp(length * 1000);
970 Training_msg_timestamp = timestamp(TRAINING_TIMING_BASE + strlen(Messages[m].message) * TRAINING_TIMING); // no voice file playing
973 Training_msg_timestamp = 0;
976 // adds simple text to the directives display
977 /*id message_training_add_simple( char *text )
981 training_process_msg(text);
982 HUD_add_to_scrollback(Training_buf, HUD_SOURCE_TRAINING);
983 Training_num_lines = split_str(Training_buf, TRAINING_LINE_WIDTH, Training_line_sizes, Training_lines, MAX_TRAINING_MSG_LINES);
984 Assert(Training_num_lines > 0);
985 for (i=0; i<Training_num_lines; i++)
986 Training_lines[i][Training_line_sizes[i]] = 0;
988 Training_msg_timestamp = timestamp(5000);
991 // add a message to the que to be sent later.
992 void message_training_que(char *text, int timestamp, int length)
996 Assert(Training_msg_que_count < TRAINING_MSG_QUE_MAX);
997 if (Training_msg_que_count < TRAINING_MSG_QUE_MAX) {
998 if (!stricmp(text, NOX("none")))
1002 for (m=0; m<Num_messages; m++)
1003 if (!stricmp(text, Messages[m].name))
1006 Assert(m < Num_messages);
1007 if (m >= Num_messages)
1011 Training_msg_que[Training_msg_que_count].num = m;
1012 Training_msg_que[Training_msg_que_count].timestamp = timestamp;
1013 Training_msg_que[Training_msg_que_count].length = length;
1014 Training_msg_que_count++;
1018 // check the training message que to see if we should play a new message yet or not.
1019 void message_training_que_check()
1021 int i, j, iship_num;
1023 // get the instructor's ship.
1024 iship_num = ship_name_lookup(NOX("instructor"));
1025 if ( iship_num == -1 )
1028 // if the instructor is dying or departing, do nothing
1029 if (Ships[iship_num].flags & (SF_DYING | SF_DEPARTING))
1032 if (Training_failure)
1035 for (i=0; i<Training_msg_que_count; i++) {
1036 if (timestamp_elapsed(Training_msg_que[i].timestamp)) {
1037 message_training_setup(Training_msg_que[i].num, Training_msg_que[i].length);
1038 // remove this message from the que now.
1039 for (j=i+1; j<Training_msg_que_count; j++)
1040 Training_msg_que[j - 1] = Training_msg_que[j];
1043 Training_msg_que_count--;
1048 // displays (renders) the training message to the screen
1049 void message_training_display()
1051 char *str, buf[256];
1052 int i, z, x, y, height, mode, count;
1054 Training_msg_visible = 0;
1055 message_training_que_check();
1056 training_obj_display();
1058 if (Training_failure){
1062 if (timestamp_elapsed(Training_msg_timestamp) || !strlen(Training_text)){
1066 message_translate_tokens(Training_buf, Training_text);
1067 training_process_msg(Training_text);
1068 Training_num_lines = split_str(Training_buf, TRAINING_LINE_WIDTH, Training_line_sizes, Training_lines, MAX_TRAINING_MSG_LINES);
1069 Assert(Training_num_lines > 0);
1070 for (i=0; i<Training_num_lines; i++) {
1071 Training_lines[i][Training_line_sizes[i]] = 0;
1072 drop_leading_white_space(Training_lines[i]);
1075 if (Training_num_lines <= 0){
1079 height = gr_get_font_height();
1080 gr_set_shader(&Training_msg_glass);
1081 gr_shade(Training_msg_window_coords[gr_screen.res][0], Training_msg_window_coords[gr_screen.res][1], TRAINING_MSG_WINDOW_WIDTH, Training_num_lines * height + height);
1083 gr_set_color_fast(&Color_bright_blue);
1085 Training_msg_visible = 1;
1086 for (i=0; i<Training_num_lines; i++) { // loop through all lines of message
1087 str = Training_lines[i];
1089 x = Training_msg_window_coords[gr_screen.res][0] + (TRAINING_MSG_WINDOW_WIDTH - TRAINING_LINE_WIDTH) / 2;
1090 y = Training_msg_window_coords[gr_screen.res][1] + i * height + height / 2 + 1;
1092 while (*str) { // loop through each character of each line
1093 if ((count < MAX_TRAINING_MSG_MODS) && (str == Training_msg_mods[count].pos)) {
1095 gr_printf(x, y, buf);
1096 gr_get_string_size(&z, NULL, buf);
1100 mode = Training_msg_mods[count++].mode;
1103 gr_set_color_fast(&Color_bright_blue);
1107 gr_set_color_fast(&Color_white);
1117 gr_printf(x, y, "%s", buf);
1121 Training_msg_method = 0;
1122 // if (Training_msg_method) {
1123 // char *msg = "Press a key to continue";
1125 // gr_get_string_size(&i, NULL, msg);
1126 // gr_printf(TRAINING_MSG_WINDOW_X + TRAINING_MSG_WINDOW_WIDTH / 2 - i / 2, TRAINING_MSG_WINDOW_Y + (Training_num_lines + 2) * height, msg);
1129 if ((Training_voice >= 0) && (Training_num_lines > 0) && !(Training_msg_timestamp)) {
1130 if (Training_voice_type)
1131 z = audiostream_is_playing(Training_voice_handle);
1133 z = snd_is_playing(Training_voice_handle);
1136 Training_msg_timestamp = timestamp(2000); // 2 second delay
1140 // processes a new training message to get hilighting information and store it in internal structures.
1141 void training_process_msg(char *msg)
1144 char *src, *dest, buf[8192];
1146 message_translate_tokens(buf, msg);
1149 dest = Training_buf;
1151 if (!strnicmp(src, NOX("<b>"), 3)) {
1152 Assert(count < MAX_TRAINING_MSG_MODS);
1154 Training_msg_mods[count].pos = dest;
1155 Training_msg_mods[count].mode = TMMOD_BOLD;
1159 if (!strnicmp(src, NOX("</b>"), 4)) {
1160 Assert(count < MAX_TRAINING_MSG_MODS);
1162 Training_msg_mods[count].pos = dest;
1163 Training_msg_mods[count].mode = TMMOD_NORMAL;
1171 if (count < MAX_TRAINING_MSG_MODS)
1172 Training_msg_mods[count].pos = NULL;
1175 void training_fail()
1177 Training_failure = 1;
1178 // JasonH: Add code here to suspend training and display a directive to warp out.
1179 // Suspend training.
1180 // Give directive to warp out.
1181 // Also ensure that a special failure debriefing is given. Must mention firing at instructor.
1182 // Ask Sandeep to write it (or you can).