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