[Add] Make $$ from selling outfits.

This commit is contained in:
Allanis 2013-03-08 13:54:30 +00:00
parent ef2bfd2052
commit eeb09fdf05
5 changed files with 32 additions and 18 deletions

View File

@ -41,9 +41,6 @@ static int land_wid = 0; // Primary land window.
static int secondary_wid = 0; // For the second opened land window (We can only have 2 max).
static Planet* planet = NULL;
// Extern.
extern unsigned int player_credits;
// Commodity excahnge.
static void commodity_exchange(void);
static void commodity_exchange_close(char* str);
@ -192,6 +189,11 @@ static void outfits_buy(char* str) {
outfit->mass - player_freeSpace());
return;
}
else if(player_outfitOwned(outfitname) >= outfit->max) {
// Already has too many.
toolkit_alert("You can only carry %d of this outfit.", outfit->max);
return;
}
pilot_addOutfit(player, outfit, q);
outfits_update(NULL);
@ -207,7 +209,13 @@ static void outfits_sell(char* str) {
outfit = outfit_get(outfitname);
q = 1;
pilot_rmOutfit(player, outfit, q);
if(player_outfitOwned(outfitname) <= 0) {
// No outfits to sell.
toolkit_alert("You can't sell something you don't have!");
return;
}
player_credits += outfit->price * pilot_rmOutfit(player, outfit, q);
outfits_update(NULL);
}

View File

@ -403,14 +403,14 @@ static void pilot_hyperspace(Pilot* p) {
}
}
void pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
int pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
int i;
char* s;
for(i = 0; i < pilot->noutfits; i++)
if(strcmp(outfit->name, pilot->outfits[i].outfit->name)==0) {
pilot->outfits[i].quantity += quantity;
return;
return quantity;
}
s = (pilot->secondary) ? pilot->secondary->outfit->name : NULL;
@ -425,10 +425,12 @@ void pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
// Hack due to realloc possibility.
pilot_setSecondary(pilot, s);
return quantity;
}
// Remove an outfit from the pilot.
void pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
int pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
int i;
char* s;
@ -436,6 +438,8 @@ void pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
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;
// Hack in case it reallocs - Can happen even when shrinking.
s = (pilot->secondary) ? pilot->secondary->outfit->name : NULL;
@ -448,10 +452,12 @@ void pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
pilot_setSecondary(pilot, s);
}
return;
return quantity;
}
WARN("Failure attempting to remove %d '%s' from pilot '%s'",
quantity, outfit->name, pilot->name);
return 0;
}
// ==Init pilot.===========================================

View File

@ -118,8 +118,8 @@ void pilot_hit(Pilot* p, const Solid* w, const unsigned int shooter,
void pilot_setSecondary(Pilot* p, const char* secondary);
void pilot_setAmmo(Pilot* p);
double pilot_face(Pilot* p, const float dir);
void pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity);
void pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity);
int pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity);
int pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity);
// Creation.
void pilot_init(Pilot* dest, Ship* ship, char* name, Faction* faction, AI_Profile* ai,

View File

@ -28,8 +28,8 @@
Pilot* player = NULL; // extern in pilot.h
// Player global properties.
char* player_name = NULL; // Player name.
unsigned int player_credits = 0; // Ze monies.
unsigned int combat_crating = 0; // Ze rating.
int player_credits = 0; // Ze monies.
int combat_crating = 0; // Ze rating.
unsigned int player_flags = 0; // Player flags.
// Input.c
double player_turn = 0.; // Turn velocity from input.

View File

@ -18,8 +18,8 @@
extern Pilot* pilot;
extern char* player_name;
extern unsigned int player_flags;
extern unsigned int player_credits;
extern unsigned int combat_crating;
extern int player_credits;
extern int combat_crating;
// Enums.
typedef enum RadarShape_ { RADAR_RECT, RADAR_CIRCLE } RadarShape; // For render functions.