[Change] outfit_getTech returns outfits instead of names.

This commit is contained in:
Allanis 2013-10-26 20:52:36 +01:00
parent e955b58817
commit ea6df25b0c
3 changed files with 16 additions and 10 deletions

View File

@ -242,6 +242,7 @@ static void commodity_sell(char* str) {
static void outfits_open(void) {
int i;
Outfit** outfits;
char** soutfits;
glTexture** toutfits;
int noutfits;
@ -297,7 +298,7 @@ static void outfits_open(void) {
&gl_smallFont, NULL, NULL);
/* Set up the outfits to buy/sell. */
soutfits = outfit_getTech(&noutfits, land_planet->tech, PLANET_TECH_MAX);
outfits = outfit_getTech(&noutfits, land_planet->tech, PLANET_TECH_MAX);
if(noutfits <= 0) { /* No outfits. */
soutfits = malloc(sizeof(char*));
@ -306,9 +307,14 @@ static void outfits_open(void) {
toutfits[0] = NULL;
noutfits = 1;
} else {
/* Create the outfit arrays. */
soutfits = malloc(sizeof(char*)*noutfits);
toutfits = malloc(sizeof(glTexture*)*noutfits);
for(i = 0; i < noutfits; i++)
toutfits[i] = outfit_get(soutfits[i])->gfx_store;
for(i = 0; i < noutfits; i++) {
soutfits[i] = strdup(outfits[i]->name);
toutfits[i] = outfits[i]->gfx_store;
}
free(outfits);
}
window_addImageArray(secondary_wid, 20, 40,

View File

@ -49,10 +49,10 @@ Outfit* outfit_get(const char* name) {
}
/* Return all the outfits. */
char** outfit_getTech(int* n, const int* tech, const int techmax) {
Outfit** outfit_getTech(int* n, const int* tech, const int techmax) {
int i, j, k, num, price;
Outfit** outfits;
char** outfitnames;
Outfit** result;
OutfitType type;
outfits = malloc(sizeof(Outfit*)*outfit_nstack);
@ -75,7 +75,7 @@ char** outfit_getTech(int* n, const int* tech, const int techmax) {
*n = 0;
price = -1;
type = OUTFIT_TYPE_NULL+1; /* First type. */
outfitnames = malloc(sizeof(char*)*num);
result = malloc(sizeof(Outfit*)*num);
/* Sort by type */
while(type < OUTFIT_TYPE_SENTINEL) {
@ -88,7 +88,7 @@ char** outfit_getTech(int* n, const int* tech, const int techmax) {
if((price == -1) || (outfits[price]->price > outfits[j]->price)) {
/* Check if already in stack. */
for(k = 0; k < (*n); k++)
if(strcmp(outfitnames[k], outfits[j]->name)==0)
if(strcmp(result[k]->name, outfits[j]->name)==0)
break;
/* Not in stack and therefore is cheapest. */
@ -100,7 +100,7 @@ char** outfit_getTech(int* n, const int* tech, const int techmax) {
type++;
else {
/* Add current cheapest to stack. */
outfitnames[*n] = strdup(outfits[price]->name);
result[*n] = outfits[price];
(*n)++;
price = -1;
}
@ -109,7 +109,7 @@ char** outfit_getTech(int* n, const int* tech, const int techmax) {
/* Cleanup. */
free(outfits);
return outfitnames;
return result;
}
/* Give the real shield damage, armour damage and knockback modifier. */

View File

@ -235,7 +235,7 @@ void outfit_calcDamage(double* dshield, double* darmour, double* knockback,
/* Get. */
Outfit* outfit_get(const char* name);
char** outfit_getTech(int* n, const int* tech, const int techmax);
Outfit** outfit_getTech(int* n, const int* tech, const int techmax);
/* Outfit types. */
int outfit_isWeapon(const Outfit* o);
int outfit_isBolt(const Outfit* o);