]> icculus.org git repositories - btb/d2x.git/blob - main/hud.c
remove rcs tags
[btb/d2x.git] / main / hud.c
1 /*
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.
12 */
13
14 /*
15  *
16  * Routines for displaying HUD messages...
17  *
18  */
19
20
21 #ifdef HAVE_CONFIG_H
22 #include <conf.h>
23 #endif
24
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28
29 #include "hudmsg.h"
30
31 #include "pstypes.h"
32 #include "u_mem.h"
33 #include "strutil.h"
34 #include "console.h"
35 #include "inferno.h"
36 #include "game.h"
37 #include "screens.h"
38 #include "gauges.h"
39 #include "physics.h"
40 #include "error.h"
41
42 #include "menu.h"           // For the font.
43 #include "mono.h"
44 #include "collide.h"
45 #include "newdemo.h"
46 #include "player.h"
47 #include "gamefont.h"
48
49 #include "wall.h"
50 #include "screens.h"
51 #include "text.h"
52 #include "laser.h"
53 #include "args.h"
54
55 int hud_first = 0;
56 int hud_last = 0;
57
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];
61
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;
66 int HUD_color = -1;
67
68 int     MSG_Playermessages = 0;
69 int     MSG_Noredundancy = 0;
70
71 int Modex_hud_msg_count;
72
73 #define LHX(x)      ((x)*(FontHires?2:1))
74 #define LHY(y)      ((y)*(FontHires?2.4:1))
75
76 // ----------------------------------------------------------------------------
77 void clear_background_messages(void)
78 {
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;
81
82                 gr_set_current_canvas(get_current_game_screen());
83
84                 copy_background_rect(0, Last_msg_ycrd, grd_curcanv->cv_bitmap.bm_w, Last_msg_ycrd+Last_msg_height-1);
85
86                 gr_set_current_canvas(canv_save);
87
88                 Last_msg_ycrd = -1;
89         }
90
91         Displayed_background_message[VR_current_page][0] = 0;
92
93 }
94
95 void HUD_clear_messages()
96 {
97         int i;
98         HUD_nmessages = 0;
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!!");
104 }
105
106
107 extern int Guided_in_big_window;
108 extern int max_window_h;
109
110 extern grs_canvas *print_to_canvas(char *s,grs_font *font, int fc, int bc, int double_flag);
111
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)
115 {
116         grs_canvas *temp_canv;
117
118         temp_canv = print_to_canvas(s, font, color, -1, 1);
119
120         gr_bitmapm(x,y,&temp_canv->cv_bitmap);
121
122         gr_free_canvas(temp_canv);
123 }
124
125 extern int max_window_w;
126
127 // ----------------------------------------------------------------------------
128 //      Writes a message on the HUD and checks its timer.
129 void HUD_render_message_frame()
130 {
131         int i, y,n;
132         int h,w,aw;
133
134         if (( HUD_nmessages < 0 ) || (HUD_nmessages > HUD_MAX_NUM))
135                 Int3(); // Get Rob!
136
137         if ( (HUD_nmessages < 1 ) && (Modex_hud_msg_count == 0))
138                 return;
139
140         HUD_message_timer -= FrameTime;
141
142         if ( HUD_message_timer < 0 )    {
143                 // Timer expired... get rid of oldest message...
144                 if (hud_last!=hud_first)        {
145                         int     temp;
146
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;
150                         HUD_nmessages--;
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;
157                 }
158         }
159
160         if (HUD_nmessages > 0 ) {
161
162                 if (HUD_color == -1)
163                         HUD_color = BM_XRGB(0,28,0);
164
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];
168
169                         if (strcmp(Displayed_background_message[VR_current_page], message)) {
170                                 int     ycrd;
171                                 grs_canvas      *canv_save = grd_curcanv;
172
173                                 ycrd = grd_curcanv->cv_bitmap.bm_y - (SMALL_FONT->ft_h+2);
174
175                                 if (ycrd < 0)
176                                         ycrd = 0;
177
178                                 gr_set_current_canvas(get_current_game_screen());
179
180                                 gr_set_curfont( SMALL_FONT );
181                                 gr_get_string_size(message, &w, &h, &aw );
182                                 clear_background_messages();
183
184
185                                 if (grd_curcanv->cv_bitmap.bm_type == BM_MODEX) {
186                                         ycrd -= h;
187                                         h *= 2;
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] = '!';
192                                         } else
193                                                 strcpy(Displayed_background_message[VR_current_page], message);
194                                 } else {
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);
198                                 }
199
200                                 gr_set_current_canvas(canv_save);
201
202                                 Last_msg_ycrd = ycrd;
203                                 Last_msg_height = h;
204
205                         }
206                 } else {
207
208                         gr_set_curfont( SMALL_FONT );
209
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;
213                                 else
214                                         y= SMALL_FONT->ft_h * 2;
215                         } else
216                                 y = SMALL_FONT->ft_h/2;
217
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;
221
222                         for (i=0; i<HUD_nmessages; i++ )        {
223                                 n = (hud_first+i) % HUD_MAX_NUM;
224                                 if ((n < 0) || (n >= HUD_MAX_NUM))
225                                         Int3(); // Get Rob!!
226                                 if (!strcmp(HUD_messages[n], "This is a bug."))
227                                         Int3(); // Get Rob!!
228                                 gr_get_string_size(&HUD_messages[n][0], &w, &h, &aw );
229                                 gr_set_fontcolor( HUD_color, -1);
230
231                                 gr_string((grd_curcanv->cv_bitmap.bm_w-w)/2,y, &HUD_messages[n][0] );
232                                 y += h+1;
233                         }
234                 }
235         }
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;
242                 }
243         }
244
245         gr_set_curfont( GAME_FONT );
246 }
247
248 int PlayerMessage=1;
249
250
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)
254 {
255         int temp;
256         char *message = NULL;
257         char *last_message=NULL;
258 #if 0
259         int temp2;
260         char *cleanmessage;
261 #endif
262         char con_message[HUD_MESSAGE_LENGTH + 3];
263
264         Modex_hud_msg_count = 2;
265
266         if ( (hud_last < 0) || (hud_last >= HUD_MAX_NUM))
267                 Int3(); // Get Rob!!
268
269         // -- mprintf((0, "message timer: %7.3f\n", f2fl(HUD_message_timer)));
270         message = &HUD_messages[hud_last][0];
271         vsprintf(message,format,args);
272
273
274         /* Produce a colorised version and send it to the console */
275         if (HUD_color == -1)
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);
282
283         // Added by Leighton
284
285    if ((Game_mode & GM_MULTI) && FindArg("-noredundancy"))
286          if (!strnicmp ("You already",message,11))
287                 return 0;
288
289    if ((Game_mode & GM_MULTI) && FindArg("-PlayerMessages") && PlayerMessage==0)
290                 return 0;
291
292         if (HUD_nmessages > 0)  {
293                 if (hud_last==0)
294                         last_message = &HUD_messages[HUD_MAX_NUM-1][0];
295                 else
296                         last_message = &HUD_messages[hud_last-1][0];
297         }
298
299         temp = (hud_last+1) % HUD_MAX_NUM;
300
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;
304                 HUD_nmessages--;
305         }
306
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
310         }
311
312         hud_last = temp;
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);
316         #ifdef NEWDEMO
317         if (Newdemo_state == ND_STATE_RECORDING )
318                 newdemo_record_hud_message( message );
319         #endif
320         HUD_message_timer = F1_0*3;             // 1 second per 5 characters
321         HUD_nmessages++;
322
323         return 1;
324 }
325
326
327 int HUD_init_message(char * format, ... )
328 {
329         int ret;
330         va_list args;
331
332         va_start(args, format);
333         ret = HUD_init_message_va(format, args);
334         va_end(args);
335
336         return ret;
337 }
338
339
340 //@@void player_dead_message(void)
341 //@@{
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);
347 //@@
348 //@@            gr_printf(0x8000, grd_curcanv->cv_bitmap.bm_h-8, TXT_PRESS_ANY_KEY);
349 //@@            gr_set_curfont( GAME_FONT );
350 //@@    }
351 //@@
352 //@@}
353
354 void player_dead_message(void)
355 {
356     if (Player_exploded) {
357         if ( Players[Player_num].lives < 2 )    {
358             int x, y, w, h, aw;
359             gr_set_curfont( HUGE_FONT );
360             gr_get_string_size( TXT_GAME_OVER, &w, &h, &aw );
361             w += 20;
362             h += 8;
363             x = (grd_curcanv->cv_w - w ) / 2;
364             y = (grd_curcanv->cv_h - h ) / 2;
365
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;
370
371             gr_string(0x8000, (grd_curcanv->cv_h - grd_curcanv->cv_font->ft_h)/2 + h/8, TXT_GAME_OVER );
372
373 #if 0
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
379             }
380 #endif
381
382         }
383         gr_set_curfont( GAME_FONT );
384         if (HUD_color == -1)
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);
388     }
389 }
390
391 // void say_afterburner_status(void)
392 // {
393 //      if (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)
394 //              HUD_init_message("Afterburner engaged.");
395 //      else
396 //              HUD_init_message("Afterburner disengaged.");
397 // }
398
399 void hud_message(int class, char *format, ...)
400 {
401         va_list vp;
402
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);
408         va_end(vp);
409 }
410