24#include "map_system.h"
37#define BUTTON_WIDTH 100
38#define BUTTON_HEIGHT 30
39#define MAP_LOOP_PROT 1000
40#define MAP_TEXT_INDENT 45
41#define MAP_MARKER_CYCLE 750
42#define MAP_MOVE_THRESHOLD 20.
43#define EASE_ALPHA ease_QuadraticInOut
45static const int RCOL_X = -10;
46static const int RCOL_TEXT_W = 135;
47static const int RCOL_HEADER_W = 140;
50static const int RCOL_W = 140 - (-10*2);
51static const int BBAR_H = 60;
56typedef struct FactionPresence_ {
65typedef struct CstMapWidget_ {
87static int map_selected = -1;
88static MapMode map_mode = MAPMODE_TRAVEL;
89static StarSystem **map_path = NULL;
90static int cur_commod = -1;
91static int cur_commod_mode = 0;
93static char** map_modes = NULL;
94static int listMapModeVisible = 0;
95static double commod_av_gal_price = 0;
96static double map_dt = 0.;
97static int map_minimal_mode = 0;
98static double map_flyto_speed = 1500.;
99static double map_mx = 0.;
100static double map_my = 0.;
101static char map_show_notes = 0;
117static void map_update_autonav(
unsigned int wid );
118static void map_update_status(
unsigned int wid,
const char *buf );
119static void map_update(
unsigned int wid );
121static void map_render(
double bx,
double by,
double w,
double h,
void *data );
122static void map_renderPath(
double x,
double y,
double zoom,
double radius,
double alpha );
123static void map_renderMarkers(
double x,
double y,
double zoom,
double r,
double a );
124static void map_renderCommod(
double bx,
double by,
double x,
double y,
125 double zoom,
double w,
double h,
double r,
int editor,
double a );
126static void map_renderCommodIgnorance(
double x,
double y,
double zoom,
127 const StarSystem *sys,
const Commodity *
c,
double a );
128static void map_drawMarker(
double x,
double y,
double zoom,
129 double r,
double a,
int num,
int cur,
int type );
131static void map_focusLose(
unsigned int wid,
const char* wgtname );
132static int map_mouse(
unsigned int wid, SDL_Event* event,
double mx,
double my,
133 double w,
double h,
double rx,
double ry,
void *data );
135static void map_setup (
void);
136static void map_updateInternal(
CstMapWidget *cst,
double dt );
137static void map_reset(
CstMapWidget* cst, MapMode mode );
138static CstMapWidget* map_globalCustomData(
unsigned int wid );
139static int map_keyHandler(
unsigned int wid, SDL_Keycode key, SDL_Keymod mod );
140static void map_buttonZoom(
unsigned int wid,
const char* str );
141static void map_setMinimal(
unsigned int wid,
int value );
142static void map_buttonMarkSystem(
unsigned int wid,
const char* str );
143static void map_buttonSystemMap(
unsigned int wid,
const char* str );
144static void map_buttonMinimal(
unsigned int wid,
const char* str );
145static void map_buttonCommodity(
unsigned int wid,
const char* str );
146static void map_selectCur (
void);
147static void map_genModeList(
void);
148static void map_update_commod_av_price();
149static void map_onClose(
unsigned int wid,
const char *str );
166 if (decorator_stack != NULL) {
167 for (
int i=0; i<
array_size(decorator_stack); i++)
170 decorator_stack = NULL;
177static int map_keyHandler(
unsigned int wid, SDL_Keycode key, SDL_Keymod mod )
181 if ((key == SDLK_SLASH) || (key == SDLK_f)) {
182 map_inputFind( wid, NULL );
189static void map_setup (
void)
194 sys_rmFlag( sys, SYSTEM_DISCOVERED | SYSTEM_INTEREST );
197 sys_rmFlag( sys, SYSTEM_HAS_LANDABLE );
198 for (
int j=0; j<
array_size(sys->spobs); j++) {
199 Spob *p = sys->spobs[j];
200 if (!spob_isKnown(p))
202 if (!spob_hasService(p, SPOB_SERVICE_LAND))
204 sys_setFlag( sys, SYSTEM_HAS_KNOWN_LANDABLE );
207 sys_setFlag( sys, SYSTEM_HAS_LANDABLE );
211 for (
int j=0; j<
array_size(sys->jumps); j++) {
212 JumpPoint *jp = &sys->jumps[j];
213 if (jp_isFlag(jp, JP_EXITONLY) || jp_isFlag(jp, JP_HIDDEN))
215 if (!jp_isFlag(jp, JP_KNOWN)) {
222 for (
int j=0; j<
array_size(sys->spobs); j++) {
223 Spob *p = sys->spobs[j];
224 if (!spob_isKnown(p)) {
232 sys_setFlag( sys, SYSTEM_DISCOVERED );
249 const char *title = _(
"Star Map");
250 const glColour cBG = { 0., 0., 0., 0.95 };
253 listMapModeVisible = 0;
256 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ))
271 if (map_selected == -1)
288 map_show( wid, 0, 0, w, h, 1., RCOL_W/2., BBAR_H/2. );
295 window_addRect( wid, (w-tw)/2., h-th, tw, th,
"rctTBar", &cBG, 0 );
301 window_addRect( wid, w-RCOL_W, 0, RCOL_W, h,
"rctRCol", &cBG, 0 );
302 window_addRect( wid, 0, 0, w, BBAR_H,
"rctBBar", &cBG, 0 );
331 window_addText( wid, -90 + 80, y, 160, 20, 1,
"txtSysname",
336 window_addImage( wid, -90 + 32, y - 32, 0, 0,
"imgFaction", NULL, 0 );
340 window_addText( wid, x, y, RCOL_HEADER_W, 20, 0,
"txtSFaction",
342 window_addText( wid, x, y-
gl_smallFont.
h-5, rw, 300, 0,
"txtFaction",
347 window_addText( wid, x, y, RCOL_HEADER_W, 20, 0,
"txtSStanding",
349 window_addText( wid, x, y-
gl_smallFont.
h-5, rw, 300, 0,
"txtStanding",
354 window_addText( wid, x, y, RCOL_HEADER_W, 20, 0,
"txtSPresence",
356 window_addText( wid, x, y-
gl_smallFont.
h-5, rw, 300, 0,
"txtPresence",
361 window_addText( wid, x, y, RCOL_HEADER_W, 20, 0,
"txtSSpobs",
363 window_addText( wid, x, y-
gl_smallFont.
h-5, rw, 300, 0,
"txtSpobs",
368 window_addText( wid, x, y, RCOL_HEADER_W, 20, 0,
"txtSServices",
370 window_addText( wid, x, y-
gl_smallFont.
h-5, rw, 300, 0,
"txtServices",
381 "btnFind", _(
"Find"), map_inputFind, SDLK_f );
387 "btnMinimal", NULL, map_buttonMinimal, SDLK_v );
388 map_setMinimal( wid, map_minimal_mode );
391 "btnSystem", _(
"System Info"), map_buttonSystemMap, SDLK_s );
394 "btnMarkSystem", _(
"Toggle Note"), map_buttonMarkSystem, SDLK_n );
405 window_addText( wid, 20, 15, w - 40 - 7*(
BUTTON_WIDTH+20), 30, 0,
413 cst = map_globalCustomData(wid);
414 map_reset( cst, map_mode );
422 window_disableButton( wid,
"btnAutonav" );
428static void map_update_commod_av_price (
void)
432 if (cur_commod == -1 || map_selected == -1) {
433 commod_av_gal_price = 0;
437 c = commod_known[cur_commod];
438 if (cur_commod_mode == 0) {
445 if ((!sys_isKnown(sys) && !sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)
452 for (
int j=0 ; j<
array_size(sys->spobs); j++) {
453 Spob *p = sys->spobs[j];
454 for (
int k=0; k<
array_size(p->commodities); k++) {
455 if (p->commodities[k] ==
c) {
456 if (p->commodityPrice[k].cnt > 0) {
457 thisPrice = p->commodityPrice[k].sum / p->commodityPrice[k].cnt;
458 sumPrice += thisPrice;
466 totPrice += sumPrice / sumCnt;
472 totPrice /= totPriceCnt;
473 commod_av_gal_price = totPrice;
477 commod_av_gal_price = 0;
480static void map_update_autonav(
unsigned int wid )
487 int rw = RCOL_HEADER_W;
488 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"#n%s#0", _(
"Fuel: ") );
489 p +=
scnprintf(&buf[p],
sizeof(buf)-p, n_(
"%d jump",
"%d jumps", jumps), jumps );
490 sys = map_getDestination( &autonav );
491 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"\n#n%s#0", _(
"Autonav: ") );
493 p +=
scnprintf(&buf[p],
sizeof(buf)-p, _(
"Off") );
496 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"#r" );
497 p +=
scnprintf(&buf[p],
sizeof(buf)-p, n_(
"%d jump",
"%d jumps", autonav), autonav );
499 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"#0" );
504 window_modifyText( wid,
"txtPlayerStatus", buf );
507static void map_update_status(
unsigned int wid,
const char *buf )
510 window_modifyText( wid,
"txtSystemStatus", buf );
524static void map_update(
unsigned int wid )
528 int f, fh, h, x, y, logow, logoh;
529 unsigned int services, services_u, services_h, services_f, services_r;
543 map_globalCustomData(wid)->
mode = map_mode;
549 if (!(sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) &&
555 map_update_commod_av_price();
558 if (map_mode == MAPMODE_TRADE) {
560 if (cur_commod_mode == 1) {
561 snprintf( buf,
sizeof(buf),
562 _(
"Showing %s prices relative to %s:\n"
563 "Positive/blue indicate profit while negative/orange values indicate loss when sold at the corresponding system."),
564 _(
c->name), _(sys->name) );
565 map_update_status( wid, buf );
568 snprintf(buf,
sizeof(buf), _(
"Showing known %s prices.\nGalaxy-wide average: %.2f"), _(
c->name), commod_av_gal_price);
569 map_update_status( wid, buf );
573 map_update_status( wid, NULL );
582 if (!sys_isKnown(sys)) {
586 if (sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED))
587 window_modifyText( wid,
"txtSysname", _(sys->name) );
589 window_modifyText( wid,
"txtSysname", _(
"Unknown") );
592 window_modifyImage( wid,
"imgFaction", NULL, 0, 0 );
595 window_modifyText( wid,
"txtFaction", _(
"Unknown") );
601 window_modifyText( wid,
"txtStanding", _(
"Unknown") );
607 window_modifyText( wid,
"txtPresence", _(
"Unknown") );
613 window_modifyText( wid,
"txtSpobs", _(
"Unknown") );
619 window_modifyText( wid,
"txtServices", _(
"Unknown") );
622 map_update_autonav( wid );
627 map_update_status( wid, NULL );
632 window_modifyText( wid,
"txtSysname", _(sys->name) );
636 for (
int i=0; i<
array_size(sys->spobs); i++) {
637 if (!spob_isKnown(sys->spobs[i]))
639 if ((sys->spobs[i]->presence.faction >= 0)
643 if ((f == -1) && (sys->spobs[i]->presence.faction >= 0)) {
644 f = sys->spobs[i]->presence.faction;
646 else if (f != sys->spobs[i]->presence.faction
647 && (sys->spobs[i]->presence.faction >= 0)) {
648 snprintf( buf,
sizeof(buf), _(
"Multiple") );
654 window_modifyImage( wid,
"imgFaction", NULL, 0, 0 );
655 window_modifyText( wid,
"txtFaction", _(
"N/A") );
656 window_modifyText( wid,
"txtStanding", _(
"N/A") );
667 logow = logo == NULL ? 0 : logo->
w * (double)FACTION_LOGO_SM /
MAX( logo->
w, logo->
h );
668 logoh = logo == NULL ? 0 : logo->
h * (double)FACTION_LOGO_SM /
MAX( logo->
w, logo->
h );
669 window_modifyImage( wid,
"imgFaction", logo, logow, logoh );
672 -90 + logow/2, -20 - 32 - 10 -
gl_defFont.
h + logoh/2);
676 window_modifyText( wid,
"txtFaction", buf );
677 window_modifyText( wid,
"txtStanding", fcttext );
695 map_updateFactionPresence( wid,
"txtPresence", sys, 0 );
697 h = window_getTextHeight( wid,
"txtPresence" );
704 for (
int i=0; i<
array_size(sys->spobs); i++) {
705 const char *prefix, *suffix;
706 Spob *s = sys->spobs[i];
708 if (!spob_isKnown(s))
719 p +=
scnprintf( &buf[p],
sizeof(buf)-p,
"#%c%s%s%s#n",
722 p +=
scnprintf( &buf[p],
sizeof(buf)-p,
",\n#%c%s%s%s#n",
727 strncpy( buf, _(
"None"),
sizeof(buf)-1 );
728 buf[
sizeof(
buf)-1] =
'\0';
731 window_modifyText( wid,
"txtSpobs", buf );
746 for (
int i=0; i<
array_size(sys->spobs); i++) {
747 Spob *pnt = sys->spobs[i];
748 if (!spob_isKnown(pnt))
751 if (!spob_hasService( pnt, SPOB_SERVICE_INHABITED ))
767 for (
int i=SPOB_SERVICE_LAND; i<=SPOB_SERVICE_SHIPYARD; i<<=1) {
770 else if (services & i)
772 else if (services_h & i)
774 else if (services_r & i)
776 else if (services_u & i)
780 p +=
scnprintf( &buf[p],
sizeof(buf)-p, _(
"None"));
782 window_modifyText( wid,
"txtServices", buf );
787 if (map_mode == MAPMODE_TRAVEL) {
792 if (sys->features != NULL)
793 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"%s", _(sys->features) );
796 for (
int i=0; i<
array_size(sys->spobs); i++) {
797 Spob *spob = sys->spobs[i];
800 if (!spob_isKnown(spob))
803 p +=
scnprintf(&buf[p],
sizeof(buf)-p, _(
", "));
809 for (
int i=0; i<
array_size(sys->jumps); i++) {
810 if (sys->jumps[i].hide<=0.) {
817 p +=
scnprintf(&buf[p],
sizeof(buf)-p, _(
", "));
818 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"#g%s#0", _(
"Trade Lane") );
822 if (sys->nebu_density > 0.) {
824 p +=
scnprintf(&buf[p],
sizeof(buf)-p, _(
", "));
827 if (sys->nebu_density > 700.)
829 else if (sys->nebu_density < 300.)
835 dmg = sys->nebu_volatility;
836 if (sys->nebu_volatility > 50.) {
837 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"#r" );
838 p +=
scnprintf(&buf[p],
sizeof(buf)-p, _(
"Volatile %sNebula (%.1f MW)"), adj, dmg);
840 else if (sys->nebu_volatility > 20.) {
841 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"#o" );
842 p +=
scnprintf(&buf[p],
sizeof(buf)-p, _(
"Dangerous %sNebula (%.1f MW)"), adj, dmg);
844 else if (sys->nebu_volatility > 0.) {
845 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"#y" );
846 p +=
scnprintf(&buf[p],
sizeof(buf)-p, _(
"Unstable %sNebula (%.1f MW)"), adj, dmg);
849 p +=
scnprintf(&buf[p],
sizeof(buf)-p, _(
"%sNebula"), adj);
850 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"#0" );
853 if (sys->interference > 0.) {
855 p +=
scnprintf(&buf[p],
sizeof(buf)-p, _(
", "));
857 itf = sys->interference;
858 if (sys->interference > 700.) {
859 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"#r" );
860 p +=
scnprintf(&buf[p],
sizeof(buf)-p, _(
"Dense Interference (%.0f%%)"), itf);
862 else if (sys->interference < 300.) {
863 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"#o" );
864 p +=
scnprintf(&buf[p],
sizeof(buf)-p, _(
"Light Interference (%.0f%%)"), itf);
867 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"#y" );
868 p +=
scnprintf(&buf[p],
sizeof(buf)-p, _(
"Interference (%.0f%%)"), itf);
870 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"#0" );
874 double density = sys->asteroid_density;
877 p +=
scnprintf(&buf[p],
sizeof(buf)-p, _(
", "));
879 if (density >= 1000.) {
880 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"#o" );
881 p +=
scnprintf(&buf[p],
sizeof(buf)-p, _(
"Dense Asteroids"));
883 else if (density <= 300.) {
884 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"#y" );
885 p +=
scnprintf(&buf[p],
sizeof(buf)-p, _(
"Light Asteroids"));
888 p +=
scnprintf(&buf[p],
sizeof(buf)-p, _(
"Asteroids"));
889 p +=
scnprintf(&buf[p],
sizeof(buf)-p,
"#0" );
892 map_update_status( wid, buf );
896 map_update_autonav( wid );
920static void map_drawMarker(
double x,
double y,
double zoom,
921 double r,
double a,
int num,
int cur,
int type )
924 const glColour* colours[] = {
925 &cMarkerNew, &cMarkerPlot, &cMarkerHigh, &cMarkerLow, &cMarkerComputer, &cMarkerNew
931 if ((num == 1) || (num == 2) || (num == 4))
940 alpha += M_PI*2. * (double)cur/(
double)num;
942 x = x + 3.0*r * cos(alpha);
943 y = y + 3.0*r * sin(alpha);
950 glUseProgram(shaders.notemarker.program);
955 glUseProgram(shaders.sysmarker.program);
957 col_blend( &col, colours[type], &cWhite,
MIN(1.0, 0.75 + 0.25*sin(2.0*M_PI*map_dt)) );
958 x += 0.25*r * cos(alpha);
959 y += 0.25*r * sin(alpha);
961 glUniform1i( shaders.sysmarker.parami, 1 );
964 col_blend( &col, colours[type], &cWhite,
MIN(1.0, 1.0 + 0.25*sin(2.0*M_PI*map_dt)) );
965 glUniform1i( shaders.sysmarker.parami, 0 );
979static void map_render(
double bx,
double by,
double w,
double h,
void *data )
989 map_updateInternal( cst, dt );
992 map_renderParams( bx, by, cst->
xpos, cst->
ypos, w, h, cst->
zoom, &x, &y, &r );
1003 map_renderFactionDisks( x, y, z, r, 0, EASE_ALPHA(cst->
alpha_faction) );
1007 map_renderSystemEnvironment( x, y, z, 0, EASE_ALPHA(cst->
alpha_env) );
1010 map_renderJumps( x, y, z, r, 0 );
1014 map_renderPath( x, y, z, r, EASE_ALPHA(cst->
alpha_path) );
1017 map_renderSystems( bx, by, x, y, z, w, h, r, cst->
mode );
1021 map_renderMarkers( x, y, z, r, EASE_ALPHA(cst->
alpha_markers) );
1025 map_renderNames( bx, by, x, y, z, w, h, 0, EASE_ALPHA(cst->
alpha_names) );
1029 map_renderCommod( bx, by, x, y, z, w, h, r, 0, EASE_ALPHA(cst->
alpha_commod) );
1033 map_renderNotes( bx, by, x, y, z, w, h, 0, EASE_ALPHA(cst->
alpha_markers) );
1036 col.r = cRadar_tSpob.r;
1037 col.g = cRadar_tSpob.g;
1038 col.b = cRadar_tSpob.b;
1041 if (map_selected != -1) {
1043 glUseProgram( shaders.selectspob.program );
1044 glUniform1f( shaders.selectspob.dt, map_dt );
1046 1.7*r, 1.7*r, 0., &shaders.selectspob, &cRadar_tSpob, 1 );
1054 glClear( GL_DEPTH_BUFFER_BIT );
1060void map_renderParams(
double bx,
double by,
double xpos,
double ypos,
1061 double w,
double h,
double zoom,
double *x,
double *y,
double *r )
1063 *r = round(
CLAMP(6., 20., 8.*zoom));
1064 *x = round((bx - xpos + w/2) * 1.);
1065 *y = round((by - ypos + h/2) * 1.);
1073void map_renderDecorators(
double x,
double y,
double zoom,
int editor,
double alpha )
1075 const glColour ccol = { .r=1., .g=1., .b=1., .a=2./3.*alpha };
1078 for (
int i=0; i<
array_size(decorator_stack); i++) {
1083 if (decorator->
image == NULL)
1091 if (sys_isFlag(sys, SYSTEM_HIDDEN))
1094 if (!sys_isKnown(sys))
1106 if (editor || visible==1) {
1107 double tx = x + decorator->x*zoom;
1108 double ty = y + decorator->
y*zoom;
1110 int sw = decorator->
image->
sw*zoom;
1111 int sh = decorator->
image->
sh*zoom;
1114 tx - sw/2, ty - sh/2, sw, sh, &ccol );
1122void map_renderFactionDisks(
double x,
double y,
double zoom,
double r,
int editor,
double alpha )
1129 if (sys_isFlag(sys,SYSTEM_HIDDEN))
1132 if ((!sys_isFlag(sys, SYSTEM_HAS_KNOWN_LANDABLE) || !sys_isKnown(sys)) && !editor)
1135 tx = x + sys->pos.x*zoom;
1136 ty = y + sys->pos.y*zoom;
1139 if (sys->faction != -1) {
1140 const glColour *col;
1141 double presence = sqrt(sys->ownerpresence);
1144 double sr = (40. + presence * 3.) * zoom * 0.5;
1152 glUseProgram(shaders.factiondisk.program);
1153 glUniform1f(shaders.factiondisk.paramf, r / sr );
1162void map_renderSystemEnvironment(
double x,
double y,
double zoom,
int editor,
double alpha )
1169 if (sys_isFlag(sys,SYSTEM_HIDDEN))
1172 if (!sys_isKnown(sys) && !editor)
1175 tx = x + sys->pos.x*zoom;
1176 ty = y + sys->pos.y*zoom;
1180 if (sys->nebu_density > 0.) {
1183 sw = (50. + sys->nebu_density * 50. / 1000.) * zoom;
1187 projection = gl_view_matrix;
1192 glUseProgram(shaders.nebula_map.program);
1195 glUniform1f(shaders.nebula_map.hue, sys->nebu_hue);
1196 glUniform1f(shaders.nebula_map.alpha, alpha);
1197 gl_uniformMat4(shaders.nebula_map.projection, &projection);
1198 glUniform1f(shaders.nebula_map.time, map_dt / 10.0);
1199 glUniform2f(shaders.nebula_map.globalpos, sys->pos.x, sys->pos.y );
1200 glUniform1f(shaders.nebula_map.volatility, sys->nebu_volatility );
1203 glEnableVertexAttribArray( shaders.nebula_map.vertex );
1205 glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
1208 glDisableVertexAttribArray( shaders.nebula_map.vertex );
1212 else if (sys->map_shader != NULL) {
1219 projection = gl_view_matrix;
1224 glUseProgram( sys->ms->program );
1227 gl_uniformMat4(sys->ms->projection, &projection);
1228 glUniform1f(sys->ms->time, map_dt);
1229 glUniform2f(sys->ms->globalpos, sys->pos.x, sys->pos.y );
1230 glUniform1f(sys->ms->alpha, alpha);
1233 glEnableVertexAttribArray( sys->ms->vertex );
1235 glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
1238 glDisableVertexAttribArray( sys->ms->vertex );
1248void map_renderJumps(
double x,
double y,
double zoom,
double radius,
int editor )
1254 if (sys_isFlag(sys,SYSTEM_HIDDEN))
1257 if (!sys_isKnown(sys) && !editor)
1260 x1 = x + sys->pos.x * zoom;
1261 y1 = y + sys->pos.y * zoom;
1263 for (
int j=0; j <
array_size(sys->jumps); j++) {
1264 double x2,y2, rx,ry, r, rw,rh;
1265 const glColour *col, *cole;
1266 StarSystem *jsys = sys->jumps[j].target;
1267 if (sys_isFlag(jsys,SYSTEM_HIDDEN))
1274 for (
int k=0; k <
array_size(jsys->jumps); k++) {
1275 if (jsys->jumps[k].target == sys) {
1276 if (jp_isFlag(&jsys->jumps[k], JP_EXITONLY))
1278 else if (jp_isFlag(&jsys->jumps[k], JP_HIDDEN))
1283 if (jp_isFlag(&sys->jumps[j], JP_EXITONLY))
1285 else if (jp_isFlag(&sys->jumps[j], JP_HIDDEN))
1290 x2 = x + jsys->pos.x * zoom;
1291 y2 = y + jsys->pos.y * zoom;
1294 r = atan2( ry, rx );
1297 if (sys->jumps[j].hide<=0.) {
1305 glUseProgram( shaders.jumplane.program );
1306 gl_uniformColor( shaders.jumplane.paramv, cole );
1307 glUniform1f( shaders.jumplane.paramf, radius );
1308 gl_renderShader( (x1+x2)/2., (y1+y2)/2., rw, rh, r, &shaders.jumplane, col, 1 );
1316void map_renderSystems(
double bx,
double by,
double x,
double y,
1317 double zoom,
double w,
double h,
double r, MapMode mode )
1320 const glColour *col;
1324 if (sys_isFlag(sys,SYSTEM_HIDDEN))
1328 if ((!sys_isKnown(sys) && !sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)
1332 tx = x + sys->pos.x*zoom;
1333 ty = y + sys->pos.y*zoom;
1336 if (!
rectOverlap(tx-r, ty-r, 2.*r, 2.*r, bx, by, w, h))
1340 if (mode == MAPMODE_EDITOR || mode == MAPMODE_TRAVEL || mode == MAPMODE_TRADE)
1344 if (mode != MAPMODE_EDITOR && !sys_isKnown(sys))
1347 if (mode == MAPMODE_EDITOR || mode == MAPMODE_TRAVEL || mode == MAPMODE_TRADE) {
1350 if (!sys_isFlag(sys, SYSTEM_HAS_KNOWN_LANDABLE) && mode != MAPMODE_EDITOR)
1353 if (mode != MAPMODE_EDITOR && !sys_isKnown(sys))
1355 else if (sys->faction < 0)
1357 else if (mode == MAPMODE_EDITOR)
1359 else if (
areEnemies(FACTION_PLAYER,sys->faction))
1361 else if (!sys_isFlag(sys, SYSTEM_HAS_LANDABLE))
1363 else if (
areAllies(FACTION_PLAYER,sys->faction))
1368 if (mode == MAPMODE_EDITOR) {
1375 else if (mode == MAPMODE_DISCOVER) {
1377 if (sys_isFlag( sys, SYSTEM_DISCOVERED ))
1386static void map_renderPath(
double x,
double y,
double zoom,
double radius,
double alpha )
1403 double x1,y1, x2,y2, rx,ry, rw,rh, r;
1404 StarSystem *sys2 = map_path[j];
1405 if (sys_isFlag(sys1,SYSTEM_HIDDEN) || sys_isFlag(sys2,SYSTEM_HIDDEN))
1407 if (jcur == jmax && jmax > 0)
1415 x1 = x + sys1->pos.x * zoom;
1416 y1 = y + sys1->pos.y * zoom;
1417 x2 = x + sys2->pos.x * zoom;
1418 y2 = y + sys2->pos.y * zoom;
1421 r = atan2( ry, rx );
1422 rw = (MOD(rx,ry)+radius)/2.;
1425 glUseProgram( shaders.jumplanegoto.program );
1426 glUniform1f( shaders.jumplanegoto.dt, map_dt );
1427 glUniform1f( shaders.jumplanegoto.paramf, radius );
1428 glUniform1i( shaders.jumplanegoto.parami, (jcur >= 1) );
1429 gl_renderShader( (x1+x2)/2., (y1+y2)/2., rw, rh, r, &shaders.jumplanegoto, &col, 1 );
1439void map_renderNotes(
double bx,
double by,
double x,
double y,
1440 double zoom,
double w,
double h,
int editor,
double alpha )
1445 if ((zoom <= 0.5) || editor)
1449 glClear( GL_DEPTH_BUFFER_BIT );
1453 double tx,ty, tw,th;
1458 if (!sys_isFlag(sys,SYSTEM_PMARKED))
1461 if (sys->note == NULL)
1465 tx = x + sys->pos.x*zoom;
1466 ty = y + sys->pos.y*zoom;
1469 if (!map_show_notes && ((
pow2(tx-map_mx-bx)+
pow2(ty-map_my-by)) >
pow2(MAP_MOVE_THRESHOLD)))
1472 if (!map_show_notes)
1473 glClear( GL_DEPTH_BUFFER_BIT );
1496void map_renderNames(
double bx,
double by,
double x,
double y,
1497 double zoom,
double w,
double h,
int editor,
double alpha )
1499 double tx,ty, vx,vy,
d,n;
1511 if (sys_isFlag(sys,SYSTEM_HIDDEN))
1515 if (!editor && !sys_isKnown(sys))
1521 tx = x + (sys->pos.x+12.) * zoom;
1522 ty = y + (sys->pos.y) * zoom - font->
h*0.5;
1525 if (!
rectOverlap(tx, ty, textw, font->
h, bx, by, w, h))
1530 gl_printRaw( font, tx, ty, &col, -1, _(sys->name) );
1534 if (!editor || (zoom <= 1.0))
1539 for (
int j=0; j<
array_size(sys->jumps); j++) {
1540 StarSystem *jsys = sys->jumps[j].target;
1542 vx = jsys->pos.x - sys->pos.x;
1543 vy = jsys->pos.y - sys->pos.y;
1547 d =
MAX(n*0.3*zoom, 15);
1548 tx = x + zoom*sys->pos.x +
d*vx;
1549 ty = y + zoom*sys->pos.y +
d*vy;
1551 n = sys->jumps[j].hide;
1553 snprintf( buf,
sizeof(buf),
"#gH: %.2f", n );
1555 snprintf( buf,
sizeof(buf),
"H: %.2f", n );
1566static void map_renderMarkers(
double x,
double y,
double zoom,
double r,
double a )
1574 if (!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED | SYSTEM_PMARKED))
1578 tx = x + sys->pos.x*zoom;
1579 ty = y + sys->pos.y*zoom;
1582 n = (sys_isFlag(sys, SYSTEM_CMARKED)) ? 1 : 0;
1583 n += (sys_isFlag(sys, SYSTEM_PMARKED)) ? 1 : 0;
1584 n += sys->markers_plot;
1585 n += sys->markers_high;
1586 n += sys->markers_low;
1587 n += sys->markers_computer;
1591 if (sys_isFlag(sys, SYSTEM_PMARKED)) {
1592 map_drawMarker( tx, ty, zoom, r, a, n, j, 5 );
1595 if (sys_isFlag(sys, SYSTEM_CMARKED)) {
1596 map_drawMarker( tx, ty, zoom, r, a, n, j, 0 );
1599 for (m=0; m<sys->markers_plot; m++) {
1600 map_drawMarker( tx, ty, zoom, r, a, n, j, 1 );
1603 for (m=0; m<sys->markers_high; m++) {
1604 map_drawMarker( tx, ty, zoom, r, a, n, j, 2 );
1607 for (m=0; m<sys->markers_low; m++) {
1608 map_drawMarker( tx, ty, zoom, r, a, n, j, 3 );
1611 for (m=0; m<sys->markers_computer; m++) {
1612 map_drawMarker( tx, ty, zoom, r, a, n, j, 4 );
1621static void map_renderSysBlack(
double bx,
double by,
double x,
double y,
double zoom,
double w,
double h,
double r,
int editor )
1628 if (sys_isFlag(sys,SYSTEM_HIDDEN))
1632 if ((!sys_isKnown(sys) && !sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)
1636 tx = x + sys->pos.x*zoom;
1637 ty = y + sys->pos.y*zoom;
1640 if (!
rectOverlap(tx - r, ty - r, r, r, bx, by, w, h))
1654void map_renderCommod(
double bx,
double by,
double x,
double y,
1655 double zoom,
double w,
double h,
double r,
int editor,
double a )
1659 double best,worst,maxPrice,minPrice,curMaxPrice,curMinPrice,thisPrice;
1662 if (cur_commod == -1 || map_selected == -1 || commod_known == NULL)
1665 c = commod_known[cur_commod];
1666 if (cur_commod_mode == 1) {
1678 curMaxPrice = curMinPrice;
1683 map_renderCommodIgnorance( x, y, zoom, sys,
c, a );
1684 map_renderSysBlack( bx, by, x, y, zoom, w, h, r, editor );
1691 minPrice = HUGE_VAL;
1693 for (
int j=0; j<
array_size(sys->spobs); j++) {
1694 Spob *p = sys->spobs[j];
1695 for (
int k=0; k<
array_size(p->commodities); k++) {
1696 if (p->commodities[k] !=
c)
1698 if (p->commodityPrice[k].cnt <= 0)
1700 thisPrice = p->commodityPrice[k].sum / p->commodityPrice[k].cnt;
1701 maxPrice =
MAX( thisPrice, maxPrice );
1702 minPrice =
MIN( thisPrice, minPrice );
1707 if (maxPrice == 0) {
1708 map_renderCommodIgnorance( x, y, zoom, sys,
c, a );
1709 map_renderSysBlack( bx, by, x, y, zoom, w, h, r, editor );
1712 curMaxPrice = maxPrice;
1713 curMinPrice = minPrice;
1716 map_renderCommodIgnorance( x, y, zoom, sys,
c, a );
1717 map_renderSysBlack( bx, by, x, y, zoom, w, h, r, editor );
1725 if (sys_isFlag(sys,SYSTEM_HIDDEN))
1729 if ((!sys_isKnown(sys) && !sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)
1733 tx = x + sys->pos.x*zoom;
1734 ty = y + sys->pos.y*zoom;
1737 if (!
rectOverlap(tx - r, ty - r, r, r, bx, by, w, h))
1742 minPrice = HUGE_VAL;
1744 for (
int j=0; j<
array_size(sys->spobs); j++) {
1745 Spob *p = sys->spobs[j];
1746 for (
int k=0; k<
array_size(p->commodities); k++) {
1747 if (p->commodities[k] !=
c)
1749 if (p->commodityPrice[k].cnt <= 0)
1751 thisPrice = p->commodityPrice[k].sum / p->commodityPrice[k].cnt;
1752 maxPrice =
MAX( thisPrice, maxPrice );
1753 minPrice =
MIN( thisPrice, minPrice );
1761 best = maxPrice - curMinPrice;
1762 worst= minPrice - curMaxPrice;
1766 gl_print(&
gl_smallFont, x + (sys->pos.x+11) * zoom, y + (sys->pos.y-22)*zoom, &ccol,
"%.1f",best);
1767 best = tanh ( 2*best / curMinPrice );
1768 col_blend( &ccol, &cFontBlue, &cFontYellow, best );
1776 worst = tanh ( -2*worst/ curMaxPrice );
1777 col_blend( &ccol, &cFontOrange, &cFontYellow, worst );
1799 if (sys_isFlag(sys,SYSTEM_HIDDEN))
1803 if ((!sys_isKnown(sys) && !sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)
1807 tx = x + sys->pos.x*zoom;
1808 ty = y + sys->pos.y*zoom;
1811 if (!
rectOverlap(tx - r, ty - r, r, r, bx, by, w, h))
1816 double sumPrice = 0;
1818 for (
int j=0; j<
array_size(sys->spobs); j++) {
1819 Spob *p = sys->spobs[j];
1820 for (
int k=0; k<
array_size(p->commodities); k++) {
1821 if (p->commodities[k] !=
c)
1823 if (p->commodityPrice[k].cnt <= 0)
1825 thisPrice = p->commodityPrice[k].sum / p->commodityPrice[k].cnt;
1826 sumPrice += thisPrice;
1837 if (sumPrice < commod_av_gal_price) {
1838 frac = tanh(5*(commod_av_gal_price / sumPrice - 1));
1839 col_blend( &ccol, &cFontOrange, &cFontYellow, frac );
1842 frac = tanh(5*(sumPrice / commod_av_gal_price - 1));
1843 col_blend( &ccol, &cFontBlue, &cFontYellow, frac );
1863static void map_renderCommodIgnorance(
double x,
double y,
double zoom,
1864 const StarSystem *sys,
const Commodity *
c,
double a )
1867 char buf[80], *line2;
1869 glColour col = cFontRed;
1872 snprintf( buf,
sizeof(buf), _(
"No price info for\n%s here"), _(
c->name) );
1873 line2 = u8_strchr( buf,
'\n', &charn );
1874 if (line2 != NULL) {
1883static int factionPresenceCompare(
const void *a,
const void *b )
1892 return strcmp( fpa->
name, fpb->
name );
1903void map_updateFactionPresence(
const unsigned int wid,
const char *name,
const StarSystem *sys,
int omniscient )
1906 char buf[STRMAX_SHORT] = {
'\0'};
1911 for (
int i=0; i<
array_size(sys->presence); i++) {
1914 if (sys->presence[i].value <= 0.)
1920 fp.
name = N_(
"Unknown");
1923 else if (omniscient)
1927 fp.
value = sys->presence[i].value;
1932 if (strcmp(fp.
name,presence[j].name)==0) {
1954 l +=
scnprintf( &buf[l],
sizeof(buf) - l,
"%s#0%s: #%c%.0f", (l==0) ?
"" :
"\n",
1955 _(p->name), col, p->value );
1959 snprintf( buf,
sizeof(buf), _(
"None") );
1961 window_modifyText( wid, name, buf );
1970static void map_focusLose(
unsigned int wid,
const char* wgtname )
1987static int map_mouse(
unsigned int wid, SDL_Event* event,
double mx,
double my,
1988 double w,
double h,
double rx,
double ry,
void *data )
1994 const double t = 15.*15.;
1996 switch (event->type) {
1997 case SDL_MOUSEWHEEL:
1999 if ((mx < 0.) || (mx > w) || (my < 0.) || (my > h))
2001 if (event->wheel.y > 0)
2002 map_buttonZoom( wid,
"btnZoomIn" );
2003 else if (event->wheel.y < 0)
2004 map_buttonZoom( wid,
"btnZoomOut" );
2007 case SDL_MOUSEBUTTONDOWN:
2009 if ((mx < 0.) || (mx > w) || (my < 0.) || (my > h))
2014 mx -= w/2 - cst->
xpos;
2015 my -= h/2 - cst->
ypos;
2022 if (sys_isFlag(sys, SYSTEM_HIDDEN))
2026 if (!sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)
2031 x = sys->pos.x * cst->
zoom;
2032 y = sys->pos.y * cst->
zoom;
2035 if (map_selected != -1) {
2037 map_system_open( map_selected );
2041 map_select( sys, (SDL_GetModState() & KMOD_SHIFT) );
2047 case SDL_MOUSEBUTTONUP:
2051 case SDL_MOUSEMOTION:
2070static void map_buttonZoom(
unsigned int wid,
const char* str )
2081 if (strcmp(str,
"btnZoomIn")==0) {
2085 else if (strcmp(str,
"btnZoomOut")==0) {
2090 map_setZoom( wid, cst->
zoom );
2102static void map_genModeList(
void)
2105 const char *odd_template, *even_template;
2107 map_onClose( 0, NULL );
2108 commod_known = calloc( commodity_getN(),
sizeof(
Commodity*) );
2111 for (
int j=0 ; j<
array_size(sys->spobs); j++) {
2112 Spob *p = sys->spobs[j];
2113 for (
int k=0; k<
array_size(p->commodities); k++) {
2114 if (p->commodityPrice[k].cnt > 0 ) {
2117 for (l=0 ; l<totGot; l++) {
2118 if ( p->commodities[k] == commod_known[l] )
2122 commod_known[totGot] = p->commodities[k];
2133 even_template = _(
"%s: Cost");
2134 odd_template = _(
"%s: Trade");
2135 for (
int i=0; i<totGot; i++) {
2136 const char *commod_text = _(commod_known[i]->name);
2148static void map_modeUpdate(
unsigned int wid,
const char* str )
2151 if (listMapModeVisible==2) {
2152 listMapModeVisible=1;
2154 else if (listMapModeVisible == 1) {
2155 int listpos = toolkit_getListPos( wid,
"lstMapMode" );
2158 map_mode = MAPMODE_TRAVEL;
2162 else if (listpos == 1) {
2163 map_mode = MAPMODE_DISCOVER;
2168 map_mode = MAPMODE_TRADE;
2169 cur_commod = (listpos - MAPMODE_TRADE) / 2;
2170 cur_commod_mode = (listpos - MAPMODE_TRADE) % 2 ;
2179static void map_modeActivate(
unsigned int wid,
const char* str )
2181 map_modeUpdate( wid, str );
2182 listMapModeVisible = 0;
2186static void map_setMinimal(
unsigned int wid,
int value )
2188 map_minimal_mode = value;
2190 window_buttonCaption( wid,
"btnMinimal", (value) ? _(
"Normal View") : _(
"Minimal View") );
2196static void map_buttonMarkSystem(
unsigned int wid,
const char* str )
2200 if (map_selected != -1) {
2204 if (sys->note != NULL) {
2210 if (sys_isFlag(sys, SYSTEM_PMARKED))
2211 sys_rmFlag(sys, SYSTEM_PMARKED);
2213 sys->note =
dialogue_input(_(
"Add System Note"), 0, 60, _(
"Write a note about the #o%s#0 system:"), sys_isKnown(sys) ? _(sys->name) : _(
"Unknown") );
2214 if (sys->note != NULL)
2215 sys_setFlag(sys, SYSTEM_PMARKED);
2223static void map_buttonSystemMap(
unsigned int wid,
const char* str )
2227 if (map_selected != -1)
2229 map_system_open( map_selected );
2235static void map_buttonMinimal(
unsigned int wid,
const char* str )
2238 map_setMinimal( wid, !map_minimal_mode );
2247static void map_buttonCommodity(
unsigned int wid,
const char* str )
2251 char **this_map_modes;
2252 static int cur_commod_last = 0;
2253 static int cur_commod_mode_last = 0;
2254 static int map_mode_last = MAPMODE_TRAVEL;
2258 mods = SDL_GetModState();
2259 if (mods & (KMOD_LCTRL | KMOD_RCTRL)) {
2260 if (map_mode == MAPMODE_TRAVEL) {
2261 map_mode = map_mode_last;
2262 cur_commod = cur_commod_last;
2263 if (cur_commod == -1)
2265 cur_commod_mode = cur_commod_mode_last;
2267 map_mode_last = map_mode;
2268 map_mode = MAPMODE_TRAVEL;
2269 cur_commod_last = cur_commod;
2270 cur_commod_mode_last = cur_commod_mode;
2273 if (cur_commod >= (
array_size(map_modes)-1)/2 )
2276 if (listMapModeVisible) {
2277 listMapModeVisible = 0;
2282 if (listMapModeVisible) {
2283 listMapModeVisible = 0;
2286 this_map_modes = calloc(
sizeof(
char*),
array_size(map_modes) );
2288 this_map_modes[i]=strdup(map_modes[i]);
2290 listMapModeVisible = 2;
2291 if (map_mode == MAPMODE_TRAVEL)
2293 else if (map_mode == MAPMODE_DISCOVER)
2296 defpos = cur_commod*2 + MAPMODE_TRADE - cur_commod_mode;
2298 window_addList( wid, -10, 60, 200, 200,
"lstMapMode",
2299 this_map_modes,
array_size(map_modes), defpos, map_modeUpdate, map_modeActivate );
2307static void map_onClose(
unsigned int wid,
const char *str )
2311 free( commod_known );
2312 commod_known = NULL;
2314 free( map_modes[i] );
2319void map_cleanup (
void)
2328void map_close (
void)
2338void map_clear (
void)
2345static void map_updateInternal(
CstMapWidget *cst,
double dt )
2347 double dx, dy, mod, angle;
2348 double mapmin = 1.-map_minimal_mode;
2350#define AMAX(x) (x) = MIN( 1., (x) + dt )
2351#define AMIN(x) (x) = MAX( 0., (x) - dt )
2353if ((x) < y) (x) = MIN( y, (x) + dt ); \
2354else (x) = MAX( y, (x) - dt )
2355 switch (cst->
mode) {
2356 case MAPMODE_EDITOR:
2357 case MAPMODE_TRAVEL:
2367 case MAPMODE_DISCOVER:
2395 angle = ANGLE(dx,dy);
2397 mod =
MIN( mod, dt*map_flyto_speed);
2398 cst->
xpos += mod * cos(angle);
2399 cst->
ypos += mod * sin(angle);
2406static void map_reset(
CstMapWidget* cst, MapMode mode )
2409 map_updateInternal( cst, 1000. );
2415static CstMapWidget* map_globalCustomData(
unsigned int wid )
2419 return (wid > 0) ? window_custGetData( wid,
"cstMap" ) : NULL;
2425static void map_selectCur (
void)
2440StarSystem* map_getDestination(
int *jumps )
2461 array_erase( &map_path, &map_path[0], &map_path[1] );
2468 if (map_path[0] ==
cur_system->jumps[j].target) {
2492void map_select(
const StarSystem *sys,
char shifted )
2495 unsigned int wid = 0;
2515 map_path = map_getJumpPath(
cur_system->name, sys->name, 0, 1, map_path );
2526 if (map_path[0] ==
cur_system->jumps[i].target) {
2544 window_enableButton( wid,
"btnAutonav" );
2546 window_disableButton( wid,
"btnAutonav" );
2558void map_cycleMissions(
int dir)
2561 StarSystem *dest = map_getDestination( NULL );
2563 int found_next_i = -1;
2564 int found_prev_i = -1;
2605 if (dir>0 && found_next_i>=0)
2607 else if (dir<0 && found_prev_i>=0)
2613 map_select( target, 0 );
2614 map_center(
window_get( MAP_WDWNAME ), target->name );
2624void map_toggleNotes()
2626 map_show_notes = !map_show_notes;
2639typedef struct SysNode_ {
2649static SysNode* A_newNode( StarSystem* sys );
2655static void A_freeList(
SysNode *first );
2656static int map_decorator_parse(
MapDecorator *temp,
const char *file );
2658static SysNode* A_newNode( StarSystem* sys )
2684 while (n->next != NULL)
2695 if (first->sys == cur) {
2704 if (n->sys == cur) {
2710 }
while ((n=n->next) != NULL);
2726 }
while ((n=n->next) != NULL);
2740 if (n->g < lowest->
g)
2742 }
while ((n=n->next) != NULL);
2746static void A_freeList(
SysNode *first )
2758 }
while ((n=n->gnext) != NULL);
2763void map_setZoom(
unsigned int wid,
double zoom )
2779StarSystem** map_getJumpPath(
const char* sysstart,
const char* sysend,
2780 int ignore_known,
int show_hidden, StarSystem** old_data )
2782 int j, cost, njumps, ojumps;
2783 StarSystem *ssys, *esys, **res;
2802 if (ssys==esys ||
array_size(ssys->jumps)==0) {
2815 open = closed = NULL;
2816 cur = A_newNode( ssys );
2819 open = A_add( open, cur );
2822 while ((cur = A_lowest(open))) {
2824 if (cur->
sys == esys)
2829 if (j > MAP_LOOP_PROT)
2833 open = A_rm( open, cur->
sys );
2834 closed = A_add( closed, cur );
2835 cost = A_g(cur) + 1;
2838 JumpPoint *jp = &cur->
sys->jumps[i];
2839 StarSystem *sys = jp->target;
2842 if (!ignore_known) {
2843 if (!jp_isKnown(jp))
2848 if (jp_isFlag( jp, JP_EXITONLY ))
2852 if (!show_hidden && jp_isFlag( jp, JP_HIDDEN ))
2856 ccost = A_in(closed, sys);
2857 if ((ccost != NULL) && (cost >= A_g(ccost)))
2862 ocost = A_in(open, sys);
2863 if (ocost != NULL) {
2864 if (cost < A_g(ocost))
2865 open = A_rm( open, sys );
2871 neighbour = A_newNode( sys );
2873 neighbour->
g = cost;
2874 open = A_add( open, neighbour );
2883 if (cur != NULL && esys == cur->
sys) {
2884 njumps = A_g(cur) + ojumps;
2885 assert( njumps > ojumps );
2890 for (
int i=0; i<njumps-ojumps; i++) {
2891 res[njumps-i-1] = cur->
sys;
2912int map_map(
const Outfit *map )
2915 sys_setFlag(map->
u.
map->systems[i], SYSTEM_KNOWN);
2921 jp_setFlag(map->
u.
map->jumps[i], JP_KNOWN);
2933int map_isUseless(
const Outfit* map )
2936 if (!sys_isKnown(map->
u.
map->systems[i]))
2943 if (!spob_isKnown(p))
2948 if (!jp_isKnown(map->
u.
map->jumps[i]))
2957int localmap_map(
const Outfit *lmap )
2969 if (jp_isFlag(jp, JP_EXITONLY) || jp_isFlag(jp, JP_HIDDEN))
2971 if (mod*jp->hide <= detect)
2972 jp_setFlag( jp, JP_KNOWN );
2980 if (mod*p->hide <= detect)
2990int localmap_isUseless(
const Outfit *lmap )
3002 if (jp_isFlag(jp, JP_EXITONLY) || jp_isFlag(jp, JP_HIDDEN))
3004 if ((mod*jp->hide <= detect) && !jp_isKnown( jp ))
3011 if ((mod*p->hide <= detect) && !spob_isKnown( p ))
3029void map_show(
int wid,
int x,
int y,
int w,
int h,
double zoom,
double xoff,
double yoff )
3034 window_addCust( wid, x, y, w, h,
3035 "cstMap", 1, map_render, map_mouse, NULL, map_focusLose, cst );
3036 window_custAutoFreeData( wid,
"cstMap" );
3050 map_setZoom( wid, zoom );
3052 map_reset( cst, MAPMODE_TRAVEL );
3062int map_center(
int wid,
const char *sys )
3078 map_flyto_speed =
MIN( 2000.,
d / 0.2 );
3090 Uint32 time = SDL_GetTicks();
3094 for (
int i=0; i<
array_size(decorator_files); i++) {
3096 int ret = map_decorator_parse( &temp, decorator_files[i] );
3099 free( decorator_files[i] );
3104 time = SDL_GetTicks() - time;
3105 DEBUG( n_(
"Loaded %d map decorator in %.3f s",
"Loaded %d map decorators in %.3f s",
array_size(decorator_stack) ),
array_size(decorator_stack), time/1000. );
3108 DEBUG( n_(
"Loaded %d map decorator",
"Loaded %d map decorators",
array_size(decorator_stack) ),
array_size(decorator_stack) );
3113static int map_decorator_parse(
MapDecorator *temp,
const char *file )
3116 xmlNodePtr node, parent;
3122 parent = doc->xmlChildrenNode;
3123 if (strcmp((
char*)parent->name,
"decorator")) {
3124 ERR(_(
"Malformed %s file: missing root element 'decorator'"), file );
3134 node = parent->xmlChildrenNode;
3136 xml_onlyNodes(node);
3137 xmlr_float(node,
"x", temp->x);
3138 xmlr_float(node,
"y", temp->
y);
3140 if (xml_isNode(node,
"image")) {
3142 MAP_DECORATOR_GFX_PATH
"%s", 1, 1, OPENGL_TEX_MIPMAPS );
3144 if (temp->
image == NULL)
3145 WARN(_(
"Could not load map decorator texture '%s'."), xml_get(node));
3149 WARN(_(
"Map decorator has unknown node '%s'."), node->name);
3150 }
while (xml_nextNode(node));
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#define array_resize(ptr_array, new_size)
Resizes the array to accomodate new_size elements.
#define array_create_size(basic_type, capacity)
Creates a new dynamic array of ‘basic_type’ with an initial capacity.
#define array_erase(ptr_array, first, last)
Erases elements in interval [first, last).
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#define array_back(ptr_array)
Returns the last element in the array.
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
void col_blend(glColour *blend, const glColour *fg, const glColour *bg, float alpha)
Blends two colours.
StarSystem * systems_stack
char * dialogue_input(const char *title, int min, int max, const char *fmt,...)
Creates a dialogue that allows the player to write a message.
const char * faction_longname(int f)
Gets the faction's long name (formal, human-readable).
int faction_exists(const char *name)
Checks to see if a faction exists by name.
int faction_isKnown(int id)
Is the faction known?
char faction_getColourChar(int f)
Gets the faction character associated to its standing with the player.
const glTexture * faction_logo(int f)
Gets the faction's logo (ideally 256x256).
int areEnemies(int a, int b)
Checks whether two factions are enemies.
const char * faction_name(int f)
Gets a factions "real" (internal) name.
const char * faction_getStandingText(int f)
Gets the player's standing in human readable form.
const glColour * faction_colour(int f)
Gets the colour of the faction.
const char * faction_mapname(int f)
Gets the faction's map name (translated).
int faction_get(const char *name)
Gets a faction ID by name.
int areAllies(int a, int b)
Checks whether two factions are allies or not.
int gl_printHeightRaw(const glFont *ft_font, const int width, const char *text)
Gets the height of a non-formatted string.
void gl_printRaw(const glFont *ft_font, double x, double y, const glColour *c, double outlineR, const char *text)
Prints text on screen.
int gl_printWidthRaw(const glFont *ft_font, const char *text)
Gets the width that it would take to print some text.
void gl_print(const glFont *ft_font, const double x, const double y, const glColour *c, const char *fmt,...)
Prints text on screen like printf.
void gui_setNav(void)
Player just changed their nav computer target.
void mat4_translate(mat4 *m, double x, double y, double z)
Translates a homogenous transformation matrix.
void mat4_scale(mat4 *m, double x, double y, double z)
Scales a homogeneous transformation matrix.
void mission_sysMark(void)
Marks all active systems that need marking.
double naev_getrealdt(void)
Gets the last delta-tick.
Header file with generic functions and naev-specifics.
char ** ndata_listRecursive(const char *path)
Lists all the visible files in a directory, at any depth.
static char buf[NEWS_MAX_LENGTH]
int rectOverlap(double x, double y, double w, double h, double x2, double y2, double w2, double h2)
Checks whether two rectangles overlap at any point.
int asprintf(char **strp, const char *fmt,...)
Like sprintf(), but it allocates a large-enough string and returns the pointer in the first argument....
int scnprintf(char *text, size_t maxlen, const char *fmt,...)
Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer....
glTexture * xml_parseTexture(xmlNodePtr node, const char *path, int defsx, int defsy, const unsigned int flags)
Parses a texture handling the sx and sy elements.
xmlDocPtr xml_parsePhysFS(const char *filename)
Analogous to xmlParseMemory/xmlParseFile.
void gl_renderShader(double x, double y, double w, double h, double r, const SimpleShader *shd, const glColour *c, int center)
Renders a simple shader.
void gl_renderRect(double x, double y, double w, double h, const glColour *c)
Renders a rectangle.
void gl_renderScale(const glTexture *texture, double bx, double by, double bw, double bh, const glColour *c)
Blits a texture scaling it.
void gl_renderCircle(double cx, double cy, double r, const glColour *c, int filled)
Draws a circle.
void gl_freeTexture(glTexture *texture)
Frees a texture.
void gl_vboActivateAttribOffset(gl_vbo *vbo, GLuint index, GLuint offset, GLint size, GLenum type, GLsizei stride)
Activates a VBO's offset.
int pilot_getJumps(const Pilot *p)
Gets the amount of jumps the pilot has left.
void player_targetHyperspaceSet(int id, int nomsg)
Sets the player's hyperspace target.
void player_hyperspacePreempt(int preempt)
Enables or disables jump points preempting spobs in autoface and target clearing.
void player_autonavStartWindow(unsigned int wid, const char *str)
Starts autonav and closes the window.
void player_autonavAbortJump(const char *reason)
Aborts regular interstellar autonav, but not in-system autonav.
StarSystem * system_getIndex(int id)
Get the system by its index.
int spob_hasSystem(const Spob *spb)
Get whether or not a spob has a system (i.e. is on the map).
const char * spob_getSymbol(const Spob *p)
Gets the spob symbol.
char spob_getColourChar(const Spob *p)
Gets the spob colour char.
int space_sysReachable(const StarSystem *sys)
Sees if a system is reachable.
int space_sysReachableFromSys(const StarSystem *target, const StarSystem *sys)
Sees if a system is reachable from another system.
StarSystem * system_get(const char *sysname)
Get the system from its name.
void spob_setKnown(Spob *p)
Sets a spob's known status, if it's real.
void spob_updateLand(Spob *p)
Updates the land possibilities of a spob.
int system_hasSpob(const StarSystem *sys)
See if the system has a spob.
const char * spob_name(const Spob *p)
Gets the translated name of a spob.
const char * spob_getServiceName(int service)
Gets the (English) name for a service code.
Faction presence container to be used for the map information stuff.
Images to be shown on the map.
A ship outfit, depends radically on the type.
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
CommodityPrice * commodityPrice
Node structure for A* pathfinding.
Represents a font in memory.
Abstraction for rendering sprite sheets.