MCPcopy Create free account
hub / github.com/NetHack/NetHack / gather_locs

Function gather_locs

src/getpos.c:512–554  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

510
511/* gather locations for monsters or objects shown on the map */
512staticfn void
513gather_locs(coord **arr_p, int *cnt_p, int gloc)
514{
515 int pass, idx;
516 coordxy x, y;
517
518 /*
519 * We always include the hero's location even if there is no monster
520 * (invisible hero without see invisible) or object (usual case)
521 * displayed there. That way, the count will always be at least 1,
522 * and player has a visual indicator (cursor returns to hero's spot)
523 * highlighting when successive 'm's or 'o's have cycled all the way
524 * through all monsters or objects.
525 *
526 * Hero's spot will always sort to array[0] because it will always
527 * be the shortest distance (namely, 0 units) away from <u.ux,u.uy>.
528 */
529
530 gloc_filter_init();
531
532 *cnt_p = idx = 0;
533 for (pass = 0; pass < 2; pass++) {
534 for (x = 1; x < COLNO; x++)
535 for (y = 0; y < ROWNO; y++) {
536 if (u_at(x, y) || gather_locs_interesting(x, y, gloc)) {
537 if (!pass) {
538 ++*cnt_p;
539 } else {
540 (*arr_p)[idx].x = x;
541 (*arr_p)[idx].y = y;
542 ++idx;
543 }
544 }
545 }
546
547 if (!pass) /* end of first pass */
548 *arr_p = (coord *) alloc(*cnt_p * sizeof (coord));
549 else /* end of second pass */
550 qsort(*arr_p, *cnt_p, sizeof (coord), cmp_coord_distu);
551 } /* pass */
552
553 gloc_filter_done();
554}
555
556char *
557dxdy_to_dist_descr(coordxy dx, coordxy dy, boolean fulldir)

Callers 2

getpos_menuFunction · 0.85
getposFunction · 0.85

Calls 5

gloc_filter_initFunction · 0.85
gather_locs_interestingFunction · 0.85
qsortFunction · 0.85
gloc_filter_doneFunction · 0.85
allocFunction · 0.70

Tested by

no test coverage detected