[Add] rmOutfits should be mount aware.
This commit is contained in:
parent
b689102f75
commit
5e34b27baa
26
src/pilot.c
26
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.
|
* @return Number of the outfits removed from the pilot.
|
||||||
*/
|
*/
|
||||||
int pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
|
int pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
|
||||||
int i, q, c;
|
int i, j, q, c, o;
|
||||||
char* osec;
|
char* osec;
|
||||||
|
PilotOutfit* po;
|
||||||
|
|
||||||
c = (outfit_isMod(outfit)) ? outfit->u.mod.cargo : 0;
|
c = (outfit_isMod(outfit)) ? outfit->u.mod.cargo : 0;
|
||||||
q = quantity;
|
q = quantity;
|
||||||
|
|
||||||
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;
|
po = &pilot->outfits[i];
|
||||||
if(pilot->outfits[i].quantity <= 0) {
|
|
||||||
|
/* 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. */
|
/* 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. */
|
/* Hack in case it reallocs - Can happen even when shrinking. */
|
||||||
osec = (pilot->secondary) ? pilot->secondary->outfit->name : NULL;
|
osec = (pilot->secondary) ? pilot->secondary->outfit->name : NULL;
|
||||||
|
|
||||||
/* Free some memory if needed. */
|
/* Free some memory if needed. */
|
||||||
if(pilot->outfits[i].mounts != NULL)
|
if(po->mounts != NULL)
|
||||||
free(pilot->outfits[i].mounts);
|
free(po->mounts);
|
||||||
|
|
||||||
/* Remove the outfit. */
|
/* Remove the outfit. */
|
||||||
memmove(&pilot->outfits[i], &pilot->outfits[i+1],
|
memmove(&pilot->outfits[i], &pilot->outfits[i+1],
|
||||||
|
Loading…
Reference in New Issue
Block a user