[Change] Some code cleanup and made map a little more sane when selecting paths.
This commit is contained in:
parent
91aa3268c0
commit
f91505b950
24
src/map.c
24
src/map.c
@ -136,16 +136,21 @@ static void map_update(void) {
|
|||||||
|
|
||||||
// Return 1 if sys is part of the map_path.
|
// Return 1 if sys is part of the map_path.
|
||||||
static int map_inPath(StarSystem* sys) {
|
static int map_inPath(StarSystem* sys) {
|
||||||
int i;
|
int i, f;
|
||||||
|
|
||||||
|
f = pilot_getJumps(player) - 1;
|
||||||
for(i = 0; i < map_npath; i++)
|
for(i = 0; i < map_npath; i++)
|
||||||
if(map_path[i] == sys)
|
if(map_path[i] == sys) {
|
||||||
return 1;
|
if(i > f) {
|
||||||
|
return 2;
|
||||||
|
} else return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the map as a custom widget.
|
// Render the map as a custom widget.
|
||||||
static void map_render(double bx, double by, double w, double h) {
|
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;
|
double x, y, r, tx, ty;
|
||||||
StarSystem* sys;
|
StarSystem* sys;
|
||||||
glColour* col;
|
glColour* col;
|
||||||
@ -188,15 +193,20 @@ static void map_render(double bx, double by, double w, double h) {
|
|||||||
// Cheaply use transparency instead of actually
|
// Cheaply use transparency instead of actually
|
||||||
// calculating from x to y the line must go. :)
|
// calculating from x to y the line must go. :)
|
||||||
for(j = 0; j < sys->njumps; j++) {
|
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?
|
// Set the colours, is the route the current one?
|
||||||
if((hyperspace_target != -1) &&
|
if((hyperspace_target != -1) &&
|
||||||
(((cur_system == sys) && (j == hyperspace_target)) ||
|
(((cur_system == sys) && (j == hyperspace_target)) ||
|
||||||
((cur_system == &systems_stack[sys->jumps[j]]) &&
|
((cur_system == &systems_stack[sys->jumps[j]]) &&
|
||||||
(sys == &systems_stack[cur_system->jumps[hyperspace_target]]))))
|
(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;
|
col = &cGreen;
|
||||||
|
else if((n > 0) && (m > 0)) {
|
||||||
|
if((n == 2) || (m == 2)) // Out of fuel.
|
||||||
|
col = &cRed;
|
||||||
|
else
|
||||||
|
col = &cYellow;
|
||||||
|
}
|
||||||
else col = &cDarkBlue;
|
else col = &cDarkBlue;
|
||||||
glBegin(GL_LINE_STRIP);
|
glBegin(GL_LINE_STRIP);
|
||||||
ACOLOUR(*col, 0.);
|
ACOLOUR(*col, 0.);
|
||||||
|
@ -195,7 +195,7 @@ void menu_info(void) {
|
|||||||
"%s\n"
|
"%s\n"
|
||||||
"%d %d jumps)",
|
"%d %d jumps)",
|
||||||
player_name, lt, player_rating(), player->name,
|
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,
|
window_addText(wid, 80, 20,
|
||||||
INFO_WIDTH-120-BUTTON_WIDTH, INFO_HEIGHT-60,
|
INFO_WIDTH-120-BUTTON_WIDTH, INFO_HEIGHT-60,
|
||||||
|
@ -155,6 +155,11 @@ double pilot_face(Pilot* p, const float dir) {
|
|||||||
return diff;
|
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.
|
// Return quantity of a pilot outfit.
|
||||||
static int pilot_oquantity(Pilot* p, PilotOutfit* w) {
|
static int pilot_oquantity(Pilot* p, PilotOutfit* w) {
|
||||||
return (outfit_isAmmo(w->outfit) && p->secondary) ?
|
return (outfit_isAmmo(w->outfit) && p->secondary) ?
|
||||||
|
@ -139,6 +139,7 @@ unsigned int pilot_getNext(const unsigned int id);
|
|||||||
unsigned int pilot_getNearest(const Pilot* p);
|
unsigned int pilot_getNearest(const Pilot* p);
|
||||||
unsigned int pilot_getHostile(void); // Only for the player.
|
unsigned int pilot_getHostile(void); // Only for the player.
|
||||||
Fleet* fleet_get(const char* name);
|
Fleet* fleet_get(const char* name);
|
||||||
|
int pilot_getJumps(const Pilot* p);
|
||||||
|
|
||||||
// MISC.
|
// MISC.
|
||||||
void pilot_shoot(Pilot* p, const unsigned int target, const int secondary);
|
void pilot_shoot(Pilot* p, const unsigned int target, const int secondary);
|
||||||
|
@ -593,7 +593,7 @@ void player_render(void) {
|
|||||||
|
|
||||||
gl_printMid(&gl_smallFont, (int)gui.nav.w, gui.nav.x,
|
gl_printMid(&gl_smallFont, (int)gui.nav.w, gui.nav.x,
|
||||||
gui.nav.y - 10 - gl_smallFont.h,
|
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);
|
systems_stack[cur_system->jumps[hyperspace_target]].name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
Reference in New Issue
Block a user