[Add] Planets now have commodities. Nothing can be done with them yet ;)
This commit is contained in:
parent
4f0420d82f
commit
aa4112f2df
@ -14,7 +14,10 @@
|
||||
<tech>
|
||||
<main>3</main>
|
||||
</tech>
|
||||
<commodities>1</commodities>
|
||||
<commodities>
|
||||
<commodity>Food</commodity>
|
||||
<commodity>Ore</commodity>
|
||||
</commodities>
|
||||
</general>
|
||||
<GFX>
|
||||
<space>konosphere.png</space>
|
||||
@ -35,7 +38,10 @@
|
||||
<tech>
|
||||
<main>4</main>
|
||||
</tech>
|
||||
<commodities>1</commodities>
|
||||
<commodities>
|
||||
<commodity>Food</commodity>
|
||||
<commodity>Ore</commodity>
|
||||
</commodities>
|
||||
</general>
|
||||
<GFX>
|
||||
<space>saracraft.png</space>
|
||||
@ -56,7 +62,9 @@
|
||||
<tech>
|
||||
<main>5</main>
|
||||
</tech>
|
||||
<commodities>1</commodities>
|
||||
<commodities>
|
||||
<commodity>Food</commodity>
|
||||
</commodities>
|
||||
</general>
|
||||
<GFX>
|
||||
<space>station00.png</space>
|
||||
|
@ -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);
|
||||
|
10
src/land.c
10
src/land.c
@ -69,6 +69,8 @@ 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);
|
||||
|
||||
@ -76,9 +78,13 @@ static void commodity_exchange(void) {
|
||||
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) {
|
||||
|
14
src/space.c
14
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);
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user