home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / slew.c < prev    next >
Text File  |  1998-06-08  |  8KB  |  252 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/slew.c $
  15.  * $Revision: 2.0 $
  16.  * $Author: john $
  17.  * $Date: 1995/02/27 11:29:32 $
  18.  * 
  19.  * Basic slew system for moving around the mine
  20.  * 
  21.  * $Log: slew.c $
  22.  * Revision 2.0  1995/02/27  11:29:32  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.34  1995/02/22  14:23:28  allender
  27.  * remove anonymous unions from object structure
  28.  * 
  29.  * Revision 1.33  1995/02/22  13:24:26  john
  30.  * Removed the vecmat anonymous unions.
  31.  * 
  32.  * Revision 1.32  1994/09/10  15:46:42  john
  33.  * First version of new keyboard configuration.
  34.  * 
  35.  * Revision 1.31  1994/08/31  18:29:58  matt
  36.  * Made slew work with new key system
  37.  * 
  38.  * Revision 1.30  1994/08/31  14:10:48  john
  39.  * Made slew go faster.
  40.  * 
  41.  * Revision 1.29  1994/08/29  19:16:38  matt
  42.  * Made slew object not have physics movement type, so slew objects don't
  43.  * get bumped.
  44.  * 
  45.  * Revision 1.28  1994/08/24  18:59:59  john
  46.  * Changed key_down_time to return fixed seconds instead of
  47.  * milliseconds.
  48.  * 
  49.  * Revision 1.27  1994/07/01  11:33:05  john
  50.  * Fixed bug with looking for stick even if one not present.
  51.  * 
  52.  * Revision 1.26  1994/05/20  11:56:33  matt
  53.  * Cleaned up find_vector_intersection() interface
  54.  * Killed check_point_in_seg(), check_player_seg(), check_object_seg()
  55.  * 
  56.  * Revision 1.25  1994/05/19  12:08:41  matt
  57.  * Use new vecmat macros and globals
  58.  * 
  59.  * Revision 1.24  1994/05/14  17:16:18  matt
  60.  * Got rid of externs in source (non-header) files
  61.  * 
  62.  * Revision 1.23  1994/05/03  12:26:38  matt
  63.  * Removed use of physics_info var rotvel, which wasn't used for rotational
  64.  * velocity at all.
  65.  * 
  66.  * Revision 1.22  1994/02/17  11:32:34  matt
  67.  * Changes in object system
  68.  * 
  69.  * Revision 1.21  1994/01/18  14:03:53  john
  70.  * made joy_get_pos use the new ints instead of
  71.  * shorts.
  72.  * 
  73.  * Revision 1.20  1994/01/10  17:11:35  mike
  74.  * Add prototype for check_object_seg
  75.  * 
  76.  * Revision 1.19  1994/01/05  10:53:38  john
  77.  * New object code by John.  
  78.  * 
  79.  * Revision 1.18  1993/12/22  15:32:50  john
  80.  * took out previos code that attempted to make
  81.  * modifiers cancel keydowntime.
  82.  * 
  83.  * Revision 1.17  1993/12/22  11:41:56  john
  84.  * Made so that keydowntime recognizes editor special case!
  85.  * 
  86.  * Revision 1.16  1993/12/14  18:13:52  matt
  87.  * Made slew work in editor even when game isn't in slew mode
  88.  * 
  89.  * Revision 1.15  1993/12/07  23:53:39  matt
  90.  * Made slew work in editor even when game isn't in slew mode
  91.  * 
  92.  * Revision 1.14  1993/12/05  22:47:49  matt
  93.  * Reworked include files in an attempt to cut down on build times
  94.  * 
  95.  * Revision 1.13  1993/12/01  11:44:14  matt
  96.  * Chagned Frfract to FrameTime
  97.  * 
  98.  * Revision 1.12  1993/11/08  16:21:42  john
  99.  * made stop_slew or whatever return an int
  100.  * 
  101.  * Revision 1.11  1993/11/01  13:59:49  john
  102.  * more slew experiments.
  103.  * 
  104.  */
  105.  
  106. #include <stdlib.h>
  107.  
  108. #include "inferno.h"
  109. #include "game.h"
  110. #include "vecmat.h"
  111. #include "key.h"
  112. #include "joy.h"
  113. #include "object.h"
  114. #include "error.h"
  115. #include "physics.h"
  116. #include "joydefs.h"
  117. #include "kconfig.h"
  118.  
  119. #pragma off (unreferenced)
  120. static char rcsid[] = "$Id: slew.c 2.0 1995/02/27 11:29:32 john Exp $";
  121. #pragma on (unreferenced)
  122.  
  123. //variables for slew system
  124.  
  125. object *slew_obj=NULL;    //what object is slewing, or NULL if none
  126.  
  127. #define JOY_NULL 15
  128. #define ROT_SPEED 8        //rate of rotation while key held down
  129. #define VEL_SPEED (2*55)    //rate of acceleration while key held down
  130.  
  131. short old_joy_x,old_joy_y;    //position last time around
  132.  
  133. //say start slewing with this object
  134. slew_init(object *obj)
  135. {
  136.     slew_obj = obj;
  137.  
  138.     slew_obj->control_type = CT_SLEW;
  139.     slew_obj->movement_type = MT_NONE;
  140.  
  141.     slew_stop();        //make sure not moving
  142. }
  143.  
  144.  
  145. int slew_stop()
  146. {
  147.     if (!slew_obj || slew_obj->control_type!=CT_SLEW) return 0;
  148.  
  149.     vm_vec_zero(&slew_obj->mtype.phys_info.velocity);
  150.     return 1;
  151. }
  152.  
  153. void slew_reset_orient()
  154. {
  155.     if (!slew_obj || slew_obj->control_type!=CT_SLEW) return;
  156.  
  157.     slew_obj->orient.rvec.x = slew_obj->orient.uvec.y = slew_obj->orient.fvec.z = f1_0;
  158.  
  159.     slew_obj->orient.rvec.y = slew_obj->orient.rvec.z = slew_obj->orient.uvec.x = 
  160.    slew_obj->orient.uvec.z = slew_obj->orient.fvec.x = slew_obj->orient.fvec.y = 0;
  161.  
  162. }
  163.  
  164. int do_slew_movement(object *obj, int check_keys, int check_joy )
  165. {
  166.     int moved = 0;
  167.     vms_vector svel, movement;                //scaled velocity (per this frame)
  168.     vms_matrix rotmat,new_pm;
  169.     int joy_x,joy_y,btns;
  170.     int joyx_moved,joyy_moved;
  171.     vms_angvec rotang;
  172.  
  173.     if (!slew_obj || slew_obj->control_type!=CT_SLEW) return 0;
  174.  
  175.     if (check_keys) {
  176.         if (Function_mode == FMODE_EDITOR) {
  177.             obj->mtype.phys_info.velocity.x += VEL_SPEED * (key_down_time(KEY_PAD9) - key_down_time(KEY_PAD7));
  178.             obj->mtype.phys_info.velocity.y += VEL_SPEED * (key_down_time(KEY_PADMINUS) - key_down_time(KEY_PADPLUS));
  179.             obj->mtype.phys_info.velocity.z += VEL_SPEED * (key_down_time(KEY_PAD8) - key_down_time(KEY_PAD2));
  180.  
  181.             rotang.p = (key_down_time(KEY_LBRACKET) - key_down_time(KEY_RBRACKET))/ROT_SPEED ;
  182.             rotang.b  = (key_down_time(KEY_PAD1) - key_down_time(KEY_PAD3))/ROT_SPEED;
  183.             rotang.h  = (key_down_time(KEY_PAD6) - key_down_time(KEY_PAD4))/ROT_SPEED;
  184.         }
  185.         else {
  186.             obj->mtype.phys_info.velocity.x += VEL_SPEED * Controls.sideways_thrust_time;
  187.             obj->mtype.phys_info.velocity.y += VEL_SPEED * Controls.vertical_thrust_time;
  188.             obj->mtype.phys_info.velocity.z += VEL_SPEED * Controls.forward_thrust_time;
  189.  
  190.             rotang.p = Controls.pitch_time/ROT_SPEED ;
  191.             rotang.b  = Controls.bank_time/ROT_SPEED;
  192.             rotang.h  = Controls.heading_time/ROT_SPEED;
  193.         }
  194.     }
  195.     else
  196.         rotang.p = rotang.b  = rotang.h  = 0;
  197.  
  198.     //check for joystick movement
  199.  
  200.     if (check_joy && joy_present && (Function_mode == FMODE_EDITOR) )    {
  201.         joy_get_pos(&joy_x,&joy_y);
  202.         btns=joy_get_btns();
  203.     
  204.         joyx_moved = (abs(joy_x - old_joy_x)>JOY_NULL);
  205.         joyy_moved = (abs(joy_y - old_joy_y)>JOY_NULL);
  206.     
  207.         if (abs(joy_x) < JOY_NULL) joy_x = 0;
  208.         if (abs(joy_y) < JOY_NULL) joy_y = 0;
  209.     
  210.         if (btns)
  211.             if (!rotang.p) rotang.p = fixmul(-joy_y * 512,FrameTime); else;
  212.         else
  213.             if (joyy_moved) obj->mtype.phys_info.velocity.z = -joy_y * 8192;
  214.     
  215.         if (!rotang.h) rotang.h = fixmul(joy_x * 512,FrameTime);
  216.     
  217.         if (joyx_moved) old_joy_x = joy_x;
  218.         if (joyy_moved) old_joy_y = joy_y;
  219.     }
  220.  
  221.     moved = rotang.p | rotang.b | rotang.h;
  222.  
  223.     vm_angles_2_matrix(&rotmat,&rotang);
  224.     vm_matrix_x_matrix(&new_pm,&obj->orient,&rotmat);
  225.     obj->orient = new_pm;
  226.     vm_transpose_matrix(&new_pm);        //make those columns rows
  227.  
  228.     moved |= obj->mtype.phys_info.velocity.x | obj->mtype.phys_info.velocity.y | obj->mtype.phys_info.velocity.z;
  229.  
  230.     svel = obj->mtype.phys_info.velocity;
  231.     vm_vec_scale(&svel,FrameTime);        //movement in this frame
  232.     vm_vec_rotate(&movement,&svel,&new_pm);
  233.  
  234. //    obj->last_pos = obj->pos;
  235.     vm_vec_add2(&obj->pos,&movement);
  236.  
  237.     moved |= (movement.x || movement.y || movement.z);
  238.  
  239.     if (moved) 
  240.         update_object_seg(obj);    //update segment id
  241.  
  242.     return moved;
  243. }
  244.  
  245. //do slew for this frame
  246. int slew_frame(int check_keys)
  247. {
  248.     return do_slew_movement( slew_obj, !check_keys, 1 );
  249.  
  250. }
  251. 
  252.