diff --git a/src/land.c b/src/land.c index cec0ee9..b50987a 100644 --- a/src/land.c +++ b/src/land.c @@ -15,6 +15,7 @@ #include "ltime.h" #include "save.h" #include "music.h" +#include "map.h" #include "land.h" /* Global/main window. */ @@ -393,6 +394,11 @@ static int outfit_canBuy(Outfit* outfit, int q, int errmsg) { } return 0; } + else if(outfit_isMap(outfit) && map_isMapped(NULL, outfit->u.map.radius)) { + if(errmsg != 0) + dialogue_alert("You already own this map."); + return 0; + } return 1; } diff --git a/src/map.c b/src/map.c index 5b03345..6f6f3e7 100644 --- a/src/map.c +++ b/src/map.c @@ -790,3 +790,48 @@ int map_map(char* targ_sys, int r) { return 0; } +/* Check to see if radius is mapped. */ +int map_isMapped(char* targ_sys, int r) { + int i, dep, ret; + StarSystem* sys, *jsys; + SysNode* closed, *open, *cur, *neighbour; + + A_gc = NULL; + open = closed = NULL; + + if(targ_sys == NULL) sys = cur_system; + else sys = system_get(targ_sys); + open = A_newNode(sys, NULL); + open->r = 0; + ret = 1; + + while((cur = A_lowest(open)) != NULL) { + /* Mark system as known and go to next. */ + sys = cur->sys; + dep = cur->r; + if(!sys_isFlag(sys, SYSTEM_KNOWN)) { + ret = 0; + break; + } + open = A_rm(open, sys); + closed = A_add(closed, cur); + + /* Check it's jumps. */ + for(i = 0; i < sys->njumps; i++) { + jsys = &systems_stack[cur->sys->jumps[i]]; + + /* System has already been parsed or is too deep. */ + if((A_in(closed, jsys) != NULL) || (dep+1 > r)) + continue; + + /* Create new node and such. */ + neighbour = A_newNode(jsys, NULL); + neighbour->r = dep+1; + open = A_add(open, neighbour); + } + } + + A_freeList(A_gc); + return ret; +} + diff --git a/src/map.h b/src/map.h index 93983f6..0f470aa 100644 --- a/src/map.h +++ b/src/map.h @@ -11,4 +11,5 @@ void map_jump(void); /* Manipulate universe stuff. */ StarSystem** map_getJumpPath(int* njumps, char* sysstart, char* sysend, int ignore_known); int map_map(char* targ_sys, int r); +int map_isMapped(char* targ_sys, int r);