]> icculus.org git repositories - taylor/freespace2.git/blob - src/missionui/missionloopbrief.cpp
a few NDEBUG updates.
[taylor/freespace2.git] / src / missionui / missionloopbrief.cpp
1 /*
2  * $Logfile: /Freespace2/code/MissionUI/MissionLoopBrief.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Campaign Loop briefing screen
8  *
9  * $Log$
10  * Revision 1.2  2002/05/07 03:16:46  theoddone33
11  * The Great Newline Fix
12  *
13  * Revision 1.1.1.1  2002/05/03 03:28:10  root
14  * Initial import.
15  *
16  * 
17  * 4     9/06/99 9:44p Jefff
18  * break out of loop support
19  * 
20  * 3     9/06/99 6:38p Dave
21  * Improved CD detection code.
22  * 
23  * 2     8/27/99 12:04a Dave
24  * Campaign loop screen.
25  *  
26  *
27  * $NoKeywords: $
28  */
29
30 #include "missionloopbrief.h"
31 #include "missionscreencommon.h"
32 #include "2d.h"
33 #include "bmpman.h"
34 #include "gamesnd.h"
35 #include "eventmusic.h"
36 #include "audiostr.h"
37 #include "key.h"
38 #include "gamesequence.h"
39 #include "missioncampaign.h"
40 #include "animplay.h"
41 #include "freespace.h"
42
43 // ---------------------------------------------------------------------------------------------------------------------------------------
44 // MISSION LOOP BRIEF DEFINES/VARS
45 //
46
47 char *Loop_brief_fname[GR_NUM_RESOLUTIONS] = {
48         "LoopBrief",            // GR_640
49         "2_LoopBrief",          // GR_1024
50 };
51
52 char *Loop_brief_mask[GR_NUM_RESOLUTIONS] = {
53         "LoopBrief-m",          // GR_640
54         "2_Loopbrief-m",        // GR_1024
55 };
56
57 #define NUM_LOOP_BRIEF_BUTTONS                          2
58 #define LOOP_BRIEF_DECLINE                                              0
59 #define LOOP_BRIEF_ACCEPT                                               1
60 ui_button_info Loop_buttons[GR_NUM_RESOLUTIONS][NUM_LOOP_BRIEF_BUTTONS] = {
61         { // GR_640
62                 ui_button_info("LBB_00",                529,    437,    -1,     -1,     0),
63                 ui_button_info("LBB_01",                575,    433,    -1,     -1,     1),
64         },
65         { // GR_1024
66                 ui_button_info("2_LBB_00",              846,    699,    -1,     -1,     0),
67                 ui_button_info("2_LBB_01",              920,    693,    -1,     -1,     1),
68         }
69 };
70
71 #define NUM_LOOP_TEXT                                                   2
72 UI_XSTR Loop_text[GR_NUM_RESOLUTIONS][NUM_LOOP_TEXT] = {
73         { // GR_640
74                 { "Decline",            1467,   514,    413,    UI_XSTR_COLOR_PINK,     -1,     &Loop_buttons[0][LOOP_BRIEF_DECLINE].button },
75                 { "Accept",                     1035,   573,    413,    UI_XSTR_COLOR_PINK,     -1,     &Loop_buttons[0][LOOP_BRIEF_ACCEPT].button },
76         },      
77         { // GR_1024
78                 { "Decline",            1467,   855,    670,    UI_XSTR_COLOR_PINK,     -1,     &Loop_buttons[1][LOOP_BRIEF_DECLINE].button },
79                 { "Accept",                     1035,   928,    670,    UI_XSTR_COLOR_PINK,     -1,     &Loop_buttons[1][LOOP_BRIEF_ACCEPT].button },
80         }
81 };
82
83 // loop brief anim
84 int Loop_brief_anim_coords[GR_NUM_RESOLUTIONS][2] = {
85         { // GR_640
86                 24, 267
87         },
88         { // GR_640
89                 167, 491
90         }
91 };
92
93 // text window coords
94 int Loop_brief_text_coords[GR_NUM_RESOLUTIONS][4] = {
95         { // GR_640
96                 25,     107,    591,    143
97         },
98         { // GR_1024
99                 40,     171,    945,    229
100         }
101 };
102
103 UI_WINDOW Loop_brief_window;
104 int Loop_brief_bitmap;
105
106 anim *Loop_anim;
107 anim_instance *Loop_anim_instance;
108
109 int Loop_sound;
110
111 // ---------------------------------------------------------------------------------------------------------------------------------------
112 // MISSION LOOP BRIEF FUNCTIONS
113 //
114
115 // button press
116 void loop_brief_button_pressed(int i)
117 {       
118         switch(i){
119         case LOOP_BRIEF_DECLINE:                
120                 // CD CHECK
121                 if(game_do_cd_mission_check(Game_current_mission_filename)){
122                         gameseq_post_event(GS_EVENT_START_GAME);
123                         gamesnd_play_iface(SND_USER_SELECT);
124                 } else {
125                         gameseq_post_event(GS_EVENT_MAIN_MENU);
126                 }               
127                 break;
128
129         case LOOP_BRIEF_ACCEPT:
130                 // select the loop mission              
131                 Campaign.loop_enabled = 1;
132                 Campaign.loop_reentry = Campaign.next_mission;                  // save reentry pt, so we can break out of loop
133                 Campaign.next_mission = Campaign.loop_mission;          
134                 
135                 // CD CHECK
136                 if(game_do_cd_mission_check(Game_current_mission_filename)){
137                         gameseq_post_event(GS_EVENT_START_GAME);
138                         gamesnd_play_iface(SND_USER_SELECT);
139                 } else {
140                         gameseq_post_event(GS_EVENT_MAIN_MENU);
141                 }               
142                 break;
143         }
144 }
145
146 // init
147 void loop_brief_init()
148 {
149         int idx;
150         ui_button_info *b;
151
152         // load the background bitmap
153         Loop_brief_bitmap = bm_load(Loop_brief_fname[gr_screen.res]);
154         Assert(Loop_brief_bitmap != -1);
155
156         // window
157         Loop_brief_window.create(0, 0, gr_screen.max_w, gr_screen.max_h, 0);
158         Loop_brief_window.set_mask_bmap(Loop_brief_mask[gr_screen.res]);        
159
160         // add the buttons
161         for (idx=0; idx<NUM_LOOP_BRIEF_BUTTONS; idx++) {
162                 b = &Loop_buttons[gr_screen.res][idx];
163
164                 b->button.create(&Loop_brief_window, "", b->x, b->y, 60, 30, 0, 1);             
165                 b->button.set_highlight_action(common_play_highlight_sound);
166                 b->button.set_bmaps(b->filename);
167                 b->button.link_hotspot(b->hotspot);
168         }
169
170         // add text
171         for(idx=0; idx<NUM_LOOP_TEXT; idx++){
172                 Loop_brief_window.add_XSTR(&Loop_text[gr_screen.res][idx]);
173         }
174
175         // load animation if any
176         Loop_anim = NULL;
177         Loop_anim_instance = NULL;
178         if(Campaign.missions[Campaign.current_mission].mission_loop_brief_anim != NULL){
179                 Loop_anim = anim_load(Campaign.missions[Campaign.current_mission].mission_loop_brief_anim);
180         } else {
181                 Loop_anim = anim_load("CB_default");
182         }
183
184         // fire up an anim instance
185         if(Loop_anim != NULL){
186                 anim_play_struct aps;
187
188                 anim_play_init(&aps, Loop_anim, Loop_brief_anim_coords[gr_screen.res][0], Loop_brief_anim_coords[gr_screen.res][1]);
189                 aps.framerate_independent = 1;
190                 aps.looped = 1;
191                 aps.screen_id = GS_STATE_LOOP_BRIEF;
192                 Loop_anim_instance = anim_play(&aps);
193         }
194
195         // init brief text
196         if(Campaign.missions[Campaign.current_mission].mission_loop_desc != NULL){
197                 brief_color_text_init(Campaign.missions[Campaign.current_mission].mission_loop_desc, Loop_brief_text_coords[gr_screen.res][2]);
198         }
199
200         // open sound
201         if(Campaign.missions[Campaign.current_mission].mission_loop_brief_sound != NULL){
202                 Loop_sound = audiostream_open(Campaign.missions[Campaign.current_mission].mission_loop_brief_sound, ASF_VOICE);
203
204                 if(Loop_sound != -1){
205                         audiostream_play(Loop_sound, Master_voice_volume, 0);
206                 }
207         }
208
209         // music
210         common_music_init(SCORE_BRIEFING);
211 }
212
213 // do
214 void loop_brief_do()
215 {
216         int k;
217         int idx;
218
219         // process keys
220         k = Loop_brief_window.process();        
221
222         switch (k) {
223         case KEY_ESC:           
224                 gameseq_post_event(GS_EVENT_MAIN_MENU);
225                 break;
226         }       
227
228         // process button presses
229         for (idx=0; idx<NUM_LOOP_BRIEF_BUTTONS; idx++){
230                 if (Loop_buttons[gr_screen.res][idx].button.pressed()){
231                         loop_brief_button_pressed(idx);
232                 }
233         }
234         
235         common_music_do();
236
237         // clear
238         GR_MAYBE_CLEAR_RES(Loop_brief_bitmap);
239         if (Loop_brief_bitmap >= 0) {
240                 gr_set_bitmap(Loop_brief_bitmap);
241                 gr_bitmap(0, 0);
242         } 
243         
244         // draw the window
245         Loop_brief_window.draw();               
246
247         // render the briefing text
248         brief_render_text(0, Loop_brief_text_coords[gr_screen.res][0], Loop_brief_text_coords[gr_screen.res][1], Loop_brief_text_coords[gr_screen.res][3], flFrametime);
249
250         // render all anims
251         anim_render_all(GS_STATE_LOOP_BRIEF, flFrametime);
252
253         gr_flip();
254 }
255
256 // close
257 void loop_brief_close()
258 {
259         // this makes sure that we're all cool no matter how the user decides to exit
260         mission_campaign_mission_over();
261
262         // free the bitmap
263         if (Loop_brief_bitmap >= 0){
264                 bm_unload(Loop_brief_bitmap);
265         }               
266         Loop_brief_bitmap = -1;
267
268         // destroy the window
269         Loop_brief_window.destroy();
270
271         // free up anim stuff
272         if(Loop_anim_instance != NULL){
273                 anim_release_render_instance(Loop_anim_instance);
274                 Loop_anim_instance = NULL;
275         }
276         if(Loop_anim != NULL){
277                 anim_free(Loop_anim);
278                 Loop_anim = NULL;
279         }
280
281         // stop voice
282         if(Loop_sound != -1){
283                 audiostream_stop(Loop_sound);
284                 audiostream_close_file(Loop_sound);
285                 Loop_sound = -1;
286         }
287
288         // stop music
289         common_music_close();
290 }