diff --git a/src/map.c b/src/map.c index 406ff2e..f08dd3a 100644 --- a/src/map.c +++ b/src/map.c @@ -35,8 +35,6 @@ extern int hyperspace_target; static void map_close(char* str); static void map_update(void); static int map_inPath(StarSystem* sys); -static int map_sysReachable(StarSystem* sys); -static int map_sysReachable(StarSystem* sys); static void map_render(double bx, double by, double w, double h); static void map_mouse(SDL_Event* event, double mx, double my); static void map_buttonZoom(char* str); @@ -150,20 +148,6 @@ static int map_inPath(StarSystem* sys) { return 0; } -/* Return 1 if player can reach the system. */ -static int map_sysReachable(StarSystem* sys) { - int i; - - if(sys->known != 0) return 1; /* It is known. */ - - /* Check to see if it is adjacent to known. */ - for(i = 0; i < sys->njumps; i++) - if(systems_stack[sys->jumps[i]].known == 1) - 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, n, m; @@ -188,7 +172,7 @@ static void map_render(double bx, double by, double w, double h) { sys = &systems_stack[i]; /* Check ot make sure system is known of adjacent to known. */ - if(!map_sysReachable(sys)) { + if(!space_sysReachable(sys)) { for(j = 0; j < sys->njumps; j++) if(systems_stack[sys->jumps[j]].known == 1) break; @@ -287,7 +271,7 @@ static void map_mouse(SDL_Event* event, double mx, double my) { sys = &systems_stack[i]; /* Must be reachable. */ - if(!map_sysReachable(sys)) + if(!space_sysReachable(sys)) continue; /* Get position. */ diff --git a/src/space.c b/src/space.c index 6925e4b..bbc9aeb 100644 --- a/src/space.c +++ b/src/space.c @@ -305,6 +305,19 @@ StarSystem** system_getJumpPath(int* njumps, char* sysstart, char* sysend) { ssys = system_get(sysstart); /* Start. */ esys = system_get(sysend); /* End. */ + /* System target must be known. */ + if(esys->known == 0) { + if(space_sysReachable(esys)) { /* Can we still reach it? */ + res = malloc(sizeof(StarSystem*)); + (*njumps) = 1; + res[0] = esys; + return res; + } + /* Can't reach - Don't make path. */ + (*njumps) = 0; + return NULL; + } + /* Start the linked lists. */ open = closed = NULL; cur = A_newNode(ssys, NULL); @@ -318,6 +331,9 @@ StarSystem** system_getJumpPath(int* njumps, char* sysstart, char* sysend) { for(i = 0; i < cur->sys->njumps; i++) { sys = &systems_stack[cur->sys->jumps[i]]; + + if(sys->known == 0) continue; + neighbour = A_newNode(sys, NULL); ocost = A_in(open, sys); @@ -474,6 +490,19 @@ char* space_getRndPlanet(void) { return res; } +/* Return 1 if player can reach the system. */ +int space_sysReachable(StarSystem* sys) { + int i; + + if(sys->known != 0) return 1; /* It is known. */ + + /* Check to see if it is adjacent to known. */ + for(i = 0; i < sys->njumps; i++) + if(systems_stack[sys->jumps[i]].known == 1) + return 1; + return 0; +} + /* Get the system from it's name. */ static StarSystem* system_get(const char* sysname) { int i; diff --git a/src/space.h b/src/space.h index 89ab809..bb2cd34 100644 --- a/src/space.h +++ b/src/space.h @@ -118,6 +118,7 @@ void space_update(const double dt); StarSystem** system_getJumpPath(int* njumps, char* sysstart, char* sysend); int space_canHyperspace(Pilot* p); int space_hyperspace(Pilot* p); +int space_sysReachable(StarSystem* sys); char** space_getFactionPlanet(int* nplanets, int* factions, int nfactions); char* space_getRndPlanet(void); void space_clearKnown(void);