16#include "background.h"
22#include "land_outfits.h"
26#include "map_system.h"
36#define BUTTON_WIDTH 80
37#define BUTTON_HEIGHT 30
39static StarSystem *cur_sys_sel = NULL;
40static int cur_spob_sel = 0;
41static Spob *cur_spobObj_sel = NULL;
42static Outfit **cur_spob_sel_outfits = NULL;
43static Ship **cur_spob_sel_ships = NULL;
45static int nameWidth = 0;
47static char infobuf[STRMAX];
48static unsigned int starCnt = 1;
51#define MAP_SYSTEM_WDWNAME "wdwSystemMap"
52#define MAPSYS_OUTFITS "mapSysOutfits"
53#define MAPSYS_SHIPS "mapSysShips"
54#define MAPSYS_TRADE "mapSysTrade"
66void map_system_cleanup(
unsigned int wid,
const char *str );
67int map_system_isOpen(
void );
70void map_system_updateSelected(
unsigned int wid );
73static void map_system_render(
double bx,
double by,
double w,
double h,
void *data );
75static int map_system_mouse(
unsigned int wid, SDL_Event* event,
double mx,
double my,
76 double w,
double h,
double rx,
double ry,
void *data );
78static int map_system_keyHandler(
unsigned int wid, SDL_Keycode key, SDL_Keymod mod );
79void map_system_show(
int wid,
int x,
int y,
int w,
int h);
81static void map_system_genOutfitsList(
unsigned int wid,
float goodsSpace,
float outfitSpace,
float shipSpace );
82static void map_system_genShipsList(
unsigned int wid,
float goodsSpace,
float outfitSpace,
float shipSpace );
83static void map_system_genTradeList(
unsigned int wid,
float goodsSpace,
float outfitSpace,
float shipSpace );
85static void map_system_array_update(
unsigned int wid,
const char* str );
87void map_system_buyCommodPrice(
unsigned int wid,
const char *str );
94int map_system_init(
void )
104int map_system_load(
void )
112void map_system_exit(
void )
123void map_system_cleanup(
unsigned int wid,
const char *str )
136 cur_spob_sel_outfits = NULL;
138 cur_spob_sel_ships = NULL;
144static int map_system_keyHandler(
unsigned int wid, SDL_Keycode key, SDL_Keymod mod )
151 if (key == SDLK_UP) {
152 cur_spob_sel =
MAX( cur_spob_sel-1, 0 );
153 map_system_updateSelected( wid );
156 if (key == SDLK_DOWN) {
157 cur_spob_sel =
MIN( cur_spob_sel+1, nshow );
158 map_system_updateSelected( wid );
167void map_system_open(
int sys_selected )
178 cur_spobObj_sel = NULL;
179 memset( infobuf,0,
sizeof(infobuf) );
189 w =
MAX(600, SCREEN_W - 140);
190 h =
MAX(540, SCREEN_H - 140);
193 wid =
window_create( MAP_SYSTEM_WDWNAME, _(
"System Info"), -1, -1, w, h );
197 window_addText( wid, 40, h-30, 160, 20, 1,
"txtSysname",
198 &
gl_defFont, &cFontGreen, _(cur_sys_sel->name) );
199 window_addImage( wid, -90 + 32, h-30, 0, 0,
"imgFaction", NULL, 0 );
205 "btnBuyCommodPrice", _(
"Buy commodity price info"), map_system_buyCommodPrice );
206 window_disableButton( wid,
"btnBuyCommodPrice");
228 map_system_show( wid, 20, 60, w-40, h-100);
229 map_system_updateSelected( wid );
237int map_system_isOpen(
void)
252void map_system_show(
int wid,
int x,
int y,
int w,
int h)
254 window_addCust( wid, x, y, w, h,
255 "cstMapSys", 1, map_system_render, map_system_mouse, NULL, NULL, NULL );
268static void map_system_render(
double bx,
double by,
double w,
double h,
void *data )
273 StarSystem *sys = cur_sys_sel;
279 double ast_nb, ast_area;
282 double unknownPresence = 0;
293 if ( starCnt >= (
unsigned int)
array_size( bgImages ) ) {
304 offset = h - pitch*nshow;
307 if (!spob_isKnown( p ))
310 if (p->gfx_space == NULL)
311 WARN( _(
"No gfx for %s…"),p->name );
315 if (p->gfx_space->w > p->gfx_space->h)
316 ih = ih * p->gfx_space->h / p->gfx_space->w;
317 else if ( p->gfx_space->w < p->gfx_space->h )
318 iw = iw * p->gfx_space->w / p->gfx_space->h;
319 gl_renderScale( p->gfx_space, bx+(pitch-iw)/2+2, by+(nshow-vis_index-1)*pitch + (pitch-ih)/2 + offset, iw, ih, &cWhite );
322 (cur_spob_sel == vis_index ? &cFontGreen : &cFontWhite), -1.,
spob_name(p) );
328 if ( bgImages[starCnt]->w > bgImages[starCnt]->h )
329 ih = ih * bgImages[starCnt]->
h / bgImages[starCnt]->
w;
330 else if ( bgImages[starCnt]->w < bgImages[starCnt]->h )
331 iw = iw * bgImages[starCnt]->
w / bgImages[starCnt]->
h;
332 ccol.r=ccol.g=ccol.b=ccol.a=1;
333 if ( phase > 120 &&
array_size( bgImages ) > 2 )
334 ccol.a = cos ( (phase-121)/30. *M_PI/2.);
335 gl_renderScale( bgImages[starCnt], bx+2 , by+(nshow-1)*pitch + (pitch-ih)/2 + offset, iw , ih, &ccol );
336 if ( phase > 120 &&
array_size( bgImages ) > 2) {
347 if ( bgImages[i]->w > bgImages[i]->h )
348 ih = ih * bgImages[i]->
h / bgImages[i]->
w;
349 else if ( bgImages[i]->w < bgImages[i]->h )
350 iw = iw * bgImages[i]->
w / bgImages[i]->
h;
352 gl_renderScale( bgImages[i], bx+2, by+(nshow-1)*pitch + (pitch-ih)/2 + offset, iw, ih, &ccol );
359 (by + (nshow-0.5)*pitch + offset), 0, &cFontRed, -1., _(
"Obscured by the nebula") );
362 (cur_spob_sel == 0 ? &cFontGreen : &cFontWhite), -1., _(sys->name) );
363 if ((cur_spob_sel==0) &&
array_size( bgImages ) > 0) {
366 iw = w - 50 - pitch - nameWidth;
368 imgw = bgImages[0]->
w;
369 imgh = bgImages[0]->
h;
370 s =
MIN( iw / imgw, ih / imgh );
373 gl_renderScale( bgImages[0], bx+w-iw+(iw-imgw)*0.5, by+h-ih+(ih-imgh)*0.5, imgw, imgh, &cWhite );
376 ccol.r=0; ccol.g=0.6+0.4*sin( phase/150.*2*M_PI ); ccol.b=0; ccol.a=1;
379 gl_renderRect( bx+1, by+(nshow-cur_spob_sel-1)*pitch + offset, iw, ih, &ccol );
380 gl_renderRect( bx+1, by+(nshow-cur_spob_sel)*pitch-ih + offset, iw, ih, &ccol );
381 gl_renderRect( bx+pitch+3-iw, by+(nshow-cur_spob_sel-1)*pitch + offset, iw, ih, &ccol );
382 gl_renderRect( bx+pitch+3-iw, by+(nshow-cur_spob_sel)*pitch-ih + offset, iw, ih, &ccol );
383 gl_renderRect( bx+1, by+(nshow-cur_spob_sel-1)*pitch + offset, ih, iw, &ccol );
384 gl_renderRect( bx+1, by+(nshow-cur_spob_sel)*pitch-iw + offset, ih, iw, &ccol );
385 gl_renderRect( bx+pitch+3-ih, by+(nshow-cur_spob_sel-1)*pitch + offset, ih, iw, &ccol );
386 gl_renderRect( bx+pitch+3-ih, by+(nshow-cur_spob_sel)*pitch-iw + offset, ih, iw, &ccol );
389 if (cur_spob_sel == 0) {
392 cnt+=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"System: %s\n"), _(sys->name) );
394 cnt+=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, n_(
"%d-star system\n",
"%d-star system\n", stars), stars );
397 if (sys->nebu_density > 0. ) {
399 if (sys->nebu_volatility > 700.)
400 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"Nebula: Volatile, ") );
401 else if (sys->nebu_volatility > 300.)
402 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"Nebula: Dangerous, ") );
403 else if (sys->nebu_volatility > 0.)
404 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"Nebula: Unstable, ") );
406 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"Nebula: Stable, ") );
409 if (sys->nebu_density > 700.)
410 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"Dense\n") );
411 else if (sys->nebu_density < 300.)
412 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"Light\n") );
414 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"Medium\n") );
416 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"Nebula: None\n") );
419 if (sys->interference > 0. ) {
420 if (sys->interference > 700.)
421 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"Interference: Dense\n") );
422 else if (sys->interference < 300.)
423 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"Interference: Light\n") );
427 ast_nb = ast_area = 0.;
428 for ( i=0; i<
array_size(sys->asteroids); i++ ) {
429 ast_nb += sys->asteroids[i].nb;
430 ast_area =
MAX( ast_area, sys->asteroids[i].area );
432 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"Asteroid field density: %.2g\n"), ast_nb*ASTEROID_REF_AREA/ast_area );
437 if (spob_isKnown( sys->spobs[i] )) {
438 if ((f==-1) && (sys->spobs[i]->presence.faction>=0) ) {
439 f = sys->spobs[i]->presence.faction;
440 }
else if (f != sys->spobs[i]->presence.faction && (sys->spobs[i]->presence.faction>=0) ) {
441 cnt+=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"Faction: Multiple\n") );
447 cnt+=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"Faction: N/A\n") );
453 if ( logo != NULL ) {
455 by + h - 21, 20, 20, &cWhite );
461 for ( i=0; i <
array_size(sys->presence); i++ ) {
462 if (sys->presence[i].value <= 0)
467 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
"#0%s: #%c%.0f\n",
469 t, sys->presence[i].value);
471 unknownPresence += sys->presence[i].value;
473 if (unknownPresence != 0)
474 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt,
"#0%s: #%c%.0f\n",
475 _(
"Unknown"),
'N', unknownPresence );
476 if (hasPresence == 0)
477 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"Presence: N/A\n"));
480 bx + 10 + pitch + nameWidth, by + h - 10 - txtHeight, 0, &cFontWhite, -1., buf );
484 if (jp_isUsable ( &sys->jumps[i])) {
486 infopos =
scnprintf( infobuf,
sizeof(infobuf), _(
" Jump points to:\n") );
487 if (sys_isKnown( sys->jumps[i].target ))
488 infopos +=
scnprintf( &infobuf[infopos],
sizeof(infobuf)-infopos,
" %s\n", _(sys->jumps[i].target->name) );
490 infopos +=
scnprintf( &infobuf[infopos],
sizeof(infobuf)-infopos, _(
" Unknown system\n") );
496 if (p->presence.faction >= 0 ) {
500 gl_renderScale( logo, bx + pitch + nameWidth + 200, by + h - 21, 20, 20, &cWhite );
504 bx+pitch+nameWidth + 230, by + h - 31, 0, &cFontWhite, -1., factionBuf );
508 if (!spob_hasService( p, SPOB_SERVICE_INHABITED ))
509 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"No space port here\n") );
510 else if (p->can_land)
511 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt,
"#g%s#0", _(
"You can land here\n") );
512 else if (
areEnemies( FACTION_PLAYER, p->presence.faction))
513 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt,
"#o%s#0", _(
"Not advisable to land here\n") );
515 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt,
"#r%s#0", _(
"You cannot land here\n") );
517 if (infobuf[0]==
'\0') {
521 infocnt +=
scnprintf( &infobuf[infocnt],
sizeof(infobuf)-infocnt,
"%s\n\n", (p->description==NULL?_(
"No description available"):_(p->description)) );
524 infocnt +=
scnprintf( &infobuf[infocnt],
sizeof(infobuf)-infocnt,
"%s\n"
525 "%s\n%s\n%s\n%s\n%s\n%s\n%s",
526 spob_hasService( p, SPOB_SERVICE_LAND) ? _(
"This system is landable") : _(
"This system is not landable"),
527 spob_hasService( p, SPOB_SERVICE_INHABITED) ? _(
"This system is inhabited") : _(
"This system is not inhabited"),
528 spob_hasService( p, SPOB_SERVICE_REFUEL) ? _(
"You can refuel here") : _(
"You cannot refuel here"),
529 spob_hasService( p, SPOB_SERVICE_BAR) ? _(
"This system has a bar") : _(
"This system does not have a bar"),
530 spob_hasService( p, SPOB_SERVICE_MISSIONS) ? _(
"This system offers missions") : _(
"This system does not offer missions"),
531 spob_hasService( p, SPOB_SERVICE_COMMODITY) ? _(
"This system has a trade outlet") : _(
"This system does not have a trade outlet"),
532 spob_hasService( p, SPOB_SERVICE_OUTFITS) ? _(
"This system sells ship equipment") : _(
"This system does not sell ship equipment"),
533 spob_hasService( p, SPOB_SERVICE_SHIPYARD) ? _(
"This system sells ships") : _(
"This system does not sell ships"));
534 if (p->bar_description && spob_hasService( p, SPOB_SERVICE_BAR ))
535 infocnt +=
scnprintf( &infobuf[infocnt],
sizeof(infobuf)-infocnt,
"\n\n%s", _(p->bar_description) );
541 bx + 10 + pitch + nameWidth, by + h - 10 - txtHeight, 0, &cFontWhite, -1., buf );
545 if (infobuf[0]!=
'\0') {
548 bx + 10 + pitch + nameWidth, by + 10, 0, &cFontGrey, -1., infobuf );
562static int map_system_mouse(
unsigned int wid, SDL_Event* event,
double mx,
double my,
563 double w,
double h,
double rx,
double ry,
void *data )
569 switch (event->type) {
570 case SDL_MOUSEBUTTONDOWN:
572 if ((mx < 0.) || (mx > w) || (my < 0.) || (my > h))
574 if (mx < pitch && my > 0) {
575 if (cur_spob_sel != (h-my) / pitch) {
576 cur_spob_sel = ( h-my) / pitch;
577 map_system_updateSelected( wid );
586static void map_system_array_update(
unsigned int wid,
const char* str )
590 char buf_price[ECON_CRED_STRLEN], buf_license[STRMAX_SHORT], buf_mass[ECON_MASS_STRLEN];
594 i = toolkit_getImageArrayPos( wid, str );
597 if ((strcmp( str, MAPSYS_OUTFITS ) == 0)) {
598 Outfit *outfit = cur_spob_sel_outfits[i];
599 double mass = outfit->
mass;
604 buf_license[0] =
'\0';
606 (cur_spobObj_sel != NULL && spob_hasService( cur_spobObj_sel, SPOB_SERVICE_BLACKMARKET )))
607 strncpy( buf_license, _(outfit->
license),
sizeof(buf_license)-1 );
609 snprintf( buf_license,
sizeof( buf_license ),
"#r%s#0", _(outfit->
license) );
615 snprintf( buf_mass,
sizeof(buf_mass), n_(
"%d t",
"%d t", (
int)round( mass ) ), (
int)round( mass ) );
622 char *desc_start = &infobuf[l];
624 while ( (desc_start = strchr( desc_start,
'\n' )) != NULL ) {
625 char *tab_pos = desc_start;
626 desc_start = strchr( &tab_pos[1],
'\n' );
627 if (desc_start == NULL)
634 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"#n%s#0 %s ", _(
"Mass:"), buf_mass );
635 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"#n%s#0 %s ", _(
"Price:"), buf_price );
636 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"%s", buf_license );
638 else if ((strcmp( str, MAPSYS_SHIPS ) == 0)) {
639 char buf_cargo[ECON_MASS_STRLEN];
640 ship = cur_spob_sel_ships[i];
644 tonnes2str( buf_mass, ship->
mass );
645 tonnes2str( buf_cargo, ship->
cap_cargo );
647 strncpy( buf_license, _(
"None"),
sizeof(buf_license)-1 );
649 || (cur_spobObj_sel != NULL && spob_hasService( cur_spobObj_sel, SPOB_SERVICE_BLACKMARKET )))
650 strncpy( buf_license, _(ship->
license),
sizeof(buf_license)-1 );
652 snprintf( buf_license,
sizeof(buf_license),
"#r%s#0", _(ship->
license) );
654 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"#n%s#0 %s", _(
"Model:"), _(ship->
name) );
657 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 %s", _(
"Fabricator:"), _(ship->
fabricator) );
658 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
" #n%s#0 %d", _(
"Crew:"), ship->
crew );
660 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 %.0f %s", _(
"CPU:"), ship->
cpu, n_(
"teraflop",
"teraflops", ship->
cpu ) );
661 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
" #n%s#0 %s", _(
"Mass:"), buf_mass );
662 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 ", _(
"Thrust:") );
663 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, _(
"%.0f kN/tonne"), ship->
thrust );
664 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
" #n%s#0 ", _(
"Speed:") );
665 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, _(
"%.0f m/s"), ship->
speed );
666 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 ", _(
"Turn:") );
667 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, _(
"%.0f deg/s"), ship->
turn*180./M_PI );
668 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
" #n%s#0 %.0f%%", _(
"Time Constant:"), ship->
dt_default*100. );
670 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 ", _(
"Absorption:") );
671 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, _(
"%.0f%% damage"), ship->
dmg_absorb*100. );
672 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 ", _(
"Shield:") );
674 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
" #n%s#0 ", _(
"Armour:") );
676 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 ", _(
"Energy:") );
678 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 %s", _(
"Cargo Space:"), buf_cargo );
679 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 %d %s", _(
"Fuel:"), ship->
fuel, n_(
"unit",
"units", ship->
fuel ) );
680 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
" #n%s#0 %d %s", _(
"Fuel Use:"),
682 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 %s", _(
"Price:"), buf_price );
683 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
" #n%s#0 %s", _(
"License:"), buf_license );
686 else if ((strcmp( str, MAPSYS_TRADE ) == 0)) {
690 credits_t globalmean;
692 char buf_mean[ECON_CRED_STRLEN], buf_globalmean[ECON_CRED_STRLEN];
693 char buf_std[ECON_CRED_STRLEN], buf_globalstd[ECON_CRED_STRLEN];
694 char buf_buy_price[ECON_CRED_STRLEN];
699 credits2str( buf_mean, mean, -1 );
700 snprintf( buf_std,
sizeof(buf_std),
"%.1f ¤", std );
701 credits2str( buf_globalmean, globalmean, -1 );
702 snprintf( buf_globalstd,
sizeof(buf_globalstd),
"%.1f ¤", globalstd );
709 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, n_(
710 "#nYou have:#0 %d tonne, purchased at %s/t\n",
711 "#nYou have:#0 %d tonnes, purchased at %s/t\n",
712 owned), owned, buf_buy_price );
715 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, n_(
716 "#nYou have:#0 %d tonne\n",
717 "#nYou have:#0 %d tonnes\n",
720 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"#n%s#0 ", _(
"Average price seen here:") );
721 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, _(
"%s/t ± %s/t"), buf_mean, buf_std );
722 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 ", _(
"Average price seen everywhere:") );
723 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, _(
"%s/t ± %s/t"), buf_globalmean, buf_globalstd );
724 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n%s",
"" );
727 WARN( _(
"Unexpected call to map_system_array_update\n") );
730void map_system_updateSelected(
unsigned int wid )
732 StarSystem *sys=cur_sys_sel;
734 int spobObjChanged = 0;
738 int noutfits,nships,ngoods;
745 for (
int i=0; i<
array_size(sys->spobs); i++) {
747 if (spob_isKnown( p )) {
749 if ( textw > nameWidth )
752 if ( cur_spob_sel == nshow ) {
753 if ( cur_spobObj_sel != p )
762 if ( textw > nameWidth )
767 pitch = (h-100) / nshow;
771 if ( cur_spob_sel >= nshow ) {
772 cur_spob_sel = nshow-1;
773 if ( cur_spobObj_sel != last ) {
774 cur_spobObj_sel = last;
778 if ( cur_spob_sel <= 0 ) {
781 if ( cur_spobObj_sel != NULL ) {
782 cur_spobObj_sel = NULL;
787 if ( spobObjChanged ) {
789 if ( cur_spobObj_sel == NULL ) {
794 window_disableButton( wid,
"btnBuyCommodPrice" );
805 if (
landed && spob_hasService( cur_spobObj_sel, SPOB_SERVICE_COMMODITY ) )
806 window_enableButton( wid,
"btnBuyCommodPrice" );
808 window_disableButton( wid,
"btnBuyCommodPrice" );
815 if ( noutfits != 0 ) {
821 }
else if ( nships!=0 )
825 map_system_genOutfitsList( wid, g, o, s );
826 map_system_genShipsList( wid, g, o, s );
827 map_system_genTradeList( wid, g, o, s );
836static void map_system_genOutfitsList(
unsigned int wid,
float goodsSpace,
float outfitSpace,
float shipSpace )
839 ImageArrayCell *coutfits;
842 int xpos, xw, ypos, yh;
844 static Spob *spobDone = NULL;
847 if (spobDone == cur_spobObj_sel) {
855 spobDone = cur_spobObj_sel;
859 cur_spob_sel_outfits = NULL;
862 if (cur_spobObj_sel == NULL)
866 if (!spob_hasService( cur_spobObj_sel, SPOB_SERVICE_OUTFITS ))
870 noutfits =
array_size( cur_spob_sel_outfits );
876 xw = ( w - nameWidth - pitch - 60 ) / 2;
877 xpos = 35 + pitch + nameWidth + xw;
878 i = (goodsSpace!=0) + (outfitSpace!=0) + (shipSpace!=0);
879 yh = (h - 100 - (i+1)*5 ) * outfitSpace;
880 ypos = 65 + 5*(shipSpace!=0) + (h - 100 - (i+1)*5)*shipSpace;
883 if (toolkit_simImageArrayVisibleElements( xw, yh, iconsize, iconsize ) < noutfits)
885 window_addImageArray( wid, xpos, ypos,
886 xw, yh, MAPSYS_OUTFITS, iconsize, iconsize,
887 coutfits, noutfits, map_system_array_update, NULL, NULL );
888 toolkit_unsetSelection( wid, MAPSYS_OUTFITS );
891static void map_system_genShipsList(
unsigned int wid,
float goodsSpace,
float outfitSpace,
float shipSpace )
893 ImageArrayCell *cships;
895 int xpos, ypos, xw, yh;
896 static Spob *spobDone=NULL;
897 int i, w, h, iconsize;
901 if (spobDone == cur_spobObj_sel) {
909 cur_spob_sel_ships = NULL;
911 assert(cur_spob_sel_ships == NULL);
913 spobDone = cur_spobObj_sel;
916 if (cur_spobObj_sel == NULL)
920 if (!spob_hasService( cur_spobObj_sel, SPOB_SERVICE_SHIPYARD ))
929 cships = calloc( nships,
sizeof(ImageArrayCell) );
930 for ( i=0; i<nships; i++ ) {
931 cships[i].image =
gl_dupTexture( cur_spob_sel_ships[i]->gfx_store );
932 cships[i].caption = strdup( _(cur_spob_sel_ships[i]->name) );
934 xw = (w - nameWidth - pitch - 60)/2;
935 xpos = 35 + pitch + nameWidth + xw;
936 i = (goodsSpace!=0) + (outfitSpace!=0) + (shipSpace!=0);
937 yh = (h - 100 - (i+1)*5 ) * shipSpace;
941 if (toolkit_simImageArrayVisibleElements( xw, yh, iconsize, iconsize ) < nships )
943 window_addImageArray( wid, xpos, ypos,
944 xw, yh, MAPSYS_SHIPS, iconsize, iconsize,
945 cships, nships, map_system_array_update, NULL, NULL );
946 toolkit_unsetSelection( wid, MAPSYS_SHIPS );
949static void map_system_genTradeList(
unsigned int wid,
float goodsSpace,
float outfitSpace,
float shipSpace )
951 static Spob *spobDone=NULL;
953 ImageArrayCell *cgoods;
954 int xpos, ypos, xw, yh, w, h, iconsize;
958 if ( spobDone == cur_spobObj_sel ) {
969 if (cur_spobObj_sel == NULL)
973 if (!spob_hasService( cur_spobObj_sel, SPOB_SERVICE_COMMODITY ))
976 spobDone = cur_spobObj_sel;
982 cgoods = calloc( ngoods,
sizeof(ImageArrayCell) );
983 for ( i=0; i<ngoods; i++ ) {
985 cgoods[i].caption = strdup( _(cur_spobObj_sel->
commodities[i]->
name) );
988 xw = (w - nameWidth - pitch - 60)/2;
989 xpos = 35 + pitch + nameWidth + xw;
990 i = (goodsSpace!=0) + (outfitSpace!=0) + (shipSpace!=0);
991 yh = (h - 100 - (i+1)*5 ) * goodsSpace;
992 ypos = 60 + 5*i + (h-100 - (i+1)*5 )*(outfitSpace + shipSpace);
995 if (toolkit_simImageArrayVisibleElements( xw, yh, iconsize, iconsize ) < ngoods )
997 window_addImageArray( wid, xpos, ypos,
998 xw, yh, MAPSYS_TRADE, iconsize, iconsize,
999 cgoods, ngoods, map_system_array_update, NULL, NULL );
1000 toolkit_unsetSelection( wid, MAPSYS_TRADE );
1006void map_system_buyCommodPrice(
unsigned int wid,
const char *str )
1011 StarSystem **syslist;
1013 char coststr[ECON_CRED_STRLEN];
1017 if ((strcmp(
cur_system->name, cur_sys_sel->name ) == 0)) {
1022 syslist=map_getJumpPath(
cur_system->name, cur_sys_sel->name, 1, 0, NULL);
1023 if ( syslist == NULL ) {
1025 dialogue_msg( _(
"Unavailable"), _(
"Commodity prices for %s are not available here at the moment."), _(cur_spobObj_sel->
name) );
1034 t -= ( njumps * 2 + 0.2 ) * NT_PERIOD_SECONDS * 1000;
1035 credits2str( coststr, cost, -1 );
1037 dialogue_msg( _(
"Insufficient Credits"), _(
"You need %s to purchase this information."), coststr );
1039 dialogue_msgRaw( _(
"No commodities sold here"),_(
"There are no commodities sold here."));
1041 dialogue_msgRaw( _(
"Already Up-to-date"), _(
"You have newer information that what is available.") );
1043 int ret =
dialogue_YesNo( _(
"Purchase commodity prices?"), _(
"Purchase %g period old pricing information for %s for %s?"),
1044 njumps*2+0.2, _(cur_spobObj_sel->
name), coststr );
1047 economy_averageSeenPricesAtTime( cur_spobObj_sel, t );
1048 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_getTextures(void)
returns the background images, and number of these
void background_clear(void)
Cleans up the background stuff.
int background_load(const char *name)
Loads a background script by name.
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?
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_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.
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)
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.
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 * space_populationStr(uint64_t population)
Gets the population in an approximated string. Note this function changes the string value each call,...
const char * spob_name(const Spob *p)
Gets the translated name of a spob.
void space_gfxLoad(StarSystem *sys)
Loads all the graphics for a star system.
credits_t lastPurchasePrice
A ship outfit, depends radically on the type.
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
CommodityPrice * commodityPrice
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.