FS2_Open
Open source remastering of the Freespace 2 engine
cmeasure.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 "cmeasure/cmeasure.h"
13 #include "gamesnd/gamesnd.h"
14 #include "hud/hud.h"
15 #include "math/staticrand.h"
16 #include "mission/missionparse.h"
17 #include "network/multimsgs.h"
18 #include "object/object.h"
19 #include "ship/ship.h"
20 #include "weapon/weapon.h"
21 
23 int Countermeasures_enabled = 1; // Debug, set to 0 means no one can fire countermeasures.
24 const float CMEASURE_DETONATE_DISTANCE = 40.0f;
25 
26 //Used to set a countermeasure velocity after being launched from a ship as a countermeasure
27 //ie not as a primary or secondary.
28 void cmeasure_set_ship_launch_vel(object *objp, object *parent_objp, int arand)
29 {
30  vec3d vel, rand_vec;
31 
32  //Get cmeasure rear velocity in world
33  vm_vec_scale_add(&vel, &parent_objp->phys_info.vel, &parent_objp->orient.vec.fvec, -25.0f);
34 
35  //Get random velocity vector
36  static_randvec(arand+1, &rand_vec);
37 
38  //Add it to the rear velocity
39  vm_vec_scale_add2(&vel, &rand_vec, 2.0f);
40 
41  objp->phys_info.vel = vel;
42 
43  //Zero out this stuff so it isn't moving
47 
48  // blow out his reverse thrusters. Or drag, same thing.
49  objp->phys_info.rotdamp = 10000.0f;
50  objp->phys_info.side_slip_time_const = 10000.0f;
51 
52  objp->phys_info.max_vel.xyz.z = -25.0f;
53  vm_vec_copy_scale(&objp->phys_info.desired_vel, &objp->orient.vec.fvec, objp->phys_info.max_vel.xyz.z );
54 }
55 
57 {
58  Assert(shipp != NULL);
59  int i, new_index;
60 
61  for (i = 1; i < Num_weapon_types; i++)
62  {
63  new_index = (shipp->current_cmeasure + i) % Num_weapon_types;
64 
65  if(Weapon_info[new_index].wi_flags & WIF_CMEASURE)
66  {
67  shipp->current_cmeasure = new_index;
68  return;
69  }
70  }
71 
72  mprintf(("Countermeasure type set to %i in frame %i\n", shipp->current_cmeasure, Framecount));
73 }
74 
75 
85 {
86  //Is this a countermeasure, and does it have a parent
87  if ( objp->type != OBJ_WEAPON || objp->parent < 0) {
88  return;
89  }
90 
92 
93  if ( objp->parent == OBJ_INDEX(Player_obj) ) {
94  hud_start_text_flash(XSTR("Evaded", 1430), 800);
96  } else if ( Objects[objp->parent].flags & OF_PLAYER_SHIP ) {
98  }
99 }
int Framecount
Definition: systemvars.cpp:22
int i
Definition: multi_pxo.cpp:466
#define WIF_CMEASURE
Definition: weapon.h:51
weapon Weapons[MAX_WEAPONS]
Definition: weapons.cpp:78
vec3d rotvel
Definition: physics.h:78
void vm_vec_scale_add(vec3d *dest, const vec3d *src1, const vec3d *src2, float k)
Definition: vecmat.cpp:266
weapon_info Weapon_info[MAX_WEAPON_TYPES]
Definition: weapons.cpp:79
"evaded" HUD popup
Definition: gamesnd.h:142
SCP_vector< game_snd > Snds
Definition: gamesnd.cpp:19
int Cmeasures_homing_check
Definition: cmeasure.cpp:22
vec3d desired_vel
Definition: physics.h:70
physics_info phys_info
Definition: object.h:157
Assert(pm!=NULL)
Definition: pstypes.h:88
#define mprintf(args)
Definition: pstypes.h:238
float side_slip_time_const
Definition: physics.h:44
void cmeasure_select_next(ship *shipp)
Definition: cmeasure.cpp:56
struct vec3d::@225::@227 xyz
void static_randvec(int num, vec3d *vp)
[To be described]
Definition: staticrand.cpp:111
vec3d max_vel
Definition: physics.h:49
GLclampf f
Definition: Glext.h:7097
void vm_vec_scale_add2(vec3d *dest, const vec3d *src, float k)
Definition: vecmat.cpp:284
#define OF_PLAYER_SHIP
Definition: object.h:109
object * objp
Definition: lua.cpp:3105
vec3d max_rotvel
Definition: physics.h:52
ship * shipp
Definition: lua.cpp:9162
int weapon_info_index
Definition: weapon.h:164
int instance
Definition: object.h:150
struct matrix::@228::@230 vec
void cmeasure_set_ship_launch_vel(object *objp, object *parent_objp, int arand)
Definition: cmeasure.cpp:28
float rotdamp
Definition: physics.h:43
int ship_get_sound(object *objp, GameSoundsIndex id)
Returns a ship-specific sound index.
Definition: ship.cpp:18614
#define OBJ_WEAPON
Definition: object.h:33
int parent
Definition: object.h:147
int snd_play(game_snd *gs, float pan, float vol_scale, int priority, bool is_voice_msg)
Definition: sound.cpp:517
Definition: ship.h:534
object Objects[MAX_OBJECTS]
Definition: object.cpp:62
int Countermeasures_enabled
Definition: cmeasure.cpp:23
int wi_flags
Definition: weapon.h:384
#define vm_vec_zero(v)
Definition: vecmat.h:37
const char * XSTR(const char *str, int index)
Definition: localize.cpp:851
#define OBJ_INDEX(objp)
Definition: object.h:235
matrix orient
Definition: object.h:153
void vm_vec_copy_scale(vec3d *dest, const vec3d *src, float s)
Definition: vecmat.cpp:257
void send_countermeasure_success_packet(int objnum)
Definition: multimsgs.cpp:6942
int Num_weapon_types
Definition: weapons.cpp:105
void cmeasure_maybe_alert_success(object *objp)
If this is a player countermeasure, let the player know they evaded a missile.
Definition: cmeasure.cpp:84
vec3d vel
Definition: physics.h:77
void hud_start_text_flash(char *txt, int t, int interval)
object * Player_obj
Definition: object.cpp:56
uint flags
Definition: object.h:151
const float CMEASURE_DETONATE_DISTANCE
Definition: cmeasure.cpp:24
int current_cmeasure
Definition: ship.h:652
char type
Definition: object.h:146