naev 0.12.5
commodity.h
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
4#pragma once
5
7#include <stdint.h>
9
10#include "opengl_tex.h"
11
12#define ECON_CRED_STRLEN \
13 32
14#define ECON_MASS_STRLEN \
15 32
16
17typedef int64_t credits_t;
18#define CREDITS_MAX \
19 ( ( (credits_t)1 ) \
20 << 53 )
21#define CREDITS_MIN \
22 ( -CREDITS_MAX )
24#define CREDITS_PRI PRIu64
25
26#define COMMODITY_FLAG_STANDARD \
27 ( 1 << 0 )
29#define COMMODITY_FLAG_ALWAYS_CAN_SELL \
30 ( 1 << 1 )
32#define COMMODITY_FLAG_PRICE_CONSTANT \
33 ( 1 << 2 )
34#define commodity_isFlag( c, f ) \
35 ( ( c )->flags & ( f ) )
36#define commodity_setFlag( c, f ) \
37 ( ( c )->flags |= ( f ) )
38#define commodity_rmFlag( c, f ) \
39 ( ( c )->flags &= ~( f ) )
40
46typedef struct CommodityModifier_ {
47 char *name;
48 float value;
49 struct CommodityModifier_ *next;
51
57typedef struct Commodity_ {
58 char *name;
60 unsigned int flags;
61
62 /* Prices. */
63 char *price_ref;
65 double price_mod;
66 double raw_price;
67 double price;
70
71 /* Misc stuff. */
72 credits_t
74 int istemp;
75 int *illegalto;
76
77 /* Dynamic economy stuff. */
80 double period;
85} Commodity;
86
87typedef struct CommodityPrice_ {
88 double price;
89 double spobPeriod;
91 double sysPeriod;
93 double sysVariation;
97 int64_t updateTime;
99 char *name;
100 double
103 double sum2;
105 int cnt;
108
109/*
110 * Commodity stuff.
111 */
113Commodity *commodity_get( const char *name );
114Commodity *commodity_getW( const char *name );
115int commodity_getN( void );
116
117Commodity *commodity_getByIndex( const int indx );
118int commodity_load( void );
119void commodity_free( void );
120
121int commodity_checkIllegal( const Commodity *com, int faction );
122
123/*
124 * Temporary commodities.
125 */
126int commodity_isTemp( const char *name );
127Commodity *commodity_newTemp( const char *name, const char *desc );
128int commodity_tempIllegalto( Commodity *com, int faction );
129
130/*
131 * Misc stuff.
132 */
133void credits2str( char *str, credits_t credits, int decimals );
134void price2str( char *str, credits_t price, credits_t credits, int decimals );
135void tonnes2str( char *str, int tonnes );
136int commodity_compareTech( const void *commodity1, const void *commodity2 );
Commodity * commodity_getAll(void)
Gets all the commodities.
Definition commodity.c:140
Commodity * commodity_get(const char *name)
Gets a commodity by name.
Definition commodity.c:151
Commodity * commodity_newTemp(const char *name, const char *desc)
Creates a new temporary commodity.
Definition commodity.c:457
void commodity_free(void)
Frees all the loaded commodities.
Definition commodity.c:586
Commodity * commodity_getByIndex(const int indx)
Gets a commodity by index.
Definition commodity.c:195
void credits2str(char *str, credits_t credits, int decimals)
Converts credits to a usable string for displaying.
Definition commodity.c:75
void tonnes2str(char *str, int tonnes)
Converts tonnes to a usable string for displaying.
Definition commodity.c:131
int commodity_getN(void)
Return the number of commodities globally.
Definition commodity.c:184
int commodity_compareTech(const void *commodity1, const void *commodity2)
Function meant for use with C89, C99 algorithm qsort().
Definition commodity.c:245
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:111
int commodity_load(void)
Loads all the commodity data.
Definition commodity.c:513
Commodity ** standard_commodities(void)
Return an array (array.h) of standard commodities. Free with array_free. (Don't free contents....
Definition commodity.c:267
int commodity_checkIllegal(const Commodity *com, int faction)
Checks to see if a commodity is illegal to a faction.
Definition commodity.c:422
Commodity * commodity_getW(const char *name)
Gets a commodity by name without warning.
Definition commodity.c:166
int commodity_tempIllegalto(Commodity *com, int faction)
Makes a temporary commodity illegal to something.
Definition commodity.c:474
int commodity_isTemp(const char *name)
Checks to see if a commodity is temporary.
Definition commodity.c:437
Represents a dictionary of values used to modify a commodity.
Definition commodity.h:46
double sysVariation
Definition commodity.h:93
double spobVariation
Definition commodity.h:92
int64_t updateTime
Definition commodity.h:97
double spobPeriod
Definition commodity.h:89
Represents a commodity.
Definition commodity.h:57
char * description
Definition commodity.h:59
CommodityModifier * spob_modifier
Definition commodity.h:79
glTexture * gfx_store
Definition commodity.h:68
int * illegalto
Definition commodity.h:75
double population_modifier
Definition commodity.h:81
char * name
Definition commodity.h:58
credits_t lastPurchasePrice
Definition commodity.h:73
CommodityModifier * faction_modifier
Definition commodity.h:84
double price_mod
Definition commodity.h:65
double price
Definition commodity.h:67
glTexture * gfx_space
Definition commodity.h:69
double period
Definition commodity.h:80
double raw_price
Definition commodity.h:66
int istemp
Definition commodity.h:74
char * price_ref
Definition commodity.h:63
unsigned int flags
Definition commodity.h:60
Abstraction for rendering sprite sheets.
Definition opengl_tex.h:43