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...
40 int HUD_nmessages = 0;
41 fix HUD_message_timer = 0; // Time, relative to Players[Player_num].time (int.frac seconds.frac), at which to erase gauge message
42 char HUD_messages[HUD_MAX_NUM][HUD_MESSAGE_LENGTH+5];
44 extern void copy_background_rect(int left,int top,int right,int bot);
45 char Displayed_background_message[2][HUD_MESSAGE_LENGTH] = {"",""};
46 int Last_msg_ycrd = -1;
47 int Last_msg_height = 6;
50 int MSG_Playermessages = 0;
51 int MSG_Noredundancy = 0;
53 int Modex_hud_msg_count;
55 #define LHX(x) ((x)*(FontHires?2:1))
56 #define LHY(y) ((y)*(FontHires?2.4:1))
58 // ----------------------------------------------------------------------------
59 void clear_background_messages(void)
61 if (((Cockpit_mode.intval == CM_STATUS_BAR) || (Cockpit_mode.intval == CM_FULL_SCREEN)) && (Last_msg_ycrd != -1) && (VR_render_sub_buffer[0].cv_bitmap.bm_y >= 6)) {
62 grs_canvas *canv_save = grd_curcanv;
64 gr_set_current_canvas(get_current_game_screen());
66 copy_background_rect(0, Last_msg_ycrd, grd_curcanv->cv_bitmap.bm_w, Last_msg_ycrd+Last_msg_height-1);
68 gr_set_current_canvas(canv_save);
73 Displayed_background_message[VR_current_page][0] = 0;
77 void HUD_clear_messages()
81 hud_first = hud_last = 0;
82 HUD_message_timer = 0;
83 clear_background_messages();
84 for (i = 0; i < HUD_MAX_NUM; i++)
85 sprintf(HUD_messages[i], "SlagelSlagel!!");
89 extern int max_window_h;
91 extern grs_canvas *print_to_canvas(char *s,grs_font *font, int fc, int bc, int double_flag);
93 // -----------------------------------------------------------------------------
94 // print to buffer, double heights, and blit bitmap to screen
95 void modex_hud_message(int x, int y, char *s, grs_font *font, int color)
97 grs_canvas *temp_canv;
99 temp_canv = print_to_canvas(s, font, color, -1, 1);
101 gr_bitmapm(x,y,&temp_canv->cv_bitmap);
103 gr_free_canvas(temp_canv);
106 extern int max_window_w;
108 // ----------------------------------------------------------------------------
109 // Writes a message on the HUD and checks its timer.
110 void HUD_render_message_frame()
115 if (( HUD_nmessages < 0 ) || (HUD_nmessages > HUD_MAX_NUM))
118 if ( (HUD_nmessages < 1 ) && (Modex_hud_msg_count == 0))
121 HUD_message_timer -= FrameTime;
123 if ( HUD_message_timer < 0 ) {
124 // Timer expired... get rid of oldest message...
125 if (hud_last!=hud_first) {
128 //&HUD_messages[hud_first][0] is deing deleted...;
129 hud_first = (hud_first+1) % HUD_MAX_NUM;
130 HUD_message_timer = F1_0*2;
132 if (HUD_nmessages == 0)
133 Modex_hud_msg_count = 2;
134 temp = Last_msg_ycrd;
135 clear_background_messages(); // If in status bar mode and no messages, then erase.
136 if (Modex_hud_msg_count)
137 Last_msg_ycrd = temp;
141 if (HUD_nmessages > 0 ) {
144 HUD_color = BM_XRGB(0,28,0);
146 if ( (VR_render_mode == VR_NONE) && ((Cockpit_mode.intval == CM_STATUS_BAR) || (Cockpit_mode.intval == CM_FULL_SCREEN)) && (VR_render_sub_buffer[0].cv_bitmap.bm_y >= (max_window_h/8))) {
147 // Only display the most recent message in this mode
148 char *message = HUD_messages[(hud_first+HUD_nmessages-1) % HUD_MAX_NUM];
150 if (strcmp(Displayed_background_message[VR_current_page], message)) {
152 grs_canvas *canv_save = grd_curcanv;
154 ycrd = grd_curcanv->cv_bitmap.bm_y - (SMALL_FONT->ft_h+2);
159 gr_set_current_canvas(get_current_game_screen());
161 gr_set_curfont( SMALL_FONT );
162 gr_get_string_size(message, &w, &h, &aw );
163 clear_background_messages();
166 if (grd_curcanv->cv_bitmap.bm_type == BM_MODEX) {
169 modex_hud_message((grd_curcanv->cv_bitmap.bm_w-w)/2, ycrd, message, SMALL_FONT, HUD_color);
170 if (Modex_hud_msg_count > 0) {
171 Modex_hud_msg_count--;
172 Displayed_background_message[VR_current_page][0] = '!';
174 strcpy(Displayed_background_message[VR_current_page], message);
176 gr_set_fontcolor( HUD_color, -1);
177 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, ycrd, message );
178 strcpy(Displayed_background_message[VR_current_page], message);
181 gr_set_current_canvas(canv_save);
183 Last_msg_ycrd = ycrd;
189 gr_set_curfont( SMALL_FONT );
191 if ( (Cockpit_mode.intval == CM_FULL_SCREEN) || (Cockpit_mode.intval == CM_LETTERBOX) ) {
192 if (Game_window_w.intval == max_window_w)
193 y = SMALL_FONT->ft_h/2;
195 y= SMALL_FONT->ft_h * 2;
197 y = SMALL_FONT->ft_h/2;
199 if (Guided_missile[Player_num] &&
200 Guided_missile[Player_num]->type == OBJ_WEAPON &&
201 Guided_missile[Player_num]->id == GUIDEDMISS_ID &&
202 Guided_missile[Player_num]->signature == Guided_missile_sig[Player_num] &&
203 Guided_in_big_window.intval)
204 y+=SMALL_FONT->ft_h+3;
206 for (i=0; i<HUD_nmessages; i++ ) {
207 n = (hud_first+i) % HUD_MAX_NUM;
208 if ((n < 0) || (n >= HUD_MAX_NUM))
210 if (!strcmp(HUD_messages[n], "This is a bug."))
212 gr_get_string_size(&HUD_messages[n][0], &w, &h, &aw );
213 gr_set_fontcolor( HUD_color, -1);
215 gr_string((grd_curcanv->cv_bitmap.bm_w-w)/2,y, &HUD_messages[n][0] );
220 else if (get_current_game_screen()->cv_bitmap.bm_type == BM_MODEX) {
221 if (Modex_hud_msg_count) {
222 int temp = Last_msg_ycrd;
223 Modex_hud_msg_count--;
224 clear_background_messages(); // If in status bar mode and no messages, then erase.
225 Last_msg_ycrd = temp;
229 gr_set_curfont( GAME_FONT );
235 // Call to flash a message on the HUD. Returns true if message drawn.
236 // (message might not be drawn if previous message was same)
237 int HUD_init_message_va(char * format, va_list args)
240 char *message = NULL;
241 char *last_message=NULL;
246 char con_message[HUD_MESSAGE_LENGTH + 3];
248 Modex_hud_msg_count = 2;
250 if ( (hud_last < 0) || (hud_last >= HUD_MAX_NUM))
253 // -- mprintf((0, "message timer: %7.3f\n", f2fl(HUD_message_timer)));
254 message = &HUD_messages[hud_last][0];
255 vsprintf(message,format,args);
258 /* Produce a colorised version and send it to the console */
260 HUD_color = BM_XRGB(0,28,0);
261 con_message[0] = CC_COLOR;
262 con_message[1] = HUD_color;
263 con_message[2] = '\0';
264 strcat(con_message, message);
265 con_printf(CON_NORMAL, "%s\n", con_message);
269 if ((Game_mode & GM_MULTI) && FindArg("-noredundancy"))
270 if (!strnicmp ("You already",message,11))
273 if ((Game_mode & GM_MULTI) && FindArg("-PlayerMessages") && PlayerMessage==0)
276 if (HUD_nmessages > 0) {
278 last_message = &HUD_messages[HUD_MAX_NUM-1][0];
280 last_message = &HUD_messages[hud_last-1][0];
283 temp = (hud_last+1) % HUD_MAX_NUM;
285 if ( temp==hud_first ) {
286 // If too many messages, remove oldest message to make room
287 hud_first = (hud_first+1) % HUD_MAX_NUM;
291 if (last_message && (!strcmp(last_message, message))) {
292 HUD_message_timer = F1_0*3; // 1 second per 5 characters
293 return 0; // ignore since it is the same as the last one
297 // Check if memory has been overwritten at this point.
298 if (strlen(message) >= HUD_MESSAGE_LENGTH)
299 Error( "Your message to HUD is too long. Limit is %i characters.\n", HUD_MESSAGE_LENGTH);
301 if (Newdemo_state == ND_STATE_RECORDING )
302 newdemo_record_hud_message( message );
304 HUD_message_timer = F1_0*3; // 1 second per 5 characters
311 int HUD_init_message(char * format, ... )
316 va_start(args, format);
317 ret = HUD_init_message_va(format, args);
324 //@@void player_dead_message(void)
326 //@@ if (!Arcade_mode && Player_exploded) { //(ConsoleObject->flags & OF_EXPLODING)) {
327 //@@ gr_set_curfont( SMALL_FONT );
328 //@@ if (HUD_color == -1)
329 //@@ HUD_color = BM_XRGB(0,28,0);
330 //@@ gr_set_fontcolor( HUD_color, -1);
332 //@@ gr_printf(0x8000, grd_curcanv->cv_bitmap.bm_h-8, TXT_PRESS_ANY_KEY);
333 //@@ gr_set_curfont( GAME_FONT );
338 void player_dead_message(void)
340 if (Player_exploded) {
341 if ( Players[Player_num].lives < 2 ) {
343 gr_set_curfont( HUGE_FONT );
344 gr_get_string_size( TXT_GAME_OVER, &w, &h, &aw );
347 x = (grd_curcanv->cv_w - w ) / 2;
348 y = (grd_curcanv->cv_h - h ) / 2;
350 Gr_scanline_darkening_level = 2*7;
351 gr_setcolor( BM_XRGB(0,0,0) );
352 gr_rect( x, y, x+w, y+h );
353 Gr_scanline_darkening_level = GR_FADE_LEVELS;
355 gr_string(0x8000, (grd_curcanv->cv_h - grd_curcanv->cv_font->ft_h)/2 + h/8, TXT_GAME_OVER );
358 // Automatically exit death after 10 secs
359 if ( GameTime > Player_time_of_death + F1_0*10 ) {
360 Function_mode = FMODE_MENU;
361 Game_mode = GM_GAME_OVER;
362 longjmp( LeaveGame, 1 ); // Exit out of game loop
367 gr_set_curfont( GAME_FONT );
369 HUD_color = BM_XRGB(0,28,0);
370 gr_set_fontcolor( HUD_color, -1);
371 gr_string(0x8000, grd_curcanv->cv_h-(grd_curcanv->cv_font->ft_h+3), TXT_PRESS_ANY_KEY);
375 // void say_afterburner_status(void)
377 // if (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)
378 // HUD_init_message("Afterburner engaged.");
380 // HUD_init_message("Afterburner disengaged.");
383 void hud_message(int class, char *format, ...)
387 va_start(vp, format);
388 if ((!MSG_Noredundancy || (class & MSGC_NOREDUNDANCY)) &&
389 (!MSG_Playermessages || !(Game_mode & GM_MULTI) ||
390 (class & MSGC_PLAYERMESSAGES)))
391 HUD_init_message_va(format, vp);