naev 0.11.5
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)
 

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 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_free (AsteroidAnchor *ast)
 Frees an asteroid anchor.
 
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 = 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.

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 1175 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 1092 of file asteroid.c.

◆ asteroid_free()

void asteroid_free ( AsteroidAnchor * ast)

Frees an asteroid anchor.

Parameters
astAsteroid anchor to free.

Definition at line 934 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 1074 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 331 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 690 of file asteroid.c.

◆ asteroid_renderSingle()

static void asteroid_renderSingle ( const Asteroid * a)
static

Renders an asteroid.

Definition at line 856 of file asteroid.c.

◆ asteroids_computeInternals()

void asteroids_computeInternals ( AsteroidAnchor * a)

Updates internal alues of an asteroid field.

Definition at line 439 of file asteroid.c.

◆ asteroids_free()

void asteroids_free ( void )

Cleans up the system.

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

◆ asteroids_init()

void asteroids_init ( void )

Initializes the system.

Definition at line 253 of file asteroid.c.

◆ asteroids_load()

int asteroids_load ( void )

Loads the asteroids.

Returns
0 on success.

Definition at line 461 of file asteroid.c.

◆ asteroids_render()

void asteroids_render ( void )

Renders the current systems' spobs.

Definition at line 817 of file asteroid.c.

◆ asteroids_renderOverlay()

void asteroids_renderOverlay ( void )

Renders the system overlay.

Definition at line 799 of file asteroid.c.

◆ asteroids_update()

void asteroids_update ( double dt)

Controls fleet spawning.

Parameters
dtCurrent delta tick.

Definition at line 73 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 498 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 1046 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 1057 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 747 of file asteroid.c.

◆ asttype_cmp()

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

Compares two asteroid types.

Definition at line 487 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 1021 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 1032 of file asteroid.c.

◆ asttype_load()

static int asttype_load ( void )
static

Loads the asteroids types.

Returns
0 on success.

Definition at line 511 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.

Definition at line 577 of file asteroid.c.

◆ debris_init()

static void debris_init ( Debris * deb)
static

Initializes a debris.

Parameters
debDebris to initialize.

Definition at line 414 of file asteroid.c.

◆ debris_renderSingle()

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

Renders a debris.

Definition at line 921 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.