naev 0.10.4
Data Structures | Macros | Functions | Variables
asteroid.c File Reference

Handles asteroid-related stuff. More...

#include "asteroid.h"
#include "conf.h"
#include "array.h"
#include "camera.h"
#include "gatherable.h"
#include "space.h"
#include "opengl.h"
#include "toolkit.h"
#include "ndata.h"
#include "player.h"
#include "nlua_asteroid.h"

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)   if (o) WARN(_("Asteroid Type '%s' missing/invalid '%s' element"), at->name, s)
 

Functions

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

Variables

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

Detailed Description

Handles asteroid-related stuff.

Definition in file asteroid.c.

Function Documentation

◆ 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 1049 of file asteroid.c.

◆ asteroid_free()

void asteroid_free ( AsteroidAnchor ast)

Frees an asteroid anchor.

Parameters
astAsteroid anchor to free.

Definition at line 891 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 1031 of file asteroid.c.

◆ asteroid_init()

static 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 306 of file asteroid.c.

◆ asteroid_loadPLG()

static 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 658 of file asteroid.c.

◆ asteroid_renderSingle()

static void asteroid_renderSingle ( const Asteroid a)
static

Renders an asteroid.

Definition at line 813 of file asteroid.c.

◆ asteroids_computeInternals()

void asteroids_computeInternals ( AsteroidAnchor a)

Updates internal alues of an asteroid field.

Definition at line 407 of file asteroid.c.

◆ asteroids_free()

void asteroids_free ( void  )

Cleans up the system.

Definition at line 902 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 954 of file asteroid.c.

◆ asteroids_init()

void asteroids_init ( void  )

Initializes the system.

Definition at line 238 of file asteroid.c.

◆ asteroids_load()

int asteroids_load ( void  )

Loads the asteroids.

Returns
0 on success.

Definition at line 429 of file asteroid.c.

◆ asteroids_render()

void asteroids_render ( void  )

Renders the current systems' spobs.

Definition at line 785 of file asteroid.c.

◆ asteroids_renderOverlay()

void asteroids_renderOverlay ( void  )

Renders the system overlay.

Definition at line 767 of file asteroid.c.

◆ asteroids_update()

void asteroids_update ( double  dt)

Controls fleet spawning.

Parameters
dtCurrent delta tick.

Definition at line 74 of file asteroid.c.

◆ astgroup_cmp()

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

Compares two asteroid type groups.

Definition at line 466 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 1003 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 1014 of file asteroid.c.

◆ astgroup_parse()

static 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 715 of file asteroid.c.

◆ asttype_cmp()

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

Compares two asteroid types.

Definition at line 455 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 978 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 989 of file asteroid.c.

◆ asttype_load()

static int asttype_load ( void  )
static

Loads the asteroids types.

Returns
0 on success.

Definition at line 479 of file asteroid.c.

◆ asttype_parse()

static 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.

< Define to help check for data errors.

Definition at line 545 of file asteroid.c.

◆ debris_init()

static void debris_init ( Debris deb)
static

Initializes a debris.

Parameters
debDebris to initialize.

Definition at line 382 of file asteroid.c.

◆ debris_renderSingle()

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

Renders a debris.

Definition at line 878 of file asteroid.c.

Variable Documentation

◆ asteroid_creating

int asteroid_creating = 0
static

Definition at line 53 of file asteroid.c.

◆ asteroid_gfx

glTexture** asteroid_gfx = NULL
static

Graphics for the asteroids (array.h).

Definition at line 52 of file asteroid.c.

◆ asteroid_groups

AsteroidTypeGroup* asteroid_groups = NULL
static

Asteroid type groups stack (array.h).

Definition at line 51 of file asteroid.c.

◆ asteroid_types

AsteroidType* asteroid_types = NULL
static

Asteroid types stack (array.h).

Definition at line 50 of file asteroid.c.

◆ DEBRIS_BUFFER

const double DEBRIS_BUFFER = 1000.

Buffer to smooth appearance of debris

Definition at line 40 of file asteroid.c.

◆ debris_gfx

glTexture** debris_gfx = NULL
static

Graphics to use for debris.

Definition at line 45 of file asteroid.c.

◆ debris_stack

Debris* debris_stack = NULL
static

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

Definition at line 44 of file asteroid.c.

◆ SCAN_FADE

const double SCAN_FADE = 10.
static

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

Definition at line 42 of file asteroid.c.