22#define BUTTON_WIDTH 120
23#define BUTTON_HEIGHT 30
26static int map_find_systems = 1;
27static int map_find_spobs = 0;
28static int map_find_outfits = 0;
29static int map_find_ships = 0;
34static int map_found_ncur = 0;
35static char **map_foundOutfitNames =
39static tech_group_t **map_known_techs =
41static Spob **map_known_spobs =
48static int map_knownInit(
void );
49static void map_knownClean(
void );
51static void map_addOutfitDetailFields(
unsigned int wid_results,
int x,
int y,
53static void map_findCheckUpdate(
unsigned int wid_map_find,
const char *str );
54static void map_findOnClose(
unsigned int wid_map_find,
const char *str );
55static void map_findDisplayMark(
unsigned int wid_results,
const char *str );
56static void map_findDisplayResult(
unsigned int wid_map_find,
map_find_t *found,
58static int map_findSearchSystems(
unsigned int wid_map_find,
const char *name );
59static int map_findSearchSpobs(
unsigned int wid_map_find,
const char *name );
60static int map_findSearchOutfits(
unsigned int wid_map_find,
const char *name );
61static int map_findSearchShips(
unsigned int wid_map_find,
const char *name );
62static void map_findSearch(
unsigned int wid_map_find,
const char *str );
63static void map_showOutfitDetail(
unsigned int wid,
const char *wgtname,
int x,
64 int y,
int w,
int h );
65static void map_adjustButtonLabel(
unsigned int wid_map_find,
68static void map_findAccumulateResult(
map_find_t *found,
int n, StarSystem *sys,
70static void map_findSelect(
const StarSystem *sys );
71static int map_sortCompare(
const void *p1,
const void *p2 );
72static void map_sortFound(
map_find_t *found,
int n );
73static char map_getSpobColourChar(
Spob *p );
74static const char *map_getSpobSymbol(
Spob *p );
76static char **map_fuzzyOutfits(
Outfit **o,
const char *name );
77static char **map_outfitsMatch(
const char *name );
78static char **map_fuzzyShips(
Ship **o,
const char *name );
79static char **map_shipsMatch(
const char *name );
84static int map_knownInit(
void )
93 for (
int i = 0; i <
array_size( sys ); i++ ) {
94 if ( !sys_isKnown( &sys[i] ) )
97 for (
int j = 0; j <
array_size( sys[i].spobs ); j++ ) {
98 Spob *spob = sys[i].spobs[j];
100 if ( spob_isKnown( spob ) && spob->
tech != NULL ) {
113static void map_knownClean(
void )
116 map_known_techs = NULL;
118 map_known_spobs = NULL;
124static void map_findCheckUpdate(
unsigned int wid_map_find,
const char *str )
127 map_find_systems ^= window_checkboxState( wid_map_find,
"chkSystem" );
128 map_find_spobs ^= window_checkboxState( wid_map_find,
"chkSpob" );
129 map_find_outfits ^= window_checkboxState( wid_map_find,
"chkOutfit" );
130 map_find_ships ^= window_checkboxState( wid_map_find,
"chkShip" );
131 window_checkboxSet( wid_map_find,
"chkSystem", map_find_systems );
132 window_checkboxSet( wid_map_find,
"chkSpob", map_find_spobs );
133 window_checkboxSet( wid_map_find,
"chkOutfit", map_find_outfits );
134 window_checkboxSet( wid_map_find,
"chkShip", map_find_ships );
143void map_inputFindType(
unsigned int parent,
const char *type )
145 map_find_systems = 0;
147 map_find_outfits = 0;
150 if ( strcmp( type,
"system" ) == 0 )
151 map_find_systems = 1;
152 else if ( strcmp( type,
"spob" ) == 0 )
154 else if ( strcmp( type,
"outfit" ) == 0 )
155 map_find_outfits = 1;
156 else if ( strcmp( type,
"ship" ) == 0 )
159 map_inputFind( parent, NULL );
165static void map_findOnClose(
unsigned int wid,
const char *str )
170 free( map_found_cur );
171 map_found_cur = NULL;
178static void map_findDisplayMark(
unsigned int wid_results,
const char *str )
181 int pos = toolkit_getListPos( wid_results,
"lstResult" );
182 StarSystem *sys = map_found_cur[pos].sys;
188 map_findSelect( sys );
194static void map_findDisplayResult(
unsigned int wid_map_find,
map_find_t *found,
197 unsigned int wid_results;
201 map_found_cur = found;
205 map_sortFound( found, n );
209 window_create(
"wdwFindResult", _(
"Search Results" ), -1, -1, 500, 452 );
215 ll = malloc(
sizeof(
char * ) * n );
216 for (
int i = 0; i < n; i++ )
217 ll[i] = strdup( found[i].display );
218 window_addList( wid_results, 20, -40, 460, 300,
"lstResult", ll, n, 0, NULL,
219 map_findDisplayMark );
223 "btnSelect", _(
"Select" ), map_findDisplayMark );
231static int map_sortCompare(
const void *p1,
const void *p2 )
252 return strcasecmp( f1->
sys->name, f2->
sys->name );
258static void map_sortFound(
map_find_t *found,
int n )
260 qsort( found, n,
sizeof(
map_find_t ), map_sortCompare );
266static int map_findDistance( StarSystem *sys,
Spob *spob,
int *jumps,
277 *distance = vec2_dist( &
player.p->solid.pos, &spob->
pos );
294 if ( spob != NULL ) {
298 StarSystem *ss = slist[i];
299 for (
int j = 0; j <
array_size( ss->jumps ); j++ ) {
300 if ( ss->jumps[j].target == slist[i - 1] ) {
301 vs = &ss->jumps[j].pos;
306 vs = &
player.p->solid.pos;
308 assert( vs != NULL );
309 assert( ve != NULL );
311 d += vec2_dist( vs, ve );
330static void map_findAccumulateResult(
map_find_t *found,
int n, StarSystem *sys,
334 char route_info[STRMAX_SHORT];
337 found[n].
spob = spob;
341 ret = map_findDistance( sys, spob, &found[n].jumps, &found[n].distance );
343 found[n].
jumps = 10e3;
345 snprintf( route_info,
sizeof( route_info ),
"%s", _(
"unknown route" ) );
347 snprintf( route_info,
sizeof( route_info ),
348 n_(
"%d jump, %.0fk distance",
"%d jumps, %.0fk distance",
350 found[n].jumps, found[n].distance / 1000. );
354 snprintf( found[n].display,
sizeof( found[n].display ), _(
"%s (%s)" ),
355 system_name( sys ), route_info );
357 snprintf( found[n].display,
sizeof( found[n].display ),
358 _(
"#%c%s%s (%s, %s)" ), map_getSpobColourChar( spob ),
359 map_getSpobSymbol( spob ),
spob_name( spob ),
360 system_name( sys ), route_info );
366static void map_findSelect(
const StarSystem *sys )
370 map_select( sys, 0 );
371 map_center( 0, sys->name );
380static int map_findSearchSystems(
unsigned int wid_map_find,
const char *name )
394 if ( ( sysname != NULL ) && ( len == 1 ) ) {
397 if ( sys_isKnown( sys ) ) {
398 map_findSelect( sys );
407 for (
int i = 0; i < len; i++ ) {
411 if ( !sys_isKnown( sys ) )
417 map_findAccumulateResult( found, n, sys, NULL );
427 map_findDisplayResult( wid_map_find, found, n );
437static int map_findSearchSpobs(
unsigned int wid_map_find,
const char *name )
442 const char *spobname;
451 if ( ( spobname != NULL ) && ( len == 1 ) ) {
454 if ( sysname != NULL ) {
457 if ( ( spob != NULL ) && spob_isKnown( spob ) ) {
461 if ( sys_isKnown( sys ) ) {
462 map_findSelect( sys );
473 for (
int i = 0; i < len; i++ ) {
481 if ( !spob_isKnown( spob ) )
486 if ( sysname == NULL )
489 if ( !sys_isKnown( sys ) )
495 map_findAccumulateResult( found, n, sys, spob );
505 map_findDisplayResult( wid_map_find, found, n );
512static char map_getSpobColourChar(
Spob *p )
525static const char *map_getSpobSymbol(
Spob *p )
535static char **map_fuzzyOutfits(
Outfit **o,
const char *name )
541 if ( SDL_strcasestr( _( o[i]->name ), name ) != NULL )
543 else if ( ( o[i]->
typename != NULL ) &&
544 SDL_strcasestr( o[i]->
typename, name ) != NULL )
546 else if ( ( o[i]->condstr != NULL ) &&
547 SDL_strcasestr( o[i]->condstr, name ) != NULL )
551 else if ( SDL_strcasestr(
outfit_summary( o[i], 0 ), name ) != NULL )
561static char **map_outfitsMatch(
const char *name )
568 names = map_fuzzyOutfits( o, name );
584static void map_addOutfitDetailFields(
unsigned int wid_results,
int x,
int y,
595 window_addRect( wid_results, -1 + iw, -50, 128, 129,
"rctImage", &cBlack,
597 window_addImage( wid_results, iw, -50 - 128, 0, 0,
"imgOutfit", NULL, 1 );
599 window_addText( wid_results, iw + 128 + 20, -50, 280, 160, 0,
"txtDescShort",
601 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"#n%s#0\n", _(
"Owned:" ) );
602 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"#n%s#0\n", _(
"Mass:" ) );
603 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"#n%s#0\n", _(
"Price:" ) );
604 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"#n%s#0\n", _(
"Money:" ) );
605 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"#n%s#0\n", _(
"License:" ) );
606 window_addText( wid_results, iw + 20, -50 - 128 - 10, 90, 160, 0,
"txtSDesc",
608 window_addText( wid_results, iw + 20, -50 - 128 - 10,
609 w - ( 20 + iw + 20 + 90 ), 160, 0,
"txtDDesc", &
gl_smallFont,
611 window_addText( wid_results, iw + 20, -50 - 128 - 10 - 160, w - ( iw + 80 ),
625static void map_showOutfitDetail(
unsigned int wid,
const char *wgtname,
int x,
626 int y,
int w,
int h )
631 char buf[STRMAX], buf_price[ECON_CRED_STRLEN], buf_money[ECON_CRED_STRLEN],
632 buf_mass[ECON_MASS_STRLEN];
634 outfit_get( map_foundOutfitNames[toolkit_getListPos( wid, wgtname )] );
638 double mass = outfit->
mass;
645 window_modifyImage( wid,
"imgOutfit", outfit->
gfx_store, 128, 128 );
647 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
" %s",
649 window_modifyText( wid,
"txtDescShort", buf );
657 window_modifyText( wid,
"txtDescription",
664 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"%d\n",
666 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"%s\n", buf_mass );
667 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"%s\n", buf_price );
668 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"%s\n", buf_money );
669 l +=
scnprintf( &buf[l],
sizeof( buf ) - l,
"%s\n",
673 window_modifyText( wid,
"txtDDesc", buf );
689static void map_adjustButtonLabel(
unsigned int wid_map_find,
const char *name )
691 if ( window_getInput( wid_map_find, name )[0] !=
'\0' ) {
692 window_buttonCaption( wid_map_find,
"btnSearch", _(
"Find" ) );
694 window_buttonCaption( wid_map_find,
"btnSearch", _(
"Show all" ) );
704static int map_findSearchOutfits(
unsigned int wid_map_find,
const char *name )
708 const char *oname, *sysname;
712 assert(
"Outfit search is not reentrant!" && map_foundOutfitNames == NULL );
717 map_foundOutfitNames = map_outfitsMatch( name );
719 if ( ( oname != NULL ) && ( len == 1 ) )
722 else if ( len > 0 ) {
726 list = malloc( len *
sizeof(
char * ) );
727 for ( i = 0; i < len; i++ )
728 list[i] = strdup( _( map_foundOutfitNames[i] ) );
729 if ( ( name == NULL ) || ( name[0] ==
'\0' ) )
731 map_addOutfitDetailFields,
732 map_showOutfitDetail,
733 _(
"Showing all known outfits:" ) );
736 _(
"Search Results" ), list, len, 452, 650,
737 map_addOutfitDetailFields, map_showOutfitDetail,
738 _(
"Search results for outfits matching '%s':" ), name );
741 map_foundOutfitNames = NULL;
747 map_foundOutfitNames = NULL;
755 for (
int i = 0; i < len; i++ ) {
761 for ( j =
array_size( olist ) - 1; j >= 0; j-- )
768 spob = map_known_spobs[i];
771 if ( !spob_hasService( spob, SPOB_SERVICE_OUTFITS ) )
776 if ( sysname == NULL )
779 if ( !sys_isKnown( sys ) )
785 map_findAccumulateResult( found, n, sys, spob );
794 map_findDisplayResult( wid_map_find, found, n );
802static char **map_fuzzyShips(
Ship **s,
const char *name )
808 if ( SDL_strcasestr( _( s[i]->name ), name ) != NULL )
810 else if ( ( s[i]->license != NULL ) &&
811 SDL_strcasestr( _( s[i]->license ), name ) != NULL )
815 else if ( SDL_strcasestr( _( s[i]->fabricator ), name ) != NULL )
817 else if ( SDL_strcasestr( _( s[i]->description ), name ) != NULL )
826static char **map_shipsMatch(
const char *name )
833 names = map_fuzzyShips( s, name );
846static int map_findSearchShips(
unsigned int wid_map_find,
const char *name )
853 const char *sname, *sysname;
861 names = map_shipsMatch( name );
863 if ( ( sname != NULL ) && ( len == 1 ) )
866 else if ( len > 0 ) {
869 list = malloc( len *
sizeof(
char * ) );
870 for ( i = 0; i < len; i++ )
871 list[i] = strdup( _( names[i] ) );
872 if ( ( name == NULL ) || ( name[0] ==
'\0' ) )
874 _(
"Showing all known ships:" ) );
877 _(
"Search results for ships matching '%s':" ),
894 for (
int i = 0; i < len; i++ ) {
899 for ( j =
array_size( slist ) - 1; j >= 0; j-- )
906 spob = map_known_spobs[i];
909 if ( !spob_hasService( spob, SPOB_SERVICE_SHIPYARD ) )
914 if ( sysname == NULL )
917 if ( !sys_isKnown( sys ) )
923 map_findAccumulateResult( found, n, sys, spob );
932 map_findDisplayResult( wid_map_find, found, n );
939static void map_findSearch(
unsigned int wid_map_find,
const char *str )
942 const char *name, *searchname;
945 name = window_getInput( wid_map_find,
"inpSearch" );
953 window_disableButton( wid_map_find,
"btnSearch" );
956 free( map_found_cur );
957 map_found_cur = NULL;
960 if ( map_find_systems ) {
961 ret = map_findSearchSystems( wid_map_find, name );
962 searchname = _(
"System" );
963 }
else if ( map_find_spobs ) {
964 ret = map_findSearchSpobs( wid_map_find, name );
965 searchname = _(
"Space Objects" );
966 }
else if ( map_find_outfits ) {
967 ret = map_findSearchOutfits( wid_map_find, name );
968 searchname = _(
"Outfit" );
969 }
else if ( map_find_ships ) {
970 ret = map_findSearchShips( wid_map_find, name );
971 searchname = _(
"Ship" );
976 dialogue_alert( _(
"%s matching '%s' not found!" ), searchname, name );
979 window_enableButton( wid_map_find,
"btnSearch" );
988void map_inputFind(
unsigned int parent,
const char *str )
991 unsigned int wid_map_find;
1000 wid_map_find =
window_create(
"wdwFind", _(
"Find…" ), -1, -1, w, h );
1008 window_addText( wid_map_find, 20, y, w - 50,
gl_defFont.h + 4, 0,
1010 _(
"Enter keyword to search for: (Partial match)" ) );
1014 window_addInput( wid_map_find, 30, y, w - 60, 20,
"inpSearch", 32, 1,
1016 window_setInputCallback( wid_map_find,
"inpSearch", map_adjustButtonLabel );
1028 window_addCheckbox( wid_map_find, x, y, 160, 20,
"chkSystem", _(
"Systems" ),
1029 map_findCheckUpdate, map_find_systems );
1031 window_addCheckbox( wid_map_find, x, y, 160, 20,
"chkSpob",
1032 _(
"Space Objects" ), map_findCheckUpdate,
1035 window_addCheckbox( wid_map_find, x, y, 160, 20,
"chkOutfit", _(
"Outfits" ),
1036 map_findCheckUpdate, map_find_outfits );
1038 window_addCheckbox( wid_map_find, x, y, 160, 20,
"chkShip", _(
"Ships" ),
1039 map_findCheckUpdate, map_find_ships );
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.
#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 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 dialogue_alert(const char *fmt,...)
Displays an alert popup with only an ok button and a message.
int dialogue_listPanelRaw(const char *title, char **items, int nitems, int extrawidth, int minheight, void(*add_widgets)(unsigned int wid, int x, int y, int w, int h), void(*select_call)(unsigned int wid, const char *wgtname, int x, int y, int w, int h), const char *msg)
Creates a list dialogue with OK and Cancel buttons, with a fixed message, as well as a small extra ar...
int dialogue_listRaw(const char *title, char **items, int nitems, const char *msg)
Creates a list dialogue with OK and Cancel button.
int dialogue_listPanel(const char *title, char **items, int nitems, int extrawidth, int minheight, void(*add_widgets)(unsigned int wid, int x, int y, int w, int h), void(*select_call)(unsigned int wid, const char *wgtname, int x, int y, int w, int h), const char *fmt,...)
Creates a list dialogue with OK and Cancel buttons, with a fixed message, as well as a small extra ar...
int dialogue_list(const char *title, char **items, int nitems, const char *fmt,...)
Creates a list dialogue with OK and Cancel button with a fixed message.
int gl_printHeightRaw(const glFont *ft_font, const int width, const char *text)
Gets the height of a non-formatted string.
Header file with generic functions and naev-specifics.
int strsort(const void *p1, const void *p2)
Sort function for sorting strings with qsort().
int scnprintf(char *text, size_t maxlen, const char *fmt,...)
Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer....
const char * outfit_description(const Outfit *o)
Gets the description of an outfit.
const char * outfit_summary(const Outfit *o, int withname)
Gets the summary of an outfit.
const Outfit * outfit_get(const char *name)
Gets an outfit by name.
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 outfit_gfxStoreLoad(Outfit *o)
Loads the store graphics for the outfit.
const char * outfit_existsCase(const char *name)
Checks to see if an outfit exists matching name (case insensitive).
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_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.
const Ship * ship_get(const char *name)
Gets a ship based on its name.
const char * ship_existsCase(const char *name)
Checks to see if an ship exists matching name (case insensitive).
Spob * spob_get(const char *spobname)
Gets a spob based on its name.
const char * spob_getSymbol(const Spob *p)
Gets the spob symbol.
char spob_getColourChar(const Spob *p)
Gets the spob colour char.
const char * system_existsCase(const char *sysname)
Checks to see if a system exists case insensitively.
StarSystem * system_getAll(void)
Gets an array (array.h) of all star systems.
char ** spob_searchFuzzyCase(const char *spobname, int *n)
Does a fuzzy case matching. Searches spob_name() but returns internal names.
char ** system_searchFuzzyCase(const char *sysname, int *n)
Does a fuzzy case matching. Searches translated names but returns internal names.
StarSystem * system_get(const char *sysname)
Get the system from its name.
const char * spob_existsCase(const char *spobname)
Check to see if a spob exists (case insensitive).
void spob_updateLand(Spob *p)
Updates the land possibilities of a spob.
const char * spob_getSystemName(const char *spobname)
Get the name of a system from a spobname.
const char * spob_name(const Spob *p)
Gets the translated name of a spob.
A ship outfit, depends radically on the type.
union Outfit::@052125200133344144252153256241104103242010347340 u
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
Represents a found target.
Ship ** tech_getShipArray(tech_group_t **tech, int num)
Gets the ships from an array of techs.
Ship ** tech_getShip(const tech_group_t *tech)
Gets all of the ships associated to a tech group.
Outfit ** tech_getOutfitArray(tech_group_t **tech, int num)
Gets the outfits from an array of techs.
Outfit ** tech_getOutfit(const tech_group_t *tech)
Gets all of the outfits associated to a tech group.