FS2_Open
Open source remastering of the Freespace 2 engine
collidedebrisweapon.cpp
Go to the documentation of this file.
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 the
6  * source.
7  *
8 */
9 
10 
11 
12 #include "asteroid/asteroid.h"
13 #include "debris/debris.h"
14 #include "math/fvi.h"
15 #include "object/objcollide.h"
16 #include "object/object.h"
17 #include "parse/scripting.h"
18 #include "weapon/weapon.h"
19 
20 
21 
22 // placeholder struct for ship_debris collisions
23 typedef struct ship_weapon_debris_struct {
24  object *ship_object;
25  object *debris_object;
31  float impulse;
33 
34 
41 {
42  vec3d hitpos;
43  int hit;
44  object *pdebris = pair->a;
45  object *weapon_obj = pair->b;
46 
47  Assert( pdebris->type == OBJ_DEBRIS );
48  Assert( weapon_obj->type == OBJ_WEAPON );
49 
50  // first check the bounding spheres of the two objects.
51  hit = fvi_segment_sphere(&hitpos, &weapon_obj->last_pos, &weapon_obj->pos, &pdebris->pos, pdebris->radius);
52  if (hit) {
53  hit = debris_check_collision(pdebris, weapon_obj, &hitpos );
54  if ( !hit )
55  return 0;
56 
57  Script_system.SetHookObjects(4, "Weapon", weapon_obj, "Debris", pdebris, "Self", weapon_obj, "Object", pdebris);
58  bool weapon_override = Script_system.IsConditionOverride(CHA_COLLIDEDEBRIS, weapon_obj);
59 
60  Script_system.SetHookObjects(2, "Self", pdebris, "Object", weapon_obj);
61  bool debris_override = Script_system.IsConditionOverride(CHA_COLLIDEWEAPON, pdebris);
62 
63  if(!weapon_override && !debris_override)
64  {
65  weapon_hit( weapon_obj, pdebris, &hitpos );
66  debris_hit( pdebris, weapon_obj, &hitpos, Weapon_info[Weapons[weapon_obj->instance].weapon_info_index].damage );
67  }
68 
69  Script_system.SetHookObjects(2, "Self", weapon_obj, "Object", pdebris);
70  if(!(debris_override && !weapon_override))
71  Script_system.RunCondition(CHA_COLLIDEDEBRIS, '\0', NULL, weapon_obj);
72 
73  Script_system.SetHookObjects(2, "Self", pdebris, "Object", weapon_obj);
74  if((debris_override && !weapon_override) || (!debris_override && !weapon_override))
76 
77  Script_system.RemHookVars(4, "Weapon", "Debris", "Self", "Object");
78  return 0;
79 
80  } else {
81  return weapon_will_never_hit( weapon_obj, pdebris, pair );
82  }
83 }
84 
85 
86 
93 {
94  if (!Asteroids_enabled)
95  return 0;
96 
97  vec3d hitpos;
98  int hit;
99  object *pasteroid = pair->a;
100  object *weapon_obj = pair->b;
101 
102  Assert( pasteroid->type == OBJ_ASTEROID);
103  Assert( weapon_obj->type == OBJ_WEAPON );
104 
105  // first check the bounding spheres of the two objects.
106  hit = fvi_segment_sphere(&hitpos, &weapon_obj->last_pos, &weapon_obj->pos, &pasteroid->pos, pasteroid->radius);
107  if (hit) {
108  hit = asteroid_check_collision(pasteroid, weapon_obj, &hitpos );
109  if ( !hit )
110  return 0;
111 
112  Script_system.SetHookObjects(4, "Weapon", weapon_obj, "Asteroid", pasteroid, "Self", weapon_obj, "Object", pasteroid);
113 
114  bool weapon_override = Script_system.IsConditionOverride(CHA_COLLIDEASTEROID, weapon_obj);
115  Script_system.SetHookObjects(2, "Self",pasteroid, "Object", weapon_obj);
116  bool asteroid_override = Script_system.IsConditionOverride(CHA_COLLIDEWEAPON, pasteroid);
117 
118  if(!weapon_override && !asteroid_override)
119  {
120  weapon_hit( weapon_obj, pasteroid, &hitpos );
121  asteroid_hit( pasteroid, weapon_obj, &hitpos, Weapon_info[Weapons[weapon_obj->instance].weapon_info_index].damage );
122  }
123 
124  Script_system.SetHookObjects(2, "Self", weapon_obj, "Object", pasteroid);
125  if(!(asteroid_override && !weapon_override))
126  Script_system.RunCondition(CHA_COLLIDEASTEROID, '\0', NULL, weapon_obj);
127 
128  Script_system.SetHookObjects(2, "Self", pasteroid, "Object", weapon_obj);
129  if((asteroid_override && !weapon_override) || (!asteroid_override && !weapon_override))
130  Script_system.RunCondition(CHA_COLLIDEWEAPON, '\0', NULL, pasteroid, Weapons[weapon_obj->instance].weapon_info_index);
131 
132  Script_system.RemHookVars(4, "Weapon", "Asteroid", "Self", "Object");
133  return 0;
134 
135  } else {
136  return weapon_will_never_hit( weapon_obj, pasteroid, pair );
137  }
138 }
139 
140 
weapon Weapons[MAX_WEAPONS]
Definition: weapons.cpp:78
weapon_info Weapon_info[MAX_WEAPON_TYPES]
Definition: weapons.cpp:79
int asteroid_check_collision(object *pasteroid, object *other_obj, vec3d *hitpos, collision_info_struct *asteroid_hit_info)
Definition: asteroid.cpp:918
Assert(pm!=NULL)
Definition: pstypes.h:88
#define OBJ_ASTEROID
Definition: object.h:44
vec3d pos
Definition: object.h:152
script_state Script_system("FS2_Open Scripting")
void debris_hit(object *debris_obj, object *other_obj, vec3d *hitpos, float damage)
Definition: debris.cpp:751
int weapon_info_index
Definition: weapon.h:164
int instance
Definition: object.h:150
object * a
Definition: objcollide.h:55
vec3d last_pos
Definition: object.h:155
#define CHA_COLLIDEDEBRIS
Definition: scripting.h:49
#define OBJ_WEAPON
Definition: object.h:33
void weapon_hit(object *weapon_obj, object *other_obj, vec3d *hitpos, int quadrant=-1)
Definition: weapons.cpp:6253
#define OBJ_DEBRIS
Definition: object.h:37
int weapon_will_never_hit(object *obj_weapon, object *other, obj_pair *current_pair)
Definition: objcollide.cpp:730
int collide_debris_weapon(obj_pair *pair)
int Asteroids_enabled
Definition: asteroid.cpp:57
#define CHA_COLLIDEASTEROID
Definition: scripting.h:50
#define CHA_COLLIDEWEAPON
Definition: scripting.h:48
int RunCondition(int condition, char format='\0', void *data=NULL, class object *objp=NULL, int more_data=0)
Definition: scripting.cpp:924
void SetHookObjects(int num,...)
Definition: scripting.cpp:556
int collide_asteroid_weapon(obj_pair *pair)
int debris_check_collision(object *pdebris, object *other_obj, vec3d *hitpos, collision_info_struct *debris_hit_info)
Definition: debris.cpp:808
void RemHookVars(unsigned int num,...)
Definition: scripting.cpp:754
struct ship_weapon_debris_struct ship_weapon_debris_struct
int fvi_segment_sphere(vec3d *intp, const vec3d *p0, const vec3d *p1, const vec3d *sphere_pos, float sphere_rad)
Definition: fvi.cpp:188
object * b
Definition: objcollide.h:56
void asteroid_hit(object *pasteroid_obj, object *other_obj, vec3d *hitpos, float damage)
Definition: asteroid.cpp:1368
float radius
Definition: object.h:154
char type
Definition: object.h:146
float damage
Definition: weapon.h:363
bool IsConditionOverride(int action, object *objp=NULL)
Definition: scripting.cpp:938