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

Function sortbill_cmp

src/shk.c:1498–1518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1496 otherwise, if their costs differ, the more expensive one comes first;
1497 if costs are the same, use internal index as tie-breaker for stable sort */
1498staticfn int QSORTCALLBACK
1499sortbill_cmp(const genericptr vptr1, const genericptr vptr2)
1500{
1501 const struct sortbill_item *sbi1 = (struct sortbill_item *) vptr1,
1502 *sbi2 = (struct sortbill_item *) vptr2;
1503 long cost1 = sbi1->cost, cost2 = sbi2->cost;
1504 int bidx1 = sbi1->bidx, bidx2 = sbi2->bidx,
1505 /* sort such that FullyUsedUp and PartlyUsedUp come before
1506 PartlyIntact, FullyIntact, KnownContainer, UndisclosedContainer */
1507 used1 = sbi1->usedup <= PartlyUsedUp, /* 0=>unpaid, 1=>used */
1508 used2 = sbi2->usedup <= PartlyUsedUp;
1509
1510 if (used1 != used2)
1511 return (used2 - used1); /* bigger comes before smaller here */
1512 if (cost1 != cost2)
1513 return (cost2 - cost1); /* bigger comes before smaller here too */
1514 /* index into eshkp->bill_p[] isn't unique (an item that is partly
1515 used and partly intact will have two ibill[] entries indexing same
1516 bill_p[] element) but duplicates won't reach here (used1 vs used2) */
1517 return (bidx1 - bidx2);
1518}
1519
1520/* delivers the cheapest item on the list */
1521staticfn long

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected