[Add] Selling of outfits, also improved purchasing of outfits.
This commit is contained in:
parent
36a8847248
commit
a33bb0624a
@ -102,7 +102,7 @@ static void board_stealCreds(char* str) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
credits += board_credits;
|
player_credits += board_credits;
|
||||||
board_credits = 0;
|
board_credits = 0;
|
||||||
board_update(); // Update the lack of credits.
|
board_update(); // Update the lack of credits.
|
||||||
player_message("You manage to steal the ship's Scred");
|
player_message("You manage to steal the ship's Scred");
|
||||||
|
@ -5,12 +5,14 @@
|
|||||||
// Convert credits to a usable string for displaying.
|
// Convert credits to a usable string for displaying.
|
||||||
// str must have 10 characters allocated.
|
// str must have 10 characters allocated.
|
||||||
void credits2str(char* str, unsigned int credits, int decimals) {
|
void credits2str(char* str, unsigned int credits, int decimals) {
|
||||||
if(credits >= 1000000000)
|
if(decimals < 0)
|
||||||
snprintf(str, 10, "%.*fB", decimals, (double)credits / 1000000000.);
|
snprintf(str, 32, "%d", credits);
|
||||||
|
else if(credits >= 1000000000)
|
||||||
|
snprintf(str, 16, "%.*fB", decimals, (double)credits / 1000000000.);
|
||||||
else if(credits >= 1000000)
|
else if(credits >= 1000000)
|
||||||
snprintf(str, 10, "%*fM", decimals, (double)credits / 1000000.);
|
snprintf(str, 16, "%*fM", decimals, (double)credits / 1000000.);
|
||||||
else if(credits >= 1000)
|
else if(credits >= 1000)
|
||||||
snprintf(str, 10, "%.*fK", decimals, (double)credits / 1000.);
|
snprintf(str, 16, "%.*fK", decimals, (double)credits / 1000.);
|
||||||
else snprintf(str, 10, "%d", credits);
|
else snprintf(str, 16, "%d", credits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
44
src/land.c
44
src/land.c
@ -41,6 +41,9 @@ 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 int secondary_wid = 0; // For the second opened land window (We can only have 2 max).
|
||||||
static Planet* planet = NULL;
|
static Planet* planet = NULL;
|
||||||
|
|
||||||
|
// Extern.
|
||||||
|
extern unsigned int player_credits;
|
||||||
|
|
||||||
// Commodity excahnge.
|
// Commodity excahnge.
|
||||||
static void commodity_exchange(void);
|
static void commodity_exchange(void);
|
||||||
static void commodity_exchange_close(char* str);
|
static void commodity_exchange_close(char* str);
|
||||||
@ -49,6 +52,7 @@ static void outfits(void);
|
|||||||
static void outfits_close(char* str);
|
static void outfits_close(char* str);
|
||||||
static void outfits_update(char* str);
|
static void outfits_update(char* str);
|
||||||
static void outfits_buy(char* str);
|
static void outfits_buy(char* str);
|
||||||
|
static void outfits_sell(char* str);
|
||||||
// Shipyard.
|
// Shipyard.
|
||||||
static void shipyard(void);
|
static void shipyard(void);
|
||||||
static void shipyard_close(char* str);
|
static void shipyard_close(char* str);
|
||||||
@ -104,15 +108,18 @@ static void outfits(void) {
|
|||||||
"Buy", outfits_buy);
|
"Buy", outfits_buy);
|
||||||
|
|
||||||
window_addButton(secondary_wid, -40-BUTTON_WIDTH, 40+BUTTON_HEIGHT,
|
window_addButton(secondary_wid, -40-BUTTON_WIDTH, 40+BUTTON_HEIGHT,
|
||||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnInfoOutfit",
|
BUTTON_WIDTH, BUTTON_HEIGHT, "btnSellOutfit",
|
||||||
"Info", NULL);
|
"Sell", outfits_sell);
|
||||||
|
|
||||||
window_addText(secondary_wid, 40+200+40, -80,
|
window_addText(secondary_wid, 40+200+40, -80,
|
||||||
80, 96, 0, "txtSDesc", &gl_smallFont, &cDConsole,
|
80, 96, 0, "txtSDesc", &gl_smallFont, &cDConsole,
|
||||||
"Name:\n"
|
"Name:\n"
|
||||||
"Type:\n"
|
"Type:\n"
|
||||||
|
"Owned:\n"
|
||||||
|
"Space taken:\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Price:\n");
|
"Price:\n"
|
||||||
|
"Money:\n");
|
||||||
|
|
||||||
window_addText(secondary_wid, 40+200+40+80, -80,
|
window_addText(secondary_wid, 40+200+40+80, -80,
|
||||||
250, 96, 0, "txtDDesc", &gl_smallFont, &cBlack, NULL);
|
250, 96, 0, "txtDDesc", &gl_smallFont, &cBlack, NULL);
|
||||||
@ -140,21 +147,31 @@ static void outfits_update(char* str) {
|
|||||||
(void)str;
|
(void)str;
|
||||||
char* outfitname;
|
char* outfitname;
|
||||||
Outfit* outfit;
|
Outfit* outfit;
|
||||||
char buf[80], buf2[32];
|
char buf[80], buf2[32], buf3[32];
|
||||||
|
|
||||||
outfitname = toolkit_getList(secondary_wid, "lstOutfits");
|
outfitname = toolkit_getList(secondary_wid, "lstOutfits");
|
||||||
outfit = outfit_get(outfitname);
|
outfit = outfit_get(outfitname);
|
||||||
|
|
||||||
window_modifyText(secondary_wid, "txtDescription", outfit->description);
|
window_modifyText(secondary_wid, "txtDescription", outfit->description);
|
||||||
credits2str(buf2, outfit->price, 0);
|
credits2str(buf2, outfit->price, -1);
|
||||||
|
credits2str(buf3, player_credits, 2);
|
||||||
snprintf(buf, 80,
|
snprintf(buf, 80,
|
||||||
"%s\n"
|
"%s\n"
|
||||||
"%s\n"
|
"%s\n"
|
||||||
|
"%d\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
"%d\n"
|
||||||
|
"%d\n"
|
||||||
|
"\n"
|
||||||
|
"%s Scred\n"
|
||||||
"%s SCred\n",
|
"%s SCred\n",
|
||||||
outfit->name,
|
outfit->name,
|
||||||
outfit_getType(outfit),
|
outfit_getType(outfit),
|
||||||
buf2);
|
player_outfitOwned(outfitname),
|
||||||
|
outfit->mass,
|
||||||
|
player_freeSpace(),
|
||||||
|
buf2,
|
||||||
|
buf3);
|
||||||
|
|
||||||
window_modifyText(secondary_wid, "txtDDesc", buf);
|
window_modifyText(secondary_wid, "txtDDesc", buf);
|
||||||
}
|
}
|
||||||
@ -171,6 +188,21 @@ static void outfits_buy(char* str) {
|
|||||||
q = 1; // Q should be dependant on MOD keys. TODO
|
q = 1; // Q should be dependant on MOD keys. TODO
|
||||||
|
|
||||||
pilot_addOutfit(player, outfit, q);
|
pilot_addOutfit(player, outfit, q);
|
||||||
|
outfits_update(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void outfits_sell(char* str) {
|
||||||
|
(void)str;
|
||||||
|
char* outfitname;
|
||||||
|
Outfit* outfit;
|
||||||
|
int q;
|
||||||
|
|
||||||
|
outfitname = toolkit_getList(secondary_wid, "lstOutfits");
|
||||||
|
outfit = outfit_get(outfitname);
|
||||||
|
q = 1;
|
||||||
|
|
||||||
|
pilot_rmOutfit(player, outfit, q);
|
||||||
|
outfits_update(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void shipyard(void) {
|
static void shipyard(void) {
|
||||||
|
55
src/pilot.c
55
src/pilot.c
@ -25,7 +25,7 @@ int pilots = 0;
|
|||||||
static int mpilots = 0;
|
static int mpilots = 0;
|
||||||
|
|
||||||
extern Pilot* player;
|
extern Pilot* player;
|
||||||
extern unsigned int combat_rating;
|
extern unsigned int combat_crating;
|
||||||
|
|
||||||
// Stack of fleets.
|
// Stack of fleets.
|
||||||
static Fleet* fleet_stack = NULL;
|
static Fleet* fleet_stack = NULL;
|
||||||
@ -218,7 +218,7 @@ void pilot_hit(Pilot* p, const Solid* w, const unsigned int shooter,
|
|||||||
if(!pilot_isFlag(p, PILOT_DEAD)) {
|
if(!pilot_isFlag(p, PILOT_DEAD)) {
|
||||||
pilot_dead(p);
|
pilot_dead(p);
|
||||||
// Adjust the combat rating based on pilot mass.
|
// Adjust the combat rating based on pilot mass.
|
||||||
if(shooter == PLAYER_ID) combat_rating += MAX(1, p->ship->mass/50);
|
if(shooter == PLAYER_ID) combat_crating += MAX(1, p->ship->mass/50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,6 +237,28 @@ void pilot_dead(Pilot* p) {
|
|||||||
pilot_setFlag(p, PILOT_DEAD);
|
pilot_setFlag(p, PILOT_DEAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pilot_setSecondary(Pilot* p, const char* secondary) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if(secondary == NULL) {
|
||||||
|
p->secondary = NULL;
|
||||||
|
p->ammo = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < p->noutfits; i++) {
|
||||||
|
if(strcmp(secondary, p->outfits[i].outfit->name)==0) {
|
||||||
|
p->secondary = &p->outfits[i];;
|
||||||
|
pilot_setAmmo(p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WARN("Attempted to set pilot '%s' secondary weapon to non-existing '%s'",
|
||||||
|
p->name, secondary);
|
||||||
|
p->secondary = NULL;
|
||||||
|
p->ammo = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Set the pilot's ammo based on their secondary weapon.
|
// Set the pilot's ammo based on their secondary weapon.
|
||||||
void pilot_setAmmo(Pilot* p) {
|
void pilot_setAmmo(Pilot* p) {
|
||||||
int i;
|
int i;
|
||||||
@ -402,13 +424,34 @@ void pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
|
|||||||
pilot_setFlag(pilot, PILOT_HASTURRET);
|
pilot_setFlag(pilot, PILOT_HASTURRET);
|
||||||
|
|
||||||
// Hack due to realloc possibility.
|
// Hack due to realloc possibility.
|
||||||
if(s) {
|
pilot_setSecondary(pilot, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove an outfit from the pilot.
|
||||||
|
void pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity) {
|
||||||
|
int i;
|
||||||
|
char* s;
|
||||||
|
|
||||||
for(i = 0; i < pilot->noutfits; i++)
|
for(i = 0; i < pilot->noutfits; i++)
|
||||||
if(strcmp(s, pilot->outfits[i].outfit->name)==0) {
|
if(strcmp(outfit->name, pilot->outfits[i].outfit->name)==0) {
|
||||||
pilot->secondary = &pilot->outfits[i];
|
pilot->outfits[i].quantity -= quantity;
|
||||||
break;
|
if(pilot->outfits[i].quantity <= 0) {
|
||||||
|
// Hack in case it reallocs - Can happen even when shrinking.
|
||||||
|
s = (pilot->secondary) ? pilot->secondary->outfit->name : NULL;
|
||||||
|
|
||||||
|
// Remove the outfit.
|
||||||
|
memmove(pilot->outfits+i, pilot->outfits+i+1,
|
||||||
|
sizeof(PilotOutfit)*(pilot->noutfits-i));
|
||||||
|
pilot->noutfits--;
|
||||||
|
pilot->outfits = realloc(pilot->outfits,
|
||||||
|
sizeof(PilotOutfit)*(pilot->noutfits));
|
||||||
|
|
||||||
|
pilot_setSecondary(pilot, s);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
WARN("Failure attempting to remove %d '%s' from pilot '%s'",
|
||||||
|
quantity, outfit->name, pilot->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==Init pilot.===========================================
|
// ==Init pilot.===========================================
|
||||||
|
@ -115,9 +115,11 @@ Fleet* fleet_get(const char* name);
|
|||||||
void pilot_shoot(Pilot* p, const unsigned int target, const int secondary);
|
void pilot_shoot(Pilot* p, const unsigned int target, const int secondary);
|
||||||
void pilot_hit(Pilot* p, const Solid* w, const unsigned int shooter,
|
void pilot_hit(Pilot* p, const Solid* w, const unsigned int shooter,
|
||||||
const double damage_shield, const double damage_armour);
|
const double damage_shield, const double damage_armour);
|
||||||
|
void pilot_setSecondary(Pilot* p, const char* secondary);
|
||||||
void pilot_setAmmo(Pilot* p);
|
void pilot_setAmmo(Pilot* p);
|
||||||
double pilot_face(Pilot* p, const float dir);
|
double pilot_face(Pilot* p, const float dir);
|
||||||
void pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity);
|
void pilot_addOutfit(Pilot* pilot, Outfit* outfit, int quantity);
|
||||||
|
void pilot_rmOutfit(Pilot* pilot, Outfit* outfit, int quantity);
|
||||||
|
|
||||||
// Creation.
|
// Creation.
|
||||||
void pilot_init(Pilot* dest, Ship* ship, char* name, Faction* faction, AI_Profile* ai,
|
void pilot_init(Pilot* dest, Ship* ship, char* name, Faction* faction, AI_Profile* ai,
|
||||||
|
46
src/player.c
46
src/player.c
@ -28,8 +28,8 @@
|
|||||||
Pilot* player = NULL; // extern in pilot.h
|
Pilot* player = NULL; // extern in pilot.h
|
||||||
// Player global properties.
|
// Player global properties.
|
||||||
char* player_name = NULL; // Player name.
|
char* player_name = NULL; // Player name.
|
||||||
unsigned int credits = 0; // Ze monies.
|
unsigned int player_credits = 0; // Ze monies.
|
||||||
unsigned int combat_rating = 0; // Ze rating.
|
unsigned int combat_crating = 0; // Ze rating.
|
||||||
unsigned int player_flags = 0; // Player flags.
|
unsigned int player_flags = 0; // Player flags.
|
||||||
// Input.c
|
// Input.c
|
||||||
double player_turn = 0.; // Turn velocity from input.
|
double player_turn = 0.; // Turn velocity from input.
|
||||||
@ -155,8 +155,8 @@ void player_new(void) {
|
|||||||
else if(xml_isNode(tmp, "y")) y = xml_getFloat(tmp);
|
else if(xml_isNode(tmp, "y")) y = xml_getFloat(tmp);
|
||||||
} while((tmp = tmp->next));
|
} while((tmp = tmp->next));
|
||||||
}
|
}
|
||||||
else if(xml_isNode(cur, "combat_rating"))
|
else if(xml_isNode(cur, "combat_crating"))
|
||||||
combat_rating = xml_getInt(cur);
|
combat_crating = xml_getInt(cur);
|
||||||
} while((cur = cur->next));
|
} while((cur = cur->next));
|
||||||
}
|
}
|
||||||
}while((node = node->next));
|
}while((node = node->next));
|
||||||
@ -166,7 +166,7 @@ void player_new(void) {
|
|||||||
xmlCleanupParser();
|
xmlCleanupParser();
|
||||||
|
|
||||||
// Money.
|
// Money.
|
||||||
credits = RNG(l, h);
|
player_credits = RNG(l, h);
|
||||||
|
|
||||||
player_newShip(ship);
|
player_newShip(ship);
|
||||||
space_init(system);
|
space_init(system);
|
||||||
@ -233,15 +233,35 @@ static char* player_ratings[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const char* player_rating(void) {
|
const char* player_rating(void) {
|
||||||
if(combat_rating == 0) return player_ratings[0];
|
if(combat_crating == 0) return player_ratings[0];
|
||||||
else if(combat_rating < 50) return player_ratings[1];
|
else if(combat_crating < 50) return player_ratings[1];
|
||||||
else if(combat_rating < 200) return player_ratings[2];
|
else if(combat_crating < 200) return player_ratings[2];
|
||||||
else if(combat_rating < 500) return player_ratings[3];
|
else if(combat_crating < 500) return player_ratings[3];
|
||||||
else if(combat_rating < 1000) return player_ratings[4];
|
else if(combat_crating < 1000) return player_ratings[4];
|
||||||
else if(combat_rating < 2500) return player_ratings[5];
|
else if(combat_crating < 2500) return player_ratings[5];
|
||||||
else if(combat_rating < 10000) return player_ratings[6];
|
else if(combat_crating < 10000) return player_ratings[6];
|
||||||
else return player_ratings[7];
|
else return player_ratings[7];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return how much space the player has remaining.
|
||||||
|
int player_freeSpace(void) {
|
||||||
|
int i, s;
|
||||||
|
s = player->ship->cap_weapon;
|
||||||
|
for(i = 0; i < player->noutfits; i++)
|
||||||
|
s -= player->outfits[i].quantity * player->outfits[i].outfit->mass;
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return amount of outfits the player owns.
|
||||||
|
int player_outfitOwned(const char* outfitname) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < player->noutfits; i++)
|
||||||
|
if(strcmp(outfitname, player->outfits[i].outfit->name)==0)
|
||||||
|
return player->outfits[i].quantity;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the background player stuff, namely planet target
|
// Render the background player stuff, namely planet target
|
||||||
@ -458,7 +478,7 @@ void player_render(void) {
|
|||||||
gl_print(NULL, gui.misc.x + 10, gui.misc.y - 10 - gl_defFont.h,
|
gl_print(NULL, gui.misc.x + 10, gui.misc.y - 10 - gl_defFont.h,
|
||||||
&cConsole, "SCred:");
|
&cConsole, "SCred:");
|
||||||
|
|
||||||
credits2str(str, credits, 2);
|
credits2str(str, player_credits, 2);
|
||||||
|
|
||||||
i = gl_printWidth(&gl_smallFont, "%s", str);
|
i = gl_printWidth(&gl_smallFont, "%s", str);
|
||||||
gl_print(&gl_smallFont, gui.misc.x + gui.misc.w - 10 - i,
|
gl_print(&gl_smallFont, gui.misc.x + gui.misc.w - 10 - i,
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
extern Pilot* pilot;
|
extern Pilot* pilot;
|
||||||
extern char* player_name;
|
extern char* player_name;
|
||||||
extern unsigned int player_flags;
|
extern unsigned int player_flags;
|
||||||
extern unsigned int credits;
|
extern unsigned int player_credits;
|
||||||
extern unsigned int combat_rating;
|
extern unsigned int combat_crating;
|
||||||
|
|
||||||
// Enums.
|
// Enums.
|
||||||
typedef enum RadarShape_ { RADAR_RECT, RADAR_CIRCLE } RadarShape; // For render functions.
|
typedef enum RadarShape_ { RADAR_RECT, RADAR_CIRCLE } RadarShape; // For render functions.
|
||||||
@ -39,6 +39,8 @@ void player_message(const char* fmt, ...);
|
|||||||
void player_clear(void);
|
void player_clear(void);
|
||||||
void player_warp(const double x, const double y);
|
void player_warp(const double x, const double y);
|
||||||
const char* player_rating(void);
|
const char* player_rating(void);
|
||||||
|
int player_freeSpace(void);
|
||||||
|
int player_outfitOwned(const char* outfitname);
|
||||||
|
|
||||||
// Keybind actions.
|
// Keybind actions.
|
||||||
void player_setRadarRel(int mod);
|
void player_setRadarRel(int mod);
|
||||||
|
Loading…
Reference in New Issue
Block a user