naev 0.11.5
economy.c File Reference

Handles economy stuff. More...

#include "economy.h"
#include "array.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 ECON_BASE_RES   30.
 
#define ECON_SELF_RES   3.
 
#define ECON_FACTION_MOD   0.1
 
#define ECON_PROD_MODIFIER   500000.
 
#define ECON_PROD_VAR   0.01
 

Functions

int economy_sysSave (xmlTextWriterPtr writer)
 Saves what is needed to be saved for economy.
 
int economy_sysLoad (xmlNodePtr parent)
 Loads player's economy properties from an XML node.
 
credits_t economy_getPrice (const Commodity *com, const StarSystem *sys, const Spob *p)
 Gets the price of a good on a spob in a system.
 
credits_t economy_getPriceAtTime (const Commodity *com, const StarSystem *sys, const Spob *p, ntime_t tme)
 Gets the price of a good on a spob in a system.
 
int economy_getAverageSpobPrice (const Commodity *com, const Spob *p, credits_t *mean, double *std)
 Gets the average price of a good on a spob in a system, using a rolling average over the times the player has landed here.
 
int economy_getAveragePrice (const Commodity *com, credits_t *mean, double *std)
 Gets the average price of a good as seen by the player (anywhere).
 
int economy_init (void)
 Initializes the economy.
 
void economy_addQueuedUpdate (void)
 Increments the queued update counter.
 
int economy_execQueued (void)
 Calls economy_refresh if an economy update is queued.
 
int economy_refresh (void)
 Regenerates the economy matrix. Should be used if the universe changes in any permanent way.
 
int economy_update (unsigned int dt)
 Updates the economy.
 
void economy_destroy (void)
 Destroys the economy.
 
static int economy_calcPrice (Spob *spob, Commodity *commodity, CommodityPrice *commodityPrice)
 Used during startup to set price and variation of the economy, depending on spob information.
 
static void economy_modifySystemCommodityPrice (StarSystem *sys)
 Modifies commodity price based on system characteristics.
 
static void economy_smoothCommodityPrice (StarSystem *sys)
 Calculates smoothing of commodity price based on neighbouring systems.
 
static void economy_calcUpdatedCommodityPrice (StarSystem *sys)
 Modifies commodity price based on neighbouring systems.
 
void economy_initialiseCommodityPrices (void)
 Initialises commodity prices for the sinusoidal economy model.
 
void economy_initialiseSingleSystem (StarSystem *sys, Spob *spob)
 
void economy_averageSeenPrices (const Spob *p)
 
void economy_averageSeenPricesAtTime (const Spob *p, const ntime_t tupdate)
 
void economy_clearKnown (void)
 Clears all system knowledge.
 
void economy_clearSingleSpob (Spob *p)
 Clears all economy knowledge of a given spob. Used by the unidiff system.
 

Variables

StarSystem * systems_stack
 
Commoditycommodity_stack
 
static int econ_initialized = 0
 
static int econ_queued = 0
 
static cs * econ_G = NULL
 
int * econ_comm = NULL
 

Detailed Description

Handles economy stuff.

Economy is handled with Nodal Analysis. Systems are modelled as nodes, jump routes are resistances and production is modelled as node intensity. This is then solved with linear algebra after each time increment.

Definition in file economy.c.

Macro Definition Documentation

◆ ECON_BASE_RES

#define ECON_BASE_RES   30.

Base resistance value for any system.

Definition at line 43 of file economy.c.

◆ ECON_FACTION_MOD

#define ECON_FACTION_MOD   0.1

Modifier on Base for faction standings.

Definition at line 45 of file economy.c.

◆ ECON_PROD_MODIFIER

#define ECON_PROD_MODIFIER   500000.

Production modifier, divide production by this amount.

Definition at line 46 of file economy.c.

◆ ECON_PROD_VAR

#define ECON_PROD_VAR   0.01

Defines the variability of production.

Definition at line 47 of file economy.c.

◆ ECON_SELF_RES

#define ECON_SELF_RES   3.

Additional resistance for the self node.

Definition at line 44 of file economy.c.

Function Documentation

◆ economy_addQueuedUpdate()

void economy_addQueuedUpdate ( void )

Increments the queued update counter.

See also
economy_execQueued

Definition at line 475 of file economy.c.

◆ economy_averageSeenPrices()

void economy_averageSeenPrices ( const Spob * p)

Definition at line 924 of file economy.c.

◆ economy_averageSeenPricesAtTime()

void economy_averageSeenPricesAtTime ( const Spob * p,
const ntime_t tupdate )

Definition at line 942 of file economy.c.

◆ economy_calcPrice()

static int economy_calcPrice ( Spob * spob,
Commodity * commodity,
CommodityPrice * commodityPrice )
static

Used during startup to set price and variation of the economy, depending on spob information.

Parameters
spobThe spob to set price on.
commodityThe commodity to set the price of.
commodityPriceWhere to write the commodity price to.
Returns
0 on success.

Definition at line 621 of file economy.c.

◆ economy_calcUpdatedCommodityPrice()

static void economy_calcUpdatedCommodityPrice ( StarSystem * sys)
static

Modifies commodity price based on neighbouring systems.

Parameters
sysSystem.

Definition at line 823 of file economy.c.

◆ economy_clearKnown()

void economy_clearKnown ( void )

Clears all system knowledge.

Definition at line 962 of file economy.c.

◆ economy_clearSingleSpob()

void economy_clearSingleSpob ( Spob * p)

Clears all economy knowledge of a given spob. Used by the unidiff system.

Definition at line 984 of file economy.c.

◆ economy_destroy()

void economy_destroy ( void )

Destroys the economy.

Definition at line 593 of file economy.c.

◆ economy_execQueued()

int economy_execQueued ( void )

Calls economy_refresh if an economy update is queued.

Definition at line 483 of file economy.c.

◆ economy_getAveragePrice()

int economy_getAveragePrice ( const Commodity * com,
credits_t * mean,
double * std )

Gets the average price of a good as seen by the player (anywhere).

Parameters
comCommodity to get price of.
[out]meanSample mean, rounded to nearest credit.
[out]stdSample standard deviation (via uncorrected population formula).
Returns
The average price of the commodity.

Definition at line 242 of file economy.c.

◆ economy_getAverageSpobPrice()

int economy_getAverageSpobPrice ( const Commodity * com,
const Spob * p,
credits_t * mean,
double * std )

Gets the average price of a good on a spob in a system, using a rolling average over the times the player has landed here.

Parameters
comCommodity to get price of.
pSpob to get price of commodity.
[out]meanSample mean, rounded to nearest credit.
[out]stdSample standard deviation (via uncorrected population formula).
Returns
The average price of the commodity.

Definition at line 172 of file economy.c.

◆ economy_getPrice()

credits_t economy_getPrice ( const Commodity * com,
const StarSystem * sys,
const Spob * p )

Gets the price of a good on a spob in a system.

Parameters
comCommodity to get price of.
sysSystem to get price of commodity.
pSpob to get price of commodity.
Returns
The price of the commodity.

Definition at line 85 of file economy.c.

◆ economy_getPriceAtTime()

credits_t economy_getPriceAtTime ( const Commodity * com,
const StarSystem * sys,
const Spob * p,
ntime_t tme )

Gets the price of a good on a spob in a system.

Parameters
comCommodity to get price of.
sysSystem to get price of commodity.
pSpob to get price of commodity.
tmeTime to get price at, eg as retunred by ntime_get()
Returns
The price of the commodity.

Definition at line 101 of file economy.c.

◆ economy_init()

int economy_init ( void )

Initializes the economy.

Returns
0 on success.

Definition at line 449 of file economy.c.

◆ economy_initialiseCommodityPrices()

void economy_initialiseCommodityPrices ( void )

Initialises commodity prices for the sinusoidal economy model.

Definition at line 859 of file economy.c.

◆ economy_initialiseSingleSystem()

void economy_initialiseSingleSystem ( StarSystem * sys,
Spob * spob )

Definition at line 917 of file economy.c.

◆ economy_modifySystemCommodityPrice()

static void economy_modifySystemCommodityPrice ( StarSystem * sys)
static

Modifies commodity price based on system characteristics.

Parameters
sysSystem.

Definition at line 711 of file economy.c.

◆ economy_refresh()

int economy_refresh ( void )

Regenerates the economy matrix. Should be used if the universe changes in any permanent way.

Definition at line 495 of file economy.c.

◆ economy_smoothCommodityPrice()

static void economy_smoothCommodityPrice ( StarSystem * sys)
static

Calculates smoothing of commodity price based on neighbouring systems.

Parameters
sysSystem.

Definition at line 789 of file economy.c.

◆ economy_sysLoad()

int economy_sysLoad ( xmlNodePtr parent)

Loads player's economy properties from an XML node.

Parameters
parentParent node for economy.
Returns
0 on success.

Definition at line 1001 of file economy.c.

◆ economy_sysSave()

int economy_sysSave ( xmlTextWriterPtr writer)

Saves what is needed to be saved for economy.

Parameters
writerXML writer to use.
Returns
0 on success.

Definition at line 1069 of file economy.c.

◆ economy_update()

int economy_update ( unsigned int dt)

Updates the economy.

Parameters
dtDeltatick in NTIME.

Definition at line 516 of file economy.c.

Variable Documentation

◆ commodity_stack

Commodity* commodity_stack
extern

Contains all the commodities.

Definition at line 39 of file commodity.c.

◆ econ_comm

int* econ_comm = NULL

Commodities to calculate.

Definition at line 61 of file economy.c.

◆ econ_G

cs* econ_G = NULL
static

Admittance matrix.

Definition at line 60 of file economy.c.

◆ econ_initialized

int econ_initialized = 0
static

Is economy system initialized?

Definition at line 58 of file economy.c.

◆ econ_queued

int econ_queued = 0
static

Whether there are any queued updates.

Definition at line 59 of file economy.c.

◆ systems_stack

StarSystem* systems_stack
extern

Star system stack.

Definition at line 92 of file space.c.