home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / radar.c < prev    next >
Text File  |  1998-06-08  |  6KB  |  204 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/radar.c $
  15.  * $Revision: 1.10 $
  16.  * $Author: john $
  17.  * $Date: 1995/02/27 12:31:15 $
  18.  * 
  19.  * Routines for drawing the radar.
  20.  * . 
  21.  * 
  22.  * $Log: radar.c $
  23.  * Revision 1.10  1995/02/27  12:31:15  john
  24.  * Version 2.0.
  25.  * 
  26.  * Revision 1.9  1995/02/01  21:03:36  john
  27.  * Lintified.
  28.  * 
  29.  * Revision 1.8  1994/08/12  22:41:28  john
  30.  * Took away Player_stats; add Players array.
  31.  * 
  32.  * Revision 1.7  1994/07/15  09:38:00  john
  33.  * Moved in radar_farthest_dist.
  34.  * 
  35.  * Revision 1.6  1994/07/14  22:05:57  john
  36.  * Made radar display not conflict with hostage
  37.  * vclip talking.
  38.  * 
  39.  * Revision 1.5  1994/07/12  18:41:51  yuan
  40.  * Tweaked location of radar and hostage screen... 
  41.  * Still needs work.
  42.  * 
  43.  * 
  44.  * Revision 1.4  1994/07/07  14:59:00  john
  45.  * Made radar powerups.
  46.  * 
  47.  * 
  48.  * Revision 1.3  1994/07/07  10:05:36  john
  49.  * Pegged objects in radar to edges.
  50.  * 
  51.  * Revision 1.2  1994/07/06  19:36:33  john
  52.  * Initial version of radar.
  53.  * 
  54.  * Revision 1.1  1994/07/06  17:22:07  john
  55.  * Initial revision
  56.  * 
  57.  * 
  58.  */
  59.  
  60.  
  61. #pragma off (unreferenced)
  62. static char rcsid[] = "$Id: radar.c 1.10 1995/02/27 12:31:15 john Exp $";
  63. #pragma on (unreferenced)
  64.  
  65.  
  66. #include <stdlib.h>
  67.  
  68. #include "error.h"
  69. #include "3d.h"
  70. #include "inferno.h"
  71. #include "object.h"
  72. #include "vclip.h"
  73. #include "game.h"
  74. #include "mono.h"
  75. #include "polyobj.h"
  76. #include "sounds.h"
  77. #include "player.h"
  78. #include "bm.h"
  79. #include "hostage.h"
  80. #include "multi.h"
  81. #include "network.h"
  82. #include "gauges.h"
  83.  
  84. static short         Hostage_monitor_x = 160-(55/2);            // X location of monitor where hostage face appears
  85. static short         Hostage_monitor_y = 100-50;             // Y
  86. static short         Hostage_monitor_w = 55;                // Width of monitor
  87. static short         Hostage_monitor_h = 41;                // Height of monitor
  88.  
  89. static fix radx, rady, rox, roy, cenx, ceny;
  90.  
  91. typedef struct blip    {
  92.     short x, y;
  93.     ubyte c;
  94. } blip;
  95.  
  96. #define MAX_BLIPS 1000
  97.  
  98. blip Blips[MAX_BLIPS];
  99. int N_blips = 0;
  100.  
  101. fix Radar_farthest_dist = (F1_0 * 20 * 15);        // 15 segments away
  102.  
  103. void radar_plot_object( object * objp, int hue )    
  104. {
  105.     ubyte flags;
  106.     g3s_point pos;
  107.     int color;
  108.     fix dist, rscale, zdist, distance;
  109.     int xpos, ypos;
  110.  
  111.     flags = g3_rotate_point(&pos,&objp->pos);
  112.     dist = vm_vec_mag_quick(&pos.p3_vec);
  113.  
  114.     // Make distance be 1.0 to 0.0, where 0.0 is 10 segments away;
  115.     if ( dist >= Radar_farthest_dist ) return;
  116.     distance = F1_0 - fixdiv( dist, Radar_farthest_dist );
  117.     color = f2i( distance*31 );
  118.  
  119.     zdist = fix_sqrt( fixmul(pos.x,pos.x)+fixmul(pos.y,pos.y) );
  120.     if (zdist < 100 ) return;        // Watch for divide overflow
  121.  
  122.     rscale = fix_acos( fixdiv(pos.z,dist) )/2;     
  123.  
  124.     xpos = f2i(fixmul( rox+fixmul(fixdiv(pos.x,zdist),rscale), radx));
  125.     ypos = f2i(fixmul( roy-fixmul(fixdiv(pos.y,zdist),rscale), rady));
  126.  
  127.     if ( xpos < Hostage_monitor_x ) xpos = Hostage_monitor_x;
  128.     if ( ypos < Hostage_monitor_y ) ypos = Hostage_monitor_y;
  129.     if ( xpos > Hostage_monitor_x+Hostage_monitor_w-1 ) xpos = Hostage_monitor_x+Hostage_monitor_w-1;
  130.     if ( ypos > Hostage_monitor_y+Hostage_monitor_h-1 ) ypos = Hostage_monitor_y+Hostage_monitor_h-1;
  131.  
  132.     Blips[N_blips].c = gr_fade_table[hue+color*256];
  133.     Blips[N_blips].x = xpos; Blips[N_blips].y = ypos;
  134.     N_blips++;
  135. }
  136.  
  137. void radar_render_frame()    
  138. {
  139.     int i,color;
  140.     object * objp;
  141.  
  142.     if (hostage_is_vclip_playing())
  143.         return;
  144.  
  145.     gr_set_current_canvas(NULL);
  146.  
  147.     gr_setcolor( BM_XRGB( 0, 31, 0 ) );
  148.     
  149.     gr_ucircle( i2f(Hostage_monitor_x+Hostage_monitor_w/2), i2f(Hostage_monitor_y+Hostage_monitor_h/2),    i2f(Hostage_monitor_w)/2);
  150.  
  151.     // Erase old blips
  152.     for (i=0; i<N_blips; i++ )    {
  153.         gr_setcolor(gr_gpixel( cockpit_bitmap[0], Blips[i].x, Blips[i].y ));
  154.         gr_upixel( Blips[i].x, Blips[i].y );
  155.     }
  156.     N_blips = 0;
  157.  
  158. //    if ( !(Players[Player_num].flags & (PLAYER_FLAGS_RADAR_ENEMIES | PLAYER_FLAGS_RADAR_POWERUPS  )) ) return;
  159.  
  160.     radx = i2f(Hostage_monitor_w*4)/2;
  161.     rady = i2f(Hostage_monitor_h*4)/2;
  162.     cenx = i2f(Hostage_monitor_x)+i2f(Hostage_monitor_w)/2;
  163.     ceny = i2f(Hostage_monitor_y)+i2f(Hostage_monitor_h)/2;
  164.  
  165.     rox = fixdiv( cenx, radx );
  166.     roy = fixdiv( ceny, rady );
  167.  
  168.     objp = Objects;
  169.     for (i=0;i<=Highest_object_index;i++) {
  170.         switch( objp->type )    {
  171.         case OBJ_PLAYER:
  172.             if ( i != Players[Player_num].objnum )    {
  173.                 if (Game_mode & GM_TEAM)
  174.                     color = get_team(i);
  175.                 else
  176.                     color = i;
  177.                 radar_plot_object( objp, gr_getcolor(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b) );
  178.             }
  179.             break;
  180. //        case OBJ_HOSTAGE:
  181. //            radar_plot_object( objp, BM_XRGB(0,31,0) );
  182. //            break;
  183. //        case OBJ_POWERUP:
  184. //            //if ( Players[Player_num].flags & PLAYER_FLAGS_RADAR_POWERUPS )
  185. //            radar_plot_object( objp, BM_XRGB(0,0,31) );
  186. //            break;
  187. //        case OBJ_ROBOT:
  188. //            //if ( Players[Player_num].flags & PLAYER_FLAGS_RADAR_ENEMIES )
  189. //            radar_plot_object( objp, BM_XRGB(31,0,0) );
  190. //            break;
  191.         default:
  192.             break;
  193.         }
  194.         objp++;
  195.     }
  196.  
  197.     // Draw new blips...
  198.     for (i=0; i<N_blips; i++ )    {
  199.         gr_setcolor( Blips[i].c );
  200.         gr_upixel( Blips[i].x, Blips[i].y );
  201.     }
  202. }
  203. 
  204.