7 #include "util/object-sort.h"
8 #include "monster-race/monster-race.h"
9 #include "object/object-value.h"
10 #include "object/tval-types.h"
11 #include "perception/object-perception.h"
12 #include "player/player-realm.h"
13 #include "system/item-entity.h"
14 #include "system/monster-race-info.h"
15 #include "system/player-type-definition.h"
17 static int get_item_sort_rank(const ItemEntity &item)
19 if (item.is_fixed_artifact()) {
23 if (item.is_random_artifact()) {
35 * @brief オブジェクトを定義された基準に従いソートするための関数 /
36 * Check if we have space for an item in the pack without overflow
37 * @param o_ptr 比較対象オブジェクトの構造体参照ポインタ1
38 * @param o_value o_ptrのアイテム価値(手動であらかじめ代入する必要がある?)
39 * @param j_ptr 比較対象オブジェクトの構造体参照ポインタ2
40 * @return o_ptrの方が上位ならばTRUEを返す。
42 bool object_sort_comp(PlayerType *player_ptr, ItemEntity *o_ptr, int32_t o_value, ItemEntity *j_ptr)
44 if (!j_ptr->is_valid()) {
48 const auto o_tval = o_ptr->bi_key.tval();
49 const auto j_tval = j_ptr->bi_key.tval();
50 if ((o_tval == get_realm1_book(player_ptr)) && (j_tval != get_realm1_book(player_ptr))) {
54 if ((j_tval == get_realm1_book(player_ptr)) && (o_tval != get_realm1_book(player_ptr))) {
58 if ((o_tval == get_realm2_book(player_ptr)) && (j_tval != get_realm2_book(player_ptr))) {
62 if ((j_tval == get_realm2_book(player_ptr)) && (o_tval != get_realm2_book(player_ptr))) {
66 if (o_tval > j_tval) {
70 if (o_tval < j_tval) {
74 if (!o_ptr->is_aware()) {
78 if (!j_ptr->is_aware()) {
82 const auto o_sval = o_ptr->bi_key.sval();
83 const auto j_sval = j_ptr->bi_key.sval();
84 if (o_sval < j_sval) {
88 if (o_sval > j_sval) {
92 if (!o_ptr->is_known()) {
96 if (!j_ptr->is_known()) {
100 const auto o_rank = get_item_sort_rank(*o_ptr);
101 const auto j_rank = get_item_sort_rank(*j_ptr);
102 if (o_rank < j_rank) {
106 if (o_rank > j_rank) {
111 case ItemKindType::FIGURINE:
112 case ItemKindType::STATUE:
113 case ItemKindType::CORPSE:
114 case ItemKindType::CAPTURE: {
115 auto o_r_idx = i2enum<MonsterRaceId>(o_ptr->pval);
116 auto j_r_idx = i2enum<MonsterRaceId>(j_ptr->pval);
117 if (monraces_info[o_r_idx].level < monraces_info[j_r_idx].level) {
121 if ((monraces_info[o_r_idx].level == monraces_info[j_r_idx].level) && (o_ptr->pval < j_ptr->pval)) {
127 case ItemKindType::SHOT:
128 case ItemKindType::ARROW:
129 case ItemKindType::BOLT:
130 if (o_ptr->to_h + o_ptr->to_d < j_ptr->to_h + j_ptr->to_d) {
134 if (o_ptr->to_h + o_ptr->to_d > j_ptr->to_h + j_ptr->to_d) {
139 case ItemKindType::ROD:
140 if (o_ptr->pval < j_ptr->pval) {
144 if (o_ptr->pval > j_ptr->pval) {
153 return o_value > j_ptr->get_price();