[Change] You can no longer buy a star map if you already know the area.

This commit is contained in:
Allanis 2013-08-03 16:31:20 +01:00
parent 82b210e6cc
commit 6ebb90dc23
3 changed files with 52 additions and 0 deletions

View File

@ -15,6 +15,7 @@
#include "ltime.h" #include "ltime.h"
#include "save.h" #include "save.h"
#include "music.h" #include "music.h"
#include "map.h"
#include "land.h" #include "land.h"
/* Global/main window. */ /* Global/main window. */
@ -393,6 +394,11 @@ static int outfit_canBuy(Outfit* outfit, int q, int errmsg) {
} }
return 0; 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; return 1;
} }

View File

@ -790,3 +790,48 @@ int map_map(char* targ_sys, int r) {
return 0; 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;
}

View File

@ -11,4 +11,5 @@ void map_jump(void);
/* Manipulate universe stuff. */ /* Manipulate universe stuff. */
StarSystem** map_getJumpPath(int* njumps, char* sysstart, char* sysend, int ignore_known); StarSystem** map_getJumpPath(int* njumps, char* sysstart, char* sysend, int ignore_known);
int map_map(char* targ_sys, int r); int map_map(char* targ_sys, int r);
int map_isMapped(char* targ_sys, int r);