home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / hostage.c < prev    next >
Text File  |  1998-06-08  |  16KB  |  585 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/hostage.c $
  15.  * $Revision: 2.0 $
  16.  * $Author: john $
  17.  * $Date: 1995/02/27 11:28:36 $
  18.  * 
  19.  * Code to render and manipulate hostages
  20.  * 
  21.  * $Log: hostage.c $
  22.  * Revision 2.0  1995/02/27  11:28:36  john
  23.  * New version 2.0, which has no anonymous unions, builds with
  24.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  25.  * 
  26.  * Revision 1.65  1995/02/22  13:45:54  allender
  27.  * remove anonymous unions from object structure
  28.  * 
  29.  * Revision 1.64  1995/02/13  20:34:57  john
  30.  * Lintized
  31.  * 
  32.  * Revision 1.63  1995/01/15  19:41:48  matt
  33.  * Ripped out hostage faces for registered version
  34.  * 
  35.  * Revision 1.62  1995/01/14  19:16:53  john
  36.  * First version of new bitmap paging code.
  37.  * 
  38.  * Revision 1.61  1994/12/19  16:35:09  john
  39.  * Made hoastage playback end when ship dies.
  40.  * 
  41.  * Revision 1.60  1994/12/06  16:30:41  yuan
  42.  * Localization
  43.  * 
  44.  * Revision 1.59  1994/11/30  17:32:46  matt
  45.  * Put hostage_face_clip array back in so editor would work
  46.  * 
  47.  * Revision 1.58  1994/11/30  17:22:13  matt
  48.  * Ripped out hostage faces in shareware version
  49.  * 
  50.  * Revision 1.57  1994/11/30  16:11:25  matt
  51.  * Use correct constant for hostage voice
  52.  * 
  53.  * Revision 1.56  1994/11/27  23:15:19  matt
  54.  * Made changes for new mprintf calling convention
  55.  * 
  56.  * Revision 1.55  1994/11/19  19:53:44  matt
  57.  * Added code to full support different hostage head clip & message for
  58.  * each hostage.
  59.  * 
  60.  * Revision 1.54  1994/11/19  16:35:15  matt
  61.  * Got rid of unused code, & made an array smaller
  62.  * 
  63.  * Revision 1.53  1994/11/14  12:42:03  matt
  64.  * Increased palette flash when hostage rescued
  65.  * 
  66.  * Revision 1.52  1994/10/28  14:43:09  john
  67.  * Added sound volumes to all sound calls.
  68.  * 
  69.  * Revision 1.51  1994/10/23  02:10:57  matt
  70.  * Got rid of obsolete hostage_info stuff
  71.  * 
  72.  * Revision 1.50  1994/10/22  00:08:44  matt
  73.  * Fixed up problems with bonus & game sequencing
  74.  * Player doesn't get credit for hostages unless he gets them out alive
  75.  * 
  76.  * Revision 1.49  1994/10/20  22:52:49  matt
  77.  * Fixed compiler warnings
  78.  * 
  79.  * Revision 1.48  1994/10/20  21:25:44  matt
  80.  * Took out silly scale down/scale up code for hostage anim
  81.  * 
  82.  * Revision 1.47  1994/10/20  12:47:28  matt
  83.  * Replace old save files (MIN/SAV/HOT) with new LVL files
  84.  * 
  85.  * Revision 1.46  1994/10/04  15:33:33  john
  86.  * Took out the old PLAY_SOUND??? code and replaced it
  87.  * with direct calls into digi_link_??? so that all sounds
  88.  * can be made 3d.
  89.  * 
  90.  * Revision 1.45  1994/09/28  23:10:46  matt
  91.  * Made hostage rescue do palette flash
  92.  * 
  93.  * Revision 1.44  1994/09/20  00:11:00  matt
  94.  * Finished gauges for Status Bar, including hostage video display.
  95.  * 
  96.  * Revision 1.43  1994/09/15  21:24:19  matt
  97.  * Changed system to keep track of whether & what cockpit is up
  98.  * Made hostage clip not queue when no cockpit
  99.  * 
  100.  * 
  101.  * Revision 1.42  1994/08/25  13:45:19  matt
  102.  * Made hostage vclips queue
  103.  * 
  104.  * Revision 1.41  1994/08/14  23:15:06  matt
  105.  * Added animating bitmap hostages, and cleaned up vclips a bit
  106.  * 
  107.  * Revision 1.40  1994/08/12  22:41:11  john
  108.  * Took away Player_stats; add Players array.
  109.  * 
  110.  * Revision 1.39  1994/07/14  22:06:35  john
  111.  * Fix radar/hostage vclip conflict.
  112.  * 
  113.  * Revision 1.38  1994/07/12  18:40:21  yuan
  114.  * Tweaked location of radar and hostage screen... 
  115.  * Still needs work.
  116.  * 
  117.  * 
  118.  * Revision 1.37  1994/07/07  09:52:17  john
  119.  * Moved hostage screen.
  120.  * 
  121.  * Revision 1.36  1994/07/06  15:23:52  john
  122.  * Revamped hostage sound.
  123.  * 
  124.  * Revision 1.35  1994/07/06  15:14:54  john
  125.  * Added hostage sound effect picking.
  126.  * 
  127.  * Revision 1.34  1994/07/06  13:25:33  john
  128.  * Added compress hostages functions.
  129.  * 
  130.  * Revision 1.33  1994/07/06  12:52:59  john
  131.  * Fixed compiler warnings.
  132.  * 
  133.  * Revision 1.32  1994/07/06  12:43:50  john
  134.  * Made generic messages for hostages.
  135.  * 
  136.  * Revision 1.31  1994/07/06  10:55:07  john
  137.  * New structures for hostages.
  138.  * 
  139.  * Revision 1.30  1994/07/05  12:49:09  john
  140.  * Put functionality of New Hostage spec into code.
  141.  * 
  142.  * Revision 1.29  1994/07/02  13:08:47  matt
  143.  * Increment stats when hostage rescued
  144.  * 
  145.  * Revision 1.28  1994/07/01  18:07:46  john
  146.  * y
  147.  * 
  148.  * Revision 1.27  1994/07/01  18:07:03  john
  149.  * *** empty log message ***
  150.  * 
  151.  * Revision 1.26  1994/07/01  17:55:26  john
  152.  * First version of not-working hostage system.
  153.  * 
  154.  * Revision 1.25  1994/06/27  15:53:21  john
  155.  * #define'd out the newdemo stuff
  156.  * 
  157.  * 
  158.  * Revision 1.24  1994/06/20  16:08:52  john
  159.  * Added volume control; made doors 3d sounds.
  160.  * 
  161.  * Revision 1.23  1994/06/16  10:15:32  yuan
  162.  * Fixed location of face.
  163.  * 
  164.  * Revision 1.22  1994/06/15  15:05:33  john
  165.  * *** empty log message ***
  166.  * 
  167.  * Revision 1.21  1994/06/14  21:15:20  matt
  168.  * Made rod objects draw lighted or not depending on a parameter, so the
  169.  * materialization effect no longer darkens.
  170.  * 
  171.  * Revision 1.20  1994/06/08  18:16:26  john
  172.  * Bunch of new stuff that basically takes constants out of the code
  173.  * and puts them into bitmaps.tbl.
  174.  * 
  175.  * Revision 1.19  1994/06/02  19:30:08  matt
  176.  * Moved texture-mapped rod drawing stuff (used for hostage & now for the
  177.  * materialization center) to object.c
  178.  * 
  179.  * 
  180.  */
  181.  
  182. #pragma off (unreferenced)
  183. static char rcsid[] = "$Id: hostage.c 2.0 1995/02/27 11:28:36 john Exp $";
  184. #pragma on (unreferenced)
  185.  
  186. #include <dos.h>
  187. #include <stdio.h>
  188. #include <stdlib.h>
  189. #include <string.h>
  190.  
  191. #include "error.h"
  192. #include "3d.h"
  193. #include "mono.h"
  194.  
  195. #include "inferno.h"
  196. #include "object.h"
  197. #include "game.h"
  198. #include "player.h"
  199.  
  200. #include "fireball.h"
  201. #include "gauges.h"
  202. #include "hostage.h"
  203.  
  204. #include "lighting.h"
  205.  
  206. #include "sounds.h"
  207. #include "vclip.h"
  208. #include "newdemo.h"
  209.  
  210. #include "text.h"
  211. #include "piggy.h"
  212.  
  213. //------------- Globaly used hostage variables --------------------------------------------------
  214. int                     N_hostage_types = 0;                              // Number of hostage types
  215. int                     Hostage_vclip_num[MAX_HOSTAGE_TYPES];    //vclip num for each tpye of hostage
  216. hostage_data         Hostages[MAX_HOSTAGES];                        // Data for each hostage in mine
  217.  
  218. //------------- Internally used hostage variables --------------------------------------------------
  219. static fix             Hostage_animation_time=-1;            // How long the rescue sequence has been playing - units are frames, not seconds - -1 means not playing
  220.  
  221. vclip Hostage_face_clip[MAX_HOSTAGES];
  222.  
  223. #ifdef HOSTAGE_FACES
  224.  
  225. static fix             HostagePlaybackSpeed=0;                // Calculated internally.  Frames/second of vclip.
  226. static int         Hostage_monitor_x = 204;             // X location of monitor where hostage face appears
  227. static int         Hostage_monitor_y = 152;            // Y
  228. static int         Hostage_monitor_w = 55;                // Width of monitor
  229. static int         Hostage_monitor_h = 41;                // Height of monitor
  230.  
  231. char                     Hostage_global_message[HOSTAGE_MAX_GLOBALS][HOSTAGE_MESSAGE_LEN];
  232. int                     Hostage_num_globals=0;
  233.  
  234. #define MAX_HOSTAGE_CLIPS 5
  235.  
  236. static int             Hostage_queue[MAX_HOSTAGE_CLIPS];
  237. static vclip         *Hostage_vclip=NULL;        // Used for the vclip on monitor
  238. static int            N_hostage_clips=0;
  239.  
  240. #define RESCUED_VCLIP_NUM    8
  241. #define RESCUED_SOUND_NUM    91
  242.  
  243. //starts next clip in queue
  244. void start_hostage_clip()
  245. {
  246.     int i,vclip_num,hostage_number;
  247.  
  248.     Assert(Hostage_animation_time==-1);        //none should be playing
  249.  
  250.     get_hostage_window_coords(&Hostage_monitor_x,&Hostage_monitor_y,&Hostage_monitor_w,&Hostage_monitor_h);
  251.  
  252.     hostage_number = Hostage_queue[0];            //get first in queue
  253.  
  254.     //drop the queue
  255.     N_hostage_clips--;
  256.     for (i=0;i<N_hostage_clips;i++)
  257.         Hostage_queue[i] = Hostage_queue[i+1];
  258.  
  259.     //get vclip num - either special one, or randomly-selected generic one
  260.     if ( Hostages[hostage_number].vclip_num > -1 )
  261.         vclip_num = Hostages[hostage_number].vclip_num;
  262.     else
  263.         vclip_num = RESCUED_VCLIP_NUM;
  264.  
  265.     Hostage_vclip = &Hostage_face_clip[vclip_num];
  266.  
  267.     // Set the time to be zero to start hostage vclip display sequence
  268.     Hostage_animation_time = 0;
  269.  
  270.     // Calculate the frame/second of the playback
  271.     HostagePlaybackSpeed = fixdiv(F1_0,Hostage_vclip->frame_time);
  272.  
  273.     // Start the sound for this hostage
  274.     if ( Hostage_vclip->sound_num > -1 )
  275.         digi_play_sample( Hostage_vclip->sound_num, F1_0 );
  276.  
  277. }
  278.  
  279. //add this hostage's clip to the queue
  280. void queue_hostage_clip(int hostage_num)
  281. {
  282.     if ((Cockpit_mode!=CM_FULL_COCKPIT && Cockpit_mode!=CM_STATUS_BAR) || N_hostage_clips>=MAX_HOSTAGE_CLIPS)
  283.         return;        //no cockpit, or queue is full
  284.  
  285.     Hostage_queue[N_hostage_clips] = hostage_num;
  286.  
  287.     N_hostage_clips++;
  288.  
  289.     if (Hostage_animation_time<=0)        //none playing?
  290.         start_hostage_clip();                //..start this one!
  291.  
  292. }
  293.  
  294. //current clip is done, stop it
  295. void stop_hostage_clip()
  296. {
  297.     get_hostage_window_coords(&Hostage_monitor_x,&Hostage_monitor_y,&Hostage_monitor_w,&Hostage_monitor_h);
  298.  
  299.     nosound();                                // Turn off sound        
  300.     Hostage_animation_time = -1;        // Consider this vclip done
  301.  
  302.     if (N_hostage_clips)            //more in queue?
  303.         start_hostage_clip();
  304.  
  305.     return;
  306. }
  307.  
  308. void stop_all_hostage_clips()
  309. {
  310.     N_hostage_clips = 0;
  311.     Hostage_animation_time=-1;
  312. }
  313.  
  314. int hostage_is_vclip_playing()
  315. {
  316.     if (Hostage_animation_time>=0)
  317.         return 1;
  318.     else
  319.         return 0;
  320. }
  321.  
  322. #endif
  323.  
  324. //---------------- Initializes the hostage system ----------------------------------------------------
  325. void hostage_init()
  326. {
  327.     Hostage_animation_time=-1;
  328. }
  329.  
  330. //-------------- Renders a hostage ----------------------------------------------------------------
  331. void draw_hostage(object *obj)
  332. {
  333.     Assert( obj->id < MAX_HOSTAGES );
  334.  
  335.     draw_object_tmap_rod(obj,Vclip[obj->rtype.vclip_info.vclip_num].frames[obj->rtype.vclip_info.framenum],1);
  336.  
  337. }
  338.  
  339. //------------- Called once when a hostage is rescued ------------------------------------------
  340. void hostage_rescue( int hostage_number )
  341. {
  342.     //mprintf( (0, "Rescued hostage %d", hostage_number ));
  343.  
  344.     if ( (hostage_number<0) || (hostage_number>=MAX_HOSTAGES) )    {
  345.             Int3();        // Get John!
  346.             return;
  347.     }
  348.  
  349.     PALETTE_FLASH_ADD(0,0,25);        //small blue flash
  350.  
  351.     Players[Player_num].hostages_on_board++;
  352.  
  353.     // Do an audio effect
  354.     if ( Newdemo_state != ND_STATE_PLAYBACK )
  355.         digi_play_sample( SOUND_HOSTAGE_RESCUED, F1_0 );
  356.  
  357.  #ifndef HOSTAGE_FACES
  358.  
  359.     HUD_init_message(TXT_HOSTAGE_RESCUED);
  360.  
  361.  #else
  362.  
  363.     // Show the text message
  364.     if ( strlen(Hostages[hostage_number].text) ) 
  365.         gauge_message("%s", Hostages[hostage_number].text );
  366.     else    {
  367.         if ( Hostage_num_globals > 0 )    {
  368.             int mn;
  369.             mn = (rand()*Hostage_num_globals)/RAND_MAX;
  370.             if ( mn>=0 && mn < Hostage_num_globals )
  371.                 gauge_message("%s", &Hostage_global_message[mn][0] );
  372.         }
  373.     }
  374.  
  375.     if ( Newdemo_state == ND_STATE_RECORDING )
  376.         newdemo_record_hostage_rescued( hostage_number );
  377.  
  378.     queue_hostage_clip(hostage_number);
  379.  #endif
  380. }
  381.  
  382. #ifdef HOSTAGE_FACES
  383.  
  384. //------------- Called once per frame to do the hostage effects --------------------------------
  385. //returns true if something drew
  386. int do_hostage_effects()
  387. {
  388.     int bitmapnum;
  389.  
  390.     // Don't do the effect if the time is <= 0
  391.     if ( Hostage_animation_time < 0 )
  392.         return 0;
  393.  
  394.     // Find next bitmap in the vclip
  395.     bitmapnum = f2i(Hostage_animation_time);
  396.     //mprintf( (0, " Time: %x  Bitmap: %d\n", Hostage_animation_time, bitmapnum  ));
  397.  
  398.     // Check if vclip is done playing.
  399.     if (bitmapnum >= Hostage_vclip->num_frames)        {
  400.         stop_hostage_clip();
  401.  
  402.         if (Hostage_animation_time >= 0)        //new clip
  403.             bitmapnum = f2i(Hostage_animation_time);
  404.         else
  405.             return 0;        //no new one
  406.     }
  407.  
  408.     get_hostage_window_coords(&Hostage_monitor_x,&Hostage_monitor_y,&Hostage_monitor_w,&Hostage_monitor_h);
  409.  
  410.     PIGGY_PAGE_IN(Hostage_vclip->frames[bitmapnum]);    
  411.     gr_bitmap(Hostage_monitor_x,Hostage_monitor_y,Hostage_vclip->frames[bitmapnum]);
  412.  
  413.     // Increment the hostage rescue time scaled to playback speed.
  414.     // This means that the integer part of the fix is the frame number
  415.     // of the animation.
  416.  
  417.     Hostage_animation_time += fixmul(FrameTime,HostagePlaybackSpeed);
  418.  
  419.     return 1;
  420. }
  421.  
  422. #endif
  423.  
  424. #define LINEBUF_SIZE 100
  425.  
  426. //------------------- Useful macros and variables ---------------
  427. #define REMOVE_EOL(s)        hostage_remove_char((s),'\n')
  428. #define REMOVE_COMMENTS(s)    hostage_remove_char((s),';')
  429.  
  430. void hostage_remove_char( char * s, char c )
  431. {
  432.     char *p;
  433.     p = strchr(s,c);
  434.     if (p) *p = '\0';
  435. }
  436.  
  437. int hostage_is_valid( int hostage_num )    {
  438.     if ( hostage_num < 0 ) return 0;
  439.     if ( hostage_num >= MAX_HOSTAGES ) return 0;
  440.     if ( Hostages[hostage_num].objnum < 0 ) return 0;
  441.     if ( Hostages[hostage_num].objnum > Highest_object_index ) return 0;
  442.     if ( Objects[Hostages[hostage_num].objnum].type != OBJ_HOSTAGE ) return 0;
  443.     if ( Objects[Hostages[hostage_num].objnum].signature != Hostages[hostage_num].objsig ) return 0;
  444.     if ( Objects[Hostages[hostage_num].objnum].id != hostage_num) return 0;
  445.     return 1;
  446. }
  447.  
  448. int hostage_object_is_valid( int objnum )    {
  449.     if ( objnum < 0 ) return 0;
  450.     if ( objnum > Highest_object_index ) return 0;
  451.     if ( Objects[objnum].type != OBJ_HOSTAGE ) return 0;
  452.     return hostage_is_valid(Objects[objnum].id);
  453. }
  454.  
  455.  
  456. int hostage_get_next_slot()    {
  457.     int i;
  458.     for (i=0; i<MAX_HOSTAGES; i++ )    {
  459.         if (!hostage_is_valid(i))
  460.             return i;
  461.     }
  462.     return MAX_HOSTAGES;
  463. }
  464.  
  465. void hostage_init_info( int objnum )    {
  466.     int i;
  467.  
  468.     i = hostage_get_next_slot();
  469.     Assert( i > -1 );
  470.     Hostages[i].objnum = objnum;
  471.     Hostages[i].objsig = Objects[objnum].signature;
  472.     //Hostages[i].type = 0;
  473.     Hostages[i].vclip_num = -1;
  474.     //Hostages[i].sound_num = -1;
  475.     strcpy( Hostages[i].text, "\0" );
  476.     Objects[objnum].id = i;
  477. }
  478.  
  479. void hostage_init_all()
  480. {
  481.     int i;
  482.  
  483.     // Initialize all their values...
  484.     for (i=0; i<MAX_HOSTAGES; i++ )    {
  485.         Hostages[i].objnum = -1;
  486.         Hostages[i].objsig = -1;
  487.         //Hostages[i].type = 0;
  488.         Hostages[i].vclip_num = -1;
  489.         //Hostages[i].sound_num = -1;
  490.         strcpy( Hostages[i].text, "\0" );
  491.     }
  492.  
  493.     //@@hostage_read_global_messages();
  494. }
  495.  
  496.  
  497. #ifdef EDITOR
  498.  
  499. void hostage_compress_all()    {
  500.     int i,newslot;
  501.     
  502.     for (i=0; i<MAX_HOSTAGES; i++ )    {
  503.         if ( hostage_is_valid(i) )    {
  504.             newslot = hostage_get_next_slot();
  505.             if ( newslot < i )    {
  506.                 mprintf( (0, "Moved hostage %d to %d\n", i, newslot ));
  507.                 Hostages[newslot] = Hostages[i];
  508.                 Objects[Hostages[newslot].objnum].id = newslot;
  509.                 Hostages[i].objnum = -1;
  510.                 i = 0;        // start over
  511.             }
  512.         }
  513.     }
  514.  
  515.     mprintf( (0, "Valid hostages:\n" ));
  516.     for (i=0; i<MAX_HOSTAGES; i++ )    {
  517.         if ( hostage_is_valid(i) )    
  518.             mprintf( (0, "%d\n", i ));
  519.     }
  520. }
  521.  
  522. #endif
  523.  
  524. //@@#include "nocfile.h"
  525. //@@
  526. //@@void hostage_read_global_messages()    {
  527. //@@    char *text_string;
  528. //@@    FILE * fp;
  529. //@@    char    inputline[LINEBUF_SIZE];
  530. //@@
  531. //@@    Hostage_num_globals=0;
  532. //@@
  533. //@@    fp = fopen( "GENERIC.HOT", "rt" );
  534. //@@    if ( fp == NULL ) return;
  535. //@@
  536. //@@    while (fgets(inputline, LINEBUF_SIZE, fp )) {
  537. //@@        
  538. //@@        REMOVE_EOL(inputline);
  539. //@@        REMOVE_COMMENTS(inputline);
  540. //@@
  541. //@@        text_string = strchr( inputline, '.' );
  542. //@@
  543. //@@        if ( text_string )    {
  544. //@@            *text_string = 0;    // turn period into end of string
  545. //@@
  546. //@@            text_string++;    // skip over period
  547. //@@            // Remove white space from beginning of string.
  548. //@@            while( (*text_string == ' ') || (*text_string == '\t') )
  549. //@@                text_string++;
  550. //@@            
  551. //@@            mprintf( (0, "Generic hostage message %d, text is '%s'\n", Hostage_num_globals, text_string ));
  552. //@@            strncpy( &Hostage_global_message[Hostage_num_globals][0], text_string, HOSTAGE_MESSAGE_LEN );
  553. //@@            Hostage_num_globals++;
  554. //@@
  555. //@@            Assert( Hostage_num_globals <= HOSTAGE_MAX_GLOBALS );
  556. //@@        }
  557. //@@    }
  558. //@@    fclose(fp);
  559. //@@}
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584. 
  585.