naev 0.11.5
commodity.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
7#include <stdint.h>
10#include "opengl.h"
11
12#define ECON_CRED_STRLEN 32
13#define ECON_MASS_STRLEN 32
15typedef int64_t credits_t;
16#define CREDITS_MAX (((credits_t)1) << 53)
17#define CREDITS_MIN (-CREDITS_MAX)
18#define CREDITS_PRI PRIu64
19
20#define COMMODITY_FLAG_STANDARD (1<<0)
21#define COMMODITY_FLAG_ALWAYS_CAN_SELL (1<<1)
22#define COMMODITY_FLAG_PRICE_CONSTANT (1<<2)
23#define commodity_isFlag(c,f) ((c)->flags & (f))
24#define commodity_setFlag(c,f) ((c)->flags |= (f))
25#define commodity_rmFlag(c,f) ((c)->flags &= ~(f))
32typedef struct CommodityModifier_ {
33 char *name;
34 float value;
35 struct CommodityModifier_ *next;
37
43typedef struct Commodity_ {
44 char *name;
46 unsigned int flags;
48 /* Prices. */
49 char *price_ref;
50 double price_mod;
51 double raw_price;
52 double price;
56 /* Misc stuff. */
58 int istemp;
59 int *illegalto;
61 /* Dynamic economy stuff. */
63 double period;
66} Commodity;
67
68typedef struct CommodityPrice_ {
69 double price;
70 double spobPeriod;
71 double sysPeriod;
73 double sysVariation;
74 int64_t updateTime;
75 char *name;
76 double sum;
77 double sum2;
78 int cnt;
80
81/*
82 * Commodity stuff.
83 */
85Commodity* commodity_get( const char* name );
86Commodity* commodity_getW( const char* name );
87int commodity_getN( void );
88
89Commodity* commodity_getByIndex( const int indx );
90int commodity_load (void);
91void commodity_free (void);
92
93int commodity_checkIllegal( const Commodity *com, int faction );
94
95/*
96 * Temporary commodities.
97 */
98int commodity_isTemp( const char* name );
99Commodity* commodity_newTemp( const char* name, const char* desc );
100int commodity_tempIllegalto( Commodity *com, int faction );
101
102/*
103 * Misc stuff.
104 */
105void credits2str( char *str, credits_t credits, int decimals );
106void price2str( char *str, credits_t price, credits_t credits, int decimals );
107void tonnes2str( char *str, int tonnes );
108int commodity_compareTech( const void *commodity1, const void *commodity2 );
Commodity * commodity_getAll(void)
Gets all the commodities.
Definition commodity.c:116
Commodity * commodity_get(const char *name)
Gets a commodity by name.
Definition commodity.c:127
Commodity * commodity_newTemp(const char *name, const char *desc)
Creates a new temporary commodity.
Definition commodity.c:419
void commodity_free(void)
Frees all the loaded commodities.
Definition commodity.c:504
Commodity * commodity_getByIndex(const int indx)
Gets a commodity by index.
Definition commodity.c:169
void credits2str(char *str, credits_t credits, int decimals)
Converts credits to a usable string for displaying.
Definition commodity.c:59
void tonnes2str(char *str, int tonnes)
Converts tonnes to a usable string for displaying.
Definition commodity.c:108
int commodity_getN(void)
Return the number of commodities globally.
Definition commodity.c:158
int commodity_compareTech(const void *commodity1, const void *commodity2)
Function meant for use with C89, C99 algorithm qsort().
Definition commodity.c:219
void price2str(char *str, credits_t price, credits_t credits, int decimals)
Given a price and on-hand credits, outputs a colourized string.
Definition commodity.c:89
int commodity_load(void)
Loads all the commodity data.
Definition commodity.c:462
Commodity ** standard_commodities(void)
Return an array (array.h) of standard commodities. Free with array_free. (Don't free contents....
Definition commodity.c:240
int commodity_checkIllegal(const Commodity *com, int faction)
Checks to see if a commodity is illegal to a faction.
Definition commodity.c:384
Commodity * commodity_getW(const char *name)
Gets a commodity by name without warning.
Definition commodity.c:142
int commodity_tempIllegalto(Commodity *com, int faction)
Makes a temporary commodity illegal to something.
Definition commodity.c:436
int commodity_isTemp(const char *name)
Checks to see if a commodity is temporary.
Definition commodity.c:399
Represents a dictionary of values used to modify a commodity.
Definition commodity.h:32
double sysVariation
Definition commodity.h:73
double spobVariation
Definition commodity.h:72
int64_t updateTime
Definition commodity.h:74
double spobPeriod
Definition commodity.h:70
Represents a commodity.
Definition commodity.h:43
char * description
Definition commodity.h:45
CommodityModifier * spob_modifier
Definition commodity.h:62
glTexture * gfx_store
Definition commodity.h:53
int * illegalto
Definition commodity.h:59
double population_modifier
Definition commodity.h:64
char * name
Definition commodity.h:44
credits_t lastPurchasePrice
Definition commodity.h:57
CommodityModifier * faction_modifier
Definition commodity.h:65
double price_mod
Definition commodity.h:50
double price
Definition commodity.h:52
glTexture * gfx_space
Definition commodity.h:54
double period
Definition commodity.h:63
double raw_price
Definition commodity.h:51
int istemp
Definition commodity.h:58
char * price_ref
Definition commodity.h:49
unsigned int flags
Definition commodity.h:46
Abstraction for rendering sprite sheets.
Definition opengl_tex.h:36