home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / o.h < prev    next >
C/C++ Source or Header  |  1998-06-08  |  19KB  |  520 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/object.h $
  15.  * $Revision: 1.75 $
  16.  * $Author: matt $
  17.  * $Date: 1994/08/03 21:06:19 $
  18.  * 
  19.  * object system definitions
  20.  * 
  21.  * $Log: object.h $
  22.  * Revision 1.75  1994/08/03  21:06:19  matt
  23.  * Added prototype for fix_object_segs(), and renamed now-unused spawn_pos
  24.  * 
  25.  * Revision 1.74  1994/08/02  12:30:27  matt
  26.  * Added support for spinning objects
  27.  * 
  28.  * Revision 1.73  1994/07/27  20:53:25  matt
  29.  * Added rotational drag & thrust, so turning now has momemtum like moving
  30.  * 
  31.  * Revision 1.72  1994/07/27  19:44:21  mike
  32.  * Objects containing objects.
  33.  * 
  34.  * Revision 1.71  1994/07/22  20:43:29  matt
  35.  * Fixed flares, by adding a physics flag that makes them stick to walls.
  36.  * 
  37.  * Revision 1.70  1994/07/21  12:42:10  mike
  38.  * Prototype new find_object_seg and update_object_seg.
  39.  * 
  40.  * Revision 1.69  1994/07/19  15:26:39  mike
  41.  * New ai_static structure.
  42.  * 
  43.  * Revision 1.68  1994/07/13  00:15:06  matt
  44.  * Moved all (or nearly all) of the values that affect player movement to 
  45.  * bitmaps.tbl
  46.  * 
  47.  * Revision 1.67  1994/07/12  12:40:12  matt
  48.  * Revamped physics system
  49.  * 
  50.  * Revision 1.66  1994/07/06  15:26:23  yuan
  51.  * Added chase mode.
  52.  * 
  53.  * Revision 1.65  1994/06/29  19:43:31  matt
  54.  * Made powerup animation not happen in render routine
  55.  * 
  56.  * Revision 1.64  1994/06/27  18:31:09  mike
  57.  * Add flares.
  58.  * 
  59.  * Revision 1.63  1994/06/14  21:15:21  matt
  60.  * Made rod objects draw lighted or not depending on a parameter, so the
  61.  * materialization effect no longer darkens.
  62.  * 
  63.  * Revision 1.62  1994/06/14  16:55:00  matt
  64.  * Got rid of physics_object speed field
  65.  * 
  66.  * Revision 1.61  1994/06/09  16:24:58  matt
  67.  * Fixed confusion with two constants, MAX_SUBOBJS & MAX_SUBMODELS, which
  68.  * were used for the same things, but had different values.
  69.  * 
  70.  * Revision 1.60  1994/06/08  10:56:44  matt
  71.  * Improved debris: now get submodel size from new POF files; debris now has
  72.  * limited life; debris can now be blown up.
  73.  * 
  74.  * Revision 1.59  1994/06/02  19:30:49  matt
  75.  * Moved texture-mapped rod drawing stuff (used for hostage & now for the
  76.  * materialization center) to object.c
  77.  * 
  78.  * Revision 1.58  1994/05/30  22:50:20  matt
  79.  * Added morph effect for robots
  80.  * 
  81.  * Revision 1.57  1994/05/30  19:46:47  mike
  82.  * Move MAX_SUBOBJS from here to inferno.h
  83.  * 
  84.  * Revision 1.56  1994/05/30  00:03:19  matt
  85.  * Got rid of robot render type, and generally cleaned up polygon model
  86.  * render objects.
  87.  * 
  88.  * Revision 1.55  1994/05/26  21:08:44  matt
  89.  * Moved robot stuff out of polygon model and into robot_info struct
  90.  * Made new file, robot.c, to deal with robots
  91.  * 
  92.  * Revision 1.54  1994/05/20  11:56:59  matt
  93.  * Cleaned up find_vector_intersection() interface
  94.  * Killed check_point_in_seg(), check_player_seg(), check_object_seg()
  95.  * 
  96.  * Revision 1.53  1994/05/19  18:53:18  yuan
  97.  * Changing player structure...
  98.  * 
  99.  * Revision 1.52  1994/05/17  12:36:16  matt
  100.  * Changed parms to obj_create() and cleaned up object creation code
  101.  * 
  102.  * Revision 1.51  1994/05/17  11:53:45  yuan
  103.  * Adding Player_init, which saves position of player at beginning of level.
  104.  * 
  105.  * Revision 1.50  1994/05/17  10:37:08  matt
  106.  * Added new parm to reset_objects(), made Num_objects not public, added
  107.  * Highest_object_index().
  108.  * 
  109.  * Revision 1.49  1994/05/16  16:48:14  yuan
  110.  * Added symbolic constant OBJECT_INITIAL_SHIELDS
  111.  * 
  112.  * Revision 1.48  1994/05/16  16:17:47  john
  113.  * Bunch of stuff on my Inferno Task list May16-23
  114.  * 
  115.  * Revision 1.47  1994/05/16  10:12:12  matt
  116.  * Added prototype for init_player_object()
  117.  * 
  118.  * Revision 1.46  1994/05/14  17:15:06  matt
  119.  * Got rid of externs in source (non-header) files
  120.  * 
  121.  * Revision 1.45  1994/05/13  20:27:37  john
  122.  * Version II of John's new object code.
  123.  * 
  124.  * Revision 1.44  1994/05/12  14:44:39  mike
  125.  * Add ai_info to object structure.
  126.  * 
  127.  * Revision 1.43  1994/05/11  23:33:08  mike
  128.  * Make RESULT_KILLS directional with RESULT_KILLS_1_2 and RESULT_KILLS_2_1.
  129.  * 
  130.  * Revision 1.42  1994/05/10  18:02:16  mike
  131.  * Increase MAX_OBJECTS from 100 to 200
  132.  * 
  133.  * Revision 1.41  1994/05/07  16:42:07  matt
  134.  * Changed name of turnbank to turnroll
  135.  * 
  136.  * Revision 1.40  1994/05/06  10:12:39  matt
  137.  * Added new function, obj_create_copy()
  138.  * 
  139.  * Revision 1.39  1994/05/05  20:39:33  matt
  140.  * Made physics code more general-purpose; moved code from object.c to
  141.  * physics.c; renamed routines; made behavior such as levelling and turn
  142.  * banking controllable by flags.
  143.  * 
  144.  * Revision 1.38  1994/05/05  16:41:12  matt
  145.  * Cleaned up repair center code, and moved some from object.c to fuelcen.c
  146.  * 
  147.  * Revision 1.37  1994/05/03  19:33:40  matt
  148.  * Cleaned up usage of rotvel field from physics_info structure
  149.  * 
  150.  * Revision 1.36  1994/05/02  18:34:14  matt
  151.  * Changed parms to obj_link(), added a little more error checking, changed
  152.  * a few fields in object physics_info, and probably a few other little things.
  153.  * 
  154.  * Revision 1.35  1994/05/02  16:30:31  john
  155.  * Added object flag OF_SHOULD_BE_DEAD which fixed the bug
  156.  * that caused very close robots to die 10 seconds after they
  157.  * actually got shot.
  158.  * 
  159.  * Revision 1.34  1994/04/29  09:18:08  matt
  160.  * Added support for multiple-piece explosions
  161.  * 
  162.  * Revision 1.33  1994/04/07  16:28:07  yuan
  163.  * Added SUPERPIG the robot with 200 hit points.
  164.  * Now robots can take multiple hits before blowing up.
  165.  * 
  166.  * Revision 1.32  1994/04/07  13:44:13  yuan
  167.  * Added powerup_info to object structure.
  168.  * 
  169.  * Revision 1.31  1994/04/01  13:34:15  matt
  170.  * Cleaned up explosion and laser code; added mutliple-stage explosions.
  171.  * 
  172.  * Revision 1.30  1994/04/01  11:15:07  yuan
  173.  * Added multiple bitmap functionality to all objects...
  174.  * (hostages, powerups, lasers, etc.)  
  175.  * Hostages and powerups are implemented in the object system,
  176.  * just need to finish function call to "affect" player.
  177.  * 
  178.  * Revision 1.29  1994/03/31  09:07:43  matt
  179.  * Made last_pos a field of all objects, not just lasers
  180.  * 
  181.  * Revision 1.28  1994/03/30  21:14:33  yuan
  182.  * Minor name change for object->damage...
  183.  * object->lifeleft now.
  184.  * 
  185.  * Revision 1.27  1994/03/28  20:57:36  yuan
  186.  * *** empty log message ***
  187.  * 
  188.  * Revision 1.26  1994/03/25  17:30:13  yuan
  189.  * Checking in hostage stuff... (start of it)
  190.  * 
  191.  * Revision 1.25  1994/03/25  16:54:55  matt
  192.  * polyobj_info field of object structure now has data for object animation
  193.  * 
  194.  * Revision 1.24  1994/02/17  11:32:50  matt
  195.  * Changes in object system
  196.  * 
  197.  * 
  198.  * 
  199.  */
  200.  
  201. #ifndef _OBJECT_H
  202. #define _OBJECT_H
  203.  
  204. #include "types.h"
  205. #include "vecmat.h"
  206. #include "segment.h"
  207. #include "gameseg.h"
  208. #include "aistruct.h"
  209. #include "gr.h"
  210.  
  211. /*
  212.  *        CONSTANTS
  213.  */
  214.  
  215. #define MAX_OBJECTS            200        //total number of objects in world
  216.  
  217. //Object types
  218. #define OBJ_NONE        255    //unused object
  219. #define OBJ_WALL        0        //A wall... not really an object, but used for collisions
  220. #define OBJ_FIREBALL    1        //a fireball, part of an explosion
  221. #define OBJ_ROBOT        2        //an evil enemy
  222. #define OBJ_HOSTAGE    3        //a hostage you need to rescue
  223. #define OBJ_PLAYER    4        //the player on the console
  224. #define OBJ_WEAPON    5        //a laser, missile, etc
  225. #define OBJ_CAMERA    6        //a camera to slew around with
  226. #define OBJ_POWERUP    7        //a powerup you can pick up
  227. #define OBJ_DEBRIS    8        //a piece of robot
  228. #define OBJ_CNTRLCEN    9        //the control center
  229. #define OBJ_FLARE        10        //the control center
  230. #define MAX_OBJECT_TYPES    11
  231.  
  232. //Result types
  233. #define RESULT_NOTHING    0        //Ignore this collision
  234. #define RESULT_CHECK        1        //Check for this collision
  235.  
  236. //Control types - what tells this object what do do
  237. #define CT_NONE            0    //doesn't move (or change movement)
  238. #define CT_AI                1    //driven by AI
  239. #define CT_EXPLOSION        2    //explosion sequencer
  240. #define CT_MULTIPLAYER    3    //via serial or network
  241. #define CT_FLYING            4    //the player is flying
  242. #define CT_SLEW            5    //slewing
  243. #define CT_FLYTHROUGH    6    //the flythrough system
  244. #define CT_DEMO            7    //recorded demo playing back
  245. //#define CT_ROBOT_FLYTHROUGH    8    //special flythrough for robots
  246. #define CT_WEAPON            9        //laser, etc.
  247. #define CT_REPAIRCEN        10    //under the control of the repair center
  248. #define CT_MORPH            11    //this object is being morphed
  249. #define CT_DEBRIS            12    //this is a piece of debris
  250. #define CT_POWERUP        13    //animating powerup blob
  251.  
  252. //Movement types
  253. #define MT_NONE            0    //doesn't move
  254. #define MT_PHYSICS        1    //moves by physics
  255. #define MT_MULTIPLAYER    2    //another player (maybe just interpolation?)
  256. #define MT_SPINNING        3    //this object doesn't move, just sits and spins
  257.  
  258. //Render types
  259. #define RT_NONE            0    //does not render
  260. #define RT_POLYOBJ        1    //a polygon model
  261. #define RT_FIREBALL        2    //a fireball
  262. #define RT_LASER            3    //a laser
  263. #define RT_HOSTAGE        4    //a hostage
  264. #define RT_POWERUP        5    //a powerup
  265. #define RT_MORPH            6    //a robot being morphed
  266.  
  267. //misc object flags
  268. #define OF_EXPLODING            1        //this object is exploding
  269. #define OF_SHOULD_BE_DEAD    2        //this object should be dead, so next time we can, we should delete this object.
  270.  
  271. //Different Weapon ID types...
  272. #define WEAPON_ID_LASER            0
  273. #define WEAPON_ID_MISSLE        1
  274. #define WEAPON_ID_CANNONBALL    2
  275.  
  276. //Object Initial shields...
  277. #define OBJECT_INITIAL_SHIELDS F1_0/2
  278.  
  279. //physics flags
  280. #define PF_TURNROLL        1        //roll when turning
  281. #define PF_LEVELLING        2        //level object with closest side
  282. #define PF_BOUNCE            4        //bounce (not slide) when hit will
  283. #define PF_WIGGLE            8        //wiggle while flying
  284. #define PF_STICK            16        //object sticks (stops moving) when hits wall
  285.  
  286. /*
  287.  *        STRUCTURES
  288.  */
  289.  
  290. //information for physics sim for an object
  291. typedef struct physics_info {
  292.     vms_vector    velocity;        //velocity vector of this object
  293.     vms_vector    thrust;            //constant force applied to this object
  294.     fix            mass;                //the mass of this object
  295.     fix            drag;                //how fast this slows down
  296.     fix            brakes;            //how much brakes applied
  297.     vms_vector    rotvel;            //rotational velecity (angles)
  298.     vms_vector    rotthrust;        //rotational acceleration
  299.     fixang        turnroll;        //rotation caused by turn banking
  300.     ushort        flags;            //misc physics flags
  301. } physics_info;
  302.  
  303. //information on remotely-controlled object
  304. typedef struct mplayer_info {
  305.     int dummy;        //what will be here?
  306. } mplayer_info;
  307.  
  308. //stuctures for different kinds of simulation
  309.  
  310. typedef struct laser_info {
  311.     fix            lifeleft;        // decreased by FrameTime each frame, if > 0 don't decrease.
  312.     short            parent_type;     // The type of the parent of this object
  313.     short            parent_num;     // The object's parent's number
  314.     int            parent_signature;    // The object's parent's signature...
  315.     vms_vector  extra_vec1;        // Used to draw the proper width of laser bolt. (Offset)
  316. } laser_info;
  317.  
  318. typedef struct explosion_info {
  319.     fix            lifeleft;        // decreased by FrameTime each frame, if > 0 don't decrease.
  320.     vms_vector    unused;            // was spawn_pos
  321.     fix            spawn_time;        // when lifeleft is < this, spawn another
  322.     fix            delete_time;    // when to delete object
  323.     short            delete_objnum;    // and what object to delete
  324. } explosion_info;
  325.  
  326. typedef struct flythrough_info {
  327.     vms_angvec  angle_step;        // Used in flythrough
  328.     vms_vector  heading;            // Where we want to be heading...
  329.     int            ft_mode;
  330. } flythrough_info;
  331.  
  332. typedef struct powerup_info {
  333.     fix            frametime;
  334.     byte            framenum;
  335. } powerup_info;
  336.  
  337. //structures for different kinds of rendering
  338.  
  339. typedef struct polyobj_info {
  340.     int            model_num;                        //which polygon model
  341.     vms_angvec    anim_angles[MAX_SUBMODELS];    //angles for each subobject
  342.     int            subobj_flags;                    //specify which subobjs to draw
  343. } polyobj_info;
  344.  
  345. typedef struct object {
  346.     int            signature;        // Every robot has a unique signature...
  347.     ubyte            type;                // what type of object this is... robot, weapon, hostage, powerup, fireball
  348.     ubyte            id;                // which form of object...which powerup, robot, etc.
  349.     short            next,prev;        // id of next and previous connected object in Objects, -1 = no connection
  350.     ubyte            control_type;  // how this object is controlled
  351.     ubyte            movement_type; // how this object moves
  352.     ubyte            render_type;    //    how this object renders
  353.     ubyte            flags;            // misc flags
  354.     short            segnum;            // segment number containing object
  355.     segmasks        segmasks;        // does obj poke into other segs?
  356.     vms_vector  pos;                // absolute x,y,z coordinate of center of object
  357.     vms_matrix  orient;            // orientation of object in world
  358.     fix            size;                // 3d size of object - for collision detection
  359.     fix            shields;         // Starts at maximum, when <0, object dies..
  360.     vms_vector  last_pos;        // where object was last frame
  361.     byte            contains_type;    //    Type of object this object contains (eg, spider contains powerup)
  362.     byte            contains_id;    //    ID of object this object contains (eg, id = blue type = key)
  363.     byte            contains_count; // number of objects of type:id this object contains
  364.     byte            dum1;                //    Unused.
  365.  
  366.     //movement info, determined by MOVEMENT_TYPE
  367.     union {
  368.         physics_info phys_info;            //a physics object
  369.         mplayer_info mplayer_info;        //controled by remote player
  370.         vms_vector     spin_rate;            //for spinning objects
  371.     };
  372.  
  373.     //control info, determined by CONTROL_TYPE
  374.     union {                                
  375.         laser_info laser_info;
  376.         explosion_info expl_info;        //NOTE: debris uses this also
  377.         ai_static    ai_info;
  378.     };
  379.  
  380.     //render info, determined by RENDER_TYPE
  381.     union {
  382.         polyobj_info pobj_info;            //polygon model
  383.         powerup_info powerup_info;        //powerup (vclip)
  384.     };
  385.  
  386. } object;
  387.  
  388. typedef struct obj_position {
  389.     vms_vector  pos;                // absolute x,y,z coordinate of center of object
  390.     vms_matrix  orient;            // orientation of object in world
  391.     short            segnum;            // segment number containing object
  392. } obj_position;    
  393.  
  394. /*
  395.  *        VARIABLES
  396.  */
  397.  
  398. extern int Object_next_signature;        // The next signature for the next newly created object
  399.  
  400. extern ubyte CollisionResult[MAX_OBJECT_TYPES][MAX_OBJECT_TYPES];
  401. // ie CollisionResult[a][b]==  what happens to a when it collides with b
  402.  
  403. extern int Player_objnum;
  404.  
  405. extern object Objects[];
  406. extern int Highest_object_index;        //highest objnum
  407. extern int num_objects;                    //not really a public, included for
  408.  
  409. extern grs_bitmap *robot_bms[];        //all bitmaps for all robots
  410. extern int robot_bm_nums[];            //starting bitmap num for each robot
  411. extern int robot_n_bitmaps[];            //how many bitmaps for each robot
  412. extern char *robot_names[];            //name of each robot
  413.  
  414. extern int Num_robot_types;
  415.  
  416. extern short free_obj_list[MAX_OBJECTS];
  417.  
  418. extern object *Player;            //pointer to the object that is the player
  419. extern object *Viewer;            //which object we are seeing from
  420.  
  421. extern object Follow;
  422.  
  423. extern obj_position Player_init;
  424.  
  425. /*
  426.  *        FUNCTIONS
  427.  */
  428.  
  429.  
  430. //do whatever setup needs to be done
  431. void init_objects();
  432.  
  433. //returns segment number object is in.  Searches out from object's current
  434. //seg, so this shouldn't be called if the object has "jumped" to a new seg
  435. int obj_get_new_seg(object *obj);
  436.  
  437. //when an object has moved into a new segment, this function unlinks it
  438. //from its old segment, and links it into the new segment
  439. void obj_relink(short objnum,int newsegnum);
  440.  
  441. //move an object from one segment to another. unlinks & relinks
  442. void obj_set_new_seg(short objnum,int newsegnum);
  443.  
  444. //links an object into a segment's list of objects.
  445. //takes object number and segment number
  446. void obj_link(int objnum,int segnum);
  447.  
  448. //unlinks an object from a segment's list of objects
  449. void obj_unlink(int objnum);
  450.  
  451. //initialize a new object.  adds to the list for the given segment
  452. //returns the object number
  453. short obj_create(ubyte type,ubyte id,short segnum,vms_vector *pos,
  454.                 vms_matrix *orient,fix size,ubyte ctype,ubyte mtype,ubyte rtype);
  455.  
  456. //make a copy of an object. returs num of new object
  457. short obj_create_copy(int objnum, vms_vector *new_pos, int newsegnum);
  458.  
  459. //remove object from the world
  460. void obj_delete(short objnum);
  461.  
  462. //called after load.  Takes number of objects,  and objects should be 
  463. //compressed
  464. void reset_objects(int n_objs);
  465.  
  466. //make object array non-sparse
  467. void compress_objects(void);
  468.  
  469. //Render an object.  Calls one of several routines based on type
  470. void render_object(object *obj);
  471.  
  472. //Draw a blob-type object, like a fireball
  473. void draw_object_blob(object *obj,grs_bitmap *bitmap);
  474.  
  475. //draw an object that is a texture-mapped rod
  476. void draw_object_tmap_rod(object *obj,grs_bitmap *bitmap,int lighted);
  477.  
  478. //Deletes all objects that have been marked for death.
  479. void obj_delete_all_that_should_be_dead();
  480.  
  481. // Toggles whether or not lock-boxes draw.
  482. void object_toggle_lock_targets();
  483.  
  484. //move all objects for the current frame
  485. void object_move_all();        // moves all objects
  486.  
  487. //set viewer object to next object in array
  488. void object_goto_next_viewer();
  489.  
  490. //draw target boxes for nearby robots
  491. void object_render_targets(void);
  492.  
  493. //move an object for the current frame
  494. void object_move_one( object * obj );
  495.  
  496. //make object0 the player, setting all relevant fields
  497. void init_player_object();
  498.  
  499. //check if object is in object->segnum.  if not, check the adjacent segs.
  500. //if not any of these, returns false, else sets obj->segnum & returns true
  501. //callers should really use find_vector_intersection()  
  502. //Note: this function is in gameseg.c
  503. int update_object_seg(struct object *obj);
  504.  
  505.  
  506. //    Finds what segment *obj is in, returns segment number.
  507. //    If not in any segment, returns -1.
  508. //    Note: This function is defined in gameseg.h, but object.h depends on gameseg.h, and
  509. //    object.h is where object is defined...get it?
  510. extern int find_object_seg(object * obj );
  511.  
  512. //    Calls find_object_seg and relinks object if segment has changed.
  513. extern int update_object_seg(object * obj );
  514.  
  515. //go through all objects and make sure they have the correct segment numbers
  516. //used when debugging is on
  517. fix_object_segs();
  518.  
  519. #endif
  520.