naev 0.12.6
ship.c File Reference

Handles the ship details. More...

#include "ship.h"
#include "array.h"
#include "colour.h"
#include "conf.h"
#include "faction.h"
#include "log.h"
#include "ndata.h"
#include "nlua.h"
#include "nlua_camera.h"
#include "nlua_gfx.h"
#include "nlua_ship.h"
#include "nstring.h"
#include "nxml.h"
#include "opengl_tex.h"
#include "shipstats.h"
#include "slots.h"
#include "sound.h"
#include "threadpool.h"
Include dependency graph for ship.c:

Go to the source code of this file.

Data Structures

struct  ShipThreadData
 Structure for threaded loading. More...

Macros

#define XML_SHIP   "ship"
#define SHIP_ENGINE   "_engine"
#define SHIP_TARGET   "_target"
#define SHIP_COMM   "_comm"
#define VIEW_WIDTH   300
#define VIEW_HEIGHT   300
#define BUTTON_WIDTH   80
#define BUTTON_HEIGHT   30
#define STATS_DESC_MAX   512
#define SHIP_FBO   3
#define STRTOSHIP(x, y)
#define STRDUP_(x)
#define ARRAYDUP_(x, y)
#define MELEMENT(o, s)

Functions

static int ship_loadPLG (Ship *temp, const char *buf)
 Loads the collision polygon for a ship.
static int ship_parse (Ship *temp, const char *filename, int firstpass)
 Extracts the in-game ship from an XML node.
static int ship_parseThread (void *ptr)
 Wrapper for threaded loading.
static void ship_freeSlot (ShipOutfitSlot *s)
static void ship_renderFramebuffer3D (const Ship *s, GLuint fbo, double size, double fw, double fh, double engine_glow, double t, const glColour *c, const Lighting *L, const mat4 *H, int blit, unsigned int flags)
 Renders a 3D ship to a framebuffer.
static int ship_cmp (const void *p1, const void *p2)
 Compares two ship pointers for qsort.
const Shipship_get (const char *name)
 Gets a ship based on its name.
const Shipship_getW (const char *name)
 Gets a ship based on its name without warning.
const char * ship_existsCase (const char *name)
 Checks to see if an ship exists matching name (case insensitive).
const Shipship_getAll (void)
 Gets the array (array.h) of all ships.
int ship_compareTech (const void *arg1, const void *arg2)
 Comparison function for qsort().
const char * ship_class (const Ship *s)
 Gets the ship's class name in human readable form.
const char * ship_classDisplay (const Ship *s)
 Gets the ship's display class in human readable form.
const char * ship_classToString (ShipClass class)
 Gets the ship class name in human readable form.
ShipClass ship_classFromString (const char *str)
 Gets the machine ship class identifier from a human readable string.
credits_t ship_basePrice (const Ship *s)
 Gets the ship's base price (no outfits).
credits_t ship_buyPrice (const Ship *s)
 The ship buy price, includes default outfits.
void ship_renderGfxStore (GLuint fbo, const Ship *s, int size, double dir, double updown, double glow)
glTextureship_gfxStore (const Ship *s, int size, double dir, double updown, double glow)
 Get the store gfx.
glTextureship_gfxComm (const Ship *s, int size, double tilt, double dir, const Lighting *Lscene)
 Loads the ship's comm graphic.
int ship_gfxAnimated (const Ship *s)
 Returns whether or not the ship has animated graphics.
int ship_size (const Ship *s)
 Gets the size of the ship.
static int ship_loadSpaceImage (Ship *temp, const char *str, int sx, int sy)
 Loads the space graphics for a ship from an image.
static int ship_loadEngineImage (Ship *temp, const char *str, int sx, int sy)
 Loads the space graphics for a ship from an image.
int ship_gfxLoaded (const Ship *s)
 Checks to see if a ship has loaded graphics.
int ship_gfxLoadNeeded (void)
 Tries to load the graphics for all ships that need it.
int ship_gfxLoad (Ship *s)
 Loads the graphics for a ship if necessary.
static int ship_parseSlot (Ship *temp, ShipOutfitSlot *slot, OutfitSlotType type, xmlNodePtr node)
 Parses a slot for a ship.
void ship_renderFramebuffer (const Ship *s, GLuint fbo, double fw, double fh, double dir, double engine_glow, double tilt, double r, int sx, int sy, const glColour *c, const Lighting *L)
 Renders a ship to a framebuffer.
int ships_load (void)
 Loads all the ships in the data files.
void ships_resize (void)
void ships_free (void)
 Frees all the ships.
double ship_maxSize (void)
 Gets the maximum size of a ship.

Variables

static Shipship_stack = NULL
static double max_size = 512.
static double ship_fbos = 0.
static GLuint ship_fbo [SHIP_FBO] = { GL_INVALID_ENUM }
static GLuint ship_tex [SHIP_FBO] = { GL_INVALID_ENUM }
static GLuint ship_texd [SHIP_FBO] = { GL_INVALID_ENUM }
static const double ship_aa_scale_base = 2.
static double ship_aa_scale = -1.

Detailed Description

Handles the ship details.

Definition in file ship.c.

Macro Definition Documentation

◆ ARRAYDUP_

#define ARRAYDUP_ ( x,
y )
Value:
do { \
for ( int i = 0; i < array_size( y ); i++ ) \
array_push_back( &x, y[i] ); \
} while ( 0 )
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
Definition array.h:179
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
Definition array.h:134

◆ BUTTON_HEIGHT

#define BUTTON_HEIGHT   30

Button height in ship view window.

Definition at line 46 of file ship.c.

◆ BUTTON_WIDTH

#define BUTTON_WIDTH   80

Button width in ship view window.

Definition at line 45 of file ship.c.

◆ MELEMENT

#define MELEMENT ( o,
s )
Value:
if ( o ) \
WARN( _( "Ship '%s' missing '%s' element" ), temp->name, s )

◆ SHIP_COMM

#define SHIP_COMM   "_comm"

Communication graphic extension.

Definition at line 40 of file ship.c.

◆ SHIP_ENGINE

#define SHIP_ENGINE   "_engine"

Engine graphic extension.

Definition at line 38 of file ship.c.

◆ SHIP_FBO

#define SHIP_FBO   3

Definition at line 61 of file ship.c.

◆ SHIP_TARGET

#define SHIP_TARGET   "_target"

Target graphic extension.

Definition at line 39 of file ship.c.

◆ STATS_DESC_MAX

#define STATS_DESC_MAX   512

Maximum length for statistics description.

Definition at line 48 of file ship.c.

◆ STRDUP_

#define STRDUP_ ( x)
Value:
( ( x == NULL ) ? NULL : strdup( x ) )

◆ STRTOSHIP

#define STRTOSHIP ( x,
y )
Value:
if ( strcmp( str, x ) == 0 ) \
return y

Definition at line 257 of file ship.c.

◆ VIEW_HEIGHT

#define VIEW_HEIGHT   300

Ship view window height.

Definition at line 43 of file ship.c.

◆ VIEW_WIDTH

#define VIEW_WIDTH   300

Ship view window width.

Definition at line 42 of file ship.c.

◆ XML_SHIP

#define XML_SHIP   "ship"

XML individual ship identifier.

Definition at line 36 of file ship.c.

Function Documentation

◆ ship_basePrice()

credits_t ship_basePrice ( const Ship * s)

Gets the ship's base price (no outfits).

Definition at line 295 of file ship.c.

◆ ship_buyPrice()

credits_t ship_buyPrice ( const Ship * s)

The ship buy price, includes default outfits.

Definition at line 303 of file ship.c.

◆ ship_class()

const char * ship_class ( const Ship * s)

Gets the ship's class name in human readable form.

Parameters
sShip to get the class name from.
Returns
The human readable class name.

Definition at line 192 of file ship.c.

◆ ship_classDisplay()

const char * ship_classDisplay ( const Ship * s)

Gets the ship's display class in human readable form.

Parameters
sShip to get the display class name from.
Returns
The human readable display class name.

Definition at line 203 of file ship.c.

◆ ship_classFromString()

ShipClass ship_classFromString ( const char * str)

Gets the machine ship class identifier from a human readable string.

Parameters
strString to extract ship class identifier from.

Definition at line 265 of file ship.c.

◆ ship_classToString()

const char * ship_classToString ( ShipClass class)

Gets the ship class name in human readable form.

Parameters
classClass to get name of.
Returns
The human readable class name.

Definition at line 216 of file ship.c.

◆ ship_cmp()

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

Compares two ship pointers for qsort.

Definition at line 86 of file ship.c.

◆ ship_compareTech()

int ship_compareTech ( const void * arg1,
const void * arg2 )

Comparison function for qsort().

Definition at line 142 of file ship.c.

◆ ship_existsCase()

const char * ship_existsCase ( const char * name)

Checks to see if an ship exists matching name (case insensitive).

Definition at line 123 of file ship.c.

◆ ship_freeSlot()

void ship_freeSlot ( ShipOutfitSlot * s)
static

Definition at line 1817 of file ship.c.

◆ ship_get()

const Ship * ship_get ( const char * name)

Gets a ship based on its name.

Parameters
nameName to match.
Returns
Ship matching name or NULL if not found.

Definition at line 99 of file ship.c.

◆ ship_getAll()

const Ship * ship_getAll ( void )

Gets the array (array.h) of all ships.

Definition at line 134 of file ship.c.

◆ ship_getW()

const Ship * ship_getW ( const char * name)

Gets a ship based on its name without warning.

Parameters
nameName to match.
Returns
Ship matching name or NULL if not found.

Definition at line 113 of file ship.c.

◆ ship_gfxAnimated()

int ship_gfxAnimated ( const Ship * s)

Returns whether or not the ship has animated graphics.

Parameters
sShip to check to see if has animated graphics.
Returns
Whether or not a ship has animated graphics.

Definition at line 513 of file ship.c.

◆ ship_gfxComm()

glTexture * ship_gfxComm ( const Ship * s,
int size,
double tilt,
double dir,
const Lighting * Lscene )

Loads the ship's comm graphic.

Must be freed afterwards.

Definition at line 418 of file ship.c.

◆ ship_gfxLoad()

int ship_gfxLoad ( Ship * s)

Loads the graphics for a ship if necessary.

Parameters
sShip to load into.

Definition at line 628 of file ship.c.

◆ ship_gfxLoaded()

int ship_gfxLoaded ( const Ship * s)

Checks to see if a ship has loaded graphics.

Definition at line 595 of file ship.c.

◆ ship_gfxLoadNeeded()

int ship_gfxLoadNeeded ( void )

Tries to load the graphics for all ships that need it.

Definition at line 603 of file ship.c.

◆ ship_gfxStore()

glTexture * ship_gfxStore ( const Ship * s,
int size,
double dir,
double updown,
double glow )

Get the store gfx.

Definition at line 383 of file ship.c.

◆ ship_loadEngineImage()

int ship_loadEngineImage ( Ship * temp,
const char * str,
int sx,
int sy )
static

Loads the space graphics for a ship from an image.

Parameters
tempShip to load into.
strPath of the image to use.
sxNumber of X sprites in image.
syNumber of Y sprites in image.

Definition at line 586 of file ship.c.

◆ ship_loadPLG()

int ship_loadPLG ( Ship * temp,
const char * buf )
static

Loads the collision polygon for a ship.

Parameters
tempShip to load into.
bufName of the file.

Definition at line 754 of file ship.c.

◆ ship_loadSpaceImage()

int ship_loadSpaceImage ( Ship * temp,
const char * str,
int sx,
int sy )
static

Loads the space graphics for a ship from an image.

Parameters
tempShip to load into.
strPath of the image to use.
sxNumber of X sprites in image.
syNumber of Y sprites in image.

Definition at line 568 of file ship.c.

◆ ship_maxSize()

double ship_maxSize ( void )

Gets the maximum size of a ship.

Definition at line 1826 of file ship.c.

◆ ship_parse()

int ship_parse ( Ship * temp,
const char * filename,
int firstpass )
static

Extracts the in-game ship from an XML node.

Parameters
tempShip to load data into.
filenameFile to load ship from.
firstpassWhether or not on the first pass.
Returns
0 on success.

Definition at line 893 of file ship.c.

◆ ship_parseSlot()

int ship_parseSlot ( Ship * temp,
ShipOutfitSlot * slot,
OutfitSlotType type,
xmlNodePtr node )
static

Parses a slot for a ship.

Parameters
tempShip to be parsed.
slotSlot being parsed.
typeType of the slot.
nodeNode containing the data.
Returns
0 on success.

Definition at line 803 of file ship.c.

◆ ship_parseThread()

int ship_parseThread ( void * ptr)
static

Wrapper for threaded loading.

Definition at line 1548 of file ship.c.

◆ ship_renderFramebuffer()

void ship_renderFramebuffer ( const Ship * s,
GLuint fbo,
double fw,
double fh,
double dir,
double engine_glow,
double tilt,
double r,
int sx,
int sy,
const glColour * c,
const Lighting * L )

Renders a ship to a framebuffer.

Definition at line 1489 of file ship.c.

◆ ship_renderFramebuffer3D()

void ship_renderFramebuffer3D ( const Ship * s,
GLuint fbo,
double size,
double fw,
double fh,
double engine_glow,
double t,
const glColour * c,
const Lighting * L,
const mat4 * H,
int blit,
unsigned int flags )
static

Renders a 3D ship to a framebuffer.

Definition at line 1354 of file ship.c.

◆ ship_renderGfxStore()

void ship_renderGfxStore ( GLuint fbo,
const Ship * s,
int size,
double dir,
double updown,
double glow )

Definition at line 327 of file ship.c.

◆ ship_size()

int ship_size ( const Ship * s)

Gets the size of the ship.

s Ship to get the size of.

Returns
Size of the ship.

Definition at line 526 of file ship.c.

◆ ships_free()

void ships_free ( void )

Frees all the ships.

Definition at line 1743 of file ship.c.

◆ ships_load()

int ships_load ( void )

Loads all the ships in the data files.

Returns
0 on success.

Definition at line 1567 of file ship.c.

◆ ships_resize()

void ships_resize ( void )

Definition at line 1720 of file ship.c.

Variable Documentation

◆ max_size

double max_size = 512.
static

Definition at line 62 of file ship.c.

◆ ship_aa_scale

double ship_aa_scale = -1.
static

Definition at line 68 of file ship.c.

◆ ship_aa_scale_base

const double ship_aa_scale_base = 2.
static

Definition at line 67 of file ship.c.

◆ ship_fbo

GLuint ship_fbo[SHIP_FBO] = { GL_INVALID_ENUM }
static

Definition at line 64 of file ship.c.

◆ ship_fbos

double ship_fbos = 0.
static

Definition at line 63 of file ship.c.

◆ ship_stack

Ship* ship_stack = NULL
static

Stack of ships available in the game.

Definition at line 59 of file ship.c.

◆ ship_tex

GLuint ship_tex[SHIP_FBO] = { GL_INVALID_ENUM }
static

Definition at line 65 of file ship.c.

◆ ship_texd

GLuint ship_texd[SHIP_FBO] = { GL_INVALID_ENUM }
static

Definition at line 66 of file ship.c.