]> icculus.org git repositories - taylor/freespace2.git/blob - src/object/collidedebrisweapon.cpp
Initial revision
[taylor/freespace2.git] / src / object / collidedebrisweapon.cpp
1 /*
2  * $Logfile: /Freespace2/code/Object/CollideDebrisWeapon.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Routines to detect collisions and do physics, damage, etc for weapons and debris
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:10  root
11  * Initial revision
12  *
13  * 
14  * 4     7/15/99 9:20a Andsager
15  * FS2_DEMO initial checkin
16  * 
17  * 3     10/16/98 1:22p Andsager
18  * clean up header files
19  * 
20  * 2     10/07/98 10:53a Dave
21  * Initial checkin.
22  * 
23  * 1     10/07/98 10:50a Dave
24  * 
25  * 7     4/02/98 6:29p Lawrance
26  * compile out asteroid references for demo
27  * 
28  * 6     3/02/98 2:58p Mike
29  * Make "asteroids" in debug console turn asteroids on/off.
30  * 
31  * 5     2/19/98 12:46a Lawrance
32  * Further work on asteroids.
33  * 
34  * 4     2/05/98 12:51a Mike
35  * Early asteroid stuff.
36  * 
37  * 3     1/13/98 8:09p John
38  * Removed the old collision system that checked all pairs.   Added code
39  * to disable collisions and particles.
40  * 
41  * 2     9/17/97 5:12p John
42  * Restructured collision routines.  Probably broke a lot of stuff.
43  * 
44  * 1     9/17/97 2:14p John
45  * Initial revision
46  *
47  * $NoKeywords: $
48  */
49
50 #include "objcollide.h"
51 #include "asteroid.h"
52 #include "debris.h"
53 #include "fvi.h"
54
55 // placeholder struct for ship_debris collisions
56 typedef struct ship_weapon_debris_struct {
57         object  *ship_object;
58         object  *debris_object;
59         vector  ship_collision_cm_pos;
60         vector  r_ship;
61         vector  collision_normal;
62         int             shield_hit_tri;
63         vector  shield_hit_tri_point;
64         float           impulse;
65 } ship_weapon_debris_struct;
66
67
68 // Checks debris-weapon collisions.  pair->a is debris and pair->b is weapon.
69 // Returns 1 if all future collisions between these can be ignored
70 int collide_debris_weapon( obj_pair * pair )
71 {
72         vector  hitpos;
73         int             hit;
74         object *pdebris = pair->a;
75         object *weapon = pair->b;
76
77         Assert( pdebris->type == OBJ_DEBRIS );
78         Assert( weapon->type == OBJ_WEAPON );
79
80         // first check the bounding spheres of the two objects.
81         hit = fvi_segment_sphere(&hitpos, &weapon->last_pos, &weapon->pos, &pdebris->pos, pdebris->radius);
82         if (hit) {
83                 hit = debris_check_collision(pdebris, weapon, &hitpos );
84                 if ( !hit )
85                         return 0;
86
87                 weapon_hit( weapon, pdebris, &hitpos );
88                 debris_hit( pdebris, weapon, &hitpos, Weapon_info[Weapons[weapon->instance].weapon_info_index].damage );
89                 return 0;
90
91         } else {
92                 return weapon_will_never_hit( weapon, pdebris, pair );
93         }
94 }                               
95
96
97
98 // Checks debris-weapon collisions.  pair->a is debris and pair->b is weapon.
99 // Returns 1 if all future collisions between these can be ignored
100 int collide_asteroid_weapon( obj_pair * pair )
101 {
102 #ifndef FS2_DEMO
103
104         if (!Asteroids_enabled)
105                 return 0;
106
107         vector  hitpos;
108         int             hit;
109         object  *pasteroid = pair->a;
110         object  *weapon = pair->b;
111
112         Assert( pasteroid->type == OBJ_ASTEROID);
113         Assert( weapon->type == OBJ_WEAPON );
114
115         // first check the bounding spheres of the two objects.
116         hit = fvi_segment_sphere(&hitpos, &weapon->last_pos, &weapon->pos, &pasteroid->pos, pasteroid->radius);
117         if (hit) {
118                 hit = asteroid_check_collision(pasteroid, weapon, &hitpos );
119                 if ( !hit )
120                         return 0;
121
122                 weapon_hit( weapon, pasteroid, &hitpos );
123                 asteroid_hit( pasteroid, weapon, &hitpos, Weapon_info[Weapons[weapon->instance].weapon_info_index].damage );
124                 return 0;
125
126         } else {
127                 return weapon_will_never_hit( weapon, pasteroid, pair );
128         }
129
130 #else
131         return 0;
132 #endif
133 }                               
134
135