]> icculus.org git repositories - btb/d2x.git/blob - main/hud.c
remove all the redundant Polygon Acceleration stuff (include/pa_enabl.h)
[btb/d2x.git] / main / hud.c
1 /* $Id: hud.c,v 1.10 2005-07-30 01:50:17 chris Exp $ */
2 /*
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.
13 */
14
15 /*
16  *
17  * Routines for displaying HUD messages...
18  *
19  */
20
21
22 #ifdef HAVE_CONFIG_H
23 #include <conf.h>
24 #endif
25
26 #include <stdio.h>
27 #include <string.h>
28 #include <stdlib.h>
29
30 #include "hudmsg.h"
31
32 #include "pstypes.h"
33 #include "u_mem.h"
34 #include "strutil.h"
35 #include "console.h"
36 #include "inferno.h"
37 #include "game.h"
38 #include "screens.h"
39 #include "gauges.h"
40 #include "physics.h"
41 #include "error.h"
42
43 #include "menu.h"           // For the font.
44 #include "mono.h"
45 #include "collide.h"
46 #include "newdemo.h"
47 #include "player.h"
48 #include "gamefont.h"
49
50 #include "wall.h"
51 #include "screens.h"
52 #include "text.h"
53 #include "laser.h"
54 #include "args.h"
55
56 int hud_first = 0;
57 int hud_last = 0;
58
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];
62
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;
67 int HUD_color = -1;
68
69 int     MSG_Playermessages = 0;
70 int     MSG_Noredundancy = 0;
71
72 int Modex_hud_msg_count;
73
74 #define LHX(x)      ((x)*(FontHires?2:1))
75 #define LHY(y)      ((y)*(FontHires?2.4:1))
76
77 #ifdef WINDOWS
78 int extra_clear=0;
79 #endif
80
81 // ----------------------------------------------------------------------------
82 void clear_background_messages(void)
83 {
84         #ifdef WINDOWS
85         if (extra_clear == FrameCount)          //don't do extra clear on same frame
86                 return;
87         #endif
88
89 #ifdef WINDOWS
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;
92 #else
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;
95 #endif
96
97                 WINDOS( dd_gr_set_current_canvas(get_current_game_screen()),
98                                 gr_set_current_canvas(get_current_game_screen())
99                 );
100
101                 copy_background_rect(0, Last_msg_ycrd, grd_curcanv->cv_bitmap.bm_w, Last_msg_ycrd+Last_msg_height-1);
102
103                 WINDOS(
104                         dd_gr_set_current_canvas(canv_save),
105                         gr_set_current_canvas(canv_save)
106                 );
107
108                 #ifdef WINDOWS
109                 if (extra_clear || !GRMODEINFO(modex)) {
110                         extra_clear = 0;
111                         Last_msg_ycrd = -1;
112                 }
113                 else
114                         extra_clear = FrameCount;
115                 #else
116                 Last_msg_ycrd = -1;
117                 #endif
118         }
119
120         Displayed_background_message[VR_current_page][0] = 0;
121
122 }
123
124 void HUD_clear_messages()
125 {
126         int i;
127         HUD_nmessages = 0;
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!!");
133 }
134
135
136 extern int Guided_in_big_window;
137 extern int max_window_h;
138
139 extern grs_canvas *print_to_canvas(char *s,grs_font *font, int fc, int bc, int double_flag);
140
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)
144 {
145         grs_canvas *temp_canv;
146
147         temp_canv = print_to_canvas(s, font, color, -1, 1);
148
149         gr_bitmapm(x,y,&temp_canv->cv_bitmap);
150
151         gr_free_canvas(temp_canv);
152 }
153
154 extern int max_window_w;
155
156 // ----------------------------------------------------------------------------
157 //      Writes a message on the HUD and checks its timer.
158 void HUD_render_message_frame()
159 {
160         int i, y,n;
161         int h,w,aw;
162
163         if (( HUD_nmessages < 0 ) || (HUD_nmessages > HUD_MAX_NUM))
164                 Int3(); // Get Rob!
165
166         if ( (HUD_nmessages < 1 ) && (Modex_hud_msg_count == 0))
167                 return;
168
169         HUD_message_timer -= FrameTime;
170
171         #ifdef WINDOWS
172         if (extra_clear)
173                 clear_background_messages();                    //      If in status bar mode and no messages, then erase.
174         #endif
175
176         if ( HUD_message_timer < 0 )    {
177                 // Timer expired... get rid of oldest message...
178                 if (hud_last!=hud_first)        {
179                         int     temp;
180
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;
184                         HUD_nmessages--;
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;
191                 }
192         }
193
194         if (HUD_nmessages > 0 ) {
195
196                 if (HUD_color == -1)
197                         HUD_color = BM_XRGB(0,28,0);
198
199         #ifdef WINDOWS
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))) {
201         #else
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))) {
203         #endif
204                         // Only display the most recent message in this mode
205                         char    *message = HUD_messages[(hud_first+HUD_nmessages-1) % HUD_MAX_NUM];
206
207                         if (strcmp(Displayed_background_message[VR_current_page], message)) {
208                                 int     ycrd;
209                                 WINDOS(
210                                         dd_grs_canvas *canv_save = dd_grd_curcanv,
211                                         grs_canvas      *canv_save = grd_curcanv
212                                 );
213
214                                 #ifdef MACINTOSH
215                                 if (Scanline_double)
216                                         FontHires=1;    // always display hires font outside of display
217                                 #endif
218
219                                 WINDOS(
220                                         ycrd = dd_grd_curcanv->yoff - (SMALL_FONT->ft_h+2),
221                                         ycrd = grd_curcanv->cv_bitmap.bm_y - (SMALL_FONT->ft_h+2)
222                                 );
223
224                                 if (ycrd < 0)
225                                         ycrd = 0;
226
227                                 WINDOS(
228                                         dd_gr_set_current_canvas(get_current_game_screen()),
229                                         gr_set_current_canvas(get_current_game_screen())
230                                 );
231
232                                 gr_set_curfont( SMALL_FONT );
233                                 gr_get_string_size(message, &w, &h, &aw );
234                                 clear_background_messages();
235
236
237                                 if (grd_curcanv->cv_bitmap.bm_type == BM_MODEX) {
238                                         WIN(Int3());    // No no no no ....
239                                         ycrd -= h;
240                                         h *= 2;
241                                         modex_hud_message((grd_curcanv->cv_bitmap.bm_w-w)/2, ycrd, message, SMALL_FONT, HUD_color);
242                                         if (Modex_hud_msg_count > 0) {
243                                                 Modex_hud_msg_count--;
244                                                 Displayed_background_message[VR_current_page][0] = '!';
245                                         } else
246                                                 strcpy(Displayed_background_message[VR_current_page], message);
247                                 } else {
248                                 WIN(DDGRLOCK(dd_grd_curcanv));
249                                         gr_set_fontcolor( HUD_color, -1);
250                                         gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, ycrd, message );
251                                         strcpy(Displayed_background_message[VR_current_page], message);
252                                 WIN(DDGRUNLOCK(dd_grd_curcanv));
253                                 }
254
255                         WINDOS(
256                                 dd_gr_set_current_canvas(canv_save),
257                                 gr_set_current_canvas(canv_save)
258                         );
259
260                                 Last_msg_ycrd = ycrd;
261                                 Last_msg_height = h;
262
263                                 #ifdef MACINTOSH
264                                 if (Scanline_double)
265                                         FontHires=0;    // always display hires font outside of display
266                                 #endif
267
268                         }
269                 } else {
270
271                         gr_set_curfont( SMALL_FONT );
272
273                         if ( (Cockpit_mode == CM_FULL_SCREEN) || (Cockpit_mode == CM_LETTERBOX) ) {
274                                 if (Game_window_w == max_window_w)
275                                         y = SMALL_FONT->ft_h/2;
276                                 else
277                                         y= SMALL_FONT->ft_h * 2;
278                         } else
279                                 y = SMALL_FONT->ft_h/2;
280
281                   if (Guided_missile[Player_num] && Guided_missile[Player_num]->type==OBJ_WEAPON && Guided_missile[Player_num]->id==GUIDEDMISS_ID &&
282                       Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num] && Guided_in_big_window)
283                               y+=SMALL_FONT->ft_h+3;
284
285                 WIN(DDGRLOCK(dd_grd_curcanv));
286                         for (i=0; i<HUD_nmessages; i++ )        {
287                                 n = (hud_first+i) % HUD_MAX_NUM;
288                                 if ((n < 0) || (n >= HUD_MAX_NUM))
289                                         Int3(); // Get Rob!!
290                                 if (!strcmp(HUD_messages[n], "This is a bug."))
291                                         Int3(); // Get Rob!!
292                                 gr_get_string_size(&HUD_messages[n][0], &w, &h, &aw );
293                                 gr_set_fontcolor( HUD_color, -1);
294
295                                 gr_string((grd_curcanv->cv_bitmap.bm_w-w)/2,y, &HUD_messages[n][0] );
296                                 y += h+1;
297                         }
298                 WIN(DDGRUNLOCK(dd_grd_curcanv));
299                 }
300         }
301         #ifndef WINDOWS
302         else if (get_current_game_screen()->cv_bitmap.bm_type == BM_MODEX) {
303                 if (Modex_hud_msg_count) {
304                         int     temp = Last_msg_ycrd;
305                         Modex_hud_msg_count--;
306                         clear_background_messages();                    //      If in status bar mode and no messages, then erase.
307                         Last_msg_ycrd = temp;
308                 }
309         }
310         #endif
311
312         gr_set_curfont( GAME_FONT );
313 }
314
315 int PlayerMessage=1;
316
317
318 // Call to flash a message on the HUD.  Returns true if message drawn.
319 // (message might not be drawn if previous message was same)
320 int HUD_init_message_va(char * format, va_list args)
321 {
322         int temp;
323         char *message = NULL;
324         char *last_message=NULL;
325 #if 0
326         int temp2;
327         char *cleanmessage;
328 #endif
329         char con_message[HUD_MESSAGE_LENGTH + 3];
330
331         Modex_hud_msg_count = 2;
332
333         if ( (hud_last < 0) || (hud_last >= HUD_MAX_NUM))
334                 Int3(); // Get Rob!!
335
336         // -- mprintf((0, "message timer: %7.3f\n", f2fl(HUD_message_timer)));
337         message = &HUD_messages[hud_last][0];
338         vsprintf(message,format,args);
339
340
341         /* Produce a colorised version and send it to the console */
342         if (HUD_color == -1)
343                 HUD_color = BM_XRGB(0,28,0);
344         con_message[0] = CC_COLOR;
345         con_message[1] = HUD_color;
346         con_message[2] = '\0';
347         strcat(con_message, message);
348         con_printf(CON_NORMAL, "%s\n", con_message);
349
350         // Added by Leighton
351
352    if ((Game_mode & GM_MULTI) && FindArg("-noredundancy"))
353          if (!strnicmp ("You already",message,11))
354                 return 0;
355
356    if ((Game_mode & GM_MULTI) && FindArg("-PlayerMessages") && PlayerMessage==0)
357                 return 0;
358
359         if (HUD_nmessages > 0)  {
360                 if (hud_last==0)
361                         last_message = &HUD_messages[HUD_MAX_NUM-1][0];
362                 else
363                         last_message = &HUD_messages[hud_last-1][0];
364         }
365
366         temp = (hud_last+1) % HUD_MAX_NUM;
367
368         if ( temp==hud_first )  {
369                 // If too many messages, remove oldest message to make room
370                 hud_first = (hud_first+1) % HUD_MAX_NUM;
371                 HUD_nmessages--;
372         }
373
374         if (last_message && (!strcmp(last_message, message))) {
375                 HUD_message_timer = F1_0*3;             // 1 second per 5 characters
376                 return 0;       // ignore since it is the same as the last one
377         }
378
379         hud_last = temp;
380         // Check if memory has been overwritten at this point.
381         if (strlen(message) >= HUD_MESSAGE_LENGTH)
382                 Error( "Your message to HUD is too long.  Limit is %i characters.\n", HUD_MESSAGE_LENGTH);
383         #ifdef NEWDEMO
384         if (Newdemo_state == ND_STATE_RECORDING )
385                 newdemo_record_hud_message( message );
386         #endif
387         HUD_message_timer = F1_0*3;             // 1 second per 5 characters
388         HUD_nmessages++;
389
390         return 1;
391 }
392
393
394 int HUD_init_message(char * format, ... )
395 {
396         int ret;
397         va_list args;
398
399         va_start(args, format);
400         ret = HUD_init_message_va(format, args);
401         va_end(args);
402
403         return ret;
404 }
405
406
407 //@@void player_dead_message(void)
408 //@@{
409 //@@    if (!Arcade_mode && Player_exploded) { //(ConsoleObject->flags & OF_EXPLODING)) {
410 //@@            gr_set_curfont( SMALL_FONT );
411 //@@            if (HUD_color == -1)
412 //@@                    HUD_color = BM_XRGB(0,28,0);
413 //@@            gr_set_fontcolor( HUD_color, -1);
414 //@@
415 //@@            gr_printf(0x8000, grd_curcanv->cv_bitmap.bm_h-8, TXT_PRESS_ANY_KEY);
416 //@@            gr_set_curfont( GAME_FONT );
417 //@@    }
418 //@@
419 //@@}
420
421 void player_dead_message(void)
422 {
423     if (Player_exploded) {
424         if ( Players[Player_num].lives < 2 )    {
425             int x, y, w, h, aw;
426             gr_set_curfont( HUGE_FONT );
427             gr_get_string_size( TXT_GAME_OVER, &w, &h, &aw );
428             w += 20;
429             h += 8;
430             x = (grd_curcanv->cv_w - w ) / 2;
431             y = (grd_curcanv->cv_h - h ) / 2;
432
433             Gr_scanline_darkening_level = 2*7;
434             gr_setcolor( BM_XRGB(0,0,0) );
435             gr_rect( x, y, x+w, y+h );
436             Gr_scanline_darkening_level = GR_FADE_LEVELS;
437
438             gr_string(0x8000, (grd_curcanv->cv_h - grd_curcanv->cv_font->ft_h)/2 + h/8, TXT_GAME_OVER );
439
440 #if 0
441             // Automatically exit death after 10 secs
442             if ( GameTime > Player_time_of_death + F1_0*10 ) {
443                     Function_mode = FMODE_MENU;
444                     Game_mode = GM_GAME_OVER;
445                     longjmp( LeaveGame, 1 );        // Exit out of game loop
446             }
447 #endif
448
449         }
450         gr_set_curfont( GAME_FONT );
451         if (HUD_color == -1)
452             HUD_color = BM_XRGB(0,28,0);
453         gr_set_fontcolor( HUD_color, -1);
454         gr_string(0x8000, grd_curcanv->cv_h-(grd_curcanv->cv_font->ft_h+3), TXT_PRESS_ANY_KEY);
455     }
456 }
457
458 // void say_afterburner_status(void)
459 // {
460 //      if (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)
461 //              HUD_init_message("Afterburner engaged.");
462 //      else
463 //              HUD_init_message("Afterburner disengaged.");
464 // }
465
466 void hud_message(int class, char *format, ...)
467 {
468         va_list vp;
469
470         va_start(vp, format);
471         if ((!MSG_Noredundancy || (class & MSGC_NOREDUNDANCY)) &&
472             (!MSG_Playermessages || !(Game_mode & GM_MULTI) ||
473              (class & MSGC_PLAYERMESSAGES)))
474                 HUD_init_message_va(format, vp);
475         va_end(vp);
476 }
477