From 8a1e7133c68bc3709735d951f3adc6ba651131e5 Mon Sep 17 00:00:00 2001 From: Allanis <allanis@saracraft.net> Date: Fri, 22 Mar 2013 20:17:16 +0000 Subject: [PATCH] [Add] player_ships and player_getShip to manipulate player ships. --- README | 2 ++ src/font.c | 3 ++- src/land.c | 7 +++++-- src/player.c | 27 +++++++++++++++++++++++++++ src/ship.c | 4 +++- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/README b/README index b0144b6..bca95f4 100644 --- a/README +++ b/README @@ -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. diff --git a/src/font.c b/src/font.c index ccf0311..a3ec735 100644 --- a/src/font.c +++ b/src/font.c @@ -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)) diff --git a/src/land.c b/src/land.c index 523143a..1a66823 100644 --- a/src/land.c +++ b/src/land.c @@ -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); diff --git a/src/player.c b/src/player.c index 347fbf4..ef81d40 100644 --- a/src/player.c +++ b/src/player.c @@ -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; +} + diff --git a/src/ship.c b/src/ship.c index 4aa1419..6f668cc 100644 --- a/src/ship.c +++ b/src/ship.c @@ -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++)