diff --git a/dat/commodity.xml b/dat/commodity.xml index ff91d1d..117d7f1 100644 --- a/dat/commodity.xml +++ b/dat/commodity.xml @@ -1,11 +1,13 @@ <?xml version="1.0" encoding="UTF-8"?> <Commodities> <commodity name="Food"> + <description>Airtight compressed nutrient packets. Very nutritious.</description> <high>160</high> <medium>140</medium> <low>120</low> </commodity> <commodity name="Ore"> + <description>An assortment of ores. Needed for all kinds of processes.</description> <high>240</high> <medium>210</medium> <low>180</low> diff --git a/src/economy.c b/src/economy.c index 4f3d721..8241bf7 100644 --- a/src/economy.c +++ b/src/economy.c @@ -47,6 +47,7 @@ Commodity* commodity_get(const char* name) { // Free a commodity. static void commodity_freeOne(Commodity* com) { if(com->name) free(com->name); + if(com->description) free(com->description); } static Commodity* commodity_parse(xmlNodePtr parent) { @@ -60,7 +61,9 @@ static Commodity* commodity_parse(xmlNodePtr parent) { node = parent->xmlChildrenNode; do { - if(xml_isNode(node, "high")) + if(xml_isNode(node, "description")) + tmp->description = strdup(xml_get(node)); + else if(xml_isNode(node, "high")) tmp->high = xml_getInt(node); else if(xml_isNode(node, "medium")) tmp->medium = xml_getInt(node); @@ -69,9 +72,10 @@ static Commodity* commodity_parse(xmlNodePtr parent) { } while((node = node->next)); #define MELEMENT(o,s)if(o)WARN("Commodity '%s' missing '"s"' element",tmp->name) - MELEMENT(tmp->high==0, "high"); - MELEMENT(tmp->medium==0, "medium"); - MELEMENT(tmp->low==0, "low"); + MELEMENT(tmp->high==0, "high"); + MELEMENT(tmp->description==NULL, "description"); + MELEMENT(tmp->medium==0, "medium"); + MELEMENT(tmp->low==0, "low"); #undef MELEMENT return tmp; diff --git a/src/economy.h b/src/economy.h index 4018f9e..4acb2aa 100644 --- a/src/economy.h +++ b/src/economy.h @@ -2,6 +2,7 @@ typedef struct Commodity_ { char* name; + char* description; int low, medium, high; // Prices. } Commodity; diff --git a/src/land.c b/src/land.c index 32c9b87..05d296b 100644 --- a/src/land.c +++ b/src/land.c @@ -46,6 +46,7 @@ static Planet* planet = NULL; // Commodity excahnge. static void commodity_exchange(void); static void commodity_exchange_close(char* str); +static void commodity_update(char* str); static void commodity_buy(char* str); static void commodity_sell(char* str); // Outfits. @@ -86,7 +87,18 @@ static void commodity_exchange(void) { window_addButton(secondary_wid, -20, 20*2+BUTTON_HEIGHT, (BUTTON_WIDTH-20)/2, BUTTON_HEIGHT, "btnCommoditySell", - "Sell", commodity_buy); + "Sell", commodity_sell); + + window_addText(secondary_wid, -20, -40, BUTTON_WIDTH, 20, 0, + "txtSInfo", &gl_smallFont, &cDConsole, + "You have:\n" + "Market price:\n"); + + window_addText(secondary_wid, -20, -40, BUTTON_WIDTH/2, 20, 0, + "txtDInfo", &gl_smallFont, &cBlack, NULL); + + window_addText(secondary_wid, -40, -80, BUTTON_WIDTH-20, 60, 0, + "txtDesc", &gl_smallFont, &cBlack, NULL); goods = malloc(sizeof(char*)*planet->ncommodities); for(i = 0; i < planet->ncommodities; i++) @@ -94,7 +106,9 @@ static void commodity_exchange(void) { window_addList(secondary_wid, 20, -40, COMMODITY_WIDTH-BUTTON_WIDTH-60, COMMODITY_HEIGHT-80-BUTTON_HEIGHT, - "lstGoods", goods, planet->ncommodities, 0, NULL); + "lstGoods", goods, planet->ncommodities, 0, commodity_update); + + commodity_update(NULL); } static void commodity_exchange_close(char* str) { @@ -102,6 +116,25 @@ static void commodity_exchange_close(char* str) { window_destroy(secondary_wid); } +static void commodity_update(char* str) { + (void)str; + char buf[128]; + char* comname; + Commodity* com; + + comname = toolkit_getList(secondary_wid, "lstGoods"); + com = commodity_get(comname); + + snprintf(buf, 128, + "%d\n" + "%d Screds/ton\n", + player_cargoOwned(comname), + com->medium); + + window_modifyText(secondary_wid, "txtDInfo", buf); + window_modifyText(secondary_wid, "txtDesc", com->description); +} + static void commodity_buy(char* str) { (void)str; char* comname; @@ -124,6 +157,7 @@ static void commodity_buy(char* str) { q = pilot_addCargo(player, com, q); player_credits -= q * com->medium; + commodity_update(NULL); } static void commodity_sell(char* str) { @@ -138,6 +172,7 @@ static void commodity_sell(char* str) { q = pilot_rmCargo(player, com, q); player_credits += q * com->medium; + commodity_update(NULL); } static void outfits(void) { diff --git a/src/player.c b/src/player.c index 344fd8c..b3b285a 100644 --- a/src/player.c +++ b/src/player.c @@ -247,7 +247,7 @@ const char* player_rating(void) { else return player_ratings[7]; } -// Return how much space the player has remaining. +// Return how much weapon. space the player has remaining. int player_freeSpace(void) { int i, s; s = player->ship->cap_weapon; @@ -268,6 +268,17 @@ int player_outfitOwned(const char* outfitname) { return 0; } +// Return how many of the commodity the player has. +int player_cargoOwned(const char* commodityname) { + int i; + + for(i = 0; i < player->ncommodities; i++) + if(strcmp(commodityname, player->commodities[i].commodity->name)==0) + return player->commodities[i].quantity; + + return 0; +} + // Render the background player stuff, namely planet target void player_renderBG(void) { double x, y; diff --git a/src/player.h b/src/player.h index 22e8c90..6d90f81 100644 --- a/src/player.h +++ b/src/player.h @@ -42,6 +42,7 @@ void player_warp(const double x, const double y); const char* player_rating(void); int player_freeSpace(void); int player_outfitOwned(const char* outfitname); +int player_cargoOwned(const char* commodityname); // Keybind actions. void player_setRadarRel(int mod);