[Add] Buy/Sell commodities. They are all the same price at the minute.
This commit is contained in:
parent
91e68ee828
commit
ca84fe6a3a
@ -1,11 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Commodities>
|
<Commodities>
|
||||||
<commodity name="Food">
|
<commodity name="Food">
|
||||||
|
<description>Airtight compressed nutrient packets. Very nutritious.</description>
|
||||||
<high>160</high>
|
<high>160</high>
|
||||||
<medium>140</medium>
|
<medium>140</medium>
|
||||||
<low>120</low>
|
<low>120</low>
|
||||||
</commodity>
|
</commodity>
|
||||||
<commodity name="Ore">
|
<commodity name="Ore">
|
||||||
|
<description>An assortment of ores. Needed for all kinds of processes.</description>
|
||||||
<high>240</high>
|
<high>240</high>
|
||||||
<medium>210</medium>
|
<medium>210</medium>
|
||||||
<low>180</low>
|
<low>180</low>
|
||||||
|
@ -47,6 +47,7 @@ Commodity* commodity_get(const char* name) {
|
|||||||
// Free a commodity.
|
// Free a commodity.
|
||||||
static void commodity_freeOne(Commodity* com) {
|
static void commodity_freeOne(Commodity* com) {
|
||||||
if(com->name) free(com->name);
|
if(com->name) free(com->name);
|
||||||
|
if(com->description) free(com->description);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Commodity* commodity_parse(xmlNodePtr parent) {
|
static Commodity* commodity_parse(xmlNodePtr parent) {
|
||||||
@ -60,7 +61,9 @@ static Commodity* commodity_parse(xmlNodePtr parent) {
|
|||||||
node = parent->xmlChildrenNode;
|
node = parent->xmlChildrenNode;
|
||||||
|
|
||||||
do {
|
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);
|
tmp->high = xml_getInt(node);
|
||||||
else if(xml_isNode(node, "medium"))
|
else if(xml_isNode(node, "medium"))
|
||||||
tmp->medium = xml_getInt(node);
|
tmp->medium = xml_getInt(node);
|
||||||
@ -70,6 +73,7 @@ static Commodity* commodity_parse(xmlNodePtr parent) {
|
|||||||
|
|
||||||
#define MELEMENT(o,s)if(o)WARN("Commodity '%s' missing '"s"' element",tmp->name)
|
#define MELEMENT(o,s)if(o)WARN("Commodity '%s' missing '"s"' element",tmp->name)
|
||||||
MELEMENT(tmp->high==0, "high");
|
MELEMENT(tmp->high==0, "high");
|
||||||
|
MELEMENT(tmp->description==NULL, "description");
|
||||||
MELEMENT(tmp->medium==0, "medium");
|
MELEMENT(tmp->medium==0, "medium");
|
||||||
MELEMENT(tmp->low==0, "low");
|
MELEMENT(tmp->low==0, "low");
|
||||||
#undef MELEMENT
|
#undef MELEMENT
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
typedef struct Commodity_ {
|
typedef struct Commodity_ {
|
||||||
char* name;
|
char* name;
|
||||||
|
char* description;
|
||||||
int low, medium, high; // Prices.
|
int low, medium, high; // Prices.
|
||||||
} Commodity;
|
} Commodity;
|
||||||
|
|
||||||
|
39
src/land.c
39
src/land.c
@ -46,6 +46,7 @@ static Planet* planet = NULL;
|
|||||||
// Commodity excahnge.
|
// Commodity excahnge.
|
||||||
static void commodity_exchange(void);
|
static void commodity_exchange(void);
|
||||||
static void commodity_exchange_close(char* str);
|
static void commodity_exchange_close(char* str);
|
||||||
|
static void commodity_update(char* str);
|
||||||
static void commodity_buy(char* str);
|
static void commodity_buy(char* str);
|
||||||
static void commodity_sell(char* str);
|
static void commodity_sell(char* str);
|
||||||
// Outfits.
|
// Outfits.
|
||||||
@ -86,7 +87,18 @@ static void commodity_exchange(void) {
|
|||||||
|
|
||||||
window_addButton(secondary_wid, -20, 20*2+BUTTON_HEIGHT,
|
window_addButton(secondary_wid, -20, 20*2+BUTTON_HEIGHT,
|
||||||
(BUTTON_WIDTH-20)/2, BUTTON_HEIGHT, "btnCommoditySell",
|
(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);
|
goods = malloc(sizeof(char*)*planet->ncommodities);
|
||||||
for(i = 0; i < planet->ncommodities; i++)
|
for(i = 0; i < planet->ncommodities; i++)
|
||||||
@ -94,7 +106,9 @@ static void commodity_exchange(void) {
|
|||||||
|
|
||||||
window_addList(secondary_wid, 20, -40,
|
window_addList(secondary_wid, 20, -40,
|
||||||
COMMODITY_WIDTH-BUTTON_WIDTH-60, COMMODITY_HEIGHT-80-BUTTON_HEIGHT,
|
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) {
|
static void commodity_exchange_close(char* str) {
|
||||||
@ -102,6 +116,25 @@ static void commodity_exchange_close(char* str) {
|
|||||||
window_destroy(secondary_wid);
|
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) {
|
static void commodity_buy(char* str) {
|
||||||
(void)str;
|
(void)str;
|
||||||
char* comname;
|
char* comname;
|
||||||
@ -124,6 +157,7 @@ static void commodity_buy(char* str) {
|
|||||||
|
|
||||||
q = pilot_addCargo(player, com, q);
|
q = pilot_addCargo(player, com, q);
|
||||||
player_credits -= q * com->medium;
|
player_credits -= q * com->medium;
|
||||||
|
commodity_update(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void commodity_sell(char* str) {
|
static void commodity_sell(char* str) {
|
||||||
@ -138,6 +172,7 @@ static void commodity_sell(char* str) {
|
|||||||
|
|
||||||
q = pilot_rmCargo(player, com, q);
|
q = pilot_rmCargo(player, com, q);
|
||||||
player_credits += q * com->medium;
|
player_credits += q * com->medium;
|
||||||
|
commodity_update(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void outfits(void) {
|
static void outfits(void) {
|
||||||
|
13
src/player.c
13
src/player.c
@ -247,7 +247,7 @@ const char* player_rating(void) {
|
|||||||
else return player_ratings[7];
|
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 player_freeSpace(void) {
|
||||||
int i, s;
|
int i, s;
|
||||||
s = player->ship->cap_weapon;
|
s = player->ship->cap_weapon;
|
||||||
@ -268,6 +268,17 @@ int player_outfitOwned(const char* outfitname) {
|
|||||||
return 0;
|
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
|
// Render the background player stuff, namely planet target
|
||||||
void player_renderBG(void) {
|
void player_renderBG(void) {
|
||||||
double x, y;
|
double x, y;
|
||||||
|
@ -42,6 +42,7 @@ void player_warp(const double x, const double y);
|
|||||||
const char* player_rating(void);
|
const char* player_rating(void);
|
||||||
int player_freeSpace(void);
|
int player_freeSpace(void);
|
||||||
int player_outfitOwned(const char* outfitname);
|
int player_outfitOwned(const char* outfitname);
|
||||||
|
int player_cargoOwned(const char* commodityname);
|
||||||
|
|
||||||
// Keybind actions.
|
// Keybind actions.
|
||||||
void player_setRadarRel(int mod);
|
void player_setRadarRel(int mod);
|
||||||
|
Loading…
Reference in New Issue
Block a user