[Add] player_ships and player_getShip to manipulate player ships.

This commit is contained in:
Allanis 2013-03-22 20:17:16 +00:00
parent fb5cc3cf18
commit 8a1e7133c6
5 changed files with 39 additions and 4 deletions

2
README
View File

@ -89,6 +89,7 @@ Keys:
Movement:
-- w : Accelerate.
-- Double tap for afterburners.
-- a : Left.
-- d : Right.
-- s : Turn 180 degree, so you can stop easily.
@ -107,6 +108,7 @@ Keys:
-- 'l' : Attempts to land or targets nearest planet.
-- 'h' : Cycles through hyperspace jump points.
-- 'j' : Jump through hyperspace.
-- 'm' : StarMap
GUI:
-- '0' : Zoom in.

View File

@ -288,7 +288,8 @@ static void glFontMakeDList(FT_Face face, char ch, GLuint list_base,
int i, j;
double x, y;
if(FT_Load_Glyph(face, FT_Get_Char_Index(face, ch), FT_LOAD_FORCE_AUTOHINT))
if(FT_Load_Glyph(face, FT_Get_Char_Index(face, ch),
FT_LOAD_FORCE_AUTOHINT))
WARN("FT_Load_Glyph failed");
if(FT_Get_Glyph(face->glyph, &glyph))

View File

@ -44,6 +44,10 @@ static int secondary_wid = 0;
static int terciary_wid = 0; // For fancy things like news, your ship etc..
Planet* land_planet = NULL;
// Extern.
extern char** player_ships(int* nships);
extern Pilot* player_getShip(char* shipname);
// Static.
// Commodity excahnge.
static void commodity_exchange(void);
static void commodity_exchange_close(char* str);
@ -497,8 +501,7 @@ static void shipyard_yours(char* str) {
BUTTON_WIDTH, BUTTON_HEIGHT, "btnCloseYourShips",
"Shipyard", shipyard_yoursClose);
ships = NULL;
nships = 0;
ships = player_ships(&nships);
window_addList(terciary_wid, 20, 40,
200, SHIPYARD_HEIGHT-80, "lstYourShips",
ships, nships, 0, NULL);

View File

@ -137,6 +137,8 @@ static void gui_renderBar(const glColour* c, const Rect* r, const double w);
// Externed.
void player_dead(void);
void player_destroyed(void);
char** player_ships(int* nships);
Pilot* player_getShip(char* shipname);
// Prompt player name.
void player_new(void) {
@ -1319,3 +1321,28 @@ void player_destroyed(void) {
player_timer = SDL_GetTicks() + 5000;
}
// Return a buffer with all the ships names.
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);
return shipnames;
}
// Return a specific ship.
Pilot* player_getShip(char* shipname) {
int i;
for(i = 0; i < player_nstack; i++)
if(strcmp(player_stack[i]->name, shipname)==0)
return player_stack[i];
WARN("Player ship '%s' not found in stack", shipname);
return NULL;
}

View File

@ -53,7 +53,9 @@ static char* ship_classes[] = {
// Return all the ships in text form.
char** ship_getTech(int* n, const int* tech, const int techmax) {
int i, j;
char** shipnames = malloc(sizeof(Ship*) * ships);
char** shipnames;
shipnames = malloc(sizeof(Ship*) * ships);
*n = 0;
for(i = 0; i < ships; i++)