[Add] Economy now dynamically flutuates slightly.
This commit is contained in:
parent
1d594b669d
commit
d3c38d90f7
@ -22,6 +22,7 @@
|
|||||||
#include "pilot.h"
|
#include "pilot.h"
|
||||||
#include "rng.h"
|
#include "rng.h"
|
||||||
#include "space.h"
|
#include "space.h"
|
||||||
|
#include "ltime.h"
|
||||||
#include "economy.h"
|
#include "economy.h"
|
||||||
|
|
||||||
#define XML_COMMODITY_ID "Commodities" /* XML section identifier. */
|
#define XML_COMMODITY_ID "Commodities" /* XML section identifier. */
|
||||||
@ -33,6 +34,7 @@
|
|||||||
#define ECON_SELF_RES 3. /**< Additional resistance for the self node. */
|
#define ECON_SELF_RES 3. /**< Additional resistance for the self node. */
|
||||||
#define ECON_FACTION_MOD 0.1 /**< Modifier on Base for faction standings. */
|
#define ECON_FACTION_MOD 0.1 /**< Modifier on Base for faction standings. */
|
||||||
#define ECON_PROD_MODIFIER 500000. /**< Production modifier, divide production by this amount. */
|
#define ECON_PROD_MODIFIER 500000. /**< Production modifier, divide production by this amount. */
|
||||||
|
#define ECON_PROD_VAR 0.01 /**< Define the variability of production. */
|
||||||
|
|
||||||
/* Commodity stack. */
|
/* Commodity stack. */
|
||||||
static Commodity* commodity_stack = NULL;
|
static Commodity* commodity_stack = NULL;
|
||||||
@ -277,18 +279,39 @@ static double econ_calcSysI(unsigned int dt, StarSystem* sys, int price) {
|
|||||||
(void)price;
|
(void)price;
|
||||||
int i;
|
int i;
|
||||||
double I;
|
double I;
|
||||||
double p;
|
double prodfactor, p, pp;
|
||||||
|
double ddt;
|
||||||
Planet* planet;
|
Planet* planet;
|
||||||
|
|
||||||
|
ddt = (double)(dt / LTIME_UNIT_LENGTH);
|
||||||
|
|
||||||
/* Calculate production level. */
|
/* Calculate production level. */
|
||||||
p = 0.;
|
p = 0.;
|
||||||
for(i = 0; i < sys->nplanets; i++) {
|
for(i = 0; i < sys->nplanets; i++) {
|
||||||
planet = sys->planets[i];
|
planet = sys->planets[i];
|
||||||
if(planet_hasService(planet, PLANET_SERVICE_BASIC))
|
if(planet_hasService(planet, PLANET_SERVICE_BASIC)) {
|
||||||
p += planet->prodfactor * sqrt(planet->population);
|
/* Calculate production.
|
||||||
|
*
|
||||||
|
* We base off the current production.
|
||||||
|
*/
|
||||||
|
prodfactor = planet->cur_prodfactor;
|
||||||
|
/* Add a variability factor based on the gaussian distribution. */
|
||||||
|
prodfactor += ECON_PROD_VAR *
|
||||||
|
NormalInverse(RNGF()*0.90 + 0.05)*ddt;
|
||||||
|
/* Add a tendency to return to the planets base production. */
|
||||||
|
prodfactor -= ECON_PROD_VAR *
|
||||||
|
(planet->cur_prodfactor - prodfactor)*ddt;
|
||||||
|
/* Save for next iteration. */
|
||||||
|
planet->cur_prodfactor = prodfactor;
|
||||||
|
/* We base off the sqrt of the population otherwise it changes too fast. */
|
||||||
|
p += prodfactor * sqrt(planet->population);
|
||||||
|
|
||||||
|
/* Add it to the current system production. */
|
||||||
|
p += pp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Intensity is the production minus the consumption. */
|
/* The intensity is basically the modified production. */
|
||||||
I = p / ECON_PROD_MODIFIER;
|
I = p / ECON_PROD_MODIFIER;
|
||||||
|
|
||||||
return I;
|
return I;
|
||||||
@ -322,7 +345,7 @@ static int econ_createGMatrix(void) {
|
|||||||
R = 1./R; /* Must be inverted. */
|
R = 1./R; /* Must be inverted. */
|
||||||
Rsum += R;
|
Rsum += R;
|
||||||
|
|
||||||
/* Matrix is symetrical. */
|
/* Matrix is symetrical and non-diagonal is negative. */
|
||||||
ret = cs_entry(M, i, sys->jumps[j], -R);
|
ret = cs_entry(M, i, sys->jumps[j], -R);
|
||||||
if(ret != 1)
|
if(ret != 1)
|
||||||
WARN("Unable to enter CSparse Matrix Cell.");
|
WARN("Unable to enter CSparse Matrix Cell.");
|
||||||
@ -332,7 +355,8 @@ static int econ_createGMatrix(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set the diagonal. */
|
/* Set the diagonal. */
|
||||||
cs_entry(M, i, i, Rsum + 1./ECON_SELF_RES);
|
Rsum += 1./ECON_SELF_RES; /* We add a resistence for dampening. */
|
||||||
|
cs_entry(M, i, i, Rsum);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compress M matrix and put into G. */
|
/* Compress M matrix and put into G. */
|
||||||
@ -350,6 +374,7 @@ static int econ_createGMatrix(void) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initializes the economy.
|
* @brief Initializes the economy.
|
||||||
|
* @return 0 on success.
|
||||||
*/
|
*/
|
||||||
int economy_init(void) {
|
int economy_init(void) {
|
||||||
int i;
|
int i;
|
||||||
@ -361,16 +386,12 @@ int economy_init(void) {
|
|||||||
systems_stack[i].prices = calloc(econ_nprices, sizeof(double));
|
systems_stack[i].prices = calloc(econ_nprices, sizeof(double));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create the resistance matrix. */
|
|
||||||
if(econ_createGMatrix())
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
/* Initialize the prices. */
|
|
||||||
economy_update(0);
|
|
||||||
|
|
||||||
/* Mark economy as initialized. */
|
/* Mark economy as initialized. */
|
||||||
econ_initialized = 1;
|
econ_initialized = 1;
|
||||||
|
|
||||||
|
/* Refresh economy. */
|
||||||
|
economy_refresh();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -762,6 +762,9 @@ static int planet_parse(Planet* planet, const xmlNodePtr parent) {
|
|||||||
}
|
}
|
||||||
} while(xml_nextNode(node));
|
} while(xml_nextNode(node));
|
||||||
|
|
||||||
|
/* Some postprocessing. */
|
||||||
|
planet->cur_prodfactor = planet->prodfactor;
|
||||||
|
|
||||||
/* Verification. */
|
/* Verification. */
|
||||||
#define MELEMENT(o,s) if(o) WARN("Planet '%s' missing '"s"' element", planet->name)
|
#define MELEMENT(o,s) if(o) WARN("Planet '%s' missing '"s"' element", planet->name)
|
||||||
MELEMENT(planet->gfx_space==NULL, "GFX space");
|
MELEMENT(planet->gfx_space==NULL, "GFX space");
|
||||||
|
@ -66,7 +66,8 @@ typedef struct Planet_ {
|
|||||||
int faction; /**< Planet faction. */
|
int faction; /**< Planet faction. */
|
||||||
|
|
||||||
int population; /**< Population of the planet. */
|
int population; /**< Population of the planet. */
|
||||||
double prodfactor; /**< Production factor of the planet. */
|
double prodfactor; /**< Default production factor of the planet. */
|
||||||
|
double cur_prodfactor; /**< Current real production factor of the planet. */
|
||||||
|
|
||||||
/* Landing details. */
|
/* Landing details. */
|
||||||
char* description; /**< Planet description. */
|
char* description; /**< Planet description. */
|
||||||
|
Loading…
Reference in New Issue
Block a user