home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / switch.c < prev    next >
Text File  |  1998-06-08  |  11KB  |  408 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/switch.c $
  15.  * $Revision: 2.1 $
  16.  * $Author: john $
  17.  * $Date: 1995/03/21 14:39:08 $
  18.  * 
  19.  * New Triggers and Switches.
  20.  * 
  21.  * $Log: switch.c $
  22.  * Revision 2.1  1995/03/21  14:39:08  john
  23.  * Ifdef'd out the NETWORK code.
  24.  * 
  25.  * Revision 2.0  1995/02/27  11:28:41  john
  26.  * New version 2.0, which has no anonymous unions, builds with
  27.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  28.  * 
  29.  * Revision 1.51  1995/01/31  15:26:23  rob
  30.  * Don't trigger matcens in anarchy games.
  31.  * 
  32.  * Revision 1.50  1995/01/26  12:18:26  rob
  33.  * Changed network_do_frame call.
  34.  * 
  35.  * Revision 1.49  1995/01/18  18:50:35  allender
  36.  * don't process triggers if in demo playback mode.  Fix for Rob to only do
  37.  * multi_send_endlevel_start if in multi player game
  38.  * 
  39.  * Revision 1.48  1995/01/13  11:59:40  rob
  40.  * Added palette fade after secret level exit.
  41.  * 
  42.  * Revision 1.47  1995/01/12  17:00:41  rob
  43.  * Fixed a problem with switches and secret levels.
  44.  * 
  45.  * Revision 1.46  1995/01/12  13:35:11  rob
  46.  * Added data flush after secret level exit.
  47.  * 
  48.  * Revision 1.45  1995/01/03  15:25:11  rob
  49.  * Fixed a compile error.
  50.  * 
  51.  * Revision 1.44  1995/01/03  15:12:02  rob
  52.  * Adding multiplayer switching.
  53.  * 
  54.  * Revision 1.43  1994/11/29  16:52:12  yuan
  55.  * Removed some obsolete commented out code.
  56.  * 
  57.  * Revision 1.42  1994/11/27  23:15:07  matt
  58.  * Made changes for new mprintf calling convention
  59.  * 
  60.  * Revision 1.41  1994/11/22  18:36:45  rob
  61.  * Added new hook for endlevel for secret doors.
  62.  * 
  63.  * Revision 1.40  1994/11/21  17:29:43  matt
  64.  * Cleaned up sequencing & game saving for secret levels
  65.  * 
  66.  * Revision 1.39  1994/11/19  15:20:32  mike
  67.  * rip out unused code and data
  68.  * 
  69.  * Revision 1.38  1994/10/25  16:09:52  yuan
  70.  * Fixed byte bug.
  71.  * 
  72.  * Revision 1.37  1994/10/24  16:05:28  matt
  73.  * Removed clear of fuelcen_control_center_destroyed
  74.  * 
  75.  * Revision 1.36  1994/10/08  14:21:13  matt
  76.  * Added include
  77.  * 
  78.  * Revision 1.35  1994/10/07  12:34:09  matt
  79.  * Added code fot going to/from secret levels
  80.  * 
  81.  * Revision 1.34  1994/10/05  15:16:10  rob
  82.  * Used to be that only player #0 could trigger switches, now only the
  83.  * LOCAL player can do it (and he's expected to tell the other guy with
  84.  * a com message if its important!)
  85.  * 
  86.  * Revision 1.33  1994/09/24  17:42:03  mike
  87.  * Kill temporary version of function written by Yuan, replaced by MK.
  88.  * 
  89.  * Revision 1.32  1994/09/24  17:10:00  yuan
  90.  * Added Matcen triggers.
  91.  * 
  92.  * Revision 1.31  1994/09/23  18:02:21  yuan
  93.  * Completed wall checking.
  94.  * 
  95.  * Revision 1.30  1994/08/19  20:09:41  matt
  96.  * Added end-of-level cut scene with external scene
  97.  * 
  98.  * Revision 1.29  1994/08/18  10:47:36  john
  99.  * Cleaned up game sequencing and player death stuff
  100.  * in preparation for making the player explode into
  101.  * pieces when dead.
  102.  * 
  103.  * Revision 1.28  1994/08/12  22:42:11  john
  104.  * Took away Player_stats; added Players array.
  105.  * 
  106.  * Revision 1.27  1994/07/02  13:50:44  matt
  107.  * Cleaned up includes
  108.  * 
  109.  * Revision 1.26  1994/06/27  16:32:25  yuan
  110.  * Commented out incomplete code...
  111.  * 
  112.  * Revision 1.25  1994/06/27  15:53:27  john
  113.  * #define'd out the newdemo stuff
  114.  * 
  115.  * 
  116.  * Revision 1.24  1994/06/27  15:10:04  yuan
  117.  * Might mess up triggers.
  118.  * 
  119.  * Revision 1.23  1994/06/24  17:01:43  john
  120.  * Add VFX support; Took Game Sequencing, like EndGame and stuff and
  121.  * took it out of game.c and into gameseq.c
  122.  * 
  123.  * Revision 1.22  1994/06/16  16:20:15  john
  124.  * Made player start out in physics mode; Neatend up game loop a bit.
  125.  * 
  126.  * Revision 1.21  1994/06/15  14:57:22  john
  127.  * Added triggers to demo recording.
  128.  * 
  129.  * Revision 1.20  1994/06/10  17:44:25  mike
  130.  * Assert on result of find_connect_side == -1
  131.  * 
  132.  * Revision 1.19  1994/06/08  10:20:15  yuan
  133.  * Removed unused testing.
  134.  * 
  135.  * 
  136.  * Revision 1.18  1994/06/07  13:10:48  yuan
  137.  * Fixed bug in check trigger... Still working on other bugs.
  138.  * 
  139.  * Revision 1.17  1994/05/30  20:22:04  yuan
  140.  * New triggers.
  141.  * 
  142.  * Revision 1.16  1994/05/27  10:32:46  yuan
  143.  * New dialog boxes (Walls and Triggers) added.
  144.  * 
  145.  * 
  146.  * Revision 1.15  1994/05/25  18:06:46  yuan
  147.  * Making new dialog box controls for walls and triggers.
  148.  * 
  149.  * Revision 1.14  1994/05/10  19:05:32  yuan
  150.  * Made end of level flag rather than menu popping up
  151.  * 
  152.  * Revision 1.13  1994/04/29  15:05:25  yuan
  153.  * Added menu pop-up at exit trigger.
  154.  * 
  155.  */
  156.  
  157.  
  158. #pragma off (unreferenced)
  159. static char rcsid[] = "$Id: switch.c 2.1 1995/03/21 14:39:08 john Exp $";
  160. #pragma on (unreferenced)
  161.  
  162. #include <stdio.h>
  163. #include <stdlib.h>
  164. #include <math.h>
  165. #include <string.h>
  166.  
  167. #include "gauges.h"
  168. #include "game.h"
  169. #include "switch.h"
  170. #include "inferno.h"
  171. #include "editor\editor.h"
  172. #include "segment.h"
  173. #include "error.h"
  174. #include "gameseg.h"
  175. #include "mono.h"
  176. #include "wall.h"
  177. #include "texmap.h"
  178. #include "fuelcen.h"
  179. #include "newdemo.h"
  180. #include "player.h"
  181. #include "endlevel.h"
  182. #include "gameseq.h"
  183. #include "multi.h"
  184. #include "network.h"
  185. #include "palette.h"
  186.  
  187. trigger Triggers[MAX_TRIGGERS];
  188. int Num_triggers;
  189.  
  190. //link Links[MAX_WALL_LINKS];
  191. //int Num_links;
  192.  
  193. #ifdef EDITOR
  194. fix trigger_time_count=F1_0;
  195.  
  196. //-----------------------------------------------------------------
  197. // Initializes all the switches.
  198. void trigger_init()
  199. {
  200.     int i;
  201.  
  202.     Num_triggers = 0;
  203. //    Num_links = 0;    
  204.  
  205.     for (i=0;i<MAX_TRIGGERS;i++)
  206.         {
  207.         Triggers[i].type = 0;
  208.         Triggers[i].flags = 0;
  209.         Triggers[i].value = 0;
  210.         Triggers[i].link_num = -1;
  211.         Triggers[i].time = -1;
  212.         }
  213.  
  214. //    for (i=0;i<MAX_WALL_LINKS;i++)
  215. //        Links[i].num_walls = 0;
  216. }
  217. #endif
  218.  
  219. //-----------------------------------------------------------------
  220. // Executes a link, attached to a trigger.
  221. // Toggles all walls linked to the switch.
  222. // Opens doors, Blasts blast walls, turns off illusions.
  223. void do_link(byte trigger_num)
  224. {
  225.     int i;
  226.  
  227.     mprintf((0, "Door link!\n"));
  228.  
  229.     if (trigger_num != -1) {
  230.         for (i=0;i<Triggers[trigger_num].num_links;i++) {
  231.             wall_toggle(&Segments[Triggers[trigger_num].seg[i]], Triggers[trigger_num].side[i]); 
  232.             mprintf((0," trigger_num %d : seg %d, side %d\n", 
  233.                 trigger_num, Triggers[trigger_num].seg[i], Triggers[trigger_num].side[i]));
  234.           }
  235.       }
  236. }
  237.  
  238. void do_matcen(byte trigger_num)
  239. {
  240.     int i;
  241.  
  242.     mprintf((0, "Matcen link!\n"));
  243.  
  244.     if (trigger_num != -1) {
  245.         for (i=0;i<Triggers[trigger_num].num_links;i++) {
  246.             trigger_matcen(Triggers[trigger_num].seg[i] ); 
  247.             mprintf((0," trigger_num %d : seg %d\n", 
  248.                 trigger_num, Triggers[trigger_num].seg[i]));
  249.           }
  250.       }
  251. }
  252.  
  253.     
  254. void do_il_on(byte trigger_num)
  255. {
  256.     int i;
  257.  
  258.     mprintf((0, "Illusion ON\n"));
  259.  
  260.     if (trigger_num != -1) {
  261.         for (i=0;i<Triggers[trigger_num].num_links;i++) {
  262.             wall_illusion_on(&Segments[Triggers[trigger_num].seg[i]], Triggers[trigger_num].side[i]); 
  263.             mprintf((0," trigger_num %d : seg %d, side %d\n", 
  264.                 trigger_num, Triggers[trigger_num].seg[i], Triggers[trigger_num].side[i]));
  265.           }
  266.       }
  267. }
  268.  
  269. void do_il_off(byte trigger_num)
  270. {
  271.     int i;
  272.     
  273.     mprintf((0, "Illusion OFF\n"));
  274.  
  275.     if (trigger_num != -1) {
  276.         for (i=0;i<Triggers[trigger_num].num_links;i++) {
  277.             wall_illusion_off(&Segments[Triggers[trigger_num].seg[i]], Triggers[trigger_num].side[i]); 
  278.             mprintf((0," trigger_num %d : seg %d, side %d\n", 
  279.                 trigger_num, Triggers[trigger_num].seg[i], Triggers[trigger_num].side[i]));
  280.           }
  281.       }
  282. }
  283.  
  284. int check_trigger_sub(int trigger_num, int pnum)
  285. {
  286.  
  287.     if (pnum == Player_num) {
  288.         if (Triggers[trigger_num].flags & TRIGGER_SHIELD_DAMAGE) {
  289.             Players[Player_num].shields -= Triggers[trigger_num].value;
  290.             mprintf((0,"BZZT!\n"));
  291.         }
  292.  
  293.         if (Triggers[trigger_num].flags & TRIGGER_EXIT) {
  294.             start_endlevel_sequence();
  295.             mprintf((0,"WOOHOO! (leaving the mine!)\n"));
  296.         }
  297.  
  298.         if (Triggers[trigger_num].flags & TRIGGER_SECRET_EXIT) {
  299.             if (Newdemo_state == ND_STATE_RECORDING)        // stop demo recording
  300.                 Newdemo_state = ND_STATE_PAUSED;
  301.  
  302.             Fuelcen_control_center_destroyed = 0;
  303.             mprintf((0,"Exiting to secret level\n"));
  304.             #ifdef NETWORK
  305.             if (Game_mode & GM_MULTI)
  306.                 multi_send_endlevel_start(1);
  307.             #endif
  308. #ifdef NETWORK
  309.             if (Game_mode & GM_NETWORK)
  310.                 network_do_frame(1, 1);
  311. #endif
  312.             gr_palette_fade_out(gr_palette, 32, 0);
  313.             PlayerFinishedLevel(1);        //1 means go to secret level
  314.             return 1;
  315.         }
  316.  
  317.         if (Triggers[trigger_num].flags & TRIGGER_ENERGY_DRAIN) {
  318.             Players[Player_num].energy -= Triggers[trigger_num].value;
  319.             mprintf((0,"SLURP!\n"));
  320.         }
  321.     }
  322.  
  323.     if (Triggers[trigger_num].flags & TRIGGER_CONTROL_DOORS) {
  324.         mprintf((0,"D"));
  325.         do_link(trigger_num);
  326.     }
  327.  
  328.     if (Triggers[trigger_num].flags & TRIGGER_MATCEN) {
  329.         if (!(Game_mode & GM_MULTI) || (Game_mode & GM_MULTI_ROBOTS))
  330.             do_matcen(trigger_num);
  331.     }
  332.  
  333.     if (Triggers[trigger_num].flags & TRIGGER_ILLUSION_ON) {
  334.         mprintf((0,"I"));
  335.         do_il_on(trigger_num);
  336.     }
  337.  
  338.     if (Triggers[trigger_num].flags & TRIGGER_ILLUSION_OFF) {
  339. //        Triggers[trigger_num].time = TRIGGER_DELAY_DOOR;
  340.         mprintf((0,"i"));
  341.         do_il_off(trigger_num);
  342.     }
  343.     return 0;
  344. }
  345.  
  346. //-----------------------------------------------------------------
  347. // Checks for a trigger whenever an object hits a trigger side.
  348. void check_trigger(segment *seg, short side, short objnum)
  349. {
  350.     int wall_num, trigger_num, ctrigger_num;
  351.     segment *csegp;
  352.      short cside;
  353.  
  354. //    mprintf(0,"T");
  355.  
  356.     if (objnum == Players[Player_num].objnum) {
  357.  
  358. //        if ( Newdemo_state == ND_STATE_RECORDING )
  359. //            newdemo_record_trigger( seg-Segments, side, objnum );
  360.  
  361.         if ( Newdemo_state == ND_STATE_PLAYBACK )
  362.             return;
  363.  
  364.         wall_num = seg->sides[side].wall_num;
  365.         if ( wall_num == -1 ) return;
  366.         
  367.         trigger_num = Walls[wall_num].trigger;
  368.  
  369.         if (trigger_num == -1)
  370.             return;
  371.  
  372.         if (check_trigger_sub(trigger_num, Player_num))
  373.             return;
  374.  
  375.         if (Triggers[trigger_num].flags & TRIGGER_ONE_SHOT) {
  376.             Triggers[trigger_num].flags &= ~TRIGGER_ON;
  377.     
  378.             csegp = &Segments[seg->children[side]];
  379.             cside = find_connect_side(seg, csegp);
  380.             Assert(cside != -1);
  381.         
  382.             wall_num = csegp->sides[cside].wall_num;
  383.             if ( wall_num == -1 ) return;
  384.             
  385.             ctrigger_num = Walls[wall_num].trigger;
  386.     
  387.             Triggers[ctrigger_num].flags &= ~TRIGGER_ON;
  388.         }
  389. #ifndef SHAREWARE
  390. #ifdef NETWORK
  391.         if (Game_mode & GM_MULTI)
  392.             multi_send_trigger(trigger_num);
  393. #endif
  394. #endif
  395.     }
  396. }
  397.   
  398. void triggers_frame_process()
  399. {
  400.     int i;
  401.  
  402.     for (i=0;i<Num_triggers;i++)
  403.         if (Triggers[i].time >= 0)
  404.             Triggers[i].time -= FrameTime;
  405. }
  406.  
  407. 
  408.