[Fix] You can no longer buy extra outfits.

This commit is contained in:
Allanis 2013-08-07 14:26:45 +01:00
parent 48353d7c79
commit 30aaa7852d

View File

@ -566,9 +566,10 @@ static void pilot_hyperspace(Pilot* p) {
} }
int pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) { int pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
int i, q; int i, q, free_space;
char* osec; char* osec;
free_space = pilot_freeSpace(pilot);
q = quantity; q = quantity;
/* Special case if it's a map. */ /* Special case if it's a map. */
@ -577,10 +578,18 @@ int pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
return 1; /* Must return 1 for paying purposes. */ return 1; /* Must return 1 for paying purposes. */
} }
/* Mod quantity down if it doesn't fit. */
if(q*outfit->mass > free_space)
q = free_space / outfit->mass;
/* Can we actually add any? */
if(q == 0)
return 0;
/* Does outfit already exist? */ /* Does outfit already exist? */
for(i = 0; i < pilot->noutfits; i++) for(i = 0; i < pilot->noutfits; i++)
if(strcmp(outfit->name, pilot->outfits[i].outfit->name)==0) { if(strcmp(outfit->name, pilot->outfits[i].outfit->name)==0) {
pilot->outfits[i].quantity += quantity; pilot->outfits[i].quantity += q;
/* Can't be over max. */ /* Can't be over max. */
if(pilot->outfits[i].quantity > outfit->max) { if(pilot->outfits[i].quantity > outfit->max) {
q -= pilot->outfits[i].quantity - outfit->max; q -= pilot->outfits[i].quantity - outfit->max;
@ -599,7 +608,7 @@ int pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
/* Grow the outfits. */ /* Grow the outfits. */
pilot->outfits = realloc(pilot->outfits, (pilot->noutfits+1)*sizeof(PilotOutfit)); pilot->outfits = realloc(pilot->outfits, (pilot->noutfits+1)*sizeof(PilotOutfit));
pilot->outfits[pilot->noutfits].outfit = outfit; pilot->outfits[pilot->noutfits].outfit = outfit;
pilot->outfits[pilot->noutfits].quantity = quantity; pilot->outfits[pilot->noutfits].quantity = q;
/* Can't be over max. */ /* Can't be over max. */
if(pilot->outfits[pilot->noutfits].quantity > outfit->max) { if(pilot->outfits[pilot->noutfits].quantity > outfit->max) {