MCPcopy Index your code
hub / github.com/NetHack/NetHack / sortloot_cmp

Function sortloot_cmp

src/invent.c:402–547  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

400
401/* qsort comparison routine for sortloot() */
402staticfn int QSORTCALLBACK
403sortloot_cmp(const genericptr vptr1, const genericptr vptr2)
404{
405 struct sortloot_item *sli1 = (struct sortloot_item *) vptr1,
406 *sli2 = (struct sortloot_item *) vptr2;
407 struct obj *obj1 = sli1->obj,
408 *obj2 = sli2->obj;
409 char *nam1, *nam2, *tmpstr;
410 int val1, val2, namcmp;
411
412 /* in-use takes precedence over all others */
413 if ((gs.sortlootmode & SORTLOOT_INUSE) != 0) {
414 /* Classify each object at most once no matter how many
415 comparisons it is involved in. */
416 if (!sli1->orderclass)
417 inuse_classify(sli1, obj1);
418 if (!sli2->orderclass)
419 inuse_classify(sli2, obj2);
420
421 val1 = sli1->inuse;
422 val2 = sli2->inuse;
423 if (val1 != val2)
424 return val2 - val1; /* bigger value comes before smaller */
425 /* neither item in use (or both are lit lamps/candles or both are
426 attached leashes; items using owornmask don't produce ties) */
427 goto tiebreak;
428 }
429
430 /* order by object class unless we're doing by-invlet without sortpack */
431 if ((gs.sortlootmode & (SORTLOOT_PACK | SORTLOOT_INVLET))
432 != SORTLOOT_INVLET) {
433 /* Classify each object at most once no matter how many
434 comparisons it is involved in. */
435 if (!sli1->orderclass)
436 loot_classify(sli1, obj1);
437 if (!sli2->orderclass)
438 loot_classify(sli2, obj2);
439
440 /* Sort by class. */
441 val1 = sli1->orderclass;
442 val2 = sli2->orderclass;
443 if (val1 != val2)
444 return val1 - val2;
445
446 /* skip sub-classes when ordering by sortpack+invlet */
447 if ((gs.sortlootmode & SORTLOOT_INVLET) == 0) {
448 /* Class matches; sort by subclass. */
449 val1 = sli1->subclass;
450 val2 = sli2->subclass;
451 if (val1 != val2)
452 return val1 - val2;
453
454 /* Class and subclass match; sort by discovery status:
455 * first unseen, then seen but not named or discovered,
456 * then named, lastly discovered.
457 * 1) potion
458 * 2) pink potion
459 * 3) dark green potion called confusion

Callers 1

sortlootFunction · 0.85

Calls 6

inuse_classifyFunction · 0.85
loot_classifyFunction · 0.85
invletter_valueFunction · 0.85
loot_xnameFunction · 0.85
dupstrFunction · 0.85
maybereleaseobufFunction · 0.85

Tested by

no test coverage detected