naev 0.11.5
ship.c File Reference

Handles the ship details. More...

#include "ship.h"
#include "array.h"
#include "colour.h"
#include "conf.h"
#include "log.h"
#include "ndata.h"
#include "nfile.h"
#include "nlua.h"
#include "nlua_gfx.h"
#include "nlua_camera.h"
#include "nstring.h"
#include "nxml.h"
#include "shipstats.h"
#include "slots.h"
#include "toolkit.h"
#include "threadpool.h"
#include "unistd.h"

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 STRTOSHIP(x, y)
 
#define MELEMENT(o, s)
 

Functions

static int ship_loadGFX (Ship *temp, const char *buf, int sx, int sy, int engine)
 Loads the graphics for a ship.
 
static int ship_loadPLG (Ship *temp, const char *buf, int size_hint)
 Loads the collision polygon for a ship.
 
static int ship_parse (Ship *temp, const char *filename)
 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 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.
 
glTextureship_loadCommGFX (const Ship *s)
 Loads the ship's comm graphic.
 
int ship_size (const Ship *s)
 Gets the size of the ship.
 
static int ship_genTargetGFX (Ship *temp, SDL_Surface *surface, int sx, int sy)
 Generates a target graphic for a ship.
 
static int ship_loadSpaceImage (Ship *temp, char *str, int sx, int sy)
 Loads the space graphics for a ship from an image.
 
static int ship_loadEngineImage (Ship *temp, char *str, int sx, int sy)
 Loads the space graphics for a ship from an image.
 
static int ship_parseSlot (Ship *temp, ShipOutfitSlot *slot, OutfitSlotType type, xmlNodePtr node)
 Parses a slot for a ship.
 
int ships_load (void)
 Loads all the ships in the data files.
 
void ships_free (void)
 Frees all the ships.
 

Variables

static Shipship_stack = NULL
 

Detailed Description

Handles the ship details.

Definition in file ship.c.

Macro Definition Documentation

◆ 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_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.

◆ STRTOSHIP

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

Definition at line 230 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 266 of file ship.c.

◆ ship_buyPrice()

credits_t ship_buyPrice ( const Ship * s)

The ship buy price, includes default outfits.

Definition at line 274 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 165 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 176 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 236 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 189 of file ship.c.

◆ ship_cmp()

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

Compares two ship pointers for qsort.

Definition at line 73 of file ship.c.

◆ ship_compareTech()

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

Comparison function for qsort().

Definition at line 129 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 110 of file ship.c.

◆ ship_freeSlot()

static void ship_freeSlot ( ShipOutfitSlot * s)
static

Definition at line 1269 of file ship.c.

◆ ship_genTargetGFX()

static int ship_genTargetGFX ( Ship * temp,
SDL_Surface * surface,
int sx,
int sy )
static

Generates a target graphic for a ship.

Definition at line 353 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 87 of file ship.c.

◆ ship_getAll()

const Ship * ship_getAll ( void )

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

Definition at line 121 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 101 of file ship.c.

◆ ship_loadCommGFX()

glTexture * ship_loadCommGFX ( const Ship * s)

Loads the ship's comm graphic.

Must be freed afterwards.

Definition at line 303 of file ship.c.

◆ ship_loadEngineImage()

static int ship_loadEngineImage ( Ship * temp,
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 463 of file ship.c.

◆ ship_loadGFX()

static int ship_loadGFX ( Ship * temp,
const char * buf,
int sx,
int sy,
int engine )
static

Loads the graphics for a ship.

Parameters
tempShip to load into.
bufName of the texture to work with.
sxNumber of X sprites in image.
syNumber of Y sprites in image.
engineWhether there is also an engine image to load.

Definition at line 478 of file ship.c.

◆ ship_loadPLG()

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

Loads the collision polygon for a ship.

Parameters
tempShip to load into.
bufName of the file.
size_hintExpected array length required.

Definition at line 526 of file ship.c.

◆ ship_loadSpaceImage()

static int ship_loadSpaceImage ( Ship * temp,
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 416 of file ship.c.

◆ ship_parse()

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

Extracts the in-game ship from an XML node.

Parameters
tempShip to load data into.
filenameFile to load ship from.
Returns
0 on success.

Definition at line 664 of file ship.c.

◆ ship_parseSlot()

static 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 581 of file ship.c.

◆ ship_parseThread()

static int ship_parseThread ( void * ptr)
static

Wrapper for threaded loading.

Definition at line 1068 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 316 of file ship.c.

◆ ships_free()

void ships_free ( void )

Frees all the ships.

Definition at line 1205 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 1087 of file ship.c.

Variable Documentation

◆ ship_stack

Ship* ship_stack = NULL
static

Stack of ships available in the game.

Definition at line 59 of file ship.c.