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 focusedStar = 0;
52#define MAP_SYSTEM_WDWNAME "wdwSystemMap"
53#define MAPSYS_OUTFITS "mapSysOutfits"
54#define MAPSYS_SHIPS "mapSysShips"
55#define MAPSYS_TRADE "mapSysTrade"
67void map_system_cleanup(
unsigned int wid,
const char *str );
68int map_system_isOpen(
void );
71void map_system_updateSelected(
unsigned int wid );
74static void map_system_render(
double bx,
double by,
double w,
double h,
void *data );
76static int map_system_mouse(
unsigned int wid,
const SDL_Event* event,
double mx,
double my,
77 double w,
double h,
double rx,
double ry,
void *data );
79static int map_system_keyHandler(
unsigned int wid, SDL_Keycode key, SDL_Keymod mod,
int isrepeat );
80void map_system_show(
int wid,
int x,
int y,
int w,
int h);
82static void map_system_genOutfitsList(
unsigned int wid,
float goodsSpace,
float outfitSpace,
float shipSpace );
83static void map_system_genShipsList(
unsigned int wid,
float goodsSpace,
float outfitSpace,
float shipSpace );
84static void map_system_genTradeList(
unsigned int wid,
float goodsSpace,
float outfitSpace,
float shipSpace );
86static void map_system_array_update(
unsigned int wid,
const char* str );
88void map_system_buyCommodPrice(
unsigned int wid,
const char *str );
95int map_system_init(
void )
105int map_system_load(
void )
113void map_system_exit(
void )
122 cur_spob_sel_outfits = NULL;
124 cur_spob_sel_ships = NULL;
130void map_system_cleanup(
unsigned int wid,
const char *str )
144static int map_system_keyHandler(
unsigned int wid, SDL_Keycode key, SDL_Keymod mod,
int isrepeat )
152 if (key == SDLK_UP) {
153 cur_spob_sel =
MAX( cur_spob_sel-1, 0 );
154 map_system_updateSelected( wid );
157 if (key == SDLK_DOWN) {
158 cur_spob_sel =
MIN( cur_spob_sel+1, nshow );
159 map_system_updateSelected( wid );
168void map_system_open(
int sys_selected )
179 cur_spobObj_sel = NULL;
180 memset( infobuf,0,
sizeof(infobuf) );
190 w =
MAX(600, SCREEN_W - 140);
191 h =
MAX(540, SCREEN_H - 140);
194 wid =
window_create( MAP_SYSTEM_WDWNAME, _(
"System Info"), -1, -1, w, h );
198 window_addText( wid, 40, h-30, 160, 20, 1,
"txtSysname",
199 &
gl_defFont, &cFontGreen, _(cur_sys_sel->name) );
200 window_addImage( wid, -90 + 32, h-30, 0, 0,
"imgFaction", NULL, 0 );
202 window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
205 window_addButton( wid, -40-BUTTON_WIDTH, 20, BUTTON_WIDTH*3, BUTTON_HEIGHT,
206 "btnBuyCommodPrice", _(
"Buy commodity price info"), map_system_buyCommodPrice );
207 window_disableButton( wid,
"btnBuyCommodPrice");
229 map_system_show( wid, 20, 60, w-40, h-100);
230 map_system_updateSelected( wid );
238int map_system_isOpen(
void)
253void map_system_show(
int wid,
int x,
int y,
int w,
int h)
255 window_addRect( wid, x, y, w, h,
"rctMapSys", &cBlack, 0 );
256 window_addCust( wid, x, y, w, h,
257 "cstMapSys", 1, map_system_render, map_system_mouse, NULL, NULL, NULL );
258 window_custSetDynamic( wid,
"cstMapSys", 1 );
271static void map_system_render(
double bx,
double by,
double w,
double h,
void *data )
276 StarSystem *sys = cur_sys_sel;
282 double ast_nb, ast_area;
285 double unknownPresence = 0;
292 offset = h - pitch*nshow;
295 if (!spob_isKnown( p ))
298 if (p->gfx_space == NULL)
299 WARN( _(
"No gfx for %s…"),p->name );
303 if (p->gfx_space->w > p->gfx_space->h)
304 ih = ih * p->gfx_space->h / p->gfx_space->w;
305 else if ( p->gfx_space->w < p->gfx_space->h )
306 iw = iw * p->gfx_space->w / p->gfx_space->h;
307 gl_renderScale( p->gfx_space, bx+(pitch-iw)/2+2, by+(nshow-vis_index-1)*pitch + (pitch-ih)/2 + offset, iw, ih, &cWhite );
310 (cur_spob_sel == vis_index ? &cFontGreen : &cFontWhite), -1.,
spob_name(p) );
323 if ( starImages[focusedStar]->w > starImages[focusedStar]->h )
324 ih = ih * starImages[focusedStar]->
h / starImages[focusedStar]->
w;
325 else if ( starImages[focusedStar]->w < starImages[focusedStar]->h )
326 iw = iw * starImages[focusedStar]->
w / starImages[focusedStar]->
h;
327 ccol.r=ccol.g=ccol.b=ccol.a=1;
328 if (phase > 120 &&
array_size( starImages ) > 1)
329 ccol.a = cos ( (phase-121)/30. *M_PI/2.);
330 gl_renderScale( starImages[focusedStar], bx+2 , by+(nshow-1)*pitch + (pitch-ih)/2 + offset, iw , ih, &ccol );
331 if (phase > 120 &&
array_size( starImages ) > 1) {
335 i = (focusedStar + 1) %
array_size( starImages );
336 if ( starImages[i]->w > starImages[i]->h )
337 ih = ih * starImages[i]->
h / starImages[i]->
w;
338 else if ( starImages[i]->w < starImages[i]->h )
339 iw = iw * starImages[i]->
w / starImages[i]->
h;
341 gl_renderScale( starImages[i], bx+2, by+(nshow-1)*pitch + (pitch-ih)/2 + offset, iw, ih, &ccol );
344 else if (sys->nebu_density > 0.) {
348 (by + (nshow-0.5)*pitch + offset), 0, &cFontRed, -1., _(
"Obscured by the nebula") );
351 (cur_spob_sel == 0 ? &cFontGreen : &cFontWhite), -1., _(sys->name) );
352 if ((cur_spob_sel==0) && bgImage != NULL) {
354 iw = w - 50 - pitch - nameWidth;
358 s =
MIN( iw / imgw, ih / imgh );
361 gl_renderScale( bgImage, bx+w-iw+(iw-imgw)*0.5, by+h-ih+(ih-imgh)*0.5, imgw, imgh, &cWhite );
364 ccol.r=0; ccol.g=0.6+0.4*sin( phase/150.*2*M_PI ); ccol.b=0; ccol.a=1;
367 gl_renderRect( bx+1, by+(nshow-cur_spob_sel-1)*pitch + offset, iw, ih, &ccol );
368 gl_renderRect( bx+1, by+(nshow-cur_spob_sel)*pitch-ih + offset, iw, ih, &ccol );
369 gl_renderRect( bx+pitch+3-iw, by+(nshow-cur_spob_sel-1)*pitch + offset, iw, ih, &ccol );
370 gl_renderRect( bx+pitch+3-iw, by+(nshow-cur_spob_sel)*pitch-ih + offset, iw, ih, &ccol );
371 gl_renderRect( bx+1, by+(nshow-cur_spob_sel-1)*pitch + offset, ih, iw, &ccol );
372 gl_renderRect( bx+1, by+(nshow-cur_spob_sel)*pitch-iw + offset, ih, iw, &ccol );
373 gl_renderRect( bx+pitch+3-ih, by+(nshow-cur_spob_sel-1)*pitch + offset, ih, iw, &ccol );
374 gl_renderRect( bx+pitch+3-ih, by+(nshow-cur_spob_sel)*pitch-iw + offset, ih, iw, &ccol );
377 if (cur_spob_sel == 0) {
380 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"#nSystem:#0 %s\n"), _(sys->name) );
382 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, n_(
"%d-star system\n",
"%d-star system\n", stars), stars );
385 if (sys->nebu_density > 0. ) {
386 double dmg = sys->nebu_volatility;
387 const char *sdmg, *adj;
392 sdmg = p_(
"nebula",
"Volatile");
394 else if (sys->nebu_volatility > 20.) {
396 sdmg = p_(
"nebula",
"Dangerous");
398 else if (sys->nebu_volatility > 0.) {
400 sdmg = p_(
"nebula",
"Unstable");
404 sdmg = p_(
"nebula",
"Stable");
408 if (sys->nebu_density > 700.)
409 adj = p_(
"nebula",
"Dense ");
410 else if (sys->nebu_density < 300.)
411 adj = p_(
"nebula",
"Light ");
415 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"#nNebula: #%c%s%s (%.1f %s)#0\n"), col, adj, sdmg, dmg, UNIT_POWER );
419 if (sys->interference > 0. ) {
420 double itf = sys->interference;
425 sint = p_(
"interference",
"Dense");
427 else if (itf > 300.) {
429 sint = p_(
"interference",
"Medium");
433 sint = p_(
"interference",
"Light");
435 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"#nInterference: #%c%s (%.0f%%)#0\n"), col, sint, itf );
439 ast_nb = ast_area = 0.;
440 for (i=0; i<
array_size(sys->asteroids); i++) {
441 ast_nb += sys->asteroids[i].nb;
442 ast_area =
MAX( ast_area, sys->asteroids[i].area );
444 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"#nAsteroid field density:#0 %.2g\n"), ast_nb*ASTEROID_REF_AREA/ast_area );
447 if (sys->features != NULL)
448 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"#nOther:#0 %s\n"), _(sys->features) );
452 if (spob_isKnown( sys->spobs[i] )) {
453 if ((f==-1) && (sys->spobs[i]->presence.faction>=0) ) {
454 f = sys->spobs[i]->presence.faction;
455 }
else if (f != sys->spobs[i]->presence.faction && (sys->spobs[i]->presence.faction>=0) ) {
456 cnt+=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"#nFaction:#0 Multiple\n") );
462 cnt+=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"#nFaction:#0 N/A\n") );
468 if ( logo != NULL ) {
470 by + h - 21, 20, 20, &cWhite );
476 for ( i=0; i <
array_size(sys->presence); i++ ) {
477 if (sys->presence[i].value <= 0)
482 cnt +=
scnprintf( &buf[cnt],
sizeof( buf ) - cnt,
"#n%s: #%c%.0f\n",
484 t, sys->presence[i].value);
486 unknownPresence += sys->presence[i].value;
488 if (unknownPresence != 0)
489 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt,
"#n%s: #%c%.0f\n",
490 _(
"Unknown"),
'N', unknownPresence );
491 if (hasPresence == 0)
492 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"#nPresence:#0 N/A\n"));
495 bx + 10 + pitch + nameWidth, by + h - 10 - txtHeight, 0, &cFontWhite, -1., buf );
499 if (jp_isUsable ( &sys->jumps[i])) {
501 infopos =
scnprintf( infobuf,
sizeof(infobuf), _(
" #nJump points to:#0\n") );
502 if (sys_isKnown( sys->jumps[i].target ))
503 infopos +=
scnprintf( &infobuf[infopos],
sizeof(infobuf)-infopos,
" %s\n", _(sys->jumps[i].target->name) );
505 infopos +=
scnprintf( &infobuf[infopos],
sizeof(infobuf)-infopos, _(
" Unknown system\n") );
511 if (p->presence.faction >= 0 ) {
515 gl_renderScale( logo, bx + pitch + nameWidth + 200, by + h - 21, 20, 20, &cWhite );
519 bx+pitch+nameWidth + 230, by + h - 31, 0, &cFontWhite, -1., factionBuf );
523 if (!spob_hasService( p, SPOB_SERVICE_INHABITED ))
524 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt, _(
"No space port here\n") );
525 else if (p->can_land)
526 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt,
"#g%s#0", _(
"You can land here\n") );
527 else if (
areEnemies( FACTION_PLAYER, p->presence.faction))
528 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt,
"#o%s#0", _(
"Not advisable to land here\n") );
530 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt,
"#r%s#0", _(
"You cannot land here\n") );
533 if (p->feature != NULL)
534 cnt +=
scnprintf( &buf[cnt],
sizeof(buf)-cnt,
"%s\n", _(p->feature) );
536 if (infobuf[0]==
'\0') {
540 infocnt +=
scnprintf( &infobuf[infocnt],
sizeof(infobuf)-infocnt,
"%s\n\n", (p->description==NULL?_(
"No description available"):_(p->description)) );
543 infocnt +=
scnprintf( &infobuf[infocnt],
sizeof(infobuf)-infocnt,
"%s\n"
548 spob_hasService( p, SPOB_SERVICE_REFUEL) ? _(
"You can refuel here") : _(
"You cannot refuel here"),
549 spob_hasService( p, SPOB_SERVICE_BAR) ? _(
"Has a bar") : _(
"Does not have a bar"),
550 spob_hasService( p, SPOB_SERVICE_MISSIONS) ? _(
"Offers missions") : _(
"Does not offer missions"),
551 spob_hasService( p, SPOB_SERVICE_COMMODITY) ?
"" : _(
"\nDoes not have a trade outlet"),
552 spob_hasService( p, SPOB_SERVICE_OUTFITS) ?
"" : _(
"\nDoes not sell ship equipment"),
553 spob_hasService( p, SPOB_SERVICE_SHIPYARD) ?
"" : _(
"\nDoes not sell ships"));
561 bx + 10 + pitch + nameWidth, by + h - 10 - txtHeight, 0, &cFontWhite, -1., buf );
565 if (infobuf[0]!=
'\0') {
568 bx + 10 + pitch + nameWidth, by + 10, 0, &cFontGrey, -1., infobuf );
582static int map_system_mouse(
unsigned int wid,
const SDL_Event* event,
double mx,
double my,
583 double w,
double h,
double rx,
double ry,
void *data )
589 switch (event->type) {
590 case SDL_MOUSEBUTTONDOWN:
592 if ((mx < 0.) || (mx > w) || (my < 0.) || (my > h))
594 if (mx < pitch && my > 0) {
595 if (cur_spob_sel != (h-my) / pitch) {
596 cur_spob_sel = ( h-my) / pitch;
597 map_system_updateSelected( wid );
606static void map_system_array_update(
unsigned int wid,
const char* str )
610 char buf_price[ECON_CRED_STRLEN], buf_license[STRMAX_SHORT], buf_mass[ECON_MASS_STRLEN];
614 i = toolkit_getImageArrayPos( wid, str );
617 if ((strcmp( str, MAPSYS_OUTFITS ) == 0)) {
618 Outfit *outfit = cur_spob_sel_outfits[i];
619 double mass = outfit->
mass;
624 buf_license[0] =
'\0';
626 (cur_spobObj_sel != NULL && spob_hasService( cur_spobObj_sel, SPOB_SERVICE_BLACKMARKET )))
627 strncpy( buf_license, _(outfit->
license),
sizeof(buf_license)-1 );
629 snprintf( buf_license,
sizeof( buf_license ),
"#r%s#0", _(outfit->
license) );
635 snprintf( buf_mass,
sizeof(buf_mass), n_(
"%d t",
"%d t", (
int)round( mass ) ), (
int)round( mass ) );
642 char *desc_start = &infobuf[l];
644 while ( (desc_start = strchr( desc_start,
'\n' )) != NULL ) {
645 char *tab_pos = desc_start;
646 desc_start = strchr( &tab_pos[1],
'\n' );
647 if (desc_start == NULL)
654 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"#n%s#0 %s ", _(
"Mass:"), buf_mass );
655 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"#n%s#0 %s ", _(
"Price:"), buf_price );
656 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"%s", buf_license );
658 else if ((strcmp( str, MAPSYS_SHIPS ) == 0)) {
659 char buf_cargo[ECON_MASS_STRLEN];
660 ship = cur_spob_sel_ships[i];
667 strncpy( buf_license, _(
"None"),
sizeof(buf_license)-1 );
669 || (cur_spobObj_sel != NULL && spob_hasService( cur_spobObj_sel, SPOB_SERVICE_BLACKMARKET )))
670 strncpy( buf_license, _(ship->
license),
sizeof(buf_license)-1 );
672 snprintf( buf_license,
sizeof(buf_license),
"#r%s#0", _(ship->
license) );
674 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"#n%s#0 %s", _(
"Model:"), _(ship->
name) );
677 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 %s", _(
"Fabricator:"), _(ship->
fabricator) );
678 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
" #n%s#0 %d", _(
"Crew:"), ship->
crew );
680 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 %.0f %s", _(
"CPU:"), ship->
cpu, UNIT_CPU );
681 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
" #n%s#0 %s", _(
"Mass:"), buf_mass );
682 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 ", _(
"Accel:") );
683 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, _(
"%.0f %s"), ship->
accel, UNIT_ACCEL );
684 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
" #n%s#0 ", _(
"Speed:") );
685 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, _(
"%.0f %s"), ship->
speed, UNIT_SPEED );
686 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 ", _(
"Turn:") );
687 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, _(
"%.0f %s"), ship->
turn*180./M_PI, UNIT_ROTATION );
688 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
" #n%s#0 %.0f%%", _(
"Time Constant:"), ship->
dt_default*100. );
690 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 ", _(
"Absorption:") );
691 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, _(
"%.0f%% damage"), ship->
dmg_absorb*100. );
692 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 ", _(
"Shield:") );
693 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, _(
"%.0f %s (%.1f %s)"), ship->
shield, UNIT_ENERGY, ship->
shield_regen, UNIT_POWER );
694 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
" #n%s#0 ", _(
"Armour:") );
695 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, _(
"%.0f %s (%.1f %s)"), ship->
armour, UNIT_ENERGY, ship->
armour_regen, UNIT_POWER );
696 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 ", _(
"Energy:") );
697 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, _(
"%.0f M%s(%.1f %s)"), ship->
energy, UNIT_ENERGY, ship->
energy_regen, UNIT_POWER );
698 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 %s", _(
"Cargo Space:"), buf_cargo );
699 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 %d %s", _(
"Fuel:"), ship->
fuel, UNIT_UNIT );
700 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
" #n%s#0 %d %s", _(
"Fuel Use:"),
702 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 %s", _(
"Price:"), buf_price );
703 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
" #n%s#0 %s", _(
"License:"), buf_license );
706 else if ((strcmp( str, MAPSYS_TRADE ) == 0)) {
710 credits_t globalmean;
712 char buf_mean[ECON_CRED_STRLEN], buf_globalmean[ECON_CRED_STRLEN];
713 char buf_std[ECON_CRED_STRLEN], buf_globalstd[ECON_CRED_STRLEN];
714 char buf_buy_price[ECON_CRED_STRLEN];
720 snprintf( buf_std,
sizeof(buf_std),
"%.1f ¤", std );
722 snprintf( buf_globalstd,
sizeof(buf_globalstd),
"%.1f ¤", globalstd );
729 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, n_(
730 "#nYou have:#0 %d tonne, purchased at %s/t\n",
731 "#nYou have:#0 %d tonnes, purchased at %s/t\n",
732 owned), owned, buf_buy_price );
735 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, n_(
736 "#nYou have:#0 %d tonne\n",
737 "#nYou have:#0 %d tonnes\n",
740 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"#n%s#0 ", _(
"Average price seen here:") );
741 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, _(
"%s/t ± %s/t"), buf_mean, buf_std );
742 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n#n%s#0 ", _(
"Average price seen everywhere:") );
743 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l, _(
"%s/t ± %s/t"), buf_globalmean, buf_globalstd );
744 l +=
scnprintf( &infobuf[l],
sizeof(infobuf)-l,
"\n%s",
"" );
747 WARN( _(
"Unexpected call to map_system_array_update\n") );
750void map_system_updateSelected(
unsigned int wid )
752 StarSystem *sys=cur_sys_sel;
754 int spobObjChanged = 0;
758 int noutfits,nships,ngoods;
765 for (
int i=0; i<
array_size(sys->spobs); i++) {
767 if (spob_isKnown( p )) {
769 if ( textw > nameWidth )
772 if ( cur_spob_sel == nshow ) {
773 if ( cur_spobObj_sel != p )
782 if ( textw > nameWidth )
787 pitch = (h-100) / nshow;
791 if ( cur_spob_sel >= nshow ) {
792 cur_spob_sel = nshow-1;
793 if ( cur_spobObj_sel != last ) {
794 cur_spobObj_sel = last;
798 if ( cur_spob_sel <= 0 ) {
801 if ( cur_spobObj_sel != NULL ) {
802 cur_spobObj_sel = NULL;
807 if ( spobObjChanged ) {
809 if ( cur_spobObj_sel == NULL ) {
814 window_disableButton( wid,
"btnBuyCommodPrice" );
825 if (
landed && spob_hasService( cur_spobObj_sel, SPOB_SERVICE_COMMODITY ) )
826 window_enableButton( wid,
"btnBuyCommodPrice" );
828 window_disableButton( wid,
"btnBuyCommodPrice" );
835 if ( noutfits != 0 ) {
841 }
else if ( nships!=0 )
845 map_system_genOutfitsList( wid, g, o, s );
846 map_system_genShipsList( wid, g, o, s );
847 map_system_genTradeList( wid, g, o, s );
856static void map_system_genOutfitsList(
unsigned int wid,
float goodsSpace,
float outfitSpace,
float shipSpace )
859 ImageArrayCell *coutfits;
862 int xpos, xw, ypos, yh;
864 static Spob *spobDone = NULL;
867 if (spobDone == cur_spobObj_sel) {
875 spobDone = cur_spobObj_sel;
879 cur_spob_sel_outfits = NULL;
882 if (cur_spobObj_sel == NULL)
886 if (!spob_hasService( cur_spobObj_sel, SPOB_SERVICE_OUTFITS ))
890 noutfits =
array_size( cur_spob_sel_outfits );
896 xw = ( w - nameWidth - pitch - 60 ) / 2;
897 xpos = 35 + pitch + nameWidth + xw;
898 i = (goodsSpace!=0) + (outfitSpace!=0) + (shipSpace!=0);
899 yh = (h - 100 - (i+1)*5 ) * outfitSpace;
900 ypos = 65 + 5*(shipSpace!=0) + (h - 100 - (i+1)*5)*shipSpace;
903 if (toolkit_simImageArrayVisibleElements( xw, yh, iconsize, iconsize ) < noutfits)
905 window_addImageArray( wid, xpos, ypos,
906 xw, yh, MAPSYS_OUTFITS, iconsize, iconsize,
907 coutfits, noutfits, map_system_array_update, NULL, NULL );
908 toolkit_unsetSelection( wid, MAPSYS_OUTFITS );
911static void map_system_genShipsList(
unsigned int wid,
float goodsSpace,
float outfitSpace,
float shipSpace )
913 ImageArrayCell *cships;
915 int xpos, ypos, xw, yh;
916 static Spob *spobDone=NULL;
917 int i, w, h, iconsize;
921 if (spobDone == cur_spobObj_sel) {
929 cur_spob_sel_ships = NULL;
931 assert(cur_spob_sel_ships == NULL);
933 spobDone = cur_spobObj_sel;
936 if (cur_spobObj_sel == NULL)
940 if (!spob_hasService( cur_spobObj_sel, SPOB_SERVICE_SHIPYARD ))
949 cships = calloc( nships,
sizeof(ImageArrayCell) );
950 for ( i=0; i<nships; i++ ) {
951 cships[i].image =
gl_dupTexture( cur_spob_sel_ships[i]->gfx_store );
952 cships[i].caption = strdup( _(cur_spob_sel_ships[i]->name) );
954 xw = (w - nameWidth - pitch - 60)/2;
955 xpos = 35 + pitch + nameWidth + xw;
956 i = (goodsSpace!=0) + (outfitSpace!=0) + (shipSpace!=0);
957 yh = (h - 100 - (i+1)*5 ) * shipSpace;
961 if (toolkit_simImageArrayVisibleElements( xw, yh, iconsize, iconsize ) < nships )
963 window_addImageArray( wid, xpos, ypos,
964 xw, yh, MAPSYS_SHIPS, iconsize, iconsize,
965 cships, nships, map_system_array_update, NULL, NULL );
966 toolkit_unsetSelection( wid, MAPSYS_SHIPS );
969static void map_system_genTradeList(
unsigned int wid,
float goodsSpace,
float outfitSpace,
float shipSpace )
971 static Spob *spobDone=NULL;
973 ImageArrayCell *cgoods;
974 int xpos, ypos, xw, yh, w, h, iconsize;
978 if ( spobDone == cur_spobObj_sel ) {
989 if (cur_spobObj_sel == NULL)
993 if (!spob_hasService( cur_spobObj_sel, SPOB_SERVICE_COMMODITY ))
996 spobDone = cur_spobObj_sel;
1002 cgoods = calloc( ngoods,
sizeof(ImageArrayCell) );
1003 for ( i=0; i<ngoods; i++ ) {
1005 cgoods[i].caption = strdup( _(cur_spobObj_sel->
commodities[i]->
name) );
1008 xw = (w - nameWidth - pitch - 60)/2;
1009 xpos = 35 + pitch + nameWidth + xw;
1010 i = (goodsSpace!=0) + (outfitSpace!=0) + (shipSpace!=0);
1011 yh = (h - 100 - (i+1)*5 ) * goodsSpace;
1012 ypos = 60 + 5*i + (h-100 - (i+1)*5 )*(outfitSpace + shipSpace);
1015 if (toolkit_simImageArrayVisibleElements( xw, yh, iconsize, iconsize ) < ngoods )
1017 window_addImageArray( wid, xpos, ypos,
1018 xw, yh, MAPSYS_TRADE, iconsize, iconsize,
1019 cgoods, ngoods, map_system_array_update, NULL, NULL );
1020 toolkit_unsetSelection( wid, MAPSYS_TRADE );
1026void map_system_buyCommodPrice(
unsigned int wid,
const char *str )
1031 StarSystem **syslist;
1033 char coststr[ECON_CRED_STRLEN];
1037 if ((strcmp(
cur_system->name, cur_sys_sel->name ) == 0)) {
1042 syslist=map_getJumpPath(
cur_system->name, NULL, cur_sys_sel->name, 1, 0, NULL, NULL);
1043 if ( syslist == NULL ) {
1045 dialogue_msg( _(
"Unavailable"), _(
"Commodity prices for %s are not available here at the moment."), _(cur_spobObj_sel->
name) );
1054 t -= ( njumps * 2 + 0.2 ) * NT_PERIOD_SECONDS * 1000;
1057 dialogue_msg( _(
"Insufficient Credits"), _(
"You need %s to purchase this information."), coststr );
1059 dialogue_msgRaw( _(
"No commodities sold here"),_(
"There are no commodities sold here."));
1061 dialogue_msgRaw( _(
"Already Up-to-date"), _(
"You have newer information that what is available.") );
1063 int ret =
dialogue_YesNo( _(
"Purchase commodity prices?"), _(
"Purchase %g period old pricing information for %s for %s?"),
1064 njumps*2+0.2, _(cur_spobObj_sel->
name), coststr );
1067 economy_averageSeenPricesAtTime( cur_spobObj_sel, t );
1068 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?
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, 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.
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.
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.