[Fix] Enforce outfit selling/buying with limits.
This commit is contained in:
parent
23a982fbb5
commit
2a572b713a
@ -71,9 +71,9 @@
|
||||
<spfx>ExpM</spfx>
|
||||
<duration>5</duration>
|
||||
<lockon>1</lockon>
|
||||
<thrust>1200</thrust>
|
||||
<thrust>1600</thrust>
|
||||
<turn>200</turn>
|
||||
<speed>600</speed>
|
||||
<speed>800</speed>
|
||||
<damage>
|
||||
<armour>25</armour>
|
||||
<shield>20</shield>
|
||||
@ -107,9 +107,9 @@
|
||||
<spfx>ExpM</spfx>
|
||||
<duration>7</duration>
|
||||
<lockon>0.5</lockon>
|
||||
<thrust>1200</thrust>
|
||||
<thrust>1300</thrust>
|
||||
<turn>200</turn>
|
||||
<speed>600</speed>
|
||||
<speed>650</speed>
|
||||
<damage>
|
||||
<armour>23</armour>
|
||||
<shield>18</shield>
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "lephisto.h"
|
||||
#include "log.h"
|
||||
#include "toolkit.h"
|
||||
#include "player.h"
|
||||
@ -212,7 +213,8 @@ static void outfits_buy(char* str) {
|
||||
return;
|
||||
}
|
||||
|
||||
player_credits -= outfit->price * pilot_addOutfit(player, outfit, q);
|
||||
player_credits -= outfit->price * pilot_addOutfit(player, outfit,
|
||||
MIN(q, outfit->max));
|
||||
outfits_update(NULL);
|
||||
}
|
||||
|
||||
|
26
src/pilot.c
26
src/pilot.c
@ -408,19 +408,31 @@ static void pilot_hyperspace(Pilot* p) {
|
||||
}
|
||||
|
||||
int pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
|
||||
int i;
|
||||
int i, q;
|
||||
char* s;
|
||||
|
||||
q = quantity;
|
||||
|
||||
for(i = 0; i < pilot->noutfits; i++)
|
||||
if(strcmp(outfit->name, pilot->outfits[i].outfit->name)==0) {
|
||||
pilot->outfits[i].quantity += quantity;
|
||||
return quantity;
|
||||
// Can't be over max.
|
||||
if(pilot->outfits[i].quantity > outfit->max) {
|
||||
q -= pilot->outfits[i].quantity - outfit->max;
|
||||
pilot->outfits[i].quantity = outfit->max;
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
||||
s = (pilot->secondary) ? pilot->secondary->outfit->name : NULL;
|
||||
pilot->outfits = realloc(pilot->outfits, (pilot->noutfits+1)*sizeof(PilotOutfit));
|
||||
pilot->outfits[pilot->noutfits].outfit = outfit;
|
||||
pilot->outfits[pilot->noutfits].quantity = quantity;
|
||||
// Can't be over max.
|
||||
if(pilot->outfits[pilot->noutfits].quantity > outfit->max) {
|
||||
q -= pilot->outfits[pilot->noutfits].quantity - outfit->max;
|
||||
pilot->outfits[i].quantity = outfit->max;
|
||||
}
|
||||
pilot->outfits[pilot->noutfits].timer = 0;
|
||||
|
||||
if(outfit_isTurret(outfit))
|
||||
@ -430,20 +442,22 @@ int pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
|
||||
// Hack due to realloc possibility.
|
||||
pilot_setSecondary(pilot, s);
|
||||
|
||||
return quantity;
|
||||
return q;
|
||||
}
|
||||
|
||||
// Remove an outfit from the pilot.
|
||||
int pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
|
||||
int i;
|
||||
int i, q;
|
||||
char* s;
|
||||
|
||||
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) {
|
||||
// We didn't actually remove the full amount.
|
||||
quantity -= pilot->outfits[i].quantity;
|
||||
q += pilot->outfits[i].quantity;
|
||||
// Hack in case it reallocs - Can happen even when shrinking.
|
||||
s = (pilot->secondary) ? pilot->secondary->outfit->name : NULL;
|
||||
|
||||
@ -456,7 +470,7 @@ int pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
|
||||
|
||||
pilot_setSecondary(pilot, s);
|
||||
}
|
||||
return quantity;
|
||||
return q;
|
||||
}
|
||||
WARN("Failure attempting to remove %d '%s' from pilot '%s'",
|
||||
quantity, outfit->name, pilot->name);
|
||||
|
Loading…
Reference in New Issue
Block a user