home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / hud.c < prev    next >
C/C++ Source or Header  |  1998-06-08  |  10KB  |  341 lines

  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-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/main/rcs/hud.c $
  15.  * $Revision: 2.2 $
  16.  * $Author: mike $
  17.  * $Date: 1995/03/30 16:36:40 $
  18.  * 
  19.  * Routines for displaying HUD messages...
  20.  * 
  21.  * $Log: hud.c $
  22.  * Revision 2.2  1995/03/30  16:36:40  mike
  23.  * text localization.
  24.  * 
  25.  * Revision 2.1  1995/03/06  15:23:50  john
  26.  * New screen techniques.
  27.  * 
  28.  * Revision 2.0  1995/02/27  11:30:41  john
  29.  * New version 2.0, which has no anonymous unions, builds with
  30.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  31.  * 
  32.  * Revision 1.27  1995/01/23  16:51:30  mike
  33.  * Show hud messages on 3d if window in three largest sizes.
  34.  * 
  35.  * Revision 1.26  1995/01/17  17:42:45  rob
  36.  * Made message timeout for HUD messages longer.
  37.  * 
  38.  * Revision 1.25  1995/01/04  11:39:03  rob
  39.  * Made HUD text get out of the way of large HUD messages.
  40.  * 
  41.  * Revision 1.24  1995/01/01  14:20:32  rob
  42.  * longer timer for hud messages.
  43.  * 
  44.  * 
  45.  * Revision 1.23  1994/12/15  13:04:34  mike
  46.  * Replace Players[Player_num].time_total references with GameTime.
  47.  * 
  48.  * Revision 1.22  1994/12/13  12:55:12  mike
  49.  * move press any key to continue message when you are dead to bottom of window.
  50.  * 
  51.  * Revision 1.21  1994/12/07  17:08:01  rob
  52.  * removed unnecessary debug info.
  53.  * 
  54.  * Revision 1.20  1994/12/07  16:24:16  john
  55.  * Took out code that kept track of messages differently for different
  56.  * screen modes... I made it so they just draw differently depending on screen mode.
  57.  * 
  58.  * Revision 1.19  1994/12/07  15:42:57  rob
  59.  * Added a bunch of debug stuff to look for HUD message problems in net games...
  60.  * 
  61.  * Revision 1.18  1994/12/06  16:30:35  yuan
  62.  * Localization
  63.  * 
  64.  * Revision 1.17  1994/12/05  00:32:36  mike
  65.  * fix randomness of color on status bar hud messages.
  66.  * 
  67.  * Revision 1.16  1994/11/19  17:05:53  rob
  68.  * Moved dead_player_message down to avoid overwriting HUD messages.
  69.  * 
  70.  * Revision 1.15  1994/11/18  23:37:56  john
  71.  * Changed some shorts to ints.
  72.  * 
  73.  * Revision 1.14  1994/11/12  16:38:25  mike
  74.  * clear some annoying debug messages.
  75.  * 
  76.  * Revision 1.13  1994/11/11  15:36:39  mike
  77.  * write hud messages on background if 3d window small enough
  78.  * 
  79.  * Revision 1.12  1994/10/20  09:49:31  mike
  80.  * Reduce number of messages.
  81.  * 
  82.  * Revision 1.11  1994/10/17  10:49:15  john
  83.  * Took out some warnings.
  84.  * 
  85.  * Revision 1.10  1994/10/17  10:45:13  john
  86.  * Made the player able to abort death by pressing any button or key.
  87.  * 
  88.  * Revision 1.9  1994/10/13  15:17:33  mike
  89.  * Remove afterburner references.
  90.  * 
  91.  * Revision 1.8  1994/10/11  12:06:32  mike
  92.  * Only show message advertising death sequence abort after player exploded.
  93.  * 
  94.  * Revision 1.7  1994/10/10  17:21:53  john
  95.  * Made so instead of saying too many messages, it scrolls off the
  96.  * oldest message.
  97.  * 
  98.  * Revision 1.6  1994/10/07  23:05:39  john
  99.  * Fixed bug with HUD not drawing stuff sometimes...
  100.  * ( I had a circular buffer that I was stepping thru
  101.  * to draw text that went: for (i=first;i<last;i++)...
  102.  * duh!! last could be less than first.)
  103.  * /
  104.  * 
  105.  * Revision 1.5  1994/09/16  13:08:20  mike
  106.  * Arcade stuff, afterburner stuff.
  107.  * 
  108.  * Revision 1.4  1994/09/14  16:26:57  mike
  109.  * player_dead_message.
  110.  * 
  111.  * Revision 1.3  1994/08/18  16:35:45  john
  112.  * Made gauges messages stay up a bit longer.
  113.  * 
  114.  * Revision 1.2  1994/08/18  12:10:21  john
  115.  * Made HUD messages scroll.
  116.  * 
  117.  * Revision 1.1  1994/08/18  11:22:09  john
  118.  * Initial revision
  119.  * 
  120.  * 
  121.  */
  122.  
  123.  
  124. #pragma off (unreferenced)
  125. static char rcsid[] = "$Id: hud.c 2.2 1995/03/30 16:36:40 mike Exp $";
  126. #pragma on (unreferenced)
  127.  
  128.  
  129.  
  130. #include <stdio.h>
  131. #include <string.h>
  132. #include <stdlib.h>
  133. #include <stdarg.h>
  134.  
  135. #include "inferno.h"
  136. #include "game.h"
  137. #include "screens.h"
  138. #include "gauges.h"
  139. #include "physics.h"
  140. #include "error.h"
  141.  
  142. #include "menu.h"            // For the font.
  143. #include "mono.h"
  144. #include "collide.h"
  145. #include "newdemo.h"
  146. #include "player.h"
  147. #include "gamefont.h"
  148.  
  149. #include "wall.h"
  150. #include "arcade.h"
  151. #include "screens.h"
  152. #include "text.h"
  153.  
  154. int hud_first = 0;
  155. int hud_last = 0;
  156.  
  157. #define HUD_MESSAGE_LENGTH    150
  158. #define HUD_MAX_NUM 4
  159.  
  160. int     HUD_nmessages = 0;
  161. fix    HUD_message_timer = 0;        // Time, relative to Players[Player_num].time (int.frac seconds.frac), at which to erase gauge message
  162. char  HUD_messages[HUD_MAX_NUM][HUD_MESSAGE_LENGTH+5];
  163.  
  164. extern void copy_background_rect(int left,int top,int right,int bot);
  165. char Displayed_background_message[HUD_MESSAGE_LENGTH] = "";
  166. int    Last_msg_ycrd = -1;
  167. int    Last_msg_height = 6;
  168. int    HUD_color = -1;
  169.  
  170. //    -----------------------------------------------------------------------------
  171. void clear_background_messages(void)
  172. {
  173.     if ((Cockpit_mode == CM_STATUS_BAR) && (Last_msg_ycrd != -1) && (VR_render_sub_buffer[0].cv_bitmap.bm_y >= 6)) {
  174.         grs_canvas    *canv_save = grd_curcanv;
  175.         gr_set_current_canvas(get_current_game_screen());
  176.         copy_background_rect(0, Last_msg_ycrd, grd_curcanv->cv_bitmap.bm_w, Last_msg_ycrd+Last_msg_height-1);
  177.         gr_set_current_canvas(canv_save);
  178.         Displayed_background_message[0] = 0;
  179.         Last_msg_ycrd = -1;
  180.     }
  181.  
  182. }
  183.  
  184. void HUD_clear_messages()
  185. {
  186.     int i;
  187.     HUD_nmessages = 0;
  188.     hud_first = hud_last = 0;
  189.     HUD_message_timer = 0;
  190.     clear_background_messages();
  191.     for (i = 0; i < HUD_MAX_NUM; i++)
  192.         sprintf(HUD_messages[i], "SlagelSlagel!!");
  193. }
  194.  
  195. //    -----------------------------------------------------------------------------
  196. //    Writes a message on the HUD and checks its timer.
  197. void HUD_render_message_frame()
  198. {
  199.     int i, y,n;
  200.     int h,w,aw;
  201.  
  202.     if (( HUD_nmessages < 0 ) || (HUD_nmessages > HUD_MAX_NUM))
  203.         Int3(); // Get Rob!
  204.  
  205.     if ( HUD_nmessages < 1 ) return;
  206.  
  207.     HUD_message_timer -= FrameTime;
  208.  
  209.     if ( HUD_message_timer < 0 )    {
  210.         // Timer expired... get rid of oldest message...
  211.         if (hud_last!=hud_first)    {
  212.             //&HUD_messages[hud_first][0] is deing deleted...;
  213.             hud_first = (hud_first+1) % HUD_MAX_NUM;
  214.             HUD_message_timer = F1_0*2;
  215.             HUD_nmessages--;
  216.             clear_background_messages();            //    If in status bar mode and no messages, then erase.
  217.         }
  218.     }
  219.  
  220.     if (HUD_nmessages > 0 )    {
  221.  
  222.         gr_set_curfont( Gamefonts[GFONT_SMALL] );    
  223.         if (HUD_color == -1)
  224.             HUD_color = BM_XRGB(0,28,0);
  225.  
  226.         if ((Cockpit_mode == CM_STATUS_BAR) && (VR_render_sub_buffer[0].cv_bitmap.bm_y >= 19)) {
  227.             // Only display the most recent message in this mode
  228.             char    *message = HUD_messages[(hud_first+HUD_nmessages-1) % HUD_MAX_NUM];
  229.  
  230.             if (strcmp(Displayed_background_message, message)) {
  231.                 int    ycrd;
  232.                 grs_canvas    *canv_save = grd_curcanv;
  233.  
  234.                 ycrd = grd_curcanv->cv_bitmap.bm_y - 9;
  235.  
  236.                 if (ycrd < 0)
  237.                     ycrd = 0;
  238.  
  239.                 gr_set_current_canvas(get_current_game_screen());
  240.  
  241.                 gr_get_string_size(message, &w, &h, &aw );
  242.                 clear_background_messages();
  243.                 gr_set_fontcolor( HUD_color, -1);
  244.                 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2, ycrd, message );
  245.  
  246.                 strcpy(Displayed_background_message, message);
  247.                 gr_set_current_canvas(canv_save);
  248.                 Last_msg_ycrd = ycrd;
  249.                 Last_msg_height = h;
  250.             }
  251.         } else {
  252.             y = 3;
  253.  
  254.               for (i=0; i<HUD_nmessages; i++ )    {    
  255.                 n = (hud_first+i) % HUD_MAX_NUM;
  256.                 if ((n < 0) || (n >= HUD_MAX_NUM))
  257.                     Int3(); // Get Rob!!
  258.                 if (!strcmp(HUD_messages[n], "This is a bug."))
  259.                     Int3(); // Get Rob!!
  260.                 gr_get_string_size(&HUD_messages[n][0], &w, &h, &aw );
  261.                 gr_set_fontcolor( HUD_color, -1);
  262.                 gr_printf((grd_curcanv->cv_bitmap.bm_w-w)/2,y, &HUD_messages[n][0] );
  263.                 y += h+1;
  264.             }
  265.         }
  266.     }
  267.  
  268.     gr_set_curfont( GAME_FONT );    
  269. }
  270.  
  271. void HUD_init_message(char * format, ... )
  272. {
  273.     va_list args;
  274.     int temp;
  275.     char *message = NULL;
  276.     char *last_message=NULL;
  277.  
  278.     if ( (hud_last < 0) || (hud_last >= HUD_MAX_NUM))
  279.         Int3(); // Get Rob!!
  280.  
  281.         va_start(args, format );
  282.         message = &HUD_messages[hud_last][0];
  283.         vsprintf(message,format,args);
  284.         va_end(args);
  285. //        mprintf((0, "Hud_message: [%s]\n", message));
  286.  
  287.         if (HUD_nmessages > 0)    {
  288.             if (hud_last==0)
  289.                 last_message = &HUD_messages[HUD_MAX_NUM-1][0];
  290.             else
  291.                 last_message = &HUD_messages[hud_last-1][0];
  292.         }
  293.  
  294.         temp = (hud_last+1) % HUD_MAX_NUM;
  295.  
  296.         if ( temp==hud_first )    {
  297.             // If too many messages, remove oldest message to make room
  298.             hud_first = (hud_first+1) % HUD_MAX_NUM;
  299.             HUD_nmessages--;
  300.         }
  301.  
  302.         if (last_message && (!strcmp(last_message, message))) {
  303.             HUD_message_timer = F1_0*3;        // 1 second per 5 characters
  304.             return;    // ignore since it is the same as the last one
  305.         }
  306.  
  307.         hud_last = temp;
  308.         // Check if memory has been overwritten at this point.
  309.         if (strlen(message) >= HUD_MESSAGE_LENGTH)
  310.             Error( "Your message to HUD is too long.  Limit is %i characters.\n", HUD_MESSAGE_LENGTH);
  311.         #ifdef NEWDEMO
  312.         if (Newdemo_state == ND_STATE_RECORDING )
  313.             newdemo_record_hud_message( message );
  314.         #endif
  315.         HUD_message_timer = F1_0*3;        // 1 second per 5 characters
  316.         HUD_nmessages++;
  317. }
  318.  
  319.  
  320. void player_dead_message(void)
  321. {
  322.     if (!Arcade_mode && Player_exploded) { //(ConsoleObject->flags & OF_EXPLODING)) {
  323.         gr_set_curfont( Gamefonts[GFONT_SMALL] );    
  324.         if (HUD_color == -1)
  325.             HUD_color = BM_XRGB(0,28,0);
  326.         gr_set_fontcolor( HUD_color, -1);
  327.  
  328.         gr_printf(0x8000, grd_curcanv->cv_bitmap.bm_h-8, TXT_PRESS_ANY_KEY);
  329.         gr_set_curfont( GAME_FONT );    
  330.     }
  331.  
  332. }
  333.  
  334. // void say_afterburner_status(void)
  335. // {
  336. //     if (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)
  337. //         HUD_init_message("Afterburner engaged.");
  338. //     else
  339. //         HUD_init_message("Afterburner disengaged.");
  340. // }
  341.