[Add] rmOutfits should be mount aware.

This commit is contained in:
Allanis 2014-05-20 15:04:15 +01:00
parent b689102f75
commit 5e34b27baa

View File

@ -1084,25 +1084,39 @@ int pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
* @return Number of the outfits removed from the pilot.
*/
int pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
int i, q, c;
int i, j, q, c, o;
char* osec;
PilotOutfit* po;
c = (outfit_isMod(outfit)) ? outfit->u.mod.cargo : 0;
q = quantity;
for(i = 0; i < pilot->noutfits; i++)
if(strcmp(outfit->name, pilot->outfits[i].outfit->name)==0) {
pilot->outfits[i].quantity -= quantity;
if(pilot->outfits[i].quantity <= 0) {
po = &pilot->outfits[i];
/* Remove quantity. */
o = po->quantity -= quantity;
/* Remove from mount points. */
if((pilot->mounted != NULL) && (po->mounts != NULL)) {
for(j = o-1; j >= po->quantity; j--) {
if(po->mounts[j] != 0)
pilot->mounted[po->mounts[j]]--;
}
}
/* Need to remove the outfit. */
if(po->quantity <= 0) {
/* We didn't actually remove the full amount. */
q += pilot->outfits[i].quantity;
q += po->quantity;
/* Hack in case it reallocs - Can happen even when shrinking. */
osec = (pilot->secondary) ? pilot->secondary->outfit->name : NULL;
/* Free some memory if needed. */
if(pilot->outfits[i].mounts != NULL)
free(pilot->outfits[i].mounts);
if(po->mounts != NULL)
free(po->mounts);
/* Remove the outfit. */
memmove(&pilot->outfits[i], &pilot->outfits[i+1],