]> icculus.org git repositories - taylor/freespace2.git/blob - include/objcollide.h
fix issue with looping audio streams
[taylor/freespace2.git] / include / objcollide.h
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Object/ObjCollide.h $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Header file for all the Collide????.cpp modules
16  *
17  * $Log$
18  * Revision 1.2  2002/06/09 04:41:14  relnev
19  * added copyright header
20  *
21  * Revision 1.1.1.1  2002/05/03 03:28:12  root
22  * Initial import.
23  *
24  * 
25  * 9     4/21/99 6:15p Dave
26  * Did some serious housecleaning in the beam code. Made it ready to go
27  * for anti-fighter "pulse" weapons. Fixed collision pair creation. Added
28  * a handy macro for recalculating collision pairs for a given object.
29  * 
30  * 8     11/19/98 11:08p Andsager
31  * Check in of physics and collision detection of rotating submodels
32  * 
33  * 7     11/17/98 4:33p Andsager
34  * add submodel_rot_hit to collision_info struct
35  * 
36  * 6     11/05/98 5:55p Dave
37  * Big pass at reducing #includes
38  * 
39  * 5     10/23/98 1:11p Andsager
40  * Make ship sparks emit correctly from rotating structures.
41  * 
42  * 4     10/20/98 1:39p Andsager
43  * Make so sparks follow animated ship submodels.  Modify
44  * ship_weapon_do_hit_stuff() and ship_apply_local_damage() to add
45  * submodel_num.  Add submodel_num to multiplayer hit packet.
46  * 
47  * 3     10/16/98 1:22p Andsager
48  * clean up header files
49  * 
50  * 2     10/07/98 10:53a Dave
51  * Initial checkin.
52  * 
53  * 1     10/07/98 10:50a Dave
54  * 
55  * 14    5/08/98 5:25p Lawrance
56  * Don't allow collision sounds too play over each so much
57  * 
58  * 13    4/24/98 5:35p Andsager
59  * Fix sparks sometimes drawing not on model.  If ship is sphere in
60  * collision, don't draw sparks.  Modify ship_apply_local_damage() to take
61  * parameter no_spark.
62  * 
63  * 12    4/01/98 1:48p Allender
64  * major changes to ship collision in multiplayer.  Clients now do own
65  * ship/ship collisions (with their own ship only)  Modifed the hull
66  * update packet to be sent quicker when object is target of player.
67  * 
68  * 11    2/26/98 10:07p Hoffoss
69  * Rewrote state saving and restoring to fix bugs and simplify the code.
70  * 
71  * 10    2/05/98 12:51a Mike
72  * Early asteroid stuff.
73  * 
74  * 9     2/04/98 6:08p Lawrance
75  * Add a light collision sound, overlay a shield collide sound if
76  * applicable.
77  * 
78  * 8     1/13/98 3:11p Allender
79  * new code to remove old weapons when no more weapon slots available.
80  * Currently not called anywhere pending further testing
81  * 
82  * 7     1/12/98 9:26p Andsager
83  * Implement collisions from rotation.
84  * 
85  * 6     1/08/98 12:12a Mike
86  * Make ships turn before warping out, if necessary, to avoid a collision.
87  * Warn player if his warpout will collide.  Abort if in stage1.
88  * 
89  * 5     1/05/98 9:07p Andsager
90  * Changed ship_shipor_debris_hit_info struct to more meaninful names
91  * 
92  * 4     12/22/97 9:56p Andsager
93  * Implement ship:debris collisions.  Generalize and move
94  * ship_ship_or_debris_hit struct from CollideShipShip to ObjCollide.h
95  * 
96  * 3     10/28/97 4:57p John
97  * Put Andsager's new sphereline collide code officially into the code
98  * base and did a little restructuring.  Fixed a few little bugs with it
99  * and added some simple bounding box elimination and did some timings.
100  * 
101  * 
102  * 2     10/25/97 10:13a Andsager
103  * Added SPHERE_POLY_CHECK to central location used by ModelCollide.cpp
104  * and Collide_ship_ship.cpp
105  * 
106  * 1     9/17/97 2:14p John
107  * Initial revision
108  *
109  * $NoKeywords: $
110  */
111
112 #ifndef _COLLIDESTUFF_H
113 #define _COLLIDESTUFF_H
114
115 #include "pstypes.h"
116
117 struct object;
118 struct CFILE;
119 struct mc_info;
120
121 // used for ship:ship and ship:debris
122 typedef struct collision_info_struct {
123         object  *heavy;
124         object  *light;
125         vector  heavy_collision_cm_pos; // should be zero
126         vector  light_collision_cm_pos; // relative cm collision pos
127         vector  r_heavy;                                                // relative to A
128         vector  r_light;                                                // relative to B
129         vector  hit_pos;                                        // relative hit position in A's rf (r_heavy)
130         vector  collision_normal;               // normal outward from heavy
131         float           hit_time;                               // time normalized [0,1] when sphere hits model
132         float           impulse;                                        // damage scales according to impulse
133         vector  light_rel_vel;                  // velocity of light relative to heavy before collison
134         int             collide_rotate;         // if collision is detected purely from rotation
135         int             submodel_num;                   // submodel of heavy object that is hit
136         int             edge_hit;                               // if edge is hit, need to change collision normal
137         int             submodel_rot_hit;               // if collision is against rotating submodel
138 } collision_info_struct;
139
140
141 //===============================================================================
142 // GENERAL COLLISION DETECTION HELPER FUNCTIONS 
143 // These are in CollideGeneral.cpp and are used by one or more of the collision-
144 // type specific collision modules.
145 //===============================================================================
146
147 // Keeps track of pairs of objects for collision detection
148 typedef struct obj_pair {
149         object *a;
150         object *b;
151         int (*check_collision)( obj_pair * pair );
152         int     next_check_time;        // a timestamp that when elapsed means to check for a collision
153         struct obj_pair *next;
154 } obj_pair;
155
156
157 #define COLLISION_OF(a,b) (((a)<<8)|(b))
158
159 #define COLLISION_TYPE_NONE     0       
160 #define COLLISION_TYPE_OLD              1       // checks all n objects with each other each frame
161 #define COLLISION_TYPE_NEW              2       // keeps track of collision pairs.  throws out collisions that won't happen.
162
163 extern int collision_type;
164
165 #define SUBMODEL_NO_ROT_HIT     0
166 #define SUBMODEL_ROT_HIT                1
167 void set_hit_struct_info(collision_info_struct *hit, mc_info *mc, int submodel_rot_hit);
168
169 void obj_reset_pairs();
170 void obj_add_pair( object *A, object *B, int check_time = -1, int add_to_end = 0 );
171
172 void obj_check_all_collisions();
173
174 // Returns TRUE if the weapon will never hit the other object.
175 // If it can it predicts how long until these two objects need
176 // to be checked and fills the time in in current_pair.
177 // CODE is locatated in CollideGeneral.cpp
178 int weapon_will_never_hit( object *weapon, object *other, obj_pair * current_pair );
179
180
181 //      See if two lines intersect by doing recursive subdivision.
182 //      Bails out if larger distance traveled is less than sum of radii + 1.0f.
183 // CODE is locatated in CollideGeneral.cpp
184 int collide_subdivide(vector *p0, vector *p1, float prad, vector *q0, vector *q1, float qrad);
185
186
187 //===============================================================================
188 // SPECIFIC COLLISION DETECTION FUNCTIONS 
189 //===============================================================================
190
191 // Checks weapon-weapon collisions.  pair->a and pair->b are weapons.
192 // Returns 1 if all future collisions between these can be ignored
193 // CODE is locatated in CollideWeaponWeapon.cpp
194 int collide_weapon_weapon( obj_pair * pair );
195
196 // Checks ship-weapon collisions.  pair->a is ship and pair->b is weapon.
197 // Returns 1 if all future collisions between these can be ignored
198 // CODE is locatated in CollideShipWeapon.cpp
199 int collide_ship_weapon( obj_pair * pair );
200 void ship_weapon_do_hit_stuff(object *ship_obj, object *weapon_obj, vector *world_hitpos, vector *hitpos, int quadrant_num, int submodel_num = -1);
201
202 // Checks debris-weapon collisions.  pair->a is debris and pair->b is weapon.
203 // Returns 1 if all future collisions between these can be ignored
204 // CODE is locatated in CollideDebrisWeapon.cpp
205 int collide_debris_weapon( obj_pair * pair );
206
207 // Checks debris-ship collisions.  pair->a is debris and pair->b is ship.
208 // Returns 1 if all future collisions between these can be ignored
209 // CODE is locatated in CollideDebrisShip.cpp
210 int collide_debris_ship( obj_pair * pair );
211
212 int collide_asteroid_ship(obj_pair *pair);
213 int collide_asteroid_weapon(obj_pair *pair);
214
215 // Checks ship-ship collisions.  pair->a and pair->b are ships.
216 // Returns 1 if all future collisions between these can be ignored
217 // CODE is locatated in CollideShipShip.cpp
218 int collide_ship_ship( obj_pair * pair );
219
220 //      Predictive functions.
221 //      Returns true if vector from curpos to goalpos with radius radius will collide with object goalobjp
222 int pp_collide(vector *curpos, vector *goalpos, object *goalobjp, float radius);
223
224 //      Return true if objp will collide with some large ship if it moves distance distance.
225 int collide_predict_large_ship(object *objp, float distance);
226
227 // function to remove old weapons when no more weapon slots available.
228 int collide_remove_weapons(void);
229
230 void collide_ship_ship_do_sound(vector *world_hit_pos, object *A, object *B, int player_involved);
231 void collide_ship_ship_sounds_init();
232
233 int get_ship_quadrant_from_global(vector *global_pos, object *objp);
234
235 #endif
236