[Change] Some code cleanup and made map a little more sane when selecting paths.

This commit is contained in:
Allanis 2013-06-01 18:07:45 +01:00
parent 91aa3268c0
commit f91505b950
5 changed files with 25 additions and 9 deletions

View File

@ -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.);

View File

@ -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,

View File

@ -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) ?

View File

@ -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);

View File

@ -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 {