diff --git a/commodities.c b/commodities.c index 2c8846e8..73d829fe 100644 --- a/commodities.c +++ b/commodities.c @@ -176,3 +176,26 @@ struct commodity *read_commodities(char *filename, int *ncommodities) *ncommodities = n; return clist; } + +/* economy, tech_level, government will be between 0.0 and 1.0 indicating the + * "wealthiness", "techiness", and "government stability" of the planet, + * respectively. + */ +float commodity_calculate_price(struct commodity *c, + float economy, float tech_level, float government) +{ + float econ_price_factor, tech_level_factor, government_factor, price; + + econ_price_factor = 2.0f * (economy - 0.5f) * c->econ_sensitivity; + tech_level_factor = 2.0f * (tech_level - 0.5f) * c->tech_sensitivity; + government_factor = 2.0f * (government - 0.5f) * c->govt_sensitivity; + + price = c->base_price + + c->base_price * econ_price_factor + + c->base_price * tech_level_factor + + c->base_price * government_factor; + + /* TODO: add some random variability, but not enough to swamp. */ + return price; +} + diff --git a/commodities.h b/commodities.h index b9162b53..97970fa5 100644 --- a/commodities.h +++ b/commodities.h @@ -34,4 +34,11 @@ struct commodity { struct commodity *read_commodities(char *filename, int *ncommodities); +/* economy, tech_level, government will be between 0.0 and 1.0 indicating the + * "wealthiness", "techiness", and "government stability" of the planet, + * respectively. + */ +float commodity_calculate_price(struct commodity *c, + float economy, float tech_level, float government); + #endif diff --git a/share/snis/commodities.txt b/share/snis/commodities.txt index 0a760479..db6162dd 100644 --- a/share/snis/commodities.txt +++ b/share/snis/commodities.txt @@ -9,75 +9,75 @@ # float govt_sensitivity; range: 0 - 1, how sensitive price is to govt. stability # float tech_sensitivity; range: 0 - 1, how sensitive price is to tech level # -dubious metaphors, volumes, 3.0, 0.2, 1.0, 0.0, 0.0, 0.0 -spicy curry, barrels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -spiritual hogwash, pamphlets, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -negative entropy, casks, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -ethical theories, manifestos, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -wine, casks, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -racy novellas, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -mysterious nostrums, vials, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -accurate horoscopes, rolls, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -cylindric diamacron, cylinders, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -jakk, kilograms, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -complicated art, flights, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -tax returns, manila folders, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -suspect philosophical theories, monographs, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -teakettles, crates, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -legal documents, volumes, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -recreational drugs, kilos, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -misc. positronics, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -dubious financial instruments, tranches, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -corn fritters, baskets, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -conspiracy theories, manifestos, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -double entendres, comprehensions, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -airtight religions, prevarications, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -onions, bushels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -bolonium, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -tractor parts, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -stolen weapons designs, briefcases, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -diplomatic papers, briefcases, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -ancient artifacts, crates, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -oxygen, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -hydrazine, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -aluminum, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -thorium, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -Misc. Krustaceans, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -Oil, barrels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -kerosene, barrels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -bacon, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -cream gravy, barrels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -Frozen biscuit dough, barrels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 +dubious metaphors, volumes, 3.0, 0.2, 1.0, 0.3, 0.1, -0.2 +spicy curry, barrels, 10.0, 0.2, 1.0, 0.2, 0.0, 0.0 +spiritual hogwash, pamphlets, 10.0, 0.2, 1.0, 0.2, 0.3, 0.0 +negative entropy, casks, 10.0, 0.2, 1.0, 0.2, 0.0, 0.2 +ethical theories, manifestos, 10.0, 0.2, 1.0, 0.2, 0.2, 0.0 +wine, casks, 10.0, 0.2, 1.0, 0.2, 0.2, 0.0 +racy novellas, tons, 10.0, 0.2, 1.0, 0.2, 0.2, 0.0 +mysterious nostrums, vials, 10.0, 0.2, 1.0, 0.1, 0.0, -0.1 +accurate horoscopes, rolls, 10.0, 0.2, 1.0, 0.2, 0.05, -0.1 +cylindric diamacron, cylinders, 10.0, 0.2, 1.0, 0.3, 0.1, 0.05 +jakk, kilograms, 10.0, 0.2, 1.0, 0.3, 0.2, 0.0 +complicated art, flights, 10.0, 0.2, 1.0, 0.3, 0.2, 0.2 +tax returns, manila folders, 10.0, 0.2, 1.0, 0.1, 0.2, 0.0 +suspect philosophical theories, monographs, 10.0, 0.2, 1.0, 0.1, 0.2, 0.0 +teakettles, crates, 10.0, 0.2, 1.0, 0.0, 0.0, -0.1 +legal documents, volumes, 10.0, 0.2, 1.0, 0.1, 0.1, 0.1 +recreational drugs, kilos, 10.0, 0.2, 1.0, 0.3, 0.3, 0.0 +misc. positronics, tons, 10.0, 0.2, 1.0, 0.1, 0.0, 0.2 +dubious financial instruments, tranches, 10.0, 0.2, 1.0, 0.1, 0.1, 0.1 +corn fritters, baskets, 10.0, 0.2, 1.0, 0.1, 0.0, 0.1 +conspiracy theories, manifestos, 10.0, 0.2, 1.0, 0.1, 0.2, 0.0 +double entendres, comprehensions, 10.0, 0.2, 1.0, 0.2, 0.2, 0.0 +airtight religions, prevarications, 10.0, 0.2, 1.0, -0.1, 0.2, -0.2 +onions, bushels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.2 +bolonium, tons, 10.0, 0.2, 1.0, 0.0, 0.0, -0.2 +tractor parts, tons, 10.0, 0.2, 1.0, 0.0, 0.0, -0.2 +stolen weapons designs, briefcases, 10.0, 0.2, 1.0, 0.0, -0.2, 0.3 +diplomatic papers, briefcases, 10.0, 0.2, 1.0, 0.0, -0.2, 0.3 +ancient artifacts, crates, 10.0, 0.2, 1.0, 0.3, 0.0, 0.3 +oxygen, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.3 +hydrazine, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.3 +aluminum, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.3 +thorium, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.3 +Misc. Krustaceans, tons, 10.0, 0.2, 1.0, 0.2, 0.0, 0.0 +Oil, barrels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.1 +kerosene, barrels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.1 +bacon, tons, 10.0, 0.2, 1.0, 0.0, 0.0, -0.1 +cream gravy, barrels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.1 +Frozen biscuit dough, barrels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.1 Chippos, bags, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 Ethanol, kegs, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 tobacco, cartons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -gold, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -platinum, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -scrap metal, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 +gold, tons, 10.0, 0.2, 1.0, 0.3, 0.2, 0.2 +platinum, tons, 10.0, 0.2, 1.0, 0.3, 0.2, 0.2 +scrap metal, tons, 10.0, 0.2, 1.0, 0.3, 0.0, 0.2 iron ore, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -thorium ore, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -bauxite, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -skittlebrau, kegs, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -peanuts, pkgs, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -beer, kegs, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -Champagne, bottles, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -vodka, bottles, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -whiskey, barrels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -distilling equipment, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -textiles, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -dried pasta, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -beeves, sides, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -raisins, bushels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -wheat, bushels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -corn, bushels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -flour, tons, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -cheese, wheels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -bullets, gross, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -maui wowie, kilograms, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -flatware, pkgs, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -cook stoves, units, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -duunmelons, bushels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -betelberries, bushels, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -pharmaceuticals, kilograms, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -coffins, units, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 -laser pistols, units, 10.0, 0.2, 1.0, 0.0, 0.0, 0.0 +thorium ore, tons, 10.0, 0.2, 1.0, 0.2, 0.0, 0.2 +bauxite, tons, 10.0, 0.2, 1.0, 0.2, 0.0, 0.2 +skittlebrau, kegs, 10.0, 0.2, 1.0, 0.2, 0.1, 0.0 +peanuts, pkgs, 10.0, 0.2, 1.0, 0.02, 0.0, 0.04 +beer, kegs, 10.0, 0.2, 1.0, 0.2, 0.0, 0.1 +Champagne, bottles, 10.0, 0.2, 1.0, 0.2, 0.2, 0.1 +vodka, bottles, 10.0, 0.2, 1.0, 0.1, 0.2, 0.1 +whiskey, barrels, 10.0, 0.2, 1.0, 0.3, 0.1, 0.1 +distilling equipment, tons, 10.0, 0.2, 1.0, 0.1, 0.3, 0.2 +textiles, tons, 10.0, 0.2, 1.0, 0.05, 0.05, 0.05 +dried pasta, tons, 10.0, 0.2, 1.0, 0.05, 0.00, 0.05 +beeves, sides, 10.0, 0.2, 1.0, 0.2, 0.0, 0.05 +raisins, bushels, 10.0, 0.2, 1.0, 0.05, 0.0, 0.05 +wheat, bushels, 10.0, 0.2, 1.0, 0.1, 0.0, 0.05 +corn, bushels, 10.0, 0.2, 1.0, 0.1, 0.0, 0.05 +flour, tons, 10.0, 0.2, 1.0, 0.05, 0.0, 0.05 +cheese, wheels, 10.0, 0.2, 1.0, 0.1, 0.0, 0.0 +bullets, gross, 10.0, 0.2, 1.0, 0.2, 0.2, 0.0 +maui wowie, kilograms, 10.0, 0.2, 1.0, 0.3, 0.3, 0.0 +flatware, pkgs, 10.0, 0.2, 1.0, 0.03, 0.0, -0.05 +cook stoves, units, 10.0, 0.2, 1.0, 0.03, 0.0, 0.03 +duunmelons, bushels, 10.0, 0.2, 1.0, 0.05, 0.0, 0.05 +betelberries, bushels, 10.0, 0.2, 1.0, 0.05, 0.0, 0.05 +pharmaceuticals, kilograms, 10.0, 0.2, 1.0, 0.2, 0.2, 0.2 +coffins, units, 10.0, 0.2, 1.0, 0.03, 0.0, 0.03 +laser pistols, units, 10.0, 0.2, 1.0, 0.1, 0.1, 0.1 diff --git a/snis_server.c b/snis_server.c index a77865a8..fea460b9 100644 --- a/snis_server.c +++ b/snis_server.c @@ -3935,6 +3935,64 @@ static int mkt_item_already_present(struct marketplace_data *mkt, int nitems, in return 0; } +static float calculate_commodity_price(struct snis_entity *planet, int item) +{ + float economy, tech_level, government; +#if 0 + int i; + static int test_done = 0; + float price; + + if (!test_done) { + + for (i = 0; i < ARRAY_SIZE(economy_name); i++) { + economy = 1.0f - (float) i / (float) ARRAY_SIZE(economy_name); + tech_level = 0.5f; + government = 0.5f; + price = commodity_calculate_price(&commodity[item], + economy, tech_level, government); + printf("economy %d: %.2f %s\n", i, price, commodity[item].name); + } + for (i = 0; i < ARRAY_SIZE(tech_level_name); i++) { + economy = 0.5f; + tech_level = 1.0f - (float) i / (float) ARRAY_SIZE(tech_level_name); + government = 0.5f; + price = commodity_calculate_price(&commodity[item], + economy, tech_level, government); + printf("tech level %d: %.2f %s\n", i, price, commodity[item].name); + } + for (i = 0; i < ARRAY_SIZE(government_name); i++) { + economy = 0.5f; + tech_level = 0.5f; + government = 1.0f - (float) i / (float) ARRAY_SIZE(government_name); + price = commodity_calculate_price(&commodity[item], + economy, tech_level, government); + printf("government %d: %.2f %s\n", i, price, commodity[item].name); + } + test_done = 1; + } +#endif + + /* economy, tech_level, government will be between 0.0 and 1.0 indicating the + * "wealthiness", "techiness", and "government stability" of the planet, + * respectively. + */ + if (planet) { + economy = 1.0f - (float) planet->tsd.planet.economy / + (float) ARRAY_SIZE(economy_name); + tech_level = 1.0f - (float) planet->tsd.planet.tech_level / + (float) ARRAY_SIZE(tech_level_name); + government = 1.0f - (float) planet->tsd.planet.government / + (float) ARRAY_SIZE(government_name); + } else { + /* Deep space starbases will be in top 10% of everything, let's say */ + economy = 1.0 - snis_randn(100) / 1000; + tech_level = 1.0 - snis_randn(100) / 1000; + government = 1.0 - snis_randn(100) / 1000; + } + return commodity_calculate_price(&commodity[item], economy, tech_level, government); +} + static void init_starbase_market(struct snis_entity *o) { int i; @@ -3964,10 +4022,23 @@ static void fabricate_prices(struct snis_entity *starbase) { int i, j; float variation; + struct snis_entity *planet; + + /* lookup associated planet, if any... */ + if (starbase->tsd.starbase.associated_planet_id < 0) { + planet = NULL; + } else { + i = lookup_by_id(starbase->tsd.starbase.associated_planet_id); + if (i < 0) + planet = NULL; + else + planet = &go[i]; + } - /* FIXME: do something better. */ + /* calculate commodity prices at this starbase based on assoc. planet */ for (i = 0; i < ncommodities; i++) - starbase->tsd.starbase.bid_price[i] = (float) (snis_randn(100) + 5); + starbase->tsd.starbase.bid_price[i] = + calculate_commodity_price(planet, i); starbase->tsd.starbase.part_price = malloc(sizeof(*starbase->tsd.starbase.part_price) * ((DAMCON_SYSTEM_COUNT - 1) * DAMCON_PARTS_PER_SYSTEM)); for (i = 0; i < DAMCON_SYSTEM_COUNT - 1; i++) {