Open source remastering of the Freespace 2 engine
weapons.cpp File Reference
#include "ai/aibig.h"
#include "asteroid/asteroid.h"
#include "cmdline/cmdline.h"
#include "cmeasure/cmeasure.h"
#include "debugconsole/console.h"
#include "fireball/fireballs.h"
#include "freespace2/freespace.h"
#include "gamesnd/gamesnd.h"
#include "globalincs/linklist.h"
#include "graphics/grbatch.h"
#include "hud/hud.h"
#include "hud/hudartillery.h"
#include "iff_defs/iff_defs.h"
#include "io/joy_ff.h"
#include "io/timer.h"
#include "localization/localize.h"
#include "math/staticrand.h"
#include "mod_table/mod_table.h"
#include "model/modelrender.h"
#include "network/multi.h"
#include "network/multimsgs.h"
#include "network/multiutil.h"
#include "object/objcollide.h"
#include "object/object.h"
#include "parse/parselo.h"
#include "parse/scripting.h"
#include "particle/particle.h"
#include "playerman/player.h"
#include "radar/radar.h"
#include "radar/radarsetup.h"
#include "render/3d.h"
#include "ship/ship.h"
#include "ship/shiphit.h"
#include "stats/scoring.h"
#include "weapon/beam.h"
#include "weapon/corkscrew.h"
#include "weapon/emp.h"
#include "weapon/flak.h"
#include "weapon/muzzleflash.h"
#include "weapon/swarm.h"
#include "weapon/weapon.h"

Go to the source code of this file.


struct  delayed_ssm_data
struct  delayed_ssm_index_data


#define MISSILE_OBJ_USED   (1<<0)
#define FLAK_DAMAGE_SCALE   0.05f
#define SHAKE_CONST   3000


typedef struct delayed_ssm_data delayed_ssm_data
typedef struct delayed_ssm_index_data delayed_ssm_index_data


int compute_num_homing_objects (object *target_objp)
void fs2netd_add_table_validation (const char *tblname)
void parse_weapon_expl_tbl (const char *filename)
void missile_obj_list_init ()
int missile_obj_list_add (int objnum)
void missle_obj_list_remove (int index)
void missile_obj_list_rebuild ()
missile_objmissile_obj_return_address (int index)
int weapon_info_lookup (const char *name)
void parse_wi_flags (weapon_info *weaponp, int wi_flags, int wi_flags2, int wi_flags3)
void parse_shockwave_info (shockwave_create_info *sci, char *pre_char)
void init_weapon_entry (int weap_info_index)
int parse_weapon (int subtype, bool replace, const char *filename)
void translate_spawn_types ()
void parse_weaponstbl (const char *filename)
void weapon_sort_by_type ()
void weapon_clean_entries ()
void weapon_release_bitmaps ()
bool weapon_is_used (int weapon_index)
void weapon_load_bitmaps (int weapon_index)
void weapon_generate_indexes_for_substitution ()
void weapon_do_post_parse ()
void weapon_expl_info_init ()
void weapon_reset_info ()
void weapon_init ()
void weapon_close ()
void weapon_level_init ()
void weapon_render_DEPRECATED (object *obj)
void weapon_delete (object *obj)
void weapon_maybe_play_warning (weapon *wp)
void detonate_nearby_missiles (object *killer_objp, object *missile_objp)
void find_homing_object (object *weapon_objp, int num)
void find_homing_object_cmeasures_1 (object *weapon_objp)
void find_homing_object_cmeasures ()
void find_homing_object_by_sig (object *weapon_objp, int sig)
bool aspect_should_lose_target (weapon *wp)
void weapon_home (object *obj, int num, float frame_time)
void weapon_process_pre (object *obj, float frame_time)
void weapon_maybe_play_flyby_sound (object *weapon_objp, weapon *wp)
void weapon_process_post (object *obj, float frame_time)
void weapon_set_tracking_info (int weapon_objnum, int parent_objnum, int target_objnum, int target_is_locked, ship_subsys *target_subsys)
size_t * get_pointer_to_weapon_fire_pattern_index (int weapon_type, ship *shipp, ship_subsys *src_turret)
int weapon_create (vec3d *pos, matrix *porient, int weapon_type, int parent_objnum, int group_id, int is_locked, int is_spawned, float fof_cooldown, ship_subsys *src_turret)
void spawn_child_weapons (object *objp)
void weapon_play_impact_sound (weapon_info *wip, vec3d *hitpos, bool is_armed)
void weapon_hit_do_sound (object *hit_obj, weapon_info *wip, vec3d *hitpos, bool is_armed)
bool turret_weapon_has_flags (ship_weapon *swp, int flags)
void weapon_do_electronics_effect (object *ship_objp, vec3d *blast_pos, int wi_index)
int weapon_area_calc_damage (object *objp, vec3d *pos, float inner_rad, float outer_rad, float max_blast, float max_damage, float *blast, float *damage, float limit)
void weapon_area_apply_blast (vec3d *force_apply_pos, object *ship_objp, vec3d *blast_pos, float blast, int make_shockwave)
void weapon_do_area_effect (object *wobjp, shockwave_create_info *sci, vec3d *pos, object *other_obj)
bool weapon_armed (weapon *wp, bool hit_target)
void weapon_hit (object *weapon_obj, object *other_obj, vec3d *hitpos, int quadrant)
void weapon_detonate (object *objp)
int weapon_create_group_id ()
void weapon_mark_as_used (int weapon_type)
void weapons_page_in ()
void weapons_page_in_cheats ()
void weapon_get_laser_color (color *c, object *objp)
void weapon_maybe_spew_particle (object *obj)
void dcf_pspew ()
 DCF (pspew_count,"Number of particles spewed at a time")
 DCF (pspew_time,"Time between particle spews")
 dc_printf ("Particle relative velocity set to %f\n", Weapon_particle_spew_vel)
 DCF (pspew_size,"Size of spewed particles")
 DCF (pspew_life,"Lifetime of spewed particles")
 DCF (pspew_scale,"How far away particles are from the weapon path")
 DCF (pspew,"Particle spew help and status provider")
float weapon_get_damage_scale (weapon_info *wip, object *wep, object *target)
void pause_in_flight_sounds ()
void weapon_pause_sounds ()
void weapon_unpause_sounds ()
void shield_impact_explosion (vec3d *hitpos, object *objp, float radius, int idx)
void weapon_render (object *obj, draw_list *scene)
void validate_SSM_entries ()


SCP_map< SCP_string, delayed_ssm_dataDelayed_SSM_data
SCP_vector< SCP_stringDelayed_SSM_names
SCP_map< SCP_string, delayed_ssm_index_dataDelayed_SSM_indices_data
SCP_vector< SCP_stringDelayed_SSM_indices
int Weapon_flyby_sound_enabled = 1
weapon Weapons [MAX_WEAPONS]
weapon_info Weapon_info [MAX_WEAPON_TYPES]
missile_obj Missile_objs [MAX_MISSILE_OBJS]
missile_obj Missile_obj_list
char * Weapon_subtype_names []
int Num_weapon_subtypes = sizeof(Weapon_subtype_names)/sizeof(char *)
flag_def_list Burst_fire_flags []
int Num_burst_fire_flags = sizeof(Burst_fire_flags)/sizeof(flag_def_list)
weapon_explosions Weapon_explosions
SCP_vector< lod_checkerLOD_checker
int Num_weapon_types = 0
int Num_weapons = 0
int Weapons_inited = 0
int Weapon_expl_initted = 0
int laser_model_inner = -1
int laser_model_outer = -1
int missile_model = -1
int First_secondary_index = -1
int Default_cmeasure_index = -1
int Num_spawn_types = 0
char ** Spawn_names = NULL
int Num_player_weapon_precedence
int Player_weapon_precedence [MAX_WEAPON_TYPES]
int Weapon_impact_timer
const float weapon_glow_scale_f = 2.3f
const float weapon_glow_scale_r = 2.3f
const float weapon_glow_scale_l = 1.5f
const int weapon_glow_alpha = 217
int Homing_hits = 0
int Homing_misses = 0
int Weapons_created = 0
int Weapon_particle_spew_count = 1
int Weapon_particle_spew_time = 25
float Weapon_particle_spew_vel = 0.4f
float Weapon_particle_spew_radius = 2.0f
float Weapon_particle_spew_lifetime = 0.15f
float Weapon_particle_spew_scale = 0.8f

Macro Definition Documentation


Definition at line 480 of file weapons.cpp.


Definition at line 135 of file weapons.cpp.


Definition at line 134 of file weapons.cpp.

#define FLAK_DAMAGE_SCALE   0.05f

Definition at line 141 of file weapons.cpp.


Definition at line 144 of file weapons.cpp.


Definition at line 130 of file weapons.cpp.


Definition at line 151 of file weapons.cpp.


Definition at line 82 of file weapons.cpp.

#define MISSILE_OBJ_USED   (1<<0)

Definition at line 81 of file weapons.cpp.

#define SHAKE_CONST   3000

Definition at line 138 of file weapons.cpp.


Definition at line 147 of file weapons.cpp.


Definition at line 1126 of file weapons.cpp.

Typedef Documentation

Function Documentation

bool aspect_should_lose_target ( weapon wp)

Definition at line 4227 of file weapons.cpp.

int compute_num_homing_objects ( object target_objp)
number of objects homing on object *target_objp

Definition at line 5919 of file aicode.cpp.

dc_printf ( "Particle relative velocity set to %f\n ,
DCF ( pspew_count  ,
"Number of particles spewed at a time"   

Definition at line 7002 of file weapons.cpp.

DCF ( pspew_time  ,
"Time between particle spews"   

Definition at line 7019 of file weapons.cpp.

DCF ( pspew_size  ,
"Size of spewed particles"   

Definition at line 7053 of file weapons.cpp.

DCF ( pspew_life  ,
"Lifetime of spewed particles"   

Definition at line 7070 of file weapons.cpp.

DCF ( pspew_scale  ,
"How far away particles are from the weapon path  

Definition at line 7087 of file weapons.cpp.

DCF ( pspew  ,
"Particle spew help and status provider"   

Definition at line 7104 of file weapons.cpp.

void dcf_pspew ( )

Debug console functionality

void detonate_nearby_missiles ( object killer_objp,
object missile_objp 

Detonate all missiles near this countermeasure.

Definition at line 3899 of file weapons.cpp.

void find_homing_object ( object weapon_objp,
int  num 

Find an object for weapon num (object *weapon_objp) to home on due to heat.

Definition at line 3945 of file weapons.cpp.

void find_homing_object_by_sig ( object weapon_objp,
int  sig 

Find object with signature "sig" and make weapon home on it.

Definition at line 4196 of file weapons.cpp.

void find_homing_object_cmeasures ( )

Someone launched countermeasures. For all heat-seeking homing objects, see if should favor tracking a countermeasure instead.

Definition at line 4170 of file weapons.cpp.

void find_homing_object_cmeasures_1 ( object weapon_objp)

Scan all countermeasures. Maybe make weapon_objp home on it.

Definition at line 4075 of file weapons.cpp.

void fs2netd_add_table_validation ( const char *  tblname)

Definition at line 1554 of file fs2netd_client.cpp.

size_t* get_pointer_to_weapon_fire_pattern_index ( int  weapon_type,
ship shipp,
ship_subsys src_turret 

Definition at line 5214 of file weapons.cpp.

void init_weapon_entry ( int  weap_info_index)

Definition at line 833 of file weapons.cpp.

int missile_obj_list_add ( int  objnum)

Add a node from the Missile_obj_list.

Only called from weapon_create()

Definition at line 406 of file weapons.cpp.

void missile_obj_list_init ( )

Clear out the Missile_obj_list

Definition at line 392 of file weapons.cpp.

void missile_obj_list_rebuild ( )

Called by the save/restore code to rebuild Missile_obj_list

Definition at line 441 of file weapons.cpp.

missile_obj* missile_obj_return_address ( int  index)

Called externally to generate an address from an index into the Missile_objs[] array

Definition at line 458 of file weapons.cpp.

void missle_obj_list_remove ( int  index)

Remove a node from the Missile_obj_list.

Only called from weapon_delete()

Definition at line 431 of file weapons.cpp.

void parse_shockwave_info ( shockwave_create_info sci,
char *  pre_char 

Definition at line 760 of file weapons.cpp.

int parse_weapon ( int  subtype,
bool  replace,
const char *  filename 

Definition at line 1128 of file weapons.cpp.

void parse_weapon_expl_tbl ( const char *  filename)

Definition at line 339 of file weapons.cpp.

void parse_weaponstbl ( const char *  filename)

Definition at line 2898 of file weapons.cpp.

void parse_wi_flags ( weapon_info weaponp,
int  wi_flags,
int  wi_flags2,
int  wi_flags3 

Definition at line 483 of file weapons.cpp.

void pause_in_flight_sounds ( )

Definition at line 7231 of file weapons.cpp.

void shield_impact_explosion ( vec3d hitpos,
object objp,
float  radius,
int  idx 

Definition at line 7263 of file weapons.cpp.

void spawn_child_weapons ( object objp)

Spawn child weapons from object *objp.

Definition at line 5676 of file weapons.cpp.

void translate_spawn_types ( )

For all weapons that spawn weapons, given an index at weaponp->spawn_type, convert the strings in Spawn_names to indices in the Weapon_types array.

Definition at line 2865 of file weapons.cpp.

bool turret_weapon_has_flags ( ship_weapon swp,
int  flags 

Returns true if any of the weapons in swp have flags

doesn't work for WIF2

Definition at line 306 of file aiturret.cpp.

void validate_SSM_entries ( )

Definition at line 7461 of file weapons.cpp.

void weapon_area_apply_blast ( vec3d force_apply_pos,
object ship_objp,
vec3d blast_pos,
float  blast,
int  make_shockwave 

Apply the blast effects of an explosion to a ship

force_apply_posWorld pos of where force is applied to object
ship_objpObject pointer of ship receiving the blast
blast_posWorld pos of blast center
blastForce of blast
make_shockwaveBoolean, whether to create a shockwave or not

Definition at line 6080 of file weapons.cpp.

int weapon_area_calc_damage ( object objp,
vec3d pos,
float  inner_rad,
float  outer_rad,
float  max_blast,
float  max_damage,
float blast,
float damage,
float  limit 

Calculate the damage for an object based on the location of an area-effect explosion.

objpObject pointer ship receiving blast effect
posWorld pos of blast center
inner_radSmallest radius at which full damage is done
outer_radRadius at which no damage is done
max_blastMaximum blast possible from explosion
max_damageMaximum damage possible from explosion
blastOUTPUT PARAMETER: receives blast value from explosion
damageOUTPUT PARAMETER: receives damage value from explosion
limitA limit on the area, needed for shockwave damage
No damage occurred, -1
Damage occured, 0

Definition at line 6025 of file weapons.cpp.

bool weapon_armed ( weapon wp,
bool  hit_target 

Definition at line 6208 of file weapons.cpp.

void weapon_clean_entries ( )

Do any post-parse cleaning on weapon entries

Definition at line 3144 of file weapons.cpp.

void weapon_close ( )

Call from game_shutdown() only!!

Definition at line 3545 of file weapons.cpp.

int weapon_create ( vec3d pos,
matrix porient,
int  weapon_type,
int  parent_objnum,
int  group_id,
int  is_locked,
int  is_spawned,
float  fof_cooldown,
ship_subsys src_turret 

Definition at line 5246 of file weapons.cpp.

int weapon_create_group_id ( )

Definition at line 6481 of file weapons.cpp.

void weapon_delete ( object obj)

Definition at line 3822 of file weapons.cpp.

void weapon_detonate ( object objp)

Definition at line 6450 of file weapons.cpp.

void weapon_do_area_effect ( object wobjp,
shockwave_create_info sci,
vec3d pos,
object other_obj 

Do the area effect for a weapon

wobjpObject pointer to weapon causing explosion
sciShockwave info
posWorld pos of explosion center
other_objObject pointer to ship that weapon impacted on (can be NULL)

Definition at line 6118 of file weapons.cpp.

void weapon_do_electronics_effect ( object ship_objp,
vec3d blast_pos,
int  wi_index 

Distrupt any subsystems that fall into damage sphere of this Electronics missile

ship_objpPointer to ship that holds subsystem
blast_posWorld pos of weapon blast
wi_indexWeapon info index of weapon causing blast

Definition at line 5934 of file weapons.cpp.

void weapon_do_post_parse ( )

Definition at line 3436 of file weapons.cpp.

void weapon_expl_info_init ( )

Definition at line 3487 of file weapons.cpp.

void weapon_generate_indexes_for_substitution ( )

Checks all of the weapon infos for substitution patterns and caches the weapon_index of any that it finds.

Definition at line 3412 of file weapons.cpp.

float weapon_get_damage_scale ( weapon_info wip,
object wep,
object target 

Return a scale factor for damage which should be applied for 2 collisions

Definition at line 7137 of file weapons.cpp.

void weapon_get_laser_color ( color c,
object objp 

Get the "color" of the laser at the given moment (since glowing lasers can cycle colors)

Definition at line 6707 of file weapons.cpp.

void weapon_hit ( object weapon_obj,
object other_obj,
vec3d hitpos,
int  quadrant 

Called when a weapon hits something (or, in the case of missiles explodes for any particular reason)

Definition at line 6253 of file weapons.cpp.

void weapon_hit_do_sound ( object hit_obj,
weapon_info wip,
vec3d hitpos,
bool  is_armed 

Play a sound effect when a weapon hits a ship

To elimate the "stereo" effect of two lasers hitting at nearly the same time, and to reduce the number of sound channels used, only play one impact sound if IMPACT_SOUND_DELTA has elapsed

Uses Weapon_impact_timer global for timer variable

Definition at line 5834 of file weapons.cpp.

void weapon_home ( object obj,
int  num,
float  frame_time 

Make weapon num home. It's also object *obj.

Definition at line 4256 of file weapons.cpp.

int weapon_info_lookup ( const char *  name)

Return the index of Weapon_info[].name that is *name.

Definition at line 467 of file weapons.cpp.

void weapon_init ( )

This will get called once at game startup

Definition at line 3516 of file weapons.cpp.

bool weapon_is_used ( int  weapon_index)

Definition at line 3269 of file weapons.cpp.

void weapon_level_init ( )

This will get called at the start of each level.

Definition at line 3582 of file weapons.cpp.

void weapon_load_bitmaps ( int  weapon_index)

Definition at line 3275 of file weapons.cpp.

void weapon_mark_as_used ( int  weapon_type)

Call before weapons_page_in to mark a weapon as used

Definition at line 6497 of file weapons.cpp.

void weapon_maybe_play_flyby_sound ( object weapon_objp,
weapon wp 

Maybe play a "whizz sound" if close enough to view position

Definition at line 4717 of file weapons.cpp.

void weapon_maybe_play_warning ( weapon wp)

Check if missile is newly locked onto the Player, maybe play a launch warning

Definition at line 3877 of file weapons.cpp.

void weapon_maybe_spew_particle ( object obj)

For weapons flagged as particle spewers, spew particles. wheee

Definition at line 6767 of file weapons.cpp.

void weapon_pause_sounds ( )

Definition at line 7248 of file weapons.cpp.

void weapon_play_impact_sound ( weapon_info wip,
vec3d hitpos,
bool  is_armed 

Figures out whether to play disarmed or armed hit sound, checks that the chosen one exists, and plays it

Definition at line 5809 of file weapons.cpp.

void weapon_process_post ( object obj,
float  frame_time 

Definition at line 4775 of file weapons.cpp.

void weapon_process_pre ( object obj,
float  frame_time 

Definition at line 4667 of file weapons.cpp.

void weapon_release_bitmaps ( )

Definition at line 3177 of file weapons.cpp.

void weapon_render ( object obj,
draw_list scene 

Definition at line 7268 of file weapons.cpp.

void weapon_render_DEPRECATED ( object obj)

Definition at line 3625 of file weapons.cpp.

void weapon_reset_info ( )

Definition at line 3505 of file weapons.cpp.

void weapon_set_tracking_info ( int  weapon_objnum,
int  parent_objnum,
int  target_objnum,
int  target_is_locked,
ship_subsys target_subsys 

Update weapon tracking information.

Definition at line 5093 of file weapons.cpp.

void weapon_sort_by_type ( )

Definition at line 2986 of file weapons.cpp.

void weapon_unpause_sounds ( )

Definition at line 7257 of file weapons.cpp.

void weapons_page_in ( )

Definition at line 6512 of file weapons.cpp.

void weapons_page_in_cheats ( )

Page_in function for cheaters, grabs all weapons that weren't already in a mission and loads the models for them.

Non-model graphics elements will get loaded when they are rendered for the first time. Maybe not the best way to do this but faster and a lot less error prone.

Definition at line 6650 of file weapons.cpp.

Variable Documentation

flag_def_list Burst_fire_flags[]
Initial value:
= {
{ "fast firing", WBF_FAST_FIRING, 0 },
{ "random length", WBF_RANDOM_LENGTH, 0 }
Definition: weapon.h:149
Definition: weapon.h:150

Definition at line 94 of file weapons.cpp.

int Default_cmeasure_index = -1

Definition at line 117 of file weapons.cpp.

SCP_map<SCP_string, delayed_ssm_data> Delayed_SSM_data

Definition at line 60 of file weapons.cpp.

SCP_vector<SCP_string> Delayed_SSM_indices

Definition at line 68 of file weapons.cpp.

SCP_map<SCP_string, delayed_ssm_index_data> Delayed_SSM_indices_data

Definition at line 67 of file weapons.cpp.

SCP_vector<SCP_string> Delayed_SSM_names

Definition at line 61 of file weapons.cpp.

int First_secondary_index = -1

Definition at line 116 of file weapons.cpp.

int Homing_hits = 0

Definition at line 4709 of file weapons.cpp.

int Homing_misses = 0

Definition at line 4709 of file weapons.cpp.

int laser_model_inner = -1

Definition at line 111 of file weapons.cpp.

int laser_model_outer = -1

Definition at line 112 of file weapons.cpp.

SCP_vector<lod_checker> LOD_checker

Definition at line 103 of file weapons.cpp.

int missile_model = -1

Definition at line 114 of file weapons.cpp.

missile_obj Missile_obj_list

Definition at line 84 of file weapons.cpp.

Definition at line 83 of file weapons.cpp.

int Num_burst_fire_flags = sizeof(Burst_fire_flags)/sizeof(flag_def_list)

Definition at line 99 of file weapons.cpp.

int Num_player_weapon_precedence

Definition at line 124 of file weapons.cpp.

int Num_spawn_types = 0

Definition at line 121 of file weapons.cpp.

int Num_weapon_subtypes = sizeof(Weapon_subtype_names)/sizeof(char *)

Definition at line 92 of file weapons.cpp.

int Num_weapon_types = 0

Definition at line 105 of file weapons.cpp.

int Num_weapons = 0

Definition at line 107 of file weapons.cpp.

int Player_weapon_precedence[MAX_WEAPON_TYPES]

Definition at line 125 of file weapons.cpp.

char** Spawn_names = NULL

Definition at line 122 of file weapons.cpp.

int Weapon_expl_initted = 0

Definition at line 109 of file weapons.cpp.

weapon_explosions Weapon_explosions

Definition at line 101 of file weapons.cpp.

int Weapon_flyby_sound_enabled = 1

Definition at line 72 of file weapons.cpp.

const int weapon_glow_alpha = 217

Definition at line 3623 of file weapons.cpp.

const float weapon_glow_scale_f = 2.3f

Definition at line 3620 of file weapons.cpp.

const float weapon_glow_scale_l = 1.5f

Definition at line 3622 of file weapons.cpp.

const float weapon_glow_scale_r = 2.3f

Definition at line 3621 of file weapons.cpp.

int Weapon_impact_timer

Definition at line 131 of file weapons.cpp.

Definition at line 79 of file weapons.cpp.

int Weapon_particle_spew_count = 1

Definition at line 6757 of file weapons.cpp.

float Weapon_particle_spew_lifetime = 0.15f

Definition at line 6761 of file weapons.cpp.

float Weapon_particle_spew_radius = 2.0f

Definition at line 6760 of file weapons.cpp.

float Weapon_particle_spew_scale = 0.8f

Definition at line 6762 of file weapons.cpp.

int Weapon_particle_spew_time = 25

Definition at line 6758 of file weapons.cpp.

float Weapon_particle_spew_vel = 0.4f

Definition at line 6759 of file weapons.cpp.

char* Weapon_subtype_names[]
Initial value:
= {

Definition at line 87 of file weapons.cpp.

weapon Weapons[MAX_WEAPONS]

Definition at line 78 of file weapons.cpp.

int Weapons_created = 0

Create a weapon object

Index of weapon in the Objects[] array, -1 if the weapon object was not created

Definition at line 5245 of file weapons.cpp.

int Weapons_inited = 0

Definition at line 108 of file weapons.cpp.