22#include "gatherable.h"
35#define XML_COMMODITY_ID "commodity"
36#define CRED_TEXT_MAX (ECON_CRED_STRLEN-4)
63 snprintf( str, CRED_TEXT_MAX, _(
"%.*f ¤"), 0, (
double)credits );
65 else if (credits >= 1000000000000000000LL)
66 snprintf( str, CRED_TEXT_MAX, _(
"%.*f E¤"), decimals, (
double)credits / 1e18 );
67 else if (credits >= 1000000000000000LL)
68 snprintf( str, CRED_TEXT_MAX, _(
"%.*f P¤"), decimals, (
double)credits / 1e15 );
69 else if (credits >= 1000000000000LL)
70 snprintf( str, CRED_TEXT_MAX, _(
"%.*f T¤"), decimals, (
double)credits / 1e12 );
71 else if (credits >= 1000000000L)
72 snprintf( str, CRED_TEXT_MAX, _(
"%.*f G¤"), decimals, (
double)credits / 1e9 );
73 else if (credits >= 1000000)
74 snprintf( str, CRED_TEXT_MAX, _(
"%.*f M¤"), decimals, (
double)credits / 1e6 );
75 else if (credits >= 1000)
76 snprintf( str, CRED_TEXT_MAX, _(
"%.*f k¤"), decimals, (
double)credits / 1e3 );
78 snprintf (str, CRED_TEXT_MAX, _(
"%.*f ¤"), decimals, (
double)credits );
89void price2str(
char *str, credits_t price, credits_t credits,
int decimals )
91 char buf[ CRED_TEXT_MAX ];
93 if (price <= credits) {
99 snprintf( str, ECON_CRED_STRLEN,
"#r%s#0", (
char*)buf );
110 snprintf( str, ECON_MASS_STRLEN, n_(
"%d tonne",
"%d tonnes", tonnes ), tonnes );
132 WARN(_(
"Commodity '%s' not found in stack"), name);
172 WARN(_(
"Commodity with index %d not found"),indx);
193 while (next != NULL ) {
201 while (next != NULL ) {
234 return strcmp( c1->
name, c2->
name );
244 for (
int i=0; i<n; i++) {
246 if (commodity_isFlag(
c,COMMODITY_FLAG_STANDARD))
261 xmlNodePtr node, parent;
268 parent = doc->xmlChildrenNode;
270 ERR(_(
"Malformed %s file: missing root element '%s'"), filename,
XML_COMMODITY_ID);
280 node = parent->xmlChildrenNode;
284 xmlr_strd(node,
"name", temp->
name);
286 xmlr_int(node,
"price", temp->
price);
287 xmlr_float(node,
"price_mod", temp->
price_mod);
288 xmlr_strd(node,
"price_ref", temp->
price_ref);
290 if (xml_isNode(node,
"gfx_space")) {
292 COMMODITY_GFX_PATH
"space/%s", 1, 1, OPENGL_TEX_MIPMAPS );
295 if (xml_isNode(node,
"gfx_store")) {
297 COMMODITY_GFX_PATH
"%s", 1, 1, OPENGL_TEX_MIPMAPS );
300 if (xml_isNode(node,
"standard")) {
301 commodity_setFlag( temp, COMMODITY_FLAG_STANDARD );
304 if (xml_isNode(node,
"always_can_sell")) {
305 commodity_setFlag( temp, COMMODITY_FLAG_ALWAYS_CAN_SELL );
308 if (xml_isNode(node,
"price_constant")) {
309 commodity_setFlag( temp, COMMODITY_FLAG_PRICE_CONSTANT );
312 if (xml_isNode(node,
"illegalto")) {
313 xmlNodePtr cur = node->xmlChildrenNode;
317 if (xml_isNode(cur,
"faction")) {
321 }
while (xml_nextNode(node));
325 xmlr_float(node,
"period", temp->
period);
326 if (xml_isNode(node,
"spob_modifier")) {
329 xmlr_attr_strd(node,
"type", newdict->name);
330 newdict->value = xml_getFloat(node);
334 if (xml_isNode(node,
"faction_modifier")) {
337 xmlr_attr_strd(node,
"type", newdict->name);
338 newdict->value = xml_getFloat(node);
343 WARN(_(
"Commodity '%s' has unknown node '%s'"),temp->
name, node->name);
344 }
while (xml_nextNode(node));
346 if (temp->
name == NULL)
347 WARN( _(
"Commodity from %s has invalid or no name"), COMMODITY_DATA_PATH);
351 WARN(_(
"No <gfx_store> node found, using default texture for commodity \"%s\""), temp->
name);
359 if (temp->
price > 0.)
360 WARN(_(
"Commodity '%s' is setting both 'price' and 'price_ref'."),temp->
name);
364#define MELEMENT(o,s) if (o) WARN( _("Commodity '%s' missing '"s"' element"), temp->name)
366 MELEMENT(temp->high==0,
"high");
367 MELEMENT(temp->medium==0,
"medium");
368 MELEMENT(temp->low==0,
"low");
408 WARN(_(
"Commodity '%s' not found in stack"), name);
428 (*c)->name = strdup(name);
429 (*c)->description = strdup(desc);
439 WARN(_(
"Trying to modify temporary commodity '%s'!"), com->
name);
465 Uint32 time = SDL_GetTicks();
472 for (
int i=0; i<
array_size(commodities); i++) {
487 free( commodities[i] );
492 time = SDL_GetTicks() - time;
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#define array_create_size(basic_type, capacity)
Creates a new dynamic array of ‘basic_type’ with an initial capacity.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
Commodity * commodity_getAll(void)
Gets all the commodities.
Commodity * commodity_get(const char *name)
Gets a commodity by name.
Commodity * commodity_newTemp(const char *name, const char *desc)
Creates a new temporary commodity.
static void commodity_freeOne(Commodity *com)
Frees a commodity.
static Commodity ** commodity_temp
void commodity_free(void)
Frees all the loaded commodities.
Commodity * commodity_getByIndex(const int indx)
Gets a commodity by index.
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 tonnes2str(char *str, int tonnes)
Converts tonnes to a usable string for displaying.
int commodity_getN(void)
Return the number of commodities globally.
int commodity_compareTech(const void *commodity1, const void *commodity2)
Function meant for use with C89, C99 algorithm qsort().
void price2str(char *str, credits_t price, credits_t credits, int decimals)
Given a price and on-hand credits, outputs a colourized string.
int commodity_load(void)
Loads all the commodity data.
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.
Commodity * commodity_getW(const char *name)
Gets a commodity by name without warning.
Commodity * commodity_stack
int commodity_tempIllegalto(Commodity *com, int faction)
Makes a temporary commodity illegal to something.
int commodity_isTemp(const char *name)
Checks to see if a commodity is temporary.
int faction_get(const char *name)
Gets a faction ID by name.
int gatherable_load(void)
Loads the gatherable system.
void gatherable_cleanup(void)
Cleans up after the gatherable system.
void naev_renderLoadscreen(void)
Renders the loadscreen if necessary.
Header file with generic functions and naev-specifics.
char ** ndata_listRecursive(const char *path)
Lists all the visible files in a directory, at any depth.
glTexture * xml_parseTexture(xmlNodePtr node, const char *path, int defsx, int defsy, const unsigned int flags)
Parses a texture handling the sx and sy elements.
xmlDocPtr xml_parsePhysFS(const char *filename)
Analogous to xmlParseMemory/xmlParseFile.
glTexture * gl_newImage(const char *path, const unsigned int flags)
Loads an image as a texture.
void gl_freeTexture(glTexture *texture)
Frees a texture.
Represents a dictionary of values used to modify a commodity.
CommodityModifier * spob_modifier
double population_modifier
CommodityModifier * faction_modifier