home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / controls.c < prev    next >
Text File  |  1998-06-08  |  10KB  |  287 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/controls.c $
  15.  * $Revision: 2.0 $
  16.  * $Author: john $
  17.  * $Date: 1995/02/27 11:27:11 $
  18.  * 
  19.  * Code for controlling player movement
  20.  * 
  21.  * $Log: controls.c $
  22.  * Revision 2.0  1995/02/27  11:27:11  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.50  1995/02/22  14:11:19  allender
  27.  * remove anonymous unions from object structure
  28.  * 
  29.  * Revision 1.49  1994/12/15  13:04:10  mike
  30.  * Replace Players[Player_num].time_total references with GameTime.
  31.  * 
  32.  * Revision 1.48  1994/11/27  23:12:13  matt
  33.  * Made changes for new mprintf calling convention
  34.  * 
  35.  * Revision 1.47  1994/11/25  22:15:54  matt
  36.  * Added asserts to try to trap frametime < 0 bug
  37.  * 
  38.  * Revision 1.46  1994/11/16  11:25:40  matt
  39.  * Took out int3's since I determined that the errors are caused by neg frametime
  40.  * 
  41.  * Revision 1.45  1994/11/15  13:07:23  matt
  42.  * Added int3's to try to trap bug
  43.  * 
  44.  * Revision 1.44  1994/10/14  16:18:12  john
  45.  * Made Assert that the object was player just nicely exit
  46.  * the function.
  47.  * 
  48.  * Revision 1.43  1994/10/13  11:35:25  john
  49.  * Made Thrustmaster FCS Hat work.  Put a background behind the
  50.  * keyboard configure.  Took out turn_sensitivity.  Changed sound/config
  51.  * menu to new menu. Made F6 be calibrate joystick.
  52.  * 
  53.  * Revision 1.42  1994/09/29  11:22:02  mike
  54.  * Zero thrust when player dies.
  55.  * 
  56.  * Revision 1.41  1994/09/16  13:10:30  mike
  57.  * Hook in afterburner stuff.
  58.  * 
  59.  * Revision 1.40  1994/09/14  22:21:54  matt
  60.  * Avoid post-death assert
  61.  * 
  62.  * Revision 1.39  1994/09/11  20:30:27  matt
  63.  * Cleaned up thrust vars, changing a few names
  64.  * 
  65.  * Revision 1.38  1994/09/10  15:46:31  john
  66.  * First version of new keyboard configuration.
  67.  * 
  68.  * Revision 1.37  1994/09/07  15:58:12  mike
  69.  * Check for player dead in controls so you can't fire or move after dead, logical, huh?
  70.  * 
  71.  * Revision 1.36  1994/09/06  14:51:56  john
  72.  * Added sensitivity adjustment, fixed bug with joystick button not
  73.  * staying down.
  74.  * 
  75.  * Revision 1.35  1994/09/01  15:43:26  john
  76.  * Put pitch bak like it was.
  77.  * 
  78.  * Revision 1.34  1994/08/31  18:59:35  john
  79.  * Made rotthrust back like it was.
  80.  * 
  81.  * Revision 1.33  1994/08/31  18:49:17  john
  82.  * Slowed Maxrothrust a bit,
  83.  * ..
  84.  * 
  85.  * Revision 1.32  1994/08/31  18:32:05  john
  86.  * Lower max rotational thrust
  87.  * 
  88.  * Revision 1.31  1994/08/29  21:18:27  john
  89.  * First version of new keyboard/oystick remapping stuff.
  90.  * 
  91.  * Revision 1.30  1994/08/29  16:18:30  mike
  92.  * trap divide overflow.
  93.  * 
  94.  * Revision 1.29  1994/08/26  14:40:45  john
  95.  * *** empty log message ***
  96.  * 
  97.  * Revision 1.28  1994/08/26  12:23:50  john
  98.  * MAde joystick read up to 15 times per second max.
  99.  * 
  100.  * Revision 1.27  1994/08/26  10:50:59  john
  101.  * Took out Controls_always_stopped.
  102.  * 
  103.  * Revision 1.26  1994/08/26  10:47:27  john
  104.  * *** empty log message ***
  105.  * 
  106.  * Revision 1.25  1994/08/26  10:46:50  john
  107.  * New version of controls.
  108.  * 
  109.  * Revision 1.24  1994/08/25  19:41:44  john
  110.  * *** empty log message ***
  111.  * 
  112.  * Revision 1.23  1994/08/25  18:44:55  john
  113.  * *** empty log message ***
  114.  * 
  115.  * Revision 1.22  1994/08/25  18:43:46  john
  116.  * First revision of new control code.
  117.  * 
  118.  * Revision 1.21  1994/08/24  20:02:46  john
  119.  * Added cyberman support; made keys work key_down_time
  120.  * returning seconds instead of milliseconds,.
  121.  * 
  122.  * 
  123.  * Revision 1.20  1994/08/24  19:00:27  john
  124.  * Changed key_down_time to return fixed seconds instead of
  125.  * milliseconds.
  126.  * 
  127.  * Revision 1.19  1994/08/19  15:22:12  mike
  128.  * Fix divide overflow in sliding.
  129.  * 
  130.  * Revision 1.18  1994/08/19  14:42:50  john
  131.  * Added joystick sensitivity.
  132.  * 
  133.  * Revision 1.17  1994/08/17  16:50:01  john
  134.  * Added damaging fireballs, missiles.
  135.  * 
  136.  * Revision 1.16  1994/08/12  22:41:54  john
  137.  * Took away Player_stats; added Players array.
  138.  * 
  139.  * Revision 1.15  1994/08/09  16:03:56  john
  140.  * Added network players to editor.
  141.  * 
  142.  * Revision 1.14  1994/07/28  12:33:31  matt
  143.  * Made sliding use thrust, rather than changing velocity directly
  144.  * 
  145.  * Revision 1.13  1994/07/27  20:53:21  matt
  146.  * Added rotational drag & thrust, so turning now has momemtum like moving
  147.  * 
  148.  * Revision 1.12  1994/07/25  10:24:06  john
  149.  * Victor stuff.
  150.  * 
  151.  * Revision 1.11  1994/07/22  17:53:16  john
  152.  * Added better victormax support
  153.  * 
  154.  * Revision 1.10  1994/07/21  21:31:29  john
  155.  * First cheapo version of VictorMaxx tracking.
  156.  * 
  157.  * Revision 1.9  1994/07/15  15:16:18  john
  158.  * Fixed some joystick stuff.
  159.  * 
  160.  * Revision 1.8  1994/07/15  09:32:09  john
  161.  * Changes player movement.
  162.  * 
  163.  * Revision 1.7  1994/07/13  00:14:58  matt
  164.  * Moved all (or nearly all) of the values that affect player movement to 
  165.  * bitmaps.tbl
  166.  * 
  167.  * Revision 1.6  1994/07/12  12:40:14  matt
  168.  * Revamped physics system
  169.  * 
  170.  * Revision 1.5  1994/07/02  13:50:39  matt
  171.  * Cleaned up includes
  172.  * 
  173.  * Revision 1.4  1994/07/01  10:55:25  john
  174.  * Added analog joystick throttle
  175.  * 
  176.  * Revision 1.3  1994/06/30  20:04:28  john
  177.  * Added -joydef support.
  178.  * 
  179.  * Revision 1.2  1994/06/30  19:01:58  matt
  180.  * Moved flying controls code from physics.c to controls.c
  181.  * 
  182.  * Revision 1.1  1994/06/30  18:41:25  matt
  183.  * Initial revision
  184.  * 
  185.  * 
  186.  */
  187.  
  188.  
  189. #pragma off (unreferenced)
  190. static char rcsid[] = "$Id: controls.c 2.0 1995/02/27 11:27:11 john Exp $";
  191. #pragma on (unreferenced)
  192.  
  193. #include <stdlib.h>
  194.  
  195. #include "mono.h"
  196. #include "key.h"
  197. #include "joy.h"
  198. #include "timer.h"
  199. #include "error.h"
  200.  
  201. #include "inferno.h"
  202. #include "game.h"
  203. #include "object.h"
  204. #include "player.h"
  205.  
  206. #include "controls.h"
  207. #include "joydefs.h"
  208. #include "victor.h"
  209. #include "render.h"
  210. #include "args.h"
  211. #include "palette.h"
  212. #include "mouse.h"
  213. #include "kconfig.h"
  214.  
  215. //look at keyboard, mouse, joystick, CyberMan, whatever, and set 
  216. //physics vars rotvel, velocity
  217.  
  218. void read_flying_controls( object * obj )
  219. {
  220.     fix    afterburner_thrust;
  221.  
  222.     Assert(FrameTime > 0);         //Get MATT if hit this!
  223.  
  224.     if (Player_is_dead) {
  225.         vm_vec_zero(&obj->mtype.phys_info.rotthrust);
  226.         vm_vec_zero(&obj->mtype.phys_info.thrust);
  227.         return;
  228.     }
  229.  
  230.     if ((obj->type!=OBJ_PLAYER) || (obj->id!=Player_num)) return;    //references to player_ship require that this obj be the player
  231.  
  232.     //    Couldn't the "50" in the next three lines be changed to "64" with no ill effect?
  233.     obj->mtype.phys_info.rotthrust.x = Controls.pitch_time;
  234.     obj->mtype.phys_info.rotthrust.y = Controls.heading_time;
  235.     obj->mtype.phys_info.rotthrust.z = Controls.bank_time;
  236.  
  237. //    mprintf( (0, "Rot thrust = %.3f,%.3f,%.3f\n", f2fl(obj->mtype.phys_info.rotthrust.x),f2fl(obj->mtype.phys_info.rotthrust.y), f2fl(obj->mtype.phys_info.rotthrust.z) ));
  238.  
  239.     afterburner_thrust = 0;
  240.     if (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER)
  241.         afterburner_thrust = FrameTime;
  242.  
  243.     // Set object's thrust vector for forward/backward
  244.     vm_vec_copy_scale(&obj->mtype.phys_info.thrust,&obj->orient.fvec, Controls.forward_thrust_time + afterburner_thrust );
  245.     
  246.     // slide left/right
  247.     vm_vec_scale_add2(&obj->mtype.phys_info.thrust,&obj->orient.rvec, Controls.sideways_thrust_time );
  248.  
  249.     // slide up/down
  250.     vm_vec_scale_add2(&obj->mtype.phys_info.thrust,&obj->orient.uvec, Controls.vertical_thrust_time );
  251.  
  252.     if (obj->mtype.phys_info.flags & PF_WIGGLE) {
  253.         fix swiggle;
  254.         fix_fastsincos(GameTime, &swiggle, NULL);
  255.         vm_vec_scale_add2(&obj->mtype.phys_info.velocity,&obj->orient.uvec,fixmul(swiggle,Player_ship->wiggle));
  256.     }
  257.  
  258.     // As of now, obj->mtype.phys_info.thrust & obj->mtype.phys_info.rotthrust are 
  259.     // in units of time... In other words, if thrust==FrameTime, that
  260.     // means that the user was holding down the Max_thrust key for the
  261.     // whole frame.  So we just scale them up by the max, and divide by
  262.     // FrameTime to make them independant of framerate
  263.  
  264.     //    Prevent divide overflows on high frame rates.
  265.     //    In a signed divide, you get an overflow if num >= div<<15
  266.     {
  267.         fix    ft = FrameTime;
  268.  
  269.         //    Note, you must check for ft < F1_0/2, else you can get an overflow  on the << 15.
  270.         if ((ft < F1_0/2) && (ft << 15 <= Player_ship->max_thrust)) {
  271.             mprintf((0, "Preventing divide overflow in controls.c for Max_thrust!\n"));
  272.             ft = (Player_ship->max_thrust >> 15) + 1;
  273.         }
  274.  
  275.         vm_vec_scale( &obj->mtype.phys_info.thrust, fixdiv(Player_ship->max_thrust,ft) );
  276.  
  277.         if ((ft < F1_0/2) && (ft << 15 <= Player_ship->max_rotthrust)) {
  278.             mprintf((0, "Preventing divide overflow in controls.c for max_rotthrust!\n"));
  279.             ft = (Player_ship->max_thrust >> 15) + 1;
  280.         }
  281.  
  282.         vm_vec_scale( &obj->mtype.phys_info.rotthrust, fixdiv(Player_ship->max_rotthrust,ft) );
  283.     }
  284.  
  285. }
  286. 
  287.