FS2_Open
Open source remastering of the Freespace 2 engine
asteroid.cpp File Reference
#include "asteroid/asteroid.h"
#include "debugconsole/console.h"
#include "fireball/fireballs.h"
#include "freespace2/freespace.h"
#include "gamesnd/gamesnd.h"
#include "globalincs/compatibility.h"
#include "globalincs/linklist.h"
#include "globalincs/systemvars.h"
#include "hud/hud.h"
#include "hud/hudescort.h"
#include "hud/hudgauges.h"
#include "hud/hudtarget.h"
#include "iff_defs/iff_defs.h"
#include "io/timer.h"
#include "localization/localize.h"
#include "math/staticrand.h"
#include "math/vecmat.h"
#include "model/model.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 "render/3d.h"
#include "ship/ship.h"
#include "ship/shiphit.h"
#include "species_defs/species_defs.h"
#include "stats/scoring.h"
#include "weapon/weapon.h"
#include <algorithm>

Go to the source code of this file.

Macros

#define ASTEROID_OBJ_USED   (1<<0)
 
#define MAX_ASTEROID_OBJS   MAX_ASTEROIDS
 
#define SMALL_DEBRIS_WEIGHT   8
 
#define MEDIUM_DEBRIS_WEIGHT   4
 
#define LARGE_DEBRIS_WEIGHT   1
 
#define ASTEROID_CHECK_WRAP_TIMESTAMP   2000
 
#define ASTEROID_UPDATE_COLLIDE_TIMESTAMP   2000
 
#define ASTEROID_MIN_COLLIDE_TIME   24
 

Functions

void asteroid_update_collide (object *objp)
 
void asteroid_obj_list_init ()
 
int asteroid_obj_list_add (int objnum)
 
void asteroid_obj_list_remove (object *obj)
 
float asteroid_cap_speed (int asteroid_info_index, float speed)
 
int asteroid_in_inner_bound_with_axes (asteroid_field *asfieldp, vec3d *pos, float delta)
 
int asteroid_in_inner_bound (asteroid_field *asfieldp, vec3d *pos, float delta)
 
void inner_bound_pos_fixup (asteroid_field *asfieldp, vec3d *pos)
 
objectasteroid_create (asteroid_field *asfieldp, int asteroid_type, int asteroid_subtype)
 
void asteroid_sub_create (object *parent_objp, int asteroid_type, vec3d *relvec)
 
void asteroid_load (int asteroid_info_index, int asteroid_subtype)
 
int get_debris_from_same_group (int index)
 
int get_debris_weight (int ship_debris_index)
 
void asteroid_create_all ()
 
void asteroid_level_init ()
 
int asteroid_should_wrap (object *objp, asteroid_field *asfieldp)
 
void asteroid_wrap_pos (object *objp, asteroid_field *asfieldp)
 
int asteroid_is_targeted (object *objp)
 
void asteroid_aim_at_target (object *objp, object *asteroid_objp, float delta_time)
 
void maybe_throw_asteroid (int count)
 
void asteroid_delete (object *obj)
 
void asteroid_maybe_reposition (object *objp, asteroid_field *asfieldp)
 
void lerp (float *goal, float f1, float f2, float scale)
 
void asteroid_process_pre (object *objp)
 
int asteroid_check_collision (object *pasteroid, object *other_obj, vec3d *hitpos, collision_info_struct *asteroid_hit_info)
 
void asteroid_render_DEPRECATED (object *obj)
 
void asteroid_render (object *obj, draw_list *scene)
 
void asc_get_relvec (vec3d *relvec, object *other_obj, vec3d *hitpos)
 
float asteroid_get_fireball_scale_multiplier (int num)
 
float asteroid_create_explosion (object *objp)
 
void asteriod_explode_sound (object *objp, int type, int play_loud)
 
void asteroid_do_area_effect (object *asteroid_objp)
 
void asteroid_hit (object *pasteroid_obj, object *other_obj, vec3d *hitpos, float damage)
 
void asteroid_level_close ()
 
 DCF_BOOL2 (asteroids, Asteroids_enabled,"enables or disables asteroids","Usage: asteroids [bool]\nTurns asteroid system on/off. If nothing passed, then toggles it.\n")
 
void hud_target_asteroid ()
 
int asteroid_count ()
 
void asteroid_maybe_break_up (object *pasteroid_obj)
 
int asteroid_get_random_in_cone (vec3d *pos, vec3d *dir, float ang, int danger)
 
void asteroid_test_collide (object *pasteroid_obj, object *pship_obj, mc_info *mc, bool lazy=false)
 
int asteroid_will_collide (object *pasteroid_obj, object *escort_objp)
 
int asteroid_valid_ship_to_warn_collide (ship *shipp)
 
void asteroid_update_collide_flag (object *asteroid_objp)
 
void asteroid_verify_collide_objnum (asteroid *asp)
 
void asteroid_process_post (object *obj)
 
int asteroid_collide_objnum (object *asteroid_objp)
 
float asteroid_time_to_impact (object *asteroid_objp)
 
void asteroid_parse_section (asteroid_info *asip)
 
void asteroid_parse_tbl ()
 
int count_incident_asteroids ()
 
int set_asteroid_throw_objnum ()
 
void asteroid_frame ()
 
void asteroid_init ()
 
void asteroid_show_brackets ()
 
void asteroid_target_closest_danger ()
 
void asteroid_page_in ()
 

Variables

asteroid_obj Asteroid_objs [MAX_ASTEROID_OBJS]
 
asteroid_obj Asteroid_obj_list
 
int Asteroids_enabled = 1
 
int Num_asteroids = 0
 
int Asteroid_throw_objnum = -1
 
int Next_asteroid_throw
 
SCP_vector< asteroid_infoAsteroid_info
 
asteroid Asteroids [MAX_ASTEROIDS]
 
asteroid_field Asteroid_field
 
char Asteroid_icon_closeup_model [NAME_LENGTH]
 
vec3d Asteroid_icon_closeup_position
 
float Asteroid_icon_closeup_zoom
 
int Cmdline_targetinfo
 

Macro Definition Documentation

#define ASTEROID_CHECK_WRAP_TIMESTAMP   2000

Definition at line 73 of file asteroid.cpp.

#define ASTEROID_MIN_COLLIDE_TIME   24

Definition at line 75 of file asteroid.cpp.

#define ASTEROID_OBJ_USED   (1<<0)

Definition at line 47 of file asteroid.cpp.

#define ASTEROID_UPDATE_COLLIDE_TIMESTAMP   2000

Definition at line 74 of file asteroid.cpp.

#define LARGE_DEBRIS_WEIGHT   1

Definition at line 55 of file asteroid.cpp.

#define MAX_ASTEROID_OBJS   MAX_ASTEROIDS

Definition at line 48 of file asteroid.cpp.

#define MEDIUM_DEBRIS_WEIGHT   4

Definition at line 54 of file asteroid.cpp.

#define SMALL_DEBRIS_WEIGHT   8

Definition at line 53 of file asteroid.cpp.

Function Documentation

void asc_get_relvec ( vec3d relvec,
object other_obj,
vec3d hitpos 
)

Create a normalized vector generally in the direction from *hitpos to other_obj->pos

Definition at line 1216 of file asteroid.cpp.

void asteriod_explode_sound ( object objp,
int  type,
int  play_loud 
)

Play sound when asteroid explodes

Definition at line 1299 of file asteroid.cpp.

void asteroid_aim_at_target ( object objp,
object asteroid_objp,
float  delta_time 
)

Create an asteroid that will hit object *objp in delta_time seconds

Definition at line 748 of file asteroid.cpp.

float asteroid_cap_speed ( int  asteroid_info_index,
float  speed 
)

Prevent speed from getting too huge so it's hard to catch up to an asteroid.

Definition at line 142 of file asteroid.cpp.

int asteroid_check_collision ( object pasteroid,
object other_obj,
vec3d hitpos,
collision_info_struct asteroid_hit_info 
)

Definition at line 918 of file asteroid.cpp.

int asteroid_collide_objnum ( object asteroid_objp)

Find the object number of the object the asteroid is about to impact

Returns
the object number that the asteroid is about to impact

Definition at line 1781 of file asteroid.cpp.

int asteroid_count ( )

Return the number of active asteroids

Definition at line 1473 of file asteroid.cpp.

object* asteroid_create ( asteroid_field asfieldp,
int  asteroid_type,
int  asteroid_subtype 
)

Create a single asteroid

Definition at line 231 of file asteroid.cpp.

void asteroid_create_all ( )

Create all the asteroids for the mission

Definition at line 529 of file asteroid.cpp.

float asteroid_create_explosion ( object objp)

Create asteroid explosion

Returns
expected time for explosion anim to last, in seconds

Definition at line 1267 of file asteroid.cpp.

void asteroid_delete ( object obj)

Delete asteroid from Asteroid_used_list

Definition at line 826 of file asteroid.cpp.

void asteroid_do_area_effect ( object asteroid_objp)

Do the area effect for an asteroid exploding

Parameters
asteroid_objpobject pointer to asteriod causing explosion

Definition at line 1329 of file asteroid.cpp.

void asteroid_frame ( )

Definition at line 2122 of file asteroid.cpp.

float asteroid_get_fireball_scale_multiplier ( int  num)

Return multiplier on asteroid radius for fireball

Definition at line 1238 of file asteroid.cpp.

int asteroid_get_random_in_cone ( vec3d pos,
vec3d dir,
float  ang,
int  danger 
)

Definition at line 1600 of file asteroid.cpp.

void asteroid_hit ( object pasteroid_obj,
object other_obj,
vec3d hitpos,
float  damage 
)

Upon asteroid asteroid_obj being hit. Apply damage and maybe make it break into smaller asteroids.

Parameters
pasteroid_objpointer to asteroid object getting hit
other_objobject that hit asteroid, can be NULL if asteroid hit by area effect
hitposworld position asteroid was hit, can be NULL if hit by area effect
damageamount of damage to apply to asteroid

Definition at line 1368 of file asteroid.cpp.

int asteroid_in_inner_bound ( asteroid_field asfieldp,
vec3d pos,
float  delta 
)

Check if asteroid is within inner bound

Returns
0 if not inside or no inner bound, 1 if inside inner bound

Definition at line 192 of file asteroid.cpp.

int asteroid_in_inner_bound_with_axes ( asteroid_field asfieldp,
vec3d pos,
float  delta 
)

Returns whether position is inside inner bounding volume

Sum together the following: 1 inside x, 2 inside y, 4 inside z inside only when sum = 7

Definition at line 168 of file asteroid.cpp.

void asteroid_init ( )

Called once, at game start. Do any one-time initializations here

Definition at line 2140 of file asteroid.cpp.

int asteroid_is_targeted ( object objp)

Is asteroid targeted?

Returns
!0 if this asteroid is a target for any ship, otherwise return 0

Definition at line 727 of file asteroid.cpp.

void asteroid_level_close ( )

De-init asteroids, called from game_level_close()

Definition at line 1423 of file asteroid.cpp.

void asteroid_level_init ( )

Init asteriod system for the level, called from game_level_init()

Definition at line 628 of file asteroid.cpp.

void asteroid_load ( int  asteroid_info_index,
int  asteroid_subtype 
)

Load in an asteroid model

Definition at line 446 of file asteroid.cpp.

void asteroid_maybe_break_up ( object pasteroid_obj)

See if asteroid should split up. We delay splitting up to allow the explosion animation to play for a bit.

Definition at line 1482 of file asteroid.cpp.

void asteroid_maybe_reposition ( object objp,
asteroid_field asfieldp 
)

See if we should reposition the asteroid. Only reposition if oustide the bounding volume and the player isn't looking towards the asteroid.

Definition at line 850 of file asteroid.cpp.

int asteroid_obj_list_add ( int  objnum)

Add a node from the Asteroid_obj_list. Only called from weapon_create()

Definition at line 105 of file asteroid.cpp.

void asteroid_obj_list_init ( )

Clear out the Asteroid_obj_list

Definition at line 91 of file asteroid.cpp.

void asteroid_obj_list_remove ( object obj)

Remove a node from the Asteroid_obj_list. Only called from weapon_delete()

Definition at line 127 of file asteroid.cpp.

void asteroid_page_in ( )

Definition at line 2222 of file asteroid.cpp.

void asteroid_parse_section ( asteroid_info asip)

Read in a single asteroid section from asteroid.tbl

Definition at line 1820 of file asteroid.cpp.

void asteroid_parse_tbl ( )

Read in data from asteroid.tbl into Asteroid_info[] array.

After this function is completes, the Asteroid_info[] array will contain exactly three asteroids per species plus exactly three generic asteroids. These three asteroids are a set of small, medium, and large asteroids in that exact order.

If asteroid.tbl contains too many or too few asteroids as per the rules above this function will abort the engine with an error message stating the number expected and it will write to the debug.log how everything was parsed.

Note that by saying "asteroid" this code is talking about the asteroids and the debris that make up asteroid fields and debris fields. Which means that these debris have nothing to do with the debris of ships that explode, however these are the same debris and asteroids that get flung at a ship that is being protected.

Definition at line 1920 of file asteroid.cpp.

void asteroid_process_post ( object obj)

Definition at line 1750 of file asteroid.cpp.

void asteroid_process_pre ( object objp)

Definition at line 908 of file asteroid.cpp.

void asteroid_render ( object obj,
draw_list scene 
)

Definition at line 1189 of file asteroid.cpp.

void asteroid_render_DEPRECATED ( object obj)

Definition at line 1170 of file asteroid.cpp.

int asteroid_should_wrap ( object objp,
asteroid_field asfieldp 
)

Should asteroid wrap from one end of the asteroid field to the other. Multiplayer clients will always return 0 from this function. We will force a wrap on the clients when server tells us

Returns
!0 if asteroid should be wrapped, 0 otherwise.

Definition at line 645 of file asteroid.cpp.

void asteroid_show_brackets ( )

Draw brackets around on-screen asteroids that are about to collide, otherwise draw an offscreen indicator

Definition at line 2150 of file asteroid.cpp.

void asteroid_sub_create ( object parent_objp,
int  asteroid_type,
vec3d relvec 
)

Create asteroids when parent_objp blows up.

Definition at line 405 of file asteroid.cpp.

void asteroid_target_closest_danger ( )

Target the closest danger asteroid to the player

Definition at line 2192 of file asteroid.cpp.

void asteroid_test_collide ( object pasteroid_obj,
object pship_obj,
mc_info mc,
bool  lazy = false 
)

Definition at line 1619 of file asteroid.cpp.

float asteroid_time_to_impact ( object asteroid_objp)

Find the time until asteroid will collide with object

Returns
the time until the asteroid will impact its collide_objnum

Definition at line 1790 of file asteroid.cpp.

void asteroid_update_collide ( object objp)

Force updating of pair stuff for asteroid *objp.

Definition at line 80 of file asteroid.cpp.

void asteroid_update_collide_flag ( object asteroid_objp)

See if asteroid will collide with a large ship on the escort list in the next ASTEROID_MIN_COLLIDE_TIME seconds.

Definition at line 1701 of file asteroid.cpp.

int asteroid_valid_ship_to_warn_collide ( ship shipp)

Warn if asteroid on collision path with ship

Returns
!0 if we should warn about asteroid hitting ship, otherwise return 0

Definition at line 1679 of file asteroid.cpp.

void asteroid_verify_collide_objnum ( asteroid asp)

Ensure that the collide objnum for the asteroid is still valid

Definition at line 1740 of file asteroid.cpp.

int asteroid_will_collide ( object pasteroid_obj,
object escort_objp 
)

Test if asteroid will collide with escort ship within ASTEROID_MIN_COLLIDE_TIME seconds

Returns
!0 if the asteroid will collide with the escort

Definition at line 1661 of file asteroid.cpp.

void asteroid_wrap_pos ( object objp,
asteroid_field asfieldp 
)

Wrap an asteroid from one end of the asteroid field to the other

Definition at line 690 of file asteroid.cpp.

int count_incident_asteroids ( )

Return number of asteroids expected to collide with a ship.

Definition at line 2071 of file asteroid.cpp.

DCF_BOOL2 ( asteroids  ,
Asteroids_enabled  ,
"enables or disables asteroids"  ,
"Usage: asteroids \nTurns asteroid system on/off. If nothing  passed[bool],
then toggles it.\n  
)
int get_debris_from_same_group ( int  index)

Randomly choose a debris model within the current group

Definition at line 490 of file asteroid.cpp.

int get_debris_weight ( int  ship_debris_index)

Returns a weight that depends on asteroid size.

The weight is then used to determine the frequencty of different sizes of ship debris

Definition at line 506 of file asteroid.cpp.

void hud_target_asteroid ( )

Definition at line 1441 of file asteroid.cpp.

void inner_bound_pos_fixup ( asteroid_field asfieldp,
vec3d pos 
)

Repositions asteroid outside the inner box on all 3 axes

Moves to the other side of the inner box a distance delta from edge of box

Definition at line 206 of file asteroid.cpp.

void lerp ( float goal,
float  f1,
float  f2,
float  scale 
)

Definition at line 903 of file asteroid.cpp.

void maybe_throw_asteroid ( int  count)

Call once per frame to maybe throw an asteroid at a ship.

Parameters
countasteroids already targeted on

Definition at line 776 of file asteroid.cpp.

int set_asteroid_throw_objnum ( )

Pick object to throw asteroids at. Pick any capital or big ship inside the bounds of the asteroid field.

Definition at line 2095 of file asteroid.cpp.

Variable Documentation

asteroid_field Asteroid_field

Definition at line 64 of file asteroid.cpp.

char Asteroid_icon_closeup_model[NAME_LENGTH]

Definition at line 69 of file asteroid.cpp.

vec3d Asteroid_icon_closeup_position

Definition at line 70 of file asteroid.cpp.

float Asteroid_icon_closeup_zoom

Definition at line 71 of file asteroid.cpp.

SCP_vector< asteroid_info > Asteroid_info

Definition at line 62 of file asteroid.cpp.

asteroid_obj Asteroid_obj_list

Definition at line 50 of file asteroid.cpp.

Definition at line 49 of file asteroid.cpp.

int Asteroid_throw_objnum = -1

Definition at line 59 of file asteroid.cpp.

asteroid Asteroids[MAX_ASTEROIDS]

Definition at line 63 of file asteroid.cpp.

int Asteroids_enabled = 1

Definition at line 57 of file asteroid.cpp.

int Cmdline_targetinfo

Definition at line 367 of file cmdline.cpp.

int Next_asteroid_throw

Definition at line 60 of file asteroid.cpp.

int Num_asteroids = 0

Definition at line 58 of file asteroid.cpp.