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

Function migrsort_cmp

src/wizcmds.c:1484–1501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1482
1483/* qsort() comparison routine for use in list_migrating_mons() */
1484staticfn int QSORTCALLBACK
1485migrsort_cmp(const genericptr vptr1, const genericptr vptr2)
1486{
1487 const struct monst *m1 = *(const struct monst **) vptr1,
1488 *m2 = *(const struct monst **) vptr2;
1489 int d1 = (int) m1->mux, l1 = (int) m1->muy,
1490 d2 = (int) m2->mux, l2 = (int) m2->muy;
1491
1492 /* if different branches, sort by dungeon number */
1493 if (d1 != d2)
1494 return d1 - d2;
1495 /* within same branch, sort by level number */
1496 if (l1 != l2)
1497 return l1 - l2;
1498 /* same destination level: use a tie-breaker to force stable sort;
1499 monst->m_id is unsigned so we need more than just simple subtraction */
1500 return (m1->m_id < m2->m_id) ? -1 : (m1->m_id > m2->m_id);
1501}
1502
1503/* called by #migratemons; displays count of migrating monsters, optionally
1504 displays them as well */

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected