[Add] Magor: You don't already know all the star system location. Go explore.

This commit is contained in:
Allanis 2013-06-23 19:22:07 +01:00
parent b0d4415cff
commit 10a4791d81
5 changed files with 101 additions and 8 deletions

View File

@ -35,6 +35,8 @@ extern int hyperspace_target;
static void map_close(char* str); static void map_close(char* str);
static void map_update(void); static void map_update(void);
static int map_inPath(StarSystem* sys); 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_render(double bx, double by, double w, double h);
static void map_mouse(SDL_Event* event, double mx, double my); static void map_mouse(SDL_Event* event, double mx, double my);
static void map_buttonZoom(char* str); static void map_buttonZoom(char* str);
@ -148,6 +150,20 @@ static int map_inPath(StarSystem* sys) {
return 0; 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. */ /* 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, n, m; int i, j, n, m;
@ -171,9 +187,18 @@ static void map_render(double bx, double by, double w, double h) {
for(i = 0; i < systems_nstack; i++) { for(i = 0; i < systems_nstack; i++) {
sys = &systems_stack[i]; sys = &systems_stack[i];
/* Draw the system. */ /* Check ot make sure system is known of adjacent to known. */
if(!map_sysReachable(sys)) {
for(j = 0; j < sys->njumps; j++)
if(systems_stack[sys->jumps[j]].known == 1)
break;
if(j == sys->njumps) /* None found. */
continue;
}
/* System Colours. */
if(sys == cur_system) COLOUR(cRadar_targ); if(sys == cur_system) COLOUR(cRadar_targ);
else if(sys->nplanets==0) COLOUR(cInert); /* TODO: dependant on planet type. */ else if((sys->known == 0) || (sys->nplanets==0)) COLOUR(cInert);
else if(areEnemies(player->faction, sys->faction)) COLOUR(cRed); else if(areEnemies(player->faction, sys->faction)) COLOUR(cRed);
else COLOUR(cYellow); else COLOUR(cYellow);
@ -182,11 +207,15 @@ static void map_render(double bx, double by, double w, double h) {
r, bx, by, w, h); r, bx, by, w, h);
/* Draw the system name. */ /* Draw the system name. */
tx = x + 7. + sys->pos.x * map_zoom; if(sys->known != 0) {
ty = y - 5. + sys->pos.y * map_zoom; tx = x + 7. + sys->pos.x * map_zoom;
gl_print(&gl_smallFont, ty = y - 5. + sys->pos.y * map_zoom;
tx + SCREEN_W/2., ty + SCREEN_H/2., gl_print(&gl_smallFont,
&cWhite, sys->name); tx + SCREEN_W/2., ty + SCREEN_H/2.,
&cWhite, sys->name);
}
if(sys->known == 0) continue; /* We dont't draw hyperspace lines. */
/* Draw the hyperspace paths. */ /* Draw the hyperspace paths. */
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
@ -257,6 +286,10 @@ static void map_mouse(SDL_Event* event, double mx, double my) {
for(i = 0; i < systems_nstack; i++) { for(i = 0; i < systems_nstack; i++) {
sys = &systems_stack[i]; sys = &systems_stack[i];
/* Must be reachable. */
if(!map_sysReachable(sys))
continue;
/* Get position. */ /* Get position. */
x = systems_stack[i].pos.x * map_zoom; x = systems_stack[i].pos.x * map_zoom;
y = systems_stack[i].pos.y * map_zoom; y = systems_stack[i].pos.y * map_zoom;

View File

@ -184,6 +184,7 @@ void player_new(void) {
var_cleanup(); var_cleanup();
missions_cleanup(); missions_cleanup();
space_clearKnown();
player_name = dialogue_input("Player Name", 3, 20, player_name = dialogue_input("Player Name", 3, 20,
"Please tell me your name:"); "Please tell me your name:");
@ -558,6 +559,7 @@ void player_render(void) {
Pilot* p; Pilot* p;
glColour* c; glColour* c;
glFont* f; glFont* f;
StarSystem* sys;
/* Pilot is dead or being created, just render her and stop. */ /* Pilot is dead or being created, just render her and stop. */
if(player_isFlag(PLAYER_DESTROYED) || player_isFlag(PLAYER_CREATING) || if(player_isFlag(PLAYER_DESTROYED) || player_isFlag(PLAYER_CREATING) ||
@ -661,6 +663,7 @@ void player_render(void) {
} }
else if(hyperspace_target >= 0) { else if(hyperspace_target >= 0) {
/* Hyperspace target. */ /* Hyperspace target. */
sys = &systems_stack[cur_system->jumps[hyperspace_target]];
c = space_canHyperspace(player) ? &cConsole : NULL; c = space_canHyperspace(player) ? &cConsole : NULL;
gl_printMid(NULL, (int)gui.nav.w, gui.nav.x, gui.nav.y - 5, gl_printMid(NULL, (int)gui.nav.w, gui.nav.x, gui.nav.y - 5,
c, "Hyperspace"); c, "Hyperspace");
@ -668,7 +671,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", pilot_getJumps(player), NULL, "%d - %s", pilot_getJumps(player),
systems_stack[cur_system->jumps[hyperspace_target]].name); (sys->known == 0) ? "Unknown" : sys->name);
} }
else { else {
/* No NAV target. */ /* No NAV target. */

View File

@ -28,6 +28,8 @@ extern int pfaction_save(xmlTextWriterPtr writer); /* Faction data. */
extern int pfaction_load(xmlNodePtr parent); extern int pfaction_load(xmlNodePtr parent);
extern int hook_save(xmlTextWriterPtr writer); /* Hooks. */ extern int hook_save(xmlTextWriterPtr writer); /* Hooks. */
extern int hook_load(xmlNodePtr parent); extern int hook_load(xmlNodePtr parent);
extern int space_sysSave(xmlTextWriterPtr writer); /* Space stuff. */
extern int space_sysLoad(xmlNodePtr parent);
extern void menu_main_close(void); extern void menu_main_close(void);
/* Static. */ /* Static. */
static int save_data(xmlTextWriterPtr writer); static int save_data(xmlTextWriterPtr writer);
@ -44,6 +46,7 @@ static int save_data(xmlTextWriterPtr writer) {
if(var_save(writer) < 0) return -1; if(var_save(writer) < 0) return -1;
if(pfaction_save(writer) < 0) return -1; if(pfaction_save(writer) < 0) return -1;
if(hook_save(writer) < 0) return -1; if(hook_save(writer) < 0) return -1;
if(space_sysSave(writer) < 0) return -1;
return 0; return 0;
} }
@ -207,6 +210,7 @@ static int load_game(char* file) {
missions_loadActive(node); missions_loadActive(node);
pfaction_load(node); pfaction_load(node);
hook_load(node); hook_load(node);
space_sysLoad(node);
xmlFreeDoc(doc); xmlFreeDoc(doc);

View File

@ -80,6 +80,8 @@ static PlanetClass planetclass_get(const char a);
extern void player_message(const char* fmt, ...); extern void player_message(const char* fmt, ...);
void planets_minimap(const double res, const double w, void planets_minimap(const double res, const double w,
const double h, const RadarShape shape); const double h, const RadarShape shape);
int space_sysSave(xmlTextWriterPtr writer);
int space_sysLoad(xmlNodePtr parent);
/* Draw the planet. Used in planet.c */ /* Draw the planet. Used in planet.c */
/* Matrix mode is already displaced to center of the minimap. */ /* Matrix mode is already displaced to center of the minimap. */
@ -615,6 +617,9 @@ void space_init(const char* sysname) {
/* Start the spawn timer. */ /* Start the spawn timer. */
spawn_timer = SDL_GetTicks() + 120000./(float)(cur_system->nfleets+1); spawn_timer = SDL_GetTicks() + 120000./(float)(cur_system->nfleets+1);
/* We know this system. */
cur_system->known = 1;
} }
/* Load the planets of name 'name'. */ /* Load the planets of name 'name'. */
@ -1111,3 +1116,48 @@ void space_exit(void) {
nstars = 0; nstars = 0;
} }
void space_clearKnown(void) {
int i;
for(i = 0; i < systems_nstack; i++)
systems_stack[i].known = 0;
}
/* Save what is needed to be saved for space. */
int space_sysSave(xmlTextWriterPtr writer) {
int i;
xmlw_startElem(writer, "space");
for(i = 0; i < systems_nstack; i++) {
if(systems_stack[i].known == 0) continue; /* Not Known */
xmlw_elem(writer, "known", "%s", systems_stack[i].name);
}
xmlw_endElem(writer); /* Space. */
return 0;
}
/* Load space. */
int space_sysLoad(xmlNodePtr parent) {
xmlNodePtr node, cur;
StarSystem* sys;
space_clearKnown();
node = parent->xmlChildrenNode;
do {
if(xml_isNode(node, "space")) {
cur = node->xmlChildrenNode;
do {
if(xml_isNode(cur, "known")) {
sys = system_get(xml_get(cur));
sys->known = 1;
}
} while(xml_nextNode(cur));
}
} while(xml_nextNode(node));
return 0;
}

View File

@ -92,6 +92,8 @@ typedef struct StarSystem_ {
int* jumps; /* Adjacent star system index number. */ int* jumps; /* Adjacent star system index number. */
int njumps; /* Number of adjacent jumps. */ int njumps; /* Number of adjacent jumps. */
int known; /* Known by player? */
} StarSystem; } StarSystem;
extern StarSystem* cur_system; /* Current star system. */ extern StarSystem* cur_system; /* Current star system. */
@ -118,5 +120,6 @@ int space_canHyperspace(Pilot* p);
int space_hyperspace(Pilot* p); int space_hyperspace(Pilot* p);
char** space_getFactionPlanet(int* nplanets, int* factions, int nfactions); char** space_getFactionPlanet(int* nplanets, int* factions, int nfactions);
char* space_getRndPlanet(void); char* space_getRndPlanet(void);
void space_clearKnown(void);
extern char* stardate; extern char* stardate;