From f91505b950cbce9dda498ebbdc9e99282b0fdace Mon Sep 17 00:00:00 2001 From: Allanis Date: Sat, 1 Jun 2013 18:07:45 +0100 Subject: [PATCH] [Change] Some code cleanup and made map a little more sane when selecting paths. --- src/map.c | 24 +++++++++++++++++------- src/menu.c | 2 +- src/pilot.c | 5 +++++ src/pilot.h | 1 + src/player.c | 2 +- 5 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/map.c b/src/map.c index b7ebae5..3941e90 100644 --- a/src/map.c +++ b/src/map.c @@ -136,16 +136,21 @@ static void map_update(void) { // Return 1 if sys is part of the map_path. static int map_inPath(StarSystem* sys) { - int i; + int i, f; + + f = pilot_getJumps(player) - 1; for(i = 0; i < map_npath; i++) - if(map_path[i] == sys) - return 1; + if(map_path[i] == sys) { + if(i > f) { + return 2; + } else return 1; + } return 0; } // Render the map as a custom widget. static void map_render(double bx, double by, double w, double h) { - int i, j; + int i, j, n, m; double x, y, r, tx, ty; StarSystem* sys; glColour* col; @@ -188,15 +193,20 @@ static void map_render(double bx, double by, double w, double h) { // Cheaply use transparency instead of actually // calculating from x to y the line must go. :) for(j = 0; j < sys->njumps; j++) { + n = map_inPath(&systems_stack[sys->jumps[j]]); + m = map_inPath(sys); // Set the colours, is the route the current one? if((hyperspace_target != -1) && (((cur_system == sys) && (j == hyperspace_target)) || ((cur_system == &systems_stack[sys->jumps[j]]) && (sys == &systems_stack[cur_system->jumps[hyperspace_target]])))) - col = &cRed; - // Is the route part of the path? - else if(map_inPath(&systems_stack[sys->jumps[j]]) && map_inPath(sys)) col = &cGreen; + else if((n > 0) && (m > 0)) { + if((n == 2) || (m == 2)) // Out of fuel. + col = &cRed; + else + col = &cYellow; + } else col = &cDarkBlue; glBegin(GL_LINE_STRIP); ACOLOUR(*col, 0.); diff --git a/src/menu.c b/src/menu.c index 561fb61..f3b5b74 100644 --- a/src/menu.c +++ b/src/menu.c @@ -195,7 +195,7 @@ void menu_info(void) { "%s\n" "%d %d jumps)", player_name, lt, player_rating(), player->name, - (int)player->fuel, (int)(player->fuel) / HYPERSPACE_FUEL); + (int)player->fuel, pilot_getJumps(player)); window_addText(wid, 80, 20, INFO_WIDTH-120-BUTTON_WIDTH, INFO_HEIGHT-60, diff --git a/src/pilot.c b/src/pilot.c index 83d4dec..b8b638e 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -155,6 +155,11 @@ double pilot_face(Pilot* p, const float dir) { return diff; } +// Get the amount of jumps the pilot has left. +int pilot_getJumps(const Pilot* p) { + return (int)(p->fuel) / HYPERSPACE_FUEL; +} + // Return quantity of a pilot outfit. static int pilot_oquantity(Pilot* p, PilotOutfit* w) { return (outfit_isAmmo(w->outfit) && p->secondary) ? diff --git a/src/pilot.h b/src/pilot.h index 6402422..e71952e 100644 --- a/src/pilot.h +++ b/src/pilot.h @@ -139,6 +139,7 @@ unsigned int pilot_getNext(const unsigned int id); unsigned int pilot_getNearest(const Pilot* p); unsigned int pilot_getHostile(void); // Only for the player. Fleet* fleet_get(const char* name); +int pilot_getJumps(const Pilot* p); // MISC. void pilot_shoot(Pilot* p, const unsigned int target, const int secondary); diff --git a/src/player.c b/src/player.c index 8cb445e..a04fe57 100644 --- a/src/player.c +++ b/src/player.c @@ -593,7 +593,7 @@ void player_render(void) { gl_printMid(&gl_smallFont, (int)gui.nav.w, gui.nav.x, gui.nav.y - 10 - gl_smallFont.h, - NULL, "%d - %s", (int)(player->fuel) / HYPERSPACE_FUEL, + NULL, "%d - %s", pilot_getJumps(player), systems_stack[cur_system->jumps[hyperspace_target]].name); } else {