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/MissionUI/RedAlert.cpp $
15 * Module for Red Alert mission interface and code
18 * Revision 1.8 2005/03/29 02:18:47 taylor
19 * Various 64-bit platform fixes
20 * Fix compiler errors with MAKE_FS1 and fix gr_set_bitmap() too
21 * Make sure that turrets can fire at asteroids for FS1 (needed for a couple missions)
22 * Streaming audio support (big thanks to Pierre Willenbrock!!)
23 * Removed dependance on strings.tbl for FS1 since we don't actually need it now
25 * Revision 1.7 2004/09/20 01:31:44 theoddone33
28 * Revision 1.6 2003/08/03 16:10:29 taylor
29 * cleanup; compile warning fixes
31 * Revision 1.5 2003/05/25 02:30:43 taylor
34 * Revision 1.4 2002/06/09 04:41:23 relnev
35 * added copyright header
37 * Revision 1.3 2002/05/26 22:06:17 relnev
38 * makefile: disable stand_gui for now.
40 * rest: staticize some globals
42 * Revision 1.2 2002/05/03 13:34:33 theoddone33
45 * Revision 1.1.1.1 2002/05/03 03:28:10 root
49 * 16 9/11/99 12:31a Mikek
50 * Bumped up max red alert status ships and status subsystems.
52 * 15 9/06/99 6:38p Dave
53 * Improved CD detection code.
55 * 14 8/24/99 5:27p Andsager
56 * Make subsystems with zero strength before mission blown off. Protect
57 * red alert pilot against dying between orders and jump.
59 * 13 8/11/99 2:17p Jefff
62 * 12 7/19/99 8:56p Andsager
63 * Added Ship_exited red_alert_carry flag and hull strength for RED ALERT
64 * carry over of Exited_ships
66 * 11 7/19/99 2:13p Dave
67 * Added some new strings for Heiko.
69 * 10 7/16/99 12:22p Jefff
70 * Added sound FX to red alert popup
72 * 9 7/09/99 10:32p Dave
73 * Command brief and red alert screens.
75 * 8 5/07/99 10:34a Andsager
76 * Make red alert work in FS2
78 * 7 2/16/99 5:07p Neilk
81 * 6 1/30/99 5:08p Dave
82 * More new hi-res stuff.Support for nice D3D textures.
84 * 5 1/27/99 9:56a Dave
85 * Temporary checkin of beam weapons for Dan to make cool sounds.
87 * 4 11/18/98 11:15a Andsager
88 * Removed old version or red_alert_read_wingman_status
90 * 3 10/13/98 9:29a Dave
91 * Started neatening up freespace.h. Many variables renamed and
92 * reorganized. Added AlphaColors.[h,cpp]
94 * 2 10/07/98 10:53a Dave
97 * 1 10/07/98 10:50a Dave
99 * 21 5/14/98 11:26a Lawrance
100 * ESC will return to the main hall
102 * 20 5/13/98 5:14p Allender
103 * red alert support to go back to previous mission
105 * 19 5/05/98 6:19p Lawrance
106 * Fix problems with "retry mission" for red alerts
108 * 18 5/05/98 3:14p Comet
109 * AL: Fix bug with restoring secondary weapons in red alert mode
111 * 17 5/04/98 10:49p Lawrance
112 * Make sure old pilot files don't cause problems with the new RedAlert
115 * 16 5/04/98 6:06p Lawrance
116 * Make red alert mode work!
118 * 15 5/02/98 4:10p Lawrance
119 * Only use first stage of briefing for red alerts
121 * 14 5/01/98 9:18p Ed
122 * mark all goals and events as failed when red alert moves ahead to next
125 * 13 4/22/98 10:13a John
126 * added assert to trap a bug
128 * 12 4/21/98 12:08a Allender
129 * only make red alert move to next mission in campaign mode
131 * 11 4/03/98 10:31a John
132 * Made briefing and debriefing arrays be malloc'd
134 * 10 3/28/98 2:53p Allender
135 * added hud gauge when entering a red alert mission
137 * 9 3/12/98 10:28p Lawrance
138 * Deal with situation where wingman status may not have been properly
141 * 8 3/12/98 9:44p Allender
142 * go to debrief in red alert when not in campaign mode
144 * 6 3/09/98 9:55p Lawrance
145 * improve some comments
147 * 5 3/09/98 4:41p Lawrance
148 * Fix up some merge problems.
150 * 4 3/09/98 4:30p Allender
151 * multiplayer secondary weapon changes. red-alert and cargo-known-delay
152 * sexpressions. Add time cargo revealed to ship structure
154 * 3 3/09/98 4:23p Lawrance
155 * Replay mission, full save/restore of wingman status
157 * 2 3/09/98 12:13a Lawrance
158 * Add support for Red Alert missions
160 * 1 3/08/98 4:54p Lawrance
167 #include "gamesequence.h"
168 #include "missionscreencommon.h"
172 #include "redalert.h"
174 #include "missionbriefcommon.h"
176 #include "missioncampaign.h"
177 #include "missiongoals.h"
178 #include "linklist.h"
179 #include "hudwingmanstatus.h"
180 #include "audiostr.h"
181 #include "freespace.h"
182 #include "alphacolors.h"
184 /////////////////////////////////////////////////////////////////////////////
185 // Red Alert Mission-Level
186 /////////////////////////////////////////////////////////////////////////////
188 static int Red_alert_status;
189 static int Red_alert_new_mission_timestamp; // timestamp used to give user a little warning for red alerts
190 static int Red_alert_num_slots_used = 0;
191 static int Red_alert_voice_started;
193 #define RED_ALERT_WARN_TIME 4000 // time to warn user that new orders are coming
195 #define RED_ALERT_NONE 0
196 #define RED_ALERT_MISSION 1
198 #define MAX_RED_ALERT_SLOTS 32
199 #define MAX_RED_ALERT_SUBSYSTEMS 64
200 #define RED_ALERT_EXITED_SHIP_CLASS -1
202 typedef struct red_alert_ship_status
204 char name[NAME_LENGTH];
207 float subsys_current_hits[MAX_RED_ALERT_SUBSYSTEMS];
208 float subsys_aggregate_current_hits[SUBSYSTEM_MAX];
209 int wep[MAX_WL_WEAPONS];
210 int wep_count[MAX_WL_WEAPONS];
211 } red_alert_ship_status;
213 static red_alert_ship_status Red_alert_wingman_status[MAX_RED_ALERT_SLOTS];
214 static char Red_alert_precursor_mission[MAX_FILENAME_LEN];
216 /////////////////////////////////////////////////////////////////////////////
217 // Red Alert Interface
218 /////////////////////////////////////////////////////////////////////////////
220 const char *Red_alert_fname[GR_NUM_RESOLUTIONS] = {
225 const char *Red_alert_mask[GR_NUM_RESOLUTIONS] = {
230 // font to use for "incoming transmission"
231 int Ra_flash_font[GR_NUM_RESOLUTIONS] = {
236 int Ra_flash_y[GR_NUM_RESOLUTIONS] = {
242 static int Ra_flash_coords[GR_NUM_RESOLUTIONS][2] = {
252 #define NUM_BUTTONS 2
254 #define RA_REPLAY_MISSION 0
255 #define RA_CONTINUE 1
257 static ui_button_info Buttons[GR_NUM_RESOLUTIONS][NUM_BUTTONS] = {
260 ui_button_info("RAB_05", 0, 435, -1, -1, 5), // Replay
261 ui_button_info("RAB_04", 553, 411, -1, -1, 4), // Exit
263 ui_button_info("RAB_00", 2, 445, -1, -1, 0),
264 ui_button_info("RAB_01", 575, 432, -1, -1, 1),
268 ui_button_info("2_RAB_00", 4, 712, -1, -1, 0),
269 ui_button_info("2_RAB_01", 920, 691, -1, -1, 1),
274 #define RED_ALERT_NUM_TEXT 3
276 UI_XSTR Red_alert_text[GR_NUM_RESOLUTIONS][RED_ALERT_NUM_TEXT] = {
278 { "Replay", 1405, 46, 451, UI_XSTR_COLOR_PINK, -1, &Buttons[0][RA_REPLAY_MISSION].button },
279 { "Previous Mission", 1452, 46, 462, UI_XSTR_COLOR_PINK, -1, &Buttons[0][RA_REPLAY_MISSION].button },
280 { "Continue", 1069, 564, 413, UI_XSTR_COLOR_PINK, -1, &Buttons[0][RA_CONTINUE].button },
283 { "Replay", 1405, 75, 722, UI_XSTR_COLOR_PINK, -1, &Buttons[1][RA_REPLAY_MISSION].button },
284 { "Previous Mission", 1452, 75, 733, UI_XSTR_COLOR_PINK, -1, &Buttons[1][RA_REPLAY_MISSION].button },
285 { "Continue", 1069, 902, 661, UI_XSTR_COLOR_PINK, -1, &Buttons[1][RA_CONTINUE].button },
290 // indicies for coordinates
297 static int Text_delay;
299 int Ra_brief_text_wnd_coords[GR_NUM_RESOLUTIONS][4] = {
312 static UI_WINDOW Ui_window;
314 static hud_anim Flash_anim;
316 static int Background_bitmap;
317 static int Red_alert_inited = 0;
319 static int Red_alert_voice;
321 // open and pre-load the stream buffers for the different voice streams
322 void red_alert_voice_load()
324 Assert( Briefing != NULL );
325 if ( strnicmp(Briefing->stages[0].voice, NOX("none"), 4) && (strlen(Briefing->stages[0].voice) > 0) ) {
326 Red_alert_voice = audiostream_open( Briefing->stages[0].voice, ASF_VOICE );
330 // close all the briefing voice streams
331 void red_alert_voice_unload()
333 if ( Red_alert_voice != -1 ) {
334 audiostream_close_file(Red_alert_voice, 0);
335 Red_alert_voice = -1;
339 // start playback of the red alert voice
340 void red_alert_voice_play()
342 if ( Red_alert_voice == -1 ){
343 return; // voice file doesn't exist
346 if ( !Briefing_voice_enabled ) {
350 if ( audiostream_is_playing(Red_alert_voice) ){
354 audiostream_play(Red_alert_voice, Master_voice_volume, 0);
355 Red_alert_voice_started = 1;
358 // stop playback of the red alert voice
359 void red_alert_voice_stop()
361 if ( Red_alert_voice == -1 )
364 audiostream_stop(Red_alert_voice); // stream is automatically rewound
367 // a button was pressed, deal with it
368 void red_alert_button_pressed(int n)
372 gameseq_post_event(GS_EVENT_ENTER_GAME);
375 case RA_REPLAY_MISSION:
376 if ( Game_mode & GM_CAMPAIGN_MODE ) {
377 // TODO: make call to campaign code to set correct mission for loading
378 // mission_campaign_play_previous_mission(Red_alert_precursor_mission);
379 if ( !mission_campaign_previous_mission() ) {
380 gamesnd_play_iface(SND_GENERAL_FAIL);
384 gameseq_post_event(GS_EVENT_START_GAME);
386 gamesnd_play_iface(SND_GENERAL_FAIL);
392 // blit "incoming transmission"
393 #define RA_FLASH_CYCLE 0.25f
394 float Ra_flash_time = 0.0f;
396 void red_alert_blit_title()
398 const char *str = XSTR("Incoming Transmission", 1406);
401 // get the string size
402 gr_set_font(Ra_flash_font[gr_screen.res]);
403 gr_get_string_size(&w, &h, str);
408 gr_init_alphacolor(&flash_color, (int)(255.0f * (Ra_flash_time / RA_FLASH_CYCLE)), 0, 0, 255, AC_TYPE_HUD);
410 gr_init_alphacolor(&flash_color, (int)(255.0f * (1.0f - (Ra_flash_time / RA_FLASH_CYCLE))), 0, 0, 255, AC_TYPE_HUD);
415 gr_set_color_fast(&flash_color);
416 gr_string(Ra_brief_text_wnd_coords[gr_screen.res][0] + ((Ra_brief_text_wnd_coords[gr_screen.res][2] - w) / 2), Ra_flash_y[gr_screen.res] - h - 5, str);
417 gr_set_color_fast(&Color_normal);
420 // increment flash time
421 Ra_flash_time += flFrametime;
422 if(Ra_flash_time >= RA_FLASH_CYCLE){
423 Ra_flash_time = 0.0f;
424 Ra_flash_up = !Ra_flash_up;
427 // back to the original font
431 // Called once when red alert interface is started
432 void red_alert_init()
437 if ( Red_alert_inited ) {
442 common_set_interface_palette("ControlConfigPalette"); // set the interface palette
444 Ui_window.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);
445 Ui_window.set_mask_bmap(Red_alert_mask[gr_screen.res]);
447 for (i=0; i<NUM_BUTTONS; i++) {
448 b = &Buttons[gr_screen.res][i];
450 b->button.create(&Ui_window, "", b->x, b->y, 60, 30, 0, 1);
451 // set up callback for when a mouse first goes over a button
452 b->button.set_highlight_action(common_play_highlight_sound);
453 b->button.set_bmaps(b->filename);
454 b->button.link_hotspot(b->hotspot);
459 for(i=0; i<RED_ALERT_NUM_TEXT; i++){
460 Ui_window.add_XSTR(&Red_alert_text[gr_screen.res][i]);
464 // set up red alert hotkeys
465 Buttons[gr_screen.res][RA_CONTINUE].button.set_hotkey(KEY_CTRLED | SDLK_RETURN);
467 // load in background image and flashing red alert animation
468 Background_bitmap = bm_load(Red_alert_fname[gr_screen.res]);
471 hud_anim_init(&Flash_anim, Ra_flash_coords[gr_screen.res][RA_X_COORD], Ra_flash_coords[gr_screen.res][RA_Y_COORD], NOX("AlertFlash"));
472 hud_anim_load(&Flash_anim);
475 Red_alert_voice = -1;
478 Briefing = &Briefings[0];
481 if ( Briefing->num_stages > 0 ) {
482 Assert(Briefing->stages[0].new_text);
483 brief_color_text_init(Briefing->stages[0].new_text, Ra_brief_text_wnd_coords[gr_screen.res][RA_W_COORD], 0);
486 red_alert_voice_load();
488 Text_delay = timestamp(200);
490 Red_alert_voice_started = 0;
491 Red_alert_inited = 1;
494 // Called once when the red alert interface is exited
495 void red_alert_close()
497 if (Red_alert_inited) {
499 red_alert_voice_stop();
500 red_alert_voice_unload();
502 if (Background_bitmap >= 0) {
503 bm_unload(Background_bitmap);
508 hud_anim_release(&Flash_anim);
510 common_free_interface_palette(); // restore game palette
514 Red_alert_inited = 0;
517 // called once per frame when game state is GS_STATE_RED_ALERT
518 void red_alert_do_frame(float frametime)
522 // ensure that the red alert interface has been initialized
523 if (!Red_alert_inited) {
528 k = Ui_window.process() & ~KEY_DEBUGGED;
531 // gameseq_post_event(GS_EVENT_ENTER_GAME);
532 gameseq_post_event(GS_EVENT_MAIN_MENU);
536 for (i=0; i<NUM_BUTTONS; i++){
537 if (Buttons[gr_screen.res][i].button.pressed()){
538 red_alert_button_pressed(i);
542 GR_MAYBE_CLEAR_RES(Background_bitmap);
543 if (Background_bitmap >= 0) {
544 gr_set_bitmap(Background_bitmap, GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
550 hud_anim_render(&Flash_anim, frametime);
555 if ( timestamp_elapsed(Text_delay) ) {
556 int finished_wipe = 0;
557 if ( Briefing->num_stages > 0 ) {
558 finished_wipe = brief_render_text(0, Ra_brief_text_wnd_coords[gr_screen.res][RA_X_COORD], Ra_brief_text_wnd_coords[gr_screen.res][RA_Y_COORD], Ra_brief_text_wnd_coords[gr_screen.res][RA_H_COORD], frametime, 0);
562 red_alert_voice_play();
566 // blit incoming transmission
567 red_alert_blit_title();
572 // set the red alert status for the current mission
573 void red_alert_set_status(int status)
575 Red_alert_status = status;
576 Red_alert_new_mission_timestamp = timestamp(-1); // make invalid
579 // Store a ships weapons into a wingman status structure
580 void red_alert_store_weapons(red_alert_ship_status *ras, ship_weapon *swp)
588 for ( i = 0; i < MAX_WL_PRIMARY; i++ ) {
589 ras->wep[i] = swp->primary_bank_weapons[i];
590 if ( ras->wep[i] >= 0 ) {
591 ras->wep_count[i] = 1;
593 ras->wep_count[i] = -1;
597 for ( i = 0; i < MAX_WL_SECONDARY; i++ ) {
598 sidx = i+MAX_WL_PRIMARY;
599 ras->wep[sidx] = swp->secondary_bank_weapons[i];
600 if ( ras->wep[sidx] >= 0 ) {
601 ras->wep_count[sidx] = swp->secondary_bank_ammo[i];
603 ras->wep_count[sidx] = -1;
608 // Take the weapons stored in a wingman_status struct, and bash them into the ship weapons struct
609 void red_alert_bash_weapons(red_alert_ship_status *ras, ship_weapon *swp)
613 // restore from ship_exited
614 if (ras->ship_class == RED_ALERT_EXITED_SHIP_CLASS) {
619 for ( i = 0; i < MAX_WL_PRIMARY; i++ ) {
620 if ( (ras->wep_count[i] > 0) && (ras->wep[i] >= 0) ) {
621 swp->primary_bank_weapons[j] = ras->wep[i];
625 swp->num_primary_banks = j;
628 for ( i = 0; i < MAX_WL_SECONDARY; i++ ) {
629 sidx = i+MAX_WL_PRIMARY;
630 if ( ras->wep[sidx] >= 0 ) {
631 swp->secondary_bank_weapons[j] = ras->wep[sidx];
632 swp->secondary_bank_ammo[j] = ras->wep_count[sidx];
636 swp->num_secondary_banks = j;
639 void red_alert_bash_subsys_status(red_alert_ship_status *ras, ship *shipp)
644 // restore from ship_exited
645 if (ras->ship_class == RED_ALERT_EXITED_SHIP_CLASS) {
649 ss = GET_FIRST(&shipp->subsys_list);
650 while ( ss != END_OF_LIST( &shipp->subsys_list ) ) {
652 if ( count >= MAX_RED_ALERT_SUBSYSTEMS ) {
653 Int3(); // ran out of subsystems
657 ss->current_hits = ras->subsys_current_hits[count];
658 if (ss->current_hits <= 0) {
659 ss->submodel_info_1.blown_off = 1;
668 for ( i = 0; i < SUBSYSTEM_MAX; i++ ) {
669 shipp->subsys_info[i].current_hits = ras->subsys_aggregate_current_hits[i];
674 void red_alert_store_subsys_status(red_alert_ship_status *ras, ship *shipp)
683 ss = GET_FIRST(&shipp->subsys_list);
684 while ( ss != END_OF_LIST( &shipp->subsys_list ) ) {
686 if ( count >= MAX_RED_ALERT_SUBSYSTEMS ) {
687 Int3(); // ran out of subsystems
691 ras->subsys_current_hits[count] = ss->current_hits;
699 for ( i = 0; i < SUBSYSTEM_MAX; i++ ) {
700 ras->subsys_aggregate_current_hits[i] = shipp->subsys_info[i].current_hits;
705 // Record the current state of the players wingman
706 void red_alert_store_wingman_status()
709 red_alert_ship_status *ras;
713 Red_alert_num_slots_used = 0;
715 // store the mission filename for the red alert precursor mission
716 strcpy(Red_alert_precursor_mission, Game_current_mission_filename);;
718 // store status for all existing ships
719 for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
720 ship_objp = &Objects[so->objnum];
721 Assert(ship_objp->type == OBJ_SHIP);
722 shipp = &Ships[ship_objp->instance];
724 if ( shipp->flags & SF_DYING ) {
728 if ( Red_alert_num_slots_used >= MAX_RED_ALERT_SLOTS ) {
729 Int3(); // ran out of red alert slots
733 if ( !(shipp->flags & SF_FROM_PLAYER_WING) && !(shipp->flags & SF_RED_ALERT_STORE_STATUS) ) {
737 ras = &Red_alert_wingman_status[Red_alert_num_slots_used];
738 Red_alert_num_slots_used++;
740 strcpy(ras->name, shipp->ship_name);
741 ras->hull = Objects[shipp->objnum].hull_strength;
742 ras->ship_class = shipp->ship_info_index;
743 red_alert_store_weapons(ras, &shipp->weapons);
744 red_alert_store_subsys_status(ras, shipp);
747 // store exited ships that did not die
748 for (int idx=0; idx<MAX_EXITED_SHIPS; idx++) {
750 if ( Red_alert_num_slots_used >= MAX_RED_ALERT_SLOTS ) {
751 Int3(); // ran out of red alert slots
755 if (Ships_exited[idx].flags & SEF_RED_ALERT_CARRY) {
756 ras = &Red_alert_wingman_status[Red_alert_num_slots_used];
757 Red_alert_num_slots_used++;
759 strcpy(ras->name, Ships_exited[idx].ship_name);
760 ras->hull = float(Ships_exited[idx].hull_strength);
761 ras->ship_class = RED_ALERT_EXITED_SHIP_CLASS; //shipp->ship_info_index;
762 red_alert_store_weapons(ras, NULL);
763 red_alert_store_subsys_status(ras, NULL);
767 Assert(Red_alert_num_slots_used > 0);
770 // Delete a ship in a red alert mission (since it must have died/departed in the previous mission)
771 void red_alert_delete_ship(ship *shipp)
773 if ( (shipp->wing_status_wing_index >= 0) && (shipp->wing_status_wing_pos >= 0) ) {
774 hud_set_wingman_status_dead(shipp->wing_status_wing_index, shipp->wing_status_wing_pos);
777 ship_add_exited_ship( shipp, SEF_PLAYER_DELETED );
778 obj_delete(shipp->objnum);
779 if ( shipp->wingnum >= 0 ) {
780 ship_wing_cleanup( shipp-Ships, &Wings[shipp->wingnum] );
784 // Take the stored wingman status information, and adjust the player wing ships accordingly
785 void red_alert_bash_wingman_status()
789 red_alert_ship_status *ras;
793 if ( !(Game_mode & GM_CAMPAIGN_MODE) ) {
797 if ( Red_alert_num_slots_used <= 0 ) {
801 // go through all ships in the game, and see if there is red alert status data for any
803 int remove_list[MAX_RED_ALERT_SLOTS];
804 int remove_count = 0;
806 for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
807 ship_objp = &Objects[so->objnum];
808 Assert(ship_objp->type == OBJ_SHIP);
809 shipp = &Ships[ship_objp->instance];
811 if ( !(shipp->flags & SF_FROM_PLAYER_WING) && !(shipp->flags & SF_RED_ALERT_STORE_STATUS) ) {
817 for ( i = 0; i < Red_alert_num_slots_used; i++ ) {
818 ras = &Red_alert_wingman_status[i];
820 if ( !stricmp(ras->name, shipp->ship_name) ) {
822 if ( ras->ship_class == RED_ALERT_EXITED_SHIP_CLASS) {
823 // if exited ship, we can only restore hull strength
824 ship_objp->hull_strength = ras->hull;
826 // if necessary, restore correct ship class
827 if ( ras->ship_class != shipp->ship_info_index ) {
828 change_ship_type(SHIP_INDEX(shipp), ras->ship_class);
830 // restore hull and weapons
831 ship_objp->hull_strength = ras->hull;
832 red_alert_bash_weapons(ras, &shipp->weapons);
833 red_alert_bash_subsys_status(ras, shipp);
838 if ( !found_match ) {
839 remove_list[remove_count++] = SHIP_INDEX(shipp);
844 for ( i = 0; i < remove_count; i++ ) {
846 red_alert_delete_ship(&Ships[remove_list[i]]);
850 // write wingman status out to the specified file
851 void red_alert_write_wingman_status(CFILE *fp)
854 red_alert_ship_status *ras;
856 cfwrite_int(Red_alert_num_slots_used, fp);
858 if ( Red_alert_num_slots_used <= 0 ) {
862 Assert(strlen(Red_alert_precursor_mission) > 0 );
863 cfwrite_string(Red_alert_precursor_mission, fp);
865 for ( i = 0; i < Red_alert_num_slots_used; i++ ) {
866 ras = &Red_alert_wingman_status[i];
867 cfwrite_string(ras->name, fp);
868 cfwrite_float(ras->hull, fp);
869 cfwrite_int(ras->ship_class, fp);
871 for ( j = 0; j < MAX_RED_ALERT_SUBSYSTEMS; j++ ) {
872 cfwrite_float(ras->subsys_current_hits[j], fp);
875 for ( j = 0; j < SUBSYSTEM_MAX; j++ ) {
876 cfwrite_float(ras->subsys_aggregate_current_hits[j], fp);
879 for ( j = 0; j < MAX_WL_WEAPONS; j++ ) {
880 cfwrite_int( ras->wep[j], fp ) ;
881 cfwrite_int( ras->wep_count[j], fp );
886 // red wingman status out of the specified file
887 void red_alert_read_wingman_status(CFILE *fp, int version)
890 red_alert_ship_status *ras;
892 Red_alert_num_slots_used = cfread_int(fp);
894 if ( Red_alert_num_slots_used <= 0 ) {
898 cfread_string(Red_alert_precursor_mission, MAX_FILENAME_LEN, fp);
900 for ( i = 0; i < Red_alert_num_slots_used; i++ ) {
901 ras = &Red_alert_wingman_status[i];
902 cfread_string(ras->name, NAME_LENGTH, fp);
903 ras->hull = cfread_float(fp);
904 ras->ship_class = cfread_int(fp);
906 for ( j = 0; j < MAX_RED_ALERT_SUBSYSTEMS; j++ ) {
907 ras->subsys_current_hits[j] = cfread_float(fp);
910 for ( j = 0; j < SUBSYSTEM_MAX; j++ ) {
911 ras->subsys_aggregate_current_hits[j] = cfread_float(fp);
914 for ( j = 0; j < MAX_WL_WEAPONS; j++ ) {
915 ras->wep[j] = cfread_int(fp) ;
916 ras->wep_count[j] = cfread_int(fp);
921 // return !0 if this is a red alert mission, otherwise return 0
922 int red_alert_mission()
924 if ( Red_alert_status == RED_ALERT_MISSION ) {
931 // called from sexpression code to start a red alert mission
932 void red_alert_start_mission()
934 // if we are not in campaign mode, go to debriefing
935 // if ( !(Game_mode & GM_CAMPAIGN_MODE) ) {
936 // gameseq_post_event( GS_EVENT_DEBRIEF ); // proceed to debriefing
940 // check player health here.
941 // if we're dead (or about to die), don't start red alert mission.
942 if (Player_obj->type == OBJ_SHIP) {
943 if (Player_obj->hull_strength > 0) {
944 // make sure we don't die
945 Player_obj->flags |= OF_GUARDIAN;
947 // do normal red alert stuff
948 Red_alert_new_mission_timestamp = timestamp(RED_ALERT_WARN_TIME);
950 // throw down a sound here to make the warning seem ultra-important
951 // gamesnd_play_iface(SND_USER_SELECT);
952 snd_play(&(Snds[SND_DIRECTIVE_COMPLETE]));
957 // called from main game loop to check to see if we should move to a red alert mission
958 int red_alert_check_status()
960 // if the timestamp is invalid, do nothing.
961 if ( !timestamp_valid(Red_alert_new_mission_timestamp) )
964 // return if the timestamp hasn't elapsed yet
965 if ( timestamp_elapsed(Red_alert_new_mission_timestamp) ) {
967 // basic premise here is to stop the current mission, and then set the next mission in the campaign
968 // which better be a red alert mission
969 if ( Game_mode & GM_CAMPAIGN_MODE ) {
970 red_alert_store_wingman_status();
971 mission_goal_fail_incomplete();
972 mission_campaign_store_goals_and_events();
973 scoring_level_close();
974 mission_campaign_eval_next_mission();
975 mission_campaign_mission_over();
978 gameseq_post_event(GS_EVENT_START_GAME);
980 gameseq_post_event(GS_EVENT_END_GAME);