diff --git a/dat/planet.xml b/dat/planet.xml index 597ec0b..60a363b 100644 --- a/dat/planet.xml +++ b/dat/planet.xml @@ -14,7 +14,10 @@
3
- 1 + + Food + Ore + konosphere.png @@ -35,7 +38,10 @@
4
- 1 + + Food + Ore + saracraft.png @@ -56,7 +62,9 @@
5
- 1 + + Food + station00.png diff --git a/src/economy.c b/src/economy.c index 7f86768..4f3d721 100644 --- a/src/economy.c +++ b/src/economy.c @@ -33,6 +33,17 @@ void credits2str(char* str, unsigned int credits, int decimals) { else snprintf(str, 16, "%d", credits); } +// Get a commodity. +Commodity* commodity_get(const char* name) { + int i; + for(i = 0; i < commodity_nstack; i++) + if(strcmp(commodity_stack[i].name, name)==0) + return &commodity_stack[i]; + + WARN("Commodity '%s' not found in stack", name); + return NULL; +} + // Free a commodity. static void commodity_freeOne(Commodity* com) { if(com->name) free(com->name); diff --git a/src/land.c b/src/land.c index 0c7de43..b846876 100644 --- a/src/land.c +++ b/src/land.c @@ -69,16 +69,22 @@ static void news_close(char* str); // The local market. static void commodity_exchange(void) { + int i; + char** goods; secondary_wid = window_create("Commodity Exchange", -1, -1, COMMODITY_WIDTH, COMMODITY_HEIGHT); window_addButton(secondary_wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnCommodityClose", "Close", commodity_exchange_close); + + goods = malloc(sizeof(char*)*planet->ncommodities); + for(i = 0; i < planet->ncommodities; i++) + goods[i] = strdup(planet->commodities[i]->name); window_addList(secondary_wid, 20, -40, - COMMODITY_WIDTH-30, COMMODITY_HEIGHT-80-BUTTON_HEIGHT, - "lstGoods", NULL, 0, 0, NULL); + 100, COMMODITY_HEIGHT-80-BUTTON_HEIGHT, + "lstGoods", goods, planet->ncommodities, 0, NULL); } static void commodity_exchange_close(char* str) { diff --git a/src/space.c b/src/space.c index f1c76da..0a35264 100644 --- a/src/space.c +++ b/src/space.c @@ -391,6 +391,18 @@ static Planet* planet_get(const char* name) { } } while((ccur = ccur->next)); } + else if(xml_isNode(cur, "commodities")) { + ccur = cur->children; + do { + if(xml_isNode(ccur, "commodity")) { + tmp->commodities = realloc(tmp->commodities, + (tmp->ncommodities+1) * sizeof(Commodity*)); + tmp->commodities[tmp->ncommodities] = + commodity_get(xml_get(ccur)); + tmp->ncommodities++; + } + } while((ccur = ccur->next)); + } } while((cur = cur->next)); } } while((node = node->next)); @@ -418,6 +430,8 @@ static Planet* planet_get(const char* name) { MELEMENT((planet_hasService(tmp, PLANET_SERVICE_OUTFITS) || planet_hasService(tmp, PLANET_SERVICE_SHIPYARD)) && (flags&FLAG_TECHSET)==0, "tech"); + MELEMENT(planet_hasService(tmp, PLANET_SERVICE_COMMODITY) && + (tmp->ncommodities==0), "commodity"); #undef MELEMENT } else WARN("No planet found matching name '%s'", name); diff --git a/src/space.h b/src/space.h index dac3628..907a745 100644 --- a/src/space.h +++ b/src/space.h @@ -1,6 +1,7 @@ #pragma once #include "faction.h" #include "opengl.h" +#include "economy.h" #include "pilot.h" #define MIN_HYPERSPACE_DIST 1500 @@ -55,6 +56,8 @@ typedef struct Planet_ { char* description; // Planet description. char* bar_description; // Spaceport bar description. unsigned int services; // Offered services. + Commodity** commodities; // Commodities sold. + int ncommodities; // Amount in stock. // tech[0] stores global tech level (everything that and below) while // tech[1-PLANET_TECH_MAX] stores the unique tech levels.