naev 0.12.6
commodity.c File Reference

Handles commodities. More...

#include "commodity.h"
#include "array.h"
#include "conf.h"
#include "faction.h"
#include "gatherable.h"
#include "log.h"
#include "ndata.h"
#include "nxml.h"
#include "opengl.h"
#include "threadpool.h"
Include dependency graph for commodity.c:

Go to the source code of this file.

Data Structures

struct  CommodityThreadData
 For threaded loading of commodities. More...

Macros

#define XML_COMMODITY_ID   "commodity"
#define CRED_TEXT_MAX

Functions

static int commodity_parseThread (void *ptr)
static void commodity_freeOne (Commodity *com)
 Frees a commodity.
static int commodity_parse (Commodity *temp, const char *filename)
 Loads a commodity.
static int commodity_cmp (const void *p1, const void *p2)
void credits2str (char *str, credits_t credits, int decimals)
 Converts credits to a usable string for displaying.
void price2str (char *str, credits_t price, credits_t credits, int decimals)
 Given a price and on-hand credits, outputs a colourized string.
void tonnes2str (char *str, int tonnes)
 Converts tonnes to a usable string for displaying.
Commoditycommodity_getAll (void)
 Gets all the commodities.
Commoditycommodity_get (const char *name)
 Gets a commodity by name.
Commoditycommodity_getW (const char *name)
 Gets a commodity by name without warning.
int commodity_getN (void)
 Return the number of commodities globally.
Commoditycommodity_getByIndex (const int indx)
 Gets a commodity by index.
int commodity_compareTech (const void *commodity1, const void *commodity2)
 Function meant for use with C89, C99 algorithm qsort().
Commodity ** standard_commodities (void)
 Return an array (array.h) of standard commodities. Free with array_free. (Don't free contents.)
int commodity_checkIllegal (const Commodity *com, int faction)
 Checks to see if a commodity is illegal to a faction.
int commodity_isTemp (const char *name)
 Checks to see if a commodity is temporary.
Commoditycommodity_newTemp (const char *name, const char *desc)
 Creates a new temporary commodity.
int commodity_tempIllegalto (Commodity *com, int faction)
 Makes a temporary commodity illegal to something.
int commodity_load (void)
 Loads all the commodity data.
void commodity_free (void)
 Frees all the loaded commodities.

Variables

Commoditycommodity_stack = NULL
static Commodity ** commodity_temp
int * econ_comm

Detailed Description

Handles commodities.

Definition in file commodity.c.

Macro Definition Documentation

◆ CRED_TEXT_MAX

#define CRED_TEXT_MAX
Value:
( ECON_CRED_STRLEN - \
4 ) /* Maximum length of just credits2str text, no markup */

Definition at line 30 of file commodity.c.

◆ XML_COMMODITY_ID

#define XML_COMMODITY_ID   "commodity"

XML document identifier

Definition at line 29 of file commodity.c.

Function Documentation

◆ commodity_checkIllegal()

int commodity_checkIllegal ( const Commodity * com,
int faction )

Checks to see if a commodity is illegal to a faction.

Parameters
comCommodity to check.
factionFaction to check to see if it is illegal to.
Returns
1 if it is illegal, 0 otherwise.

Definition at line 422 of file commodity.c.

◆ commodity_cmp()

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

Definition at line 60 of file commodity.c.

◆ commodity_compareTech()

int commodity_compareTech ( const void * commodity1,
const void * commodity2 )

Function meant for use with C89, C99 algorithm qsort().

Parameters
commodity1First argument to compare.
commodity2Second argument to compare.
Returns
-1 if first argument is inferior, +1 if it's superior, 0 if ties.

Definition at line 245 of file commodity.c.

◆ commodity_free()

void commodity_free ( void )

Frees all the loaded commodities.

Definition at line 586 of file commodity.c.

◆ commodity_freeOne()

void commodity_freeOne ( Commodity * com)
static

Frees a commodity.

Parameters
comCommodity to free.

Definition at line 209 of file commodity.c.

◆ commodity_get()

Commodity * commodity_get ( const char * name)

Gets a commodity by name.

Parameters
nameName to match.
Returns
Commodity matching name.

Definition at line 151 of file commodity.c.

◆ commodity_getAll()

Commodity * commodity_getAll ( void )

Gets all the commodities.

Definition at line 140 of file commodity.c.

◆ commodity_getByIndex()

Commodity * commodity_getByIndex ( const int indx)

Gets a commodity by index.

Parameters
indxIndex of the commodity.
Returns
Commodity at that index or NULL.

Definition at line 195 of file commodity.c.

◆ commodity_getN()

int commodity_getN ( void )

Return the number of commodities globally.

Returns
Number of commodities globally.

Definition at line 184 of file commodity.c.

◆ commodity_getW()

Commodity * commodity_getW ( const char * name)

Gets a commodity by name without warning.

Parameters
nameName to match.
Returns
Commodity matching name.

Definition at line 166 of file commodity.c.

◆ commodity_isTemp()

int commodity_isTemp ( const char * name)

Checks to see if a commodity is temporary.

Name of the commodity to check.

Returns
1 if temporary, 0 otherwise.

Definition at line 437 of file commodity.c.

◆ commodity_load()

int commodity_load ( void )

Loads all the commodity data.

Returns
0 on success.

Definition at line 513 of file commodity.c.

◆ commodity_newTemp()

Commodity * commodity_newTemp ( const char * name,
const char * desc )

Creates a new temporary commodity.

Parameters
nameName of the commodity to create.
descDescription of the commodity to create.
Returns
newly created commodity.

Definition at line 457 of file commodity.c.

◆ commodity_parse()

int commodity_parse ( Commodity * temp,
const char * filename )
static

Loads a commodity.

Parameters
tempCommodity to load data into.
filenameFile to parse.
Returns
Commodity loaded from parent.

Definition at line 286 of file commodity.c.

◆ commodity_parseThread()

int commodity_parseThread ( void * ptr)
static

Definition at line 495 of file commodity.c.

◆ commodity_tempIllegalto()

int commodity_tempIllegalto ( Commodity * com,
int faction )

Makes a temporary commodity illegal to something.

Definition at line 474 of file commodity.c.

◆ credits2str()

void credits2str ( char * str,
credits_t credits,
int decimals )

Converts credits to a usable string for displaying.

Parameters
[out]strOutput is stored here, must have at least a size of ECON_CRED_STRLEN.
creditsCredits to display, negative value to display full string.
decimalsDecimals to use.

Definition at line 75 of file commodity.c.

◆ price2str()

void price2str ( char * str,
credits_t price,
credits_t credits,
int decimals )

Given a price and on-hand credits, outputs a colourized string.

Parameters
[out]strOutput is stored here, must have at least a size of ECON_CRED_STRLEN.
pricePrice to display.
creditsCredits available.
decimalsDecimals to use.

Definition at line 111 of file commodity.c.

◆ standard_commodities()

Commodity ** standard_commodities ( void )

Return an array (array.h) of standard commodities. Free with array_free. (Don't free contents.)

Definition at line 267 of file commodity.c.

◆ tonnes2str()

void tonnes2str ( char * str,
int tonnes )

Converts tonnes to a usable string for displaying.

Parameters
[out]strOutput is stored here, must have at least a size of ECON_MASS_STRLEN.
tonnesNumber of tonnes to display.

Definition at line 131 of file commodity.c.

Variable Documentation

◆ commodity_stack

Commodity* commodity_stack = NULL

Contains all the commodities.

Definition at line 35 of file commodity.c.

◆ commodity_temp

Commodity** commodity_temp
static
Initial value:
=
NULL

Contains all the temporary commodities.

Definition at line 36 of file commodity.c.

◆ econ_comm

int* econ_comm
extern

Commodities to calculate.

Definition at line 56 of file economy.c.