naev 0.12.6
asteroid.c File Reference

Handles asteroid-related stuff. More...

#include "asteroid.h"
#include "array.h"
#include "camera.h"
#include "conf.h"
#include "damagetype.h"
#include "explosion.h"
#include "font.h"
#include "gatherable.h"
#include "ndata.h"
#include "nlua_asteroid.h"
#include "ntracing.h"
#include "nxml.h"
#include "opengl.h"
#include "player.h"
#include "rng.h"
#include "sound.h"
#include "space.h"
Include dependency graph for asteroid.c:

Go to the source code of this file.

Data Structures

struct  Debris
 Represents a small asteroid debris rendered in the player frame. More...

Macros

#define MELEMENT(o, s)

Functions

static int asttype_cmp (const void *p1, const void *p2)
 Compares two asteroid types.
static int asttype_parse (AsteroidType *at, const char *file)
 Parses the XML of an asteroid type.
static int asteroid_loadPLG (AsteroidType *temp, const char *buf)
 Loads the collision polygon for an asteroid type.
static int astgroup_cmp (const void *p1, const void *p2)
 Compares two asteroid type groups.
static int astgroup_parse (AsteroidTypeGroup *ag, const char *file)
 Parses an asteroid type group from a file.
static int asttype_load (void)
 Loads the asteroids types.
static int asteroid_updateSingle (Asteroid *a)
static void asteroid_renderSingle (const Asteroid *a)
 Renders an asteroid.
static void debris_renderSingle (const Debris *d, double cx, double cy)
 Renders a debris.
static void debris_init (Debris *deb)
 Initializes a debris.
static int asteroid_init (Asteroid *ast, const AsteroidAnchor *field)
 Initializes an asteroid.
void asteroids_update (double dt)
 Controls fleet spawning.
void asteroids_init (void)
 Initializes the system.
void asteroids_computeInternals (AsteroidAnchor *a)
 Updates internal alues of an asteroid field.
int asteroids_load (void)
 Loads the asteroids.
void asteroids_renderOverlay (void)
 Renders the system overlay.
void asteroids_render (void)
 Renders the current systems' spobs.
void asteroid_initAnchor (AsteroidAnchor *ast)
 Initializes an asteroid anchor.
void asteroid_freeAnchor (AsteroidAnchor *ast)
 Frees an asteroid anchor.
void asteroid_freeExclude (AsteroidExclusion *exc)
 Frees an asteroid exclusion.
void asteroids_free (void)
 Cleans up the system.
int asteroids_inField (const vec2 *p)
 See if the position is in an asteroid field.
const AsteroidTypeasttype_getAll (void)
 Gets all the asteroid types.
AsteroidTypeasttype_getName (const char *name)
 Gets the ID of an asteroid type by name.
const AsteroidTypeGroupastgroup_getAll (void)
 Gets all the asteroid type groups.
AsteroidTypeGroupastgroup_getName (const char *name)
 Gets an asteroid type group by name.
void asteroid_hit (Asteroid *a, const Damage *dmg, int max_rarity, double mining_bonus)
 Hits an asteroid.
void asteroid_explode (Asteroid *a, int max_rarity, double mining_bonus)
 Makes an asteroid explode.
void asteroid_collideQueryIL (AsteroidAnchor *anc, IntList *il, int x1, int y1, int x2, int y2)

Variables

const double DEBRIS_BUFFER
static const double SCAN_FADE
static Debrisdebris_stack
static glTexture ** debris_gfx = NULL
static double asteroid_dt
static AsteroidTypeasteroid_types
static AsteroidTypeGroupasteroid_groups
static glTexture ** asteroid_gfx
static int asteroid_creating = 0

Detailed Description

Handles asteroid-related stuff.

Definition in file asteroid.c.

Macro Definition Documentation

◆ MELEMENT

#define MELEMENT ( o,
s )
Value:
if ( o ) \
WARN( _( "Asteroid Type '%s' missing/invalid '%s' element" ), at->name, \
s )

Function Documentation

◆ asteroid_collideQueryIL()

void asteroid_collideQueryIL ( AsteroidAnchor * anc,
IntList * il,
int x1,
int y1,
int x2,
int y2 )

Definition at line 1294 of file asteroid.c.

◆ asteroid_explode()

void asteroid_explode ( Asteroid * a,
int max_rarity,
double mining_bonus )

Makes an asteroid explode.

Parameters
aasteroid to make explode
max_rarityMaximum rarity of the rewards to give, set to -1 for none.
mining_bonusBonus to mining.

Definition at line 1209 of file asteroid.c.

◆ asteroid_freeAnchor()

void asteroid_freeAnchor ( AsteroidAnchor * ast)

Frees an asteroid anchor.

Parameters
astAsteroid anchor to free.

Definition at line 1036 of file asteroid.c.

◆ asteroid_freeExclude()

void asteroid_freeExclude ( AsteroidExclusion * exc)

Frees an asteroid exclusion.

Parameters
excAsteroid exclusion to free.

Definition at line 1051 of file asteroid.c.

◆ asteroid_hit()

void asteroid_hit ( Asteroid * a,
const Damage * dmg,
int max_rarity,
double mining_bonus )

Hits an asteroid.

Parameters
ahit asteroid
dmgDamage being done
max_rarityMaximum rarity of the rewards to give if destroyed.
mining_bonusBonus to mining.

Definition at line 1189 of file asteroid.c.

◆ asteroid_init()

int asteroid_init ( Asteroid * ast,
const AsteroidAnchor * field )
static

Initializes an asteroid.

Parameters
astAsteroid to initialize.
fieldAsteroid field the asteroid belongs to.

Definition at line 398 of file asteroid.c.

◆ asteroid_initAnchor()

void asteroid_initAnchor ( AsteroidAnchor * ast)

Initializes an asteroid anchor.

Definition at line 1019 of file asteroid.c.

◆ asteroid_loadPLG()

int asteroid_loadPLG ( AsteroidType * temp,
const char * buf )
static

Loads the collision polygon for an asteroid type.

Parameters
tempAsteroidType to load into.
bufName of the file.

Definition at line 773 of file asteroid.c.

◆ asteroid_renderSingle()

void asteroid_renderSingle ( const Asteroid * a)
static

Renders an asteroid.

Definition at line 940 of file asteroid.c.

◆ asteroid_updateSingle()

int asteroid_updateSingle ( Asteroid * a)
static

Definition at line 83 of file asteroid.c.

◆ asteroids_computeInternals()

void asteroids_computeInternals ( AsteroidAnchor * a)

Updates internal alues of an asteroid field.

Definition at line 508 of file asteroid.c.

◆ asteroids_free()

void asteroids_free ( void )

Cleans up the system.

Definition at line 1059 of file asteroid.c.

◆ asteroids_inField()

int asteroids_inField ( const vec2 * p)

See if the position is in an asteroid field.

Parameters
ppointer to the position.
Returns
-1 If false; index of the field otherwise.

Definition at line 1109 of file asteroid.c.

◆ asteroids_init()

void asteroids_init ( void )

Initializes the system.

Definition at line 298 of file asteroid.c.

◆ asteroids_load()

int asteroids_load ( void )

Loads the asteroids.

Returns
0 on success.

Definition at line 532 of file asteroid.c.

◆ asteroids_render()

void asteroids_render ( void )

Renders the current systems' spobs.

Definition at line 897 of file asteroid.c.

◆ asteroids_renderOverlay()

void asteroids_renderOverlay ( void )

Renders the system overlay.

Definition at line 875 of file asteroid.c.

◆ asteroids_update()

void asteroids_update ( double dt)

Controls fleet spawning.

Parameters
dtCurrent delta tick.

Definition at line 203 of file asteroid.c.

◆ astgroup_cmp()

int astgroup_cmp ( const void * p1,
const void * p2 )
static

Compares two asteroid type groups.

Definition at line 568 of file asteroid.c.

◆ astgroup_getAll()

const AsteroidTypeGroup * astgroup_getAll ( void )

Gets all the asteroid type groups.

Returns
An array (array.h) containing all the asteroid type groups.

Definition at line 1159 of file asteroid.c.

◆ astgroup_getName()

AsteroidTypeGroup * astgroup_getName ( const char * name)

Gets an asteroid type group by name.

Parameters
nameName of the asteroid type group to get.
Returns
The asteroid type group matching the name.

Definition at line 1170 of file asteroid.c.

◆ astgroup_parse()

int astgroup_parse ( AsteroidTypeGroup * ag,
const char * file )
static

Parses an asteroid type group from a file.

Parameters
[out]agAsteroid type group to load.
fileFile to load from.
Returns
0 on success.

Definition at line 821 of file asteroid.c.

◆ asttype_cmp()

int asttype_cmp ( const void * p1,
const void * p2 )
static

Compares two asteroid types.

Definition at line 557 of file asteroid.c.

◆ asttype_getAll()

const AsteroidType * asttype_getAll ( void )

Gets all the asteroid types.

Returns
All the asteroid types (array.h).

Definition at line 1133 of file asteroid.c.

◆ asttype_getName()

AsteroidType * asttype_getName ( const char * name)

Gets the ID of an asteroid type by name.

Parameters
nameName of the asteroid type to get.
Returns
Matching asteroid type.

Definition at line 1144 of file asteroid.c.

◆ asttype_load()

int asttype_load ( void )
static

Loads the asteroids types.

Returns
0 on success.

Definition at line 581 of file asteroid.c.

◆ asttype_parse()

int asttype_parse ( AsteroidType * at,
const char * file )
static

Parses the XML of an asteroid type.

Parameters
[out]atOutfit asteroid type.
fileFile containing the XML information.

Definition at line 649 of file asteroid.c.

◆ debris_init()

void debris_init ( Debris * deb)
static

Initializes a debris.

Parameters
debDebris to initialize.

Definition at line 483 of file asteroid.c.

◆ debris_renderSingle()

void debris_renderSingle ( const Debris * d,
double cx,
double cy )
static

Renders a debris.

Definition at line 1007 of file asteroid.c.

Variable Documentation

◆ asteroid_creating

int asteroid_creating = 0
static

Definition at line 67 of file asteroid.c.

◆ asteroid_dt

double asteroid_dt
static
Initial value:
=
0.

Used as a global variable when threading.

Definition at line 55 of file asteroid.c.

◆ asteroid_gfx

glTexture** asteroid_gfx
static
Initial value:
=
NULL

Graphics for the asteroids (array.h).

Definition at line 65 of file asteroid.c.

◆ asteroid_groups

AsteroidTypeGroup* asteroid_groups
static
Initial value:
=
NULL

Asteroid type groups stack (array.h).

Definition at line 63 of file asteroid.c.

◆ asteroid_types

AsteroidType* asteroid_types
static
Initial value:
=
NULL

Asteroid types stack (array.h).

Definition at line 61 of file asteroid.c.

◆ DEBRIS_BUFFER

const double DEBRIS_BUFFER
Initial value:
=
1000.

Buffer to smooth appearance of debris

Definition at line 46 of file asteroid.c.

◆ debris_gfx

glTexture** debris_gfx = NULL
static

Graphics to use for debris.

Definition at line 54 of file asteroid.c.

◆ debris_stack

Debris* debris_stack
static
Initial value:
=
NULL

All the debris in the current system (array.h).

Definition at line 52 of file asteroid.c.

◆ SCAN_FADE

const double SCAN_FADE
static
Initial value:
=
10.

1/time it takes to fade in/out scanning text.

Definition at line 49 of file asteroid.c.