+bool object_sort_comp(object_type *o_ptr, s32b o_value, object_type *j_ptr)
+{
+ int o_type, j_type;
+
+ /* Use empty slots */
+ if (!j_ptr->k_idx) return TRUE;
+
+ /* Hack -- readable books always come first */
+ if ((o_ptr->tval == REALM1_BOOK) &&
+ (j_ptr->tval != REALM1_BOOK)) return TRUE;
+ if ((j_ptr->tval == REALM1_BOOK) &&
+ (o_ptr->tval != REALM1_BOOK)) return FALSE;
+
+ if ((o_ptr->tval == REALM2_BOOK) &&
+ (j_ptr->tval != REALM2_BOOK)) return TRUE;
+ if ((j_ptr->tval == REALM2_BOOK) &&
+ (o_ptr->tval != REALM2_BOOK)) return FALSE;
+
+ /* Objects sort by decreasing type */
+ if (o_ptr->tval > j_ptr->tval) return TRUE;
+ if (o_ptr->tval < j_ptr->tval) return FALSE;
+
+ /* Non-aware (flavored) items always come last */
+ /* Can happen in the home */
+ if (!object_is_aware(o_ptr)) return FALSE;
+ if (!object_is_aware(j_ptr)) return TRUE;
+
+ /* Objects sort by increasing sval */
+ if (o_ptr->sval < j_ptr->sval) return TRUE;
+ if (o_ptr->sval > j_ptr->sval) return FALSE;
+
+ /* Unidentified objects always come last */
+ /* Objects in the home can be unknown */
+ if (!object_is_known(o_ptr)) return FALSE;
+ if (!object_is_known(j_ptr)) return TRUE;
+
+ /* Fixed artifacts, random artifacts and ego items */
+ if (object_is_fixed_artifact(o_ptr)) o_type = 3;
+ else if (o_ptr->art_name) o_type = 2;
+ else if (object_is_ego(o_ptr)) o_type = 1;
+ else o_type = 0;
+
+ if (object_is_fixed_artifact(j_ptr)) j_type = 3;
+ else if (j_ptr->art_name) j_type = 2;
+ else if (object_is_ego(j_ptr)) j_type = 1;
+ else j_type = 0;
+
+ if (o_type < j_type) return TRUE;
+ if (o_type > j_type) return FALSE;
+
+ switch (o_ptr->tval)
+ {
+ case TV_FIGURINE:
+ case TV_STATUE:
+ case TV_CORPSE:
+ case TV_CAPTURE:
+ if (r_info[o_ptr->pval].level < r_info[j_ptr->pval].level) return TRUE;
+ if ((r_info[o_ptr->pval].level == r_info[j_ptr->pval].level) && (o_ptr->pval < j_ptr->pval)) return TRUE;
+ return FALSE;
+
+ case TV_SHOT:
+ case TV_ARROW:
+ case TV_BOLT:
+ /* Objects sort by increasing hit/damage bonuses */
+ if (o_ptr->to_h + o_ptr->to_d < j_ptr->to_h + j_ptr->to_d) return TRUE;
+ if (o_ptr->to_h + o_ptr->to_d > j_ptr->to_h + j_ptr->to_d) return FALSE;
+ break;
+
+ /* Hack: otherwise identical rods sort by
+ increasing recharge time --dsb */
+ case TV_ROD:
+ if (o_ptr->pval < j_ptr->pval) return TRUE;
+ if (o_ptr->pval > j_ptr->pval) return FALSE;
+ break;
+ }
+
+ /* Objects sort by decreasing value */
+ return o_value > object_value(j_ptr);
+}
+
+