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);
59static void map_findAccumulateResult(
map_find_t *found,
int n, StarSystem *sys,
Spob *spob );
60static void map_findSelect(
const StarSystem *sys );
61static int map_sortCompare(
const void *p1,
const void *p2 );
62static void map_sortFound(
map_find_t *found,
int n );
63static char map_getSpobColourChar(
Spob *p );
64static const char *map_getSpobSymbol(
Spob *p );
66static char **map_fuzzyOutfits(
Outfit **o,
const char *name );
67static char **map_outfitsMatch(
const char *name );
68static char **map_fuzzyShips(
Ship **o,
const char *name );
69static char **map_shipsMatch(
const char *name );
74static int map_knownInit (
void)
84 if (!sys_isKnown( &sys[i] ))
87 for (
int j=0; j<
array_size(sys[i].spobs); j++) {
88 Spob *spob = sys[i].spobs[j];
90 if (spob_isKnown( spob ) && spob->
tech != NULL) {
103static void map_knownClean (
void)
106 map_known_techs = NULL;
108 map_known_spobs = NULL;
114static void map_findCheckUpdate(
unsigned int wid_map_find,
const char* str )
117 map_find_systems ^= window_checkboxState( wid_map_find,
"chkSystem" );
118 map_find_spobs ^= window_checkboxState( wid_map_find,
"chkSpob" );
119 map_find_outfits ^= window_checkboxState( wid_map_find,
"chkOutfit" );
120 map_find_ships ^= window_checkboxState( wid_map_find,
"chkShip" );
121 window_checkboxSet( wid_map_find,
"chkSystem", map_find_systems );
122 window_checkboxSet( wid_map_find,
"chkSpob", map_find_spobs );
123 window_checkboxSet( wid_map_find,
"chkOutfit", map_find_outfits );
124 window_checkboxSet( wid_map_find,
"chkShip", map_find_ships );
133void map_inputFindType(
unsigned int parent,
const char *type )
135 map_find_systems = 0;
137 map_find_outfits = 0;
140 if (strcmp(type,
"system")==0)
141 map_find_systems = 1;
142 else if (strcmp(type,
"spob")==0)
144 else if (strcmp(type,
"outfit")==0)
145 map_find_outfits = 1;
146 else if (strcmp(type,
"ship")==0)
149 map_inputFind(parent, NULL);
155static void map_findOnClose(
unsigned int wid,
const char* str )
160 free( map_found_cur );
161 map_found_cur = NULL;
168static void map_findDisplayMark(
unsigned int wid_results,
const char* str )
171 int pos = toolkit_getListPos( wid_results,
"lstResult" );
172 StarSystem *sys = map_found_cur[ pos ].
sys;
175 map_findSelect( sys );
184static void map_findDisplayResult(
unsigned int wid_map_find,
map_find_t *found,
int n )
186 unsigned int wid_results;
190 map_found_cur = found;
194 map_sortFound( found, n );
197 wid_results =
window_create(
"wdwFindResult", _(
"Search Results"), -1, -1, 500, 452 );
203 ll = malloc(
sizeof(
char*) * n );
204 for (
int i=0; i<n; i++)
205 ll[i] = strdup( found[i].display );
206 window_addList( wid_results, 20, -40, 460, 300,
207 "lstResult", ll, n, 0, NULL, map_findDisplayMark );
211 "btnSelect", _(
"Select"), map_findDisplayMark );
219static int map_sortCompare(
const void *p1,
const void *p2 )
240 return strcasecmp( f1->
sys->name, f2->
sys->name );
246static void map_sortFound(
map_find_t *found,
int n )
248 qsort( found, n,
sizeof(
map_find_t), map_sortCompare );
254static int map_findDistance( StarSystem *sys,
Spob *spob,
int *jumps,
double *distance )
276 slist = map_getJumpPath(
cur_system->name, sys->name, 0, 1, NULL );
285 if (
cur_system->jumps[j].target == slist[0]) {
291 WARN(_(
"Jump to first system not found!"));
295 d = vec2_dist( vs, ve );
298 for (i=0; i<(*jumps-1); i++) {
299 StarSystem *ss = slist[i];
302 for (
int j=0; j <
array_size(ss->jumps); j++) {
307 vs = &ss->jumps[j].pos;
310 if (ss->jumps[j].target == slist[i-1])
311 vs = &ss->jumps[j].pos;
315 if (ss->jumps[j].target == slist[i+1]) {
316 ve = &ss->jumps[j].pos;
326 if ((vs==NULL) || (ve==NULL)) {
327 WARN( _(
"Matching jumps not found, something is up...") );
333 d += vec2_dist( vs, ve );
339 StarSystem *ss = slist[ i ];
340 for (
int j=0; j <
array_size(ss->jumps); j++) {
341 if (ss->jumps[j].target == slist[i-1]) {
342 vs = &ss->jumps[j].pos;
350 assert( vs != NULL );
351 assert( ve != NULL );
353 d += vec2_dist( vs, ve );
372static void map_findAccumulateResult(
map_find_t *found,
int n, StarSystem *sys,
Spob *spob )
375 char route_info[STRMAX_SHORT];
378 found[n].
spob = spob;
382 ret = map_findDistance( sys, spob, &found[n].jumps, &found[n].distance );
384 found[n].
jumps = 10e3;
386 snprintf( route_info,
sizeof(route_info),
"%s", _(
"unknown route") );
389 snprintf( route_info,
sizeof(route_info),
390 n_(
"%d jump, %.0fk distance",
"%d jumps, %.0fk distance", found[n].jumps ),
391 found[n].jumps, found[n].distance/1000. );
395 snprintf( found[n].display,
sizeof(found[n].display),
396 _(
"%s (%s)"), _(sys->name), route_info );
398 snprintf( found[n].display,
sizeof(found[n].display),
399 _(
"#%c%s%s (%s, %s)"), map_getSpobColourChar(spob),
400 map_getSpobSymbol(spob),
401 spob_name(spob), _(sys->name), route_info );
407static void map_findSelect(
const StarSystem *sys )
411 map_select( sys, 0 );
412 map_center( 0, sys->name );
421static int map_findSearchSystems(
unsigned int wid_map_find,
const char *name )
435 if ((sysname != NULL) && (len == 1)) {
438 if (sys_isKnown(sys)) {
439 map_findSelect( sys );
448 for (
int i=0; i<len; i++) {
452 if (!sys_isKnown(sys))
458 map_findAccumulateResult( found, n, sys, NULL );
468 map_findDisplayResult( wid_map_find, found, n );
478static int map_findSearchSpobs(
unsigned int wid_map_find,
const char *name )
483 const char *spobname;
492 if ((spobname != NULL) && (len == 1)) {
495 if (sysname != NULL) {
498 if ((spob != NULL) && spob_isKnown(spob)) {
502 if (sys_isKnown(sys)) {
503 map_findSelect( sys );
514 for (
int i=0; i<len; i++) {
522 if (!spob_isKnown(spob))
530 if (!sys_isKnown(sys))
536 map_findAccumulateResult( found, n, sys, spob );
546 map_findDisplayResult( wid_map_find, found, n );
553static char map_getSpobColourChar(
Spob *p )
566static const char *map_getSpobSymbol(
Spob *p )
575static char **map_fuzzyOutfits(
Outfit **o,
const char *name )
581 if (
strcasestr( _(o[i]->name), name ) != NULL)
583 else if ((o[i]->
typename != NULL) &&
strcasestr( o[i]->
typename, name ) != NULL)
585 else if ((o[i]->condstr != NULL) &&
strcasestr( o[i]->condstr, name ) != NULL)
599static char **map_outfitsMatch(
const char *name )
606 names = map_fuzzyOutfits( o, name );
621static void map_addOutfitDetailFields(
unsigned int wid_results,
int x,
int y,
int w,
int h)
631 window_addRect( wid_results, -1 + iw, -50, 128, 129,
"rctImage", &cBlack, 0 );
632 window_addImage( wid_results, iw, -50-128, 0, 0,
"imgOutfit", NULL, 1 );
634 window_addText( wid_results, iw + 128 + 20, -50,
635 280, 160, 0,
"txtDescShort", &
gl_smallFont, NULL, NULL );
636 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", _(
"Owned:") );
637 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", _(
"Mass:") );
638 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", _(
"Price:") );
639 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", _(
"Money:") );
640 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"#n%s#0\n", _(
"License:") );
641 window_addText( wid_results, iw+20, -50-128-10,
643 window_addText( wid_results, iw+20, -50-128-10,
644 w - (20 + iw + 20 + 90), 160, 0,
"txtDDesc", &
gl_smallFont, NULL, NULL );
645 window_addText( wid_results, iw+20, -50-128-10-160,
646 w-(iw+80), 180, 0,
"txtDescription",
660static void map_showOutfitDetail(
unsigned int wid,
const char* wgtname,
int x,
int y,
int w,
int h )
665 char buf[STRMAX], buf_price[ECON_CRED_STRLEN], buf_money[ECON_CRED_STRLEN], buf_mass[ECON_MASS_STRLEN];
666 const Outfit *outfit =
outfit_get( map_foundOutfitNames[toolkit_getListPos(wid, wgtname)] );
670 double mass = outfit->
mass;
676 window_modifyImage( wid,
"imgOutfit", outfit->
gfx_store, 128, 128 );
679 window_modifyText( wid,
"txtDescShort", buf );
688 credits2str( buf_price, outfit->
price, 2 );
690 tonnes2str( buf_mass, (
int)round( mass ) );
694 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s\n", buf_mass );
695 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s\n", buf_price );
696 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s\n", buf_money );
699 window_modifyText( wid,
"txtDDesc", buf );
715static int map_findSearchOutfits(
unsigned int wid_map_find,
const char *name )
719 const char *oname, *sysname;
723 assert(
"Outfit search is not reentrant!" && map_foundOutfitNames == NULL );
728 map_foundOutfitNames = map_outfitsMatch( name );
730 if ((oname != NULL) && (len == 1))
737 list = malloc( len*
sizeof(
char*) );
738 for (i=0; i<len; i++)
739 list[i] = strdup( _(map_foundOutfitNames[i]) );
741 map_addOutfitDetailFields, map_showOutfitDetail,
742 _(
"Search results for outfits matching '%s':"), name );
745 map_foundOutfitNames = NULL;
751 map_foundOutfitNames = NULL;
759 for (
int i=0; i<len; i++) {
772 spob = map_known_spobs[i];
775 if (!spob_hasService(spob,SPOB_SERVICE_OUTFITS))
783 if (!sys_isKnown(sys))
789 map_findAccumulateResult( found, n, sys, spob );
798 map_findDisplayResult( wid_map_find, found, n );
805static char **map_fuzzyShips(
Ship **s,
const char *name )
811 if (
strcasestr( _(s[i]->name), name ) != NULL)
813 else if ((s[i]->license != NULL) &&
strcasestr( _(s[i]->license), name ) != NULL)
817 else if (
strcasestr( _(s[i]->fabricator), name ) != NULL)
819 else if (
strcasestr( _(s[i]->description), name ) != NULL)
828static char **map_shipsMatch(
const char *name )
835 names = map_fuzzyShips( s, name );
847static int map_findSearchShips(
unsigned int wid_map_find,
const char *name )
854 const char *sname, *sysname;
862 names = map_shipsMatch( name );
864 if ((sname != NULL) && (len == 1))
870 list = malloc( len*
sizeof(
char*) );
871 for (i=0; i<len; i++)
872 list[i] = strdup( _(names[i]) );
874 _(
"Search results for ships matching '%s':"), name );
890 for (
int i=0; i<len; i++) {
902 spob = map_known_spobs[i];
905 if (!spob_hasService(spob,SPOB_SERVICE_SHIPYARD))
913 if (!sys_isKnown(sys))
919 map_findAccumulateResult( found, n, sys, spob );
928 map_findDisplayResult( wid_map_find, found, n );
935static void map_findSearch(
unsigned int wid_map_find,
const char* str )
938 const char *name, *searchname;
941 name = window_getInput( wid_map_find,
"inpSearch" );
949 window_disableButton( wid_map_find,
"btnSearch" );
952 free( map_found_cur );
953 map_found_cur = NULL;
956 if (map_find_systems) {
957 ret = map_findSearchSystems( wid_map_find, name );
958 searchname = _(
"System");
960 else if (map_find_spobs) {
961 ret = map_findSearchSpobs( wid_map_find, name );
962 searchname = _(
"Space Objects");
964 else if (map_find_outfits) {
965 ret = map_findSearchOutfits( wid_map_find, name );
966 searchname = _(
"Outfit");
968 else if (map_find_ships) {
969 ret = map_findSearchShips( wid_map_find, name );
970 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:") );
1014 window_addInput( wid_map_find, 30, y, w - 60, 20,
1020 "btnSearch", _(
"Find"), map_findSearch );
1026 window_addCheckbox( wid_map_find, x, y, 160, 20,
1027 "chkSystem", _(
"Systems"), map_findCheckUpdate, map_find_systems );
1029 window_addCheckbox( wid_map_find, x, y, 160, 20,
1030 "chkSpob", _(
"Space Objects"), map_findCheckUpdate, map_find_spobs );
1032 window_addCheckbox( wid_map_find, x, y, 160, 20,
1033 "chkOutfit", _(
"Outfits"), map_findCheckUpdate, map_find_outfits );
1035 window_addCheckbox( wid_map_find, x, y, 160, 20,
1036 "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 dialogue_alert(const char *fmt,...)
Displays an alert popup with only an ok button and a message.
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.
char * strcasestr(const char *haystack, const char *needle)
Finds a string inside another string case insensitively.
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.
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.