1 /* $Id: hud.c,v 1.11 2005-07-30 09:16:25 chris Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Routines for displaying HUD messages...
43 #include "menu.h" // For the font.
59 int HUD_nmessages = 0;
60 fix HUD_message_timer = 0; // Time, relative to Players[Player_num].time (int.frac seconds.frac), at which to erase gauge message
61 char HUD_messages[HUD_MAX_NUM][HUD_MESSAGE_LENGTH+5];
63 extern void copy_background_rect(int left,int top,int right,int bot);
64 char Displayed_background_message[2][HUD_MESSAGE_LENGTH] = {"",""};
65 int Last_msg_ycrd = -1;
66 int Last_msg_height = 6;
69 int MSG_Playermessages = 0;
70 int MSG_Noredundancy = 0;
72 int Modex_hud_msg_count;
74 #define LHX(x) ((x)*(FontHires?2:1))
75 #define LHY(y) ((y)*(FontHires?2.4:1))
81 // ----------------------------------------------------------------------------
82 void clear_background_messages(void)
85 if (extra_clear == FrameCount) //don't do extra clear on same frame
90 if (((Cockpit_mode == CM_STATUS_BAR) || (Cockpit_mode == CM_FULL_SCREEN)) && (Last_msg_ycrd != -1) && (dd_VR_render_sub_buffer[0].yoff >= 6)) {
91 dd_grs_canvas *canv_save = dd_grd_curcanv;
93 if (((Cockpit_mode == CM_STATUS_BAR) || (Cockpit_mode == CM_FULL_SCREEN)) && (Last_msg_ycrd != -1) && (VR_render_sub_buffer[0].cv_bitmap.bm_y >= 6)) {
94 grs_canvas *canv_save = grd_curcanv;
97 WINDOS( dd_gr_set_current_canvas(get_current_game_screen()),
98 gr_set_current_canvas(get_current_game_screen())
101 copy_background_rect(0, Last_msg_ycrd, grd_curcanv->cv_bitmap.bm_w, Last_msg_ycrd+Last_msg_height-1);
104 dd_gr_set_current_canvas(canv_save),
105 gr_set_current_canvas(canv_save)
109 if (extra_clear || !GRMODEINFO(modex)) {
114 extra_clear = FrameCount;
120 Displayed_background_message[VR_current_page][0] = 0;
124 void HUD_clear_messages()
128 hud_first = hud_last = 0;
129 HUD_message_timer = 0;
130 clear_background_messages();
131 for (i = 0; i < HUD_MAX_NUM; i++)
132 sprintf(HUD_messages[i], "SlagelSlagel!!");
136 extern int Guided_in_big_window;
137 extern int max_window_h;
139 extern grs_canvas *print_to_canvas(char *s,grs_font *font, int fc, int bc, int double_flag);
141 // -----------------------------------------------------------------------------
142 // print to buffer, double heights, and blit bitmap to screen
143 void modex_hud_message(int x, int y, char *s, grs_font *font, int color)
145 grs_canvas *temp_canv;
147 temp_canv = print_to_canvas(s, font, color, -1, 1);
149 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
151 gr_free_canvas(temp_canv);
154 extern int max_window_w;
156 // ----------------------------------------------------------------------------
157 // Writes a message on the HUD and checks its timer.
158 void HUD_render_message_frame()
163 if (( HUD_nmessages < 0 ) || (HUD_nmessages > HUD_MAX_NUM))
166 if ( (HUD_nmessages < 1 ) && (Modex_hud_msg_count == 0))
169 HUD_message_timer -= FrameTime;
173 clear_background_messages(); // If in status bar mode and no messages, then erase.
176 if ( HUD_message_timer < 0 ) {
177 // Timer expired... get rid of oldest message...
178 if (hud_last!=hud_first) {
181 //&HUD_messages[hud_first][0] is deing deleted...;
182 hud_first = (hud_first+1) % HUD_MAX_NUM;
183 HUD_message_timer = F1_0*2;
185 if (HUD_nmessages == 0)
186 Modex_hud_msg_count = 2;
187 temp = Last_msg_ycrd;
188 clear_background_messages(); // If in status bar mode and no messages, then erase.
189 if (Modex_hud_msg_count)
190 Last_msg_ycrd = temp;
194 if (HUD_nmessages > 0 ) {
197 HUD_color = BM_XRGB(0,28,0);
200 if ( (VR_render_mode==VR_NONE) && ((Cockpit_mode == CM_STATUS_BAR) || (Cockpit_mode == CM_FULL_SCREEN)) && (dd_VR_render_sub_buffer[0].yoff >= (max_window_h/8))) {
202 if ( (VR_render_mode==VR_NONE) && ((Cockpit_mode == CM_STATUS_BAR) || (Cockpit_mode == CM_FULL_SCREEN)) && (VR_render_sub_buffer[0].cv_bitmap.bm_y >= (max_window_h/8))) {
204 // Only display the most recent message in this mode
205 char *message = HUD_messages[(hud_first+HUD_nmessages-1) % HUD_MAX_NUM];
207 if (strcmp(Displayed_background_message[VR_current_page], message)) {
210 dd_grs_canvas *canv_save = dd_grd_curcanv,
211 grs_canvas *canv_save = grd_curcanv
215 ycrd = dd_grd_curcanv->yoff - (SMALL_FONT->ft_h+2),
216 ycrd = grd_curcanv->cv_bitmap.bm_y - (SMALL_FONT->ft_h+2)
223 dd_gr_set_current_canvas(get_current_game_screen()),
224 gr_set_current_canvas(get_current_game_screen())
227 gr_set_curfont( SMALL_FONT );
228 gr_get_string_size(message, &w, &h, &aw );
229 clear_background_messages();
232 if (grd_curcanv->cv_bitmap.bm_type == BM_MODEX) {
233 WIN(Int3()); // No no no no ....
236 modex_hud_message((grd_curcanv->cv_bitmap.bm_w-w)/2, ycrd, message, SMALL_FONT, HUD_color);
237 if (Modex_hud_msg_count > 0) {
238 Modex_hud_msg_count--;
239 Displayed_background_message[VR_current_page][0] = '!';
241 strcpy(Displayed_background_message[VR_current_page], message);
243 WIN(DDGRLOCK(dd_grd_curcanv));
244 gr_set_fontcolor( HUD_color, -1);
245 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, ycrd, message );
246 strcpy(Displayed_background_message[VR_current_page], message);
247 WIN(DDGRUNLOCK(dd_grd_curcanv));
251 dd_gr_set_current_canvas(canv_save),
252 gr_set_current_canvas(canv_save)
255 Last_msg_ycrd = ycrd;
261 gr_set_curfont( SMALL_FONT );
263 if ( (Cockpit_mode == CM_FULL_SCREEN) || (Cockpit_mode == CM_LETTERBOX) ) {
264 if (Game_window_w == max_window_w)
265 y = SMALL_FONT->ft_h/2;
267 y= SMALL_FONT->ft_h * 2;
269 y = SMALL_FONT->ft_h/2;
271 if (Guided_missile[Player_num] && Guided_missile[Player_num]->type==OBJ_WEAPON && Guided_missile[Player_num]->id==GUIDEDMISS_ID &&
272 Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] && Guided_in_big_window)
273 y+=SMALL_FONT->ft_h+3;
275 WIN(DDGRLOCK(dd_grd_curcanv));
276 for (i=0; i<HUD_nmessages; i++ ) {
277 n = (hud_first+i) % HUD_MAX_NUM;
278 if ((n < 0) || (n >= HUD_MAX_NUM))
280 if (!strcmp(HUD_messages[n], "This is a bug."))
282 gr_get_string_size(&HUD_messages[n][0], &w, &h, &aw );
283 gr_set_fontcolor( HUD_color, -1);
285 gr_string((grd_curcanv->cv_bitmap.bm_w-w)/2,y, &HUD_messages[n][0] );
288 WIN(DDGRUNLOCK(dd_grd_curcanv));
292 else if (get_current_game_screen()->cv_bitmap.bm_type == BM_MODEX) {
293 if (Modex_hud_msg_count) {
294 int temp = Last_msg_ycrd;
295 Modex_hud_msg_count--;
296 clear_background_messages(); // If in status bar mode and no messages, then erase.
297 Last_msg_ycrd = temp;
302 gr_set_curfont( GAME_FONT );
308 // Call to flash a message on the HUD. Returns true if message drawn.
309 // (message might not be drawn if previous message was same)
310 int HUD_init_message_va(char * format, va_list args)
313 char *message = NULL;
314 char *last_message=NULL;
319 char con_message[HUD_MESSAGE_LENGTH + 3];
321 Modex_hud_msg_count = 2;
323 if ( (hud_last < 0) || (hud_last >= HUD_MAX_NUM))
326 // -- mprintf((0, "message timer: %7.3f\n", f2fl(HUD_message_timer)));
327 message = &HUD_messages[hud_last][0];
328 vsprintf(message,format,args);
331 /* Produce a colorised version and send it to the console */
333 HUD_color = BM_XRGB(0,28,0);
334 con_message[0] = CC_COLOR;
335 con_message[1] = HUD_color;
336 con_message[2] = '\0';
337 strcat(con_message, message);
338 con_printf(CON_NORMAL, "%s\n", con_message);
342 if ((Game_mode & GM_MULTI) && FindArg("-noredundancy"))
343 if (!strnicmp ("You already",message,11))
346 if ((Game_mode & GM_MULTI) && FindArg("-PlayerMessages") && PlayerMessage==0)
349 if (HUD_nmessages > 0) {
351 last_message = &HUD_messages[HUD_MAX_NUM-1][0];
353 last_message = &HUD_messages[hud_last-1][0];
356 temp = (hud_last+1) % HUD_MAX_NUM;
358 if ( temp==hud_first ) {
359 // If too many messages, remove oldest message to make room
360 hud_first = (hud_first+1) % HUD_MAX_NUM;
364 if (last_message && (!strcmp(last_message, message))) {
365 HUD_message_timer = F1_0*3; // 1 second per 5 characters
366 return 0; // ignore since it is the same as the last one
370 // Check if memory has been overwritten at this point.
371 if (strlen(message) >= HUD_MESSAGE_LENGTH)
372 Error( "Your message to HUD is too long. Limit is %i characters.\n", HUD_MESSAGE_LENGTH);
374 if (Newdemo_state == ND_STATE_RECORDING )
375 newdemo_record_hud_message( message );
377 HUD_message_timer = F1_0*3; // 1 second per 5 characters
384 int HUD_init_message(char * format, ... )
389 va_start(args, format);
390 ret = HUD_init_message_va(format, args);
397 //@@void player_dead_message(void)
399 //@@ if (!Arcade_mode && Player_exploded) { //(ConsoleObject->flags & OF_EXPLODING)) {
400 //@@ gr_set_curfont( SMALL_FONT );
401 //@@ if (HUD_color == -1)
402 //@@ HUD_color = BM_XRGB(0,28,0);
403 //@@ gr_set_fontcolor( HUD_color, -1);
405 //@@ gr_printf(0x8000, grd_curcanv->cv_bitmap.bm_h-8, TXT_PRESS_ANY_KEY);
406 //@@ gr_set_curfont( GAME_FONT );
411 void player_dead_message(void)
413 if (Player_exploded) {
414 if ( Players[Player_num].lives < 2 ) {
416 gr_set_curfont( HUGE_FONT );
417 gr_get_string_size( TXT_GAME_OVER, &w, &h, &aw );
420 x = (grd_curcanv->cv_w - w ) / 2;
421 y = (grd_curcanv->cv_h - h ) / 2;
423 Gr_scanline_darkening_level = 2*7;
424 gr_setcolor( BM_XRGB(0,0,0) );
425 gr_rect( x, y, x+w, y+h );
426 Gr_scanline_darkening_level = GR_FADE_LEVELS;
428 gr_string(0x8000, (grd_curcanv->cv_h - grd_curcanv->cv_font->ft_h)/2 + h/8, TXT_GAME_OVER );
431 // Automatically exit death after 10 secs
432 if ( GameTime > Player_time_of_death + F1_0*10 ) {
433 Function_mode = FMODE_MENU;
434 Game_mode = GM_GAME_OVER;
435 longjmp( LeaveGame, 1 ); // Exit out of game loop
440 gr_set_curfont( GAME_FONT );
442 HUD_color = BM_XRGB(0,28,0);
443 gr_set_fontcolor( HUD_color, -1);
444 gr_string(0x8000, grd_curcanv->cv_h-(grd_curcanv->cv_font->ft_h+3), TXT_PRESS_ANY_KEY);
448 // void say_afterburner_status(void)
450 // if (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)
451 // HUD_init_message("Afterburner engaged.");
453 // HUD_init_message("Afterburner disengaged.");
456 void hud_message(int class, char *format, ...)
460 va_start(vp, format);
461 if ((!MSG_Noredundancy || (class & MSGC_NOREDUNDANCY)) &&
462 (!MSG_Playermessages || !(Game_mode & GM_MULTI) ||
463 (class & MSGC_PLAYERMESSAGES)))
464 HUD_init_message_va(format, vp);