2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
16 * Routines for displaying HUD messages...
42 #include "menu.h" // For the font.
58 int HUD_nmessages = 0;
59 fix HUD_message_timer = 0; // Time, relative to Players[Player_num].time (int.frac seconds.frac), at which to erase gauge message
60 char HUD_messages[HUD_MAX_NUM][HUD_MESSAGE_LENGTH+5];
62 extern void copy_background_rect(int left,int top,int right,int bot);
63 char Displayed_background_message[2][HUD_MESSAGE_LENGTH] = {"",""};
64 int Last_msg_ycrd = -1;
65 int Last_msg_height = 6;
68 int MSG_Playermessages = 0;
69 int MSG_Noredundancy = 0;
71 int Modex_hud_msg_count;
73 #define LHX(x) ((x)*(FontHires?2:1))
74 #define LHY(y) ((y)*(FontHires?2.4:1))
76 // ----------------------------------------------------------------------------
77 void clear_background_messages(void)
79 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)) {
80 grs_canvas *canv_save = grd_curcanv;
82 gr_set_current_canvas(get_current_game_screen());
84 copy_background_rect(0, Last_msg_ycrd, grd_curcanv->cv_bitmap.bm_w, Last_msg_ycrd+Last_msg_height-1);
86 gr_set_current_canvas(canv_save);
91 Displayed_background_message[VR_current_page][0] = 0;
95 void HUD_clear_messages()
99 hud_first = hud_last = 0;
100 HUD_message_timer = 0;
101 clear_background_messages();
102 for (i = 0; i < HUD_MAX_NUM; i++)
103 sprintf(HUD_messages[i], "SlagelSlagel!!");
107 extern int Guided_in_big_window;
108 extern int max_window_h;
110 extern grs_canvas *print_to_canvas(char *s,grs_font *font, int fc, int bc, int double_flag);
112 // -----------------------------------------------------------------------------
113 // print to buffer, double heights, and blit bitmap to screen
114 void modex_hud_message(int x, int y, char *s, grs_font *font, int color)
116 grs_canvas *temp_canv;
118 temp_canv = print_to_canvas(s, font, color, -1, 1);
120 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
122 gr_free_canvas(temp_canv);
125 extern int max_window_w;
127 // ----------------------------------------------------------------------------
128 // Writes a message on the HUD and checks its timer.
129 void HUD_render_message_frame()
134 if (( HUD_nmessages < 0 ) || (HUD_nmessages > HUD_MAX_NUM))
137 if ( (HUD_nmessages < 1 ) && (Modex_hud_msg_count == 0))
140 HUD_message_timer -= FrameTime;
142 if ( HUD_message_timer < 0 ) {
143 // Timer expired... get rid of oldest message...
144 if (hud_last!=hud_first) {
147 //&HUD_messages[hud_first][0] is deing deleted...;
148 hud_first = (hud_first+1) % HUD_MAX_NUM;
149 HUD_message_timer = F1_0*2;
151 if (HUD_nmessages == 0)
152 Modex_hud_msg_count = 2;
153 temp = Last_msg_ycrd;
154 clear_background_messages(); // If in status bar mode and no messages, then erase.
155 if (Modex_hud_msg_count)
156 Last_msg_ycrd = temp;
160 if (HUD_nmessages > 0 ) {
163 HUD_color = BM_XRGB(0,28,0);
165 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))) {
166 // Only display the most recent message in this mode
167 char *message = HUD_messages[(hud_first+HUD_nmessages-1) % HUD_MAX_NUM];
169 if (strcmp(Displayed_background_message[VR_current_page], message)) {
171 grs_canvas *canv_save = grd_curcanv;
173 ycrd = grd_curcanv->cv_bitmap.bm_y - (SMALL_FONT->ft_h+2);
178 gr_set_current_canvas(get_current_game_screen());
180 gr_set_curfont( SMALL_FONT );
181 gr_get_string_size(message, &w, &h, &aw );
182 clear_background_messages();
185 if (grd_curcanv->cv_bitmap.bm_type == BM_MODEX) {
188 modex_hud_message((grd_curcanv->cv_bitmap.bm_w-w)/2, ycrd, message, SMALL_FONT, HUD_color);
189 if (Modex_hud_msg_count > 0) {
190 Modex_hud_msg_count--;
191 Displayed_background_message[VR_current_page][0] = '!';
193 strcpy(Displayed_background_message[VR_current_page], message);
195 gr_set_fontcolor( HUD_color, -1);
196 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, ycrd, message );
197 strcpy(Displayed_background_message[VR_current_page], message);
200 gr_set_current_canvas(canv_save);
202 Last_msg_ycrd = ycrd;
208 gr_set_curfont( SMALL_FONT );
210 if ( (Cockpit_mode == CM_FULL_SCREEN) || (Cockpit_mode == CM_LETTERBOX) ) {
211 if (Game_window_w == max_window_w)
212 y = SMALL_FONT->ft_h/2;
214 y= SMALL_FONT->ft_h * 2;
216 y = SMALL_FONT->ft_h/2;
218 if (Guided_missile[Player_num] && Guided_missile[Player_num]->type==OBJ_WEAPON && Guided_missile[Player_num]->id==GUIDEDMISS_ID &&
219 Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] && Guided_in_big_window)
220 y+=SMALL_FONT->ft_h+3;
222 for (i=0; i<HUD_nmessages; i++ ) {
223 n = (hud_first+i) % HUD_MAX_NUM;
224 if ((n < 0) || (n >= HUD_MAX_NUM))
226 if (!strcmp(HUD_messages[n], "This is a bug."))
228 gr_get_string_size(&HUD_messages[n][0], &w, &h, &aw );
229 gr_set_fontcolor( HUD_color, -1);
231 gr_string((grd_curcanv->cv_bitmap.bm_w-w)/2,y, &HUD_messages[n][0] );
236 else if (get_current_game_screen()->cv_bitmap.bm_type == BM_MODEX) {
237 if (Modex_hud_msg_count) {
238 int temp = Last_msg_ycrd;
239 Modex_hud_msg_count--;
240 clear_background_messages(); // If in status bar mode and no messages, then erase.
241 Last_msg_ycrd = temp;
245 gr_set_curfont( GAME_FONT );
251 // Call to flash a message on the HUD. Returns true if message drawn.
252 // (message might not be drawn if previous message was same)
253 int HUD_init_message_va(char * format, va_list args)
256 char *message = NULL;
257 char *last_message=NULL;
262 char con_message[HUD_MESSAGE_LENGTH + 3];
264 Modex_hud_msg_count = 2;
266 if ( (hud_last < 0) || (hud_last >= HUD_MAX_NUM))
269 // -- mprintf((0, "message timer: %7.3f\n", f2fl(HUD_message_timer)));
270 message = &HUD_messages[hud_last][0];
271 vsprintf(message,format,args);
274 /* Produce a colorised version and send it to the console */
276 HUD_color = BM_XRGB(0,28,0);
277 con_message[0] = CC_COLOR;
278 con_message[1] = HUD_color;
279 con_message[2] = '\0';
280 strcat(con_message, message);
281 con_printf(CON_NORMAL, "%s\n", con_message);
285 if ((Game_mode & GM_MULTI) && FindArg("-noredundancy"))
286 if (!strnicmp ("You already",message,11))
289 if ((Game_mode & GM_MULTI) && FindArg("-PlayerMessages") && PlayerMessage==0)
292 if (HUD_nmessages > 0) {
294 last_message = &HUD_messages[HUD_MAX_NUM-1][0];
296 last_message = &HUD_messages[hud_last-1][0];
299 temp = (hud_last+1) % HUD_MAX_NUM;
301 if ( temp==hud_first ) {
302 // If too many messages, remove oldest message to make room
303 hud_first = (hud_first+1) % HUD_MAX_NUM;
307 if (last_message && (!strcmp(last_message, message))) {
308 HUD_message_timer = F1_0*3; // 1 second per 5 characters
309 return 0; // ignore since it is the same as the last one
313 // Check if memory has been overwritten at this point.
314 if (strlen(message) >= HUD_MESSAGE_LENGTH)
315 Error( "Your message to HUD is too long. Limit is %i characters.\n", HUD_MESSAGE_LENGTH);
317 if (Newdemo_state == ND_STATE_RECORDING )
318 newdemo_record_hud_message( message );
320 HUD_message_timer = F1_0*3; // 1 second per 5 characters
327 int HUD_init_message(char * format, ... )
332 va_start(args, format);
333 ret = HUD_init_message_va(format, args);
340 //@@void player_dead_message(void)
342 //@@ if (!Arcade_mode && Player_exploded) { //(ConsoleObject->flags & OF_EXPLODING)) {
343 //@@ gr_set_curfont( SMALL_FONT );
344 //@@ if (HUD_color == -1)
345 //@@ HUD_color = BM_XRGB(0,28,0);
346 //@@ gr_set_fontcolor( HUD_color, -1);
348 //@@ gr_printf(0x8000, grd_curcanv->cv_bitmap.bm_h-8, TXT_PRESS_ANY_KEY);
349 //@@ gr_set_curfont( GAME_FONT );
354 void player_dead_message(void)
356 if (Player_exploded) {
357 if ( Players[Player_num].lives < 2 ) {
359 gr_set_curfont( HUGE_FONT );
360 gr_get_string_size( TXT_GAME_OVER, &w, &h, &aw );
363 x = (grd_curcanv->cv_w - w ) / 2;
364 y = (grd_curcanv->cv_h - h ) / 2;
366 Gr_scanline_darkening_level = 2*7;
367 gr_setcolor( BM_XRGB(0,0,0) );
368 gr_rect( x, y, x+w, y+h );
369 Gr_scanline_darkening_level = GR_FADE_LEVELS;
371 gr_string(0x8000, (grd_curcanv->cv_h - grd_curcanv->cv_font->ft_h)/2 + h/8, TXT_GAME_OVER );
374 // Automatically exit death after 10 secs
375 if ( GameTime > Player_time_of_death + F1_0*10 ) {
376 Function_mode = FMODE_MENU;
377 Game_mode = GM_GAME_OVER;
378 longjmp( LeaveGame, 1 ); // Exit out of game loop
383 gr_set_curfont( GAME_FONT );
385 HUD_color = BM_XRGB(0,28,0);
386 gr_set_fontcolor( HUD_color, -1);
387 gr_string(0x8000, grd_curcanv->cv_h-(grd_curcanv->cv_font->ft_h+3), TXT_PRESS_ANY_KEY);
391 // void say_afterburner_status(void)
393 // if (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)
394 // HUD_init_message("Afterburner engaged.");
396 // HUD_init_message("Afterburner disengaged.");
399 void hud_message(int class, char *format, ...)
403 va_start(vp, format);
404 if ((!MSG_Noredundancy || (class & MSGC_NOREDUNDANCY)) &&
405 (!MSG_Playermessages || !(Game_mode & GM_MULTI) ||
406 (class & MSGC_PLAYERMESSAGES)))
407 HUD_init_message_va(format, vp);