15#include "background.h"
21#include "land_outfits.h"
23#include "map_system.h"
30#define BUTTON_WIDTH 80
31#define BUTTON_HEIGHT 30
33static StarSystem *cur_sys_sel = NULL;
34static int cur_spob_sel = 0;
35static Spob *cur_spobObj_sel = NULL;
36static Outfit **cur_spob_sel_outfits = NULL;
37static Ship **cur_spob_sel_ships = NULL;
39static int nameWidth = 0;
41static char infobuf[STRMAX];
42static unsigned int focusedStar = 0;
47#define MAP_SYSTEM_WDWNAME "wdwSystemMap"
48#define MAPSYS_OUTFITS "mapSysOutfits"
49#define MAPSYS_SHIPS "mapSysShips"
50#define MAPSYS_TRADE "mapSysTrade"
62void map_system_cleanup(
unsigned int wid,
const char *str );
63int map_system_isOpen(
void );
66void map_system_updateSelected(
unsigned int wid );
69static void map_system_render(
double bx,
double by,
double w,
double h,
72static int map_system_mouse(
unsigned int wid,
const SDL_Event *event,
73 double mx,
double my,
double w,
double h,
74 double rx,
double ry,
void *data );
76static int map_system_keyHandler(
unsigned int wid, SDL_Keycode key,
77 SDL_Keymod mod,
int isrepeat );
78void map_system_show(
int wid,
int x,
int y,
int w,
int h );
80static void map_system_genOutfitsList(
unsigned int wid,
float goodsSpace,
81 float outfitSpace,
float shipSpace );
82static void map_system_genShipsList(
unsigned int wid,
float goodsSpace,
83 float outfitSpace,
float shipSpace );
84static void map_system_genTradeList(
unsigned int wid,
float goodsSpace,
85 float outfitSpace,
float shipSpace );
87static void map_system_array_update(
unsigned int wid,
const char *str );
89void map_system_buyCommodPrice(
unsigned int wid,
const char *str );
96int map_system_init(
void )
106int map_system_load(
void )
114void map_system_exit(
void )
116 for (
int i = 0; i <
array_size( starImages ); i++ )
123 cur_spob_sel_outfits = NULL;
125 cur_spob_sel_ships = NULL;
131void map_system_cleanup(
unsigned int wid,
const char *str )
145static int map_system_keyHandler(
unsigned int wid, SDL_Keycode key,
146 SDL_Keymod mod,
int isrepeat )
150 if ( key == SDLK_m ) {
154 if ( key == SDLK_UP ) {
155 cur_spob_sel =
MAX( cur_spob_sel - 1, 0 );
156 map_system_updateSelected( wid );
159 if ( key == SDLK_DOWN ) {
160 cur_spob_sel =
MIN( cur_spob_sel + 1, nshow );
161 map_system_updateSelected( wid );
170void map_system_open(
int sys_selected )
181 cur_spobObj_sel = NULL;
182 memset( infobuf, 0,
sizeof( infobuf ) );
192 w =
MAX( 600, SCREEN_W - 140 );
193 h =
MAX( 540, SCREEN_H - 140 );
196 wid =
window_create( MAP_SYSTEM_WDWNAME, _(
"System Info" ), -1, -1, w, h );
200 window_addText( wid, 40, h - 30, 160, 20, 1,
"txtSysname", &
gl_defFont,
201 &cFontGreen, system_name( cur_sys_sel ) );
202 window_addImage( wid, -90 + 32, h - 30, 0, 0,
"imgFaction", NULL, 0 );
209 _(
"Buy commodity price info" ),
210 map_system_buyCommodPrice );
211 window_disableButton( wid,
"btnBuyCommodPrice" );
233 map_system_show( wid, 20, 60, w - 40, h - 100 );
234 map_system_updateSelected( wid );
242int map_system_isOpen(
void )
257void map_system_show(
int wid,
int x,
int y,
int w,
int h )
259 window_addRect( wid, x, y, w, h,
"rctMapSys", &cBlack, 0 );
260 window_addCust( wid, x, y, w, h,
"cstMapSys", 1, map_system_render,
261 map_system_mouse, NULL, NULL, NULL );
262 window_custSetDynamic( wid,
"cstMapSys", 1 );
275static void map_system_render(
double bx,
double by,
double w,
double h,
281 StarSystem *sys = cur_sys_sel;
283 static int phase = 0;
287 double ast_nb, ast_area;
290 double unknownPresence = 0;
297 offset = h - pitch * nshow;
298 for ( i = 0; i <
array_size( sys->spobs ); i++ ) {
300 if ( !spob_isKnown( p ) )
303 if ( p->gfx_space == NULL )
304 WARN( _(
"No gfx for %s…" ), p->name );
308 if ( p->gfx_space->w > p->gfx_space->h )
309 ih = ih * p->gfx_space->h / p->gfx_space->w;
310 else if ( p->gfx_space->w < p->gfx_space->h )
311 iw = iw * p->gfx_space->w / p->gfx_space->h;
313 by + ( nshow - vis_index - 1 ) * pitch +
314 ( pitch - ih ) / 2 + offset,
318 by + ( nshow - vis_index - 0.5 ) * pitch + offset,
319 ( cur_spob_sel == vis_index ? &cFontGreen : &cFontWhite ),
333 if ( starImages[focusedStar]->w > starImages[focusedStar]->h )
334 ih = ih * starImages[focusedStar]->h / starImages[focusedStar]->w;
335 else if ( starImages[focusedStar]->w < starImages[focusedStar]->h )
336 iw = iw * starImages[focusedStar]->w / starImages[focusedStar]->h;
337 ccol.r = ccol.g = ccol.b = ccol.a = 1;
338 if ( phase > 120 &&
array_size( starImages ) > 1 )
339 ccol.a = cos( ( phase - 121 ) / 30. * M_PI / 2. );
341 by + ( nshow - 1 ) * pitch + ( pitch - ih ) / 2 + offset,
343 if ( phase > 120 &&
array_size( starImages ) > 1 ) {
347 i = ( focusedStar + 1 ) %
array_size( starImages );
348 if ( starImages[i]->w > starImages[i]->h )
349 ih = ih * starImages[i]->h / starImages[i]->w;
350 else if ( starImages[i]->w < starImages[i]->h )
351 iw = iw * starImages[i]->w / starImages[i]->h;
354 by + ( nshow - 1 ) * pitch + ( pitch - ih ) / 2 +
358 }
else if ( sys->nebu_density > 0. ) {
361 _(
"Obscured by the nebula" ) );
363 ( by + ( nshow - 0.5 ) * pitch + offset ), 0, &cFontRed,
364 -1., _(
"Obscured by the nebula" ) );
367 by + ( nshow - 0.5 ) * pitch + offset,
368 ( cur_spob_sel == 0 ? &cFontGreen : &cFontWhite ), -1.,
369 system_name( sys ) );
370 if ( ( cur_spob_sel == 0 ) && bgImage != NULL ) {
371 double imgw, imgh, s;
372 iw = w - 50 - pitch - nameWidth;
376 s =
MIN( iw / imgw, ih / imgh );
380 by + h - ih + ( ih - imgh ) * 0.5, imgw, imgh, &cWhite );
384 ccol.g = 0.6 + 0.4 * sin( phase / 150. * 2 * M_PI );
389 gl_renderRect( bx + 1, by + ( nshow - cur_spob_sel - 1 ) * pitch + offset,
391 gl_renderRect( bx + 1, by + ( nshow - cur_spob_sel ) * pitch - ih + offset,
394 by + ( nshow - cur_spob_sel - 1 ) * pitch + offset, iw, ih,
397 by + ( nshow - cur_spob_sel ) * pitch - ih + offset, iw, ih,
399 gl_renderRect( bx + 1, by + ( nshow - cur_spob_sel - 1 ) * pitch + offset,
401 gl_renderRect( bx + 1, by + ( nshow - cur_spob_sel ) * pitch - iw + offset,
404 by + ( nshow - cur_spob_sel - 1 ) * pitch + offset, ih, iw,
407 by + ( nshow - cur_spob_sel ) * pitch - iw + offset, ih, iw,
411 if ( cur_spob_sel == 0 ) {
414 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt, _(
"#nSystem:#0 %s\n" ),
415 system_name( sys ) );
417 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
418 n_(
"%d-star system\n",
"%d-star system\n", stars ),
422 if ( sys->nebu_density > 0. ) {
423 double dmg = sys->nebu_volatility;
424 const char *sdmg, *adj;
429 if ( sys_isFlag( sys, SYSTEM_HIDENEBULADAMAGE ) )
430 snprintf( dmgstr,
sizeof( dmgstr ),
431 p_(
"nebula_volatility",
"??? %s" ), UNIT_POWER );
433 snprintf( dmgstr,
sizeof( dmgstr ),
434 p_(
"nebula_volatility",
"%.1f %s" ),
435 sys->nebu_volatility, UNIT_POWER );
438 if ( dmg > SYS_VOLATILITY_VOLATILE ) {
440 sdmg = p_(
"nebula",
"Volatile" );
441 }
else if ( sys->nebu_volatility > SYS_VOLATILITY_DANGEROUS ) {
443 sdmg = p_(
"nebula",
"Dangerous" );
444 }
else if ( sys->nebu_volatility > 0. ) {
446 sdmg = p_(
"nebula",
"Unstable" );
449 sdmg = p_(
"nebula",
"Stable" );
453 if ( sys->nebu_density > 700. )
454 adj = p_(
"nebula",
"Dense " );
455 else if ( sys->nebu_density < 300. )
456 adj = p_(
"nebula",
"Light " );
460 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
461 _(
"#nNebula: #%c%s%s (%s)#0\n" ), col, adj, sdmg,
466 if ( sys->interference > 0. ) {
467 double itf = sys->interference;
472 sint = p_(
"interference",
"Dense" );
473 }
else if ( itf > 30. ) {
475 sint = p_(
"interference",
"Medium" );
478 sint = p_(
"interference",
"Light" );
480 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
481 _(
"#nInterference: #%c%s (%.0f%%)#0\n" ), col, sint,
486 ast_nb = ast_area = 0.;
487 for ( i = 0; i <
array_size( sys->asteroids ); i++ ) {
488 ast_nb += sys->asteroids[i].nmax;
489 ast_area =
MAX( ast_area, sys->asteroids[i].area );
491 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
492 _(
"#nAsteroid field density:#0 %.2g\n" ),
493 ast_nb * ASTEROID_REF_AREA / ast_area );
496 if ( sys->features != NULL )
497 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
498 _(
"#nOther:#0 %s\n" ), _( sys->features ) );
501 for ( i = 0; i <
array_size( sys->spobs ); i++ ) {
502 if ( spob_isKnown( sys->spobs[i] ) ) {
503 if ( ( f == -1 ) && ( sys->spobs[i]->presence.faction >= 0 ) ) {
504 f = sys->spobs[i]->presence.faction;
505 }
else if ( f != sys->spobs[i]->presence.faction &&
506 ( sys->spobs[i]->presence.faction >= 0 ) ) {
507 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
508 _(
"#nFaction:#0 Multiple\n" ) );
514 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
515 _(
"#nFaction:#0 N/A\n" ) );
520 scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
521 _(
"#nFaction:#0 %s\n#nStanding:#0 %s\n" ),
525 if ( logo != NULL ) {
526 gl_renderScale( logo, bx + pitch + nameWidth + 200, by + h - 21, 20,
533 for ( i = 0; i <
array_size( sys->presence ); i++ ) {
534 if ( sys->presence[i].value <= 0 )
539 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
"#n%s: #%c%.0f\n",
541 sys->presence[i].value );
543 unknownPresence += sys->presence[i].value;
545 if ( unknownPresence != 0 )
546 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
"#n%s: #%c%.0f\n",
547 _(
"Unknown" ),
'N', unknownPresence );
548 if ( hasPresence == 0 )
549 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
550 _(
"#nPresence:#0 N/A\n" ) );
552 ( w - nameWidth - pitch - 60 ) / 2, buf );
554 txtHeight, bx + 10 + pitch + nameWidth,
555 by + h - 10 - txtHeight, 0, &cFontWhite, -1., buf );
558 for ( i = 0; i <
array_size( sys->jumps ); i++ ) {
559 if ( jp_isUsable( &sys->jumps[i] ) ) {
561 infopos =
scnprintf( infobuf,
sizeof( infobuf ),
562 _(
" #nJump points to:#0\n" ) );
563 if ( sys_isKnown( sys->jumps[i].target ) )
565 scnprintf( &infobuf[infopos],
sizeof( infobuf ) - infopos,
566 " %s\n", system_name( sys->jumps[i].target ) );
569 scnprintf( &infobuf[infopos],
sizeof( infobuf ) - infopos,
570 _(
" Unknown system\n" ) );
576 if ( p->presence.faction >= 0 ) {
580 gl_renderScale( logo, bx + pitch + nameWidth + 200, by + h - 21, 20,
583 snprintf( factionBuf, 64,
"%s",
586 bx + pitch + nameWidth + 230, by + h - 31, 0,
587 &cFontWhite, -1., factionBuf );
591 scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
592 _(
"#nSpace Object:#0 %s\n#nPlanetary class:#0 %s "
593 "#nPopulation:#0 %s\n" ),
595 if ( !spob_hasService( p, SPOB_SERVICE_INHABITED ) )
596 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
597 _(
"No space port here\n" ) );
598 else if ( p->can_land )
599 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
"#g%s#0",
600 _(
"You can land here\n" ) );
601 else if (
areEnemies( FACTION_PLAYER, p->presence.faction ) )
602 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
"#o%s#0",
603 _(
"Not advisable to land here\n" ) );
605 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
"#r%s#0",
606 _(
"You cannot land here\n" ) );
609 if ( p->feature != NULL )
610 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
"%s\n",
613 if ( infobuf[0] ==
'\0' ) {
618 &infobuf[infocnt],
sizeof( infobuf ) - infocnt,
"%s\n\n",
619 ( p->description == NULL ? _(
"No description available" )
620 : _( p->description ) ) );
624 &infobuf[infocnt],
sizeof( infobuf ) - infocnt,
632 spob_hasService( p, SPOB_SERVICE_REFUEL )
633 ? _(
"You can refuel here" )
634 : _(
"You cannot refuel here" ),
635 spob_hasService( p, SPOB_SERVICE_BAR ) ? _(
"Has a bar" )
636 : _(
"Does not have a bar" ),
637 spob_hasService( p, SPOB_SERVICE_MISSIONS )
638 ? _(
"Offers missions" )
639 : _(
"Does not offer missions" ),
640 spob_hasService( p, SPOB_SERVICE_COMMODITY )
642 : _(
"\nDoes not have a trade outlet" ),
643 spob_hasService( p, SPOB_SERVICE_OUTFITS )
645 : _(
"\nDoes not sell ship equipment" ),
646 spob_hasService( p, SPOB_SERVICE_SHIPYARD )
648 : _(
"\nDoes not sell ships" ) );
655 ( w - nameWidth - pitch - 60 ) / 2, buf );
658 txtHeight, bx + 10 + pitch + nameWidth,
659 by + h - 10 - txtHeight, 0, &cFontWhite, -1., buf );
663 if ( infobuf[0] !=
'\0' ) {
665 &
gl_smallFont, ( w - nameWidth - pitch - 60 ) / 2, infobuf );
667 txtHeight, bx + 10 + pitch + nameWidth, by + 10, 0,
668 &cFontGrey, -1., infobuf );
682static int map_system_mouse(
unsigned int wid,
const SDL_Event *event,
683 double mx,
double my,
double w,
double h,
684 double rx,
double ry,
void *data )
690 switch ( event->type ) {
691 case SDL_MOUSEBUTTONDOWN:
693 if ( ( mx < 0. ) || ( mx > w ) || ( my < 0. ) || ( my > h ) )
695 if ( mx < pitch && my > 0 ) {
696 if ( cur_spob_sel != ( h - my ) / pitch ) {
697 cur_spob_sel = ( h - my ) / pitch;
698 map_system_updateSelected( wid );
707static void map_system_array_update(
unsigned int wid,
const char *str )
711 char buf_price[ECON_CRED_STRLEN], buf_license[STRMAX_SHORT],
712 buf_mass[ECON_MASS_STRLEN];
716 i = toolkit_getImageArrayPos( wid, str );
719 if ( ( strcmp( str, MAPSYS_OUTFITS ) == 0 ) ) {
720 Outfit *outfit = cur_spob_sel_outfits[i];
721 double mass = outfit->
mass;
726 buf_license[0] =
'\0';
728 ( cur_spobObj_sel != NULL &&
729 spob_hasService( cur_spobObj_sel,
730 SPOB_SERVICE_BLACKMARKET ) ) )
731 strncpy( buf_license, _( outfit->
license ),
732 sizeof( buf_license ) - 1 );
734 snprintf( buf_license,
sizeof( buf_license ),
"#r%s#0",
741 snprintf( buf_mass,
sizeof( buf_mass ),
742 n_(
"%d t",
"%d t", (
int)round( mass ) ), (
int)round( mass ) );
746 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"\n%s\n\n",
752 char *desc_start = &infobuf[l];
753 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"%s\n\n",
755 while ( ( desc_start = strchr( desc_start,
'\n' ) ) != NULL ) {
756 char *tab_pos = desc_start;
757 desc_start = strchr( &tab_pos[1],
'\n' );
758 if ( desc_start == NULL )
764 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"#n%s#0 %d ",
766 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"#n%s#0 %s ",
767 _(
"Mass:" ), buf_mass );
768 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"#n%s#0 %s ",
769 _(
"Price:" ), buf_price );
770 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"%s", buf_license );
771 }
else if ( ( strcmp( str, MAPSYS_SHIPS ) == 0 ) ) {
772 char buf_cargo[ECON_MASS_STRLEN];
773 ship = cur_spob_sel_ships[i];
780 strncpy( buf_license, _(
"None" ),
sizeof( buf_license ) - 1 );
782 ( cur_spobObj_sel != NULL &&
783 spob_hasService( cur_spobObj_sel,
784 SPOB_SERVICE_BLACKMARKET ) ) )
785 strncpy( buf_license, _( ship->
license ),
sizeof( buf_license ) - 1 );
787 snprintf( buf_license,
sizeof( buf_license ),
"#r%s#0",
790 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"#n%s#0 %s",
791 _(
"Model:" ), _( ship->
name ) );
792 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
" #n%s#0 %s",
794 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"\n\n%s\n",
796 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"\n#n%s#0 %s",
798 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
" #n%s#0 %d",
799 _(
"Crew:" ), ship->
crew );
801 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"\n#n%s#0 %.0f %s",
802 _(
"CPU:" ), ship->
cpu, UNIT_CPU );
803 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
" #n%s#0 %s",
804 _(
"Mass:" ), buf_mass );
805 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"\n#n%s#0 ",
807 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l, _(
"%.0f %s" ),
808 ship->
accel, UNIT_ACCEL );
809 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
" #n%s#0 ",
811 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l, _(
"%.0f %s" ),
812 ship->
speed, UNIT_SPEED );
813 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"\n#n%s#0 ",
815 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l, _(
"%.0f %s" ),
816 ship->
turn * 180. / M_PI, UNIT_ROTATION );
817 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
" #n%s#0 %.0f%%",
818 _(
"Time Constant:" ), ship->
dt_default * 100. );
820 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"\n#n%s#0 ",
821 _(
"Absorption:" ) );
822 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l, _(
"%.0f%% damage" ),
824 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"\n#n%s#0 ",
826 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
827 _(
"%.0f %s (%.1f %s)" ), ship->
shield, UNIT_ENERGY,
829 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
" #n%s#0 ",
831 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
832 _(
"%.0f %s (%.1f %s)" ), ship->
armour, UNIT_ENERGY,
834 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"\n#n%s#0 ",
836 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
837 _(
"%.0f M%s(%.1f %s)" ), ship->
energy, UNIT_ENERGY,
839 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"\n#n%s#0 %s",
840 _(
"Cargo Space:" ), buf_cargo );
841 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"\n#n%s#0 %d %s",
842 _(
"Fuel:" ), ship->
fuel, UNIT_UNIT );
843 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
" #n%s#0 %d %s",
845 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"\n#n%s#0 %s",
846 _(
"Price:" ), buf_price );
847 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
" #n%s#0 %s",
848 _(
"License:" ), buf_license );
849 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"\n%s",
851 }
else if ( ( strcmp( str, MAPSYS_TRADE ) == 0 ) ) {
855 credits_t globalmean;
857 char buf_mean[ECON_CRED_STRLEN], buf_globalmean[ECON_CRED_STRLEN];
858 char buf_std[ECON_CRED_STRLEN], buf_globalstd[ECON_CRED_STRLEN];
859 char buf_buy_price[ECON_CRED_STRLEN];
861 com = cur_spobObj_sel->commodities[i];
866 snprintf( buf_std,
sizeof( buf_std ),
"%.1f ¤",
869 snprintf( buf_globalstd,
sizeof( buf_globalstd ),
"%.1f ¤",
873 l =
scnprintf( infobuf,
sizeof( infobuf ) - l,
"%s\n\n%s\n\n",
878 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
879 n_(
"#nYou have:#0 %d tonne, purchased at %s/t\n",
880 "#nYou have:#0 %d tonnes, purchased at %s/t\n",
882 owned, buf_buy_price );
884 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
885 n_(
"#nYou have:#0 %d tonne\n",
886 "#nYou have:#0 %d tonnes\n", owned ),
889 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"#n%s#0 ",
890 _(
"Average price seen here:" ) );
892 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l, _(
"%s/t ± %s/t" ),
895 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l, _(
"%s/t ± %s/t" ),
896 _(
"??" ), _(
"??" ) );
897 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"\n#n%s#0 ",
898 _(
"Average price seen everywhere:" ) );
899 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l, _(
"%s/t ± %s/t" ),
900 buf_globalmean, buf_globalstd );
901 l +=
scnprintf( &infobuf[l],
sizeof( infobuf ) - l,
"\n%s",
"" );
903 WARN( _(
"Unexpected call to map_system_array_update\n" ) );
906void map_system_updateSelected(
unsigned int wid )
908 StarSystem *sys = cur_sys_sel;
910 int spobObjChanged = 0;
914 int noutfits, nships, ngoods;
921 for (
int i = 0; i <
array_size( sys->spobs ); i++ ) {
923 if ( spob_isKnown( p ) ) {
925 if ( textw > nameWidth )
928 if ( cur_spob_sel == nshow ) {
929 if ( cur_spobObj_sel != p )
938 if ( textw > nameWidth )
943 pitch = ( h - 100 ) / nshow;
947 if ( cur_spob_sel >= nshow ) {
948 cur_spob_sel = nshow - 1;
949 if ( cur_spobObj_sel != last ) {
950 cur_spobObj_sel = last;
954 if ( cur_spob_sel <= 0 ) {
957 if ( cur_spobObj_sel != NULL ) {
958 cur_spobObj_sel = NULL;
963 if ( spobObjChanged ) {
965 if ( cur_spobObj_sel == NULL ) {
970 window_disableButton( wid,
"btnBuyCommodPrice" );
979 ngoods =
array_size( cur_spobObj_sel->commodities );
983 spob_hasService( cur_spobObj_sel, SPOB_SERVICE_COMMODITY ) )
984 window_enableButton( wid,
"btnBuyCommodPrice" );
986 window_disableButton( wid,
"btnBuyCommodPrice" );
993 if ( noutfits != 0 ) {
999 }
else if ( nships != 0 )
1003 map_system_genOutfitsList( wid, g, o, s );
1004 map_system_genShipsList( wid, g, o, s );
1005 map_system_genTradeList( wid, g, o, s );
1014static void map_system_genOutfitsList(
unsigned int wid,
float goodsSpace,
1015 float outfitSpace,
float shipSpace )
1018 ImageArrayCell *coutfits;
1021 int xpos, xw, ypos, yh;
1023 static Spob *spobDone = NULL;
1026 if ( spobDone == cur_spobObj_sel ) {
1034 spobDone = cur_spobObj_sel;
1038 cur_spob_sel_outfits = NULL;
1041 if ( cur_spobObj_sel == NULL )
1045 if ( !spob_hasService( cur_spobObj_sel, SPOB_SERVICE_OUTFITS ) )
1049 noutfits =
array_size( cur_spob_sel_outfits );
1051 if ( noutfits <= 0 )
1054 &noutfits,
player.p, 1 );
1056 xw = ( w - nameWidth - pitch - 60 ) / 2;
1057 xpos = 35 + pitch + nameWidth + xw;
1058 i = ( goodsSpace != 0 ) + ( outfitSpace != 0 ) + ( shipSpace != 0 );
1059 yh = ( h - 100 - ( i + 1 ) * 5 ) * outfitSpace;
1060 ypos = 65 + 5 * ( shipSpace != 0 ) + ( h - 100 - ( i + 1 ) * 5 ) * shipSpace;
1063 if ( toolkit_simImageArrayVisibleElements( xw, yh, iconsize, iconsize ) <
1066 window_addImageArray( wid, xpos, ypos, xw, yh, MAPSYS_OUTFITS, iconsize,
1067 iconsize, coutfits, noutfits, map_system_array_update,
1069 toolkit_unsetSelection( wid, MAPSYS_OUTFITS );
1072static void map_system_genShipsList(
unsigned int wid,
float goodsSpace,
1073 float outfitSpace,
float shipSpace )
1075 ImageArrayCell *cships;
1077 int xpos, ypos, xw, yh;
1078 static Spob *spobDone = NULL;
1079 int i, w, h, iconsize;
1083 if ( spobDone == cur_spobObj_sel ) {
1090 cur_spob_sel_ships = NULL;
1092 assert( cur_spob_sel_ships == NULL );
1094 spobDone = cur_spobObj_sel;
1097 if ( cur_spobObj_sel == NULL )
1101 if ( !spob_hasService( cur_spobObj_sel, SPOB_SERVICE_SHIPYARD ) )
1104 cur_spob_sel_ships =
tech_getShip( cur_spobObj_sel->tech );
1110 cships = calloc( nships,
sizeof( ImageArrayCell ) );
1111 for ( i = 0; i < nships; i++ ) {
1112 cships[i].image =
ship_gfxStore( cur_spob_sel_ships[i], 256, 0., 0., 0. );
1113 cships[i].caption = strdup( _( cur_spob_sel_ships[i]->name ) );
1115 xw = ( w - nameWidth - pitch - 60 ) / 2;
1116 xpos = 35 + pitch + nameWidth + xw;
1117 i = ( goodsSpace != 0 ) + ( outfitSpace != 0 ) + ( shipSpace != 0 );
1118 yh = ( h - 100 - ( i + 1 ) * 5 ) * shipSpace;
1122 if ( toolkit_simImageArrayVisibleElements( xw, yh, iconsize, iconsize ) <
1125 window_addImageArray( wid, xpos, ypos, xw, yh, MAPSYS_SHIPS, iconsize,
1126 iconsize, cships, nships, map_system_array_update,
1128 toolkit_unsetSelection( wid, MAPSYS_SHIPS );
1131static void map_system_genTradeList(
unsigned int wid,
float goodsSpace,
1132 float outfitSpace,
float shipSpace )
1134 static Spob *spobDone = NULL;
1136 ImageArrayCell *cgoods;
1137 int xpos, ypos, xw, yh, w, h, iconsize;
1141 if ( spobDone == cur_spobObj_sel ) {
1152 if ( cur_spobObj_sel == NULL )
1156 if ( !spob_hasService( cur_spobObj_sel, SPOB_SERVICE_COMMODITY ) )
1159 spobDone = cur_spobObj_sel;
1161 ngoods =
array_size( cur_spobObj_sel->commodities );
1165 cgoods = calloc( ngoods,
sizeof( ImageArrayCell ) );
1166 for ( i = 0; i < ngoods; i++ ) {
1168 gl_dupTexture( cur_spobObj_sel->commodities[i]->gfx_store );
1169 cgoods[i].caption = strdup( _( cur_spobObj_sel->commodities[i]->name ) );
1172 xw = ( w - nameWidth - pitch - 60 ) / 2;
1173 xpos = 35 + pitch + nameWidth + xw;
1174 i = ( goodsSpace != 0 ) + ( outfitSpace != 0 ) + ( shipSpace != 0 );
1175 yh = ( h - 100 - ( i + 1 ) * 5 ) * goodsSpace;
1177 60 + 5 * i + ( h - 100 - ( i + 1 ) * 5 ) * ( outfitSpace + shipSpace );
1180 if ( toolkit_simImageArrayVisibleElements( xw, yh, iconsize, iconsize ) <
1183 window_addImageArray( wid, xpos, ypos, xw, yh, MAPSYS_TRADE, iconsize,
1184 iconsize, cgoods, ngoods, map_system_array_update,
1186 toolkit_unsetSelection( wid, MAPSYS_TRADE );
1192void map_system_buyCommodPrice(
unsigned int wid,
const char *str )
1197 StarSystem **syslist;
1199 char coststr[ECON_CRED_STRLEN];
1203 if ( ( strcmp(
cur_system->name, cur_sys_sel->name ) == 0 ) ) {
1208 map_getJumpPath(
cur_system, NULL, cur_sys_sel, 1, 0, NULL, NULL );
1209 if ( syslist == NULL ) {
1212 _(
"Commodity prices for %s are not available here at "
1214 _( cur_spobObj_sel->name ) );
1224 t -= ( njumps * 2 + 0.2 ) * NT_PERIOD_SECONDS * 1000;
1228 _(
"You need %s to purchase this information." ), coststr );
1229 else if (
array_size( cur_spobObj_sel->commodities ) == 0 )
1231 _(
"There are no commodities sold here." ) );
1232 else if ( cur_spobObj_sel->commodityPrice[0].updateTime >= t )
1234 _(
"Already Up-to-date" ),
1235 _(
"You have newer information that what is available." ) );
1238 _(
"Purchase commodity prices?" ),
1239 _(
"Purchase %g period old pricing information for %s for %s?" ),
1240 njumps * 2 + 0.2, _( cur_spobObj_sel->name ), coststr );
1243 economy_averageSeenPricesAtTime( cur_spobObj_sel, t );
1244 map_system_array_update( wid, MAPSYS_TRADE );
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
glTexture ** background_getStarTextures(void)
Returns an array (array.h) of star background images in the system background.
void background_clear(void)
Cleans up the background stuff.
glTexture * background_getAmbientTexture(void)
Returns an overall background image (nebula, for instance), or NULL if none exists.
int background_load(const char *name)
Loads a background script by name.
void credits2str(char *str, credits_t credits, int decimals)
Converts credits to a usable string for displaying.
void tonnes2str(char *str, int tonnes)
Converts tonnes to a usable string for displaying.
void price2str(char *str, credits_t price, credits_t credits, int decimals)
Given a price and on-hand credits, outputs a colourized string.
void dialogue_msg(const char *caption, const char *fmt,...)
Opens a dialogue window with an ok button and a message.
void dialogue_msgRaw(const char *caption, const char *msg)
Opens a dialogue window with an ok button and a fixed message.
int dialogue_YesNo(const char *caption, const char *fmt,...)
Runs a dialogue with both yes and no options.
int economy_getAveragePrice(const Commodity *com, credits_t *mean, double *std)
Gets the average price of a good as seen by the player (anywhere).
int economy_getAverageSpobPrice(const Commodity *com, const Spob *p, credits_t *mean, double *std)
Gets the average price of a good on a spob in a system, using a rolling average over the times the pl...
const char * faction_longname(int f)
Gets the faction's long name (formal, human-readable).
int faction_isKnown(int id)
Is the faction known?
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_shortname(int f)
Gets a factions short name (human-readable).
const char * faction_getStandingText(int f)
Gets the player's standing in human readable form.
char faction_reputationColourChar(int f)
Gets the faction character associated to its standing with the player.
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.
int gl_printTextRaw(const glFont *ft_font, const int width, const int height, double bx, double by, int line_height, const glColour *c, double outlineR, const char *text)
Prints a block of text that fits in the dimensions given.
ImageArrayCell * outfits_imageArrayCells(const Outfit **outfits, int *noutfits, const Pilot *p, int store)
Generates image array cells corresponding to outfits.
Header file with generic functions and naev-specifics.
int scnprintf(char *text, size_t maxlen, const char *fmt,...)
Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer....
ntime_t ntime_get(void)
Gets the current time.
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.
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
void gl_freeTexture(glTexture *texture)
Frees a texture.
int outfit_isLauncher(const Outfit *o)
Checks if outfit is a weapon launcher.
size_t outfit_getNameWithClass(const Outfit *outfit, char *buf, size_t size)
Gets a brief name/class description suitable for the title section of an outfitter screen.
int outfit_isFighterBay(const Outfit *o)
Checks if outfit is a fighter bay.
int outfit_amount(const Outfit *o)
Gets the amount an outfit can hold.
int pilot_cargoOwned(const Pilot *pilot, const Commodity *cargo)
Gets how many of the commodity a pilot has.
const char * pilot_outfitDescription(const Pilot *p, const Outfit *o)
Gets the description of an outfit for a given pilot.
const char * pilot_outfitSummary(const Pilot *p, const Outfit *o, int withname)
Gets the summary of an outfit for a give pilot.
int player_hasLicense(const char *license)
Checks to see if player has license.
credits_t player_modCredits(credits_t amount)
Modifies the amount of credits the player has.
int player_hasCredits(credits_t amount)
Checks to see if the player has enough credits.
int player_outfitOwned(const Outfit *o)
Gets how many of the outfit the player owns.
const char * ship_classDisplay(const Ship *s)
Gets the ship's display class in human readable form.
credits_t ship_buyPrice(const Ship *s)
The ship buy price, includes default outfits.
glTexture * ship_gfxStore(const Ship *s, int size, double dir, double updown, double glow)
Get the store gfx.
void space_gfxUnload(StarSystem *sys)
Unloads all the graphics for a star system.
StarSystem * system_getIndex(int id)
Get the system by its index.
const char * spob_name(const Spob *p)
Gets the translated name of a spob.
const char * space_populationStr(const Spob *spb)
Gets the population in an approximated string. Note this function changes the string value each call,...
void space_gfxLoad(StarSystem *sys)
Loads all the graphics for a star system.
credits_t lastPurchasePrice
A ship outfit, depends radically on the type.
union Outfit::@125206365173064275134261143013340144375262037177 u
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
Abstraction for rendering sprite sheets.
Ship ** tech_getShip(const tech_group_t *tech)
Gets all of the ships associated to a tech group.
Outfit ** tech_getOutfit(const tech_group_t *tech)
Gets all of the outfits associated to a tech group.