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

View File

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