From 5e34b27baa9e79d32d2e9a963346d26c5d21378c Mon Sep 17 00:00:00 2001 From: Allanis Date: Tue, 20 May 2014 15:04:15 +0100 Subject: [PATCH] [Add] rmOutfits should be mount aware. --- src/pilot.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/pilot.c b/src/pilot.c index 7e24460..6081126 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -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],