[Add] player_getLoc and don't allow player to repeat ship names.

This commit is contained in:
Allanis 2013-03-22 21:04:25 +00:00
parent 8da2cb1299
commit 269de8dcfe
3 changed files with 56 additions and 23 deletions

View File

@ -194,10 +194,14 @@ static void outfits(void) {
int noutfits;
char buf[128];
// Create window.
snprintf(buf, 128, "%s - Outfits", land_planet->name);
secondary_wid = window_create(buf, -1, -1,
OUTFITS_WIDTH, OUTFITS_HEIGHT);
// Will allow buying from keyboard.
window_setFptr(secondary_wid, outfits_buy);
// Buttons.
window_addButton(secondary_wid, -20, 20,
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseOutfits",
"Close", outfits_close);
@ -447,8 +451,8 @@ static void shipyard_update(char* str) {
shipname = toolkit_getList(secondary_wid, "lstShipyard");
ship = ship_get(shipname);
window_modifyText(secondary_wid, "txtDescription", ship->description);
window_modifyImage(secondary_wid, "imgTarget", ship->gfx_target);
window_modifyText(secondary_wid, "txtDescription", ship->description);
credits2str(buf2, ship->price, 2);
credits2str(buf3, player_credits, 2);
@ -516,11 +520,6 @@ static void shipyard_yoursClose(char* str) {
static void spaceport_bar(void) {
secondary_wid = window_create("SpacePort Bar", -1, -1, BAR_WIDTH, BAR_HEIGHT);
window_addText(secondary_wid, 20, -30,
BAR_WIDTH-40, BAR_HEIGHT - 40 - BUTTON_HEIGHT, 0,
"txtDescription", &gl_smallFont, &cBlack,
land_planet->bar_description);
window_addButton(secondary_wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
"btnCloseBar", "Close", spaceport_bar_close);
@ -528,7 +527,12 @@ static void spaceport_bar(void) {
BUTTON_WIDTH, BUTTON_HEIGHT, "btnNews",
"News", (void(*)(char*))news);
window_addText(secondary_wid, 20, -30,
BAR_WIDTH-40, BAR_HEIGHT - 40 - BUTTON_HEIGHT, 0,
"txtDescription", &gl_smallFont, &cBlack,
land_planet->bar_description);
}
static void spaceport_bar_close(char* str) {
if(strcmp(str, "btnCloseBar")==0)
window_destroy(secondary_wid);
@ -539,14 +543,14 @@ static void news(void) {
terciary_wid = window_create("News Reports",
-1, -1, NEWS_WIDTH, NEWS_HEIGHT);
window_addButton(terciary_wid, -20, 20,
BUTTON_WIDTH, BUTTON_HEIGHT,
"btnCloseNews", "Close", news_close);
window_addText(terciary_wid, 20, 20 + BUTTON_HEIGHT + 20,
NEWS_WIDTH-40, NEWS_HEIGHT - 20 - BUTTON_HEIGHT - 20 - 20 -20,
0, "txtNews", &gl_smallFont, &cBlack,
"News reporters report that they are on strike right now! D:");
window_addButton(terciary_wid, -20, 20,
BUTTON_WIDTH, BUTTON_HEIGHT,
"btnCloseNews", "Close", news_close);
}
static void news_close(char* str) {

View File

@ -810,7 +810,8 @@ void pilot_destroy(Pilot* p) {
// Free the prisoned pilot!
void pilots_free(void) {
int i;
for(i = 0; i < pilots; i++)
if(player) pilot_free(player);
for(i = 1; i < pilots; i++)
pilot_free(pilot_stack[i]);
free(pilot_stack);
pilot_stack = NULL;

View File

@ -139,6 +139,7 @@ void player_dead(void);
void player_destroyed(void);
char** player_ships(int* nships);
Pilot* player_getShip(char* shipname);
char* player_getLoc(char* shipname);
// Prompt player name.
void player_new(void) {
@ -277,6 +278,7 @@ void player_newShip(Ship* ship, double px, double py,
static void player_nameShipClose(char* str) {
(void)str;
int i;
char* ship_name;
unsigned int wid;
@ -288,6 +290,19 @@ static void player_nameShipClose(char* str) {
return;
}
// Do not repeat the same ship name.
if(player && (strcmp(ship_name, player->name)==0)) {
toolkit_alert("You cannot name two ships the same!");
return;
}
for(i = 0; i < player_nstack; i++) {
if(strcmp(player_stack[i]->name, ship_name)==0) {
toolkit_alert("You cannot name two ships the same");
return;
}
}
player_newShipMake(ship_name);
window_destroy(wid);
@ -391,14 +406,8 @@ const char* player_rating(void) {
else return player_ratings[7];
}
// Return how much weapon. 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;
// TODO: Get rid of it.
}
// Return amount of outfits the player owns.
@ -1325,15 +1334,22 @@ void player_destroyed(void) {
player_timer = SDL_GetTicks() + 5000;
}
// Return a buffer with all the ships names.
// Return a buffer with all the ships names, or none if there
// aren't any.
char** player_ships(int* nships) {
int i;
char** shipnames;
(*nships) = player_nstack;
shipnames = malloc(sizeof(char*) * player_nstack);
for(i = 0; i < player_nstack; i++)
shipnames[i] = strdup(player_stack[i]->name);
if(player_nstack==0) {
(*nships) = 1;
shipnames = malloc(sizeof(char*));
shipnames[0] = strdup("None");
} else {
(*nships) = player_nstack;
shipnames = malloc(sizeof(char*) * player_nstack);
for(i = 0; i < player_nstack; i++)
shipnames[i] = strdup(player_stack[i]->name);
}
return shipnames;
}
@ -1350,3 +1366,15 @@ Pilot* player_getShip(char* shipname) {
return NULL;
}
// Return location of a specific ship.
char* player_getLoc(char* shipname) {
int i;
for(i = 0; i < player_nstack; i++)
if(strcmp(player_stack[i]->name, shipname)==0)
return player_lstack[i];
WARN("Player ship '%s' not found in stack", shipname);
return NULL;
}