naev 0.11.5
commodity.c File Reference

Handles commidities. More...

#include "commodity.h"
#include "conf.h"
#include "array.h"
#include "economy.h"
#include "gatherable.h"
#include "hook.h"
#include "log.h"
#include "ndata.h"
#include "nstring.h"
#include "ntime.h"
#include "nxml.h"
#include "pilot.h"
#include "player.h"
#include "rng.h"
#include "space.h"
#include "spfx.h"

Go to the source code of this file.

Macros

#define XML_COMMODITY_ID   "commodity"
 
#define CRED_TEXT_MAX   (ECON_CRED_STRLEN-4) /* Maximum length of just credits2str text, no markup */
 

Functions

static void commodity_freeOne (Commodity *com)
 Frees a commodity.
 
static int commodity_parse (Commodity *temp, const char *filename)
 Loads a commodity.
 
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 = NULL
 
int * econ_comm
 

Detailed Description

Handles commidities.

Definition in file commodity.c.

Macro Definition Documentation

◆ CRED_TEXT_MAX

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

Definition at line 36 of file commodity.c.

◆ XML_COMMODITY_ID

#define XML_COMMODITY_ID   "commodity"

XML document identifier

Definition at line 35 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 384 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 219 of file commodity.c.

◆ commodity_free()

void commodity_free ( void )

Frees all the loaded commodities.

Definition at line 504 of file commodity.c.

◆ commodity_freeOne()

static void commodity_freeOne ( Commodity * com)
static

Frees a commodity.

Parameters
comCommodity to free.

Definition at line 183 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 127 of file commodity.c.

◆ commodity_getAll()

Commodity * commodity_getAll ( void )

Gets all the commodities.

Definition at line 116 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 169 of file commodity.c.

◆ commodity_getN()

int commodity_getN ( void )

Return the number of commodities globally.

Returns
Number of commodities globally.

Definition at line 158 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 142 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 temorary, 0 otherwise.

Definition at line 399 of file commodity.c.

◆ commodity_load()

int commodity_load ( void )

Loads all the commodity data.

Returns
0 on success.

Definition at line 462 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 419 of file commodity.c.

◆ commodity_parse()

static 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 259 of file commodity.c.

◆ commodity_tempIllegalto()

int commodity_tempIllegalto ( Commodity * com,
int faction )

Makes a temporary commodity illegal to something.

Definition at line 436 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 59 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 89 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 240 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 108 of file commodity.c.

Variable Documentation

◆ commodity_stack

Commodity* commodity_stack = NULL

Contains all the commodities.

Definition at line 39 of file commodity.c.

◆ commodity_temp

Commodity** commodity_temp = NULL
static

Contains all the temporary commodities.

Definition at line 40 of file commodity.c.

◆ econ_comm

int* econ_comm
extern

Commodities to calculate.

Definition at line 61 of file economy.c.