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 = NULL;
37static tech_group_t **map_known_techs = NULL;
38static Spob **map_known_spobs = NULL;
44static int map_knownInit (
void);
45static void map_knownClean (
void);
47static void map_addOutfitDetailFields(
unsigned int wid_results,
int x,
int y,
int w,
int h);
48static void map_findCheckUpdate(
unsigned int wid_map_find,
const char *str );
49static void map_findOnClose(
unsigned int wid_map_find,
const char* str );
50static void map_findDisplayMark(
unsigned int wid_results,
const char* str );
51static void map_findDisplayResult(
unsigned int wid_map_find,
map_find_t *found,
int n );
52static int map_findSearchSystems(
unsigned int wid_map_find,
const char *name );
53static int map_findSearchSpobs(
unsigned int wid_map_find,
const char *name );
54static int map_findSearchOutfits(
unsigned int wid_map_find,
const char *name );
55static int map_findSearchShips(
unsigned int wid_map_find,
const char *name );
56static void map_findSearch(
unsigned int wid_map_find,
const char* str );
57static void map_showOutfitDetail(
unsigned int wid,
const char* wgtname,
int x,
int y,
int w,
int h);
58static void map_adjustButtonLabel(
unsigned int wid_map_find,
const char* name );
60static void map_findAccumulateResult(
map_find_t *found,
int n, StarSystem *sys,
Spob *spob );
61static void map_findSelect(
const StarSystem *sys );
62static int map_sortCompare(
const void *p1,
const void *p2 );
63static void map_sortFound(
map_find_t *found,
int n );
64static char map_getSpobColourChar(
Spob *p );
65static const char *map_getSpobSymbol(
Spob *p );
67static char **map_fuzzyOutfits(
Outfit **o,
const char *name );
68static char **map_outfitsMatch(
const char *name );
69static char **map_fuzzyShips(
Ship **o,
const char *name );
70static char **map_shipsMatch(
const char *name );
75static int map_knownInit (
void)
85 if (!sys_isKnown( &sys[i] ))
88 for (
int j=0; j<
array_size(sys[i].spobs); j++) {
89 Spob *spob = sys[i].spobs[j];
91 if (spob_isKnown( spob ) && spob->
tech != NULL) {
104static void map_knownClean (
void)
107 map_known_techs = NULL;
109 map_known_spobs = NULL;
115static void map_findCheckUpdate(
unsigned int wid_map_find,
const char* str )
118 map_find_systems ^= window_checkboxState( wid_map_find,
"chkSystem" );
119 map_find_spobs ^= window_checkboxState( wid_map_find,
"chkSpob" );
120 map_find_outfits ^= window_checkboxState( wid_map_find,
"chkOutfit" );
121 map_find_ships ^= window_checkboxState( wid_map_find,
"chkShip" );
122 window_checkboxSet( wid_map_find,
"chkSystem", map_find_systems );
123 window_checkboxSet( wid_map_find,
"chkSpob", map_find_spobs );
124 window_checkboxSet( wid_map_find,
"chkOutfit", map_find_outfits );
125 window_checkboxSet( wid_map_find,
"chkShip", map_find_ships );
134void map_inputFindType(
unsigned int parent,
const char *type )
136 map_find_systems = 0;
138 map_find_outfits = 0;
141 if (strcmp(type,
"system")==0)
142 map_find_systems = 1;
143 else if (strcmp(type,
"spob")==0)
145 else if (strcmp(type,
"outfit")==0)
146 map_find_outfits = 1;
147 else if (strcmp(type,
"ship")==0)
150 map_inputFind(parent, NULL);
156static void map_findOnClose(
unsigned int wid,
const char* str )
161 free( map_found_cur );
162 map_found_cur = NULL;
169static void map_findDisplayMark(
unsigned int wid_results,
const char* str )
172 int pos = toolkit_getListPos( wid_results,
"lstResult" );
173 StarSystem *sys = map_found_cur[ pos ].
sys;
179 map_findSelect( sys );
185static void map_findDisplayResult(
unsigned int wid_map_find,
map_find_t *found,
int n )
187 unsigned int wid_results;
191 map_found_cur = found;
195 map_sortFound( found, n );
198 wid_results =
window_create(
"wdwFindResult", _(
"Search Results"), -1, -1, 500, 452 );
204 ll = malloc(
sizeof(
char*) * n );
205 for (
int i=0; i<n; i++)
206 ll[i] = strdup( found[i].display );
207 window_addList( wid_results, 20, -40, 460, 300,
208 "lstResult", ll, n, 0, NULL, map_findDisplayMark );
211 window_addButton( wid_results, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
212 "btnSelect", _(
"Select"), map_findDisplayMark );
213 window_addButton( wid_results, -40 - BUTTON_WIDTH, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
220static int map_sortCompare(
const void *p1,
const void *p2 )
241 return strcasecmp( f1->
sys->name, f2->
sys->name );
247static void map_sortFound(
map_find_t *found,
int n )
249 qsort( found, n,
sizeof(
map_find_t), map_sortCompare );
255static int map_findDistance( StarSystem *sys,
Spob *spob,
int *jumps,
double *distance )
285 StarSystem *ss = slist[ i ];
286 for (
int j=0; j <
array_size(ss->jumps); j++) {
287 if (ss->jumps[j].target == slist[i-1]) {
288 vs = &ss->jumps[j].pos;
296 assert( vs != NULL );
297 assert( ve != NULL );
299 d += vec2_dist( vs, ve );
318static void map_findAccumulateResult(
map_find_t *found,
int n, StarSystem *sys,
Spob *spob )
321 char route_info[STRMAX_SHORT];
324 found[n].
spob = spob;
328 ret = map_findDistance( sys, spob, &found[n].jumps, &found[n].distance );
330 found[n].
jumps = 10e3;
332 snprintf( route_info,
sizeof(route_info),
"%s", _(
"unknown route") );
335 snprintf( route_info,
sizeof(route_info),
336 n_(
"%d jump, %.0fk distance",
"%d jumps, %.0fk distance", found[n].jumps ),
337 found[n].jumps, found[n].distance/1000. );
341 snprintf( found[n].display,
sizeof(found[n].display),
342 _(
"%s (%s)"), _(sys->name), route_info );
344 snprintf( found[n].display,
sizeof(found[n].display),
345 _(
"#%c%s%s (%s, %s)"), map_getSpobColourChar(spob),
346 map_getSpobSymbol(spob),
347 spob_name(spob), _(sys->name), route_info );
353static void map_findSelect(
const StarSystem *sys )
357 map_select( sys, 0 );
358 map_center( 0, sys->name );
367static int map_findSearchSystems(
unsigned int wid_map_find,
const char *name )
381 if ((sysname != NULL) && (len == 1)) {
384 if (sys_isKnown(sys)) {
385 map_findSelect( sys );
394 for (
int i=0; i<len; i++) {
398 if (!sys_isKnown(sys))
404 map_findAccumulateResult( found, n, sys, NULL );
414 map_findDisplayResult( wid_map_find, found, n );
424static int map_findSearchSpobs(
unsigned int wid_map_find,
const char *name )
429 const char *spobname;
438 if ((spobname != NULL) && (len == 1)) {
441 if (sysname != NULL) {
444 if ((spob != NULL) && spob_isKnown(spob)) {
448 if (sys_isKnown(sys)) {
449 map_findSelect( sys );
460 for (
int i=0; i<len; i++) {
468 if (!spob_isKnown(spob))
476 if (!sys_isKnown(sys))
482 map_findAccumulateResult( found, n, sys, spob );
492 map_findDisplayResult( wid_map_find, found, n );
499static char map_getSpobColourChar(
Spob *p )
512static const char *map_getSpobSymbol(
Spob *p )
521static char **map_fuzzyOutfits(
Outfit **o,
const char *name )
527 if (SDL_strcasestr( _(o[i]->name), name ) != NULL)
529 else if ((o[i]->
typename != NULL) && SDL_strcasestr( o[i]->
typename, name ) != NULL)
531 else if ((o[i]->condstr != NULL) && SDL_strcasestr( o[i]->condstr, name ) != NULL)
545static char **map_outfitsMatch(
const char *name )
552 names = map_fuzzyOutfits( o, name );
568static void map_addOutfitDetailFields(
unsigned int wid_results,
int x,
int y,
int w,
int h)
578 window_addRect( wid_results, -1 + iw, -50, 128, 129,
"rctImage", &cBlack, 0 );
579 window_addImage( wid_results, iw, -50-128, 0, 0,
"imgOutfit", NULL, 1 );
581 window_addText( wid_results, iw + 128 + 20, -50,
582 280, 160, 0,
"txtDescShort", &
gl_smallFont, NULL, NULL );
583 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", _(
"Owned:") );
584 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", _(
"Mass:") );
585 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", _(
"Price:") );
586 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", _(
"Money:") );
587 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", _(
"License:") );
588 window_addText( wid_results, iw+20, -50-128-10,
590 window_addText( wid_results, iw+20, -50-128-10,
591 w - (20 + iw + 20 + 90), 160, 0,
"txtDDesc", &
gl_smallFont, NULL, NULL );
592 window_addText( wid_results, iw+20, -50-128-10-160,
593 w-(iw+80), 180, 0,
"txtDescription",
607static void map_showOutfitDetail(
unsigned int wid,
const char* wgtname,
int x,
int y,
int w,
int h )
612 char buf[STRMAX], buf_price[ECON_CRED_STRLEN], buf_money[ECON_CRED_STRLEN], buf_mass[ECON_MASS_STRLEN];
613 const Outfit *outfit =
outfit_get( map_foundOutfitNames[toolkit_getListPos(wid, wgtname)] );
617 double mass = outfit->
mass;
623 window_modifyImage( wid,
"imgOutfit", outfit->
gfx_store, 128, 128 );
626 window_modifyText( wid,
"txtDescShort", buf );
641 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s\n", buf_mass );
642 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s\n", buf_price );
643 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s\n", buf_money );
646 window_modifyText( wid,
"txtDDesc", buf );
662static void map_adjustButtonLabel(
unsigned int wid_map_find,
const char* name )
664 if ( window_getInput( wid_map_find, name )[0] !=
'\0' ) {
665 window_buttonCaption( wid_map_find,
"btnSearch", _(
"Find") );
667 window_buttonCaption( wid_map_find,
"btnSearch", _(
"Show all") );
677static int map_findSearchOutfits(
unsigned int wid_map_find,
const char *name )
681 const char *oname, *sysname;
685 assert(
"Outfit search is not reentrant!" && map_foundOutfitNames == NULL );
690 map_foundOutfitNames = map_outfitsMatch( name );
692 if ((oname != NULL) && (len == 1))
699 list = malloc( len*
sizeof(
char*) );
700 for (i=0; i<len; i++)
701 list[i] = strdup( _(map_foundOutfitNames[i]) );
702 if ((name==NULL) || (name[0]==
'\0'))
704 map_addOutfitDetailFields, map_showOutfitDetail,
705 _(
"Showing all known outfits:") );
708 map_addOutfitDetailFields, map_showOutfitDetail,
709 _(
"Search results for outfits matching '%s':"), name );
712 map_foundOutfitNames = NULL;
718 map_foundOutfitNames = NULL;
726 for (
int i=0; i<len; i++) {
739 spob = map_known_spobs[i];
742 if (!spob_hasService(spob,SPOB_SERVICE_OUTFITS))
750 if (!sys_isKnown(sys))
756 map_findAccumulateResult( found, n, sys, spob );
765 map_findDisplayResult( wid_map_find, found, n );
772static char **map_fuzzyShips(
Ship **s,
const char *name )
778 if (SDL_strcasestr( _(s[i]->name), name ) != NULL)
780 else if ((s[i]->license != NULL) && SDL_strcasestr( _(s[i]->license), name ) != NULL)
784 else if (SDL_strcasestr( _(s[i]->fabricator), name ) != NULL)
786 else if (SDL_strcasestr( _(s[i]->description), name ) != NULL)
795static char **map_shipsMatch(
const char *name )
802 names = map_fuzzyShips( s, name );
815static int map_findSearchShips(
unsigned int wid_map_find,
const char *name )
822 const char *sname, *sysname;
830 names = map_shipsMatch( name );
832 if ((sname != NULL) && (len == 1))
838 list = malloc( len*
sizeof(
char*) );
839 for (i=0; i<len; i++)
840 list[i] = strdup( _(names[i]) );
841 if ((name==NULL) || (name[0]==
'\0'))
843 _(
"Showing all known ships:") );
846 _(
"Search results for ships matching '%s':"), name );
862 for (
int i=0; i<len; i++) {
874 spob = map_known_spobs[i];
877 if (!spob_hasService(spob,SPOB_SERVICE_SHIPYARD))
885 if (!sys_isKnown(sys))
891 map_findAccumulateResult( found, n, sys, spob );
900 map_findDisplayResult( wid_map_find, found, n );
907static void map_findSearch(
unsigned int wid_map_find,
const char* str )
910 const char *name, *searchname;
913 name = window_getInput( wid_map_find,
"inpSearch" );
919 window_disableButton( wid_map_find,
"btnSearch" );
922 free( map_found_cur );
923 map_found_cur = NULL;
926 if (map_find_systems) {
927 ret = map_findSearchSystems( wid_map_find, name );
928 searchname = _(
"System");
930 else if (map_find_spobs) {
931 ret = map_findSearchSpobs( wid_map_find, name );
932 searchname = _(
"Space Objects");
934 else if (map_find_outfits) {
935 ret = map_findSearchOutfits( wid_map_find, name );
936 searchname = _(
"Outfit");
938 else if (map_find_ships) {
939 ret = map_findSearchShips( wid_map_find, name );
940 searchname = _(
"Ship");
946 dialogue_alert( _(
"%s matching '%s' not found!"), searchname, name );
949 window_enableButton( wid_map_find,
"btnSearch" );
958void map_inputFind(
unsigned int parent,
const char* str )
961 unsigned int wid_map_find;
970 wid_map_find =
window_create(
"wdwFind", _(
"Find…"), -1, -1, w, h );
978 window_addText( wid_map_find, 20, y, w - 50,
gl_defFont.
h+4, 0,
980 _(
"Enter keyword to search for: (Partial match)") );
984 window_addInput( wid_map_find, 30, y, w - 60, 20,
986 window_setInputCallback( wid_map_find,
"inpSearch", map_adjustButtonLabel );
990 window_addButton( wid_map_find, -30, 20+BUTTON_HEIGHT+20, BUTTON_WIDTH, BUTTON_HEIGHT,
991 "btnSearch", _(
"Show all"), map_findSearch );
992 window_addButton( wid_map_find, -30, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
997 window_addCheckbox( wid_map_find, x, y, 160, 20,
998 "chkSystem", _(
"Systems"), map_findCheckUpdate, map_find_systems );
1000 window_addCheckbox( wid_map_find, x, y, 160, 20,
1001 "chkSpob", _(
"Space Objects"), map_findCheckUpdate, map_find_spobs );
1003 window_addCheckbox( wid_map_find, x, y, 160, 20,
1004 "chkOutfit", _(
"Outfits"), map_findCheckUpdate, map_find_outfits );
1006 window_addCheckbox( wid_map_find, x, y, 160, 20,
1007 "chkShip", _(
"Ships"), 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.
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_getSystem(const char *spobname)
Get the name of a system from a spobname.
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_name(const Spob *p)
Gets the translated name of a spob.
A ship outfit, depends radically on the type.
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.