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